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: s_bbs_2chThreadWidgetContainer.php 4851 2012-04-15 00:43:29Z fishbone $
14 * @link http://www.magic3.org
16 require_once($gEnvManager->getCurrentWidgetContainerPath() . '/s_bbs_2chBaseWidgetContainer.php');
18 class s_bbs_2chThreadWidgetContainer extends s_bbs_2chBaseWidgetContainer
23 function __construct()
26 parent::__construct();
31 * _assign()でデータを埋め込むテンプレートファイルのファイル名を返す。
32 * 読み込むディレクトリは、「自ウィジェットディレクトリ/include/template」に固定。
34 * @param RequestManager $request HTTPリクエスト処理クラス
35 * @param object $param 任意使用パラメータ。そのまま_assign()に渡る
36 * @return string テンプレートファイル名。テンプレートライブラリを使用しない場合は空文字列「''」を返す。
38 function _setTemplate($request, &$param)
40 $task = $request->trimValueOf('task');
41 if ($task == self::TASK_NEW_THREAD){ // 新規スレッド作成画面
42 return 'newthread.tmpl.html';
44 return 'thread.tmpl.html';
50 * _setTemplate()で指定したテンプレートファイルにデータを埋め込む。
52 * @param RequestManager $request HTTPリクエスト処理クラス
53 * @param object $param 任意使用パラメータ。_setTemplate()と共有。
56 function _assign($request, &$param)
58 $task = $request->trimValueOf('task');
59 if ($task == self::TASK_NEW_THREAD){ // 新規スレッド作成画面
60 return $this->createNewThread($request);
62 return $this->createThreadList($request);
68 * @param RequestManager $request HTTPリクエスト処理クラス
71 function createNewThread($request)
73 $act = $request->trimValueOf('act');
74 $postTicket = $request->trimValueOf('ticket'); // POST確認用
75 $subject = $request->trimValueOf('bbs_subject');// 投稿件名
76 $message = $request->valueOf('bbs_message');// 投稿メッセージ
77 $name = $request->trimValueOf('bbs_name');// 名前
78 $email = $request->trimValueOf('bbs_email');// Eメールアドレス
80 if ($act == 'add'){ // 新規追加のとき
81 if (!empty($postTicket) && $postTicket == $request->getSessionValue(M3_SESSION_POST_TICKET)){ // 正常なPOST値のとき
83 $this->checkInput($subject, 'タイトル', 'ERROR:タイトルが存在しません!');
84 if (function_exists('mb_strlen')){
85 $length = mb_strlen($subject);
87 $length = strlen($subject);
89 if ($length > $this->_configArray[self::CF_SUBJECT_LENGTH]) $this->setUserErrorMsg('ERROR:タイトルが長すぎます!(最大文字数' . $this->_configArray[self::CF_SUBJECT_LENGTH] . ')');
92 $this->checkMessageInput($this->_boardId, -1/*スレッドIDチェックなし*/, $name, $email, $message);
95 if ($this->getMsgCount() == 0){
97 $threadId = md5(time() . $this->gRequest->trimServerValueOf('REMOTE_ADDR'));
100 $ret = $this->_db->addNewThread($this->_boardId, $threadId, $subject, $name, $email, $message);
102 if ($ret){ // データ追加成功のとき
103 //$this->setMsg(self::MSG_GUIDANCE, 'スレッドを作成しました');
104 $this->setMsg(self::MSG_GUIDANCE, '書きこみが終わりました。');
105 $replaceNew = true; // データを再取得
108 $this->tmpl->addVar("_widget", "name_disabled", 'disabled ');
109 $this->tmpl->addVar("_widget", "email_disabled", 'disabled ');
110 $this->tmpl->addVar("_widget", "subject_disabled", 'disabled ');
111 $this->tmpl->addVar("_widget", "message_disabled", 'disabled ');
112 $this->tmpl->addVar("_widget", "button_disabled", 'disabled ');
114 //$this->setMsg(self::MSG_APP_ERR, 'スレッドを作成に失敗しました');
115 $this->setMsg(self::MSG_APP_ERR, '書きこみに失敗しました。');
119 $this->setMsg(self::MSG_APP_ERR, '不正な投稿により、書きこみに失敗しました。');
121 $request->unsetSessionValue(M3_SESSION_POST_TICKET); // セッション値をクリア
125 $this->tmpl->addVar("_widget", "subject", $this->convertToDispString($subject));
126 $this->tmpl->addVar("_widget", "message", $this->convertToDispString($message));
128 $makeThreadColor = $this->_configArray[self::CF_MAKE_THREAD_COLOR]; // スレッド作成部背景色
129 $makeThreadStyle .= 'background-color:' . $makeThreadColor . ';';
130 $this->tmpl->addVar("_widget", "make_thread_style", $makeThreadStyle);
132 $enctype = 'application/x-www-form-urlencoded';
133 if (!empty($this->_configArray[self::CF_FILE_UPLOAD])){ // ファイルアップロード許可のとき
134 $enctype = 'multipart/form-data';
135 $this->tmpl->setAttribute('file_upload', 'visibility', 'visible');// ファイルアップロード領域追加
137 $this->tmpl->addVar("_widget", "enctype", $enctype);
140 $postTicket = md5(time() . $this->gAccess->getAccessLogSerialNo());
141 $request->setSessionValue(M3_SESSION_POST_TICKET, $postTicket); // セッションに保存
142 $this->tmpl->addVar("_widget", "ticket", $postTicket); // 画面に書き出し
145 * 取得したコンテンツ項目をテンプレートに設定する
147 * @param int $index 行番号
148 * @param array $fetchedRow 取得行
149 * @param object $param 任意使用パラメータ
150 * @return bool trueを返すとループ続行。falseを返すとその時点で終了。
152 function itemsLoop($index, $fetchedRow)