[solved] Randomise page alias when page first created

For questions and problems with the CMS core. This board is NOT for any 3rd party modules, addons, PHP scripts or anything NOT distributed with the CMS made simple package itself.
Post Reply
Cerulean
Forum Members
Forum Members
Posts: 172
Joined: Mon Nov 01, 2010 8:56 am

[solved] Randomise page alias when page first created

Post by Cerulean »

Several clients have needed a simple way to "hide" pages on their website so they are only viewable to visitors who have been provided with the page URL. I do this by creating a special page template with a "noindex" metatag, and then advise them when creating the page to:
- uncheck "Show in menu"
- replace the default page alias with a random string of letters (so the URL is more difficult for a non-authorised visitor to guess)

BTW, I realise this doesn't provide a great deal of security - it's just for basic privacy.

This is all fine, but I thought I'd see if there is a way to automate this process. I was thinking of attaching a UDT to an appropriate event, which did something like...
if page parent = x then uncheck "Show in Menu" and replace page alias with randomised string

But I can't see an event that fires only when a page is first created. There's ContentEditPre/Post, but I don't want the alias randomised on every edit. Is there a suitable event I can attach to, or any other suggestions on achieving this?

Thanks.
Last edited by Cerulean on Sat Apr 26, 2014 7:13 am, edited 1 time in total.
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm

Re: Randomise page alias when page first created

Post by calguy1000 »

No, there is no event or any other mechanism to grammatically change the page alias algorithm. sorry.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
User avatar
Dr.CSS
Moderator
Moderator
Posts: 12711
Joined: Thu Mar 09, 2006 5:32 am

Re: Randomise page alias when page first created

Post by Dr.CSS »

Install front end users module, set it to allow multi log in of user, make one user and give this out to every one to log in, set the pages to Content Type: Protected...
Cerulean
Forum Members
Forum Members
Posts: 172
Joined: Mon Nov 01, 2010 8:56 am

Re: [solved] Randomise page alias when page first created

Post by Cerulean »

Ummm... what happened to the rest of the replies that were in this thread? Moved? Deleted? Why?
Cerulean
Forum Members
Forum Members
Posts: 172
Joined: Mon Nov 01, 2010 8:56 am

Re: [solved] Randomise page alias when page first created

Post by Cerulean »

Looks like the disappeared replies will remain a mystery.

Anyway, here is the final UDT attached to the ContentEditPre event:

Code: Select all

$content_obj =& $params["content"];
$parentid = $content_obj->ParentId();
$extra = $content_obj->GetPropertyValue("extra1");

// Adjust parentid below as needed
if ($parentid == 33 && $extra != "is-randomised") {
    $random = substr(md5(time()), 0, 12);
    $content_obj->SetAlias($random);
    $content_obj->SetShowInMenu(false);
    $content_obj->SetPropertyValue("extra1", "is-randomised");
}
Post Reply

Return to “CMSMS Core”