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