Page MenuHomeIn-Portal Phabricator

in-portal
No OneTemporary

File Metadata

Created
Sun, Jul 20, 6:28 AM

in-portal

Index: trunk/kernel/units/categories/categories_item.php
===================================================================
--- trunk/kernel/units/categories/categories_item.php (revision 4805)
+++ trunk/kernel/units/categories/categories_item.php (revision 4806)
@@ -1,151 +1,140 @@
<?php
class CategoriesItem extends kDBItem
{
- /**
- * Use automatic filename generation
- *
- * @var bool
- */
- var $useFilenames = true;
-
- function Create()
+ function Create($force_id=false, $system_create=false)
{
if (!$this->Validate()) return false;
$this->SetDBField('ResourceId', $this->Application->NextResourceId());
$this->SetDBField('CreatedById', $this->Application->GetVar('u_id') );
$this->SetDBField('CreatedOn_date', adodb_mktime() );
$this->SetDBField('CreatedOn_time', adodb_mktime() );
-
- if ($this->useFilenames) {
- $this->checkFilename();
- $this->generateFilename();
- }
+
+ $this->checkFilename();
+ $this->generateFilename();
$this->SetDBField('ParentId', $this->Application->GetVar('m_cat_id') );
- $ret = parent::Create();
- if($ret)
- {
+ $ret = parent::Create($force_id, $system_create);
+ if ($ret) {
$sql = 'UPDATE %s SET ParentPath = %s WHERE CategoryId = %s';
$parent_path = $this->buildParentPath();
$this->Conn->Query( sprintf($sql, $this->TableName, $this->Conn->qstr($parent_path), $this->GetID() ) );
$this->SetDBField('ParentPath', $parent_path);
}
return $ret;
}
function Update($id=null, $system_update=false)
{
- if ($this->useFilenames) {
- $this->checkFilename();
- $this->generateFilename();
- }
+ $this->checkFilename();
+ $this->generateFilename();
+
$ret = parent::Update($id, $system_update);
return $ret;
}
function buildParentPath()
{
$parent_id = $this->GetDBField('ParentId');
$cat_table = $this->Application->getUnitOption($this->Prefix, 'TableName');
$sql = 'SELECT ParentPath FROM '.$cat_table.' WHERE CategoryId = %s';
$parent_path = $this->Conn->GetOne( sprintf($sql, $parent_id) );
if(!$parent_path && $parent_id) $parent_path = '|'.$parent_id.'|';
return $parent_path.$this->GetID().'|';
}
/**
- * replace not allowed symbols with "_" chars + remove duplicate "_" chars in result
- *
- * @param string $string
- * @return string
- */
+ * replace not allowed symbols with "_" chars + remove duplicate "_" chars in result
+ *
+ * @param string $string
+ * @return string
+ */
function stripDisallowed($string)
{
$not_allowed = Array( ' ', '\\', '/', ':', '*', '?', '"', '<', '>', '|', '`',
'~', '!', '@', '#', '$', '%', '^', '&', '(', ')', '~',
'+', '=', '-', '{', '}', ']', '[', "'", ';', '.', ',');
$string = str_replace($not_allowed, '_', $string);
$string = preg_replace('/(_+)/', '_', $string);
$string = $this->checkAutoFilename($string);
return $string;
}
function checkFilename()
{
if( !$this->GetDBField('AutomaticFilename') )
{
$filename = $this->GetDBField('Filename');
$this->SetDBField('Filename', $this->stripDisallowed($filename) );
}
}
function checkAutoFilename($filename)
{
if(!$filename) return $filename;
$item_id = !$this->GetID() ? 0 : $this->GetID();
// check temp table
$sql_temp = 'SELECT '.$this->IDField.' FROM '.$this->TableName.' WHERE Filename = '.$this->Conn->qstr($filename);
$found_temp_ids = $this->Conn->GetCol($sql_temp);
// check live table
$sql_live = 'SELECT '.$this->IDField.' FROM '.$this->Application->GetLiveName($this->TableName).' WHERE Filename = '.$this->Conn->qstr($filename);
$found_live_ids = $this->Conn->GetCol($sql_live);
$found_item_ids = array_unique( array_merge($found_temp_ids, $found_live_ids) );
$has_page = preg_match('/(.*)_([\d]+)([a-z]*)$/', $filename, $rets);
$duplicates_found = (count($found_item_ids) > 1) || ($found_item_ids && $found_item_ids[0] != $item_id);
if ($duplicates_found || $has_page) // other category has same filename as ours OR we have filename, that ends with _number
{
$append = $duplicates_found ? '_a' : '';
if($has_page)
{
$filename = $rets[1].'_'.$rets[2];
$append = $rets[3] ? $rets[3] : '_a';
}
// check live & temp table
$sql_temp = 'SELECT '.$this->IDField.' FROM '.$this->TableName.' WHERE (Filename = %s) AND ('.$this->IDField.' != '.$item_id.')';
$sql_live = 'SELECT '.$this->IDField.' FROM '.$this->Application->GetLiveName($this->TableName).' WHERE (Filename = %s) AND ('.$this->IDField.' != '.$item_id.')';
while ( $this->Conn->GetOne( sprintf($sql_temp, $this->Conn->qstr($filename.$append)) ) > 0 ||
$this->Conn->GetOne( sprintf($sql_live, $this->Conn->qstr($filename.$append)) ) > 0 )
{
if (substr($append, -1) == 'z') $append .= 'a';
$append = substr($append, 0, strlen($append) - 1) . chr( ord( substr($append, -1) ) + 1 );
}
return $filename.$append;
}
return $filename;
}
/**
- * Generate item's filename based on it's title field value
- *
- * @return string
- */
+ * Generate item's filename based on it's title field value
+ *
+ * @return string
+ */
function generateFilename()
{
if ( !$this->GetDBField('AutomaticFilename') && $this->GetDBField('Filename') ) return false;
$title_field = $this->Application->getUnitOption($this->Prefix, 'TitleField');
$name = $this->stripDisallowed( $this->GetDBField($title_field) );
if ( $name != $this->GetDBField('Filename') ) $this->SetDBField('Filename', $name);
}
}
?>
\ No newline at end of file
Property changes on: trunk/kernel/units/categories/categories_item.php
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.6
\ No newline at end of property
+1.7
\ No newline at end of property
Index: trunk/kernel/units/general/helpers/mod_rewrite_helper.php
===================================================================
--- trunk/kernel/units/general/helpers/mod_rewrite_helper.php (revision 4805)
+++ trunk/kernel/units/general/helpers/mod_rewrite_helper.php (revision 4806)
@@ -1,300 +1,307 @@
<?php
class kModRewriteHelper extends kHelper {
function kModRewriteHelper()
{
parent::kHelper();
$this->HTTPQuery =& $this->Application->recallObject('HTTPQuery');
}
function processRewriteURL()
{
// directory_1_2_3/sc1/inlink/detail/3/l1_ka_asd.html
$url = $this->HTTPQuery->Get('_mod_rw_url_');
if( substr($url, -5) == '.html' ) $url = substr($url, 0, strlen($url) - 5 );
$url_parts = $url ? explode('/', $url) : Array();
$process_module = true;
if($this->HTTPQuery->Get('rewrite') == 'on' || !$url_parts)
{
// set default values
$defaults = Array('m_cat_id' => 0, 'm_cat_page' => 1, 'm_opener' => 's');
foreach ($defaults as $default_key => $default_value)
{
if ($this->HTTPQuery->Get($default_key) == null) {
$this->HTTPQuery->Set($default_key, $default_value);
}
}
}
if(!$url_parts)
{
$this->Application->Phrases = new PhrasesCache();
$this->Application->VerifyLanguageId();
$this->Application->Phrases->Init('phrases');
$this->Application->VerifyThemeId();
$this->HTTPQuery->Set('t', $this->HTTPQuery->getDefaultTemplate('') );
$this->HTTPQuery->finalizeParsing(Array('m'));
return false;
}
else
{
$this->HTTPQuery->Set('t', '');
}
$url_part = array_shift($url_parts);
// match language
$sql = 'SELECT LanguageId FROM '.TABLE_PREFIX.'Language WHERE LOWER(PackName) = '.$this->Conn->qstr($url_part).' AND Enabled = 1';
$language_id = $this->Conn->GetOne($sql);
$this->Application->Phrases = new PhrasesCache();
if($language_id)
{
$this->HTTPQuery->Set('m_lang', $language_id);
$url_part = $url_parts ? array_shift($url_parts) : ''; // prepare next url part for parsing
}
$this->Application->VerifyLanguageId();
// $this->HTTPQuery->Get('m_lang') );
// match theme
if($url_part)
{
$sql = 'SELECT ThemeId FROM '.TABLE_PREFIX.'Theme WHERE LOWER(Name) = '.$this->Conn->qstr($url_part).' AND Enabled = 1';
$theme_id = $this->Conn->GetOne($sql);
if($theme_id)
{
$this->HTTPQuery->Set('m_theme', $theme_id);
$url_part = $url_parts ? array_shift($url_parts) : ''; // prepare next url part for parsing
}
}
$this->Application->VerifyThemeId(); // verify anyway - will set default if not found!!!
// match category
$category_id = 0;
if($url_part)
{
$category_stack = Array();
$category_found = false;
$category_path = '';
$rets = Array(); // just in case someone has used this variable before
do
{
$category_path = trim($category_path.'/'.$url_part, '/');
if( preg_match('/(.*)_([\d]+)$/', $category_path, $rets) )
{
$category_path = $rets[1];
$this->HTTPQuery->Set('m_cat_page', $rets[2]);
}
- $sql = 'SELECT CategoryId
- FROM '.TABLE_PREFIX.'Category
- WHERE NamedParentPath = '.$this->Conn->qstr($category_path);
- array_push($category_stack, $this->Conn->GetOne($sql) );
+ if ($category_path == '') {
+ // this is "Home" virtual category
+ array_push($category_stack, 0);
+ }
+ else {
+ $sql = 'SELECT CategoryId
+ FROM '.TABLE_PREFIX.'Category
+ WHERE NamedParentPath = '.$this->Conn->qstr($category_path);
+ array_push($category_stack, $this->Conn->GetOne($sql) );
+ }
+
$category_found = end($category_stack);
- if($category_found) $url_part = array_shift($url_parts);
+ if ($category_found !== false) $url_part = array_shift($url_parts);
}while ($category_found && $url_part);
if (count($category_stack)) {
$category_id = array_pop($category_stack); // remove last not found category
if($category_id === false)
{
$category_id = array_pop($category_stack);
}
- if($category_id)
+ if($category_id !== false)
{
$this->HTTPQuery->Set('m_cat_id', $category_id);
}
}
elseif (!$category_found && getArrayValue($rets, 2)) {
$url_part = array_shift($url_parts);
}
}
if (!$url_part) {
// no more parts left in url
$process_module = false;
$sql = 'SELECT CachedCategoryTemplate
FROM '.TABLE_PREFIX.'Category
WHERE CategoryId = '.$category_id;
$category_template = $this->Conn->GetOne($sql);
if ($category_template) {
$category_template = explode('/', $category_template);
$url_part = array_shift($category_template);
$url_parts = $category_template;
}
else {
$url_part = 'index';
}
}
elseif ($url_part && count($url_parts) <= 1 && $category_id) {
// only filename left, no other parts
$process_module = false;
$sql = 'SELECT ParentPath, CachedItemTemplate, CachedCategoryTemplate
FROM '.TABLE_PREFIX.'Category
WHERE CategoryId = '.$category_id;
$category_data = $this->Conn->GetRow($sql);
$root_category_id = array_shift( explode('|', substr($category_data['ParentPath'], 1, -1)) );
$module_info = $this->Application->findModule('RootCat', $root_category_id);
if ($module_info) {
$module_prefix = $module_info['Var'];
$module_event = new kEvent($module_prefix.':ParseEnv', Array('url_parts' => array_merge(Array($url_part), $url_parts)) );
$this->Application->HandleEvent($module_event);
if ($module_event->status == erSUCCESS && $this->HTTPQuery->Get($module_prefix.'_id')) {
$item_template = $category_data['CachedItemTemplate'];
if ($item_template) {
$url_parts = explode('/', $item_template);
array_push($url_parts, $url_part); // save item's filename as not processed
$url_part = array_shift($url_parts);
}
}
elseif (!$module_event->getEventParam('url_parts')) {
// parseEnv has processed that param
$url_part = '';
$category_template = $category_data['CachedCategoryTemplate'];
if ($category_template) {
$category_template = explode('/', $category_template);
$url_part = array_shift($category_template);
$url_parts = $category_template;
}
else {
$url_part = 'index';
}
}
}
}
// match module
$next_template = $this->HTTPQuery->Get('next_template');
if($url_part || $next_template)
{
if($next_template)
{
$next_template_parts = explode('/', $next_template);
$module_folder = array_shift($next_template_parts);
}
else
{
$module_folder = $url_part;
}
foreach ($this->Application->ModuleInfo as $module_name => $module_data)
{
if( trim($module_data['TemplatePath'], '/') == $module_folder )
{
$module_prefix = $module_data['Var'];
break;
}
}
}
// match template
$template_path = '';
$template_found = false;
if($url_part)
{
// search for template in real template records
array_unshift($url_parts, $url_part);
$template_parts = $url_parts;
$url_parts = Array();
do
{
$template_path = implode('/', $template_parts);
$t_parts['path'] = dirname($template_path) == '.' ? '' : '/'.dirname($template_path);
$t_parts['file'] = basename($template_path);
$sql = 'SELECT FileId
FROM '.TABLE_PREFIX.'ThemeFiles
WHERE (FilePath = '.$this->Conn->qstr($t_parts['path']).') AND (FileName = '.$this->Conn->qstr($t_parts['file'].'.tpl').')';
// $sql = 'SELECT FileId FROM '.TABLE_PREFIX.'ThemeFiles WHERE CONCAT(FilePath, "/", FileName) = '.$this->Conn->qstr('/'.$template_path.'.tpl');
$template_found = $this->Conn->GetOne($sql);
if(!$template_found)
{
array_unshift( $url_parts, array_pop($template_parts) );
}
}while (!$template_found && $template_parts);
// try to find template in virtual templates in case if such ability exists
if ($this->Application->isModuleEnabled('In-CMS') && !$template_found) {
$template_parts = $url_parts;
$url_parts = Array();
do
{
$template_path = implode('/', $template_parts);
$sql = 'SELECT PageId FROM '.TABLE_PREFIX.'Pages WHERE Path = '.$this->Conn->qstr($template_path);
$template_found = $this->Conn->GetOne($sql);
if(!$template_found)
{
array_unshift( $url_parts, array_pop($template_parts) );
}
}while (!$template_found && $template_parts);
}
}
// guess template if no existing template found
if(!$template_found && isset($module_folder) && $module_folder)
{
// 1. try index template of module
$sql = 'SELECT FileId FROM '.TABLE_PREFIX.'ThemeFiles WHERE CONCAT(FilePath, "/", FileName) = '.$this->Conn->qstr('/'.$module_folder.'/index.tpl');
$template_found = $this->Conn->GetOne($sql);
if($template_found)
{
$template_path = $module_folder.'/index';
array_shift($url_parts);
}
else
{
// 2. return error template then
$template_found = true;
$template_path = $this->Application->ConfigValue('ErrorTemplate');
if(!$template_path) $template_path = 'error_notfound';
header('HTTP/1.0 404 Not Found');
}
}
$this->HTTPQuery->Set('t', $this->HTTPQuery->getDefaultTemplate($template_found ? $template_path : '') );
// pass params left to module
$this->Application->Phrases->Init('phrases');
$passed = Array('m');
$module_params = Array();
if ( isset($module_prefix) ) {
$passed[] = $module_prefix;
$module_event = new kEvent($module_prefix.':ParseEnv', Array('url_parts' => $url_parts) );
if ($process_module) {
$this->Application->HandleEvent($module_event);
}
$item_id = $this->HTTPQuery->Get($module_prefix.'_id');
$module_params = Array($module_prefix.'_id' => $item_id ? $item_id : '0' );
if ($module_event->status == erFAIL) {
$not_found = $this->Application->ConfigValue('ErrorTemplate');
$this->HTTPQuery->Set('t', $not_found ? $not_found : 'error_notfound' );
}
}
$this->HTTPQuery->finalizeParsing($passed, $module_params);
}
}
?>
\ No newline at end of file
Property changes on: trunk/kernel/units/general/helpers/mod_rewrite_helper.php
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.1
\ No newline at end of property
+1.2
\ No newline at end of property
Index: trunk/core/units/categories/categories_item.php
===================================================================
--- trunk/core/units/categories/categories_item.php (revision 4805)
+++ trunk/core/units/categories/categories_item.php (revision 4806)
@@ -1,151 +1,140 @@
<?php
class CategoriesItem extends kDBItem
{
- /**
- * Use automatic filename generation
- *
- * @var bool
- */
- var $useFilenames = true;
-
- function Create()
+ function Create($force_id=false, $system_create=false)
{
if (!$this->Validate()) return false;
$this->SetDBField('ResourceId', $this->Application->NextResourceId());
$this->SetDBField('CreatedById', $this->Application->GetVar('u_id') );
$this->SetDBField('CreatedOn_date', adodb_mktime() );
$this->SetDBField('CreatedOn_time', adodb_mktime() );
-
- if ($this->useFilenames) {
- $this->checkFilename();
- $this->generateFilename();
- }
+
+ $this->checkFilename();
+ $this->generateFilename();
$this->SetDBField('ParentId', $this->Application->GetVar('m_cat_id') );
- $ret = parent::Create();
- if($ret)
- {
+ $ret = parent::Create($force_id, $system_create);
+ if ($ret) {
$sql = 'UPDATE %s SET ParentPath = %s WHERE CategoryId = %s';
$parent_path = $this->buildParentPath();
$this->Conn->Query( sprintf($sql, $this->TableName, $this->Conn->qstr($parent_path), $this->GetID() ) );
$this->SetDBField('ParentPath', $parent_path);
}
return $ret;
}
function Update($id=null, $system_update=false)
{
- if ($this->useFilenames) {
- $this->checkFilename();
- $this->generateFilename();
- }
+ $this->checkFilename();
+ $this->generateFilename();
+
$ret = parent::Update($id, $system_update);
return $ret;
}
function buildParentPath()
{
$parent_id = $this->GetDBField('ParentId');
$cat_table = $this->Application->getUnitOption($this->Prefix, 'TableName');
$sql = 'SELECT ParentPath FROM '.$cat_table.' WHERE CategoryId = %s';
$parent_path = $this->Conn->GetOne( sprintf($sql, $parent_id) );
if(!$parent_path && $parent_id) $parent_path = '|'.$parent_id.'|';
return $parent_path.$this->GetID().'|';
}
/**
- * replace not allowed symbols with "_" chars + remove duplicate "_" chars in result
- *
- * @param string $string
- * @return string
- */
+ * replace not allowed symbols with "_" chars + remove duplicate "_" chars in result
+ *
+ * @param string $string
+ * @return string
+ */
function stripDisallowed($string)
{
$not_allowed = Array( ' ', '\\', '/', ':', '*', '?', '"', '<', '>', '|', '`',
'~', '!', '@', '#', '$', '%', '^', '&', '(', ')', '~',
'+', '=', '-', '{', '}', ']', '[', "'", ';', '.', ',');
$string = str_replace($not_allowed, '_', $string);
$string = preg_replace('/(_+)/', '_', $string);
$string = $this->checkAutoFilename($string);
return $string;
}
function checkFilename()
{
if( !$this->GetDBField('AutomaticFilename') )
{
$filename = $this->GetDBField('Filename');
$this->SetDBField('Filename', $this->stripDisallowed($filename) );
}
}
function checkAutoFilename($filename)
{
if(!$filename) return $filename;
$item_id = !$this->GetID() ? 0 : $this->GetID();
// check temp table
$sql_temp = 'SELECT '.$this->IDField.' FROM '.$this->TableName.' WHERE Filename = '.$this->Conn->qstr($filename);
$found_temp_ids = $this->Conn->GetCol($sql_temp);
// check live table
$sql_live = 'SELECT '.$this->IDField.' FROM '.$this->Application->GetLiveName($this->TableName).' WHERE Filename = '.$this->Conn->qstr($filename);
$found_live_ids = $this->Conn->GetCol($sql_live);
$found_item_ids = array_unique( array_merge($found_temp_ids, $found_live_ids) );
$has_page = preg_match('/(.*)_([\d]+)([a-z]*)$/', $filename, $rets);
$duplicates_found = (count($found_item_ids) > 1) || ($found_item_ids && $found_item_ids[0] != $item_id);
if ($duplicates_found || $has_page) // other category has same filename as ours OR we have filename, that ends with _number
{
$append = $duplicates_found ? '_a' : '';
if($has_page)
{
$filename = $rets[1].'_'.$rets[2];
$append = $rets[3] ? $rets[3] : '_a';
}
// check live & temp table
$sql_temp = 'SELECT '.$this->IDField.' FROM '.$this->TableName.' WHERE (Filename = %s) AND ('.$this->IDField.' != '.$item_id.')';
$sql_live = 'SELECT '.$this->IDField.' FROM '.$this->Application->GetLiveName($this->TableName).' WHERE (Filename = %s) AND ('.$this->IDField.' != '.$item_id.')';
while ( $this->Conn->GetOne( sprintf($sql_temp, $this->Conn->qstr($filename.$append)) ) > 0 ||
$this->Conn->GetOne( sprintf($sql_live, $this->Conn->qstr($filename.$append)) ) > 0 )
{
if (substr($append, -1) == 'z') $append .= 'a';
$append = substr($append, 0, strlen($append) - 1) . chr( ord( substr($append, -1) ) + 1 );
}
return $filename.$append;
}
return $filename;
}
/**
- * Generate item's filename based on it's title field value
- *
- * @return string
- */
+ * Generate item's filename based on it's title field value
+ *
+ * @return string
+ */
function generateFilename()
{
if ( !$this->GetDBField('AutomaticFilename') && $this->GetDBField('Filename') ) return false;
$title_field = $this->Application->getUnitOption($this->Prefix, 'TitleField');
$name = $this->stripDisallowed( $this->GetDBField($title_field) );
if ( $name != $this->GetDBField('Filename') ) $this->SetDBField('Filename', $name);
}
}
?>
\ No newline at end of file
Property changes on: trunk/core/units/categories/categories_item.php
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.6
\ No newline at end of property
+1.7
\ No newline at end of property
Index: trunk/core/units/general/helpers/mod_rewrite_helper.php
===================================================================
--- trunk/core/units/general/helpers/mod_rewrite_helper.php (revision 4805)
+++ trunk/core/units/general/helpers/mod_rewrite_helper.php (revision 4806)
@@ -1,300 +1,307 @@
<?php
class kModRewriteHelper extends kHelper {
function kModRewriteHelper()
{
parent::kHelper();
$this->HTTPQuery =& $this->Application->recallObject('HTTPQuery');
}
function processRewriteURL()
{
// directory_1_2_3/sc1/inlink/detail/3/l1_ka_asd.html
$url = $this->HTTPQuery->Get('_mod_rw_url_');
if( substr($url, -5) == '.html' ) $url = substr($url, 0, strlen($url) - 5 );
$url_parts = $url ? explode('/', $url) : Array();
$process_module = true;
if($this->HTTPQuery->Get('rewrite') == 'on' || !$url_parts)
{
// set default values
$defaults = Array('m_cat_id' => 0, 'm_cat_page' => 1, 'm_opener' => 's');
foreach ($defaults as $default_key => $default_value)
{
if ($this->HTTPQuery->Get($default_key) == null) {
$this->HTTPQuery->Set($default_key, $default_value);
}
}
}
if(!$url_parts)
{
$this->Application->Phrases = new PhrasesCache();
$this->Application->VerifyLanguageId();
$this->Application->Phrases->Init('phrases');
$this->Application->VerifyThemeId();
$this->HTTPQuery->Set('t', $this->HTTPQuery->getDefaultTemplate('') );
$this->HTTPQuery->finalizeParsing(Array('m'));
return false;
}
else
{
$this->HTTPQuery->Set('t', '');
}
$url_part = array_shift($url_parts);
// match language
$sql = 'SELECT LanguageId FROM '.TABLE_PREFIX.'Language WHERE LOWER(PackName) = '.$this->Conn->qstr($url_part).' AND Enabled = 1';
$language_id = $this->Conn->GetOne($sql);
$this->Application->Phrases = new PhrasesCache();
if($language_id)
{
$this->HTTPQuery->Set('m_lang', $language_id);
$url_part = $url_parts ? array_shift($url_parts) : ''; // prepare next url part for parsing
}
$this->Application->VerifyLanguageId();
// $this->HTTPQuery->Get('m_lang') );
// match theme
if($url_part)
{
$sql = 'SELECT ThemeId FROM '.TABLE_PREFIX.'Theme WHERE LOWER(Name) = '.$this->Conn->qstr($url_part).' AND Enabled = 1';
$theme_id = $this->Conn->GetOne($sql);
if($theme_id)
{
$this->HTTPQuery->Set('m_theme', $theme_id);
$url_part = $url_parts ? array_shift($url_parts) : ''; // prepare next url part for parsing
}
}
$this->Application->VerifyThemeId(); // verify anyway - will set default if not found!!!
// match category
$category_id = 0;
if($url_part)
{
$category_stack = Array();
$category_found = false;
$category_path = '';
$rets = Array(); // just in case someone has used this variable before
do
{
$category_path = trim($category_path.'/'.$url_part, '/');
if( preg_match('/(.*)_([\d]+)$/', $category_path, $rets) )
{
$category_path = $rets[1];
$this->HTTPQuery->Set('m_cat_page', $rets[2]);
}
- $sql = 'SELECT CategoryId
- FROM '.TABLE_PREFIX.'Category
- WHERE NamedParentPath = '.$this->Conn->qstr($category_path);
- array_push($category_stack, $this->Conn->GetOne($sql) );
+ if ($category_path == '') {
+ // this is "Home" virtual category
+ array_push($category_stack, 0);
+ }
+ else {
+ $sql = 'SELECT CategoryId
+ FROM '.TABLE_PREFIX.'Category
+ WHERE NamedParentPath = '.$this->Conn->qstr($category_path);
+ array_push($category_stack, $this->Conn->GetOne($sql) );
+ }
+
$category_found = end($category_stack);
- if($category_found) $url_part = array_shift($url_parts);
+ if ($category_found !== false) $url_part = array_shift($url_parts);
}while ($category_found && $url_part);
if (count($category_stack)) {
$category_id = array_pop($category_stack); // remove last not found category
if($category_id === false)
{
$category_id = array_pop($category_stack);
}
- if($category_id)
+ if($category_id !== false)
{
$this->HTTPQuery->Set('m_cat_id', $category_id);
}
}
elseif (!$category_found && getArrayValue($rets, 2)) {
$url_part = array_shift($url_parts);
}
}
if (!$url_part) {
// no more parts left in url
$process_module = false;
$sql = 'SELECT CachedCategoryTemplate
FROM '.TABLE_PREFIX.'Category
WHERE CategoryId = '.$category_id;
$category_template = $this->Conn->GetOne($sql);
if ($category_template) {
$category_template = explode('/', $category_template);
$url_part = array_shift($category_template);
$url_parts = $category_template;
}
else {
$url_part = 'index';
}
}
elseif ($url_part && count($url_parts) <= 1 && $category_id) {
// only filename left, no other parts
$process_module = false;
$sql = 'SELECT ParentPath, CachedItemTemplate, CachedCategoryTemplate
FROM '.TABLE_PREFIX.'Category
WHERE CategoryId = '.$category_id;
$category_data = $this->Conn->GetRow($sql);
$root_category_id = array_shift( explode('|', substr($category_data['ParentPath'], 1, -1)) );
$module_info = $this->Application->findModule('RootCat', $root_category_id);
if ($module_info) {
$module_prefix = $module_info['Var'];
$module_event = new kEvent($module_prefix.':ParseEnv', Array('url_parts' => array_merge(Array($url_part), $url_parts)) );
$this->Application->HandleEvent($module_event);
if ($module_event->status == erSUCCESS && $this->HTTPQuery->Get($module_prefix.'_id')) {
$item_template = $category_data['CachedItemTemplate'];
if ($item_template) {
$url_parts = explode('/', $item_template);
array_push($url_parts, $url_part); // save item's filename as not processed
$url_part = array_shift($url_parts);
}
}
elseif (!$module_event->getEventParam('url_parts')) {
// parseEnv has processed that param
$url_part = '';
$category_template = $category_data['CachedCategoryTemplate'];
if ($category_template) {
$category_template = explode('/', $category_template);
$url_part = array_shift($category_template);
$url_parts = $category_template;
}
else {
$url_part = 'index';
}
}
}
}
// match module
$next_template = $this->HTTPQuery->Get('next_template');
if($url_part || $next_template)
{
if($next_template)
{
$next_template_parts = explode('/', $next_template);
$module_folder = array_shift($next_template_parts);
}
else
{
$module_folder = $url_part;
}
foreach ($this->Application->ModuleInfo as $module_name => $module_data)
{
if( trim($module_data['TemplatePath'], '/') == $module_folder )
{
$module_prefix = $module_data['Var'];
break;
}
}
}
// match template
$template_path = '';
$template_found = false;
if($url_part)
{
// search for template in real template records
array_unshift($url_parts, $url_part);
$template_parts = $url_parts;
$url_parts = Array();
do
{
$template_path = implode('/', $template_parts);
$t_parts['path'] = dirname($template_path) == '.' ? '' : '/'.dirname($template_path);
$t_parts['file'] = basename($template_path);
$sql = 'SELECT FileId
FROM '.TABLE_PREFIX.'ThemeFiles
WHERE (FilePath = '.$this->Conn->qstr($t_parts['path']).') AND (FileName = '.$this->Conn->qstr($t_parts['file'].'.tpl').')';
// $sql = 'SELECT FileId FROM '.TABLE_PREFIX.'ThemeFiles WHERE CONCAT(FilePath, "/", FileName) = '.$this->Conn->qstr('/'.$template_path.'.tpl');
$template_found = $this->Conn->GetOne($sql);
if(!$template_found)
{
array_unshift( $url_parts, array_pop($template_parts) );
}
}while (!$template_found && $template_parts);
// try to find template in virtual templates in case if such ability exists
if ($this->Application->isModuleEnabled('In-CMS') && !$template_found) {
$template_parts = $url_parts;
$url_parts = Array();
do
{
$template_path = implode('/', $template_parts);
$sql = 'SELECT PageId FROM '.TABLE_PREFIX.'Pages WHERE Path = '.$this->Conn->qstr($template_path);
$template_found = $this->Conn->GetOne($sql);
if(!$template_found)
{
array_unshift( $url_parts, array_pop($template_parts) );
}
}while (!$template_found && $template_parts);
}
}
// guess template if no existing template found
if(!$template_found && isset($module_folder) && $module_folder)
{
// 1. try index template of module
$sql = 'SELECT FileId FROM '.TABLE_PREFIX.'ThemeFiles WHERE CONCAT(FilePath, "/", FileName) = '.$this->Conn->qstr('/'.$module_folder.'/index.tpl');
$template_found = $this->Conn->GetOne($sql);
if($template_found)
{
$template_path = $module_folder.'/index';
array_shift($url_parts);
}
else
{
// 2. return error template then
$template_found = true;
$template_path = $this->Application->ConfigValue('ErrorTemplate');
if(!$template_path) $template_path = 'error_notfound';
header('HTTP/1.0 404 Not Found');
}
}
$this->HTTPQuery->Set('t', $this->HTTPQuery->getDefaultTemplate($template_found ? $template_path : '') );
// pass params left to module
$this->Application->Phrases->Init('phrases');
$passed = Array('m');
$module_params = Array();
if ( isset($module_prefix) ) {
$passed[] = $module_prefix;
$module_event = new kEvent($module_prefix.':ParseEnv', Array('url_parts' => $url_parts) );
if ($process_module) {
$this->Application->HandleEvent($module_event);
}
$item_id = $this->HTTPQuery->Get($module_prefix.'_id');
$module_params = Array($module_prefix.'_id' => $item_id ? $item_id : '0' );
if ($module_event->status == erFAIL) {
$not_found = $this->Application->ConfigValue('ErrorTemplate');
$this->HTTPQuery->Set('t', $not_found ? $not_found : 'error_notfound' );
}
}
$this->HTTPQuery->finalizeParsing($passed, $module_params);
}
}
?>
\ No newline at end of file
Property changes on: trunk/core/units/general/helpers/mod_rewrite_helper.php
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.1
\ No newline at end of property
+1.2
\ No newline at end of property

Event Timeline