4 * Description: Converts all internal paths according to the current scheme (http or https)
6 * Author: Michael Vogel <https://pirati.ca/profile/heluecht>
10 function convpath_install() {
11 register_hook('page_end', 'addon/convpath/convpath.php', 'convpath_page_end');
12 register_hook('page_header', 'addon/convpath/convpath.php', 'convpath_page_header');
13 register_hook('ping_xmlize', 'addon/convpath/convpath.php', 'convpath_ping_xmlize_hook');
14 register_hook('prepare_body', 'addon/convpath/convpath.php', 'convpath_prepare_body_hook');
15 register_hook('display_item', 'addon/convpath/convpath.php', 'convpath_display_item_hook');
19 function convpath_uninstall() {
20 unregister_hook('page_end', 'addon/convpath/convpath.php', 'convpath_page_end');
21 unregister_hook('page_header', 'addon/convpath/convpath.php', 'convpath_page_header');
22 unregister_hook('ping_xmlize', 'addon/convpath/convpath.php', 'convpath_ping_xmlize_hook');
23 unregister_hook('prepare_body', 'addon/convpath/convpath.php', 'convpath_prepare_body_hook');
24 unregister_hook('display_item', 'addon/convpath/convpath.php', 'convpath_display_item_hook');
27 function convpath_ping_xmlize_hook(&$a, &$o) {
28 $o["photo"] = convpath_url($a, $o["photo"]);
31 function convpath_page_header(&$a, &$o){
32 $o = convpath_convert($o);
35 function convpath_page_end(&$a, &$o){
36 $o = convpath_convert($o);
37 if (isset($a->page['aside']))
38 $a->page['aside'] = convpath_convert($a->page['aside']);
41 function convpath_prepare_body_hook(&$a, &$o) {
42 $o["html"] = convpath_convert($o["html"]);
45 function convpath_display_item_hook(&$a, &$o) {
46 if (isset($o["output"])) {
47 if (isset($o["output"]["thumb"]))
48 $o["output"]["thumb"] = convpath_url($a, $o["output"]["thumb"]);
49 if (isset($o["output"]["author-avatar"]))
50 $o["output"]["author-avatar"] = convpath_url($a, $o["output"]["author-avatar"]);
51 if (isset($o["output"]["owner-avatar"]))
52 $o["output"]["owner-avatar"] = convpath_url($a, $o["output"]["owner-avatar"]);
53 if (isset($o["output"]["owner_photo"]))
54 $o["output"]["owner_photo"] = convpath_url($a, $o["output"]["owner_photo"]);
58 function convpath_url($a, $path) {
62 $ssl = (substr($a->get_baseurl(), 0, 8) == "https://");
65 $search = "http://".$a->get_hostname();
66 $replace = "https://".$a->get_hostname();
68 $search = "https://".$a->get_hostname();
69 $replace = "http://".$a->get_hostname();
72 $path = str_replace($search, $replace, $path);
78 Converts a given path according to the current scheme
80 function convpath_convert($path) {
86 $ssl = (substr($a->get_baseurl(), 0, 8) == "https://");
89 $search = "http://".$a->get_hostname();
90 $replace = "https://".$a->get_hostname();
92 $search = "https://".$a->get_hostname();
93 $replace = "http://".$a->get_hostname();
95 $searcharr = array("src='".$search, 'src="'.$search);
96 $replacearr = array("src='".$replace, 'src="'.$replace);
97 $path = str_replace($searcharr, $replacearr, $path);
99 //$path = str_replace($search, $replace, $path);