Index: branches/RC/core/units/general/helpers/mod_rewrite_helper.php
===================================================================
diff -u -r10459 -r11501
--- branches/RC/core/units/general/helpers/mod_rewrite_helper.php (.../mod_rewrite_helper.php) (revision 10459)
+++ branches/RC/core/units/general/helpers/mod_rewrite_helper.php (.../mod_rewrite_helper.php) (revision 11501)
@@ -342,62 +342,43 @@
{
if (!isset($url_parts[0])) return false;
- if ($this->Application->isModuleEnabled('Proj-CMS')) {
- $friendly = $this->Conn->GetRow(
- ' SELECT CategoryId, NamedParentPath FROM '.TABLE_PREFIX.'Category
- WHERE FriendlyURL = '.$this->Conn->qstr(implode('/', $url_parts)));
- if ($friendly) {
- $vars['m_cat_id'] = $friendly['CategoryId'];
- $vars['t'] = preg_replace('/^content\//i', '', $friendly['NamedParentPath']);
- return true;
- }
+ $sql = 'SELECT CategoryId, NamedParentPath
+ FROM ' . TABLE_PREFIX . 'Category
+ WHERE FriendlyURL = ' . $this->Conn->qstr(implode('/', $url_parts));
+ $friendly = $this->Conn->GetRow($sql);
+ if ($friendly) {
+ $vars['m_cat_id'] = $friendly['CategoryId'];
+ $vars['t'] = preg_replace('/^content\//i', '', $friendly['NamedParentPath']);
+ return true;
+ }
- $template_path = 'content/'.implode('/', $url_parts);
+ $template_path = 'content/' . implode('/', $url_parts);
- $sql = 'SELECT CategoryId, IsIndex, NamedParentPath FROM '.TABLE_PREFIX.'Category
- WHERE
- LOWER(NamedParentPath) = '.$this->Conn->qstr($template_path).'
- AND
- Status IN (1,4) ';
- $template_found = $this->Conn->GetRow($sql);
+ $sql = 'SELECT CategoryId, IsIndex, NamedParentPath FROM '.TABLE_PREFIX.'Category
+ WHERE
+ LOWER(NamedParentPath) = '.$this->Conn->qstr($template_path).'
+ AND
+ Status IN (1,4) ';
+ $template_found = $this->Conn->GetRow($sql);
- if ($template_found) {
- // IsIndex = 2 is a Container-only page, meaning it should go to index-page child
- if ($template_found['IsIndex'] == 2) {
- $template_found = $this->Conn->GetRow('
- SELECT CategoryId, NamedParentPath FROM '.TABLE_PREFIX.'Category
- WHERE ParentId = '.$template_found['CategoryId'].' AND IsIndex = 1
- ');
- $vars['t'] = preg_replace('/^content\//i', '', $template_found['NamedParentPath']);
- }
- else {
- $vars['t'] = implode('/', $url_parts);
- }
- $vars['m_cat_id'] = $template_found['CategoryId'];
- $vars['is_virtual'] = true; // for template from POST
- return true;
+ if ($template_found) {
+ // IsIndex = 2 is a Container-only page, meaning it should go to index-page child
+ if ($template_found['IsIndex'] == 2) {
+ $sql = 'SELECT CategoryId, NamedParentPath
+ FROM ' . TABLE_PREFIX . 'Category
+ WHERE ParentId = '.$template_found['CategoryId'].' AND IsIndex = 1';
+ $template_found = $this->Conn->GetRow($sql);
+ $vars['t'] = preg_replace('/^content\//i', '', $template_found['NamedParentPath']);
}
- }
+ else {
+ $vars['t'] = implode('/', $url_parts);
+ }
- if ($this->Application->isModuleEnabled('In-Edit')) {
- $template_path = implode('/', $url_parts);
- $sql = 'SELECT p.PageId, ci.CategoryId FROM '.TABLE_PREFIX.'Pages AS p
- LEFT JOIN '.TABLE_PREFIX.'CategoryItems AS ci
- ON ci.ItemResourceId = p.ResourceId
- WHERE
- Path = '.$this->Conn->qstr($template_path).'
- AND
- ci.PrimaryCat = 1
- AND
- p.Status = 1';
- $template_found = $this->Conn->GetRow($sql);
+ $vars['m_cat_id'] = $template_found['CategoryId'];
+ $vars['is_virtual'] = true; // for template from POST
- if ($template_found) {
- $vars['m_cat_id'] = $template_found['CategoryId'];
- $vars['t'] = $template_path;
- return true;
- }
+ return true;
}
return false;
@@ -484,6 +465,8 @@
$this->ProcessLanguage($url_parts, $vars);
$this->ProcessTheme($url_parts, $vars);
+ // bug #1: cancells all other processing in case, when cms page is found
+ // bug #2: doesn't match template partially, e.g. "test/case/other" will not match to page "test/case" with "other" left for future processing
if ( $this->ProcessVirtualTemplate($url_parts, $vars) ) {
return $vars;
}
Index: branches/RC/core/install/install_schema.sql
===================================================================
diff -u -r11495 -r11501
--- branches/RC/core/install/install_schema.sql (.../install_schema.sql) (revision 11495)
+++ branches/RC/core/install/install_schema.sql (.../install_schema.sql) (revision 11501)
@@ -410,7 +410,6 @@
CategoryTemplate varchar(255) NOT NULL default '',
CachedCategoryTemplate varchar(255) NOT NULL default '',
Template varchar(255) default NULL,
- Path varchar(255) default NULL,
UseExternalUrl tinyint(3) unsigned NOT NULL default '0',
ExternalUrl varchar(255) NOT NULL default '',
UseMenuIconUrl tinyint(3) unsigned NOT NULL default '0',
Index: branches/RC/core/units/categories/categories_tag_processor.php
===================================================================
diff -u -r11495 -r11501
--- branches/RC/core/units/categories/categories_tag_processor.php (.../categories_tag_processor.php) (revision 11495)
+++ branches/RC/core/units/categories/categories_tag_processor.php (.../categories_tag_processor.php) (revision 11501)
@@ -1014,9 +1014,18 @@
$template = $this->Application->GetVar('t');
}
- if (strtolower($page->GetDBField('NamedParentPath')) != strtolower('Content/'.$template)) {
- // load, when used page object doesn't match requested page object
- $page->Load('Content/'.$template, 'NamedParentPath');
+ // different path in structure AND design template differes from requested template
+ $structure_path_match = strtolower( $page->GetDBField('NamedParentPath') ) == strtolower('Content/' . $template);
+ $design_match = $page->GetDBField('Template') == $template;
+
+ if (!$structure_path_match && !$design_match) {
+ // Same sql like in "c:getPassedID". Load, when current page object doesn't match requested page object
+ $sql = 'SELECT ' . $page->IDField . '
+ FROM ' . $page->TableName . '
+ WHERE (NamedParentPath = ' . $this->Conn->qstr('Content/' . $template) . ') OR (IsSystem = 1 AND Template = ' . $this->Conn->qstr($template) . ')';
+ $page_id = $this->Conn->GetOne($sql);
+
+ $page->Load($page_id);
}
return $page;
@@ -1060,7 +1069,7 @@
if (EDITING_MODE == EDITING_MODE_CMS) {
$bg_color = isset($params['bgcolor']) ? $params['bgcolor'] : '#ffffff';
$url_params = Array (
- 'pass' => 'm,st,content',
+ 'pass' => 'm,' . $this->Prefix . ',content',
'm_opener' => 'd',
'st_id' => $page->GetID(),
'content_id' => $content->GetID(),
@@ -1084,7 +1093,7 @@
// link from Front-End to admin, don't remove "index.php"
$edit_url = $this->Application->HREF('in-edit/pages/content_edit', ADMIN_DIRECTORY, $url_params, 'index.php');
$button_css = 'font-family: Arial, Verdana; font-size: 9pt; '.$pos_float.' z-index: 99; background-color: #F7C300; color: #CE0031; border: 1px solid #CE0031; padding: 1px 10px 1px 10px; cursor: pointer;';
- $edit_code = '
Edit
';
+ $edit_code = 'Edit
';
if (isset($params['forms_later']) && $params['forms_later']) {
$tmp = $edit_code;
@@ -1252,7 +1261,7 @@
$page =& $this->_getPage($params);
$url_params = Array(
- 'pass' => 'm,st',
+ 'pass' => 'm,' . $this->Prefix,
'm_opener' => 'd',
'st_id' => $page->GetID(),
'st_mode' => 't',
@@ -1264,9 +1273,9 @@
'index_file' => 'index.php',
);
- $edit_url = $this->Application->HREF('proj-cms/structure/structure_edit', '/admin', $url_params);
+ $edit_url = $this->Application->HREF('categories/categories_edit', '/admin', $url_params);
$button_css = 'position: absolute; z-index: 1; top: 1; left 1; font-family: Arial, Verdana; font-size: 9px; background-color: #F7C300; color: #CE0031; border: 1px solid #CE0031; width: auto; padding: 2px 10px 2px 10px; cursor: pointer;';
- $edit_code = 'Page Properties';
+ $edit_code = '
Page Properties';
$title = $this->PageInfo(array('type' => 'htmlhead_title'));
$edit_code .= '
'."\n";
- if ( $.isFunction(window.parent.frames["menu"].SyncActive) ) {
- window.parent.frames["menu"].SyncActive("' . $browse_url . '");
- }
- }
-
-
'."\n";*/
-
- $edit_code .= ''."\n";
-
return $edit_code;
}
@@ -1566,7 +1572,7 @@
$object =& $this->getObject($params);
$template = $object->GetDBField('NamedParentPath');
- $url_params = Array ('admin' => 1, 'pass' => 'm', 'index_file' => 'index.php');
+ $url_params = Array ('admin' => 1, 'pass' => 'm', 'm_cat_id' => $object->GetID(), 'index_file' => 'index.php');
return $this->Application->HREF($template, '_FRONT_END_', $url_params);
}
Index: branches/RC/core/units/general/helpers/category_helper.php
===================================================================
diff -u -r11336 -r11501
--- branches/RC/core/units/general/helpers/category_helper.php (.../category_helper.php) (revision 11336)
+++ branches/RC/core/units/general/helpers/category_helper.php (.../category_helper.php) (revision 11501)
@@ -6,7 +6,7 @@
{
$main_category_id = isset($params['cat_id']) ? $params['cat_id'] : $this->Application->GetVar('m_cat_id');
- $home_element = $this->getHomeCategoryPath($params);
+ $home_element = $this->getHomeCategoryPath($params, $main_category_id);
if (!getArrayValue($params, 'titles') && !getArrayValue($params, 'templates')) {
// no static templates given, show only category path
return $home_element . $this->getCategoryPath($main_category_id, $params);
@@ -161,10 +161,11 @@
return $module_info;
}
- function getHomeCategoryPath($params)
+ function getHomeCategoryPath($params, $current_category)
{
- $block_params['cat_id'] = 0;
+ $block_params['cat_id'] = $this->Application->findModule('Name', 'Proj-CMS', 'RootCat'); // 0;
$block_params['no_editing'] = 1;
+ $block_params['current'] = $current_category == $block_params['cat_id'] ? 1 : 0;
$block_params['cat_name'] = $this->Application->ProcessParsedTag('m', 'RootCategoryName', $params);
$block_params['name'] = $this->SelectParam($params, 'root_cat_render_as,render_as');
return $this->Application->ParseBlock($block_params);
@@ -207,12 +208,16 @@
WHERE '.$id_field.' = '.$main_category_id;
$category_data = $this->Conn->GetRow($sql);
+ $skip_category = $this->Application->findModule('Name', 'Proj-CMS', 'RootCat');
$cached_path[$main_category_id] = Array ();
if ($category_data) {
$category_names = explode('&|&', $category_data[$navbar_field]);
$category_ids = explode('|', substr($category_data['ParentPath'], 1, -1));
foreach ($category_ids as $category_index => $category_id) {
+ if ($category_id == $skip_category) {
+ continue;
+ }
$cached_path[$main_category_id][$category_id] = $category_names[$category_index];
}
}
Index: branches/RC/core/units/categories/categories_config.php
===================================================================
diff -u -r11495 -r11501
--- branches/RC/core/units/categories/categories_config.php (.../categories_config.php) (revision 11495)
+++ branches/RC/core/units/categories/categories_config.php (.../categories_config.php) (revision 11501)
@@ -307,7 +307,6 @@
'required' => 1, 'default' => null
),
- 'Path' => Array ('type' => 'string', 'formatter' => 'kFormatter', 'regexp'=>'/^[a-zA-Z0-9\-_\.\\/]*$/', 'error_msgs' => Array ('invalid_format'=>'!la_invalid_chars!'), 'default' => null, /*'unique'=>Array ('Path')*/),
'UseExternalUrl' => Array (
'type' => 'int',
'formatter' => 'kOptionsFormatter', 'options' => Array (0 => 'la_No', 1 => 'la_Yes'), 'use_phrases' => 1,
Index: branches/RC/core/units/configuration/configuration_event_handler.php
===================================================================
diff -u -r11200 -r11501
--- branches/RC/core/units/configuration/configuration_event_handler.php (.../configuration_event_handler.php) (revision 11200)
+++ branches/RC/core/units/configuration/configuration_event_handler.php (.../configuration_event_handler.php) (revision 11501)
@@ -144,14 +144,17 @@
}
}
- if ($event->status == erSUCCESS && $items_info) { // reset cache
- $id_field = $this->Application->getUnitOption($event->Prefix, 'IDField');
- $table_name = $this->Application->getUnitOption($event->Prefix, 'TableName');
+ if ($event->status == erSUCCESS) { // reset cache
+ $refresh_sections = false;
+ if ($items_info) {
+ $id_field = $this->Application->getUnitOption($event->Prefix, 'IDField');
+ $table_name = $this->Application->getUnitOption($event->Prefix, 'TableName');
- $sql = 'SELECT ' . $id_field . '
- FROM ' . $table_name . '
- WHERE ' . $id_field . ' IN (' . implode(',', array_keys($items_info)) . ') AND (VariableName = "AdvancedUserManagement")';
- $refresh_sections = $this->Conn->GetCol($sql);
+ $sql = 'SELECT ' . $id_field . '
+ FROM ' . $table_name . '
+ WHERE ' . $id_field . ' IN (' . implode(',', array_keys($items_info)) . ') AND (VariableName = "AdvancedUserManagement")';
+ $refresh_sections = $this->Conn->GetCol($sql);
+ }
if ($refresh_sections) {
// reset sections too, because of AdvancedUserManagement
Index: branches/RC/core/kernel/parser/template.php
===================================================================
diff -u -r11227 -r11501
--- branches/RC/core/kernel/parser/template.php (.../template.php) (revision 11227)
+++ branches/RC/core/kernel/parser/template.php (.../template.php) (revision 11501)
@@ -200,7 +200,7 @@
function TemplateExists($filename)
{
- $real_file = $this->GetRealFilename($filename);
+ $real_file = $this->GetRealFilename( strtolower($filename) );
if (!preg_match('/\.tpl$/', $real_file)) {
$real_file .= '.tpl';
}
Index: branches/RC/core/units/categories/cache_updater.php
===================================================================
diff -u -r11495 -r11501
--- branches/RC/core/units/categories/cache_updater.php (.../cache_updater.php) (revision 11495)
+++ branches/RC/core/units/categories/cache_updater.php (.../cache_updater.php) (revision 11501)
@@ -334,7 +334,7 @@
$data['category_template'] = '';
$data['item_template'] = '';
$data['children_count'] = 0;
- $data['system'] = 0;
+// $data['system'] = 0;
$data['left'] = 0;
$data['right'] = 2;
$data['debug_title'] = 'ROOT';
@@ -406,7 +406,7 @@
{
$fields_hash = Array (
'ParentPath' => '|'.implode('|', $data['parent_path']).'|',
- 'NamedParentPath' => $data['system'] ? $data['file_name'] : implode('/', $data['named_path'] ),
+ 'NamedParentPath' => /*$data['system'] ? $data['file_name'] :*/ implode('/', $data['named_path'] ),
'CachedCategoryTemplate' => $data['category_template'],
'CachedDescendantCatsQty' => $data['children_count'],
'TreeLeft' => $data['left'],
@@ -443,7 +443,7 @@
$data['parent_path'][] = $category_id;
$data['named_path'][] = preg_replace('/^Content\\//', '', $record['Filename']);
- $data['system'] = $record['IsSystem'];
+// $data['system'] = $record['IsSystem'];
$data['file_name'] = $record['Filename'];
// it is one of the modules root category
Index: branches/RC/core/admin_templates/categories/edit_content.tpl
===================================================================
diff -u
--- branches/RC/core/admin_templates/categories/edit_content.tpl (revision 0)
+++ branches/RC/core/admin_templates/categories/edit_content.tpl (revision 11501)
@@ -0,0 +1,54 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+"/>
+
+
\ No newline at end of file
Index: branches/RC/core/kernel/application.php
===================================================================
diff -u -r11495 -r11501
--- branches/RC/core/kernel/application.php (.../application.php) (revision 11495)
+++ branches/RC/core/kernel/application.php (.../application.php) (revision 11501)
@@ -804,8 +804,6 @@
// hide debug output from ajax requests automatically
define('DBG_SKIP_REPORTING', 1);
}
-
- define('EDITING_MODE', 0); // user can't edit anything
}
elseif ($this->GetVar('admin')) {
// viewing front-end through admin's frame
@@ -819,14 +817,10 @@
$editing_mode = $this->GetVar('editing_mode');
define('EDITING_MODE', $editing_mode ? $editing_mode : EDITING_MODE_CMS);
}
- else {
- // user can't edit anything
- define('EDITING_MODE', 0);
- }
- } else {
- define('EDITING_MODE', 0); // user can't edit anything
}
+ safeDefine('EDITING_MODE', 0); // user can't edit anything
+
if (!$this->RequestProcessed) $this->ProcessRequest();
$this->InitParser();
@@ -837,6 +831,10 @@
if (!$this->TemplatesCache->TemplateExists($t) && !$this->IsAdmin()) {
$t = $cms_handler->GetDesignTemplate();
+
+ if ($this->isDebugMode()) {
+ $this->Debugger->appendHTML('Design Template: ' . $t . '; CategoryID: ' . $this->GetVar('m_cat_id'));
+ }
}
/*else {
$cms_handler->SetCatByTemplate();
Index: branches/RC/core/kernel/db/db_event_handler.php
===================================================================
diff -u -r11495 -r11501
--- branches/RC/core/kernel/db/db_event_handler.php (.../db_event_handler.php) (revision 11495)
+++ branches/RC/core/kernel/db/db_event_handler.php (.../db_event_handler.php) (revision 11501)
@@ -83,6 +83,10 @@
$this->Application->LinkVar('m_cat_id');
}
+ if ($event->Name == 'OnSaveWidths') {
+ return $this->Application->IsAdmin() && $this->Application->LoggedIn();
+ }
+
return parent::CheckPermission($event);
}
@@ -2432,7 +2436,8 @@
*/
function OnSaveWidths(&$event)
{
- safeDefine('DBG_SKIP_REPORTING', 1);
+ $event->status = erSTOP;
+
$lang =& $this->Application->recallObject('lang.current');
// header('Content-type: text/xml; charset='.$lang->GetDBField('Charset'));
@@ -2441,7 +2446,8 @@
$picker_helper->PreparePicker($event->getPrefixSpecial(), $this->Application->GetVar('grid_name'));
$picker_helper->SaveWidths($event->getPrefixSpecial(), $this->Application->GetVar('widths'));
- exit;
+
+ echo 'OK';
}
/**
Index: branches/RC/core/units/categories/categories_item.php
===================================================================
diff -u -r11368 -r11501
--- branches/RC/core/units/categories/categories_item.php (.../categories_item.php) (revision 11368)
+++ branches/RC/core/units/categories/categories_item.php (.../categories_item.php) (revision 11501)
@@ -68,7 +68,7 @@
function stripDisallowed($string)
{
$filenames_helper =& $this->Application->recallObject('FilenamesHelper');
- /* @var $filenames_helper FilenamesHelper */
+ /* @var $filenames_helper kFilenamesHelper */
$string = $filenames_helper->replaceSequences($string);
@@ -77,12 +77,12 @@
function checkFilename()
{
- // System templates allow any characters in filename, because they may and will contain "/"
- if( !$this->GetDBField('AutomaticFilename') && !$this->GetDBField('IsSystem'))
- {
- $filename = $this->GetDBField('Filename');
- $this->SetDBField('Filename', $this->stripDisallowed($filename) );
+ if ($this->GetDBField('AutomaticFilename')) {
+ return ;
}
+
+ $filename = $this->GetDBField('Filename');
+ $this->SetDBField('Filename', $this->stripDisallowed($filename));
}
function checkAutoFilename($filename)
Index: branches/RC/core/units/general/main_event_handler.php
===================================================================
diff -u -r10274 -r11501
--- branches/RC/core/units/general/main_event_handler.php (.../main_event_handler.php) (revision 10274)
+++ branches/RC/core/units/general/main_event_handler.php (.../main_event_handler.php) (revision 11501)
@@ -87,9 +87,13 @@
$category_filename = $this->Application->getFilename('c', $processed_params['m_cat_id']);
$t = isset($url_params['t']) && $url_params['t'] ? $url_params['t'] : false;
// category name doesn't match template name -> Proj-CMS/In-Edit tricks
- if (!preg_match('/Content\/'.preg_quote($t, '/').'/i', $category_filename)) {
- $ret .= $category_filename.'/';
+
+ preg_match('/Content\/(.*)/i', $category_filename, $regs);
+ if ($regs && ($regs[1] != $t)) {
+ $ret .= ($t == '__default__' ? $regs[1] : $category_filename) . '/';
}
+
+// $ret .= $this->Application->getFilename('c', $processed_params['m_cat_id']).'/';
$url_params['category_processed'] = true;
}
else {
Index: branches/RC/core/units/categories/categories_event_handler.php
===================================================================
diff -u -r11495 -r11501
--- branches/RC/core/units/categories/categories_event_handler.php (.../categories_event_handler.php) (revision 11495)
+++ branches/RC/core/units/categories/categories_event_handler.php (.../categories_event_handler.php) (revision 11501)
@@ -438,7 +438,10 @@
if (!array_key_exists($template, $page_by_template)) {
$sql = 'SELECT ' . $this->Application->getUnitOption($event->Prefix, 'IDField') . '
FROM ' . $this->Application->getUnitOption($event->Prefix, 'TableName') . '
- WHERE NamedParentPath = ' . $this->Conn->qstr($template) . ' OR NamedParentPath = ' . $this->Conn->qstr('Content/' . $template);
+ WHERE
+ (NamedParentPath = ' . $this->Conn->qstr($template) . ') OR
+ (NamedParentPath = ' . $this->Conn->qstr('Content/' . $template) . ') OR
+ (IsSystem = 1 AND Template = ' . $this->Conn->qstr($template) . ')';
$page_id = $this->Conn->GetOne($sql);
}
else {
@@ -537,27 +540,11 @@
* Set cache modification mark if needed
*
* @param kEvent $event
- * @todo Path field is empty for each of virtual pages. Any logic here?
*/
function OnBeforeDeleteFromLive(&$event)
{
- // 1. update paths (cms part)
$id = $event->getEventParam('id');
- $old_paths = $this->Application->RecallVar('old_paths');
- $old_paths = $old_paths ? unserialize($old_paths) : Array ();
-
- $live_object =& $this->Application->recallObject($event->Prefix.'.-live', null, Array('live_table' => true, 'skip_autoload' => true));
- /* @var $live_object kDBItem */
-
- $live_object->Load($id);
- $live_path = $live_object->GetField('Path');
- $old_paths[$id] = $live_path;
-
- $this->Application->StoreVar('old_paths', serialize($old_paths));
-
- // 2. set perm cache update mark
-
// loding anyway, because this object is needed by "c-perm:OnBeforeDeleteFromLive" event
$temp_object =& $event->getObject( Array('skip_autoload' => true) );
$temp_object->Load($id);
@@ -571,6 +558,9 @@
}
// existing category was edited, check if in-cache fields are modified
+ $live_object =& $this->Application->recallObject($event->Prefix.'.-item', null, Array('live_table' => true, 'skip_autoload' => true));
+ $live_object->Load($id);
+
$cached_fields = Array('Name', 'Filename', 'CategoryTemplate', 'ParentId', 'Priority');
foreach ($cached_fields as $cached_field) {
@@ -1289,15 +1279,11 @@
/* @var $object kDBItem */
$object->SetDBField('Template', $this->_stripTemplateExtension( $object->GetDBField('Template') ));
- $object->SetDBField('Path', $this->_stripTemplateExtension( $object->GetDBField('Path') ));
- if ($object->GetDBField('IsSystem') == 1) {
+ if ($object->GetDBField('IsSystem') == 1) {
if (!$this->_templateFound($object->GetDBField('Template'), $object->GetDBField('ThemeId'))) {
$object->SetError('Template', 'template_file_missing', 'la_err_TemplateFileMissing');
}
- else {
- $object->SetDBField('Filename', 'Content/' . $object->GetDBField('Template'));
- }
}
$this->_saveTitleField($object, 'Title');
@@ -1328,45 +1314,6 @@
}
/**
- * When page is renamed, then update all links to it in content blocks
- *
- * @param kEvent $event
- * @todo Path field empty for each virtual page. Any logic here?
- */
- function OnBeforeCopyToLive(&$event)
- {
- $id = $event->getEventParam('id');
-
- $temp =& $this->Application->recallObject($event->Prefix.'.-temp', $event->Prefix);
- $temp->SwitchToTemp();
- $temp->Load($id);
-
- $old_paths = $this->Application->RecallVar('old_paths');
- $old_paths = $old_paths ? unserialize($old_paths) : array();
- if ($old_paths[$id]) {
- $live_path = $old_paths[$id];
- }
- else {
- return;
- }
-
- $temp_path = $temp->GetField('Path');
- if ($temp_path !== $live_path) {
- $languages_count = ceil($this->Conn->GetOne('SELECT COUNT(*) FROM '.TABLE_PREFIX.'Language')/5)*5;
- $lang_parts = array();
- for ($i=1;$i<=$languages_count;$i++) {
- $lang_parts[] =
- 'l'.$i.'_Content =
- REPLACE(l'.$i.'_Content,
- '.$this->Conn->qstr($live_path).',
- '.$this->Conn->qstr($temp_path).')';
- }
- $query = 'UPDATE '.TABLE_PREFIX.'PageContent SET '.join(',', $lang_parts);
- $this->Conn->Query($query);
- }
- }
-
- /**
* Don't allow to delete system pages, when not in debug mode
*
* @param kEvent $event
@@ -1419,8 +1366,8 @@
$page_description = '';
if ($system) {
- $design_template = $template;
- $template_info = $this->_getTemplateInfo($template, $theme_id);
+ $design_template = strtolower($template);
+ $template_info = $this->_getTemplateInfo($design_template, $theme_id);
if ($template_info) {
if (array_key_exists('name', $template_info) && $template_info['name']) {
$page_name = $template_info['name'];
@@ -1448,7 +1395,6 @@
$object->Clear();
$object->SetDBField('ParentId', $page_category);
- $object->SetDBField('Filename', $system ? 'Content/' . $template : $template);
$object->SetDBField('IsSystem', $system);
@@ -1462,7 +1408,6 @@
// This way we can store CMS-blocks based on system template name on HDD no matter where it's location is
// and we can address him from template using his system path OR structure path (CMS-blocks should work too).
- $object->SetDBField('AutomaticFilename', 0);
$object->SetDBField('IsMenu', 0);
$object->SetDBField('ThemeId', $system ? $theme_id : 0);
$object->SetDBField('Priority', $min_priority - 1);
@@ -1495,40 +1440,37 @@
$object =& $this->Application->recallObject($this->Prefix . '.-item', null, Array ('skip_autoload' => true));
/* @var $object kDBItem */
- if (isset($theme_id)) {
- // extract system page from category path (if any)
- $template_path = $category_path;
- while (!$this->_templateFound(implode('/', $template_path), $theme_id) && $template_path) {
- array_pop($template_path);
- }
+ $parent_id = $base_category;
- if ($template_path) {
- $template = implode('/', $template_path);
- $object->Load( Array ('Filename' => 'Content/' . $template, 'ParentId' => $base_category, 'ThemeId' => $theme_id) );
- if (!$object->isLoaded()) {
- // force creating system page
- $this->_prepareAutoPage($object, $template, $theme_id, SMS_MODE_FORCE);
- }
+ $filenames_helper =& $this->Application->recallObject('FilenamesHelper');
+ /* @var $filenames_helper kFilenamesHelper */
- $category_path = array_slice($category_path, count($template_path));
+ $safe_category_path = array_map(Array (&$filenames_helper, 'replaceSequences'), $category_path);
- return $this->_getParentCategoryFromPath($category_path, $object->GetID());
- }
- }
-
- $parent_id = $base_category;
-
foreach ($category_path as $category_order => $category_name) {
$this->Application->SetVar('m_cat_id', $parent_id);
- $object->Load( Array ('Filename' => $category_name, 'ParentId' => $parent_id, 'ThemeId' => 0) );
- if ($object->isLoaded()) {
- // page found -> use it's id
- $parent_id = $object->GetID();
- }
- else {
- // page not found -> force creating virtual page
- if (!$this->_prepareAutoPage($object, $category_name, null, false)) {
+ // get virtual category first, when possible
+ $sql = 'SELECT ' . $object->IDField . '
+ FROM ' . $object->TableName . '
+ WHERE
+ (
+ Filename = ' . $this->Conn->qstr($safe_category_path[$category_order]) . ' OR
+ Filename = ' . $this->Conn->qstr( $filenames_helper->replaceSequences('_Auto: ' . $category_name) ) . '
+ ) AND
+ (ParentId = ' . $parent_id . ') AND
+ (ThemeId = 0 OR ThemeId = ' . $theme_id . ')
+ ORDER BY ThemeId ASC';
+ $parent_id = $this->Conn->GetOne($sql);
+
+ if ($parent_id === false) {
+ // page not found
+ $template = implode('/', array_slice($safe_category_path, 0, $category_order + 1));
+
+ // don't process system templates in sub-categories
+ $system = $this->_templateFound($template, $theme_id) && (strpos($template, '/') === false);
+
+ if (!$this->_prepareAutoPage($object, $category_name, $theme_id, $system ? SMS_MODE_FORCE : false)) {
// page was not created
break;
}
@@ -1563,6 +1505,12 @@
$template = 'theme:' . $this->_getThemeName($theme_id) . '/' . $template;
$template_file = $this->Application->TemplatesCache->GetRealFilename($template) . '.tpl';
+
+ if (!file_exists($template_file)) {
+ // when template without info it's placed in top category
+ return Array ();
+ }
+
$template_data = file_get_contents($template_file);
if (substr($template_data, 0, 6) == '