| 
 
I Want To Create A Module

Well, it's simple.  First, give your module a name.  (We'll call ours "test_mod").  Now, create the main file ".php", and put a class in it called pagecache_mod_.  Now, there are 5 different triggers (enable, clear, store, process, afterStore), which are done at different times.  Each one should have it's own method (named the same as the trigger) in this class.  Each method should have 2 arguments (&$data, &$info).  Each method should return an array($data, $info). 

Each trigger looks for different data in the return.
  • Enable triggers look for the return to be either array(true,xxx) or array(false,xxx) (xxx doesn't matter).  True allows the component to continue processing, False tells it not to cache this page.
  • Clear triggers don't look at the return at all.  You must call the appropriate backend yourself (so if you want to delete a page, call pagecache_backend::delete($name), or to clear the cache pagecache_backend::clear())
  • Store triggers pass the body of the HTML page, and the $info array before the page is stored. It expects both back.  If you add anything to the $info array, it'll store it with the page.  If you set $info['ttl'] = 0, it'll cancel the caching of the page.
  • AfterStore triggers pass the body of the HTML page, and the $info array, but only needs the body back.  This is usefull for modifing the display page without affecting the cached version.
  • Process triggers pass the body and $info array when a cached page is about to be displayed.  This is useful for modifing the display page without affecting the cached version.

So, in our test module, we'll create two methods, Enable and Store.  Here's our file

<?php
defined('_VALID_MOS') or die('Direct Access Is Not Permitted');

class pagecache_mod_test_mod {
	
	function enable(&$data, &$info) {
		global $database;
                  $sql = "SELECT value FROM #__pagecache_test_mod WHERE pub = 1";
                  $database->setQuery($sql);
                  $dump = $database->loadObjectList();
		if(is_array($dump)) {
	       	foreach($dump as $value2) {
               	if(False!==strpos(_pagecache_current_page,$value2->value)) return(array(false,false));       
            }
        }
		return array(true,true);
	}

	function store(&$data, &$info) {
		global $database;
                  $sql = "SELECT value FROM #__pagecache_test_mod WHERE pub = 1";
                  $database->setQuery($sql);
                  $dump = $database->loadObjectList();
		if(is_array($dump)) {
	       	foreach($dump as $value2) {
            	if(strpos($data,$value2->value)!== false ) $data = str_replace($value2->value,"{$value2->value}",$data);
            }
        }
		return array("data"=>$data, "info"=>$info);
	}
}

Now, we can optionally create a backend for the module (if you need it).  If you are, it needs to be named "admin..php".  Now, the variables are set as follows ($option=com_pagecache, $act=modules, $element=).  $task will be dependant on the toolbar item clicked within the module admin ("publish", "unpublish", "new", "edit", "delete" are available).  The file is included linearly (meaning that there's nothing special about the file, it's just like any other Joomla admin file).

 So, now that we have a front end file, we need an install file. If you're not including an admin file, then leave the out.  This is pretty simple, so here it goes:



	test_mod
	Your Name
	GNU/GPL
	xxxxx
	Whatever it does!!!

	test_mod.php
	admin.test_mod.php

	
		DROP TABLE IF EXISTS #__pagecache_test_mod
		CREATE TABLE `#__pagecache_test_mod` (
			  `id` int(11) NOT NULL auto_increment,
			  `value` varchar(256) collate latin1_general_ci NOT NULL,
			  `pub` tinyint(4) NOT NULL default '0',
			  `desc` text collate latin1_general_ci NOT NULL,
			  PRIMARY KEY  (`id`),
			  UNIQUE KEY `value` (`value`),
			) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci
		DROP TABLE IF EXISTS #__pagecache_test_mod
	

	
		enable
		store
	


As you can see, this is a little different from a standard Joomla install file.  Note and , as well as  vs.  (unquery is called upon uninstallation of the module). 

Tags
100,00% of 1 voters found this FAQ useful,  I found this FAQ  useful useful  not useful not useful
< Prev   Next >
feed image
Copyright 2007 Anthony Ferrara, All Rights Reserved