OSDN Git Service

初回コミット(v2.6.17.1)
[magic3/magic3.git] / widgets / custom_search / include / container / custom_searchWidgetContainer.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    カスタム検索
10  * @author     株式会社 毎日メディアサービス
11  * @copyright  Copyright 2010-2013 株式会社 毎日メディアサービス.
12  * @license    http://www.gnu.org/copyleft/gpl.html  GPL License
13  * @version    SVN: $Id: custom_searchWidgetContainer.php 5969 2013-04-29 13:16:04Z fishbone $
14  * @link       http://www.m-media.co.jp
15  */
16 require_once($gEnvManager->getContainerPath() . '/baseWidgetContainer.php');
17 require_once($gEnvManager->getCurrentWidgetDbPath() . '/custom_searchDb.php');
18
19 class custom_searchWidgetContainer extends BaseWidgetContainer
20 {
21         private $db;    // DB接続オブジェクト
22         private $langId;                // 現在の言語
23         private $categoryInfoArray = array();           // カテゴリ種別メニュー
24         private $resultCount;                           // 結果表示件数
25         const DEFAULT_CONFIG_ID = 0;
26         const DEFAULT_TITLE = 'カスタム検索';                     // デフォルトのウィジェットタイトル
27         const FIELD_HEAD = 'item';                      // フィールド名の先頭文字列
28         const DEFAULT_SEARCH_COUNT      = 20;                           // デフォルトの検索結果表示数
29         const LINK_PAGE_COUNT           = 10;                   // リンクページ数
30         const MESSAGE_NO_KEYWORD        = '検索キーワードが入力されていません';
31         const MESSAGE_FIND_NO_CONTENT   = '該当するコンテンツが見つかりません';
32         const CONTENT_SIZE = 200;                       // 検索結果コンテンツの文字列最大長
33         const SEARCH_LIST_CONTENT_ID = 'SEARCH_LIST';   // 検索一覧に表示するコンテンツのID
34         const DEFAULT_SEARCH_ACT = 'custom_search';             // 検索実行処理
35
36         /**
37          * コンストラクタ
38          */
39         function __construct()
40         {
41                 // 親クラスを呼び出す
42                 parent::__construct();
43                 
44                 // DBオブジェクト作成
45                 $this->db = new custom_searchDb();
46         }
47         /**
48          * テンプレートファイルを設定
49          *
50          * _assign()でデータを埋め込むテンプレートファイルのファイル名を返す。
51          * 読み込むディレクトリは、「自ウィジェットディレクトリ/include/template」に固定。
52          *
53          * @param RequestManager $request               HTTPリクエスト処理クラス
54          * @param object         $param                 任意使用パラメータ。そのまま_assign()に渡る
55          * @return string                                               テンプレートファイル名。テンプレートライブラリを使用しない場合は空文字列「''」を返す。
56          */
57         function _setTemplate($request, &$param)
58         {
59                 return 'index.tmpl.html';
60         }
61         /**
62          * テンプレートにデータ埋め込む
63          *
64          * _setTemplate()で指定したテンプレートファイルにデータを埋め込む。
65          *
66          * @param RequestManager $request               HTTPリクエスト処理クラス
67          * @param object         $param                 任意使用パラメータ。_setTemplate()と共有。
68          * @param                                                               なし
69          */
70         function _assign($request, &$param)
71         {
72                 $this->langId = $this->gEnv->getCurrentLanguage();
73                 $this->currentPageUrl = $this->gEnv->createCurrentPageUrl();// 現在のページURL
74                 
75                 // 定義ID取得
76                 $configId = $this->gEnv->getCurrentWidgetConfigId();
77                 if (empty($configId)) $configId = self::DEFAULT_CONFIG_ID;
78                 
79                 // パラメータオブジェクトを取得
80                 $targetObj = $this->getWidgetParamObjByConfigId($configId);
81                 if (empty($targetObj)){         // 定義データが取得できないとき
82                         $this->cancelParse();           // テンプレート変換処理中断
83                         return;
84                 }
85                 
86                 // ログインユーザでないときは、ユーザ制限のない項目だけ表示
87                 $isAll = false;
88                 if ($this->gEnv->isCurrentUserLogined()) $isAll = true;
89                 
90                 $name = $targetObj->name;// 定義名
91                 $this->resultCount      = intval($targetObj->resultCount);                      // 表示項目数
92                 if ($this->resultCount <= 0) $this->resultCount = self::DEFAULT_SEARCH_COUNT;
93                 $this->searchTextId = $targetObj->searchTextId;         // 検索用テキストフィールドのタグID
94                 $this->searchButtonId = $targetObj->searchButtonId;             // 検索用ボタンのタグID
95                 $this->searchResetId = $targetObj->searchResetId;               // 検索エリアリセットボタンのタグID
96                 $isTargetContent = $targetObj->isTargetContent;         // 汎用コンテンツを検索対象とするかどうか
97                 $isTargetUser = $targetObj->isTargetUser;                       // ユーザ作成コンテンツを検索対象とするかどうか
98                 $isTargetBlog = $targetObj->isTargetBlog;                       // ブログ記事を検索対象とするかどうか
99                 $isTargetProduct = $targetObj->isTargetProduct;                 // 商品情報を検索対象とするかどうか
100                 $isTargetEvent = $targetObj->isTargetEvent;                     // イベント情報を検索対象とするかどうか
101                 $isTargetBbs = $targetObj->isTargetBbs;                 // BBSを検索対象とするかどうか
102                 $isTargetPhoto = $targetObj->isTargetPhoto;                     // フォトギャラリーを検索対象とするかどうか
103                 $searchTemplate = $targetObj->searchTemplate;           // 検索用テンプレート
104                 if (!empty($targetObj->fieldInfo)) $this->fieldInfoArray = $targetObj->fieldInfo;                       // 項目定義
105                 $searchFormId = $this->gEnv->getCurrentWidgetId() . '_' . $configId . '_form';          // フォームのID
106                 $pageNo = $request->trimIntValueOf(M3_REQUEST_PARAM_PAGE_NO, '1');                              // ページ番号
107                 
108                 // 入力値を取得
109                 $this->valueArray = array();
110                 $categoryArray = array();
111                 $fieldCount = count($this->fieldInfoArray);
112                 for ($i = 0; $i < $fieldCount; $i++){
113                         $itemName = self::FIELD_HEAD . ($i + 1);
114                         $itemValue = $request->trimValueOf($itemName);
115                         $this->valueArray[] = $itemValue;
116                         
117                         // 表示するカテゴリIDを取得
118                         $categoryType = $this->fieldInfoArray[$i]->categoryType;
119                         if (!in_array($categoryType, $categoryArray)) $categoryArray[] = $categoryType; // カテゴリ種別メニュー
120                 }
121                 $keyword = $request->trimValueOf('keyword');            // 検索キーワード
122                 $act = $request->trimValueOf('act');
123                 // ##### joomla!検索インターフェイス #####
124                 $task = $request->trimValueOf('task');
125                 $option = $request->trimValueOf('option');
126                 
127                 if ($act == self::DEFAULT_SEARCH_ACT ||                 // 検索実行
128                         ($task == 'search' && $option == 'com_search')){                // joomla!検索インターフェイスからの検索
129                         
130                         // ##### joomla!検索インターフェイスからの実行の場合 #####
131                         if ($task == 'search' && $option == 'com_search'){
132                                 $keyword = $request->trimValueOf('searchword');         // 検索キーワード
133                         }
134                         
135                         // 検索キーワードが空以外の場合は、キーワードログを残す
136                         $parsedKeywords = array();
137                         if (!empty($keyword)){
138                                 // キーワード分割
139                                 $parsedKeywords = $this->gInstance->getTextConvManager()->parseSearchKeyword($keyword);
140                                 
141                                 // 検索キーワードを記録
142                                 for ($i = 0; $i < count($parsedKeywords); $i++){
143                                         $this->gInstance->getAnalyzeManager()->logSearchWord($this->gEnv->getCurrentWidgetId(), $parsedKeywords[$i]);
144                                 }
145                         }
146                         
147                         // カテゴリの設定値を取得
148                         $selectCategory = array();
149                         $fieldCount = count($this->fieldInfoArray);
150                         for ($i = 0; $i < $fieldCount; $i++){
151                                 $infoObj = $this->fieldInfoArray[$i];
152                                 $categoryType = $infoObj->categoryType;                 // カテゴリ種別
153                                 
154                                 // 設定値がある場合のみ取得
155                                 $inputValue = $this->valueArray[$i];            // 入力値
156                                 if (!empty($inputValue)) $selectCategory[$categoryType] = $inputValue;          // 入力値
157                         }
158                         
159                         // 入力条件が検索キーワードのみの場合、キーワードが入力されていなければエラーメッセージを表示
160                         if ($fieldCount == 0 && empty($parsedKeywords)){
161                                 $message = self::MESSAGE_NO_KEYWORD;
162                         } else {
163                                 // ##### 検索実行の場合 #####
164                                 // 総数を取得
165 //                              $totalCount = $this->db->searchContentsCountByKeyword($parsedKeywords, $selectCategory, $this->langId, $isAll, $isTargetContent, $isTargetUser, $isTargetBlog,
166 //                                                              $isTargetProduct, $isTargetEvent, $isTargetBbs, $isTargetPhoto);
167                                 $totalCount = $this->db->searchContentsByKeyword(0/*項目数取得*/, 0/*ダミー*/, $parsedKeywords, $selectCategory, $this->langId, $isAll, $isTargetContent, $isTargetUser, $isTargetBlog,
168                                                                 $isTargetProduct, $isTargetEvent, $isTargetBbs, $isTargetPhoto);
169
170                                 // リンク文字列作成、ページ番号調整
171                                 $pageLink = $this->createPageLink($pageNo, $totalCount, $this->resultCount, $this->currentPageUrl . '&act=' . self::DEFAULT_SEARCH_ACT . '&keyword=' . urlencode($keyword));
172                                 
173                                 // 検出項目を表示
174                                 $this->db->searchContentsByKeyword($this->resultCount, $pageNo, $parsedKeywords, $selectCategory, $this->langId, $isAll, $isTargetContent, $isTargetUser, $isTargetBlog, 
175                                                                 $isTargetProduct, $isTargetEvent, $isTargetBbs, $isTargetPhoto, array($this, 'searchItemsLoop'));
176                                 
177                                 if ($this->isExistsViewData){
178                                         // ページリンクを埋め込む
179                                         if (!empty($pageLink)){
180                                                 $this->tmpl->setAttribute('page_link_top', 'visibility', 'visible');            // リンク表示
181                                                 $this->tmpl->setAttribute('page_link', 'visibility', 'visible');                // リンク表示
182                                                 $this->tmpl->addVar("page_link_top", "page_link", $pageLink);
183                                                 $this->tmpl->addVar("page_link", "page_link", $pageLink);
184                                         }
185                                 } else {        // 検索結果なしの場合
186                                         $this->tmpl->setAttribute('result_list', 'visibility', 'hidden');
187                                         $message = self::MESSAGE_FIND_NO_CONTENT;
188                                 }
189                         }
190                 }
191                 // カテゴリ情報を取得
192                 $ret = $this->db->getAllCategoryForMenu($this->langId, $categoryArray, $rows);
193                 if ($ret){
194                         $line = array();
195                         $rowCount = count($rows);
196                         for ($i = 0; $i < $rowCount; $i++){
197                                 $line[] = $rows[$i];
198                                 $itemId = $rows[$i]['ua_item_id'];
199                                 if (empty($itemId)){            // カテゴリ種別のとき
200                                         $categoryId = $rows[$i]['ua_id'];
201                                         $this->categoryInfoArray[$categoryId] = $line;
202                                         $line = array();
203                                 }
204                         }
205                 }
206                 // メッセージを表示
207                 if (!empty($message)){
208                         $this->tmpl->setAttribute('message', 'visibility', 'visible');
209                         $this->tmpl->addVar("message", "message", $this->convertToDispString($message));
210                 }
211                 
212                 // 検索画面作成
213                 $fieldOutput = $this->createFieldOutput($searchTemplate);
214                 
215                 // 表示データ埋め込み
216                 $this->tmpl->addVar("_widget", "page_sub",      $this->gEnv->getCurrentPageSubId());            // ページサブID
217                 $this->tmpl->addVar("_widget", "html",  $fieldOutput);
218                 $this->tmpl->addVar("_widget", "search_text_id",        $this->searchTextId);           // 検索用テキストフィールドのタグID
219                 $this->tmpl->addVar("_widget", "search_button_id",      $this->searchButtonId);         // 検索用ボタンのタグID
220                 $this->tmpl->addVar("_widget", "search_reset_id",       $this->searchResetId);          // 検索エリアリセットボタンのタグID
221                 $this->tmpl->addVar("_widget", "search_form_id",        $searchFormId);         // 検索フォームのタグID
222                 $this->tmpl->addVar("_widget", "keyword",       $keyword);              // 検索キーワード
223                 $this->tmpl->addVar("_widget", "search_act",    self::DEFAULT_SEARCH_ACT);              // 検索実行処理
224         }
225         /**
226          * ウィジェットのタイトルを設定
227          *
228          * @param RequestManager $request               HTTPリクエスト処理クラス
229          * @param object         $param                 任意使用パラメータ。そのまま_assign()に渡る
230          * @return string                                               ウィジェットのタイトル名
231          */
232         function _setTitle($request, &$param)
233         {
234                 return self::DEFAULT_TITLE;
235         }
236         /**
237          * 検索条件フィールド作成
238          *
239          * @param string $templateData  テンプレートデータ
240          * @return string                               フィールドデータ
241          */
242         function createFieldOutput($templateData)
243         {
244                 $fieldOutput = $templateData;
245                 
246                 $fieldCount = count($this->fieldInfoArray);
247                 for ($i = 0; $i < $fieldCount; $i++){
248                         $infoObj = $this->fieldInfoArray[$i];
249                         $categoryType = $infoObj->categoryType;                 // カテゴリ種別
250                         $selectType = $infoObj->selectType;                             // 選択タイプ
251                         $titleVisible = $infoObj->titleVisible;         // タイトル表示制御
252                         $initValue = $infoObj->initValue;               // 初期値
253                         $categoryItems = $this->categoryInfoArray[$categoryType];               // カテゴリ項目
254                         $categoryItemCount = count($categoryItems) -1;
255                         $categoryName = $categoryItems[$categoryItemCount]['ua_name'];          // カテゴリ種別名
256                         
257                         // 入力フィールドの作成
258                         $inputTag = '';
259                         $fieldName = self::FIELD_HEAD . ($i + 1);
260                         $inputValue = $this->valueArray[$i];            // 入力値
261                         $inputTag = '';
262                         switch ($selectType){
263                                 case 'single':  // 単一選択
264                                         // タイトルの設定
265                                         if (!empty($titleVisible)) $inputTag .= $this->convertToDispString($categoryName);
266                                         
267                                         $inputTag .= '<select id="' . $fieldName . '" name="' . $fieldName . '" >' . M3_NL;
268                                         $name = '&nbsp;';
269                                         if (!empty($initValue)) $name = $this->convertToDispString($initValue);
270                                         $inputTag .= '<option value="">' . $name . '</option>' . M3_NL;
271                                         for ($j = 0; $j < $categoryItemCount; $j++){
272                                                 $param = array();
273                                                 $paramStr = '';
274                                                 $value = $categoryItems[$j]['ua_item_id'];
275                                                 $name = $categoryItems[$j]['ua_name'];
276                                                 if (!empty($inputValue) && strcmp($inputValue, $value) == 0) $param[] = 'selected';
277                                                 if (count($param) > 0) $paramStr = ' ' . implode($param, ' ');
278                                                 $inputTag .= '<option value="' . $this->convertToDispString($value) . '"' . $paramStr . '>' . $this->convertToDispString($name) . '</option>' . M3_NL;
279                                         }
280                                         $inputTag .= '</select>' . M3_NL;
281                                         break;
282                                 case 'multi':   // 複数選択
283                                         $fieldName .= '[]';
284                                         
285                                         // タイトルの設定
286                                         if (!empty($titleVisible)) $inputTag .= $this->convertToDispString($categoryName);
287
288                                         for ($j = 0; $j < $categoryItemCount; $j++){
289                                                 $param = array();
290                                                 $paramStr = '';
291                                                 $value = $categoryItems[$j]['ua_item_id'];
292                                                 $name = $categoryItems[$j]['ua_name'];
293                                                 for ($k = 0; $k < count($inputValue); $k++){
294                                                         if (!empty($inputValue[$k]) && strcmp($inputValue[$k], $value) == 0) $param[] = 'checked';
295                                                 }
296                                                 if (count($param) > 0) $paramStr = ' ' . implode($param, ' ');
297                                                 $inputTag .= '<label><input type="checkbox" name="' . $fieldName . '" value="' . $this->convertToDispString($value) . '"'
298                                                                                 . $paramStr . ' />' . $this->convertToDispString($name) . '</label>';
299                                         }
300                                         $inputTag .= M3_NL;
301                                         break;
302                         }
303                         
304                         // テンプレートに埋め込む
305                         $keyTag = M3_TAG_START . M3_TAG_MACRO_ITEM_KEY . ($i + 1) . M3_TAG_END;
306                         $fieldOutput = str_replace($keyTag, $inputTag, $fieldOutput);
307                 }
308                 return $fieldOutput;
309         }
310         /**
311          * 取得したコンテンツ項目をテンプレートに設定する
312          *
313          * @param int           $index                  行番号
314          * @param array         $fetchedRow             取得行
315          * @param object        $param                  任意使用パラメータ
316          * @return bool                                         trueを返すとループ続行。falseを返すとその時点で終了。
317          */
318         function searchItemsLoop($index, $fetchedRow)
319         {
320                 // コンテンツへのリンクを生成
321                 $linkUrl = '';
322                 $summary = '';          // コンテンツ概要
323                 $contentType = $fetchedRow['type'];
324                 switch ($contentType){
325                         case M3_VIEW_TYPE_CONTENT:              // 汎用コンテンツの場合
326                                 $contentId = $fetchedRow['id'];
327                                 
328                                 // コンテンツへのリンクを作成
329                                 $linkUrl = $this->getUrl($this->gEnv->getDefaultUrl() . '?' . M3_REQUEST_PARAM_CONTENT_ID . '=' . $contentId, true/*リンク用*/);
330
331                                 // コンテンツを取得
332                                 $ret = $this->db->getContentByContentId(''/*汎用コンテンツ*/, $contentId, $this->langId, $row);
333                                 if ($ret){
334                                         // テキストに変換。HTMLタグ削除。
335                                         $content = $this->gInstance->getTextConvManager()->htmlToText($row['cn_html']);
336                 
337                                         // 登録したキーワードを変換
338                                         // *** キーワード部分の検索はどうする? ***
339                                         $this->gInstance->getTextConvManager()->convByKeyValue($content, $content);
340                 
341                                         // 検索結果用にテキストを詰める。改行、タブ、スペース削除。
342                                         $content = str_replace(array("\r", "\n", "\t", " "), '', $content);
343                 
344                                         // 文字列長を修正
345                                         if (function_exists('mb_strimwidth')){
346                                                 $content = mb_strimwidth($content, 0, self::CONTENT_SIZE, '…');
347                                         } else {
348                                                 $content = substr($content, 0, self::CONTENT_SIZE) . '...';
349                                         }
350                                         $summary = $content;
351                                 }
352                                 break;
353                         case M3_VIEW_TYPE_USER:         // ユーザ作成コンテンツの場合
354                                 $roomId = $fetchedRow['id'];
355                                 $groupId = $fetchedRow['group_id'];                     // ルームの所属グループ
356                                 
357                                 // コンテンツへのリンクを作成
358                                 $linkUrl = $this->getUrl($this->gEnv->getDefaultUrl() . '?'. M3_REQUEST_PARAM_ROOM_ID . '=' . $roomId, true/*リンク用*/);
359                                 
360                                 // ルームIDに対応したコンテンツをすべて取得
361                                 $contentArray = $this->getAllContent($roomId, $this->langId, $searchListItemId);
362                                         
363                                 if (empty($searchListItemId)){          // 検索一覧用データがないとき
364                                         // タブ情報を取得
365                                         $ret = $this->db->getDefaultTab($this->langId, $groupId, $defaultTabRow);
366                                         
367                                         // 検索一覧用のコンテンツかデフォルトのタブの内容を表示
368                                         if ($ret){
369                                                 // タブ内容を作成
370                                                 $content = $defaultTabRow['ub_template_html'];
371                 
372                                                 // コンテンツ項目IDを取得
373                                                 $useItemArray = array();
374                                                 $useItem = $defaultTabRow['ub_use_item_id'];
375                                                 if (!empty($useItem)){
376                                                         $useItemArray = explode(',', $useItem);
377                                                 }
378                         
379                                                 // タブにコンテンツデータを埋め込む
380                                                 for ($i = 0; $i < count($useItemArray); $i++){
381                                                         $itemId = $useItemArray[$i];
382                                                         $keyTag = M3_TAG_START . M3_TAG_MACRO_ITEM_KEY . $itemId . M3_TAG_END;// 埋め込みタグ
383
384                                                         $contentInfo = $contentArray[$itemId];
385                                                         if (isset($contentInfo)){       
386                                                                 $contentData = $contentInfo['uc_data'];
387                                 
388                                                                 // テキスト、数値のときは文字エスケープ処理
389                                                                 if ($contentInfo['ui_type'] != 0){
390                                                                         $contentData = $this->convertToDispString($contentData);
391                                                                 }
392                                                         } else {
393                                                                 $contentData = '';
394                                                         }
395                                                         // 埋め込みタグ変換
396                                                         $content = str_replace($keyTag, $contentData, $content);
397                                                 }
398                                         
399                                                 // タブの内容をテキストに変換
400                                                 $content = $this->gInstance->getTextConvManager()->htmlToText($content);
401                 
402                                                 // 検索結果用にテキストを詰める。改行、タブ、スペース削除。
403                                                 $content = str_replace(array("\r", "\n", "\t", " "), '', $content);
404                 
405                                                 // 文字列長を修正
406                                                 if (function_exists('mb_strimwidth')){
407                                                         $content = mb_strimwidth($content, 0, self::CONTENT_SIZE, '…');
408                                                 } else {
409                                                         $content = substr($content, 0, self::CONTENT_SIZE) . '...';
410                                                 }
411                                                 $summary = $content;
412                                         }
413                                 } else {                // 検索一覧用データがあるとき
414                                         $contentInfo = $contentArray[$searchListItemId];
415                                         if (isset($contentInfo)){       
416                                                 $contentData = $contentInfo['uc_data'];
417                 
418                                                 // テキスト、数値のときは文字エスケープ処理
419                                                 if ($contentInfo['ui_type'] != 0){
420                                                         $contentData = $this->convertToDispString($contentData);
421                                                 }
422                                         } else {
423                                                 $contentData = '';
424                                         }
425                                         $summary = $contentData;
426                                 }
427                                 break;
428                         case M3_VIEW_TYPE_BLOG:                 // ブログコンテンツの場合
429                                 $entryId = $fetchedRow['id'];
430                                 
431                                 // ブログ記事へのリンクを作成
432                                 $linkUrl = $this->getUrl($this->gEnv->getDefaultUrl() . '?' . M3_REQUEST_PARAM_BLOG_ENTRY_ID . '=' . $entryId, true/*リンク用*/);
433
434                                 // ブログ記事を取得
435                                 $ret = $this->db->getEntryByEntryId($entryId, $this->langId, $row);
436                                 if ($ret){
437                                         // テキストに変換。HTMLタグ削除。
438                                         $content = $this->gInstance->getTextConvManager()->htmlToText($row['be_html']);
439                 
440                                         // 検索結果用にテキストを詰める。改行、タブ、スペース削除。
441                                         $content = str_replace(array("\r", "\n", "\t", " "), '', $content);
442                 
443                                         // 文字列長を修正
444                                         if (function_exists('mb_strimwidth')){
445                                                 $content = mb_strimwidth($content, 0, self::CONTENT_SIZE, '…');
446                                         } else {
447                                                 $content = substr($content, 0, self::CONTENT_SIZE) . '...';
448                                         }
449                                         $summary = $content;
450                                 }
451                                 break;
452                         case M3_VIEW_TYPE_PRODUCT:                      // 商品情報の場合
453                                 $productId = $fetchedRow['id'];
454                                 
455                                 // 商品情報へのリンクを作成
456                                 $linkUrl = $this->getUrl($this->gEnv->getDefaultUrl() . '?' . M3_REQUEST_PARAM_PRODUCT_ID . '=' . $productId, true/*リンク用*/);
457
458                                 // 商品情報を取得
459                                 $ret = $this->db->getProductByProductId($productId, $this->langId, $row);
460                                 if ($ret){
461                                         $summary = $row['pt_description_short'];
462                                         if (empty($summary)){
463                                                 // テキストに変換。HTMLタグ削除。
464                                                 $content = $this->gInstance->getTextConvManager()->htmlToText($row['pt_description']);
465         
466                                                 // 検索結果用にテキストを詰める。改行、タブ、スペース削除。
467                                                 $content = str_replace(array("\r", "\n", "\t", " "), '', $content);
468         
469                                                 // 文字列長を修正
470                                                 if (function_exists('mb_strimwidth')){
471                                                         $content = mb_strimwidth($content, 0, self::CONTENT_SIZE, '…');
472                                                 } else {
473                                                         $content = substr($content, 0, self::CONTENT_SIZE) . '...';
474                                                 }
475                                                 $summary = $content;
476                                         }
477                                 }
478                                 break;
479                         case M3_VIEW_TYPE_EVENT:                        // イベント情報の場合
480                                 $eventId = $fetchedRow['id'];
481                                 
482                                 // イベント情報へのリンクを作成
483                                 $linkUrl = $this->getUrl($this->gEnv->getDefaultUrl() . '?' . M3_REQUEST_PARAM_EVENT_ID . '=' . $eventId, true/*リンク用*/);
484
485                                 // イベント情報を取得
486                                 $ret = $this->db->getEvent($eventId, $this->langId, $row);
487                                 if ($ret){
488                                         $summary = $row['ee_summary'];
489                                         if (empty($summary)){
490                                                 // テキストに変換。HTMLタグ削除。
491                                                 $content = $this->gInstance->getTextConvManager()->htmlToText($row['ee_html']);
492         
493                                                 // 検索結果用にテキストを詰める。改行、タブ、スペース削除。
494                                                 $content = str_replace(array("\r", "\n", "\t", " "), '', $content);
495         
496                                                 // 文字列長を修正
497                                                 if (function_exists('mb_strimwidth')){
498                                                         $content = mb_strimwidth($content, 0, self::CONTENT_SIZE, '…');
499                                                 } else {
500                                                         $content = substr($content, 0, self::CONTENT_SIZE) . '...';
501                                                 }
502                                                 $summary = $content;
503                                         }
504                                 }
505                                 break;
506                         case M3_VIEW_TYPE_BBS:                  // BBSスレッド情報の場合
507                                 $threadId = $fetchedRow['id'];
508                                 
509                                 // フォト情報へのリンクを作成
510                                 $linkUrl = $this->getUrl($this->gEnv->getDefaultUrl() . '?' . M3_REQUEST_PARAM_BBS_THREAD_ID . '=' . $threadId, true/*リンク用*/);
511
512                                 // フォト情報を取得
513                                 $ret = $this->db->getBbsThread($threadId, $row);
514                                 if ($ret){
515                                         // テキストに変換。HTMLタグ削除。
516                                         $content = $this->gInstance->getTextConvManager()->htmlToText($row['te_message']);
517
518                                         // 検索結果用にテキストを詰める。改行、タブ、スペース削除。
519                                         $content = str_replace(array("\r", "\n", "\t", " "), '', $content);
520
521                                         // 文字列長を修正
522                                         if (function_exists('mb_strimwidth')){
523                                                 $content = mb_strimwidth($content, 0, self::CONTENT_SIZE, '…');
524                                         } else {
525                                                 $content = substr($content, 0, self::CONTENT_SIZE) . '...';
526                                         }
527                                         $summary = $content;
528                                 }
529                                 break;
530                         case M3_VIEW_TYPE_PHOTO:                        // フォト情報の場合
531                                 $photoId = $fetchedRow['id'];
532                                 
533                                 // フォト情報へのリンクを作成
534                                 $linkUrl = $this->getUrl($this->gEnv->getDefaultUrl() . '?' . M3_REQUEST_PARAM_PHOTO_ID . '=' . $photoId, true/*リンク用*/);
535
536                                 // フォト情報を取得
537                                 $ret = $this->db->getPhoto($photoId, $this->langId, $row);
538                                 if ($ret){
539                                         $summary = $row['ht_summary'];
540                                         if (empty($summary)){
541                                                 // テキストに変換。HTMLタグ削除。
542                                                 $content = $this->gInstance->getTextConvManager()->htmlToText($row['ht_description']);
543         
544                                                 // 検索結果用にテキストを詰める。改行、タブ、スペース削除。
545                                                 $content = str_replace(array("\r", "\n", "\t", " "), '', $content);
546         
547                                                 // 文字列長を修正
548                                                 if (function_exists('mb_strimwidth')){
549                                                         $content = mb_strimwidth($content, 0, self::CONTENT_SIZE, '…');
550                                                 } else {
551                                                         $content = substr($content, 0, self::CONTENT_SIZE) . '...';
552                                                 }
553                                                 $summary = $content;
554                                         }
555                                 }
556                                 break;
557                         default:
558                                 break;
559                 }
560                 $titleLink = $this->convertToDispString($fetchedRow['name']);
561                 if (!empty($linkUrl)) $titleLink = '<a href="' . $this->convertUrlToHtmlEntity($linkUrl) . '" >' . $titleLink . '</a>';
562
563                 $row = array(
564                         'title' => $titleLink,                  // タイトル
565                         'body' => $summary                      // コンテンツ概要
566                 );
567                 $this->tmpl->addVars('result_list', $row);
568                 $this->tmpl->parseTemplate('result_list', 'a');
569                 $this->isExistsViewData = true;                         // 表示データがあるかどうか
570                 return true;
571         }
572         /**
573          * すべてのコンテンツ項目を取得
574          *
575          * @param string $roomId                ルームID
576          * @param string $langId                言語ID
577          * @param string $listItemId    検索一覧に表示するコンテンツのID
578          * @return array                                コンテンツ項目IDをキーにしたコンテンツ項目レコードの連想配列
579          */
580         function getAllContent($roomId, $langId, &$listItemId)
581         {
582                 $destArray = array();
583                 
584                 $ret = $this->db->getAllContentsByRoomId($roomId, $langId, $rows);
585                 if ($ret){
586                         $count = count($rows);
587                         for ($i = 0; $i < $count; $i++){
588                                 $key = $rows[$i]['uc_id'];
589                                 $destArray[$key] = $rows[$i];
590                 
591                                 // 検索一覧に表示するコンテンツのID
592                                 if ($rows[$i]['ui_key'] == self::SEARCH_LIST_CONTENT_ID) $listItemId = $key;
593                         }
594                 }
595                 return $destArray;
596         }
597         /**
598          * ページリンク作成
599          *
600          * @param int $pageNo                   ページ番号(1~)。ページ番号が範囲外にある場合は自動的に調整
601          * @param int $totalCount               総項目数
602          * @param int $viewItemCount    1ページあたりの項目数
603          * @param string $baseUrl               リンク用のベースURL
604          * @return string                               リンクHTML
605          */
606         function createPageLink(&$pageNo, $totalCount, $viewItemCount, $baseUrl)
607         {
608                 // 表示するページ番号の修正
609                 $pageCount = (int)(($totalCount -1) / $viewItemCount) + 1;              // 総ページ数
610                 if ($pageNo < 1) $pageNo = 1;
611                 if ($pageNo > $pageCount) $pageNo = $pageCount;
612
613                 // ページング用リンク作成
614                 $pageLink = '';
615                 if ($pageCount > 1){    // ページが2ページ以上のときリンクを作成
616                         //for ($i = 1; $i <= $pageCount; $i++){
617                         // ページ数1から「LINK_PAGE_COUNT」までのリンクを作成
618                         $maxPageCount = $pageCount < self::LINK_PAGE_COUNT ? $pageCount : self::LINK_PAGE_COUNT;
619                         for ($i = 1; $i <= $maxPageCount; $i++){
620                                 if ($i == $pageNo){
621                                         $link = '&nbsp;' . $i;
622                                 } else {
623                                         //$linkUrl = $this->getUrl($baseUrl . '&page=' . $i, true/*リンク用*/);
624                                         $linkUrl = $this->getUrl($this->addSearchParam($baseUrl . '&page=' . $i), true/*リンク用*/);
625                                         $link = '&nbsp;<a href="' . $this->convertUrlToHtmlEntity($linkUrl) . '" >' . $i . '</a>';
626                                 }
627                                 $pageLink .= $link;
628                         }
629                         // 残りは「...」表示
630                         if ($pageCount > self::LINK_PAGE_COUNT) $pageLink .= '&nbsp;...';
631                 }
632                 if ($pageNo > 1){               // 前ページがあるとき
633                         //$linkUrl = $this->getUrl($baseUrl . '&page=' . ($pageNo -1), true/*リンク用*/);
634                         $linkUrl = $this->getUrl($this->addSearchParam($baseUrl . '&page=' . ($pageNo -1)), true/*リンク用*/);
635                         $link = '<a href="' . $this->convertUrlToHtmlEntity($linkUrl) . '" >前へ</a>';
636                         $pageLink = $link . $pageLink;
637                 }
638                 if ($pageNo < $pageCount){              // 次ページがあるとき
639                         //$linkUrl = $this->getUrl($baseUrl . '&page=' . ($pageNo +1), true/*リンク用*/);
640                         $linkUrl = $this->getUrl($this->addSearchParam($baseUrl . '&page=' . ($pageNo +1)), true/*リンク用*/);
641                         $link = '&nbsp;<a href="' . $this->convertUrlToHtmlEntity($linkUrl) . '" >次へ</a>';
642                         $pageLink .= $link;
643                 }
644                 return $pageLink;
645         }
646         /**
647          * URLに検索条件のパラメータを付加
648          *
649          * @param string $url   URL
650          * @return string               作成されたURL
651          */
652         function addSearchParam($url)
653         {
654                 $destUrl = $url;
655                 $fieldCount = count($this->fieldInfoArray);
656                 for ($i = 0; $i < $fieldCount; $i++){
657                         $itemName = self::FIELD_HEAD . ($i + 1);
658                         $itemValue = $this->gRequest->trimValueOf($itemName);
659                         if (is_array($itemValue)){
660                                 $paramCount = count($itemValue);
661                                 for ($j = 0; $j < $paramCount; $j++){
662                                         $destUrl .= '&' . $itemName . '[]=' . urlencode($itemValue[$j]);
663                                 }
664                         } else {
665                                 if (!empty($itemValue)) $destUrl .= '&' . $itemName . '=' . urlencode($itemValue);
666                         }
667                 }
668                 return $destUrl;
669         }
670 }
671 ?>