Ejemplo n.º 1
0
 /**
  * undocumented function
  *
  * @return void
  **/
 protected function populate_links()
 {
     if (is_array($this->links) && !empty($this->links)) {
         return;
     }
     // Already done
     $this->links = array();
     // @FIXME: Not sure this is the best way to specify languages
     $alt_langs = bbl_get_active_langs();
     $this->screen = is_admin() ? get_current_screen() : false;
     // Create a handy flag for whether we're editing a post or listing posts
     $editing_post = false;
     $listing_posts = false;
     if (is_admin()) {
         $editing_post = is_admin() && 'post' == $this->screen->base && isset($_GET['post']);
         $listing_posts = is_admin() && 'edit' == $this->screen->base && !isset($_GET['post']);
     }
     // Create a handy flag for whether we're editing a term or listing terms
     $editing_term = false;
     $listing_terms = false;
     if (is_admin()) {
         $editing_term = is_admin() && 'edit-tags' == $this->screen->base && isset($_GET['tag_ID']);
         $listing_terms = is_admin() && 'edit-tags' == $this->screen->base && !isset($_GET['tag_ID']);
     }
     if (is_singular() || is_single() || $editing_post) {
         $this->translations = bbl_get_post_translations(get_the_ID());
         $this->jobs = bbl_get_incomplete_post_jobs(get_the_ID());
     } else {
         if ('page' == get_option('show_on_front') && is_home()) {
             $this->translations = bbl_get_post_translations(get_option('page_for_posts'));
             $this->jobs = bbl_get_incomplete_post_jobs(get_option('page_for_posts'));
         } else {
             if ((!is_admin() and is_tax() || is_category()) || $editing_term) {
                 if (isset($_REQUEST['tag_ID'])) {
                     $term = get_term((int) @$_REQUEST['tag_ID'], $this->screen->taxonomy);
                 } else {
                     $term = get_queried_object();
                 }
                 $this->translations = bbl_get_term_translations($term->term_id, $term->taxonomy);
                 $this->jobs = bbl_get_term_jobs($term->term_id, $term->taxonomy);
             }
         }
     }
     foreach ($alt_langs as $i => &$alt_lang) {
         // @TODO: Convert to a switch statement, convert all the vars to a single property on the class
         if (is_admin()) {
             if ($editing_post) {
                 // Admin: Editing post link
                 $this->add_admin_post_link($alt_lang);
             } else {
                 if ($editing_term) {
                     // Admin: Editing term link
                     $this->add_admin_term_link($alt_lang);
                 } else {
                     if ($listing_posts) {
                         // Admin: Listing posts link
                         $this->add_admin_list_posts_link($alt_lang);
                     } else {
                         if ($listing_terms) {
                             // Admin: Listing terms link
                             $this->add_admin_list_terms_link($alt_lang);
                         } else {
                             // Admin: Generic link link
                             $this->add_admin_generic_link($alt_lang);
                         }
                     }
                 }
             }
             continue;
         }
         if (is_singular() || is_single() || 'page' == get_option('show_on_front') && is_home()) {
             // Single posts, pages, blog homepage
             $this->add_post_link($alt_lang);
             continue;
         }
         // Don't add a switcher link if the language is not public and
         // the user cannot edit any posts (as a rough guide to whether
         // they are more than just a subscriber).
         // @TODO this cap check should move into each add_*_link() method:
         if (!bbl_is_public_lang($alt_lang->code) && !current_user_can('edit_posts')) {
             continue;
         }
         if (is_front_page()) {
             // Language homepage
             // is_front_page works for language homepages, phew
             $this->add_front_page_link($alt_lang);
         } else {
             if (is_post_type_archive()) {
                 // Post type archives
                 $this->add_post_type_archive_link($alt_lang);
             } else {
                 if (is_tax() || is_category()) {
                     // Category or taxonomy archive
                     $this->add_taxonomy_archive_link($alt_lang);
                 } else {
                     // 404's, amongst other things
                     $this->add_arbitrary_link($alt_lang);
                 }
             }
         }
     }
     // Make up the class attribute on all links
     foreach ($this->links as $lang_code => &$link) {
         $link['class'] = implode(' ', $link['classes']);
         $link['active'] = $lang_code == bbl_get_current_lang_code();
     }
 }
 public function get_post_terms_to_translate($post_id, $lang_code)
 {
     $post = get_post($post_id);
     $taxos = get_object_taxonomies($post->post_type);
     $trans_terms = array();
     foreach ($taxos as $key => $taxo) {
         if (!bbl_is_translated_taxonomy($taxo)) {
             continue;
         }
         $terms = get_the_terms($post, $taxo);
         if (empty($terms)) {
             continue;
         }
         foreach ($terms as $term) {
             $trans = bbl_get_term_translations($term->term_id, $term->taxonomy);
             if (!isset($trans[$lang_code])) {
                 $trans_terms[$taxo][$term->term_id] = $term;
             }
         }
     }
     return $trans_terms;
 }