You are here

function elysia_cron_decode_script in Elysia Cron 6.2

Same name and namespace in other branches
  1. 5.2 elysia_cron.module \elysia_cron_decode_script()
  2. 5 elysia_cron.module \elysia_cron_decode_script()
  3. 6 elysia_cron.module \elysia_cron_decode_script()
  4. 7.2 elysia_cron.module \elysia_cron_decode_script()
  5. 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

File

./elysia_cron.module, line 769

Code

function elysia_cron_decode_script($text, $apply = true) {
  global $elysia_cron_settings;
  $lines = explode("\n", $text);
  $lastcomment = '';
  $errors = array();
  $conf = array();
  foreach ($lines as $line) {
    $line = trim($line);
    if (!empty($line)) {
      if ($line[0] == '#') {
        $lastcomment = trim(substr($line, 1));
      }
      else {
        if (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;
}