Index: branches/unlabeled/unlabeled-1.58.2/core/kernel/utility/unit_config_reader.php =================================================================== diff -u -r5642 -r5726 --- branches/unlabeled/unlabeled-1.58.2/core/kernel/utility/unit_config_reader.php (.../unit_config_reader.php) (revision 5642) +++ branches/unlabeled/unlabeled-1.58.2/core/kernel/utility/unit_config_reader.php (.../unit_config_reader.php) (revision 5726) @@ -500,13 +500,15 @@ if (!isset($this->configData[$rets[1]])) { $this->loadConfig($rets[1]); } - $ret = getArrayValue($this->configData, $rets[1], $name, $rets[2]); + $ret = isset($this->configData[$rets[1]][$name][$ret[2]]) ? $this->configData[$rets[1]][$name][$ret[2]] : false; +// $ret = getArrayValue($this->configData, $rets[1], $name, $rets[2]); } else { if (!isset($this->configData[$prefix])) { $this->loadConfig($prefix); } - $ret = getArrayValue($this->configData, $prefix, $name); + $ret = isset($this->configData[$prefix][$name]) ? $this->configData[$prefix][$name] : false; +// $ret = getArrayValue($this->configData, $prefix, $name); } return $ret === false ? $default : $ret; } @@ -523,7 +525,7 @@ if (!isset($this->configData[$prefix])) { $this->loadConfig($prefix); } - + return $this->configData[$prefix]; } Index: branches/unlabeled/unlabeled-1.15.2/core/kernel/utility/event.php =================================================================== diff -u -r5497 -r5726 --- branches/unlabeled/unlabeled-1.15.2/core/kernel/utility/event.php (.../event.php) (revision 5497) +++ branches/unlabeled/unlabeled-1.15.2/core/kernel/utility/event.php (.../event.php) (revision 5726) @@ -1,7 +1,7 @@ Init($prefix,$special); $this->Name = getArrayValue($params,'name'); } @@ -146,7 +146,7 @@ } if (isset($specificParams)) $this->specificParams = $specificParams; } - + function setEventParam($name,$value) { $this->specificParams[$name]=$value; @@ -158,14 +158,14 @@ array_unshift($args, $this->specificParams); return call_user_func_array('getArrayValue', $args); // getArrayValue($this->specificParams, $name); } - + function getPrefixSpecial($from_submit=false) { $separator=!$from_submit?'.':'_'; $ret=$this->Prefix.$separator.$this->Special; return rtrim($ret,$separator); } - + /** * Set's pseudo class that differs from * the one specified in $Prefix @@ -177,15 +177,15 @@ { $this->pseudoClass = $this->Prefix.$appendix; } - + function Init($prefix, $special = '') { $this->Prefix = $prefix; $this->pseudoClass = $prefix; // default value $this->Special = $special; $this->Prefix_Special = rtrim($this->Prefix.'.'.$this->Special,'.'); } - + /** * Returns object used in event * @@ -197,7 +197,7 @@ $object =& $this->Application->recallObject($this->Prefix_Special, $this->pseudoClass, $params); return $object; } - + /** * Calls passed event by name in current prefix/special environment * Called event gets this event as MasterEvent, @@ -216,15 +216,15 @@ $child_event->redirect_params = $this->redirect_params; $child_event->redirect_script = $this->redirect_script; $child_event->Name = $name; - + $this->Application->HandleEvent( $child_event ); - + $this->status = $child_event->status; $this->redirect = $child_event->redirect; $this->redirect_params = $child_event->redirect_params; $this->redirect_script = $child_event->redirect_script; } - + /** * Set's redirect param for event * @@ -236,7 +236,7 @@ { $this->redirect_params[$name] = $value; } - + /** * Allows to merge passed redirect params hash with existing ones * @@ -247,7 +247,7 @@ { $this->redirect_params = array_merge_recursive2($this->redirect_params, $params); } - + /** * Returns Master event name if any * @@ -258,9 +258,9 @@ { return is_object($this->MasterEvent) ? $this->MasterEvent->Name : false; } - + /** - * Allows to tell if this event was called some how (e.g. subevent, hook) from event requested + * Allows to tell if this event was called some how (e.g. subevent, hook) from event requested * * @param string $event_key event key in format [prefix[.special]:]event_name * @return unknown @@ -271,10 +271,10 @@ if (strpos($event_key, ':') === false) { $event_key = $this->getPrefixSpecial().':'.$event_key; } - + return $event_manager->eventRunning($event_key); } - + /** * Returns section for current event * @@ -286,16 +286,16 @@ if ($perm_section) { return $perm_section; } - + $top_prefix = $this->getEventParam('top_prefix'); $section = $this->Application->getUnitOption($top_prefix.'.main', 'PermSection'); - + if (!$section) { trigger_error('Permission section not specified for prefix '.$top_prefix.'', E_USER_ERROR); } return $section; } - + } ?> \ No newline at end of file Index: branches/unlabeled/unlabeled-1.22.2/core/kernel/kbase.php =================================================================== diff -u -r5615 -r5726 --- branches/unlabeled/unlabeled-1.22.2/core/kernel/kbase.php (.../kbase.php) (revision 5615) +++ branches/unlabeled/unlabeled-1.22.2/core/kernel/kbase.php (.../kbase.php) (revision 5726) @@ -467,7 +467,7 @@ { foreach($this->Fields as $field => $options) { - if( getArrayValue($options, 'default') === '#NOW#') + if( isset($options['default']) && $options['default'] === '#NOW#') { $this->Fields[$field]['default'] = adodb_mktime(); } @@ -559,9 +559,9 @@ function PrepareOptions($field_name) { - if( $formatter_class = getArrayValue($this->Fields[$field_name], 'formatter') ) + if ( isset($this->Fields[$field_name]['formatter']) ) { - $formatter =& $this->Application->recallObject($formatter_class); + $formatter =& $this->Application->recallObject( $this->Fields[$field_name]['formatter'] ); $formatter->PrepareOptions($field_name, $this->Fields[$field_name], $this); } } @@ -598,7 +598,7 @@ { return $this->GetID() ? false : true; } - + /** * Returns parent table information * Index: branches/unlabeled/unlabeled-1.37.2/core/kernel/event_manager.php =================================================================== diff -u -r5715 -r5726 --- branches/unlabeled/unlabeled-1.37.2/core/kernel/event_manager.php (.../event_manager.php) (revision 5715) +++ branches/unlabeled/unlabeled-1.37.2/core/kernel/event_manager.php (.../event_manager.php) (revision 5726) @@ -380,11 +380,11 @@ $mode_hooks =& $this->afterHooks; } - $hooks = getArrayValue($mode_hooks, strtolower($event_key.'.'.$event->Name)); - if (!$hooks) { - $hooks = Array(); + if (!isset($mode_hooks[strtolower($event_key.'.'.$event->Name)])) { + $hooks = array(); + return $hooks; } - return $hooks; + return $mode_hooks[strtolower($event_key.'.'.$event->Name)]; } /** Index: branches/unlabeled/unlabeled-1.14.2/core/kernel/parser/template.php =================================================================== diff -u -r5566 -r5726 --- branches/unlabeled/unlabeled-1.14.2/core/kernel/parser/template.php (.../template.php) (revision 5566) +++ branches/unlabeled/unlabeled-1.14.2/core/kernel/parser/template.php (.../template.php) (revision 5726) @@ -175,6 +175,49 @@ $real_file = $this->GetRealFilename($filename); return file_exists($real_file); } + + + function GetPreParsed($template) + { + $real_name = $this->GetRealFilename($template); + $fname = $real_name.'.php'; + $fname = str_replace(FULL_PATH, FULL_PATH.'/kernel/cache', $fname); + + $tname = $real_name.'.tpl'; + if (defined('SAFE_MODE') && SAFE_MODE) { + $conn =& $this->Application->GetADODBConnection(); + $cached = $conn->GetRow('SELECT * FROM '.TABLE_PREFIX.'Cache WHERE VarName = "'.$fname.'"'); + if ($cached !== false && $cached['Cached'] > filemtime($tname)) { + return array('active' => 1, 'fname' => $fname, 'tname' => $tname, 'mode' => 'db', 'content' => $cached['Data']); + } + } + else { + if (file_exists($fname) && file_exists($tname) && filemtime($fname) > filemtime($tname)) { + return array('active' => 1, 'fname' => $fname, 'tname' => $tname, 'mode' => 'file'); + } + if (!file_exists($fname)) $this->CheckDir(dirname($fname)); //make sure to create directory if pre-parsed file does not exist + } + return array('active' => 0, 'fname' => $fname, 'tname' => $tname); + } + + function CheckDir($dir) + { + if (file_exists($dir)) { + return; + } + else { + $segments = explode('/', $dir); + $cur_path = ''; + foreach ($segments as $segment) { + // do not add leading / for windows paths (c:\...) + $cur_path .= preg_match('/^[a-zA-Z]{1}:/', $segment) ? $segment : '/'.$segment; + if (!file_exists($cur_path)) { + mkdir($cur_path); + } + } + } + } + } Index: branches/unlabeled/unlabeled-1.155.2/core/kernel/application.php =================================================================== diff -u -r5724 -r5726 --- branches/unlabeled/unlabeled-1.155.2/core/kernel/application.php (.../application.php) (revision 5724) +++ branches/unlabeled/unlabeled-1.155.2/core/kernel/application.php (.../application.php) (revision 5726) @@ -136,8 +136,20 @@ */ var $EventManager = null; + /** + * Ref to itself, needed because everybody used to write $this->Application, even inside kApplication + * + * @var kApplication + */ var $Application = null; + /** + * Ref for TemplatesChache + * + * @var TemplatesCache + */ + var $TemplatesCache = null; + var $CompilationCache = array(); //used when compiling templates var $CachedProcessors = array(); //used when running compiled templates @@ -632,12 +644,12 @@ if (!$this->RequestProcessed) $this->ProcessRequest(); $this->InitParser(); - $template_cache =& $this->recallObject('TemplatesCache'); + $this->TemplatesCache =& $this->recallObject('TemplatesCache'); $t = $this->GetVar('t'); if ($this->isModuleEnabled('In-CMS')) { $cms_handler =& $this->recallObject('cms_EventHandler'); - if (!$template_cache->TemplateExists($t) && !$this->IsAdmin()) { + if (!$this->TemplatesCache->TemplateExists($t) && !$this->IsAdmin()) { $t = $cms_handler->GetDesignTemplate(); } /*else { @@ -649,7 +661,7 @@ $this->Debugger->appendMemoryUsage('Application before Parsing:'); } - $this->HTML = $this->Parser->Parse( $template_cache->GetTemplateBody($t), $t ); + $this->HTML = $this->Parser->ParseTemplate( $t ); if ($this->isDebugMode() && constOn('DBG_PROFILE_MEMORY')) { $this->Debugger->appendMemoryUsage('Application after Parsing:'); @@ -905,11 +917,13 @@ $this->cache[$name] = $tpl; } + /* Seems to be not used anywhere... /Kostja + function SetTemplateBody($title,$body) { $templates_cache =& $this->recallObject('TemplatesCache'); $templates_cache->SetTemplateBody($title,$body); - } + }*/ function ProcessTag($tag_data) { @@ -1985,8 +1999,9 @@ function LoggedIn() { - $user =& $this->recallObject('u'); - $user_id = $user->GetID(); + $user_id = $this->Application->RecallVar('user_id'); +// $user =& $this->recallObject('u'); +// $user_id = $user->GetID(); $ret = $user_id > 0; if ($this->IsAdmin() && ($user_id == -1)) { Index: branches/unlabeled/unlabeled-1.10.2/core/kernel/parser/construct_tags.php =================================================================== diff -u -r5548 -r5726 --- branches/unlabeled/unlabeled-1.10.2/core/kernel/parser/construct_tags.php (.../construct_tags.php) (revision 5548) +++ branches/unlabeled/unlabeled-1.10.2/core/kernel/parser/construct_tags.php (.../construct_tags.php) (revision 5726) @@ -198,10 +198,8 @@ $template = new Template(); $template->SetBody($this->Parser->GetBuffer()); - $templates_cache =& $this->Application->recallObject('TemplatesCache'); - //Adding template to application' cache - $templates_cache->SetTemplate($this->BlockName, $template, $this->Parser->TemplateName); + $this->Application->TemplatesCache->SetTemplate($this->BlockName, $template, $this->Parser->TemplateName); if (defined('EXPERIMENTAL_PRE_PARSE')) { $code = $this->Parser->GetCode(); @@ -212,7 +210,7 @@ $this->Parser->UsedProcessors = null;*/ array_unshift($code, '$o = \'\';'); - array_unshift($code, '$application->Parser->SetParams($params);'); + array_unshift($code, '$application->Parser->SetParams($params, false);'); array_unshift($code, '$application =& kApplication::Instance();'); array_unshift($code, 'extract($params);'); Index: branches/unlabeled/unlabeled-1.61.2/core/kernel/processors/main_processor.php =================================================================== diff -u -r5715 -r5726 --- branches/unlabeled/unlabeled-1.61.2/core/kernel/processors/main_processor.php (.../main_processor.php) (revision 5715) +++ branches/unlabeled/unlabeled-1.61.2/core/kernel/processors/main_processor.php (.../main_processor.php) (revision 5726) @@ -512,21 +512,19 @@ function MyInclude($params) { $BlockParser =& $this->Application->makeClass('TemplateParser'); - $BlockParser->SetParams($params); +// $BlockParser->SetParams($params); $parser =& $this->Application->Parser; $this->Application->Parser =& $BlockParser; $t = $this->SelectParam($params, 't,template,block,name'); $t = eregi_replace("\.tpl$", '', $t); - $templates_cache =& $this->Application->recallObject('TemplatesCache'); - $res = $BlockParser->Parse( $templates_cache->GetTemplateBody($t, getArrayValue($params, 'is_silent')), $t ); + $res = $BlockParser->ParseTemplate( $t, 1, $params ); - if ( !$BlockParser->DataExists && (isset($params['data_exists']) || isset($params['block_no_data'])) ) { if ($block_no_data = getArrayValue($params, 'block_no_data')) { $res = $BlockParser->Parse( - $templates_cache->GetTemplateBody($block_no_data, getArrayValue($params, 'is_silent') ), + $this->Application->TemplatesCache->GetTemplateBody($block_no_data, getArrayValue($params, 'is_silent') ), $t ); } @@ -538,6 +536,7 @@ $this->Application->Parser->DataExists = $this->Application->Parser->DataExists || $BlockParser->DataExists; return $res; } + function ModuleInclude($params) { $ret = ''; @@ -859,7 +858,7 @@ $lang =& $this->Application->recallObject('lang.current'); header('Content-type: text/xml; charset='.$lang->GetDBField('Charset')); } - + function RootCategoryName($params) { $root_phrase = $this->Application->ConfigValue('Root_Name'); Index: branches/unlabeled/unlabeled-1.24.2/core/kernel/parser/template_parser.php =================================================================== diff -u -r5437 -r5726 --- branches/unlabeled/unlabeled-1.24.2/core/kernel/parser/template_parser.php (.../template_parser.php) (revision 5437) +++ branches/unlabeled/unlabeled-1.24.2/core/kernel/parser/template_parser.php (.../template_parser.php) (revision 5726) @@ -61,14 +61,16 @@ return $a_len > $b_len ? -1 : 1; } - function SetParams($params) + function SetParams($params, $for_parsing=true) { if (!is_array($params)) $params = Array(); $this->ForSort = array(); $this->Params = $params; $this->ParamsStack[$this->ParamsRecursionIndex] = $params; + if (!$for_parsing) return ; + foreach ($params as $key => $val) { $this->AddParam('/[{]{0,1}\$'.$key.'[}]{0,1}/i', $val, 1); //Do not sort every time } @@ -90,7 +92,7 @@ function SetParam($name, $value) { $this->Params[strtolower($name)] = $value; - $this->AddParam('/[{]{0,1}\$'.$name.'[}]{0,1}/i', $val, 0); + $this->AddParam('/[{]{0,1}\$'.$name.'[}]{0,1}/i', $value, $this->FromPreParseCache); } function SetBuffer($body) @@ -352,6 +354,97 @@ } } + function ParseTemplate($name, $pre_parse = 1, $params=array()) + { + $this->FromPreParseCache = false; + if ($this->GetParam('from_inportal')) $pre_parse = 0; + if ($pre_parse) { + $pre_parsed = $this->Application->TemplatesCache->GetPreParsed($name); + if ($pre_parsed && $pre_parsed['active']) { // active means good (not expired) pre-parsed cache + $this->FromPreParseCache = true; + $this->SetParams($params, 0); // 0 to disable params sorting and regexp generation - not needed when processing pre-parsed + ob_start(); + if ($pre_parsed['mode'] == 'file') { + include($pre_parsed['fname']); + } + else { + eval('?'.'>'.$pre_parsed['content']); + } + $output = ob_get_contents(); + ob_end_clean(); + } + else { + $this->SetParams($params); + + $this->CompiledBuffer .= '<'.'?php'."\n"; + $this->CompiledBuffer .= 'global $application;'."\n"; + + $this->CompiledBuffer .= '$params =& $application->Parser->Params;'."\n"; + $this->CompiledBuffer .= 'extract($params);'."\n"; + + $this->CompiledBuffer .= '$o = \'\';'."\n"; + + $output = $this->NewParse($this->Application->TemplatesCache->GetTemplateBody($name), $name); + + $this->CompiledBuffer .= '?'.'>'."\n"; + + if (defined('SAFE_MODE') && SAFE_MODE) { + if (!isset($conn)) $conn =& $this->Application->GetADODBConnection(); + $conn->Query('REPLACE INTO '.TABLE_PREFIX.'Cache (VarName, Data, Cached) VALUES ('.$conn->qstr($pre_parsed['fname']).','.$conn->qstr($this->CompiledBuffer).','.adodb_mktime().')'); + } + else { + $compiled = fopen($pre_parsed['fname'], 'w'); + fwrite($compiled, $this->CompiledBuffer); + fclose($compiled); + } + + } + if ( !$this->GetParam('from_inportal') && strpos($output, 'Application->recallObject('Inp1Parser'); + $output = $inp1_parser->NewParse($name, $output); + } + return $output; + } + + // pre-parse is OFF + $this->SetParams($params); + return $this->NewParse($this->Application->TemplatesCache->GetTemplateBody($name), $name, $pre_parse); + } + + function NewParse($template, $name='unknown', $pre_parse = 1) + { + $this->Template = $template; + $this->TemplateName = $name; + $this->Position = 0; + $this->Output = ''; + $this->TagHolder = new MyTagHolder(); + + $has_inp_tags = false; + + if (!getArrayValue($this->Params, 'PrefixSpecial')) { + $this->Params['PrefixSpecial'] = '$PrefixSpecial'; + } + + //While we have more tags + while ($tag_data = $this->FindTag2()) + { + if ($tag_data == '__COMMENT__') continue; + //Create tag object from passed tag data + if( $this->Application->isDebugMode() && constOn('DBG_SHOW_TAGS') ) + { + global $debugger; + $debugger->appendHTML('mode: '.$this->SkipModeName().' tag '.$debugger->highlightString($tag_data).' in '.$debugger->getFileLink($debugger->getLocalFile(FULL_PATH.THEMES_PATH.'/'.$this->TemplateName).'.tpl', $this->CurrentLineNumber(), '', true)); + } + $tag =& $this->TagHolder->GetTag($tag_data, $this); + + if (!$this->CheckRecursion($tag)) //we do NOT process closing tags + { + $tag->Process(); + } + } + return $this->Output; + } + function Parse($template, $name='unknown', $pre_parse = 1) { $this->Template = $template; @@ -365,16 +458,15 @@ if ($this->GetParam('from_inportal')) $pre_parse = 0; if (defined('EXPERIMENTAL_PRE_PARSE') && $pre_parse) { - $template_cache =& $this->Application->recallObject('TemplatesCache'); - $fname = $template_cache->GetRealFilename($this->TemplateName).'.php'; + $fname = $this->Application->TemplatesCache->GetRealFilename($this->TemplateName).'.php'; $fname = str_replace(FULL_PATH, FULL_PATH.'/kernel/cache', $fname); if (!defined('SAFE_MODE') || !SAFE_MODE) { $this->CheckDir(dirname($fname)); } - $tname = $template_cache->GetRealFilename($this->TemplateName).'.tpl'; + $tname = $this->Application->TemplatesCache->GetRealFilename($this->TemplateName).'.tpl'; $output = ''; $is_cached = false; ob_start();