]> git.mxchange.org Git - friendica.git/blob - theme.php
d2526ed55392e8231a9649476e8ace2d784d0216
[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         register_hook('contact_photo_menu', 'view/theme/frio/theme.php', 'frio_contact_photo_menu');
36         register_hook('nav_info', 'view/theme/frio/theme.php', 'frio_remote_nav');
37
38         logger("installed theme frio");
39 }
40
41 function frio_uninstall() {
42         unregister_hook('prepare_body_final', 'view/theme/frio/theme.php', 'frio_item_photo_links');
43         unregister_hook('item_photo_menu', 'view/theme/frio/theme.php', 'frio_item_photo_menu');
44         unregister_hook('nav_info', 'view/theme/frio/theme.php', 'frio_remote_nav');
45
46         logger("uninstalled theme frio");
47 }
48 /**
49  * @brief Replace friendica photo links
50  * 
51  *  This function does replace the links to photos
52  *  of other friendica users. Original the photos are
53  *  linked to the photo page. Now they will linked directly
54  *  to the photo file. This function is nessesary to use colorbox
55  *  in the network stream
56  * 
57  * @param App $a
58  * @param array $body_info The item and its html output
59  */
60 function frio_item_photo_links(&$a, &$body_info) {
61         require_once('include/Photo.php');
62
63         $phototypes = Photo::supportedTypes();
64         $occurence = 1;
65         $p = bb_find_open_close($body_info['html'], "<a", ">");
66
67         while($p !== false && ($occurence++ < 500)) {
68                 $link = substr($body_info['html'], $p['start'], $p['end'] - $p['start']);
69                 $matches = array();
70
71                 preg_match("/\/photos\/[\w]+\/image\/([\w]+)/", $link, $matches);
72                 if($matches) {
73                         // Replace the link for the photo's page with a direct link to the photo itself
74                         $newlink = str_replace($matches[0], "/photo/{$matches[1]}", $link);
75
76                         // Add a "quiet" parameter to any redir links to prevent the "XX welcomes YY" info boxes
77                         $newlink = preg_replace("/href=\"([^\"]+)\/redir\/([^\"]+)&url=([^\"]+)\"/", 'href="$1/redir/$2&quiet=1&url=$3"', $newlink);
78
79                          // Having any arguments to the link for Colorbox causes it to fetch base64 code instead of the image
80                         $newlink = preg_replace("/\/[?&]zrl=([^&\"]+)/", '', $newlink);
81
82                         $body_info['html'] = str_replace($link, $newlink, $body_info['html']);
83                 }
84
85                 $p = bb_find_open_close($body_info['html'], "<a", ">", $occurence);
86         }
87 }
88
89 /**
90  * @brief Replace links of the item_photo_menu
91  * 
92  *  This function replaces the original poke and the message links
93  *  to call the addToModal javascript function so this pages can
94  *  be loaded in a bootstrap modal
95  * 
96  * @param app $a The app data
97  * @param array $arr Contains item data and the original photo_menu
98  */
99 function frio_item_photo_menu($a, &$arr){
100
101         foreach($arr["menu"] as $k =>$v) {
102                 if(strpos($v,'poke/?f=&c=') === 0 || strpos($v,'message/new/') === 0) {
103                         $v = "javascript:addToModal('" . $v . "'); return false;";
104                         $arr["menu"][$k] = $v;
105                 }
106         }
107         $args = array('item' => $item, 'menu' => $menu);
108 }
109
110 /**
111  * @brief Replace links of the contact_photo_menu
112  * 
113  *  This function replaces the original poke and the message links
114  *  to call the addToModal javascript function so this pages can
115  *  be loaded in a bootstrap modal
116  *  Additionally the profile, status and photo page links  will be changed
117  *  to don't open in a new tab if the contact is a friendica contact.
118  * 
119  * @param app $a The app data
120  * @param array $args Contains contact data and the original photo_menu
121  */
122 function frio_contact_photo_menu($a, &$args){
123
124         $pokelink = "";
125         $pmlink = "";
126         $cid = "";
127
128         $cid = $args["contact"]["id"];
129         $pokelink = $args["menu"]["poke"][1];
130         $pmlink = $args["menu"]["pm"][1];
131
132         // Set the the indicator for opening the status, profile and photo pages
133         // in a new tab to false if the contact a dfrn (friendica) contact
134         // We do this because we can go back on foreign friendica pages throuhg
135         // friendicas "magic-link" which indicates a friendica user on froreign
136         // friendica servers as remote user or visitor
137         //
138         // The value for opening in a new tab is e.g. when 
139         // $args["menu"]["status"][2] is true. If the value of the [2] key is true
140         // and if it's a friendica contact we set it to false
141         foreach($args["menu"] as $k =>$v) {
142                 if($k === "status" || $k === "profile" || $k === "photos") {
143                         $v[2] = (($args["contact"]["network"] === "dfrn") ? false : true);
144                         $args["menu"][$k][2] = $v[2];
145                 }
146         }
147
148         // Add to pm and poke links a new key with the value 'modal'.
149         // Later we can make conditions in the corresponing templates (e.g.
150         // contact_template.tpl)
151         if(strpos($pokelink,'poke/?f=&c='. $cid) !== false)
152                 $args["menu"]["poke"][3] = "modal";
153
154         if(strpos($pmlink,'message/new/' . $cid) !== false)
155                 $args["menu"]["pm"][3] = "modal";
156
157         $args = array('contact' => $contact, 'menu' => &$menu);
158 }
159
160 /**
161  * @brief Construct remote nav menu
162  * 
163  *  It creates a remote baseurl form $_SESSION for remote users and friendica
164  *  visitors. This url will be added to some of the nav links. With this behaviour 
165  *  the user will come back to her/his own pages on his/her friendica server.
166  *  Not all possible links are available (notifications, administrator, manage,
167  *  notes aren't available because we have no way the check remote permissions)..
168  *  Some links will point to the local pages because the user would expect
169  *  local page (these pages are: search, community, help, apps, directory).
170  * 
171  * @param app $a The App class
172  * @param array $nav The original nav menu
173  */
174 function frio_remote_nav($a,&$nav) {
175         // get the homelink from $_XSESSION
176         $homelink = get_my_url();
177         if(! $homelink)
178                 $homelink = ((x($_SESSION,'visitor_home')) ? $_SESSION['visitor_home'] : '');
179
180         // split up the url in it's parts (protocol,domain/directory, /profile/, nickname
181         // I'm not familiar with regex, so someone might find a better solutionen
182         // 
183         // E.g $homelink = 'https://friendica.domain.com/profile/mickey' should result in an array
184         // with 0 => 'https://friendica.domain.com/profile/mickey' 1 => 'https://',
185         // 2 => 'friendica.domain.com' 3 => '/profile/' 4 => 'mickey'
186         // 
187         //$server_url = preg_match('/^(https?:\/\/.*?)\/profile\//2', $homelink);
188         preg_match('/^(https?:\/\/)?(.*?)(\/profile\/)(.*)/', $homelink, $url_parts);
189
190         // Construct the server url of the visitor. So we could link back to his/her own menu.
191         // And construct a webbie (e.g. mickey@friendica.domain.com for the search in gcontact
192         // We use the webbie for search in gcontact because we don't know if gcontact table stores
193         // the right value if its http or https protocol
194         if(count($url_parts)) {
195                 $server_url = $url_parts[1] . $url_parts[2];
196                 $webbie = $url_parts[4] . '@' . $url_parts[2];
197         }
198
199         // since $userinfo isn't available for the hook we write it to the nav array
200         // this isn't optimal because the contact query will be done now twice
201         if(local_user()) {
202                 // empty the server url for local user because we won't need it
203                 $server_url = '';
204                 // user info
205                 $r = q("SELECT `micro` FROM `contact` WHERE `uid` = %d AND `self` = 1", intval($a->user['uid']));
206                 
207                 $r[0]['photo'] = (count($r) ? $a->remove_baseurl($r[0]['micro']) : "images/person-48.jpg");
208                 $r[0]['name'] = $a->user['username'];
209
210         } elseif(!local_user() && remote_user()) {
211                 $r = q("SELECT `name`, `nick`, `micro` AS `photo` FROM `contact` WHERE `id` = %d", intval(remote_user()));
212                 $nav['remote'] = t("Remote");
213
214         } elseif(get_my_url ()) {
215                 $r = q("SELECT `name`, `nick`, `photo` FROM `gcontact`
216                                 WHERE `addr` = '%s' AND `network` = 'dfrn'",
217                         dbesc($webbie));
218                 $nav['remote'] = t("Visitor");
219         }
220
221         if(count($r)){
222                         $nav['userinfo'] = array(
223                                 'icon' => (count($r) ? $r[0]['photo'] : "images/person-48.jpg"),
224                                 'name' => $r[0]['name'],
225                         );
226                 }
227
228         if(!local_user() && !empty($server_url)) {
229                 $nav['logout'] = Array($server_url . '/logout',t('Logout'), "", t('End this session'));
230
231                 // user menu
232                 $nav['usermenu'][] = Array($server_url . '/profile/' . $a->user['nickname'], t('Status'), "", t('Your posts and conversations'));
233                 $nav['usermenu'][] = Array($server_url . '/profile/' . $a->user['nickname']. '?tab=profile', t('Profile'), "", t('Your profile page'));
234                 $nav['usermenu'][] = Array($server_url . '/photos/' . $a->user['nickname'], t('Photos'), "", t('Your photos'));
235                 $nav['usermenu'][] = Array($server_url . '/videos/' . $a->user['nickname'], t('Videos'), "", t('Your videos'));
236                 $nav['usermenu'][] = Array($server_url . '/events/', t('Events'), "", t('Your events'));
237
238                 // navbar links
239                 $nav['network'] = array($server_url . '/network', t('Network'), "", t('Conversations from your friends'));
240                 $nav['events'] = Array($server_url . '/events', t('Events'), "", t('Events and Calendar'));
241                 $nav['messages'] = array($server_url . '/message', t('Messages'), "", t('Private mail'));
242                 $nav['settings'] = array($server_url . '/settings', t('Settings'),"", t('Account settings'));
243                 $nav['contacts'] = array($server_url . '/contacts', t('Contacts'),"", t('Manage/edit friends and contacts'));
244                 $nav['sitename'] = $a->config['sitename'];
245         }
246 }