| Current Path : /proc/1908984/root/proc/self/root/proc/self/root/proc/2411249/cwd/ |
| Current File : //proc/1908984/root/proc/self/root/proc/self/root/proc/2411249/cwd/Json.php.tar |
home/digilove/public_html/110/libraries/src/Input/Json.php 0000644 00000003342 15235156057 0017400 0 ustar 00 <?php
/**
* Joomla! Content Management System
*
* @copyright (C) 2012 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\CMS\Input;
defined('JPATH_PLATFORM') or die;
use Joomla\CMS\Filter\InputFilter;
/**
* Joomla! Input JSON Class
*
* This class decodes a JSON string from the raw request data and makes it available via
* the standard JInput interface.
*
* @since 3.0.1
* @deprecated 5.0 Use Joomla\Input\Json instead
*/
class Json extends Input
{
/**
* @var string The raw JSON string from the request.
* @since 3.0.1
* @deprecated 5.0 Use Joomla\Input\Json instead
*/
private $_raw;
/**
* Constructor.
*
* @param array $source Source data (Optional, default is the raw HTTP input decoded from JSON)
* @param array $options Array of configuration parameters (Optional)
*
* @since 3.0.1
* @deprecated 5.0 Use Joomla\Input\Json instead
*/
public function __construct(array $source = null, array $options = array())
{
if (isset($options['filter']))
{
$this->filter = $options['filter'];
}
else
{
$this->filter = InputFilter::getInstance();
}
if (is_null($source))
{
$this->_raw = file_get_contents('php://input');
$this->data = json_decode($this->_raw, true);
if (!is_array($this->data))
{
$this->data = array();
}
}
else
{
$this->data = &$source;
}
$this->options = $options;
}
/**
* Gets the raw JSON string from the request.
*
* @return string The raw JSON string from the request.
*
* @since 3.0.1
* @deprecated 5.0 Use Joomla\Input\Json instead
*/
public function getRaw()
{
return $this->_raw;
}
}
home/digilove/public_html/components/com_akeeba/Model/Json.php 0000644 00000015644 15235163333 0020533 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\Site\Model;
// Protect from unauthorized access
defined('_JEXEC') || die();
use Akeeba\Backup\Site\Controller\Mixin\FrontEndPermissions;
use Akeeba\Backup\Site\Model\Json\Encapsulation;
use Akeeba\Backup\Site\Model\Json\Task;
use Akeeba\Engine\Platform;
use Akeeba\Engine\Util\Complexify;
use FOF40\Container\Container;
use FOF40\Model\Model;
// JSON API version number
define('AKEEBA_JSON_API_VERSION', '400');
/*
* Short API version history:
* 300 First draft. Basic backup working. Encryption semi-broken.
* 316 Fixed download feature.
* 320 Minor bug fixes
* 330 Introduction of Akeeba Solo
* 335 Configuration overrides in startBackup
* 340 Advanced API allows full configuration
* 350 exportConfiguration, importConfiguration
* 400 API version 2
*
* Notes:
*
* When support for non-Raw encapsulations was removed December 2019 the API level was left at 350 (same
* since May 2016). If you see API level 350 try using only ever using the RAW encapsulation.
*
* If you see API level 400 or greater you SHOULD try using JSON API v2. The legacy JSON API will eventually go away.
*/
if (!defined('AKEEBA_BACKUP_ORIGIN'))
{
define('AKEEBA_BACKUP_ORIGIN', 'json');
}
/**
* JSON API model. Handles remote API calls through our JSON API.
*/
class Json extends Model
{
use FrontEndPermissions;
/** @var int Normal reply */
public const COM_AKEEBA_CPANEL_LBL_STATUS_OK = 200;
/** @var int Invalid credentials */
public const STATUS_NOT_AUTH = 401;
/** @var int Not enough privileges */
public const STATUS_NOT_ALLOWED = 403;
/** @var int Requested resource not found */
public const STATUS_NOT_FOUND = 404;
/** @var int Unknown JSON method */
public const STATUS_INVALID_METHOD = 405;
/** @var int An error occurred */
public const COM_AKEEBA_CPANEL_LBL_STATUS_ERROR = 500;
/** @var int Not implemented feature */
public const STATUS_NOT_IMPLEMENTED = 501;
/** @var int Remote service not activated */
public const STATUS_NOT_AVAILABLE = 503;
/** @var int Data encapsulation format */
private $encapsulationType = 1;
/** @var Encapsulation */
private $encapsulation;
/** @var string A password passed to us by the caller */
private $password = null;
/**
* Overridden constructor
*
* Sets up the encapsulation.
*
* @param Container $container The configuration variables to this model
* @param array $config Configuration values for this model
*/
public function __construct(Container $container, array $config)
{
parent::__construct($container, $config);
$this->encapsulation = new Encapsulation($this->serverKey());
}
/**
* Parses the JSON data sent by the client and executes the appropriate JSON API task
*
* @param string $json The raw JSON data received from the remote client
*
* @return string The JSON-encoded, fully encapsulated response
*/
public function execute($json)
{
// Check if we're activated
$enabled = $this->container->params->get('jsonapi_enabled', 0) == 1;
// Is the Secret Key strong enough?
$validKey = $this->serverKey();
if (!Complexify::isStrongEnough($validKey, false))
{
$enabled = false;
}
$rawEncapsulation = $this->encapsulation->getEncapsulationByCode('ENCAPSULATION_RAW');
if (!$this->confirmDates())
{
return $this->getResponse('Your version of Akeeba Backup is too old. Please update it to re-enable the remote backup and administration features.', 402);
}
if (!$enabled)
{
return $this->getResponse('Access denied', 503);
}
// Try to JSON-decode the request's input first
$request = @json_decode($json, true);
if (is_null($request))
{
return $this->getResponse('JSON decoding error', 500);
}
// Transform legacy requests
if (!is_array($request))
{
$request = [
'encapsulation' => $rawEncapsulation,
'body' => $request,
];
}
// Transform partial requests
if (!isset($request['encapsulation']))
{
$request['encapsulation'] = $rawEncapsulation;
}
// Make sure we have a request body
if (!isset($request['body']))
{
$request['body'] = '';
}
try
{
$request['body'] = $this->encapsulation->decode($request['encapsulation'], $request['body']);
}
catch (\Exception $e)
{
return $this->getResponse($e->getMessage(), $e->getCode());
}
// Replicate the encapsulation preferences of the client for our own output
$this->encapsulationType = $request['encapsulation'];
// Store the client-specified key, or use the server key if none specified and the request
// came encrypted.
$this->password = $request['body']['key'] ?? $this->serverKey();
// Run the method
$params = [];
if (isset($request['body']['data']))
{
$params = (array) $request['body']['data'];
}
try
{
if (class_exists('Joomla\CMS\Component\ComponentHelper') && \Joomla\CMS\Component\ComponentHelper::isEnabled('com_akeebabackup'))
{
throw new \RuntimeException(sprintf('Please finish upgrading to Akeeba Backup 9 and uninstall Akeeba Backup 8 per the instructions shown on your site\'s backend, Components, Akeeba Backup'), 400);
}
$taskHandler = new Task($this->container);
$data = $taskHandler->execute($request['body']['method'], $params);
}
catch (\RuntimeException $e)
{
return $this->getResponse($e->getMessage(), $e->getCode());
}
return $this->getResponse($data);
}
/**
* Packages the response to a JSON-encoded object, optionally encrypting the data part with a caller-supplied
* password.
*
* @param mixed $data The response to encapsulate
* @param int $status The status code to return. 200 = Success, anything else is treated as an error.
*
* @return string The JSON-encoded response
*/
private function getResponse($data, $status = 200)
{
// Initialize the response
$response = [
'encapsulation' => $this->encapsulationType,
'body' => [
'status' => $status,
'data' => null,
],
];
if ($status != 200)
{
$response['encapsulation'] = $this->encapsulation->getEncapsulationByCode('ENCAPSULATION_RAW');
}
try
{
$response['body']['data'] = $this->encapsulation->encode($response['encapsulation'], $data, $this->password);
}
catch (\Exception $e)
{
$response['encapsulation'] = $this->encapsulation->getEncapsulationByCode('ENCAPSULATION_RAW');
$response['body'] = [
'status' => $e->getCode(),
'data' => $e->getMessage(),
];
}
return '###' . json_encode($response) . '###';
}
/**
* Get the server key, i.e. the Secret Word for the front-end backups and JSON API
*
* @return mixed
*/
private function serverKey()
{
static $key = null;
if (is_null($key))
{
$key = Platform::getInstance()->get_platform_configuration_option('frontend_secret_word', '');
}
return $key;
}
}
home/digilove/public_html/libraries/fof30/Hal/Render/Json.php 0000644 00000006454 15241432552 0020052 0 ustar 00 <?php
/**
* @package FOF
* @copyright Copyright (c)2010-2019 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license GNU GPL version 2 or later
*/
namespace FOF30\Hal\Render;
use FOF30\Hal\Document;
use FOF30\Hal\Link;
use FOF30\Model\DataModel;
defined('_JEXEC') or die;
/**
* Implements the HAL over JSON renderer
*
* @see http://stateless.co/hal_specification.html
*/
class Json implements RenderInterface
{
/**
* When data is an array we'll output the list of data under this key
*
* @var string
*/
private $_dataKey = '_list';
/**
* The document to render
*
* @var Document
*/
protected $_document;
/**
* Public constructor
*
* @param Document &$document The document to render
*/
public function __construct(Document &$document)
{
$this->_document = $document;
}
/**
* Render a HAL document in JSON format
*
* @param array $options Rendering options. You can currently only set json_options (json_encode options)
*
* @return string The JSON representation of the HAL document
*/
public function render($options = array())
{
if (isset($options['data_key']))
{
$this->_dataKey = $options['data_key'];
}
if (isset($options['json_options']))
{
$jsonOptions = $options['json_options'];
}
else
{
$jsonOptions = 0;
}
$serialiseThis = new \stdClass;
// Add links
$collection = $this->_document->getLinks();
$serialiseThis->_links = new \stdClass;
foreach ($collection as $rel => $links)
{
if (!is_array($links))
{
$serialiseThis->_links->$rel = $this->_getLink($links);
}
else
{
$serialiseThis->_links->$rel = array();
foreach ($links as $link)
{
array_push($serialiseThis->_links->$rel, $this->_getLink($link));
}
}
}
// Add embedded documents
$collection = $this->_document->getEmbedded();
if (!empty($collection))
{
$serialiseThis->_embedded = new \stdClass;
foreach ($collection as $rel => $embeddeddocs)
{
$serialiseThis->_embedded->$rel = array();
if (!is_array($embeddeddocs))
{
$embeddeddocs = array($embeddeddocs);
}
foreach ($embeddeddocs as $embedded)
{
$renderer = new static($embedded);
array_push($serialiseThis->_embedded->$rel, $renderer->render($options));
}
}
}
// Add data
$data = $this->_document->getData();
if (is_object($data))
{
if ($data instanceof DataModel)
{
$data = $data->toArray();
}
else
{
$data = (array) $data;
}
if (!empty($data))
{
foreach ($data as $k => $v)
{
$serialiseThis->$k = $v;
}
}
}
elseif (is_array($data))
{
$serialiseThis->{$this->_dataKey} = $data;
}
return json_encode($serialiseThis, $jsonOptions);
}
/**
* Converts a FOFHalLink object into a stdClass object which will be used
* for JSON serialisation
*
* @param Link $link The link you want converted
*
* @return \stdClass The converted link object
*/
protected function _getLink(Link $link)
{
$ret = array(
'href' => $link->href
);
if ($link->templated)
{
$ret['templated'] = 'true';
}
if ($link->name)
{
$ret['name'] = $link->name;
}
if ($link->hreflang)
{
$ret['hreflang'] = $link->hreflang;
}
if ($link->title)
{
$ret['title'] = $link->title;
}
return (object) $ret;
}
}
home/digilove/public_html/110/libraries/fof40/View/DataView/Json.php 0000644 00000013553 15242164740 0021047 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\View\DataView;
defined('_JEXEC') || die;
use FOF40\Model\DataModel;
use Joomla\CMS\Document\Document as JoomlaDocument;
use Joomla\CMS\Document\JsonDocument;
use Joomla\CMS\Uri\Uri;
class Json extends Raw implements DataViewInterface
{
/**
* Set to true if your onBefore* methods have already populated the item, items, limitstart etc properties used to
* render a JSON document.
*
* @var bool
*/
public $alreadyLoaded = false;
/**
* Record listing offset (how many records to skip before starting showing some)
*
* @var int
*/
protected $limitStart = 0;
/**
* Record listing limit (how many records to show)
*
* @var int
*/
protected $limit = 10;
/**
* Total number of records in the result set
*
* @var int
*/
protected $total = 0;
/**
* The record being displayed
*
* @var DataModel
*/
protected $item;
/**
* Overrides the default method to execute and display a template script.
* Instead of loadTemplate is uses loadAnyTemplate.
*
* @param string $tpl The name of the template file to parse
*
* @return boolean True on success
*
* @throws \Exception When the layout file is not found
*/
public function display($tpl = null)
{
$eventName = 'onBefore' . ucfirst($this->doTask);
$this->triggerEvent($eventName, [$tpl]);
$eventName = 'onAfter' . ucfirst($this->doTask);
$this->triggerEvent($eventName, [$tpl]);
return true;
}
/**
* The event which runs when we are displaying the record list JSON view
*
* @param string $tpl The sub-template to use
*/
public function onBeforeBrowse($tpl = null)
{
// Load the model
/** @var DataModel $model */
$model = $this->getModel();
$result = '';
if (!$this->alreadyLoaded)
{
$this->limitStart = $model->getState('limitstart', 0);
$this->limit = $model->getState('limit', 0);
$this->items = $model->get(true, $this->limitStart, $this->limit);
$this->total = $model->count();
}
$document = $this->container->platform->getDocument();
/** @var JsonDocument $document */
if ($document instanceof JoomlaDocument)
{
$document->setMimeEncoding('application/json');
}
if (is_null($tpl))
{
$tpl = 'json';
}
$hasFailed = false;
try
{
$result = $this->loadTemplate($tpl, true);
if ($result instanceof \Exception)
{
$hasFailed = true;
}
}
catch (\Exception $e)
{
$hasFailed = true;
}
if ($hasFailed)
{
// Default JSON behaviour in case the template isn't there!
$result = [];
foreach ($this->items as $item)
{
$result[] = (is_object($item) && method_exists($item, 'toArray')) ? $item->toArray() : $item;
}
$json = json_encode($result, JSON_PRETTY_PRINT);
// JSONP support
$callback = $this->input->get('callback', null, 'raw');
if (!empty($callback))
{
echo $callback . '(' . $json . ')';
}
else
{
$defaultName = $this->input->get('view', 'main', 'cmd');
$filename = $this->input->get('basename', $defaultName, 'cmd');
$document->setName($filename);
echo $json;
}
}
else
{
echo $result;
}
}
/**
* The event which runs when we are displaying a single item JSON view
*
* @param string $tpl The view sub-template to use
*/
protected function onBeforeRead($tpl = null)
{
self::renderSingleItem($tpl);
}
/**
* The event which runs when we are displaying a single item JSON view
*
* @param string $tpl The view sub-template to use
*/
protected function onAfterSave($tpl = null)
{
self::renderSingleItem($tpl);
}
/**
* Renders a single item JSON view
*
* @param string $tpl The view sub-template to use
*/
protected function renderSingleItem($tpl)
{
// Load the model
/** @var DataModel $model */
$model = $this->getModel();
$result = '';
if (!$this->alreadyLoaded)
{
$this->item = $model->find();
}
$document = $this->container->platform->getDocument();
/** @var JsonDocument $document */
if ($document instanceof JoomlaDocument)
{
$document->setMimeEncoding('application/json');
}
if (is_null($tpl))
{
$tpl = 'json';
}
$hasFailed = false;
try
{
$result = $this->loadTemplate($tpl, true);
if ($result instanceof \Exception)
{
$hasFailed = true;
}
}
catch (\Exception $e)
{
$hasFailed = true;
}
if ($hasFailed)
{
$data = (is_object($this->item) && method_exists($this->item, 'toArray')) ? $this->item->toArray() : $this->item;
$json = json_encode($data, JSON_PRETTY_PRINT);
// JSONP support
$callback = $this->input->get('callback');
if (!empty($callback))
{
echo $callback . '(' . $json . ')';
}
else
{
$defaultName = $this->input->get('view', 'main', 'cmd');
$filename = $this->input->get('basename', $defaultName, 'cmd');
$document->setName($filename);
echo $json;
}
}
else
{
echo $result;
}
}
/**
* Convert an absolute URI to a relative one
*
* @param string $uri The URI to convert
*
* @return string The relative URL
*/
protected function _removeURIBase($uri)
{
static $root = null, $rootlen = 0;
if (is_null($root))
{
$root = rtrim(Uri::base(false), '/');
$rootlen = strlen($root);
}
if (substr($uri, 0, $rootlen) == $root)
{
$uri = substr($uri, $rootlen);
}
return ltrim($uri, '/');
}
/**
* Returns a Uri instance with a prototype URI used as the base for the
* other URIs created by the JSON renderer
*
* @return Uri The prototype Uri instance
*/
protected function _getPrototypeURIForPagination()
{
$protoUri = new Uri('index.php');
$protoUri->setQuery($this->input->getData());
$protoUri->delVar('savestate');
$protoUri->delVar('base_path');
return $protoUri;
}
}
home/digilove/public_html/libraries/fof30/View/DataView/Json.php 0000644 00000024464 15242353163 0020547 0 ustar 00 <?php
/**
* @package FOF
* @copyright Copyright (c)2010-2019 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license GNU GPL version 2 or later
*/
namespace FOF30\View\DataView;
use FOF30\Hal\Document;
use FOF30\Hal\Link;
use FOF30\Model\DataModel;
defined('_JEXEC') or die;
class Json extends Raw implements DataViewInterface
{
/**
* Record listing offset (how many records to skip before starting showing some)
*
* @var int
*/
protected $limitStart = 0;
/**
* Record listing limit (how many records to show)
*
* @var int
*/
protected $limit = 10;
/**
* Total number of records in the result set
*
* @var int
*/
protected $total = 0;
/**
* The record being displayed
*
* @var DataModel
*/
protected $item = null;
/**
* When set to true we'll add hypermedia to the output, implementing the
* HAL specification (http://stateless.co/hal_specification.html)
*
* @var boolean
*/
public $useHypermedia = false;
/**
* Set to true if your onBefore* methods have already populated the item, items, limitstart etc properties used to
* render a JSON document.
*
* @var bool
*/
public $alreadyLoaded = false;
/**
* Overrides the default method to execute and display a template script.
* Instead of loadTemplate is uses loadAnyTemplate.
*
* @param string $tpl The name of the template file to parse
*
* @return boolean True on success
*
* @throws \Exception When the layout file is not found
*/
public function display($tpl = null)
{
$eventName = 'onBefore' . ucfirst($this->doTask);
$this->triggerEvent($eventName, array($tpl));
$eventName = 'onAfter' . ucfirst($this->doTask);
$this->triggerEvent($eventName, array($tpl));
return true;
}
/**
* The event which runs when we are displaying the record list JSON view
*
* @param string $tpl The sub-template to use
*/
public function onBeforeBrowse($tpl = null)
{
// Load the model
/** @var DataModel $model */
$model = $this->getModel();
$result = '';
if (!$this->alreadyLoaded)
{
$this->limitStart = $model->getState('limitstart', 0);
$this->limit = $model->getState('limit', 0);
$this->items = $model->get(true, $this->limitStart, $this->limit);
$this->total = $model->count();
}
$document = $this->container->platform->getDocument();
/** @var \JDocumentJSON $document */
if ($document instanceof \JDocument)
{
if ($this->useHypermedia)
{
$document->setMimeEncoding('application/hal+json');
}
else
{
$document->setMimeEncoding('application/json');
}
}
if (is_null($tpl))
{
$tpl = 'json';
}
$hasFailed = false;
try
{
$result = $this->loadTemplate($tpl, true);
if ($result instanceof \Exception)
{
$hasFailed = true;
}
}
catch (\Exception $e)
{
$hasFailed = true;
}
if ($hasFailed)
{
// Default JSON behaviour in case the template isn't there!
if ($this->useHypermedia)
{
$data = array();
foreach($this->items as $item)
{
if(is_object($item) && method_exists($item, 'toArray'))
{
$data[] = $item->toArray();
}
else
{
$data[] = $item;
}
}
$HalDocument = $this->_createDocumentWithHypermedia($data, $model);
$json = $HalDocument->render('json');
}
else
{
$result = array();
foreach($this->items as $item)
{
if(is_object($item) && method_exists($item, 'toArray'))
{
$result[] = $item->toArray();
}
else
{
$result[] = $item;
}
}
if (version_compare(PHP_VERSION, '5.4', 'ge'))
{
$json = json_encode($result, JSON_PRETTY_PRINT);
}
else
{
$json = json_encode($result);
}
}
// JSONP support
$callback = $this->input->get('callback', null, 'raw');
if (!empty($callback))
{
echo $callback . '(' . $json . ')';
}
else
{
$defaultName = $this->input->get('view', 'main', 'cmd');
$filename = $this->input->get('basename', $defaultName, 'cmd');
$document->setName($filename);
echo $json;
}
}
else
{
echo $result;
}
}
/**
* The event which runs when we are displaying a single item JSON view
*
* @param string $tpl The view sub-template to use
*/
protected function onBeforeRead($tpl = null)
{
self::renderSingleItem($tpl);
}
/**
* The event which runs when we are displaying a single item JSON view
*
* @param string $tpl The view sub-template to use
*/
protected function onAfterSave($tpl = null)
{
self::renderSingleItem($tpl);
}
/**
* Renders a single item JSON view
*
* @param string $tpl The view sub-template to use
*/
protected function renderSingleItem($tpl) {
// Load the model
/** @var DataModel $model */
$model = $this->getModel();
$result = '';
if (!$this->alreadyLoaded)
{
$this->item = $model->find();
}
$document = $this->container->platform->getDocument();
/** @var \JDocumentJSON $document */
if ($document instanceof \JDocument)
{
if ($this->useHypermedia)
{
$document->setMimeEncoding('application/hal+json');
}
else
{
$document->setMimeEncoding('application/json');
}
}
if (is_null($tpl))
{
$tpl = 'json';
}
$hasFailed = false;
try
{
$result = $this->loadTemplate($tpl, true);
if ($result instanceof \Exception)
{
$hasFailed = true;
}
}
catch (\Exception $e)
{
$hasFailed = true;
}
if ($hasFailed)
{
// Default JSON behaviour in case the template isn't there!
if ($this->useHypermedia)
{
$haldocument = $this->_createDocumentWithHypermedia($this->item, $model);
$json = $haldocument->render('json');
}
else
{
if (is_object($this->item) && method_exists($this->item, 'toArray'))
{
$data = $this->item->toArray();
}
else
{
$data = $this->item;
}
if (version_compare(PHP_VERSION, '5.4', 'ge'))
{
$json = json_encode($data, JSON_PRETTY_PRINT);
}
else
{
$json = json_encode($data);
}
}
// JSONP support
$callback = $this->input->get('callback', null);
if (!empty($callback))
{
echo $callback . '(' . $json . ')';
}
else
{
$defaultName = $this->input->get('view', 'main', 'cmd');
$filename = $this->input->get('basename', $defaultName, 'cmd');
$document->setName($filename);
echo $json;
}
}
else
{
echo $result;
}
}
/**
* Creates a \FOF30\Hal\Document using the provided data
*
* @param mixed|array $data The data to put in the document
* @param DataModel $model The model of this view
*
* @return \FOF30\Hal\Document A HAL-enabled document
*/
protected function _createDocumentWithHypermedia($data, $model = null)
{
// Create a new HAL document
if (is_array($data))
{
$count = count($data);
}
else
{
$count = null;
}
if ($count == 1)
{
reset($data);
$document = new Document(end($data));
}
else
{
$document = new Document($data);
}
// Create a self link
$uri = (string) (\JUri::getInstance());
$uri = $this->_removeURIBase($uri);
$uri = \JRoute::_($uri);
$document->addLink('self', new Link($uri));
// Create relative links in a record list context
if (is_array($data) && ($model instanceof DataModel))
{
if(!isset($this->total))
{
$this->total = $model->count();
}
if(!isset($this->limitStart))
{
$this->limitStart = $model->getState('limitstart', 0);
}
if(!isset($this->limit))
{
$this->limit = $model->getState('limit', 0);
}
$pagination = new \JPagination($this->total, $this->limitStart, $this->limit);
if ($pagination->pagesTotal > 1)
{
// Try to guess URL parameters and create a prototype URL
// NOTE: You are better off specialising this method
$protoUri = $this->_getPrototypeURIForPagination();
// The "first" link
$uri = clone $protoUri;
$uri->setVar('limitstart', 0);
$uri = \JRoute::_($uri);
$document->addLink('first', new Link($uri));
// Do we need a "prev" link?
if ($pagination->pagesCurrent > 1)
{
$prevPage = $pagination->pagesCurrent - 1;
$limitstart = ($prevPage - 1) * $pagination->limit;
$uri = clone $protoUri;
$uri->setVar('limitstart', $limitstart);
$uri = \JRoute::_($uri);
$document->addLink('prev', new Link($uri));
}
// Do we need a "next" link?
if ($pagination->pagesCurrent < $pagination->pagesTotal)
{
$nextPage = $pagination->pagesCurrent + 1;
$limitstart = ($nextPage - 1) * $pagination->limit;
$uri = clone $protoUri;
$uri->setVar('limitstart', $limitstart);
$uri = \JRoute::_($uri);
$document->addLink('next', new Link($uri));
}
// The "last" link?
$lastPage = $pagination->pagesTotal;
$limitstart = ($lastPage - 1) * $pagination->limit;
$uri = clone $protoUri;
$uri->setVar('limitstart', $limitstart);
$uri = \JRoute::_($uri);
$document->addLink('last', new Link($uri));
}
}
return $document;
}
/**
* Convert an absolute URI to a relative one
*
* @param string $uri The URI to convert
*
* @return string The relative URL
*/
protected function _removeURIBase($uri)
{
static $root = null, $rootlen = 0;
if (is_null($root))
{
$root = rtrim(\JUri::base(false), '/');
$rootlen = strlen($root);
}
if (substr($uri, 0, $rootlen) == $root)
{
$uri = substr($uri, $rootlen);
}
return ltrim($uri, '/');
}
/**
* Returns a JUri instance with a prototype URI used as the base for the
* other URIs created by the JSON renderer
*
* @return \JUri The prototype JUri instance
*/
protected function _getPrototypeURIForPagination()
{
$protoUri = new \JUri('index.php');
$protoUri->setQuery($this->input->getData());
$protoUri->delVar('savestate');
$protoUri->delVar('base_path');
return $protoUri;
}
}
home/digilove/public_html/110/libraries/vendor/joomla/input/src/Json.php 0000644 00000003421 15243306334 0022206 0 ustar 00 <?php
/**
* Part of the Joomla Framework Input Package
*
* @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
namespace Joomla\Input;
use Joomla\Filter;
/**
* Joomla! Input JSON Class
*
* This class decodes a JSON string from the raw request data and makes it available via
* the standard Input interface.
*
* @since 1.0
*/
class Json extends Input
{
/**
* @var string The raw JSON string from the request.
* @since 1.0
*/
private $raw;
/**
* Constructor.
*
* @param array $source Source data (Optional, default is the raw HTTP input decoded from JSON)
* @param array $options Array of configuration parameters (Optional)
*
* @since 1.0
*/
public function __construct($source = null, array $options = array())
{
if (isset($options['filter']))
{
$this->filter = $options['filter'];
}
else
{
$this->filter = new Filter\InputFilter;
}
if ($source === null)
{
$this->raw = file_get_contents('php://input');
// This is a workaround for where php://input has already been read.
// See note under php://input on https://www.php.net/manual/en/wrappers.php.php
if (empty($this->raw) && isset($GLOBALS['HTTP_RAW_POST_DATA']))
{
$this->raw = $GLOBALS['HTTP_RAW_POST_DATA'];
}
$this->data = json_decode($this->raw, true);
if (!\is_array($this->data))
{
$this->data = array();
}
}
else
{
$this->data = $source;
}
// Set the options for the class.
$this->options = $options;
}
/**
* Gets the raw JSON string from the request.
*
* @return string The raw JSON string from the request.
*
* @since 1.0
*/
public function getRaw()
{
return $this->raw;
}
}