<?php
function wpfresh5_get_social_networks() {
	$networks = array(
		'facebook' => array(
			'label' => 'Facebook Share',
			'text' => 'Share',
			'value' => 'facebook',
			'icon' => 'facebook',
			'url' => 'https://www.facebook.com/sharer.php?u={url}'
		),
		'twitter' => array(
			'label' => 'Twitter',
			'text' => 'Tweet',
			'value' => 'twitter',
			'icon' => 'twitter',
			'url' => 'https://twitter.com/intent/tweet?url={url}&text={title}'
		),
		'googleplus' => array(
			'label' => 'Google +',
			'text' => 'Share',
			'value' => 'googleplus',
			'icon' => 'google-plus',
			'url' => 'https://plus.google.com/share?url={url}'
		),
		'pinterest' => array(
			'label' => 'Pinterest',
			'text' => 'Pin it',
			'value' => 'pinterest',
			'icon' => 'pinterest',
			'url' => 'https://pinterest.com/pin/create/bookmarklet/?media={img}&url={url}&is_video=0&description={title}'
		),
		'linkedin' => array(
			'label' => 'Linkedin',
			'text' => 'Share',
			'value' => 'linkedin',
			'icon' => 'linkedin',
			'url' => 'https://www.linkedin.com/shareArticle?url={url}&title={title}'
		),
		'digg' => array(
			'label' => 'Digg',
			'text' => 'Share',
			'value' => 'digg',
			'icon' => 'digg',
			'url' => 'http://digg.com/submit?url={url}&title={title}'
		),
		'reddit' => array(
			'label' => 'Reddit',
			'text' => 'Share',
			'value' => 'reddit',
			'icon' => 'reddit',
			'url' => 'https://reddit.com/submit?url={url}&title={title}'
		),
	);
	return $networks;
}

add_filter( 'the_content', 'wpfresh5_social_btns' );

function wpfresh5_social_btns( $content ) {
	$show = wpfresh5_get_settings( array( 'social', 'share', 'show' ) );
	if( !$show )
		return $content;
	$post_types = wpfresh5_get_settings( array( 'social', 'share', 'post_types' ) );
	if( empty ( $post_types ) )
		return $content;
	// var_dump($post_types);
	$post_types = array_keys( $post_types );
	if( !is_singular( $post_types ) )
		return $content;
	$networks = wpfresh5_get_settings( array( 'social', 'share', 'networks' ) );
	// var_dump($networks);

	if( empty ( $networks ) )
		return $content;
	$snetworks = wpfresh5_get_social_networks();
	$post_id = get_the_id();
	$str = '<div id="wpfresh5-social-share">';
	foreach( $networks as $network ) {
		$el = $snetworks[$network];
		$str .= '<a href="'.wpfresh5_fix_social_url( $el['url'], $post_id ).'" class="dsb-btn dsb-'.$el['value'].'-bg dsb-white"><i class="fa fa-'.$el['icon'].'"></i> '.$el['text'].'</a>';
	}

	$str .= '</div>';
	$position = wpfresh5_get_settings( array( 'social', 'share', 'position' ) );
	if( $position )
		return $str.$content;
	else
		return $content.$str;
}

function wpfresh5_fix_social_url( $url, $post_id ) {
	$from = array( '{url}', '{title}', '{img}' );
	$to = array( urlencode( get_permalink( $post_id ) ), urlencode( get_the_title( $post_id ) ), urlencode( get_the_post_thumbnail_url( $post_id ) )  );
	return str_replace( $from, $to, $url );
}
/*
//Adding the Open Graph in the Language Attributes
function add_opengraph_doctype( $output ) {
        return $output . ' xmlns:og="http://opengraphprotocol.org/schema/" xmlns:fb="http://www.facebook.com/2008/fbml"';
    }
add_filter('language_attributes', 'add_opengraph_doctype');

//Lets add Open Graph Meta Info

function wpfresh5_insert_fb_in_head() {
	$ogmetadata = wpfresh5_get_settings( array( 'social', 'metadata', 'facebook' ) );
	if( !$ogmetadata )
		return;
    global $post;
    if ( !is_singular()) //if it is not a post or a page
        return;
        echo '<meta property="fb:admins" content="YOUR USER ID"/>';
        echo '<meta property="og:title" content="' . get_the_title() . '"/>';
        echo '<meta property="og:type" content="article"/>';
        echo '<meta property="og:url" content="' . get_permalink() . '"/>';
        echo '<meta property="og:site_name" content="Your Site NAME Goes HERE"/>';
    if(!has_post_thumbnail( $post->ID )) { //the post does not have featured image, use a default image
        $default_image="http://example.com/image.jpg"; //replace this with a default image on your server or an image in your media library
        echo '<meta property="og:image" content="' . $default_image . '"/>';
    }
    else{
        $thumbnail_src = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'medium' );
        echo '<meta property="og:image" content="' . esc_attr( $thumbnail_src[0] ) . '"/>';
    }
    echo "
";
}
add_action( 'wp_head', 'wpfresh5_insert_fb_in_head', 5 );*/

function wpfresh5_call_public_hooks() {

	// create object of public class to pass options
	$plugin_public = new WPFresh5SocialMetadata( /*$this->options, $this->version*/ );
	// $this->plugin_public = $plugin_public;

	// hook to upate plugin db/options based on version
	add_action( 'wp_head', array( $plugin_public, 'insert_meta_tags' ), 99999 );
	// hook to add Open Graph Namespace
	add_filter( 'language_attributes', array( $plugin_public, 'add_open_graph_namespace' ), 99999 );
	// hook to add option for excerpt for pages
	add_action( 'init', array( $plugin_public, 'add_excerpts_to_pages' ) );

}

add_action( 'init', 'wpfresh5_call_public_hooks' );

class WPFresh5SocialMetadata {

	/**
	 * Options saved in database.
	 *
	 * @since    1.0
	 */
	private $options;

	/**
	 * Current version of the plugin.
	 *
	 * @since    1.0
	 */
	private $version;

	/**
	 * Facebook Open Graph Image size
	 *
	 * @since    1.0
	 */
	private $fb_image_size = '';

	/**
	 * Get saved options.
	 *
	 * @since    1.0
     * @param    array     $options    Plugin options saved in database
     * @param    string    $version    Current version of the plugin
	 */
	public function __construct( /*$options, $version*/ ) {
		$this->options = array();
		/*$this->options = $options;
		$this->version = $version;*/

	}

	/**
	 * Get http/https protocol at the website
	 *
	 * @since    1.0
	 */
	public function get_http_protocol() {
		
		if ( isset( $_SERVER['HTTPS'] ) && ! empty( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] != 'off' ) {
			return "https://";
		} else {
			return "http://";
		}
	
	}

	/**
	 * Add Open Graph Namespace
	 *
	 * @since    1.0
	 */
	public function add_open_graph_namespace( $output ) {
		
		if ( stristr( $output, 'xmlns:og' ) === false ) {
			$output = $output . ' xmlns:og="http://ogp.me/ns#"';
		}
		if ( stristr( $output, 'xmlns:fb' ) === false ) {
			$output = $output . ' xmlns:fb="http://ogp.me/ns/fb#"';
		}

		return $output;
		
	}

	/**
	 * Insert meta tags in <head>
	 *
	 * @since    1.0
	 */
	public function insert_meta_tags() {
		$settings = wpfresh5_get_settings( array( 'social', 'metadata' ) );
		$metatags = wpfresh5_get_settings( array( 'seo', 'general', 'metatags' ) );
		$facebook = wpfresh5_get_settings( array( 'social', 'metadata', 'facebook' ) );
		$twitter = wpfresh5_get_settings( array( 'social', 'metadata', 'twitter' ) );
		$googleplus = wpfresh5_get_settings( array( 'social', 'metadata', 'googleplus' ) );
		$googleplus_publisher = wpfresh5_get_settings( array( 'social', 'metadata', 'googleplus_publisher' ) );
		$twitter_username = wpfresh5_get_settings( array( 'social', 'metadata', 'twitter_username' ) );
		$twitter_cardtype = wpfresh5_get_settings( array( 'social', 'metadata', 'twitter_cardtype' ) );
		$default_img = wpfresh5_get_settings( array( 'social', 'metadata', 'default_img' ) );

		$fb_og_type = 'article';
		$fb_image_additional = array();
		$fb_locale = '';
		$fb_og_image = '';
		$facebook_author_linkrelgp = '';
		$facebook_author_twitter = '';

		global $post;
		/*$custom_meta = get_post_meta( $post->ID, '_heateor_ogmt_meta', true );
		if ( $custom_meta && isset( $custom_meta['disable_tags'] ) && $custom_meta['disable_tags'] == 1 ) {
			return;
		}*/

		if ( is_singular() ) {
			// title OG meta tag
			$facebook_title = esc_attr( wp_strip_all_tags( stripslashes( $post->post_title ), true ) );
			//if SubHeading is enabled
			// if ( isset( $this->options['show_subheading'] ) && $this->is_subheading_plugin_active() ) {
			// 	$facebook_title .= ' - ' . get_the_subheading();
			// }

			// url OG meta tag
			$fb_og_url = get_permalink();
			// if homepage
			if ( is_front_page() ) {
				$fb_og_url = get_option( 'home' );
				$fb_og_type = 'website';
			}

			// description OG meta tag
			if ( trim( $post->post_excerpt ) != '' ) {
				$fb_og_desc = trim( $post->post_excerpt );
			} else {
				$fb_og_desc = trim( $post->post_content );
			}
			$fb_og_desc = intval( 300 ) > 0 ? mb_substr( esc_attr( wp_strip_all_tags( strip_shortcodes( stripslashes( $fb_og_desc ) ), true ) ), 0, 300 ) : esc_attr( wp_strip_all_tags( strip_shortcodes( stripslashes( $fb_og_desc ) ), true ) );

			// image OG meta tag
			$fb_og_image = $this->get_post_image();

			// Author
			$facebook_author = '';
			$facebook_author_meta = '';
			
			$author_id = $post->post_author;
			if ( /*$author_id > 0 && ! ( is_page() && isset( $this->options['hide_author_pages'] ) )*/ 0 ) {
				$facebook_author = get_the_author_meta( 'heateor_ogmt_author_facebook', $author_id );
				$facebook_author_meta = get_the_author_meta( 'display_name', $author_id );
				$facebook_author_linkrelgp = get_the_author_meta( 'heateor_ogmt_author_googleplus', $author_id );
				$facebook_author_twitter = get_the_author_meta( 'heateor_ogmt_author_twitter', $author_id );
			}

			// Published and Modified time
			if ( is_singular( 'post' ) ) {
				$facebook_article_pub_date = get_the_date( 'c' );
				$facebook_article_mod_date = get_the_modified_date( 'c' );
			} else {
				// unset( $this->options['enable_fb_dates'] );
				$facebook_article_pub_date = '';
				$facebook_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 {
				//unset( $this->options['enable_fb_article_section'] );
			}

		} else {
			global $wp_query;
			
			$facebook_title = esc_attr( wp_strip_all_tags( stripslashes( get_bloginfo( 'name' ) ), true ) );
			$fb_og_url = ( ( ! empty( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] == 'on' ) ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; 

			$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;

			$fb_og_desc = esc_attr( wp_strip_all_tags( stripslashes( get_bloginfo( 'description' ) ), true ) );
			
			if ( is_category() ) {
				$facebook_title = esc_attr( wp_strip_all_tags( stripslashes( single_cat_title( '', false ) ), true ) );
				$term = $wp_query->get_queried_object();
				$fb_og_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_og_desc = $cat_desc;
				}
			} else {
				if ( is_tag() ) {
					$facebook_title = esc_attr( wp_strip_all_tags( stripslashes( single_tag_title( '', false ) ), true ) );
					$term = $wp_query->get_queried_object();
					$fb_og_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_og_desc = $tag_desc;
					}
				} else {
					if ( is_tax() ) {
						$facebook_title = esc_attr( wp_strip_all_tags( stripslashes( single_term_title( '', false ) ), true ) );
						$term = $wp_query->get_queried_object();
						$fb_og_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_og_image = $image;
									}
								}
							}
						}
					} else {
						if ( is_search() ) {
							$facebook_title = esc_attr( wp_strip_all_tags( stripslashes( __( 'Search for' ) .' "' .get_search_query() .'"' ), true ) );
							$fb_og_url = get_search_link();
						} else {
							if ( is_author() ) {
								$facebook_title = esc_attr( wp_strip_all_tags( stripslashes( get_the_author_meta( 'display_name', get_query_var( 'author' ) ) ), true ) );
								$fb_og_url = get_author_posts_url( get_query_var( 'author' ), get_query_var( 'author_name' ) );
							} else {
								if ( is_archive() ) {
									if ( is_day() ) {
										$facebook_title = esc_attr( wp_strip_all_tags( stripslashes( get_query_var( 'day' ) . ' ' .single_month_title( ' ', false ) . ' ' . __( 'Archives' ) ), true ) );
										$fb_og_url = get_day_link( get_query_var( 'year' ), get_query_var( 'monthnum' ), get_query_var( 'day' ) );
									} else {
										if ( is_month() ) {
											$facebook_title = esc_attr( wp_strip_all_tags( stripslashes( single_month_title( ' ', false ) . ' ' . __( 'Archives' ) ), true ) );
											$fb_og_url = get_month_link( get_query_var( 'year' ), get_query_var( 'monthnum' ) );
										} else {
											if ( is_year() ) {
												$facebook_title = esc_attr( wp_strip_all_tags( stripslashes( get_query_var( 'year' ) . ' ' . __( 'Archives' ) ), true ) );
												$fb_og_url = get_year_link( get_query_var( 'year' ) );
											}
										}
									}
								} else {
									if ( is_front_page() ) {
										$fb_og_url = get_option( 'home' );
										$fb_og_type =  'website';
									}
								}
							}
						}
					}
				}
			}
		}

		// If there is no description, just add the title
		if ( trim( $fb_og_desc ) == '' ) {
			$fb_og_desc = $facebook_title;
		}		
	
		// MONSTERINSIGHTS?
		/*if (  1 ) {
			if ( defined( 'WPSEO_VERSION' ) ) {
				$wpseo = WPSEO_Frontend::get_instance();
				$facebook_title = wp_strip_all_tags( $wpseo->title( false ), true );
				// Title - From SubHeading plugin

				// URL - From Yoast SEO
				$fb_og_url = $wpseo->canonical( false );
				// Description - From Yoast SEO OR our plugin
				$fb_desc_temp = $wpseo->metadesc( false );
				$fb_og_desc = wp_strip_all_tags( trim( $fb_desc_temp ) != '' ? trim( $fb_desc_temp ) : $fb_og_desc, true );
			}
		}*/

		// Plugin Filters
		$facebook_title = apply_filters( 'wpfresh5_ogmt_fb_og_title', $facebook_title );
		$fb_og_desc = apply_filters( 'wpfresh5_ogmt_fb_og_desc', $fb_og_desc );
		$fb_og_image = apply_filters( 'wpfresh5_ogmt_fb_og_image', $fb_og_image );
		$fb_image_additional = apply_filters( 'wpfresh5_ogmt_fb_og_image_additional', $fb_image_additional );
		$fb_locale = apply_filters( 'wpfresh5_ogmt_fb_og_locale', $fb_locale );
		$fb_image_size = false;
		
		if ( trim( $fb_og_image ) != '' ) {
			/*if ( isset( $this->options['enable_fb_image_size'] ) ) {
				if ( $this->fb_image_size ) { 
					$fb_image_size = $this->fb_image_size;
				} else {
					$fb_image_size = $this->get_open_graph_image_size( $fb_og_image );
				}
			}*/
		} else {
			// unset( $this->options['enable_fb_image_size'] );
		}

		// encode spaces in URLs
		if ( isset( $fb_og_url ) && $fb_og_url == '' ) {
			$fb_og_url = ( ( ! empty( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] == 'on' ) ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; 
		} elseif ( trim( $fb_og_url ) != '' ) {
			$fb_og_url = str_replace( ' ', '%20', trim( $fb_og_url ) );
		}
		if ( isset( $fb_publisher ) && trim( $fb_publisher ) != '' ) {
			$fb_publisher =	str_replace( ' ', '%20', trim( $fb_publisher ) );
		}
		
		if( !empty( $googleplus_publisher ) ) 
			$googleplus_publisher = str_replace( ' ', '%20', $googleplus_publisher );
		
		if ( isset( $facebook_author ) && trim( $facebook_author ) != '' ) {
			$facebook_author = str_replace( ' ', '%20', trim( $facebook_author ) );
		}
		if ( isset( $facebook_author_linkrelgp ) && trim( $facebook_author_linkrelgp ) != '' ) {
			$facebook_author_linkrelgp = str_replace( ' ', '%20', trim( $facebook_author_linkrelgp ) );
		}
		if ( isset( $fb_og_image ) && trim( $fb_og_image ) == '' && isset( $default_img ) && $default_img != '' ) {
			$fb_og_image = $default_img;
		}
		if ( isset( $fb_og_image ) && trim( $fb_og_image ) != '' ) {
			$fb_og_image = str_replace( ' ', '%20', trim( $fb_og_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 ) );
			}
		}

		$fb_og_desc = esc_attr( strip_shortcodes( trim( $fb_og_desc ) ) );
		$facebook_title = esc_attr( trim( $facebook_title ) );

		$html = '
<!-- START - WP Freshstart 5 Social Metadata  -->';
		// General meta tags
		if ( /*isset( $this->options['canonical_url'] )*/ $metatags ) {
			$html .= '
<link rel="canonical" href="' . trim( esc_attr( $fb_og_url ) ) . '"/>';
		}
		if ( /*isset( $this->options['author_meta'] ) && $facebook_author_meta != ''*/ 0 ) {
			$html .= '
<meta name="author" content="' . trim( esc_attr( $facebook_author_meta ) ) . '"/>';
		}
		if ( $metatags/*isset( $this->options['meta_description_tag'] )*/ ) {
			$html .= '
<meta name="description" content="' . $fb_og_desc . '"/>';
		}
		if( $facebook ) {
		// Facebook OG Meta Tags
		if ( /*isset( $this->options['enable_fb_locale'] )*/1 ) {
			$html .= '
<meta property="og:locale" content="' . trim( esc_attr( trim( $fb_locale ) != '' ? trim( $fb_locale ) : trim( get_locale() ) ) ) . '"/>';
		}
		if ( /*isset( $this->options['enable_fb_site_name'] )*/ 1 ) {
			$html .= '
<meta property="og:site_name" content="' . trim( esc_attr( get_bloginfo( 'name' ) ) ) . '"/>';
		}
		if ( 1/*isset( $this->options['enable_fb_title'] )*/ ) {
			$html .= '
<meta property="og:title" content="' . $facebook_title . '"/>';
		}
		if ( 1/*isset( $this->options['enable_fb_url'] )*/ ) {
			$html .= '
<meta property="og:url" content="' . trim( esc_attr( $fb_og_url ) ) . '"/>';
		}
		if ( 1/*isset( $this->options['enable_fb_type'] )*/ ) {
			$html .= '
<meta property="og:type" content="' . trim( esc_attr( $fb_og_type ) ) . '"/>';
		}
		if ( /*isset( $this->options['enable_fb_image'] ) &&*/ trim( $fb_og_image ) != '' ) {
			$html .= '
<meta property="og:image" content="' . trim( esc_attr( $fb_og_image ) ) . '"/>';
		}
		if ( 0 /*isset( $this->options['enable_fb_image'] ) && 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( /*isset( $this->options['enable_fb_image_size'] ) && isset( $fb_image_size ) && is_array( $fb_image_size ) != ''*/ 0 ) {
				$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 ( /*isset( $this->options['enable_fb_dates'] )*/ 0 ) {
			if ( trim( $facebook_article_pub_date ) != '' ) {
				$html .= '
<meta property="article:published_time" content="' . trim( esc_attr( $facebook_article_pub_date ) ) . '"/>';
			}
			if ( trim( $facebook_article_mod_date ) != '' ) {
				$html .= '
<meta property="article:modified_time" content="' . trim( esc_attr( $facebook_article_mod_date ) ) . '" />
<meta property="og:updated_time" content="' . trim( esc_attr( $facebook_article_mod_date ) ) . '" />
			';
			}
		}
	/*	if ( isset( $this->options['enable_fb_article_section'] ) && 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 ( isset( $this->options['enable_fb_publisher'] ) && trim( $fb_publisher ) != '' ) {
			$html .= '
<meta property="article:publisher" content="' . trim( esc_attr( $fb_publisher ) ) . '"/>';
		}
		if ( isset( $this->options['enable_fb_author'] ) && $facebook_author != '' ) {
			$html .= '
<meta property="article:author" content="' . trim( esc_attr( $facebook_author ) ) . '"/>';
		}*/
		if ( 1/*isset( $this->options['enable_fb_description'] )*/ ) {
			$html .= '
<meta property="og:description" content="' . $fb_og_desc . '"/>';
		}
		}
		if( $twitter ) {
			// Twitter start
		// Twitter cards
		if ( 1/*isset( $this->options['enable_twitter_title'] )*/ ) {
			$html .= '
<meta name="twitter:title" content="' . $facebook_title . '"/>';
		}
		if ( 1/*isset( $this->options['enable_twitter_url'] )*/ ) { 
			$html .= '
<meta name="twitter:url" content="' . trim( esc_attr( $fb_og_url ) ) . '"/>';
		}
		if ( isset( $twitter_username ) && $twitter_username != '' ) {
			$html .= '
<meta name="twitter:site" content="@' . $twitter_username . '"/>';
		}
		/*if ( isset( $this->options['enable_twitter_creator'] ) && ( trim( $facebook_author_twitter ) != '' || $twitter_username != '' ) ) {
			$html .= '
<meta name="twitter:creator" content="@' . esc_attr( $facebook_author_twitter != '' ? $facebook_author_twitter : $twitter_username ) . '"/>';
		}*/
		if ( 1/*isset( $this->options['enable_twitter_description'] )*/ ) {
			$html .= '
<meta name="twitter:description" content="' . $fb_og_desc . '"/>';
		}
		if ( /*isset( $this->options['enable_twitter_image'] ) &&*/ trim( $fb_og_image ) != '' ) {
			$html .= '
<meta name="twitter:image" content="' . trim( esc_attr( $fb_og_image ) ) . '"/>';
		}
		if ( /*isset( $this->options['enable_twitter_title'] ) || isset( $this->options['enable_twitter_url'] ) || isset( $this->options['enable_twitter_creator'] ) ||*/ isset( $twitter_username ) /*|| isset( $this->options['enable_twitter_image'] )*/ ) {
			$html .= '
<meta name="twitter:card" content="' . esc_attr( $twitter_cardtype  == 'summary_large' ? 'summary_large_image' : $twitter_cardtype  ) . '"/>';
		}

	} // Twitter End
	if( $googleplus ) {
		// Google/Schema Tags
		if ( 1/*isset( $this->options['enable_google_itemprop'] )*/ ) {
			$html .= '
<meta itemprop="name" content="' . $facebook_title . '"/>';
		}
		if ( /*isset( $this->options['enable_google_publisher'] ) &&*/ $googleplus_publisher != '' ) {
			$html .= '
<link rel="publisher" href="' . esc_attr( $googleplus_publisher ) . '"/>';
		}
		if ( /*isset( $this->options['enable_google_author'] ) &&*/ trim( $facebook_author_linkrelgp ) != '' ) {
			$html .= '
<link rel="author" href="' . trim( esc_attr( $facebook_author_linkrelgp ) ) . '"/>';
		}
		if ( /*isset( $this->options['enable_google_description'] )*/ 1 ) {
			$html .= '
<meta itemprop="description" content="' . $fb_og_desc . '"/>';
		}
		if ( /*isset( $this->options['enable_google_image'] ) &&*/ trim( $fb_og_image ) != '' ) {
			$html .= '
<meta itemprop="image" content="' . trim( esc_attr( $fb_og_image) ) . '"/>';
		}
	}
		$html .= '
<!-- END - WP Freshstart 5 Social Metadata -->

';
		echo $html;

	}

	/**
	 * Get image url to show in image meta tag for singular page
	 *
	 * @since    1.0
	 */
	private function get_post_image() {

		global $post;

		$thumbnail_done = false;
		$fb_og_image = '';
		$fb_og_image_min_size = 200;
		
		// Attachment page
		if ( is_attachment() ) {
			if ( $attachment_image_url = wp_get_attachment_image_src( null, 'full' ) ) {
				$fb_og_image = trim( $attachment_image_url[0] );
				$image_size = array( intval( $attachment_image_url[1] ), intval( $attachment_image_url[2] ) );
				if ( trim( $fb_og_image ) != '' ) {
					$thumbnail_done = true;
				}
			}
		}

		// Featured image
		if ( ! $thumbnail_done ) {
			if ( function_exists( 'get_post_thumbnail_id' ) ) {
				if ( isset( $this->options['image_tag_featured'] ) ) {
					if ( $attachment_id = get_post_thumbnail_id( $post->ID ) ) {
						$fb_og_image = wp_get_attachment_url( $attachment_id, false );
						$thumbnail_done = true;
					}
				}
			}
		}

		// From post/page content
		if ( ! $thumbnail_done ) {
			if ( isset( $this->options['image_tag_first'] ) ) {
				$imgreg = '/<img .*src=["\']( [^ ^"^\']*)["\']/';
				preg_match_all( $imgreg, trim( $post->post_content ), $matches );
				if ( $matches[1] ) {
					$temp_image = false;
					foreach( $matches[1] as $image ) {
						$pos = strpos( $image, home_url() );
						if ( $pos === false ) {
							if ( stristr( $image, 'http://' ) || stristr( $image, 'https://' ) || mb_substr( $image, 0, 2 ) == '//' ) {
								if ( mb_substr( $image, 0, 2 ) == '//' ) { $image = ( ( ! empty( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] == 'on' ) ? 'https:' : 'http:' ) . $image; }
								$temp_image = $image;
								$temp_image_size = $temp_image;
							} else {
								$temp_image = home_url() . $image;
								$temp_image_size = ABSPATH . str_replace( trailingslashit( home_url() ), '', $temp_image );
							}
						} else {
							$temp_image = $image;
							$temp_image_size = ABSPATH . str_replace( trailingslashit( home_url() ), '', $temp_image );
						}
						if ( $temp_image ) {
							if ( $image_size = $this->get_open_graph_image_size( $temp_image_size ) ) {
								if ( $image_size[0] >= $fb_og_image_min_size && $image_size[1] >= $fb_og_image_min_size ) {
									$fb_og_image = $temp_image;
									$thumbnail_done = true;
									break;
								}
							}
						}
					}
				}
			}
		}

		// From media gallery
		if ( ! $thumbnail_done ) {
			if ( isset( $this->options['image_tag_gallery'] ) ) {
				$images = get_posts( array( 'post_type' => 'attachment', 'numberposts' => -1, 'post_status' => null, 'order' => 'ASC', 'orderby' => 'menu_order', 'post_mime_type' => 'image', 'post_parent' => $post->ID ) );
				if ( $images ) {
					foreach( $images as $image ) {
						$temp_image = wp_get_attachment_url( $image->ID, false );
						$temp_image_size = ABSPATH . str_replace( trailingslashit( home_url() ), '', $temp_image );
						if ( $image_size = $this->get_open_graph_image_size( $temp_image_size ) ) {
							if ( $image_size[0] >= $fb_og_image_min_size && $image_size[1] >= $fb_og_image_min_size ) {
								$fb_og_image = $temp_image;
								$thumbnail_done = true;
								break;
							}
						}
					}
				}
			}
		}

		// From default
		if ( ! $thumbnail_done ) {
			if ( isset( $this->options['image_tag_default'] ) ) {
				$fb_og_image = $default_img;
			} else {
				$fb_og_image = '';
			}
		}

		return $fb_og_image;
	
	}

	/**
	 * Get image size
	 *
	 * @since    1.0
	 */
	private function get_open_graph_image_size( $image_url ) {
		
		if ( stristr( $image_url, 'http://' ) || stristr( $image_url, 'https://' ) || mb_substr( $image_url, 0, 2 ) == '//' ) {
			if ( function_exists( 'curl_version' ) && function_exists( 'imagecreatefromstring' ) ) {
				// Getting just a part of the image to speed things up. From http://stackoverflow.com/questions/4635936/super-fast-getimagesize-in-php
				$headers = array(
					"Range: bytes=0-32768"
				);
				$curl = curl_init( $image_url );
				curl_setopt( $curl, CURLOPT_HTTPHEADER, $headers );
				curl_setopt( $curl, CURLOPT_RETURNTRANSFER, 1 );
				//Set HTTP REFERER and USER AGENT just in case. Some servers may have hotlinking protection
				curl_setopt( $curl, CURLOPT_REFERER, ( ( ! empty( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] == 'on' ) ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST']. $_SERVER['REQUEST_URI'] );
				curl_setopt( $curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT'] );
				if ( $data = curl_exec( $curl ) ) {
					if ( $image = @imagecreatefromstring( $data ) ) { //Mute errors because we're not loading the all image
						if ( $image_width = imagesx( $image ) ) {
							//We have to fake the image type - For RSS
							$ext = pathinfo( $image_url, PATHINFO_EXTENSION );
							switch(strtolower( $ext ) ) {
								case 'gif':
									$type = 1;
									break;
								case 'jpg':
								case 'jpeg':
									$type = 2;
									break;
								case 'png':
									$type = 3;
									break;
								default:
									$type = 2;
									break;
							}
							$image_size = array( $image_width, imagesy( $image ), $type, '' );
						} else {
							$image_size = false;
						}
					} else {
						$image_size = false;
					}
				} else {
					$image_size = false;
				}
				curl_close( $curl );
			} else {
				if ( intval( ini_get( 'allow_url_fopen' ) ) == 1 ) {
					$image_size = getimagesize( $image_url );
				} else {
					$image_size = false;
				}
			}
		} else {
			$image_size = getimagesize( $image_url );
		}
		$this->fb_image_size = $image_size;
		
		return $image_size;
	
	}

	/**
	 * Check if Subheading plugin is active
	 *
	 * @since    1.0
	 */
	private function is_subheading_plugin_active() {

		if ( class_exists( 'SubHeading' ) && function_exists( 'get_the_subheading' ) ) {
			return true;
		}
		
		return false;
	
	}

	/**
	 * Add option for excerpt for pages
	 *
	 * @since    1.0
	 */
	public function add_excerpts_to_pages() {
	     
	     add_post_type_support( 'page', 'excerpt' );

	}

}

// Pinterest Pin It

/*add_filter( 'the_content', 'wpfresh5_pinterest_btn' );
function wpfresh5_pinterest_btn( $content ) {
    $pinterest = wpfresh5_get_settings( array( 'social', 'pinterest', 'pin_img' ) );
	if( $pinterest && is_singular() ) {
		return '<div class="wpf5-pcontent">'.$content.'</div>';
	}
}*/

add_filter('the_content', 'wpfresh5_pinterest_btn');
function wpfresh5_pinterest_btn( $content ) {
	global $wp_query;
	$pin_img = wpfresh5_get_settings( array( 'social', 'pinterest', 'pin_img' ) );
	if( !$pin_img || !is_singular() )
		return $content;
	include_once WPFRESH5_DIR.'/lib/simple_html_dom.php';
	if ( !function_exists( 'str_get_html' ) )
		return $content;
	// $options    = get_option('pin_it_buttons_options');
	$post_url   = rawurlencode(get_permalink()); 
	$post_title = rawurlencode(get_the_title());
	$pin_count  = 1/*$options['pinit_pincount']*/; // Position of the pin counter
	//$pin_button    = '<span class="pinit-button-'.$pin_count.'"><a href="http://pinterest.com/pin/create/button/?url=%s&media=%s&description=%s" class="pin-it-button" count-layout="%s"><img border="0" src="//assets.pinterest.com/images/PinExt.png" title="Pin It" /></a></span>';

	// The shortcodes run after the filter. So we'll check for them in $content instead.
	/*$pinit = $options['pinit_pinit'];
	if ( strpos($content, '[nopinit]') )
			$pinit = false;
	if ( strpos($content, '[dopinit]') )
			$pinit = true;*/

	// First see if we want to show pins according to the settings.
	// $options = get_option('pin_it_buttons_options');
	/*if( ( $options['pinit_show_on_frontpage'] == 0 && is_front_page() ) OR 
			( $options['pinit_show_on_frontpage'] == 0 && is_home() ) OR 
			( $options['pinit_show_on_pages'] == 0 && is_page() ) OR
			( $options['pinit_show_on_posts'] == 0 && is_single() ) OR 
			is_admin() OR ($pinit==false) ) 
					return $content;*/

	// Tag all images
	$html = str_get_html( $content, true, true, DEFAULT_TARGET_CHARSET, false );
	if( $html ) {
		foreach( $html->find('img') as $e )
	    	$e->class .= ' wpf5pin-it';
    }
	$content = $html;

	//$html->clear(); 
	unset($html);

	return $content;

}

// Output the pin-it jQuery settings to the document head.
// add_action('wp_head', 'wpfresh5_pinterest_print_script', 100);
/*function wpfresh5_pinterest_print_script() {

	$options      = get_option('pin_it_buttons_options');
	$pin_count    = $options['pinit_pincount']; 
	$pin_location = $options['pinit_location']; 
	$min_size     = $options['pinit_minsize']; 
	$pin_text     = $options['pinit_text'];
	echo '<script>
	jQuery(window).load(function(){
		jQuery().pinit({
			selector: ".pin-it",
			align: "'. $pin_location .'",
			minSize: "'. $min_size .'",
			fadeSpeed: 200,
			opacity: 1,
			pinCount: "'. $pin_count .'",
			pinText: "'. $pin_text .'",
			';
	echo ($pin_location == "bottomLeft" || $pin_location == "bottomRight") ? 'offsetBottom: "50"' : 'offsetBottom: "10"';
	echo '
		});
	});
</script>
';

}*/
?>