/[drupal]/contributions/modules/piwik/piwik.admin.inc
ViewVC logotype

Contents of /contributions/modules/piwik/piwik.admin.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.3 - (show annotations) (download) (as text)
Mon May 12 16:29:01 2008 UTC (18 months, 2 weeks ago) by hass
Branch: MAIN
CVS Tags: HEAD
Changes since 1.2: +3 -3 lines
File MIME type: text/x-php
Sync with latest code
1 <?php
2 // $Id: piwik.admin.inc,v 1.1.2.2 2008/05/12 15:40:33 hass Exp $
3
4 /**
5 * @file
6 * Administrative page callbacks for the piwik module.
7 */
8
9 /**
10 * Implementation of hook_admin_settings() for configuring the module
11 */
12 function piwik_admin_settings_form(&$form_state) {
13 $form['account'] = array(
14 '#type' => 'fieldset',
15 '#title' => t('General settings'),
16 '#collapsible' => FALSE,
17 );
18
19 $form['account']['piwik_idsite'] = array(
20 '#type' => 'textfield',
21 '#title' => t('Piwik site ID'),
22 '#default_value' => variable_get('piwik_idsite', ''),
23 '#size' => 15,
24 '#maxlength' => 20,
25 '#required' => TRUE,
26 '#description' => t('The user account number is unique to the websites domain.'),
27 );
28 $form['account']['piwik_url_http'] = array(
29 '#type' => 'textfield',
30 '#title' => t('Piwik HTTP URL'),
31 '#default_value' => variable_get('piwik_url_http', ''),
32 '#size' => 80,
33 '#maxlength' => 255,
34 '#required' => TRUE,
35 '#description' => t('The URL to your Piwik base directory. Example: http://www.example.com/piwik/.'),
36 );
37 $form['account']['piwik_url_https'] = array(
38 '#type' => 'textfield',
39 '#title' => t('Piwik HTTP URL'),
40 '#default_value' => variable_get('piwik_url_https', ''),
41 '#size' => 80,
42 '#maxlength' => 255,
43 '#description' => t('The URL to your Piwik base directory with SSL certificate installed. Required if you track a SSL enabled website. Example: https://www.example.com/piwik/.'),
44 );
45
46 // Standard tracking configurations.
47 $form['user_vis_settings'] = array(
48 '#type' => 'fieldset',
49 '#title' => t('User specific tracking settings'),
50 '#collapsible' => TRUE,
51 );
52 $form['user_vis_settings']['piwik_custom'] = array(
53 '#type' => 'radios',
54 '#title' => t('Custom tracking settings'),
55 '#options' => array(
56 t('Users cannot control whether or not they add tracking.'),
57 t('Add tracking by default, but let individual users hide it.'),
58 t('Hide tracking by default, but let individual users add it.')
59 ),
60 '#description' => t('Allow individual users to customize the visibility of tracking in their account settings.'),
61 '#default_value' => variable_get('piwik_custom', 0),
62 );
63
64 // Render the role overview.
65 $form['role_vis_settings'] = array(
66 '#type' => 'fieldset',
67 '#title' => t('Role specific tracking settings'),
68 '#collapsible' => TRUE,
69 );
70
71 $roles = user_roles();
72 $role_options = array();
73 foreach ($roles as $rid => $name) {
74 $role_options[$rid] = $name;
75 }
76 $form['role_vis_settings']['piwik_roles'] = array(
77 '#type' => 'checkboxes',
78 '#title' => t('Add tracking for specific roles'),
79 '#default_value' => variable_get('piwik_roles', array()),
80 '#options' => $role_options,
81 '#description' => t('Add tracking only for the selected role(s). If you select no roles, the tracking will be added to all users.'),
82 );
83
84 // Page specific visibility configurations.
85 $form['page_vis_settings'] = array(
86 '#type' => 'fieldset',
87 '#title' => t('Page specific tracking settings'),
88 '#collapsible' => TRUE,
89 '#collapsed' => TRUE,
90 );
91
92 $access = user_access('use PHP for tracking visibility');
93 $visibility = variable_get('piwik_visibility', 0);
94 $pages = variable_get('piwik_pages', '');
95
96 if ($visibility == 2 && !$access) {
97 $form['page_vis_settings'] = array();
98 $form['page_vis_settings']['visibility'] = array('#type' => 'value', '#value' => 2);
99 $form['page_vis_settings']['pages'] = array('#type' => 'value', '#value' => $pages);
100 }
101 else {
102 $options = array(t('Add to every page except the listed pages.'), t('Add to the listed pages only.'));
103 $description = t("Enter one page per line as Drupal paths. The '*' character is a wildcard. Example paths are %blog for the blog page and %blog-wildcard for every personal blog. %front is the front page.", array('%blog' => 'blog', '%blog-wildcard' => 'blog/*', '%front' => '<front>'));
104
105 if ($access) {
106 $options[] = t('Add if the following PHP code returns <code>TRUE</code> (PHP-mode, experts only).');
107 $description .= ' '. t('If the PHP-mode is chosen, enter PHP code between %php. Note that executing incorrect PHP-code can break your Drupal site.', array('%php' => '<?php ?>'));
108 }
109 $form['page_vis_settings']['piwik_visibility'] = array(
110 '#type' => 'radios',
111 '#title' => t('Add tracking to specific pages'),
112 '#options' => $options,
113 '#default_value' => $visibility,
114 );
115 $form['page_vis_settings']['piwik_pages'] = array(
116 '#type' => 'textarea',
117 '#title' => t('Pages'),
118 '#default_value' => $pages,
119 '#description' => $description,
120 );
121 }
122
123 /* TODO: For future use.
124 // Segmentation based user tracking.
125 $profile_enabled = module_exists('profile');
126 $form['segmentation'] = array(
127 '#type' => 'fieldset',
128 '#title' => t('User segmentation settings'),
129 '#collapsible' => TRUE,
130 );
131
132 // Compile a list of fields to show.
133 $fields = array(
134 'uid' => t('User identifier'),
135 'name' => t('User name'),
136 'roles' => t('User roles')
137 );
138 if ($profile_enabled) {
139 $result = db_query('SELECT name, title, type, weight FROM {profile_fields} ORDER BY weight');
140 while ($record = db_fetch_object($result)) {
141 $fields[$record->name] = $record->title;
142 }
143 }
144
145 $form['segmentation']['piwik_segmentation'] = array(
146 '#type' => 'select',
147 '#title' => t('Track users based on'),
148 '#description' => t('Segment users based on different properties, additionaly to the basic IP address based tracking provided by Piwik.') . (!$profile_enabled ? ' '. t('<a href="@module_list">Enable the profile module</a> to be able to use profile fields for more granular tracking.', array('@module_list' => url('admin/build/modules'))) : '') .' '. t('Selecting one or more values is supported. To select multiple items, hold down CTRL while selecting fields.'),
149 '#default_value' => variable_get('piwik_segmentation', ''),
150 '#options' => $fields,
151 '#size' => $profile_enabled ? 10 : 3,
152 '#multiple' => TRUE
153 );
154 */
155
156 // Advanced feature configurations.
157 $form['advanced'] = array(
158 '#type' => 'fieldset',
159 '#title' => t('Advanced settings'),
160 '#collapsible' => TRUE,
161 '#collapsed' => TRUE,
162 );
163
164 $form['advanced']['piwik_cache'] = array(
165 '#type' => 'checkbox',
166 '#title' => t('Cache tracking code file locally'),
167 '#description' => t("If checked, the tracking code file is retrieved from Piwik and cached locally. It is updated daily from your Piwik servers to ensure updates to tracking code are reflected in the local copy."),
168 '#default_value' => variable_get('piwik_cache', 0),
169 );
170 if (variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC) == FILE_DOWNLOADS_PRIVATE) {
171 $form['advanced']['piwik_cache']['#disabled'] = TRUE;
172 $form['advanced']['piwik_cache']['#description'] .= ' '. t('<a href="!url">Public file transfers</a> must be enabled to allow local caching.', array('!url' => url('admin/settings/file-system', array('query' => drupal_get_destination()))));
173 }
174
175 /* TODO: For future use.
176 $site_search_dependencies = '<div class="admin-dependencies">';
177 $site_search_dependencies .= t('Depends on: !dependencies', array('!dependencies' => (module_exists('search') ? 'Search'. t(' (<span class="admin-enabled">enabled</span>)') : 'Search'. t(' (<span class="admin-disabled">disabled</span>)'))));
178 $site_search_dependencies .= '</div>';
179
180 $form['advanced']['piwik_site_search'] = array(
181 '#type' => 'checkbox',
182 '#title' => t('Track internal search'),
183 '#description' => t('If checked, internal search keywords are tracked. You must configure your Piwik account to use the internal query parameter <em>search</em>.') . $site_search_dependencies,
184 '#default_value' => variable_get('piwik_site_search', FALSE),
185 '#disabled' => (module_exists('search') ? FALSE : TRUE),
186 );
187 */
188
189 $form['advanced']['piwik_codesnippet'] = array(
190 '#type' => 'textarea',
191 '#title' => t('Custom JavaScript code'),
192 '#default_value' => variable_get('piwik_codesnippet', ''),
193 '#rows' => 5,
194 '#description' => t('You can add custom Piwik code snippets here. These will be added to every page that Piwik appears on. <strong>Do not include the &lt;script&gt; tags</strong>, and always end your code with a semicolon (;).')
195 );
196
197 $form['advanced']['piwik_js_scope'] = array(
198 '#type' => 'select',
199 '#title' => t('JavaScript scope'),
200 '#description' => t("<strong>Warning:</strong> Adding the external JavaScript files to the footer region is recommended for performance reasons."),
201 '#options' => array(
202 'footer' => t('Footer'),
203 'header' => t('Header'),
204 ),
205 '#default_value' => variable_get('piwik_js_scope', 'footer'),
206 );
207
208 return system_settings_form($form);
209 }
210
211 function piwik_admin_settings_form_validate($form, &$form_state) {
212 if (!preg_match('/^\d{1,}$/', $form_state['values']['piwik_idsite'])) {
213 form_set_error('piwik_idsite', t('A valid Piwik site ID is an integer only.'));
214 }
215 if ($result = drupal_http_request($form_state['values']['piwik_url_http'] . 'piwik.php')) {
216 if ($result->code != 200) {
217 form_set_error('piwik_url_http', t('A valid Piwik url is required. The provided URL was not accessible.'));
218 }
219 }
220 if (!empty($form_state['values']['piwik_url_https']) && $result = drupal_http_request($form_state['values']['piwik_url_https'] . 'piwik.php')) {
221 if ($result->code != 200) {
222 form_set_error('piwik_url_https', t('A valid Piwik url for SSL is required. The provided URL was not accessible.'));
223 }
224 }
225
226 // This is for the Newbie's who cannot read a text area description.
227 if (preg_match('/^(.*)<\/?script(.*)>(.*)/', $form_state['values']['piwik_codesnippet'])) {
228 form_set_error('piwik_codesnippet', t('Do not include the &lt;script&gt; tags in this field.'));
229 }
230
231 // Trim some text area values.
232 $form_state['values']['piwik_pages'] = trim($form_state['values']['piwik_pages']);
233 $form_state['values']['piwik_codesnippet'] = trim($form_state['values']['piwik_codesnippet']);
234 }

  ViewVC Help
Powered by ViewVC 1.1.2