예제 #1
0
 public static function wpadm_show_stat()
 {
     $show = !is_super_admin() || !is_admin() || !get_option(_PREFIX_STAT . 'counter_id');
     if (!$show) {
         if (isset($_POST['send'])) {
             $new_instance['counter_hidden'] = isset($_POST['hidden_counter']) && $_POST['hidden_counter'] == 1 ? 2 : 0;
             $new_instance['counter_image'] = get_option(_PREFIX_STAT . 'default_image');
             $new_instance['counter_image_color'] = isset($_POST['color_image']) ? $_POST['color_image'] : "#ffffff";
             $new_instance['counter_image_color_text'] = isset($_POST['color_text']) ? $_POST['color_text'] : "#000000";
             $new_instance['counter_protected_password'] = isset($_POST['password_counter']) && $_POST['password_counter'] == 1 ? $_POST['password_counter'] : 0;
             $data_post_default = array("action" => "get_count_image_on_setting", "image" => $new_instance['counter_image'], "hidden" => $new_instance['counter_hidden'], "image_color" => $new_instance['counter_image_color'], "image_color_text" => $new_instance['counter_image_color_text'], "protected_password" => $new_instance['counter_protected_password'], "wpadm" => 1);
             $result_default_image_setting = wpadm_wp_stat::sendToServer($data_post_default, true);
             if (isset($result_default_image_setting['code'])) {
                 update_option(_PREFIX_STAT . 'counter_code', $result_default_image_setting['code']);
                 update_option(_PREFIX_STAT . 'default_hidden', $new_instance['counter_hidden']);
                 update_option(_PREFIX_STAT . 'image_color', $new_instance['counter_image_color']);
                 update_option(_PREFIX_STAT . 'image_color_text', $new_instance['counter_image_color_text']);
                 update_option(_PREFIX_STAT . 'protected_password', $new_instance['counter_protected_password']);
             }
         }
         $data = array('action' => 'get_statistic');
         // hash
         self::$file_hash = plugin_dir_path(__FILE__) . "temp/data.stat";
         self::checkDir();
         $data_hash = self::getHash();
         $data['count_hash'] = count($data_hash);
         $data['time_hash'] = filemtime(self::$file_hash);
         if ($data['count_hash'] == 0) {
             $data['first'] = true;
         }
         //end hash
         $month_now = date("n");
         $year_now = date("Y");
         $start_today = date("j");
         $id_counter = get_option(_PREFIX_STAT . 'counter_id');
         $date_week = self::getWeekDates();
         if ($res = self::sendToServer($data, true)) {
             if (isset($res["stat"]['all']['years']) && !file_exists(plugin_dir_path(__FILE__) . "temp/notice") && $res["stat"]['all']['years'] > 0) {
                 if (!is_dir(plugin_dir_path(__FILE__) . "temp")) {
                     mkdir(plugin_dir_path(__FILE__) . "temp", 0755);
                 }
                 file_put_contents(plugin_dir_path(__FILE__) . "temp/notice", 1);
             }
             if (isset($res["stat"]['all']['months'])) {
                 $browser = isset($res["stat"]['all']['details']['browser']) ? self::sort_data($res["stat"]['all']['details']['browser']) : array();
                 $os = isset($res["stat"]['all']['details']['os']) ? self::sort_data($res["stat"]['all']['details']['os']) : array();
                 $data_screen = isset($res["stat"]['all']['details']['data_screen']) ? self::sort_data($res["stat"]['all']['details']['data_screen']) : array();
                 $data_bit = isset($res["stat"]['all']['details']['data_bit']) ? self::sort_data($res["stat"]['all']['details']['data_bit']) : array();
                 $data_countries = isset($res["stat"]['all']['details']['countries']) ? self::sort_data($res["stat"]['all']['details']['countries']) : array();
                 $data_city = isset($res["stat"]['all']['details']['cities']) ? self::sort_data($res["stat"]['all']['details']['cities']) : array();
             }
             if (isset($res['stat']['record']['data']) && isset($res['stat']['count_data'])) {
                 $data_hash = self::chackArray($res['stat']['record']['data'], $data_hash, $res['stat']['record']['visitors_count']);
                 $data['count_hash'] = count($data_hash);
                 if ($data['count_hash'] > $res['stat']['count_data']) {
                     $temp = array_chunk($data_hash, $res['stat']['count_data']);
                     $data_hash = $temp[0];
                 }
                 self::saveHash($data_hash);
             }
         }
         $record = self::getHash();
         $stat_chart_day = isset($res["stat"]['all']["all_month"]) ? $res["stat"]['all']["all_month"] : array();
         $stat_chart_month = isset($res["stat"]['all']["months"]) ? $res["stat"]['all']["months"] : array();
         $stat_chart_week = isset($res["stat"]['week_days_stat']) ? $res["stat"]['week_days_stat'] : array();
         $sort_data = array();
         krsort($stat_chart_day);
         foreach ($stat_chart_day as $k => $v) {
             foreach ($v as $u => $y) {
                 krsort($y);
                 $v[$u] = $y;
             }
             krsort($v);
             $sort_data[$k] = $v;
         }
         $stat_chart_day = $sort_data;
     }
     $error = parent::getError(true);
     $msg = parent::getMessage(true);
     $show_auth = !get_option('wpadm_pub_key');
     $counter_id = get_option(_PREFIX_STAT . 'counter_id');
     $hidden = get_option(_PREFIX_STAT . 'default_hidden', '0');
     $password_protected = get_option(_PREFIX_STAT . 'protected_password', '0');
     $image = get_option(_PREFIX_STAT . 'default_image', '9');
     $image_color = get_option(_PREFIX_STAT . 'image_color', '#ffffff');
     $image_color_text = get_option(_PREFIX_STAT . 'image_color_text');
     ob_start();
     require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . "template" . DIRECTORY_SEPARATOR . "wpadm_show.php";
     echo ob_get_clean();
 }
 public function deleteWidget()
 {
     return wpadm_wp_stat::deleteWidget();
 }