]> git.mxchange.org Git - friendica.git/blob - view/theme/diabook/theme.php
diabook-themes: removed fpostit due to security issues and small fix in german transl...
[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.020)
7  * Author: 
8  */
9
10
11 //print diabook-version for debugging
12 $diabook_version = "Diabook (Version: 1.020)";
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__).'/ch_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__).'/ch_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         
140    
141    //right_aside FIND FRIENDS
142         if(local_user()) {
143         $nv = array();
144         $nv['title'] = Array("", t('Find Friends'), "", "");
145         $nv['directory'] = Array('directory', t('Local Directory'), "", "");
146         $nv['global_directory'] = Array('http://dir.friendica.com/', t('Global Directory'), "", "");
147         $nv['match'] = Array('match', t('Similar Interests'), "", "");
148         $nv['suggest'] = Array('suggest', t('Friend Suggestions'), "", "");
149         $nv['invite'] = Array('invite', t('Invite Friends'), "", "");
150         
151         $nv['search'] = '<form name="simple_bar" method="get" action="http://dir.friendika.com/directory">
152                                                 <span class="sbox_l"></span>
153                                                 <span class="sbox">
154                                                 <input type="text" name="search" size="13" maxlength="50">
155                                                 </span>
156                                                 <span class="sbox_r" id="srch_clear"></span>';
157         
158         $aside['$nv'] = $nv;
159         };
160    
161    //Community Page
162    if(local_user()) {
163    $page = '<div id="page-sidebar-right_aside" class="widget">
164                         <div class="title tool">
165                         <h3>'.t("Community Pages").'<a id="close_pages_icon"  onClick="close_pages()" class="icon close_box" title="close"></a></h3></div>
166                         <div id="sidebar-page-list"><ul>';
167
168         $pagelist = array();
169
170         $contacts = q("SELECT `id`, `url`, `name`, `micro`FROM `contact`
171                         WHERE `network`= 'dfrn' AND `forum` = 1 AND `uid` = %d
172                         ORDER BY `name` ASC",
173                         intval($a->user['uid'])
174         );
175
176         $pageD = array();
177
178         // Look if the profile is a community page
179         foreach($contacts as $contact) {
180                 $pageD[] = array("url"=>$contact["url"], "name"=>$contact["name"], "id"=>$contact["id"], "micro"=>$contact['micro']);
181         };
182         
183
184         $contacts = $pageD;
185
186         foreach($contacts as $contact) {
187                 $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">'.
188                                 $contact["name"]."</a></li>";
189         }
190         $page .= '</ul></div></div>';
191         //if (sizeof($contacts) > 0)
192                 
193                 $aside['$page'] = $page;        
194         }
195   //END Community Page  
196   //helpers
197    $helpers = array();
198         $helpers['title'] = Array("", t('Help or @NewHere ?'), "", "");
199         
200         $aside['$helpers'] = $helpers;
201    //end helpers
202    //connectable services
203    $con_services = array();
204         $con_services['title'] = Array("", t('Connect Services'), "", "");
205         
206         $aside['$con_services'] = $con_services;
207    //end connectable services
208   
209   
210    //get_baseurl
211    $url = $a->get_baseurl($ssl_state);   
212    $aside['$url'] = $url;
213
214         $tpl = file_get_contents(dirname(__file__).'/communityhome.tpl');
215         $a->page['right_aside'] = replace_macros($tpl, $aside);
216         
217         
218         
219         
220 }
221
222
223 //profile_side at networkpages
224 if ($a->argv[0] === "network" && local_user()){
225
226         // USER MENU
227         if(local_user()) {
228                 
229                 $r = q("SELECT micro FROM contact WHERE uid=%d AND self=1", intval($a->user['uid']));
230                                 
231                 $userinfo = array(
232                                         'icon' => (count($r) ? $r[0]['micro']: $a->get_baseurl()."/images/default-profile-mm.jpg"),
233                                         'name' => $a->user['username'],
234                                 );      
235                 $ps = array('usermenu'=>array());
236                 $ps['usermenu']['status'] = Array('profile/' . $a->user['nickname'], t('Home'), "", t('Your posts and conversations'));
237                 $ps['usermenu']['profile'] = Array('profile/' . $a->user['nickname']. '?tab=profile', t('Profile'), "", t('Your profile page'));
238                 $ps['usermenu']['contacts'] = Array('contacts' , t('Contacts'), "", t('Your contacts'));                                
239                 $ps['usermenu']['photos'] = Array('photos/' . $a->user['nickname'], t('Photos'), "", t('Your photos'));
240                 $ps['usermenu']['events'] = Array('events/', t('Events'), "", t('Your events'));
241                 $ps['usermenu']['notes'] = Array('notes/', t('Personal notes'), "", t('Your personal photos'));
242                 $ps['usermenu']['community'] = Array('community/', t('Community'), "", "");
243                 $ps['usermenu']['pgroups'] = Array('http://dir.friendica.com/directory/forum', t('Community Pages'), "", "");
244
245                 $tpl = get_markup_template('profile_side.tpl');
246
247                 $a->page['aside'] .= replace_macros($tpl, array(
248                                 '$userinfo' => $userinfo,
249                                 '$ps' => $ps,
250                         ));
251
252         }
253         
254         $ccCookie = $_COOKIE['close_pages'] + $_COOKIE['close_helpers'] + $_COOKIE['close_services'] + $_COOKIE['close_friends'] + $_COOKIE['close_lastusers'] + $_COOKIE['close_lastphotos'] + $_COOKIE['close_lastlikes'];
255         
256         if($ccCookie != "7") {
257         // COMMUNITY
258         diabook_community_info();
259
260         // CUSTOM CSS
261         if($resolution == "normal") {$cssFile = $a->get_baseurl($ssl_state)."/view/theme/diabook/style-network.css";}
262         if($resolution == "wide") {$cssFile = $a->get_baseurl($ssl_state)."/view/theme/diabook/style-network-wide.css";}
263         }
264 }
265
266
267
268 //right_aside at profile pages
269 if ($a->argv[0].$a->argv[1] === "profile".$a->user['nickname']){
270         if($ccCookie != "7") {
271         // COMMUNITY
272         diabook_community_info();
273         
274         // CUSTOM CSS
275         if($resolution == "normal") {$cssFile = $a->get_baseurl($ssl_state)."/view/theme/diabook/style-profile.css";}
276         if($resolution == "wide") {$cssFile = $a->get_baseurl($ssl_state)."/view/theme/diabook/style-profile-wide.css";}
277         
278         }
279 }
280
281 // custom css
282 if (!is_null($cssFile)) $a->page['htmlhead'] .= sprintf('<link rel="stylesheet" type="text/css" href="%s" />', $cssFile);
283
284
285
286 //load jquery.cookie.js
287 $cookieJS = $a->get_baseurl($ssl_state)."/view/theme/diabook/js/jquery.cookie.js";
288 $a->page['htmlhead'] .= sprintf('<script language="JavaScript" src="%s"></script>', $cookieJS);
289
290 //load jquery.ae.image.resize.js
291 $imageresizeJS = $a->get_baseurl($ssl_state)."/view/theme/diabook/js/jquery.ae.image.resize.js";
292 $a->page['htmlhead'] .= sprintf('<script language="JavaScript" src="%s" ></script>', $imageresizeJS);
293
294 //load jquery.autogrow-textarea.js
295 $autogrowJS = $a->get_baseurl($ssl_state)."/view/theme/diabook/js/jquery.autogrow.textarea.js";
296 $a->page['htmlhead'] .= sprintf('<script language="JavaScript" src="%s" ></script>', $autogrowJS);
297
298 //js scripts
299 //comment-edit-wrapper on photo_view
300 if ($a->argv[0].$a->argv[2] === "photos"."image"){
301
302 $a->page['htmlhead'] .= '
303 <script>
304         $(function(){
305         
306                 $(".comment-edit-form").css("display","table");
307                         
308                         });
309     </script>';
310         
311 }
312
313 $a->page['htmlhead'] .= '
314
315 <script>
316  $(function() {
317         $("a.lightbox").fancybox(); // Select all links with lightbox class
318  });
319    
320  </script>';
321  
322 $a->page['htmlhead'] .= '
323
324 <script type="text/javascript">
325
326 function tautogrow(id){
327                 $("textarea#comment-edit-text-" +id).autogrow();        
328         };
329  </script>';
330  
331  
332 $a->page['htmlhead'] .= '
333  <script>
334  
335 $(document).ready(function() {
336     $("iframe").each(function(){
337         var ifr_source = $(this).attr("src");
338         var wmode = "wmode=transparent";
339         if(ifr_source.indexOf("?") != -1) {
340             var getQString = ifr_source.split("?");
341             var oldString = getQString[1];
342             var newString = getQString[0];
343             $(this).attr("src",newString+"?"+wmode+"&"+oldString);
344         }
345         else $(this).attr("src",ifr_source+"?"+wmode);
346     });
347       
348
349 });
350
351 function yt_iframe() {
352         
353         $("iframe").load(function() { 
354         var ifr_src = $(this).contents().find("body iframe").attr("src");
355         $("iframe").contents().find("body iframe").attr("src", ifr_src+"&wmode=transparent");
356     });
357
358         };
359   
360  </script>';
361  
362
363 if ($a->argv[0].$a->argv[1] === "profile".$a->user['nickname'] or $a->argv[0] === "network" && local_user()){
364 $a->page['htmlhead'] .= '
365 <script>
366
367  $(function() {
368         $(".oembed.photo img").aeImageResize({height: 400, width: 400});
369   });
370 </script>';
371
372
373         if($ccCookie != "7") {
374 $a->page['htmlhead'] .= '
375 <script>
376 $("right_aside").ready(function(){
377         
378         if($.cookie("close_pages") == "1") 
379                 {
380                 document.getElementById( "close_pages" ).style.display = "none";
381                         };
382         
383         if($.cookie("close_helpers") == "1") 
384                 {
385                 document.getElementById( "close_helpers" ).style.display = "none";
386                         };
387                         
388         if($.cookie("close_services") == "1") 
389                 {
390                 document.getElementById( "close_services" ).style.display = "none";
391                         };
392                         
393         if($.cookie("close_friends") == "1") 
394                 {
395                 document.getElementById( "close_friends" ).style.display = "none";
396                         };
397         
398                         
399         if($.cookie("close_lastusers") == "1") 
400                 {
401                 document.getElementById( "close_lastusers" ).style.display = "none";
402                         };
403                         
404         if($.cookie("close_lastphotos") == "1") 
405                 {
406                 document.getElementById( "close_lastphotos" ).style.display = "none";
407                         };
408                         
409         if($.cookie("close_lastlikes") == "1") 
410                 {
411                 document.getElementById( "close_lastlikes" ).style.display = "none";
412                         };}
413
414 );
415
416 function close_pages(){
417  document.getElementById( "close_pages" ).style.display = "none";
418  $.cookie("close_pages","1", { expires: 365, path: "/" });
419  };
420  
421 function close_helpers(){
422  document.getElementById( "close_helpers" ).style.display = "none";
423   $.cookie("close_helpers","1", { expires: 365, path: "/" });
424  };
425
426 function close_services(){
427  document.getElementById( "close_services" ).style.display = "none";
428  $.cookie("close_services","1", { expires: 365, path: "/" });
429  };
430  
431 function close_friends(){
432  document.getElementById( "close_friends" ).style.display = "none";
433  $.cookie("close_friends","1", { expires: 365, path: "/" });
434  };
435
436  
437 function close_lastusers(){
438  document.getElementById( "close_lastusers" ).style.display = "none";
439  $.cookie("close_lastusers","1", { expires: 365, path: "/" });
440  };
441
442 function close_lastphotos(){
443  document.getElementById( "close_lastphotos" ).style.display = "none";
444  $.cookie("close_lastphotos","1", { expires: 365, path: "/" });
445  };
446  
447 function close_lastlikes(){
448  document.getElementById( "close_lastlikes" ).style.display = "none";
449  $.cookie("close_lastlikes","1", { expires: 365, path: "/" });
450  };
451 </script>';}
452
453 $a->page['htmlhead'] .= ' 
454 <script>
455 function restore_boxes(){
456         $.cookie("close_pages","2", { expires: 365, path: "/" });
457         $.cookie("close_helpers","2", { expires: 365, path: "/" });
458         $.cookie("close_services","2", { expires: 365, path: "/" });
459         $.cookie("close_friends","2", { expires: 365, path: "/" });
460         $.cookie("close_lastusers","2", { expires: 365, path: "/" });
461         $.cookie("close_lastphotos","2", { expires: 365, path: "/" });
462         $.cookie("close_lastlikes","2", { expires: 365, path: "/" });
463         alert("Right-hand column was restored. Please refresh your browser");
464   }
465 </script>';}
466
467
468 $a->page['htmlhead'] .= ' 
469
470 <script>
471 function insertFormatting(comment,BBcode,id) {
472         
473                 var tmpStr = $("#comment-edit-text-" + id).val();
474                 if(tmpStr == comment) {
475                         tmpStr = "";
476                         $("#comment-edit-text-" + id).addClass("comment-edit-text-full");
477                         $("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
478                         openMenu("comment-edit-submit-wrapper-" + id);
479                                                                 }
480
481         textarea = document.getElementById("comment-edit-text-" +id);
482         if (document.selection) {
483                 textarea.focus();
484                 selected = document.selection.createRange();
485                 if (BBcode == "url"){
486                         selected.text = "["+BBcode+"]" + "http://" +  selected.text + "[/"+BBcode+"]";
487                         } else                  
488                 selected.text = "["+BBcode+"]" + selected.text + "[/"+BBcode+"]";
489         } else if (textarea.selectionStart || textarea.selectionStart == "0") {
490                 var start = textarea.selectionStart;
491                 var end = textarea.selectionEnd;
492                 if (BBcode == "url"){
493                         textarea.value = textarea.value.substring(0, start) + "["+BBcode+"]" + "http://" + textarea.value.substring(start, end) + "[/"+BBcode+"]" + textarea.value.substring(end, textarea.value.length);
494                         } else
495                 textarea.value = textarea.value.substring(0, start) + "["+BBcode+"]" + textarea.value.substring(start, end) + "[/"+BBcode+"]" + textarea.value.substring(end, textarea.value.length);
496         }
497         return true;
498 }
499 </script> ';