View difference between Paste ID: ubSMTws9 and 6SxMfCwy
SHOW: | | - or go back to the newest paste.
1
<?php
2
/*
3
Plugin Name: 012 PS Multi Languages
4
Plugin URI: http://wordpress.org/extend/plugins/012-ps-multi-languages/
5
Description: Manager Multilingual Wordpress for one URL 
6
Author: Wang Bin (oh@prime-strategy.co.jp)
7
Version: 1.2
8
Author URI: http://www.prime-strategy.co.jp/about/staff/oh/
9
*/
10
11
/**
12
 * ps_multi_languages
13
 *
14
 * Main Manager Custom Plugin Class
15
 *
16
 * @package ps_multi_languages
17
 */
18
class ps_multi_languages{
19
	/*
20
	 *マルチ言語
21
	 */
22
	var $multilingual;
23
	
24
	/*
25
	 * マルチ言語コード
26
	 */
27
	var $multilingual_code;
28
	
29
	/*
30
	 * 検索の表示タイトル
31
	 */
32
	var $search_multilingual_title;
33
	
34
	/*
35
	 * タクソノミーの頭文字
36
	 */
37
	var $prefix_taxonomy;
38
	
39
	/*
40
	 * バックエンドの言語(システムの言語)
41
	 */
42
	var $WPLANGKEY;
43
	
44
	/*
45
	 * デフォルトの言語
46
	 */
47
	private  $load_lang = 'en';
48
49
	/*
50
	*	Start Manager Custom  on plugins loaded
51
	*/
52
	function ps_multi_languages( ){
53
		$this->__construct( );
54
	}
55
56
	/*
57
	 * コンストラクタ.
58
	 */
59
	function __construct( ) {
60
		$this->init( );
61
			
62
	}
63
64
	/**
65
	* ファンクション名:get_load_lang
66
	* 機能概要:ロード言語を取得する
67
	* 作成:プライム・ストラテジー株式会社 王 濱
68
	* 作成:
69
	* 変更:
70
	* @param なし
71
	* @return String ロード言語
72
	*/
73
	function get_load_lang( ){
74
		return $this->load_lang;
75
	}
76
	
77
	/**
78
	* ファンクション名:set_load_lang
79
	* 機能概要:ロード言語を設定する
80
	* 作成:プライム・ストラテジー株式会社 王 濱
81
	* 作成:
82
	* 変更:
83
	* @param String ロード言語
84
	* @return なし
85
	*/
86
	function set_load_lang( $lang ){
87
		
88
		if ( $this->multilingual_code[$lang] ):
89
			$this->load_lang = $lang;
90
		else:
91
			$this->load_lang = $this->WPLANGKEY;
92
		endif;
93
94
	}
95
96
	/*
97
	 * initializing
98
	 */
99
	function init( ){
100
101
		if( !defined('DOCUMENTROOT') ):
102
			define( 'DOCUMENTROOT' , $_SERVER['DOCUMENT_ROOT'] );
103
		endif;
104
105
		if( !defined('HOMEDIR') ):
106
			define( 'HOMEDIR' , dirname($_SERVER['DOCUMENT_ROOT']) );
107
		endif;
108
		
109
		if( !defined('DS') ):
110
			define( 'DS', DIRECTORY_SEPARATOR );
111
		endif;
112
113
		define( 'CONFIG_DIR' , '/config' );
114
		
115
	    define( 'MULTI_LANGUAGES_DIR' , dirname(__FILE__) );
116
117
	    define( 'WPCONTENT_M17N_CONFIG_DIR' , WP_CONTENT_DIR . '/012-m17n-config' );
118
119
		if ( !$this->ps_012_m17n_include_once_or_notices( )):
120
	    	return;
121
	    endif;    
122
	    
123
		if ( !$this->multilingual || !is_array( $this->multilingual ) ){
124
			add_action('admin_notices', array(&$this,'admin_notices_multilingual'));
125
			return;	
126
		}
127
			    
128
	    $this->init_mulit_languages( );
129
	    
130
		$this->Start( );
131
		
132
	}	
133
	
134
	/**
135
	* ファンクション名:Start
136
	* 機能概要:プラグインの機能実行をスタート 
137
	* 作成:プライム・ストラテジー株式会社 王 濱
138
	* 作成:
139
	* 変更:
140
	* @param なし
141
	* @return なし
142
	*/
143
	function Start( ){
144
	
145
		if ( is_admin( ) ):
146
			//管理画面カスタマイズ
147
			add_action( 'admin_init'									, array( &$this , 'admin_multilingual_edit' ) 				);
148
			//タクソノミークラス、投稿編集クラス、一般設定クラスの読み込み
149
			add_action( 'admin_init'									, array( &$this , 'admin_multilingual_includes' ) 			);
150
			//サイトのタイトルとキャッチフレーズを多国語対応
151
			add_action( 'admin_init'									, array( &$this, 'regist_contact_info_field' ) 				);
152
			add_filter( 'whitelist_options'								, array( &$this, 'add_contact_info_field' ) 				);
153
			//JSとCSSを読み込みします。
154
			//add_action( 'admin_footer-post.php'							, array( &$this, 'add_admin_print_styles' ) );
155
			add_action( 'admin_print_styles-edit-tags.php'				, array( &$this, 'add_admin_print_styles' ) 				);			
156
		else:
157
			//add_action( 'init'											, array( &$this, 'ps_init_multilingua' ) 				);
158
			//カテゴリー、タグ、タクソノミー
159
			add_filter( 'get_terms' 									, array( &$this, 'ps_multilingual_get_terms') 		, 10 , 3);
160
			add_filter( 'get_the_terms' 								, array( &$this, 'ps_multilingual_get_the_terms') 	, 10 , 3);
161
			add_filter( 'get_term' 										, array( &$this, 'ps_multilingual_get_term') 		, 10 , 2);
162
			
163
			//言語コード
164
			add_filter('language_attributes'							, array( &$this, 'ps_language_attributes_multilingual')		);
165
			//サイト名と
166
			add_filter('bloginfo'										, array( &$this, 'ps_bloginfo_multilingual') 		, 10 , 2);
167
			/***********/
168
			add_filter('blog_details'									, array( &$this, 'ps_blog_details_multilingual') 		, 10);
169
			
170
			//
171
			add_filter('locale'											, array( &$this, 'ps_locale_multilingual') 					);
172
173
			add_filter('wp_list_pages'									, array( &$this, 'ps_wp_list_page_multilingual') 			);
174
			add_filter('wp_nav_menu'									, array( &$this, 'ps_wp_nav_menu_multilingual') 	, 10 , 2);
175
			add_filter('wp_page_menu'									, array( &$this, 'ps_wp_nav_menu_multilingual') 	, 10 , 2);
176
			//add_filter('language_attributes'							, array(&$this,'reset_language_attributes') );
177
			
178
			add_filter('wp_title' 										, array( &$this, 'ps_wp_title_multilingual' ) 		, 10 , 2);
179
			add_filter('single_post_title' 								, array( &$this, 'ps_single_post_title_multilingual'),10 , 2);
180
			add_action('the_posts'										, array( &$this, 'ps_012_m17n_the_posts')			, 10 , 2);
181
			
182
			//検索対応
183
			add_filter('pre_get_posts'									, array( &$this , 'ps_012_m17n_search' ) 					);
184
			
185
			
186
		endif;
187
		
188
		$this->init_view_mulit_lang( );		
189
	}
190
191
	/**
192
	* ファンクション名:ps_012_m17n_include_once_or_notices
193
	* 機能概要: check confing file and include
194
	* 作成:プライム・ストラテジー株式会社 王 濱
195
	* 変更:
196
	* @param なし
197
	* @return なし
198
	*/
199
	function  ps_012_m17n_include_once_or_notices( ){
200
		if ( is_multisite( ) ):
201
			global $blog_id;
202
			if (file_exists( WPCONTENT_M17N_CONFIG_DIR . CONFIG_DIR . DS .'config-'.$blog_id.'.php' ) ):
203
				include_once ( WPCONTENT_M17N_CONFIG_DIR . CONFIG_DIR . DS .'config-'.$blog_id.'.php' );
204
				return true;
205
			endif;
206
			if ( file_exists( WPCONTENT_M17N_CONFIG_DIR . CONFIG_DIR . DS .'config.php')):
207
				include_once ( WPCONTENT_M17N_CONFIG_DIR . CONFIG_DIR . DS .'config.php' );
208
	    		return true;
209
			endif;
210
			if (file_exists( MULTI_LANGUAGES_DIR . CONFIG_DIR . DS .'config-'.$blog_id.'.php' ) ):
211
	    		include_once ( MULTI_LANGUAGES_DIR . CONFIG_DIR . DS .'config-'.$blog_id.'.php' );
212
				return true;
213
			endif;
214
			if ( file_exists( MULTI_LANGUAGES_DIR . CONFIG_DIR . DS .'config.php')):
215
	    		include_once ( MULTI_LANGUAGES_DIR . CONFIG_DIR . DS .'config.php');
216
	    		return true;
217
			endif;
218
		else:
219
			if( file_exists( WPCONTENT_M17N_CONFIG_DIR . CONFIG_DIR . DS .'config.php') ):
220
	    		include_once ( WPCONTENT_M17N_CONFIG_DIR . CONFIG_DIR . DS .'config.php' );
221
	    		return true;
222
			endif;
223
			if( file_exists( MULTI_LANGUAGES_DIR . CONFIG_DIR . DS .'config.php') ):
224
	    		include_once ( MULTI_LANGUAGES_DIR . CONFIG_DIR . DS .'config.php');
225
	    		return true;
226
			endif;
227
228
	    endif;
229
	    
230
	    add_action('admin_notices', array(&$this,'custom_taxonomy_admin_notices'));
231
	    return false;
232
	}
233
	/**
234
	* ファンクション名:init_mulit_languages
235
	* 機能概要:デフォルトのロード言語を設定する()
236
	* 作成:プライム・ストラテジー株式会社 王 濱
237
	* 変更:
238
	* @param なし
239
	* @return なし
240
	*/
241
	function init_mulit_languages( ){
242
243
		if( defined('MULTILINGUAL_WPLANG') ):
244
			$this->WPLANGKEY = MULTILINGUAL_WPLANG;
245
			//$this->WPLANGKEY = WPLANG ;
246
		elseif( defined('WPLANG') ):
247
			$this->WPLANGKEY = WPLANG;
248
		else:
249
			$WPLANG = get_option('WPLANG' , true);
250
			if( $WPLANG ):
251
				$this->WPLANGKEY = $WPLANG ;
252
			else:
253
				$this->WPLANGKEY = 'en' ;
254
			endif;
255
		endif;
256
		
257
		$this->WPLANGKEY = strtolower( substr( $this->WPLANGKEY, 0, 2 ) );
258
		unset( $this->multilingual[$this->WPLANGKEY] );
259
260
	}
261
		
262
	/**
263
	* ファンクション名:admin_multilingual_includes
264
	* 機能概要:管理画面の多国語化タクソノミーとポスト
265
	* 作成:プライム・ストラテジー株式会社 王 濱
266
	* 変更:
267
	* @param resource
268
	* @param int
269
	* @param string
270
	* @return
271
	*/
272
	function admin_multilingual_includes( ){
273
	    //新規編集する場合、多国語化
274
	    include_once ( MULTI_LANGUAGES_DIR . '/includes/ps-multilingual-edit-post.php');
275
		
276
		//タクソノミー管理画面の多国語化
277
	    include_once ( MULTI_LANGUAGES_DIR . '/includes/ps-multilingual-taxonomy.php');
278
279
	}
280
	
281
	/**
282
	* ファンクション名:init_view_mulit_lang
283
	* 機能概要:フォロートの表示ロード言語
284
	* 作成:プライム・ストラテジー株式会社 王 濱
285
	* 変更:
286
	* @param resource
287
	* @param int
288
	* @param string
289
	* @return
290
	*/
291
	function init_view_mulit_lang( ){
292
		
293
		if ( $_GET['lang'] ):
294
		
295
			$this->set_load_lang( $_GET['lang'] );
296
			
297
			setcookie( '_ps_enqueue_language', $this->get_load_lang() , time() + 31536000 , "/");
298
299
		elseif( $_COOKIE['_ps_enqueue_language'] ):
300
			
301
			$this->set_load_lang( $_COOKIE['_ps_enqueue_language'] );
302
			
303
		else:
304
		
305
			#-------------------------------------------------------------------------------------------------
306
			$UserLanguage = explode( ',', $_SERVER['HTTP_ACCEPT_LANGUAGE'] ); #ユーザー言語の取得
307
			#-------------------------------------------------------------------------------------------------
308
	
309
			$language = array_shift($UserLanguage);
310
	
311
			$language = $language ? substr( $language, 0, 2 ) : $language ;
312
313
			$this->set_load_lang( $language );
314
			
315
			setcookie( '_ps_enqueue_language', $this->get_load_lang() , time() + 31536000 , "/");
316
			
317
		endif;
318
		
319
	}
320
	
321
	function ps_init_multilingua( ){
322
323
	}
324
	
325
	/**
326
	* ファンクション名:
327
	* 機能概要:
328
	* 作成:プライム・ストラテジー株式会社 王 濱
329
	* 作成:
330
	* 変更:
331
	* @param resource
332
	* @param int
333
	* @param string
334
	* @return
335
	*/
336
	function add_admin_print_styles( ){
337
338
		wp_enqueue_script( 'prefix-js-' . strtolower(__CLASS__) , plugins_url('js/prefix-js.js', __FILE__) );
339
340
		wp_register_style( 'prefix-style-'. strtolower(__CLASS__) , plugins_url('css/prefix-style.css', __FILE__) );
341
		
342
		wp_enqueue_style( 'prefix-style-' . strtolower(__CLASS__) );
343
	}
344
	
345
	/**
346
	* ファンクション名:
347
	* 機能概要:
348
	* 作成:プライム・ストラテジー株式会社 王 濱
349
	* 作成:
350
	* 変更:
351
	* @param resource
352
	* @param int
353
	* @param string
354
	* @return
355
	*/
356
	function ps_locale_multilingual( $locale ){
357
		
358
		$multilingual = $this->get_load_lang();
359
		
360
		$multilingual_locale = $this->multilingual_code[$multilingual];
361
		
362
		return $multilingual_locale ? $multilingual_locale : 'en_US';
363
	
364
	}
365
	
366
	/**
367
	* ファンクション名:
368
	* 機能概要:
369
	* 作成:プライム・ストラテジー株式会社 王 濱
370
	* 作成:
371
	* 変更:
372
	* @param resource
373
	* @param int
374
	* @param string
375
	* @return
376
	*/	
377
	function ps_bloginfo_multilingual( $show = '', $filter = '' ){
378
		
379
		$multilingual = $this->get_load_lang( );
380
		
381
		if ( $multilingual == $this->WPLANGKEY && $filter != 'keyword' ){
382
			return $show;
383
		}
384
		
385
		if ( $filter == 'name' || $filter == 'blogname'):
386
			$show = $this->get_multilingual_option( $multilingual , 'blogname' );
387
		elseif ( $filter == 'description' || $filter == 'blogdescription' ):
388
			$show = $this->get_multilingual_option( $multilingual , 'blogdescription' );
389
		elseif ( $filter == 'keyword' ):
390
			$show = $this->get_multilingual_option( $multilingual , $filter );
391
		endif;
392
		
393
		return $show;
394
	}
395
	
396
	/**
397
	* ファンクション名:ps_blog_details_multilingual
398
	* 機能概要:子サイトのサイト名を該当言語にする
399
	* 作成:プライム・ストラテジー株式会社 王 濱
400
	* 作成:
401
	* 変更:
402
	* @param Object $details
403
	* @param Object $details
404
	* @return
405
	*/	
406
	function ps_blog_details_multilingual( $details ){
407
		$multilingual = $this->get_load_lang( );
408
409
		if ( $multilingual == $this->WPLANGKEY ){
410
			return $details;
411
		}
412
		
413
		if ( is_multisite( ) ):
414
			global $blog_id;
415
			$blogname = $this->get_multilingual_option( $multilingual , 'blogname' );
416
			
417
			if ( $blogname && $blog_id == $details->blog_id ) {
418
				$details->blogname = $blogname;	
419
			}
420
		endif;
421
		
422
		return $details;		
423
		
424
	}
425
	
426
	/**
427
	* ファンクション名:
428
	* 機能概要:
429
	* 作成:プライム・ストラテジー株式会社 王 濱
430
	* 作成:
431
	* 変更:
432
	* @param resource
433
	* @param int
434
	* @param string
435
	* @return
436
	*/	
437
	function get_multilingual_option( $lang, $key ){
438
439
		if ( $key  ){
440
			$option = get_option( $key . '_' . $lang );
441
		}
442
		if ( $option ){
443
			return $option;
444
		}
445
		
446
		return get_option( $key );
447
		
448
	}
449
450
	/**
451
	* ファンクション名:ps_language_attributes_multilingual
452
	* 機能概要:<html dir="ltr" lang="言語コード">の設定
453
	* 作成:プライム・ストラテジー株式会社 王 濱
454
	* 変更:
455
	* @param resource
456
	* @param int
457
	* @param string
458
	* @return
459
	*/
460
	function ps_language_attributes_multilingual( $output = null ){
461
		$attributes = array();
462
		$doctype = 'html';
463
464
		if ( preg_match('|xml|' , $output)){
465
			$doctype = 'xhtml';
466
		}
467
468
		if ( $this->get_load_lang() == $this->WPLANGKEY  ){
469
			return $output;
470
		}
471
	
472
		if ( function_exists( 'is_rtl' ) )
473
			$attributes[] = 'dir="' . ( is_rtl() ? 'rtl' : 'ltr' ) . '"';
474
	
475
		$lang = get_bloginfo('language');
476
		if ( $lang_code ):
477
			$lang = str_replace('_', '-', $lang_code);
478
		endif;
479
480
		if ( $lang ) :
481
			if ( get_option('html_type') == 'text/html' || $doctype == 'html' )
482
				$attributes[] = "lang=\"$lang\"";
483
	
484
			if ( get_option('html_type') != 'text/html' || $doctype == 'xhtml' )
485
				$attributes[] = "xml:lang=\"$lang\"";
486
		endif;
487
		
488
		$output = implode(' ', $attributes);
489
		
490
		$output = apply_filters('regist_language_attributes', $output);
491
		
492
		echo $output;
493
	}
494
495
	/**
496
	* ファンクション名:
497
	* 機能概要:
498
	* 作成:プライム・ストラテジー株式会社 王 濱
499
	* 変更:
500
	* @param resource
501
	* @param int
502
	* @param string
503
	* @return
504
	*/
505
	function get_multilingual_code( $lang ){
506
		
507
		if ( $lang ):
508
			$lang_code = $this->multilingual_code[$lang];
509
			$lang_code = str_replace('_', '-', $lang_code);
510
		else:
511
			$lang_code = $this->multilingual_code[$this->WPLANGKEY];
512
			$lang_code = str_replace('_', '-', $lang_code);
513
		endif;	
514
		return $lang_code;
515
	}
516
	
517
	/**
518
	* ファンクション名:ps_012_m17n_the_posts
519
	* 機能概要: 投稿、ページ、カスタム投稿タイプのタイトルと内容を該当言語にする
520
	* 作成:プライム・ストラテジー株式会社 王 濱
521
	* 変更:
522
	* @param Object $posts
523
	* @param Object $query_this
524
	* @return Object $posts
525
	*/
526
	function ps_012_m17n_the_posts( $posts , $query_this){
527
528
529
		if ( $this->get_load_lang() == $this->WPLANGKEY  ){
530
			return $posts;
531
		}
532
533
		if ( !$posts ){
534
			return $posts;
535
		}
536
	
537
		foreach ( $posts as $key => $post){
538
			$multilingual_Name = get_post_meta( $post->ID, 'post_content_' . $this->load_lang , true);
539
			
540
			if ( $multilingual_Name ):
541
				$post->post_content =  $multilingual_Name;
542
			endif;
543
			
544
			$multilingual_title = get_post_meta( $post->ID, 'post_title_' . $this->load_lang , true);
545
			
546
			if ( $multilingual_title ):
547
				$post->post_title =  $multilingual_title;
548
			endif;
549
			$multilingual_excerpt = get_post_meta( $post->ID, 'post_excerpt_' . $this->load_lang , true);
550
			
551
			if ( $multilingual_excerpt ):
552
				$post->post_excerpt =  $multilingual_excerpt;
553
			endif;
554
			$post->post_content = preg_replace('|<p>&gt;</p>|' , '' , $post->post_content );
555
			$post->post_content = preg_replace('|&gt;|' , '' , $post->post_content );		
556
		}
557
		
558
		return $posts;
559
		
560
	}
561
	
562
	/**
563
	* ファンクション名:ps_single_post_title_multilingual
564
	* 機能概要: 投稿、ページ、カスタム投稿タイプのタイトルを該当言語にする
565
	* 作成:プライム・ストラテジー株式会社 王 濱
566
	* 変更:
567
	* @param String $title
568
	* @param Object $_post
569
	* @return String $title
570
	*/
571
	function ps_single_post_title_multilingual( $title , $_post ){
572
		
573
		if ( is_single() || ( is_home() && !is_front_page() ) || ( is_page() && !is_front_page() ) ) {
574
			
575
			$multilingual_title = get_post_meta( $_post->ID, 'post_title_' . $this->load_lang , true);
576
			
577
			if ( $multilingual_title ):
578
				$title =  $multilingual_title;
579
			endif;					
580
		}
581
		
582
		return $title;
583
	}
584
	
585
	/**
586
	* ファンクション名:ps_012_m17n_search
587
	* 機能概要:多国化の検索対応
588
	* 作成:プライム・ストラテジー株式会社 王 濱
589
	* 変更:
590
	* @param Array $pre
591
	* @return Array $pre 
592
	*/	
593
	function ps_012_m17n_search( $pre ){
594
		global $blog_id, $wpdb;
595
		if ( !is_search() ){
596
		    return $pre;
597
		}
598
		if ( $this->get_load_lang() == $this->WPLANGKEY  ){
599
			return $pre;
600
		}
601
		
602
		$lang =  $this->get_load_lang();
603
	    if ( $lang ){
604
	        $meta_query = array(
605
	            array(
606
	                'key'  => 'post_title_' . $lang,
607
	                'value' => $pre->query_vars['s'],
608
	                'compare' => 'LIKE'
609
	            ), 
610
	            array(
611
	                'key'  => 'post_content_' . $lang,
612
	                'value' => $pre->query_vars['s'],
613
	                'compare' => 'LIKE'
614
	            ),
615
	            'relation'=>'OR'
616
	         );
617
	        $teest = $pre->query_vars['s'];
618
	        $pre->query_vars['s'] = "";
619
	        $pre->query_vars['meta_query'] = $meta_query;
620
	        //add_filter('posts_where', array( &$this , 'ps_search_where' ));
621
	    }
622
	    		
623
		return $pre;
624
	}
625
	
626
	/**
627
	* ファンクション名:ps_wp_title_multi_lang
628
	* 機能概要:多国語のタイトルを表示する
629
	* 作成:プライム・ストラテジー株式会社 王 濱
630
	* 作成:
631
	* 変更:
632
	* @param String $title(デフォルト語のタイトル)
633
	* @return String $title(多国語タイトル)
634
	*/
635
	function ps_wp_title_multilingual( $title, $mark = '' ){
636
		
637
		if ( $this->get_load_lang() == $this->WPLANGKEY  ){
638
			return $title;
639
		}
640
		
641
		if ( is_search() ):
642
		
643
			$lang = $this->get_load_lang();
644
			
645
			$searchResults = $this->search_multilingual_title[$lang];
646
			
647
			if ( $searchResults ){
648
				$preg_quote = preg_quote($mark,'|');
649
				$title = preg_replace('|' . $preg_quote .'(.*)'. $preg_quote .'|', $mark . ' ' . $searchResults . ' ' . $mark , $title);
650
			}
651
			
652
			if ( $_GET['s'] ):
653
				return $_GET['s'] . $title;
654
			elseif ( $_POST['s'] ):
655
				return  $_POST['s']  . $title;
656
			endif;
657
		endif;
658
		return $title;
659
	}
660
		
661
	/**  
662
	 * ファンクション名:ps_wp_nav_menu_multilingual
663
	 * 機能概要:wp_nav_menuの表示タイトルを該当言語にする
664
	 * 作成:プライム・ストラテジー株式会社 王 濱
665
	 * 変更:
666
	 * @param   Array $nav_menu
667
	 * @param   Array $args
668
	 * @return  Array 全$nav_menu
669
	 */
670
	function ps_wp_nav_menu_multilingual( $nav_menu, $args  ) {
671
672
		if ( $this->get_load_lang() == $this->WPLANGKEY  ){
673
			return $nav_menu;
674
		}
675
		
676
		$aliases = $this->get_multilingual_title( );
677
		if ( $aliases ):
678
			foreach ( $aliases as $alias  ):
679
				$nav_menu = preg_replace( '/>' . preg_quote( trim($alias['post_title']), '/' ) . '</', '>' . $alias['meta_value'] . '<',  $nav_menu );
680
			endforeach;
681
		endif;
682
		
683
		return $nav_menu;
684
	}
685
	
686
	/**  
687
	 * ファンクション名:ps_wp_list_page_multilingual
688
	 * 機能概要:wp_list_pageの表示タイトルを該当言語にする
689
	 * 作成:プライム・ストラテジー株式会社 王 濱
690
	 * 変更:
691
	 * @param   Array $global_navi
692
	 * @return  Array 全$global_navi
693
	 */
694
	function ps_wp_list_page_multilingual( $global_navi ){
695
696
		if ( $this->get_load_lang() == $this->WPLANGKEY  ){
697
			return $global_navi;
698
		}
699
		
700
		$aliases = $this->get_multilingual_title( );
701
702
		if ( $aliases ):
703
			foreach( $aliases as $alias):
704
				$global_navi = preg_replace( '/>' . preg_quote( trim($alias['post_title']), '/' ) . '</', '>' . $alias['meta_value'] . '<',  $global_navi );
705
			endforeach;
706
		endif;
707
		return $global_navi;
708
	}
709
710
	/**  
711
	 * ファンクション名:get_multilingual_title
712
	 * 機能概要:全カスタムフィールドを取得
713
	 * 作成:プライム・ストラテジー株式会社 王 濱
714
	 * 変更:
715
	 * @param   String post_id
716
	  * @return  Array 全カスタムフィールド
717
	 */
718
	function get_multilingual_title( ){
719
		global $wpdb;
720
		$sql ="
721
		SELECT	a.`post_title`,
722
				b.`meta_value`
723
		FROM	`$wpdb->posts` as a,
724
				`$wpdb->postmeta` as b
725
		WHERE	a.`ID` = b.`post_id`
726
		AND		b.`meta_key` = 'post_title_{$this->get_load_lang()}'";
727
		
728
		if ( $this->get_load_lang() != $this->WPLANGKEY ):
729
			$aliases = $wpdb->get_results( $sql, 'ARRAY_A' );
730
		endif;
731
		
732
		return $aliases;
733
		
734
	}
735
736
	/**  
737
	 * ファンクション名:get_multilingual_excerpt
738
	 * 機能概要:全カスタムフィールドを取得
739
	 * 作成:プライム・ストラテジー株式会社 王 濱
740
	 * 変更:
741
	 * @param   String post_id
742
	  * @return  Array 全カスタムフィールド
743
	 */
744
	function get_multilingual_excerpt( ){
745
		global $wpdb;
746
		$sql ="
747
		SELECT	a.`post_excerpt`,
748
				b.`meta_value`
749
		FROM	`$wpdb->posts` as a,
750
				`$wpdb->postmeta` as b
751
		WHERE	a.`ID` = b.`post_id`
752
		AND		b.`meta_key` = 'post_excerpt_{$this->get_load_lang()}'";
753
		
754
		if ( $this->get_load_lang() != $this->WPLANGKEY ):
755
			$aliases = $wpdb->get_results( $sql, 'ARRAY_A' );
756
		endif;
757
		
758
		return $aliases;
759
		
760
	}
761
	
762
	/**  
763
	 * ファンクション名:get_ps_post_customs
764
	 * 機能概要:全カスタムフィールドを取得
765
	 * 作成:プライム・ストラテジー株式会社 王 濱
766
	 * 変更:
767
	 * @param   String post_id
768
	  * @return  Array 全カスタムフィールド
769
	 */
770
	function get_ps_post_customs( $post_id  ){   
771
	    $custom_fields = get_post_custom($post_id);
772
	    $return = array();  
773
	    foreach( $custom_fields as $key => $field ){
774
	    	if ( count( $field ) > 1 ){
775
	    		foreach ( $field as $key2 => $val  ){
776
	    			$return[$key][$key2] = $val;
777
	    		}
778
	    	}else{
779
	    		if ( preg_match('/^_(.*)/' , $key  )){
780
	        		$return[$key] = maybe_unserialize($field[0]) ;
781
	    		}else{
782
	    			$return[$key] = $field[0];
783
	    		}
784
	    	}
785
	    }
786
	    return $return;
787
	}
788
789
790
	/**
791
	* ファンクション名:
792
	* 機能概要:
793
	* 作成:プライム・ストラテジー株式会社 王 濱
794
	* 変更:
795
	* @param resource
796
	* @param int
797
	* @param string
798
	* @return
799
	*/
800
	function ps_multilingual_get_terms ( $terms, $taxonomies, $args ){
801
802
		$lang = $this->get_load_lang( ); 
803
		
804
		$current_option = get_option( $taxonomies[0] . '-' . $lang );
805
806
		foreach ( $terms as $key => $term ):
807
			if ( $this->WPLANGKEY != $lang ):
808
				$multilingual_Name = $current_option[$term->term_id];
809
				if ( $multilingual_Name ):
810
					$terms[$key]->name = is_array($multilingual_Name) ? join(',', $multilingual_Name) :  $multilingual_Name ;
811
				endif;
812
			endif;
813
						
814
		endforeach;
815
816
		return $terms;
817
	}
818
819
	/**
820
	* ファンクション名:
821
	* 機能概要:
822
	* 作成:プライム・ストラテジー株式会社 王 濱
823
	* 変更:
824
	* @param resource
825
	* @param int
826
	* @param string
827
	* @return
828
	*/
829
	function ps_multilingual_get_the_terms( $terms, $id, $taxonomy ){
830
		$lang = $this->get_load_lang( ); 
831
	
832
		$current_option = get_option( $taxonomy . '-' . $lang );
833
		
834
		foreach ( $terms as $key => $term ):
835
			if ( $this->WPLANGKEY != $lang ):
836
				$multilingual_Name = $current_option[$term->term_id];
837
				if ( $multilingual_Name ):
838
					$terms[$key]->name = is_array($multilingual_Name) ? join(',', $multilingual_Name) :  $multilingual_Name ;
839
				endif;
840
			endif;
841
						
842
		endforeach;
843
844
		return $terms;	
845
	}
846
	
847
	/**
848
	* ファンクション名:
849
	* 機能概要:
850
	* 作成:プライム・ストラテジー株式会社 王 濱
851
	* 変更:
852
	* @param resource
853
	* @param int
854
	* @param string
855
	* @return
856
	*/	
857
	function ps_multilingual_get_term( $term, $taxonomy ){
858
		$lang = $this->get_load_lang( );
859
		$current_option = get_option( $taxonomy . '-' . $lang );
860
861
		$multilingual_Name = $current_option[$term->term_id];
862
863
		if ( $this->WPLANGKEY != $lang ):
864
			if ( $multilingual_Name ):
865
				$term->name = is_array($multilingual_Name) ? join(',', $multilingual_Name) :  $multilingual_Name ;
866
			endif;
867
		endif;
868
		
869
		return $term;
870
		
871
	}
872
	
873
	/**
874
	* ファンクション名:
875
	* 機能概要:
876
	* 作成:プライム・ストラテジー株式会社 王 濱
877
	* 変更:
878
	* @param resource
879
	* @param int
880
	* @param string
881
	* @return
882
	*/
883
	function regist_contact_info_field() {
884
		
885
		$flag_icon = $this->flags_dir . $this->WPLANGKEY . '.png';
886-
			if ( url_exists( $flag_icon )):
886+
			if ( ps_url_exists( $flag_icon )):
887
				$flag_icon = '<img src="' .  $flag_icon. '">&nbsp; ';	
888
			endif;
889
		add_settings_field( 'hr_' . $this->WPLANGKEY , $flag_icon   , array($this , 'display_option_general_hr' ), 'general' , 'default' , array($this->WPLANGKEY));
890
		
891
		add_settings_field( 'keyword_en' ,  __('Term')  , array($this , 'display_keyword_info' ), 'general' , 'default' , array($this->WPLANGKEY));
892
893
		foreach ( $this->multilingual as $key => $lang ):
894
			$flag_icon = $this->flags_dir . $key . '.png';
895-
			if ( url_exists( $flag_icon )):
895+
			if ( ps_url_exists( $flag_icon )):
896
				$flag_icon = '<img src="' .  $flag_icon. '">&nbsp; ';	
897
			endif;
898
			add_settings_field( 'hr_' . $key , $flag_icon  .  $lang  , array($this , 'display_option_general_hr' ), 'general' , 'default' , array($key));
899
			add_settings_field( 'blogname_' . $key ,  __('Site Title')  , array($this , 'display_blogname_info' ), 'general' , 'default' , array($key));
900
			add_settings_field( 'blogdescription_' . $key , __('Site Tagline')  , array($this , 'display_blogdescription_info' ), 'general' , 'default' , array($key));
901
			add_settings_field( 'keyword_' . $key , __('Term')  , array($this , 'display_keyword_info' ), 'general' , 'default' , array($key));
902
		endforeach;
903
		
904
	}
905
906
	/**
907
	* ファンクション名:
908
	* 機能概要:
909
	* 作成:プライム・ストラテジー株式会社 王 濱
910
	* 変更:
911
	* @param resource
912
	* @param int
913
	* @param string
914
	* @return
915
	*/
916
	function display_blogname_info( $lang ) {
917
		$lang = $lang[0];
918
		$blogname_lang = get_option( 'blogname_' . $lang );
919
?>
920
		<input type="text" id="blogname_<?php echo $lang;?>"  name="blogname_<?php echo $lang;?>" value="<?php echo esc_html( $blogname_lang ); ?>" class="regular-text">
921
<?php
922
	}
923
	
924
	/**
925
	* ファンクション名:
926
	* 機能概要:
927
	* 作成:プライム・ストラテジー株式会社 王 濱
928
	* 変更:
929
	* @param resource
930
	* @param int
931
	* @param string
932
	* @return
933
	*/
934
	function display_option_general_hr( $lang ){
935
936
	}
937
	
938
	/**
939
	* ファンクション名:
940
	* 機能概要:
941
	* 作成:プライム・ストラテジー株式会社 王 濱
942
	* 変更:
943
	* @param resource
944
	* @param int
945
	* @param string
946
	* @return
947
	*/
948
	function display_blogdescription_info( $lang ) {
949
		$lang = $lang[0];
950
		$blogdescription_lang = get_option( 'blogdescription_' . $lang );
951
?>
952
				<input type="text" id="blogdescription_<?php echo $lang;?>"  name="blogdescription_<?php echo $lang;?>" value="<?php echo esc_html( $blogdescription_lang ); ?>" class="regular-text">
953
<?php
954
	}
955
956
	/**
957
	* ファンクション名:
958
	* 機能概要:
959
	* 作成:プライム・ストラテジー株式会社 王 濱
960
	* 変更:
961
	* @param resource
962
	* @param int
963
	* @param string
964
	* @return
965
	*/
966
	function display_keyword_info( $lang ) {
967
		$lang = $lang[0];
968
		$keyword_lang = get_option( 'keyword_' . $lang );
969
?>
970
		<input type="text" id="keyword_<?php echo $lang;?>"  name="keyword_<?php echo $lang;?>" value="<?php echo esc_html( $keyword_lang ); ?>" class="regular-text">
971
<?php
972
	}	
973
974
	/**
975
	* ファンクション名:
976
	* 機能概要:
977
	* 作成:プライム・ストラテジー株式会社 王 濱
978
	* 変更:
979
	* @param resource
980
	* @param int
981
	* @param string
982
	* @return
983
	*/
984
	function add_contact_info_field( $whitelist_options ) {
985
986
		foreach ( $this->multilingual as $key => $lang ):
987
			$whitelist_options['general'][] = 'blogname_' . $key;
988
			$whitelist_options['general'][] = 'blogdescription_' . $key;
989
			$whitelist_options['general'][] = 'keyword_' . $key;
990
		endforeach;
991
		$whitelist_options['general'][] = 'keyword_en';	
992
		return $whitelist_options;
993
	}
994
	
995
	/**
996
	* ファンクション名:admin_multilingual_edit
997
	* 機能概要:管理画面のカスタマイズ処理
998
	* 作成:プライム・ストラテジー株式会社 王 濱
999
	* 変更:
1000
	* @param resource
1001
	* @param int
1002
	* @param string
1003
	* @return
1004
	*/
1005
	function admin_multilingual_edit( ){
1006
		
1007
		//カスタマイズ処理国旗のディレクトリを取得する
1008
		$this->flags_dir = plugins_url('flags/', __FILE__);
1009
		
1010
	}
1011
	
1012
	/**
1013
	* ファンクション名:ps_012_multilingual_list
1014
	* 機能概要:多国語の切替リンクを設定する
1015
	* 作成:プライム・ストラテジー株式会社 王 濱
1016
	* 変更:
1017
	* @param String $lang
1018
	* @return String $snippet
1019
	*/
1020
	function ps_012_multilingual_list( $lang = null ){
1021
		if ( !$lang ){
1022
			$lang = $this->get_load_lang();
1023
		}
1024
		$snippet = array();
1025
		$request_uri = $_SERVER['REQUEST_URI'];
1026
	
1027
		foreach ( $this->multilingual_code as $key => $load_lang ){
1028
				$snippet[$key]['name'] =  $this->format_code_lang( $key );// == 'ja' ? '日本' : strtoupper($key);
1029
				$snippet[$key]['url'] = $this->get_multilingual_request_uri($request_uri, $key );
1030
				$snippet[$key]['current'] = $key == $lang ? ' current' : '';
1031
		}
1032
		return $snippet;
1033
	}
1034
	
1035
	/**
1036
	* ファンクション名:get_multilingual_request_uri
1037
	* 機能概要:多言語のリクエストのURLを作成
1038
	* 作成:プライム・ストラテジー株式会社 王 濱
1039
	* 変更:
1040
	* @param string $url URL
1041
	* @param string $lang 言語コード
1042
	* @return url 再設定URL
1043
	*/
1044
	function get_multilingual_request_uri($url ,  $lang ){
1045
		
1046
		if ( preg_match( '|\?lang='. $lang .'|' , $url) ||  preg_match( '|&lang='. $lang .'|' , $url ) ){
1047
			return $url;
1048
		}elseif( preg_match( '|\?lang=[\w]{2}|' , $url) ){
1049
			return preg_replace('|(\?)lang=([\w]{2})|' , "$1lang=" . $lang , $url);
1050
		}elseif( preg_match( '|&lang=[\w]{2}|' , $url) ){
1051
			return preg_replace('|(&)lang=([\w]{2})|' , "$1lang=" . $lang , $url);
1052
		}else{
1053
			if ( preg_match('|\?[\w]+=|', $url, $m )){
1054
				return $url . '&lang=' . $lang;
1055
			}else{
1056
				return $url . '?lang=' . $lang;
1057
			}
1058
		}
1059
	}
1060
1061
	/**
1062
	* ファンクション名:
1063
	* 機能概要:
1064
	* 作成:プライム・ストラテジー株式会社 王 濱
1065
	* 作成:
1066
	* 変更:
1067
	* @param resource
1068
	* @param int
1069
	* @param string
1070
	* @return
1071
	*/
1072
	function format_code_lang( $code = '' ) {
1073
		$code = strtolower( substr( $code, 0, 2 ) );
1074
		$lang_codes = array(
1075
			'aa' => 'Afar', 'ab' => 'Abkhazian', 'af' => 'Afrikaans', 'ak' => 'Akan', 'sq' => 'Albanian', 'am' => 'Amharic', 'ar' => 'Arabic', 'an' => 'Aragonese', 'hy' => 'Armenian', 'as' => 'Assamese', 'av' => 'Avaric', 'ae' => 'Avestan', 'ay' => 'Aymara', 'az' => 'Azerbaijani', 'ba' => 'Bashkir', 'bm' => 'Bambara', 'eu' => 'Basque', 'be' => 'Belarusian', 'bn' => 'Bengali',
1076
			'bh' => 'Bihari', 'bi' => 'Bislama', 'bs' => 'Bosnian', 'br' => 'Breton', 'bg' => 'Bulgarian', 'my' => 'Burmese', 'ca' => 'Catalan; Valencian', 'ch' => 'Chamorro', 'ce' => 'Chechen', 'zh' => 'Chinese', 'cu' => 'Church Slavic; Old Slavonic; Church Slavonic; Old Bulgarian; Old Church Slavonic', 'cv' => 'Chuvash', 'kw' => 'Cornish', 'co' => 'Corsican', 'cr' => 'Cree',
1077
			'cs' => 'Czech', 'da' => 'Danish', 'dv' => 'Divehi; Dhivehi; Maldivian', 'nl' => 'Dutch; Flemish', 'dz' => 'Dzongkha', 'en' => 'English', 'eo' => 'Esperanto', 'et' => 'Estonian', 'ee' => 'Ewe', 'fo' => 'Faroese', 'fj' => 'Fijjian', 'fi' => 'Finnish', 'fr' => 'French', 'fy' => 'Western Frisian', 'ff' => 'Fulah', 'ka' => 'Georgian', 'de' => 'German', 'gd' => 'Gaelic; Scottish Gaelic',
1078
			'ga' => 'Irish', 'gl' => 'Galician', 'gv' => 'Manx', 'el' => 'Greek, Modern', 'gn' => 'Guarani', 'gu' => 'Gujarati', 'ht' => 'Haitian; Haitian Creole', 'ha' => 'Hausa', 'he' => 'Hebrew', 'hz' => 'Herero', 'hi' => 'Hindi', 'ho' => 'Hiri Motu', 'hu' => 'Hungarian', 'ig' => 'Igbo', 'is' => 'Icelandic', 'io' => 'Ido', 'ii' => 'Sichuan Yi', 'iu' => 'Inuktitut', 'ie' => 'Interlingue',
1079
			'ia' => 'Interlingua (International Auxiliary Language Association)', 'id' => 'Indonesian', 'ik' => 'Inupiaq', 'it' => 'Italian', 'jv' => 'Javanese', 'ja' => 'Japanese', 'kl' => 'Kalaallisut; Greenlandic', 'kn' => 'Kannada', 'ks' => 'Kashmiri', 'kr' => 'Kanuri', 'kk' => 'Kazakh', 'km' => 'Central Khmer', 'ki' => 'Kikuyu; Gikuyu', 'rw' => 'Kinyarwanda', 'ky' => 'Kirghiz; Kyrgyz',
1080
			'kv' => 'Komi', 'kg' => 'Kongo', 'ko' => 'Korean', 'kj' => 'Kuanyama; Kwanyama', 'ku' => 'Kurdish', 'lo' => 'Lao', 'la' => 'Latin', 'lv' => 'Latvian', 'li' => 'Limburgan; Limburger; Limburgish', 'ln' => 'Lingala', 'lt' => 'Lithuanian', 'lb' => 'Luxembourgish; Letzeburgesch', 'lu' => 'Luba-Katanga', 'lg' => 'Ganda', 'mk' => 'Macedonian', 'mh' => 'Marshallese', 'ml' => 'Malayalam',
1081
			'mi' => 'Maori', 'mr' => 'Marathi', 'ms' => 'Malay', 'mg' => 'Malagasy', 'mt' => 'Maltese', 'mo' => 'Moldavian', 'mn' => 'Mongolian', 'na' => 'Nauru', 'nv' => 'Navajo; Navaho', 'nr' => 'Ndebele, South; South Ndebele', 'nd' => 'Ndebele, North; North Ndebele', 'ng' => 'Ndonga', 'ne' => 'Nepali', 'nn' => 'Norwegian Nynorsk; Nynorsk, Norwegian', 'nb' => 'Bokmål, Norwegian, Norwegian Bokmål',
1082
			'no' => 'Norwegian', 'ny' => 'Chichewa; Chewa; Nyanja', 'oc' => 'Occitan, Provençal', 'oj' => 'Ojibwa', 'or' => 'Oriya', 'om' => 'Oromo', 'os' => 'Ossetian; Ossetic', 'pa' => 'Panjabi; Punjabi', 'fa' => 'Persian', 'pi' => 'Pali', 'pl' => 'Polish', 'pt' => 'Portuguese', 'ps' => 'Pushto', 'qu' => 'Quechua', 'rm' => 'Romansh', 'ro' => 'Romanian', 'rn' => 'Rundi', 'ru' => 'Russian',
1083
			'sg' => 'Sango', 'sa' => 'Sanskrit', 'sr' => 'Serbian', 'hr' => 'Croatian', 'si' => 'Sinhala; Sinhalese', 'sk' => 'Slovak', 'sl' => 'Slovenian', 'se' => 'Northern Sami', 'sm' => 'Samoan', 'sn' => 'Shona', 'sd' => 'Sindhi', 'so' => 'Somali', 'st' => 'Sotho, Southern', 'es' => 'Spanish; Castilian', 'sc' => 'Sardinian', 'ss' => 'Swati', 'su' => 'Sundanese', 'sw' => 'Swahili',
1084
			'sv' => 'Swedish', 'ty' => 'Tahitian', 'ta' => 'Tamil', 'tt' => 'Tatar', 'te' => 'Telugu', 'tg' => 'Tajik', 'tl' => 'Tagalog', 'th' => 'Thai', 'bo' => 'Tibetan', 'ti' => 'Tigrinya', 'to' => 'Tonga (Tonga Islands)', 'tn' => 'Tswana', 'ts' => 'Tsonga', 'tk' => 'Turkmen', 'tr' => 'Turkish', 'tw' => 'Twi', 'ug' => 'Uighur; Uyghur', 'uk' => 'Ukrainian', 'ur' => 'Urdu', 'uz' => 'Uzbek',
1085
			've' => 'Venda', 'vi' => 'Vietnamese', 'vo' => 'Volapük', 'cy' => 'Welsh','wa' => 'Walloon','wo' => 'Wolof', 'xh' => 'Xhosa', 'yi' => 'Yiddish', 'yo' => 'Yoruba', 'za' => 'Zhuang; Chuang', 'zu' => 'Zulu' );
1086
		$lang_codes = apply_filters( 'format_code_lang', $lang_codes, $code );
1087
		return strtr( $code, $lang_codes );
1088
	}
1089
1090
	/**
1091
	* ファンクション名:custom_taxonomy_admin_notices
1092
	* 機能概要:設定ファイルなし、警告メッセージ
1093
	* 作成:プライム・ストラテジー株式会社 王 濱
1094
	* 変更:
1095
	*/	
1096
	function custom_taxonomy_admin_notices(){
1097
		echo '<div class="error" style="text-align: center;"><p style="color: red; font-size: 14px; font-weight: bold;">プラグイン012 PS Multi Languages :設定ファイル<strong>_config.php</strong>の名前を<strong>config.php OR config-{$blog_id}.php</strong>に変更し、<strong>configファイル</strong>の設定を行ってください。</p></div>';
1098
	}
1099
	
1100
	/**
1101
	* ファンクション名:admin_notices_multilingual
1102
	* 機能概要:設定ファイルあり、$ultilingualがない場合警告メッセージ
1103
	* 作成:プライム・ストラテジー株式会社 王 濱
1104
	* 変更:
1105
	*/	
1106
	function admin_notices_multilingual(){
1107
		echo '<div class="error" style="text-align: center;"><p style="color: red; font-size: 14px; font-weight: bold;">プラグイン012 PS Multi Languages:設定ファイル<strong>config.php OR config-{$blog_id}.php</strong>の多国語設定配列($multilingual)の設定を行ってください。</p></div>';
1108
	}
1109
	
1110
	/**
1111
	* ファンクション名:get_bread_crumb_array
1112
	* 機能概要:パンくずナビのデータを作成
1113
	* 作成:
1114
	* 変更:
1115
	* @param void
1116
	* @return Array $bread_crumb_arr
1117
	*/	
1118
	function get_bread_crumb_array() {
1119
		global $post,$term , $wp_post_types , $blog_id , $all_post_type , $wp_query ;
1120
		
1121
		$bread_crumb_arr = array();
1122
		
1123
		$multilingual = $this->get_load_lang( );
1124
		
1125
		$default_ml = $this->WPLANGKEY;
1126
	
1127
		//  if ( $multilingual == $default_ml ){
1128
		
1129
		if ( is_multisite() && false ){
1130
			$site=get_blog_details($blog_id);
1131
			$site_url = get_bloginfo( 'url' );
1132
			$bread_crumb_arr[] = array( 'title' => 'Top Home' , 'link' =>  '/' );
1133
			$bread_crumb_arr[] = array( 'title' => $site->blogname , 'link' => $site_url . '/' );
1134
		}else{
1135
			$front_page_id = get_option( 'page_on_front' );
1136
		
1137
			if ( $front_page_id > 0 ){
1138
				$front_page = get_page( $front_page_id );
1139
				if ( $multilingual == $default_ml ){
1140
					$front_page_title =  $front_page->post_title;
1141
				}else{
1142
					$front_page_title = get_post_meta( $front_page_id , 'post_title_' . $multilingual , true);
1143
					if ( !$front_page_title ){
1144
						$front_page_title =  $front_page->post_title;	
1145
					}
1146
				}
1147
			}else{
1148
				$front_page_title = 'Home';
1149
			}
1150
			$bread_crumb_arr[] = array( 'title' => $front_page_title , 'link' =>  '/' );
1151
		}
1152
1153
		
1154
		if ( is_404() ) {
1155
			$bread_crumb_arr[] = array( 'title' =>  'No results found.' , 'link' => false );
1156
		} elseif ( is_search() || ( isset( $_GET['s'] ) && $_GET['s'] == false )) {
1157
			$search_results = $this->search_multilingual_title[$multilingual];
1158
			if ( $search_results ){
1159
				$bread_crumb_arr[] = array( 'title' => sprintf( $search_results . ' &#8220;%s&#8221;' , $_GET['s'] ), 'link' => false );
1160
			}else{
1161
				$bread_crumb_arr[] = array( 'title' => sprintf( __('Search results for &#8220;%s&#8221;')  , $_GET['s'] ), 'link' => false );
1162
			}
1163
		} elseif ( is_tax() ) {//oh start 2011/08/04
1164
				//カスタム投稿タイプを取得する
1165
				//$post_type =  get_post_type(); 
1166
				//クエリからtaxonomy(カスタム分類タクソノミー)のslug取
1167
				$taxonomy = get_query_var( 'taxonomy' );
1168
1169
				//termの情報を取得
1170
				$term_object = get_term_by( 'slug', get_query_var( 'term' ), $taxonomy );
1171
	
1172
				if ( is_taxonomy_hierarchical( $taxonomy ) && $term_object->parent != 0 ) {
1173
			        $ancestors = array_reverse( get_ancestors( $term_object->term_id, $taxonomy ) );
1174
			        foreach ( $ancestors as $ancestor_id ) {
1175
			            $ancestor = get_term( $ancestor_id, $taxonomy );
1176
			            $bread_crumb_arr[] = array( 'title' => $ancestor->name, 'link' => get_term_link( $ancestor, $term) );
1177
			        }
1178
			    }
1179
		   		$bread_crumb_arr[] = array( 'title' => $term_object->name , 'link' => get_term_link( $term_object, $term ) );
1180
			
1181
		} elseif ( is_home() || is_front_page() ) {
1182
		} elseif ( is_attachment() ) {
1183
			if ( $post->post_parent ) {
1184
				if ( $parent_post = get_post( $post->post_parent ) ) {
1185
					if ( $multilingual == $default_ml ){
1186
						$parent_post_title =  $parent_post->post_title;
1187
					}else{
1188
						$parent_post_title = get_post_meta( $parent_post->ID , 'post_title_' . $multilingual , true);
1189
						if ( !$front_page_title ){
1190
							$parent_post_title =  $parent_post->post_title;
1191
						}
1192
					}
1193
				}
1194
				$bread_crumb_arr[] = array( 'title' => $parent_post->post_title, 'link' => get_permalink( $parent_post->ID ) );
1195
			}
1196
			$bread_crumb_arr[] = array( 'title' => $post->post_name, 'link' => get_permalink( $post->ID ) );
1197
1198
		} elseif ( is_single() ) {
1199
	
1200
			//カスタム投稿タイプを取得する
1201
			$post_type =  get_post_type(); 
1202
			
1203
			$taxonomy = get_query_var( 'taxonomy' );
1204
		
1205
			//$taxonomy = ( in_array($post->post_type,array('post','attachment')) ? 'category':$post->post_type . '-category');
1206
			$post_term = get_the_terms($post->ID,$taxonomy); 
1207
1208
			$post_type_taxonomies = get_object_taxonomies( $post_type, false );
1209
			
1210
			if ( is_array( $post_type_taxonomies ) && count( $post_type_taxonomies ) ) {
1211
				foreach( $post_type_taxonomies as $tax_slug => $taxonomy ) {
1212
					if ( $taxonomy->hierarchical ) {
1213
						$terms = get_the_terms( $post->ID, $tax_slug );
1214
						if ( $terms ) {
1215
							$post_term = array_shift( $terms );
1216
							$taxonomy = $post_term->taxonomy;
1217
							break;
1218
						}
1219
					}
1220
				}
1221
			}
1222
			
1223
			if ( !$post_term || is_wp_error($post_term)){
1224
				$default_category = get_option( $post_type .  '_default_category');
1225
				$post_term = get_term(  $default_category , $taxonomy);
1226
			}
1227
1228
			if ( is_taxonomy_hierarchical( $taxonomy ) && $post_term->parent != 0 ) {
1229
		        $ancestors = array_reverse( get_ancestors( $post_term->term_id, $taxonomy ) );
1230
		        foreach ( $ancestors as $ancestor_id ) {
1231
		            $ancestor = get_term( $ancestor_id, $taxonomy );
1232
	
1233
		           	if (!in_array($post->post_type,array('post','attachment'))){
1234
		            	 $bread_crumb_arr[] = array( 'title' => $ancestor->name , 'link' => get_term_link( $ancestor, $post_term->slug ) );
1235
		           	}else{
1236
		           		$bread_crumb_arr[] = array( 'title' => $ancestor->name , 'link' => get_term_link( $ancestor, $post_term->slug ) );
1237
		           	}
1238
		        }
1239
		    }
1240
	
1241
		    if ( $post_term && !$post_term->errors){
1242
				$bread_crumb_arr[] = array( 'title' => $post_term->name, 'link' => get_term_link( $post_term, $post_term->slug ));
1243
		    }
1244
1245
		    if ( $multilingual != $default_ml ){
1246
	       		$multi_lang_Name = get_post_meta( $post->ID, 'post_title_' . $multilingual , true);
1247
	        	$post->post_title = $multi_lang_Name ? $multi_lang_Name : $post->post_title;
1248
		    }
1249
	        
1250
			$bread_crumb_arr[] = array( 'title' => $post->post_title , 'link' => get_permalink( $post->ID ) );
1251
					
1252
		} elseif ( is_page() ) {
1253
			$ancestors = array_reverse(get_post_ancestors( $post ) );
1254
			$ancestor_posts = get_posts( 'post_type=page&include=' . implode( ',', $ancestors ) );
1255
			foreach( $ancestors as $ancestor ) {
1256
				foreach ( $ancestor_posts as $ancestor_post ) {
1257
					if ( $ancestor == $ancestor_post->ID ) {
1258
						if ( $multilingual != $default_ml ){
1259
				       		$multi_lang_Name = get_post_meta( $ancestor_post->ID, 'post_title_' . $multilingual , true);
1260
				        	$ancestor_post->post_title = $multi_lang_Name ? $multi_lang_Name : $ancestor_post->post_title;
1261
						}				
1262
						$bread_crumb_arr[] = array( 'title' => $ancestor_post->post_title , 'link' => get_permalink( $ancestor_post->ID ) );
1263
					}
1264
				}
1265
			}
1266
			$bread_crumb_arr[] = array( 'title' => $post->post_title , 'link' => get_permalink( $post->ID ) );
1267
			
1268
		} elseif ( is_category() ) {
1269
			global $cat;
1270
			
1271
			$category = get_category( $cat );
1272
1273
			if ( $category->parent != 0 ) {
1274
				$ancestors = array_reverse( $this->get_category_ancestors( $category->parent ) );
1275
				foreach ( $ancestors as $ancestor ) {
1276
					$bread_crumb_arr[] = array( 'title' => $ancestor->name , 'link' => get_category_link( $ancestor->term_id ) );
1277
				}
1278
			}
1279
	  		$bread_crumb_arr[] = array( 'title' => $category->name , 'link' => get_category_link( $cat ) );
1280
		} elseif ( is_tag() ) {
1281
			global $tag_id;
1282
			$tag = get_tag( $tag_id );
1283
			$bread_crumb_arr[] = array( 'title' => $tag->name , 'link' => get_tag_link( $tag_id ) );
1284
		} elseif ( is_author() ) {
1285
			global $author;
1286
			$bread_crumb_arr[] = array( 'title' =>  get_author_name( $author ), 'link' => get_author_posts_url( $author ) );
1287
		} elseif ( is_day() ) {
1288
			$year = get_query_var( 'year' );
1289
			$month = get_query_var( 'monthnum' );
1290
			$day = get_query_var( 'day' );
1291
			$bread_crumb_arr[] = array( 'title' =>  $year , 'link' => get_year_link( $year ) );
1292
			$bread_crumb_arr[] = array( 'title' =>  $month , 'link' => get_month_link( $year, $month ) );
1293
			$bread_crumb_arr[] = array( 'title' =>  $day , 'link' => get_day_link( $year, $month, $day ) );
1294
		} elseif ( is_month() ) {
1295
			$year = get_query_var( 'year' );
1296
			$month = get_query_var( 'monthnum' );
1297
			$bread_crumb_arr[] = array( 'title' =>  $year , 'link' => get_year_link( $year ) );
1298
			$bread_crumb_arr[] = array( 'title' =>  $month , 'link' => get_month_link( $year, $month ) );
1299
		} elseif ( is_year() ) {
1300
			$year = get_query_var( 'year' );
1301
			$bread_crumb_arr[] = array( 'title' =>  $year , 'link' => get_year_link( $year ) );
1302
		}
1303
		return $bread_crumb_arr;
1304
	}
1305
	
1306
	/**
1307
	* ファンクション名:get_bread_crumb_array
1308
	* 機能概要:パンくずナビのデータを作成
1309
	* 作成:
1310
	* 変更:
1311
	* @param void
1312
	* @return Array $bread_crumb_arr
1313
	*/	
1314
	function bread_crumb( $type = 'list', $echo = false ) {
1315
	
1316
		$bread_crumb_arr = $this->get_bread_crumb_array();
1317
	
1318
		if ( $type == 'string' ) {
1319
			$output = array();
1320
			$cnt = 1;
1321
			foreach ( $bread_crumb_arr as $ancestor ) {
1322
				if ( $cnt == count( $bread_crumb ) ) {
1323
					$output[] = '<strong>' . apply_filters( 'the_title', $ancestor['title'] ) . '</strong>';
1324
				} else {
1325
					$output[] = '<a href="' . $ancestor['link'] . '">' . apply_filters( 'the_title', $ancestor['title'] ) . '</a>';
1326
				}
1327
				$cnt++;
1328
			}
1329
			$output = implode( esc_html( $this->settings['disp']['bc_joint_string'] ), $output );
1330
		} else {
1331
			$output = '<ul id="bread_crumb">' . "\n";
1332
			$cnt = 1;
1333
			foreach ( $bread_crumb_arr as $ancestor ) {
1334
	            $classes = array();
1335
	            $classes[] = 'bc_level-' . $cnt;
1336
	            if ( $cnt == 1 ) {
1337
	                $classes[] = 'bc_top';
1338
	            } else {
1339
	                $classes[] = 'bc_sub';
1340
	            }    
1341
	            if ( $cnt == count( $bread_crumb_arr ) ) {
1342
	                $classes[] = 'tail';
1343
	                $output .= '    <li class="' . implode( ' ', $classes ) . '">' . apply_filters( 'the_title', $ancestor['title'] ) . '</li>' . "\n";
1344
	            } elseif( $ancestor['no_link'] === true ){
1345
	                $output .= '    <li class="' . implode( ' ', $classes ) . '">' . apply_filters( 'the_title', $ancestor['title'] ) . '</li>' . "\n";
1346
	            } else {
1347
	                $output .= '    <li class="' . implode( ' ', $classes ) . '"><a href="' . $ancestor['link'] . '" '. $ancestor['target'] .'>' . apply_filters( 'the_title', $ancestor['title'] ) . '</a></li>' . "\n";
1348
	            }    
1349
	            $cnt++;
1350
			}
1351
			$output .= '</ul>' . "\n";
1352
		}
1353
		
1354
		if ( $echo ) {
1355
			echo $output;
1356
		} else {
1357
			return $output;
1358
		}
1359
	}
1360
	
1361
	function get_category_ancestors( $cat_id, $ancestors = array() ) {
1362
		$cat = get_category( $cat_id );
1363
		$ancestors[] = $cat;
1364
		if ( $cat->parent != 0 ) {
1365
			$ancestors = $this->get_category_ancestors( $cat->parent, $ancestors );
1366
		}
1367
		return $ancestors;
1368
	}
1369
	
1370
}//class end
1371
1372
$ps_multi_languages = new ps_multi_languages( );
1373
1374
if ( isset($ps_multi_languages ) ){
1375
	include_once ( MULTI_LANGUAGES_DIR . '/config/functions.php' );
1376
}
1377
?>