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 ) ); } /* 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' ) ); /*wp_enqueue_script('masonry',get_template_directory_uri() . '/js/masonry.pkgd.min.js', array('jquery'), null, false);*/ 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); wp_enqueue_script( 'ajax-script', get_template_directory_uri() . '/js/script.js', array('jquery'), null, false); 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( 'page_title' => 'Paramètres site', 'menu_title' => 'Paramètres site', 'menu_slug' => 'theme-options', 'capability' => 'edit_posts', 'parent_slug' => '', 'position' => false, ) ); acf_add_options_sub_page( array( 'page_title' => 'Paramètres site', 'menu_title' => 'Paramètres site', '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 ""; } 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'); if (isset($_GET['tag'])) { $tag = $_GET['tag']; }else{ $tag =''; } 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' ), 'afp_tags' => $tag, ) ); } add_action('wp_enqueue_scripts', 'ajax_filter_posts_scripts', 100); // Script for getting posts function ajax_filter_get_posts() { $p = ''; $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'])) { 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']) . '"'; } } if (isset($_GET['list'])) { $p .= ' theme_repeater="' . $_GET['list'] . '"'; } if (isset($_GET['id'])) { $p .= ' id="' . $_GET['id'] . '"'; } 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 . ']'); 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 = []; $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(); 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' ) )); } endwhile; endif; if (!isset($arrays)) return $years; $uniq_arrs = array_unique( $arrays ); foreach($uniq_arrs as $arr) { if ($cat->slug === 'presentation' || $cat->slug === 'documents' || $cat->slug === 'meetings') { $years[$arr] = $arr; }else{ $years[$arr] = ($arr - 1) . '/' . $arr; } } return $years; } function filter_years_html($years, $category) { echo ""; } /* 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; } ///////////////////// RECUPERATION ET AFFICHAGE DE LA BOURSE ////////////////////// // 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.) // 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.) // CRON à mettre dans crons/FinancialHistory.php avec 0 4 * * * (tous les jours à 4H) //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' ); function getFinancialHistoryDatasByPeriod($period = false) { global $wpdb; 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"); } function getGraphData(){ $period = $_POST['period']; global $wpdb; $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; } 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); } $date_arr = array_reverse($date_arr); $values = array_reverse($values); echo json_encode(array("dates" => $date_arr, "values" => $values)); die(); } ///////////////////// ALERTES POUR LES OFFRES D'EMPLOI ////////////////////// // CRON à mettre dans crons/DigitalRecruiter.php avec 0 8 * * MON (tous les lundis à 8H) // 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; $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"]; } $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){ $wpdb->delete( 'wp_digitalrecruiter_jobalert', array( 'email' => $email ) ); $wpdb->insert( 'wp_digitalrecruiter_jobalert', array( 'email' => $email, 'contract_id' => $types !== "all" ? $types : NULL, 'workingtime_id' => $temps !== "all" ? $temps : NULL, 'job_id' => $metiers !== "all" ? $metiers : NULL, ), array( '%s', '%d', '%d', '%d', ) ); echo(json_encode('ok')); }else{ echo(json_encode('Une erreur est survenue. Veuillez recharger la page.')); } die(); } //////////////////////////////// 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 ''; } else { echo ''; } echo strtoupper($l['code']); echo ''; if($lc < count($languages)) { echo ' / '; } $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(); // 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 ) ) { $this->break_point = ceil( $this->current_menu->count / 2 ) + 1; } $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 . '