diff --git a/content/themes/ldc/functions.php b/content/themes/ldc/functions.php
index bd53a081..d077d252 100644
--- a/content/themes/ldc/functions.php
+++ b/content/themes/ldc/functions.php
@@ -419,6 +419,8 @@ function catLink($cat_id) {
// 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
@@ -428,13 +430,9 @@ add_action( 'wp_ajax_nopriv_getGraphData', 'getGraphData' );
function getFinancialHistoryDatasByPeriod($period = false)
{
global $wpdb;
- if ($period){
- if ($period === "5"){
- return $wpdb->get_results("SELECT * FROM wp_financialdata_history LIMIT 5");
- }
- return $wpdb->get_results("SELECT * FROM wp_financialdata_history WHERE date > CURDATE() - INTERVAL $period DAY");
- }
- return $wpdb->get_results("SELECT * FROM wp_financialdata_history");
+ 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(){
diff --git a/content/themes/ldc/partials/finance-api.php b/content/themes/ldc/partials/finance-api.php
index e81710dd..7b171878 100644
--- a/content/themes/ldc/partials/finance-api.php
+++ b/content/themes/ldc/partials/finance-api.php
@@ -24,17 +24,17 @@
Financial Data : LOUP.PA (LDC SA)
= number_format($price, 2); ?> EUR
-
+
= number_format($change, 2); ?>€ (= $change_percent; ?>)
-
+
= number_format($change, 2); ?>€ (= $change_percent; ?>)
-
+
= wp_date("d/m/Y H:i:s"); ?> (UTC+2)
-
1 Jour
+
5 Jours
1 mois
6 mois
diff --git a/crons/FinancialIntraday.php b/crons/FinancialIntraday.php
index 0d0f66c3..e25389c7 100644
--- a/crons/FinancialIntraday.php
+++ b/crons/FinancialIntraday.php
@@ -78,47 +78,6 @@ function getIntradayData() {
]
);
}
-
- $baseUrl = 'https://www.alphavantage.co/query?apikey=' . $token . '&function=GLOBAL_QUOTE&symbol=LOUP.PA';
-
- $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, $baseUrl);
- $response = curl_exec($ch);
-
- if (!curl_errno($ch)) {
- $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
- if ($http_code !== 200) {
- email(MAIL_ADMIN, '[ERROR] Erreur "API" Alphavantage : getIntradayData (2)', 'Code HTTP de l\'erreur : ' . $http_code);
- die();
- }
- }else{
- email(MAIL_ADMIN, '[ERROR] Erreur "API" Alphavantage : getIntradayData (2)', 'Erreur cURL');
- die();
- }
-
- curl_close($ch);
-
- $stock = json_decode($response, true);
-
- if (!isset($stock['Global Quote'])) {
- email(MAIL_ADMIN, '[ERROR] Erreur "API" Alphavantage : getIntradayData (2)', 'Champs requis manquant.');
- return;
- }
-
- $wpdb->replace(
- 'wp_financialdata',
- array(
- 'name' => 'stock',
- 'data' => json_encode($stock['Global Quote']),
- ),
- array(
- '%s',
- '%s',
- )
- );
}
function email($email, $subject, $message)
diff --git a/crons/FinancialStock.php b/crons/FinancialStock.php
new file mode 100644
index 00000000..7a6e11c6
--- /dev/null
+++ b/crons/FinancialStock.php
@@ -0,0 +1,61 @@
+ date('H:i:s', strtotime('17:30:00')))
+ return;
+
+ global $wpdb;
+ $token = "A0RACEYVTKIGRF5M";
+
+ $baseUrl = 'https://www.alphavantage.co/query?apikey=' . $token . '&function=GLOBAL_QUOTE&symbol=LOUP.PA';
+
+ $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, $baseUrl);
+ $response = curl_exec($ch);
+
+ if (!curl_errno($ch)) {
+ $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
+ if ($http_code !== 200) {
+ email(MAIL_ADMIN, '[ERROR] Erreur "API" Alphavantage : getStockDatas', 'Code HTTP de l\'erreur : ' . $http_code);
+ die();
+ }
+ }else{
+ email(MAIL_ADMIN, '[ERROR] Erreur "API" Alphavantage : getStockDatas', 'Erreur cURL');
+ die();
+ }
+
+ curl_close($ch);
+
+ $stock = json_decode($response, true);
+
+ if (!isset($stock['Global Quote'])) {
+ email(MAIL_ADMIN, '[ERROR] Erreur "API" Alphavantage : getStockDatas', 'Champs requis manquant.');
+ return;
+ }
+
+ $wpdb->replace(
+ 'wp_financialdata',
+ array(
+ 'name' => 'stock',
+ 'data' => json_encode($stock['Global Quote']),
+ ),
+ array(
+ '%s',
+ '%s',
+ )
+ );
+}
+
+function email($email, $subject, $message)
+{
+ $headers[] = 'From: Groupe LDC
';
+ wp_mail($email, $subject, $message, $headers);
+}