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()) { $fb_title .= ' - ' . 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 } } } } } } } } //If no description let's just add the title if (trim($fb_desc) == '') { $fb_desc = $fb_title; } //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()) { $fb_title .= ' - ' . 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_title = apply_filters('fb_og_title', $fb_title); $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); $fb_locale = apply_filters('fb_og_locale', $fb_locale); $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)); } } $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:src" 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 __construct($action = '') { $this->action = $action; if ('showlisting' == $this->action) { $this->listing_id = get_query_var('listing') ? wpbdp_get_post_by_slug(get_query_var('listing'))->ID : wpbdp_getv($_GET, 'id', get_query_var('id')); add_filter('get_the_time', array(&$this, 'listing_page__get_the_time'), 10, 2); add_filter('get_the_date', array(&$this, 'listing_page__get_the_date'), 10, 2); add_filter('get_the_modified_time', array(&$this, 'listing_page__get_the_modified_time'), 10, 2); add_filter('get_the_modified_date', array(&$this, 'listing_page__get_the_modified_date'), 10, 2); } }
function listing_opentags() { $listing_id = get_query_var('listing') ? wpbdp_get_post_by_slug(get_query_var('listing'))->ID : wpbdp_getv($_GET, 'id', get_query_var('id')); $listing = WPBDP_Listing::get($listing_id); if (!$listing) { return; } echo '<meta property="og:type" content="website" />'; echo '<meta property="og:title" content="' . esc_attr(WPBDP_SEO::listing_title($listing_id)) . '" />'; echo '<meta property="og:url" content="' . esc_url($listing->get_permalink()) . '" />'; echo '<meta property="og:description" content="' . esc_attr(WPBDP_SEO::listing_og_description($listing_id)) . '" />'; if ($thumbnail_id = $listing->get_thumbnail_id()) { if ($img = wp_get_attachment_image_src($thumbnail_id, 'wpbdp-large')) { echo '<meta property="og:image" content="' . $img[0] . '" />'; } } }