How to generate pages on the fly?

Third Party Plugins to CMSimple - how to install, use and create plugins

Moderator: Tata

Post Reply
svasti
Posts: 1651
Joined: Wed Dec 17, 2008 5:08 pm

How to generate pages on the fly?

Post by svasti » Sun Apr 17, 2016 6:36 pm

Working on miniblog
and the alpha version of the next version comes with the possibility that external persons can write blogs (via Christoph's extedit_XH, after log in via register/memberpages).

However, the URLs now look like this:

http://www.mycmsimple.yx/?Blog&mblog=author---title

Seems to me not very elegant. What do you think? I'd rather have

http://www.mycmsimple.yx/?Blog/author/title

Would that be possible? And if, how to do it?

cmb
Posts: 14225
Joined: Tue Jun 21, 2011 11:04 am
Location: Bingen, RLP, DE
Contact:

Re: How to generate pages on the fly?

Post by cmb » Sun Apr 17, 2016 7:32 pm

svasti wrote:I'd rather have

http://www.mycmsimple.yx/?Blog/author/title

Would that be possible? And if, how to do it?
Off the top of my head: when CMSimple(_XH) starts up, the "URL" of the page (i.e. Blog/author/title) is stored in $su, and if there's no such page, $s is set to -1. When the plugins are loaded, one can catch certain $su values and append any HTML to $o; if the latter is actually done, $s won't be fixed by CMSimple(_XH), but the system doesn't complain.
Christoph M. Becker – Plugins for CMSimple_XH

svasti
Posts: 1651
Joined: Wed Dec 17, 2008 5:08 pm

Re: How to generate pages on the fly?

Post by svasti » Mon Apr 18, 2016 9:04 am

Yep, that's it. Works!

svasti
Posts: 1651
Joined: Wed Dec 17, 2008 5:08 pm

Re: How to generate pages on the fly?

Post by svasti » Wed Apr 20, 2016 3:24 pm

Too bad, doesn't quite work :cry:
A very strange finding:

Some, not all, plugins will not evaluate in the blog pages addressed as ?miniblog/author/title
CMSimple complains that these plugin calls are not defined. However if the page is addressed in the old style ?Blog&mblog=author---title there is no problem, all plugin calls work.

So I had CMSimple print out all its functions (there were 205 in this case): the functions that didn't work came in the alphabet after miniblog. After I renamed the miniblog plugin folder to zzminiblog everything worked.

So how do I get CMSimple to process miniblog as last plugin? Or how do I make CMSimple evaluated the remaining (alphabet wise) plugin calls after miniblog has beem processed?

Edit: And is there a way these new URLs could be added to the internal Link list of the online editors? And to the sitemap? And to sitemapper_XH? And what about the search function...

cmb
Posts: 14225
Joined: Tue Jun 21, 2011 11:04 am
Location: Bingen, RLP, DE
Contact:

Re: How to generate pages on the fly?

Post by cmb » Wed Apr 20, 2016 5:13 pm

svasti wrote:So how do I get CMSimple to process miniblog as last plugin? Or how do I make CMSimple evaluated the remaining (alphabet wise) plugin calls after miniblog has beem processed?
Just use XH_afterPluginLoading. :)
svasti wrote:And is there a way these new URLs could be added to the internal Link list of the online editors? And to the sitemap? And to sitemapper_XH? And what about the search function...
Hm, that's more of a problem. The editor's link list and the sitemap are built using the $u array. Probably it's not a problem to append to $u, but I wouldn't insert elements into it – all the other related arrays would have to be modified also. And doing that in the middle of the plugin loading or after all plugins would have been loaded, surely creates a mess (if only in some rare circumstances). Sitemapper_XH also relies on $u & Co., so bad luck.

Regarding the search function: in my opinion there should be a hook for plugins to register interest in participating in the search. If a search is requested, the core would dispatch to all registered plugins, each of which would return their own search results. The core would merge these results with its own, and present the list to user.
Christoph M. Becker – Plugins for CMSimple_XH

svasti
Posts: 1651
Joined: Wed Dec 17, 2008 5:08 pm

Re: How to generate pages on the fly?

Post by svasti » Wed Apr 20, 2016 7:20 pm

cmb wrote:Just use XH_afterPluginLoading. :)
Not quite sure how to use it.
The function producing the page is

Code: Select all

if ($s == -1 && strpos($su,'miniblog')===0 && strlen($su) > 11) {
    $o = Miniblog_extPage($su);
}
function Miniblog_extPage($url) {...
Now where and how to insert XH_afterPluginLoading()?
cmb wrote:Probably it's not a problem to append to $u
I thought of adding all links at the end, so may be a possibility.
cmb wrote:Regarding the search function: in my opinion there should be a hook for plugins
Ok, a point for 1.7

cmb
Posts: 14225
Joined: Tue Jun 21, 2011 11:04 am
Location: Bingen, RLP, DE
Contact:

Re: How to generate pages on the fly?

Post by cmb » Wed Apr 20, 2016 9:52 pm

svasti wrote:
cmb wrote:Just use XH_afterPluginLoading. :)
Not quite sure how to use it.
The function producing the page is

Code: Select all

if ($s == -1 && strpos($su,'miniblog')===0 && strlen($su) > 11) {
    $o = Miniblog_extPage($su);
}
function Miniblog_extPage($url) {... 
Now where and how to insert XH_afterPluginLoading()?
XH_afterPluginLoading() expects a callback function to be passed as parameter. This callback function is called by the core immediately after all plugins have been loaded (i.e. after index.php and admin.php have been included). So, for instance, somewhere in index.php write:

Code: Select all

XH_afterPluginLoading(
    function () {
        global $s, $su, $o;
        
        if ($s == -1 && strpos($su, 'miniblog')===0 && strlen($su) > 11) {
            $o = Miniblog_extPage($su);
        }
    }
); 
Christoph M. Becker – Plugins for CMSimple_XH

svasti
Posts: 1651
Joined: Wed Dec 17, 2008 5:08 pm

Re: How to generate pages on the fly?

Post by svasti » Thu Apr 21, 2016 6:26 pm

Very nice, this does the job. Sorry that I had to ask :oops:

My experiences with adding the new URLs are mixed. Blog postings are entered via extedit (by members), however extedit is a bit restricted: it seems not to show the link list.
So I thought adding the new URLs doesn't make much sense. :roll:
The new URLs will only be added in admin mode, so that the admin can take advantage of them.

Post Reply