You are here

function _js_injector_load_rule in JS injector 7

Same name and namespace in other branches
  1. 6.2 js_injector.module \_js_injector_load_rule()
  2. 6 js_injector.module \_js_injector_load_rule()

Helper function to load all JS injection rules.

7 calls to _js_injector_load_rule()
js_injector_admin_form in ./js_injector.admin.inc
Form builder function for JS Injector's main admin page.
js_injector_delete_confirm in ./js_injector.admin.inc
Menu callback -- ask for confirmation of rule deletion.
js_injector_edit in ./js_injector.admin.inc
Form builder function for the JS rule edit form.
js_injector_edit_save in ./js_injector.admin.inc
Submit button callback for the JS rule edit form.
js_injector_init in ./js_injector.module
Implements hook_init(). Checks to see whether any JS files should be added to the current page, based on rules configured by the site administrator.

... See full list

File

./js_injector.module, line 144
Allows administrators to inject JS into the page output based on configurable rules. Useful for adding simple JS tweaks without modifying a site's official theme.

Code

function _js_injector_load_rule($crid = NULL, $reset = FALSE) {
  static $rules;

  // TODO: Change to drupal_static_fast pattern.
  if (!isset($rules) || $reset) {
    if (!$reset && ($cache = cache_get('js_injector:rules')) && !empty($cache->data)) {
      $rules = $cache->data;
    }
    else {
      $rules = array();
      $results = db_query("SELECT * FROM {js_injector_rule}", array(), array(
        'fetch' => PDO::FETCH_ASSOC,
      ))
        ->fetchAllAssoc('crid');
      foreach ($results as $id => $rule) {
        $rules[$id] = $rule;
      }
      cache_set('js_injector:rules', $rules);
    }
  }
  if (is_numeric($crid)) {
    return $rules[$crid];
  }
  else {
    return $rules;
  }
}