source: branches/version-2_12-dev/data/class/plugin/SC_Plugin_Template_Transform_List.php @ 21420

Revision 21420, 6.6 KB checked in by Seasoft, 12 years ago (diff)

#1613 (ソース整形・ソースコメントの改善)

  • Zend Framework PHP 標準コーディング規約への準拠を高めた
Line 
1<?php
2/*
3 * This file is part of EC-CUBE
4 *
5 * Copyright(c) 2000-2012 LOCKON CO.,LTD. All Rights Reserved.
6 *
7 * http://www.lockon.co.jp/
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.
22 *
23 */
24
25/**
26 * テンプレートの transform に関する情報のコンテナとなるクラス
27 *
28 * @package Plugin
29 * @author LOCKON CO.,LTD.
30 * @version $Id: $
31 */
32class SC_Plugin_Template_Transform_List {
33
34    // トランスフォームするテンプレートの配列
35    var $arrConfsByTemplates;
36    var $arrTemplatesByPlugin;
37    var $arrBlocsByPlugin;
38
39    /**
40     * SC_Plugin_Template_Transform_List オブジェクトを返す(Singletonパターン)
41     *
42     * @return object SC_Plugin_Template_Transform_List
43     */
44    function getSingletonInstance() {
45        if (!isset($GLOBALS['_SC_Plugin_Template_Transform_List_instance']) || is_null($GLOBALS['_SC_Plugin_Template_Transform_List_instance'])) {
46            $GLOBALS['_SC_Plugin_Template_Transform_List_instance'] =& new SC_Plugin_Template_Transform_List();
47        }
48        return $GLOBALS['_SC_Plugin_Template_Transform_List_instance'];
49    }
50
51    /**
52     * 初期化
53     *
54     * @return void
55     */
56    function init() {
57        $this->arrConfsByTemplates = array();
58        // プラグインが介入するテンプレートの配列
59        $this->arrTemplatesByPlugin = array();
60        // HeadNaviに追加するブロックの配列
61        $this->arrHeadNaviBlocsByPlugin = array();
62    }
63
64    /**
65     * 設定対象のテンプレートをセットする
66     *
67     * @param streing $tmpl 設定対象のテンプレートパス
68     * @param SC_Plugin_Base $objPlugin プラグインオブジェクト
69     * @return SC_Plugin_Template_Transformer 指定したテンプレートを transform するための SC_Plugin_Template_Transformer オブジェクト
70     */
71    function setTemplate($tmpl, SC_Plugin_Base $objPlugin) {
72        $this->arrTemplatesByPlugin[$objPlugin->arrSelfInfo['class_name']][$tmpl] = 1;
73
74        if (!is_array($this->arrConfsByTemplates)) $this->arrConfsByTemplates = array();
75        if (!array_key_exists($tmpl, $this->arrConfsByTemplates)) {
76            // テンプレートパスをキーにトランスフォーマのインスタンスをセット.
77            $this->arrConfsByTemplates[$tmpl] = new SC_Plugin_Template_Transformer($tmpl);
78        }
79        // 処理を行うプラグイン名をセットする.
80        $this->arrConfsByTemplates[$tmpl]->setCurrentPlugin($objPlugin->arrSelfInfo['class_name']);
81        return $this->arrConfsByTemplates[$tmpl];
82    }
83
84    /**
85     * 設定対象の管理者用テンプレートをセットする
86     *
87     * @param streing $tmpl 設定対象のテンプレートのパス(adminディレクトリからの相対パス)
88     * @param SC_Plugin_Base $objPlugin プラグインオブジェクト
89     * @return SC_Plugin_Template_Transformer SC_Plugin_Template_Transformer オブジェクト
90     */
91    function setTemplateAdmin($tmpl, SC_Plugin_Base $objPlugin) {
92        return $this->setTemplate('admin/'.$tmpl, $objPlugin);
93    }
94
95    /**
96     * 設定対象のPC用テンプレートをセットする
97     *
98     * @param streing $tmpl 設定対象のテンプレートのパス(PCディレクトリからの相対パス)
99     * @param SC_Plugin_Base $objPlugin プラグインオブジェクト
100     * @return SC_Plugin_Template_Transformer SC_Plugin_Template_Transformer オブジェクト
101     */
102    function setTemplatePC($tmpl, SC_Plugin_Base $objPlugin) {
103        return $this->setTemplate(TEMPLATE_NAME.'/'.$tmpl, $objPlugin);
104    }
105
106    /**
107     * 設定対象の携帯用テンプレートをセットする
108     *
109     * @param streing $tmpl 設定対象のテンプレートのパス(携帯ディレクトリからの相対パス)
110     * @param SC_Plugin_Base $objPlugin プラグインオブジェクト
111     * @return SC_Plugin_Template_Transformer SC_Plugin_Template_Transformer オブジェクト
112     */
113    function setTemplateMobile($tmpl, SC_Plugin_Base $objPlugin) {
114        return $this->setTemplate(MOBILE_TEMPLATE_NAME.'/'.$tmpl, $objPlugin);
115    }
116
117    /**
118     * 設定対象のスマホ用テンプレートをセットする
119     *
120     * @param streing         $tmpl      設定対象のテンプレートのパス(スマホディレクトリからの相対パス)
121     * @param SC_Plugin_Base $objPlugin プラグインオブジェクト
122     * @return SC_Plugin_Template_Transformer SC_Plugin_Template_Transformer オブジェクト
123     */
124    function setTemplateSphone($tmpl, SC_Plugin_Base $objPlugin) {
125        return $this->setTemplate(SMARTPHONE_TEMPLATE_NAME.'/'.$tmpl, $objPlugin);
126    }
127
128    /**
129     * 指定したテンプレートの transform を実行する
130     *
131     * @param string $group_name transformするテンプレート
132     * @return void
133     */
134    function transform($tmpl) {
135        $this->arrConfsByTemplates[$tmpl]->saveHTMLFile($tmpl);
136    }
137
138    /**
139     * 全てのテンプレートの transform を実行する
140     *
141     * @param boolean $test_mode
142     * @return void
143     */
144    function transformAll($test_mode = false) {
145        foreach ($this->arrConfsByTemplates as $tmpl => $objTransformaer) {
146            $objTransformaer->saveHTMLFile($tmpl, $test_mode);
147        }
148    }
149
150    /**
151     * テンプレートのヘッダに追加するPHPのURLをセットする
152     *
153     * @param string $url PHPファイルのURL
154     * @return void
155     */
156    function setHeadNavi($url){
157        $this->arrHeadNaviBlocsByPlugin[$url] = TARGET_ID_HEAD;
158    }
159
160    /**
161     * PHPのURLをテンプレートのヘッダに追加する
162     *
163     * @param array|null $arrBlocs  配置情報を含めたブロックの配列
164     * @return void
165     */
166    function setHeadNaviBlocs(&$arrBlocs){
167        foreach($this->arrHeadNaviBlocsByPlugin as $key => $value){
168            $arrBlocs[] = array(
169                'target_id' =>$value,
170                'php_path' => $key
171            );
172        }
173    }
174
175}
Note: See TracBrowser for help on using the repository browser.