From 82b26b0b3699b788c23e5c6a5430cbcf7e19d6e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mi=C5=82osz?= Date: Fri, 21 Feb 2014 21:00:58 +0100 Subject: [PATCH] Initial commit --- LICENSE | 20 ++++++++++++++++ README.md | 4 ++++ init.php | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 95 insertions(+) create mode 100644 LICENSE create mode 100644 README.md create mode 100644 init.php diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..43797c0 --- /dev/null +++ b/LICENSE @@ -0,0 +1,20 @@ +The MIT License (MIT) + +Copyright (c) 2014 kuc + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..8c84d1d --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +Af_SoupIo +========= + +Tiny Tiny RSS plugin to enlarging images in Soup.io feeds diff --git a/init.php b/init.php new file mode 100644 index 0000000..edc531a --- /dev/null +++ b/init.php @@ -0,0 +1,71 @@ +host = $host; + $host->add_hook($host::HOOK_ARTICLE_FILTER, $this); + } + + function hook_article_filter($article) { + $owner_uid = $article["owner_uid"]; + + if (strpos($article["link"], "soup.io") !== FALSE) { + if (strpos($article["plugin_data"], "soupio,$owner_uid:") === FALSE) { + + $doc = new DOMDocument(); + @$doc->loadHTML('' . $article["content"]); + + if ($doc) { + $xpath = new DOMXPath($doc); + $entries = $xpath->query('(//img[@alt])'); + + $basenode = false; + + foreach ($entries as $entry) { + // mark that image was found + $basenode = $entry->parentNode; + + // remove width and height + $width = $entry->getAttributeNode("width"); + if ($width) { + $entry->removeAttributeNode($width); + } + $height = $entry->getAttributeNode("height"); + if ($height) { + $entry->removeAttributeNode($height); + } + + // replace src + $src = $entry->getAttribute("src"); + $src = str_replace('_400.', '.', $src); + $entry->setAttribute("src", $src); + break; + } + + if($basenode) { + $doc->removeChild($doc->firstChild); + $article["content"] = $doc->saveHTML(); + $article["plugin_data"] = "soupio,$owner_uid:" . $article["plugin_data"]; + } + } + } else if (isset($article["stored"]["content"])) { + $article["content"] = $article["stored"]["content"]; + } + } + + return $article; + } +}