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

Revision 19860, 72.2 KB checked in by nanasess, 13 years ago (diff)

#843(複数配送先の指定)

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