You are here

function cpn_preprocess_block in Code per Node 7

Same name and namespace in other branches
  1. 6 cpn.module \cpn_preprocess_block()

Implements of template_preprocess_block().

Adds files to the page (but only if they exist).

File

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

Code

function cpn_preprocess_block(&$vars) {
  $css = variable_get('cpn_path', 'public://cpn') . '/' . $vars['block']->module . '-' . $vars['block']->delta . '.css';
  $js = variable_get('cpn_path', 'public://cpn') . '/' . $vars['block']->module . '-' . $vars['block']->delta . '.js';
  if (is_file($css)) {
    $options = array(
      'type' => 'file',
      'group' => CSS_THEME,
      'weight' => variable_get('cpn_weight_css', CSS_THEME) + 1,
      'preprocess' => variable_get('cpn_aggregation_css', TRUE),
    );
    drupal_add_css($css, $options);
  }
  if (is_file($js)) {
    $options = array(
      'type' => 'file',
      'group' => JS_THEME,
      'weight' => variable_get('cpn_weight_js', JS_THEME) + 1,
      'preprocess' => variable_get('cpn_aggregation_js', TRUE),
    );
    drupal_add_js($js, $options);
  }

  // The noscript option has to be handled differently.
  try {
    $noscript = db_query("SELECT noscript FROM {block} WHERE module = :module AND delta = :delta", array(
      ':module' => $vars['block']->module,
      ':delta' => $vars['block']->delta,
    ))
      ->fetchField();
    if (!empty($noscript)) {
      if (is_array($vars['content'])) {
        $vars['content']['cpn']['#markup'] = cpn_output_noscript($noscript);
      }
      else {
        $vars['content'] .= cpn_output_noscript($noscript);
      }
    }
  } catch (Exception $e) {
    watchdog('cpn', 'Error loading block records for CPN, were the database updates ran?');
  }
}