mirror of
https://git.tt-rss.org/git/tt-rss.git
synced 2025-12-13 08:15:55 +00:00
debug logging system rework:
* support various logging levels per-message * remove hacks like debug_suppress, DAEMON_EXTENDED_DEBUG, etc * _debug() is kept as a compatibility shim for plugins
This commit is contained in:
@@ -8,10 +8,6 @@ class Af_Comics_Pa extends Af_ComicFilter {
|
||||
function process(&$article) {
|
||||
if (strpos($article["link"], "penny-arcade.com") !== FALSE && strpos($article["title"], "Comic:") !== FALSE) {
|
||||
|
||||
/*if ($debug_enabled) {
|
||||
_debug("af_pennyarcade: Processing comic");
|
||||
}*/
|
||||
|
||||
$doc = new DOMDocument();
|
||||
|
||||
if ($doc->loadHTML(fetch_file_contents($article["link"]))) {
|
||||
@@ -27,9 +23,6 @@ class Af_Comics_Pa extends Af_ComicFilter {
|
||||
}
|
||||
|
||||
if (strpos($article["link"], "penny-arcade.com") !== FALSE && strpos($article["title"], "News Post:") !== FALSE) {
|
||||
/*if ($debug_enabled) {
|
||||
_debug("af_pennyarcade: Processing news post");
|
||||
}*/
|
||||
$doc = new DOMDocument();
|
||||
|
||||
if ($doc->loadHTML(fetch_file_contents($article["link"]))) {
|
||||
|
||||
@@ -287,7 +287,7 @@ class Af_Psql_Trgm extends Plugin {
|
||||
$row = $sth->fetch();
|
||||
$nequal = $row['nequal'];
|
||||
|
||||
_debug("af_psql_trgm: num equals: $nequal");
|
||||
Debug::log("af_psql_trgm: num equals: $nequal", Debug::$LOG_EXTENDED);
|
||||
|
||||
if ($nequal != 0) {
|
||||
$article["force_catchup"] = true;
|
||||
@@ -304,7 +304,7 @@ class Af_Psql_Trgm extends Plugin {
|
||||
$row = $sth->fetch();
|
||||
$similarity_result = $row['ms'];
|
||||
|
||||
_debug("af_psql_trgm: similarity result: $similarity_result");
|
||||
Debug::log("af_psql_trgm: similarity result: $similarity_result", Debug::$LOG_EXTENDED);
|
||||
|
||||
if ($similarity_result >= $similarity) {
|
||||
$article["force_catchup"] = true;
|
||||
|
||||
@@ -82,7 +82,7 @@ class Af_RedditImgur extends Plugin {
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
private function inline_stuff($article, &$doc, $xpath, $debug = false) {
|
||||
private function inline_stuff($article, &$doc, $xpath) {
|
||||
|
||||
$entries = $xpath->query('(//a[@href]|//img[@src])');
|
||||
$img_entries = $xpath->query("(//img[@src])");
|
||||
@@ -93,12 +93,12 @@ class Af_RedditImgur extends Plugin {
|
||||
foreach ($entries as $entry) {
|
||||
if ($entry->hasAttribute("href") && strpos($entry->getAttribute("href"), "reddit.com") === FALSE) {
|
||||
|
||||
_debug("processing href: " . $entry->getAttribute("href"), $debug);
|
||||
Debug::log("processing href: " . $entry->getAttribute("href"), Debug::$LOG_VERBOSE);
|
||||
|
||||
$matches = array();
|
||||
|
||||
if (!$found && preg_match("/^https?:\/\/twitter.com\/(.*?)\/status\/(.*)/", $entry->getAttribute("href"), $matches)) {
|
||||
_debug("handling as twitter: " . $matches[1] . " " . $matches[2], $debug);
|
||||
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")));
|
||||
|
||||
@@ -130,7 +130,7 @@ class Af_RedditImgur extends Plugin {
|
||||
|
||||
if (!$found && preg_match("/https?:\/\/(www\.)?gfycat.com\/([a-z]+)$/i", $entry->getAttribute("href"), $matches)) {
|
||||
|
||||
_debug("Handling as Gfycat", $debug);
|
||||
Debug::log("Handling as Gfycat", Debug::$LOG_VERBOSE);
|
||||
|
||||
$source_stream = 'https://giant.gfycat.com/' . $matches[2] . '.mp4';
|
||||
$poster_url = 'https://thumbs.gfycat.com/' . $matches[2] . '-mobile.jpg';
|
||||
@@ -145,7 +145,7 @@ class Af_RedditImgur extends Plugin {
|
||||
|
||||
if (!$found && preg_match("/https?:\/\/v\.redd\.it\/(.*)$/i", $entry->getAttribute("href"), $matches)) {
|
||||
|
||||
_debug("Handling as reddit inline video", $debug);
|
||||
Debug::log("Handling as reddit inline video", Debug::$LOG_VERBOSE);
|
||||
|
||||
$img = $img_entries->item(0);
|
||||
|
||||
@@ -157,7 +157,7 @@ class Af_RedditImgur extends Plugin {
|
||||
|
||||
// Get original article URL from v.redd.it redirects
|
||||
$source_article_url = $this->get_location($matches[0]);
|
||||
_debug("Resolved ".$matches[0]." to ".$source_article_url, $debug);
|
||||
Debug::log("Resolved ".$matches[0]." to ".$source_article_url, Debug::$LOG_VERBOSE);
|
||||
|
||||
$source_stream = false;
|
||||
|
||||
@@ -190,7 +190,7 @@ class Af_RedditImgur extends Plugin {
|
||||
|
||||
if (!$found && preg_match("/https?:\/\/(www\.)?streamable.com\//i", $entry->getAttribute("href"))) {
|
||||
|
||||
_debug("Handling as Streamable", $debug);
|
||||
Debug::log("Handling as Streamable", Debug::$LOG_VERBOSE);
|
||||
|
||||
$tmp = fetch_file_contents($entry->getAttribute("href"));
|
||||
|
||||
@@ -216,21 +216,21 @@ class Af_RedditImgur extends Plugin {
|
||||
|
||||
// imgur .gif -> .gifv
|
||||
if (!$found && preg_match("/i\.imgur\.com\/(.*?)\.gif$/i", $entry->getAttribute("href"))) {
|
||||
_debug("Handling as imgur gif (->gifv)", $debug);
|
||||
Debug::log("Handling as imgur gif (->gifv)", Debug::$LOG_VERBOSE);
|
||||
|
||||
$entry->setAttribute("href",
|
||||
str_replace(".gif", ".gifv", $entry->getAttribute("href")));
|
||||
}
|
||||
|
||||
if (!$found && preg_match("/\.(gifv|mp4)$/i", $entry->getAttribute("href"))) {
|
||||
_debug("Handling as imgur gifv", $debug);
|
||||
Debug::log("Handling as imgur gifv", Debug::$LOG_VERBOSE);
|
||||
|
||||
$source_stream = str_replace(".gifv", ".mp4", $entry->getAttribute("href"));
|
||||
|
||||
if (strpos($source_stream, "imgur.com") !== FALSE)
|
||||
$poster_url = str_replace(".mp4", "h.jpg", $source_stream);
|
||||
|
||||
$this->handle_as_video($doc, $entry, $source_stream, $poster_url, $debug);
|
||||
$this->handle_as_video($doc, $entry, $source_stream, $poster_url);
|
||||
|
||||
$found = true;
|
||||
}
|
||||
@@ -243,7 +243,7 @@ class Af_RedditImgur extends Plugin {
|
||||
|
||||
$vid_id = $matches[1];
|
||||
|
||||
_debug("Handling as youtube: $vid_id", $debug);
|
||||
Debug::log("Handling as youtube: $vid_id", Debug::$LOG_VERBOSE);
|
||||
|
||||
$iframe = $doc->createElement("iframe");
|
||||
$iframe->setAttribute("class", "youtube-player");
|
||||
@@ -265,7 +265,7 @@ class Af_RedditImgur extends Plugin {
|
||||
mb_strpos($entry->getAttribute("href"), "i.reddituploads.com") !== FALSE ||
|
||||
mb_strpos($this->get_content_type($entry->getAttribute("href")), "image/") !== FALSE) {
|
||||
|
||||
_debug("Handling as a picture", $debug);
|
||||
Debug::log("Handling as a picture", Debug::$LOG_VERBOSE);
|
||||
|
||||
$img = $doc->createElement('img');
|
||||
$img->setAttribute("src", $entry->getAttribute("href"));
|
||||
@@ -281,7 +281,7 @@ class Af_RedditImgur extends Plugin {
|
||||
if (!$found && preg_match("/^https?:\/\/gyazo\.com\/([^\.\/]+$)/", $entry->getAttribute("href"), $matches)) {
|
||||
$img_id = $matches[1];
|
||||
|
||||
_debug("handling as gyazo: $img_id", $debug);
|
||||
Debug::log("handling as gyazo: $img_id", Debug::$LOG_VERBOSE);
|
||||
|
||||
$img = $doc->createElement('img');
|
||||
$img->setAttribute("src", "https://i.gyazo.com/$img_id.jpg");
|
||||
@@ -295,7 +295,7 @@ class Af_RedditImgur extends Plugin {
|
||||
|
||||
// let's try meta properties
|
||||
if (!$found) {
|
||||
_debug("looking for meta og:image", $debug);
|
||||
Debug::log("looking for meta og:image", Debug::$LOG_VERBOSE);
|
||||
|
||||
$content = fetch_file_contents(["url" => $entry->getAttribute("href"),
|
||||
"http_accept" => "text/*"]);
|
||||
@@ -415,9 +415,9 @@ class Af_RedditImgur extends Plugin {
|
||||
return 2;
|
||||
}
|
||||
|
||||
private function handle_as_video($doc, $entry, $source_stream, $poster_url = false, $debug = false) {
|
||||
private function handle_as_video($doc, $entry, $source_stream, $poster_url = false) {
|
||||
|
||||
_debug("handle_as_video: $source_stream", $debug);
|
||||
Debug::log("handle_as_video: $source_stream", Debug::$LOG_VERBOSE);
|
||||
|
||||
$video = $doc->createElement('video');
|
||||
$video->setAttribute("autoplay", "1");
|
||||
@@ -454,14 +454,14 @@ class Af_RedditImgur extends Plugin {
|
||||
@$doc->loadHTML("<html><body><a href=\"$url\">[link]</a></body>");
|
||||
$xpath = new DOMXPath($doc);
|
||||
|
||||
$found = $this->inline_stuff([], $doc, $xpath, true);
|
||||
$found = $this->inline_stuff([], $doc, $xpath);
|
||||
|
||||
print "Inline result: $found\n";
|
||||
|
||||
if (!$found) {
|
||||
print "\nReadability result:\n";
|
||||
|
||||
$article = $this->readability([], $url, $doc, $xpath, true);
|
||||
$article = $this->readability([], $url, $doc, $xpath);
|
||||
|
||||
print_r($article);
|
||||
} else {
|
||||
@@ -523,7 +523,7 @@ class Af_RedditImgur extends Plugin {
|
||||
"useragent" => $useragent_compat,
|
||||
"http_accept" => "text/html"]);
|
||||
|
||||
if ($debug) _debug("tmplen: " . mb_strlen($tmp));
|
||||
Debug::log("tmplen: " . mb_strlen($tmp), Debug::$LOG_VERBOSE);
|
||||
|
||||
if ($tmp && mb_strlen($tmp) < 1024 * 500) {
|
||||
|
||||
|
||||
@@ -170,7 +170,7 @@ class Cache_Starred_Images extends Plugin implements IHandler {
|
||||
|
||||
$status_filename = $this->cache_dir . $article_id . "-" . sha1($site_url) . ".status";
|
||||
|
||||
//_debug("status: $status_filename"); return;
|
||||
Debug::log("status: $status_filename", Debug::$LOG_EXTENDED);
|
||||
|
||||
if (file_exists($status_filename))
|
||||
$status = json_decode(file_get_contents($status_filename), true);
|
||||
@@ -181,7 +181,7 @@ class Cache_Starred_Images extends Plugin implements IHandler {
|
||||
|
||||
// only allow several download attempts for article
|
||||
if ($status["attempt"] > $this->max_cache_attempts) {
|
||||
_debug("too many attempts for $site_url");
|
||||
Debug::log("too many attempts for $site_url", Debug::$LOG_VERBOSE);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -214,7 +214,7 @@ class Cache_Starred_Images extends Plugin implements IHandler {
|
||||
|
||||
$local_filename = $this->cache_dir . $article_id . "-" . sha1($src) . $extension;
|
||||
|
||||
//_debug("cache_images: downloading: $src to $local_filename");
|
||||
Debug::log("cache_images: downloading: $src to $local_filename", Debug::$LOG_VERBOSE);
|
||||
|
||||
if (!file_exists($local_filename)) {
|
||||
$file_content = fetch_file_contents(["url" => $src, "max_size" => MAX_CACHE_FILE_SIZE]);
|
||||
|
||||
@@ -24,11 +24,11 @@ class Import_Export extends Plugin implements IHandler {
|
||||
return;
|
||||
}
|
||||
|
||||
_debug("please enter your username:");
|
||||
Debug::log("please enter your username:");
|
||||
|
||||
$username = trim(read_stdin());
|
||||
|
||||
_debug("importing $filename for user $username...\n");
|
||||
Debug::log("importing $filename for user $username...\n");
|
||||
|
||||
$sth = $this->pdo->prepare("SELECT id FROM ttrss_users WHERE login = ?");
|
||||
$sth->execute($username);
|
||||
|
||||
Reference in New Issue
Block a user