public function RemoteCalls::perform in Anti Spam by CleanTalk 8.4
Same name and namespace in other branches
- 9.1.x src/lib/Cleantalk/Common/RemoteCalls.php \Cleantalk\Common\RemoteCalls::perform()
Execute corresponding method of RemoteCalls if exists
Return value
void|string
File
- src/
lib/ Cleantalk/ Common/ RemoteCalls.php, line 74
Class
Namespace
Cleantalk\CommonCode
public function perform() {
$action = strtolower(Get::get('spbc_remote_call_action'));
$token = strtolower(Get::get('spbc_remote_call_token'));
$actions = $this->available_rc_actions;
if (count($actions) !== 0 && array_key_exists($action, $actions)) {
$cooldown = isset($actions[$action]['cooldown']) ? $actions[$action]['cooldown'] : self::COOLDOWN;
// Return OK for test remote calls
if (Get::get('test')) {
die('OK');
}
if (time() - $actions[$action]['last_call'] >= $cooldown) {
$actions[$action]['last_call'] = time();
$this
->setLastCall($action);
// Check API key
if ($token === strtolower(md5($this->api_key))) {
// Flag to let plugin know that Remote Call is running.
$this->rc_running = true;
$action_method = 'action__' . $action;
if (method_exists(static::class, $action_method)) {
// Delay before perform action;
if (Get::get('delay')) {
sleep(Get::get('delay'));
}
$action_result = static::$action_method();
$response = empty($action_result['error']) ? 'OK' : 'FAIL ' . json_encode(array(
'error' => $action_result['error'],
));
if (!Get::get('continue_execution')) {
die($response);
}
return $response;
}
else {
$out = 'FAIL ' . json_encode(array(
'error' => 'UNKNOWN_ACTION_METHOD',
));
}
}
else {
$out = 'FAIL ' . json_encode(array(
'error' => 'WRONG_TOKEN',
));
}
}
else {
$out = 'FAIL ' . json_encode(array(
'error' => 'TOO_MANY_ATTEMPTS',
));
}
}
else {
$out = 'FAIL ' . json_encode(array(
'error' => 'UNKNOWN_ACTION',
));
}
die($out);
}