You are here

function jstimer_load_js in Javascript Timer 7

Same name and namespace in other branches
  1. 6 jstimer.module \jstimer_load_js()

Determine whether or not to to add javascript.

Return value

boolean TRUE if the javascript should be added, FALSE otherwise.

File

./jstimer.module, line 108

Code

function jstimer_load_js() {
  $js_load_option = variable_get('jstimer_js_load_option', DEFAULT_JS_LOAD);
  if ($js_load_option == 1) {

    //every page
    return TRUE;
  }
  else {
    if ($js_load_option == 2 || $js_load_option == 0) {
      if ($js_load_option == 0) {

        // all nodes
        $pages = 'node/*';
        $exclude = '';
      }
      else {

        // page list
        $pages = variable_get('jstimer_js_load_pages', '');
        $exclude = variable_get('jstimer_js_exclude_pages', '');
      }
      $path = drupal_get_path_alias($_GET['q']);
      if ($exclude) {
        $regexp = '/^(' . preg_replace(array(
          '/(\\r\\n?|\\n)/',
          '/\\\\\\*/',
          '/(^|\\|)\\\\<front\\\\>($|\\|)/',
        ), array(
          '|',
          '.*',
          '\\1' . preg_quote(variable_get('site_frontpage', 'node'), '/') . '\\2',
        ), preg_quote($exclude, '/')) . ')$/';
        $page_match = preg_match($regexp, $path);
        if ($path != $_GET['q']) {
          $page_match = $page_match || preg_match($regexp, $_GET['q']);
        }
        if ($page_match) {
          return 0;
        }
      }
      $regexp = '/^(' . preg_replace(array(
        '/(\\r\\n?|\\n)/',
        '/\\\\\\*/',
        '/(^|\\|)\\\\<front\\\\>($|\\|)/',
      ), array(
        '|',
        '.*',
        '\\1' . preg_quote(variable_get('site_frontpage', 'node'), '/') . '\\2',
      ), preg_quote($pages, '/')) . ')$/';

      // Compare with the internal and path alias (if any).
      $page_match = preg_match($regexp, $path);
      if ($path != $_GET['q']) {
        $page_match = $page_match || preg_match($regexp, $_GET['q']);
      }
      return $page_match == 1;
    }
  }
}