-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdoubleclick_floodlight.module
118 lines (108 loc) · 4.49 KB
/
doubleclick_floodlight.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<?php
/**
* @file
* Functions for the doubleclick_floodlight tag module.
*/
/**
* Implements hook_help().
*/
function doubleclick_floodlight_help($path) {
switch ($path) {
case 'admin/help#doubleclick_floodlight':
$output = '<p>' . t('The Doubleclick Floodlight module allows you to integrate Floodlight Tags onto your site.') . '</p>';
return $output;
}
}
/**
* Implements hook_permission().
*/
function doubleclick_floodlight_permission() {
return array(
'administer doubleclick floodlight' => array(
'title' => t('Administer Doubleclick Floodlight'),
'description' => t('Users can enable, edit, and disable Doubleclick Floodlight tag.'),
),
);
}
/**
* Implements hook_menu().
*/
function doubleclick_floodlight_menu() {
$items = array();
$items['admin/config/services/floodlight'] = array(
'title' => 'Doubleclick Floodlight Settings',
'type' => MENU_LOCAL_TASK,
'description' => "Configure tag parameters.",
'page callback' => 'drupal_get_form',
'page arguments' => array('doubleclick_floodlight_admin_settings'),
'access arguments' => array('administer doubleclick floodlight'),
'file' => 'doubleclick_floodlight.admin.inc',
'weight' => 5,
);
return $items;
}
/**
* Implements hook_page_build().
*/
function doubleclick_floodlight_page_build(&$page) {
$enabled = variable_get('doubleclick_floodlight_enabled', 0);
// If module enabled & configured we'll display it on all pages but admin.
if ($enabled && !path_is_admin(current_path())) {
$region = variable_get('doubleclick_floodlight_region', 'page_top');
$account_id = variable_get('doubleclick_floodlight_account_id', '');
$type = variable_get('doubleclick_floodlight_type', '');
$cat = variable_get('doubleclick_floodlight_cat', '');
$show_standard = variable_get('doubleclick_floodlight_show_standard', 0);
$show_unique = variable_get('doubleclick_floodlight_show_unique', 0);
if (!empty($account_id)) {
if ($show_standard) {
$std_pix = doubleclick_floodlight_standard_pixel($account_id, $type, $cat);
$page[$region]['doubleclick_floodlight_std'] = array(
'#markup' => $std_pix,
);
}
if ($show_unique) {
$uniq_pix = doubleclick_floodlight_unique_pixel($account_id, $type, $cat);
$page[$region]['doubleclick_floodlight_uniq'] = array(
'#markup' => $uniq_pix,
);
}
}
}
}
/**
* Helper function to get the Standard doubleclick pixel.
*/
function doubleclick_floodlight_standard_pixel($account_id, $type, $cat) {
$script = array(
'<iframe id="doubleclick_floodlight_standard_pixel" width="1" height="1" frameborder="0" style="display:none"></iframe>',
'<script type="text/javascript">',
'(function(){',
'var url = \'https://' . check_plain($account_id) . '.fls.doubleclick.net/activityi;src=' . check_plain($account_id) . ';type=' . check_plain($type) . ';cat=' . check_plain($cat) . ';ord=\' + Math.random() * 10000000000000 + \'?\';',
'document.getElementById(\'doubleclick_floodlight_standard_pixel\').setAttribute(\'src\', url);',
'})();',
'</script>',
'<noscript>',
'<iframe src="https://' . check_plain($account_id) . '.fls.doubleclick.net/activityi;src=' . check_plain($account_id) . ';type=' . check_plain($type) . ';cat=' . check_plain($cat) . ';ord=1?" width="1" height="1" frameborder="0" style="display:none"></iframe>',
'</noscript>',
);
return implode(PHP_EOL, $script);
}
/**
* Helper function to get the Unique doubleclick pixel.
*/
function doubleclick_floodlight_unique_pixel($account_id, $type, $cat) {
$script = array(
'<iframe id="doubleclick_floodlight_unique_pixel" width="1" height="1" frameborder="0" style="display:none"></iframe>',
'<script type="text/javascript">',
'(function(){',
'var url = \'https://' . check_plain($account_id) . '.fls.doubleclick.net/activityi;src=' . check_plain($account_id) . ';type=' . check_plain($type) . ';cat=' . check_plain($cat) . ';ord=1;num=\' + Math.random() * 10000000000000 + \'?\';',
'document.getElementById(\'doubleclick_floodlight_unique_pixel\').setAttribute(\'src\', url);',
'})();',
'</script>',
'<noscript>',
'<iframe src="https://' . check_plain($account_id) . '.fls.doubleclick.net/activityi;src=' . check_plain($account_id) . ';type=' . check_plain($type) . ';cat=' . check_plain($cat) . ';ord=1;num=1?" width="1" height="1" frameborder="0" style="display:none"></iframe>',
'</noscript>',
);
return implode(PHP_EOL, $script);
}