<?php
/*
 * Copyright (c) 2017-2024 Aimy Extensions, Netzum Sorglos Software GmbH
 * Copyright (c) 2015-2017 Aimy Extensions, Lingua-Systems Software GmbH
 *
 * https://www.aimy-extensions.com/
 *
 * License: GNU GPLv2, see LICENSE.txt within distribution and/or
 *          https://www.aimy-extensions.com/software-license.html
 */
 defined( '_JEXEC' ) or die(); use Joomla\CMS\Factory; use Joomla\CMS\Uri\Uri; use Joomla\CMS\Language\Text; use Joomla\CMS\Router\Route; use Joomla\Registry\Registry; class plgSystemAimySpeedOptimizationInstallerScript { const V_JOOMLA_MIN = '3.9.0'; const V_PHP_MIN = '7.0.0'; public function preflight( $type, $adapter ) { $requiredPhpExts = array( 'dom', 'mbstring' ); foreach ( $requiredPhpExts as $ext ) { if ( ! extension_loaded( $ext ) ) { Factory::getApplication()->enqueueMessage( 'Aimy Speed Optimization requires the ' . '<b>' . ucfirst( $ext ) . ' PHP extension</b> to ' . 'be installed which is not the case on your system. ' . '<b>Please install the extension first!</b>', 'error' ); return false; } } return ( self::check_php_version( self::V_PHP_MIN ) && self::check_joomla_version( self::V_JOOMLA_MIN ) ); } public function postflight( $route, $adapter ) { $task = strtolower( $route ); if ( $task != 'install' && $task != 'update' ) { return; } Factory::getApplication()->setUserState( 'htaccess_state', false, 'aimyspeedoptimization' ); if ( $task == 'update' ) { if ( strpos( JVERSION, '3.' ) !== 0 ) { try { self::deleteExtensionParam( 'dl_key' ); } catch ( Exception $e ) { error_log( 'AimySpeedOptimization: ' . $e->getMessage() ); } } } if ( $task == 'install' ) { Factory::getLanguage()->load( 'plg_system_aimyspeedoptimization', JPATH_ADMINISTRATOR ); echo '<div style="padding:32px;text-align:center;">', '<h1>', '<img src="', Uri::base(), '../media/plg_aimyspeedoptimization/aimy-logo_340x327.png" ', 'width="340" height="327" alt="Aimy" />', '<br/>', 'Aimy Speed Optimization (PRO) v21.0', '</h1>', '<p class="lead">', Text::_( $task == 'update' ? 'AIMY_SO_HINT_UPDATED' : 'AIMY_SO_HINT_INSTALLED' ), '!', '</p>'; $cfg_url = false; $enabled = false; try { $db = Factory::getDbo(); $q = $db->getQuery( true ); $q->select( $db->quoteName( array( 'extension_id', 'enabled' ) ) ) ->from( $db->quoteName( '#__extensions' ) ) ->where( $db->quoteName( 'element' ) . ' = ' . $db->quote( 'aimyspeedoptimization' ) ) ->where( $db->quoteName( 'type' ) . ' = ' . $db->quote( 'plugin' ) ); $db->setQuery( $q ); $row = $db->loadObject(); if ( $row && $row->extension_id ) { $cfg_url = Route::_( 'index.php?' . 'option=com_plugins&task=plugin.edit&' . 'extension_id=' . $row->extension_id ); $enabled = $row->enabled; } } catch ( Exception $e ) {} echo '<p>'; if ( $cfg_url ) { echo self::_btn( $cfg_url, Text::_( ! $enabled ? 'AIMY_SO_HINT_ENABLE_CONFIGURE' : 'AIMY_SO_HINT_CONFIGURE' ) ), ' &nbsp; '; } echo self::_btn( 'https://www.aimy-extensions.com/joomla/speed-optimization.html#user-manual', Text::_( 'AIMY_SO_HINT_READ_MANUAL' ), true ), ' &nbsp; ', self::_btn( 'https://aimy-extensions.com/images/products/speed-optimization/plg-aimy-speed-optimization.pdf?v=21.0', Text::_( 'AIMY_SO_HINT_DL_MANUAL' ), false ), '</p>'; echo '<p style="padding:12px 0;" />', '<a href="https://www.aimy-extensions.com/joomla/speed-optimization.html" target="_blank">https://www.aimy-extensions.com/joomla/speed-optimization.html</a>', '</p>', '</div>', "\n"; } } public function uninstall( $parent ) { require_once( JPATH_ROOT . '/plugins/system/aimyspeedoptimization/HtaccessHelper.php' ); $app = Factory::getApplication(); if ( AimySpeedOptimizationHtaccessHelper::htaccess_exists() ) { try { AimySpeedOptimizationHtaccessHelper::cleanup(); Factory::getLanguage()->load( 'plg_system_aimyspeedoptimization', JPATH_ADMINISTRATOR ); $app->enqueueMessage( 'Aimy Speed Optimization: ' . Text::_( 'AIMY_SO_MSG_HTACCESS_UPDATED' ) ); } catch ( Exception $e ) { $app->enqueueMessage( 'Aimy Speed Optimization: ' . $e->getMessage(), 'error' ); } } return true; } static private function _btn( $url, $text, $new_tab = false ) { return '<a class="btn btn-lg btn-success" href="' . $url . '" ' . ( $new_tab ? 'target="_blank" ' : '' ) . 'role="button" style="color:#FFF">' . $text . '!' . '</a>'; } static private function check_php_version( $min ) { if ( version_compare( PHP_VERSION, $min, '<' ) ) { Factory::getApplication()->enqueueMessage( 'You are currently using PHP ' . PHP_VERSION . ', ' . 'but Aimy Speed Optimization requires at least PHP ' . $min . '.', 'error' ); return false; } return true; } static private function check_joomla_version( $min ) { $jv = defined( 'JVERSION' ) ? JVERSION : 0; if ( version_compare( $jv, $min, '<' ) ) { Factory::getApplication()->enqueueMessage( 'You are currently using Joomla! ' . $jv . ', ' . 'but Aimy Speed Optimization requires at least Joomla! ' . $min . '.', 'error' ); return false; } return true; } static private function deleteExtensionParam( $name ) { $element = ( 'plg' == 'com' ? 'com_' : '' ) . 'aimyspeedoptimization'; $db = Factory::getDbo(); $q = $db->getQuery( true ); $q->select( $db->quoteName( 'params' ) ) ->from( $db->quoteName( '#__extensions' ) ) ->where( $db->quoteName( 'element' ) . ' = ' . $db->quote( $element ) ); $db->setQuery( $q ); $rv = $db->loadResult(); if ( empty( $rv ) ) { return false; } $params = new Registry(); $params->loadString( $rv ); if ( ! $params or ! $params->exists( $name ) ) { return false; } $params->remove( $name ); $q = $db->getQuery( true ); $q->update( $db->quoteName( '#__extensions' ) ) ->set( $db->quoteName( 'params' ) . ' = ' . $db->quote( $params->toString() ) ) ->where( $db->quoteName( 'element' ) . ' = ' . $db->quote( $element ) ); $db->setQuery( $q ); return $db->execute(); } } 
