]> git.mxchange.org Git - friendica.git/blob - view/theme/diabook-blue/theme.php
eb2d484ba02b69326ecfa4fd4c28f96a83e7ad70
[friendica.git] / view / theme / diabook-blue / theme.php
1 <?php
2
3 /*
4  * Name: Diabook-blue
5  * Description: Diabook-blue: report bugs and request here: http://pad.toktan.org/p/diabook or contact me : thomas_bierey@friendica.eu
6  * Version: (Version: 1.018)
7  * Author: 
8  */
9
10
11 //print diabook-version for debugging
12 $diabook_version = "Diabook-blue (Version: 1.018)";
13 $a->page['htmlhead'] .= sprintf('<script "%s" ></script>', $diabook_version);
14
15 //change css on network and profilepages
16 $cssFile = null;
17
18
19 /**
20  * prints last community activity
21  */
22 function diabook_blue_community_info(){
23         $a = get_app();
24
25         // last 12 users
26         $aside['$lastusers_title'] = t('Last users');
27         $aside['$lastusers_items'] = array();
28         $sql_extra = "";
29         $publish = (get_config('system','publish_all') ? '' : " AND `publish` = 1 " );
30         $order = " ORDER BY `register_date` DESC ";
31
32         $r = q("SELECT `profile`.*, `profile`.`uid` AS `profile_uid`, `user`.`nickname`
33                         FROM `profile` LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid` 
34                         WHERE `is-default` = 1 $publish AND `user`.`blocked` = 0 $sql_extra $order LIMIT %d , %d ",
35                 0,
36                 9
37         );
38         $tpl = file_get_contents( dirname(__file__).'/directory_item.tpl');
39         if(count($r)) {
40                 $photo = 'thumb';
41                 foreach($r as $rr) {
42                         $profile_link = $a->get_baseurl() . '/profile/' . ((strlen($rr['nickname'])) ? $rr['nickname'] : $rr['profile_uid']);
43                         $entry = replace_macros($tpl,array(
44                                 '$id' => $rr['id'],
45                                 '$profile-link' => $profile_link,
46                                 '$photo' => $rr[$photo],
47                                 '$alt-text' => $rr['name'],
48                         ));
49                         $aside['$lastusers_items'][] = $entry;
50                 }
51         }
52         
53         
54         // last 10 liked items
55         $aside['$like_title'] = t('Last likes');
56         $aside['$like_items'] = array();
57         $r = q("SELECT `T1`.`created`, `T1`.`liker`, `T1`.`liker-link`, `item`.* FROM 
58                         (SELECT `parent-uri`, `created`, `author-name` AS `liker`,`author-link` AS `liker-link` 
59                                 FROM `item` WHERE `verb`='http://activitystrea.ms/schema/1.0/like' GROUP BY `parent-uri` ORDER BY `created` DESC) AS T1
60                         INNER JOIN `item` ON `item`.`uri`=`T1`.`parent-uri` 
61                         WHERE `T1`.`liker-link` LIKE '%s%%' OR `item`.`author-link` LIKE '%s%%'
62                         GROUP BY `uri`
63                         ORDER BY `T1`.`created` DESC
64                         LIMIT 0,5",
65                         $a->get_baseurl(),$a->get_baseurl()
66                         );
67
68         foreach ($r as $rr) {
69                 $author  = '<a href="' . $rr['liker-link'] . '">' . $rr['liker'] . '</a>';
70                 $objauthor =  '<a href="' . $rr['author-link'] . '">' . $rr['author-name'] . '</a>';
71                 
72                 //var_dump($rr['verb'],$rr['object-type']); killme();
73                 switch($rr['verb']){
74                         case 'http://activitystrea.ms/schema/1.0/post':
75                                 switch ($rr['object-type']){
76                                         case 'http://activitystrea.ms/schema/1.0/event':
77                                                 $post_type = t('event');
78                                                 break;
79                                         default:
80                                                 $post_type = t('status');
81                                 }
82                                 break;
83                         default:
84                                 if ($rr['resource-id']){
85                                         $post_type = t('photo');
86                                         $m=array();     preg_match("/\[url=([^]]*)\]/", $rr['body'], $m);
87                                         $rr['plink'] = $m[1];
88                                 } else {
89                                         $post_type = t('status');
90                                 }
91                 }
92                 $plink = '<a href="' . $rr['plink'] . '">' . $post_type . '</a>';
93
94                 $aside['$like_items'][] = sprintf( t('%1$s likes %2$s\'s %3$s'), $author, $objauthor, $plink);
95                 
96         }
97         
98         
99         // last 12 photos
100         $aside['$photos_title'] = t('Last photos');
101         $aside['$photos_items'] = array();
102         $r = q("SELECT `photo`.`id`, `photo`.`resource-id`, `photo`.`scale`, `photo`.`desc`, `user`.`nickname`, `user`.`username` FROM 
103                                 (SELECT `resource-id`, MAX(`scale`) as maxscale FROM `photo` 
104                                         WHERE `profile`=0 AND `contact-id`=0 AND `album` NOT IN ('Contact Photos', '%s', 'Profile Photos', '%s')
105                                                 AND `allow_cid`='' AND `allow_gid`='' AND `deny_cid`='' AND `deny_gid`='' GROUP BY `resource-id`) AS `t1`
106                                 INNER JOIN `photo` ON `photo`.`resource-id`=`t1`.`resource-id` AND `photo`.`scale` = `t1`.`maxscale`,
107                                 `user` 
108                                 WHERE `user`.`uid` = `photo`.`uid`
109                                 AND `user`.`blockwall`=0
110                                 AND `user`.`hidewall`=0
111                                 ORDER BY `photo`.`edited` DESC
112                                 LIMIT 0, 9",
113                                 dbesc(t('Contact Photos')),
114                                 dbesc(t('Profile Photos'))
115                                 );
116                 if(count($r)) {
117                 $tpl = file_get_contents( dirname(__file__).'/directory_item.tpl');
118                 foreach($r as $rr) {
119                         $photo_page = $a->get_baseurl() . '/photos/' . $rr['nickname'] . '/image/' . $rr['resource-id'];
120                         $photo_url = $a->get_baseurl() . '/photo/' .  $rr['resource-id'] . '-' . $rr['scale'] .'.jpg';
121                 
122                         $entry = replace_macros($tpl,array(
123                                 '$id' => $rr['id'],
124                                 '$profile-link' => $photo_page,
125                                 '$photo' => $photo_url,
126                                 '$alt-text' => $rr['username']." : ".$rr['desc'],
127                         ));
128
129                         $aside['$photos_items'][] = $entry;
130                 }
131         }
132         
133         $fostitJS = "javascript: (function() {
134                                         the_url = '".$a->get_baseurl($ssl_state)."/view/theme/diabook-blue/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));
135                                                 a_funct = function() {
136                                                         if (!window.open(the_url, 'fpostit', 'location=yes,links=no,scrollbars=no,toolbar=no,width=600,height=300')) location.href = the_url};
137                                                         if (/Firefox/.test(navigator.userAgent)) {setTimeout(a_funct, 0)} 
138                                                         else {a_funct()}})()" ;
139   
140    $aside['$fostitJS'] = $fostitJS;
141    
142    //nav FIND FRIENDS
143         if(local_user()) {
144         $nv = array();
145         $nv['title'] = Array("", t('Find Friends'), "", "");
146         $nv['directory'] = Array('directory', t('Local Directory'), "", "");
147         $nv['global_directory'] = Array('http://dir.friendica.com/', t('Global Directory'), "", "");
148         $nv['match'] = Array('match', t('Similar Interests'), "", "");
149         $nv['suggest'] = Array('suggest', t('Friend Suggestions'), "", "");
150         $nv['invite'] = Array('invite', t('Invite Friends'), "", "");
151         
152         $nv['search'] = '<form name="simple_bar" method="get" action="http://dir.friendika.com/directory">
153                                                 <span class="sbox_l"></span>
154                                                 <span class="sbox">
155                                                 <input type="text" name="search" size="13" maxlength="50">
156                                                 </span>
157                                                 <span class="sbox_r" id="srch_clear"></span>';
158                                                 
159         $aside['$nv'] = $nv;
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    //postit
209    $postit = array();
210         $postit['title'] = Array("", t('PostIt to Friendica'), t('Post to Friendica'), "");
211         $postit['text'] = Array("", t(' from anywhere by bookmarking this Link.'), "", "");
212         
213         $aside['$postit'] = $postit;
214    //end postit
215   
216    //get_baseurl   
217    $url = $a->get_baseurl($ssl_state);   
218    $aside['$url'] = $url;
219
220         $tpl = file_get_contents(dirname(__file__).'/communityhome.tpl');
221         $a->page['right_aside'] = replace_macros($tpl, $aside);
222         
223 }
224
225
226 //profile_side at networkpages
227 if ($a->argv[0] === "network" && local_user()){
228
229         // USER MENU
230         if(local_user()) {
231                 
232                 $r = q("SELECT micro FROM contact WHERE uid=%d AND self=1", intval($a->user['uid']));
233                                 
234                 $userinfo = array(
235                                         'icon' => (count($r) ? $r[0]['micro']: $a->get_baseurl()."/images/default-profile-mm.jpg"),
236                                         'name' => $a->user['username'],
237                                 );      
238                 $ps = array('usermenu'=>array());
239                 $ps['usermenu']['status'] = Array('profile/' . $a->user['nickname'], t('Home'), "", t('Your posts and conversations'));
240                 $ps['usermenu']['profile'] = Array('profile/' . $a->user['nickname']. '?tab=profile', t('Profile'), "", t('Your profile page'));
241                 $ps['usermenu']['contacts'] = Array('contacts' , t('Contacts'), "", t('Your contacts'));                
242                 $ps['usermenu']['photos'] = Array('photos/' . $a->user['nickname'], t('Photos'), "", t('Your photos'));
243                 $ps['usermenu']['events'] = Array('events/', t('Events'), "", t('Your events'));
244                 $ps['usermenu']['notes'] = Array('notes/', t('Personal notes'), "", t('Your personal photos'));
245                 $ps['usermenu']['community'] = Array('community/', t('Community'), "", "");
246                 $ps['usermenu']['pgroups'] = Array('http://dir.friendika.com/directory/forum', t('Community Pages'), "", "");
247
248                 $tpl = get_markup_template('profile_side.tpl');
249
250                 $a->page['aside'] .= replace_macros($tpl, array(
251                                 '$userinfo' => $userinfo,
252                                 '$ps' => $ps,
253                         ));
254
255         }
256         
257         $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'];
258         
259         if($ccCookie != "8") {
260         // COMMUNITY
261         diabook_blue_community_info();
262         
263         // CUSTOM CSS
264         $cssFile = $a->get_baseurl($ssl_state)."/view/theme/diabook-blue/style-network.css";
265         }
266 }
267
268
269
270 //right_aside at profile pages
271 if ($a->argv[0].$a->argv[1] === "profile".$a->user['nickname']){
272         if($ccCookie != "8") {
273         // COMMUNITY
274         diabook_blue_community_info();
275         
276         // CUSTOM CSS
277         $cssFile = $a->get_baseurl($ssl_state)."/view/theme/diabook-blue/style-profile.css";
278         }
279 }
280
281
282 // custom css
283 if (!is_null($cssFile)) $a->page['htmlhead'] .= sprintf('<link rel="stylesheet" type="text/css" href="%s" />', $cssFile);
284
285 //load jquery.cookie.js
286 $cookieJS = $a->get_baseurl($ssl_state)."/view/theme/diabook-blue/js/jquery.cookie.js";
287 $a->page['htmlhead'] .= sprintf('<script language="JavaScript" src="%s" ></script>', $cookieJS);
288
289 //load jquery.ae.image.resize.js
290 $imageresizeJS = $a->get_baseurl($ssl_state)."/view/theme/diabook-blue/js/jquery.ae.image.resize.js";
291 $a->page['htmlhead'] .= sprintf('<script language="JavaScript" src="%s" ></script>', $imageresizeJS);
292
293 //load jquery.autogrow-textarea.js
294 $autogrowJS = $a->get_baseurl($ssl_state)."/view/theme/diabook-blue/js/jquery.autogrow.textarea.js";
295 $a->page['htmlhead'] .= sprintf('<script language="JavaScript" src="%s" ></script>', $autogrowJS);
296
297 //js scripts
298 //comment-edit-wrapper on photo_view
299 if ($a->argv[0].$a->argv[2] === "photos"."image"){
300
301 $a->page['htmlhead'] .= '
302 <script>
303         $(function(){
304         
305                 $(".comment-edit-form").css("display","table");
306                         
307                         });
308     </script>';
309         
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 $a->page['htmlhead'] .= '
332  <script>
333  
334 $(document).ready(function() {
335     $("iframe").each(function(){
336         var ifr_source = $(this).attr("src");
337         var wmode = "wmode=transparent";
338         if(ifr_source.indexOf("?") != -1) {
339             var getQString = ifr_source.split("?");
340             var oldString = getQString[1];
341             var newString = getQString[0];
342             $(this).attr("src",newString+"?"+wmode+"&"+oldString);
343         }
344         else $(this).attr("src",ifr_source+"?"+wmode);
345     });
346       
347
348 });
349
350 function yt_iframe() {
351         
352         $("iframe").load(function() { 
353         var ifr_src = $(this).contents().find("body iframe").attr("src");
354         $("iframe").contents().find("body iframe").attr("src", ifr_src+"&wmode=transparent");
355     });
356
357         };
358   
359  </script>';
360
361
362 if ($a->argv[0].$a->argv[1] === "profile".$a->user['nickname'] or $a->argv[0] === "network" && local_user()){
363 $a->page['htmlhead'] .= '
364 <script>
365
366  $(function() {
367         $(".oembed.photo img").aeImageResize({height: 400, width: 400});
368   });
369 </script>';
370
371
372         if($ccCookie != "8") {
373 $a->page['htmlhead'] .= '
374 <script>
375 $("right_aside").ready(function(){
376         
377         if($.cookie("close_pages") == "1") 
378                 {
379                 document.getElementById( "close_pages" ).style.display = "none";
380                         };
381         
382         if($.cookie("close_helpers") == "1") 
383                 {
384                 document.getElementById( "close_helpers" ).style.display = "none";
385                         };
386                         
387         if($.cookie("close_services") == "1") 
388                 {
389                 document.getElementById( "close_services" ).style.display = "none";
390                         };
391                         
392         if($.cookie("close_friends") == "1") 
393                 {
394                 document.getElementById( "close_friends" ).style.display = "none";
395                         };
396         
397         if($.cookie("close_postit") == "1") 
398                 {
399                 document.getElementById( "close_postit" ).style.display = "none";
400                         };
401                         
402         if($.cookie("close_lastusers") == "1") 
403                 {
404                 document.getElementById( "close_lastusers" ).style.display = "none";
405                         };
406                         
407         if($.cookie("close_lastphotos") == "1") 
408                 {
409                 document.getElementById( "close_lastphotos" ).style.display = "none";
410                         };
411                         
412         if($.cookie("close_lastlikes") == "1") 
413                 {
414                 document.getElementById( "close_lastlikes" ).style.display = "none";
415                         };}
416
417 );
418
419 function close_pages(){
420  document.getElementById( "close_pages" ).style.display = "none";
421  $.cookie("close_pages","1", { expires: 365, path: "/" });
422  };
423  
424 function close_helpers(){
425  document.getElementById( "close_helpers" ).style.display = "none";
426   $.cookie("close_helpers","1", { expires: 365, path: "/" });
427  };
428
429 function close_services(){
430  document.getElementById( "close_services" ).style.display = "none";
431  $.cookie("close_services","1", { expires: 365, path: "/" });
432  };
433  
434 function close_friends(){
435  document.getElementById( "close_friends" ).style.display = "none";
436  $.cookie("close_friends","1", { expires: 365, path: "/" });
437  };
438
439 function close_postit(){
440  document.getElementById( "close_postit" ).style.display = "none";
441  $.cookie("close_postit","1", { expires: 365, path: "/" });
442  };
443  
444 function close_lastusers(){
445  document.getElementById( "close_lastusers" ).style.display = "none";
446  $.cookie("close_lastusers","1", { expires: 365, path: "/" });
447  };
448
449 function close_lastphotos(){
450  document.getElementById( "close_lastphotos" ).style.display = "none";
451  $.cookie("close_lastphotos","1", { expires: 365, path: "/" });
452  };
453  
454 function close_lastlikes(){
455  document.getElementById( "close_lastlikes" ).style.display = "none";
456  $.cookie("close_lastlikes","1", { expires: 365, path: "/" });
457  };
458 </script>';}
459
460 $a->page['htmlhead'] .= ' 
461 <script>
462 function restore_boxes(){
463         $.cookie("close_pages","2", { expires: 365, path: "/" });
464         $.cookie("close_helpers","2", { expires: 365, path: "/" });
465         $.cookie("close_services","2", { expires: 365, path: "/" });
466         $.cookie("close_friends","2", { expires: 365, path: "/" });
467         $.cookie("close_postit","2", { expires: 365, path: "/" });
468         $.cookie("close_lastusers","2", { expires: 365, path: "/" });
469         $.cookie("close_lastphotos","2", { expires: 365, path: "/" });
470         $.cookie("close_lastlikes","2", { expires: 365, path: "/" });
471         alert("Right-hand column was restored. Please refresh your browser");
472   }
473 </script>';}
474
475 $a->page['htmlhead'] .= ' 
476
477 <script type="text/javascript">
478 function insertFormatting(comment,BBcode,id) {
479         
480                 var tmpStr = $("#comment-edit-text-" + id).val();
481                 if(tmpStr == comment) {
482                         tmpStr = "";
483                         $("#comment-edit-text-" + id).addClass("comment-edit-text-full");
484                         $("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
485                         openMenu("comment-edit-submit-wrapper-" + id);
486                                                                                         }
487
488         textarea = document.getElementById("comment-edit-text-" +id);
489         if (document.selection) {
490                 textarea.focus();
491                 selected = document.selection.createRange();
492                 if (BBcode == "url"){
493                         selected.text = "["+BBcode+"]" + "http://" +  selected.text + "[/"+BBcode+"]";
494                         } else                  
495                 selected.text = "["+BBcode+"]" + selected.text + "[/"+BBcode+"]";
496         } else if (textarea.selectionStart || textarea.selectionStart == "0") {
497                 var start = textarea.selectionStart;
498                 var end = textarea.selectionEnd;
499                 if (BBcode == "url"){
500                         textarea.value = textarea.value.substring(0, start) + "["+BBcode+"]" + "http://" + textarea.value.substring(start, end) + "[/"+BBcode+"]" + textarea.value.substring(end, textarea.value.length);
501                         } else
502                 textarea.value = textarea.value.substring(0, start) + "["+BBcode+"]" + textarea.value.substring(start, end) + "[/"+BBcode+"]" + textarea.value.substring(end, textarea.value.length);
503         }
504         return true;
505 }
506 </script> ';