OSDN Git Service

初回コミット(v2.6.17.1)
[magic3/magic3.git] / widgets / m / blog / include / container / m_blogBaseWidgetContainer.php
1 <?php
2 /**
3  * コンテナクラス
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-2010 Magic3 Project.
12  * @license    http://www.gnu.org/copyleft/gpl.html  GPL License
13  * @version    SVN: $Id: m_blogBaseWidgetContainer.php 3836 2010-11-17 06:05:07Z fishbone $
14  * @link       http://www.magic3.org
15  */
16 require_once($gEnvManager->getContainerPath() . '/baseMobileWidgetContainer.php');
17 require_once($gEnvManager->getCurrentWidgetDbPath() . '/blogDb.php');
18
19 class m_blogBaseWidgetContainer extends BaseMobileWidgetContainer
20 {
21         protected $_db;                 // DB接続オブジェクト
22         protected $_mobileId;           // 携帯ID
23         protected $_blogId;     // ブログID
24         protected $_spacer;             // スペーサ
25         protected $_currentPageUrl;// 現在のページのURL(携帯用のパラメータ付き)
26         // 表示設定
27         const ERR_MESSAGE_COLOR = '#ff0000';                    // エラーメッセージカラー
28         const SPACER_FORMAT = '<div style="background-color:#aaaaaa;margin:1px 0;height:1px;"><img src="%s/images/system/spacer.gif" width="1" height="1" /></div>';            // スペーサフォーマット
29         const LINK_PAGE_COUNT           = 5;                    // リンクページ数
30         const SEARCH_BODY_SIZE = 200;                   // 検索結果の記事本文の文字列最大長
31         
32         // 値定義
33         const CF_ENTRY_VIEW_COUNT               = 'm:entry_view_count';                 // 記事表示数
34         const CF_ENTRY_VIEW_ORDER               = 'm:entry_view_order';                 // 記事表示方向
35         const CF_SEARCH_COUNT           = 'm:search_count';             // 検索記事数
36         const CF_SEARCH_ORDER           = 'm:search_order';             // 検索記事表示方向
37         const CF_TITLE_COLOR                    = 'm:title_color';                      // タイトルの背景色
38         
39         // 画面
40         const DEFAULT_TASK = 'read';            // デフォルトの画面
41         const TASK_READ = 'read';               // スレッド表示
42         // URL用パラメータ
43 //      const URL_PARAM_MEMBER_ID = 'memberid';         // 会員ID
44 //      const URL_PARAM_MESSAGE_ID = 'messageid';               // メッセージID
45         // 共通のCSS
46         const CSS_LINK_STYLE_BOTTOM = 'text-align:center;';                                     // 下のリンク部のスタイル
47         const CSS_LINK_STYLE_INNER_BOTTOM = 'text-align:right;';        // 内枠の下のリンク部のスタイル
48         // 画面タイトル
49         const DEFAULT_TITLE_SEARCH = '検索';          // 検索時のデフォルトタイトル
50         // 表示メッセージ
51         const MESSAGE_NO_ENTRY_TITLE = 'ブログ記事未登録';
52         const MESSAGE_NO_ENTRY          = 'ブログ記事は登録されていません';                              // ブログ記事が登録されていないメッセージ
53         const MESSAGE_FIND_NO_ENTRY     = 'ブログ記事が見つかりません';
54         const MESSAGE_EXT_ENTRY         = '続きを読む';                                    // 投稿記事に続きがある場合の表示
55         const MESSAGE_EXT_ENTRY_PRE     = '…&nbsp;';                                                  // 投稿記事に続きがある場合の表示
56         const MESSAGE_SEARCH_KEYWORD = '検索キーワード:&nbsp;';                               // 検索キーワード用ラベル
57         // アクセス分析用
58         const CONTENT_TYPE = 'bg';              // 参照数カウント用
59                 
60         /**
61          * コンストラクタ
62          */
63         function __construct()
64         {
65                 // 親クラスを呼び出す
66                 parent::__construct();
67                                 
68                 // 端末IDを取得
69                 $this->_mobileId = $this->gEnv->getMobileId();
70                                         
71                 // サブウィジェット起動のときだけ初期処理実行
72                 if ($this->gEnv->getIsSubWidget()){
73                         // DBオブジェクト作成
74                         $this->_db = new blogDb();
75                 
76                         // 定義ID取得
77                         // 定義IDから掲示板IDを作成
78                         $configId = $this->gEnv->getCurrentWidgetConfigId();
79                         $this->_blogId = '';
80                 
81                         // BBS定義を読み込む
82                         $this->_loadConfig($this->_blogId);
83                 
84                         //$this->_currentPageUrl = $this->gEnv->createCurrentPageUrl(); // 現在のページのURL
85                         $this->_currentPageUrl = $this->gEnv->createCurrentPageUrlForMobile();// 現在のページのURL(携帯用のパラメータ付き)
86                         
87                         // スペーサ作成
88                         $this->_spacer = sprintf(self::SPACER_FORMAT, $this->getUrl($this->gEnv->getRootUrl()));
89                 }
90         }
91         /**
92          * テンプレートにデータ埋め込む
93          *
94          * _setTemplate()で指定したテンプレートファイルにデータを埋め込む。
95          *
96          * @param RequestManager $request               HTTPリクエスト処理クラス
97          * @param object         $param                 任意使用パラメータ。_setTemplate()と共有。
98          * @return                                                              なし
99          */
100         function _postAssign($request, &$param)
101         {
102                 // 共通のリンク設定
103                 $this->tmpl->addVar("_widget", "link_style_bottom", self::CSS_LINK_STYLE_BOTTOM);// 下のリンク部のスタイル
104                 $this->tmpl->addVar("_widget", "link_style_inner_bottom", self::CSS_LINK_STYLE_INNER_BOTTOM);// 内枠下のリンク部のスタイル
105                 $this->tmpl->addVar('_widget', 'top_url', $this->gEnv->createCurrentPageUrlForMobile(''));
106                 
107                 // メッセージカラーを設定
108                 if ($this->getMsgCount(1) > 0 || $this->getMsgCount(2) > 0){            // エラーメッセージが出力されているとき
109                         $errMessageColor = self::ERR_MESSAGE_COLOR;             // エラーメッセージ色
110                         $errMessageStyle = '';
111                         if (!empty($errMessageColor)) $errMessageStyle .= 'color:' . $errMessageColor . ';';
112                         $attr = 'style="' . $errMessageStyle . 'text-align:center;"';
113                         $this->setMessageAttr($attr);
114                 } else if ($this->getMsgCount(3) > 0){                  // ガイダンスメッセージが出力されているとき
115                         $attr = 'style="text-align:center;"';
116                         $this->setMessageAttr($attr);
117                 }
118         }
119         /**
120          * ブログ定義値をDBから取得
121          *
122          * @param string $blogId        ブログID
123          * @return bool                         true=取得成功、false=取得失敗
124          */
125         function _loadConfig($blogId)
126         {
127                 $this->_configArray = array();
128
129                 // BBS定義を読み込み
130                 $ret = $this->_db->getAllConfig($rows, $blogId);
131                 if ($ret){
132                         // 取得データを連想配列にする
133                         $configCount = count($rows);
134                         for ($i = 0; $i < $configCount; $i++){
135                                 $key = $rows[$i]['bg_id'];
136                                 $value = $rows[$i]['bg_value'];
137                                 $this->_configArray[$key] = $value;
138                         }
139                 }
140                 return $ret;
141         }
142         /**
143          * メッセージを表示用に変換
144          *
145          * @param string $message               変換元メッセージ
146          * @param string $threadId              スレッドID
147          * @return string                               変換後メッセージ
148          */
149         function convDispMessage($message, $threadId)
150         {
151                 // リンク変換
152                 /*if (!empty($this->_autolink)){                // 自動リンク作成のとき
153                         $message = preg_replace("/(https?):\/\/([\w;\/\?:\@&=\+\$,\-\.!~\*'\(\)%#]+)/", "<a href=\"$1://$2\" target=\"_blank\">$1://$2</a>", $message);
154                 
155                         // メッセージへのリンク
156                 //      $baseUrl = $this->convertUrlToHtmlEntity($this->getUrl($this->_currentPageUrl . '&' . M3_REQUEST_PARAM_BBS_THREAD_ID . '=' . $threadId, true));
157                         $messageUrl = $baseUrl . $this->convertUrlToHtmlEntity('&' . M3_REQUEST_PARAM_ITEM_NO . '=');
158                         $messageListUrl = $baseUrl . $this->convertUrlToHtmlEntity('&' . M3_REQUEST_PARAM_LIST_NO . '=');
159                         $message = preg_replace("/&gt;&gt;([0-9]+)(?![-\d])/", '<a href="' . $messageUrl . '$1" target="_blank">&gt;&gt;$1</a>', $message);
160                         $message = preg_replace("/&gt;&gt;([0-9]+)\-([0-9]+)/", '<a href="' . $messageListUrl . '$1-$2" target="_blank">&gt;&gt;$1-$2</a>', $message);
161                 }*/
162                 return $message;
163         }
164         /**
165          * テキストデータを表示用のテキストに変換
166          *
167          * 変換内容 ・改行コードをスペース「&nbsp;」に変換
168          *
169          * @param string $src                   変換するデータ
170          * @return string                               変換後データ
171          */
172         function _convertToPreviewTextWithSpace($src)
173         {
174                 return preg_replace("/(\015\012)|(\015)|(\012)/", "&nbsp;", $src);
175         }
176 }
177 ?>