first commit
This commit is contained in:
34
plugins/system/jlsitemap_cron/fields/date.php
Normal file
34
plugins/system/jlsitemap_cron/fields/date.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?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\Form\FormField;
|
||||
|
||||
class JFormFieldDate extends FormField
|
||||
{
|
||||
/**
|
||||
* The form field type.
|
||||
*
|
||||
* @var string
|
||||
*
|
||||
* @since 1.0.1
|
||||
*/
|
||||
protected $type = 'date';
|
||||
|
||||
/**
|
||||
* Name of the layout being used to render the field
|
||||
*
|
||||
* @var string
|
||||
*
|
||||
* @since 1.0.1
|
||||
*/
|
||||
protected $layout = 'plugins.system.jlsitemap_cron.fields.date';
|
||||
}
|
||||
46
plugins/system/jlsitemap_cron/fields/key.php
Normal file
46
plugins/system/jlsitemap_cron/fields/key.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?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\Form\FormField;
|
||||
|
||||
class JFormFieldKey extends FormField
|
||||
{
|
||||
/**
|
||||
* The form field type.
|
||||
*
|
||||
* @var string
|
||||
*
|
||||
* @since 0.0.2
|
||||
*/
|
||||
protected $type = 'key';
|
||||
|
||||
/**
|
||||
* Name of the layout being used to render the field
|
||||
*
|
||||
* @var string
|
||||
*
|
||||
* @since 0.0.2
|
||||
*/
|
||||
protected $layout = 'plugins.system.jlsitemap_cron.fields.key';
|
||||
|
||||
/**
|
||||
* Method to get the field label markup.
|
||||
*
|
||||
* @return string The field label markup.
|
||||
*
|
||||
* @since 0.0.2
|
||||
*/
|
||||
protected function getLabel()
|
||||
{
|
||||
return '';
|
||||
}
|
||||
}
|
||||
59
plugins/system/jlsitemap_cron/fields/link.php
Normal file
59
plugins/system/jlsitemap_cron/fields/link.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?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\Application\SiteApplication;
|
||||
use Joomla\CMS\Form\FormField;
|
||||
use Joomla\CMS\Uri\Uri;
|
||||
|
||||
class JFormFieldLink extends FormField
|
||||
{
|
||||
/**
|
||||
* The form field type.
|
||||
*
|
||||
* @var string
|
||||
*
|
||||
* @since 0.0.2
|
||||
*/
|
||||
protected $type = 'link';
|
||||
|
||||
/**
|
||||
* Name of the layout being used to render the field
|
||||
*
|
||||
* @var string
|
||||
*
|
||||
* @since 0.0.2
|
||||
*/
|
||||
protected $layout = 'plugins.system.jlsitemap_cron.fields.link';
|
||||
|
||||
/**
|
||||
* Method to get the data to be passed to the layout for rendering.
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @since 0.0.2
|
||||
*/
|
||||
protected function getLayoutData()
|
||||
{
|
||||
$site = SiteApplication::getInstance('site');
|
||||
$router = $site->getRouter();
|
||||
$root = Uri::getInstance()->toString(array('scheme', 'host', 'port'));
|
||||
$link = 'index.php?option=com_ajax&plugin=jlsitemap_cron&group=system&format=raw';
|
||||
$link = $router->build($link)->toString();
|
||||
$link = str_replace('/?', '?', $link);
|
||||
$link = $root . $link;
|
||||
|
||||
$data = parent::getLayoutData();
|
||||
$data['link'] = $link;
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
213
plugins/system/jlsitemap_cron/jlsitemap_cron.php
Normal file
213
plugins/system/jlsitemap_cron/jlsitemap_cron.php
Normal file
@@ -0,0 +1,213 @@
|
||||
<?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\Application\SiteApplication;
|
||||
use Joomla\CMS\Date\Date;
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\HTML\HTMLHelper;
|
||||
use Joomla\CMS\Language\Text;
|
||||
use Joomla\CMS\MVC\Model\BaseDatabaseModel;
|
||||
use Joomla\CMS\Plugin\CMSPlugin;
|
||||
use Joomla\CMS\Uri\Uri;
|
||||
use Joomla\Registry\Registry;
|
||||
|
||||
class PlgSystemJLSitemap_Cron extends CMSPlugin
|
||||
{
|
||||
/**
|
||||
* Affects constructor behavior. If true, language files will be loaded automatically.
|
||||
*
|
||||
* @var boolean
|
||||
*
|
||||
* @since 0.0.2
|
||||
*/
|
||||
protected $autoloadLanguage = true;
|
||||
|
||||
/**
|
||||
* Cron last run date.
|
||||
*
|
||||
* @var string
|
||||
*
|
||||
* @since 1.10.1
|
||||
*/
|
||||
protected $_lastRun = null;
|
||||
|
||||
/**
|
||||
* Method to add cron js.
|
||||
*
|
||||
* @throws Exception
|
||||
*
|
||||
* @since 0.0.2
|
||||
*/
|
||||
public function onBeforeRender()
|
||||
{
|
||||
if ($this->params->get('client_enable') && $this->checkCacheTime())
|
||||
{
|
||||
$app = Factory::getApplication();
|
||||
$mode = $this->params->get('client_mode', 'all');
|
||||
if ($mode == 'all' || ($mode == 'admin' && $app->isClient('administrator')) || ($mode == 'site' && $app->isClient('site')))
|
||||
{
|
||||
// Set params
|
||||
$site = SiteApplication::getInstance('site');
|
||||
$router = $site->getRouter();
|
||||
$link = 'index.php?option=com_ajax&plugin=jlsitemap_cron&group=system&format=json';
|
||||
$link = str_replace('administrator/', '', $router->build($link)->toString());
|
||||
$link = str_replace('/?', '?', $link);
|
||||
$link = trim(Uri::root(true), '/') . '/' . trim($link, '/');
|
||||
|
||||
$params = array('ajax_url' => $link);
|
||||
Factory::getDocument()->addScriptOptions('jlsitemap_cron', $params);
|
||||
|
||||
// Add script
|
||||
HTMLHelper::_('script', 'media/plg_system_jlsitemap_cron/js/cron.min.js', array('version' => 'auto'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to run cron
|
||||
*
|
||||
* @throws Exception
|
||||
*
|
||||
* @return bool True on success, False on failure.
|
||||
*
|
||||
* @since 0.0.2
|
||||
*/
|
||||
public function onAjaxJlsitemap_cron()
|
||||
{
|
||||
$app = Factory::getApplication();
|
||||
$generate = false;
|
||||
$error = '';
|
||||
$clientRun = $this->params->get('client_enable');
|
||||
|
||||
// Client checks
|
||||
if ($clientRun)
|
||||
{
|
||||
if ($this->checkCacheTime())
|
||||
{
|
||||
$generate = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
$error = Text::_('PLG_SYSTEM_JLSITEMAP_GENERATION_ERROR_CACHE');
|
||||
}
|
||||
}
|
||||
|
||||
// Server checks
|
||||
if (!$clientRun)
|
||||
{
|
||||
if (!$this->params->get('key_enabled'))
|
||||
{
|
||||
$generate = true;
|
||||
}
|
||||
elseif (!$generate = ($app->input->get('key', '') == $this->params->get('key')))
|
||||
{
|
||||
$error = Text::_('PLG_SYSTEM_JLSITEMAP_GENERATION_ERROR_KEY');
|
||||
}
|
||||
}
|
||||
|
||||
// Run generation
|
||||
if (!$error && $generate && $urls = $this->generate())
|
||||
{
|
||||
$success = Text::sprintf('PLG_SYSTEM_JLSITEMAP_GENERATION_SUCCESS', count($urls->includes),
|
||||
count($urls->excludes), count($urls->all));
|
||||
|
||||
// Prepare json response
|
||||
if ($app->input->get('format', 'raw') == 'json')
|
||||
{
|
||||
$success = explode('<br>', $success);
|
||||
}
|
||||
|
||||
return $success;
|
||||
}
|
||||
elseif ($error)
|
||||
{
|
||||
throw new Exception(Text::sprintf('PLG_SYSTEM_JLSITEMAP_GENERATION_FAILURE', $error));
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to generate site map.
|
||||
*
|
||||
* @throws Exception
|
||||
*
|
||||
* @return object|false Sitemap generation result on success, False on failure.
|
||||
*
|
||||
* @since 0.0.2
|
||||
*/
|
||||
protected function generate()
|
||||
{
|
||||
try
|
||||
{
|
||||
// Update last run
|
||||
$this->params->set('last_run', Factory::getDate()->toSql());
|
||||
$plugin = new stdClass();
|
||||
$plugin->type = 'plugin';
|
||||
$plugin->element = 'jlsitemap_cron';
|
||||
$plugin->folder = 'system';
|
||||
$plugin->params = (string) $this->params;
|
||||
Factory::getDbo()->updateObject('#__extensions', $plugin, array('type', 'element', 'folder'));
|
||||
|
||||
// Run generation
|
||||
/* @var $model JLSitemapModelSitemap */
|
||||
BaseDatabaseModel::addIncludePath(JPATH_SITE . '/components/com_jlsitemap/models');
|
||||
$model = BaseDatabaseModel::getInstance('Sitemap', 'JLSitemapModel', array('ignore_request' => true));
|
||||
|
||||
if (!$result = $model->generate())
|
||||
{
|
||||
throw new Exception(Text::sprintf('PLG_SYSTEM_JLSITEMAP_GENERATION_FAILURE', $model->getError()));
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
throw new Exception(Text::sprintf('PLG_SYSTEM_JLSITEMAP_GENERATION_FAILURE', $e->getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to check client cache time
|
||||
*
|
||||
* @return bool True if run. False if don't run
|
||||
*
|
||||
* @since 0.0.2
|
||||
*/
|
||||
protected function checkCacheTime()
|
||||
{
|
||||
if ($this->_lastRun === null)
|
||||
{
|
||||
$db = Factory::getDbo();
|
||||
$query = $db->getQuery('true')
|
||||
->select('params')
|
||||
->from('#__extensions')
|
||||
->where($db->quoteName('type') . ' = ' . $db->quote('plugin'))
|
||||
->where($db->quoteName('element') . ' = ' . $db->quote('jlsitemap_cron'))
|
||||
->where($db->quoteName('folder') . ' = ' . $db->quote('system'));
|
||||
$params = new Registry($db->setQuery($query)->loadResult());
|
||||
$this->_lastRun = $params->get('last_run', false);
|
||||
}
|
||||
|
||||
if (!$this->_lastRun)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// Prepare cache time
|
||||
$offset = ' + ' . $this->params->get('client_cache_number', 1) . ' ' .
|
||||
$this->params->get('client_cache_value', 'day');
|
||||
$cache = new Date($this->_lastRun . $offset);
|
||||
|
||||
return (Factory::getDate()->toUnix() >= $cache->toUnix());
|
||||
}
|
||||
}
|
||||
83
plugins/system/jlsitemap_cron/jlsitemap_cron.xml
Normal file
83
plugins/system/jlsitemap_cron/jlsitemap_cron.xml
Normal file
@@ -0,0 +1,83 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<extension version="3.9" type="plugin" group="system" method="upgrade">
|
||||
<name>PLG_SYSTEM_JLSITEMAP_CRON</name>
|
||||
<author>Joomline</author>
|
||||
<creationDate>13.04.2022</creationDate>
|
||||
<copyright>Copyright (c) 2010 - 2022 Joomline. All rights reserved.</copyright>
|
||||
<license>http://www.gnu.org/copyleft/gpl.html GNU/GPL</license>
|
||||
<authorEmail>sale@joomline.ru</authorEmail>
|
||||
<authorUrl>https://joomline.ru/</authorUrl>
|
||||
<version>1.12.0</version>
|
||||
<description>PLG_SYSTEM_JLSITEMAP_CRON_DESCRIPTION</description>
|
||||
<scriptfile>script.php</scriptfile>
|
||||
<languages folder="language">
|
||||
<language tag="en-GB">en-GB/en-GB.plg_system_jlsitemap_cron.ini</language>
|
||||
<language tag="en-GB">en-GB/en-GB.plg_system_jlsitemap_cron.sys.ini</language>
|
||||
<language tag="ru-RU">ru-RU/ru-RU.plg_system_jlsitemap_cron.ini</language>
|
||||
<language tag="ru-RU">ru-RU/ru-RU.plg_system_jlsitemap_cron.sys.ini</language>
|
||||
</languages>
|
||||
<files>
|
||||
<filename plugin="jlsitemap_cron">jlsitemap_cron.php</filename>
|
||||
<folder>fields</folder>
|
||||
</files>
|
||||
<config>
|
||||
<fields name="params" addfieldpath="/plugins/system/jlsitemap_cron/fields">
|
||||
<fieldset name="basic">
|
||||
<field name="link" type="link" label="PLG_SYSTEM_JLSITEMAP_CRON_PARAMS_LINK"/>
|
||||
<field name="last_run" type="date"
|
||||
readonly="true"
|
||||
class="readonly"
|
||||
label="PLG_SYSTEM_JLSITEMAP_CRON_PARAMS_LAST_RUN"/>
|
||||
<field name="key_enabled" type="radio"
|
||||
label="PLG_SYSTEM_JLSITEMAP_CRON_PARAMS_KEY"
|
||||
default="0"
|
||||
class="btn-group btn-group-yesno"
|
||||
showon="client_enable:0">
|
||||
<option value="0">JNO</option>
|
||||
<option value="1">JYES</option>
|
||||
</field>
|
||||
<field name="key" type="key" showon="key_enabled:1[AND]client_enable:0"/>
|
||||
<field name="client_enable" type="radio"
|
||||
label="PLG_SYSTEM_JLSITEMAP_CRON_PARAMS_CLIENT"
|
||||
default="0"
|
||||
class="btn-group btn-group-yesno">
|
||||
<option value="0">JNO</option>
|
||||
<option value="1">JYES</option>
|
||||
</field>
|
||||
<field name="client_mode" type="radio"
|
||||
label="PLG_SYSTEM_JLSITEMAP_CRON_PARAMS_CLIENT_MODE"
|
||||
default="all"
|
||||
class="btn-group btn-group-yesno"
|
||||
showon="client_enable:1">
|
||||
<option value="all">PLG_SYSTEM_JLSITEMAP_CRON_PARAMS_CLIENT_MODE_ALL</option>
|
||||
<option value="admin">PLG_SYSTEM_JLSITEMAP_CRON_PARAMS_CLIENT_MODE_ADMIN</option>
|
||||
<option value="site">PLG_SYSTEM_JLSITEMAP_CRON_PARAMS_CLIENT_MODE_SITE</option>
|
||||
</field>
|
||||
<field name="client_cache_number" type="number"
|
||||
label="PLG_SYSTEM_JLSITEMAP_CRON_PARAMS_CLIENT_CACHE"
|
||||
default="1"
|
||||
min="1"
|
||||
step="1"
|
||||
showon="client_enable:1"/>
|
||||
<field name="client_cache_value" type="list"
|
||||
label=" "
|
||||
default="day"
|
||||
showon="client_enable:1">
|
||||
<option value="minutes">PLG_SYSTEM_JLSITEMAP_CRON_PARAMS_CLIENT_CACHE_MINUTES</option>
|
||||
<option value="hours">PLG_SYSTEM_JLSITEMAP_CRON_PARAMS_CLIENT_CACHE_HOURS</option>
|
||||
<option value="day">PLG_SYSTEM_JLSITEMAP_CRON_PARAMS_CLIENT_CACHE_DAY</option>
|
||||
<option value="week">PLG_SYSTEM_JLSITEMAP_CRON_PARAMS_CLIENT_CACHE_WEEK</option>
|
||||
<option value="month">PLG_SYSTEM_JLSITEMAP_CRON_PARAMS_CLIENT_CACHE_MONTH</option>
|
||||
<option value="year">PLG_SYSTEM_JLSITEMAP_CRON_PARAMS_CLIENT_CACHE_YEAR</option>
|
||||
</field>
|
||||
</fieldset>
|
||||
</fields>
|
||||
</config>
|
||||
<media destination="plg_system_jlsitemap_cron" folder="media">
|
||||
<folder>css</folder>
|
||||
<folder>js</folder>
|
||||
</media>
|
||||
<layouts destination="plugins/system/jlsitemap_cron" folder="layouts">
|
||||
<folder>fields</folder>
|
||||
</layouts>
|
||||
</extension>
|
||||
187
plugins/system/jlsitemap_cron/script.php
Normal file
187
plugins/system/jlsitemap_cron/script.php
Normal file
@@ -0,0 +1,187 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user