])*>( )*\s*<\/p>/i',
'/])*>( )*\s*<\/span>/i',
'/])*>( )*\s*<\/strong>/i',
'/])*>( )*\s*<\/em>/i',
'/])*>( )*\s*<\/font>/i',
'/])*>( )*\s*<\/small>/i',
'/<\?xml:namespace([^>])*><\/\?xml:namespace>/i',
'/<\?xml:namespace([^>])*\/>/i',
'/class=\"MsoNormal\"/i',
'/";
echo "
";
echo " ";
for ($k=0;$k<=$j;$k++) {
echo "node id ";
echo "pre ";
echo "tag ";
echo "post ";
echo "parentTag ";
echo "tipo ";
}
echo "$k ";
echo " ".htmlspecialchars($this->matrix[$k]["pre"])." ";
echo " ".htmlspecialchars($this->matrix[$k]["tag"])." ";
echo " ".htmlspecialchars($this->matrix[$k]["post"])." ";
echo " ".$this->matrix[$k]["parentTag"]." ";
echo " ".$this->matrix[$k]["tagType"]."
{$j}
\n\n\n\n".$this->fixedxhtmlDisplayCode;
}
return $errorsCounter;
}
}
?>
/**
* Network関係の関数を集めたクラス
* @version 1.0.0
* @author Yoshikuni Tamura
* @date 2013-01-01
*
* @par 詳細
* Network関係の関数を集めたクラスにするつもりですが、今はSSHとSCPがメインになってます
*
*/
class CNetwork extends CObject{
var $connection = array();
/**
* Contructor. Set up default domain. can be over-ridden.
*/
public function __construct(){}
/**
* SSHコネクション($serverでコネクションをLocalシェアーします)
* USER@HOST:PAHTをArrayにする
*/
public function ssh_connect( $server , $user , $cert='' , $pass='' ){
if( !$this->connection['ssh'][$server] ){
if( $this->connection['ssh'][$server] = ssh2_connect( $server , 22 , array('hostkey'=>'ssh-rsa') ) ){
if( $user && $pass ){
return ssh2_auth_password( $this->connection['ssh'][$server], $user , $pass );
}else{
if( !$cert['pub'] && defined('__SSH_PUB_KEY') ){ $cert['pub'] = __SSH_PUB_KEY; }
if( !$cert['private'] && defined('__SSH_PRIVATE_KEY') ){ $cert['private'] = __SSH_PRIVATE_KEY; }
$ret = ssh2_auth_pubkey_file($this->connection['ssh'][$server], 'vnsh', $cert['pub'] , $cert['private'] );
}
}
if( !$ret ){ return false; }
}
return ($this->connection['ssh'][$server]) ? $this->connection['ssh'][$server] : false;
}
/**
* SSH Exec
* USER@HOST:PAHTをArrayにする
* @return {streem}
*/
public function ssh_exec( $con , $commond ){
return ssh2_exec($con, $commond );
}
/**
* SSH情報
* USER@HOST:PAHTをArrayにする
*/
public function ssh_get_info( $in ){
$in = trim( $in );
if(preg_match( "(\@)" , $in ) ){
$arr = explode( '@' , $in );
$user = $arr[0];
$in = $arr[1];
}
if(preg_match( "(:)" , $in )){
$arr = explode( ':' , $in );
$server = $arr[0];
$in = $arr[1];
}
$path = $in;
return array( 'server' => $server , 'user' => $user , 'path' => $path );
}
/**
* ローカル及びSSH経由でlsコマンドを行う
* @param {resource|string} Connection resource か Local Path。resourceの場合SSH経由のlsになる
* @param {string} Local Path
*/
public function ssh_ls( $con_or_path , $path='' ){
if( is_resource( $con_or_path ) ){
if( $stream = ssh2_exec($con_or_path, 'ls '.$path ) ){
stream_set_blocking($stream, true);
$ret = fread($stream , 4096 );
return explode( "\n" , $ret );
}
}else{
return ls($con_or_path);
}
}
/**
* ローカル及びSSH経由でis_dirコマンドを行う
* @param {resource|string} Connection resource か Local Path。resourceの場合SSH経由のfileになる
* @param {string} Local Path
*/
public function ssh_is_dir( $con_or_path , $path='' ){
if( is_resource( $con_or_path ) ){
if( $stream = ssh2_exec($con_or_path, 'file '.$path ) ){
stream_set_blocking($stream, true);
$ret = fread($stream , 4096 );
return preg_match( "(: directory)" , $ret );
}
}else{
return is_dir($con_or_path);
}
}
/**
* ローカル及びSSH経由でmkdirコマンドを行う(0755がセットされる)
* @param {resource|string} Connection resource か Local Path。resourceの場合SSH経由のmkdirになる
* @param {string} Local Path
*/
public function ssh_mkdir( $con_or_path , $path='' ){
if( is_resource( $con_or_path ) ){
if( $stream = ssh2_exec($con_or_path, 'mkdir '.$path ) ){
return true;
}
}else{
if( !file_exists( $con_or_path ) ){
return mkdir($con_or_path , 0755 );
}
}
}
//SCP ---------------------
private function is_dist_file_name( $source , $dist ){
$arr1 = explode( '/' , $source);
$arr2 = explode( '/' , $dist);
return $arr1[count($arr1)-1] == $arr2[count($arr2)-1];
}
/**
SCP送信
*/
private function scp_send( $con , $source , $dest , $mode=0644 ){
if( $this->ssh_is_dir( $source ) ){
if( substr( $source , -1 , 1) == '/' ){
$source = $source;
$dir_name = dir_name( $source ).'/';
}else{
$source = $source.'/';
}
$dest = ( substr( $dest , -1 , 1) == '/' ) ? $dest : $dest.'/';
$files = $this->ssh_ls( $source );
$this->ssh_mkdir( $con , $dest.$dir_name );//リモートサーバーにDIRを制作
if( $files ){
foreach( $files as $file ){
if( is_dir( $source.$file ) ){
$source_file_name = $source.$file.'/';
$dest_file_name = $dest.$dir_name;
}else{
$source_file_name = $source.$file;
$dest_file_name = $dest.$dir_name.$file;
}
if( !$this->scp_send( $con , $source_file_name , $dest_file_name , $mode ) ){
return false;
}
}
}
}else{
if( !$this->is_dist_file_name($source , $dest ) ){
$arr1 = explode( '/' , $source);
$dest = $dest.'/'.$arr1[count($arr1)-1];
}
return ssh2_scp_send( $con , $source , $dest , 0644 );
}
return true;
}
/**
SCP受信
*/
private function scp_recv( $con , $source , $dest , $mode=0644 ){
if( $this->ssh_is_dir( $con , $source ) ){
if( substr( $source , -1 , 1) == '/' ){
$source = $source;
$dir_name = dir_name( $source ).'/';
}else{
$source = $source.'/';
}
$dest = ( substr( $dest , -1 , 1) == '/' ) ? $dest : $dest.'/';
$files = $this->ssh_ls( $con , $source );
$this->ssh_mkdir( $dest.$dir_name );
if( $files ){
foreach( $files as $file ){
if( $file ){
if( is_dir( $source.$file ) ){
$source_file_name = $source.$file.'/';
$dest_file_name = $dest.$dir_name;
}else{
$source_file_name = $source.$file;
$dest_file_name = $dest.$dir_name.$file;
}
if( !$this->scp_recv( $con , $source_file_name , $dest_file_name , $mode , $scp_action ) ){
return false;
}
}
}
}
}else{
if( !$this->is_dist_file_name($source , $dest ) ){
$arr1 = explode( '/' , $source);
$dest = $dest.'/'.$arr1[count($arr1)-1];
}
if( ssh2_scp_recv( $con , $source , $dest ) ){
chmod( $dest , $mode );
return true;
}
return false;
}
return true;
}
/**
* SCP送受信(使い方は通常のSCPと同じです。)
* @param {String} User@Host:/PATH/A/B/FILE or User@Host:/PATH/A/B/DIR
* @param {String} User@Host:/PATH/A/B/DIR
* @param {Array} cert Array('pub'=> 'public kye' , 'private' => 'private key' );
* @param {int} トランスファー後のファイルモード;
* @param {String} user username
* @param {String} pass passwor
* @return {bool}
* @see ssh_get_info ssh_connect
*
* //$cert['pub'] = '/home/vnsh/vnnet/agora/www/golf/t1.pub.pub';
* //$cert['private'] = '/home/vnsh/vnnet/agora/www/golf/t1.pub';
* Dirごとまとめて送受信例
*
* 送信
* print_r( $this->controller->network->scp( "/home/vnsh/vnnet/agora/www/golf/controllers" , 'vnsh@72.34.254.53:/home/vnsh/aa' , $cert ) );
* 受取
* print_r( $this->controller->network->scp( 'vnsh@72.34.254.53:/home/vnsh/test/' , "/tmp/" , $cert ) );
* サーバー間での送信
* print_r( $this->controller->network->scp( 'vnsh@72.34.254.53:/home/vnsh/aa' , 'vnsh@72.34.254.53:/home/vnsh/ttt2' , $cert ) );
*
*単一ファイルの例
* 送信
* print_r( $this->controller->network->scp( "/home/vnsh/vnnet/agora/www/golf/controllers/class.CAppController.php" , 'vnsh@72.34.254.53:/home/vnsh' , $cert ) );
* 受取
* print_r( $this->controller->network->scp( 'vnsh@72.34.254.53:/home/vnsh/class.CAppController.php' , "/tmp/" , $cert ) );
* サーバー間での送信
* print_r( $this->controller->network->scp( 'vnsh@72.34.254.53:/home/vnsh/class.CAppController.php' , 'vnsh@72.34.254.53:/home/vnsh/ttt3' , $cert ) );
*
*
*/
public function scp( $source_info , $dest_info , $cert="" , $mode=0644 , $user="" , $pass="" ){
$source = $this->ssh_get_info( $source_info );
$dest = $this->ssh_get_info( $dest_info );
if( $source['server'] && $dest['server'] ){
//両方ともサーバーの場合(リモートコピー)
$uniqid = uniqid();
$this->scp_mkdir( __DATA_TMP.$uniqid );
$con_r = $this->ssh_connect( $source['server'] , $source['user'] , $cert );
$con_s = $this->ssh_connect( $dest['server'] , $dest['user'] , $cert );
if( $this->scp_recv( $con_r , $source['path'] , __DATA_TMP.$uniqid , $mode ) ){
$this->scp_send( $con_s , __DATA_TMP.$uniqid , $dest['path'] , $mode );
if( file_exists( __DATA_TMP.$uniqid ) ){
exec( 'rm -R '.__DATA_TMP.$uniqid );
}
return True;
}
}elseif( $source['server'] ){
//送信元がサーバーの場合(つまり受取)
$con = $this->ssh_connect( $source['server'] , $source['user'] , $cert );
return $this->scp_recv( $con , $source['path'] , $dest['path'] , $mode );
}else{
//受信先がサーバーの場合(つまり送信)
$con = $this->ssh_connect( $dest['server'] , $dest['user'] , $cert );
return $this->scp_send( $con , $source['path'] , $dest['path'] , $mode );
}
return false;
}
/**
* ssh経由でコマンドを実行
* @param {resource|string} Connection resource か Local Path。resourceの場合SSH経由のmkdirになる
* @param {string} Local Path
*/
public function ssh( $con , $commond ){
$stream = $this->ssh_exec( $con , $commond );
/**
* ブロックモードを有効にする
* @see http://www.phpmaniacs.com/newsgroups/article.php?id=85352&group=php.notes
*/
stream_set_blocking($stream, true);
fread($stream, 4096);
return false;
}
/*
この関数は受ける側でセキュリティーが必要です。
多用しない方が無難(ファイル置き換えられる可能性あり)
*/
function upload( $url , $file , $name='' ){
$ch = curl_init();
$name = ( $name ) ? $name : 'file';
$data = array( 'VNWF_SUBMIT' => 1 , $name => '@'.$file );
curl_setopt($ch, CURLOPT_URL, $url );
curl_setopt($ch, CURLOPT_POST, 1 );
curl_setopt($ch, CURLOPT_POSTFIELDS, $data );
return curl_exec($ch);
}
}
?>
/**
* @brief Cookie操作クラス
* @version 1.0.0
* @author Yoshikuni Tamura
* @date 2013-01-01
*
*/
class CCookie extends CObject{
// Encryption key. Change this.
const DES_KEY = 'test';
private $default_path = '/';
private $default_domain = null;
private $default_secure = 0;
private $default_httponly = 0;
private $encrypt_prefix = '_EnC_';
private $current_var = array();
/**
* Contructor. Set up default domain. can be over-ridden.
*/
public function __construct(){
$this->default_domain = $this->get_root_domain();
}
/**
* Create a cookie
* @return bool true/false
*@par サンプル
*@code
$c->cookie->regist( 'js_echo_req' , time() , 500000 );
@endcode
*/
public function regist( $name , $data , $expire , $encrypt=null , $path=null , $domain=null , $secure=null , $httponly=null ){
if( is_null($name) || is_null($data) || ( $expire <= 0 ) ){
trigger_error("some cookie values are missing. name: {$name}, data: {$data}, expire : {$expire}");
return false;
}
if( !$path ){
$path = $this->default_path;
}
if( is_null($domain) ){
$domain = $this->default_domain;
}
if( is_null($secure) ){
$secure = $this->default_secure;
}
if( is_null($httponly) ){
$httponly = $this->default_httponly;
}
$expire = time() + $expire;
$data = $this->set_value( $data , $encrypt );
if( !isset( $this->current_var[$name] ) ){
$this->current_var[$name] = $data;
}
setcookie( $name , $data , $expire , $path , $domain , $secure , $httponly );
}
/**
* Kill a cookie
* @param string $cookieName to kill
* @return bool true/false
*/
public function remove( $name=null , $path=null , $domain=null ){
if( $name ){
if( is_null($path) ){
$path = $this->default_path;
}
if( is_null($domain) ){
$domain = $this->default_domain;
}
if( $this->current_var[$name] ){ unset( $this->current_var[$name] ); }
return setcookie( $name , null , (time()-1) , $path , $domain );
}else{
return False;
}
}
/**
* Set cookie value
* @param string $value cookie value
* @return bool whether the string was a string
*/
public function set_value($value=null, $encrypt=false){
if(!is_null($value)){
if( $encrypt ){
$data = $this->encrypt_prefix.$this->cookie_encryption($value);
}else{
// $data = base64_encode($value);
$data = urlencode($value);
}
$len = (function_exists('mb_strlen')?mb_strlen($data):strlen($data));
if($len>4096){
trigger_error('Cookie data exceeds 4kb');
return false;
}
return $data;
}
return false;
}
/**
* Get cookie value
*/
public function get( $name=null ){
return $this->get_cookie($name);
}
/**
* Get cookie value
*@par サンプル
*@code
arr = $this->controller->cookie->get_cookie( '_a' );
@endcode
*/
public function get_cookie( $name=null ){
if( $name ){
if( isset( $this->current_var[$name] ) ){
return $this->current_var[$name];
}else{
if( isset($_COOKIE[$name]) ){
$val = $_COOKIE[$name];
if( preg_match( "(". $this->encrypt_prefix .")" , $val ) ){
// if( ereg( $this->encrypt_prefix , $val ) ){
$val = substr( $val , strlen( $this->encrypt_prefix ) );
return $this->cookie_encryption( $val , true );
}else{
return urldecode( $val );
// return base64_decode( $val );
}
}
}
}
}
/**
* Get cookie value
*/
public function get_all_cookie(){
if( $_COOKIE ){
foreach( $_COOKIE as $key => $val ){
$rtn[$key] = $this->get_cookie($key);
}
return $rtn;
}
}
/**
* Jenky bit to retrieve root domain if not supplied
* @return string Le Domain
*/
private function get_root_domain(){
$host = $_SERVER['HTTP_HOST'];
$parts = explode('.', $host);
if(count($parts)>1){
$tld = array_pop($parts);
$domain = array_pop($parts).'.'.$tld;
} else {
$domain = array_pop($parts);
}
return '.'.$domain;
}
/**
* Value Encryption
* @param string $str string to be (de|en)crypted
* @param string $decrypt whether to decrypt or not
* @return string (de|en)crypted string
*/
private function cookie_encryption( $str=null , $decrypt=False ){
if(is_null($str)){
trigger_error('enc null string');
return $str;
}
$iv_size = mcrypt_get_iv_size(MCRYPT_3DES, MCRYPT_MODE_ECB);
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
$key_size = mcrypt_get_key_size(MCRYPT_3DES, MCRYPT_MODE_ECB);
$key = substr(self::DES_KEY,0,$key_size);
if($decrypt){
$return = mcrypt_decrypt(MCRYPT_3DES, $key, base64_decode($str), MCRYPT_MODE_ECB, $iv);
} else {
$return = base64_encode(mcrypt_encrypt(MCRYPT_3DES, $key, $str, MCRYPT_MODE_ECB, $iv));
}
return trim( $return );
}
}
?>
/**
* ブラウザーミミッククラス
* @author Yoshikuni Tamura
* @version 1.0.0
* @date 2006-05-01
*/
class CBrowser extends CObject{
/** */
public function __construct(){}
public function browser( $url , $is_tor=false ){
return $this->firefox( $url , $is_tor );
}
/*
* Firfoxとしてページをロード
* @para {string} url
* @return {string} HTMLソース
* @see load_html()
*/
public function firefox($url, $is_tor=false, $return_header=false ){
$header = array();
$header[] = 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8';
$header[] = 'Cache-Control: max-age=0';
$header[] = 'Connection: keep-alive';
$header[] = 'Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7';
$header[] = 'Accept-Language: ja,en-us;q=0.7,en;q=0.3';
$header[] = 'Accept-Encoding: gzip, deflate';
$header[] = 'User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:19.0) Gecko/20100101 Firefox/19.0';
if( $return_header ){
return $this->load_header( $url , $header , $is_tor );
}else{
return $this->load_html( $url , $header , $is_tor );
}
}
/*
* HTMLをCULRからロードします
* @para {string} url
* @para {array} header
* @return {string} HTMLソース
* @see firefox()
*/
public function load_html($url , $header=null , $is_tor=false ){
$ch = curl_init($url);
if( $header ){ curl_setopt($ch, CURLOPT_HTTPHEADER, $header); }
curl_setopt($ch, CURLOPT_ENCODING, 'gzip');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3);
if($is_tor){
curl_setopt($ch, CURLOPT_PROXY, "127.0.0.1:9050");
curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
}
$html = curl_exec($ch);
curl_close($ch);
return $html;
}
/*
* HTMLをCULRからロードします
* @para {string} url
* @para {array} header
* @return {string} HTMLソース
* @see firefox()
*/
public function load_header($url , $header=null , $is_tor=false ){
$ch = curl_init($url);
if( $header ){ curl_setopt($ch, CURLOPT_HTTPHEADER, $header); }
curl_setopt($ch, CURLOPT_ENCODING, 'gzip');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3);
if($is_tor){
curl_setopt($ch, CURLOPT_PROXY, "127.0.0.1:9050");
curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
}
curl_exec($ch);
$header = curl_getinfo($ch);
curl_close($ch);
return $header;
}
/*
* Forkしてリモートファイルのmime typeを返します
* @para {array} urls
* @return {array} array( URL \t mime \t size \t width \t height )でリターン
* get_remote_file_info_forkはいずれブラウザー化した方が良い気がします。今はヘッダーのみ取得可能になってます
* @see get_remote_file_info()
*/
function get_remote_file_info_fork($urls){
if( $urls ){
//apach版phpはforkが使えないので外部でCall
$argv = base64_encode(serialize($urls));
$cmd = 'php '.__CLASS.'tools/get_remote_file_info_fork.php '.$argv . ' 3';
exec( $cmd , $tmp );
$tmp = unserialize(base64_decode($tmp[0]));
return $tmp;
}
return false;
}
/*
* リモートファイルのmime typeを返します
* @para {string} url
* @return {array} [mime] =>mime [size] =>size
* @see get_remote_file_info_fork()
*/
function get_remote_file_info($url , $info_type=null){
if( $url ){
$header = get_headers( $url );
if( $header ){
if( preg_match( '/200 OK/i' , $header[0] ) || preg_match( '/302 Found/i' , $header[0] ) ){
foreach( $header as $key => $val ){
if( preg_match( '/Content-Type:/i' , $val ) ){
$arr= explode( ':' , $val);
$arr= explode( ';' , $arr[1]);
$ret['mime'] = trim($arr[0]);
}
if( preg_match( '/Content-Length:/' , $val ) ){
$arr= explode( ':' , $val);
$arr= explode( ';' , $arr[1]);
$ret['size'] = trim($arr[0]);
}
if( preg_match( '/ETag:/' , $val ) ){
$arr= explode( ':' , $val);
$arr= explode( ';' , $arr[1]);
$ret['etag'] = trim(str_replace( '"' , '' , $arr[0]));
}
}
}
if( $info_type ){
return $ret[$info_type];
}else{
if( preg_match( '/image/i' , $ret['mime'] ) ){
$dimension = getimagesize($url);
return array_merge( $ret , array( 'width'=>$dimension[0] , 'height'=>$dimension[1] ) );
}
return $ret;
}
}
}
return false;
}
/*
* リモートファイルのmime typeを返します
*
* K.Suzuki: 2013/09/11 redirectしているサイトに対応。
*
* @para {string} url
* @return {array} [mime] =>mime [size] =>size
* @see get_remote_file_info_fork()
*/
function get_remote_file_info_redirect($url , $info_type=null){
if( $url ){
$header = get_headers( $url );
if( $header ){
$state = 'check_header';
foreach( $header as $key => $val ){
if ($state == 'check_connection') {
// redirectしているサイトのヘッダの場合、200や302が途中で出てくるので、それを探す。
if( preg_match( '/200 OK/i' , val ) || preg_match( '/302 Found/i' , val ) ){
$state = 'check_file_attributes';
}
}
else {
if( preg_match( '/Content-Type:/i' , $val ) ){
$arr= explode( ':' , $val);
$arr= explode( ';' , $arr[1]);
$ret['mime'] = trim($arr[0]);
}
if( preg_match( '/Content-Length:/' , $val ) ){
$arr= explode( ':' , $val);
$arr= explode( ';' , $arr[1]);
$ret['size'] = trim($arr[0]);
}
if( preg_match( '/ETag:/' , $val ) ){
$arr= explode( ':' , $val);
$arr= explode( ';' , $arr[1]);
$ret['etag'] = trim(str_replace( '"' , '' , $arr[0]));
}
}
}
if( $info_type ){
return $ret[$info_type];
}else{
if( preg_match( '/image/i' , $ret['mime'] ) ){
$dimension = getimagesize($url);
return array_merge( $ret , array( 'width'=>$dimension[0] , 'height'=>$dimension[1] ) );
}
return $ret;
}
}
}
return false;
}
/*
* HTML内のsrcのRealPAHTを返します
* @arg URLとHTMLなで指定されている相対ファイルPahtを絶対Pathにします。
* @arg つまり、../image.jpgや./image.jpg等を、DOMAIN/image.jpg DOMAIN/img/image.jpg等に変換します
* @para {string} url
* @para {string} file
* @return {string} domain
*/
function src_realpath( $url , $file ){
$url = trim( $url );
$file = trim( $file );
if( $file ){
if( !preg_match( '/http:\/\//i' , $file ) && !preg_match( '/https:\/\//i' , $file )){
if( substr( $file , 0 , 1 ) == '/' ){
$file = domain( $url ).$file;
}else{
$tmp = parse_url($url);
$url = $tmp['scheme'].'://'.$tmp['host'].$tmp['path'];
$tmp = pathinfo($tmp['path']);
if( $tmp['extension'] ){
$tmp = explode( '/' , $url );
array_pop($tmp);
$url = implode( '/' , $tmp ).'/';
}
if( substr( $file , 0 , 3 ) == '../' ){
if( substr( $url , -1 ) == '/' ){
$url = substr( $url , 0 , -1 );
}
$tmp1 = explode( '/' , $url );
$tmp2 = explode( '/' , $file );
foreach( $tmp2 as $val ){
if( $val == '..'){
array_shift($tmp2);
array_pop($tmp1);
}
}
$file = implode( '/' , $tmp1 ).'/'.implode( '/' , $tmp2 );
}elseif( substr( $file , 0 , 2 ) == './' ){
$file = $url.substr( $file , 2 );
}else{
$file = $url.$file;
}
}
}
}
return $file;
}
function html_head_info($url){
$contents = $this->browser( $url );
$result = false;
preg_match_all('/<\s*meta\s.*?>/i', $contents , $meta_tag );
preg_match_all('/<\s*link\s.*?>/i', $contents , $link_tag );
if( is_string($contents) ){
$title = null;
$links = null;
$metas = null;
preg_match('/HTTP ERROR '.$code.'
' );
}
}else{
$this->header = $in;
header( $in , $replace );
}
}
public function setContentType($in){
$this->content_type = $in;
}
public function sendHeadder($in , $replace=true , $code=null){
$this->setHeader($in , $replace , $code);
}
/**
* @return {void}
*@par サンプル
*@code
* $c->header->set404();
* @endcode
*/
public function set404(){
$this->sendHeadder('Status: 404 Not Found' );
$this->sendHeadder('HTTP/1.0 404 Not Found' , true , 404 );
}
// Edited by Kono on 2019/01/30 08:55:00 START
/**
* @return {void}
*/
public function set403(){
$this->sendHeadder('HTTP/1.0 403 Forbidden' , true , 403 );
}
// Edited by Kono END
/**
* @return {void}
*/
public function set310(){
$this->sendHeadder('HTTP/1.0 301 Moved Permanently' , true , 310 );
}
/**
* @return {void}
*/
public function reload( $get=null, $as_url=False ,$ignore=null ){
$get = ( $get ) ? $get : $_GET;
$ignore = ( $ignore ) ? $ignore : array( '_INTERNAL_ACTION_URL' );
$this->location( __HTTP_SCHEME.$_SERVER["HTTP_HOST"].$_SERVER["REQUEST_URI"] , $_GET , '' , '' , $ignore );
}
/**
* @return {void}
*/
public function get_current( $get=null, $as_url=False ,$ignore=null ){
$get = ( $get ) ? $get : $_GET;
$ignore = ( $ignore ) ? $ignore : array( '_INTERNAL_ACTION_URL' );
return $this->location( __HTTP_SCHEME.$_SERVER["HTTP_HOST"].$_SERVER["REQUEST_URI"] , $_GET , '' , true , $ignore , true );
}
public function get_previous( $get=null, $as_url=False ){
if( $_SERVER["HTTP_REFERER"] ){
$get = ( $get ) ? $get : $_GET;
$ignore = ( $ignore ) ? $ignore : array( '_INTERNAL_ACTION_URL' );
return $this->location( $_SERVER["HTTP_REFERER"] , $_GET , '' , true , $ignore , true );
}
}
public function get_get_string( $get=null , $ignore=null){
$ignore = ( $ignore ) ? $ignore : array( '_INTERNAL_ACTION_URL' );
$get = ( $get ) ? $get : $_GET;
if( is_array( $get ) ){
foreach( $get as $key => $val ){
if( array_search( $key , $ignore ) === false ){
$_tmp[$key] = $val;
}
}
return implode( '&' , $_tmp );
}
return '';
}
/**
* @return {void}
*@par サンプル
*@code
$this->controller->header->previous('setdl=1');
function user_logout() {
$this->user_login_status( 'out' );
$this->c->header->previous();
}
@endcode
*/
public function previous( $get=null, $as_url=False ){
if( $_SERVER["HTTP_REFERER"] ){
$this->location( $_SERVER["HTTP_REFERER"] , $get , $as_url );
}else{
$this->location( __HTTP_SCHEME.$_SERVER["HTTP_HOST"] );
}
}
/**
* テスト関数(飛ばされるHeddaerを表示する)
* @return {void}
*/
public function _location($in,$get=null, $as_url=False ){
$this->location($in,$get , $as_url , true );
}
/**
* GetStringを構成する為の仮関数
* @param {String} in
* @return {String}
* @par サンプル
* @code
* $_get = $this->to_keys_and_vals( $get );
* @endcode
*/
private function to_keys_and_vals( $in ){
if( $in ){
$tmp = explode( '&' , $in );
foreach( $tmp as $key => $val ){
$_tmp = explode( '=' , $val );
$ret[$_tmp[0]] = $_tmp[1];
}
return $ret;
}
}
/**
* location hedderを構成+送信。送信されるValueがある場合GetStginrを構成してサーバーへ送信します
* @param {String} in
* @param {String|Array} get Get Stringとして送信するデータがある場合はここで指定。ArrayかStrginで渡せます。$in内のGETとつなげます。
* @param {bool} as_url URL形式でGetValueを構成。array("key"=>"value")のvalue部分のみがhttp://****.com/value1/value2/value3/value4....となります。
* @param {bool} show_addr 送信されるヘッダーを表示(テスト関数)
* @return {void|String}
* @par サンプル
* @code
* public function _location($in,$get=null, $as_url=False ){
* $this->location($in,$get , $as_url , true );
* }
* @endcode
*/
public function location($in,$get=null, $as_url=False , $dont_exist=false , $ignore=array() , $return_url=false ){
if( $get ){
if( $as_url ){
if( is_array( $get ) ){
$tmp = $get;
}else{
$tmp = explode( '&' , $get );
}
foreach( $tmp as $val ){
$_tmp = explode( '=' , $get );
$in = $in.'/'.$_tmp[1];
}
}else{
//?が入っている場合一度解体して、新規にGetとして登録がある方を上書きする
if( preg_match( "(\?)" , $in ) ){
$__tmp = explode( '?' , $in );
$in = $__tmp[0];
$__tmp = $this->to_keys_and_vals( $__tmp[1] );
if( is_array($__tmp) ){
//if( count($__tmp) ){
if( is_array( $get ) ){
$get = array_merge( $__tmp , $get );
}else{
$_get = $this->to_keys_and_vals( $get );
$get = array_merge( $__tmp , $_get );
}
}
}
if( is_array( $get ) ){
foreach( $get as $key => $val ){
if( array_search( $key , $ignore ) === false ){
$_tmp[$key] = $val;
}
}
if( $_tmp ){
$tmp = http_build_query($_tmp);
//$tmp = implode( '&' , $_tmp);
$in = $in.'?'.$tmp;
}
}else{
$in = $in.'?'.$get;
}
}
}
if( $return_url ){
$dont_exist = true;
return $in;
}else{
$this->sendHeadder("Location: $in");
}
if( !$dont_exist ){
exit();
}
}
/**
* file -i -b コマンドで取得したfile typeをContent-typeで送信
* @param {String} file path
* @return {void}
* @par サンプル
* @code
* $this->controller->header->sendContentType( __DATA_UPFILE.$this->variables['VIEW_VAR']['file'] );
* @endcode
*/
public function sendContentType($file=null){
//ここで送信可能なHeddserを選ぶようにいずれする
if( !empty( $file ) && file_exists( $file ) ){
exec( "file -i -b ".$file , $_arr );
//Edited by Tamura on 2014/11/16 11:15:20なぜか以下でも動いてました。修正
//exec( "file -i -b ".$tmp_name , $_arr );
header("Content-type: ".$_arr[0]);
}
}
/**
* "Content-type: application/pdf" を送信
* @return {void}
*/
public function sendPDF(){$this->sendHeadder( "Content-type: application/pdf" );}
/**
* "Content-type: application/x-excel" を送信
* MS系ファイルはバージョンによってヘッダーが多数存在します。
* いずれはファイルパスを渡してバージョンに対応しないと問題がでます。
* @return {void}
*/
public function sendExcel(){$this->sendHeadder( "Content-type: application/x-excel" );}
/**
* "Content-type: application/msword" を送信
* MS系ファイルはバージョンによってヘッダーが多数存在します。
* いずれはファイルパスを渡してバージョンに対応しないと問題がでます。
* @return {void}
*/
public function sendWord(){$this->sendHeadder( "Content-type: application/msword" );}
/**
* "Content-type: text/xml;charset=UTF-8" を送信
* @return {void}
*/
public function sendXml(){$this->sendHeadder( "Content-Type: text/xml;charset=UTF-8" );}
/**
* "Content-type: text/plain;charset=UTF-8" を送信
* @return {void}
*/
public function sendPlain(){$this->sendHeadder( "Content-Type: text/plain;charset=UTF-8" );}
/**
* "Content-type: application/json;charset=UTF-8" を送信
* @return {void}
*/
public function sendJson(){$this->sendHeadder( "Content-Type: application/json;charset=UTF-8" );}
/**
* "Content-type: text/javascript;charset=UTF-8" を送信
* @return {void}
*/
public function sendJavascript(){$this->sendHeadder( "Content-Type: text/javascript;charset=UTF-8" );}
/**
* "Content-type: text/html;charset=UTF-8" を送信
* @return {void}
*/
public function sendHmlt(){$this->sendHeadder( "Content-Type: text/html;charset=UTF-8" );}
/**
* "Content-type: text/css" を送信
* @return {void}
*/
public function sendCss(){$this->sendHeadder( "Content-Type: text/css" );}
public function sendCsv(){ $this->setContentType( "text/csv" ); }
/**
* データをファイルとして送信
* @param {String} data
* @return {void}
*/
public function sendAsFile( $data , $name=null , $ext=null ){
//$file = "/tmp/".uniqid();
$file = sys_get_temp_dir().'/'.uniqid();
file_put_contents( $file , $data);
$this->sendFile( $file , $name , $ext );
unlink($file);
}
/**
* ファイル送信。ヘッダー送信とファイル送信を同時に行います(未完成)
* 印刷をクリックするとPDFがダウンロードされるようにviewから呼ばれるように変更予定
* MS系ファイルはバージョンによってヘッダーが多数存在します。
* いずれはファイルパスを渡してバージョンに対応しないと問題がでます。
* @param {String} file
* @return {void}
*/
public function sendFile( $file , $name=null , $ext=null ){
if( $file ){
if($this->content_type){
$content_type = $this->content_type;
}else{
if( file_exists($file) && preg_match( '/(\/tmp|\/home|data\/upimg\/)/' , $file ) ){
exec( "file -i -b ".$file , $ret );
if( preg_match( '/(.*);/i' , $ret[0] , $match ) ){
$content_type = trim( $match[1] );
}
}elseif( preg_match( '/(http|https)/' , $file , $ret ) ){
$header = get_headers( $file );
foreach( $header as $key => $val ){
if( preg_match( '/Content-Type:/i' , $val ) ){
$arr= explode( ':' , $val);
$arr= explode( ';' , $arr[1]);
$content_type = trim($arr[0]);
}
}
}
}
if( $content_type ){
if( !$ext ){
$ext = array_search( $content_type , $GLOBALS['__MIME_TYPES'] );
}
$ext = '.'.$ext;
$name = ($name) ? $name : uniqid();
$pos = -1 * ( strlen($ext) );
$name = ( substr( $name , $pos ) == $ext) ? $name : $name.$ext;
header('Content-Transfer-Encoding: binary');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s', time()) . ' GMT');
header("Content-Description: File Transfer");
header('Content-type: '.$content_type);
header('Content-Disposition: attachment; filename="'.$name.'"');
//header('Content-Disposition: inline; filename="'.$name.'"');
readfile( $file );
}
}
}
}
?>
/**
* @brief 言語設定クラス
* @version 1.0.0
* @author Yoshikuni Tamura
* @date 2013-01-01
* @par 詳細
* @arg ISO 639-1 2 char langage codeを使用
* @note
*
* Localeを有効にするには
* dpkg-reconfigure localesでLOCALEをInstallする必要があります。
*
*
*/
class CLang extends CObject{
var $code = array( 'ab'=> 'abk' , 'aa'=> 'aar' , 'af'=> 'afr' , 'ak'=> 'aka' , 'sq'=> 'alb' , 'am'=> 'amh' , 'ar'=> 'ara' , 'an'=> 'arg' , 'hy'=> 'arm' , 'as'=> 'asm' , 'av'=> 'ava' , 'ae'=> 'ave' , 'ay'=> 'aym' , 'az'=> 'aze' , 'bm'=> 'bam' , 'ba'=> 'bak' , 'eu'=> 'baq' , 'be'=> 'bel' , 'bn'=> 'ben' , 'bh'=> 'bih' , 'bi'=> 'bis' , 'bjn'=> 'bjn' , 'bs'=> 'bos' , 'br'=> 'bre' , 'bg'=> 'bul' , 'my'=> 'bur' , 'ca'=> 'cat' , 'ch'=> 'cha' , 'ce'=> 'che' , 'ny'=> 'nya' , 'zh'=> 'chi' , 'cv'=> 'chv' , 'kw'=> 'cor' , 'co'=> 'cos' , 'cr'=> 'cre' , 'hr'=> 'hrv' , 'cs'=> 'cze' , 'da'=> 'dan' , 'day'=> 'day' , 'dv'=> 'div' , 'nl'=> 'dut' , 'dz'=> 'dzo' , 'en'=> 'eng' , 'eo'=> 'epo' , 'et'=> 'est' , 'ee'=> 'ewe' , 'fo'=> 'fao' , 'fj'=> 'fij' , 'fi'=> 'fin' , 'fr'=> 'fre' , 'ff'=> 'ful' , 'gl'=> 'glg' , 'ka'=> 'geo' , 'de'=> 'ger' , 'el'=> 'gre' , 'gn'=> 'grn' , 'gu'=> 'guj' , 'ht'=> 'hat' , 'ha'=> 'hau' , 'he'=> 'heb' , 'hz'=> 'her' , 'hi'=> 'hin' , 'ho'=> 'hmo' , 'hu'=> 'hun' , 'ia'=> 'ina' , 'id'=> 'ind' , 'ie'=> 'ile' , 'ga'=> 'gle' , 'ig'=> 'ibo' , 'ik'=> 'ipk' , 'io'=> 'ido' , 'is'=> 'ice' , 'it'=> 'ita' , 'iu'=> 'iku' , 'ja'=> 'jpn' , 'jv'=> 'jav' , 'kl'=> 'kal' , 'kn'=> 'kan' , 'kr'=> 'kau' , 'ks'=> 'kas' , 'kk'=> 'kaz' , 'km'=> 'khm' , 'ki'=> 'kik' , 'rw'=> 'kin' , 'ky'=> 'kir' , 'kv'=> 'kom' , 'kg'=> 'kon' , 'ko'=> 'kor' , 'ku'=> 'kur' , 'kj'=> 'kua' , 'la'=> 'lat' , 'lb'=> 'ltz' , 'lg'=> 'lug' , 'li'=> 'lim' , 'ln'=> 'lin' , 'lo'=> 'lao' , 'lt'=> 'lit' , 'lu'=> 'lub' , 'lv'=> 'lav' , 'gv'=> 'glv' , 'mk'=> 'mac' , 'mg'=> 'mlg' , 'ms'=> 'may' , 'ml'=> 'mal' , 'mt'=> 'mlt' , 'mi'=> 'mao' , 'mr'=> 'mar' , 'mh'=> 'mah' , 'mn'=> 'mon' , 'na'=> 'nau' , 'nv'=> 'nav' , 'nb'=> 'nob' , 'nd'=> 'nde' , 'ne'=> 'nep' , 'ng'=> 'ndo' , 'nn'=> 'nno' , 'no'=> 'nor' , 'ii'=> 'iii' , 'nr'=> 'nbl' , 'oc'=> 'oci' , 'oj'=> 'oji' , 'cu'=> 'chu' , 'om'=> 'orm' , 'or'=> 'ori' , 'os'=> 'oss' , 'pa'=> 'pan' , 'pi'=> 'pli' , 'fa'=> 'per' , 'pl'=> 'pol' , 'ps'=> 'pus' , 'pt'=> 'por' , 'qu'=> 'que' , 'rm'=> 'roh' , 'rn'=> 'run' , 'ro'=> 'rum' , 'ru'=> 'rus' , 'sa'=> 'san' , 'sc'=> 'srd' , 'sd'=> 'snd' , 'se'=> 'sme' , 'sm'=> 'smo' , 'sg'=> 'sag' , 'sr'=> 'srp' , 'gd'=> 'gla' , 'sn'=> 'sna' , 'si'=> 'sin' , 'sk'=> 'slo' , 'sl'=> 'slv' , 'so'=> 'som' , 'st'=> 'sot' , 'es'=> 'spa' , 'su'=> 'sun' , 'sw'=> 'swa' , 'ss'=> 'ssw' , 'sv'=> 'swe' , 'ta'=> 'tam' , 'te'=> 'tel' , 'tg'=> 'tgk' , 'th'=> 'tha' , 'ti'=> 'tir' , 'bo'=> 'tib' , 'tk'=> 'tuk' , 'tl'=> 'tgl' , 'tn'=> 'tsn' , 'to'=> 'ton' , 'tr'=> 'tur' , 'ts'=> 'tso' , 'tt'=> 'tat' , 'tw'=> 'twi' , 'ty'=> 'tah' , 'ug'=> 'uig' , 'uk'=> 'ukr' , 'ur'=> 'urd' , 'uz'=> 'uzb' , 've'=> 'ven' , 'vi'=> 'vie' , 'vo'=> 'vol' , 'wa'=> 'wln' , 'cy'=> 'wel' , 'wo'=> 'wol' , 'fy'=> 'fry' , 'xh'=> 'xho' , 'yi'=> 'yid' , 'yo'=> 'yor' , 'za'=> 'zha' , 'zu'=> 'zul' );
var $locale_code = array( 'ara' => 'ar_AA' , 'chi' => 'zh_CN' , 'ger' => 'de_DE' , 'eng' => 'en_US' , 'spa' => 'es_MX' , 'fre' => 'fr_FR' , 'hin' => 'hi_IN' , 'ita' => 'it_IT' , 'jpn' => 'ja_JP' , 'kor' => 'ko_KR' , 'por' => 'pt_BR' , 'rus' => 'ru_RU' , 'tha' => 'th_TH' );
var $lang;
public function __construct(){
}
/**
*ISO 639-2 -> 1
*/
public function to2code($in){ return $this->get6391($in); }
/**
*ISO 639-1 -> 2
*/
public function to3code(){ return $this->get6392($in); }
/**
*ISO 639-1
*/
public function get6391($in){ return array_search( $in , $this->code ); }
/**
*ISO 639-2
*/
public function get6392( $in ){ return $this->code[$in]; }
/**
*ISO 639-1及び2を返す、1の場合2、2の場合1を返します
*/
public function getCode( $in ){
if(strlen( trim( $in ) ) === 3 ){
if( array_search( $in , $this->code ) ){
return trim( $in );
}
}else{
$code = $this->get6392($in);
if($code){
return $code;
}
}
return false;
}
/**
*$_REQUEST['set_language_use']を取得
*/
public function getRequestedLanguage(){
if( isset( $_REQUEST['set_language_use'] ) ){
//Edited by Tamura on 2022/12/02 15:39:23
return trim( $_REQUEST['set_language_use'] );
//return trim( $_POST['set_language_use'] );
}
return false;
}
/**
*$set_language_useをCookieへ保存
*/
public function saveLanguageUse( $lang ){
$arr = explode( '.' , $_SERVER["HTTP_HOST"] );
//K.Suzuki: 2014/03/28 mushr.jpなどのurlは頭を切らない。
if (count($arr)>2) {
unset( $arr[0] );
}
$dom = implode( '.' , $arr );
setcookie ( "language_use" , $lang , time() + 157680000 , "/" , ".".$dom );
}
public function redirect($lang=null){
$arr = explode( "?" , $_SERVER['REQUEST_URI'] );
if( !empty($lang) ){
$tmp_url_lang = substr( $arr[0] , 1 , 3 );
if( isset( $this->c->variables['WWW_VAR']['LANG_SELECTION'][$tmp_url_lang] ) ){
$uri = substr_replace( $arr[0] , $lang , 1 , 3 );
}else{
$uri = '/'.$lang.$arr[0];
}
}
//K.Suzuki: 2014/03/28 httpsにも対応
if ( $_SERVER['HTTPS'] ) {
$url = "https://".$_SERVER["HTTP_HOST"].$uri;
}
else {
$url = "http://".$_SERVER["HTTP_HOST"].$uri;
}
$tmp = array();
foreach( $_GET as $key => $val ) {
//Edited by Tamura on 2022/12/02 15:39:23
if( $key != "set_language_use" && $key != "language" && $key != "_INTERNAL_ACTION_URL" && $key != "redirect"){
//if( $key != "language" && $key != "_INTERNAL_ACTION_URL" && $key != "redirect"){
$tmp[$key] = $val;
//Edited by Tamura on 2015/06/20 20:46:32
//$tmp[] = "$key=$val";
}
}
if( count( $tmp )){
//Edited by Tamura on 2015/06/20 20:46:32
//$url .= "?".implode( "&" , $tmp );
$url .= "?".http_build_query($tmp);
}
//die();
header( "Location: $url" );
die();
}
/**
*$_COOKIE["language_use"]、$_REQUEST['set_language_use']、及び$_SERVER["HTTP_ACCEPT_LANGUAGE"]の指定で使用言語を設定しCookieへ保存
*/
public function get_lang(){
if( $_REQUEST["language_use"] ){
$this->lang = $_REQUEST["language_use"];
}elseif( defined('__LANG_IN_URL') ){
$this->lang = trim(substr( __LANG_IN_URL , 1));
$this->saveLanguageUse( $this->lang );
}else{
$user_languages = array();
if ( isset( $_SERVER["HTTP_ACCEPT_LANGUAGE"] ) ){
$languages = strtolower( $_SERVER["HTTP_ACCEPT_LANGUAGE"] );
// $languages = ' fr-ch;q=0.3, da, en-us;q=0.8, en;q=0.5, fr;q=0.3';
$languages = str_replace( ' ', '', $languages );
$languages = explode( ",", $languages );
foreach ( $languages as $language_list ){
$temp_array = array();
$temp_array[0] = substr( $language_list, 0, strcspn( $language_list, ';' ) );
$temp_array[1] = substr( $language_list, 0, 2 );
$user_languages[] = $temp_array;
}
}else{
$user_languages[0] = array( '','','','' );
}
$lang = $_COOKIE["checkLang"]? $_COOKIE["checkLang"]: $user_languages[0][1];
}
// 2文字コード(ISO 639-1 Code) から3文字コード(ISO 639-2 Code)に変換するために
$this->lang = $this->getCode($this->lang);
if(!$this->lang){
$this->lang = __DEFAULT_LANGTYPE;
}
return $this->lang;
}
/**
* localeの取得
*/
public function get_locale($lang=null){
if( $lang ){
return $this->locale_code[$lang];
}elseif( $this->lang ){
return $this->locale_code[$this->lang];
}elseif( defined( '__LANGTYPE' ) && __LANGTYPE ){
return $this->locale_code[__LANGTYPE];
}else{
return $this->locale_code[$this->get_lang()];
}
}
/**
* gettextの設定
* dpkg-reconfigure locales localeの追加Unix上で
*/
public function set_locale( $locale , $path , $domain=null , $lang=null ){
if( $lang){
$locale = $this->get_locale($lang);
}
if( $locale){
$locale = $locale.'.utf8';
define( '__CURRENT_LOCALE' , $locale );
$GLOBALS['CURRENT_LOCALE'] = $locale;
//putenv("LANG=$locale");
$tmp = setlocale( LC_ALL , $locale );
$path = ($path) ? $path : __LOCALE;
//gettextの設定
if( $domain ){
$domain = $domain;
}else{
$domain = ( defined( '__SITE_LOCALE' ) ) ? __SITE_LOCALE : __DEFAULT_LOCALE;
}
$test = bindtextdomain( $domain, $path );
$test = bind_textdomain_codeset( $domain , 'UTF-8');
textdomain( $domain );
return $tmp;
}
}
/**
*言語ファイルのロード
*/
function & load_lang_file( $file , $is_plain=False){
$load_stop = false;
if( file_exists( $file ) ){
if( $is_plain === True ){
$line = file( $file );
$n = count( $line );
for( $i=0 ; $i < $n ; $i++ ){
if( trim( $line[$i] ) ){
//コメント排除
if( trim( $line[$i] ) == '/*' ){
$load_stop = true;
}
if( trim( $line[$i] ) == '*/' ){
$load_stop = false;
}
if( !$load_stop ){
$arr = explode( "//" , $line[$i] );
if( trim( $arr[0] ) ){
$_arr = explode( "=" , $arr[0] );
$key = trim($_arr[0]);
unset( $_arr[0] );
$rtn[$key] = trim( implode( "=" , $_arr ) );
}
}
}
}
}else{
require_once $file;
$rtn = $LANG;
}
return $rtn;
}else{
return false;
}
}
}
?>
/**
* @brief CTime関係クラス(未完成)
* @version 1.0.0
* @author Yoshikuni Tamura
* @date 2013-01-01
*/
class CTime{
var $dt_obj;
var $def_timezone;
var $user_timezone;
function __construct(){
if( $GLOBALS['def_timezone'] ){
$this->def_timezone = $GLOBALS['def_timezone'];
}else{
$GLOBALS['def_timezone'] = $this->def_timezone = date_default_timezone_get();
}
}
function time($timezone=null){return $this->timestamp($timezone); }
/**
timestampを返す
*/
function timestamp($timezone=null){
$timezone = ( $timezone ) ? $timezone : $this->def_timezone;
date_default_timezone_set($timezone);
return time();
/*
if( $in ){ date_default_timezone_set($in); }
$dt_obj = new DateTime();
if( $in ){ date_default_timezone_set($this->def_timezone);}
return $dt_obj->format('U');
*/
}
public function set_timezone($timezone){
if( $timezone ){
if(!$this->user_timezone){
$this->user_timezone = date_default_timezone_get();
}
date_default_timezone_set($timezone);
}
}
public function unset_timezone(){
if($this->user_timezone){
date_default_timezone_set($this->user_timezone);
}
}
/**
mktime
*/
function mktime($h=0,$m=0,$s=0,$n=0,$d=0,$y=0,$timezone=null){
$timezone = ( $timezone ) ? $timezone : $this->def_timezone;
date_default_timezone_set($timezone);
$ts = mktime($h,$m,$s,$n,$d,$y);
return ( date( "I" , $ts ) ) ? $ts + 3600 : $ts;
}
/**
utcを返す
*/
function utc(){
date_default_timezone_set('UTC');
return time();
}
/**
timestampをLoaclに変換
*/
function local($timestamp,$timezone=null){
$timezone = ( $timezone ) ? $timezone : $this->def_timezone;
date_default_timezone_set($timezone);
if( date( "I" , $timestamp ) ){
return date( 'U' , $timestamp ) + 3600;
}else{
return date( 'U' , $timestamp );
}
}
/*
echo( 'Local --> '.date( 'Y/n/j H:i:s' , $obj_time->timestamp() )."
");
echo( 'UTC -->'.date( 'Y/n/j H:i:s' , $obj_time->timestamp( 'UTC' ) )."
");
echo( 'Tokyo '.date( 'Y/n/j H:i:s' , $obj_time->local($obj_time->utc() , 'Asia/Tokyo'))."
");
echo( 'UTC '.date( 'Y/n/j H:i:s' , $obj_time->utc() )."
");
echo( 'Tokyo '.date( 'Y/n/j H:i:s' , $obj_time->local($obj_time->utc() , 'Asia/Tokyo'))."
");
echo( 'UTC '.date( 'Y/n/j H:i:s' , $obj_time->utc() )."
");
echo( 'UTC '.date( 'Y/n/j H:i:s' , $obj_time->local( $obj_time->utc(1,1,1,1,1,1) , 'UTC') )."
");
echo( 'America/Los_Angeles '.date( 'Y/n/j H:i:s' , $obj_time->local( $obj_time->utc(1,1,1,1,1,1) , 'America/Los_Angeles') )."
");
echo( 'UTC '.date( 'Y/n/j H:i:s' , $obj_time->mktime(1,1,1,1,1,1) )."
");
//代表の関数
function getTimestamp( $tz ){
$this->localToUTC();
return call_user_method( "utcTo".$tz , $this , $tz );
}
function isInDST($hem){
$m = date( "n" , $this->timestamp );
if( $hem == "n" || $this->hem == "N")
return ( 3 < $m && $m <= 11 ) ? 1 : -1;
elseif($this->hem == "s" || $this->hem == "S")
return ( 3 > $m || $m >= 11 ) ? 1 : -1;
}
//LocalからUTCへ変換
function localToUTC(){
if( $this->cmosUseDST ){
$m = date( "n" , $this->timestamp );
// $this->dst = ( 3 < $m && $m < 11 ) ? 1 : -1;
$this->dst = date( "I" );
}
$t = $this->timestamp;
$this->utc = mktime ( date( H , $t ) + $this->deffToUTC , date(i,$t) , date(s,$t) , date(n,$t) , date(j,$t) , date(Y,$t) , $this->dst );
}
*/
/**
(例) Mon, 15 Aug 2005 15:12:46 UTC を返す
*/
/*
function getTime($in = 'America/Los_Angeles'){
$this->timestamp = $in;
if( $in ){ date_default_timezone_set($in);}
$dt_obj = new DateTime();
if( $in ){ date_default_timezone_set($this->def_timezone);}
return $dt_obj->format(DATE_RFC822);
}
function getTimeformat($in = 'America/Los_Angeles'){
$this->timestamp = $in;
if( $in ){ date_default_timezone_set($in);}
$dt_obj = new DateTime();
if( $in ){ date_default_timezone_set($this->def_timezone);}
return $dt_obj->format("F d, Y / h:ia");
}
*/
/**
以下トップページに表示させる時間
(例)2010年(平成22年)12月31日金曜日 午後3時45分
*/
/* function getJPformat($in = 'America/Los_Angeles'){
$this->timestamp = $in;
if( $in ){ date_default_timezone_set($in);}
$dt_obj = new DateTime();
if( $in ){ date_default_timezone_set($this->def_timezone);}
list($gengo, $year) = $this->time2gengo( $dt_obj->format("Ymd"), $dt_obj->format("Y") );
return $dt_obj->format("Y年({$gengo}{$year}年) m月d日h時i分A");
}
*/
/**
*/
/* function getYmd($in = 'America/Los_Angeles'){
$this->timestamp = $in;
if( $in ){ date_default_timezone_set($in);}
$dt_obj = new DateTime();
if( $in ){ date_default_timezone_set($this->def_timezone);}
return $dt_obj->format("Ymd");
}
*/
/**
元号
*/
/* function time2gengo($in,$yr) {
if ($in >= 19890108) {
$gengo = '平成';
$year = $yr - 1988;
} else if ($ymd >= 19261225) {
$gengo = '昭和';
$year = $yr - 1925;
} else if ($ymd >= 19120730) {
$gengo = '大正';
$year = $yr - 1911;
} else {
$gengo = '明治';
$year = $yr - 1868;
}
return array($gengo, $year);
}
*/
/**
* date関数拡張 - 日本語曜日名,元号に対応
* ※SJISエンコードでは文字化けすることあり
* @param string $format フォーマット文字列
* J : 日本語曜日名(月,火‥‥日の1文字)を返す
* K : 元号(明治, 大正, 昭和, 平成)を返す
* k : 元号年を返す
* その他は date 関数と同じ
* @param int $timestamp UNIX TIME(省略可能;date関数と同じ)
* @return string フォーマットされた時刻(date 関数と同じ)
*/
/*
function jdate($format) {
//英文曜日=>日本語曜日変換テーブル
static $table = array('Sun' => '日', 'Mon' => '月', 'Tue' => '火',
'Wed' => '水', 'Thu' => '木', 'Fri' => '金', 'Sat' => '土');
$timestump = (func_num_args() == 1) ? time() : func_get_arg(1);
//日本語曜日名
$str = $table[date('D', $timestump)]; //日本語曜日を計算
$format = mb_ereg_replace('J', $str, $format); //フォーマットを置換
//元号
list($gengo, $year) = time2gengo($timestump);
$format = mb_ereg_replace('K', $gengo, $format); //フォーマットを置換
$format = mb_ereg_replace('k', $year, $format);
return date($format, $timestump);
}
*/
}
/**
* @brief CUserAgentを処理します
* @version 1.0.0
* @author Yoshikuni Tamura
* @date 2013-01-01
*/
class CUserAgent{
var $agent;
var $detector;
var $ip_host_table;//大量に確認する場合様に設定
//Edited by Tamura on 2015/08/11 06:35:36
var $as_pc = array( 'pc' , 'windows' , 'ipad' );
function __construct(){
$this->set_detector();
}
//Edited by Tamura on 2015/08/11 06:35:36
function set_detector(){
$detector['windows'] = "/Windows NT/i";
$detector['iphone'] = "/iPhone/i";
$detector['ipod'] = "/iPod/i";
$detector['ipad'] = "/iPad/i";
$detector['android'] = "/^Android/i";
$detector['dream'] = "/dream/i";
$detector['cupcake'] = "/CUPCAKE/i";
$detector['blackberry9500'] = "/blackberry9500/i";
$detector['blackberry9530'] = "/blackberry9530/i";
$detector['blackberry9520'] = "/blackberry9520/i";
$detector['blackberry9550'] = "/blackberry9550/i";
$detector['blackberry9800'] = "/blackberry9800/i";
$detector['webos'] = "/webOS/i";
$detector['incognito'] = "/incognito/i";
$detector['webmate'] = "/webmate/i";
// Edited by Kono on 2017/10/31 11:00:00 START
// サムソンのAndroidの機種「SM-G900T」を追加
// $detector['samsung'] = "/samsung/i";
$detector['samsung'] = "/samsung|SM-G900T/i";
// Edited by Kono END
$detector['htc'] = "/HTC/";
$detector['nokia'] = "/nokia/i";
$detector['motorola'] = "/motorola/i";
$detector['lg'] = "/lg-/i";
$detector['sonyericsson'] = "/sonyericsson/i";
$detector['docomo'] = "/^DoCoMo/i";
$detector['vodafone'] = "/^Vodafone/i";
$detector['willcom'] = "/^Willcom/i";
$detector['softbank'] = "/^(J¥-PHONE|Vodafone|MOT¥-[CV]|SoftBank)/i";
$detector['au'] = "/^KDDI¥-/i";
$detector['nexus'] = "/Nexus/i";
$this->detector = $detector;
}
function is_ip($str) {
return filter_var($str, FILTER_VALIDATE_IP);
}
function is_ip_v4($ip) {
if(filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
return true;
}
return false;
}
function is_ip_v6($ip) {
if(filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
return true;
}
return false;
}
function is_bot( $ip , $user_agent=null ){
$ret = false;
if( preg_match('/'.__STATS_BOT_AGENT.'/' , $user_agent ) ){
$ret = true;
}else{
$ip = trim($ip);
if( $this->is_ip($ip)){
if( !$host = $this->ip_host_table[$ip] ){
$host = gf_gethostbyaddr ( $ip );
}
}else{
$host = $ip;
}
$this->ip_host_table[$ip] = $host;
if(preg_match('/'.__STATS_BOT_HOSTS.'/' , $host )){
$ret = true;
}
//厳格に調べる場合は、逆引きできないHostは削除する
if( defined('__STATS_STRICT_BOT_CHECK') && __STATS_STRICT_BOT_CHECK === true ){
if( $this->is_ip_v4($ip) ){
if($ip == $host){ $ret = true; }
}
}
}
/*
if($ret){
print_r( 'Bot found : '.$ip.' '.$host.' '.$user_agent."\n" );
}else{
print_r( 'Human Access: '.$ip.' '.$host.' '.$user_agent."\n" );
}
*/
return $ret;
}
function is_smart_phone(){ return $this->agent['smart_phone']; }
function is_mobile(){ return $this->agent['mobile']; }
/**
携帯、PC対応用に、ENCODEやVIEWのテンプレートを切り替える。
*/
function getUserAgent( &$c , $agent=null ){
$MD = new Mobile_Detect();
if( $agent ){
$MD->setUserAgent($agent);
}
if( $MD->isMobile() && !$MD->isTablet()){
if( $MD->isiOS() ){
$divice = 'iphone';
}elseif( $MD->isAndroidOS() ){
$divice = 'android';
}else{
$divice = 'other';
}
$this->agent['mobile'] = true;
$this->agent['smart_phone'] = true;
}else{
if( $MD->isiOS() ){
$divice = 'ipad';
}elseif( $MD->isAndroidOS() ){
$divice = 'android';
}else{
$divice = 'pc';
}
$this->agent['mobile'] = false;
$this->agent['smart_phone'] = false;
}
$this->agent['divice'] = $divice;
return $this->agent;
/*
$agent = ($agent) ? $agent : $_SERVER['HTTP_USER_AGENT'];
//foreach( $c->variables['WWW_VAR']['USER_AGENT_DETECTION'] as $key => $val ){
foreach( $this->detector as $key => $val ){
if(preg_match($val, $agent)){
$divice = $key;
break;
}
}
if( !$divice) { $divice = 'pc'; }
$this->agent['divice'] = $divice;
//PCを優先にする為に肯定文から否定文にしました。
//if( $divice !='pc' && !in_array( $divice , $c->variables['WWW_VAR']['USER_AGENT_AS_PC'] ) ){
if( $divice !='pc' && !in_array( $divice , $this->as_pc ) ){
$this->agent['mobile'] = true;
$this->agent['smart_phone'] = true;
}else{
$this->agent['mobile'] = false;
$this->agent['smart_phone'] = false;
}
return $this->agent;
*/
}
}
/**
* @brief Mail送信クラス
* @version 1.0.0
* @author Yoshikuni Tamura
* @date 2013-01-01
*
* @par 詳細
* phpのmail()関数は使用せず、直接Sendmailプロセスへ送信します。sendmailの設定が出来ている事が前提になります
*
* @par エンコードについて
* デフォルトではBase64を使用します。Bの指定でBase64、Qの指定でQuoted-Printableを利用可能です
*
* @par アドレスフォーマット
* Arrayもしくは、Stringで指定してください。以下の3つのフォーマットをto, from ,replayで受け付けます。
* @arg to@vivinavi.com
* @arg 田村 メール送信タイトル
";
* $this->c->mail->html( $html );
*
* //HTMLとしてBodyをファイルからロード(URL可)
* $this->c->mail->load_html( 'body.html' );
*
* //Attachmentロード(URL可)
* $this->c->mail->load_attachment( "http://URL/test.pdf" );
* $this->c->mail->load_attachment( "http://URL/test.jpeg" );
* $this->c->mail->load_attachment( "./local_test.jpeg" );
*
* //送信
* $this->c->mail->send( "to@vivinavi.com" , "こんちわ" );
* $this->c->mail->send( array( "to@vivinavi.com","田村"), "こんちわ" );
* $this->c->mail->send( array( "to@vivinavi.com","田村"), "こんちわ" , array( "from@vivinavi.com","送信者名"));
* @endcode
*
*/
define('__X_VN_VERSION' , '1.0.0' );
class CMail extends CObject{
var $title;
var $body;
var $to;
var $from;
var $reply;
var $headers = array();
var $sendmail_path = '/usr/sbin/sendmail';
var $debug = false;
var $text;
var $html;
var $attachment = array();
// var $set_prefix = true;
var $prefix = true;
var $sender_suffix = false; //Edited by Tamura on 2018/08/17 23:32:27
var $send_type;
var $unsubscribe_key;
var $unsubscribe_url;
var $unsubscribe_onclick;
var $set_unsubscribe = false;
public function __construct(){}
/**
* gettext用関数
* @param {string} lang in
* @return {string} 変換後のString
*/
public function _( $in ){
//return $this->controller->_( func_get_args() );
return $this->controller->_( $in );
}
/**
* ngettext用関数
* @param {string} lang msgid1
* @param {string} lang msgid2
* @param {string} lang in
* @return {string} 変換後のString
*/
public function _n( $msgid1 , $msgid2 , $in ){
return $this->controller->_n( $msgid1 , $msgid2 , $in );
}
/**
* CSanitize::clean($in , 'output' ) のエイリアス。返値を出力します
*
* 出力時の改行やForm時の
等の制御。詳細はCSanitize::clean()を確認してください。
* @return {string}
* @see output_adjust() CSanitize::clean()
*/
public function print_out( $in , $print_option=null , $return_str=false ){
$ret = $this->controller->sanitize->clean( $in , 'output' , $print_option );
if( $return_str ){
return $ret;
}else{
echo( $ret );
}
}
/**
* CSanitize::clean($in , 'output' ) のエイリアス。返値を出力しません
*
* 出力時の改行やForm時の
等の制御。詳細はCSanitize::clean()を確認してください。
* @return {string}
* @see print_out() CSanitize::clean()
*/
public function output_adjust( $in , $print_option=null ){
return $this->controller->sanitize->clean( $in , 'output' , $print_option );
}
/**
* Debug On
* @return {string} title
*/
function debug(){
$this->debug = true;
}
/**
* Load後にタイトルを返す
* @return {string} title
*/
function getTitle(){
return $this->title;
}
/**
* Load後にBodyを返す
* @return {string} title
*/
function getBody(){
return $this->body;
}
/**
* Load後にBodyを返す
* @return {string} title
*/
function getText(){
return $this->text;
}
/**
* Load後にBodyを返す
* @return {string} title
*/
function getHtml(){
return $this->html;
}
/**
* VariableをExtractしてFileをInclude
* @arg ExtractされるvariablesはCContoller::setm()で設定されたvaliablesのみです。
* @arg URLを指定した場合、VariableをExtractは使用できません
* @return {string} title
* @see body()
*/
function _load( $file ){
if( preg_match( "(http://|https://)" , $file ) ){
$ret = file_get_contents($file);
}else{
$controller = $this->controller;
if( isset($this->variables["MAIL_CONTENTS"]) ){
$data = $this->variables["MAIL_CONTENTS"];
}
//Edited by Tamura on 2023/03/26 15:13:13
//強制的にOFF
$GLOBALS['DTAMURA'] = 0;
if( $data ){ extract( $data , EXTR_SKIP ); }
if( !$this->debug ){ ob_start();}
if( include( $file ) ){
//ここでメール情報もしあればもロード
if( !empty($title) ){$this->title = $title; }
if( !empty($reply) ){ $this->reply = $reply; }
if( !empty($from) ){ $this->from = $from; }
if( !empty($to) ){ $this->to = $to; }
$ret = ob_get_contents();
}
if( !$this->debug ){ ob_end_clean();}
}
return $ret;
}
/**
* Bodyをセットする
* @param {strin} body data
* @param {bool} true = HTMLとして表示する
* @param {cahr} Q = 'Quoted-Printable' B ='Base64'
* @return {void}
* @see body() html() load() load_html() load_attachment()
*/
function body( $data , $is_html=false , $encode="B" ){
if( $is_html ){
$encode = ( $encode == 'Q' ) ? 'Quoted-Printable' : 'Base64';
// $data = $this->_load( $file );
$line[] = "Content-Type: text/html; charset=UTF-8";
$line[] = "Content-Transfer-Encoding:".$encode;
$line[] = "";
//phpのバージョンによりchunk_splitをする必要がある場合があります。
//$line[] = chunk_split( mb_convert_encoding( $data , $encode , "UTF-8" ) , 75 , "\n");
$line[] = mb_convert_encoding( $data , $encode , "UTF-8" );
$this->html .= implode( "\n" , $line );
}else{
$line[] = "Content-Type: text/plain; charset=UTF-8";
// Edited by Kono on 2019/07/04 13:11:01 START
$line[] = "Content-Transfer-Encoding: 8bit";
// Edited by Kono END
$line[] = "";
$line[] = $data;
$this->text .= implode( "\n" , $line );
}
}
/**
* HTMLとしてBodyをセットします
* @param {strin} body data
* @param {cahr} Q = 'Quoted-Printable' B ='Base64'
* @see body() html() load() load_html() load_attachment()
*/
function html( $data , $encode="B" ){
$this->body( $data , true , $encode );
}
/**
* ファイルをロードして、BodyにTextとしてセットします
* @param {strin} file path or URL
* @see body() html() load() load_html() load_attachment()
*/
function load( $file , $pre_file=""){
$data = $this->_load( $file );
//K.Suzuki 2016/02/03 主に送信者への送信確認用に、BODYの頭に追加できるようにしました。
if ($pre_file) {
$pre_data = $this->_load($pre_file);
$data = $pre_data.PHP_EOL.$data;
}
$this->body( $data );
}
/**
* HTMLファイルをロードして、BodyにHTMLとしてセットします
* @param {strin} file path or URL
* @param {cahr} Q = 'Quoted-Printable' B ='Base64'
* @see body() html() load() load_html() load_attachment()
*/
function load_html( $file , $encode="B" ){
$data = $this->_load( $file );
$this->html( $data , $encode );
}
/**
* Attachmentをロード(ローカルファイル及びURLからロードできます)
* @param {strin} file path or URL
* @param {strin} name 添付された後のファイルの名前
* @see body() html() load() load_html() load_attachment()
*/
function attachment( $data , $name , $mime ){
if( $data ){
$data = base64_encode( $data );
$line[] = 'Content-Type: '.$mime.'; name="'.$name.'"';
$line[] = 'Content-Transfer-Encoding: base64';
$line[] = 'Content-Disposition: attachment; filename="'.$name.'"';
$line[] = "";
$line[] = chunk_split( $data , 76 , "\n");
$line[] = "";
$line[] = "";
$this->attachment[] = implode( "\n" , $line );
return true;
}
return false;
}
/**
* Attachmentをロード(ローカルファイル及びURLからロードできます)
* @param {strin} file path or URL
* @param {strin} name 添付された後のファイルの名前
* @see body() html() load() load_html() load_attachment()
*/
function load_attachment( $file , $name=null ){
$data = file_get_contents( $file );
if( $data ){
$mime = $this->get_mimeheader( $file );
if( preg_match( "(http://|https://)" , $file ) ){
$ext = $this->controller->mime2ext($mime);
$name = uniqid().'.'.$ext;
}
// K.Suzuki: 2013/06/18 日本語をMIMEに変換。
// $name = ( $name ) ? mb_encode_mimeheader( $name , "UTF-8" ) : $file;
$name = ( $name ) ? $this->encode_mimeheader( $name , "UTF-8" ) : basename($file);
return $this->attachment($data , $name , $mime );
}
return false;
}
function set_abuse( $url=null ){
$url = ($url) ? $url : __ABUSE_REPORT_URL;
$this->headers['X-Report-Abuse'] = 'Please report abuse to: '.$url;
}
function set_dmca( $url=null ){
$url = ($url) ? $url : __DMCACOPYRIGHT_URL;
$this->headers['X-Report-Dmcacopyright'] = 'Please report DMCA copyright to: '.$url;
}
//Edited by Tamura on 2025/12/13 09:20:58
/**
* set postfix log stats id
*/
public function set_stats_id( $in = null ){
$this->headers['X-VN-MAIL-ID'] = (!empty($in)) ? $in : uniqid();
return $this->headers['X-VN-MAIL-ID'];
}
/**
* unsubscribeの構成
*/
function set_unsubscribe( $key=null , $onclick=false , $url=null ){
$this->set_unsubscribe = true;
$this->unsubscribe_key = $key;
$this->unsubscribe_url = $url;
if($onclick){
$this->unsubscribe_onclick = true;
}
}
//Edited by Tamura on 2021/03/18 13:45:26
private function _add_unsubscribe_header( $to ){
if($to && $this->set_unsubscribe ){
if($this->unsubscribe_url){
$url = $this->unsubscribe_url;
}elseif(defined('__UNSUBSCRIBE_URL')){
$url = __UNSUBSCRIBE_URL;
}
if( $url ){
$key = ( $this->unsubscribe_key ) ? $this->unsubscribe_key : $this->send_type;
$model = $this->controller->AddModel( 'global_blocks_unsubscribe' );
list($k,$u) = $model->unsubscribe_keys( $key , $this->get_address( $to ) );
$this->headers['List-Unsubscribe'] = '<'.$url.'?k='.$k.'&u='.$u.'>, メール送信タイトル
";
* $this->c->mail->html( $html );
*
* //HTMLとしてBodyをファイルからロード(URL可)
* $this->c->mail->load_html( 'body.html' );
*
* //Attachmentロード(URL可)
* $this->c->mail->load_attachment( "http://URL/test.pdf" );
* $this->c->mail->load_attachment( "http://URL/test.jpeg" );
* $this->c->mail->load_attachment( "./local_test.jpeg" );
*
* //送信
* $this->c->mail->send( "to@vivinavi.com" , "こんちわ" );
* $this->c->mail->send( array( "to@vivinavi.com","田村"), "こんちわ" );
* $this->c->mail->send( array( "to@vivinavi.com","田村"), "こんちわ" , array( "from@vivinavi.com","送信者名"));
* @endcode
*
* @par アドレスフォーマットについて
* Arrayもしくは、Stringで指定してください。以下の3つのフォーマットをto, from ,replayで受け付けます。
* @arg to@vivinavi.com
* @arg 田村