/[drupal]/contributions/modules/send/modules/send_track/includes/send_track.track.inc
ViewVC logotype

Diff of /contributions/modules/send/modules/send_track/includes/send_track.track.inc

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

revision 1.2, Tue May 26 15:06:07 2009 UTC revision 1.3, Fri Aug 7 01:00:05 2009 UTC
# Line 1  Line 1 
1  <?php // $Id: send_track.track.inc,v 1.1 2009/05/25 20:27:13 vauxia Exp $  <?php // $Id: send_track.track.inc,v 1.2 2009/05/26 15:06:07 vauxia Exp $
2    
3  /**  /**
4   * Menu callback for a tracking activity.   * Menu callback for a tracking activity.
# Line 8  function send_track_page($op, $send_reci Line 8  function send_track_page($op, $send_reci
8    $path = join('/', array_slice($args, 2));    $path = join('/', array_slice($args, 2));
9    
10    // Call the API function that manages tracking activities.    // Call the API function that manages tracking activities.
11    send_track($op, $send_recipient, $path);    send_track($op, NULL, $send_recipient, $path);
12    
13    // The rest of the path is presumably a URL to redirect to.    // The rest of the path is presumably a URL to redirect to.
14    drupal_goto($path);    drupal_goto($path);
15  }  }
16    
17  function send_track($op, $send_recipient = NULL, $path = NULL) {  /**
18     * Schema alter code for the send_recipient table.
19     * Handlers can optionally create additional fields for tracking purposes.
20     */
21    function _send_track_schema_alter(&$schema) {
22      // The table doesn't exist at all.
23      $table = 'send_recipient';
24      $new = !db_table_exists($table);
25    
26      foreach (module_invoke_all('send_track_handler_info') as $info) {
27        if (isset($info['database columns'])) {
28    
29          $indexes = array();
30          if (isset($info['database indexes'])) {
31            $indexes = array('indexes' => $info['database indexes']);
32            $schema[$table]['indexes'] = array_merge($schema[$table]['indexes'], $info['database indexes']);
33          }
34    
35          foreach ($info['database columns'] as $name => $spec) {
36            // Add this column to the schema array.
37            $schema[$table]['fields'][$name] = $spec;
38    
39            // Add the column to the database if it does not already exist.
40            if (!$new && !db_column_exists($table, $name)) {
41              db_add_field($ret, $table, $name, $spec, $indexes);
42              $indexes = array();
43            }
44          }
45        }
46      }
47    }
48    
49    function send_track($op, $value = 1, $send_recipient = NULL, $path = NULL) {
50    if (!$send_recipient) {    if (!$send_recipient) {
51      // Look for send_recipient info that was previously set in the session.      // Look for send_recipient info that was previously set in the session.
52      if (isset($_SESSION['send_recipient'])) {      if (isset($_SESSION['send_recipient'])) {
# Line 73  function send_track_send_track_handler_i Line 105  function send_track_send_track_handler_i
105        'description' => t('An open-rate tracker.'),        'description' => t('An open-rate tracker.'),
106        'callback' => 'send_track_open',        'callback' => 'send_track_open',
107        'count once' => TRUE,        'count once' => TRUE,
108          'database columns' => array(
109            'open' => array('type' => 'int', 'size' => 'tiny', 'not null' => TRUE, 'default' => 0),
110          ),
111      ),      ),
112      'click' => array(      'click' => array(
113        'title' => t('Clickthru'),        'title' => t('Click-through'),
114        'description' => t('Track the number of times an embedded URL is clicked.'),        'description' => t('Track the number of times an embedded URL is clicked.'),
115        'callback' => 'send_track_click',        'callback' => 'send_track_click',
116        'count once' => FALSE,        'count once' => FALSE,
117          'database columns' => array(
118            'click' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
119          ),
120      )      )
121    );    );
122  }  }
# Line 96  function _send_track_send_message_alter( Line 134  function _send_track_send_message_alter(
134      $pattern = '@(src=")('. $base_url .')?('. base_path() .')(.*q=)?([^"]+)@mi';      $pattern = '@(src=")('. $base_url .')?('. base_path() .')(.*q=)?([^"]+)@mi';
135      $body = preg_replace($pattern, '\1\2\3\4'.$open_path.'\5', $body, 1);      $body = preg_replace($pattern, '\1\2\3\4'.$open_path.'\5', $body, 1);
136    
137      // Clickthru      // Click-through
138      $click_path  = 'send/c/'. $r->hash .'/';      $click_path  = 'send/c/'. $r->hash .'/';
139      $pattern = '@(href=")('. $base_url .')?('. base_path() .')(.*q=)?([^"]+)@mi';      $pattern = '@(href=")('. $base_url .')?('. base_path() .')(.*q=)?([^"]+)@mi';
140      $body = preg_replace($pattern, '\1\2\3\4'.$click_path.'\5', $body);      $body = preg_replace($pattern, '\1\2\3\4'.$click_path.'\5', $body);
141    
142      // TODO: Also track fully-qualified links to remote URLs.      // TODO: Add tracking for fully-qualified links to remote URLs.
143      //$click_full = url('send/c/'. $r->hash, array('absolute' => TRUE));      //$click_full = url('send/c/'. $r->hash, array('absolute' => TRUE));
144      $message['body'] = $body;      $message['body'] = $body;
145    }    }
146  }  }
147    
148  /**  /**
  * Custom behavior for the "open" activity.  
  */  
 function send_track_open($send_track) {  
 }  
   
 /**  
149   * Custom behavior for the "click" activity.   * Custom behavior for the "click" activity.
150   */   */
151  function send_track_click($send_track) {  function send_track_click($send_track) {

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3

  ViewVC Help
Powered by ViewVC 1.1.2