<?php 
defined('ABSPATH') or die('I Don\'t allow You');

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() {
    wp_enqueue_style( 'portfolio_madness_main_style', get_template_directory_uri() . '/style.css',array(),wp_get_theme()->get('Version'));
	wp_enqueue_style( 'portfolio_madness_fonts', get_template_directory_uri() . '/assets/css/ac3_fonts.css',array( 'portfolio_madness_main_style' ),wp_get_theme()->get('Version'));
	wp_enqueue_style( 'portfolio_madness_bootstrap', get_template_directory_uri() . '/assets/css/bootstrap.min.css',array( 'portfolio_madness_main_style','portfolio_madness_fonts' ),wp_get_theme()->get('Version'));
	wp_enqueue_style( 'portfolio_madness_slick', get_template_directory_uri() . '/assets/css/slick.css',array( 'portfolio_madness_main_style','portfolio_madness_fonts','portfolio_madness_bootstrap' ),wp_get_theme()->get('Version'));
}

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.'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();
}
