/[drupal]/contributions/modules/firestats/firestats.module
ViewVC logotype

Contents of /contributions/modules/firestats/firestats.module

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


Revision 1.4 - (show annotations) (download) (as text)
Sat Nov 11 18:32:34 2006 UTC (3 years ago) by Gurpartap
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-5
Changes since 1.3: +0 -2 lines
File MIME type: text/x-php
minor fix
1 <?php
2
3 /**
4 * FireStats Drupal integration module.
5 * Copyright Omry Yadan & Gurpartap Singh.
6 * License: GPL GNU (http://www.gnu.org/copyleft/gpl.html).
7 * Report issues/bugs at: http://drupal.org/project/issues/firestats
8 */
9
10 function firestats_help($section) {
11 switch ($section) {
12 case 'admin/help#firestats':
13 return 'Install <a href="http://firestats.cc/">FireStats</a>, then setup the <b>firestats path</b> in <em>'. l('firestats settings', 'admin/settings/firestats') . '</em>. Settings will be disabled unless you enter correct firestats path.';
14 break;
15 case 'admin/modules#description':
16 return 'FireStats statistics engine integration module. You must install <a href="http://firestats.cc/" />firestats</a> to use this module.';
17 break;
18 }
19 }
20
21 function firestats_settings() {
22 $attributes = file_exists(FS_INSTALL_PATH) ? '' : array('disabled' => 'disabled');
23 $test = file_exists(FS_INSTALL_PATH) ? t('<img src="' . base_path() . '/misc/watchdog-warning.png" /><em> Firestats was found at: '. FS_SERVER_PATH . '</em>') : t('<img src="' . base_path() . '/misc/watchdog-error.png" /><em> Firestats path is not correct. Settings disabled.</em>');
24 $roles = user_roles();
25 $form = array();
26
27 $form['firestats_settings'] = array(
28 '#type' => 'fieldset',
29 '#title' => t('Firestats configuration'),
30 '#collapsed' => TRUE,
31 );
32 $form['firestats_settings']['firestats_path'] = array(
33 '#type' => 'textfield',
34 '#title' => t('Firestats path'),
35 '#default_value' => variable_get('firestats_path', ''),
36 '#description' => t('Enter the path relative to your server root. Without trailing slash.<br />Example: <em>/var/www/html/firestats</em>.'),
37 );
38 $form['firestats_settings']['firestats_test'] = array(
39 '#type' => 'markup',
40 '#value' => $test,
41 );
42 $form['firestats_settings_others'] = array(
43 '#type' => 'fieldset',
44 '#title' => t('Disable stats for:'),
45 '#collapsed' => TRUE,
46 );
47 $form['firestats_settings_others']['firestats_admin_disable'] = array(
48 '#type' => 'checkbox',
49 '#title' => t('Administration pages'),
50 '#default_value' => variable_get('firestats_admin_disable', 0),
51 '#attributes' => $attributes,
52 '#description' => t('Checking this option will disable stats for administration pages. (i.e. <em>?q=admin/*</em>)'),
53 );
54 $form['firestats_settings_others']['firestats_role_disable'] = array(
55 '#type' => 'select',
56 '#title' => t('These roles'),
57 '#options' => $roles,
58 '#multiple' => TRUE,
59 '#attributes' => $attributes,
60 '#default_value' => variable_get('firestats_role_disable', ''),
61 '#description' => t('Checking this option will disable stats for selected roles.'),
62 );
63 $form['firestats_settings_others']['firestats_users_disable'] = array(
64 '#type' => 'textarea',
65 '#title' => t('These users'),
66 '#attributes' => $attributes,
67 '#default_value' => variable_get('firestats_users_disable', NULL),
68 '#description' => t('Stats will be disabled for entered users. Separate by new line or comma.'),
69 );
70
71 return $form;
72 }
73
74 /*function firestats_settings_form_validate($form_id, $form_values) {
75 if (!$firestats_path = $form_values['firestats_path']) { //interupts reset to default option when path is incorrect
76 form_set_error('firestats_path', 'FireStats path is not configured.');
77 }
78 if(!file_exists($firestats_path . '/php/db-hit.php')) {
79 form_set_error('firestats_path', 'FireStats was not found at <em>'. $firestats_path . '</em>');
80 }
81 }*/
82
83 function firestats_init() {
84 define('FS_FULL_INSTALLATION', '0');
85 define('FS_SERVER_PATH', variable_get('firestats_path', ''));
86 if (FS_SERVER_PATH != NULL)
87 define('FS_INSTALL_PATH', FS_SERVER_PATH . '/php/db-hit.php');
88 }
89
90 function firestats_exit() {
91 global $user;
92 $udf = '';
93 $rdf = '';
94 $users_disabled_for = trim(variable_get('firestats_users_disable', NULL));
95 if ($users_disabled_for != NULL) {
96 $users_disabled_for = str_replace(array("\r\n", "\n", "\r"), ', ', $users_disabled_for);
97 $users_disabled_for = str_replace(',', ', ', $users_disabled_for);
98 $users_disabled_for = str_replace(', ', ', ', $users_disabled_for);
99 $users_disabled_for = explode(', ', $users_disabled_for);
100 $udf = in_array($user->name, $users_disabled_for);
101 }
102 $roles_disabled_for = variable_get('firestats_role_disable', '');
103 $rdf_status = '';
104 if (count($roles_disabled_for) != 0) {
105 foreach ($roles_disabled_for as $key => $value) {
106 $rdf_status = array_key_exists($key, $user->roles);
107 }
108 }
109
110
111 if((arg(0) == 'admin' && variable_get('firestats_admin_disable', 0)) || $udf || $rdf_status) {
112 return;
113 }
114 elseif ($file_exists = file_exists(FS_INSTALL_PATH)) {
115 require_once(FS_INSTALL_PATH);
116 fs_add_hit(null,true);
117 return;
118 }
119 }

  ViewVC Help
Powered by ViewVC 1.1.2