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