<?php

/**

 * Returns a boolean if at least one social media link is found

 *

 * This function returns true if at least one

 * social media link is found. If none are

 * found it will return false.

 *

 * @function has_social_media()

 *

 * @uses ow_global_var()

 *

 * @return (bool) Returns true if social media link found

 *

 * @since 1.0.11 

 *

 */

function has_social_media() {

	

	$socials = array( 

		ow_global_var( 'facebook' ),

		ow_global_var( 'twitter' ),

		ow_global_var( 'linkedin' ),

		ow_global_var( 'googleplus' ),

	);

	

	foreach ( $socials as $social ) {

		

		if ( $social ) {

			

			return true;

		}

	}

	return false;

}







/**

 * Returns a social icon link

 *

 * This function returns a social icon link.

 * It will check to see if an SVG icon exists,

 * and if it does, return the icon in an <a>

 * tag linking to the registered URL in the

 * database. If the SVG is not found, it will

 * push a message to the developer console.

 *

 * @function social_icon()

 *

 * @uses get_template_directory(), ow_global_var(), developer_console_message()

 *

 * @param (string) $var the name of the social icon, $url the URL of the link, $target the target window for the link

 *

 * @return (string) an SVG in an <a> tag

 *

 * @since 1.0.19 

 *

 */

function social_icon( $var, $url = '', $target = "_blank" ) {

	

	$path = get_template_directory() . '/img/social-icons/' . $var . '.svg';

	if($var=='twitter'){$path = WP_PLUGIN_URL . '/ow-plugin/img/social-icons/' . $var . '.svg';}

	//echo WP_PLUGIN_URL . '/ow-plugin/img/social-icons/' . $var . '.svg';

	if($var=='twitter'){$svg = file_get_contents( $path );

						$link = ( $url != '' ) ? $url : ow_global_var( $var );

						echo '<a href="' . $link . '" target="' . $target . '" rel="external">' . $svg . '</a>';}

	if ( file_exists( $path ) ) {

		

		$link = ( $url != '' ) ? $url : ow_global_var( $var );

		

		if ( $link ) {

			

			$svg = file_get_contents( $path );

			

			echo '<a href="' . $link . '" target="' . $target . '" rel="external">' . $svg . '</a>';

		} else {

			

			developer_console_message( $var . ' social link - href not defined', 'alert' );	

		}

	} else {

		

		developer_console_message( $var . ' social icon not found', 'alert' );	

	}	

}







/**

 * Returns an email icon link

 *

 * This function returns an email icon link.

 * This function is different from the

 * social_icon() function because this will

 * obfuscate the email address via the

 * securemail() function. If the SVG is not

 * found, it will push a message to the

 * developer console.

 *

 * @function ow_email_icon()

 *

 * @uses get_template_directory(), securemail(), developer_console_message()

 *

 * @param (string) $url the mailto: link

 *

 * @return (string) an email icon in a mailto: <a> tag

 *

 * @since 1.0.0 

 *

 */

function ow_email_icon( $url = '' ) {

	

	$path = get_template_directory() . '/img/social-icons/email.svg';

	

	if ( file_exists( $path ) ) {

		

		$svg = file_get_contents( $path );

		echo securemail( $url,  $svg );		

	} else {

		

		developer_console_message( 'email icon not found', 'alert' );	

	}	

}







/**

 * Returns the RSS icon link

 *

 * This function returns the RSS icon link

 * for the Tax Tips & News. This function

 * will link to the RSS feed of the Tax

 * Tips & News. If the SVG is not found,

 * it will push a message to the developer

 * console. This function doesn't require

 * the link to go to 'news/tax-news/rss-feed'

 * as the endpoint 'rss-feed' will work with

 * any URL structure, in fact, this function

 * is probably too specific by declaring it!

 *

 * @function ow_rss_icon()

 *

 * @uses get_template_directory(), get_site_url(), developer_console_message()

 *

 * @param N/A

 *

 * @return (string) an RSS icon link to the Tax Tips & News RSS feed

 *

 * @since 1.0.14 

 *

 */

function ow_rss_icon() {

	

	$path = get_template_directory() . '/img/social-icons/rss.svg';

	

	if ( file_exists( $path ) ) {

		

		$link = get_site_url() . '/news/tax-news/rss-feed/';

		$svg = file_get_contents( $path );

		return '<a href="' . $link . '" target="_blank" class="rss-link">' . $svg . 'Tax Tips & News RSS Feed</a>';



	} else {

		

		developer_console_message( 'rss icon not found', 'alert' );	

	}	

}