You are here

function pardot_js in Pardot Integration 7

Same name and namespace in other branches
  1. 7.2 pardot.module \pardot_js()

Processes pardot_js() variables and adds settings.

@group themeable

1 call to pardot_js()
pardot_init in ./pardot.module
Implements hook_init().

File

./pardot.module, line 238
Pardot integration module.

Code

function pardot_js() {
  $settings['pardot_a_id'] = check_plain(variable_get('pardot_a_id', ''));

  // Compare with the internal and path alias (if any) to find any special campaigns.
  $results = db_query('SELECT campaign_id, paths FROM {pardot_campaign}');
  foreach ($results as $row) {
    $path = drupal_get_path_alias($_GET['q']);

    // Compare with the internal and path alias (if any).
    $page_match = drupal_match_path($path, $row->paths);
    if ($path != $_GET['q']) {
      $page_match = $page_match || drupal_match_path($_GET['q'], $row->paths);
    }
    if ($page_match) {
      $settings['pardot_c_id'] = check_plain($row->campaign_id);
      break;
    }
  }
  if (!isset($settings['pardot_c_id'])) {
    $settings['pardot_c_id'] = check_plain(variable_get('pardot_c_id', ''));
  }

  // Compare with the internal and path alias (if any) and add scoring.
  $path = drupal_get_path_alias($_GET['q']);
  $score = db_query("SELECT score FROM {pardot_scoring} WHERE path = :path", array(
    ':path' => $path,
  ))
    ->fetchField();
  if (!$score) {
    $score = db_query("SELECT score FROM {pardot_scoring} WHERE path = :path", array(
      ':path' => $_GET['q'],
    ))
      ->fetchField();
  }
  $settings['score'] = check_plain($score);
  drupal_add_js(array(
    'pardot' => $settings,
  ), 'setting');
}