<?php

// Prevent Direct Access
if( !defined('ABSPATH') ){
	exit;
}

// ---------- Theme Setup

function maxo_theme_setup(){

	// Title Tag Support
	add_theme_support('title-tag');

	// Post Thumbnail Support
	add_theme_support('post-thumbnails');

	// Image Sizes
	set_post_thumbnail_size(500, 340, true);
	add_image_size('blog', 800);
	add_image_size('blog_wide', 1200);
	add_image_size('portfolio-thumb', 500, 500, true);
	add_image_size('team', 350, 315, true);
}

add_action('after_setup_theme', 'maxo_theme_setup');

// ---------- Excerpt Settings

function maxo_excerpt_more($more) {
	return ' ...';
}

add_filter('excerpt_more', 'maxo_excerpt_more');

function maxo_excerpt_length() {
	return 41;
}

add_filter('excerpt_length', 'maxo_excerpt_length');

// ---------- Disable Contact Form 7 autop

add_filter('wpcf7_autop_or_not', '__return_false');

// ---------- Disable theme update

function maxo_disable_theme_update($value){

    if( isset($value) && is_object($value) ){
        unset($value->response[get_template()]);
    }

    return $value;
}

add_filter('site_transient_update_themes', 'maxo_disable_theme_update');

// ---------- Placeholder For IE9

function maxo_add_placeholder(){
?>
<!--[if lt IE 10]>
<script src="<?php echo get_theme_file_uri('assets/js/jquery.placeholder.min.js') ?>" type="text/javascript"></script>
<script type="text/javascript">$('input, textarea').placeholder();</script>
<![endif]-->
<?php
}

add_action('wp_footer', 'maxo_add_placeholder', 99);

// ---------- Map Variables

function maxo_map_variables(){
	if( is_front_page() && get_theme_mod('contact_map_display', true) && get_theme_mod('contact_map_iframe', '') == '' ){
?>
<script>
	var $maxo_map_latitude = <?php echo get_theme_mod('contact_map_latitude', '0') ?>;
	var $maxo_map_longitude = <?php echo get_theme_mod('contact_map_longitude', '0') ?>;
	var $maxo_map_zoom = <?php echo get_theme_mod('contact_map_zoom', '14') ?>;
	var $maxo_map_title = '<?php echo get_theme_mod('contact_map_marker_title', '') ?>';
	var $maxo_map_pin = '<?php echo get_theme_file_uri('assets/images/pin.png') ?>';
</script>
<?php
	}
}

add_action('wp_footer', 'maxo_map_variables', 1);

// ---------- Blog Detect Function

function is_blog(){
	return ( is_archive() || is_author() || is_category() || is_home() || is_single() || is_tag() ) && 'post' == get_post_type();
}

// ---------- Constants

// Site is_rtl detect (use this in admin pages to avoid conflict when admin and site locales are different. this always returns site front-end is_rtl status)
if( get_locale() == get_user_locale() ){
	define( 'MAXO_IS_RTL', is_rtl() );
}
else{
	$rtl_locales = ['arq', 'ar', 'bcc', 'dv', 'haz', 'ckb', 'ary', 'ps', 'fa_IR', 'fa_AF', 'snd', 'azb', 'ur'];
	define( 'MAXO_IS_RTL', in_array(get_locale(), $rtl_locales) );
}
