| 1 |
<?php |
<?php |
| 2 |
|
|
| 3 |
//$Id: click.module,v 1.5.2.2 2007/02/25 22:18:03 kbahey Exp $ |
//$Id$ |
| 4 |
|
//$Name$ |
| 5 |
// Copyright 2005 Khalid Baheyeldin http://2bits.com |
// Copyright 2005 Khalid Baheyeldin http://2bits.com |
| 6 |
|
|
| 7 |
define(CLICK_IGNORE_SITE, 'click_ignore_site'); |
define(CLICK_IGNORE_SITE, 'click_ignore_site'); |
| 9 |
define(CLICK_CRON_TIMESTAMP_DAY, 'click_cron_timestamp_day'); |
define(CLICK_CRON_TIMESTAMP_DAY, 'click_cron_timestamp_day'); |
| 10 |
define(CLICK_CRON_TIMESTAMP_WEEK, 'click_cron_timestamp_week'); |
define(CLICK_CRON_TIMESTAMP_WEEK, 'click_cron_timestamp_week'); |
| 11 |
|
|
| 12 |
function click_help($section) { |
/** |
| 13 |
switch ($section) { |
* Implementation of hook_help(). |
| 14 |
case 'admin/settings/click': |
*/ |
| 15 |
|
function click_help($path, $arg) { |
| 16 |
|
switch ($path) { |
| 17 |
|
case 'admin/help#click': |
| 18 |
$output = t('Track click thrus from newletters and ads on other sites'); |
$output = t('Track click thrus from newletters and ads on other sites'); |
| 19 |
break; |
break; |
| 20 |
} |
} |
| 21 |
return $output; |
return $output; |
| 22 |
} |
} |
| 23 |
|
|
| 24 |
|
/** |
| 25 |
|
* Implementation of hook_perm(). |
| 26 |
|
*/ |
| 27 |
function click_perm() { |
function click_perm() { |
| 28 |
return array ('view click links', 'view click stats'); |
return array ('view click links', 'view click stats'); |
| 29 |
} |
} |
| 30 |
|
|
| 31 |
function click_menu($may_cache) { |
/** |
| 32 |
|
* Implementation of hook_menu(). |
| 33 |
|
*/ |
| 34 |
|
function click_menu() { |
| 35 |
$items = array(); |
$items = array(); |
| 36 |
|
|
| 37 |
$nid = 0; |
$items['node/%click_nid/click'] = array( |
| 38 |
$gid = 0; |
'title' => 'Clicks', |
| 39 |
|
'page callback' => 'click_view', |
| 40 |
if (is_numeric(arg(1))) { |
'page arguments' => array(1), |
| 41 |
$nid = (int)arg(1); |
'access arguments' => array('view click stats'), |
| 42 |
} |
'weight' => 10, |
| 43 |
|
'type' => MENU_LOCAL_TASK, |
| 44 |
if (is_numeric(arg(2))) { |
); |
| 45 |
$gid = (int)arg(2); |
$items['click/%click_nid/%click_gid'] = array( |
| 46 |
} |
'page callback' => 'click_do', |
| 47 |
|
'page arguments' => array(1, 2), |
| 48 |
if (arg(0) == 'node' && $nid) { |
'access arguments' => array('access content'), |
| 49 |
$items[] = array( |
'type' => MENU_CALLBACK, |
| 50 |
'path' => "node/$nid/click", |
); |
| 51 |
'callback' => 'click_view', |
$items['admin/settings/click'] = array( |
| 52 |
'title' => t('clicks'), |
'title' => 'Click Thru tracking', |
| 53 |
'access' => user_access('view click stats'), |
'description' => 'Settings of the Click Thru tracking module', |
| 54 |
'weight' => 10, |
'page callback' => 'drupal_get_form', |
| 55 |
'type' => MENU_LOCAL_TASK, |
'page arguments' => array('click_admin_settings'), |
| 56 |
); |
'access arguments' => array('administer site configuration'), |
| 57 |
} |
'type' => MENU_NORMAL_ITEM, |
| 58 |
|
); |
| 59 |
$items[] = array( |
$items['admin/reports/click'] = array( |
| 60 |
'path' => "click/$nid/$gid", |
'title' => 'Click report', |
| 61 |
'callback' => 'click_do', |
'page callback' => 'click_report', |
| 62 |
'access' => TRUE, |
'access arguments' => array('view click stats'), |
| 63 |
'type' => MENU_CALLBACK, |
'type' => MENU_NORMAL_ITEM, |
| 64 |
); |
); |
|
|
|
|
if ($may_cache) { |
|
|
$items[] = array( |
|
|
'path' => 'admin/settings/click', |
|
|
'title' => 'Click Thru tracking', |
|
|
'description' => t('Settings of the Click Thru tracking module'), |
|
|
'callback' => 'drupal_get_form', |
|
|
'callback arguments' => array('click_admin_settings'), |
|
|
'access' => user_access('administer site configuration'), |
|
|
); |
|
|
|
|
|
$items[] = array( |
|
|
'path' => 'admin/logs/click', |
|
|
'title' => t('clicks'), |
|
|
'callback' => 'click_report', |
|
|
'access' => user_access('view click stats'), |
|
|
'type' => MENU_NORMAL_ITEM, |
|
|
); |
|
|
} |
|
| 65 |
|
|
| 66 |
return $items; |
return $items; |
| 67 |
} |
} |
| 68 |
|
|
| 69 |
|
/** |
| 70 |
|
* Menu callback; presents the settings form for click |
| 71 |
|
*/ |
| 72 |
function click_admin_settings() { |
function click_admin_settings() { |
| 73 |
global $user; |
global $user; |
| 74 |
$click_group = CLICK_GROUP . $user->uid; |
$click_group = CLICK_GROUP . $user->uid; |
| 126 |
return $links; |
return $links; |
| 127 |
} |
} |
| 128 |
|
|
| 129 |
function click_view() { |
function click_view($nid) { |
|
$nid = arg(1); |
|
| 130 |
$fmt = 'Y-m-d H:i:s'; |
$fmt = 'Y-m-d H:i:s'; |
| 131 |
|
|
| 132 |
$result = db_query('SELECT * FROM {clicks} WHERE nid = %d ORDER BY gid ASC', $nid); |
$result = db_query('SELECT * FROM {clicks} WHERE nid = %d ORDER BY gid ASC', $nid); |
| 140 |
$rows[] = array(array('data' => ('Last click at: ')), array('data' => format_date($click->last, 'custom', $fmt))); |
$rows[] = array(array('data' => ('Last click at: ')), array('data' => format_date($click->last, 'custom', $fmt))); |
| 141 |
$output .= $group . theme('table', array(), $rows); |
$output .= $group . theme('table', array(), $rows); |
| 142 |
} |
} |
| 143 |
print theme('page', $output); |
return theme('page', $output); |
| 144 |
} |
} |
| 145 |
|
|
| 146 |
function click_report() { |
function click_report() { |
|
|
|
| 147 |
$header = array( |
$header = array( |
| 148 |
array('data' => t('group'), 'field' => 'gid'), |
array('data' => t('group'), 'field' => 'gid'), |
| 149 |
array('data' => t('node title'), 'field' => 'title'), |
array('data' => t('node title'), 'field' => 'title'), |
| 151 |
array('data' => t('week clicks'), 'field' => 'week_clicks'), |
array('data' => t('week clicks'), 'field' => 'week_clicks'), |
| 152 |
array('data' => t('total clicks'), 'field' => 'total_clicks') |
array('data' => t('total clicks'), 'field' => 'total_clicks') |
| 153 |
); |
); |
| 154 |
|
|
| 155 |
$sql = 'SELECT n.title, c.* FROM {clicks} c, {node} n WHERE c.nid = n.nid' . tablesort_sql($header); |
$sql = 'SELECT n.title, c.* FROM {clicks} c, {node} n WHERE c.nid = n.nid' . tablesort_sql($header); |
| 156 |
$result = pager_query($sql, 50); |
$result = pager_query($sql, 50); |
| 157 |
while ($click = db_fetch_object($result)) { |
while ($click = db_fetch_object($result)) { |
| 166 |
if (!$rows) { |
if (!$rows) { |
| 167 |
$rows[] = array(array('data' => t('No data.'), 'colspan' => '4')); |
$rows[] = array(array('data' => t('No data.'), 'colspan' => '4')); |
| 168 |
} |
} |
| 169 |
|
|
| 170 |
$pager = theme('pager', NULL, 50, 0); |
$pager = theme('pager', NULL, 50, 0); |
| 171 |
|
|
| 172 |
if (!empty($pager)) { |
if (!empty($pager)) { |
| 173 |
$rows[] = array(array('data' => $pager, 'colspan' => '4')); |
$rows[] = array(array('data' => $pager, 'colspan' => '4')); |
| 174 |
} |
} |
| 175 |
print theme('page', theme('table', $header, $rows), t('Click Thru Report')); |
|
| 176 |
|
return theme('page', theme('table', $header, $rows), t('Click Thru Report')); |
| 177 |
} |
} |
| 178 |
|
|
| 179 |
function click_do() { |
function click_do($nid, $group) { |
| 180 |
global $base_url; |
global $base_url; |
| 181 |
|
|
|
$nid = (int)arg(1); |
|
|
$group = (int)arg(2); |
|
| 182 |
$path = "node/$nid"; |
$path = "node/$nid"; |
|
|
|
| 183 |
$ignore = variable_get(CLICK_IGNORE_SITE, 0); |
$ignore = variable_get(CLICK_IGNORE_SITE, 0); |
| 184 |
$referer = $_SERVER['HTTP_REFERER']; |
$referer = $_SERVER['HTTP_REFERER']; |
| 185 |
if ($ignore && stristr($referer, $base_url)) { |
if ($ignore && stristr($referer, $base_url)) { |
| 194 |
} |
} |
| 195 |
|
|
| 196 |
function click_insert_update($nid, $group = 0) { |
function click_insert_update($nid, $group = 0) { |
|
|
|
| 197 |
$num = db_result(db_query('SELECT nid FROM {clicks} WHERE nid = %d AND gid = %d', $nid, $group)); |
$num = db_result(db_query('SELECT nid FROM {clicks} WHERE nid = %d AND gid = %d', $nid, $group)); |
| 198 |
if ($num > 0) { |
if ($num > 0) { |
| 199 |
db_query('UPDATE {clicks} SET day_clicks = day_clicks + 1, |
db_query('UPDATE {clicks} SET day_clicks = day_clicks + 1, |
| 224 |
db_query('UPDATE {clicks} SET week_clicks = 0'); |
db_query('UPDATE {clicks} SET week_clicks = 0'); |
| 225 |
} |
} |
| 226 |
} |
} |
| 227 |
|
|
| 228 |
|
function click_nid_load($arg) { |
| 229 |
|
return (is_numeric($arg) ? $arg : FALSE); |
| 230 |
|
} |
| 231 |
|
|
| 232 |
|
function click_gid_load($arg) { |
| 233 |
|
return (is_numeric($arg) ? $arg : FALSE); |
| 234 |
|
} |