summaryrefslogtreecommitdiffstats
path: root/articleenhancer/globalarticleenhancer.php
diff options
context:
space:
mode:
Diffstat (limited to 'articleenhancer/globalarticleenhancer.php')
-rw-r--r--articleenhancer/globalarticleenhancer.php70
1 files changed, 0 insertions, 70 deletions
diff --git a/articleenhancer/globalarticleenhancer.php b/articleenhancer/globalarticleenhancer.php
deleted file mode 100644
index e7f5ca177..000000000
--- a/articleenhancer/globalarticleenhancer.php
+++ /dev/null
@@ -1,70 +0,0 @@
-<?php
-/**
- * ownCloud - News
- *
- * This file is licensed under the Affero General Public License version 3 or
- * later. See the COPYING file.
- *
- * @author Alessandro Cosentino <cosenal@gmail.com>
- * @author Bernhard Posselt <dev@bernhard-posselt.com>
- * @copyright Alessandro Cosentino 2012
- * @copyright Bernhard Posselt 2012, 2014
- */
-
-namespace OCA\News\ArticleEnhancer;
-
-use DomDocument;
-use DOMXpath;
-
-use \OCA\News\Db\Item;
-
-
-class GlobalArticleEnhancer implements ArticleEnhancer {
-
-
- /**
- * This method is run after all enhancers and for every item
- */
- public function enhance(Item $item) {
-
- $dom = new DOMDocument();
-
- // wrap it inside a div if there is none to prevent invalid wrapping
- // inside <p> tags
- $body = '<div>' . $item->getBody() . '</div>';
-
- $isOk = @$dom->loadHTML(
- $body, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD
- );
-
- $xpath = new DOMXpath($dom);
-
- // remove youtube autoplay
- // NOTE: PHP supports only XPath 1.0 so no matches() function :(
- $youtubeIframes = "//iframe[contains(@src, 'youtube.com')]";
-
- $elements = $xpath->query($youtubeIframes);
- foreach ($elements as $element) {
-
- // src needs to be matched against regex to prevent false positives
- // and because theres no XPath matches function available
- $src = $element->getAttribute('src');
- $regex = '%^(http://|https://|//)(www\.)?youtube.com/' .
- '.*\?.*autoplay=1.*%i';
-
- if (preg_match($regex, $src)) {
- $replaced = str_replace('autoplay=1', 'autoplay=0', $src);
- $element->setAttribute('src', $replaced);
- }
- }
-
- // save all changes back to the item
- if ($isOk) {
- $item->setBody(trim($dom->saveHTML()));
- }
-
- return $item;
- }
-
-
-} \ No newline at end of file