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