eloqua.module in Eloqua 7
Same filename and directory in other branches
Eloqua Integration Module
This module provides Eloqua visitor tracking and some basic configuration.
@package Eloqua
File
eloqua.moduleView source
<?php
/**
* @file
* Eloqua Integration Module
*
* This module provides Eloqua visitor tracking and some basic configuration.
*
* @package Eloqua
*/
define('ELOQUA_PAGES', "admin\nadmin/*\nbatch\nnode/add*\nnode/*/*\nuser/*/*");
/**
* Implements hook_init().
*/
function eloqua_init() {
global $user;
if (_eloqua_visibility_pages() == 1) {
if (_eloqua_visibility_roles($user)) {
$site_id = check_plain(variable_get('eloqua_site_id', 0));
drupal_add_js(array(
'eloqua' => array(
'siteId' => $site_id,
),
), 'setting');
drupal_add_js(drupal_get_path('module', 'eloqua') . '/eloqua.js');
}
}
}
/**
* Implements hook_menu().
*/
function eloqua_menu() {
$items['admin/config/services/eloqua'] = array(
'title' => 'Eloqua',
'description' => 'Create and edit Eloqua settings.',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'eloqua_admin_form',
),
'access arguments' => array(
'access administration pages',
),
'type' => MENU_NORMAL_ITEM,
'file' => 'eloqua.admin.inc',
);
return $items;
}
/**
* Based on visibility setting this function returns TRUE if the Eloqua code
* should be added to the current page and otherwise FALSE.
*/
function _eloqua_visibility_pages() {
static $page_match;
// Cache visibility result if function is called more than once.
if (!isset($page_match)) {
$visibility = variable_get('eloqua_visibility_pages', 0);
$setting_pages = variable_get('eloqua_pages', ELOQUA_PAGES);
// Match path if necessary.
if (!empty($setting_pages)) {
// Convert path to lowercase. This allows comparison of the same path
// with different case. Ex: /Page, /page, /PAGE.
$pages = drupal_strtolower($setting_pages);
if ($visibility < 2) {
// Convert the Drupal path to lowercase
$path = drupal_strtolower(drupal_get_path_alias($_GET['q']));
// Compare the lowercase internal and lowercase path alias (if any).
$page_match = drupal_match_path($path, $pages);
if ($path != $_GET['q']) {
$page_match = $page_match || drupal_match_path($_GET['q'], $pages);
}
// When $visibility has a value of 0, the tracking code is displayed on
// all pages except those listed in $pages. When set to 1, it
// is displayed only on those pages listed in $pages.
$page_match = !($visibility xor $page_match);
}
elseif (module_exists('php')) {
$page_match = php_eval($setting_pages);
}
else {
$page_match = FALSE;
}
}
else {
$page_match = TRUE;
}
}
return $page_match;
}
/**
* Based on visibility setting this function returns TRUE if the Eloqua code
* should be added for the current role and otherwise FALSE.
*/
function _eloqua_visibility_roles($user) {
$visibility = variable_get('eloqua_visibility_roles', 0);
$enabled = $visibility;
$roles = variable_get('eloqua_roles', array());
if (array_sum($roles) > 0) {
// One or more roles are selected.
foreach (array_keys($user->roles) as $rid) {
// Is the current user a member of one of these roles?
if (isset($roles[$rid]) && $rid == $roles[$rid]) {
// Current user is a member of a role that should be tracked/excluded from tracking.
$enabled = !$visibility;
break;
}
}
}
else {
// No role is selected for tracking, therefore all roles should be tracked.
$enabled = TRUE;
}
return $enabled;
}
Functions
Name | Description |
---|---|
eloqua_init | Implements hook_init(). |
eloqua_menu | Implements hook_menu(). |
_eloqua_visibility_pages | Based on visibility setting this function returns TRUE if the Eloqua code should be added to the current page and otherwise FALSE. |
_eloqua_visibility_roles | Based on visibility setting this function returns TRUE if the Eloqua code should be added for the current role and otherwise FALSE. |
Constants
Name | Description |
---|---|
ELOQUA_PAGES | @file Eloqua Integration Module |