/**
  * filter to avoid modifying theme's header and changes 'virtually' location for each language
  * @since 0.9.7
  */
 function xili_wp_nav_menu_args($args)
 {
     $xili_theme_options = get_theme_xili_options();
     $ok = isset($xili_theme_options['nav_menus']) && $xili_theme_options['nav_menus'] === 'nav_menus' ? true : false;
     global $xili_language;
     $default = 'en_us';
     // currently the default language of theme as in core WP
     $slug = the_curlang();
     if ($default != $slug && $ok) {
         $theme_location = $args['theme_location'];
         if (has_nav_menu($theme_location . $this->menu_lang_sep . $slug)) {
             // only if a menu is set by webmaster in menus dashboard
             $args['theme_location'] = $theme_location . $this->menu_lang_sep . $slug;
         }
     }
     return $args;
 }
    function widget($args, $instance)
    {
        if (method_exists($this, 'is_preview')) {
            // 3.9
            $cache = array();
            if (!$this->is_preview()) {
                $cache = wp_cache_get('xili_widget_recent_posts', 'widget');
            }
        } else {
            $cache = wp_cache_get('xili_widget_recent_posts', 'widget');
        }
        if (!is_array($cache)) {
            $cache = array();
        }
        if (isset($cache[$args['widget_id']])) {
            echo $cache[$args['widget_id']];
            return;
        }
        ob_start();
        extract($args);
        $title = apply_filters('widget_title', empty($instance['title']) ? __('Recent Posts') : $instance['title']);
        if (!($number = (int) $instance['number'])) {
            $number = 10;
        } else {
            if ($number < 1) {
                $number = 1;
            } else {
                if ($number > 15) {
                    $number = 15;
                }
            }
        }
        $show_date = isset($instance['show_date']) ? $instance['show_date'] : false;
        $the_lang = $instance['the_lang'];
        if (!isset($instance['post_type']) || $instance['post_type'] == '') {
            $post_type_arr = array('post');
        } else {
            $post_type_arr = explode(',', $instance['post_type']);
        }
        if (class_exists('xili_language')) {
            $tmp_query = isset($wp_query->query_vars[QUETAG]) ? $wp_query->query_vars[QUETAG] : "";
            if ($the_lang == '') {
                // new filter 'xili_widget_posts_args' with two params: array and args 2.9.22
                $thequery = apply_filters('xili_widget_posts_args', array('posts_per_page' => $number, 'post_type' => $post_type_arr, 'no_found_rows' => true, 'post_status' => 'publish', 'ignore_sticky_posts' => true), $args);
            } else {
                $lang = $the_lang == '*' ? the_curlang() : $the_lang;
                $thequery = apply_filters('xili_widget_posts_args', array('posts_per_page' => $number, 'post_type' => $post_type_arr, 'no_found_rows' => true, 'post_status' => 'publish', 'ignore_sticky_posts' => true, 'tax_query' => array(array('field' => 'slug', 'taxonomy' => TAXONAME, 'terms' => $lang))), $args);
            }
            $r = new WP_Query($thequery);
        } else {
            $thequery = apply_filters('widget_posts_args', array('posts_per_page' => $number, 'no_found_rows' => true, 'post_status' => 'publish', 'ignore_sticky_posts' => true));
            $r = new WP_Query($thequery);
        }
        if ($r->have_posts()) {
            ?>
		<?php 
            echo $before_widget;
            ?>
		<?php 
            if ($title) {
                echo $before_title . $title . $after_title;
            }
            ?>
		<ul>
		<?php 
            while ($r->have_posts()) {
                $r->the_post();
                ?>
			<li><a href="<?php 
                the_permalink();
                ?>
" title="<?php 
                echo esc_attr(get_the_title() ? get_the_title() : get_the_ID());
                ?>
"><?php 
                if (get_the_title()) {
                    the_title();
                } else {
                    the_ID();
                }
                ?>
 </a>
			<?php 
                if ($show_date) {
                    ?>
				<span class="post-date"><?php 
                    echo get_the_date();
                    ?>
</span>
			<?php 
                }
                ?>

			</li>
		<?php 
            }
            ?>
		</ul>
		<?php 
            echo $after_widget;
            wp_reset_postdata();
        }
        if (method_exists($this, 'is_preview')) {
            // 3.9
            if (!$this->is_preview()) {
                $cache[$args['widget_id']] = ob_get_flush();
                wp_cache_set('xili_widget_recent_posts', $cache, 'widget');
            } else {
                ob_flush();
            }
        } else {
            $cache[$args['widget_id']] = ob_get_flush();
            wp_cache_set('xili_widget_recent_posts', $cache, 'widget');
        }
    }
 /**
  *
  * prepare terms of topic-tag and attach language for replies
  *
  */
 function xl_bbp_edit_reply_pre_set_terms($terms, $topic_id, $reply_id)
 {
     global $xili_tidy_tags_topic;
     $taxonomy = get_option('_bbp_topic_tag_slug', 'topic-tag');
     $taxonomy_obj = get_taxonomy($taxonomy);
     if (current_user_can($taxonomy_obj->cap->assign_terms)) {
         $lang_group = the_curlang() . '-' . $xili_tidy_tags_topic->xili_settings['tidylangsgroup'];
         $group = term_exists($lang_group, $xili_tidy_tags_topic->tidy_taxonomy);
         // Explode by comma
         if (strstr($terms, ',')) {
             $tags = explode(',', $terms);
         } else {
             $tags = array($terms);
         }
         foreach ($tags as $term) {
             // if exists add current language
             $res = term_exists($term, $taxonomy);
             if (is_array($res)) {
                 // if not assigned - (int) mandatory - true to add language or group
                 wp_set_object_terms($res['term_id'], array((int) $group['term_id']), $xili_tidy_tags_topic->tidy_taxonomy, true);
             } else {
                 // if not add and assign language
                 $res = wp_insert_term($term, $taxonomy);
                 if (!is_wp_error($res)) {
                     wp_set_object_terms($res['term_id'], array((int) $group['term_id']), $xili_tidy_tags_topic->tidy_taxonomy, true);
                 }
             }
         }
         global $xili_xl_bbp_addon;
         // don't modify the reply tags string - check option - a reply cannot reduce tags list
         if (isset($xili_xl_bbp_addon['main']->xili_settings['reply-keep-tags']) && $xili_xl_bbp_addon['main']->xili_settings['reply-keep-tags']) {
             $topic_terms = get_the_terms($topic_id, $taxonomy);
             // those of topic
             if (!is_wp_error($topic_terms) && !empty($topic_terms)) {
                 foreach ($topic_terms as $term) {
                     if (!in_array($term->name, $tags)) {
                         $tags[] = $term->name;
                     }
                 }
                 return $tags;
             }
         }
     }
     return $terms;
 }
Esempio n. 4
0
 /**
  * insert languages list objects in nav menu at insertion point (filter wp_nav_menu_objects)
  *
  * @since 2.8.8
  * @updated 2.9.11 (page) , 2.9.20 (menu)
  * @updated 2.10.1 - singular if exists
  * @updated 2.11.2 - better class assignation (ancestor) - thanks to Bastian
  * @updated 2.12.2 - compatible
  *
  */
 function insert_language_objects_in_nav_menu($sorted_menu_items, $args)
 {
     global $post, $wp_query;
     // detect insertion point menu object and menu type
     $new_sorted_menu_items = array();
     foreach ($sorted_menu_items as $key => $menu_object) {
         if ($menu_object->url == $this->insertion_point_dummy_link_menu) {
             // #insertmenu
             $queried_object = $wp_query->get_queried_object();
             $queried_object_id = (int) $wp_query->queried_object_id;
             if (false !== strpos($menu_object->attr_title, 'menu-wo-')) {
                 $langkey = explode('-', str_replace('menu-wo-', '', $menu_object->attr_title));
                 // approach < 2.14.2
             } else {
                 $langkey_ids = explode('-', str_replace('menu-wlid-', '', $menu_object->attr_title));
                 $langkey = array();
                 $id_slug = array_flip($this->langs_ids_array);
                 foreach ($langkey_ids as $lang_id) {
                     $langkey[] = $id_slug[$lang_id];
                 }
             }
             $menu_id_list = '';
             $menu_slug_list = '';
             foreach ($menu_object->classes as $one_class) {
                 if (false !== strpos($one_class, 'xlmenulist-')) {
                     $menu_id_list = str_replace('xlmenulist-', '', $one_class);
                     continue;
                 } else {
                     if (false !== strpos($one_class, 'xlmenuslug')) {
                         // to be compatible with export xml
                         $menu_slug_list = str_replace('xlmenuslug' . $this->menu_slug_sep, '', $one_class);
                         // -- seems better than _
                         continue;
                     }
                 }
             }
             if ($menu_id_list) {
                 $menu_ids = explode('-', $menu_id_list);
                 // here saved as term_id (container of menu items) (<2.12.2)
             } else {
                 if ($menu_slug_list) {
                     $menu_slugs = explode($this->menu_slug_sep, $menu_slug_list);
                     foreach ($menu_slugs as $one_slug) {
                         $term_data = term_exists($one_slug, 'nav_menu');
                         $menu_ids[] = is_array($term_data) ? $term_data['term_id'] : 0;
                     }
                 }
             }
             $menu_list = count($langkey) == count($menu_ids) ? array_combine($langkey, $menu_ids) : array();
             // pb in count
             $curlang = the_curlang();
             if (isset($menu_list[$curlang])) {
                 $menu_structure_exists = term_exists((int) $menu_list[$curlang], 'nav_menu') ? true : false;
             } else {
                 $menu_structure_exists = false;
             }
             if ($curlang && $menu_structure_exists) {
                 $menu_items = wp_get_nav_menu_items($menu_list[$curlang]);
                 // need term_id of structure
                 _wp_menu_item_classes_by_context($menu_items);
                 // added 2.11.2
                 if ($menu_items) {
                     // added in 1.8 to sort inserted menu content and to insert class 'menu-item-has-children' as in nav-menu-template.php
                     $sorted_menu_items = $menu_items_with_children = array();
                     foreach ((array) $menu_items as $menu_item) {
                         $sorted_menu_items[$menu_item->menu_order] = $menu_item;
                         if ($menu_item->menu_item_parent) {
                             $menu_items_with_children[$menu_item->menu_item_parent] = true;
                         }
                     }
                     // Add the menu-item-has-children class where applicable
                     if ($menu_items_with_children) {
                         foreach ($sorted_menu_items as &$menu_item) {
                             if (isset($menu_items_with_children[$menu_item->ID])) {
                                 $menu_item->classes[] = 'menu-item-has-children';
                             }
                         }
                     }
                     unset($menu_items, $menu_item);
                     foreach ($sorted_menu_items as $new_menu_item) {
                         // not recursive : impossible to decode insertion point inside menu
                         if (!in_array($new_menu_item->url, array($this->insertion_point_dummy_link_menu, $this->insertion_point_dummy_link_page, $this->insertion_point_dummy_link))) {
                             $new_classes = array("insertion-point");
                             if ($new_menu_item->menu_item_parent == 0) {
                                 $new_menu_item->menu_item_parent = $menu_object->menu_item_parent;
                             }
                             // heritate from insertion point
                             $new_menu_item->classes = array_merge($menu_object->classes, $new_classes, $new_menu_item->classes);
                             // fixed 2.11.2
                             $new_sorted_menu_items[] = $new_menu_item;
                         }
                     }
                 }
             }
         } else {
             if ($menu_object->url == $this->insertion_point_dummy_link_page) {
                 // #insertpagelist
                 $classes = $menu_object->classes;
                 $i = 0;
                 $defaults = array('sort_order' => 'ASC', 'sort_column' => 'menu_order', 'hierarchical' => 1, QUETAG => $this->curlang);
                 $r = wp_parse_args($menu_object->attr_title, $defaults);
                 extract($r, EXTR_SKIP);
                 $pagelist = get_pages($r);
                 foreach ($pagelist as $onepage) {
                     $class = is_page($onepage->ID) ? ' current-menu-item' : '';
                     $i++;
                     $new_lang_menu_item = (object) array();
                     $id = $menu_object->ID * 1000 + $i;
                     $new_lang_menu_item->ID = $id;
                     $new_lang_menu_item->url = get_permalink($onepage->ID);
                     // $onepage->guid;
                     $new_lang_menu_item->title = $onepage->post_title;
                     $new_lang_menu_item->attr_title = apply_filters('xl_nav_menu_page_attr_title', '...', $onepage->ID);
                     $new_lang_menu_item->description = apply_filters('xl_nav_menu_page_description', '', $onepage->ID);
                     // for twentyfifteen 2.15.4
                     $new_lang_menu_item->menu_item_parent = $menu_object->menu_item_parent;
                     $new_lang_menu_item->db_id = $menu_object->db_id;
                     $new_lang_menu_item->target = $menu_object->target;
                     $new_lang_menu_item->classes = array_merge($menu_object->classes, explode(' ', $class));
                     $new_sorted_menu_items[] = $new_lang_menu_item;
                 }
             } else {
                 if ($menu_object->url == $this->insertion_point_dummy_link) {
                     // language
                     $classes = $menu_object->classes;
                     $keys = array();
                     foreach ($this->langs_list_options as $one) {
                         $keys[] = $one[0];
                     }
                     $type_array = array_values(array_intersect($keys, $menu_object->classes));
                     $type = $type_array[0];
                     $hidden = true;
                     // hidden here as defined in list - only available language are listed
                     // create array of language menu objects
                     $listlanguages = $this->get_listlanguages();
                     $new_menu_objects = array();
                     $i = 0;
                     foreach ($listlanguages as $language) {
                         $link = false;
                         $display = $hidden && $this->xili_settings['lang_features'][$language->slug]['hidden'] == 'hidden' ? false : true;
                         if ($display && !(in_array($type, array('navmenu-a', 'navmenu-1a', 'navmenu-1ao')) && $language->slug == the_curlang())) {
                             $i++;
                             if ($language->slug != the_curlang()) {
                                 $class = 'lang-' . $language->slug;
                             } else {
                                 $class = 'lang-' . $language->slug . ' current-lang current-menu-item';
                             }
                             $language_qv = $this->lang_slug_qv_trans($language->slug);
                             if (in_array($type, array('navmenu-1', 'navmenu-1a', 'navmenu-1ao'))) {
                                 $this->doing_list_language = $language->slug;
                                 // for date filter if lang_perma
                                 $currenturl = $this->current_url($this->lang_perma);
                                 if (is_singular() && !is_front_page()) {
                                     if (in_array($type, array('navmenu-1a', 'navmenu-1'))) {
                                         // 2.13.3
                                         $link = $this->link_of_linked_post($post->ID, $language->slug);
                                     } else {
                                         $targetpost = $this->linked_post_in($post->ID, $language->slug);
                                         if ($targetpost) {
                                             $link = get_permalink($targetpost);
                                         }
                                     }
                                     $title = sprintf(__($this->xili_settings['list_link_title']['current_post'], the_theme_domain()), __($language->description, $this->thetextdomain));
                                 } else {
                                     if ($wp_query->is_posts_page) {
                                         // 2.8.4
                                         $link = $this->link_of_linked_post(get_option('page_for_posts'), $language->slug);
                                         $title = sprintf(__($this->xili_settings['list_link_title']['latest_posts'], the_theme_domain()), _x($language->description, 'linktitle', $this->thetextdomain));
                                     } else {
                                         if (function_exists('xili_tidy_tag_in_other_lang') && (is_tag() || $this->is_tax_improved())) {
                                             // 2.9.1
                                             $q = '';
                                             if (!is_tag() && $this->is_tax_improved()) {
                                                 $queried_object = $wp_query->get_queried_object();
                                                 $q = '&tidy_post_tag=' . $queried_object->taxonomy;
                                             }
                                             if ($link = xili_tidy_tag_in_other_lang("format=term_link&lang=" . $language->name . $q)) {
                                                 $title = xili_tidy_tag_in_other_lang("format=term_name&lang=" . $language->name . $q);
                                             } else {
                                                 $link = $this->lang_perma ? str_replace('%lang%', $language_qv, $currenturl) : add_query_arg(array(QUETAG => $language_qv), $currenturl);
                                                 $title = sprintf(__($this->xili_settings['list_link_title']['post_selected'], the_theme_domain()), _x($language->description, 'linktitle', $this->thetextdomain));
                                             }
                                         } else {
                                             $link = $this->lang_perma ? str_replace('%lang%', $language_qv, $currenturl) : add_query_arg(array(QUETAG => $language_qv), $currenturl);
                                             $link = apply_filters('xiliml_language_list_menu_link', $link, $type, $language->slug, $language_qv);
                                             // 2.19.3
                                             $title = sprintf(__($this->xili_settings['list_link_title']['post_selected'], the_theme_domain()), _x($language->description, 'linktitle', $this->thetextdomain));
                                         }
                                     }
                                 }
                                 $this->doing_list_language = false;
                             } else {
                                 // 'navmenu', 'navmenu-a'
                                 $link = $this->lang_perma ? str_replace('%lang%', $language_qv, get_bloginfo('url') . '/%lang%/') : add_query_arg(array(QUETAG => $language_qv), get_bloginfo('url'));
                                 $title = esc_attr(sprintf(__($this->xili_settings['list_link_title']['post_selected'], $this->thetextdomain), _x($language->description, 'linktitle', $this->thetextdomain)));
                             }
                             // only required values...
                             if ($link) {
                                 $new_lang_menu_item = (object) array();
                                 $id = $menu_object->ID * 100 + $i;
                                 $new_lang_menu_item->ID = $id;
                                 $new_lang_menu_item->url = $link;
                                 $new_lang_menu_item->title = __($language->description, $this->thetextdomain);
                                 $new_lang_menu_item->attr_title = $title;
                                 $new_lang_menu_item->description = apply_filters('xl_nav_menu_lang_description', '', $language->slug);
                                 // for twentyfifteen 2.15.4
                                 $new_lang_menu_item->menu_item_parent = $menu_object->menu_item_parent;
                                 $new_lang_menu_item->db_id = $menu_object->db_id;
                                 $new_lang_menu_item->target = $menu_object->target;
                                 $new_lang_menu_item->classes = array_merge($menu_object->classes, explode(' ', $class));
                                 $new_sorted_menu_items[] = $new_lang_menu_item;
                             }
                         }
                         // language
                     }
                     // display
                 } else {
                     // no dummy insertion
                     $new_sorted_menu_items[] = $menu_object;
                 }
             }
         }
     }
     // foreach menu
     return $new_sorted_menu_items;
 }
 function insert_lang_pagenum_link($link)
 {
     global $xili_language, $wp_rewrite;
     $the_lang = $xili_language->lang_slug_qv_trans(the_curlang());
     // by default
     $home = trailingslashit(get_bloginfo('url'));
     //if ( $the_lang == '' ) $the_lang = xili_language_trans_slug_qv ( $xili_language->default_slug );
     if ($the_lang != '' && false === strpos($link, '/' . $the_lang)) {
         return str_replace($home . $wp_rewrite->root, $home . $wp_rewrite->root . $the_lang . '/', $link);
     }
     return $link;
 }