HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Simple Pages 1.0

This discussion is related to the Simple Pages addon.

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
«1

Comments

  • Excellent.

  • 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 Detroit Admin

    @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 Detroit Admin

    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 Detroit Admin
    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 Detroit Admin
    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 Detroit Admin
    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 Detroit Admin

    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 Detroit Admin

    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 Detroit Admin

    @peregrine‌ Thanks, added it.

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

Sign In or Register to comment.