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