From 034a8c540a99e3fa6194a112d5b129d0b7193de1 Mon Sep 17 00:00:00 2001 From: ghost Date: Fri, 15 Sep 2023 23:24:59 +0300 Subject: [PATCH] add api user agent customization --- example/environment/env.example.php | 4 +++- src/crontab/export/feed.php | 4 +++- src/crontab/export/push.php | 2 +- src/library/curl.php | 12 ++++++------ 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/example/environment/env.example.php b/example/environment/env.example.php index c3eff89..c74d0f4 100644 --- a/example/environment/env.example.php +++ b/example/environment/env.example.php @@ -145,7 +145,9 @@ define('NODE_RULE_SUBJECT', 'Common'); define('NODE_RULE_LANGUAGES', 'All'); // API -define('API_VERSION', 1); +define('API_VERSION', '1.0.0'); + +define('API_USER_AGENT', WEBSITE_NAME); /// Export define('API_EXPORT_ENABLED', true); diff --git a/src/crontab/export/feed.php b/src/crontab/export/feed.php index 05c47fb..947fec8 100644 --- a/src/crontab/export/feed.php +++ b/src/crontab/export/feed.php @@ -47,7 +47,6 @@ try // Manifest $manifest = [ - 'version' => API_VERSION, 'updated' => time(), 'settings' => (object) @@ -109,6 +108,9 @@ try 'MAGNET_STOP_WORDS_SIMILAR' => (object) MAGNET_STOP_WORDS_SIMILAR, + 'API_VERSION' => (string) API_VERSION, + 'API_USER_AGENT' => (string) API_USER_AGENT, + 'API_EXPORT_ENABLED' => (bool) API_EXPORT_ENABLED, 'API_EXPORT_PUSH_ENABLED' => (bool) API_EXPORT_PUSH_ENABLED, 'API_EXPORT_USERS_ENABLED' => (bool) API_EXPORT_USERS_ENABLED, diff --git a/src/crontab/export/push.php b/src/crontab/export/push.php index daaef87..29e5971 100644 --- a/src/crontab/export/push.php +++ b/src/crontab/export/push.php @@ -339,7 +339,7 @@ if (API_EXPORT_PUSH_ENABLED) // Send push request $debug['result'][$manifest->import->push]['request'] = $request; - $curl = new Curl($manifest->import->push, $request); + $curl = new Curl($manifest->import->push, API_USER_AGENT, $request); if ($response = $curl->getResponse()) { diff --git a/src/library/curl.php b/src/library/curl.php index 7de42fa..e713485 100644 --- a/src/library/curl.php +++ b/src/library/curl.php @@ -6,8 +6,8 @@ class Curl private $_response; public function __construct(string $url, - array $post = [], string $userAgent = 'YGGtracker', + array $post = [], int $connectTimeout = 10, bool $header = false, bool $followLocation = false, @@ -17,6 +17,11 @@ class Curl { $this->_connection = curl_init($url); + if ($userAgent) + { + curl_setopt($this->_connection, CURLOPT_USERAGENT, $userAgent); + } + if (!empty($post)) { curl_setopt($this->_connection, CURLOPT_POST, true); @@ -38,11 +43,6 @@ class Curl curl_setopt($this->_connection, CURLOPT_SSL_VERIFYHOST, $sslVerifyHost); curl_setopt($this->_connection, CURLOPT_SSL_VERIFYPEER, $sslVerifyPeer); - if ($userAgent) - { - curl_setopt($this->_connection, CURLOPT_USERAGENT, $userAgent); - } - $this->_response = curl_exec($this->_connection); }