예제 #1
0
 public static function hour($all = false)
 {
     DigitalPointBetterAnalytics_Model_Widget::getStatsWidgetData();
     // This really should be a core WordPress function (deleting expired transients), but w/e...
     global $wpdb;
     if (!$all) {
         $time = time();
     } else {
         $time = time() + 86400 * 365;
     }
     $sql = "DELETE a, b FROM {$wpdb->options} a, {$wpdb->options} b\n                WHERE a.option_name LIKE %s\n                AND a.option_name NOT LIKE %s\n                AND b.option_name = CONCAT( '_transient_timeout_', SUBSTRING( a.option_name, 12 ) )\n                AND b.option_value < %d";
     $wpdb->query($wpdb->prepare($sql, $wpdb->esc_like('_transient_ba_') . '%', $wpdb->esc_like('_transient_timeout_') . '%', $time));
 }
예제 #2
0
파일: Jobs.php 프로젝트: Vatia13/tofido
 public static function hour($all = false)
 {
     DigitalPointBetterAnalytics_Model_Widget::getStatsWidgetData();
     if (get_transient('ba_exp_live') || date('G', current_time('timestamp')) == 0) {
         $betterAnalyticsOptions = get_option('better_analytics');
         if ($profile = DigitalPointBetterAnalytics_Helper_Reporting::getInstance()->getProfileByProfileId($betterAnalyticsOptions['api']['profile'])) {
             DigitalPointBetterAnalytics_Model_Experiments::getAllExperiments($profile['accountId'], $profile['webPropertyId'], $profile['id']);
         }
     }
     // This really should be a core WordPress function (deleting expired transients), but w/e...
     global $wpdb;
     if (!$all) {
         $time = time();
     } else {
         $time = time() + 86400 * 365;
     }
     $sql = "DELETE a, b FROM {$wpdb->options} a, {$wpdb->options} b\n                WHERE a.option_name LIKE %s\n                AND a.option_name NOT LIKE %s\n                AND b.option_name = CONCAT( '_transient_timeout_', SUBSTRING( a.option_name, 12 ) )\n                AND b.option_value < %d";
     $wpdb->query($wpdb->prepare($sql, $wpdb->esc_like('_transient_ba_') . '%', $wpdb->esc_like('_transient_timeout_') . '%', $time));
 }
예제 #3
0
 public function actionCharts()
 {
     // sanitize
     $_POST['dimension'] = preg_replace('#[^a-z0-9\\:]#i', '', @$_POST['dimension']);
     $_POST['metric'] = preg_replace('#[^a-z0-9\\:]#i', '', @$_POST['metric']);
     $_POST['days'] = absint(@$_POST['days']);
     $_POST['realtime'] = absint(@$_POST['realtime']);
     $dimension = substr($_POST['dimension'], 2);
     $type = substr($_POST['dimension'], 0, 1);
     $betterAnalyticsPick = get_option('ba_dashboard_pick');
     if ($_POST['dimension'] != @$betterAnalyticsPick['dimension'] || $_POST['metric'] != @$betterAnalyticsPick['metric'] || $_POST['days'] != @$betterAnalyticsPick['days'] || $_POST['realtime'] != @$betterAnalyticsPick['realtime']) {
         update_option('ba_dashboard_pick', array('dimension' => $_POST['dimension'], 'metric' => $_POST['metric'], 'days' => $_POST['days'], 'realtime' => $_POST['realtime']));
     }
     if (!empty($_POST['realtime'])) {
         if (!($realTime = get_transient('ba_realtime'))) {
             $realTime = DigitalPointBetterAnalytics_Model_Widget::getRealtimeData(55, true);
         }
         $realTimeOutput = array('users' => 0);
         if (!empty($realTime)) {
             foreach ($realTime as $key => $value) {
                 if (is_array($value)) {
                     $realTimeOutput[$key][] = array(ucwords(strtolower($key == 'keywords' ? __('Organic Search Keywords', 'better-analytics') : ($key == 'referral_path' ? __('Referring URL', 'better-analytics') : ($key == 'page_path' ? __('Current Page', 'better-analytics') : ($key == 'medium' ? __('Medium', 'better-analytics') : ($key == 'devices' ? __('Devices', 'better-analytics') : '')))))), __('Visitors', 'better-analytics'));
                     foreach ($value as $name => $amount) {
                         $realTimeOutput[$key][] = array($name, intval($amount));
                     }
                 } else {
                     $realTimeOutput[$key] = intval($value);
                 }
             }
         }
         wp_send_json(array('realtime_data' => $realTimeOutput, 'title' => __('Real-time', 'better-analytics')));
     } else {
         $validDimensions = $this->getDimensionsForCharts();
         $validMetrics = $this->getMetricsForCharts();
         $chartData = array_merge(array(array($validDimensions[$_POST['dimension']], $validMetrics[$_POST['metric']])), DigitalPointBetterAnalytics_Helper_Reporting::getInstance()->getChart(1, intval($_POST['days']), $_POST['metric'], $dimension));
         wp_send_json(array('chart_data' => $chartData, 'title' => $dimension == 'ga:date' ? $validMetrics[$_POST['metric']] : $validDimensions[$_POST['dimension']], 'type' => $type));
     }
 }
예제 #4
0
파일: Stats.php 프로젝트: Vatia13/tofido
 function widget($args, $instance)
 {
     if (!empty($instance['private'])) {
         if (!DigitalPointBetterAnalytics_Base_Public::getInstance()->canViewReports()) {
             return;
         }
     }
     $stats = get_transient('ba_stats_' . md5(@$instance['metric'] . '-' . @$instance['days'] . '-' . (@$instance['this_page_only'] ? $_SERVER['REQUEST_URI'] : '')));
     if (@$stats === false && !empty($instance['this_page_only'])) {
         $cacheKey = DigitalPointBetterAnalytics_Model_Widget::getStatsWidgetStart($instance);
         $stats = DigitalPointBetterAnalytics_Model_Widget::getStatsWidgetEnd($instance, $cacheKey);
     }
     if (!empty($stats)) {
         $metricTitle = DigitalPointBetterAnalytics_Model_Reporting::getMetricNameByKey($instance['metric']);
         echo $args['before_widget'];
         if (!empty($instance['title'])) {
             echo $args['before_title'];
             echo esc_html($instance['title']);
             echo $args['after_title'];
         }
         printf($instance['format'], $metricTitle, number_format_i18n($stats));
         echo $args['after_widget'];
     }
 }