gc->collect(); } /*************************************************** Parameter Utility ****************************************************/ function __getUrlParameter( &$c ) { $params = array(); $tmp = explode('/', $_GET['_INTERNAL_ACTION_URL']); if(defined('__ACTION_AS_XML_JSON') ){ $params['action'] = __ACTION_AS_XML_JSON; }else{ $params['action'] = $tmp[__ACTION_POSITION]; } $param_start = __ACTION_POSITION+1; foreach ( $tmp as $i => $value) { if ($i >= $param_start) { $params[] = $value; } } return $params; } function __getDomainParameter() { $tmp = explode( '.', $_SERVER["HTTP_HOST"] ); return strtolower($tmp[0]); } function __getActionController() { if( !is_def( '__ACTION_CONTROLLER' ) ){ $params = array(); if( preg_match( '/([a-z0-9]*?)\.(xml|json)/' , $_GET['_INTERNAL_ACTION_URL'] , $xml_json )){ define( '__ACTION_AS_XML_JSON' , $xml_json[1] ) ; define( '__DATA_ACCESS_EXTENSIONS' , $xml_json[2] ) ; $_GET['_INTERNAL_ACTION_URL'] = preg_replace( '/[a-z0-9]*?\.(xml|json)/' , '' , $_GET['_INTERNAL_ACTION_URL'] ); } $tmp = explode('/', $_GET['_INTERNAL_ACTION_URL']); if( false !== in_array( $tmp[0] , array( 'jpn','eng','spa','tha','kor','chi','deu','fre','rus','ara','spa','hin','ita','por','tha' ))){ define( '__LANG_IN_URL' , '/'.$tmp[0] ) ; $params['action_controller'] = trim( $tmp[1] ); define( '__ACTION_POSITION' , 2 ) ; }elseif($_REQUEST["language_use"]){ define( '__LANG_IN_URL' , '/'.$_REQUEST["language_use"] ) ; define( '__ACTION_POSITION' , 1 ) ; // define( '__LANG_IN_URL' , '' ) ; $params['action_controller'] = trim( $tmp[0] ); }else{ define( '__LANG_IN_URL' , '' ) ; define( '__ACTION_POSITION' , 1 ) ; $params['action_controller'] = trim( $tmp[0] ); } if( $params['action_controller'] == '' ){ $params['action_controller'] = 'top'; } define( '__ACTION_CONTROLLER' , $params['action_controller'] ) ; return $params['action_controller']; }else{ return __ACTION_CONTROLLER; } } /*************************************************** サイト・ユーザ-個別設定 関係 ****************************************************/ //得エラー時のメール送信設定及びその他の設定($GLOBALS['ERROR']でエラーが飛んできてます) function config_error_report($c){ CError::report_via_mail(); } //言語設定 **************************************************** function clean_request_value( &$c ){ $c->request = $c->sanitize->clean( $c->request ); } //サーチエンジンからの間違えリンクを修正 function config_search_engin_check( &$c ) { $model = $c->AddModel( 'search_engin_check' ); //Googleの古いサイトからのリンク調節 $action_controller = __getActionController(); if( $action_controller == 'JA' ){ $model->check_if_old_site(); } //サーチエンジンで間違ったDivice設定がされてる場合 $model->check_set_divice_view(); $model->block_bot(); } //UserAgent function config_ua( &$c , &$ua ) { if( defined( '__TEST_FORCE_LAYOUT') ){ if( __TEST_FORCE_LAYOUT == 'mobile' ){ $UA = array( 'mobile' => true , 'smart_phone' => true ); }elseif( __TEST_FORCE_LAYOUT == 'pc' ){ $UA = array( 'mobile' => false , 'smart_phone' => false ); }else{ $UA = $ua->getUserAgent( $c ); } }else{ $UA = $ua->getUserAgent( $c ); } //K.Suzuki 2015/11/03 三原さん要望対応。開発SERVERのみでMOBILEが見れる。 //http://delta.vivinavi.com/production/mod_ticket/_wid_14cd3d9a14e075e5a246f48b3862e3afa38af21d // if ((gethostname() !== 'acolon') || ($_SERVER['SERVER_ADDR'] !== 'beta.vivinavi.com')) { // if (__IS_BETAs) { // $UA['smart_phone'] = 0; // $UA['mobile'] = 0; // } if( $c->request['set_divice_view'] ){ if( $c->request['set_divice_view'] == 'pc' ){ $c->cookie->regist( 'divice_view' , 'pc' , 86400 ); }elseif( $c->request['set_divice_view'] == 'mobile' ){ $c->cookie->regist( 'divice_view' , 'mobile' , 86400 ); }else{ $c->cookie->remove( 'divice_view' ); } $c->header->reload('','',array( 'set_divice_view' , '_INTERNAL_ACTION_URL' )); } // Edited by Kono on 2019/06/19 13:52:52 START // if( $c->request['divice_view'] == 'pc' ){ // $UA['smart_phone'] = 0; // $UA['mobile'] = 0; // }elseif( $c->request['divice_view'] == 'mobile' ){ // $UA['smart_phone'] = 1; // $UA['mobile'] = 1; // } // GETパラメタを先に見て、なかったらREQUEST(COOKIE含む)を見る。 if( $c->get['divice_view'] == 'pc' ){ $UA['smart_phone'] = 0; $UA['mobile'] = 0; } elseif( $c->get['divice_view'] == 'mobile' ){ $UA['smart_phone'] = 1; $UA['mobile'] = 1; } elseif( $c->request['divice_view'] == 'pc' ){ $UA['smart_phone'] = 0; $UA['mobile'] = 0; } elseif( $c->request['divice_view'] == 'mobile' ){ $UA['smart_phone'] = 1; $UA['mobile'] = 1; } // Edited by Kono END $c->seta( 'WWW_VAR' , 'USER_AGENT' , $UA ); //Edited by Tamura on 2015/08/11 06:35:36 define('__MOBILE' , $UA['mobile'] ); define('__SMART_PHONE' , $UA['smart_phone'] ); define('__DIVICE' , $UA['divice'] ); if( __MOBILE ){ define('__DIVICE_VIEW' , __WWW_VIEWS . 'mobile/' ); }else{ define('__DIVICE_VIEW' , __WWW_VIEWS . 'pc/' ); } } //言語設定 **************************************************** function config_language( &$lang , &$c ){ $__LANGTYPE = $lang->get_lang(); $__LOCALE_CODE = $lang->get_locale(); //Viewの確認 if( !file_exists( __WWW_VIEWS . $__LANGTYPE ) ){ // $__LANGTYPE = "jpn"; } if( $__LANGTYPE ){ define('__LOCALE_CODE' , $__LOCALE_CODE ); define('__LC' , $__LOCALE_CODE ); define('__LANGTYPE' , $__LANGTYPE ); define('__LT' , $__LANGTYPE ); define('__LANG_L' , __LANG . __LANGTYPE . __DS ); define('__LLANG' , __WWW_LANG . __LANGTYPE . __DS ); define('__LMAIL' , __WWW_MAIL . __LANGTYPE . __DS ); //Edited by Tamura on 2015/08/11 06:35:36 define('__LVIEWS' , __DIVICE_VIEW . __LANGTYPE . __DS ); //LANG config load ------------------- //言語は先にロードしないとwww_variables内で反映されない $c->load_lang( __LLANG .__LANGTYPE.'.php' ); //gettext用ドメインを設定 $c->lang->set_locale( __LOCALE_CODE , __WWW_LOCALE ); } } //各種Variables 設定関係 function load_www_variables(&$controller){ $c = &$controller; $SUB_DOMAIN = __getDomainParameter(); $ACTION_CONTROLLER = __getActionController(); define('__VN_LOCATION' , $SUB_DOMAIN ); //www_variables load require_once __WWW_CONFIG . 'www_variables.php'; //www_variables load require_once __WWW_CONFIG . 'tmp_variables.php'; //footer_icons load require_once __WWW_CONFIG . 'footer_icons.php'; //site_id_config load $c->AddModel('site_id_config'); $c->AddModel('item'); $WWW_VAR['SITE_ID_CONFIG'] = $c->MSite_id_config->get_config(); $WWW_VAR['AREA_ORDER'] = $c->MSite_id_config->get_area_order(); $c->MSite_id_config->set_lang(); ob_start(); //追加Langのロード(ロードは各SiteServiceConfigよりこちらが先) if( $WWW_VAR['DEFAULT_LANGS'] ){ foreach ( $WWW_VAR['DEFAULT_LANGS'] as $lang ) { $c->load_lang( $lang ); } } //追加Cofnigのロード if( $WWW_VAR['DEFAULT_CONFIGS'] ){ foreach ( $WWW_VAR['DEFAULT_CONFIGS'] as $val ) { require_once $val; } } ob_end_clean(); //Area config load if (file_exists(__AREA_CONFIG . $SUB_DOMAIN . '_config.php')) { require_once __AREA_CONFIG . $SUB_DOMAIN . '_config.php'; }else{ if( $c->MSite_id_config->define_site_id($SUB_DOMAIN) ){ require_once __AREA_CONFIG .'common_config.php'; }else{ $c->header->set404(); exit; } } define( '__SITE_ID_FULLTEXT' , '"+'.__SITE_ID.'"' ); define( '__SITE_ID_REGEXP_FREAM' , '(^__SK__|[[:space:]]__SK__[[:space:]]|[[:space:]]__SK__)' ); define( '__SITE_ID_REGEXP' , preg_replace('/__SK__/' , __SITE_ID , __SITE_ID_REGEXP_FREAM )); //ItemListのLoad $WWW_VAR['item_list'] = $c->MItem->get_item(); //product_listの設定(Betaはいるのか不明) $WWW_VAR['product_list'] = $c->MSite_id_config->set_product_list( $WWW_VAR['item_list'] ); //身近なエリアのびびなび $WWW_VAR['SITE_ID_CONFIG'][__SITE_ID]['nearby_area'] = $c->MSite_id_config->get_neaby_area_by_site_id(__SITE_ID, $WWW_VAR['SITE_ID_CONFIG_NEARBY_AREA_NUM']); //Serevice config load(__SERVICE_IDは$ACTION_CONTROLLERでLoadされた後に移動) if( file_exists( __SERVICE_CONFIG . __ACTION_CONTROLLER . '_config.php') ){ require_once __SERVICE_CONFIG . __ACTION_CONTROLLER . '_config.php'; } //元々はServiceLangのLoadが$lang_usesのロードより先でした。 //Edited by Tamura on 2014/09/18 16:19:31 //Service langを設定(Service langを優先にする) if( defined('__SERVICE_ID') ){ define('__URL_TO_SERVICE' , __LANG_IN_URL.'/'.__SERVICE_ID.'/' ); if( file_exists( __LLANG . __LANGTYPE . '_' . __SERVICE_ID .'.php')){ $c->load_lang( __LLANG . __LANGTYPE . '_' . __SERVICE_ID .'.php' ); } }else{ define('__URL_TO_SERVICE' , __LANG_IN_URL.'/' ); } //他にLangの設定があればLoad if( !empty( $lang_uses ) ){ foreach( $lang_uses as $lang ){ $c->load_lang($lang); } } //gettext用ドメインを設定 // $c->lang->set_locale( __LOCALE_CODE , __WWW_LOCALE ); //LocalTimestampの設定 if( defined('__TIMEZONE') ){ date_default_timezone_set(__TIMEZONE); //これはUserConfigでもやってます。 // define( '__UTC_OFFSET' , date('Z')/60/60 ); } if( !empty( $config_uses ) ){ foreach( $config_uses as $key => $val ){ require_once $val; } } //この位置からずらすな!消すな! //ここに無いと設定の上書きしません。 // $c->seta( 'FW_VAR' , $FW_VAR ); $c->seta( 'WWW_VAR' , $WWW_VAR ); $c->seta( 'GARBAGE_COLLECTION' , $GARBAGE_COLLECTION ); if( !empty( $config_uses ) ){ $c->set_config_use( $config_uses );} if( !empty( $lang_uses ) ){ $c->set_lang_use( $lang_uses );} if( !empty( $models_uses ) ){ $c->set_models_use( $models_uses );} if( !empty( $components_uses ) ){ $c->set_components_use( $components_uses );} //IphoneでinputのTextで日本語が打てない問題の臨時対応(多分cid cliant idと_CIDをご認識して、textのフィールドで日本語が打てない問題) if( !empty($c->request['_CIDATA']) ){ if( !empty($c->request['_CID'] )){ $c->request['_CID'] = gf_array_merge_recursive($c->request['_CID'] , $c->request['_CIDATA'] ); }else{ $c->request['_CID'] = $c->request['_CIDATA']; } unset($c->request['_CIDATA']); } //その他サイト必須関数 __init_area_controll( $c ); __js_enable_echo( $c ); // びびなび ロサンゼルス(アメリカ) クラシファイド タウン情報 掲示板 / 情報掲示板< //Metaセット $c->set_meta( 'description' , $c->variables['LANG']['SERVICE_DESCRIPTION'] ); $c->set_meta( 'keyword' , $c->variables['LANG']['SERVICE_KEYWORD'] ); define( '__UB_REUQEST' , 'd='.$_SERVER["HTTP_HOST"].'&lat='.__LAT_CENTER.'&lng='.__LNG_CENTER.'&n='.$c->variables['LANG']['SERVICE_TITLE'] ); } //エリアコントロール function __init_area_controll( &$c ){ $c->AddModel( 'area_control' ); $c->MArea_control->init(); } //JS使用可能確認 function __js_enable_echo( &$c ) { //Js Enable Echo Check if( !empty( $c->request['_ajax'] ) ){ $c->js_enabled = true; }else{ //K.Suzuki 2015/12/09 //現時点ではjs_echo_backはrequestに入っていない。js_echo_reqを使っているのもここだけ。いったんコメントアウト。 // if( ( $c->request['js_echo_req'] - 5 ) < $c->request['js_echo_back'] ){ // $c->js_enabled = true; // } // $c->cookie->regist( 'js_echo_req' , time() , 500000 ); } } //Staff情報設定 function config_staff( &$c ){ $MStaff = $c->AddModel( "staff" ); $MStaff->define_staff(); } //User情報設定 function config_user( &$c ){ //Test Userをセットする場合 if( is_def( '__TEST_USER_FORCE_LOGIN') ){ $c->{__USER_LOGIN_MODEL}->test_login(); } //Edited by Tamura on 2023/03/16 17:11:43 if( $_SERVER["REMOTE_USER"] ) { if( preg_match('|'.__SATFF_DOMAIN.'|' , $_SERVER['HTTP_REFERER'] ) && ( defined('__ADMIN_ENABLED_PROXY_LOGIN') && __ADMIN_ENABLED_PROXY_LOGIN === true) ){ $MStaff = $c->AddModel( "staff" ); if( $MStaff->is_staff()){ if( !empty($c->request['_USER_AS']) ){ if( $_USER_AS = $c->request['_USER_AS'] ){ $user = $c->{__USER_LOGIN_MODEL}->user_set_info_as_admin($_USER_AS); }else{ $user = $c->{__USER_LOGIN_MODEL}->user_login_status('out'); } }else{ $user = $c->{__USER_LOGIN_MODEL}->user_login_status(); } } }else{ $user = $c->{__USER_LOGIN_MODEL}->user_login_status(); } }else{ $user = $c->{__USER_LOGIN_MODEL}->user_login_status(); } //自動ログイン調節 if( !$user ){ $user = $c->{__USER_LOGIN_MODEL}->user_klogin(); } /* if( !$user = $c->{__USER_LOGIN_MODEL}->user_login_status() ){ //自動ログイン調節 // 自動ログイン一旦解除 K.suzuki 12/26 $user = $c->{__USER_LOGIN_MODEL}->user_klogin(); } */ define('__USER_ID' , empty( $user ) ? null : $user['uid'] ); define('__USER_USERNAME' , empty( $user ) ? null : $c->output_adjust($user['username'])); define('__USER_LOGIN_USER_ID' , empty( $user ) ? null : $user['login_user_id']); define('__USER_LOGIN_USERNAME' , empty( $user ) ? null : $user['login_username']); define('__USER_LOGIN_LEVEL' , empty( $user ) ? null : $user['level']); define('__USER_OFFICIAL_ACCOUNT' , empty( $user ) ? null : $user['official_account']); define('__BIZ_ID' , empty( $user ) ? null : $user['bizid']); define('__BIZ_USERNAME' , empty( $user ) ? null : $c->output_adjust($user['biz_username'])); define('__USER_LOGIN_STATUS' , empty( $user ) ? null : $user['_login_status']); define('__USER_POST_LAT' , empty( $user ) ? null : $user['preference']['post_lat']); define('__USER_POST_LNG' , empty( $user ) ? null : $user['preference']['post_lng']); define('__USER_LANG' , empty( $user ) ? null : $user['preference']['cfg_default_lang']); define('__AC_BLOACK_CLASS' , empty( $user ) ? null : $user['preference']['ac_bloack_class']); define('__AC_USER_CLASS' , empty( $user ) ? null : $user['preference']['ac_user_class']); define('__AC_GROUP_CLASS' , empty( $user ) ? null : $user['preference']['ac_group_class']); define('__AC_ADMIN_CLASS' , empty( $user ) ? null : $user['preference']['ac_admin_class']); define('__AC_AGE_CLASS' , empty( $user ) ? null : $user['preference']['ac_age_class']); define('__AC_AREA_CLASS' , empty( $user ) ? null : $user['preference']['ac_area_class']); define('__AC_REMORT_CLASS' , empty( $user ) ? null : $user['preference']['ac_remort_class']); define('__AC_LOGIN_CLASS' , empty( $user ) ? null : $user['preference']['ac_login_class']); define('__AC_REFRENCE_CLASS' , empty( $user ) ? null : $user['preference']['ac_refrence_class']); define('__AC_SPAM_CLASS' , empty( $user ) ? null : $user['preference']['ac_spam_class']); define('__AC_USER_RATE' , empty( $user ) ? null : $user['preference']['ac_user_rate']); define('__AC_COMUNITY_RATE' , empty( $user ) ? null : $user['preference']['ac_comunity_rate']); define('__CFG_CURRENCY' , empty( $user ) ? null : $user['preference']['cfg_currency']); $_bid_ = $c->cookie->get_cookie( "_bid_" ); if( !$_bid_ ){ //まだこの時点ではModelが使えないためIDは制作する。 $_bid_ = $c->MIdck->makeid( '_bid_' ); $c->cookie->regist( '_bid_' , $_bid_ , 15552000 ); } define('__BID' , $_bid_ ); $GLOBALS["message_by_thread"] = 0; //$c->variables["USER_VAR"]["preference"]["message_by_thread"] = 1; //Map Langage設定 if( !empty( $c->request['MAP_LANG'] ) && $c->variables['WWW_VAR']['MAP_LANG_SELECTION'][$c->request['MAP_LANG']] ){ $c->session->add( "MAP_LANG" , $c->variables['WWW_VAR']['MAP_LANG_SELECTION'][$c->request['MAP_LANG']] ); }elseif( !empty( $user['preference']['cfg_map_lang'] ) ){ $c->session->add( "MAP_LANG" , $user['preference']['cfg_map_lang'] ); } //UserがLang設定を更新したらここで一度設定して、リダイレクト if( $lang = $c->lang->getRequestedLanguage() ){ $c->lang->saveLanguageUse( $lang ); if( !$_SERVER['REMOTE_USER'] ){ $c->{__USER_LOGIN_MODEL}->update_user_value( 'cfg_default_lang' , $lang ); $c->{__USER_LOGIN_MODEL}->user_update_session_preference( 'cfg_map_lang' , $c->variables['WWW_VAR']['MAP_LANG_SELECTION'][$lang] ); } $c->session->add( "MAP_LANG" , $c->variables['WWW_VAR']['MAP_LANG_SELECTION'][$lang] ); $c->lang->redirect( $lang ); } //課税地域と通貨を設定 if( !empty($user['preference']['cfg_currency']) ){ define('__USER_CURRENCY' , $user['preference']['cfg_currency'] ); }else{ define('__USER_CURRENCY' , ( defined( '__DEFAULT_CURRENCY' ) ) ? __DEFAULT_CURRENCY : null ); } if( !empty($user['preference']['cfg_tax_area']) ){ define('__DEFAULT_TAX_AREA' , $user['preference']['cfg_tax_area'] ); }else{ define('__DEFAULT_TAX_AREA' , ( defined( '__DEFAULT_TAX_AREA' ) ) ? __DEFAULT_TAX_AREA : null ); } define('__USER_TAXABLE_AGNET' , ( !empty( $user['preference']['cfg_taxable_agnet'] ) ) ? true : false ); define('__USER_CART_ACTIVATED', ( !empty( $user['preference']['ucart'] ) ) ? true : false ); //Edited by Tamura on 2020/05/15 15:09:50 //User Cart関係 if( !empty($user['preference']['cfg_user_cart_price_limit']) ){ define( '__USER_ITEM_PRICE_LIMIT', $user['preference']['cfg_user_cart_price_limit'] ); }else{ define( '__USER_ITEM_PRICE_LIMIT', ( defined('__BIZ_ID')) ? constant( '__USER_ITEM_PRICE_LIMIT_BIZID_'.strtoupper(__USER_CURRENCY) ) : constant( '__USER_ITEM_PRICE_LIMIT_USER_'.strtoupper(__USER_CURRENCY)) ); } define('__USER_TIMEZONE_OVERRIDE' , true ); //LocalTimestampの設定 if( !empty($user['preference']['cfg_timezone']) && defined('__USER_TIMEZONE_OVERRIDE') && __USER_TIMEZONE_OVERRIDE ){ date_default_timezone_set($user['preference']['cfg_timezone']); } //Userの変更 if( !empty( $_REQUEST['_switch_user'] ) ){ $c->{__USER_LOGIN_MODEL}->switch_user(); } //デフォルトのAgentID設定 if( !defined('__AGENT_ID' ) ){ define('__AGENT_ID' , ( defined('__BIZAREA' ) ) ? 'BizArea' : __SERVICE_SITE ); } $c->AddModel( 'user_access_control' ); // Edited by Kono on 2019/01/29 13:31:00 START // $c->MUser_access_control->check_user_access_control( __USER_ID , $_SERVER['REMOTE_HOST'] , __BID ); $c->MUser_access_control->check_user_access_control( __USER_ID , __REMOTE_HOST , __BID ); // Edited by Kono END } /*************************************************** FW設定 関係 ****************************************************/ //Buffer Controll function config_ob_start( &$ob ){ $ob->start(); } function config_ob_end( &$ob ){ //この設定を有効にすると、viewでdisplayが終わって、ob->flush()をCallした瞬間にバッファーを送信します。 //また、その後に書かれている処理は持続されますが、待機及び表示はされません。 //if( defined('__CLOSE_AFTER_FLASH') && __CLOSE_AFTER_FLASH && !$GLOBALS['DTAMURA'] ){ if( defined('__CLOSE_AFTER_FLASH') ){ $ob->flush_close(); }else{ $ob->flush(); } } //Server Status //DownしているサーバーをMemcacheからロード(このデータはCronで動く/home/vnsh/vnnet/agora/agora_script/check_muse_server_status.phpから来ます) function config_server_status(&$c) { $arr = unserialize ( $c->memcache->get("server_status") ); $SERVER_STATUS = false; if( is_array($arr) && !empty( $arr ) ){ foreach( $arr as $key => $val ){ $SERVER_STATUS[$val['ip']] = $val['status']; } } $c->seta( 'SERVER_STATUS' , $SERVER_STATUS ); } //DB設定 function config_database(&$dh) { require __WWW_CONFIG . 'database.php'; if( is_array( $dbs ) ){ foreach ($dbs as $name => $database ) { $dh->setup( $name, $database ); } } } //Headert function config_header_class(&$c) { $c->header->setHeader('Expires: Sat, 01 Jan 2000 00:00:00 GMT'); $c->header->setHeader('Last-Modified: '.gmdate("D, d M Y H:i:s").' GMT'); $c->header->setHeader('Pragma: no-cache'); $c->header->setHeader('ETag: PUB' . time()); $c->header->setHeader('Cache-Control: no-cache'); } //session設定 function config_session_class(&$c) { if( defined('__ACTION_DOMAIN')){ ini_set('session.cookie_domain', '.'.__ACTION_DOMAIN ); if( preg_match( '/(rsce-beta\.vivinavi|rsce\.vivinavi)/',$_SERVER["HTTP_HOST"]) ){ $session_name = 'vnrsce'; }else{ $session_name = ( __IS_BETA ) ? 'beta-vnsess' : 'vnsess'; } $c->session->session_name( $session_name ); $c->session->session_save_path( __DATA_SESSION ); $c->session->session_start(); } } //Cookie設定 // Edited by Kono on 2018/07/31 14:52:00 START // function config_cookie_class( &$c ) {} function config_cookie_class( &$c ) { if( $c->cookie->get( __COOKIE_KEY_AGREED_TO_USE_OF_COOKIES ) ) { define( '__IS_AGREED_TO_USE_OF_COOKIES', true ); // クッキーを上書き $c->cookie->regist( __COOKIE_KEY_AGREED_TO_USE_OF_COOKIES, '1', 2 * 365 * 24 * 60 * 60 ); } } // Edited by Kono END //コントローラー設定 (CAppControllerを使用) function config_controller_class(){ require_once __WWW_CONTROLLERS . 'class.CAppController.php'; return "CAppController"; } function config_controller( &$c ){ // $c->config_controller(); } //モデル設定 function config_models( &$c ){ //Default Modelのロード if( $c->variables['WWW_VAR']['DEFAULT_MODELS'] ){ foreach ( $c->variables['WWW_VAR']['DEFAULT_MODELS'] as $model ) { $c->AddModel( $model ); } } } //モジュール設定 function config_module( &$c ){ if( $c->variables['WWW_VAR']['DEFAULT_MODULES'] ){ foreach ( $c->variables['WWW_VAR']['DEFAULT_MODULES'] as $module ) { $c->AddModule( $module ); } } } //コンポーネント設定 function config_components( &$c ){ if( !empty( $c->variables['WWW_VAR']['DEFAULT_COMPONENTS'] ) ){ foreach ( $c->variables['WWW_VAR']['DEFAULT_COMPONENTS'] as $component ) { $c->AddComponent( $component ); } } } /*************************************************** Action 関係 ****************************************************/ /** DispatchでCall これ作って、特定の掲示板にアクセスさせないようにする。?メンテ中みたいに。 @return {void} */ function before_action(){ if( defined('__STOP_ALL_SITE' ) && __STOP_ALL_SITE){ include __ERROR_DOCUMENT."maintenance.php"; die(); } } /** DispatchでCall @return {void} */ function after_action(){} //Action コントローラー設定 function & config_action_controller_class( &$c ){ $action_controller = __getActionController(); $actionControllerPath = __WWW_CONTROLLERS . $action_controller . '_action_controller.php'; if(file_exists($actionControllerPath)) { require_once $actionControllerPath; $action_controller_name = 'C' . ucfirst($action_controller) . 'ActionController'; $action_controller = new $action_controller_name(); $params = __getUrlParameter( $c ); $action = &$params['action']; if( trim( $params['action'] ) == '' || !method_exists( $action_controller , $action ) ){ $params['original_action'] = $params['action']; $params['action'] = 'index'; } $c->params = &$params; $c->action = &$action; $c->action_controller = &$action_controller_name; $c->seta( 'action' , $action ); $c->seta( 'action_controller' , $action_controller_name ); $c->seta( 'PARAMETERS_VAR' , $params ); $c->seta( 'VIEW_VAR' , 'action' , $action ); $c->seta( 'VIEW_VAR' , 'action_controller' , $action_controller_name ); $c->seta( 'VIEW_VAR' , 'params' , $params ); define('__URL_TO_ACTION' , '/'.__SERVICE_ID.'/'.$action.'/' ); return $action_controller; }else{ //ここでメソッドが無ければ404にする $c->header->set404(); exit; } } /*************************************************** View関係 ****************************************************/ function config_view_process($c) { if( !empty( $c->variables['WWW_VAR']['process_view'] ) && !$c->variables['WWW_VAR']['process_view'] ){ return False; }else{ return True; } } function config_view_class($c) { $SERVICE_ID = __getActionController(); /* ここでメインのVIEWコントローラー設定 */ if( $c->is_mobile() ){ require_once __WWW_VIEWS . "class.VAppController_mobile.php"; }else{ require_once __WWW_VIEWS . "class.VAppController.php"; } $lang_viewPath = __LVIEWS . $SERVICE_ID . __DS . 'class.' .$SERVICE_ID.'_view.php'; $viewPath = __WWW_VIEWS . $SERVICE_ID . __DS . 'class.' .$SERVICE_ID.'_view.php'; if (file_exists($lang_viewPath)) { require_once $lang_viewPath; $viewClass = 'V' . ucfirst($SERVICE_ID) . 'View'; }elseif(file_exists($viewPath)) { require_once $viewPath; $viewClass = 'V' . ucfirst($SERVICE_ID) . 'View'; }else{ $viewClass = 'CView'; } return $viewClass; } //Javascript & CSS function config_javascript_and_css(&$view) { if( !empty( $view->variables['WWW_VAR']['DEFAULT_JAPASCRIPT'] ) ){ foreach ( $view->variables['WWW_VAR']['DEFAULT_JAPASCRIPT'] as $script ) { $view->js( $script ); } } //Edited by Tamura on 2015/08/11 06:35:36 if( !empty( $view->variables['WWW_VAR']['DEFAULT_CSS'] ) ){ foreach ( $view->variables['WWW_VAR']['DEFAULT_CSS'] as $css ) { $view->css( $css ); } } if( $view->is_mobile() ){ //Edited by Tamura on 2015/08/11 06:35:36 //$view->css( __LANGTYPE . __DS . 'cell.css' ); //$view->css( __LANGTYPE . __DS . 'cell_gn.css' ); //$view->js( __HTTP_SCHEME.'js.vivinavi.com/mobile.js' ); } } //Layoutの特殊設定 function config_layout(&$view) { if( !empty($view->request['layout']) && $view->request['layout'] ){ $view->set_layout( __LVIEWS . 'layouts' . __DS . $view->request['layout'].'.php' ); } } function after_render(&$controller) { $controller->MSqllog->save(); $controller->after_render(); $run_time = round( getmicrotime() - $GLOBALS['INDEX_LOAD_TIME'] , 7 ); $log = date("Y/m/d" , __TIMESTAMP )."\t".__REMOTE_ADDR."\t".$_COOKIE["vnsess"]."\t".__SERVICE_ID."\t".$_REQUEST["_INTERNAL_ACTION_URL"]."\t".$_SERVER['HTTP_REFERER']."\t".__USER_ID."\t".__LANGTYPE."\t".$_SERVER['HTTP_HOST']."\t".__TIMESTAMP."\t".__BID."\t".$run_time."\t".__MOBILE."\t".__SMART_PHONE."\t".__DIVICE."\t".$_SERVER["REQUEST_URI"]."\t".$_SERVER['HTTP_USER_AGENT']."\n"; file_put_contents( __DATA_AC_LOG.__SITE_ID.'_ACCESS.log' , $log , FILE_APPEND | LOCK_EX); if( defined('__SLOW_LOG_CATCH') && $run_time > __SLOW_LOG_CATCH ){ file_put_contents( __DATA_AC_LOG.__SITE_ID.'_SLOW_ACCESS.log' , $log , FILE_APPEND | LOCK_EX); } // //特定UAを探す // //loccallyからクローラーでアクセスしたものを検知する // $ua = $_SERVER['HTTP_USER_AGENT'] ?? ''; // $ref = $_SERVER['HTTP_REFERER'] ?? ''; // if(preg_match('/Chrome\/91\.0\.4472\.124/i', $ua) && ($ref === '')){ // ob_start(); // phpinfo(); // $tmp_path = sys_get_temp_dir()."/phpinfo.html"; // $phpinfo_html = ob_get_clean(); // file_put_contents($tmp_path, $phpinfo_html); //確認用 // $html = file_get_contents($tmp_path); // //メール // $to = "sysad@vivinavi.com"; // $sub = "[BOT-TRACE] phpinfo"; // $controller->mail->load_attachment($tmp_path); // $controller->mail->html($phpinfo_html); // $controller->mail->send( $to, $sub); // //削除 // unlink($tmp_path); // ob_end_clean(); // } } getFixedHtml($dirty_html); // ------------------------------------------------- Class HtmlFixer { public $dirtyhtml; public $fixedhtml; public $allowed_styles; // inline styles array of allowed css (if empty means ALL allowed) private $matrix; // array used to store nodes public $debug; private $fixedhtmlDisplayCode; public function __construct() { $this->dirtyhtml = ""; $this->fixedhtml = ""; $this->debug = false; $this->fixedhtmlDisplayCode = ""; $this->allowed_styles = array(); } public function getFixedHtml($dirtyhtml) { $c = 0; $this->dirtyhtml = $dirtyhtml; $this->fixedhtml = ""; $this->fixedhtmlDisplayCode = ""; if (is_array($this->matrix)) unset($this->matrix); $errorsFound=0; while ($c<10) { /* iterations, every time it's getting better... */ if ($c>0) $this->dirtyhtml = $this->fixedxhtml; $errorsFound = $this->charByCharJob(); if (!$errorsFound) $c=10; // if no corrections made, stops iteration $this->fixedxhtml=str_replace('','',$this->fixedxhtml); $this->fixedxhtml=str_replace('','',$this->fixedxhtml); $this->fixedxhtml = $this->removeSpacesAndBadTags($this->fixedxhtml); $c++; } return $this->fixedxhtml; } private function fixStrToLower($m){ /* $m is a part of the tag: make the first part of attr=value lowercase */ $right = strstr($m, '='); $left = str_replace($right,'',$m); return strtolower($left).$right; } private function fixQuotes($s){ $q = "\"";// thanks to emmanuel@evobilis.com if (!stristr($s,"=")) return $s; $out = $s; preg_match_all("|=(.*)|",$s,$o,PREG_PATTERN_ORDER); for ($i = 0; $i< count ($o[1]); $i++) { $t = trim ( $o[1][$i] ) ; $lc=""; if ($t!="") { if ($t[strlen($t)-1]==">") { $lc= ($t[strlen($t)-2].$t[strlen($t)-1])=="/>" ? "/>" : ">" ; $t=substr($t,0,-1); } //missing " or ' at the beginning if (($t[0]!="\"")&&($t[0]!="'")) $out = str_replace( $t, "\"".$t,$out); else $q=$t[0]; //missing " or ' at the end if (($t[strlen($t)-1]!="\"")&&($t[strlen($t)-1]!="'")) $out = str_replace( $t.$lc, $t.$q.$lc,$out); } } return $out; } private function fixTag($t){ /* remove non standard attributes and call the fix for quoted attributes */ $t = preg_replace ( array( '/borderColor=([^ >])*/i', '/border=([^ >])*/i' ), array( '', '' ) , $t); $ar = explode(" ",$t); $nt = ""; for ($i=0;$ifixStrToLower($ar[$i]); if (stristr($ar[$i],"=")) $ar[$i] = $this->fixQuotes($ar[$i]); // thanks to emmanuel@evobilis.com //if (stristr($ar[$i],"=") && !stristr($ar[$i],"=\"")) $ar[$i] = $this->fixQuotes($ar[$i]); $nt.=$ar[$i]." "; } $nt=preg_replace("/<( )*/i","<",$nt); $nt=preg_replace("/( )*>/i",">",$nt); return trim($nt); } private function extractChars($tag1,$tag2,$tutto) { /*extract a block between $tag1 and $tag2*/ if (!stristr($tutto, $tag1)) return ''; $s=stristr($tutto,$tag1); $s=substr( $s,strlen($tag1)); if (!stristr($s,$tag2)) return ''; $s1=stristr($s,$tag2); return substr($s,0,strlen($s)-strlen($s1)); } private function mergeStyleAttributes($s) { // // merge many style definitions in the same tag in just one attribute style // $x = ""; $temp = ""; $c = 0; while(stristr($s,"style=\"")) { $temp = $this->extractChars("style=\"","\"",$s); if ($temp=="") { // missing closing quote! add missing quote. return preg_replace("/(\/)?>/i","\"\\1>",$s); } if ($c==0) $s = str_replace("style=\"".$temp."\"","##PUTITHERE##",$s); $s = str_replace("style=\"".$temp."\"","",$s); if (!preg_match("/;$/i",$temp)) $temp.=";"; $x.=$temp; $c++; } if (count($this->allowed_styles)>0) { // keep only allowed styles by Martin Vool 2010-04-19 $check=explode(';', $x); $x=""; foreach($check as $chk){ foreach($this->allowed_styles as $as) if(stripos($chk, $as) !== False) { $x.=$chk.';'; break; } } } if ($c>0) $s = str_replace("##PUTITHERE##","style=\"".$x."\"",$s); return $s; } private function fixAutoclosingTags($tag,$tipo=""){ /* metodo richiamato da fix() per aggiustare i tag auto chiudenti (
) */ if (in_array( $tipo, array ("img","input","br","hr")) ) { if (!stristr($tag,'/>')) $tag = str_replace('>','/>',$tag ); } return $tag; } private function getTypeOfTag($tag) { $tag = trim(preg_replace("/[\>\<\/]/i","",$tag)); $a = explode(" ",$tag); return $a[0]; } private function checkTree() { // return the number of errors found $errorsCounter = 0; for ($i=1;$imatrix);$i++) { $flag=false; if ($this->matrix[$i]["tagType"]=="div") { //div cannot stay inside a p, b, etc. $parentType = $this->matrix[$this->matrix[$i]["parentTag"]]["tagType"]; if (in_array($parentType, array("p","b","i","font","u","small","strong","em"))) $flag=true; } if (in_array( $this->matrix[$i]["tagType"], array( "b", "strong" )) ) { //b cannot stay inside b o strong. $parentType = $this->matrix[$this->matrix[$i]["parentTag"]]["tagType"]; if (in_array($parentType, array("b","strong"))) $flag=true; } if (in_array( $this->matrix[$i]["tagType"], array ( "i", "em") )) { //i cannot stay inside i or em $parentType = $this->matrix[$this->matrix[$i]["parentTag"]]["tagType"]; if (in_array($parentType, array("i","em"))) $flag=true; } if ($this->matrix[$i]["tagType"]=="p") { $parentType = $this->matrix[$this->matrix[$i]["parentTag"]]["tagType"]; if (in_array($parentType, array("p","b","i","font","u","small","strong","em"))) $flag=true; } if ($this->matrix[$i]["tagType"]=="table") { $parentType = $this->matrix[$this->matrix[$i]["parentTag"]]["tagType"]; if (in_array($parentType, array("p","b","i","font","u","small","strong","em","tr","table"))) $flag=true; } if ($flag) { $errorsCounter++; if ($this->debug) echo "
Found a ".$this->matrix[$i]["tagType"]." tag inside a ".htmlspecialchars($parentType)." tag at node $i: MOVED
"; $swap = $this->matrix[$this->matrix[$i]["parentTag"]]["parentTag"]; if ($this->debug) echo "
Every node that has parent ".$this->matrix[$i]["parentTag"]." will have parent ".$swap."
"; $this->matrix[$this->matrix[$i]["parentTag"]]["tag"]=""; $this->matrix[$this->matrix[$i]["parentTag"]]["tagType"]=""; $hoSpostato=0; for ($j=count($this->matrix)-1;$j>=$i;$j--) { if ($this->matrix[$j]["parentTag"]==$this->matrix[$i]["parentTag"]) { $this->matrix[$j]["parentTag"] = $swap; $hoSpostato=1; } } } } return $errorsCounter; } private function findSonsOf($parentTag) { // build correct html recursively $out= ""; for ($i=1;$imatrix);$i++) { if ($this->matrix[$i]["parentTag"]==$parentTag) { if ($this->matrix[$i]["tag"]!="") { $out.=$this->matrix[$i]["pre"]; $out.=$this->matrix[$i]["tag"]; $out.=$this->matrix[$i]["post"]; } else { $out.=$this->matrix[$i]["pre"]; $out.=$this->matrix[$i]["post"]; } if ($this->matrix[$i]["tag"]!="") { $out.=$this->findSonsOf($i); if ($this->matrix[$i]["tagType"]!="") { //write the closing tag if (!in_array($this->matrix[$i]["tagType"], array ( "br","img","hr","input"))) $out.="matrix[$i]["tagType"].">"; } } } } return $out; } private function findSonsOfDisplayCode($parentTag) { //used for debug $out= ""; for ($i=1;$imatrix);$i++) { if ($this->matrix[$i]["parentTag"]==$parentTag) { $out.= "
{$i}:"; if ($this->matrix[$i]["tag"]!="") { if ($this->matrix[$i]["pre"]!="") $out.=htmlspecialchars($this->matrix[$i]["pre"])."
"; $out.="".htmlspecialchars($this->matrix[$i]["tag"])."{$i} ".$this->matrix[$i]["tagType"].""; $out.=htmlspecialchars($this->matrix[$i]["post"]); } else { if ($this->matrix[$i]["pre"]!="") $out.=htmlspecialchars($this->matrix[$i]["pre"])."
"; $out.=htmlspecialchars($this->matrix[$i]["post"]); } if ($this->matrix[$i]["tag"]!="") { $out.="
".$this->findSonsOfDisplayCode($i)."
\n"; if ($this->matrix[$i]["tagType"]!="") { if (($this->matrix[$i]["tagType"]!="br") && ($this->matrix[$i]["tagType"]!="img") && ($this->matrix[$i]["tagType"]!="hr")&& ($this->matrix[$i]["tagType"]!="input")) $out.="
".htmlspecialchars("matrix[$i]["tagType"].">")."{$i} ".$this->matrix[$i]["tagType"]."
"; } } $out.="
\n"; } } return $out; } private function removeSpacesAndBadTags($s) { $i=0; while ($i<10) { $i++; $s = preg_replace ( array( '/[\r\n]/i', '/ /i', '/])*>( )*\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', '/<\/o:p>/i', '/])*>/i', '//', '/<\?(.|\s)*?\?>/' ), array( ' ', ' ', '', '', '', '', '', '', '', '', '', ' ', '', '' ) , trim($s)); } return $s; } private function charByCharJob() { $s = $this->removeSpacesAndBadTags($this->dirtyhtml); if ($s=="") return; $s = "".$s.""; $contenuto = ""; $ns = ""; $i=0; $j=0; $indexparentTag=0; $padri=array(); array_push($padri,"0"); $this->matrix[$j]["tagType"]=""; $this->matrix[$j]["tag"]=""; $this->matrix[$j]["parentTag"]="0"; $this->matrix[$j]["pre"]=""; $this->matrix[$j]["post"]=""; $tags=array(); while($i") { /* $tag contains a tag <...chars...> let's clean it! */ $tag = $this->fixTag($tag); $tagType = $this->getTypeOfTag($tag); $tag = $this->fixAutoclosingTags($tag,$tagType); $tag = $this->mergeStyleAttributes($tag); if (!isset($tags[$tagType])) $tags[$tagType]=0; $tagok=true; if (($tags[$tagType]==0)&&(stristr($tag,'/'.$tagType.'>'))) { $tagok=false; /* there is a close tag without any open tag, I delete it */ if ($this->debug) echo "
Found a closing tag ".htmlspecialchars($tag)." at char $i without open tag: REMOVED
"; } } if ($tagok) { $j++; $this->matrix[$j]["pre"]=""; $this->matrix[$j]["post"]=""; $this->matrix[$j]["parentTag"]=""; $this->matrix[$j]["tag"]=""; $this->matrix[$j]["tagType"]=""; if (stristr($tag,'/'.$tagType.'>')) { /* it's the closing tag */ $ind = array_pop($padri); $this->matrix[$j]["post"]=$contenuto; $this->matrix[$j]["parentTag"]=$ind; $tags[$tagType]--; } else { if (@preg_match("/".$tagType."\/>$/i",$tag)||preg_match("/\/>/i",$tag)) { /* it's a autoclosing tag */ $this->matrix[$j]["tagType"]=$tagType; $this->matrix[$j]["tag"]=$tag; $indexparentTag = array_pop($padri); array_push($padri,$indexparentTag); $this->matrix[$j]["parentTag"]=$indexparentTag; $this->matrix[$j]["pre"]=$contenuto; $this->matrix[$j]["post"]=""; } else { /* it's a open tag */ $tags[$tagType]++; $this->matrix[$j]["tagType"]=$tagType; $this->matrix[$j]["tag"]=$tag; $indexparentTag = array_pop($padri); array_push($padri,$indexparentTag); array_push($padri,$j); $this->matrix[$j]["parentTag"]=$indexparentTag; $this->matrix[$j]["pre"]=$contenuto; $this->matrix[$j]["post"]=""; } } } } else { /* content of the tag */ $ns.=$s[$i]; } $i++; } /* remove not valid tags */ for ($eli=$j+1;$elimatrix);$eli++) { $this->matrix[$eli]["pre"]=""; $this->matrix[$eli]["post"]=""; $this->matrix[$eli]["parentTag"]=""; $this->matrix[$eli]["tag"]=""; $this->matrix[$eli]["tagType"]=""; } $errorsCounter = $this->checkTree(); // errorsCounter contains the number of removed tags $this->fixedxhtml=$this->findSonsOf(0); // build html fixed if ($this->debug) { $this->fixedxhtmlDisplayCode=$this->findSonsOfDisplayCode(0); echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; for ($k=0;$k<=$j;$k++) { echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; } echo "
node idpretagpostparentTagtipo
$k ".htmlspecialchars($this->matrix[$k]["pre"])." ".htmlspecialchars($this->matrix[$k]["tag"])." ".htmlspecialchars($this->matrix[$k]["post"])." ".$this->matrix[$k]["parentTag"]." ".$this->matrix[$k]["tagType"]."
"; echo "
{$j}
\n\n\n\n".$this->fixedxhtmlDisplayCode; } return $errorsCounter; } } ?>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); } } ?>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 ); } } ?>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('/([^>]*)<\/title>/si', $contents, $match ); //if (isset($match) && is_array($match) && count($match) > 0){ if (!empty($match)){ $title = strip_tags($match[1]); } //Links if( $link_tag[0] ){ foreach( $link_tag[0] as $tag ){ preg_match_all('/\s\w*?=(["?].*?["?]|.*?[^\s]+)?/i', $tag , $tmp ); foreach( $tmp[0] as $val ){ $arr = explode( "=" , $val ); $arr[1] = preg_replace('(\'|")', '' , $arr[1] ); $_tmp[trim($arr[0])] = trim($arr[1]); } $links[] = $_tmp; unset( $_tmp ); } } if( $meta_tag[0] ){ foreach( $meta_tag[0] as $tag ){ preg_match_all('/\s\w*?=(["?].*?["?]|.*?[^\s]+)?/i', $tag , $tmp ); foreach( $tmp[0] as $val ){ $arr = explode( "=" , $val ); $arr[0] = trim($arr[0]); $arr[1] = trim( preg_replace('(\'|")', '' , $arr[1] ) ); $_tmp[$arr[0]] = $arr[1]; } if( $_tmp['name'] ){ $metas[$_tmp['name']] = $_tmp['content']; }else{ $metas[$arr[0]] = $arr[1]; } unset( $_tmp ); } } $result = array ( 'title' => $title , 'meta' => $metas , 'link' => $links ); } return $result; } } ?><? /** * @author Yoshikuni Tamura * @version 1.0.0 * @date 2006-05-01 * @note 改造してOBをキャッシュするのはありかもしれません。 */ class CHeader extends CObject{ var $header; var $content_type; /** */ public function __construct(){} /** * ヘッダー送信 * @param {String} in * @param {bool} replace php header参照 * @param {int} code HTTP Error code * @return {void} * @par サンプル * @code * $c->header->setHeader('Expires: Sat, 01 Jan 2000 00:00:00 GMT'); * @endcode */ public function setHeader($in , $replace=true , $code=null){ if( $code ){ header( $in , $replace , $code ); if( file_exists( __ERROR_DOCUMENT.$code.".php" ) ){ include __ERROR_DOCUMENT.$code.".php"; }elseif( file_exists( __ERROR_DOCUMENT.$code.".html" ) ) { include __ERROR_DOCUMENT.$code.".html"; }else{ echo( '<html><head><title>HTTP ERROR '.$code.'

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 ); } } } } ?> '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; } } } ?>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); } */ } 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; */ } } * @arg array( "to@vivinavi.com" , "田村" ); * * @par サンプル * @code * //TextとしてBodyを変数からセット * $body = "こんにちわ"; * $this->c->mail->body( $body ); * * //TextとしてBodyをファイルからロード(URL可) * $this->c->mail->load( 'body.php' ); * * //HTMLとしてBodyを変数からセット * $html = "

メール送信タイトル

"; * $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.'>, '; if($this->unsubscribe_onclick){ $this->headers['List-Unsubscribe-Post'] = 'List-Unsubscribe=One-Click'; } } } } //Edited by Tamura on 2021/03/18 13:45:26 private function _add_unsubscribe_link( $in , $encode=false ){ if( $this->set_unsubscribe && $this->headers['List-Unsubscribe'] ){ preg_match('/<(.*?)>/', $this->headers['List-Unsubscribe'] , $ret); if( $encode ){ //ここはメールアドレスをリンクにいれる為一度解体する必要があります。 //本文を作る前にリンクを入れ替えする事も考えましたが、send()時に$toをセットしているため、send()前に本文をセットする都合上 //どおしても一度解体する必要があります。 $tmp = explode( "\n\n" , $in); $_ret[] = array_shift ( $tmp ); $_ret[] = ''; $_ret[] = mb_convert_encoding( preg_replace('/__REPLACE_WITH_UNSUBSCRIBE_LINK__/', $ret[1] , mb_convert_encoding( trim(implode($tmp)) , "UTF-8" , $encode ) ) , $encode , "UTF-8" ); return implode("\n",$_ret); }else{ return preg_replace('/__REPLACE_WITH_UNSUBSCRIBE_LINK__/', $ret[1] , $in ); } } return $in; } /** * mimeheaderの構成 */ function get_mimeheader( $file ){ if( preg_match( "(http://|https://)" , $file ) ){ $headers = get_headers( $file ); foreach( $headers as $key => $val ){ if( preg_match( "(Content-Type:)" , $val ) ){ $arr = explode( ':' , $val ); return trim( $arr[1] ); } } }else{ return mime_content_type( $file ); } } /** * Boundaryを構成します * @arg 以下の構成をフォームするFunction * @code * boundary_id * --boundary_id * --alt-boundary_id * plain text body * --alt-boundary_id * html body * --alt-boundary_id-- * --boundary_id * attachments 1 * --boundary_id * attachments 2 * --boundary_id-- * @endcode * * @return {string} body */ function compose( $encode='B'){ $encode = ( $encode == 'Q' ) ? 'Quoted-Printable' : 'Base64'; //Edited by Tamura on 2021/03/18 13:45:26 $this->text = $this->_add_unsubscribe_link($this->text); $this->html = $this->_add_unsubscribe_link($this->html , $encode ); $boundary_id = 'boundary_'.uniqid(); if( !empty($this->html) ){ //plain/hmlt Alternative $line[] = 'Content-Type: multipart/alternative; boundary="nikoniko-'.$boundary_id.'"'; //$line[] = 'Content-Transfer-Encoding:'.$encode; $line[] = ''; $line[] = '--nikoniko-'.$boundary_id; $line[] = $this->text; $line[] = ''; $line[] = '--nikoniko-'.$boundary_id; $line[] = $this->html; $line[] = '--nikoniko-'.$boundary_id.'--'; $line[] = ''; }else{ //Plain $line[] = $this->text; } $body = implode( "\n" , $line ); unset($line); //メール構成 if( !empty($this->attachment) ){ foreach( $this->attachment as $key => $val ){ $tmp[] = '--'.$boundary_id; $tmp[] = $val; } $attachment = implode( "\n" , $tmp ); unset($tmp); $line[] = 'Content-Type: multipart/mixed; boundary="'.$boundary_id.'"'; //$line[] = 'Content-Transfer-Encoding:'.$encode; $line[] = ''; $line[] = '--'.$boundary_id; $line[] = $body; $line[] = ''; $line[] = $attachment; $line[] = '--'.$boundary_id.'--'; $body = implode( "\n" , $line ); unset($line); } return $body; } /** * Array及び 名前 形式のアドレス部分の取得 * * @return {string} メールアドレス */ function get_name( $in ){ if( is_array($in) ){ return $in[1]; }else{ if( preg_match( "(<)" , $in ) ){ $arr = explode('<', $in ); return trim( $arr[0] ); }else{ return $in; } } } /** * Array及び 名前 形式のアドレス部分の取得 * * @return {string} 名前 */ function get_address( $in ){ if( is_array($in) ){ return $in[0]; }else{ if( preg_match( "(<)" , $in ) ){ $arr = explode('<', $in ); return trim( preg_replace('/>/' , '' , $arr[1] ) ); }else{ return $in; } } } /** * メールヘッダー用のアドレスを制作 * @arg 以下のフォーマットを$typeに従って制作します * @arg From : from@vivinavi.com * @arg To : from@vivinavi.com * @arg Reply-To : from@vivinavi.com * * @param {string} type From To Reply-to等 * @param {string|array} mail address * to@vivinavi.com, 田村 , array( "田村" , "to@vivinavi.com" );形式 * @return {string} ヘッダー用アドレス */ function address( $type , $in , $add_suffix=false){ if($in){ if( is_array($in) ){ // K.Suzuki: 2013/06/18 日本語をMIMEに変換。 // $address = $in[1].' <'.mb_encode_mimeheader( $in[0] , "UTF-8" ).'>'; //Message同様、suffixを付ける。//K.Suzuki 2016/02/03 if ( $add_suffix === true && defined( '__MAIL_FROM_SUFFIX') && strpos($in[1], __MAIL_FROM_SUFFIX) === false ) { //Edited by Tamura on 2018/08/17 23:32:27 //$in[1] = $in[1].__MAIL_FROM_SUFFIX; if( $this->sender_suffix === false ){ // Edited by Iguchi on 2019/11/16 11:30:00 START // $in[1] = $in[1].__MAIL_FROM_SUFFIX; // Edited by Iguchi on 2020/01/09 15:10:00 START //suffix言語対応 // $in[1] = $in[1].' '.__MAIL_FROM_SUFFIX; $mail_from_suffix = ( $this->c->variables['LANG']['MAIL_FROM_SUFFIX'] ) ? $this->c->variables['LANG']['MAIL_FROM_SUFFIX'] : __MAIL_FROM_SUFFIX; $in[1] = $in[1].' '.$mail_from_suffix; // Edited by Iguchi END // Edited by Iguchi END }else{ $in[1] = $in[1].$this->sender_suffix; } } $address = $this->encode_mimeheader( $in[1] , "UTF-8" ).' <'.$in[0].'>'; }else{ $in = trim($in); if( preg_match( "/(.*?)<(.*?)>/" , $in , $match ) ){ $arr = explode( '<' , $in ); $name = trim( $match[1] ); $addr = trim( $match[2] ); if( !$name ){ $name = $addr; } // K.Suzuki: 2013/06/18 PHPのmb_encode_mimeheaderはバグがあるので変更 // $name = mb_encode_mimeheader( trim( $name ) , "UTF-8" ); // $name = $this->encode_mimeheader( trim( $name ) , "UTF-8" ); if ( $add_suffix === true && defined( '__MAIL_FROM_SUFFIX') && strpos($name, __MAIL_FROM_SUFFIX) === false ) { if( $this->sender_suffix === false ){ $mail_from_suffix = ( $this->c->variables['LANG']['MAIL_FROM_SUFFIX'] ) ? $this->c->variables['LANG']['MAIL_FROM_SUFFIX'] : __MAIL_FROM_SUFFIX; $name = $name.' '.$mail_from_suffix; }else{ $name = $name.$this->sender_suffix; } } //Edited by Tamura on 2024/01/05 11:29:21 $address = $name." <".$addr.'>'; $address = $this->encode_mimeheader( trim( $name ) , "UTF-8" )." <".$addr.'>'; }else{ $address = $in; } } return $type .': '.$address; } } /** * set_prefix */ public function set_prefix( $in=true ){ // Edited by Kono on 2018/09/27 10:54:00 START // 空をセットする場合があるため、ifをコメントアウト。 // if( $in ){ $this->prefix = $in; // } // Edited by Kono END } /** * set_suffix */ //Edited by Tamura on 2018/08/17 23:32:27 public function set_suffix( $in ){ $this->sender_suffix = $in; } /** * to from等をローカル変数へセット、及びデフォルト値等の準備 * @see CMail::controller() */ private function prepare( $to , $from='' , $reply='' , $title='' , $body='' ){ if($to){ $this->to = $to; } if($body){ $this->body = $body; } if($title){ $this->title = $title; }else{ if( !$this->title && defined( '__MAIL_TITLE') ){ $this->title = __MAIL_TITLE; } } if( $this->prefix ){ if( $this->prefix === true ){ if(defined( '__MAIL_PREFIX') ){ // Edited by Iguchi on 2020/01/09 15:10:00 START //prefix言語対応 // $this->title = __MAIL_PREFIX." ".$this->title; $mail_prefix = ( $this->c->variables['LANG']['MAIL_PREFIX'] ) ? $this->c->variables['LANG']['MAIL_PREFIX'] : __MAIL_PREFIX; $this->title = $mail_prefix." ".$this->title; // Edited by Iguchi END } }else{ $this->title = $this->prefix." ".$this->title; } } if($from){ $this->from = $from; }else{ if( !$this->from && defined( '__MAIL_SUPPORT') ){ $this->from = __MAIL_SUPPORT; } } if($reply){ $this->reply = $reply; }else{ $this->reply = $this->from; //Edited by Tamura on 2015/09/15 17:29:12 // if( !$this->reply && defined( '__MAIL_RETURN' ) ){ // $this->reply = __MAIL_RETURN; // } } } /** * メール送信をします * @par Bodyのセットは別途body()メソッドによって行ってください。 * @code * //TextとしてBodyを変数からセット * $body = "こんにちわ"; * $this->c->mail->body( $body ); * * //TextとしてBodyをファイルからロード(URL可) * $this->c->mail->load( 'body.php' ); * * //HTMLとしてBodyを変数からセット * $html = "

メール送信タイトル

"; * $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 田村 * @arg array( "田村" , "to@vivinavi.com" ); * * @param {string|array} to address * @param {string} title * @param {string|array} from address * @param {string|array} reply address * @param {array} add_header * @param {char} encode B or Q * @return {bool} true = 送信 */ function _send( $to=null , $title=null , $from=null , $reply=null , $add_header=null , $encode='B' , $save_file=null){ $status = false; if( $to ){ $this->prepare( $to , $from , $reply , $title ); $this->set_abuse(); $this->set_dmca(); $this->_add_unsubscribe_header($this->to); $line[] = "X-VN: ".__X_VN_VERSION; $line[] = "X-Mailer: VN-Mailer [version nikox ]"; $line[] = "MIME-Version: 1.0"; $line[] = $this->address( 'From' , $this->from , true); $line[] = $this->address( 'Reply-To' , $this->reply ); $line[] = $this->address( 'Return-Path' , $this->reply ); $line[] = $this->address( 'To' , $this->to ); // K.Suzuki: 2013/06/18 PHPのエンコーダーはバグがあるので変更。 // $line[] = 'Subject: '.mb_encode_mimeheader( $this->title , "UTF-8" ); $line[] = 'Subject: '.$this->encode_mimeheader( $this->title , "UTF-8" ); //追加ヘッダー if( $this->headers ){ foreach( $this->headers as $key => $val ){ $line[] = $key.": ".$val; } } //追加ヘッダー if( $add_header ){ foreach( $add_header as $key => $val ){ $line[] = $key.": ".$val; } } $line[] = $this->compose( $encode ); $_from = $this->get_address( $this->from ); $_to = $this->get_address( $this->to ); // Edited by Kono on 2018/10/16 09:53:00 START // テストメールアドレス廃止のため、コメントアウト。 //いずれこれは消す // if ( __IS_BETA && !isset($GLOBALS['DISABLE_IS_BETA'] ) ) { // $_to = __TEST_EMAIL_ADDRESS; // } // Edited by Kono END if( is_null($save_file) ){ if( $mp = popen( $this->sendmail_path.' -f '.$_from.' '.$_to , 'w' ) ){ //Edited by Tamura on 2022/11/09 11:10:23 ///Headderにスペースが入るとエラーになる為 //fputs($mp, implode( "\n" , $line ) ); fputs($mp, implode( "\n" , array_filter($line) ) ); pclose($mp); $status = true; }else{ trigger_error( "Sendmail Error TID:$tid \n", E_USER_ERROR); $status = false; } }else{ $save_data = $this->sendmail_path.' -f '.$_from.' '.$_to."\n".$this->send_type."\n\n".implode( "\n" , array_filter($line) ); if( $save_file === false ){ $status = $save_data; }else{ if( $save_file === true ){ $status = $save_file = __DATA_TMP.md5($save_data); file_put_contents( $save_file , $save_data ); }else{ $status = file_put_contents( $save_file , $save_data ); } } } } $this->_clear(); return $status; } //SMTPLogin用(postfix mynetwork外から)のメール送信関数 function snail($to,$title,$body, $from=null , $pass=null){ //sudo apt-get install heirloom-mailx //SMTP AuthをGlobalIPから使用する為、Loginの必要あり。 //PHPのMail関数では不可能なので、別途設置( //dpkg-reconfigure exim4-configでの設定は、基本他と同じ //etc/hosts内のサーバー名がFQDNの必要あり。DDNSでHost名は対応済み。 //tail -f /var/log/mail.log にてPostfix submissionの確認可能 //Mar 3 23:43:11 durif postfix/submission/smtpd[167860]: disconnect from FNAfx-10p6-178.ppp11.odn.ad.jp[143.90.60.178] //Mar 3 23:43:26 durif postfix/submission/smtpd[167860]: connect from FNAfx-10p6-178.ppp11.odn.ad.jp[143.90.60.178] //Mar 3 23:43:27 durif postfix/submission/smtpd[167860]: Anonymous TLS connection established from fnafx-10p6-178.ppp11.odn.ad.jp[143.90.60.178]: TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits) //Mar 3 23:43:28 durif postfix/submission/smtpd[167860]: 09B53540022A: client=FNAfx-10p6-178.ppp11.odn.ad.jp[143.90.60.178], sasl_method=LOGIN, sasl_username=sysad@vivinavi.com //$from = 'sysad@vivinavi.com'; //$pass = '#Muv5HeSV%l6CGdL'; $smtp_config[] = '-S smtp="smtp.vivinavi.com:587"'; $smtp_config[] = '-S smtp-use-starttls'; $smtp_config[] = '-S smtp-auth=login'; $smtp_config[] = '-S smtp-auth-user="'.$from.'"'; $smtp_config[] = '-S smtp-auth-password='.$pass.''; $smtp_config[] = '-S ssl-verify=ignore '; $cmd = 'echo "'.$body.'" | s-nail -s "'.$title.'" '.implode( ' ' , $smtp_config ).' -r '.$from.' '.$to; exec($cmd); } //Save file function //rename 's/.sent//' /home/vnsh/vnnet/agora/www/beta/var/invoice_mail_file/* function send_saved_mail( $save_file ){ $status = false; if( $save_file && file_exists($save_file) && !preg_match( '|.sent|' , $save_file ) ){ $data = file_get_contents($save_file); $tmp = explode( "\n\n" , $data ); $_commond = explode( "\n" , array_shift($tmp) ); $commond = $_commond[0]; //$commond t= '/usr/sbin/sendmail -f info@vivinavi.com tamura@vivinavi.com'; $type = $_commond[1]; $body = trim(implode( "\n\n" , $tmp )); if( $mp = popen( $commond , 'w' ) ){ fputs($mp, $body ); pclose($mp); $status = true; }else{ trigger_error( "Sendmail Error $save_file \n", E_USER_ERROR); $status = false; } rename( $save_file , $save_file.'.sent' ); } return $status; } //Save file function function save( $save_file , $type=null , $to=null , $title=null , $from=null , $reply=null , $add_header=null , $encode='B' ){ if( $type ){ return $this->{$type}( $to , $title , $from , $reply , $add_header , $encode , $save_file ); }else{ return $this->send( $to , $title , $from , $reply , $add_header , $encode , $save_file ); } return false; } private function send_check_block( $type , $to=null , $title=null , $from=null , $reply=null , $add_header=null , $encode='B' , $save_file=null, $domain=null ){ $model = $this->controller->AddModel( 'global_blocks' ); if( $type ){ $this->send_type = $type; } // Edited by Horie on 2025/11/21 KmhAhJmYFW2VnHUL /*if ( $domain === null ) { $domain = __MAIL_RECEIVED_DOMAIN; }*/ if( !$model->is_blocked( $to , $type , $domain ) ){ return $this->_send( $to , $title , $from , $reply , $add_header , $encode , $save_file ); } //Blockの場合ここでclearしないと前のデータが上書きされる $this->_clear(); return false; } //Global Block対応版メール------------------- function send( $to=null , $title=null , $from=null , $reply=null , $add_header=null , $encode='B' , $save_file=null ){ //$typeなしのGlobalBlockのみ検査 return $this->send_check_block( null , $to , $title , $from , $reply , $add_header , $encode , $save_file ); } function system( $to=null , $title=null , $from=null , $reply=null , $add_header=null , $encode='B' , $save_file=null ){ return $this->send_check_block( 'system' , $to , $title , $from , $reply , $add_header , $encode , $save_file ); } function service( $to=null , $title=null , $from=null , $reply=null , $add_header=null , $encode='B' , $save_file=null ){ return $this->send_check_block( 'service' , $to , $title , $from , $reply , $add_header , $encode , $save_file ); } function news( $to=null , $title=null , $from=null , $reply=null , $add_header=null , $encode='B' , $save_file=null ){ return $this->send_check_block( 'news' , $to , $title , $from , $reply , $add_header , $encode , $save_file ); } function recommend( $to=null , $title=null , $from=null , $reply=null , $add_header=null , $encode='B' , $save_file=null ){ return $this->send_check_block( 'recommend' , $to , $title , $from , $reply , $add_header , $encode , $save_file ); } function mailmaga( $to=null , $title=null , $from=null , $reply=null , $add_header=null , $encode='B' , $save_file=null ){ return $this->send_check_block( 'mailmaga' , $to , $title , $from , $reply , $add_header , $encode , $save_file ); } function no_block( $to=null , $title=null , $from=null , $reply=null , $add_header=null , $encode='B' , $save_file=null ){ return $this->_send( $to , $title , $from , $reply , $add_header , $encode , $save_file ); } //Global Block対応版メール------------------- function clear(){ $this->_clear(); } private function _clear(){ $this->title = ""; $this->body = ""; $this->to = ""; $this->from = ""; $this->reply = ""; $this->text = ""; $this->html = ""; $this->attachment = array(); $this->headers = array(); $this->unsubscribe_key = ""; $this->unsubscribe_url = ""; $this->unsubscribe_onclick = false; $this->send_type = ""; } //K.Suzuki: 2013/06/18 //へッダ文字数が75を超えた場合にアウトルックで文字化けした問題対策。 //PHPではじめからあるmb_encode_mimeheader()はバグがある。 //関数は以下より引用後、\r\nをPHP_EOLに変更した。こうしないと、Outlookで文字化けするので。 /* us2.php.net/manual/ja/function.mb-encode-mimeheader.php*/ private function encode_mimeheader($string, $charset=null) { if (!$charset) { $charset = mb_internal_encoding(); } if (!$string) { return -1; } $start = "=?$charset?B?"; $end = "?="; $encoded = ''; /* Each line must have length <= 75, including $start and $end */ $length = 75 - strlen($start) - strlen($end); /* Average multi-byte ratio */ $ratio = mb_strlen($string, $charset) / strlen($string); /* Base64 has a 4:3 ratio */ $magic = $avglength = floor(3 * $length * $ratio / 4); for ($i=0; $i <= mb_strlen($string, $charset); $i+=$magic) { $magic = $avglength; $offset = 0; /* Recalculate magic for each line to be 100% sure */ do { $magic -= $offset; $chunk = mb_substr($string, $i, $magic, $charset); $chunk = base64_encode($chunk); $offset++; } while (strlen($chunk) > $length); if ($chunk) $encoded .= ' '.$start.$chunk.$end.PHP_EOL; } /* Chomp the first space and the last linefeed */ $encoded = substr($encoded, 1, -strlen(PHP_EOL)); return $encoded; } /** * testigu * 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 test_load_html( $file , $encode="B" , $embedded_image=null){ $data = $this->test_load( $file , $embedded_image); $this->html( $data , $encode); } /** * testigu * VariableをExtractしてFileをInclude * @arg ExtractされるvariablesはCContoller::setm()で設定されたvaliablesのみです。 * @arg URLを指定した場合、VariableをExtractは使用できません * @return {string} title * @see body() */ function test_load( $file, $embedded_image=false ){ 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"]; } if( $data ){ extract( $data , EXTR_SKIP ); } if( !$this->debug ){ ob_start();} if( include( $file ) ){ //ここでメール情報もしあればもロード if( $title ){$this->title = $title; } if( $reply ){ $this->reply = $reply; } if( $from ){ $this->from = $from; } if( $to ){ $this->to = $to; } $ret = ob_get_contents(); } if( !$this->debug ){ ob_end_clean();} } // imgファイル編集 if( $embedded_image ){ // imgタグを抽出 $pattern_img = '//i'; preg_match_all( $pattern_img, $ret , $matchs ); // imgタグのsrcの中身($matchs[1])を解析 if ( is_array( $matchs ) && isset( $matchs[1] ) ) { foreach( $matchs[1] as $img_url ){ $img_url = strtolower(trim($img_url)); // imgファイルをすべてbase64に変換 if( $embedded_image == 'all' ){ $target_url[] = $img_url; $edited_url[] = $this->image_as_base64($img_url); } // 共通のimgファイル(header、footerなど)のみbase64に変換 if( $embedded_image == 'common' ){ // 以下のURLだと共通ファイルとみなす(?) $common_imgs = array( 'https://world.vivinavi.com/', 'https://bizarea.vivinavi.com/' ); foreach($common_imgs as $common_img_url){ $is_cmmmon_file = strpos($img_url, $common_img_url ); if($is_cmmmon_file !== false){ // echo($img_url); $target_url[] = $img_url; $edited_url[] = $this->image_as_base64($img_url); } } } } $new_ret = str_replace( $target_url, $edited_url, $ret ); // echo 'HTML--------------'; // echo $new_ret; // echo 'HTML--------------'; return $new_ret; } } return $ret; } function image_as_base64($file){ $format = ( preg_match("/.png/", $file) ) ? 'png' : 'jpeg'; $data = base64_encode(file_get_contents($file)); return 'data:image/' . $format . ';base64, '.$data; // return 'data:image/jpeg;base64, '.$data; } /** * メールファイルのみ読込 */ function read_mail_file( $file ){ return $this->_load( $file ); } } ?>kakasi_path = $path; } function set_mecab_path( $path ){ $this->mecab_path = $path; } /** * 漢字=半角英数字の間に半角スペースを挿入する * @param string $sour 変換前文字列 * @param string $mode 'space' \x20を挿入する/'HTML'  を挿入する * @return string 変換後文字列 */ function add_space($sour) { $sp=" "; //合致パターン $reg[1] = "([0-9A-Za-z]+)([ぁ-煕]+)"; $reg[2] = "([ぁ-煕]+)([0-9A-Za-z]+)"; //置換パターン $rep[1] = "\\1$sp\\2"; $rep[2] = "\\1$sp\\2"; $dest = $sour; foreach ($reg as $key=>$val) { $dest = mb_ereg_replace($val, $rep[$key], $dest); } return $dest; } /** * 基本的な文字修正 * @param string $sour 変換前文字列 * @param string $mode 'space' \x20を挿入する/'HTML'  を挿入する * @return string 変換後文字列 */ function convert_specialchars($str){ $str = htmlspecialchars ( $str , ENT_QUOTES ); $str = strip_tags($str); // $str = ereg_replace ( "\t" , "" , $str ); $str = preg_replace( '/\t/', '' , $str ); //マジッククオート対応:マジッククオートがOnの場合はこれをする。 // $str = ereg_replace ( "\'" , "'" , $str ); // $str = ereg_replace ( "\"" , """ , $str ); $str = preg_replace ( "/'/" , "'" , $str ); $str = preg_replace ( "/\"/" , """ , $str ); //print($str); //print("-------------------------\n"); // $str = eregi_replace("<", "<", $str ); // $str = eregi_replace(">", ">", $str ); return $str; } /** * mmecab **/ //========================================================================================== function mecab( $str=null , $word_class_arr=array() , $word_only="" ){ if( !trim( $str ) ){ return False; } //取得する品詞があれば、その存在確認 $class_n = count( $word_class_arr ); $str = $this->convert_specialchars ( $str ); $str = mb_convert_encoding( $str , "EUC-JP" , "UTF-8" ); //mecabとkakashiを使用(mecab,kakasi内はECUで処理する->UTFでは文字化けした為) //mecabだけでは、長い名前の会社が来た時に分解できない為 exec( "echo '$str' | ".$this->kakasi_path." -w -ieuc -oeuc" , $tmp ); exec( "echo '".$tmp[0]."' | ".$this->mecab_path." -b 262144" , $rtn ); $n = ( is_array($rtn) && !empty($rtn) ) ? count($rtn) : 0; //$n = count($rtn); $return = array(); for( $i=0 ; $i < $n ; $i++ ){ $tmp = mb_convert_encoding( trim($rtn[$i]) , "UTF-8" , "EUC-JP" ); //品詞チェックの為全て展開 $arr = explode( "\t" , $tmp ); $_arr = explode( "," , $arr[1] ); if( $arr[0] && trim( $arr[0]) != "EOS" && !in_array( trim( $arr[0] ) , $this->stop_word ) ){ //排除する品詞がある場合 if($class_n){ if( in_array( $_arr[0] , $word_class_arr ) ){ //単語のみを返すか、全て返すか $return[] = ( $word_only ) ? trim( $arr[0] ) : trim( $tmp ); } }else{ //全ての分かちを返す場合 //単語のみを返すか、全て返すか $return[] = ( $word_only ) ? trim( $arr[0] ) : trim( $tmp ); } } } return $return; } //分かち分の制作 function wakachi( $str=null , $lang="jpn" , $word_class_arr=array() ){ if( $lang == "jpn" ){ return implode( " " , $this->mecab( $str , $word_class_arr=array() , True )); }else{ //中国語とか return False; } } /** * Ngram with sepelater * Stringはスペース区切りで渡す * return array **/ //========================================================================================== function ngram( $string , $n , $space_char=" " ){ //スペースで埋める為のスペース配列作る //if( !count( $GLOBALS["__ngram_space"] ) ){ if( empty( $GLOBALS["__ngram_space"] ) ){ for( $i=0 ; $i <= $n ; $i++ ){ $GLOBALS["__ngram_space"][0] .= ""; for( $_i=0 ; $_i < $i ; $_i++ ){ $GLOBALS["__ngram_space"][$i] .= $space_char; } } } //Stringを空白で分ける $arr = explode( " " , $string ); $n = ( is_array($arr) && !empty($rtn) ) ? count($rtn) : 0; //$n = count($rtn); $num = count( $arr ); //分かち文をループ for( $i=0 ; $i < $num ; $i++ ){ if( trim( $arr[$i]) ){ //ループ設定(-の数からスタート) $length = mb_strlen($arr[$i], "UTF-8"); $start = 1 - $n; $end = $length; for( $s=$start ; $s < $end ; $s++ ){ //0より小さい場合 if( $s <= 0 ){ $ngram = $GLOBALS["__ngram_space"][ $s * -1 ].mb_substr( $arr[$i] , 0 , $n+$s , "UTF-8" ); }else{ //0より大きい場合 $ngram = mb_substr( $arr[$i] , $s , $n , "UTF-8" ); $tmp = mb_strlen( $ngram , "UTF-8"); //0より大きい且つ、substrのreturnがnより小さい場合。Space入れる if( $tmp < $n ){ $ngram = $ngram . $GLOBALS["__ngram_space"][$n-$tmp]; } } $ngrams[] = $ngram; } } } return $ngrams; } function get_kana( $str=null ){ if( trim( $str ) ){ $str = $this->convert_specialchars ( $str ); $cmd = ( "echo '$str' | ".$this->kakasi_path." -JH -KH -iutf8 -outf8" ); exec($cmd , $tmp); return trim( implode( $tmp ) ); } return False; } function sort_by_lang( $data , $target=null , $use_kana=false ){ if( $data ){ if($target){ foreach( $data as $key => $val ){ if( $val[$target] ){ if($use_kana){ $sort[$key] = $this->get_kana( $val[$target] ); }else{ $sort[$key] = $val[$target]; } }else{ $sort[$key] = ''; } $tmp[$key] = $val; } }else{ foreach( $data as $key => $val ){ if( $this->controller->variables['LANG'][$val] ){ if($use_kana){ $sort[$key] = $this->get_kana( $this->variables['LANG'][$val] ); }else{ $sort[$key] = $this->controller->variables['LANG'][$val]; } }else{ $sort[$key] = $val; } $tmp[$key] = $val; } } natsort($sort); foreach( $sort as $key => $val ){ //Edited by Tamura on 2015/10/31 14:27:23 //$ret[] = $tmp[$key]; $ret[$key] = $tmp[$key]; } return $ret; } return $data; } } ?>