Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Try Vanilla Forums Cloud product

Simple Pages 1.0

This discussion is related to the Simple Pages addon.
LincLinc Director of DevelopmentDetroit Vanilla Staff

I was brainstorming the dead-simplest way of doing "static" pages without any database modifications and came up with this. Probably not going to be adding more features to it any time soon. Should scale very well.

ShadowdareAnonymoosehgtonightjackmaessenAdrianperegrineAaronWebsteyBleistivtCansili

Comments

  • hgtonighthgtonight ∞ · New Moderator

    This is a cool little plugin!

    Is there a reason you went with searching on not found versus adding a route?

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

  • peregrineperegrine MVP
    edited January 2015

    interesting plugin.... note:

    only root admin can make a page since it uses a non-existing permission in vanilla 2.1

    a possible tweak

    CheckPermission('Garden.Community.Manage')

    could be changed to

    CheckPermission('Garden.Users.Edit')

    a possible issue

    editing page cause a duplicate discussion to be created as well, at least that is what I see.

    A readme with some sample instructions regarding slug would go a long way for users.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • LincLinc Director of Development Detroit Vanilla Staff

    @hgtonight said:
    Is there a reason you went with searching on not found versus adding a route?

    Yes: routes don't scale. They'll bog down the config.php with a ton of text, which needs to get re-read on every request.

    Also, a route will override controllers, meaning you could then break your site if you created a page at 'profile', for instance.

    hgtonight
  • LincLinc Director of Development Detroit Vanilla Staff

    Good thoughts, @peregrine. I've now released 1.1:

    • Added Garden.Settings.Manage permission option for 2.1 compatibility.
    • Renamed 'Page Slug' field to 'URL Slug' and added helper text.
    • Added validation rule to enforce choosing a slug if making page.
    peregrine
  • LincLinc Director of Development Detroit Vanilla Staff
    edited January 2015

    @peregrine said:
    editing page cause a duplicate discussion to be created as well, at least that is what I see.

    I didn't see this happening on my test install of 2.1. Anyone else see this? What field(s) are you editing, specifically?

    Presently, you wouldn't be able to retroactively edit a discussion to convert it to a page. Known limitation. However, changing the rest should work.

  • peregrineperegrine MVP
    edited January 2015

    @Linc said:

    I didn't see this happening on my test install of 2.1. Anyone else see this? What field(s) are you editing, specifically?

    thx for the replies!

    I went to the last discussion in the topics index and edited it. I'm on a localhost. vanilla 2.1.6
    version 1.1 of plugin.

    a step by step read me with some screenshots would be handy.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • peregrineperegrine MVP
    edited January 2015

    @linc

    for the life of me I couldn't figure out how this plugin worked.

    but as it turns out on my local host with vanilla installed in vanilla folder.

    I had to change

    // Page exists with requested slug, so dispatch; no redirect.
            if (val('DiscussionID', $result)) {
                SaveToConfig('SimplePage.Found', true, false);
                Gdn::Dispatcher()->Dispatch(discussionUrl($result, '', false));
                exit();
            }
    

    to

    // Page exists with requested slug, so dispatch; no redirect.
            if (val('DiscussionID', $result)) {
                SaveToConfig('SimplePage.Found', true, false);
    
    
                       $disc = discussionUrl($result, '', false);
                       $disc = str_replace("/vanilla/index.php?p=","",$disc);
    
                Gdn::Dispatcher()->Dispatch($disc);
                exit();
            }
    

    now finally I can see it is a cool plugin.

    I'm puzzled why it wouldn't work with standard code.

    the original discussionUrl($result, '', false)

    evaluated to "/vanilla/index.php?p=/discussion/221/testpage"

    and I had to chop it to look like

    /discussion/221/testpage

    prior to dispatch otherwise I got page not found.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • LincLinc Director of Development Detroit Vanilla Staff
    edited January 2015

    I probably neglected to account for subfolder sites.

  • peregrineperegrine MVP
    edited January 2015
        ultimately I changed it to this, if helps anyone.
    
    $DID = val('DiscussionID', $result);
    if ($DID > 0) {
        SaveToConfig('SimplePage.Found', true, false);
        Gdn::Dispatcher()->Dispatch("/discussion/{$DID}/x");
        exit();
        }
    

    @linc said: I was brainstorming the dead-simplest way of doing "static" pages

    was this auto-brainstorming or did you brainstorm in a committee.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • LincLinc Director of Development Detroit Vanilla Staff
    edited January 2015

    I'm fairly certain the solution will be to simply wrap discussionUrl() with Url().

    No it already does that. I actually see no difference between the result of your code and mine.

  • peregrineperegrine MVP
    edited January 2015

    with yours
    I get this being dispatched "/vanilla/index.php?p=/discussion/221/testpage" // doesn't work for me,.

    but it doesn't like that at least with my localhost and /vanilla folder standard .htaccess

    with my code snippets - I have this being dispatched - /discussion/221/testpage // which works for me.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

    Linc
  • LincLinc Director of Development Detroit Vanilla Staff

    I see. It's taking a double-fall from both the subfolder and the Rewrite not being enabled. Your fix is correct; my change is functionally the same.

        if ($discussionID = val('DiscussionID', $result)) {
            SaveToConfig('SimplePage.Found', true, false);
            Gdn::Dispatcher()->Dispatch('/discussion/'.$discussionID);
            exit();
        }
    
    peregrine
  • peregrineperegrine MVP
    edited January 2015

    aha - that explains it. your mod of my mod works for me as well and is cleaner.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • I realized later after you mentioned Rewrite it (that I was testing for days with and forgot to change back)

    $Configuration['Garden']['RewriteUrls'] = FALSE;

    and that was the source of the issue.

    but the change you made is more robust and seems to work for both

    $Configuration['Garden']['RewriteUrls'] = FALSE;
    or
    $Configuration['Garden']['RewriteUrls'] = TRUE;

    Although it still seems there may still be portions of vanilla that won't work correctly if you have

    $Configuration['Garden']['RewriteUrls'] = FALSE;


    is $Configuration['Garden']['RewriteUrls'] = TRUE; pretty much mandatory or do you want to hear about other things that may not work with $Configuration['Garden']['RewriteUrls'] = FALSE;

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • LincLinc Director of Development Detroit Vanilla Staff

    I believe we are planning to switch to making RewriteUrls a mandatory setting in the future. I'm not sure what the current status is regarding our support for it. @Todd?

  • I've installed/enabled this, but am curious, is this a plugin that just works and doesn't have settings? I don't see any way of setting things up once I've enabled the plugin.

  • peregrineperegrine MVP
    edited January 2015

    @Skisma said:
    I've installed/enabled this, but am curious, is this a plugin that just works and doesn't have settings? I don't see any way of setting things up once I've enabled the plugin.

    since there are no global options - there is no need for a settings page.

    the settings are when you post a discussion. i.e. Show As Page for users with garden settings manage permissions.

    Many plugins have no settings page, because there is no need.

    perhaps one day - linc will attach a screenshot to the plugin, and user mysteries will be put too rest. :wink:

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • peregrineperegrine MVP
    edited January 2015

    on my localhost with forum installed in vanilla subfolder.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • LincLinc Director of Development Detroit Vanilla Staff

    @peregrine‌ Thanks, added it.

    Also released yesterday's fix as 1.2, and added an icon.

  • peregrineperegrine MVP
    edited January 2015

    @Linc said:
    peregrine‌ Thanks, added it.

    Also released yesterday's fix as 1.2, and added an icon.

    thank you. I "approve" this plugin :)

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

    cia113311
  • ToddTodd Chief Product Officer Vanilla Staff

    @Linc said:
    I believe we are planning to switch to making RewriteUrls a mandatory setting in the future. I'm not sure what the current status is regarding our support for it. Todd?

    We will be requiring url rewrites in the future, yes.

    peregrinecia113311
  • I recommend, explicit routes and route reversal for automatically updating urls, as other frameworks do. Implicit routes have their use but are limited, there is not reason to attach a particular url scheme to a particular controller. Of course implicit routes can be a fallback.

    It makes more sense to get the url from reversal like django than be limited to a fixed albeit relative url scheme.

    routes in config.php is limited, it would be useful to set routes in app or plugin as a configuration.

    However in this case the the not found handler is appropriate. When Linc says that routes are not scalable, they are not scalable if not well matched, but there is nothing wrong and quite a bit right with explicit routing if done well and appropriately. Many MVC framework make use of them as standard.

    grep is your friend.

    AnonymooseBleistivtShadowdare
  • Nice plugin!

    In the current version (1.2) the plugin performs a redirect from the discussion url to the "slug" url. However, the links in the forum are not changed, so this redirect has to be performed on every call.

    Therefore, I propose to change the forum links directly. Hence, the following code could be added to the plugin (based on the code for discussionUrl() in vanilla 2.2):
    if (!function_exists('discussionUrl')) { function discussionUrl($Discussion, $Page = '', $WithDomain = true) { $Discussion = (object)$Discussion; if($Discussion->Type=='SimplePage' && !empty($Discussion->ForeignID)) { $Result = '/'.$Discussion->ForeignID; } else { $Name = Gdn_Format::Url($Discussion->Name); if (empty($Name)) { $Name = 'x'; } $Result = '/discussion/'.$Discussion->DiscussionID.'/'.$Name; } if ($Page) { if ($Page > 1 || Gdn::Session()->UserID) { $Result .= '/p'.$Page; } } return Url($Result, $WithDomain); } }

Sign In or Register to comment.