OSDN Git Service

Awstatsの出力データの参照機能を管理機能に追加。
authornaoki hirata <naoki@magic3.org>
Tue, 8 Apr 2014 09:54:18 +0000 (18:54 +0900)
committernaoki hirata <naoki@magic3.org>
Tue, 8 Apr 2014 09:54:18 +0000 (18:54 +0900)
include/common/m3Func.php
include/common/userInfo.php
templates/_admin4/css/style.css
widgets/admin_main/include/container/admin_mainAwstatsWidgetContainer.php
widgets/admin_main/include/container/admin_mainConditionBaseWidgetContainer.php
widgets/admin_main/include/container/admin_mainWidgetContainer.php
widgets/admin_main/include/template/awstats.tmpl.html [new file with mode: 0644]

index 5a00cad..ca831a1 100644 (file)
@@ -8,9 +8,9 @@
  *
  * @package    Magic3 Framework
  * @author     平田直毅(Naoki Hirata) <naoki@aplo.co.jp>
- * @copyright  Copyright 2006-2012 Magic3 Project.
+ * @copyright  Copyright 2006-2014 Magic3 Project.
  * @license    http://www.gnu.org/copyleft/gpl.html  GPL License
- * @version    SVN: $Id: m3Func.php 5303 2012-10-22 09:31:23Z fishbone $
+ * @version    SVN: $Id$
  * @link       http://www.magic3.org
  */
 /**
@@ -282,6 +282,48 @@ function removeExtension($path)
 //     }
 }
 /**
+ * 相対パスから絶対パスを生成(パスまたはURL)
+ *
+ * @param string $rel                  相対パス
+ * @param string $base                 基点のパス(パスまたはURL)
+ * @return string                              絶対パス
+ */
+function rel2abs($rel, $base)
+{
+       /* return if already absolute URL */
+       if (parse_url($rel, PHP_URL_SCHEME) != '') return $rel;
+
+       /* queries and anchors */
+       if ($rel[0]=='#' || $rel[0]=='?') return $base.$rel;
+
+       /* parse base URL and convert to local variables: $scheme, $host, $path */
+       extract(parse_url($base));
+
+       /* remove non-directory element from path */
+//     $path = preg_replace('#/[^/]*$#', '', $path);
+
+       /* destroy path if relative url points to root */
+       if ($rel[0] == '/') $path = '';
+
+       /* dirty absolute URL // with port number if exists */
+       if (parse_url($base, PHP_URL_PORT) != ''){
+               $abs = "$host:" . parse_url($base, PHP_URL_PORT) . "$path/$rel";
+       }else{
+               $abs = "$host$path/$rel";
+       }
+       
+       /* replace '//' or '/./' or '/foo/../' with '/' */
+       $re = array('#(/\.?/)#', '#/(?!\.\.)[^/]+/\.\./#');
+       for ($n = 1; $n > 0; $abs = preg_replace($re, '/', $abs, -1, $n)){}
+
+    // 絶対パスを返す
+       if (empty($scheme)){
+               return $abs;
+       } else {
+       return $scheme . '://' . $abs;
+       }
+}
+/**
  * ディレクトリ内のファイル一覧の取得
  *
  * @param string $dirPath                      ディレクトリのパス
index 8f5a59a..396e8d4 100644 (file)
@@ -8,9 +8,9 @@
  *
  * @package    Magic3 Framework
  * @author     平田直毅(Naoki Hirata) <naoki@aplo.co.jp>
- * @copyright  Copyright 2006-2013 Magic3 Project.
+ * @copyright  Copyright 2006-2014 Magic3 Project.
  * @license    http://www.gnu.org/copyleft/gpl.html  GPL License
- * @version    SVN: $Id: userInfo.php 6096 2013-06-12 11:33:36Z fishbone $
+ * @version    SVN: $Id$
  * @link       http://www.magic3.org
  */
 class UserInfo
@@ -25,7 +25,7 @@ class UserInfo
        public $_recordSerial;                  // 更新時に使用
        
        // ユーザタイプ
-       //const USER_TYPE_VISITOR                               = -100;                 // 訪問者(ログインなし)
+       //const USER_TYPE_GUEST                         = -100;                         // ゲストユーザ(ログインなし)
        const USER_TYPE_NOT_AUTHENTICATED       = -1;                           // 未承認ユーザ
        const USER_TYPE_TMP                                     = 0;                            // 仮ユーザ
        const USER_TYPE_NORMAL                          = 10;                           // 一般ユーザ
index 6416e3c..978b02b 100644 (file)
@@ -51,6 +51,20 @@ a:hover {
        color: #FF0000;
        text-decoration  : none;
 }*/
+/****** 管理画面全体 *****/
+.m3admin_container {
+       margin:0 auto;
+       width:90%;
+}
+.m3admin_container .m3title {
+       display:inline-block;
+}
+.m3list_indent1 {
+       margin-left:70px;
+}
+.m3list_indent2 {
+       margin-left:140px;
+}
 /*** Bootstrap bug fix ***/
 input[type="password"]{
        font-size: 14px;
index f9898d6..61cffb6 100644 (file)
@@ -17,9 +17,8 @@ require_once($gEnvManager->getCurrentWidgetContainerPath() .  '/admin_mainConditi
 
 class admin_mainAwstatsWidgetContainer extends admin_mainConditionBaseWidgetContainer
 {
-       const CF_LAST_DATE_CALC_PV      = 'last_date_calc_pv';  // ページビュー集計の最終更新日
-       const DEFAULT_STR_NOT_CALC = '未集計';               // 未集計時の表示文字列
-       const MAX_CALC_DAYS = 30;                                       // 最大集計日数
+       private $awstatsPath;           // Awstatsデータディレクトリパス
+       private $awstatsUrl;            // AwstatsデータディレクトリURL
        
        /**
         * コンストラクタ
@@ -41,7 +40,7 @@ class admin_mainAwstatsWidgetContainer extends admin_mainConditionBaseWidgetCont
         */
        function _setTemplate($request, &$param)
        {
-               return 'analyzecalc.tmpl.html';
+               return 'awstats.tmpl.html';
        }
        /**
         * テンプレートにデータ埋め込む
@@ -54,29 +53,102 @@ class admin_mainAwstatsWidgetContainer extends admin_mainConditionBaseWidgetCont
         */
        function _assign($request, &$param)
        {
-               $act = $request->trimValueOf('act');
+               $this->awstatsPath = $this->getAwstatsPath();           // Awstatsデータディレクトリパス
+               $this->awstatsUrl = $this->getAwstatsUrl();             // AwstatsデータディレクトリURL
+               
+               // 集計ファイルを取得
+               list($yearFileArray, $monthFileArray) = $this->getYearMonthFile($this->awstatsPath);
+               
+               // 年月データ一覧を作成
+               $this->createYearMonthList($yearFileArray, $monthFileArray);
+               
+               // 値を埋め込む
+               $this->tmpl->addVar("_widget", "last_index", $this->getAwstatsUrl());
+       }
+       /**
+        * 年月ごとの集計ファイルを取得(昇順)
+        *
+        * @param string $path          検索ディレクトリ
+        * @return array                        月別ファイル一覧と年別ファイルの一覧の配列
+        */
+       function getYearMonthFile($path)
+       {
+               $yearArray = array();
+               $monthArray = array();
+               
+               $dir = dir($path);
+               while (($file = $dir->read()) !== false){
+                       $filePath = $path . '/' . $file;
+                       // ディレクトリかどうかチェック
+                       if (strncmp($file, '.', 1) != 0 && $file != '..' && is_file($filePath)){
+                               $ret = preg_match("/^([0-9]{4})([0-9]{0,2})\.html$/", $file, $match);
+                               if ($ret){
+                                       if (empty($match[2])){
+                                               $yearArray[] = $match[0];
+                                       } else {
+                                               $monthArray[] = $match[0];
+                                       }
+                               }
 
-               if ($act == 'calc'){            // 集計実行のとき
-                       $messageArray = array();
-                       $ret = $this->gInstance->getAnalyzeManager()->updateAnalyticsData($messageArray);
-                       if ($ret){
-                               $this->setMsg(self::MSG_GUIDANCE, $messageArray[0]);
-                       } else {
-                               $this->setMsg(self::MSG_APP_ERR, $messageArray[0]);
                        }
-               } else if ($act == 'delall'){           // 集計データを削除するとき
-               //      $ret = $this->db->updateStatus(self::CF_LAST_DATE_CALC_PV, '');
-               } else {                // 初期状態
                }
-
-               // 値を埋め込む
-//             $lastDateCalcPv = $this->db->getStatus(self::CF_LAST_DATE_CALC_PV);             // ページビュー集計最終更新日
-               if (empty($lastDateCalcPv)){
-                       $lastDateCalcPv = self::DEFAULT_STR_NOT_CALC;
-               } else {
-                       $lastDateCalcPv = $this->convertToDispDate($lastDateCalcPv);            // 最終集計日
+               $dir->close();
+               
+               sort($yearArray);
+               sort($monthArray);
+               return array($yearArray, $monthArray);
+       }
+       /**
+        * 年月一覧を作成
+        *
+        * @param array $yearFileArray                  年データファイル名
+        * @param array $monthFileArray                 月データファイル名
+        * @return なし                                               
+        */
+       function createYearMonthList($yearFileArray, $monthFileArray)
+       {
+               if (count($monthFileArray) > 0){
+                       preg_match("/^([0-9]{4})([0-9]{0,2})\.html$/", $monthFileArray[0], $match);
+                       $startYear = intval($match[1]);
+                       $startMonth = intval($match[2]);
+                       
+                       preg_match("/^([0-9]{4})([0-9]{0,2})\.html$/", $monthFileArray[count($monthFileArray) -1], $match);
+                       $endYear = intval($match[1]);
+                       $endMonth = intval($match[2]);
+               }
+               
+               for ($i = $endYear; $i >= $startYear; $i--){
+                       // 月データの出力
+                       $this->tmpl->clearTemplate('month_list');
+                       for ($j = 1; $j <= 12; $j++){
+                               // ファイルの存在チェック
+                               $filename = $i . sprintf('%02d', $j) . '.html';
+                               $monthDataFile = $this->awstatsPath . '/' . $filename;
+                               $monthTag = $j . '月';
+                               if (file_exists($monthDataFile)){
+                                       $monthDataUrl = $this->awstatsUrl . '/' . $filename;
+                                       $monthTag = '<a href="' . $monthDataUrl . '" target="_blank">' . $monthTag . '</a>';
+                               }
+                               $monthRow = array(
+                                       'month' =>      $monthTag                                                                               // 月
+                               );
+                               $this->tmpl->addVars('month_list', $monthRow);
+                               $this->tmpl->parseTemplate('month_list', 'a');
+                       }
+                       // ファイルの存在チェック
+                       $filename = $i . '.html';
+                       $yearDataFile = $this->awstatsPath . '/' . $filename;
+                       $yearTag = $i . '年';
+                       if (file_exists($yearDataFile)){
+                               $yearDataUrl = $this->awstatsUrl . '/' . $filename;             // AwstatsデータディレクトリURL
+                               $yearTag = '<a href="' . $yearDataUrl . '" target="_blank">' . $yearTag . '</a>';
+                       }
+                       $yearRow = array(
+                                       'year'          =>      $yearTag                // 年
+                       );
+                       $this->tmpl->addVars('year_list', $yearRow);
+                       $this->tmpl->parseTemplate('year_list', 'a');
                }
-               $this->tmpl->addVar("_widget", "lastdate_pv", $lastDateCalcPv);
        }
 }
 ?>
index 639c352..e4654ae 100644 (file)
@@ -31,6 +31,7 @@ class admin_mainConditionBaseWidgetContainer extends admin_mainBaseWidgetContain
        const TASK_SEARCHWORDLOG_DETAIL = 'searchwordlog_detail';               // 検索語ログ詳細
        const TASK_AWSTATS              = 'awstats';            // Awstats表示
        const DEFAULT_TOP_PAGE = 'accesslog';           // デフォルトのトップ画面
+       const CF_AWSTATS_DATA_PATH = 'awstats_data_path';               // Awstatsデータパス
        
        /**
         * コンストラクタ
@@ -176,7 +177,12 @@ class admin_mainConditionBaseWidgetContainer extends admin_mainBaseWidgetContain
                        if ($task == self::TASK_AWSTATS) $current = 'id="current"';
                        // ヘルプを作成
                        $helpText = $this->gInstance->getHelpManager()->getHelpText(self::TASK_AWSTATS);
-                       $menuText .= '<li ' . $current . '><a href="'. $this->getUrl($link) .'"><span ' . $helpText . '>Awstats</span></a></li>' . M3_NL;
+                       $isAwstats = $this->isExistsAwstats();
+                       if ($isAwstats){                // Awstatsが使用可能な場合
+                               $menuText .= '<li ' . $current . '><a href="'. $this->getUrl($link) .'"><span ' . $helpText . '>Awstats</span></a></li>' . M3_NL;
+                       } else {
+                               $menuText .= '<li ' . $current . '><a href="javascript:void(0);"><span ' . $helpText . '>Awstats</span></a></li>' . M3_NL;
+                       }
                } else if ($task == self::TASK_GRAPH || // グラフ表示
                                        $task == self::TASK_CALC){              // 集計
 
@@ -206,5 +212,41 @@ class admin_mainConditionBaseWidgetContainer extends admin_mainBaseWidgetContain
                $outputText .= '<table width="90%"><tr><td>' . $linkList . $menuText . '</td></tr></table>' . M3_NL;
                $this->tmpl->addVar("_widget", "menu_items", $outputText);
        }
+       /**
+        * Awstatsの作成データが参照できるかどうか
+        *
+        * @return bool         true=参照可、false=参照不可
+        */
+       function isExistsAwstats()
+       {
+               $awstatsDataPath = $this->getAwstatsPath();
+               if (is_dir($awstatsDataPath)){
+                       return true;
+               } else {
+                       return false;
+               }
+       }
+       /**
+        * Awstatsの作成データのパスを取得
+        *
+        * @return string               パス
+        */
+       function getAwstatsPath()
+       {
+               $path = $this->gSystem->getSystemConfig(self::CF_AWSTATS_DATA_PATH);
+               $awstatsDataPath = rel2abs($path, $this->gEnv->getSystemRootPath());
+               return $awstatsDataPath;
+       }
+       /**
+        * Awstatsの作成データのURLを取得
+        *
+        * @return string               URL
+        */
+       function getAwstatsUrl()
+       {
+               $path = $this->gSystem->getSystemConfig(self::CF_AWSTATS_DATA_PATH);
+               $awstatsDataPath = rel2abs($path, $this->gEnv->getRootUrl());
+               return $awstatsDataPath;
+       }
 }
 ?>
index f9e478a..6797ecc 100644 (file)
@@ -260,6 +260,7 @@ class admin_mainWidgetContainer extends admin_mainBaseWidgetContainer
                                                case 'opelog':                  // 運用ログ
                                                case 'accesslog':                       // アクセスログ
                                                case 'searchwordlog':           // 検索語ログ一覧
+                                               case 'awstats':                         // Awstats
                                                case 'resbrowse':                       // リソースブラウズ(resbrowseからfilebrowserを起動)
 //                                             case 'filebrowse':                      // ファイルブラウズ
                                                case 'filebrowser':                     // ファイルブラウズ(elfinder)
diff --git a/widgets/admin_main/include/template/awstats.tmpl.html b/widgets/admin_main/include/template/awstats.tmpl.html
new file mode 100644 (file)
index 0000000..51a7805
--- /dev/null
@@ -0,0 +1,28 @@
+/**
+ * 表示データ作成用テンプレート(patTemplate)
+ *
+ * LICENSE: This source file is licensed under the terms of the GNU General Public License.
+ *
+ * @package    Magic3 Framework
+ * @author     平田直毅(Naoki Hirata) <naoki@aplo.co.jp>
+ * @copyright  Copyright 2006-2014 Magic3 Project.
+ * @license    http://www.gnu.org/copyleft/gpl.html  GPL License
+ * @version    SVN: $Id$
+ * @link       http://www.magic3.org
+ */
+<patTemplate:tmpl name="_widget">
+<div class="m3admin_container">
+<!-- m3:ErrorMessage -->
+<h3 class="m3title">Awstats</h3>
+<ul class="list-group">
+<li class="list-group-item"><a href="{LAST_INDEX}" target="_blank">最新</a></li>
+<patTemplate:tmpl name="year_list">
+<li class="list-group-item">{YEAR}<ul class="list-inline m3list_indent1">
+<patTemplate:tmpl name="month_list">
+<li>{MONTH}</li>
+</patTemplate:tmpl>
+</ul></li>
+</patTemplate:tmpl>
+</ul>
+</div>
+</patTemplate:tmpl>