primo commit
This commit is contained in:
688
administrator/components/com_tabulizer/models/datasources.php
Normal file
688
administrator/components/com_tabulizer/models/datasources.php
Normal file
@ -0,0 +1,688 @@
|
||||
<?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');
|
||||
|
||||
jimport( 'joomla.application.component.model' );
|
||||
|
||||
class tabulizerModelDatasources extends JModelLegacy {
|
||||
var $data_sources = null;
|
||||
var $data_source = null;
|
||||
var $data_files = null;
|
||||
var $limit = null;
|
||||
var $limitstart = null;
|
||||
var $total_count = null;
|
||||
var $publishing_preferences = null;
|
||||
|
||||
function __construct(){
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
function getPagination() {
|
||||
$pagination = null;
|
||||
if (!empty($this->limit) && !empty($this->total_count)) {
|
||||
if ($this->total_count > $this->limit) {
|
||||
jimport('joomla.html.pagination');
|
||||
$pagination = new JPagination($this->total_count, $this->limitstart, $this->limit );
|
||||
}
|
||||
}
|
||||
return $pagination;
|
||||
}
|
||||
|
||||
function getReturnURLs(&$urls) {
|
||||
$jinput = JFactory::getApplication()->input;
|
||||
$option = $jinput->getCmd('option');
|
||||
|
||||
$urls = array();
|
||||
$urls['data_sources'] = $jinput->getString('data_sources_return_url',str_replace('&','&',JRoute::_('index.php?option='.$option.'&task=viewDataSources&limit='.$this->limit.'&limitstart='.$this->limitstart)));
|
||||
$url = str_replace('&','&',JRoute::_('index.php?option='.$option.'&task=viewRulesetArchives'));
|
||||
$urls['archives'] = $url;
|
||||
}
|
||||
|
||||
function loadDataSources($limit, $limitstart, &$error_msg) {
|
||||
$jinput = JFactory::getApplication()->input;
|
||||
$option = $jinput->getCmd('option');
|
||||
$db = JFactory::getDbo();
|
||||
|
||||
$this->limit = $limit;
|
||||
$this->limitstart = $limitstart;
|
||||
|
||||
if (!empty($limit)) {
|
||||
$query = 'SELECT id, tag, title, source_type, source_params, cache_type, cache_time FROM #__tabulizer_data_source LIMIT '.intval($limitstart).', '.intval($limit);
|
||||
} else {
|
||||
$query = 'SELECT id, tag, title, source_type, source_params, cache_type, cache_time FROM #__tabulizer_data_source';
|
||||
}
|
||||
$db->setQuery($query);
|
||||
$rows = $db->loadObjectList();
|
||||
|
||||
if (empty($rows)) {
|
||||
return false;
|
||||
} else {
|
||||
$this->data_sources = $rows;
|
||||
$query = 'SELECT count(*) FROM #__tabulizer_data_source WHERE 1';
|
||||
$db->setQuery($query);
|
||||
$this->total_count = $db->loadResult();
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function loadPublishingPreferences(&$error_msg) {
|
||||
$jinput = JFactory::getApplication()->input;
|
||||
$option = $jinput->getCmd('option');
|
||||
$db = JFactory::getDbo();
|
||||
|
||||
if (!empty($this->data_source)) {
|
||||
$tag = $this->data_source->tag;
|
||||
} else {
|
||||
// this should never happen
|
||||
$error_msg = 'Data source is not loaded!';
|
||||
return false;
|
||||
}
|
||||
|
||||
$query = 'SELECT * FROM #__tabulizer_data_source_publishing_preferences WHERE tag = ' . $db->quote($tag);
|
||||
$db->setQuery($query);
|
||||
$row = $db->loadObject();
|
||||
|
||||
$this->publishing_preferences = $row;
|
||||
return true;
|
||||
}
|
||||
|
||||
function getPublishingPreferences() {
|
||||
return $this->publishing_preferences;
|
||||
}
|
||||
|
||||
function savePublishingPreferences($tag, &$error_msg) {
|
||||
$jinput = JFactory::getApplication()->input;
|
||||
$option = $jinput->getCmd('option');
|
||||
$db = JFactory::getDbo();
|
||||
|
||||
$query = 'SELECT * FROM #__tabulizer_data_source_publishing_preferences WHERE tag = ' . $db->quote($tag);
|
||||
$db->setQuery($query);
|
||||
$row = $db->loadObject();
|
||||
|
||||
$status = $jinput->getInt('ds_status',0);
|
||||
$mode = $jinput->getString('ds_mode',null);
|
||||
$keyphrases = $jinput->getString('ds_keyphrases',null);
|
||||
|
||||
if (!empty($row)) {
|
||||
$query = 'UPDATE #__tabulizer_data_source_publishing_preferences SET `status`='.$db->quote($status).', `mode`='.$db->quote($mode).', `keyphrases`='.$db->quote($keyphrases).' WHERE tag = ' . $db->quote($tag);
|
||||
} else {
|
||||
$query = 'INSERT INTO #__tabulizer_data_source_publishing_preferences (`tag`,`status`,`mode`,`keyphrases`) VALUES ('.$db->quote($tag).','.$db->quote($status).','.$db->quote($mode).','.$db->quote($keyphrases).')';
|
||||
}
|
||||
|
||||
return TabulizerDatabase::executeQuery($query, $error_msg);
|
||||
}
|
||||
|
||||
function getDataSourceRequest($source_type, $field_prefix, &$error_msg) {
|
||||
TabulizerPath::requireLib('data_source','common');
|
||||
return TabulizerDataSource::getRequestedParams($source_type, $field_prefix, $error_msg);
|
||||
}
|
||||
|
||||
function getDataSources() {
|
||||
return $this->data_sources;
|
||||
}
|
||||
|
||||
function loadDataSource($id = null, $tag = null) {
|
||||
$jinput = JFactory::getApplication()->input;
|
||||
$option = $jinput->getCmd('option');
|
||||
$db = JFactory::getDbo();
|
||||
|
||||
if (isset($tag)) {
|
||||
$query = 'SELECT id, tag, title, source_type, source_params, cache_type, cache_time FROM #__tabulizer_data_source WHERE tag = '. $db->quote($tag);
|
||||
} else {
|
||||
$query = 'SELECT id, tag, title, source_type, source_params, cache_type, cache_time FROM #__tabulizer_data_source WHERE id = '. $db->quote($id);
|
||||
}
|
||||
$db->setQuery($query);
|
||||
$result = $db->loadObject();
|
||||
if (!empty($result)) {
|
||||
$this->data_source = $result;
|
||||
return $result;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function getDataSource() {
|
||||
return $this->data_source;
|
||||
}
|
||||
|
||||
function importDataSource($data_source, &$errors) {
|
||||
TabulizerPath::requireLib('data_source','common');
|
||||
|
||||
// validate type
|
||||
$options = TabulizerDataSource::getSourceTypeLabel();
|
||||
if (!array_key_exists($data_source['source_type'],$options)) {
|
||||
$errors[] = sprintf(JText::_('COM_TABULIZER_DATA_SOURCE_INVALID_TYPE'), $data_source['source_type']);
|
||||
return false;
|
||||
}
|
||||
|
||||
// validate cache
|
||||
if ($data_source['cache_type'] != TABULIZER_DATA_SOURCE_CACHE_OFF) {
|
||||
if (empty($data_source['cache_time'])) $data_source['cache_type'] = TABULIZER_DATA_SOURCE_CACHE_OFF;
|
||||
else $data_source['cache_type'] = TABULIZER_DATA_SOURCE_CACHE_ON;
|
||||
}
|
||||
|
||||
if (TabulizerDataSource::validateDataSourceParams($data_source['params'], $error_msg)) {
|
||||
TabulizerDataSource::encodeParams($data_source['source_type'], $data_source['params'], $source_params_str, $error_msg);
|
||||
$data_source['source_params'] = $source_params_str;
|
||||
return $this->saveDataSource($data_source, $errors);
|
||||
} else {
|
||||
$errors[] = $error_msg;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function importDataSourceArchive($filename, &$errors) {
|
||||
$contents = file_get_contents($filename);
|
||||
if (empty($contents)) return false;
|
||||
|
||||
$p = xml_parser_create();
|
||||
xml_parse_into_struct($p, $contents, $vals, $index);
|
||||
xml_parser_free($p);
|
||||
|
||||
$data_source_open = false;
|
||||
$data_source = array();
|
||||
|
||||
foreach ($vals as $node) {
|
||||
switch ($node['tag']) {
|
||||
case 'DATASOURCE':
|
||||
if ($node['type'] == 'open') {
|
||||
$data_source = array();
|
||||
if (!empty($node['attributes']['TITLE'])) {
|
||||
$data_source['title'] = trim($node['attributes']['TITLE']);
|
||||
}
|
||||
if (!empty($node['attributes']['TAG'])) {
|
||||
$data_source['tag'] = trim($node['attributes']['TAG']);
|
||||
} else {
|
||||
$data_source['tag'] = TabulizerString::generateRandomString(24);
|
||||
}
|
||||
if (!empty($node['attributes']['SOURCE_TYPE'])) {
|
||||
$data_source['source_type'] = strtolower(trim($node['attributes']['SOURCE_TYPE']));
|
||||
}
|
||||
if (!empty($node['attributes']['CACHE_TYPE'])) {
|
||||
$data_source['cache_type'] = intval(trim($node['attributes']['CACHE_TYPE']));
|
||||
} else {
|
||||
$data_source['cache_type'] = TABULIZER_DATA_SOURCE_DEFAULT_CACHE_TYPE;
|
||||
}
|
||||
if (!empty($node['attributes']['CACHE_TIME'])) {
|
||||
$data_source['cache_time'] = intval(trim($node['attributes']['CACHE_TIME']));
|
||||
} else {
|
||||
$data_source['cache_time'] = TABULIZER_DATA_SOURCE_DEFAULT_CACHE_TIME;
|
||||
}
|
||||
|
||||
if (isset($data_source['title']) && isset($data_source['source_type'])) {
|
||||
$data_source['params'] = array();
|
||||
$data_source_open = true;
|
||||
} else {
|
||||
$data_source_open = false;
|
||||
}
|
||||
} else if ($node['type'] == 'close') {
|
||||
if ($data_source_open) {
|
||||
$this->importDataSource($data_source, $errors);
|
||||
$data_source_open = false;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 'PARAM':
|
||||
if ($data_source_open) {
|
||||
if ($node['type'] == 'complete') {
|
||||
$attributes = $node['attributes'];
|
||||
$attribute_key = empty($attributes['KEY'])?null:strtolower(trim($attributes['KEY']));
|
||||
$attribute_value = isset($attributes['VALUE'])?trim($attributes['VALUE']):null;
|
||||
if (isset($attribute_key) && (isset($attribute_value))) {
|
||||
$data_source['params'][$attribute_key] = $attribute_value;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($errors)) return true;
|
||||
else return false;
|
||||
}
|
||||
|
||||
function verifyCompatibility($data_source, &$error_msg) {
|
||||
TabulizerPath::requireLib('data_source','common');
|
||||
if (!TabulizerDataSource::decodeParams($data_source['source_type'],$data_source['source_params'],$source_params,$error_msg)) {
|
||||
// this should never happen
|
||||
$error_msg = 'Invalid data source params at verifyCompatibility';
|
||||
return false;
|
||||
}
|
||||
$server_side = false;
|
||||
if (!empty($source_params['server_side'])) $server_side = true;
|
||||
if ($server_side) {
|
||||
TabulizerPath::requireLib('ruleset','admin');
|
||||
$loader = new Ruleset();
|
||||
$ruleset = $loader->getRuleset($source_params['ruleset_name'],$source_params['ruleset_archive']);
|
||||
if (empty($ruleset)) {
|
||||
// this should never happen
|
||||
$error_msg = 'Invalid ruleset for data source at verifyCompatibility';
|
||||
return false;
|
||||
}
|
||||
$split_rule = false;
|
||||
$pagination_rule = false;
|
||||
if (!empty($ruleset['rules'])) {
|
||||
foreach ($ruleset['rules'] as $rule) {
|
||||
if (!empty($rule['split'])) $split_rule = true;
|
||||
if (!empty($rule['pagination'])) $pagination_rule = true;
|
||||
}
|
||||
}
|
||||
if ($split_rule) {
|
||||
$error_msg = JText::_('COM_TABULIZER_INVALID_DATA_SOURCE_SERVER_SIDE_INCOMPATIBILITY_SPLIT');
|
||||
return false;
|
||||
}
|
||||
if (!$pagination_rule) {
|
||||
$error_msg = JText::_('COM_TABULIZER_INVALID_DATA_SOURCE_SERVER_SIDE_INCOMPATIBILITY_PAGINATION');
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function saveDataSource($data_source, &$error_msg) {
|
||||
$db = JFactory::getDbo();
|
||||
$new_entry = (empty($data_source['id']))?true:false;
|
||||
$cache_type = intval($data_source['cache_type']);
|
||||
if ($cache_type == TABULIZER_DATA_SOURCE_CACHE_OFF) {
|
||||
$cache_time = 'NULL';
|
||||
} else {
|
||||
$cache_time = intval($data_source['cache_time']);
|
||||
if (empty($cache_time)) $cache_time = TABULIZER_DATA_SOURCE_DEFAULT_CACHE_TIME;
|
||||
}
|
||||
|
||||
// compatibilty issues such as: server side + split, or server side and lack of pagination
|
||||
if (!$this->verifyCompatibility($data_source,$error_msg)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($new_entry) {
|
||||
$query = 'INSERT INTO #__tabulizer_data_source (`tag`, `title`, `source_type`, `source_params`, `cache_type`, `cache_time`) VALUES ('.$db->quote($data_source['tag']).','.$db->quote($data_source['title']).','.$db->quote($data_source['source_type']).','.$db->quote($data_source['source_params']).','.$cache_type.','.$cache_time.')';
|
||||
} else {
|
||||
$query = 'UPDATE #__tabulizer_data_source SET `title`='.$db->quote($data_source['title']).', `source_type`='.$db->quote($data_source['source_type']).', `source_params`='.$db->quote($data_source['source_params']). ', `cache_type`='.$cache_type.', `cache_time`='.$cache_time.' WHERE `id` = '.intval($data_source['id']);
|
||||
// remove cache contents
|
||||
$data_source_tags = array($data_source['tag']);
|
||||
$this->deleteDataSourceCache($data_source_tags);
|
||||
}
|
||||
return TabulizerDatabase::executeQuery($query, $error_msg);
|
||||
}
|
||||
|
||||
function clearDataSourceCache($id, &$error_msg) {
|
||||
$db = JFactory::getDbo();
|
||||
|
||||
$query = 'SELECT tag FROM #__tabulizer_data_source WHERE id = '. intval($id);
|
||||
$db->setQuery($query);
|
||||
$data_source_tag = $db->loadResult();
|
||||
|
||||
if (!empty($data_source_tag)) {
|
||||
$this->deleteDataSourceImages($id);
|
||||
$data_source_tags = array($data_source_tag);
|
||||
return $this->deleteDataSourceCache($data_source_tags);
|
||||
} else return false;
|
||||
}
|
||||
|
||||
function deleteDataSource($ids, &$error_msg) {
|
||||
$db = JFactory::getDbo();
|
||||
|
||||
$query = 'SELECT tag FROM #__tabulizer_data_source WHERE id IN ('.implode(',',$ids).')';
|
||||
$db->setQuery($query);
|
||||
$data_source_tags = $db->loadColumn();
|
||||
|
||||
if ($data_source_tags) {
|
||||
$this->deleteDataSourceCache($data_source_tags);
|
||||
|
||||
$query = 'DELETE FROM #__tabulizer_data_source WHERE id IN ('.implode(',',$ids).')';
|
||||
return TabulizerDatabase::executeQuery($query, $error_msg);
|
||||
}
|
||||
}
|
||||
|
||||
function deleteDataSourceCache($data_source_tags) {
|
||||
$db = JFactory::getDbo();
|
||||
|
||||
$tags = array();
|
||||
foreach ($data_source_tags as $tag) {
|
||||
$tags[] = $db->quote($tag);
|
||||
}
|
||||
|
||||
$query = 'SELECT cache_id FROM #__tabulizer_data_source_cache_key_map WHERE tag IN ('.implode(',',$tags).')';
|
||||
$db->setQuery($query);
|
||||
$cache_ids = $db->loadColumn();
|
||||
if (!empty($cache_ids)) {
|
||||
$query = 'DELETE FROM #__tabulizer_data_source_cache WHERE cache_id IN ('.implode(',',$cache_ids).')';
|
||||
TabulizerDatabase::executeQuery($query, $error_msg);
|
||||
$query = 'DELETE FROM #__tabulizer_data_source_cache_properties WHERE cache_id IN ('.implode(',',$cache_ids).')';
|
||||
TabulizerDatabase::executeQuery($query, $error_msg);
|
||||
}
|
||||
|
||||
$query = 'DELETE FROM #__tabulizer_data_source_cache_key_map WHERE tag IN ('.implode(',',$tags).')';
|
||||
return TabulizerDatabase::executeQuery($query, $error_msg);
|
||||
}
|
||||
|
||||
function deleteDataSourceImages($data_source_id) {
|
||||
$data_source = $this->loadDataSource($data_source_id);
|
||||
if ($data_source->source_type == 'excel') {
|
||||
TabulizerPath::requireLib('data_source','common');
|
||||
if (!TabulizerDataSource::decodeParams($data_source->source_type,$data_source->source_params,$params,$error_msg)) {
|
||||
// this should never happen
|
||||
$error_msg = 'Invalid data source params at verifyCompatibility';
|
||||
return false;
|
||||
}
|
||||
|
||||
$read_images = isset($params['read_images'])?$params['read_images']:false;
|
||||
if (!$read_images) return true; // nothing to do
|
||||
else {
|
||||
$image_tag = $data_source->tag;
|
||||
$image_prefix = 'tbl_' . $image_tag;
|
||||
$output_image_dir = TabulizerPath::getDirPath('sheet_images');
|
||||
|
||||
// traverse image directory for matches
|
||||
$image_files = scandir($output_image_dir);
|
||||
if (!empty($image_files)) {
|
||||
foreach ($image_files as $image_file) {
|
||||
if (strpos($image_file, $image_prefix)!==false) {
|
||||
$image_filepath = $output_image_dir . '/'. $image_file;
|
||||
@unlink($image_filepath);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function addMergingTreeTag($nodes, &$merging_tree) {
|
||||
if (is_array($nodes)) {
|
||||
foreach ($nodes as $node) {
|
||||
if (is_array($node)) {
|
||||
$this->addMergingTreeTag($node, $merging_tree);
|
||||
} else {
|
||||
$merging_tree[] = $node;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function exportDataSource($data_source, &$ds_merging_tree, &$ds_associated_files, &$ds_file_contents, &$error_msg) {
|
||||
if (!TabulizerDataSource::decodeParams($data_source->source_type, $data_source->source_params, $params, $errors)) {
|
||||
$error_msg = sprintf(JText::_('COM_TABULIZER_UNABLE_TO_DECODE_DATA_SROUCE_PARAMS'),$data_source->tag);
|
||||
return false;
|
||||
}
|
||||
$ds_file_contents .= ' <datasource';
|
||||
$ds_file_contents .= ' title="'.TabulizerString::makeXMLSafe($data_source->title).'"';
|
||||
if (!empty($data_source->tag)) $ds_file_contents .= ' tag="'.TabulizerString::makeXMLSafe($data_source->tag).'"';
|
||||
$ds_file_contents .= ' source_type="'.TabulizerString::makeXMLSafe($data_source->source_type).'"';
|
||||
$ds_file_contents .= ' cache_type="'.TabulizerString::makeXMLSafe($data_source->cache_type).'"';
|
||||
if (!empty($data_source->cache_type)) {
|
||||
if ($data_source->cache_type != TABULIZER_DATA_SOURCE_CACHE_OFF) {
|
||||
$ds_file_contents .= ' cache_time="' . TabulizerString::makeXMLSafe($data_source->cache_time) . '"';
|
||||
}
|
||||
}
|
||||
$ds_file_contents .= '>'."\n";
|
||||
foreach ($params as $key => $value) {
|
||||
switch ($key) {
|
||||
case 'ruleset_archive':
|
||||
$associated_files = TabulizerRulesetAssociation::loadArchiveFiles($value);
|
||||
if ($associated_files) {
|
||||
$ds_associated_files = TabulizerRulesetAssociation::mergeAssociations($ds_associated_files,$associated_files);
|
||||
}
|
||||
break;
|
||||
case 'filepath':
|
||||
$associated_files = TabulizerRulesetAssociation::loadDataFile($value, $filename);
|
||||
if ($associated_files) {
|
||||
$ds_associated_files = TabulizerRulesetAssociation::mergeAssociations($ds_associated_files,$associated_files);
|
||||
$value = $filename;
|
||||
}
|
||||
break;
|
||||
case 'merging_tree':
|
||||
TabulizerPath::requireLib('merger_extraction','common');
|
||||
$extractor = new MergerExtraction();
|
||||
$nodes = $extractor->getMergingTree($value);
|
||||
if (!empty($nodes)) {
|
||||
$ds_merging_tree = array();
|
||||
$this->addMergingTreeTag($nodes, $ds_merging_tree);
|
||||
}
|
||||
break;
|
||||
}
|
||||
$ds_file_contents .= ' <param key="'.$key.'" value="'.TabulizerString::makeXMLSafe($value).'" />'."\n";
|
||||
}
|
||||
$ds_file_contents .= ' </datasource>'."\n";
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function exportDataSources($ids, &$error_msg) {
|
||||
TabulizerPath::requireLib('data_source','common');
|
||||
$db = JFactory::getDbo();
|
||||
|
||||
$query = 'SELECT * FROM #__tabulizer_data_source WHERE id IN ('.implode(',',$ids).')';
|
||||
$db->setQuery($query);
|
||||
$data_sources = $db->loadObjectList();
|
||||
|
||||
if (empty($data_sources)) {
|
||||
$error_msg = JText::_('COM_TABULIZER_UNABLE_TO_LOAD_SELECTED_DATA_SOURCES');
|
||||
return false;
|
||||
}
|
||||
|
||||
$ds_associated_files = array();
|
||||
|
||||
$ds_file_contents = '<?xml version="1.0" encoding="utf-8"?>'."\n".'<datasources>' . "\n";
|
||||
$data_source = array_shift($data_sources);
|
||||
while ($data_source) {
|
||||
$ds_merging_tree = array();
|
||||
if (!$this->exportDataSource($data_source, $ds_merging_tree, $ds_associated_files, $ds_file_contents, $error_msg)) return false;
|
||||
if (!empty($ds_merging_tree)) {
|
||||
$tags = array();
|
||||
foreach ($ds_merging_tree as $tag) $tags[] = $db->quote($tag);
|
||||
$query = 'SELECT * FROM #__tabulizer_data_source WHERE tag IN ('.implode(',',$tags).')';
|
||||
$db->setQuery($query);
|
||||
$data_sources_entries = $db->loadObjectList();
|
||||
if (empty($data_sources_entries)) {
|
||||
foreach ($data_sources_entries as $data_source) {
|
||||
array_push($data_sources, $data_source);
|
||||
}
|
||||
}
|
||||
}
|
||||
$data_source = array_shift($data_sources);
|
||||
}
|
||||
$ds_file_contents .= '</datasources>';
|
||||
|
||||
$archive_dir = TabulizerPath::getDirBase('temp');
|
||||
$archive_filename = $archive_dir .DIRECTORY_SEPARATOR. 'ds_download.zip';
|
||||
$ds_filename = 'ds_' . TabulizerString::generateRandomString() . '.xml';
|
||||
$ds_filepath = $archive_dir .DIRECTORY_SEPARATOR. $ds_filename;
|
||||
if (file_put_contents($ds_filepath, $ds_file_contents)) {
|
||||
$associated_files = array('datasources'=>array($ds_filename=>$ds_filepath));
|
||||
$ds_associated_files = TabulizerRulesetAssociation::mergeAssociations($ds_associated_files,$associated_files);
|
||||
} else {
|
||||
$error_msg = sprintf(JText::_('COM_TABULIZER_DATA_SOURCE_UNABLE_TO_WRITE_TEMP_EXPORT_FILE'),$ds_filepath);
|
||||
return false;
|
||||
}
|
||||
|
||||
$zip = new ZipArchive;
|
||||
$return_code = $zip->open($archive_filename,ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE);
|
||||
if ($return_code === TRUE) {
|
||||
foreach ($ds_associated_files as $zipdir => $files) {
|
||||
if (empty($files)) continue;
|
||||
$zip->addEmptyDir($zipdir);
|
||||
foreach ($files as $filename => $filepath) {
|
||||
$zip->addFile($filepath, $zipdir .DIRECTORY_SEPARATOR. $filename);
|
||||
}
|
||||
}
|
||||
$zip->close();
|
||||
} else {
|
||||
$error_desc = TabulizerUtils::getZipArchiveErrorDescription($return_code);
|
||||
$error_msg = sprintf(JText::_('COM_TABULIZER_DATA_FILE_ZIP_LIBRARY_MISSING'),$error_desc);
|
||||
return false;
|
||||
}
|
||||
|
||||
// finally output the temp zip file
|
||||
header('Pragma: public');
|
||||
header('Expires: 0');
|
||||
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
|
||||
header('Cache-Control: private', false); // required for certain browsers
|
||||
header('Content-Type: application/zip');
|
||||
|
||||
header('Content-Disposition: attachment; filename="'. basename($archive_filename) . '";');
|
||||
header('Content-Transfer-Encoding: binary');
|
||||
header('Content-Length: ' . filesize($archive_filename));
|
||||
|
||||
ob_clean();
|
||||
flush();
|
||||
readfile($archive_filename);
|
||||
|
||||
// remove temporary files
|
||||
@unlink($archive_filename);
|
||||
@unlink($ds_filepath);
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
function loadDataFiles($limit = 0, $limitstart = 0) {
|
||||
TabulizerPath::requireLib('data_source','common');
|
||||
$data_path = TabulizerPath::getDirPath('data');
|
||||
|
||||
$file2ds = array();
|
||||
$this->loadDataSources(0,0,$error_msg);
|
||||
if (!empty($this->data_sources)) {
|
||||
foreach ($this->data_sources as $data_source) {
|
||||
$source_type = $data_source->source_type;
|
||||
$applicable_source_types = explode(',','csv,excel,html,rss');
|
||||
if (in_array($source_type,$applicable_source_types)) {
|
||||
$title = $data_source->title;
|
||||
if (TabulizerDataSource::decodeParams($source_type,$data_source->source_params,$params,$error_msg)) {
|
||||
$id = $data_source->id;
|
||||
$return_url = '&data_sources_return_url='.urlencode(JFilterOutput::ampReplace ('index.php?option=com_tabulizer&task=viewDataFiles'));
|
||||
$link = '<a href="'.JFilterOutput::ampReplace ('index.php?option=com_tabulizer&task=editDataSource&ds_id='.$id.'&cid[]='.$id.$return_url).'">'.$title.'</a>';
|
||||
if (isset($params['filepath'])) {
|
||||
if (file_exists($data_path .DIRECTORY_SEPARATOR. $params['filepath'])) {
|
||||
if (!isset($file2ds[$params['filepath']])) $file2ds[$params['filepath']] = array();
|
||||
$file2ds[$params['filepath']][] = $link;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$data_files = array();
|
||||
$files = scandir($data_path);
|
||||
if (!empty($files)) {
|
||||
$allowed_extensions = explode(',',strtolower(ALLOWED_FILE_TYPES_FOR_DATA_IMPORTATION));
|
||||
foreach ($files as $file) {
|
||||
$filepath = $data_path .DIRECTORY_SEPARATOR. $file;
|
||||
if (is_file($filepath)) {
|
||||
if (($file!='.')&&($file!='..')) {
|
||||
$parts = pathinfo($filepath);
|
||||
if (isset($parts['extension'])) {
|
||||
$extension = strtolower($parts['extension']);
|
||||
if (in_array($extension,$allowed_extensions)) {
|
||||
$linked_data_sources = '';
|
||||
if (isset($file2ds[$file])) $linked_data_sources = implode("<br/>\n", $file2ds[$file]);
|
||||
$data_files[$file] = array('modified'=>date("Y-m-d H:i:s.", filemtime($filepath)), 'linked_data_sources'=>$linked_data_sources);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->data_files = $data_files;
|
||||
}
|
||||
|
||||
function getDataFiles() {
|
||||
return $this->data_files;
|
||||
}
|
||||
|
||||
function deleteDataFile($filenames, &$error_msg) {
|
||||
$this->loadDataFiles();
|
||||
$data_path = realpath(TabulizerPath::getDirPath('data'));
|
||||
foreach ($filenames as $filename) {
|
||||
if (isset($this->data_files[$filename])) {
|
||||
$filepath = realpath($data_path .DIRECTORY_SEPARATOR. $filename);
|
||||
$base_path = pathinfo($filepath, PATHINFO_DIRNAME);
|
||||
if ($data_path != $base_path) {
|
||||
$error_msg = 'Invalid base path - please report this.';
|
||||
return false;
|
||||
} else
|
||||
if (file_exists($filepath)) {
|
||||
@unlink($filepath);
|
||||
}
|
||||
} else {
|
||||
$error_msg = 'Invalid file selection:'.$filename. ' - make sure it exists in the data files directory and it has the proper extension.';
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function outputDataFiles($filenames, &$error_msg) {
|
||||
$this->loadDataFiles();
|
||||
$data_path = realpath(TabulizerPath::getDirPath('data'));
|
||||
|
||||
$archive_dir = $data_path;
|
||||
$archive_filename = $archive_dir .DIRECTORY_SEPARATOR. 'download.zip';
|
||||
|
||||
$zip = new ZipArchive;
|
||||
$return_code = $zip->open($archive_filename,ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE);
|
||||
if ($return_code === TRUE) {
|
||||
foreach ($filenames as $filename) {
|
||||
if (isset($this->data_files[$filename])) {
|
||||
$filepath = realpath($data_path .DIRECTORY_SEPARATOR. $filename);
|
||||
$base_path = pathinfo($filepath, PATHINFO_DIRNAME);
|
||||
if ($data_path != $base_path) {
|
||||
$error_msg = "Invalid base path $base_path for zip entry.";
|
||||
return false;
|
||||
} else if (file_exists($filepath)) {
|
||||
$zip->addFile($filepath, $filename);
|
||||
} else {
|
||||
$error_msg = "File not found: $filepath";
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
$error_msg = 'Invalid file selection:'.$filename. ' - make sure it exists in the data files directory and it has the proper extension.';
|
||||
return false;
|
||||
}
|
||||
}
|
||||
$zip->close();
|
||||
} else {
|
||||
$error_desc = TabulizerUtils::getZipArchiveErrorDescription($return_code);
|
||||
$error_msg = sprintf(JText::_('COM_TABULIZER_DATA_FILE_ZIP_LIBRARY_MISSING'),$error_desc);
|
||||
return false;
|
||||
}
|
||||
|
||||
// finally output the temp zip file
|
||||
header('Pragma: public');
|
||||
header('Expires: 0');
|
||||
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
|
||||
header('Cache-Control: private', false); // required for certain browsers
|
||||
header('Content-Type: application/zip');
|
||||
|
||||
header('Content-Disposition: attachment; filename="'. basename($archive_filename) . '";');
|
||||
header('Content-Transfer-Encoding: binary');
|
||||
header('Content-Length: ' . filesize($archive_filename));
|
||||
|
||||
ob_clean();
|
||||
flush();
|
||||
readfile($archive_filename);
|
||||
|
||||
// remove temporary files
|
||||
@unlink($archive_filename);
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
1
administrator/components/com_tabulizer/models/index.html
Normal file
1
administrator/components/com_tabulizer/models/index.html
Normal file
@ -0,0 +1 @@
|
||||
<html><body bgcolor="#FFFFFF"></body></html>
|
||||
80
administrator/components/com_tabulizer/models/rule.php
Normal file
80
administrator/components/com_tabulizer/models/rule.php
Normal file
@ -0,0 +1,80 @@
|
||||
<?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');
|
||||
|
||||
jimport( 'joomla.application.component.model' );
|
||||
|
||||
TabulizerPath::requireLib('ruleset','admin');
|
||||
|
||||
class tabulizerModelRule extends JModelLegacy {
|
||||
|
||||
var $rule_id = null;
|
||||
var $ruleset_name = null;
|
||||
var $archive_filename = null;
|
||||
var $rule = null;
|
||||
|
||||
function __construct(){
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
function loadRule($rule_id, $ruleset_name, $archive_file) {
|
||||
$this->rule_id = $rule_id;
|
||||
$this->ruleset_name = $ruleset_name;
|
||||
$this->archive_filename = $archive_file;
|
||||
|
||||
$ruleset = new Ruleset();
|
||||
$this->rule = $ruleset->getRule($this->rule_id, $this->ruleset_name, $this->archive_filename);
|
||||
|
||||
if (!empty($this->rule)) {
|
||||
$this->rule['rule_id'] = $rule_id;
|
||||
$this->rule['ruleset_name'] = $ruleset_name;
|
||||
$this->rule['filename'] = $archive_file;
|
||||
}
|
||||
|
||||
return $this->rule;
|
||||
}
|
||||
|
||||
function getRule() {
|
||||
if (empty($this->rule)) {
|
||||
$this->loadRule($this->rule_id, $this->ruleset_name, $this->archive_filename);
|
||||
}
|
||||
|
||||
return $this->rule;
|
||||
}
|
||||
|
||||
function saveRule($rule, $rule_id, $ruleset_name, $ruleset_file) {
|
||||
$ruleset = new Ruleset();
|
||||
return $ruleset->saveRule($rule, $rule_id, $ruleset_name, $ruleset_file);
|
||||
}
|
||||
|
||||
function deleteRule($rule_ids, $ruleset_name, $ruleset_file) {
|
||||
$ruleset = new Ruleset();
|
||||
return $ruleset->deleteRule($rule_ids, $ruleset_name, $ruleset_file);
|
||||
}
|
||||
|
||||
function getReturnURLs(&$urls) {
|
||||
$jinput = JFactory::getApplication()->input;
|
||||
$option = $jinput->getCmd('option');
|
||||
|
||||
$urls = array();
|
||||
$url = $jinput->getString('archives_return_url','');
|
||||
$urls['archives'] = empty($url)?str_replace('&','&',JRoute::_('index.php?option='.$option.'&task=viewrulesetarchives')):urldecode($url);
|
||||
$url = $jinput->getString('archive_return_url','');
|
||||
$urls['archive'] = empty($url)?str_replace('&','&',JRoute::_('index.php?option='.$option.'&task=viewrulesetarchive&archive_filename='.$this->archive_filename)):urldecode($url);
|
||||
$url = str_replace('&','&',JRoute::_('index.php?option='.$option.'&task=viewruleset&ruleset_name='.urlencode($this->ruleset_name).'&archive_filename='.urlencode($this->archive_filename)));
|
||||
$urls['ruleset'] = $url;
|
||||
}
|
||||
}
|
||||
?>
|
||||
89
administrator/components/com_tabulizer/models/ruleset.php
Normal file
89
administrator/components/com_tabulizer/models/ruleset.php
Normal file
@ -0,0 +1,89 @@
|
||||
<?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');
|
||||
|
||||
jimport( 'joomla.application.component.model' );
|
||||
|
||||
TabulizerPath::requireLib('ruleset','admin');
|
||||
|
||||
class tabulizerModelRuleset extends JModelLegacy {
|
||||
|
||||
var $ruleset_name = null;
|
||||
var $archive_filename = null;
|
||||
var $ruleset = null;
|
||||
|
||||
function __construct(){
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
function loadRuleset($ruleset_name, $archive_file) {
|
||||
$this->archive_filename = $archive_file;
|
||||
$this->ruleset_name = $ruleset_name;
|
||||
|
||||
$ruleset = new Ruleset();
|
||||
$this->ruleset = $ruleset->getRuleset($this->ruleset_name, $this->archive_filename);
|
||||
|
||||
return $this->ruleset;
|
||||
}
|
||||
|
||||
function getRuleset() {
|
||||
if (empty($this->ruleset)) {
|
||||
$this->loadRuleset($this->ruleset_name, $this->archive_filename);
|
||||
}
|
||||
|
||||
return $this->ruleset;
|
||||
}
|
||||
|
||||
function saveRuleset($new_ruleset, $ruleset_file) {
|
||||
$ruleset = new Ruleset();
|
||||
return $ruleset->saveRuleset($new_ruleset, $ruleset_file);
|
||||
}
|
||||
|
||||
function deleteRuleset($ruleset_names, $ruleset_file) {
|
||||
$ruleset = new Ruleset();
|
||||
return $ruleset->deleteRuleset($ruleset_names, $ruleset_file);
|
||||
}
|
||||
|
||||
function getAllRulesetNames($exclude_ruleset_names = array()) {
|
||||
$ruleset = new Ruleset();
|
||||
return $ruleset->getAllRulesetNames($exclude_ruleset_names);
|
||||
}
|
||||
|
||||
function getAllRulesetTitles($exclude_ruleset_titles = array()) {
|
||||
$ruleset = new Ruleset();
|
||||
return $ruleset->getAllRulesetTitles($exclude_ruleset_titles);
|
||||
}
|
||||
|
||||
function getRecommendedName($seed = '') {
|
||||
$ruleset = new Ruleset();
|
||||
return $ruleset->getRecommendedName($seed);
|
||||
}
|
||||
|
||||
function getReturnURLs(&$urls) {
|
||||
$jinput = JFactory::getApplication()->input;
|
||||
$option = $jinput->getCmd('option');
|
||||
|
||||
$urls = array();
|
||||
$url = $jinput->getString('archives_return_url','');
|
||||
$urls['archives'] = empty($url)?str_replace('&','&',JRoute::_('index.php?option='.$option.'&task=viewrulesetarchives')):urldecode($url);
|
||||
$url = $jinput->getString('archive_return_url','');
|
||||
$urls['archive'] = empty($url)?str_replace('&','&',JRoute::_('index.php?option='.$option.'&task=viewrulesetarchive&archive_filename='.$this->archive_filename)):urldecode($url);
|
||||
$url = str_replace('&','&',JRoute::_('index.php?option='.$option.'&task=viewruleset&ruleset_name='.urlencode($this->ruleset_name).'&archive_filename='.urlencode($this->archive_filename)));
|
||||
$urls['ruleset'] = $url;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
224
administrator/components/com_tabulizer/models/rulesetarchive.php
Normal file
224
administrator/components/com_tabulizer/models/rulesetarchive.php
Normal file
@ -0,0 +1,224 @@
|
||||
<?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');
|
||||
|
||||
jimport( 'joomla.application.component.model' );
|
||||
|
||||
TabulizerPath::requireLib('ruleset','admin');
|
||||
|
||||
class tabulizerModelRulesetarchive extends JModelLegacy {
|
||||
var $archive_filename = null;
|
||||
var $ruleset_archive = null;
|
||||
var $ruleset_name = null;
|
||||
var $css = null;
|
||||
var $limit = null;
|
||||
var $limitstart = null;
|
||||
var $total_count = null;
|
||||
|
||||
function __construct(){
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
function loadRulesetArchive($filename, $limit=0, $limitstart=0) {
|
||||
$this->archive_filename = $filename;
|
||||
$ruleset = new Ruleset();
|
||||
$ruleset_archive = $ruleset->getRulesets($this->archive_filename,$limit,$limitstart,$total_count);
|
||||
if (!empty($ruleset_archive)) {
|
||||
$this->ruleset_archive = $ruleset_archive;
|
||||
$this->ruleset_archive['filename'] = $this->archive_filename;
|
||||
$this->limit = $limit;
|
||||
$this->limitstart = $limitstart;
|
||||
$this->total_count = $total_count;
|
||||
}
|
||||
|
||||
return $this->ruleset_archive;
|
||||
}
|
||||
|
||||
function getRulesetArchive() {
|
||||
if (empty($this->ruleset_archive)) {
|
||||
$this->loadRulesetArchive($this->archive_filename);
|
||||
}
|
||||
|
||||
return $this->ruleset_archive;
|
||||
}
|
||||
|
||||
function getPagination() {
|
||||
$pagination = null;
|
||||
if (!empty($this->limit) && !empty($this->total_count)) {
|
||||
if ($this->total_count > $this->limit) {
|
||||
jimport('joomla.html.pagination');
|
||||
$pagination = new JPagination($this->total_count, $this->limitstart, $this->limit );
|
||||
}
|
||||
}
|
||||
return $pagination;
|
||||
}
|
||||
|
||||
function getReturnURLs(&$urls) {
|
||||
$jinput = JFactory::getApplication()->input;
|
||||
$option = $jinput->getCmd('option');
|
||||
|
||||
$urls = array();
|
||||
$url = $jinput->getString('archives_return_url','');
|
||||
$urls['archives'] = empty($url)?str_replace('&','&',JRoute::_('index.php?option='.$option.'&task=viewrulesetarchives')):urldecode($url);
|
||||
$url = str_replace('&','&',JRoute::_('index.php?option='.$option.'&task=viewrulesetarchive&archive_filename='.$this->archive_filename.'&limit='.$this->limit.'&limitstart='.$this->limitstart));
|
||||
$urls['archive'] = $url;
|
||||
}
|
||||
|
||||
function saveRulesetArchive($ruleset_archive) {
|
||||
$ruleset = new Ruleset();
|
||||
return $ruleset->saveRulesetArchive($ruleset_archive);
|
||||
}
|
||||
|
||||
function deleteRulesetArchive($ruleset_files) {
|
||||
$ruleset = new Ruleset();
|
||||
return $ruleset->deleteRulesetArchive($ruleset_files);
|
||||
}
|
||||
|
||||
function getAllRulesetArchiveNames($exclude_archive_names = array()) {
|
||||
$ruleset = new Ruleset();
|
||||
return $ruleset->getAllRulesetArchiveNames($exclude_archive_names);
|
||||
}
|
||||
|
||||
function getAllRulesetArchiveFilenames($exclude_archive_filenames = array()) {
|
||||
$ruleset = new Ruleset();
|
||||
return $ruleset->getAllRulesetArchiveFilenames($exclude_archive_filenames);
|
||||
}
|
||||
|
||||
function getAllRulesetNames($exclude_ruleset_names = array()) {
|
||||
$ruleset = new Ruleset();
|
||||
return $ruleset->getAllRulesetNames($exclude_ruleset_names);
|
||||
}
|
||||
|
||||
function getAllRulesetTitles($exclude_ruleset_titles = array()) {
|
||||
$ruleset = new Ruleset();
|
||||
return $ruleset->getAllRulesetTitles($exclude_ruleset_titles);
|
||||
}
|
||||
|
||||
function getRecommendedName($seed = '') {
|
||||
$recommended_ruleset_name = '';
|
||||
|
||||
$filename = $this->ruleset_archive['filename'];
|
||||
$rulesets = $this->ruleset_archive['rulesets'];
|
||||
$basename = 'ruleset';
|
||||
$dot = stripos($filename, '.xml');
|
||||
if ($dot !== false) {
|
||||
$basename_clean = strtolower(str_replace(array('-','.','_',' '), array('_','_','_',''), substr($filename,0,$dot)));
|
||||
if ($basename_clean != '') $basename = $basename_clean;
|
||||
|
||||
}
|
||||
if (empty($rulesets)) {
|
||||
$recommended_ruleset_name = $basename . '_1';
|
||||
} else {
|
||||
$num_of_rulesets = count($rulesets)+1;
|
||||
for ($i=1;$i<=$num_of_rulesets;$i++) {
|
||||
$recommended_ruleset_name = $basename . '_' . $i;
|
||||
if (isset($rulesets[$recommended_ruleset_name])) continue;
|
||||
else break;
|
||||
}
|
||||
}
|
||||
|
||||
return $recommended_ruleset_name;
|
||||
}
|
||||
|
||||
function loadCSSFile($css_filename, $archive_filename, $ruleset_name) {
|
||||
$this->css = array();
|
||||
|
||||
$this->css['css_filename'] = $css_filename;
|
||||
$css_path = TabulizerPath::getFilePath($css_filename, 'css');
|
||||
$this->css['css_filepath'] = $css_path;
|
||||
if (file_exists($css_path)) {
|
||||
$this->css['new'] = false;
|
||||
$this->css['css_contents'] = file_get_contents($css_path);
|
||||
} else {
|
||||
$this->css['new'] = true;
|
||||
$this->css['css_contents'] = '';
|
||||
}
|
||||
|
||||
$this->css['archive_filename'] = $archive_filename;
|
||||
$this->css['ruleset_name'] = $ruleset_name;
|
||||
|
||||
$rules_path = TabulizerPath::getFilePath($archive_filename, 'rules');
|
||||
if (file_exists($rules_path)) {
|
||||
$this->css['rulesets'] = $this->loadRulesetArchive($archive_filename);
|
||||
}
|
||||
|
||||
$this->css['css_skeleton'] = '';
|
||||
if (!empty($this->css['rulesets']['rulesets'])) {
|
||||
if (!empty($ruleset_name)) {
|
||||
$skeleton_rulesets = array($ruleset_name => $this->css['rulesets']['rulesets'][$ruleset_name]);
|
||||
} else {
|
||||
$skeleton_rulesets = $this->css['rulesets']['rulesets'];
|
||||
}
|
||||
$this->css['css_skeleton'] = $this->generateCSSSkeleton($skeleton_rulesets);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function generateCSSSkeleton($rulesets) {
|
||||
$css_code = '';
|
||||
$suffix_sep = '-';
|
||||
$css_lines = array();
|
||||
|
||||
foreach ($rulesets as $ruleset_name => $ruleset) {
|
||||
$css_code .= "'\\n'+'\\n'+'/* {$ruleset_name} */'+'\\n'+'\\n'+\n";
|
||||
|
||||
$table_selector = trim('table.tabtable'.$suffix_sep.$ruleset['suffix']);
|
||||
$tr_selectors = array('tr.tabrow');
|
||||
$td_selectors = array('td.tabcol');
|
||||
|
||||
$css_line = "'{$table_selector} {}'+'\\n'+\n";
|
||||
if (!in_array($css_line, $css_lines)) { $css_code .= $css_line; $css_lines[] = $css_line; }
|
||||
|
||||
foreach ($ruleset['rules'] as $rule) {
|
||||
if (empty($rule['style'])) continue;
|
||||
if ($rule['element'] == 'row') {
|
||||
$selector = trim('tr.'.$rule['style']);
|
||||
if (!in_array($selector, $tr_selectors)) {
|
||||
$tr_selectors[] = $selector;
|
||||
}
|
||||
} else {
|
||||
$selector = trim('td.'.$rule['style']);
|
||||
if (!in_array($selector, $td_selectors)) $td_selectors[] = $selector;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($tr_selectors as $tr_selector) {
|
||||
$css_line = "'{$table_selector} {$tr_selector} {}'+'\\n'+\n";
|
||||
if (!in_array($css_line, $css_lines)) { $css_code .= $css_line; $css_lines[] = $css_line; }
|
||||
|
||||
foreach ($td_selectors as $td_selector) {
|
||||
$css_line = "'{$table_selector} {$tr_selector} {$td_selector} {}'+'\\n'+\n";
|
||||
if (!in_array($css_line, $css_lines)) { $css_code .= $css_line; $css_lines[] = $css_line; }
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (!empty($css_code)) $css_code .= "'';\n";
|
||||
|
||||
return $css_code;
|
||||
}
|
||||
|
||||
function getCSSFile() {
|
||||
return $this->css;
|
||||
}
|
||||
|
||||
function saveCSSFile($css_filename, $css_contents) {
|
||||
$css_path = TabulizerPath::getFilePath($css_filename, 'css');
|
||||
return file_put_contents($css_path, $css_contents);
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
@ -0,0 +1,363 @@
|
||||
<?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');
|
||||
|
||||
jimport( 'joomla.application.component.model' );
|
||||
|
||||
TabulizerPath::requireLib('ruleset','admin');
|
||||
|
||||
class tabulizerModelRulesetarchives extends JModelLegacy {
|
||||
var $ruleset_archives = null;
|
||||
var $css_code = null;
|
||||
var $user_preferences = null;
|
||||
var $user_permissions = null;
|
||||
var $system_status = null;
|
||||
var $limit = null;
|
||||
var $limitstart = null;
|
||||
var $total_count = null;
|
||||
|
||||
function __construct(){
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
function loadRulesetArchives($limit=0, $limitstart=0) {
|
||||
$ruleset = new Ruleset();
|
||||
$this->ruleset_archives = $ruleset->getRulesets(null,$limit,$limitstart,$total_count);
|
||||
$this->limit = $limit;
|
||||
$this->limitstart = $limitstart;
|
||||
$this->total_count = $total_count;
|
||||
return $this->ruleset_archives;
|
||||
}
|
||||
|
||||
function getRulesetArchives() {
|
||||
if (empty($this->ruleset_archives)) {
|
||||
$this->loadRulesetArchives();
|
||||
}
|
||||
|
||||
return $this->ruleset_archives;
|
||||
}
|
||||
|
||||
function exportRulesetArchives($ids, &$error_msg) {
|
||||
|
||||
$ra_associated_files = array();
|
||||
foreach ($ids as $archive_filename) {
|
||||
$associated_files = TabulizerRulesetAssociation::loadArchiveFiles($archive_filename);
|
||||
if ($associated_files) {
|
||||
$ra_associated_files = TabulizerRulesetAssociation::mergeAssociations($ra_associated_files,$associated_files);
|
||||
}
|
||||
}
|
||||
|
||||
$archive_dir = TabulizerPath::getDirBase('temp');
|
||||
$archive_filename = $archive_dir .DIRECTORY_SEPARATOR. 'archive_download.zip';
|
||||
|
||||
$zip = new ZipArchive;
|
||||
$return_code = $zip->open($archive_filename,ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE);
|
||||
if ($return_code === TRUE) {
|
||||
foreach ($ra_associated_files as $zipdir => $files) {
|
||||
if (empty($files)) continue;
|
||||
$zip->addEmptyDir($zipdir);
|
||||
foreach ($files as $filename => $filepath) {
|
||||
$zip->addFile($filepath, $zipdir .DIRECTORY_SEPARATOR. $filename);
|
||||
}
|
||||
}
|
||||
$zip->close();
|
||||
} else {
|
||||
$error_desc = TabulizerUtils::getZipArchiveErrorDescription($return_code);
|
||||
$error_msg = sprintf(JText::_('COM_TABULIZER_DATA_FILE_ZIP_LIBRARY_MISSING'),$error_desc);
|
||||
return false;
|
||||
}
|
||||
|
||||
// finally output the temp zip file
|
||||
header('Pragma: public');
|
||||
header('Expires: 0');
|
||||
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
|
||||
header('Cache-Control: private', false); // required for certain browsers
|
||||
header('Content-Type: application/zip');
|
||||
|
||||
header('Content-Disposition: attachment; filename="'. basename($archive_filename) . '";');
|
||||
header('Content-Transfer-Encoding: binary');
|
||||
header('Content-Length: ' . filesize($archive_filename));
|
||||
|
||||
ob_clean();
|
||||
flush();
|
||||
readfile($archive_filename);
|
||||
|
||||
// remove temporary files
|
||||
@unlink($archive_filename);
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
function getPagination() {
|
||||
$pagination = null;
|
||||
if (!empty($this->limit) && !empty($this->total_count)) {
|
||||
if ($this->total_count > $this->limit) {
|
||||
jimport('joomla.html.pagination');
|
||||
$pagination = new JPagination($this->total_count, $this->limitstart, $this->limit );
|
||||
}
|
||||
}
|
||||
return $pagination;
|
||||
}
|
||||
|
||||
function getReturnURLs(&$urls) {
|
||||
$jinput = JFactory::getApplication()->input;
|
||||
$option = $jinput->getCmd('option');
|
||||
|
||||
$urls = array();
|
||||
$url = str_replace('&','&',JRoute::_('index.php?option='.$option.'&task=viewrulesetarchives&limit='.$this->limit.'&limitstart='.$this->limitstart));
|
||||
$urls['archives'] = $url;
|
||||
}
|
||||
|
||||
function getRulesetConflicts() {
|
||||
TabulizerPath::requireLib('ruleset','admin');
|
||||
$ruleset = new Ruleset();
|
||||
return $ruleset->getRulesetConflicts();
|
||||
}
|
||||
|
||||
function loadUserPreferences(&$error_msg) {
|
||||
$preferences = TabulizerInfo::getUserPreferences($error_msg);
|
||||
if ($preferences) {
|
||||
$this->user_preferences = $preferences;
|
||||
return true;
|
||||
} else return false;
|
||||
}
|
||||
|
||||
function getUserPreferences() {
|
||||
return $this->user_preferences;
|
||||
}
|
||||
|
||||
function saveUserPreferences(&$error_msg) {
|
||||
$db = JFactory::getDbo();
|
||||
$user = JFactory::getUser();
|
||||
$jinput = JFactory::getApplication()->input;
|
||||
|
||||
if ($user->guest) {
|
||||
$error_msg = JText::_('COM_TABULIZER_USER_PREFERENCES_NOT_LOGGED_ERROR');
|
||||
return false;
|
||||
}
|
||||
$user_id = $user->id;
|
||||
|
||||
$action = 'system-save';
|
||||
$allow_save = (TabulizerPermissions::isAllowed($action))?1:0;
|
||||
if ($allow_save) {
|
||||
if (!$this->saveSystemPreferences($error_msg)) return false;
|
||||
}
|
||||
|
||||
$preferences = TabulizerInfo::getUserPreferences($error_msg, 'none');
|
||||
|
||||
// update or insert new preferences entry ?
|
||||
$new_entry = true;
|
||||
$update_keys = array();
|
||||
|
||||
$query = 'SELECT pref.* FROM #__tabulizer_user_preferences as pref WHERE user_id = '.$user_id;
|
||||
$db->setQuery($query);
|
||||
|
||||
$rows = $db->loadObjectList();
|
||||
if (!empty($rows)) {
|
||||
$new_entry = false;
|
||||
foreach ($rows as $row) {
|
||||
if (!empty($row->key)) {
|
||||
$preferences[$row->key] = $row->value;
|
||||
$update_keys[$row->key] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$queries = array();
|
||||
foreach ($preferences as $key => $value) {
|
||||
$value = $jinput->getString($key,0);
|
||||
if ($new_entry || empty($update_keys[$key])) {
|
||||
$query = 'INSERT INTO #__tabulizer_user_preferences (`user_id`, `key`, `value`) VALUES ('.$user_id.','.$db->quote($key).','.$db->quote($value).')';
|
||||
} else {
|
||||
$query = 'UPDATE #__tabulizer_user_preferences SET `value` = '.$db->quote($value).' WHERE `user_id` = '.$user_id .' AND `key` = '. $db->quote($key);
|
||||
}
|
||||
$queries[] = $query;
|
||||
}
|
||||
|
||||
foreach ($queries as $query) {
|
||||
if (!TabulizerDatabase::executeQuery($query,$error_msg,$db)) {
|
||||
$error_msg = JText::_('COM_TABULIZER_USER_PREFERENCES_DB_SAVE_ERROR').$error_msg;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function saveSystemPreferences(&$error_msg) {
|
||||
$db = JFactory::getDbo();
|
||||
$user = JFactory::getUser();
|
||||
$jinput = JFactory::getApplication()->input;
|
||||
|
||||
if ($user->guest) {
|
||||
$error_msg = JText::_('COM_TABULIZER_USER_PREFERENCES_NOT_LOGGED_ERROR');
|
||||
return false;
|
||||
}
|
||||
$user_id = 0; // 0 -> System user
|
||||
|
||||
$preferences = TabulizerInfo::getUserPreferences($error_msg, 'only');
|
||||
|
||||
// update or insert new preferences entry ?
|
||||
$new_entry = true;
|
||||
$update_keys = array();
|
||||
|
||||
$query = 'SELECT pref.* FROM #__tabulizer_user_preferences as pref WHERE user_id = ' . $user_id;
|
||||
$db->setQuery($query);
|
||||
|
||||
$rows = $db->loadObjectList();
|
||||
if (!empty($rows)) {
|
||||
$new_entry = false;
|
||||
foreach ($rows as $row) {
|
||||
if (!empty($row->key)) {
|
||||
$preferences[$row->key] = $row->value;
|
||||
$update_keys[$row->key] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$queries = array();
|
||||
foreach ($preferences as $key => $value) {
|
||||
$value = $jinput->getString($key,0);
|
||||
if ($new_entry || empty($update_keys[$key])) {
|
||||
$query = 'INSERT INTO #__tabulizer_user_preferences (`user_id`, `key`, `value`) VALUES ('.$user_id.','.$db->quote($key).','.$db->quote($value).')';
|
||||
} else {
|
||||
$query = 'UPDATE #__tabulizer_user_preferences SET `value` = '.$db->quote($value).' WHERE `user_id` = '.$user_id .' AND `key` = '. $db->quote($key);
|
||||
}
|
||||
$queries[] = $query;
|
||||
}
|
||||
|
||||
foreach ($queries as $query) {
|
||||
$db->setQuery($query);
|
||||
if (defined('JOOMLA_3_MODE')) {
|
||||
if (!$db->execute()) {
|
||||
$error_msg = JText::_('COM_TABULIZER_USER_PREFERENCES_DB_SAVE_ERROR');
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (!$db->query()) {
|
||||
$error_msg = JText::_('COM_TABULIZER_USER_PREFERENCES_DB_SAVE_ERROR') . $db->getErrorMsg();
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function loadAccessPermissions(&$error_msg) {
|
||||
// placeholder for other platforms
|
||||
}
|
||||
|
||||
function saveAccessPermissions(&$error_msg) {
|
||||
// placeholder for other platforms
|
||||
}
|
||||
|
||||
function getAccessPermissions() {
|
||||
return $this->user_permissions;
|
||||
}
|
||||
|
||||
function loadDataSources($limit, $limitstart, &$error_msg) {
|
||||
$jinput = JFactory::getApplication()->input;
|
||||
$option = $jinput->getCmd('option');
|
||||
$db = JFactory::getDbo();
|
||||
|
||||
$query = 'SELECT * FROM #__tabulizer_data_sources LIMIT '.intval($limitstart).', '.intval($limit);
|
||||
$db->setQuery($query);
|
||||
$rows = $db->loadObjectList();
|
||||
if (!empty($rows)) {
|
||||
foreach ($rows as $row) {
|
||||
if (!empty($row->key)) {
|
||||
$data_sources[$row->key] = $row->value;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$error_msg = JText::_('COM_TABULIZER_DATA_SOURCES_DB_LOAD_ERROR');
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->data_sources = $data_sources;
|
||||
return true;
|
||||
}
|
||||
|
||||
function getDataSources() {
|
||||
return $this->data_sources;
|
||||
}
|
||||
|
||||
function saveDataSource(&$error_msg) {
|
||||
$db = JFactory::getDbo();
|
||||
$user = JFactory::getUser();
|
||||
$jinput = JFactory::getApplication()->input;
|
||||
|
||||
if ($user->guest) {
|
||||
$error_msg = JText::_('COM_TABULIZER_DATA_SOURCES_NOT_LOGGED_ERROR');
|
||||
return false;
|
||||
}
|
||||
$user_id = $user->id;
|
||||
|
||||
$id = $jinput->getInt('ds_id', null);
|
||||
$tag = $jinput->getString('ds_tag', null);
|
||||
$source_type = $jinput->getString('ds_source_type', null);
|
||||
$source_params = $jinput->getString('ds_source_params', null);
|
||||
|
||||
$new_entry = (empty($id))?true:false;
|
||||
|
||||
if (empty($tag)||empty($source_type)||empty($source_params)) {
|
||||
$error_msg = JText::_('COM_TABULIZER_DATA_SOURCES_INVALID_PARAMS_ERROR');
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($new_entry) {
|
||||
$query = 'INSERT INTO #__tabulizer_data_sources (`tag`, `source_type`, `source_params`) VALUES ('.$db->quote($tag).','.$db->quote($source_type).','.$db->quote($source_params).')';
|
||||
} else {
|
||||
$query = 'UPDATE #__tabulizer_data_sources SET `tag` = '.$db->quote($tag).', `source_type`='.$db->quote($source_type).', `source_params`='.$db->quote($source_params);
|
||||
}
|
||||
|
||||
$db->setQuery($query);
|
||||
if (defined('JOOMLA_3_MODE')) {
|
||||
if (!$db->execute()) {
|
||||
$error_msg = JText::_('COM_TABULIZER_DATA_SOURCES_DB_SAVE_ERROR') . $db->getErrorMsg();
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (!$db->query()) {
|
||||
$error_msg = JText::_('COM_TABULIZER_DATA_SOURCES_DB_SAVE_ERROR') . $db->getErrorMsg();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function loadStatus() {
|
||||
TabulizerInfo::getSystemStatus($this->system_status);
|
||||
}
|
||||
|
||||
function getStatus() {
|
||||
return $this->system_status;
|
||||
}
|
||||
|
||||
function exportRulesetArchivesSkeletonCSSCode($export_archive_filenames = array()) {
|
||||
/* obsolete code */
|
||||
return $this->css_code;
|
||||
}
|
||||
|
||||
function getRulesetArchivesSkeletonCSSCode() {
|
||||
return $this->css_code;
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user