* * @return string */ function FindTag() { $tagOpen = strpos($this->Template, '<%', $this->Position); //Finding tag start $inp_tag = false; $tagOpenLen = 2; $inpOpen = strpos($this->Template, 'Position); if ($inpOpen !== false && ($tagOpen === false || $inpOpen < $tagOpen)) { $tagOpen = $inpOpen; $inp_tag = true; $tagOpenLen = 6; } if ($tagOpen === false) { //If not tags left - adding all other data $this->AppendOutput(substr($this->Template, $this->Position)); return false; } //Adding all data before tag open $this->AppendOutput(substr($this->Template, $this->Position, $tagOpen - $this->Position)); //Finding tag end $tagCloseLen = 2; if ($inp_tag) { $tagClose = strpos($this->Template, "/>", $tagOpen); $inpClose = strpos($this->Template, "", $tagOpen); if ($inpClose !== false && $inpClose < $tagClose) { $tagClose = $inpClose; $tagCloseLen = 7; } } else { $tagClose = strpos($this->Template, "%>", $tagOpen); } if ($tagClose === false) die ("Can't find tag closing"); //Cutting out the tag itself $tag = substr($this->Template, $tagOpen + $tagOpenLen, $tagClose - $tagOpen - $tagOpenLen); if ($inp_tag) { if (strpos($tag, '_') !== false) { list($prefix, $the_tag) = explode('_', $tag, 2); $tag = $prefix.':'.$the_tag; } else $tag .= ':'; } //Seting current position right after the tag $this->Position = $tagClose + $tagCloseLen; return $tag; } function Parse($template, $name='unknown') { $this->Template = $template; $this->TemplateName = $name; $this->Position = 0; $this->Output = ''; //While we have more tags while ($tag_data = $this->FindTag()) { //Create tag object from passed tag data if (defined('DEBUG_TAGS')&&DEBUG_TAGS) { global $debugger; $debugger->appendHTML("mode: ".$this->SkipModeName()." tag ".$debugger->highlightString($tag_data)." in ".$debugger->getFileLink($debugger->getLocalFile(DOC_ROOT.BASE_PATH.THEMES_PATH.'/'.$this->TemplateName).'.tpl', $this->CurrentLineNumber(), '', true)); } $tag =& new MyTag($tag_data, $this); if (!$this->CheckRecursion($tag)) //we do NOT process closing tags { $tag->Process(); } } if ( !$this->GetParam('from_inportal') ) { if ( strpos($this->Output, 'Application->recallObject('Inp1Parser'); $this->Output = $inp1_parser->Parse($name, $this->Output); } } return $this->Output; } function ParseBlock($params, $force_pass_params=0, $as_template=false) { if (defined('EXPERIMENTAL_PRE_PARSE')) { if (isset($this->Application->PreParsedBlocks[$params['name']]) ) { $f = $this->Application->PreParsedBlocks[$params['name']]; //$this->SetParams($params); return $f($params); } } $BlockParser =& $this->Application->Factory->makeClass('TemplateParser'); if (isset($params['pass_params']) || $force_pass_params) { $BlockParser->SetParams(array_merge($this->Params, $params)); } else $BlockParser->SetParams($params); $this->Application->Parser =& $BlockParser; if (!isset($params['name'])) die("***Error: Block name not passed to ParseBlock
"); $templates_cache =& $this->Application->recallObject('TemplatesCache'); $template_name = $as_template ? $params['name'] : $templates_cache->GetTemplateFileName($params['name']) . '-block:'.$params['name']; $silent = getArrayValue($params, 'from_inportal') && !defined('DBG_TEMPLATE_FAILURE'); $o = $BlockParser->Parse( $templates_cache->GetTemplateBody($params['name'], $silent), $template_name ); $this->Application->Parser =& $this; return $o; } } class MyTag extends Tag { /** * Set's Prefix and Special for Tag object * based on ones from tagname * * @param string $tag_data * @access protected */ function ParseTagData($tag_data) { $tag_data = $this->ReplaceParams($tag_data) . ' '; $tag_data = $this->Application->ReplaceLanguageTags($tag_data); list ($key_data, $params) = explode(' ', $tag_data, 2); //cand.test_TagProcessor:PrintList $tmp=explode(':',$key_data); $this->Tag=$tmp[1]; $tmp=$this->Application->processPrefix($tmp[0]); $this->Prefix=$tmp['prefix']; $this->Special=$tmp['special']; $this->Processor=$this->Prefix; if ($params != '') $this->ParseNamedParams($params); } /** * Set's Prefix and Special for TagProcessor * based on tag beeing processed * * @return string * @access protected */ function DoProcessTag() { // $tag->Prefix - l_TagProcessor $tmp = $this->Application->processPrefix($this->Processor); $processor =& $this->Application->recallObject($tmp['prefix'].'_TagProcessor'); // $this->Processor $tmp=explode('_',$tmp['prefix'],2); $processor->Prefix=$tmp[0]; $processor->Special=$this->Special; return $processor->ProcessTag($this); } /** * Process IF tags in specific way * */ function Process() { if ($this->Processor == 'm' || $this->Processor == 'm_TagProcessor') { //if we are procssing Main tags if ($this->Tag == 'block') { $tag =& new BlockTag('', $this->Parser); $tag->CopyFrom($this); $tag->Process(); } elseif ($this->Parser->SkipMode == skip_tags) { return; } elseif ( $this->Tag == 'if' || $this->Tag == 'ifnot' || $this->Tag == 'else' || $this->Tag == 'elseif' ) { $tag =& new MyConstructTag('', $this->Parser); $tag->CopyFrom($this); $tag->Process(); } elseif ($this->Tag == 'xml') { $tag =& new XMLTag('', $this->Parser); $tag->CopyFrom($this); $tag->Process(); } else { if ($this->Parser->SkipMode == skip) return; //if (!$this->ProcessMainTag()) //other main tags $this->ProcessTag(); } } else { //normal tags - processors other than main if ($this->Parser->SkipMode == skip_tags || $this->Parser->SkipMode == skip) return; //do not parse if we skipping tags $this->ProcessTag(); //$this->Parser->AppendOutput(''.$this->Tag.''); } } } class MyConstructTag extends ConstructTag { function GetLogic() { $prefix = $this->GetParam('prefix'); $function = $this->GetParam('function'); if ($prefix !== false) { $tag =& new MyTag('', $this->Parser); $tag->Tag = $function; $tmp = $this->Application->processPrefix($prefix); $tag->Processor = $tmp['prefix']; $tag->Prefix=$tmp['prefix']; $tag->Special=$tmp['special']; $tag->NamedParams = $this->NP; $this->Logic = $tag->DoProcessTag(); // echo " this->Logic : ".$this->Logic."
"; } else { $this->Logic = $function; } } } class MyApplication extends kApplication { function RegisterDefaultClasses() { parent::RegisterDefaultClasses(); $this->registerClass('InpTemplateParser',MODULES_PATH.'/in-commerce/general/my_application.php','TemplateParser'); $this->registerClass('Inp1Parser',MODULES_PATH.'/in-commerce/general/inp1_parser.php','Inp1Parser'); $this->registerClass('InpSessionStorage',MODULES_PATH.'/in-commerce/general/inp_ses_storage.php','SessionStorage'); $this->registerClass('kCatDBItem',MODULES_PATH.'/in-commerce/general/cat_dbitem.php'); $this->registerClass('kCatDBList',MODULES_PATH.'/in-commerce/general/cat_dblist.php'); $this->registerClass('kCatDBEventHandler',MODULES_PATH.'/in-commerce/general/cat_event_handler.php'); $this->registerClass('InpLoginEventHandler',MODULES_PATH.'/in-commerce/general/inp_login_event_handler.php','login_EventHandler'); $this->registerClass('InpDBEventHandler',MODULES_PATH.'/in-commerce/general/inp_db_event_handler.php','kDBEventHandler'); $this->registerClass('InpTempTablesHandler',MODULES_PATH.'/in-commerce/general/inp_temp_handler.php','kTempTablesHandler'); $this->registerClass('InpUnitConfigReader',MODULES_PATH.'/in-commerce/general/inp_unit_config_reader.php','kUnitConfigReader'); $this->registerClass('InpCustomFieldsHelper',MODULES_PATH.'/in-commerce/general/custom_fields.php','InpCustomFieldsHelper'); } function KernelDie($message) { $this->trigerError($message,E_USER_ERROR); exit; } function ConfigValue($name) { return $this->DB->GetOne('SELECT VariableValue FROM '.TABLE_PREFIX.'ConfigurationValues WHERE VariableName = '.$this->DB->qstr($name) ); } } ?>