Version 5.0.0 beta 1
This commit is contained in:
1 parent
25ddeb65d6
commit
15c7beabc5
6736 files changed
+627902
-497943
No files matched your search
@@ -11,9 +11,19 @@
|
||||
namespace IPS\core;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use IPS\Http\Request\CurlException;
|
||||
use IPS\Http\Url;
|
||||
use IPS\Log;
|
||||
use IPS\Patterns\Singleton;
|
||||
use IPS\Settings;
|
||||
use IPS\Task;
|
||||
use function count;
|
||||
use function defined;
|
||||
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -24,19 +34,19 @@ if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
*
|
||||
* The submission should always happen via the queue system!
|
||||
*/
|
||||
class _IndexNow extends \IPS\Patterns\Singleton
|
||||
class IndexNow extends Singleton
|
||||
{
|
||||
/**
|
||||
* @brief Singleton Instances
|
||||
*/
|
||||
protected static $instance = NULL;
|
||||
protected static ?Singleton $instance = NULL;
|
||||
|
||||
/**
|
||||
* @brief Target URL for the API Request
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
static $apiUrl = "https://api.indexnow.org/indexnow/";
|
||||
static string $apiUrl = "https://api.indexnow.org/indexnow/";
|
||||
|
||||
/**
|
||||
* Is the extension enabled?
|
||||
@@ -45,16 +55,16 @@ class _IndexNow extends \IPS\Patterns\Singleton
|
||||
*/
|
||||
public function isEnabled(): bool
|
||||
{
|
||||
return (bool) \IPS\Settings::i()->indexnow_enabled;
|
||||
return (bool) Settings::i()->indexnow_enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Queues a URL to be sent to indexnow
|
||||
*
|
||||
* @param $url
|
||||
* @param Url|string $url
|
||||
* @return void
|
||||
*/
|
||||
public static function addUrlToQueue( $url )
|
||||
public static function addUrlToQueue( Url|string $url ) : void
|
||||
{
|
||||
static::addUrlsToQueue([ $url ] );
|
||||
}
|
||||
@@ -65,39 +75,40 @@ class _IndexNow extends \IPS\Patterns\Singleton
|
||||
* @param array $urls
|
||||
* @return void
|
||||
*/
|
||||
public static function addUrlsToQueue( array $urls )
|
||||
public static function addUrlsToQueue( array $urls ) : void
|
||||
{
|
||||
$obj = static::i();
|
||||
if( $obj->isEnabled() )
|
||||
{
|
||||
\IPS\Task::queue( 'core', 'IndexNow', [ 'urls' => array_map('strval', $urls) ] );
|
||||
Task::queue( 'core', 'IndexNow', [ 'urls' => array_map('strval', $urls) ] );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends all the urls in the queue to indexnow
|
||||
*
|
||||
* @param array $urls
|
||||
* @return void
|
||||
*/
|
||||
public function send( array $urls )
|
||||
public function send( array $urls ) : void
|
||||
{
|
||||
/* Move on if there's nothing to send */
|
||||
if( !\count( $urls ) )
|
||||
if( !count( $urls ) )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$url = \IPS\Http\Url::internal( '', 'front' );
|
||||
$url = Url::internal( '', 'front' );
|
||||
$data = array(
|
||||
'host' => \IPS\Http\Url::baseUrl(\IPS\Http\Url::PROTOCOL_WITHOUT ),
|
||||
'key' => \IPS\Settings::i()->indexnow_key,
|
||||
'keyLocation' => (string) $url->setPath( $url->data[ \IPS\Http\Url::COMPONENT_PATH ] . $this->getKeyFileName() ),
|
||||
'host' => Url::baseUrl(Url::PROTOCOL_WITHOUT ),
|
||||
'key' => Settings::i()->indexnow_key,
|
||||
'keyLocation' => (string) $url->setPath( $url->data[ Url::COMPONENT_PATH ] . $this->getKeyFileName() ),
|
||||
'urlList' => $urls,
|
||||
);
|
||||
|
||||
|
||||
try {
|
||||
$response = \IPS\Http\Url::external(static::$apiUrl)->request()
|
||||
$response = Url::external(static::$apiUrl)->request()
|
||||
->setHeaders(array('Content-Type' => 'application/json'))->post(json_encode($data));
|
||||
if (!$response->isSuccessful()) {
|
||||
switch ($response->httpResponseCode) {
|
||||
@@ -114,11 +125,11 @@ class _IndexNow extends \IPS\Patterns\Singleton
|
||||
default:
|
||||
$error = 'unknown_error';
|
||||
}
|
||||
\IPS\Log::log( $response->httpResponseCode . ' ' . $error . ' ' . print_r($response, TRUE) . print_r($data, TRUE), 'IndexNow');
|
||||
Log::log( $response->httpResponseCode . ' ' . $error . ' ' . print_r($response, TRUE) . print_r($data, TRUE), 'IndexNow');
|
||||
}
|
||||
} catch (\IPS\Http\Request\CurlException $e)
|
||||
} catch (CurlException $e)
|
||||
{
|
||||
\IPS\Log::log( $e->getMessage(), 'IndexNow' );
|
||||
Log::log($e->getMessage(), 'IndexNow');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,7 +140,7 @@ class _IndexNow extends \IPS\Patterns\Singleton
|
||||
*/
|
||||
public function getKeyFileName(): string
|
||||
{
|
||||
return \IPS\Settings::i()->indexnow_key . '.txt';
|
||||
return Settings::i()->indexnow_key . '.txt';
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -139,6 +150,6 @@ class _IndexNow extends \IPS\Patterns\Singleton
|
||||
*/
|
||||
public function getKeyfileContent(): string
|
||||
{
|
||||
return \IPS\Settings::i()->indexnow_key;
|
||||
return Settings::i()->indexnow_key;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user