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-2013 Magic3 Project.
12 * @license http://www.gnu.org/copyleft/gpl.html GPL License
13 * @version SVN: $Id: admin_commentCommentWidgetContainer.php 6115 2013-06-16 12:39:34Z fishbone $
14 * @link http://www.magic3.org
16 require_once($gEnvManager->getWidgetContainerPath('comment') . '/admin_commentBaseWidgetContainer.php');
18 class admin_commentCommentWidgetContainer extends admin_commentBaseWidgetContainer
20 private $serialNo; // 選択中の項目のシリアル番号
21 private $langId; // デフォルトの言語
22 private $serialArray = array(); // 表示されている項目シリアル番号
23 private $contentType; // 選択中のコンテンツタイプ
24 private $contentTypeArray; // コンテンツ選択メニュー用
25 private $permitHtml; // HTMLあり
26 private $status; // コメント状態(0=未設定、1=非公開、2=公開)
27 private $statusTypeArray; // コメント状態メニュー作成用
29 const DEFAULT_LIST_COUNT = 20; // 最大リスト表示数
30 const COMMENT_SIZE = 40; // コメント内容の最大文字列長
31 const SEARCH_ICON_FILE = '/images/system/search16.png'; // 検索用アイコン
32 const PREVIEW_ICON_FILE = '/images/system/preview.png'; // プレビュー用アイコン
33 const UNTITLED_CONTENT = 'タイトル未設定';
38 function __construct()
41 parent::__construct();
44 $this->contentTypeArray = array_merge(array(array('name' => '[すべて]', 'value' => '')), $this->gPage->getMainContentType());// コンテンツタイプ取得
45 $this->langId = $this->gEnv->getDefaultLanguage();
46 $this->statusTypeArray = array( array( 'name' => '未承認', 'value' => '0'),
47 array( 'name' => '非公開', 'value' => '1'),
48 array( 'name' => '公開', 'value' => '2'));
53 * _assign()でデータを埋め込むテンプレートファイルのファイル名を返す。
54 * 読み込むディレクトリは、「自ウィジェットディレクトリ/include/template」に固定。
56 * @param RequestManager $request HTTPリクエスト処理クラス
57 * @param object $param 任意使用パラメータ。そのまま_assign()に渡る
58 * @return string テンプレートファイル名。テンプレートライブラリを使用しない場合は空文字列「''」を返す。
60 function _setTemplate($request, &$param)
62 $task = $request->trimValueOf('task');
63 if ($task == 'comment_detail'){ // 詳細画面
64 return 'admin_comment_detail.tmpl.html';
66 return 'admin_comment.tmpl.html';
72 * _setTemplate()で指定したテンプレートファイルにデータを埋め込む。
74 * @param RequestManager $request HTTPリクエスト処理クラス
75 * @param object $param 任意使用パラメータ。_setTemplate()と共有。
78 function _assign($request, &$param)
80 $task = $request->trimValueOf('task');
81 if ($task == 'comment_detail'){ // 詳細画面
82 return $this->createDetail($request);
84 return $this->createList($request);
88 * JavascriptファイルをHTMLヘッダ部に設定
90 * JavascriptファイルをHTMLのheadタグ内に追加出力する。
91 * _assign()よりも後に実行される。
93 * @param RequestManager $request HTTPリクエスト処理クラス
94 * @param object $param 任意使用パラメータ。
95 * @return string Javascriptファイル。出力しない場合は空文字列を設定。
97 function _addScriptFileToHead($request, &$param)
99 $scriptArray = array($this->getUrl($this->gEnv->getScriptsUrl() . self::CALENDAR_SCRIPT_FILE), // カレンダースクリプトファイル
100 $this->getUrl($this->gEnv->getScriptsUrl() . self::CALENDAR_LANG_FILE), // カレンダー言語ファイル
101 $this->getUrl($this->gEnv->getScriptsUrl() . self::CALENDAR_SETUP_FILE)); // カレンダーセットアップファイル
106 * CSSファイルをHTMLヘッダ部に設定
108 * CSSファイルをHTMLのheadタグ内に追加出力する。
109 * _assign()よりも後に実行される。
111 * @param RequestManager $request HTTPリクエスト処理クラス
112 * @param object $param 任意使用パラメータ。
113 * @return string CSS文字列。出力しない場合は空文字列を設定。
115 function _addCssFileToHead($request, &$param)
117 return $this->getUrl($this->gEnv->getScriptsUrl() . self::CALENDAR_CSS_FILE);
122 * _setTemplate()で指定したテンプレートファイルにデータを埋め込む。
124 * @param RequestManager $request HTTPリクエスト処理クラス
127 function createList($request)
130 $maxListCount = self::DEFAULT_LIST_COUNT;
133 $act = $request->trimValueOf('act');
134 // $this->contentType = $request->trimValueOf('content_type'); // 選択中のコンテンツタイプ
135 // if (empty($this->contentType)) $this->contentType = $request->trimValueOf('item_content_type'); // 選択中のコンテンツタイプ
138 $pageNo = $request->trimValueOf('page'); // ページ番号
139 if (empty($pageNo)) $pageNo = 1;
141 $search_startDt = $request->trimValueOf('search_start'); // 検索範囲開始日付
142 if (!empty($search_startDt)) $search_startDt = $this->convertToProperDate($search_startDt);
143 $search_endDt = $request->trimValueOf('search_end'); // 検索範囲終了日付
144 if (!empty($search_endDt)) $search_endDt = $this->convertToProperDate($search_endDt);
145 $keyword = $request->trimValueOf('search_keyword'); // 検索キーワード
147 if ($act == 'delete'){ // 項目削除の場合
148 $listedItem = explode(',', $request->trimValueOf('seriallist'));
150 for ($i = 0; $i < count($listedItem); $i++){
152 $itemName = 'item' . $i . '_selected';
153 $itemValue = ($request->trimValueOf($itemName) == 'on') ? 1 : 0;
155 if ($itemValue){ // チェック項目
156 $delItems[] = $listedItem[$i];
159 if (count($delItems) > 0){
160 $ret = self::$_mainDb->delCommentItem($delItems);
161 if ($ret){ // データ削除成功のとき
162 $this->setGuidanceMsg('データを削除しました');
164 $this->setAppErrorMsg('データ削除に失敗しました');
167 } else if ($act == 'search'){ // 検索のとき
168 if (!empty($search_startDt) && !empty($search_endDt) && $search_startDt > $search_endDt){
169 $this->setUserErrorMsg('期間の指定範囲にエラーがあります。');
171 $pageNo = 1; // ページ番号初期化
172 } else if ($act == 'selcontenttype'){ // コンテンツタイプ変更のとき
174 // $this->contentType = $this->getDefaultContentType(); // コンテンツタイプ
178 $this->createContentTypeMenu();
180 // ###### 一覧の取得条件を作成 ######
181 if (!empty($search_endDt)) $endDt = $this->getNextDay($search_endDt);
182 $parsedKeywords = $this->gInstance->getTextConvManager()->parseSearchKeyword($keyword);
185 $totalCount = self::$_mainDb->getCommentItemCount($this->_contentType, $this->langId, $search_startDt, $endDt, $parsedKeywords);
188 $pageCount = (int)(($totalCount -1) / $maxListCount) + 1; // 総ページ数
189 if ($pageNo < 1) $pageNo = 1;
190 if ($pageNo > $pageCount) $pageNo = $pageCount;
191 $this->firstNo = ($pageNo -1) * $maxListCount + 1; // 先頭番号
195 if ($pageCount > 1){ // ページが2ページ以上のときリンクを作成
196 for ($i = 1; $i <= $pageCount; $i++){
198 $link = ' ' . $i;
200 $link = ' <a href="#" onclick="selpage(\'' . $i . '\');return false;">' . $i . '</a>';
207 self::$_mainDb->searchCommentItems($this->_contentType, $this->langId, $maxListCount, $pageNo, $search_startDt, $endDt, $parsedKeywords, array($this, 'itemListLoop'));
208 if (count($this->serialArray) <= 0) $this->tmpl->setAttribute('itemlist', 'visibility', 'hidden');// コメントがないときは、一覧を表示しない
211 $searchImg = $this->getUrl($this->gEnv->getRootUrl() . self::SEARCH_ICON_FILE);
213 $this->tmpl->addVar("_widget", "search_img", $searchImg);
214 $this->tmpl->addVar("_widget", "search_str", $searchStr);
217 $this->tmpl->addVar("_widget", "page_link", $pageLink);
218 $this->tmpl->addVar("_widget", "total_count", $totalCount);
221 $this->tmpl->addVar("_widget", "search_start", $search_startDt); // 開始日付
222 $this->tmpl->addVar("_widget", "search_end", $search_endDt); // 終了日付
223 $this->tmpl->addVar("_widget", "search_keyword", $keyword); // 検索キーワード
226 $this->tmpl->addVar("_widget", "serial_list", implode($this->serialArray, ','));// 表示項目のシリアル番号を設定
227 $this->tmpl->addVar("_widget", "page", $pageNo); // ページ番号
228 $this->tmpl->addVar("_widget", "list_count", $maxListCount); // 一覧表示項目数
229 // $this->tmpl->addVar('_widget', 'config_admin_url', $this->getUrl($this->getConfigAdminUrl()));// コメント管理画面URL
230 $this->tmpl->addVar('_widget', 'config_admin_url', $this->getUrl($this->_baseUrl));
235 * @param RequestManager $request HTTPリクエスト処理クラス
238 function createDetail($request)
240 $act = $request->trimValueOf('act');
241 $this->serialNo = $request->trimValueOf('serial'); // 選択項目のシリアル番号
242 if (empty($this->serialNo)) $this->serialNo = 0;
243 // $name = $request->trimValueOf('item_name');
244 // $html = $request->valueOf('item_html');
245 // $url = $request->valueOf('item_url');
246 // $email = $request->valueOf('item_email');
247 // $reg_user = $request->valueOf('item_reg_user');
248 $this->status = $request->trimValueOf('item_status'); // エントリー状態(0=未設定、1=編集中、2=公開、3=非公開)
249 // $this->contentType = $request->trimValueOf('content_type'); // 選択中のコンテンツタイプ
252 $ret = self::$_mainDb->getConfig($this->_contentType, ''/*全体の定義*/, $row);
254 $this->permitHtml = $row[commentCommonDef::FD_PERMIT_HTML]; // HTMLあり
256 $this->permitHtml = 0; // HTMLあり
259 $reloadData = false; // データの再ロード
260 if ($act == 'update'){ // 項目更新の場合
262 if ($this->getMsgCount() == 0){
263 $fieldData = array('cm_status' => $this->status);
264 $ret = self::$_mainDb->updateCommentItem($this->serialNo, $fieldData);
267 $this->setGuidanceMsg('データを更新しました');
268 $reloadData = true; // データの再ロード
270 $this->setAppErrorMsg('データ更新に失敗しました');
273 } else if ($act == 'delete'){ // 項目削除の場合
274 if (empty($this->serialNo)){
275 $this->setUserErrorMsg('削除項目が選択されていません');
278 if ($this->getMsgCount() == 0){
279 $ret = self::$_mainDb->delCommentItem(array($this->serialNo));
280 if ($ret){ // データ削除成功のとき
281 $this->setGuidanceMsg('データを削除しました');
283 $this->setAppErrorMsg('データ削除に失敗しました');
286 } else if ($act == 'deleteid'){ // ID項目削除の場合
287 } else { // 初期画面表示のとき
288 $reloadData = true; // データの再ロード
292 if ($reloadData){ // データの再ロード
293 $ret = self::$_mainDb->getCommentItem($this->serialNo, $row);
295 $contentsId = $row['cm_contents_id']; // 共通コンテンツID
296 $title = $row['cm_title']; // コメントタイトル
297 $this->status = $row['cm_status']; // コメント状態(0=未設定、1=非公開、2=公開)
299 if ($this->permitHtml){ // HTMLコメントの場合
300 $commentTag = str_replace(M3_TAG_START . M3_TAG_MACRO_ROOT_URL . M3_TAG_END, $this->currentPageRootUrl, $row['cm_message']);// アプリケーションルートを変換
302 $commentTag = $this->convertToPreviewText($this->convertToDispString($row['cm_message']));// 改行コードをbrタグに変換
304 $email = $row['cm_email']; // Eメール
305 if (!empty($row['lu_email'])) $email = $row['lu_email'];
306 $url = $row['cm_url']; // URL
307 $author = $row['cm_author']; // 投稿者
308 if (!empty($row['author'])) $author = $row['author'];
309 $reg_dt = $row['cm_create_dt']; // 投稿日時
310 $update_user = $row['update_user_name']; // 更新者
311 $update_dt = $row['cm_update_dt']; // 更新日時
314 $contentTitle = $this->getContentTitle($this->_contentType, $contentsId);
318 $this->createStatusMenu();
321 $this->tmpl->addVar("_widget", "serial", $this->serialNo); // シリアル番号
323 // 入力フィールドの設定、共通項目のデータ設定
324 /* if ($this->entryId == 0){ // 記事IDが0のときは、新規追加モードにする
325 $this->tmpl->addVar('_widget', 'id', '新規');
327 $this->tmpl->setAttribute('add_button', 'visibility', 'visible');
329 $this->tmpl->addVar('_widget', 'id', $this->entryId);
331 if ($this->serialNo == 0){ // 未登録データのとき
333 $this->tmpl->setAttribute('add_button', 'visibility', 'visible');
336 $this->tmpl->setAttribute('delete_button', 'visibility', 'visible');
337 $this->tmpl->setAttribute('update_button', 'visibility', 'visible');
341 $this->tmpl->addVar("_widget", "content_title", $this->convertToDispString($contentTitle)); // コンテンツタイトル
342 $this->tmpl->addVar("_widget", "title", $this->convertToDispString($title)); // コメントタイトル
343 $this->tmpl->addVar("_widget", "comment", $commentTag); // コメント内容
344 $this->tmpl->addVar("_widget", "email", $this->convertToDispString($email)); // Eメール
345 $this->tmpl->addVar("_widget", "url", $this->convertToDispString($url)); // URL
346 $this->tmpl->addVar("_widget", "author", $this->convertToDispString($author)); // 投稿者
347 $this->tmpl->addVar("_widget", "date", $this->convertToDispDateTime($reg_dt)); // 投稿日時
348 $this->tmpl->addVar("_widget", "update_user", $this->convertToDispString($update_user)); // 更新者
349 $this->tmpl->addVar("_widget", "update_dt", $this->convertToDispDateTime($update_dt)); // 更新日時
350 //$this->tmpl->addVar('_widget', 'config_admin_url', $this->getUrl($this->getConfigAdminUrl()));// コメント管理画面URL
351 $this->tmpl->addVar('_widget', 'config_admin_url', $this->getUrl($this->_baseUrl));
354 * 取得したデータをテンプレートに設定する
356 * @param int $index 行番号(0~)
357 * @param array $fetchedRow フェッチ取得した行
358 * @param object $param 未使用
359 * @return bool true=処理続行の場合、false=処理終了の場合
361 function itemListLoop($index, $fetchedRow, $param)
364 $serial = $fetchedRow['cm_serial'];
366 $contentsId = $fetchedRow['cm_contents_id']; // 共通コンテンツID
367 $contentType = $fetchedRow['cm_content_type']; // コンテンツタイプ
370 switch ($fetchedRow['cm_status']){
371 case 0: $status = '<font color="red">未承認</font>';
373 case 1: $status = '<font color="orange">非公開</font>';
375 case 2: $status = '<font color="green">公開</font>';
379 $title = $this->getContentTitle($contentType, $contentsId);
381 $userName = $fetchedRow['lu_name'];
382 if (empty($userName)) $userName = $fetchedRow['cm_author'];
385 $comment = strip_tags($fetchedRow['cm_message']); // タグを削除
386 if (function_exists('mb_strimwidth')){
387 $comment = mb_strimwidth($comment, 0, self::COMMENT_SIZE, '…');
389 $comment = substr($comment, 0, self::COMMENT_SIZE) . '...';
392 // $previewUrl = $this->gEnv->getDefaultUrl() . '?' . M3_REQUEST_PARAM_CONTENT_ID . '=' . $contentId;
393 $previewUrl = commentCommonDef::createCommentUrl($contentType, $contentsId, $fetchedRow['cm_no']);
394 $previewImg = $this->getUrl($this->gEnv->getRootUrl() . self::PREVIEW_ICON_FILE);
395 $previewStr = 'プレビュー';
398 'index' => $index, // 項目番号
399 'serial' => $serial, // シリアル番号
400 'content_title' => $this->convertToDispString($title), // コンテンツタイトル
401 'no' => $this->convertToDispString($fetchedRow['cm_no']), // コメント番号
402 'name' => $this->convertToDispString($fetchedRow['cm_title']), // コメントタイトル
403 'content' => $this->convertToDispString($comment), // コメント内容
404 'status' => $status, // 公開状況
405 'author' => $this->convertToDispString($userName), // 投稿者
406 'date' => $this->convertToDispDateTime($fetchedRow['cm_create_dt']), // 投稿日時
407 'preview_url' => $previewUrl, // プレビュー用のURL
408 'preview_img' => $previewImg, // プレビュー用の画像
409 'preview_str' => $previewStr // プレビュー文字列
411 $this->tmpl->addVars('itemlist', $row);
412 $this->tmpl->parseTemplate('itemlist', 'a');
415 $this->serialArray[] = $serial;
423 function createContentTypeMenu()
425 for ($i = 0; $i < count($this->contentTypeArray); $i++){
426 $name = $this->contentTypeArray[$i]['name'];
427 $value = $this->contentTypeArray[$i]['value'];
430 'name' => $name, // 名前
431 'value' => $value, // 値
432 'selected' => $this->convertToSelectedString($value, $this->_contentType) // 選択中の項目かどうか
434 $this->tmpl->addVars('content_type_list', $row);
435 $this->tmpl->parseTemplate('content_type_list', 'a');
441 * @param string $contentType コンテンツタイプ
442 * @param string $contentsId 共通コンテンツID
445 function getContentTitle($contentType, $contentsId)
447 $contentName = self::UNTITLED_CONTENT;
449 switch ($contentType){
450 case M3_VIEW_TYPE_CONTENT: // 汎用コンテンツ
451 $ret = self::$_mainDb->getContentById(''/*PC用コンテンツ*/, $this->_langId, $contentsId, $row);
452 if ($ret) $contentName = $row['cn_name'];
454 case M3_VIEW_TYPE_PRODUCT: // 商品情報(Eコマース)
455 $ret = self::$_mainDb->getProductById($contentsId, $this->_langId, $row);
456 if ($ret) $contentName = $row['pt_name'];
458 case M3_VIEW_TYPE_BBS: // BBS
461 case M3_VIEW_TYPE_BLOG: // ブログ
462 $ret = self::$_mainDb->getEntryById($contentsId, $this->_langId, $row);
463 if ($ret) $contentName = $row['be_name'];
465 case M3_VIEW_TYPE_WIKI: // wiki
466 $contentName = $contentsId;
468 case M3_VIEW_TYPE_USER: // ユーザ作成コンテンツ
469 $ret = self::$_mainDb->getRoomById($contentsId, $this->_langId, $row);
470 if ($ret) $contentName = $row['ur_name'];
472 case M3_VIEW_TYPE_EVENT: // イベント情報
473 $ret = self::$_mainDb->getEventById($contentsId, $this->_langId, $row);
474 if ($ret) $contentName = $row['ee_name'];
476 case M3_VIEW_TYPE_PHOTO: // フォトギャラリー
477 $ret = self::$_mainDb->getPhotoById($contentsId, $this->_langId, $row);
478 if ($ret) $contentName = $row['ht_name'];
488 function createStatusMenu()
490 for ($i = 0; $i < count($this->statusTypeArray); $i++){
491 $value = $this->statusTypeArray[$i]['value'];
492 $name = $this->statusTypeArray[$i]['name'];
494 if ($this->status == $value) $selected = 'selected';
497 'value' => $value, // タイプ値
498 'name' => $this->convertToDispString($name), // タイプ名
499 'selected' => $selected // 選択中かどうか
501 $this->tmpl->addVars('status_list', $row);
502 $this->tmpl->parseTemplate('status_list', 'a');