You are here

function forena_load_block_file in Forena Reports 7

Same name and namespace in other branches
  1. 6 forena.common.inc \forena_load_block_file()

Load a block file form disk and introspect the comments to determine security Return a structured array based on this.

Parameters

unknown_type $filepath:

unknown_type $comment:

1 call to forena_load_block_file()
FrxDataProvider::load_block in ./FrxDataProvider.inc
Default block load Loads the data block based on the block name from the file system. The classes that are derived from this will set the block_ext property, which in most cases is .sql but might be something different. The load of the block file…

File

./forena.common.inc, line 459
Common functions used throughout the project but loaded in this file to keep the module file lean.

Code

function forena_load_block_file($filepath, $comment = '--', $trim) {
  if (!file_exists($filepath)) {
    return array();
  }
  $block_data = file_get_contents($filepath);
  $lines = explode("\n", $block_data);
  $cnt = count($lines);
  $access = '';
  $i = 0;
  $block = '';
  $data = '';
  while ($i < $cnt) {
    $l = trim($lines[$i], "\r");
    @(list($d, $c) = explode($comment, $l, 2));
    if ($trim) {
      $c = trim($c, $trim);
    }
    if ($c) {
      list($a, $o) = explode('=', $c, 2);
      if (trim($a) == 'ACCESS') {
        $access = trim($o);
      }
    }
    if (strpos($l, $comment) !== 0) {
      $data .= "{$l}\n";
    }
    $i++;
  }
  return array(
    'access' => $access,
    'source' => $data,
  );
}