Index: branches/5.2.x/core/units/categories/categories_event_handler.php =================================================================== diff -u -r13840 -r14092 --- branches/5.2.x/core/units/categories/categories_event_handler.php (.../categories_event_handler.php) (revision 13840) +++ branches/5.2.x/core/units/categories/categories_event_handler.php (.../categories_event_handler.php) (revision 14092) @@ -1,6 +1,6 @@ Application->GetVar($event->getPrefixSpecial() . '_id'); - $home_category = $this->Application->findModule('Name', 'Core', 'RootCat'); + $home_category = $this->Application->getBaseCategory(); $this->Application->StoreVar('IsRootCategory_'.$this->Application->GetVar('m_wid'), ($category_id === '0') || ($category_id == $home_category)); @@ -291,7 +291,7 @@ if ("$parent_cat_id" == '0') { // replace "0" category with "Content" category id (this way template - $parent_cat_id = $this->Application->findModule('Name', 'Core', 'RootCat'); + $parent_cat_id = $this->Application->getBaseCategory(); } if ("$parent_cat_id" != 'any') { @@ -591,7 +591,7 @@ ( (NamedParentPath = ' . $this->Conn->qstr($template) . ') OR (NamedParentPath = ' . $this->Conn->qstr('Content/' . $template) . ') OR - (IsSystem = 1 AND CachedTemplate = ' . $this->Conn->qstr($template) . ') + (`Type` = ' . PAGE_TYPE_TEMPLATE . ' AND CachedTemplate = ' . $this->Conn->qstr($template) . ') ) AND (ThemeId = ' . $this->_getCurrentThemeId() . ' OR ThemeId = 0)'; $page_id = $this->Conn->GetOne($sql); @@ -602,7 +602,7 @@ if ($page_id === false && EDITING_MODE) { // create missing pages, when in editing mode - $object =& $this->Application->recallObject($this->Prefix . '.-new', null, Array('skip_autoload' => true)); + $object =& $this->Application->recallObject($this->Prefix . '.rebuild', null, Array('skip_autoload' => true)); /* @var $object kDBItem */ $created = $this->_prepareAutoPage($object, $template, null, SMS_MODE_AUTO, false); // create virtual (not system!) page @@ -758,7 +758,7 @@ // 2. preset template $category_id = $this->Application->GetVar('m_cat_id'); - $root_category = $this->Application->findModule('Name', 'Core', 'RootCat'); + $root_category = $this->Application->getBaseCategory(); if ($category_id == $root_category) { $object->SetDBField('Template', $this->_getDefaultDesign()); } @@ -1143,7 +1143,7 @@ $sql = 'SELECT ' . $id_field . ' FROM ' . $table_name . ' - WHERE ' . $id_field . ' IN (' . implode(',', $clipboard_data['copy']) . ') AND (IsSystem = 0) AND (ThemeId = 0)'; + WHERE ' . $id_field . ' IN (' . implode(',', $clipboard_data['copy']) . ') AND (`Type` = ' . PAGE_TYPE_VIRTUAL . ') AND (ThemeId = 0)'; $allowed_ids = $this->Conn->GetCol($sql); if (!$allowed_ids) { @@ -1405,29 +1405,21 @@ $ids = $this->StoreSelectedIDs($event); if ($ids) { + $propagate_category_status = $this->Application->GetVar('propagate_category_status'); $status_field = array_shift( $this->Application->getUnitOption($event->Prefix,'StatusField') ); foreach ($ids as $id) { $object->Load($id); + $object->SetDBField($status_field, $event->Name == 'OnMassApprove' ? 1 : 0); - switch ($event->Name) { - case 'OnMassApprove': - $object->SetDBField($status_field, 1); - break; - - case 'OnMassDecline': - $object->SetDBField($status_field, 0); - break; - } - - if ($this->Application->GetVar('propagate_category_status')) { - $sql = 'UPDATE '.$object->TableName.' - SET '.$status_field.' = '.$object->GetDBField($status_field).' - WHERE TreeLeft BETWEEN '.$object->GetDBField('TreeLeft').' AND '.$object->GetDBField('TreeRight'); - $this->Conn->Query($sql); - } - if ($object->Update()) { + if ($propagate_category_status) { + $sql = 'UPDATE '.$object->TableName.' + SET '.$status_field.' = '.$object->GetDBField($status_field).' + WHERE TreeLeft BETWEEN '.$object->GetDBField('TreeLeft').' AND '.$object->GetDBField('TreeRight'); + $this->Conn->Query($sql); + } + $event->status = erSUCCESS; $email_event = $event->Name == 'OnMassApprove' ? 'CATEGORY.APPROVE' : 'CATEGORY.DENY'; @@ -1515,7 +1507,17 @@ } } else { - $real_t = $this->_getDefaultDesign(); + $not_found = $this->Application->ConfigValue('ErrorTemplate'); + $real_t = $not_found ? $not_found : 'error_notfound'; + + $themes_helper =& $this->Application->recallObject('ThemesHelper'); + /* @var $themes_helper kThemesHelper */ + + $theme_id = $this->Application->GetVar('m_theme'); + $category_id = $themes_helper->getPageByTemplate($real_t, $theme_id); + $this->Application->SetVar('m_cat_id', $category_id); + + header('HTTP/1.0 404 Not Found'); } // replace alias in form #alias_name# to actual template used in this theme @@ -1558,6 +1560,18 @@ $now = adodb_mktime(); + if ( !$this->Application->isDebugMode() && strpos($event->Special, 'rebuild') === false ) { + $object->SetDBField('Type', $object->GetOriginalField('Type')); + $object->SetDBField('Protected', $object->GetOriginalField('Protected')); + + if ( $object->GetDBField('Protected') ) { + // some fields are read-only for protected pages, when debug mode is off + $object->SetDBField('AutomaticFilename', $object->GetOriginalField('AutomaticFilename')); + $object->SetDBField('Filename', $object->GetOriginalField('Filename')); + $object->SetDBField('Status', $object->GetOriginalField('Status')); + } + } + if ($object->GetChangedFields()) { $object->SetDBField('Modified_date', $now); $object->SetDBField('Modified_time', $now); @@ -1566,7 +1580,7 @@ $object->setRequired('PageCacheKey', $object->GetDBField('OverridePageCacheKey')); $object->SetDBField('Template', $this->_stripTemplateExtension( $object->GetDBField('Template') )); - if ($object->GetDBField('IsSystem') == 1) { + if ($object->GetDBField('Type') == PAGE_TYPE_TEMPLATE) { if (!$this->_templateFound($object->GetDBField('Template'), $object->GetDBField('ThemeId'))) { $object->SetError('Template', 'template_file_missing', 'la_error_TemplateFileMissing'); } @@ -1575,7 +1589,7 @@ $this->_saveTitleField($object, 'Title'); $this->_saveTitleField($object, 'MenuTitle'); - $root_category = $this->Application->findModule('Name', 'Core', 'RootCat'); + $root_category = $this->Application->getBaseCategory(); if (($object->GetDBField('ParentId') == $root_category) && ($object->GetDBField('Template') == CATEGORY_TEMPLATE_INHERIT)) { $object->SetError('Template', 'no_inherit'); @@ -1626,7 +1640,8 @@ function OnBeforeItemDelete(&$event) { $object =& $event->getObject(); - if ($object->GetDBField('IsSystem') && !$this->Application->isDebugMode()) { + + if ( $object->GetDBField('Protected') && !$this->Application->isDebugMode() ) { $event->status = erFAIL; } } @@ -1642,13 +1657,13 @@ $template = $this->_stripTemplateExtension($template); if ($system_mode == SMS_MODE_AUTO) { - $system = $this->_templateFound($template, $theme_id) ? 1 : 0; + $page_type = $this->_templateFound($template, $theme_id) ? PAGE_TYPE_TEMPLATE : PAGE_TYPE_VIRTUAL; } else { - $system = $system_mode == SMS_MODE_FORCE ? 1 : 0; + $page_type = $system_mode == SMS_MODE_FORCE ? PAGE_TYPE_TEMPLATE : PAGE_TYPE_VIRTUAL; } - if ($system && $template_info === false) { + if (($page_type == PAGE_TYPE_TEMPLATE) && ($template_info === false)) { // do not autocreate system pages, when browsing through site return false; } @@ -1657,25 +1672,25 @@ $theme_id = $this->_getCurrentThemeId(); } - $root_category = $this->Application->findModule('Name', 'Core', 'RootCat'); + $root_category = $this->Application->getBaseCategory(); $page_category = $this->Application->GetVar('m_cat_id'); if (!$page_category) { $page_category = $root_category; $this->Application->SetVar('m_cat_id', $page_category); } - if (!$system && strpos($template, '/') !== false) { + if (($page_type == PAGE_TYPE_VIRTUAL) && (strpos($template, '/') !== false)) { // virtual page, but have "/" in template path -> create it's path $category_path = explode('/', $template); $template = array_pop($category_path); $page_category = $this->_getParentCategoryFromPath($category_path, $root_category, $theme_id); } - $page_name = $system ? '_Auto: ' . $template : $template; + $page_name = ($page_type == PAGE_TYPE_TEMPLATE) ? '_Auto: ' . $template : $template; $page_description = ''; - if ($system) { + if ($page_type == PAGE_TYPE_TEMPLATE) { $design_template = strtolower($template); // leading "/" not added ! if ($template_info) { if (array_key_exists('name', $template_info) && $template_info['name']) { @@ -1698,10 +1713,11 @@ $object->Clear(); $object->SetDBField('ParentId', $page_category); - $object->SetDBField('IsSystem', $system); + $object->SetDBField('Type', $page_type); + $object->SetDBField('Protected', 1); // $page_type == PAGE_TYPE_TEMPLATE $object->SetDBField('IsMenu', 0); - $object->SetDBField('ThemeId', $theme_id); // $system ? $theme_id : 0 + $object->SetDBField('ThemeId', $theme_id); // put all templates to then end of list (in their category) $min_priority = $this->_getNextPriority($page_category, $object->TableName); @@ -1734,7 +1750,7 @@ $backup_category_id = $this->Application->GetVar('m_cat_id'); - $object =& $this->Application->recallObject($this->Prefix . '.-item', null, Array ('skip_autoload' => true)); + $object =& $this->Application->recallObject($this->Prefix . '.rebuild-path', null, Array ('skip_autoload' => true)); /* @var $object kDBItem */ $parent_id = $base_category; @@ -1853,7 +1869,7 @@ $settings = $site_config_helper->getSettings(); - $root_category = $this->Application->findModule('Name', 'Core', 'RootCat'); + $root_category = $this->Application->getBaseCategory(); // set root category $section_ajustments = $this->Application->getUnitOption($event->Prefix, 'SectionAdjustments'); @@ -1907,7 +1923,7 @@ } else { // sort by parent path on Front-End only - $list_sortings = $this->Application->getUnitOption($event->Prefix, 'ListSortings'); + $list_sortings = $this->Application->getUnitOption($event->Prefix, 'ListSortings', Array ()); $list_sortings['']['ForcedSorting'] = Array ("CurrentSort" => 'asc'); $this->Application->setUnitOption($event->Prefix, 'ListSortings', $list_sortings); } @@ -2005,7 +2021,7 @@ set_time_limit(0); ini_set('memory_limit', -1); - $dummy =& $this->Application->recallObject($event->Prefix . '.-dummy', null, Array ('skip_autoload' => true)); + $dummy =& $this->Application->recallObject($event->Prefix . '.rebuild', null, Array ('skip_autoload' => true)); /* @var $dummy kDBItem */ $error_count = 0;