]> git.mxchange.org Git - friendica.git/blob - view/theme/diabook/theme.php
Merge remote branch 'upstream/master'
[friendica.git] / view / theme / diabook / theme.php
1 <?php
2
3 /*
4  * Name: Diabook
5  * Description: Diabook: report bugs and request here: http://pad.toktan.org/p/diabook or contact me : thomas_bierey@friendica.eu
6  * Version: 
7  * Author: 
8  */
9
10 $a->theme_info = array(
11   'extends' => 'diabook',
12 );
13
14 //profile_side at networkpages
15
16 if($is_url = preg_match ("/\bnetwork\b/i", $_SERVER['REQUEST_URI'])) {
17 //
18
19 $nav['usermenu']=array();
20 $userinfo = null;
21
22 if(local_user()) {
23         
24
25
26 $r = q("SELECT micro FROM contact WHERE uid=%d AND self=1", intval($a->user['uid']));
27                 
28 $userinfo = array(
29                         'icon' => (count($r) ? $r[0]['micro']: $a->get_baseurl()."/images/default-profile-mm.jpg"),
30                         'name' => $a->user['username'],
31                 );      
32         
33 $ps['usermenu'][status] = Array('profile/' . $a->user['nickname'], t('Home'), "", t('Your posts and conversations'));
34 $ps['usermenu'][profile] = Array('profile/' . $a->user['nickname']. '?tab=profile', t('Profile'), "", t('Your profile page'));
35 $ps['usermenu'][photos] = Array('photos/' . $a->user['nickname'], t('Photos'), "", t('Your photos'));
36 $ps['usermenu'][events] = Array('events/', t('Events'), "", t('Your events'));
37 $ps['usermenu'][notes] = Array('notes/', t('Personal notes'), "", t('Your personal photos'));
38 $ps['usermenu'][community] = Array('community/', t('Community'), "", "");
39
40
41 $tpl = get_markup_template('profile_side.tpl');
42
43 $a->page['aside'] .= replace_macros($tpl, array(
44                 '$userinfo' => $userinfo,
45                 '$ps' => $ps,
46         ));
47
48 }
49
50 //right_aside at networkpages
51
52 // last 12 users
53         $aside['$lastusers_title'] = t('Last users');
54         $aside['$lastusers_items'] = array();
55         $sql_extra = "";
56         $publish = (get_config('system','publish_all') ? '' : " AND `publish` = 1 " );
57         $order = " ORDER BY `register_date` DESC ";
58
59         $r = q("SELECT `profile`.*, `profile`.`uid` AS `profile_uid`, `user`.`nickname`
60                         FROM `profile` LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid` 
61                         WHERE `is-default` = 1 $publish AND `user`.`blocked` = 0 $sql_extra $order LIMIT %d , %d ",
62                 0,
63                 12
64         );
65         $tpl = file_get_contents( dirname(__file__).'/directory_item.tpl');
66         if(count($r)) {
67                 $photo = 'thumb';
68                 foreach($r as $rr) {
69                         $profile_link = $a->get_baseurl() . '/profile/' . ((strlen($rr['nickname'])) ? $rr['nickname'] : $rr['profile_uid']);
70                         $entry = replace_macros($tpl,array(
71                                 '$id' => $rr['id'],
72                                 '$profile-link' => $profile_link,
73                                 '$photo' => $rr[$photo],
74                                 '$alt-text' => $rr['name'],
75                         ));
76                         $aside['$lastusers_items'][] = $entry;
77                 }
78         }
79         
80 // last 10 liked items
81         $aside['$like_title'] = t('Last likes');
82         $aside['$like_items'] = array();
83         $r = q("SELECT `T1`.`created`, `T1`.`liker`, `T1`.`liker-link`, `item`.* FROM 
84                         (SELECT `parent-uri`, `created`, `author-name` AS `liker`,`author-link` AS `liker-link` 
85                                 FROM `item` WHERE `verb`='http://activitystrea.ms/schema/1.0/like' GROUP BY `parent-uri` ORDER BY `created` DESC) AS T1
86                         INNER JOIN `item` ON `item`.`uri`=`T1`.`parent-uri` 
87                         WHERE `T1`.`liker-link` LIKE '%s%%' OR `item`.`author-link` LIKE '%s%%'
88                         GROUP BY `uri`
89                         ORDER BY `T1`.`created` DESC
90                         LIMIT 0,10",
91                         $a->get_baseurl(),$a->get_baseurl()
92                         );
93
94         foreach ($r as $rr) {
95                 $author  = '<a href="' . $rr['liker-link'] . '">' . $rr['liker'] . '</a>';
96                 $objauthor =  '<a href="' . $rr['author-link'] . '">' . $rr['author-name'] . '</a>';
97                 
98                 //var_dump($rr['verb'],$rr['object-type']); killme();
99                 switch($rr['verb']){
100                         case 'http://activitystrea.ms/schema/1.0/post':
101                                 switch ($rr['object-type']){
102                                         case 'http://activitystrea.ms/schema/1.0/event':
103                                                 $post_type = t('event');
104                                                 break;
105                                         default:
106                                                 $post_type = t('status');
107                                 }
108                                 break;
109                         default:
110                                 if ($rr['resource-id']){
111                                         $post_type = t('photo');
112                                         $m=array();     preg_match("/\[url=([^]]*)\]/", $rr['body'], $m);
113                                         $rr['plink'] = $m[1];
114                                 } else {
115                                         $post_type = t('status');
116                                 }
117                 }
118                 $plink = '<a href="' . $rr['plink'] . '">' . $post_type . '</a>';
119
120                 $aside['$like_items'][] = sprintf( t('%1$s likes %2$s\'s %3$s'), $author, $objauthor, $plink);
121                 
122         }
123 // last 12 photos
124         $aside['$photos_title'] = t('Last photos');
125         $aside['$photos_items'] = array();
126         $r = q("SELECT `photo`.`id`, `photo`.`resource-id`, `photo`.`scale`, `photo`.`desc`, `user`.`nickname`, `user`.`username` FROM 
127                                 (SELECT `resource-id`, MAX(`scale`) as maxscale FROM `photo` 
128                                         WHERE `profile`=0 AND `contact-id`=0 AND `album` NOT IN ('Contact Photos', '%s', 'Profile Photos', '%s')
129                                                 AND `allow_cid`='' AND `allow_gid`='' AND `deny_cid`='' AND `deny_gid`='' GROUP BY `resource-id`) AS `t1`
130                                 INNER JOIN `photo` ON `photo`.`resource-id`=`t1`.`resource-id` AND `photo`.`scale` = `t1`.`maxscale`,
131                                 `user` 
132                                 WHERE `user`.`uid` = `photo`.`uid`
133                                 AND `user`.`blockwall`=0
134                                 ORDER BY `photo`.`edited` DESC
135                                 LIMIT 0, 12",
136                                 dbesc(t('Contact Photos')),
137                                 dbesc(t('Profile Photos'))
138                                 );
139                 if(count($r)) {
140                 $tpl = file_get_contents( dirname(__file__).'/directory_item.tpl');
141                 foreach($r as $rr) {
142                         $photo_page = $a->get_baseurl() . '/photos/' . $rr['nickname'] . '/image/' . $rr['resource-id'];
143                         $photo_url = $a->get_baseurl() . '/photo/' .  $rr['resource-id'] . '-' . $rr['scale'] .'.jpg';
144                 
145                         $entry = replace_macros($tpl,array(
146                                 '$id' => $rr['id'],
147                                 '$profile-link' => $photo_page,
148                                 '$photo' => $photo_url,
149                                 '$alt-text' => $rr['username']." : ".$rr['desc'],
150                         ));
151
152                         $aside['$photos_items'][] = $entry;
153                 }
154         }
155         
156
157         $tpl = file_get_contents(dirname(__file__).'/communityhome.tpl');
158         $a->page['right_aside'] = replace_macros($tpl, $aside);
159         
160 }
161
162 //right_aside at profile pages
163
164 if($is_url = preg_match ("/\bprofile\b/i", $_SERVER['REQUEST_URI'])) {
165 //right_aside
166
167 // last 12 users
168         $aside['$lastusers_title'] = t('Last users');
169         $aside['$lastusers_items'] = array();
170         $sql_extra = "";
171         $publish = (get_config('system','publish_all') ? '' : " AND `publish` = 1 " );
172         $order = " ORDER BY `register_date` DESC ";
173
174         $r = q("SELECT `profile`.*, `profile`.`uid` AS `profile_uid`, `user`.`nickname`
175                         FROM `profile` LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid` 
176                         WHERE `is-default` = 1 $publish AND `user`.`blocked` = 0 $sql_extra $order LIMIT %d , %d ",
177                 0,
178                 12
179         );
180         $tpl = file_get_contents( dirname(__file__).'/directory_item.tpl');
181         if(count($r)) {
182                 $photo = 'thumb';
183                 foreach($r as $rr) {
184                         $profile_link = $a->get_baseurl() . '/profile/' . ((strlen($rr['nickname'])) ? $rr['nickname'] : $rr['profile_uid']);
185                         $entry = replace_macros($tpl,array(
186                                 '$id' => $rr['id'],
187                                 '$profile-link' => $profile_link,
188                                 '$photo' => $rr[$photo],
189                                 '$alt-text' => $rr['name'],
190                         ));
191                         $aside['$lastusers_items'][] = $entry;
192                 }
193         }
194         
195 // last 10 liked items
196         $aside['$like_title'] = t('Last likes');
197         $aside['$like_items'] = array();
198         $r = q("SELECT `T1`.`created`, `T1`.`liker`, `T1`.`liker-link`, `item`.* FROM 
199                         (SELECT `parent-uri`, `created`, `author-name` AS `liker`,`author-link` AS `liker-link` 
200                                 FROM `item` WHERE `verb`='http://activitystrea.ms/schema/1.0/like' GROUP BY `parent-uri` ORDER BY `created` DESC) AS T1
201                         INNER JOIN `item` ON `item`.`uri`=`T1`.`parent-uri` 
202                         WHERE `T1`.`liker-link` LIKE '%s%%' OR `item`.`author-link` LIKE '%s%%'
203                         GROUP BY `uri`
204                         ORDER BY `T1`.`created` DESC
205                         LIMIT 0,10",
206                         $a->get_baseurl(),$a->get_baseurl()
207                         );
208
209         foreach ($r as $rr) {
210                 $author  = '<a href="' . $rr['liker-link'] . '">' . $rr['liker'] . '</a>';
211                 $objauthor =  '<a href="' . $rr['author-link'] . '">' . $rr['author-name'] . '</a>';
212                 
213                 //var_dump($rr['verb'],$rr['object-type']); killme();
214                 switch($rr['verb']){
215                         case 'http://activitystrea.ms/schema/1.0/post':
216                                 switch ($rr['object-type']){
217                                         case 'http://activitystrea.ms/schema/1.0/event':
218                                                 $post_type = t('event');
219                                                 break;
220                                         default:
221                                                 $post_type = t('status');
222                                 }
223                                 break;
224                         default:
225                                 if ($rr['resource-id']){
226                                         $post_type = t('photo');
227                                         $m=array();     preg_match("/\[url=([^]]*)\]/", $rr['body'], $m);
228                                         $rr['plink'] = $m[1];
229                                 } else {
230                                         $post_type = t('status');
231                                 }
232                 }
233                 $plink = '<a href="' . $rr['plink'] . '">' . $post_type . '</a>';
234
235                 $aside['$like_items'][] = sprintf( t('%1$s likes %2$s\'s %3$s'), $author, $objauthor, $plink);
236                 
237         }
238 // last 12 photos
239         $aside['$photos_title'] = t('Last photos');
240         $aside['$photos_items'] = array();
241         $r = q("SELECT `photo`.`id`, `photo`.`resource-id`, `photo`.`scale`, `photo`.`desc`, `user`.`nickname`, `user`.`username` FROM 
242                                 (SELECT `resource-id`, MAX(`scale`) as maxscale FROM `photo` 
243                                         WHERE `profile`=0 AND `contact-id`=0 AND `album` NOT IN ('Contact Photos', '%s', 'Profile Photos', '%s')
244                                                 AND `allow_cid`='' AND `allow_gid`='' AND `deny_cid`='' AND `deny_gid`='' GROUP BY `resource-id`) AS `t1`
245                                 INNER JOIN `photo` ON `photo`.`resource-id`=`t1`.`resource-id` AND `photo`.`scale` = `t1`.`maxscale`,
246                                 `user` 
247                                 WHERE `user`.`uid` = `photo`.`uid`
248                                 AND `user`.`blockwall`=0
249                                 ORDER BY `photo`.`edited` DESC
250                                 LIMIT 0, 12",
251                                 dbesc(t('Contact Photos')),
252                                 dbesc(t('Profile Photos'))
253                                 );
254                 if(count($r)) {
255                 $tpl = file_get_contents( dirname(__file__).'/directory_item.tpl');
256                 foreach($r as $rr) {
257                         $photo_page = $a->get_baseurl() . '/photos/' . $rr['nickname'] . '/image/' . $rr['resource-id'];
258                         $photo_url = $a->get_baseurl() . '/photo/' .  $rr['resource-id'] . '-' . $rr['scale'] .'.jpg';
259                 
260                         $entry = replace_macros($tpl,array(
261                                 '$id' => $rr['id'],
262                                 '$profile-link' => $photo_page,
263                                 '$photo' => $photo_url,
264                                 '$alt-text' => $rr['username']." : ".$rr['desc'],
265                         ));
266
267                         $aside['$photos_items'][] = $entry;
268                 }
269         }
270         
271
272         $tpl = file_get_contents(dirname(__file__).'/communityhome.tpl');
273         $a->page['right_aside'] = replace_macros($tpl, $aside);
274         
275 }
276
277 //change css on network and profilepages
278 $cssFile = null;
279
280 if($is_url = preg_match ("/\bnetwork\b/i", $_SERVER['REQUEST_URI'])) {
281         $cssFile = $a->get_baseurl($ssl_state)."/view/theme/diabook/style-network.css";
282         }
283         
284 if($is_url = preg_match ("/\bprofile\b/i", $_SERVER['REQUEST_URI'])) {
285                 $cssFile = $a->get_baseurl($ssl_state)."/view/theme/diabook/style-profile.css";
286                 }
287                 
288
289
290 //js scripts
291 $a->page['htmlhead'] .= <<< EOT
292
293 <link rel="stylesheet" type="text/css" href="$cssFile" />
294
295 <script>
296
297 //contacts
298 $('html').click(function() {
299  $('#nav-contacts-linkmenu').removeClass('selected');
300  document.getElementById( "nav-contacts-menu" ).style.display = "none";
301  });
302  
303  $('#nav-contacts-linkmenu').click(function(event){
304      event.stopPropagation();
305  });
306
307 //messages
308 $('html').click(function() {
309  $('#nav-messages-linkmenu').removeClass('selected');
310  document.getElementById( "nav-messages-menu" ).style.display = "none";
311  });
312
313  $('#nav-messages-linkmenu').click(function(event){
314      event.stopPropagation();
315  });
316
317 //notifications
318 $('html').click(function() {
319  $('#nav-notifications-linkmenu').removeClass('selected');
320  document.getElementById( "nav-notifications-menu" ).style.display = "none";
321  });
322
323  $('#nav-notifications-linkmenu').click(function(event){
324      event.stopPropagation();
325  });
326
327 //usermenu
328 $('html').click(function() {
329  $('#nav-user-linkmenu').removeClass('selected');
330  document.getElementById( "nav-user-menu" ).style.display = "none";
331  });
332
333  $('#nav-user-linkmenu').click(function(event){
334      event.stopPropagation();
335  });
336  
337  //settingsmenu
338  $('html').click(function() {
339  $('#nav-site-linkmenu').removeClass('selected');
340  document.getElementById( "nav-site-menu" ).style.display = "none";
341  });
342
343  $('#nav-site-linkmenu').click(function(event){
344      event.stopPropagation();
345  });
346  //appsmenu
347  $('html').click(function() {
348  $('#nav-apps-link').removeClass('selected');
349  document.getElementById( "nav-apps-menu" ).style.display = "none";
350  });
351
352  $('#nav-apps-link').click(function(event){
353      event.stopPropagation();
354  });
355  
356  $(function() {
357         $('a.lightbox').fancybox(); // Select all links with lightbox class
358 });
359
360  
361  </script>
362 EOT;