Index: branches/5.2.x/core/units/categories/categories_event_handler.php =================================================================== diff -u -r14572 -r14585 --- branches/5.2.x/core/units/categories/categories_event_handler.php (.../categories_event_handler.php) (revision 14572) +++ branches/5.2.x/core/units/categories/categories_event_handler.php (.../categories_event_handler.php) (revision 14585) @@ -1,6 +1,6 @@ finalizePermissionCheck($event, $perm_value); } + if ($event->Name == 'OnRecalculatePriorities') { + $perm_helper =& $this->Application->recallObject('PermissionsHelper'); + /* @var $perm_helper kPermissionsHelper */ + + $category_id = $this->Application->GetVar('m_cat_id'); + + return $perm_helper->AddCheckPermission($category_id, $event->Prefix) || $perm_helper->ModifyCheckPermission(0, $category_id, $event->Prefix); + } + if ($event->Name == 'OnPasteClipboard') { // forces permission check to work by current category for "Paste In Category" operation $category_id = $this->Application->GetVar('m_cat_id'); @@ -219,6 +228,11 @@ $this->Application->StoreVar('IsRootCategory_'.$this->Application->GetVar('m_wid'), ($category_id === '0') || ($category_id == $home_category)); parent::OnEdit($event); + + if ($event->status == erSUCCESS) { + // keep "Section Properties" link (in browse modes) clean + $this->Application->DeleteVar('admin'); + } } /** @@ -502,22 +516,20 @@ $search_event = $event_mapping[$type]; $this->$search_event($event); - $search_table = TABLE_PREFIX.'ses_'.$this->Application->GetSID().'_'.TABLE_PREFIX.'Search'; - $sql = 'SHOW TABLES LIKE "'.$search_table.'"'; + $object =& $event->getObject(); + /* @var $object kDBList */ - if ($this->Conn->Query($sql)) { - $search_res_ids = $this->Conn->GetCol('SELECT ResourceId FROM '.$search_table); - } + $search_sql = ' FROM ' . TABLE_PREFIX . 'ses_' . $this->Application->GetSID() . '_' . TABLE_PREFIX . 'Search + search_result LEFT JOIN %1$s ON %1$s.ResourceId = search_result.ResourceId'; + $sql = str_replace('FROM %1$s', $search_sql, $object->SelectClause); - if (isset($search_res_ids) && $search_res_ids) { - $type_clauses['search']['include'] = '%1$s.ResourceId IN ('.implode(',', $search_res_ids).')'; - $type_clauses['search']['except'] = '%1$s.ResourceId NOT IN ('.implode(',', $search_res_ids).')'; - } - else { - $type_clauses['search']['include'] = '0'; - $type_clauses['search']['except'] = '1'; - } + $object->SetSelectSQL($sql); + $object->addCalculatedField('Relevance', 'search_result.Relevance'); + $object->AddOrderField('search_result.Relevance', 'desc', true); + + $type_clauses['search']['include'] = '1'; + $type_clauses['search']['except'] = '0'; $type_clauses['search']['having_filter'] = false; } @@ -1603,11 +1615,12 @@ $root_category = $this->Application->getBaseCategory(); - if (($object->GetDBField('ParentId') == $root_category) && ($object->GetDBField('Template') == CATEGORY_TEMPLATE_INHERIT)) { + if ( file_exists(FULL_PATH . '/themes') && ($object->GetDBField('ParentId') == $root_category) && ($object->GetDBField('Template') == CATEGORY_TEMPLATE_INHERIT) ) { + // there are themes + creating top level category $object->SetError('Template', 'no_inherit'); } - if (!$this->Application->isAdminUser) { + if ( !$this->Application->isAdminUser && $object->isVirtualField('cust_RssSource') ) { // only administrator can set/change "cust_RssSource" field if ($object->GetDBField('cust_RssSource') != $object->GetOriginalField('cust_RssSource')) { @@ -2326,9 +2339,9 @@ } } - $where_clause = '(' . implode(') OR (', $where_clause) . ')'; + $where_clause = '((' . implode(') OR (', $where_clause) . '))'; // 2 braces for next clauses, see below! - $where_clause = $where_clause.' AND '.$items_table.'.Status=1'; + $where_clause = $where_clause . ' AND (' . $items_table . '.Status = ' . STATUS_ACTIVE . ')'; if ($event->MasterEvent && $event->MasterEvent->Name == 'OnListBuild') { if ($event->MasterEvent->getEventParam('ResultIds')) { @@ -2358,6 +2371,14 @@ $config_elem = $search_config[ $map_key ]; $weight = $config_elem['Priority']; + + // search by whole words only ([[:<:]] - word boundary) + /*$revelance_parts[] = 'IF('.$field.' REGEXP "[[:<:]]('.implode(' ', $positive_words).')[[:>:]]", '.$weight.', 0)'; + foreach ($positive_words as $keyword) { + $revelance_parts[] = 'IF('.$field.' REGEXP "[[:<:]]('.$keyword.')[[:>:]]", '.$weight.', 0)'; + }*/ + + // search by partial word matches too $revelance_parts[] = 'IF('.$field.' LIKE "%'.implode(' ', $positive_words).'%", '.$weight_sum.', 0)'; foreach ($positive_words as $keyword) { $revelance_parts[] = 'IF('.$field.' LIKE "%'.$keyword.'%", '.$weight.', 0)'; @@ -2404,9 +2425,16 @@ FROM '.$object->TableName.' '.implode(' ', $join_clauses).' WHERE '.$where_clause.' - GROUP BY '.$items_table.'.'.$this->Application->getUnitOption($event->Prefix, 'IDField'); + GROUP BY '.$items_table.'.'.$this->Application->getUnitOption($event->Prefix, 'IDField').' ORDER BY Relevance DESC'; $res = $this->Conn->Query($sql); + + if ( !$search_table_exists ) { + $sql = 'ALTER TABLE ' . $search_table . ' + ADD INDEX (ResourceId), + ADD INDEX (Relevance)'; + $this->Conn->Query($sql); + } } /**