7 * LICENSE: This source file is licensed under the terms of the GNU General Public License.
9 * @package Magic3 Framework
10 * @author 株式会社 毎日メディアサービス
11 * @copyright Copyright 2010 株式会社 毎日メディアサービス.
12 * @license http://www.gnu.org/copyleft/gpl.html GPL License
13 * @version SVN: $Id: admin_mainSearchwordlogWidgetContainer.php 5802 2013-03-07 06:14:29Z fishbone $
14 * @link http://www.m-media.co.jp
16 require_once($gEnvManager->getCurrentWidgetContainerPath() . '/admin_mainConditionBaseWidgetContainer.php');
17 require_once($gEnvManager->getCurrentWidgetDbPath() . '/admin_mainDb.php');
18 require_once($gEnvManager->getCurrentWidgetDbPath() . '/admin_serverDb.php');
20 class admin_mainSearchwordlogWidgetContainer extends admin_mainConditionBaseWidgetContainer
22 private $db; // DB接続オブジェクト
23 private $serverDb; // DB接続オブジェクト
24 private $sysDb; // システムDBオブジェクト
25 private $serialNo; // シリアルNo
26 private $serialArray = array(); // 表示されているコンテンツシリアル番号
27 private $clientIp; // クライアントのIPアドレス
28 private $path; // アクセスパス
29 private $logOrder; // 検索語の表示順
30 private $logOrderArray; // 検索語の表示順タイプ
31 private $browserIconFile; // ブラウザアイコンファイル名
32 private $showMessage; // メッセージ画面かどうか
33 private $message; // 表示メッセージ
34 private $server; // 指定サーバ
35 private $startNo; // 先頭の項目番号
36 const DEFAULT_LIST_COUNT = 30; // 最大リスト表示数
37 const MAX_PAGE_COUNT = 20; // 最大ページ数
38 const FLAG_ICON_DIR = '/images/system/flag/'; // 国旗アイコンディレクトリ
39 const BROWSER_ICON_DIR = '/images/system/browser/'; // ブラウザアイコンディレクトリ
40 const ICON_SIZE = 16; // アイコンのサイズ
41 // const DEFAULT_LOG_LEVEL = '0'; // デフォルトのログレベル
42 // const DEFAULT_LOG_STATUS = '1'; // デフォルトのログステータス
43 const DEFAULT_LOG_ORDER = '0'; // デフォルトの検索語表示順
44 const DEFAULT_ACCESS_PATH = 'index'; // デフォルトのアクセスパス(PC用アクセスポイント)
45 const ACCESS_PATH_ALL = '_all'; // アクセスパスすべて選択
46 const ACCESS_PATH_OTHER = '_other'; // アクセスパスその他
51 function __construct()
54 parent::__construct();
57 $this->db = new admin_mainDb();
58 $this->serverDb = new admin_serverDb();
61 $this->logOrderArray = array( array( 'name' => '最新', 'value' => '0'),
62 array( 'name' => '頻度高', 'value' => '1'));
65 $this->browserIconFile = array(
66 'OP' => 'opera.png', // opera
67 'IE' => 'ie.png', // microsoft internet explorer
68 'NS' => 'netscape.png', // netscape
69 'GA' => 'galeon.png', // galeon
70 'PX' => 'phoenix.png', // phoenix
71 'FF' => 'firefox.png', // firefox
72 'FB' => 'firebird.png', // mozilla firebird
73 'SM' => 'seamonkey.png', // seamonkey
74 'CA' => 'camino.png', // camino
75 'SF' => 'safari.png', // safari
76 'CH' => 'chrome.gif', // chrome
77 'KM' => 'k-meleon.png', // k-meleon
78 'MO' => 'mozilla.gif', // mozilla
79 'KO' => 'konqueror.png', // konqueror
80 'BB' => '', // blackberry
81 'IC' => 'icab.png', // icab
84 'MC' => '', // ncsa mosaic
86 'OW' => 'omniweb.png', // omniweb
87 'HJ' => '', // hotjava
88 'BX' => '', // browsex
89 'AV' => '', // amigavoyager
90 'AW' => '', // amiga-aweb
91 'IB' => '', // ibrowse
93 'EP' => 'epiphany.png', // epiphany
94 'FL' => 'flock.png', // flock
95 'SL' => 'sleipnir.gif' ,// sleipnir
96 'LU' => 'lunascape.gif', // lunascape
97 'SH' => 'shiira.gif', // shiira
98 'SW' => 'swift.png', // swift
99 'PS' => 'playstation.gif', // playstation portable
100 'PP' => 'playstation.gif', // ワイプアウトピュア
101 'NC' => 'netcaptor.gif', // netcaptor
102 'WT' => 'webtv.gif', // webtv
105 'GB' => 'google.gif', // Google
106 'MS' => 'msn.gif', // MSN
107 'YA' => 'yahoo.gif', // YahooSeeker
108 'GO' => 'goo.gif', // goo
109 'HT' => 'hatena.gif', // はてなアンテナ
110 'NV' => 'naver.gif', // Naver(韓国)
113 'DC' => 'docomo.gif', // ドコモ
114 'AU' => 'au.gif', // au
115 'SB' => 'softbank.gif', // ソフトバンク
121 * _assign()でデータを埋め込むテンプレートファイルのファイル名を返す。
122 * 読み込むディレクトリは、「自ウィジェットディレクトリ/include/template」に固定。
124 * @param RequestManager $request HTTPリクエスト処理クラス
125 * @param object $param 任意使用パラメータ。そのまま_assign()に渡る
126 * @return string テンプレートファイル名。テンプレートライブラリを使用しない場合は空文字列「''」を返す。
128 function _setTemplate($request, &$param)
130 // サーバ指定されている場合は接続先DBを変更
131 $this->server = $request->trimValueOf(M3_REQUEST_PARAM_SERVER);
132 if (!empty($this->server)){
134 $ret = $this->serverDb->getServerById($this->server, $row);
136 $dbDsn = $row['ts_db_connect_dsn']; // DB接続情報
137 $dbAccount = $row['ts_db_account']; // DB接続アカウント
138 $dbPassword = $row['ts_db_password'];// DB接続パスワード
141 $ret = $this->db->openLocalDb($dbDsn, $dbAccount, $dbPassword);// 接続先を変更
143 if (!$ret){ // サーバに接続できない場合
144 $this->showMessage = true; // メッセージ画面かどうか
145 $this->message = 'サーバに接続できません';
146 return 'message.tmpl.html';
150 $task = $request->trimValueOf('task');
151 if ($task == 'searchwordlog_detail'){ // 詳細画面
152 return 'searchwordlog_detail.tmpl.html';
154 return 'searchwordlog.tmpl.html';
160 * _setTemplate()で指定したテンプレートファイルにデータを埋め込む。
162 * @param RequestManager $request HTTPリクエスト処理クラス
163 * @param object $param 任意使用パラメータ。_setTemplate()と共有。
166 function _assign($request, &$param)
168 if ($this->showMessage){ // メッセージ画面かどうか
169 $this->setMsg(self::MSG_APP_ERR, $this->message);
172 $task = $request->trimValueOf('task');
173 if ($task == 'searchwordlog_detail'){ // 詳細画面
174 return $this->createDetail($request);
176 return $this->createList($request);
182 * @param RequestManager $request HTTPリクエスト処理クラス
185 function createList($request)
187 $this->clientIp = $this->gRequest->trimServerValueOf('REMOTE_ADDR'); // クライアントのIPアドレス
188 $act = $request->trimValueOf('act');
189 $this->path = $request->trimValueOf('path'); // アクセスパス
190 if (empty($this->path)) $this->path = self::DEFAULT_ACCESS_PATH;
191 $this->logOrder = $request->trimValueOf('logorder');// 検索語の表示順
192 if ($this->logOrder == '') $this->logOrder = self::DEFAULT_LOG_ORDER;
195 $viewCount = $request->trimValueOf('viewcount');// 表示項目数
196 if ($viewCount == '') $viewCount = self::DEFAULT_LIST_COUNT; // 表示項目数
197 $pageNo = $request->trimValueOf('page'); // ページ番号
198 if (empty($pageNo)) $pageNo = 1;
201 $pathParam = $this->path;
202 if ($pathParam == self::ACCESS_PATH_ALL){
204 } else if ($pathParam == self::ACCESS_PATH_OTHER){ // その他のパス
207 switch ($this->logOrder){
210 $this->tmpl->setAttribute('show_last_log', 'visibility', 'visible');// 最新から検索語を表示
213 $totalCount = $this->db->getSearchWordLogCount($pathParam);
216 $this->tmpl->setAttribute('show_sum_log', 'visibility', 'visible');// 検索頻度順に検索語を表示
219 $totalCount = $this->db->getSearchWordSumCount($pathParam);
224 $pageCount = (int)(($totalCount -1) / $viewCount) + 1; // 総ページ数
225 if ($pageNo < 1) $pageNo = 1;
226 if ($pageNo > $pageCount) $pageNo = $pageCount;
227 $startNo = ($pageNo -1) * $viewCount +1; // 先頭の行番号
228 $endNo = $pageNo * $viewCount > $totalCount ? $totalCount : $pageNo * $viewCount;// 最後の行番号
229 $this->startNo = $startNo; // 先頭の項目番号
233 if ($pageCount > 1){ // ページが2ページ以上のときリンクを作成
234 for ($i = 1; $i <= $pageCount; $i++){
235 if ($i > self::MAX_PAGE_COUNT) break; // 最大ページ数以上のときは終了
237 $link = ' ' . $i;
239 $link = ' <a href="#" onclick="selpage(\'' . $i . '\');return false;">' . $i . '</a>';
245 // アクセスパスメニュー、表示順選択メニュー作成
246 $this->createPathMenu();
247 $this->createLogOrderMenu();
249 $this->tmpl->addVar("_widget", "page_link", $pageLink);
250 $this->tmpl->addVar("_widget", "total_count", $totalCount);
251 $this->tmpl->addVar("_widget", "page", $pageNo); // ページ番号
252 $this->tmpl->addVar("_widget", "view_count", $viewCount); // 最大表示項目数
253 $this->tmpl->addVar("search_range", "start_no", $startNo);
254 $this->tmpl->addVar("search_range", "end_no", $endNo);
255 if ($totalCount > 0) $this->tmpl->setAttribute('search_range', 'visibility', 'visible');// 検出範囲を表示
258 $accessLogUrl = '?task=accesslog_detail&openby=simple';
259 if (!empty($this->server)) $accessLogUrl .= '&_server=' . $this->server;
260 $this->tmpl->addVar("_widget", "access_log_url", $accessLogUrl);
263 switch ($this->logOrder){
266 $this->db->getSearchWordLogList($viewCount, $pageNo, $pathParam, array($this, 'logListLoop'));
267 if (count($this->serialArray) == 0) $this->tmpl->setAttribute('loglist', 'visibility', 'hidden'); // ログがないときは非表示
269 $this->tmpl->addVar("_widget", "detail_disabled", 'disabled'); // 詳細画面遷移なし
272 $this->db->getSearchWordSumList($viewCount, $pageNo, $pathParam, array($this, 'logListSumLoop'));
273 if (count($this->serialArray) == 0) $this->tmpl->setAttribute('loglist_sum', 'visibility', 'hidden'); // ログがないときは非表示
276 $this->tmpl->addVar("_widget", "serial_list", implode($this->serialArray, ','));// 表示項目のシリアル番号を設定
281 * @param RequestManager $request HTTPリクエスト処理クラス
284 function createDetail($request)
286 $act = $request->trimValueOf('act');
287 $word = $request->trimValueOf('word'); // 比較語
288 $this->path = $request->trimValueOf('path'); // アクセスパス
289 if (empty($this->path)) $this->path = self::DEFAULT_ACCESS_PATH;
290 $this->logOrder = $request->trimValueOf('logorder');// 検索語の表示順
291 if ($this->logOrder == '') $this->logOrder = self::DEFAULT_LOG_ORDER;
292 $savedPageNo = $request->trimValueOf('page'); // ページ番号
295 $viewCount = $request->trimValueOf('viewcount');// 表示項目数
296 if ($viewCount == '') $viewCount = self::DEFAULT_LIST_COUNT; // 表示項目数
297 $pageNo = $request->trimValueOf('page_'); // ページ番号
298 if (empty($pageNo)) $pageNo = 1;
301 $pathParam = $this->path;
302 if ($pathParam == self::ACCESS_PATH_ALL){
304 } else if ($pathParam == self::ACCESS_PATH_OTHER){ // その他のパス
307 $totalCount = $this->db->getSearchWordLogCountByWord($word, $pathParam);
310 $pageCount = (int)(($totalCount -1) / $viewCount) + 1; // 総ページ数
311 if ($pageNo < 1) $pageNo = 1;
312 if ($pageNo > $pageCount) $pageNo = $pageCount;
313 $startNo = ($pageNo -1) * $viewCount +1; // 先頭の行番号
314 $endNo = $pageNo * $viewCount > $totalCount ? $totalCount : $pageNo * $viewCount;// 最後の行番号
315 $this->startNo = $startNo; // 先頭の項目番号
319 if ($pageCount > 1){ // ページが2ページ以上のときリンクを作成
320 for ($i = 1; $i <= $pageCount; $i++){
321 if ($i > self::MAX_PAGE_COUNT) break; // 最大ページ数以上のときは終了
323 $link = ' ' . $i;
325 $link = ' <a href="#" onclick="selpage(\'' . $i . '\');return false;">' . $i . '</a>';
331 $this->tmpl->addVar("_widget", "page_link", $pageLink);
332 $this->tmpl->addVar("_widget", "total_count", $totalCount);
333 $this->tmpl->addVar("_widget", "page_", $pageNo); // ページ番号
334 $this->tmpl->addVar("_widget", "view_count", $viewCount); // 最大表示項目数
335 $this->tmpl->addVar("search_range", "start_no", $startNo);
336 $this->tmpl->addVar("search_range", "end_no", $endNo);
337 if ($totalCount > 0) $this->tmpl->setAttribute('search_range', 'visibility', 'visible');// 検出範囲を表示
339 // 前ウィンドウから引き継いだパラメータ
340 $this->tmpl->addVar("_widget", "log_order", $this->logOrder);
341 $this->tmpl->addVar("_widget", "path", $this->path);
342 $this->tmpl->addVar("_widget", "compare_word", $word);
343 $this->tmpl->addVar("_widget", "page", $savedPageNo);
346 $accessLogUrl = '?task=accesslog_detail&openby=simple';
347 if (!empty($this->server)) $accessLogUrl .= '&_server=' . $this->server;
348 $this->tmpl->addVar("_widget", "access_log_url", $accessLogUrl);
351 $this->db->getSearchWordLogListByWord($word, $viewCount, $pageNo, $pathParam, array($this, 'logListLoop'));
352 if (count($this->serialArray) == 0) $this->tmpl->setAttribute('loglist', 'visibility', 'hidden'); // ログがないときは非表示
355 * 検索語一覧取得したデータをテンプレートに設定する
357 * @param int $index 行番号(0~)
358 * @param array $fetchedRow フェッチ取得した行
359 * @param object $param 未使用
360 * @return bool true=処理続行の場合、false=処理終了の場合
362 function logListLoop($index, $fetchedRow, $param)
365 $no = $this->startNo + $index;
367 // ブラウザ、プラットフォームの情報を取得
368 $isMobile = false; // 携帯かどうか
369 $browserCode = $this->gInstance->getAnalyzeManager()->getBrowserType($fetchedRow['al_user_agent'], $version);
371 if (!empty($browserCode)){
373 if ($browserCode == 'DC' || // ドコモ
374 $browserCode == 'AU' || // au
375 $browserCode == 'SB'){ // ソフトバンク
381 if (!empty($fetchedRow['al_accept_language'])) $countryCode = $this->gInstance->getAnalyzeManager()->getBrowserCountryCode($fetchedRow['al_accept_language']);
382 if ($isMobile) $countryCode = 'jp'; // 携帯の場合は日本に設定
385 if (!empty($countryCode)){
386 $iconTitle = $countryCode;
387 $iconUrl = $this->gEnv->getRootUrl() . self::FLAG_ICON_DIR . $countryCode . '.png';
388 $countryImg = '<img src="' . $this->getUrl($iconUrl) . '" border="0" alt="' . $iconTitle . '" title="' . $iconTitle . '" />';
391 // ブラウザ、プラットフォームの情報を取得
392 $browserCode = $this->gInstance->getAnalyzeManager()->getBrowserType($fetchedRow['al_user_agent'], $version);
394 if (!empty($browserCode)){
395 $iconFile = $this->browserIconFile[$browserCode];
396 if (!empty($iconFile)){
397 $iconTitle = $browserCode;
398 $iconUrl = $this->gEnv->getRootUrl() . self::BROWSER_ICON_DIR . $iconFile;
399 $browserImg = '<img src="' . $this->getUrl($iconUrl) . '" border="0" alt="' . $iconTitle . '" title="' . $iconTitle . '" />';
404 if (!empty($fetchedRow['sw_access_log_serial'])) $accessLog = $this->convertToDispString($fetchedRow['sw_access_log_serial']);
407 'index' => $index, // 行番号
408 'no' => $no, // シリアル番号
409 'word' => $this->convertToDispString($fetchedRow['sw_word']), // 語句
410 'browser' => $browserImg, // ブラウザ
411 'country' => $countryImg, // 国画像
412 'access_log' => $accessLog, // アクセスログ番号
413 'user' => $this->convertToDispString($fetchedRow['lu_name']), // ユーザ
414 'dt' => $this->convertToDispDateTime($fetchedRow['al_dt']), // 出力日時
415 'selected' => $selected // 項目選択用ラジオボタン
417 $this->tmpl->addVars('loglist', $row);
418 $this->tmpl->parseTemplate('loglist', 'a');
421 $this->serialArray[] = $fetchedRow['sw_serial'];
425 * 検索語一覧取得したデータをテンプレートに設定する
427 * @param int $index 行番号(0~)
428 * @param array $fetchedRow フェッチ取得した行
429 * @param object $param 未使用
430 * @return bool true=処理続行の場合、false=処理終了の場合
432 function logListSumLoop($index, $fetchedRow, $param)
435 $no = $this->startNo + $index;
438 $word = $fetchedRow['sw_basic_word'];
439 $ret = $this->db->getSearchWordLogByCompareWord($word, $row);
442 'index' => $index, // 行番号
443 'no' => $no, // シリアル番号
444 'word' => $this->convertToDispString($row['sw_word']), // 語句
445 'compare_word' => $this->convertToDispString($word), // 比較語
446 'count' => $this->convertToDispString($fetchedRow['ct']), // 検索回数
447 'country' => $countryImg, // 国画像
448 'access_log' => $accessLog, // アクセスログ番号
449 'user' => $this->convertToDispString($row['lu_name']), // ユーザ
450 'dt' => $this->convertToDispDateTime($row['al_dt']), // 出力日時
451 'selected' => $selected // 項目選択用ラジオボタン
453 $this->tmpl->addVars('loglist_sum', $row);
454 $this->tmpl->parseTemplate('loglist_sum', 'a');
457 $this->serialArray[] = $no;
465 function createPathMenu()
468 if ($this->path == self::ACCESS_PATH_ALL){// アクセスパスすべて選択
469 $selected = 'selected';
472 'value' => self::ACCESS_PATH_ALL, // アクセスパス
473 'name' => 'すべて表示', // 表示文字列
474 'selected' => $selected // 選択中かどうか
476 $this->tmpl->addVars('path_list', $row);
477 $this->tmpl->parseTemplate('path_list', 'a');
479 $this->db->getPageIdList(array($this, 'pageIdLoop'), 0/*ページID*/);
482 if ($this->path == self::ACCESS_PATH_OTHER){// アクセスパスその他
483 $selected = 'selected';
486 'value' => self::ACCESS_PATH_OTHER, // アクセスパス
487 'name' => 'その他', // 表示文字列
488 'selected' => $selected // 選択中かどうか
490 $this->tmpl->addVars('path_list', $row);
491 $this->tmpl->parseTemplate('path_list', 'a');
498 function createLogOrderMenu()
500 for ($i = 0; $i < count($this->logOrderArray); $i++){
501 $value = $this->logOrderArray[$i]['value'];
502 $name = $this->logOrderArray[$i]['name'];
505 if ($value == $this->logOrder) $selected = 'selected';
508 'value' => $value, // 表示順
509 'name' => $name, // 表示順名
510 'selected' => $selected // 選択中かどうか
512 $this->tmpl->addVars('logorder_list', $row);
513 $this->tmpl->parseTemplate('logorder_list', 'a');
517 * ページID、取得したデータをテンプレートに設定する
519 * @param int $index 行番号(0~)
520 * @param array $fetchedRow フェッチ取得した行
521 * @param object $param 未使用
522 * @return bool true=処理続行の場合、false=処理終了の場合
524 function pageIdLoop($index, $fetchedRow, $param)
527 if ($fetchedRow['pg_path'] == $this->path){
528 $selected = 'selected';
530 $name = $this->convertToDispString($fetchedRow['pg_path']) . ' - ' . $this->convertToDispString($fetchedRow['pg_name']); // ページ名
532 'value' => $this->convertToDispString($fetchedRow['pg_path']), // アクセスパス
533 'name' => $name, // ページ名
534 'selected' => $selected // 選択中かどうか
536 $this->tmpl->addVars('path_list', $row);
537 $this->tmpl->parseTemplate('path_list', 'a');