187 lines
4.7 KiB
PHP
187 lines
4.7 KiB
PHP
<?php
|
|
/**
|
|
* @package System - JLSitemap Cron Plugin
|
|
* @version 1.12.0
|
|
* @author Joomline - joomline.ru
|
|
* @copyright Copyright (c) 2010 - 2022 Joomline. All rights reserved.
|
|
* @license GNU/GPL license: http://www.gnu.org/copyleft/gpl.html
|
|
* @link https://joomline.ru/
|
|
*/
|
|
|
|
defined('_JEXEC') or die;
|
|
|
|
use Joomla\CMS\Factory;
|
|
use Joomla\CMS\Filesystem\File;
|
|
use Joomla\CMS\Filesystem\Folder;
|
|
use Joomla\CMS\Filesystem\Path;
|
|
use Joomla\CMS\Installer\Installer;
|
|
use Joomla\CMS\Installer\InstallerAdapter;
|
|
use Joomla\CMS\Language\Text;
|
|
use Joomla\CMS\Log\Log;
|
|
|
|
class PlgSystemJLSitemap_CronInstallerScript
|
|
{
|
|
/**
|
|
* Runs right after any installation action.
|
|
*
|
|
* @param string $type Type of PostFlight action. Possible values are:
|
|
* @param InstallerAdapter $parent Parent object calling object.
|
|
*
|
|
* @return void
|
|
*
|
|
* @since 0.0.1
|
|
*/
|
|
function postflight($type, $parent)
|
|
{
|
|
// Enable plugin
|
|
if ($type == 'install')
|
|
{
|
|
$this->enablePlugin($parent);
|
|
}
|
|
|
|
// Parse layouts
|
|
$this->parseLayouts($parent->getParent()->getManifest()->layouts, $parent->getParent());
|
|
}
|
|
|
|
/**
|
|
* Enable plugin after installation
|
|
*
|
|
* @param InstallerAdapter $parent Parent object calling object.
|
|
*
|
|
* @return void
|
|
*
|
|
* @since 1.4.0
|
|
*/
|
|
protected function enablePlugin($parent)
|
|
{
|
|
// Prepare plugin object
|
|
$plugin = new stdClass();
|
|
$plugin->type = 'plugin';
|
|
$plugin->element = $parent->getElement();
|
|
$plugin->folder = (string) $parent->getParent()->manifest->attributes()['group'];
|
|
$plugin->enabled = 1;
|
|
|
|
// Update record
|
|
Factory::getDbo()->updateObject('#__extensions', $plugin, array('type', 'element', 'folder'));
|
|
}
|
|
|
|
/**
|
|
* Method to parse through a layout element of the installation manifest and take appropriate action.
|
|
*
|
|
* @param SimpleXMLElement $element The XML node to process.
|
|
* @param Installer $installer Installer calling object.
|
|
*
|
|
* @return boolean True on success
|
|
*
|
|
* @since 1.6.2
|
|
*/
|
|
public function parseLayouts(SimpleXMLElement $element, $installer)
|
|
{
|
|
if (!$element || !count($element->children()))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
// Get destination
|
|
$folder = ((string) $element->attributes()->destination) ? '/' . $element->attributes()->destination : null;
|
|
$destination = Path::clean(JPATH_ROOT . '/layouts' . $folder);
|
|
|
|
// Get source
|
|
$folder = (string) $element->attributes()->folder;
|
|
$source = ($folder && file_exists($installer->getPath('source') . '/' . $folder)) ?
|
|
$installer->getPath('source') . '/' . $folder : $installer->getPath('source');
|
|
|
|
// Prepare files
|
|
$copyFiles = array();
|
|
foreach ($element->children() as $file)
|
|
{
|
|
$path['src'] = Path::clean($source . '/' . $file);
|
|
$path['dest'] = Path::clean($destination . '/' . $file);
|
|
|
|
// Is this path a file or folder?
|
|
$path['type'] = $file->getName() === 'folder' ? 'folder' : 'file';
|
|
if (basename($path['dest']) !== $path['dest'])
|
|
{
|
|
$newdir = dirname($path['dest']);
|
|
if (!Folder::create($newdir))
|
|
{
|
|
Log::add(Text::sprintf('JLIB_INSTALLER_ERROR_CREATE_DIRECTORY', $newdir), Log::WARNING, 'jerror');
|
|
|
|
return false;
|
|
}
|
|
}
|
|
|
|
$copyFiles[] = $path;
|
|
}
|
|
|
|
return $installer->copyFiles($copyFiles);
|
|
}
|
|
|
|
/**
|
|
* This method is called after extension is uninstalled.
|
|
*
|
|
* @param InstallerAdapter $parent Parent object calling object.
|
|
*
|
|
* @return void
|
|
*
|
|
* @since 0.0.2
|
|
*/
|
|
public function uninstall($parent)
|
|
{
|
|
// Remove layouts
|
|
$this->removeLayouts($parent->getParent()->getManifest()->layouts);
|
|
}
|
|
|
|
/**
|
|
* Method to parse through a layouts element of the installation manifest and remove the files that were installed.
|
|
*
|
|
* @param SimpleXMLElement $element The XML node to process.
|
|
*
|
|
* @return boolean True on success
|
|
*
|
|
* @since 1.6.2
|
|
*/
|
|
protected function removeLayouts(SimpleXMLElement $element)
|
|
{
|
|
if (!$element || !count($element->children()))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
// Get the array of file nodes to process
|
|
$files = $element->children();
|
|
|
|
// Get source
|
|
$folder = ((string) $element->attributes()->destination) ? '/' . $element->attributes()->destination : null;
|
|
$source = Path::clean(JPATH_ROOT . '/layouts' . $folder);
|
|
|
|
// Process each file in the $files array (children of $tagName).
|
|
foreach ($files as $file)
|
|
{
|
|
$path = Path::clean($source . '/' . $file);
|
|
|
|
// Actually delete the files/folders
|
|
if (is_dir($path))
|
|
{
|
|
$val = Folder::delete($path);
|
|
}
|
|
else
|
|
{
|
|
$val = File::delete($path);
|
|
}
|
|
|
|
if ($val === false)
|
|
{
|
|
Log::add('Failed to delete ' . $path, Log::WARNING, 'jerror');
|
|
$retval = false;
|
|
}
|
|
}
|
|
|
|
if (!empty($folder))
|
|
{
|
|
Folder::delete($source);
|
|
}
|
|
|
|
return $retval;
|
|
}
|
|
} |