Index: trunk/core/kernel/startup.php =================================================================== diff -u -N -r2581 -r2596 --- trunk/core/kernel/startup.php (.../startup.php) (revision 2581) +++ trunk/core/kernel/startup.php (.../startup.php) (revision 2596) @@ -80,6 +80,8 @@ safeDefine('CUSTOM_UPLOAD_PATH', '/templates/images/custom/'); safeDefine('MAX_UPLOAD_SIZE', min(ini_get('upload_max_filesize'), ini_get('post_max_size'))*1024*1024); +if (ini_get('safe_mode')) define('SAFE_MODE', 1); + safeDefine('CACHE_CONFIGS_FILES', 1); safeDefine('EXPERIMENTAL_PRE_PARSE', 1); safeDefine('SILENT_LOG', 0); Index: trunk/core/units/general/inp_ses_storage.php =================================================================== diff -u -N -r2540 -r2596 --- trunk/core/units/general/inp_ses_storage.php (.../inp_ses_storage.php) (revision 2540) +++ trunk/core/units/general/inp_ses_storage.php (.../inp_ses_storage.php) (revision 2596) @@ -25,7 +25,7 @@ $this->SetMode( $mode ); $this->SetCookieDomain( SERVER_NAME ); parent::Init($prefix,$special); - + if (!defined('ADMIN')) { $group_list = $this->Application->ConfigValue('User_GuestGroup').','.$this->Application->ConfigValue('User_LoggedInGroup'); $this->SetField('GroupList', $group_list); @@ -45,47 +45,47 @@ $this->DataValueField = 'VariableValue'; $this->DataVarField = 'VariableName'; } - + function LocateSession($sid) { $query = ' SELECT '.$this->TimestampField.' FROM '.$this->TableName.' WHERE '.$this->IDField.' = '.$this->Conn->qstr($sid); $result = $this->Conn->GetOne($query); - + if($result===false) return false; - + $this->Expiration = $result + $this->SessionTimeout; return true; } - + function UpdateSession(&$session) { $query = ' UPDATE '.$this->TableName.' SET '.$this->TimestampField.' = unix_timestamp() WHERE '.$this->IDField.' = '.$this->Conn->qstr($session->SID); $this->Conn->Query($query); } - - + + function StoreSession(&$session) { parent::StoreSession($session); $this->SetField($session, 'IpAddress', $_SERVER['REMOTE_ADDR']); $this->SetField($session, 'GroupList', $this->Application->ConfigValue('User_GuestGroup')); } - + function GetExpiredSIDs() { $query = ' SELECT '.$this->IDField.' FROM '.$this->TableName.' WHERE '.time().' - '.$this->TimestampField.' > '.$this->SessionTimeout; $ret = $this->Conn->GetCol($query); if($ret) $this->DeleteEditTables(); return $ret; - + } - + function DeleteEditTables() { - $tables = $this->Conn->GetCol('SHOW TABLES'); + $tables = $this->Conn->GetCol('SHOW TABLES'); $mask_edit_table = '/'.TABLE_PREFIX.'ses_(.*)_edit_(.*)/'; $mask_search_table = '/'.TABLE_PREFIX.'ses_(.*)_(.*)/'; - + $sql='SELECT COUNT(*) FROM '.$this->TableName.' WHERE '.$this->IDField.' = \'%s\''; foreach($tables as $table) { Index: trunk/kernel/units/general/cat_event_handler.php =================================================================== diff -u -N -r2041 -r2596 --- trunk/kernel/units/general/cat_event_handler.php (.../cat_event_handler.php) (revision 2041) +++ trunk/kernel/units/general/cat_event_handler.php (.../cat_event_handler.php) (revision 2596) @@ -4,48 +4,48 @@ $application->Factory->includeClassFile('kDBEventHandler'); class kCatDBEventHandler extends InpDBEventHandler { - + function OnCopy(&$event) { $object = $event->getObject(); $this->StoreSelectedIDs($event); $ids = $this->getSelectedIDs($event); $this->Application->StoreVar($event->getPrefixSpecial().'_clipboard', implode(',', $ids)); $this->Application->StoreVar($event->getPrefixSpecial().'_clipboard_mode', 'copy'); - + $this->Application->StoreVar('ClipBoard', 'COPY-0.'.$object->TableName.'.ResourceId=0'); $event->redirect_params = Array('opener' => 's', 'pass_events'=>true); //do not go up - STAY } - + function OnCut(&$event) { $object = $event->getObject(); $this->StoreSelectedIDs($event); $ids = $this->getSelectedIDs($event); $this->Application->StoreVar($event->getPrefixSpecial().'_clipboard', implode(',', $ids)); $this->Application->StoreVar($event->getPrefixSpecial().'_clipboard_mode', 'cut'); - + $this->Application->StoreVar('ClipBoard', 'CUT-0.'.$object->TableName.'.ResourceId=0'); $event->redirect_params = Array('opener' => 's', 'pass_events'=>true); //do not go up - STAY } - + function OnPaste(&$event) { $ids = $this->Application->RecallVar($event->getPrefixSpecial().'_clipboard'); if ($ids == '') { $event->redirect = false; return; } - + //recalling by different name, because we may get kDBList, if we recall just by prefix $object =& $this->Application->recallObject($event->getPrefixSpecial().'.item', $event->Prefix); $this->prepareObject($object, $event); - + if ($this->Application->RecallVar($event->getPrefixSpecial().'_clipboard_mode') == 'copy') { $ids_arr = explode(',', $ids); - + $temp =& $this->Application->recallObject($event->getPrefixSpecial().'_TempHandler', 'kTempTablesHandler'); - + if($ids_arr) { $temp->CloneItems($event->Prefix, $event->Special, $ids_arr); @@ -60,7 +60,7 @@ } $event->status = erSUCCESS; } - + /** * Occurs when pasting category * @@ -70,7 +70,7 @@ { $inp_clipboard = $this->Application->RecallVar('ClipBoard'); $inp_clipboard = explode('-', $inp_clipboard, 2); - + if($inp_clipboard[0] == 'COPY') { $saved_cat_id = $this->Application->GetVar('m_cat_id'); @@ -100,7 +100,7 @@ $this->Application->SetVar('m_cat_id', $saved_cat_id); } } - + /** * Apply scope clause * @@ -109,7 +109,7 @@ function SetCustomQuery(&$event) { $object =& $event->getObject(); - + if ($event->Special != 'showall') { if ( $event->getEventParam('parent_cat_id') ) { $parent_cat_id = $event->getEventParam('parent_cat_id'); @@ -123,7 +123,7 @@ $parent_cat_id = 0; } } - + if ((string) $parent_cat_id != 'any') { if ($event->getEventParam('recursive')) { $current_path = $this->Conn->GetOne('SELECT ParentPath FROM '.TABLE_PREFIX.'Category WHERE CategoryId='.$parent_cat_id); @@ -138,7 +138,7 @@ else { $object->addFilter('primary_filter', 'PrimaryCat = 1'); } - + $view_perm = 1; $object->addFilter('perm_filter', 'perm.PermId = '.$view_perm); if (!defined('ADMIN')) { @@ -149,18 +149,18 @@ $view_filter = implode(' OR ', $view_filters); $object->addFilter('perm_filter2', $view_filter); } - + if (!defined('ADMIN')) { $object->addFilter('status_filter', $object->TableName.'.Status = 1'); } - + /*$list_type = $event->getEventParam('ListType'); switch($list_type) { case 'favorites': $fav_table = $this->Application->getUnitOption('fav','TableName'); $user_id =& $this->Application->GetVar('u_id'); - + $sql = 'SELECT DISTINCT f.ResourceId FROM '.$fav_table.' f LEFT JOIN '.$object->TableName.' p ON p.ResourceId = f.ResourceId Index: trunk/core/kernel/parser/construct_tags.php =================================================================== diff -u -N -r2566 -r2596 --- trunk/core/kernel/parser/construct_tags.php (.../construct_tags.php) (revision 2566) +++ trunk/core/kernel/parser/construct_tags.php (.../construct_tags.php) (revision 2596) @@ -1,35 +1,32 @@ StopTag = $tag; } - + function StoreSkipMode() { $this->SkipMode = $this->Parser->SkipMode; } - + function RestoreSkipMode() { $this->Parser->SetSkipMode($this->SkipMode); } - + function RestoreThisLevelSkipMode() { $this->SkipMode = $this->Parser->Recursion[$this->Parser->RecursionIndex]->SkipMode; } - + function SuggestSkipMode($mode) { if ($mode >= 1) //if we need to skip - always forcing it @@ -39,7 +36,7 @@ $this->Parser->SetSkipMode(parse); //set it to off only then } } - + function GetLogic() { $check = $this->GetParam('check'); @@ -60,14 +57,14 @@ $this->NP['function'] = $function; $inverse = $this->GetParam('inverse'); - + if ($prefix !== false) { $tag =& new Tag('', $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; @@ -80,30 +77,30 @@ } if($inverse) $this->Logic = !$this->Logic; } - + function Process() { switch ($this->Tag) { case 'if': case 'ifnot': $this->GetLogic(); - + $this->SetStopTag('endif'); //This recursion level should end when 'endif' is found $this->Parser->Recurve($this); //Saving current tag in parser recursion array $this->StoreSkipMode(); //Storing initial SkipMode - + if ($this->Logic) { $this->SuggestSkipMode(parse); //suggest we parse it } else { $this->SuggestSkipMode(skip); //suggest we don't parse it } break; - case 'elseif': + case 'elseif': $if_logic = $this->Parser->Recursion[$this->Parser->RecursionIndex]->Logic; if (!$if_logic) { //if IF or ELSEIF above have not worked $this->GetLogic(); - + if ($this->Logic) { //ELSEIF should run $this->Parser->Recursion[$this->Parser->RecursionIndex]->Logic = $this->Logic; //To escape running ELSE or ELSEIF below $this->SuggestSkipMode(parse); @@ -127,7 +124,7 @@ break; } } - + function CheckRecursion(&$tag) { if ($this->CheckEndRecursion($tag)) { @@ -150,7 +147,7 @@ } return false; } - + function CheckEndRecursion(&$tag) { if ($tag->GetParam('_closing_tag_') == 1 && $tag->Tag == $this->Tag) { @@ -163,7 +160,7 @@ class BlockTag extends ConstructTag { var $BlockName = ''; var $InsideBlock = 0; - + function Process() { switch ($this->Tag) { @@ -186,22 +183,22 @@ break; } } - + function CheckRecursion(&$tag) { if (parent::CheckRecursion($tag)) { //if endtag matches (SkipMode would be restored then) //Creating template from buffer - + //if (defined('EXPERIMENTAL_PRE_PARSE') && isset($this->Application->PreParsedBlocks[$this->BlockName])) return true; - + $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); - + if (defined('EXPERIMENTAL_PRE_PARSE')) { $code = $this->Parser->GetCode(); array_unshift($code, '$o = \'\';'); @@ -216,13 +213,13 @@ $defaults .= ');'; array_unshift($code, '$params = array_merge_recursive2($defaults, $params);'); array_unshift($code, $defaults); - - $code[] = 'return $o;'; - + + $code[] = 'return $o;'; + global $debugger; - + $dbg_functions = $this->Application->isDebugMode() && dbg_ConstOn('DBG_PRINT_PREPARSED'); - + $f_body = ''; //echo "
";
 				$l = 0;
@@ -236,18 +233,18 @@
 				}
 				if ($dbg_functions) echo "} // function ".$this->BlockName." end

"; //echo "
"; - + //caching func body $this->Application->PreParsedCache[$this->BlockName] = $f_body; - + $func = create_function('$params', $f_body); $this->Application->PreParsedBlocks[$this->BlockName] = $func; $this->Parser->Args = null; $this->Parser->ResetCode(); - + $this->Parser->AppendCompiledFunction($this->BlockName, $f_body); } - return true; + return true; } else { // append the tag itself to the block - while in block, we check every tag to be 'blockend' Index: trunk/core/units/general/cat_event_handler.php =================================================================== diff -u -N -r2041 -r2596 --- trunk/core/units/general/cat_event_handler.php (.../cat_event_handler.php) (revision 2041) +++ trunk/core/units/general/cat_event_handler.php (.../cat_event_handler.php) (revision 2596) @@ -4,48 +4,48 @@ $application->Factory->includeClassFile('kDBEventHandler'); class kCatDBEventHandler extends InpDBEventHandler { - + function OnCopy(&$event) { $object = $event->getObject(); $this->StoreSelectedIDs($event); $ids = $this->getSelectedIDs($event); $this->Application->StoreVar($event->getPrefixSpecial().'_clipboard', implode(',', $ids)); $this->Application->StoreVar($event->getPrefixSpecial().'_clipboard_mode', 'copy'); - + $this->Application->StoreVar('ClipBoard', 'COPY-0.'.$object->TableName.'.ResourceId=0'); $event->redirect_params = Array('opener' => 's', 'pass_events'=>true); //do not go up - STAY } - + function OnCut(&$event) { $object = $event->getObject(); $this->StoreSelectedIDs($event); $ids = $this->getSelectedIDs($event); $this->Application->StoreVar($event->getPrefixSpecial().'_clipboard', implode(',', $ids)); $this->Application->StoreVar($event->getPrefixSpecial().'_clipboard_mode', 'cut'); - + $this->Application->StoreVar('ClipBoard', 'CUT-0.'.$object->TableName.'.ResourceId=0'); $event->redirect_params = Array('opener' => 's', 'pass_events'=>true); //do not go up - STAY } - + function OnPaste(&$event) { $ids = $this->Application->RecallVar($event->getPrefixSpecial().'_clipboard'); if ($ids == '') { $event->redirect = false; return; } - + //recalling by different name, because we may get kDBList, if we recall just by prefix $object =& $this->Application->recallObject($event->getPrefixSpecial().'.item', $event->Prefix); $this->prepareObject($object, $event); - + if ($this->Application->RecallVar($event->getPrefixSpecial().'_clipboard_mode') == 'copy') { $ids_arr = explode(',', $ids); - + $temp =& $this->Application->recallObject($event->getPrefixSpecial().'_TempHandler', 'kTempTablesHandler'); - + if($ids_arr) { $temp->CloneItems($event->Prefix, $event->Special, $ids_arr); @@ -60,7 +60,7 @@ } $event->status = erSUCCESS; } - + /** * Occurs when pasting category * @@ -70,7 +70,7 @@ { $inp_clipboard = $this->Application->RecallVar('ClipBoard'); $inp_clipboard = explode('-', $inp_clipboard, 2); - + if($inp_clipboard[0] == 'COPY') { $saved_cat_id = $this->Application->GetVar('m_cat_id'); @@ -100,7 +100,7 @@ $this->Application->SetVar('m_cat_id', $saved_cat_id); } } - + /** * Apply scope clause * @@ -109,7 +109,7 @@ function SetCustomQuery(&$event) { $object =& $event->getObject(); - + if ($event->Special != 'showall') { if ( $event->getEventParam('parent_cat_id') ) { $parent_cat_id = $event->getEventParam('parent_cat_id'); @@ -123,7 +123,7 @@ $parent_cat_id = 0; } } - + if ((string) $parent_cat_id != 'any') { if ($event->getEventParam('recursive')) { $current_path = $this->Conn->GetOne('SELECT ParentPath FROM '.TABLE_PREFIX.'Category WHERE CategoryId='.$parent_cat_id); @@ -138,7 +138,7 @@ else { $object->addFilter('primary_filter', 'PrimaryCat = 1'); } - + $view_perm = 1; $object->addFilter('perm_filter', 'perm.PermId = '.$view_perm); if (!defined('ADMIN')) { @@ -149,18 +149,18 @@ $view_filter = implode(' OR ', $view_filters); $object->addFilter('perm_filter2', $view_filter); } - + if (!defined('ADMIN')) { $object->addFilter('status_filter', $object->TableName.'.Status = 1'); } - + /*$list_type = $event->getEventParam('ListType'); switch($list_type) { case 'favorites': $fav_table = $this->Application->getUnitOption('fav','TableName'); $user_id =& $this->Application->GetVar('u_id'); - + $sql = 'SELECT DISTINCT f.ResourceId FROM '.$fav_table.' f LEFT JOIN '.$object->TableName.' p ON p.ResourceId = f.ResourceId Index: trunk/core/kernel/parser/template_parser.php =================================================================== diff -u -N -r2566 -r2596 --- trunk/core/kernel/parser/template_parser.php (.../template_parser.php) (revision 2566) +++ trunk/core/kernel/parser/template_parser.php (.../template_parser.php) (revision 2596) @@ -1,13 +1,14 @@ Ses =& $this->Application->recallObject('Session'); } - + function AddParam($pattern, $value, $dont_sort=0) { $this->ForSort[] = Array($pattern, $value); if (!$dont_sort) //used when mass-adding params, to escape sorting after every new param $this->SortParams(); //but do sort by default! } - + //We need to sort params by its name length desc, so that params starting with same word get parsed correctly function SortParams() { @@ -51,15 +52,15 @@ $this->Values[] = $pair[1]; } } - + function CmpParams($a, $b) { $a_len = strlen($a[0]); $b_len = strlen($b[0]); if ($a_len == $b_len) return 0; return $a_len > $b_len ? -1 : 1; } - + function SetParams($params) { if (!is_array($params)) $params = Array(); @@ -69,39 +70,39 @@ } $this->SortParams(); //Sort once after adding is done } - + function GetParam($name) { //return isset($this->Params[strtolower($name)]) ? $this->Params[strtolower($name)] : false; return isset($this->Params[$name]) ? $this->Params[$name] : false; } - + function SetParam($name, $value) { $this->Params[strtolower($name)] = $value; } - + function SetBuffer($body) { $this->Buffers[$this->RecursionIndex] = $body; } - + function GetBuffer() { return $this->Buffers[$this->RecursionIndex]; } - + function GetCode() { - return $this->Code[$this->RecursionIndex]; + return $this->Code[$this->RecursionIndex]; } - + function AppendBuffer($append) { $this->Buffers[$this->RecursionIndex] .= $append; $this->AppendCode( $this->ConvertToCode($append) ); } - + function AppendOutput($append, $append_code=false) { if ($this->SkipMode == parse) { @@ -115,14 +116,14 @@ $this->AppendBuffer($append); //append to buffer if we are skipping tags } } - + function ConvertToCode($data) { $code = '$o .= \''. str_replace("'", "\'", $data) .'\';'; $code = explode("\n", $code); return $code; } - + function AppendCode($code) { if (defined('EXPERIMENTAL_PRE_PARSE')) { @@ -139,15 +140,15 @@ } } } - + function AppendCompiledFunction($f_name, $f_body) { $real_name = 'f_'.abs(crc32($this->TemplateName)).'_'.$f_name; if (defined('EXPERIMENTAL_PRE_PARSE')) { // if such function already compiled if ( isset($this->Application->CompiledFunctions[$f_name]) || function_exists($real_name) - ) + ) { if (!isset($this->Application->CompiledFunctions[$f_name])) { $real_name = $real_name.'_'; @@ -156,22 +157,22 @@ $real_name = $this->Application->CompiledFunctions[$f_name].'_'; } } - + $this->CompiledBuffer .= 'if (!function_exists(\''.$real_name.'\')) {'."\n"; - - + + $this->CompiledBuffer .= "\t".'$application->PreParsedBlocks[\''.$f_name.'\'] = \''.$real_name.'\';'; $this->CompiledBuffer .= "\n\t".'function '.$real_name.'($params)'."\n\t{\n"; $this->CompiledBuffer .= $f_body; $this->CompiledBuffer .= "\t}\n\n"; - + $this->CompiledBuffer .= '}'."\n"; - + $this->Application->CompiledFunctions[$f_name] = $real_name; - + } } - + function AppendCompiledCode($code) { if (defined('EXPERIMENTAL_PRE_PARSE')) { @@ -186,7 +187,7 @@ $this->CompiledBuffer .= "\t".'echo $o;'."\n\t".'$o = \'\';'."\n"; } } - + function AppendCompiledHTML($append) { if (defined('EXPERIMENTAL_PRE_PARSE')) { @@ -195,16 +196,16 @@ $this->CompiledBuffer .= '<'.'?php'."\n"; } } - + function ResetCode() { $this->Code[$this->RecursionIndex] = Array(); } - + function FindTag2() { $openings = Array('<%' => '%>', ' Array('>', '/>'), ' '>', '' => ''); - + $tag_open_pos = false; foreach ($openings as $an_opening => $closings) { $pos = strpos($this->Template, $an_opening, $this->Position); @@ -215,16 +216,16 @@ $tag_closings = $closings; } } - + if ($tag_open_pos === false) { //If no tags left - adding all other data $this->AppendOutput(substr($this->Template, $this->Position), true); return false; } - + //Adding all data before tag open $this->AppendOutput(substr($this->Template, $this->Position, $tag_open_pos - $this->Position), true); - - + + if (is_array($tag_closings)) { $tag_close_pos = false; foreach ($tag_closings as $a_closing) { @@ -244,11 +245,11 @@ $tag_close_pos = strpos($this->Template, $closing_tag, $tag_open_pos); } $close_len = strlen($closing_tag); - + //Cutting out the tag itself $tag = substr($this->Template, $tag_open_pos + $open_len, $tag_close_pos - $tag_open_pos - $open_len); - - + + if ($opening_tag == '') { //empty closing means old style in-portal if .... $tag = 'm:endif'; } - + if ($opening_tag == 'Params, 'PrefixSpecial'); - $tag = $prefix.$tag; + $tag = $prefix.$tag; } - + // temporary - for backward compatability with in-portal style if if ($opening_tag == '' && $tag_part != 'm_if' && $tag_part != 'm_DefineElement') { if (strpos($the_tag, ' ') !== false) { @@ -294,25 +295,25 @@ } $tag = 'm:if prefix="'.$prefix.'" function="'.$function.'" '.$params; } - - $this->Position = $tag_close_pos + $close_len; + + $this->Position = $tag_close_pos + $close_len; return $tag; } - + function CurrentLineNumber() { return substr_count(substr($this->Template, 0, $this->Position), "\n")+1; } - + function SkipModeName() { switch ($this->SkipMode) { case skip: return 'skip'; case skip_tags: return 'skip_tags'; - case parse: return 'parse'; + case parse: return 'parse'; } } - + function CheckDir($dir) { if (file_exists($dir)) { @@ -329,48 +330,64 @@ } } } - + function Parse($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 ($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 = str_replace(DOC_ROOT.BASE_PATH, DOC_ROOT.BASE_PATH.'/kernel/cache', $fname); - $this->CheckDir(dirname($fname)); - + + if (!defined('SAFE_MODE') || !SAFE_MODE) { + $this->CheckDir(dirname($fname)); + } + $tname = $template_cache->GetRealFilename($this->TemplateName).'.tpl'; - - if (file_exists($fname) && filemtime($fname) > filemtime($tname)) { - ob_start(); - include($fname); - $output = ob_get_contents(); - ob_end_clean(); - - if ( !$this->GetParam('from_inportal') ) { - if ( strpos($output, 'Application->recallObject('Inp1Parser'); - $output = $inp1_parser->Parse($name, $output); - } + + $output = ''; + $is_cached = false; + ob_start(); + 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)) { + eval('?'.'>'.$cached['Data'].'<'.'?'); + $is_cached = true; } + } + else { + if (file_exists($fname) && filemtime($fname) > filemtime($tname)) { + include($fname); + $is_cached = true; + } + } + $output = ob_get_contents(); + ob_end_clean(); + + if ( $is_cached && !$this->GetParam('from_inportal') ) { + if ( strpos($output, 'Application->recallObject('Inp1Parser'); + $output = $inp1_parser->Parse($name, $output); + } return $output; } - + $this->CompiledBuffer .= '<'.'?php'."\n"; $this->CompiledBuffer .= 'global $application;'."\n"; $this->CompiledBuffer .= '$o = \'\';'."\n"; } - + if (!getArrayValue($this->Params, 'PrefixSpecial')) { $this->Params['PrefixSpecial'] = '$PrefixSpecial'; } @@ -386,41 +403,47 @@ } // $tag =& new MyTag($tag_data, $this); $tag =& $this->TagHolder->GetTag($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); $has_inp_tags = true; } } - - + + if (defined('EXPERIMENTAL_PRE_PARSE') && $pre_parse && !$has_inp_tags) { // $this->CompiledBuffer .= 'echo $o;'."\n"; $this->CompiledBuffer .= '?'.'>'."\n"; - - $compiled = fopen($fname, 'w'); - fwrite($compiled, $this->CompiledBuffer); - fclose($compiled); + + 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($fname).','.$conn->qstr(str_replace('<'.'?php','<'.'?',$this->CompiledBuffer)).','.mktime().')'); + } + else { + $compiled = fopen($fname, 'w'); + fwrite($compiled, $this->CompiledBuffer); + fclose($compiled); + } } - + return $this->Output; } - + function ParseBlock($params, $force_pass_params=0, $as_template=false) { if( $this->Application->isDebugMode() && dbg_ConstOn('DBG_SHOW_TAGS') ) { global $debugger; $debugger->appendHTML('ParseBlock '.$params['name'].' pass_params is '.$params['pass_params'].' force is '.$force_pass_params.' in '.$debugger->getFileLink($debugger->getLocalFile(DOC_ROOT.BASE_PATH.THEMES_PATH.'/'.$this->TemplateName).'.tpl', $this->CurrentLineNumber(), '', true)); - + } /*if ( $this->Application->isDebugMode() && dbg_ConstOn('DBG_PRE_PARSE') ) { global $debugger; @@ -429,35 +452,35 @@ if (defined('EXPERIMENTAL_PRE_PARSE')) { $this->MainParser = false; if (isset($this->Application->PreParsedBlocks[$params['name']]) ) { - + if ($this->ParamsRecursionIndex == 0) { $this->ParamsStack[$this->ParamsRecursionIndex] = $this->Params; } - + if (isset($params['pass_params']) || $force_pass_params) { $pass_params = array_merge($this->ParamsStack[$this->ParamsRecursionIndex], $params); } else { $pass_params = $params; } - + $this->ParamsStack[++$this->ParamsRecursionIndex] = $pass_params; $this->Params = $pass_params; - + $f = $this->Application->PreParsedBlocks[$params['name']]; - + // $this->ParamsRecursionIndex--; - + //$this->SetParams($params); $ret = $f($pass_params); - + unset($this->ParamsStack[$this->ParamsRecursionIndex--]); $this->Params = $this->ParamsStack[$this->ParamsRecursionIndex]; $this->MainParser = true; return $ret; } } - + $BlockParser =& $this->Application->makeClass('TemplateParser'); if (isset($params['pass_params']) || $force_pass_params) { $BlockParser->SetParams(array_merge($this->Params, $params)); @@ -467,32 +490,32 @@ $this->Application->Parser =& $BlockParser; if (!isset($params['name'])) trigger_error('***Error: Block name not passed to ParseBlock', E_USER_ERROR); $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), + $templates_cache->GetTemplateBody($params['name'], $silent), $template_name ); if (getArrayValue($params, 'BlockNoData') && !$BlockParser->DataExists) { $template_name = $as_template ? $params['BlockNoData'] : $templates_cache->GetTemplateFileName($params['BlockNoData']) . '-block:'.$params['BlockNoData']; $o = $BlockParser->Parse( - $templates_cache->GetTemplateBody($params['BlockNoData'], $silent), + $templates_cache->GetTemplateBody($params['BlockNoData'], $silent), $template_name - ); + ); } $this->Application->Parser =& $this; $this->Application->Parser->DataExists = $this->Application->Parser->DataExists || $BlockParser->DataExists; return $o; } - + function Recurve(&$tag) { $this->Recursion[++$this->RecursionIndex] =& $tag; } - + function CheckRecursion(&$tag) { if ($this->RecursionIndex > 0) { //If we are inside the recursion @@ -503,7 +526,7 @@ } return false; } - + function SetSkipMode($mode) { $this->SkipMode = $mode; Index: trunk/core/kernel/utility/debugger.php =================================================================== diff -u -N -r2581 -r2596 --- trunk/core/kernel/utility/debugger.php (.../debugger.php) (revision 2581) +++ trunk/core/kernel/utility/debugger.php (.../debugger.php) (revision 2596) @@ -6,41 +6,41 @@ { return defined($const_name) && constant($const_name); } - + function dbg_safeDefine($const_name,$const_value) { if(!defined($const_name)) define($const_name,$const_value); } - + unset($_REQUEST['debug_host']); // this var messed up whole detection stuff :( - + // Detect fact, that this session beeing debugged by Zend Studio foreach($_REQUEST as $rq_name=>$rq_value) { if( substr($rq_name,0,6)=='debug_' ) { dbg_safeDefine('DBG_ZEND_PRESENT', 1); break; - } + } } - + dbg_safeDefine('DBG_ZEND_PRESENT',0); - + // set default values for debugger constants $dbg_constMap=Array('DBG_OPTIONS'=>0, 'DBG_USE_HIGHLIGHT'=>1, 'DBG_USE_SHUTDOWN_FUNC'=>DBG_ZEND_PRESENT?0:1, 'DBG_HANDLE_ERRORS'=>DBG_ZEND_PRESENT?0:1, 'DBG_IGNORE_STRICT_ERRORS'=>1, 'DBG_DOMVIEWER'=>'/temp/domviewer.html', - 'DOC_ROOT'=> str_replace('\\', '/', realpath($_SERVER['DOCUMENT_ROOT']) ), // windows hack + 'DOC_ROOT'=> str_replace('\\', '/', realpath($_SERVER['DOCUMENT_ROOT']) ), // windows hack 'DBG_LOCAL_BASE_PATH'=>'w:'); - + foreach($dbg_constMap as $dbg_constName=>$dbg_constValue) { dbg_safeDefine($dbg_constName,$dbg_constValue); } - + // only for IE, in case if no windows php script editor defined /*if(!defined('WINDOWS_EDITOR')) { @@ -50,8 +50,8 @@ define('WINDOWS_EDITOR',$dbg_editors[$dbg_editor]['editor'].' '.$dbg_editors[$dbg_editor]['params']); unset($dbg_editors,$dbg_editor); }*/ - - class Debugger + + class Debugger { /** * Debugger data for building report @@ -62,27 +62,27 @@ var $ProfilerData = Array(); var $ProfilerTotals = Array(); var $RecursionStack = Array(); // prevent recursion when processing debug_backtrace() function results - + var $TraceNextError=false; - + var $Options = 0; var $OptionsMap = Array('shutdown_func' => 1, 'error_handler' => 2, 'output_buffer' => 4, 'highlight_output' => 8); - - + + var $longErrors=Array(); - + /** * Amount of memory used by debugger itself * * @var Array * @access private */ var $memoryUsage=Array(); - + var $IncludesData=Array(); var $IncludeLevel=0; - + function Debugger() { $this->profileStart('kernel4_startup', 'Startup and Initialization of kernel4'); @@ -91,19 +91,19 @@ $this->memoryUsage['error_handling']=0; // memory amount used by error handler $this->appendRequest(); } - + function initOptions() { - + } - + function mapLongError($msg) { $key=$this->generateID(); $this->longErrors[$key]=$msg; return $key; } - + function setOption($name,$value) { if( !isset($this->OptionsMap[$name]) ) die('undefined debugger option: ['.$name.']
'); @@ -116,13 +116,13 @@ $this->Options=$this->Options&~$this->OptionsMap[$name]; } } - + function getOption($name) { if( !isset($this->OptionsMap[$name]) ) die('undefined debugger option: ['.$name.']
'); return ($this->Options & $this->OptionsMap[$name]) == $this->OptionsMap[$name]; } - + /** * Set's flag, that next error that occurs will * be prepended by backtrace results @@ -132,7 +132,7 @@ { $this->TraceNextError=true; } - + function dumpVars() { $dumpVars = func_get_args(); @@ -141,12 +141,12 @@ $this->Data[] = Array('value' => $varValue, 'debug_type' => 'var_dump'); } } - + function prepareHTML($dataIndex) { $Data =& $this->Data[$dataIndex]; if($Data['debug_type'] == 'html') return $Data['html']; - + switch($Data['debug_type']) { case 'error': @@ -155,19 +155,19 @@ $ret .= ' in '.$fileLink.' on line '.$Data['line'].''; return $ret; break; - + case 'var_dump': return $this->highlightString( print_r($Data['value'], true) ); break; - + case 'trace': ini_set('memory_limit','500M'); $trace =& $Data['trace']; - + //return 'sorry'; //return $this->highlightString(print_r($trace,true)); - - + + $i = 0; $traceCount = count($trace); $ret = ''; while($i < $traceCount) @@ -180,11 +180,11 @@ $ret .= 'Function: '.$this->getFileLink($traceRec['file'],$traceRec['line'],$func_name); $ret .= ' in '.basename($traceRec['file']).' on line '.$traceRec['line'].'
'; } - else + else { $ret .= 'no file information available'; } - + // ensure parameter value is not longer then 200 symbols $this->processTraceArguments($traceRec['args']); $args = $this->highlightString(print_r($traceRec['args'], true)); @@ -193,20 +193,20 @@ } return $ret; break; - + case 'profiler': $profileKey = $Data['profile_key']; $Data =& $this->ProfilerData[$profileKey]; $runtime = ($Data['ends'] - $Data['begins']); // in seconds return 'Name: '.$Data['description'].'
Runtime: '.$runtime.'s'; break; - + default: return 'incorrect debug data'; break; } } - + function processTraceArguments(&$traceArgs) { if(!$traceArgs) return ''; @@ -215,7 +215,7 @@ if( is_array($argValue) || is_object($argValue) ) { if(is_object($argValue) && !in_array(get_class($argValue),$this->RecursionStack) ) - { + { // object & not in stack - ok array_push($this->RecursionStack, get_class($argValue)); settype($argValue,'array'); @@ -239,13 +239,13 @@ } } } - + function cutStringForHTML($string) { if( strlen($string) > 200 ) $string = substr($string,0,50).' ...'; return $string; } - + /** * Format SQL Query using predefined formatting * and highlighting techniques @@ -259,7 +259,7 @@ $sql = preg_replace('/(CREATE TABLE|DROP TABLE|SELECT|UPDATE|SET|REPLACE|INSERT|DELETE|VALUES|FROM|LEFT JOIN|INNER JOIN|LIMIT|WHERE|HAVING|GROUP BY|ORDER BY) /is', "\n\t$1 ",$sql); return $this->highlightString($sql); } - + function highlightString($string) { if( dbg_ConstOn('DBG_USE_HIGHLIGHT') ) @@ -274,7 +274,7 @@ return $string; } } - + function getFileLink($file, $lineno = 1, $title = '') { if(!$title) $title = $file; @@ -283,36 +283,36 @@ { return ''.$title.''; } - else + else { - return ''.$title.''; + return ''.$title.''; } - + } - + function getLocalFile($remoteFile) { - return str_replace(DOC_ROOT, DBG_LOCAL_BASE_PATH, $remoteFile); + return str_replace(DOC_ROOT, DBG_LOCAL_BASE_PATH, $remoteFile); } - + function appendTrace() { $trace = debug_backtrace(); array_shift($trace); $this->Data[] = Array('trace' => $trace, 'debug_type' => 'trace'); } - + function appendMemoryUsage($msg, $used=null) { if (!isset($used)) $used = round(memory_get_usage()/1024); $this->appendHTML('Memory usage '.$msg.' '.$used.'Kb'); } - + function appendHTML($html) { - $this->Data[] = Array('html' => $html,'debug_type' => 'html'); + $this->Data[] = Array('html' => $html,'debug_type' => 'html'); } - + /** * Change debugger info that was already generated before. * Returns true if html was set. @@ -326,9 +326,9 @@ { if( !isset($this->Data[$index]) || $this->Data[$index]['debug_type'] != 'html' ) { - return false; + return false; } - + switch ($type) { case 'append': @@ -343,7 +343,7 @@ } return true; } - + /** * Move $debugLineCount lines of input from debug output * end to beginning. @@ -355,19 +355,19 @@ $lines = array_splice($this->Data,count($this->Data)-$debugLineCount,$debugLineCount); $this->Data = array_merge($lines,$this->Data); } - + function moveAfterRow($new_row, $debugLineCount) { $lines = array_splice($this->Data,count($this->Data)-$debugLineCount,$debugLineCount); $rows_before = array_splice($this->Data,0,$new_row,$lines); $this->Data = array_merge($rows_before,$this->Data); } - + function appendRequest() { $script = $_SERVER['SCRIPT_FILENAME']; $this->appendHTML('ScriptName: '.$this->getFileLink($script,1,basename($script)).' ('.dirname($script).')'); - + $this->appendHTML('DomViewer:  '); ob_start(); @@ -390,35 +390,35 @@ $src = isset($_GET[$key]) ? 'GE' : (isset($_POST[$key]) ? 'PO' : (isset($_COOKIE[$key]) ? 'CO' : '?') ); echo ''.$src.''.$key.''.$value.''; } - ?> + ?> appendHTML( ob_get_contents() ); ob_end_clean(); } - + function appendSession() { if( isset($_SESSION)&&$_SESSION ) { $this->appendHTML('PHP Session: ['.ini_get('session.name').']'); $this->dumpVars($_SESSION); $this->moveToBegin(2); - } + } } - + function profileStart($key, $description) { $timeStamp = $this->getMoment(); $this->ProfilerData[$key] = Array('begins' => $timeStamp, 'ends' => 5000, 'debuggerRowID' => count($this->Data), 'description' => $description); $this->Data[] = array('profile_key' => $key, 'debug_type' => 'profiler'); } - + function profileFinish($key) { $this->ProfilerData[$key]['ends'] = $this->getMoment(); } - + function profilerAddTotal($total_key, $key=null, $value=null) { if (!isset($this->ProfilerTotals[$total_key])) { @@ -429,17 +429,17 @@ } $this->ProfilerTotals[$total_key] += $value; } - + function getMoment() { - list($usec, $sec) = explode(' ', microtime()); - return ((float)$usec + (float)$sec); + list($usec, $sec) = explode(' ', microtime()); + return ((float)$usec + (float)$sec); } - + function generateID() { list($usec, $sec) = explode(" ",microtime()); - + $id_part_1 = substr($usec, 4, 4); $id_part_2 = mt_rand(1,9); $id_part_3 = substr($sec, 6, 4); @@ -451,55 +451,55 @@ } return $id_part_1.$id_part_2.$id_part_3; } - - + + function getErrorNameByCode($errorCode) { switch($errorCode) { case E_USER_ERROR: return 'Fatal Error'; break; - + case E_WARNING: case E_USER_WARNING: return 'Warning'; break; - + case E_NOTICE: case E_USER_NOTICE: return 'Notice'; break; - + case E_STRICT: return 'PHP5 Strict'; break; - + default: return ''; break; } } - + /** * Generates report * */ function printReport($returnResult = false) { if( dbg_ConstOn('DBG_SKIP_REPORTING') ) return; - + $this->profileFinish('script_runtime'); if( dbg_ConstOn('DBG_ZEND_PRESENT') ) return; - + dbg_safeDefine('DBG_RAISE_ON_WARNINGS',0); dbg_safeDefine('DBG_WINDOW_WIDTH', 700); - + $this->memoryUsage['debugger_start']=memory_get_usage(); - + // show php session if any $this->appendSession(); - + // ensure, that 1st line of debug output always is this one: $this->appendHTML('Hide Debugger'); $this->moveToBegin(1); @@ -547,49 +547,49 @@ $this->appendHTML('Sub-Total configs: '.' Mem: '.sprintf("%.4f Kb", $totals_configs['mem']/1024).' Time: '.sprintf("%.4f", $totals_configs['time'])); $this->appendHTML('Grand Total: '.' Mem: '.sprintf("%.4f Kb", ($totals['mem']+$totals_configs['mem'])/1024).' Time: '.sprintf("%.4f", $totals['time']+$totals_configs['time'])); } - - + + $i = 0; $lineCount = count($this->Data); ob_start(); ?>