| 1 |
<?php |
<?php |
| 2 |
// $Id: statistics_advanced.module,v 1.1.2.24 2009/04/17 02:27:44 davereid Exp $ |
// $Id: statistics_advanced.module,v 1.1.2.25 2009/05/26 03:57:48 davereid Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 46 |
*/ |
*/ |
| 47 |
function statistics_advanced_link_alter(&$links, $node) { |
function statistics_advanced_link_alter(&$links, $node) { |
| 48 |
// @todo Remove when http://drupal.org/node/321295 is fixed. |
// @todo Remove when http://drupal.org/node/321295 is fixed. |
| 49 |
if (!is_array($links) || !is_object($node)) { |
if (_statistics_advanced_check_link_alter($links, $node)) { |
|
$message = 'Invalid parameters for hook_link_alter(). Please report this message to <a href="http://drupal.org/node/321295">http://drupal.org/node/321295</a>.'; |
|
|
$backtrace = array_slice(debug_backtrace(), 1, 2); |
|
|
foreach($backtrace as $index => $caller) { |
|
|
$message .= '<br />'. t('line @line in @file (@function)', array('@file' => $caller['file'], '@line' => $caller['line'], '@function' => $caller['function'])); |
|
|
} |
|
|
drupal_set_message($message, 'error', FALSE); |
|
|
watchdog('statistics_adv', $message, array(), WATCHDOG_ERROR); |
|
| 50 |
return; |
return; |
| 51 |
} |
} |
| 52 |
|
|
| 59 |
} |
} |
| 60 |
|
|
| 61 |
/** |
/** |
| 62 |
|
* Check that the correct parameters are passed to hook_link_alter(). |
| 63 |
|
* |
| 64 |
|
* A lot of modules that were convered from Drupal 5 to 6 did not switch the |
| 65 |
|
* parameters around and cause errors. |
| 66 |
|
* |
| 67 |
|
* @todo Remove when http://drupal.org/node/321295 is fixed. |
| 68 |
|
*/ |
| 69 |
|
function _statistics_advanced_check_link_alter($links, $node) { |
| 70 |
|
if (!is_array($links) || !is_object($node)) { |
| 71 |
|
$message = 'Invalid parameters for hook_link_alter(). Please report this message to <a href="http://drupal.org/node/321295">http://drupal.org/node/321295</a>.'; |
| 72 |
|
$backtrace = array_slice(debug_backtrace(), 2, 2); |
| 73 |
|
foreach ($backtrace as $index => $caller) { |
| 74 |
|
$message .= '<br />'. strtr('line @line in @file (@function)', array('@file' => $caller['file'], '@line' => $caller['line'], '@function' => $caller['function'])); |
| 75 |
|
} |
| 76 |
|
drupal_set_message($message, 'error', FALSE); |
| 77 |
|
watchdog('statistics_adv', $message, array(), WATCHDOG_ERROR); |
| 78 |
|
return TRUE; |
| 79 |
|
} |
| 80 |
|
} |
| 81 |
|
|
| 82 |
|
/** |
| 83 |
* Implementation of hook_boot(). |
* Implementation of hook_boot(). |
| 84 |
* |
* |
| 85 |
* Checks to see if this is a unique content view by checking the 'accesslog' |
* Checks to see if this is a unique content view by checking the 'accesslog' |
| 163 |
elseif (statistics_advanced_user_access('exclude visits from counters')) { |
elseif (statistics_advanced_user_access('exclude visits from counters')) { |
| 164 |
_statistics_advanced_ignore('nodecounter', TRUE); |
_statistics_advanced_ignore('nodecounter', TRUE); |
| 165 |
} |
} |
| 166 |
/*else { |
//else { |
| 167 |
// If the node has been previously read by the user and has changed since |
// // If the node has been previously read by the user and has changed since |
| 168 |
// the last read, count it as a new read. |
// // the last read, count it as a new read. |
| 169 |
$changed = db_result(db_query("SELECT changed FROM {node} WHERE nid = %d", array(':nid' => arg(1)))); |
// $changed = db_result(db_query("SELECT changed FROM {node} WHERE nid = %d", array(':nid' => arg(1)))); |
| 170 |
$last_read = _statistics_advanced_ignore('nodecounter'); |
// $last_read = _statistics_advanced_ignore('nodecounter'); |
| 171 |
if ($last_read && $changed > $last_read) { |
// if ($last_read && $changed > $last_read) { |
| 172 |
_statistics_advanced_ignore('nodecounter', FALSE); |
// _statistics_advanced_ignore('nodecounter', FALSE); |
| 173 |
} |
// } |
| 174 |
}*/ |
//} |
| 175 |
} |
} |
| 176 |
|
|
| 177 |
// Check if user's access log entry should be ignored based on user role. |
// Check if user's access log entry should be ignored based on user role. |
| 207 |
* A copy of user.module's user_access() function so we do not need to load |
* A copy of user.module's user_access() function so we do not need to load |
| 208 |
* the entire user.module during cached visits. |
* the entire user.module during cached visits. |
| 209 |
*/ |
*/ |
| 210 |
function statistics_advanced_user_access($string, $account = NULL, $reset = FALSE) { |
function statistics_advanced_user_access($string, $account = NULL) { |
| 211 |
// If user.module is loaded, use that function call since it most likely has |
// If user.module is loaded, use that function call since it most likely has |
| 212 |
// the permissions already cached. |
// the permissions already cached. |
| 213 |
if (function_exists('user_access')) { |
if (function_exists('user_access')) { |
| 214 |
return user_access($string, $account, $reset); |
return user_access($string, $account); |
| 215 |
} |
} |
|
|
|
|
global $user; |
|
|
static $perm = array(); |
|
| 216 |
|
|
| 217 |
if ($reset) { |
static $perm = array(); |
|
$perm = array(); |
|
|
} |
|
| 218 |
|
|
| 219 |
if (is_null($account)) { |
if (!isset($account)) { |
| 220 |
|
global $user; |
| 221 |
$account = $user; |
$account = $user; |
| 222 |
} |
} |
| 223 |
|
|