/**
 * @param WP_Query $q
 *
 * @return mixed
 */
function wpml_home_url_parse_query($q)
{
    if (!$q->is_main_query()) {
        return $q;
    }
    global $sitepress_settings;
    $site_url = get_site_url();
    $parts = parse_url($site_url);
    if (!isset($parts['path'])) {
        $parts['path'] = '';
    }
    if (!WPML_Root_Page::is_current_request_root()) {
        return $q;
    } else {
        remove_action('parse_query', 'wpml_home_url_parse_query');
        $request_array = explode('/', $_SERVER["REQUEST_URI"]);
        $sanitized_query = array_pop($request_array);
        $potential_pagination_parameter = array_pop($request_array);
        if (is_numeric($potential_pagination_parameter)) {
            if ($sanitized_query) {
                $sanitized_query .= '&';
            }
            $sanitized_query .= 'page=' . $potential_pagination_parameter;
        }
        $sanitized_query = str_replace('?', '', $sanitized_query);
        $q->parse_query($sanitized_query);
        add_action('parse_query', 'wpml_home_url_parse_query');
        $q->query_vars['page_id'] = $sitepress_settings["urls"]["root_page"];
        $q->query['page_id'] = $sitepress_settings["urls"]["root_page"];
        $q->is_page = 1;
        $q->queried_object = new WP_Post(get_post($sitepress_settings["urls"]["root_page"]));
        $q->queried_object_id = $sitepress_settings["urls"]["root_page"];
        $q->query_vars['error'] = "";
        $q->is_404 = false;
        $q->query['error'] = null;
    }
    return $q;
}
 /**
  * @param WPML_URL_Converter $url_converter
  * @param array              $active_languages
  * @param string             $default_language
  * @param WPML_Cookie        $cookie
  */
 public function __construct(&$url_converter, $active_languages, $default_language, $cookie)
 {
     parent::__construct($url_converter, $active_languages, $default_language, $cookie);
     global $wpml_url_filters;
     if (strpos((string) filter_var($_SERVER['REQUEST_URI']), 'wpml_root_page=1') !== false || $wpml_url_filters->frontend_uses_root() !== false) {
         WPML_Root_Page::init();
     }
 }
 /**
  * @param WPML_Post_Translation $post_translation
  * @param WPML_URL_Converter    $url_converter
  * @param WPML_Canonicals       $canonicals
  * @param SitePress             $sitepress
  */
 public function __construct(&$post_translation, &$url_converter, WPML_Canonicals $canonicals, &$sitepress)
 {
     parent::__construct($post_translation, $sitepress);
     $this->url_converter =& $url_converter;
     $this->canonicals = $canonicals;
     if ($this->frontend_uses_root() === true) {
         WPML_Root_Page::init();
     }
     $this->add_hooks();
 }
 private function maybe_setup_rootpage()
 {
     if (WPML_Root_Page::is_current_request_root()) {
         if (WPML_Root_Page::uses_html_root()) {
             $html_file = (false === strpos($this->urls['root_html_file_path'], '/') ? ABSPATH : '') . $this->urls['root_html_file_path'];
             /** @noinspection PhpIncludeInspection */
             include $html_file;
             exit;
         } else {
             $root_page_actions = wpml_get_root_page_actions_obj();
             $root_page_actions->wpml_home_url_setup_root_page();
         }
     }
 }
 /**
  * @param WPML_Post_Translation $post_translation
  * @param WPML_URL_Converter    $url_converter
  * @param SitePress             $sitepress
  */
 public function __construct(&$post_translation, &$url_converter, &$sitepress)
 {
     parent::__construct($post_translation, $sitepress);
     $this->url_converter =& $url_converter;
     if ($this->frontend_uses_root() === true) {
         WPML_Root_Page::init();
         add_filter('page_link', array($this, 'permalink_filter_root'), 1, 2);
     } else {
         add_filter('page_link', array($this, 'permalink_filter'), 1, 2);
     }
     add_filter('home_url', array($this, 'home_url_filter'), -10, 4);
     // posts and pages links filters
     add_filter('post_link', array($this, 'permalink_filter'), 1, 2);
     add_filter('post_type_link', array($this, 'permalink_filter'), 1, 2);
     add_filter('get_edit_post_link', array($this, 'get_edit_post_link'), 1, 3);
 }
예제 #6
0
 /**
  * @param $url
  * Filters links to the root page, so that they are displayed properly in the front-end.
  *
  * @return mixed
  */
 public function filter_root_permalink($url)
 {
     global $wpml_url_converter;
     if (WPML_Root_Page::get_root_id() > 0 && WPML_Root_Page::is_root_page($url)) {
         $url_parts = parse_url($url);
         $query = isset($url_parts['query']) ? $url_parts['query'] : '';
         $path = isset($url_parts['path']) ? $url_parts['path'] : '';
         $slugs = array_filter(explode('/', $path));
         $last_slug = array_pop($slugs);
         $new_url = $wpml_url_converter->get_abs_home();
         $new_url = is_numeric($last_slug) ? trailingslashit(trailingslashit($new_url) . $last_slug) : $new_url;
         $query = self::unset_page_query_vars($query);
         $new_url = trailingslashit($new_url);
         $url = (bool) $query === true ? trailingslashit($new_url) . '?' . $query : $new_url;
     }
     return $url;
 }
예제 #7
0
 public static function init()
 {
     if (WPML_Root_Page::uses_html_root() || WPML_Root_Page::get_root_id() > 0 || strpos((string) filter_var($_SERVER['REQUEST_URI']), 'wpml_root_page=1') !== false || (bool) filter_input(INPUT_POST, '_wpml_root_page') === true) {
         global $wpml_root_page_actions;
         $wpml_root_page_actions = wpml_get_root_page_actions_obj();
         add_action('init', array($wpml_root_page_actions, 'wpml_home_url_init'), 0);
         add_filter('wp_page_menu_args', array($wpml_root_page_actions, 'wpml_home_url_exclude_root_page_from_menus'));
         add_filter('wp_get_nav_menu_items', array($wpml_root_page_actions, 'exclude_root_page_menu_item'), 10, 1);
         add_filter('wp_list_pages_excludes', array($wpml_root_page_actions, 'wpml_home_url_exclude_root_page'));
         add_filter('page_attributes_dropdown_pages_args', array($wpml_root_page_actions, 'wpml_home_url_exclude_root_page2'));
         add_filter('get_pages', array($wpml_root_page_actions, 'wpml_home_url_get_pages'));
         add_action('save_post', array($wpml_root_page_actions, 'wpml_home_url_save_post_actions'), 0, 2);
         if (self::get_root_id() > 0) {
             add_filter('template_include', array('WPML_Root_Page', 'wpml_home_url_template_include'));
             add_filter('the_preview', array('WPML_Root_Page', 'front_page_id_filter'));
         }
         $root_page_actions = wpml_get_root_page_actions_obj();
         add_action('icl_set_element_language', array($root_page_actions, 'delete_root_page_lang'), 10, 0);
     }
 }
예제 #8
0
 function get_ls_languages($template_args = array())
 {
     //Returns false if is admin and settings are corrupted
     if (is_admin() && !SitePress::check_settings_integrity()) {
         return false;
     }
     /** @var $wp_query WP_Query */
     global $sitepress, $wpdb, $wp_query, $w_this_lang;
     $current_language = $this->get_current_language();
     $default_language = $this->get_default_language();
     $cache_key_args = $template_args ? array_filter($template_args) : array('default');
     $cache_key_args[] = $current_language;
     $cache_key_args[] = $default_language;
     $cache_key_args = array_filter($cache_key_args);
     $cache_key = md5(json_encode($cache_key_args));
     $cache_group = 'ls_languages';
     $found = false;
     $ls_languages = wp_cache_get($cache_key, $cache_group, $found);
     if ($found) {
         return $ls_languages;
     }
     if (is_null($this->wp_query)) {
         $this->set_wp_query();
     }
     // use original wp_query for this
     // backup current $wp_query
     if (!isset($wp_query)) {
         return $this->get_active_languages();
     }
     $_wp_query_back = clone $wp_query;
     unset($wp_query);
     global $wp_query;
     // make it global again after unset
     $wp_query = clone $this->wp_query;
     $w_active_languages = $this->get_active_languages();
     $this_lang = $this->this_lang;
     if ($this_lang == 'all') {
         $w_this_lang = array('code' => 'all', 'english_name' => 'All languages', 'display_name' => __('All languages', 'sitepress'));
     } else {
         $w_this_lang = $this->get_language_details($this_lang);
     }
     if (isset($template_args['skip_missing'])) {
         //override default setting
         $icl_lso_link_empty = !$template_args['skip_missing'];
     } else {
         $icl_lso_link_empty = $this->settings['icl_lso_link_empty'];
     }
     // 1. Determine translations
     if (is_category()) {
         $skip_empty = false;
         $term_taxonomy_id_prepared = $wpdb->prepare("SELECT term_taxonomy_id FROM {$wpdb->term_taxonomy} WHERE term_id=%d AND taxonomy=%s", array(get_query_var('cat'), 'category'));
         $term_taxonomy_id = $wpdb->get_var($term_taxonomy_id_prepared);
         $trid = $sitepress->get_element_trid($term_taxonomy_id, 'tax_category');
         $translations = $this->get_element_translations($trid, 'tax_category', $skip_empty);
     } elseif (is_tag()) {
         $skip_empty = false;
         $term_taxonomy_id_prepared = $wpdb->prepare("SELECT term_taxonomy_id FROM {$wpdb->term_taxonomy} WHERE term_id=%d AND taxonomy=%s", array(get_query_var('tag_id'), 'post_tag'));
         $term_taxonomy_id = $wpdb->get_var($term_taxonomy_id_prepared);
         $trid = $sitepress->get_element_trid($term_taxonomy_id, 'tax_post_tag');
         $translations = $this->get_element_translations($trid, 'tax_post_tag', $skip_empty);
     } elseif (is_tax()) {
         $skip_empty = false;
         $term_taxonomy_id_prepared = $wpdb->prepare("SELECT term_taxonomy_id FROM {$wpdb->term_taxonomy} WHERE term_id=%d AND taxonomy=%s", array($wp_query->get_queried_object_id(), get_query_var('taxonomy')));
         $term_taxonomy_id = $wpdb->get_var($term_taxonomy_id_prepared);
         if ($this->is_translated_taxonomy(get_query_var('taxonomy'))) {
             $trid = $this->get_element_trid($term_taxonomy_id, 'tax_' . get_query_var('taxonomy'));
             $translations = $this->get_element_translations($trid, 'tax_' . get_query_var('taxonomy'), $skip_empty);
         } else {
             $translations[$this->get_current_language()] = (object) array('translation_id' => 0, 'language_code' => $this->get_default_language(), 'original' => 1, 'name' => get_query_var('taxonomy'), 'term_id' => $wp_query->get_queried_object_id());
         }
     } elseif (is_archive()) {
         $translations = array();
     } elseif (is_attachment()) {
         // Exception for attachments. Not translated.
         $trid = $sitepress->get_element_trid($wp_query->get_queried_object_id(), 'post_attachment');
         $translations = $this->get_element_translations($trid, 'post_attachment');
     } elseif (is_page() || 'page' == get_option('show_on_front') && (isset($this->wp_query->queried_object_id) && $this->wp_query->queried_object_id == get_option('page_on_front') || isset($this->wp_query->queried_object_id) && $this->wp_query->queried_object_id == get_option('page_for_posts'))) {
         $trid = $sitepress->get_element_trid($wp_query->get_queried_object_id(), 'post_page');
         $translations = $this->get_element_translations($trid, 'post_page');
     } elseif (is_singular() && !empty($wp_query->posts)) {
         $trid = $sitepress->get_element_trid($this->wp_query->post->ID, 'post_' . $wp_query->posts[0]->post_type);
         $translations = $this->get_element_translations($trid, 'post_' . $wp_query->posts[0]->post_type);
     } else {
         $wp_query->is_singular = false;
         $wp_query->is_archive = false;
         $wp_query->is_category = false;
         $wp_query->is_404 = true;
     }
     // 2. determine url
     foreach ($w_active_languages as $k => $lang) {
         $skip_lang = false;
         if (is_singular() || !empty($this->wp_query->queried_object_id) && $this->wp_query->queried_object_id == get_option('page_for_posts')) {
             $this_lang_tmp = $this->this_lang;
             $this->this_lang = $lang['code'];
             $lang_page_on_front = get_option('page_on_front');
             $lang_page_for_posts = get_option('page_for_posts');
             if ($lang_page_on_front && $lang['code'] != $default_language) {
                 $lang_page_on_front = icl_object_id($lang_page_on_front, 'page', false, $lang['code']);
             }
             if ($lang_page_for_posts && $lang['code'] != $default_language) {
                 $lang_page_for_posts = icl_object_id($lang_page_for_posts, 'page', false, $lang['code']);
             }
             if ('page' == get_option('show_on_front') && !empty($translations[$lang['code']]) && $translations[$lang['code']]->element_id == $lang_page_on_front) {
                 $lang['translated_url'] = $this->language_url($lang['code']);
             } elseif ('page' == get_option('show_on_front') && !empty($translations[$lang['code']]) && $translations[$lang['code']]->element_id && $translations[$lang['code']]->element_id == $lang_page_for_posts) {
                 if ($lang_page_for_posts) {
                     $lang['translated_url'] = get_permalink($lang_page_for_posts);
                 } else {
                     $lang['translated_url'] = $this->language_url($lang['code']);
                 }
             } else {
                 if (!empty($translations[$lang['code']]) && isset($translations[$lang['code']]->post_title)) {
                     $lang['translated_url'] = get_permalink($translations[$lang['code']]->element_id);
                     $lang['missing'] = 0;
                 } else {
                     if ($icl_lso_link_empty) {
                         if (!empty($template_args['link_empty_to'])) {
                             $lang['translated_url'] = str_replace('{%lang}', $lang['code'], $template_args['link_empty_to']);
                         } else {
                             $lang['translated_url'] = $this->language_url($lang['code']);
                         }
                     } else {
                         $skip_lang = true;
                     }
                     $lang['missing'] = 1;
                 }
             }
             $this->this_lang = $this_lang_tmp;
         } elseif (is_category()) {
             if (isset($translations[$lang['code']])) {
                 global $icl_adjust_id_url_filter_off;
                 // force  the category_link_adjust_id to not modify this
                 $icl_adjust_id_url_filter_off = true;
                 $lang['translated_url'] = get_category_link($translations[$lang['code']]->term_id);
                 $icl_adjust_id_url_filter_off = false;
                 // restore default bahavior
                 $lang['missing'] = 0;
             } else {
                 if ($icl_lso_link_empty) {
                     if (!empty($template_args['link_empty_to'])) {
                         $lang['translated_url'] = str_replace('{%lang}', $lang['code'], $template_args['link_empty_to']);
                     } else {
                         $lang['translated_url'] = $this->language_url($lang['code']);
                     }
                 } else {
                     // dont skip the currrent language
                     if ($current_language != $lang['code']) {
                         $skip_lang = true;
                     }
                 }
                 $lang['missing'] = 1;
             }
         } elseif (is_tax()) {
             if (isset($translations[$lang['code']])) {
                 global $icl_adjust_id_url_filter_off;
                 // force  the category_link_adjust_id to not modify this
                 $icl_adjust_id_url_filter_off = true;
                 $lang['translated_url'] = get_term_link((int) $translations[$lang['code']]->term_id, get_query_var('taxonomy'));
                 $icl_adjust_id_url_filter_off = false;
                 // restore default bahavior
                 $lang['missing'] = 0;
             } else {
                 if ($icl_lso_link_empty) {
                     if (!empty($template_args['link_empty_to'])) {
                         $lang['translated_url'] = str_replace('{%lang}', $lang['code'], $template_args['link_empty_to']);
                     } else {
                         $lang['translated_url'] = $this->language_url($lang['code']);
                     }
                 } else {
                     // dont skip the currrent language
                     if ($current_language != $lang['code']) {
                         $skip_lang = true;
                     }
                 }
                 $lang['missing'] = 1;
             }
         } elseif (is_tag()) {
             if (isset($translations[$lang['code']])) {
                 global $icl_adjust_id_url_filter_off;
                 // force  the category_link_adjust_id to not modify this
                 $icl_adjust_id_url_filter_off = true;
                 $lang['translated_url'] = get_tag_link($translations[$lang['code']]->term_id);
                 $icl_adjust_id_url_filter_off = false;
                 // restore default bahavior
                 $lang['missing'] = 0;
             } else {
                 if ($icl_lso_link_empty) {
                     if (!empty($template_args['link_empty_to'])) {
                         $lang['translated_url'] = str_replace('{%lang}', $lang['code'], $template_args['link_empty_to']);
                     } else {
                         $lang['translated_url'] = $this->language_url($lang['code']);
                     }
                 } else {
                     // dont skip the currrent language
                     if ($current_language != $lang['code']) {
                         $skip_lang = true;
                     }
                 }
                 $lang['missing'] = 1;
             }
         } elseif (is_author()) {
             global $authordata, $wp_query;
             if (empty($authordata)) {
                 $authordata = get_userdata(get_query_var('author'));
             }
             $post_type = get_query_var('post_type') ? get_query_var('post_type') : 'post';
             if ($wpdb->get_var("SELECT COUNT(p.ID) FROM {$wpdb->posts} p\r\n\t\t\t\t\t\tJOIN {$wpdb->prefix}icl_translations t ON p.ID=t.element_id AND t.element_type = 'post_{$post_type}'\r\n\t\t\t\t\t\tWHERE p.post_author='{$authordata->ID}' AND post_type='{$post_type}' AND post_status='publish' AND language_code='{$lang['code']}'")) {
                 remove_filter('home_url', array($this, 'home_url'), 1, 4);
                 remove_filter('author_link', array($this, 'author_link'));
                 $author_url = get_author_posts_url($authordata->ID);
                 add_filter('home_url', array($this, 'home_url'), 1, 4);
                 add_filter('author_link', array($this, 'author_link'));
                 $lang['translated_url'] = $this->convert_url($author_url, $lang['code']);
                 $lang['missing'] = 0;
             } else {
                 if ($icl_lso_link_empty) {
                     if (!empty($template_args['link_empty_to'])) {
                         $lang['translated_url'] = str_replace('{%lang}', $lang['code'], $template_args['link_empty_to']);
                     } else {
                         $lang['translated_url'] = $this->language_url($lang['code']);
                     }
                 } else {
                     // dont skip the currrent language
                     if ($current_language != $lang['code']) {
                         $skip_lang = true;
                     }
                 }
                 $lang['missing'] = 1;
             }
         } elseif (is_archive() && !is_tag()) {
             global $icl_archive_url_filter_off;
             $icl_archive_url_filter_off = true;
             if ($this->wp_query->is_year) {
                 if (isset($this->wp_query->query_vars['m']) && !$this->wp_query->query_vars['year']) {
                     $this->wp_query->query_vars['year'] = substr($this->wp_query->query_vars['m'], 0, 4);
                 }
                 $lang['translated_url'] = $this->archive_url(get_year_link($this->wp_query->query_vars['year']), $lang['code']);
             } elseif ($this->wp_query->is_month) {
                 if (isset($this->wp_query->query_vars['m']) && !$this->wp_query->query_vars['year']) {
                     $this->wp_query->query_vars['year'] = substr($this->wp_query->query_vars['m'], 0, 4);
                     $this->wp_query->query_vars['monthnum'] = substr($this->wp_query->query_vars['m'], 4, 2);
                 } else {
                     if ($icl_lso_link_empty) {
                         if (!empty($template_args['link_empty_to'])) {
                             $lang['translated_url'] = str_replace('{%lang}', $lang['code'], $template_args['link_empty_to']);
                         } else {
                             $lang['translated_url'] = $this->language_url($lang['code']);
                         }
                     }
                     $lang['missing'] = 1;
                 }
                 $lang['translated_url'] = $this->archive_url(get_month_link($this->wp_query->query_vars['year'], $this->wp_query->query_vars['monthnum']), $lang['code']);
             } elseif ($this->wp_query->is_day) {
                 if (isset($this->wp_query->query_vars['m']) && !$this->wp_query->query_vars['year']) {
                     $this->wp_query->query_vars['year'] = substr($this->wp_query->query_vars['m'], 0, 4);
                     $this->wp_query->query_vars['monthnum'] = substr($this->wp_query->query_vars['m'], 4, 2);
                     $this->wp_query->query_vars['day'] = substr($this->wp_query->query_vars['m'], 6, 2);
                     gmdate('Y', current_time('timestamp'));
                     //force wp_timezone_override_offset to be called
                 }
                 $lang['translated_url'] = $this->archive_url(get_day_link($this->wp_query->query_vars['year'], $this->wp_query->query_vars['monthnum'], $this->wp_query->query_vars['day']), $lang['code']);
             } else {
                 if (isset($this->wp_query->query_vars['post_type'])) {
                     do_action('_icl_before_archive_url', $this->wp_query->query_vars['post_type'], $lang['code']);
                     if ($this->is_translated_post_type($this->wp_query->query_vars['post_type']) && function_exists('get_post_type_archive_link')) {
                         remove_filter('post_type_archive_link', array($this, 'post_type_archive_link_filter'), 10);
                         $lang['translated_url'] = $this->convert_url(get_post_type_archive_link($this->wp_query->query_vars['post_type']), $lang['code']);
                     } else {
                         if ($k != $this->get_default_language()) {
                             $skip_lang = true;
                             unset($w_active_languages[$k]);
                         }
                     }
                     do_action('_icl_after_archive_url', $this->wp_query->query_vars['post_type'], $lang['code']);
                 }
             }
             add_filter('post_type_archive_link', array($this, 'post_type_archive_link_filter'), 10, 2);
             $icl_archive_url_filter_off = false;
         } elseif (is_search()) {
             $url_glue = strpos($this->language_url($lang['code']), '?') === false ? '?' : '&';
             $lang['translated_url'] = $this->language_url($lang['code']) . $url_glue . 's=' . urlencode($wp_query->query['s']);
         } else {
             global $icl_language_switcher_preview;
             if ($icl_lso_link_empty || is_home() || is_404() || 'page' == get_option('show_on_front') && ($this->wp_query->queried_object_id == get_option('page_on_front') || $this->wp_query->queried_object_id == get_option('page_for_posts')) || $icl_language_switcher_preview || WPML_Root_Page::is_current_request_root()) {
                 $lang['translated_url'] = $this->language_url($lang['code']);
                 $skip_lang = false;
             } else {
                 $skip_lang = true;
                 unset($w_active_languages[$k]);
             }
         }
         if (!$skip_lang) {
             $w_active_languages[$k] = $lang;
         } else {
             unset($w_active_languages[$k]);
         }
     }
     // 3.
     foreach ($w_active_languages as $k => $v) {
         $lang_code = $w_active_languages[$k]['language_code'] = $w_active_languages[$k]['code'];
         unset($w_active_languages[$k]['code']);
         $native_name = $this->get_display_language_name($lang_code, $lang_code);
         if (!$native_name) {
             $native_name = $w_active_languages[$k]['english_name'];
         }
         $w_active_languages[$k]['native_name'] = $native_name;
         $translated_name = $this->get_display_language_name($lang_code, $current_language);
         if (!$translated_name) {
             $translated_name = $w_active_languages[$k]['english_name'];
         }
         $w_active_languages[$k]['translated_name'] = $translated_name;
         unset($w_active_languages[$k]['display_name']);
         unset($w_active_languages[$k]['english_name']);
         if (isset($w_active_languages[$k]['translated_url'])) {
             $w_active_languages[$k]['url'] = $w_active_languages[$k]['translated_url'];
             unset($w_active_languages[$k]['translated_url']);
         } else {
             $w_active_languages[$k]['url'] = $this->language_url($k);
         }
         $flag = $this->get_flag($lang_code);
         if ($flag->from_template) {
             $wp_upload_dir = wp_upload_dir();
             $flag_url = $wp_upload_dir['baseurl'] . '/flags/' . $flag->flag;
         } else {
             $flag_url = ICL_PLUGIN_URL . '/res/flags/' . $flag->flag;
         }
         $w_active_languages[$k]['country_flag_url'] = $flag_url;
         $w_active_languages[$k]['active'] = $current_language == $lang_code ? '1' : 0;
     }
     // 4. pass GET parameters
     $parameters_copied = apply_filters('icl_lang_sel_copy_parameters', array_map('trim', explode(',', $this->settings['icl_lang_sel_copy_parameters'])));
     if ($parameters_copied) {
         foreach ($_GET as $k => $v) {
             if (in_array($k, $parameters_copied)) {
                 $gets_passed[$k] = $v;
             }
         }
     }
     if (!empty($gets_passed)) {
         $gets_passed = http_build_query($gets_passed);
         foreach ($w_active_languages as $code => $al) {
             if (empty($al['missing'])) {
                 $glue = false !== strpos($w_active_languages[$code]['url'], '?') ? '&' : '?';
                 $w_active_languages[$code]['url'] .= $glue . $gets_passed;
             }
         }
     }
     // restore current $wp_query
     unset($wp_query);
     global $wp_query;
     // make it global again after unset
     $wp_query = clone $_wp_query_back;
     unset($_wp_query_back);
     $w_active_languages = apply_filters('icl_ls_languages', $w_active_languages);
     $w_active_languages = $this->sort_ls_languages($w_active_languages, $template_args);
     // Change the url, in case languages in subdomains are set.
     if ($this->settings['language_negotiation_type'] == 2) {
         foreach ($w_active_languages as $lang => $element) {
             $w_active_languages[$lang]['url'] = $this->convert_url($element['url'], $lang);
         }
     }
     wp_reset_query();
     wp_cache_set($cache_key, $w_active_languages, $cache_group);
     return $w_active_languages;
 }
예제 #9
0
<?php

if (WPML_Root_Page::uses_html_root() || WPML_Root_Page::get_root_id() > 0 || strpos((string) filter_var($_SERVER['REQUEST_URI']), 'wpml_root_page=1') !== false || (bool) filter_input(INPUT_POST, '_wpml_root_page') === true) {
    $root_page_actions = wpml_get_root_page_actions_obj();
    add_action('init', array($root_page_actions, 'wpml_home_url_init'), 0);
    add_filter('wp_page_menu_args', array($root_page_actions, 'wpml_home_url_exclude_root_page_from_menus'));
    add_filter('wp_list_pages_excludes', array($root_page_actions, 'wpml_home_url_exclude_root_page'));
    add_filter('page_attributes_dropdown_pages_args', array($root_page_actions, 'wpml_home_url_exclude_root_page2'));
    add_filter('get_pages', array($root_page_actions, 'wpml_home_url_get_pages'));
    add_action('save_post', array($root_page_actions, 'wpml_home_url_save_post_actions'), 0, 2);
    WPML_Root_Page::init();
}
class WPML_Root_Page
{
    public static function init()
    {
        if (self::get_root_id() > 0) {
            add_filter('template_include', array('WPML_Root_Page', 'wpml_home_url_template_include'));
            add_filter('the_preview', array('WPML_Root_Page', 'front_page_id_filter'));
        }
        $root_page_actions = wpml_get_root_page_actions_obj();
        add_action('icl_set_element_language', array($root_page_actions, 'delete_root_page_lang'), 10, 0);
    }
    /**
     * Checks if the value in $_SERVER['REQUEST_URI] points towards the root page.
     * Therefore this can be used to check if the current request points towards the root page.
     *
     * @return bool
     */
    public static function is_current_request_root()
    {
예제 #10
0
 function get_ls_languages($template_args = array())
 {
     /** @var $wp_query WP_Query */
     global $wp_query, $w_this_lang, $wpml_post_translations, $wpml_term_translations;
     $current_language = $this->get_current_language();
     $default_language = $this->get_default_language();
     $cache_key_args = $template_args ? array_filter($template_args) : array('default');
     $cache_key_args[] = $current_language;
     $cache_key_args[] = $default_language;
     $cache_key_args = array_filter($cache_key_args);
     $cache_key = md5(wp_json_encode($cache_key_args));
     $cache_group = 'ls_languages';
     $found = false;
     $ls_languages = wp_cache_get($cache_key, $cache_group, $found);
     if ($found) {
         return $ls_languages;
     }
     if (is_null($this->wp_query)) {
         $this->set_wp_query();
     }
     // use original wp_query for this
     // backup current $wp_query
     if (!isset($wp_query)) {
         return $this->get_active_languages();
     }
     $_wp_query_back = clone $wp_query;
     unset($wp_query);
     global $wp_query;
     // make it global again after unset
     $wp_query = clone $this->wp_query;
     $w_active_languages = $this->get_active_languages();
     $this_lang = $this->this_lang;
     if ($this_lang == 'all') {
         $w_this_lang = array('code' => 'all', 'english_name' => 'All languages', 'display_name' => __('All languages', 'sitepress'));
     } else {
         $w_this_lang = $this->get_language_details($this_lang);
     }
     if (isset($template_args['skip_missing'])) {
         //override default setting
         $icl_lso_link_empty = !$template_args['skip_missing'];
     } else {
         $icl_lso_link_empty = $this->settings['icl_lso_link_empty'];
     }
     $languages_helper = new WPML_Languages($wpml_term_translations, $this, $wpml_post_translations);
     list($translations, $wp_query) = $languages_helper->get_ls_translations($wp_query, $_wp_query_back, $this->wp_query);
     // 2. determine url
     foreach ($w_active_languages as $k => $lang) {
         $skip_lang = false;
         if (is_singular() || isset($_wp_query_back->query['name']) && isset($_wp_query_back->query['post_type']) || !empty($this->wp_query->queried_object_id) && $this->wp_query->queried_object_id == get_option('page_for_posts')) {
             $this_lang_tmp = $this->this_lang;
             $this->this_lang = $lang['code'];
             $lang_page_on_front = get_option('page_on_front');
             $lang_page_for_posts = get_option('page_for_posts');
             if ($lang_page_on_front) {
                 $lang_page_on_front = icl_object_id($lang_page_on_front, 'page', false, $lang['code']);
             }
             if ($lang_page_for_posts) {
                 $lang_page_for_posts = icl_object_id($lang_page_for_posts, 'page', false, $lang['code']);
             }
             if ('page' === get_option('show_on_front') && !empty($translations[$lang['code']]) && $translations[$lang['code']]->element_id == $lang_page_on_front) {
                 $lang['translated_url'] = $this->language_url($lang['code']);
             } elseif ('page' == get_option('show_on_front') && !empty($translations[$lang['code']]) && $translations[$lang['code']]->element_id && $translations[$lang['code']]->element_id == $lang_page_for_posts) {
                 if ($lang_page_for_posts) {
                     $lang['translated_url'] = get_permalink($lang_page_for_posts);
                 } else {
                     $lang['translated_url'] = $this->language_url($lang['code']);
                 }
             } else {
                 if (!empty($translations[$lang['code']]) && isset($translations[$lang['code']]->post_title)) {
                     $lang['translated_url'] = get_permalink($translations[$lang['code']]->element_id);
                     $lang['missing'] = 0;
                 } else {
                     if ($icl_lso_link_empty) {
                         if (!empty($template_args['link_empty_to'])) {
                             $lang['translated_url'] = str_replace('{%lang}', $lang['code'], $template_args['link_empty_to']);
                         } else {
                             $lang['translated_url'] = $this->language_url($lang['code']);
                         }
                     } else {
                         $skip_lang = true;
                     }
                     $lang['missing'] = 1;
                 }
             }
             $this->this_lang = $this_lang_tmp;
         } elseif (is_category() || is_tax() || is_tag()) {
             global $icl_adjust_id_url_filter_off;
             $icl_adjust_id_url_filter_off = true;
             list($lang, $skip_lang) = $languages_helper->add_tax_url_to_ls_lang($lang, $translations, $icl_lso_link_empty, $skip_lang);
             $icl_adjust_id_url_filter_off = false;
         } elseif (is_author()) {
             global $authordata;
             if (empty($authordata)) {
                 $authordata = get_userdata(get_query_var('author'));
             }
             remove_filter('home_url', array($this, 'home_url'), 1, 4);
             remove_filter('author_link', array($this, 'author_link'));
             list($lang, $skip_lang) = $languages_helper->add_author_url_to_ls_lang($lang, $authordata, $icl_lso_link_empty, $skip_lang);
             add_filter('home_url', array($this, 'home_url'), 1, 4);
             add_filter('author_link', array($this, 'author_link'));
         } elseif (is_archive() && !is_tag()) {
             global $icl_archive_url_filter_off;
             $icl_archive_url_filter_off = true;
             remove_filter('post_type_archive_link', array($this, 'post_type_archive_link_filter'), 10);
             list($lang, $skip_lang) = $languages_helper->add_date_or_cpt_url_to_ls_lang($lang, $this->wp_query, $icl_lso_link_empty, $skip_lang);
             add_filter('post_type_archive_link', array($this, 'post_type_archive_link_filter'), 10, 2);
             $icl_archive_url_filter_off = false;
         } elseif (is_search()) {
             $url_glue = strpos($this->language_url($lang['code']), '?') === false ? '?' : '&';
             $lang['translated_url'] = $this->language_url($lang['code']) . $url_glue . 's=' . urlencode($wp_query->query['s']);
         } else {
             global $icl_language_switcher_preview;
             if ($icl_lso_link_empty || is_home() || is_404() || 'page' === get_option('show_on_front') && ($this->wp_query->queried_object_id == get_option('page_on_front') || $this->wp_query->queried_object_id == get_option('page_for_posts')) || $icl_language_switcher_preview || WPML_Root_Page::is_current_request_root()) {
                 $lang['translated_url'] = $this->language_url($lang['code']);
                 $skip_lang = false;
             } else {
                 $skip_lang = true;
                 unset($w_active_languages[$k]);
             }
         }
         if (!$skip_lang) {
             $w_active_languages[$k] = $lang;
         } else {
             unset($w_active_languages[$k]);
         }
     }
     // 3.
     foreach ($w_active_languages as $k => $v) {
         $w_active_languages[$k] = $languages_helper->get_ls_language($k, $current_language, $w_active_languages[$k]);
     }
     // 4. pass GET parameters
     $parameters_copied = apply_filters('icl_lang_sel_copy_parameters', array_map('trim', explode(',', wpml_get_setting_filter('', 'icl_lang_sel_copy_parameters'))));
     if ($parameters_copied) {
         foreach ($_GET as $k => $v) {
             if (in_array($k, $parameters_copied)) {
                 $gets_passed[$k] = $v;
             }
         }
     }
     if (!empty($gets_passed)) {
         $gets_passed = http_build_query($gets_passed);
         foreach ($w_active_languages as $code => $al) {
             if (empty($al['missing'])) {
                 $glue = false !== strpos($w_active_languages[$code]['url'], '?') ? '&' : '?';
                 $w_active_languages[$code]['url'] .= $glue . $gets_passed;
             }
         }
     }
     // restore current $wp_query
     unset($wp_query);
     global $wp_query;
     // make it global again after unset
     $wp_query = clone $_wp_query_back;
     unset($_wp_query_back);
     $w_active_languages = apply_filters('icl_ls_languages', $w_active_languages);
     $w_active_languages = $languages_helper->sort_ls_languages($w_active_languages, $template_args);
     // Change the url, in case languages in subdomains are set.
     if ($this->settings['language_negotiation_type'] == 2) {
         foreach ($w_active_languages as $lang => $element) {
             $w_active_languages[$lang]['url'] = $this->convert_url($element['url'], $lang);
         }
     }
     wp_reset_query();
     wp_cache_set($cache_key, $w_active_languages, $cache_group);
     return $w_active_languages;
 }
 /**
  * @param WP_Query $q
  *
  * @return mixed
  */
 function wpml_home_url_parse_query($q)
 {
     if (!$q->is_main_query()) {
         return $q;
     }
     if (!WPML_Root_Page::is_current_request_root()) {
         return $q;
     } else {
         remove_action('parse_query', array($this, 'wpml_home_url_parse_query'));
         $request_array = explode('/', $_SERVER["REQUEST_URI"]);
         $sanitized_query = array_pop($request_array);
         $potential_pagination_parameter = array_pop($request_array);
         if (is_numeric($potential_pagination_parameter)) {
             if ($sanitized_query) {
                 $sanitized_query .= '&';
             }
             $sanitized_query .= 'page=' . $potential_pagination_parameter;
         }
         $sanitized_query = str_replace('?', '', $sanitized_query);
         $q->parse_query($sanitized_query);
         add_action('parse_query', array($this, 'wpml_home_url_parse_query'));
         $root_id = $this->get_root_page_id();
         $q->query_vars['page_id'] = $root_id;
         $q->query['page_id'] = $root_id;
         $q->is_page = 1;
         $q->queried_object = new WP_Post(get_post($root_id));
         $q->queried_object_id = $root_id;
         $q->query_vars['error'] = "";
         $q->is_404 = false;
         $q->query['error'] = null;
     }
     return $q;
 }
 public function wpml_root_page_posts_where_filter($where, $post_type)
 {
     global $wpdb;
     $where .= $wpdb->prepare(" AND ID != %d ", WPML_Root_Page::get_root_id());
     return $where;
 }
 /**
  * @param WP_Query $q
  *
  * @return mixed
  */
 function wpml_home_url_parse_query($q)
 {
     if (!$q->is_main_query()) {
         return $q;
     }
     if (!WPML_Root_Page::is_current_request_root()) {
         return $q;
     } else {
         remove_action('parse_query', array($this, 'wpml_home_url_parse_query'));
         $request_array = explode('/', $_SERVER['REQUEST_URI']);
         $sanitized_query = array_pop($request_array);
         $potential_pagination_parameter = array_pop($request_array);
         if (is_numeric($potential_pagination_parameter)) {
             if ($sanitized_query) {
                 $sanitized_query .= '&';
             }
             $sanitized_query .= 'page=' . $potential_pagination_parameter;
         }
         $sanitized_query = str_replace('?', '', $sanitized_query);
         $q->parse_query($sanitized_query);
         $root_id = $this->get_root_page_id();
         add_action('parse_query', array($this, 'wpml_home_url_parse_query'));
         if (false !== $root_id) {
             $q = $this->set_page_query_parameters($q, $root_id);
         } else {
             $front_page = get_option('page_on_front');
             if ($front_page) {
                 $q = $this->set_page_query_parameters($q, $front_page);
             }
         }
     }
     return $q;
 }
예제 #14
0
function webdados_fb_open_graph()
{
    global $webdados_fb_open_graph_plugin_settings, $webdados_fb_open_graph_plugin_name, $webdados_fb_open_graph_plugin_version, $webdados_fb_open_graph_settings;
    //Upgrade
    webdados_fb_open_graph_upgrade();
    //Get options - OLD (until 0.5.4)
    /*foreach($webdados_fb_open_graph_plugin_settings as $key) {
    		$$key=get_option('wonderm00n_open_graph_'.$key);
    	}*/
    //Get options - NEW (after 0.5.4)
    extract($webdados_fb_open_graph_settings);
    //Also set Title Tag?
    $fb_set_title_tag = 0;
    //Additional images
    $fb_image_additional = array();
    $fb_type = 'article';
    if (is_singular()) {
        //It's a Post or a Page or an attachment page - It can also be the homepage if it's set as a page
        global $post;
        $fb_title = esc_attr(strip_tags(stripslashes($post->post_title)));
        //SubHeading
        if ($fb_show_subheading == 1) {
            if (webdados_fb_open_graph_subheadingactive()) {
                if (isset($fb_subheading_position) && $fb_subheading_position == 'before') {
                    $fb_title = trim(trim(get_the_subheading()) . ' - ' . trim($fb_title), ' -');
                } else {
                    $fb_title = trim(trim($fb_title) . ' - ' . trim(get_the_subheading()), ' -');
                }
            }
        }
        $fb_url = get_permalink();
        if (is_front_page()) {
            /* Fix homepage type when it's a static page */
            $fb_url = get_option('home') . (intval($fb_url_add_trailing) == 1 ? '/' : '');
            $fb_type = trim($fb_type_homepage == '' ? 'website' : $fb_type_homepage);
        }
        if (trim($post->post_excerpt) != '') {
            //If there's an excerpt that's what we'll use
            $fb_desc = trim($post->post_excerpt);
        } else {
            //If not we grab it from the content
            $fb_desc = trim($post->post_content);
        }
        $fb_desc = intval($fb_desc_chars) > 0 ? mb_substr(esc_attr(strip_tags(strip_shortcodes(stripslashes($fb_desc)))), 0, $fb_desc_chars) : esc_attr(strip_tags(strip_shortcodes(stripslashes($fb_desc))));
        if (intval($fb_image_show) == 1 || intval($fb_image_show_schema) == 1 || intval($fb_image_show_twitter) == 1) {
            $fb_image = webdados_fb_open_graph_post_image($fb_image_use_specific, $fb_image_use_featured, $fb_image_use_content, $fb_image_use_media, $fb_image_use_default, $fb_image);
        }
        //Author
        $author_id = $post->post_author;
        if ($author_id > 0) {
            $fb_author = get_the_author_meta('facebook', $author_id);
            $fb_author_meta = get_the_author_meta('display_name', $author_id);
            $fb_author_linkrelgp = get_the_author_meta('googleplus', $author_id);
            $fb_author_twitter = get_the_author_meta('twitter', $author_id);
        } else {
            $fb_author = '';
            $fb_author_meta = '';
            $fb_author_linkrelgp = '';
            $fb_author_twitter = '';
        }
        //Author - Hide on pages?
        if (is_page() && $fb_author_hide_on_pages == 1) {
            $fb_author = '';
            $fb_author_meta = '';
            $fb_author_linkrelgp = '';
            $fb_author_twitter = '';
        }
        //Published and Modified time
        if (is_singular('post')) {
            $fb_article_pub_date = get_the_date('c');
            $fb_article_mod_date = get_the_modified_date('c');
        } else {
            $fb_article_dates_show = 0;
            $fb_article_pub_date = '';
            $fb_article_mod_date = '';
        }
        //Categories
        if (is_singular('post')) {
            $cats = get_the_category();
            if (!is_wp_error($cats) && (is_array($cats) && count($cats) > 0)) {
                $fb_sections = array();
                foreach ($cats as $cat) {
                    $fb_sections[] = $cat->name;
                }
            }
        } else {
            $fb_article_sections_show = 0;
        }
        //Business Directory Plugin
        if ($fb_show_businessdirectoryplugin == 1) {
            @(include_once ABSPATH . 'wp-admin/includes/plugin.php');
            if (is_plugin_active('business-directory-plugin/wpbusdirman.php')) {
                global $wpbdp;
                //$bdpaction = _wpbdp_current_action();
                $bdpaction = $wpbdp->controller->get_current_action();
                switch ($bdpaction) {
                    case 'showlisting':
                        //Listing
                        $listing_id = get_query_var('listing') ? wpbdp_get_post_by_slug(get_query_var('listing'))->ID : wpbdp_getv($_GET, 'id', get_query_var('id'));
                        $bdppost = get_post($listing_id);
                        $fb_title = esc_attr(strip_tags(stripslashes($bdppost->post_title))) . ' - ' . $fb_title;
                        $fb_set_title_tag = 1;
                        $fb_url = get_permalink($listing_id);
                        if (trim($bdppost->post_excerpt) != '') {
                            //If there's an excerpt that's what we'll use
                            $fb_desc = trim($bdppost->post_excerpt);
                        } else {
                            //If not we grab it from the content
                            $fb_desc = trim($bdppost->post_content);
                        }
                        $fb_desc = intval($fb_desc_chars) > 0 ? mb_substr(esc_attr(strip_tags(strip_shortcodes(stripslashes($fb_desc)))), 0, $fb_desc_chars) : esc_attr(strip_tags(strip_shortcodes(stripslashes($fb_desc))));
                        if (intval($fb_image_show) == 1 || intval($fb_image_show_schema) == 1 || intval($fb_image_show_twitter) == 1) {
                            $thumbdone = false;
                            if (intval($fb_image_use_featured) == 1) {
                                //Featured
                                if ($id_attachment = get_post_thumbnail_id($bdppost->ID)) {
                                    //There's a featured/thumbnail image for this listing
                                    $fb_image = wp_get_attachment_url($id_attachment, false);
                                    $thumbdone = true;
                                }
                            }
                            if (!$thumbdone) {
                                //Main image loaded
                                if ($thumbnail_id = wpbdp_listings_api()->get_thumbnail_id($bdppost->ID)) {
                                    $fb_image = wp_get_attachment_url($thumbnail_id, false);
                                }
                            }
                        }
                        break;
                    case 'browsecategory':
                        //Categories
                        $term = get_term_by('slug', get_query_var('category'), wpbdp_categories_taxonomy());
                        $fb_title = esc_attr(strip_tags(stripslashes($term->name))) . ' - ' . $fb_title;
                        $fb_set_title_tag = 1;
                        $fb_url = get_term_link($term);
                        if (trim($term->description) != '') {
                            $fb_desc = trim($term->description);
                        }
                        break;
                    case 'main':
                        //Main page
                        //No changes
                        break;
                    default:
                        //No changes
                        break;
                }
            }
        }
    } else {
        global $wp_query;
        //Other pages - Defaults
        $fb_title = esc_attr(strip_tags(stripslashes(get_bloginfo('name'))));
        //$fb_url=get_option('home').(intval($fb_url_add_trailing)==1 ? '/' : ''); //2013-11-4 changed from 'siteurl' to 'home'
        $fb_url = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
        //Not really canonical but will work for now
        //These are only used in posts/pages
        $fb_article_sections_show = 0;
        $fb_article_dates_show = 0;
        $fb_author_show = 0;
        $fb_author_show_meta = 0;
        $fb_author_show_linkrelgp = 0;
        $fb_author_show_twitter = 0;
        switch (trim($fb_desc_homepage)) {
            case 'custom':
                $fb_desc = esc_attr(strip_tags(stripslashes($fb_desc_homepage_customtext)));
                //WPML?
                if (function_exists('icl_object_id') && function_exists('icl_register_string')) {
                    global $sitepress;
                    if (ICL_LANGUAGE_CODE != $sitepress->get_default_language()) {
                        $fb_desc = icl_t('wd-fb-og', 'wd_fb_og_desc_homepage_customtext', $fb_desc);
                    } else {
                        //We got it already
                    }
                }
                break;
            default:
                $fb_desc = esc_attr(strip_tags(stripslashes(get_bloginfo('description'))));
                break;
        }
        if (is_category()) {
            $fb_title = esc_attr(strip_tags(stripslashes(single_cat_title('', false))));
            $term = $wp_query->get_queried_object();
            $fb_url = get_term_link($term, $term->taxonomy);
            $cat_desc = trim(esc_attr(strip_tags(stripslashes(category_description()))));
            if (trim($cat_desc) != '') {
                $fb_desc = $cat_desc;
            }
        } else {
            if (is_tag()) {
                $fb_title = esc_attr(strip_tags(stripslashes(single_tag_title('', false))));
                $term = $wp_query->get_queried_object();
                $fb_url = get_term_link($term, $term->taxonomy);
                $tag_desc = trim(esc_attr(strip_tags(stripslashes(tag_description()))));
                if (trim($tag_desc) != '') {
                    $fb_desc = $tag_desc;
                }
            } else {
                if (is_tax()) {
                    $fb_title = esc_attr(strip_tags(stripslashes(single_term_title('', false))));
                    $term = $wp_query->get_queried_object();
                    $fb_url = get_term_link($term, $term->taxonomy);
                    //WooCommerce
                    if (intval($fb_image_show) == 1 || intval($fb_image_show_schema) == 1 || intval($fb_image_show_twitter) == 1) {
                        if (class_exists('woocommerce') && $fb_wc_usecategthumb == 1 && is_product_category()) {
                            if ($thumbnail_id = get_woocommerce_term_meta($term->term_id, 'thumbnail_id', true)) {
                                if ($image = wp_get_attachment_url($thumbnail_id)) {
                                    $fb_image = $image;
                                }
                            }
                        }
                    }
                } else {
                    if (is_search()) {
                        $fb_title = esc_attr(strip_tags(stripslashes(__('Search for') . ' "' . get_search_query() . '"')));
                        $fb_url = get_search_link();
                    } else {
                        if (is_author()) {
                            $fb_title = esc_attr(strip_tags(stripslashes(get_the_author_meta('display_name', get_query_var('author')))));
                            $fb_url = get_author_posts_url(get_query_var('author'), get_query_var('author_name'));
                        } else {
                            if (is_archive()) {
                                if (is_day()) {
                                    $fb_title = esc_attr(strip_tags(stripslashes(get_query_var('day') . ' ' . single_month_title(' ', false) . ' ' . __('Archives'))));
                                    $fb_url = get_day_link(get_query_var('year'), get_query_var('monthnum'), get_query_var('day'));
                                } else {
                                    if (is_month()) {
                                        $fb_title = esc_attr(strip_tags(stripslashes(single_month_title(' ', false) . ' ' . __('Archives'))));
                                        $fb_url = get_month_link(get_query_var('year'), get_query_var('monthnum'));
                                    } else {
                                        if (is_year()) {
                                            $fb_title = esc_attr(strip_tags(stripslashes(get_query_var('year') . ' ' . __('Archives'))));
                                            $fb_url = get_year_link(get_query_var('year'));
                                        }
                                    }
                                }
                            } else {
                                if (is_front_page()) {
                                    $fb_url = get_option('home') . (intval($fb_url_add_trailing) == 1 ? '/' : '');
                                    $fb_type = trim($fb_type_homepage == '' ? 'website' : $fb_type_homepage);
                                } else {
                                    //Others... Defaults already set up there
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    //og:type for WPML root page?
    if (function_exists('icl_object_id') && function_exists('icl_register_string')) {
        if (class_exists('WPML_Root_Page')) {
            if (WPML_Root_Page::is_current_request_root()) {
                $fb_type = trim($fb_type_homepage == '' ? 'website' : $fb_type_homepage);
            }
        }
    }
    //YOAST?
    if ($fb_show_wpseoyoast == 1) {
        if (defined('WPSEO_VERSION')) {
            $wpseo = WPSEO_Frontend::get_instance();
            //App ID - From our plugin
            //Admin ID - From our plugin
            //Locale - From our plugin
            //Sitename - From our plugin
            //Title - From WPSEO
            $fb_title = strip_tags($wpseo->title(false));
            //Title - SubHeading plugin
            if ($fb_show_subheading == 1) {
                if (webdados_fb_open_graph_subheadingactive()) {
                    if (isset($fb_subheading_position) && $fb_subheading_position == 'before') {
                        $fb_title = trim(trim(get_the_subheading()) . ' - ' . trim($fb_title), ' -');
                    } else {
                        $fb_title = trim(trim($fb_title) . ' - ' . trim(get_the_subheading()), ' -');
                    }
                }
            }
            //URL - From WPSEO
            $fb_url = $wpseo->canonical(false);
            //Description - From WPSEO or our plugin
            $fb_desc_temp = $wpseo->metadesc(false);
            $fb_desc = strip_tags(trim($fb_desc_temp) != '' ? trim($fb_desc_temp) : $fb_desc);
            //Image - From our plugin
        }
    }
    //WooCommerce - Additional product images?
    if (intval($fb_image_show) == 1 && class_exists('woocommerce') && $fb_wc_useproductgallery == 1 && is_product()) {
        global $post;
        $product = new WC_Product($post->ID);
        if ($attachment_ids = $product->get_gallery_attachment_ids()) {
            foreach ($attachment_ids as $attachment_id) {
                if ($image_link = wp_get_attachment_url($attachment_id)) {
                    if (trim($image_link) != '') {
                        $fb_image_additional[] = trim($image_link);
                    }
                }
            }
        }
    }
    //Apply Filters
    $fb_locale = apply_filters('fb_og_locale', $fb_locale);
    $fb_title = apply_filters('fb_og_title', $fb_title);
    $fb_url = apply_filters('fb_og_url', $fb_url);
    $fb_type = apply_filters('fb_og_type', $fb_type);
    $fb_desc = apply_filters('fb_og_desc', $fb_desc);
    $fb_image = apply_filters('fb_og_image', $fb_image);
    $fb_image_additional = apply_filters('fb_og_image_additional', $fb_image_additional);
    //Image size
    $fb_image_size = false;
    if (intval($fb_image_show) == 1 && trim($fb_image) != '') {
        if (intval($fb_image_size_show) == 1) {
            if (isset($GLOBALS['webdados_fb_img_size'])) {
                //Already fetched
                $fb_image_size = $GLOBALS['webdados_fb_img_size'];
            } else {
                $fb_image_size = webdados_fb_open_graph_getimagesize($fb_image);
            }
        }
    } else {
        $fb_image_size_show = 0;
    }
    //No spaces on URLs
    if (isset($fb_url) && trim($fb_url) != '') {
        $fb_url = str_replace(' ', '%20', trim($fb_url));
    }
    if (isset($fb_publisher) && trim($fb_publisher) != '') {
        $fb_publisher = str_replace(' ', '%20', trim($fb_publisher));
    }
    if (isset($fb_publisher_schema) && trim($fb_publisher_schema) != '') {
        $fb_publisher_schema = str_replace(' ', '%20', trim($fb_publisher_schema));
    }
    if (isset($fb_author) && trim($fb_author) != '') {
        $fb_author = str_replace(' ', '%20', trim($fb_author));
    }
    if (isset($fb_author_linkrelgp) && trim($fb_author_linkrelgp) != '') {
        $fb_author_linkrelgp = str_replace(' ', '%20', trim($fb_author_linkrelgp));
    }
    if (isset($fb_image) && trim($fb_image) != '') {
        $fb_image = str_replace(' ', '%20', trim($fb_image));
    }
    if (isset($fb_image_additional) && is_array($fb_image_additional) && count($fb_image_additional)) {
        foreach ($fb_image_additional as $key => $value) {
            $fb_image_additional[$key] = str_replace(' ', '%20', trim($value));
        }
    }
    //If no description let's just add the title as a last resort
    if (trim($fb_desc) == '') {
        $fb_desc = $fb_title;
    }
    $html = '
<!-- START - ' . $webdados_fb_open_graph_plugin_name . ' ' . $webdados_fb_open_graph_plugin_version . ' -->
';
    if (intval($fb_app_id_show) == 1 && trim($fb_app_id) != '') {
        $html .= '<meta property="fb:app_id" content="' . trim(esc_attr($fb_app_id)) . '"/>
';
    }
    if (intval($fb_admin_id_show) == 1 && trim($fb_admin_id) != '') {
        $html .= '<meta property="fb:admins" content="' . trim(esc_attr($fb_admin_id)) . '"/>
';
    }
    if (intval($fb_locale_show) == 1) {
        $html .= '<meta property="og:locale" content="' . trim(esc_attr(trim($fb_locale) != '' ? trim($fb_locale) : trim(get_locale()))) . '"/>
';
    }
    if (intval($fb_sitename_show) == 1) {
        $html .= '<meta property="og:site_name" content="' . trim(esc_attr(get_bloginfo('name'))) . '"/>
';
    }
    if (intval($fb_title_show) == 1) {
        $html .= '<meta property="og:title" content="' . trim(esc_attr($fb_title)) . '"/>
';
    }
    if (intval($fb_set_title_tag) == 1) {
        //Does nothing so far. We try to create the <title> tag but it's too late now
    }
    if (intval($fb_title_show_schema) == 1) {
        $html .= '<meta itemprop="name" content="' . trim(esc_attr($fb_title)) . '"/>
';
    }
    if (intval($fb_title_show_twitter) == 1) {
        $html .= '<meta name="twitter:title" content="' . trim(esc_attr($fb_title)) . '"/>
';
    }
    if (intval($fb_url_show) == 1) {
        $html .= '<meta property="og:url" content="' . trim(esc_attr($fb_url)) . '"/>
';
    }
    if (intval($fb_url_show_twitter) == 1) {
        $html .= '<meta name="twitter:url" content="' . trim(esc_attr($fb_url)) . '"/>
';
    }
    if (intval($fb_url_canonical) == 1) {
        $html .= '<link rel="canonical" href="' . trim(esc_attr($fb_url)) . '"/>
';
    }
    if (intval($fb_type_show) == 1) {
        $html .= '<meta property="og:type" content="' . trim(esc_attr($fb_type)) . '"/>
';
    }
    if (intval($fb_article_dates_show) == 1 && trim($fb_article_pub_date) != '') {
        $html .= '<meta property="article:published_time" content="' . trim(esc_attr($fb_article_pub_date)) . '"/>
';
    }
    if (intval($fb_article_dates_show) == 1 && trim($fb_article_mod_date) != '') {
        $html .= '<meta property="article:modified_time" content="' . trim(esc_attr($fb_article_mod_date)) . '" />
<meta property="og:updated_time" content="' . trim(esc_attr($fb_article_mod_date)) . '" />
';
    }
    if (intval($fb_article_sections_show) == 1 && isset($fb_sections) && is_array($fb_sections) && count($fb_sections) > 0) {
        foreach ($fb_sections as $fb_section) {
            $html .= '<meta property="article:section" content="' . trim(esc_attr($fb_section)) . '"/>
';
        }
    }
    if (intval($fb_publisher_show) == 1 && trim($fb_publisher) != '') {
        $html .= '<meta property="article:publisher" content="' . trim(esc_attr($fb_publisher)) . '"/>
';
    }
    if (intval($fb_publisher_show_schema) == 1 && trim($fb_publisher_schema) != '') {
        $html .= '<link rel="publisher" href="' . trim(esc_attr($fb_publisher_schema)) . '"/>
';
    }
    if (intval($fb_publisher_show_twitter) == 1 && trim($fb_publisher_twitteruser) != '') {
        $html .= '<meta name="twitter:site" content="@' . trim(esc_attr($fb_publisher_twitteruser)) . '"/>
';
    }
    if (intval($fb_author_show) == 1 && $fb_author != '') {
        $html .= '<meta property="article:author" content="' . trim(esc_attr($fb_author)) . '"/>
';
    }
    if (intval($fb_author_show_meta) == 1 && $fb_author_meta != '') {
        $html .= '<meta name="author" content="' . trim(esc_attr($fb_author_meta)) . '"/>
';
    }
    if (intval($fb_author_show_linkrelgp) == 1 && trim($fb_author_linkrelgp) != '') {
        $html .= '<link rel="author" href="' . trim(esc_attr($fb_author_linkrelgp)) . '"/>
';
    }
    if (intval($fb_author_show_twitter) == 1 && (trim($fb_author_twitter) != '' || trim($fb_publisher_twitteruser) != '')) {
        $html .= '<meta name="twitter:creator" content="@' . trim(esc_attr(trim($fb_author_twitter) != '' ? trim($fb_author_twitter) : trim($fb_publisher_twitteruser))) . '"/>
';
    }
    if (intval($fb_desc_show) == 1) {
        $html .= '<meta property="og:description" content="' . trim(esc_attr($fb_desc)) . '"/>
';
    }
    if (intval($fb_desc_show_meta) == 1) {
        $html .= '<meta name="description" content="' . trim(esc_attr($fb_desc)) . '"/>
';
    }
    if (intval($fb_desc_show_schema) == 1) {
        $html .= '<meta itemprop="description" content="' . trim(esc_attr($fb_desc)) . '"/>
';
    }
    if (intval($fb_desc_show_twitter) == 1) {
        $html .= '<meta name="twitter:description" content="' . trim(esc_attr($fb_desc)) . '"/>
';
    }
    if (intval($fb_image_show) == 1 && trim($fb_image) != '') {
        $html .= '<meta property="og:image" content="' . trim(esc_attr($fb_image)) . '"/>
';
    }
    if (intval($fb_image_show) == 1 && isset($fb_image_additional) && is_array($fb_image_additional) && count($fb_image_additional) > 0) {
        foreach ($fb_image_additional as $fb_image_additional_temp) {
            $html .= '<meta property="og:image" content="' . trim(esc_attr($fb_image_additional_temp)) . '"/>
';
        }
    } else {
        //We only show the image size if we only have one image
        if (intval($fb_image_size_show) == 1 && isset($fb_image_size) && is_array($fb_image_size) != '') {
            $html .= '<meta property="og:image:width" content="' . intval(esc_attr($fb_image_size[0])) . '"/>
<meta property="og:image:height" content="' . intval(esc_attr($fb_image_size[1])) . '"/>
';
        }
    }
    if (intval($fb_image_show_schema) == 1 && trim($fb_image) != '') {
        $html .= '<meta itemprop="image" content="' . trim(esc_attr($fb_image)) . '"/>
';
    }
    if (intval($fb_image_show_twitter) == 1 && trim($fb_image) != '') {
        $html .= '<meta name="twitter:image" content="' . trim(esc_attr($fb_image)) . '"/>
';
    }
    if (intval($fb_title_show_twitter) == 1 || intval($fb_url_show_twitter) == 1 || $fb_author_show_twitter == 1 || $fb_publisher_show_twitter == 1 || $fb_image_show_twitter == 1) {
        $html .= '<meta name="twitter:card" content="' . trim(esc_attr($fb_twitter_card_type)) . '"/>
';
    }
    $html .= '<!-- END - ' . $webdados_fb_open_graph_plugin_name . ' -->

';
    echo $html;
}
    public function insert_meta_tags()
    {
        global $webdados_fb, $wp_query;
        //Also set Title Tag? - Needed??
        $fb_set_title_tag = 0;
        //Init values
        $fb_locale = '';
        $fb_title = '';
        $fb_url = '';
        $fb_desc = '';
        $fb_image = '';
        $fb_type = 'article';
        $fb_author = '';
        $fb_author_meta = '';
        $fb_author_linkrelgp = '';
        $fb_author_twitter = '';
        $fb_article_pub_date = '';
        $fb_article_mod_date = '';
        $fb_image_additional = array();
        $fb_additional_tags = array('name' => array(), 'property' => array());
        $fb_publisher = trim($this->options['fb_publisher']);
        $fb_publisher_schema = trim($this->options['fb_publisher_schema']);
        $fb_publisher_twitteruser = trim($this->options['fb_publisher_twitteruser']);
        //Homepage Description
        switch ($this->options['fb_desc_homepage']) {
            case 'custom':
                $fb_desc_homepage = $this->options['fb_desc_homepage_customtext'];
                //WPML?
                if ($webdados_fb->is_wpml_active()) {
                    global $sitepress;
                    if (ICL_LANGUAGE_CODE != $sitepress->get_default_language()) {
                        $fb_desc_homepage = icl_t('wd-fb-og', 'wd_fb_og_desc_homepage_customtext', $fb_desc_homepage);
                    }
                }
                break;
            default:
                $fb_desc_homepage = get_bloginfo('description');
                break;
        }
        //Open tag
        $html = '
<!-- START - ' . WEBDADOS_FB_PLUGIN_NAME . ' ' . WEBDADOS_FB_VERSION . ' -->
';
        if (is_singular()) {
            global $post;
            // Title
            //It's a Post or a Page or an attachment page - It can also be the homepage if it's set as a page
            $fb_title = esc_attr(wp_strip_all_tags(stripslashes($post->post_title), true));
            //SubHeading
            if (isset($this->options['fb_show_subheading']) && intval($this->options['fb_show_subheading']) == 1 && $webdados_fb->is_subheading_plugin_active()) {
                if (isset($this->options['fb_subheading_position']) && $this->options['fb_subheading_position'] == 'before') {
                    $fb_title = trim(trim(get_the_subheading()) . ' - ' . trim($fb_title), ' -');
                } else {
                    $fb_title = trim(trim($fb_title) . ' - ' . trim(get_the_subheading()), ' -');
                }
            }
            // URL
            $fb_url = get_permalink();
            // Type if it's a homepage page
            if (is_front_page()) {
                /* Fix homepage type when it's a static page */
                $fb_url = get_option('home') . (intval($this->options['fb_url_add_trailing']) == 1 ? '/' : '');
                $fb_type = trim($this->options['fb_type_homepage'] == '' ? 'website' : $this->options['fb_type_homepage']);
            }
            // Description
            if (trim($post->post_excerpt) != '') {
                //If there's an excerpt that's what we'll use
                $fb_desc = trim($post->post_excerpt);
            } else {
                //If not we grab it from the content
                $fb_desc = trim($post->post_content);
            }
            // Image
            if (intval($this->options['fb_image_show']) == 1 || intval($this->options['fb_image_show_schema']) == 1 || intval($this->options['fb_image_show_twitter']) == 1) {
                $fb_image = $this->get_post_image();
            }
            // Author
            $author_id = $post->post_author;
            if ($author_id > 0 && !(is_page() && intval($this->options['fb_author_hide_on_pages']) == 1)) {
                $fb_author = get_the_author_meta('facebook', $author_id);
                $fb_author_meta = get_the_author_meta('display_name', $author_id);
                $fb_author_linkrelgp = get_the_author_meta('googleplus', $author_id);
                $fb_author_twitter = get_the_author_meta('twitter', $author_id);
            }
            //Published and Modified time - We should check this out and maybe have it for any kind of post...
            if (is_singular('post')) {
                $fb_article_pub_date = get_the_date('c');
                $fb_article_mod_date = get_the_modified_date('c');
            } else {
                //Reset dates show because we're not on posts
                $this->options['fb_article_dates_show'] = 0;
            }
            //Sections
            if (is_singular('post')) {
                $cats = get_the_category();
                if (!is_wp_error($cats) && (is_array($cats) && count($cats) > 0)) {
                    $fb_sections = array();
                    foreach ($cats as $cat) {
                        $fb_sections[] = $cat->name;
                    }
                }
            } else {
                $this->options['fb_article_sections_show'] = 0;
            }
            // Business Directory Plugin
            if (isset($this->options['fb_show_businessdirectoryplugin']) && $webdados_fb->is_business_directory_active()) {
                global $wpbdp;
                $bdp_action = wpbdp_current_action();
                $bdp_disable_cpt = wpbdp_get_option('disable-cpt');
                $current_view_object = $wpbdp->dispatcher->current_view_object();
                switch ($bdp_action) {
                    case 'show_listing':
                        $fb_title = trim(esc_attr(wp_strip_all_tags(stripslashes($this->post->post_title), true)) . ' - ' . $fb_title, ' -');
                        $fb_set_title_tag = 1;
                        $fb_url = get_permalink($this->post->ID);
                        if (trim($this->post->post_excerpt) != '') {
                            //If there's an excerpt that's what we'll use
                            $fb_desc = trim($this->post->post_excerpt);
                        } else {
                            //If not we grab it from the content
                            $fb_desc = trim($this->post->post_content);
                        }
                        if (intval($this->options['fb_image_show']) == 1 || intval($this->options['fb_image_show_schema']) == 1 || intval($this->options['fb_image_show_twitter']) == 1) {
                            $thumbdone = false;
                            if (intval($this->options['fb_image_use_featured']) == 1) {
                                //Featured
                                if ($id_attachment = get_post_thumbnail_id($this->post->ID)) {
                                    //There's a featured/thumbnail image for this listing
                                    $fb_image = wp_get_attachment_url($id_attachment, false);
                                    $thumbdone = true;
                                } else {
                                }
                            }
                            if (!$thumbdone) {
                                //Main image loaded
                                if ($thumbnail_id = wpbdp_listings_api()->get_thumbnail_id($this->post->ID)) {
                                    $fb_image = wp_get_attachment_url($thumbnail_id, false);
                                    $thumbdone = true;
                                }
                            }
                        }
                }
            }
            // WooCommerce
            if ($webdados_fb->is_woocommerce_active() && is_product()) {
                $fb_type = 'product';
                $product = new WC_Product($post->ID);
                //Price
                $fb_additional_tags['property']['og_price_amount'] = array($product->get_price_including_tax());
                if (function_exists('get_woocommerce_currency')) {
                    $fb_additional_tags['property']['og_price_currency'] = array(get_woocommerce_currency());
                }
                $fb_additional_tags['name']['twitter_label1'] = array(__('Price', 'wd-fb-og'));
                if (function_exists('get_woocommerce_currency')) {
                    $fb_additional_tags['name']['twitter_data1'] = array($product->get_price_including_tax() . ' ' . get_woocommerce_currency());
                }
                //Additional product images?
                if (intval($this->options['fb_image_show']) == 1 && $this->options['fb_wc_useproductgallery'] == 1) {
                    if ($attachment_ids = $product->get_gallery_attachment_ids()) {
                        foreach ($attachment_ids as $attachment_id) {
                            if ($image_link = wp_get_attachment_url($attachment_id)) {
                                if (trim($image_link) != '') {
                                    $fb_image_additional[] = array('fb_image' => trim($image_link), 'png_overlay' => intval($this->options['fb_wc_usepg_png_overlay']) ? true : false);
                                }
                            }
                        }
                    }
                }
            }
        } else {
            //Other pages - Defaults
            $fb_title = esc_attr(wp_strip_all_tags(stripslashes(get_bloginfo('name')), true));
            $fb_url = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
            //Not really canonical but will work for now
            $fb_image = trim($this->options['fb_image']);
            $this->options['fb_article_sections_show'] = 0;
            $this->options['fb_article_dates_show'] = 0;
            $this->options['fb_author_show'] = 0;
            $this->options['fb_author_show_meta'] = 0;
            $this->options['fb_author_show_linkrelgp'] = 0;
            $this->options['fb_author_show_twitter'] = 0;
            $this->options['fb_author_show_twitter'] = 0;
            //Category
            if (is_category()) {
                $fb_title = esc_attr(wp_strip_all_tags(stripslashes(single_cat_title('', false)), true));
                $term = $wp_query->get_queried_object();
                $fb_url = get_term_link($term, $term->taxonomy);
                $cat_desc = trim(esc_attr(wp_strip_all_tags(stripslashes(category_description()), true)));
                if (trim($cat_desc) != '') {
                    $fb_desc = $cat_desc;
                }
            } else {
                if (is_tag()) {
                    $fb_title = esc_attr(wp_strip_all_tags(stripslashes(single_tag_title('', false)), true));
                    $term = $wp_query->get_queried_object();
                    $fb_url = get_term_link($term, $term->taxonomy);
                    $tag_desc = trim(esc_attr(wp_strip_all_tags(stripslashes(tag_description()), true)));
                    if (trim($tag_desc) != '') {
                        $fb_desc = $tag_desc;
                    }
                } else {
                    if (is_tax()) {
                        $fb_title = esc_attr(wp_strip_all_tags(stripslashes(single_term_title('', false)), true));
                        $term = $wp_query->get_queried_object();
                        $fb_url = get_term_link($term, $term->taxonomy);
                        $tax_desc = trim(esc_attr(wp_strip_all_tags(stripslashes(term_description()), true)));
                        if (trim($tax_desc) != '') {
                            $fb_desc = $tag_desc;
                        }
                        //WooCommerce
                        if ($webdados_fb->is_woocommerce_active() && intval($this->options['fb_wc_usecategthumb']) == 1 && is_product_category()) {
                            if (intval($this->options['fb_image_show']) == 1 || intval($this->options['fb_image_show_schema']) == 1 || intval($this->options['fb_image_show_twitter']) == 1) {
                                if ($thumbnail_id = get_woocommerce_term_meta($term->term_id, 'thumbnail_id', true)) {
                                    if ($image = wp_get_attachment_url($thumbnail_id)) {
                                        $fb_image = $image;
                                    }
                                }
                            }
                        }
                    } else {
                        if (is_search()) {
                            $fb_title = esc_attr(wp_strip_all_tags(stripslashes(__('Search for', 'wd-fb-og') . ' "' . get_search_query() . '"'), true));
                            $fb_url = get_search_link();
                        } else {
                            if (is_author()) {
                                $fb_title = esc_attr(wp_strip_all_tags(stripslashes(get_the_author_meta('display_name', get_query_var('author'))), true));
                                $fb_url = get_author_posts_url(get_query_var('author'), get_query_var('author_name'));
                            } else {
                                if (is_archive()) {
                                    if (is_day()) {
                                        $fb_title = esc_attr(wp_strip_all_tags(stripslashes(get_query_var('day') . ' ' . single_month_title(' ', false) . ' ' . __('Archives', 'wd-fb-og')), true));
                                        $fb_url = get_day_link(get_query_var('year'), get_query_var('monthnum'), get_query_var('day'));
                                    } else {
                                        if (is_month()) {
                                            $fb_title = esc_attr(wp_strip_all_tags(stripslashes(single_month_title(' ', false) . ' ' . __('Archives', 'wd-fb-og')), true));
                                            $fb_url = get_month_link(get_query_var('year'), get_query_var('monthnum'));
                                        } else {
                                            if (is_year()) {
                                                $fb_title = esc_attr(wp_strip_all_tags(stripslashes(get_query_var('year') . ' ' . __('Archives', 'wd-fb-og')), true));
                                                $fb_url = get_year_link(get_query_var('year'));
                                            }
                                        }
                                    }
                                } else {
                                    if (is_front_page()) {
                                        $fb_url = get_option('home') . (intval($this->options['fb_url_add_trailing']) == 1 ? '/' : '');
                                        $fb_type = trim($this->options['fb_type_homepage'] == '' ? 'website' : $this->options['fb_type_homepage']);
                                        $fb_desc = $fb_desc_homepage;
                                    } else {
                                        //Others... Defaults already set up there
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        //og:type for WPML root page?
        if ($webdados_fb->is_wpml_active()) {
            if (class_exists('WPML_Root_Page')) {
                if (WPML_Root_Page::is_current_request_root()) {
                    $fb_type = trim($this->options['fb_type_homepage'] == '' ? 'website' : $this->options['fb_type_homepage']);
                }
            }
        }
        //Default description, if empty until now
        if (trim($fb_desc) == '') {
            switch ($this->options['fb_desc_default_option']) {
                case 'custom':
                    $fb_desc = $this->options['fb_desc_default'];
                    //WPML?
                    if ($webdados_fb->is_wpml_active()) {
                        global $sitepress;
                        if (ICL_LANGUAGE_CODE != $sitepress->get_default_language()) {
                            $fb_desc = icl_t('wd-fb-og', 'wd_fb_og_fb_desc_default', $fb_desc);
                        }
                    }
                    break;
                default:
                    $fb_desc = $fb_desc_homepage;
                    break;
            }
        }
        //Trim description
        $fb_desc = trim(str_replace('&nbsp;', ' ', $fb_desc));
        //Non-breaking spaces are usefull on a meta description. We'll just convert them to normal spaces to really trim it
        $fb_desc = trim(intval($this->options['fb_desc_chars']) > 0 ? mb_substr(wp_strip_all_tags(strip_shortcodes(stripslashes($fb_desc), true)), 0, intval($this->options['fb_desc_chars'])) : wp_strip_all_tags(strip_shortcodes(stripslashes($fb_desc), true)));
        //YOAST SEO?
        if ($this->options['fb_show_wpseoyoast'] == 1) {
            if ($webdados_fb->is_yoast_seo_active()) {
                $wpseo = WPSEO_Frontend::get_instance();
                //Title
                $fb_title_temp = $wpseo->title(false);
                $fb_title = wp_strip_all_tags(trim($fb_title_temp) != '' ? trim($fb_title_temp) : $fb_title, true);
                //Title - SubHeading plugin
                if ($fb_title_temp != '' && $this->options['fb_show_subheading'] == 1) {
                    if ($webdados_fb->is_subheading_plugin_active()) {
                        if (isset($this->options['fb_subheading_position']) && $this->options['fb_subheading_position'] == 'before') {
                            $fb_title = trim(trim(get_the_subheading()) . ' - ' . trim($fb_title), ' -');
                        } else {
                            $fb_title = trim(trim($fb_title) . ' - ' . trim(get_the_subheading()), ' -');
                        }
                    }
                }
                //URL
                $fb_url_temp = $wpseo->canonical(false);
                $fb_url = wp_strip_all_tags(trim($fb_url_temp) != '' ? trim($fb_url_temp) : $fb_url, true);
                //Description
                $fb_desc_temp = $wpseo->metadesc(false);
                $fb_desc = wp_strip_all_tags(trim($fb_desc_temp) != '' ? trim($fb_desc_temp) : $fb_desc, true);
            }
        }
        //All in One SEO Pack?
        if ($this->options['fb_show_aioseop'] == 1) {
            if ($webdados_fb->is_aioseop_active()) {
                global $aiosp;
                //Title - Why are we getting the first post title on archives and homepage...?!?
                $fb_title_temp = $aiosp->orig_title;
                $fb_title = wp_strip_all_tags(trim($fb_title_temp) != '' ? trim($fb_title_temp) : $fb_title, true);
                //Title - SubHeading plugin
                if ($fb_title_temp != '' && $this->options['fb_show_subheading'] == 1) {
                    if ($webdados_fb->is_subheading_plugin_active()) {
                        if (isset($this->options['fb_subheading_position']) && $this->options['fb_subheading_position'] == 'before') {
                            $fb_title = trim(trim(get_the_subheading()) . ' - ' . trim($fb_title), ' -');
                        } else {
                            $fb_title = trim(trim($fb_title) . ' - ' . trim(get_the_subheading()), ' -');
                        }
                    }
                }
                //URL - See aioseop_class.php 3898 - We have a problem because wp_query is not the same right now
                /*$fb_url_temp = '';
                				$aioseop_options = get_option( 'aioseop_options' );
                				$opts = $aiosp->meta_opts;
                				var_dump($wp_query);
                				$show_page = true;
                				if ( ! empty( $aioseop_options['aiosp_no_paged_canonical_links'] ) ) {
                					$show_page = false;
                				}
                				if ( $aioseop_options['aiosp_can'] ) {
                					if ( ! empty( $aioseop_options['aiosp_customize_canonical_links'] ) && ! empty( $opts['aiosp_custom_link'] ) ) {
                						$fb_url_temp = $opts['aiosp_custom_link'];
                					}
                					if ( empty( $url ) ) {
                						$fb_url_temp = $aiosp->aiosp_mrt_get_url( $wp_query, $show_page );
                					}
                		
                					$fb_url_temp = $aiosp->validate_url_scheme( $fb_url_temp );
                		
                					$fb_url_temp = apply_filters( 'aioseop_canonical_url', $fb_url_temp );
                				}
                				var_dump($fb_url_temp);
                				$fb_url = wp_strip_all_tags( trim($fb_url_temp)!='' ? trim($fb_url_temp) : $fb_url, true);*/
                //Description - Why are we getting the first post description on archives and homepage...?!?
                if (is_home() && !is_front_page()) {
                    $post = aiosp_common::get_blog_page();
                } else {
                    $post = $aiosp->get_queried_object();
                }
                $fb_desc_temp = apply_filters('aioseop_description', $aiosp->get_main_description($post));
                $fb_desc = wp_strip_all_tags(trim($fb_desc_temp) != '' ? trim($fb_desc_temp) : $fb_desc, true);
            }
        }
        //Apply Filters
        $fb_locale = apply_filters('fb_og_locale', $fb_locale);
        $fb_title = apply_filters('fb_og_title', $fb_title);
        $fb_url = apply_filters('fb_og_url', $fb_url);
        $fb_type = apply_filters('fb_og_type', $fb_type);
        $fb_desc = apply_filters('fb_og_desc', $fb_desc);
        $fb_image = apply_filters('fb_og_image', $fb_image);
        $fb_image_additional = apply_filters('fb_og_image_additional', $fb_image_additional);
        //Image size
        $fb_image_size = false;
        if (intval($this->options['fb_image_show']) == 1 && trim($fb_image) != '') {
            if (intval($this->options['fb_image_size_show']) == 1) {
                if (isset($this->image_size) && is_array($this->image_size)) {
                    //Already fetched
                    $fb_image_size = $this->image_size;
                } else {
                    $fb_image_size = $this->get_open_graph_image_size($fb_image);
                }
            }
        } else {
            $this->options['fb_image_show'] = 0;
        }
        //Image overlay - Single?
        if (intval($this->options['fb_image_show']) == 1 && intval($this->options['fb_image_overlay']) == 1 && apply_filters('fb_og_image_overlay', true, $fb_image)) {
            //Single
            $temp_fb_image_overlay = $this->get_image_with_overlay($fb_image);
            if ($temp_fb_image_overlay['overlay']) {
                $fb_image = $temp_fb_image_overlay['fb_image'];
                //We know the exact size now. We better just show it, right?
                $this->options['fb_image_size_show'] = 1;
                $fb_image_size = array(WEBDADOS_FB_W, WEBDADOS_FB_H);
            }
            //Additional
            if (isset($fb_image_additional) && is_array($fb_image_additional) && count($fb_image_additional) > 0) {
                foreach ($fb_image_additional as $key => $value) {
                    if ($value['png_overlay']) {
                        $temp_fb_image_overlay = $this->get_image_with_overlay($value['fb_image']);
                        if ($temp_fb_image_overlay['overlay']) {
                            $fb_image_additional[$key]['fb_image'] = $temp_fb_image_overlay['fb_image'];
                        }
                    }
                }
            }
        }
        //No spaces on URLs
        if (isset($fb_url) && trim($fb_url) != '') {
            $fb_url = str_replace(' ', '%20', trim($fb_url));
        }
        if (isset($fb_publisher) && trim($fb_publisher) != '') {
            $fb_publisher = str_replace(' ', '%20', trim($fb_publisher));
        }
        if (isset($fb_publisher_schema) && trim($fb_publisher_schema) != '') {
            $fb_publisher_schema = str_replace(' ', '%20', trim($fb_publisher_schema));
        }
        if (isset($fb_author) && trim($fb_author) != '') {
            $fb_author = str_replace(' ', '%20', trim($fb_author));
        }
        if (isset($fb_author_linkrelgp) && trim($fb_author_linkrelgp) != '') {
            $fb_author_linkrelgp = str_replace(' ', '%20', trim($fb_author_linkrelgp));
        }
        if (isset($fb_image) && trim($fb_image) != '') {
            $fb_image = str_replace(' ', '%20', trim($fb_image));
        }
        if (isset($fb_image_additional) && is_array($fb_image_additional) && count($fb_image_additional)) {
            foreach ($fb_image_additional as $key => $value) {
                $fb_image_additional[$key]['fb_image'] = str_replace(' ', '%20', trim($value['fb_image']));
            }
        }
        //If there's still no description let's just add the title as a last resort
        if (trim($fb_desc) == '') {
            $fb_desc = $fb_title;
        }
        //Print tags
        // Facebook
        $html .= ' <!-- Facebook Open Graph -->
';
        //Locale
        if (intval($this->options['fb_locale_show']) == 1) {
            $html .= '  <meta property="og:locale" content="' . trim(esc_attr(trim($this->options['fb_locale']) != '' ? trim($this->options['fb_locale']) : trim(get_locale()))) . '"/>
';
        }
        //Site name
        if (intval($this->options['fb_sitename_show']) == 1) {
            $html .= '  <meta property="og:site_name" content="' . trim(esc_attr(get_bloginfo('name'))) . '"/>
';
        }
        //Title
        if (intval($this->options['fb_title_show']) == 1 && trim($fb_title) != '') {
            $html .= '  <meta property="og:title" content="' . trim(esc_attr($fb_title)) . '"/>
';
        }
        //URL
        if (intval($this->options['fb_url_show']) == 1 && trim($fb_url) != '') {
            $html .= '  <meta property="og:url" content="' . trim(esc_attr($fb_url)) . '"/>
';
        }
        //Type
        if (intval($this->options['fb_type_show']) == 1 && trim($fb_type) != '') {
            $html .= '  <meta property="og:type" content="' . trim(esc_attr($fb_type)) . '"/>
';
        }
        //Description
        if (intval($this->options['fb_desc_show']) == 1 && trim($fb_desc) != '') {
            $html .= '  <meta property="og:description" content="' . trim(esc_attr($fb_desc)) . '"/>
';
        }
        //Image
        if (intval($this->options['fb_image_show']) == 1 && trim($fb_image) != '') {
            $html .= '  <meta property="og:image" content="' . trim(esc_attr($fb_image)) . '"/>
';
        }
        //Additional Images
        if (intval($this->options['fb_image_show']) == 1 && isset($fb_image_additional) && is_array($fb_image_additional) && count($fb_image_additional) > 0) {
            foreach ($fb_image_additional as $fb_image_additional_temp) {
                $html .= '  <meta property="og:image" content="' . trim(esc_attr($fb_image_additional_temp['fb_image'])) . '"/>
';
            }
        } else {
            //Image Size - We only show the image size if we only have one image
            if (intval($this->options['fb_image_size_show']) == 1 && isset($fb_image_size) && is_array($fb_image_size)) {
                $html .= '  <meta property="og:image:width" content="' . intval(esc_attr($fb_image_size[0])) . '"/>
  <meta property="og:image:height" content="' . intval(esc_attr($fb_image_size[1])) . '"/>
';
            }
        }
        //Dates
        if (intval($this->options['fb_article_dates_show']) == 1 && trim($fb_article_pub_date) != '') {
            $html .= '  <meta property="article:published_time" content="' . trim(esc_attr($fb_article_pub_date)) . '"/>
';
        }
        if (intval($this->options['fb_article_dates_show']) == 1 && trim($fb_article_mod_date) != '') {
            $html .= '  <meta property="article:modified_time" content="' . trim(esc_attr($fb_article_mod_date)) . '" />
  <meta property="og:updated_time" content="' . trim(esc_attr($fb_article_mod_date)) . '" />
';
        }
        //Sections
        if (intval($this->options['fb_article_sections_show']) == 1 && isset($fb_sections) && is_array($fb_sections) && count($fb_sections) > 0) {
            foreach ($fb_sections as $fb_section) {
                $html .= '  <meta property="article:section" content="' . trim(esc_attr($fb_section)) . '"/>
';
            }
        }
        //Author
        if (intval($this->options['fb_author_show']) == 1 && $fb_author != '') {
            $html .= '  <meta property="article:author" content="' . trim(esc_attr($fb_author)) . '"/>
';
        }
        //Publisher
        if (intval($this->options['fb_publisher_show']) == 1 && trim($fb_publisher) != '') {
            $html .= '  <meta property="article:publisher" content="' . trim(esc_attr($fb_publisher)) . '"/>
';
        }
        //App ID
        if (intval($this->options['fb_app_id_show']) == 1 && trim($this->options['fb_app_id']) != '') {
            $html .= '  <meta property="fb:app_id" content="' . trim(esc_attr($this->options['fb_app_id'])) . '"/>
';
        }
        //Admins
        if (intval($this->options['fb_admin_id_show']) == 1 && trim($this->options['fb_admin_id']) != '') {
            $html .= '  <meta property="fb:admins" content="' . trim(esc_attr($this->options['fb_admin_id'])) . '"/>
';
        }
        // Schema
        $html .= ' <!-- Google+ / Schema.org -->
';
        //Title
        if (intval($this->options['fb_title_show_schema']) == 1 && trim($fb_title) != '') {
            $html .= '  <meta itemprop="name" content="' . trim(esc_attr($fb_title)) . '"/>
';
        }
        //Description
        if (intval($this->options['fb_desc_show_schema']) == 1 && trim($fb_desc) != '') {
            $html .= '  <meta itemprop="description" content="' . trim(esc_attr($fb_desc)) . '"/>
';
        }
        //Image
        if (intval($this->options['fb_image_show_schema']) == 1 && trim($fb_image) != '') {
            $html .= '  <meta itemprop="image" content="' . trim(esc_attr($fb_image)) . '"/>
';
        }
        //Author
        if (intval($this->options['fb_author_show_linkrelgp']) == 1 && trim($fb_author_linkrelgp) != '') {
            $html .= '  <link rel="author" href="' . trim(esc_attr($fb_author_linkrelgp)) . '"/>
';
        }
        //Publisher
        if (intval($this->options['fb_publisher_show_schema']) == 1 && trim($fb_publisher_schema) != '') {
            $html .= '  <link rel="publisher" href="' . trim(esc_attr($fb_publisher_schema)) . '"/>
';
        }
        // Twitter
        $html .= ' <!-- Twitter Cards -->
';
        //Title
        if (intval($this->options['fb_title_show_twitter']) == 1 && trim($fb_title) != '') {
            $html .= '  <meta name="twitter:title" content="' . trim(esc_attr($fb_title)) . '"/>
';
        }
        //URL
        if (intval($this->options['fb_url_show_twitter']) == 1 && trim($fb_url) != '') {
            $html .= '  <meta name="twitter:url" content="' . trim(esc_attr($fb_url)) . '"/>
';
        }
        //Description
        if (intval($this->options['fb_desc_show_twitter']) == 1 && trim($fb_desc) != '') {
            $html .= '  <meta name="twitter:description" content="' . trim(esc_attr($fb_desc)) . '"/>
';
        }
        //Image
        if (intval($this->options['fb_image_show_twitter']) == 1 && trim($fb_image) != '') {
            $html .= '  <meta name="twitter:image" content="' . trim(esc_attr($fb_image)) . '"/>
';
        }
        //Twitter Card
        if (intval($this->options['fb_title_show_twitter']) == 1 || intval($this->options['fb_url_show_twitter']) == 1 || intval($this->options['fb_desc_show_twitter']) == 1 || intval($this->options['fb_publisher_show_twitter']) == 1 || intval($this->options['fb_image_show_twitter']) == 1) {
            $html .= '  <meta name="twitter:card" content="' . trim(esc_attr($this->options['fb_twitter_card_type'])) . '"/>
';
        }
        //Author
        if (intval($this->options['fb_author_show_twitter']) == 1 && trim($fb_author_twitter) != '') {
            $html .= '  <meta name="twitter:creator" content="@' . trim(esc_attr($fb_author_twitter)) . '"/>
';
        }
        //Publisher
        if (intval($this->options['fb_publisher_show_twitter']) == 1 && trim($fb_publisher_twitteruser) != '') {
            $html .= '  <meta name="twitter:site" content="@' . trim(esc_attr($fb_publisher_twitteruser)) . '"/>
';
        }
        // SEO
        $html .= ' <!-- SEO -->
';
        //Title
        if (intval($fb_set_title_tag) == 1 && trim($fb_title) != '') {
            //Does nothing so far. We try to create the <title> tag but it's too late now
            //We should use wp_title(), but do we want to? This is only because Business Directory Plugin and they seem to have it covered by now...
        }
        //URL
        if (intval($this->options['fb_url_canonical']) == 1) {
            $html .= '  <link rel="canonical" href="' . trim(esc_attr($fb_url)) . '"/>
';
        }
        //Description
        if (intval($this->options['fb_desc_show_meta']) == 1 && trim($fb_desc) != '') {
            $html .= '  <meta name="description" content="' . trim(esc_attr($fb_desc)) . '"/>
';
        }
        //Author
        if (intval($this->options['fb_author_show_meta']) == 1 && $fb_author_meta != '') {
            $html .= '  <meta name="author" content="' . trim(esc_attr($fb_author_meta)) . '"/>
';
        }
        //Publisher
        if (intval($this->options['fb_publisher_show_meta']) == 1) {
            $html .= '  <meta name="publisher" content="' . trim(esc_attr(get_bloginfo('name'))) . '"/>
';
        }
        // SEO
        $html .= ' <!-- Misc. tags -->
';
        foreach ($fb_additional_tags as $type => $tags) {
            foreach ($tags as $tag => $values) {
                foreach ($values as $value) {
                    $html .= '  <meta ' . $type . '="' . str_replace('_', ':', trim($tag)) . '" content="' . trim(esc_attr($value)) . '"/>
';
                }
            }
        }
        //Close tag
        $html .= '<!-- END - ' . WEBDADOS_FB_PLUGIN_NAME . ' ' . WEBDADOS_FB_VERSION . ' -->

';
        echo $html;
    }