OSDN Git Service

初回コミット(v2.6.17.1)
[magic3/magic3.git] / widgets / s / bbs_2ch / include / container / s_bbs_2chThreadWidgetContainer.php
1 <?php
2 /**
3  * index.php用コンテナクラス
4  *
5  * PHP versions 5
6  *
7  * LICENSE: This source file is licensed under the terms of the GNU General Public License.
8  *
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
15  */
16 require_once($gEnvManager->getCurrentWidgetContainerPath() .    '/s_bbs_2chBaseWidgetContainer.php');
17
18 class s_bbs_2chThreadWidgetContainer extends s_bbs_2chBaseWidgetContainer
19 {
20         /**
21          * コンストラクタ
22          */
23         function __construct()
24         {
25                 // 親クラスを呼び出す
26                 parent::__construct();
27         }
28         /**
29          * テンプレートファイルを設定
30          *
31          * _assign()でデータを埋め込むテンプレートファイルのファイル名を返す。
32          * 読み込むディレクトリは、「自ウィジェットディレクトリ/include/template」に固定。
33          *
34          * @param RequestManager $request               HTTPリクエスト処理クラス
35          * @param object         $param                 任意使用パラメータ。そのまま_assign()に渡る
36          * @return string                                               テンプレートファイル名。テンプレートライブラリを使用しない場合は空文字列「''」を返す。
37          */
38         function _setTemplate($request, &$param)
39         {
40                 $task = $request->trimValueOf('task');
41                 if ($task == self::TASK_NEW_THREAD){            // 新規スレッド作成画面
42                         return 'newthread.tmpl.html';
43                 } else {                        // スレッド一覧画面
44                         return 'thread.tmpl.html';
45                 }
46         }
47         /**
48          * テンプレートにデータ埋め込む
49          *
50          * _setTemplate()で指定したテンプレートファイルにデータを埋め込む。
51          *
52          * @param RequestManager $request               HTTPリクエスト処理クラス
53          * @param object         $param                 任意使用パラメータ。_setTemplate()と共有。
54          * @param                                                               なし
55          */
56         function _assign($request, &$param)
57         {
58                 $task = $request->trimValueOf('task');
59                 if ($task == self::TASK_NEW_THREAD){            // 新規スレッド作成画面
60                         return $this->createNewThread($request);
61                 } else {                        // スレッド一覧画面
62                         return $this->createThreadList($request);
63                 }
64         }
65         /**
66          * 新規スレッド投稿画面作成
67          *
68          * @param RequestManager $request               HTTPリクエスト処理クラス
69          * @param                                                               なし
70          */
71         function createNewThread($request)
72         {
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メールアドレス
79                 
80                 if ($act == 'add'){             // 新規追加のとき
81                         if (!empty($postTicket) && $postTicket == $request->getSessionValue(M3_SESSION_POST_TICKET)){           // 正常なPOST値のとき
82                                 // 入力チェック
83                                 $this->checkInput($subject, 'タイトル', 'ERROR:タイトルが存在しません!');
84                                 if (function_exists('mb_strlen')){
85                                         $length = mb_strlen($subject);
86                                 } else {
87                                         $length = strlen($subject);
88                                 }
89                                 if ($length > $this->_configArray[self::CF_SUBJECT_LENGTH]) $this->setUserErrorMsg('ERROR:タイトルが長すぎます!(最大文字数' . $this->_configArray[self::CF_SUBJECT_LENGTH] . ')');
90                         
91                                 // その他の入力項目のエラーチェック
92                                 $this->checkMessageInput($this->_boardId, -1/*スレッドIDチェックなし*/, $name, $email, $message);
93                         
94                                 // エラーなしの場合は、データを更新
95                                 if ($this->getMsgCount() == 0){
96                                         // スレッドID作成
97                                         $threadId = md5(time() . $this->gRequest->trimServerValueOf('REMOTE_ADDR'));
98                                 
99                                         // 新規スレッドの追加
100                                         $ret = $this->_db->addNewThread($this->_boardId, $threadId, $subject, $name, $email, $message);
101
102                                         if ($ret){              // データ追加成功のとき
103                                                 //$this->setMsg(self::MSG_GUIDANCE, 'スレッドを作成しました');
104                                                 $this->setMsg(self::MSG_GUIDANCE, '書きこみが終わりました。');
105                                                 $replaceNew = true;                     // データを再取得
106                                         
107                                                 // 入力項目を使用不可に設定
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 ');
113                                         } else {
114                                                 //$this->setMsg(self::MSG_APP_ERR, 'スレッドを作成に失敗しました');
115                                                 $this->setMsg(self::MSG_APP_ERR, '書きこみに失敗しました。');
116                                         }
117                                 }
118                         } else {
119                                 $this->setMsg(self::MSG_APP_ERR, '不正な投稿により、書きこみに失敗しました。');
120                         }
121                         $request->unsetSessionValue(M3_SESSION_POST_TICKET);            // セッション値をクリア
122                 }
123
124                 // 入力データを再設定
125                 $this->tmpl->addVar("_widget", "subject", $this->convertToDispString($subject));
126                 $this->tmpl->addVar("_widget", "message", $this->convertToDispString($message));
127                 
128                 $makeThreadColor = $this->_configArray[self::CF_MAKE_THREAD_COLOR];             // スレッド作成部背景色
129                 $makeThreadStyle .= 'background-color:' . $makeThreadColor . ';';
130                 $this->tmpl->addVar("_widget", "make_thread_style", $makeThreadStyle);
131                 
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');// ファイルアップロード領域追加
136                 }
137                 $this->tmpl->addVar("_widget", "enctype", $enctype);
138                 
139                 // ハッシュキー作成
140                 $postTicket = md5(time() . $this->gAccess->getAccessLogSerialNo());
141                 $request->setSessionValue(M3_SESSION_POST_TICKET, $postTicket);         // セッションに保存
142                 $this->tmpl->addVar("_widget", "ticket", $postTicket);                          // 画面に書き出し
143         }
144         /**
145          * 取得したコンテンツ項目をテンプレートに設定する
146          *
147          * @param int           $index                  行番号
148          * @param array         $fetchedRow             取得行
149          * @param object        $param                  任意使用パラメータ
150          * @return bool                                         trueを返すとループ続行。falseを返すとその時点で終了。
151          */
152         function itemsLoop($index, $fetchedRow)
153         {
154                 return true;
155         }
156 }
157 ?>