Source for file GC_Utils.php
Documentation is available at GC_Utils.php
* This file is part of EC-CUBE
* Copyright(c) 2000-2011 LOCKON CO.,LTD. All Rights Reserved.
* http://www.lockon.co.jp/
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
* @author LOCKON CO.,LTD.
* @version $Id: GC_Utils.php 21028 2011-07-12 04:22:28Z habu $
/*----------------------------------------------------------------------
* [概要] 引数データをCSVとして、クライアントにダウンロードさせる
* [注釈] 引数は1,2ともカンマ区切りになっていること
*----------------------------------------------------------------------*/
$fiest_name = date('YmdHis') . ".csv";
Header("Content-disposition: attachment; filename=${fiest_name}");
Header("Content-type: application/octet-stream; name=${fiest_name}");
$return = $header. $contents;
if (mb_detect_encoding($return) == CHAR_CODE){
$return = mb_convert_encoding($return,'SJIS',CHAR_CODE);
$return = str_replace( array( "\r\n", "\r" ), "\n", $return);
/*----------------------------------------------------------------------
* [引数] 1:CSVにする配列 2:引数1が連想配列時の添え字を指定した配列
*----------------------------------------------------------------------*/
function gfSetCsv( $array, $arrayIndex = "" ){
//引数$arrayIndexは、$arrayが連想配列のときに添え字を指定してやるために使用する
for ($i= 0; $i< count($array); $i++ ){
for ($j= 0; $j< count($array[$i]); $j++ ){
if ( $j > 0 ) $return .= ",";
$return .= mb_ereg_replace("<","<",mb_ereg_replace( "\"","\"\"",$array[$i][$arrayIndex[$j]] )) . "\"";
$return .= mb_ereg_replace("<","<",mb_ereg_replace( "\"","\"\"",$array[$i][$j] )) . "\"";
/*----------------------------------------------------------------------
* [引数] 1:日付文字列(yyyy/mm/dd、yyyy-mm-dd hh:mm:ss等)
*----------------------------------------------------------------------*/
list ($by, $bm, $bd) = preg_split("/[-/ ]/", $dbdate);
if($tm * 100 + $td < $bm * 100 + $bd) $age-- ;
if (DEBUG_MODE === true) {
"*** start Debug ***\n" .
* @param int $forLogInfo ログ出力用に利用するかどうか(1:ログ出力用に利用する)
* @return string 呼び出し元クラス、関数名、行数の文字列表現
if ( $forLogInfo === true ){
if( ($traces[3]['class'] === 'LC_Page'
|| $traces[3]['class'] === 'LC_Page_Admin')
&& $traces[3]['function'] === 'log')
$str = $traces[$bklv]['class'] . "::" . $traces[$bklv]['function'] . "(" . $traces[$bklv- 1]['line'] . ") ";
* ログメッセージに、呼び出し元関数名等の情報を付加して返します
* @param string $mess ログメッセージ
* @param string $log_level ログレベル("Info" or "Debug")
* @return string ログメッセージに呼び出し元関数名等の情報を付加した文字列
// メッセージの前に、ログ出力元関数名とログ出力関数呼び出し部分の行数を付与
// ログレベル=Debugの場合は、[Debug]を先頭に付与する
if ($log_level === 'Debug') {
$mess = "[Debug]" . $mess;
* @param string $mess ログメッセージ
* @param string $log_level ログレベル("Info" or "Debug")
// ログレベル=Debugの場合は、DEBUG_MODEがtrueの場合のみログ出力する
if ($log_level === 'Debug'&& DEBUG_MODE === false) {
// ログメッセージに、呼び出し元関数名等の情報を付加する
// ※現在は管理画面用・フロント用のログ出力とも、同じファイル(site.log)に出力します。
// 分けたい場合は、以下の関数呼び出しの第2引数にファイルパスを指定してください
GC_Utils_Ex::gfPrintLog($mess);
* @param string $mess ログメッセージ
* @param string $log_level ログレベル("Info" or "Debug")
// ログレベル=Debugの場合は、DEBUG_MODEがtrueの場合のみログ出力する
if ($log_level === 'Debug'&& DEBUG_MODE === false) {
// ログメッセージに、呼び出し元関数名等の情報を付加する
// ※現在は管理画面用・フロント用のログ出力とも、同じファイル(site.log)に出力します。
// 分けたい場合は、以下の関数呼び出しの第2引数にファイルパスを指定してください
GC_Utils_Ex::gfPrintLog($mess);
/*----------------------------------------------------------------------
* [概要] ログファイルに日時、処理ファイル名、メッセージを出力
*----------------------------------------------------------------------*/
$today = date("Y/m/d H:i:s");
$mess = strtr($mess, $trans_tbl);
$fp = fopen($path, "a+");
fwrite( $fp, $today. " [". $_SERVER['PHP_SELF']. "] ". $mess. " from ". $_SERVER['REMOTE_ADDR']. "\n" );
GC_Utils_Ex::gfLogRotation(MAX_LOG_QUANTITY, MAX_LOG_SIZE, $path);
* XXX この類のローテーションは通常 0 開始だが、本実装は 1 開始である。
* この中でログ出力は行なわないこと。(無限ループの懸念あり)
* @param integer $max_log 最大ファイル数
* @param integer $max_size 最大サイズ
* @param string $path ファイルパス
// ファイルが最大サイズを超えていない場合、終了
if (filesize($path) <= $max_size) return;
// Windows 版 PHP への対策として明示的に事前削除
$path_max = "$path.$max_log";
// 削除に失敗時した場合、ログローテーションは見送り
for ($i = $max_log; $i >= 2; $i-- ) {
$path_old = "$path." . ($i - 1);
/*----------------------------------------------------------------------
*----------------------------------------------------------------------*/
$character = "abcdefghkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ2345679";
$pw = preg_split("//", $character, 0, PREG_SPLIT_NO_EMPTY);
for($i = 0; $i< $pwLength; $i++ ) {
/*----------------------------------------------------------------------------------------------------------------------
* [概要] 入力されたメールアドレスをメール関数用の宛先に変換
* [引数] 「メールアドレス」または「名前<メールアドレス>」、複数アドレス指定時はカンマ区切りで指定する。
* [戻値] 「メールアドレス」または「JIS_MIMEにコード変換した名前 <メールアドレス>」、複数アドレス指定時はカンマ区切りで返却する。
*----------------------------------------------------------------------------------------------------------------------*/
$addrs = explode(",", $str); //アドレスを配列に入れる
foreach ($addrs as $addr) {
if (preg_match("/^(.+)<(.+)>$/", $addr, $matches)) {
$mailaddrs[] = mb_encode_mimeheader(trim($matches[1])). " <". trim($matches[2]). ">";
$mailaddrs[] = trim($addr);
return implode(", ", $mailaddrs); //複数アドレスはカンマ区切りにする
Documentation generated on Fri, 24 Feb 2012 14:00:57 +0900 by Seasoft
|