Index: branches/5.1.x/core/kernel/processors/main_processor.php =================================================================== diff -u -N -r12127 -r12657 --- branches/5.1.x/core/kernel/processors/main_processor.php (.../main_processor.php) (revision 12127) +++ branches/5.1.x/core/kernel/processors/main_processor.php (.../main_processor.php) (revision 12657) @@ -1,6 +1,6 @@ Tag=='include') $tag->Tag='MyInclude'; - return parent::ProcessTag($tag); - } - - /** * Base folder for all template includes * * @param Array $params * @return string */ function TemplatesBase($params) { - $force_admin = array_key_exists('force_admin', $params) && $params['force_admin']; - $module = array_key_exists('module', $params) ? $params['module'] : 'core'; + static $cached = Array (); - if ($this->Application->IsAdmin() || $force_admin) { - if ($module == 'in-portal') { - $module = 'kernel'; - } + $cache_key = crc32( serialize($params) ); - $path = $force_admin ? '/core/admin_templates' : THEMES_PATH; - $path = preg_replace('/\/(.*?)\/(.*)/', $module.'/\\2', $path); // remove leading slash + substitute module - } - else { - $path = mb_substr(THEMES_PATH, 1); + if (!array_key_exists($cache_key, $cached)) { + $force_admin = array_key_exists('force_admin', $params) && $params['force_admin']; + $module = array_key_exists('module', $params) ? $params['module'] : 'core'; - if (mb_strtolower($module) == 'in-portal') { - $module_folder = 'platform'; + if ($this->Application->IsAdmin() || $force_admin) { + if ($module == 'in-portal') { + $module = 'kernel'; + } + + $path = $force_admin ? '/core/admin_templates' : THEMES_PATH; + $path = preg_replace('/\/(.*?)\/(.*)/', $module.'/\\2', $path); // remove leading slash + substitute module } else { - $module_folder = $this->Application->findModule('Name', $module, 'TemplatePath'); + $path = mb_substr(THEMES_PATH, 1); + + if (mb_strtolower($module) == 'in-portal') { + $module_folder = 'platform'; + } + else { + $module_folder = $this->Application->findModule('Name', $module, 'TemplatePath'); + } + + $path .= rtrim('/' . trim($module_folder, '/'), '/') . '/'; } - $path .= rtrim('/' . trim($module_folder, '/'), '/') . '/'; + $cached[$cache_key] = $this->Application->BaseURL() . $path; } - return $this->Application->BaseURL() . $path; + return $cached[$cache_key]; } /** @@ -217,54 +214,34 @@ } /** - * Returns block parameter by name + * Returns block parameter by name (used only as "check" parameter value for "m_if" tag !) * * @param Array $params * @return stirng * @access public */ function Param($params) { - //$parser =& $this->Application->recallObject('TemplateParser'); $name = $params['name']; - if (isset($this->Application->LateParsed[$name])) { + + /*if (isset($this->Application->LateParsed[$name])) { $f = $this->Application->PreParsedBlocks['capture_'.$name.$this->Application->LateParsed[$name]]; $this->Application->Parser->SetParam($name, $f(array())); - } + }*/ $res = $this->Application->Parser->GetParam($params['name']); - if ($res === false) $res = ''; - if (isset($params['plus'])) + if ($res === false) { + $res = ''; + } + + if (isset($params['plus'])) { $res += $params['plus']; + } + return $res; } - function DefaultParam($params) - { - foreach ($params as $key => $val) { - if ($this->Application->Parser->GetParam($key) === false) { - $this->Application->Parser->SetParam($key, $val); - } - } - } - /** - * Gets value of specified field from specified prefix_special and set it as parser param - * - * @param Array $params - */ - /*function SetParam($params) - { - // - list($prefix_special, $field_name) = explode(':', $params['src']); - - $object =& $this->Application->recallObject($prefix_special); - $name = $this->SelectParam($params, 'param,name,var'); - - $this->Application->Parser->SetParam($name, $object->GetField($field_name) ); - }*/ - - /** * Compares block parameter with value specified * * @param Array $params @@ -273,9 +250,9 @@ */ function ParamEquals($params) { - //$parser =& $this->Application->recallObject('TemplateParser'); $name = $this->SelectParam($params, 'name,var,param'); $value = $params['value']; + return ($this->Application->Parser->GetParam($name) == $value); } @@ -379,7 +356,9 @@ */ function GetConst($params) { - return defined($this->SelectParam($params, 'name,const')) ? constant($this->SelectParam($params, 'name,const,param')) : ''; + $constant_name = $this->SelectParam($params, 'name,const'); + + return defined($constant_name) ? constant($constant_name) : ''; } /** @@ -504,7 +483,8 @@ } } - $translation = $this->Application->Phrase($phrase_name); + $no_editing = array_key_exists('no_editing', $params) && $params['no_editing']; + $translation = $this->Application->Phrase($phrase_name, !$no_editing); if (isset($params['escape']) && $params['escape']) { $translation = htmlspecialchars($translation, ENT_QUOTES); @@ -596,75 +576,6 @@ } } - /** - * Includes template - * and returns it's - * parsed version - * - * @param Array $params - * @return string - * @access public - */ - function MyInclude($params) - { - if (defined('NPARSER') && NPARSER) { - return $this->Application->Parser->IncludeTemplate($params, isset($params['is_silent']) ? 1 : 0); - } - - $BlockParser =& $this->Application->makeClass('TemplateParser'); - /* @var $BlockParser TemplateParser */ - -// $BlockParser->SetParams($params); - $parser =& $this->Application->Parser; - $this->Application->Parser =& $BlockParser; - - // this is for the parser to know the master template in case an error occurs, - // ParseTemplate will reset it anyway, but this will allow error handler to display the tempalte - // which tries to include missing template for example - $this->Application->Parser->TemplateName = $parser->TemplateName; - - $t = $this->SelectParam($params, 't,template,block,name'); - $t = eregi_replace("\.tpl$", '', $t); - - if (!$t) { - trigger_error('Template name not specified in <inp2:m_include .../> tag', E_USER_ERROR); - } - - if (isset($this->Application->PreParsedBlocks[$t]) ) { - $params['name'] = $t; - $res = $this->Application->ParseBlock($params); - } - else { - $res = $BlockParser->ParseTemplate($t, 1, $params, isset($params['is_silent']) ? 1 : 0 ); - } - - if (!$BlockParser->DataExists && ((isset($params['data_exists']) && $params['data_exists']) || isset($params['block_no_data']))) { - if ($block_no_data = getArrayValue($params, 'block_no_data')) { - if (isset($this->Application->PreParsedBlocks[$block_no_data]) ) { - // block_no_data is another block name - $res = $this->Application->ParseBlock(Array('name' => $block_no_data)); - } - else { - // block_no_data is template name (only looks through real templates) - $res = $BlockParser->ParseTemplate($block_no_data, 1, Array(), getArrayValue($params, 'is_silent')); - } - } - else { - $res = ''; - } - } - - $this->Application->Parser =& $parser; - $this->Application->Parser->DataExists = $this->Application->Parser->DataExists || $BlockParser->DataExists; - - if (isset($params['return_params']) && $params['return_params']) { - $new_params = array_merge($this->Application->Parser->Params, $BlockParser->ParamsStack[0]); - $this->Application->Parser->SetParams($new_params, false); - } - - return $res; - } - function ModuleInclude($params) { $ret = ''; @@ -707,7 +618,8 @@ if ($no_data) { $block_params['block_no_data'] = $module_prefix.'/'.$no_data; } - $ret .= $this->MyInclude($block_params); + + $ret .= $this->Application->Parser->IncludeTemplate($block_params, isset($block_params['is_silent']) ? 1 : 0); } return $ret; @@ -718,67 +630,7 @@ return $this->Application->isModuleEnabled( $params['module'] ); } - /*function Kernel_Scripts($params) - { - return ''; - }*/ - - - /*function GetUserPermission($params) - { - // echo"GetUserPermission $params[name]"; - if ($this->Application->RecallVar('user_type') == 1) - return 1; - else { - $perm_name = $params[name]; - $aPermissions = unserialize($this->Application->RecallVar('user_permissions')); - if ($aPermissions) - return $aPermissions[$perm_name]; - } - }*/ - - /** - * Set's parser block param value - * - * @param Array $params - * @access public - */ - function AddParam($params) - { - $parser =& $this->Application->Parser; // recallObject('TemplateParser'); - foreach ($params as $param => $value) { - $this->Application->SetVar($param, $value); - $parser->SetParam($param, $value); - $parser->AddParam('/\$'.$param.'/', $value); - } - } - - /*function ParseToVar($params) - { - $var = $params['var']; - $tagdata = $params['tag']; - $parser =& $this->Application->Parser; //recallObject('TemplateParser'); - $res = $this->Application->ProcessTag($tagdata); - - $parser->SetParam($var, $res); - $parser->AddParam('/\$'.$var.'/', $res); - return ''; - }*/ - - /*function TagNotEmpty($params) - { - $tagdata = $params['tag']; - $res = $this->Application->ProcessTag($tagdata); - return $res != ''; - }*/ - - /*function TagEmpty($params) - { - return !$this->TagNotEmpty($params); - }*/ - - /** * Checks if debug mode is on * * @param Array $params @@ -787,10 +639,10 @@ */ function IsDebugMode($params) { - return $this->Application->isDebugMode(); + return defined('DEBUG_MODE') && $this->Application->isDebugMode(); } - function MassParse($params) + /*function MassParse($params) { $qty = $params['qty']; $block = $params['block']; @@ -830,7 +682,7 @@ $o.= $this->Application->ParseBlock($block_params, 1); } return $o; - } + }*/ function LoggedIn($params) { @@ -1052,8 +904,10 @@ function RootCategoryName($params) { - $root_phrase = $this->Application->ConfigValue('Root_Name'); - return $this->Application->Phrase($root_phrase); + $phrase_name = $this->Application->ConfigValue('Root_Name'); + $no_editing = array_key_exists('no_editing', $params) && $params['no_editing']; + + return $this->Application->Phrase($phrase_name, !$no_editing); } /** @@ -1072,15 +926,18 @@ } } - function CaptchaImage($params){ + function CaptchaImage($params) + { + $this->NoDebug($params); + $this->Application->SetVar('skip_last_template', 1); + $captcha_helper =& $this->Application->recallObject('CaptchaHelper'); /* @var $captcha_helper kCaptchaHelper */ - $captcha_helper->GenerateCaptchaImage( - $this->Application->RecallVar($this->Application->GetVar('var')), - $this->Application->GetVar('w'), - $this->Application->GetVar('h'), - true - ); + + // generate captcha code + $code = $captcha_helper->prepareCode( $this->Application->GetVar('var') ); + + $captcha_helper->GenerateCaptchaImage($code, $this->Application->GetVar('w'), $this->Application->GetVar('h'), true); } function SID($params)