1039 lines
35 KiB
PHP
1039 lines
35 KiB
PHP
<?php
|
|
|
|
// use LDCCRM\WPCrm;
|
|
/* CRM */
|
|
|
|
use LDC\LDCCRM\CrmApiV2;
|
|
use LDC\LDCCRM\Enums\ApiError;
|
|
use LDC\LDCCRM\Exceptions\ApiErrorException;
|
|
use LDC\LDCCRM\Exceptions\CrmException;
|
|
use LDC\LDCCRM\Exceptions\ValidationException;
|
|
use LDC\LDCCRM\WordPress\WPCrm;
|
|
|
|
/**
|
|
* Initialise CrmApiV2
|
|
*
|
|
* @return void
|
|
*/
|
|
function initApiCrm()
|
|
{
|
|
return new CrmApiV2(CRM_ENDPOINT, CRM_TOKEN, CRM_PASSWORD);
|
|
}
|
|
|
|
|
|
// TODO : vérifier si pas d'incidence sur les dates du site
|
|
// ! Changed remove block 'REMOVE GUTENBERG STYLES' as breaks tinymce styles on front. (24/03/23)
|
|
//date_default_timezone_set('Europe/Paris');
|
|
|
|
/*******************************************************************
|
|
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->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;
|
|
// ! Plus utilisé avec sendin blue.
|
|
// $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 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 setAjaxUrlVar()
|
|
{
|
|
echo '<script type="text/javascript">
|
|
var ajaxurl = "' . esc_url(admin_url('admin-ajax.php')) . '";
|
|
</script>';
|
|
}
|
|
|
|
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());
|
|
$_style_media = '/css/media.css';
|
|
wp_enqueue_style('media-styles', get_template_directory_uri() . $_style_media, [], filemtime(get_template_directory() . $_style_media));
|
|
|
|
// * COOKIES
|
|
$_style_cookies = '/css/cookies-ldc.min.css';
|
|
wp_enqueue_style('cookie', get_template_directory_uri() . $_style_cookies, [], filemtime(get_template_directory() . $_style_cookies));
|
|
$_js_cookies = '/js/ldcweb-cn.min.js';
|
|
wp_enqueue_script('cookie', get_template_directory_uri() . $_js_cookies, [], null, filemtime(get_template_directory() . $_js_cookies));
|
|
$_style_inline_cookies = '/css/cn-inline-buttons.css';
|
|
wp_enqueue_style('inline-cookie', get_template_directory_uri() . $_style_inline_cookies, [], filemtime(get_template_directory() . $_style_inline_cookies));
|
|
$_js_inline_cookies = '/js/cn-inline-buttons.js';
|
|
wp_enqueue_script('inline-cookie', get_template_directory_uri() . $_js_inline_cookies, ['cookie'], filemtime(get_template_directory() . $_js_inline_cookies), true);
|
|
|
|
/* 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 );
|
|
// ! Only if user is logged in push normal jquery
|
|
if (is_user_logged_in()) {
|
|
wp_enqueue_script('jquery-js', get_template_directory_uri() . '/js/jquery-1.11.1.min.js', array(), null, false);
|
|
}
|
|
wp_register_script('jqueryUseWPML', '', [], '', false);
|
|
wp_enqueue_script('jqueryUseWPML');
|
|
wp_add_inline_script('jqueryUseWPML', '$ = jQuery');
|
|
// * Set missing ajaxurl var
|
|
add_action('wp_head', 'setAjaxUrlVar');
|
|
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
|
|
);
|
|
|
|
// pass Ajax Url to script.js
|
|
wp_localize_script('ajax-script', 'ajaxurl', array('ajaxurl' => admin_url('admin-ajax.php')));
|
|
wp_localize_script(
|
|
'ajax-script',
|
|
'security',
|
|
array('ajax-security-nonce' => wp_create_nonce('ajax-security-nonce'))
|
|
);
|
|
wp_localize_script(
|
|
'ajax-script',
|
|
'lang',
|
|
array('lang' => ICL_LANGUAGE_CODE)
|
|
);
|
|
|
|
|
|
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 "<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');
|
|
|
|
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 = [];
|
|
|
|
$concernedSlugs = [
|
|
'presentation', 'presentation-en',
|
|
'documents', 'documents-en',
|
|
'meetings',
|
|
];
|
|
|
|
$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 (in_array($cat->slug, $concernedSlugs)) {
|
|
$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 (in_array($cat->slug, $concernedSlugs)) {
|
|
$years[$arr] = $arr;
|
|
} else {
|
|
$years[$arr] = ($arr - 1) . '/' . $arr;
|
|
}
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
///////////////////// 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;
|
|
}
|
|
|
|
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'];
|
|
|
|
if (empty($token)) {
|
|
echo (json_encode('Une erreur est survenue. Veuillez recharger la page.'));
|
|
die();
|
|
}
|
|
|
|
$secret = getenv('RECAPTCHA_V3_SECRET');
|
|
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 '<a class="langs__item" href="' . esc_url($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();
|
|
|
|
// 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 . '</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>';
|
|
} else if ($item["title"] == "Présentation des engagements" || $item["title"] == "Les 4 engagements LDC" || $item["title"] == "Points clés" || $item["title"] == 'Nos pôles') {
|
|
echo '<div class="menu-mobile-message">' . $item["title"] . '</div>';
|
|
} else
|
|
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 {
|
|
echo '<!-- no menu defined in location "' . $theme_location . '" -->';
|
|
}
|
|
}
|
|
|
|
|
|
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;
|
|
}
|
|
|
|
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');
|
|
}
|
|
|
|
function str_lreplace($search, $replace, $subject)
|
|
{
|
|
$pos = strrpos($subject, $search);
|
|
|
|
if ($pos !== false) {
|
|
$subject = substr_replace($subject, $replace, $pos, strlen($search));
|
|
}
|
|
|
|
return $subject;
|
|
}
|
|
|
|
/** Newsletter actionnaires - page finance **/
|
|
add_action('wp_ajax_newsletterCta', 'newsletterCta');
|
|
add_action('wp_ajax_nopriv_newsletterCta', 'newsletterCta');
|
|
function newsletterCta()
|
|
{
|
|
check_ajax_referer('ajax-security-nonce', 'security');
|
|
|
|
if (!isset($_POST['email'])) {
|
|
echo wp_json_encode(['status' => "KO", "msg" => "Veuillez remplir tous les champs."]);
|
|
exit;
|
|
}
|
|
|
|
if (!isset($_POST['lang'])) {
|
|
$lang = 'fr';
|
|
} else {
|
|
if (!in_array($_POST['lang'], ['fr', 'en'])) {
|
|
$lang = $lang = 'fr';
|
|
} else {
|
|
$lang = filter_var($_POST['lang'], FILTER_SANITIZE_STRING);
|
|
}
|
|
}
|
|
|
|
$zEmail = filter_var($_POST['email'], FILTER_SANITIZE_EMAIL);
|
|
|
|
initApiCrm();
|
|
try {
|
|
if (WPCrm::setSingleOptin($zEmail, true)) {
|
|
$status = "OK";
|
|
$code = 200;
|
|
$message = $lang === 'fr' ? "Inscription validée !" : "Registration confirmed!";
|
|
} else {
|
|
$message = $lang === 'fr' ? "Une erreur est survenue, veuillez recharger la page." : "An error has occurred, please reload the page.";
|
|
}
|
|
} catch (ValidationException | CrmException | ApiErrorException $e) {
|
|
$code = $e->getStatusCode();
|
|
$message = (get_class($e) === CrmException::class ? $e->getMessage() : get_class($e) === ValidationException::class ? $e->getMessage() : $e->getApiError()->label);
|
|
writeLog("ERROR CRM API : $code - $message | email : $zEmail");
|
|
if ($e->getApiError()->equals(ApiError::singleOptinCustomerExists())) {
|
|
$message = $lang === 'fr' ? "Vous avez déjà un compte enregistré avec cet email." : "You already have an account registered with this email address.";
|
|
}
|
|
}
|
|
echo wp_json_encode(['status' => $status, 'code' => $code, 'message' => $message]);
|
|
die();
|
|
}
|
|
|
|
/**
|
|
* Write to error log
|
|
*
|
|
* @param mixed $log
|
|
* @return void
|
|
*/
|
|
function writeLog($log)
|
|
{
|
|
if (true === WP_DEBUG) {
|
|
if (is_array($log) || is_object($log)) {
|
|
// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log, WordPress.PHP.DevelopmentFunctions.error_log_print_r, Squiz.PHP.DiscouragedFunctions.Found
|
|
error_log(print_r($log, true));
|
|
} else {
|
|
// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log, WordPress.PHP.DevelopmentFunctions.error_log_print_r, Squiz.PHP.DiscouragedFunctions.Found
|
|
error_log($log);
|
|
}
|
|
}
|
|
}
|