]> git.mxchange.org Git - friendica.git/blob - theme.php
af41cb287e1f5f1575dc3fed8560925fbf6ffd23
[friendica.git] / theme.php
1 <?php
2 /*
3  * Name: frio
4  * Description: Bootstrap V3 theme. The theme is currently under construction, so it is far from finished. For further information have a look at the <a href="https://github.com/rabuzarus/frio/blob/master/README.md">ReadMe</a> and <a href="https://github.com/rabuzarus/frio">GitHub</a>.
5  * Version: V.0.1 Alpha
6  * Author: Rabuzarus <https://friendica.kommune4.de/profile/rabuzarus>
7  * 
8  */
9
10 $frio = "view/theme/frio";
11
12 global $frio;
13
14 function frio_init(&$a) {
15         set_template_engine($a, 'smarty3');
16
17         $baseurl = $a->get_baseurl();
18
19         $style = get_pconfig(local_user(), 'frio', 'style');
20
21         $frio = "view/theme/frio";
22
23         global $frio;
24         
25         
26
27
28         if ($style == "")
29                 $style = get_config('frio', 'style');
30 }
31
32 function frio_install() {
33         register_hook('prepare_body_final', 'view/theme/frio/theme.php', 'frio_item_photo_links');
34         register_hook('item_photo_menu', 'view/theme/frio/theme.php', 'frio_item_photo_menu');
35
36         logger("installed theme frio");
37 }
38
39 function frio_uninstall() {
40         unregister_hook('prepare_body_final', 'view/theme/frio/theme.php', 'frio_item_photo_links');
41         unregister_hook('item_photo_menu', 'view/theme/frio/theme.php', 'frio_item_photo_menu');
42
43         logger("uninstalled theme frio");
44 }
45 /**
46  * @brief Replace friendica photo links
47  * 
48  *  This function does replace the links to photos
49  *  of other friendica users. Original the photos are
50  *  linked to the photo page. Now they will linked directly
51  *  to the photo file. This function is nessesary to use colorbox
52  *  in the network stream
53  * 
54  * @param App $a
55  * @param array $body_info The item and its html output
56  */
57 function frio_item_photo_links(&$a, &$body_info) {
58         require_once('include/Photo.php');
59
60         $phototypes = Photo::supportedTypes();
61         $occurence = 1;
62         $p = bb_find_open_close($body_info['html'], "<a", ">");
63
64         while($p !== false && ($occurence++ < 500)) {
65                 $link = substr($body_info['html'], $p['start'], $p['end'] - $p['start']);
66                 $matches = array();
67
68                 preg_match("/\/photos\/[\w]+\/image\/([\w]+)/", $link, $matches);
69                 if($matches) {
70                         // Replace the link for the photo's page with a direct link to the photo itself
71                         $newlink = str_replace($matches[0], "/photo/{$matches[1]}", $link);
72
73                         // Add a "quiet" parameter to any redir links to prevent the "XX welcomes YY" info boxes
74                         $newlink = preg_replace("/href=\"([^\"]+)\/redir\/([^\"]+)&url=([^\"]+)\"/", 'href="$1/redir/$2&quiet=1&url=$3"', $newlink);
75
76                          // Having any arguments to the link for Colorbox causes it to fetch base64 code instead of the image
77                         $newlink = preg_replace("/\/[?&]zrl=([^&\"]+)/", '', $newlink);
78
79                         $body_info['html'] = str_replace($link, $newlink, $body_info['html']);
80                 }
81
82                 $p = bb_find_open_close($body_info['html'], "<a", ">", $occurence);
83         }
84 }
85
86 /**
87  * @brief Replace links of the item_photo_menu
88  * 
89  *  This function replaces the original poke and the message links
90  *  to call the addToModal javascript function so this pages can
91  *  be loaded in a bootstrap modal
92  * 
93  * @param app $a The app data
94  * @param array $arr Contains item data and the original photo_menu
95  */
96 function frio_item_photo_menu($a, &$arr){
97
98         foreach($arr["menu"] as $k =>$v) {
99                 if(strpos($v,'poke/?f=&c=') === 0 || strpos($v,'message/new/') === 0) {
100                         $v = "javascript:addToModal('" . $v . "'); return false;";
101                         $arr["menu"][$k] = $v;
102                         $testvariable = $testvariable+1;
103                 }
104         }
105         $args = array('item' => $item, 'menu' => $menu);
106 }