function elysia_cron_decode_script in Elysia Cron 7.2
Same name and namespace in other branches
- 5.2 elysia_cron.module \elysia_cron_decode_script()
- 5 elysia_cron.module \elysia_cron_decode_script()
- 6.2 elysia_cron.module \elysia_cron_decode_script()
- 6 elysia_cron.module \elysia_cron_decode_script()
- 7 elysia_cron.module \elysia_cron_decode_script()
2 calls to elysia_cron_decode_script()
- elysia_cron_initialize in ./
elysia_cron.module - elysia_cron_settings_form_validate in ./
elysia_cron.admin.inc - Validate handler for 'elysia_cron_settings_form' form.
File
- ./
elysia_cron.module, line 952
Code
function elysia_cron_decode_script($text, $apply = TRUE) {
global $_elysia_cron_settings;
$lines = explode(PHP_EOL, $text);
$lastcomment = '';
$errors = array();
foreach ($lines as $line) {
$line = trim($line);
if (!empty($line)) {
if ($line[0] == '#') {
$lastcomment = trim(substr($line, 1));
}
elseif (preg_match('/^(-[ ]*|)([0-9*,\\/-]+[ ]+[0-9*,\\/-]+[ ]+[0-9*,\\/-]+[ ]+[0-9*,\\/-]+[ ]+[0-9*,\\/-]+)[ ]+((?:ctx|ch):([a-zA-Z0-9_-]+)[ ]+|)([^(:]+)(\\(.*\\);|)$/', $line, $r)) {
$c = array(
'disabled' => !empty($r[1]),
'rule' => $r[2],
'description' => $lastcomment,
'channel' => $r[4] ? $r[4] : 'default',
);
$lastcomment = '';
if (empty($r[6])) {
if (!isset($_elysia_cron_settings[$r[5]])) {
// Referring a module function that not exists.
$errors[] = $line;
continue;
}
$name = $r[5];
}
else {
// Custom expression, generate a unique name.
$postfix = '';
while (isset($_elysia_cron_settings[$r[5] . $postfix])) {
$postfix = ($postfix ? $postfix : 0) + 1;
}
$name = $r[5] . $postfix;
$c['expression'] = $r[5] . $r[6];
}
if ($apply) {
$_elysia_cron_settings[$name] = isset($_elysia_cron_settings[$name]) ? array_merge($_elysia_cron_settings[$name], $c) : $c;
}
}
else {
$errors[] = $line;
}
}
else {
$lastcomment = '';
}
}
return count($errors) ? $errors : FALSE;
}