source: branches/version-2_12-dev/data/class/util/SC_Utils.php @ 21445

Revision 21445, 69.7 KB checked in by Seasoft, 12 years ago (diff)

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

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