@@ -121,36 +121,36 @@ |
||
| 121 | 121 | $contentScore = 0; |
| 122 | 122 | |
| 123 | 123 | switch ($this->nodeName) { |
| 124 | - case 'div': |
|
| 125 | - $contentScore += 5; |
|
| 126 | - break; |
|
| 127 | - |
|
| 128 | - case 'pre': |
|
| 129 | - case 'td': |
|
| 130 | - case 'blockquote': |
|
| 131 | - $contentScore += 3; |
|
| 132 | - break; |
|
| 133 | - |
|
| 134 | - case 'address': |
|
| 135 | - case 'ol': |
|
| 136 | - case 'ul': |
|
| 137 | - case 'dl': |
|
| 138 | - case 'dd': |
|
| 139 | - case 'dt': |
|
| 140 | - case 'li': |
|
| 141 | - case 'form': |
|
| 142 | - $contentScore -= 3; |
|
| 143 | - break; |
|
| 144 | - |
|
| 145 | - case 'h1': |
|
| 146 | - case 'h2': |
|
| 147 | - case 'h3': |
|
| 148 | - case 'h4': |
|
| 149 | - case 'h5': |
|
| 150 | - case 'h6': |
|
| 151 | - case 'th': |
|
| 152 | - $contentScore -= 5; |
|
| 153 | - break; |
|
| 124 | + case 'div': |
|
| 125 | + $contentScore += 5; |
|
| 126 | + break; |
|
| 127 | + |
|
| 128 | + case 'pre': |
|
| 129 | + case 'td': |
|
| 130 | + case 'blockquote': |
|
| 131 | + $contentScore += 3; |
|
| 132 | + break; |
|
| 133 | + |
|
| 134 | + case 'address': |
|
| 135 | + case 'ol': |
|
| 136 | + case 'ul': |
|
| 137 | + case 'dl': |
|
| 138 | + case 'dd': |
|
| 139 | + case 'dt': |
|
| 140 | + case 'li': |
|
| 141 | + case 'form': |
|
| 142 | + $contentScore -= 3; |
|
| 143 | + break; |
|
| 144 | + |
|
| 145 | + case 'h1': |
|
| 146 | + case 'h2': |
|
| 147 | + case 'h3': |
|
| 148 | + case 'h4': |
|
| 149 | + case 'h5': |
|
| 150 | + case 'h6': |
|
| 151 | + case 'th': |
|
| 152 | + $contentScore -= 5; |
|
| 153 | + break; |
|
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | $this->contentScore = $contentScore + ($weightClasses ? $this->getClassWeight() : 0); |
@@ -328,7 +328,7 @@ discard block |
||
| 328 | 328 | $ret = iterator_to_array($this->childNodes); |
| 329 | 329 | if ($filterEmptyDOMText) { |
| 330 | 330 | // Array values is used to discard the key order. Needs to be 0 to whatever without skipping any number |
| 331 | - $ret = array_values(array_filter($ret, function ($node) { |
|
| 331 | + $ret = array_values(array_filter($ret, function($node) { |
|
| 332 | 332 | return $node->nodeName !== '#text' || mb_strlen(trim($node->nodeValue)); |
| 333 | 333 | })); |
| 334 | 334 | } |
@@ -427,7 +427,7 @@ discard block |
||
| 427 | 427 | } |
| 428 | 428 | |
| 429 | 429 | // And there should be no text nodes with real content |
| 430 | - return array_reduce(iterator_to_array($children), function ($carry, $child) { |
|
| 430 | + return array_reduce(iterator_to_array($children), function($carry, $child) { |
|
| 431 | 431 | if (!$carry === false) { |
| 432 | 432 | return false; |
| 433 | 433 | } |
@@ -480,7 +480,7 @@ discard block |
||
| 480 | 480 | * are dealing with (And at this point we know they are empty or are just whitespace, because of the |
| 481 | 481 | * mb_strlen in this chain of checks). |
| 482 | 482 | */ |
| 483 | - + count(array_filter(iterator_to_array($this->childNodes), function ($child) { |
|
| 483 | + + count(array_filter(iterator_to_array($this->childNodes), function($child) { |
|
| 484 | 484 | return $child instanceof DOMText; |
| 485 | 485 | })) |
| 486 | 486 | |
@@ -498,7 +498,7 @@ discard block |
||
| 498 | 498 | return $this->nodeType === XML_TEXT_NODE || in_array($this->nodeName, $this->phrasing_elems) !== false || |
| 499 | 499 | (!is_null($this->childNodes) && |
| 500 | 500 | ($this->nodeName === 'a' || $this->nodeName === 'del' || $this->nodeName === 'ins') && |
| 501 | - array_reduce(iterator_to_array($this->childNodes), function ($carry, $node) { |
|
| 501 | + array_reduce(iterator_to_array($this->childNodes), function($carry, $node) { |
|
| 502 | 502 | return $node->isPhrasingContent() && $carry; |
| 503 | 503 | }, true) |
| 504 | 504 | ); |
@@ -194,7 +194,7 @@ discard block |
||
| 194 | 194 | $this->attempts[] = ['articleContent' => $result, 'textLength' => $length]; |
| 195 | 195 | |
| 196 | 196 | // No luck after removing flags, just return the longest text we found during the different loops |
| 197 | - usort($this->attempts, function ($a, $b) { |
|
| 197 | + usort($this->attempts, function($a, $b) { |
|
| 198 | 198 | return $a['textLength'] < $b['textLength']; |
| 199 | 199 | }); |
| 200 | 200 | |
@@ -273,7 +273,7 @@ discard block |
||
| 273 | 273 | } |
| 274 | 274 | |
| 275 | 275 | // Prepend the XML tag to avoid having issues with special characters. Should be harmless. |
| 276 | - $dom->loadHTML('<?xml encoding="UTF-8">' . $html); |
|
| 276 | + $dom->loadHTML('<?xml encoding="UTF-8">'.$html); |
|
| 277 | 277 | $dom->encoding = 'UTF-8'; |
| 278 | 278 | |
| 279 | 279 | $this->removeScripts($dom); |
@@ -491,7 +491,7 @@ discard block |
||
| 491 | 491 | * I can assure you it works properly if you let the code run. |
| 492 | 492 | */ |
| 493 | 493 | if (preg_match('/ [\|\-\\\\\/>»] /i', $curTitle)) { |
| 494 | - $titleHadHierarchicalSeparators = (bool)preg_match('/ [\\\\\/>»] /', $curTitle); |
|
| 494 | + $titleHadHierarchicalSeparators = (bool) preg_match('/ [\\\\\/>»] /', $curTitle); |
|
| 495 | 495 | $curTitle = preg_replace('/(.*)[\|\-\\\\\/>»] .*/i', '$1', $originalTitle); |
| 496 | 496 | |
| 497 | 497 | $this->logger->info(sprintf('[Metadata] Found hierarchical separators in title, new title is: \'%s\'', $curTitle)); |
@@ -507,7 +507,7 @@ discard block |
||
| 507 | 507 | // could assume it's the full title. |
| 508 | 508 | $match = false; |
| 509 | 509 | for ($i = 1; $i <= 2; $i++) { |
| 510 | - foreach ($this->dom->getElementsByTagName('h' . $i) as $hTag) { |
|
| 510 | + foreach ($this->dom->getElementsByTagName('h'.$i) as $hTag) { |
|
| 511 | 511 | // Trim texts to avoid having false negatives when the title is surrounded by spaces or tabs |
| 512 | 512 | if (trim($hTag->nodeValue) === trim($curTitle)) { |
| 513 | 513 | $match = true; |
@@ -579,17 +579,17 @@ discard block |
||
| 579 | 579 | |
| 580 | 580 | // Scheme-rooted relative URI. |
| 581 | 581 | if (substr($uri, 0, 2) === '//') { |
| 582 | - return $scheme . '://' . substr($uri, 2); |
|
| 582 | + return $scheme.'://'.substr($uri, 2); |
|
| 583 | 583 | } |
| 584 | 584 | |
| 585 | 585 | // Prepath-rooted relative URI. |
| 586 | 586 | if (substr($uri, 0, 1) === '/') { |
| 587 | - return $prePath . $uri; |
|
| 587 | + return $prePath.$uri; |
|
| 588 | 588 | } |
| 589 | 589 | |
| 590 | 590 | // Dotslash relative URI. |
| 591 | 591 | if (strpos($uri, './') === 0) { |
| 592 | - return $pathBase . substr($uri, 2); |
|
| 592 | + return $pathBase.substr($uri, 2); |
|
| 593 | 593 | } |
| 594 | 594 | // Ignore hash URIs: |
| 595 | 595 | if (substr($uri, 0, 1) === '#') { |
@@ -598,7 +598,7 @@ discard block |
||
| 598 | 598 | |
| 599 | 599 | // Standard relative URI; add entire path. pathBase already includes a |
| 600 | 600 | // trailing "/". |
| 601 | - return $pathBase . $uri; |
|
| 601 | + return $pathBase.$uri; |
|
| 602 | 602 | } |
| 603 | 603 | |
| 604 | 604 | /** |
@@ -614,17 +614,17 @@ discard block |
||
| 614 | 614 | if ($this->dom->baseURI !== null) { |
| 615 | 615 | if (substr($this->dom->baseURI, 0, 1) === '/') { |
| 616 | 616 | // URLs starting with '/' override completely the URL defined in the link |
| 617 | - $pathBase = parse_url($url, PHP_URL_SCHEME) . '://' . parse_url($url, PHP_URL_HOST) . $this->dom->baseURI; |
|
| 617 | + $pathBase = parse_url($url, PHP_URL_SCHEME).'://'.parse_url($url, PHP_URL_HOST).$this->dom->baseURI; |
|
| 618 | 618 | } else { |
| 619 | 619 | // Otherwise just prepend the base to the actual path |
| 620 | - $pathBase = parse_url($url, PHP_URL_SCHEME) . '://' . parse_url($url, PHP_URL_HOST) . dirname(parse_url($url, PHP_URL_PATH)) . '/' . rtrim($this->dom->baseURI, '/') . '/'; |
|
| 620 | + $pathBase = parse_url($url, PHP_URL_SCHEME).'://'.parse_url($url, PHP_URL_HOST).dirname(parse_url($url, PHP_URL_PATH)).'/'.rtrim($this->dom->baseURI, '/').'/'; |
|
| 621 | 621 | } |
| 622 | 622 | } else { |
| 623 | - $pathBase = parse_url($url, PHP_URL_SCHEME) . '://' . parse_url($url, PHP_URL_HOST) . dirname(parse_url($url, PHP_URL_PATH)) . '/'; |
|
| 623 | + $pathBase = parse_url($url, PHP_URL_SCHEME).'://'.parse_url($url, PHP_URL_HOST).dirname(parse_url($url, PHP_URL_PATH)).'/'; |
|
| 624 | 624 | } |
| 625 | 625 | |
| 626 | 626 | $scheme = parse_url($pathBase, PHP_URL_SCHEME); |
| 627 | - $prePath = $scheme . '://' . parse_url($pathBase, PHP_URL_HOST); |
|
| 627 | + $prePath = $scheme.'://'.parse_url($pathBase, PHP_URL_HOST); |
|
| 628 | 628 | |
| 629 | 629 | return [$pathBase, $scheme, $prePath]; |
| 630 | 630 | } |
@@ -658,7 +658,7 @@ discard block |
||
| 658 | 658 | continue; |
| 659 | 659 | } |
| 660 | 660 | |
| 661 | - $matchString = $node->getAttribute('class') . ' ' . $node->getAttribute('id'); |
|
| 661 | + $matchString = $node->getAttribute('class').' '.$node->getAttribute('id'); |
|
| 662 | 662 | |
| 663 | 663 | if (!$node->isProbablyVisible()) { |
| 664 | 664 | $this->logger->debug(sprintf('[Get Nodes] Removing hidden node... Match string was: \'%s\'', $matchString)); |
@@ -1049,7 +1049,7 @@ discard block |
||
| 1049 | 1049 | while ($parentOfTopCandidate->nodeName !== 'body' && $parentOfTopCandidate->nodeType === XML_ELEMENT_NODE) { |
| 1050 | 1050 | $listsContainingThisAncestor = 0; |
| 1051 | 1051 | for ($ancestorIndex = 0; $ancestorIndex < count($alternativeCandidateAncestors) && $listsContainingThisAncestor < $MINIMUM_TOPCANDIDATES; $ancestorIndex++) { |
| 1052 | - $listsContainingThisAncestor += (int)in_array($parentOfTopCandidate, $alternativeCandidateAncestors[$ancestorIndex]); |
|
| 1052 | + $listsContainingThisAncestor += (int) in_array($parentOfTopCandidate, $alternativeCandidateAncestors[$ancestorIndex]); |
|
| 1053 | 1053 | } |
| 1054 | 1054 | if ($listsContainingThisAncestor >= $MINIMUM_TOPCANDIDATES) { |
| 1055 | 1055 | $topCandidate = $parentOfTopCandidate; |
@@ -1285,7 +1285,7 @@ discard block |
||
| 1285 | 1285 | $row = $tbody->getFirstElementChild(); |
| 1286 | 1286 | if ($row->hasSingleTagInsideElement('td')) { |
| 1287 | 1287 | $cell = $row->getFirstElementChild(); |
| 1288 | - $cell = NodeUtility::setNodeTag($cell, (array_reduce(iterator_to_array($cell->childNodes), function ($carry, $node) { |
|
| 1288 | + $cell = NodeUtility::setNodeTag($cell, (array_reduce(iterator_to_array($cell->childNodes), function($carry, $node) { |
|
| 1289 | 1289 | return $node->isPhrasingContent() && $carry; |
| 1290 | 1290 | }, true)) ? 'p' : 'div'); |
| 1291 | 1291 | $table->parentNode->replaceChild($cell, $table); |
@@ -1465,7 +1465,7 @@ discard block |
||
| 1465 | 1465 | $node = $DOMNodeList->item($length - 1 - $i); |
| 1466 | 1466 | |
| 1467 | 1467 | // First check if we're in a data table, in which case don't remove us. |
| 1468 | - if ($node->hasAncestorTag('table', -1, function ($node) { |
|
| 1468 | + if ($node->hasAncestorTag('table', -1, function($node) { |
|
| 1469 | 1469 | return $node->isReadabilityDataTable(); |
| 1470 | 1470 | })) { |
| 1471 | 1471 | continue; |
@@ -1577,7 +1577,7 @@ discard block |
||
| 1577 | 1577 | public function _cleanHeaders(DOMDocument $article) |
| 1578 | 1578 | { |
| 1579 | 1579 | for ($headerIndex = 1; $headerIndex < 3; $headerIndex++) { |
| 1580 | - $headers = $article->getElementsByTagName('h' . $headerIndex); |
|
| 1580 | + $headers = $article->getElementsByTagName('h'.$headerIndex); |
|
| 1581 | 1581 | /** @var $header DOMElement */ |
| 1582 | 1582 | foreach ($headers as $header) { |
| 1583 | 1583 | $weight = 0; |
@@ -57,13 +57,13 @@ discard block |
||
| 57 | 57 | print "<fieldset class='narrow'>"; |
| 58 | 58 | print "<label class='checkbox'>"; |
| 59 | 59 | print_checkbox("enable_readability", $enable_readability); |
| 60 | - print " " . __("Extract missing content using Readability (requires af_readability)") . "</label>"; |
|
| 60 | + print " ".__("Extract missing content using Readability (requires af_readability)")."</label>"; |
|
| 61 | 61 | print "</fieldset>"; |
| 62 | 62 | |
| 63 | 63 | print "<fieldset class='narrow'>"; |
| 64 | 64 | print "<label class='checkbox'>"; |
| 65 | 65 | print_checkbox("enable_content_dupcheck", $enable_content_dupcheck); |
| 66 | - print " " . __("Enable additional duplicate checking") . "</label>"; |
|
| 66 | + print " ".__("Enable additional duplicate checking")."</label>"; |
|
| 67 | 67 | print "</fieldset>"; |
| 68 | 68 | |
| 69 | 69 | print_button("submit", __("Save"), 'class="alt-primary"'); |
@@ -96,14 +96,14 @@ discard block |
||
| 96 | 96 | foreach ($entries as $entry) { |
| 97 | 97 | if ($entry->hasAttribute("href") && strpos($entry->getAttribute("href"), "reddit.com") === FALSE) { |
| 98 | 98 | |
| 99 | - Debug::log("processing href: " . $entry->getAttribute("href"), Debug::$LOG_VERBOSE); |
|
| 99 | + Debug::log("processing href: ".$entry->getAttribute("href"), Debug::$LOG_VERBOSE); |
|
| 100 | 100 | |
| 101 | 101 | $matches = array(); |
| 102 | 102 | |
| 103 | 103 | if (!$found && preg_match("/^https?:\/\/twitter.com\/(.*?)\/status\/(.*)/", $entry->getAttribute("href"), $matches)) { |
| 104 | - Debug::log("handling as twitter: " . $matches[1] . " " . $matches[2], Debug::$LOG_VERBOSE); |
|
| 104 | + Debug::log("handling as twitter: ".$matches[1]." ".$matches[2], Debug::$LOG_VERBOSE); |
|
| 105 | 105 | |
| 106 | - $oembed_result = fetch_file_contents("https://publish.twitter.com/oembed?url=" . urlencode($entry->getAttribute("href"))); |
|
| 106 | + $oembed_result = fetch_file_contents("https://publish.twitter.com/oembed?url=".urlencode($entry->getAttribute("href"))); |
|
| 107 | 107 | |
| 108 | 108 | if ($oembed_result) { |
| 109 | 109 | $oembed_result = json_decode($oembed_result, true); |
@@ -111,7 +111,7 @@ discard block |
||
| 111 | 111 | if ($oembed_result && isset($oembed_result["html"])) { |
| 112 | 112 | |
| 113 | 113 | $tmp = new DOMDocument(); |
| 114 | - if ($tmp->loadHTML('<?xml encoding="utf-8" ?>' . $oembed_result["html"])) { |
|
| 114 | + if ($tmp->loadHTML('<?xml encoding="utf-8" ?>'.$oembed_result["html"])) { |
|
| 115 | 115 | $p = $doc->createElement("p"); |
| 116 | 116 | |
| 117 | 117 | $p->appendChild($doc->importNode( |
@@ -135,8 +135,8 @@ discard block |
||
| 135 | 135 | |
| 136 | 136 | Debug::log("Handling as Gfycat", Debug::$LOG_VERBOSE); |
| 137 | 137 | |
| 138 | - $source_stream = 'https://giant.gfycat.com/' . $matches[2] . '.mp4'; |
|
| 139 | - $poster_url = 'https://thumbs.gfycat.com/' . $matches[2] . '-mobile.jpg'; |
|
| 138 | + $source_stream = 'https://giant.gfycat.com/'.$matches[2].'.mp4'; |
|
| 139 | + $poster_url = 'https://thumbs.gfycat.com/'.$matches[2].'-mobile.jpg'; |
|
| 140 | 140 | |
| 141 | 141 | $content_type = $this->get_content_type($source_stream); |
| 142 | 142 | |
@@ -184,7 +184,7 @@ discard block |
||
| 184 | 184 | } |
| 185 | 185 | |
| 186 | 186 | if (!$source_stream) { |
| 187 | - $source_stream = "https://v.redd.it/" . $matches[1] . "/DASH_600_K"; |
|
| 187 | + $source_stream = "https://v.redd.it/".$matches[1]."/DASH_600_K"; |
|
| 188 | 188 | } |
| 189 | 189 | |
| 190 | 190 | $this->handle_as_video($doc, $entry, $source_stream, $poster_url); |
@@ -542,7 +542,7 @@ discard block |
||
| 542 | 542 | |
| 543 | 543 | // do not try to embed posts linking back to other reddit posts |
| 544 | 544 | // readability.php requires PHP 5.6 |
| 545 | - if ($url && strpos($url, "reddit.com") === FALSE && version_compare(PHP_VERSION, '5.6.0', '>=')) { |
|
| 545 | + if ($url && strpos($url, "reddit.com") === FALSE && version_compare(PHP_VERSION, '5.6.0', '>=')) { |
|
| 546 | 546 | |
| 547 | 547 | /* link may lead to a huge video file or whatever, we need to check content type before trying to |
| 548 | 548 | parse it which p much requires curl */ |
@@ -94,7 +94,7 @@ discard block |
||
| 94 | 94 | //$debug = 1; |
| 95 | 95 | |
| 96 | 96 | foreach ($entries as $entry) { |
| 97 | - if ($entry->hasAttribute("href") && strpos($entry->getAttribute("href"), "reddit.com") === FALSE) { |
|
| 97 | + if ($entry->hasAttribute("href") && strpos($entry->getAttribute("href"), "reddit.com") === false) { |
|
| 98 | 98 | |
| 99 | 99 | Debug::log("processing href: " . $entry->getAttribute("href"), Debug::$LOG_VERBOSE); |
| 100 | 100 | |
@@ -115,7 +115,7 @@ discard block |
||
| 115 | 115 | $p = $doc->createElement("p"); |
| 116 | 116 | |
| 117 | 117 | $p->appendChild($doc->importNode( |
| 118 | - $tmp->getElementsByTagName("blockquote")->item(0), TRUE)); |
|
| 118 | + $tmp->getElementsByTagName("blockquote")->item(0), true)); |
|
| 119 | 119 | |
| 120 | 120 | $br = $doc->createElement('br'); |
| 121 | 121 | $entry->parentNode->insertBefore($p, $entry); |
@@ -140,7 +140,7 @@ discard block |
||
| 140 | 140 | |
| 141 | 141 | $content_type = $this->get_content_type($source_stream); |
| 142 | 142 | |
| 143 | - if (strpos($content_type, "video/") !== FALSE) { |
|
| 143 | + if (strpos($content_type, "video/") !== false) { |
|
| 144 | 144 | $this->handle_as_video($doc, $entry, $source_stream, $poster_url); |
| 145 | 145 | $found = 1; |
| 146 | 146 | } |
@@ -230,7 +230,7 @@ discard block |
||
| 230 | 230 | |
| 231 | 231 | $source_stream = str_replace(".gifv", ".mp4", $entry->getAttribute("href")); |
| 232 | 232 | |
| 233 | - if (strpos($source_stream, "imgur.com") !== FALSE) |
|
| 233 | + if (strpos($source_stream, "imgur.com") !== false) |
|
| 234 | 234 | $poster_url = str_replace(".mp4", "h.jpg", $source_stream); |
| 235 | 235 | |
| 236 | 236 | $this->handle_as_video($doc, $entry, $source_stream, $poster_url); |
@@ -265,8 +265,8 @@ discard block |
||
| 265 | 265 | } |
| 266 | 266 | |
| 267 | 267 | if (!$found && preg_match("/\.(jpg|jpeg|gif|png)(\?[0-9][0-9]*)?$/i", $entry->getAttribute("href")) || |
| 268 | - mb_strpos($entry->getAttribute("href"), "i.reddituploads.com") !== FALSE || |
|
| 269 | - mb_strpos($this->get_content_type($entry->getAttribute("href")), "image/") !== FALSE) { |
|
| 268 | + mb_strpos($entry->getAttribute("href"), "i.reddituploads.com") !== false || |
|
| 269 | + mb_strpos($this->get_content_type($entry->getAttribute("href")), "image/") !== false) { |
|
| 270 | 270 | |
| 271 | 271 | Debug::log("Handling as a picture", Debug::$LOG_VERBOSE); |
| 272 | 272 | |
@@ -393,7 +393,7 @@ discard block |
||
| 393 | 393 | |
| 394 | 394 | public function hook_article_filter($article) { |
| 395 | 395 | |
| 396 | - if (strpos($article["link"], "reddit.com/r/") !== FALSE) { |
|
| 396 | + if (strpos($article["link"], "reddit.com/r/") !== false) { |
|
| 397 | 397 | $doc = new DOMDocument(); |
| 398 | 398 | @$doc->loadHTML($article["content"]); |
| 399 | 399 | $xpath = new DOMXPath($doc); |
@@ -542,7 +542,7 @@ discard block |
||
| 542 | 542 | |
| 543 | 543 | // do not try to embed posts linking back to other reddit posts |
| 544 | 544 | // readability.php requires PHP 5.6 |
| 545 | - if ($url && strpos($url, "reddit.com") === FALSE && version_compare(PHP_VERSION, '5.6.0', '>=')) { |
|
| 545 | + if ($url && strpos($url, "reddit.com") === false && version_compare(PHP_VERSION, '5.6.0', '>=')) { |
|
| 546 | 546 | |
| 547 | 547 | /* link may lead to a huge video file or whatever, we need to check content type before trying to |
| 548 | 548 | parse it which p much requires curl */ |
@@ -550,7 +550,7 @@ discard block |
||
| 550 | 550 | $useragent_compat = "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)"; |
| 551 | 551 | $content_type = $this->get_content_type($url, $useragent_compat); |
| 552 | 552 | |
| 553 | - if ($content_type && strpos($content_type, "text/html") !== FALSE) { |
|
| 553 | + if ($content_type && strpos($content_type, "text/html") !== false) { |
|
| 554 | 554 | |
| 555 | 555 | foreach ($this->host->get_hooks(PluginHost::HOOK_GET_FULL_TEXT) as $p) { |
| 556 | 556 | $extracted_content = $p->hook_get_full_text($url); |
@@ -1,42 +1,42 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | class Af_RedditImgur extends Plugin { |
| 3 | 3 | |
| 4 | - /* @var PluginHost $host */ |
|
| 5 | - private $host; |
|
| 4 | + /* @var PluginHost $host */ |
|
| 5 | + private $host; |
|
| 6 | 6 | |
| 7 | - public function about() { |
|
| 8 | - return array(1.0, |
|
| 9 | - "Inline images (and other content) in Reddit RSS feeds", |
|
| 10 | - "fox"); |
|
| 11 | - } |
|
| 7 | + public function about() { |
|
| 8 | + return array(1.0, |
|
| 9 | + "Inline images (and other content) in Reddit RSS feeds", |
|
| 10 | + "fox"); |
|
| 11 | + } |
|
| 12 | 12 | |
| 13 | - public function flags() { |
|
| 14 | - return array("needs_curl" => true); |
|
| 15 | - } |
|
| 13 | + public function flags() { |
|
| 14 | + return array("needs_curl" => true); |
|
| 15 | + } |
|
| 16 | 16 | |
| 17 | - public function init($host) { |
|
| 18 | - $this->host = $host; |
|
| 17 | + public function init($host) { |
|
| 18 | + $this->host = $host; |
|
| 19 | 19 | |
| 20 | - $host->add_hook($host::HOOK_ARTICLE_FILTER, $this); |
|
| 21 | - $host->add_hook($host::HOOK_PREFS_TAB, $this); |
|
| 22 | - } |
|
| 20 | + $host->add_hook($host::HOOK_ARTICLE_FILTER, $this); |
|
| 21 | + $host->add_hook($host::HOOK_PREFS_TAB, $this); |
|
| 22 | + } |
|
| 23 | 23 | |
| 24 | - public function hook_prefs_tab($args) { |
|
| 25 | - if ($args != "prefFeeds") return; |
|
| 24 | + public function hook_prefs_tab($args) { |
|
| 25 | + if ($args != "prefFeeds") return; |
|
| 26 | 26 | |
| 27 | - print "<div dojoType=\"dijit.layout.AccordionPane\" |
|
| 27 | + print "<div dojoType=\"dijit.layout.AccordionPane\" |
|
| 28 | 28 | title=\"<i class='material-icons'>extension</i> ".__('Reddit content settings (af_redditimgur)')."\">"; |
| 29 | 29 | |
| 30 | - $enable_readability = $this->host->get($this, "enable_readability"); |
|
| 31 | - $enable_content_dupcheck = $this->host->get($this, "enable_content_dupcheck"); |
|
| 30 | + $enable_readability = $this->host->get($this, "enable_readability"); |
|
| 31 | + $enable_content_dupcheck = $this->host->get($this, "enable_content_dupcheck"); |
|
| 32 | 32 | |
| 33 | - if (version_compare(PHP_VERSION, '5.6.0', '<')) { |
|
| 34 | - print_error("Readability requires PHP version 5.6."); |
|
| 35 | - } |
|
| 33 | + if (version_compare(PHP_VERSION, '5.6.0', '<')) { |
|
| 34 | + print_error("Readability requires PHP version 5.6."); |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - print "<form dojoType='dijit.form.Form'>"; |
|
| 37 | + print "<form dojoType='dijit.form.Form'>"; |
|
| 38 | 38 | |
| 39 | - print "<script type='dojo/method' event='onSubmit' args='evt'> |
|
| 39 | + print "<script type='dojo/method' event='onSubmit' args='evt'> |
|
| 40 | 40 | evt.preventDefault(); |
| 41 | 41 | if (this.validate()) { |
| 42 | 42 | console.log(dojo.objectToQuery(this.getValues())); |
@@ -50,235 +50,235 @@ discard block |
||
| 50 | 50 | } |
| 51 | 51 | </script>"; |
| 52 | 52 | |
| 53 | - print_hidden("op", "pluginhandler"); |
|
| 54 | - print_hidden("method", "save"); |
|
| 55 | - print_hidden("plugin", "af_redditimgur"); |
|
| 53 | + print_hidden("op", "pluginhandler"); |
|
| 54 | + print_hidden("method", "save"); |
|
| 55 | + print_hidden("plugin", "af_redditimgur"); |
|
| 56 | 56 | |
| 57 | - print "<fieldset class='narrow'>"; |
|
| 58 | - print "<label class='checkbox'>"; |
|
| 59 | - print_checkbox("enable_readability", $enable_readability); |
|
| 60 | - print " " . __("Extract missing content using Readability (requires af_readability)") . "</label>"; |
|
| 61 | - print "</fieldset>"; |
|
| 57 | + print "<fieldset class='narrow'>"; |
|
| 58 | + print "<label class='checkbox'>"; |
|
| 59 | + print_checkbox("enable_readability", $enable_readability); |
|
| 60 | + print " " . __("Extract missing content using Readability (requires af_readability)") . "</label>"; |
|
| 61 | + print "</fieldset>"; |
|
| 62 | 62 | |
| 63 | - print "<fieldset class='narrow'>"; |
|
| 64 | - print "<label class='checkbox'>"; |
|
| 65 | - print_checkbox("enable_content_dupcheck", $enable_content_dupcheck); |
|
| 66 | - print " " . __("Enable additional duplicate checking") . "</label>"; |
|
| 67 | - print "</fieldset>"; |
|
| 63 | + print "<fieldset class='narrow'>"; |
|
| 64 | + print "<label class='checkbox'>"; |
|
| 65 | + print_checkbox("enable_content_dupcheck", $enable_content_dupcheck); |
|
| 66 | + print " " . __("Enable additional duplicate checking") . "</label>"; |
|
| 67 | + print "</fieldset>"; |
|
| 68 | 68 | |
| 69 | - print_button("submit", __("Save"), 'class="alt-primary"'); |
|
| 70 | - print "</form>"; |
|
| 69 | + print_button("submit", __("Save"), 'class="alt-primary"'); |
|
| 70 | + print "</form>"; |
|
| 71 | 71 | |
| 72 | - print "</div>"; |
|
| 73 | - } |
|
| 72 | + print "</div>"; |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | - public function save() { |
|
| 76 | - $enable_readability = checkbox_to_sql_bool($_POST["enable_readability"]); |
|
| 77 | - $enable_content_dupcheck = checkbox_to_sql_bool($_POST["enable_content_dupcheck"]); |
|
| 75 | + public function save() { |
|
| 76 | + $enable_readability = checkbox_to_sql_bool($_POST["enable_readability"]); |
|
| 77 | + $enable_content_dupcheck = checkbox_to_sql_bool($_POST["enable_content_dupcheck"]); |
|
| 78 | 78 | |
| 79 | - $this->host->set($this, "enable_readability", $enable_readability, false); |
|
| 80 | - $this->host->set($this, "enable_content_dupcheck", $enable_content_dupcheck); |
|
| 79 | + $this->host->set($this, "enable_readability", $enable_readability, false); |
|
| 80 | + $this->host->set($this, "enable_content_dupcheck", $enable_content_dupcheck); |
|
| 81 | 81 | |
| 82 | - echo __("Configuration saved"); |
|
| 83 | - } |
|
| 82 | + echo __("Configuration saved"); |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | - /** |
|
| 86 | - * @SuppressWarnings(PHPMD.UnusedFormalParameter) |
|
| 87 | - */ |
|
| 88 | - private function inline_stuff($article, &$doc, $xpath) { |
|
| 85 | + /** |
|
| 86 | + * @SuppressWarnings(PHPMD.UnusedFormalParameter) |
|
| 87 | + */ |
|
| 88 | + private function inline_stuff($article, &$doc, $xpath) { |
|
| 89 | 89 | |
| 90 | - $entries = $xpath->query('(//a[@href]|//img[@src])'); |
|
| 91 | - $img_entries = $xpath->query("(//img[@src])"); |
|
| 90 | + $entries = $xpath->query('(//a[@href]|//img[@src])'); |
|
| 91 | + $img_entries = $xpath->query("(//img[@src])"); |
|
| 92 | 92 | |
| 93 | - $found = false; |
|
| 94 | - //$debug = 1; |
|
| 93 | + $found = false; |
|
| 94 | + //$debug = 1; |
|
| 95 | 95 | |
| 96 | - foreach ($entries as $entry) { |
|
| 97 | - if ($entry->hasAttribute("href") && strpos($entry->getAttribute("href"), "reddit.com") === FALSE) { |
|
| 96 | + foreach ($entries as $entry) { |
|
| 97 | + if ($entry->hasAttribute("href") && strpos($entry->getAttribute("href"), "reddit.com") === FALSE) { |
|
| 98 | 98 | |
| 99 | - Debug::log("processing href: " . $entry->getAttribute("href"), Debug::$LOG_VERBOSE); |
|
| 99 | + Debug::log("processing href: " . $entry->getAttribute("href"), Debug::$LOG_VERBOSE); |
|
| 100 | 100 | |
| 101 | - $matches = array(); |
|
| 101 | + $matches = array(); |
|
| 102 | 102 | |
| 103 | - if (!$found && preg_match("/^https?:\/\/twitter.com\/(.*?)\/status\/(.*)/", $entry->getAttribute("href"), $matches)) { |
|
| 104 | - Debug::log("handling as twitter: " . $matches[1] . " " . $matches[2], Debug::$LOG_VERBOSE); |
|
| 103 | + if (!$found && preg_match("/^https?:\/\/twitter.com\/(.*?)\/status\/(.*)/", $entry->getAttribute("href"), $matches)) { |
|
| 104 | + Debug::log("handling as twitter: " . $matches[1] . " " . $matches[2], Debug::$LOG_VERBOSE); |
|
| 105 | 105 | |
| 106 | - $oembed_result = fetch_file_contents("https://publish.twitter.com/oembed?url=" . urlencode($entry->getAttribute("href"))); |
|
| 106 | + $oembed_result = fetch_file_contents("https://publish.twitter.com/oembed?url=" . urlencode($entry->getAttribute("href"))); |
|
| 107 | 107 | |
| 108 | - if ($oembed_result) { |
|
| 109 | - $oembed_result = json_decode($oembed_result, true); |
|
| 108 | + if ($oembed_result) { |
|
| 109 | + $oembed_result = json_decode($oembed_result, true); |
|
| 110 | 110 | |
| 111 | - if ($oembed_result && isset($oembed_result["html"])) { |
|
| 111 | + if ($oembed_result && isset($oembed_result["html"])) { |
|
| 112 | 112 | |
| 113 | - $tmp = new DOMDocument(); |
|
| 114 | - if ($tmp->loadHTML('<?xml encoding="utf-8" ?>' . $oembed_result["html"])) { |
|
| 115 | - $p = $doc->createElement("p"); |
|
| 113 | + $tmp = new DOMDocument(); |
|
| 114 | + if ($tmp->loadHTML('<?xml encoding="utf-8" ?>' . $oembed_result["html"])) { |
|
| 115 | + $p = $doc->createElement("p"); |
|
| 116 | 116 | |
| 117 | - $p->appendChild($doc->importNode( |
|
| 118 | - $tmp->getElementsByTagName("blockquote")->item(0), TRUE)); |
|
| 117 | + $p->appendChild($doc->importNode( |
|
| 118 | + $tmp->getElementsByTagName("blockquote")->item(0), TRUE)); |
|
| 119 | 119 | |
| 120 | - $br = $doc->createElement('br'); |
|
| 121 | - $entry->parentNode->insertBefore($p, $entry); |
|
| 122 | - $entry->parentNode->insertBefore($br, $entry); |
|
| 120 | + $br = $doc->createElement('br'); |
|
| 121 | + $entry->parentNode->insertBefore($p, $entry); |
|
| 122 | + $entry->parentNode->insertBefore($br, $entry); |
|
| 123 | 123 | |
| 124 | - $found = 1; |
|
| 125 | - } |
|
| 126 | - } |
|
| 127 | - } |
|
| 128 | - } |
|
| 124 | + $found = 1; |
|
| 125 | + } |
|
| 126 | + } |
|
| 127 | + } |
|
| 128 | + } |
|
| 129 | 129 | |
| 130 | - if (!$found && preg_match("/\.gfycat.com\/([a-z]+)?(\.[a-z]+)$/i", $entry->getAttribute("href"), $matches)) { |
|
| 131 | - $entry->setAttribute("href", "http://www.gfycat.com/".$matches[1]); |
|
| 132 | - } |
|
| 130 | + if (!$found && preg_match("/\.gfycat.com\/([a-z]+)?(\.[a-z]+)$/i", $entry->getAttribute("href"), $matches)) { |
|
| 131 | + $entry->setAttribute("href", "http://www.gfycat.com/".$matches[1]); |
|
| 132 | + } |
|
| 133 | 133 | |
| 134 | - if (!$found && preg_match("/https?:\/\/(www\.)?gfycat.com\/([a-z]+)$/i", $entry->getAttribute("href"), $matches)) { |
|
| 134 | + if (!$found && preg_match("/https?:\/\/(www\.)?gfycat.com\/([a-z]+)$/i", $entry->getAttribute("href"), $matches)) { |
|
| 135 | 135 | |
| 136 | - Debug::log("Handling as Gfycat", Debug::$LOG_VERBOSE); |
|
| 136 | + Debug::log("Handling as Gfycat", Debug::$LOG_VERBOSE); |
|
| 137 | 137 | |
| 138 | - $source_stream = 'https://giant.gfycat.com/' . $matches[2] . '.mp4'; |
|
| 139 | - $poster_url = 'https://thumbs.gfycat.com/' . $matches[2] . '-mobile.jpg'; |
|
| 138 | + $source_stream = 'https://giant.gfycat.com/' . $matches[2] . '.mp4'; |
|
| 139 | + $poster_url = 'https://thumbs.gfycat.com/' . $matches[2] . '-mobile.jpg'; |
|
| 140 | 140 | |
| 141 | - $content_type = $this->get_content_type($source_stream); |
|
| 141 | + $content_type = $this->get_content_type($source_stream); |
|
| 142 | 142 | |
| 143 | - if (strpos($content_type, "video/") !== FALSE) { |
|
| 144 | - $this->handle_as_video($doc, $entry, $source_stream, $poster_url); |
|
| 145 | - $found = 1; |
|
| 146 | - } |
|
| 147 | - } |
|
| 143 | + if (strpos($content_type, "video/") !== FALSE) { |
|
| 144 | + $this->handle_as_video($doc, $entry, $source_stream, $poster_url); |
|
| 145 | + $found = 1; |
|
| 146 | + } |
|
| 147 | + } |
|
| 148 | 148 | |
| 149 | - if (!$found && preg_match("/https?:\/\/v\.redd\.it\/(.*)$/i", $entry->getAttribute("href"), $matches)) { |
|
| 149 | + if (!$found && preg_match("/https?:\/\/v\.redd\.it\/(.*)$/i", $entry->getAttribute("href"), $matches)) { |
|
| 150 | 150 | |
| 151 | - Debug::log("Handling as reddit inline video", Debug::$LOG_VERBOSE); |
|
| 151 | + Debug::log("Handling as reddit inline video", Debug::$LOG_VERBOSE); |
|
| 152 | 152 | |
| 153 | - $img = $img_entries->item(0); |
|
| 153 | + $img = $img_entries->item(0); |
|
| 154 | 154 | |
| 155 | - if ($img) { |
|
| 156 | - $poster_url = $img->getAttribute("src"); |
|
| 157 | - } else { |
|
| 158 | - $poster_url = false; |
|
| 159 | - } |
|
| 155 | + if ($img) { |
|
| 156 | + $poster_url = $img->getAttribute("src"); |
|
| 157 | + } else { |
|
| 158 | + $poster_url = false; |
|
| 159 | + } |
|
| 160 | 160 | |
| 161 | - // Get original article URL from v.redd.it redirects |
|
| 162 | - $source_article_url = $this->get_location($matches[0]); |
|
| 163 | - Debug::log("Resolved ".$matches[0]." to ".$source_article_url, Debug::$LOG_VERBOSE); |
|
| 164 | - |
|
| 165 | - $source_stream = false; |
|
| 166 | - |
|
| 167 | - if ($source_article_url) { |
|
| 168 | - $j = json_decode(fetch_file_contents($source_article_url.".json"), true); |
|
| 169 | - |
|
| 170 | - if ($j) { |
|
| 171 | - foreach ($j as $listing) { |
|
| 172 | - foreach ($listing["data"]["children"] as $child) { |
|
| 173 | - if ($child["data"]["url"] == $matches[0]) { |
|
| 174 | - try { |
|
| 175 | - $source_stream = $child["data"]["media"]["reddit_video"]["fallback_url"]; |
|
| 176 | - } |
|
| 177 | - catch (Exception $e) { |
|
| 178 | - } |
|
| 179 | - break 2; |
|
| 180 | - } |
|
| 181 | - } |
|
| 182 | - } |
|
| 183 | - } |
|
| 184 | - } |
|
| 161 | + // Get original article URL from v.redd.it redirects |
|
| 162 | + $source_article_url = $this->get_location($matches[0]); |
|
| 163 | + Debug::log("Resolved ".$matches[0]." to ".$source_article_url, Debug::$LOG_VERBOSE); |
|
| 164 | + |
|
| 165 | + $source_stream = false; |
|
| 166 | + |
|
| 167 | + if ($source_article_url) { |
|
| 168 | + $j = json_decode(fetch_file_contents($source_article_url.".json"), true); |
|
| 169 | + |
|
| 170 | + if ($j) { |
|
| 171 | + foreach ($j as $listing) { |
|
| 172 | + foreach ($listing["data"]["children"] as $child) { |
|
| 173 | + if ($child["data"]["url"] == $matches[0]) { |
|
| 174 | + try { |
|
| 175 | + $source_stream = $child["data"]["media"]["reddit_video"]["fallback_url"]; |
|
| 176 | + } |
|
| 177 | + catch (Exception $e) { |
|
| 178 | + } |
|
| 179 | + break 2; |
|
| 180 | + } |
|
| 181 | + } |
|
| 182 | + } |
|
| 183 | + } |
|
| 184 | + } |
|
| 185 | 185 | |
| 186 | - if (!$source_stream) { |
|
| 187 | - $source_stream = "https://v.redd.it/" . $matches[1] . "/DASH_600_K"; |
|
| 188 | - } |
|
| 186 | + if (!$source_stream) { |
|
| 187 | + $source_stream = "https://v.redd.it/" . $matches[1] . "/DASH_600_K"; |
|
| 188 | + } |
|
| 189 | 189 | |
| 190 | - $this->handle_as_video($doc, $entry, $source_stream, $poster_url); |
|
| 191 | - $found = 1; |
|
| 192 | - } |
|
| 190 | + $this->handle_as_video($doc, $entry, $source_stream, $poster_url); |
|
| 191 | + $found = 1; |
|
| 192 | + } |
|
| 193 | 193 | |
| 194 | - if (!$found && preg_match("/https?:\/\/(www\.)?streamable.com\//i", $entry->getAttribute("href"))) { |
|
| 194 | + if (!$found && preg_match("/https?:\/\/(www\.)?streamable.com\//i", $entry->getAttribute("href"))) { |
|
| 195 | 195 | |
| 196 | - Debug::log("Handling as Streamable", Debug::$LOG_VERBOSE); |
|
| 196 | + Debug::log("Handling as Streamable", Debug::$LOG_VERBOSE); |
|
| 197 | 197 | |
| 198 | - $tmp = fetch_file_contents($entry->getAttribute("href")); |
|
| 198 | + $tmp = fetch_file_contents($entry->getAttribute("href")); |
|
| 199 | 199 | |
| 200 | - if ($tmp) { |
|
| 201 | - $tmpdoc = new DOMDocument(); |
|
| 200 | + if ($tmp) { |
|
| 201 | + $tmpdoc = new DOMDocument(); |
|
| 202 | 202 | |
| 203 | - if (@$tmpdoc->loadHTML($tmp)) { |
|
| 204 | - $tmpxpath = new DOMXPath($tmpdoc); |
|
| 203 | + if (@$tmpdoc->loadHTML($tmp)) { |
|
| 204 | + $tmpxpath = new DOMXPath($tmpdoc); |
|
| 205 | 205 | |
| 206 | - $source_node = $tmpxpath->query("//video[contains(@class,'video-player-tag')]//source[contains(@src, '.mp4')]")->item(0); |
|
| 207 | - $poster_node = $tmpxpath->query("//video[contains(@class,'video-player-tag') and @poster]")->item(0); |
|
| 206 | + $source_node = $tmpxpath->query("//video[contains(@class,'video-player-tag')]//source[contains(@src, '.mp4')]")->item(0); |
|
| 207 | + $poster_node = $tmpxpath->query("//video[contains(@class,'video-player-tag') and @poster]")->item(0); |
|
| 208 | 208 | |
| 209 | - if ($source_node && $poster_node) { |
|
| 210 | - $source_stream = $source_node->getAttribute("src"); |
|
| 211 | - $poster_url = $poster_node->getAttribute("poster"); |
|
| 209 | + if ($source_node && $poster_node) { |
|
| 210 | + $source_stream = $source_node->getAttribute("src"); |
|
| 211 | + $poster_url = $poster_node->getAttribute("poster"); |
|
| 212 | 212 | |
| 213 | - $this->handle_as_video($doc, $entry, $source_stream, $poster_url); |
|
| 214 | - $found = 1; |
|
| 215 | - } |
|
| 216 | - } |
|
| 217 | - } |
|
| 218 | - } |
|
| 213 | + $this->handle_as_video($doc, $entry, $source_stream, $poster_url); |
|
| 214 | + $found = 1; |
|
| 215 | + } |
|
| 216 | + } |
|
| 217 | + } |
|
| 218 | + } |
|
| 219 | 219 | |
| 220 | - // imgur .gif -> .gifv |
|
| 221 | - if (!$found && preg_match("/i\.imgur\.com\/(.*?)\.gif$/i", $entry->getAttribute("href"))) { |
|
| 222 | - Debug::log("Handling as imgur gif (->gifv)", Debug::$LOG_VERBOSE); |
|
| 220 | + // imgur .gif -> .gifv |
|
| 221 | + if (!$found && preg_match("/i\.imgur\.com\/(.*?)\.gif$/i", $entry->getAttribute("href"))) { |
|
| 222 | + Debug::log("Handling as imgur gif (->gifv)", Debug::$LOG_VERBOSE); |
|
| 223 | 223 | |
| 224 | - $entry->setAttribute("href", |
|
| 225 | - str_replace(".gif", ".gifv", $entry->getAttribute("href"))); |
|
| 226 | - } |
|
| 224 | + $entry->setAttribute("href", |
|
| 225 | + str_replace(".gif", ".gifv", $entry->getAttribute("href"))); |
|
| 226 | + } |
|
| 227 | 227 | |
| 228 | - if (!$found && preg_match("/\.(gifv|mp4)$/i", $entry->getAttribute("href"))) { |
|
| 229 | - Debug::log("Handling as imgur gifv", Debug::$LOG_VERBOSE); |
|
| 228 | + if (!$found && preg_match("/\.(gifv|mp4)$/i", $entry->getAttribute("href"))) { |
|
| 229 | + Debug::log("Handling as imgur gifv", Debug::$LOG_VERBOSE); |
|
| 230 | 230 | |
| 231 | - $source_stream = str_replace(".gifv", ".mp4", $entry->getAttribute("href")); |
|
| 231 | + $source_stream = str_replace(".gifv", ".mp4", $entry->getAttribute("href")); |
|
| 232 | 232 | |
| 233 | - if (strpos($source_stream, "imgur.com") !== FALSE) |
|
| 234 | - $poster_url = str_replace(".mp4", "h.jpg", $source_stream); |
|
| 233 | + if (strpos($source_stream, "imgur.com") !== FALSE) |
|
| 234 | + $poster_url = str_replace(".mp4", "h.jpg", $source_stream); |
|
| 235 | 235 | |
| 236 | - $this->handle_as_video($doc, $entry, $source_stream, $poster_url); |
|
| 236 | + $this->handle_as_video($doc, $entry, $source_stream, $poster_url); |
|
| 237 | 237 | |
| 238 | - $found = true; |
|
| 239 | - } |
|
| 238 | + $found = true; |
|
| 239 | + } |
|
| 240 | 240 | |
| 241 | - $matches = array(); |
|
| 242 | - if (!$found && preg_match("/youtube\.com\/v\/([\w-]+)/", $entry->getAttribute("href"), $matches) || |
|
| 243 | - preg_match("/youtube\.com\/.*?[\&\?]v=([\w-]+)/", $entry->getAttribute("href"), $matches) || |
|
| 244 | - preg_match("/youtube\.com\/watch\?v=([\w-]+)/", $entry->getAttribute("href"), $matches) || |
|
| 245 | - preg_match("/\/\/youtu.be\/([\w-]+)/", $entry->getAttribute("href"), $matches)) { |
|
| 241 | + $matches = array(); |
|
| 242 | + if (!$found && preg_match("/youtube\.com\/v\/([\w-]+)/", $entry->getAttribute("href"), $matches) || |
|
| 243 | + preg_match("/youtube\.com\/.*?[\&\?]v=([\w-]+)/", $entry->getAttribute("href"), $matches) || |
|
| 244 | + preg_match("/youtube\.com\/watch\?v=([\w-]+)/", $entry->getAttribute("href"), $matches) || |
|
| 245 | + preg_match("/\/\/youtu.be\/([\w-]+)/", $entry->getAttribute("href"), $matches)) { |
|
| 246 | 246 | |
| 247 | - $vid_id = $matches[1]; |
|
| 247 | + $vid_id = $matches[1]; |
|
| 248 | 248 | |
| 249 | - Debug::log("Handling as youtube: $vid_id", Debug::$LOG_VERBOSE); |
|
| 249 | + Debug::log("Handling as youtube: $vid_id", Debug::$LOG_VERBOSE); |
|
| 250 | 250 | |
| 251 | - $iframe = $doc->createElement("iframe"); |
|
| 252 | - $iframe->setAttribute("class", "youtube-player"); |
|
| 253 | - $iframe->setAttribute("type", "text/html"); |
|
| 254 | - $iframe->setAttribute("width", "640"); |
|
| 255 | - $iframe->setAttribute("height", "385"); |
|
| 256 | - $iframe->setAttribute("src", "https://www.youtube.com/embed/$vid_id"); |
|
| 257 | - $iframe->setAttribute("allowfullscreen", "1"); |
|
| 258 | - $iframe->setAttribute("frameborder", "0"); |
|
| 251 | + $iframe = $doc->createElement("iframe"); |
|
| 252 | + $iframe->setAttribute("class", "youtube-player"); |
|
| 253 | + $iframe->setAttribute("type", "text/html"); |
|
| 254 | + $iframe->setAttribute("width", "640"); |
|
| 255 | + $iframe->setAttribute("height", "385"); |
|
| 256 | + $iframe->setAttribute("src", "https://www.youtube.com/embed/$vid_id"); |
|
| 257 | + $iframe->setAttribute("allowfullscreen", "1"); |
|
| 258 | + $iframe->setAttribute("frameborder", "0"); |
|
| 259 | 259 | |
| 260 | - $br = $doc->createElement('br'); |
|
| 261 | - $entry->parentNode->insertBefore($iframe, $entry); |
|
| 262 | - $entry->parentNode->insertBefore($br, $entry); |
|
| 260 | + $br = $doc->createElement('br'); |
|
| 261 | + $entry->parentNode->insertBefore($iframe, $entry); |
|
| 262 | + $entry->parentNode->insertBefore($br, $entry); |
|
| 263 | 263 | |
| 264 | - $found = true; |
|
| 265 | - } |
|
| 264 | + $found = true; |
|
| 265 | + } |
|
| 266 | 266 | |
| 267 | - if (!$found && preg_match("/\.(jpg|jpeg|gif|png)(\?[0-9][0-9]*)?$/i", $entry->getAttribute("href")) || |
|
| 268 | - mb_strpos($entry->getAttribute("href"), "i.reddituploads.com") !== FALSE || |
|
| 269 | - mb_strpos($this->get_content_type($entry->getAttribute("href")), "image/") !== FALSE) { |
|
| 267 | + if (!$found && preg_match("/\.(jpg|jpeg|gif|png)(\?[0-9][0-9]*)?$/i", $entry->getAttribute("href")) || |
|
| 268 | + mb_strpos($entry->getAttribute("href"), "i.reddituploads.com") !== FALSE || |
|
| 269 | + mb_strpos($this->get_content_type($entry->getAttribute("href")), "image/") !== FALSE) { |
|
| 270 | 270 | |
| 271 | - Debug::log("Handling as a picture", Debug::$LOG_VERBOSE); |
|
| 271 | + Debug::log("Handling as a picture", Debug::$LOG_VERBOSE); |
|
| 272 | 272 | |
| 273 | - $img = $doc->createElement('img'); |
|
| 274 | - $img->setAttribute("src", $entry->getAttribute("href")); |
|
| 273 | + $img = $doc->createElement('img'); |
|
| 274 | + $img->setAttribute("src", $entry->getAttribute("href")); |
|
| 275 | 275 | |
| 276 | - $br = $doc->createElement('br'); |
|
| 277 | - $entry->parentNode->insertBefore($img, $entry); |
|
| 278 | - $entry->parentNode->insertBefore($br, $entry); |
|
| 276 | + $br = $doc->createElement('br'); |
|
| 277 | + $entry->parentNode->insertBefore($img, $entry); |
|
| 278 | + $entry->parentNode->insertBefore($br, $entry); |
|
| 279 | 279 | |
| 280 | - $found = true; |
|
| 281 | - } |
|
| 280 | + $found = true; |
|
| 281 | + } |
|
| 282 | 282 | |
| 283 | 283 | // imgur via link rel="image_src" href="..." |
| 284 | 284 | if (!$found && preg_match("/imgur/", $entry->getAttribute("href"))) { |
@@ -311,109 +311,109 @@ discard block |
||
| 311 | 311 | } |
| 312 | 312 | } |
| 313 | 313 | |
| 314 | - // wtf is this even |
|
| 315 | - if (!$found && preg_match("/^https?:\/\/gyazo\.com\/([^\.\/]+$)/", $entry->getAttribute("href"), $matches)) { |
|
| 316 | - $img_id = $matches[1]; |
|
| 314 | + // wtf is this even |
|
| 315 | + if (!$found && preg_match("/^https?:\/\/gyazo\.com\/([^\.\/]+$)/", $entry->getAttribute("href"), $matches)) { |
|
| 316 | + $img_id = $matches[1]; |
|
| 317 | 317 | |
| 318 | - Debug::log("handling as gyazo: $img_id", Debug::$LOG_VERBOSE); |
|
| 318 | + Debug::log("handling as gyazo: $img_id", Debug::$LOG_VERBOSE); |
|
| 319 | 319 | |
| 320 | - $img = $doc->createElement('img'); |
|
| 321 | - $img->setAttribute("src", "https://i.gyazo.com/$img_id.jpg"); |
|
| 320 | + $img = $doc->createElement('img'); |
|
| 321 | + $img->setAttribute("src", "https://i.gyazo.com/$img_id.jpg"); |
|
| 322 | 322 | |
| 323 | - $br = $doc->createElement('br'); |
|
| 324 | - $entry->parentNode->insertBefore($img, $entry); |
|
| 325 | - $entry->parentNode->insertBefore($br, $entry); |
|
| 323 | + $br = $doc->createElement('br'); |
|
| 324 | + $entry->parentNode->insertBefore($img, $entry); |
|
| 325 | + $entry->parentNode->insertBefore($br, $entry); |
|
| 326 | 326 | |
| 327 | - $found = true; |
|
| 328 | - } |
|
| 327 | + $found = true; |
|
| 328 | + } |
|
| 329 | 329 | |
| 330 | - // let's try meta properties |
|
| 331 | - if (!$found) { |
|
| 332 | - Debug::log("looking for meta og:image", Debug::$LOG_VERBOSE); |
|
| 330 | + // let's try meta properties |
|
| 331 | + if (!$found) { |
|
| 332 | + Debug::log("looking for meta og:image", Debug::$LOG_VERBOSE); |
|
| 333 | 333 | |
| 334 | - $content = fetch_file_contents(["url" => $entry->getAttribute("href"), |
|
| 335 | - "http_accept" => "text/*"]); |
|
| 334 | + $content = fetch_file_contents(["url" => $entry->getAttribute("href"), |
|
| 335 | + "http_accept" => "text/*"]); |
|
| 336 | 336 | |
| 337 | - if ($content) { |
|
| 338 | - $cdoc = new DOMDocument(); |
|
| 337 | + if ($content) { |
|
| 338 | + $cdoc = new DOMDocument(); |
|
| 339 | 339 | |
| 340 | - if (@$cdoc->loadHTML($content)) { |
|
| 341 | - $cxpath = new DOMXPath($cdoc); |
|
| 340 | + if (@$cdoc->loadHTML($content)) { |
|
| 341 | + $cxpath = new DOMXPath($cdoc); |
|
| 342 | 342 | |
| 343 | - $og_image = $cxpath->query("//meta[@property='og:image']")->item(0); |
|
| 344 | - $og_video = $cxpath->query("//meta[@property='og:video']")->item(0); |
|
| 343 | + $og_image = $cxpath->query("//meta[@property='og:image']")->item(0); |
|
| 344 | + $og_video = $cxpath->query("//meta[@property='og:video']")->item(0); |
|
| 345 | 345 | |
| 346 | - if ($og_video) { |
|
| 346 | + if ($og_video) { |
|
| 347 | 347 | |
| 348 | - $source_stream = $og_video->getAttribute("content"); |
|
| 348 | + $source_stream = $og_video->getAttribute("content"); |
|
| 349 | 349 | |
| 350 | - if ($source_stream) { |
|
| 350 | + if ($source_stream) { |
|
| 351 | 351 | |
| 352 | - if ($og_image) { |
|
| 353 | - $poster_url = $og_image->getAttribute("content"); |
|
| 354 | - } else { |
|
| 355 | - $poster_url = false; |
|
| 356 | - } |
|
| 352 | + if ($og_image) { |
|
| 353 | + $poster_url = $og_image->getAttribute("content"); |
|
| 354 | + } else { |
|
| 355 | + $poster_url = false; |
|
| 356 | + } |
|
| 357 | 357 | |
| 358 | - $this->handle_as_video($doc, $entry, $source_stream, $poster_url); |
|
| 359 | - $found = true; |
|
| 360 | - } |
|
| 358 | + $this->handle_as_video($doc, $entry, $source_stream, $poster_url); |
|
| 359 | + $found = true; |
|
| 360 | + } |
|
| 361 | 361 | |
| 362 | - } else if ($og_image) { |
|
| 362 | + } else if ($og_image) { |
|
| 363 | 363 | |
| 364 | - $og_src = $og_image->getAttribute("content"); |
|
| 364 | + $og_src = $og_image->getAttribute("content"); |
|
| 365 | 365 | |
| 366 | - if ($og_src) { |
|
| 367 | - $img = $doc->createElement('img'); |
|
| 368 | - $img->setAttribute("src", $og_src); |
|
| 366 | + if ($og_src) { |
|
| 367 | + $img = $doc->createElement('img'); |
|
| 368 | + $img->setAttribute("src", $og_src); |
|
| 369 | 369 | |
| 370 | - $br = $doc->createElement('br'); |
|
| 371 | - $entry->parentNode->insertBefore($img, $entry); |
|
| 372 | - $entry->parentNode->insertBefore($br, $entry); |
|
| 370 | + $br = $doc->createElement('br'); |
|
| 371 | + $entry->parentNode->insertBefore($img, $entry); |
|
| 372 | + $entry->parentNode->insertBefore($br, $entry); |
|
| 373 | 373 | |
| 374 | - $found = true; |
|
| 375 | - } |
|
| 376 | - } |
|
| 377 | - } |
|
| 378 | - } |
|
| 379 | - } |
|
| 374 | + $found = true; |
|
| 375 | + } |
|
| 376 | + } |
|
| 377 | + } |
|
| 378 | + } |
|
| 379 | + } |
|
| 380 | 380 | |
| 381 | - } |
|
| 381 | + } |
|
| 382 | 382 | |
| 383 | - // remove tiny thumbnails |
|
| 384 | - if ($entry->hasAttribute("src")) { |
|
| 385 | - if ($entry->parentNode && $entry->parentNode->parentNode) { |
|
| 386 | - $entry->parentNode->parentNode->removeChild($entry->parentNode); |
|
| 387 | - } |
|
| 388 | - } |
|
| 389 | - } |
|
| 383 | + // remove tiny thumbnails |
|
| 384 | + if ($entry->hasAttribute("src")) { |
|
| 385 | + if ($entry->parentNode && $entry->parentNode->parentNode) { |
|
| 386 | + $entry->parentNode->parentNode->removeChild($entry->parentNode); |
|
| 387 | + } |
|
| 388 | + } |
|
| 389 | + } |
|
| 390 | 390 | |
| 391 | - return $found; |
|
| 392 | - } |
|
| 391 | + return $found; |
|
| 392 | + } |
|
| 393 | 393 | |
| 394 | - public function hook_article_filter($article) { |
|
| 394 | + public function hook_article_filter($article) { |
|
| 395 | 395 | |
| 396 | - if (strpos($article["link"], "reddit.com/r/") !== FALSE) { |
|
| 397 | - $doc = new DOMDocument(); |
|
| 398 | - @$doc->loadHTML($article["content"]); |
|
| 399 | - $xpath = new DOMXPath($doc); |
|
| 396 | + if (strpos($article["link"], "reddit.com/r/") !== FALSE) { |
|
| 397 | + $doc = new DOMDocument(); |
|
| 398 | + @$doc->loadHTML($article["content"]); |
|
| 399 | + $xpath = new DOMXPath($doc); |
|
| 400 | 400 | |
| 401 | - $content_link = $xpath->query("(//a[contains(., '[link]')])")->item(0); |
|
| 401 | + $content_link = $xpath->query("(//a[contains(., '[link]')])")->item(0); |
|
| 402 | 402 | |
| 403 | - if ($this->host->get($this, "enable_content_dupcheck")) { |
|
| 403 | + if ($this->host->get($this, "enable_content_dupcheck")) { |
|
| 404 | 404 | |
| 405 | - if ($content_link) { |
|
| 406 | - $content_href = $content_link->getAttribute("href"); |
|
| 407 | - $entry_guid = $article["guid_hashed"]; |
|
| 408 | - $owner_uid = $article["owner_uid"]; |
|
| 405 | + if ($content_link) { |
|
| 406 | + $content_href = $content_link->getAttribute("href"); |
|
| 407 | + $entry_guid = $article["guid_hashed"]; |
|
| 408 | + $owner_uid = $article["owner_uid"]; |
|
| 409 | 409 | |
| 410 | - if (DB_TYPE == "pgsql") { |
|
| 411 | - $interval_qpart = "date_entered < NOW() - INTERVAL '1 day'"; |
|
| 412 | - } else { |
|
| 413 | - $interval_qpart = "date_entered < DATE_SUB(NOW(), INTERVAL 1 DAY)"; |
|
| 414 | - } |
|
| 410 | + if (DB_TYPE == "pgsql") { |
|
| 411 | + $interval_qpart = "date_entered < NOW() - INTERVAL '1 day'"; |
|
| 412 | + } else { |
|
| 413 | + $interval_qpart = "date_entered < DATE_SUB(NOW(), INTERVAL 1 DAY)"; |
|
| 414 | + } |
|
| 415 | 415 | |
| 416 | - $sth = $this->pdo->prepare("SELECT COUNT(id) AS cid |
|
| 416 | + $sth = $this->pdo->prepare("SELECT COUNT(id) AS cid |
|
| 417 | 417 | FROM ttrss_entries, ttrss_user_entries WHERE |
| 418 | 418 | ref_id = id AND |
| 419 | 419 | $interval_qpart AND |
@@ -421,149 +421,149 @@ discard block |
||
| 421 | 421 | owner_uid = ? AND |
| 422 | 422 | content LIKE ?"); |
| 423 | 423 | |
| 424 | - $sth->execute([$entry_guid, $owner_uid, "%href=\"$content_href\">[link]%"]); |
|
| 424 | + $sth->execute([$entry_guid, $owner_uid, "%href=\"$content_href\">[link]%"]); |
|
| 425 | 425 | |
| 426 | - if ($row = $sth->fetch()) { |
|
| 427 | - $num_found = $row['cid']; |
|
| 426 | + if ($row = $sth->fetch()) { |
|
| 427 | + $num_found = $row['cid']; |
|
| 428 | 428 | |
| 429 | - if ($num_found > 0) $article["force_catchup"] = true; |
|
| 430 | - } |
|
| 431 | - } |
|
| 432 | - } |
|
| 429 | + if ($num_found > 0) $article["force_catchup"] = true; |
|
| 430 | + } |
|
| 431 | + } |
|
| 432 | + } |
|
| 433 | 433 | |
| 434 | - $found = $this->inline_stuff($article, $doc, $xpath); |
|
| 434 | + $found = $this->inline_stuff($article, $doc, $xpath); |
|
| 435 | 435 | |
| 436 | - $node = $doc->getElementsByTagName('body')->item(0); |
|
| 436 | + $node = $doc->getElementsByTagName('body')->item(0); |
|
| 437 | 437 | |
| 438 | - if ($node && $found) { |
|
| 439 | - $article["content"] = $doc->saveHTML($node); |
|
| 440 | - } else if ($content_link) { |
|
| 441 | - $article = $this->readability($article, $content_link->getAttribute("href"), $doc, $xpath); |
|
| 442 | - } |
|
| 443 | - } |
|
| 438 | + if ($node && $found) { |
|
| 439 | + $article["content"] = $doc->saveHTML($node); |
|
| 440 | + } else if ($content_link) { |
|
| 441 | + $article = $this->readability($article, $content_link->getAttribute("href"), $doc, $xpath); |
|
| 442 | + } |
|
| 443 | + } |
|
| 444 | 444 | |
| 445 | - return $article; |
|
| 446 | - } |
|
| 445 | + return $article; |
|
| 446 | + } |
|
| 447 | 447 | |
| 448 | - public function api_version() { |
|
| 449 | - return 2; |
|
| 450 | - } |
|
| 448 | + public function api_version() { |
|
| 449 | + return 2; |
|
| 450 | + } |
|
| 451 | 451 | |
| 452 | - private function handle_as_video($doc, $entry, $source_stream, $poster_url = false) { |
|
| 452 | + private function handle_as_video($doc, $entry, $source_stream, $poster_url = false) { |
|
| 453 | 453 | |
| 454 | - Debug::log("handle_as_video: $source_stream", Debug::$LOG_VERBOSE); |
|
| 454 | + Debug::log("handle_as_video: $source_stream", Debug::$LOG_VERBOSE); |
|
| 455 | 455 | |
| 456 | - $video = $doc->createElement('video'); |
|
| 457 | - $video->setAttribute("autoplay", "1"); |
|
| 458 | - $video->setAttribute("controls", "1"); |
|
| 459 | - $video->setAttribute("loop", "1"); |
|
| 456 | + $video = $doc->createElement('video'); |
|
| 457 | + $video->setAttribute("autoplay", "1"); |
|
| 458 | + $video->setAttribute("controls", "1"); |
|
| 459 | + $video->setAttribute("loop", "1"); |
|
| 460 | 460 | |
| 461 | - if ($poster_url) $video->setAttribute("poster", $poster_url); |
|
| 461 | + if ($poster_url) $video->setAttribute("poster", $poster_url); |
|
| 462 | 462 | |
| 463 | - $source = $doc->createElement('source'); |
|
| 464 | - $source->setAttribute("src", $source_stream); |
|
| 465 | - $source->setAttribute("type", "video/mp4"); |
|
| 463 | + $source = $doc->createElement('source'); |
|
| 464 | + $source->setAttribute("src", $source_stream); |
|
| 465 | + $source->setAttribute("type", "video/mp4"); |
|
| 466 | 466 | |
| 467 | - $video->appendChild($source); |
|
| 467 | + $video->appendChild($source); |
|
| 468 | 468 | |
| 469 | - $br = $doc->createElement('br'); |
|
| 470 | - $entry->parentNode->insertBefore($video, $entry); |
|
| 471 | - $entry->parentNode->insertBefore($br, $entry); |
|
| 469 | + $br = $doc->createElement('br'); |
|
| 470 | + $entry->parentNode->insertBefore($video, $entry); |
|
| 471 | + $entry->parentNode->insertBefore($br, $entry); |
|
| 472 | 472 | |
| 473 | - $img = $doc->createElement('img'); |
|
| 474 | - $img->setAttribute("src", |
|
| 475 | - "data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs%3D"); |
|
| 473 | + $img = $doc->createElement('img'); |
|
| 474 | + $img->setAttribute("src", |
|
| 475 | + "data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs%3D"); |
|
| 476 | 476 | |
| 477 | - $entry->parentNode->insertBefore($img, $entry); |
|
| 478 | - } |
|
| 477 | + $entry->parentNode->insertBefore($img, $entry); |
|
| 478 | + } |
|
| 479 | 479 | |
| 480 | - public function testurl() { |
|
| 481 | - $url = htmlspecialchars($_REQUEST["url"]); |
|
| 480 | + public function testurl() { |
|
| 481 | + $url = htmlspecialchars($_REQUEST["url"]); |
|
| 482 | 482 | |
| 483 | - header("Content-type: text/plain"); |
|
| 483 | + header("Content-type: text/plain"); |
|
| 484 | 484 | |
| 485 | - print "URL: $url\n"; |
|
| 485 | + print "URL: $url\n"; |
|
| 486 | 486 | |
| 487 | - $doc = new DOMDocument(); |
|
| 488 | - @$doc->loadHTML("<html><body><a href=\"$url\">[link]</a></body>"); |
|
| 489 | - $xpath = new DOMXPath($doc); |
|
| 487 | + $doc = new DOMDocument(); |
|
| 488 | + @$doc->loadHTML("<html><body><a href=\"$url\">[link]</a></body>"); |
|
| 489 | + $xpath = new DOMXPath($doc); |
|
| 490 | 490 | |
| 491 | - $found = $this->inline_stuff([], $doc, $xpath); |
|
| 491 | + $found = $this->inline_stuff([], $doc, $xpath); |
|
| 492 | 492 | |
| 493 | - print "Inline result: $found\n"; |
|
| 493 | + print "Inline result: $found\n"; |
|
| 494 | 494 | |
| 495 | - if (!$found) { |
|
| 496 | - print "\nReadability result:\n"; |
|
| 495 | + if (!$found) { |
|
| 496 | + print "\nReadability result:\n"; |
|
| 497 | 497 | |
| 498 | - $article = $this->readability([], $url, $doc, $xpath); |
|
| 498 | + $article = $this->readability([], $url, $doc, $xpath); |
|
| 499 | 499 | |
| 500 | - print_r($article); |
|
| 501 | - } else { |
|
| 502 | - print "\nResulting HTML:\n"; |
|
| 500 | + print_r($article); |
|
| 501 | + } else { |
|
| 502 | + print "\nResulting HTML:\n"; |
|
| 503 | 503 | |
| 504 | - print $doc->saveHTML(); |
|
| 505 | - } |
|
| 506 | - } |
|
| 504 | + print $doc->saveHTML(); |
|
| 505 | + } |
|
| 506 | + } |
|
| 507 | 507 | |
| 508 | - private function get_header($url, $useragent = SELF_USER_AGENT, $header) { |
|
| 509 | - $ret = false; |
|
| 508 | + private function get_header($url, $useragent = SELF_USER_AGENT, $header) { |
|
| 509 | + $ret = false; |
|
| 510 | 510 | |
| 511 | - if (function_exists("curl_init") && !defined("NO_CURL")) { |
|
| 512 | - $ch = curl_init($url); |
|
| 513 | - curl_setopt($ch, CURLOPT_TIMEOUT, 5); |
|
| 514 | - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
|
| 515 | - curl_setopt($ch, CURLOPT_HEADER, true); |
|
| 516 | - curl_setopt($ch, CURLOPT_NOBODY, true); |
|
| 517 | - curl_setopt($ch, CURLOPT_FOLLOWLOCATION, !ini_get("open_basedir")); |
|
| 518 | - curl_setopt($ch, CURLOPT_USERAGENT, $useragent); |
|
| 511 | + if (function_exists("curl_init") && !defined("NO_CURL")) { |
|
| 512 | + $ch = curl_init($url); |
|
| 513 | + curl_setopt($ch, CURLOPT_TIMEOUT, 5); |
|
| 514 | + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
|
| 515 | + curl_setopt($ch, CURLOPT_HEADER, true); |
|
| 516 | + curl_setopt($ch, CURLOPT_NOBODY, true); |
|
| 517 | + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, !ini_get("open_basedir")); |
|
| 518 | + curl_setopt($ch, CURLOPT_USERAGENT, $useragent); |
|
| 519 | 519 | |
| 520 | - @curl_exec($ch); |
|
| 521 | - $ret = curl_getinfo($ch, $header); |
|
| 522 | - } |
|
| 520 | + @curl_exec($ch); |
|
| 521 | + $ret = curl_getinfo($ch, $header); |
|
| 522 | + } |
|
| 523 | 523 | |
| 524 | - return $ret; |
|
| 525 | - } |
|
| 524 | + return $ret; |
|
| 525 | + } |
|
| 526 | 526 | |
| 527 | - private function get_content_type($url, $useragent = SELF_USER_AGENT) { |
|
| 528 | - return $this->get_header($url, $useragent, CURLINFO_CONTENT_TYPE); |
|
| 529 | - } |
|
| 527 | + private function get_content_type($url, $useragent = SELF_USER_AGENT) { |
|
| 528 | + return $this->get_header($url, $useragent, CURLINFO_CONTENT_TYPE); |
|
| 529 | + } |
|
| 530 | 530 | |
| 531 | - private function get_location($url, $useragent = SELF_USER_AGENT) { |
|
| 532 | - return $this->get_header($url, $useragent, CURLINFO_EFFECTIVE_URL); |
|
| 533 | - } |
|
| 531 | + private function get_location($url, $useragent = SELF_USER_AGENT) { |
|
| 532 | + return $this->get_header($url, $useragent, CURLINFO_EFFECTIVE_URL); |
|
| 533 | + } |
|
| 534 | 534 | |
| 535 | - /** |
|
| 536 | - * @SuppressWarnings(PHPMD.UnusedFormalParameter) |
|
| 537 | - */ |
|
| 538 | - private function readability($article, $url, $doc, $xpath, $debug = false) { |
|
| 535 | + /** |
|
| 536 | + * @SuppressWarnings(PHPMD.UnusedFormalParameter) |
|
| 537 | + */ |
|
| 538 | + private function readability($article, $url, $doc, $xpath, $debug = false) { |
|
| 539 | 539 | |
| 540 | - if (!defined('NO_CURL') && function_exists("curl_init") && $this->host->get($this, "enable_readability") && |
|
| 541 | - mb_strlen(strip_tags($article["content"])) <= 150) { |
|
| 540 | + if (!defined('NO_CURL') && function_exists("curl_init") && $this->host->get($this, "enable_readability") && |
|
| 541 | + mb_strlen(strip_tags($article["content"])) <= 150) { |
|
| 542 | 542 | |
| 543 | - // do not try to embed posts linking back to other reddit posts |
|
| 544 | - // readability.php requires PHP 5.6 |
|
| 545 | - if ($url && strpos($url, "reddit.com") === FALSE && version_compare(PHP_VERSION, '5.6.0', '>=')) { |
|
| 543 | + // do not try to embed posts linking back to other reddit posts |
|
| 544 | + // readability.php requires PHP 5.6 |
|
| 545 | + if ($url && strpos($url, "reddit.com") === FALSE && version_compare(PHP_VERSION, '5.6.0', '>=')) { |
|
| 546 | 546 | |
| 547 | - /* link may lead to a huge video file or whatever, we need to check content type before trying to |
|
| 547 | + /* link may lead to a huge video file or whatever, we need to check content type before trying to |
|
| 548 | 548 | parse it which p much requires curl */ |
| 549 | 549 | |
| 550 | - $useragent_compat = "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)"; |
|
| 551 | - $content_type = $this->get_content_type($url, $useragent_compat); |
|
| 550 | + $useragent_compat = "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)"; |
|
| 551 | + $content_type = $this->get_content_type($url, $useragent_compat); |
|
| 552 | 552 | |
| 553 | - if ($content_type && strpos($content_type, "text/html") !== FALSE) { |
|
| 553 | + if ($content_type && strpos($content_type, "text/html") !== FALSE) { |
|
| 554 | 554 | |
| 555 | - foreach ($this->host->get_hooks(PluginHost::HOOK_GET_FULL_TEXT) as $p) { |
|
| 556 | - $extracted_content = $p->hook_get_full_text($url); |
|
| 555 | + foreach ($this->host->get_hooks(PluginHost::HOOK_GET_FULL_TEXT) as $p) { |
|
| 556 | + $extracted_content = $p->hook_get_full_text($url); |
|
| 557 | 557 | |
| 558 | - if ($extracted_content) { |
|
| 559 | - $article["content"] = $extracted_content; |
|
| 560 | - break; |
|
| 561 | - } |
|
| 562 | - } |
|
| 563 | - } |
|
| 564 | - } |
|
| 565 | - } |
|
| 558 | + if ($extracted_content) { |
|
| 559 | + $article["content"] = $extracted_content; |
|
| 560 | + break; |
|
| 561 | + } |
|
| 562 | + } |
|
| 563 | + } |
|
| 564 | + } |
|
| 565 | + } |
|
| 566 | 566 | |
| 567 | - return $article; |
|
| 568 | - } |
|
| 567 | + return $article; |
|
| 568 | + } |
|
| 569 | 569 | } |
@@ -22,7 +22,9 @@ discard block |
||
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | public function hook_prefs_tab($args) { |
| 25 | - if ($args != "prefFeeds") return; |
|
| 25 | + if ($args != "prefFeeds") { |
|
| 26 | + return; |
|
| 27 | + } |
|
| 26 | 28 | |
| 27 | 29 | print "<div dojoType=\"dijit.layout.AccordionPane\" |
| 28 | 30 | title=\"<i class='material-icons'>extension</i> ".__('Reddit content settings (af_redditimgur)')."\">"; |
@@ -173,8 +175,7 @@ discard block |
||
| 173 | 175 | if ($child["data"]["url"] == $matches[0]) { |
| 174 | 176 | try { |
| 175 | 177 | $source_stream = $child["data"]["media"]["reddit_video"]["fallback_url"]; |
| 176 | - } |
|
| 177 | - catch (Exception $e) { |
|
| 178 | + } catch (Exception $e) { |
|
| 178 | 179 | } |
| 179 | 180 | break 2; |
| 180 | 181 | } |
@@ -230,8 +231,9 @@ discard block |
||
| 230 | 231 | |
| 231 | 232 | $source_stream = str_replace(".gifv", ".mp4", $entry->getAttribute("href")); |
| 232 | 233 | |
| 233 | - if (strpos($source_stream, "imgur.com") !== FALSE) |
|
| 234 | - $poster_url = str_replace(".mp4", "h.jpg", $source_stream); |
|
| 234 | + if (strpos($source_stream, "imgur.com") !== FALSE) { |
|
| 235 | + $poster_url = str_replace(".mp4", "h.jpg", $source_stream); |
|
| 236 | + } |
|
| 235 | 237 | |
| 236 | 238 | $this->handle_as_video($doc, $entry, $source_stream, $poster_url); |
| 237 | 239 | |
@@ -426,7 +428,9 @@ discard block |
||
| 426 | 428 | if ($row = $sth->fetch()) { |
| 427 | 429 | $num_found = $row['cid']; |
| 428 | 430 | |
| 429 | - if ($num_found > 0) $article["force_catchup"] = true; |
|
| 431 | + if ($num_found > 0) { |
|
| 432 | + $article["force_catchup"] = true; |
|
| 433 | + } |
|
| 430 | 434 | } |
| 431 | 435 | } |
| 432 | 436 | } |
@@ -458,7 +462,9 @@ discard block |
||
| 458 | 462 | $video->setAttribute("controls", "1"); |
| 459 | 463 | $video->setAttribute("loop", "1"); |
| 460 | 464 | |
| 461 | - if ($poster_url) $video->setAttribute("poster", $poster_url); |
|
| 465 | + if ($poster_url) { |
|
| 466 | + $video->setAttribute("poster", $poster_url); |
|
| 467 | + } |
|
| 462 | 468 | |
| 463 | 469 | $source = $doc->createElement('source'); |
| 464 | 470 | $source->setAttribute("src", $source_stream); |
@@ -14,8 +14,9 @@ |
||
| 14 | 14 | |
| 15 | 15 | global $fetch_last_error_content; |
| 16 | 16 | |
| 17 | - if (!$res && $fetch_last_error_content) |
|
| 18 | - $res = $fetch_last_error_content; |
|
| 17 | + if (!$res && $fetch_last_error_content) { |
|
| 18 | + $res = $fetch_last_error_content; |
|
| 19 | + } |
|
| 19 | 20 | |
| 20 | 21 | $doc = new DOMDocument(); |
| 21 | 22 | |
@@ -6,7 +6,7 @@ |
||
| 6 | 6 | } |
| 7 | 7 | |
| 8 | 8 | public function process(&$article) { |
| 9 | - if (strpos($article["guid"], "whompcomic.com") !== FALSE) { |
|
| 9 | + if (strpos($article["guid"], "whompcomic.com") !== false) { |
|
| 10 | 10 | |
| 11 | 11 | $res = fetch_file_contents($article["link"], false, false, false, |
| 12 | 12 | false, false, 0, |
@@ -1,36 +1,36 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | class Af_Comics_Whomp extends Af_ComicFilter { |
| 3 | 3 | |
| 4 | - public function supported() { |
|
| 5 | - return array("Whomp!"); |
|
| 6 | - } |
|
| 4 | + public function supported() { |
|
| 5 | + return array("Whomp!"); |
|
| 6 | + } |
|
| 7 | 7 | |
| 8 | - public function process(&$article) { |
|
| 9 | - if (strpos($article["guid"], "whompcomic.com") !== FALSE) { |
|
| 8 | + public function process(&$article) { |
|
| 9 | + if (strpos($article["guid"], "whompcomic.com") !== FALSE) { |
|
| 10 | 10 | |
| 11 | - $res = fetch_file_contents($article["link"], false, false, false, |
|
| 12 | - false, false, 0, |
|
| 13 | - "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)"); |
|
| 11 | + $res = fetch_file_contents($article["link"], false, false, false, |
|
| 12 | + false, false, 0, |
|
| 13 | + "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)"); |
|
| 14 | 14 | |
| 15 | - global $fetch_last_error_content; |
|
| 15 | + global $fetch_last_error_content; |
|
| 16 | 16 | |
| 17 | - if (!$res && $fetch_last_error_content) |
|
| 18 | - $res = $fetch_last_error_content; |
|
| 17 | + if (!$res && $fetch_last_error_content) |
|
| 18 | + $res = $fetch_last_error_content; |
|
| 19 | 19 | |
| 20 | - $doc = new DOMDocument(); |
|
| 20 | + $doc = new DOMDocument(); |
|
| 21 | 21 | |
| 22 | - if (@$doc->loadHTML($res)) { |
|
| 23 | - $xpath = new DOMXPath($doc); |
|
| 24 | - $basenode = $xpath->query('//img[@id="cc-comic"]')->item(0); |
|
| 22 | + if (@$doc->loadHTML($res)) { |
|
| 23 | + $xpath = new DOMXPath($doc); |
|
| 24 | + $basenode = $xpath->query('//img[@id="cc-comic"]')->item(0); |
|
| 25 | 25 | |
| 26 | - if ($basenode) { |
|
| 27 | - $article["content"] = $doc->saveHTML($basenode); |
|
| 28 | - } |
|
| 29 | - } |
|
| 26 | + if ($basenode) { |
|
| 27 | + $article["content"] = $doc->saveHTML($basenode); |
|
| 28 | + } |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | - return true; |
|
| 32 | - } |
|
| 31 | + return true; |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - return false; |
|
| 35 | - } |
|
| 34 | + return false; |
|
| 35 | + } |
|
| 36 | 36 | } |
@@ -15,8 +15,9 @@ |
||
| 15 | 15 | |
| 16 | 16 | global $fetch_last_error_content; |
| 17 | 17 | |
| 18 | - if (!$res && $fetch_last_error_content) |
|
| 19 | - $res = $fetch_last_error_content; |
|
| 18 | + if (!$res && $fetch_last_error_content) { |
|
| 19 | + $res = $fetch_last_error_content; |
|
| 20 | + } |
|
| 20 | 21 | |
| 21 | 22 | $doc = new DOMDocument(); |
| 22 | 23 | |
@@ -7,7 +7,7 @@ |
||
| 7 | 7 | |
| 8 | 8 | public function process(&$article) { |
| 9 | 9 | |
| 10 | - if (strpos($article["guid"], "darklegacycomics.com") !== FALSE) { |
|
| 10 | + if (strpos($article["guid"], "darklegacycomics.com") !== false) { |
|
| 11 | 11 | |
| 12 | 12 | $res = fetch_file_contents($article["link"], false, false, false, |
| 13 | 13 | false, false, 0, |
@@ -1,38 +1,38 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | class Af_Comics_DarkLegacy extends Af_ComicFilter { |
| 3 | 3 | |
| 4 | - public function supported() { |
|
| 5 | - return array("Dark Legacy Comics"); |
|
| 6 | - } |
|
| 4 | + public function supported() { |
|
| 5 | + return array("Dark Legacy Comics"); |
|
| 6 | + } |
|
| 7 | 7 | |
| 8 | - public function process(&$article) { |
|
| 8 | + public function process(&$article) { |
|
| 9 | 9 | |
| 10 | - if (strpos($article["guid"], "darklegacycomics.com") !== FALSE) { |
|
| 10 | + if (strpos($article["guid"], "darklegacycomics.com") !== FALSE) { |
|
| 11 | 11 | |
| 12 | - $res = fetch_file_contents($article["link"], false, false, false, |
|
| 13 | - false, false, 0, |
|
| 14 | - "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)"); |
|
| 12 | + $res = fetch_file_contents($article["link"], false, false, false, |
|
| 13 | + false, false, 0, |
|
| 14 | + "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)"); |
|
| 15 | 15 | |
| 16 | - global $fetch_last_error_content; |
|
| 16 | + global $fetch_last_error_content; |
|
| 17 | 17 | |
| 18 | - if (!$res && $fetch_last_error_content) |
|
| 19 | - $res = $fetch_last_error_content; |
|
| 18 | + if (!$res && $fetch_last_error_content) |
|
| 19 | + $res = $fetch_last_error_content; |
|
| 20 | 20 | |
| 21 | - $doc = new DOMDocument(); |
|
| 21 | + $doc = new DOMDocument(); |
|
| 22 | 22 | |
| 23 | - if (@$doc->loadHTML($res)) { |
|
| 24 | - $xpath = new DOMXPath($doc); |
|
| 25 | - $basenode = $xpath->query('//div[@class="comic"]')->item(0); |
|
| 23 | + if (@$doc->loadHTML($res)) { |
|
| 24 | + $xpath = new DOMXPath($doc); |
|
| 25 | + $basenode = $xpath->query('//div[@class="comic"]')->item(0); |
|
| 26 | 26 | |
| 27 | - if ($basenode) { |
|
| 27 | + if ($basenode) { |
|
| 28 | 28 | |
| 29 | - $article["content"] = $doc->saveHTML($basenode); |
|
| 30 | - } |
|
| 31 | - } |
|
| 29 | + $article["content"] = $doc->saveHTML($basenode); |
|
| 30 | + } |
|
| 31 | + } |
|
| 32 | 32 | |
| 33 | - return true; |
|
| 34 | - } |
|
| 33 | + return true; |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | - return false; |
|
| 37 | - } |
|
| 36 | + return false; |
|
| 37 | + } |
|
| 38 | 38 | } |
@@ -54,7 +54,7 @@ |
||
| 54 | 54 | $i->parentNode->removeChild($i); |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | - if ($basenode){ |
|
| 57 | + if ($basenode) { |
|
| 58 | 58 | $article["content"] = $doc->saveHTML($basenode); |
| 59 | 59 | } |
| 60 | 60 | } |
@@ -46,8 +46,9 @@ |
||
| 46 | 46 | |
| 47 | 47 | $avatar = $xpath->query('(//div[@class="avatar"]//img)')->item(0); |
| 48 | 48 | |
| 49 | - if ($basenode) |
|
| 50 | - $basenode->insertBefore($avatar, $basenode->firstChild); |
|
| 49 | + if ($basenode) { |
|
| 50 | + $basenode->insertBefore($avatar, $basenode->firstChild); |
|
| 51 | + } |
|
| 51 | 52 | |
| 52 | 53 | $uninteresting = $xpath->query('(//div[@class="avatar"])'); |
| 53 | 54 | foreach ($uninteresting as $i) { |
@@ -6,7 +6,7 @@ discard block |
||
| 6 | 6 | } |
| 7 | 7 | |
| 8 | 8 | public function process(&$article) { |
| 9 | - if (strpos($article["link"], "penny-arcade.com") !== FALSE && strpos($article["title"], "Comic:") !== FALSE) { |
|
| 9 | + if (strpos($article["link"], "penny-arcade.com") !== false && strpos($article["title"], "Comic:") !== false) { |
|
| 10 | 10 | |
| 11 | 11 | $doc = new DOMDocument(); |
| 12 | 12 | |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | return true; |
| 23 | 23 | } |
| 24 | 24 | |
| 25 | - if (strpos($article["link"], "penny-arcade.com") !== FALSE && strpos($article["title"], "News Post:") !== FALSE) { |
|
| 25 | + if (strpos($article["link"], "penny-arcade.com") !== false && strpos($article["title"], "News Post:") !== false) { |
|
| 26 | 26 | $doc = new DOMDocument(); |
| 27 | 27 | |
| 28 | 28 | if ($doc->loadHTML(fetch_file_contents($article["link"]))) { |
@@ -1,67 +1,67 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | class Af_Comics_Pa extends Af_ComicFilter { |
| 3 | 3 | |
| 4 | - public function supported() { |
|
| 5 | - return array("Penny Arcade"); |
|
| 6 | - } |
|
| 4 | + public function supported() { |
|
| 5 | + return array("Penny Arcade"); |
|
| 6 | + } |
|
| 7 | 7 | |
| 8 | - public function process(&$article) { |
|
| 9 | - if (strpos($article["link"], "penny-arcade.com") !== FALSE && strpos($article["title"], "Comic:") !== FALSE) { |
|
| 8 | + public function process(&$article) { |
|
| 9 | + if (strpos($article["link"], "penny-arcade.com") !== FALSE && strpos($article["title"], "Comic:") !== FALSE) { |
|
| 10 | 10 | |
| 11 | - $doc = new DOMDocument(); |
|
| 11 | + $doc = new DOMDocument(); |
|
| 12 | 12 | |
| 13 | - if ($doc->loadHTML(fetch_file_contents($article["link"]))) { |
|
| 14 | - $xpath = new DOMXPath($doc); |
|
| 15 | - $basenode = $xpath->query('(//div[@id="comicFrame"])')->item(0); |
|
| 13 | + if ($doc->loadHTML(fetch_file_contents($article["link"]))) { |
|
| 14 | + $xpath = new DOMXPath($doc); |
|
| 15 | + $basenode = $xpath->query('(//div[@id="comicFrame"])')->item(0); |
|
| 16 | 16 | |
| 17 | - if ($basenode) { |
|
| 18 | - $article["content"] = $doc->saveHTML($basenode); |
|
| 19 | - } |
|
| 20 | - } |
|
| 17 | + if ($basenode) { |
|
| 18 | + $article["content"] = $doc->saveHTML($basenode); |
|
| 19 | + } |
|
| 20 | + } |
|
| 21 | 21 | |
| 22 | - return true; |
|
| 23 | - } |
|
| 22 | + return true; |
|
| 23 | + } |
|
| 24 | 24 | |
| 25 | - if (strpos($article["link"], "penny-arcade.com") !== FALSE && strpos($article["title"], "News Post:") !== FALSE) { |
|
| 26 | - $doc = new DOMDocument(); |
|
| 25 | + if (strpos($article["link"], "penny-arcade.com") !== FALSE && strpos($article["title"], "News Post:") !== FALSE) { |
|
| 26 | + $doc = new DOMDocument(); |
|
| 27 | 27 | |
| 28 | - if ($doc->loadHTML(fetch_file_contents($article["link"]))) { |
|
| 29 | - $xpath = new DOMXPath($doc); |
|
| 30 | - $entries = $xpath->query('(//div[@class="post"])'); |
|
| 28 | + if ($doc->loadHTML(fetch_file_contents($article["link"]))) { |
|
| 29 | + $xpath = new DOMXPath($doc); |
|
| 30 | + $entries = $xpath->query('(//div[@class="post"])'); |
|
| 31 | 31 | |
| 32 | - $basenode = false; |
|
| 32 | + $basenode = false; |
|
| 33 | 33 | |
| 34 | - foreach ($entries as $entry) { |
|
| 35 | - $basenode = $entry; |
|
| 36 | - } |
|
| 34 | + foreach ($entries as $entry) { |
|
| 35 | + $basenode = $entry; |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | - $meta = $xpath->query('(//div[@class="meta"])')->item(0); |
|
| 39 | - if ($meta->parentNode) { $meta->parentNode->removeChild($meta); } |
|
| 38 | + $meta = $xpath->query('(//div[@class="meta"])')->item(0); |
|
| 39 | + if ($meta->parentNode) { $meta->parentNode->removeChild($meta); } |
|
| 40 | 40 | |
| 41 | - $header = $xpath->query('(//div[@class="postBody"]/h2)')->item(0); |
|
| 42 | - if ($header->parentNode) { $header->parentNode->removeChild($header); } |
|
| 41 | + $header = $xpath->query('(//div[@class="postBody"]/h2)')->item(0); |
|
| 42 | + if ($header->parentNode) { $header->parentNode->removeChild($header); } |
|
| 43 | 43 | |
| 44 | - $header = $xpath->query('(//div[@class="postBody"]/div[@class="comicPost"])')->item(0); |
|
| 45 | - if ($header->parentNode) { $header->parentNode->removeChild($header); } |
|
| 44 | + $header = $xpath->query('(//div[@class="postBody"]/div[@class="comicPost"])')->item(0); |
|
| 45 | + if ($header->parentNode) { $header->parentNode->removeChild($header); } |
|
| 46 | 46 | |
| 47 | - $avatar = $xpath->query('(//div[@class="avatar"]//img)')->item(0); |
|
| 47 | + $avatar = $xpath->query('(//div[@class="avatar"]//img)')->item(0); |
|
| 48 | 48 | |
| 49 | - if ($basenode) |
|
| 50 | - $basenode->insertBefore($avatar, $basenode->firstChild); |
|
| 49 | + if ($basenode) |
|
| 50 | + $basenode->insertBefore($avatar, $basenode->firstChild); |
|
| 51 | 51 | |
| 52 | - $uninteresting = $xpath->query('(//div[@class="avatar"])'); |
|
| 53 | - foreach ($uninteresting as $i) { |
|
| 54 | - $i->parentNode->removeChild($i); |
|
| 55 | - } |
|
| 52 | + $uninteresting = $xpath->query('(//div[@class="avatar"])'); |
|
| 53 | + foreach ($uninteresting as $i) { |
|
| 54 | + $i->parentNode->removeChild($i); |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - if ($basenode){ |
|
| 58 | - $article["content"] = $doc->saveHTML($basenode); |
|
| 59 | - } |
|
| 60 | - } |
|
| 57 | + if ($basenode){ |
|
| 58 | + $article["content"] = $doc->saveHTML($basenode); |
|
| 59 | + } |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - return true; |
|
| 63 | - } |
|
| 62 | + return true; |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - return false; |
|
| 66 | - } |
|
| 65 | + return false; |
|
| 66 | + } |
|
| 67 | 67 | } |
@@ -17,8 +17,9 @@ |
||
| 17 | 17 | false, false, 0, |
| 18 | 18 | "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:50.0) Gecko/20100101 Firefox/50.0"); |
| 19 | 19 | |
| 20 | - if (!$res && $fetch_last_error_content) |
|
| 21 | - $res = $fetch_last_error_content; |
|
| 20 | + if (!$res && $fetch_last_error_content) { |
|
| 21 | + $res = $fetch_last_error_content; |
|
| 22 | + } |
|
| 22 | 23 | |
| 23 | 24 | if (@$doc->loadHTML($res)) { |
| 24 | 25 | $xpath = new DOMXPath($doc); |
@@ -6,8 +6,8 @@ |
||
| 6 | 6 | } |
| 7 | 7 | |
| 8 | 8 | public function process(&$article) { |
| 9 | - if (strpos($article["link"], "cad-comic.com") !== FALSE) { |
|
| 10 | - if (strpos($article["title"], "News:") === FALSE) { |
|
| 9 | + if (strpos($article["link"], "cad-comic.com") !== false) { |
|
| 10 | + if (strpos($article["title"], "News:") === false) { |
|
| 11 | 11 | |
| 12 | 12 | global $fetch_last_error_content; |
| 13 | 13 | |
@@ -1,39 +1,39 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | class Af_Comics_Cad extends Af_ComicFilter { |
| 3 | 3 | |
| 4 | - public function supported() { |
|
| 5 | - return array("Ctrl+Alt+Del"); |
|
| 6 | - } |
|
| 4 | + public function supported() { |
|
| 5 | + return array("Ctrl+Alt+Del"); |
|
| 6 | + } |
|
| 7 | 7 | |
| 8 | - public function process(&$article) { |
|
| 9 | - if (strpos($article["link"], "cad-comic.com") !== FALSE) { |
|
| 10 | - if (strpos($article["title"], "News:") === FALSE) { |
|
| 8 | + public function process(&$article) { |
|
| 9 | + if (strpos($article["link"], "cad-comic.com") !== FALSE) { |
|
| 10 | + if (strpos($article["title"], "News:") === FALSE) { |
|
| 11 | 11 | |
| 12 | - global $fetch_last_error_content; |
|
| 12 | + global $fetch_last_error_content; |
|
| 13 | 13 | |
| 14 | - $doc = new DOMDocument(); |
|
| 14 | + $doc = new DOMDocument(); |
|
| 15 | 15 | |
| 16 | - $res = fetch_file_contents($article["link"], false, false, false, |
|
| 17 | - false, false, 0, |
|
| 18 | - "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:50.0) Gecko/20100101 Firefox/50.0"); |
|
| 16 | + $res = fetch_file_contents($article["link"], false, false, false, |
|
| 17 | + false, false, 0, |
|
| 18 | + "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:50.0) Gecko/20100101 Firefox/50.0"); |
|
| 19 | 19 | |
| 20 | - if (!$res && $fetch_last_error_content) |
|
| 21 | - $res = $fetch_last_error_content; |
|
| 20 | + if (!$res && $fetch_last_error_content) |
|
| 21 | + $res = $fetch_last_error_content; |
|
| 22 | 22 | |
| 23 | - if (@$doc->loadHTML($res)) { |
|
| 24 | - $xpath = new DOMXPath($doc); |
|
| 25 | - $basenode = $xpath->query('//div[@class="comicpage"]/a/img')->item(0); |
|
| 23 | + if (@$doc->loadHTML($res)) { |
|
| 24 | + $xpath = new DOMXPath($doc); |
|
| 25 | + $basenode = $xpath->query('//div[@class="comicpage"]/a/img')->item(0); |
|
| 26 | 26 | |
| 27 | - if ($basenode) { |
|
| 28 | - $article["content"] = $doc->saveHTML($basenode); |
|
| 29 | - } |
|
| 30 | - } |
|
| 27 | + if ($basenode) { |
|
| 28 | + $article["content"] = $doc->saveHTML($basenode); |
|
| 29 | + } |
|
| 30 | + } |
|
| 31 | 31 | |
| 32 | - } |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - return true; |
|
| 35 | - } |
|
| 34 | + return true; |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - return false; |
|
| 38 | - } |
|
| 37 | + return false; |
|
| 38 | + } |
|
| 39 | 39 | } |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | |
| 37 | 37 | foreach ($matches as $tag) { |
| 38 | 38 | // Only strings starting with a number sign are considered tags |
| 39 | - if ( substr($tag->textContent, 0, 1) == '#' ) { |
|
| 39 | + if (substr($tag->textContent, 0, 1) == '#') { |
|
| 40 | 40 | $tags[] = mb_strtolower(substr($tag->textContent, 1), 'utf-8'); |
| 41 | 41 | } |
| 42 | 42 | } |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | |
| 55 | 55 | // Add comic title to article type if not empty (mostly Sunday strips) |
| 56 | 56 | if ($comic_title) { |
| 57 | - $article["title"] = $article["title"] . " - " . $comic_title; |
|
| 57 | + $article["title"] = $article["title"]." - ".$comic_title; |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | if (!empty($tags)) { |
@@ -15,8 +15,9 @@ |
||
| 15 | 15 | |
| 16 | 16 | global $fetch_last_error_content; |
| 17 | 17 | |
| 18 | - if (!$res && $fetch_last_error_content) |
|
| 19 | - $res = $fetch_last_error_content; |
|
| 18 | + if (!$res && $fetch_last_error_content) { |
|
| 19 | + $res = $fetch_last_error_content; |
|
| 20 | + } |
|
| 20 | 21 | |
| 21 | 22 | $doc = new DOMDocument(); |
| 22 | 23 | |
@@ -7,8 +7,8 @@ |
||
| 7 | 7 | } |
| 8 | 8 | |
| 9 | 9 | public function process(&$article) { |
| 10 | - if (strpos($article["link"], "dilbert.com") !== FALSE || |
|
| 11 | - strpos($article["link"], "/DilbertDailyStrip") !== FALSE) { |
|
| 10 | + if (strpos($article["link"], "dilbert.com") !== false || |
|
| 11 | + strpos($article["link"], "/DilbertDailyStrip") !== false) { |
|
| 12 | 12 | |
| 13 | 13 | $res = fetch_file_contents($article["link"], false, false, false, |
| 14 | 14 | false, false, 0, |
@@ -2,72 +2,72 @@ |
||
| 2 | 2 | |
| 3 | 3 | class Af_Comics_Dilbert extends Af_ComicFilter { |
| 4 | 4 | |
| 5 | - public function supported() { |
|
| 6 | - return array("Dilbert"); |
|
| 7 | - } |
|
| 5 | + public function supported() { |
|
| 6 | + return array("Dilbert"); |
|
| 7 | + } |
|
| 8 | 8 | |
| 9 | - public function process(&$article) { |
|
| 10 | - if (strpos($article["link"], "dilbert.com") !== FALSE || |
|
| 11 | - strpos($article["link"], "/DilbertDailyStrip") !== FALSE) { |
|
| 9 | + public function process(&$article) { |
|
| 10 | + if (strpos($article["link"], "dilbert.com") !== FALSE || |
|
| 11 | + strpos($article["link"], "/DilbertDailyStrip") !== FALSE) { |
|
| 12 | 12 | |
| 13 | - $res = fetch_file_contents($article["link"], false, false, false, |
|
| 14 | - false, false, 0, |
|
| 15 | - "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:50.0) Gecko/20100101 Firefox/50.0"); |
|
| 13 | + $res = fetch_file_contents($article["link"], false, false, false, |
|
| 14 | + false, false, 0, |
|
| 15 | + "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:50.0) Gecko/20100101 Firefox/50.0"); |
|
| 16 | 16 | |
| 17 | - global $fetch_last_error_content; |
|
| 17 | + global $fetch_last_error_content; |
|
| 18 | 18 | |
| 19 | - if (!$res && $fetch_last_error_content) |
|
| 20 | - $res = $fetch_last_error_content; |
|
| 19 | + if (!$res && $fetch_last_error_content) |
|
| 20 | + $res = $fetch_last_error_content; |
|
| 21 | 21 | |
| 22 | - $doc = new DOMDocument(); |
|
| 22 | + $doc = new DOMDocument(); |
|
| 23 | 23 | |
| 24 | - if (@$doc->loadHTML($res)) { |
|
| 25 | - $xpath = new DOMXPath($doc); |
|
| 24 | + if (@$doc->loadHTML($res)) { |
|
| 25 | + $xpath = new DOMXPath($doc); |
|
| 26 | 26 | |
| 27 | - // Get the image container |
|
| 28 | - $basenode = $xpath->query('(//div[@class="img-comic-container"]/a[@class="img-comic-link"])')->item(0); |
|
| 27 | + // Get the image container |
|
| 28 | + $basenode = $xpath->query('(//div[@class="img-comic-container"]/a[@class="img-comic-link"])')->item(0); |
|
| 29 | 29 | |
| 30 | - // Get the comic title |
|
| 31 | - $comic_title = $xpath->query('(//span[@class="comic-title-name"])')->item(0)->textContent; |
|
| 30 | + // Get the comic title |
|
| 31 | + $comic_title = $xpath->query('(//span[@class="comic-title-name"])')->item(0)->textContent; |
|
| 32 | 32 | |
| 33 | - // Get tags from the article |
|
| 34 | - $matches = $xpath->query('(//p[contains(@class, "comic-tags")][1]//a)'); |
|
| 35 | - $tags = array(); |
|
| 33 | + // Get tags from the article |
|
| 34 | + $matches = $xpath->query('(//p[contains(@class, "comic-tags")][1]//a)'); |
|
| 35 | + $tags = array(); |
|
| 36 | 36 | |
| 37 | - foreach ($matches as $tag) { |
|
| 38 | - // Only strings starting with a number sign are considered tags |
|
| 39 | - if ( substr($tag->textContent, 0, 1) == '#' ) { |
|
| 40 | - $tags[] = mb_strtolower(substr($tag->textContent, 1), 'utf-8'); |
|
| 41 | - } |
|
| 42 | - } |
|
| 37 | + foreach ($matches as $tag) { |
|
| 38 | + // Only strings starting with a number sign are considered tags |
|
| 39 | + if ( substr($tag->textContent, 0, 1) == '#' ) { |
|
| 40 | + $tags[] = mb_strtolower(substr($tag->textContent, 1), 'utf-8'); |
|
| 41 | + } |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - // Get the current comics transcript and set it |
|
| 45 | - // as the title so it will be visible on mousover |
|
| 46 | - $transcript = $xpath->query('(//div[starts-with(@id, "js-toggle-transcript-")]//p)')->item(0); |
|
| 47 | - if ($transcript) { |
|
| 48 | - $basenode->setAttribute("title", $transcript->textContent); |
|
| 49 | - } |
|
| 44 | + // Get the current comics transcript and set it |
|
| 45 | + // as the title so it will be visible on mousover |
|
| 46 | + $transcript = $xpath->query('(//div[starts-with(@id, "js-toggle-transcript-")]//p)')->item(0); |
|
| 47 | + if ($transcript) { |
|
| 48 | + $basenode->setAttribute("title", $transcript->textContent); |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - if ($basenode) { |
|
| 52 | - $article["content"] = $doc->saveHTML($basenode); |
|
| 53 | - } |
|
| 51 | + if ($basenode) { |
|
| 52 | + $article["content"] = $doc->saveHTML($basenode); |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - // Add comic title to article type if not empty (mostly Sunday strips) |
|
| 56 | - if ($comic_title) { |
|
| 57 | - $article["title"] = $article["title"] . " - " . $comic_title; |
|
| 58 | - } |
|
| 55 | + // Add comic title to article type if not empty (mostly Sunday strips) |
|
| 56 | + if ($comic_title) { |
|
| 57 | + $article["title"] = $article["title"] . " - " . $comic_title; |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - if (!empty($tags)) { |
|
| 61 | - // Ignore existing tags and just replace them all |
|
| 62 | - $article["tags"] = array_unique($tags); |
|
| 63 | - } |
|
| 60 | + if (!empty($tags)) { |
|
| 61 | + // Ignore existing tags and just replace them all |
|
| 62 | + $article["tags"] = array_unique($tags); |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - } |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - return true; |
|
| 68 | - } |
|
| 67 | + return true; |
|
| 68 | + } |
|
| 69 | 69 | |
| 70 | - return false; |
|
| 71 | - } |
|
| 70 | + return false; |
|
| 71 | + } |
|
| 72 | 72 | } |
| 73 | 73 | ?> |
@@ -17,11 +17,13 @@ discard block |
||
| 17 | 17 | $this->host = $host; |
| 18 | 18 | $this->cache = new DiskCache("starred-images"); |
| 19 | 19 | |
| 20 | - if ($this->cache->makeDir()) |
|
| 21 | - chmod($this->cache->getDir(), 0777); |
|
| 20 | + if ($this->cache->makeDir()) { |
|
| 21 | + chmod($this->cache->getDir(), 0777); |
|
| 22 | + } |
|
| 22 | 23 | |
| 23 | - if (!$this->cache->exists(".no-auto-expiry")) |
|
| 24 | - $this->cache->touch(".no-auto-expiry"); |
|
| 24 | + if (!$this->cache->exists(".no-auto-expiry")) { |
|
| 25 | + $this->cache->touch(".no-auto-expiry"); |
|
| 26 | + } |
|
| 25 | 27 | |
| 26 | 28 | if ($this->cache->isWritable()) { |
| 27 | 29 | $host->add_hook($host::HOOK_HOUSE_KEEPING, $this); |
@@ -141,8 +143,10 @@ discard block |
||
| 141 | 143 | |
| 142 | 144 | $data = fetch_file_contents(["url" => $url, "max_size" => MAX_CACHE_FILE_SIZE]); |
| 143 | 145 | |
| 144 | - if ($data) |
|
| 145 | - return $this->cache->put($local_filename, $data);; |
|
| 146 | + if ($data) { |
|
| 147 | + return $this->cache->put($local_filename, $data); |
|
| 148 | + } |
|
| 149 | + ; |
|
| 146 | 150 | |
| 147 | 151 | } else { |
| 148 | 152 | //Debug::log("cache_images: local file exists for $url", Debug::$LOG_VERBOSE); |
@@ -167,10 +171,11 @@ discard block |
||
| 167 | 171 | |
| 168 | 172 | Debug::log("status: $status_filename", Debug::$LOG_VERBOSE); |
| 169 | 173 | |
| 170 | - if ($this->cache->exists($status_filename)) |
|
| 171 | - $status = json_decode($this->cache->get($status_filename), true); |
|
| 172 | - else |
|
| 173 | - $status = []; |
|
| 174 | + if ($this->cache->exists($status_filename)) { |
|
| 175 | + $status = json_decode($this->cache->get($status_filename), true); |
|
| 176 | + } else { |
|
| 177 | + $status = []; |
|
| 178 | + } |
|
| 174 | 179 | |
| 175 | 180 | $status["attempt"] += 1; |
| 176 | 181 | |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | public function hook_house_keeping() { |
| 36 | 36 | /* since HOOK_UPDATE_TASK is not available to user plugins, this hook is a next best thing */ |
| 37 | 37 | |
| 38 | - Debug::log("caching media of starred articles for user " . $this->host->get_owner_uid() . "..."); |
|
| 38 | + Debug::log("caching media of starred articles for user ".$this->host->get_owner_uid()."..."); |
|
| 39 | 39 | |
| 40 | 40 | $sth = $this->pdo->prepare("SELECT content, ttrss_entries.title, |
| 41 | 41 | ttrss_user_entries.owner_uid, link, site_url, ttrss_entries.id, plugin_data |
@@ -53,13 +53,13 @@ discard block |
||
| 53 | 53 | $usth = $this->pdo->prepare("UPDATE ttrss_entries SET plugin_data = ? WHERE id = ?"); |
| 54 | 54 | |
| 55 | 55 | while ($line = $sth->fetch()) { |
| 56 | - Debug::log("processing article " . $line["title"], Debug::$LOG_VERBOSE); |
|
| 56 | + Debug::log("processing article ".$line["title"], Debug::$LOG_VERBOSE); |
|
| 57 | 57 | |
| 58 | 58 | if ($line["site_url"]) { |
| 59 | 59 | $success = $this->cache_article_images($line["content"], $line["site_url"], $line["owner_uid"], $line["id"]); |
| 60 | 60 | |
| 61 | 61 | if ($success) { |
| 62 | - $plugin_data = "starred_cache_images,${line['owner_uid']}:" . $line["plugin_data"]; |
|
| 62 | + $plugin_data = "starred_cache_images,${line['owner_uid']}:".$line["plugin_data"]; |
|
| 63 | 63 | |
| 64 | 64 | $usth->execute([$plugin_data, $line['id']]); |
| 65 | 65 | } |
@@ -69,9 +69,9 @@ discard block |
||
| 69 | 69 | |
| 70 | 70 | /* actual housekeeping */ |
| 71 | 71 | |
| 72 | - Debug::log("expiring " . $this->cache->getDir() . "..."); |
|
| 72 | + Debug::log("expiring ".$this->cache->getDir()."..."); |
|
| 73 | 73 | |
| 74 | - $files = glob($this->cache->getDir() . "/*.{png,mp4,status}", GLOB_BRACE); |
|
| 74 | + $files = glob($this->cache->getDir()."/*.{png,mp4,status}", GLOB_BRACE); |
|
| 75 | 75 | |
| 76 | 76 | $last_article_id = 0; |
| 77 | 77 | $article_exists = 1; |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | public function hook_enclosure_entry($enc, $article_id) { |
| 98 | - $local_filename = $article_id . "-" . sha1($enc["content_url"]); |
|
| 98 | + $local_filename = $article_id."-".sha1($enc["content_url"]); |
|
| 99 | 99 | |
| 100 | 100 | if ($this->cache->exists($local_filename)) { |
| 101 | 101 | $enc["content_url"] = $this->cache->getUrl($local_filename); |
@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | if ($entry->hasAttribute('src')) { |
| 115 | 115 | $src = rewrite_relative_url($site_url, $entry->getAttribute('src')); |
| 116 | 116 | |
| 117 | - $local_filename = $article_id . "-" . sha1($src); |
|
| 117 | + $local_filename = $article_id."-".sha1($src); |
|
| 118 | 118 | |
| 119 | 119 | if ($this->cache->exists($local_filename)) { |
| 120 | 120 | $entry->setAttribute("src", $this->cache->getUrl($local_filename)); |
@@ -128,7 +128,7 @@ discard block |
||
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | private function cache_url($article_id, $url) { |
| 131 | - $local_filename = $article_id . "-" . sha1($url); |
|
| 131 | + $local_filename = $article_id."-".sha1($url); |
|
| 132 | 132 | |
| 133 | 133 | if (!$this->cache->exists($local_filename)) { |
| 134 | 134 | Debug::log("cache_images: downloading: $url to $local_filename", Debug::$LOG_VERBOSE); |
@@ -136,7 +136,7 @@ discard block |
||
| 136 | 136 | $data = fetch_file_contents(["url" => $url, "max_size" => MAX_CACHE_FILE_SIZE]); |
| 137 | 137 | |
| 138 | 138 | if ($data) |
| 139 | - return $this->cache->put($local_filename, $data);; |
|
| 139 | + return $this->cache->put($local_filename, $data); ; |
|
| 140 | 140 | |
| 141 | 141 | } else { |
| 142 | 142 | //Debug::log("cache_images: local file exists for $url", Debug::$LOG_VERBOSE); |
@@ -148,7 +148,7 @@ discard block |
||
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | private function cache_article_images($content, $site_url, $owner_uid, $article_id) { |
| 151 | - $status_filename = $article_id . "-" . sha1($site_url) . ".status"; |
|
| 151 | + $status_filename = $article_id."-".sha1($site_url).".status"; |
|
| 152 | 152 | |
| 153 | 153 | /* housekeeping might run as a separate user, in this case status/media might not be writable */ |
| 154 | 154 | if (!$this->cache->isWritable($status_filename)) { |
@@ -181,7 +181,7 @@ discard block |
||
| 181 | 181 | $has_images = false; |
| 182 | 182 | $success = false; |
| 183 | 183 | |
| 184 | - if ($doc->loadHTML('<?xml encoding="UTF-8">' . $content)) { |
|
| 184 | + if ($doc->loadHTML('<?xml encoding="UTF-8">'.$content)) { |
|
| 185 | 185 | $xpath = new DOMXPath($doc); |
| 186 | 186 | $entries = $xpath->query('(//img[@src])|(//video/source[@src])'); |
| 187 | 187 | |
@@ -1,43 +1,43 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | class Cache_Starred_Images extends Plugin { |
| 3 | 3 | |
| 4 | - /* @var PluginHost $host */ |
|
| 5 | - private $host; |
|
| 6 | - /* @var DiskCache $cache */ |
|
| 7 | - private $cache; |
|
| 4 | + /* @var PluginHost $host */ |
|
| 5 | + private $host; |
|
| 6 | + /* @var DiskCache $cache */ |
|
| 7 | + private $cache; |
|
| 8 | 8 | private $max_cache_attempts = 5; // per-article |
| 9 | 9 | |
| 10 | - public function about() { |
|
| 11 | - return array(1.0, |
|
| 12 | - "Automatically cache media files in Starred articles", |
|
| 13 | - "fox"); |
|
| 14 | - } |
|
| 10 | + public function about() { |
|
| 11 | + return array(1.0, |
|
| 12 | + "Automatically cache media files in Starred articles", |
|
| 13 | + "fox"); |
|
| 14 | + } |
|
| 15 | 15 | |
| 16 | - public function init($host) { |
|
| 17 | - $this->host = $host; |
|
| 18 | - $this->cache = new DiskCache("starred-images"); |
|
| 16 | + public function init($host) { |
|
| 17 | + $this->host = $host; |
|
| 18 | + $this->cache = new DiskCache("starred-images"); |
|
| 19 | 19 | |
| 20 | - if ($this->cache->makeDir()) |
|
| 21 | - chmod($this->cache->getDir(), 0777); |
|
| 20 | + if ($this->cache->makeDir()) |
|
| 21 | + chmod($this->cache->getDir(), 0777); |
|
| 22 | 22 | |
| 23 | - if (!$this->cache->exists(".no-auto-expiry")) |
|
| 24 | - $this->cache->touch(".no-auto-expiry"); |
|
| 23 | + if (!$this->cache->exists(".no-auto-expiry")) |
|
| 24 | + $this->cache->touch(".no-auto-expiry"); |
|
| 25 | 25 | |
| 26 | - if ($this->cache->isWritable()) { |
|
| 27 | - $host->add_hook($host::HOOK_HOUSE_KEEPING, $this); |
|
| 28 | - $host->add_hook($host::HOOK_ENCLOSURE_ENTRY, $this); |
|
| 29 | - $host->add_hook($host::HOOK_SANITIZE, $this); |
|
| 30 | - } else { |
|
| 31 | - user_error("Starred cache directory ".$this->cache->getDir()." is not writable.", E_USER_WARNING); |
|
| 32 | - } |
|
| 33 | - } |
|
| 26 | + if ($this->cache->isWritable()) { |
|
| 27 | + $host->add_hook($host::HOOK_HOUSE_KEEPING, $this); |
|
| 28 | + $host->add_hook($host::HOOK_ENCLOSURE_ENTRY, $this); |
|
| 29 | + $host->add_hook($host::HOOK_SANITIZE, $this); |
|
| 30 | + } else { |
|
| 31 | + user_error("Starred cache directory ".$this->cache->getDir()." is not writable.", E_USER_WARNING); |
|
| 32 | + } |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | - public function hook_house_keeping() { |
|
| 36 | - /* since HOOK_UPDATE_TASK is not available to user plugins, this hook is a next best thing */ |
|
| 35 | + public function hook_house_keeping() { |
|
| 36 | + /* since HOOK_UPDATE_TASK is not available to user plugins, this hook is a next best thing */ |
|
| 37 | 37 | |
| 38 | - Debug::log("caching media of starred articles for user " . $this->host->get_owner_uid() . "..."); |
|
| 38 | + Debug::log("caching media of starred articles for user " . $this->host->get_owner_uid() . "..."); |
|
| 39 | 39 | |
| 40 | - $sth = $this->pdo->prepare("SELECT content, ttrss_entries.title, |
|
| 40 | + $sth = $this->pdo->prepare("SELECT content, ttrss_entries.title, |
|
| 41 | 41 | ttrss_user_entries.owner_uid, link, site_url, ttrss_entries.id, plugin_data |
| 42 | 42 | FROM ttrss_entries, ttrss_user_entries LEFT JOIN ttrss_feeds ON |
| 43 | 43 | (ttrss_user_entries.feed_id = ttrss_feeds.id) |
@@ -48,115 +48,115 @@ discard block |
||
| 48 | 48 | plugin_data NOT LIKE '%starred_cache_images%' |
| 49 | 49 | ORDER BY ".sql_random_function()." LIMIT 100"); |
| 50 | 50 | |
| 51 | - if ($sth->execute([$this->host->get_owner_uid()])) { |
|
| 51 | + if ($sth->execute([$this->host->get_owner_uid()])) { |
|
| 52 | 52 | |
| 53 | - $usth = $this->pdo->prepare("UPDATE ttrss_entries SET plugin_data = ? WHERE id = ?"); |
|
| 53 | + $usth = $this->pdo->prepare("UPDATE ttrss_entries SET plugin_data = ? WHERE id = ?"); |
|
| 54 | 54 | |
| 55 | - while ($line = $sth->fetch()) { |
|
| 56 | - Debug::log("processing article " . $line["title"], Debug::$LOG_VERBOSE); |
|
| 55 | + while ($line = $sth->fetch()) { |
|
| 56 | + Debug::log("processing article " . $line["title"], Debug::$LOG_VERBOSE); |
|
| 57 | 57 | |
| 58 | - if ($line["site_url"]) { |
|
| 59 | - $success = $this->cache_article_images($line["content"], $line["site_url"], $line["owner_uid"], $line["id"]); |
|
| 58 | + if ($line["site_url"]) { |
|
| 59 | + $success = $this->cache_article_images($line["content"], $line["site_url"], $line["owner_uid"], $line["id"]); |
|
| 60 | 60 | |
| 61 | - if ($success) { |
|
| 62 | - $plugin_data = "starred_cache_images,${line['owner_uid']}:" . $line["plugin_data"]; |
|
| 61 | + if ($success) { |
|
| 62 | + $plugin_data = "starred_cache_images,${line['owner_uid']}:" . $line["plugin_data"]; |
|
| 63 | 63 | |
| 64 | - $usth->execute([$plugin_data, $line['id']]); |
|
| 65 | - } |
|
| 66 | - } |
|
| 67 | - } |
|
| 68 | - } |
|
| 64 | + $usth->execute([$plugin_data, $line['id']]); |
|
| 65 | + } |
|
| 66 | + } |
|
| 67 | + } |
|
| 68 | + } |
|
| 69 | 69 | |
| 70 | - /* actual housekeeping */ |
|
| 70 | + /* actual housekeeping */ |
|
| 71 | 71 | |
| 72 | - Debug::log("expiring " . $this->cache->getDir() . "..."); |
|
| 72 | + Debug::log("expiring " . $this->cache->getDir() . "..."); |
|
| 73 | 73 | |
| 74 | - $files = glob($this->cache->getDir() . "/*.{png,mp4,status}", GLOB_BRACE); |
|
| 74 | + $files = glob($this->cache->getDir() . "/*.{png,mp4,status}", GLOB_BRACE); |
|
| 75 | 75 | |
| 76 | - $last_article_id = 0; |
|
| 77 | - $article_exists = 1; |
|
| 76 | + $last_article_id = 0; |
|
| 77 | + $article_exists = 1; |
|
| 78 | 78 | |
| 79 | - foreach ($files as $file) { |
|
| 80 | - list ($article_id, $hash) = explode("-", basename($file)); |
|
| 79 | + foreach ($files as $file) { |
|
| 80 | + list ($article_id, $hash) = explode("-", basename($file)); |
|
| 81 | 81 | |
| 82 | - if ($article_id != $last_article_id) { |
|
| 83 | - $last_article_id = $article_id; |
|
| 82 | + if ($article_id != $last_article_id) { |
|
| 83 | + $last_article_id = $article_id; |
|
| 84 | 84 | |
| 85 | - $sth = $this->pdo->prepare("SELECT id FROM ttrss_entries WHERE id = ?"); |
|
| 86 | - $sth->execute([$article_id]); |
|
| 85 | + $sth = $this->pdo->prepare("SELECT id FROM ttrss_entries WHERE id = ?"); |
|
| 86 | + $sth->execute([$article_id]); |
|
| 87 | 87 | |
| 88 | - $article_exists = $sth->fetch(); |
|
| 89 | - } |
|
| 88 | + $article_exists = $sth->fetch(); |
|
| 89 | + } |
|
| 90 | 90 | |
| 91 | - if (!$article_exists) { |
|
| 92 | - unlink($file); |
|
| 93 | - } |
|
| 94 | - } |
|
| 95 | - } |
|
| 91 | + if (!$article_exists) { |
|
| 92 | + unlink($file); |
|
| 93 | + } |
|
| 94 | + } |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | - public function hook_enclosure_entry($enc, $article_id) { |
|
| 98 | - $local_filename = $article_id . "-" . sha1($enc["content_url"]); |
|
| 97 | + public function hook_enclosure_entry($enc, $article_id) { |
|
| 98 | + $local_filename = $article_id . "-" . sha1($enc["content_url"]); |
|
| 99 | 99 | |
| 100 | - if ($this->cache->exists($local_filename)) { |
|
| 101 | - $enc["content_url"] = $this->cache->getUrl($local_filename); |
|
| 102 | - } |
|
| 100 | + if ($this->cache->exists($local_filename)) { |
|
| 101 | + $enc["content_url"] = $this->cache->getUrl($local_filename); |
|
| 102 | + } |
|
| 103 | 103 | |
| 104 | - return $enc; |
|
| 105 | - } |
|
| 104 | + return $enc; |
|
| 105 | + } |
|
| 106 | 106 | |
| 107 | - public function hook_sanitize($doc, $site_url, $allowed_elements, $disallowed_attributes, $article_id) { |
|
| 108 | - $xpath = new DOMXpath($doc); |
|
| 107 | + public function hook_sanitize($doc, $site_url, $allowed_elements, $disallowed_attributes, $article_id) { |
|
| 108 | + $xpath = new DOMXpath($doc); |
|
| 109 | 109 | |
| 110 | - if ($article_id) { |
|
| 111 | - $entries = $xpath->query('(//img[@src])|(//video/source[@src])'); |
|
| 110 | + if ($article_id) { |
|
| 111 | + $entries = $xpath->query('(//img[@src])|(//video/source[@src])'); |
|
| 112 | 112 | |
| 113 | - foreach ($entries as $entry) { |
|
| 114 | - if ($entry->hasAttribute('src')) { |
|
| 115 | - $src = rewrite_relative_url($site_url, $entry->getAttribute('src')); |
|
| 113 | + foreach ($entries as $entry) { |
|
| 114 | + if ($entry->hasAttribute('src')) { |
|
| 115 | + $src = rewrite_relative_url($site_url, $entry->getAttribute('src')); |
|
| 116 | 116 | |
| 117 | - $local_filename = $article_id . "-" . sha1($src); |
|
| 117 | + $local_filename = $article_id . "-" . sha1($src); |
|
| 118 | 118 | |
| 119 | - if ($this->cache->exists($local_filename)) { |
|
| 120 | - $entry->setAttribute("src", $this->cache->getUrl($local_filename)); |
|
| 121 | - $entry->removeAttribute("srcset"); |
|
| 122 | - } |
|
| 123 | - } |
|
| 124 | - } |
|
| 125 | - } |
|
| 119 | + if ($this->cache->exists($local_filename)) { |
|
| 120 | + $entry->setAttribute("src", $this->cache->getUrl($local_filename)); |
|
| 121 | + $entry->removeAttribute("srcset"); |
|
| 122 | + } |
|
| 123 | + } |
|
| 124 | + } |
|
| 125 | + } |
|
| 126 | 126 | |
| 127 | - return $doc; |
|
| 128 | - } |
|
| 127 | + return $doc; |
|
| 128 | + } |
|
| 129 | 129 | |
| 130 | - private function cache_url($article_id, $url) { |
|
| 131 | - $local_filename = $article_id . "-" . sha1($url); |
|
| 130 | + private function cache_url($article_id, $url) { |
|
| 131 | + $local_filename = $article_id . "-" . sha1($url); |
|
| 132 | 132 | |
| 133 | - if (!$this->cache->exists($local_filename)) { |
|
| 134 | - Debug::log("cache_images: downloading: $url to $local_filename", Debug::$LOG_VERBOSE); |
|
| 133 | + if (!$this->cache->exists($local_filename)) { |
|
| 134 | + Debug::log("cache_images: downloading: $url to $local_filename", Debug::$LOG_VERBOSE); |
|
| 135 | 135 | |
| 136 | - $data = fetch_file_contents(["url" => $url, "max_size" => MAX_CACHE_FILE_SIZE]); |
|
| 136 | + $data = fetch_file_contents(["url" => $url, "max_size" => MAX_CACHE_FILE_SIZE]); |
|
| 137 | 137 | |
| 138 | - if ($data) |
|
| 139 | - return $this->cache->put($local_filename, $data);; |
|
| 138 | + if ($data) |
|
| 139 | + return $this->cache->put($local_filename, $data);; |
|
| 140 | 140 | |
| 141 | - } else { |
|
| 142 | - //Debug::log("cache_images: local file exists for $url", Debug::$LOG_VERBOSE); |
|
| 141 | + } else { |
|
| 142 | + //Debug::log("cache_images: local file exists for $url", Debug::$LOG_VERBOSE); |
|
| 143 | 143 | |
| 144 | - return true; |
|
| 145 | - } |
|
| 144 | + return true; |
|
| 145 | + } |
|
| 146 | 146 | |
| 147 | - return false; |
|
| 148 | - } |
|
| 147 | + return false; |
|
| 148 | + } |
|
| 149 | 149 | |
| 150 | - private function cache_article_images($content, $site_url, $owner_uid, $article_id) { |
|
| 151 | - $status_filename = $article_id . "-" . sha1($site_url) . ".status"; |
|
| 150 | + private function cache_article_images($content, $site_url, $owner_uid, $article_id) { |
|
| 151 | + $status_filename = $article_id . "-" . sha1($site_url) . ".status"; |
|
| 152 | 152 | |
| 153 | - /* housekeeping might run as a separate user, in this case status/media might not be writable */ |
|
| 154 | - if (!$this->cache->isWritable($status_filename)) { |
|
| 155 | - Debug::log("status not writable: $status_filename", Debug::$LOG_VERBOSE); |
|
| 156 | - return false; |
|
| 157 | - } |
|
| 153 | + /* housekeeping might run as a separate user, in this case status/media might not be writable */ |
|
| 154 | + if (!$this->cache->isWritable($status_filename)) { |
|
| 155 | + Debug::log("status not writable: $status_filename", Debug::$LOG_VERBOSE); |
|
| 156 | + return false; |
|
| 157 | + } |
|
| 158 | 158 | |
| 159 | - Debug::log("status: $status_filename", Debug::$LOG_VERBOSE); |
|
| 159 | + Debug::log("status: $status_filename", Debug::$LOG_VERBOSE); |
|
| 160 | 160 | |
| 161 | 161 | if ($this->cache->exists($status_filename)) |
| 162 | 162 | $status = json_decode($this->cache->get($status_filename), true); |
@@ -176,49 +176,49 @@ discard block |
||
| 176 | 176 | return false; |
| 177 | 177 | } |
| 178 | 178 | |
| 179 | - $doc = new DOMDocument(); |
|
| 179 | + $doc = new DOMDocument(); |
|
| 180 | 180 | |
| 181 | - $has_images = false; |
|
| 182 | - $success = false; |
|
| 181 | + $has_images = false; |
|
| 182 | + $success = false; |
|
| 183 | 183 | |
| 184 | 184 | if ($doc->loadHTML('<?xml encoding="UTF-8">' . $content)) { |
| 185 | - $xpath = new DOMXPath($doc); |
|
| 186 | - $entries = $xpath->query('(//img[@src])|(//video/source[@src])'); |
|
| 185 | + $xpath = new DOMXPath($doc); |
|
| 186 | + $entries = $xpath->query('(//img[@src])|(//video/source[@src])'); |
|
| 187 | 187 | |
| 188 | - foreach ($entries as $entry) { |
|
| 188 | + foreach ($entries as $entry) { |
|
| 189 | 189 | |
| 190 | - if ($entry->hasAttribute('src') && strpos($entry->getAttribute('src'), "data:") !== 0) { |
|
| 190 | + if ($entry->hasAttribute('src') && strpos($entry->getAttribute('src'), "data:") !== 0) { |
|
| 191 | 191 | |
| 192 | - $has_images = true; |
|
| 192 | + $has_images = true; |
|
| 193 | 193 | |
| 194 | - $src = rewrite_relative_url($site_url, $entry->getAttribute('src')); |
|
| 194 | + $src = rewrite_relative_url($site_url, $entry->getAttribute('src')); |
|
| 195 | 195 | |
| 196 | - if ($this->cache_url($article_id, $src)) { |
|
| 197 | - $success = true; |
|
| 198 | - } |
|
| 199 | - } |
|
| 200 | - } |
|
| 201 | - } |
|
| 196 | + if ($this->cache_url($article_id, $src)) { |
|
| 197 | + $success = true; |
|
| 198 | + } |
|
| 199 | + } |
|
| 200 | + } |
|
| 201 | + } |
|
| 202 | 202 | |
| 203 | - $esth = $this->pdo->prepare("SELECT content_url FROM ttrss_enclosures WHERE post_id = ? AND |
|
| 203 | + $esth = $this->pdo->prepare("SELECT content_url FROM ttrss_enclosures WHERE post_id = ? AND |
|
| 204 | 204 | (content_type LIKE '%image%' OR content_type LIKE '%video%')"); |
| 205 | 205 | |
| 206 | 206 | if ($esth->execute([$article_id])) { |
| 207 | - while ($enc = $esth->fetch()) { |
|
| 207 | + while ($enc = $esth->fetch()) { |
|
| 208 | 208 | |
| 209 | - $has_images = true; |
|
| 210 | - $url = rewrite_relative_url($site_url, $enc["content_url"]); |
|
| 209 | + $has_images = true; |
|
| 210 | + $url = rewrite_relative_url($site_url, $enc["content_url"]); |
|
| 211 | 211 | |
| 212 | - if ($this->cache_url($article_id, $url)) { |
|
| 213 | - $success = true; |
|
| 214 | - } |
|
| 215 | - } |
|
| 216 | - } |
|
| 212 | + if ($this->cache_url($article_id, $url)) { |
|
| 213 | + $success = true; |
|
| 214 | + } |
|
| 215 | + } |
|
| 216 | + } |
|
| 217 | 217 | |
| 218 | - return $success || !$has_images; |
|
| 219 | - } |
|
| 218 | + return $success || !$has_images; |
|
| 219 | + } |
|
| 220 | 220 | |
| 221 | - public function api_version() { |
|
| 222 | - return 2; |
|
| 223 | - } |
|
| 221 | + public function api_version() { |
|
| 222 | + return 2; |
|
| 223 | + } |
|
| 224 | 224 | } |