Index: branches/5.0.x/core/kernel/startup.php
===================================================================
diff -u -N -r12299 -r12323
--- branches/5.0.x/core/kernel/startup.php (.../startup.php) (revision 12299)
+++ branches/5.0.x/core/kernel/startup.php (.../startup.php) (revision 12323)
@@ -1,6 +1,6 @@
profileStart('inc_globals', KERNEL_PATH . '/globals.php', $globals_start);
$debugger->profileFinish('inc_globals', KERNEL_PATH . '/globals.php', $globals_end);
@@ -153,14 +151,10 @@
$debugger->AttachToApplication();
}
- if( !function_exists('adodb_mktime') ) include_once(KERNEL_PATH . '/utility/adodb-time.inc.php');
+ if( !function_exists('adodb_mktime') ) {
+ include_once(KERNEL_PATH . '/utility/adodb-time.inc.php');
+ }
-// include_once(KERNEL_PATH . '/utility/temp_handler.php'); // needed because of static calls from kBase
- // up to here
-
// global constants
define ('KG_TO_POUND', 2.20462262);
- define ('POUND_TO_KG', 0.45359237);
-
-
-?>
\ No newline at end of file
+ define ('POUND_TO_KG', 0.45359237);
\ No newline at end of file
Index: branches/5.0.x/core/kernel/db/db_tag_processor.php
===================================================================
diff -u -N -r12299 -r12323
--- branches/5.0.x/core/kernel/db/db_tag_processor.php (.../db_tag_processor.php) (revision 12299)
+++ branches/5.0.x/core/kernel/db/db_tag_processor.php (.../db_tag_processor.php) (revision 12323)
@@ -1,6 +1,6 @@
Application->Parser->GetParam('columns');
+
return round(100/$columns).'%';
}
@@ -819,12 +820,13 @@
*/
function HasParam($params, $param_name = null)
{
- if( !isset($param_name) )
- {
+ if ( !isset($param_name) ) {
$param_name = $this->SelectParam($params, 'name');
$params = $this->Application->Parser->Params;
}
+
$value = isset($params[$param_name]) ? $params[$param_name] : false;
+
return $value && ($value != '$'.$param_name);
}
Index: branches/5.0.x/core/kernel/session/session.php
===================================================================
diff -u -N -r12299 -r12323
--- branches/5.0.x/core/kernel/session/session.php (.../session.php) (revision 12299)
+++ branches/5.0.x/core/kernel/session/session.php (.../session.php) (revision 12323)
@@ -1,6 +1,6 @@
Application->isDebugMode() && constOn('DBG_SHOW_SESSIONDATA')) {
+ if (defined('DEBUG_MODE') && $this->Application->isDebugMode() && constOn('DBG_SHOW_SESSIONDATA')) {
// dump session data
$this->Application->Debugger->appendHTML('SessionStorage [' . ($this->RecallVar('admin') == 1 ? 'Admin' : 'Front-End') . '] ('.$comment.'):');
$session_data = $this->Data->GetParams();
@@ -954,7 +954,7 @@
}
$this->Application->Debugger->dumpVars($session_data);
}
- if ($this->Application->isDebugMode() && constOn('DBG_SHOW_PERSISTENTDATA')) {
+ if (defined('DEBUG_MODE') && $this->Application->isDebugMode() && constOn('DBG_SHOW_PERSISTENTDATA')) {
// dump persistent session data
if ($this->Storage->PersistentVars) {
$this->Application->Debugger->appendHTML('Persistant Session:');
Index: branches/5.0.x/core/kernel/utility/http_query.php
===================================================================
diff -u -N -r12299 -r12323
--- branches/5.0.x/core/kernel/utility/http_query.php (.../http_query.php) (revision 12299)
+++ branches/5.0.x/core/kernel/utility/http_query.php (.../http_query.php) (revision 12323)
@@ -1,6 +1,6 @@
convertPostEvents();
// if ($this->Application->RewriteURLs()) {
if ($this->Application->RewriteURLs() || $this->Get('_mod_rw_url_')) {
- if( $this->Application->isDebugMode() )
- {
+ if (defined('DEBUG_MODE') && $this->Application->isDebugMode()) {
$this->Application->Debugger->profileStart('url_parsing');
$this->processRewriteURL();
$description = 'Parsing MOD_REWRITE url (template: '.$this->Get('t').')';
$this->Application->Debugger->profileFinish('url_parsing', $description);
}
- else
- {
+ else {
$this->processRewriteURL();
}
}
@@ -377,26 +375,19 @@
function extractSIDAndTemplate(&$parts)
{
$vars = Array ();
- if (defined('INPORTAL_ENV') && INPORTAL_ENV) { // SID-TEMPLATE
- $sub_parts = array_shift($parts);
- list($sid, $t) = explode('-', $sub_parts, 2);
+ $sub_parts = array_shift($parts);
+ list ($sid, $t) = explode('-', $sub_parts, 2);
+
+ if ($sid) {
// Save Session ID
- if ($sid) {
- $this->Set('sid', $sid);
- $vars['sid'] = $sid;
- }
+ $this->Set('sid', $sid);
+ $vars['sid'] = $sid;
}
- else { // SID:TEMPLATE
- // Save Session ID
- $sid = array_shift($parts);
- if ($sid) $vars['sid'] = $sid;
- $t = array_shift($parts);
- }
-
// Save Template Name
$vars['t'] = $this->getDefaultTemplate($t);
+
return $vars;
}
Index: branches/5.0.x/core/kernel/db/dbitem.php
===================================================================
diff -u -N -r12299 -r12323
--- branches/5.0.x/core/kernel/db/dbitem.php (.../dbitem.php) (revision 12299)
+++ branches/5.0.x/core/kernel/db/dbitem.php (.../dbitem.php) (revision 12323)
@@ -1,6 +1,6 @@
Application->isDebugMode() )
- {
+ if ($this->Application->isDebugMode()) {
$this->Application->Debugger->appendTrace();
}
+
trigger_error('Query method is called in class '.get_class($this).' for prefix '.$this->getPrefixSpecial().'', E_USER_ERROR);
}
Index: branches/5.0.x/core/units/admin/admin_events_handler.php
===================================================================
diff -u -N -r12299 -r12323
--- branches/5.0.x/core/units/admin/admin_events_handler.php (.../admin_events_handler.php) (revision 12299)
+++ branches/5.0.x/core/units/admin/admin_events_handler.php (.../admin_events_handler.php) (revision 12323)
@@ -1,6 +1,6 @@
Application->recallObject('NParserCompiler');
/* @var $compiler NParserCompiler */
+
$compiler->CompileTemplatesStep();
$event->status = erSTOP;
}
Index: branches/5.0.x/core/kernel/nparser/template.php
===================================================================
diff -u -N
--- branches/5.0.x/core/kernel/nparser/template.php (revision 12310)
+++ branches/5.0.x/core/kernel/nparser/template.php (revision 0)
@@ -1,304 +0,0 @@
-SetBasePath($base_path)) {
- if (isset($filename)) {
- $this->Filename = $filename;
- $this->LoadTemplate($silent);
- }
- }
- }
-
- function SetBasePath($base_path=null)
- {
- if (isset($base_path)) {
- $base_path = eregi_replace("/$", '', $base_path); //Cutting possible last slash
- $this->BasePath = $base_path;
- return true;
- }
- return false;
- }
-
- function GetFullPath()
- {
- return $this->BasePath.'/'.ltrim($this->Filename, '/').'.tpl';
- }
-
- /**
- * Enter description here...
- *
- * @param int $silent template not found {0 - fatal error, 1 - warning, 2 - nothing}
- * @return bool
- */
- function LoadTemplate($silent = 0)
- {
- $filename = $this->GetFullPath();
- if (file_exists($filename)) {
- if (filesize ($filename) == 0) {
- trigger_error("Template file size is 0: $filename", ($silent ? E_USER_NOTICE : E_USER_ERROR) );
- }
-
- // stripping out special comments
- $this->SetBody(preg_replace('//sU', '', file_get_contents($filename)));
- /*$handle = fopen ($filename, "r");
- $contents = fread ($handle, filesize ($filename));
- $this->SetBody($contents);
- fclose ($handle);*/
- return true;
- }
- else {
- if (($silent != 2) && !$silent) {
- $application =& kApplication::Instance();
- if ($application->isDebugMode()) {
- $application->Debugger->appendTrace();
- }
- trigger_error('File or block not found: '.$filename.' at '.$application->Parser->TemplateName, E_USER_ERROR);
- }
- return false;
- }
- }
-
- function SetBody($body)
- {
- $this->Body = $body;
- }
-
- function GetBody()
- {
- return $this->Body;
- }
-}
-
-class TemplatesCache extends kBase {
- var $Templates = Array();
- var $BasePath;
- var $FileNames = Array();
-
- /**
- * Force templates cache to search templates on front-end:
- * true - search for theme name in template name
- * false - don't search anywhere
- * name - theme name to prepend for each template name
- *
- * @var mixed
- */
- var $forceThemeName = false;
-
- function TemplatesCache()
- {
- parent::kBase();
- $this->BasePath = FULL_PATH.THEMES_PATH;
-
- $conn =& $this->Application->GetADODBConnection();
- }
-
- /**
- * Based on template name gets it's location on disk and owner module
- *
- * @param string $filename
- * @return Array 0 - path on disk, 1 - template name
- */
- function GetTemplatePaths($filename)
- {
- if ($this->Application->IsAdmin() && isset($this->Application->ReplacementTemplates[$filename])) {
- $filename = $this->Application->ReplacementTemplates[$filename];
- }
-
- // allows to use non-replaced version of replaced template
- $filename = preg_replace('/^original:(.*)/', '\\1', $filename);
-
- if (preg_match('#^[\/]{0,1}([^\/]*)\/(.*)#', $filename, $regs)) {
- $module_filename = $regs[2];
- $first_dir = $regs[1];
- }
- else {
- $first_dir = '';
- $module_filename = $filename;
- }
-
- if (is_string($this->forceThemeName)) {
- // when defined, then all templates are read from given theme name
- $first_dir = 'theme:' . $this->forceThemeName . ($first_dir ? '/' . $first_dir : '');
- }
-
- // !preg_match for backward compatability with full-path plugins
- if ($this->Application->IsAdmin() && $first_dir == 'plugins' && !preg_match('/admin_templates/', $module_filename)) {
- if (preg_match('#^[\/]{0,1}([^\/]*)\/(.*)#', $module_filename, $regs)) {;
- $path = MODULES_PATH.'/'.mb_strtolower($first_dir).'/'.$regs[1].'/admin_templates';
- $module_filename = $regs[2];
- }
- else {
- $first_dir = '';
- $module_filename = $filename;
- }
- }
- elseif ( $this->Application->IsAdmin() && $this->Application->findModule('Name', $first_dir)) {
- if ($first_dir == 'in-portal') {
- $first_dir = 'kernel';
- }
- $path = MODULES_PATH.'/'.mb_strtolower($first_dir).'/admin_templates';
- }
- elseif ($this->forceThemeName && preg_match('/^theme:(.*)/', $first_dir, $regs)) {
- // ability to use Front-End templates in admin (only during mass compilation)
- $path = FULL_PATH . '/themes/' . $regs[1];
- }
- else {
- $path = $this->BasePath;
- $module_filename = $first_dir.'/'.$module_filename;
- }
-
- return Array ($path, $module_filename);
- }
-
- function LoadTemplate($filename, $title=NULL, $silent=0)
- {
- list ($path, $module_filename) = $this->GetTemplatePaths($filename);
-
- $template = new Template($path, $module_filename, $silent);
- if (!isset($title)) $title = $filename;
- $this->SetTemplate($title, $template);
- }
-
- function GetRealFilename($filename)
- {
- list ($path, $module_filename) = $this->GetTemplatePaths($filename);
- return $path.'/'.trim($module_filename, '/');
- }
-
- function SetTemplate($title, &$template, $filename=null)
- {
- if (!isset($filename)) $filename=$title;
- $this->Templates[$title] = $template;
- $this->FileNames[$title] = $filename;
- }
-
- function &GetTemplate($title, $silent=0)
- {
- if (!isset($this->Templates[$title])) {
- $this->LoadTemplate($title, null, $silent);
- }
- return $this->Templates[$title];
- }
-
- function GetTemplateBody($title, $silent=0)
- {
- $template =& $this->GetTemplate($title, $silent);
- if ( !is_object($template) ) {
- return '';
- }
- return $template->GetBody();
- }
-
- function GetTemplateFileName($title)
- {
- return getArrayValue($this->FileNames, $title);
- }
-
- function SetTemplateBody($title, $body)
- {
- $template = new Template();
- $template->SetBody($body);
- $this->SetTemplate($title, $template);
- }
-
- function ParseTemplate($template_name)
- {
- $Parser = new TemplateParser($this->Application);
- return $Parser->Parse( $this->GetTemplateBody($template_name) );
- }
-
- function TemplateExists($filename)
- {
- if ((strpos($filename, '../') !== false) || (trim($filename) !== $filename)) {
- // when relative paths or special chars are found template names from url, then it's hacking attempt
- return false;
- }
-
- $real_file = $this->GetRealFilename( strtolower($filename) );
- if (substr($real_file, -4) != '.tpl') {
- // add ".tpl" file extension, when not specified in template name
- $real_file .= '.tpl';
- }
-
- return file_exists($real_file);
- }
-
-
- function GetPreParsed($template)
- {
- $real_name = $this->GetRealFilename($template);
- $fname = $real_name.'.php';
- $fname = str_replace(FULL_PATH, WRITEABLE . '/cache', $fname);
-
- $tname = $real_name.'.tpl';
- if (!file_exists($tname)) {
- return false;
- }
-
- 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)) {
- // make sure to create directory if pre-parsed file does not exist
- $this->CheckDir( dirname($fname), WRITEABLE . '/cache' );
- }
- }
- return array('active' => 0, 'fname' => $fname, 'tname' => $tname, 'mode'=>'file');
- }
-
- /**
- * Recursive mkdir
- *
- * @param string $dir
- * @param string $base_path base path to directory where folders should be created in
- */
- function CheckDir($dir, $base_path = '')
- {
- if (file_exists($dir)) {
- return;
- }
- else {
- // remove $base_path from beggining because it is already created during install
- $dir = preg_replace('/^'.preg_quote($base_path.'/', '/').'/', '', $dir, 1);
- $segments = explode('/', $dir);
- $cur_path = $base_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);
- }
- }
- }
- }
-
-}
\ No newline at end of file
Index: branches/5.0.x/core/kernel/utility/factory.php
===================================================================
diff -u -N -r12299 -r12323
--- branches/5.0.x/core/kernel/utility/factory.php (.../factory.php) (revision 12299)
+++ branches/5.0.x/core/kernel/utility/factory.php (.../factory.php) (revision 12323)
@@ -1,6 +1,6 @@
Application->isDebugMode() && constOn('DBG_FACTORY')) {
+ if (defined('DEBUG_MODE') && defined('DBG_FACTORY') && DBG_FACTORY && $this->Application->isDebugMode()) {
global $debugger;
+
$debugger->appendHTML('Creating object: Pseudo class: '.$pseudo_class.' Prefix: '.$name);
$debugger->appendTrace();
}
@@ -160,7 +161,7 @@
return $false;
}
- if ($this->Application->isDebugMode() && constOn('DBG_FACTORY')) {
+ if (defined('DEBUG_MODE') && defined('DBG_FACTORY') && DBG_FACTORY && $this->Application->isDebugMode()) {
global $debugger;
$debugger->appendHTML('Creating object: Pseudo class: '.$pseudo_class.' Prefix: '.$name);
$debugger->appendTrace();
Index: branches/5.0.x/core/kernel/nparser/template.php
===================================================================
diff -u -N -r12310 -r12323
--- branches/5.0.x/core/kernel/nparser/template.php (.../template.php) (revision 12310)
+++ branches/5.0.x/core/kernel/nparser/template.php (.../template_cache.php) (revision 12323)
@@ -1,6 +1,6 @@
SetBasePath($base_path)) {
- if (isset($filename)) {
- $this->Filename = $filename;
- $this->LoadTemplate($silent);
- }
- }
- }
-
- function SetBasePath($base_path=null)
- {
- if (isset($base_path)) {
- $base_path = eregi_replace("/$", '', $base_path); //Cutting possible last slash
- $this->BasePath = $base_path;
- return true;
- }
- return false;
- }
-
- function GetFullPath()
- {
- return $this->BasePath.'/'.ltrim($this->Filename, '/').'.tpl';
- }
-
/**
- * Enter description here...
+ * Base path for searching templates
*
- * @param int $silent template not found {0 - fatal error, 1 - warning, 2 - nothing}
- * @return bool
+ * @var string
*/
- function LoadTemplate($silent = 0)
- {
- $filename = $this->GetFullPath();
- if (file_exists($filename)) {
- if (filesize ($filename) == 0) {
- trigger_error("Template file size is 0: $filename", ($silent ? E_USER_NOTICE : E_USER_ERROR) );
- }
-
- // stripping out special comments
- $this->SetBody(preg_replace('//sU', '', file_get_contents($filename)));
- /*$handle = fopen ($filename, "r");
- $contents = fread ($handle, filesize ($filename));
- $this->SetBody($contents);
- fclose ($handle);*/
- return true;
- }
- else {
- if (($silent != 2) && !$silent) {
- $application =& kApplication::Instance();
- if ($application->isDebugMode()) {
- $application->Debugger->appendTrace();
- }
- trigger_error('File or block not found: '.$filename.' at '.$application->Parser->TemplateName, E_USER_ERROR);
- }
- return false;
- }
- }
-
- function SetBody($body)
- {
- $this->Body = $body;
- }
-
- function GetBody()
- {
- return $this->Body;
- }
-}
-
-class TemplatesCache extends kBase {
- var $Templates = Array();
var $BasePath;
- var $FileNames = Array();
/**
* Force templates cache to search templates on front-end:
@@ -104,12 +33,36 @@
*/
var $forceThemeName = false;
+ /**
+ * Compile templates to database
+ *
+ * @var bool
+ */
+ var $_compileToDatabase = false;
+
+ /**
+ * Compress compiled templates
+ *
+ * @var bool
+ */
+ var $_compressOutput = false;
+
+ /**
+ * Tells, that we are in administrative console (for performance)
+ *
+ * @var bool
+ */
+ var $_isAdmin = false;
+
function TemplatesCache()
{
parent::kBase();
- $this->BasePath = FULL_PATH.THEMES_PATH;
- $conn =& $this->Application->GetADODBConnection();
+ $this->BasePath = FULL_PATH . THEMES_PATH;
+
+ $this->_compileToDatabase = defined('SAFE_MODE') && SAFE_MODE;
+ $this->_compressOutput = $this->Application->ConfigValue('UseTemplateCompression');
+ $this->_isAdmin = $this->Application->IsAdmin();
}
/**
@@ -120,7 +73,7 @@
*/
function GetTemplatePaths($filename)
{
- if ($this->Application->IsAdmin() && isset($this->Application->ReplacementTemplates[$filename])) {
+ if ($this->_isAdmin && array_key_exists($filename, $this->Application->ReplacementTemplates)) {
$filename = $this->Application->ReplacementTemplates[$filename];
}
@@ -142,7 +95,7 @@
}
// !preg_match for backward compatability with full-path plugins
- if ($this->Application->IsAdmin() && $first_dir == 'plugins' && !preg_match('/admin_templates/', $module_filename)) {
+ if ($this->_isAdmin && ($first_dir == 'plugins') && !preg_match('/admin_templates/', $module_filename)) {
if (preg_match('#^[\/]{0,1}([^\/]*)\/(.*)#', $module_filename, $regs)) {;
$path = MODULES_PATH.'/'.mb_strtolower($first_dir).'/'.$regs[1].'/admin_templates';
$module_filename = $regs[2];
@@ -152,10 +105,10 @@
$module_filename = $filename;
}
}
- elseif ( $this->Application->IsAdmin() && $this->Application->findModule('Name', $first_dir)) {
- if ($first_dir == 'in-portal') {
+ elseif ($this->_isAdmin && $this->Application->findModule('Name', $first_dir)) {
+ /*if ($first_dir == 'in-portal') {
$first_dir = 'kernel';
- }
+ }*/
$path = MODULES_PATH.'/'.mb_strtolower($first_dir).'/admin_templates';
}
elseif ($this->forceThemeName && preg_match('/^theme:(.*)/', $first_dir, $regs)) {
@@ -170,63 +123,24 @@
return Array ($path, $module_filename);
}
- function LoadTemplate($filename, $title=NULL, $silent=0)
- {
- list ($path, $module_filename) = $this->GetTemplatePaths($filename);
-
- $template = new Template($path, $module_filename, $silent);
- if (!isset($title)) $title = $filename;
- $this->SetTemplate($title, $template);
- }
-
+ /**
+ * Returns template filename by given template name
+ *
+ * @param string $filename
+ * @return string
+ */
function GetRealFilename($filename)
{
list ($path, $module_filename) = $this->GetTemplatePaths($filename);
return $path.'/'.trim($module_filename, '/');
}
- function SetTemplate($title, &$template, $filename=null)
- {
- if (!isset($filename)) $filename=$title;
- $this->Templates[$title] = $template;
- $this->FileNames[$title] = $filename;
- }
-
- function &GetTemplate($title, $silent=0)
- {
- if (!isset($this->Templates[$title])) {
- $this->LoadTemplate($title, null, $silent);
- }
- return $this->Templates[$title];
- }
-
- function GetTemplateBody($title, $silent=0)
- {
- $template =& $this->GetTemplate($title, $silent);
- if ( !is_object($template) ) {
- return '';
- }
- return $template->GetBody();
- }
-
- function GetTemplateFileName($title)
- {
- return getArrayValue($this->FileNames, $title);
- }
-
- function SetTemplateBody($title, $body)
- {
- $template = new Template();
- $template->SetBody($body);
- $this->SetTemplate($title, $template);
- }
-
- function ParseTemplate($template_name)
- {
- $Parser = new TemplateParser($this->Application);
- return $Parser->Parse( $this->GetTemplateBody($template_name) );
- }
-
+ /**
+ * Checks, that given template exists on disk
+ *
+ * @param string $filename
+ * @return bool
+ */
function TemplateExists($filename)
{
if ((strpos($filename, '../') !== false) || (trim($filename) !== $filename)) {
@@ -243,38 +157,260 @@
return file_exists($real_file);
}
-
+ /**
+ * Returns information about template compilation status
+ *
+ * @param string $template
+ * @return Array
+ */
function GetPreParsed($template)
{
$real_name = $this->GetRealFilename($template);
- $fname = $real_name.'.php';
- $fname = str_replace(FULL_PATH, WRITEABLE . '/cache', $fname);
+ $fname = str_replace(FULL_PATH, WRITEABLE . '/cache', $real_name . '.php');
- $tname = $real_name.'.tpl';
+ $tname = $real_name . '.tpl';
if (!file_exists($tname)) {
+ // given template doesn't exist
return false;
}
- if (defined('SAFE_MODE') && SAFE_MODE) {
- $conn =& $this->Application->GetADODBConnection();
- $cached = $conn->GetRow('SELECT * FROM '.TABLE_PREFIX.'Cache WHERE VarName = "'.$fname.'"');
+ if ($this->_compileToDatabase) {
+ $sql = 'SELECT *
+ FROM ' . TABLE_PREFIX . 'Cache
+ WHERE VarName = "' . $fname . '"';
+ $cached = $this->Conn->GetRow($sql);
+
if ($cached !== false && $cached['Cached'] > filemtime($tname)) {
- return array('active' => 1, 'fname' => $fname, 'tname' => $tname, 'mode' => 'db', 'content' => $cached['Data']);
+ 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');
+ return Array ('active' => 1, 'fname' => $fname, 'tname' => $tname, 'mode' => 'file');
}
+
if (!file_exists($fname)) {
// make sure to create directory if pre-parsed file does not exist
- $this->CheckDir( dirname($fname), WRITEABLE . '/cache' );
+ $this->CheckDir(dirname($fname), WRITEABLE . '/cache');
}
}
- return array('active' => 0, 'fname' => $fname, 'tname' => $tname, 'mode'=>'file');
+
+ // when compiled template is expired or doesn't exist
+
+ return Array ('active' => 0, 'fname' => $fname, 'tname' => $tname, 'mode' => 'file');
}
/**
+ * Saves compiled template version to database or disk
+ *
+ * @param string $filename
+ * @param string $compiled_template
+ */
+ function saveTemplate($filename, &$compiled_template)
+ {
+ if ($this->_compileToDatabase) {
+ $fields_hash = Array (
+ 'VarName' => $filename,
+ 'Data' => &$compiled_template,
+ 'Cached' => adodb_mktime(),
+ );
+
+ $this->Conn->doInsert($fields_hash, TABLE_PREFIX . 'Cache', 'REPLACE');
+ }
+ else {
+ $fp = fopen($filename, 'w');
+
+ if ($this->_compressOutput) {
+ $compiled_template = $this->_compress($compiled_template);
+ }
+
+ if (!fwrite($fp, $compiled_template)) {
+ trigger_error('Saving compiled template failed', E_USER_ERROR);
+ }
+
+ fclose($fp);
+ }
+ }
+
+ /**
+ * Runs template and returns result (template already should be compiled by now)
+ *
+ * @param NParser $_parser
+ * @param Array $pre_parsed
+ * @return string
+ */
+ function &runTemplate(&$_parser, &$pre_parsed)
+ {
+ ob_start();
+
+ if ($this->_compileToDatabase) {
+ $sql = 'SELECT *
+ FROM ' . TABLE_PREFIX . 'Cache
+ WHERE VarName = "' . $pre_parsed['fname'] . '"';
+
+ $cached = $this->Conn->GetRow($sql);
+
+ if (($cached !== false) && ($cached['Cached'] > filemtime($pre_parsed['tname']))) {
+ eval('?' . '>' . $cached['Data']);
+ }
+ }
+ else {
+ if ($pre_parsed['mode'] == 'file') {
+ include($pre_parsed['fname']);
+ }
+ else {
+ eval('?' . '>' . $pre_parsed['content']);
+ }
+ }
+
+ $output = ob_get_clean();
+
+ return $output;
+ }
+
+ /**
+ * Compress given php code
+ *
+ * @param string $src
+ * @return string
+ */
+ function _compress($src) {
+ // Whitespaces left and right from this signs can be ignored
+ static $IW = array(
+ T_CONCAT_EQUAL, // .=
+ T_DOUBLE_ARROW, // =>
+ T_BOOLEAN_AND, // &&
+ T_BOOLEAN_OR, // ||
+ T_IS_EQUAL, // ==
+ T_IS_NOT_EQUAL, // != or <>
+ T_IS_SMALLER_OR_EQUAL, // <=
+ T_IS_GREATER_OR_EQUAL, // >=
+ T_INC, // ++
+ T_DEC, // --
+ T_PLUS_EQUAL, // +=
+ T_MINUS_EQUAL, // -=
+ T_MUL_EQUAL, // *=
+ T_DIV_EQUAL, // /=
+ T_IS_IDENTICAL, // ===
+ T_IS_NOT_IDENTICAL, // !==
+ T_DOUBLE_COLON, // ::
+ T_PAAMAYIM_NEKUDOTAYIM, // ::
+ T_OBJECT_OPERATOR, // ->
+ T_DOLLAR_OPEN_CURLY_BRACES, // ${
+ T_AND_EQUAL, // &=
+ T_MOD_EQUAL, // %=
+ T_XOR_EQUAL, // ^=
+ T_OR_EQUAL, // |=
+ T_SL, // <<
+ T_SR, // >>
+ T_SL_EQUAL, // <<=
+ T_SR_EQUAL, // >>=
+ );
+
+ $tokens = token_get_all($src);
+
+ $new = "";
+ $c = sizeof($tokens);
+ $iw = false; // ignore whitespace
+ $ih = false; // in HEREDOC
+ $ls = ""; // last sign
+ $ot = null; // open tag
+
+ for ($i = 0; $i < $c; $i++) {
+ $token = $tokens[$i];
+
+ if (is_array($token)) {
+ list ($tn, $ts) = $token; // tokens: number, string, line
+ $tname = token_name($tn);
+
+ if ($tn == T_INLINE_HTML) {
+ $new .= $ts;
+ $iw = false;
+ } else {
+ if ($tn == T_OPEN_TAG) {
+ if (strpos($ts, " ") || strpos($ts, "\n") || strpos($ts, "\t") || strpos($ts, "\r")) {
+ $ts = rtrim($ts);
+ }
+
+ $ts .= " ";
+ $new .= $ts;
+ $ot = T_OPEN_TAG;
+ $iw = true;
+ } elseif ($tn == T_OPEN_TAG_WITH_ECHO) {
+ $new .= $ts;
+ $ot = T_OPEN_TAG_WITH_ECHO;
+ $iw = true;
+ } elseif ($tn == T_CLOSE_TAG) {
+ if ($ot == T_OPEN_TAG_WITH_ECHO) {
+ $new = rtrim($new, "; ");
+ } else {
+ $ts = " ".$ts;
+ }
+
+ $new .= $ts;
+ $ot = null;
+ $iw = false;
+ } elseif (in_array($tn, $IW)) {
+ $new .= $ts;
+ $iw = true;
+ } elseif ($tn == T_CONSTANT_ENCAPSED_STRING || $tn == T_ENCAPSED_AND_WHITESPACE) {
+ if ($ts[0] == '"') {
+ $ts = addcslashes($ts, "\n\t\r");
+ }
+
+ $new .= $ts;
+ $iw = true;
+ } elseif ($tn == T_WHITESPACE) {
+ $nt = @$tokens[$i+1];
+ if (!$iw && (!is_string($nt) || $nt == '$') && !in_array($nt[0], $IW)) {
+ $new .= " ";
+ }
+
+ $iw = false;
+ } elseif ($tn == T_START_HEREDOC) {
+ $new .= "<<ProcessParsedTag($tag->Tag, $tag->NP, $tag->getPrefixSpecial());
-
- /*$Method=$tag->Tag;
- if(method_exists($this, $Method))
- {
- //echo htmlspecialchars($tag->GetFullTag()).'
';
- return $this->$Method($tag->NP);
- }
- else
- {
- if ($this->Application->hasObject('TagsAggregator')) {
- $aggregator =& $this->Application->recallObject('TagsAggregator');
- $tag_mapping = $aggregator->GetArrayValue($tag->Prefix, $Method);
- if ($tag_mapping) {
-
- $mapped_tag = new Tag('', $this->Application->Parser);
- $mapped_tag->CopyFrom($tag);
- $mapped_tag->Processor = $tag_mapping[0];
- $mapped_tag->Tag = $tag_mapping[1];
- $mapped_tag->NP['PrefixSpecial'] = $tag->getPrefixSpecial();
- $mapped_tag->RebuildTagData();
- return $mapped_tag->DoProcessTag();
- }
- }
- trigger_error('Tag '.$Method.' Undefined in '.get_class($this).'[Agregated Tag]:
'.$tag->RebuildTagData().'',E_USER_WARNING);
- return false;
- }*/
}
function CheckTag($tag, $prefix)
@@ -93,7 +67,7 @@
{
$Method = $tag;
if (method_exists($this, $Method)) {
- if ($this->Application->isDebugMode() && constOn('DBG_SHOW_TAGS')) {
+ if (defined('DEBUG_MODE') && defined('DBG_SHOW_TAGS') && DBG_SHOW_TAGS && $this->Application->isDebugMode()) {
$this->Application->Debugger->appendHTML('Processing PreParsed Tag '.$Method.' in '.$this->Prefix);
}
Index: branches/5.0.x/core/units/pdf/pdf_helper.php
===================================================================
diff -u -N -r12299 -r12323
--- branches/5.0.x/core/units/pdf/pdf_helper.php (.../pdf_helper.php) (revision 12299)
+++ branches/5.0.x/core/units/pdf/pdf_helper.php (.../pdf_helper.php) (revision 12323)
@@ -1,6 +1,6 @@
Application->InitParser();
- $xml = $this->Application->Parser->ParseTemplate($template, 1, $template_params);
+
+ $this->Application->Parser->SetParams($template_params);
+ $xml = $this->Application->Parser->Run($template);
+
$xml_helper =& $this->Application->recallObject('kXMLHelper');
/* @var $xml_helper kXMLHelper */
Index: branches/5.0.x/core/kernel/nparser/nparser.php
===================================================================
diff -u -N -r12299 -r12323
--- branches/5.0.x/core/kernel/nparser/nparser.php (.../nparser.php) (revision 12299)
+++ branches/5.0.x/core/kernel/nparser/nparser.php (.../nparser.php) (revision 12323)
@@ -1,6 +1,6 @@
_compressOutput = $this->Application->ConfigValue('UseTemplateCompression');
- }
-
function Compile($pre_parsed, $template_name = 'unknown')
{
$data = file_get_contents($pre_parsed['tname']);
@@ -76,23 +62,8 @@
}
// saving compiled version (only when compilation was successful)
- if (defined('SAFE_MODE') && SAFE_MODE) { // store cache files in database since can't save on filesystem
- 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->Buffers[0]).','.adodb_mktime().')');
- }
- else {
- $compiled = fopen($pre_parsed['fname'], 'w');
+ $this->Application->TemplatesCache->saveTemplate($pre_parsed['fname'], $this->Buffers[0]);
- if ($this->_compressOutput) {
- $this->Buffers[0] = $this->_compress($this->Buffers[0]);
- }
-
- if (!fwrite($compiled, $this->Buffers[0])) {
- trigger_error('Saving compiled template failed', E_USER_ERROR);
- }
- fclose($compiled);
- }
-
return true;
}
@@ -329,14 +300,18 @@
return $code;
}
- function CheckTemplate($t, $silent=null)
+ function CheckTemplate($t, $silent = null)
{
$pre_parsed = $this->Application->TemplatesCache->GetPreParsed($t);
if (!$pre_parsed) {
if (!$silent) {
- if ($this->Application->isDebugMode()) $this->Application->Debugger->appendTrace();
+ if ($this->Application->isDebugMode()) {
+ $this->Application->Debugger->appendTrace();
+ }
+
trigger_error('Cannot include "' . $t . '" - file does not exist', E_USER_ERROR);
}
+
return false;
}
@@ -349,44 +324,32 @@
$t = preg_replace('/^theme:.*?\//', '', $t);
}
- if (!$inc_parser->Compile($pre_parsed, $t)) return false;
+ if (!$inc_parser->Compile($pre_parsed, $t)) {
+ return false;
+ }
}
+
return $pre_parsed;
}
- function Run($t, $silent=null)
+ function Run($t, $silent = null)
{
if ((strpos($t, '../') !== false) || (trim($t) !== $t)) {
// when relative paths or special chars are found template names from url, then it's hacking attempt
return false;
}
$pre_parsed = $this->CheckTemplate($t, $silent);
- if (!$pre_parsed) return false;
+ if (!$pre_parsed) {
+ return false;
+ }
+
$backup_template = $this->TemplateName;
$backup_fullpath = $this->TempalteFullPath;
$this->TemplateName = $t;
$this->TempalteFullPath = $pre_parsed['tname'];
- ob_start();
- $_parser =& $this;
- if (defined('SAFE_MODE') && SAFE_MODE) { // read cache files from database since can't save on filesystem
- $conn =& $this->Application->GetADODBConnection();
- $cached = $conn->GetRow('SELECT * FROM '.TABLE_PREFIX.'Cache WHERE VarName = "'.$pre_parsed['fname'].'"');
- if ($cached !== false && $cached['Cached'] > filemtime($pre_parsed['tname'])) {
- eval('?'.'>'.$cached['Data']);
- }
- }
- else {
- if ($pre_parsed['mode'] == 'file') {
- include($pre_parsed['fname']);
- }
- else {
- eval('?'.'>'.$pre_parsed['content']);
- }
- }
- $output = ob_get_contents();
- ob_end_clean();
+ $output =& $this->Application->TemplatesCache->runTemplate($this, $pre_parsed);
$this->TemplateName = $backup_template;
$this->TempalteFullPath = $backup_fullpath;
@@ -739,140 +702,4 @@
$this->CacheSet($this->PopPointer(), $ret); // . ($this->CurrentKeyPart ? ':'.$this->CurrentKeyPart : '')
echo $ret;
}
-
- function _compress($src) {
- // Whitespaces left and right from this signs can be ignored
- static $IW = array(
- T_CONCAT_EQUAL, // .=
- T_DOUBLE_ARROW, // =>
- T_BOOLEAN_AND, // &&
- T_BOOLEAN_OR, // ||
- T_IS_EQUAL, // ==
- T_IS_NOT_EQUAL, // != or <>
- T_IS_SMALLER_OR_EQUAL, // <=
- T_IS_GREATER_OR_EQUAL, // >=
- T_INC, // ++
- T_DEC, // --
- T_PLUS_EQUAL, // +=
- T_MINUS_EQUAL, // -=
- T_MUL_EQUAL, // *=
- T_DIV_EQUAL, // /=
- T_IS_IDENTICAL, // ===
- T_IS_NOT_IDENTICAL, // !==
- T_DOUBLE_COLON, // ::
- T_PAAMAYIM_NEKUDOTAYIM, // ::
- T_OBJECT_OPERATOR, // ->
- T_DOLLAR_OPEN_CURLY_BRACES, // ${
- T_AND_EQUAL, // &=
- T_MOD_EQUAL, // %=
- T_XOR_EQUAL, // ^=
- T_OR_EQUAL, // |=
- T_SL, // <<
- T_SR, // >>
- T_SL_EQUAL, // <<=
- T_SR_EQUAL, // >>=
- );
-
- $tokens = token_get_all($src);
-
- $new = "";
- $c = sizeof($tokens);
- $iw = false; // ignore whitespace
- $ih = false; // in HEREDOC
- $ls = ""; // last sign
- $ot = null; // open tag
-
- for ($i = 0; $i < $c; $i++) {
- $token = $tokens[$i];
-
- if (is_array($token)) {
- list ($tn, $ts) = $token; // tokens: number, string, line
- $tname = token_name($tn);
-
- if ($tn == T_INLINE_HTML) {
- $new .= $ts;
- $iw = false;
- } else {
- if ($tn == T_OPEN_TAG) {
- if (strpos($ts, " ") || strpos($ts, "\n") || strpos($ts, "\t") || strpos($ts, "\r")) {
- $ts = rtrim($ts);
- }
-
- $ts .= " ";
- $new .= $ts;
- $ot = T_OPEN_TAG;
- $iw = true;
- } elseif ($tn == T_OPEN_TAG_WITH_ECHO) {
- $new .= $ts;
- $ot = T_OPEN_TAG_WITH_ECHO;
- $iw = true;
- } elseif ($tn == T_CLOSE_TAG) {
- if ($ot == T_OPEN_TAG_WITH_ECHO) {
- $new = rtrim($new, "; ");
- } else {
- $ts = " ".$ts;
- }
-
- $new .= $ts;
- $ot = null;
- $iw = false;
- } elseif (in_array($tn, $IW)) {
- $new .= $ts;
- $iw = true;
- } elseif ($tn == T_CONSTANT_ENCAPSED_STRING || $tn == T_ENCAPSED_AND_WHITESPACE) {
- if ($ts[0] == '"') {
- $ts = addcslashes($ts, "\n\t\r");
- }
-
- $new .= $ts;
- $iw = true;
- } elseif ($tn == T_WHITESPACE) {
- $nt = @$tokens[$i+1];
- if (!$iw && (!is_string($nt) || $nt == '$') && !in_array($nt[0], $IW)) {
- $new .= " ";
- }
-
- $iw = false;
- } elseif ($tn == T_START_HEREDOC) {
- $new .= "<<Application->InitParser();
$parser_params = $this->Application->Parser->Params; // backup parser params
- // ==== for TemplateParser class only: begin ====
-// $parser_pattern = $this->Application->Parser->Pattern;
-// $parser_values = $this->Application->Parser->Values;
-// $this->Application->Parser->Pattern = Array(); // fixes bug in TemplateParser::SortParams
-// $this->Application->Parser->Values = Array(); // fixes bug in TemplateParser::SortParams
- // ==== for TemplateParser class only: end ====
-
$this->Application->Parser->SetParams( array_merge_recursive2($parser_params, $direct_params) );
$message = implode('&|&', explode("\n\n", $message, 2)); // preserves double \n in case when tag is located in subject field
$message = $this->Application->Parser->Parse($message, 'email_template', 0);
- // ==== for TemplateParser class only: begin ====
-// $this->Application->Parser->Pattern = $parser_pattern;
-// $this->Application->Parser->Values = $parser_values;
- // ==== for TemplateParser class only: end ====
-
$this->Application->Parser->SetParams($parser_params); // restore parser params
// 2. replace line endings, that are send with data submitted via request
Index: branches/5.0.x/core/kernel/db/dblist.php
===================================================================
diff -u -N -r12299 -r12323
--- branches/5.0.x/core/kernel/db/dblist.php (.../dblist.php) (revision 12299)
+++ branches/5.0.x/core/kernel/db/dblist.php (.../dblist.php) (revision 12323)
@@ -1,6 +1,6 @@
Application->isDebugMode() )
- {
+ if ($this->Application->isDebugMode()) {
global $debugger;
$debugger->appendTrace();
}
+
trigger_error('Depricated method kDBList->SetWhereClause. Use kDBList->addFilter instead.', E_USER_ERROR);
}
Index: branches/5.0.x/core/kernel/utility/debugger.php
===================================================================
diff -u -N -r12299 -r12323
--- branches/5.0.x/core/kernel/utility/debugger.php (.../debugger.php) (revision 12299)
+++ branches/5.0.x/core/kernel/utility/debugger.php (.../debugger.php) (revision 12323)
@@ -1,6 +1,6 @@
isDebugMode() && constOn('DBG_PROFILE_MEMORY')) {
+ if (defined('DEBUG_MODE') && $this->isDebugMode() && constOn('DBG_PROFILE_MEMORY')) {
$this->Debugger->appendMemoryUsage('Application before Init:');
}
if (!$this->isDebugMode() && !constOn('DBG_ZEND_PRESENT')) {
@@ -320,15 +312,15 @@
$this->RegisterDefaultBuildEvents();
$this->SetDefaultConstants();
- if( defined('DEBUG_MODE') && $this->isDebugMode() ) {
+ if (defined('DEBUG_MODE') && $this->isDebugMode()) {
$this->Debugger->appendTimestamp('Before UnitConfigReader');
}
$this->UnitConfigReader =& $this->recallObject('kUnitConfigReader');
$this->UnitConfigReader->scanModules(MODULES_PATH);
$this->registerModuleConstants();
- if( defined('DEBUG_MODE') && $this->isDebugMode() ) {
+ if (defined('DEBUG_MODE') && $this->isDebugMode()) {
$this->Debugger->appendTimestamp('After UnitConfigReader');
}
@@ -339,13 +331,13 @@
$this->HttpQuery =& $this->recallObject('HTTPQuery');
- if( defined('DEBUG_MODE') && $this->isDebugMode() ) {
+ if (defined('DEBUG_MODE') && $this->isDebugMode()) {
$this->Debugger->appendTimestamp('Processed HTTPQuery initial');
}
$this->Session =& $this->recallObject('Session');
- if( defined('DEBUG_MODE') && $this->isDebugMode() ) {
+ if (defined('DEBUG_MODE') && $this->isDebugMode()) {
$this->Debugger->appendTimestamp('Processed Session');
}
@@ -363,7 +355,7 @@
$this->Session->ValidateExpired();
- if( defined('DEBUG_MODE') && $this->isDebugMode() ) {
+ if (defined('DEBUG_MODE') && $this->isDebugMode()) {
$this->Debugger->appendTimestamp('Processed HTTPQuery AfterInit');
}
@@ -372,17 +364,16 @@
$this->Phrases->Init('phrases');
- if( defined('DEBUG_MODE') && $this->isDebugMode() ) {
+ if (defined('DEBUG_MODE') && $this->isDebugMode()) {
$this->Debugger->appendTimestamp('Loaded cache and phrases');
}
$this->UnitConfigReader->AfterConfigRead();
- if( defined('DEBUG_MODE') && $this->isDebugMode() ) {
+ if (defined('DEBUG_MODE') && $this->isDebugMode()) {
$this->Debugger->appendTimestamp('Processed AfterConfigRead');
}
-
/*// Module items are recalled during url parsing & PhrasesCache is needed already there,
// because it's used in their build events. That's why phrases cache initialization is
// called from kHTTPQuery in case when mod_rewrite is used
@@ -403,7 +394,7 @@
$this->ValidateLogin();
- if( defined('DEBUG_MODE') && $this->isDebugMode() ) {
+ if (defined('DEBUG_MODE') && $this->isDebugMode()) {
$this->Debugger->profileFinish('kernel4_startup');
}
@@ -617,14 +608,12 @@
$this->registerClass('Params', KERNEL_PATH.'/utility/params.php');
$this->registerClass('kHelper', KERNEL_PATH.'/kbase.php');
- $this->registerClass('kCache', KERNEL_PATH.'/utility/cache.php', 'Cache', Array('Params'));
- $this->registerClass('kHTTPQuery', KERNEL_PATH.'/utility/http_query.php', 'HTTPQuery', Array('Params') );
+ $this->registerClass('kCache', KERNEL_PATH.'/utility/cache.php', 'Cache', 'Params');
+ $this->registerClass('kHTTPQuery', KERNEL_PATH.'/utility/http_query.php', 'HTTPQuery', 'Params');
$this->registerClass('Session', KERNEL_PATH.'/session/session.php');
$this->registerClass('SessionStorage', KERNEL_PATH.'/session/session.php');
-
-
$this->registerClass('Params', KERNEL_PATH.'/utility/params.php', 'kActions');
$this->registerClass('kMultipleFilter', KERNEL_PATH.'/utility/filters.php');
@@ -636,25 +625,20 @@
$this->registerClass('kMainTagProcessor', KERNEL_PATH.'/processors/main_processor.php','m_TagProcessor', 'kTagProcessor');
$this->registerClass('kDBTagProcessor', KERNEL_PATH.'/db/db_tag_processor.php', null, 'kTagProcessor');
-
- $this->registerClass('TemplatesCache', KERNEL_PATH.'/nparser/template.php',null, 'kDBTagProcessor');
- $this->registerClass('Template', KERNEL_PATH.'/nparser/template.php');
-
+ $this->registerClass('TemplatesCache', KERNEL_PATH.'/nparser/template_cache.php', null, Array ('kHelper', 'kDBTagProcessor'));
$this->registerClass('NParser', KERNEL_PATH.'/nparser/nparser.php');
- $this->registerClass('kEmailSendingHelper', KERNEL_PATH.'/utility/email_send.php', 'EmailSender', Array('kHelper'));
+ $this->registerClass('kEmailSendingHelper', KERNEL_PATH.'/utility/email_send.php', 'EmailSender', 'kHelper');
$this->registerClass('kSocket', KERNEL_PATH.'/utility/socket.php', 'Socket');
if (file_exists(MODULES_PATH.'/in-commerce/units/currencies/currency_rates.php')) {
$this->registerClass('kCurrencyRates', MODULES_PATH.'/in-commerce/units/currencies/currency_rates.php');
}
- $this->registerClass('FCKeditor', FULL_PATH.'/admin/editor/cmseditor/fckeditor.php'); // need this?
-
/* Moved from MyApplication */
- $this->registerClass('InpSession',KERNEL_PATH.'/../units/general/inp_ses_storage.php','Session');
- $this->registerClass('InpSessionStorage',KERNEL_PATH.'/../units/general/inp_ses_storage.php','SessionStorage');
+ $this->registerClass('InpSession',KERNEL_PATH.'/../units/general/inp_ses_storage.php', 'Session');
+ $this->registerClass('InpSessionStorage',KERNEL_PATH.'/../units/general/inp_ses_storage.php', 'SessionStorage');
$this->registerClass('kCatDBItem',KERNEL_PATH.'/../units/general/cat_dbitem.php');
$this->registerClass('kCatDBItemExportHelper',KERNEL_PATH.'/../units/general/cat_dbitem_export.php', 'CatItemExportHelper');
@@ -792,7 +776,7 @@
$event_manager =& $this->recallObject('EventManager');
/* @var $event_manager kEventManager */
- if($this->isDebugMode() && constOn('DBG_SHOW_HTTPQUERY')) {
+ if (defined('DEBUG_MODE') && $this->isDebugMode() && constOn('DBG_SHOW_HTTPQUERY')) {
$this->Debugger->appendHTML('HTTPQuery:');
$this->Debugger->dumpVars($this->HttpQuery->_Params);
}
@@ -812,7 +796,7 @@
*/
function Run()
{
- if($this->isDebugMode() && constOn('DBG_PROFILE_MEMORY')) {
+ if (defined('DEBUG_MODE') && $this->isDebugMode() && constOn('DBG_PROFILE_MEMORY')) {
$this->Debugger->appendMemoryUsage('Application before Run:');
}
@@ -862,48 +846,31 @@
$t = ltrim($cms_handler->GetDesignTemplate(), '/');
- if ($this->isDebugMode()) {
+ if (defined('DEBUG_MODE') && $this->isDebugMode()) {
$this->Debugger->appendHTML('Design Template: ' . $t . '; CategoryID: ' . $this->GetVar('m_cat_id'));
}
}
/*else {
$cms_handler->SetCatByTemplate();
}*/
- if($this->isDebugMode() && constOn('DBG_PROFILE_MEMORY')) {
+ if (defined('DEBUG_MODE') && $this->isDebugMode() && constOn('DBG_PROFILE_MEMORY')) {
$this->Debugger->appendMemoryUsage('Application before Parsing:');
}
- if (defined('NPARSER') && 'NPARSER') {
- $this->HTML = $this->NParser->Run( $t );
- }
- else {
- $this->HTML = $this->Parser->ParseTemplate( $t );
- }
+ $this->HTML = $this->Parser->Run($t);
- if ($this->isDebugMode() && constOn('DBG_PROFILE_MEMORY')) {
+ if (defined('DEBUG_MODE') && $this->isDebugMode() && constOn('DBG_PROFILE_MEMORY')) {
$this->Debugger->appendMemoryUsage('Application after Parsing:');
}
}
function InitParser($theme_name = false)
{
- if (defined('NPARSER') && 'NPARSER') {
- if( !is_object($this->NParser) ) {
- $this->NParser =& $this->recallObject('NParser');
- $this->TemplatesCache =& $this->recallObject('TemplatesCache');
-
- // can be removed in future
-// $this->Parser =& $this->recallObject('TemplateParser');
- $this->Parser =& $this->NParser;
- }
+ if( !is_object($this->Parser) ) {
+ $this->Parser =& $this->recallObject('NParser');
+ $this->TemplatesCache =& $this->recallObject('TemplatesCache');
}
- else {
- if( !is_object($this->Parser) ) {
- $this->Parser =& $this->recallObject('TemplateParser');
- $this->TemplatesCache =& $this->recallObject('TemplatesCache');
- }
- }
$this->TemplatesCache->forceThemeName = $theme_name;
}
@@ -918,11 +885,12 @@
function Done()
{
$this->HandleEvent( new kEvent('adm:OnBeforeShutdown') );
- if ($this->isDebugMode() && constOn('DBG_PROFILE_MEMORY')) {
+
+ if (defined('DEBUG_MODE') && $this->isDebugMode() && constOn('DBG_PROFILE_MEMORY')) {
$this->Debugger->appendMemoryUsage('Application before Done:');
}
- if ($this->isDebugMode()) {
+ if (defined('DEBUG_MODE') && $this->isDebugMode()) {
$this->EventManager->RunRegularEvents(reAFTER);
$this->Session->SaveData();
@@ -1254,34 +1222,11 @@
$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)
- {
- $a_tag = new Tag($tag_data,$this->Parser);
- return $a_tag->DoProcessTag();
- }
-
function ProcessParsedTag($prefix, $tag, $params)
{
- if (defined('NPARSER') && NPARSER) {
- $p = $this->Parser->GetProcessor($prefix);
- return $p->ProcessParsedTag($tag, $params, $prefix);
- }
+ $processor = $this->Parser->GetProcessor($prefix);
- $a_tag = new Tag('',$this->Parser);
- $a_tag->Tag = $tag;
- $tmp=$this->Application->processPrefix($prefix);
- $a_tag->Processor = $tmp['prefix'];
- $a_tag->Special = $tmp['special'];
- $a_tag->NamedParams = $params;
- return $a_tag->DoProcessTag();
+ return $processor->ProcessParsedTag($tag, $params, $prefix);
}
/**
@@ -1306,7 +1251,10 @@
*/
function ParseBlock($params, $pass_params = 0, $as_template = false)
{
- if (substr($params['name'], 0, 5) == 'html:') return substr($params['name'], 6);
+ if (substr($params['name'], 0, 5) == 'html:') {
+ return substr($params['name'], 6);
+ }
+
return $this->Parser->ParseBlock($params, $pass_params, $as_template);
}
@@ -1793,7 +1741,7 @@
$ret = ENV_VAR_NAME.'=';
}
- $ret .= $sid.(constOn('INPORTAL_ENV') ? '-' : ':');
+ $ret .= $sid . '-'; // SID-TEMPLATE
$encode = false;
if (isset($params['__URLENCODE__'])) {
@@ -2235,8 +2183,9 @@
*/
function &recallTagProcessor($prefix)
{
- $this->InitParser(); // because kDBTagProcesor is in TemplateParser dependencies
- $result =& $this->recallObject($prefix.'_TagProcessor');
+ $this->InitParser(); // because kDBTagProcesor is in NParser dependencies
+ $result =& $this->recallObject($prefix . '_TagProcessor');
+
return $result;
}
Index: branches/5.0.x/core/kernel/utility/unit_config_reader.php
===================================================================
diff -u -N -r12299 -r12323
--- branches/5.0.x/core/kernel/utility/unit_config_reader.php (.../unit_config_reader.php) (revision 12299)
+++ branches/5.0.x/core/kernel/utility/unit_config_reader.php (.../unit_config_reader.php) (revision 12323)
@@ -1,6 +1,6 @@
_sortRewriteListeners();
$this->CacheParsedData();
- if ($this->Application->isDebugMode(false) && constOn('DBG_VALIDATE_CONFIGS')) {
+ if (defined('DEBUG_MODE') && DEBUG_MODE && defined('DBG_VALIDATE_CONFIGS') && DBG_VALIDATE_CONFIGS) {
// validate configs here to have changes from OnAfterConfigRead hooks to prefixes
foreach ($this->configData as $prefix => $config) {
if (!isset($config['TableName'])) continue;
Index: branches/5.0.x/core/kernel/processors/main_processor.php
===================================================================
diff -u -N -r12299 -r12323
--- branches/5.0.x/core/kernel/processors/main_processor.php (.../main_processor.php) (revision 12299)
+++ branches/5.0.x/core/kernel/processors/main_processor.php (.../main_processor.php) (revision 12323)
@@ -1,6 +1,6 @@
Tag=='include') $tag->Tag='MyInclude';
- return parent::ProcessTag($tag);
- }
-
- /**
* Base folder for all template includes
*
* @param Array $params
@@ -219,54 +206,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
@@ -275,9 +242,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);
}
@@ -381,7 +348,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) : '';
}
/**
@@ -599,75 +568,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 = '';
@@ -710,7 +610,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;
@@ -721,67 +622,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
@@ -790,10 +631,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'];
@@ -833,7 +674,7 @@
$o.= $this->Application->ParseBlock($block_params, 1);
}
return $o;
- }
+ }*/
function LoggedIn($params)
{