- Timestamp:
- 2013/08/26 15:52:37 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/version-2_13_0/data/class/helper/SC_Helper_PageLayout.php
r23069 r23126 23 23 24 24 /** 25 * Webページのレイアウト情報を制御するヘルパークラス. 25 * Webãã¼ã¸ã®ã¬ã¤ã¢ã¦ãæ 26 å ±ãå¶å¾¡ãããã«ãã¼ã¯ã©ã¹. 26 27 * 27 28 * @package Helper … … 32 33 { 33 34 /** 34 * ページのレイアウト情報を取得し, 設定する. 35 * 36 * 現在の URL に応じたページのレイアウト情報を取得し, LC_Page インスタンスに 37 * 設定する. 38 * 39 * @access public 40 * @param LC_Page $objPage LC_Page インスタンス 41 * @param boolean $preview プレビュー表示の場合 true 42 * @param string $url ページのURL($_SERVER['SCRIPT_NAME'] の情報) 43 * @param integer $device_type_id 端末種別ID 35 * ãã¼ã¸ã®ã¬ã¤ã¢ã¦ãæ 36 å ±ãåå¾ã, è¨å®ãã. 37 * 38 * ç¾å¨ã® URL ã«å¿ãããã¼ã¸ã®ã¬ã¤ã¢ã¦ãæ 39 å ±ãåå¾ã, LC_Page ã¤ã³ã¹ã¿ã³ã¹ã« 40 * è¨å®ãã. 41 * 42 * @access public 43 * @param LC_Page $objPage LC_Page ã¤ã³ã¹ã¿ã³ã¹ 44 * @param boolean $preview ãã¬ãã¥ã¼è¡¨ç¤ºã®å ´å true 45 * @param string $url ãã¼ã¸ã®URL($_SERVER['SCRIPT_NAME'] ã®æ 46 å ±) 47 * @param integer $device_type_id 端æ«ç¨®å¥ID 44 48 * @return void 45 49 */ 46 function sfGetPageLayout(&$objPage, $preview = false, $url = '', $device_type_id = DEVICE_TYPE_PC) 47 { 48 // URLを元にページ情報を取得 50 public function sfGetPageLayout(&$objPage, $preview = false, $url = '', $device_type_id = DEVICE_TYPE_PC) 51 { 52 // URLãå 53 ã«ãã¼ã¸æ 54 å ±ãåå¾ 49 55 if ($preview === false) { 50 56 $url = preg_replace('|^' . preg_quote(ROOT_URLPATH) . '|', '', $url); 51 57 $arrPageData = $this->getPageProperties($device_type_id, null, 'url = ?', array($url)); 52 58 } 53 // プレビューの場合は, プレビュー用のデータを取得59 // ãã¬ãã¥ã¼ã®å ´åã¯, ãã¬ãã¥ã¼ç¨ã®ãã¼ã¿ãåå¾ 54 60 else { 55 61 $arrPageData = $this->getPageProperties($device_type_id, 0); … … 57 63 58 64 if (empty($arrPageData[0])) { 59 trigger_error('ページ情報を取得できませんでした。', E_USER_ERROR); 65 trigger_error('ãã¼ã¸æ 66 å ±ãåå¾ã§ãã¾ããã§ããã', E_USER_ERROR); 60 67 } 61 68 … … 63 70 64 71 if (!file_exists($objPage->tpl_mainpage)) { 65 $msg = ' メイン部のテンプレートが存在しません。[' . $objPage->tpl_mainpage . ']';72 $msg = 'ã¡ã¤ã³é¨ã®ãã³ãã¬ã¼ããåå¨ãã¾ããã[' . $objPage->tpl_mainpage . ']'; 66 73 trigger_error($msg, E_USER_ERROR); 67 74 } … … 73 80 } 74 81 75 // ページタイトルを設定82 // ãã¼ã¸ã¿ã¤ãã«ãè¨å® 76 83 if (SC_Utils_Ex::isBlank($objPage->tpl_title)) { 77 84 $objPage->tpl_title = $objPage->arrPageLayout['page_name']; 78 85 } 79 86 80 // 該当ページのブロックを取得し, 配置する 87 // 該å½ãã¼ã¸ã®ãããã¯ãåå¾ã, é 88 ç½®ãã 81 89 $masterData = new SC_DB_MasterData_Ex(); 82 90 $arrTarget = $masterData->getMasterData('mtb_target'); 83 91 $arrBlocs = $this->getBlocPositions($device_type_id, $objPage->arrPageLayout['page_id']); 84 // 無効なプラグインのブロックを取り除く.92 // ç¡å¹ãªãã©ã°ã¤ã³ã®ãããã¯ãåãé¤ã. 85 93 $objPlugin = SC_Helper_Plugin_Ex::getSingletonInstance(); 86 94 $arrBlocs = $objPlugin->getEnableBlocs($arrBlocs); 87 // php_path, tpl_path が存在するものを, 各ターゲットに配置 95 // php_path, tpl_path ãåå¨ãããã®ã, åã¿ã¼ã²ããã«é 96 ç½® 88 97 foreach ($arrTarget as $target_id => $value) { 89 98 foreach ($arrBlocs as $arrBloc) { … … 95 104 $objPage->arrPageLayout[$arrTarget[$target_id]][] = $arrBloc; 96 105 } else { 97 $error = " ブロックが見つかりません\n"106 $error = "ãããã¯ãè¦ã¤ããã¾ãã\n" 98 107 . 'tpl_path: ' . $arrBloc['tpl_path'] . "\n" 99 108 . 'php_path: ' . $arrBloc['php_path']; … … 102 111 } 103 112 } 104 // カラム数を取得する113 // ã«ã©ã æ°ãåå¾ãã 105 114 $objPage->tpl_column_num = $this->getColumnNum($objPage->arrPageLayout); 106 115 } 107 116 108 117 /** 109 * ページの属性を取得する. 110 * 111 * この関数は, dtb_pagelayout の情報を検索する. 112 * $device_type_id は必須. デフォルト値は DEVICE_TYPE_PC. 113 * $page_id が null の場合は, $page_id が 0 以外のものを検索する. 114 * 115 * @access public 116 * @param integer $device_type_id 端末種別ID 117 * @param integer $page_id ページID; null の場合は, 0 以外を検索する. 118 * @param string $where 追加の検索条件 119 * @param array $arrParams 追加の検索パラメーター 120 * @return array ページ属性の配列 121 */ 122 function getPageProperties($device_type_id = DEVICE_TYPE_PC, $page_id = null, $where = '', $arrParams = array()) 118 * ãã¼ã¸ã®å±æ§ãåå¾ãã. 119 * 120 * ãã®é¢æ°ã¯, dtb_pagelayout ã®æ 121 å ±ãæ¤ç´¢ãã. 122 * $device_type_id ã¯å¿ 123 é . ããã©ã«ãå¤ã¯ DEVICE_TYPE_PC. 124 * $page_id ã null ã®å ´åã¯, $page_id ã 0 以å¤ã®ãã®ãæ¤ç´¢ãã. 125 * 126 * @access public 127 * @param integer $device_type_id 端æ«ç¨®å¥ID 128 * @param integer $page_id ãã¼ã¸ID; null ã®å ´åã¯, 0 以å¤ãæ¤ç´¢ãã. 129 * @param string $where 追å ã®æ¤ç´¢æ¡ä»¶ 130 * @param array $arrParams 追å ã®æ¤ç´¢ãã©ã¡ã¼ã¿ã¼ 131 * @return array ãã¼ã¸å±æ§ã®é 132 å 133 */ 134 public function getPageProperties($device_type_id = DEVICE_TYPE_PC, $page_id = null, $where = '', $arrParams = array()) 123 135 { 124 136 $objQuery =& SC_Query_Ex::getSingletonInstance(); … … 137 149 138 150 /** 139 * ブロック情報を取得する. 140 * 141 * @access public 142 * @param integer $device_type_id 端末種別ID 143 * @param string $where 追加の検索条件 144 * @param array $arrParams 追加の検索パラメーター 145 * @param boolean $has_realpath php_path, tpl_path の絶対パスを含める場合 true 146 * @return array ブロック情報の配列 147 */ 148 function getBlocs($device_type_id = DEVICE_TYPE_PC, $where = '', $arrParams = array(), $has_realpath = true) 151 * ãããã¯æ 152 å ±ãåå¾ãã. 153 * 154 * @access public 155 * @param integer $device_type_id 端æ«ç¨®å¥ID 156 * @param string $where 追å ã®æ¤ç´¢æ¡ä»¶ 157 * @param array $arrParams 追å ã®æ¤ç´¢ãã©ã¡ã¼ã¿ã¼ 158 * @param boolean $has_realpath php_path, tpl_path ã®çµ¶å¯¾ãã¹ãå«ããå ´å true 159 * @return array ãããã¯æ 160 å ±ã®é 161 å 162 */ 163 public function getBlocs($device_type_id = DEVICE_TYPE_PC, $where = '', $arrParams = array(), $has_realpath = true) 149 164 { 150 165 $objBloc = new SC_Helper_Bloc_Ex($device_type_id); … … 158 173 159 174 /** 160 * ブロック配置情報を取得する. 161 * 162 * @access public 163 * @param integer $device_type_id 端末種別ID 164 * @param integer $page_id ページID 165 * @param boolean $has_realpath php_path, tpl_path の絶対パスを含める場合 true 166 * @return array 配置情報を含めたブロックの配列 167 */ 168 function getBlocPositions($device_type_id, $page_id, $has_realpath = true) 175 * ãããã¯é 176 ç½®æ 177 å ±ãåå¾ãã. 178 * 179 * @access public 180 * @param integer $device_type_id 端æ«ç¨®å¥ID 181 * @param integer $page_id ãã¼ã¸ID 182 * @param boolean $has_realpath php_path, tpl_path ã®çµ¶å¯¾ãã¹ãå«ããå ´å true 183 * @return array é 184 ç½®æ 185 å ±ãå«ãããããã¯ã®é 186 å 187 */ 188 public function getBlocPositions($device_type_id, $page_id, $has_realpath = true) 169 189 { 170 190 $objQuery =& SC_Query_Ex::getSingletonInstance(); … … 183 203 } 184 204 185 //全ページ設定と各ページのブロックの重複を削除 205 //å 206 ¨ãã¼ã¸è¨å®ã¨åãã¼ã¸ã®ãããã¯ã®éè¤ãåé¤ 186 207 $arrUniqBlocIds = array(); 187 208 foreach ($arrBlocs as $index => $arrBloc) { 188 if ($arrBloc['anywhere'] == 1) {209 if ($arrBloc['anywhere'] == 1) { 189 210 $arrUniqBlocIds[] = $arrBloc['bloc_id']; 190 211 } 191 212 } 192 213 foreach ($arrBlocs as $bloc_index => $arrBlocData) { 193 if (in_array($arrBlocData['bloc_id'], $arrUniqBlocIds) && $arrBlocData['anywhere'] == 0) {214 if (in_array($arrBlocData['bloc_id'], $arrUniqBlocIds) && $arrBlocData['anywhere'] == 0) { 194 215 unset($arrBlocs[$bloc_index]); 195 216 } … … 200 221 201 222 /** 202 * ページ情報を削除する. 203 * 204 * XXX ファイルを確実に削除したかどうかのチェック 205 * 206 * @access public 207 * @param integer $page_id ページID 208 * @param integer $device_type_id 端末種別ID 209 * @return integer 削除数 210 */ 211 function lfDelPageData($page_id, $device_type_id = DEVICE_TYPE_PC) 223 * ãã¼ã¸æ 224 å ±ãåé¤ãã. 225 * 226 * XXX ãã¡ã¤ã«ã確å®ã«åé¤ãããã©ããã®ãã§ã㯠227 * 228 * @access public 229 * @param integer $page_id ãã¼ã¸ID 230 * @param integer $device_type_id 端æ«ç¨®å¥ID 231 * @return integer åé¤æ° 232 */ 233 public function lfDelPageData($page_id, $device_type_id = DEVICE_TYPE_PC) 212 234 { 213 235 $objQuery =& SC_Query_Ex::getSingletonInstance(); 214 // page_id が空でない場合にはdeleteを実行236 // page_id ã空ã§ãªãå ´åã«ã¯deleteãå®è¡ 215 237 if ($page_id != '') { 216 238 $arrPageData = $this->getPageProperties($device_type_id, $page_id); 217 239 $ret = $objQuery->delete('dtb_pagelayout', 'page_id = ? AND device_type_id = ?', array($page_id, $device_type_id)); 218 // ファイルの削除240 // ãã¡ã¤ã«ã®åé¤ 219 241 $this->lfDelFile($arrPageData[0]['filename'], $device_type_id); 220 242 } … … 224 246 225 247 /** 226 * ページのファイルを削除する.227 * 228 * dtb_pagelayout の削除後に呼び出すこと。248 * ãã¼ã¸ã®ãã¡ã¤ã«ãåé¤ãã. 249 * 250 * dtb_pagelayout ã®åé¤å¾ã«å¼ã³åºããã¨ã 229 251 * 230 252 * @access private 231 * @param string$filename232 * @param integer $device_type_id 端末種別ID233 * @return void // TODO boolean にするべき?234 */ 235 function lfDelFile($filename, $device_type_id)253 * @param string $filename 254 * @param integer $device_type_id 端æ«ç¨®å¥ID 255 * @return void // TODO boolean ã«ããã¹ã? 256 */ 257 public function lfDelFile($filename, $device_type_id) 236 258 { 237 259 $objQuery =& SC_Query_Ex::getSingletonInstance(); 238 260 239 261 /* 240 * 同名ファイルの使用件数 241 * PHP ファイルは, 複数のデバイスで共有するため, device_type_id を条件に入れない 262 * ååãã¡ã¤ã«ã®ä½¿ç¨ä»¶æ° 263 * PHP ãã¡ã¤ã«ã¯, è¤æ°ã®ããã¤ã¹ã§å 264 ±æãããã, device_type_id ãæ¡ä»¶ã«å 265 ¥ããªã 242 266 */ 243 267 $exists = $objQuery->exists('dtb_pagelayout', 'filename = ?', array($filename)); 244 268 245 269 if (!$exists) { 246 // php ファイルの削除270 // phpãã¡ã¤ã«ã®åé¤ 247 271 $del_php = HTML_REALDIR . $filename . '.php'; 248 272 if (file_exists($del_php)) { … … 251 275 } 252 276 253 // tpl ファイルの削除277 // tplãã¡ã¤ã«ã®åé¤ 254 278 $del_tpl = $this->getTemplatePath($device_type_id) . $filename . '.tpl'; 255 279 if (file_exists($del_tpl)) { … … 259 283 260 284 /** 261 * 編集可能ページかどうか.262 * 263 * @access public 264 * @param integer $device_type_id 端末種別ID265 * @param integer $page_id ページID266 * @return 編集可能ページの場合true267 */ 268 function isEditablePage($device_type_id, $page_id)285 * ç·¨éå¯è½ãã¼ã¸ãã©ãã. 286 * 287 * @access public 288 * @param integer $device_type_id 端æ«ç¨®å¥ID 289 * @param integer $page_id ãã¼ã¸ID 290 * @return ç·¨éå¯è½ãã¼ã¸ã®å ´å true 291 */ 292 public function isEditablePage($device_type_id, $page_id) 269 293 { 270 294 if ($page_id == 0) { … … 280 304 281 305 /** 282 * テンプレートのパスを取得する.283 * 284 * @access public 285 * @param integer $device_type_id 端末種別ID286 * @param boolean $isUser USER_REALDIR 以下のパスを返す場合true287 * @return string テンプレートのパス288 */ 289 function getTemplatePath($device_type_id = DEVICE_TYPE_PC, $isUser = false)306 * ãã³ãã¬ã¼ãã®ãã¹ãåå¾ãã. 307 * 308 * @access public 309 * @param integer $device_type_id 端æ«ç¨®å¥ID 310 * @param boolean $isUser USER_REALDIR 以ä¸ã®ãã¹ãè¿ãå ´å true 311 * @return string ãã³ãã¬ã¼ãã®ãã¹ 312 */ 313 public function getTemplatePath($device_type_id = DEVICE_TYPE_PC, $isUser = false) 290 314 { 291 315 $templateName = ''; … … 316 340 317 341 /** 318 * DocumentRoot から user_data のパスを取得する.319 * 320 * 引数 $hasPackage を true にした場合は, user_data/packages/template_name321 * を取得する.322 * 323 * @access public 324 * @param integer $device_type_id 端末種別ID325 * @param boolean $hasPackage パッケージのパスも含める場合true326 * @return string 端末に応じた DocumentRoot から user_data までのパス327 */ 328 function getUserDir($device_type_id = DEVICE_TYPE_PC, $hasPackage = false)342 * DocumentRoot ãã user_data ã®ãã¹ãåå¾ãã. 343 * 344 * å¼æ° $hasPackage ã true ã«ããå ´åã¯, user_data/packages/template_name 345 * ãåå¾ãã. 346 * 347 * @access public 348 * @param integer $device_type_id 端æ«ç¨®å¥ID 349 * @param boolean $hasPackage ããã±ã¼ã¸ã®ãã¹ãå«ããå ´å true 350 * @return string 端æ«ã«å¿ãã DocumentRoot ãã user_data ã¾ã§ã®ãã¹ 351 */ 352 public function getUserDir($device_type_id = DEVICE_TYPE_PC, $hasPackage = false) 329 353 { 330 354 switch ($device_type_id) { … … 350 374 351 375 /** 352 * ブロックの php_path, tpl_path を設定する.376 * ãããã¯ã® php_path, tpl_path ãè¨å®ãã. 353 377 * 354 378 * @access private 355 * @param integer $device_type_id 端末種別ID 356 * @param array $arrBlocs 設定するブロックの配列 379 * @param integer $device_type_id 端æ«ç¨®å¥ID 380 * @param array $arrBlocs è¨å®ãããããã¯ã®é 381 å 357 382 * @return void 358 383 */ 359 function setBlocPathTo($device_type_id = DEVICE_TYPE_PC, &$arrBlocs = array())384 public function setBlocPathTo($device_type_id = DEVICE_TYPE_PC, &$arrBlocs = array()) 360 385 { 361 386 foreach ($arrBlocs as $key => $value) { … … 368 393 369 394 /** 370 * カラム数を取得する.395 * ã«ã©ã æ°ãåå¾ãã. 371 396 * 372 397 * @access private 373 * @param array $arrPageLayout レイアウト情報の配列 374 * @return integer $col_num カラム数 375 */ 376 function getColumnNum($arrPageLayout) 377 { 378 // メインは確定 398 * @param array $arrPageLayout ã¬ã¤ã¢ã¦ãæ 399 å ±ã®é 400 å 401 * @return integer $col_num ã«ã©ã æ° 402 */ 403 public function getColumnNum($arrPageLayout) 404 { 405 // ã¡ã¤ã³ã¯ç¢ºå® 379 406 $col_num = 1; 380 407 // LEFT NAVI … … 382 409 // RIGHT NAVI 383 410 if (count($arrPageLayout['RightNavi']) > 0) $col_num++; 384 385 411 return $col_num; 386 412 }
Note: See TracChangeset
for help on using the changeset viewer.