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-2012 Magic3 Project.
12 * @license http://www.gnu.org/copyleft/gpl.html GPL License
13 * @version SVN: $Id: blog_mainCommentWidgetContainer.php 5145 2012-08-29 13:21:42Z fishbone $
14 * @link http://www.magic3.org
16 require_once($gEnvManager->getCurrentWidgetContainerPath() . '/blog_mainBaseWidgetContainer.php');
17 require_once($gEnvManager->getCurrentWidgetDbPath() . '/blog_mainDb.php');
18 require_once($gEnvManager->getCurrentWidgetDbPath() . '/blog_commentDb.php');
20 class blog_mainCommentWidgetContainer extends blog_mainBaseWidgetContainer
22 private $db; // DB接続オブジェクト
23 private $mainDb; // DB接続オブジェクト
24 private $serialNo; // 選択中の項目のシリアル番号
26 private $lang; // 現在の選択言語
27 private $serialArray = array(); // 表示されている項目シリアル番号
28 private $entryArray = array(); // 表示されている項目の記事ID
29 const CONTENT_TYPE = 'bg'; // 記事参照数取得用
30 const DEFAULT_LIST_COUNT = 20; // 最大リスト表示数
31 const CATEGORY_COUNT = 2; // 記事カテゴリーの選択可能数
32 const COMMENT_SIZE = 40; // コメント内容の最大文字列長
37 function __construct()
40 parent::__construct();
43 $this->db = new blog_commentDb();
44 $this->mainDb = new blog_mainDb();
49 * _assign()でデータを埋め込むテンプレートファイルのファイル名を返す。
50 * 読み込むディレクトリは、「自ウィジェットディレクトリ/include/template」に固定。
52 * @param RequestManager $request HTTPリクエスト処理クラス
53 * @param object $param 任意使用パラメータ。そのまま_assign()に渡る
54 * @return string テンプレートファイル名。テンプレートライブラリを使用しない場合は空文字列「''」を返す。
56 function _setTemplate($request, &$param)
58 $task = $request->trimValueOf('task');
59 if ($task == 'comment_detail'){ // 詳細画面
60 return 'admin_comment_detail.tmpl.html';
62 return 'admin_comment.tmpl.html';
68 * _setTemplate()で指定したテンプレートファイルにデータを埋め込む。
70 * @param RequestManager $request HTTPリクエスト処理クラス
71 * @param object $param 任意使用パラメータ。_setTemplate()と共有。
74 function _assign($request, &$param)
76 $task = $request->trimValueOf('task');
77 if ($task == 'comment_detail'){ // 詳細画面
78 return $this->createDetail($request);
80 return $this->createList($request);
84 * JavascriptファイルをHTMLヘッダ部に設定
86 * JavascriptファイルをHTMLのheadタグ内に追加出力する。
87 * _assign()よりも後に実行される。
89 * @param RequestManager $request HTTPリクエスト処理クラス
90 * @param object $param 任意使用パラメータ。
91 * @return string Javascriptファイル。出力しない場合は空文字列を設定。
93 function _addScriptFileToHead($request, &$param)
95 $scriptArray = array($this->getUrl($this->gEnv->getScriptsUrl() . self::CALENDAR_SCRIPT_FILE), // カレンダースクリプトファイル
96 $this->getUrl($this->gEnv->getScriptsUrl() . self::CALENDAR_LANG_FILE), // カレンダー言語ファイル
97 $this->getUrl($this->gEnv->getScriptsUrl() . self::CALENDAR_SETUP_FILE)); // カレンダーセットアップファイル
102 * CSSファイルをHTMLヘッダ部に設定
104 * CSSファイルをHTMLのheadタグ内に追加出力する。
105 * _assign()よりも後に実行される。
107 * @param RequestManager $request HTTPリクエスト処理クラス
108 * @param object $param 任意使用パラメータ。
109 * @return string CSS文字列。出力しない場合は空文字列を設定。
111 function _addCssFileToHead($request, &$param)
113 return $this->getUrl($this->gEnv->getScriptsUrl() . self::CALENDAR_CSS_FILE);
118 * _setTemplate()で指定したテンプレートファイルにデータを埋め込む。
120 * @param RequestManager $request HTTPリクエスト処理クラス
123 function createList($request)
126 $defaultLangId = $this->gEnv->getDefaultLanguage();
128 $act = $request->trimValueOf('act');
129 $this->langId = $request->trimValueOf('item_lang'); // 現在メニューで選択中の言語
130 if (empty($this->langId)) $this->langId = $defaultLangId; // 言語が選択されていないときは、デフォルト言語を設定
131 $blogId = $request->trimValueOf(M3_REQUEST_PARAM_BLOG_ID); // 所属ブログ
134 $pageNo = $request->trimValueOf('page'); // ページ番号
135 if (empty($pageNo)) $pageNo = 1;
138 $maxListCount = self::DEFAULT_LIST_COUNT;
139 $serializedParam = $this->_db->getWidgetParam($this->gEnv->getCurrentWidgetId());
140 if (!empty($serializedParam)){
141 $dispInfo = unserialize($serializedParam);
142 $maxListCount = $dispInfo->maxMemberListCountByAdmin; // 会員リスト最大表示数
145 $search_startDt = $request->trimValueOf('search_start'); // 検索範囲開始日付
146 if (!empty($search_startDt)) $search_startDt = $this->convertToProperDate($search_startDt);
147 $search_endDt = $request->trimValueOf('search_end'); // 検索範囲終了日付
148 if (!empty($search_endDt)) $search_endDt = $this->convertToProperDate($search_endDt);
149 $search_keyword = $request->trimValueOf('search_keyword'); // 検索キーワード
151 if ($act == 'delete'){ // 項目削除の場合
152 $listedItem = explode(',', $request->trimValueOf('seriallist'));
154 for ($i = 0; $i < count($listedItem); $i++){
156 $itemName = 'item' . $i . '_selected';
157 $itemValue = ($request->trimValueOf($itemName) == 'on') ? 1 : 0;
159 if ($itemValue){ // チェック項目
160 $delItems[] = $listedItem[$i];
163 if (count($delItems) > 0){
164 $ret = $this->db->delCommentItem($delItems);
165 if ($ret){ // データ削除成功のとき
166 $this->setGuidanceMsg('データを削除しました');
168 $this->setAppErrorMsg('データ削除に失敗しました');
171 } else if ($act == 'search'){ // 検索のとき
172 if (!empty($search_startDt) && !empty($search_endDt) && $search_startDt > $search_endDt){
173 $this->setUserErrorMsg('期間の指定範囲にエラーがあります。');
175 $pageNo = 1; // ページ番号初期化
176 } else if ($act == 'selpage'){ // ページ選択
178 // ###### 一覧の取得条件を作成 ######
179 if (!empty($search_endDt)) $endDt = $this->getNextDay($search_endDt);
182 $totalCount = $this->db->getCommentItemCount($search_startDt, $endDt, $search_keyword, $this->langId, $blogId);
185 $pageCount = (int)(($totalCount -1) / $maxListCount) + 1; // 総ページ数
186 if ($pageNo < 1) $pageNo = 1;
187 if ($pageNo > $pageCount) $pageNo = $pageCount;
188 $this->firstNo = ($pageNo -1) * $maxListCount + 1; // 先頭番号
192 if ($pageCount > 1){ // ページが2ページ以上のときリンクを作成
193 for ($i = 1; $i <= $pageCount; $i++){
195 $link = ' ' . $i;
197 $link = ' <a href="#" onclick="selpage(\'' . $i . '\');return false;">' . $i . '</a>';
204 $this->db->searchCommentItems($maxListCount, $pageNo, $search_startDt, $endDt, $search_keyword, $this->langId, array($this, 'itemListLoop'), $blogId);
205 if (count($this->serialArray) <= 0) $this->tmpl->setAttribute('itemlist', 'visibility', 'hidden');// 投稿記事がないときは、一覧を表示しない
208 $this->tmpl->addVar("_widget", "page_link", $pageLink);
209 $this->tmpl->addVar("_widget", "total_count", $totalCount);
212 $this->tmpl->addVar("_widget", "search_start", $search_startDt); // 開始日付
213 $this->tmpl->addVar("_widget", "search_end", $search_endDt); // 終了日付
214 $this->tmpl->addVar("_widget", "search_keyword", $search_keyword); // 検索キーワード
217 $this->tmpl->addVar("_widget", "serial_list", implode($this->serialArray, ','));// 表示項目のシリアル番号を設定
218 $this->tmpl->addVar("_widget", "entry_list", implode($this->entryArray, ','));// 表示項目の記事IDを設定
219 $this->tmpl->addVar("_widget", "page", $pageNo); // ページ番号
220 $this->tmpl->addVar("_widget", "list_count", $maxListCount); // 一覧表示項目数
225 * @param RequestManager $request HTTPリクエスト処理クラス
228 function createDetail($request)
231 $defaultLangId = $this->gEnv->getDefaultLanguage();
232 $regUserId = $this->gEnv->getCurrentUserId(); // 記事投稿ユーザ
233 $regDt = date("Y/m/d H:i:s"); // 投稿日時
235 $act = $request->trimValueOf('act');
236 $this->langId = $request->trimValueOf('item_lang'); // 現在メニューで選択中の言語
237 if (empty($this->langId)) $this->langId = $defaultLangId; // 言語が選択されていないときは、デフォルト言語を設定
238 $this->entryId = $request->trimValueOf('entry'); // 記事エントリーID
239 $this->serialNo = $request->trimValueOf('serial'); // 選択項目のシリアル番号
240 if (empty($this->serialNo)) $this->serialNo = 0;
241 $name = $request->trimValueOf('item_name');
242 $html = $request->valueOf('item_html');
243 $url = $request->valueOf('item_url');
244 $email = $request->valueOf('item_email');
245 $reg_user = $request->valueOf('item_reg_user');
246 $status = $request->trimValueOf('item_status'); // エントリー状態(0=未設定、1=編集中、2=公開、3=非公開)
248 $dataReload = false; // データの再ロード
249 if ($act == 'add'){ // 項目追加の場合
252 $this->checkInput($name, 'タイトル');
255 if ($this->getMsgCount() == 0){
256 $ret = $this->db->addEntryItem(0, $this->langId, $name, $html, $status, $this->categoryArray, $regUserId, $regDt, $newSerial);
258 $this->setGuidanceMsg('データを追加しました');
260 $this->serialNo = $newSerial;
261 $dataReload = true; // データの再ロード
263 $this->setAppErrorMsg('データ追加に失敗しました');
266 } else if ($act == 'update'){ // 項目更新の場合
268 if ($this->getMsgCount() == 0){
269 $ret = $this->db->updateCommentItem($this->serialNo, $name, $html, $url, $reg_user, $email);
271 $this->setGuidanceMsg('データを更新しました');
272 $dataReload = true; // データの再ロード
274 $this->setAppErrorMsg('データ更新に失敗しました');
277 } else if ($act == 'delete'){ // 項目削除の場合
278 if (empty($this->serialNo)){
279 $this->setUserErrorMsg('削除項目が選択されていません');
282 if ($this->getMsgCount() == 0){
283 $ret = $this->db->delCommentItem(array($this->serialNo));
284 if ($ret){ // データ削除成功のとき
285 $this->setGuidanceMsg('データを削除しました');
287 $this->setAppErrorMsg('データ削除に失敗しました');
290 } else if ($act == 'deleteid'){ // ID項目削除の場合
291 } else { // 初期画面表示のとき
292 $dataReload = true; // データの再ロード
296 if ($dataReload){ // データの再ロード
297 $ret = $this->db->getCommentBySerial($this->serialNo, $row);
299 $this->entryId = $row['be_id']; // エントリーID
300 $entryTitle = $row['be_name']; // 記事タイトル
301 $name = $row['bo_name']; // コメントタイトル
302 $html = $row['bo_html']; // HTML
303 $email = $row['bo_email']; // eメール
304 $url = $row['bo_url']; // URL
305 $reg_user = $row['bo_user_name']; // 投稿者
306 $reg_dt = $this->convertToDispDateTime($row['bo_regist_dt']); // 投稿日時
307 $update_user = $row['update_user_name']; // 更新者
308 $update_dt = $this->convertToDispDateTime($row['bo_update_dt']); // 更新日時
313 $this->tmpl->addVar("_widget", "serial", $this->serialNo); // シリアル番号
315 // 入力フィールドの設定、共通項目のデータ設定
316 if ($this->entryId == 0){ // 記事IDが0のときは、新規追加モードにする
317 $this->tmpl->addVar('_widget', 'id', '新規');
319 $this->tmpl->setAttribute('add_button', 'visibility', 'visible');
321 $this->tmpl->addVar('_widget', 'id', $this->entryId);
323 if ($this->serialNo == 0){ // 未登録データのとき
325 $this->tmpl->setAttribute('add_button', 'visibility', 'visible');
328 $this->tmpl->setAttribute('delete_button', 'visibility', 'visible');// デフォルト言語以外はデータ削除
329 $this->tmpl->setAttribute('update_button', 'visibility', 'visible');
333 $this->tmpl->addVar("_widget", "entry_title", $this->convertToDispString($entryTitle)); // 記事タイトル
334 $this->tmpl->addVar("_widget", "name", $this->convertToDispString($name)); // コメントタイトル
335 $this->tmpl->addVar("_widget", "html", $this->convertToDispString($html)); // HTML
336 $this->tmpl->addVar("_widget", "email", $this->convertToDispString($email)); // Eメール
337 $this->tmpl->addVar("_widget", "url", $this->convertToDispString($url)); // URL
338 $this->tmpl->addVar("_widget", "reg_user", $this->convertToDispString($reg_user)); // 投稿者
339 $this->tmpl->addVar("_widget", "entry_dt", $reg_dt); // 投稿日時
340 $this->tmpl->addVar("_widget", "update_user", $this->convertToDispString($update_user)); // 更新者
341 $this->tmpl->addVar("_widget", "update_dt", $update_dt); // 更新日時
344 * 取得したデータをテンプレートに設定する
346 * @param int $index 行番号(0~)
347 * @param array $fetchedRow フェッチ取得した行
348 * @param object $param 未使用
349 * @return bool true=処理続行の場合、false=処理終了の場合
351 function itemListLoop($index, $fetchedRow, $param)
354 $serial = $fetchedRow['bo_serial'];
357 $entryId = $fetchedRow['be_id'];
360 /*switch ($fetchedRow['bo_status']){
361 case 1: $status = '<font color="green">公開</font>'; break;
362 case 2: $status = '非公開'; break;
366 if (function_exists('mb_strimwidth')){
367 $comment = mb_strimwidth($fetchedRow['bo_html'], 0, self::COMMENT_SIZE, '…');
369 $comment = substr($fetchedRow['bo_html'], 0, self::COMMENT_SIZE) . '...';
372 'index' => $index, // 項目番号
373 'no' => $index + 1, // 行番号
374 'serial' => $serial, // シリアル番号
375 'entry_name' => $this->convertToDispString($fetchedRow['be_name']), // 記事タイトル
376 'name' => $this->convertToDispString($fetchedRow['bo_name']), // コメントタイトル
377 'content' => $this->convertToDispString($comment), // コメント内容
378 'lang' => $lang, // 対応言語
379 'status' => $status, // 公開状況
380 'reg_user' => $this->convertToDispString($fetchedRow['bo_user_name']), // 投稿者
381 'reg_date' => $this->convertToDispDateTime($fetchedRow['bo_regist_dt']) // 投稿日時
383 $this->tmpl->addVars('itemlist', $row);
384 $this->tmpl->parseTemplate('itemlist', 'a');
387 $this->serialArray[] = $serial;
388 if (!in_array($entryId, $this->entryArray)) $this->entryArray[] = $entryId; // 存在しない場合は追加