Template Class Reference

List of all members.

Public Member Functions

Static Public Member Functions

  • static & singleton ($use_caching=false, $cache_id=NULL, $cache_auto_display=true, $cache_allow_override=true, $cache_prefix="", $retain_expired_cachefiles=false)

Detailed Description

Definition at line 36 of file Template.php.


Member Function Documentation

Template::add_fallback ( dirs = false  ) 

Definition at line 2163 of file Template.php.

02163                                              {
02164                 if ($dirs && !is_array($dirs)) $dirs = array($dirs);
02165                 if (!is_array($dirs)) $dirs = array();
02166                 if (!is_array($this->template_fallback_dirs)) $this->template_fallback_dirs = array();
02167                 $this->template_fallback_dirs = array_merge($this->template_fallback_dirs,$dirs);
02168         }

Template::add_override ( dirs = false  ) 

Definition at line 2175 of file Template.php.

02175                                              {
02176                 if ($dirs && !is_array($dirs)) $dirs = array($dirs);
02177                 if (!is_array($dirs)) $dirs = array();
02178                 if (!is_array($this->template_override_dirs)) $this->template_override_dirs = array();
02179                 $this->template_override_dirs = array_merge($this->template_override_dirs,$dirs);
02180         }

Template::add_relative_override ( dirs = false  ) 

Definition at line 2188 of file Template.php.

02188                                                       {
02189                 if ($dirs && !is_array($dirs)) $dirs = array($dirs);
02190                 if (!is_array($dirs)) $dirs = array();
02191                 if (!is_array($this->template_override_subdirs)) $this->template_override_subdirs = array();
02192                 $this->template_override_subdirs = array_merge($this->template_override_subdirs,$dirs);
02193         }

Template::append ( variable,
value 
)

Definition at line 356 of file Template.php.

Referenced by end_capture().

00356                                           {
00357                 $variable = strtolower($variable);
00358                 $this->variables[$variable] .= $value;
00359         }

Template::arithmetic_op ( variable,
operand,
operator,
postprocess,
postprocessinfo 
)

Definition at line 956 of file Template.php.

Referenced by transform().

00956                                                                                            {
00957                 if (!is_numeric($operand)) $operand = $this->evaluate_expression($operand);
00958                 switch($operator) {
00959                         case "and": $res = ($variable and $operand); break;
00960                         case "xor": $res = ($variable xor $operand); break;
00961                         case "or": $res = ($variable or $operand); break;
00962                         case "mod": $res = $variable % $operand; break;
00963                         case "add": $res = $variable + $operand; break;
00964                         case "sub": $res = $variable - $operand; break;
00965                         case "mul": $res = $variable * $operand; break;
00966                         case "div": $res = ($operand!=0) ? $variable / $operand : '(DIV0)'; break;
00967                         default:
00968                                 return 0;
00969                 }
00970 
00971                 switch($postprocess) {
00972                         case "floor": return floor($res);
00973                         case "ceil": return ceil($res);
00974                         case "round": return round($res,(int) $postprocessinfo);
00975                         default: return $res;
00976                 }
00977         }

Template::assign ( variable,
value = "" 
)

Definition at line 319 of file Template.php.

Referenced by end_capture(), evaluate_assignment(), loop(), and set().

00319                                              {
00320                 if (is_array($variable)) {
00321                         foreach ($variable as $var=>$val) {
00322                                 $var = strtolower($var);
00323                                 $this->variables[$var] = $val;
00324                         }
00325                 } else {
00326                         $this->variables[strtolower($variable)] = $value;
00327                 }
00328         }

Template::assign_by_ref ( variable,
&$  value 
)

Definition at line 335 of file Template.php.

Referenced by loop(), prepare_multipage(), and set_server_variables().

00335                                                   {
00336                 $this->variables[strtolower($variable)] = &$value;
00337         }

Template::begin_capture ( variable  ) 

Definition at line 373 of file Template.php.

00373                                           {
00374                 $this->capturing = $variable;
00375 
00376                 ob_start();
00377                 ob_implicit_flush(0);
00378         }

Template::cache ( id  ) 

Definition at line 1798 of file Template.php.

Referenced by display(), and load_expired_cache().

01798                             {
01799 
01800                 if (!is_dir(CACHE_PATH) || !is_writeable(CACHE_PATH)) {
01801                         $this->error = "Cache path does not exist or is not writable";
01802                         return false;
01803                 }
01804 
01805                 if ($this->nocache_perm_semaphore) {
01806                         if (file_exists($this->nocache_perm_semaphore)) {
01807                                 $this->error = "Permanent no-cache semaphore exists; not caching page";
01808                                 return false;
01809                         }
01810                 }
01811                 if ($this->nocache_temp_semaphore) {
01812                         if (file_exists($this->nocache_temp_semaphore)) {
01813                                 if (filectime($this->nocache_temp_semaphore)+$this->nocache_temp_timeout<time()) {
01814                                         @unlink($this->nocache_temp_semaphore);
01815                                 } else {
01816                                         $this->error = "Permanent no-cache semaphore exists; not caching page";
01817                                         return false;
01818                                 }
01819                         }
01820                 }
01821                 $this->nocache_perm_semaphore = $permanent;
01822                 $this->nocache_temp_semaphore = $temporary;
01823 
01824 
01825                 $cache_content_type = $this->cache_content_type ? '_' . str_replace('/','!',$this->cache_content_type) : '';
01826                 $expire_time = time() + $this->cache_expire_time;
01827                 $cachefile = CACHE_PATH."/dtcache_".$this->cache_prefix.md5($id)."{$cache_content_type}_{$expire_time}.dat";
01828 
01829                 $fp = @fopen($cachefile,"w");
01830                 if ($fp) {
01831                         fwrite($fp,$this->output);
01832                         fclose($fp);
01833                         return true;
01834                 } else {
01835                         $this->error = "Unable to create cache file: [$cachefile]";
01836                         return false;
01837                 }
01838         }

Template::clear_cache ( prefix = ""  ) 

Definition at line 1945 of file Template.php.

01945                                          {
01946                 $cachename = "dtcache_".$prefix;
01947                 $cachename_len = strlen($cachename);
01948 
01949                 // search the cache path for a valid cached copy of the page
01950                 $d = dir(CACHE_PATH);
01951 
01952                 while (false !== ($entry = $d->read())) {
01953 
01954                         // did this filename begin with the cache filename stub?
01955                         if (substr($entry,0,$cachename_len)==$cachename) {
01956                                 @unlink(CACHE_PATH.$entry);
01957                         }
01958                 }
01959                 $d->close();
01960         }

Template::clear_expired_cache (  ) 

Definition at line 1932 of file Template.php.

Referenced by load_cache().

01932                                        {
01933                 if (is_array($this->expired_cachefiles)) {
01934                         foreach ($this->expired_cachefiles as $expired_cachefile=>$content_type) {
01935                                 @unlink($expired_cachefile);
01936                         }
01937                 }
01938         }

Template::compare ( expr1,
expr2,
data1,
data2 
)

Definition at line 1535 of file Template.php.

Referenced by preg_compare().

01535                                                       {
01536 //      echo $this->variables["existingaccount"];
01537 //      echo "<span style='color: red'>[$expr1/$expr2/$data1/$data2]</span>";
01538 
01539                 $data1 = $this->evaluate_expression($data1);
01540                 $data2 = $this->evaluate_expression($data2);
01541                 return $this->conditional($expr1."==".$expr2,"$data1{else}$data2");
01542         }

Template::compound_evaluation ( expression  ) 

Definition at line 1327 of file Template.php.

Referenced by evaluate_condition().

01327                                                   {
01328                 $expression = substr($expression,1);
01329                 if (substr($expression,-1)==')') $expression = substr($expression,0,strlen($expression)-1);
01330 
01331                 $conditions = preg_split('/\)\s*(or|and|\&\&|\|\|)\s*\(/i',$expression,-1,PREG_SPLIT_DELIM_CAPTURE);
01332 
01333                 $first = true;
01334                 $lastresult = NULL;
01335                 $lastoperator = '';
01336 
01337                 while (count($conditions)) {
01338                         $condition = trim(array_shift($conditions));
01339 
01340                         $result = $this->evaluate_condition($condition);
01341 
01342                         if (count($conditions)) $operator = strtolower(trim(array_shift($conditions)));
01343 
01344                         if ($first) {
01345                                 //echo "[$condition]("; var_dump($result); echo ")";
01346                                 $lastresult = $result;
01347                                 $first = false;
01348                         } else {
01349                                 //echo "[$lastoperator][$condition]("; var_dump($result); echo ")";
01350                                 switch($lastoperator) {
01351                                         case 'or':
01352                                         case '||':
01353                                                 $lastresult = $lastresult || $result;
01354                                                 break;
01355                                         case 'and':
01356                                         case '&&':
01357                                                 $lastresult = $lastresult && $result;
01358                                                 break;
01359                                         default:
01360                                                 $lastresult = false;
01361                                                 break;
01362                                 }
01363                         }
01364                         $lastoperator = $operator;
01365                 }
01366 
01367                 //echo "==("; var_dump($result); echo ")<br>";
01368 
01369                 return $lastresult;
01370         }

Template::conditional ( condition,
expr,
tagelse = "else",
tagelseif = "elseif" 
)

Definition at line 1482 of file Template.php.

Referenced by compare(), preg_conditional_check(), and preg_conditional_if().

01482                                                                                    {
01483                 //echo "<br /><br /><span style='color: #0000FF'>conditional((<span style='color: #000099'>$condition</span>,<span style='color: #990099'>$expr</span>,<span style='color: #009999'>$tagelse</span>))</span><br /><br />";
01484                 //$expr = str_replace('\"','"',$expr);
01485                 //$condition = str_replace('\"','"',$condition);
01486 
01487                 //$expr = stripslashes($expr);
01488                 //$condition = stripslashes($condition);
01489 
01490                 $expr1 = '';
01491                 $expr2 = '';
01492 
01493                 $iselseif = preg_match("/^([\s\S]*?)\{".$tagelseif." (.*?)\}([\s\S]*)$/",$expr,$matches);
01494                 if ($iselseif) {
01495                         $expr1 = &$matches[1];
01496                         $condelseif = $matches[2];
01497                         $expr2 = &$matches[3];
01498                         $iselse = true;
01499                 } else {
01500                         $iselse = preg_match("/^([\s\S]*)\{".$tagelse."\}([\s\S]*)$/",$expr,$matches);
01501                         if ($iselse) {
01502                                 $expr1 = &$matches[1];
01503                                 $expr2 = &$matches[2];
01504                         }
01505                 }
01506                 if (!$iselse) {
01507                         $expr2 = &$expr;
01508                 }
01509 
01510                 //echo "<span style='color: #550000'>[[<span style='color: #FF0000'>$expr</span> ]][[ <span style='color: #FF0000'>$expr2</span>]]</span>";
01511 
01512                 //echo "[<span style='color: red'>$expr1</span>]";
01513                 //echo "[<span style='color: green'>$expr2</span>]";
01514                 $evaltrue = $this->evaluate_condition($condition);
01515 
01516 //              echo "=======\nif ($condition) {\n$expr1\n} else {\n$expr2\n}\nCondition: ".($evaltrue?"yes":"no")."\n=======\n";
01517 
01518 //              echo "[$evaltrue::$iselse]<br>\n[$expr1::$expr2::$expr]";
01519 
01520                 if ($evaltrue==($iselse>0)) {
01521                         // if the expression evaluated to true, OR
01522                         // the expression evaluated to false and there was no {else} tag
01523                         return $this->parse_tags($expr1);
01524                 } else {
01525                         // if the expression evaluated to false, OR
01526                         // the expression evaluated to true and there was an {else} tag
01527                         if ($iselseif>0) {
01528                                 //return $this->conditional($condelseif,$expr2);
01529                                 return $this->conditional($condelseif,$expr2,$tagelse,$tagelseif);
01530                         }
01531                         return $this->parse_tags($expr2);
01532                 }
01533         }

Template::custom_plugin ( name,
func,
parameters,
data = false 
)

Definition at line 1609 of file Template.php.

01609                                                                       {
01610                 if ($data!==false) $data = stripslashes($data);
01611                 $parameters = stripslashes($parameters);
01612                 $parameters .= " ";
01613                 if (!preg_match_all("/(.*?)\=(\"[^\"?]*\"|[^\s?]+)\s+/i",$parameters,$params,PREG_SET_ORDER)) {
01614                         $params = array();
01615                 }
01616                 $parameter_list = array();
01617 
01618                 foreach ($params as $pkey=>$param) {
01619                         list(,$k,$v) = $param;
01620                         $parameter_list[$k] = $this->evaluate_expression($v);
01621                 }
01622                 if (is_callable($func)) {
01623                         $output = call_user_func($func,$parameter_list,$data);
01624                 } else {
01625                         $output = "[Error: Custom plug-in function {$func}() does not exist]";
01626                 }
01627 
01628                 return $output;
01629         }

Template::date_select ( method,
data 
)

Definition at line 752 of file Template.php.

Referenced by transform().

00752                                             {
00753                 $date = $data;
00754                 array_shift($method); // get rid of the actual 'dateselect' string
00755                 $basename = array_shift($method);
00756                 $flags = $method;
00757 
00758                 $allownull = in_array("allownull",$flags);
00759                 $datetype = array_shift($flags);
00760                 $options = array();
00761                 $null_date = array(
00762                         "mon"=>-1,
00763                         "mday"=>-1,
00764                         "year"=>-1,
00765                         "hours"=>-1,
00766                         "minutes"=>-1
00767                 );
00768 
00769 
00770                 foreach ($flags as $k=>$flag) {
00771                         if (strpos($flag,'=')!==false) {
00772                                 list($flagname,$flagvalue) = explode('=',$flag);
00773                                 if (substr($flagvalue,0,1)=='$') $flagvalue = $this->lookup($flagvalue);
00774                                 $options[$flagname] = $flagvalue;
00775                         }
00776                 }
00777 
00778                 if (!$options['minyear']) $options['minyear'] = date('Y');
00779                 if (!$options['maxyear']) $options['maxyear'] = date('Y')+10;
00780 
00781                 if (substr($date,0,1)=='$') $date = $this->lookup($date);
00782                 switch($datetype) {
00783                         case "datetime":
00784                                 $time = $this->mysql_datetime_to_time($date);
00785                                 break;
00786                         case 'nulldatetime':
00787                                 list($datearray["year"],$datearray["mon"],$datearray["mday"],$datearray["hours"],$datearray["minutes"],$datearray["seconds"]) = sscanf($date,'%04d-%02d-%02d %02d:%02d:%02d');
00788                                 break;
00789                         case "timestamp":
00790                                 $time = $this->mysql_timestamp_to_time($date);
00791                                 break;
00792                         case "unix":
00793                                 $time = (int) $date;
00794                                 break;
00795                         case "null":
00796                                 $time = -1;
00797                                 break;
00798                         case "now":
00799                                 $time = time();
00800                                 break;
00801                         default:
00802                                 return "Invalid date type: $datetype";
00803                                 break;
00804                 }
00805                 if ($datearray) {
00806                         $date = $datearray;
00807                 } elseif ($time<=0) {
00808                         $date = $null_date;
00809                 } else {
00810                         $date = getdate($time);
00811                 }
00812 
00813 
00814                 $months = array(
00815                         $this->xlat("Jan"),
00816                         $this->xlat("Feb"),
00817                         $this->xlat("Mar"),
00818                         $this->xlat("Apr"),
00819                         $this->xlat("May"),
00820                         $this->xlat("Jun"),
00821                         $this->xlat("Jul"),
00822                         $this->xlat("Aug"),
00823                         $this->xlat("Sep"),
00824                         $this->xlat("Oct"),
00825                         $this->xlat("Nov"),
00826                         $this->xlat("Dec")
00827                 );
00828 
00829                 $output = "";
00830                 if (!in_array("timeonly",$flags)) {
00831 
00832                         if (in_array("nomonth",$flags)) {
00833                                 $output .= "<input type='hidden' name='{$basename}_month' id='{$basename}_month' value='1'>\n";
00834                         } else {
00835                                 $output = "<select name='{$basename}_month' id='{$basename}_month' size='1'>\n";
00836                                 if ($allownull) $output .= "<option value='0' /> ---\n";
00837                                 foreach ($months as $k=>$month) {
00838                                         $output .= "<option value='".($k+1)."'".($k+1==$date["mon"]?" selected='selected'":"")." /> $month\n";
00839                                 }
00840                                 $output .= "</select>\n";
00841                         }
00842 
00843                         if (in_array("noday",$flags)) {
00844                                 $output .= "<input type='hidden' name='{$basename}_day' id='{$basename}_day' value='1'>\n";
00845                         } else {
00846                                 $output .= "<select name='{$basename}_day' id='{$basename}_day' size='1'>\n";
00847                                 if ($allownull) $output .= "<option value='0' /> --\n";
00848                                 for ($i=1; $i<32; $i++) {
00849                                         $output .= "<option value='$i'".($i==$date["mday"]?" selected='selected'":"")." /> $i\n";
00850                                 }
00851                                 $output .= "</select>\n";
00852                         }
00853 
00854                         if (in_array("noyear",$flags)) {
00855                                 $output .= "<input type='hidden' name='{$basename}_year' id='{$basename}_year' value='".date('Y')."'>\n";
00856                         } else {
00857                                 $output .= "<select name='{$basename}_year' id='{$basename}_year' size='1'>\n";
00858                                 if ($allownull) $output .= "<option value='0' /> ----\n";
00859 
00860                                 for ($i=$options['minyear']; $i<=$options['maxyear']; $i++) {
00861                                         $output .= "<option value='$i'".($i==$date["year"]?" selected='selected'":"")." /> $i\n";
00862                                 }
00863                                 $output .= "</select>\n";
00864                         }
00865                 }
00866 
00867                 if (in_array("showtime",$flags) || in_array("timeonly",$flags)) {
00868                         $houronly = in_array("houronly",$flags);
00869                         $ampm = in_array("ampm",$flags);
00870                         $anytime = in_array("anytime",$flags);
00871 
00872                         if (!in_array("timeonly",$flags)) $output .= "&nbsp;";
00873                         $output .= "<select name='{$basename}_hour' id='{$basename}_hour' size='1'>\n";
00874                         if ($allownull) $output .= "<option value='' /> ".($anytime ? "Any Time" : "--")."\n";
00875 
00876                         $hourvalue = (int) $date["hours"];
00877                         if ($ampm) {
00878                                 if ($hourvalue==0) {
00879                                         $hourvalue = 12;
00880                                 } elseif ($hourvalue>11) {
00881                                         $hourvalue -= 12;
00882                                 }
00883                         }
00884 
00885                         for ($i=($ampm?1:0); $i<($ampm?13:24); $i++) {
00886                                 $h = $i;
00887                                 $timeformat = ($h<10?"0":"").$h.($houronly?":00":"");
00888 
00889                                 $output .= "<option value='$i'".($i==$hourvalue?" selected='selected'":"")." /> $timeformat\n";
00890                         }
00891 
00892                         $output .= "</select>\n";
00893 
00894                         if (!$houronly) {
00895                                 $output .= " : <select name='{$basename}_min' id='{$basename}_min' size='1'>\n";
00896                                 if ($allownull) $output .= "<option value='' /> --\n";
00897                                 for ($i=0; $i<60; $i++) {
00898                                         $output .= "<option value='$i'".($i==$date["minutes"]?" selected='selected'":"")." /> ".($i<10?"0":"").$i."\n";
00899                                 }
00900                                 $output .= "</select>\n";
00901                         }
00902 
00903                         if ($ampm) {
00904                                 $ampmvalue = $date['hours']>11 ? 1 : 0;
00905                                 $options = array(
00906                                         0=>$this->xlat('AM'),
00907                                         1=>$this->xlat('PM')
00908                                 );
00909 
00910                                 $output .= " <select name='{$basename}_ampm' id='{$basename}_ampm' size='1'>\n";
00911                                 foreach ($options as $k=>$v) {
00912                                         $output .= "<option value='{$k}'".($ampmvalue==$k?" selected='selected'":"")." /> {$v}\n";
00913                                 }
00914                                 $output .= "</select>\n";
00915                         }
00916                 }
00917 
00918                 return $output;
00919 
00920         }

Template::display ( template_file,
absolute_path = false 
)

Definition at line 1748 of file Template.php.

01748                                                                 {
01749                 if (!$this->loaded = $this->load_template($template_file,$absolute_path)) return false;
01750 
01751 
01752                 $this->parse();
01753                 echo $this->output;
01754 
01755 
01756                 // if caching is enabled, then cache the document
01757                 if ($this->cache_expire_time && $this->auto_store_cache) $this->cache($this->cache_id);
01758 
01759                 if (!(defined('DISABLE_TEMPLATE_CACHING') && DISABLE_TEMPLATE_CACHING) && (defined('TEMPLATE_CACHE_DEBUG') && TEMPLATE_CACHE_DEBUG) ) {
01760                         echo "<div align='center'>Cache miss (\"$this->cache_id\"".($this->cache_prefix?"; prefix: \"{$this->cache_prefix}\"":"").")</div>";
01761                 }
01762 
01763 
01764                 return true;
01765         }

Template::display_cached_page (  ) 

Definition at line 124 of file Template.php.

Referenced by Template().

00124                                        {
00125                 if ($this->cache_content_type && !headers_sent()) Header('Content-type: '.$this->cache_content_type);
00126                 echo $this->output;
00127                 if (TEMPLATE_CACHE_DEBUG) {
00128                         echo "<div align='center'>Cache hit (\"$this->cache_id\"".($this->cache_prefix?"; prefix: \"{$this->cache_prefix}\"":"").")</div>";
00129                 }
00130         }

Template::end_capture ( append = false  ) 

Definition at line 384 of file Template.php.

00384                                             {
00385                 if ($append) {
00386                         $this->append($this->capturing,ob_get_contents());
00387                 } else {
00388                         $this->assign($this->capturing,ob_get_contents());
00389                 }
00390                 ob_end_clean();
00391         }

Template::evaluate_assignment ( expression  ) 

Definition at line 1544 of file Template.php.

01544                                                   {
01545 
01546                 if (preg_match("/\\\$([A-Za-z0-9\[\]\\\$_\.]+)\=((\\\$[A-Za-z0-9\[\]\\\$_\.]+)|(\".*?\")|([0-9]+))/",$expression,$matches)) {
01547                         list(,$variable,$assignment) = $matches;
01548                         $assignment = $this->evaluate_expression($assignment);
01549                         $this->assign($variable,$assignment);
01550                         return array($variable,$assignment);
01551                 } else {
01552                         return array("[*INVALID_EXPRESSION*]","$expression");
01553                 }
01554         }

Template::evaluate_condition ( condition  ) 

Definition at line 1420 of file Template.php.

Referenced by compound_evaluation(), conditional(), lookup(), and preg_include_template().

01420                                                 {
01421                 $this->debug_conditions = false;
01422 
01423                 // compound expression
01424                 if (substr($condition,0,1)=='(') return $this->compound_evaluation($condition);
01425 
01426 //      We made this change so that things like {if $txn.description|contains:"My string">0} would be possible
01427 //              if (preg_match("/^(\\\$[A-Za-z0-9\[\]\\\$_\.\|\:]+|\".*?\"|[0-9]+)([>|<|\=]?[\=]{0,2}|\!\=)(\\\$[A-Za-z0-9\[\]\\\$_\.\|\:]+|\".*?\"|[0-9]+)$/",$condition,$matches)) {
01428                 if (
01429                         preg_match(
01430                                 "/^".
01431                                         "(\\\$[A-Za-z0-9\[\]\\\$_\.\|\:\\\"\s]+|\".*?\"|[0-9]+)".       // expr1
01432                                         "(?:".
01433 //                                              "([>|<|\=]?[\=]{0,2}|\!\=)".                                                          // operator
01434                                                 "([><\=]{1,2}|\!\=)".                                                                         // operator
01435                                                 "(\\\$[A-Za-z0-9\[\]\\\$_\.\|\:]+|\".*?\"|[0-9]+)".             // expr2
01436                                         ")?".
01437                                 "$/"
01438                                 ,
01439                                 $condition,
01440                                 $matches
01441                         )
01442                 ) {
01443                         @list(,$expr1,$operator,$expr2) = $matches;
01444 
01445                         if ($this->debug_conditions) echo "[$expr1::$operator::$expr2]\n";
01446 
01447                         $expr1 = $this->evaluate_expression($expr1);
01448                         $expr2 = $this->evaluate_expression($expr2);
01449 
01450                         if ($this->debug_conditions) echo "[$expr1::$operator::$expr2]\n";
01451 
01452                         $evaltrue = false;
01453                         // could have used eval(), but that would generate an error
01454                         // if $operator was invalid... so this is easier.
01455                         switch ($operator) {
01456                                 case "===":             $evaltrue = ($expr1===$expr2); break;
01457                                 case "==":
01458                                 case "=":               $evaltrue = ($expr1==$expr2); break;
01459                                 case "<":               $evaltrue = ($expr1<$expr2); break;
01460                                 case "<=":      $evaltrue = ($expr1<=$expr2); break;
01461                                 case ">":               $evaltrue = ($expr1>$expr2); break;
01462                                 case ">=":      $evaltrue = ($expr1>=$expr2); break;
01463                                 case "<>":
01464                                 case "!=":      $evaltrue = ($expr1!=$expr2); break;
01465                                 case "":        $evaltrue = $expr1; break;
01466                                 default:
01467                                         echo "[Invalid operator: $operator]";
01468                                         return false;
01469                                         // TODO: Error! invalid comparison operator
01470                                         break;
01471                         }
01472 
01473                         if ($this->debug_conditions) echo "[".($evaltrue?"true":"false")."]<br>\n";
01474                         return $evaltrue;
01475                 } else {
01476 //              echo "nope[$condition]";
01477 
01478                         return $this->evaluate_expression($condition);
01479                 }
01480         }

Template::evaluate_expression ( expr  ) 

Definition at line 1396 of file Template.php.

Referenced by arithmetic_op(), compare(), custom_plugin(), evaluate_assignment(), evaluate_condition(), lookup(), and transform().

01396                                             {
01397                 if (preg_match("/^\"(.*?)\"$/",$expr,$matches)) {
01398                         return $matches[1];
01399 
01400                 } elseif (preg_match("/^(\\\$[A-Za-z0-9\[\]\\\$_\.]+|\".*?\"|[0-9]+)([\+|\-|\/|\*])(\\\$[A-Za-z0-9\[\]\\\$_\.]+|\".*?\"|[0-9]+)$/",$expr,$matches)) {
01401                         return "expression";
01402 
01403                 } elseif (substr($expr,0,1)=="$") {
01404                         return $this->lookup($expr);
01405                         /*
01406                         $expr = strtolower(substr($expr,1));
01407                         return $this->variables[$expr];
01408                         */
01409 
01410                 } elseif (is_numeric($expr)) {
01411                         return (int) $expr;
01412 
01413                 } else {
01414                         // eh?! invalid expression!
01415                         return "";
01416 
01417                 }
01418         }

Template::get ( template_file,
absolute_path = false 
)

Definition at line 1771 of file Template.php.

01771                                                             {
01772                 if (!$this->loaded = $this->load_template($template_file,$absolute_path)) return false;
01773 
01774                 $this->parse();
01775                 return $this->output;
01776         }

Template::get_from_var ( template  ) 

Definition at line 1783 of file Template.php.

01783                                          {
01784                 $this->template = $template;
01785 
01786                 $this->parse();
01787                 return $this->output;
01788         }

Template::get_template_filename ( filename,
absolute_path = false 
)

Definition at line 185 of file Template.php.

Referenced by include_template(), and load_template().

00185                                                                          {
00186                 if ($this->template_dir && !$absolute_path) {
00187 
00188                         $pathname = false;
00189 
00190                         if ($this->template_override_dirs && count($this->template_override_dirs)) {
00191                                 reset($this->template_override_dirs);
00192                                 foreach ($this->template_override_dirs as $k=>$dir) {
00193                                         if (substr($dir,-1)!="/") $dir .= "/";
00194                                         $pathname = $dir.$filename;
00195                                         if (is_readable($pathname)) {
00196                                                 break;
00197                                         } else {
00198                                                 $pathname = '';
00199                                         }
00200                                 }
00201                         }
00202 
00203                         if ($this->template_override_subdirs && count($this->template_override_subdirs)) {
00204                                 if (substr($this->template_dir,-1)!="/") $this->template_dir .= "/";
00205 
00206                                 reset($this->template_override_subdirs);
00207                                 foreach ($this->template_override_subdirs as $k=>$dir) {
00208                                         if (substr($dir,-1)!="/") $dir .= "/";
00209 
00210                                         //      $pathname = $this->template_dir . $dir . $filename;
00211 
00212                                         // this change ensures that relative {include}'s will handle override subdirs
00213                                         // in a sane manner -- with a template override dir of "override/" and a template
00214                                         // dir of "/templates/", using {include "../whatever.tpl"} would yield:
00215                                         //      /templates/custom/../whatever.tpl
00216                                         // ...which doesn't make sense, given that ../ should be relative to templates/.
00217                                         // Using this new technique yields:
00218                                         //      /templates/../custom/whatever.tpl
00219                                         // ...which makes more sense.
00220                                         $pathname = $this->template_dir . $filename;
00221                                         $pathname = dirname($pathname) . '/' . $dir . basename($pathname);
00222 
00223                                         if (is_readable($pathname)) {
00224                                                 break;
00225                                         } else {
00226                                                 $pathname = '';
00227                                         }
00228                                 }
00229                         }
00230 
00231                         if (!strlen($pathname)) {
00232                                 // get the full path to the template based on $this->template_dir
00233                                 if (substr($this->template_dir,-1)!="/") $this->template_dir .= "/";
00234                                 $pathname = $this->template_dir.$filename;
00235 
00236                                 if ($this->template_fallback_dirs && count($this->template_fallback_dirs)) {
00237                                         // if a fallback template directory has been set, and the template was not
00238                                         // found in $this->template_dir, then check the $this->template_fallback_dir
00239                                         // directory
00240                                         if (!is_readable($pathname)) {
00241                                                 reset($this->template_fallback_dirs);
00242                                                 foreach ($this->template_fallback_dirs as $k=>$dir) {
00243                                                         if (substr($dir,-1)!="/") $dir .= "/";
00244                                                         $pathname = $dir.$filename;
00245                                                         if (is_readable($pathname)) break;
00246                                                 }
00247                                         }
00248                                 }
00249                         }
00250                         $filename = $pathname;
00251 
00252                 } elseif (defined("TEMPLATE_BASE") && !$absolute_path) {
00253                         $filename = TEMPLATE_BASE.$filename;
00254                 }
00255 
00256                 return $filename;
00257         }

Template::include_template ( filename  ) 

Definition at line 259 of file Template.php.

Referenced by preg_include_template().

00259                                              {
00260                 if (substr($filename,0,2)=='./') {
00261                         $currentdir = dirname($this->current_filename);
00262                         if (substr($currentdir,-1)!='/') $currentdir .= '/';
00263                         $filename = $currentdir . substr($filename,2);
00264 
00265                         $absolute = true;
00266                 } else {
00267                         $absolute = false;
00268                 }
00269 
00270                 $filename = $this->get_template_filename($filename,$absolute);
00271                 $result = $this->read_template($filename);
00272                 if ($result===false) $result = "";
00273 
00274         return $result;
00275         }

Template::load_cache ( id  ) 

Definition at line 1847 of file Template.php.

Referenced by Template().

01847                                  {
01848 
01849                 // Set the stub for the filename (eg: dtcache_ffffffffffffff_<expiretime>.dat).
01850                 // Note that the expiry time is stored right in the filename to increase performance.
01851                 $cachename = "dtcache_".$this->cache_prefix.md5($id)."_";
01852                 $cachename_len = strlen($cachename);
01853                 $cachefile = "";
01854 
01855                 if (!is_dir(CACHE_PATH) || !is_readable(CACHE_PATH)) return false;
01856 
01857                 // maintain a list of expired cached versions of this page for removal
01858                 $this->expired_cachefiles = array();
01859 
01860                 // search the cache path for a valid cached copy of the page
01861                 $d = dir(CACHE_PATH);
01862                 while (false !== ($entry = $d->read())) {
01863 
01864                         // did this filename begin with the cache filename stub?
01865                         if (substr($entry,0,$cachename_len)==$cachename) {
01866 
01867                                 // strip out the prefix and .dat suffix
01868                                 $page_cache_data = substr($entry,$cachename_len,strlen($entry) - $cachename_len - 4);
01869 
01870                                 // determine whether or not it contains a mime type
01871                                 if (($p = strpos($page_cache_data,'_'))!==false) {
01872                                         $cache_content_type = str_replace('!','/',substr($page_cache_data,0,$p));
01873                                         $expire_time = (int) substr($page_cache_data,$p+1);
01874                                 } else {
01875                                         $expire_time = (int) $page_cache_data;
01876                                 }
01877 
01878                                 if ($expire_time > time()) {
01879                                         // if the expiry date is later than now, we've got a cache hit
01880                                         $cachefile = CACHE_PATH.$entry;
01881                                         $this->cache_content_type = $cache_content_type;
01882                                         break;
01883                                 } else {
01884                                         // otherwise, this is an expired cache file, so we may as well remove
01885                                         // it to increase performance on subsequent calls
01886                                         $this->expired_cachefiles[ CACHE_PATH.$entry ] = $cache_content_type;
01887                                 }
01888                         }
01889                 }
01890                 $d->close();
01891 
01892                 // if a cachefile was found above, load and return it
01893                 if ($cachefile) {
01894                         $this->clear_expired_cache();
01895                         return $this->load_contents($cachefile);
01896 
01897                 // otherwise, make a note of the expired cache files that were available;
01898                 // we may need to fall back to one of these if the MySQL server is too busy
01899                 } else {
01900                         if (!$this->retain_expired_cachefiles) $this->clear_expired_cache();
01901                 }
01902                 return false;
01903         }

Template::load_contents ( filename  ) 

Definition at line 1969 of file Template.php.

Referenced by load_cache(), and load_expired_cache().

01969                                           {
01970                 $this->output = "";
01971 
01972                 if ($this->debug_load) echo "Template::load_contents({$filename})\n";
01973                 $fp = fopen($filename,"r");
01974                 if ($fp) {
01975                         while (!feof($fp)) {
01976                                 $this->output .= fread($fp,4096);
01977                         }
01978                         fclose($fp);
01979 
01980                         return true;
01981                 } else {
01982                         $this->error = "Input file $filename not found";
01983                         return false;
01984                 }
01985         }

Template::load_expired_cache ( recache_time = false  ) 

Definition at line 1908 of file Template.php.

01908                                                            {
01909                 if (!$this->expired_cachefiles) return false;
01910 
01911                 $keys = array_keys($this->expired_cachefiles);
01912                 sort($keys);
01913                 $lastkey = array_pop($keys);
01914 
01915                 $lasttype = $this->expired_cachefiles[ $lastkey ];
01916 
01917                 $cachefile = $lastkey;
01918 
01919                 $ok = $this->load_contents($cachefile);
01920                 if ($ok && $recache_time) {
01921                         $this->cache_content_type = $lasttype;
01922                         $this->set_cache_lifetime($recache_time);
01923                         $this->cache($this->cache_id);
01924                 }
01925                 return $ok;
01926         }

Template::load_plugin ( name  ) 

Definition at line 2146 of file Template.php.

02146                                     {
02147                 $filename = dirname(__FILE__)."/plugin_{$name}.php";
02148                 if (is_readable($filename) && include($filename)) {
02149                         $registerfunc = "dt_register_{$name}";
02150                         if (function_exists($registerfunc)) {
02151                                 return $registerfunc($this);
02152                         }
02153                 }
02154 
02155                 return false;
02156         }

Template::load_template ( filename,
absolute_path = false 
)

Definition at line 277 of file Template.php.

Referenced by display(), and get().

00277                                                                  {
00278                 $filename = $this->get_template_filename($filename,$absolute_path);
00279                 $this->template = $this->read_template($filename);
00280                 if ($this->template===false) {
00281                         $this->template = "";
00282                 } else {
00283                         $this->current_filename = $filename;
00284                 }
00285                 return $this->template;
00286         }

Template::lookup ( variable  ) 

Definition at line 438 of file Template.php.

Referenced by date_select(), evaluate_expression(), loop(), preg_lookup(), transform(), and var_or_lit().

00438                                    {
00439                 if (substr($variable,0,1)==" ") { return "{".$variable."}"; } // not to be parsed!
00440 
00441                 /* NOTE: If you add any new values for $x, be sure to update
00442                  * the ::var_or_lit() method's $specialchars variable above.
00443                  */
00444                 $x = substr($variable,0,1);
00445                 if ($x=="=") {
00446                         // gettext translation
00447 //                      $variable = stripslashes($variable);
00448                         if (preg_match("/^\=\"(.*?)\"(?:\,(.*?))?$/",$variable,$match)) {
00449                                 @list(,$msg,$arguments) = $match;
00450                         } else {
00451                                 $msg = $this->lookup(substr($variable,1));
00452                         }
00453 
00454 /*
00455                         if (strpos($msg,'settings are')!==false ){
00456                                 var_dump($arguments);
00457                                 die($msg);
00458 
00459                         }
00460 */
00461 
00462                         $msg = $this->xlat($msg);
00463                         if ($arguments) {
00464                                 //
00465                                 // REMOVED THIS:
00466                                 //
00467                         //$arguments .= ",";
00468                         //preg_match_all("/(=?\".*?\"|[0-9]+|=?\\\$[A-Za-z0-9_|\[\]\\\$_\.]+)\,/",$arguments,$args,PREG_PATTERN_ORDER);
00469                         //$args = $args[1];
00470                                 //
00471                                 // AND REPLACED WITH THIS:
00472                                 //
00473                         $args = preg_split('/,(?=[\"\=\$])/',$arguments);
00474                         //
00475                         // so that you could do things like {="This is the date: %d",$mydate|mysqldatetime:formatted:M_d,_Y}
00476                         // ..otherwise the comma would have been interpreted as another parameter
00477 
00478                         if (is_array($args)) {
00479                                 foreach ($args as $k=>$v) {
00480                                         $translate_arg = (substr($v,0,1)=='=');
00481                                         if ($translate_arg) $v = substr($v,1);
00482 
00483                                         $v = $this->evaluate_expression($v);
00484 
00485                                         if ($translate_arg) $v = $this->xlat($v);
00486 
00487                                         $args[$k] = $v;
00488                                 }
00489                                 }
00490                         $msg = @vsprintf($msg,$args);
00491                         }
00492                         $res = $msg;
00493 
00494                 } elseif ($x=="$") {
00495                         // variable
00496                         $transform = "";
00497 
00498                         // remove the $
00499                         $variable = substr($variable,1);
00500 
00501                         $p = strpos($variable,"|");
00502                         if ($p!==false) {
00503                                 $transform = substr($variable,$p+1);
00504                                 $variable = substr($variable,0,$p);
00505                         }
00506 
00507                         // if the variable is, for example, {$foo[$bar]}, parse out the portion(s) in brackets...
00508                         // essentially, if $bar = harf, this will be changed to {$foo.harf}, then parsed below
00509                         while(($p = strpos($variable,"["))!==false) {
00510                                 $q = strpos($variable,"]");
00511                                 if ($q<$p) break; // prevent problems on weirdness like $foo]bar or something
00512 
00513                                 $subvar = substr($variable,$p+1,$q-$p-1);
00514                                 $subvar = $this->evaluate_expression($subvar);
00515 
00516                                 $var_pre = substr($variable,0,$p);
00517                                 $var_post = substr($variable,$q+1);
00518                                 $variable = $var_pre.".".$subvar.$var_post;
00519                         }
00520 
00521                         // if the variable is {$array.element}, we want the "array" portion in lowercase
00522                         // but the "element" portion must retain its case (as array keys are case sentitive)
00523                         if (($p = strpos($variable,"."))!==false) {
00524                                 $v = substr($variable,0,$p);
00525                                 $variable = strtolower($v).substr($variable,$p);
00526                         } else {
00527                                 $variable = strtolower($variable);
00528                         }
00529 
00530                         $varset = false;
00531 
00532                         // if variable contains periods, it's referencing elements of an array (eg: {$client.name})
00533                         if (strpos($variable,".")!==false) {
00534                                 $keys = explode(".",$variable);
00535 
00536                                 switch($keys[0]) {
00537                                         case '_constants':
00538                                                 $varset = @defined($keys[1]);
00539                                                 $res = $varset? @constant($keys[1]) : '';
00540                                                 break;
00541                                         default:
00542                                                 $res = isset($this->variables[$keys[0]]) ? $this->variables[$keys[0]] : NULL;
00543                                                 $varset = isset($this->variables[$keys[0]]);
00544 
00545                                                 if ($varset) {
00546                                                         $needclosebracket = false;
00547                                                         $bracketkey = "";
00548 
00549                                                         for ($i=1; $i<count($keys); $i++) {
00550                                                                 $key = $keys[$i];
00551 
00552                                                                 // the following line allows things like $document.elements.$elementno.name
00553                                                                 if (substr($key,0,1)=="$") $key = $this->lookup($key);
00554                                                                 if (is_object($res)) {
00555                                                                         $res = $res->$key;
00556                                                                 } else {
00557                                                                   $res = (isset($res[(string)$key])) ? $res[(string)$key] : (is_int($key) && isset($res[$key])) ? $res[$key] : NULL;
00558                                                                 }
00559                                                         }
00560                                                 }
00561                                 }
00562                         } else {
00563                                 $varset = isset($this->variables[$variable]);
00564                                 $res = ($varset) ? $this->variables[$variable] : '';
00565                         }
00566                         if (!$varset) {
00567                                 // variable wasn't set!
00568                                 $this->error = "Undefined variables encountered during parsing";
00569                                 $this->warnings .= "Template variable {$variable} undefined";
00570                                 if ($this->display_undefined)
00571                                         $res = "{Undefined:".strtoupper($variable)."}";
00572                         }
00573                         if ($transform) {
00574                                 $res = $this->transform($transform,$res);
00575                         }
00576 
00577                 } elseif ($x=="*") {
00578                         if (substr($variable,-1)=="*") $res="";
00579                 } elseif ($x=='?') {
00580                         if (preg_match(
00581                                 '/^'.
00582                                         '\?('.
00583                                                 '(?:\$?[A-Za-z0-9_\.\|]+)'.
00584                                                         '(?:[>|<|\=]?[\=]?)'.
00585                                                 '(?:\".*\"|\$?[A-Za-z0-9_\.\|]+)'.
00586                                         ')'.
00587                                         '\?'.
00588                                                 '(\".*\"|\$?[A-Za-z0-9_\.\|]+)'.
00589                                         '\:'.
00590                                                 '(\".*\"|\$?[A-Za-z0-9_\.\|]+)'.
00591                                 '$/',$variable,$match)
00592                         ) {
00593                                 list(,$condition,$iftrue,$iffalse) = $match;
00594                                 $res = $this->var_or_lit(
00595                                         $this->evaluate_condition($condition) ? $iftrue : $iffalse
00596                                 );
00597 
00598                         }
00599 
00600                 } else {
00601                         $res = "{".$variable."}";
00602                 }
00603                 return $res;
00604         }

Template::loop ( iterator,
records,
data 
)

Definition at line 1556 of file Template.php.

Referenced by preg_loop().

01556                                                 {
01557 
01558 //              $data = stripslashes($data);
01559                 $records = $this->lookup('$'.strtolower($records));
01560                 if ( !is_array($records) || !count($records) ) return "";
01561 
01562                 $output = "";
01563                 $iteration = 0;
01564                 $last_key = "";
01565                 if (is_array($records)) {
01566                         $iterations = count($records);
01567                         foreach ($records as $k=>$v) {
01568                                 $iteration++;
01569                                 $this->assign(
01570                                         "_loop",
01571                                         array(
01572                                                 "key"=>$k,
01573                                                 "iteration"=>$iteration,
01574                                                 "iterations"=>$iterations,
01575                                                 "odd"=>$iteration%2,
01576                                                 "first"=>($iteration==1),
01577                                                 "last"=>($iteration==$iterations),
01578                                                 "lastodd"=>($iteration%2) && ($iteration==$iterations),
01579                                                 "prev_iteration"=>$iteration-1,
01580                                                 "next_iteration"=>$iteration+1,
01581                                                 "prev_key"=>$last_key
01582                                         )
01583                                 );
01584                                 $this->assign_by_ref(
01585                                         $iterator,
01586                                         $v
01587                                 );
01588 
01589                                 $parsediteration = $data;
01590                             if (!defined("DT_NO_TRANSFORMS")) {
01591                                 // do a post-loop set, for variables we want to use *outside* a loop
01592                                     $parsediteration = preg_replace_callback("/\{loopset\s+\\\$([A-Za-z0-9\[\]\\\$_\.]+)\}([\s\S]*?)\{\/loopset\}/i",array(&$this,"preg_set"),$parsediteration);
01593                             }
01594 
01595                                 $parsediteration = $this->parse_loops($parsediteration,true);
01596                                 $parsediteration = $this->parse_tpl($parsediteration);
01597 
01598                                 $output .= $parsediteration;
01599 
01600                                 $last_key = $k;
01601                                 // unset for hte next iteration
01602                 }
01603                 }
01604                 $this->unassign($iterator);
01605                 $this->unassign("_loop");
01606                 return $output;
01607         }

Template::mysql_datetime_to_time ( dt  ) 

Definition at line 646 of file Template.php.

Referenced by date_select(), and mysql_time_transform().

00646                                              {
00647             if ($dt=="1000-01-01 00:00:00") { return "None"; }
00648             $yr = substr($dt,0,4);
00649             $mo = substr($dt,5,2);
00650             $dy = substr($dt,8,2);
00651             $hr = substr($dt,11,2);
00652             $mn = substr($dt,14,2);
00653             $sc = substr($dt,17,2);
00654             return mktime($hr,$mn,$sc,$mo,$dy,$yr);
00655         }

Template::mysql_time_transform ( datetime,
method,
data 
)

Definition at line 657 of file Template.php.

Referenced by transform().

00657                                                                {
00658                 switch($datetime) {
00659                         case 3:
00660                                 $dt = (int) $data;
00661                                 break;
00662                         case 2:
00663                                 $dt = time();
00664                                 break;
00665                         case 1:
00666                                 $dt = $this->mysql_datetime_to_time($data);
00667                                 break;
00668                         default:
00669                                 $dt = $this->mysql_timestamp_to_time($data);
00670                                 break;
00671                 }
00672 
00673                 // third parameter, if set, specifies an offset for the specified time;
00674                 // if Z is used, the current timezone offset is used
00675                 if (isset($method[3])) {
00676                         $offset = $method[3];
00677                         if (substr($offset,0,1)=='+') $offset = substr($offset,1);
00678                         if ($offset=='Z') $offset = date('Z');
00679                         $offset = (int) $offset;
00680                         $dt += $offset;
00681                 }
00682 
00683                 $datestyle = strtolower($method[1]);
00684 
00685                 if (preg_match('/^([a-z]+)([+-])([0-9]+)$/i',$datestyle,$matches)) {
00686                         $datestyle = $matches[1];
00687                         $offset = (int) $matches[3] * ( ($matches[2]=='-') ? -1 : 1 );
00688                         $dt += $offset;
00689                 }
00690 
00691                 if (!$datestyle) $datestyle="verbose";
00692                 if ($datestyle=="full") {
00693                         $dateformat = "l, F d, Y";
00694                         $timeformat = "h:i:sa";
00695                         $monthformat = "F, Y";
00696                 } if ($datestyle=="verbose") {
00697                         $dateformat = "M d, Y";
00698                         $timeformat = "h:i:sa";
00699                         $monthformat = "M, Y";
00700                 } elseif ($datestyle=="numeric") {
00701                         $dateformat = "m-d-Y";
00702                         $timeformat = "H:i:s";
00703                         $monthformat = "m/Y";
00704                 } elseif ($datestyle=="verbosenosecs") {
00705                         $dateformat = "M d, Y";
00706                         $timeformat = "h:ia";
00707                         $monthformat = "M, Y";
00708                 } elseif ($datestyle=="formatted") {
00709                         // Shift the command and date style off of the beginning of the array
00710                         array_shift($method);
00711                         array_shift($method);
00712                         // any colons beyond the first are intended as part of the date string, so re-implode
00713                         // the array
00714                         $datestr = implode(":",$method);
00715                         // replace any underscores with spaces
00716                         $datestr = str_replace("_"," ",$datestr);
00717 
00718                         if (substr($datestr,0,1)=='[') {
00719                                 $p = strpos($datestr,']');
00720                                 if ($p!==false) {
00721                                         $remainder = substr($datestr,$p+2);
00722                                         $datestr = substr($datestr,1,$p-1);
00723                                         $method = explode(':',$remainder);
00724                                 }
00725                         }
00726                 } elseif ($datestyle=="unix") {
00727                         return $dt;
00728                 }
00729 
00730                 if ($datestyle!="formatted") {
00731                         $datedetails = strtolower($method[2]);
00732                         if (!$datedetails) $datedetails="full";
00733                         switch($datedetails) {
00734                                 case "full":
00735                                         $datestr = "$dateformat $timeformat";
00736                                     break;
00737                                 case "date":
00738                                         $datestr = $dateformat;
00739                                     break;
00740                                 case "monthyear":
00741                                         $datestr = $monthformat;
00742                                     break;
00743                                 case "time":
00744                                         $datestr = $timeformat;
00745                                     break;
00746                         }
00747                 }
00748                 return @date($datestr,$dt);
00749         }

Template::mysql_timestamp_to_time ( dt  ) 

Definition at line 635 of file Template.php.

Referenced by date_select(), and mysql_time_transform().

00635                                               {
00636                 if ($dt=="00000000000000") { return "None"; }
00637             $yr = substr($dt,0,4);
00638             $mo = substr($dt,4,2);
00639             $dy = substr($dt,6,2);
00640             $hr = substr($dt,8,2);
00641             $mn = substr($dt,10,2);
00642             $sc = substr($dt,12,2);
00643             return mktime($hr,$mn,$sc,$mo,$dy,$yr);
00644         }

Template::parse (  ) 

Definition at line 1724 of file Template.php.

Referenced by display(), get(), and get_from_var().

01724                          {
01725                 $this->warnings = "";
01726 
01727             $parsed = $this->template;
01728             if (!defined("DT_NO_TRANSFORMS")) {
01729                 // do a pre-loop set, in case we want to use variables *in* a loop
01730                     $parsed = preg_replace_callback("/\{set\s+\\\$([A-Za-z0-9\[\]\\\$_\.]+)\}([\s\S]*?)\{\/set\}/i",array(&$this,"preg_set"),$parsed);
01731             }
01732                 if (!defined("DT_NO_LOOPINC")) {
01733                         $parsed = $this->parse_includes($parsed);
01734                         $parsed = $this->parse_loops($parsed);
01735         }
01736             if (!defined("DT_NO_TRANSFORMS")) {
01737                 // do a post-loop set, for variables we want to use *outside* a loop
01738                     $parsed = preg_replace_callback("/\{postset\s+\\\$([A-Za-z0-9\[\]\\\$_\.]+)\}([\s\S]*?)\{\/postset\}/i",array(&$this,"preg_set"),$parsed);
01739             }
01740                 $this->output = $this->parse_tpl($parsed);
01741 
01742                 foreach ($this->filters as $name=>$function) {
01743                         $this->output = $function($this->output);
01744                 }
01745         }

Template::parse_date_select ( basename,
timeonly = false 
)

Definition at line 927 of file Template.php.

00927                                                                 {
00928                 $mo = (int) $_REQUEST[$basename."_month"];
00929                 $dy = (int) $_REQUEST[$basename."_day"];
00930                 $yr = (int) $_REQUEST[$basename."_year"];
00931                 $hr = (int) $_REQUEST[$basename."_hour"];
00932                 $mn = (int) $_REQUEST[$basename."_min"];
00933                 if (isset($_REQUEST[$basename."_ampm"])) {
00934                         $ispm = ((int) $_REQUEST[$basename."_ampm"]) > 0;
00935                         if ($ispm) {
00936                                 $hr += 12;
00937                                 if ($hr>23) $hr = 0;
00938                         } else {
00939                                 if ($hr>11) $hr = 0;
00940                         }
00941                 }
00942 
00943                 if ($timeonly) {
00944                         $mo = date('m');
00945                         $dy = date('d');
00946                         $yr = date('Y');
00947                 }
00948 
00949 //              echo "[$basename/$mo/$dy/$yr/$hr/$mn]";
00950 
00951                 if ($mo<=0 || $dy<=0 || $yr<=0) return 0;
00952 
00953                 return mktime($hr,$mn,0,$mo,$dy,$yr);
00954         }

Template::parse_includes ( parsed  ) 

Definition at line 1712 of file Template.php.

Referenced by parse().

01712                                          {
01713                 $this->preg_includes = 0;
01714                 while (true) {
01715                         $parsed = preg_replace_callback("/\{include\s+(?:file\=)?\"(.*?)\"\s*(.*?)\/?\}/i",array(&$this,"preg_include_template"),$parsed);
01716                         if (!$this->preg_includes) break;
01717 
01718                         $this->preg_includes = 0;
01719                 }
01720                 return $parsed;
01721         }

Template::parse_loops ( parsed,
subloops = false 
)

Definition at line 1692 of file Template.php.

Referenced by loop(), parse(), and preg_loop().

01692                                                         {
01693         $parsed = preg_replace_callback("/\{".($subloops?'sub':'')."loop([0-9]?)\s+\\\$(.*?)\s*\=\s*\\\$(.*?)\}([\s\S]*?)\{\/".($subloops?'sub':'')."loop\\1\}/i",array(&$this,"preg_loop"),$parsed);
01694 
01695         return $parsed;
01696         }

Template::parse_tags ( s  ) 

Definition at line 1376 of file Template.php.

Referenced by conditional(), parse_tpl(), and set().

01376                                 {
01377                 // replace any variables
01378 
01379                 if (!defined("DT_NO_CONDITIONALS") && (strpos($s,'{compare')!==false) ) {
01380 //                  $s = preg_replace("/\{compare (\\\$[A-Za-z0-9\[\]\\\$_\.]+|\".*?\"|[0-9]+)\,(\\\$[A-Za-z0-9\[\]\\\$_\.]+|\".*?\"|[0-9]+),(\\\$[A-Za-z0-9\[\]\\\$_\.]+|\".*?\"|[0-9]+),(\\\$[A-Za-z0-9\[\]\\\$_\.]+|\".*?\"|[0-9]+)\}/ie","\$this->compare('\\1','\\2','\\3','\\4')",$s);
01381                     $s = preg_replace_callback("/\{compare (\\\$[A-Za-z0-9\[\]\\\$_\.]+|\".*?\"|[0-9]+)\,(\\\$[A-Za-z0-9\[\]\\\$_\.]+|\".*?\"|[0-9]+),(\\\$[A-Za-z0-9\[\]\\\$_\.]+|\".*?\"|[0-9]+),(\\\$[A-Za-z0-9\[\]\\\$_\.]+|\".*?\"|[0-9]+)\}/i",array(&$this,"preg_compare"),$s);
01382                 }
01383 
01384 //              $s = preg_replace("/\{(.*?)\}/e", "\$this->lookup('\\1')", $s);
01385                 $s = preg_replace_callback("/\{(.*?)\}/", array(&$this,"preg_lookup"), $s);
01386                 // make any transformations
01387 
01388                 $s = preg_replace("/\{\*(.*?)\*\}/","",$s);
01389 
01390                 if (!defined("DT_NO_TRANSFORMS") && (strpos($s,'{transform')!==false) ) {
01391                         $s = preg_replace("/\{transform (.*?)\}([\s\S]*?)\{\/transform\}/ie","\$this->transform('\\1','\\2')",$s);
01392                 }
01393                 return $s;
01394         }

Template::parse_tpl ( tpl  ) 

Definition at line 1643 of file Template.php.

Referenced by loop(), and parse().

01643                                  {
01644                 if (!defined("DT_NO_CONDITIONALS")) {
01645 //                      $tpl = preg_replace("/\{check (.*?)\}([\s\S]*?)\{\/check\}/ie", "\$this->conditional('\\1','\\2','otherwise','otherwisecheck')",$tpl);
01646                         if (strpos($tpl,'{check')!==false) $tpl = preg_replace_callback("/\{check (.*?)\}([\s\S]*?)\{\/check\}/i", array(&$this,"preg_conditional_check"),$tpl);
01647 //              echo "<hr><b>After check</b>:<br> $tpl<hr>";
01648 
01649 //              $tpl = preg_replace("/\{if (.*?)\}([\s\S]*?)\{\/if\}/ie", "\$this->conditional('\\1','\\2')",$tpl);
01650                 if (strpos($tpl,'{if')!==false) $tpl = preg_replace_callback("/\{if (.*?)\}([\s\S]*?)\{\/if\}/i", array(&$this,"preg_conditional_if"),$tpl);
01651 //              echo "<hr><b>After if</b>:<br> $tpl<hr>";
01652         }
01653 
01654                 $tpl = $this->parse_tags($tpl);
01655 
01656 
01657                 if (!defined("DT_NO_CUSTOMPLUGINS")) {
01658                         if (is_array($this->plugins)) {
01659                                 foreach ($this->plugins as $name=>$func) {
01660                                         $encapsulate = (substr($name,-2)=='[]');
01661                                         if ($encapsulate) {
01662                                                 $name = substr($name,0,strlen($name)-2);
01663                                                 $regex = "/\{$name\s*(.*?)\}([\s\S]*?)\{\/$name\}/i";
01664                                         } else {
01665                                                 $regex = "/\{$name\s*(.*?)\}/i";
01666                                         }
01667                                         if (is_callable($func)) {
01668                                                 $tpl = preg_replace($regex."e", "\$this->custom_plugin('$name',\$func,'\\1'".($encapsulate?",'\\2'":"").")",$tpl);
01669                                         } else {
01670                                                 $tpl = preg_replace($regex, "[Error: Custom function {$func}() does not exist]",$tpl);
01671                                         }
01672                                 }
01673                         }
01674                 }
01675 
01676                 return $tpl;
01677         }

Template::pop_template_dir (  ) 

Definition at line 2205 of file Template.php.

02205                                     {
02206                 $this->template_dir = array_pop($this->stored_template_dirs);
02207                 $this->template_fallback_dirs = array_pop($this->stored_template_fallback_dirs);
02208         }

Template::preg_compare ( matches  ) 

Definition at line 1372 of file Template.php.

01372                                         {
01373                 return $this->compare($matches[1],$matches[2],$matches[3],$matches[4]);
01374         }

Template::preg_conditional_check ( matches  ) 

Definition at line 1631 of file Template.php.

01631                                                   {
01632                 //echo "<span style='color: #999900'>[".$matches[1]."::::".$matches[2]."]</span>";
01633                 $x = $this->conditional($matches[1],$matches[2],'otherwise','otherwisecheck');
01634                 //echo "<span style='color: #FF9900'>[$x]</span>";
01635                 return $x;
01636         }

Template::preg_conditional_if ( matches  ) 

Definition at line 1638 of file Template.php.

01638                                                {
01639                 //echo "[<span style='color: #999900'>".$matches[1]."::::".$matches[2]."]</span>";
01640                 return $this->conditional($matches[1],$matches[2]);
01641         }

Template::preg_include_template ( matches  ) 

Definition at line 1698 of file Template.php.

01698                                                  {
01699                 $this->preg_includes++;
01700 
01701                 $condition = $matches[2];
01702                 if ( strlen($condition) && preg_match('/if\s*=\s*(.*?)$/i',$condition,$condmatches) ) {
01703                         if (!$this->evaluate_condition($condmatches[1])) return "";
01704                 }
01705                 return $this->include_template($matches[1]);
01706         }

Template::preg_lookup ( matches  ) 

Definition at line 393 of file Template.php.

00393                                        {
00394                 return $this->lookup($matches[1]);
00395         }

Template::preg_loop ( matches  ) 

Definition at line 1685 of file Template.php.

01685                                      {
01686                 list(,$loopindex,$iterator,$records,$data) = $matches;
01687                 $data = $this->parse_loops($data);
01688 
01689                 return $this->loop($iterator,$records,$data);
01690         }

Template::preg_set ( matches  ) 

Definition at line 1708 of file Template.php.

01708                                     {
01709                 return $this->set($matches[1],$matches[2],$matches[5]);
01710         }

Template::prepare_multipage ( &$  default_pagelimit,
itemcount,
baseurl,
sef = false,
show_showall = false 
)

Definition at line 2014 of file Template.php.

02014                                                                                                                {
02015                 $startindex = isset($_REQUEST["pstart"]) ? (int) $_REQUEST["pstart"] : 0;
02016                 if ($startindex<0) $startindex = 0;
02017 
02018 //              $pagelimit = isset($_REQUEST["plimit"]) ? $_REQUEST["plimit"] : 0;
02019                 $pagelimit = isset($_REQUEST["plimit"]) ? $_REQUEST["plimit"] : $default_pagelimit;
02020                 if (!$pagelimit && !$show_showall) $pagelimit = $default_pagelimit;
02021                 if (!$pagelimit && !$show_showall) $pagelimit = 5;
02022 
02023 //              $default_pagelimit = $pagelimit;
02024 
02025                 $this->multipage["itemcount"] = $itemcount;
02026                 $this->multipage["pagelimit"] = $pagelimit;
02027                 if ($pagelimit==0) {
02028                         $this->multipage["currentpage"] = 1;
02029                         $this->multipage["totalpages"] = 1;
02030                 } else {
02031                         $this->multipage["currentpage"] = $currentpage = ceil($startindex / $pagelimit) + 1;
02032                         $this->multipage["totalpages"] = $totalpages = ceil($itemcount / $pagelimit);
02033                 }
02034 
02035                 if ($startindex>$itemcount) $startindex = $itemcount - $pagelimit;
02036                 $this->multipage["startindex"] = $startindex = $startindex<0?0:$startindex;
02037 
02038                 $eq = $sef ? '/' : '=';
02039                 $amp = $sef ? '/' : '&amp;';
02040 
02041                 $nav = "";
02042                 $previdx = -1;
02043                 $nextidx = -1;
02044 
02045                 $individuallimit = 10;
02046 
02047                 $overtenstep = 5;
02048                 if ($totalpages>20) {
02049                         $overtenstep = max(1,floor($totalpages/5));
02050                         $individuallimit = 6;
02051                 }
02052                 if ($overtenstep+$individuallimit>$totalpages) $overtenstep = max(1,$totalpages - $individuallimit);
02053 
02054 
02055                 $individualstart = floor($currentpage / $overtenstep) * $overtenstep - $overtenstep;
02056                 $individualstart = $currentpage - floor($individuallimit/2);
02057                 if ($individualstart<0) $individualstart = 0;
02058 
02059                 $individualend = $individualstart + $individuallimit;
02060                 if ($individualend>$totalpages) {
02061                         $individualend = $totalpages;
02062                         if ($individualend - $individuallimit >= 0) $individualstart = $individualend - $individuallimit;
02063                 }
02064 
02065                 /*
02066                 $individualstart = floor($currentpage / 5) * 5 - 5; if ($individualstart<0) $individualstart = 0;
02067                 $individualend = $individualstart + 10;
02068                 if ($individualend>$totalpages) {
02069                         $individualend = $totalpages;
02070                         if ($individualend - 10 >= 0) $individualstart = $individualend - 10;
02071                 }
02072 
02073                 */
02074 
02075                 if ($sef) {
02076                         if (substr($baseurl,-1)!="/") $baseurl .= "/";
02077                 } else {
02078                         $baseurl .= (strpos($baseurl,"?")!==false) ? "&amp;" : "?";
02079                 }
02080 
02081                 $baseurl = preg_replace('/&p(start|limit)=[0-9]+/i','',$baseurl);
02082                 $baseurl = preg_replace('/\?p(start|limit)=[0-9]+/i','?',$baseurl);
02083 
02084                 $pagenumber = 1;
02085                 while(true) {
02086                         $pagestart = ($pagenumber - 1) * $pagelimit;
02087 
02088                         if ($pagenumber==$currentpage) {
02089                                 $nav .= $pagenumber;
02090                         } else {
02091                                 $nav .= "<a href=\"{$baseurl}pstart{$eq}{$pagestart}{$amp}plimit{$eq}{$pagelimit}\">".($pagenumber)."</a>";
02092                         }
02093                         $nav .= " | ";
02094 
02095                         $lastpagenumber = $pagenumber;
02096 
02097                         if ($totalpages>10) {
02098                                 if ($pagenumber<$individualstart) {
02099                                         $pagenumber += $overtenstep;
02100                                         if ($pagenumber>$individualstart) $pagenumber = $individualstart;
02101                                 }
02102                                 elseif ($pagenumber>=$individualend) $pagenumber += $overtenstep;
02103                                 else $pagenumber++;
02104                         } else {
02105                                 $pagenumber++;
02106                         }
02107 
02108                         if ($pagenumber>$totalpages) {
02109                                 if ($lastpagenumber!=$totalpages) {
02110                                         $pagenumber = $totalpages;
02111                                 } else {
02112                                         break;
02113                                 }
02114                         }
02115                         if ($itemcount==0) break;
02116                 }
02117 
02118                 $nav = substr($nav,0,strlen($nav)-3);
02119 
02120                 if ( ($pagelimit>0) && ($startindex!=0) ) {
02121                         $previdx = $startindex - $pagelimit;
02122                         if ($previdx<0) $previdx = 0;
02123 
02124                         $nav = "<a href=\"{$baseurl}pstart{$eq}{$previdx}{$amp}plimit{$eq}{$pagelimit}\">{$this->page_prev}</a> | ".$nav;
02125                 }
02126                 if ( ($pagelimit>0) && ($startindex+$pagelimit<$itemcount) ) {
02127                         $nextidx = $currentpage * $pagelimit;
02128 
02129                         $nav .= " | <a href=\"{$baseurl}pstart{$eq}{$nextidx}{$amp}plimit{$eq}{$pagelimit}\">{$this->page_next}</a>";
02130                 }
02131 
02132                 if ($show_showall) {
02133                         if ($pagelimit>0) {
02134                                 $nav .= " | <a href=\"{$baseurl}pstart{$eq}0{$amp}plimit{$eq}0\">{$this->page_show_all}</a>";
02135                         } else {
02136                                 $nav .= " | <a href=\"{$baseurl}pstart{$eq}0{$amp}plimit{$eq}{$default_pagelimit}\">{$this->page_show_pages}</a>";
02137                         }
02138                 }
02139 
02140                 $this->multipage["nav"] = $nav;
02141 
02142                 $this->assign_by_ref("_multipage",$this->multipage);
02143                 return $startindex;
02144         }

Template::push_template_dir ( dir,
fallback_dirs = false 
)

Definition at line 2195 of file Template.php.

02195                                                               {
02196                 array_push($this->stored_template_dirs,$this->template_dir);
02197                 array_push($this->stored_template_fallback_dirs,$this->template_fallback_dirs);
02198 
02199                 $this->template_dir = $dir;
02200                 if ($fallback_dirs && !is_array($fallback_dirs)) $fallback_dirs = array($fallback_dirs);
02201                 if (!is_array($fallback_dirs)) $fallback_dirs = array();
02202                 $this->template_fallback_dirs = $fallback_dirs;
02203         }

Template::read_template ( filename  ) 

Definition at line 295 of file Template.php.

Referenced by include_template(), and load_template().

00295                                           {
00296                 if ($this->debug_load) echo "Template::read_template({$filename})\n";
00297                 $fp = @fopen($filename,"r");
00298                 if ($fp) {
00299                         $template = "";
00300                         while (!feof($fp)) {
00301                                 $template .= str_replace(array("\n","\t"),array(''),fread($fp,4096));
00302                         }
00303                         fclose($fp);
00304 
00305                         return $template;
00306                 } else {
00307                         $this->error = "Template $filename not found";
00308                         return false;
00309                 }
00310         }

Template::restore_template_dir ( saved  ) 

Definition at line 2214 of file Template.php.

02214                                               {
02215                 $res = @unserialize($saved);
02216                 if ( (!$res) || (!is_array($res)) || (count($res)!=4) ) return false;
02217                 list($this->template_dir,$this->template_fallback_dirs,$this->stored_template_dirs,$this->stored_template_fallback_dirs) = $res;
02218         }

Template::save_template_dir (  ) 

Definition at line 2210 of file Template.php.

02210                                      {
02211                 return serialize(array($this->template_dir,$this->template_fallback_dirs,$this->stored_template_dirs,$this->stored_template_fallback_dirs));
02212         }

Template::set ( variable,
data 
)

Definition at line 1679 of file Template.php.

01679                                       {
01680         $output = $this->parse_tags($data);
01681             $variable = trim($variable);
01682         $this->assign($variable,$output);
01683         }

Template::set_cache_lifetime ( cache_expire_time  ) 

Definition at line 132 of file Template.php.

Referenced by load_expired_cache().

00132                                                         {
00133                 $this->cache_expire_time = $cache_expire_time;
00134         }

Template::set_fallback ( dirs = false  ) 

Definition at line 2158 of file Template.php.

02158                                              {
02159                 if ($dirs && !is_array($dirs)) $dirs = array($dirs);
02160                 $this->template_fallback_dirs = $dirs;
02161         }

Template::set_nocache_semaphore ( permanent = false,
temporary = false,
timeout = 28800 
)

Definition at line 136 of file Template.php.

00136                                                                                          {
00137                 $this->nocache_perm_semaphore = $permanent;
00138                 $this->nocache_temp_semaphore = $temporary;
00139                 $this->nocache_temp_timeout = $timeout; // 8 hours
00140         }

Template::set_override ( dirs = false  ) 

Definition at line 2170 of file Template.php.

02170                                              {
02171                 if ($dirs && !is_array($dirs)) $dirs = array($dirs);
02172                 $this->template_override_dirs = $dirs;
02173         }

Template::set_relative_override ( dirs = false  ) 

Definition at line 2182 of file Template.php.

02182                                                       {
02183                 if ($dirs && !is_array($dirs)) $dirs = array($dirs);
02184                 if (!is_array($dirs)) $dirs = array();
02185                 $this->template_override_subdirs = $dirs;
02186         }

Template::set_server_variables (  ) 

Definition at line 145 of file Template.php.

Referenced by Template().

00145                                         {
00146                 $this->variables = array(
00147                         "server_php_self"=>$_SERVER["PHP_SELF"],
00148                         "server_request_uri"=>$_SERVER["SCRIPT_NAME"], /* $_SERVER["REQUEST_URI"] breaks IIS */
00149                         "server_server_name"=>$_SERVER["SERVER_NAME"],
00150                         "server_script_name"=>$_SERVER["SCRIPT_NAME"],
00151                         "server_remote_addr"=>$_SERVER["REMOTE_ADDR"],
00152                         "server_unix_time"=>time(),
00153                         "server_date"=>strftime("%b %d, %Y"),
00154                         "server_time"=>strftime("%I:%M:%S%p"),
00155                         "_nil"=>0,
00156                         "_null"=>0,
00157                         "_"=>0,
00158                 );
00159                 $this->assign_by_ref("_REQUEST",$_REQUEST);
00160                 $this->assign_by_ref("_SERVER",$_SERVER);
00161                 $this->assign_by_ref("_ENV",$_ENV);
00162                 $this->assign_by_ref("_COOKIE",$_COOKIE);
00163 
00164                 // Note: you MUST CALL session_start() BEFORE instantiating the Template object
00165                 // if you want to access $_SESSION from templates
00166                 $this->assign_by_ref("_SESSION",$_SESSION);
00167 
00168                 if (defined("TPL_CUSTOM_PLUGINS")) {
00169                         $plugins = explode("|",TPL_CUSTOM_PLUGINS);
00170                         foreach ($plugins as $k=>$plugin) {
00171                                 list($plugin_name,$plugin_function) = explode(":",$plugin);
00172                                 $this->plugins[$plugin_name] = $plugin_function;
00173                         }
00174                 }
00175                 if (defined("TPL_CUSTOM_TRANSFORMS")) {
00176                         $transforms = explode("|",TPL_CUSTOM_TRANSFORMS);
00177                         foreach ($transforms as $k=>$transform) {
00178                                 list($transform_name,$transform_function) = explode(":",$transform);
00179                                 $this->transforms[$transform_name] = $transform_function;
00180                         }
00181                 }
00182 
00183         }

static& Template::singleton ( use_caching = false,
cache_id = NULL,
cache_auto_display = true,
cache_allow_override = true,
cache_prefix = "",
retain_expired_cachefiles = false 
) [static]

Definition at line 2220 of file Template.php.

Referenced by tep_post_prepare_email().

02220                                                                                                                                                                             {
02221                 if (!isset($GLOBALS['singletons']['directemplate'])) {
02222                         $GLOBALS['singletons']['directemplate'] = new Template($use_caching,$cache_id,$cache_auto_display,$cache_allow_override,$cache_prefix,$retain_expired_cachefiles);
02223                 }
02224 
02225                 return $GLOBALS['singletons']['directemplate'];
02226         }

Template::Template ( use_caching = false,
cache_id = NULL,
cache_auto_display = true,
cache_allow_override = true,
cache_prefix = "",
retain_expired_cachefiles = false 
)

* $_SERVER["REQUEST_URI"] breaks IIS */

Definition at line 40 of file Template.php.

Referenced by singleton().

00040                                                                                                                                                                    {
00041                 //      $use_caching              - TRUE if page caching should be enabled, otherwise false
00042                 //      $cache_id             - a unique identifier used to store/retrieve this page
00043                 //      $cache_auto_display   - if a valid cached copy of this page exists, and
00044                 //                              $cache_auto_display is TRUE, the constructor will automatically
00045                 //                              display the cached version and terminate the script (otherwise,
00046                 //                          if FALSE, the user must manually display the cached page)
00047                 //      $cache_allow_override - if TRUE, passing ?nocache=1 to the calling script will prevent caching.
00048                 //      $retain_expired_cachefiles - see below
00049                 set_magic_quotes_runtime(0);
00050                 $this->cache_prefix = $cache_prefix;
00051 
00052                 $this->page_prev = "&lt; Prev";
00053                 $this->page_next = "Next &gt;";
00054                 $this->page_show_all = "Show All";
00055                 $this->page_show_pages = "Show Pages";
00056 
00057                 $this->plugins = array();
00058                 $this->transforms = array();
00059 
00060                 // set this to TRUE if you don't want ::load_cache() to automatically remove any
00061                 // expired versions of the requested page; this can be used to allow fallbacks to
00062                 // an expired copy of the cached page when, eg: MySQL cannot be reached... use
00063                 // the ::clear_expired_cache() to manually clear the expired cache pages
00064                 $this->retain_expired_cachefiles = $retain_expired_cachefiles;
00065 
00066                 // if the user didn't specify a cache ID, generate one that's hopefully unique
00068                 if (is_null($cache_id)) $cache_id = $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
00069                 $this->cache_id = $cache_id;
00070 
00071                 // should we use caching?
00072                 if ($use_caching && !(defined('DISABLE_TEMPLATE_CACHING') && DISABLE_TEMPLATE_CACHING) ) {
00073                         // has caching been overridden?
00074                         if (!($cache_allow_override and isset($_REQUEST["nocache"]))) {
00075                                 if ($this->load_cache($this->cache_id)) { // try to load cached copy
00076                                         // cache hit!
00077                                         $this->cached = true;
00078                                         if ($cache_auto_display) { // if enabled, display the cached page and terminate
00079                                                 $this->display_cached_page();
00080                                                 die;
00081                                         }
00082                                 } else {
00083                                         if (defined('TEMPLATE_CACHE_DEBUG') && TEMPLATE_CACHE_DEBUG) {
00084                                                 echo "<div align='center'>Cache miss (\"$this->cache_id\"".($this->cache_prefix?"; prefix: \"{$this->cache_prefix}\"":"").")</div>";
00085                                         }
00086                                 }
00087                         }
00088                 }
00089 
00090                 // not cached, so load the template from disk
00091                 $this->cached = false;
00092                 $this->cache_content_type = false;
00093                 $this->auto_store_cache = true; // cache files should automatically be created
00094                 $this->nocache_semaphore = false; // will not look for a "no-cache" semaphore
00095 
00096 
00097                 // if the following is enabled, template variables that have not been set will
00098                 // appear as "{Undefined:VARIABLENAME}" when parsed
00099                 $this->display_undefined = false;
00100 
00101                 $this->set_server_variables();
00102                 $this->filters = array();
00103                 $this->template_fallback_dirs = array();
00104                 $this->template_override_dirs = array();
00105                 $this->template_override_subdirs = array();
00106                 $this->stored_template_dirs = array();
00107                 $this->stored_template_fallback_dirs = array();
00108                 $this->internal_i18n = false;
00109                 $this->utf8 = false;
00110                 $this->cache_expire_time = NULL;
00111                 $this->debug_load = false;
00112         }

Template::time_text ( time,
method 
)

Definition at line 606 of file Template.php.

Referenced by transform().

00606                                           {
00607                 $durations = array(
00608                         1=>                     array('second','seconds','sec','secs'),
00609                         60=>            array('minute','minutes','min','mins'),
00610                         60*60=>         array('hour','hours','hr','hrs'),
00611                         24*60*60=>      array('day','days','day','days')
00612                 );
00613 
00614                 $output = array();
00615 
00616                 $nosecs = in_array('nosecs',$method);
00617 
00618                 $textindex = in_array('full',$method) ? 0 : 2;
00619                 foreach (array_reverse($durations,true) as $seconds=>$texts) {
00620                         if ( $nosecs && ($seconds==1) ) continue;
00621                         $amount = $seconds>0 ? floor($time / $seconds) : 0;
00622                         $time -= $amount*$seconds;
00623 
00624                         $pluralindex = (int) ($amount != 1);
00625                         $text = $texts[ $textindex+$pluralindex ];
00626                         $text = $this->xlat($text);
00627 
00628                         if ($amount>0) $output[] = sprintf("%d %s",$amount,$text);
00629                 }
00630                 if (!count($output)) $output[] = sprintf("%d %s",0,$durations[1][ $textindex+1 ]);
00631 
00632                 return implode(', ',$output);
00633         }

Template::transform ( method,
data 
)

Definition at line 979 of file Template.php.

Referenced by lookup().

00979                                           {
00980                 //if (strpos($method,'str_replace')!==false) { $woo = true; }
00981                 // check for multiple chained transforms
00982                 if (strpos($method,"|")!==false) {
00983                         // if found, explode $method and call self once for each method
00984                         $transforms = explode("|",$method);
00985                         foreach ($transforms as $k=>$method) {
00986                                 $data = $this->transform($method,$data);
00987                         }
00988                         return $data;
00989                 }
00990                 $method = explode(":",$method);
00991                 foreach ($method as $varname=>$varvalue) {
00992 //                      if ($woo) echo "$varname=$varvalue<br>";
00993                         $method[$varname] = $this->var_or_lit($varvalue,false);
00994                 }
00995 
00996 
00997                 $requested_transform = strtolower($method[0]);
00998                 switch($requested_transform) {
00999                         case "ucfirst":
01000                                 $output = ucfirst($data);
01001                                 break;
01002                         case "strtolower":
01003                                 $output = strtolower($data);
01004                                 break;
01005                         case "strtoupper":
01006                                 $output = strtoupper($data);
01007                                 break;
01008                         case "ucwords":
01009                                 $output = ucwords($data);
01010                                 break;
01011                         case "urlencode":
01012                                 if ($method[1]=='raw') {
01013                                         $output = rawurlencode($data);
01014                                 } else {
01015                                         $output = urlencode($data);
01016                                 }
01017                                 break;
01018                         case "urldecode":
01019                                 if ($method[1]=='raw') {
01020                                         $output = rawurldecode($data);
01021                                 } else {
01022                                         $output = urldecode($data);
01023                                 }
01024                                 break;
01025                         case "htmlentities":
01026                                 $output = $this->utf8 ? htmlentities($data,ENT_QUOTES,'UTF-8') : htmlentities($data);
01027                                 break;
01028                         case "currency":
01029                                 if (!defined('CURRENCY_FORMAT')) define('CURRENCY_FORMAT','%.2f');
01030                                 $output = sprintf(CURRENCY_FORMAT,$data);
01031                                 break;
01032                         case "addslashes":
01033                                 $output = addslashes($data);
01034                                 break;
01035                         case "jsescape":
01036                                 $from = array("\\\\","\n","\r","\"","'","&","<",">");
01037                                 $to = array("\\\\\\\\","\\n","\\r","\\\"","\\'","\\x26","\\x3C","\\x3E");
01038                                 $output = str_replace($from,$to,$data);
01039                                 break;
01040                         case "stripslashes":
01041                                 $output = stripslashes($data);
01042                                 break;
01043                         case "striptags":
01044                         case "strip_tags":
01045                                 $output = strip_tags($data);
01046                                 break;
01047                         case "trim":
01048                                 $output = trim($data);
01049                                 break;
01050                         case "count":
01051                                 $output = is_array($data) ? count($data) : 0;
01052                                 break;
01053                         case "abs":
01054                                 $output = abs($data);
01055                                 break;
01056                         case "min":
01057                                 $limit = (float) $method[1];
01058                                 $value = (float) $data;
01059                                 $output = min($value,$limit);
01060                                 break;
01061                         case "max":
01062                                 $limit = (float) $method[1];
01063                                 $value = (float) $data;
01064                                 $output = max($value,$limit);
01065                                 break;
01066                         case "round":
01067                                 $precision = (int) $method[1];
01068                                 $output = round($data,$precision);
01069                                 break;
01070                         case "floor":
01071                                 $output = floor($data);
01072                                 break;
01073                         case "ceil":
01074                                 $output = ceil($data);
01075                                 break;
01076                         case "filesize":
01077                                 $precision = (int) $method[1];
01078                                 $data = (int) $data;
01079                                 if ($data>1024*1024*1024) {
01080                                         $data = round($data / 1024*1024*1024,$precision).'G';
01081                                 } elseif ($data>1024*1024) {
01082                                         $data = round($data / 1024*1024,$precision).'M';
01083                                 } elseif ($data>1024) {
01084                                         $data = round($data / 1024,$precision).'K';
01085                                 }
01086                                 return $data;
01087                                 break;
01088                         case "substr":
01089                                 if(count($method)==2) {
01090                                         $output = substr($data,(int) $method[1]);
01091                                 } else {
01092                                         $output = substr($data,(int) $method[1],(int) $method[2]);
01093                                 }
01094                                 break;
01095                         case "preg_replace":
01096                                 $output = preg_replace(urldecode($method[1]),$method[2],$data);
01097                                 break;
01098                         case "str_replace":
01099                                 $keyword = trim($method[1]);
01100                                 if ( (substr($keyword,0,1)!='$') && (substr($keyword,0,1)!='"') ) $keyword = "\"$keyword\"";
01101                                 $keyword = $this->evaluate_expression($keyword);
01102 
01103                                 $replacement = trim($method[2]);
01104                                 if ( (substr($replacement,0,1)!='$') && (substr($replacement,0,1)!='"') ) $replacement = "\"$replacement\"";
01105                                 $replacement = $this->evaluate_expression($replacement);
01106 
01107                                 $replacement = preg_replace_callback("/\{(.*?)\}/", array(&$this,"preg_lookup"), $replacement);
01108 
01109                                 $output = str_replace($keyword,$replacement,$data);
01110                                 break;
01111                         case "preg_match":
01112                                 $output = preg_match(urldecode($method[1]),$data);
01113                                 break;
01114                         case "contains":
01115                                 $keyword = preg_replace(array('/^"/','/"$/'),"",$method[1]);
01116                                 if (is_array($data)) {
01117                                         $output = in_array($keyword,$data);
01118                                 } else {
01119                                         $output = (strpos($data,$keyword)!==false);
01120                                 }
01121                                 break;
01122                         case "default":
01123                                 $fallback = $method[1];
01124                                 $c = substr($fallback,0,1);
01125                                 if ($c=='$' || $c=='=') $fallback = $this->lookup($fallback);
01126 
01127                                 $output = strlen($data) ? $data : $fallback;
01128                                 break;
01129                         case "sprintf":
01130                                 $format = preg_replace(array('/^"/','/"$/'),"",$method[1]);
01131                                 $output = sprintf($format,$data);
01132                                 break;
01133                         case "mysqldatetime":
01134                                 $output = $this->mysql_time_transform(1,$method,$data);
01135                                 break;
01136                         case "mysqltimestamp":
01137                                 $output = $this->mysql_time_transform(0,$method,$data);
01138                                 break;
01139                         case "unixtimestamp":
01140                                 $output = $this->mysql_time_transform(3,$method,$data);
01141                                 break;
01142                         case "timetext":
01143                                 $output = $this->time_text($data,$method);
01144                                 break;
01145                         case "gettime":
01146                                 $output = $this->mysql_time_transform(2,$method,$data);
01147                                 break;
01148                         case "yesno":
01149                                 $output = ((int) $data>0?"Yes":"No");
01150                                 break;
01151                         case "truefalse":
01152                                 $output = ((int) $data>0?"True":"False");
01153                                 break;
01154                         case "null":
01155                                 $output = $data;
01156                                 break;
01157                         case "noquotes":
01158                                 $output = str_replace("\"","&quot;",$data);
01159                                 break;
01160                         case "quoteconvert":
01161                                 $output = str_replace("\"","''",$data);
01162                                 break;
01163                         case "nbsp":
01164                                 $output = str_replace(' ',"&nbsp;",$data);
01165                                 break;
01166                         case "underscore":
01167                                 $output = str_replace(' ',"_",$data);
01168                                 break;
01169                         case "wordwrap":
01170                                 $width = $method[1]; if (strlen($width)) { $width = (int) $width; } else { $width = 75; }
01171                                 $break = $method[2]; if (!strlen($break)) $break = "\n";
01172                                 $cut = $method[3]; if (strlen($cut)) { $cut = (int) $cut; } else { $cut = true; }
01173                                 $filename_wrap = ($method[4]=='filename');
01174 
01175                                 if ($filename_wrap) {
01176                                         $data = str_replace(" ","\xFF",$data);
01177                                         $data = str_replace("/"," ",$data);
01178 
01179                                         $break = str_replace(" ","\xFF",$break);
01180                                         $break = '/' . $break;
01181                                 }
01182                                 $output = wordwrap($data,$width,$break,$cut);
01183                                 if ($filename_wrap) {
01184                                         $output = str_replace(" ","/",$output);
01185                                         $output = str_replace("\xFF"," ",$output);
01186                                 }
01187                                 break;
01188                         case "ellipsis":
01189                                 $maxlen = (int) $method[1];
01190                                 if (strlen($data)>$maxlen) $data = substr($data,0,$maxlen-3)."...";
01191                                 $output = $data;
01192                                 break;
01193                         case "midellipsis":
01194                                 $ellipsis = ' ... ';
01195                                 $maxlen = (int) $method[1];
01196                                 $endingchars = $method[2];
01197                                 if ($endingchars=="filename") {
01198                                         $p = strrpos($data,'/');
01199                                         if ($p!==false) {
01200                                                 $endingchars = strlen($data) - $p;
01201                                                 $ellipsis = trim($ellipsis);
01202                                         } else {
01203                                                 $endingchars = false;
01204                                         }
01205                                 } else {
01206                                         $endingchars = (int) $endingchars;
01207                                 }
01208                                 if (!$endingchars) $endingchars = 8;
01209                                 if (strlen($data)>$maxlen) {
01210                                         $ending = substr($data,-$endingchars);
01211                                         $data = substr($data,0,$maxlen-3-$endingchars). $ellipsis . $ending;
01212                                 }
01213                                 $output = $data;
01214                                 break;
01215                         case "dateselect":
01216                                 $output = $this->date_select($method,$data);
01217                                 break;
01218                         case "random":
01219                                 $output = rand();
01220                                 break;
01221                         case "nl2br":
01222                                 $output = nl2br($data);
01223                                 break;
01224                         case "base64_encode":
01225                                 $output = base64_encode($data);
01226                                 break;
01227                         case "strpad":
01228                                 $char = $method[1];
01229                                 $len = $method[2];
01230                                 $output = $data;
01231 
01232                                 $padright = ($len<0);
01233                                 $len = abs($len);
01234 
01235                                 if ($len>strlen($output)) {
01236                                         if ($padright) {
01237                                                 $output = $output . str_repeat($char,$len - strlen($output));
01238                                         } else {
01239                                                 $output = str_repeat($char,$len - strlen($output)) . $output;
01240                                         }
01241                                 }
01242                                 break;
01243                         case "chr":
01244                                 $output = chr($data);
01245                                 break;
01246                         case "ord":
01247                                 $output = ord($data);
01248                                 break;
01249                         case "or":
01250                         case "and":
01251                         case "xor":
01252                         case "mod":
01253                         case "add":
01254                         case "sub":
01255                         case "mul":
01256                         case "div":
01257                                 @list($operator,$operand,$postprocess,$postprocessinfo) = $method;
01258                                 $output = $this->arithmetic_op($data,$operand,strtolower($operator),$postprocess,$postprocessinfo);
01259                                 break;
01260                         case "vardump":
01261                                 // eg: {transform vardump}something{/transform} performs var_dump($something)
01262                                 ob_start();
01263                                 var_dump($this->lookup('$'.$data));
01264                                 $output = "<pre>\n".ob_get_contents()."</pre>";
01265                                 ob_end_clean();
01266                                 break;
01267                         case "in_keys":
01268                                 $arrayname = $method[1];
01269                                 $array = $this->lookup('$'.$arrayname);
01270 
01271                                 return isset($array[$data]);
01272                                 break;
01273                         case "in_array":
01274                                 $arrayname = $method[1];
01275                                 $array = $this->lookup('$'.$arrayname);
01276 
01277                                 return in_array($data,$array);
01278                                 break;
01279                         case "in_set":
01280                                 return in_array($data,$method);
01281                                 break;
01282                         case "range":
01283                                 $lo = $method[1];
01284                                 $hi = $method[2];
01285                                 $output = range($lo,$hi);
01286                                 break;
01287                         case "implode":
01288                                 array_shift($method);
01289                                 $separator = array_shift($method);
01290 
01291                                 // any remaining methods represent transforms that we need to apply
01292                                 // to each element in the array before imploding
01293                                 if (count($method)) {
01294                                         if (is_array($data)) {
01295                                                 foreach ($data as $key=>$value) {
01296                                                         reset($method);
01297                                                         foreach ($method as $k=>$thismethod) {
01298                                                                 $data[$key] = $this->transform($thismethod,$data[$key]);
01299                                                         }
01300                                                 }
01301                                         }
01302                                 }
01303 
01304                                 $output = is_array($data) ? implode($separator,$data) : '';
01305                                 break;
01306                         case "explode":
01307                                 array_shift($method);
01308                                 $separator = array_shift($method);
01309                                 $pieces = count($method) ? array_shift($method) : NULL;
01310 
01311                                 $output = explode($separator,$data,$pieces);
01312                                 break;
01313                         default:
01314                                 if (!defined("DT_NO_CUSTOMTRANSFORMS")) {
01315                                         if (is_array($this->transforms)) {
01316                                                 array_shift($method);
01317                                                 if ($func = $this->transforms[$requested_transform]) {
01318                                                         if (is_callable($func)) $output = call_user_func($func,$data,$method);
01319                                                 }
01320                                         }
01321                                 }
01322 
01323                 }
01324                 return $output;
01325         }

Template::unassign ( variable  ) 

Definition at line 339 of file Template.php.

Referenced by loop().

00339                                      {
00340                 if (is_array($variable)) {
00341               foreach ($variable as $var=>$val) {
00342                 $var = strtolower($var);
00343                 unset($this->variables[$var]);
00344               }
00345             } else {
00346                         $variable = strtolower($variable);
00347               unset($this->variables[$variable]);
00348                 }
00349         }

Template::var_or_lit ( expression,
brace_if_unquoted = true 
)

Definition at line 408 of file Template.php.

Referenced by lookup(), and transform().

00408                                                                    {
00409                 $specialchars = '$*=?';
00410                 $firstchar = substr($expression,0,1);
00411                 if (strpos($specialchars,$firstchar)!==false) {
00412                         return $this->lookup($expression);
00413                 } elseif ( ($firstchar=='"') || ($firstchar=="'") ) {
00414                         $lit = substr($expression,1,strlen($expression)-2);
00415 
00416                         // interpret any variables inside the value
00417                         $lit = preg_replace("/\%([0-9A-Fa-f]{2})/e", "''.chr(hexdec('\\1')).''", $lit);
00418 //                      $lit = preg_replace("/\{(.*?)\}/e", "\$this->lookup('\\1')", $lit);
00419                         $lit = preg_replace_callback("/\{(.*?)\}/", array(&$this,"preg_lookup"), $lit);
00420 
00421                         // %7B = [
00422                         // %7D = ]
00423 
00424                         return $lit;
00425                 } else {
00426                         if ($brace_if_unquoted) $expression = '{'.$expression.'}';
00427                         return $expression;
00428                 }
00429         }

Template::xlat ( s  ) 

Definition at line 114 of file Template.php.

Referenced by date_select(), lookup(), and time_text().

00114                           {
00115                 if ($this->internal_i18n && function_exists('__')) {
00116                         $s = __($s);
00117                 } elseif (function_exists('_')) {
00118                         $s = _($s);
00119                 }
00120 
00121                 return $s;
00122         }


The documentation for this class was generated from the following file: