You are here

function cpn_init in Code per Node 6

Implementation of hook_init().

File

./cpn.module, line 163
Primary hook implementations.

Code

function cpn_init() {
  $page_is_admin = arg(0) == 'admin';
  foreach (array(
    'css',
    'js',
  ) as $type) {

    // Only proceed if the 'agree' option was checked and if some code was
    // actually saved.
    $agree = variable_get('cpn_global_' . $type . '_agree', FALSE);
    $code = variable_get('cpn_global_' . $type, '');
    if ($agree && !empty($code)) {

      // Only proceed if either this is not an admin page or if the 'load on
      // admin pages too' option was checked.
      $force_on_admin = (bool) variable_get('cpn_global_' . $type . '_admin', FALSE);
      if (!$page_is_admin || $force_on_admin) {
        $file = file_create_path(variable_get('cpn_path', 'cpn') . '/global.' . $type);
        if (!empty($file)) {
          if ($type == 'css') {
            drupal_add_css($file, 'theme', NULL, variable_get('cpn_aggregation_css', TRUE));
          }
          else {
            drupal_add_js($file, 'theme', 'header', TRUE, variable_get('cpn_aggregation_js', TRUE));
          }
        }
      }
    }
  }
}