source: branches/version-2_5-dev/data/class/util/SC_Utils.php @ 19547

Revision 19547, 73.5 KB checked in by Seasoft, 16 years ago (diff)

#628(未使用処理・定義などの削除)

  • SC_Utils#sfDomainSessionStart
  • Property svn:eol-style set to LF
  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/x-httpd-php; charset=UTF-8
Line 
1<?php
2/*
3 * This file is part of EC-CUBE
4 *
5 * Copyright(c) 2000-2010 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 *
27 * 主に static 参照するユーティリティ系の関数群
28 *
29 * :XXX: 内部でインスタンスを生成している関数は, Helper クラスへ移動するべき...
30 *
31 * @package Util
32 * @author LOCKON CO.,LTD.
33 * @version $Id:SC_Utils.php 15532 2007-08-31 14:39:46Z nanasess $
34 */
35class SC_Utils {
36
37    /**
38     * サイト管理情報から値を取得する。
39     * データが存在する場合、必ず1以上の数値が設定されている。
40     * 0を返した場合は、呼び出し元で対応すること。
41     *
42     * @param $control_id 管理ID
43     * @param $dsn DataSource
44     * @return $control_flg フラグ
45     */
46    function sfGetSiteControlFlg($control_id, $dsn = "") {
47
48        // データソース
49        if($dsn == "") {
50            if(defined('DEFAULT_DSN')) {
51                $dsn = DEFAULT_DSN;
52            } else {
53                return;
54            }
55        }
56
57        // クエリ生成
58        $target_column = "control_flg";
59        $table_name = "dtb_site_control";
60        $where = "control_id = ?";
61        $arrval = array($control_id);
62        $control_flg = 0;
63
64        // クエリ発行
65        $objQuery = new SC_Query($dsn, true, true);
66        $arrSiteControl = $objQuery->select($target_column, $table_name, $where, $arrval);
67
68        // データが存在すればフラグを取得する
69        if (count($arrSiteControl) > 0) {
70            $control_flg = $arrSiteControl[0]["control_flg"];
71        }
72
73        return $control_flg;
74    }
75
76    // インストール初期処理
77    function sfInitInstall() {
78        // インストール済みが定義されていない。
79        if (!defined('ECCUBE_INSTALL')) {
80            $phpself = $_SERVER['PHP_SELF'];
81            if( !ereg('/install/', $phpself) ) {
82                $path = substr($phpself, 0, strpos($phpself, basename($phpself)));
83                $install_url = SC_Utils::searchInstallerPath($path);
84                header('Location: ' . $install_url);
85                exit;
86            }
87        }
88        $path = HTML_PATH . "install/index.php";
89        if(file_exists($path)) {
90            SC_Utils::sfErrorHeader("&gt;&gt; /install/index.phpは、インストール完了後にファイルを削除してください。");
91        }
92    }
93
94    /**
95     * インストーラのパスを検索し, URL を返す.
96     *
97     * $path と同階層に install/index.php があるか検索する.
98     * 存在しない場合は上位階層を再帰的に検索する.
99     * インストーラのパスが見つかった場合は, その URL を返す.
100     * DocumentRoot まで検索しても見つからない場合は /install/index.php を返す.
101     *
102     * @param string $path 検索対象のパス
103     * @return string インストーラの URL
104     */
105    function searchInstallerPath($path) {
106        $installer = 'install/index.php';
107
108        if (SC_Utils::sfIsHTTPS()) {
109            $proto = "https://";
110        } else {
111            $proto = "http://";
112        }
113        $host = $proto . $_SERVER['SERVER_NAME'];
114        if ($path == '/') {
115            return $host . $path . $installer;
116        }
117        if (substr($path, -1, 1) != '/') {
118            $path .= $path . '/';
119        }
120        $installer_url = $host . $path . $installer;
121        $resources = fopen(SC_Utils::getRealURL($installer_url), 'r');
122        if ($resources === false) {
123            $installer_url = SC_Utils::searchInstallerPath($path . '../');
124        }
125        return $installer_url;
126    }
127
128    /**
129     * 相対パスで記述された URL から絶対パスの URL を取得する.
130     *
131     * この関数は, http(s):// から始まる URL を解析し, 相対パスで記述されていた
132     * 場合, 絶対パスに変換して返す
133     *
134     * 例)
135     * http://www.example.jp/aaa/../index.php
136     * ↓
137     * http://www.example.jp/index.php
138     *
139     * @param string $url http(s):// から始まる URL
140     * @return string $url を絶対パスに変換した URL
141     */
142    function getRealURL($url) {
143        $parse = parse_url($url);
144        $tmp = split('/', $parse['path']);
145        $results = array();
146        foreach ($tmp as $v) {
147            if ($v == '' || $v == '.') {
148                // queit.
149            } elseif ($v == '..') {
150                array_pop($results);
151            } else {
152                array_push($results, $v);
153            }
154        }
155
156        $path = join('/', $results);
157        return $parse['scheme'] . '://' . $parse['host'] . '/' . $path;
158    }
159
160    // 装飾付きエラーメッセージの表示
161    function sfErrorHeader($mess, $print = false) {
162        global $GLOBAL_ERR;
163        $GLOBAL_ERR.="<div style='color: #F00; font-weight: bold; font-size: 12px;"
164            . "background-color: #FEB; text-align: center; padding: 5px;'>";
165        $GLOBAL_ERR.= $mess;
166        $GLOBAL_ERR.= "</div>";
167        if($print) {
168            print($GLOBAL_ERR);
169        }
170    }
171
172    /* エラーページの表示 */
173    function sfDispError($type) {
174
175        require_once(CLASS_EX_PATH . "page_extends/error/LC_Page_Error_DispError_Ex.php");
176
177        $objPage = new LC_Page_Error_DispError_Ex();
178        register_shutdown_function(array($objPage, "destroy"));
179        $objPage->init();
180        $objPage->type = $type;
181        $objPage->process();
182        exit;
183    }
184
185    /* サイトエラーページの表示 */
186    function sfDispSiteError($type, $objSiteSess = "", $return_top = false, $err_msg = "") {
187        global $objCampaignSess;
188
189        require_once(CLASS_EX_PATH . "page_extends/error/LC_Page_Error_Ex.php");
190
191        $objPage = new LC_Page_Error_Ex();
192        register_shutdown_function(array($objPage, "destroy"));
193        $objPage->init();
194        $objPage->type = $type;
195        $objPage->objSiteSess = $objSiteSess;
196        $objPage->return_top = $return_top;
197        $objPage->err_msg = $err_msg;
198        $objPage->is_mobile = (defined('MOBILE_SITE')) ? true : false;
199        $objPage->process();
200        exit;
201    }
202
203    /**
204     * 例外エラーページの表示
205     *
206     * @param string $debugMsg デバッグ用のメッセージ
207     * @return void
208     */
209    function sfDispException($debugMsg = null) {
210        require_once(CLASS_EX_PATH . "page_extends/error/LC_Page_Error_SystemError_Ex.php");
211
212        $objPage = new LC_Page_Error_SystemError_Ex();
213        register_shutdown_function(array($objPage, "destroy"));
214        $objPage->init();
215        if (!is_null($debugMsg)) {
216            $objPage->addDebugMsg($debugMsg);
217        }
218        if (function_exists("debug_backtrace")) {
219            $objPage->backtrace = debug_backtrace();
220        }
221        GC_Utils_Ex::gfPrintLog($objPage->sfGetErrMsg());
222        $objPage->process();
223
224        exit();
225    }
226
227    /* 認証の可否判定 */
228    function sfIsSuccess($objSess, $disp_error = true) {
229        $ret = $objSess->IsSuccess();
230        if($ret != SUCCESS) {
231            if($disp_error) {
232                // エラーページの表示
233                SC_Utils::sfDispError($ret);
234            }
235            return false;
236        }
237        // リファラーチェック(CSRFの暫定的な対策)
238        // 「リファラ無」 の場合はスルー
239        // 「リファラ有」 かつ 「管理画面からの遷移でない」 場合にエラー画面を表示する
240        if ( empty($_SERVER['HTTP_REFERER']) ) {
241            // TODO 警告表示させる?
242            // sfErrorHeader('>> referrerが無効になっています。');
243        } else {
244            $domain  = SC_Utils::sfIsHTTPS() ? SSL_URL : SITE_URL;
245            $pattern = sprintf('|^%s.*|', $domain);
246            $referer = $_SERVER['HTTP_REFERER'];
247
248            // 管理画面から以外の遷移の場合はエラー画面を表示
249            if (!preg_match($pattern, $referer)) {
250                if ($disp_error) SC_Utils::sfDispError(INVALID_MOVE_ERRORR);
251                return false;
252            }
253        }
254        return true;
255    }
256
257    /**
258     * 文字列をアスタリスクへ変換する.
259     *
260     * @param string $passlen 変換する文字列
261     * @return string アスタリスクへ変換した文字列
262     */
263    function lfPassLen($passlen){
264        $ret = "";
265        for ($i=0;$i<$passlen;true){
266            $ret.="*";
267            $i++;
268        }
269        return $ret;
270    }
271
272    /**
273     * HTTPSかどうかを判定
274     *
275     * @return bool
276     */
277    function sfIsHTTPS () {
278        // HTTPS時には$_SERVER['HTTPS']には空でない値が入る
279        // $_SERVER['HTTPS'] != 'off' はIIS用
280        if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') {
281            return true;
282        } else {
283            return false;
284        }
285    }
286
287    /**
288     *  正規の遷移がされているかを判定
289     *  前画面でuniqidを埋め込んでおく必要がある
290     *  @param  obj  SC_Session, SC_SiteSession
291     *  @return bool
292     */
293    function sfIsValidTransition($objSess) {
294        // 前画面からPOSTされるuniqidが正しいものかどうかをチェック
295        $uniqid = $objSess->getUniqId();
296        if ( !empty($_POST['uniqid']) && ($_POST['uniqid'] === $uniqid) ) {
297            return true;
298        } else {
299            return false;
300        }
301    }
302
303    /**
304     * 前のページで正しく登録が行われたか判定
305     *
306     * @deprecated SC_SiteSession::isPrePage() を使用して下さい
307     */
308    function sfIsPrePage(&$objSiteSess) {
309        $ret = $objSiteSess->isPrePage();
310        if($ret != true) {
311            // エラーページの表示
312            SC_Utils::sfDispSiteError(PAGE_ERROR, $objSiteSess);
313        }
314    }
315
316    /**
317     * @deprecated SC_CartSession クラスを使用してください
318     */
319    function sfCheckNormalAccess(&$objSiteSess, &$objCartSess) {
320        // ユーザユニークIDの取得
321        $uniqid = $objSiteSess->getUniqId();
322
323        $cartkeys = $objCartSess->getKeys();
324
325        foreach ($cartKeys as $cartKey) {
326            // 購入ボタンを押した時のカート内容がコピーされていない場合のみコピーする。
327            $objCartSess->saveCurrentCart($uniqid, $cartKey);
328            // POSTのユニークIDとセッションのユニークIDを比較(ユニークIDがPOSTされていない場合はスルー)
329            $ret = $objSiteSess->checkUniqId();
330            if($ret != true) {
331                // エラーページの表示
332                SC_Utils_Ex::sfDispSiteError(CANCEL_PURCHASE, $objSiteSess);
333            }
334
335            // カート内が空でないか || 購入ボタンを押してから変化がないか
336            $quantity = $objCartSess->getTotalQuantity($cartKey);
337            $ret = $objCartSess->checkChangeCart($cartKey);
338            if($ret == true || !($quantity > 0)) {
339                // カート情報表示に強制移動する
340                // FIXME false を返して, Page クラスで遷移させるべき...
341                if (defined("MOBILE_SITE")) {
342                    header("Location: ". MOBILE_URL_CART_TOP
343                           . "?" . session_name() . "=" . session_id());
344                } else {
345                    header("Location: ".URL_CART_TOP);
346                }
347                exit;
348            }
349        }
350        return $uniqid;
351    }
352
353    /* DB用日付文字列取得 */
354    function sfGetTimestamp($year, $month, $day, $last = false) {
355        if($year != "" && $month != "" && $day != "") {
356            if($last) {
357                $time = "23:59:59";
358            } else {
359                $time = "00:00:00";
360            }
361            $date = $year."-".$month."-".$day." ".$time;
362        } else {
363            $date = "";
364        }
365        return     $date;
366    }
367
368    /**
369     *  INT型の数値チェック
370     *  ・FIXME: マイナス値の扱いが不明確
371     *  ・XXX: INT_LENには収まるが、INT型の範囲を超えるケースに対応できないのでは?
372     *
373     *  @param mixed $value
374     *  @return bool
375     */
376    //
377    function sfIsInt($value) {
378        if (strlen($value) >= 1 && strlen($value) <= INT_LEN && is_numeric($value)) {
379            return true;
380        }
381        return false;
382    }
383
384    /*
385     * 桁が0で埋められているかを判定する
386     *
387     * @param string $value 検査対象
388     * @return boolean 0で埋められている
389     */
390    function sfIsZeroFilling($value) {
391        if (strlen($value) > 1 && $value{0} === '0')
392            return true;
393        return false;
394    }
395
396    function sfCSVDownload($data, $prefix = ""){
397
398        if($prefix == "") {
399            $dir_name = SC_Utils::sfUpDirName();
400            $file_name = $dir_name . date("ymdHis") .".csv";
401        } else {
402            $file_name = $prefix . date("ymdHis") .".csv";
403        }
404
405        /* HTTPヘッダの出力 */
406        Header("Content-disposition: attachment; filename=${file_name}");
407        Header("Content-type: application/octet-stream; name=${file_name}");
408        Header("Cache-Control: ");
409        Header("Pragma: ");
410
411        if (mb_internal_encoding() == CHAR_CODE){
412            $data = mb_convert_encoding($data,'SJIS-Win',CHAR_CODE);
413        }
414
415        /* データを出力 */
416        echo $data;
417    }
418
419    /* 1階層上のディレクトリ名を取得する */
420    function sfUpDirName() {
421        $path = $_SERVER['PHP_SELF'];
422        $arrVal = split("/", $path);
423        $cnt = count($arrVal);
424        return $arrVal[($cnt - 2)];
425    }
426
427
428
429
430    /**
431     * 現在のサイトを更新(ただしポストは行わない)
432     *
433     * @deprecated LC_Page::reload() を使用して下さい.
434     */
435    function sfReload($get = "") {
436        if ($_SERVER["SERVER_PORT"] == "443" ){
437            $url = ereg_replace(URL_DIR . "$", "", SSL_URL);
438        } else {
439            $url = ereg_replace(URL_DIR . "$", "", SITE_URL);
440        }
441
442        if($get != "") {
443            header("Location: ". $url . $_SERVER['PHP_SELF'] . "?" . $get);
444        } else {
445            header("Location: ". $url . $_SERVER['PHP_SELF']);
446        }
447        exit;
448    }
449
450    // チェックボックスの値をマージ
451    function sfMergeCBValue($keyname, $max) {
452        $conv = "";
453        $cnt = 1;
454        for($cnt = 1; $cnt <= $max; $cnt++) {
455            if ($_POST[$keyname . $cnt] == "1") {
456                $conv.= "1";
457            } else {
458                $conv.= "0";
459            }
460        }
461        return $conv;
462    }
463
464    // html_checkboxesの値をマージして2進数形式に変更する。
465    function sfMergeCheckBoxes($array, $max) {
466        $ret = "";
467        if(is_array($array)) {
468            foreach($array as $val) {
469                $arrTmp[$val] = "1";
470            }
471        }
472        for($i = 1; $i <= $max; $i++) {
473            if(isset($arrTmp[$i]) && $arrTmp[$i] == "1") {
474                $ret.= "1";
475            } else {
476                $ret.= "0";
477            }
478        }
479        return $ret;
480    }
481
482
483    // html_checkboxesの値をマージして「-」でつなげる。
484    function sfMergeParamCheckBoxes($array) {
485        $ret = '';
486        if(is_array($array)) {
487            foreach($array as $val) {
488                if($ret != "") {
489                    $ret.= "-$val";
490                } else {
491                    $ret = $val;
492                }
493            }
494        } else {
495            $ret = $array;
496        }
497        return $ret;
498    }
499
500    // html_checkboxesの値をマージしてSQL検索用に変更する。
501    function sfSearchCheckBoxes($array) {
502        $max = max($array);
503        $ret = '';
504        for ($i = 1; $i <= $max; $i++) {
505            $ret .= in_array($i, $array) ? '1' : '_';
506        }
507        if (strlen($ret) != 0) {
508            $ret .= '%';
509        }
510        return $ret;
511    }
512
513    // 2進数形式の値をhtml_checkboxes対応の値に切り替える
514    function sfSplitCheckBoxes($val) {
515        $arrRet = array();
516        $len = strlen($val);
517        for($i = 0; $i < $len; $i++) {
518            if(substr($val, $i, 1) == "1") {
519                $arrRet[] = ($i + 1);
520            }
521        }
522        return $arrRet;
523    }
524
525    // チェックボックスの値をマージ
526    function sfMergeCBSearchValue($keyname, $max) {
527        $conv = "";
528        $cnt = 1;
529        for($cnt = 1; $cnt <= $max; $cnt++) {
530            if ($_POST[$keyname . $cnt] == "1") {
531                $conv.= "1";
532            } else {
533                $conv.= "_";
534            }
535        }
536        return $conv;
537    }
538
539    // チェックボックスの値を分解
540    function sfSplitCBValue($val, $keyname = "") {
541        $arr = array();
542        $len = strlen($val);
543        $no = 1;
544        for ($cnt = 0; $cnt < $len; $cnt++) {
545            if($keyname != "") {
546                $arr[$keyname . $no] = substr($val, $cnt, 1);
547            } else {
548                $arr[] = substr($val, $cnt, 1);
549            }
550            $no++;
551        }
552        return $arr;
553    }
554
555    // キーと値をセットした配列を取得
556    function sfArrKeyValue($arrList, $keyname, $valname, $len_max = "", $keysize = "") {
557        $arrRet = array();
558        $max = count($arrList);
559
560        if($len_max != "" && $max > $len_max) {
561            $max = $len_max;
562        }
563
564        for($cnt = 0; $cnt < $max; $cnt++) {
565            if($keysize != "") {
566                $key = SC_Utils::sfCutString($arrList[$cnt][$keyname], $keysize);
567            } else {
568                $key = $arrList[$cnt][$keyname];
569            }
570            $val = $arrList[$cnt][$valname];
571
572            if(!isset($arrRet[$key])) {
573                $arrRet[$key] = $val;
574            }
575
576        }
577        return $arrRet;
578    }
579
580    // キーと値をセットした配列を取得(値が複数の場合)
581    function sfArrKeyValues($arrList, $keyname, $valname, $len_max = "", $keysize = "", $connect = "") {
582
583        $max = count($arrList);
584
585        if($len_max != "" && $max > $len_max) {
586            $max = $len_max;
587        }
588
589        for($cnt = 0; $cnt < $max; $cnt++) {
590            if($keysize != "") {
591                $key = SC_Utils::sfCutString($arrList[$cnt][$keyname], $keysize);
592            } else {
593                $key = $arrList[$cnt][$keyname];
594            }
595            $val = $arrList[$cnt][$valname];
596
597            if($connect != "") {
598                $arrRet[$key].= "$val".$connect;
599            } else {
600                $arrRet[$key][] = $val;
601            }
602        }
603        return $arrRet;
604    }
605
606    // 配列の値をカンマ区切りで返す。
607    function sfGetCommaList($array, $space=true, $arrPop = array()) {
608        if (count($array) > 0) {
609            $line = "";
610            foreach($array as $val) {
611                if (!in_array($val, $arrPop)) {
612                    if ($space) {
613                        $line .= $val . ", ";
614                    } else {
615                        $line .= $val . ",";
616                    }
617                }
618            }
619            if ($space) {
620                $line = ereg_replace(", $", "", $line);
621            } else {
622                $line = ereg_replace(",$", "", $line);
623            }
624            return $line;
625        } else {
626            return false;
627        }
628
629    }
630
631    /* 配列の要素をCSVフォーマットで出力する。*/
632    function sfGetCSVList($array) {
633        $line = "";
634        if (count($array) > 0) {
635            foreach($array as $key => $val) {
636                $val = mb_convert_encoding($val, CHAR_CODE, CHAR_CODE);
637                $line .= "\"".$val."\",";
638            }
639            $line = ereg_replace(",$", "\r\n", $line);
640        }else{
641            return false;
642        }
643        return $line;
644    }
645
646    /* 配列の要素をPDFフォーマットで出力する。*/
647    function sfGetPDFList($array) {
648        foreach($array as $key => $val) {
649            $line .= "\t".$val;
650        }
651        $line.="\n";
652        return $line;
653    }
654
655
656
657    /*-----------------------------------------------------------------*/
658    /*    check_set_term
659    /*    年月日に別れた2つの期間の妥当性をチェックし、整合性と期間を返す
660    /* 引数 (開始年,開始月,開始日,終了年,終了月,終了日)
661    /* 戻値 array(1,2,3)
662    /*          1.開始年月日 (YYYY/MM/DD 000000)
663    /*            2.終了年月日 (YYYY/MM/DD 235959)
664    /*            3.エラー ( 0 = OK, 1 = NG )
665    /*-----------------------------------------------------------------*/
666    function sfCheckSetTerm ( $start_year, $start_month, $start_day, $end_year, $end_month, $end_day ) {
667
668        // 期間指定
669        $error = 0;
670        if ( $start_month || $start_day || $start_year){
671            if ( ! checkdate($start_month, $start_day , $start_year) ) $error = 1;
672        } else {
673            $error = 1;
674        }
675        if ( $end_month || $end_day || $end_year){
676            if ( ! checkdate($end_month ,$end_day ,$end_year) ) $error = 2;
677        }
678        if ( ! $error ){
679            $date1 = $start_year ."/".sprintf("%02d",$start_month) ."/".sprintf("%02d",$start_day) ." 000000";
680            $date2 = $end_year   ."/".sprintf("%02d",$end_month)   ."/".sprintf("%02d",$end_day)   ." 235959";
681            if ($date1 > $date2) $error = 3;
682        } else {
683            $error = 1;
684        }
685        return array($date1, $date2, $error);
686    }
687
688    // エラー箇所の背景色を変更するためのfunction SC_Viewで読み込む
689    function sfSetErrorStyle(){
690        return 'style="background-color:'.ERR_COLOR.'"';
691    }
692
693    /* DBに渡す数値のチェック
694     * 10桁以上はオーバーフローエラーを起こすので。
695     */
696    function sfCheckNumLength( $value ){
697        if ( ! is_numeric($value)  ){
698            return false;
699        }
700
701        if ( strlen($value) > 9 ) {
702            return false;
703        }
704
705        return true;
706    }
707
708    // 一致した値のキー名を取得
709    function sfSearchKey($array, $word, $default) {
710        foreach($array as $key => $val) {
711            if($val == $word) {
712                return $key;
713            }
714        }
715        return $default;
716    }
717
718    function sfGetErrorColor($val) {
719        if($val != "") {
720            return "background-color:" . ERR_COLOR;
721        }
722        return "";
723    }
724
725    function sfGetEnabled($val) {
726        if( ! $val ) {
727            return " disabled=\"disabled\"";
728        }
729        return "";
730    }
731
732    function sfGetChecked($param, $value) {
733        if ((string)$param === (string)$value) {
734            return "checked=\"checked\"";
735        }
736        return "";
737    }
738
739    function sfTrim($str) {
740        $ret = mb_ereg_replace("^[  \n\r]*", "", $str);
741        $ret = mb_ereg_replace("[  \n\r]*$", "", $ret);
742        return $ret;
743    }
744
745    /**
746     * 税金額を返す
747     *
748     * ・店舗基本情報に基づいた計算は SC_Helper_DB::sfTax() を使用する
749     *
750     * @param integer $price 計算対象の金額
751     * @param integer $tax 税率(%単位)
752     *     XXX integer のみか不明
753     * @param integer $tax_rule 端数処理
754     * @return integer 税金額
755     */
756    function sfTax($price, $tax, $tax_rule) {
757        $real_tax = $tax / 100;
758        $ret = $price * $real_tax;
759        switch($tax_rule) {
760        // 四捨五入
761        case 1:
762            $ret = round($ret);
763            break;
764        // 切り捨て
765        case 2:
766            $ret = floor($ret);
767            break;
768        // 切り上げ
769        case 3:
770            $ret = ceil($ret);
771            break;
772        // デフォルト:切り上げ
773        default:
774            $ret = ceil($ret);
775            break;
776        }
777        return $ret;
778    }
779
780    /**
781     * 税金付与した金額を返す
782     *
783     * ・店舗基本情報に基づいた計算は SC_Helper_DB::sfTax() を使用する
784     *
785     * @param integer $price 計算対象の金額
786     * @param integer $tax 税率(%単位)
787     *     XXX integer のみか不明
788     * @param integer $tax_rule 端数処理
789     * @return integer 税金付与した金額
790     */
791    function sfPreTax($price, $tax, $tax_rule) {
792        return $price + SC_Utils_Ex::sfTax($price, $tax, $tax_rule);
793    }
794
795    // 桁数を指定して四捨五入
796    function sfRound($value, $pow = 0){
797        $adjust = pow(10 ,$pow-1);
798
799        // 整数且つ0出なければ桁数指定を行う
800        if(SC_Utils::sfIsInt($adjust) and $pow > 1){
801            $ret = (round($value * $adjust)/$adjust);
802        }
803
804        $ret = round($ret);
805
806        return $ret;
807    }
808
809    /* ポイント付与 */
810    function sfPrePoint($price, $point_rate, $rule = POINT_RULE, $product_id = "") {
811        $real_point = $point_rate / 100;
812        $ret = $price * $real_point;
813        switch($rule) {
814        // 四捨五入
815        case 1:
816            $ret = round($ret);
817            break;
818        // 切り捨て
819        case 2:
820            $ret = floor($ret);
821            break;
822        // 切り上げ
823        case 3:
824            $ret = ceil($ret);
825            break;
826        // デフォルト:切り上げ
827        default:
828            $ret = ceil($ret);
829            break;
830        }
831        return $ret;
832    }
833
834    /* 規格分類の件数取得 */
835    function sfGetClassCatCount() {
836        $sql = "select count(dtb_class.class_id) as count, dtb_class.class_id ";
837        $sql.= "from dtb_class inner join dtb_classcategory on dtb_class.class_id = dtb_classcategory.class_id ";
838        $sql.= "where dtb_class.del_flg = 0 AND dtb_classcategory.del_flg = 0 ";
839        $sql.= "group by dtb_class.class_id, dtb_class.name";
840        $objQuery = new SC_Query();
841        $arrList = $objQuery->getAll($sql);
842        // キーと値をセットした配列を取得
843        $arrRet = SC_Utils::sfArrKeyValue($arrList, 'class_id', 'count');
844
845        return $arrRet;
846    }
847
848    function sfGetProductClassId($product_id, $classcategory_id1, $classcategory_id2) {
849        // $where = "product_id = ? AND classcategory_id1 = ? AND classcategory_id2 = ?";
850        $where = "product_id = ?";
851        $objQuery = new SC_Query();
852        // $ret = $objQuery->get("dtb_products_class", "product_class_id", $where, Array($product_id, $classcategory_id1, $classcategory_id2));
853        $ret = $objQuery->get("dtb_products_class", "product_class_id", $where, Array($product_id));
854        return $ret;
855    }
856
857    /* 文末の「/」をなくす */
858    function sfTrimURL($url) {
859        $ret = ereg_replace("[/]+$", "", $url);
860        return $ret;
861    }
862
863    /* DBから取り出した日付の文字列を調整する。*/
864    function sfDispDBDate($dbdate, $time = true) {
865        list($y, $m, $d, $H, $M) = split("[- :]", $dbdate);
866
867        if(strlen($y) > 0 && strlen($m) > 0 && strlen($d) > 0) {
868            if ($time) {
869                $str = sprintf("%04d/%02d/%02d %02d:%02d", $y, $m, $d, $H, $M);
870            } else {
871                $str = sprintf("%04d/%02d/%02d", $y, $m, $d, $H, $M);
872            }
873        } else {
874            $str = "";
875        }
876        return $str;
877    }
878
879    /* 配列をキー名ごとの配列に変更する */
880    function sfSwapArray($array, $isColumnName = true) {
881        $arrRet = array();
882        $max = count($array);
883        for($i = 0; $i < $max; $i++) {
884            $j = 0;
885            foreach($array[$i] as $key => $val) {
886                if ($isColumnName) {
887                    $arrRet[$key][] = $val;
888                } else {
889                    $arrRet[$j][] = $val;
890                }
891                $j++;
892            }
893        }
894        return $arrRet;
895    }
896
897    /**
898     * 連想配列から新たな配列を生成して返す.
899     *
900     * $requires が指定された場合, $requires に含まれるキーの値のみを返す.
901     *
902     * @param array 連想配列
903     * @param array 必須キーの配列
904     * @return array 連想配列の値のみの配列
905     */
906    function getHash2Array($hash, $requires = array()) {
907        $array = array();
908        $i = 0;
909        foreach ($hash as $key => $val) {
910            if (!empty($requires)) {
911                if (in_array($key, $requires)) {
912                    $array[$i] = $val;
913                    $i++;
914                }
915            } else {
916                $array[$i] = $val;
917                $i++;
918            }
919        }
920        return $array;
921    }
922
923    /* かけ算をする(Smarty用) */
924    function sfMultiply($num1, $num2) {
925        return ($num1 * $num2);
926    }
927
928    /**
929     * 加算ポイントの計算
930     *
931     * ・店舗基本情報に基づいた計算は SC_Helper_DB::sfGetAddPoint() を使用する
932     *
933     * @param integer $totalpoint
934     * @param integer $use_point
935     * @param integer $point_rate
936     * @return integer 加算ポイント
937     */
938    function sfGetAddPoint($totalpoint, $use_point, $point_rate) {
939        // 購入商品の合計ポイントから利用したポイントのポイント換算価値を引く方式
940        $add_point = $totalpoint - intval($use_point * ($point_rate / 100));
941
942        if($add_point < 0) {
943            $add_point = '0';
944        }
945        return $add_point;
946    }
947
948    /* 一意かつ予測されにくいID */
949    function sfGetUniqRandomId($head = "") {
950        // 予測されないようにランダム文字列を付与する。
951        $random = GC_Utils_Ex::gfMakePassword(8);
952        // 同一ホスト内で一意なIDを生成
953        $id = uniqid($head);
954        return ($id . $random);
955    }
956
957    /* 文字列に強制的に改行を入れる */
958    function sfPutBR($str, $size) {
959        $i = 0;
960        $cnt = 0;
961        $line = array();
962        $ret = "";
963
964        while($str[$i] != "") {
965            $line[$cnt].=$str[$i];
966            $i++;
967            if(strlen($line[$cnt]) > $size) {
968                $line[$cnt].="<br />";
969                $cnt++;
970            }
971        }
972
973        foreach($line as $val) {
974            $ret.=$val;
975        }
976        return $ret;
977    }
978
979    // 二回以上繰り返されているスラッシュ[/]を一つに変換する。
980    function sfRmDupSlash($istr){
981        if(ereg("^http://", $istr)) {
982            $str = substr($istr, 7);
983            $head = "http://";
984        } else if(ereg("^https://", $istr)) {
985            $str = substr($istr, 8);
986            $head = "https://";
987        } else {
988            $str = $istr;
989        }
990        $str = ereg_replace("[/]+", "/", $str);
991        $ret = $head . $str;
992        return $ret;
993    }
994
995    /**
996     * テキストファイルの文字エンコーディングを変換する.
997     *
998     * $filepath に存在するテキストファイルの文字エンコーディングを変換する.
999     * 変換前の文字エンコーディングは, mb_detect_order で設定した順序で自動検出する.
1000     * 変換後は, 変換前のファイル名に「enc_」というプレフィクスを付与し,
1001     * $out_dir で指定したディレクトリへ出力する
1002     *
1003     * TODO $filepath のファイルがバイナリだった場合の扱い
1004     * TODO fwrite などでのエラーハンドリング
1005     *
1006     * @access public
1007     * @param string $filepath 変換するテキストファイルのパス
1008     * @param string $enc_type 変換後のファイルエンコーディングの種類を表す文字列
1009     * @param string $out_dir 変換後のファイルを出力するディレクトリを表す文字列
1010     * @return string 変換後のテキストファイルのパス
1011     */
1012    function sfEncodeFile($filepath, $enc_type, $out_dir) {
1013        $ifp = fopen($filepath, "r");
1014
1015        // 正常にファイルオープンした場合
1016        if ($ifp !== false) {
1017
1018            $basename = basename($filepath);
1019            $outpath = $out_dir . "enc_" . $basename;
1020
1021            $ofp = fopen($outpath, "w+");
1022
1023            while(!feof($ifp)) {
1024                $line = fgets($ifp);
1025                $line = mb_convert_encoding($line, $enc_type, "auto");
1026                fwrite($ofp,  $line);
1027            }
1028
1029            fclose($ofp);
1030            fclose($ifp);
1031        }
1032        // ファイルが開けなかった場合はエラーページを表示
1033          else {
1034              SC_Utils::sfDispError('');
1035              exit;
1036        }
1037        return     $outpath;
1038    }
1039
1040    function sfCutString($str, $len, $byte = true, $commadisp = true) {
1041        if($byte) {
1042            if(strlen($str) > ($len + 2)) {
1043                $ret =substr($str, 0, $len);
1044                $cut = substr($str, $len);
1045            } else {
1046                $ret = $str;
1047                $commadisp = false;
1048            }
1049        } else {
1050            if(mb_strlen($str) > ($len + 1)) {
1051                $ret = mb_substr($str, 0, $len);
1052                $cut = mb_substr($str, $len);
1053            } else {
1054                $ret = $str;
1055                $commadisp = false;
1056            }
1057        }
1058
1059        // 絵文字タグの途中で分断されないようにする。
1060        if (isset($cut)) {
1061            // 分割位置より前の最後の [ 以降を取得する。
1062            $head = strrchr($ret, '[');
1063
1064            // 分割位置より後の最初の ] 以前を取得する。
1065            $tail_pos = strpos($cut, ']');
1066            if ($tail_pos !== false) {
1067                $tail = substr($cut, 0, $tail_pos + 1);
1068            }
1069
1070            // 分割位置より前に [、後に ] が見つかった場合は、[ から ] までを
1071            // 接続して絵文字タグ1個分になるかどうかをチェックする。
1072            if ($head !== false && $tail_pos !== false) {
1073                $subject = $head . $tail;
1074                if (preg_match('/^\[emoji:e?\d+\]$/', $subject)) {
1075                    // 絵文字タグが見つかったので削除する。
1076                    $ret = substr($ret, 0, -strlen($head));
1077                }
1078            }
1079        }
1080
1081        if($commadisp){
1082            $ret = $ret . "...";
1083        }
1084        return $ret;
1085    }
1086
1087    // 年、月、締め日から、先月の締め日+1、今月の締め日を求める。
1088    function sfTermMonth($year, $month, $close_day) {
1089        $end_year = $year;
1090        $end_month = $month;
1091
1092        // 開始月が終了月と同じか否か
1093        $same_month = false;
1094
1095        // 該当月の末日を求める。
1096        $end_last_day = date("d", mktime(0, 0, 0, $month + 1, 0, $year));
1097
1098        // 月の末日が締め日より少ない場合
1099        if($end_last_day < $close_day) {
1100            // 締め日を月末日に合わせる
1101            $end_day = $end_last_day;
1102        } else {
1103            $end_day = $close_day;
1104        }
1105
1106        // 前月の取得
1107        $tmp_year = date("Y", mktime(0, 0, 0, $month, 0, $year));
1108        $tmp_month = date("m", mktime(0, 0, 0, $month, 0, $year));
1109        // 前月の末日を求める。
1110        $start_last_day = date("d", mktime(0, 0, 0, $month, 0, $year));
1111
1112        // 前月の末日が締め日より少ない場合
1113        if ($start_last_day < $close_day) {
1114            // 月末日に合わせる
1115            $tmp_day = $start_last_day;
1116        } else {
1117            $tmp_day = $close_day;
1118        }
1119
1120        // 先月の末日の翌日を取得する
1121        $start_year = date("Y", mktime(0, 0, 0, $tmp_month, $tmp_day + 1, $tmp_year));
1122        $start_month = date("m", mktime(0, 0, 0, $tmp_month, $tmp_day + 1, $tmp_year));
1123        $start_day = date("d", mktime(0, 0, 0, $tmp_month, $tmp_day + 1, $tmp_year));
1124
1125        // 日付の作成
1126        $start_date = sprintf("%d/%d/%d 00:00:00", $start_year, $start_month, $start_day);
1127        $end_date = sprintf("%d/%d/%d 23:59:59", $end_year, $end_month, $end_day);
1128
1129        return array($start_date, $end_date);
1130    }
1131
1132    // PDF用のRGBカラーを返す
1133    function sfGetPdfRgb($hexrgb) {
1134        $hex = substr($hexrgb, 0, 2);
1135        $r = hexdec($hex) / 255;
1136
1137        $hex = substr($hexrgb, 2, 2);
1138        $g = hexdec($hex) / 255;
1139
1140        $hex = substr($hexrgb, 4, 2);
1141        $b = hexdec($hex) / 255;
1142
1143        return array($r, $g, $b);
1144    }
1145
1146    // 再帰的に多段配列を検索して一次元配列(Hidden引渡し用配列)に変換する。
1147    function sfMakeHiddenArray($arrSrc, $arrDst = array(), $parent_key = "") {
1148        if(is_array($arrSrc)) {
1149            foreach($arrSrc as $key => $val) {
1150                if($parent_key != "") {
1151                    $keyname = $parent_key . "[". $key . "]";
1152                } else {
1153                    $keyname = $key;
1154                }
1155                if(is_array($val)) {
1156                    $arrDst = SC_Utils::sfMakeHiddenArray($val, $arrDst, $keyname);
1157                } else {
1158                    $arrDst[$keyname] = $val;
1159                }
1160            }
1161        }
1162        return $arrDst;
1163    }
1164
1165    // DB取得日時をタイムに変換
1166    function sfDBDatetoTime($db_date) {
1167        $date = ereg_replace("\..*$","",$db_date);
1168        $time = strtotime($date);
1169        return $time;
1170    }
1171
1172    /**
1173     * テンプレートを切り替えて出力する
1174     *
1175     * @deprecated 2008/04/02以降使用不可
1176     */
1177    function sfCustomDisplay(&$objPage, $is_mobile = false) {
1178        $basename = basename($_SERVER["REQUEST_URI"]);
1179
1180        if($basename == "") {
1181            $path = $_SERVER["REQUEST_URI"] . DIR_INDEX_URL;
1182        } else {
1183            $path = $_SERVER["REQUEST_URI"];
1184        }
1185
1186        if(isset($_GET['tpl']) && $_GET['tpl'] != "") {
1187            $tpl_name = $_GET['tpl'];
1188        } else {
1189            $tpl_name = ereg_replace("^/", "", $path);
1190            $tpl_name = ereg_replace("/", "_", $tpl_name);
1191            $tpl_name = ereg_replace("(\.php$|\.html$)", ".tpl", $tpl_name);
1192        }
1193
1194        $template_path = TEMPLATE_FTP_DIR . $tpl_name;
1195echo $template_path;
1196        if($is_mobile === true) {
1197            $objView = new SC_MobileView();
1198            $objView->assignobj($objPage);
1199            $objView->display(SITE_FRAME);
1200        } else if(file_exists($template_path)) {
1201            $objView = new SC_UserView(TEMPLATE_FTP_DIR, COMPILE_FTP_DIR);
1202            $objView->assignobj($objPage);
1203            $objView->display($tpl_name);
1204        } else {
1205            $objView = new SC_SiteView();
1206            $objView->assignobj($objPage);
1207            $objView->display(SITE_FRAME);
1208        }
1209    }
1210
1211    // PHPのmb_convert_encoding関数をSmartyでも使えるようにする
1212    function sf_mb_convert_encoding($str, $encode = 'CHAR_CODE') {
1213        return  mb_convert_encoding($str, $encode);
1214    }
1215
1216    // PHPのmktime関数をSmartyでも使えるようにする
1217    function sf_mktime($format, $hour=0, $minute=0, $second=0, $month=1, $day=1, $year=1999) {
1218        return  date($format,mktime($hour, $minute, $second, $month, $day, $year));
1219    }
1220
1221    // PHPのdate関数をSmartyでも使えるようにする
1222    function sf_date($format, $timestamp = '') {
1223        return  date( $format, $timestamp);
1224    }
1225
1226    // チェックボックスの型を変換する
1227    function sfChangeCheckBox($data , $tpl = false){
1228        if ($tpl) {
1229            if ($data == 1){
1230                return 'checked';
1231            }else{
1232                return "";
1233            }
1234        }else{
1235            if ($data == "on"){
1236                return 1;
1237            }else{
1238                return 2;
1239            }
1240        }
1241    }
1242
1243    // 2つの配列を用いて連想配列を作成する
1244    function sfarrCombine($arrKeys, $arrValues) {
1245
1246        if(count($arrKeys) <= 0 and count($arrValues) <= 0) return array();
1247
1248        $keys = array_values($arrKeys);
1249        $vals = array_values($arrValues);
1250
1251        $max = max( count( $keys ), count( $vals ) );
1252        $combine_ary = array();
1253        for($i=0; $i<$max; $i++) {
1254            $combine_ary[$keys[$i]] = $vals[$i];
1255        }
1256        if(is_array($combine_ary)) return $combine_ary;
1257
1258        return false;
1259    }
1260
1261    /* 子ID所属する親IDを取得する */
1262    function sfGetParentsArraySub($arrData, $pid_name, $id_name, $child) {
1263        $max = count($arrData);
1264        $parent = "";
1265        for($i = 0; $i < $max; $i++) {
1266            if($arrData[$i][$id_name] == $child) {
1267                $parent = $arrData[$i][$pid_name];
1268                break;
1269            }
1270        }
1271        return $parent;
1272    }
1273
1274    /* 階層構造のテーブルから与えられたIDの兄弟を取得する */
1275    function sfGetBrothersArray($arrData, $pid_name, $id_name, $arrPID) {
1276        $max = count($arrData);
1277
1278        $arrBrothers = array();
1279        foreach($arrPID as $id) {
1280            // 親IDを検索する
1281            for($i = 0; $i < $max; $i++) {
1282                if($arrData[$i][$id_name] == $id) {
1283                    $parent = $arrData[$i][$pid_name];
1284                    break;
1285                }
1286            }
1287            // 兄弟IDを検索する
1288            for($i = 0; $i < $max; $i++) {
1289                if($arrData[$i][$pid_name] == $parent) {
1290                    $arrBrothers[] = $arrData[$i][$id_name];
1291                }
1292            }
1293        }
1294        return $arrBrothers;
1295    }
1296
1297    /* 階層構造のテーブルから与えられたIDの直属の子を取得する */
1298    function sfGetUnderChildrenArray($arrData, $pid_name, $id_name, $parent) {
1299        $max = count($arrData);
1300
1301        $arrChildren = array();
1302        // 子IDを検索する
1303        for($i = 0; $i < $max; $i++) {
1304            if($arrData[$i][$pid_name] == $parent) {
1305                $arrChildren[] = $arrData[$i][$id_name];
1306            }
1307        }
1308        return $arrChildren;
1309    }
1310
1311    /**
1312     * SQLシングルクォート対応
1313     * @deprecated SC_Query::quote() を使用すること
1314     */
1315    function sfQuoteSmart($in){
1316
1317        if (is_int($in) || is_double($in)) {
1318            return $in;
1319        } elseif (is_bool($in)) {
1320            return $in ? 1 : 0;
1321        } elseif (is_null($in)) {
1322            return 'NULL';
1323        } else {
1324            return "'" . str_replace("'", "''", $in) . "'";
1325        }
1326    }
1327
1328    // ディレクトリを再帰的に生成する
1329    function sfMakeDir($path) {
1330        static $count = 0;
1331        $count++;  // 無限ループ回避
1332        $dir = dirname($path);
1333        if(ereg("^[/]$", $dir) || ereg("^[A-Z]:[\\]$", $dir) || $count > 256) {
1334            // ルートディレクトリで終了
1335            return;
1336        } else {
1337            if(is_writable(dirname($dir))) {
1338                if(!file_exists($dir)) {
1339                    mkdir($dir);
1340                    GC_Utils::gfPrintLog("mkdir $dir");
1341                }
1342            } else {
1343                SC_Utils::sfMakeDir($dir);
1344                if(is_writable(dirname($dir))) {
1345                    if(!file_exists($dir)) {
1346                        mkdir($dir);
1347                        GC_Utils::gfPrintLog("mkdir $dir");
1348                    }
1349                }
1350           }
1351        }
1352        return;
1353    }
1354
1355    // ディレクトリ以下のファイルを再帰的にコピー
1356    function sfCopyDir($src, $des, $mess = "", $override = false){
1357        if(!is_dir($src)){
1358            return false;
1359        }
1360
1361        $oldmask = umask(0);
1362        $mod= stat($src);
1363
1364        // ディレクトリがなければ作成する
1365        if(!file_exists($des)) {
1366            if(!mkdir($des, $mod[2])) {
1367                print("path:" . $des);
1368            }
1369        }
1370
1371        $fileArray=glob( $src."*" );
1372        if (is_array($fileArray)) {
1373            foreach( $fileArray as $key => $data_ ){
1374                // CVS管理ファイルはコピーしない
1375                if(ereg("/CVS/Entries", $data_)) {
1376                    break;
1377                }
1378                if(ereg("/CVS/Repository", $data_)) {
1379                    break;
1380                }
1381                if(ereg("/CVS/Root", $data_)) {
1382                    break;
1383                }
1384
1385                mb_ereg("^(.*[\/])(.*)",$data_, $matches);
1386                $data=$matches[2];
1387                if( is_dir( $data_ ) ){
1388                    $mess = SC_Utils::sfCopyDir( $data_.'/', $des.$data.'/', $mess);
1389                }else{
1390                    if(!$override && file_exists($des.$data)) {
1391                        $mess.= $des.$data . ":ファイルが存在します\n";
1392                    } else {
1393                        if(@copy( $data_, $des.$data)) {
1394                            $mess.= $des.$data . ":コピー成功\n";
1395                        } else {
1396                            $mess.= $des.$data . ":コピー失敗\n";
1397                        }
1398                    }
1399                    $mod=stat($data_ );
1400                }
1401            }
1402        }
1403        umask($oldmask);
1404        return $mess;
1405    }
1406
1407    // 指定したフォルダ内のファイルを全て削除する
1408    function sfDelFile($dir){
1409        if(file_exists($dir)) {
1410            $dh = opendir($dir);
1411            // フォルダ内のファイルを削除
1412            while($file = readdir($dh)){
1413                if ($file == "." or $file == "..") continue;
1414                $del_file = $dir . "/" . $file;
1415                if(is_file($del_file)){
1416                    $ret = unlink($dir . "/" . $file);
1417                }else if (is_dir($del_file)){
1418                    $ret = SC_Utils::sfDelFile($del_file);
1419                }
1420
1421                if(!$ret){
1422                    return $ret;
1423                }
1424            }
1425
1426            // 閉じる
1427            closedir($dh);
1428
1429            // フォルダを削除
1430            return rmdir($dir);
1431        }
1432    }
1433
1434    /*
1435     * 関数名:sfWriteFile
1436     * 引数1 :書き込むデータ
1437     * 引数2 :ファイルパス
1438     * 引数3 :書き込みタイプ
1439     * 引数4 :パーミッション
1440     * 戻り値:結果フラグ 成功なら true 失敗なら false
1441     * 説明 :ファイル書き出し
1442     */
1443    function sfWriteFile($str, $path, $type, $permission = "") {
1444        //ファイルを開く
1445        if (!($file = fopen ($path, $type))) {
1446            return false;
1447        }
1448
1449        //ファイルロック
1450        flock ($file, LOCK_EX);
1451        //ファイルの書き込み
1452        fputs ($file, $str);
1453        //ファイルロックの解除
1454        flock ($file, LOCK_UN);
1455        //ファイルを閉じる
1456        fclose ($file);
1457        // 権限を指定
1458        if($permission != "") {
1459            chmod($path, $permission);
1460        }
1461
1462        return true;
1463    }
1464
1465    /**
1466     * ブラウザに強制的に送出する
1467     *
1468     * @param boolean|string $output 半角スペース256文字+改行を出力するか。または、送信する文字列を指定。
1469     * @return void
1470     */
1471    function sfFlush($output = false, $sleep = 0){
1472        // 出力をバッファリングしない(==日本語自動変換もしない)
1473        while (@ob_end_flush());
1474
1475        if ($output === true) {
1476            // IEのために半角スペース256文字+改行を出力
1477            //echo str_repeat(' ', 256) . "\n";
1478            echo str_pad('', 256) . "\n";
1479        } else if ($output !== false) {
1480            echo $output;
1481        }
1482
1483        // 出力をフラッシュする
1484        flush();
1485
1486        ob_start();
1487
1488        // 時間のかかる処理
1489        sleep($sleep);
1490    }
1491
1492    // @versionの記載があるファイルからバージョンを取得する。
1493    function sfGetFileVersion($path) {
1494        if(file_exists($path)) {
1495            $src_fp = fopen($path, "rb");
1496            if($src_fp) {
1497                while (!feof($src_fp)) {
1498                    $line = fgets($src_fp);
1499                    if(ereg("@version", $line)) {
1500                        $arrLine = split(" ", $line);
1501                        $version = $arrLine[5];
1502                    }
1503                }
1504                fclose($src_fp);
1505            }
1506        }
1507        return $version;
1508    }
1509
1510    // 指定したURLに対してPOSTでデータを送信する
1511    function sfSendPostData($url, $arrData, $arrOkCode = array()){
1512        require_once(DATA_PATH . "module/Request.php");
1513
1514        // 送信インスタンス生成
1515        $req = new HTTP_Request($url);
1516
1517        $req->addHeader('User-Agent', 'DoCoMo/2.0 P2101V(c100)');
1518        $req->setMethod(HTTP_REQUEST_METHOD_POST);
1519
1520        // POSTデータ送信
1521        $req->addPostDataArray($arrData);
1522
1523        // エラーが無ければ、応答情報を取得する
1524        if (!PEAR::isError($req->sendRequest())) {
1525
1526            // レスポンスコードがエラー判定なら、空を返す
1527            $res_code = $req->getResponseCode();
1528
1529            if(!in_array($res_code, $arrOkCode)){
1530                $response = "";
1531            }else{
1532                $response = $req->getResponseBody();
1533            }
1534
1535        } else {
1536            $response = "";
1537        }
1538
1539        // POSTデータクリア
1540        $req->clearPostData();
1541
1542        return $response;
1543    }
1544
1545    /**
1546     * $array の要素を $arrConvList で指定した方式で mb_convert_kana を適用する.
1547     *
1548     * @param array $array 変換する文字列の配列
1549     * @param array $arrConvList mb_convert_kana の適用ルール
1550     * @return array 変換後の配列
1551     * @see mb_convert_kana
1552     */
1553    function mbConvertKanaWithArray($array, $arrConvList) {
1554        foreach ($arrConvList as $key => $val) {
1555            if(isset($array[$key])) {
1556                $array[$key] = mb_convert_kana($array[$key] ,$val);
1557            }
1558        }
1559        return $array;
1560    }
1561
1562    /**
1563     * 配列の添字が未定義の場合は空文字を代入して定義する.
1564     *
1565     * @param array $array 添字をチェックする配列
1566     * @param array $defineIndexes チェックする添字
1567     * @return array 添字を定義した配列
1568     */
1569    function arrayDefineIndexes($array, $defineIndexes) {
1570        foreach ($defineIndexes as $key) {
1571            if (!isset($array[$key])) $array[$key] = "";
1572        }
1573        return $array;
1574    }
1575
1576    /**
1577     * $arrSrc のうち、キーが $arrKey に含まれるものを返す
1578     *
1579     * $arrSrc に含まない要素は返されない。
1580     *
1581     * @param array $arrSrc
1582     * @param array $arrKey
1583     * @return array
1584     */
1585    function sfArrayIntersectKeys($arrSrc, $arrKey) {
1586        $arrRet = array();
1587        foreach ($arrKey as $key) {
1588            if (isset($arrSrc[$key])) $arrRet[$key] = $arrSrc[$key];
1589        }
1590        return $arrRet;
1591    }
1592
1593    /**
1594     * XML宣言を出力する.
1595     *
1596     * XML宣言があると問題が発生する UA は出力しない.
1597     *
1598     * @return string XML宣言の文字列
1599     */
1600    function printXMLDeclaration() {
1601        $ua = $_SERVER['HTTP_USER_AGENT'];
1602        if (!preg_match("/MSIE/", $ua) || preg_match("/MSIE 7/", $ua)) {
1603            print("<?xml version='1.0' encoding='" . CHAR_CODE . "'?>\n");
1604        }
1605    }
1606
1607    /*
1608     * 関数名:sfGetFileList()
1609     * 説明 :指定パス配下のディレクトリ取得
1610     * 引数1 :取得するディレクトリパス
1611     */
1612    function sfGetFileList($dir) {
1613        $arrFileList = array();
1614        $arrDirList = array();
1615
1616        if (is_dir($dir)) {
1617            if ($dh = opendir($dir)) {
1618                $cnt = 0;
1619                // 行末の/を取り除く
1620                while (($file = readdir($dh)) !== false) $arrDir[] = $file;
1621                $dir = ereg_replace("/$", "", $dir);
1622                // アルファベットと数字でソート
1623                natcasesort($arrDir);
1624                foreach($arrDir as $file) {
1625                    // ./ と ../を除くファイルのみを取得
1626                    if($file != "." && $file != "..") {
1627
1628                        $path = $dir."/".$file;
1629                        // SELECT内の見た目を整えるため指定文字数で切る
1630                        $file_name = SC_Utils::sfCutString($file, FILE_NAME_LEN);
1631                        $file_size = SC_Utils::sfCutString(SC_Utils::sfGetDirSize($path), FILE_NAME_LEN);
1632                        $file_time = date("Y/m/d", filemtime($path));
1633
1634                        // ディレクトリとファイルで格納配列を変える
1635                        if(is_dir($path)) {
1636                            $arrDirList[$cnt]['file_name'] = $file;
1637                            $arrDirList[$cnt]['file_path'] = $path;
1638                            $arrDirList[$cnt]['file_size'] = $file_size;
1639                            $arrDirList[$cnt]['file_time'] = $file_time;
1640                            $arrDirList[$cnt]['is_dir'] = true;
1641                        } else {
1642                            $arrFileList[$cnt]['file_name'] = $file;
1643                            $arrFileList[$cnt]['file_path'] = $path;
1644                            $arrFileList[$cnt]['file_size'] = $file_size;
1645                            $arrFileList[$cnt]['file_time'] = $file_time;
1646                            $arrFileList[$cnt]['is_dir'] = false;
1647                        }
1648                        $cnt++;
1649                    }
1650                }
1651                closedir($dh);
1652            }
1653        }
1654
1655        // フォルダを先頭にしてマージ
1656        return array_merge($arrDirList, $arrFileList);
1657    }
1658
1659    /*
1660     * 関数名:sfGetDirSize()
1661     * 説明 :指定したディレクトリのバイト数を取得
1662     * 引数1 :ディレクトリ
1663     */
1664    function sfGetDirSize($dir) {
1665        if(file_exists($dir)) {
1666            // ディレクトリの場合下層ファイルの総量を取得
1667            if (is_dir($dir)) {
1668                $handle = opendir($dir);
1669                while ($file = readdir($handle)) {
1670                    // 行末の/を取り除く
1671                    $dir = ereg_replace("/$", "", $dir);
1672                    $path = $dir."/".$file;
1673                    if ($file != '..' && $file != '.' && !is_dir($path)) {
1674                        $bytes += filesize($path);
1675                    } else if (is_dir($path) && $file != '..' && $file != '.') {
1676                        // 下層ファイルのバイト数を取得する為、再帰的に呼び出す。
1677                        $bytes += SC_Utils::sfGetDirSize($path);
1678                    }
1679                }
1680            } else {
1681                // ファイルの場合
1682                $bytes = filesize($dir);
1683            }
1684        }
1685        // ディレクトリ(ファイル)が存在しない場合は0byteを返す
1686        if($bytes == "") $bytes = 0;
1687
1688        return $bytes;
1689    }
1690
1691    /*
1692     * 関数名:sfDeleteDir()
1693     * 説明 :指定したディレクトリを削除
1694     * 引数1 :削除ファイル
1695     */
1696    function sfDeleteDir($dir) {
1697        $arrResult = array();
1698        if(file_exists($dir)) {
1699            // ディレクトリかチェック
1700            if (is_dir($dir)) {
1701                if ($handle = opendir("$dir")) {
1702                    $cnt = 0;
1703                    while (false !== ($item = readdir($handle))) {
1704                        if ($item != "." && $item != "..") {
1705                            if (is_dir("$dir/$item")) {
1706                                sfDeleteDir("$dir/$item");
1707                            } else {
1708                                $arrResult[$cnt]['result'] = @unlink("$dir/$item");
1709                                $arrResult[$cnt]['file_name'] = "$dir/$item";
1710                            }
1711                        }
1712                        $cnt++;
1713                    }
1714                }
1715                closedir($handle);
1716                $arrResult[$cnt]['result'] = @rmdir($dir);
1717                $arrResult[$cnt]['file_name'] = "$dir/$item";
1718            } else {
1719                // ファイル削除
1720                $arrResult[0]['result'] = @unlink("$dir");
1721                $arrResult[0]['file_name'] = "$dir";
1722            }
1723        }
1724
1725        return $arrResult;
1726    }
1727
1728    /*
1729     * 関数名:sfGetFileTree()
1730     * 説明 :ツリー生成用配列取得(javascriptに渡す用)
1731     * 引数1 :ディレクトリ
1732     * 引数2 :現在のツリーの状態開いているフォルダのパスが | 区切りで格納
1733     */
1734    function sfGetFileTree($dir, $tree_status) {
1735
1736        $cnt = 0;
1737        $arrTree = array();
1738        $default_rank = count(split('/', $dir));
1739
1740        // 文末の/を取り除く
1741        $dir = ereg_replace("/$", "", $dir);
1742        // 最上位層を格納(user_data/)
1743        if(sfDirChildExists($dir)) {
1744            $arrTree[$cnt]['type'] = "_parent";
1745        } else {
1746            $arrTree[$cnt]['type'] = "_child";
1747        }
1748        $arrTree[$cnt]['path'] = $dir;
1749        $arrTree[$cnt]['rank'] = 0;
1750        $arrTree[$cnt]['count'] = $cnt;
1751        // 初期表示はオープン
1752        if($_POST['mode'] != '') {
1753            $arrTree[$cnt]['open'] = lfIsFileOpen($dir, $tree_status);
1754        } else {
1755            $arrTree[$cnt]['open'] = true;
1756        }
1757        $cnt++;
1758
1759        sfGetFileTreeSub($dir, $default_rank, $cnt, $arrTree, $tree_status);
1760
1761        return $arrTree;
1762    }
1763
1764    /*
1765     * 関数名:sfGetFileTree()
1766     * 説明 :ツリー生成用配列取得(javascriptに渡す用)
1767     * 引数1 :ディレクトリ
1768     * 引数2 :デフォルトの階層(/区切りで 0,1,2・・・とカウント)
1769     * 引数3 :連番
1770     * 引数4 :現在のツリーの状態開いているフォルダのパスが | 区切りで格納
1771     */
1772    function sfGetFileTreeSub($dir, $default_rank, &$cnt, &$arrTree, $tree_status) {
1773
1774        if(file_exists($dir)) {
1775            if ($handle = opendir("$dir")) {
1776                while (false !== ($item = readdir($handle))) $arrDir[] = $item;
1777                // アルファベットと数字でソート
1778                natcasesort($arrDir);
1779                foreach($arrDir as $item) {
1780                    if ($item != "." && $item != "..") {
1781                        // 文末の/を取り除く
1782                        $dir = ereg_replace("/$", "", $dir);
1783                        $path = $dir."/".$item;
1784                        // ディレクトリのみ取得
1785                        if (is_dir($path)) {
1786                            $arrTree[$cnt]['path'] = $path;
1787                            if(sfDirChildExists($path)) {
1788                                $arrTree[$cnt]['type'] = "_parent";
1789                            } else {
1790                                $arrTree[$cnt]['type'] = "_child";
1791                            }
1792
1793                            // 階層を割り出す
1794                            $arrCnt = split('/', $path);
1795                            $rank = count($arrCnt);
1796                            $arrTree[$cnt]['rank'] = $rank - $default_rank + 1;
1797                            $arrTree[$cnt]['count'] = $cnt;
1798                            // フォルダが開いているか
1799                            $arrTree[$cnt]['open'] = lfIsFileOpen($path, $tree_status);
1800                            $cnt++;
1801                            // 下層ディレクトリ取得の為、再帰的に呼び出す
1802                            sfGetFileTreeSub($path, $default_rank, $cnt, $arrTree, $tree_status);
1803                        }
1804                    }
1805                }
1806            }
1807            closedir($handle);
1808        }
1809    }
1810
1811    /*
1812     * 関数名:sfDirChildExists()
1813     * 説明 :指定したディレクトリ配下にファイルがあるか
1814     * 引数1 :ディレクトリ
1815     */
1816    function sfDirChildExists($dir) {
1817        if(file_exists($dir)) {
1818            if (is_dir($dir)) {
1819                $handle = opendir($dir);
1820                while ($file = readdir($handle)) {
1821                    // 行末の/を取り除く
1822                    $dir = ereg_replace("/$", "", $dir);
1823                    $path = $dir."/".$file;
1824                    if ($file != '..' && $file != '.' && is_dir($path)) {
1825                        return true;
1826                    }
1827                }
1828            }
1829        }
1830
1831        return false;
1832    }
1833
1834    /*
1835     * 関数名:lfIsFileOpen()
1836     * 説明 :指定したファイルが前回開かれた状態にあったかチェック
1837     * 引数1 :ディレクトリ
1838     * 引数2 :現在のツリーの状態開いているフォルダのパスが | 区切りで格納
1839     */
1840    function lfIsFileOpen($dir, $tree_status) {
1841        $arrTreeStatus = split('\|', $tree_status);
1842        if(in_array($dir, $arrTreeStatus)) {
1843            return true;
1844        }
1845
1846        return false;
1847    }
1848
1849    /*
1850     * 関数名:sfDownloadFile()
1851     * 引数1 :ファイルパス
1852     * 説明 :ファイルのダウンロード
1853     */
1854    function sfDownloadFile($file) {
1855         // ファイルの場合はダウンロードさせる
1856        Header("Content-disposition: attachment; filename=".basename($file));
1857        Header("Content-type: application/octet-stream; name=".basename($file));
1858        Header("Cache-Control: ");
1859        Header("Pragma: ");
1860        echo (sfReadFile($file));
1861    }
1862
1863    /*
1864     * 関数名:sfCreateFile()
1865     * 引数1 :ファイルパス
1866     * 引数2 :パーミッション
1867     * 説明 :ファイル作成
1868     */
1869    function sfCreateFile($file, $mode = "") {
1870        // 行末の/を取り除く
1871        if($mode != "") {
1872            $ret = @mkdir($file, $mode);
1873        } else {
1874            $ret = @mkdir($file);
1875        }
1876
1877        return $ret;
1878    }
1879
1880    /*
1881     * 関数名:sfReadFile()
1882     * 引数1 :ファイルパス
1883     * 説明 :ファイル読込
1884     */
1885    function sfReadFile($filename) {
1886        $str = "";
1887        // バイナリモードでオープン
1888        $fp = @fopen($filename, "rb" );
1889        //ファイル内容を全て変数に読み込む
1890        if($fp) {
1891            $str = @fread($fp, filesize($filename)+1);
1892        }
1893        @fclose($fp);
1894
1895        return $str;
1896    }
1897
1898   /**
1899     * CSV出力用データ取得
1900     *
1901     * @return string
1902     */
1903    function getCSVData($array, $arrayIndex) {
1904        for ($i = 0; $i < count($array); $i++){
1905            // インデックスが設定されている場合
1906            if (is_array($arrayIndex) && 0 < count($arrayIndex)){
1907                for ($j = 0; $j < count($arrayIndex); $j++ ){
1908                    if ( $j > 0 ) $return .= ",";
1909                    $return .= "\"";
1910                    $return .= mb_ereg_replace("<","<",mb_ereg_replace( "\"","\"\"",$array[$i][$arrayIndex[$j]] )) ."\"";
1911                }
1912            } else {
1913                for ($j = 0; $j < count($array[$i]); $j++ ){
1914                    if ( $j > 0 ) $return .= ",";
1915                    $return .= "\"";
1916                    $return .= mb_ereg_replace("<","<",mb_ereg_replace( "\"","\"\"",$array[$i][$j] )) ."\"";
1917                }
1918            }
1919            $return .= "\n";
1920        }
1921        return $return;
1922    }
1923
1924   /**
1925     * 配列をテーブルタグで出力する。
1926     *
1927     * @return string
1928     */
1929    function getTableTag($array) {
1930        $html = "<table>";
1931        $html.= "<tr>";
1932        foreach($array[0] as $key => $val) {
1933            $html.="<th>$key</th>";
1934        }
1935        $html.= "</tr>";
1936
1937        $cnt = count($array);
1938
1939        for($i = 0; $i < $cnt; $i++) {
1940            $html.= "<tr>";
1941            foreach($array[$i] as $val) {
1942                $html.="<td>$val</td>";
1943            }
1944            $html.= "</tr>";
1945        }
1946        return $html;
1947    }
1948
1949   /**
1950     * 一覧-メイン画像のファイル指定がない場合、専用の画像ファイルに書き換える。
1951     *
1952     * @param string &$filename ファイル名
1953     * @return string
1954     */
1955    function sfNoImageMainList($filename = '') {
1956        if (strlen($filename) == 0 || substr($filename, -1, 1) == '/') {
1957            $filename .= 'noimage_main_list.jpg';
1958        }
1959        return $filename;
1960    }
1961
1962   /**
1963     * 詳細-メイン画像のファイル指定がない場合、専用の画像ファイルに書き換える。
1964     *
1965     * @param string &$filename ファイル名
1966     * @return string
1967     */
1968    function sfNoImageMain($filename = '') {
1969        if (strlen($filename) == 0 || substr($filename, -1, 1) == '/') {
1970            $filename .= 'noimage_main.png';
1971        }
1972        return $filename;
1973    }
1974
1975    /* デバッグ用 ------------------------------------------------------------------------------------------------*/
1976    function sfPrintR($obj) {
1977        print("<div style='font-size: 12px;color: #00FF00;'>\n");
1978        print("<strong>**デバッグ中**</strong><br />\n");
1979        print("<pre>\n");
1980        //print_r($obj);
1981        var_dump($obj);
1982        print("</pre>\n");
1983        print("<strong>**デバッグ中**</strong></div>\n");
1984    }
1985
1986    /**
1987     * ポイント使用するかの判定
1988     *
1989     * @param integer $status 対応状況
1990     * @return boolean 使用するか(顧客テーブルから減算するか)
1991     */
1992    function sfIsUsePoint($status) {
1993        switch ($status) {
1994            case ORDER_CANCEL:      // キャンセル
1995                return false;
1996            default:
1997                break;
1998        }
1999
2000        return true;
2001    }
2002
2003    /**
2004     * ポイント加算するかの判定
2005     *
2006     * @param integer $status 対応状況
2007     * @return boolean 加算するか
2008     */
2009    function sfIsAddPoint($status) {
2010        switch ($status) {
2011            case ORDER_NEW:         // 新規注文
2012            case ORDER_PAY_WAIT:    // 入金待ち
2013            case ORDER_PRE_END:     // 入金済み
2014            case ORDER_CANCEL:      // キャンセル
2015            case ORDER_BACK_ORDER:  // 取り寄せ中
2016                return false;
2017
2018            case ORDER_DELIV:       // 発送済み
2019                return true;
2020
2021            default:
2022                break;
2023        }
2024
2025        return false;
2026    }
2027
2028    /**
2029     * ランダムな文字列を取得する
2030     *
2031     * @param integer $length 文字数
2032     * @return string ランダムな文字列
2033     */
2034    function sfGetRandomString($length = 1) {
2035        require_once(dirname(__FILE__) . '/../../module/Text/Password.php');
2036        return Text_Password::create($length);
2037    }
2038
2039    /**
2040     * 現在の URL を取得する
2041     *
2042     * @return string 現在のURL
2043     */
2044    function sfGetUrl() {
2045        $url = '';
2046
2047        if (SC_Utils_Ex::sfIsHTTPS()) {
2048            $url = "https://";
2049        } else {
2050            $url = "http://";
2051        }
2052
2053        $url .= $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . '?' . $_SERVER['QUERY_STRING'];
2054
2055        return $url;
2056    }
2057
2058    /**
2059     * バックトレースをテキスト形式で出力する
2060     *
2061     * @return string テキストで表現したバックトレース
2062     */
2063    function sfBacktraceToString($arrBacktrace) {
2064        $string = '';
2065
2066        foreach (array_reverse($arrBacktrace) as $backtrace) {
2067            if (strlen($backtrace['class']) >= 1) {
2068                $func = $backtrace['class'] . $backtrace['type'] . $backtrace['function'];
2069            } else {
2070                $func = $backtrace['function'];
2071            }
2072
2073            $string .= $backtrace['file'] . " " . $backtrace['line'] . ":" . $func . "\n";
2074        }
2075
2076        return $string;
2077    }
2078
2079    /**
2080     * 管理機能かを判定
2081     *
2082     * @return bool 管理機能か
2083     */
2084    function sfIsAdminFunction() {
2085        return defined('ADMIN_FUNCTION') && ADMIN_FUNCTION;
2086    }
2087
2088    /**
2089     * フロント機能かを判定
2090     *
2091     * @return bool フロント機能か
2092     */
2093    function sfIsFrontFunction() {
2094        return SC_Utils_Ex::sfIsPcSite() || SC_Utils_Ex::sfIsMobileSite();
2095    }
2096
2097    /**
2098     * フロント機能PCサイトかを判定
2099     *
2100     * @return bool フロント機能PCサイトか
2101     */
2102    function sfIsPcSite() {
2103        return defined('FRONT_FUNCTION_PC_SITE') && FRONT_FUNCTION_PC_SITE;
2104    }
2105
2106    /**
2107     * フロント機能モバイル機能かを判定
2108     *
2109     * @return bool フロント機能モバイル機能か
2110     */
2111    function sfIsMobileSite() {
2112        return defined('MOBILE_SITE') && MOBILE_SITE;
2113    }
2114
2115    /**
2116     * インストール機能かを判定
2117     *
2118     * @return bool インストール機能か
2119     */
2120    function sfIsInstallFunction() {
2121        return defined('INSTALL_FUNCTION') && INSTALL_FUNCTION;
2122    }
2123
2124    // 郵便番号から住所の取得
2125    function sfGetAddress($zipcode) {
2126
2127        $objQuery = new SC_Query(ZIP_DSN);
2128
2129        $masterData = new SC_DB_MasterData_Ex();
2130        $arrPref = $masterData->getMasterData("mtb_pref", array("pref_id", "pref_name", "rank"));
2131        // インデックスと値を反転させる。
2132        $arrREV_PREF = array_flip($arrPref);
2133
2134        // 郵便番号検索文作成
2135        $zipcode = mb_convert_kana($zipcode ,"n");
2136        $sqlse = "SELECT state, city, town FROM mtb_zip WHERE zipcode = ?";
2137
2138        $data_list = $objQuery->getAll($sqlse, array($zipcode));
2139        if (empty($data_list)) return array();
2140
2141        /*
2142         総務省からダウンロードしたデータをそのままインポートすると
2143         以下のような文字列が入っているので 対策する。
2144         ・(1・19丁目)
2145         ・以下に掲載がない場合
2146        */
2147        $town =  $data_list[0]['town'];
2148        $town = ereg_replace("(.*)$","",$town);
2149        $town = ereg_replace("以下に掲載がない場合","",$town);
2150        $data_list[0]['town'] = $town;
2151        $data_list[0]['state'] = $arrREV_PREF[$data_list[0]['state']];
2152
2153        return $data_list;
2154    }
2155
2156    /**
2157     * プラグインが配置されているディレクトリ(フルパス)を取得する
2158     *
2159     * @param string $file プラグイン情報ファイル(info.php)のパス
2160     * @return SimpleXMLElement プラグイン XML
2161     */
2162    function sfGetPluginFullPathByRequireFilePath($file) {
2163        return str_replace('\\', '/', dirname($file)) . '/';
2164    }
2165
2166    /**
2167     * プラグインのパスを取得する
2168     *
2169     * @param string $pluginFullPath プラグインが配置されているディレクトリ(フルパス)
2170     * @return SimpleXMLElement プラグイン XML
2171     */
2172    function sfGetPluginPathByPluginFullPath($pluginFullPath) {
2173        return basename(rtrim($pluginFullPath, '/'));
2174    }
2175
2176    /**
2177     * プラグイン情報配列の基本形を作成する
2178     *
2179     * @param string $file プラグイン情報ファイル(info.php)のパス
2180     * @return array プラグイン情報配列
2181     */
2182    function sfMakePluginInfoArray($file) {
2183        $fullPath = SC_Utils_Ex::sfGetPluginFullPathByRequireFilePath($file);
2184
2185        return
2186            array(
2187                // パス
2188                'path' => SC_Utils_Ex::sfGetPluginPathByPluginFullPath($fullPath),
2189                // プラグイン名
2190                'name' => '未定義',
2191                // フルパス
2192                'fullpath' => $fullPath,
2193                // バージョン
2194                'version' => null,
2195                // 著作者
2196                'auther' => '未定義',
2197            )
2198        ;
2199    }
2200
2201    /**
2202     * プラグイン情報配列を取得する
2203     *
2204     * TODO include_once を利用することで例外対応をサボタージュしているのを改善する。
2205     *
2206     * @param string $path プラグインのディレクトリ名
2207     * @return array プラグイン情報配列
2208     */
2209    function sfGetPluginInfoArray($path) {
2210        return (array)include_once(PLUGIN_PATH . "$path/plugin_info.php");
2211    }
2212
2213    /**
2214     * プラグイン XML を読み込む
2215     *
2216     * TODO 空だったときを考慮
2217     *
2218     * @return SimpleXMLElement プラグイン XML
2219     */
2220    function sfGetPluginsXml() {
2221        return simplexml_load_file(PLUGIN_PATH . 'plugins.xml');
2222    }
2223
2224    /**
2225     * プラグイン XML を書き込む
2226     *
2227     * @param SimpleXMLElement $pluginsXml プラグイン XML
2228     * @return integer ファイルに書き込まれたバイト数を返します。
2229     */
2230    function sfPutPluginsXml($pluginsXml) {
2231        if (!($pluginsXml instanceof SimpleXMLElement)) SC_Utils_Ex::sfDispException();
2232
2233        $xml = $pluginsXml->asXML();
2234        if (strlen($xml) == 0) SC_Utils_Ex::sfDispException();
2235
2236        $return = file_put_contents(PLUGIN_PATH . 'plugins.xml', $pluginsXml->asXML());
2237        if ($return === false) SC_Utils_Ex::sfDispException();
2238
2239        return $return;
2240    }
2241
2242    function sfLoadPluginInfo($filenamePluginInfo) {
2243        return (array)include_once $filenamePluginInfo;
2244    }
2245
2246    /**
2247     * 現在の Unix タイムスタンプを float (秒単位) でマイクロ秒まで返す
2248     *
2249     * PHP4の上位互換用途。
2250     * FIXME PHP4でテストする。(現状全くテストしていない。)
2251     * @param SimpleXMLElement $pluginsXml プラグイン XML
2252     * @return integer ファイルに書き込まれたバイト数を返します。
2253     */
2254    function sfMicrotimeFloat() {
2255        $microtime = microtime(true);
2256        if (is_string($microtime)) {
2257            list($usec, $sec) = explode(" ", microtime());
2258            return ((float)$usec + (float)$sec);
2259        }
2260        return $microtime;
2261    }
2262
2263    /**
2264     * 変数が空白かどうかをチェックする.
2265     *
2266     * 引数 $val が空白かどうかをチェックする. 空白の場合は true.
2267     * 以下の文字は空白と判断する.
2268     * - " " (ASCII 32 (0x20)), 通常の空白
2269     * - "\t" (ASCII 9 (0x09)), タブ
2270     * - "\n" (ASCII 10 (0x0A)), リターン
2271     * - "\r" (ASCII 13 (0x0D)), 改行
2272     * - "\0" (ASCII 0 (0x00)), NULバイト
2273     * - "\x0B" (ASCII 11 (0x0B)), 垂直タブ
2274     *
2275     * 引数 $val が配列の場合は, 空の配列の場合 true を返す.
2276     *
2277     * 引数 $greedy が true の場合は, 全角スペース, ネストした空の配列も
2278     * 空白と判断する.
2279     *
2280     * @param mixed $val チェック対象の変数
2281     * @param boolean $greedy "貧欲"にチェックを行う場合 true
2282     * @return boolean $val が空白と判断された場合 true
2283     */
2284    function isBlank($val, $greedy = true) {
2285        if (is_array($val)) {
2286            if ($greedy) {
2287                foreach ($val as $in) {
2288                    if (!SC_Utils::isBlank($in, $greedy)) {
2289                        return false;
2290                    }
2291                }
2292            } else {
2293                return empty($val);
2294            }
2295        }
2296
2297        if ($greedy) {
2298            $val = preg_replace("/ /", "", $val);
2299        }
2300
2301        $val = trim($val);
2302        if (strlen($val) > 0) {
2303            return false;
2304        }
2305        return true;
2306    }
2307}
2308?>
Note: See TracBrowser for help on using the repository browser.