public function FrxDataSource::parseSQLFile in Forena Reports 7.4
Same name and namespace in other branches
- 7.3 FrxDataSource.inc \FrxDataSource::parseSQLFile()
1 call to FrxDataSource::parseSQLFile()
File
- ./
FrxDataSource.inc, line 257 - Class that defines default methods for access control in an FrxDataSource
Class
- FrxDataSource
- @file Class that defines default methods for access control in an FrxDataSource
Code
public function parseSQLFile($contents) {
$comment = $this->comment_prefix;
$trim = $this->comment_suffix;
$lines = explode("\n", $contents);
$cnt = count($lines);
$access = '';
$i = 0;
$block = '';
$parms = Frx::Data()
->currentContext();
$data = '';
$source = '';
$file = '';
$skip = FALSE;
$in_info = FALSE;
$found_case = FALSE;
$info_text = '';
$tokens = array();
$options = array();
$switch = '';
while ($i < $cnt) {
$l = trim($lines[$i], "\r");
@(list($d, $c) = explode($comment, $l, 2));
if ($trim) {
$c = trim($c, $trim);
}
if ($c) {
$c = trim($c);
@(list($a, $o) = explode('=', $c, 2));
$a = trim($a);
if ($a && $o || $c == 'END' || $c == 'ELSE' || $c == 'INFO') {
if ($c != 'INFO') {
$in_info = false;
}
switch ($a) {
case 'ACCESS':
$access = trim($o);
break;
case 'SWITCH':
$switch = trim($o);
$found_case = FALSE;
break;
case 'CASE':
$match = $this->te
->replace($switch, TRUE) == $this->te
->replace($o);
if ($match) {
$found_case = TRUE;
}
$skip = !$match;
break;
case 'IF':
$skip = !$this->te
->test(trim($o));
break;
case 'END':
$skip = FALSE;
$switch = '';
break;
case 'ELSE':
$skip = $switch ? $found_case : !$skip;
break;
case 'INFO':
$in_info = TRUE;
break;
case 'INCLUDE':
if (!$skip) {
$inc_block = $this
->getSQLInclude(trim($o));
if ($inc_block) {
$data .= $inc_block['source'];
$tokens = array_merge($tokens, $inc_block['tokens']);
}
}
break;
}
}
if ($a != 'ACCESS') {
$file .= "{$l}\n";
}
}
else {
$file .= "{$l}\n";
}
if ($in_info) {
if (strpos($l, $comment) !== 0 && $l) {
$info_text .= "{$l}\n";
}
}
elseif (!$skip) {
if (strpos($l, $comment) !== 0 && $l) {
$data .= "{$l}\n";
}
}
$i++;
}
$tokens = array_merge($tokens, $this
->tokens($contents));
if ($info_text) {
$options = drupal_parse_info_format($info_text);
}
$block = array(
'source' => $data,
'file' => trim($file, " \n"),
'tokens' => $tokens,
'options' => $options,
'access' => $access,
);
return $block;
}