OSDN Git Service

初回コミット(v2.6.17.1)
[magic3/magic3.git] / widgets / image2 / include / container / image2WidgetContainer.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-2009 Magic3 Project.
12  * @license    http://www.gnu.org/copyleft/gpl.html  GPL License
13  * @version    SVN: $Id: image2WidgetContainer.php 2268 2009-08-31 03:29:18Z fishbone $
14  * @link       http://www.magic3.org
15  */
16 require_once($gEnvManager->getContainerPath() . '/baseWidgetContainer.php');
17 require_once($gEnvManager->getCurrentWidgetDbPath() . '/image2Db.php');
18
19 class image2WidgetContainer extends BaseWidgetContainer
20 {
21         private $db;                    // DB接続オブジェクト
22         private $langId;                // 現在の言語
23         private $paramObj;              // 定義取得用
24         private $headCss;                       // ヘッダ出力用CSS
25         const DEFAULT_CONFIG_ID = 0;
26         
27         /**
28          * コンストラクタ
29          */
30         function __construct()
31         {
32                 // 親クラスを呼び出す
33                 parent::__construct();
34                 
35                 // DBオブジェクト作成
36                 $this->db = new image2Db();
37         }
38         /**
39          * テンプレートファイルを設定
40          *
41          * _assign()でデータを埋め込むテンプレートファイルのファイル名を返す。
42          * 読み込むディレクトリは、「自ウィジェットディレクトリ/include/template」に固定。
43          *
44          * @param RequestManager $request               HTTPリクエスト処理クラス
45          * @param object         $param                 任意使用パラメータ。そのまま_assign()に渡る
46          * @return string                                               テンプレートファイル名。テンプレートライブラリを使用しない場合は空文字列「''」を返す。
47          */
48         function _setTemplate($request, &$param)
49         {
50                 return 'index.tmpl.html';
51         }
52         /**
53          * テンプレートにデータ埋め込む
54          *
55          * _setTemplate()で指定したテンプレートファイルにデータを埋め込む。
56          *
57          * @param RequestManager $request               HTTPリクエスト処理クラス
58          * @param object         $param                 任意使用パラメータ。_setTemplate()と共有。
59          * @param                                                               なし
60          */
61         function _assign($request, &$param)
62         {
63                 $this->langId = $this->gEnv->getCurrentLanguage();
64                 
65                 // 定義ID取得
66                 $configId = $this->gEnv->getCurrentWidgetConfigId();
67                 if (empty($configId)) $configId = self::DEFAULT_CONFIG_ID;
68                 
69                 // パラメータオブジェクトを取得
70                 $targetObj = $this->getWidgetParamObjByConfigId($configId);
71                 if (!empty($targetObj)){                // 定義データが取得できたとき
72                         $menuId         = $targetObj->menuId;   // メニューID
73                         $name           = $targetObj->name;// 定義名
74                         $imageUrl       = $targetObj->imageUrl;                                                 // 画像へのパス
75                         $linkUrl        = $targetObj->linkUrl;                  // リンク先
76                         $align          = $targetObj->align;                    // 表示位置
77                         $bgcolor        = $targetObj->bgcolor;          // 画像バックグランドカラー
78                         $width          = $targetObj->width;            // 画像の幅
79                         $height         = $targetObj->height;           // 画像の高さ
80                         $margin         = $targetObj->margin;           // 画像マージン
81                         $widthType      = $targetObj->widthType;                // 画像の幅単位
82                         $heightType     = $targetObj->heightType;               // 画像の高さ単位
83                         $posx           = $targetObj->posx;             // x座標
84                         $posy           = $targetObj->posy;             // y座標
85                         $posxType       = $targetObj->posxType;         // x座標単位
86                         $posyType       = $targetObj->posyType;         // y座標単位
87                         $posType        = $targetObj->posType;          // 座標指定方法(相対座標)
88                         $usePos         = $targetObj->usePos;                   // 座標指定を可能とするかどうか
89                         $useLink        = $targetObj->useLink;                  // 画像にリンクを付けるかどうか
90                                 
91                         // 画像のパスを修正
92                         if (!empty($imageUrl)){
93                                 $imageUrl = str_replace(M3_TAG_START . M3_TAG_MACRO_ROOT_URL . M3_TAG_END, $this->gEnv->getRootUrl(), $imageUrl);
94                         }
95                         if (!empty($imageUrl)){
96                                 // 外側のdivの設定
97                                 $divStyle = '';
98                                 if (!empty($align)){
99                                         $align = 'align="' . $align . '"';
100                                         $this->tmpl->addVar("_widget", "align", $align);
101                                 }
102                                 if (!empty($bgcolor)) $divStyle .= 'background:' . $bgcolor . ';';
103                                 $divStyle .= 'margin:0;';
104                                 if (!empty($divStyle)){
105                                         $divStyle = 'style="' . $divStyle . '"';
106                                         $this->tmpl->addVar("_widget", "div_style",     $divStyle);
107                                 }
108                         
109                                 // 画像
110                                 $imgStyle = 'border:0;';
111                                 $destImg = '<img src="' . $this->getUrl($imageUrl) . '"';
112
113                                 if ($width > 0){
114                                         $destImg .= ' width="' . $width;
115                                         if ($widthType == 0){
116                                                 $destImg .= '"';
117                                         } else {
118                                                 $destImg .= '%"';
119                                         }
120                                 }
121                                 if ($height > 0){
122                                         $destImg .= ' height="' . $height;
123                                         if ($heightType == 0){
124                                                 $destImg .= '"';
125                                         } else {
126                                                 $destImg .= '%"';
127                                         }
128                                 }
129                                 // マージン
130                                 if (!empty($margin)) $imgStyle .= 'margin:' . $margin . 'px;';
131                                 
132                                 // 座標
133                                 if ($usePos){
134                                         if ($posType == 'absolute'){
135                                                 $imgStyle .= 'position:absolute;';
136                                         } else {
137                                                 $imgStyle .= 'position:relative;';
138                                         }
139                                         $imgStyle .= 'left:' . $posx;
140                                         if ($posxType == 0){
141                                                 $imgStyle .= 'px;';
142                                         } else {
143                                                 $imgStyle .= '%;';
144                                         }
145                                         $imgStyle .= 'top:' . $posy;
146                                         if ($posyType == 0){
147                                                 $imgStyle .= 'px;';
148                                         } else {
149                                                 $imgStyle .= '%;';
150                                         }
151                                 }
152                         
153                                 if (!empty($imgStyle)){
154                                         $destImg .= ' style="'. $imgStyle . '"';
155                                 }
156                                 $destImg .= ' />';
157                         
158                                 if ($useLink){          // リンクありのとき
159                                         $destImg = '<a href="' . $this->convertUrlToHtmlEntity($linkUrl) . '">' . $destImg . '</a>';
160                                 }
161                                 $this->tmpl->addVar("_widget", "image", $destImg);
162                         }
163                 }
164         }
165 }
166 ?>