| 1 |
<?php
|
| 2 |
// $Id$
|
| 3 |
/**
|
| 4 |
* @file
|
| 5 |
* Provides an integration with StatCounter which logs user activity.
|
| 6 |
*
|
| 7 |
* Copyright 2008 by Jimmy Berry ("boombatower", http://drupal.org/user/214218)
|
| 8 |
*/
|
| 9 |
|
| 10 |
/**
|
| 11 |
* Implementation of hook_help().
|
| 12 |
*/
|
| 13 |
function statcounter_help($section = "admin/help#statcounter") {
|
| 14 |
$output = '';
|
| 15 |
switch ($section) {
|
| 16 |
case 'admin/help#statcounter':
|
| 17 |
$output = t('<p>The StatCounter module provides an integration of StatCounter for Drupal. The
|
| 18 |
module allows you to insert tracking code on pages within the specific scope. For more detialed
|
| 19 |
instructions please visit the StatCounter settings and read the instructions on that page.</p>
|
| 20 |
<p>If you would like to change the location of the code on the page goto
|
| 21 |
<a href="'. base_path() .'admin/build/block' .'">admin/build/block</a> and change the location of the "StatCounter"
|
| 22 |
block.</p>');
|
| 23 |
break;
|
| 24 |
case 'admin/settings/statcounter':
|
| 25 |
$output = t('<p>To setup a StatCounter project with the integration module please visit
|
| 26 |
<a href="http://statcounter.com">http://statcounter.com</a> and perform the following setups:</p>
|
| 27 |
<ol>
|
| 28 |
<li>Login to your account.</li>
|
| 29 |
<li>Create the project to be used if you haven\'t already.</li>
|
| 30 |
<li>Click on the wrench icon for that project.</li>
|
| 31 |
<li>Click "Install Code."</li>
|
| 32 |
<li>Setup the code the way you prefer, but on the "Installation Options" screen select
|
| 33 |
"No, I want the default install guide" instead of "Yes, I use."</li>
|
| 34 |
<li>Copy the code in the textarea and paste it into the textarea below labled code.</li>
|
| 35 |
<li>Set the scope.</li>
|
| 36 |
</ol>');
|
| 37 |
break;
|
| 38 |
}
|
| 39 |
|
| 40 |
return $output;
|
| 41 |
}
|
| 42 |
|
| 43 |
/**
|
| 44 |
* Implementation of hook_menu().
|
| 45 |
*/
|
| 46 |
function statcounter_menu($may_cache) {
|
| 47 |
if ($may_cache) {
|
| 48 |
$items = array(
|
| 49 |
array(
|
| 50 |
'path' => 'admin/settings/statcounter',
|
| 51 |
'title' => t('StatCounter'),
|
| 52 |
'description' => t('Configure StatCounter integration.'),
|
| 53 |
'callback' => 'drupal_get_form',
|
| 54 |
'callback arguments' => array('statcounter_settings'),
|
| 55 |
'access' => user_access('administer statcounter'))
|
| 56 |
);
|
| 57 |
return $items;
|
| 58 |
}
|
| 59 |
}
|
| 60 |
|
| 61 |
/**
|
| 62 |
* Implementation of hook_perm().
|
| 63 |
*/
|
| 64 |
function statcounter_perm() {
|
| 65 |
return array('administer statcounter');
|
| 66 |
}
|
| 67 |
|
| 68 |
/**
|
| 69 |
* Implementation of hook_block().
|
| 70 |
*/
|
| 71 |
function statcounter_block($op = 'list', $delta = 0, $edit = array()) {
|
| 72 |
switch ($op) {
|
| 73 |
case 'list':
|
| 74 |
$blocks = array();
|
| 75 |
$blocks[0]['info'] = t('StatCounter');
|
| 76 |
return $blocks;
|
| 77 |
case 'configure':
|
| 78 |
return array();
|
| 79 |
case 'save':
|
| 80 |
return;
|
| 81 |
case 'view': default:
|
| 82 |
if (statcounter_display()) {
|
| 83 |
$block = array();
|
| 84 |
$block['content'] = variable_get('statcounter_code', '');
|
| 85 |
return $block;
|
| 86 |
}
|
| 87 |
}
|
| 88 |
}
|
| 89 |
|
| 90 |
/**
|
| 91 |
* Check to see if the StatCounter code should be added to the page.
|
| 92 |
*/
|
| 93 |
function statcounter_display() {
|
| 94 |
if (variable_get('statcounter_code', '') != '') {
|
| 95 |
switch (variable_get('statcounter_scope', 'home')) {
|
| 96 |
case 'all':
|
| 97 |
return TRUE;
|
| 98 |
case 'user':
|
| 99 |
return (strpos(substr(statcounter_get_url(), 0, 5), 'admin') === FALSE);
|
| 100 |
case 'admin':
|
| 101 |
return (strpos(substr(statcounter_get_url(), 0, 5), 'admin') !== FALSE);
|
| 102 |
case 'home':
|
| 103 |
return (statcounter_get_url() == 'home');
|
| 104 |
}
|
| 105 |
}
|
| 106 |
return FALSE;
|
| 107 |
}
|
| 108 |
|
| 109 |
/**
|
| 110 |
* Get the url to be used with for checking.
|
| 111 |
*/
|
| 112 |
function statcounter_get_url() {
|
| 113 |
if (isset($_GET['q'])) {
|
| 114 |
return ($_GET['q'] == variable_get('site_frontpage', 'node') ? 'home' : $_GET['q']);
|
| 115 |
}
|
| 116 |
return 'unknown';
|
| 117 |
}
|
| 118 |
|
| 119 |
/**
|
| 120 |
* Create the setting form.
|
| 121 |
*/
|
| 122 |
function statcounter_settings() {
|
| 123 |
$from = array();
|
| 124 |
$form['general'] = array(
|
| 125 |
'#type' => 'fieldset',
|
| 126 |
'#title' => t('General'),
|
| 127 |
'#description' => t('General setup information.'));
|
| 128 |
$form['general']['statcounter_code'] = array(
|
| 129 |
'#type' => 'textarea',
|
| 130 |
'#rows' => '12',
|
| 131 |
'#title' => t('Code'),
|
| 132 |
'#description' => t('Place the StatCounter code that will be inserted on pages within the specified scope.'),
|
| 133 |
'#default_value' => variable_get('statcounter_code', '')
|
| 134 |
);
|
| 135 |
$form['general']['statcounter_scope'] = array(
|
| 136 |
'#type' => 'radios',
|
| 137 |
'#title' => t('Scope'),
|
| 138 |
'#description' => t('The pages that the StatCounter code will be inserted on.'),
|
| 139 |
'#default_value' => variable_get('statcounter_scope', 'home'),
|
| 140 |
'#options' => array(
|
| 141 |
'all' => t('All pages'),
|
| 142 |
'user' => t('Non-admin pages'),
|
| 143 |
'admin' => t('Admin pages'),
|
| 144 |
'home' => t('Home page'),
|
| 145 |
)
|
| 146 |
);
|
| 147 |
|
| 148 |
return system_settings_form($form);
|
| 149 |
}
|
| 150 |
|
| 151 |
/**
|
| 152 |
* Save variables and setup block if first save.
|
| 153 |
*/
|
| 154 |
function statcounter_settings_submit($form_id, $form_values) {
|
| 155 |
variable_set('statcounter_code', $form_values['statcounter_code']);
|
| 156 |
variable_set('statcounter_scope', $form_values['statcounter_scope']);
|
| 157 |
drupal_set_message(t('The configuration options have been saved.'));
|
| 158 |
|
| 159 |
if (variable_get('statcounter_code', '') == '') { // First time.
|
| 160 |
global $theme_key;
|
| 161 |
|
| 162 |
init_theme();
|
| 163 |
|
| 164 |
$block = array();
|
| 165 |
$block['status'] = 1;
|
| 166 |
$block['weight'] = 0;
|
| 167 |
$block['region'] = 'footer';
|
| 168 |
$block['module'] = 'statcounter';
|
| 169 |
$block['delta'] = 0;
|
| 170 |
$block['theme'] = $theme_key;
|
| 171 |
|
| 172 |
block_admin_display_submit('block_admin_display', array($block));
|
| 173 |
}
|
| 174 |
}
|