[16430] | 1 | <?php |
---|
| 2 | /* |
---|
[16582] | 3 | * This file is part of EC-CUBE |
---|
| 4 | * |
---|
[16430] | 5 | * Copyright(c) 2000-2007 LOCKON CO.,LTD. All Rights Reserved. |
---|
| 6 | * |
---|
| 7 | * http://www.lockon.co.jp/ |
---|
[16582] | 8 | * |
---|
| 9 | * This program is free software; you can redistribute it and/or |
---|
| 10 | * modify it under the terms of the GNU General Public License |
---|
| 11 | * as published by the Free Software Foundation; either version 2 |
---|
| 12 | * of the License, or (at your option) any later version. |
---|
| 13 | * |
---|
| 14 | * This program is distributed in the hope that it will be useful, |
---|
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 17 | * GNU General Public License for more details. |
---|
| 18 | * |
---|
| 19 | * You should have received a copy of the GNU General Public License |
---|
| 20 | * along with this program; if not, write to the Free Software |
---|
| 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
---|
[16430] | 22 | */ |
---|
| 23 | |
---|
| 24 | // {{{ requires |
---|
| 25 | require_once(CLASS_PATH . "pages/LC_Page.php"); |
---|
| 26 | require_once(DATA_PATH . "module/Tar.php"); |
---|
[16682] | 27 | require_once(CLASS_EX_PATH . "helper_extends/SC_Helper_FileManager_Ex.php"); |
---|
[16430] | 28 | |
---|
| 29 | /** |
---|
| 30 | * テンプレート設定 のページクラス. |
---|
| 31 | * |
---|
| 32 | * @package Page |
---|
| 33 | * @author LOCKON CO.,LTD. |
---|
| 34 | * @version $Id$ |
---|
| 35 | */ |
---|
| 36 | class LC_Page_Admin_Design_Template extends LC_Page { |
---|
| 37 | |
---|
| 38 | // }}} |
---|
| 39 | // {{{ functions |
---|
| 40 | |
---|
| 41 | /** テンプレートデータ種別 */ |
---|
| 42 | var $arrSubnavi = array( |
---|
| 43 | 'title' => array( |
---|
| 44 | 1 => 'top', |
---|
| 45 | 2 => 'product', |
---|
| 46 | 3 => 'detail', |
---|
| 47 | 4 => 'mypage' |
---|
| 48 | ), |
---|
| 49 | 'name' =>array( |
---|
| 50 | 1 => 'TOPページ', |
---|
| 51 | 2 => '商品一覧ページ', |
---|
| 52 | 3 => '商品詳細ページ', |
---|
| 53 | 4 => 'MYページ' |
---|
| 54 | ) |
---|
| 55 | ); |
---|
| 56 | |
---|
| 57 | /** |
---|
| 58 | * Page を初期化する. |
---|
| 59 | * |
---|
| 60 | * @return void |
---|
| 61 | */ |
---|
| 62 | function init() { |
---|
| 63 | parent::init(); |
---|
[16677] | 64 | $this->tpl_mainpage = 'design/template.tpl'; |
---|
| 65 | $this->tpl_subnavi = 'design/subnavi.tpl'; |
---|
| 66 | $this->tpl_subno = 'template'; |
---|
| 67 | $this->tpl_mainno = "design"; |
---|
| 68 | $this->tpl_subtitle = 'テンプレート設定'; |
---|
| 69 | $this->arrErr = array(); |
---|
| 70 | $this->arrForm = array(); |
---|
[16716] | 71 | $this->tpl_select = DEFAULT_TEMPLATE_NAME; |
---|
[16682] | 72 | ini_set("max_execution_time", 300); |
---|
[16430] | 73 | } |
---|
| 74 | |
---|
| 75 | /** |
---|
| 76 | * Page のプロセス. |
---|
| 77 | * |
---|
| 78 | * @return void |
---|
| 79 | */ |
---|
| 80 | function process() { |
---|
[16677] | 81 | // 認証可否の判定 |
---|
| 82 | $objSession = new SC_Session(); |
---|
| 83 | SC_Utils::sfIsSuccess($objSession); |
---|
[16768] | 84 | |
---|
[16677] | 85 | // uniqidをテンプレートへ埋め込み |
---|
| 86 | $this->uniqid = $objSession->getUniqId(); |
---|
[16768] | 87 | |
---|
[16677] | 88 | $objView = new SC_AdminView(); |
---|
[16768] | 89 | |
---|
[16677] | 90 | switch($this->lfGetMode()) { |
---|
[16768] | 91 | |
---|
[16677] | 92 | // 登録ボタン押下時 |
---|
| 93 | case 'register': |
---|
| 94 | // 画面遷移の正当性チェック |
---|
| 95 | if (!SC_Utils::sfIsValidTransition($objSession)) { |
---|
| 96 | sfDispError(''); |
---|
| 97 | } |
---|
| 98 | // パラメータ検証 |
---|
| 99 | $objForm = $this->lfInitRegister(); |
---|
| 100 | if ($objForm->checkError()) { |
---|
[16769] | 101 | SC_Utils_Ex::sfDispError(''); |
---|
[16677] | 102 | } |
---|
[16768] | 103 | |
---|
[16677] | 104 | $template_code = $objForm->getValue('template_code'); |
---|
[16716] | 105 | $this->tpl_select = $template_code; |
---|
[16768] | 106 | |
---|
[16680] | 107 | if($template_code == "") { |
---|
| 108 | $template_code = "default"; |
---|
[16677] | 109 | } |
---|
[16768] | 110 | |
---|
[16677] | 111 | // DBへ使用するテンプレートを登録 |
---|
| 112 | $this->lfRegisterTemplate($template_code); |
---|
[16768] | 113 | |
---|
[16677] | 114 | // XXX コンパイルファイルのクリア処理を行う |
---|
| 115 | $objView->_smarty->clear_compiled_tpl(); |
---|
[16768] | 116 | |
---|
[17193] | 117 | // common.cssの内容を更新 |
---|
| 118 | $this->lfChangeCommonCss($template_code); |
---|
| 119 | |
---|
[17136] | 120 | // ブロック位置を更新 |
---|
| 121 | $this->lfChangeBloc($template_code); |
---|
| 122 | |
---|
[16677] | 123 | // 完了メッセージ |
---|
| 124 | $this->tpl_onload="alert('登録が完了しました。');"; |
---|
| 125 | break; |
---|
[16768] | 126 | |
---|
[16677] | 127 | // 削除ボタン押下時 |
---|
| 128 | case 'delete': |
---|
| 129 | // 画面遷移の正当性チェック |
---|
[16680] | 130 | if (!SC_Utils::sfIsValidTransition($objSession)) { |
---|
| 131 | SC_Utils::sfDispError(''); |
---|
[16677] | 132 | } |
---|
| 133 | // パラメータ検証 |
---|
| 134 | $objForm = $this->lfInitDelete(); |
---|
| 135 | if ($objForm->checkError()) { |
---|
[16680] | 136 | SC_Utils::sfDispError(''); |
---|
[16677] | 137 | } |
---|
[16768] | 138 | |
---|
[16680] | 139 | $template_code = $objForm->getValue('template_code_temp'); |
---|
[16677] | 140 | if ($template_code == $this->lfGetNowTemplate()) { |
---|
| 141 | $this->tpl_onload = "alert('選択中のテンプレートは削除出来ません');"; |
---|
| 142 | break; |
---|
| 143 | } |
---|
[16768] | 144 | |
---|
[16677] | 145 | $this->lfDeleteTemplate($template_code); |
---|
| 146 | break; |
---|
[16768] | 147 | |
---|
[16680] | 148 | // downloadボタン押下時 |
---|
| 149 | case 'download': |
---|
| 150 | // 画面遷移の正当性チェック |
---|
| 151 | if (!SC_Utils::sfIsValidTransition($objSession)) { |
---|
| 152 | SC_Utils::sfDispError(''); |
---|
| 153 | } |
---|
| 154 | // パラメータ検証 |
---|
| 155 | $objForm = $this->lfInitDownload(); |
---|
| 156 | $template_code = $objForm->getValue('template_code_temp'); |
---|
| 157 | // ユーザデータの下のファイルも保存する。 |
---|
[16703] | 158 | $from_dir = USER_TEMPLATE_PATH . $template_code . "/"; |
---|
| 159 | $to_dir = SMARTY_TEMPLATES_DIR . $template_code . "/_packages/"; |
---|
| 160 | SC_Utils::sfMakeDir($to_dir); |
---|
| 161 | SC_Utils::sfCopyDir($from_dir, $to_dir); |
---|
[16682] | 162 | SC_Helper_FileManager::downloadArchiveFiles(SMARTY_TEMPLATES_DIR . $template_code); |
---|
[16680] | 163 | break; |
---|
[16768] | 164 | |
---|
[16677] | 165 | // プレビューボタン押下時 |
---|
| 166 | case 'preview': |
---|
| 167 | break; |
---|
[16768] | 168 | |
---|
[16677] | 169 | default: |
---|
| 170 | break; |
---|
| 171 | } |
---|
[16768] | 172 | |
---|
[16677] | 173 | // defaultパラメータのセット |
---|
| 174 | $this->templates = $this->lfGetAllTemplates(); |
---|
| 175 | $this->now_template = $this->lfGetNowtemplate(); |
---|
[16768] | 176 | |
---|
[16677] | 177 | // 画面の表示 |
---|
| 178 | $objView->assignobj($this); |
---|
| 179 | $objView->display(MAIN_FRAME); |
---|
[16430] | 180 | } |
---|
| 181 | |
---|
| 182 | /** |
---|
| 183 | * デストラクタ. |
---|
| 184 | * |
---|
| 185 | * @return void |
---|
| 186 | */ |
---|
| 187 | function destroy() { |
---|
| 188 | parent::destroy(); |
---|
| 189 | } |
---|
| 190 | |
---|
[16677] | 191 | function lfGetMode(){ |
---|
| 192 | if (isset($_POST['mode'])) return $_POST['mode']; |
---|
| 193 | } |
---|
[16768] | 194 | |
---|
[16677] | 195 | function lfInitRegister() { |
---|
| 196 | $objForm = new SC_FormParam(); |
---|
| 197 | $objForm->addParam( |
---|
| 198 | 'template_code', 'template_code', STEXT_LEN, '', |
---|
| 199 | array("EXIST_CHECK","SPTAB_CHECK","MAX_LENGTH_CHECK", "ALNUM_CHECK") |
---|
| 200 | ); |
---|
| 201 | $objForm->setParam($_POST); |
---|
[16768] | 202 | |
---|
[16677] | 203 | return $objForm; |
---|
| 204 | } |
---|
[16768] | 205 | |
---|
[16677] | 206 | function lfInitDelete() { |
---|
| 207 | $objForm = new SC_FormParam(); |
---|
| 208 | $objForm->addParam( |
---|
[16680] | 209 | 'template_code_temp', 'template_code_temp', STEXT_LEN, '', |
---|
[16677] | 210 | array("EXIST_CHECK","SPTAB_CHECK","MAX_LENGTH_CHECK", "ALNUM_CHECK") |
---|
| 211 | ); |
---|
| 212 | $objForm->setParam($_POST); |
---|
[16768] | 213 | |
---|
[16680] | 214 | return $objForm; |
---|
| 215 | } |
---|
[16768] | 216 | |
---|
[16680] | 217 | function lfInitDownload() { |
---|
| 218 | $objForm = new SC_FormParam(); |
---|
| 219 | $objForm->addParam( |
---|
| 220 | 'template_code_temp', 'template_code_temp', STEXT_LEN, '', |
---|
| 221 | array("EXIST_CHECK","SPTAB_CHECK","MAX_LENGTH_CHECK", "ALNUM_CHECK") |
---|
| 222 | ); |
---|
| 223 | $objForm->setParam($_POST); |
---|
[16768] | 224 | |
---|
[16677] | 225 | return $objForm; |
---|
| 226 | } |
---|
[16768] | 227 | |
---|
[16677] | 228 | /** |
---|
| 229 | * 現在適用しているテンプレートパッケージ名を取得する. |
---|
| 230 | * |
---|
| 231 | * @param void |
---|
| 232 | * @return string テンプレートパッケージ名 |
---|
| 233 | */ |
---|
| 234 | function lfGetNowTemplate() { |
---|
| 235 | $objQuery = new SC_Query(); |
---|
| 236 | $arrRet = $objQuery->select('top_tpl', 'dtb_baseinfo'); |
---|
| 237 | if (isset($arrRet[0]['top_tpl'])) { |
---|
| 238 | return $arrRet[0]['top_tpl']; |
---|
| 239 | } |
---|
| 240 | return null; |
---|
| 241 | } |
---|
[16768] | 242 | |
---|
[16677] | 243 | /** |
---|
| 244 | * 使用するテンプレートをDBへ登録する |
---|
| 245 | */ |
---|
| 246 | function lfRegisterTemplate($template_code) { |
---|
| 247 | $objQuery = new SC_Query(); |
---|
[16680] | 248 | $sqlval['name'] = "\"" . $template_code . "\""; |
---|
| 249 | $objQuery->update("mtb_constants", $sqlval, "id = ?", array('DEFAULT_TEMPLATE_NAME')); |
---|
| 250 | // キャッシュを生成 |
---|
| 251 | $masterData = new SC_DB_MasterData_Ex(); |
---|
| 252 | // 更新したデータを取得 |
---|
| 253 | $mtb_constants = $masterData->getDBMasterData("mtb_constants"); |
---|
| 254 | $masterData->clearCache("mtb_constants"); |
---|
| 255 | $masterData->createCache("mtb_constants", $mtb_constants, true, |
---|
| 256 | array("id", "remarks", "rank")); |
---|
[16677] | 257 | } |
---|
[17136] | 258 | |
---|
[16677] | 259 | /** |
---|
[17193] | 260 | * common.cssの更新 |
---|
| 261 | */ |
---|
| 262 | function lfChangeCommonCss($template_code) { |
---|
| 263 | $css_path = USER_PATH . "css/common.css"; |
---|
| 264 | |
---|
| 265 | // ファイル内容取得 |
---|
| 266 | $css_data = file_get_contents($css_path); |
---|
| 267 | |
---|
| 268 | // ファイル内容更新 |
---|
| 269 | $pt = '/(@import url\("\.\.\/packages\/.+\/css\/import\.css"\);)/'; |
---|
| 270 | $rp = '@import url("../packages/'. $template_code. '/css/import.css");'; |
---|
| 271 | $css = preg_replace($pt, $rp, $css_data); |
---|
| 272 | |
---|
| 273 | // ファイル更新 |
---|
| 274 | $fp = fopen($css_path,"w"); |
---|
| 275 | fwrite($fp, $css); |
---|
| 276 | fclose($fp); |
---|
| 277 | } |
---|
| 278 | |
---|
| 279 | /** |
---|
[17136] | 280 | * ブロック位置の更新 |
---|
[16677] | 281 | */ |
---|
[17136] | 282 | function lfChangeBloc($template_code) { |
---|
| 283 | $objQuery = new SC_Query(); |
---|
| 284 | $filepath = USER_TEMPLATE_PATH. $template_code. "/sql/update_bloc.sql"; |
---|
| 285 | |
---|
| 286 | // ブロック位置更新SQLファイル有 |
---|
| 287 | if(file_exists($filepath)) { |
---|
| 288 | if($fp = fopen($filepath, "r")) { |
---|
| 289 | $sql = fread($fp, filesize($filepath)); |
---|
| 290 | fclose($fp); |
---|
| 291 | } |
---|
| 292 | // 改行、タブを1スペースに変換 |
---|
| 293 | $sql = preg_replace("/[\r\n\t]/", " " ,$sql); |
---|
| 294 | $sql_split = split(";", $sql); |
---|
| 295 | foreach($sql_split as $key => $val){ |
---|
| 296 | if (trim($val) != "") { |
---|
| 297 | $objQuery->query($val); |
---|
| 298 | } |
---|
| 299 | } |
---|
[16677] | 300 | } |
---|
| 301 | } |
---|
[16768] | 302 | |
---|
[17136] | 303 | /** |
---|
| 304 | * テンプレートパッケージの削除 |
---|
| 305 | */ |
---|
| 306 | function lfDeleteTemplate($template_code) { |
---|
| 307 | // DB更新 |
---|
| 308 | $objQuery = new SC_Query(); |
---|
| 309 | $objQuery->delete('dtb_templates', 'template_code = ?', array($template_code)); |
---|
| 310 | // テンプレート削除 |
---|
| 311 | $templates_dir = SMARTY_TEMPLATES_DIR. $template_code. "/"; |
---|
| 312 | SC_Utils_Ex::sfDelFile($templates_dir); |
---|
| 313 | // ユーザーデータ削除 |
---|
| 314 | $user_dir = USER_TEMPLATE_PATH. $template_code. "/"; |
---|
| 315 | SC_Utils_Ex::sfDelFile($user_dir); |
---|
| 316 | } |
---|
| 317 | |
---|
[16677] | 318 | function lfGetAllTemplates() { |
---|
| 319 | $objQuery = new SC_Query(); |
---|
| 320 | $arrRet = $objQuery->select('*', 'dtb_templates'); |
---|
| 321 | if (empty($arrRet)) return array(); |
---|
[16768] | 322 | |
---|
[16677] | 323 | return $arrRet; |
---|
| 324 | } |
---|
[16430] | 325 | } |
---|
| 326 | ?> |
---|