diff --git a/smart_paging.module b/smart_paging.module index b39c1fe..8d21752 100644 --- a/smart_paging.module +++ b/smart_paging.module @@ -1655,4 +1655,39 @@ function smart_paging_entities() { 'taxonomy_term', ); return $entities; -} \ No newline at end of file +} + +/** + * Intercept the views_view template to alter the pager links when AJAX is enabled + */ +function smart_paging_preprocess_views_view(&$vars) { + if ($vars['view']->use_ajax && isset($vars['pager'])) { + $vars['pager'] = preg_replace_callback('/href="(.+?)"/', '_smart_paging_href_replace', $vars['pager']); + } +} + +/** + * Callback function for fixing ajax pagination links + * Similar to smart_paging_url_inbound_alter() but returns the fixed + * path with the page in the query string rather than in $_GET + */ +function _smart_paging_href_replace($match) { + $path = trim($match[1], '/'); + $path_info = parse_url($path); + $args = arg(NULL, $path_info['path']); + $arg_count = count($args) - 1; + $page = $args[$arg_count]; + $sub_page = $args[$arg_count - 1]; + if ($arg_count > 2 && is_numeric($sub_page) && is_numeric($page)) { + if ($args[$arg_count - 2] == variable_get('smart_paging_path_prefix', 'page')) { + parse_str($path_info['query'], $query_array); + $query_array['page'] = "$sub_page,$page"; + $path_info['query'] = http_build_query($query_array); + $alias = arg(NULL, $path_info['path']); + unset($alias[$arg_count - 2], $alias[$arg_count - 1], $alias[$arg_count]); + $path_info['path'] = implode('/', $alias); + } + } + return 'href="/' . $path_info['path'] . '?' . urldecode($path_info['query']) . '"'; +} +