コード例 #1
0
ファイル: Controller.php プロジェクト: aleafboat/techlog
 public function record_access()
 {
     $remote_host = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '-';
     $referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '-';
     $user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '-';
     $stats = new StatsModel(array('time_str' => 'now()', 'remote_host' => $remote_host, 'request' => "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'referer' => $referer, 'user_agent' => $user_agent));
     Repository::persist($stats);
     RedisRepository::setIpCache($remote_host);
 }
コード例 #2
0
ファイル: InfosController.php プロジェクト: aleafboat/techlog
 public function listAction()
 {
     $labels = array();
     $uv = array();
     $pv = array();
     $timestamp = time();
     for ($i = 0; $i < 14; ++$i) {
         $date = date('Y-m-d', $timestamp - 3600 * 24 * (14 - 1) + $i * 3600 * 24);
         list($total, $date) = SqlRepository::getUVInfos($date);
         $uv[] = $total;
         $labels[] = $date;
     }
     $pv_count = SqlRepository::getPVInfos($timestamp);
     foreach ($pv_count as $pv_info) {
         $pv[] = $pv_info['total'];
     }
     $all_pv = Repository::findCountFromStats();
     $all_uv = RedisRepository::getAllUV();
     $category_infos = SqlRepository::getCategoryInfos();
     $colors = array(array('color' => 'rgba(0, 255, 255, 0.8)', 'light' => 'rgba(220, 220, 220, 0.3)'), array('color' => 'rgba(255, 255, 128, 0.8)', 'light' => 'rgba(220, 220, 220, 0.3)'), array('color' => 'rgba(128, 128, 255, 0.8)', 'light' => 'rgba(220, 220, 220, 0.3)'), array('color' => 'rgba(17, 177, 255, 0.8)', 'light' => 'rgba(220, 220, 220, 0.3)'), array('color' => 'rgba(255, 128, 192, 0.8)', 'light' => 'rgba(220, 220, 220, 0.3)'), array('color' => 'rgba(128, 255, 128, 0.8)', 'light' => 'rgba(220, 220, 220, 0.3)'), array('color' => 'rgba(104, 180, 255, 0.8)', 'light' => 'rgba(220, 220, 220, 0.3)'));
     $category_data = array();
     $temp_infos = array();
     for ($i = 0; $i < count($category_infos); ++$i) {
         $infos = $category_infos[$i];
         $temp_infos['label'] = $infos['category'];
         $temp_infos['value'] = intval($infos['total']);
         $temp_infos['color'] = $colors[$i]['color'];
         $temp_infos['highlight'] = $colors[$i]['light'];
         $category_data[] = $temp_infos;
     }
     $category_data[] = array('label' => '心情小说', 'value' => intval(Repository::findCountFromMood()), 'color' => $colors[count($colors) - 1]['color'], 'highlight' => $colors[count($colors) - 1]['light']);
     $category_infos = SqlRepository::getCategoryNewArticle();
     $category_ids = array('龙潭书斋' => 1, '读书笔记' => 2, '龙渊阁记' => 3, '技术分享' => 4);
     if ($this->is_root) {
         $category_ids['龙泉日记'] = 5;
         $category_ids['龙泉财报'] = 6;
         $category_ids['心情小说'] = 'mood';
     }
     $params = array('all_pv' => $all_pv, 'all_uv' => $all_uv, 'today_pv' => $pv[13], 'today_uv' => $uv[13], 'category_infos' => $category_infos, 'category_ids' => json_encode($category_ids), 'pv' => json_encode($pv), 'uv' => json_encode($uv), 'labels' => json_encode($labels), 'category_data' => json_encode($category_data), 'title' => '数据统计');
     $this->display(__METHOD__, $params);
 }
コード例 #3
0
ファイル: RedisRepository.php プロジェクト: aleafboat/techlog
 private static function connect()
 {
     if (!empty(self::$redis)) {
         return;
     }
     $config = file_get_contents(APP_PATH . '/config.json');
     $config = json_decode($config, true);
     if (empty($config)) {
         echo 'ERROR: CONFIG ERROR' . PHP_EOL;
         exit;
     }
     $config = $config['redis'];
     try {
         self::$redis = new Redis();
         self::$redis->connect($config['host'], $config['port']);
         self::$redis->auth($config['password']);
     } catch (Exception $e) {
         echo '缓存连接失败 ' . $e->getMessage();
         exit;
     }
 }