ocPortal Developer's Guide: Splurgh
» Return to Contents
The splurgh functions build up a special compressed format of a tree structure, that is output as javascript code. Javascript functions in javascript.php interpret the compressed format, expanding it into a full uncompressed page.
sources/splurgh.php
Global_functions_splurgh.php
Function summary
|
string
|
splurgh_master_build (string key_name, array map, URLPATH url_stub, ID_TEXT _cache_file, TIME last_change_time, ?AUTO_LINK first_id)
|
|
string
|
_splurgh_do_node (array map, AUTO_LINK node, string chain, array fulltable, integer nest)
|
string splurgh_master_build(string key_name, array map, URLPATH url_stub, ID_TEXT _cache_file, TIME last_change_time, ?AUTO_LINK first_id)
Get a splurghified version of the specified item.
Parameters…
| Name |
key_name |
| Description |
The name of what the key we want to reference is in our array of maps (e.g. 'id') |
| Type |
string |
| Name |
map |
| Description |
A row of maps for data we are splurghing; this is probably just the result of $GLOBALS['SITE_DB']->query_select |
| Type |
array |
| Name |
url_stub |
| Description |
The stub that links will be passed through |
| Type |
URLPATH |
| Name |
_cache_file |
| Description |
The page name we will be saving customised HTML under |
| Type |
ID_TEXT |
| Name |
last_change_time |
| Description |
The time we did our last change to the data being splurghed (so it can see if we can simply decache instead of deriving) |
| Type |
TIME |
| Name |
first_id |
| Description |
The ID that is at the root of our tree (NULL: db_get_first_id) |
| Default value |
|
| Type |
?AUTO_LINK |
Returns…
| Description |
A string of HTML that represents our splurghing (will desplurgh in the users browser) |
| Type |
string |
function splurgh_master_build($key_name,$map,$url_stub,$_cache_file,$last_change_time,$first_id=NULL)
{
if (is_null($first_id)) $first_id=db_get_first_id();
if (!array_key_exists($first_id,$map)) return '';
if (!has_js()) warn_exit(do_lang_tempcode('MSG_JS_NEEDED'));
require_javascript('javascript_splurgh');
if (is_browser_decacheing())
$last_change_time=time();
$cache_file=zone_black_magic_filterer(get_custom_file_base().'/'.get_zone_name().'/pages/html_custom/'.filter_naughty(user_lang()).'/'.filter_naughty($_cache_file).'.htm');
if ((!file_exists($cache_file)) || (is_browser_decacheing()) || (filesize($cache_file)==0) || ($last_change_time>filemtime($cache_file)))
{
$myfile=@fopen($cache_file,'wt');
if ($myfile===false) intelligent_write_error($cache_file);
$fulltable=array();
$splurgh=_splurgh_do_node($map,$first_id,'',$fulltable,0);
$page=do_template('SPLURGH',array('_GUID'=>'8775edfc5a386fdf2cec69b0fc889952','KEY_NAME'=>$key_name,'URL_STUB'=>$url_stub,'SPLURGH'=>str_replace('"','\'',$splurgh)));
$ev=$page->evaluate();
if (fwrite($myfile,$ev)<strlen($ev)) warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE'));
fclose($myfile);
fix_permissions($cache_file);
sync_file($cache_file);
return $ev;
}
return file_get_contents($cache_file,FILE_TEXT);
}
string _splurgh_do_node(array map, AUTO_LINK node, string chain, array fulltable, integer nest)
Build up the splurgh nodes recursively for given details.
Parameters…
| Name |
map |
| Description |
A row of maps for data we are splurghing; this is probably just the result of $GLOBALS['SITE_DB']->query_select |
| Type |
array |
| Name |
node |
| Description |
The node we are examining |
| Type |
AUTO_LINK |
| Name |
chain |
| Description |
The chain we have built up during our recursion |
| Type |
string |
| Name |
fulltable |
| Description |
Nodes marked as done (so we don't repeat them in other hierarchy positions if it they get repeated) |
| Type |
array |
| Name |
nest |
| Description |
The level of recursion |
| Type |
integer |
Returns…
| Description |
A specially encoded string that represents our splurghing |
| Type |
string |
function _splurgh_do_node($map,$node,$chain,&$fulltable,$nest)
{
$fulltable[$node]=1;
$title=$map[$node]['title'];
$children=$map[$node]['children'];
$out=strval($node).'!'.str_replace('[','[',str_replace(']',']',str_replace(',',',',$title))).',';
if (count($children)>0)
{
$out.='[';
foreach ($children as $child)
{
if ((!array_key_exists($child,$fulltable)) && (array_key_exists($child,$map)))
$out.=_splurgh_do_node($map,$child,$chain.strval($node).'~',$fulltable,$nest+1);
}
$out.='],';
}
return $out;
}
0 reviews: Unrated (average)
There have been no comments yet