Index: trunk/core/units/general/cat_tag_processor.php =================================================================== diff -u -N --- trunk/core/units/general/cat_tag_processor.php (revision 8771) +++ trunk/core/units/general/cat_tag_processor.php (revision 0) @@ -1,463 +0,0 @@ -PermHelper = $this->Application->recallObject('PermissionsHelper'); - } - - function ItemIcon($params) - { - $object =& $this->Application->recallObject($this->getPrefixSpecial(),$this->Prefix, $params); - - $grids = $this->Application->getUnitOption($this->Prefix,'Grids'); - $icons =& $grids[ $params['grid'] ]['Icons']; - - $status_fields = $this->Application->getUnitOption($this->Prefix,'StatusField'); - if (!$status_fields) return $icons['default']; - - $value = $object->GetDBField($status_fields[0]); // sets base status icon - /* @var $object kDBItem */ - if ($value == STATUS_ACTIVE) { - if( $object->HasField('IsPop') && $object->GetDBField('IsPop') ) $value = 'POP'; - if( $object->HasField('IsHot') && $object->GetDBField('IsHot') ) $value = 'HOT'; - if( $object->HasField('IsNew') && $object->GetDBField('IsNew') ) $value = 'NEW'; - if( $object->HasField('EditorsPick') && $object->GetDBField('EditorsPick') ) $value = 'PICK'; - } - - return isset($icons[$value]) ? $icons[$value] : $icons['default']; - } - - /** - * Allows to create valid mod-rewrite compatible link to module item - * - * @param Array $params - * @param string $id_prefix - * @return string - */ - function ItemLink($params, $id_prefix = null) - { - $params = array_merge($params, Array('pass' => 'm,'.$this->Prefix) ); - - $item_id = isset($params[$id_prefix.'_id']) && $params[$id_prefix.'_id']; - if (!$item_id) { - $item_id = $this->Application->GetVar($this->getPrefixSpecial().'_id'); - if (!$item_id) { - $item_id = $this->Application->GetVar($this->Prefix.'_id'); - } - } - $params[$this->Prefix.'_id'] = $item_id; - - $object =& $this->getObject($params); - $params['m_cat_id'] = $object->GetDBField('CategoryId'); - $params['pass_category'] = 1; - - return $this->Application->ProcessParsedTag('m', 't', $params); - } - - function CategoryPath($params) - { - if ($this->Application->IsAdmin()) { - // path for module root category in admin - if (!isset($params['cat_id'])) { - $params['cat_id'] = $this->Application->RecallVar($params['session_var'], 0); - } - } - else { - // path for category item category in front-end - $object =& $this->getObject($params); - $params['cat_id'] = $object->GetDBField('CategoryId'); - } - - return $this->Application->ProcessParsedTag('c', 'CategoryPath', $params); - } - - function BuildListSpecial($params) - { - if ($this->Special != '') return $this->Special; - if ( isset($params['parent_cat_id']) ) { - $parent_cat_id = $params['parent_cat_id']; - } - else { - $parent_cat_id = $this->Application->GetVar('c_id'); - if (!$parent_cat_id) { - $parent_cat_id = $this->Application->GetVar('m_cat_id'); - } - } - - $recursive = isset($params['recursive']); - - $types = $this->SelectParam($params, 'types'); - $except = $this->SelectParam($params, 'except'); - - if ($types.$except.$recursive == '') { - return parent::BuildListSpecial($params); - } - - $special = crc32($parent_cat_id.$types.$except.$recursive); - return $special; - } - - function CatalogItemCount($params) - { - $object =& $this->GetList($params); - if (!$object->Counted) { - $object->CountRecs(); - } - return $object->NoFilterCount != $object->RecordsCount ? $object->RecordsCount.' / '.$object->NoFilterCount : $object->RecordsCount; - } - - function ListReviews($params) - { - $prefix = $this->Prefix.'-rev'; - $review_tag_processor =& $this->Application->recallObject($prefix.'.item_TagProcessor'); - return $review_tag_processor->PrintList($params); - } - - function ReviewCount($params) - { - $review_tag_processor =& $this->Application->recallObject('rev.item_TagProcessor'); - return $review_tag_processor->TotalRecords($params); - } - - function InitCatalogTab($params) - { - $tab_params['mode'] = $this->Application->GetVar('tm'); // single/multi selection possible - $tab_params['special'] = $this->Application->GetVar('ts'); // use special for this tab - $tab_params['dependant'] = $this->Application->GetVar('td'); // is grid dependant on categories grid - - // set default params (same as in catalog) - if ($tab_params['mode'] === false) $tab_params['mode'] = 'multi'; - if ($tab_params['special'] === false) $tab_params['special'] = ''; - if ($tab_params['dependant'] === false) $tab_params['dependant'] = 'yes'; - - // pass params to block with tab content - $params['name'] = $params['render_as']; - $params['prefix'] = trim($this->Prefix.'.'.($tab_params['special'] ? $tab_params['special'] : $this->Special), '.'); - $params['cat_prefix'] = trim('c.'.($tab_params['special'] ? $tab_params['special'] : $this->Special), '.'); - $params['tab_mode'] = $tab_params['mode']; - $params['tab_dependant'] = $tab_params['dependant']; - $params['show_category'] = $tab_params['special'] == 'showall' ? 1 : 0; // this is advanced view -> show category name - - return $this->Application->ParseBlock($params, 1); - } - - /** - * Show CachedNavbar of current item primary category - * - * @param Array $params - * @return string - */ - function CategoryName($params) - { - // show category cachednavbar of - $object =& $this->getObject($params); - $category_id = isset($params['cat_id']) ? $params['cat_id'] : $object->GetDBField('CategoryId'); - - $category_path = $this->Application->getCache('category_paths', $category_id); - if ($category_path === false) { - // not chached - if ($category_id > 0) { - $category_path = trim($this->CategoryName( Array('cat_id' => 0) ).' > '.str_replace('&|&', ' > ', $object->GetDBField('CachedNavbar')), ' > '); - } - else { - $category_path = $this->Application->Phrase( $this->Application->ConfigValue('Root_Name') ); - } - $this->Application->setCache('category_paths', $category_id, $category_path); - } - return $category_path; - } - - /** - * Allows to determine if original value should be shown - * - * @param Array $params - * @return bool - */ - function DisplayOriginal($params) - { - // original id found & greather then zero + show original - $display_original = isset($params['display_original']) && $params['display_original']; - - $owner_field = $this->Application->getUnitOption($this->Prefix, 'OwnerField'); - if (!$owner_field) { - $owner_field = 'CreatedById'; - } - - $object =& $this->getObject($params); - $perm_value = $this->PermHelper->ModifyCheckPermission($object->GetDBField($owner_field), $object->GetDBField('CategoryId'), $this->Prefix); - - return $display_original && ($perm_value == 1) && $this->Application->GetVar($this->Prefix.'.original_id'); - } - - /** - * Checks if user have one of required permissions - * - * @param Array $params - * @return bool - */ - function HasPermission($params) - { - $perm_helper =& $this->Application->recallObject('PermissionsHelper'); - /* @var $perm_helper kPermissionsHelper */ - - $params['raise_warnings'] = 0; - $object =& $this->getObject($params); - /* @var $object kCatDBItem */ - - // 1. category restriction - $params['cat_id'] = $object->isLoaded() ? $object->GetDBField('ParentPath') : $this->Application->GetVar('m_cat_id'); - - // 2. owner restriction - $owner_field = $this->Application->getUnitOption($this->Prefix, 'OwnerField'); - if (!$owner_field) { - $owner_field = 'CreatedById'; - } - $is_owner = $object->GetDBField($owner_field) == $this->Application->RecallVar('user_id'); - - return $perm_helper->TagPermissionCheck($params, $is_owner); - } - - /** - * Creates link to current category or to module root category, when current category is home - * - * @param Array $params - * @return string - */ - function SuggestItemLink($params) - { - if (!isset($params['cat_id'])) { - $params['cat_id'] = $this->Application->GetVar('m_cat_id'); - } - - if ($params['cat_id'] == 0) { - $params['cat_id'] = $this->Application->findModule('Var', $this->Prefix, 'RootCat'); - } - - return $this->Application->ProcessParsedTag('c', 'CategoryLink', $params); - } - - /** - * Allows to detect if item has any additional images available - * - * @param Array $params - * @return string - */ - function HasAdditionalImages($params) - { - $object =& $this->getObject($params); - $sql = 'SELECT ImageId - FROM '.$this->Application->getUnitOption('img', 'TableName').' - WHERE ResourceId = '.$object->GetDBField('ResourceId').' AND DefaultImg != 1 AND Enabled = 1'; - return $this->Conn->GetOne($sql) ? 1 : 0; - } - - /** - * Checks that item is pending - * - * @param Array $params - * @return bool - */ - function IsPending($params) - { - $object =& $this->getObject($params); - - $pending_status = Array (STATUS_PENDING, STATUS_PENDING_EDITING); - return in_array($object->GetDBField('Status'), $pending_status); - } - - function IsFavorite($params) - { - static $favorite_status = Array (); - - $object =& $this->getObject($params); - /* @var $object kDBList */ - - if (!isset($favorite_status[$this->Special])) { - $resource_ids = $object->GetCol('ResourceId'); - - $user_id = $this->Application->RecallVar('user_id'); - $sql = 'SELECT FavoriteId, ResourceId - FROM '.$this->Application->getUnitOption('fav', 'TableName').' - WHERE (PortalUserId = '.$user_id.') AND (ResourceId IN ('.implode(',', $resource_ids).'))'; - $favorite_status[$this->Special] = $this->Conn->GetCol($sql, 'ResourceId'); - } - - return isset($favorite_status[$this->Special][$object->GetDBField('ResourceId')]); - } - - /** - * Returns item's editors pick status (using not formatted value) - * - * @param Array $params - * @return bool - */ - function IsEditorsPick($params) - { - $object =& $this->getObject($params); - - return $object->GetDBField('EditorsPick') == 1; - } - - function FavoriteToggleLink($params) - { - $fav_prefix = $this->Prefix.'-fav'; - $params['pass'] = implode(',', Array('m', $this->Prefix, $fav_prefix)); - $params[$fav_prefix.'_event'] = 'OnFavoriteToggle'; - return $this->Application->ProcessParsedTag('m', 'Link', $params); - } - - /** - * Checks if item is passed in url - * - * @param Array $params - * @return bool - */ - function ItemAvailable($params) - { - return $this->Application->GetVar($this->getPrefixSpecial().'_id') > 0; - } - - function SortingSelected($params) - { - $list =& $this->GetList($params); - $user_sorting_start = $this->getUserSortIndex(); - - $sorting = strtolower($list->GetOrderField($user_sorting_start).'|'.$list->GetOrderDirection($user_sorting_start)); - - if ($sorting == strtolower($params['sorting'])) return $params['selected']; - } - - function CombinedSortingDropDownName($params) - { - return $this->Prefix.'_CombinedSorting'; - } - - /** - * Prepares name for field with event in it (used only on front-end) - * - * @param Array $params - * @return string - */ - function SubmitName($params) - { - return 'events['.$this->Prefix.']['.$params['event'].']'; - } - - /** - * Returns prefix + any word (used for shared between categories per page settings) - * - * @param Array $params - * @return string - */ - function VarName($params) - { - return $this->Prefix.'_'.$params['type']; - } - - /** - * Checks if we are viewing module root category - * - * @param Array $params - * @return bool - */ - function IsModuleHome($params) - { - $root_category = $this->Application->findModule('Var', $this->Prefix, 'RootCat'); - - return $root_category == $this->Application->GetVar('m_cat_id'); - } - - /** - * Dynamic votes indicator - * - * @param Array $params - * - * @return string - */ - function VotesIndicator($params) - { - $blocks_params = $this->prepareTagParams($params); - $blocks_params['name'] = $params['render_as']; - - $object =& $this->getObject($params); - /* @var $object kDBItem */ - - if ($this->Application->ConfigValue('UseFloatRating')) { - $rating = $object->GetDBField('CachedRating'); - $float_rating = floor(($rating - floor($rating)) / 0.25) * 0.25; - } - else { - $rating = round( $object->GetDBField('CachedRating') ); - $float_rating = 0; - } - - $i = 1; - $ret = ''; - while ($i <= 5) { - $blocks_params['number'] = $i; - $blocks_params['active'] = $rating >= $i ? 1 : 0; - - if ($rating > $i - 1 && $rating < $i && $float_rating > 0) { - $blocks_params['active'] = 1; - $blocks_params['float_rating'] = $float_rating; - } - else { - $blocks_params['float_rating'] = ''; - } - - $ret .= trim($this->Application->ParseBlock($blocks_params)); - $i++; - } - - return $ret; - } - - function RelevanceIndicator($params) - { - $object =& $this->getObject($params); - - $search_results_table = TABLE_PREFIX.'ses_'.$this->Application->GetSID().'_'.TABLE_PREFIX.'Search'; - $sql = 'SELECT Relevance - FROM '.$search_results_table.' - WHERE ResourceId = '.$object->GetDBField('ResourceId'); - - $percents_off = (int)(100 - (100 * $this->Conn->GetOne($sql))); - $percents_off = ($percents_off < 0) ? 0 : $percents_off; - if ($percents_off) { - $params['percent_off'] = $percents_off; - $params['percent_on'] = 100 - $percents_off; - $params['name'] = $this->SelectParam($params, 'relevance_normal_render_as,block_relevance_normal'); - } - else { - $params['name'] = $this->SelectParam($params, 'relevance_full_render_as,block_relevance_full'); - } - return $this->Application->ParseBlock($params); - } - - function SearchResultField($params) - { - $ret = $this->Field($params); - - $keywords = unserialize( $this->Application->RecallVar('highlight_keywords') ); - $opening = $this->Application->ParseBlock( Array('name' => $this->SelectParam($params, 'highlight_opening_render_as,block_highlight_opening')) ); - $closing = $this->Application->ParseBlock( Array('name' => $this->SelectParam($params, 'highlight_closing_render_as,block_highlight_closing')) ); - - foreach ($keywords as $index => $keyword) { - $keywords[$index] = preg_quote($keyword, '/'); - } - - return preg_replace('/('.implode('|', $keywords).')/i', $opening.'\\1'.$closing, $ret); - } - } - -?> \ No newline at end of file