]> git.mxchange.org Git - friendica-addons.git/commitdiff
convpath: changed strategy for url conversion.
authorMichael Vogel <icarus@dabo.de>
Sun, 16 Mar 2014 18:12:41 +0000 (19:12 +0100)
committerMichael Vogel <icarus@dabo.de>
Sun, 16 Mar 2014 18:12:41 +0000 (19:12 +0100)
convpath/convpath.php

index e5dc0b36705eb0eb42354c2c5cc460fe64464b4d..9509369420fc4fbbcb5f18c0060dccd8c7587749 100644 (file)
 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
 */