You are here

public function FrxDataSource::parseSQLFile in Forena Reports 7.3

Same name and namespace in other branches
  1. 7.4 FrxDataSource.inc \FrxDataSource::parseSQLFile()
2 calls to FrxDataSource::parseSQLFile()
FrxDataSource::loadBlockFromDB in ./FrxDataSource.inc
FrxDataSource::loadBlockFromFile in ./FrxDataSource.inc

File

./FrxDataSource.inc, line 302
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;
  $info_text = '';
  $tokens = array();
  $options = array();
  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':
            dpm($this->te
              ->replace($switch), 'SWITCH');
            $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':
            $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));
  $options = drupal_parse_info_format($info_text);
  $block = array(
    'source' => $data,
    'file' => trim($file, " \n"),
    'tokens' => $tokens,
    'options' => $options,
  );
  if ($access) {
    $block['access'] = $access;
  }
  return $block;
}