PluginProbe
Bogo / 2.7
Bogo v2.7
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 2.7, at bogo.php

133 lines 3.7 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: 2.7
11 */
12
13 define( 'BOGO_VERSION', '2.7' );
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/rewrite.php';
25 require_once BOGO_PLUGIN_DIR . '/includes/link-template.php';
26 require_once BOGO_PLUGIN_DIR . '/includes/language-switcher.php';
27 require_once BOGO_PLUGIN_DIR . '/includes/nav-menu.php';
28 require_once BOGO_PLUGIN_DIR . '/includes/widgets.php';
29 require_once BOGO_PLUGIN_DIR . '/includes/post.php';
30 require_once BOGO_PLUGIN_DIR . '/includes/user.php';
31 require_once BOGO_PLUGIN_DIR . '/includes/capabilities.php';
32 require_once BOGO_PLUGIN_DIR . '/includes/query.php';
33 require_once BOGO_PLUGIN_DIR . '/includes/flags.php';
34
35 if ( is_admin() ) {
36 require_once BOGO_PLUGIN_DIR . '/admin/admin.php';
37 }
38
39 add_action( 'plugins_loaded', 'bogo_plugins_loaded' );
40
41 function bogo_plugins_loaded() {
42 load_plugin_textdomain( 'bogo', 'wp-content/plugins/bogo/languages', 'bogo/languages' );
43 }
44
45 add_action( 'init', 'bogo_init' );
46
47 function bogo_init() {
48 bogo_languages();
49
50 if ( ! ( is_admin() || is_robots() || is_feed() || is_trackback() ) ) {
51 $locale = get_locale();
52
53 if ( ! isset( $_COOKIE['lang'] ) || $_COOKIE['lang'] != $locale )
54 setcookie( 'lang', $locale, 0, '/' );
55 }
56 }
57
58 add_filter( 'locale', 'bogo_locale' );
59
60 function bogo_locale( $locale ) {
61 global $wp_rewrite, $wp_query;
62
63 if ( ! did_action( 'plugins_loaded' ) )
64 return $locale;
65
66 if ( is_admin() )
67 return bogo_get_user_locale();
68
69 $default_locale = bogo_get_default_locale();
70
71 if ( ! empty( $wp_query->query_vars ) ) {
72 if ( ( $lang = get_query_var( 'lang' ) ) && $closest = bogo_get_closest_locale( $lang ) )
73 return $closest;
74 else
75 return $default_locale;
76 }
77
78 if ( isset( $wp_rewrite ) && $wp_rewrite->using_permalinks() ) {
79 $url = is_ssl() ? 'https://' : 'http://';
80 $url .= $_SERVER['HTTP_HOST'];
81 $url .= $_SERVER['REQUEST_URI'];
82
83 $home = set_url_scheme( get_option( 'home' ) );
84 $home = trailingslashit( $home );
85
86 $available_languages = bogo_available_languages();
87 $available_languages = array_map( 'bogo_lang_slug', array_keys( $available_languages ) );
88 $available_languages = implode( '|', $available_languages );
89 $pattern = '#^' . preg_quote( $home ) . '(' . $available_languages . ')(/|$)#';
90
91 if ( preg_match( $pattern, $url, $matches )
92 && $closest = bogo_get_closest_locale( $matches[1] ) )
93 return $closest;
94 }
95
96 $lang = bogo_get_lang_from_url();
97
98 if ( $lang && $closest = bogo_get_closest_locale( $lang ) )
99 return $closest;
100
101 $locale = $default_locale;
102
103 return $locale;
104 }
105
106 add_filter( 'query_vars', 'bogo_query_vars' );
107
108 function bogo_query_vars( $query_vars ) {
109 $query_vars[] = 'lang';
110
111 return $query_vars;
112 }
113
114 add_action( 'wp_enqueue_scripts', 'bogo_enqueue_scripts' );
115
116 function bogo_enqueue_scripts() {
117 wp_enqueue_style( 'bogo',
118 plugins_url( 'includes/css/style.css', BOGO_PLUGIN_BASENAME ),
119 array(), BOGO_VERSION, 'all' );
120
121 if ( is_rtl() ) {
122 wp_enqueue_style( 'bogo-rtl',
123 plugins_url( 'includes/css/style-rtl.css', BOGO_PLUGIN_BASENAME ),
124 array(), BOGO_VERSION, 'all' );
125 }
126 }
127
128 add_action( 'deactivate_' . BOGO_PLUGIN_BASENAME, 'bogo_deactivate' );
129
130 function bogo_deactivate() {
131 bogo_delete_prop( 'lang_rewrite_regex' );
132 }
133