1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Provides a preprocess function for the author pane used by
|
6
|
* Advanced Forum and Advanced Profile Kit.
|
7
|
*/
|
8
|
|
9
|
/**
|
10
|
* Implements hook_preprocess_author_pane().
|
11
|
*/
|
12
|
function user_stats_preprocess_author_pane(&$variables) {
|
13
|
if (function_exists('author_pane_api') && author_pane_api() == "2") {
|
14
|
// Check if this preprocess needs to be run given who's calling it.
|
15
|
if (!author_pane_run_preprocess('user_stats', $variables['caller'])) {
|
16
|
return;
|
17
|
}
|
18
|
}
|
19
|
|
20
|
$account_id = $variables['account']->uid;
|
21
|
|
22
|
if ($account_id != 0) {
|
23
|
static $cached_stats = array();
|
24
|
if (isset($cached_stats[$account_id])) {
|
25
|
// Pull the values from the cache
|
26
|
if ($cached_stats[$account_id]['posts'] !== FALSE) {
|
27
|
// We don't want the variable to be created if the user doesn't have
|
28
|
// access to see them to avoid printing the label.
|
29
|
$variables['user_stats_posts'] = $cached_stats[$account_id]['posts'];
|
30
|
}
|
31
|
|
32
|
if ($cached_stats[$account_id]['ip'] !== FALSE) {
|
33
|
$variables['user_stats_ip'] = $cached_stats[$account_id]['ip'];
|
34
|
}
|
35
|
}
|
36
|
else {
|
37
|
// No cached values for this user. Fetch them.
|
38
|
$posts = user_stats_get_stats('post_count', $account_id);
|
39
|
if ($posts !== FALSE) {
|
40
|
$variables['user_stats_posts'] = $posts;
|
41
|
}
|
42
|
|
43
|
$ip = user_stats_get_stats('ip_address', $account_id);
|
44
|
if ($ip !== FALSE) {
|
45
|
$variables['user_stats_ip'] = $ip;
|
46
|
}
|
47
|
|
48
|
// Write to the cache variable. We do this even if it's FALSE because
|
49
|
// we check for that before using it.
|
50
|
$cached_stats[$account_id]['posts'] = $posts;
|
51
|
$cached_stats[$account_id]['ip'] = $ip;
|
52
|
}
|
53
|
}
|
54
|
}
|
55
|
|
56
|
/**
|
57
|
* Implements hook_author_pane_allow_preprocess_disable().
|
58
|
*/
|
59
|
function user_stats_author_pane_allow_preprocess_disable() {
|
60
|
return array('user_stats' => 'User Stats');
|
61
|
}
|