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