]> git.mxchange.org Git - friendica.git/blob - view/theme/frio/theme.php
added template for the blocklist editor in the admin panel
[friendica.git] / view / theme / frio / 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/friendica/friendica/tree/develop/view/theme/frio/README.md">ReadMe</a>.
5  * Version: V.0.7
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(App $a) {
15
16         // disable the events module link in the profile tab
17         $a->theme_events_in_profile = false;
18
19         set_template_engine($a, 'smarty3');
20
21         $baseurl = App::get_baseurl();
22
23         $style = get_pconfig(local_user(), 'frio', 'style');
24
25         $frio = "view/theme/frio";
26
27         global $frio;
28
29         // if the device is a mobile device set js is_mobile
30         // variable so the js scripts can use this information
31         if($a->is_mobile || $a->is_tablet) {
32                 $a->page["htmlhead"] .= <<< EOT
33                         <script>
34                                 var is_mobile = 1;
35                         </script>
36 EOT;
37                         }
38
39         if ($style == "")
40                 $style = get_config('frio', 'style');
41 }
42
43 function frio_install() {
44         register_hook('prepare_body_final', 'view/theme/frio/theme.php', 'frio_item_photo_links');
45         register_hook('item_photo_menu', 'view/theme/frio/theme.php', 'frio_item_photo_menu');
46         register_hook('contact_photo_menu', 'view/theme/frio/theme.php', 'frio_contact_photo_menu');
47         register_hook('nav_info', 'view/theme/frio/theme.php', 'frio_remote_nav');
48         register_hook('acl_lookup_end', 'view/theme/frio/theme.php', 'frio_acl_lookup');
49
50         logger("installed theme frio");
51 }
52
53 function frio_uninstall() {
54         unregister_hook('prepare_body_final', 'view/theme/frio/theme.php', 'frio_item_photo_links');
55         unregister_hook('item_photo_menu', 'view/theme/frio/theme.php', 'frio_item_photo_menu');
56         unregister_hook('contact_photo_menu', 'view/theme/frio/theme.php', 'frio_contact_photo_menu');
57         unregister_hook('nav_info', 'view/theme/frio/theme.php', 'frio_remote_nav');
58         unregister_hook('acl_lookup_end', 'view/theme/frio/theme.php', 'frio_acl_lookup');
59
60         logger("uninstalled theme frio");
61 }
62 /**
63  * @brief Replace friendica photo links hook
64  *
65  *  This function does replace the links to photos
66  *  of other friendica users. Original the photos are
67  *  linked to the photo page. Now they will linked directly
68  *  to the photo file. This function is nessesary to use colorbox
69  *  in the network stream
70  *
71  * @param App $a Unused but required by hook definition
72  * @param array $body_info The item and its html output
73  */
74 function frio_item_photo_links(App $a, &$body_info) {
75         require_once('include/Photo.php');
76
77         $phototypes = Photo::supportedTypes();
78         $occurence = 1;
79         $p = bb_find_open_close($body_info['html'], "<a", ">");
80
81         while($p !== false && ($occurence++ < 500)) {
82                 $link = substr($body_info['html'], $p['start'], $p['end'] - $p['start']);
83                 $matches = array();
84
85                 preg_match("/\/photos\/[\w]+\/image\/([\w]+)/", $link, $matches);
86                 if($matches) {
87                         // Replace the link for the photo's page with a direct link to the photo itself
88                         $newlink = str_replace($matches[0], "/photo/{$matches[1]}", $link);
89
90                         // Add a "quiet" parameter to any redir links to prevent the "XX welcomes YY" info boxes
91                         $newlink = preg_replace("/href=\"([^\"]+)\/redir\/([^\"]+)&url=([^\"]+)\"/", 'href="$1/redir/$2&quiet=1&url=$3"', $newlink);
92
93                          // Having any arguments to the link for Colorbox causes it to fetch base64 code instead of the image
94                         $newlink = preg_replace("/\/[?&]zrl=([^&\"]+)/", '', $newlink);
95
96                         $body_info['html'] = str_replace($link, $newlink, $body_info['html']);
97                 }
98
99                 $p = bb_find_open_close($body_info['html'], "<a", ">", $occurence);
100         }
101 }
102
103 /**
104  * @brief Replace links of the item_photo_menu hook
105  *
106  *  This function replaces the original poke and the message links
107  *  to call the addToModal javascript function so this pages can
108  *  be loaded in a bootstrap modal
109  *
110  * @param App $a Unused but required by the hook definition
111  * @param array $arr Contains item data and the original photo_menu
112  */
113 function frio_item_photo_menu(App $a, &$arr) {
114
115         foreach($arr["menu"] as $k =>$v) {
116                 if(strpos($v,'poke/?f=&c=') === 0 || strpos($v,'message/new/') === 0) {
117                         $v = "javascript:addToModal('" . $v . "'); return false;";
118                         $arr["menu"][$k] = $v;
119                 }
120         }
121         $args = array('item' => $item, 'menu' => $menu);
122 }
123
124 /**
125  * @brief Replace links of the contact_photo_menu
126  *
127  *  This function replaces the original poke and the message links
128  *  to call the addToModal javascript function so this pages can
129  *  be loaded in a bootstrap modal
130  *  Additionally the profile, status and photo page links  will be changed
131  *  to don't open in a new tab if the contact is a friendica contact.
132  *
133  * @param app $a The app data
134  * @param array $args Contains contact data and the original photo_menu
135  */
136 function frio_contact_photo_menu(App $a, &$args){
137
138         $pokelink = "";
139         $pmlink = "";
140         $cid = "";
141
142         $cid = $args["contact"]["id"];
143         $pokelink = $args["menu"]["poke"][1];
144         $pmlink = $args["menu"]["pm"][1];
145
146         // Set the the indicator for opening the status, profile and photo pages
147         // in a new tab to false if the contact a dfrn (friendica) contact
148         // We do this because we can go back on foreign friendica pages throuhg
149         // friendicas "magic-link" which indicates a friendica user on froreign
150         // friendica servers as remote user or visitor
151         //
152         // The value for opening in a new tab is e.g. when
153         // $args["menu"]["status"][2] is true. If the value of the [2] key is true
154         // and if it's a friendica contact we set it to false
155         foreach($args["menu"] as $k =>$v) {
156                 if($k === "status" || $k === "profile" || $k === "photos") {
157                         $v[2] = (($args["contact"]["network"] === "dfrn") ? false : true);
158                         $args["menu"][$k][2] = $v[2];
159                 }
160         }
161
162         // Add to pm and poke links a new key with the value 'modal'.
163         // Later we can make conditions in the corresponing templates (e.g.
164         // contact_template.tpl)
165         if(strpos($pokelink,'poke/?f=&c='. $cid) !== false)
166                 $args["menu"]["poke"][3] = "modal";
167
168         if(strpos($pmlink,'message/new/' . $cid) !== false)
169                 $args["menu"]["pm"][3] = "modal";
170
171         $args = array('contact' => $contact, 'menu' => &$menu);
172 }
173
174 /**
175  * @brief Construct remote nav menu
176  *
177  *  It creates a remote baseurl form $_SESSION for remote users and friendica
178  *  visitors. This url will be added to some of the nav links. With this behaviour
179  *  the user will come back to her/his own pages on his/her friendica server.
180  *  Not all possible links are available (notifications, administrator, manage,
181  *  notes aren't available because we have no way the check remote permissions)..
182  *  Some links will point to the local pages because the user would expect
183  *  local page (these pages are: search, community, help, apps, directory).
184  *
185  * @param app $a The App class
186  * @param array $nav The original nav menu
187  */
188 function frio_remote_nav($a,&$nav) {
189         // get the homelink from $_XSESSION
190         $homelink = get_my_url();
191         if(! $homelink)
192                 $homelink = ((x($_SESSION,'visitor_home')) ? $_SESSION['visitor_home'] : '');
193
194         // split up the url in it's parts (protocol,domain/directory, /profile/, nickname
195         // I'm not familiar with regex, so someone might find a better solutionen
196         //
197         // E.g $homelink = 'https://friendica.domain.com/profile/mickey' should result in an array
198         // with 0 => 'https://friendica.domain.com/profile/mickey' 1 => 'https://',
199         // 2 => 'friendica.domain.com' 3 => '/profile/' 4 => 'mickey'
200         //
201         //$server_url = preg_match('/^(https?:\/\/.*?)\/profile\//2', $homelink);
202         preg_match('/^(https?:\/\/)?(.*?)(\/profile\/)(.*)/', $homelink, $url_parts);
203
204         // Construct the server url of the visitor. So we could link back to his/her own menu.
205         // And construct a webbie (e.g. mickey@friendica.domain.com for the search in gcontact
206         // We use the webbie for search in gcontact because we don't know if gcontact table stores
207         // the right value if its http or https protocol
208         if(count($url_parts)) {
209                 $server_url = $url_parts[1] . $url_parts[2];
210                 $webbie = $url_parts[4] . '@' . $url_parts[2];
211         }
212
213         // since $userinfo isn't available for the hook we write it to the nav array
214         // this isn't optimal because the contact query will be done now twice
215         if(local_user()) {
216                 // empty the server url for local user because we won't need it
217                 $server_url = '';
218                 // user info
219                 $r = q("SELECT `micro` FROM `contact` WHERE `uid` = %d AND `self`", intval($a->user['uid']));
220
221                 $r[0]['photo'] = (dbm::is_result($r) ? $a->remove_baseurl($r[0]['micro']) : "images/person-48.jpg");
222                 $r[0]['name'] = $a->user['username'];
223
224         } elseif(!local_user() && remote_user()) {
225                 $r = q("SELECT `name`, `nick`, `micro` AS `photo` FROM `contact` WHERE `id` = %d", intval(remote_user()));
226                 $nav['remote'] = t("Guest");
227
228         } elseif(get_my_url ()) {
229                 $r = q("SELECT `name`, `nick`, `photo` FROM `gcontact`
230                                 WHERE `addr` = '%s' AND `network` = 'dfrn'",
231                         dbesc($webbie));
232                 $nav['remote'] = t("Visitor");
233         }
234
235         if (dbm::is_result($r)){
236                         $nav['userinfo'] = array(
237                                 'icon' => (dbm::is_result($r) ? $r[0]['photo'] : "images/person-48.jpg"),
238                                 'name' => $r[0]['name'],
239                         );
240                 }
241
242         if(!local_user() && !empty($server_url)) {
243                 $nav['logout'] = Array($server_url . '/logout', t('Logout'), "", t('End this session'));
244
245                 // user menu
246                 $nav['usermenu'][] = Array($server_url . '/profile/' . $a->user['nickname'], t('Status'), "", t('Your posts and conversations'));
247                 $nav['usermenu'][] = Array($server_url . '/profile/' . $a->user['nickname']. '?tab=profile', t('Profile'), "", t('Your profile page'));
248                 $nav['usermenu'][] = Array($server_url . '/photos/' . $a->user['nickname'], t('Photos'), "", t('Your photos'));
249                 $nav['usermenu'][] = Array($server_url . '/videos/' . $a->user['nickname'], t('Videos'), "", t('Your videos'));
250                 $nav['usermenu'][] = Array($server_url . '/events/', t('Events'), "", t('Your events'));
251
252                 // navbar links
253                 $nav['network'] = array($server_url . '/network', t('Network'), "", t('Conversations from your friends'));
254                 $nav['events'] = Array($server_url . '/events', t('Events'), "", t('Events and Calendar'));
255                 $nav['messages'] = array($server_url . '/message', t('Messages'), "", t('Private mail'));
256                 $nav['settings'] = array($server_url . '/settings', t('Settings'),"", t('Account settings'));
257                 $nav['contacts'] = array($server_url . '/contacts', t('Contacts'),"", t('Manage/edit friends and contacts'));
258                 $nav['sitename'] = $a->config['sitename'];
259         }
260 }
261 /**
262  * @brief: Search for contacts
263  *
264  * This function search for a users contacts. The code is copied from contact search
265  * in /mod/contacts.php. With this function the contacts will permitted to acl_lookup()
266  * and can grabbed as json. For this we use the type="r". This is usful to to let js
267  * grab the contact data.
268  * We use this to give the data to textcomplete and have a filter function at the
269  * contact page.
270  *
271  * @param App $a The app data @TODO Unused
272  * @param array $results The array with the originals from acl_lookup()
273  */
274 function frio_acl_lookup($a, &$results) {
275         require_once("mod/contacts.php");
276
277         $nets = ((x($_GET,"nets")) ? notags(trim($_GET["nets"])) : "");
278
279         // we introduce a new search type, r should do the same query like it's
280         // done in /mod/contacts for connections
281         if ($results["type"] == "r") {
282                 $searching = false;
283                 if ($search) {
284                         $search_hdr = $search;
285                         $search_txt = dbesc(protect_sprintf(preg_quote($search)));
286                         $searching = true;
287                 }
288                 $sql_extra .= (($searching) ? " AND (`attag` LIKE '%%".dbesc($search_txt)."%%' OR `name` LIKE '%%".dbesc($search_txt)."%%' OR `nick` LIKE '%%".dbesc($search_txt)."%%') " : "");
289
290                 if ($nets) {
291                         $sql_extra .= sprintf(" AND network = '%s' ", dbesc($nets));
292                 }
293
294                 $sql_extra2 = ((($sort_type > 0) && ($sort_type <= CONTACT_IS_FRIEND)) ? sprintf(" AND `rel` = %d ",intval($sort_type)) : '');
295
296
297                 $r = q("SELECT COUNT(*) AS `total` FROM `contact`
298                         WHERE `uid` = %d AND NOT `self` AND NOT `pending` $sql_extra $sql_extra2 ",
299                         intval($_SESSION['uid']));
300                 if (dbm::is_result($r)) {
301                         $total = $r[0]["total"];
302                 }
303
304                 $sql_extra3 = unavailable_networks();
305
306                 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND NOT `self` AND NOT `pending` $sql_extra $sql_extra2 $sql_extra3 ORDER BY `name` ASC LIMIT 100 ",
307                         intval($_SESSION['uid'])
308                 );
309
310                 $contacts = array();
311
312                 if (dbm::is_result($r)) {
313                         foreach ($r as $rr) {
314                                 $contacts[] = _contact_detail_for_template($rr);
315                         }
316                 }
317
318                 $results["items"] = $contacts;
319                 $results["tot"] = $total;
320         }
321 }