You are here

function cleanpager_init in Clean Pagination 7

Same name and namespace in other branches
  1. 5 cleanpager.module \cleanpager_init()
  2. 6 cleanpager.module \cleanpager_init()

Implements hook_init().

File

./cleanpager.module, line 106

Code

function cleanpager_init() {
  global $_cleanpager_rewritten;

  // The current url looks like /test?page=1 but it should have clean pager
  $path = cleanpager_path();
  if (!$_cleanpager_rewritten && variable_get('cleanpager_redirect_301', FALSE) && isset($_GET['page']) && cleanpager_match_path($path)) {
    $path = _cleanpager_generate_current_page_url();

    // Pass along additional query string values.
    $query_values = $_GET;
    unset($query_values['page']);
    if (isset($query_values['q'])) {
      unset($query_values['q']);
    }

    // Execut the redirect.
    drupal_goto($path, array(
      'query' => $query_values,
    ), 301);
  }
  elseif (cleanpager_check_match()) {
    if (variable_get('cleanpager_add_can_link', FALSE)) {
      $path = _cleanpager_generate_current_page_url();
      drupal_add_html_head_link(array(
        'rel' => 'canonical',
        'href' => url($path, array(
          'absolute' => TRUE,
        )),
      ));
    }
    if (variable_get('cleanpager_use_seo_links', '') == 1) {
      drupal_add_js(drupal_get_path('module', 'cleanpager') . '/cleanpager.js');
    }
  }
}