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

Revision 19802, 73.4 KB checked in by Seasoft, 13 years ago (diff)

#834(パラメータの定数名に「URL」を含むにもかかわらず、パスのみのものがある) 一部改修

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