View source
<?php
function cleanpager_menu($may_cache) {
$items = array();
if (cleanpager_check_match()) {
if (variable_get('cleanpager_use_seo_links', '') == 1) {
drupal_add_js(drupal_get_path('module', 'cleanpager') . '/cleanpager.js');
}
}
if ($may_cache == FALSE) {
return false;
}
$items[] = array(
'path' => 'admin/settings/cleanpage',
'title' => t('Clean Pagination Settings'),
'callback' => 'drupal_get_form',
'callback arguments' => 'cleanpager_admin_settings',
'access' => user_access('cleanpager administer'),
'description' => t('Global configuration of Clean Pagination functionality.'),
'type' => MENU_NORMAL_ITEM,
);
return $items;
}
function cleanpager_admin_settings() {
$form['cleanpager_pages'] = array(
'#title' => 'Pages',
'#description' => 'Set which pages to apply clean pagination to. Put each page on a new line and use the full page name, without a leading slash. Probably the easiest way to test this out to to create a view with only 1 or 2 nodes per page and add the URL to this list. An example how you would type a page is "admin/content/node".',
'#type' => 'textarea',
'#rows' => '7',
'#default_value' => variable_get('cleanpager_pages', ''),
);
$form['cleanpager_use_seo_links'] = array(
'#title' => 'Use SEO Links',
'#description' => 'Using SEO links will add the page URL to the pagination links, and then will remove them via jquery once the page is loaded.',
'#type' => 'checkbox',
'#default_value' => variable_get('cleanpager_use_seo_links', ''),
);
return system_settings_form($form);
}
function cleanpager_perm() {
return array(
"cleanpage administer",
);
}
function cleanpager_init() {
if (cleanpager_check_match()) {
$url_array = explode('/', $_GET['q']);
$page = end($url_array);
array_pop($url_array);
if (is_numeric($page)) {
$_GET['page'] = $page;
}
}
}
function cleanpager_check_match() {
$matches = variable_get('cleanpager_pages', '');
if (trim($matches) != '') {
$matches = explode("\n", $matches);
foreach ($matches as $match) {
$match = trim($match);
$match = str_replace('/', '\\/', $match);
if (preg_match('/' . $match . '([0-9]*)/', $_GET['q'])) {
return true;
break;
}
}
}
return false;
}
function phptemplate_pager_link($text, $page_new, $element, $parameters = array(), $attributes = array()) {
if (!cleanpager_check_match()) {
$q = $_GET['q'];
$page = isset($_GET['page']) ? $_GET['page'] : '';
if ($new_page = implode(',', pager_load_array($page_new[$element], $element, explode(',', $page)))) {
$parameters['page'] = $new_page;
}
}
else {
$new_page = implode(',', pager_load_array($page_new[$element], $element, explode(',', $page)));
$arguments = explode('/', $_GET['q']);
if ($_GET['page'] > 0) {
array_pop($arguments);
}
$pre_page_q = implode('/', $arguments);
$q .= $pre_page_q;
if ($new_page) {
$q .= '/' . $new_page;
}
}
$query = array();
if (count($parameters)) {
$query[] = drupal_query_string_encode($parameters, array());
}
$querystring = pager_get_querystring();
if ($querystring != '') {
$query[] = $querystring;
}
if (!isset($attributes['title'])) {
static $titles = NULL;
if (!isset($titles)) {
$titles = array(
t('« first') => t('Go to first page'),
t('‹ previous') => t('Go to previous page'),
t('next ›') => t('Go to next page'),
t('last »') => t('Go to last page'),
);
}
if (isset($titles[$text])) {
$attributes['title'] = $titles[$text];
}
else {
if (is_numeric($text)) {
$attributes['title'] = t('Go to page @number', array(
'@number' => $text,
));
}
}
if (is_numeric($text) && $q && variable_get('cleanpager_use_seo_links', '') == 1) {
$text = 'Visit ' . $pre_page_q . ' Page ' . ($new_page + 1);
}
}
return l($text, $q, $attributes, count($query) ? implode('&', $query) : NULL);
}
function cleanpager_footer() {
}