<?php

// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

/**
 * Get css classes for site-header
 * @return string Space separated list of classes
 */





function shrk_get_header_class() {
	global $shrk_options;
	$classes = array();

	if ( isset( $shrk_options['menu_width'] ) && $shrk_options['menu_width'] != '1' ) {
		$classes[] = 'full-width-menu';
	}
	return implode(' ', $classes);
}


if ( !function_exists('shrk_the_header') ) {
	/**
	 * Echo the site header
	 */
	function shrk_the_header() {
		global $shrk_options;

		if ( shrk_get_mso('header_transparent') == 'no-header' ) {
			return;
		}

		$nav_align = isset($shrk_options['menu_alignment']) ? 'navbar-' . $shrk_options['menu_alignment'] : 'navbar-left';

		?>
		
		<header class="site-header <?php echo esc_attr( shrk_get_header_class() ); ?>">
			<?php do_action( 'shrk-header-topbar' ); ?>
			<nav id="primary-navigation" class="site-navigation header-style-1">        
				<div class="container">
					<div class="row">
						<div class="site-navigation-inner col-12">
							<div class="navbar">
								<div class="navbar-header">
									<!-- Your site title as branding in the menu -->
									<a class="navbar-brand <?php echo empty( $shrk_options['site_logo']['url'] ) ? 'no-image' : 'image'; ?>" href="<?php echo esc_url( home_url( '/' ) ); ?>" title="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>" rel="home">
										<?php if ( empty( $shrk_options['site_logo']['url'] ) ) { ?>
										<?php bloginfo( 'name' ); ?>
										<?php } else { ?>
										<img class='main-logo solid-logo' src='<?php echo esc_url($shrk_options['site_logo']['url']); ?>' alt='<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>' />
										<?php if ( !empty( $shrk_options['transp_site_logo']['url'] ) ) { ?>
										<img class='main-logo transp-logo' src='<?php echo esc_url($shrk_options['transp_site_logo']['url']); ?>' alt='<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>' />
										<?php } ?>
										<?php } ?>
									</a>
								</div>
								<?php wp_nav_menu(
									array(
										'theme_location' => 'primary',
										'container_class' => 'navbar-collapse navbar-responsive-collapse hidden-xs',
										'menu_class' => 'nav navbar-nav ' . esc_attr( $nav_align ),
										'fallback_cb' => 'shrk_fallback_menu',
										'menu_id' => 'main-menu',
										'walker' => shrk_get_menu_walker()
										)
								); ?>
								<div class="navbar-width-fix"></div>
								<?php do_action('shrk_header_right_content'); ?>
							</div><!-- .navbar -->
						</div>
					</div>
				</div><!-- .container -->
			</nav><!-- .site-navigation -->
		</header>

		<?php
	}
}

/**
 * Echoes the header menu icon used in smaller screens
 */
function shrk_header_get_menu_icon() {
	?>
	<div class="header-icon menu-mobile">
		<ul class="navbar-nav nav">
			<li class="">
				<a href="#" class="navbar-toggle">
					<i class="ion-android-menu ion"></i>
					<svg xmlns="http://www.w3.org/2000/svg" width="512" height="512" viewBox="0 0 512 512">
						<rect x="23.5" y="75.5" width="466.4" height="40"></rect>
						<rect x="23.5" y="231" width="466.4" height="40"></rect>
						<rect x="23.5" y="386.5" width="466.4" height="40"></rect>
					</svg>
				</a>
			</li>
		</ul>
	</div>
	<?php

}
add_action( 'shrk_header_right_content', 'shrk_header_get_menu_icon', 8 );

/**
 * Echoes a separator for use in the header
 */
function shrk_header_get_separator() {
	?>
	<div class="navbar-sep header-icon"></div>
	<?php
}

/**
 * Echoes the header search icon
 */
function shrk_header_search_icon() {
	?>
	<div class="header-icon header-search">
		<ul class="navbar-nav nav">
			<li class="">
				<a href="#" class="header-search-button">
					<i class="ion-ios-search-strong ion"></i>
				</a>

				<div class="search-dropdown sub-menu container">
					<?php if ( class_exists( 'YITH_WCAS' ) ) : ?>
					<?php echo wp_kses( do_shortcode('[yith_woocommerce_ajax_search]'), shrk_kses_allowed( 'shortcode' ) ); ?>
					<?php else: ?>
					<?php get_search_form( true ); ?>
					<?php endif; ?>
				</div>
			</li>
		</ul>
	</div>
	<?php
}

/**
 * Get the instance of the menu walker
 * @return onject The custom walker instance
 */
function shrk_get_menu_walker() {
	if ( class_exists( 'shrk_menu_walker' ) ) {
		return new shrk_menu_walker;
	} else {
		return new Walker_Nav_Menu;
	}
}

/**
 * Echoes the classes attribute
 * for the html element
 */
function shrk_html_classes() {
	global $shrk_options;
	$classes = array();

	if ( empty( $shrk_options ) ) return;

	if ( $shrk_options['no_theme_caps'] == '1' ) {
		$classes[] = 'no-theme-caps';
	}

	if ( !empty( $shrk_options['hide_until_fonts_typekit'] ) && $shrk_options['hide_until_fonts_typekit'] == '1' ) {
		$classes[] = 'hide-until-fonts';
	}

	if ( !empty( $classes )) {
		echo 'class="' . esc_attr( implode( apply_filters( 'shrk-html-classes', $classes ), ' ' ) ) . '"';
	}

}
add_action( 'shrk-html-element', 'shrk_html_classes' );

/**
 * Used to filter the body_class for the current configuration
 * and displayed page.
 * 
 * @param  array $classes Classes input
 * @return array          Classes output
 */
function shrk_body_classes_extra( $classes ) {
	global $shrk_options;
	global $post;

	if ( empty( $shrk_options ) ) return $classes;

	$transparent_header = false;
	$pcv                = shrk_get_mso('page_content_visibility', $post ? $post->ID : null, 'sections_content'); // Kept for backward compatibility 

	if ( is_multi_author() ) {
		$classes[] = 'group-blog'; // Adds a class of group-blog to blogs with more than 1 published author
	}

	if ( !empty($shrk_options['site_width_layout'])) { 
		$classes[] = esc_attr($shrk_options['site_width_layout']); 
	} else {
		$classes[] = 'full-layout';
	}

	if ( $shrk_options['menu_sticky'] == '1' && !is_singular('pagesections') ) {
		$classes[] = 'head-type-sticky'; 
	} else {
		$classes[] = 'head-type-normal'; 
	}

	if ( !empty($shrk_options['woo_cart_display']) ) {
		$classes[] = 'woo-cart-' . esc_attr($shrk_options['woo_cart_display']); 
	}

	if ( !empty($shrk_options['auto_show_cart']) && $shrk_options['auto_show_cart'] == '1' ) {
		$classes[] = 'auto_show_cart';
	}

	if ( isset($_REQUEST['ajaxpreview']) && $_REQUEST['ajaxpreview'] == 'true' ) {
		$classes[] = 'ajaxpreview';
	}

	if ( shrk_get_mso('header_transparent') == '1' && ( shrk_has_visible_sections() || shrk_has_cover_image() || apply_filters('shrk_transp_header_allowed', false) ) ) {
		$classes[]          = 'transparent-header';
		$transparent_header = true;
	}

	if ( shrk_get_mso('header_transparent') == 'no-header' ) {
		$classes[] = 'no-header';
	}
	
	if ( $pcv ) {
		$classes[] = 'visibility-' . esc_attr($pcv);
	}

	if ( shrk_has_visible_sections() ) {
		$classes[] = 'has-sections';
		if ( $transparent_header ) {
			$classes[] = 'header-over-content';
		}
	} else {
		$classes[] = 'has-no-sections';
	}

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

/**
 * Used to filter the classes for the site's footer
 * 
 * @param  string $class Space-separated list of classes
 * @return string        Space-separated list of classes
 */
function shrk_footer_widgets_classes( $class ) {
	$class .= ' ' . shrk_get_theme_option('footer_widgets_scheme', 'dark');
	$class .= shrk_get_theme_option('footer_widgets_shadow') == 1 ? ' shadow' : '';
	$class .= shrk_get_theme_option('footer_widgets_nopadding') == 1 ? ' nopadding' : '';
	return $class;
}
add_filter( 'shrk_footer_widgets_class', 'shrk_footer_widgets_classes' );

/**
 * Used to filter the classes for the site's socket
 * 
 * @param  string $class Space-separated list of classes
 * @return string        Space-separated list of classes
 */
function shrk_footer_socket_classes( $class ) {
	$class .= ' ' . shrk_get_theme_option('footer_socket_scheme', 'dark');
	$class .= shrk_get_theme_option('footer_socket_shadow') == 1 ? ' shadow' : '';
	return $class;
}
add_filter( 'shrk_footer_socket_class', 'shrk_footer_socket_classes' );

/**
 * Echoes the analytics code from the related
 * theme option
 *
 * Printed directly in wp_head as analytics
 * code usually comes in script tags.
 * 
 */
function shrk_theme_analytics_code() {
	global $shrk_options;

	if ( !empty($shrk_options['google_analytics_code']) ) {
		echo $shrk_options['google_analytics_code'];
	}
}
add_action( 'wp_head', 'shrk_theme_analytics_code', 2000 );

/**
 * Echoes the mobile browser theme color tag 
 * from the related theme option
 */
function shrk_head_browser_theme_color() {
	global $shrk_options;

	if ( !empty($shrk_options['browser_theme_color']) ) {
		echo '<meta name="theme-color" content="' . esc_attr( $shrk_options['browser_theme_color'] ) . '">';
	}
}
add_action( 'wp_head', 'shrk_head_browser_theme_color' );

/**
 * Gets the featured image or the first gallery image if featured image not set
 * @param  integer $postid      the ID of the post to get the image from
 * @param  string  $image_size  WP registered image size
 * @return string  	            Source of image as string
 */
function shrk_get_gallery_post_image( $postid=null, $image_size ) {
	global $post;

	if ( empty($postid) ) {
		$postid = $post->ID;
	}

	$gallery_images_ids = shrk_remove_empty_from_array( explode( ',', shrk_get_meta_option( 'gallery_items', $postid ) ) );

	if ( has_post_thumbnail( $postid ) ) {
		$portfolio_main_image = wp_get_attachment_image_src( get_post_thumbnail_id( $postid ), $image_size ); 
	} elseif ( isset($gallery_images_ids[0]) ) {
		$portfolio_main_image = wp_get_attachment_image_src( $gallery_images_ids[0], $image_size );
	} else {
		$portfolio_main_image = false;
	}

	return $portfolio_main_image;
}

if(!function_exists('shrk_topbar')) {
	/**
	 * Echo the topbar for the site
	 * if enabled
	 */
	function shrk_topbar() {
		global $shrk_options;


		if ( !isset( $shrk_options['topbar_enabled'] ) || $shrk_options['topbar_enabled'] != '1' ) return;

		?>
		<div class="top-bar hidden-xs <?php echo ($shrk_options['topbar_reverse_layout'] == '1') ? 'reverse' : ''; ?>">
			<div class="container">
				<div class="row">
					<div class="infolinks"><?php echo wp_kses( do_shortcode( $shrk_options['topbar_text_content'] ), shrk_kses_allowed( 'shortcode' ) ); ?></div>
					<div class="nav <?php echo ($shrk_options['topbar_reverse_layout'] == '1') ? 'navbar-left' : 'navbar-right'; ?>">
						<?php wp_nav_menu(
							array(
								'theme_location' => 'topbar-nav',
								'container_class' => '',
								'menu_class' => '',
								'fallback_cb' => 'shrk_no_menu_message',
								'menu_id' => 'topbar-menu',
								'walker' => shrk_get_menu_walker()
								)
								); ?>
					</div>
				</div>
			</div>
		</div>
		<?php
	}
	add_action( 'shrk-header-topbar', 'shrk_topbar' );
}

/**
 * Template tags
 */
if ( ! function_exists( 'shrk_content_nav' ) ) {
	/**
	 * Display navigation to next/previous pages when applicable
	 */
	function shrk_content_nav( $nav_id, $nav_class='' ) {
		global $wp_query, $post;

		// Don't print empty markup on single pages if there's nowhere to navigate.
		if ( is_single() ) {
			$previous = ( is_attachment() ) ? get_post( $post->post_parent ) : get_adjacent_post( false, '', true );
			$next = get_adjacent_post( false, '', false );

			if ( ! $next && ! $previous )
				return;
		}

		// Don't print empty markup in archives if there's only one page.
		if ( $wp_query->max_num_pages < 2 && ( is_home() || is_archive() || is_search() ) )
			return;

		$nav_class .= ( is_single() ) ? ' post-navigation' : ' paging-navigation';

		?>
		<nav id="<?php echo esc_attr( $nav_id ); ?>" class="<?php echo esc_attr( $nav_class ); ?>">
			<h2 class="screen-reader-text"><?php esc_html_e( 'Post navigation', 'ux-shop' ); ?></h2>

			<?php if ( is_single() ) : // navigation links for single posts ?>

				<?php previous_post_link( '<div class="nav-previous">%link</div>', '<i class="icon-ws-arrow-left" ></i><span class="meta-nav">%title</span>' ); ?>
				<?php next_post_link( '<div class="nav-next">%link</div>', '<i class="icon-ws-arrow-right" ></i><span class="meta-nav">%title</span>' ); ?>

			<?php elseif ( $wp_query->max_num_pages > 1 && ( is_home() || is_archive() || is_search() ) ) : // navigation links for home, archive, and search pages ?>

				<?php if ( get_next_posts_link() ) : ?>
					<div class="nav-previous"><?php next_posts_link( '<i class="icon-ws-arrow-left" ></i><span class="meta-nav">' . esc_html__( 'Older posts', 'ux-shop' ) . '</span>' ); ?></div>
				<?php endif; ?>

				<?php if ( get_previous_posts_link() ) : ?>
					<div class="nav-next"><?php previous_posts_link( '<i class="icon-ws-arrow-right" ></i><span class="meta-nav">' . esc_html__( 'Newer posts', 'ux-shop' ) . '</span>' ); ?></div>
				<?php endif; ?>

			<?php endif; ?>

		</nav><!-- #<?php echo esc_html( $nav_id ); ?> -->
		<?php
	}
}

if ( ! function_exists( 'shrk_comment' ) ) {
	/**
	 * Template for comments and pingbacks.
	 *
	 * Used as a callback by wp_list_comments() for displaying the comments.
	 */
	function shrk_comment( $comment, $args, $depth ) {
		$GLOBALS['comment'] = $comment;

		if ( 'pingback' == $comment->comment_type || 'trackback' == $comment->comment_type ) : ?>

		<li id="comment-<?php comment_ID(); ?>" <?php comment_class( 'media' ); ?>>
			<div class="comment-body">
				<?php esc_html_e( 'Pingback:', 'ux-shop' ); ?> <?php comment_author_link(); ?> <?php edit_comment_link( esc_html__( 'Edit', 'ux-shop' ), '<span class="edit-link">', '</span>' ); ?>
			</div>

		<?php else : ?>

			<li id="comment-<?php comment_ID(); ?>" <?php comment_class( empty( $args['has_children'] ) ? '' : 'parent' ); ?>>
				<article id="div-comment-<?php comment_ID(); ?>" class="comment-body media">
					<a class="pull-left" href="#">
						<?php if ( 0 != $args['avatar_size'] ) echo get_avatar( $comment, $args['avatar_size'] ); ?>
					</a>

					<div class="media-body">
						<div class="media-body-wrap panel">

							<h5 class="media-heading"><?php printf( wp_kses( __( '%s <span class="says">says:</span>', 'ux-shop' ), shrk_kses_allowed() ), sprintf( '<cite class="fn">%s</cite>', get_comment_author_link() ) ); ?></h5>
							<p class="comment-meta">
								<a href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ); ?>">
									<time datetime="<?php comment_time( 'c' ); ?>">
										<?php printf( _x( '%1$s at %2$s', '1: date, 2: time', 'ux-shop' ), get_comment_date(), get_comment_time() ); ?>
									</time>
								</a> 
								<?php edit_comment_link( wp_kses( __( '<span class="fa fa-edit"></span> Edit', 'ux-shop' ), shrk_kses_allowed() ), '<span class="edit-link">', '</span>' ); ?>
							</p>

							<?php if ( '0' == $comment->comment_approved ) : ?>
								<p class="comment-awaiting-moderation"><?php esc_html_e( 'Your comment is awaiting moderation.', 'ux-shop' ); ?></p>
							<?php endif; ?>

							<div class="comment-content">
								<?php comment_text(); ?>
							</div><!-- .comment-content -->

							<footer class="reply comment-reply panel-footer">
								<?php comment_reply_link( array_merge( $args, array( 'add_below' => 'div-comment', 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
							</footer><!-- .reply -->

						</div>
					</div><!-- .media-body -->

				</article><!-- .comment-body -->

		<?php
		endif;
	}
}

if ( ! function_exists( 'shrk_the_attached_image' ) ) {
	/**
	 * Prints the attached image with a link to the next attached image.
	 */
	function shrk_the_attached_image() {
		$post                = get_post();
		$attachment_size     = apply_filters( 'shrk_attachment_size', array( 1200, 1200 ) );
		$next_attachment_url = wp_get_attachment_url();

		/**
		 * Grab the IDs of all the image attachments in a gallery so we can get the
		 * URL of the next adjacent image in a gallery, or the first image (if
		 * we're looking at the last image in a gallery), or, in a gallery of one,
		 * just the link to that image file.
		 */
		$attachment_ids = get_posts( array(
			'post_parent'    => $post->post_parent,
			'fields'         => 'ids',
			'numberposts'    => -1,
			'post_status'    => 'inherit',
			'post_type'      => 'attachment',
			'post_mime_type' => 'image',
			'order'          => 'ASC',
			'orderby'        => 'menu_order ID'
			) );

		// If there is more than 1 attachment in a gallery...
		if ( count( $attachment_ids ) > 1 ) {
			foreach ( $attachment_ids as $attachment_id ) {
				if ( $attachment_id == $post->ID ) {
					$next_id = current( $attachment_ids );
					break;
				}
			}

			// get the URL of the next image attachment...
			if ( $next_id )
				$next_attachment_url = get_attachment_link( $next_id );

			// or get the URL of the first image attachment.
			else
				$next_attachment_url = get_attachment_link( array_shift( $attachment_ids ) );
		}

		printf( '<a href="%1$s" title="%2$s" rel="attachment">%3$s</a>',
			esc_url( $next_attachment_url ),
			the_title_attribute( array( 'echo' => false ) ),
			wp_get_attachment_image( $post->ID, $attachment_size )
			);
	}
}


if ( ! function_exists( 'shrk_entry_meta' ) ) {
	/**
	 * Prints HTML with meta information for the current post-date/time and author.
	 */
	function shrk_entry_meta() {
		$time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time>';
		
		$time_string = sprintf( $time_string,
			esc_attr( get_the_date( 'c' ) ),
			esc_html( get_the_date() )
			);
		
		$time_string = sprintf( '<a href="%1$s" title="%2$s" rel="bookmark">%3$s</a>',
			esc_url( get_permalink() ),
			esc_attr( get_the_time() ),
			$time_string
			);
		
		if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ){
			$time_string_update = '<time class="updated" datetime="%1$s">%2$s</time>';
			$time_string_update = sprintf( $time_string_update,
				esc_attr( get_the_modified_date( 'c' ) ),
				esc_html( get_the_modified_date() )
				);
			$time_string_update = sprintf( '<a href="%1$s" title="%2$s" rel="bookmark">%3$s</a>',
				esc_url( get_permalink() ),
				esc_attr( get_the_time() ),
				$time_string_update
				);
			$time_string .= esc_html__(', updated on ', 'ux-shop') . $time_string_update;
		} 
		
		printf( '<span class="posted-on">' . esc_html__( 'Posted on %1$s', 'ux-shop' ) . '</span> <span class="byline">' . esc_html__( 'by %2$s', 'ux-shop' ) . '</span>',
			$time_string,
			sprintf( '<span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s">%3$s</a></span>',
				esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
				esc_attr( sprintf( esc_html__( 'View all posts by %s', 'ux-shop' ), get_the_author() ) ),
				esc_html( get_the_author() )
				)
			);

		shrk_entry_meta_taxonomies();
	}	
}

/**
 * Prints List of categories and tags
 * comma separated in html tags
 */
function shrk_entry_meta_taxonomies() {
	$categories_list = get_the_category_list( _x( ', ', 'Used between list items, there is a space after the comma.', 'ux-shop' ) );
	if ( $categories_list && shrk_categorized_blog() ) {
		printf( '<span class="cat-links">%1$s<span class="screen-reader-text">%2$s </span>%3$s</span>',
			_x( ' in ', 'Like posted `in` category', 'ux-shop' ),
			_x( 'Categories', 'Used before category names.', 'ux-shop' ),
			$categories_list
		);
	}
	$tags_list = get_the_tag_list( '', _x( ', ', 'Used between list items, there is a space after the comma.', 'ux-shop' ) );
	if ( $tags_list ) {
		printf( '<span class="tags-links">%1$s<span class="screen-reader-text">%2$s </span>%3$s</span>',
			_x( ' tagged ', 'Like `tagged` with tags', 'ux-shop' ),
			_x( 'Tags', 'Used before tag names.', 'ux-shop' ),
			$tags_list
		);
	}
}

/**
 * Returns true if a blog has more than 1 category
 * 
 * @return boolean
 */
function shrk_categorized_blog() {
	if ( false === ( $all_the_cool_cats = get_transient( 'all_the_cool_cats' ) ) ) {
		// Create an array of all the categories that are attached to posts
		$all_the_cool_cats = get_categories( array(
			'hide_empty' => 1,
			) );

		// Count the number of categories that are attached to the posts
		$all_the_cool_cats = count( $all_the_cool_cats );

		set_transient( 'all_the_cool_cats', $all_the_cool_cats );
	}

	if ( '1' != $all_the_cool_cats ) {
		return true;
	} else {
		return false;
	}
}

/**
 * Echoes a small SVG graphic used as a separator
 */
function shrk_get_separator_svg() {
	?>
	<div class="theme-sep small">
		<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
			 width="30.422px" height="7px" viewBox="0 0 30.422 7" enable-background="new 0 0 30.422 7" xml:space="preserve">
		<g>
			<defs>
				<rect id="SVGID_1_" x="-6.057" width="45" height="7"/>
			</defs>
			<clipPath id="SVGID_2_">
				<use xlink:href="#SVGID_1_"  overflow="visible"/>
			</clipPath>
			<path clip-path="url(#SVGID_2_)" fill="#E0382F" d="M32.869,7l-0.926-0.926L38.018,0l0.926,0.926L32.869,7z M29.069,7l-0.926-0.926
				L34.218,0l0.926,0.926L29.069,7z M25.27,7l-0.926-0.926L30.418,0l0.926,0.926L25.27,7z M21.469,7l-0.926-0.926L26.617,0
				l0.926,0.926L21.469,7z M17.67,7l-0.926-0.926L22.818,0l0.926,0.926L17.67,7z M13.869,7l-0.926-0.926L19.018,0l0.926,0.926
				L13.869,7z M10.069,7L9.144,6.074L15.218,0l0.926,0.926L10.069,7z M2.469,7L1.543,6.074L7.618,0l0.926,0.926L2.469,7z M-1.331,7
				l-0.926-0.926L3.818,0l0.926,0.926L-1.331,7z M6.27,7L5.344,6.074L11.417,0l0.926,0.926L6.27,7z M-5.13,7l-0.926-0.926L0.018,0
				l0.926,0.926L-5.13,7z"/>
		</g>
		</svg>
	</div>
	<?php
}

/**
 * Echoes a clearfix div
 */
function shrk_get_clearfix_div() {
	?>
	<div class="clearfix"></div>
	<?php
}

/**
 * Echoes the go to top button
 */
function shrk_get_top_link_button() {
	$style = shrk_get_theme_option( 'scroll_to_top_button_style', false ) ? 'round' : 'square';
	?>
	<a href="#" id="scroll-to-top" class="<?php echo esc_attr( $style ); ?>" title="<?php echo esc_html__( 'Scroll to top', 'ux-shop' ); ?>"><i class="ion ion-ios-arrow-up"></i></a>
	<?php
}


if ( ! function_exists( 'shrk_get_share_buttons' ) ) {
	/**
	 * Echoes the share buttons div
	 */
	function shrk_get_share_buttons() {

		$share_link_url        = esc_url( get_the_permalink() );
		$share_image_url       = esc_url( shrk_get_post_thumbnail_url() );
		$share_link_title      = esc_attr( get_the_title() );
		$share_summary         = esc_html( get_the_excerpt() );
		$share_twitter_summary = esc_html( get_the_excerpt() );
		$enabled_providers     = apply_filters( 'shrk_social_share_providers', shrk_get_theme_option( 'social_share_providers', array() ) );

		echo '<div class="share-button"><div class="social-icons">';
			foreach ($enabled_providers as $key => $provider) {
				switch ($provider) {
					case 'facebook':
						$fb_url = '//www.facebook.com/sharer.php?u=' . $share_link_url;
						?> 
						<a target="_blank" class="icon facebook" href="<?php echo esc_url( $fb_url ); ?>" title="<?php esc_html_e( 'Facebook', 'ux-shop' ) ?>" data-label="Facebook" onclick="window.open(this.href,this.title,'width=500,height=500,top=300px,left=300px');  return false;" rel="nofollow"></a>
						<?php
						break;
					case 'twitter':
						$twitter_url = '//twitter.com/share?url=' . $share_link_url . '&amp;text=' . $share_twitter_summary;
						?>
						<a target="_blank" class="icon twitter" href="<?php echo esc_url( $twitter_url ); ?>" title="<?php esc_html_e( 'Twitter', 'ux-shop' ) ?>" onclick="window.open(this.href,this.title,'width=500,height=500,top=300px,left=300px');  return false;" rel="nofollow"></a>
						<?php
						break;
					case 'pinterest':
						$pinterest_url = '//pinterest.com/pin/create/button/?url=' . $share_link_url . '&amp;description=' . $share_summary . '&amp;media=' . $share_image_url;
						?>
						<a target="_blank" class="icon pinterest" href="<?php echo esc_url( $pinterest_url ); ?>" title="<?php esc_html_e( 'Pinterest', 'ux-shop' ) ?>" onclick="window.open(this.href,this.title,'width=500,height=500,top=300px,left=300px');  return false;" rel="nofollow"></a>
						<?php
						break;
					case 'googleplus':
						$gplus_url = '//plus.google.com/share?url=' . $share_link_url;
						?>
						<a target="_blank" class="icon googleplus" href="<?php echo esc_url( $gplus_url ); ?>" title="<?php esc_html_e( 'Google+', 'ux-shop' ) ?>" onclick="window.open(this.href,this.title,'width=500,height=500,top=300px,left=300px');  return false;" rel="nofollow"></a>
						<?php
						break;
					case 'email':
						$email_url = 'mailto:?subject=I%20wanted%20you%20to%20see%20this%20site&amp;body=' . $share_link_url . '&amp;title=' . $share_link_title;
						?>
						<a class="icon email" href="<?php echo esc_url( $email_url ); ?>" title="<?php esc_html_e( 'Email', 'ux-shop' ) ?>"></a>
						<?php
						break;
					case 'linkedin':
						$linkedin_url = '//www.linkedin.com/shareArticle?mini=true&amp;url=' . $share_link_url . '&amp;title=' . $share_link_title;
						?>
						<a target="_blank" class="icon linkedin" href="<?php echo esc_url( $linkedin_url ); ?>" title="<?php esc_html_e( 'LinkedIn', 'ux-shop' ) ?>" onclick="window.open(this.href,this.title,'width=500,height=500,top=300px,left=300px');  return false;" rel="nofollow"></a>
						<?php
						break;	
					default:
						break;
				}
			}
		echo '</div></div>';
	}
}

/**
 * Filters the attributes for the page cover
 * 
 * @param  string $classes space separated list of css classes
 * @return string          space separated list of attributes for the page cover element
 */
function shrk_get_page_cover_atts( $classes ) {
	global $post;
	$atts        = array();
	$style_rules = array();
	$data        = array();
	$classes     = explode(' ', $classes);

	if ( shrk_get_cover_image() ) {

		$classes[]     = 'has-cover-image';

		// Text color theme
		$classes[] = shrk_get_mso( 'cover_text_theme' ) == 'dark' ? 'dark' : 'light';

		// Cover overlay
		if ( shrk_get_mso( 'cover_overlay_enabled' ) == '1' ) {
			$classes[] = 'has-overlay';	

			if ( shrk_get_mso( 'cover_overlay_opacity_min' ) !== NULL ) {
				$data[] = 'data-opac-min="' . esc_attr( shrk_get_mso( 'cover_overlay_opacity_min' ) ) . '"';
			}
			
			if ( shrk_get_mso( 'cover_overlay_opacity_max' ) !== NULL ) {
				$data[] = 'data-opac-max="' . esc_attr( shrk_get_mso( 'cover_overlay_opacity_max' ) ) . '"';
			}

			add_action( 'shrk-page-cover-after', 'shrk_cover_overlay_div' );
		} else {
			$classes[] = 'no-overlay';	
		}

		// Bottom shadow
		if ( shrk_get_mso( 'cover_image_shadow' ) == '1' ) {
			$classes[] = 'shadow-bottom';
		}
		
		// Header fadeout on scroll out
		if ( shrk_get_mso( 'cover_header_fade' ) == '1' ) {
			$classes[] = 'fade-header';
		}

		// Show or hide the page header
		if ( shrk_get_mso( 'hide_cover_page_header' ) == '1' ) {
			$classes[] = 'no-page-header';
		}

		// Set cover height mode
		if ( $cover_height_mode = shrk_get_mso( 'cover_height_mode' ) ) {
			$classes[] = $cover_height_mode;
		}

		// Set cover height and padding
		if ( $cover_height_mode == 'customheight' && shrk_get_mso( 'cover_custom_height' ) ) {
			$data[] = 'data-section-height="' . esc_attr( shrk_get_mso( 'cover_custom_height' ) ) . '"';
		} elseif ( $cover_height_mode == 'paddingheight' && $cover_padding = shrk_get_mso( 'cover_padding' ) ) {
			$style_rules[] = 'padding-top: ' . $cover_padding['padding-top'] . ';';
			$style_rules[] = 'padding-bottom: ' . $cover_padding['padding-bottom'] . ';';
		}
	}

	// Title uppercase
	if ( shrk_get_mso( 'cover_no_uppercase_title' ) == '1' ) {
		$classes[] = 'no-forced-uppercase';
	}

	$classes = apply_filters( 'shrk-page-cover-classes', $classes );

	$atts['style']   = 'style="' . esc_attr( implode(' ', $style_rules) ) . '"';
	$atts['classes'] = 'class="' . esc_attr( implode(' ', $classes) ) . '"';
	$atts['data']    = implode(' ', $data);

	return implode(' ', $atts);
}
add_filter( 'shrk-page-cover-atts', 'shrk_get_page_cover_atts' );

function shrk_get_cover_background_div() {
	global $post;
	
	if ( shrk_get_cover_image() ) {
		$atts = $style_rules = $data = $classes = array();

		if ( apply_filters( 'shrk-page-cover-lazyload-bg', true ) ) {
			$cover_id  = shrk_get_cover_image( array(), true );
			$srcset    = !empty( $cover_id ) ? wp_get_attachment_image_srcset( $cover_id, 'shrk_section_bg' ) : '';
			$data[]    = 'data-image-bg="' . esc_url( shrk_get_cover_image() ) . '"';
			$data[]    = 'data-image-ar="' . esc_attr( shrk_get_image_aspect( $cover_id, 'shrk_section_bg' ) ) . '"';
			$data[]    = 'data-srcset="' . esc_attr( $srcset ) . '"';
			$classes[] = 'lazyload-bg';
			$classes[] = 'lazyload-on-visible';
		} else {
			$style_rules[] = 'background-image: url(\'' . esc_url( shrk_get_cover_image() ) . '\');';
		}

		// Parallax (stellar.js)
		if ( shrk_get_mso( 'cover_parallax' ) ) {
			wp_enqueue_script( 'jquery-stellar' ); 
			$data[]    = 'data-stellar-ratio="' . intval( shrk_get_mso( 'cover_parallax_ratio', $post->ID, '50' ) )/100 . '"';
			$data[]    = 'data-stellar-vertical-offset="' . intval( shrk_get_mso( 'cover_parallax_offset', $post->ID, '0' ) ) . '"';
			$classes[] = 'parallax-bg';
		}

		$atts['style']   = 'style="' . esc_attr( implode(' ', $style_rules) ) . '"';
		$atts['classes'] = 'class="' . esc_attr( implode(' ', $classes) ) . '"';
		$atts['data']    = implode(' ', $data);

		echo '<div class="page-cover-bg ' . implode(' ', $classes) . '" ' . implode(' ', $atts) . '></div>';
	}
}
add_action( 'shrk-page-cover-after', 'shrk_get_cover_background_div' );

/**
 * Echoes the cover-overlay div
 * for use in the page cover
 */
function shrk_cover_overlay_div() {
	echo '<div class="cover-overlay"></div>';
}

/**
 * Get the cover image to display
 * @param  array   $atts   Attributes array to control output
 * @param  boolean $getID  Makes the function return the ID instead of the URL of the cover image
 * @return string  Source URL of the cover image
 */
function shrk_get_cover_image( $atts = array(), $getID = FALSE ) {
	global $post;
	$cover = $cover_id = $is_product = null;

	if ( is_home() && get_option( 'page_for_posts' ) ) {
		$cover    = wp_get_attachment_image_src( get_post_thumbnail_id( get_option( 'page_for_posts' ) ), 'shrk_section_bg' );
		$cover_id = get_post_thumbnail_id( get_option( 'page_for_posts' ) );
		$cover    = $cover[0];
	}

	if ( ( is_singular() || ( defined('DOING_AJAX') && DOING_AJAX ) ) && get_post_type( $post->ID ) == 'product' ) { //note: is_product returns false when called through shortcode
		$is_product = true;

		if ( isset( $atts['thumb_fb'] ) ) {
			$thumb_fb = $atts['thumb_fb'];
		} else {
			$thumb_fb = shrk_get_mso( 'cover_thumbnail_fallback' ) == '1' ? true : false;	
		}

		if ( shrk_get_meta_option( 'product_cover_image' ) ) {
			$cover_id = shrk_get_meta_option( 'product_cover_image' );
			$cover    = wp_get_attachment_image_src( $cover_id, 'shrk_section_bg' );
			$cover    = $cover[0];
		}

		if ( !$cover && $thumb_fb && has_post_thumbnail() ) {
			$cover = shrk_get_post_thumbnail_url( 'shrk_section_bg' );
			$cover_id = get_post_thumbnail_id();
		}
	}

	if ( !$cover && is_singular() && !$is_product && has_post_thumbnail() ) {
		$cover = shrk_get_post_thumbnail_url( 'shrk_section_bg' );
		$cover_id = get_post_thumbnail_id();
	}

	$cover    = apply_filters( 'shrk-cover-image', $cover );
	$cover_id = apply_filters( 'shrk-cover-image-id', $cover_id );

	if ( $getID ) {
		return !empty( $cover_id ) ? $cover_id : false;
	} else {
		return !empty( $cover ) ? $cover : false;
	}
}

/**
 * Check if a cover image is available
 * @return boolean
 */
function shrk_has_cover_image() {
	return shrk_get_cover_image() ? true : false;
}

/**
 * Add full image size to src_set
 * As WP doesn't include unless requested
 * but can be usefull for hi-dpi screens.
 * 
 * @since 1.0.8
 *
 * @param array  $sources {
 *     One or more arrays of source data to include in the 'srcset'.
 *
 *     @type array $width {
 *         @type string $url        The URL of an image source.
 *         @type string $descriptor The descriptor type used in the image candidate string,
 *                                  either 'w' or 'x'.
 *         @type int    $value      The source width if paired with a 'w' descriptor, or a
 *                                  pixel density value if paired with an 'x' descriptor.
 *     }
 * }
 * @param array  $size_array    Array of width and height values in pixels (in that order).
 * @param string $image_src     The 'src' of the image.
 * @param array  $image_meta    The image meta data as returned by 'wp_get_attachment_metadata()'.
 * @param int    $attachment_id Image attachment ID or 0.
 */
function shrk_add_image_srcset( $sources, $size_array, $image_src, $image_meta, $attachment_id ) {

	$full_meta = wp_get_attachment_metadata( $attachment_id );
	if ( !empty( $full_meta ) && !isset( $sources[ $full_meta['width'] ] ) ) {
	
		$is_src = false;

		// Get the width and height of the image.
		$image_width = (int) $size_array[0];
		$image_height = (int) $size_array[1];

		// Retrieve the uploads sub-directory from the full size image.
		$dirname = _wp_get_attachment_relative_path( $full_meta['file'] );

		if ( $dirname ) {
			$dirname = trailingslashit( $dirname );
		}

		$upload_dir = wp_get_upload_dir();
		$baseurl = trailingslashit( $upload_dir['baseurl'] );

		/*
		 * If currently on HTTPS, prefer HTTPS URLs when we know they're supported by the domain
		 * (which is to say, when they share the domain name of the current request).
		 */
		if ( is_ssl() && 'https' !== substr( $baseurl, 0, 5 ) && parse_url( $baseurl, PHP_URL_HOST ) === $_SERVER['HTTP_HOST'] ) {
			$baseurl = set_url_scheme( $baseurl, 'https' );
		}

		// If the file name is part of the `src`, we've confirmed a match.
		if ( false !== strpos( $image_src, $full_meta['file'] ) ) {
			$is_src = true;
		}

		// If the image dimensions are within 1px of the expected size, use it.
		if ( wp_image_matches_ratio( $image_width, $image_height, $full_meta['width'], $full_meta['height'] ) ) {
			// Add the URL, descriptor, and value to the sources array to be returned.
			$source = array(
				'url'        => $baseurl . $full_meta['file'],
				'descriptor' => 'w',
				'value'      => $full_meta['width'],
			);

			// The 'src' image has to be the first in the 'srcset', because of a bug in iOS8. See #35030.
			if ( $is_src ) {
				$sources = array( $full_meta['width'] => $source ) + $sources;
			} else {
				$sources[ $full_meta['width'] ] = $source;
			}
		}
		
	}

	return $sources;
}
add_filter( 'wp_calculate_image_srcset', 'shrk_add_image_srcset', 10, 5 );

/**
 * Returns the Aspect ratio of an image round to 3 decimal points
 * 
 * @param  integer $img_id The image id
 * @param  string $size    Image size
 * @return float           The Aspect ratio
 */
function shrk_get_image_aspect( $img_id, $size = 'thumbnail' ) {
	if ( empty( $img_id ) ) {
		return '';
	}

	$img_obj = wp_get_attachment_image_src( $img_id, $size );

	if ( !empty( $img_obj ) && !empty( $img_obj[1] ) && !empty( $img_obj[2] ) ) {
		return round ( intval( $img_obj[1] ) / intval( $img_obj[2] ), 3 );
	}

	return '';
}

/**
 * Helper to retrieve the image URL for a post thumbnail
 * @param  string $size the requested image size
 * @return string       the image url
 */
function shrk_get_post_thumbnail_url( $size = 'shrk_section_bg' ) {
	$post_thumbnail = wp_get_attachment_image_src( get_post_thumbnail_id(), $size );
	return $post_thumbnail[0];
}

/**
 * Flush out the transients used in shrk_categorized_blog
 */
function shrk_category_transient_flusher() {
	delete_transient( 'all_the_cool_cats' );
}
add_action( 'edit_category', 'shrk_category_transient_flusher' );
add_action( 'save_post',     'shrk_category_transient_flusher' );

/**
 * shrk_tag_cloud_mod
 * modifies tag cloud (widget)
 */
function shrk_tag_cloud_mod( $return, $tags, $args ) {

	$counts = array();
	$el_class = "";
	$real_counts = array(); // For the alt tag
	foreach ( (array) $tags as $key => $tag ) {
		$real_counts[ $key ] = $tag->count;
		$counts[ $key ] = call_user_func( $args['topic_count_scale_callback'], $tag->count );
	}

	// Assemble the data that will be used to generate the tag cloud markup.
	$tags_data = array();
	foreach ( $tags as $key => $tag ) {
		$tag_id = isset( $tag->id ) ? $tag->id : $key;

		$count = $counts[ $key ];
		$real_count = $real_counts[ $key ];

		$el_class = is_tag( $tag_id ) || is_tax( 'product_tag', $tag_id ) ? ' current-tag' : '';

		$tags_data[] = array(
			'id'         => $tag_id,
			'url'        => '#' != $tag->link ? $tag->link : '#',
			'name'	     => $tag->name,
			'title'      => sprintf( esc_html__( '%d items tagged %s', 'ux-shop' ), $real_count, $tag->name ),
			'slug'       => $tag->slug,
			'real_count' => $real_count,
			'class'	     => esc_attr( 'tag-link-' . $tag_id . $el_class ),
		);
	}

	/**
	 * Filter the data used to generate the tag cloud.
	 *
	 * @since 4.3.0
	 *
	 * @param array $tags_data An array of term data for term used to generate the tag cloud.
	 */
	$tags_data = apply_filters( 'wp_generate_tag_cloud_data', $tags_data );

	$a = array();

	// generate the output links array
	foreach ( $tags_data as $key => $tag_data ) {
		$a[] = "<a href='" . esc_url( $tag_data['url'] ) . "' class='" . esc_attr( $tag_data['class'] ) . "' title='" . esc_attr( $tag_data['title'] ) . "'>" . esc_html( $tag_data['name'] ) . "<span class='tag-count'>" . esc_attr( $tag_data['real_count'] ) . "</span></a>";
	}

	switch ( $args['format'] ) {
		case 'array' :
			$return =& $a;
			break;
		case 'list' :
			$return = "<ul class='wp-tag-cloud'>\n\t<li>";
			$return .= join( "</li>\n\t<li>", $a );
			$return .= "</li>\n</ul>\n";
			break;
		default :
			$return = join( $args['separator'], $a );
			break;
	}

	return $return;
}
add_filter( 'wp_generate_tag_cloud', 'shrk_tag_cloud_mod', 10, 3 );

?>