예제 #1
0
 /**
  * Ajax Tracking (client-side, javascript)
  */
 public static function slimtrack_js()
 {
     $data_string = base64_decode($_REQUEST['data']);
     if ($data_string === false) {
         do_action('slimstat_track_exit_101');
         exit('-101.0');
     }
     // Parse the information we received
     parse_str($data_string, self::$data_js);
     self::$data_js = apply_filters('slimstat_filter_pageview_data_js', self::$data_js);
     if (empty(self::$data_js['ci']) && empty(self::$data_js['id'])) {
         do_action('slimstat_track_exit_102');
         exit('-102.0');
     }
     if (!empty(self::$data_js['ci'])) {
         list(self::$data_js['ci'], $nonce) = explode('.', self::$data_js['ci']);
         if ($nonce != md5(self::$data_js['ci'] . self::$options['secret'])) {
             do_action('slimstat_track_exit_103');
             exit('-103.0');
         }
     } else {
         list(self::$data_js['id'], $nonce) = explode('.', self::$data_js['id']);
         if ($nonce != md5(self::$data_js['id'] . self::$options['secret'])) {
             do_action('slimstat_track_exit_104');
             exit('-104.0');
         }
         self::$stat['id'] = self::$data_js['id'];
         // This script can be called to track outbound links
         if (!empty(self::$data_js['obr'])) {
             self::$stat['outbound_resource'] = strip_tags(trim(self::$data_js['obr']));
             self::$stat['outbound_domain'] = !empty(self::$data_js['obd']) ? strip_tags(self::$data_js['obd']) : '';
             if (strpos(self::$stat['outbound_resource'], '://') == false && substr(self::$stat['outbound_resource'], 0, 1) != '/' && substr(self::$stat['outbound_resource'], 0, 1) != '#') {
                 self::$stat['outbound_resource'] = '/' . self::$stat['outbound_resource'];
             }
             self::$stat['notes'] = !empty(self::$data_js['no']) ? strip_tags(stripslashes(trim(self::$data_js['no']))) : '';
             self::$stat['position'] = !empty(self::$data_js['po']) ? strip_tags(trim(self::$data_js['po'])) : '';
             self::$stat['type'] = isset(self::$data_js['ty']) ? abs(intval(self::$data_js['ty'])) : 0;
             $timezone = get_option('timezone_string');
             if (!empty($timezone)) {
                 date_default_timezone_set($timezone);
             }
             $lt = localtime();
             if (!empty($timezone)) {
                 date_default_timezone_set('UTC');
             }
             self::$stat['dt'] = mktime($lt[2], $lt[1], $lt[0], $lt[4] + 1, $lt[3], $lt[5] + 1900);
             self::insert_row(self::$stat, $GLOBALS['wpdb']->prefix . 'slim_outbound');
             do_action('slimstat_track_success_outbound', self::$stat);
             exit(self::$stat['id'] . '.' . md5(self::$stat['id'] . self::$options['secret']));
         }
     }
     // Track client-side information (screen resolution, plugins, etc)
     if (!empty(self::$data_js['sw']) && !empty(self::$data_js['sh'])) {
         $screenres = array('resolution' => self::$data_js['sw'] . 'x' . self::$data_js['sh'], 'colordepth' => !empty(self::$data_js['cd']) ? self::$data_js['cd'] : '', 'antialias' => !empty(self::$data_js['aa']) ? intval(self::$data_js['aa']) : 0);
         $screenres = apply_filters('slimstat_filter_pageview_screenres', $screenres, self::$stat);
         // Now we insert the new screen resolution in the lookup table, if it doesn't exist
         self::$stat['screenres_id'] = self::maybe_insert_row($screenres, $GLOBALS['wpdb']->base_prefix . 'slim_screenres', 'screenres_id', array());
     }
     self::$stat['plugins'] = !empty(self::$data_js['pl']) ? substr(str_replace('|', ',', self::$data_js['pl']), 0, -1) : '';
     // If Javascript mode is enabled, record this pageview
     if (self::$options['javascript_mode'] == 'yes' || !empty(self::$data_js['ci'])) {
         self::slimtrack();
     } else {
         self::_set_visit_id(true);
         if (!empty(self::$stat['screenres_id'])) {
             self::$wpdb->query(self::$wpdb->prepare("\n\t\t\t\t\tUPDATE {$GLOBALS['wpdb']->prefix}slim_stats\n\t\t\t\t\tSET screenres_id = %d, plugins = %s\n\t\t\t\t\tWHERE id = %d", self::$stat['screenres_id'], self::$stat['plugins'], self::$stat['id']));
         }
     }
     // Was this pageview tracked?
     if (self::$stat['id'] <= 0) {
         $abs_error_code = abs(self::$stat['id']);
         switch ($abs_error_code) {
             case '212':
                 do_action('slimstat_track_exit_' . $abs_error_code, self::$stat, $browser);
                 break;
             default:
                 do_action('slimstat_track_exit_' . $abs_error_code, self::$stat);
         }
         exit(self::$stat['id'] . '.0');
     }
     // Send the ID back to Javascript to track future interactions
     do_action('slimstat_track_success');
     exit(self::$stat['id'] . '.' . md5(self::$stat['id'] . self::$options['secret']));
 }
예제 #2
0
 /**
  * Makes sure that the data received from the client is well-formed (and that nobody is trying to do bad stuff)
  */
 protected static function _check_data_integrity($_data = '')
 {
     // Parse the information we received
     self::$data_js = apply_filters('slimstat_filter_pageview_data_js', $_data);
     // Do we have an id for this request?
     if (empty(self::$data_js['id']) || empty(self::$data_js['op'])) {
         do_action('slimstat_track_exit_102');
         self::$stat['id'] = -102;
         self::_set_error_array(__('Invalid payload string. Try clearing your WordPress cache.', 'wp-slimstat'));
         self::slimstat_save_options();
         exit('-102.0');
     }
     // Make sure that the control code is valid
     list(self::$data_js['id'], $nonce) = explode('.', self::$data_js['id']);
     if ($nonce !== md5(self::$data_js['id'] . self::$options['secret'])) {
         do_action('slimstat_track_exit_103');
         self::$stat['id'] = -103;
         self::_set_error_array(__('Invalid data signature. Try clearing your WordPress cache.', 'wp-slimstat'));
         self::slimstat_save_options();
         exit('-103.0');
     }
 }