]> git.mxchange.org Git - friendica-addons.git/blob - convpath/convpath.php
fixing a problem with automatization ;-)
[friendica-addons.git] / convpath / convpath.php
1 <?php
2 /**
3  * Name: Convert Paths
4  * Description: Converts all internal paths according to the current scheme (http or https)
5  * Version: 1.0
6  * Author: Michael Vogel <https://pirati.ca/profile/heluecht>
7  * 
8  */
9
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');
16 }
17
18
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');
25 }
26
27 function convpath_ping_xmlize_hook(&$a, &$o) {
28         $o["photo"] = convpath_url($a, $o["photo"]);
29 }
30
31 function convpath_page_header(&$a, &$o){
32         $o = convpath_convert($o);
33 }
34
35 function convpath_page_end(&$a, &$o){
36         $o = convpath_convert($o);
37         $a->page['aside'] = convpath_convert($a->page['aside']);
38 }
39
40 function convpath_prepare_body_hook(&$a, &$o) {
41         $o["html"] = convpath_convert($o["html"]);
42 }
43
44 function convpath_display_item_hook(&$a, &$o) {
45         if (isset($o["output"])) {
46                 if (isset($o["output"]["thumb"]))
47                         $o["output"]["thumb"] = convpath_url($a, $o["output"]["thumb"]);
48                 if (isset($o["output"]["author-avatar"]))
49                         $o["output"]["author-avatar"] = convpath_url($a, $o["output"]["author-avatar"]);
50                 if (isset($o["output"]["owner-avatar"]))
51                         $o["output"]["owner-avatar"] = convpath_url($a, $o["output"]["owner-avatar"]);
52                 if (isset($o["output"]["owner_photo"]))
53                         $o["output"]["owner_photo"] = convpath_url($a, $o["output"]["owner_photo"]);
54         }
55 }
56
57 function convpath_url($a, $path) {
58         if ($path == "")
59                 return("");
60
61         $ssl = (substr($a->get_baseurl(), 0, 8) == "https://");
62
63         if ($ssl) {
64                 $search = "http://".$a->get_hostname();
65                 $replace = "https://".$a->get_hostname();
66         } else {
67                 $search = "https://".$a->get_hostname();
68                 $replace = "http://".$a->get_hostname();
69         }
70
71         $path = str_replace($search, $replace, $path);
72
73         return($path);
74 }
75
76 /*
77 Converts a given path according to the current scheme
78 */
79 function convpath_convert($path) {
80         global $a;
81
82         if ($path == "")
83                 return("");
84
85         $ssl = (substr($a->get_baseurl(), 0, 8) == "https://");
86
87         if ($ssl) {
88                 $search = "http://".$a->get_hostname();
89                 $replace = "https://".$a->get_hostname();
90         } else {
91                 $search = "https://".$a->get_hostname();
92                 $replace = "http://".$a->get_hostname();
93         }
94         $searcharr = array("src='".$search, 'src="'.$search);
95         $replacearr = array("src='".$replace, 'src="'.$replace);
96         $path = str_replace($searcharr, $replacearr, $path);
97
98         //$path = str_replace($search, $replace, $path);
99
100         return($path);
101 }