-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhitsteps.module
166 lines (141 loc) · 5.5 KB
/
hitsteps.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
<?php
/**
* @file
* Adds Hitsteps javascript tracking code to your site pages.
*
* Copyright 2015 by ("Hitsteps", http://www.hitsteps.com)
*/
/**
* Implementation of hook_help().
*/
function hitsteps_help($section = "admin/help#hitsteps", $arg) {
$output = '';
switch ($section) {
case 'admin/help#hitsteps':
$output = '<p>' . t('The hitsteps module provides an integration of hitsteps for Drupal. The
module allows you to insert tracking code on pages within the specific scope. For more detialed
instructions please visit the hitsteps settings on your drupal and read the instructions on that page.') . '</p>
<p>' . t('If you would like to change the location of the code on the page goto ') . '<a href="'.url('admin/build/block') . '">' . t('Blocks') . '</a>' . t(' and change the
location of the "hitsteps" block.') . '</p>';
break;
case 'admin/settings/hitsteps':
if (strlen(substr(variable_get('hitsteps_code', ''),0,32))==32){
$output = '<iframe scrollable="no" scrolling="no" name="hitsteps-stat" frameborder="0" style="background-color: #fff; border: 1px solid #A4A2A3;" margin="0" padding="0" marginheight="0" marginwidth="0" width="100%" height="400" src="http://www.hitsteps.com/stats/wp3.2.php?code='.variable_get('hitsteps_code', '').'"> </iframe>';
}else{
$output = '<p>' . t('To setup a hitsteps tracking code with the this integration module please visit
') . '<a href="http://www.hitsteps.com/">' . t('Hitsteps Website') . '</a>' . t(' and perform the following setups:') . '</p>
<ol>
<li>' . t("Login to your account. ( Register if you don't have an account )") . '</li>
<li>' . t("Add your website on Hitsteps website to be used if you haven't already.") . '</li>
<li>' . t('Click on the Setting link for added website.') . '</li>
<li>' . t('Get your Hitsteps API Code on Hitsteps website Setting page.') . '</li>
<li>' . t('Copy the API Code in the textarea and paste it into the textarea below labled Hitsteps api code.') . '</li>
<li>' . t('Set the scope ( usually All Pages ) . ') . '</li>
<li>' . t('Go to the !blockspage and set the hitsteps block to region you would like it to display in. ( Footer is recommended )',array('!blockspage' => l(t('Blocks page'), 'admin/structure/block'))) . '</li>
</ol>';
}
break;
}
return $output;
}
/**
* Implementation of hook_menu().
*/
function hitsteps_menu() {
$items = array();
$items['admin/settings/hitsteps'] = array(
'title' => 'Hitsteps',
'description' => 'Configure hitsteps integration.',
'page callback' => 'drupal_get_form',
'page arguments' => array('hitsteps_settings'),
'access callback' => 'user_access',
'access arguments' => array('administer hitsteps')
);
return $items;
}
/**
* Implementation of hook_perm().
*/
function hitsteps_perm() {
return array('administer hitsteps');
}
/**
* Implements hook_block_view().
*/
function hitsteps_block_view($delta = '') {
$block = array();
if (hitsteps_display()) {
$block['content'] = "<!-- HITSTEPS DRUPAL TRACKING CODE - DO NOT CHANGE -->
<script src='http://www.hitsteps.com/track.php?code=".substr(variable_get('hitsteps_code', ''),0,32)."' type='text/javascript' ></script>
<noscript><a href='http://www.hitsteps.com/'><img src='http://www.hitsteps.com/track.php?mode=img&code=".substr(variable_get('hitsteps_code', ''),0,32)."' alt='Realtime hit counter' />web stats</a></noscript>
<!-- hitsteps TRACKING CODE - DO NOT CHANGE -->";
}
return $block;
}
/**
* Implements hook_block_info().
*/
function hitsteps_block_info() {
$blocks = array();
$blocks['hitsteps'] = array(
'info' => t('Hitsteps')
);
return $blocks;
}
/**
* Create the setting form.
*/
function hitsteps_settings() {
$from = array();
$form['general'] = array(
'#type' => 'fieldset',
'#title' => t('General'),
'#description' => t('General setup information.'));
$form['general']['hitsteps_code'] = array(
'#type' => 'textarea',
'#rows' => '1',
'#title' => t('Hitsteps API Code'),
'#description' => t('Place the Hitsteps API Code that will be inserted on pages within the specified scope.'),
'#default_value' => variable_get('hitsteps_code', '')
);
$form['general']['hitsteps_scope'] = array(
'#type' => 'radios',
'#title' => t('Scope'),
'#description' => t('The pages that the hitsteps code will be inserted on.'),
'#default_value' => variable_get('hitsteps_scope', 'all'),
'#options' => array(
'all' => t('All pages'),
'user' => t('Non-admin pages'),
'admin' => t('Admin pages'),
'home' => t('Home page'),
)
);
return system_settings_form($form);
}
/**
* Check to see if the hitsteps code should be added to the page.
*/
function hitsteps_display() {
if (variable_get('hitsteps_code', '') != '') {
switch (variable_get('hitsteps_scope', 'all')) {
case 'all':
return TRUE;
case 'user':
return (strpos(substr(hitsteps_get_url(), 0, 5), 'admin') === FALSE);
case 'admin':
return (strpos(substr(hitsteps_get_url(), 0, 5), 'admin') !== FALSE);
case 'home':
return (hitsteps_get_url() == 'home');
}
}
return FALSE;
}
/**
* Get the url to be used with for checking.
*/
function hitsteps_get_url() {
if (isset($_GET['q'])) {
return ($_GET['q'] == variable_get('site_frontpage', 'node') ? 'home' : $_GET['q']);
}
return 'unknown';
}