<?php
/**
 * Functions which enhance the theme by hooking into WordPress
 *
 * @package Social_Charity
 */

/**
 * Adds custom classes to the array of body classes.
 *
 * @param array $classes Classes for the body element.
 * @return array
 */
function social_charity_body_classes( $classes ) {
	// Adds a class of hfeed to non-singular pages.
	if ( ! is_singular() ) {
		$classes[] = 'hfeed';
	}

	// Adds a class of no-sidebar when there is no sidebar present.
	if ( ! is_active_sidebar( 'sidebar-1' ) ) {
		$classes[] = 'no-sidebar';
	}

	return $classes;
}
add_filter( 'body_class', 'social_charity_body_classes' );

/**
 * Add a pingback url auto-discovery header for single posts, pages, or attachments.
 */
function social_charity_pingback_header() {
	if ( is_singular() && pings_open() ) {
		echo '<link rel="pingback" href="', esc_url( get_bloginfo( 'pingback_url' ) ), '">';
	}
}
add_action( 'wp_head', 'social_charity_pingback_header' );

// Top Header Contact Info
if( ! function_exists('social_charity_top_header_contact_info_items')):
	function social_charity_top_header_contact_info_items(){
		$defaults =  array(
			array(
				'icon' => 'fa fa-phone',
				'title' => ' + (123) 456 7890',
			),
			array(
				'icon' => 'fa fa-envelope',
				'title' => 'info.demo@email.com',
			)
		);
		$contact_items = get_theme_mod( 'top_header_contact_info_items', $defaults );
		if( $contact_items  ){ 
			foreach( $contact_items as $contact ){ ?>
				<li>
					<a href="#"><span class="<?php echo esc_attr($contact['icon']);?>" aria-hidden="true"></span><?php echo esc_html($contact['title']);?></a>
				</li>
				<?php
			}
		}
	}
endif;	


// Footer Social items
if( ! function_exists( 'social_charity_footer_social_items') ):
	function social_charity_footer_social_items(){
		$defaults =  array(
			array(
				'font' => 'fa fa-facebook',
				'link' => 'https://www.facebook.com/',                        
			),
			array(
				'font' => 'fa fa-linkedin',
				'link' => 'https://www.linkedin.com/',
			),
			array(
				'font' => 'fa fa-twitter',
				'link' => 'https://twitter.com/',
			),
			array(
				'font' => 'fa fa-google-plus',
				'link' => 'https://plus.google.com',
			)
		);
		$social_items = get_theme_mod( 'social_charity_social_links', $defaults );
		$social_enable = get_theme_mod('footer_social_media_enable');
		if( $social_enable  ){ ?>
			<ul>
				<?php foreach( $social_items as $social ){ ?>

					<li><a href="<?php echo esc_url($social['link']);?>"><span class="<?php echo esc_attr($social['font']);?>" aria-hidden="true"></span></a></li>

					<?php
				}?>
			</ul>
			<?php
		}
	}
endif;

// Contact Page Social items
if( ! function_exists( 'social_charity_contact_page_social_items')):
	function social_charity_contact_page_social_items(){
		$defaults =  array(
			array(
				'font' => 'fa fa-facebook',
				'link' => 'https://www.facebook.com/',                        
			),
			array(
				'font' => 'fa fa-linkedin',
				'link' => 'https://www.linkedin.com/',
			),
			array(
				'font' => 'fa fa-twitter',
				'link' => 'https://twitter.com/',
			),
			array(
				'font' => 'fa fa-google-plus',
				'link' => 'https://plus.google.com',
			)
		);
		$social_items = get_theme_mod( 'social_charity_contact_social_links', $defaults );

		if( $social_items  ){ ?>
			
			<ul class="social-links">
				<?php foreach( $social_items as $social ){ ?>

					<li><a href="<?php echo esc_url($social['link']);?>"><span class="<?php echo esc_attr($social['font']);?>" aria-hidden="true"></span></a></li>

					<?php
				}?>
			</ul>
			<?php
		}
	}
endif;