]> git.mxchange.org Git - friendica.git/blob - view/theme/diabook/theme.php
diabook-themes: add diabook-green and some minor css/bug-fixes
[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.021)
7  * Author: 
8  */
9
10
11 //print diabook-version for debugging
12 $diabook_version = "Diabook (Version: 1.021)";
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
30
31 /**
32  * prints last community activity
33  */
34
35
36  
37 function diabook_community_info(){
38         $a = get_app();
39
40
41         // last 12 users
42         $aside['$lastusers_title'] = t('Last users');
43         $aside['$lastusers_items'] = array();
44         $sql_extra = "";
45         $publish = (get_config('system','publish_all') ? '' : " AND `publish` = 1 " );
46         $order = " ORDER BY `register_date` DESC ";
47
48         $r = q("SELECT `profile`.*, `profile`.`uid` AS `profile_uid`, `user`.`nickname`
49                         FROM `profile` LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid` 
50                         WHERE `is-default` = 1 $publish AND `user`.`blocked` = 0 $sql_extra $order LIMIT %d , %d ",
51                 0,
52                 9
53         );
54         $tpl = file_get_contents( dirname(__file__).'/ch_directory_item.tpl');
55         if(count($r)) {
56                 $photo = 'thumb';
57                 foreach($r as $rr) {
58                         $profile_link = $a->get_baseurl() . '/profile/' . ((strlen($rr['nickname'])) ? $rr['nickname'] : $rr['profile_uid']);
59                         $entry = replace_macros($tpl,array(
60                                 '$id' => $rr['id'],
61                                 '$profile-link' => $profile_link,
62                                 '$photo' => $rr[$photo],
63                                 '$alt-text' => $rr['name'],
64                         ));
65                         $aside['$lastusers_items'][] = $entry;
66                 }
67         }
68         
69         
70         // last 10 liked items
71         $aside['$like_title'] = t('Last likes');
72         $aside['$like_items'] = array();
73         $r = q("SELECT `T1`.`created`, `T1`.`liker`, `T1`.`liker-link`, `item`.* FROM 
74                         (SELECT `parent-uri`, `created`, `author-name` AS `liker`,`author-link` AS `liker-link` 
75                                 FROM `item` WHERE `verb`='http://activitystrea.ms/schema/1.0/like' GROUP BY `parent-uri` ORDER BY `created` DESC) AS T1
76                         INNER JOIN `item` ON `item`.`uri`=`T1`.`parent-uri` 
77                         WHERE `T1`.`liker-link` LIKE '%s%%' OR `item`.`author-link` LIKE '%s%%'
78                         GROUP BY `uri`
79                         ORDER BY `T1`.`created` DESC
80                         LIMIT 0,5",
81                         $a->get_baseurl(),$a->get_baseurl()
82                         );
83
84         foreach ($r as $rr) {
85                 $author  = '<a href="' . $rr['liker-link'] . '">' . $rr['liker'] . '</a>';
86                 $objauthor =  '<a href="' . $rr['author-link'] . '">' . $rr['author-name'] . '</a>';
87                 
88                 //var_dump($rr['verb'],$rr['object-type']); killme();
89                 switch($rr['verb']){
90                         case 'http://activitystrea.ms/schema/1.0/post':
91                                 switch ($rr['object-type']){
92                                         case 'http://activitystrea.ms/schema/1.0/event':
93                                                 $post_type = t('event');
94                                                 break;
95                                         default:
96                                                 $post_type = t('status');
97                                 }
98                                 break;
99                         default:
100                                 if ($rr['resource-id']){
101                                         $post_type = t('photo');
102                                         $m=array();     preg_match("/\[url=([^]]*)\]/", $rr['body'], $m);
103                                         $rr['plink'] = $m[1];
104                                 } else {
105                                         $post_type = t('status');
106                                 }
107                 }
108                 $plink = '<a href="' . $rr['plink'] . '">' . $post_type . '</a>';
109
110                 $aside['$like_items'][] = sprintf( t('%1$s likes %2$s\'s %3$s'), $author, $objauthor, $plink);
111                 
112         }
113         
114         
115         // last 12 photos
116         $aside['$photos_title'] = t('Last photos');
117         $aside['$photos_items'] = array();
118         $r = q("SELECT `photo`.`id`, `photo`.`resource-id`, `photo`.`scale`, `photo`.`desc`, `user`.`nickname`, `user`.`username` FROM 
119                                 (SELECT `resource-id`, MAX(`scale`) as maxscale FROM `photo` 
120                                         WHERE `profile`=0 AND `contact-id`=0 AND `album` NOT IN ('Contact Photos', '%s', 'Profile Photos', '%s')
121                                                 AND `allow_cid`='' AND `allow_gid`='' AND `deny_cid`='' AND `deny_gid`='' GROUP BY `resource-id`) AS `t1`
122                                 INNER JOIN `photo` ON `photo`.`resource-id`=`t1`.`resource-id` AND `photo`.`scale` = `t1`.`maxscale`,
123                                 `user` 
124                                 WHERE `user`.`uid` = `photo`.`uid`
125                                 AND `user`.`blockwall`=0
126                                 AND `user`.`hidewall`=0
127                                 ORDER BY `photo`.`edited` DESC
128                                 LIMIT 0, 9",
129                                 dbesc(t('Contact Photos')),
130                                 dbesc(t('Profile Photos'))
131                                 );
132                 if(count($r)) {
133                 $tpl = file_get_contents( dirname(__file__).'/ch_directory_item.tpl');
134                 foreach($r as $rr) {
135                         $photo_page = $a->get_baseurl() . '/photos/' . $rr['nickname'] . '/image/' . $rr['resource-id'];
136                         $photo_url = $a->get_baseurl() . '/photo/' .  $rr['resource-id'] . '-' . $rr['scale'] .'.jpg';
137                 
138                         $entry = replace_macros($tpl,array(
139                                 '$id' => $rr['id'],
140                                 '$profile-link' => $photo_page,
141                                 '$photo' => $photo_url,
142                                 '$alt-text' => $rr['username']." : ".$rr['desc'],
143                         ));
144
145                         $aside['$photos_items'][] = $entry;
146                 }
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
295
296 //load jquery.cookie.js
297 $cookieJS = $a->get_baseurl($ssl_state)."/view/theme/diabook/js/jquery.cookie.js";
298 $a->page['htmlhead'] .= sprintf('<script language="JavaScript" src="%s"></script>', $cookieJS);
299
300 //load jquery.ae.image.resize.js
301 $imageresizeJS = $a->get_baseurl($ssl_state)."/view/theme/diabook/js/jquery.ae.image.resize.js";
302 $a->page['htmlhead'] .= sprintf('<script language="JavaScript" src="%s" ></script>', $imageresizeJS);
303
304 //load jquery.autogrow-textarea.js
305 $autogrowJS = $a->get_baseurl($ssl_state)."/view/theme/diabook/js/jquery.autogrow.textarea.js";
306 $a->page['htmlhead'] .= sprintf('<script language="JavaScript" src="%s" ></script>', $autogrowJS);
307
308 //js scripts
309 //comment-edit-wrapper on photo_view
310 if ($a->argv[0].$a->argv[2] === "photos"."image"){
311
312 $a->page['htmlhead'] .= '
313 <script>
314         $(function(){
315         
316                 $(".comment-edit-form").css("display","table");
317                         
318                         });
319     </script>';
320         
321 }
322
323 $a->page['htmlhead'] .= '
324
325 <script>
326  $(function() {
327         $("a.lightbox").fancybox(); // Select all links with lightbox class
328  });
329    
330  </script>';
331  
332 $a->page['htmlhead'] .= '
333
334 <script type="text/javascript">
335
336 function tautogrow(id){
337                 $("textarea#comment-edit-text-" +id).autogrow();        
338         };
339  </script>';
340  
341  
342 $a->page['htmlhead'] .= '
343  <script>
344  
345 $(document).ready(function() {
346     $("iframe").each(function(){
347         var ifr_source = $(this).attr("src");
348         var wmode = "wmode=transparent";
349         if(ifr_source.indexOf("?") != -1) {
350             var getQString = ifr_source.split("?");
351             var oldString = getQString[1];
352             var newString = getQString[0];
353             $(this).attr("src",newString+"?"+wmode+"&"+oldString);
354         }
355         else $(this).attr("src",ifr_source+"?"+wmode);
356     });
357       
358
359 });
360
361 function yt_iframe() {
362         
363         $("iframe").load(function() { 
364         var ifr_src = $(this).contents().find("body iframe").attr("src");
365         $("iframe").contents().find("body iframe").attr("src", ifr_src+"&wmode=transparent");
366     });
367
368         };
369   
370  </script>';
371  
372 if($a->argv[0] === "settings" && local_user()) {
373 $a->page['htmlhead'] .= ' 
374 <script>
375 function restore_boxes(){
376         $.cookie("close_pages","2", { expires: 365, path: "/" });
377         $.cookie("close_helpers","2", { expires: 365, path: "/" });
378         $.cookie("close_services","2", { expires: 365, path: "/" });
379         $.cookie("close_friends","2", { expires: 365, path: "/" });
380         $.cookie("close_lastusers","2", { expires: 365, path: "/" });
381         $.cookie("close_lastphotos","2", { expires: 365, path: "/" });
382         $.cookie("close_lastlikes","2", { expires: 365, path: "/" });
383         alert("Right-hand column was restored. Please refresh your browser");
384   }
385 </script>';}
386
387
388
389 if ($a->argv[0].$a->argv[1] === "profile".$a->user['nickname'] or $a->argv[0] === "network" && local_user()){
390 $a->page['htmlhead'] .= '
391 <script>
392
393  $(function() {
394         $(".oembed.photo img").aeImageResize({height: 400, width: 400});
395   });
396 </script>';
397
398
399         if($ccCookie != "7") {
400 $a->page['htmlhead'] .= '
401 <script>
402 $("right_aside").ready(function(){
403         
404         if($.cookie("close_pages") == "1") 
405                 {
406                 document.getElementById( "close_pages" ).style.display = "none";
407                         };
408         
409         if($.cookie("close_helpers") == "1") 
410                 {
411                 document.getElementById( "close_helpers" ).style.display = "none";
412                         };
413                         
414         if($.cookie("close_services") == "1") 
415                 {
416                 document.getElementById( "close_services" ).style.display = "none";
417                         };
418                         
419         if($.cookie("close_friends") == "1") 
420                 {
421                 document.getElementById( "close_friends" ).style.display = "none";
422                         };
423         
424                         
425         if($.cookie("close_lastusers") == "1") 
426                 {
427                 document.getElementById( "close_lastusers" ).style.display = "none";
428                         };
429                         
430         if($.cookie("close_lastphotos") == "1") 
431                 {
432                 document.getElementById( "close_lastphotos" ).style.display = "none";
433                         };
434                         
435         if($.cookie("close_lastlikes") == "1") 
436                 {
437                 document.getElementById( "close_lastlikes" ).style.display = "none";
438                         };}
439
440 );
441
442 function close_pages(){
443  document.getElementById( "close_pages" ).style.display = "none";
444  $.cookie("close_pages","1", { expires: 365, path: "/" });
445  };
446  
447 function close_helpers(){
448  document.getElementById( "close_helpers" ).style.display = "none";
449   $.cookie("close_helpers","1", { expires: 365, path: "/" });
450  };
451
452 function close_services(){
453  document.getElementById( "close_services" ).style.display = "none";
454  $.cookie("close_services","1", { expires: 365, path: "/" });
455  };
456  
457 function close_friends(){
458  document.getElementById( "close_friends" ).style.display = "none";
459  $.cookie("close_friends","1", { expires: 365, path: "/" });
460  };
461
462  
463 function close_lastusers(){
464  document.getElementById( "close_lastusers" ).style.display = "none";
465  $.cookie("close_lastusers","1", { expires: 365, path: "/" });
466  };
467
468 function close_lastphotos(){
469  document.getElementById( "close_lastphotos" ).style.display = "none";
470  $.cookie("close_lastphotos","1", { expires: 365, path: "/" });
471  };
472  
473 function close_lastlikes(){
474  document.getElementById( "close_lastlikes" ).style.display = "none";
475  $.cookie("close_lastlikes","1", { expires: 365, path: "/" });
476  };
477 </script>';}}
478
479 $a->page['htmlhead'] .= ' 
480
481 <script>
482 function insertFormatting(comment,BBcode,id) {
483         
484                 var tmpStr = $("#comment-edit-text-" + id).val();
485                 if(tmpStr == comment) {
486                         tmpStr = "";
487                         $("#comment-edit-text-" + id).addClass("comment-edit-text-full");
488                         $("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
489                         openMenu("comment-edit-submit-wrapper-" + id);
490                                                                 }
491
492         textarea = document.getElementById("comment-edit-text-" +id);
493         if (document.selection) {
494                 textarea.focus();
495                 selected = document.selection.createRange();
496                 if (BBcode == "url"){
497                         selected.text = "["+BBcode+"]" + "http://" +  selected.text + "[/"+BBcode+"]";
498                         } else                  
499                 selected.text = "["+BBcode+"]" + selected.text + "[/"+BBcode+"]";
500         } else if (textarea.selectionStart || textarea.selectionStart == "0") {
501                 var start = textarea.selectionStart;
502                 var end = textarea.selectionEnd;
503                 if (BBcode == "url"){
504                         textarea.value = textarea.value.substring(0, start) + "["+BBcode+"]" + "http://" + textarea.value.substring(start, end) + "[/"+BBcode+"]" + textarea.value.substring(end, textarea.value.length);
505                         } else
506                 textarea.value = textarea.value.substring(0, start) + "["+BBcode+"]" + textarea.value.substring(start, end) + "[/"+BBcode+"]" + textarea.value.substring(end, textarea.value.length);
507         }
508         return true;
509 }
510 </script> ';