7 * LICENSE: This source file is licensed under the terms of the GNU General Public License.
9 * @package Magic3 Framework
10 * @author 平田直毅(Naoki Hirata) <naoki@aplo.co.jp>
11 * @copyright Copyright 2006-2011 Magic3 Project.
12 * @license http://www.gnu.org/copyleft/gpl.html GPL License
13 * @version SVN: $Id: access_countWidgetContainer.php 4423 2011-11-07 05:31:29Z fishbone $
14 * @link http://www.magic3.org
16 require_once($gEnvManager->getContainerPath() . '/baseWidgetContainer.php');
17 require_once($gEnvManager->getCurrentWidgetDbPath() . '/access_countDb.php');
19 class access_countWidgetContainer extends BaseWidgetContainer
21 private $db; // DB接続オブジェクト
22 private $config = array();
23 private $isSystemManageUser; // システム運用可能ユーザかどうか
24 private $isHiddenCounter; // システム管理者、システム運用者の場合のみカウンターを表示するかどうか
29 function __construct()
32 parent::__construct();
34 // ###### アクセスカウンターの表示設定 ######
36 $this->config['img'] = $this->getUrl($this->gEnv->getCurrentWidgetRootUrl()) . '/images/';
37 $this->config['animated_img'] = $this->config['img'];
38 $this->config['animated_img_prefix'] = 'a'; // アニメーション画像ファイル用プレフィックス
41 $this->config['pad'] = 7;
44 $this->config['width'] = 16;
45 $this->config['height'] = 22;
48 $this->db = new access_countDb();
53 * _assign()でデータを埋め込むテンプレートファイルのファイル名を返す。
54 * 読み込むディレクトリは、「自ウィジェットディレクトリ/include/template」に固定。
56 * @param RequestManager $request HTTPリクエスト処理クラス
57 * @param object $param 任意使用パラメータ。そのまま_assign()に渡る
58 * @return string テンプレートファイル名。テンプレートライブラリを使用しない場合は空文字列「''」を返す。
60 function _setTemplate($request, &$param)
62 return 'index.tmpl.html';
67 * _setTemplate()で指定したテンプレートファイルにデータを埋め込む。
69 * @param RequestManager $request HTTPリクエスト処理クラス
70 * @param object $param 任意使用パラメータ。_setTemplate()と共有。
73 function _assign($request, &$param)
75 $this->isSystemManageUser = $this->gEnv->isSystemManageUser(); // システム運用可能ユーザかどうか
78 $this->isHiddenCounter = 0; // システム管理者、システム運用者の場合のみカウンターを表示するかどうか
79 $paramObj = $this->getWidgetParamObj();
80 if (!empty($paramObj)){
81 $this->isHiddenCounter = $paramObj->isHiddenCounter;
85 $numberList = $this->createOutput();
86 if (empty($numberList)){ // データが空のときは出力をキャンセル
89 $this->tmpl->addVar("_widget", "number_list", $numberList);
95 * @return bool true=新規アクセス、false=2回目以降アクセス
97 function isNewVisitor()
100 $ssid = session_id();
103 $ret = $this->db->isSessionExists($ssid);
104 if ($ret){ // レコードが存在しているときは、既存訪問者
113 * @param bool $up 新規のアクセスかどうか(true=新規アクセス、false=2回目以降アクセス)
116 function readCounter(&$up)
118 $date = date('Y-m-d');
119 $up = false; // 新規かどうか
122 if (!$this->isSystemManageUser){ // システム管理者、システム運用者の場合はカウントしない
123 // 1セッションに付き、一回だけカウンタを更新する
124 // 新規セッションであれば、カウンタを更新
125 if ($this->isNewVisitor()){
126 $this->db->incrementCount($date);
130 $count = $this->db->getCount($date);
136 * @return string HTMLテキスト
138 function createOutput()
141 $count = $this->readCounter($up);
143 if (!empty($this->isHiddenCounter) && !$this->isSystemManageUser){ // システム管理者、システム運用者以外はカウンターを表示しない
146 $countStr = sprintf("%0"."".$this->config['pad'].""."d", $count -1); // 1つ前のカウント
147 $destCountStr = sprintf("%0"."".$this->config['pad'].""."d", $count); // 実際のカウント
150 for ($i = 0; $i < strlen($countStr); $i++){
151 if (substr($countStr, $i, 1) == substr($destCountStr, $i, 1)){
152 $digit_pos = substr($countStr, $i, 1);
153 $html_output .= "<img src=\"".$this->config['img']."$digit_pos.gif\"";
155 $digit_pos = substr($destCountStr, $i, 1);
156 $html_output .= "<img src=\"".$this->config['animated_img']. $this->config['animated_img_prefix'] . "$digit_pos.gif\"";
158 $html_output .= " width=\"".$this->config['width']."\" height=\"".$this->config['height']."\" style=\"border:0;margin:0;padding:0;\" />";
161 for ($i = 0; $i < strlen($countStr); $i++){
162 $digit_pos = substr($destCountStr, $i, 1);
163 $html_output .= "<img src=\"".$this->config['img']."$digit_pos.gif\"";
164 $html_output .= " width=\"".$this->config['width']."\" height=\"".$this->config['height']."\" style=\"border:0;margin:0;padding:0;\" />";