/**
  * Is there an accept header and the feature is active for the site and the current language is not in the
  * noredirect cookie?
  *
  * @return bool
  */
 public function is_redirectable()
 {
     if (empty($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
         return FALSE;
     }
     if (!isset($_SESSION) && !session_id()) {
         session_start();
     }
     if (isset($_SESSION['noredirect'])) {
         $current_site_language = mlp_get_current_blog_language();
         $existing = (array) $_SESSION['noredirect'];
         if (in_array($current_site_language, $existing)) {
             return FALSE;
         }
     }
     /**
      * Filter whether the user should be redirected.
      *
      * @param bool $do_redirect Redirect or not?
      *
      * @return bool
      */
     if (!apply_filters('mlp_do_redirect', TRUE)) {
         return FALSE;
     }
     return (bool) get_option($this->option_name);
 }
 /**
  * Checks if the current request should be redirected.
  *
  * Requires an accept header, the redirect feature being active for the current site, and the current language not
  * being included in the $_SESSION's noredirect element.
  *
  * @return bool
  */
 public function is_redirectable()
 {
     if (empty($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
         return false;
     }
     if (!get_option($this->option_name)) {
         return false;
     }
     if (!isset($_SESSION) && !session_id()) {
         session_start();
     }
     if (isset($_SESSION['noredirect'])) {
         $current_site_language = mlp_get_current_blog_language();
         if (in_array($current_site_language, (array) $_SESSION['noredirect'])) {
             return false;
         }
     }
     /**
      * Filters if the current request should be redirected.
      *
      * @param bool $redirect Redirect the current request?
      *
      * @return bool
      */
     return (bool) apply_filters('mlp_do_redirect', true);
 }
 /**
  * Do browser and blog language already correspond?
  * Is redirect turned off through session-cookie?
  *
  * @since 0.1
  * @return void
  */
 public function check_redirect()
 {
     // Current blog's language (shortcode)
     $current_lang = mlp_get_current_blog_language(2);
     // Browser lang = blog lang?
     if ($current_lang == $this->defined_browser_lang) {
         $this->no_redirect = TRUE;
         return;
     }
     // Cookie check. User might want to
     // read some blogs in their original
     // language
     if (isset($_SESSION['noredirect'])) {
         if (in_array($current_lang, $_SESSION['noredirect'])) {
             $this->no_redirect = TRUE;
         }
     }
 }
 /**
  * Get the linked elements and display them as a list
  * flag from a blogid
  *
  * @since	0.1
  * @access	public
  * @param	int $blog_id ID of a blog
  * @uses	mlp_get_available_languages, mlp_get_available_languages_titles, is_single,
  * 			is_page, mlp_get_linked_elements, mlp_get_language_flag, get_current_blog_id,
  * 			get_blog_post, get_site_url
  * @return	string output of the bloglist
  */
 public static function show_linked_elements($args)
 {
     global $wp_query;
     $output = '';
     $languages = mlp_get_available_languages();
     $language_titles = mlp_get_available_languages_titles();
     if (!(0 < count($languages))) {
         return $output;
     }
     // returns NULL if there is no post, get_the_ID() throws a notice,
     // if we don' check this before.
     $default_post = get_post();
     if ($default_post) {
         $current_element_id = get_the_ID();
     } elseif (!empty($wp_query->queried_object) && !empty($wp_query->queried_object->ID)) {
         $current_element_id = $wp_query->queried_object->ID;
     } else {
         $current_element_id = 0;
     }
     $linked_elements = array();
     // double check to avoid issues with a static front page.
     if (!is_front_page() && !is_home() && is_singular()) {
         $linked_elements = mlp_get_linked_elements($current_element_id);
     }
     $defaults = array('link_text' => 'text', 'echo' => TRUE, 'sort' => 'blogid', 'show_current_blog' => FALSE);
     $params = wp_parse_args($args, $defaults);
     if ('blogid' == $params['sort']) {
         ksort($languages);
     } else {
         asort($languages);
     }
     $output .= '<div class="mlp_language_box"><ul>';
     foreach ($languages as $language_blog => $language_string) {
         $current_language = mlp_get_current_blog_language(2);
         if ($current_language == $language_string && $params['show_current_blog'] == FALSE) {
             continue;
         }
         // Get params
         $flag = mlp_get_language_flag($language_blog);
         $title = mlp_get_available_languages_titles(TRUE);
         // Display type
         if ('flag' == $params['link_text'] && '' != $flag) {
             $display = '<img src="' . $flag . '" alt="' . $languages[$language_blog] . '" title="' . $title[$language_blog] . '" />';
         } else {
             if ('text' == $params['link_text'] && !empty($language_titles[$language_blog])) {
                 $display = $language_titles[$language_blog];
             } else {
                 if ('text_flag' == $params['link_text']) {
                     $display = '<img src="' . $flag . '" alt="' . $languages[$language_blog] . '" title="' . $title[$language_blog] . '" />';
                     if (!empty($language_titles[$language_blog])) {
                         $display .= ' ' . $language_titles[$language_blog];
                     }
                 } else {
                     $display = $languages[$language_blog];
                 }
             }
         }
         $class = get_current_blog_id() == $language_blog ? 'id="mlp_current_locale"' : '';
         // set element to 0 to avoid empty element
         if (!isset($linked_elements[$language_blog])) {
             $linked_elements[$language_blog] = 0;
         }
         // Check post status
         $post = $linked_elements[$language_blog] > 0 ? get_blog_post($language_blog, $linked_elements[$language_blog]) : '';
         do_action('mlp_before_link');
         $link = (is_single() || is_page() || is_home()) && isset($post->post_status) && ('publish' === $post->post_status || 'private' === $post->post_status && is_super_admin()) ? get_blog_permalink($language_blog, $linked_elements[$language_blog]) : get_site_url($language_blog);
         // apply filter to help others to change the link
         $link = apply_filters('mlp_linked_element_link', $link, $language_blog, $linked_elements[$language_blog]);
         do_action('mlp_after_link');
         // Output link elements
         $output .= '<li ' . ($current_language == $language_string ? 'class="current"' : '') . '><a rel="alternate" hreflang="' . self::get_blog_language($language_blog) . '" ' . $class . ' href="' . $link . '">' . $display . '</a></li>';
     }
     $output .= '</ul></div>';
     return $output;
 }