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