public function eval_syntax($str, $version) { if (is_null(self::$started)) { self::$started = microtime(true); } $this->version = $version; $str = str_replace(array("\r\n", "\r"), array("\n", "\n"), $str); if ($version == 1) { //replace comments $str = preg_replace('#\\/\\*.+?\\*\\/#s', '', $str); //merge multiline strings if (preg_match_all('#\\{\\{(.+?)\\}\\}#s', $str, $matches) && is_array($matches[0]) && sizeof($matches[0]) > 0) { foreach ($matches[0] as $key => $val) { $str = str_replace($val, str_replace("\n", '\\n', $matches[1][$key]), $str); } } $result = array(); $this->cmd_list = explode("\n", $str); if (!isset($this->cmd_list[1])) { $this->cmd_list = explode("[br]", $str); } $this->build_indexes(); while (list($key, $line) = each($this->cmd_list)) { if (self::$started + self::XT_SYNTAX_TIMEOUT < microtime(true)) { return 'XtScript Error: Timeout.'; } $line = trim(trim($line), ';'); if (!empty($line) && strpos($line, '#') !== 0) { //replace back newlines $line = str_replace('\\n', "\n", $line); $splited = explode(' ', $line, 2); $cmd = strtolower($splited[0]); $args = array(); if ($cmd == 'assign' || $cmd == 'var') { $args = explode('=', $splited[1], 2); } elseif ($cmd == 'include') { $args = explode(',', $splited[1]); $args = array_map('trim', $args); } elseif ($cmd == 'call' || $cmd == 'function') { $splited = explode(' ', $splited[1], 2); $function = $splited[0]; if (!isset($splited[1])) { $aargs = array(); } else { $aargs = explode(';', $splited[1]); } $args = array($function); if (sizeof($aargs) > 0) { foreach ($aargs as $aarg) { $aarg = trim($aarg); $tmp = explode('=', $aarg, 2); $args[$tmp[0]] = common::get_param($tmp[1], ''); } } } elseif (isset($splited[1])) { $args = $splited[1]; } $result[] = $this->eval_cmd($cmd, $args); } } return implode('', $result); } return ''; }