Projet

Général

Profil

Révision e9f59589

Ajouté par Assos Assos il y a presque 10 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/piwik/piwik.module
3 3
/**
4 4
 * @file
5 5
 * Drupal Module: Piwik
6
 * Adds the required Javascript to the bottom of all your Drupal pages
7
 * to allow tracking by the Piwik statistics package.
6
 *
7
 * Adds the required Javascript to all your Drupal pages to allow tracking by
8
 * the Piwik statistics package.
8 9
 *
9 10
 * @author: Alexander Hass <http://drupal.org/user/85918>
10 11
 */
11 12

  
12
define('PK_TRACKFILES_EXTENSIONS', '7z|aac|arc|arj|asf|asx|avi|bin|csv|doc|exe|flv|gif|gz|gzip|hqx|jar|jpe?g|js|mp(2|3|4|e?g)|mov(ie)?|msi|msp|pdf|phps|png|ppt|qtm?|ra(m|r)?|sea|sit|tar|tgz|torrent|txt|wav|wma|wmv|wpd|xls|xml|z|zip');
13
/**
14
 * Define the default file extension list that should be tracked as download.
15
 */
16
define('PIWIK_TRACKFILES_EXTENSIONS', '7z|aac|arc|arj|asf|asx|avi|bin|csv|doc|exe|flv|gif|gz|gzip|hqx|jar|jpe?g|js|mp(2|3|4|e?g)|mov(ie)?|msi|msp|pdf|phps|png|ppt|qtm?|ra(m|r)?|sea|sit|tar|tgz|torrent|txt|wav|wma|wmv|wpd|xls|xml|z|zip');
17

  
18
/**
19
 * Define default path exclusion list to remove tracking from admin pages,
20
 * see http://drupal.org/node/34970 for more information.
21
 */
22
define('PIWIK_PAGES', "admin\nadmin/*\nbatch\nnode/add*\nnode/*/*\nuser/*/*");
13 23

  
14 24
/**
15 25
 * Implements hook_help().
......
88 98
  // 1. Check if the piwik account number has a value.
89 99
  // 2. Track page views based on visibility value.
90 100
  // 3. Check if we should track the currently active user's role.
91
  if (!empty($id) && (_piwik_visibility_pages() || in_array($status, $trackable_status_codes)) && _piwik_visibility_user($user)) {
101
  if (preg_match('/^\d{1,}$/', $id) && (_piwik_visibility_pages() || in_array($status, $trackable_status_codes)) && _piwik_visibility_user($user)) {
92 102

  
93 103
    $url_http = variable_get('piwik_url_http', '');
94 104
    $url_https = variable_get('piwik_url_https', '');
95
    $scope = variable_get('piwik_js_scope', 'footer');
105
    $scope = variable_get('piwik_js_scope', 'header');
96 106

  
97 107
    $set_custom_url = '';
98 108
    $set_document_title = '';
99 109
    $set_custom_data = array();
100 110

  
111
    // Add link tracking.
112
    $link_settings = array();
113
    $link_settings['trackMailto'] = variable_get('piwik_trackmailto', 1);
114

  
115
    drupal_add_js(array('piwik' => $link_settings), 'setting');
116
    drupal_add_js(drupal_get_path('module', 'piwik') . '/piwik.js');
117

  
101 118
    // Piwik can show a tree view of page titles that represents the site structure
102 119
    // if setDocumentTitle() provides the page titles as a "/" delimited list.
103 120
    // This may makes it easier to browse through the statistics of page titles
......
110 127
        array_shift($titles);
111 128
      }
112 129

  
130
      // Remove all empty titles.
131
      $titles = array_filter($titles);
132

  
113 133
      if (!empty($titles)) {
114 134
        // Encode title, at least to keep "/" intact.
115 135
        $titles = array_map('urlencode', $titles);
......
118 138
      }
119 139
    }
120 140

  
141
    // Add messages tracking.
142
    $message_events = '';
143
    if ($message_types = variable_get('piwik_trackmessages', array())) {
144
      $message_types = array_values(array_filter($message_types));
145
      $status_heading = array(
146
        'status' => t('Status message'),
147
        'warning' => t('Warning message'),
148
        'error' => t('Error message'),
149
      );
150

  
151
      foreach (drupal_get_messages(NULL, FALSE) as $type => $messages) {
152
        // Track only the selected message types.
153
        if (in_array($type, $message_types)) {
154
          foreach ($messages as $message) {
155
            $message_events .= '_paq.push(["trackEvent", ' . drupal_json_encode(t('Messages')) . ', ' . drupal_json_encode($status_heading[$type]) . ', ' . drupal_json_encode(strip_tags($message)) . ']);';
156
          }
157
        }
158
      }
159
    }
160

  
121 161
    // If this node is a translation of another node, pass the original
122 162
    // node instead.
123 163
    if (module_exists('translation') && variable_get('piwik_translation_set', 0)) {
......
133 173

  
134 174
    // Track access denied (403) and file not found (404) pages.
135 175
    if ($status == '403 Forbidden') {
136
      $set_document_title = '"403/URL = " + String(document.location.pathname + document.location.search).replace(/\//g,"%2f") + "/From = " + String(document.referrer).replace(/\//g,"%2f")';
176
      $set_document_title = '"403/URL = " + encodeURIComponent(document.location.pathname+document.location.search) + "/From = " + encodeURIComponent(document.referrer)';
137 177
    }
138 178
    elseif ($status == '404 Not Found') {
139
      $set_document_title = '"404/URL = " + String(document.location.pathname + document.location.search).replace(/\//g,"%2f") + "/From = " + String(document.referrer).replace(/\//g,"%2f")';
179
      $set_document_title = '"404/URL = " + encodeURIComponent(document.location.pathname+document.location.search) + "/From = " + encodeURIComponent(document.referrer)';
140 180
    }
141 181

  
142 182
    // Add custom variables.
......
202 242
    }
203 243

  
204 244
    // Custom file download extensions.
205
    if ((variable_get('piwik_track', 1)) && !(variable_get('piwik_trackfiles_extensions', PK_TRACKFILES_EXTENSIONS) == PK_TRACKFILES_EXTENSIONS)) {
206
      $script .= '_paq.push(["setDownloadExtensions", ' . drupal_json_encode(variable_get('piwik_trackfiles_extensions', PK_TRACKFILES_EXTENSIONS)) . ']);';
245
    if ((variable_get('piwik_track', 1)) && !(variable_get('piwik_trackfiles_extensions', PIWIK_TRACKFILES_EXTENSIONS) == PIWIK_TRACKFILES_EXTENSIONS)) {
246
      $script .= '_paq.push(["setDownloadExtensions", ' . drupal_json_encode(variable_get('piwik_trackfiles_extensions', PIWIK_TRACKFILES_EXTENSIONS)) . ']);';
207 247
    }
208 248

  
209 249
    // Disable tracking for visitors who have opted out from tracking via DNT (Do-Not-Track) header.
......
250 290

  
251 291
    // Add link tracking.
252 292
    if (variable_get('piwik_track', 1)) {
293
      // Disable tracking of links with ".no-tracking" and ".colorbox" classes.
294
      $ignore_classes = array(
295
        'no-tracking',
296
        'colorbox',
297
      );
298
      // Disable the download & outlink tracking for specific CSS classes.
299
      // Custom code snippets with 'setIgnoreClasses' will override the value.
300
      // http://developer.piwik.org/api-reference/tracking-javascript#disable-the-download-amp-outlink-tracking-for-specific-css-classes
301
      $script .= '_paq.push(["setIgnoreClasses", ' . drupal_json_encode($ignore_classes) . ']);';
302

  
303
      // Enable download & outlink link tracking.
253 304
      $script .= '_paq.push(["enableLinkTracking"]);';
254 305
    }
306

  
307
    if (!empty($message_events)) {
308
      $script .= $message_events;
309
    }
255 310
    if (!empty($codesnippet_after)) {
256 311
      $script .= $codesnippet_after;
257 312
    }
......
529 584
  if (!isset($page_match)) {
530 585

  
531 586
    $visibility = variable_get('piwik_visibility_pages', 0);
532
    $setting_pages = variable_get('piwik_pages', '');
587
    $setting_pages = variable_get('piwik_pages', PIWIK_PAGES);
533 588

  
534 589
    // Match path if necessary.
535 590
    if (!empty($setting_pages)) {

Formats disponibles : Unified diff