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_photoslideWidgetContainer.php 4868 2012-04-20 10:05:13Z fishbone $
14 * @link http://www.magic3.org
16 require_once($gEnvManager->getContainerPath() . '/baseWidgetContainer.php');
17 require_once($gEnvManager->getCurrentWidgetDbPath() . '/s_photoslideDb.php');
19 class s_photoslideWidgetContainer extends BaseWidgetContainer
21 private $db; // DB接続オブジェクト
22 private $css; // 追加CSS
23 private $visible; // 表示するかどうか
24 private $dispType; // 画像表示方法
25 const DEFAULT_CONFIG_ID = 0;
26 const DEFAULT_IMAGE_TYPE = 'directory'; // デフォルトの画像タイプ
27 const PHOTO_IMAGE_DIR = '/widgets/photo/image'; // フォトギャラリー公開画像ディレクトリ
28 const DEFAULT_PHOTO_IMAGE_EXT = 'jpg'; // フォトギャラリー公開画像ファイル拡張子
29 const CF_PHOTO_CATEGORY_PASSWORD = 'photo_category_password'; // 画像カテゴリーのパスワード制限
34 function __construct()
37 parent::__construct();
40 $this->db = new s_photoslideDb();
45 * _assign()でデータを埋め込むテンプレートファイルのファイル名を返す。
46 * 読み込むディレクトリは、「自ウィジェットディレクトリ/include/template」に固定。
48 * @param RequestManager $request HTTPリクエスト処理クラス
49 * @param object $param 任意使用パラメータ。そのまま_assign()に渡る
50 * @return string テンプレートファイル名。テンプレートライブラリを使用しない場合は空文字列「''」を返す。
52 function _setTemplate($request, &$param)
54 return 'index.tmpl.html';
59 * _setTemplate()で指定したテンプレートファイルにデータを埋め込む。
61 * @param RequestManager $request HTTPリクエスト処理クラス
62 * @param object $param 任意使用パラメータ。_setTemplate()と共有。
65 function _assign($request, &$param)
67 $langId = $this->gEnv->getCurrentLanguage(); // 表示言語を取得
70 $configId = $this->gEnv->getCurrentWidgetConfigId();
71 if (empty($configId)) $configId = self::DEFAULT_CONFIG_ID;
74 $targetObj = $this->getWidgetParamObjByConfigId($configId);
75 if (empty($targetObj)){// 定義データが取得できないときは終了
76 $this->cancelParse(); // テンプレート変換処理中断
83 $name = $targetObj->name;// 定義名
84 $imageType = $targetObj->imageType;// 表示画像タイプ
85 $dir = $targetObj->dir; // 画像の読み込みディレクトリ
86 $cssId = $targetObj->cssId; // CSS用ID
87 $this->css = $targetObj->css; // 追加CSS
88 $this->dispType = $targetObj->dispType; // 表示方法
89 $effect = $targetObj->effect; // エフェクト
90 $speed = $targetObj->speed;
91 $imageCount = $targetObj->imageCount; // 画像取得数
92 $sortOrder = $targetObj->sortOrder; // 画像並び順
93 $this->sortKey = $targetObj->sortKey; // 画像ソートキー
98 $this->createImageList($dir);
101 if (!$this->db->getConfig(self::CF_PHOTO_CATEGORY_PASSWORD)){ // カテゴリーパスワード制限がかかっているときは画像の表示不可
102 $this->db->getPhotoItems($imageCount, $langId, $this->sortKey, $sortOrder, array($this, 'itemLoop'));
108 $effectStr = $this->createEffect($effect, $speed);
109 $this->tmpl->addVar('_widget', 'effect', $effectStr);
110 $this->tmpl->addVar('_widget', 'css_id', $cssId);
111 $this->visible = true;
116 * CSSデータをHTMLのheadタグ内に追加出力する。
117 * _assign()よりも後に実行される。
119 * @param RequestManager $request HTTPリクエスト処理クラス
120 * @param object $param 任意使用パラメータ。
121 * @return string CSS文字列。出力しない場合は空文字列を設定。
123 function _addCssToHead($request, &$param)
134 * @param string $effect エフェクト
135 * @param string $speed speedパラメータ
136 * @return string エフェクト文字列
138 function createEffect($effect, $speed)
141 if (!empty($effect)) $effectStr .= 'fx: \'' . $effect . '\'';
143 if (!empty($effectStr)) $effectStr .= ',';
144 $effectStr .= 'speed: \'' . $speed . '\'';
151 * @param string $dir 画像のあるディレクトリ
154 function createImageList($dir)
157 $searchPath = $this->gEnv->getSystemRootPath() . $dir; // 画像検索パス
158 $urlPath = $this->gEnv->getRootUrl() . $dir;
161 $files = $this->getFiles($searchPath);
164 switch ($this->dispType){
173 for ($i = 0; $i < count($files); $i++){
174 $imageUrl = $urlPath . '/' . $files[$i];
175 $imageTag = '<img src="' . $this->convertUrlToHtmlEntity($this->getUrl($imageUrl)) . '" />';
177 'image_tag' => $imageTag // 画像タグ
179 $this->tmpl->addVars('image_list', $row);
180 $this->tmpl->parseTemplate('image_list', 'a');
184 * 取得したデータをテンプレートに設定する
186 * @param int $index 行番号(0~)
187 * @param array $fetchedRow フェッチ取得した行
188 * @param object $param 未使用
189 * @return bool true=処理続行の場合、false=処理終了の場合
191 function itemLoop($index, $fetchedRow, $param)
193 $photoId = $fetchedRow['ht_public_id']; // フォトID
194 $title = $fetchedRow['ht_name']; // サムネール画像タイトル
197 $url = $this->gEnv->getDefaultSmartphoneUrl() . '?' . M3_REQUEST_PARAM_PHOTO_ID . '=' . $photoId;
198 $urlLink = $this->getUrl($url, true);
201 $imageUrl = $this->getUrl($this->getPhotoImageUrl($photoId));
203 $dispTitle = $this->convertToDispString($title);
204 $imageTag = '<a href="' . $this->convertUrlToHtmlEntity($urlLink) . '" data-ajax="false"><img src="' . $this->convertUrlToHtmlEntity($imageUrl) . '" alt="' . $dispTitle . '" title="' . $dispTitle . '" /></a>';
206 'image_tag' => $imageTag // アルバムのサムネール画像
208 $this->tmpl->addVars('image_list', $row);
209 $this->tmpl->parseTemplate('image_list', 'a');
215 * @param string $path 読み込みディレクトリ
216 * @return array ファイル名一覧
218 function getFiles($path)
220 $filenames = array();
223 while (($file = $dir->read()) !== false){
224 $filePath = $path . '/' . $file;
226 if (strncmp($file, '.', 1) != 0 && $file != '..' && is_file($filePath)
227 && strncmp($file, '_', 1) != 0){ // 「_」で始まる名前のファイルは読み込まない
228 $filenames[] = $file;
238 * @param string $photoId 画像ID
239 * @return string 画像URL
241 function getPhotoImageUrl($photoId)
243 return $this->gEnv->getResourceUrl() . self::PHOTO_IMAGE_DIR . '/' . $photoId . '.' . self::DEFAULT_PHOTO_IMAGE_EXT;