PluginProbe
Bogo / 2.5
Bogo v2.5
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 / admin / admin.php

admin.php in Bogo 2.5, at admin/admin.php

196 lines 5.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 require_once BOGO_PLUGIN_DIR . '/admin/includes/user.php';
4 require_once BOGO_PLUGIN_DIR . '/admin/includes/post.php';
5 require_once BOGO_PLUGIN_DIR . '/admin/includes/nav-menu.php';
6 require_once BOGO_PLUGIN_DIR . '/admin/includes/widgets.php';
7
8 add_action( 'admin_enqueue_scripts', 'bogo_admin_enqueue_scripts' );
9
10 function bogo_admin_enqueue_scripts( $hook_suffix ) {
11 if ( false !== strpos( $hook_suffix, 'bogo-tools' )
12 || 'widgets.php' == $hook_suffix
13 || 'user-edit.php' == $hook_suffix ) {
14 wp_enqueue_style( 'bogo-admin',
15 plugins_url( 'admin/includes/css/admin.css', BOGO_PLUGIN_BASENAME ),
16 array(), BOGO_VERSION, 'all' );
17
18 return;
19 }
20
21 if ( 'nav-menus.php' == $hook_suffix ) {
22 $nav_menu_id = absint( get_user_option( 'nav_menu_recently_edited' ) );
23 $nav_menu_items = wp_get_nav_menu_items( $nav_menu_id );
24 $locales = array();
25
26 foreach ( (array) $nav_menu_items as $item ) {
27 $locales[$item->db_id] = $item->bogo_locales;
28 }
29
30 $prefix = 'menu-item-bogo-locale';
31
32 wp_enqueue_script( 'bogo-admin',
33 plugins_url( 'admin/includes/js/admin.js', BOGO_PLUGIN_BASENAME ),
34 array( 'jquery' ),
35 BOGO_VERSION, true );
36
37 wp_localize_script( 'bogo-admin', '_bogo', array(
38 'availableLanguages' => bogo_available_languages( 'orderby=value' ),
39 'locales' => $locales,
40 'selectorLegend' => __( 'Displayed on pages in', 'bogo' ),
41 'cbPrefix' => $prefix ) );
42
43 wp_enqueue_style( 'bogo-admin',
44 plugins_url( 'admin/includes/css/admin.css', BOGO_PLUGIN_BASENAME ),
45 array(), BOGO_VERSION, 'all' );
46
47 return;
48 }
49
50 if ( 'options-general.php' == $hook_suffix ) {
51 wp_enqueue_script( 'bogo-admin',
52 plugins_url( 'admin/includes/js/admin.js', BOGO_PLUGIN_BASENAME ),
53 array( 'jquery' ),
54 BOGO_VERSION, true );
55
56 wp_localize_script( 'bogo-admin', '_bogo', array(
57 'defaultLocale' => bogo_get_default_locale() ) );
58
59 return;
60 }
61 }
62
63 add_action( 'admin_menu', 'bogo_admin_menu' );
64
65 function bogo_admin_menu() {
66 $tools = add_management_page(
67 __( 'Bogo Tools', 'bogo' ), __( 'Bogo', 'bogo' ),
68 'update_core', 'bogo-tools', 'bogo_tools_page' );
69
70 add_action( 'load-' . $tools, 'bogo_load_tools_page' );
71 }
72
73 function bogo_load_tools_page() {
74 require_once( ABSPATH . 'wp-admin/includes/translation-install.php' );
75
76 $action = isset( $_GET['action'] ) ? $_GET['action'] : '';
77
78 if ( 'install_translation' == $action ) {
79 check_admin_referer( 'bogo-tools' );
80
81 if ( ! current_user_can( 'update_core' ) ) {
82 wp_die( __( 'You are not allowed to install translations.', 'bogo' ) );
83 }
84
85 $locale = isset( $_GET['locale'] ) ? $_GET['locale'] : null;
86
87 if ( wp_download_language_pack( $locale ) ) {
88 $redirect_to = add_query_arg(
89 array( 'locale' => $locale, 'message' => 'success' ),
90 menu_page_url( 'bogo-tools', false ) );
91 } else {
92 $redirect_to = add_query_arg(
93 array( 'locale' => $locale, 'message' => 'failed' ),
94 menu_page_url( 'bogo-tools', false ) );
95 }
96
97 wp_safe_redirect( $redirect_to );
98 exit();
99 }
100 }
101
102 function bogo_tools_page() {
103 $message = "";
104
105 if ( isset( $_GET['message'] ) ) {
106 if ( 'success' == $_GET['message'] ) {
107 $message = __( "Translation installed successfully.", 'bogo' );
108 } elseif ( 'failed' == $_GET['message'] ) {
109 $message = __( "Translation install failed.", 'bogo' );
110 }
111 }
112
113 $default_locale = bogo_get_default_locale();
114 $available_locales = bogo_available_locales();
115
116 ?>
117 <div class="wrap">
118
119 <h2><?php echo esc_html( __( 'Bogo Tools', 'bogo' ) ); ?></h2>
120
121 <?php if ( ! empty( $message ) ) : ?>
122 <div id="message" class="updated"><p><?php echo esc_html( $message ); ?></p></div>
123 <?php endif; ?>
124
125 <h3 class="title"><?php echo esc_html( __( 'Available Languages', 'bogo' ) ); ?></h3>
126
127 <table id="bogo-languages-table" class="widefat">
128 <thead>
129 <tr><th></th><th><?php echo esc_html( __( 'Language', 'bogo' ) ); ?></th></tr>
130 </thead>
131 <tfoot>
132 <tr><th></th><th><?php echo esc_html( __( 'Language', 'bogo' ) ); ?></th></tr>
133 </tfoot>
134 <tbody id="translations">
135 <tr><th>1</th><td><p>
136 <strong><?php echo esc_html( bogo_get_language( $default_locale ) ); ?></strong>
137 [<?php echo esc_html( $default_locale ); ?>]
138 <br /><?php echo esc_html( __( 'Site Default Language', 'bogo' ) ); ?>
139 </p></td></tr>
140
141 <?php
142 $count = 1;
143
144 foreach ( $available_locales as $locale ) {
145 if ( $locale == $default_locale ) {
146 continue;
147 }
148
149 $count += 1;
150 ?>
151 <tr><th><?php echo $count; ?></th><td><p>
152 <strong><?php echo esc_html( bogo_get_language( $locale ) ); ?></strong>
153 [<?php echo esc_html( $locale ); ?>]
154 <br /><?php echo esc_html( __( 'Installed', 'bogo' ) ); ?>
155 </p></td></tr>
156 <?php
157 }
158
159 $can_install = wp_can_install_language_pack();
160
161 foreach ( wp_get_available_translations() as $locale => $translation ) {
162 if ( in_array( $locale, $available_locales ) ) {
163 continue;
164 }
165
166 $count += 1;
167
168 $install_link = '';
169
170 if ( $can_install ) {
171 $install_link = menu_page_url( 'bogo-tools', false );
172 $install_link = add_query_arg(
173 array( 'action' => 'install_translation', 'locale' => $locale ),
174 $install_link );
175 $install_link = wp_nonce_url( $install_link, 'bogo-tools' );
176 $install_link = sprintf( '<a href="%1$s" class="install">%2$s</a>',
177 $install_link, esc_html( __( 'Install', 'bogo' ) ) );
178 }
179 ?>
180 <tr><th><?php echo $count; ?></th><td><p>
181 <strong><?php echo esc_html( bogo_get_language( $locale ) ); ?></strong>
182 [<?php echo esc_html( $locale ); ?>]
183 <?php echo $install_link; ?>
184 </p></td></tr>
185 <?php
186 }
187 ?>
188
189 </tbody>
190 </table>
191
192 </div>
193 <?php
194 }
195
196 ?>