Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Page Caching Plugin
#1
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/
My Github Repos: Github
Website: DigiMute
Reply
#2
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);
        }        
    }
My Github Repos: Github
Website: DigiMute
Reply
#3
n00dles101 Wrote:Another Page Caching plugin !! Well sort of.

"Page Indexing", I would suggest...

Thanks for sharing it!
Reply
#4
Mike, am I right that your menu function is 1 lvl deep (parent+1st child) ?
Addons: blue business theme, Online Visitors, Notepad
Reply
#5
@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;
    }        
}
My Github Repos: Github
Website: DigiMute
Reply
#6
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 Smile
Addons: blue business theme, Online Visitors, Notepad
Reply
#7
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.
Reply
#8
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.
Reply
#9
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...
My Github Repos: Github
Website: DigiMute
Reply
#10
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.)
Reply
#11
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.
I18N, I18N Search, I18N Gallery, I18N Special Pages - essential plugins for multi-language sites.
Reply
#12
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
My Github Repos: Github
Website: DigiMute
Reply
#13
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)
Reply
#14
Tks Carlos, version 2.2 now up in Extend which checks for 'edit-success' and writes the file.
My Github Repos: Github
Website: DigiMute
Reply
#15
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"?
Reply
#16
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>
Reply
#17
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
My Github Repos: Github
Website: DigiMute
Reply
#18
Code:
503 Service Unavailable
The server is temporarily busy, try again later!
Reply
#19
@oleg06, which server , yours ? Mine? Extend?

8)
My Github Repos: Github
Website: DigiMute
Reply
#20
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
Reply
#21
Mike-

Any change of updating this to use zlib compression on the pages.array file? xml compresses so nicely...

-Rob A>
Reply




Users browsing this thread: 1 Guest(s)