]> git.mxchange.org Git - friendica.git/blob - view/theme/diabook-aerith/theme.php
Merge branch 'master' of https://github.com/friendica/friendica
[friendica.git] / view / theme / diabook-aerith / theme.php
1 <?php
2
3 /*
4  * Name: Diabook-aerith
5  * Description: Diabook-aerith : report bugs and request here: http://pad.toktan.org/p/diabook or contact me : thomas_bierey@friendica.eu
6  * Version: (Version: 1.015)
7  * Author: 
8  */
9
10
11 //print diabook-version for debugging
12 $diabook_version = "Diabook-aerith (Version: 1.015)";
13 $a->page['htmlhead'] .= sprintf('<script "%s" ></script>', $diabook_version);
14
15
16 //change css on network and profilepages
17 $cssFile = null;
18
19
20 /**
21  * prints last community activity
22  */
23 function diabook_aerith_community_info(){
24         $a = get_app();
25         //right_aside at networkpages
26
27         // last 12 users
28         $aside['$lastusers_title'] = t('Last users');
29         $aside['$lastusers_items'] = array();
30         $sql_extra = "";
31         $publish = (get_config('system','publish_all') ? '' : " AND `publish` = 1 " );
32         $order = " ORDER BY `register_date` DESC ";
33
34         $r = q("SELECT `profile`.*, `profile`.`uid` AS `profile_uid`, `user`.`nickname`
35                         FROM `profile` LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid` 
36                         WHERE `is-default` = 1 $publish AND `user`.`blocked` = 0 $sql_extra $order LIMIT %d , %d ",
37                 0,
38                 9
39         );
40         $tpl = file_get_contents( dirname(__file__).'/directory_item.tpl');
41         if(count($r)) {
42                 $photo = 'thumb';
43                 foreach($r as $rr) {
44                         $profile_link = $a->get_baseurl() . '/profile/' . ((strlen($rr['nickname'])) ? $rr['nickname'] : $rr['profile_uid']);
45                         $entry = replace_macros($tpl,array(
46                                 '$id' => $rr['id'],
47                                 '$profile-link' => $profile_link,
48                                 '$photo' => $rr[$photo],
49                                 '$alt-text' => $rr['name'],
50                         ));
51                         $aside['$lastusers_items'][] = $entry;
52                 }
53         }
54         
55         
56         // last 10 liked items
57         $aside['$like_title'] = t('Last likes');
58         $aside['$like_items'] = array();
59         $r = q("SELECT `T1`.`created`, `T1`.`liker`, `T1`.`liker-link`, `item`.* FROM 
60                         (SELECT `parent-uri`, `created`, `author-name` AS `liker`,`author-link` AS `liker-link` 
61                                 FROM `item` WHERE `verb`='http://activitystrea.ms/schema/1.0/like' GROUP BY `parent-uri` ORDER BY `created` DESC) AS T1
62                         INNER JOIN `item` ON `item`.`uri`=`T1`.`parent-uri` 
63                         WHERE `T1`.`liker-link` LIKE '%s%%' OR `item`.`author-link` LIKE '%s%%'
64                         GROUP BY `uri`
65                         ORDER BY `T1`.`created` DESC
66                         LIMIT 0,5",
67                         $a->get_baseurl(),$a->get_baseurl()
68                         );
69
70         foreach ($r as $rr) {
71                 $author  = '<a href="' . $rr['liker-link'] . '">' . $rr['liker'] . '</a>';
72                 $objauthor =  '<a href="' . $rr['author-link'] . '">' . $rr['author-name'] . '</a>';
73                 
74                 //var_dump($rr['verb'],$rr['object-type']); killme();
75                 switch($rr['verb']){
76                         case 'http://activitystrea.ms/schema/1.0/post':
77                                 switch ($rr['object-type']){
78                                         case 'http://activitystrea.ms/schema/1.0/event':
79                                                 $post_type = t('event');
80                                                 break;
81                                         default:
82                                                 $post_type = t('status');
83                                 }
84                                 break;
85                         default:
86                                 if ($rr['resource-id']){
87                                         $post_type = t('photo');
88                                         $m=array();     preg_match("/\[url=([^]]*)\]/", $rr['body'], $m);
89                                         $rr['plink'] = $m[1];
90                                 } else {
91                                         $post_type = t('status');
92                                 }
93                 }
94                 $plink = '<a href="' . $rr['plink'] . '">' . $post_type . '</a>';
95
96                 $aside['$like_items'][] = sprintf( t('%1$s likes %2$s\'s %3$s'), $author, $objauthor, $plink);
97                 
98         }
99         
100         
101         // last 12 photos
102         $aside['$photos_title'] = t('Last photos');
103         $aside['$photos_items'] = array();
104         $r = q("SELECT `photo`.`id`, `photo`.`resource-id`, `photo`.`scale`, `photo`.`desc`, `user`.`nickname`, `user`.`username` FROM 
105                                 (SELECT `resource-id`, MAX(`scale`) as maxscale FROM `photo` 
106                                         WHERE `profile`=0 AND `contact-id`=0 AND `album` NOT IN ('Contact Photos', '%s', 'Profile Photos', '%s')
107                                                 AND `allow_cid`='' AND `allow_gid`='' AND `deny_cid`='' AND `deny_gid`='' GROUP BY `resource-id`) AS `t1`
108                                 INNER JOIN `photo` ON `photo`.`resource-id`=`t1`.`resource-id` AND `photo`.`scale` = `t1`.`maxscale`,
109                                 `user` 
110                                 WHERE `user`.`uid` = `photo`.`uid`
111                                 AND `user`.`blockwall`=0
112                                 AND `user`.`hidewall`=0
113                                 ORDER BY `photo`.`edited` DESC
114                                 LIMIT 0, 9",
115                                 dbesc(t('Contact Photos')),
116                                 dbesc(t('Profile Photos'))
117                                 );
118                 if(count($r)) {
119                 $tpl = file_get_contents( dirname(__file__).'/directory_item.tpl');
120                 foreach($r as $rr) {
121                         $photo_page = $a->get_baseurl() . '/photos/' . $rr['nickname'] . '/image/' . $rr['resource-id'];
122                         $photo_url = $a->get_baseurl() . '/photo/' .  $rr['resource-id'] . '-' . $rr['scale'] .'.jpg';
123                 
124                         $entry = replace_macros($tpl,array(
125                                 '$id' => $rr['id'],
126                                 '$profile-link' => $photo_page,
127                                 '$photo' => $photo_url,
128                                 '$alt-text' => $rr['username']." : ".$rr['desc'],
129                         ));
130
131                         $aside['$photos_items'][] = $entry;
132                 }
133         }
134         
135         $fostitJS = "javascript: (function() {
136                                         the_url = '".$a->get_baseurl($ssl_state)."/view/theme/diabook-aerith/fpostit/fpostit.php?url=' + encodeURIComponent(window.location.href) + '&title=' + encodeURIComponent(document.title) + '&text=' + encodeURIComponent(''+(window.getSelection ? window.getSelection() : document.getSelection ? document.getSelection() : document.selection.createRange().text));
137                                                 a_funct = function() {
138                                                         if (!window.open(the_url, 'fpostit', 'location=yes,links=no,scrollbars=no,toolbar=no,width=600,height=300')) location.href = the_url};
139                                                         if (/Firefox/.test(navigator.userAgent)) {setTimeout(a_funct, 0)} 
140                                                         else {a_funct()}})()" ;
141   
142    $aside['$fostitJS'] = $fostitJS;
143    
144    //nav FIND FRIENDS
145         if(local_user()) {
146         $nv = array();
147    $nv['title'] = Array("", t('Find Friends'), "", "");
148         $nv['directory'] = Array('directory', t('Local Directory'), "", "");
149         $nv['global_directory'] = Array('http://dir.friendica.com/', t('Global Directory'), "", "");
150         $nv['match'] = Array('match', t('Similar Interests'), "", "");
151         $nv['suggest'] = Array('suggest', t('Friend Suggestions'), "", "");
152         $nv['invite'] = Array('invite', t('Invite Friends'), "", "");
153         
154         $nv['search'] = '<form name="simple_bar" method="get" action="http://dir.friendika.com/directory">
155                                                 <span class="sbox_l"></span>
156                                                 <span class="sbox">
157                                                 <input type="text" name="search" size="13" maxlength="50">
158                                                 </span>
159                                                 <span class="sbox_r" id="srch_clear"></span>';
160                                                 
161         $aside['$nv'] = $nv;
162         };
163         //Community Page
164         if(local_user()) {
165    $page = '<div id="page-sidebar-right_aside" class="widget">
166                         <div class="title tool">
167                         <h3>'.t("Community Pages").'<a id="close_pages_icon"  onClick="close_pages()" class="icon close_box" title="close"></a></h3></div>
168                         <div id="sidebar-page-list"><ul>';
169
170         $pagelist = array();
171
172         $contacts = q("SELECT `id`, `url`, `name`, `micro`FROM `contact`
173                         WHERE `network`= 'dfrn' AND `forum` = 1 AND `uid` = %d
174                         ORDER BY `name` ASC",
175                         intval($a->user['uid'])
176         );
177
178         $pageD = array();
179
180         // Look if the profile is a community page
181         foreach($contacts as $contact) {
182                 $pageD[] = array("url"=>$contact["url"], "name"=>$contact["name"], "id"=>$contact["id"], "micro"=>$contact['micro']);
183         };
184         
185
186         $contacts = $pageD;
187
188         foreach($contacts as $contact) {
189                 $page .= '<li style="list-style-type: none;" class="tool"><img height="20" width="20" style="float: left; margin-right: 3px;" src="' . $contact['micro'] .'" alt="' . $contact['url'] . '" /> <a href="'.$a->get_baseurl().'/redir/'.$contact["id"].'" style="margin-top: 2px;" title="' . $contact['url'] . '" class="label" target="external-link">'.
190                                 $contact["name"]."</a></li>";
191         }
192         $page .= '</ul></div></div>';
193         //if (sizeof($contacts) > 0)
194                 
195                 $aside['$page'] = $page;
196         }               
197   //END Community Page  
198   //helpers
199    $helpers = array();
200         $helpers['title'] = Array("", t('Help or @NewHere ?'), "", "");
201         
202         $aside['$helpers'] = $helpers;
203    //end helpers
204    //connectable services
205    $con_services = array();
206         $con_services['title'] = Array("", t('Connect Services'), "", "");
207         
208         $aside['$con_services'] = $con_services;
209    //end connectable services
210    //postit
211    $postit = array();
212         $postit['title'] = Array("", t('PostIt to Friendica'), t('Post to Friendica'), "");
213         $postit['text'] = Array("", t(' from anywhere by bookmarking this Link.'), "", "");
214         
215         $aside['$postit'] = $postit;
216    //end postit
217   
218    //get_baseurl              
219    $url = $a->get_baseurl($ssl_state);   
220    $aside['$url'] = $url;
221
222         $tpl = file_get_contents(dirname(__file__).'/communityhome.tpl');
223         $a->page['right_aside'] = replace_macros($tpl, $aside);
224         
225 }
226
227
228 //profile_side at networkpages
229 if ($a->argv[0] === "network" && local_user()){
230
231         // USER MENU
232         if(local_user()) {
233                 
234                 $r = q("SELECT micro FROM contact WHERE uid=%d AND self=1", intval($a->user['uid']));
235                                 
236                 $userinfo = array(
237                                         'icon' => (count($r) ? $r[0]['micro']: $a->get_baseurl()."/images/default-profile-mm.jpg"),
238                                         'name' => $a->user['username'],
239                                 );      
240                 $ps = array('usermenu'=>array());
241                 $ps['usermenu']['status'] = Array('profile/' . $a->user['nickname'], t('Home'), "", t('Your posts and conversations'));
242                 $ps['usermenu']['profile'] = Array('profile/' . $a->user['nickname']. '?tab=profile', t('Profile'), "", t('Your profile page'));
243                 $ps['usermenu']['contacts'] = Array('contacts' , t('Contacts'), "", t('Your contacts'));                
244                 $ps['usermenu']['photos'] = Array('photos/' . $a->user['nickname'], t('Photos'), "", t('Your photos'));
245                 $ps['usermenu']['events'] = Array('events/', t('Events'), "", t('Your events'));
246                 $ps['usermenu']['notes'] = Array('notes/', t('Personal notes'), "", t('Your personal photos'));
247                 $ps['usermenu']['community'] = Array('community/', t('Community'), "", "");
248                 $ps['usermenu']['pgroups'] = Array('http://dir.friendika.com/directory/forum', t('Community Pages'), "", "");
249
250                 $tpl = get_markup_template('profile_side.tpl');
251
252                 $a->page['aside'] .= replace_macros($tpl, array(
253                                 '$userinfo' => $userinfo,
254                                 '$ps' => $ps,
255                         ));
256
257         }
258         
259         $ccCookie = $_COOKIE['close_pages'] + $_COOKIE['close_helpers'] + $_COOKIE['close_services'] + $_COOKIE['close_friends'] + $_COOKIE['close_postit'] + $_COOKIE['close_lastusers'] + $_COOKIE['close_lastphotos'] + $_COOKIE['close_lastlikes'];
260         
261         if($ccCookie != "8") {
262         // COMMUNITY
263         diabook_aerith_community_info();
264         
265         // CUSTOM CSS
266         $cssFile = $a->get_baseurl($ssl_state)."/view/theme/diabook-aerith/style-network.css";
267         }
268 }
269
270
271
272 //right_aside at profile pages
273 if ($a->argv[0].$a->argv[1] === "profile".$a->user['nickname']){
274         if($ccCookie != "8") {
275         // COMMUNITY
276         diabook_aerith_community_info();
277         
278         // CUSTOM CSS
279         $cssFile = $a->get_baseurl($ssl_state)."/view/theme/diabook-aerith/style-profile.css";
280         }
281 }
282
283 //tabs at right_aside on settings page
284 if ($a->argv[0] === "settings"){
285         
286         $tabs = array(
287                 array(
288                         'label' => t('Account settings'),
289                         'url'   => $a->get_baseurl(true).'/settings',
290                         'sel'   => (($a->argc == 1)?'active':''),
291                 ),      
292                 array(
293                         'label' => t('Display settings'),
294                         'url'   => $a->get_baseurl(true).'/settings/display',
295                         'sel'   => (($a->argc > 1) && ($a->argv[1] === 'display')?'active':''),
296                 ),                      
297                 array(
298                         'label' => t('Edit/Manage Profiles'),
299                         'url'   => $a->get_baseurl(true).'/profiles',
300                 ),      
301                 array(
302                         'label' => t('Connector settings'),
303                         'url'   => $a->get_baseurl(true).'/settings/connectors',
304                         'sel'   => (($a->argc > 1) && ($a->argv[1] === 'connectors')?'active':''),
305                 ),
306                 array(
307                         'label' => t('Plugin settings'),
308                         'url'   => $a->get_baseurl(true).'/settings/addon',
309                         'sel'   => (($a->argc > 1) && ($a->argv[1] === 'addon')?'active':''),
310                 ),
311                 array(
312                         'label' => t('Connections'),
313                         'url' => $a->get_baseurl(true) . '/settings/oauth',
314                         'sel' => (($a->argc > 1) && ($a->argv[1] === 'oauth')?'active':''),
315                 ),
316                 array(
317                         'label' => t('Export personal data'),
318                         'url' => $a->get_baseurl(true) . '/uexport',
319                         'sel' => ''
320                 )
321         );
322         $tabtpl = file_get_contents(dirname(__file__).'/rs_common_tabs.tpl') ;
323         $a->page['aside'] = replace_macros($tabtpl, array(
324                 '$tabs' => $tabs,
325         ));
326         
327         
328         // CUSTOM CSS
329         $cssFile = $a->get_baseurl($ssl_state)."/view/theme/diabook-aerith/style-settings.css";
330         
331 }
332
333
334 // custom css
335 if (!is_null($cssFile)) $a->page['htmlhead'] .= sprintf('<link rel="stylesheet" type="text/css" href="%s" />', $cssFile);
336
337 //load jquery.cookie.js
338 $cookieJS = $a->get_baseurl($ssl_state)."/view/theme/diabook-aerith/js/jquery.cookie.js";
339 $a->page['htmlhead'] .= sprintf('<script language="JavaScript" src="%s" ></script>', $cookieJS);
340
341 //load jquery.ae.image.resize.js
342 $imageresizeJS = $a->get_baseurl($ssl_state)."/view/theme/diabook-aerith/js/jquery.ae.image.resize.js";
343 $a->page['htmlhead'] .= sprintf('<script language="JavaScript" src="%s" ></script>', $imageresizeJS);
344
345 //js scripts
346 //comment-edit-wrapper on photo_view
347 if ($a->argv[0].$a->argv[2] === "photos"."image"){
348
349 $a->page['htmlhead'] .= '
350 <script>
351         $(function(){
352         
353                 $(".comment-edit-form").css("display","table");
354                         
355                         });
356     </script>';
357         
358 }
359
360 $a->page['htmlhead'] .= '
361
362 <script>
363  $(function() {
364         $("a.lightbox").fancybox(); // Select all links with lightbox class
365  });
366   
367  </script>';
368
369 $a->page['htmlhead'] .= '
370  <script>
371  
372 $(document).ready(function() {
373     $("iframe").each(function(){
374         var ifr_source = $(this).attr("src");
375         var wmode = "wmode=transparent";
376         if(ifr_source.indexOf("?") != -1) {
377             var getQString = ifr_source.split("?");
378             var oldString = getQString[1];
379             var newString = getQString[0];
380             $(this).attr("src",newString+"?"+wmode+"&"+oldString);
381         }
382         else $(this).attr("src",ifr_source+"?"+wmode);
383     });
384       
385
386 });
387
388 function yt_iframe() {
389         
390         $("iframe").load(function() { 
391         var ifr_src = $(this).contents().find("body iframe").attr("src");
392         $("iframe").contents().find("body iframe").attr("src", ifr_src+"&wmode=transparent");
393     });
394
395         };
396   
397  </script>';
398
399 if ($a->argv[0].$a->argv[1] === "profile".$a->user['nickname'] or $a->argv[0] === "network" && local_user()){
400 $a->page['htmlhead'] .= '
401 <script>
402
403  $(function() {
404         $(".oembed.photo img").aeImageResize({height: 400, width: 400});
405   });
406 </script>';
407
408
409         if($ccCookie != "8") {
410 $a->page['htmlhead'] .= '
411 <script>
412 $("right_aside").ready(function(){
413         
414         if($.cookie("close_pages") == "1") 
415                 {
416                 document.getElementById( "close_pages" ).style.display = "none";
417                         };
418         
419         if($.cookie("close_helpers") == "1") 
420                 {
421                 document.getElementById( "close_helpers" ).style.display = "none";
422                         };
423                         
424         if($.cookie("close_services") == "1") 
425                 {
426                 document.getElementById( "close_services" ).style.display = "none";
427                         };
428                         
429         if($.cookie("close_friends") == "1") 
430                 {
431                 document.getElementById( "close_friends" ).style.display = "none";
432                         };
433         
434         if($.cookie("close_postit") == "1") 
435                 {
436                 document.getElementById( "close_postit" ).style.display = "none";
437                         };
438                         
439         if($.cookie("close_lastusers") == "1") 
440                 {
441                 document.getElementById( "close_lastusers" ).style.display = "none";
442                         };
443                         
444         if($.cookie("close_lastphotos") == "1") 
445                 {
446                 document.getElementById( "close_lastphotos" ).style.display = "none";
447                         };
448                         
449         if($.cookie("close_lastlikes") == "1") 
450                 {
451                 document.getElementById( "close_lastlikes" ).style.display = "none";
452                         };}
453
454 );
455
456 function close_pages(){
457  document.getElementById( "close_pages" ).style.display = "none";
458  $.cookie("close_pages","1", { expires: 365, path: "/" });
459  };
460  
461 function close_helpers(){
462  document.getElementById( "close_helpers" ).style.display = "none";
463   $.cookie("close_helpers","1", { expires: 365, path: "/" });
464  };
465
466 function close_services(){
467  document.getElementById( "close_services" ).style.display = "none";
468  $.cookie("close_services","1", { expires: 365, path: "/" });
469  };
470  
471 function close_friends(){
472  document.getElementById( "close_friends" ).style.display = "none";
473  $.cookie("close_friends","1", { expires: 365, path: "/" });
474  };
475
476 function close_postit(){
477  document.getElementById( "close_postit" ).style.display = "none";
478  $.cookie("close_postit","1", { expires: 365, path: "/" });
479  };
480  
481 function close_lastusers(){
482  document.getElementById( "close_lastusers" ).style.display = "none";
483  $.cookie("close_lastusers","1", { expires: 365, path: "/" });
484  };
485
486 function close_lastphotos(){
487  document.getElementById( "close_lastphotos" ).style.display = "none";
488  $.cookie("close_lastphotos","1", { expires: 365, path: "/" });
489  };
490  
491 function close_lastlikes(){
492  document.getElementById( "close_lastlikes" ).style.display = "none";
493  $.cookie("close_lastlikes","1", { expires: 365, path: "/" });
494  };
495 </script>';}
496
497 $a->page['htmlhead'] .= ' 
498 <script>
499 function restore_boxes(){
500         $.cookie("close_pages","2", { expires: 365, path: "/" });
501         $.cookie("close_helpers","2", { expires: 365, path: "/" });
502         $.cookie("close_services","2", { expires: 365, path: "/" });
503         $.cookie("close_friends","2", { expires: 365, path: "/" });
504         $.cookie("close_postit","2", { expires: 365, path: "/" });
505         $.cookie("close_lastusers","2", { expires: 365, path: "/" });
506         $.cookie("close_lastphotos","2", { expires: 365, path: "/" });
507         $.cookie("close_lastlikes","2", { expires: 365, path: "/" });
508         alert("Right-hand column was restored. Please refresh your browser");
509   }
510 </script>';}