ocPortal Developer's Guide: Zones, pages, modules, hooks and blocks
» Return to Contents
Oh crikey, all that terminology! If you don't know any of these terms, please read the glossary.
Zones are a new concept to ocPortal that make it so much more flexible than the original version. Zones are 'page spaces', that are stored in a subdirectory of the main site (or for the Welcome Zone, the main directory).
New zones may be created to wrap collections of pages for a large MOD; a good example of the use of a zone is the CEDI zone, which wraps the whole CEDI system together.
Modules and blocks will upgrade themselves if it is detected that the installed version is older than the version on-disk.
Modules and blocks all contain and info method, that returns an array of information that contains the following attributes:
- author, the primary author of the resource
- organisation, the primary organisation of the resource
- version, the version number of this resource
- hacked_by, the person who has 'hacked' (modded) this resource, or NULL if it is 'pure'
- hack_version, the version number of the 'hack' by this 'hacker', or NULL
- locked, true if this resource may never be uninstalled
- update_require_upgrade, set this to anything if the resource requires upgrading from previous versions (i.e. it is not the first version, and it requires to run upgrade code to update previous versions database records)
- hack_require_upgrade, this is equivalent to the above, but applies to the truth for the hacked version rather than the original resource
Please note that version numbers must be integers. i.e. The sequence must only involve whole numbers (1,2,3,4…)
You may create a 'minimodule' instead of a full module, and just echo out your output. Most developers will find this preferable. The same goes for a miniblock instead of a block.
sources/zones.php
Global_functions_zones.php
Function summary
|
void
|
init__zones ()
|
|
PATH
|
zone_black_magic_filterer (PATH path, boolean relative)
|
|
ID_TEXT
|
get_zone_name ()
|
|
?ID_TEXT
|
get_module_zone (ID_TEXT module_name, ID_TEXT type, ?string dir2, string ftype, boolean error)
|
|
?ID_TEXT
|
get_comcode_zone (ID_TEXT page_name, boolean error)
|
|
?ID_TEXT
|
get_page_zone (ID_TEXT page_name, boolean error)
|
|
tempcode
|
load_minimodule_page (PATH string)
|
|
tempcode
|
load_module_page (PATH string, ID_TEXT codename)
|
|
array
|
find_all_zones (boolean search, boolean get_titles, boolean force_all, integer start, integer max)
|
|
void
|
cache_module_installed_status ()
|
|
boolean
|
module_installed (ID_TEXT module)
|
|
PATH
|
_get_module_path (ID_TEXT zone, ID_TEXT module)
|
|
array
|
find_all_hooks (ID_TEXT type, ID_TEXT entry)
|
|
tempcode
|
do_block (ID_TEXT codename, ?array map, ?integer ttl)
|
|
string
|
block_params_arr_to_str (array map)
|
|
mixed
|
do_block_hunt_file (ID_TEXT codename, ?array map)
|
|
?LONG_TEXT
|
do_block_get_cache_identifier (mixed cache_on, ?array map)
|
|
PATH
|
_get_block_path (ID_TEXT block)
|
|
boolean
|
block_installed (ID_TEXT block)
|
|
array
|
find_all_pages_wrap (ID_TEXT zone, boolean keep_ext_on, boolean consider_redirects, integer show_method, ?ID_TEXT page_type)
|
|
array
|
find_all_pages (ID_TEXT zone, ID_TEXT type, string ext, boolean keep_ext_on, ?TIME cutoff_time, integer show_method)
|
|
array
|
find_all_modules (ID_TEXT zone)
|
|
array
|
extract_module_functions (PATH path, array functions, ?array params)
|
void init__zones()
Standard code module initialisation function.
Parameters…
(No return value)
function init__zones()
{
global $CACHE_ON,$CLASS_CACHE;
$CACHE_ON=NULL;
$CLASS_CACHE=array();
global $ARB_COUNTER;
$ARB_COUNTER=1;
global $DO_NOT_CACHE_THIS;
$DO_NOT_CACHE_THIS=false;
global $MODULES_ZONES,$MODULES_ZONES_DEFAULT;
$MODULES_ZONES=function_exists('persistant_cache_get')?persistant_cache_get('MODULES_ZONES'):NULL;
global $SITE_INFO;
$hardcoded=(isset($SITE_INFO['hardcode_common_module_zones'])) && ($SITE_INFO['hardcode_common_module_zones']=='1');
if (get_forum_type()=='ocf')
{
if ($hardcoded)
{
$MODULES_ZONES_DEFAULT=array( // Breaks redirects etc, but handy optimisation if you have a vanilla layout
'forumview'=>'forum',
'topicview'=>'forum',
'topics'=>'forum',
'vforums'=>'forum',
'points'=>'site',
'members'=>'site',
'catalogues'=>'site',
'join'=>'',
'login'=>'',
'recommend'=>'',
);
} else
{
$MODULES_ZONES_DEFAULT=array(
'join'=>'',
'login'=>'',
);
}
} else
{
$MODULES_ZONES_DEFAULT=array(
'join'=>'',
);
}
global $VIRTUALISED_ZONES;
$VIRTUALISED_ZONES=NULL;
if (is_null($MODULES_ZONES))
{
foreach ($MODULES_ZONES_DEFAULT as $key=>$val)
{
if ((!$hardcoded) && (!is_file(get_file_base().'/'.$val.'/pages/modules/'.$key.'.php')))
{
unset($MODULES_ZONES_DEFAULT[$key]);
}
}
$MODULES_ZONES=$MODULES_ZONES_DEFAULT;
}
global $ALL_ZONES,$ALL_ZONES_TITLED;
$ALL_ZONES=NULL;
$ALL_ZONES_TITLED=NULL;
global $MODULE_INSTALLED_CACHE;
$MODULE_INSTALLED_CACHE=array();
global $HOOKS_CACHE;
$HOOKS_CACHE=function_exists('persistant_cache_get')?persistant_cache_get('HOOKS'):array();
if ($HOOKS_CACHE===NULL) $HOOKS_CACHE=array();
define('FIND_ALL_PAGES__PERFORMANT',0);
define('FIND_ALL_PAGES__NEWEST',1);
define('FIND_ALL_PAGES__ALL',2);
global $BLOCKS_AT_CACHE;
$BLOCKS_AT_CACHE=function_exists('persistant_cache_get')?persistant_cache_get('BLOCKS_AT'):array();
if ($BLOCKS_AT_CACHE===NULL) $BLOCKS_AT_CACHE=array();
}
PATH zone_black_magic_filterer(PATH path, boolean relative)
Consider virtual zone merging, where paths are not necessarily where you'd expect for pages in zones.
Parameters…
| Name |
path |
| Description |
The path, assuming in the obvious place. |
| Type |
PATH |
| Name |
relative |
| Description |
Where the passed path is relative. |
| Default value |
boolean-false |
| Type |
boolean |
Returns…
| Description |
The fixed path. |
| Type |
PATH |
function zone_black_magic_filterer($path,$relative=false)
{
static $no_collapse_zones=NULL;
if ($no_collapse_zones===NULL) $no_collapse_zones=(get_option('collapse_user_zones',true)!=='1');
if ($no_collapse_zones) return $path;
static $zbmf_cache=array();
if (isset($zbmf_cache[$path])) return $zbmf_cache[$path];
if ($relative)
{
$stripped=$path;
} else
{
$cfb=get_custom_file_base();
if (substr($path,0,strlen($cfb))==$cfb)
{
$stripped=substr($path,strlen($cfb)+1);
} else
{
$fb=get_file_base();
$stripped=substr($path,strlen($fb)+1);
}
}
if ($stripped!='')
{
if ($stripped[0]=='/') $stripped=substr($stripped,1);
if (($stripped[0]=='p') && (substr($stripped,0,6)=='pages/')) // Ah, need to do some checks as we are looking in the welcome zone
{
$full=$relative?(get_file_base().'/'.$path):$path;
if (!is_file($full))
{
$site_equiv=get_file_base().'/site/'.$stripped;
if (is_file($site_equiv))
{
$ret=$relative?('site/'.$stripped):$site_equiv;
$zbmf_cache[$path]=$ret;
return $ret;
}
}
}
}
$zbmf_cache[$path]=$path;
return $path;
}
ID_TEXT get_zone_name()
Get the name of the zone the current page request is coming from.
Parameters…
Returns…
| Description |
The current zone |
| Type |
ID_TEXT |
function get_zone_name()
{
global $ZONE,$RELATIVE_PATH,$SITE_INFO,$VIRTUALISED_ZONES;
if ($ZONE!==NULL) return $ZONE['zone_name'];
if ($VIRTUALISED_ZONES!==false)
{
$VIRTUALISED_ZONES=false;
$url_path=dirname(ocp_srv('REQUEST_URI'));
foreach ($SITE_INFO as $key=>$val)
{
if (($key[0]=='Z') && (substr($key,0,13))=='ZONE_MAPPING_')
{
$VIRTUALISED_ZONES=true;
if ((preg_replace('#:\d+$#','',ocp_srv('HTTP_HOST'))==$val[0]) && (preg_match('#^'.(($val[1]=='')?'':('/'.preg_quote($val[1]))).'(/|$)#',$url_path)!=0))
return substr($key,13);
}
}
}
$real_zone=(($RELATIVE_PATH=='data') || ($RELATIVE_PATH=='data_custom'))?get_param('zone',''):$RELATIVE_PATH;
return $real_zone;
}
?ID_TEXT get_module_zone(ID_TEXT module_name, ID_TEXT type, ?string dir2, string ftype, boolean error)
Find the zone a page is in.
Parameters…
| Name |
module_name |
| Description |
The page name to find |
| Type |
ID_TEXT |
| Name |
type |
| Description |
The type of the page we are looking for |
| Default value |
modules |
| Type |
ID_TEXT |
| Name |
dir2 |
| Description |
The special subcategorisation of page we are looking for (e.g. 'EN' for a comcode page) (NULL: none) |
| Default value |
|
| Type |
?string |
| Name |
ftype |
| Description |
The file extension for the page type |
| Default value |
php |
| Type |
string |
| Name |
error |
| Description |
Whether ocPortal should bomb out if the page was not found |
| Default value |
boolean-true |
| Type |
boolean |
Returns…
| Description |
The zone the page is in (NULL: not found) |
| Type |
?ID_TEXT |
function get_module_zone($module_name,$type='modules',$dir2=NULL,$ftype='php',$error=true)
{
global $MODULES_ZONES;
if ((isset($MODULES_ZONES[$module_name])) || ((!$error) && (array_key_exists($module_name,$MODULES_ZONES)) && ($type=='modules')/*don't want to look at cached failure for different page type*/))
{
return $MODULES_ZONES[$module_name];
}
$error=false; // hack for now
$zone=get_zone_name();
if (($module_name==get_page_name()) && (running_script('index')) && ($module_name!='login'))
{
$MODULES_ZONES[$module_name]=$zone;
return $zone;
}
if (($type=='modules') && (substr($module_name,0,6)=='admin_'))
{
$zone='adminzone';
$MODULES_ZONES[$module_name]=$zone;
return $zone;
}
if (($type=='modules') && (substr($module_name,0,4)=='cms_'))
{
$zone='cms';
$MODULES_ZONES[$module_name]=$zone;
return $zone;
}
global $REDIRECT_CACHE;
$first_zones=array((substr($module_name,0,6)=='admin_')?'adminzone':$zone);
if ($zone!='') $first_zones[]='';
if (($zone!='site')/* && (is_file(get_file_base().'/site/index.php'))*/) $first_zones[]='site';
foreach ($first_zones as $zone)
{
if ((isset($REDIRECT_CACHE[$zone][$module_name])) && ($REDIRECT_CACHE[$zone][$module_name]['r_is_transparent']==1)) // Only needs to actually look for redirections in first zones until end due to the way precedences work (we know the current zone will be in the first zones)
{
$MODULES_ZONES[$module_name]=$zone;
if (function_exists('persistant_cache_set')) persistant_cache_set('MODULES_ZONES',$MODULES_ZONES);
return $zone;
}
if ((is_file(zone_black_magic_filterer(get_file_base().'/'.$zone.'/pages/'.$type.'/'.(($dir2===NULL)?'':($dir2.'/')).$module_name.'.'.$ftype)))
|| (is_file(zone_black_magic_filterer(get_file_base().'/'.$zone.'/pages/'.$type.'_custom/'.(($dir2===NULL)?'':($dir2.'/')).$module_name.'.'.$ftype))))
{
if ((isset($REDIRECT_CACHE[$zone][$module_name])) && ($REDIRECT_CACHE[$zone][$module_name]['r_is_transparent']==0) && ($REDIRECT_CACHE[$zone][$module_name]['r_to_page']==$module_name)) $zone=$REDIRECT_CACHE[$zone][$module_name]['r_to_zone'];
$MODULES_ZONES[$module_name]=$zone;
if (function_exists('persistant_cache_set')) persistant_cache_set('MODULES_ZONES',$MODULES_ZONES);
return $zone;
}
}
$zones=find_all_zones();
foreach ($zones as $zone)
{
if (!in_array($zone,$first_zones))
{
if ((is_file(zone_black_magic_filterer(get_file_base().'/'.$zone.'/pages/'.$type.'/'.(($dir2===NULL)?'':($dir2.'/')).$module_name.'.'.$ftype)))
|| (is_file(zone_black_magic_filterer(get_file_base().'/'.$zone.'/pages/'.$type.'_custom/'.(($dir2===NULL)?'':($dir2.'/')).$module_name.'.'.$ftype))))
{
if ((isset($REDIRECT_CACHE[$zone][$module_name])) && ($REDIRECT_CACHE[$zone][$module_name]['r_is_transparent']==0) && ($REDIRECT_CACHE[$zone][$module_name]['r_to_page']==$module_name)) $zone=$REDIRECT_CACHE[$zone][$module_name]['r_to_zone'];
$MODULES_ZONES[$module_name]=$zone;
if (function_exists('persistant_cache_set')) persistant_cache_set('MODULES_ZONES',$MODULES_ZONES);
return $zone;
}
}
}
foreach ($zones as $zone) // Okay, finally check for redirects
{
if ((isset($REDIRECT_CACHE[$zone][$module_name])) && ($REDIRECT_CACHE[$zone][$module_name]['r_is_transparent']==1))
{
$MODULES_ZONES[$module_name]=$zone;
if (function_exists('persistant_cache_set')) persistant_cache_set('MODULES_ZONES',$MODULES_ZONES);
return $zone;
}
}
if (!$error)
{
$MODULES_ZONES[$module_name]=NULL;
return NULL;
}
warn_exit(do_lang_tempcode('MISSING_MODULE_REFERENCED',$module_name));
}
?ID_TEXT get_comcode_zone(ID_TEXT page_name, boolean error)
Find the zone a comcode page is in.
Parameters…
| Name |
page_name |
| Description |
The comcode page name to find |
| Type |
ID_TEXT |
| Name |
error |
| Description |
Whether ocPortal should bomb out if the page was not found |
| Default value |
boolean-true |
| Type |
boolean |
Returns…
| Description |
The zone the comcode page is in (NULL: missing) |
| Type |
?ID_TEXT |
function get_comcode_zone($page_name,$error=true)
{
$test=get_module_zone($page_name,'comcode',user_lang(),'txt',false);
if (!is_null($test)) return $test;
$test=get_module_zone($page_name,'comcode',get_site_default_lang(),'txt',false);
if (!is_null($test)) return $test;
$test=get_module_zone($page_name,'comcode',fallback_lang(),'txt',false);
if (!is_null($test)) return $test;
if ($error) warn_exit(do_lang_tempcode('MISSING_MODULE_REFERENCED',$page_name));
return NULL;
}
?ID_TEXT get_page_zone(ID_TEXT page_name, boolean error)
Find the zone a page is in.
Parameters…
| Name |
page_name |
| Description |
The page name to find |
| Type |
ID_TEXT |
| Name |
error |
| Description |
Whether ocPortal should bomb out if the page was not found |
| Default value |
boolean-true |
| Type |
boolean |
Returns…
| Description |
The zone the page is in (NULL: missing) |
| Type |
?ID_TEXT |
function get_page_zone($page_name,$error=true)
{
$test=get_module_zone($page_name,'modules',NULL,'php',false);
if (!is_null($test)) return $test;
$test=get_module_zone($page_name,'comcode',get_site_default_lang(),'txt',false);
if (!is_null($test)) return $test;
$test=get_module_zone($page_name,'comcode',fallback_lang(),'txt',false);
if (!is_null($test)) return $test;
$test=get_module_zone($page_name,'html',get_site_default_lang(),'htm',false);
if (!is_null($test)) return $test;
$test=get_module_zone($page_name,'html',fallback_lang(),'htm',false);
if (!is_null($test)) return $test;
$test=get_module_zone($page_name,'minimodules',NULL,'php',false);
if (!is_null($test)) return $test;
if ($error) warn_exit(do_lang_tempcode('MISSING_MODULE_REFERENCED',$page_name));
return NULL;
}
tempcode load_minimodule_page(PATH string)
Runs the specified mini-module.The module result is returned.
Parameters…
| Name |
string |
| Description |
The relative path to the module file |
| Type |
PATH |
Returns…
| Description |
The result of executing the module |
| Type |
tempcode |
function load_minimodule_page($string)
{
global $PAGE_STRING;
if (is_null($PAGE_STRING)) $PAGE_STRING=$string;
require_code('developer_tools');
destrictify();
ob_start();
require_code(filter_naughty($string));
$out=new ocp_tempcode();
$out->attach(ob_get_contents());
ob_end_clean();
restrictify();
return $out;
}
tempcode load_module_page(PATH string, ID_TEXT codename)
Runs the specified module, but also update any stats for the module, and check to see if it needs upgrading or reinstalling.The module result is returned.
Parameters…
| Name |
string |
| Description |
The relative path to the module file |
| Type |
PATH |
| Name |
codename |
| Description |
The page name to load |
| Type |
ID_TEXT |
Returns…
| Description |
The result of executing the module |
| Type |
tempcode |
function load_module_page($string,$codename)
{
global $PAGE_STRING;
if (is_null($PAGE_STRING)) $PAGE_STRING=$string;
require_code(filter_naughty($string));
if (class_exists('Mx_'.filter_naughty_harsh($codename)))
{
$object=object_factory('Mx_'.filter_naughty_harsh($codename));
} else
{
$object=object_factory('Module_'.filter_naughty_harsh($codename));
}
// Get info about what is installed and what is on disk
$rows=$GLOBALS['SITE_DB']->query_select('modules',array('*'),array('module_the_name'=>$codename),'',1);
if (array_key_exists(0,$rows))
{
$info=$object->info();
$installed_version=$rows[0]['module_version'];
$installed_hack_version=$rows[0]['module_hack_version'];
$installed_hacked_by=$rows[0]['module_hacked_by'];
if (is_null($installed_hacked_by)) $installed_hacked_by='';
$this_version=$info['version'];
$this_hack_version=$info['hack_version'];
$this_hacked_by=$info['hacked_by'];
if (is_null($this_hacked_by)) $this_hacked_by='';
// See if we need to do an upgrade
if (($installed_version<$this_version) && (array_key_exists('update_require_upgrade',$info)))
{
require_code('database_action');
require_code('config2');
require_code('menus2');
$GLOBALS['SITE_DB']->query_update('modules',array('module_version'=>$this_version,'module_hack_version'=>$this_hack_version,'module_hacked_by'=>$this_hacked_by),array('module_the_name'=>$codename),'',1); // Happens first so if there is an error it won't loop (if we updated install code manually there will be an error)
$object->install($installed_version,$installed_hack_version,$installed_hacked_by);
}
elseif (($installed_hack_version<$this_hack_version) && (array_key_exists('hack_require_upgrade',$info)))
{
require_code('database_action');
require_code('config2');
require_code('menus2');
/* if (($installed_hacked_by!=$this_hacked_by) && (!is_null($installed_hacked_by)))
{
fatal_exit();
} Probably better we leave the solution to this to modders rather than just block the potential for there even to be a solution */
$GLOBALS['SITE_DB']->query_update('modules',array('module_version'=>$this_version,'module_hack_version'=>$this_hack_version,'module_hacked_by'=>$this_hacked_by),array('module_the_name'=>$codename),'',1);
$object->install($installed_version,$installed_hack_version,$installed_hacked_by);
}
} else
{
require_code('zones2');
$zone=substr($string,0,strpos($string,'/'));
if ($zone=='pages') $zone='';
reinstall_module($zone,$codename);
}
return $object->run();
}
array find_all_zones(boolean search, boolean get_titles, boolean force_all, integer start, integer max)
Find the installed zones, up to the first $max installed
Parameters…
| Name |
search |
| Description |
Whether to search the file system and return zones that might not be fully in the system (otherwise will just use the database) |
| Default value |
boolean-false |
| Type |
boolean |
| Name |
get_titles |
| Description |
Whether to get titles for the zones as well. Only if !$search |
| Default value |
boolean-false |
| Type |
boolean |
| Name |
force_all |
| Description |
Whether to insist on getting all zones (there could be thousands in theory...) |
| Default value |
boolean-false |
| Type |
boolean |
| Name |
start |
| Description |
Start position to get results from |
| Default value |
0 |
| Type |
integer |
| Name |
max |
| Description |
Maximum zones to get |
| Default value |
50 |
| Type |
integer |
Returns…
| Description |
A list of zone names / a list of quartets (name, title, show in menu, default page) |
| Type |
array |
function find_all_zones($search=false,$get_titles=false,$force_all=false,$start=0,$max=50)
{
if ($search)
{
$out=array('');
$dh=opendir(get_file_base());
while (($file=readdir($dh))!==false)
{
if (($file!='.') && ($file!='..') && (is_dir($file)) && (is_readable(get_file_base().'/'.$file)) && (is_file(get_file_base().'/'.$file.'/index.php')) && (is_dir(get_file_base().'/'.$file.'/pages/modules')))
{
if ((get_option('collapse_user_zones',true)==='1') && ($file=='site')) continue;
$out[]=$file;
if ((!$force_all) && (count($out)==$max)) break;
}
}
closedir($dh);
return $out;
}
global $ALL_ZONES,$ALL_ZONES_TITLED,$SITE_INFO;
if ($get_titles)
{
if ($ALL_ZONES_TITLED===NULL) $ALL_ZONES_TITLED=function_exists('persistant_cache_get')?persistant_cache_get('ALL_ZONES_TITLED'):NULL;
if ($ALL_ZONES_TITLED!==NULL) return $ALL_ZONES_TITLED;
} else
{
if ($ALL_ZONES===NULL) $ALL_ZONES=function_exists('persistant_cache_get')?persistant_cache_get('ALL_ZONES'):NULL;
if ($ALL_ZONES!==NULL) return $ALL_ZONES;
}
$rows=$GLOBALS['SITE_DB']->query_select('zones',array('*','zone_title AS _zone_title'),NULL,'ORDER BY zone_name',$force_all?NULL:$max,$start);
if ((!$force_all) && (count($rows)==$max))
{
$rows=$GLOBALS['SITE_DB']->query_select('zones',array('*','zone_title AS _zone_title'),NULL,'ORDER BY zone_title',$max/*reasonable limit; zone_title is sequential for default zones*/);
}
$zones_titled=array();
$zones=array();
foreach ($rows as $zone)
{
if ((get_option('collapse_user_zones',true)==='1') && ($zone['zone_name']=='site')) continue;
$zone['zone_title']=get_translated_text($zone['_zone_title']);
$folder=get_file_base().'/'.$zone['zone_name'].'/pages';
if (((isset($SITE_INFO['no_disk_sanity_checks'])) && ($SITE_INFO['no_disk_sanity_checks']=='1')) || (is_file(get_file_base().'/'.$zone['zone_name'].'/index.php')))
{
$zones[]=$zone['zone_name'];
$zones_titled[$zone['zone_name']]=array($zone['zone_name'],$zone['zone_title'],array_key_exists('zone_displayed_in_menu',$zone)?$zone['zone_displayed_in_menu']:1,$zone['zone_default_page'],$zone);
}
}
$ALL_ZONES_TITLED=$zones_titled;
if (function_exists('persistant_cache_set')) persistant_cache_set('ALL_ZONES_TITLED',$ALL_ZONES_TITLED);
$ALL_ZONES=$zones;
if (function_exists('persistant_cache_set')) persistant_cache_set('ALL_ZONES',$ALL_ZONES);
return $get_titles?$zones_titled:$zones;
}
void cache_module_installed_status()
Look up and remember what modules are installed.
Parameters…
(No return value)
function cache_module_installed_status()
{
global $MODULE_INSTALLED_CACHE;
$rows=$GLOBALS['SITE_DB']->query_select('modules',array('module_the_name'));
foreach ($rows as $row)
{
$MODULE_INSTALLED_CACHE[$row['module_the_name']]=true;
}
}
boolean module_installed(ID_TEXT module)
Check to see if a module is installed.
Parameters…
| Name |
module |
| Description |
The module name |
| Type |
ID_TEXT |
Returns…
| Description |
Whether it is |
| Type |
boolean |
function module_installed($module)
{
global $MODULE_INSTALLED_CACHE;
if (array_key_exists($module,$MODULE_INSTALLED_CACHE)) return $MODULE_INSTALLED_CACHE[$module];
$test=$GLOBALS['SITE_DB']->query_value_null_ok('modules','module_the_name',array('module_the_name'=>$module));
$answer=!is_null($test);
$MODULE_INSTALLED_CACHE[$module]=$answer;
return $answer;
}
PATH _get_module_path(ID_TEXT zone, ID_TEXT module)
Get the path to a module known to be in a certain zone.
Parameters…
| Name |
zone |
| Description |
The zone name |
| Type |
ID_TEXT |
| Name |
module |
| Description |
The module name |
| Type |
ID_TEXT |
Returns…
| Description |
The module path |
| Type |
PATH |
function _get_module_path($zone,$module)
{
$module_path=zone_black_magic_filterer(($zone=='')?('pages/modules_custom/'.filter_naughty_harsh($module).'.php'):(filter_naughty($zone).'/pages/modules_custom/'.filter_naughty_harsh($module).'.php'),true);
if (!is_file(get_file_base().'/'.$module_path))
{
$module_path=zone_black_magic_filterer(($zone=='')?('pages/modules/'.filter_naughty_harsh($module).'.php'):(filter_naughty($zone).'/pages/modules/'.filter_naughty_harsh($module).'.php'),true);
}
return $module_path;
}
array find_all_hooks(ID_TEXT type, ID_TEXT entry)
Get an array of all the hook implementations for a hook class.
Parameters…
| Name |
type |
| Description |
The type of hook |
| Type |
ID_TEXT |
| Values restricted to |
blocks modules systems |
| Name |
entry |
| Description |
The hook class to find hook implementations for (e.g. the name of a module) |
| Type |
ID_TEXT |
Returns…
| Description |
A map of hook implementation name to [sources|sources_custom] |
| Type |
array |
function find_all_hooks($type,$entry)
{
global $HOOKS_CACHE;
if (isset($HOOKS_CACHE[$type.'/'.$entry])) return $HOOKS_CACHE[$type.'/'.$entry];
$out=array();
$dir=get_file_base().'/sources/hooks/'.filter_naughty($type).'/'.filter_naughty($entry);
$dh=@opendir($dir);
if ($dh!==false)
{
while (($file=readdir($dh))!==false)
{
$basename=basename($file,'.php');
if (($file==$basename.'.php') && (preg_match('#^[\w\-]*$#',$basename)!=0))
{
// if ((filesize($dir.'/'.$file)>0) && (substr($file,0,4)!='ocf_'))
$out[$basename]='sources';
}
}
closedir($dh);
}
if (!in_safe_mode())
{
$dir=get_file_base().'/sources_custom/hooks/'.filter_naughty($type).'/'.filter_naughty($entry);
$dh=@opendir($dir);
if ($dh!==false)
{
while (($file=readdir($dh))!==false)
{
$basename=basename($file,'.php');
if (($file==$basename.'.php') && (preg_match('#^[\w\-]*$#',$basename)!=0))
{
// if ((filesize($dir.'/'.$file)>0) && (substr($file,0,4)!='ocf_'))
$out[$basename]='sources_custom';
}
}
closedir($dh);
}
}
// Optimisation, so that hooks with same name as our page get loaded first
$page=get_param('page','',true);
if (array_key_exists($page,$out))
{
$_out=array($page=>$out[$page]);
unset($out[$page]);
$out=array_merge($_out,$out);
}
$HOOKS_CACHE[$type.'/'.$entry]=$out;
if (function_exists('persistant_cache_set')) persistant_cache_set('HOOKS',$HOOKS_CACHE,true);
return $out;
}
tempcode do_block(ID_TEXT codename, ?array map, ?integer ttl)
Get the processed tempcode for the specified block. Please note that you pass multiple parameters in as an array, but single parameters go in as a string or other flat variable.
Parameters…
| Name |
codename |
| Description |
The block name |
| Type |
ID_TEXT |
| Name |
map |
| Description |
The block parameter map (NULL: no parameters) |
| Default value |
|
| Type |
?array |
| Name |
ttl |
| Description |
The TTL to use in minutes (NULL: block default) |
| Default value |
|
| Type |
?integer |
Returns…
| Description |
The generated tempcode |
| Type |
tempcode |
function do_block($codename,$map=NULL,$ttl=NULL)
{
global $LANGS_REQUESTED,$JAVASCRIPTS,$CSSS,$DO_NOT_CACHE_THIS;
$DO_NOT_CACHE_THIS=false;
if ((cron_installed()) && (running_script('index')))
{
if ($codename=='side_weather' || $codename=='side_rss' || $codename=='main_rss') // Special cases to stop external dependencies causing issues
{
$map['cache']='2';
}
}
$object=NULL;
if (((get_option('is_on_block_cache')=='1') || (get_param_integer('keep_cache',0)==1) || (get_param_integer('cache',0)==1) || (get_param_integer('cache_blocks',0)==1)) && ((get_param_integer('keep_cache',NULL)!==0) && (get_param_integer('cache_blocks',NULL)!==0) && (get_param_integer('cache',NULL)!==0)) && (strpos(get_param('special_page_type',''),'t')===false))
{
// See if the block may be cached (else cannot, or is yet unknown)
if (($map!==NULL) && (isset($map['cache'])) && ($map['cache']=='0'))
{
$row=NULL;
} else // We may allow it to be cached but not store the cache signature, as it is too complex
{
$row=find_cache_on($codename);
if ($row===NULL)
{
$object=do_block_hunt_file($codename,$map);
if ((is_object($object)) && (method_exists($object,'cacheing_environment')))
{
$info=$object->cacheing_environment($map);
if ($info!==NULL)
$row=array('cached_for'=>$codename,'cache_on'=>$info['cache_on'],'cache_ttl'=>$info['ttl']);
}
}
if (($row===NULL) && ((isset($map['cache'])) && ($map['cache']=='1') || (isset($map['quick_cache'])) && ($map['quick_cache']=='1')))
{
$row=array('cached_for'=>$codename,'cache_on'=>'$map','cache_ttl'=>60);
}
}
if ($row!==NULL)
{
$cache_identifier=do_block_get_cache_identifier($row['cache_on'],$map);
// See if it actually is cached
if ($cache_identifier!==NULL)
{
if ($ttl===NULL) $ttl=$row['cache_ttl'];
$cache=get_cache_entry($codename,$cache_identifier,$ttl,true,(array_key_exists('cache',$map)) && ($map['cache']=='2'),$map);
if ($cache===NULL)
{
$nql_backup=$GLOBALS['NO_QUERY_LIMIT'];
$GLOBALS['NO_QUERY_LIMIT']=true;
if ($object!==NULL) $object=do_block_hunt_file($codename,$map);
if (!is_object($object))
{
// This probably happened as we uninstalled a block, and now we're getting a "missing block" message back.
if (!defined('HIPHOP_PHP'))
{
// Removed outdated cache-on information
$GLOBALS['SITE_DB']->query_delete('cache_on',array('cached_for'=>$codename),'',1);
persistant_cache_delete('CACHE_ON');
}
$out=new ocp_tempcode();
$out->attach($object);
return $out;
}
$backup_langs_requested=$LANGS_REQUESTED;
$backup_javascripts=$JAVASCRIPTS;
$backup_csss=$CSSS;
$LANGS_REQUESTED=array();
$JAVASCRIPTS=array('javascript'=>1,'javascript_thumbnails'=>1);
$CSSS=array('no_cache'=>1,'global'=>1);
$cache=$object->run($map);
$cache->handle_symbol_preprocessing();
if (!$DO_NOT_CACHE_THIS)
{
require_code('caches2');
if ((isset($map['quick_cache'])) && ($map['quick_cache']=='1') && (has_cookies())) $cache=make_string_tempcode($cache->evaluate());
put_into_cache($codename,$ttl,$cache_identifier,$cache,array_keys($LANGS_REQUESTED),array_keys($JAVASCRIPTS),array_keys($CSSS),true);
} elseif (($ttl!=-1) && ($cache->is_empty())) // Try again with no TTL, if we currently failed but did impose a TTL
{
$LANGS_REQUESTED+=$backup_langs_requested;
$JAVASCRIPTS+=$backup_javascripts;
$CSSS+=$backup_csss;
return do_block($codename,$map,-1);
}
$LANGS_REQUESTED+=$backup_langs_requested;
$JAVASCRIPTS+=$backup_javascripts;
$CSSS+=$backup_csss;
$GLOBALS['NO_QUERY_LIMIT']=$nql_backup;
}
return $cache;
}
}
}
// NB: If we've got this far cache="2" is ignored. But later on (for normal expiries, different contexts, etc) cache_on will be known so not an issue.
// We will need to load the actual file
if (is_null($object)) $object=do_block_hunt_file($codename,$map);
if (is_object($object))
{
if ($map===NULL) $map=array();
$nql_backup=$GLOBALS['NO_QUERY_LIMIT'];
$GLOBALS['NO_QUERY_LIMIT']=true;
$backup_langs_requested=$LANGS_REQUESTED;
$backup_javascripts=$JAVASCRIPTS;
$backup_csss=$CSSS;
$LANGS_REQUESTED=array();
$JAVASCRIPTS=array('javascript'=>1,'javascript_thumbnails'=>1);
$CSSS=array('no_cache'=>1,'global'=>1);
$cache=$object->run($map);
$GLOBALS['NO_QUERY_LIMIT']=$nql_backup;
} else
{
$out=new ocp_tempcode();
$out->attach($object);
return $out;
}
// May it be added to cache_on?
if ((!$DO_NOT_CACHE_THIS) && (method_exists($object,'cacheing_environment')) && ((get_option('is_on_block_cache')=='1') || (get_param_integer('keep_cache',0)==1) || (get_param_integer('cache_blocks',0)==1) || (get_param_integer('cache',0)==1)) && ((get_param_integer('keep_cache',NULL)!==0) && (get_param_integer('cache_blocks',NULL)!==0) && (get_param_integer('cache',NULL)!==0)))
{
$info=$object->cacheing_environment($map);
if ($info!==NULL)
{
$cache_identifier=do_block_get_cache_identifier($info['cache_on'],$map);
if ($cache_identifier!==NULL)
{
require_code('caches2');
put_into_cache($codename,$info['ttl'],$cache_identifier,$cache,array_keys($LANGS_REQUESTED),array_keys($JAVASCRIPTS),array_keys($CSSS),true);
if ((!defined('HIPHOP_PHP')) && (!is_array($info['cache_on'])))
{
$GLOBALS['SITE_DB']->query_insert('cache_on',array('cached_for'=>$codename,'cache_on'=>$info['cache_on'],'cache_ttl'=>$info['ttl']),false,true); // Allow errors in case of race conditions
}
}
}
}
$LANGS_REQUESTED+=$backup_langs_requested;
$JAVASCRIPTS+=$backup_javascripts;
$CSSS+=$backup_csss;
return $cache;
}
string block_params_arr_to_str(array map)
Convert a parameter set from a an array (for PHP code) to a string (for templates).
Parameters…
| Name |
map |
| Description |
The parameters / acceptable parameter pattern |
| Type |
array |
Returns…
| Description |
The parameters / acceptable parameter pattern, as template safe parameter |
| Type |
string |
function block_params_arr_to_str($map)
{
ksort($map);
$_map='';
foreach ($map as $key=>$val)
{
if ($_map!='') $_map.=',';
$_map.=$key.'='.str_replace(',','\,',$val);
}
return $_map;
}
mixed do_block_hunt_file(ID_TEXT codename, ?array map)
Get the block object for a given block codename.
Parameters…
| Name |
codename |
| Description |
The block name |
| Type |
ID_TEXT |
| Name |
map |
| Description |
The block parameter map (NULL: no parameters) |
| Default value |
|
| Type |
?array |
Returns…
| Description |
Either the block object, or the string output of a miniblock |
| Type |
mixed |
function do_block_hunt_file($codename,$map=NULL)
{
global $BLOCKS_AT_CACHE;
$codename=filter_naughty_harsh($codename);
$file_base=get_file_base();
global $_REQUIRED_CODE;
if (((isset($BLOCKS_AT_CACHE[$codename])) && ($BLOCKS_AT_CACHE[$codename]=='sources_custom/blocks')) || ((!isset($BLOCKS_AT_CACHE[$codename])) && (is_file($file_base.'/sources_custom/blocks/'.$codename.'.php'))))
{
if (!isset($_REQUIRED_CODE['blocks/'.$codename])) require_once($file_base.'/sources_custom/blocks/'.$codename.'.php');
$_REQUIRED_CODE['blocks/'.$codename]=1;
if (!isset($BLOCKS_AT_CACHE[$codename]))
{
$BLOCKS_AT_CACHE[$codename]='sources_custom/blocks';
if (function_exists('persistant_cache_set')) persistant_cache_set('BLOCKS_AT',$BLOCKS_AT_CACHE,true);
}
}
elseif (((isset($BLOCKS_AT_CACHE[$codename])) && ($BLOCKS_AT_CACHE[$codename]=='sources/blocks')) || ((!isset($BLOCKS_AT_CACHE[$codename])) && (is_file($file_base.'/sources/blocks/'.$codename.'.php'))))
{
if (!isset($_REQUIRED_CODE['blocks/'.$codename])) require_once($file_base.'/sources/blocks/'.$codename.'.php');
$_REQUIRED_CODE['blocks/'.$codename]=1;
if (!isset($BLOCKS_AT_CACHE[$codename]))
{
$BLOCKS_AT_CACHE[$codename]='sources/blocks';
if (function_exists('persistant_cache_set')) persistant_cache_set('BLOCKS_AT',$BLOCKS_AT_CACHE,true);
}
}
else
{
if (((isset($BLOCKS_AT_CACHE[$codename])) && ($BLOCKS_AT_CACHE[$codename]=='sources_custom/miniblocks')) || ((!isset($BLOCKS_AT_CACHE[$codename])) && (is_file($file_base.'/sources_custom/miniblocks/'.$codename.'.php'))))
{
require_code('developer_tools');
destrictify();
ob_start();
if (defined('HIPHOP_PHP'))
{
require('sources_custom/miniblocks/'.$codename.'.php');
} else
{
require($file_base.'/sources_custom/miniblocks/'.$codename.'.php');
}
$object=ob_get_contents();
ob_end_clean();
restrictify();
if (!isset($BLOCKS_AT_CACHE[$codename]))
{
$BLOCKS_AT_CACHE[$codename]='sources_custom/miniblocks';
if (function_exists('persistant_cache_set')) persistant_cache_set('BLOCKS_AT',$BLOCKS_AT_CACHE,true);
}
}
elseif (((isset($BLOCKS_AT_CACHE[$codename])) && ($BLOCKS_AT_CACHE[$codename]=='sources/miniblocks')) || ((!isset($BLOCKS_AT_CACHE[$codename])) && (is_file($file_base.'/sources/miniblocks/'.$codename.'.php'))))
{
require_code('developer_tools');
destrictify();
ob_start();
if (defined('HIPHOP_PHP'))
{
require('sources/miniblocks/'.$codename.'.php');
} else
{
require($file_base.'/sources/miniblocks/'.$codename.'.php');
}
$object=ob_get_contents();
ob_end_clean();
restrictify();
if (!isset($BLOCKS_AT_CACHE[$codename]))
{
$BLOCKS_AT_CACHE[$codename]='sources/miniblocks';
if (function_exists('persistant_cache_set')) persistant_cache_set('BLOCKS_AT',$BLOCKS_AT_CACHE,true);
}
} elseif ((is_null($map)) || (!array_key_exists('failsafe',$map)) || ($map['failsafe']!='1'))
{
$temp=paragraph(do_lang_tempcode('MISSING_BLOCK_FILE',escape_html($codename)),'90dfdlksds8d7dyddssdds','error_marker');
return $temp->evaluate();
} else $object='';
return $object;
}
$_object=object_factory('Block_'.$codename);
return $_object;
}
?LONG_TEXT do_block_get_cache_identifier(mixed cache_on, ?array map)
Takes a string which is a PHP expression over $map (parameter map), and returns a derived identifier.We see if we have something cached by looking for a matching identifier.
Parameters…
| Name |
cache_on |
| Description |
PHP expression over $map (the parameter map of the block) OR a call_user_func specifier that will return a result (which will be used if cacheing is really very important, even for Hip Hop PHP) |
| Type |
mixed |
| Name |
map |
| Description |
The block parameter map (NULL: no parameters) |
| Type |
?array |
Returns…
| Description |
The derived cache identifier (NULL: the identifier is CURRENTLY null meaning cannot be cached) |
| Type |
?LONG_TEXT |
function do_block_get_cache_identifier($cache_on,$map)
{
$_cache_identifier=array();
if (is_array($cache_on))
{
$_cache_identifier=call_user_func($cache_on[0],$map);
} else
{
if (($cache_on!='') && (!defined('HIPHOP_PHP')))
{
$_cache_on=eval('return '.$cache_on.';'); // NB: This uses $map, as $map is referenced inside $cache_on
if ($_cache_on===NULL) return NULL;
foreach ($_cache_on as $on)
{
$_cache_identifier[]=$on;
}
} elseif (defined('HIPHOP_PHP')) return NULL;
}
$_cache_identifier[]=get_users_timezone(get_member());
$_cache_identifier[]=(get_bot_type()===NULL);
global $TEMPCODE_SETGET;
$_cache_identifier[]=isset($TEMPCODE_SETGET['in_panel'])?$TEMPCODE_SETGET['in_panel']:'0';
$_cache_identifier[]=isset($TEMPCODE_SETGET['interlock'])?$TEMPCODE_SETGET['interlock']:'0';
$cache_identifier=serialize($_cache_identifier);
return $cache_identifier;
}
PATH _get_block_path(ID_TEXT block)
Gets the path to a block code file for a block code name
Parameters…
| Name |
block |
| Description |
The name of the block |
| Type |
ID_TEXT |
Returns…
| Description |
The path to the block |
| Type |
PATH |
function _get_block_path($block)
{
$block_path=get_file_base().'/sources_custom/blocks/'.filter_naughty_harsh($block).'.php';
if (!is_file($block_path))
{
$block_path=get_file_base().'/sources/blocks/'.filter_naughty_harsh($block).'.php';
if (!is_file($block_path))
{
$block_path=get_file_base().'/sources_custom/miniblocks/'.filter_naughty_harsh($block).'.php';
}
}
return $block_path;
}
boolean block_installed(ID_TEXT block)
Check to see if a block is installed.
Parameters…
| Name |
block |
| Description |
The module name |
| Type |
ID_TEXT |
Returns…
| Description |
Whether it is |
| Type |
boolean |
function block_installed($block)
{
$test=$GLOBALS['SITE_DB']->query_value_null_ok('blocks','block_name',array('block_name'=>$block));
return !is_null($test);
}
array find_all_pages_wrap(ID_TEXT zone, boolean keep_ext_on, boolean consider_redirects, integer show_method, ?ID_TEXT page_type)
Get an array of all the pages everywhere in the zone, limited by the selection algorithm (for small sites everything will be returned, for larger ones it depends on the show method).
Parameters…
| Name |
zone |
| Description |
The zone name |
| Type |
ID_TEXT |
| Name |
keep_ext_on |
| Description |
Whether to leave file extensions on the page name |
| Default value |
boolean-false |
| Type |
boolean |
| Name |
consider_redirects |
| Description |
Whether to take redirects into account |
| Default value |
boolean-false |
| Type |
boolean |
| Name |
show_method |
| Description |
Selection algorithm constant |
| Default value |
0 |
| Type |
integer |
| Values restricted to |
0 1 2 |
| Name |
page_type |
| Description |
Page type to show (NULL: all) |
| Default value |
|
| Type |
?ID_TEXT |
Returns…
| Description |
A map of page name to type (modules_custom, etc) |
| Type |
array |
function find_all_pages_wrap($zone,$keep_ext_on=false,$consider_redirects=false,$show_method=0,$page_type=NULL)
{
require_code('zones2');
return _find_all_pages_wrap($zone,$keep_ext_on,$consider_redirects,$show_method,$page_type);
}
array find_all_pages(ID_TEXT zone, ID_TEXT type, string ext, boolean keep_ext_on, ?TIME cutoff_time, integer show_method)
Get an array of all the pages of the specified type (module, etc) and extension (for small sites everything will be returned, for larger ones it depends on the show method).
Parameters…
| Name |
zone |
| Description |
The zone name |
| Type |
ID_TEXT |
| Name |
type |
| Description |
The type |
| Type |
ID_TEXT |
| Values restricted to |
modules modules_custom comcode comcode_custom html html_custom |
| Name |
ext |
| Description |
The file extension to limit us to (without a dot) |
| Default value |
php |
| Type |
string |
| Name |
keep_ext_on |
| Description |
Whether to leave file extensions on the page name |
| Default value |
boolean-false |
| Type |
boolean |
| Name |
cutoff_time |
| Description |
Only show pages newer than (NULL: no restriction) |
| Default value |
|
| Type |
?TIME |
| Name |
show_method |
| Description |
Selection algorithm constant |
| Default value |
0 |
| Type |
integer |
| Values restricted to |
0 1 2 |
Returns…
| Description |
A map of page name to type (modules_custom, etc) |
| Type |
array |
function find_all_pages($zone,$type,$ext='php',$keep_ext_on=false,$cutoff_time=NULL,$show_method=0)
{
require_code('zones2');
return _find_all_pages($zone,$type,$ext,$keep_ext_on,$cutoff_time,$show_method);
}
array find_all_modules(ID_TEXT zone)
Get an array of all the modules.
Parameters…
| Name |
zone |
| Description |
The zone name |
| Type |
ID_TEXT |
Returns…
| Description |
A map of page name to type (modules_custom, etc) |
| Type |
array |
function find_all_modules($zone)
{
require_code('zones2');
return _find_all_modules($zone);
}
array extract_module_functions(PATH path, array functions, ?array params)
Extract code to execute the requested functions with the requested parameters from the module at the given path.We used to actually load up the module, but it ate all our RAM when we did!
Parameters…
| Name |
path |
| Description |
The path to the module |
| Type |
PATH |
| Name |
functions |
| Description |
Array of functions to be executing |
| Type |
array |
| Name |
params |
| Description |
A list of parameters to pass to our functions (NULL: none) |
| Default value |
|
| Type |
?array |
Returns…
| Description |
A list of pieces of code to do the equivalent of executing the requested functions with the requested parameters |
| Type |
array |
sources/zones2.php
Global_functions_zones2.php
Function summary
|
void
|
init__zones2 ()
|
|
void
|
actual_add_zone (ID_TEXT zone, SHORT_TEXT title, ID_TEXT default_page, SHORT_TEXT header_text, ID_TEXT theme, BINARY wide, BINARY require_session, BINARY displayed_in_menu)
|
|
array
|
get_module_overridables (ID_TEXT zone, ID_TEXT page)
|
|
integer
|
upgrade_module (ID_TEXT zone, ID_TEXT module)
|
|
boolean
|
reinstall_module (ID_TEXT zone, ID_TEXT module)
|
|
void
|
uninstall_module (ID_TEXT zone, ID_TEXT module)
|
|
array
|
find_all_blocks ()
|
|
string
|
cleanup_block_name (ID_TEXT block)
|
|
array
|
get_block_parameters (ID_TEXT block)
|
|
integer
|
upgrade_block (ID_TEXT block)
|
|
boolean
|
reinstall_block (ID_TEXT block)
|
|
void
|
uninstall_block (ID_TEXT block)
|
|
array
|
extract_module_functions_page (ID_TEXT zone, ID_TEXT page, array functions, ?array params)
|
|
?array
|
extract_module_info (PATH path)
|
|
array
|
_find_all_pages_wrap (ID_TEXT zone, boolean keep_ext_on, boolean consider_redirects, integer show_method, ?ID_TEXT page_type)
|
|
array
|
_find_all_pages (ID_TEXT zone, ID_TEXT type, string ext, boolean keep_ext_on, ?TIME cutoff_time, integer show_method, ?boolean custom)
|
|
array
|
_find_all_modules (ID_TEXT zone)
|
void init__zones2()
Standard code module initialisation function.
Parameters…
(No return value)
function init__zones2()
{
global $CLASS_CACHE;
$CLASS_CACHE=array();
}
void actual_add_zone(ID_TEXT zone, SHORT_TEXT title, ID_TEXT default_page, SHORT_TEXT header_text, ID_TEXT theme, BINARY wide, BINARY require_session, BINARY displayed_in_menu)
Add a zone.
Parameters…
| Name |
zone |
| Description |
Name of the zone |
| Type |
ID_TEXT |
| Name |
title |
| Description |
The zone title |
| Type |
SHORT_TEXT |
| Name |
default_page |
| Description |
The zones default page |
| Default value |
start |
| Type |
ID_TEXT |
| Name |
header_text |
| Description |
The header text |
| Default value |
|
| Type |
SHORT_TEXT |
| Name |
theme |
| Description |
The theme |
| Default value |
default |
| Type |
ID_TEXT |
| Name |
wide |
| Description |
Whether the zone is wide |
| Default value |
0 |
| Type |
BINARY |
| Name |
require_session |
| Description |
Whether the zone requires a session for pages to be used |
| Default value |
0 |
| Type |
BINARY |
| Name |
displayed_in_menu |
| Description |
Whether the zone in displayed in the menu coded into some themes |
| Default value |
1 |
| Type |
BINARY |
(No return value)
function actual_add_zone($zone,$title,$default_page='start',$header_text='',$theme='default',$wide=0,$require_session=0,$displayed_in_menu=1)
{
require_code('type_validation');
if (!is_alphanumeric($zone)) warn_exit(do_lang_tempcode('BAD_CODENAME'));
if (get_file_base()!=get_custom_file_base()) warn_exit(do_lang_tempcode('SHARED_INSTALL_PROHIBIT'));
// Check doesn't already exist
$test=$GLOBALS['SITE_DB']->query_value_null_ok('zones','zone_header_text',array('zone_name'=>$zone));
if (!is_null($test))
{
if (file_exists(get_file_base().'/'.$zone)) // Ok it's here completely, so we can't create
{
warn_exit(do_lang_tempcode('ALREADY_EXISTS',escape_html($zone)));
} else // In DB, not on disk, so we'll just delete DB record
{
persistant_cache_delete(array('ZONE',$zone));
$GLOBALS['SITE_DB']->query_delete('zones',array('zone_name'=>$zone),'',1);
}
}
if (!file_exists(get_file_base().'/'.$zone))
{
// Create structure
afm_make_directory($zone.'/pages/minimodules_custom',true,true);
afm_make_directory($zone.'/pages/minimodules',false,true);
afm_make_directory($zone.'/pages/modules_custom',true,true);
afm_make_directory($zone.'/pages/modules',false,true);
$langs=array_keys(find_all_langs(true));
foreach ($langs as $lang)
{
afm_make_directory($zone.'/pages/comcode_custom/'.$lang,true,true);
afm_make_directory($zone.'/pages/comcode/'.$lang,false,true);
afm_make_directory($zone.'/pages/html_custom/'.$lang,true,true);
afm_make_directory($zone.'/pages/html/'.$lang,false,true);
}
afm_make_file($zone.'/index.php',file_get_contents(get_file_base().'/site/index.php'),false);
if (file_exists(get_file_base().'/pages/.htaccess'))
afm_make_file($zone.'/pages/.htaccess',file_get_contents(get_file_base().'/pages/.htaccess'),false);
$index_php=array('pages/comcode','pages/comcode/EN','pages/comcode_custom','pages/comcode_custom/EN',
'pages/html','pages/html/EN','pages/html_custom','pages/html_custom/EN',
'pages/modules','pages/modules_custom','pages');
foreach ($index_php as $i)
{
afm_make_file($zone.'/'.$i.'/index.html','',false);
}
$default_menu=<<<END
[block="zone_{$zone}_menu" type="tree" caption="Menu"]side_stored_menu[/block]
[block failsafe="1"]side_users_online[/block]
[block failsafe="1"]side_stats[/block]
[block]side_personal_stats[/block]
END;
afm_make_file($zone.'/pages/comcode_custom/EN/panel_left.txt',$default_menu,true);
}
afm_make_file($zone.'/pages/comcode_custom/EN/'.filter_naughty($default_page).'.txt','[title]'.do_lang('YOUR_NEW_ZONE').'[/title]'.chr(10).chr(10).do_lang('YOUR_NEW_ZONE_PAGE',$zone.':'.$default_page).chr(10).chr(10).'[block]main_comcode_page_children[/block]',true);
$GLOBALS['SITE_DB']->query_insert('zones',array('zone_name'=>$zone,'zone_title'=>insert_lang($title,1),'zone_default_page'=>$default_page,'zone_header_text'=>insert_lang($header_text,1),'zone_theme'=>$theme,'zone_wide'=>$wide,'zone_require_session'=>$require_session,'zone_displayed_in_menu'=>$displayed_in_menu));
require_code('menus2');
$menu_item_count=$GLOBALS['SITE_DB']->query_value('menu_items','COUNT(*)',array('i_menu'=>'zone_menu'));
if ($menu_item_count<40)
add_menu_item_simple('zone_menu',NULL,$title,$zone.':',0,1);
log_it('ADD_ZONE',$zone);
persistant_cache_delete('ALL_ZONES');
decache('main_sitemap');
decache('side_stored_menu');
decache('side_zone_jump');
}
array get_module_overridables(ID_TEXT zone, ID_TEXT page)
Get a list of overridable SP's for a module.
Parameters…
| Name |
zone |
| Description |
The zone it is in |
| Type |
ID_TEXT |
| Name |
page |
| Description |
The page name |
| Type |
ID_TEXT |
Returns…
| Description |
A pair: List of overridable SP's, SP-page |
| Type |
array |
function get_module_overridables($zone,$page)
{
$overridables=array();
$sp_page=$page;
$_pagelinks=extract_module_functions_page($zone,$page,array('get_page_links'),array(NULL,false,NULL,true));
if (!is_null($_pagelinks[0])) // If it's a CMS-supporting module (e.g. downloads)
{
$pagelinks=is_array($_pagelinks[0])?call_user_func_array($_pagelinks[0][0],$_pagelinks[0][1]):eval($_pagelinks[0]);
if ((!is_null($pagelinks[0])) && (!is_null($pagelinks[1]))) // If it's not disabled
{
$_overridables=extract_module_functions_page(get_module_zone($pagelinks[1]),$pagelinks[1],array('get_sp_overrides'));
if (!is_null($_overridables[0])) // If it's a CMS-supporting module with SP overrides
{
$overridables=is_array($_overridables[0])?call_user_func_array($_overridables[0][0],$_overridables[0][1]):eval($_overridables[0]);
}
$sp_page=$pagelinks[1];
}
} else
{
$_overridables=extract_module_functions_page($zone,$page,array('get_sp_overrides'));
if (!is_null($_overridables[0])) // If it's a CMS-supporting module with SP overrides
{
$overridables=is_array($_overridables[0])?call_user_func_array($_overridables[0][0],$_overridables[0][1]):eval($_overridables[0]);
}
}
return array($overridables,$sp_page);
}
integer upgrade_module(ID_TEXT zone, ID_TEXT module)
Upgrade the specified module.
Parameters…
| Name |
zone |
| Description |
The zone name |
| Type |
ID_TEXT |
| Name |
module |
| Description |
The module name |
| Type |
ID_TEXT |
Returns…
| Description |
0=No upgrade. -2=Not installed, 1=Upgrade |
| Type |
integer |
function upgrade_module($zone,$module)
{
require_code('database_action');
require_code('config2');
require_code('menus2');
$rows=$GLOBALS['SITE_DB']->query_select('modules',array('*'),array('module_the_name'=>$module),'',1);
if (!array_key_exists(0,$rows)) return (-2); // Not installed, so can't upgrade
$upgrade_from=$rows[0]['module_version'];
$upgrade_from_hack=$rows[0]['module_hack_version'];
$module_path=get_file_base().'/'._get_module_path($zone,$module);
$functions=extract_module_functions($module_path,array('info','install'),array($upgrade_from,$upgrade_from_hack));
if ((is_null($functions[1])) && (strpos($module_path,'/modules_custom/')!==false))
{
if ((strpos($module_path,'/modules_custom/')!==false) && (file_exists(str_replace('/modules_custom/','/modules/',$module_path))) && ((strpos(file_get_contents($module_path),'function install(')===false) || (strpos(file_get_contents($module_path),'function info(')===false)))
{
$module_path=str_replace('/modules_custom/','/modules/',$module_path);
}
$functions=extract_module_functions($module_path,array('info','install'),array($upgrade_from,$upgrade_from_hack));
}
if (is_null($functions[0]))
{
$info=array();
$info['author']='Chris Graham';
$info['organisation']='ocProducts';
$info['hacked_by']=NULL;
$info['hack_version']=NULL;
$info['version']=2;
$info['locked']=true;
} else
{
$info=is_array($functions[0])?call_user_func_array($functions[0][0],$functions[0][1]):eval($functions[0]);
}
$ret=0;
if ((!is_null($functions[1])) && (array_key_exists('update_require_upgrade',$info)))
{
if ((($upgrade_from<$info['version']) && (array_key_exists('update_require_upgrade',$info)))
|| (($upgrade_from_hack<$info['hack_version']) && (array_key_exists('hack_require_upgrade',$info))))
{
if (is_array($functions[1]))
{
call_user_func_array($functions[1][0],$functions[1][1]);
} else
{
eval($functions[1]);
}
$ret=1;
}
}
if (is_null($info['hacked_by'])) $info['installed_hacked_by']='';
$GLOBALS['SITE_DB']->query_update('modules',array('module_version'=>$info['version'],'module_hack_version'=>$info['hack_version'],'module_hacked_by'=>is_null($info['hacked_by'])?'':$info['hacked_by']),array('module_the_name'=>$module),'',1);
return $ret;
}
boolean reinstall_module(ID_TEXT zone, ID_TEXT module)
Reinstall the specified module.
Parameters…
| Name |
zone |
| Description |
The zone name |
| Type |
ID_TEXT |
| Name |
module |
| Description |
The module name |
| Type |
ID_TEXT |
Returns…
| Description |
Whether a module installer had to be run |
| Type |
boolean |
function reinstall_module($zone,$module)
{
$GLOBALS['NO_QUERY_LIMIT']=true;
$module_path=get_file_base().'/'._get_module_path($zone,$module);
require_code('database_action');
require_code('config2');
require_code('menus2');
require_code('files2');
$GLOBALS['SITE_DB']->query_delete('modules',array('module_the_name'=>$module),'',1);
$functions=extract_module_functions($module_path,array('info','install','uninstall'));
if ((is_null($functions[1])) && (strpos($module_path,'/modules_custom/')!==false))
{
if ((strpos($module_path,'/modules_custom/')!==false) && (file_exists(str_replace('/modules_custom/','/modules/',$module_path))) && ((strpos(file_get_contents($module_path),'function install(')===false) || (strpos(file_get_contents($module_path),'function info(')===false)))
{
$module_path=str_replace('/modules_custom/','/modules/',$module_path);
}
$functions=extract_module_functions($module_path,array('info','install','uninstall'));
}
if (is_null($functions[0]))
{
$info=array();
$info['author']='Chris Graham';
$info['organisation']='ocProducts';
$info['hacked_by']=NULL;
$info['hack_version']=NULL;
$info['version']=2;
$info['locked']=true;
} else
{
$info=is_array($functions[0])?call_user_func_array($functions[0][0],$functions[0][1]):eval($functions[0]);
}
if (!is_null($functions[2]))
{
if (is_array($functions[2]))
{
call_user_func_array($functions[2][0],$functions[2][1]);
} else
{
eval($functions[2]);
}
}
if (is_null($info)) return false;
if (is_null($info['hacked_by'])) $info['hacked_by']='';
if (!is_null($functions[1]))
{
if (is_array($functions[1]))
{
call_user_func_array($functions[1][0],$functions[1][1]);
} else
{
eval($functions[1]);
}
}
$GLOBALS['SITE_DB']->query_insert('modules',array('module_the_name'=>$module,'module_author'=>$info['author'],'module_organisation'=>$info['organisation'],'module_hacked_by'=>is_null($info['hacked_by'])?'':$info['hacked_by'],'module_hack_version'=>$info['hack_version'],'module_version'=>$info['version']));
return (!is_null($functions[1]));
}
void uninstall_module(ID_TEXT zone, ID_TEXT module)
Completely uninstall the specified module from the system.
Parameters…
| Name |
zone |
| Description |
The zone name |
| Type |
ID_TEXT |
| Name |
module |
| Description |
The module name |
| Type |
ID_TEXT |
(No return value)
function uninstall_module($zone,$module)
{
$module_path=get_file_base().'/'._get_module_path($zone,$module);
require_code('database_action');
require_code('config2');
require_code('files2');
$GLOBALS['SITE_DB']->query_delete('modules',array('module_the_name'=>$module),'',1);
$GLOBALS['SITE_DB']->query_delete('group_page_access',array('page_name'=>$module)); // As some modules will try and install this themselves. Entry point permissions they won't.
$GLOBALS['SITE_DB']->query_delete('gsp',array('the_page'=>$module)); // Ditto
if (file_exists($module_path))
{
$functions=extract_module_functions($module_path,array('uninstall'));
if ((is_null($functions[0])) && (strpos($module_path,'/modules_custom/')!==false))
{
if ((strpos($module_path,'/modules_custom/')!==false) && (file_exists(str_replace('/modules_custom/','/modules/',$module_path))) && ((strpos(file_get_contents($module_path),'function install(')===false) || (strpos(file_get_contents($module_path),'function info(')===false)))
{
$module_path=str_replace('/modules_custom/','/modules/',$module_path);
}
$functions=extract_module_functions($module_path,array('uninstall'));
}
if (is_null($functions[0])) return;
if (is_array($functions[0]))
{
call_user_func_array($functions[0][0],$functions[0][1]);
} else
{
eval($functions[0]);
}
}
}
array find_all_blocks()
Get an array of all the blocks that are currently installed (miniblocks not included).
Parameters…
Returns…
| Description |
Map of all blocks (name->[sources/sources_custom]) |
| Type |
array |
function find_all_blocks()
{
$out=array();
$dh=opendir(get_file_base().'/sources/blocks');
while (($file=readdir($dh))!==false)
{
if ((substr($file,-4)=='.php') && (preg_match('#^[\w\-]*$#',substr($file,0,strlen($file)-4))!=0))
{
$out[substr($file,0,strlen($file)-4)]='sources';
}
}
closedir($dh);
if (!in_safe_mode())
{
$dh=@opendir(get_file_base().'/sources_custom/blocks');
if ($dh!==false)
{
while (($file=readdir($dh))!==false)
{
if ((substr($file,-4)=='.php') && (preg_match('#^[\w\-]*$#',substr($file,0,strlen($file)-4))!=0))
{
$out[substr($file,0,strlen($file)-4)]='sources_custom';
}
}
closedir($dh);
}
}
return $out;
}
string cleanup_block_name(ID_TEXT block)
Make a block codename look nice
Parameters…
| Name |
block |
| Description |
The raw block codename |
| Type |
ID_TEXT |
Returns…
| Description |
A nice human readable version of the name |
| Type |
string |
function cleanup_block_name($block)
{
$title=do_lang('BLOCK_TRANS_NAME_'.$block,NULL,NULL,NULL,NULL,false);
if (!is_null($title)) return $title;
$block=str_replace('_ocf_','_',$block);
return ucwords(str_replace('_',' ',str_replace('block_bottom_','Bottom: ',str_replace('block_side_','Side: ',str_replace('block_main_','Main: ',$block)))));
}
array get_block_parameters(ID_TEXT block)
Gets parameters for a block
Parameters…
| Name |
block |
| Description |
The name of the block to get parameters for |
| Type |
ID_TEXT |
Returns…
| Description |
A list of parameters the block takes |
| Type |
array |
function get_block_parameters($block)
{
$block_path=_get_block_path($block);
$info=extract_module_info($block_path);
if (is_null($info)) return array();
$ret=array_key_exists('parameters',$info)?$info['parameters']:array();
if (is_null($ret)) return array();
return $ret;
}
integer upgrade_block(ID_TEXT block)
Upgrades a block to the latest version available on your ocPortal installation. This function can only upgrade to the latest version put into the block directory. You should not need to use this function.
Parameters…
| Name |
block |
| Description |
The name of the block to upgrade |
| Type |
ID_TEXT |
Returns…
| Description |
0=No upgrade. -2=Not installed, 1=Upgrade |
| Type |
integer |
function upgrade_block($block)
{
require_code('database_action');
$rows=$GLOBALS['SITE_DB']->query_select('blocks',array('*'),array('block_name'=>$block),'',1);
if (!array_key_exists(0,$rows)) return (-2); // Not installed, so can't upgrade
$upgrade_from=$rows[0]['block_version'];
$upgrade_from_hack=$rows[0]['block_hack_version'];
$block_path=_get_block_path($block);
$functions=extract_module_functions($block_path,array('info','install'),array($upgrade_from,$upgrade_from_hack));
if (is_null($functions[0])) return 0;
$info=is_array($functions[0])?call_user_func_array($functions[0][0],$functions[0][1]):eval($functions[0]);
if ((!is_null($functions[1])) && (array_key_exists('update_require_upgrade',$info)))
{
if ((($upgrade_from<$info['version']) && (array_key_exists('update_require_upgrade',$info)))
|| (($upgrade_from_hack<$info['hack_version']) && (array_key_exists('hack_require_upgrade',$info))))
{
if (is_array($functions[1]))
{
call_user_func_array($functions[1][0],$functions[1][1]);
} else
{
eval($functions[1]);
}
if (is_null($info['hacked_by'])) $info['installed_hacked_by']='';
$GLOBALS['SITE_DB']->query_update('blocks',array('block_version'=>$info['version'],'block_hack_version'=>$info['hack_version'],'block_hacked_by'=>is_null($info['hacked_by'])?'':$info['hacked_by']),array('block_name'=>$block),'',1);
return 1;
}
}
return 0;
}
boolean reinstall_block(ID_TEXT block)
Reinstall a block if it has become corrupted for any reason.Again, you should not need to use this function.
Parameters…
| Name |
block |
| Description |
The name of the block to reinstall |
| Type |
ID_TEXT |
Returns…
| Description |
Whether installation was required |
| Type |
boolean |
function reinstall_block($block)
{
//echo $block.'<br />';
$block_path=_get_block_path($block);
$GLOBALS['SITE_DB']->query_delete('blocks',array('block_name'=>$block),'',1);
require_code('database_action');
require_code('menus2');
require_code('config2');
require_code('files2');
$functions=extract_module_functions($block_path,array('info','install','uninstall'));
if (is_null($functions[0])) return false;
if (!is_null($functions[2]))
{
if (is_array($functions[2]))
{
call_user_func_array($functions[2][0],$functions[2][1]);
} else
{
eval($functions[2]);
}
}
$info=is_array($functions[0])?call_user_func_array($functions[0][0],$functions[0][1]):eval($functions[0]);
if (is_null($info)) return false;
if (is_null($info['hacked_by'])) $info['hacked_by']='';
$GLOBALS['SITE_DB']->query_insert('blocks',array('block_name'=>$block,'block_author'=>$info['author'],'block_organisation'=>$info['organisation'],'block_hacked_by'=>is_null($info['hacked_by'])?'':$info['hacked_by'],'block_hack_version'=>$info['hack_version'],'block_version'=>$info['version']));
if (!is_null($functions[1]))
{
if (is_array($functions[1]))
{
call_user_func_array($functions[1][0],$functions[1][1]);
} else
{
eval($functions[1]);
}
return true;
}
return false;
}
void uninstall_block(ID_TEXT block)
This function totally uninstalls a block from the system. Yet again, you should not need to use this function.
Parameters…
| Name |
block |
| Description |
The name of the block to uninstall |
| Type |
ID_TEXT |
(No return value)
function uninstall_block($block)
{
$block_path=_get_block_path($block);
require_code('database_action');
require_code('menus2');
require_code('files2');
$GLOBALS['SITE_DB']->query_delete('blocks',array('block_name'=>$block),'',1);
$GLOBALS['SITE_DB']->query_delete('cache_on',array('cached_for'=>$block),'',1);
$GLOBALS['SITE_DB']->query_delete('cache',array('cached_for'=>$block));
if (file_exists($block_path))
{
$functions=extract_module_functions($block_path,array('uninstall'));
if (is_null($functions[0])) return;
if (is_array($functions[0]))
{
call_user_func_array($functions[0][0],$functions[0][1]);
} else
{
eval($functions[0]);
}
}
}
array extract_module_functions_page(ID_TEXT zone, ID_TEXT page, array functions, ?array params)
Extract code to execute the requested functions with the requested parameters from the module requested.
Parameters…
| Name |
zone |
| Description |
The zone it is in |
| Type |
ID_TEXT |
| Name |
page |
| Description |
The page name |
| Type |
ID_TEXT |
| Name |
functions |
| Description |
Array of functions to be executing |
| Type |
array |
| Name |
params |
| Description |
A list of parameters to pass to our functions (NULL: none) |
| Default value |
|
| Type |
?array |
Returns…
| Description |
A list of pieces of code to do the equivalent of executing the requested functions with the requested parameters |
| Type |
array |
?array extract_module_info(PATH path)
Extract the info function from a module at a given path.
Parameters…
| Name |
path |
| Description |
The path to the module |
| Type |
PATH |
Returns…
| Description |
A module information map (NULL: module contains no info method) |
| Type |
?array |
array _find_all_pages_wrap(ID_TEXT zone, boolean keep_ext_on, boolean consider_redirects, integer show_method, ?ID_TEXT page_type)
Get an array of all the pages everywhere in the zone (for small sites everything will be returned, for larger ones it depends on the show method).
Parameters…
| Name |
zone |
| Description |
The zone name |
| Type |
ID_TEXT |
| Name |
keep_ext_on |
| Description |
Whether to leave file extensions on the page name |
| Default value |
boolean-false |
| Type |
boolean |
| Name |
consider_redirects |
| Description |
Whether to take redirects into account |
| Default value |
boolean-false |
| Type |
boolean |
| Name |
show_method |
| Description |
Selection algorithm constant |
| Default value |
0 |
| Type |
integer |
| Values restricted to |
0 1 2 |
| Name |
page_type |
| Description |
Page type to show (NULL: all) |
| Default value |
|
| Type |
?ID_TEXT |
Returns…
| Description |
A map of page name to type (modules_custom, etc) |
| Type |
array |
function _find_all_pages_wrap($zone,$keep_ext_on=false,$consider_redirects=false,$show_method=0,$page_type=NULL)
{
$pages=array();
if ((is_null($page_type)) || ($page_type=='modules'))
{
if (!in_safe_mode())
{
$pages+=find_all_pages($zone,'modules_custom','php',$keep_ext_on,NULL,$show_method);
}
$pages+=find_all_pages($zone,'modules','php',$keep_ext_on,NULL,$show_method);
}
$langs=multi_lang()?array_keys(find_all_langs()):array(get_site_default_lang());
foreach ($langs as $lang)
{
if ((is_null($page_type)) || ($page_type=='comcode'))
{
if (!in_safe_mode())
{
$pages+=find_all_pages($zone,'comcode_custom/'.$lang,'txt',$keep_ext_on,NULL,$show_method);
}
$pages+=find_all_pages($zone,'comcode/'.$lang,'txt',$keep_ext_on,NULL,$show_method);
}
if ((is_null($page_type)) || ($page_type=='html'))
{
if (!in_safe_mode())
{
$pages+=find_all_pages($zone,'html_custom/'.$lang,'htm',$keep_ext_on,NULL,$show_method);
}
$pages+=find_all_pages($zone,'html/'.$lang,'htm',$keep_ext_on,NULL,$show_method);
}
}
if ((is_null($page_type)) || ($page_type=='minimodules'))
{
if (!in_safe_mode())
{
$pages+=find_all_pages($zone,'minimodules_custom','php',$keep_ext_on,NULL,$show_method);
}
$pages+=find_all_pages($zone,'minimodules','php',$keep_ext_on,NULL,$show_method);
}
if (addon_installed('redirects_editor'))
{
if ($consider_redirects)
{
$redirects=$GLOBALS['SITE_DB']->query_select('redirects',array('*'),array('r_from_zone'=>$zone));
foreach ($redirects as $r)
{
if ($r['r_is_transparent']==0)
{
//unset($pages[$r['r_from_page']]); // We don't want to link to anything that is a full redirect - Actually, we don't want to hide things too much, could be confusing
} else
{
$pages[$r['r_from_page']]='redirect:'.$r['r_to_zone'].':'.$r['r_to_page'];
}
}
}
}
return $pages;
}
array _find_all_pages(ID_TEXT zone, ID_TEXT type, string ext, boolean keep_ext_on, ?TIME cutoff_time, integer show_method, ?boolean custom)
Get an array of all the pages of the specified type (module, etc) and extension (for small sites everything will be returned, for larger ones it depends on the show method).
Parameters…
| Name |
zone |
| Description |
The zone name |
| Type |
ID_TEXT |
| Name |
type |
| Description |
The type (including language, if appropriate) |
| Type |
ID_TEXT |
| Values restricted to |
modules modules_custom comcode/EN comcode_custom/EN html/EN html_custom/EN |
| Name |
ext |
| Description |
The file extension to limit us to (without a dot) |
| Default value |
php |
| Type |
string |
| Name |
keep_ext_on |
| Description |
Whether to leave file extensions on the page name |
| Default value |
boolean-false |
| Type |
boolean |
| Name |
cutoff_time |
| Description |
Only show pages newer than (NULL: no restriction) |
| Default value |
|
| Type |
?TIME |
| Name |
show_method |
| Description |
Selection algorithm constant |
| Default value |
0 |
| Type |
integer |
| Values restricted to |
0 1 2 |
| Name |
custom |
| Description |
Whether to search under the custom-file-base (NULL: auto-decide) |
| Default value |
|
| Type |
?boolean |
Returns…
| Description |
A map of page name to type (modules_custom, etc) |
| Type |
array |
function _find_all_pages($zone,$type,$ext='php',$keep_ext_on=false,$cutoff_time=NULL,$show_method=0,$custom=NULL)
{
$out=array();
$module_path=($zone=='')?('pages/'.filter_naughty($type)):(filter_naughty($zone).'/pages/'.filter_naughty($type));
if (is_null($custom))
{
$custom=((strpos($type,'comcode_custom')!==false) || (strpos($type,'html_custom')!==false));
if (($custom) && (get_custom_file_base()!=get_file_base())) $out=_find_all_pages($zone,$type,$ext,false,NULL,$show_method,false);
}
$stub=$custom?get_custom_file_base():get_file_base();
$dh=@opendir($stub.'/'.$module_path);
if ($dh!==false)
{
while (($file=readdir($dh))!==false)
{
if ((substr($file,-4)=='.'.$ext) && (file_exists($stub.'/'.$module_path.'/'.$file)) && (preg_match('#^[\w\-]*$#',substr($file,0,strlen($file)-4))!=0))
{
if (!is_null($cutoff_time))
if (filectime($stub.'/'.$module_path.'/'.$file)<$cutoff_time) continue;
if ($ext=='txt')
{
switch ($show_method)
{
case FIND_ALL_PAGES__NEWEST: // Only gets newest if it's a large site
if (count($out)>300)
{
$out=array();
$records=$GLOBALS['SITE_DB']->query_select('comcode_pages',array('the_page'),array('the_zone'=>$zone),'ORDER BY p_add_date DESC',300);
foreach ($records as $record)
{
$file=$record['the_page'].'.txt';
if (!file_exists($stub.'/'.$module_path.'/'.$file)) continue;
if (!is_null($cutoff_time))
if (filectime($stub.'/'.$module_path.'/'.$file)<$cutoff_time) continue;
$out[$keep_ext_on?$file:substr($file,0,strlen($file)-4)]=$type;
}
} else break;
//break; Actually, no, let it roll on to the next one to get key files too
case FIND_ALL_PAGES__PERFORMANT: // Default, chooses selection carefully based on site size
if (($show_method==FIND_ALL_PAGES__NEWEST) || (count($out)>300))
{
if ($show_method!=FIND_ALL_PAGES__NEWEST) $out=array();
$records=$GLOBALS['SITE_DB']->query('SELECT the_page FROM '.get_table_prefix().'comcode_pages WHERE '.db_string_equal_to('the_zone',$zone).' AND ('.db_string_equal_to('the_page',get_zone_default_page($zone)).' OR the_page LIKE \''.db_encode_like('panel\_%').'\') ORDER BY p_add_date DESC');
foreach ($records as $record)
{
$file=$record['the_page'].'.txt';
if (!file_exists($stub.'/'.$module_path.'/'.$file)) continue;
if (!is_null($cutoff_time))
if (filectime($stub.'/'.$module_path.'/'.$file)<$cutoff_time) continue;
$out[$keep_ext_on?$file:substr($file,0,strlen($file)-4)]=$type;
}
break 2;
}
break;
case FIND_ALL_PAGES__ALL: // Nothing special
break;
}
}
$out[$keep_ext_on?$file:substr($file,0,strlen($file)-4)]=$type;
}
}
closedir($dh);
}
if (($zone=='') && (get_option('collapse_user_zones',true)==='1'))
$out+=_find_all_pages('site',$type,$ext,$keep_ext_on);
ksort($out);
return $out;
}
array _find_all_modules(ID_TEXT zone)
Get an array of all the modules.
Parameters…
| Name |
zone |
| Description |
The zone name |
| Type |
ID_TEXT |
Returns…
| Description |
A map of page name to type (modules_custom, etc) |
| Type |
array |
function _find_all_modules($zone)
{
if (in_safe_mode())
{
return find_all_pages($zone,'modules');
}
return find_all_pages($zone,'modules')+find_all_pages($zone,'modules_custom');
}
Hooks are special objects that exist for modules or blocks that use them. They define modular functionality that the block or module can call upon, in order to extend it's influence to uncoupled concepts. For example, the stats block uses hooks for each type of stats in order to avoid putting a burden on that block knowing about all types of content (and thus being highly contested over by modders wanting to add stuff). By using hooks, modularity can be maintained and functionality extended by addition of hooks, not modification of existing code.
Hooks are used for the following in ocPortal, in a default installation:
- point-store frontends
- cache rebuilders
- importers
- content search handlers
- unvalidated handlers
- newsletter what's new handlers
- side stats
- staff checklist
Tutorial - Module Basics
This tutorial will show you the basics of creating a module, and making it automatically install and uninstall itself.
1) Create a blank PHP file in root/pages/modules/, call it 'teapot.php'
2) Insert the following code:
Code (php)
<?php /*
Put your copyright notice in here.
*/
class Module_teapot
{
function info
()
{
$info['author']='Bob';
$info['organisation']='Bobsoft';
$info['hacked_by']=NULL;
$info['hack_version']=NULL;
$info['version']=1;
$info['locked']=false;
//If locked is true, this module cannot be uninstalled as other modules use its functionality
return $info;
}
function uninstall
()
{
//Uninstall code goes here
}
function install
($upgrade_from=NULL, $upgrade_from_hack=NULL)
{
//Install code goes here
}
function run
()
{
// What action are we going to do?
$type=get_param
("type","");
//This is for the lang used below
//This is normally where you would add required languages and code
require_lang
('comcode');
if ($type=="foo") return $this->foo();
return $this->interface();
}
function foo
()
{
You would put some
sort of action code in here
, such
as adding a teapot
}
function interface()
{
$title=get_page_title
('REFERENCE_SOURCE');
//Here is some completely random code to display a results field, and show you how to as well
//You really should get strings from the language INI files using do_lang, but that is beyond the scope of this tutorial
$fields_title=results_field_title
(array('Name','Address','Age'));
$url=build_url
(array("page"=>"teapot"));
$fields = blank_tempcode
();
$values = array('Bobby','Fred','Shower Cap');
$values2 = array('James','House','Ducky');
foreach($values as $i=>$value)
{
$fields->attach(results_entry
(array(hyperlink
($url, $value), $values2[$i], $value)));
}
//Of course, $fields will not be blank, but I might as well show you a nice error trapper...
if ($fields->is_blank()) return message_page
($title,do_lang
("NO_ENTRIES"));
$output = results_table
(0,'start',3,'max', $fields_title, $fields,false);
return do_template
('INDEX_PAGE',array('PRE'=>'','POST'=>'','TITLE'=>$title,'CONTENT'=>$output));
}
}
?>
Explanation:
The module is wrapped in a class starting with 'Module_', then the name of the file (without the '.php' extension).
The info function is called to provide information to admins about this module. You have to have an info function.
The install function is called on installation to install the module. You would place code to add permissions, config options, and do database operations such as adding tables in this function.
The uninstall function is obviously called to uninstall the module. You should remove
ALL traces of your module in this function.
The run function is called when someone requests a page from this module. You have to have this function. Generally, it is used as a 'contents' page - it looks at the GET variables, and decides what the user wants to do. It then executes the associated function, which outputs whatever it need to, to the browser.
The build_url function call returns a complete URL, taking an array of required GET variables as input.
Here you can see how to use tempcode: Initialize a tempcode variable, then add stuff to it using ->attach
3) Add your own code as required.
Blocks are small, reusable sections of code that can be placed anywhere in the website. They are supported by comcode, using the 'block' tag, and can be seen everywhere on a default installation of ocPortal. Things such as the Image Of The Day (IOTD), and the RSS feed on the main page are all blocks.
Blocks are referenced by codename, and filenames and function names are based on that codename.
By convention, a block is either a main block or a side block, but ocPortal defines no strict mechanism for dealing with this.
Tutorial - Displaying a Block
To display a block, you need a block, and some code to display it with. The block needs to work. Here is the PHP code to display the block:
Code (php)
$output->attach(do_block('main_rss', $rss_feed_url));
Alternatively, you could achieve the same end in comcode:
Code
[html][block="http://slashdot.org/index.rss"]main_rss[/block][/html]
0 reviews: Unrated (average)
There have been no comments yet