Index: kernel/db/cat_event_handler.php =================================================================== --- kernel/db/cat_event_handler.php (revision 13152) +++ kernel/db/cat_event_handler.php (working copy) @@ -1737,64 +1737,67 @@ */ function SetPagination(&$event) { + $object =& $event->getObject(); + /* @var $object kDBList */ + // get PerPage (forced -> session -> config -> 10) - $per_page = $this->getPerPage($event); + $object->SetPerPage( $this->getPerPage($event) ); + // main lists on Front-End have special get parameter for page + $page = $object->mainList ? $this->Application->GetVar('page') : false; - $object =& $event->getObject(); - $object->SetPerPage($per_page); - $this->Application->StoreVarDefault($event->getPrefixSpecial().'_Page', 1, true); // true for optional + if (!$page) { + // page is given in "env" variable for given prefix + $page = $this->Application->GetVar($event->getPrefixSpecial() . '_Page'); + } - $page = $this->Application->GetVar($event->getPrefixSpecial().'_Page'); - if (!$page) - { - $page = $this->Application->GetVar($event->getPrefixSpecial(true).'_Page'); + if (!$page && $event->Special) { + // when not part of env, then variables like "prefix.special_Page" are + // replaced (by PHP) with "prefix_special_Page", so check for that too + $page = $this->Application->GetVar($event->getPrefixSpecial(true) . '_Page'); } - if (!$page) - { - if( $this->Application->RewriteURLs() ) - { - $page = $this->Application->GetVar($event->Prefix.'_Page'); - if (!$page) - { - $page = $this->Application->RecallVar($event->Prefix.'_Page'); + if (!$object->mainList) { + // main lists doesn't use session for page storing + $this->Application->StoreVarDefault($event->getPrefixSpecial() . '_Page', 1, true); // true for optional + + if (!$page) { + if ($this->Application->RewriteURLs()) { + // when page not found by prefix+special, then try to search it without special at all + $page = $this->Application->GetVar($event->Prefix . '_Page'); + + if (!$page) { + // page not found in request -> get from session + $page = $this->Application->RecallVar($event->Prefix . '_Page'); + } + + if ($page) { + // page found in request -> store in session + $this->Application->StoreVar($event->getPrefixSpecial() . '_Page', $page, true); //true for optional + } } - if($page) $this->Application->StoreVar($event->getPrefixSpecial().'_Page', $page, true); //true for optional + else { + // page not found in request -> get from session + $page = $this->Application->RecallVar($event->getPrefixSpecial() . '_Page'); + } } - else - { - $page = $this->Application->RecallVar($event->getPrefixSpecial().'_Page'); + else { + // page found in request -> store in session + $this->Application->StoreVar($event->getPrefixSpecial() . '_Page', $page, true); //true for optional } - } - else { - $this->Application->StoreVar($event->getPrefixSpecial().'_Page', $page, true); //true for optional - } - if( !$event->getEventParam('skip_counting') ) - { - $pages = $object->GetTotalPages(); - if($page > $pages) - { - $this->Application->StoreVar($event->getPrefixSpecial().'_Page', 1); - $page = 1; + if ( !$event->getEventParam('skip_counting') ) { + // when stored page is larger, then maximal list page number + // (such case is also processed in kDBList::Query method) + $pages = $object->GetTotalPages(); + + if ($page > $pages) { + $page = 1; + $this->Application->StoreVar($event->getPrefixSpecial().'_Page', 1, true); + } } } - /*$cur_per_page = $per_page; - $per_page = $event->getEventParam('per_page'); - if ($per_page == 'list_next') { - - $cur_page = $page; - - $object =& $this->Application->recallObject($event->Prefix); - $object->SetPerPage(1); - $cur_item_index = $object->CurrentIndex; - - $page = ($cur_page-1) * $cur_per_page + $cur_item_index + 1; - $object->SetPerPage(1); - }*/ - $object->SetPage($page); } Index: kernel/db/cat_tag_processor.php =================================================================== --- kernel/db/cat_tag_processor.php (revision 13152) +++ kernel/db/cat_tag_processor.php (working copy) @@ -430,7 +430,13 @@ function CombinedSortingDropDownName($params) { - return $this->Prefix.'_CombinedSorting'; + $list =& $this->GetList($params); + + if ($list->mainList) { + return parent::CombinedSortingDropDownName($params); + } + + return $list->Prefix . '_CombinedSorting'; } /** @@ -441,7 +447,13 @@ */ function SubmitName($params) { - return 'events['.$this->Prefix.']['.$params['event'].']'; + $list =& $this->GetList($params); + + if ($list->mainList) { + return parent::SubmitName($params); + } + + return 'events[' . $list->Prefix . '][' . $params['event'] . ']'; } /** @@ -452,7 +464,13 @@ */ function VarName($params) { - return $this->Prefix.'_'.$params['type']; + $list =& $this->GetList($params); + + if ($list->mainList) { + return parent::VarName($params); + } + + return $list->Prefix . '_' . $params['type']; } /** Index: kernel/db/db_event_handler.php =================================================================== --- kernel/db/db_event_handler.php (revision 13152) +++ kernel/db/db_event_handler.php (working copy) @@ -638,6 +638,14 @@ $this->dbBuild($object,$event); + if (!$object->mainList && $event->getEventParam('main_list')) { + // once list is set to main, then even "requery" parameter can't remove that + /*$passed = $this->Application->GetVar('passed'); + $this->Application->SetVar('passed', $passed . ',' . $event->Prefix);*/ + + $object->mainList = true; + } + $sql = $this->ListPrepareQuery($event); $sql = $this->Application->ReplaceLanguageTags($sql); $object->setSelectSQL($sql); @@ -704,11 +712,20 @@ */ function OnSetPerPage(&$event) { - $per_page = $this->Application->GetVar($event->getPrefixSpecial(true).'_PerPage'); - $this->Application->StoreVar($event->getPrefixSpecial().'_PerPage', $per_page); + $per_page = $this->Application->GetVar($event->getPrefixSpecial(true) . '_PerPage'); + $event->SetRedirectParam($event->getPrefixSpecial() . '_PerPage', $per_page); + $event->SetRedirectParam('pass', 'm,' . $event->getPrefixSpecial()); - $view_name = $this->Application->RecallVar($event->getPrefixSpecial().'_current_view'); - $this->Application->StorePersistentVar($event->getPrefixSpecial().'_PerPage.'.$view_name, $per_page); + if (!$this->Application->isAdminUser) { + $list_helper =& $this->Application->recallObject('ListHelper'); + /* @var $list_helper ListHelper */ + + $this->_passListParams($event, 'per_page'); + + if ($per_page != $list_helper->getDefaultPerPage($event->Prefix)) { + $event->SetRedirectParam('per_page', $per_page); + } + } } /** @@ -719,10 +736,63 @@ function OnSetPage(&$event) { $page = $this->Application->GetVar($event->getPrefixSpecial(true) . '_Page'); - $event->SetRedirectParam($event->getPrefixSpecial().'_Page', $page); + $event->SetRedirectParam($event->getPrefixSpecial() . '_Page', $page); + $event->SetRedirectParam('pass', 'm,' . $event->getPrefixSpecial()); + + if (!$this->Application->isAdminUser) { + if ($page > 1) { + $event->SetRedirectParam('page', $page); + } + + $this->_passListParams($event, 'page'); + } } /** + * Passes through main list pagination and sorting + * + * @param kEvent $event + * @param string $skip_var + */ + function _passListParams(&$event, $skip_var) + { + $param_names = array_diff(Array ('page', 'per_page', 'sort_by'), Array ($skip_var)); + + $list_helper =& $this->Application->recallObject('ListHelper'); + /* @var $list_helper ListHelper */ + + foreach ($param_names as $param_name) { + $value = $this->Application->GetVar($param_name); + + switch ($param_name) { + case 'page': + if ($value > 1) { + $event->SetRedirectParam('page', $value); + } + break; + + case 'per_page': + if ($value > 0) { + if ($value != $list_helper->getDefaultPerPage($event->Prefix)) { + $event->SetRedirectParam('per_page', $value); + } + } + break; + + case 'sort_by': + $event->setPseudoClass('_List'); + $object =& $event->getObject( Array ('main_list' => 1) ); + /* @var $object kDBList */ + + if ($list_helper->hasUserSorting($object)) { + $event->SetRedirectParam('sort_by', $value); + } + break; + } + } + } + + /** * Set's correct page for list * based on data provided with event * @@ -732,49 +802,51 @@ */ function SetPagination(&$event) { + $object =& $event->getObject(); + /* @var $object kDBList */ + // get PerPage (forced -> session -> config -> 10) - $per_page = $this->getPerPage($event); + $object->SetPerPage( $this->getPerPage($event) ); - $object =& $event->getObject(); - $object->SetPerPage($per_page); - $this->Application->StoreVarDefault($event->getPrefixSpecial().'_Page', 1, true); // true for optional + // main lists on Front-End have special get parameter for page + $page = $object->mainList ? $this->Application->GetVar('page') : false; - $page = $this->Application->GetVar($event->getPrefixSpecial().'_Page'); if (!$page) { - $page = $this->Application->GetVar($event->getPrefixSpecial(true).'_Page'); + // page is given in "env" variable for given prefix + $page = $this->Application->GetVar($event->getPrefixSpecial() . '_Page'); } - if (!$page) { - $page = $this->Application->RecallVar($event->getPrefixSpecial().'_Page'); - } - else { - $this->Application->StoreVar($event->getPrefixSpecial().'_Page', $page); - } - if( !$event->getEventParam('skip_counting') ) - { - $pages = $object->GetTotalPages(); - if($page > $pages) - { - $this->Application->StoreVar($event->getPrefixSpecial().'_Page', 1); - $page = 1; - } + if (!$page && $event->Special) { + // when not part of env, then variables like "prefix.special_Page" are + // replaced (by PHP) with "prefix_special_Page", so check for that too + $page = $this->Application->GetVar($event->getPrefixSpecial(true) . '_Page'); } - /*$per_page = $event->getEventParam('per_page'); - if ($per_page == 'list_next') { + if (!$object->mainList) { + // main lists doesn't use session for page storing + $this->Application->StoreVarDefault($event->getPrefixSpecial() . '_Page', 1, true); // true for optional - $cur_page = $page; - $cur_per_page = $per_page; + if ($page) { + // page found in request -> store in session + $this->Application->StoreVar($event->getPrefixSpecial() . '_Page', $page, true); //true for optional + } + else { + // page not found in request -> get from session + $page = $this->Application->RecallVar($event->getPrefixSpecial() . '_Page'); + } - $object->SetPerPage(1); + if ( !$event->getEventParam('skip_counting') ) { + // when stored page is larger, then maximal list page number + // (such case is also processed in kDBList::Query method) + $pages = $object->GetTotalPages(); - $object =& $this->Application->recallObject($event->Prefix); - $cur_item_index = $object->CurrentIndex; + if ($page > $pages) { + $page = 1; + $this->Application->StoreVar($event->getPrefixSpecial() . '_Page', 1, true); + } + } + } - $page = ($cur_page-1) * $cur_per_page + $cur_item_index + 1; - $object->SetPerPage(1); - }*/ - $object->SetPage($page); } @@ -786,53 +858,84 @@ */ function getPerPage(&$event) { - // 1. per-page is passed as tag parameter to PrintList, InitList, etc. + $object =& $event->getObject(); + /* @var $object kDBList */ + $per_page = $event->getEventParam('per_page'); - /*if ($per_page == 'list_next') { - $per_page = ''; - }*/ + if ($per_page) { + // per-page is passed as tag parameter to PrintList, InitList, etc. + $config_mapping = $this->Application->getUnitOption($event->Prefix, 'ConfigMapping'); - // 2. per-page variable name is store into config variable - $config_mapping = $this->Application->getUnitOption($event->Prefix, 'ConfigMapping'); - if ($config_mapping) { - switch ( $per_page ){ - case 'short_list' : - $per_page = $this->Application->ConfigValue($config_mapping['ShortListPerPage']); - break; - case 'default' : - $per_page = $this->Application->ConfigValue($config_mapping['PerPage']); - break; + // 2. per-page setting is stored in configuration variable + if ($config_mapping) { + // such pseudo per-pages are only defined in templates directly + switch ($per_page) { + case 'short_list': + $per_page = $this->Application->ConfigValue($config_mapping['ShortListPerPage']); + break; + + case 'default': + $per_page = $this->Application->ConfigValue($config_mapping['PerPage']); + break; + } } + + return $per_page; } + if (!$per_page && $object->mainList) { + // main lists on Front-End have special get parameter for per-page + $per_page = $this->Application->GetVar('per_page'); + } + if (!$per_page) { - // per-page is stored to persistent session - $view_name = $this->Application->RecallVar($event->getPrefixSpecial().'_current_view'); + // per-page is given in "env" variable for given prefix + $per_page = $this->Application->GetVar($event->getPrefixSpecial() . '_PerPage'); + } - $storage_prefix = $event->getEventParam('same_special') ? $event->Prefix : $event->getPrefixSpecial(); - $per_page = $this->Application->RecallPersistentVar($storage_prefix.'_PerPage.'.$view_name, ALLOW_DEFAULT_SETTINGS); + if (!$per_page && $event->Special) { + // when not part of env, then variables like "prefix.special_PerPage" are + // replaced (by PHP) with "prefix_special_PerPage", so check for that too + $per_page = $this->Application->GetVar($event->getPrefixSpecial(true) . '_PerPage'); + } - if (!$per_page) { - // per-page is stored to current session - $per_page = $this->Application->RecallVar($storage_prefix.'_PerPage'); + if (!$object->mainList) { + // per-page given in env and not in main list + $view_name = $this->Application->RecallVar($event->getPrefixSpecial() . '_current_view'); + + if ($per_page) { + // per-page found in request -> store in session and persistent session + $this->Application->StoreVar($event->getPrefixSpecial() . '_PerPage', $per_page, true); //true for optional + $this->Application->StorePersistentVar($event->getPrefixSpecial() . '_PerPage.' . $view_name, $per_page); } + else { + // per-page not found in request -> get from pesistent session (or session) + $storage_prefix = $event->getEventParam('same_special') ? $event->Prefix : $event->getPrefixSpecial(); + $per_page = $this->Application->RecallPersistentVar($storage_prefix . '_PerPage.' . $view_name, ALLOW_DEFAULT_SETTINGS); - if (!$per_page) { - if ($config_mapping) { - if (!isset($config_mapping['PerPage'])) { - trigger_error('Incorrect mapping of PerPage key in config for prefix '.$event->Prefix.'', E_USER_WARNING); - } - $per_page = $this->Application->ConfigValue($config_mapping['PerPage']); - } if (!$per_page) { - // none of checked above per-page locations are useful, then try default value - $default_per_page = $event->getEventParam('default_per_page'); - $per_page = is_numeric($default_per_page) ? $default_per_page : 10; + // per-page is stored to current session + $per_page = $this->Application->RecallVar($storage_prefix . '_PerPage'); } } } + if (!$per_page) { + // per page wan't found in request/session/persistent session + $list_helper =& $this->Application->recallObject('ListHelper'); + /* @var $list_helper ListHelper */ + + // allow to override default per-page value from tag + $default_per_page = $event->getEventParam('default_per_page'); + + if (!is_numeric($default_per_page)) { + $default_per_page = 10; + } + + $per_page = $list_helper->getDefaultPerPage($event->Prefix, $default_per_page); + } + return $per_page; } @@ -847,25 +950,36 @@ function SetSorting(&$event) { $event->setPseudoClass('_List'); + $object =& $event->getObject(); + /* @var $object kDBList */ - $storage_prefix = $event->getEventParam('same_special') ? $event->Prefix : $event->Prefix_Special; - $cur_sort1 = $this->Application->RecallVar($storage_prefix.'_Sort1'); - $cur_sort1_dir = $this->Application->RecallVar($storage_prefix.'_Sort1_Dir'); - $cur_sort2 = $this->Application->RecallVar($storage_prefix.'_Sort2'); - $cur_sort2_dir = $this->Application->RecallVar($storage_prefix.'_Sort2_Dir'); + if ($object->mainList) { + $sort_by = $this->Application->GetVar('sort_by'); + $cur_sort1 = $cur_sort1_dir = $cur_sort2 = $cur_sort2_dir = false; - $sorting_configs = $this->Application->getUnitOption($event->Prefix, 'ConfigMapping'); - $list_sortings = $this->Application->getUnitOption($event->Prefix, 'ListSortings'); - $sorting_prefix = getArrayValue($list_sortings, $event->Special) ? $event->Special : ''; + if ($sort_by) { + list ($cur_sort1, $cur_sort1_dir) = explode(',', $sort_by); + } + } + else { + $storage_prefix = $event->getEventParam('same_special') ? $event->Prefix : $event->Prefix_Special; + $cur_sort1 = $this->Application->RecallVar($storage_prefix . '_Sort1'); + $cur_sort1_dir = $this->Application->RecallVar($storage_prefix . '_Sort1_Dir'); + $cur_sort2 = $this->Application->RecallVar($storage_prefix . '_Sort2'); + $cur_sort2_dir = $this->Application->RecallVar($storage_prefix . '_Sort2_Dir'); + } $tag_sort_by = $event->getEventParam('sort_by'); + if ($tag_sort_by) { if ($tag_sort_by == 'random') { $object->AddOrderField('RAND()', ''); } else { + // multiple sortings could be specified at once $tag_sort_by = explode('|', $tag_sort_by); + foreach ($tag_sort_by as $sorting_element) { list ($by, $dir) = explode(',', $sorting_element); $object->AddOrderField($by, $dir); @@ -873,39 +987,49 @@ } } - if ($sorting_configs && isset ($sorting_configs['DefaultSorting1Field'])){ - $list_sortings[$sorting_prefix]['Sorting'] = Array( + $list_sortings = $this->Application->getUnitOption($event->Prefix, 'ListSortings'); + $sorting_prefix = getArrayValue($list_sortings, $event->Special) ? $event->Special : ''; + $sorting_configs = $this->Application->getUnitOption($event->Prefix, 'ConfigMapping'); + + if ($sorting_configs && array_key_exists('DefaultSorting1Field', $sorting_configs)) { + // sorting defined in configuration variables overrides one from unit config + $list_sortings[$sorting_prefix]['Sorting'] = Array ( $this->Application->ConfigValue($sorting_configs['DefaultSorting1Field']) => $this->Application->ConfigValue($sorting_configs['DefaultSorting1Dir']), $this->Application->ConfigValue($sorting_configs['DefaultSorting2Field']) => $this->Application->ConfigValue($sorting_configs['DefaultSorting2Dir']), ); } - // Use default if not specified - if ( !$cur_sort1 || !$cur_sort1_dir) - { - if ( $sorting = getArrayValue($list_sortings, $sorting_prefix, 'Sorting') ) { + // use default if not specified in session + if (!$cur_sort1 || !$cur_sort1_dir) { + $sorting = getArrayValue($list_sortings, $sorting_prefix, 'Sorting'); + + if ($sorting) { reset($sorting); $cur_sort1 = key($sorting); $cur_sort1_dir = current($sorting); + if (next($sorting)) { - $cur_sort2 = key($sorting); - $cur_sort2_dir = current($sorting); + $cur_sort2 = key($sorting); + $cur_sort2_dir = current($sorting); } } } - if ( $forced_sorting = getArrayValue($list_sortings, $sorting_prefix, 'ForcedSorting') ) { + // always add forced sorting before any user sortings + $forced_sorting = getArrayValue($list_sortings, $sorting_prefix, 'ForcedSorting'); + + if ($forced_sorting) { foreach ($forced_sorting as $field => $dir) { $object->AddOrderField($field, $dir); } } - if($cur_sort1 != '' && $cur_sort1_dir != '') - { + // add user sortings + if ($cur_sort1 != '' && $cur_sort1_dir != '') { $object->AddOrderField($cur_sort1, $cur_sort1_dir); } - if($cur_sort2 != '' && $cur_sort2_dir != '') - { + + if ($cur_sort2 != '' && $cur_sort2_dir != '') { $object->AddOrderField($cur_sort2, $cur_sort2_dir); } } @@ -1011,6 +1135,7 @@ $this->Application->StoreVar($event->Prefix_Special.'_Sort1', $cur_sort1); $this->Application->StoreVar($event->Prefix_Special.'_Sort1_Dir', $cur_sort1_dir); + if ($use_double_sorting) { $this->Application->StoreVar($event->Prefix_Special.'_Sort2', $cur_sort2); $this->Application->StoreVar($event->Prefix_Special.'_Sort2_Dir', $cur_sort2_dir); @@ -1024,17 +1149,43 @@ */ function OnSetSortingDirect(&$event) { - $combined = $this->Application->GetVar($event->Prefix.'_CombinedSorting'); + // used on Front-End in category item lists + $prefix_special = $event->getPrefixSpecial(); + $combined = $this->Application->GetVar($event->getPrefixSpecial(true) . '_CombinedSorting'); + if ($combined) { - list($field, $dir) = explode('|', $combined); - $this->Application->StoreVar($event->Prefix.'_Sort1', $field); - $this->Application->StoreVar($event->Prefix.'_Sort1_Dir', $dir); + list ($field, $dir) = explode('|', $combined); + + if ($this->Application->isAdmin || !$this->Application->GetVar('main_list')) { + $this->Application->StoreVar($prefix_special . '_Sort1', $field); + $this->Application->StoreVar($prefix_special . '_Sort1_Dir', $dir); + } + else { + $event->setPseudoClass('_List'); + $this->Application->SetVar('sort_by', $field . ',' . $dir); + + $object =& $event->getObject( Array ('main_list' => 1) ); + /* @var $object kDBList */ + + $list_helper =& $this->Application->recallObject('ListHelper'); + /* @var $list_helper ListHelper */ + + $this->_passListParams($event, 'sort_by'); + + if ($list_helper->hasUserSorting($object)) { + $event->SetRedirectParam('sort_by', $field . ',' . strtolower($dir)); + } + + $event->SetRedirectParam('pass', 'm'); + } + return ; } - $field_pos = $this->Application->GetVar($event->Prefix.'_SortPos'); - $this->Application->LinkVar($event->Prefix.'_Sort'.$field_pos, $event->Prefix.'_Sort'.$field_pos); - $this->Application->LinkVar($event->Prefix.'_Sort'.$field_pos.'_Dir', $event->Prefix.'_Sort'.$field_pos.'_Dir'); + // used in "View Menu -> Sort" menu in administrative console + $field_pos = $this->Application->GetVar($event->getPrefixSpecial(true) . '_SortPos'); + $this->Application->LinkVar($event->getPrefixSpecial(true) . '_Sort' . $field_pos, $prefix_special . '_Sort' . $field_pos); + $this->Application->LinkVar($event->getPrefixSpecial(true) . '_Sort' . $field_pos . '_Dir', $prefix_special . '_Sort' . $field_pos . '_Dir'); } /** Index: kernel/db/db_tag_processor.php =================================================================== --- kernel/db/db_tag_processor.php (revision 13152) +++ kernel/db/db_tag_processor.php (working copy) @@ -388,17 +388,29 @@ } $requery = isset($params['requery']) && $params['requery']; + $main_list = array_key_exists('main_list', $params) && $params['main_list']; + if ($list_name && !$requery) { - $names_mapping = $this->Application->GetVar('NamesToSpecialMapping'); + // list with "list_name" parameter + $names_mapping = $this->Application->GetVar('NamesToSpecialMapping', Array ()); - $special = is_array($names_mapping) && isset($names_mapping[$this->Prefix]) && isset($names_mapping[$this->Prefix][$list_name]) ? $names_mapping[$this->Prefix][$list_name] : false; -// $special = getArrayValue($names_mapping, $this->Prefix, $list_name); - if (!$special) { - $special = $this->BuildListSpecial($params); + if (!array_key_exists($this->Prefix, $names_mapping)) { + // create prefix-based array to special mapping storage + $names_mapping[$this->Prefix] = Array (); } + + if (!array_key_exists($list_name, $names_mapping[$this->Prefix])) { + // special missing -> generate one + $special = $main_list ? $this->Special : $this->BuildListSpecial($params); + } + else { + // get special, formed during list initialization + $special = $names_mapping[$this->Prefix][$list_name]; + } } else { - $special = $this->BuildListSpecial($params); + // list without "list_name" parameter + $special = $main_list ? $this->Special : $this->BuildListSpecial($params); } $prefix_special = rtrim($this->Prefix.'.'.$special, '.'); @@ -445,6 +457,13 @@ return $ret; } + function CombinedSortingDropDownName($params) + { + $list =& $this->GetList($params); + + return $list->getPrefixSpecial() . '_CombinedSorting'; + } + /** * Prepares name for field with event in it (used only on front-end) * @@ -457,7 +476,7 @@ $prefix_special = $list->getPrefixSpecial(); - return 'events['.$prefix_special.']['.$params['event'].']'; + return 'events[' . $prefix_special . '][' . $params['event'] . ']'; } /** @@ -636,20 +655,81 @@ function PageLink($params) { - $t = isset($params['template']) ? $params['template'] : ''; - unset($params['template']); + static $default_per_page = Array (); - if (!$t) $t = $this->Application->GetVar('t'); + $object =& $this->GetList($params); + /* @var $object kDBList */ - if (isset($params['page'])) { - $this->Application->SetVar($this->getPrefixSpecial().'_Page', $params['page']); + // process sorting + if ($object->mainList) { + if (!array_key_exists('sort_by', $params)) { + $sort_by = $this->Application->GetVar('sort_by'); + + if ($sort_by !== false) { + $params['sort_by'] = $sort_by; + } + } + } + + $prefix_special = $this->getPrefixSpecial(); + + // process page + $page = array_key_exists('page', $params) ? $params['page'] : $this->Application->GetVar($prefix_special . '_Page'); + + if (!$page) { + // ensure, that page is always present + if ($object->mainList) { + $params[$prefix_special . '_Page'] = $this->Application->GetVar('page', 1); + } + else { + $params[$prefix_special . '_Page'] = 1; + } + } + + if (array_key_exists('page', $params)) { + $params[$prefix_special . '_Page'] = $params['page']; unset($params['page']); } - if (!isset($params['pass'])) { - $params['pass'] = 'm,'.$this->getPrefixSpecial(); + // process per-page + $per_page = array_key_exists('per_page', $params) ? $params['per_page'] : $this->Application->GetVar($prefix_special . '_PerPage'); + + if (!$per_page) { + // ensure, that per-page is always present + list ($prefix, ) = explode('.', $prefix_special); + + if (!array_key_exists($prefix, $default_per_page)) { + $list_helper =& $this->Application->recallObject('ListHelper'); + /* @var $list_helper ListHelper */ + + $default_per_page[$prefix] = $list_helper->getDefaultPerPage($prefix); + } + + if ($object->mainList) { + $params[$prefix_special . '_PerPage'] = $this->Application->GetVar('per_page', $default_per_page[$prefix]); + } + else { + $params[$prefix_special . '_PerPage'] = $default_per_page[$prefix]; + } } + if (array_key_exists('per_page', $params)) { + $params[$prefix_special . '_PerPage'] = $params['per_page']; + unset($params['per_page']); + } + + if (!array_key_exists('pass', $params)) { + $params['pass'] = 'm,' . $prefix_special; + } + + // process template + $t = array_key_exists('template', $params) ? $params['template'] : ''; + unset($params['template']); + + if (!$t) { + $t = $this->Application->GetVar('t'); + } + return $this->Application->HREF($t, '', $params); } @@ -1171,7 +1251,28 @@ return $this->PrintPages($params); } + function PerPageBar($params) + { + $object =& $this->GetList($params); + $ret = ''; + $per_pages = explode(';', $params['per_pages']); + $block_params = $this->prepareTagParams($params); + $block_params['name'] = $params['render_as']; + + foreach ($per_pages as $per_page) { + $block_params['per_page'] = $per_page; + $this->Application->SetVar($this->getPrefixSpecial() . '_PerPage', $per_page); + $block_params['selected'] = $per_page == $object->PerPage; + + $ret .= $this->Application->ParseBlock($block_params, 1); + } + + $this->Application->SetVar($this->getPrefixSpecial() . '_PerPage', $object->PerPage); + + return $ret; + } + /** * Returns field name (processed by kMultiLanguage formatter * if required) and item's id from it's IDField or field required @@ -1312,52 +1413,11 @@ function OrderChanged($params) { $list =& $this->GetList($params); - $user_sorting_start = $this->getUserSortIndex(); - $sorting_configs = $this->Application->getUnitOption($this->Prefix, 'ConfigMapping', Array ()); - $list_sortings = $this->Application->getUnitOption($this->Prefix, 'ListSortings', Array ()); - $sorting_prefix = getArrayValue($list_sortings, $this->Special) ? $this->Special : ''; + $list_helper =& $this->Application->recallObject('ListHelper'); + /* @var $list_helper ListHelper */ - if (array_key_exists('DefaultSorting1Field', $sorting_configs)) { - $list_sortings[$sorting_prefix]['Sorting'] = Array ( - $this->Application->ConfigValue($sorting_configs['DefaultSorting1Field']) => $this->Application->ConfigValue($sorting_configs['DefaultSorting1Dir']), - $this->Application->ConfigValue($sorting_configs['DefaultSorting2Field']) => $this->Application->ConfigValue($sorting_configs['DefaultSorting2Dir']), - ); - } - - $sorting = getArrayValue($list_sortings, $sorting_prefix, 'Sorting'); - $sort_fields = is_array($sorting) ? array_keys($sorting) : Array (); - - for ($order_number = 0; $order_number < 2; $order_number++) { - // currect sorting in list - $sorting_pos = $user_sorting_start + $order_number; - $current_order_field = $list->GetOrderField($sorting_pos, true); - $current_order_direction = $list->GetOrderDirection($sorting_pos, true); - - if (!$current_order_field || !$current_order_direction) { - // no sorting defined for this sorting position - continue; - } - - // user sorting found - if (array_key_exists($order_number, $sort_fields)) { - // default sorting found - $default_order_field = $sort_fields[$order_number]; - $default_order_direction = $sorting[$default_order_field]; - - if ($current_order_field != $default_order_field || $current_order_direction != $default_order_direction) { - // #1. user sorting differs from default sorting -> changed - return true; - } - } - else { - // #2. user sorting + no default sorting -> changed - return true; - } - } - - // #3. user sorting match default or not defined -> not changed - return false; + return $list_helper->hasUserSorting($list); } /** @@ -2317,6 +2377,7 @@ function PerPageSelected($params) { $list =& $this->GetList($params); + return $list->PerPage == $params['per_page'] ? $params['selected'] : ''; } @@ -2330,7 +2391,7 @@ { $list =& $this->GetList($params); - return $list->getPrefixSpecial().'_'.$params['type']; + return $list->getPrefixSpecial() . '_' . $params['type']; } /** Index: kernel/db/dblist.php =================================================================== --- kernel/db/dblist.php (revision 13152) +++ kernel/db/dblist.php (working copy) @@ -22,13 +22,12 @@ */ class kDBList extends kDBBase { - /** * Holds totals for fields specified in config * * @var Array */ - var $Totals = Array(); + var $Totals = Array (); /** * Description @@ -61,7 +60,7 @@ * * @var int */ - var $SelectedCount=0; + var $SelectedCount = 0; /** * Array of records selected @@ -127,7 +126,7 @@ * @var kMultipleFilter * @access private */ - var $WhereFilter = Array(FLT_SYSTEM => null, FLT_NORMAL => null, FLT_SEARCH => null, FLT_VIEW => null); + var $WhereFilter = Array (FLT_SYSTEM => null, FLT_NORMAL => null, FLT_SEARCH => null, FLT_VIEW => null); /** * Holds list HAVING filter object @@ -135,17 +134,26 @@ * @var kMultipleFilter * @access private */ - var $HavingFilter = Array(FLT_SYSTEM => null, FLT_NORMAL => null, FLT_SEARCH => null, FLT_VIEW => null); + var $HavingFilter = Array (FLT_SYSTEM => null, FLT_NORMAL => null, FLT_SEARCH => null, FLT_VIEW => null); - var $AggregateFilter = Array(FLT_SYSTEM => null, FLT_NORMAL => null); + var $AggregateFilter = Array (FLT_SYSTEM => null, FLT_NORMAL => null); - var $GroupByFields = Array(); + var $GroupByFields = Array (); var $Queried = false; + var $Counted = false; + var $TotalsCalculated = false; /** + * Identifies this list as main on the page, that allows to react on "page", "per_page" and "sort_by" parameters from url + * + * @var bool + */ + var $mainList = false; + + /** * Creates kDBList * * @return kDBList @@ -289,19 +297,19 @@ if( $this->GetGroupClause() ) { - $this->RecordsCount = count( $this->Conn->GetCol($sql) ); + $this->RecordsCount = count( $this->Conn->GetCol($sql) ); } else { $this->RecordsCount = (int)$this->Conn->GetOne($sql); } - $system_sql = $this->GetSelectSQL(true,true); - if($system_sql == $all_sql) //no need to query the same again - { - $this->NoFilterCount = $this->RecordsCount; - return; - } + $system_sql = $this->GetSelectSQL(true,true); + if($system_sql == $all_sql) //no need to query the same again + { + $this->NoFilterCount = $this->RecordsCount; + return; + } $sql = $this->getCountSQL($system_sql); if( $this->GetGroupClause() ) Index: kernel/event_manager.php =================================================================== --- kernel/event_manager.php (revision 13152) +++ kernel/event_manager.php (working copy) @@ -168,7 +168,7 @@ unset($this->queryMaps[$prefix]); } -// 'passed' is set later in ProcessRequest - do we really need it here? (it breakes HTTPQuery initialization...) +// 'passed' is set later in ProcessRequest - do we really need it here? (it breakes HTTPQuery initialization...) // $this->Application->SetVar('passed', implode(',', array_keys($this->queryMaps)) ); return $query_map; } @@ -351,7 +351,11 @@ $query_map = array_flip($query_map); if (isset($query_map['event'])) { $event_name = $this->Application->GetVar($prefix_special . '_event'); - if ($event_name) { + + // we need to check for pre 5.1.0 url format, because of "PerPage" + // query string part (that was added in place of "event" query + // string part) is available only since 5.1.0 version + if ($event_name && !is_numeric($event_name)) { $events[$prefix_special] = $event_name; } } Index: kernel/processors/main_processor.php =================================================================== --- kernel/processors/main_processor.php (revision 13152) +++ kernel/processors/main_processor.php (working copy) @@ -166,7 +166,10 @@ function FormAction($params) { - $params['pass'] = 'all,m'; + if (!array_key_exists('pass', $params)) { + $params['pass'] = 'all,m'; + } + $params['pass_category'] = 1; return $this->Application->HREF('', '', $params); @@ -1034,4 +1037,24 @@ $format = isset($params['format']) ? $params['format'] : 'd.m.Y H:i:s'; return adodb_date($format); } + + function GetUrlHiddenFileds($params) + { + $vars = Array ('page', 'per_page', 'sort_by'); + $ret = ''; + + if (array_key_exists('skip', $params)) { + $vars = array_diff($vars, $params['skip']); + } + + foreach ($vars as $var_name) { + $var_value = $this->Application->GetVar($var_name); + + if ($var_value) { + $ret .= ''; + } + } + + return $ret; + } } Index: units/agents/agents_config.php =================================================================== --- units/agents/agents_config.php (revision 13152) +++ units/agents/agents_config.php (working copy) @@ -26,8 +26,9 @@ 'QueryString' => Array ( 1 => 'id', 2 => 'Page', - 3 => 'event', - 4 => 'mode', + 3 => 'PerPage', + 4 => 'event', + 5 => 'mode', ), 'Hooks' => Array ( Index: units/ban_rules/ban_rules_config.php =================================================================== --- units/ban_rules/ban_rules_config.php (revision 13152) +++ units/ban_rules/ban_rules_config.php (working copy) @@ -25,8 +25,9 @@ 'QueryString' => Array ( 1 => 'id', 2 => 'Page', - 3 => 'event', - 4 => 'mode', + 3 => 'PerPage', + 4 => 'event', + 5 => 'mode', ), 'IDField' => 'RuleId', Index: units/categories/categories_config.php =================================================================== --- units/categories/categories_config.php (revision 13152) +++ units/categories/categories_config.php (working copy) @@ -59,8 +59,9 @@ 'QueryString' => Array ( 1 => 'id', 2 => 'Page', - 3 => 'event', - 4 => 'mode', + 3 => 'PerPage', + 4 => 'event', + 5 => 'mode', ), 'AggregateTags' => Array ( Index: units/categories/categories_tag_processor.php =================================================================== --- units/categories/categories_tag_processor.php (revision 13152) +++ units/categories/categories_tag_processor.php (working copy) @@ -737,7 +737,7 @@ */ function SubmitName($params) { - return 'events['.$this->Prefix.']['.$params['event'].']'; + return 'events[' . $this->Prefix . '][' . $params['event'] . ']'; } /** @@ -872,23 +872,9 @@ function PageLink($params) { - $t = isset($params['template']) ? $params['template'] : ''; - unset($params['template']); + $params['m_cat_page'] = $this->Application->GetVar($this->getPrefixSpecial() . '_Page'); - if (!$t) $t = $this->Application->GetVar('t'); - - if (isset($params['page'])) { - $this->Application->SetVar($this->getPrefixSpecial().'_Page', $params['page']); - unset($params['page']); - } - - $params['m_cat_page'] = $this->Application->GetVar($this->getPrefixSpecial().'_Page'); - - if (!isset($params['pass'])) { - $params['pass'] = 'm,'.$this->getPrefixSpecial(); - } - - return $this->Application->HREF($t, '', $params); + return parent::PageLink($params); } /** Index: units/category_items/category_items_config.php =================================================================== --- units/category_items/category_items_config.php (revision 13152) +++ units/category_items/category_items_config.php (working copy) @@ -30,9 +30,10 @@ 'cms-ci'=> Array('ParentPrefix' => 'cms',), ), 'QueryString' => Array( - 1 => 'id', - 2 => 'page', - 3 => 'event', + 1 => 'id', + 2 => 'Page', + 3 => 'PerPage', + 4 => 'event', ), 'IDField' => 'CategoryId', // in this case idfield doesn't exit in destination table 'StatusField' => Array('PrimaryCat'), // field, that is affected by Approve/Decline events Index: units/config_search/config_search_config.php =================================================================== --- units/config_search/config_search_config.php (revision 13152) +++ units/config_search/config_search_config.php (working copy) @@ -48,9 +48,10 @@ 'AutoLoad' => true, 'hooks' => Array(), 'QueryString' => Array( - 1 => 'id', - 2 => 'page', - 3 => 'event', + 1 => 'id', + 2 => 'Page', + 3 => 'PerPage', + 4 => 'event', ), 'IDField' => 'SearchConfigId', Index: units/configuration/configuration_config.php =================================================================== --- units/configuration/configuration_config.php (revision 13152) +++ units/configuration/configuration_config.php (working copy) @@ -26,8 +26,9 @@ 'QueryString' => Array ( 1 => 'id', 2 => 'Page', - 3 => 'event', - 4 => 'mode', + 3 => 'PerPage', + 4 => 'event', + 5 => 'mode', ), 'IDField' => 'VariableId', Index: units/content/content_config.php =================================================================== --- units/content/content_config.php (revision 13152) +++ units/content/content_config.php (working copy) @@ -24,8 +24,9 @@ 'QueryString' => Array ( 1 => 'id', 2 => 'Page', - 3 => 'event', - 4 => 'mode', + 3 => 'PerPage', + 4 => 'event', + 5 => 'mode', // needed? ), 'IDField' => 'PageContentId', Index: units/custom_fields/custom_fields_config.php =================================================================== --- units/custom_fields/custom_fields_config.php (revision 13152) +++ units/custom_fields/custom_fields_config.php (working copy) @@ -24,10 +24,11 @@ 'hooks' => Array(), 'QueryString' => Array( 1 => 'id', - 2 => 'page', - 3 => 'event', - 4 => 'type', - 5 => 'mode', + 2 => 'Page', + 3 => 'PerPage', + 4 => 'event', + 5 => 'type', + 6 => 'mode', ), 'Hooks' => Array( Index: units/email_events/email_events_config.php =================================================================== --- units/email_events/email_events_config.php (revision 13152) +++ units/email_events/email_events_config.php (working copy) @@ -26,8 +26,9 @@ 'QueryString' => Array ( 1 => 'id', 2 => 'Page', - 3 => 'event', - 4 => 'mode', + 3 => 'PerPage', + 4 => 'event', + 5 => 'mode', ), 'IDField' => 'EventId', Index: units/email_queue/email_queue_config.php =================================================================== --- units/email_queue/email_queue_config.php (revision 13152) +++ units/email_queue/email_queue_config.php (working copy) @@ -26,8 +26,9 @@ 'QueryString' => Array ( 1 => 'id', 2 => 'Page', - 3 => 'event', - 4 => 'mode', + 3 => 'PerPage', + 4 => 'event', + 5 => 'mode', ), 'IDField' => 'EmailQueueId', Index: units/favorites/favorites_config.php =================================================================== --- units/favorites/favorites_config.php (revision 13152) +++ units/favorites/favorites_config.php (working copy) @@ -63,9 +63,10 @@ ), 'QueryString' => Array ( - 1 => 'id', - 2 => 'page', - 3 => 'event', + 1 => 'id', + 2 => 'Page', + 3 => 'PerPage', + 4 => 'event', ), 'IDField' => 'FavoriteId', Index: units/files/files_config.php =================================================================== --- units/files/files_config.php (revision 13152) +++ units/files/files_config.php (working copy) @@ -25,8 +25,9 @@ 'QueryString' => Array ( 1 => 'id', - 2 => 'page', - 3 => 'event', + 2 => 'Page', + 3 => 'PerPage', + 4 => 'event', ), 'IDField' => 'FileId', Index: units/form_fields/form_fields_config.php =================================================================== --- units/form_fields/form_fields_config.php (revision 13152) +++ units/form_fields/form_fields_config.php (working copy) @@ -22,9 +22,10 @@ 'TagProcessorClass' => Array('class'=>'FormFieldsTagProcessor','file'=>'form_fields_tp.php'), 'AutoLoad' => true, 'QueryString' => Array( - 1 => 'id', - 2 => 'page', - 3 => 'event', + 1 => 'id', + 2 => 'Page', + 3 => 'PerPage', + 4 => 'event', ), 'IDField' => 'FormFieldId', Index: units/form_submissions/form_submissions_config.php =================================================================== --- units/form_submissions/form_submissions_config.php (revision 13152) +++ units/form_submissions/form_submissions_config.php (working copy) @@ -22,9 +22,10 @@ 'TagProcessorClass' => Array('class'=>'FormSubmissionTagProcessor', 'file' => 'form_submission_tp.php', 'build_event'=>'OnBuild'), 'AutoLoad' => true, 'QueryString' => Array( - 1 => 'id', - 2 => 'page', - 3 => 'event', + 1 => 'id', + 2 => 'Page', + 3 => 'PerPage', + 4 => 'event', ), 'Hooks' => Array( Index: units/forms/forms_config.php =================================================================== --- units/forms/forms_config.php (revision 13152) +++ units/forms/forms_config.php (working copy) @@ -22,10 +22,11 @@ 'TagProcessorClass' => Array('class'=>'FormsTagProcessor','file'=>'forms_tp.php','build_event'=>'OnBuild'), 'AutoLoad' => true, 'QueryString' => Array( - 1 => 'id', - 2 => 'Page', - 3 => 'event', - 4 => 'mode', + 1 => 'id', + 2 => 'Page', + 3 => 'PerPage', + 4 => 'event', + 5 => 'mode', ), 'Hooks' => Array( Array( Index: units/groups/groups_config.php =================================================================== --- units/groups/groups_config.php (revision 13152) +++ units/groups/groups_config.php (working copy) @@ -26,9 +26,10 @@ 'QueryString' => Array ( 1 => 'id', - 2 => 'page', - 3 => 'event', - 4 => 'mode', + 2 => 'Page', + 3 => 'PerPage', + 4 => 'event', + 5 => 'mode', ), 'IDField' => 'GroupId', Index: units/helpers/helpers_config.php =================================================================== --- units/helpers/helpers_config.php (revision 13152) +++ units/helpers/helpers_config.php (working copy) @@ -58,5 +58,6 @@ Array ('class' => 'kXMLHelper', 'pseudo' => 'kXMLHelper', 'file' => 'xml_helper.php', 'build_event' => '', 'require_classes' => 'kHelper'), Array ('class' => 'kCatDBItemExportHelper', 'pseudo' => 'CatItemExportHelper', 'file' => 'cat_dbitem_export_helper.php', 'build_event' => '', 'require_classes' => 'kHelper'), Array ('class' => 'EmailMessageHelper', 'pseudo' => 'EmailMessageHelper', 'file' => 'email_message_helper.php', 'build_event' => '', 'require_classes' => 'kHelper'), + Array ('class' => 'ListHelper', 'pseudo' => 'ListHelper', 'file' => 'list_helper.php', 'build_event' => '', 'require_classes' => 'kHelper'), ), ); \ No newline at end of file Index: units/helpers/list_helper.php =================================================================== --- units/helpers/list_helper.php (revision 0) +++ units/helpers/list_helper.php (revision 0) @@ -0,0 +1,125 @@ +getPrefixSpecial(), $cache)) { + return $cache[ $list->getPrefixSpecial() ]; + } + + $user_sorting_start = $this->getUserSortIndex($list); + + $sorting_configs = $this->Application->getUnitOption($list->Prefix, 'ConfigMapping', Array ()); + $list_sortings = $this->Application->getUnitOption($list->Prefix, 'ListSortings', Array ()); + $sorting_prefix = getArrayValue($list_sortings, $list->Special) ? $list->Special : ''; + + if (array_key_exists('DefaultSorting1Field', $sorting_configs)) { + $list_sortings[$sorting_prefix]['Sorting'] = Array ( + $this->Application->ConfigValue($sorting_configs['DefaultSorting1Field']) => $this->Application->ConfigValue($sorting_configs['DefaultSorting1Dir']), + $this->Application->ConfigValue($sorting_configs['DefaultSorting2Field']) => $this->Application->ConfigValue($sorting_configs['DefaultSorting2Dir']), + ); + } + + $sorting = getArrayValue($list_sortings, $sorting_prefix, 'Sorting'); + $sort_fields = is_array($sorting) ? array_keys($sorting) : Array (); + + for ($order_number = 0; $order_number < 2; $order_number++) { + // currect sorting in list + $sorting_pos = $user_sorting_start + $order_number; + $current_order_field = $list->GetOrderField($sorting_pos, true); + $current_order_direction = $list->GetOrderDirection($sorting_pos, true); + + if (!$current_order_field || !$current_order_direction) { + // no sorting defined for this sorting position + continue; + } + + // remove language prefix from field + $field_options = $list->GetFieldOptions($current_order_field); + if (array_key_exists('formatter', $field_options) && $field_options['formatter'] == 'kMultiLanguage') { + // remove language prefix + $current_order_field = preg_replace('/^l[\d]+_(.*)/', '\\1', $current_order_field); + } + + // user sorting found + if (array_key_exists($order_number, $sort_fields)) { + // default sorting found + $default_order_field = $sort_fields[$order_number]; + $default_order_direction = $sorting[$default_order_field]; // because people can write + + if ($current_order_field != $default_order_field || strcasecmp($current_order_direction, $default_order_direction) != 0) { + // #1. user sorting differs from default sorting -> changed + $cache[ $list->getPrefixSpecial() ] = true; + return true; + } + } + else { + // #2. user sorting + no default sorting -> changed + $cache[ $list->getPrefixSpecial() ] = true; + return true; + } + } + + // #3. user sorting match default or not defined -> not changed + $cache[ $list->getPrefixSpecial() ] = false; + return false; + } + + /** + * Returns default per-page value for given prefix + * + * @param string $prefix + * @param int $default + * @return int + */ + function getDefaultPerPage($prefix, $default = 10) + { + $ret = false; + $config_mapping = $this->Application->getUnitOption($prefix, 'ConfigMapping'); + + if ($config_mapping) { + if (!array_key_exists('PerPage', $config_mapping)) { + trigger_error('Incorrect mapping of PerPage key in config for prefix ' . $event->Prefix . '', E_USER_WARNING); + } + + $per_page = $this->Application->ConfigValue($config_mapping['PerPage']); + + if ($per_page) { + return $per_page; + } + } + + // none of checked above per-page locations are useful, then try default value + return $default; + } + + /** + * Returns index where 1st changable sorting field begins + * + * @param kDBList $list + * @return int + * @todo This is copy of kDBTagProcessor::getUserSortIndex method. + * Can't call helper there, because it will slow down grid output + * when we have a lot of columns + */ + function getUserSortIndex(&$list) + { + $list_sortings = $this->Application->getUnitOption($list->Prefix, 'ListSortings'); + $sorting_prefix = getArrayValue($list_sortings, $list->Special) ? $list->Special : ''; + + $user_sorting_start = 0; + if ( $forced_sorting = getArrayValue($list_sortings, $sorting_prefix, 'ForcedSorting') ) { + $user_sorting_start = count($forced_sorting); + } + return $user_sorting_start; + } + } \ No newline at end of file Index: units/helpers/mod_rewrite_helper.php =================================================================== --- units/helpers/mod_rewrite_helper.php (revision 13152) +++ units/helpers/mod_rewrite_helper.php (working copy) @@ -103,12 +103,10 @@ } foreach ($vars as $name => $value) { - $this->HTTPQuery->Set($name,$value); + $this->HTTPQuery->Set($name, $value); } -// if ($restored) { - $this->InitAll(); -// } + $this->InitAll(); // also will use parsed language to load phrases from it $this->HTTPQuery->finalizeParsing($passed); } @@ -162,10 +160,10 @@ if (($this->_modulePrefix === false) && in_array('parseCategory', $this->_partsFound)) { // no item found, but category found -> module index page - foreach ($this->Application->RewriteListeners as $prefix => $listener) { + /*foreach ($this->Application->RewriteListeners as $prefix => $listener) { // no idea what module we are talking about, so pass info form all modules $vars['pass'][] = $prefix; - } + }*/ return $vars; } @@ -211,7 +209,7 @@ foreach ($this->Application->RewriteListeners as $prefix => $listener) { // set default page - $vars[$prefix . '_Page'] = 1; // will override page in session in case, when none is given in url + // $vars[$prefix . '_Page'] = 1; // will override page in session in case, when none is given in url if ($page_number) { // page given in url - use it @@ -248,7 +246,7 @@ $physical_template = array_search($template_path, $this->Application->structureTemplateMapping); - if ($physical_template !== false) { + if (($physical_template !== false) && (substr($physical_template, 0, 3) != 'id:')) { // replace menu template name with it's actual template name on disk list ($template_path) = explode(':', $physical_template, 2); } @@ -443,7 +441,6 @@ WHERE Enabled = 1 ORDER BY SortKey DESC'; $language_info = $this->Conn->GetRow($sql); - $this->Application->Phrases = new PhrasesCache(); if ($language_info && $language_info['LanguageId'] && $language_info['SortKey']) { // primary language will be selected in case, when $url_part doesn't match to other's language pack name @@ -565,9 +562,9 @@ */ function removePages() { - foreach ($this->Application->RewriteListeners as $prefix => $listener) { + /*foreach ($this->Application->RewriteListeners as $prefix => $listener) { $this->Application->DeleteVar($prefix . '_Page'); - } + }*/ } /** @@ -681,6 +678,8 @@ */ function _buildCategoryItemUrl($prefix_special, &$params, $keep_events) { + static $default_per_page = Array (); + $ret = ''; list ($prefix) = explode('.', $prefix_special); $processed_params = $this->getProcessedParams($prefix_special, $params, $keep_events); @@ -689,6 +688,13 @@ return ''; } + if (!array_key_exists($prefix, $default_per_page)) { + $list_helper =& $this->Application->recallObject('ListHelper'); + /* @var $list_helper ListHelper */ + + $default_per_page[$prefix] = $list_helper->getDefaultPerPage($prefix); + } + if ($processed_params[$prefix_special . '_id']) { // this allows to fill 3 cache records with one query (see this method for details) $category_id = array_key_exists('m_cat_id', $params) ? $params['m_cat_id'] : $this->Application->GetVar('m_cat_id'); @@ -720,9 +726,16 @@ // category item prefix and $params['pass_category'] will not be added automatically $params['pass_category'] = true; } - else { - $ret .= $processed_params[$prefix_special . '_Page'] . '/'; + elseif ($processed_params[$prefix_special . '_Page'] > 1) { + // $ret .= $processed_params[$prefix_special . '_Page'] . '/'; + $params['page'] = $processed_params[$prefix_special . '_Page']; } + + $per_page = $processed_params[$prefix_special . '_PerPage']; + + if ($per_page && ($per_page != $default_per_page[$prefix])) { + $params['per_page'] = $processed_params[$prefix_special . '_PerPage']; + } } return mb_strtolower( rtrim($ret, '/') ); Index: units/images/images_config.php =================================================================== --- units/images/images_config.php (revision 13152) +++ units/images/images_config.php (working copy) @@ -70,9 +70,10 @@ ), 'QueryString' => Array( - 1 => 'id', - 2 => 'page', - 3 => 'event', + 1 => 'id', + 2 => 'Page', + 3 => 'PerPage', + 4 => 'event', ), 'RegularEvents' => Array ( Index: units/languages/languages_config.php =================================================================== --- units/languages/languages_config.php (revision 13152) +++ units/languages/languages_config.php (working copy) @@ -47,10 +47,11 @@ ), 'QueryString' => Array( - 1 => 'id', - 2 => 'page', - 3 => 'event', - 4 => 'mode', + 1 => 'id', + 2 => 'Page', + 3 => 'PerPage', + 4 => 'event', + 5 => 'mode', ), 'IDField' => 'LanguageId', Index: units/logs/change_logs/change_logs_config.php =================================================================== --- units/logs/change_logs/change_logs_config.php (revision 13152) +++ units/logs/change_logs/change_logs_config.php (working copy) @@ -30,8 +30,9 @@ 'QueryString' => Array ( 1 => 'id', 2 => 'Page', - 3 => 'event', - 4 => 'mode', + 3 => 'PerPage', + 4 => 'event', + 5 => 'mode', ), 'IDField' => 'ChangeLogId', Index: units/logs/email_logs/email_logs_config.php =================================================================== --- units/logs/email_logs/email_logs_config.php (revision 13152) +++ units/logs/email_logs/email_logs_config.php (working copy) @@ -26,8 +26,9 @@ 'QueryString' => Array ( 1 => 'id', 2 => 'Page', - 3 => 'event', - 4 => 'mode', + 3 => 'PerPage', + 4 => 'event', + 5 => 'mode', ), 'IDField' => 'EmailLogId', Index: units/logs/search_logs/search_logs_config.php =================================================================== --- units/logs/search_logs/search_logs_config.php (revision 13152) +++ units/logs/search_logs/search_logs_config.php (working copy) @@ -26,8 +26,9 @@ 'QueryString' => Array ( 1 => 'id', 2 => 'Page', - 3 => 'event', - 4 => 'mode', + 3 => 'PerPage', + 4 => 'event', + 5 => 'mode', ), 'IDField' => 'SearchLogId', Index: units/logs/session_logs/session_logs_config.php =================================================================== --- units/logs/session_logs/session_logs_config.php (revision 13152) +++ units/logs/session_logs/session_logs_config.php (working copy) @@ -26,8 +26,9 @@ 'QueryString' => Array ( 1 => 'id', 2 => 'Page', - 3 => 'event', - 4 => 'mode', + 3 => 'PerPage', + 4 => 'event', + 5 => 'mode', ), 'IDField' => 'SessionLogId', Index: units/mailing_lists/mailing_lists_config.php =================================================================== --- units/mailing_lists/mailing_lists_config.php (revision 13152) +++ units/mailing_lists/mailing_lists_config.php (working copy) @@ -26,8 +26,9 @@ 'QueryString' => Array ( 1 => 'id', 2 => 'Page', - 3 => 'event', - 4 => 'mode', + 3 => 'PerPage', + 4 => 'event', + 5 => 'mode', ), 'RegularEvents' => Array ( Index: units/modules/modules_config.php =================================================================== --- units/modules/modules_config.php (revision 13152) +++ units/modules/modules_config.php (working copy) @@ -22,10 +22,11 @@ 'TagProcessorClass' => Array('class'=>'ModulesTagProcessor','file'=>'modules_tag_processor.php','build_event'=>'OnBuild'), 'AutoLoad' => true, 'QueryString' => Array( - 1 => 'id', - 2 => 'page', - 3 => 'event', - 4 => 'mode', + 1 => 'id', + 2 => 'Page', + 3 => 'PerPage', + 4 => 'event', + 5 => 'mode', ), 'IDField' => 'Name', Index: units/permissions/permissions_config.php =================================================================== --- units/permissions/permissions_config.php (revision 13152) +++ units/permissions/permissions_config.php (working copy) @@ -65,9 +65,10 @@ ), 'QueryString' => Array( - 1 => 'id', - 2 => 'page', - 3 => 'event', + 1 => 'id', + 2 => 'Page', + 3 => 'PerPage', + 4 => 'event', ), 'IDField' => 'PermissionId', Index: units/phrases/phrases_config.php =================================================================== --- units/phrases/phrases_config.php (revision 13152) +++ units/phrases/phrases_config.php (working copy) @@ -26,10 +26,11 @@ 'QueryString' => Array ( 1 => 'id', - 2 => 'page', - 3 => 'event', - 4 => 'label', - 5 => 'mode', // labels can be edited directly + 2 => 'Page', + 3 => 'PerPage', + 4 => 'event', + 5 => 'label', // labels can be edited directly + 6 => 'mode', ), 'IDField' => 'PhraseId', Index: units/related_searches/related_searches_config.php =================================================================== --- units/related_searches/related_searches_config.php (revision 13152) +++ units/related_searches/related_searches_config.php (working copy) @@ -33,9 +33,10 @@ 'AutoLoad' => true, 'QueryString' => Array( - 1 => 'id', - 2 => 'page', - 3 => 'event', + 1 => 'id', + 2 => 'Page', + 3 => 'PerPage', + 4 => 'event', ), 'IDField' => 'RelatedSearchId', 'StatusField' => Array('Enabled'), Index: units/relationship/relationship_config.php =================================================================== --- units/relationship/relationship_config.php (revision 13152) +++ units/relationship/relationship_config.php (working copy) @@ -44,9 +44,10 @@ ), ), 'QueryString' => Array( - 1 => 'id', - 2 => 'page', - 3 => 'event', + 1 => 'id', + 2 => 'Page', + 3 => 'PerPage', + 4 => 'event', ), 'IDField' => 'RelationshipId', 'StatusField' => Array('Enabled','Type'), Index: units/reviews/reviews_config.php =================================================================== --- units/reviews/reviews_config.php (revision 13152) +++ units/reviews/reviews_config.php (working copy) @@ -78,8 +78,9 @@ 'QueryString' => Array ( 1 => 'id', 2 => 'Page', - 3 => 'event', - 4 => 'mode', + 3 => 'PerPage', + 4 => 'event', + 5 => 'mode', ), 'ParentPrefix' => 'p', // replace all usage of rev to "p-rev" and then remove this param from here and Prefix too Index: units/selectors/selectors_config.php =================================================================== --- units/selectors/selectors_config.php (revision 13152) +++ units/selectors/selectors_config.php (working copy) @@ -74,9 +74,10 @@ ), 'QueryString' => Array( - 1 => 'id', - 2 => 'page', - 3 => 'event', + 1 => 'id', + 2 => 'Page', + 3 => 'PerPage', + 4 => 'event', ), 'IDField' => 'SelectorId', Index: units/skins/skins_config.php =================================================================== --- units/skins/skins_config.php (revision 13152) +++ units/skins/skins_config.php (working copy) @@ -35,10 +35,11 @@ ), ), 'QueryString' => Array( - 1 => 'id', - 2 => 'Page', - 3 => 'event', - 4 => 'mode', + 1 => 'id', + 2 => 'Page', + 3 => 'PerPage', + 4 => 'event', + 5 => 'mode', ), 'IDField' => 'SkinId', 'StatusField' => Array('IsPrimary'), Index: units/spelling_dictionary/spelling_dictionary_config.php =================================================================== --- units/spelling_dictionary/spelling_dictionary_config.php (revision 13152) +++ units/spelling_dictionary/spelling_dictionary_config.php (working copy) @@ -26,8 +26,9 @@ 'QueryString' => Array ( 1 => 'id', 2 => 'Page', - 3 => 'event', - 4 => 'mode', + 3 => 'PerPage', + 4 => 'event', + 5 => 'mode', ), 'IDField' => 'SpellingDictionaryId', Index: units/statistics/statistics_config.php =================================================================== --- units/statistics/statistics_config.php (revision 13152) +++ units/statistics/statistics_config.php (working copy) @@ -24,10 +24,11 @@ 'AutoLoad' => true, 'QueryString' => Array( - 1 => 'id', - 2 => 'page', - 3 => 'event', - 4 => 'mode', + 1 => 'id', + 2 => 'Page', + 3 => 'PerPage', + 4 => 'event', + 5 => 'mode', ), 'IDField' => 'StatItemId', Index: units/stop_words/stop_words_config.php =================================================================== --- units/stop_words/stop_words_config.php (revision 13152) +++ units/stop_words/stop_words_config.php (working copy) @@ -26,8 +26,9 @@ 'QueryString' => Array ( 1 => 'id', 2 => 'Page', - 3 => 'event', - 4 => 'mode', + 3 => 'PerPage', + 4 => 'event', + 5 => 'mode', ), 'IDField' => 'StopWordId', Index: units/structure/structure_config.php =================================================================== --- units/structure/structure_config.php (revision 13152) +++ units/structure/structure_config.php (working copy) @@ -23,11 +23,12 @@ 'AutoLoad' => true, - 'QueryString' => Array( + 'QueryString' => Array( 1 => 'id', - 2 => 'page', - 3 => 'event', - 4 => 'mode', + 2 => 'Page', + 3 => 'PerPage', + 4 => 'event', + 5 => 'mode', ), 'ConfigPriority' => 0, 'Hooks' => Array( Index: units/stylesheets/stylesheets_config.php =================================================================== --- units/stylesheets/stylesheets_config.php (revision 13152) +++ units/stylesheets/stylesheets_config.php (working copy) @@ -34,10 +34,11 @@ ), ), 'QueryString' => Array( - 1 => 'id', - 2 => 'page', - 3 => 'event', - 4 => 'mode', + 1 => 'id', + 2 => 'Page', + 3 => 'PerPage', + 4 => 'event', + 5 => 'mode', ), 'IDField' => 'StylesheetId', Index: units/theme_files/theme_files_config.php =================================================================== --- units/theme_files/theme_files_config.php (revision 13152) +++ units/theme_files/theme_files_config.php (working copy) @@ -23,9 +23,10 @@ 'AutoLoad' => true, 'QueryString' => Array( - 1 => 'id', - 2 => 'page', - 3 => 'event', + 1 => 'id', + 2 => 'Page', + 3 => 'PerPage', + 4 => 'event', ), 'IDField' => 'FileId', Index: units/themes/themes_config.php =================================================================== --- units/themes/themes_config.php (revision 13152) +++ units/themes/themes_config.php (working copy) @@ -23,10 +23,11 @@ 'AutoLoad' => true, 'Hooks' => Array(), 'QueryString' => Array( - 1 => 'id', - 2 => 'Page', - 3 => 'event', - 4 => 'mode', + 1 => 'id', + 2 => 'Page', + 3 => 'PerPage', + 4 => 'event', + 5 => 'mode', ), 'IDField' => 'ThemeId', Index: units/thesaurus/thesaurus_config.php =================================================================== --- units/thesaurus/thesaurus_config.php (revision 13152) +++ units/thesaurus/thesaurus_config.php (working copy) @@ -26,8 +26,9 @@ 'QueryString' => Array ( 1 => 'id', 2 => 'Page', - 3 => 'event', - 4 => 'mode', + 3 => 'PerPage', + 4 => 'event', + 5 => 'mode', ), 'IDField' => 'ThesaurusId', Index: units/user_groups/user_groups_config.php =================================================================== --- units/user_groups/user_groups_config.php (revision 13152) +++ units/user_groups/user_groups_config.php (working copy) @@ -72,9 +72,10 @@ 'AutoLoad' => true, 'QueryString' => Array ( - 1 => 'id', - 2 => 'page', - 3 => 'event', + 1 => 'id', + 2 => 'Page', + 3 => 'PerPage', + 4 => 'event', ), 'IDField' => 'GroupId', Index: units/user_profile/user_profile_config.php =================================================================== --- units/user_profile/user_profile_config.php (revision 13152) +++ units/user_profile/user_profile_config.php (working copy) @@ -24,8 +24,8 @@ 'QueryString' => Array ( 1 => 'id', 2 => 'Page', - 3 => 'event', - 4 => 'mode', + 3 => 'PerPage', + 4 => 'event', ), 'IDField' => 'VariableId', Index: units/users/users_config.php =================================================================== --- units/users/users_config.php (revision 13152) +++ units/users/users_config.php (working copy) @@ -96,10 +96,11 @@ ), 'QueryString' => Array( - 1 => 'id', - 2 => 'Page', - 3 => 'event', - 4 => 'mode', + 1 => 'id', + 2 => 'Page', + 3 => 'PerPage', + 4 => 'event', + 5 => 'mode', ), 'RegularEvents' => Array( Index: units/visits/visits_config.php =================================================================== --- units/visits/visits_config.php (revision 13152) +++ units/visits/visits_config.php (working copy) @@ -23,10 +23,11 @@ 'AutoLoad' => true, 'QueryString' => Array ( - 1 => 'id', - 2 => 'Page', - 3 => 'event', - 4 => 'mode', + 1 => 'id', + 2 => 'Page', + 3 => 'PerPage', + 4 => 'event', + 5 => 'mode', ), 'Hooks' => Array (