]> git.mxchange.org Git - friendica.git/blob - view/theme/diabook/theme.php
Merge branch 'master', remote-tracking branch 'remotes/upstream/master'
[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 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
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  
333 $a->page['htmlhead'] .= '
334
335 <script type="text/javascript">
336
337 function tautogrow(id){
338                 $("textarea#comment-edit-text-" +id).autogrow();        
339         };
340  </script>';
341  
342  
343 $a->page['htmlhead'] .= '
344  <script>
345  
346 $(document).ready(function() {
347     $("iframe").each(function(){
348         var ifr_source = $(this).attr("src");
349         var wmode = "wmode=transparent";
350         if(ifr_source.indexOf("?") != -1) {
351             var getQString = ifr_source.split("?");
352             var oldString = getQString[1];
353             var newString = getQString[0];
354             $(this).attr("src",newString+"?"+wmode+"&"+oldString);
355         }
356         else $(this).attr("src",ifr_source+"?"+wmode);
357     });
358       
359
360 });
361
362 function yt_iframe() {
363         
364         $("iframe").load(function() { 
365         var ifr_src = $(this).contents().find("body iframe").attr("src");
366         $("iframe").contents().find("body iframe").attr("src", ifr_src+"&wmode=transparent");
367     });
368
369         };
370   
371  </script>';
372  
373 if($a->argv[0] === "settings" && local_user()) {
374 $a->page['htmlhead'] .= ' 
375 <script>
376 function restore_boxes(){
377         $.cookie("close_pages","2", { expires: 365, path: "/" });
378         $.cookie("close_helpers","2", { expires: 365, path: "/" });
379         $.cookie("close_services","2", { expires: 365, path: "/" });
380         $.cookie("close_friends","2", { expires: 365, path: "/" });
381         $.cookie("close_lastusers","2", { expires: 365, path: "/" });
382         $.cookie("close_lastphotos","2", { expires: 365, path: "/" });
383         $.cookie("close_lastlikes","2", { expires: 365, path: "/" });
384         alert("Right-hand column was restored. Please refresh your browser");
385   }
386 </script>';}
387
388
389
390 if ($a->argv[0].$a->argv[1] === "profile".$a->user['nickname'] or $a->argv[0] === "network" && local_user()){
391 $a->page['htmlhead'] .= '
392 <script>
393
394  $(function() {
395         $(".oembed.photo img").aeImageResize({height: 400, width: 400});
396   });
397 </script>';
398
399
400         if($ccCookie != "7") {
401 $a->page['htmlhead'] .= '
402 <script>
403 $("right_aside").ready(function(){
404         
405         if($.cookie("close_pages") == "1") 
406                 {
407                 document.getElementById( "close_pages" ).style.display = "none";
408                         };
409         
410         if($.cookie("close_helpers") == "1") 
411                 {
412                 document.getElementById( "close_helpers" ).style.display = "none";
413                         };
414                         
415         if($.cookie("close_services") == "1") 
416                 {
417                 document.getElementById( "close_services" ).style.display = "none";
418                         };
419                         
420         if($.cookie("close_friends") == "1") 
421                 {
422                 document.getElementById( "close_friends" ).style.display = "none";
423                         };
424         
425                         
426         if($.cookie("close_lastusers") == "1") 
427                 {
428                 document.getElementById( "close_lastusers" ).style.display = "none";
429                         };
430                         
431         if($.cookie("close_lastphotos") == "1") 
432                 {
433                 document.getElementById( "close_lastphotos" ).style.display = "none";
434                         };
435                         
436         if($.cookie("close_lastlikes") == "1") 
437                 {
438                 document.getElementById( "close_lastlikes" ).style.display = "none";
439                         };}
440
441 );
442
443 function close_pages(){
444  document.getElementById( "close_pages" ).style.display = "none";
445  $.cookie("close_pages","1", { expires: 365, path: "/" });
446  };
447  
448 function close_helpers(){
449  document.getElementById( "close_helpers" ).style.display = "none";
450   $.cookie("close_helpers","1", { expires: 365, path: "/" });
451  };
452
453 function close_services(){
454  document.getElementById( "close_services" ).style.display = "none";
455  $.cookie("close_services","1", { expires: 365, path: "/" });
456  };
457  
458 function close_friends(){
459  document.getElementById( "close_friends" ).style.display = "none";
460  $.cookie("close_friends","1", { expires: 365, path: "/" });
461  };
462
463  
464 function close_lastusers(){
465  document.getElementById( "close_lastusers" ).style.display = "none";
466  $.cookie("close_lastusers","1", { expires: 365, path: "/" });
467  };
468
469 function close_lastphotos(){
470  document.getElementById( "close_lastphotos" ).style.display = "none";
471  $.cookie("close_lastphotos","1", { expires: 365, path: "/" });
472  };
473  
474 function close_lastlikes(){
475  document.getElementById( "close_lastlikes" ).style.display = "none";
476  $.cookie("close_lastlikes","1", { expires: 365, path: "/" });
477  };
478 </script>';}}
479
480 $a->page['htmlhead'] .= ' 
481
482 <script>
483 function insertFormatting(BBcode,id) {
484         
485                 var tmpStr = $("#comment-edit-text-" + id).val();
486                 if(tmpStr == comment) {
487                         tmpStr = "";
488                         $("#comment-edit-text-" + id).addClass("comment-edit-text-full");
489                         $("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
490                         openMenu("comment-edit-submit-wrapper-" + id);
491                                                                 }
492
493         textarea = document.getElementById("comment-edit-text-" +id);
494         if (document.selection) {
495                 textarea.focus();
496                 selected = document.selection.createRange();
497                 if (BBcode == "url"){
498                         selected.text = "["+BBcode+"]" + "http://" +  selected.text + "[/"+BBcode+"]";
499                         } else                  
500                 selected.text = "["+BBcode+"]" + selected.text + "[/"+BBcode+"]";
501         } else if (textarea.selectionStart || textarea.selectionStart == "0") {
502                 var start = textarea.selectionStart;
503                 var end = textarea.selectionEnd;
504                 if (BBcode == "url"){
505                         textarea.value = textarea.value.substring(0, start) + "["+BBcode+"]" + "http://" + textarea.value.substring(start, end) + "[/"+BBcode+"]" + textarea.value.substring(end, textarea.value.length);
506                         } else
507                 textarea.value = textarea.value.substring(0, start) + "["+BBcode+"]" + textarea.value.substring(start, end) + "[/"+BBcode+"]" + textarea.value.substring(end, textarea.value.length);
508         }
509         return true;
510 }
511
512 function cmtBbOpen(id) {
513         $(".comment-edit-bb-" + id).show();
514 }
515 function cmtBbClose(id) {
516         $(".comment-edit-bb-" + id).hide();
517 }
518
519 </script> ';