PluginProbe
Bogo / 2.4
Bogo v2.4
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
← All changes | admin/includes/post.php +143 -202 2.92.4 View file →
@@ -10,11 +10,10 @@
10 10
11 11 add_filter( 'manage_posts_columns', 'bogo_posts_columns', 10, 2 );
12 12
13 13 function bogo_posts_columns( $posts_columns, $post_type ) {
14 - if ( ! bogo_is_localizable_post_type( $post_type ) ) {
14 + if ( ! bogo_is_localizable_post_type( $post_type ) )
15 15 return $posts_columns;
16 - }
17 16
18 17 if ( ! isset( $posts_columns['locale'] ) ) {
19 18 $posts_columns = array_merge(
20 19 array_slice( $posts_columns, 0, 3 ),
@@ -24,35 +23,29 @@
24 23
25 24 return $posts_columns;
26 25 }
27 26
28 -add_action( 'manage_pages_custom_column',
29 - 'bogo_manage_posts_custom_column', 10, 2 );
30 -add_action( 'manage_posts_custom_column',
31 - 'bogo_manage_posts_custom_column', 10, 2 );
27 +add_action( 'manage_pages_custom_column', 'bogo_manage_posts_custom_column', 10, 2 );
28 +add_action( 'manage_posts_custom_column', 'bogo_manage_posts_custom_column', 10, 2 );
32 29
33 30 function bogo_manage_posts_custom_column( $column_name, $post_id ) {
34 - if ( 'locale' != $column_name ) {
31 + $post_type = get_post_type( $post_id );
32 +
33 + if ( ! bogo_is_localizable_post_type( $post_type ) )
35 34 return;
36 - }
37 35
38 - $post_type = get_post_type( $post_id );
39 -
40 - if ( ! bogo_is_localizable_post_type( $post_type ) ) {
36 + if ( 'locale' != $column_name )
41 37 return;
42 - }
43 38
44 39 $locale = get_post_meta( $post_id, '_locale', true );
45 40
46 - if ( empty( $locale ) ) {
41 + if ( empty( $locale ) )
47 42 return;
48 - }
49 43
50 44 $language = bogo_get_language( $locale );
51 45
52 - if ( empty( $language ) ) {
46 + if ( empty( $language ) )
53 47 $language = $locale;
54 - }
55 48
56 49 echo sprintf( '<a href="%1$s">%2$s</a>',
57 50 esc_url( add_query_arg(
58 51 array( 'post_type' => $post_type, 'lang' => $locale ),
@@ -92,105 +85,65 @@
92 85 add_filter( 'post_row_actions', 'bogo_post_row_actions', 10, 2 );
93 86 add_filter( 'page_row_actions', 'bogo_post_row_actions', 10, 2 );
94 87
95 88 function bogo_post_row_actions( $actions, $post ) {
96 - if ( ! bogo_is_localizable_post_type( $post->post_type ) ) {
89 + if ( ! bogo_is_localizable_post_type( $post->post_type ) )
97 90 return $actions;
98 - }
99 91
100 92 $post_type_object = get_post_type_object( $post->post_type );
101 93
102 94 if ( ! current_user_can( $post_type_object->cap->edit_post, $post->ID )
103 - || 'trash' == $post->post_status ) {
95 + || 'trash' == $post->post_status )
104 96 return $actions;
105 - }
106 97
107 98 $user_locale = bogo_get_user_locale();
108 99 $post_locale = bogo_get_post_locale( $post->ID );
109 100
110 - if ( $user_locale == $post_locale ) {
101 + if ( $user_locale == $post_locale )
111 102 return $actions;
112 - }
113 103
114 - if ( $translation = bogo_get_post_translation( $post, $user_locale ) ) {
115 - if ( empty( $translation->ID ) || $translation->ID == $post->ID ) {
104 + $translations = bogo_get_post_translations( $post );
105 +
106 + if ( ! empty( $translations[$user_locale] ) ) {
107 + $translation = $translations[$user_locale];
108 +
109 + if ( empty( $translation->ID ) || $translation->ID == $post->ID )
116 110 return $actions;
117 - }
118 111
112 + $title = __( 'Edit %s translation of this item', 'bogo' );
119 113 $text = __( 'Edit %s translation', 'bogo' );
114 +
120 115 $edit_link = get_edit_post_link( $translation->ID );
116 +
121 117 } else {
118 + $title = __( 'Translate this item into %s', 'bogo' );
122 119 $text = __( 'Translate into %s', 'bogo' );
120 +
123 121 $edit_link = admin_url( 'post-new.php?post_type=' . $post->post_type
124 - . '&action=bogo-add-translation'
125 122 . '&locale=' . $user_locale
126 123 . '&original_post=' . $post->ID );
127 - $edit_link = wp_nonce_url( $edit_link, 'bogo-add-translation' );
128 124 }
129 125
130 126 $language = bogo_get_language( $user_locale );
131 127
132 - if ( empty( $language ) ) {
128 + if ( empty( $language ) )
133 129 $language = $user_locale;
134 - }
135 130
136 - $actions['translate'] = sprintf(
137 - '<a href="%1$s">%2$s</a>',
138 - $edit_link,
139 - esc_html( sprintf( $text, $language ) ) );
131 + $actions['translate'] = '<a title="' . esc_attr( sprintf( $title, $language ) ) . '" href="' . $edit_link . '">' . esc_html( sprintf( $text, $language ) ) . '</a>';
140 132
141 133 return $actions;
142 134 }
143 135
144 -add_action( 'admin_init', 'bogo_add_translation' );
145 -
146 -function bogo_add_translation() {
147 - if ( empty( $_REQUEST['action'] )
148 - || 'bogo-add-translation' != $_REQUEST['action'] ) {
149 - return;
150 - }
151 -
152 - check_admin_referer( 'bogo-add-translation' );
153 -
154 - $locale = isset( $_REQUEST['locale'] ) ? $_REQUEST['locale'] : '';
155 - $original_post = isset( $_REQUEST['original_post'] )
156 - ? absint( $_REQUEST['original_post'] ) : 0;
157 -
158 - if ( ! bogo_is_available_locale( $locale )
159 - || ! current_user_can( 'bogo_access_locale', $locale ) ) {
160 - return;
161 - }
162 -
163 - if ( ! $original_post || ! $original_post = get_post( $original_post ) ) {
164 - return;
165 - }
166 -
167 - $post_type_object = get_post_type_object( $original_post->post_type );
168 -
169 - if ( $post_type_object
170 - && current_user_can( $post_type_object->cap->edit_posts ) ) {
171 - $new_post_id = bogo_duplicate_post( $original_post, $locale );
172 -
173 - if ( $new_post_id ) {
174 - $redirect_to = get_edit_post_link( $new_post_id, 'raw' );
175 - wp_safe_redirect( $redirect_to );
176 - exit();
177 - }
178 - }
179 -}
180 -
181 136 /* Single Post */
182 137
183 138 add_action( 'add_meta_boxes', 'bogo_add_l10n_meta_boxes', 10, 2 );
184 139
185 140 function bogo_add_l10n_meta_boxes( $post_type, $post ) {
186 - if ( ! bogo_is_localizable_post_type( $post_type ) ) {
141 + if ( ! bogo_is_localizable_post_type( $post_type ) )
187 142 return;
188 - }
189 143
190 - if ( in_array( $post_type, array( 'comment', 'link' ) ) ) {
144 + if ( in_array( $post_type, array( 'comment', 'link' ) ) )
191 145 return;
192 - }
193 146
194 147 add_meta_box( 'bogol10ndiv', __( 'Language', 'bogo' ),
195 148 'bogo_l10n_meta_box', null, 'side', 'high' );
196 149 }
@@ -198,174 +151,165 @@
198 151 function bogo_l10n_meta_box( $post ) {
199 152 $initial = ( 'auto-draft' == $post->post_status );
200 153
201 154 if ( $initial ) {
202 - $post_locale = isset( $_REQUEST['locale'] ) ? $_REQUEST['locale'] : '';
155 + $locale = isset( $_REQUEST['locale'] ) ? $_REQUEST['locale'] : '';
203 156
204 - if ( ! bogo_is_available_locale( $post_locale ) ) {
205 - $post_locale = bogo_get_user_locale();
206 - }
157 + if ( ! bogo_is_available_locale( $locale ) )
158 + $locale = bogo_get_user_locale();
207 159
208 - $original_post = empty( $_REQUEST['original_post'] )
209 - ? '' : $_REQUEST['original_post'];
160 + $original_post = empty( $_REQUEST['original_post'] ) ? '' : $_REQUEST['original_post'];
210 161 } else {
211 - $post_locale = bogo_get_post_locale( $post->ID );
162 + $locale = bogo_get_post_locale( $post->ID );
212 163 $original_post = get_post_meta( $post->ID, '_original_post', true );
213 164
214 - if ( empty( $original_post ) ) {
165 + if ( empty( $original_post ) )
215 166 $original_post = $post->ID;
216 - }
217 167 }
218 168
219 - $translations = bogo_get_post_translations( $post->ID );
220 - $available_locales = bogo_available_locales( array(
221 - 'exclude' => array_merge(
222 - array( $post_locale ),
223 - array_keys( (array) $translations ) ),
224 - 'exclude_enus_if_inactive' => true,
225 - 'current_user_can_access' => true ) );
169 + $lang = bogo_get_language( $locale );
170 +
171 + if ( empty( $lang ) )
172 + $lang = $locale;
173 +
226 174 ?>
227 175 <div class="hidden">
228 -<input type="hidden" name="locale" value="<?php echo esc_attr( $post_locale ); ?>" />
176 +<input type="hidden" name="locale" value="<?php echo esc_attr( $locale ); ?>" />
229 177 <input type="hidden" name="original_post" value="<?php echo esc_attr( $original_post ); ?>" />
230 178 </div>
231 179
232 180 <div class="descriptions">
233 -<?php
234 - $lang = bogo_get_language( $post_locale );
235 - $lang = empty( $lang ) ? $post_locale : $lang;
236 -?>
237 181 <p><strong><?php echo esc_html( __( 'Language', 'bogo' ) ); ?>:</strong>
238 182 <?php echo esc_html( $lang ); ?></p>
239 183 </div>
240 184
241 185 <?php
242 - do {
243 - if ( ! $translations && ( $initial || empty( $available_locales ) ) ) {
244 - break;
245 - }
186 + bogo_metabox_translations( $post );
187 + bogo_metabox_add_translation( $post );
188 +}
246 189
247 - echo '<div class="descriptions">';
248 - echo sprintf( '<p><strong>%s:</strong></p>',
249 - esc_html( __( 'Translations', 'bogo' ) ) );
250 - echo '<ul id="bogo-translations">';
190 +function bogo_metabox_translations( $post ) {
191 + $translations = bogo_get_post_translations( $post->ID );
251 192
252 - if ( $translations ) {
253 - foreach ( $translations as $locale => $translation ) {
254 - $edit_link = get_edit_post_link( $translation->ID );
255 - echo '<li>';
193 + if ( empty( $translations ) )
194 + return;
256 195
257 - if ( $edit_link ) {
258 - echo sprintf( '<a href="%1$s" target="_blank">%2$s</a>',
259 - esc_url( $edit_link ), get_the_title( $translation->ID ) );
260 - } else {
261 - echo get_the_title( $translation->ID );
262 - }
196 +?>
197 +<p><strong><?php echo esc_html( __( 'Translations', 'bogo' ) ); ?>:</strong></p>
263 198
264 - $lang = bogo_get_language( $locale );
265 - $lang = empty( $lang ) ? $locale : $lang;
266 - echo ' [' . $lang . ']';
267 - echo '</li>';
268 - }
269 - }
199 +<ul style="list-style: disc inside; margin-left: 1em;">
200 +<?php
201 + foreach ( $translations as $locale => $translation ) {
202 + $edit_link = get_edit_post_link( $translation->ID );
270 203
271 - echo '</ul>';
272 - echo '</div>';
273 - } while (0);
204 + echo '<li>';
274 205
275 - do {
276 - if ( $initial || empty( $available_locales ) ) {
277 - break;
278 - }
206 + if ( $edit_link )
207 + echo '<a href="' . esc_url( $edit_link ) . '" target="_blank">' . get_the_title( $translation->ID ) . '</a>';
208 + else
209 + echo get_the_title( $translation->ID );
279 210
280 - echo '<div id="bogo-add-translation-actions" class="descriptions">';
281 - echo sprintf( '<p><strong>%s:</strong></p>',
282 - esc_html( __( 'Add Translation', 'bogo' ) ) );
283 - echo '<select id="bogo-translations-to-add">';
211 + $lang = bogo_get_language( $locale );
284 212
285 - foreach ( $available_locales as $locale ) {
286 - $lang = bogo_get_language( $locale );
287 - $lang = empty( $lang ) ? $locale : $lang;
288 - echo sprintf( '<option value="%1$s">%2$s</option>',
289 - esc_attr( $locale ), esc_html( $lang ) );
290 - }
213 + if ( empty( $lang ) )
214 + $lang = $locale;
291 215
292 - echo '</select>';
293 - echo '<p>';
294 - echo sprintf(
295 - '<button type="button" class="button" id="%1$s">%2$s</button>',
296 - 'bogo-add-translation',
297 - esc_html( __( 'Add Translation', 'bogo' ) ) );
298 - echo '<span class="spinner"></span>';
299 - echo '</p>';
300 - echo '<div class="clear"></div>';
301 - echo '</div>';
302 - } while (0);
216 + echo ' [' . $lang . ']';
217 + echo '</li>';
218 + }
219 +?>
220 +</ul>
221 +<?php
303 222 }
304 223
305 -add_action( 'save_post', 'bogo_save_post', 10, 2 );
224 +function bogo_metabox_add_translation( $post ) {
225 + if ( 'auto-draft' == $post->post_status )
226 + return;
306 227
307 -function bogo_save_post( $post_id, $post ) {
308 - if ( did_action( 'import_start' ) && ! did_action( 'import_end' ) ) {
309 - // Importing
228 + $post_locale = bogo_get_post_locale( $post->ID );
229 + $user_locale = bogo_get_user_locale();
230 +
231 + if ( $post_locale == $user_locale )
310 232 return;
233 +
234 + $locale = $user_locale;
235 +
236 + $translations = bogo_get_post_translations( $post->ID );
237 +
238 + if ( isset( $translations[$locale] ) )
239 + return;
240 +
241 + $lang = bogo_get_language( $locale );
242 +
243 + if ( empty( $lang ) )
244 + $lang = $locale;
245 +
246 + $edit_link = admin_url( 'post-new.php?post_type=' . $post->post_type
247 + . '&locale=' . $locale
248 + . '&original_post=' . $post->ID );
249 +
250 +?>
251 +<p class="textright"><a href="<?php echo $edit_link; ?>" target="_blank" class="button"><?php echo esc_html( sprintf( __( 'Add %s translation', 'bogo' ), $lang ) ) ?></a></p>
252 +<?php
253 +}
254 +
255 +add_filter( 'default_title', 'bogo_translation_default', 10, 2 );
256 +add_filter( 'default_content', 'bogo_translation_default', 10, 2 );
257 +add_filter( 'default_excerpt', 'bogo_translation_default', 10, 2 );
258 +
259 +function bogo_translation_default( $value, $post ) {
260 + if ( ! empty( $value )
261 + || empty( $_REQUEST['original_post'] )
262 + || ! $original = get_post( $_REQUEST['original_post'] ) ) {
263 + return $value;
311 264 }
312 265
313 - if ( ! bogo_is_localizable_post_type( $post->post_type ) ) {
314 - return;
266 + if ( 'default_title' == current_filter() ) {
267 + $value = $original->post_title;
268 + } elseif ( 'default_content' == current_filter() ) {
269 + $value = $original->post_content;
270 + } elseif ( 'default_excerpt' == current_filter() ) {
271 + $value = $original->post_excerpt;
315 272 }
316 273
317 - $current_locales = get_post_meta( $post_id, '_locale' );
318 - $locale = null;
274 + return $value;
275 +}
319 276
320 - if ( ! empty( $current_locales ) ) {
321 - foreach ( $current_locales as $current_locale ) {
322 - if ( bogo_is_available_locale( $current_locale ) ) {
323 - $locale = $current_locale;
324 - break;
325 - }
326 - }
277 +add_action( 'save_post', 'bogo_save_post', 10, 2 );
327 278
328 - if ( empty( $locale ) || 1 < count( $current_locales ) ) {
329 - delete_post_meta( $post_id, '_locale' );
330 - $current_locales = array();
331 - }
332 - }
279 +function bogo_save_post( $post_id, $post ) {
280 + if ( did_action( 'import_start' ) && ! did_action( 'import_end' ) ) // Importing
281 + return;
333 282
334 - if ( empty( $current_locales ) ) {
335 - if ( bogo_is_available_locale( $locale ) ) {
336 - // $locale = $locale;
337 - } elseif ( ! empty( $_REQUEST['locale'] )
338 - && bogo_is_available_locale( $_REQUEST['locale'] ) ) {
283 + if ( ! bogo_is_localizable_post_type( $post->post_type ) )
284 + return;
285 +
286 + $old_locale = get_post_meta( $post_id, '_locale', true );
287 +
288 + if ( empty( $old_locale ) ) {
289 + if ( ! empty( $_REQUEST['locale'] ) && bogo_is_available_locale( $_REQUEST['locale'] ) )
339 290 $locale = $_REQUEST['locale'];
340 - } elseif ( 'auto-draft' == get_post_status( $post_id ) ) {
291 + elseif ( 'auto-draft' == get_post_status( $post_id ) )
341 292 $locale = bogo_get_user_locale();
342 - } else {
293 + else
343 294 $locale = bogo_get_default_locale();
344 - }
345 -
346 - add_post_meta( $post_id, '_locale', $locale, true );
347 295 }
348 296
349 - $current_original_posts = get_post_meta( $post_id, '_original_post' );
297 + if ( ! empty( $locale ) && $locale != $old_locale )
298 + update_post_meta( $post_id, '_locale', $locale );
299 + else
300 + $locale = $old_locale;
350 301
351 - if ( ! empty( $current_original_posts ) ) {
352 - if ( 1 < count( $current_original_posts ) ) {
353 - delete_post_meta( $post_id, '_original_post' );
354 - } else {
355 - return;
356 - }
357 - }
302 + if ( $original = get_post_meta( $post_id, '_original_post', true ) )
303 + return;
358 304
359 305 if ( ! empty( $_REQUEST['original_post'] ) ) {
360 - $original = get_post_meta( $_REQUEST['original_post'],
361 - '_original_post', true );
306 + $original = get_post_meta( $_REQUEST['original_post'], '_original_post', true );
362 307
363 - if ( empty( $original ) ) {
308 + if ( empty( $original ) )
364 309 $original = (int) $_REQUEST['original_post'];
365 - }
366 310
367 - add_post_meta( $post_id, '_original_post', $original, true );
311 + update_post_meta( $post_id, '_original_post', $original );
368 312 return;
369 313 }
370 314
371 315 $original = $post_id;
@@ -381,9 +325,9 @@
381 325 'meta_key' => '_original_post',
382 326 'meta_value' => $original ) );
383 327
384 328 if ( empty( $posts ) ) {
385 - add_post_meta( $post_id, '_original_post', $original, true );
329 + update_post_meta( $post_id, '_original_post', $original );
386 330 return;
387 331 }
388 332
389 333 $original += 1;
@@ -394,23 +338,20 @@
394 338
395 339 function bogo_unique_post_slug( $slug, $post_id, $status, $type, $parent, $original ) {
396 340 global $wp_rewrite;
397 341
398 - if ( ! bogo_is_localizable_post_type( $type ) ) {
342 + if ( ! bogo_is_localizable_post_type( $type ) )
399 343 return $slug;
400 - }
401 344
402 345 $feeds = is_array( $wp_rewrite->feeds ) ? $wp_rewrite->feeds : array();
403 346
404 - if ( in_array( $original, $feeds ) ) {
347 + if ( in_array( $original, $feeds ) )
405 348 return $slug;
406 - }
407 349
408 - $locale = bogo_get_post_locale( $post_id );
350 + $locale = get_post_meta( $post_id, '_locale', true );
409 351
410 - if ( empty( $locale ) ) {
352 + if ( empty( $locale ) )
411 353 return $slug;
412 - }
413 354
414 355 $args = array(
415 356 'posts_per_page' => 1,
416 357 'post__not_in' => array( $post_id ),
@@ -420,11 +361,10 @@
420 361
421 362 $hierarchical = in_array( $type, get_post_types( array( 'hierarchical' => true ) ) );
422 363
423 364 if ( $hierarchical ) {
424 - if ( preg_match( "@^($wp_rewrite->pagination_base)?\d+$@", $original ) ) {
365 + if ( preg_match( "@^($wp_rewrite->pagination_base)?\d+$@", $original ) )
425 366 return $slug;
426 - }
427 367
428 368 $args['post_parent'] = $parent;
429 369 }
430 370
@@ -430,10 +370,11 @@
430 370
431 371 $q = new WP_Query();
432 372 $posts = $q->query( $args );
433 373
434 - if ( empty( $posts ) ) {
374 + if ( empty( $posts ) )
435 375 $slug = $original;
436 - }
437 376
438 377 return $slug;
439 378 }
379 +
380 +?>