Commit 8d8d5cda authored by metzlerd's avatar metzlerd
Browse files

??

parent 415fe178
<?php
/**
* @file FrxSQLQueryBuilder.inc
* FrxSQLQuery SQL Builder
* This class defines a common query builder that is used to
* make SQL safe queries based on named column filteres.
* @author metzlerd
*/
class FrxSQLQueryBuilder {
private $repository;
private $provider;
private $block_name;
private $sql;
private $clauses = array();
private $descriptions = array();
private $where_clause = array();
private $comparison_operators= array(
'<' => 'is less than',
'>' => 'is greater than',
'=' => 'is equal to',
'<>' => 'is not equal to',
'= any' => 'is one of',
'LIKE' => 'is like',
);
private $data;
/**
* @param unknown_type $block
* @return FrxSQLQueryBuilder
*/
public function block($block) {
list($provider, $block_name) = @explode('/', $block, 2);
$this->provider = $provider;
$this->block_name = $block_name;
$this->repository = Frx::RepoMan()->repository($provider);
$this->loadBlock();
return $this;
}
/**
* @return FrxSQLQueryBuilder
*/
protected function loadblock() {
if ($this->repository && $this->block_name) {
$this->block = $this->repository->loadBlock($This->block_name);
}
return $this;
}
/**
* Starts the query builder
* Enter description here ...
*/
public function query($block, $values = array()) {
$this->applied_filters = array();
$this->block=$block;
$this->data = $values;
return $this;
}
/**
* Executes the query that was started with query method
* Enter description here ...
*/
public function execute() {
return Frx::RepoMan()->data($this->block, $this->data, $this->sql());
}
/**
* Return the last where clause used for the data block.
*/
public function sql() {
$where = '';
$i=0;
if (count($this->where_clause)>0) {
foreach ($this->where_clause as $clause) {
$i++;
$where .= $i==1 ? 'WHERE ' : ' AND ';
$where .= $clause;
}
}
return $where;
}
public function where($condition, $include = TRUE ) {
if ($include) $this->where_clause[] = $condition;
return $this;
}
/**
* Filters the query that is being executed
* Enter description here ...
* @param string $field
* @param string $comparison
*/
public function filter($field, $comparison, $include=TRUE) {
if ($include===NULL) $include = (!empty($this->data[$field]));
if ($include && @$this->comparison_operators[$comparison]) {
$this->where_clause[] = $field . ' ' . $comparison . ' :' . $field ;
}
return $this;
}
/**
* Removing
* Enter description here ...
* @param unknown_type $field
* @param unknown_type $comparison
* @param unknown_type $value
*/
public function condition($field, $value, $comparison='=') {
$this->data[$field] = $value;
$this->filter($field, $comparison);
}
/**
* Filters the query if the value is present
* Enter description here ...
* @param string $field
* @param string $comparison
*/
public function filter_not_null($field, $comparison) {
if (!empty($this->data[$field])) {
$this->filter($field, $comparison);
}
return $this;
}
<?php
/**
* @file FrxSQLQueryBuilder.inc
* FrxSQLQuery SQL Builder
* This class defines a common query builder that is used to
* make SQL safe queries based on named column filteres.
* @author metzlerd
*/
class FrxSQLQueryBuilder {
private $repository;
private $provider;
private $block_name;
private $sql;
private $clauses = array();
private $descriptions = array();
private $where_clause = array();
private $comparison_operators= array(
'<' => 'is less than',
'>' => 'is greater than',
'=' => 'is equal to',
'<>' => 'is not equal to',
'= any' => 'is one of',
'LIKE' => 'is like',
);
private $data;
/**
* @param unknown_type $block
* @return FrxSQLQueryBuilder
*/
public function block($block) {
list($provider, $block_name) = @explode('/', $block, 2);
$this->provider = $provider;
$this->block_name = $block_name;
$this->repository = Frx::RepoMan()->repository($provider);
$this->loadBlock();
return $this;
}
/**
* @return FrxSQLQueryBuilder
*/
protected function loadblock() {
if ($this->repository && $this->block_name) {
$this->block = $this->repository->loadBlock($This->block_name);
}
return $this;
}
/**
* Starts the query builder
* Enter description here ...
*/
public function query($block, $values = array()) {
$this->applied_filters = array();
$this->block=$block;
$this->data = $values;
return $this;
}
/**
* Executes the query that was started with query method
* Enter description here ...
*/
public function execute() {
return Frx::RepoMan()->data($this->block, $this->data, $this->sql());
}
/**
* Return the last where clause used for the data block.
*/
public function sql() {
$where = '';
$i=0;
if (count($this->where_clause)>0) {
foreach ($this->where_clause as $clause) {
$i++;
$where .= $i==1 ? 'WHERE ' : ' AND ';
$where .= $clause;
}
}
return $where;
}
public function where($condition, $include = TRUE ) {
if ($include) $this->where_clause[] = $condition;
return $this;
}
/**
* Filters the query that is being executed
* Enter description here ...
* @param string $field
* @param string $comparison
*/
public function filter($field, $comparison, $include=TRUE) {
if ($include===NULL) $include = (!empty($this->data[$field]));
if ($include && @$this->comparison_operators[$comparison]) {
$this->where_clause[] = $field . ' ' . $comparison . ' :' . $field ;
}
return $this;
}
/**
* Removing
* Enter description here ...
* @param unknown_type $field
* @param unknown_type $comparison
* @param unknown_type $value
*/
public function condition($field, $value, $comparison='=') {
$this->data[$field] = $value;
$this->filter($field, $comparison);
}
/**
* Filters the query if the value is present
* Enter description here ...
* @param string $field
* @param string $comparison
*/
public function filter_not_null($field, $comparison) {
if (!empty($this->data[$field])) {
$this->filter($field, $comparison);
}
return $this;
}
}
\ No newline at end of file
<?php
/**
* @file FrxMPDF.inc
* PDF document via MPDF Library
* @author davidmetzler
*
*/
class FrxMPDF extends FrxDocument {
private $p;
public function __construct() {
// To do - use config variable of path to mpdf libs
define('_MPDF_PATH', 'sites/all/libraries/mpdf/');
include_once('sites/all/libraries/mpdf/mpdf.php');
$this->content_type='application/pdf';
}
public function render($r, $format, $options = array()) {
// To Do
// The option switch off links on PDF will bee good here too
$disable_links = variable_get('forena_pdf_disable_links', TRUE);
$html = $this->check_markup($r->html);
if ($disable_links) {
$html = preg_replace('/<a href=\"(.*?)\">(.*?)<\/a>/', "\\2", $html);
}
$mpdf = new mPDF('UTF-8');
$mpdf->AddPageByArray(array(
'orientation' => 'P'
));
$output = '';
$output = '<html><head>';
$output .= '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>';
if (@$options['css'] || isset($r->rpt_xml->head->style)) {
$output .= '<style type="text/css">';
$output .= $css;
if (isset($r->rpt_xml->head->style)) {
$sheet = (string)$r->rpt_xml->head->style;
$output .= $sheet;
}
$output .= '</style>';
}
$output .= '<title>' . $r->title . "</title></head><body class='forena-report $link_class'><h1>" . $r->title . '</h1>' . $html;
$output .= '</body></html>';
foreach (Frx::Skin()->stylesheets as $type => $sheets) {
foreach ($sheets as $sheet) {
switch ($type) {
case 'all':
case 'print':
case 'screen':
case 'pdf':
$mpdf->WriteHTML(file_get_contents($sheet), 1);
//echo $sheet;
break;
}
}
}
$mpdf->WriteHTML($output);
// $pdf = $mpdf->Output('', 'S');
$pdf = $mpdf->Output();
return $pdf;
}
public function output($pdf) {
$http_headers = array(
'Pragma' => 'no-cache',
'Expires' => '0',
'Cache-Control' => 'no-cache, must-revalidate',
'Cache-Control' => 'private',
'Content-Transfer-Encoding' => 'binary',
'Content-Type' => 'application/pdf',
);
foreach ($http_headers as $name => $value) {
$value = preg_replace('/\r?\n(?!\t| )/', '', $value);
drupal_add_http_header($name, $value);
}
return TRUE;
}
}
<?php
/**
* @file FrxMPDF.inc
* PDF document via MPDF Library
* @author davidmetzler
*
*/
class FrxMPDF extends FrxDocument {
private $p;
public function __construct() {
// To do - use config variable of path to mpdf libs
define('_MPDF_PATH', 'sites/all/libraries/mpdf/');
include_once('sites/all/libraries/mpdf/mpdf.php');
$this->content_type='application/pdf';
}
public function render($r, $format, $options = array()) {
// To Do
// The option switch off links on PDF will bee good here too
$disable_links = variable_get('forena_pdf_disable_links', TRUE);
$html = $this->check_markup($r->html);
if ($disable_links) {
$html = preg_replace('/<a href=\"(.*?)\">(.*?)<\/a>/', "\\2", $html);
}
$mpdf = new mPDF('UTF-8');
$mpdf->AddPageByArray(array(
'orientation' => 'P'
));
$output = '';
$output = '<html><head>';
$output .= '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>';
if (@$options['css'] || isset($r->rpt_xml->head->style)) {
$output .= '<style type="text/css">';
$output .= $css;
if (isset($r->rpt_xml->head->style)) {
$sheet = (string)$r->rpt_xml->head->style;
$output .= $sheet;
}
$output .= '</style>';
}
$output .= '<title>' . $r->title . "</title></head><body class='forena-report $link_class'><h1>" . $r->title . '</h1>' . $html;
$output .= '</body></html>';
foreach (Frx::Skin()->stylesheets as $type => $sheets) {
foreach ($sheets as $sheet) {
switch ($type) {
case 'all':
case 'print':
case 'screen':
case 'pdf':
$mpdf->WriteHTML(file_get_contents($sheet), 1);
//echo $sheet;
break;
}
}
}
$mpdf->WriteHTML($output);
// $pdf = $mpdf->Output('', 'S');
$pdf = $mpdf->Output();
return $pdf;
}
public function output($pdf) {
$http_headers = array(
'Pragma' => 'no-cache',
'Expires' => '0',
'Cache-Control' => 'no-cache, must-revalidate',
'Cache-Control' => 'private',
'Content-Transfer-Encoding' => 'binary',
'Content-Type' => 'application/pdf',
);
foreach ($http_headers as $name => $value) {
$value = preg_replace('/\r?\n(?!\t| )/', '', $value);
drupal_add_http_header($name, $value);
}
return TRUE;
}
}
<?php
/**
* @file FrxHtmlDoc
* Straight XML document with no wrapping theme.
* @author davidmetzler
*
*/
class FrxXMLDoc extends FrxDocument {
public function __construct() {
$this->content_type = 'application/xml';
}
public function render($r, $format, $options = array()) {
$body = $this->check_markup($r->html);
$output = '<?xml version="1.0"?>' . "\n";
$output .= '<div>' . $body . "</div>\n";
return $output;
}
public function output($output) {
header('Content-Type: ' . $this->content_type);
header('Cache-Control:');
header('Pragma:');
header('Cache-Control: must-revalidate');
print $output;
return TRUE;
}
<?php
/**
* @file FrxHtmlDoc
* Straight XML document with no wrapping theme.
* @author davidmetzler
*
*/
class FrxXMLDoc extends FrxDocument {
public function __construct() {
$this->content_type = 'application/xml';
}
public function render($r, $format, $options = array()) {
$body = $this->check_markup($r->html);
$output = '<?xml version="1.0"?>' . "\n";
$output .= '<div>' . $body . "</div>\n";
return $output;
}
public function output($output) {
header('Content-Type: ' . $this->content_type);
header('Cache-Control:');
header('Pragma:');
header('Cache-Control: must-revalidate');
print $output;
return TRUE;
}
}
\ No newline at end of file
<?php
/**
* @file forena.drush.inc
* Implementation of drush command hook.
*/
function forena_drush_command() {
$items = array();
$items['clear-forena-cache'] = array(
'description' => 'Clear forenas report cache',
'examples' => array('drush frxcc'),
'aliases' => array('frxcc')
);
$items['deliver-forena-reports'] = array(
'description' => 'Copy/Deliver module provided forena reports',
'examples' => array('drush frxcp'),
'aliases' => array('frxcp'),
);
return $items;
}
/**
* Execute a clear forena's cache from drush
*/
function drush_forena_clear_forena_cache() {
require_once 'forena.common.inc';
require_once 'forena.admin.inc';
forena_sync_reports(FALSE);
}
/**
* Execute copy of the reports from drush.
*/
function drush_forena_deliver_forena_reports() {
require_once 'forena.common.inc';
require_once 'forena.admin.inc';
forena_sync_reports(TRUE);
<?php
/**
* @file forena.drush.inc
* Implementation of drush command hook.
*/
function forena_drush_command() {
$items = array();
$items['clear-forena-cache'] = array(
'description' => 'Clear forenas report cache',
'examples' => array('drush frxcc'),
'aliases' => array('frxcc')
);
$items['deliver-forena-reports'] = array(
'description' => 'Copy/Deliver module provided forena reports',
'examples' => array('drush frxcp'),
'aliases' => array('frxcp'),
);
return $items;
}
/**
* Execute a clear forena's cache from drush
*/
function drush_forena_clear_forena_cache() {
require_once 'forena.common.inc';
require_once 'forena.admin.inc';
forena_sync_reports(FALSE);
}
/**
* Execute copy of the reports from drush.
*/
function drush_forena_deliver_forena_reports() {
require_once 'forena.common.inc';
require_once 'forena.admin.inc';
forena_sync_reports(TRUE);
}
\ No newline at end of file
<?php
/**
* @file
* Forena PDF installation
*/
/**
* Implementation of hook_uninstall
*/
function forena_pdf_uninstall() {
variable_del('forena_pdf_disable_links');
variable_del('forena_pdf_generator');
variable_del('fornea_pdf_prince_path');
<?php
/**
* @file
* Forena PDF installation
*/
/**
* Implementation of hook_uninstall
*/
function forena_pdf_uninstall() {
variable_del('forena_pdf_disable_links');
variable_del('forena_pdf_generator');
variable_del('fornea_pdf_prince_path');
}
\ No newline at end of file
<?php
/**
* @file
* Implements a title renderer
* @author metzlerd
*
*/
class FrxTitle extends FrxRenderer {
public function render() {
$html = $this->innerXML();
$html = $this->teng->replace($html);
$text = check_plain($html);
$this->frxReport->title = $text;
return '';
}
<?php
/**
* @file