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