| 1 |
<?php
|
| 2 |
// $Id: click_heatmap.module,v 1.4 2008/02/04 20:02:08 boombatower Exp $
|
| 3 |
/**
|
| 4 |
* @file
|
| 5 |
* Provides an integration of the ClickHeat utility which creates click heatmaps.
|
| 6 |
*
|
| 7 |
* Copyright 2008 by Jimmy Berry ("boombatower", http://drupal.org/user/214218)
|
| 8 |
*/
|
| 9 |
|
| 10 |
/**
|
| 11 |
* Implementation of hook_help().
|
| 12 |
*/
|
| 13 |
function click_heatmap_help($page = "admin/help#click_heatmap", $arg) {
|
| 14 |
$output = '';
|
| 15 |
switch ($page) {
|
| 16 |
case 'admin/help#click_heatmap':
|
| 17 |
$output = t('<p>The Click Heatmap modules provides integration between Drupal and the ClickHeat library.
|
| 18 |
The module itself does not record the necessary data or generate the click heatmaps themselves.
|
| 19 |
Instead this module adds the necessary Javascript to Drupal pages in order to have the click data
|
| 20 |
sent to the ClickHeat library.</p>
|
| 21 |
<p>Please make sure that you setup the Click Heatmap settings and read the instructions on that page.</p>');
|
| 22 |
break;
|
| 23 |
case 'admin/settings/click_heatmap':
|
| 24 |
$output = t('<p>In order for the ClickHeat integration to work a server with the ClickHeat library
|
| 25 |
needs to be setup. The ClickHeat library can be downloaded from
|
| 26 |
<a href="http://www.labsmedia.com/clickheat/">http://www.labsmedia.com/clickheat/</a>.</p>
|
| 27 |
<p>The ClickHeat library comes with a setup tool and administration interface. The interface
|
| 28 |
can be used to view click heatmaps once the data has been recorded. This module will add
|
| 29 |
the necessary Javascript to pages under the specifed scope to send the click data to the
|
| 30 |
specified ClickHeat server.</p>
|
| 31 |
<p>Make sure that the server url specified relates to the root directory on a server that has the
|
| 32 |
ClickHeat library installed and configured.</p>');
|
| 33 |
break;
|
| 34 |
}
|
| 35 |
|
| 36 |
return $output;
|
| 37 |
}
|
| 38 |
|
| 39 |
/**
|
| 40 |
* Implementation of hook_menu().
|
| 41 |
*/
|
| 42 |
function click_heatmap_menu() {
|
| 43 |
$items = array();
|
| 44 |
|
| 45 |
$items['admin/settings/click_heatmap'] = array(
|
| 46 |
'title' => 'Click heatmap settings',
|
| 47 |
'description' => 'Configure click heatmap.',
|
| 48 |
'page callback' => 'drupal_get_form',
|
| 49 |
'page arguments' => array('click_heatmap_settings'),
|
| 50 |
'access callback' => 'user_access',
|
| 51 |
'access arguments' => array('administer heatmaps'),
|
| 52 |
);
|
| 53 |
return $items;
|
| 54 |
}
|
| 55 |
|
| 56 |
/**
|
| 57 |
* Implementation of hook_perm().
|
| 58 |
*/
|
| 59 |
function click_heatmap_perm() {
|
| 60 |
return array('administer heatmaps');
|
| 61 |
}
|
| 62 |
|
| 63 |
/**
|
| 64 |
* Implementation of hook_footer().
|
| 65 |
*/
|
| 66 |
function click_heatmap_footer() {
|
| 67 |
if (click_heatmap_display()) {
|
| 68 |
drupal_add_js(
|
| 69 |
"clickHeatSite = '". variable_get('site_name', 'Drupal Click Heatmap') ."';
|
| 70 |
clickHeatGroup = '". click_heatmap_get_url() ."';
|
| 71 |
clickHeatServer = '". variable_get('click_heatmap_server_url', '') ."/click.php';
|
| 72 |
initClickHeat();",
|
| 73 |
'inline', 'footer');
|
| 74 |
return '<script type="text/javascript" src="'. variable_get('click_heatmap_server_url', '') .'/js/clickheat.js"></script>'."\n";
|
| 75 |
}
|
| 76 |
}
|
| 77 |
|
| 78 |
/**
|
| 79 |
* Check to see if the click heatmap javascript should be added to the page.
|
| 80 |
*/
|
| 81 |
function click_heatmap_display() {
|
| 82 |
if (variable_get('click_heatmap_server_url', '') != '') {
|
| 83 |
switch (variable_get('click_heatmap_scope', 'home')) {
|
| 84 |
case 'all':
|
| 85 |
return TRUE;
|
| 86 |
case 'user':
|
| 87 |
return (strpos(substr(click_heatmap_get_url(), 0, 5), 'admin') === FALSE);
|
| 88 |
case 'admin':
|
| 89 |
return (strpos(substr(click_heatmap_get_url(), 0, 5), 'admin') !== FALSE);
|
| 90 |
case 'home':
|
| 91 |
return (click_heatmap_get_url() == 'home');
|
| 92 |
}
|
| 93 |
}
|
| 94 |
return FALSE;
|
| 95 |
}
|
| 96 |
|
| 97 |
/**
|
| 98 |
* Get the url to be used with ClickHeat system.
|
| 99 |
*/
|
| 100 |
function click_heatmap_get_url() {
|
| 101 |
if (isset($_GET['q'])) {
|
| 102 |
return ($_GET['q'] == variable_get('site_frontpage', 'node') ? 'home' : $_GET['q']);
|
| 103 |
}
|
| 104 |
return 'unknown';
|
| 105 |
}
|
| 106 |
|
| 107 |
/**
|
| 108 |
* Create the setting form.
|
| 109 |
*/
|
| 110 |
function click_heatmap_settings() {
|
| 111 |
$from = array();
|
| 112 |
$form['general'] = array(
|
| 113 |
'#type' => 'fieldset',
|
| 114 |
'#title' => t('General'),
|
| 115 |
'#description' => t('General setup information.'));
|
| 116 |
$form['general']['click_heatmap_server_url'] = array(
|
| 117 |
'#type' => 'textfield',
|
| 118 |
'#title' => t('Server url'),
|
| 119 |
'#description' => t('The location that the click data will be stored. Example http://drupal.org/clickheat'),
|
| 120 |
'#default_value' => variable_get('click_heatmap_server_url', '')
|
| 121 |
);
|
| 122 |
$form['general']['click_heatmap_scope'] = array(
|
| 123 |
'#type' => 'radios',
|
| 124 |
'#title' => t('Scope'),
|
| 125 |
'#description' => t('The pages that Click heatmaps will be generated for.'),
|
| 126 |
'#default_value' => variable_get('click_heatmap_scope', 'home'),
|
| 127 |
'#options' => array(
|
| 128 |
'all' => t('All pages'),
|
| 129 |
'user' => t('Non-admin pages'),
|
| 130 |
'admin' => t('Admin pages'),
|
| 131 |
'home' => t('Home page'),
|
| 132 |
)
|
| 133 |
);
|
| 134 |
|
| 135 |
return system_settings_form($form);
|
| 136 |
}
|
| 137 |
|
| 138 |
/**
|
| 139 |
* Ensure that the server url submitted is valid.
|
| 140 |
*/
|
| 141 |
function click_heatmap_settings_validate($form, &$form_state) {
|
| 142 |
// Check to make sure that the url does not end with '/'.
|
| 143 |
if ($form_state['values']['click_heatmap_server_url'][strlen($form_state['values']['click_heatmap_server_url']) - 1] == '/') {
|
| 144 |
form_set_error('click_heatmap_server_url', 'Server url must not end with a forward slash (/).');
|
| 145 |
}
|
| 146 |
|
| 147 |
// Make sure url is using http(s) protocol.
|
| 148 |
$uri = parse_url($form_state['values']['click_heatmap_server_url']);
|
| 149 |
if ($uri['scheme'] != 'http' && $uri['scheme'] != 'https') {
|
| 150 |
form_set_error('click_heatmap_server_url', 'Server url must use the http(s) protocol.');
|
| 151 |
}
|
| 152 |
|
| 153 |
// Make sure the url points to a valid installation.
|
| 154 |
$response = drupal_http_request($form_state['values']['click_heatmap_server_url'] .'/click.php');
|
| 155 |
|
| 156 |
if ($response->data != 'Parameters or config error') {
|
| 157 |
form_set_error('click_heatmap_server_url', 'Valid ClickHeat installation not found at server url.');
|
| 158 |
}
|
| 159 |
}
|