FrxDataProvider.inc in Forena Reports 6
Same filename and directory in other branches
Class that defines default methods for access control in an FrxDataProvider
File
FrxDataProvider.incView source
<?php
/**
* @file
* Class that defines default methods for access control in an FrxDataProvider
*
*/
class FrxDataProvider {
public $conf;
public $block_path;
public $comment_prefix;
public $comment_suffix;
public $block_ext;
protected $te;
public function __construct($conf, $repos_path) {
$this->conf = $conf;
$this->comment_prefix = '--';
$this->block_ext = 'sql';
$this->block_path = $repos_path;
}
/**
* Implements the basic default security check of calling
* an access method.
*
* @param unknown_type $arg
* @return unknown
*/
public function access($arg) {
$f = $this->conf['access callback'];
if ($f && is_callable($f)) {
return $f($arg);
}
elseif (isset($this->conf['access block'])) {
$block = $this->conf['access block'];
if (isset($this->conf['access path'])) {
$path = $this->conf['access path'];
}
return forena_block_access($block, $path, $arg);
}
else {
return user_access('access content');
}
}
/**
* 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 should return data, access and
* probably parameters to.
* @param unknown_type $block_name
* @return unknown
*/
public function load_block($block_name, $clause = '') {
$filename = $this->block_path . '/' . $block_name . '.' . $this->block_ext;
$block = forena_load_block_file($filename, $this->comment_prefix, $this->comment_suffix);
// If we have a regular expression token parser, then get the tokens out of the block.
if ($this->te) {
$tokens = $this->te
->tokens($block['source']);
//drupal_set_message("tokens: ". print_r($tokens, 1));
//check tokens in the where clause
if ($clause) {
$clause_tokens = $this->te
->tokens($clause);
//drupal_set_message("clause tokens: ". print_r($clause_tokens, 1));
$temp = array();
$temp = array_merge($tokens, $clause_tokens);
//check for duplicates in block tokens
if ($clause_tokens) {
foreach ($clause_tokens as $ct) {
if (!$temp[$ct]) {
array_push($tokens, $ct);
}
}
}
}
$block['tokens'] = $tokens;
}
return $block;
}
/**
* Find all the blocks matching a provided search string
*
* @param string $search part block names to search for
* @return unknown
*/
public function list_blocks($search, $subdir = '', $this_list = array()) {
$block_list = $this_list;
// First find files that match the search string
$path = $this->block_path . '/';
if ($subdir) {
$path = $subdir . '/';
}
$block_path .= $path . '*' . $search . '*.' . $this->block_ext;
// Find sql files
$d = glob($block_path);
if ($d) {
foreach ($d as $file_name) {
// Split off the extention
$p = strripos($file_name, '.');
if ($p !== FALSE) {
$ext = substr($file_name, $p + 1);
$block_name = substr($file_name, 0, $p);
}
else {
$ext = '';
$block_name = $file_name;
}
$block_list[] = str_replace($this->block_path . '/', '', $block_name);
}
}
// Find directories
$d = glob($path . '*');
if ($d) {
foreach ($d as $dir_name) {
if (is_dir($dir_name)) {
$block_list += $this
->list_blocks($search, $dir_name, $block_list);
}
}
}
return $block_list;
}
}
Classes
Name | Description |
---|---|
FrxDataProvider | @file Class that defines default methods for access control in an FrxDataProvider |