2020-04-17 16:50:36 +02:00
< ? php
2020-07-17 17:29:32 +02:00
// TODO : vérifier si pas d'incidence sur les dates du site
//date_default_timezone_set('Europe/Paris');
2020-06-25 10:40:14 +02:00
/*******************************************************************
SMTP Mail / HTML Mail
*******************************************************************/
add_filter ( " wp_mail_content_type " , " set_html_content_type " );
function set_html_content_type () {
return " text/html " ;
}
add_action ( 'phpmailer_init' , 'configure_smtp' );
function configure_smtp ( PHPMailer $phpmailer ){
$phpmailer -> isSMTP (); //switch to smtp
$phpmailer -> Host = SMTP_HOST ;
$phpmailer -> SMTPAuth = SMTP_AUTH ;
$phpmailer -> Port = SMTP_PORT ;
$phpmailer -> Username = SMTP_USER ;
$phpmailer -> Password = SMTP_PASS ;
$phpmailer -> SMTPSecure = SMTP_SECURE ;
$phpmailer -> SMTPOptions = array (
'ssl' => array (
'verify_peer' => false ,
'verify_peer_name' => false ,
'allow_self_signed' => true
)
);
}
2020-04-17 16:50:36 +02:00
/* REMOVE EMOJI START */
remove_action ( 'wp_head' , 'print_emoji_detection_script' , 7 );
remove_action ( 'admin_print_scripts' , 'print_emoji_detection_script' );
remove_action ( 'wp_print_styles' , 'print_emoji_styles' );
remove_action ( 'admin_print_styles' , 'print_emoji_styles' );
/* REMOVE EMOJI END */
remove_filter ( 'the_content' , 'wpautop' );
add_filter ( 'excerpt_length' , function (){
return 50 ;
});
/* REMOVE GUTENBERG STYLES START */
function smartwp_remove_wp_block_library_css (){
wp_dequeue_style ( 'wp-block-library' );
wp_dequeue_style ( 'wp-block-library-theme' );
}
add_action ( 'wp_enqueue_scripts' , 'smartwp_remove_wp_block_library_css' );
/* REMOVE GUTENBERG STYLES END */
/* REMOVE ATTRS START */
add_action ( 'wp_loaded' , 'prefix_output_buffer_start' );
function prefix_output_buffer_start () {
ob_start ( " prefix_output_callback " );
}
function prefix_output_callback ( $buffer ) {
return preg_replace ( " %[ ]type=[ \ ' \" ]text \ /(javascript|css)[ \ ' \" ]% " , '' , $buffer );
}
/* REMOVE ATTRS END */
/* CF7 remove tags START */
add_filter ( 'wpcf7_autop_or_not' , '__return_false' );
/* CF7 remove tags end */
function load_js_css () {
wp_enqueue_style ( 'fonts' , get_template_directory_uri () . '/fonts/stylesheet.css' );
wp_enqueue_style ( 'swiper' , get_template_directory_uri () . '/css/swiper.min.css' );
wp_enqueue_style ( 'fancybox' , get_template_directory_uri () . '/css/jquery.fancybox.min.css' );
wp_enqueue_style ( 'styles' , get_stylesheet_uri ());
wp_enqueue_style ( 'media-styles' , get_template_directory_uri () . '/css/media.css' );
/* wp_deregister_script ( 'jquery' );
wp_register_script ( 'jquery' , get_template_directory_uri () . '/js/jquery-1.11.1.min.js' );
wp_enqueue_script ( 'jquery' ); */
//wp_enqueue_script( 'twentytwenty-js', get_template_directory_uri() . '/js/index.js', array(), $theme_version, false );
wp_enqueue_script ( 'jquery-js' , get_template_directory_uri () . '/js/jquery-1.11.1.min.js' , array (), null , false );
wp_localize_script ( 'jquery-js' , 'ajaxurl' , admin_url ( 'admin-ajax.php' ) );
2020-11-18 15:37:37 +01:00
/*wp_enqueue_script('masonry',get_template_directory_uri() . '/js/masonry.pkgd.min.js', array('jquery'), null, false);*/
2020-04-17 16:50:36 +02:00
wp_enqueue_script ( 'chart-js' , get_template_directory_uri () . '/js/Chart.js' , array (), null , false );
wp_enqueue_script ( 'swiper' , get_template_directory_uri () . '/js/swiper.min.js' , array ( 'jquery' ), null , true );
wp_enqueue_script ( 'fancybox' , get_template_directory_uri () . '/js/jquery.fancybox.min.js' , array ( 'jquery' ), null , true );
//wp_enqueue_script('tagcanvas',get_template_directory_uri() . '/js/jquery.tagcanvas.min.js',array('jquery'),null,true);
wp_enqueue_script ( 'tagcanvas' , get_template_directory_uri () . '/js/tagcanvas.min.js' , array ( 'jquery' ), null , true );
2020-11-18 15:37:37 +01:00
wp_enqueue_script ( 'ajax-script' , get_template_directory_uri () . '/js/script.js' , array ( 'jquery' ), null , false );
2020-04-17 16:50:36 +02:00
wp_enqueue_script ( 'cont-script' , get_template_directory_uri () . '/js/cont-page.js' , array ( 'jquery' ) );
wp_localize_script ( 'ajax-script' , 'cc_ajax_object' ,
array ( 'ajaxurl' => admin_url ( 'admin-ajax.php' ) ) );
// wp_localize_script('jquery', 'ajaxurl', admin_url( 'admin-ajax.php' ) );
// wp_enqueue_script('script', get_template_directory_uri() . '/js/script.js', array('jquery'), null, true);
$translation_array = array ( 'templateUrl' => get_stylesheet_directory_uri () );
wp_localize_script ( 'script' , 'theme_path' , $translation_array );
}
add_action ( 'wp_enqueue_scripts' , 'load_js_css' );
function global_vars () {
global $current_time ;
$current_time = current_time ( 'timestamp' );
}
add_action ( 'init' , 'global_vars' );
/* POST THUMBNAILS START */
if ( function_exists ( 'add_theme_support' )) {
add_theme_support ( 'post-thumbnails' );
set_post_thumbnail_size ( 412 , 240 );
}
/* POST THUMBNAILS END */
add_action ( 'after_setup_theme' , function (){
register_nav_menus ( array (
'top' => 'Top menu' ,
));
register_nav_menus ( array (
'header_left' => 'Header menu left' ,
));
register_nav_menus ( array (
'header_right' => 'Header menu right' ,
));
register_nav_menus ( array (
'footer' => 'Footer menu' ,
));
register_nav_menus ( array (
'mobile' => 'Mobile menu' ,
));
/* register_nav_menus ( array (
'copyright' => 'Copyright' ,
)); */
});
/* ACF theme options START */
if ( function_exists ( 'acf_add_options_page' ) ) {
acf_add_options_page (
array (
2020-06-25 10:40:14 +02:00
'page_title' => 'Paramètres site' ,
'menu_title' => 'Paramètres site' ,
2020-04-17 16:50:36 +02:00
'menu_slug' => 'theme-options' ,
'capability' => 'edit_posts' ,
'parent_slug' => '' ,
'position' => false ,
)
);
acf_add_options_sub_page (
array (
2020-06-25 10:40:14 +02:00
'page_title' => 'Paramètres site' ,
'menu_title' => 'Paramètres site' ,
2020-04-17 16:50:36 +02:00
'menu_slug' => 'theme-options-global' ,
'capability' => 'edit_posts' ,
'parent_slug' => 'theme-options' ,
'position' => false ,
'icon_url' => false ,
'redirect' => false ,
)
);
}
/* ACF theme options END */
/* FILTER START */
function get_tags_in_use ( $category_name , $type = 'name' ){
$my_posts = new WP_Query (
" category_name= " . $category_name ,
'posts_per_page = -1'
);
$tags_by_id = array ();
$tags_by_name = array ();
$tags_by_slug = array ();
if ( $my_posts -> have_posts ()) : while ( $my_posts -> have_posts ()) : $my_posts -> the_post ();
$post_tags = wp_get_post_tags ( $my_posts -> post -> ID );
foreach ( $post_tags as $tag ) :
$tag_id = $tag -> term_id ;
$tag_name = $tag -> name ;
$tag_slug = $tag -> slug ;
if ( ! in_array ( $tag_id , $tags_by_id ))
array_push ( $tags_by_id , $tag_id );
if ( ! in_array ( $tag_name , $tags_by_name ))
array_push ( $tags_by_name , $tag_name );
if ( ! in_array ( $tag_slug , $tags_by_slug ))
array_push ( $tags_by_slug , $tag_slug );
endforeach ;
endwhile ; endif ;
if ( $type == 'id' )
return $tags_by_id ;
if ( $type == 'name' )
return $tags_by_name ;
if ( $type == 'slug' )
return $tags_by_slug ;
}
function tags_filter ( $category_name = 'none' ) {
$tags = get_tags_in_use ( $category_name );
if ( empty ( $tags )) {
return false ;
}
echo " <ul> " ;
foreach ( $tags as $tag ) :
$term = get_term_by ( 'name' , $tag , 'post_tag' );
echo '<li>' ;
echo ' < a class = " tax-filter "
data - tag = " ' . $term->slug . ' "
data - category = " ' . $category_name . ' "
> ' . $term->name . ' </ a > ' ;
echo ' </li>' ;
endforeach ;
echo " </ul> " ;
}
function ajax_filter_posts_scripts () {
// Enqueue script
wp_register_script ( 'afp_script' , get_template_directory_uri () . '/js/ajax-filter-posts.js' , false , null , false );
wp_enqueue_script ( 'afp_script' );
2020-05-04 15:59:02 +02:00
if ( isset ( $_GET [ 'tag' ])) {
$tag = $_GET [ 'tag' ];
} else {
$tag = '' ;
}
2020-04-17 16:50:36 +02:00
wp_localize_script ( 'afp_script' , 'afp_vars' , array (
'afp_nonce' => wp_create_nonce ( 'afp_nonce' ), // Create nonce which we later will use to verify AJAX request
'afp_ajax_url' => admin_url ( 'admin-ajax.php' ),
2020-05-04 15:59:02 +02:00
'afp_tags' => $tag ,
2020-04-17 16:50:36 +02:00
)
);
}
add_action ( 'wp_enqueue_scripts' , 'ajax_filter_posts_scripts' , 100 );
// Script for getting posts
function ajax_filter_get_posts () {
$p = '' ;
2020-06-25 15:48:29 +02:00
$l = 9 ;
if ( isset ( $_GET [ 'limit' ])) {
$l = $_GET [ 'limit' ];
}
if ( isset ( $_GET [ 'taxonomy' ])) {
$p .= ' tag="' . implode ( ',' , $_GET [ 'taxonomy' ]) . '"' ;
}
if ( isset ( $_GET [ 'order' ])) {
$p .= ' order="' . $_GET [ 'order' ] . '"' ;
}
if ( isset ( $_GET [ 'category' ])) {
$p .= ' category="' . $_GET [ 'category' ] . '"' ;
} else {
$p .= ' category="news"' ;
}
if ( isset ( $_GET [ 'years' ])) {
2020-12-03 11:12:20 +01:00
if ( isset ( $_GET [ 'category' ]) && ( $_GET [ 'category' ] === 'presentation' || $_GET [ 'category' ] === 'documents' || $_GET [ 'category' ] === 'meetings' )){
$p .= ' meta_key="exercice" meta_value="' . implode ( ',' , $_GET [ 'years' ]) . '" meta_compare="IN" meta_relation="AND"' ;
} else {
$p .= ' custom_args="date_query:' . implode ( ',' , $_GET [ 'years' ]) . '"' ;
}
2020-06-25 15:48:29 +02:00
}
if ( isset ( $_GET [ 'list' ])) {
$p .= ' theme_repeater="' . $_GET [ 'list' ] . '"' ;
}
if ( isset ( $_GET [ 'id' ])) {
$p .= ' id="' . $_GET [ 'id' ] . '"' ;
}
2020-12-14 10:14:37 +01:00
echo do_shortcode ( '[ajax_load_more loading_style="infinite fading-circles" post_type="post" posts_per_page="' . $l . '" max_pages="1" scroll="true" nested="true" button_label="' . __ ( 'See more news' , 'LDC Custom string' ) . '" ' . $p . ']' );
2020-04-17 16:50:36 +02:00
die ();
}
add_action ( 'wp_ajax_filter_posts' , 'ajax_filter_get_posts' );
add_action ( 'wp_ajax_nopriv_filter_posts' , 'ajax_filter_get_posts' );
/* FILTER END */
function get_posts_years_array ( $cat ) {
$years = [];
2020-12-03 11:12:20 +01:00
2020-04-17 16:50:36 +02:00
$cat_id = $cat -> term_id ;
$args = array ( 'cat' => $cat_id , 'posts_per_page' => - 1 );
$query = new WP_Query ( $args ); // Start the wordpress loop!
if ( $query -> have_posts () ) :
while ( $query -> have_posts () ) : $query -> the_post ();
2020-12-03 11:12:20 +01:00
if ( $cat -> slug === 'presentation' || $cat -> slug === 'documents' || $cat -> slug === 'meetings' ) {
$exercice = get_field ( 'exercice' );
if ( $exercice !== NULL )
$arrays [] = $exercice [ 'value' ];
} else {
$arrays [] = intval ( get_the_time ( __ ( 'Y' , 'archives-category-date' ) ));
}
2020-04-17 16:50:36 +02:00
endwhile ;
endif ;
2020-12-03 11:12:20 +01:00
if ( ! isset ( $arrays ))
return $years ;
2020-04-17 16:50:36 +02:00
$uniq_arrs = array_unique ( $arrays );
foreach ( $uniq_arrs as $arr ) {
2020-12-03 11:12:20 +01:00
if ( $cat -> slug === 'presentation' || $cat -> slug === 'documents' || $cat -> slug === 'meetings' ) {
$years [ $arr ] = $arr ;
} else {
$years [ $arr ] = ( $arr - 1 ) . '/' . $arr ;
}
2020-04-17 16:50:36 +02:00
}
2020-12-03 11:12:20 +01:00
2020-04-17 16:50:36 +02:00
return $years ;
}
function filter_years_html ( $years , $category ) {
echo " <ul> " ;
foreach ( $years as $y => $string ) :
echo '<li>' ;
echo ' < a class = " tax-filter "
data - year = " ' . $y . ' "
data - category = " ' . $category . ' "
> ' . $string . ' </ a > ' ;
echo ' </li>' ;
endforeach ;
echo " </ul> " ;
}
/* Fix 404 error for custom post type pages */
flush_rewrite_rules ( false );
/* Thumbs START */
/* add_image_size ( 'social-icon' , 32 , 32 , true );
add_image_size ( 'info-icon' , 75 , 75 , true );
add_image_size ( 'expertise-icon' , 40 , 40 , true ); */
/* Thumbs END */
/*
function custom_post_type_create () {
register_post_type ( 'infopage' ,
array (
'labels' => array (
'name' => __ ( 'Infopages' ),
'singular_name' => __ ( 'Infopage' )
),
'public' => true ,
'publicly_queryable' => true ,
'show_ui' => true ,
'query_var' => true ,
'show_in_nav_menus' => true ,
'capability_type' => 'post' ,
'hierarchical' => false ,
'rewrite' => array ( 'slug' => 'infopages' , 'with_front' => false ),
'supports' => array ( 'title' , 'editor' , 'thumbnail' ),
'has_archive' => true
)
);
register_taxonomy ( 'infopage-cat' , array ( 'infopage' ), array (
'label' => 'Infopage Categories' , // определяется параметром $labels->name
'labels' => array (
'name' => 'Infopage Categories' ,
'singular_name' => 'Infopage Categories' ,
),
'public' => true ,
'hierarchical' => true ,
'show_in_nav_menus' => true ,
'has_archive' => true ,
'rewrite' => false ,
) );
}
add_action ( 'init' , 'custom_post_type_create' ); */
function catName ( $cat_id ) {
$cat_id = ( int ) $cat_id ;
$category = get_category ( $cat_id );
return $category -> name ;
}
function catLink ( $cat_id ) {
$category = get_the_category ();
$category_link = get_category_link ( $cat_id );
return $category_link ;
}
2020-05-07 10:17:55 +02:00
///////////////////// RECUPERATION ET AFFICHAGE DE LA BOURSE //////////////////////
2020-05-06 16:58:19 +02:00
2020-12-10 08:02:13 +01:00
// CRON à mettre dans crons/FinancialIntraday.php avec */15 9-18 * * * (toutes les 15 min entre 9h et 18h, on ne peut pas faire 17h30 mais gérer dans le code.)
2020-04-17 16:50:36 +02:00
2020-12-16 10:55:13 +01:00
// CRON à mettre dans crons/FinancialStock.php avec */15 9-18 * * * (toutes les 15 min entre 9h et 18h, on ne peut pas faire 17h30 mais gérer dans le code.)
2020-12-10 08:02:13 +01:00
// CRON à mettre dans crons/FinancialHistory.php avec 0 4 * * * (tous les jours à 4H)
2020-04-17 16:50:36 +02:00
//AJAX pour récupérer les données de l'action en fonction de la période pour les afficher dans un chartJS
add_action ( 'wp_ajax_getGraphData' , 'getGraphData' );
add_action ( 'wp_ajax_nopriv_getGraphData' , 'getGraphData' );
2020-06-23 12:23:23 +02:00
function getFinancialHistoryDatasByPeriod ( $period = false )
{
global $wpdb ;
2020-12-16 10:55:13 +01:00
if ( $period )
return $wpdb -> get_results ( " SELECT * FROM wp_financialdata_history WHERE date >= CURDATE() - INTERVAL $period DAY ORDER BY date DESC " );
return $wpdb -> get_results ( " SELECT * FROM wp_financialdata_history ORDER BY date DESC " );
2020-06-23 12:23:23 +02:00
}
2020-04-17 16:50:36 +02:00
function getGraphData (){
$period = $_POST [ 'period' ];
global $wpdb ;
2020-06-23 12:23:23 +02:00
$date_arr = [];
$values = [];
switch ( $period ){
case '5' :
case '30' :
case '182' :
case '365' :
case '1825' :
$periodDatas = getFinancialHistoryDatasByPeriod ( $period );
break ;
case 'YTD' :
$p = date ( 'z' );
$periodDatas = getFinancialHistoryDatasByPeriod ( $p );
break ;
case 'all' :
$periodDatas = getFinancialHistoryDatasByPeriod ();
break ;
case 'intraday' :
$periodDatas = $wpdb -> get_results ( " SELECT * FROM wp_financialdata_intraday " );
break ;
}
2020-04-17 16:50:36 +02:00
2020-06-23 12:23:23 +02:00
foreach ( $periodDatas as $item ) {
if ( $period == 'intraday' ){
array_push ( $date_arr , date ( 'H:i' , strtotime ( $item -> date )));
} else {
array_push ( $date_arr , date ( 'd/m/Y' , strtotime ( $item -> date )));
}
array_push ( $values , $item -> close );
}
2020-04-17 16:50:36 +02:00
2020-06-23 12:23:23 +02:00
$date_arr = array_reverse ( $date_arr );
$values = array_reverse ( $values );
2020-04-17 16:50:36 +02:00
2020-06-23 12:23:23 +02:00
echo json_encode ( array ( " dates " => $date_arr , " values " => $values ));
2020-04-17 16:50:36 +02:00
die ();
}
2020-12-08 09:02:20 +01:00
///////////////////// ALERTES POUR LES OFFRES D'EMPLOI //////////////////////
2020-04-17 16:50:36 +02:00
2020-12-08 09:02:20 +01:00
// CRON à mettre dans crons/DigitalRecruiter.php avec 0 8 * * MON (tous les lundis à 8H)
2020-04-17 16:50:36 +02:00
// Ajax pour enregistrer les utilisateurs a l'alerte job avec leur paramètres
add_action ( 'wp_ajax_registerMailJobAlert' , 'registerMailJobAlert' );
add_action ( 'wp_ajax_nopriv_registerMailJobAlert' , 'registerMailJobAlert' );
function registerMailJobAlert (){
global $wpdb ;
2020-07-31 11:15:18 +02:00
$metiers = sanitize_text_field ( $_POST [ 'metiers' ]);
$types = sanitize_text_field ( $_POST [ 'types' ]);
$temps = sanitize_text_field ( $_POST [ 'temps' ]);
$email = sanitize_email ( $_POST [ 'email' ]);
$token = $_POST [ 'token' ];
$secret = " 6LePZvAUAAAAAHW0Upj3jRH9wTzGrMO1aWpg9ICn " ;
if ( isset ( $_SERVER [ " HTTP_X_FORWARDED_FOR " ]) && $_SERVER [ " HTTP_X_FORWARDED_FOR " ] != " " ){
if ( strpos ( $_SERVER [ 'HTTP_X_FORWARDED_FOR' ], ',' )) {
$explode = explode ( ',' , $_SERVER [ 'HTTP_X_FORWARDED_FOR' ]);
$remoteip = trim ( $explode [ 0 ]);
} else {
$remoteip = $_SERVER [ 'HTTP_X_FORWARDED_FOR' ];
}
} else {
$remoteip = $_SERVER [ " REMOTE_ADDR " ];
}
2020-04-17 16:50:36 +02:00
2020-07-31 11:15:18 +02:00
$api_url = " https://www.google.com/recaptcha/api/siteverify?secret= " . $secret . " &response= " . $token . " &remoteip= " . $remoteip ;
$decode = json_decode ( file_get_contents ( $api_url ), true );
if ( $decode [ 'success' ] == true ){
2020-04-17 16:50:36 +02:00
2020-12-08 09:02:20 +01:00
$wpdb -> delete ( 'wp_digitalrecruiter_jobalert' , array ( 'email' => $email ) );
2020-04-17 16:50:36 +02:00
2020-12-08 09:02:20 +01:00
$wpdb -> insert (
'wp_digitalrecruiter_jobalert' ,
2020-07-31 11:15:18 +02:00
array (
'email' => $email ,
2020-12-08 09:02:20 +01:00
'contract_id' => $types !== " all " ? $types : NULL ,
'workingtime_id' => $temps !== " all " ? $temps : NULL ,
'job_id' => $metiers !== " all " ? $metiers : NULL ,
2020-07-31 11:15:18 +02:00
),
array (
'%s' ,
2020-12-08 09:02:20 +01:00
'%d' ,
'%d' ,
'%d' ,
2020-07-31 11:15:18 +02:00
)
);
echo ( json_encode ( 'ok' ));
} else {
echo ( json_encode ( 'Une erreur est survenue. Veuillez recharger la page.' ));
}
die ();
2020-04-17 16:50:36 +02:00
}
//////////////////////////////// POC : GMAP Societe //////////////////////////////////////////////
//--- Intégration de la classe CSociete pour faciliter la manipulation des objets ?
require_once ( get_template_directory () . '/societe.class.php' );
// ---- CPT Societe
function wp_cpt_societes () {
$labels = array (
'name' => _x ( 'Société' , 'Post Type General Name' ),
'singular_name' => _x ( 'Société' , 'Post Type Singular Name' ),
'menu_name' => __ ( 'Sociétés' ),
'all_items' => __ ( 'Tous les Sociétés' ),
'view_item' => __ ( 'Voir les Sociétés' ),
'add_new_item' => __ ( 'Ajouter une Société' ),
'add_new' => __ ( 'Ajouter' ),
'edit_item' => __ ( 'Editer la Société' ),
'update_item' => __ ( 'Modifier la Société' ),
'search_items' => __ ( 'Rechercher une Société' ),
'not_found' => __ ( 'Non trouvée' ),
'not_found_in_trash' => __ ( 'Non trouvée dans la corbeille' ),
);
$args = array (
'label' => __ ( 'Société' ),
'labels' => $labels ,
'supports' => array ( 'title' , 'editor' , 'thumbnail' ),
'hierarchical' => true ,
'public' => true ,
'has_archive' => true ,
'taxonomies' => array ( 'type' ),
'rewrite' => array ( 'slug' => 'type' ),
'map_meta_cap' => true ,
'menu_icon' => 'dashicons-admin-site-alt2'
);
register_post_type ( 'societe' , $args );
}
add_action ( 'init' , 'wp_cpt_societes' , 0 );
// ---- Taxo : Type d'activité des societes
function taxo_type_societe () {
$args = array (
'label' => __ ( 'Type d\'Activité' ),
'hierarchical' => true ,
'rewrite' => array ( 'slug' => 'type-activite' , 'with_front' => false ),
'show_ui' => true ,
'show_in_quick_edit' => false ,
'show_in_rest' => false ,
'show_admin_column' => true ,
);
register_taxonomy ( 'type-activite' , 'societe' , $args );
}
add_action ( 'init' , 'taxo_type_societe' );
// ---- Taxo : Filières des societes
function taxo_filieres_societe () {
$args = array (
'label' => __ ( 'Filières' ),
'hierarchical' => true ,
'rewrite' => array ( 'slug' => 'filieres' , 'with_front' => false ),
'show_ui' => true ,
'show_in_quick_edit' => false ,
'show_admin_column' => true ,
);
register_taxonomy ( 'filieres' , 'societe' , $args );
}
add_action ( 'init' , 'taxo_filieres_societe' );
// Fonction utilitaires pour réintégrer les sociétés en fonction d'un json et d'un dossier de logos
function importSociete (){
include_once ( ABSPATH . 'wp-admin/includes/image.php' );
$dir = wp_upload_dir ();
$file = $dir [ 'basedir' ] . " /import/export_societe.json " ;
$data = file_get_contents ( $file );
foreach ( json_decode ( $data ) as $oSociete ) {
//Insertion du post
$postarr = array (
'post_title' => $oSociete -> titre ,
'post_status' => 'publish' ,
'post_type' => 'societe' ,
);
$societeId = wp_insert_post ( $postarr );
$term = get_term_by ( 'name' , $oSociete -> filiere , 'filieres' );
$termId = $term -> term_id ;
update_field ( 'field_5e5f6c2f2c95a' , $termId , $societeId );
$termType = get_term_by ( 'slug' , $oSociete -> type_activite , 'type-activite' );
$termTypeId = $termType -> term_id ;
update_field ( 'field_5e5f6c002c959' , $termTypeId , $societeId );
//Ajout du logo
$fullpath_img = $dir [ 'basedir' ] . " /import/ " . $oSociete -> logo ;
$full_path = $dir [ 'path' ] . " / " . $oSociete -> logo ;
copy ( $fullpath_img , $full_path );
// Check the type of file. We'll use this as the 'post_mime_type'.
$filetype = wp_check_filetype ( basename ( $full_path ), null );
// Prepare an array of post data for the attachment.
$attachment = array (
'guid' => $dir [ 'url' ] . '/' . basename ( $full_path ),
'post_mime_type' => $filetype [ 'type' ],
'post_title' => preg_replace ( '/\.[^.]+$/' , '' , basename ( $full_path ) ),
'post_content' => '' ,
'post_status' => 'inherit'
);
// Insert the attachment.
$attach_id = wp_insert_attachment ( $attachment , $full_path , $societeId );
$attach_data = wp_generate_attachment_metadata ( $attach_id , $full_path );
wp_update_attachment_metadata ( $attach_id , $attach_data );
// Saving image
update_field ( 'field_5e5f6e8adcab0' , $attach_id , $societeId );
//Ajout des champs de base avec ACF
update_field ( 'field_5e5f6ea3dcab1' , $oSociete -> adresse , $societeId );
update_field ( 'field_5e5f6eb7dcab2' , $oSociete -> responsable , $societeId );
update_field ( 'field_5e5f6ec6dcab3' , $oSociete -> departement , $societeId );
update_field ( 'field_5e5f6ed7dcab4' , $oSociete -> activite , $societeId );
update_field ( 'field_5e5f6ee2dcab5' , $oSociete -> effectif , $societeId );
update_field ( 'field_5e5f6ef7dcab6' , $oSociete -> contact , $societeId );
update_field ( 'field_5e5f6f09dcab7' , $oSociete -> url , $societeId );
update_field ( 'field_5e5f6f1bdcab8' , $oSociete -> infos_sup , $societeId );
update_field ( 'field_5e5f6f4fdcaba' , $oSociete -> responsable_pole , $societeId );
update_field ( 'field_5e5f6fb4dcabb' , $oSociete -> latitude , $societeId );
update_field ( 'field_5e5f6fbcdcabc' , $oSociete -> longitude , $societeId );
}
}
add_theme_support ( 'title-tag' );
add_filter ( 'document_title_parts' , function ( $title )
{
if ( is_search () )
$title [ 'title' ] = sprintf (
esc_html__ ( '“%s” result213123 page' , 'ldc' ),
get_search_query ()
);
return $title ;
} );
add_filter ( 'relevanssi_index_custom_fields' , 'rlv_skip_custom_fields' );
function rlv_skip_custom_fields ( $custom_fields ) {
$unwanted_fields = array ( 'text_block' );
$custom_fields = array_diff ( $custom_fields , $unwanted_fields );
return $custom_fields ;
}
add_action ( 'alm_get_theme_repeater' , 'alm_get_theme_repeater' );
function alm_get_theme_repeater ( $theme_repeater ){
get_template_part ( 'partials/' . $theme_repeater );
}
add_filter ( 'alm_modify_query_args' , 'alm_modify_query_args_parida' );
function alm_modify_query_args_parida ( $args ) {
if ( isset ( $args [ " date_query " ])){
if ( ! is_array ( $args [ " date_query " ]))
$args [ " date_query " ] = array ( $args [ " date_query " ]);
$s = array ();
foreach ( $args [ " date_query " ] as $year )
$s [][ 'year' ] = $year ;
$args [ " date_query " ] = array ( 'relation' => 'OR' , $s );
}
return $args ;
}
function language_selector_flags (){
$languages = icl_get_languages ( 'skip_missing=0&orderby=code' );
$lc = 1 ;
if ( ! empty ( $languages )){
foreach ( $languages as $l ){
if ( ! $l [ 'active' ]) {
echo '<a class="langs__item" href="' . $l [ 'url' ] . '">' ;
} else {
echo '<a class="langs__item active">' ;
}
echo strtoupper ( $l [ 'code' ]);
echo '</a>' ;
if ( $lc < count ( $languages )) {
echo '<span href="langs__item"> / </span>' ;
}
$lc ++ ;
}
}
}
/*
class CustomWalker extends Walker_Nav_Menu {
var $current_menu = null ;
var $break_point = null ;
function start_el ( & $output , $item , $depth , $args ) {
global $wp_query ;
// Get the locations of nav menus
$theme_locations = get_nav_menu_locations ();
2020-05-04 15:59:02 +02:00
2020-04-17 16:50:36 +02:00
// Get the menu object of the current nav menu based on the returned theme location
$menu_obj = get_term ( $theme_locations [ $args -> theme_location ], 'nav_menu' );
if ( ! isset ( $this -> current_menu ) ) {
$this -> current_menu = wp_get_nav_menu_object ( $menu_obj -> term_id );
}
if ( ! isset ( $this -> break_point ) ) {
2020-05-04 15:59:02 +02:00
$this -> break_point = ceil ( $this -> current_menu -> count / 2 ) + 1 ;
}
2020-04-17 16:50:36 +02:00
$indent = ( $depth ) ? str_repeat ( " \t " , $depth ) : '' ;
$class_names = $value = '' ;
$classes = empty ( $item -> classes ) ? array () : ( array ) $item -> classes ;
$classes [] = 'menu-item-' . $item -> ID ;
$class_names = join ( ' ' , apply_filters ( 'nav_menu_css_class' , array_filter ( $classes ), $item , $args ) );
$class_names = ' class="' . esc_attr ( $class_names ) . '"' ;
$id = apply_filters ( 'nav_menu_item_id' , 'menu-item-' . $item -> ID , $item , $args );
$id = strlen ( $id ) ? ' id="' . esc_attr ( $id ) . '"' : '' ;
if ( $this -> break_point == $item -> menu_order ) {
$output .= $indent . '</li></ul><ul class="nav top-nav cf right"><li' . $id . $value . $class_names . '>' ;
} else {
$output .= $indent . '<li' . $id . $value . $class_names . '>' ;
}
$attributes = ! empty ( $item -> attr_title ) ? ' title="' . esc_attr ( $item -> attr_title ) . '"' : '' ;
$attributes .= ! empty ( $item -> target ) ? ' target="' . esc_attr ( $item -> target ) . '"' : '' ;
$attributes .= ! empty ( $item -> xfn ) ? ' rel="' . esc_attr ( $item -> xfn ) . '"' : '' ;
$attributes .= ! empty ( $item -> url ) ? ' href="' . esc_attr ( $item -> url ) . '"' : '' ;
$item_output = $args -> before ;
$item_output .= '<a' . $attributes . '>' ;
$item_output .= $args -> link_before . apply_filters ( 'the_title' , $item -> title , $item -> ID ) . $args -> link_after ;
$item_output .= '</a>' ;
$item_output .= $args -> after ;
$output .= apply_filters ( 'walker_nav_menu_start_el' , $item_output , $item , $depth , $args );
}
} */
function custom_menu_output ( $theme_location ) {
if ( ( $theme_location ) && ( $locations = get_nav_menu_locations ()) && isset ( $locations [ $theme_location ]) ) {
$menu = get_term ( $locations [ $theme_location ], 'nav_menu' );
$menu_items = wp_get_nav_menu_items ( $menu -> term_id );
$menus = array ();
foreach ( $menu_items as $menu_item ) {
$pid = $menu_item -> menu_item_parent ? $menu_item -> menu_item_parent : 0 ;
$menus [ $pid ][ $menu_item -> ID ] = array (
'link' => $menu_item -> url ,
'title' => $menu_item -> title ,
'id' => $menu_item -> ID ,
);
}
$pomoika = '' ;
$i = 0 ;
foreach ( $menus as $key => $menu ) {
if ( $key == 0 )
echo '<div class="mobile-menu__block mobile-menu__block_main"><ul data-menu="main" class="mobile-menu__level">' ;
else
//var_dump($menus[0][$key]);
echo '<div class="mobile-menu__block mobile-menu__block_sub" data-menu="submenu-' . $key . '"><div class="mobile-menu__block-title"><div class="mobile-menu__block-close"></div><a href="' . $menus [ 0 ][ $key ][ 'link' ] . '">' . $menus [ 0 ][ $key ][ 'title' ] . '</a></div><ul class="mobile-menu__level">' ;
if ( $key == " 2951 " )
{
get_template_part ( 'partials/menu-rejoin-mobile' , ICL_LANGUAGE_CODE );
echo '</ul></div>' ;
} else {
foreach ( $menu as $item ) {
if ( isset ( $menus [ $item [ 'id' ]])) {
echo '<li class="mobile-menu__item"><a class="mobile-menu__link" href="' . $item [ " link " ] . '">' . $item [ 'title' ] . '</a><a class="menu-arrow-box mobile-menu__link_hassub" data-submenu="submenu-' . $item [ 'id' ] . '" href="#"><div class="menu-submenu-arrow"></div></a></li>' ;
}
2020-10-23 14:14:24 +02:00
else if ( $item [ " title " ] == " Présentation des engagements " || $item [ " title " ] == " Les 4 engagements LDC " || $item [ " title " ] == " Points clés " || $item [ " title " ] == 'Nos pôles' ) {
2020-04-17 16:50:36 +02:00
echo '<div class="menu-mobile-message">' . $item [ " title " ] . '</div>' ;
2020-05-04 15:59:02 +02:00
} else
2020-04-17 16:50:36 +02:00
echo '<li class="mobile-menu__item"><a class="mobile-menu__link" href="' . $item [ 'link' ] . '">' . $item [ 'title' ] . '</a></li>' ;
}
echo '</ul>' . $pomoika ;
}
if ( $i == 0 )
{
get_template_part ( 'partials/footer-mobile' );
echo '</div>' ;
$pomoika = '</div>' ;
$i ++ ;
}
}
} else {
2020-06-25 15:48:29 +02:00
echo '<!-- no menu defined in location "' . $theme_location . '" -->' ;
2020-04-17 16:50:36 +02:00
}
}
add_filter ( 'post_limits' , 'rlv_postsperpage' );
function rlv_postsperpage ( $limits ) {
if ( is_search () ) {
global $wp_query ;
$wp_query -> query_vars [ 'posts_per_page' ] = 10 ;
}
return $limits ;
2020-05-04 15:59:02 +02:00
}
2020-10-29 09:08:42 +01:00
function remove_menus (){
remove_menu_page ( 'edit-comments.php' ); //Comments
remove_menu_page ( 'themes.php' ); //Appearance
remove_menu_page ( 'plugins.php' ); //Plugins
remove_menu_page ( 'users.php' ); //Users
remove_menu_page ( 'tools.php' ); //Tools
remove_menu_page ( 'options-general.php' ); //Settings
}
if ( ENV !== ENV_LOCAL ){
add_action ( 'admin_menu' , 'remove_menus' );
}