| Current Path : /home/purehotels/public_html/administrator/components/com_easyfolderlistingpro/ |
| Current File : /home/purehotels/public_html/administrator/components/com_easyfolderlistingpro/script.php |
<?php
/**
* @version 3.2.12
* @author Michael A. Gilkes (michael@valorapps.com)
* @copyright Michael Albert Gilkes
* @license GNU/GPLv3
Easy Folder Listing Pro Component for Joomla!
Copyright (C) 2012-2016 Michael Albert Gilkes (Valor Apps)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
jimport('joomla.installer.installer');
class com_easyfolderlistingproInstallerScript
{
/**
* Called before any type of action. Method to run before an install/update/uninstall method.
*
* @param string $route Which action is happening (install|update|discover_install)
* @param JAdapterInstance $parent The object responsible for running this script
*
* @return boolean True on success
*/
function preflight($route, $adapter)
{
}
/**
* Called on installation
*
* @param JAdapterInstance $adapter The object responsible for running this script
*
* @return boolean True on success
*/
function install($adapter)
{
$this->handleSQLupdates();
}
/**
* Called on update
*
* @param JAdapterInstance $adapter The object responsible for running this script
*
* @return boolean True on success
*/
function update($adapter)
{
$results = $this->handleSQLupdates();
$this->showSqlResults($results);
}
/**
* Called on uninstallation
*
* @param JAdapterInstance $adapter The object responsible for running this script
*/
function uninstall($adapter)
{
$results = $this->uninstallExtensions();
$this->displayResults($results, false);
}
/**
* Called after any type of action. Method to run after an install/update/discover_install method.
*
* @param string $route Which action is happening (install|update|discover_install)
* @param JAdapterInstance $adapter The object responsible for running this script
*
* @return boolean True on success
*/
function postflight($route, $adapter)
{
$results = $this->installExtensions($adapter);
$this->displayResults($results);
}
/**
* Dynamically adds new columns to sql tables or removes old columns from sql tables
*
* Notes:
* - modaltype (#__eflp_profiles) added in version 3.1.6
* - iconsafter (#__eflp_profiles) added in version 3.1.8
* - nofilesfound (#__eflp_profiles) added in version 3.2.10
* - emptylistingpath (#__eflp_profiles) added in version 3.2.10
* - useraccessnotallowed (#__eflp_profiles) added in version 3.2.10
* - unpublishedlisting (#__eflp_profiles) added in version 3.2.10
* - obfuscatelink (#__eflp_profiles) added in version 3.2.12
*/
private function handleSQLupdates()
{
$db = JFactory::getDbo();
$new_cols = array(
array('add' => true, 'result' => 'VALORAPPS_NOCHANGE', 'column' => 'modaltype', 'table' => '#__eflp_profiles', 'type' => "varchar(50) NOT NULL DEFAULT 'auto'", 'after' => 'modalheight'),
array('add' => true, 'result' => 'VALORAPPS_NOCHANGE', 'column' => 'iconsafter', 'table' => '#__eflp_profiles', 'type' => "tinyint(3) unsigned NOT NULL DEFAULT '1'", 'after' => 'previewer'),
array('add' => true, 'result' => 'VALORAPPS_NOCHANGE', 'column' => 'unpublishedlisting', 'table' => '#__eflp_profiles', 'type' => "tinyint(3) unsigned NOT NULL DEFAULT '1'", 'after' => 'method'),
array('add' => true, 'result' => 'VALORAPPS_NOCHANGE', 'column' => 'useraccessnotallowed', 'table' => '#__eflp_profiles', 'type' => "tinyint(3) unsigned NOT NULL DEFAULT '1'", 'after' => 'method'),
array('add' => true, 'result' => 'VALORAPPS_NOCHANGE', 'column' => 'emptylistingpath', 'table' => '#__eflp_profiles', 'type' => "tinyint(3) unsigned NOT NULL DEFAULT '1'", 'after' => 'method'),
array('add' => true, 'result' => 'VALORAPPS_NOCHANGE', 'column' => 'nofilesfound', 'table' => '#__eflp_profiles', 'type' => "tinyint(3) unsigned NOT NULL DEFAULT '1'", 'after' => 'method'),
array('add' => true, 'result' => 'VALORAPPS_NOCHANGE', 'column' => 'obfuscatelink', 'table' => '#__eflp_profiles', 'type' => "tinyint(3) unsigned NOT NULL DEFAULT '1'", 'after' => 'download')
);
foreach ($new_cols as $i => $col_array)
{
$found_before = array_key_exists($col_array['column'], $db->getTableColumns($col_array['table']));
if ($col_array['add'] == true && $found_before === false)
{
$query = "ALTER IGNORE TABLE `{$col_array['table']}` ADD COLUMN `{$col_array['column']}` {$col_array['type']} AFTER `{$col_array['after']}`";
$db->setQuery($query);
$db->execute();
}
elseif ($col_array['add'] == false && $found_before == true)
{
$query = "ALTER IGNORE TABLE `{$col_array['table']}` DROP COLUMN `{$col_array['column']}`";
$db->setQuery($query);
$db->execute();
}
$found_after = array_key_exists($col_array['column'], $db->getTableColumns($col_array['table']));
if ($col_array['add'] == true && $found_before === false && $found_after == true)
{
$new_cols[$i]['result'] = 'VALORAPPS_ADDED';
}
elseif ($col_array['add'] == false && $found_before == true && $found_after === false)
{
$new_cols[$i]['result'] = 'VALORAPPS_REMOVED';
}
}
return $new_cols;
}
private function showSqlResults($results)
{
$html = '<h1>'.JText::_('VALORAPPS_SQLUPDATES_HEADING').'</h1>'."\n";
$html.= '<table class="table table-bordered">'."\n";
$html.= ' <thead>'."\n";
$html.= ' <tr>'."\n";
$html.= ' <th class="title">'.JText::_('VALORAPPS_SQLTABLE_HEADING').'</th>'."\n";
$html.= ' <th width="30%">'.JText::_('VALORAPPS_SQLCOLUMN_HEADING').'</th>'."\n";
$html.= ' <th width="30%">'.JText::_('VALORAPPS_SQLRESULT_HEADING').'</th>'."\n";
$html.= ' </tr>'."\n";
$html.= ' </thead>'."\n";
$html.= ' <tbody>'."\n";
foreach ($results as $k => $result)
{
$html.= ' <tr class="row'.($k % 2).'">'."\n";
$html.= ' <td>'.$result['table'].'</td>'."\n";
$html.= ' <td>'.$result['column'].' '.$result['type'].'</td>'."\n";
$html.= ' <td>'.JText::_($result['result']).'</td>'."\n";
$html.= ' </tr>'."\n";
}
$html.= ' </tbody>'."\n";
$html.= '</table>'."\n".'<br />';
echo $html;
}
private function installExtensions($adapter)
{
$results = $this->extensionData();
$source = $adapter->getParent()->getPath('source');
for ($i = 0; $i < count($results); $i++)
{
$installer = new JInstaller();
$installer->setOverwrite(true);
$plugin_path = $source.DIRECTORY_SEPARATOR.'extensions'.DIRECTORY_SEPARATOR.$results[$i]['source'];
$results[$i]['status'] = $installer->install($plugin_path);
}
return $results;
}
private function uninstallExtensions()
{
$results = $this->extensionData();
$db = JFactory::getDbo();
for ($i = 0; $i < count($results); $i++)
{
$db->setQuery('SELECT `extension_id` FROM #__extensions WHERE `type` = "'.$results[$i]['type'].'" AND `element` = "'.$results[$i]['element'].'" AND `folder` = "'.$results[$i]['folder'].'"');
$id = $db->loadResult();
if($id)
{
$installer = new JInstaller();
$results[$i]['status'] = $installer->uninstall($results[$i]['type'], $id);
}
}
return $results;
}
private function extensionData()
{
$results = array();
//easyfolderlistingpro plugin
$results[0]['name'] = JText::_('COM_EFLP_COMPANION_CONTENT_PLUGIN');
$results[0]['type'] = "plugin";
$results[0]['element'] = "easyfolderlistingpro";
$results[0]['source'] = "plg_easyfolderlistingpro";
$results[0]['folder'] = "content";
$results[0]['status'] = false;
//easyfolderlistingpro-xtd plugin
$results[1]['name'] = JText::_('COM_EFLP_COMPANION_CODEHELPER_PLUGIN');
$results[1]['type'] = "plugin";
$results[1]['element'] = "easyfolderlistingpro";
$results[1]['source'] = "plg_easyfolderlistingpro-xtd";
$results[1]['folder'] = "editor-xtd";
$results[1]['status'] = false;
//easyfolderlistingpro module
$results[2]['name'] = JText::_('COM_EFLP_COMPANION_MODULE');
$results[2]['type'] = "module";
$results[2]['element'] = "mod_easyfolderlistingpro";
$results[2]['source'] = "mod_easyfolderlistingpro";
$results[2]['folder'] = "";
$results[2]['status'] = false;
return $results;
}
private function displayResults($results, $install = true)
{
$heading = JText::_('COM_EFLP_INSTALLATION_HEADING');
if ($install == false)
{
$heading = JText::_('COM_EFLP_UNINSTALLATION_HEADING');
}
$html = '<h1>'.$heading.'</h1>'."\n";
$html.= '<table class="table table-bordered">'."\n";
$html.= ' <thead>'."\n";
$html.= ' <tr>'."\n";
$html.= ' <th class="title">'.JText::_('VALORAPPS_EXTENSIONS_NAME_HEADING').'</th>'."\n";
$html.= ' <th width="30%">'.JText::_('VALORAPPS_EXTENSIONS_TYPE_HEADING').'</th>'."\n";
$html.= ' <th width="30%">'.JText::_('VALORAPPS_EXTENSIONS_STATUS_HEADING').'</th>'."\n";
$html.= ' </tr>'."\n";
$html.= ' </thead>'."\n";
$html.= ' <tbody>'."\n";
foreach ($results as $k => $result)
{
$html.= ' <tr class="row'.($k % 2).'">'."\n";
$html.= ' <td>'.$result['name'].'</td>'."\n";
$html.= ' <td>'.$result['folder'].' '.$result['type'].'</td>'."\n";
$html.= ' <td><span style="color: '.(($result['status']) ? 'green;">'.JText::_('VALORAPPS_EXTENSIONS_SUCCESS') : 'red;">'.JText::_('VALORAPPS_EXTENSIONS_FAIL')).'</span></td>'."\n";
$html.= ' </tr>'."\n";
}
$html.= ' </tbody>'."\n";
$html.= '</table>'."\n";
echo $html;
}
}