]> git.mxchange.org Git - friendica-addons.git/blob - convpath/convpath.php
Merge commit 'upstream/master'
[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 }
14
15
16 function convpath_uninstall() {
17         unregister_hook('page_end', 'addon/convpath/convpath.php', 'convpath_page_end');
18         unregister_hook('page_header', 'addon/convpath/convpath.php', 'convpath_page_header');
19 }
20
21 function convpath_page_header(&$a, &$o){
22         $o = convpath_convert($o);
23 }
24
25 function convpath_page_end(&$a, &$o){
26         $o = convpath_convert($o);
27         $a->page['aside'] = convpath_convert($a->page['aside']);
28 }
29
30 /*
31 Converts a given path according to the current scheme
32 */
33 function convpath_convert($path) {
34         global $a;
35
36         if ($path == "")
37                 return("");
38
39         $ssl = (substr($a->get_baseurl(), 0, 8) == "https://");
40
41         if ($ssl) {
42                 $search = "http://".$a->get_hostname();
43                 $replace = "https://".$a->get_hostname();
44         } else {
45                 $search = "https://".$a->get_hostname();
46                 $replace = "http://".$a->get_hostname();
47         }
48         $searcharr = array("src='".$search, 'src="'.$search);
49         $replacearr = array("src='".$replace, 'src="'.$replace);
50         $path = str_replace($searcharr, $replacearr, $path);
51
52         //$path = str_replace($search, $replace, $path);
53
54         return($path);
55 }