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' => 'Theme settings',
'menu_title' => 'Theme settings',
'menu_slug' => 'theme-options',
'capability' => 'edit_posts',
'parent_slug' => '',
'position' => false,
)
);
acf_add_options_sub_page(
array(
'page_title' => 'Global',
'menu_title' => 'Global',
'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 "
";
foreach ($tags as $tag):
$term = get_term_by('name', $tag, 'post_tag');
echo '- ';
echo '' . $term->name . '';
echo '
';
endforeach;
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 = 3;
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']))
$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" post_status="future, publish" posts_per_page="'.$l.'" max_pages="1" scroll="true" nested="true" button_label="Voir plus d’actualités" ' . $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();
$catarrays[] = $cat_id;
$arrays[] = intval(get_the_time( __( 'Y', 'archives-category-date' ) ));
endwhile;
endif;
$uniq_arrs = array_unique( $arrays );
foreach($uniq_arrs as $arr) {
$years[$arr] = ($arr-1).'/'.$arr;
}
return $years;
}
function filter_years_html($years, $category) {
echo "";
foreach ($years as $y => $string):
echo '- ';
echo '' . $string . '';
echo '
';
endforeach;
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;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////// POC LDC 2020 //////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////// POC : REPONDRE AUX CONTACTS DIRECTEMENT DEPUIS L'ADMINISTRATION //////////////////////
// ---- CPT Message
function wp_cpt_messages() {
$labels = array(
'name' => _x( 'Message', 'Post Type General Name'),
'singular_name' => _x( 'Message', 'Post Type Singular Name'),
'menu_name' => __( 'Messages'),
'all_items' => __( 'Tous les Messages'),
'view_item' => __( 'Voir les Messages'),
'add_new_item' => __( 'Ajouter un Message'),
'add_new' => __( 'Ajouter'),
'edit_item' => __( 'Editer le Message'),
'update_item' => __( 'Modifier le Message'),
'search_items' => __( 'Rechercher un Message'),
'not_found' => __( 'Non trouvée'),
'not_found_in_trash' => __( 'Non trouvée dans la corbeille'),
);
$args = array(
'label' => __( 'Message'),
'labels' => $labels,
'supports' => array( 'title', 'editor', 'thumbnail'),
'hierarchical' => true,
'public' => true,
'has_archive' => true,
'taxonomies' => array('type'),
'rewrite' => array( 'slug' => 'type/%gamme%'),
'map_meta_cap' => true,
'menu_icon' => 'dashicons-email-alt'
);
register_post_type( 'message', $args );
}
add_action( 'init', 'wp_cpt_messages', 0 );
// ---- Taxo : Type de message
function taxo_type_message() {
$args = array(
'label' => __( 'Type' ),
'hierarchical' => true,
'rewrite' => array( 'slug' => 'type', 'with_front' => false ),
'show_ui' => true,
'show_in_quick_edit' => false,
'show_admin_column' => true,
);
register_taxonomy( 'type', 'message', $args );
}
add_action( 'init', 'taxo_type_message');
// Ajout de la possibilité d'ordonner la colonne par type
function add_message_sortable_columns( $cols ) {
$cols[ 'taxonomy-type' ] = 'taxonomy-type';
return $cols;
}
add_filter( 'manage_edit-message_sortable_columns', 'add_message_sortable_columns' );
//Ajout du selecteur permettant de filtrer par type
function filter_message_by_taxonomies( $post_type, $which ) {
// Apply this only on a specific post type
if ( 'message' !== $post_type )
return;
// A list of taxonomy slugs to filter by
$taxonomies = array( 'type');
foreach ( $taxonomies as $taxonomy_slug ) {
// Retrieve taxonomy data
$taxonomy_obj = get_taxonomy( $taxonomy_slug );
$taxonomy_name = $taxonomy_obj->labels->name;
// Retrieve taxonomy terms
$terms = get_terms( $taxonomy_slug );
// Display filter HTML
echo "';
}
}
add_action( 'restrict_manage_posts', 'filter_message_by_taxonomies' , 10, 2);
// Ajout colonne de réponse
function custom_message_columns_title($columns) {
$columns['repondre'] = 'Répondre';
unset($columns['date']);
return $columns;
}
add_filter('manage_edit-message_columns', 'custom_message_columns_title');
// Ajout contenu dans colonne de réponse
function custom_message_columns_content($column) {
global $post;
switch ($column) {
case 'repondre' :
echo('Répondre au message');
break;
}
}
add_action('manage_message_posts_custom_column', 'custom_message_columns_content');
// Ajout script spécifique sur l'admin message
function my_enqueue($hook) {
$screen = get_current_screen();
if ('edit-message' !== $screen->id) {
return;
}
wp_register_script( 'jQuery', 'https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js', null, null, true );
wp_enqueue_script('jQuery');
wp_enqueue_script( 'fancy', get_template_directory_uri() . '/assets/js/fancy.js',false,'1.1',true);
wp_enqueue_style( 'fancycss', get_template_directory_uri() . '/assets/js/fancy.css',false,'1.1','all');
wp_localize_script('fancy', 'ajaxurl', admin_url( 'admin-ajax.php' ) );
wp_enqueue_style( 'fancyboxcss', get_template_directory_uri() . '/assets/js/fancybox/jquery.fancybox.min.css',false,'1.1','all');
wp_enqueue_script( 'fancyboxjs', get_template_directory_uri() . '/assets/js/fancybox/jquery.fancybox.min.js',false,'1.1','all');
$html = "";
$html .= "
";
echo($html);
}
add_action('admin_enqueue_scripts', 'my_enqueue');
//Ajax pour ouvrir la page de réponse
add_action( 'wp_ajax_getReponseForMsg', 'getReponseForMsg' );
add_action( 'wp_ajax_nopriv_getReponseForMsg', 'getReponseForMsg' );
function getReponseForMsg(){
global $wpdb;
$postid = $_POST['id'];
$civilite = get_field('field_5e57a09acdacf', $postid);
$nom = get_field('field_5e57a087cdacd', $postid);
$prenom = get_field('field_5e57a095cdace', $postid);
$adresse = get_field('field_5e57a0a9cdad0', $postid);
$codepostal = get_field('field_5e57a0afcdad1', $postid);
$ville = get_field('field_5e57a0b8cdad2', $postid);
$email = get_field('field_5e57a0becdad3', $postid);
$telephone = get_field('field_5e57a0c3cdad4', $postid);
$message = get_field('field_5e57a0d9cdad5', $postid);
$html = "";
$html .= "
Message du consommateur :
";
$html .= "
Nom Prénom : ".$nom." ".$prenom."
";
$html .= "
E-mail : ".$email."
";
$html .= "
Adresse : ".$adresse."
";
$html .= "
Code Postal : ".$codepostal."
";
$html .= "
Ville : ".$ville."
";
$html .= "
Téléphone : ".$telephone."
";
$html .= "
Message envoyé :
";
$html .= "
".$message."
";
$html .= "
Votre Réponse :
";
$html .= "
";
$html .= "
";
$html .= "
";
$html .= "
";
echo($html);
die();
}
//Ajax d'envoi de la réponse
add_action( 'wp_ajax_sendReponse', 'sendReponse' );
add_action( 'wp_ajax_nopriv_sendReponse', 'sendReponse' );
function sendReponse(){
global $wpdb;
$email = $_POST['email'];
$message = $_POST['message'];
wp_mail($email, "Réponse à votre message sur le site LDC", $message, '');
$html = "Message Envoyé !
";
echo($html);
die();
}
///////////////////// RECUPERATION ET AFFICHAGE DE LA BOURSE //////////////////////
add_filter( 'cron_schedules', function ( $schedules ) {
$schedules['every-30-minutes'] = array(
'interval' => 30 * MINUTE_IN_SECONDS,
'display' => __( 'Every 30 minutes' )
);
return $schedules;
} );
if (!wp_next_scheduled( 'getFinancialData_hook')) {
wp_schedule_event(strtotime('4:30:00'), 'daily', 'getFinancialData_hook');
}
add_action( 'getFinancialData_hook', 'getFinancialData');
if (!wp_next_scheduled ( 'getIntradayData_hook')) {
wp_schedule_event(strtotime('9:00:00'), 'every-30-minutes', 'getIntradayData_hook');
}
add_action('getIntradayData_hook', 'getIntradayData');
//Fonction Pour récupérer les données de l'action (A utiliser dans un cron toutes les 30 minutes entre 09h 17h30)
function getIntradayData() {
global $wpdb;
$token = "0cM90jcNAWtMvgq922We3IRj6URAILQFxjnlySHoWCYCeTZMp7H7T7WTQzGE";
$baseUrl = 'https://intraday.worldtradingdata.com/api/v1/intraday?';
$queryParams = [
'symbol' => 'LOUP.PA',
'api_token' => $token,
'interval' => '1',
'range' => '1',
];
$url = $baseUrl . http_build_query($queryParams);
$ch = curl_init();
$options = [
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_SSL_VERIFYHOST => 2,
CURLOPT_SSL_VERIFYPEER => 2,
];
curl_setopt_array($ch, $options);
$response = curl_exec($ch);
curl_close($ch);
$intraday_data = json_decode($response);
if(isset($intraday_data->intraday)){
$intraday_data = json_encode($intraday_data->intraday);
$wpdb->replace(
'wp_financialdata',
array(
'name' => 'intraday',
'data' => $intraday_data,
),
array(
'%s',
'%s',
)
);
}
// GET Stock Info and store it in bdd
$url_stock = "https://api.worldtradingdata.com/api/v1/stock?symbol=LOUP.PA&api_token=".$token;
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $url_stock);
$stock = json_decode(curl_exec($ch));
// Check the return value of curl_exec(), too
if ($stock === false) {
throw new \Exception(curl_error($ch), curl_errno($ch));
}
curl_close($ch);
if(!isset($stock->data)){
return;
}
$stock_data = json_encode($stock->data);
$wpdb->replace(
'wp_financialdata',
array(
'name' => 'stock',
'data' => $stock_data,
),
array(
'%s',
'%s',
)
);
die();
}
//Fonction pour récupérer les données historiques de l'action (A utiliser dans un cron toutes les nuits)
function getFinancialData(){
global $wpdb;
$token = "0cM90jcNAWtMvgq922We3IRj6URAILQFxjnlySHoWCYCeTZMp7H7T7WTQzGE";
//Get historical data for financial data
$url_historical = 'https://api.worldtradingdata.com/api/v1/history?symbol=LOUP.PA&api_token='.$token;
// var_dump($url_historical);die;
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $url_historical);
$response = curl_exec($ch);
file_put_contents('test.txt', $response);
$history = json_decode($response);
// Check the return value of curl_exec(), too
if ($history === false) {
throw new \Exception(curl_error($ch), curl_errno($ch));
}
curl_close($ch);
if(!isset($history->history)){
return;
}
$history_data = json_encode($history->history);
$wpdb->replace(
'wp_financialdata',
array(
'name' => 'history',
'data' => $history_data,
),
array(
'%s',
'%s',
)
);
die();
}
//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 getGraphData(){
$period = $_POST['period'];
global $wpdb;
$stock_data = $wpdb->get_results("SELECT * FROM wp_financialdata WHERE name = 'stock'");
$stock = json_decode($stock_data[0]->data);
$stock_object = (array) $stock[0];
$stock_day = date('d/m/Y');
$stock_value = $stock_object['price'];
$historical_data = $wpdb->get_results("SELECT * FROM wp_financialdata WHERE name = 'history'");
$history = json_decode($historical_data[0]->data);
$historical_array = (array) $history;
$date_arr = array();
$values = array();
if($period == "all"){
array_push($date_arr, $stock_day);
array_push($values, $stock_value);
$history_4 = $historical_array;
} else if($period == "YTD"){
array_push($date_arr, $stock_day);
array_push($values, $stock_value);
$history_4 = array();
$currentYear = date('Y');
foreach ($historical_array as $date => $obj) {
if(date('Y', strtotime($date)) == $currentYear){
$history_4[$date] = $obj;
}
}
} else if ($period == "intraday"){
$history_4 = array();
$intraday_data = $wpdb->get_results("SELECT * FROM wp_financialdata WHERE name = 'intraday'");
$intraday = json_decode($intraday_data[0]->data);
$intraday_array = (array) $intraday;
foreach ($intraday_array as $date => $obj) {
$history_4[$date] = $obj;
}
} else {
array_push($date_arr, $stock_day);
array_push($values, $stock_value);
if($period != 5){
$dayToGo = strtotime('-'.$period." day");
$history_4 = array();
foreach ($historical_array as $date => $obj) {
if(strtotime($date) >= $dayToGo){
$history_4[$date] = $obj;
}
}
} else {
$history_4 = array_slice($historical_array, 0, $period - 1);
}
}
foreach ($history_4 as $date => $obj) {
if($period == 'intraday'){
array_push($date_arr, date('H:i', strtotime($date)));
} else {
array_push($date_arr, date('d/m/Y', strtotime($date)));
}
array_push($values, $obj->close);
}
$date_arr = array_reverse($date_arr);
$values = array_reverse($values);
echo json_encode(array("dates" => $date_arr, "values" => $values));
die();
}
///////////////////// POC : ALERTES POUR LES OFFRES D'EMPLOI //////////////////////
//Fonction pour récupérer et enregistrer les données DigitalRecruiters dans une table
function getDataFromDigitalRecruiters(){
global $wpdb;
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_URL, 'https://app.digitalrecruiters.com/export/job-ads/VB6kTDohe53TK0SMiu4CRGpj14UXLvgzh3mFu7eY');
$result = curl_exec($ch);
curl_close($ch);
$poles = array();
$metier = array();
$type = array();
$tps = array();
if($result){
$oDigitalRecruiter = json_decode($result);
if(isset($oDigitalRecruiter->ads)){
foreach($oDigitalRecruiter->ads as $offer){
$hierarchy_array = $offer->entity->hierarchy;
foreach ($hierarchy_array as $oHierarchy) {
if($oHierarchy->column_name == "Pôles"){
$p = $oHierarchy->public_name;
}
}
if(!in_array($p, $poles)){
array_push($poles, $p);
}
$m = $offer->service;
if(!in_array($m, $metier)){
array_push($metier, $m);
}
$t = $offer->contract_type;
if(!in_array($t, $type)){
array_push($type, $t);
}
$tp = $offer->contract_work_period;
if(!in_array($tp, $tps)){
array_push($tps, $tp);
}
}
}
}
$wpdb->replace(
'wp_recruiterdata',
array(
'name' => 'poles',
'data' => json_encode($poles),
),
array(
'%s',
'%s',
)
);
$wpdb->replace(
'wp_recruiterdata',
array(
'name' => 'metiers',
'data' => json_encode($metier),
),
array(
'%s',
'%s',
)
);
$wpdb->replace(
'wp_recruiterdata',
array(
'name' => 'types',
'data' => json_encode($type),
),
array(
'%s',
'%s',
)
);
$wpdb->replace(
'wp_recruiterdata',
array(
'name' => 'temps',
'data' => json_encode($tps),
),
array(
'%s',
'%s',
)
);
$wpdb->replace(
'wp_recruiterdata',
array(
'name' => 'data',
'data' => json_encode($oDigitalRecruiter->ads),
),
array(
'%s',
'%s',
)
);
die();
}
// 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;
$poles = $_POST['poles'];
$metiers = $_POST['metiers'];
$types = $_POST['types'];
$temps = $_POST['temps'];
$email = $_POST['email'];
$data = array(
'poles' => $poles,
'metiers' => $metiers,
'types' => $types,
'temps' => $temps
);
$wpdb->delete( 'wp_jobalert', array( 'email' => $email ) );
$wpdb->replace(
'wp_jobalert',
array(
'email' => $email,
'data' => json_encode($data),
),
array(
'%s',
'%s',
)
);
echo(json_encode('ok'));
die();
}
//Fonctions qui cherchent les annonces correspondantes et les envoient par mail (A mettre dans un cron toutes les nuits)
//Attention, Il faut mettre la configuration SMTP pour l'envoi de mail / Faire un template de mail
function checkMailToAlert() {
global $wpdb;
//Récupère les informations des personnes enregistrés pour l'alerte
$alertData = $wpdb->get_results(
"
SELECT email, data
FROM wp_jobalert
",
ARRAY_A
);
//Récupère les informations de digitalrecruiter (les différents poles, types, metiers, temps et la liste des annonces)
$jobData = $wpdb->get_results(
"
SELECT name, data
FROM wp_recruiterdata
",
ARRAY_A
);
//Créé les tableaux des infos digitalrecruiters
foreach ($jobData as $dataValues) {
switch ($dataValues['name']) {
case 'poles':
$poles = json_decode($dataValues['data']);
break;
case 'metiers':
$metiers = json_decode($dataValues['data']);
break;
case 'types':
$types = json_decode($dataValues['data']);
break;
case 'temps':
$temps = json_decode($dataValues['data']);
break;
case 'data':
$jobads = json_decode($dataValues['data']);
break;
}
}
//Pour chaque personne ayant demandés une alerte
foreach ($alertData as $userData) {
$userEmail = $userData['email'];
$userPoleFilter = "";
$userMetierFilter = "";
$userTypeFilter = "";
$userTempsFilter = "";
$userJobAds = $jobads;
//Correspondance entre ID des filtres utilisateurs avec les tableaux des infos digitalrecruiters (Récupère la valeur de recherche)
$oFilters = json_decode($userData['data']);
if($oFilters->poles != 'all'){
$userPoleFilter = $poles[$oFilters->poles];
}
if($oFilters->metiers != 'all'){
$userMetierFilter = $metiers[$oFilters->metiers];
}
if($oFilters->types != 'all'){
$userTypeFilter = $types[$oFilters->types];
}
if($oFilters->temps != 'all'){
$userTempsFilter = $temps[$oFilters->temps];
}
$keysToDelete = array();
//Pour chaque Annonces, on va checker chaque filtres et récupérer les ids a supprimer du tableaux
foreach ($userJobAds as $key => $oJob) {
$remove = false;
if($userMetierFilter != "" && $oJob->service != $userMetierFilter){
$remove = true;
}
if($userTypeFilter != "" && $oJob->contract_type != $userTypeFilter){
$remove = true;
}
if($userTempsFilter != "" && $oJob->contract_work_period != $userTempsFilter){
$remove = true;
}
foreach ($oJob->entity->hierarchy as $hierarchy) {
if($hierarchy->column_name == "Pôles"){
if($userPoleFilter != "" && $hierarchy->public_name != $userPoleFilter){
$remove = true;
}
}
}
if($remove){
array_push($keysToDelete, $key);
}
}
//Effacement des annonces qui ne correspondent pas au filtres.
foreach ($keysToDelete as $key) {
unset($userJobAds[$key]);
}
//Envoi du mail s'il y a des annonces correspondantes
if(count($userJobAds) > 0){
$body = "";
$body .= "";
$body .= "";
$body .= "Bonjour,
";
$body .= "Vous vous êtes inscrits pour recevoir des alertes aux annonces LDC correspondantes a votre profil.
";
$body .= "De nouveaux résultats sont disponibles :
";
$body .= "";
$body .= "Merci
";
$body .= "";
}
var_dump($body);
echo '
';
}
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 . '