Warning: Can't use blame annotator:
svn blame failed on branches/version-2_11-dev/data/class/util/SC_Utils.php: バイナリファイル 'file:///home/svn/open/branches/version-2_11-dev/data/class/util/SC_Utils.php' に対しては blame で各行の最終変更者を計算できません 195004

source: branches/version-2_11-dev/data/class/util/SC_Utils.php @ 21241

Revision 21241, 70.9 KB checked in by shutta, 13 years ago (diff)

refs #1476 (インクルードしているライブラリをバージョンアップする)
PEAR::HTTP_Requestのアップデート時にaddPostDataArrayメソッドが削除されてしまったのに対応。
独自に追加していたaddPostDataArrayメソッドの書き換え。

  • 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
RevLine 
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    // 指定したURLに対してPOSTでデータを送信する
1287    function sfSendPostData($url, $arrData, $arrOkCode = array()){
1288        require_once DATA_REALDIR . 'module/HTTP/Request.php';
1289
1290        // 送信インスタンス生成
1291        $req = new HTTP_Request($url);
1292
1293        $req->addHeader('User-Agent', 'DoCoMo/2.0 P2101V(c100)');
1294        $req->setMethod(HTTP_REQUEST_METHOD_POST);
1295
1296        // POSTデータ送信
1297        foreach ($arrData as $key => $val) {
1298            $req->addPostData($key, $val);
1299        }
1300
1301        // エラーが無ければ、応答情報を取得する
1302        if (!PEAR::isError($req->sendRequest())) {
1303
1304            // レスポンスコードがエラー判定なら、空を返す
1305            $res_code = $req->getResponseCode();
1306
1307            if(!in_array($res_code, $arrOkCode)){
1308                $response = "";
1309            }else{
1310                $response = $req->getResponseBody();
1311            }
1312
1313        } else {
1314            $response = "";
1315        }
1316
1317        // POSTデータクリア
1318        $req->clearPostData();
1319
1320        return $response;
1321    }
1322
1323    /**
1324     * $array の要素を $arrConvList で指定した方式で mb_convert_kana を適用する.
1325     *
1326     * @param array $array 変換する文字列の配列
1327     * @param array $arrConvList mb_convert_kana の適用ルール
1328     * @return array 変換後の配列
1329     * @see mb_convert_kana
1330     */
1331    function mbConvertKanaWithArray($array, $arrConvList) {
1332        foreach ($arrConvList as $key => $val) {
1333            if(isset($array[$key])) {
1334                $array[$key] = mb_convert_kana($array[$key] ,$val);
1335            }
1336        }
1337        return $array;
1338    }
1339
1340    /**
1341     * 配列の添字が未定義の場合は空文字を代入して定義する.
1342     *
1343     * @param array $array 添字をチェックする配列
1344     * @param array $defineIndexes チェックする添字
1345     * @return array 添字を定義した配列
1346     */
1347    function arrayDefineIndexes($array, $defineIndexes) {
1348        foreach ($defineIndexes as $key) {
1349            if (!isset($array[$key])) $array[$key] = "";
1350        }
1351        return $array;
1352    }
1353
1354    /**
1355     * $arrSrc のうち、キーが $arrKey に含まれるものを返す
1356     *
1357     * $arrSrc に含まない要素は返されない。
1358     *
1359     * @param array $arrSrc
1360     * @param array $arrKey
1361     * @return array
1362     */
1363    function sfArrayIntersectKeys($arrSrc, $arrKey) {
1364        $arrRet = array();
1365        foreach ($arrKey as $key) {
1366            if (isset($arrSrc[$key])) $arrRet[$key] = $arrSrc[$key];
1367        }
1368        return $arrRet;
1369    }
1370
1371    /**
1372     * XML宣言を出力する.
1373     *
1374     * XML宣言があると問題が発生する UA は出力しない.
1375     *
1376     * @return string XML宣言の文字列
1377     */
1378    function printXMLDeclaration() {
1379        $ua = $_SERVER['HTTP_USER_AGENT'];
1380        if (!preg_match("/MSIE/", $ua) || preg_match("/MSIE 7/", $ua)) {
1381            echo '<?xml version="1.0" encoding="' . CHAR_CODE . '"?>' . "\n";
1382        }
1383    }
1384
1385    /*
1386     * 関数名:sfGetFileList()
1387     * 説明 :指定パス配下のディレクトリ取得
1388     * 引数1 :取得するディレクトリパス
1389     */
1390    function sfGetFileList($dir) {
1391        $arrFileList = array();
1392        $arrDirList = array();
1393
1394        if (is_dir($dir)) {
1395            if ($dh = opendir($dir)) {
1396                $cnt = 0;
1397                // 行末の/を取り除く
1398                while (($file = readdir($dh)) !== false) $arrDir[] = $file;
1399                $dir = ereg_replace("/$", "", $dir);
1400                // アルファベットと数字でソート
1401                natcasesort($arrDir);
1402                foreach($arrDir as $file) {
1403                    // ./ と ../を除くファイルのみを取得
1404                    if($file != "." && $file != "..") {
1405
1406                        $path = $dir."/".$file;
1407                        // SELECT内の見た目を整えるため指定文字数で切る
1408                        $file_name = SC_Utils_Ex::sfCutString($file, FILE_NAME_LEN);
1409                        $file_size = SC_Utils_Ex::sfCutString(SC_Utils_Ex::sfGetDirSize($path), FILE_NAME_LEN);
1410                        $file_time = date("Y/m/d", filemtime($path));
1411
1412                        // ディレクトリとファイルで格納配列を変える
1413                        if(is_dir($path)) {
1414                            $arrDirList[$cnt]['file_name'] = $file;
1415                            $arrDirList[$cnt]['file_path'] = $path;
1416                            $arrDirList[$cnt]['file_size'] = $file_size;
1417                            $arrDirList[$cnt]['file_time'] = $file_time;
1418                            $arrDirList[$cnt]['is_dir'] = true;
1419                        } else {
1420                            $arrFileList[$cnt]['file_name'] = $file;
1421                            $arrFileList[$cnt]['file_path'] = $path;
1422                            $arrFileList[$cnt]['file_size'] = $file_size;
1423                            $arrFileList[$cnt]['file_time'] = $file_time;
1424                            $arrFileList[$cnt]['is_dir'] = false;
1425                        }
1426                        $cnt++;
1427                    }
1428                }
1429                closedir($dh);
1430            }
1431        }
1432
1433        // フォルダを先頭にしてマージ
1434        return array_merge($arrDirList, $arrFileList);
1435    }
1436
1437    /*
1438     * 関数名:sfGetDirSize()
1439     * 説明 :指定したディレクトリのバイト数を取得
1440     * 引数1 :ディレクトリ
1441     */
1442    function sfGetDirSize($dir) {
1443        if(file_exists($dir)) {
1444            // ディレクトリの場合下層ファイルの総量を取得
1445            if (is_dir($dir)) {
1446                $handle = opendir($dir);
1447                while ($file = readdir($handle)) {
1448                    // 行末の/を取り除く
1449                    $dir = ereg_replace("/$", "", $dir);
1450                    $path = $dir."/".$file;
1451                    if ($file != '..' && $file != '.' && !is_dir($path)) {
1452                        $bytes += filesize($path);
1453                    } else if (is_dir($path) && $file != '..' && $file != '.') {
1454                        // 下層ファイルのバイト数を取得する為、再帰的に呼び出す。
1455                        $bytes += SC_Utils_Ex::sfGetDirSize($path);
1456                    }
1457                }
1458            } else {
1459                // ファイルの場合
1460                $bytes = filesize($dir);
1461            }
1462        }
1463        // ディレクトリ(ファイル)が存在しない場合は0byteを返す
1464        if($bytes == "") $bytes = 0;
1465
1466        return $bytes;
1467    }
1468
1469    /*
1470     * 関数名:sfDeleteDir()
1471     * 説明 :指定したディレクトリを削除
1472     * 引数1 :削除ファイル
1473     */
1474    function sfDeleteDir($dir) {
1475        $arrResult = array();
1476        if(file_exists($dir)) {
1477            // ディレクトリかチェック
1478            if (is_dir($dir)) {
1479                if ($handle = opendir("$dir")) {
1480                    $cnt = 0;
1481                    while (false !== ($item = readdir($handle))) {
1482                        if ($item != "." && $item != "..") {
1483                            if (is_dir("$dir/$item")) {
1484                                sfDeleteDir("$dir/$item");
1485                            } else {
1486                                $arrResult[$cnt]['result'] = @unlink("$dir/$item");
1487                                $arrResult[$cnt]['file_name'] = "$dir/$item";
1488                            }
1489                        }
1490                        $cnt++;
1491                    }
1492                }
1493                closedir($handle);
1494                $arrResult[$cnt]['result'] = @rmdir($dir);
1495                $arrResult[$cnt]['file_name'] = "$dir/$item";
1496            } else {
1497                // ファイル削除
1498                $arrResult[0]['result'] = @unlink("$dir");
1499                $arrResult[0]['file_name'] = "$dir";
1500            }
1501        }
1502
1503        return $arrResult;
1504    }
1505
1506    /*
1507     * 関数名:sfGetFileTree()
1508     * 説明 :ツリー生成用配列取得(javascriptに渡す用)
1509     * 引数1 :ディレクトリ
1510     * 引数2 :現在のツリーの状態開いているフォルダのパスが | 区切りで格納
1511     */
1512    function sfGetFileTree($dir, $tree_status) {
1513
1514        $cnt = 0;
1515        $arrTree = array();
1516        $default_rank = count(explode('/', $dir));
1517
1518        // 文末の/を取り除く
1519        $dir = ereg_replace("/$", "", $dir);
1520        // 最上位層を格納(user_data/)
1521        if(sfDirChildExists($dir)) {
1522            $arrTree[$cnt]['type'] = "_parent";
1523        } else {
1524            $arrTree[$cnt]['type'] = "_child";
1525        }
1526        $arrTree[$cnt]['path'] = $dir;
1527        $arrTree[$cnt]['rank'] = 0;
1528        $arrTree[$cnt]['count'] = $cnt;
1529        // 初期表示はオープン
1530        if($_POST['mode'] != '') {
1531            $arrTree[$cnt]['open'] = lfIsFileOpen($dir, $tree_status);
1532        } else {
1533            $arrTree[$cnt]['open'] = true;
1534        }
1535        $cnt++;
1536
1537        sfGetFileTreeSub($dir, $default_rank, $cnt, $arrTree, $tree_status);
1538
1539        return $arrTree;
1540    }
1541
1542    /*
1543     * 関数名:sfGetFileTree()
1544     * 説明 :ツリー生成用配列取得(javascriptに渡す用)
1545     * 引数1 :ディレクトリ
1546     * 引数2 :デフォルトの階層(/区切りで 0,1,2・・・とカウント)
1547     * 引数3 :連番
1548     * 引数4 :現在のツリーの状態開いているフォルダのパスが | 区切りで格納
1549     */
1550    function sfGetFileTreeSub($dir, $default_rank, &$cnt, &$arrTree, $tree_status) {
1551
1552        if(file_exists($dir)) {
1553            if ($handle = opendir("$dir")) {
1554                while (false !== ($item = readdir($handle))) $arrDir[] = $item;
1555                // アルファベットと数字でソート
1556                natcasesort($arrDir);
1557                foreach($arrDir as $item) {
1558                    if ($item != "." && $item != "..") {
1559                        // 文末の/を取り除く
1560                        $dir = ereg_replace("/$", "", $dir);
1561                        $path = $dir."/".$item;
1562                        // ディレクトリのみ取得
1563                        if (is_dir($path)) {
1564                            $arrTree[$cnt]['path'] = $path;
1565                            if(sfDirChildExists($path)) {
1566                                $arrTree[$cnt]['type'] = "_parent";
1567                            } else {
1568                                $arrTree[$cnt]['type'] = "_child";
1569                            }
1570
1571                            // 階層を割り出す
1572                            $arrCnt = explode('/', $path);
1573                            $rank = count($arrCnt);
1574                            $arrTree[$cnt]['rank'] = $rank - $default_rank + 1;
1575                            $arrTree[$cnt]['count'] = $cnt;
1576                            // フォルダが開いているか
1577                            $arrTree[$cnt]['open'] = lfIsFileOpen($path, $tree_status);
1578                            $cnt++;
1579                            // 下層ディレクトリ取得の為、再帰的に呼び出す
1580                            sfGetFileTreeSub($path, $default_rank, $cnt, $arrTree, $tree_status);
1581                        }
1582                    }
1583                }
1584            }
1585            closedir($handle);
1586        }
1587    }
1588
1589    /*
1590     * 関数名:sfDirChildExists()
1591     * 説明 :指定したディレクトリ配下にファイルがあるか
1592     * 引数1 :ディレクトリ
1593     */
1594    function sfDirChildExists($dir) {
1595        if(file_exists($dir)) {
1596            if (is_dir($dir)) {
1597                $handle = opendir($dir);
1598                while ($file = readdir($handle)) {
1599                    // 行末の/を取り除く
1600                    $dir = ereg_replace("/$", "", $dir);
1601                    $path = $dir."/".$file;
1602                    if ($file != '..' && $file != '.' && is_dir($path)) {
1603                        return true;
1604                    }
1605                }
1606            }
1607        }
1608
1609        return false;
1610    }
1611
1612    /*
1613     * 関数名:lfIsFileOpen()
1614     * 説明 :指定したファイルが前回開かれた状態にあったかチェック
1615     * 引数1 :ディレクトリ
1616     * 引数2 :現在のツリーの状態開いているフォルダのパスが | 区切りで格納
1617     */
1618    function lfIsFileOpen($dir, $tree_status) {
1619        $arrTreeStatus = explode('\|', $tree_status);
1620        if(in_array($dir, $arrTreeStatus)) {
1621            return true;
1622        }
1623
1624        return false;
1625    }
1626
1627    /*
1628     * 関数名:sfDownloadFile()
1629     * 引数1 :ファイルパス
1630     * 説明 :ファイルのダウンロード
1631     */
1632    function sfDownloadFile($file) {
1633         // ファイルの場合はダウンロードさせる
1634        Header("Content-disposition: attachment; filename=".basename($file));
1635        Header("Content-type: application/octet-stream; name=".basename($file));
1636        Header("Cache-Control: ");
1637        Header("Pragma: ");
1638        echo (sfReadFile($file));
1639    }
1640
1641    /*
1642     * 関数名:sfCreateFile()
1643     * 引数1 :ファイルパス
1644     * 引数2 :パーミッション
1645     * 説明 :ファイル作成
1646     */
1647    function sfCreateFile($file, $mode = "") {
1648        // 行末の/を取り除く
1649        if($mode != "") {
1650            $ret = @mkdir($file, $mode);
1651        } else {
1652            $ret = @mkdir($file);
1653        }
1654
1655        return $ret;
1656    }
1657
1658    /*
1659     * 関数名:sfReadFile()
1660     * 引数1 :ファイルパス
1661     * 説明 :ファイル読込
1662     */
1663    function sfReadFile($filename) {
1664        $str = "";
1665        // バイナリモードでオープン
1666        $fp = @fopen($filename, 'rb' );
1667        //ファイル内容を全て変数に読み込む
1668        if($fp) {
1669            $str = @fread($fp, filesize($filename)+1);
1670        }
1671        @fclose($fp);
1672
1673        return $str;
1674    }
1675
1676   /**
1677     * CSV出力用データ取得
1678     *
1679     * @return string
1680     */
1681    function getCSVData($array, $arrayIndex) {
1682        for ($i = 0; $i < count($array); $i++){
1683            // インデックスが設定されている場合
1684            if (is_array($arrayIndex) && 0 < count($arrayIndex)){
1685                for ($j = 0; $j < count($arrayIndex); $j++ ){
1686                    if ( $j > 0 ) $return .= ",";
1687                    $return .= "\"";
1688                    $return .= mb_ereg_replace("<","<",mb_ereg_replace( "\"","\"\"",$array[$i][$arrayIndex[$j]] )) ."\"";
1689                }
1690            } else {
1691                for ($j = 0; $j < count($array[$i]); $j++ ){
1692                    if ( $j > 0 ) $return .= ",";
1693                    $return .= "\"";
1694                    $return .= mb_ereg_replace("<","<",mb_ereg_replace( "\"","\"\"",$array[$i][$j] )) ."\"";
1695                }
1696            }
1697            $return .= "\n";
1698        }
1699        return $return;
1700    }
1701
1702   /**
1703     * 配列をテーブルタグで出力する。
1704     *
1705     * @return string
1706     */
1707    function getTableTag($array) {
1708        $html = "<table>";
1709        $html.= "<tr>";
1710        foreach($array[0] as $key => $val) {
1711            $html.="<th>$key</th>";
1712        }
1713        $html.= "</tr>";
1714
1715        $cnt = count($array);
1716
1717        for($i = 0; $i < $cnt; $i++) {
1718            $html.= "<tr>";
1719            foreach($array[$i] as $val) {
1720                $html.="<td>$val</td>";
1721            }
1722            $html.= "</tr>";
1723        }
1724        return $html;
1725    }
1726
1727   /**
1728     * 一覧-メイン画像のファイル指定がない場合、専用の画像ファイルに書き換える。
1729     *
1730     * @param string &$filename ファイル名
1731     * @return string
1732     */
1733    function sfNoImageMainList($filename = '') {
1734        if (strlen($filename) == 0 || substr($filename, -1, 1) == '/') {
1735            $filename .= 'noimage_main_list.jpg';
1736        }
1737        return $filename;
1738    }
1739
1740   /**
1741     * 詳細-メイン画像のファイル指定がない場合、専用の画像ファイルに書き換える。
1742     *
1743     * @param string &$filename ファイル名
1744     * @return string
1745     */
1746    function sfNoImageMain($filename = '') {
1747        if (strlen($filename) == 0 || substr($filename, -1, 1) == '/') {
1748            $filename .= 'noimage_main.png';
1749        }
1750        return $filename;
1751    }
1752
1753    /* デバッグ用 ------------------------------------------------------------------------------------------------*/
1754    function sfPrintR($obj) {
1755        echo '<div style="font-size: 12px;color: #00FF00;">' . "\n";
1756        echo '<strong>**デバッグ中**</strong><br />' . "\n";
1757        echo '<pre>' . "\n";
1758        var_dump($obj);
1759        echo '</pre>' . "\n";
1760        echo '<strong>**デバッグ中**</strong></div>' . "\n";
1761    }
1762
1763    /**
1764     * ランダムな文字列を取得する
1765     *
1766     * @param integer $length 文字数
1767     * @return string ランダムな文字列
1768     */
1769    function sfGetRandomString($length = 1) {
1770        require_once dirname(__FILE__) . '/../../module/Text/Password.php';
1771        return Text_Password::create($length);
1772    }
1773
1774    /**
1775     * 現在の URL を取得する
1776     *
1777     * @return string 現在のURL
1778     */
1779    function sfGetUrl() {
1780        $url = '';
1781
1782        if (SC_Utils_Ex::sfIsHTTPS()) {
1783            $url = "https://";
1784        } else {
1785            $url = "http://";
1786        }
1787
1788        $url .= $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . '?' . $_SERVER['QUERY_STRING'];
1789
1790        return $url;
1791    }
1792
1793    /**
1794     * バックトレースをテキスト形式で出力する
1795     *
1796     * @return string テキストで表現したバックトレース
1797     */
1798    function sfBacktraceToString($arrBacktrace) {
1799        $string = '';
1800
1801        foreach (array_reverse($arrBacktrace) as $backtrace) {
1802            if (strlen($backtrace['class']) >= 1) {
1803                $func = $backtrace['class'] . $backtrace['type'] . $backtrace['function'];
1804            } else {
1805                $func = $backtrace['function'];
1806            }
1807
1808            $string .= $backtrace['file'] . " " . $backtrace['line'] . ":" . $func . "\n";
1809        }
1810
1811        return $string;
1812    }
1813
1814    /**
1815     * 管理機能かを判定
1816     *
1817     * @return bool 管理機能か
1818     */
1819    function sfIsAdminFunction() {
1820        return defined('ADMIN_FUNCTION') && ADMIN_FUNCTION;
1821    }
1822
1823    /**
1824     * フロント機能かを判定
1825     *
1826     * @return bool フロント機能か
1827     */
1828    function sfIsFrontFunction() {
1829        return defined('FRONT_FUNCTION') && FRONT_FUNCTION;
1830    }
1831
1832    /**
1833     * インストール機能かを判定
1834     *
1835     * @return bool インストール機能か
1836     */
1837    function sfIsInstallFunction() {
1838        return defined('INSTALL_FUNCTION') && INSTALL_FUNCTION;
1839    }
1840
1841    // 郵便番号から住所の取得
1842    function sfGetAddress($zipcode) {
1843
1844        $objQuery = new SC_Query_Ex(ZIP_DSN);
1845
1846        $masterData = new SC_DB_MasterData_Ex();
1847        $arrPref = $masterData->getMasterData('mtb_pref');
1848        // インデックスと値を反転させる。
1849        $arrREV_PREF = array_flip($arrPref);
1850
1851        // 郵便番号検索文作成
1852        $zipcode = mb_convert_kana($zipcode ,'n');
1853        $sqlse = "SELECT state, city, town FROM mtb_zip WHERE zipcode = ?";
1854
1855        $data_list = $objQuery->getAll($sqlse, array($zipcode));
1856        if (empty($data_list)) return array();
1857
1858        /*
1859         総務省からダウンロードしたデータをそのままインポートすると
1860         以下のような文字列が入っているので 対策する。
1861         ・(1・19丁目)
1862         ・以下に掲載がない場合
1863        */
1864        $town =  $data_list[0]['town'];
1865        $town = ereg_replace("(.*)$","",$town);
1866        $town = ereg_replace("以下に掲載がない場合","",$town);
1867        $data_list[0]['town'] = $town;
1868        $data_list[0]['state'] = $arrREV_PREF[$data_list[0]['state']];
1869
1870        return $data_list;
1871    }
1872
1873    /**
1874     * プラグインが配置されているディレクトリ(フルパス)を取得する
1875     *
1876     * @param string $file プラグイン情報ファイル(info.php)のパス
1877     * @return SimpleXMLElement プラグイン XML
1878     */
1879    function sfGetPluginFullPathByRequireFilePath($file) {
1880        return str_replace('\\', '/', dirname($file)) . '/';
1881    }
1882
1883    /**
1884     * プラグインのパスを取得する
1885     *
1886     * @param string $pluginFullPath プラグインが配置されているディレクトリ(フルパス)
1887     * @return SimpleXMLElement プラグイン XML
1888     */
1889    function sfGetPluginPathByPluginFullPath($pluginFullPath) {
1890        return basename(rtrim($pluginFullPath, '/'));
1891    }
1892
1893    /**
1894     * プラグイン情報配列の基本形を作成する
1895     *
1896     * @param string $file プラグイン情報ファイル(info.php)のパス
1897     * @return array プラグイン情報配列
1898     */
1899    function sfMakePluginInfoArray($file) {
1900        $fullPath = SC_Utils_Ex::sfGetPluginFullPathByRequireFilePath($file);
1901
1902        return
1903            array(
1904                // パス
1905                'path' => SC_Utils_Ex::sfGetPluginPathByPluginFullPath($fullPath),
1906                // プラグイン名
1907                'name' => '未定義',
1908                // フルパス
1909                'fullpath' => $fullPath,
1910                // バージョン
1911                'version' => null,
1912                // 著作者
1913                'auther' => '未定義',
1914            )
1915        ;
1916    }
1917
1918    /**
1919     * プラグイン情報配列を取得する
1920     *
1921     * TODO include_once を利用することで例外対応をサボタージュしているのを改善する。
1922     *
1923     * @param string $path プラグインのディレクトリ名
1924     * @return array プラグイン情報配列
1925     */
1926    function sfGetPluginInfoArray($path) {
1927        return (array)include_once(PLUGIN_REALDIR . "$path/plugin_info.php");
1928    }
1929
1930    /**
1931     * プラグイン XML を読み込む
1932     *
1933     * TODO 空だったときを考慮
1934     *
1935     * @return SimpleXMLElement プラグイン XML
1936     */
1937    function sfGetPluginsXml() {
1938        return simplexml_load_file(PLUGIN_REALDIR . 'plugins.xml');
1939    }
1940
1941    /**
1942     * プラグイン XML を書き込む
1943     *
1944     * @param SimpleXMLElement $pluginsXml プラグイン XML
1945     * @return integer ファイルに書き込まれたバイト数を返します。
1946     */
1947    function sfPutPluginsXml($pluginsXml) {
1948        if (version_compare(PHP_VERSION, '5.0.0', '>')) {
1949           return;
1950        }
1951
1952        $xml = $pluginsXml->asXML();
1953        if (strlen($xml) == 0) SC_Utils_Ex::sfDispException();
1954
1955        $return = file_put_contents(PLUGIN_REALDIR . 'plugins.xml', $pluginsXml->asXML());
1956        if ($return === false) SC_Utils_Ex::sfDispException();
1957        return $return;
1958    }
1959
1960    function sfLoadPluginInfo($filenamePluginInfo) {
1961        return (array)include_once $filenamePluginInfo;
1962    }
1963
1964    /**
1965     * 現在の Unix タイムスタンプを float (秒単位) でマイクロ秒まで返す
1966     *
1967     * PHP4の上位互換用途。
1968     * FIXME PHP4でテストする。(現状全くテストしていない。)
1969     * @param SimpleXMLElement $pluginsXml プラグイン XML
1970     * @return integer ファイルに書き込まれたバイト数を返します。
1971     */
1972    function sfMicrotimeFloat() {
1973        $microtime = microtime(true);
1974        if (is_string($microtime)) {
1975            list($usec, $sec) = explode(" ", microtime());
1976            return (float)$usec + (float)$sec;
1977        }
1978        return $microtime;
1979    }
1980
1981    /**
1982     * 変数が空白かどうかをチェックする.
1983     *
1984     * 引数 $val が空白かどうかをチェックする. 空白の場合は true.
1985     * 以下の文字は空白と判断する.
1986     * - " " (ASCII 32 (0x20)), 通常の空白
1987     * - "\t" (ASCII 9 (0x09)), タブ
1988     * - "\n" (ASCII 10 (0x0A)), リターン
1989     * - "\r" (ASCII 13 (0x0D)), 改行
1990     * - "\0" (ASCII 0 (0x00)), NULバイト
1991     * - "\x0B" (ASCII 11 (0x0B)), 垂直タブ
1992     *
1993     * 引数 $val が配列の場合は, 空の配列の場合 true を返す.
1994     *
1995     * 引数 $greedy が true の場合は, 全角スペース, ネストした空の配列も
1996     * 空白と判断する.
1997     *
1998     * @param mixed $val チェック対象の変数
1999     * @param boolean $greedy "貧欲"にチェックを行う場合 true
2000     * @return boolean $val が空白と判断された場合 true
2001     */
2002    function isBlank($val, $greedy = true) {
2003        if (is_array($val)) {
2004            if ($greedy) {
2005                if (empty($val)) {
2006                    return true;
2007                }
2008                $array_result = true;
2009                foreach ($val as $in) {
2010                    /*
2011                     * SC_Utils_Ex への再帰は無限ループやメモリリークの懸念
2012                     * 自クラスへ再帰する.
2013                     */
2014                    $array_result = SC_Utils::isBlank($in, $greedy);
2015                    if (!$array_result) {
2016                        return false;
2017                    }
2018                }
2019                return $array_result;
2020            } else {
2021                return empty($val);
2022            }
2023        }
2024
2025        if ($greedy) {
2026            $val = preg_replace("/ /", "", $val);
2027        }
2028
2029        $val = trim($val);
2030        if (strlen($val) > 0) {
2031            return false;
2032        }
2033        return true;
2034    }
2035
2036    /**
2037     * 指定されたURLのドメインが一致するかを返す
2038     *
2039     * 戻り値:一致(true) 不一致(false)
2040     *
2041     * @param string $url
2042     * @return boolean
2043     */
2044    function sfIsInternalDomain($url) {
2045        $netURL = new Net_URL(HTTP_URL);
2046        $host = $netURL->host;
2047        if (!$host) return false;
2048        $host = preg_quote($host, "#");
2049        if (!preg_match("#^(http|https)://{$host}#i", $url)) return false;
2050        return true;
2051    }
2052
2053    /**
2054     * パスワードのハッシュ化
2055     *
2056     * @param string $str 暗号化したい文言
2057     * @param string $salt salt
2058     * @return string ハッシュ暗号化された文字列
2059     */
2060    function sfGetHashString($str, $salt) {
2061        $res = '';
2062        if ($salt == '') {
2063            $salt = AUTH_MAGIC;
2064        }
2065        if ( AUTH_TYPE == 'PLAIN') {
2066            $res = $str;
2067        } else {
2068            $res = hash_hmac(PASSWORD_HASH_ALGOS, $str . ":" . AUTH_MAGIC, $salt);
2069        }
2070        return $res;
2071    }
2072
2073    /**
2074     * パスワード文字列のハッシュ一致判定
2075     *
2076     * @param string $pass 確認したいパスワード文字列
2077     * @param string $hashpass 確認したいパスワードハッシュ文字列
2078     * @param string $salt salt
2079     * @return boolean 一致判定
2080     */
2081    function sfIsMatchHashPassword($pass, $hashpass, $salt) {
2082        $res = false;
2083        if ($hashpass != '') {
2084            if (AUTH_TYPE == 'PLAIN') {
2085                if($pass === $hashpass) {
2086                    $res = true;
2087                }
2088            } else {
2089                if (empty($salt)) {
2090                    // 旧バージョン(2.11未満)からの移行を考慮
2091                    $hash = sha1($pass . ":" . AUTH_MAGIC);
2092                } else {
2093                    $hash = SC_Utils_Ex::sfGetHashString($pass, $salt);
2094                }
2095                if($hash === $hashpass) {
2096                    $res = true;
2097                }
2098            }
2099        }
2100        return $res;
2101    }
2102
2103    /**
2104     * 検索結果の1ページあたりの最大表示件数を取得する
2105     *
2106     * フォームの入力値から最大表示件数を取得する
2107     * 取得できなかった場合は, 定数 SEARCH_PMAX の値を返す
2108     *
2109     * @param string $search_page_max 表示件数の選択値
2110     * @return integer 1ページあたりの最大表示件数
2111     */
2112    function sfGetSearchPageMax($search_page_max) {
2113        if (SC_Utils_Ex::sfIsInt($search_page_max) && $search_page_max > 0) {
2114            $page_max = intval($search_page_max);
2115        } else {
2116            $page_max = SEARCH_PMAX;
2117        }
2118        return $page_max;
2119    }
2120
2121    /**
2122     * 値を JSON 形式にして返す.
2123     *
2124     * この関数は, json_encode() 又は Services_JSON::encode() のラッパーです.
2125     * json_encode() 関数が使用可能な場合は json_encode() 関数を使用する.
2126     * 使用できない場合は, Services_JSON::encode() 関数を使用する.
2127     *
2128     * @param mixed $value JSON 形式にエンコードする値
2129     * @return string JSON 形式にした文字列
2130     * @see json_encode()
2131     * @see Services_JSON::encode()
2132     */
2133    function jsonEncode($value) {
2134        if (function_exists('json_encode')) {
2135            return json_encode($value);
2136        } else {
2137            require_once dirname(__FILE__) . '/../../module/Services/JSON.php';
2138            GC_Utils_Ex::gfPrintLog(' *use Services_JSON::encode(). faster than using the json_encode!');
2139            $objJson = new Services_JSON();
2140            return $objJson->encode($value);
2141        }
2142    }
2143
2144    /**
2145     * JSON 文字列をデコードする.
2146     *
2147     * この関数は, json_decode() 又は Services_JSON::decode() のラッパーです.
2148     * json_decode() 関数が使用可能な場合は json_decode() 関数を使用する.
2149     * 使用できない場合は, Services_JSON::decode() 関数を使用する.
2150     *
2151     * @param string $json JSON 形式にエンコードされた文字列
2152     * @return mixed デコードされた PHP の型
2153     * @see json_decode()
2154     * @see Services_JSON::decode()
2155     */
2156    function jsonDecode($json) {
2157        if (function_exists('json_decode')) {
2158            return json_decode($json);
2159        } else {
2160            require_once dirname(__FILE__) . '/../../module/Services/JSON.php';
2161            GC_Utils_Ex::gfPrintLog(' *use Services_JSON::decode(). faster than using the json_decode!');
2162            $objJson = new Services_JSON();
2163            return $objJson->decode($json);
2164        }
2165    }
2166
2167    /**
2168     * パスが絶対パスかどうかをチェックする.
2169     *
2170     * 引数のパスが絶対パスの場合は true を返す.
2171     * この関数は, パスの存在チェックを行なわないため注意すること.
2172     *
2173     * @param string チェック対象のパス
2174     * @return boolean 絶対パスの場合 true
2175     */
2176    function isAbsoluteRealPath($realpath) {
2177        if (strpos(PHP_OS, 'WIN') === false) {
2178            return (substr($realpath, 0, 1) == '/');
2179        } else {
2180            return preg_match('/^[a-zA-Z]:(\\\|\/)/', $realpath) ? true : false;
2181        }
2182    }
2183
2184    /**
2185     * ディレクトリを再帰的に作成する.
2186     *
2187     * mkdir 関数の $recursive パラメーターを PHP4 でサポートする.
2188     *
2189     * @param string $pathname ディレクトリのパス
2190     * @param integer $mode 作成するディレクトリのパーミッション
2191     * @return boolean 作成に成功した場合 true; 失敗した場合 false
2192     * @see http://jp.php.net/mkdir
2193     */
2194    function recursiveMkdir($pathname, $mode = 0777) {
2195        /*
2196         * SC_Utils_Ex への再帰は無限ループやメモリリークの懸念
2197         * 自クラスへ再帰する.
2198         */
2199        is_dir(dirname($pathname)) || SC_Utils::recursiveMkdir(dirname($pathname), $mode);
2200        return is_dir($pathname) || @mkdir($pathname, $mode);
2201    }
2202}
2203?>
Note: See TracBrowser for help on using the repository browser.