Your IP : 216.73.216.43


Current Path : /home/cbequiperp/www/plugins/system/installer_xtendr/templates/
Upload File :
Current File : /home/cbequiperp/www/plugins/system/installer_xtendr/templates/script.package.php

<?php
/**
 * @package     Smålabs Installer extender for Joomla
 *
 * @author      Jasper Dik <joomla@smalabs.net>
 * @link        https://www.smalabs.net
 * @copyright   Copyright © 2017  J.J.A.Dik / Smålabs. All rights reserved.
 * @license     GNU/GPL version 3 (https://www.gnu.org/licenses/gpl-3.0.html)
 */

// No direct access
defined('_JEXEC') or die();

/**
 * Template class that shows how to embed the Smålabs Installer Extendr into a Joomla installer script for
 * extension packages.
 *
 * @since   1.0
 */
class Template
{
    /**
     * @var     array
     *
     * @since   1.0
     */
    public $requirements = array(
        'joomla' => array(
            'min' => '1.2.3',
            'max' => '2.3.4',
        ),
        'php' => array(
            'min' => '1.2.3',
            'max' => '2.3.4',
        ),
    );

    /**
     * Array containing all information about the files that need to be deleted or moved from the install package to
     * their destination in the Joomla setup.
     * - The source path is relative to the install package directory
     * - The destination path is relative to the Joomla base directory
     * 
     * @var array
     *
     * @since   1.0
     */
    public $files = array(
        'move' => array(
            array(
                'src' => 'sourcePath',
                'dest' => 'destinationPath',
            ),
        ),
        'delete' => array(
            array('path' => 'filePath'),
        ),
    );

    /**
     * Array containing all information about the directories that need to be deleted or moved from the install package to
     * their destination in the Joomla setup.
     * - The source path is relative to the the install package directory
     * - The destination path is relative to the Joomla base directory
     * 
     * @var array
     *
     * @since   1.0
     */
    public $folder = array(
        'move' => array(
            array(
                'src' => 'sourcePath',
                'dest' => 'destinationPath',
            ),
        ),
        'delete' => array(
            array('path' => 'folderPath'),
        )
    );


    /**
     * List containing all the information about the extensions that should only be installed/updated when a previous
     * version of the extension is installed
     *
     * @var     array
     *
     * @since   1.0
     */
    public $install = array(
        array (
            'type'      => 'component',
            'id'        => 'com_template',
            'file'      => 'com_template-v123.zip',
            'downgrade' => true,                    // When set to false, it disallows updating to a lower version
            'updateOnly'=> false,                   // Only installs the update when a version of the extension is already installed
            'uninstall' => true,                    // When set to false, it does not uninstall the extension when the package is uninstalled
        ),
        array (
            'type'      => 'plugin',
            'group'     => 'system',
            'id'        => 'plg_template',
            'file'      => 'com_template-v123.zip',
            'downgrade' => true,
            'updateOnly'=> false,
            'uninstall' => true,
        ),
        array (
            'type'      => 'module',
            'client'    => 'site/admin',
            'id'        => 'mod_template',
            'file'      => 'com_template-v123.zip',
            'position'  => 'top',
            'downgrade' => true,
            'updateOnly'=> false,
            'uninstall' => true,
        ),
        array (
            'type'      => 'template',
            'client'    => 'site/admin',
            'id'        => 'tmpl_template',
            'file'      => 'tmpl_template-v123.zip',
            'downgrade' => true,
            'updateOnly'=> false,
            'uninstall' => true,
        ),
        array (
            'type'      => 'library',
            'id'        => 'lib_template',
            'file'      => 'lib_template-v123.zip',
            'downgrade' => true,
            'updateOnly'=> false,
            'uninstall' => true,
        ),
        array (
            'type'      => 'file',
            'id'        => 'file_template',
            'file'      => 'file_template-v123.zip',
            'downgrade' => true,
            'updateOnly'=> false,
            'uninstall' => true,
        ),
    );

    /**
     * List containing information about obsolete extensions that should be uninstalled when the package is installed or
     * updated.
     *
     * @var     array
     *
     * @since   1.0
     */
    public $uninstall = array(
        array (
            'type'      => 'component',
            'id'        => 'com_template',
        ),
        array (
            'type'      => 'plugin',
            'group'     => 'system',
            'id'        => 'plg_template',
        ),
        array (
            'type'      => 'module',
            'client'    => 'site/admin',
            'id'        => 'mod_template',
        ),
        array (
            'type'      => 'template',
            'client'    => 'site/admin',
            'id'        => 'tmpl_template',
        ),
        array (
            'type'      => 'library',
            'id'        => 'lib_template',
            'name'      => 'PKG_LIB_NAME',
            'desc'      => 'PKG_LIB_DESCRIPTION',
        ),
        array (
            'type'      => 'file',
            'id'        => 'file_template',
            'name'      => 'PKG_FILE_NAME',
            'desc'      => 'PKG_FILE_DESCRIPTION',
        ),
    );


    public $text = array(
        'type'          => 'component/plugin/module/...',
        'element'       => 'com_template',
        'category'        => 'site/admin (module/template), system/content/editor/... (plugin)',
        'header'       	=> 'COM_TEMPLATE_INSTALLER_HEADER',
        'install'       => 'COM_TEMPLATE_INSTALLER_INSTALL',
        'update'        => 'COM_TEMPLATE_INSTALLER_UPDATE',
        'uninstall'     => 'COM_TEMPLATE_INSTALLER_UNINSTALL',
        'url'			=> 'https://smalabs.net',
        'copyright'		=> '&copy; 2007 J.J.A.Dik / Sm&aring;labs',
    );


    /**
     * Method to run before the install/update/uninstall method
     * 
     * @param string                $task       Type of change made (install/update/uninstall)
     * @param \JAdapterInstance     $adapter    The object responsible for running this script
     * 
     * @return void
     *
     * @since   1.0
     */
    public function preflight($task, $adapter)
    {
        $this->installInstallerXtendr($adapter);
        
        \Smalabs\Joomla\Installer\Dispatcher\Package::preflight($adapter, $this, $task);
    }


    /**
     * Method to support installing an extension
     *
     * @param \JAdapterInstance     $adapter    The object responsible for running this script
     *
     * @return void
     *
     * @since   1.0
     */
    public function install($adapter)
    {
        \Smalabs\Joomla\Installer\Dispatcher\Package::install($adapter, $this);
    }


    /**
     * Method to support uninstalling an extension
     *
     * @param \JAdapterInstance     $adapter    The object responsible for running this script
     *
     * @return void
     *
     * @since   1.0
     */
    public function uninstall($adapter)
    {
        \Smalabs\Joomla\Installer\Dispatcher\Package::uninstall($adapter, $this);
    }


    /**
     * Method to support updating an extension
     *
     * @param \JAdapterInstance     $adapter    The object responsible for running this script
     *
     * @return void
     *
     * @since   1.0
     */
    public function update($adapter)
    {
        \Smalabs\Joomla\Installer\Dispatcher\Package::update($adapter, $this);
    }



    /**
     * Method to run after the install/update/uninstall method
     *
     * @param string                $task       Type of change made (install/update/uninstall)
     * @param \JAdapterInstance     $adapter    The object responsible for running this script
     *
     * @return void
     *
     * @since   1.0
     */
    public function postFlight($task, $adapter)
    {
        \Smalabs\Joomla\Installer\Dispatcher\Package::postflight($adapter, $this, $task);
    }


    /**
     * Checks if the Smålabs framework is installed and installs the update when required
     *
     * @param   \JAdapterInstance   $adapter    The object responsible for running this script
     *
     * @throws  \RuntimeException   
     * 
     * @return  bool                True on success or if an update was not required
     *
     * @throws  \Exception
     *
     * @since   1.0
     */
    protected function installInstallerXtendr($adapter)
    {
        $app = \JFactory::getApplication();
        $db = \JFactory::getDbo();

        // Check if the installer xtendr zip-file exists
        $sourcePath     = $adapter->getParent()->getPath('source');
        $sourcePkg      = $sourcePath . '/plg_system_installer_xtendr.zip';
        if (!\JFile::exists($sourcePkg))
        {
            throw new \Exception('Unable to install the package, could not locate the Installer extender');
        }

        // Extract the Installer Xtendr files
        $package            = \JInstallerHelper::unpack($sourcePkg);

        // Check the installer version. Only install versions that have the same or a higher version number
        if (!$newVersion = $this->getVersionFromManifest($package['dir'] . '/installer_xtendr.xml'))
        {
            throw new \Exception('Unable to locate manifest file for the Installer Extender');
        }

        if ($currentVersion = $this->getVersionFromManifest(JPATH_PLUGINS . '/system/installer_extendr/installer_extendr.xml'))
        {
            if ($currentVersion >= $newVersion)
            {
                return true;
            }
        }

        // Install the Installer Xtendr
        $xtendrInstaller    = new \JInstaller;
        try
        {
            $installResult = $xtendrInstaller->install($package['dir']);
        }
        catch (\Exception $e)
        {
            throw new \Exception('Failed to install the required Installer Extender. The following error was reported: ' . $e->getMessage());
        }

        // Publish the framework to enable the live update functionality
        $query = $db->getQuery(true)
            ->update($db->qn('#__extensions'))
            ->set($db->qn('enabled').' = '.$db->q('1'))
            ->where($db->qn('folder').' = '.$db->q('system'))
            ->where($db->qn('element').' = '.$db->q('installer_xtendr'));
        $db->setQuery($query);
        $db->execute();

        // The framework is now installed and enabled. If the namespace is not registered yet, register it now
        if (!class_exists('\Smalabs\Joomla\Installer\System\Language'))
        {
            \JLoader::registerNamespace('Smalabs\\Joomla\\Installer', JPATH_PLUGINS . '/system/installer_xtendr/libraries');
        }

        return true;
    }

    /**
     * Extracts the version from a manifest xml
     *
     * @param   string  $path
     *
     * @return  bool|string
     *
     * @since   1.0
     */
    protected function getVersionFromManifest($path)
    {
        if (!JFile::exists($path))
        {
            return false;
        }

        if (!$xml = simplexml_load_file($path))
        {
            return false;
        }

        return (string) $xml->version;
    }
}