From cbd007bf380695858bd39c5b6f286efebfd0836a Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Fri, 7 Sep 2018 09:38:11 +0300 Subject: initial --- init.php | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 init.php diff --git a/init.php b/init.php new file mode 100644 index 0000000..90d01a8 --- /dev/null +++ b/init.php @@ -0,0 +1,62 @@ +host = $host; + + $host->add_hook($host::HOOK_RENDER_ARTICLE, $this); + $host->add_hook($host::HOOK_RENDER_ARTICLE_CDM, $this); + } + + function hook_render_article($article) { + return $this->hook_render_article_cdm($article); + } + + function hook_render_article_cdm($article) { + + $doc = new DOMDocument(); + + $found = false; + + if (@$doc->loadHTML($article["content"])) { + + $xpath = new DOMXpath($doc); + $elems = $xpath->query('(//*[@href])'); + + foreach ($elems as $elem) { + $url = $elem->getAttribute("href"); + $local_filename = CACHE_DIR . "/images/" . sha1($url); + + if (file_exists($local_filename) && filesize($local_filename) > 0) { + $local_url = get_self_url_prefix() . '/public.php?op=cached_url&hash=' . sha1($url); + + $elem->setAttribute("href", $local_url); + $elem->nodeValue = ""; + $elem->appendChild($doc->createTextNode($local_url)); + + $found = true; + } + } + } + + if ($found) { + $article["content"] = $doc->saveXML(); + } + + return $article; + } + + + function api_version() { + return 2; + } + +} +?> -- cgit v1.2.3