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

Diff of /contributions/modules/click/click.module

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

revision 1.4 by unconed, Thu Apr 13 15:49:30 2006 UTC revision 1.5 by kbahey, Mon Jan 29 19:29:51 2007 UTC
# Line 1  Line 1 
1  <?php  <?php
2    
3  //$Id: click.module,v 1.3 2006/01/21 02:47:20 kbahey Exp $  //$Id: click.module,v 1.4 2006/04/13 15:49:30 unconed Exp $
4    
5  // Copyright 2005 Khalid Baheyeldin http://2bits.com  // Copyright 2005 Khalid Baheyeldin http://2bits.com
6    
7  define(CLICK_IGNORE_SITE, 'click_ignore_site');  define(CLICK_IGNORE_SITE,         'click_ignore_site');
8    define(CLICK_GROUP,               'click_group_');
9    define(CLICK_CRON_TIMESTAMP_DAY,  'click_cron_timestamp_day');
10    define(CLICK_CRON_TIMESTAMP_WEEK, 'click_cron_timestamp_week');
11    
12  function click_help($section) {  function click_help($section) {
13    switch ($section) {    switch ($section) {
     case 'admin/modules#description':  
       $output = t('Track click thrus from newletters and ads on other sites');  
       break;  
14      case 'admin/settings/click':      case 'admin/settings/click':
15        $output = t('Track click thrus from newletters and ads on other sites');        $output = t('Track click thrus from newletters and ads on other sites');
16        break;        break;
# Line 25  function click_perm() { Line 25  function click_perm() {
25  function click_menu($may_cache) {  function click_menu($may_cache) {
26    $items = array();    $items = array();
27    
28      $nid = 0;
29      $gid = 0;
30    
31    if (is_numeric(arg(1))) {    if (is_numeric(arg(1))) {
32      $nid = (int)arg(1);      $nid = (int)arg(1);
33    }    }
34    
35    if (is_numeric(arg(2))) {    if (is_numeric(arg(2))) {
36      $gid = (int)arg(2);      $gid = (int)arg(2);
37    }    }
   else {  
     $gid = 0;  
   }  
38    
39    if (arg(0) == 'node') {    if (arg(0) == 'node' && $nid) {
40      $items[] = array(      $items[] = array(
41        'path'     => "node/$nid/click",        'path'     => "node/$nid/click",
42        'callback' => 'click_view',        'callback' => 'click_view',
43        'title'    => t('clicks'),        'title'    => t('clicks'),
44        'access'   => user_access('view click stats'),        'access'   => user_access('view click stats'),
45        'weight'   => 10,        'weight'   => 10,
46        'type'     => MENU_LOCAL_TASK);        'type'     => MENU_LOCAL_TASK,
47          );
48    }    }
49    
50    $items[] = array(    $items[] = array(
51      'path'     => "click/$nid/$gid",      'path'     => "click/$nid/$gid",
52      'callback' => 'click_do',      'callback' => 'click_do',
53      'access'   => TRUE,      'access'   => TRUE,
54      'type'     => MENU_CALLBACK);      'type'     => MENU_CALLBACK,
55        );
56    
57      if ($may_cache) {
58        $items[] = array(
59          'path' => 'admin/settings/click',
60          'title' => 'Click Thru tracking',
61          'description' => t('Settings of the Click Thru tracking module'),
62          'callback' => 'drupal_get_form',
63          'callback arguments' => array('click_settings'),
64          'access' => user_access('administer site configuration'),
65          );
66    
67        $items[] = array(
68          'path'     => 'admin/logs/click',
69          'title'    => t('clicks'),
70          'callback' => 'click_report',
71          'access'   => user_access('view click stats'),
72          'type'     => MENU_NORMAL_ITEM,
73          );
74      }
75    
   $items[] = array(  
     'path'     => 'admin/logs/click',  
     'title'    => t('clicks'),  
     'callback' => 'click_report',  
     'access'   => user_access('view click stats'),  
     'type'     => MENU_NORMAL_ITEM);  
   
76    return $items;    return $items;
77  }  }
78    
79  function click_settings() {  function click_settings() {
80    global $user;    global $user;
81    $group = 'click_group_' . $user->uid;    $group = CLICK_GROUP . $user->uid;
82    
83    $form['click_settings'] = array(    $form['click_settings'] = array(
84      '#type' => 'fieldset',      '#type' => 'fieldset',
# Line 92  function click_settings() { Line 107  function click_settings() {
107       '#multiple' => false,       '#multiple' => false,
108       '#required' => true,       '#required' => true,
109    );    );
   return $form;  
110    
111      return system_settings_form($form);
112  }  }
113    
114  function click_link($type, $node = null, $teaser = false) {  function click_link($type, $node = null, $teaser = false) {
115    global $user;    global $user;
116    $group = 'click_group_' . $user->uid;    $group = CLICK_GROUP . $user->uid;
117    
118    $links = array();    $links = array();
119    
120    $click_group = variable_get($group, 0);    $click_group = variable_get($group, 0);
121    
122    if (user_access('view click links')) {    if (user_access('view click links')) {
123      $links[] = l(t('click link'), "click/$node->nid/$click_group",      $links['click_link'] = array(
124        array('class' => 'click_link', 'title' => t('Link to track click thrus.')));        'title'      => t('click link'),
125          'href'       => "click/$node->nid/$click_group",
126          'attributes' => array('title' => t('Link to track click thrus.')),
127          );
128    }    }
129    
130    if (user_access('view click stats')) {    if (user_access('view click stats')) {
131      $clicks = _click_count($node->nid);      $clicks = _click_count($node->nid);
132      if ($clicks > 0) {      if ($clicks > 0) {
133        $links[] = t('%num clicks', array('%num'=>$clicks));      $links['click_link_stats'] = array(
134          'title'      => t('%num clicks', array('%num'=>$clicks)),
135          );
136      }      }
137    }    }
138    
139    return $links;    return $links;
140  }  }
141    
# Line 207  function _click_count($nid) { Line 228  function _click_count($nid) {
228    
229  function click_cron() {  function click_cron() {
230    // 24 hours * 60 minutes * 60 seconds - 5 minutes    // 24 hours * 60 minutes * 60 seconds - 5 minutes
231    if ((time() - variable_get('click_cron_timestamp_day', 0)) >= 86100) {    if ((time() - variable_get(CLICK_CRON_TIMESTAMP_DAY, 0)) >= 86100) {
232      variable_set('click_cron_timestamp_day', time());      variable_set(CLICK_CRON_TIMESTAMP_DAY, time());
233      db_query('UPDATE {clicks} SET day_clicks  = 0');      db_query('UPDATE {clicks} SET day_clicks  = 0');
234    }    }
235    
236    // 7 days * 24 hours * 60 minutes * 60 seconds - 5 minutes    // 7 days * 24 hours * 60 minutes * 60 seconds - 5 minutes
237    if ((time() - variable_get('click_cron_timestamp_week', 0)) >= 604500) {    if ((time() - variable_get(CLICK_CRON_TIMESTAMP_WEEK, 0)) >= 604500) {
238      variable_set('click_cron_timestamp_week', time());      variable_set(CLICK_CRON_TIMESTAMP_WEEK, time());
239      db_query('UPDATE {clicks} SET week_clicks = 0');      db_query('UPDATE {clicks} SET week_clicks = 0');
240    }    }
241  }  }
   
 function click_update_1() {  
   return _system_update_utf8(array('clicks'));  
 }  

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.5

  ViewVC Help
Powered by ViewVC 1.1.3