-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.php
71 lines (56 loc) · 1.61 KB
/
init.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
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;
}
}