mirror of
https://git.tt-rss.org/git/tt-rss.git
synced 2025-12-13 08:15:55 +00:00
remove a lot of stuff from global context (functions.php), add a few helper classes instead
This commit is contained in:
@@ -13,7 +13,7 @@ class Af_Comics_Cad extends Af_ComicFilter {
|
||||
|
||||
$doc = new DOMDocument();
|
||||
|
||||
$res = fetch_file_contents($article["link"], false, false, false,
|
||||
$res = UrlHelper::fetch($article["link"], false, false, false,
|
||||
false, false, 0,
|
||||
"Mozilla/5.0 (Windows NT 6.1; WOW64; rv:50.0) Gecko/20100101 Firefox/50.0");
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ class Af_Comics_ComicClass extends Af_ComicFilter {
|
||||
// lol at people who block clients by user agent
|
||||
// oh noes my ad revenue Q_Q
|
||||
|
||||
$res = fetch_file_contents($article["link"], false, false, false,
|
||||
$res = UrlHelper::fetch($article["link"], false, false, false,
|
||||
false, false, 0,
|
||||
"Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)");
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ class Af_Comics_ComicPress extends Af_ComicFilter {
|
||||
// lol at people who block clients by user agent
|
||||
// oh noes my ad revenue Q_Q
|
||||
|
||||
$res = fetch_file_contents(["url" => $article["link"],
|
||||
$res = UrlHelper::fetch(["url" => $article["link"],
|
||||
"useragent" => "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)"]);
|
||||
|
||||
$doc = new DOMDocument();
|
||||
@@ -37,7 +37,7 @@ class Af_Comics_ComicPress extends Af_ComicFilter {
|
||||
|
||||
if ($webtoon_link) {
|
||||
|
||||
$res = fetch_file_contents(["url" => $webtoon_link->getAttribute("href"),
|
||||
$res = UrlHelper::fetch(["url" => $webtoon_link->getAttribute("href"),
|
||||
"useragent" => "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)"]);
|
||||
|
||||
if (@$doc->loadHTML($res)) {
|
||||
|
||||
@@ -9,7 +9,7 @@ class Af_Comics_DarkLegacy extends Af_ComicFilter {
|
||||
|
||||
if (strpos($article["guid"], "darklegacycomics.com") !== false) {
|
||||
|
||||
$res = fetch_file_contents($article["link"], false, false, false,
|
||||
$res = UrlHelper::fetch($article["link"], false, false, false,
|
||||
false, false, 0,
|
||||
"Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)");
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ class Af_Comics_Dilbert extends Af_ComicFilter {
|
||||
if (strpos($article["link"], "dilbert.com") !== false ||
|
||||
strpos($article["link"], "/DilbertDailyStrip") !== false) {
|
||||
|
||||
$res = fetch_file_contents($article["link"], false, false, false,
|
||||
$res = UrlHelper::fetch($article["link"], false, false, false,
|
||||
false, false, 0,
|
||||
"Mozilla/5.0 (Windows NT 6.1; WOW64; rv:50.0) Gecko/20100101 Firefox/50.0");
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ class Af_Comics_Explosm extends Af_ComicFilter {
|
||||
|
||||
$doc = new DOMDocument();
|
||||
|
||||
if (@$doc->loadHTML(fetch_file_contents($article["link"]))) {
|
||||
if (@$doc->loadHTML(UrlHelper::fetch($article["link"]))) {
|
||||
$xpath = new DOMXPath($doc);
|
||||
$basenode = $xpath->query('(//img[@id="main-comic"])')->item(0);
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ class Af_Comics_Gocomics extends Af_ComicFilter {
|
||||
|
||||
$article_link = $site_url . date('/Y/m/d');
|
||||
|
||||
$body = fetch_file_contents(array('url' => $article_link, 'type' => 'text/html', 'followlocation' => false));
|
||||
$body = UrlHelper::fetch(array('url' => $article_link, 'type' => 'text/html', 'followlocation' => false));
|
||||
|
||||
$feed_title = htmlspecialchars($comic[1]);
|
||||
$site_url = htmlspecialchars($site_url);
|
||||
|
||||
@@ -37,7 +37,7 @@ class Af_Comics_Gocomics_FarSide extends Af_ComicFilter {
|
||||
$tpl->setVariable('FEED_URL', htmlspecialchars($url), true);
|
||||
$tpl->setVariable('SELF_URL', htmlspecialchars($url), true);
|
||||
|
||||
$body = fetch_file_contents(['url' => $article_link, 'type' => 'text/html', 'followlocation' => false]);
|
||||
$body = UrlHelper::fetch(['url' => $article_link, 'type' => 'text/html', 'followlocation' => false]);
|
||||
|
||||
if ($body) {
|
||||
$doc = new DOMDocument();
|
||||
|
||||
@@ -10,7 +10,7 @@ class Af_Comics_Pa extends Af_ComicFilter {
|
||||
|
||||
$doc = new DOMDocument();
|
||||
|
||||
if ($doc->loadHTML(fetch_file_contents($article["link"]))) {
|
||||
if ($doc->loadHTML(UrlHelper::fetch($article["link"]))) {
|
||||
$xpath = new DOMXPath($doc);
|
||||
$basenode = $xpath->query('(//div[@id="comicFrame"])')->item(0);
|
||||
|
||||
@@ -25,7 +25,7 @@ class Af_Comics_Pa extends Af_ComicFilter {
|
||||
if (strpos($article["link"], "penny-arcade.com") !== false && strpos($article["title"], "News Post:") !== false) {
|
||||
$doc = new DOMDocument();
|
||||
|
||||
if ($doc->loadHTML(fetch_file_contents($article["link"]))) {
|
||||
if ($doc->loadHTML(UrlHelper::fetch($article["link"]))) {
|
||||
$xpath = new DOMXPath($doc);
|
||||
$entries = $xpath->query('(//div[@class="post"])');
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ class Af_Comics_Pvp extends Af_ComicFilter {
|
||||
function process(&$article) {
|
||||
if (strpos($article["guid"], "pvponline.com") !== false) {
|
||||
|
||||
$res = fetch_file_contents($article["link"], false, false, false,
|
||||
$res = UrlHelper::fetch($article["link"], false, false, false,
|
||||
false, false, 0,
|
||||
"Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)");
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ class Af_Comics_Tfd extends Af_ComicFilter {
|
||||
function process(&$article) {
|
||||
if (strpos($article["link"], "toothpastefordinner.com") !== false ||
|
||||
strpos($article["link"], "marriedtothesea.com") !== false) {
|
||||
$res = fetch_file_contents($article["link"], false, false, false,
|
||||
$res = UrlHelper::fetch($article["link"], false, false, false,
|
||||
false, false, 0,
|
||||
"Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)");
|
||||
|
||||
@@ -16,7 +16,7 @@ class Af_Comics_Tfd extends Af_ComicFilter {
|
||||
|
||||
$doc = new DOMDocument();
|
||||
|
||||
if (@$doc->loadHTML(fetch_file_contents($article["link"]))) {
|
||||
if (@$doc->loadHTML(UrlHelper::fetch($article["link"]))) {
|
||||
$xpath = new DOMXPath($doc);
|
||||
$basenode = $xpath->query('//img[contains(@src, ".gif")]')->item(0);
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ class Af_Comics_Twp extends Af_ComicFilter {
|
||||
|
||||
$doc = new DOMDocument();
|
||||
|
||||
if (@$doc->loadHTML(fetch_file_contents($article["link"]))) {
|
||||
if (@$doc->loadHTML(UrlHelper::fetch($article["link"]))) {
|
||||
$xpath = new DOMXpath($doc);
|
||||
|
||||
$basenode = $xpath->query("//td/center/img")->item(0);
|
||||
|
||||
@@ -8,7 +8,7 @@ class Af_Comics_Whomp extends Af_ComicFilter {
|
||||
function process(&$article) {
|
||||
if (strpos($article["guid"], "whompcomic.com") !== false) {
|
||||
|
||||
$res = fetch_file_contents($article["link"], false, false, false,
|
||||
$res = UrlHelper::fetch($article["link"], false, false, false,
|
||||
false, false, 0,
|
||||
"Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)");
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ class Af_Proxy_Http extends Plugin {
|
||||
}
|
||||
|
||||
public function imgproxy() {
|
||||
$url = validate_url(clean($_REQUEST["url"]));
|
||||
$url = UrlHelper::validate(clean($_REQUEST["url"]));
|
||||
|
||||
// called without user context, let's just redirect to original URL
|
||||
if (!$_SESSION["uid"] || $_REQUEST['af_proxy_http_token'] != $_SESSION['af_proxy_http_token']) {
|
||||
@@ -62,7 +62,7 @@ class Af_Proxy_Http extends Plugin {
|
||||
header("Location: " . $this->cache->getUrl($local_filename));
|
||||
return;
|
||||
} else {
|
||||
$data = fetch_file_contents(["url" => $url, "max_size" => MAX_CACHE_FILE_SIZE]);
|
||||
$data = UrlHelper::fetch(["url" => $url, "max_size" => MAX_CACHE_FILE_SIZE]);
|
||||
|
||||
if ($data) {
|
||||
if ($this->cache->put($local_filename, $data)) {
|
||||
@@ -125,7 +125,7 @@ class Af_Proxy_Http extends Plugin {
|
||||
foreach (explode(" " , $this->ssl_known_whitelist) as $host) {
|
||||
if (substr(strtolower($parts['host']), -strlen($host)) === strtolower($host)) {
|
||||
$parts['scheme'] = 'https';
|
||||
$url = build_url($parts);
|
||||
$url = UrlHelper::build_url($parts);
|
||||
if ($all_remote && $is_remote) {
|
||||
break;
|
||||
} else {
|
||||
|
||||
@@ -176,7 +176,7 @@ class Af_Readability extends Plugin {
|
||||
|
||||
global $fetch_effective_url;
|
||||
|
||||
$tmp = fetch_file_contents([
|
||||
$tmp = UrlHelper::fetch([
|
||||
"url" => $url,
|
||||
"http_accept" => "text/*",
|
||||
"type" => "text/html"]);
|
||||
@@ -235,7 +235,7 @@ class Af_Readability extends Plugin {
|
||||
$extracted_content = $this->extract_content($article["link"]);
|
||||
|
||||
# let's see if there's anything of value in there
|
||||
$content_test = trim(strip_tags(sanitize($extracted_content)));
|
||||
$content_test = trim(strip_tags(Sanitizer::sanitize($extracted_content)));
|
||||
|
||||
if ($content_test) {
|
||||
$article["content"] = $extracted_content;
|
||||
@@ -264,7 +264,7 @@ class Af_Readability extends Plugin {
|
||||
$extracted_content = $this->extract_content($link);
|
||||
|
||||
# let's see if there's anything of value in there
|
||||
$content_test = trim(strip_tags(sanitize($extracted_content)));
|
||||
$content_test = trim(strip_tags(Sanitizer::sanitize($extracted_content)));
|
||||
|
||||
if ($content_test) {
|
||||
return $extracted_content;
|
||||
@@ -303,7 +303,7 @@ class Af_Readability extends Plugin {
|
||||
$ret = [];
|
||||
|
||||
if ($row = $sth->fetch()) {
|
||||
$ret["content"] = sanitize($this->extract_content($row["link"]));
|
||||
$ret["content"] = Sanitizer::sanitize($this->extract_content($row["link"]));
|
||||
}
|
||||
|
||||
print json_encode($ret);
|
||||
|
||||
@@ -103,7 +103,7 @@ class Af_RedditImgur extends Plugin {
|
||||
if (!$found && preg_match("/^https?:\/\/twitter.com\/(.*?)\/status\/(.*)/", $entry->getAttribute("href"), $matches)) {
|
||||
Debug::log("handling as twitter: " . $matches[1] . " " . $matches[2], Debug::$LOG_VERBOSE);
|
||||
|
||||
$oembed_result = fetch_file_contents("https://publish.twitter.com/oembed?url=" . urlencode($entry->getAttribute("href")));
|
||||
$oembed_result = UrlHelper::fetch("https://publish.twitter.com/oembed?url=" . urlencode($entry->getAttribute("href")));
|
||||
|
||||
if ($oembed_result) {
|
||||
$oembed_result = json_decode($oembed_result, true);
|
||||
@@ -165,7 +165,7 @@ class Af_RedditImgur extends Plugin {
|
||||
$source_stream = false;
|
||||
|
||||
if ($source_article_url) {
|
||||
$j = json_decode(fetch_file_contents($source_article_url.".json"), true);
|
||||
$j = json_decode(UrlHelper::fetch($source_article_url.".json"), true);
|
||||
|
||||
if ($j) {
|
||||
foreach ($j as $listing) {
|
||||
@@ -195,7 +195,7 @@ class Af_RedditImgur extends Plugin {
|
||||
|
||||
Debug::log("Handling as Streamable", Debug::$LOG_VERBOSE);
|
||||
|
||||
$tmp = fetch_file_contents($entry->getAttribute("href"));
|
||||
$tmp = UrlHelper::fetch($entry->getAttribute("href"));
|
||||
|
||||
if ($tmp) {
|
||||
$tmpdoc = new DOMDocument();
|
||||
@@ -285,7 +285,7 @@ class Af_RedditImgur extends Plugin {
|
||||
|
||||
Debug::log("handling as imgur page/whatever", Debug::$LOG_VERBOSE);
|
||||
|
||||
$content = fetch_file_contents(["url" => $entry->getAttribute("href"),
|
||||
$content = UrlHelper::fetch(["url" => $entry->getAttribute("href"),
|
||||
"http_accept" => "text/*"]);
|
||||
|
||||
if ($content) {
|
||||
@@ -331,7 +331,7 @@ class Af_RedditImgur extends Plugin {
|
||||
if (!$found) {
|
||||
Debug::log("looking for meta og:image", Debug::$LOG_VERBOSE);
|
||||
|
||||
$content = fetch_file_contents(["url" => $entry->getAttribute("href"),
|
||||
$content = UrlHelper::fetch(["url" => $entry->getAttribute("href"),
|
||||
"http_accept" => "text/*"]);
|
||||
|
||||
if ($content) {
|
||||
|
||||
@@ -40,16 +40,16 @@ class Cache_Starred_Images extends Plugin {
|
||||
|
||||
Debug::log("caching media of starred articles for user " . $this->host->get_owner_uid() . "...");
|
||||
|
||||
$sth = $this->pdo->prepare("SELECT content, ttrss_entries.title,
|
||||
$sth = $this->pdo->prepare("SELECT content, ttrss_entries.title,
|
||||
ttrss_user_entries.owner_uid, link, site_url, ttrss_entries.id, plugin_data
|
||||
FROM ttrss_entries, ttrss_user_entries LEFT JOIN ttrss_feeds ON
|
||||
(ttrss_user_entries.feed_id = ttrss_feeds.id)
|
||||
WHERE ref_id = ttrss_entries.id AND
|
||||
marked = true AND
|
||||
site_url != '' AND
|
||||
site_url != '' AND
|
||||
ttrss_user_entries.owner_uid = ? AND
|
||||
plugin_data NOT LIKE '%starred_cache_images%'
|
||||
ORDER BY ".sql_random_function()." LIMIT 100");
|
||||
ORDER BY ".Db::sql_random_function()." LIMIT 100");
|
||||
|
||||
if ($sth->execute([$this->host->get_owner_uid()])) {
|
||||
|
||||
@@ -139,7 +139,7 @@ class Cache_Starred_Images extends Plugin {
|
||||
if (!$this->cache->exists($local_filename)) {
|
||||
Debug::log("cache_images: downloading: $url to $local_filename", Debug::$LOG_VERBOSE);
|
||||
|
||||
$data = fetch_file_contents(["url" => $url, "max_size" => MAX_CACHE_FILE_SIZE]);
|
||||
$data = UrlHelper::fetch(["url" => $url, "max_size" => MAX_CACHE_FILE_SIZE]);
|
||||
|
||||
if ($data)
|
||||
return $this->cache->put($local_filename, $data);;
|
||||
|
||||
@@ -23,7 +23,7 @@ class No_Iframes extends Plugin {
|
||||
$entries = $xpath->query('//iframe');
|
||||
|
||||
foreach ($entries as $entry) {
|
||||
if (!iframe_whitelisted($entry))
|
||||
if (!Sanitizer::iframe_whitelisted($entry))
|
||||
$entry->parentNode->removeChild($entry);
|
||||
}
|
||||
|
||||
@@ -34,4 +34,4 @@ class No_Iframes extends Plugin {
|
||||
return 2;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user