<?php 
defined('ABSPATH') or die('I Don\'t allow You');
define('tdomain',"portfolio_madness",true);
define('ICL_DONT_LOAD_LANGUAGE_SELECTOR_CSS', true);
define('ICL_DONT_LOAD_LANGUAGES_JS', true);
define('ICL_DONT_LOAD_NAVIGATION_CSS', true);
require_once(dirname(__FILE__).'/inc/Classes/madness_main.php');
function portfolio_madness_setup() {
	/*
	 * Make theme available for translation.
	 * Translations can be filed at WordPress.org. See: https://translate.wordpress.org/projects/wp-themes/portfolio_madness
	 * If you're building a theme based on Twenty Seventeen, use a find and replace
	 * to change 'portfolio_madness' to the name of your theme in all the template files.
	 */
	load_theme_textdomain( 'portfolio_madness' );

	// Add default posts and comments RSS feed links to head.
	add_theme_support( 'automatic-feed-links' );

	/*
	 * Let WordPress manage the document title.
	 * By adding theme support, we declare that this theme does not use a
	 * hard-coded <title> tag in the document head, and expect WordPress to
	 * provide it for us.
	 */
	add_theme_support( 'title-tag' );

	/*
	 * Enable support for Post Thumbnails on posts and pages.
	 *
	 * @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/
	 */
	add_theme_support( 'post-thumbnails' );

	add_image_size( 'portfolio_madness-featured-image', 2000, 1200, true );

	add_image_size( 'portfolio_madness-thumbnail-avatar', 100, 100, true );

	// Set the default content width.
	$GLOBALS['content_width'] = 525;

	// This theme uses wp_nav_menu() in two locations.
	register_nav_menus( array(
		'top'    => __( 'Top Menu', 'portfolio_madness' ),
		'social' => __( 'Social Links Menu', 'portfolio_madness' ),
	) );

	/*
	 * Switch default core markup for search form, comment form, and comments
	 * to output valid HTML5.
	 */
	add_theme_support( 'html5', array(
		'comment-form',
		'comment-list',
		'gallery',
		'caption',
	) );

	/*
	 * Enable support for Post Formats.
	 *
	 * See: https://codex.wordpress.org/Post_Formats
	 */
	add_theme_support( 'post-formats', array(
		'aside',
		'image',
		'video',
		'quote',
		'link',
		'gallery',
		'audio',
	) );

	// Add theme support for Custom Logo.
	add_theme_support( 'custom-logo', array(
		'width'       => 250,
		'height'      => 250,
		'flex-width'  => true,
	) );

	// Add theme support for selective refresh for widgets.
	add_theme_support( 'customize-selective-refresh-widgets' );

	/*
	 * This theme styles the visual editor to resemble the theme style,
	 * specifically font, colors, and column width.
 	 */
	//add_editor_style( array( 'assets/css/editor-style.css', portfolio_madness_fonts_url() ) );
}
add_action( 'after_setup_theme', 'portfolio_madness_setup' );

//add_action( 'wp_enqueue_scripts', 'portfolio_madness_enqueue_styles' );
function portfolio_madness_enqueue_styles() {
    $t=wp_get_theme();
    $v=$t->get('Version');
    $tdu=get_template_directory_uri();
    wp_enqueue_style( 'portfolio_madness_main_style', $tdu . '/style.css',array(),$v);
    wp_enqueue_style( 'portfolio_madness_main_style_h', $tdu . '/assets/css/main_styles/habilidades.css',array(),$v);
    wp_enqueue_style( 'portfolio_madness_main_style_m', $tdu . '/assets/css/main_styles/menu.css',array(),$v);
    wp_enqueue_style( 'portfolio_madness_main_style_i', $tdu . '/assets/css/main_styles/inputs.css',array(),$v);
    
    /*
    @import url("./assets/css/main_styles/menu.css?v1.2.7.1");
	@import url("./assets/css/main_styles/habilidades.css?v1.2.7.2");
	@import url("./assets/css/main_styles/inputs.css?v1.2.7.1");
     */
	wp_enqueue_style( 'portfolio_madness_fonts', $tdu . '/assets/css/ac3_fonts.css',array( 'portfolio_madness_main_style' ),$v);
	wp_enqueue_style( 'portfolio_madness_bootstrap', $tdu . '/assets/css/bootstrap.min.css',array( 'portfolio_madness_main_style','portfolio_madness_fonts' ),$v);
	wp_enqueue_style( 'portfolio_madness_slick', $tdu . '/assets/css/slick.css',array( 'portfolio_madness_main_style','portfolio_madness_fonts','portfolio_madness_bootstrap' ),$v);
}
add_action( 'wp_enqueue_scripts', 'portfolio_madness_enqueue_styles2' );
function portfolio_madness_enqueue_styles2() {
    $t=wp_get_theme();
    $v=$t->get('Version');
    $tdu=get_template_directory_uri();
    wp_enqueue_style( 'portfolio_madness_preloader', $tdu . '/assets/css/main_styles/preload.css',array(),$v);
}
function styles_as_script_load($echo=false){
	$t=wp_get_theme();
    $v=$t->get('Version');
	$v='?ver='.$v;
    $tdu=get_template_directory_uri();
	$scripts=array();
	$scripts['0-Main Styles 1']=$tdu . '/style.css' . $v;
	$scripts['1-Main Styles 2']=$tdu . '/assets/css/main_styles/habilidades.css' . $v;
	$scripts['2-Main Styles 3']=$tdu . '/assets/css/main_styles/menu.css' . $v;
	$scripts['3-Main Styles 4']=$tdu . '/assets/css/main_styles/inputs.css' . $v;
	$scripts['ac3']=$tdu . '/assets/css/main_styles/ac3_fonts.php' . $v;
	$scripts['5-Bootstrap']=$tdu . '/assets/css/bootstrap.min.css' . $v;
	$scripts['6-Slick Slider']=$tdu . '/assets/css/slick.css' . $v;
	ob_start();
	?>
	<script>
		<?php foreach($scripts as $id=>$script){
		?> 
		<?php if($id!='ac3'){ ?>
		madness.add_style('<?=$id;?>','<?=$script;?>','<?=str_replace(' ','_',strtolower('style_'.$id));?>');<?php
			}else{ ?>
		madness.add_font('<?=$id;?>','<?=$script;?>','<?=str_replace(' ','_',strtolower('style_'.$id));?>');<?php } ?>
		<?php }?>
	</script>
	<?php
	$ret=ob_get_clean();
	if($echo!==false){
		echo $ret;
	}
	return $ret;
}
function scripts_as_ajax_load($echo=false){
	$t=wp_get_theme();
    $v=$t->get('Version');
	$v='?ver='.$v;
    $tdu=get_template_directory_uri();
	$assets=get_template_directory_uri().'/assets/js/';
	$scripts=array();
	$scripts['Bootstrap']=$assets.'bootstrap.min.js' . $v;
	$scripts['Slick Slider']=$assets.'slick.min.js' . $v;
	ob_start();
	?>
	<script>
		<?php foreach($scripts as $id=>$script){?>
		madness.add_script('<?=$id;?>','<?=$script;?>','<?=str_replace(' ','_',strtolower('script_'.$id));?>');
		<?php }?>
	</script>
	<?php
	$ret=ob_get_clean();
	if($echo!==false){
		echo $ret;
	}
	return $ret;
}
add_action( 'wp_enqueue_scripts', 'portfolio_madness_enqueue_scripts' );
function portfolio_madness_enqueue_scripts() {
	$v=wp_get_theme()->get('Version');
	$slug='portfolio_madness_';
	$assets=get_template_directory_uri().'/assets/js/';
	wp_deregister_script('jquery');
	wp_enqueue_script('jquery', $assets.'jquery.min.js', array(), $v, false );
	wp_enqueue_script( $slug.'total_madness', $assets.'madness_core.js', array('jquery'), $v, false );
}
//add_action( 'wp_enqueue_scripts', 'portfolio_madness_enqueue_scripts2' );
function portfolio_madness_enqueue_scripts2() {
	$v=wp_get_theme()->get('Version');
	$slug='portfolio_madness_';
	$assets=get_template_directory_uri().'/assets/js/';
	wp_enqueue_script( $slug.'bootstrap', $assets.'bootstrap.min.js', array('jquery'), $v, false );
	wp_enqueue_script( $slug.'slick', $assets.'slick.min.js', array('jquery',$slug.'bootstrap'), $v, false );
}
add_action( 'admin_enqueue_scripts', 'portfolio_madness_enqueue_admin_scripts' );
function portfolio_madness_enqueue_admin_scripts() {
	wp_enqueue_style( 'portfolio_madness_admin_fonts', get_template_directory_uri() . '/assets/css/ac3_fonts.css',array(),wp_get_theme()->get('Version'));
	add_editor_style( get_template_directory_uri() . '/assets/css/ac3_fonts.css');
}

function background(){
	$background=get_page_by_title( 'IMG'.date('d'), 'object', 'backgrounds' );
	$img=wp_get_attachment_url( get_post_thumbnail_id($background->ID),'full');
	return $img;
}

add_action('wp_head','social_meta_tags');
function social_meta_tags(){
	ob_start();
	$link=get_permalink();
	$img=(wp_get_attachment_image_src(get_post_thumbnail_id())!==false)?wp_get_attachment_image_src(get_post_thumbnail_id(),'full'):wp_get_attachment_image_src(get_post_thumbnail_id(get_bloginfo('page_on_front')),'full');
	if($img!==false){
		$img=$img[0];
	}
	$name=get_the_title();
	$description=(strlen(str_replace(' ','',get_the_excerpt())>0))?get_the_excerpt():get_bloginfo('description');
	$site_title=get_bloginfo('name');
	$autor='adomasalcore3';
	$fb_id='100000733435480';
	?>
	<!-- Twitter Card data -->
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:site" content="@<?=$autor?>">
<meta name="twitter:title" content="<?=$name.' - '.$site_title;?>">
<meta name="twitter:description" content="<?=$description;?>">
<meta name="twitter:creator" content="@<?=$autor;?>">
<!-- Twitter summary card with large image must be at least 280x150px -->
<meta name="twitter:image:src" content="<?=$img;?>">

<!-- Open Graph data -->
<meta property="og:title" content="<?=$name;?>" />
<meta property="og:type" content="article" />
<meta property="og:url" content="<?=$link;?>" />
<meta property="og:image" content="<?=$img;?>" />
<meta property="og:description" content="<?=$description;?>" />
<meta property="og:site_name" content="<?=$site_title;?>" />
<meta property="article:published_time" content="<?php get_the_date('Y-m-d');echo 'T'; get_the_date('H:i:s-01:00')?>" />
<meta property="article:modified_time" content="<?php the_modified_date('Y-m-d');echo 'T'; the_modified_date('H:i:s-01:00')?>" />
<meta property="article:section" content="Article Section" />
<meta property="article:tag" content="Article Tag" />
<meta property="fb:admins" content="<?=$fb_id;?>" />
<!-- Schema.org markup for Google+ -->
<meta itemprop="name" content="<?=$name.' - '.$site_title;?>">
<meta itemprop="description" content="<?=$description;?>">
<meta itemprop="image" content="<?=$img;?>">
	<?php
	echo ob_get_clean();
}

function get_job_description(){
	ob_start();
	$p_terms = wp_get_post_terms(get_the_ID(), 'jobdone', array( 'parent' => 0, 'hide_empty' => 0 ));
	if(!empty($p_terms)){ 
		foreach($p_terms as $p_term){
			?><h4><?=$p_term->name?></h4><?php
			$cterms=wp_get_post_terms(get_the_ID(), 'jobdone', array( 'parent' => $p_term->term_id, 'hide_empty' => 0 ));
			if(!empty($cterms)){
				?><p class="super_icons_inside"><?php
				foreach($cterms as $term){
					?><i class="<?=the_field('icon_class', $term)?>" title="<?=$term->name;?>"></i>; <?php 
				}
				?></p><?php
			}
		}
	}
	return ob_get_clean();
}
