[16430] | 1 | <?php |
---|
| 2 | /* |
---|
[16582] | 3 | * This file is part of EC-CUBE |
---|
| 4 | * |
---|
[18701] | 5 | * Copyright(c) 2000-2010 LOCKON CO.,LTD. All Rights Reserved. |
---|
[16430] | 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 |
---|
[19805] | 25 | require_once(CLASS_REALDIR . "pages/admin/LC_Page_Admin.php"); |
---|
| 26 | require_once(DATA_REALDIR . "module/Tar.php"); |
---|
| 27 | require_once(CLASS_EX_REALDIR . "helper_extends/SC_Helper_FileManager_Ex.php"); |
---|
[16430] | 28 | |
---|
| 29 | /** |
---|
| 30 | * テンプレート設定 のページクラス. |
---|
| 31 | * |
---|
| 32 | * @package Page |
---|
| 33 | * @author LOCKON CO.,LTD. |
---|
| 34 | * @version $Id$ |
---|
| 35 | */ |
---|
[19661] | 36 | class LC_Page_Admin_Design_Template extends LC_Page_Admin { |
---|
[16430] | 37 | |
---|
| 38 | // }}} |
---|
| 39 | // {{{ functions |
---|
| 40 | |
---|
| 41 | /** |
---|
| 42 | * Page を初期化する. |
---|
| 43 | * |
---|
| 44 | * @return void |
---|
| 45 | */ |
---|
| 46 | function init() { |
---|
| 47 | parent::init(); |
---|
[19725] | 48 | $this->tpl_mainpage = 'design/template.tpl'; |
---|
| 49 | $this->tpl_subnavi = 'design/subnavi.tpl'; |
---|
| 50 | $this->tpl_subno = 'template'; |
---|
| 51 | $this->tpl_mainno = "design"; |
---|
| 52 | $this->tpl_subtitle = 'テンプレート設定'; |
---|
| 53 | $this->arrErr = array(); |
---|
| 54 | $this->arrForm = array(); |
---|
| 55 | $this->tpl_select = TEMPLATE_NAME; |
---|
| 56 | ini_set("max_execution_time", 300); |
---|
[16430] | 57 | } |
---|
| 58 | |
---|
| 59 | /** |
---|
| 60 | * Page のプロセス. |
---|
| 61 | * |
---|
| 62 | * @return void |
---|
| 63 | */ |
---|
| 64 | function process() { |
---|
[19661] | 65 | $this->action(); |
---|
| 66 | $this->sendResponse(); |
---|
| 67 | } |
---|
[16768] | 68 | |
---|
[19661] | 69 | /** |
---|
| 70 | * Page のアクション. |
---|
| 71 | * |
---|
[19713] | 72 | * FIXME ロジックを見直し |
---|
| 73 | * |
---|
[19661] | 74 | * @return void |
---|
| 75 | */ |
---|
| 76 | function action() { |
---|
| 77 | // 認証可否の判定 |
---|
[19725] | 78 | $objSession = new SC_Session(); |
---|
| 79 | SC_Utils::sfIsSuccess($objSession); |
---|
[16768] | 80 | |
---|
[19725] | 81 | // uniqidをテンプレートへ埋め込み |
---|
| 82 | $this->uniqid = $objSession->getUniqId(); |
---|
[16768] | 83 | |
---|
[19725] | 84 | $objView = new SC_AdminView(); |
---|
[16768] | 85 | |
---|
[19725] | 86 | switch($this->lfGetMode()) { |
---|
[16768] | 87 | |
---|
[19725] | 88 | // 登録ボタン押下時 |
---|
| 89 | case 'register': |
---|
| 90 | // 画面遷移の正当性チェック |
---|
| 91 | if (!SC_Utils::sfIsValidTransition($objSession)) { |
---|
| 92 | sfDispError(''); |
---|
| 93 | } |
---|
| 94 | // パラメータ検証 |
---|
| 95 | $objForm = $this->lfInitRegister(); |
---|
| 96 | if ($objForm->checkError()) { |
---|
| 97 | SC_Utils_Ex::sfDispError(''); |
---|
| 98 | } |
---|
[16768] | 99 | |
---|
[19725] | 100 | $template_code = $objForm->getValue('template_code'); |
---|
[19661] | 101 | $this->tpl_select = $template_code; |
---|
[16768] | 102 | |
---|
[19725] | 103 | if($template_code == "") { |
---|
| 104 | $template_code = "default"; |
---|
| 105 | } |
---|
[16768] | 106 | |
---|
[19725] | 107 | // DBへ使用するテンプレートを登録 |
---|
| 108 | $this->lfRegisterTemplate($template_code); |
---|
[16768] | 109 | |
---|
[19725] | 110 | // XXX コンパイルファイルのクリア処理を行う |
---|
| 111 | $objView->_smarty->clear_compiled_tpl(); |
---|
[19628] | 112 | |
---|
[19725] | 113 | // common.cssの内容を更新 |
---|
| 114 | $this->lfChangeCommonCss($template_code); |
---|
| 115 | |
---|
| 116 | // テンプレートのコピー |
---|
| 117 | $this->lfCopyTemplate($template_code); |
---|
| 118 | |
---|
| 119 | // ブロック位置を更新 |
---|
| 120 | $this->lfChangeBloc($template_code); |
---|
[17136] | 121 | |
---|
[19725] | 122 | // 完了メッセージ |
---|
| 123 | $this->tpl_onload="alert('登録が完了しました。');"; |
---|
| 124 | break; |
---|
[16768] | 125 | |
---|
[19725] | 126 | // 削除ボタン押下時 |
---|
| 127 | case 'delete': |
---|
| 128 | // 画面遷移の正当性チェック |
---|
| 129 | if (!SC_Utils::sfIsValidTransition($objSession)) { |
---|
| 130 | SC_Utils::sfDispError(''); |
---|
| 131 | } |
---|
| 132 | // パラメータ検証 |
---|
| 133 | $objForm = $this->lfInitDelete(); |
---|
| 134 | if ($objForm->checkError()) { |
---|
| 135 | SC_Utils::sfDispError(''); |
---|
| 136 | } |
---|
| 137 | |
---|
| 138 | //現在使用中のテンプレートとデフォルトのテンプレートは削除できないようにする |
---|
| 139 | $template_code = $objForm->getValue('template_code_temp'); |
---|
| 140 | if ($template_code == TEMPLATE_NAME || $template_code == DEFAULT_TEMPLATE_NAME) { |
---|
| 141 | $this->tpl_onload = "alert('選択中のテンプレートは削除出来ません');"; |
---|
| 142 | break; |
---|
| 143 | } |
---|
| 144 | $this->lfDeleteTemplate($template_code); |
---|
| 145 | break; |
---|
[16768] | 146 | |
---|
[19725] | 147 | // downloadボタン押下時 |
---|
| 148 | case 'download': |
---|
| 149 | // 画面遷移の正当性チェック |
---|
| 150 | if (!SC_Utils::sfIsValidTransition($objSession)) { |
---|
| 151 | SC_Utils::sfDispError(''); |
---|
| 152 | } |
---|
| 153 | // パラメータ検証 |
---|
| 154 | $objForm = $this->lfInitDownload(); |
---|
| 155 | $template_code = $objForm->getValue('template_code_temp'); |
---|
| 156 | // ユーザデータの下のファイルも保存する。 |
---|
[19807] | 157 | $from_dir = USER_TEMPLATE_REALDIR . $template_code . "/"; |
---|
[19805] | 158 | $to_dir = SMARTY_TEMPLATES_REALDIR . $template_code . "/_packages/"; |
---|
[19725] | 159 | SC_Utils::sfMakeDir($to_dir); |
---|
| 160 | SC_Utils::sfCopyDir($from_dir, $to_dir); |
---|
[19805] | 161 | SC_Helper_FileManager::downloadArchiveFiles(SMARTY_TEMPLATES_REALDIR . $template_code); |
---|
[19725] | 162 | break; |
---|
[16768] | 163 | |
---|
[19725] | 164 | // プレビューボタン押下時 |
---|
| 165 | case 'preview': |
---|
| 166 | break; |
---|
[16768] | 167 | |
---|
[19725] | 168 | default: |
---|
| 169 | break; |
---|
| 170 | } |
---|
[16768] | 171 | |
---|
[19725] | 172 | // defaultパラメータのセット |
---|
| 173 | $this->templates = $this->lfGetAllTemplates(); |
---|
| 174 | $this->now_template = TEMPLATE_NAME; |
---|
[19722] | 175 | $this->device_type_id = $device_type_id; |
---|
[16430] | 176 | } |
---|
| 177 | |
---|
| 178 | /** |
---|
| 179 | * デストラクタ. |
---|
| 180 | * |
---|
| 181 | * @return void |
---|
| 182 | */ |
---|
| 183 | function destroy() { |
---|
| 184 | parent::destroy(); |
---|
| 185 | } |
---|
| 186 | |
---|
[19725] | 187 | function lfGetMode(){ |
---|
| 188 | if (isset($_POST['mode'])) return $_POST['mode']; |
---|
| 189 | } |
---|
[16768] | 190 | |
---|
[19725] | 191 | function lfInitRegister() { |
---|
| 192 | $objForm = new SC_FormParam(); |
---|
| 193 | $objForm->addParam( |
---|
| 194 | 'template_code', 'template_code', STEXT_LEN, '', |
---|
| 195 | array("EXIST_CHECK","SPTAB_CHECK","MAX_LENGTH_CHECK", "ALNUM_CHECK") |
---|
| 196 | ); |
---|
| 197 | $objForm->setParam($_POST); |
---|
[16768] | 198 | |
---|
[19725] | 199 | return $objForm; |
---|
| 200 | } |
---|
[16768] | 201 | |
---|
[19725] | 202 | function lfInitDelete() { |
---|
| 203 | $objForm = new SC_FormParam(); |
---|
| 204 | $objForm->addParam( |
---|
| 205 | 'template_code_temp', 'template_code_temp', STEXT_LEN, '', |
---|
| 206 | array("EXIST_CHECK","SPTAB_CHECK","MAX_LENGTH_CHECK", "ALNUM_CHECK") |
---|
| 207 | ); |
---|
| 208 | $objForm->setParam($_POST); |
---|
[16768] | 209 | |
---|
[19725] | 210 | return $objForm; |
---|
| 211 | } |
---|
[16768] | 212 | |
---|
[19725] | 213 | function lfInitDownload() { |
---|
| 214 | $objForm = new SC_FormParam(); |
---|
| 215 | $objForm->addParam( |
---|
| 216 | 'template_code_temp', 'template_code_temp', STEXT_LEN, '', |
---|
| 217 | array("EXIST_CHECK","SPTAB_CHECK","MAX_LENGTH_CHECK", "ALNUM_CHECK") |
---|
| 218 | ); |
---|
| 219 | $objForm->setParam($_POST); |
---|
[16768] | 220 | |
---|
[19725] | 221 | return $objForm; |
---|
| 222 | } |
---|
[16768] | 223 | |
---|
[18571] | 224 | /** |
---|
| 225 | * 使用するテンプレートをDBへ登録する |
---|
| 226 | */ |
---|
| 227 | function lfRegisterTemplate($template_code) { |
---|
| 228 | $masterData = new SC_DB_MasterData_Ex(); |
---|
[17136] | 229 | |
---|
[18571] | 230 | $data = array('TEMPLATE_NAME' => var_export($template_code, TRUE)); |
---|
| 231 | |
---|
| 232 | // DBのデータを更新 |
---|
| 233 | $masterData->updateMasterData('mtb_constants', array(), $data); |
---|
| 234 | |
---|
| 235 | // キャッシュを生成 |
---|
| 236 | $masterData->createCache('mtb_constants', array(), true, array('id', 'remarks')); |
---|
| 237 | } |
---|
| 238 | |
---|
[19725] | 239 | /** |
---|
| 240 | * common.cssの更新 |
---|
| 241 | */ |
---|
[17193] | 242 | function lfChangeCommonCss($template_code) { |
---|
[19805] | 243 | $css_path = USER_REALDIR . "css/common.css"; |
---|
[17193] | 244 | |
---|
| 245 | // ファイル内容取得 |
---|
| 246 | $css_data = file_get_contents($css_path); |
---|
| 247 | |
---|
| 248 | // ファイル内容更新 |
---|
| 249 | $pt = '/(@import url\("\.\.\/packages\/.+\/css\/import\.css"\);)/'; |
---|
| 250 | $rp = '@import url("../packages/'. $template_code. '/css/import.css");'; |
---|
| 251 | $css = preg_replace($pt, $rp, $css_data); |
---|
| 252 | |
---|
| 253 | // ファイル更新 |
---|
| 254 | $fp = fopen($css_path,"w"); |
---|
| 255 | fwrite($fp, $css); |
---|
| 256 | fclose($fp); |
---|
| 257 | } |
---|
[19725] | 258 | |
---|
| 259 | /** |
---|
| 260 | * ブロック位置の更新 |
---|
| 261 | */ |
---|
| 262 | function lfChangeBloc($template_code) { |
---|
| 263 | $objQuery = new SC_Query(); |
---|
[19807] | 264 | $filepath = USER_TEMPLATE_REALDIR. $template_code. "/sql/update_bloc.sql"; |
---|
[19725] | 265 | |
---|
| 266 | // ブロック位置更新SQLファイル有 |
---|
| 267 | if(file_exists($filepath)) { |
---|
| 268 | if($fp = fopen($filepath, "r")) { |
---|
| 269 | $sql = fread($fp, filesize($filepath)); |
---|
| 270 | fclose($fp); |
---|
| 271 | } |
---|
| 272 | // 改行、タブを1スペースに変換 |
---|
| 273 | $sql = preg_replace("/[\r\n\t]/", " " ,$sql); |
---|
| 274 | $sql_split = split(";", $sql); |
---|
| 275 | foreach($sql_split as $key => $val){ |
---|
| 276 | if (trim($val) != "") { |
---|
| 277 | $objQuery->query($val); |
---|
| 278 | } |
---|
| 279 | } |
---|
| 280 | } |
---|
| 281 | } |
---|
[16768] | 282 | |
---|
[19725] | 283 | /** |
---|
| 284 | * テンプレートパッケージの削除 |
---|
| 285 | */ |
---|
| 286 | function lfDeleteTemplate($template_code) { |
---|
| 287 | // DB更新 |
---|
| 288 | $objQuery = new SC_Query(); |
---|
| 289 | $objQuery->delete('dtb_templates', 'template_code = ?', array($template_code)); |
---|
| 290 | // テンプレート削除 |
---|
[19805] | 291 | $templates_dir = SMARTY_TEMPLATES_REALDIR. $template_code. "/"; |
---|
[19725] | 292 | SC_Utils_Ex::sfDelFile($templates_dir); |
---|
| 293 | // コンパイル削除 |
---|
[19805] | 294 | $templates_c_dir = DATA_REALDIR. "Smarty/templates_c/". $template_code. "/"; |
---|
[19725] | 295 | SC_Utils_Ex::sfDelFile($templates_c_dir); |
---|
| 296 | // ユーザーデータ削除 |
---|
[19807] | 297 | $user_dir = USER_TEMPLATE_REALDIR. $template_code. "/"; |
---|
[19725] | 298 | SC_Utils_Ex::sfDelFile($user_dir); |
---|
| 299 | } |
---|
[17136] | 300 | |
---|
[19725] | 301 | function lfGetAllTemplates() { |
---|
| 302 | $objQuery = new SC_Query(); |
---|
| 303 | $arrRet = $objQuery->select('*', 'dtb_templates'); |
---|
| 304 | if (empty($arrRet)) return array(); |
---|
[16768] | 305 | |
---|
[19725] | 306 | return $arrRet; |
---|
| 307 | } |
---|
[19628] | 308 | |
---|
[17673] | 309 | /* |
---|
| 310 | * 関数名:lfCreateTemplate() |
---|
| 311 | * 引数1 :ディレクトリパス |
---|
| 312 | * 引数2 :作成ファイル名 |
---|
| 313 | * 説明 :キャンペーンの初期テンプレート作成 |
---|
| 314 | * 戻り値:無し |
---|
| 315 | */ |
---|
| 316 | function lfCreateTemplate($dir, $file , $cart_flg) { |
---|
[19725] | 317 | umask(0); |
---|
[17673] | 318 | $objFileManager = new SC_Helper_FileManager_Ex(); |
---|
[19725] | 319 | |
---|
[17673] | 320 | // 作成ファイルディレクトリ |
---|
| 321 | $create_dir = $dir . $file; |
---|
| 322 | $create_active_dir = $create_dir . "/" . CAMPAIGN_TEMPLATE_ACTIVE; |
---|
| 323 | $create_end_dir = $create_dir . "/" . CAMPAIGN_TEMPLATE_END; |
---|
| 324 | // デフォルトファイルディレクトリ |
---|
[19807] | 325 | $default_dir = TEMPLATE_REALDIR . CAMPAIGN_TEMPLATE_REALDIR; |
---|
[17673] | 326 | $default_active_dir = $default_dir . "/" . CAMPAIGN_TEMPLATE_ACTIVE; |
---|
| 327 | $default_end_dir = $default_dir . "/" . CAMPAIGN_TEMPLATE_END; |
---|
| 328 | |
---|
| 329 | $ret = $objFileManager->sfCreateFile($create_dir, 0755); |
---|
| 330 | $ret = $objFileManager->sfCreateFile($create_active_dir, 0755); |
---|
| 331 | $ret = $objFileManager->sfCreateFile($create_end_dir, 0755); |
---|
| 332 | |
---|
| 333 | // キャンペーン実行PHPをコピー |
---|
| 334 | $ret = $objFileManager->sfCreateFile(CAMPAIGN_PATH . $file); |
---|
[19807] | 335 | copy(HTML_REALDIR . CAMPAIGN_TEMPLATE_REALDIR . "index.php", CAMPAIGN_PATH . $file . "/index.php"); |
---|
| 336 | copy(HTML_REALDIR . CAMPAIGN_TEMPLATE_REALDIR . "application.php", CAMPAIGN_PATH . $file . "/application.php"); |
---|
| 337 | copy(HTML_REALDIR . CAMPAIGN_TEMPLATE_REALDIR . "complete.php", CAMPAIGN_PATH . $file . "/complete.php"); |
---|
| 338 | copy(HTML_REALDIR . CAMPAIGN_TEMPLATE_REALDIR . "entry.php", CAMPAIGN_PATH . $file . "/entry.php"); |
---|
[17673] | 339 | |
---|
| 340 | // デフォルトテンプレート作成(キャンペーン中) |
---|
| 341 | $header = $this->lfGetFileContents($default_active_dir."header.tpl"); |
---|
| 342 | SC_Utils_Ex::sfWriteFile($header, $create_active_dir."header.tpl", "w"); |
---|
| 343 | $contents = $this->lfGetFileContents($default_active_dir."contents.tpl"); |
---|
| 344 | if(!$cart_flg) { |
---|
| 345 | $contents .= "\n" . '<!--{*ログインフォーム*}-->' . "\n"; |
---|
| 346 | $contents .= $this->lfGetFileContents(CAMPAIGN_BLOC_PATH . "login.tpl"); |
---|
| 347 | $contents .= '<!--{*会員登録フォーム*}-->'."\n"; |
---|
| 348 | $contents .= $this->lfGetFileContents(CAMPAIGN_BLOC_PATH . "entry.tpl"); |
---|
| 349 | } |
---|
| 350 | SC_Utils_Ex::sfWriteFile($contents, $create_active_dir."contents.tpl", "w"); |
---|
| 351 | $footer = $this->lfGetFileContents($default_active_dir."footer.tpl"); |
---|
| 352 | SC_Utils_Ex::sfWriteFile($footer, $create_active_dir."footer.tpl", "w"); |
---|
| 353 | |
---|
| 354 | // サイトフレーム作成 |
---|
| 355 | $site_frame = $header."\n"; |
---|
| 356 | $site_frame .= '<script type="text/javascript" src="<!--{$TPL_DIR}-->js/navi.js"></script>'."\n"; |
---|
| 357 | $site_frame .= '<script type="text/javascript" src="<!--{$TPL_DIR}-->js/site.js"></script>'."\n"; |
---|
| 358 | $site_frame .= '<!--{include file=$tpl_mainpage}-->'."\n"; |
---|
| 359 | $site_frame .= $footer."\n"; |
---|
| 360 | SC_Utils_Ex::sfWriteFile($site_frame, $create_active_dir."site_frame.tpl", "w"); |
---|
| 361 | |
---|
| 362 | /* デフォルトテンプレート作成(キャンペーン終了) */ |
---|
| 363 | $header = $this->lfGetFileContents($default_end_dir."header.tpl"); |
---|
| 364 | SC_Utils_Ex::sfWriteFile($header, $create_end_dir."header.tpl", "w"); |
---|
| 365 | $contents = $this->lfGetFileContents($default_end_dir."contents.tpl"); |
---|
| 366 | SC_Utils_Ex::sfWriteFile($contents, $create_end_dir."contents.tpl", "w"); |
---|
| 367 | $footer = $this->lfGetFileContents($default_end_dir."footer.tpl"); |
---|
| 368 | SC_Utils_Ex::sfWriteFile($footer, $create_end_dir."footer.tpl", "w"); |
---|
| 369 | } |
---|
| 370 | |
---|
| 371 | /* |
---|
| 372 | * 関数名:lfGetFileContents() |
---|
| 373 | * 引数1 :ファイルパス |
---|
| 374 | * 説明 :ファイル読込 |
---|
| 375 | * 戻り値:無し |
---|
| 376 | */ |
---|
| 377 | function lfGetFileContents($read_file) { |
---|
| 378 | |
---|
| 379 | if(file_exists($read_file)) { |
---|
| 380 | $contents = file_get_contents($read_file); |
---|
| 381 | } else { |
---|
| 382 | $contents = ""; |
---|
| 383 | } |
---|
| 384 | |
---|
| 385 | return $contents; |
---|
| 386 | } |
---|
[16430] | 387 | } |
---|
| 388 | ?> |
---|