<?php

/**
 ** activation theme
 **/


function theme_enqueue_styles()
{

	wp_enqueue_style('parent-style', get_template_directory_uri() . '/style.css');
	wp_enqueue_style('app-css', get_stylesheet_directory_uri() . '/css/app.css');
	wp_enqueue_style('original-previous-css', get_stylesheet_directory_uri() . '/css/base-styles-previous-theme.css');
}

function theme_enqueue_librairies()
{
	wp_enqueue_script('jquery_min_script', get_stylesheet_directory_uri() . '/assets/jquery.js');
	wp_enqueue_style('bootstrap', get_stylesheet_directory_uri() . '/assets/bootstrap/bootstrap.min.css"');
	wp_enqueue_style('slick', get_stylesheet_directory_uri() . '/assets/slick/slick.css');
	wp_enqueue_style('slick-theme', get_stylesheet_directory_uri() . '/assets/slick/slick-theme.css');
	wp_enqueue_style('slick-modal', get_stylesheet_directory_uri() . '/assets/slick/slickmodal.css');
	wp_enqueue_style('slick-modal', get_stylesheet_directory_uri() . '/assets/snackbar/snackbar.css');
}

add_action('wp_enqueue_scripts', 'theme_enqueue_styles');
add_action('wp_enqueue_scripts', 'theme_enqueue_librairies');

function  theme_enqueue_styles_back()
{
	wp_enqueue_style('app-css', get_stylesheet_directory_uri() . '/css/app.css');
	wp_enqueue_style('original-previous-css', get_stylesheet_directory_uri() . '/css/base-styles-previous-theme.css');
}

add_action('enqueue_block_editor_assets', 'theme_enqueue_styles_back');

/* Image mise à la une*/

function my_login_logo_url()
{
	return 'https://deligraph.com';
}
add_filter('login_headerurl', 'my_login_logo_url');

function my_login_logo_url_title()
{
	return 'Agence web et studio graphique Deligraph à Bruxelles';
}
add_filter('login_headertitle', 'my_login_logo_url_title');


function my_login_logo()
{ ?>
	<style type="text/css">
		body.login div#login h1 a {
			background-image: url(<?php echo get_stylesheet_directory_uri(); ?>/images/logo-deligraph.png) !important;
			height: 103px !important;
			background-size: 100% !important;
			width: 274px !important;
		}
	</style>
<?php }
add_action('login_enqueue_scripts', 'my_login_logo');

/**********************************
 *
 * Fonction de pagination 
 *
 ***********************************/

function custom_pagination($numpages = '', $pagerange = '', $paged = '')
{

	if (empty($pagerange)) {
		$pagerange = 2;
	}

	/**
	 * This first part of our function is a fallback
	 * for custom pagination inside a regular loop that
	 * uses the global $paged and global $wp_query variables.
	 * 
	 * It's good because we can now override default pagination
	 * in our theme, and use this function in default quries
	 * and custom queries.
	 */
	global $paged;
	if (empty($paged)) {
		$paged = 1;
	}
	if ($numpages == '') {
		global $wp_query;
		$numpages = $wp_query->max_num_pages;
		if (!$numpages) {
			$numpages = 1;
		}
	}

	/** 
	 * We construct the pagination arguments to enter into our paginate_links
	 * function. 
	 */
	$pagination_args = array(
		'base'            => get_pagenum_link(1) . '%_%',
		'format'          => 'page/%#%',
		'total'           => $numpages,
		'current'         => $paged,
		'show_all'        => False,
		'end_size'        => 1,
		'mid_size'        => $pagerange,
		'prev_next'       => True,
		'prev_text'       => __('&laquo;'),
		'next_text'       => __('&raquo;'),
		'type'            => 'plain',
		'add_args'        => false,
		'add_fragment'    => ''
	);

	$paginate_links = paginate_links($pagination_args);

	if ($paginate_links) {
		echo "<nav class='custom-pagination'>";
		echo $paginate_links;
		echo "</nav>";
	}
}



/* ---- SHORTCODE ---- */

function shortcode_col($atts, $content)
{
	extract(shortcode_atts(
		array(
			'pousse' => 'FR'
		),
		$atts
	));

	if ($pousse == "1") {
		$nbr = "4";
	} elseif ($pousse == "2") {
		$nbr = "8";
	} elseif ($pousse == "0") {
		$nbr = "0";
	}
	return '<div class="offset-lg-' . $nbr . ' col-lg-4 colonne">' . $content . '</div>';
}
add_shortcode('col', 'shortcode_col');


/* ADD MENU */

function register_my_menu()
{
	register_nav_menu('MegaMenu', __('MegaMenu'));
}
add_action('init', 'register_my_menu');


/* ------------------------------
		ENABLE SVG
------------------------------*/


function cc_mime_types($mimes)
{
	$mimes['svg'] = 'image/svg+xml';
	return $mimes;
}
add_filter('upload_mimes', 'cc_mime_types');

?>