Version 4.1.2
This commit is contained in:
1 parent
3ba79295ee
commit
28bd025b35
1131 files changed
+63658
-20579
No files matched your search
@@ -69,7 +69,7 @@ class _Curl
|
||||
* @param bool|int $followRedirects Automatically follow redirects? If a number is provided, will follow up to that number of redirects
|
||||
* @return void
|
||||
*/
|
||||
public function __construct( $url, $timeout, $httpVersion, $followRedirects )
|
||||
public function __construct( $url, $timeout=5, $httpVersion=NULL, $followRedirects=TRUE )
|
||||
{
|
||||
/* Init */
|
||||
$this->url = $url;
|
||||
@@ -272,6 +272,22 @@ class _Curl
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle SSL checks
|
||||
*
|
||||
* @param boolean $value True will enable SSL checks, false will disable them
|
||||
* @return \IPS\Http\Request\Socket
|
||||
*/
|
||||
public function sslCheck( $value=TRUE )
|
||||
{
|
||||
curl_setopt_array( $this->curl, array(
|
||||
CURLOPT_SSL_VERIFYHOST => ( $value ) ? 2 : FALSE,
|
||||
CURLOPT_SSL_VERIFYPEER => (boolean) $value
|
||||
) );
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic Method: __call
|
||||
* Used for other HTTP methods (like PUT and DELETE)
|
||||
@@ -331,7 +347,7 @@ class _Curl
|
||||
}
|
||||
|
||||
/* If this is FTP we need to fudge the headers a little */
|
||||
if( $this->url->data['scheme'] == 'ftp' )
|
||||
if( isset( $this->url->data['scheme'] ) and $this->url->data['scheme'] == 'ftp' )
|
||||
{
|
||||
$output = "HTTP/1.1 200 OK\nFTP: True\r\n\r\n" . $output;
|
||||
}
|
||||
|
||||
@@ -91,6 +91,18 @@ class _Sockets
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle SSL checks
|
||||
*
|
||||
* @param boolean $value True will enable SSL checks, false will disable them
|
||||
* @return \IPS\Http\Request\Socket
|
||||
*/
|
||||
public function sslCheck( $value=TRUE )
|
||||
{
|
||||
/* This is here for compatibility with curl */
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic Method: __call
|
||||
*
|
||||
|
||||
+58
-18
@@ -247,7 +247,10 @@ class _Url
|
||||
{
|
||||
/* Always lowercase */
|
||||
$value = mb_strtolower( $value );
|
||||
|
||||
|
||||
/* Get rid of newlines/carriage returns as they're not cool in friendly URL titles */
|
||||
$value = str_replace( array( "\r\n", "\r", "\n" ), ' ', $value );
|
||||
|
||||
/* Just for readability */
|
||||
$value = str_replace( ' ', '-', $value );
|
||||
|
||||
@@ -358,7 +361,7 @@ class _Url
|
||||
$keys = array( $keys => $keys );
|
||||
}
|
||||
|
||||
$queryString = array_diff_key( $this->queryString, $keys );
|
||||
$queryString = array_diff_key( $this->queryString, array_combine( array_values( $keys ), array_values( $keys ) ) );
|
||||
}
|
||||
|
||||
return $this->reconstruct( $this->data, $queryString );
|
||||
@@ -494,7 +497,7 @@ class _Url
|
||||
/* Is it internal? We have to ignore protocol because areas like force login over https and secure checkout in Nexus will use https urls for an otherwise http site and we end up with infinite redirects */
|
||||
if ( $internal === NULL )
|
||||
{
|
||||
$this->isInternal = ( mb_substr( str_replace( 'https://', 'http://', $this->url ), 0, mb_strlen( str_replace( 'https://', 'http://', \IPS\Settings::i()->base_url ) ) ) === str_replace( 'https://', 'http://', \IPS\Settings::i()->base_url ) );
|
||||
$this->isInternal = ( mb_substr( str_replace( array( 'https://', 'http://' ), '//', $this->url ), 0, mb_strlen( str_replace( array( 'https://', 'http://' ), '//', \IPS\Settings::i()->base_url ) ) ) === str_replace( array( 'https://', 'http://' ), '//', \IPS\Settings::i()->base_url ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -642,17 +645,16 @@ class _Url
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the query/path
|
||||
* Get FURL query
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function queryPath()
|
||||
public function getFurlQuery()
|
||||
{
|
||||
/* Determine our gateway */
|
||||
$gatewayFile = explode( '/', str_replace( '\\', '/', $_SERVER['SCRIPT_FILENAME'] ) );
|
||||
$gatewayFile = array_pop( $gatewayFile );
|
||||
|
||||
/* Work out what the FURL "query" is */
|
||||
|
||||
$baseUrl = $this->utf8ParseUrl( \IPS\Settings::i()->base_url );
|
||||
|
||||
if ( \IPS\Settings::i()->htaccess_mod_rewrite )
|
||||
@@ -681,9 +683,7 @@ class _Url
|
||||
}
|
||||
}
|
||||
|
||||
$query = preg_replace( '#^(' . preg_quote( rtrim( $baseUrl['path'], '/' ), '#' ) . ')/(' . $gatewayFile . ')?(?:(?:\?/|\?))?(.+?)?$#', '$3', $query );
|
||||
|
||||
return $query;
|
||||
return preg_replace( '#^(' . preg_quote( rtrim( $baseUrl['path'], '/' ), '#' ) . ')/(' . $gatewayFile . ')?(?:(?:\?/|\?))?(.+?)?$#', '$3', $query );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -704,8 +704,8 @@ class _Url
|
||||
/* Get furl definition */
|
||||
$furlDefinition = static::furlDefinition();
|
||||
|
||||
/* What is the query */
|
||||
$query = $this->queryPath();
|
||||
/* Work out what the FURL "query" is */
|
||||
$query = $this->getFurlQuery();
|
||||
|
||||
/* Examine our URLs */
|
||||
$this->examineFurl( $furlDefinition, $query, $set, $usedTemplate );
|
||||
@@ -777,7 +777,23 @@ class _Url
|
||||
{
|
||||
try
|
||||
{
|
||||
$correctUrl = $usedTemplate['verify']::loadFromUrl( \IPS\Http\Url::internal( $usedTemplate['_rebuiltUrl'], 'front' ) )->url();
|
||||
$contentObject = $usedTemplate['verify']::loadFromUrl( \IPS\Http\Url::internal( $usedTemplate['_rebuiltUrl'], 'front' ) );
|
||||
|
||||
if( method_exists( $contentObject, 'canView' ) )
|
||||
{
|
||||
if( $contentObject->canView() )
|
||||
{
|
||||
$correctUrl = $contentObject->url();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new \OutOfRangeException;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$correctUrl = $contentObject->url();
|
||||
}
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
@@ -848,8 +864,24 @@ class _Url
|
||||
{
|
||||
parse_str( $data['real'], $paramsInCorrectUrl );
|
||||
$paramsInCorrectUrl = array_merge( array_keys( $paramsInCorrectUrl ), $params );
|
||||
|
||||
$correctUrl = $data['verify']::loadFromUrl( \IPS\Http\Url::internal( $requestedUrl->data['query'], 'front' ) )->url();
|
||||
|
||||
$contentObject = $data['verify']::loadFromUrl( \IPS\Http\Url::internal( $requestedUrl->data['query'], 'front' ) );
|
||||
|
||||
if( method_exists( $contentObject, 'canView' ) )
|
||||
{
|
||||
if( $contentObject->canView() )
|
||||
{
|
||||
$correctUrl = $contentObject->url();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new \OutOfRangeException;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$correctUrl = $contentObject->url();
|
||||
}
|
||||
|
||||
$paramsToSet = array();
|
||||
foreach ( $requestedUrl->queryString as $k => $v )
|
||||
@@ -942,7 +974,7 @@ class _Url
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function examineFurl( &$furlDefinition, &$query, &$set, &$usedTemplate, $checkAlias=FALSE, $checkWithoutTopLevel=FALSE )
|
||||
public function examineFurl( &$furlDefinition, &$query, &$set, &$usedTemplate, $checkAlias=FALSE, $checkWithoutTopLevel=FALSE )
|
||||
{
|
||||
foreach ( $furlDefinition as $_key => $data )
|
||||
{
|
||||
@@ -1110,7 +1142,7 @@ class _Url
|
||||
}
|
||||
|
||||
/* Set a default user-agent since many services block requests without one, i.e. spotify */
|
||||
$requestObj->setHeaders( array( 'User-Agent' => 'IPS Community Suite 4.0' ) );
|
||||
$requestObj->setHeaders( array( 'User-Agent' => 'IPS Community Suite 4.1' ) );
|
||||
|
||||
return $requestObj;
|
||||
}
|
||||
@@ -1125,7 +1157,15 @@ class _Url
|
||||
public function import( $storageExtension )
|
||||
{
|
||||
$parts = $this->utf8ParseUrl( $this->url );
|
||||
return \IPS\File::create( $storageExtension, basename( $parts['path'] ), $this->request()->get() );
|
||||
$response = $this->request()->get();
|
||||
|
||||
/* We should not attempt to "import" 404, 403, 500, etc. responses */
|
||||
if( (int) $response->httpResponseCode !== 200 )
|
||||
{
|
||||
throw new \RuntimeException( "COULD_NOT_IMPORT" );
|
||||
}
|
||||
|
||||
return \IPS\File::create( $storageExtension, basename( $parts['path'] ), $response );
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user