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