File: /var/www/html/wp-content/plugins/bsx/be/bsx-rest-process.php
<?php
// ===== 1. WP CRON SETUP (alle 5 Minuten) =====
add_action('wp', 'setup_cron_sync1');
function setup_cron_sync1() {
if (!wp_next_scheduled('sync_camp_backend')) {
wp_schedule_event(time(), 'five_minutes', 'sync_camp_backend');
}
}
// Custom Cron Intervall definieren
add_filter('cron_schedules', 'add_five_minutes_cron_interval');
function add_five_minutes_cron_interval($schedules) {
$schedules['five_minutes'] = array(
'interval' => 300,
'display' => __('Every 5 minutes')
);
return $schedules;
}
add_action('sync_camp_backend', function() {
$dat = bsx_rest_get("cupd");
save_to_db($dat);
});
function save_to_db($dat) {
global $wpdb;
$table = 'wp_bsx_kpi';
foreach ($dat as $c) {
$old = $wpdb->get_results($wpdb->prepare(
"select * from wp_bsx_kpi where cid = %s",$c['cid'])
);
if ($old[0]->stat != $c['stat']) {
wp_set_post_terms( $c['cid'], $c['stat'], 'campaign-status');
if($c['stat']=='Active') {
$xdt = 0;
$xprc = 0;
} else {
$xdt = $c['xdt'] ?? 0;
$xprc = $c['xprc'] ?? 0;
}
} else {
$xdt = $c['xdt'] ?? 0;
$xprc = $c['xprc'] ?? 0;
}
$xprc = $c['xprc'] ?? 0;
$xdt = $c['xdt'] ?? 0;
// $c = gmt2local($c);
$wpdb->replace(
$table,
array(
'cid' => $c['cid'],
'ysym' => $c['ysym'],
'proc' => $c['proc'],
'stat' => $c['stat'],
'mngd' => $c['mngd'],
'cass_id' => $c['cass_id'],
'ls' => $c['ls'],
'pdt' => $c['pdt'],
'edt' => $c['edt'],
'eprc' => $c['eprc'],
'cdt' => $c['cdt'],
'cprc' => $c['cprc'],
'xdt' => $xdt,
'xprc' => $xprc,
'tenure' => $c['tenure'],
'dt' => $c['dt'],
'perf' => $c['perf'],
'perf_oe' => $c['perf_oe']
),
array(
"%d",
'%s',
'%s',
'%s',
'%d',
'%d',
'%d',
'%s',
'%s',
'%f',
'%s',
'%f',
'%s',
'%f',
'%f',
'%s',
'%f',
'%f'
)
);
}
}
// ===== 1. WP CRON SETUP (15 Minuten) =====
add_action('wp', 'setup_cron_sync2');
function setup_cron_sync2() {
if (!wp_next_scheduled('sync_events_backend')) {
wp_schedule_event(time(), 'fifteen_minutes', 'sync_events_backend');
}
}
// Custom Cron Intervall definieren
add_filter('cron_schedules', 'add_fifteen_minutes_cron_interval');
function add_fifteen_minutes_cron_interval($schedules) {
$schedules['fifteen_minutes'] = array(
'interval' => 900,
'display' => __('Every 15 minutes')
);
return $schedules;
}
add_action('sync_events_backend', function() {
$evnts = bsx_rest_get("events");
save_events($evnts);
});
function save_events($evnts) {
global $wpdb;
$table = 'wp_bsx_events';
foreach ($evnts as $r) {
$exist = $wpdb->get_results($wpdb->prepare(
"select * from wp_bsx_events where eid = %s", $r['eid'])
);
if($exist) continue;
$wpdb->insert(
$table,
array(
'eid' => $r['eid'],
'dt' => $r['dt'],
'cid' => $r['cid'],
'ysym' => $r['ysym'],
'etype' => $r['etype'],
'val' => $r['val'],
'created' => $r['created']
),
array(
"%d",
'%s',
'%d',
'%s',
'%s',
'%f',
'%s'
)
);
}
$msgs = $wpdb->get_results(
"select * from wp_bsx_events a join wp_bsx_up b on a.cid = b.item_id"
);
var_dump($msgs);
}
/*
foreach($msgs as $msg) {
$commrow = $wpdb->get_row($wpdb->prepare(
'select * from wp_bsx_comm where eid = %s and user_id = %s', $msg->eid, $msg->user_id)
);
if(count($commrow)>0) continue;
$message = match($msg->etype) {
'eod' => sprintf("Please note that instrument $'%s' made a large price movement of %5.1f%% during today´s trading session \n\n\nYou are receiving this email because you have subscribed to news about $'%s' on BlackStyx Capital. Please head to your account (https://persephone-group.com/account) to manage notification settings.",
$msg->ysym, $msg->value * 100, $msg->ysym);
'intra' => sprintf("Instrument $'%s' made a large intraday price movement of %5.1f%% \n\n\nYou are receiving this email because you have subscribed to news about $'%s' on BlackStyx Capital. Please head to your account (https://persephone-group.com/account) to manage notification settings.",
$msg->ysym, $msg->value * 100, $msg->ysym);
}
wp_mail("gregor@povh",
*/