<?php

/**
 * This source file is subject to the GNU GENERAL PUBLIC LICENSE (GPL 3.0)
 * It is also available at this URL: http://www.gnu.org/licenses/gpl-3.0.txt
 */

define( 'CITYMAG_MIN_PHP_VERSION', '5.3' );

/*-----------------------------------------------------------------------------------*/
/* Switches back to the previous theme if the minimum PHP version is not met */
/*-----------------------------------------------------------------------------------*/

if ( ! function_exists( 'citymag_check_php_version' ) ) {

	function citymag_check_php_version() {

		if ( version_compare( PHP_VERSION, CITYMAG_MIN_PHP_VERSION, '<' ) ) {
			add_action( 'admin_notices', 'citymag_min_php_not_met_notice' );
			switch_theme( get_option( 'theme_switched' ));
			return false;

		};
	}

	add_action( 'after_switch_theme', 'citymag_check_php_version' );

}

/*-----------------------------------------------------------------------------------*/
/* An error notice that can be displayed if the Minimum PHP version is not met */
/*-----------------------------------------------------------------------------------*/

if ( ! function_exists( 'citymag_min_php_not_met_notice' ) ) {

	function citymag_min_php_not_met_notice() {
		?>
		<div class="notice notice-error is_dismissable">
			<p>
				<?php esc_html_e('You need to update your PHP version to run this theme.', 'citymag' ); ?><br />
				<?php
				printf(
					esc_html__( 'Actual version is: %1$s, required version is: %2$s.', 'citymag' ),
					PHP_VERSION,
					CITYMAG_MIN_PHP_VERSION
				);
				?>
			</p>
		</div>
		<?php

	}

}

/*-----------------------------------------------------------------------------------*/
/* WooCommerce is active */
/*-----------------------------------------------------------------------------------*/

if ( ! function_exists( 'citymag_is_woocommerce_active' ) ) {

	function citymag_is_woocommerce_active( $type = '' ) {

        global $woocommerce;

        if ( isset( $woocommerce ) ) {

			if ( !$type || call_user_func($type) ) {

				return true;

			}

		}

	}

}

/*-----------------------------------------------------------------------------------*/
/* Get post comments */
/*-----------------------------------------------------------------------------------*/

if ( ! function_exists( 'citymag_comments' ) ) {

	function citymag_comments($comment, $args, $depth) {

	?>

		<li <?php comment_class(); ?> id="li-comment-<?php comment_ID() ?>">

		<div id="comment-<?php comment_ID(); ?>" class="comment-container">

			<div class="comment-avatar">
				<?php echo get_avatar($comment->comment_author_email, 80 ); ?>
			</div>

			<div class="comment-text">

            	<header class="comment-author">

                    <span class="author"><cite><?php printf( esc_html__('%s has written:','citymag'), get_comment_author_link());?> </cite></span>

                    <time datetime="<?php echo esc_attr(get_comment_date())?>" class="comment-date">

                        <a href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ) ?>">
                            <?php printf(esc_html__('%1$s at %2$s','citymag'), get_comment_date(),  get_comment_time()) ?>
                        </a>

                        <?php

							comment_reply_link(
								array_merge(
									$args,
									array(
										'depth' => $depth,
										'max_depth' => $args['max_depth']
									)
								)
							);

							edit_comment_link(esc_html__('(Edit)','citymag'));

						?>

                    </time>

				</header>

				<?php if ($comment->comment_approved == '0') : ?>

                    <p><em><?php esc_html_e('Your comment is awaiting approval.','citymag') ?></em></p>

				<?php endif; ?>

				<?php comment_text() ?>

			</div>

			<div class="clear"></div>

		</div>

	<?php

	}

}

/*-----------------------------------------------------------------------------------*/
/* Get archive title */
/*-----------------------------------------------------------------------------------*/

if (!function_exists('citymag_get_the_archive_title')) {

	function citymag_get_archive_title() {

		if ( is_category() ) {
			$title = sprintf( esc_html__( 'Category: %s', 'citymag' ), single_cat_title( '', false ) );
		} elseif ( is_tag() ) {
			$title = sprintf( esc_html__( 'Tag: %s', 'citymag' ), single_tag_title( '', false ) );
		} elseif ( is_author() ) {
			$title = sprintf( esc_html__( 'Author: %s', 'citymag' ), '<span class="vcard">' . get_the_author() . '</span>' );
		} elseif ( is_year() ) {
			$title = sprintf( esc_html__( 'Year: %s', 'citymag' ), get_the_date( esc_html_x( 'Y', 'yearly archives date format', 'citymag' ) ) );
		} elseif ( is_month() ) {
			$title = sprintf( esc_html__( 'Month: %s', 'citymag' ), get_the_date( esc_html_x( 'F Y', 'monthly archives date format', 'citymag' ) ) );
		} elseif ( is_day() ) {
			$title = sprintf( esc_html__( 'Day: %s', 'citymag' ), get_the_date( esc_html_x( 'F j, Y', 'daily archives date format', 'citymag' ) ) );
		} elseif ( is_tax( 'post_format' ) ) {
			if ( is_tax( 'post_format', 'post-format-aside' ) ) {
				$title = esc_html_x( 'Asides', 'post format archive title', 'citymag' );
			} elseif ( is_tax( 'post_format', 'post-format-gallery' ) ) {
				$title = esc_html_x( 'Galleries', 'post format archive title', 'citymag' );
			} elseif ( is_tax( 'post_format', 'post-format-image' ) ) {
				$title = esc_html_x( 'Images', 'post format archive title', 'citymag' );
			} elseif ( is_tax( 'post_format', 'post-format-video' ) ) {
				$title = esc_html_x( 'Videos', 'post format archive title', 'citymag' );
			} elseif ( is_tax( 'post_format', 'post-format-quote' ) ) {
				$title = esc_html_x( 'Quotes', 'post format archive title', 'citymag' );
			} elseif ( is_tax( 'post_format', 'post-format-link' ) ) {
				$title = esc_html_x( 'Links', 'post format archive title', 'citymag' );
			} elseif ( is_tax( 'post_format', 'post-format-status' ) ) {
				$title = esc_html_x( 'Statuses', 'post format archive title', 'citymag' );
			} elseif ( is_tax( 'post_format', 'post-format-audio' ) ) {
				$title = esc_html_x( 'Audio', 'post format archive title', 'citymag' );
			} elseif ( is_tax( 'post_format', 'post-format-chat' ) ) {
				$title = esc_html_x( 'Chats', 'post format archive title', 'citymag' );
			}
		} elseif ( is_post_type_archive() ) {
			$title = sprintf( esc_html__( 'Archives: %s', 'citymag' ), post_type_archive_title( '', false ) );
		} elseif ( is_tax() ) {
			$tax = get_taxonomy( get_queried_object()->taxonomy );
			$title = sprintf( esc_html__( '%1$s: %2$s', 'citymag' ), $tax->labels->singular_name, single_term_title( '', false ) );
		}

		if ( isset($title) )  :
			return $title;
		else:
			return false;
		endif;

	}

}

/*-----------------------------------------------------------------------------------*/
/* Check if is single page */
/*-----------------------------------------------------------------------------------*/

if (!function_exists('citymag_is_single')) {

	function citymag_is_single() {

		if ( is_single() || is_page() ) :

			return true;

		endif;

	}

}

/*-----------------------------------------------------------------------------------*/
/* Get theme setting */
/*-----------------------------------------------------------------------------------*/

if (!function_exists('citymag_setting')) {

	function citymag_setting($id, $default = FALSE ) {

		return get_theme_mod($id, $default);

	}

}

/*-----------------------------------------------------------------------------------*/
/* Get post meta */
/*-----------------------------------------------------------------------------------*/

if (!function_exists('citymag_postmeta')) {

	function citymag_postmeta( $id, $default = '' ) {

		global $post, $wp_query;

		if (citymag_is_woocommerce_active('is_shop')) :

			$content_ID = get_option('woocommerce_shop_page_id');

		else :

			$content_ID = (isset($post->ID)) ? $post->ID : false;

		endif;

		$val = get_post_meta( $content_ID , $id, TRUE);

		if ( !empty($val) ) :

			return $val;

		else:

			return $default;

		endif;

	}

}

/*-----------------------------------------------------------------------------------*/
/* Add Skype on allowed protocols */
/*-----------------------------------------------------------------------------------*/

if (!function_exists('citymag_kses_allowed_protocols')) {

	function citymag_kses_allowed_protocols($protocols) {

		$protocols[] = 'skype';
		return $protocols;

	}

	add_filter( 'kses_allowed_protocols', 'citymag_kses_allowed_protocols');

}

/*-----------------------------------------------------------------------------------*/
/* Responsive embed */
/*-----------------------------------------------------------------------------------*/

if (!function_exists('citymag_embed_html')) {

	function citymag_embed_html( $html ) {
		return '<div class="embed-container">' . $html . '</div>';
	}

	add_filter( 'embed_oembed_html', 'citymag_embed_html', 10, 3 );
	add_filter( 'video_embed_html', 'citymag_embed_html' );

}

/*-----------------------------------------------------------------------------------*/
/* Content template */
/*-----------------------------------------------------------------------------------*/

if (!function_exists('citymag_template')) {

	function citymag_template($id) {

		$template = array (

			'full' => 'col-md-12' ,
			'left-sidebar' => 'col-md-8' ,
			'right-sidebar' => 'col-md-8'

		);

		$span = $template['right-sidebar'];
		$sidebar =  'right-sidebar';

		if (
			citymag_is_woocommerce_active('is_woocommerce') &&
			citymag_postmeta('citymag_template') &&
			is_search()
		) {

			$span = $template[esc_attr(citymag_postmeta('citymag_template'))];
			$sidebar =  esc_attr(citymag_postmeta('citymag_template'));

		} elseif (
			!is_attachment() &&
			citymag_postmeta('citymag_template') &&
			(is_page() || is_single() || citymag_is_woocommerce_active('is_shop'))
		) {

			$span = $template[esc_attr(citymag_postmeta('citymag_template'))];
			$sidebar =  esc_attr(citymag_postmeta('citymag_template'));

		} elseif (
			!citymag_is_woocommerce_active('is_woocommerce') &&
			( is_category() || is_tag() || is_month() ) &&
			citymag_setting('citymag_category_layout')
		) {

			$span = $template[esc_attr(citymag_setting('citymag_category_layout'))];
			$sidebar =  esc_attr(citymag_setting('citymag_category_layout'));

		} elseif (
			is_home() &&
			citymag_setting('citymag_home_layout')
		) {

			$span = $template[esc_attr(citymag_setting('citymag_home_layout'))];
			$sidebar =  esc_attr(citymag_setting('citymag_home_layout'));

		} else if (
			!citymag_is_woocommerce_active('is_woocommerce') &&
			is_search() &&
			citymag_setting('citymag_search_layout')
		) {

			$span = $template[esc_attr(citymag_setting('citymag_search_layout'))];
			$sidebar =  esc_attr(citymag_setting('citymag_search_layout'));

		} else if (
			citymag_is_woocommerce_active('is_woocommerce') &&
			( citymag_is_woocommerce_active('is_product_category') || citymag_is_woocommerce_active('is_product_tag') ) &&
			citymag_setting('citymag_woocommerce_category_layout')
		) {

			$span = $template[esc_attr(citymag_setting('citymag_woocommerce_category_layout'))];
			$sidebar =  esc_attr(citymag_setting('citymag_woocommerce_category_layout'));

		} elseif ( is_attachment() ) {

			$span = $template['full'];
			$sidebar =  'full';

		}

		return ${$id};

	}

}

/*-----------------------------------------------------------------------------------*/
/* Is archive */
/*-----------------------------------------------------------------------------------*/

if (!function_exists('citymag_is_archive')) {

	function citymag_is_archive() {

		if (
			is_category() ||
			is_tag() ||
			is_author() ||
			is_year() ||
			is_month()

		) {

			return true;

		} else {

			return false;

		}

	}

}

/*-----------------------------------------------------------------------------------*/
/* BODY CLASSES */
/*-----------------------------------------------------------------------------------*/

if (!function_exists('citymag_body_classes_function')) {

	function citymag_body_classes_function($classes) {

		global $wp_customize;

		if ( isset( $wp_customize ) ) :

			$classes[] = 'is_customizer_panel';

		endif;

		if (
			( is_home() ) ||
			( citymag_is_archive() ) ||
			( is_search() )
		) :

			$classes[] = 'is_blog_section';

		endif;

		if (
			( 
				!get_background_image() &&
				get_theme_mod('background_color','ffffff') == 'ffffff'
			)
		) :

			$classes[] = 'is_minimal_layout';

		endif;

		if ( citymag_setting('citymag_topbar_rightcolumn') == 'secondary_menu') :

			$classes[] = 'is_fullwidth_topbar';

		endif;

		if ( citymag_setting('citymag_underline_below_section_titles', false) == true ) :

			$classes[] = 'hide_underline_below_section_titles';

		endif;

		if ( 
			(
				citymag_is_archive() && 
				citymag_setting('citymag_category_layout') == 'full'
			) || 
			(
				is_search() && 
				citymag_setting('citymag_search_layout') == 'full'
			)
		) :

			$classes[] = 'top-section-fullwidth-layout';
		
		endif;
		
		return $classes;

	}

	add_filter('body_class', 'citymag_body_classes_function');

}

/*-----------------------------------------------------------------------------------*/
/* Post class */
/*-----------------------------------------------------------------------------------*/

if (!function_exists('citymag_post_class')) {

	function citymag_post_class($classes) {

		$masonry  = 'post-container masonry-item col-md-4';
		$standard = 'post-container col-md-12';

		if ( !citymag_is_single() ) {

			if ( is_home() ) {

				if ( 
					citymag_setting('citymag_home_layout') == 'col-md-4'
				) {

					$classes[] = $masonry;

				} else {

					$classes[] = $standard;

				}

			} else if ( is_archive() && !citymag_is_woocommerce_active('is_shop') ) {

				if ( citymag_setting('citymag_category_layout') == 'col-md-4' ) {

					$classes[] = $masonry;

				} else {

					$classes[] = $standard;

				}

			} else if ( is_search() ) {

				if ( citymag_setting('citymag_search_layout') == 'col-md-4' ) {

					$classes[] = $masonry;

				} else {

					$classes[] = $standard;

				}

			}

		} else if ( citymag_is_single() && citymag_is_woocommerce_active('is_cart') ) {

			$classes[] = 'post-container col-md-12 woocommerce_cart_page';

		} else if ( citymag_is_single() && !citymag_is_woocommerce_active('is_product') ) {

			$classes[] = 'post-container col-md-12';

		} else if ( is_page() ) {

			$classes[] = 'full';

		}

		if (
			( is_home() ) ||
			( citymag_is_archive() ) ||
			( is_search() )
		) :

			$classes[] = 'post-container-wrap';

		endif;
		
		if (
			(
				( is_home() ) ||
				( citymag_is_archive() ) ||
				( is_search() )
	
			) &&
			( citymag_setting('citymag_has_post_placeholder', true) == true)
		) :

			$classes[] = 'has-post-placeholder';

		endif;

		return $classes;

	}

	add_filter('post_class', 'citymag_post_class');

}

/*-----------------------------------------------------------------------------------*/
/* Get paged */
/*-----------------------------------------------------------------------------------*/

if (!function_exists('citymag_paged')) {

	function citymag_paged() {

		if ( get_query_var('paged') ) {
			$paged = get_query_var('paged');
		} elseif ( get_query_var('page') ) {
			$paged = get_query_var('page');
		} else {
			$paged = 1;
		}

		return $paged;

	}

}

/*-----------------------------------------------------------------------------------*/
/* Swipebox post gallery */
/*-----------------------------------------------------------------------------------*/

if (!function_exists('citymag_swipebox')) {

	function citymag_swipebox($html, $id, $size, $permalink, $icon, $text) {

		if ( !$permalink )
			return str_replace( '<a', '<a class="swipebox"', $html );
		else
			return $html;
	}

	add_filter( 'wp_get_attachment_link', 'citymag_swipebox', 10, 6);

}

/*-----------------------------------------------------------------------------------*/
/* Get link url  */
/*-----------------------------------------------------------------------------------*/

if (!function_exists('citymag_get_link_url')) {

	function citymag_get_link_url() {

		$content = get_the_content();
		$has_url = get_url_in_content( $content );
		return ( $has_url ) ? $has_url : apply_filters( 'the_permalink', get_permalink() );

	}

}

/*-----------------------------------------------------------------------------------*/
/* Excerpt more */
/*-----------------------------------------------------------------------------------*/

if (!function_exists('citymag_hide_excerpt_more')) {

	function citymag_hide_excerpt_more() {
		return '';
	}

	add_filter('the_content_more_link', 'citymag_hide_excerpt_more');
	add_filter('excerpt_more', 'citymag_hide_excerpt_more');

}

/*-----------------------------------------------------------------------------------*/
/* Customize excerpt more */
/*-----------------------------------------------------------------------------------*/

if (!function_exists('citymag_customize_excerpt_more')) {

	function citymag_customize_excerpt_more( $excerpt ) {

		global $post;

		if ( citymag_is_single() ) :

			return $excerpt;

		else:

			$allowed = array(
				'span' => array(
					'class' => array(),
				),
			);

			$class = 'button ';
			$button = esc_html__('Read More','citymag');
			$container = 'class="read-more"';

			if ( citymag_setting('citymag_readmore_layout') == "default" || !citymag_setting('citymag_readmore_layout') ) :

				$class = 'button ' . esc_attr(citymag_setting('citymag_readmore_layout'));
				$button = esc_html__('Read More','citymag');
				$container = 'class="read-more"';

			else :

				$class = 'nobutton';
				$button = ' [&hellip;] ';
				$container = '';

			endif;

			if (
				( $pos=strpos($post->post_content, '<!--more-->') ) &&
				!has_excerpt($post->ID)
			):

				$content = apply_filters( 'the_content', get_the_content());

			else:

				$content = $excerpt;

			endif;

			return $content . '<div class="read-more-wrapper"><a '. wp_kses($container, $allowed) . ' href="' . esc_url(get_permalink($post->ID)) . '" title="'.esc_attr__('Read More','citymag').'"> <span class="'.esc_attr($class).'">'.$button.'</span></a></div>';

		endif;


	}

	add_filter( 'get_the_excerpt', 'citymag_customize_excerpt_more' );

}

/*-----------------------------------------------------------------------------------*/
/* Featured posts more tag */
/*-----------------------------------------------------------------------------------*/

if (!function_exists('citymag_featured_post_more_tag')) {

    function citymag_featured_post_more_tag($postID) {

        $excerpt = wp_trim_excerpt('', $postID);

        if (!empty($excerpt)) {
            $more = ' <a href="' . esc_url(get_permalink($postID)) . '">[&hellip;]</a>';
            return $excerpt . $more;
        }

        return $excerpt;
    }

}
	
/*-----------------------------------------------------------------------------------*/
/* Get post icon */
/*-----------------------------------------------------------------------------------*/

if (!function_exists('citymag_posticon')) {

	function citymag_posticon() {
		
		$html = '';

		$icons = array (
			'video' => 'fa fa-play' , 
			'gallery' => 'fa fa-camera' , 
			'audio' => 'fa fa-volume-up' , 
			'chat' => 'fa fa-users', 
			'status' => 'fa fa-keyboard-o', 
			'image' => 'fa fa-picture-o' ,
			'quote' => 'fa fa-quote-left', 
			'link' => 'fa fa-external-link', 
			'aside' => 'fa fa-file-text-o', 
		);

		if ( get_post_format() ) { 
		
			$html .= '<i class="'.esc_attr($icons[get_post_format()]).'"></i> '; 
			$html .= ucfirst( strtolower( esc_html(get_post_format()) )); 
		
		} else {
		
			$html .= '<i class="fa fa-pencil-square"></i> '; 
			$html .= esc_html__( 'Article','citymag'); 
		
		}

		return $html;

	}

}
/*-----------------------------------------------------------------------------------*/
/* Enqueue block editor styles */
/*-----------------------------------------------------------------------------------*/

if (!function_exists('citymag_enqueue_block_editor')) {

	function citymag_enqueue_block_editor() {
		wp_enqueue_style('citymag-block-editor-styles', get_template_directory_uri() . '/assets/css/block-styles.css', array(), '1.0.0' );
	}

	add_action( 'enqueue_block_editor_assets', 'citymag_enqueue_block_editor' );

}
/*-----------------------------------------------------------------------------------*/
/* Enqueue script and styles */
/*-----------------------------------------------------------------------------------*/

if (!function_exists('citymag_scripts_styles')) {

	function citymag_scripts_styles() {

		$googleFontsArgs = array(
			'family' =>    str_replace('|', '%7C', citymag_google_font_args()),
			'subset' =>    'latin,latin-ext'
		);

		wp_enqueue_style('dashicons');
		wp_enqueue_style('google-fonts', add_query_arg ( $googleFontsArgs, "https://fonts.googleapis.com/css" ), array(), '1.0.0' );
		wp_enqueue_style('bootstrap', get_template_directory_uri() . '/assets/css/bootstrap.css', array(), '3.3.7' );
		wp_enqueue_style('font-awesome', get_template_directory_uri() . '/assets/css/font-awesome.css', array(), '4.7.0' );
		wp_enqueue_style('swipebox', get_template_directory_uri() . '/assets/css/swipebox.css', array(), '1.3.0' );
		wp_enqueue_style('slick', get_template_directory_uri() . '/assets/css/slick.css', array(), '1.8.0' );
		wp_enqueue_style('citymag-style', get_stylesheet_uri(), array() );
		wp_enqueue_style('citymag-block-editor-styles', get_template_directory_uri() . '/assets/css/block-styles.css', array(), '1.0.0' );
		wp_enqueue_style('citymag-woocommerce', get_template_directory_uri() . '/assets/css/citymag-woocommerce.css', array(), '1.0.0' );

		wp_enqueue_style(
			'citymag-' . esc_attr(get_theme_mod('citymag_skin', 'orange')),
			get_template_directory_uri() . '/assets/skins/' . esc_attr(get_theme_mod('citymag_skin', 'orange')) . '.css',
			array( 'citymag-style' ),
			'1.0.0'
		);

		wp_enqueue_script( 'citymag-navigation', get_template_directory_uri() . '/assets/js/navigation.js' , array('jquery'), '1.0', TRUE );

		wp_localize_script( 'citymag-navigation', 'accessibleNavigationScreenReaderText', array(
			'expandMain'   => __( 'Open the main menu', 'citymag' ),
			'collapseMain' => __( 'Close the main menu', 'citymag' ),
			'expandChild'   => __( 'expand submenu', 'citymag' ),
			'collapseChild' => __( 'collapse submenu', 'citymag' ),
		));

		wp_enqueue_script(
			'jquery.ticker',
			get_template_directory_uri() . '/assets/js/jquery.ticker.js',
			array('jquery'),
			'1.2.1',
			TRUE
		);

		wp_enqueue_script('jquery-easing', get_template_directory_uri() . '/assets/js/jquery.easing.js' , array('jquery'), '1.3', TRUE );
		wp_enqueue_script('jquery-nicescroll', get_template_directory_uri() . '/assets/js/jquery.nicescroll.js' , array('jquery'), '3.7.6', TRUE );
		wp_enqueue_script('jquery-swipebox', get_template_directory_uri() . '/assets/js/jquery.swipebox.js' , array('jquery'), '1.4.4', TRUE );
		wp_enqueue_script('jquery-touchSwipe', get_template_directory_uri() . '/assets/js/jquery.touchSwipe.js' , array('jquery'), '1.6.18', TRUE );
		wp_enqueue_script('fitvids', get_template_directory_uri() . '/assets/js/jquery.fitvids.js' , array('jquery'), '1.1', TRUE );
		wp_enqueue_script('slick', get_template_directory_uri() . '/assets/js/slick.js' , array('jquery'), '1.8.0', TRUE );
		wp_enqueue_script('citymag-template',get_template_directory_uri() . '/assets/js/citymag-template.js',array('jquery', 'imagesloaded', 'masonry'), '1.0.0', TRUE );

		if ( is_singular() ) wp_enqueue_script( 'comment-reply' );

		wp_enqueue_script('html5shiv', get_template_directory_uri().'/assets/scripts/html5shiv.js', FALSE, '3.7.3');
		wp_script_add_data('html5shiv', 'conditional', 'IE 8' );
		wp_enqueue_script('selectivizr', get_template_directory_uri().'/assets/scripts/selectivizr.js', FALSE, '1.0.3b');
		wp_script_add_data('selectivizr', 'conditional', 'IE 8' );

	}

	add_action( 'wp_enqueue_scripts', 'citymag_scripts_styles' );

}

/*-----------------------------------------------------------------------------------*/
/* Theme setup */
/*-----------------------------------------------------------------------------------*/

if (!function_exists('citymag_setup')) {

	function citymag_setup() {

		global $content_width;

		if ( !isset($content_width) )
			$content_width = 1170;

		load_theme_textdomain( 'citymag', get_template_directory() . '/languages');

		add_theme_support( "responsive-embeds" );
		add_theme_support( 'wp-block-styles');
		add_theme_support( 'align-wide' );

		add_theme_support( 'post-formats', array( 'aside','gallery','quote','video','audio','link','status','chat','image' ) );
		add_theme_support( 'automatic-feed-links' );
		add_theme_support( 'post-thumbnails' );
		add_theme_support( 'woocommerce' );
		add_theme_support( 'title-tag' );
		add_theme_support( 'custom-logo');

		register_default_headers( array(
			'default-image' => array(
				'url'           => get_stylesheet_directory_uri() . '/assets/images/header/header.jpg',
				'thumbnail_url' => get_stylesheet_directory_uri() . '/assets/images/header/resized-header.jpg',
				'description'   => esc_html__( 'Default image', 'citymag' ),
			),
		));

		add_theme_support( 'custom-header', array(
			'width'         => 1920,
			'height'        => 692,
			'default-image' => get_stylesheet_directory_uri() . '/assets/images/header/header.jpg',
			'header-text' 	=> false,
		));

		add_theme_support( 'custom-background', array(
			'default-color' => 'ffffff',
		));

		add_image_size( 'citymag_post_blocks_large', 700, 611, true );
		add_image_size( 'citymag_post_blocks_medium', 600, 396, true );
		add_image_size( 'citymag_post_blocks_small', 120, 100, true );
		add_image_size( 'citymag_featured_post_large', 549, 410, true );
		add_image_size( 'citymag_featured_post_small', 95 , 95, true );
		add_image_size( 'citymag_trending_image', 140, 140, TRUE );
		add_image_size( 'citymag_blog_thumbnail', 790, 550, TRUE );

		register_nav_menu( 'main-menu', esc_attr__( 'Main Menu', 'citymag' ) );
		register_nav_menu( 'secondary-menu', esc_attr__( 'Secondary Menu', 'citymag' ) );

		require_once( trailingslashit( get_template_directory() ) . '/core/post-formats/aside-format.php' );
		require_once( trailingslashit( get_template_directory() ) . '/core/post-formats/default-format.php' );
		require_once( trailingslashit( get_template_directory() ) . '/core/post-formats/image-format.php' );
		require_once( trailingslashit( get_template_directory() ) . '/core/post-formats/link-format.php' );
		require_once( trailingslashit( get_template_directory() ) . '/core/post-formats/page-format.php' );
		require_once( trailingslashit( get_template_directory() ) . '/core/post-formats/product-format.php' );
		require_once( trailingslashit( get_template_directory() ) . '/core/post-formats/quote-format.php' );

		require_once( trailingslashit( get_template_directory() ) . '/core/post/related-post.php' );

		require_once( trailingslashit( get_template_directory() ) . '/core/post/featured-posts/horizontal-featured-posts.php' );
		require_once( trailingslashit( get_template_directory() ) . '/core/post/featured-posts/vertical-featured-posts.php' );
		require_once( trailingslashit( get_template_directory() ) . '/core/post/featured-posts/vertical-list-featured-posts.php' );

		require_once( trailingslashit( get_template_directory() ) . '/core/post-blocks/main-article.php' );
		require_once( trailingslashit( get_template_directory() ) . '/core/post-blocks/small-article.php' );

		require_once( trailingslashit( get_template_directory() ) . '/core/post-blocks/modules/module-1.php' );
		require_once( trailingslashit( get_template_directory() ) . '/core/post-blocks/modules/module-2.php' );

		require_once( trailingslashit( get_template_directory() ) . '/core/templates/after-content.php' );
		require_once( trailingslashit( get_template_directory() ) . '/core/templates/before-content.php' );
		require_once( trailingslashit( get_template_directory() ) . '/core/templates/masonry.php' );
		require_once( trailingslashit( get_template_directory() ) . '/core/templates/media.php' );
		require_once( trailingslashit( get_template_directory() ) . '/core/templates/news-ticker.php' );
		require_once( trailingslashit( get_template_directory() ) . '/core/templates/pagination.php' );
		require_once( trailingslashit( get_template_directory() ) . '/core/templates/post-author.php' );
		require_once( trailingslashit( get_template_directory() ) . '/core/templates/post-blocks.php' );
		require_once( trailingslashit( get_template_directory() ) . '/core/templates/post-formats.php' );
		require_once( trailingslashit( get_template_directory() ) . '/core/templates/related-posts.php' );
		require_once( trailingslashit( get_template_directory() ) . '/core/templates/social_links.php' );
		require_once( trailingslashit( get_template_directory() ) . '/core/templates/title.php' );
		require_once( trailingslashit( get_template_directory() ) . '/core/templates/top-section.php' );

		require_once( trailingslashit( get_template_directory() ) . '/core/sidebars/bottom-sidebar.php' );
		require_once( trailingslashit( get_template_directory() ) . '/core/sidebars/footer-sidebar.php' );
		require_once( trailingslashit( get_template_directory() ) . '/core/sidebars/header-sidebar.php' );
		require_once( trailingslashit( get_template_directory() ) . '/core/sidebars/scroll-sidebar.php' );
		require_once( trailingslashit( get_template_directory() ) . '/core/sidebars/side-sidebar.php' );

		require_once( trailingslashit( get_template_directory() ) . '/core/includes/class-customize.php' );
		require_once( trailingslashit( get_template_directory() ) . '/core/includes/class-metaboxes.php' );
		require_once( trailingslashit( get_template_directory() ) . '/core/includes/class-notice.php' );
		require_once( trailingslashit( get_template_directory() ) . '/core/includes/class-plugin-activation.php' );
		require_once( trailingslashit( get_template_directory() ) . '/core/includes/class-welcome-page.php' );

		require_once( trailingslashit( get_template_directory() ) . '/core/admin/customize/google-fonts.php' );
		require_once( trailingslashit( get_template_directory() ) . '/core/admin/customize/customize.php' );

		require_once( trailingslashit( get_template_directory() ) . '/core/functions/function-required-plugins.php' );
		require_once( trailingslashit( get_template_directory() ) . '/core/functions/function-style.php' );
		require_once( trailingslashit( get_template_directory() ) . '/core/functions/function-widgets.php' );
		require_once( trailingslashit( get_template_directory() ) . '/core/functions/function-woocommerce.php' );

		require_once( trailingslashit( get_template_directory() ) . '/core/widgets/news_widget.php' );

		require_once( trailingslashit( get_template_directory() ) . '/core/metaboxes/page.php' );
		require_once( trailingslashit( get_template_directory() ) . '/core/metaboxes/post.php' );
		require_once( trailingslashit( get_template_directory() ) . '/core/metaboxes/product.php' );


	}

	add_action( 'after_setup_theme', 'citymag_setup' );

}

/*-----------------------------------------------------------------------------------*/
/* Load custom widgets */
/*-----------------------------------------------------------------------------------*/

if (!function_exists('citymag_widgets_init')) {

	function citymag_widgets_init() {

		register_widget( 'citymag_news_widget' );

	}

	add_action('widgets_init', 'citymag_widgets_init');

}

/*-----------------------------------------------------------------------------------*/
/* Get categories */
/*-----------------------------------------------------------------------------------*/ 

if (!function_exists('citymag_get_categories')) {

	function citymag_get_categories() {

		$args = array(
			'taxonomy' => 'category',
			'hide_empty' => true,
		);

		$return['all'] = esc_html__( 'All categories', 'citymag' );

		foreach ( get_terms($args) as $cat) {
			$return[$cat->term_id] = $cat->name;
		}
		
		return $return;

	}

}

/*-----------------------------------------------------------------------------------*/
/* Get current date */
/*-----------------------------------------------------------------------------------*/

if (!function_exists('citymag_get_current_date')) {

	function citymag_get_current_date() {

			$date_format = esc_attr(citymag_setting('citymag_topbar_date_format', 'l, F j Y'));

			if(strtotime(wp_date($date_format))) {
				$current_date = wp_date($date_format);
			} else {
				$current_date = wp_date('l, F j Y');
			}

			return $current_date;

	}

}

/*-----------------------------------------------------------------------------------*/
/* Get topbar right column */
/*-----------------------------------------------------------------------------------*/

if (!function_exists('citymag_get_topbar_right_column')) {

	function citymag_get_topbar_right_column() {

			$html = '';

			$right_column = citymag_setting('citymag_topbar_rightcolumn', 'topbar_text');

			switch ($right_column) {

				case 'social_icons':

					$html = citymag_get_social_icons();
				
				break;
				
				case 'secondary_menu':

					$html = '<div id="secondary-menu-wrapper">';

						$html .= '<button class="menu-toggle" aria-controls="top-menu" aria-expanded="false" type="button">';
							$html .= '<span aria-hidden="true">'.esc_html__( 'Menu', 'citymag' ).'</span>';
							$html .= '<span class="dashicons" aria-hidden="true"></span>';
						$html .= '</button>';

					$html .= '<nav id="secondary-menu" class="header-menu" >';
						$html .= wp_nav_menu(array('theme_location' => 'secondary-menu', 'container' => false, 'echo' => false));
					$html .= '</nav>';
					
					$html .= '</div>';

				break;
				
				default :
				case 'topbar_text':

					$html = '<div id="topbar-text">';

						$html .= esc_html(citymag_setting('citymag_topbar_text', __( 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.','citymag')));
					
					$html .= '</div>';

				break;
			
			}

			$htmlLength = strlen($html);

			return ($htmlLength > 0) ? '<div class="topbar-right-column">' . $html . '</div>' : '';

	}

}

/*-----------------------------------------------------------------------------------*/
/* Get thumbnail post categories */
/*-----------------------------------------------------------------------------------*/

if (!function_exists('citymag_get_thumbnail_post_categories')) {

	function citymag_get_thumbnail_post_categories() {

		$categories = get_the_category();

		$category = '<div class="post-meta">';
		$category .=  '<span class="post-meta-category">'; 
		
		if ( ! empty( $categories ) ) {

			foreach ( $categories as $v) {

				$category .=  '<a href="' . esc_url( get_category_link( $v->term_id ) ) . '">' . esc_html( $v->name ) . '</a>';
			
			}

		}
		
		$category .=  '</span>';
		$category .=  '</div>';

		return $category;


	}

}

?>