| Current Path : /home/digilove/www/41423/ |
| Current File : /home/digilove/www/41423/Http.php.tar |
home/digilove/public_html/libraries/regularlabs/src/Http.php 0000644 00000010771 15234617033 0020310 0 ustar 00 <?php
/**
* @package Regular Labs Library
* @version 23.7.24631
*
* @author Peter van Westen <info@regularlabs.com>
* @link https://regularlabs.com
* @copyright Copyright © 2023 Regular Labs All Rights Reserved
* @license GNU General Public License version 2 or later
*/
namespace RegularLabs\Library;
defined('_JEXEC') or die;
use Joomla\CMS\Factory as JFactory;
use Joomla\CMS\Http\HttpFactory as JHttpFactory;
use Joomla\Registry\Registry;
use RegularLabs\Library\CacheNew as Cache;
use RuntimeException;
/**
* Class Http
* @package RegularLabs\Library
*/
class Http
{
/**
* Get the contents of the given internal url
*
* @param string $url
* @param int $timeout
*
* @return string
*/
public static function get($url, $timeout = 20)
{
if (Uri::isExternal($url))
{
return '';
}
return @file_get_contents($url, false, stream_context_create(['http' => ['timeout' => $timeout]]))
|| self::getFromUrl($url, $timeout);
}
/**
* Get the contents of the given external url from the Regular Labs server
*
* @param string $url
* @param int $timeout
*
* @return string
*/
public static function getFromServer($url, $timeout = 20)
{
$cache = new Cache([__METHOD__, $url]);
$cache_ttl = JFactory::getApplication()->input->getInt('cache', 0);
if ($cache_ttl)
{
$cache->useFiles($cache_ttl > 1 ? $cache_ttl : null);
}
if ($cache->exists())
{
return $cache->get();
}
// only allow url calls from administrator
if ( ! Document::isClient('administrator'))
{
die;
}
// only allow when logged in
$user = JFactory::getApplication()->getIdentity() ?: JFactory::getUser();
if ( ! $user->id)
{
die;
}
if (substr($url, 0, 4) != 'http')
{
$url = 'http://' . $url;
}
// only allow url calls to regularlabs.com domain
if ( ! (RegEx::match('^https?://([^/]+\.)?regularlabs\.com/', $url)))
{
die;
}
// only allow url calls to certain files
if (
strpos($url, 'download.regularlabs.com/extensions.php') === false
&& strpos($url, 'download.regularlabs.com/extensions.json') === false
&& strpos($url, 'download.regularlabs.com/extensions.xml') === false
)
{
die;
}
$content = self::getContents($url, $timeout);
if (empty($content))
{
return '';
}
$format = (strpos($url, '.json') !== false || strpos($url, 'format=json') !== false)
? 'application/json'
: 'text/xml';
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");
header("Content-type: " . $format);
return $cache->set($content);
}
/**
* Get the contents of the given url
*
* @param string $url
* @param int $timeout
*
* @return string
*/
public static function getFromUrl($url, $timeout = 20)
{
$cache = new Cache([__METHOD__, $url]);
$cache_ttl = JFactory::getApplication()->input->getInt('cache', 0);
if ($cache_ttl)
{
$cache->useFiles($cache_ttl > 1 ? $cache_ttl : null);
}
if ($cache->exists())
{
return $cache->get();
}
$content = self::getContents($url, $timeout);
if (empty($content))
{
return '';
}
return $cache->set($content);
}
/**
* Load the contents of the given url
*
* @param string $url
* @param int $timeout
*
* @return string
*/
private static function getContents($url, $timeout = 20)
{
try
{
// Adding a valid user agent string, otherwise some feed-servers returning an error
$options = new Registry([
'userAgent' => 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:41.0) Gecko/20100101 Firefox/41.0',
]);
$content = JHttpFactory::getHttp($options)->get($url, null, $timeout)->body;
}
catch (RuntimeException $e)
{
return '';
}
return $content;
}
}
home/digilove/public_html/110/libraries/src/Http/Http.php 0000644 00000022230 15235157750 0017224 0 ustar 00 <?php
/**
* Joomla! Content Management System
*
* @copyright (C) 2011 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\CMS\Http;
defined('JPATH_PLATFORM') or die;
use Joomla\Registry\Registry;
use Joomla\CMS\Http\HttpFactory;
use Joomla\CMS\Http\TransportInterface;
use Joomla\CMS\Uri\Uri;
/**
* HTTP client class.
*
* @since 1.7.3
*/
class Http
{
/**
* @var Registry Options for the HTTP client.
* @since 1.7.3
*/
protected $options;
/**
* @var TransportInterface The HTTP transport object to use in sending HTTP requests.
* @since 1.7.3
*/
protected $transport;
/**
* Constructor.
*
* @param Registry $options Client options object. If the registry contains any headers.* elements,
* these will be added to the request headers.
* @param TransportInterface $transport The HTTP transport object.
*
* @since 1.7.3
*/
public function __construct(Registry $options = null, TransportInterface $transport = null)
{
$this->options = isset($options) ? $options : new Registry;
$this->transport = isset($transport) ? $transport : HttpFactory::getAvailableDriver($this->options);
}
/**
* Get an option from the HTTP client.
*
* @param string $key The name of the option to get.
*
* @return mixed The option value.
*
* @since 1.7.3
*/
public function getOption($key)
{
return $this->options->get($key);
}
/**
* Set an option for the HTTP client.
*
* @param string $key The name of the option to set.
* @param mixed $value The option value to set.
*
* @return Http This object for method chaining.
*
* @since 1.7.3
*/
public function setOption($key, $value)
{
$this->options->set($key, $value);
return $this;
}
/**
* Method to send the OPTIONS command to the server.
*
* @param string $url Path to the resource.
* @param array $headers An array of name-value pairs to include in the header of the request.
* @param integer $timeout Read timeout in seconds.
*
* @return Response
*
* @since 1.7.3
*/
public function options($url, array $headers = null, $timeout = null)
{
// Look for headers set in the options.
$temp = (array) $this->options->get('headers');
foreach ($temp as $key => $val)
{
if (!isset($headers[$key]))
{
$headers[$key] = $val;
}
}
// Look for timeout set in the options.
if ($timeout === null && $this->options->exists('timeout'))
{
$timeout = $this->options->get('timeout');
}
return $this->transport->request('OPTIONS', new Uri($url), null, $headers, $timeout, $this->options->get('userAgent', null));
}
/**
* Method to send the HEAD command to the server.
*
* @param string $url Path to the resource.
* @param array $headers An array of name-value pairs to include in the header of the request.
* @param integer $timeout Read timeout in seconds.
*
* @return Response
*
* @since 1.7.3
*/
public function head($url, array $headers = null, $timeout = null)
{
// Look for headers set in the options.
$temp = (array) $this->options->get('headers');
foreach ($temp as $key => $val)
{
if (!isset($headers[$key]))
{
$headers[$key] = $val;
}
}
// Look for timeout set in the options.
if ($timeout === null && $this->options->exists('timeout'))
{
$timeout = $this->options->get('timeout');
}
return $this->transport->request('HEAD', new Uri($url), null, $headers, $timeout, $this->options->get('userAgent', null));
}
/**
* Method to send the GET command to the server.
*
* @param string $url Path to the resource.
* @param array $headers An array of name-value pairs to include in the header of the request.
* @param integer $timeout Read timeout in seconds.
*
* @return Response
*
* @since 1.7.3
*/
public function get($url, array $headers = null, $timeout = null)
{
// Look for headers set in the options.
$temp = (array) $this->options->get('headers');
foreach ($temp as $key => $val)
{
if (!isset($headers[$key]))
{
$headers[$key] = $val;
}
}
// Look for timeout set in the options.
if ($timeout === null && $this->options->exists('timeout'))
{
$timeout = $this->options->get('timeout');
}
return $this->transport->request('GET', new Uri($url), null, $headers, $timeout, $this->options->get('userAgent', null));
}
/**
* Method to send the POST command to the server.
*
* @param string $url Path to the resource.
* @param mixed $data Either an associative array or a string to be sent with the request.
* @param array $headers An array of name-value pairs to include in the header of the request
* @param integer $timeout Read timeout in seconds.
*
* @return Response
*
* @since 1.7.3
*/
public function post($url, $data, array $headers = null, $timeout = null)
{
// Look for headers set in the options.
$temp = (array) $this->options->get('headers');
foreach ($temp as $key => $val)
{
if (!isset($headers[$key]))
{
$headers[$key] = $val;
}
}
// Look for timeout set in the options.
if ($timeout === null && $this->options->exists('timeout'))
{
$timeout = $this->options->get('timeout');
}
return $this->transport->request('POST', new Uri($url), $data, $headers, $timeout, $this->options->get('userAgent', null));
}
/**
* Method to send the PUT command to the server.
*
* @param string $url Path to the resource.
* @param mixed $data Either an associative array or a string to be sent with the request.
* @param array $headers An array of name-value pairs to include in the header of the request.
* @param integer $timeout Read timeout in seconds.
*
* @return Response
*
* @since 1.7.3
*/
public function put($url, $data, array $headers = null, $timeout = null)
{
// Look for headers set in the options.
$temp = (array) $this->options->get('headers');
foreach ($temp as $key => $val)
{
if (!isset($headers[$key]))
{
$headers[$key] = $val;
}
}
// Look for timeout set in the options.
if ($timeout === null && $this->options->exists('timeout'))
{
$timeout = $this->options->get('timeout');
}
return $this->transport->request('PUT', new Uri($url), $data, $headers, $timeout, $this->options->get('userAgent', null));
}
/**
* Method to send the DELETE command to the server.
*
* @param string $url Path to the resource.
* @param array $headers An array of name-value pairs to include in the header of the request.
* @param integer $timeout Read timeout in seconds.
*
* @return Response
*
* @since 1.7.3
*/
public function delete($url, array $headers = null, $timeout = null)
{
// Look for headers set in the options.
$temp = (array) $this->options->get('headers');
foreach ($temp as $key => $val)
{
if (!isset($headers[$key]))
{
$headers[$key] = $val;
}
}
// Look for timeout set in the options.
if ($timeout === null && $this->options->exists('timeout'))
{
$timeout = $this->options->get('timeout');
}
return $this->transport->request('DELETE', new Uri($url), null, $headers, $timeout, $this->options->get('userAgent', null));
}
/**
* Method to send the TRACE command to the server.
*
* @param string $url Path to the resource.
* @param array $headers An array of name-value pairs to include in the header of the request.
* @param integer $timeout Read timeout in seconds.
*
* @return Response
*
* @since 1.7.3
*/
public function trace($url, array $headers = null, $timeout = null)
{
// Look for headers set in the options.
$temp = (array) $this->options->get('headers');
foreach ($temp as $key => $val)
{
if (!isset($headers[$key]))
{
$headers[$key] = $val;
}
}
// Look for timeout set in the options.
if ($timeout === null && $this->options->exists('timeout'))
{
$timeout = $this->options->get('timeout');
}
return $this->transport->request('TRACE', new Uri($url), null, $headers, $timeout, $this->options->get('userAgent', null));
}
/**
* Method to send the PATCH command to the server.
*
* @param string $url Path to the resource.
* @param mixed $data Either an associative array or a string to be sent with the request.
* @param array $headers An array of name-value pairs to include in the header of the request.
* @param integer $timeout Read timeout in seconds.
*
* @return Response
*
* @since 3.0.1
*/
public function patch($url, $data, array $headers = null, $timeout = null)
{
// Look for headers set in the options.
$temp = (array) $this->options->get('headers');
foreach ($temp as $key => $val)
{
if (!isset($headers[$key]))
{
$headers[$key] = $val;
}
}
// Look for timeout set in the options.
if ($timeout === null && $this->options->exists('timeout'))
{
$timeout = $this->options->get('timeout');
}
return $this->transport->request('PATCH', new Uri($url), $data, $headers, $timeout, $this->options->get('userAgent', null));
}
}