Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
alt-grr committed Feb 21, 2014
0 parents commit 82b26b0
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 0 deletions.
20 changes: 20 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -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.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Af_SoupIo
=========

Tiny Tiny RSS plugin to enlarging images in Soup.io feeds
71 changes: 71 additions & 0 deletions init.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php

class Af_SoupIo extends Plugin {

private $host;

function about() {
return array(1.0,
"Insert larger images in soup.io feeds.",
"kuc");
}

function api_version() {
return 2;
}

function init($host) {
$this->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('<?xml encoding="UTF-8"?>' . $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;
}
}

0 comments on commit 82b26b0

Please sign in to comment.