primo commit

This commit is contained in:
2024-12-17 17:34:10 +01:00
commit e650f8df99
16435 changed files with 2451012 additions and 0 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 404 B

View File

@ -0,0 +1,52 @@
<?php
/**
* @version 6.2.6 tabulizer $
* @package tabulizer
* @copyright Copyright © 2011 - All rights reserved.
* @license GNU/GPL
* @author Dimitrios Mourloukos
* @author mail info@alterora.gr
* @website www.tabulizer.com
*
*/
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
TabulizerPath::requireLib('tabulizer','common');
TabulizerPath::requireLib('convert','dialog');
$jinput = JFactory::getApplication()->input;
$errors = array();
if (get_magic_quotes_gpc()) {
$text = stripslashes($jinput->post->get('raw_text','','raw'));
$caption = stripslashes($jinput->post->getString('table_caption',''));
} else {
$text = $jinput->post->get('raw_text','','raw');
$caption = $jinput->post->getString('table_caption','');
}
$separator = $jinput->post->getString('column_separator','');
$enclosure = $jinput->post->getString('column_enclosure','');
$ruleset_name = $jinput->post->getString('ruleset_name','');
$ruleset_filename = $jinput->post->getString('archive_filename','');
$use_comments = intval($jinput->post->getInt('use_comments',0));
$column_consistency = intval($jinput->post->getInt('column_consistency',0));
$metadata = array('caption'=>$caption);
$table = new Tabulizer();
if ($use_comments) $table->setComments(true);
$html = $table->process($text, $separator, $enclosure, $column_consistency, $metadata, $ruleset_filename, $ruleset_name, $errors);
if (!empty($errors)) {
$html = ERROR_CODE_PREFIX;
foreach ($errors as $error) {
$html .= '<error>'.$error.'</error>';
}
}
jexit($html);
?>

View File

@ -0,0 +1,46 @@
<?php
/**
* @version 6.2.6 tabulizer $
* @package tabulizer
* @copyright Copyright © 2011 - All rights reserved.
* @license GNU/GPL
* @author Dimitrios Mourloukos
* @author mail info@alterora.gr
* @website www.tabulizer.com
*
*/
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
class DataSourceLoader {
function getData($data_source_tag, $data_source_user_params) {
TabulizerPath::requireLib('data_source','common');
$output_str = TabulizerDataSource::getTableDataJSON($data_source_tag,$data_source_user_params);
jexit($output_str);
}
function process() {
$data_source_tag = null;
$data_source_user_params = null;
if (isset($_REQUEST['ds_tag'])) {
$data_source_tag = $_REQUEST['ds_tag'];
}
if (isset($_REQUEST['ds_user_params'])) {
$data_source_user_params = $_REQUEST['ds_user_params'];
}
if (preg_match('/^[a-zA-Z0-9\._\-]{2,128}$/i',$data_source_tag)) {
$this->getData($data_source_tag, $data_source_user_params);
}
}
}
$ds_loader = new DataSourceLoader();
$ds_loader->process();
?>

View File

@ -0,0 +1,101 @@
<?php
/**
* @version 6.2.6 tabulizer $
* @package tabulizer
* @copyright Copyright © 2011 - All rights reserved.
* @license GNU/GPL
* @author Dimitrios Mourloukos
* @author mail info@alterora.gr
* @website www.tabulizer.com
*
*/
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
$jinput = JFactory::getApplication()->input;
$clb_name = addslashes( $jinput->getString('clb_name',''));
$css_url = TabulizerPath::getURLPath('dialog.css', 'admin_css');
$js_url = TabulizerPath::getURLPath('jquery-1.6.4.min.js', 'admin_js');
$js_base64_url = TabulizerPath::getURLPath('base64_tools.js','admin_js');
$page_title = JText::_('COM_TABULIZER_TITLE');
$js_code = '
function TabulizerInsertClick() {
var ds_tag = document.getElementById("ds_tag").value;
var ds_params = document.getElementById("ds_params").value;
if ((ds_tag)&&(ds_params!="")) {
ds_params = B64.encode(ds_params);
result = "{tabulizer:data_source["+ds_tag+"] user_params["+ds_params+"]}";
} else if (ds_tag) {
result = "{tabulizer:data_source["+ds_tag+"]}";
}
window.opener.tabulizerdsClickCallback( "'.$clb_name.'", result );
window.close();
}
function TabulizerCancelClick() {
window.close();
}
';
$document = JFactory::getDocument();
$document->addScript($js_url);
$document->addScript($js_base64_url);
$document->addStyleSheet($css_url);
TabulizerJS::addScriptDeclaration($js_code);
$document->setTitle($page_title);
$database = JFactory::getDBO();
$errors = array();
$html = '';
$query = 'SELECT * FROM #__tabulizer_data_source WHERE 1 ORDER BY title ASC';
$database->setQuery($query);
$data_sources = $database->loadObjectList();
$user_params = TabulizerForm::getTextCtrl('ds_params', '');
if (empty($data_sources)) {
?>
<form name="tabulizer_form" id="tabulizer_form" method="post" onSubmit="return false">
<div style="padding: 10px; background-color: #FFFFCC;"><?php echo JText::_('COM_TABULIZER_NO_DATA_SOURCES_WERE_FOUND_EDITOR_BTN');?></div>
<br/>
<input type="button" value="<?php echo JText::_('COM_TABULIZER_CLOSE'); ?>" onClick="TabulizerCancelClick()" class="btn">
</td></tr>
</table>
<?php echo JHTML::_( 'form.token' ); ?>
</form>
<?php
} else {
$options = array();
foreach ($data_sources as $data_source) {
$options[$data_source->tag] = $data_source->title;
}
$data_sources_list = TabulizerForm::getSelectCtrl('ds_tag',null,$options);
?>
<form name="tabulizer_form" id="tabulizer_form" method="post" onSubmit="return false">
<table border="0" cellspacing="0" cellpadding="2" width="100%">
<tr><td><?php echo JText::_('COM_TABULIZER_DATA_SOURCES'); ?>:</td><td><?php echo $data_sources_list; ?></td></tr>
<tr><td><?php echo JText::_('COM_TABULIZER_DATA_SOURCES_USER_PARAMS'); ?>:</td><td><?php echo $user_params; ?></td></tr>
<tr><td colspan="2" align="left" valign="bottom" nowrap>
<hr/>
<input type="submit" value="<?php echo JText::_('COM_TABULIZER_INSERT_TABLE'); ?>" onClick="TabulizerInsertClick()" class="btn">
<input type="button" value="<?php echo JText::_('COM_TABULIZER_CANCEL_CONVERSION'); ?>" onClick="TabulizerCancelClick()" class="btn">
</td></tr>
</table>
<?php echo JHTML::_( 'form.token' ); ?>
</form>
<?php
}
?>

View File

@ -0,0 +1,736 @@
<?php
/**
* @version 6.2.6 tabulizer $
* @package tabulizer
* @copyright Copyright © 2011 - All rights reserved.
* @license GNU/GPL
* @author Dimitrios Mourloukos
* @author mail info@alterora.gr
* @website www.tabulizer.com
*
*/
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
// increase memory and execution time limits
TabulizerPerformance::increaseProcessingLimits();
class ExportData {
var $form_prefix = null;
var $export_source = null;
var $export_type = null;
var $export_output = null;
var $export_data = null;
var $export_filename = null;
var $export_email_recipients = null;
var $export_email_subject = null;
var $export_email_body = null;
var $export_dir = null;
function getExportParams(&$error_msg) {
$this->form_prefix = $_REQUEST['form_prefix'];
if (empty($this->form_prefix)) {
$error_msg = 'The form prefix is empty!';
return false;
} else {
$form_prefix = $this->form_prefix;
}
if (!empty($_REQUEST[$form_prefix . '_exportsource']))
$this->export_source = urldecode($_REQUEST[$form_prefix . '_exportsource']);
if (!empty($_REQUEST[$form_prefix . '_exporttype']))
$this->export_type = $_REQUEST[$form_prefix . '_exporttype'];
if (!empty($_REQUEST[$form_prefix . '_exportoutput']))
$this->export_output = $_REQUEST[$form_prefix . '_exportoutput'];
if (!empty($_REQUEST[$form_prefix . '_exportdata'])) {
$this->export_data = urldecode($_REQUEST[$form_prefix . '_exportdata']);
// handle magic quotes
if (get_magic_quotes_gpc()) {
$this->export_data = stripslashes($this->export_data);
}
}
if (!empty($_REQUEST[$form_prefix . '_exportfile'])) {
$this->export_filename = urldecode($_REQUEST[$form_prefix . '_exportfile']);
}
if (!empty($_REQUEST[$form_prefix . '_datasourcetag'])) {
TabulizerPath::requireLib('data_source','common');
$data_source_tag = $_REQUEST[$form_prefix . '_datasourcetag'];
$data_source_user_params = $_REQUEST[$form_prefix . '_dsuserparams'];
// get header row(s) first
$errors = array();
$params = null;
$search_filters = array();
$results = TabulizerDataSource::getDataSourceContents($data_source_tag, $data_source_user_params, $search_filters, $params, $errors);
if (empty($results)) {
$this->export_data = $error_msg;
} else {
$delimiter = ',';
// open raw memory as file, no need for temp files, be careful not to run out of memory thought */
$f = fopen('php://memory', 'w');
foreach ($results['rows'] as $line) {
fputcsv($f, $line, $delimiter);
}
// rewind the "file" with the csv lines
fseek($f, 0);
$this->export_data = stream_get_contents($f);
}
// now, get the rest of the data
$server_side = empty($params['server_side'])?false:true;
if ($server_side) {
// now, get the rest of the data
$results = $this->getFilteredServerSideData($data_source_tag, $data_source_user_params, $error_msg);
if (empty($results)) {
$this->export_data = $error_msg;
} else {
$delimiter = ',';
// open raw memory as file, no need for temp files, be careful not to run out of memory thought */
$f = fopen('php://memory', 'w');
foreach ($results['rows'] as $line) {
fputcsv($f, $line, $delimiter);
}
// rewind the "file" with the csv lines
fseek($f, 0);
$this->export_data .= stream_get_contents($f);
}
} else {
$errors = array();
$params = null;
$search_filters = array('all'=>1);
$results = TabulizerDataSource::getDataSourceContents($data_source_tag, $data_source_user_params, $search_filters, $params, $errors);
if (empty($results)) {
$this->export_data = $error_msg;
} else {
$delimiter = ',';
// open raw memory as file, no need for temp files, be careful not to run out of memory thought */
$f = fopen('php://memory', 'w');
foreach ($results['rows'] as $line) {
fputcsv($f, $line, $delimiter);
}
// rewind the "file" with the csv lines
fseek($f, 0);
$this->export_data .= stream_get_contents($f);
}
}
}
$email_export_permissions = TabulizerPermissions::getExportDataPermissions();
$allow_recipients = $email_export_permissions['allow_recipients'];
$allow_subject = $email_export_permissions['allow_subject'];
$allow_body = $email_export_permissions['allow_body'];
if (!empty($_REQUEST[$form_prefix . '_exportemail_recipients']) && $allow_recipients) {
$this->export_email_recipients = urldecode($_REQUEST[$form_prefix . '_exportemail_recipients']);
$recipients = explode(',',$this->export_email_recipients);
$this->export_email_recipients = array();
$regex = '/^[-0-9a-zA-Z.+_]+@[-0-9a-zA-Z.+_]+\.[a-zA-Z]{2,4}$/i';
if (!empty($recipients)) {
foreach ($recipients as $recipient) {
$recipient = trim($recipient);
if (preg_match($regex, $recipient)) $this->export_email_recipients[] = $recipient;
if (count($this->export_email_recipients)>EXPORT_TABLE_EMAIL_RECIPIENTS_MAX_NUM) break;
}
}
}
if (!empty($_REQUEST[$form_prefix . '_exportemail_subject']) && $allow_subject) {
$this->export_email_subject = urldecode($_REQUEST[$form_prefix . '_exportemail_subject']);
// handle magic quotes
if (get_magic_quotes_gpc()) {
$this->export_email_subject = stripslashes($this->export_email_subject);
}
if (mb_strlen($this->export_email_subject)>EXPORT_TABLE_EMAIL_SUBJECT_MAX_SIZE) $this->export_email_subject = mb_substr($this->export_email_subject,0,EXPORT_TABLE_EMAIL_SUBJECT_MAX_SIZE);
}
if (!empty($_REQUEST[$form_prefix . '_exportemail_body']) && $allow_body) {
$this->export_email_body = urldecode($_REQUEST[$form_prefix . '_exportemail_body']);
// handle magic quotes
if (get_magic_quotes_gpc()) {
$this->export_email_body = stripslashes($this->export_email_body);
}
if (mb_strlen($this->export_email_body)>EXPORT_TABLE_EMAIL_BODY_MAX_SIZE) $this->export_email_body = mb_substr($this->export_email_body,0,EXPORT_TABLE_EMAIL_BODY_MAX_SIZE);
}
$this->export_dir = TabulizerPath::getDirPath('temp');
// do some sanity checks on filename, if present
if (!empty($this->export_filename)) {
$filename_pattern = '/^([a-z0-9_\.]{2,128})$/i';
if (!preg_match($filename_pattern, $this->export_filename)) {
$error_msg = "Invalid filename {$this->export_filename} for the temporary export file!";
return false;
}
$export_filename = $this->export_dir . $this->export_filename;
if (!file_exists($export_filename)) {
$error_msg = "Temporary export file not found or could not be opened!";
return false;
}
$this->export_data = file_get_contents($export_filename);
if (empty($this->export_data)) {
$error_msg = "Temporary export file contained no data!";
return false;
}
}
return true;
}
function removeExportFile() {
$export_filename = $this->export_dir . $this->export_filename;
if (file_exists($export_filename)) {
@unlink($export_filename);
return true;
} else return false;
}
function getFilteredServerSideData($data_source_tag, $data_source_user_params, &$error_msg) {
TabulizerPath::requireLib('tabulizer','common');
$tab = new Tabulizer();
TabulizerPath::requireLib('server_side','common');
$server_side_helper = new ServerSideHelper($data_source_tag, $data_source_user_params);
$server_side_helper->getQueryParams($server_side_query);
$errors = array();
$params = null;
$search_filters = null;
if (!empty($server_side_query)) {
// see if you can avoid reading all data
if (empty($server_side_query['search']) && (empty($server_side_query['order_by']))) {
if (!empty($server_side_query['pagination'])) {
if (isset($server_side_query['pagination']['limit'])) {
$limit_start = (isset($server_side_query['pagination']['limit_start']))?$server_side_query['pagination']['limit_start']:0;
$limit = $server_side_query['pagination']['limit'];
$search_filters['limit_start'] = $limit_start;
$search_filters['limit'] = $limit;
}
}
} else {
$search_filters['all'] = 1;
}
TabulizerPath::requireLib('data_source','common');
$results = TabulizerDataSource::getDataSourceContents($data_source_tag, $data_source_user_params, $search_filters, $params, $errors);
if (empty($results)) {
$error_msg = JText::_('COM_TABULIZER_DATA_SOURCE_ERROR_CAPTION');
return false;
} else {
if (!empty($params['consistency'])) $tab->setColumnConsistency(true);
$rows = &$results['rows'];
$total_records = $results['total_rows'];
$total_display_records = $results['total_rows'];
$offset = 0;
$length = 0;
if (!empty($server_side_query['search'])) {
$unset_keys = array();
foreach ($rows as $row_id => $row) {
$found = true;
foreach ($server_side_query['search'] as $column_id => $search_options) {
$match_op = $search_options['match'];
if ($column_id == 'all') {
$search_string = implode('~',$row);
} else if (isset($row[$column_id])) {
$search_string = $row[$column_id];
} else {
$search_string = null;
}
if (isset($search_string)) {
$search_string = trim(strip_tags($search_string));
if ($search_string == '') $search_string = null;
}
if (isset($search_string)) {
if ($match_op == 'smart') {
// smart filtering - match all values that contain the search word
if (mb_stripos($search_string,$search_options['value'])===false) { $found = false; break; }
} else if ($match_op == 'start_with') {
if (mb_stripos($search_string,$search_options['value'])!==0) { $found = false; break; }
} else if ($match_op == 'exact') {
$search_value = $search_options['value'];
$search_string = trim(strip_tags($search_string));
if (mb_stripos($search_string,$search_value)===false) { $found = false; break; }
else {
$len1 = mb_strlen($search_string);
$len2 = mb_strlen($search_value);
if ($len1 != $len2) { $found = false; break; }
}
} else if ($match_op == 'numeric_int') {
if (is_numeric($search_string)) {
$search_string = intval($search_string);
if (!self::compareMatch($search_string, $search_options)) { $found = false; break; }
} else { $found = false; break; }
} else if ($match_op == 'numeric_period') {
$search_string = str_replace(',','',$search_string);
if (is_numeric($search_string)) {
$search_string = floatval($search_string);
if (!self::compareMatch($search_string, $search_options)) { $found = false; break; }
} else { $found = false; break; }
} else if ($match_op == 'numeric_comma') {
$search_string = str_replace(',','.',str_replace('.','',$search_string));
if (is_numeric($search_string)) {
$search_string = floatval($search_string);
if (!self::compareMatch($search_string, $search_options)) { $found = false; break; }
} else { $found = false; break; }
} else if ($match_op == 'date_auto') {
$search_string = strtotime($search_string);
if (($search_string === false)||($search_string===-1)) { $found = false; break; }
else {
if (!self::compareMatch($search_string, $search_options)) { $found = false; break; }
}
} else if ($match_op == 'date_ymd') {
$parts = preg_split('#[-\.\/\\/]+#',$search_string);
if (count($parts)==3) {
$search_string = strtotime($parts[0].'-'.$parts[1].'-'.$parts[2]);
if (($search_string === false)||($search_string===-1)) { $found = false; break; }
else {
if (!self::compareMatch($search_string, $search_options)) { $found = false; break; }
}
} else { $found = false; break; }
} else if ($match_op == 'date_ydm') {
$parts = preg_split('#[-\.\/\\/]+#',$search_string);
if (count($parts)==3) {
$search_string = strtotime($parts[0].'-'.$parts[2].'-'.$parts[1]);
if (($search_string === false)||($search_string===-1)) { $found = false; break; }
else {
if (!self::compareMatch($search_string, $search_options)) { $found = false; break; }
}
} else { $found = false; break; }
} else if ($match_op == 'date_dmy') {
$parts = preg_split('#[-\.\/\\/]+#',$search_string);
if (count($parts)==3) {
$search_string = strtotime($parts[2].'-'.$parts[1].'-'.$parts[0]);
if (($search_string === false)||($search_string===-1)) { $found = false; break; }
else {
if (!self::compareMatch($search_string, $search_options)) { $found = false; break; }
}
} else { $found = false; break; }
} else if ($match_op == 'date_mdy') {
$parts = preg_split('#[-\.\/\\/]+#',$search_string);
if (count($parts)==3) {
$search_string = strtotime($parts[2].'-'.$parts[0].'-'.$parts[1]);
if (($search_string === false)||($search_string===-1)) { $found = false; break; }
else {
if (!self::compareMatch($search_string, $search_options)) { $found = false; break; }
}
} else { $found = false; break; }
} else {
// smart filtering - match all values that contain the search word
if (mb_stripos($search_string,$search_value)===false) { $found = false; break; }
}
} else {
// do not match empty values
$found = false;
}
}
if (!$found) $unset_keys[] = $row_id;
}
if (!empty($unset_keys)) {
foreach ($unset_keys as $row_id) {
unset($rows[$row_id]);
}
}
$total_display_records = count($rows);
}
if (!empty($server_side_query['order_by'])) {
$sort_helper = new SortingRowsHelper();
$sort_helper->setOrder($server_side_query['order_by']['column_id'], $server_side_query['order_by']['dir']);
usort($rows, array($sort_helper, 'compare'));
}
if (!empty($server_side_query['pagination'])) {
if (isset($server_side_query['pagination']['limit_start'])) {
$offset = $server_side_query['pagination']['limit_start'];
} else {
$offset = 0;
}
if (isset($server_side_query['pagination']['limit'])) {
$length = $server_side_query['pagination']['limit'];
if ($length == 'all') $length= count($rows);
} else {
$length = null;
}
}
if (!empty($length)) {
if (isset($search_filters['all'])) {
$lower_limit = $offset;
$upper_limit = $offset + $length;
$unset_keys = array();
$row_counter = 0;
foreach ($rows as $row_id => $row) {
if (($row_counter<$lower_limit)||($row_counter>$upper_limit)) {
$unset_keys[] = $row_id ;
}
$row_counter++;
}
if (!empty($unset_keys)) {
foreach ($unset_keys as $row_id) {
unset($rows[$row_id]);
}
}
}
if (count($rows)) {
$server_data = array('rows'=>$rows);
return $server_data;
} else {
$error_msg = JText::_('COM_TABULIZER_DATA_TABLE_FILTERING_RETURNED_ZERO_RECORDS');
return false;
}
} else {
$error_msg = JText::_('COM_TABULIZER_SERVER_SIDE_PAGINATION_IS_MISSING');
return false;
}
}
} else {
$error_msg = JText::_('COM_TABULIZER_SERVER_SIDE_QUERY_IS_MISSING');
return false;
}
return false;
}
function getExportData(&$error_msg) {
// remove temporary export file, its contents are already copied to export_data variable
$this->removeExportFile();
switch ($this->export_type) {
case 'csv': $content_type = 'text/csv'; break;
case 'xls': $content_type = 'application/vnd.ms-excel'; break;
case 'xlsx': $content_type = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'; break;
case 'pdf': $content_type = 'application/pdf'; break;
case 'png': $content_type = 'image/png'; break;
case 'jpg': $content_type = 'image/jpeg'; break;
case 'gif': $content_type = 'image/gif'; break;
default:
$error_msg = "Unknown export type {$this->export_type}!";
return false;
break;
}
header('Set-Cookie: fileDownload=true; path=/');
header('Cache-Control: max-age=60, must-revalidate');
header("Content-type: {$content_type}");
header('Content-Disposition: attachment; filename="'.$this->export_filename.'"');
//header("Pragma: no-cache");
//header("Expires: 0");
jexit($this->export_data);
return true;
}
function num2alpha($n) {
$r = '';
for ($i = 1; $n >= 0 && $i < 10; $i++) {
$r = chr(0x41 + ($n % pow(26, $i) / pow(26, $i - 1))) . $r;
$n -= pow(26, $i);
}
return $r;
}
function getExcelCoord($row_id, $column_id) {
$column_alpha = $this->num2alpha($column_id-1);
return $column_alpha . $row_id;
}
function cvs2Table($contents) {
$rows = array();
$lines = explode("\n",$contents);
foreach ($lines as $line) {
if ($line != '') {
$row = TabulizerString::my_str_getcsv( $line, ',', '"');
$rows[] = $row;
}
}
return $rows;
}
function saveExportData(&$error_msg) {
switch ($this->export_type) {
case 'csv':
$this->export_filename = 'table_' . rand() . '_' . time() . '.csv';
$export_data = $this->export_data;
$export_filename = $this->export_dir . $this->export_filename;
if (file_put_contents($export_filename, $export_data)) {
return true;
} else {
$error_msg = sprintf(JText::_('COM_TABULIZER_EXPORT_ERROR_CANNOT_WRITE_EXPORT_FILE'), $this->export_dir);
return false;
}
break;
case 'xls':
case 'xlsx':
case 'pdf':
# Include path
$phpexcel_path = TabulizerPath::getDirPath('phpexcel');
set_include_path(get_include_path() . PATH_SEPARATOR . $phpexcel_path);
# PHPExcel_IOFactory
require_once($phpexcel_path.DIRECTORY_SEPARATOR.'IOFactory.php');
$this->export_filename = 'table_' . rand() . '_' . time() . '.'.$this->export_type;
$export_data = $this->export_data;
$export_filename = $this->export_dir . $this->export_filename;
$objPHPExcel = new PHPExcel();
$objPHPExcel->getActiveSheet()->setTitle('Table');
$rows = $this->cvs2Table($export_data);
foreach ($rows as $row_id => $row) {
foreach ($row as $column_id => $cell) {
$cell_coord = $this->getExcelCoord($row_id+1, $column_id+1);
$objPHPExcel->getActiveSheet()->setCellValue($cell_coord, $cell);
}
}
switch ($this->export_type) {
case 'xls': $outputFileType = 'Excel5'; break;
case 'xlsx': $outputFileType = 'Excel2007'; break;
case 'pdf':
$rendererName = PHPExcel_Settings::PDF_RENDERER_DOMPDF;
$rendererLibraryPath = TabulizerPath::getDirPath('dompdf');
if ($rendererLibraryPath) {
set_include_path(get_include_path() . PATH_SEPARATOR . $rendererLibraryPath);
if (!PHPExcel_Settings::setPdfRenderer(
$rendererName,
$rendererLibraryPath
)) {
$error_msg = JText::_('COM_TABULIZER_EXPORT_TABLE_PDF_LIBRARY_MISSING');
return false;
}
} else {
$error_msg = JText::_('COM_TABULIZER_EXPORT_TABLE_PDF_LIBRARY_MISSING');
return false;
}
$outputFileType = 'PDF';
$objPHPExcel->getActiveSheet(0)->getPageSetup()->setOrientation(PHPExcel_Worksheet_PageSetup::ORIENTATION_LANDSCAPE);
$objPHPExcel->getActiveSheet(0)->getPageSetup()->setPaperSize(PHPExcel_Worksheet_PageSetup::PAPERSIZE_A4);
$objPHPExcel->getActiveSheet(0)->getPageSetup()->setFitToWidth(true);
$objPHPExcel->getActiveSheet(0)->getPageSetup()->setFitToHeight(true);
$objPHPExcel->getActiveSheet(0)->setShowGridlines(false);
break;
}
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, $outputFileType);
$objWriter->save($export_filename);
return true;
break;
case 'png':
$this->export_filename = 'graph_' . rand() . '_' . time() . '.png';
$export_data = str_replace(' ', '+', str_replace('data:image/png;base64,','',$this->export_data));
$export_data = base64_decode($export_data);
$export_filename = $this->export_dir . $this->export_filename;
if (file_put_contents($export_filename, $export_data)) {
return true;
} else {
$error_msg = sprintf(JText::_('COM_TABULIZER_EXPORT_ERROR_CANNOT_WRITE_EXPORT_FILE'), $this->export_dir);
return false;
}
break;
case 'jpg':
// save the image first as png
$tmp_filename = $this->export_dir . 'graph_' . rand() . '_' . time() . '.png';
$export_data = str_replace(' ', '+', str_replace('data:image/png;base64,','',$this->export_data));
$export_data = base64_decode($export_data);
if (file_put_contents($tmp_filename, $export_data)) {
$image = imagecreatefrompng($tmp_filename);
$bg = imagecreatetruecolor(imagesx($image), imagesy($image));
imagefill($bg, 0, 0, imagecolorallocate($bg, 255, 255, 255));
imagealphablending($bg, TRUE);
imagecopy($bg, $image, 0, 0, 0, 0, imagesx($image), imagesy($image));
imagedestroy($image);
$quality = EXPORT_TABLE_IMAGE_QUALITY;
$this->export_filename = 'graph_' . rand() . '_' . time() . '.jpg';
$export_filename = $this->export_dir . $this->export_filename;
imagejpeg($bg, $export_filename, $quality);
ImageDestroy($bg);
@unlink($tmp_filename);
return true;
} else {
$error_msg = sprintf(JText::_('COM_TABULIZER_EXPORT_ERROR_CANNOT_WRITE_EXPORT_FILE'), $this->export_dir);
return false;
}
break;
case 'gif':
// save the image first as png
$tmp_filename = $this->export_dir . 'graph_' . rand() . '_' . time() . '.png';
$export_data = str_replace(' ', '+', str_replace('data:image/png;base64,','',$this->export_data));
$export_data = base64_decode($export_data);
if (file_put_contents($tmp_filename, $export_data)) {
$image = imagecreatefrompng($tmp_filename);
$this->export_filename = 'graph_' . rand() . '_' . time() . '.gif';
$export_filename = $this->export_dir . $this->export_filename;
imagegif($image, $export_filename);
imagedestroy($image);
@unlink($tmp_filename);
return true;
} else {
$error_msg = sprintf(JText::_('COM_TABULIZER_EXPORT_ERROR_CANNOT_WRITE_EXPORT_FILE'), $this->export_dir);
return false;
}
break;
default:
$error_msg = "Unknown export type {$this->export_type}!";
return false;
break;
}
}
function emailExportData(&$error_msg) {
$mailer = JFactory::getMailer();
// set sender
$sender_info = TabulizerInfo::getMailSenderInfo();
$sender = array( $sender_info['email'], $sender_info['name']);
$mailer->setSender($sender);
// set recipient
if (empty($this->export_email_recipients)) {
$user = JFactory::getUser();
if ($user->guest) {
$error_msg = JText::_('COM_TABULIZER_EXPORT_ERROR_USER_NOT_LOGGED_IN');
$this->removeExportFile();
return false;
}
$this->export_email_recipients = array($user->email);
}
$mailer->addRecipient($this->export_email_recipients);
$export_filename = $this->export_dir . $this->export_filename;
switch ($this->export_type) {
case 'csv':
case 'xls':
case 'xlsx':
case 'pdf':
$subject = empty($this->export_email_subject)?JText::_('COM_TABULIZER_EXPORT_TABLE_EMAIL_SUBJECT'):$this->export_email_subject;
$body_text = empty($this->export_email_body)?JText::_('COM_TABULIZER_EXPORT_TABLE_EMAIL_BODY'):$this->export_email_body;
$body = '<div>'.$body_text.'<br/></div>';
// Attach file
$mailer->addAttachment($export_filename);
break;
case 'png':
case 'jpg':
case 'gif':
$subject = empty($this->export_email_subject)?JText::_('COM_TABULIZER_EXPORT_IMAGE_EMAIL_SUBJECT'):$this->export_email_subject;
$body_text = empty($this->export_email_body)?JText::_('COM_TABULIZER_EXPORT_IMAGE_EMAIL_BODY'):$this->export_email_body;
$body = '<div>'.$body_text.'<br/><br/>'
. '<img src="cid:graph_id" alt="Table Graph"/></div>';
// Add embedded image
$image_type = ($this->export_type == 'jpg')?'jpeg':$this->export_type;
$mailer->AddEmbeddedImage($export_filename, 'graph_id', $this->export_filename, 'base64', 'image/'.$image_type );
break;
default:
$error_msg = "Unknown export type {$this->export_type}!";
$this->removeExportFile();
return false;
break;
}
$mailer->setSubject($subject);
$mailer->setBody($body);
$mailer->isHTML(true);
$mailer->Encoding = 'base64';
$send = $mailer->Send();
if ( $send !== true ) {
$error_msg = JText::_('COM_TABULIZER_EXPORT_ERROR_COULD_NOT_SEND_EMAIL');
$this->removeExportFile();
return false;
}
$this->removeExportFile();
return true;
}
function outputJSON($user_data, $error_flag) {
if ($error_flag) {
$output = $user_data;
} else {
$output = json_encode($user_data);
}
jexit($output);
}
function outputFile($user_msg, $error_flag = true) {
if (!$error_flag) {
header('Set-Cookie: fileDownload=true; path=/');
}
header('Cache-Control: max-age=60, must-revalidate');
header("Content-Type: text/html; charset=utf-8");
jexit($user_msg);
}
function processRequest() {
// get export params
if (!$this->getExportParams($error_msg)) {
if (empty($this->export_filename)) {
$this->outputJSON($error_msg, true);
} else {
$this->outputFile($error_msg, true);
}
return false;
}
// see if filename is set
if (empty($this->export_filename)) {
if (!$this->saveExportData($error_msg)) {
$this->outputJSON($error_msg, true);
return false;
} else {
$this->outputJSON(array('filename_tmp' => $this->export_filename), false);
return true;
}
} else {
if ($this->export_output == 'email') {
if (!$this->emailExportData($error_msg)) {
$this->outputFile($error_msg, true);
return false;
} else {
$this->outputFile(JText::_('COM_TABULIZER_EXPORT_EMAIL_SUCCESS_MESSAGE'), false);
}
} else {
if (!$this->getExportData($error_msg)) {
$this->outputFile($error_msg, true);
return false;
}
}
}
return true;
}
}
$export_controller = new ExportData();
$export_controller->processRequest();
?>

View File

@ -0,0 +1,22 @@
<?php
/**
* @version 6.2.6 tabulizer $
* @package tabulizer
* @copyright Copyright © 2011 - All rights reserved.
* @license GNU/GPL
* @author Dimitrios Mourloukos
* @author mail info@alterora.gr
* @website www.tabulizer.com
*
*/
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
TabulizerPath::requireLib('csv_extraction','common');
$extractor = new CSVExtraction();
$extractor->processJSON();
?>

View File

@ -0,0 +1,22 @@
<?php
/**
* @version 6.2.6 tabulizer $
* @package tabulizer
* @copyright Copyright © 2011 - All rights reserved.
* @license GNU/GPL
* @author Dimitrios Mourloukos
* @author mail info@alterora.gr
* @website www.tabulizer.com
*
*/
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
TabulizerPath::requireLib('excel_extraction','common');
$extractor = new ExcelExtraction();
$extractor->processJSON();
?>

View File

@ -0,0 +1,22 @@
<?php
/**
* @version 6.2.6 tabulizer $
* @package tabulizer
* @copyright Copyright © 2011 - All rights reserved.
* @license GNU/GPL
* @author Dimitrios Mourloukos
* @author mail info@alterora.gr
* @website www.tabulizer.com
*
*/
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
TabulizerPath::requireLib('grid_data_extraction','common');
$extractor = new GridDataExtraction();
$extractor->processJSON();
?>

View File

@ -0,0 +1,569 @@
<?php
/**
* @version 6.2.6 tabulizer $
* @package tabulizer
* @copyright Copyright © 2011 - All rights reserved.
* @license GNU/GPL
* @author Dimitrios Mourloukos
* @author mail info@alterora.gr
* @website www.tabulizer.com
*
*/
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
class TableExtraction {
var $contents = null;
var $caret_position = null;
function getInput(&$error_msg) {
if (isset($_REQUEST['editor_content'])) {
$this->contents = $_REQUEST['editor_content'];
// remove unwanted slashes when magin quotes is on
if (get_magic_quotes_gpc()) {
$this->contents = stripslashes($this->contents);
}
// remove unwanted carriage return chars
$rcount = 0;
$offset = 0;
$pos = mb_strpos ( $this->contents, "\r\n", $offset);
while ($pos) {
$rcount++;
$offset = $pos + 2;
$pos = mb_strpos ( $this->contents, "\r\n", $offset);
}
if ($rcount) {
$this->contents = str_replace("\r\n","\n",$this->contents);
}
}
if (isset($_REQUEST['caret_position'])) {
$this->caret_position = $_REQUEST['caret_position'];
if (get_magic_quotes_gpc()) {
$this->caret_position = stripslashes($this->caret_position);
}
$this->caret_position = intval($this->caret_position);
}
if (empty($this->contents) || empty($this->caret_position)) {
$error_msg = JText::_('COM_TABULIZER_INVALID_TABLE_SELECTION');
return false;
} else return true;
}
function verifyPHPLibraries(&$error_msg) {
if (!function_exists('libxml_use_internal_errors')) {
$error_msg = sprintf(JText::_('COM_TABULIZER_XML_PARSER_MISSING'), 'libxml_use_internal_errors');
return false;
}
return true;
}
function process() {
$error_msg = null;
if ($this->verifyPHPLibraries($error_msg)) {
$this->getInput($error_msg);
}
if (!$error_msg) {
$extracted_data = array('table_caption'=>null, 'table_text'=>null, 'column_separator'=>null, 'column_enclosure'=>null, 'ruleset_archive'=>null, 'ruleset_name'=>null, 'range_from'=>null, 'range_to'=>null, 'error_msg'=>null);
if ($this->extractTableData($extracted_data)) {
$this->outputData($extracted_data);
} else {
$this->outputError($extracted_data['error_msg']);
}
} else {
$this->outputError($error_msg);
}
}
function extractTableRowsAndColumns($rows, &$extracted_data) {
$table_array = array();
$cell_values = array();
$row_id = 0;
$sort_keys_flag = false;
foreach ($rows as $row) {
$row_id++;
if (empty($table_array[$row_id])) {
$table_array[$row_id] = array();
}
$column_id = 0;
foreach ($row as $cell) {
$column_id++;
while (isset($table_array[$row_id][$column_id])) $column_id++;
$cell_value = str_replace("\n",'', $cell['value']);
$table_array[$row_id][$column_id] = $cell_value;
$cell_values[] = $cell_value;
if ((!empty($cell['colspan'])) && (!empty($cell['rowspan']))) {
$rowspan = $cell['rowspan'];
$colspan = $cell['colspan'];
for ($i=0;$i<$rowspan;$i++) {
$row_id_span = $row_id + $i;
if (empty($table_array[$row_id_span])) $table_array[$row_id_span] = array();
for ($j=0;$j<$colspan;$j++) {
$column_id_span = $column_id + $j;
$table_array[$row_id_span][$column_id_span] = '';
}
}
$table_array[$row_id][$column_id] = $cell_value;
$column_id += $colspan;
$sort_keys_flag = true;
} else if (!empty($cell['colspan'])) {
$span = $cell['colspan'];
for ($i=1;$i<$span;$i++) {
$column_id++;
$table_array[$row_id][$column_id] = '';
}
} else if (!empty($cell['rowspan'])) {
$span = $cell['rowspan'];
for ($i=1;$i<$span;$i++) {
$row_id_span = $row_id + $i;
if (empty($table_array[$row_id_span])) $table_array[$row_id_span] = array();
$table_array[$row_id_span][$column_id] = '';
}
$sort_keys_flag = true;
}
}
}
$column_separator_found = false;
if (empty($cell_values)) {
$extracted_data['error_msg'] = JText::_('COM_TABULIZER_INVALID_TABLE_SELECTION');
return false;
} else {
$separators = TabulizerUtils::getSeparatorList(true);
foreach ($separators as $sep => $column_separator) {
$valid = true;
foreach ($cell_values as $value) {
if (empty($value)) continue;
if (strpos($value,$sep) !== false) { $valid = false; break; }
}
if ($valid) {
$column_separator_found = true;
break;
}
}
}
# use text enclosure, if needed
if (!$column_separator_found) {
$column_separator = SEPARATOR_COMMA;
$column_enclosure = ENCLOSURE_DOUBLE_QUOTES;
$sep = ',';
$enclosure = '"';
$escape = ENCLOSURE_ESCAPE;
} else {
$column_enclosure = ENCLOSURE_NONE;
$enclosure = '';
}
$sep = $enclosure . $sep . $enclosure;
$current_count = 0;
$column_count = 0;
$table_text = '';
foreach ($table_array as $row_id => $cells) {
// sort array keys is needed, in case you have used colspan or rowspan
if ($sort_keys_flag) {
ksort($cells);
}
$current_count = count($cells);
if (empty($column_count)) $column_count = $current_count;
else if ($column_count != $current_count) {
$extracted_data['error_msg'] = JText::_('COM_TABULIZER_INVALID_TABLE_SELECTION');
return false;
}
if ($column_enclosure != ENCLOSURE_NONE) {
$ra = $escape . $enclosure;
$rw = $enclosure;
foreach ($cells as &$cell) {
$cell = str_replace($rw, $ra, $cell);
}
}
$table_text .= $enclosure. implode($sep,$cells) . $enclosure . "\n";
}
$extracted_data['table_text'] = $table_text;
$extracted_data['column_separator'] = $column_separator;
$extracted_data['column_enclosure'] = $column_enclosure;
return true;
}
function extractTableData(&$extracted_data) {
$contents = $this->contents;
$caret_position = $this->caret_position;
$table_caption = '';
$ruleset_archive = '';
$ruleset_name = '';
# search for table limits
$range = array();
$range_stack = array();
$table_ranges = array();
$pos = mb_stripos($contents, '<table');
while ($pos !== false) {
$range[$pos] = 'open';
$pos = mb_stripos($contents, '<table', $pos + 6);
}
$pos = mb_stripos($contents, '</table');
while ($pos !== false) {
$epos = mb_stripos($contents, '>', $pos + 7);
if ($epos) {
$range[$epos] = 'close';
$pos = mb_stripos($contents, '</table', $epos + 1);
} else {
$pos = false;
}
}
ksort($range);
foreach ($range as $key => $value) {
if ($value == 'open') {
$limit = $key;
array_push($range_stack, $limit);
} else {
$limit = array_pop($range_stack);
if ($limit !== false) {
$table_ranges[] = array('open' => $limit, 'close' => $key);
}
}
}
// check if you have an unclosed table
if (count($range_stack)) {
$limit = array_pop($range_stack);
$table_ranges[] = array('open' => $limit, 'close' => mb_strlen($contents) - 1);
}
$selected_range = array('from' => null, 'to' => null);
if (count($table_ranges)) {
foreach ($table_ranges as $table_range) {
$range_from = $table_range['open'];
$range_to = $table_range['close'];
if (($caret_position > $range_from) && ($caret_position < $range_to)) {
if (!isset($selected_range['from'])) {
$selected_range['from'] = $range_from;
$selected_range['to'] = $range_to;
} else if ($selected_range['from'] < $range_from) {
$selected_range['from'] = $range_from;
$selected_range['to'] = $range_to;
}
}
}
}
if ((!isset($selected_range['from']))||(!isset($selected_range['to']))) {
$extracted_data['error_msg'] = JText::_('COM_TABULIZER_INVALID_TABLE_SELECTION');
return false;
} else {
$range_from = $selected_range['from'];
$range_to = $selected_range['to'];
if ($range_to < $range_from) {
$extracted_data['error_msg'] = JText::_('COM_TABULIZER_INVALID_TABLE_SELECTION');
return false;
} else {
$range_len = $range_to - $range_from + 1;
$table_source = mb_substr ( $contents, $range_from, $range_len );
}
}
# load and normalize table contents
$table_source = str_replace(array("\n", "\r"), " ", $table_source);
$rows = array();
# mourlouk note: DOMDocument is not bahaving correctly, try to solve this by using the following char conversion
$table_source = mb_convert_encoding($table_source, 'HTML-ENTITIES', 'UTF-8');
$dom = new DOMDocument();
libxml_use_internal_errors(true);
$dom->loadHTML('<?xml encoding="UTF-8">' . $table_source);
$table = $dom->getElementsByTagName('table')->item(0);
if ($table->hasAttribute('data-ruleset')) {
$data_ruleset = trim($table->getAttribute('data-ruleset'));
list($ruleset_archive, $ruleset_name) = explode(':',$data_ruleset);
}
$error_msg = null;
$user_preferences = TabulizerInfo::getUserPreferences($error_msg);
$remove_leftovers = $user_preferences['retabulize_remove_leftovers'];
if ($table->hasAttribute('id') && $remove_leftovers) {
$table_id = trim($table->getAttribute('id'));
$directive_pos_start = null;
$directive_pos_end = mb_stripos($contents, 'id['.$table_id.']}');
if ($directive_pos_end!==false) {
$pos_offset = 0;
$pos_start = mb_stripos($contents, '{tabulizer:', $pos_offset);
while ($pos_start !== false) {
if ($pos_start < $directive_pos_end) {
$directive_pos_start = $pos_start;
$pos_offset = $pos_start + 11;
$pos_start = mb_stripos($contents, '{tabulizer:', $pos_offset);
} else {
break;
}
}
}
if (!empty($directive_pos_start)) {
// try to locate unmatched HTML elements that will removed below the table
$above_area = mb_substr($contents, $directive_pos_end + 19, $range_from - $directive_pos_end - 19);
if (!empty($above_area)) {
$above_area = str_replace(array("\n", "\r"), " ", $above_area);
$above_area_len = mb_strlen($above_area);
$open_tags = array();
$open_tag = $close_tag = $append_tag = false;
$tag = '';
for ($i=0;$i<$above_area_len;$i++) {
$ch = mb_substr($above_area,$i,1);
$chn = ($i == ($above_area_len - 1))?' ':mb_substr($above_area,$i+1,1);
switch ($ch) {
case '<':
if ($chn != '/') {
$open_tag = true;
$append_tag = true;
$tag = '';
} else if ($chn == '/') {
$close_tag = true;
$append_tag = true;
$tag = '';
$i++;
}
break;
case '>':
if ($open_tag) {
$open_tags[] = strtolower($tag);
$open_tag = false;
} else if ($close_tag) {
$tag = strtolower($tag);
if (count($open_tags)) {
foreach ($open_tags as $ot_key => $ot_value) {
if ($ot_value == $tag) {
unset($open_tags[$ot_key]);
break;
}
}
}
$close_tag = false;
}
break;
default:
if (($open_tag || $close_tag)) {
if ($ch == ' ') $append_tag = false;
if ($append_tag) $tag .= $ch;
}
break;
}
}
if (count($open_tags)>0) {
$below_area = mb_substr($contents,$range_to+1);
$below_area_len = mb_strlen($below_area);
if ($below_area_len>0) {
for ($i=0;$i<$below_area_len;$i++) {
$ch = mb_substr($below_area,$i,1);
$chn = ($i == ($below_area_len - 1))?' ':mb_substr($below_area,$i+1,1);
switch ($ch) {
case '<':
if ($chn != '/') {
$open_tag = true;
$append_tag = true;
$tag = '';
} else if ($chn == '/') {
$close_tag = true;
$append_tag = true;
$tag = '';
$i++;
}
break;
case '>':
if ($open_tag) {
$open_tags[] = strtolower($tag);
$open_tag = false;
} else if ($close_tag) {
$tag = strtolower($tag);
if (count($open_tags)) {
foreach ($open_tags as $ot_key => $ot_value) {
if ($ot_value == $tag) {
unset($open_tags[$ot_key]);
break;
}
}
}
$close_tag = false;
// check if we are done
if (count($open_tags)==0) {
$range_to += $i + 1;
$i = $below_area_len;
}
}
break;
default:
if (($open_tag || $close_tag)) {
if ($ch == ' ') $append_tag = false;
if ($append_tag) $tag .= $ch;
}
break;
}
}
}
}
}
$range_from = $directive_pos_start;
}
}
/*
Tag Description
<table> Defines a table
<th> Defines a header cell in a table
<tr> Defines a row in a table
<td> Defines a cell in a table
<caption> Defines a table caption
<colgroup> Specifies a group of one or more columns in a table for formatting
<col> Specifies column properties for each column within a <colgroup> element
<thead> Groups the header content in a table
<tbody> Groups the body content in a table
<tfoot>
*/
$table_elements = array('head'=>array(),'body'=>array(),'foot'=>array());
foreach($table->childNodes as $node) {
if (is_object($node)) {
$nodeName = strtoupper($node->nodeName);
$table_section = null;
switch ($nodeName) {
case 'CAPTION': $table_caption = trim($node->nodeValue);
break;
case 'TBODY': if (empty($table_section)) $table_section = 'body';
case 'THEAD': if (empty($table_section)) $table_section = 'head';
case 'TFOOT': if (empty($table_section)) $table_section = 'foot';
foreach ($node->childNodes as $tr) {
if (is_object($tr)) {
$cells = array();
foreach ($tr->childNodes as $td) {
if (is_object($td)) {
$tdName = strtoupper($td->nodeName);
if (($tdName=='TD')||($tdName=='TH')) {
$cell = array('value' => $dom->saveXML($td));
if ($td->hasAttribute('colspan')) {
$cell['colspan'] = $td->getAttribute('colspan');
}
if ($td->hasAttribute('rowspan')) {
$cell['rowspan'] = $td->getAttribute('rowspan');
}
if (preg_match('/^<td([^>]*)>(.+)<\/td>$/si',$cell['value'],$matches)) $cell['value'] = trim($matches[2]);
else if (preg_match('/^<th([^>]*)>(.+)<\/th>$/si',$cell['value'],$matches)) $cell['value'] = trim($matches[2]);
$cells[] = $cell;
}
}
}
$table_elements[$table_section][] = $cells;
}
}
break;
case 'TR':
$table_section = 'body';
$tr = &$node;
$cells = array();
foreach ($tr->childNodes as $td) {
if (is_object($td)) {
$tdName = strtoupper($td->nodeName);
if (($tdName=='TD')||($tdName=='TH')) {
$cell = array('value' => $dom->saveXML($td));
if ($td->hasAttribute('colspan')) {
$cell['colspan'] = $td->getAttribute('colspan');
}
if ($td->hasAttribute('rowspan')) {
$cell['rowspan'] = $td->getAttribute('rowspan');
}
if (preg_match('/^<td([^>]*)>(.+)<\/td>$/si',$cell['value'],$matches)) $cell['value'] = trim($matches[2]);
else if (preg_match('/^<th([^>]*)>(.+)<\/th>$/si',$cell['value'],$matches)) $cell['value'] = trim($matches[2]);
$cells[] = $cell;
}
}
}
$table_elements[$table_section][] = $cells;
break;
default:
// CAPTION
// COLGROUP
// do nothing
break;
}
}
}
$extracted_data['range_from'] = $range_from;
$extracted_data['range_to'] = $range_to;
if (!empty($table_caption)) $extracted_data['table_caption'] = $table_caption;
if (!empty($ruleset_archive)) $extracted_data['ruleset_archive'] = $ruleset_archive;
if (!empty($ruleset_name)) $extracted_data['ruleset_name'] = $ruleset_name;
$rows = array();
foreach ($table_elements as $table_section => $table_rows) {
if (!empty($table_rows)) {
foreach ($table_rows as $table_row) {
if (!empty($table_row)) {
$rows[] = $table_row;
}
}
}
}
if ($rows) {
return $this->extractTableRowsAndColumns($rows, $extracted_data);
} else {
// no rows
return false;
}
}
//function outputData($table_caption, $table_text, $column_separator, $range_from, $range_to, $error_msg) {
function outputData($extracted_data) {
if (!empty($extracted_data['error_msg'])) {
$output = json_encode(array("error_msg" => $extracted_data['error_msg']));
} else {
$output_array = array();
$keys = array('table_caption','table_text','column_separator','column_enclosure','ruleset_archive','ruleset_name','range_from','range_to');
foreach ($keys as $key) {
if (isset($extracted_data[$key])) {
$output_array[$key] = $extracted_data[$key];
}
}
$output = json_encode($output_array);
}
jexit($output);
}
function outputError($error_msg) {
$output = json_encode(array("error_msg" => $error_msg));
jexit($output);
}
}
$form = new TableExtraction();
$form->process();
?>

View File

@ -0,0 +1,88 @@
<?php
/**
* @version 6.2.6 tabulizer $
* @package tabulizer
* @copyright Copyright © 2011 - All rights reserved.
* @license GNU/GPL
* @author Dimitrios Mourloukos
* @author mail info@alterora.gr
* @website www.tabulizer.com
*
*/
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
function grabTableData() {
$jinput = JFactory::getApplication()->input;
$params['filepath'] = $jinput->getString('grab_url','');
$params['table_order'] = $jinput->getString('grab_index','');
$params['table_attribute_name'] = $jinput->getString('grab_attr_name','');
$params['table_attribute_value'] = $jinput->getString('grab_attr_value','');
TabulizerPath::requireLib('html_extraction','common');
$grabber = new HTMLExtraction();
$grabber->getTableRows($rows, $params, $error_msg);
if (empty($error_msg)) {
$cell_values = array();
foreach ($rows as $row) {
$cell_values[] = implode('', $row);
}
$column_separator_found = false;
if (empty($cell_values)) {
$extracted_data['error_msg'] = JText::_('COM_TABULIZER_INVALID_TABLE_SELECTION');
return false;
} else {
$separators = TabulizerUtils::getSeparatorList(true);
foreach ($separators as $sep => $column_separator) {
$valid = true;
foreach ($cell_values as $value) {
if (empty($value)) continue;
if (strpos($value,$sep) !== false) { $valid = false; break; }
}
if ($valid) {
$column_separator_found = true;
break;
}
}
}
# use text enclosure, if needed
if (!$column_separator_found) {
$column_separator = SEPARATOR_COMMA;
$column_enclosure = ENCLOSURE_DOUBLE_QUOTES;
$sep = ',';
$enclosure = '"';
$escape = ENCLOSURE_ESCAPE;
} else {
$column_enclosure = ENCLOSURE_NONE;
$enclosure = '';
}
$sep = $enclosure . $sep . $enclosure;
$table_text = '';
foreach ($rows as $row_id => $cells) {
if ($column_enclosure != ENCLOSURE_NONE) {
$ra = $escape . $enclosure;
$rw = $enclosure;
foreach ($cells as &$cell) {
$cell = str_replace($rw, $ra, $cell);
}
}
$table_text .= $enclosure. implode($sep,$cells) . $enclosure . "\n";
}
$json_response = json_encode(array('input_text'=>$table_text, 'input_separator'=>$column_separator, 'input_enclosure'=>$column_enclosure));
jexit($json_response);
} else {
jexit($error_msg);
}
}
grabTableData();
?>

View File

@ -0,0 +1,4 @@
<html>
<body bgcolor="#FFFFFF">
</body>
</html>

View File

@ -0,0 +1,22 @@
<?php
/**
* @version 6.2.6 tabulizer $
* @package tabulizer
* @copyright Copyright © 2011 - All rights reserved.
* @license GNU/GPL
* @author Dimitrios Mourloukos
* @author mail info@alterora.gr
* @website www.tabulizer.com
*
*/
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
TabulizerPath::requireLib('grid_data_save','common');
$extractor = new GridDataSave();
$extractor->processJSON();
?>

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,126 @@
<?php
/**
* @version 6.2.6 tabulizer $
* @package tabulizer
* @copyright Copyright © 2011 - All rights reserved.
* @license GNU/GPL
* @author Dimitrios Mourloukos
* @author mail info@alterora.gr
* @website www.tabulizer.com
*
*/
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
class CSVUploader {
function file_upload_error_message($error_code) {
$error_msg = '';
switch ($error_code) {
case UPLOAD_ERR_INI_SIZE:
$error_msg = JText::_('COM_TABULIZER_UPLOAD_ERR_INI_SIZE');
case UPLOAD_ERR_FORM_SIZE:
$error_msg = JText::_('COM_TABULIZER_UPLOAD_ERR_FORM_SIZE');
case UPLOAD_ERR_PARTIAL:
$error_msg = JText::_('COM_TABULIZER_UPLOAD_ERR_PARTIAL');
case UPLOAD_ERR_NO_FILE:
$error_msg = JText::_('COM_TABULIZER_UPLOAD_ERR_NO_FILE');
case UPLOAD_ERR_NO_TMP_DIR:
$error_msg = JText::_('COM_TABULIZER_Missing a temporary folder');
case UPLOAD_ERR_CANT_WRITE:
$error_msg = JText::_('COM_TABULIZER_UPLOAD_ERR_CANT_WRITE');
case UPLOAD_ERR_EXTENSION:
$error_msg = JText::_('COM_TABULIZER_UPLOAD_ERR_EXTENSION');
default:
$error_msg = 'Unknown upload error';
}
return $error_msg;
}
function verifyUploadedFile(&$csv_filename, &$error_msg) {
$jinput = JFactory::getApplication()->input;
$uploaded_fieldname = 'csv_file';
$file = $jinput->files->get($uploaded_fieldname);
foreach ($file as $key => &$value) {
$value = trim(str_replace('&gt;','',$value));
}
if ($file["error"] > 0) {
$error_msg = sprintf(JText::_('COM_TABULIZER_CSV_UPLOAD_FAILED'),$this->file_upload_error_message($file["error"]));
return false;
} else {
$uploaded_filename = $file['name'];
$uploaded_file = $file['tmp_name'];
$uploaded_size = $file["size"];
$uploaded_type = strtolower($file["type"]);
# sanity checks
// 1. File size
if ($uploaded_size > MAX_UPLOAD_CSV_FILE_SIZE) {
$error_msg = sprintf(JText::_('COM_TABULIZER_CSV_UPLOAD_INVALID_FILE_SIZE'),MAX_UPLOAD_CSV_FILE_SIZE);
return false;
}
// 2. File type
/*
// Note: the official mine type is 'application/vnd.ms-excel' but each browser could set it's own variation
// We decided to comment this check, because it's easily bypassed by changing the extension (xls), which is already checked at the client side.
$valid_mime_types = array('application/vnd.ms-excel', 'application/msexcel', 'application/x-msexcel', 'application/x-ms-excel', 'application/x-excel', 'application/x-dos_ms_excel', 'application/xls', 'application/octet-stream');
if (!in_array($uploaded_type, $valid_mime_types)) {
$error_msg = sprintf(JText::_('COM_TABULIZER_SHEET_UPLOAD_INVALID_FILE_TYPE'), $uploaded_type);
return false;
}
*/
// 3. File extension
$path_parts = pathinfo($uploaded_filename);
$filename_ext = strtolower($path_parts['extension']);
$valid_extensions = array('csv','txt','text');
if (!in_array($filename_ext, $valid_extensions)) {
$error_msg = sprintf(JText::_('COM_TABULIZER_CSV_UPLOAD_INVALID_FILE_EXT'), $filename_ext);
return false;
}
# Copy file to temp dir
$import_hash = time() . mt_rand();
$csv_filename = 'csv' . $import_hash . '.utemp.'. $filename_ext;
$temp_filename_path = TabulizerPath::getFilePath($csv_filename, 'temp');
if(!move_uploaded_file($uploaded_file, $temp_filename_path)) {
$error_msg = sprintf(JText::_('COM_TABULIZER_CSV_UPLOAD_MOVE_FAILED'), $temp_filename_path);
return false;
}
}
return true;
}
function process() {
$error_msg = null;
$sheet_filename = null;
if ($this->verifyUploadedFile($sheet_filename, $error_msg)) {
$this->outputData($sheet_filename, $error_msg);
} else {
$this->outputData(null, $error_msg);
}
}
function outputData($filename, $error_msg) {
if (!empty($error_msg)) {
$output = json_encode(array("error_msg" => $error_msg));
} else {
$output = json_encode(array("filename" => $filename));
}
echo '<div id="upload_file_return">'.$output.'</div>';
}
}
$form = new CSVUploader();
$form->process();
?>

View File

@ -0,0 +1,126 @@
<?php
/**
* @version 6.2.6 tabulizer $
* @package tabulizer
* @copyright Copyright © 2011 - All rights reserved.
* @license GNU/GPL
* @author Dimitrios Mourloukos
* @author mail info@alterora.gr
* @website www.tabulizer.com
*
*/
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
class ExcelUploader {
function file_upload_error_message($error_code) {
$error_msg = '';
switch ($error_code) {
case UPLOAD_ERR_INI_SIZE:
$error_msg = JText::_('COM_TABULIZER_UPLOAD_ERR_INI_SIZE'); break;
case UPLOAD_ERR_FORM_SIZE:
$error_msg = JText::_('COM_TABULIZER_UPLOAD_ERR_FORM_SIZE'); break;
case UPLOAD_ERR_PARTIAL:
$error_msg = JText::_('COM_TABULIZER_UPLOAD_ERR_PARTIAL'); break;
case UPLOAD_ERR_NO_FILE:
$error_msg = JText::_('COM_TABULIZER_UPLOAD_ERR_NO_FILE'); break;
case UPLOAD_ERR_NO_TMP_DIR:
$error_msg = JText::_('COM_TABULIZER_Missing a temporary folder'); break;
case UPLOAD_ERR_CANT_WRITE:
$error_msg = JText::_('COM_TABULIZER_UPLOAD_ERR_CANT_WRITE'); break;
case UPLOAD_ERR_EXTENSION:
$error_msg = JText::_('COM_TABULIZER_UPLOAD_ERR_EXTENSION'); break;
default:
$error_msg = 'Unknown upload error'; break;
}
return $error_msg;
}
function verifyUploadedFile(&$sheet_filename, &$error_msg) {
$jinput = JFactory::getApplication()->input;
$uploaded_fieldname = 'sheet_file';
$file = $jinput->files->get($uploaded_fieldname);
foreach ($file as $key => &$value) {
$value = trim(str_replace('&gt;','',$value));
}
if ($file["error"] > 0) {
$error_msg = sprintf(JText::_('COM_TABULIZER_SHEET_UPLOAD_FAILED'),$this->file_upload_error_message($file["error"]));
return false;
} else {
$uploaded_filename = $file['name'];
$uploaded_file = $file['tmp_name'];
$uploaded_size = $file["size"];
$uploaded_type = strtolower($file["type"]);
# sanity checks
// 1. File size
if ($uploaded_size > MAX_UPLOAD_SHEET_FILE_SIZE) {
$error_msg = sprintf(JText::_('COM_TABULIZER_SHEET_UPLOAD_INVALID_FILE_SIZE'),MAX_UPLOAD_SHEET_FILE_SIZE);
return false;
}
// 2. File type
/*
// Note: the official mine type is 'application/vnd.ms-excel' but each browser could set it's own variation
// We decided to comment this check, because it's easily bypassed by changing the extension (xls), which is already checked at the client side.
$valid_mime_types = array('application/vnd.ms-excel', 'application/msexcel', 'application/x-msexcel', 'application/x-ms-excel', 'application/x-excel', 'application/x-dos_ms_excel', 'application/xls', 'application/octet-stream');
if (!in_array($uploaded_type, $valid_mime_types)) {
$error_msg = sprintf(JText::_('COM_TABULIZER_SHEET_UPLOAD_INVALID_FILE_TYPE'), $uploaded_type);
return false;
}
*/
// 3. File extension
$path_parts = pathinfo($uploaded_filename);
$filename_ext = strtolower($path_parts['extension']);
$valid_extensions = array('xls','xlsx','ods');
if (!in_array($filename_ext, $valid_extensions)) {
$error_msg = sprintf(JText::_('COM_TABULIZER_SHEET_UPLOAD_INVALID_FILE_EXT'), $filename_ext);
return false;
}
# Copy file to temp dir
$import_hash = time() . mt_rand();
$sheet_filename = 'sheet' . $import_hash . '.utemp.'. $filename_ext;
$temp_filename_path = TabulizerPath::getFilePath($sheet_filename, 'sheet_upload');
if(!move_uploaded_file($uploaded_file, $temp_filename_path)) {
$error_msg = sprintf(JText::_('COM_TABULIZER_SHEET_UPLOAD_MOVE_FAILED'), $temp_filename_path);
return false;
}
}
return true;
}
function process() {
$error_msg = null;
$sheet_filename = null;
if ($this->verifyUploadedFile($sheet_filename, $error_msg)) {
$this->outputData($sheet_filename, $error_msg);
} else {
$this->outputData(null, $error_msg);
}
}
function outputData($filename, $error_msg) {
if (!empty($error_msg)) {
$output = json_encode(array("error_msg" => $error_msg));
} else {
$output = json_encode(array("filename" => $filename));
}
echo '<div id="upload_file_return">'.$output.'</div>';
}
}
$form = new ExcelUploader();
$form->process();
?>