source: branches/feature-module-update/data/class/SC_View.php @ 15257

Revision 15257, 9.3 KB checked in by nanasess, 17 years ago (diff)

暫定コミット

  • Property svn:keywords set to Id
  • Property svn:mime-type set to application/x-httpd-php; charset=UTF-8
Line 
1<?php
2/*
3 * Copyright(c) 2000-2007 LOCKON CO.,LTD. All Rights Reserved.
4 *
5 * http://www.lockon.co.jp/
6 */
7
8$SC_VIEW_PHP_DIR = realpath(dirname(__FILE__));
9require_once($SC_VIEW_PHP_DIR . "/../module/Smarty/libs/Smarty.class.php");
10require_once($SC_VIEW_PHP_DIR . "/../include/php_ini.inc");
11//require_once(CLASS_PATH . "util_extends/SC_Utils_Ex.php");
12
13class SC_View {
14
15    var $_smarty;
16    var $objSiteInfo; // サイト情報
17
18    // コンストラクタ
19    function SC_View($siteinfo = true) {
20        global $SC_VIEW_PHP_DIR;
21
22        $this->_smarty = new Smarty;
23        $this->_smarty->left_delimiter = '<!--{';
24        $this->_smarty->right_delimiter = '}-->';
25        $this->_smarty->register_modifier("sfDispDBDate", array("SC_Utils_Ex", "sfDispDBDate"));
26        $this->_smarty->register_modifier("sfConvSendDateToDisp", array("SC_Utils_Ex", "sfConvSendDateToDisp"));
27        $this->_smarty->register_modifier("sfConvSendWdayToDisp", array("SC_Utils_Ex", "sfConvSendWdayToDisp"));
28        $this->_smarty->register_modifier("sfGetVal", array("SC_Utils_Ex", "sfGetVal"));
29        $this->_smarty->register_modifier("sfSetErrorStyle", array("SC_Utils_Ex", "sfSetErrorStyle"));
30        $this->_smarty->register_modifier("sfGetErrorColor", array("SC_Utils_Ex", "sfGetErrorColor"));
31        $this->_smarty->register_modifier("sfTrim", array("SC_Utils_Ex", "sfTrim"));
32        $this->_smarty->register_modifier("sfPreTax", array("SC_Utils_Ex", "sfPreTax"));
33        $this->_smarty->register_modifier("sfPrePoint", array("SC_Utils_Ex", "sfPrePoint"));
34        $this->_smarty->register_modifier("sfGetChecked",array("SC_Utils_Ex", "sfGetChecked"));
35        $this->_smarty->register_modifier("sfTrimURL", array("SC_Utils_Ex", "sfTrimURL"));
36        $this->_smarty->register_modifier("sfMultiply", array("SC_Utils_Ex", "sfMultiply"));
37        $this->_smarty->register_modifier("sfPutBR", array("SC_Utils_Ex", "sfPutBR"));
38        $this->_smarty->register_modifier("sfRmDupSlash", array("SC_Utils_Ex", "sfRmDupSlash"));
39        $this->_smarty->register_modifier("sfCutString", array("SC_Utils_Ex", "sfCutString"));
40        $this->_smarty->plugins_dir=array("plugins", $SC_VIEW_PHP_DIR . "/../smarty_extends");
41        $this->_smarty->register_modifier("sf_mb_convert_encoding", array("SC_Utils_Ex", "sf_mb_convert_encoding"));
42        $this->_smarty->register_modifier("sf_mktime", array("SC_Utils_Ex", "sf_mktime"));
43        $this->_smarty->register_modifier("sf_date", array("SC_Utils_Ex", "sf_date"));
44        $this->_smarty->register_modifier("str_replace", array("SC_Utils_Ex", "str_replace"));
45//        $this->_smarty->register_modifier("sfPrintEbisTag", array("SC_Utils_Ex", "sfPrintEbisTag"));
46//        $this->_smarty->register_modifier("sfPrintAffTag", array("SC_Utils_Ex", "sfPrintAffTag"));
47        $this->_smarty->register_modifier("sfGetCategoryId", array("SC_Utils_Ex", "sfGetCategoryId"));
48        $this->_smarty->register_function("sfIsHTTPS", array("SC_Utils_Ex", "sfIsHTTPS"));
49        $this->_smarty->default_modifiers = array('script_escape');
50
51        if(ADMIN_MODE == '1') {
52            $this->time_start = time();
53        }
54
55        // サイト情報を取得する
56        if($siteinfo) {
57            if(!defined('LOAD_SITEINFO')) {
58                $this->objSiteInfo = new SC_SiteInfo();
59                $arrInfo['arrSiteInfo'] = $this->objSiteInfo->data;
60
61                // 都道府県名を変換
62                global $arrPref;
63                $arrInfo['arrSiteInfo']['pref'] = $arrPref[$arrInfo['arrSiteInfo']['pref']];
64
65                 // サイト情報を割り当てる
66                foreach ($arrInfo as $key => $value){
67                    $this->_smarty->assign($key, $value);
68                }
69
70                define('LOAD_SITEINFO', 1);
71            }
72        }
73    }
74
75    // テンプレートに値を割り当てる
76    function assign($val1, $val2) {
77        $this->_smarty->assign($val1, $val2);
78    }
79
80    // テンプレートの処理結果を取得
81    function fetch($template) {
82        return $this->_smarty->fetch($template);
83    }
84
85    // テンプレートの処理結果を表示
86    function display($template, $no_error = false) {
87        if(!$no_error) {
88            global $GLOBAL_ERR;
89            if(!defined('OUTPUT_ERR')) {
90                print($GLOBAL_ERR);
91                define('OUTPUT_ERR','ON');
92            }
93        }
94
95        $this->_smarty->display($template);
96        if(ADMIN_MODE == '1') {
97            $time_end = time();
98            $time = $time_end - $this->time_start;
99            print("処理時間:" . $time . "秒");
100        }
101    }
102
103      // オブジェクト内の変数をすべて割り当てる。
104      function assignobj($obj) {
105        $data = get_object_vars($obj);
106
107        foreach ($data as $key => $value){
108            $this->_smarty->assign($key, $value);
109        }
110      }
111
112      // 連想配列内の変数をすべて割り当てる。
113      function assignarray($array) {
114          foreach ($array as $key => $val) {
115              $this->_smarty->assign($key, $val);
116          }
117      }
118
119    /* サイト初期設定 */
120    function initpath() {
121        global $SC_VIEW_PHP_DIR;
122
123        $array['tpl_mainnavi'] = $SC_VIEW_PHP_DIR . '/../Smarty/templates/frontparts/mainnavi.tpl';
124        $array['tpl_root_id'] = SC_Utils_Ex::sfGetRootId();
125        $this->assignarray($array);
126    }
127
128    // デバッグ
129    function debug($var = true){
130        $this->_smarty->debugging = $var;
131    }
132
133
134}
135
136class SC_AdminView extends SC_View{
137    function SC_AdminView() {
138        parent::SC_View(false);
139        $this->_smarty->template_dir = TEMPLATE_ADMIN_DIR;
140        $this->_smarty->compile_dir = COMPILE_ADMIN_DIR;
141        $this->initpath();
142    }
143
144    function printr($data){
145        print_r($data);
146    }
147}
148
149class SC_SiteView extends SC_View{
150    function SC_SiteView($cart = true) {
151        parent::SC_View();
152
153        $this->_smarty->template_dir = TEMPLATE_DIR;
154        $this->_smarty->compile_dir = COMPILE_DIR;
155        $this->initpath();
156
157        // PHP5ではsessionをスタートする前にヘッダー情報を送信していると警告が出るため、先にセッションをスタートするように変更
158        SC_Utils_Ex::sfDomainSessionStart();
159
160        if($cart){
161            $include_dir = realpath(dirname( __FILE__));
162            require_once($include_dir . "/SC_CartSession.php");
163            $objCartSess = new SC_CartSession();
164            $objCartSess->setPrevURL($_SERVER['REQUEST_URI']);
165        }
166    }
167}
168
169class SC_UserView extends SC_SiteView{
170    function SC_UserView($template_dir, $compile_dir = COMPILE_DIR) {
171        parent::SC_SiteView();
172        $this->_smarty->template_dir = $template_dir;
173        $this->_smarty->compile_dir = $compile_dir;
174    }
175}
176
177class SC_InstallView extends SC_View{
178    function SC_InstallView($template_dir, $compile_dir = COMPILE_DIR) {
179        parent::SC_View(false);
180        $this->_smarty->template_dir = $template_dir;
181        $this->_smarty->compile_dir = $compile_dir;
182    }
183}
184
185class SC_MobileView extends SC_SiteView {
186    function SC_MobileView() {
187        parent::SC_SiteView();
188        $this->_smarty->template_dir = MOBILE_TEMPLATE_DIR;
189        $this->_smarty->compile_dir = MOBILE_COMPILE_DIR;
190    }
191}
192
193//function sfCutString($str, $len, $byte = true, $commadisp = true) {
194//        if($byte) {
195//            if(strlen($str) > ($len + 2)) {
196//                $ret =substr($str, 0, $len);
197//                $cut = substr($str, $len);
198//            } else {
199//                $ret = $str;
200//                $commadisp = false;
201//            }
202//        } else {
203//            if(mb_strlen($str) > ($len + 1)) {
204//                $ret = mb_substr($str, 0, $len);
205//                $cut = mb_substr($str, $len);
206//            } else {
207//                $ret = $str;
208//                $commadisp = false;
209//            }
210//        }
211//
212//        // 絵文字タグの途中で分断されないようにする。
213//        if (isset($cut)) {
214//            // 分割位置より前の最後の [ 以降を取得する。
215//            $head = strrchr($ret, '[');
216//
217//            // 分割位置より後の最初の ] 以前を取得する。
218//            $tail_pos = strpos($cut, ']');
219//            if ($tail_pos !== false) {
220//                $tail = substr($cut, 0, $tail_pos + 1);
221//            }
222//
223//            // 分割位置より前に [、後に ] が見つかった場合は、[ から ] までを
224//            // 接続して絵文字タグ1個分になるかどうかをチェックする。
225//            if ($head !== false && $tail_pos !== false) {
226//                $subject = $head . $tail;
227//                if (preg_match('/^\[emoji:e?\d+\]$/', $subject)) {
228//                    // 絵文字タグが見つかったので削除する。
229//                    $ret = substr($ret, 0, -strlen($head));
230//                }
231//            }
232//        }
233//
234//        if($commadisp){
235//            $ret = $ret . "...";
236//        }
237//        return $ret;
238//    }
239//
240//function sfRmDupSlash($istr){
241//        if(ereg("^http://", $istr)) {
242//            $str = substr($istr, 7);
243//            $head = "http://";
244//        } else if(ereg("^https://", $istr)) {
245//            $str = substr($istr, 8);
246//            $head = "https://";
247//        } else {
248//            $str = $istr;
249//        }
250//        $str = ereg_replace("[/]+", "/", $str);
251//        $ret = $head . $str;
252//        return $ret;
253//    }
254?>
Note: See TracBrowser for help on using the repository browser.