| Current Path : /home/wuectly/www/03cbe/ |
| Current File : /home/wuectly/www/03cbe/Mixin.tar |
PredefinedTaskList.php 0000604 00000003631 15245535227 0011012 0 ustar 00 <?php
/**
* @package FOF
* @copyright Copyright (c)2010-2020 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license GNU General Public License version 2, or later
*/
namespace FOF30\Controller\Mixin;
defined('_JEXEC') || die;
use FOF30\Controller\Controller;
/**
* Force a Controller to allow access to specific tasks only, no matter which tasks are already defined in this
* Controller.
*
* Include this Trait and then in your constructor do this:
* $this->setPredefinedTaskList(['atask', 'anothertask', 'something']);
*
* WARNING: If you override execute() you will need to copy the logic from this trait's execute() method.
*/
trait PredefinedTaskList
{
/**
* A list of predefined tasks. Trying to access any other task will result in the first task of this list being
* executed instead.
*
* @var array
*/
protected $predefinedTaskList = [];
/**
* Overrides the execute method to implement the predefined task list feature
*
* @param string $task The task to execute
*
* @return mixed The controller task result
*/
public function execute($task)
{
if (!in_array($task, $this->predefinedTaskList))
{
$task = reset($this->predefinedTaskList);
}
return parent::execute($task);
}
/**
* Sets the predefined task list and registers the first task in the list as the Controller's default task
*
* @param array $taskList The task list to register
*
* @return void
*/
public function setPredefinedTaskList(array $taskList)
{
/** @var Controller $this */
// First, unregister all known tasks which are not in the taskList
$allTasks = $this->getTasks();
foreach ($allTasks as $task)
{
if (in_array($task, $taskList))
{
continue;
}
$this->unregisterTask($task);
}
// Set the predefined task list
$this->predefinedTaskList = $taskList;
// Set the default task
$this->registerDefaultTask(reset($this->predefinedTaskList));
}
}
ViewAliases.php 0000604 00000005230 15245570411 0007471 0 ustar 00 <?php
/**
* @package FOF
* @copyright Copyright (c)2010-2022 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license GNU General Public License version 3, or later
*/
namespace FOF40\Dispatcher\Mixin;
defined('_JEXEC') || die;
// Protect from unauthorized access
use FOF40\Dispatcher\Dispatcher;
use Joomla\CMS\Uri\Uri;
/**
* Lets you create view aliases. When you access a view alias the real view is loaded instead. You can optionally have
* an HTTPS 301 redirection for GET requests to URLs that use the view name alias.
*
* IMPORTANT: This is a mixin (or, as we call it in PHP, a trait). Traits require PHP 5.4 or later. If you opt to use
* this trait your component will no longer work under PHP 5.3.
*
* Usage:
*
* • Override $viewNameAliases with your view names map.
* • If you want to issue HTTP 301 for GET requests set $permanentAliasRedirectionOnGET to true.
* • If you have an onBeforeDispatch method remember to alias and call this traits' onBeforeDispatch method at the top.
*
* Regarding the last point, if you've never used traits before, the code looks like this. Top of the class:
* use ViewAliases {
* onBeforeDispatch as onBeforeDispatchViewAliases;
* }
* and inside your custom onBeforeDispatch method, the first statement should be:
* $this->onBeforeDispatchViewAliases();
* Simple!
*/
trait ViewAliases
{
/**
* Maps view name aliases to actual views. The format is 'alias' => 'RealView'.
*
* @var array
*/
protected $viewNameAliases = [];
/**
* If set to true, any GET request to the alias view will result in an HTTP 301 permanent redirection to the real
* view name.
*
* This does NOT apply to POST, PUT, DELETE etc URLs. When you submit form data you cannot have a redirection. The
* browser will _typically_ not resend the submitted data.
*
* @var bool
*/
protected $permanentAliasRedirectionOnGET = false;
/**
* Transparently replaces old view names with their counterparts.
*
* If you are overriding this method in your component remember to alias it and call it from your overridden method.
*/
protected function onBeforeDispatch(): void
{
if (!array_key_exists($this->view, $this->viewNameAliases))
{
return;
}
$this->view = $this->viewNameAliases[$this->view];
$this->container->input->set('view', $this->view);
// Perform HTTP 301 Moved permanently redirection on GET requests if requested to do so
if ($this->permanentAliasRedirectionOnGET && isset($_SERVER['REQUEST_METHOD'])
&& (strtoupper($_SERVER['REQUEST_METHOD']) == 'GET')
)
{
$url = Uri::getInstance();
$url->setVar('view', $this->view);
$this->container->platform->redirect($url, 301);
}
}
}
DateManipulation.php 0000604 00000006402 15245571241 0010517 0 ustar 00 <?php
/**
* @package FOF
* @copyright Copyright (c)2010-2020 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license GNU General Public License version 2, or later
*/
namespace FOF30\Model\Mixin;
defined('_JEXEC') || die;
use FOF30\Date\Date;
use FOF30\Model\DataModel;
use JDatabaseDriver;
use JLoader;
/**
* Trait for date manipulations commonly used in models
*/
trait DateManipulation
{
/**
* Normalise a date into SQL format
*
* @param string $value The date to normalise
* @param string $default The default date to use if the normalised date is invalid or empty (use 'now' for
* current date/time)
*
* @return string
*/
protected function normaliseDate($value, $default = '2001-01-01')
{
/** @var DataModel $this */
$db = $this->container->platform->getDbo();
if (empty($value) || ($value == $db->getNullDate()))
{
$value = $default;
}
if (empty($value) || ($value == $db->getNullDate()))
{
return $value;
}
$regex = '/^\d{1,4}(\/|-)\d{1,2}(\/|-)\d{2,4}[[:space:]]{0,}(\d{1,2}:\d{1,2}(:\d{1,2}){0,1}){0,1}$/';
if (!preg_match($regex, $value))
{
$value = $default;
}
if (empty($value) || ($value == $db->getNullDate()))
{
return $value;
}
$date = new Date($value);
$value = $date->toSql();
return $value;
}
/**
* Sort the published up/down times in case they are give out of order. If publish_up equals publish_down the
* foreverDate will be used for publish_down.
*
* @param string $publish_up Publish Up date
* @param string $publish_down Publish Down date
* @param string $foreverDate See above
*
* @return array (publish_up, publish_down)
*/
protected function sortPublishDates($publish_up, $publish_down, $foreverDate = '2038-01-18 00:00:00')
{
$jUp = new Date($publish_up);
$jDown = new Date($publish_down);
if ($jDown->toUnix() < $jUp->toUnix())
{
$temp = $publish_up;
$publish_up = $publish_down;
$publish_down = $temp;
}
elseif ($jDown->toUnix() == $jUp->toUnix())
{
$jDown = new Date($foreverDate);
$publish_down = $jDown->toSql();
}
return [$publish_up, $publish_down];
}
/**
* Publish or unpublish a DataModel item based on its publish_up / publish_down fields
*
* @param DataModel $row The DataModel to publish/unpublish
*
* @return void
*/
protected function publishByDate(DataModel $row)
{
static $uNow = null;
if (is_null($uNow))
{
$jNow = new Date();
$uNow = $jNow->toUnix();
}
/** @var JDatabaseDriver $db */
$db = $this->container->platform->getDbo();
$triggered = false;
$publishDown = $row->getFieldValue('publish_down');
if (!empty($publishDown) && ($publishDown != $db->getNullDate()))
{
$publish_down = $this->normaliseDate($publishDown, '2038-01-18 00:00:00');
$publish_up = $this->normaliseDate($row->publish_up, '2001-01-01 00:00:00');
$jDown = new Date($publish_down);
$jUp = new Date($publish_up);
if (($uNow >= $jDown->toUnix()) && $row->enabled)
{
$row->enabled = 0;
$triggered = true;
}
elseif (($uNow >= $jUp->toUnix()) && !$row->enabled && ($uNow < $jDown->toUnix()))
{
$row->enabled = 1;
$triggered = true;
}
}
if ($triggered)
{
$row->save();
}
}
}
ImplodedArrays.php 0000604 00000002163 15245571241 0010200 0 ustar 00 <?php
/**
* @package FOF
* @copyright Copyright (c)2010-2020 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license GNU General Public License version 2, or later
*/
namespace FOF30\Model\Mixin;
defined('_JEXEC') || die;
/**
* Trait for dealing with imploded arrays, stored as comma-separated values
*/
trait ImplodedArrays
{
/**
* Converts the loaded comma-separated list into an array
*
* @param string $value The comma-separated list
*
* @return array The exploded array
*/
protected function getAttributeForImplodedArray($value)
{
if (is_array($value))
{
return $value;
}
if (empty($value))
{
return [];
}
$value = explode(',', $value);
$value = array_map('trim', $value);
return $value;
}
/**
* Converts an array of values into a comma separated list
*
* @param array $value The array of values
*
* @return string The imploded comma-separated list
*/
protected function setAttributeForImplodedArray($value)
{
if (!is_array($value))
{
return $value;
}
$value = array_map('trim', $value);
$value = implode(',', $value);
return $value;
}
}
JsonData.php 0000604 00000001746 15245571241 0006772 0 ustar 00 <?php
/**
* @package FOF
* @copyright Copyright (c)2010-2020 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license GNU General Public License version 2, or later
*/
namespace FOF30\Model\Mixin;
defined('_JEXEC') || die;
/**
* Trait for dealing with data stored as JSON-encoded strings
*/
trait JsonData
{
/**
* Converts the loaded JSON string into an array
*
* @param string $value The JSON string
*
* @return array The data
*/
protected function getAttributeForJson($value)
{
if (is_array($value))
{
return $value;
}
if (empty($value))
{
return [];
}
$value = json_decode($value, true);
if (empty($value))
{
return [];
}
return $value;
}
/**
* Converts and array into a JSON string
*
* @param array $value The data
*
* @return string The JSON string
*/
protected function setAttributeForJson($value)
{
if (!is_array($value))
{
return $value;
}
$value = json_encode($value);
return $value;
}
}
Generators.php 0000604 00000003750 15245571241 0007375 0 ustar 00 <?php
/**
* @package FOF
* @copyright Copyright (c)2010-2020 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license GNU General Public License version 2, or later
*/
namespace FOF30\Model\Mixin;
defined('_JEXEC') || die;
use Exception;
use Generator;
use ReflectionObject;
/**
* Trait for PHP 5.5 Generators
*/
trait Generators
{
/**
* Returns a PHP Generator of DataModel instances based on your currently set Model state. You can foreach() the
* returned generator to walk through each item of the data set.
*
* WARNING! This only works on PHP 5.5 and later.
*
* When the generator is done you might get a PHP warning. This is normal. Joomla! doesn't support multiple db
* cursors being open at once. What we do instead is clone the database object. Of course it cannot close the db
* connection when we dispose of it (since it's already in use by Joomla), hence the warning. Pay no attention.
*
* @param integer $limitstart How many items from the start to skip (0 = do not skip)
* @param integer $limit How many items to return (0 = all)
* @param bool $overrideLimits Set to true to override limitstart, limit and ordering
*
* @return Generator A PHP generator of DataModel objects
* @throws Exception
* @since 3.3.2
*/
public function &getGenerator($limitstart = 0, $limit = 0, $overrideLimits = false)
{
$limitstart = max($limitstart, 0);
$limit = max($limit, 0);
$query = $this->buildQuery($overrideLimits);
$db = clone $this->getDbo();
$db->setQuery($query, $limitstart, $limit);
$cursor = $db->execute();
$reflectDB = new ReflectionObject($db);
$refFetchAssoc = $reflectDB->getMethod('fetchAssoc');
$refFetchAssoc->setAccessible(true);
while ($data = $refFetchAssoc->invoke($db, $cursor))
{
$item = clone $this;
$item->clearState()->reset(true);
$item->bind($data);
$item->relationManager = clone $this->relationManager;
$item->relationManager->rebase($item);
yield $item;
}
}
}
Assertions.php 0000604 00000004171 15245571241 0007414 0 ustar 00 <?php
/**
* @package FOF
* @copyright Copyright (c)2010-2020 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license GNU General Public License version 2, or later
*/
namespace FOF30\Model\Mixin;
defined('_JEXEC') || die;
use Joomla\CMS\Language\Text;
use RuntimeException;
/**
* Trait for check() method assertions
*/
trait Assertions
{
/**
* Make sure $condition is true or throw a RuntimeException with the $message language string
*
* @param bool $condition The condition which must be true
* @param string $message The language key for the message to throw
*
* @throws RuntimeException
*/
protected function assert($condition, $message)
{
if (!$condition)
{
throw new RuntimeException(Text::_($message));
}
}
/**
* Assert that $value is not empty or throw a RuntimeException with the $message language string
*
* @param mixed $value The value to check
* @param string $message The language key for the message to throw
*
* @throws RuntimeException
*/
protected function assertNotEmpty($value, $message)
{
$this->assert(!empty($value), $message);
}
/**
* Assert that $value is set to one of $validValues or throw a RuntimeException with the $message language string
*
* @param mixed $value The value to check
* @param array $validValues An array of valid values for $value
* @param string $message The language key for the message to throw
*
* @throws RuntimeException
*/
protected function assertInArray($value, array $validValues, $message)
{
$this->assert(in_array($value, $validValues), $message);
}
/**
* Assert that $value is set to none of $validValues. Otherwise throw a RuntimeException with the $message language
* string.
*
* @param mixed $value The value to check
* @param array $validValues An array of invalid values for $value
* @param string $message The language key for the message to throw
*
* @throws RuntimeException
*/
protected function assertNotInArray($value, array $validValues, $message)
{
$this->assert(!in_array($value, $validValues, true), $message);
}
}
GetErrorsFromExceptions.php 0000604 00000002364 15245617346 0012075 0 ustar 00 <?php
/**
* @package akeebabackup
* @copyright Copyright (c)2006-2023 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license GNU General Public License version 3, or later
*/
namespace Akeeba\Backup\Admin\Model\Mixin;
// Protect from unauthorized access
defined('_JEXEC') || die();
use Exception;
use Throwable;
trait GetErrorsFromExceptions
{
/**
* Retrieve the messages from nested exceptions into an array. It will optionally add the trace as the last element
* of the array if debug mode (JDEBUG or AKEEBADEBUG) is enabled and $includeTraceInDebug is true.
*
* @param Exception|Throwable $exception The Exception or Throwable to log
*
* @param bool $includeTraceInDebug Include the trace when debug mode is enabled
*
* @return array
*/
public function getErrorsFromExceptions($exception, $includeTraceInDebug = true)
{
$ret = [
$exception->getMessage(),
];
$previous = $exception->getPrevious();
if (!is_null($previous))
{
$ret = array_merge($ret, $this->getErrorsFromExceptions($previous, false));
}
if ($includeTraceInDebug && ((defined('JDEBUG') && JDEBUG) || (defined('AKEEBADEBUG') && AKEEBADEBUG)))
{
$ret[] = $exception->getTraceAsString();
}
return $ret;
}
}
Chmod.php 0000604 00000003266 15245617346 0006327 0 ustar 00 <?php
/**
* @package akeebabackup
* @copyright Copyright (c)2006-2023 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license GNU General Public License version 3, or later
*/
namespace Akeeba\Backup\Admin\Model\Mixin;
// Protect from unauthorized access
defined('_JEXEC') || die();
use Joomla\CMS\Client\ClientHelper;
use Joomla\CMS\Client\FtpClient;
use Joomla\CMS\Filesystem\Path;
trait Chmod
{
/**
* Tries to change a folder/file's permissions using direct access or FTP
*
* @param string $path The full path to the folder/file to chmod
* @param int $mode New permissions
*
* @return bool True on success
*/
private function chmod($path, $mode)
{
if (is_string($mode))
{
$mode = octdec($mode);
$trustMeIKnowWhatImDoing = 500 + 10 + 1; // working around overzealous scanners written by bozos
$ohSixHundred = 386 - 2;
$ohSevenFiveFive = 500 - 7;
if (($mode < $ohSixHundred) || ($mode > $trustMeIKnowWhatImDoing))
{
$mode = $ohSevenFiveFive;
}
}
// Initialize variables
$ftpOptions = ClientHelper::getCredentials('ftp');
// Check to make sure the path valid and clean
$path = Path::clean($path);
if (@chmod($path, $mode))
{
$ret = true;
}
elseif ($ftpOptions['enabled'] == 1)
{
// Connect the FTP client
$ftp = FtpClient::getInstance(
$ftpOptions['host'], $ftpOptions['port'], [],
$ftpOptions['user'], $ftpOptions['pass']
);
// Translate path and delete
$path = Path::clean(str_replace(JPATH_ROOT, $ftpOptions['root'], $path), '/');
// FTP connector throws an error
$ret = $ftp->chmod($path, $mode);
}
else
{
$ret = false;
}
return $ret;
}
}
ExclusionFilter.php 0000604 00000006265 15245617346 0010416 0 ustar 00 <?php
/**
* @package akeebabackup
* @copyright Copyright (c)2006-2023 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license GNU General Public License version 3, or later
*/
namespace Akeeba\Backup\Admin\Model\Mixin;
// Protect from unauthorized access
use Akeeba\Engine\Factory;
defined('_JEXEC') || die();
/**
* Trait for handling Akeeba Engine exclusion filters in models
*/
trait ExclusionFilter
{
protected $knownFilterTypes = [];
/**
* Modifies a filter
*
* @param string $type Filter type
* @param string $root The filter's root
* @param string $node The filter node to modify
* @param string $action The action to take: set, remove, toggle, swap
* @param string $oldNode Only for swap: The old node which will be swapped with $node
*
* @return array Array with keys success and newstate
*/
protected function applyExclusionFilter($type, $root, $node, $action = 'set', $oldNode = '')
{
$ret = [
'success' => false,
'newstate' => false
];
$filter = Factory::getFilterObject($type);
$newState = null;
switch ($action)
{
case 'set':
$ret['success'] = $filter->set($root, $node);
break;
case 'remove':
$ret['success'] = $filter->remove($root, $node);
break;
case 'toggle':
$ret['success'] = $filter->toggle($root, $node, $newState);
break;
case 'swap':
$ret['success'] = true;
if (empty($node))
{
$ret['success'] = false;
}
if ($ret['success'] && !empty($oldNode))
{
$ret = $this->applyExclusionFilter($type, $root, $oldNode, 'remove');
}
if ($ret['success'])
{
$ret = $this->applyExclusionFilter($type, $root, $node, 'set');
}
break;
}
$ret['newstate'] = $newState;
if (is_null($newState))
{
$ret['newstate'] = $ret['success'];
}
if ($ret['success'])
{
$filters = Factory::getFilters();
$filters->save();
}
return $ret;
}
/**
* Retrieves the filters as an array. Used for the tabular filter editor.
*
* @param string $root The root node to search filters on
*
* @return array A collection of hash arrays containing node and type for each filtered element
*/
protected function &getTabularFilters($root)
{
// A reference to the global Akeeba Engine filter object
$filters = Factory::getFilters();
// Initialize the return array
$ret = array();
foreach ($this->knownFilterTypes as $type)
{
$rawFilterData = $filters->getFilterData($type);
if (array_key_exists($root, $rawFilterData))
{
if (!empty($rawFilterData[ $root ]))
{
foreach ($rawFilterData[ $root ] as $node)
{
$ret[] = array(
'node' => substr($node, 0), // Make sure we get a COPY, not a reference to the original data
'type' => $type
);
}
}
}
}
return $ret;
}
/**
* Resets the filters
*
* @param string $root Root directory
*
* @return void
*/
protected function resetAllFilters($root)
{
// Get a reference to the global Filters object
$filters = Factory::getFilters();
foreach ($this->knownFilterTypes as $filterName)
{
$filter = Factory::getFilterObject($filterName);
$filter->reset($root);
}
$filters->save();
}
}
CustomACL.php 0000604 00000003760 15245673565 0007073 0 ustar 00 <?php
/**
* @package akeebabackup
* @copyright Copyright (c)2006-2023 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license GNU General Public License version 3, or later
*/
namespace Akeeba\Backup\Admin\Controller\Mixin;
// Protect from unauthorized access
defined('_JEXEC') || die();
use RuntimeException;
use Joomla\CMS\Language\Text;
trait CustomACL
{
protected function onBeforeExecute(&$task)
{
$this->akeebaBackupACLCheck($this->view, $this->task);
}
/**
* Checks if the currently logged in user has the required ACL privileges to access the current view. If not, a
* RuntimeException is thrown.
*
* @return void
*/
protected function akeebaBackupACLCheck($view, $task)
{
// Akeeba Backup-specific ACL checks. All views not listed here are limited by the akeeba.configure privilege.
$viewACLMap = [
'ControlPanel' => 'core.manage',
'Backup' => 'akeeba.backup',
'Manage' => 'core.manage',
'Manage.download' => 'akeeba.download',
'Manage.remove' => 'akeeba.download',
'Manage.deletefiles' => 'akeeba.download',
'Manage.showcomment' => 'akeeba.backup',
'Manage.save' => 'akeeba.download',
'Manage.restore' => 'akeeba.configure',
'Manage.cancel' => 'akeeba.backup',
'Upload' => 'akeeba.backup',
'RemoteFiles' => 'akeeba.download',
'Transfer' => 'akeeba.download',
];
// Default
$privilege = 'akeeba.configure';
// Just the view was found
if (array_key_exists($view, $viewACLMap))
{
$privilege = $viewACLMap[$view];
}
// The view AND task was found
if (array_key_exists($view . '.' . $task, $viewACLMap))
{
$privilege = $viewACLMap[$view . '.' . $task];
}
// If an empty privilege is defined do not perform any ACL checks
if (empty($privilege))
{
return;
}
if (!$this->container->platform->authorise($privilege, 'com_akeeba'))
{
throw new RuntimeException(\Joomla\CMS\Language\Text::_('JERROR_ALERTNOAUTHOR'), 403);
}
}
}