remove SELF_USER_AGENT custom constant, replaced with configurable Config::HTTP_USER_AGENT / Config::get_user_agent()
This commit is contained in:
parent
5c60254474
commit
2c931df77c
|
@ -170,6 +170,9 @@ class Config {
|
||||||
const AUTH_MIN_INTERVAL = "AUTH_MIN_INTERVAL";
|
const AUTH_MIN_INTERVAL = "AUTH_MIN_INTERVAL";
|
||||||
// minimum amount of seconds required between authentication attempts
|
// minimum amount of seconds required between authentication attempts
|
||||||
|
|
||||||
|
const HTTP_USER_AGENT = "HTTP_USER_AGENT";
|
||||||
|
// http user agent (changing this is not recommended)
|
||||||
|
|
||||||
// default values for all of the above:
|
// default values for all of the above:
|
||||||
private const _DEFAULTS = [
|
private const _DEFAULTS = [
|
||||||
Config::DB_TYPE => [ "pgsql", Config::T_STRING ],
|
Config::DB_TYPE => [ "pgsql", Config::T_STRING ],
|
||||||
|
@ -224,6 +227,8 @@ class Config {
|
||||||
Config::CHECK_FOR_PLUGIN_UPDATES => [ "true", Config::T_BOOL ],
|
Config::CHECK_FOR_PLUGIN_UPDATES => [ "true", Config::T_BOOL ],
|
||||||
Config::ENABLE_PLUGIN_INSTALLER => [ "true", Config::T_BOOL ],
|
Config::ENABLE_PLUGIN_INSTALLER => [ "true", Config::T_BOOL ],
|
||||||
Config::AUTH_MIN_INTERVAL => [ 5, Config::T_INT ],
|
Config::AUTH_MIN_INTERVAL => [ 5, Config::T_INT ],
|
||||||
|
Config::HTTP_USER_AGENT => [ 'Tiny Tiny RSS/%s (https://tt-rss.org/)',
|
||||||
|
Config::T_STRING ],
|
||||||
];
|
];
|
||||||
|
|
||||||
private static $instance;
|
private static $instance;
|
||||||
|
@ -632,4 +637,8 @@ class Config {
|
||||||
|
|
||||||
return $rv;
|
return $rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static function get_user_agent() {
|
||||||
|
return sprintf(self::get(self::HTTP_USER_AGENT), self::get_version());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -281,8 +281,7 @@ class UrlHelper {
|
||||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||||
curl_setopt($ch, CURLOPT_HEADER, true);
|
curl_setopt($ch, CURLOPT_HEADER, true);
|
||||||
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
|
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
|
||||||
curl_setopt($ch, CURLOPT_USERAGENT, $useragent ? $useragent :
|
curl_setopt($ch, CURLOPT_USERAGENT, $useragent ? $useragent : Config::get_user_agent());
|
||||||
SELF_USER_AGENT);
|
|
||||||
curl_setopt($ch, CURLOPT_ENCODING, "");
|
curl_setopt($ch, CURLOPT_ENCODING, "");
|
||||||
|
|
||||||
if ($http_referrer)
|
if ($http_referrer)
|
||||||
|
|
|
@ -157,8 +157,7 @@
|
||||||
require_once 'controls.php';
|
require_once 'controls.php';
|
||||||
require_once 'controls_compat.php';
|
require_once 'controls_compat.php';
|
||||||
|
|
||||||
define('SELF_USER_AGENT', 'Tiny Tiny RSS/' . Config::get_version() . ' (http://tt-rss.org/)');
|
ini_set('user_agent', Config::get_user_agent());
|
||||||
ini_set('user_agent', SELF_USER_AGENT);
|
|
||||||
|
|
||||||
/* compat shims */
|
/* compat shims */
|
||||||
|
|
||||||
|
|
|
@ -785,7 +785,8 @@ class Af_RedditImgur extends Plugin {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function get_header($url, $header, $useragent = SELF_USER_AGENT) {
|
/** $useragent defaults to Config::get_user_agent() */
|
||||||
|
private function get_header($url, $header, $useragent = false) {
|
||||||
$ret = false;
|
$ret = false;
|
||||||
|
|
||||||
if (function_exists("curl_init")) {
|
if (function_exists("curl_init")) {
|
||||||
|
@ -795,7 +796,7 @@ class Af_RedditImgur extends Plugin {
|
||||||
curl_setopt($ch, CURLOPT_HEADER, true);
|
curl_setopt($ch, CURLOPT_HEADER, true);
|
||||||
curl_setopt($ch, CURLOPT_NOBODY, true);
|
curl_setopt($ch, CURLOPT_NOBODY, true);
|
||||||
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, !ini_get("open_basedir"));
|
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, !ini_get("open_basedir"));
|
||||||
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
|
curl_setopt($ch, CURLOPT_USERAGENT, $useragent ? $useragent : Config::get_user_agent());
|
||||||
|
|
||||||
@curl_exec($ch);
|
@curl_exec($ch);
|
||||||
$ret = curl_getinfo($ch, $header);
|
$ret = curl_getinfo($ch, $header);
|
||||||
|
@ -804,11 +805,11 @@ class Af_RedditImgur extends Plugin {
|
||||||
return $ret;
|
return $ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function get_content_type($url, $useragent = SELF_USER_AGENT) {
|
private function get_content_type($url, $useragent = false) {
|
||||||
return $this->get_header($url, CURLINFO_CONTENT_TYPE, $useragent);
|
return $this->get_header($url, CURLINFO_CONTENT_TYPE, $useragent);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function get_location($url, $useragent = SELF_USER_AGENT) {
|
private function get_location($url, $useragent = false) {
|
||||||
return $this->get_header($url, CURLINFO_EFFECTIVE_URL, $useragent);
|
return $this->get_header($url, CURLINFO_EFFECTIVE_URL, $useragent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue