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