__construct( ); } /* * コンストラクタ. */ function __construct( ) { $this->init( ); } /** * ファンクション名:get_load_lang * 機能概要:ロード言語を取得する * 作成:プライム・ストラテジー株式会社 王 濱 * 作成: * 変更: * @param なし * @return String ロード言語 */ function get_load_lang( ){ return $this->load_lang; } /** * ファンクション名:set_load_lang * 機能概要:ロード言語を設定する * 作成:プライム・ストラテジー株式会社 王 濱 * 作成: * 変更: * @param String ロード言語 * @return なし */ function set_load_lang( $lang ){ if ( $this->multilingual_code[$lang] ): $this->load_lang = $lang; else: $this->load_lang = $this->WPLANGKEY; endif; } /* * initializing */ function init( ){ if( !defined('DOCUMENTROOT') ): define( 'DOCUMENTROOT' , $_SERVER['DOCUMENT_ROOT'] ); endif; if( !defined('HOMEDIR') ): define( 'HOMEDIR' , dirname($_SERVER['DOCUMENT_ROOT']) ); endif; if( !defined('DS') ): define( 'DS', DIRECTORY_SEPARATOR ); endif; define( 'CONFIG_DIR' , '/config' ); define( 'MULTI_LANGUAGES_DIR' , dirname(__FILE__) ); define( 'WPCONTENT_M17N_CONFIG_DIR' , WP_CONTENT_DIR . '/012-m17n-config' ); if ( !$this->ps_012_m17n_include_once_or_notices( )): return; endif; if ( !$this->multilingual || !is_array( $this->multilingual ) ){ add_action('admin_notices', array(&$this,'admin_notices_multilingual')); return; } $this->init_mulit_languages( ); $this->Start( ); } /** * ファンクション名:Start * 機能概要:プラグインの機能実行をスタート * 作成:プライム・ストラテジー株式会社 王 濱 * 作成: * 変更: * @param なし * @return なし */ function Start( ){ if ( is_admin( ) ): //管理画面カスタマイズ add_action( 'admin_init' , array( &$this , 'admin_multilingual_edit' ) ); //タクソノミークラス、投稿編集クラス、一般設定クラスの読み込み add_action( 'admin_init' , array( &$this , 'admin_multilingual_includes' ) ); //サイトのタイトルとキャッチフレーズを多国語対応 add_action( 'admin_init' , array( &$this, 'regist_contact_info_field' ) ); add_filter( 'whitelist_options' , array( &$this, 'add_contact_info_field' ) ); //JSとCSSを読み込みします。 //add_action( 'admin_footer-post.php' , array( &$this, 'add_admin_print_styles' ) ); add_action( 'admin_print_styles-edit-tags.php' , array( &$this, 'add_admin_print_styles' ) ); else: add_filter('pre_get_posts' , array( &$this , 'ps_multilingual_pre_get_posts' ) ); //add_action( 'init' , array( &$this, 'ps_init_multilingua' ) ); //カテゴリー、タグ、タクソノミー add_filter( 'get_terms' , array( &$this, 'ps_multilingual_get_terms') , 10 , 3); add_filter( 'get_the_terms' , array( &$this, 'ps_multilingual_get_the_terms') , 10 , 3); add_filter( 'get_term' , array( &$this, 'ps_multilingual_get_term') , 10 , 2); //言語コード add_filter('language_attributes' , array( &$this, 'ps_language_attributes_multilingual') ); //サイト名と add_filter('bloginfo' , array( &$this, 'ps_bloginfo_multilingual') , 10 , 2); /***********/ add_filter('blog_details' , array( &$this, 'ps_blog_details_multilingual') , 10); // add_filter('locale' , array( &$this, 'ps_locale_multilingual') ); add_filter('wp_list_pages' , array( &$this, 'ps_wp_list_page_multilingual') ); add_filter('wp_nav_menu' , array( &$this, 'ps_wp_nav_menu_multilingual') , 10 , 2); add_filter('wp_page_menu' , array( &$this, 'ps_wp_nav_menu_multilingual') , 10 , 2); //add_filter('language_attributes' , array(&$this,'reset_language_attributes') ); add_filter('wp_title' , array( &$this, 'ps_wp_title_multilingual' ) , 10 , 2); add_filter('single_post_title' , array( &$this, 'ps_single_post_title_multilingual'),10 , 2); add_filter('the_posts' , array( &$this, 'ps_012_m17n_the_posts') , 10 , 2); //検索対応 add_filter('pre_get_posts' , array( &$this , 'ps_012_m17n_search' ) ); //admin bar's blogname add_filter('option_blogname' , array( &$this , 'ps_blogname_multilingual' ) ); endif; $this->init_view_mulit_lang( ); } /** * ファンクション名:ps_012_m17n_include_once_or_notices * 機能概要: check confing file and include * 作成:プライム・ストラテジー株式会社 王 濱 * 変更: * @param なし * @return なし */ function ps_012_m17n_include_once_or_notices( ){ if ( is_multisite( ) ): global $blog_id; if (file_exists( WPCONTENT_M17N_CONFIG_DIR . CONFIG_DIR . DS .'config-'.$blog_id.'.php' ) ): include_once ( WPCONTENT_M17N_CONFIG_DIR . CONFIG_DIR . DS .'config-'.$blog_id.'.php' ); return true; endif; if ( file_exists( WPCONTENT_M17N_CONFIG_DIR . CONFIG_DIR . DS .'config.php')): include_once ( WPCONTENT_M17N_CONFIG_DIR . CONFIG_DIR . DS .'config.php' ); return true; endif; if (file_exists( MULTI_LANGUAGES_DIR . CONFIG_DIR . DS .'config-'.$blog_id.'.php' ) ): include_once ( MULTI_LANGUAGES_DIR . CONFIG_DIR . DS .'config-'.$blog_id.'.php' ); return true; endif; if ( file_exists( MULTI_LANGUAGES_DIR . CONFIG_DIR . DS .'config.php')): include_once ( MULTI_LANGUAGES_DIR . CONFIG_DIR . DS .'config.php'); return true; endif; else: if( file_exists( WPCONTENT_M17N_CONFIG_DIR . CONFIG_DIR . DS .'config.php') ): include_once ( WPCONTENT_M17N_CONFIG_DIR . CONFIG_DIR . DS .'config.php' ); return true; endif; if( file_exists( MULTI_LANGUAGES_DIR . CONFIG_DIR . DS .'config.php') ): include_once ( MULTI_LANGUAGES_DIR . CONFIG_DIR . DS .'config.php'); return true; endif; endif; add_action('admin_notices', array(&$this,'custom_taxonomy_admin_notices')); return false; } /** * ファンクション名:init_mulit_languages * 機能概要:デフォルトのロード言語を設定する() * 作成:プライム・ストラテジー株式会社 王 濱 * 変更: * @param なし * @return なし */ function init_mulit_languages( ){ if( defined('MULTILINGUAL_WPLANG') ): $this->WPLANGKEY = MULTILINGUAL_WPLANG; //$this->WPLANGKEY = WPLANG ; elseif( defined('WPLANG') ): $this->WPLANGKEY = WPLANG; else: $WPLANG = get_option('WPLANG' , true); if( $WPLANG ): $this->WPLANGKEY = $WPLANG ; else: $this->WPLANGKEY = 'en' ; endif; endif; $this->WPLANGKEY = strtolower( substr( $this->WPLANGKEY, 0, 2 ) ); unset( $this->multilingual[$this->WPLANGKEY] ); } /** * ファンクション名:admin_multilingual_includes * 機能概要:管理画面の多国語化タクソノミーとポスト * 作成:プライム・ストラテジー株式会社 王 濱 * 変更: * @param resource * @param int * @param string * @return */ function admin_multilingual_includes( ){ //新規編集する場合、多国語化 include_once ( MULTI_LANGUAGES_DIR . '/includes/ps-multilingual-edit-post.php'); //タクソノミー管理画面の多国語化 include_once ( MULTI_LANGUAGES_DIR . '/includes/ps-multilingual-taxonomy.php'); } /** * ファンクション名:init_view_mulit_lang * 機能概要:フォロートの表示ロード言語 * 作成:プライム・ストラテジー株式会社 王 濱 * 変更: * @param resource * @param int * @param string * @return */ function init_view_mulit_lang( ){ if ( $_GET['lang'] ): $this->set_load_lang( $_GET['lang'] ); setcookie( '_ps_enqueue_language', $this->get_load_lang() , time() + 31536000 , "/"); elseif( $_COOKIE['_ps_enqueue_language'] ): $this->set_load_lang( $_COOKIE['_ps_enqueue_language'] ); else: #------------------------------------------------------------------------------------------------- $UserLanguage = explode( ',', $_SERVER['HTTP_ACCEPT_LANGUAGE'] ); #ユーザー言語の取得 #------------------------------------------------------------------------------------------------- $language = array_shift($UserLanguage); $language = $language ? substr( $language, 0, 2 ) : $language ; $this->set_load_lang( $language ); setcookie( '_ps_enqueue_language', $this->get_load_lang() , time() + 31536000 , "/"); endif; } function ps_init_multilingua( ){ } /** * ファンクション名: * 機能概要: * 作成:プライム・ストラテジー株式会社 王 濱 * 作成: * 変更: * @param resource * @param int * @param string * @return */ function add_admin_print_styles( ){ wp_enqueue_script( 'prefix-js-' . strtolower(__CLASS__) , plugins_url('js/prefix-js.js', __FILE__) ); wp_register_style( 'prefix-style-'. strtolower(__CLASS__) , plugins_url('css/prefix-style.css', __FILE__) ); wp_enqueue_style( 'prefix-style-' . strtolower(__CLASS__) ); } /** * ファンクション名: * 機能概要: * 作成:プライム・ストラテジー株式会社 王 濱 * 作成: * 変更: * @param resource * @param int * @param string * @return */ function ps_locale_multilingual( $locale ){ $multilingual = $this->get_load_lang(); $multilingual_locale = $this->multilingual_code[$multilingual]; return $multilingual_locale ? $multilingual_locale : 'en_US'; } /** * ファンクション名: * 機能概要: * 作成:プライム・ストラテジー株式会社 王 濱 * 作成: * 変更: * @param resource * @param int * @param string * @return */ function ps_bloginfo_multilingual( $show = '', $filter = '' ){ $multilingual = $this->get_load_lang( ); if ( $multilingual == $this->WPLANGKEY && $filter != 'keyword' ){ return $show; } if ( $filter == 'name' || $filter == 'blogname'): $show = $this->get_multilingual_option( $multilingual , 'blogname' ); elseif ( $filter == 'description' || $filter == 'blogdescription' ): $show = $this->get_multilingual_option( $multilingual , 'blogdescription' ); elseif ( $filter == 'keyword' ): $show = $this->get_multilingual_option( $multilingual , $filter ); endif; return $show; } /** * ファンクション名: ps_blogname_multilingual * 機能概要:ログイン状態よりフォロートのadmin barのサイト名を表示する * 作成:プライム・ストラテジー株式会社 王 濱 * 作成: * 変更: * @param resource * @param int * @param string * @return */ function ps_blogname_multilingual( $blogname ){ $multilingual = $this->get_load_lang( ); if ( $multilingual == $this->WPLANGKEY ){ return $blogname; }else{ if ( $multilingual ){ $ml_blogname = get_option( 'blogname_' . $multilingual ); } if ( $ml_blogname ){ return $ml_blogname; }else{ $multilingual; } } } /** * ファンクション名:ps_blog_details_multilingual * 機能概要:子サイトのサイト名を該当言語にする * 作成:プライム・ストラテジー株式会社 王 濱 * 作成: * 変更: * @param Object $details * @param Object $details * @return */ function ps_blog_details_multilingual( $details ){ $multilingual = $this->get_load_lang( ); if ( $multilingual == $this->WPLANGKEY ){ return $details; } if ( is_multisite( ) ): global $blog_id; $blogname = $this->get_multilingual_option( $multilingual , 'blogname' ); if ( $blogname && $blog_id == $details->blog_id ) { $details->blogname = $blogname; } endif; return $details; } /** * ファンクション名: * 機能概要: * 作成:プライム・ストラテジー株式会社 王 濱 * 作成: * 変更: * @param resource * @param int * @param string * @return */ function get_multilingual_option( $lang, $key ){ if ( $key ){ $option = get_option( $key . '_' . $lang ); } if ( $option ){ return $option; } return get_option( $key ); } /** * ファンクション名:ps_language_attributes_multilingual * 機能概要:の設定 * 作成:プライム・ストラテジー株式会社 王 濱 * 変更: * @param resource * @param int * @param string * @return */ function ps_language_attributes_multilingual( $output = null ){ $attributes = array(); $doctype = 'html'; if ( preg_match('|xml|' , $output)){ $doctype = 'xhtml'; } if ( $this->get_load_lang() == $this->WPLANGKEY ){ return $output; } if ( function_exists( 'is_rtl' ) ) $attributes[] = 'dir="' . ( is_rtl() ? 'rtl' : 'ltr' ) . '"'; $lang = get_bloginfo('language'); if ( $lang_code ): $lang = str_replace('_', '-', $lang_code); endif; if ( $lang ) : if ( get_option('html_type') == 'text/html' || $doctype == 'html' ) $attributes[] = "lang=\"$lang\""; if ( get_option('html_type') != 'text/html' || $doctype == 'xhtml' ) $attributes[] = "xml:lang=\"$lang\""; endif; $output = implode(' ', $attributes); $output = apply_filters('regist_language_attributes', $output); echo $output; } /** * ファンクション名: * 機能概要: * 作成:プライム・ストラテジー株式会社 王 濱 * 変更: * @param resource * @param int * @param string * @return */ function get_multilingual_code( $lang ){ if ( $lang ): $lang_code = $this->multilingual_code[$lang]; $lang_code = str_replace('_', '-', $lang_code); else: $lang_code = $this->multilingual_code[$this->WPLANGKEY]; $lang_code = str_replace('_', '-', $lang_code); endif; return $lang_code; } /** * ファンクション名:ps_012_m17n_the_posts * 機能概要: 投稿、ページ、カスタム投稿タイプのタイトルと内容を該当言語にする * 作成:プライム・ストラテジー株式会社 王 濱 * 変更: * @param Object $posts * @param Object $query_this * @return Object $posts */ function ps_012_m17n_the_posts( $posts , $query_this){ if ( $this->get_load_lang() == $this->WPLANGKEY ){ return $posts; } if ( !$posts ){ return $posts; } foreach ( $posts as $key => $post){ $multilingual_Name = get_post_meta( $post->ID, 'post_content_' . $this->load_lang , true); if ( $multilingual_Name ): $post->post_content = $multilingual_Name; endif; $multilingual_title = get_post_meta( $post->ID, 'post_title_' . $this->load_lang , true); if ( $multilingual_title ): $post->post_title = $multilingual_title; endif; $post->post_content = preg_replace('|
>
|' , '' , $post->post_content ); $post->post_content = preg_replace('|>|' , '' , $post->post_content ); } return $posts; } /** * ファンクション名:ps_single_post_title_multilingual * 機能概要: 投稿、ページ、カスタム投稿タイプのタイトルを該当言語にする * 作成:プライム・ストラテジー株式会社 王 濱 * 変更: * @param String $title * @param Object $_post * @return String $title */ function ps_single_post_title_multilingual( $title , $_post ){ if ( is_single() || ( is_home() && !is_front_page() ) || ( is_page() && !is_front_page() ) ) { $multilingual_title = get_post_meta( $_post->ID, 'post_title_' . $this->load_lang , true); if ( $multilingual_title ): $title = $multilingual_title; endif; } return $title; } /** * ファンクション名:ps_012_m17n_search * 機能概要:多国化の検索対応 * 作成:プライム・ストラテジー株式会社 王 濱 * 変更: * @param Array $pre * @return Array $pre */ function ps_012_m17n_search( $pre ){ global $blog_id, $wpdb; if ( !is_search() ){ return $pre; } if ( $this->get_load_lang() == $this->WPLANGKEY ){ return $pre; } $lang = $this->get_load_lang(); if ( $lang && get_search_query() ){ $meta_query = array( array( 'key' => 'post_title_' . $lang, 'value' => $pre->query_vars['s'], 'compare' => 'LIKE' ), array( 'key' => 'post_content_' . $lang, 'value' => $pre->query_vars['s'], 'compare' => 'LIKE' ), 'relation'=>'OR' ); $teest = $pre->query_vars['s']; $pre->query_vars['s'] = ""; $pre->query_vars['meta_query'] = $meta_query; //add_filter('posts_where', array( &$this , 'ps_search_where' )); } return $pre; } /** * ファンクション名:ps_wp_title_multi_lang * 機能概要:多国語のタイトルを表示する * 作成:プライム・ストラテジー株式会社 王 濱 * 作成: * 変更: * @param String $title(デフォルト語のタイトル) * @return String $title(多国語タイトル) */ function ps_wp_title_multilingual( $title, $mark = '' ){ if ( $this->get_load_lang() == $this->WPLANGKEY ){ return $title; } if ( is_search() ): $lang = $this->get_load_lang(); $searchResults = $this->search_multilingual_title[$lang]; if ( $searchResults ){ $preg_quote = preg_quote($mark,'|'); $title = preg_replace('|' . $preg_quote .'(.*)'. $preg_quote .'|', $mark . ' ' . $searchResults . ' ' . $mark , $title); } if ( $_GET['s'] ): return $_GET['s'] . $title; elseif ( $_POST['s'] ): return $_POST['s'] . $title; endif; endif; return $title; } /** * ファンクション名:ps_wp_nav_menu_multilingual * 機能概要:wp_nav_menuの表示タイトルを該当言語にする * 作成:プライム・ストラテジー株式会社 王 濱 * 変更: * @param Array $nav_menu * @param Array $args * @return Array 全$nav_menu */ function ps_wp_nav_menu_multilingual( $nav_menu, $args ) { if ( $this->get_load_lang() == $this->WPLANGKEY ){ return $nav_menu; } $aliases = $this->get_multilingual_title( ); if ( $aliases ): foreach ( $aliases as $alias ): $nav_menu = preg_replace( '/>' . preg_quote( trim($alias['post_title']), '/' ) . '', '>' . $alias['meta_value'] . '<', $nav_menu ); endforeach; endif; return $nav_menu; } /** * ファンクション名:ps_wp_list_page_multilingual * 機能概要:wp_list_pageの表示タイトルを該当言語にする * 作成:プライム・ストラテジー株式会社 王 濱 * 変更: * @param Array $global_navi * @return Array 全$global_navi */ function ps_wp_list_page_multilingual( $global_navi ){ if ( $this->get_load_lang() == $this->WPLANGKEY ){ return $global_navi; } $aliases = $this->get_multilingual_title( ); if ( $aliases ): foreach( $aliases as $alias): $global_navi = preg_replace( '/>' . preg_quote( trim($alias['post_title']), '/' ) . '', '>' . $alias['meta_value'] . '<', $global_navi ); endforeach; endif; return $global_navi; } /** * ファンクション名:get_multilingual_title * 機能概要:全カスタムフィールドを取得 * 作成:プライム・ストラテジー株式会社 王 濱 * 変更: * @param String post_id * @return Array 全カスタムフィールド */ function get_multilingual_title( ){ global $wpdb; $sql =" SELECT a.`post_title`, b.`meta_value` FROM `$wpdb->posts` as a, `$wpdb->postmeta` as b WHERE a.`ID` = b.`post_id` AND b.`meta_key` = 'post_title_{$this->get_load_lang()}'"; if ( $this->get_load_lang() != $this->WPLANGKEY ): $aliases = $wpdb->get_results( $sql, 'ARRAY_A' ); endif; return $aliases; } /** * ファンクション名:get_ps_post_customs * 機能概要:全カスタムフィールドを取得 * 作成:プライム・ストラテジー株式会社 王 濱 * 変更: * @param String post_id * @return Array 全カスタムフィールド */ function get_ps_post_customs( $post_id ){ $custom_fields = get_post_custom($post_id); $return = array(); foreach( $custom_fields as $key => $field ){ if ( count( $field ) > 1 ){ foreach ( $field as $key2 => $val ){ $return[$key][$key2] = $val; } }else{ if ( preg_match('/^_(.*)/' , $key )){ $return[$key] = maybe_unserialize($field[0]) ; }else{ $return[$key] = $field[0]; } } } return $return; } /** * ファンクション名: * 機能概要: * 作成:プライム・ストラテジー株式会社 王 濱 * 変更: * @param resource * @param int * @param string * @return */ function ps_multilingual_get_terms ( $terms, $taxonomies, $args ){ $lang = $this->get_load_lang( ); $current_option = get_option( $taxonomies[0] . '-' . $lang ); foreach ( $terms as $key => $term ): if ( $this->WPLANGKEY != $lang ): $multilingual_Name = $current_option[$term->term_id]; if ( $multilingual_Name ): $terms[$key]->name = is_array($multilingual_Name) ? join(',', $multilingual_Name) : $multilingual_Name ; endif; endif; endforeach; return $terms; } /** * ファンクション名: * 機能概要: * 作成:プライム・ストラテジー株式会社 王 濱 * 変更: * @param resource * @param int * @param string * @return */ function ps_multilingual_get_the_terms( $terms, $id, $taxonomy ){ $lang = $this->get_load_lang( ); $current_option = get_option( $taxonomy . '-' . $lang ); foreach ( $terms as $key => $term ): if ( $this->WPLANGKEY != $lang ): $multilingual_Name = $current_option[$term->term_id]; if ( $multilingual_Name ): $terms[$key]->name = is_array($multilingual_Name) ? join(',', $multilingual_Name) : $multilingual_Name ; endif; endif; endforeach; return $terms; } /** * ファンクション名: * 機能概要: * 作成:プライム・ストラテジー株式会社 王 濱 * 変更: * @param resource * @param int * @param string * @return */ function ps_multilingual_get_term( $term, $taxonomy ){ $lang = $this->get_load_lang( ); $current_option = get_option( $taxonomy . '-' . $lang ); $multilingual_Name = $current_option[$term->term_id]; if ( $this->WPLANGKEY != $lang ): if ( $multilingual_Name ): $term->name = is_array($multilingual_Name) ? join(',', $multilingual_Name) : $multilingual_Name ; endif; endif; return $term; } /** * ファンクション名: * 機能概要: * 作成:プライム・ストラテジー株式会社 王 濱 * 変更: * @param resource * @param int * @param string * @return */ function regist_contact_info_field() { $flag_icon = $this->flags_dir . $this->WPLANGKEY . '.png'; if ( ps_url_exists( $flag_icon )): $flag_icon = 'プラグイン012 PS Multi Languages :設定ファイル_config.phpの名前をconfig.php OR config-{$blog_id}.phpに変更し、configファイルの設定を行ってください。
プラグイン012 PS Multi Languages:設定ファイルconfig.php OR config-{$blog_id}.phpの多国語設定配列($multilingual)の設定を行ってください。