Source for file OCSP_TEMPLATE.phpclass
Documentation is available at OCSP_TEMPLATE.phpclass
* openCSP class file OCSP_TEMPLATE.phpclass
* @project Open CSP-Management
* @author Peter Krebs <pitlinz@users.sourceforge.net>
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
* @version $Id: OCSP_TEMPLATE.phpclass,v 1.11 2008/12/10 15:39:06 peterkrebs Exp $
// ---------------------------------------------------------
// ---------------------------------------------------------
require_once dirname(__FILE__
) .
_OCSP_DIRSEP_ .
"pcf_templates.phpinc";
* openCSP class OCSP_TEMPLATE
* @project Open CSP-Management
* @author Peter Krebs <pitlinz@users.sourceforge.net>
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
* @version $Id: OCSP_TEMPLATE.phpclass,v 1.11 2008/12/10 15:39:06 peterkrebs Exp $
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
* @constant string CLASS_SRC_FILE
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
/*** class vars ------------------------------------------------------ */
/*** class methods --------------------------------------------------- */
* returns an array with fields found in the template
* each array element has a NAME and a TYPE index
* @param string $aTemplate
public static function getVars($aTemplate,$varSign=
'$',$debug=
False)
return $obj_tmpl->getTmplVars();
* @param string $aTemplate
public static function parse($aTemplate,$aArr=
NULL,$debug=
False,$varSign=
'$')
//return pcf_tmpl_parse($aTemplate,$aArr,$debug,$varSign);
return $obj_tmpl->getParsedTemplate($aArr,$debug);
* appends a query string to an url
* @param string $queryString
if ((substr($queryString,0,1) ==
"?") ||
(substr($queryString,0,1) ==
"&"))
$queryString =
substr($queryString,1);
return $url .
$queryString;
return $url .
"&" .
$queryString;
return $url .
"?" .
$queryString;
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
/*** compostion --------------------------------------------------- */
/*** attributes -------------------------------------------------- */
* @var string $myTemplate
* the template values to replace
* the char sign used (character which encloses the placeholders)
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
* @param string $aTemplate
public function __construct($aTemplate=
Null,$varSign=
'$',$debug=
False)
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
* @param string $aTemplate
foreach($arr_vars as $str_key =>
$arr_varDesc)
$arr_ret[$arr_varDesc['NAME']] =
array('NAME'=>
$arr_varDesc['NAME'],'TYPE'=>
$str_type);
foreach($this->simpleVars as $str_type =>
$arr_vars)
foreach($arr_vars as $str_key =>
$arr_varDesc)
$arr_ret[$arr_varDesc['NAME']] =
array('NAME'=>
$arr_varDesc['NAME'],'TYPE'=>
$str_type);
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
* extracts the template placeholders out of the template
* @param string $aTemplate
while($int_pos !==
False)
$str_part=
substr($aTemplate,$int_pos);
$arr_ret[]=
substr($str_part,0,$int_pos);
$aTemplate =
substr($str_part,$int_pos);
$arr_ret[]=
substr($str_part,0,$int_pos);
$aTemplate =
substr($str_part,$int_pos);
$arr_ret[]=
substr($str_part,0,$int_pos);
$aTemplate =
substr($str_part,$int_pos);
* checks a subpart of a placeholder if it's an array
* @param string $placeholderPart
if ((strpos($placeholderPart,"#") ===
0) &&
strstr($placeholderPart,"|"))
$arr_ret[0] =
array('NAME' =>
$arr_ret[0]);
* checks if a placeholderPart includes a date format (-D...~VARNAME)
* @param string $placeholderPart
if (strpos($placeholderPart,"-D") ===
0)
$arr_ret['NAME'] =
$arr_format[1];
$arr_ret['FORMATTYPE'] =
"D";
$arr_ret['FORMAT'] =
$arr_format[0];
if (strpos($placeholderPart,"-P") ===
0)
$arr_ret['NAME'] =
$arr_format[1];
$arr_ret['FORMATTYPE'] =
"P";
$arr_ret['FORMAT'] =
$arr_format[0];
if (strpos($placeholderPart,"-JS") ===
0)
$arr_ret['NAME'] =
$arr_format[1];
$arr_ret['FORMATTYPE'] =
"JS";
$arr_ret['FORMAT'] =
$arr_format[0];
if (strpos($placeholderPart,"!") ===
0)
$arr_ret['FORMATTYPE'] =
"!";
foreach($arr_parts as $idx => $str_part)
if (strpos($str_part,PCF_TMPLVAR_IF) === 0)
if ($debug) echoDebugLine(__FILE__,__LINE__,nl2br(htmlspecialchars($str_part)));
$str_varName=md5($str_part);
$str_part =
substr($str_part,strlen(PCF_TMPLVAR_IF));
if (strpos($str_part,$this->varSign.
PCF_TMPLVAR_IF))
throw new exception("INSIDE IF NOT IMPLEMENTED");
$arr_cond = explode('|',$str_part);
$this->complexVars[PCF_TMPLVAR_IF][$str_varName]['NAME']=
$arr_cond[0];
$this->complexVars[PCF_TMPLVAR_IF][$str_varName]['SUBTMPL']=
$str_part;
foreach($arr_cond as $str_cond)
if ($arr_condParts = explode("~",$str_cond,2))
$this->complexVars[PCF_TMPLVAR_IF][$str_varName]['CONDITIONS'][$arr_condParts[0]] =
$arr_condParts[1];
if (strpos($str_part,PCF_TMPLVAR_DBLOOKUP) === 0)
$str_varName=md5($str_part);
$this->complexVars[PCF_TMPLVAR_DBLOOKUP][$str_varName]['REPLACE'] =
$this->varSign .
$str_part .
PCF_TMPLVAR_DBLOOKUP .
$this->varSign;
$str_query =
trim(substr($str_part,strlen(PCF_TMPLVAR_DBLOOKUP)));
$this->complexVars[PCF_TMPLVAR_DBLOOKUP][$str_varName]['NAME'] =
'QUERY' .
$str_varName;
$this->complexVars[PCF_TMPLVAR_DBLOOKUP][$str_varName]['QUERY'] =
$str_query;
if (strpos($str_part,PCF_TMPLVAR_ASIS))
'REPLACE' =>
$this->varSign .
$str_part .
$this->
$arr_types = array(PCF_TMPLVAR_ARR,PCF_TMPLVAR_GET,PCF_TMPLVAR_SESSION,PCF_TMPLVAR_POST,PCF_TMPLVAR_BASE64,PCF_TMPLVAR_SERVER,PCF_TMPLVAR_GLOBALS);
foreach($arr_types as $cha_Type)
if (strpos($str_part,$cha_Type) === 0)
$str_part=
substr($str_part,strlen($cha_Type));
'REPLACE' => $str_replace,
$this->simpleVars[$cha_Type][implode('|',$arr_desc)]=
array_merge($tmp_array,$arr_name);
$arr_desc['REPLACE'] = $str_replace;
$this->simpleVars[$cha_Type][$str_replace] =
$arr_desc;
$arr_desc['REPLACE'] = $str_replace;
$this->simpleVars[$cha_Type][$str_replace] =
$arr_desc;
$arr_desc['REPLACE'] = $str_replace;
$this->simpleVars[$cha_Type][$str_replace] =
$arr_desc;
$arr_desc['REPLACE'] = $str_replace;
$this->simpleVars[$cha_Type][$str_replace] =
$arr_desc;
'REPLACE' =>
$str_replace
if ($debug) echoDebugLine(__FILE__,__LINE__,"<p>" . htmlspecialchars($str_part) . "</p>");
foreach($this->complexVars[PCF_TMPLVAR_IF] as $str_name =>
$arr_var)
if (!isset($this->complexVars[PCF_TMPLVAR_IF][$str_name]['EXTRACTED']) ||
! $this->complexVars[PCF_TMPLVAR_IF][$str_name]['EXTRACTED'])
{ // to avoid endless loops
$this->complexVars[PCF_TMPLVAR_IF][$str_name]['EXTRACTED'] =
True;
echoDebugLine(__FILE__,__LINE__,"<p>SimpleVars:</p><pre>" . print_r($this->simpleVars,True) .
"</pre>");
echoDebugLine(__FILE__
,__LINE__
,"<p>ComplexVars:</p><pre>" .
print_r($this->complexVars,True) .
"</pre>");
protected function _parseComplex($aTmpl,$dataArray,$strict=False,$debug=False)
if ($debug) echoDebugMethod(__FILE__,get_class($this),"OCSP_TEMPLATE::parseComplex()","<pre>" . htmlspecialchars(print_r($this->complexVars,True)) .
"</pre><p>" .
htmlspecialchars($aTmpl) .
"</p>");
foreach($this->complexVars[PCF_TMPLVAR_IF] as $cha_type =>
$arr_vars)
if ($strict && !isset($dataArray[$arr_vars['NAME']]))
if (strpos($str_return,$arr_vars['REPLACE']) !== False)
if ($debug) echoDebugLine(__FILE__,__LINE__,"<p>" . htmlspecialchars($arr_vars['REPLACE']) . " found</p>");
if (!isset($dataArray[$arr_vars['NAME']]))
if (isset($arr_vars['CONDITIONS']['NULL']))
$str_value = $arr_vars['CONDITIONS']['DEFAULT'];
} else if (isset($arr_vars['CONDITIONS']['DEFAULT'])) {
$str_value = $arr_vars['CONDITIONS']['DEFAULT'];
if (isset($arr_vars['CONDITIONS'][$dataArray[$arr_vars['NAME']]]))
$str_value = $arr_vars['CONDITIONS'][$dataArray[$arr_vars['NAME']]];
if (!empty($dataArray[$arr_vars['NAME']]) && isset($arr_vars['CONDITIONS']['NOTNULL'])) {
$str_value = $arr_vars['CONDITIONS']['NOTNULL'];
} else if (isset($arr_vars['CONDITIONS']['DEFAULT'])) {
$str_value = $arr_vars['CONDITIONS']['DEFAULT'];
$str_value = $this->_parseComplex($str_value,$dataArray,$strict,$debug);
$str_value =
$this->_parseSimple($str_value,$dataArray,$strict,$debug);
if ($debug) echoDebugLine(__FILE__,__LINE__,$arr_vars['NAME'] . ":<br />" . htmlspecialchars($str_value));
//echoDebugLine(__FILE__,__LINE__,"<p>\$str_return</p><pre>" . htmlspecialchars($str_return) . "</pre>");
$str_return = str_replace($arr_vars['REPLACE'],$str_value,$str_return);
//echoDebugLine(__FILE__,__LINE__,"<p>\$str_return</p><pre>" . htmlspecialchars($str_return) . "</pre><hr />");
protected function _parseSimple($aTmpl,$dataArray,$strict=False,$debug=False)
if ($debug) echoDebugMethod(__FILE__,get_class($this),"OCSP_TEMPLATE::parseSimple()");
foreach($this->simpleVars as $cha_type =>
$arr_typeVars)
if ($debug) echoDebugLine(__FILE__,__LINE__,"<h1>Type: {
$cha_type}</
h1>
");
foreach($arr_typeVars as $str_name => $arr_varDesc)
if ($strict && !isset($dataArray[$arr_varDesc['NAME']]))
if (strpos($str_return,$arr_varDesc['REPLACE']) !== False)
$str_value = (isset($dataArray[$arr_varDesc['NAME']]) ? $dataArray[$arr_varDesc['NAME']] : "");
$str_value = $this->_getVarValue($str_value,$arr_varDesc,$debug);
if ($str_value = isset
($dataArray[$arr_varDesc['NAME']]))
if (is_array($str_value))
$str_value = serialize($str_value);
$str_value = base64_encode($str_value);
if ($debug) echoDebugLine(__FILE__,__LINE__,"<h2>GET_VAR: {
$arr_varDesc['NAME']}</
h2><
pre>
" .
print_r($_GET,True) .
"</pre>");
$str_value=(isset($_GET['oaxArg'][$arr_varDesc['NAME']]) ? $_GET['oaxArg'][$arr_varDesc['NAME']] : "");
$str_value=(isset($_GET[$arr_varDesc['NAME']]) ? $_GET[$arr_varDesc['NAME']] : $val);
$str_value = $this->_getVarValue($str_value,$arr_varDesc,$debug);
case PCF_TMPLVAR_SESSION:
if ($str_value =
OCSP_SESSION::getInstance(True)->getValue($arr_varDesc['NAME']))
$str_value = $this->_getVarValue($str_value,$arr_varDesc,$debug);
$str_value = (isset($_POST[$arr_varDesc['NAME']]) ? $_POST[$arr_varDesc['NAME']] : Null);
$str_value = $this->_getVarValue($str_value,$arr_varDesc,$debug);
$str_value =
(isset
($_SERVER[$arr_varDesc['NAME']]) ?
$_SERVER[$arr_varDesc['NAME']] :
Null);
$str_value =
$this->_getVarValue($str_value,$arr_varDesc,$debug);
case PCF_TMPLVAR_GLOBALS:
if ($str_value =
OCSP_CONF::getInstance()->getValue($arr_varDesc['NAME']))
$str_value = $this->_getVarValue($str_value,$arr_varDesc,$debug);
if (isset($GLOBALS[$arr_varDesc['NAME']]))
$str_value = $this->_getVarValue($GLOBALS[$arr_varDesc['NAME']],$arr_varDesc,$debug);
if (isset($GLOBALS['OCSP_CONF'][$arr_varDesc['NAME']]))
$str_value = $this->_getVarValue($GLOBALS['OCSP_CONF'][$arr_varDesc['NAME']],$arr_varDesc,$debug);
if (isset($GLOBALS['OCSP_VAL'][$arr_varDesc['NAME']]))
$str_value = $this->_getVarValue($GLOBALS['OCSP_VAL'][$arr_varDesc['NAME']],$arr_varDesc,$debug);
//echoDebugLine(__FILE__,__LINE__,"<p>{$cha_type}[{$str_name}] :" . htmlspecialchars($arr_varDesc['REPLACE']) . "</p><pre>" . htmlspecialchars($str_return) . "</pre>");
$str_return = str_replace($arr_varDesc['REPLACE'],$str_value,$str_return);
//echoDebugLine(__FILE__,__LINE__,"<pre>" . htmlspecialchars($str_return) . "</pre><p>{$cha_type}[{$str_name}]</p><hr />");
* checks the format an returns the proper formated value
protected function _getVarValue($aValue,$varDesc,$debug)
if ($debug) echoDebugMethod(__FILE__,get_class($this),"OCSP_TEMPLATE::_getVarValue()",print_r($varDesc,True));
if (isset($varDesc['KEYS']) && is_array($varDesc['KEYS']))
foreach($varDesc['KEYS'] as $str_key)
if (isset($arr_value[$str_key]))
$arr_value = $arr_value[$str_key];
$str_return = $arr_value;
if (isset($varDesc['FORMATTYPE']))
switch($varDesc['FORMATTYPE'])
pcf_require_class("OCSP_DATE","common/");
$obj_date = new OCSP_DATE();
$obj_date->setDateStr($str_return);
$str_return =
$obj_date->dateStr($varDesc['FORMAT']);
if ($debug) echoDebugLine(__FILE__
,__LINE__
,"Value: " .
intval($str_return));
if (!empty($varDesc['FORMAT']))
$str_return = sprintf($varDesc['FORMAT'],$str_return);
if ($debug) echoDebugLine(__FILE__,__LINE__,"Value: " . intval($str_return));
if (!empty($varDesc['FORMAT']))
$str_return = str_replace($varDesc['FORMAT'],"\\" . $varDesc['FORMAT'], $str_return);
$str_return = pcf_js_escape($str_return);
if ($debug) echoDebugLine(__FILE__,__LINE__,"Value: " . intval($str_return));
if ($debug) echoDebugLine(__FILE__,__LINE__,"Value: " . intval($str_return));
return intval($str_return);
if ($debug) echoDebugLine(__FILE__,__LINE__,"Value: " . intval($str_return));
* parse special values of a template
* @param array $dataArray
public function parseSpecials($strTmpl,$dataArray,$debug)
if ($debug) echoDebugMethod(__FILE__,get_class($this),"OCSP_TEMPLATE::parseSpecials()");
return pcf_tmpl_repl_specials($strTmpl,$dataArray);
* returns the parsed template
* @param array $dataArray
public function getParsedTemplate($dataArray,$debug=False)
if ($debug) echoDebugMethod(__FILE__,get_class($this),"OCSP_TEMPLATE::getParsedTemplate();");
$str_return =
$this->_parseSimple($str_return,$dataArray,False,$debug);
* parses only the set values and keeps other placeholders
* @param array $dataArray
public function getValueParsedTemplate($dataArray,$debug=False)
if ($debug) echoDebugMethod(__FILE__,get_class($this),"OCSP_TEMPLATE::getValueParsedTemplate();");
$str_return =
$this->_parseSimple($str_return,$dataArray,True,$debug);
Documentation generated on Thu, 08 Jan 2009 17:47:11 +0100 by phpDocumentor 1.4.0a2