Index: branches/RC/core/units/categories/categories_event_handler.php =================================================================== diff -u -N -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) == '