/**
* @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])");
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")));
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';
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);
// 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;
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"));
// 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;
}
$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");
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"));
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");
// 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/*"]);
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");
@$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 {
"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) {