7 * LICENSE: This source file is licensed under the terms of the GNU General Public License.
10 * @author 株式会社 毎日メディアサービス
11 * @copyright Copyright 2010 株式会社 毎日メディアサービス.
12 * @license http://www.gnu.org/copyleft/gpl.html GPL License
13 * @version SVN: $Id: chacha_mainBaseWidgetContainer.php 3352 2010-07-08 02:59:39Z fishbone $
14 * @link http://www.m-media.co.jp
16 require_once($gEnvManager->getContainerPath() . '/baseWidgetContainer.php');
17 require_once($gEnvManager->getCurrentWidgetDbPath() . '/chacha_mainDb.php');
19 class chacha_mainBaseWidgetContainer extends BaseWidgetContainer
21 protected $_db; // DB接続オブジェクト
22 protected $_configArray; // BBS定義値
23 protected $_headCss; // CSS定義
24 protected $_boardId; // 掲示板ID
25 protected $_currentPageUrl; // 現在のページのURL
26 protected $_autolink; // リンクを自動作成
27 const CREATE_CODE_RETRY_COUNT = 10; // コード生成のリトライ数
28 const DEFAULT_BBS_ID_HEAD = 'board'; // デフォルトの掲示板ID
29 const DEFAULT_LAST_MESSAGE_COUNT = 50; // メッセージ取得用デフォルトの最新メッセージ数
30 const DEFAULT_MESSAGE_COUNT_PER_PAGE = 100; // メッセージ取得用デフォルトの1ページあたりメッセージ数
31 const AVATAR_DIR = '/widgets/chacha/avatar'; // アバター格納ディレクトリ
32 const AVATAR32_DIR = '/widgets/chacha/avatar32'; // アバター(小)格納ディレクトリ
33 const DEFAULT_AVATAR_ICON_FILE = '/images/default_avatar.gif'; // デフォルトのアバターアイコン
34 const DEFAULT_AVATAR_FILE_EXT = 'gif'; // アバターファイルのデフォルト拡張子
35 const DEFAULT_SMALL_AVATAR_FILE_EXT = 'gif'; // アバター(小)ファイルのデフォルト拡張子
36 const AVATAR_TAG_ID = 'chacha_avatar_image'; // アバタータグID
37 const AVATAR_SIZE = 64; // アバター画像のサイズ
38 const SMALL_AVATAR_SIZE = 32; // アバター画像(小)のサイズ
39 const TOP_MESSAGE_LENGTH = 100; // トップページのメッセージ長
41 const CF_BBS_TITLE = 'title'; // 掲示板タイトル
42 const CF_TITLE_COLOR = 'title_color'; // タイトルカラー
43 const CF_TOP_LINK = 'top_link'; // トップ画像のリンク先
44 const CF_TOP_IMAGE = 'top_image'; // トップ画像
45 const CF_BBS_GUIDE = 'bbs_guide'; // 掲示板規則
46 const CF_BG_IMAGE = 'bg_image'; // 背景画像
48 const CF_BG_COLOR = 'bg_color'; // 背景色
49 const CF_INNER_BG_COLOR = 'inner_bg_color'; // 内枠のデフォルト背景色
50 const CF_PROFILE_COLOR = 'profile_color'; // プロフィール背景色
52 const CF_MENU_COLOR = 'menu_color'; // メニュー背景色
53 const CF_MAKE_THREAD_COLOR = 'makethread_color'; // スレッド作成部背景色
54 const CF_THREAD_COLOR = 'thread_color'; // スレッド表示部背景色
55 const CF_TEXT_COLOR = 'text_color'; // 文字色
57 const CF_SUBJECT_LENGTH = 'subject_length'; // 件名最大長
58 const CF_NAME_LENGTH = 'name_length'; // 投稿者名最大長
59 const CF_EMAIL_LENGTH = 'email_length'; // emailアドレス最大長
60 const CF_MESSAGE_LENGTH = 'message_length'; // 最大メッセージ長
61 const CF_ERR_MESSAGE_COLOR = 'err_message_color'; // エラーメッセージ文字色
62 const CF_LINE_LENGTH = 'line_length'; // 投稿文行長
63 const CF_LINE_COUNT = 'line_count'; // 投稿文行数
64 const CF_RES_ANCHOR_LINK_COUNT = 'res_anchor_link_count'; // レスアンカーリンク数
65 const CF_THREAD_COUNT = 'thread_count'; // トップ画面に表示するスレッド最大数
66 const CF_RES_COUNT = 'res_count'; // トップ画面に表示するレス最大数
67 const CF_THREAD_RES = 'thread_res'; // 1スレッドに投稿できるレス数の上限
68 const CF_MENU_THREAD_COUNT = 'menu_thread_count'; // メニューに表示するスレッド最大数
69 const CF_SHOW_EMAIL = 'show_email'; // Eメールアドレスを表示
70 const CF_AUTOLINK = 'autolink'; // 自動的にリンクを作成
71 const CF_NONAME_NAME = 'noname_name'; // 名前未設定時の表示名
72 const CF_MESSAGE_COUNT_TOP = 'message_count_top'; // トップページのメッセージ表示項目数
73 const CF_MESSAGE_COUNT_MYPAGE = 'message_count_mypage'; // マイページのメッセージ表示項目数
74 const CF_TOP_CONTENTS = 'top_contents'; // トップコンテンツ
76 const TASK_TOP = 'top'; // トップ画面
77 const TASK_SUBJECT = 'subject'; // スレッド件名
78 const TASK_THREAD = 'thread'; // スレッド処理
79 const TASK_NEW_THREAD = 'newthread'; // スレッド新規作成
80 const TASK_READ = 'read'; // スレッド表示
81 const TASK_PROFILE = 'profile'; // プロフィール表示
82 const TASK_MYPAGE = 'mypage'; // マイページ表示
84 const URL_PARAM_MEMBER_ID = 'memberid'; // 会員ID
85 const URL_PARAM_MESSAGE_ID = 'messageid'; // メッセージID
88 const CSS_BLOG_STYLE = 'width:100%;text-align:left;padding:10px 0 10px 0;'; // ベースのスタイル
89 const CSS_BLOG_TOP_STYLE = 'width:95%;text-align:left;padding:0 0 5px 0;'; // トップコンテンツ枠のスタイル
90 const CSS_BLOG_INNER_STYLE = 'width:95%;text-align:left;padding:5px 0 5px 0;'; // 内枠のスタイル
91 const CSS_LINK_STYLE_TOP = 'margin:0 10px;text-align:right;'; // 上のリンク部のスタイル
92 const CSS_LINK_STYLE_BOTTOM = 'margin:0 10px;'; // 下のリンク部のスタイル
93 const CSS_LINK_STYLE_INNER_BOTTOM = 'margin:0 10px;text-align:right;'; // 内枠の下のリンク部のスタイル
98 function __construct()
101 parent::__construct();
103 // サブウィジェット起動のときだけ初期処理実行
104 if ($this->gEnv->getIsSubWidget()){
106 $this->_db = new chacha_mainDb();
110 $configId = $this->gEnv->getCurrentWidgetConfigId();
111 $this->_boardId = self::DEFAULT_BBS_ID_HEAD . intval($configId);
114 $this->_loadConfig($this->_boardId);
116 $this->_currentPageUrl = $this->gEnv->createCurrentPageUrl(); // 現在のページのURL
117 $this->_autolink = $this->_configArray[self::CF_AUTOLINK]; // リンクを自動作成
123 * _setTemplate()で指定したテンプレートファイルにデータを埋め込む。
125 * @param RequestManager $request HTTPリクエスト処理クラス
126 * @param object $param 任意使用パラメータ。_setTemplate()と共有。
129 function _postAssign($request, &$param)
132 if ($param == 'ajax') return;
135 /* $titleColor = $this->_configArray[self::CF_TITLE_COLOR]; // タイトルカラー
136 $topImage = $this->_configArray[self::CF_TOP_IMAGE];
137 if (!empty($topImage)){
138 $topLink = $this->convertUrlToHtmlEntity($this->_configArray[self::CF_TOP_LINK]); // トップ画像のリンク先
139 $topImage = $this->gEnv->getCurrentWidgetImagesUrl() . '/' . $topImage;
140 $topImage = '<img src="' . $topImage . '" border="0" />';
141 if (!empty($topLink)) $topImage = '<a href="' . $topLink . '">' . $topImage . '</a>';
143 $this->tmpl->addVar("_widget", "top_image", $topImage); // トップ画像
146 $title = $this->_configArray[self::CF_BBS_TITLE]; // 掲示板タイトル
147 $this->tmpl->addVar("_widget", "bbs_title", $this->convertToDispString($title));
148 $this->tmpl->addVar("_widget", "guide", $this->_configArray[self::CF_BBS_GUIDE]);*/
151 $bbsStyle = self::CSS_BLOG_STYLE;
152 $bgImage = $this->gEnv->getCurrentWidgetImagesUrl() . '/' . $this->_configArray[self::CF_BG_IMAGE];
153 $bgColor = $this->_configArray[self::CF_BG_COLOR];
154 $textColor = $this->_configArray[self::CF_TEXT_COLOR]; // 文字色
155 // $bbsStyle .= 'background-image:url(' . $bgImage . ');';
156 $bbsStyle .= 'background-color:' . $bgColor . ';';
157 // $bbsStyle .= 'color:' . $textColor . ';';
158 $this->tmpl->addVar("_widget", "blog_style", $bbsStyle);
159 $this->tmpl->addVar("top_link_area", "link_style_top", self::CSS_LINK_STYLE_TOP);// 上下のリンク部のスタイル
160 $this->tmpl->addVar("_widget", "link_style_bottom", self::CSS_LINK_STYLE_BOTTOM);// 下のリンク部のスタイル
161 $this->tmpl->addVar("_widget", "link_style_inner_bottom", self::CSS_LINK_STYLE_INNER_BOTTOM);// 内枠下のリンク部のスタイル
163 $menuColor = $this->_configArray[self::CF_MENU_COLOR]; // メニュー背景色
164 $menuStyle .= 'background-color:' . $menuColor . ';';
165 $this->tmpl->addVar("_widget", "menu_style", $menuStyle);
168 if ($this->getMsgCount(1) > 0 || $this->getMsgCount(2) > 0){ // エラーメッセージが出力されているとき
169 $errMessageColor = $this->_configArray[self::CF_ERR_MESSAGE_COLOR]; // エラーメッセージ色
170 if (!empty($errMessageColor)){
171 $errMessageStyle .= 'color:' . $errMessageColor . ';';
172 $attr = 'style="' . $errMessageStyle . '"';
173 $this->setMessageAttr($attr);
178 $cssId = $this->gEnv->getCurrentWidgetId() . '_0';
179 $this->tmpl->addVar("_widget", "css_id", $cssId); // CSS用ID
182 $this->tmpl->addVar("_widget", "home_url", $this->convertUrlToHtmlEntity($this->getUrl($this->gEnv->createCurrentPageUrl(), true)));
183 // $this->tmpl->addVar("_widget", "subject_url", $this->convertUrlToHtmlEntity($this->getUrl($this->gEnv->createCurrentPageUrl() . '&task=' . self::TASK_SUBJECT, true))); // スレッド件名
184 // $this->tmpl->addVar("_widget", "newthread_url", $this->convertUrlToHtmlEntity($this->getUrl($this->gEnv->createCurrentPageUrl() . '&task=' . self::TASK_NEW_THREAD, true))); // 新規スレッド作成
189 * CSSデータをHTMLのheadタグ内に追加出力する。
190 * _assign()よりも後に実行される。
192 * @param RequestManager $request HTTPリクエスト処理クラス
193 * @param object $param 任意使用パラメータ。
194 * @return string CSS文字列。出力しない場合は空文字列を設定。
196 function _addCssToHead($request, &$param)
198 return $this->_headCss;
203 * @param string $boardId 掲示板ID
204 * @return bool true=取得成功、false=取得失敗
206 function _loadConfig($boardId)
208 $this->_configArray = array();
211 $ret = $this->_db->getAllConfig($rows, $boardId);
214 $configCount = count($rows);
215 for ($i = 0; $i < $configCount; $i++){
216 $key = $rows[$i]['mc_id'];
217 $value = $rows[$i]['mc_value'];
218 $this->_configArray[$key] = $value;
226 * @param string $boardId 掲示板ID
227 * @param string $threadId スレッドID
228 * @param string $name ユーザ名
229 * @param string $email Eメールアドレス
230 * @param string $message 投稿文
231 * @return bool true=正常終了、false=異常終了
233 function checkMessageInput($boardId, $threadId, $name, $email, $message)
236 $this->checkInput($threadId, 'スレッドID');
237 $this->checkInput($message, 'メッセージ');
239 if ($this->getMsgCount() == 0){
241 $ret = $this->_db->getThreadInfo($boardId, $threadId, $row);
244 $resCount = $this->_configArray[self::CF_THREAD_RES];
245 if ($row['th_message_count'] > $resCount){
246 $this->setUserErrorMsg('このスレッドは' . $resCount . 'を超えました。<br /> もう書けないので、新しいスレッドを立ててくださいです。。。');
249 $this->setUserErrorMsg('ERROR:スレッドIDが不正です!');
253 if (strlen($message) > $this->_configArray[self::CF_MESSAGE_LENGTH]){
254 $this->setUserErrorMsg('ERROR:本文が長すぎます!');
258 if (strlen($name) > $this->_configArray[self::CF_NAME_LENGTH]) $this->setUserErrorMsg('ERROR:名前が長すぎます!');
261 if (strlen($email) > $this->_configArray[self::CF_EMAIL_LENGTH]) $this->setUserErrorMsg('ERROR:メールアドレスが長すぎます!');
263 if ($this->getMsgCount() == 0){
272 * @param string $memberId 会員ID
275 function getAvatarUrl($memberId)
277 $avatarImagePath = $this->gEnv->getResourcePath() . self::AVATAR_DIR . '/' . $memberId . '.' . self::DEFAULT_AVATAR_FILE_EXT;
278 if (file_exists($avatarImagePath)){ // アバターファイルが見つからないときはデフォルトを使用
279 $avatarImageUrl = $this->gEnv->getResourceUrl() . self::AVATAR_DIR . '/' . $memberId . '.' . self::DEFAULT_AVATAR_FILE_EXT;
281 $avatarImageUrl = $this->gEnv->getCurrentWidgetRootUrl() . self::DEFAULT_AVATAR_ICON_FILE;
283 return $avatarImageUrl;
288 * @param string $message 変換元メッセージ
289 * @param string $threadId スレッドID
290 * @return string 変換後メッセージ
292 function convDispMessage($message, $threadId)
295 if (!empty($this->_autolink)){ // 自動リンク作成のとき
296 $message = preg_replace("/(https?):\/\/([\w;\/\?:\@&=\+\$,\-\.!~\*'\(\)%#]+)/", "<a href=\"$1://$2\" target=\"_blank\">$1://$2</a>", $message);
299 // $baseUrl = $this->convertUrlToHtmlEntity($this->getUrl($this->_currentPageUrl . '&' . M3_REQUEST_PARAM_BBS_THREAD_ID . '=' . $threadId, true));
300 $messageUrl = $baseUrl . $this->convertUrlToHtmlEntity('&' . M3_REQUEST_PARAM_ITEM_NO . '=');
301 $messageListUrl = $baseUrl . $this->convertUrlToHtmlEntity('&' . M3_REQUEST_PARAM_LIST_NO . '=');
302 $message = preg_replace("/>>([0-9]+)(?![-\d])/", '<a href="' . $messageUrl . '$1" target="_blank">>>$1</a>', $message);
303 $message = preg_replace("/>>([0-9]+)\-([0-9]+)/", '<a href="' . $messageListUrl . '$1-$2" target="_blank">>>$1-$2</a>', $message);
310 * @param string $baseChars 使用する文字
311 * @param int $length 作成する文字列の長さ
312 * @return string ランダム文字列。作成できなかった場合は空文字列。
314 function _createRandString($baseChars, $length)
319 if (!(is_numeric($length) && $length > 0)) return $destStr;
321 for ($i = 0; $i < $length; $i++){
322 $pos = rand(0, strlen($baseChars) -1);
323 $destStr .= $baseChars[$pos];
328 * テキストデータを表示用のテキストに変換
330 * 変換内容 ・改行コードをスペース「 」に変換
332 * @param string $src 変換するデータ
333 * @return string 変換後データ
335 function _convertToPreviewTextWithSpace($src)
337 return preg_replace("/(\015\012)|(\015)|(\012)/", " ", $src);