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