Files
conservatorio-tomadini/administrator/components/com_tabulizer/install/install.helper.php
2024-12-17 17:34:10 +01:00

540 lines
27 KiB
PHP

<?php
/**
* @package Tabulizer
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
**/
defined('_JEXEC') or die('Restricted access');
jimport('joomla.installer.installer');
jimport('joomla.installer.helper');
jimport('joomla.version');
class tabulizerInstallHelper {
private $app = null;
private $db = null;
private $parent = null;
private $status = null;
private $legacy = false;
public function __construct() {
$this->app = JFactory::getApplication();
$this->db = JFactory::getDBO();
$this->status = new JObject();
$this->status->plugins = array();
$this->status->extra = array();
$this->status->texts = array();
$this->status->operation = '';
}
private function executeQuery($query) {
$this->db->setQuery($query);
if (version_compare(JVERSION, '3', 'ge')) {
$this->db->execute();
} else {
$this->db->query();
}
}
private function setParent($parent) {
if (!$this->parent) {
$this->parent = $parent->getParent();
$this->manifest = $this->parent->getManifest();
}
$this->status->src = $this->parent->getPath('source');
$this->status->trg = $this->parent->getPath('extension_administrator');
$lang = JFactory::getLanguage();
$lang->load('com_tabulizer',JPATH_ADMINISTRATOR);
}
private function installPlugins() {
$plugins = &$this->manifest->plugins;
if (is_array($plugins)) $plugins = &$plugins[0];
if (isset($plugins)) {
$attributes = $plugins->attributes();
$folder = isset($attributes['folder']) ? $attributes['folder'] : 'plugins';
foreach ($plugins->children() as $plugin) {
$attributes = $plugin->attributes();
$name = isset($attributes['plugin']) ? $attributes['plugin'] : '';
$group = isset($attributes['group']) ? $attributes['group'] : '';
if (!empty($name) && !empty($group)) {
$path = $this->status->src.DIRECTORY_SEPARATOR.$folder.DIRECTORY_SEPARATOR.$group.DIRECTORY_SEPARATOR.$name;
$query = "SELECT 1 FROM #__extensions WHERE type='plugin' and element=".$this->db->Quote($name)." AND folder=".$this->db->Quote($group);
$this->db->setQuery($query);
$installed = $this->db->loadResult();
$installer = new JInstaller;
$result = $installer->install($path);
if ($result) {
if ($installed) $text_result = JText::_('COM_TABULIZER_INSTALL_UPDATED');
else $text_result = JText::_('COM_TABULIZER_INSTALL_INSTALLED');
} else {
if ($installed) $text_result = JText::_('COM_TABULIZER_INSTALL_NOT_UPDATED');
else $text_result = JText::_('COM_TABULIZER_INSTALL_NOT_INSTALLED');
}
$this->status->plugins[] = array('name'=>$name, 'group'=>$group, 'result'=>$result, 'text_result'=>$text_result);
if (!$installed) {
$query = "UPDATE #__extensions SET enabled=1 WHERE type='plugin' and element=".$this->db->Quote($name)." AND folder=".$this->db->Quote($group);
$this->executeQuery($query);
if (($name == 'tabulizercsslegacy') && ($group=='system') && (!$this->legacy)) {
$query = "UPDATE #__extensions SET enabled=0 WHERE type='plugin' and element=".$this->db->Quote($name)." AND folder=".$this->db->Quote($group);
$this->executeQuery($query);
}
if (($name == 'tabulizerds') && ($group=='search')) {
$query = "UPDATE #__extensions SET enabled=0 WHERE type='plugin' and element=".$this->db->Quote($name)." AND folder=".$this->db->Quote($group);
$this->executeQuery($query);
}
}
}
}
}
}
public function install($parent) {
$this->setParent($parent);
$this->status->operation = 'install';
$this->status->texts['ok'] = JText::_('COM_TABULIZER_INSTALL_INSTALLED');
$this->status->texts['ko'] = JText::_('COM_TABULIZER_INSTALL_NOT_INSTALLED');
$this->status->texts['heading'] = JText::_('COM_TABULIZER_INSTALL_INSTALL_HEADING');
$this->prepareTabulizerInstallation();
$this->installDatabaseTables();
$this->installPlugins();
}
private function uninstallPlugins() {
$plugins = &$this->manifest->plugins;
if (is_array($plugins)) $plugins = &$plugins[0];
if (isset($plugins)) {
foreach ($plugins->children() as $plugin) {
$attributes = $plugin->attributes();
$name = isset($attributes['plugin']) ? $attributes['plugin'] : '';
$group = isset($attributes['group']) ? $attributes['group'] : '';
if (!empty($name) && !empty($group)) {
$query = "SELECT extension_id FROM #__extensions WHERE type='plugin' and folder=".$this->db->Quote($group)." and element=".$this->db->Quote($name)."";
$this->db->setQuery($query);
$db_plugins = $this->db->loadObjectList();
$result = false;
if (count($db_plugins)) {
$result = true;
foreach ($db_plugins as $db_plugin) {
$installer = new JInstaller;
$result = $installer->uninstall('plugin', $db_plugin->extension_id, 0) && $result;
}
}
if ($result) $text_result = JText::_('COM_TABULIZER_INSTALL_REMOVED');
else $text_result = JText::_('COM_TABULIZER_INSTALL_NOT_REMOVED');
$this->status->plugins[] = array ('name'=>$name, 'group'=>$group, 'result'=>$result, 'text_result'=>$text_result);
}
}
}
}
/**
This is a Tabulizer only process that takes care of two things:
1. Creates the joomla library folder specific for Tabulizer, if it does not exist.
2. Checks to see if a previous (legacy) installation has rules and css files that need to be moved to the Tabulizer library folder
*/
private function prepareTabulizerInstallation() {
$library_path = JPATH_SITE .DIRECTORY_SEPARATOR. 'templates' .DIRECTORY_SEPARATOR. 'tabulizer';
# new directories that need to be created
$new_directories = array(
$library_path,
$library_path .DIRECTORY_SEPARATOR. 'rules',
$library_path .DIRECTORY_SEPARATOR. 'css',
$library_path .DIRECTORY_SEPARATOR. 'images',
$library_path .DIRECTORY_SEPARATOR. 'calc',
$library_path .DIRECTORY_SEPARATOR. 'modify',
$library_path .DIRECTORY_SEPARATOR. 'graph',
$library_path .DIRECTORY_SEPARATOR. 'js',
$library_path .DIRECTORY_SEPARATOR. 'language',
$library_path .DIRECTORY_SEPARATOR. 'htc',
$library_path .DIRECTORY_SEPARATOR. 'docs',
$library_path .DIRECTORY_SEPARATOR. 'themes',
$library_path .DIRECTORY_SEPARATOR. 'datasources',
$library_path .DIRECTORY_SEPARATOR. 'data',
$library_path .DIRECTORY_SEPARATOR. 'uploads',
$library_path .DIRECTORY_SEPARATOR. 'legacy', $library_path .DIRECTORY_SEPARATOR. 'legacy' .DIRECTORY_SEPARATOR. 'rules', $library_path .DIRECTORY_SEPARATOR. 'legacy' .DIRECTORY_SEPARATOR. 'css', $library_path .DIRECTORY_SEPARATOR. 'legacy' .DIRECTORY_SEPARATOR. 'images'
);
#some of them may already exists, so check for their existance before creating them
foreach ($new_directories as $new_directory) {
if (!file_exists($new_directory)) {
$result = @mkdir($new_directory, 0755, true);
if (!$result) {
$this->status->extra[] = array('name'=>JText::_('COM_TABULIZER_INSTALL_LIBRARY'),'result'=>false, 'text_result'=> JText::_('COM_TABULIZER_INSTALL_NOT_CREATED'));
$msg = sprintf(JText::_('COM_TABULIZER_INSTALL_WRONG_DIR_PERMISSIONS'),$new_directory);
JFactory::getApplication()->enqueueMessage($msg, 'warning');
return false;
}
$this->status->extra[] = array('name'=>JText::_('COM_TABULIZER_INSTALL_LIBRARY'),'result'=>true, 'text_result'=> JText::_('COM_TABULIZER_INSTALL_CREATED'));
}
}
# check to see if you need to move rulesets compatible with Tabulizer 2.5 to the new location
$old_library_path = JPATH_LIBRARIES .DIRECTORY_SEPARATOR. 'alterora/tabulizer';
$old_library_dirs = array($old_library_path.DIRECTORY_SEPARATOR. 'rules' => $library_path .DIRECTORY_SEPARATOR. 'rules',
$old_library_path.DIRECTORY_SEPARATOR. 'css' => $library_path .DIRECTORY_SEPARATOR. 'css',
$old_library_path.DIRECTORY_SEPARATOR. 'images' => $library_path .DIRECTORY_SEPARATOR. 'images');
foreach ($old_library_dirs as $old_dir => $new_dir) {
if (file_exists($old_dir)) {
$old_moved = true;
// copy all files
if ($handle = opendir($old_dir)) {
while (false !== ($entry = readdir($handle))) {
if (($entry != '.') && ($entry != '..')) {
$source_file = $old_dir .DIRECTORY_SEPARATOR. $entry;
$destination_file = $new_dir .DIRECTORY_SEPARATOR. $entry;
if (is_file($source_file) && !file_exists($destination_file)) {
$result = @copy($source_file, $destination_file);
if (!$result) {
$this->status->extra[] = array('name'=>JText::_('COM_TABULIZER_INSTALL_LIBRARY_OLD'),'result'=>false, 'text_result'=> JText::_('COM_TABULIZER_INSTALL_NOT_MOVED'));
$msg = sprintf(JText::_('COM_TABULIZER_INSTALL_WRONG_FILE_PERMISSIONS'),$destination_file);
JFactory::getApplication()->enqueueMessage($msg, 'warning');
return false;
}
}
}
}
closedir($handle);
}
}
}
# check to see if you need to create a legacy directory and activate the related system plugin
$legacy_dirs = array(JPATH_PLUGINS.DIRECTORY_SEPARATOR.'editors-xtd'.DIRECTORY_SEPARATOR. 'tabulizer' .DIRECTORY_SEPARATOR. 'tabulizer'.DIRECTORY_SEPARATOR. 'rules' => $library_path .DIRECTORY_SEPARATOR. 'legacy' .DIRECTORY_SEPARATOR. 'rules',
JPATH_PLUGINS.DIRECTORY_SEPARATOR.'editors-xtd'.DIRECTORY_SEPARATOR. 'tabulizer' .DIRECTORY_SEPARATOR. 'tabulizer'.DIRECTORY_SEPARATOR. 'css' => $library_path .DIRECTORY_SEPARATOR. 'legacy' .DIRECTORY_SEPARATOR. 'css',
JPATH_PLUGINS.DIRECTORY_SEPARATOR.'editors-xtd'.DIRECTORY_SEPARATOR. 'tabulizer' .DIRECTORY_SEPARATOR. 'tabulizer'.DIRECTORY_SEPARATOR. 'images' => $library_path .DIRECTORY_SEPARATOR. 'legacy' .DIRECTORY_SEPARATOR. 'images');
$legacy_moved = false;
foreach ($legacy_dirs as $legacy_dir => $new_dir) {
if (file_exists($legacy_dir)) {
$legacy_moved = true;
// copy all files
if ($handle = opendir($legacy_dir)) {
while (false !== ($entry = readdir($handle))) {
if (($entry != '.') && ($entry != '..')) {
$source_file = $legacy_dir .DIRECTORY_SEPARATOR. $entry;
$destination_file = $new_dir .DIRECTORY_SEPARATOR. $entry;
if (is_file($source_file) && !file_exists($destination_file)) {
$result = @copy($source_file, $destination_file);
if (!$result) {
$this->status->extra[] = array('name'=>JText::_('COM_TABULIZER_INSTALL_LIBRARY_LEGACY'),'result'=>false, 'text_result'=> JText::_('COM_TABULIZER_INSTALL_NOT_MOVED'));
$msg = sprintf(JText::_('COM_TABULIZER_INSTALL_WRONG_FILE_PERMISSIONS'),$destination_file);
JFactory::getApplication()->enqueueMessage($msg, 'warning');
return false;
}
}
}
}
closedir($handle);
}
} else if (file_exists($new_dir)) {
// check if the folder are empty
if ($handle = opendir($new_dir)) {
while (false !== ($entry = readdir($handle))) {
if (($entry != '.') && ($entry != '..')) {
$source_file = $new_dir .DIRECTORY_SEPARATOR. $entry;
if (is_file($source_file)){
$this->legacy = true;
break;
}
}
}
closedir($handle);
}
}
}
if ($legacy_moved) {
$this->legacy = true;
$this->status->extra[] = array('name'=>JText::_('COM_TABULIZER_INSTALL_LIBRARY_LEGACY'),'result'=>true, 'text_result'=> JText::_('COM_TABULIZER_INSTALL_MOVED'));
}
# uninstall the Tabulizer legacy system CSS plugin (if present)
$name = 'tabulizercss';
$group = 'system';
$query = "SELECT extension_id FROM #__extensions WHERE type='plugin' and folder=".$this->db->Quote($group)." and element=".$this->db->Quote($name)."";
$this->db->setQuery($query);
$db_plugin = $this->db->loadResult();
if ($db_plugin) {
$installer = new JInstaller;
$result = $installer->uninstall('plugin', $db_plugin, 0);
if ($result) $text_result = JText::_('COM_TABULIZER_INSTALL_REMOVED');
else $text_result = JText::_('COM_TABULIZER_INSTALL_NOT_REMOVED');
$this->status->plugins[] = array ('name'=>$name, 'group'=>$group, 'result'=>$result, 'text_result'=>$text_result);
}
# uninstall the rest of plugins from previous installations (if present)
$plugins = &$this->manifest->plugins;
if (is_array($plugins)) $plugins = &$plugins[0];
if (isset($plugins)) {
foreach ($plugins->children() as $plugin) {
$attributes = $plugin->attributes();
$name = isset($attributes['plugin']) ? $attributes['plugin'] : '';
$group = isset($attributes['group']) ? $attributes['group'] : '';
if (!empty($name) && !empty($group)) {
$query = "SELECT extension_id FROM #__extensions WHERE type='plugin' and folder=".$this->db->Quote($group)." and element=".$this->db->Quote($name)."";
$this->db->setQuery($query);
$db_plugins = $this->db->loadObjectList();
if (count($db_plugins)) {
$result = true;
foreach ($db_plugins as $db_plugin) {
$installer = new JInstaller;
$result = $installer->uninstall('plugin', $db_plugin->extension_id, 0) && $result;
}
if ($result) $text_result = JText::_('COM_TABULIZER_INSTALL_REMOVED');
else $text_result = JText::_('COM_TABULIZER_INSTALL_NOT_REMOVED');
$this->status->plugins[] = array ('name'=>$name, 'group'=>$group, 'result'=>$result, 'text_result'=>$text_result);
}
}
}
}
return true;
}
private function installDatabaseTables() {
$query = 'CREATE TABLE IF NOT EXISTS #__tabulizer_user_preferences ( `user_id` int(11) NOT NULL, `key` varchar(63) NOT NULL, `value` varchar(255) NOT NULL, PRIMARY KEY (`user_id`,`key`)) ENGINE=InnoDB DEFAULT CHARSET=utf8';
$this->executeQuery($query);
$query = 'CREATE TABLE IF NOT EXISTS #__tabulizer_user_permissions (`action` varchar(255) NOT NULL, `roles` varchar(255) NOT NULL, PRIMARY KEY (`action`)) ENGINE=InnoDB DEFAULT CHARSET=utf8';
$this->executeQuery($query);
$query = 'CREATE TABLE IF NOT EXISTS `#__tabulizer_data_source` (`id` int(11) NOT NULL AUTO_INCREMENT, `title` varchar(255) NOT NULL, `tag` varchar(255) NOT NULL, `source_type` varchar(24) NOT NULL, `source_params` text NOT NULL, `cache_type` int(11) NOT NULL DEFAULT \'0\', `cache_time` int(11) DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `tag` (`tag`)) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1';
$this->executeQuery($query);
$query = 'DROP TABLE IF EXISTS `#__tabulizer_data_source_cache`';
$this->executeQuery($query);
$query = 'CREATE TABLE IF NOT EXISTS `#__tabulizer_data_source_cache` (`cache_id` int(11) NOT NULL, `row_start` int(11) NOT NULL, `num_of_rows` int(11) NOT NULL, `num_of_columns` int(11) NOT NULL, `contents` mediumtext NOT NULL, PRIMARY KEY (`cache_id`,`row_start`)) ENGINE=InnoDB DEFAULT CHARSET=utf8';
$this->executeQuery($query);
$query = 'DROP TABLE IF EXISTS `#__tabulizer_data_source_cache_key_map`';
$this->executeQuery($query);
$query = 'CREATE TABLE IF NOT EXISTS `#__tabulizer_data_source_cache_key_map` (`cache_key` varchar(255) NOT NULL, `cache_id` bigint(20) unsigned NOT NULL, `cache_properties` varchar(255) DEFAULT NULL, `cache_expiration` int(11) DEFAULT NULL, `tag` varchar(255) NOT NULL, PRIMARY KEY (`cache_key`)) ENGINE=InnoDB DEFAULT CHARSET=utf8';
$this->executeQuery($query);
$query = 'DROP TABLE IF EXISTS `#__tabulizer_data_source_cache_properties`';
$this->executeQuery($query);
$query = 'CREATE TABLE IF NOT EXISTS `#__tabulizer_data_source_cache_properties` ( `id` int(11) NOT NULL, `cache_id` int(11) NOT NULL, `part_id` int(11) NOT NULL, `part_contents` mediumtext NOT NULL, PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;';
$this->executeQuery($query);
$query = 'DROP TABLE IF EXISTS `#__tabulizer_data_source_publishing_preferences`';
$this->executeQuery($query);
$query = 'CREATE TABLE IF NOT EXISTS `#__tabulizer_data_source_publishing_preferences` ( `id` int(11) NOT NULL AUTO_INCREMENT, `tag` varchar(255) NOT NULL, `status` int(11) NOT NULL DEFAULT \'0\', `mode` varchar(16) NOT NULL, `keyphrases` text, PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;';
$this->executeQuery($query);
}
private function updateDatabaseTables() {
$query = 'CREATE TABLE IF NOT EXISTS #__tabulizer_user_preferences ( `user_id` int(11) NOT NULL, `key` varchar(63) NOT NULL, `value` varchar(255) NOT NULL, PRIMARY KEY (`user_id`,`key`)) ENGINE=InnoDB DEFAULT CHARSET=utf8';
$this->executeQuery($query);
$query = 'CREATE TABLE IF NOT EXISTS #__tabulizer_user_permissions (`action` varchar(255) NOT NULL, `roles` varchar(255) NOT NULL, PRIMARY KEY (`action`)) ENGINE=InnoDB DEFAULT CHARSET=utf8';
$this->executeQuery($query);
$query = 'CREATE TABLE IF NOT EXISTS `#__tabulizer_data_source` (`id` int(11) NOT NULL AUTO_INCREMENT, `title` varchar(255) NOT NULL, `tag` varchar(255) NOT NULL, `source_type` varchar(24) NOT NULL, `source_params` text NOT NULL, `cache_type` int(11) NOT NULL DEFAULT \'0\', `cache_time` int(11) DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `tag` (`tag`)) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1';
$this->executeQuery($query);
$query = 'DROP TABLE IF EXISTS `#__tabulizer_data_source_cache`';
$this->executeQuery($query);
$query = 'CREATE TABLE IF NOT EXISTS `#__tabulizer_data_source_cache` (`cache_id` int(11) NOT NULL, `row_start` int(11) NOT NULL, `num_of_rows` int(11) NOT NULL, `num_of_columns` int(11) NOT NULL, `contents` mediumtext NOT NULL, PRIMARY KEY (`cache_id`,`row_start`)) ENGINE=InnoDB DEFAULT CHARSET=utf8';
$this->executeQuery($query);
$query = 'DROP TABLE IF EXISTS `#__tabulizer_data_source_cache_key_map`';
$this->executeQuery($query);
$query = 'CREATE TABLE IF NOT EXISTS `#__tabulizer_data_source_cache_key_map` (`cache_key` varchar(255) NOT NULL, `cache_id` bigint(20) unsigned NOT NULL, `cache_properties` varchar(255) DEFAULT NULL, `cache_expiration` int(11) DEFAULT NULL, `tag` varchar(255) NOT NULL, PRIMARY KEY (`cache_key`)) ENGINE=InnoDB DEFAULT CHARSET=utf8';
$this->executeQuery($query);
$query = 'DROP TABLE IF EXISTS `#__tabulizer_data_source_cache_properties`';
$this->executeQuery($query);
$query = 'CREATE TABLE IF NOT EXISTS `#__tabulizer_data_source_cache_properties` ( `id` int(11) NOT NULL, `cache_id` int(11) NOT NULL, `part_id` int(11) NOT NULL, `part_contents` mediumtext NOT NULL, PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;';
$this->executeQuery($query);
$query = 'DROP TABLE IF EXISTS `#__tabulizer_data_source_publishing_preferences`';
$this->executeQuery($query);
$query = 'CREATE TABLE IF NOT EXISTS `#__tabulizer_data_source_publishing_preferences` ( `id` int(11) NOT NULL AUTO_INCREMENT, `tag` varchar(255) NOT NULL, `status` int(11) NOT NULL DEFAULT \'0\', `mode` varchar(16) NOT NULL, `keyphrases` text, PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;';
$this->executeQuery($query);
}
private function uninstallDatabaseTables() {
$query = 'DROP TABLE IF EXISTS #__tabulizer_user_preferences';
$this->executeQuery($query);
$query = 'CREATE TABLE IF NOT EXISTS #__tabulizer_user_permissions (`action` varchar(255) NOT NULL, `roles` varchar(255) NOT NULL, PRIMARY KEY (`action`)) ENGINE=InnoDB DEFAULT CHARSET=utf8';
$this->executeQuery($query);
$query = 'DROP TABLE IF EXISTS `#__tabulizer_data_source`';
$this->executeQuery($query);
$query = 'DROP TABLE IF EXISTS `#__tabulizer_data_source_cache`';
$this->executeQuery($query);
$query = 'DROP TABLE IF EXISTS `#__tabulizer_data_source_cache_key_map`';
$this->executeQuery($query);
$query = 'DROP TABLE IF EXISTS `#__tabulizer_data_source_cache_properties`';
$this->executeQuery($query);
$query = 'DROP TABLE IF EXISTS `#__tabulizer_data_source_publishing_preferences`';
$this->executeQuery($query);
}
private function installNewRulesets() {
$library_path = JPATH_SITE .DIRECTORY_SEPARATOR. 'templates' .DIRECTORY_SEPARATOR. 'tabulizer';
# install new rulesets that came with the installation distribution (may override previous ones)
$installation_rulesets_dir = JPATH_ADMINISTRATOR .DIRECTORY_SEPARATOR. 'components/com_tabulizer/assets/rulesets/';
$installation_dirs = array(
$installation_rulesets_dir . 'rules' => $library_path .DIRECTORY_SEPARATOR. 'rules',
$installation_rulesets_dir . 'css' => $library_path .DIRECTORY_SEPARATOR. 'css',
$installation_rulesets_dir . 'images' => $library_path .DIRECTORY_SEPARATOR. 'images',
$installation_rulesets_dir . 'calc' => $library_path .DIRECTORY_SEPARATOR. 'calc',
$installation_rulesets_dir . 'modify' => $library_path .DIRECTORY_SEPARATOR. 'modify',
$installation_rulesets_dir . 'graph' => $library_path .DIRECTORY_SEPARATOR. 'graph',
$installation_rulesets_dir . 'js' => $library_path .DIRECTORY_SEPARATOR. 'js',
$installation_rulesets_dir . 'language' => $library_path .DIRECTORY_SEPARATOR. 'language',
$installation_rulesets_dir . 'htc' => $library_path .DIRECTORY_SEPARATOR. 'htc',
$installation_rulesets_dir . 'docs' => $library_path .DIRECTORY_SEPARATOR. 'docs',
$installation_rulesets_dir . 'themes' => $library_path .DIRECTORY_SEPARATOR. 'themes',
$installation_rulesets_dir . 'datasources' => $library_path .DIRECTORY_SEPARATOR. 'datasources',
$installation_rulesets_dir . 'data' => $library_path .DIRECTORY_SEPARATOR. 'data',
$installation_rulesets_dir . 'uploads' => $library_path .DIRECTORY_SEPARATOR. 'uploads'
);
$new_moved = false;
foreach ($installation_dirs as $installation_dir => $new_dir) {
if (file_exists($installation_dir)) {
$new_moved = true;
// copy all files
if ($handle = opendir($installation_dir)) {
while (false !== ($entry = readdir($handle))) {
if (($entry != '.') && ($entry != '..')) {
$source_file = $installation_dir .DIRECTORY_SEPARATOR. $entry;
$destination_file = $new_dir .DIRECTORY_SEPARATOR. $entry;
if (is_file($source_file) && !file_exists($destination_file)) {
$result = @copy($source_file, $destination_file);
if (!$result) {
$this->status->extra[] = array('name'=>JText::_('COM_TABULIZER_INSTALL_NEW_RULESETS'),'result'=>false, 'text_result'=> JText::_('COM_TABULIZER_INSTALL_NOT_INSTALLED'));
$msg = sprintf(JText::_('COM_TABULIZER_INSTALL_WRONG_FILE_PERMISSIONS'),$destination_file);
JFactory::getApplication()->enqueueMessage($msg, 'warning');
return false;
}
}
}
}
closedir($handle);
}
}
}
if ($new_moved) {
$this->status->extra[] = array('name'=>JText::_('COM_TABULIZER_INSTALL_NEW_RULESETS'),'result'=>true, 'text_result'=> JText::_('COM_TABULIZER_INSTALL_INSTALLED'));
}
}
public function uninstall($parent) {
$this->setParent($parent);
$this->status->operation = 'uninstall';
$this->status->texts['ok'] = JText::_('COM_TABULIZER_INSTALL_REMOVED');
$this->status->texts['ko'] = JText::_('COM_TABULIZER_INSTALL_NOT_REMOVED');
$this->status->texts['heading'] = JText::_('COM_TABULIZER_INSTALL_UNINSTALL_HEADING');
$this->uninstallDatabaseTables();
$this->uninstallPlugins();
$this->displayStatus();
}
public function update($parent) {
$this->setParent($parent);
$this->status->operation = 'update';
$this->status->texts['ok'] = JText::_('COM_TABULIZER_INSTALL_UPDATED');
$this->status->texts['ko'] = JText::_('COM_TABULIZER_INSTALL_NOT_UPDATED');
$this->status->texts['heading'] = JText::_('COM_TABULIZER_INSTALL_UPDATE_HEADING');
$this->prepareTabulizerInstallation();
$this->updateDatabaseTables();
$this->installPlugins();
}
public function postflight($type, $parent) {
$this->installNewRulesets();
$this->displayStatus();
}
private function displayStatus() {
$k = 0;
$status = &$this->status;
?>
<h2><?php echo $status->texts['heading']; ?></h2>
<table class="table table-striped" id="itemList">
<thead>
<tr>
<th class="title" colspan="2"><?php echo JText::_('COM_TABULIZER_INSTALL_EXTENSION'); ?></th>
<th width="30%" align="center"><?php echo JText::_('COM_TABULIZER_INSTALL_STATUS'); ?></th>
</tr>
</thead>
<tbody>
<tr class="row0">
<td class="key" colspan="2"><?php echo JText::_('COM_TABULIZER_INSTALL_COMPONENT'); ?></td>
<td><strong style="color: green;"><?php echo $status->texts['ok']; ?></strong></td>
</tr>
<?php if (count($status->plugins)) { ?>
<tr class="row<?php echo (++$k % 2); ?>">
<th><?php echo JText::_('COM_TABULIZER_INSTALL_PLUGIN'); ?></th>
<th><?php echo JText::_('COM_TABULIZER_INSTALL_GROUP'); ?></th>
<th>&nbsp;</th>
</tr>
<?php foreach ($status->plugins as $plugin) { ?>
<tr class="row<?php echo (++$k % 2); ?>">
<td class="key"><?php echo $plugin['name']; ?></td>
<td class="key"><?php echo $plugin['group']; ?></td>
<td><strong style="color: <?php echo ($plugin['result']) ? 'green' : 'red' ?>;"><?php echo $plugin['text_result']; ?></strong></td>
</tr>
<?php } ?>
<?php } ?>
<?php if (count($status->extra)) { ?>
<tr class="row<?php echo (++$k % 2); ?>">
<th colspan=2><?php echo JText::_('COM_TABULIZER_INSTALL_EXTRA'); ?></th>
<th>&nbsp;</th>
</tr>
<?php foreach ($status->extra as $extra) { ?>
<tr class="row<?php echo (++$k % 2); ?>">
<td class="key" colspan="2"><?php echo $extra['name']; ?></td>
<td><strong style="color: <?php echo ($extra['result']) ? 'green' : 'red' ?>;"><?php echo $extra['text_result']; ?></strong></td>
</tr>
<?php } ?>
<?php } ?>
</tbody>
</table>
<?php
if ($status->operation != 'uninstall') {
$lang = JFactory::getLanguage();
if (JFile::exists($status->trg.DIRECTORY_SEPARATOR.'install'.DIRECTORY_SEPARATOR.'notes'.DIRECTORY_SEPARATOR.$lang->getTag().'.php'))
require($status->trg.DIRECTORY_SEPARATOR.'install'.DIRECTORY_SEPARATOR.'notes'.DIRECTORY_SEPARATOR.$lang->getTag().'.php');
elseif (JFile::exists($status->trg.DIRECTORY_SEPARATOR.'install'.DIRECTORY_SEPARATOR.'notes'.DIRECTORY_SEPARATOR.'en-GB.php'))
require($status->trg.DIRECTORY_SEPARATOR.'install'.DIRECTORY_SEPARATOR.'notes'.DIRECTORY_SEPARATOR.'en-GB.php');
}
}
}
?>