PluginProbe
Bogo / 3.0
Bogo v3.0
3.9.3 trunk 1.0 1.1 2.0 2.0.1 2.1 2.1.1 2.1.2 2.1.3 2.2 2.3 2.4 2.4.1 2.4.2 2.4.3 2.5 2.6 2.6.1 2.7 2.8 2.8.1 2.9 3.0 3.0.1 All 52 releases
bogo / bogo.php

bogo.php in Bogo 3.0, at bogo.php

147 lines 4.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Plugin Name: Bogo
4 Description: A straight-forward multilingual plugin. No more double-digit custom DB tables or hidden HTML comments that could cause you headaches later on.
5 Plugin URI: http://ideasilo.wordpress.com/bogo/
6 Author: Takayuki Miyoshi
7 Author URI: http://ideasilo.wordpress.com/
8 Text Domain: bogo
9 Domain Path: /languages/
10 Version: 3.0
11 */
12
13 define( 'BOGO_VERSION', '3.0' );
14
15 define( 'BOGO_PLUGIN', __FILE__ );
16
17 define( 'BOGO_PLUGIN_BASENAME', plugin_basename( BOGO_PLUGIN ) );
18
19 define( 'BOGO_PLUGIN_NAME', trim( dirname( BOGO_PLUGIN_BASENAME ), '/' ) );
20
21 define( 'BOGO_PLUGIN_DIR', untrailingslashit( dirname( BOGO_PLUGIN ) ) );
22
23 require_once BOGO_PLUGIN_DIR . '/includes/functions.php';
24 require_once BOGO_PLUGIN_DIR . '/includes/pomo.php';
25 require_once BOGO_PLUGIN_DIR . '/includes/rewrite.php';
26 require_once BOGO_PLUGIN_DIR . '/includes/link-template.php';
27 require_once BOGO_PLUGIN_DIR . '/includes/language-switcher.php';
28 require_once BOGO_PLUGIN_DIR . '/includes/nav-menu.php';
29 require_once BOGO_PLUGIN_DIR . '/includes/widgets.php';
30 require_once BOGO_PLUGIN_DIR . '/includes/post.php';
31 require_once BOGO_PLUGIN_DIR . '/includes/user.php';
32 require_once BOGO_PLUGIN_DIR . '/includes/capabilities.php';
33 require_once BOGO_PLUGIN_DIR . '/includes/query.php';
34 require_once BOGO_PLUGIN_DIR . '/includes/flags.php';
35 require_once BOGO_PLUGIN_DIR . '/includes/rest-api.php';
36
37 if ( is_admin() ) {
38 require_once BOGO_PLUGIN_DIR . '/admin/admin.php';
39 }
40
41 add_action( 'plugins_loaded', 'bogo_plugins_loaded' );
42
43 function bogo_plugins_loaded() {
44 load_plugin_textdomain( 'bogo', 'wp-content/plugins/bogo/languages', 'bogo/languages' );
45 }
46
47 add_action( 'init', 'bogo_init' );
48
49 function bogo_init() {
50 bogo_languages();
51 Bogo_POMO::import( get_locale() );
52
53 if ( ! ( is_admin() || is_robots() || is_feed() || is_trackback() ) ) {
54 $locale = get_locale();
55
56 if ( ! isset( $_COOKIE['lang'] ) || $_COOKIE['lang'] != $locale ) {
57 setcookie( 'lang', $locale, 0, '/' );
58 }
59 }
60 }
61
62 add_filter( 'locale', 'bogo_locale' );
63
64 function bogo_locale( $locale ) {
65 global $wp_rewrite, $wp_query;
66
67 if ( ! did_action( 'plugins_loaded' ) ) {
68 return $locale;
69 }
70
71 static $bogo_locale = '';
72
73 if ( $bogo_locale ) {
74 return $bogo_locale;
75 }
76
77 if ( is_admin() ) {
78 return $bogo_locale = bogo_get_user_locale();
79 }
80
81 $default_locale = bogo_get_default_locale();
82
83 if ( ! empty( $wp_query->query_vars ) ) {
84 if ( ( $lang = get_query_var( 'lang' ) )
85 && $closest = bogo_get_closest_locale( $lang ) ) {
86 return $bogo_locale = $closest;
87 } else {
88 return $bogo_locale = $default_locale;
89 }
90 }
91
92 if ( isset( $wp_rewrite ) && $wp_rewrite->using_permalinks() ) {
93 $url = is_ssl() ? 'https://' : 'http://';
94 $url .= $_SERVER['HTTP_HOST'];
95 $url .= $_SERVER['REQUEST_URI'];
96
97 $home = set_url_scheme( get_option( 'home' ) );
98 $home = trailingslashit( $home );
99
100 $available_locales = bogo_available_locales();
101 $available_locales = array_map( 'bogo_lang_slug', $available_locales );
102 $available_locales = implode( '|', $available_locales );
103 $pattern = '#^' . preg_quote( $home ) . '(' . $available_locales . ')(/|$)#';
104
105 if ( preg_match( $pattern, $url, $matches )
106 && $closest = bogo_get_closest_locale( $matches[1] ) ) {
107 return $bogo_locale = $closest;
108 }
109 }
110
111 $lang = bogo_get_lang_from_url();
112
113 if ( $lang && $closest = bogo_get_closest_locale( $lang ) ) {
114 return $bogo_locale = $closest;
115 }
116
117 return $bogo_locale = $default_locale;
118 }
119
120 add_filter( 'query_vars', 'bogo_query_vars' );
121
122 function bogo_query_vars( $query_vars ) {
123 $query_vars[] = 'lang';
124
125 return $query_vars;
126 }
127
128 add_action( 'wp_enqueue_scripts', 'bogo_enqueue_scripts' );
129
130 function bogo_enqueue_scripts() {
131 wp_enqueue_style( 'bogo',
132 plugins_url( 'includes/css/style.css', BOGO_PLUGIN_BASENAME ),
133 array(), BOGO_VERSION, 'all' );
134
135 if ( is_rtl() ) {
136 wp_enqueue_style( 'bogo-rtl',
137 plugins_url( 'includes/css/style-rtl.css', BOGO_PLUGIN_BASENAME ),
138 array(), BOGO_VERSION, 'all' );
139 }
140 }
141
142 add_action( 'deactivate_' . BOGO_PLUGIN_BASENAME, 'bogo_deactivate' );
143
144 function bogo_deactivate() {
145 bogo_delete_prop( 'lang_rewrite_regex' );
146 }
147