| Current Path : /home/smartconb/www/armencom33/administrator/components/com_eyesite/ |
| Current File : /home/smartconb/www/armencom33/administrator/components/com_eyesite/install.php |
<?php
/********************************************************************
Product : Eyesite
Date : 6 May 2024
Copyright : Les Arbres Design 2009-2024
Contact : https://www.lesarbresdesign.info
Licence : GNU General Public License
*********************************************************************/
defined('_JEXEC') or die('Restricted Access');
use Joomla\CMS\Factory;
use Joomla\CMS\Installer\Installer;
use Joomla\CMS\HTML\HTMLHelper;
class com_EyesiteInstallerScript
{
var $db;
var $previous_component_version;
var $app;
public function preflight($type, $parent)
{
if ($type == 'uninstall')
return;
$app = Factory::getApplication();
if (defined('JVERSION'))
$joomla_version = JVERSION; // get the Joomla version (JVERSION did not exist before Joomla 2.5)
else
$joomla_version = '1.x';
if (version_compare($joomla_version,"3.10","<"))
{
$app->enqueueMessage("Eyesite requires at least Joomla 3.10. Your version is $joomla_version", 'error');
return false;
}
// we only support MySql
$dbtype = $app->get('dbtype');
if (!strstr($dbtype,'mysql'))
{
$app->enqueueMessage("Eyesite currently only supports MYSQL databases. It cannot run with $dbtype", 'error');
return false;
}
$this->db = Factory::getDBO();
$db_version = $this->ladb_loadResult('select version()');
if (version_compare($db_version,"5.5.3","<"))
{
$app->enqueueMessage("Eyesite requires at least MySql 5.5.3. Your version is $db_version", 'error');
return false;
}
if (version_compare(PHP_VERSION,"5.3.0","<"))
{
$app->enqueueMessage("Eyesite requires at least PHP 5.3.0. Your version is ".PHP_VERSION, 'error');
return false;
}
// do not install if an old incompatible version of the plugin is installed
if (file_exists(JPATH_ROOT.'/plugins/system/eyesite/eyesite.xml'))
{
$xml_array = Installer::parseXMLInstallFile(JPATH_ROOT.'/plugins/system/eyesite/eyesite.xml');
$plugin_version = $xml_array['version'];
$plugin_major_version = substr($plugin_version,0,1);
if ($plugin_major_version < 5)
{
$app->enqueueMessage("Sorry, this version of Eyesite is not compatible with the version of the Eyesite Plugin currently installed ($plugin_version). ".
"Please uninstall or upgrade the Plugin before you install this version of Eyesite. We apologise for the inconvenience. ".
"The new version has NOT been installed.", 'error');
return false;
}
}
// get the previously installed version, if any
// also clean out some old files
if (file_exists(JPATH_ADMINISTRATOR.'/components/com_eyesite/eyesite.xml'))
{
$xml_array = Installer::parseXMLInstallFile(JPATH_ADMINISTRATOR.'/components/com_eyesite/eyesite.xml');
$this->previous_component_version = $xml_array['version'];
self::recurse_delete(JPATH_SITE."/administrator/components/com_eyesite/assets");
self::deleteAdminViews(array('help','history_list','history_item'));
}
return true;
}
public function uninstall($parent)
{
$this->db = Factory::getDBO();
$this->ladb_execute("DROP TABLE IF EXISTS `#__eye_site`;");
$this->ladb_execute("DROP TABLE IF EXISTS `#__eye_site_history`;");
$app = Factory::getApplication();
$app->enqueueMessage("Eyesite has been uninstalled", 'message');
return true;
}
//-------------------------------------------------------------------------------
// The main install function
//
public function postflight($type, $parent)
{
if ($type == 'uninstall')
return;
$this->app = Factory::getApplication();
// check the Joomla version
if (substr(JVERSION,0,1) > "5")
$this->app->enqueueMessage("This version of Eyesite has not been tested on this version of Joomla", 'notice');
// get the component version from the component manifest xml file
$component_version = $parent->getManifest()->version;
// delete redundant files from older versions
@unlink(JPATH_ROOT.'/administrator/components/com_eyesite/toolbar.eyesite.html.php');
@unlink(JPATH_ROOT.'/administrator/components/com_eyesite/toolbar.eyesite.php');
@unlink(JPATH_ROOT.'/administrator/components/com_eyesite/admin.eyesite.php');
@unlink(JPATH_ROOT.'/administrator/components/com_eyesite/admin.eyesite.html.php');
@unlink(JPATH_ROOT.'/administrator/components/com_eyesite/install.mysql.sql');
@unlink(JPATH_ROOT.'/administrator/components/com_eyesite/uninstall.mysql.sql');
@unlink(JPATH_ROOT.'/administrator/components/com_eyesite/joomla15.xml');
@unlink(JPATH_ROOT.'/administrator/components/com_eyesite/joomla16.xml');
@unlink(JPATH_ROOT.'/administrator/components/com_eyesite/download.eyesite.php');
@unlink(JPATH_ROOT.'/administrator/components/com_eyesite/common.eyesite.php');
@unlink(JPATH_ROOT.'/administrator/components/com_eyesite/eyesite_helper.php');
@unlink(JPATH_ROOT.'/administrator/components/com_eyesite/config.eyesite.php');
@unlink(JPATH_ROOT.'/administrator/components/com_eyesite/eyesite_log.txt');
@unlink(JPATH_ROOT.'/administrator/components/com_eyesite/install.eyesite.php');
@unlink(JPATH_ROOT.'/administrator/components/com_eyesite/forms/config.xml');
@unlink(JPATH_ROOT.'/administrator/components/com_eyesite/forms');
@unlink(JPATH_ROOT.'/administrator/components/com_eyesite/tid_notice.txt'); // re-created in the admin controller
@unlink(JPATH_ROOT.'/administrator/components/com_eyesite/latest_eyesite.xml'); // re-created by the about view
@unlink(JPATH_ROOT.'/administrator/components/com_eyesite/latest_plg_eyesite.xml'); // re-created by the about view
@unlink(JPATH_ROOT.'/administrator/components/com_eyesite/fields/tracebuttons.php');
@unlink(JPATH_ROOT.'/administrator/components/com_eyesite/assets/mail_ok.png');
@unlink(JPATH_ROOT.'/administrator/components/com_eyesite/assets/mail_no.png');
if (substr(JVERSION,0,1) > '3')
{
@unlink(JPATH_SITE.'/administrator/components/com_eyesite/assets/eyesite_j3.css');
self::recurse_delete(JPATH_SITE.'/administrator/components/com_eyesite/forms_j3');
self::recurse_delete(JPATH_SITE.'/administrator/components/com_eyesite/fields_j3');
}
// we now install language files in the component directory, so must remove them from the system-wide directory, since those would take precedence
// from version 5 the plugin language files are also installed in the plugin directory
$dirs = glob(JPATH_ADMINISTRATOR.'/language/*',GLOB_ONLYDIR);
foreach ($dirs as $dir)
{
$sub_dir = basename($dir);
@unlink($dir.'/'.$sub_dir.'.com_eyesite.ini');
@unlink($dir.'/'.$sub_dir.'.com_eyesite.sys.ini');
@unlink($dir.'/'.$sub_dir.'.plg_system_eyesite.ini');
}
// remove redundant http update sites, if present
$this->db = Factory::getDBO();
$this->ladb_execute_ignore("DELETE FROM `#__update_sites` WHERE `name` LIKE 'Eyesite%' AND SUBSTRING(`location`,1,5) = 'http:'");
// create our database tables - this will display an error if it fails
$this->ladb_execute("CREATE TABLE IF NOT EXISTS `#__eye_site` (
`id` int(11) NOT NULL auto_increment,
`filepath` text NOT NULL,
`md5` varchar(32) NOT NULL,
`state` tinyint(4) NOT NULL,
`datetime` datetime NOT NULL,
`filesize` bigint(20) NOT NULL,
`new_md5` varchar(32) NOT NULL,
`new_datetime` datetime NOT NULL,
`new_filesize` bigint(20) NOT NULL,
`date_added` datetime NOT NULL,
`date_checked` datetime NOT NULL,
PRIMARY KEY (`id`),
KEY `Filepath` (`filepath`(180))
) DEFAULT CHARSET=utf8mb4 COLLATE utf8mb4_unicode_ci AUTO_INCREMENT=1;");
$this->ladb_execute("CREATE TABLE IF NOT EXISTS `#__eye_site_history` (
`id` int(11) NOT NULL auto_increment,
`datetime` datetime NOT NULL,
`state` tinyint(4) NOT NULL,
`summary` varchar(255) NOT NULL,
`details` mediumtext NOT NULL,
PRIMARY KEY (`id`)
) DEFAULT CHARSET=utf8mb4 AUTO_INCREMENT=1;");
$this->ladb_execute("ALTER TABLE `#__eye_site` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci");
$this->ladb_execute("ALTER TABLE `#__eye_site_history` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci");
$this->ladb_execute("ALTER TABLE `#__eye_site` CHANGE `filepath` `filepath` TEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL");
// if updating from <v8.00 add xml to the list of file types to scan
if (isset($this->previous_component_version) && (version_compare($this->previous_component_version,"8.00", "<")) )
$this->upgrade_config();
// write an entry to the Eyesite history (state 14 = LAE_HISTORY_INFO)
$query = "INSERT INTO `#__eye_site_history` (`datetime`, `state`, `summary`, `details`)
VALUES (NOW(), 14, 'Installed Eyesite version $component_version', '')";
$this->ladb_execute($query);
// we are done, show the update or install message
if (isset($this->previous_component_version) && version_compare($this->previous_component_version,$component_version,"<"))
{
$url = 'https://www.lesarbresdesign.info/version-history/eyesite';
$link = HTMLHelper::link($url, $url, 'target="_blank"');
$this->app->enqueueMessage("Eyesite updated to version $component_version. Here's what changed: $link", 'message');
}
else
$this->app->enqueueMessage("Eyesite version $component_version installed.", 'message');
return true;
}
//-------------------------------------------------------------------------------
// When upgrading from version < 8.0 we add .xml to the list of extensions
//
function upgrade_config()
{
$query = "SELECT extension_id, `params` from `#__extensions` WHERE `type` = 'component' AND `element` = 'com_eyesite'";
$rows = $this->ladb_loadObjectList($query);
if ($rows === false)
return;
$row = $rows[0];
if (empty($row->params) || ($row->params == '{}'))
return; // no parameters yet
$config_data = json_decode($row->params);
if (empty($config_data->extensions))
return; // empty list - all extensions are scanned
$extensions_array = explode(",",$config_data->extensions);
$extensions_array = array_map('trim',$extensions_array);
$extensions_array = array_map('strtolower',$extensions_array);
if (in_array('xml', $extensions_array))
return; // xml is already in the list
$config_data->extensions .= ',xml';
$query = "UPDATE `#__extensions` SET `params` = ".$this->db->quote(json_encode($config_data))." WHERE `extension_id` = ".$row->extension_id;
$this->ladb_execute($query);
}
//-------------------------------------------------------------------------------
// Delete one or more back end views
//
static function deleteAdminViews($views)
{
foreach ($views as $view)
self::recurse_delete(JPATH_SITE."/administrator/components/com_eyesite/views/$view");
}
//-------------------------------------------------------------------------------
// Recursively delete a folder and all its contents
//
static function recurse_delete($dir)
{
if (!file_exists($dir))
return;
$files = array_diff(scandir($dir), array('.','..'));
foreach ($files as $file)
if (is_dir($dir.'/'.$file))
self::recurse_delete($dir.'/'.$file);
else
unlink($dir.'/'.$file);
rmdir($dir);
}
//-------------------------------------------------------------------------------
// Execute a SQL query and return true if it worked, false if it failed
//
function ladb_execute($query)
{
try
{
$this->db->setQuery($query);
$this->db->execute();
}
catch (RuntimeException $e)
{
$message = $e->getMessage();
$this->app->enqueueMessage($message, 'error');
return false;
}
return true;
}
//-------------------------------------------------------------------------------
// Execute a SQL query ignoring any errors
//
function ladb_execute_ignore($query)
{
try
{
$this->db->setQuery($query);
$this->db->execute();
}
catch (RuntimeException $e)
{
return;
}
return;
}
//-------------------------------------------------------------------------------
// Get an array of rows from the database and return it, or false if it failed
//
function ladb_loadObjectList($query)
{
try
{
$this->db->setQuery($query);
$result = $this->db->loadObjectList();
}
catch (RuntimeException $e)
{
$message = $e->getMessage();
$this->app->enqueueMessage($message, 'error');
return false;
}
return $result;
}
//-------------------------------------------------------------------------------
// Get a single value from the database as an object and return it, or false if it failed
//
function ladb_loadResult($query)
{
try
{
$this->db->setQuery($query);
$result = $this->db->loadResult();
}
catch (RuntimeException $e)
{
$message = $e->getMessage();
$this->app->enqueueMessage($message, 'error');
return false;
}
return $result;
}
}