From 0568a5d8bbbc81baa237ae262f9025b232279396 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Sun, 16 Mar 2014 19:12:41 +0100 Subject: [PATCH] convpath: changed strategy for url conversion. --- convpath/convpath.php | 46 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/convpath/convpath.php b/convpath/convpath.php index e5dc0b367..950936942 100644 --- a/convpath/convpath.php +++ b/convpath/convpath.php @@ -10,12 +10,22 @@ function convpath_install() { register_hook('page_end', 'addon/convpath/convpath.php', 'convpath_page_end'); register_hook('page_header', 'addon/convpath/convpath.php', 'convpath_page_header'); + register_hook('ping_xmlize', 'addon/convpath/convpath.php', 'convpath_ping_xmlize_hook'); + register_hook('prepare_body', 'addon/convpath/convpath.php', 'convpath_prepare_body_hook'); + register_hook('display_item', 'addon/convpath/convpath.php', 'convpath_display_item_hook'); } function convpath_uninstall() { unregister_hook('page_end', 'addon/convpath/convpath.php', 'convpath_page_end'); unregister_hook('page_header', 'addon/convpath/convpath.php', 'convpath_page_header'); + unregister_hook('ping_xmlize', 'addon/convpath/convpath.php', 'convpath_ping_xmlize_hook'); + unregister_hook('prepare_body', 'addon/convpath/convpath.php', 'convpath_prepare_body_hook'); + unregister_hook('display_item', 'addon/convpath/convpath.php', 'convpath_display_item_hook'); +} + +function convpath_ping_xmlize_hook(&$a, &$o) { + $o["photo"] = convpath_url($a, $o["photo"]); } function convpath_page_header(&$a, &$o){ @@ -27,6 +37,42 @@ function convpath_page_end(&$a, &$o){ $a->page['aside'] = convpath_convert($a->page['aside']); } +function convpath_prepare_body_hook(&$a, &$o) { + $o["html"] = convpath_convert($o["html"]); +} + +function convpath_display_item_hook(&$a, &$o) { + if (isset($o["output"])) { + if (isset($o["output"]["thumb"])) + $o["output"]["thumb"] = convpath_url($a, $o["output"]["thumb"]); + if (isset($o["output"]["author-avatar"])) + $o["output"]["author-avatar"] = convpath_url($a, $o["output"]["author-avatar"]); + if (isset($o["output"]["owner-avatar"])) + $o["output"]["owner-avatar"] = convpath_url($a, $o["output"]["owner-avatar"]); + if (isset($o["output"]["owner_photo"])) + $o["output"]["owner_photo"] = convpath_url($a, $o["output"]["owner_photo"]); + } +} + +function convpath_url($a, $path) { + if ($path == "") + return(""); + + $ssl = (substr($a->get_baseurl(), 0, 8) == "https://"); + + if ($ssl) { + $search = "http://".$a->get_hostname(); + $replace = "https://".$a->get_hostname(); + } else { + $search = "https://".$a->get_hostname(); + $replace = "http://".$a->get_hostname(); + } + + $path = str_replace($search, $replace, $path); + + return($path); +} + /* Converts a given path according to the current scheme */