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