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

Revision 20677, 70.7 KB checked in by nanasess, 13 years ago (diff)

#854(PHP4対応)

  • foreach 内でのリファレンスを修正

#793 (非推奨機能の削除)

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