Posts: 1,108
Threads: 70
Joined: Aug 2009
Another Page Caching plugin !! Well sort of.
The Pages.php Plugin caches all you page data into a single XML file called /data/pages/pages.array
This file is read into an array and is made available to your templates to quickly access page information without having to read in individual files each time.
The XML file is updated each time a page is edited and saved.
The plugin has been tested with a site with 2500+ pages each one with a menu entry. Page Generation on a site this size was faster by approx 70% as there was only 2 file reads, one for the pages and one for the content. For the above example the menu generation script used the plugin rather than reading in each file.
All data except the "Content" information is added to the file.
The following functions are available to you:
Code: getPageContent($page) - Echos the content of the Page
getPageField($page,$field) - Echos the Field of the requested Page returnPageContent($page) - Returns the content of the Page
returnPageField($page,$field) - Returns the Field of the requested Page
getChildren($page) - returns an array of slug names that are children of the given page
Note: $page is the Slug Name
If your using in your templates, the variable $id can be used for the current page.
Should work fine with all version since 2.x
Install Instructions:
Just copy into the plugins folder and your done.
Download on http://get-simple.info/extend/plugin/pagesphp/65/
Posts: 1,108
Threads: 70
Joined: Aug 2009
Here is my Menu generation function using the plugin.
Code: //****************************************************//
//** FUNCTION: getMenu() **//
//** **//
//** Returns the main menu of the site. **//
//****************************************************//
function getMenu($currentpage) {
global $PRETTYURLS;
global $digi_pagesArray;
$menu = '';
$pagesSorted = subval_sort($digi_pagesArray,'menuOrder');
if (count($pagesSorted) != 0) {
foreach ($pagesSorted as $page) {
$sel = ''; $classes = '';
$url_nav = $page['slug'];
if ($page['menuStatus'] == 'Y' && $page['private']!='Y') {
if ("$currentpage" == "$url_nav") { $classes = "current ". $url_nav; } else { $classes = $url_nav; }
if ($page['menu'] == '') { $page['menu'] = $page['title']; }
if ($page['title'] == '') { $page['title'] = $page['menu']; }
$menu .= '<li class="'. $classes .'" ><a href="'. find_url($page['slug'],$page['parent']) . '" title="'. $page['title'] .'">'.$page['menu'].'</a></li>'."\n";
$menu .='<li>/</li>';
}
}
echo substr($menu,0,-10);
}
}
Posts: 3,491
Threads: 106
Joined: Mar 2010
n00dles101 Wrote:Another Page Caching plugin !! Well sort of.
"Page Indexing", I would suggest...
Thanks for sharing it!
Posts: 1,204
Threads: 30
Joined: Jun 2010
Mike, am I right that your menu function is 1 lvl deep (parent+1st child) ?
Addons: blue business theme, Online Visitors, Notepad
Posts: 1,108
Threads: 70
Joined: Aug 2009
@yoyoe, yes its only a single level menu.
This one however will do it for you... I've taken out the "<li>/</li>" spacer..
You'll need to style as you need...
And one file read, instead of every page of your site... 8)
Hope its of use....
Code: function getMenu($currentpage) {
global $PRETTYURLS;
global $digi_pagesArray;
$menu = '';
$startUL=false;
$pagesSorted = subval_sort($digi_pagesArray,'menuOrder');
if (count($pagesSorted) != 0) {
foreach ($pagesSorted as $page) {
$sel = ''; $classes = '';
$url_nav = $page['slug'];
if ($page['menuStatus'] == 'Y' && $page['private']!='Y' && $page['parent']=='') {
if ("$currentpage" == "$url_nav") { $classes = "current ". $url_nav; } else { $classes = $url_nav; }
if ($page['menu'] == '') { $page['menu'] = $page['title']; }
if ($page['title'] == '') { $page['title'] = $page['menu']; }
$menu .= '<li class="'. $classes .'" ><a href="'. find_url($page['slug'],$page['parent']) . '" title="'. $page['title'] .'">'.$page['menu'].'</a>'."\n";
$submenus=getChildren($url_nav);
if (count($submenus) != 0) {
$smenu='';
foreach ($submenus as $submenu){
if (returnPageField($submenu,'menuStatus')=='Y'){
$smenu .= "<li class='submenu'>".$submenu."</li>";
}
}
if ($smenu!='') $menu.='<ul>'.$smenu.'</ul>';
}
$menu .='</li>';
}
}
echo $menu;
}
}
Posts: 1,204
Threads: 30
Joined: Jun 2010
2010-12-20, 14:30:56
(This post was last modified: 2010-12-20, 14:31:59 by BlackRose.)
I'll have to look deeper into this function.
I used for now getchild 1.5, and it has own caching function.
I'm thinking about some serious changes to make GS working with 3 lvl menu, as it could be the easiest method for multilanguage sites.
edit: thanks for this function
Addons: blue business theme, Online Visitors, Notepad
Posts: 3,491
Threads: 106
Joined: Mar 2010
To get a page's last saved date you have to:
Code: returnPageField($slug,'pubdate');
That is, use 'pubdate', not 'pubDate' as you might expect.
Posts: 3,491
Threads: 106
Joined: Mar 2010
There's a small issue with this plugin: it doesn't update the page index when you change anything (edit and save a page, delete page...) until you save a page again.
Seems it is because it's hooked to changedata-save, fired before the current page file is written.
Posts: 1,108
Threads: 70
Joined: Aug 2009
Thanks Carlos, would never have spotted that..
Hmmm now how to sort it out...
Looks like we might have to add a hook after the file save.
No other way to do stuff like this....
Leave it with me...
Mike...
Posts: 3,491
Threads: 106
Joined: Mar 2010
Thanks for the quick reply Mike.
I think something might be done by using the 'header' hook... (at the destination page, once saved)
BTW the index should also be updated when a page is removed.
(Perhaps it should be periodically generated, just in case some pages get updated by a plugin or script.)
Posts: 2,094
Threads: 54
Joined: Jan 2011
n00dles101 Wrote:Thanks Carlos, would never have spotted that..
Hmmm now how to sort it out...
Looks like we might have to add a hook after the file save.
Or just delete the cache on changedata-save and recreate it on demand.
E.g. I create the search index of the I18N Search plugin, when a user searches the first time.
Posts: 1,108
Threads: 70
Joined: Aug 2009
latest version 2.1 of the PageCaching/indexing plugin
Updates:
o - Changed plugin to use header hook
o - fixed a bug in retrunPageField if field was content
o - added hook to allow other plugin to cache their data
Posts: 3,491
Threads: 106
Joined: Mar 2010
n00dles101 Wrote:o - Changed plugin to use header hook
Now the index is being rewritten on every backend's page you browse... That's not what I meant.
I think you may check for parameter upd=edit-success (saving, restoring and deleting pages)
Posts: 1,108
Threads: 70
Joined: Aug 2009
Tks Carlos, version 2.2 now up in Extend which checks for 'edit-success' and writes the file.
Posts: 3,491
Threads: 106
Joined: Mar 2010
Great, Mike. Tested, works perfect (BTW I suggest you edit the Extend info about the plugin: it is compatible up to 3.0)
But... would you please change "pubdate" to GS's "pubDate"?
Posts: 290
Threads: 26
Joined: Oct 2010
Hey Mike - any chance of adding an "echoPageField" just as a convenience to theme builders?
Also, I haven't yet played too much, but should you have a
Code: stripslashes(htmlspecialchars_decode($whatever, ENT_QUOTES));
on the title, meta, and metad fields?
Thanks,
-Rob A>
Posts: 1,108
Threads: 70
Joined: Aug 2009
Thanks for the feedback guys...
Version 2.3 Update
o - All value now use strip_decode before outputting
o - Added alias function 'echoPageField' which is an alias for 'getPageField'
o - changed pubdate to pubDate
Posts: 1,928
Threads: 88
Joined: Apr 2010
Code: 503 Service Unavailable
The server is temporarily busy, try again later!
Posts: 1,108
Threads: 70
Joined: Aug 2009
@oleg06, which server , yours ? Mine? Extend?
8)
Posts: 1,928
Threads: 88
Joined: Apr 2010
Strangely enough, after I deleted your new plugin and put the earlier version, and then again filled the new one, everything was fine.
I checked 2 times, the result is the same
Posts: 290
Threads: 26
Joined: Oct 2010
Mike-
Any change of updating this to use zlib compression on the pages.array file? xml compresses so nicely...
-Rob A>
|