-
Notifications
You must be signed in to change notification settings - Fork 0
/
visit_counter.module
71 lines (66 loc) · 1.77 KB
/
visit_counter.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
/**
* @file
* Main functions for the visit counter module.
*/
/**
* Implements hook_theme().
*/
function visit_counter_theme($existing, $type, $theme, $path) {
return array(
'visit_counter_block' => array(
'template' => 'templates/visit_counter_block',
'variables' => array(
'nid' => NULL,
),
),
);
}
/**
* Implements hook_block_info().
*/
function visit_counter_block_info() {
// This example comes from node.module.
$blocks['visit_counter_block'] = array(
'info' => t('Visit Counter'),
);
return $blocks;
}
/**
* Implements hook_block_view().
*/
function visit_counter_block_view($delta = '') {
if ($delta == 'visit_counter_block') {
$node = menu_get_object();
if ($node) {
variable_set('visit_counter_' . $node->nid, variable_get('visit_counter_' . $node->nid) + 1);
global $user;
foreach ($user->roles as $role) {
if ($role == 'administrator') {
variable_set('visit_counter_' . $node->nid, variable_get('visit_counter_' . $node->nid) + 9);
}
}
if (variable_get('visit_counter_' . $node->nid, NULL) != NULL) {
if (variable_get('visit_counter_' . $node->nid) % 100 == 0) {
drupal_set_message(t("You are the (100th times a multiplier) visitor on this page!"));
}
return array(
'subject' => 'Visit Counter for node ' . $node->nid,
'content' => theme('visit_counter_block', array('nid' => $node->nid)),
);
}
else {
return array(
'subject' => 'Visit Counter for node ' . $node->nid,
'content' => '0',
);
}
}
else {
return array(
'subject' => 'Visit Counter',
'content' => 'Sorry, the node could not be loaded :(',
);
}
}
}