]> 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.025)
7  * Author: 
8  */
9
10 $a = get_app();
11 $a->theme_info = array(
12     'family' => 'diabook',
13         'version' => '1.025'
14 );
15
16 function diabook_init(&$a) {
17         
18 //print diabook-version for debugging
19 $diabook_version = "Diabook (Version: 1.025)";
20 $a->page['htmlhead'] .= sprintf('<script "%s" ></script>', $diabook_version);
21
22 //change css on network and profilepages
23 $cssFile = null;
24
25 $resolution=false;
26 $resolution = get_pconfig(local_user(), "diabook", "resolution");
27 if ($resolution===false) $resolution="normal";
28
29 //Add META viewport tag respecting the resolution to header for tablets
30 if ($resolution=="wide") {
31   $a->page['htmlhead'] .= '<meta name="viewport" content="width=1200" />';
32 } else {
33   $a->page['htmlhead'] .= '<meta name="viewport" content="width=980" />';
34 }
35
36
37 $color = false;
38 $site_color = get_config("diabook", "color" );
39 if (local_user()) {$color = get_pconfig(local_user(), "diabook", "color");}
40 if ($color===false) $color=$site_color;
41 if ($color===false) $color="diabook";
42
43 if ($color=="diabook") $color_path = "/";
44 if ($color=="aerith") $color_path = "/diabook-aerith/";
45 if ($color=="blue") $color_path = "/diabook-blue/";
46 if ($color=="red") $color_path = "/diabook-red/";
47 if ($color=="pink") $color_path = "/diabook-pink/";
48 if ($color=="green") $color_path = "/diabook-green/";
49 if ($color=="dark") $color_path = "/diabook-dark/";
50
51
52         //profile_side at networkpages
53         if ($a->argv[0] === "network" && local_user()){
54
55         // USER MENU
56         if(local_user()) {
57                 
58                 $r = q("SELECT micro FROM contact WHERE uid=%d AND self=1", intval($a->user['uid']));
59                                 
60                 $userinfo = array(
61                                         'icon' => (count($r) ? $r[0]['micro']: $a->get_baseurl()."/images/default-profile-mm.jpg"),
62                                         'name' => $a->user['username'],
63                                 );      
64                 $ps = array('usermenu'=>array());
65                 $ps['usermenu']['status'] = Array('profile/' . $a->user['nickname'], t('Home'), "", t('Your posts and conversations'));
66                 $ps['usermenu']['profile'] = Array('profile/' . $a->user['nickname']. '?tab=profile', t('Profile'), "", t('Your profile page'));
67                 $ps['usermenu']['contacts'] = Array('contacts' , t('Contacts'), "", t('Your contacts'));                                
68                 $ps['usermenu']['photos'] = Array('photos/' . $a->user['nickname'], t('Photos'), "", t('Your photos'));
69                 $ps['usermenu']['events'] = Array('events/', t('Events'), "", t('Your events'));
70                 $ps['usermenu']['notes'] = Array('notes/', t('Personal notes'), "", t('Your personal photos'));
71                 $ps['usermenu']['community'] = Array('community/', t('Community'), "", "");
72                 $ps['usermenu']['pgroups'] = Array('http://dir.friendica.com/directory/forum', t('Community Pages'), "", "");
73
74                 $tpl = get_markup_template('profile_side.tpl');
75
76                 $a->page['aside'] = replace_macros($tpl, array(
77                                 '$userinfo' => $userinfo,
78                                 '$ps' => $ps,
79                         )).$a->page['aside'];
80
81         }
82         
83         $ccCookie = $_COOKIE['close_pages'] + $_COOKIE['close_profiles'] + $_COOKIE['close_helpers'] + $_COOKIE['close_services'] + $_COOKIE['close_friends'] + $_COOKIE['close_twitter'] + $_COOKIE['close_lastusers'] + $_COOKIE['close_lastphotos'] + $_COOKIE['close_lastlikes'];
84         
85         if($ccCookie != "9") {
86         // COMMUNITY
87         diabook_community_info();
88
89         // CUSTOM CSS
90         if($resolution == "normal") {$cssFile = $a->get_baseurl($ssl_state)."/view/theme/diabook".$color_path."style-network.css";}
91         if($resolution == "wide") {$cssFile = $a->get_baseurl($ssl_state)."/view/theme/diabook".$color_path."style-network-wide.css";}
92         }
93         }
94
95
96
97         //right_aside at profile pages
98         if ($a->argv[0].$a->argv[1] === "profile".$a->user['nickname']){
99         if($ccCookie != "9") {
100         // COMMUNITY
101         diabook_community_info();
102         
103         // CUSTOM CSS
104         if($resolution == "normal") {$cssFile = $a->get_baseurl($ssl_state)."/view/theme/diabook".$color_path."style-profile.css";}
105         if($resolution == "wide") {$cssFile = $a->get_baseurl($ssl_state)."/view/theme/diabook".$color_path."style-profile-wide.css";}
106         
107         }
108         }
109         
110         //js scripts
111         //load jquery.cookie.js
112         $cookieJS = $a->get_baseurl($ssl_state)."/view/theme/diabook/js/jquery.cookie.js";
113         $a->page['htmlhead'] .= sprintf('<script language="JavaScript" src="%s"></script>', $cookieJS);
114         
115         //load jquery.ae.image.resize.js
116         $imageresizeJS = $a->get_baseurl($ssl_state)."/view/theme/diabook/js/jquery.ae.image.resize.js";
117         $a->page['htmlhead'] .= sprintf('<script language="JavaScript" src="%s" ></script>', $imageresizeJS);
118         
119         //load jquery.ui.js
120         $jqueryuiJS = $a->get_baseurl($ssl_state)."/view/theme/diabook/js/jquery-ui-1.8.20.custom.min.js";
121         $a->page['htmlhead'] .= sprintf('<script language="JavaScript" src="%s" ></script>', $jqueryuiJS);
122         
123         //load jquery.twitter.search.js
124         if($_COOKIE['close_twitter'] != "1") {
125         $twitterJS = $a->get_baseurl($ssl_state)."/view/theme/diabook/js/jquery.twitter.search.js";
126         $a->page['htmlhead'] .= sprintf('<script language="JavaScript" src="%s" ></script>', $twitterJS);
127         }
128         
129         $a->page['htmlhead'] .= '
130         <script>
131         
132          $(function() {
133                 $("a.lightbox").fancybox(); // Select all links with lightbox class
134                 });
135            
136          $(window).load(function() {
137                 var footer_top = $(document).height() - 30;
138                 $("div#footerbox").attr("style", "border-top: 1px solid #D2D2D2; width: 70%;right: 15%;position: absolute;top:"+footer_top+"px;");
139          });
140          
141          
142         
143         </script>';
144         
145         //check if twitterbox is active and print
146         if($_COOKIE['close_twitter'] != "1") {
147                 $a->page['htmlhead'] .= '
148                 <script>
149                 $(function() {
150                 $("#twitter").twitterSearch({               
151                 term: "friendica",
152                 animInSpeed: 250,
153                 bird:    false, 
154                 avatar:  false, 
155                 colorExterior: "#fff",
156                 title: "Last Tweets",
157                 timeout: 10000          });
158                 });
159                 </script>';}
160                         
161         //check if community_home-plugin is activated and change css
162         $nametocheck = "communityhome";
163         $r = q("select id from addon where name = '%s' and installed = 1", dbesc($nametocheck));
164         if(count($r) == "1") {
165         
166         $a->page['htmlhead'] .= '
167         <script>
168         $(document).ready(function() {
169         $("div#login-submit-wrapper").attr("style","padding-top: 120px;");
170         });
171         </script>';     
172         }
173         //comment-edit-wrapper on photo_view
174         if ($a->argv[0].$a->argv[2] === "photos"."image"){
175         $a->page['htmlhead'] .= '
176         <script>
177                 $(function(){
178                 $(".comment-edit-form").css("display","table");
179                         });
180     </script>';
181         }
182         //restore right hand col at settingspage
183         if($a->argv[0] === "settings" && local_user()) {
184         $a->page['htmlhead'] .= ' 
185         <script>
186         function restore_boxes(){
187         $.cookie("close_pages","2", { expires: 365, path: "/" });
188         $.cookie("close_helpers","2", { expires: 365, path: "/" });
189         $.cookie("close_profiles","2", { expires: 365, path: "/" });
190         $.cookie("close_services","2", { expires: 365, path: "/" });
191         $.cookie("close_friends","2", { expires: 365, path: "/" });
192         $.cookie("close_twitter","2", { expires: 365, path: "/" });
193         $.cookie("close_lastusers","2", { expires: 365, path: "/" });
194         $.cookie("close_lastphotos","2", { expires: 365, path: "/" });
195         $.cookie("close_lastlikes","2", { expires: 365, path: "/" });
196         $.cookie("Boxorder",null, { expires: 365, path: "/" });
197         alert("Right-hand column was restored. Please refresh your browser");
198    }
199         </script>';}
200         
201         if ($a->argv[0].$a->argv[1] === "profile".$a->user['nickname'] or $a->argv[0] === "network" && local_user()){
202         $a->page['htmlhead'] .= '
203         <script>
204
205         $(function() {
206         $(".oembed.photo img").aeImageResize({height: 400, width: 400});
207         });
208         </script>';
209         
210         if($ccCookie != "9") {
211         $a->page['htmlhead'] .= '
212         <script>
213         $("right_aside").ready(function(){
214         
215         if($.cookie("close_pages") == "1") 
216                 {
217                 document.getElementById( "close_pages" ).style.display = "none";
218                         };
219                         
220         if($.cookie("close_profiles") == "1") 
221                 {
222                 document.getElementById( "close_profiles" ).style.display = "none";
223                         };
224         
225         if($.cookie("close_helpers") == "1") 
226                 {
227                 document.getElementById( "close_helpers" ).style.display = "none";
228                         };
229                         
230         if($.cookie("close_services") == "1") 
231                 {
232                 document.getElementById( "close_services" ).style.display = "none";
233                         };
234                         
235         if($.cookie("close_friends") == "1") 
236                 {
237                 document.getElementById( "close_friends" ).style.display = "none";
238                         };
239         
240         if($.cookie("close_twitter") == "1") 
241                 {
242                 document.getElementById( "twitter" ).style.display = "none";
243                         };      
244                         
245         if($.cookie("close_lastusers") == "1") 
246                 {
247                 document.getElementById( "close_lastusers" ).style.display = "none";
248                         };
249                         
250         if($.cookie("close_lastphotos") == "1") 
251                 {
252                 document.getElementById( "close_lastphotos" ).style.display = "none";
253                         };
254                         
255         if($.cookie("close_lastlikes") == "1") 
256                 {
257                 document.getElementById( "close_lastlikes" ).style.display = "none";
258                         };}
259
260         );
261
262         function close_pages(){
263          document.getElementById( "close_pages" ).style.display = "none";
264         $.cookie("close_pages","1", { expires: 365, path: "/" });
265         };
266  
267         function close_profiles(){
268         document.getElementById( "close_profiles" ).style.display = "none";
269         $.cookie("close_profiles","1", { expires: 365, path: "/" });
270         };
271  
272         function close_helpers(){
273         document.getElementById( "close_helpers" ).style.display = "none";
274         $.cookie("close_helpers","1", { expires: 365, path: "/" });
275         };
276
277         function close_services(){
278         document.getElementById( "close_services" ).style.display = "none";
279         $.cookie("close_services","1", { expires: 365, path: "/" });
280         };
281  
282         function close_friends(){
283          document.getElementById( "close_friends" ).style.display = "none";
284          $.cookie("close_friends","1", { expires: 365, path: "/" });
285          };
286  
287         function close_twitter(){
288         document.getElementById( "twitter" ).style.display = "none";
289          $.cookie("close_twitter","1", { expires: 365, path: "/" });
290         };
291  
292         function close_lastusers(){
293          document.getElementById( "close_lastusers" ).style.display = "none";
294         $.cookie("close_lastusers","1", { expires: 365, path: "/" });
295          };
296
297         function close_lastphotos(){
298         document.getElementById( "close_lastphotos" ).style.display = "none";
299          $.cookie("close_lastphotos","1", { expires: 365, path: "/" });
300          };
301  
302         function close_lastlikes(){
303          document.getElementById( "close_lastlikes" ).style.display = "none";
304          $.cookie("close_lastlikes","1", { expires: 365, path: "/" });
305          };
306         </script>';}
307         }
308         //end js scripts
309
310         // custom css
311         if (!is_null($cssFile)) $a->page['htmlhead'] .= sprintf('<link rel="stylesheet" type="text/css" href="%s" />', $cssFile);
312
313         //footer
314         $tpl = get_markup_template('footer.tpl');
315         $a->page['footer'] .= replace_macros($tpl, array());
316         
317         //
318         js_in_foot();
319 }
320
321
322  function diabook_community_info() {
323         $a = get_app();
324         // comunity_profiles
325         if($_COOKIE['close_profiles'] != "1") {
326         $aside['$comunity_profilest_title'] = t('Community Profiles');
327         $aside['$comunity_profiles_items'] = array();
328         $r = q("select gcontact.* from gcontact left join glink on glink.gcid = gcontact.id 
329                           where glink.cid = 0 and glink.uid = 0 order by rand() limit 9");
330         $tpl = file_get_contents( dirname(__file__).'/ch_directory_item.tpl');
331         if(count($r)) {
332                 $photo = 'photo';
333                 foreach($r as $rr) {
334                         $profile_link = $a->get_baseurl() . '/profile/' . ((strlen($rr['nickname'])) ? $rr['nickname'] : $rr['profile_uid']);
335                         $entry = replace_macros($tpl,array(
336                                 '$id' => $rr['id'],
337                                 '$profile-link' => zrl($rr['url']),
338                                 '$photo' => $rr[$photo],
339                                 '$alt-text' => $rr['name'],
340                         ));
341                         $aside['$comunity_profiles_items'][] = $entry;
342                 }
343         }}
344         
345         // last 12 users
346         if($_COOKIE['close_lastusers'] != "1") {
347         $aside['$lastusers_title'] = t('Last users');
348         $aside['$lastusers_items'] = array();
349         $sql_extra = "";
350         $publish = (get_config('system','publish_all') ? '' : " AND `publish` = 1 " );
351         $order = " ORDER BY `register_date` DESC ";
352
353         $r = q("SELECT `profile`.*, `profile`.`uid` AS `profile_uid`, `user`.`nickname`
354                         FROM `profile` LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid` 
355                         WHERE `is-default` = 1 $publish AND `user`.`blocked` = 0 $sql_extra $order LIMIT %d , %d ",
356                 0,
357                 9
358         );
359         $tpl = file_get_contents( dirname(__file__).'/ch_directory_item.tpl');
360         if(count($r)) {
361                 $photo = 'thumb';
362                 foreach($r as $rr) {
363                         $profile_link = $a->get_baseurl() . '/profile/' . ((strlen($rr['nickname'])) ? $rr['nickname'] : $rr['profile_uid']);
364                         $entry = replace_macros($tpl,array(
365                                 '$id' => $rr['id'],
366                                 '$profile-link' => $profile_link,
367                                 '$photo' => $rr[$photo],
368                                 '$alt-text' => $rr['name'],
369                         ));
370                         $aside['$lastusers_items'][] = $entry;
371                 }
372         }}
373         
374         // last 10 liked items
375         if($_COOKIE['close_lastlikes'] != "1") {
376         $aside['$like_title'] = t('Last likes');
377         $aside['$like_items'] = array();
378         $r = q("SELECT `T1`.`created`, `T1`.`liker`, `T1`.`liker-link`, `item`.* FROM 
379                         (SELECT `parent-uri`, `created`, `author-name` AS `liker`,`author-link` AS `liker-link` 
380                                 FROM `item` WHERE `verb`='http://activitystrea.ms/schema/1.0/like' GROUP BY `parent-uri` ORDER BY `created` DESC) AS T1
381                         INNER JOIN `item` ON `item`.`uri`=`T1`.`parent-uri` 
382                         WHERE `T1`.`liker-link` LIKE '%s%%' OR `item`.`author-link` LIKE '%s%%'
383                         GROUP BY `uri`
384                         ORDER BY `T1`.`created` DESC
385                         LIMIT 0,5",
386                         $a->get_baseurl(),$a->get_baseurl()
387                         );
388
389         foreach ($r as $rr) {
390                 $author  = '<a href="' . $rr['liker-link'] . '">' . $rr['liker'] . '</a>';
391                 $objauthor =  '<a href="' . $rr['author-link'] . '">' . $rr['author-name'] . '</a>';
392                 
393                 //var_dump($rr['verb'],$rr['object-type']); killme();
394                 switch($rr['verb']){
395                         case 'http://activitystrea.ms/schema/1.0/post':
396                                 switch ($rr['object-type']){
397                                         case 'http://activitystrea.ms/schema/1.0/event':
398                                                 $post_type = t('event');
399                                                 break;
400                                         default:
401                                                 $post_type = t('status');
402                                 }
403                                 break;
404                         default:
405                                 if ($rr['resource-id']){
406                                         $post_type = t('photo');
407                                         $m=array();     preg_match("/\[url=([^]]*)\]/", $rr['body'], $m);
408                                         $rr['plink'] = $m[1];
409                                 } else {
410                                         $post_type = t('status');
411                                 }
412                 }
413                 $plink = '<a href="' . $rr['plink'] . '">' . $post_type . '</a>';
414
415                 $aside['$like_items'][] = sprintf( t('%1$s likes %2$s\'s %3$s'), $author, $objauthor, $plink);
416                 
417         }}
418         
419         // last 12 photos
420         if($_COOKIE['close_photos'] != "1") {
421         $aside['$photos_title'] = t('Last photos');
422         $aside['$photos_items'] = array();
423         $r = q("SELECT `photo`.`id`, `photo`.`resource-id`, `photo`.`scale`, `photo`.`desc`, `user`.`nickname`, `user`.`username` FROM 
424                                 (SELECT `resource-id`, MAX(`scale`) as maxscale FROM `photo` 
425                                         WHERE `profile`=0 AND `contact-id`=0 AND `album` NOT IN ('Contact Photos', '%s', 'Profile Photos', '%s')
426                                                 AND `allow_cid`='' AND `allow_gid`='' AND `deny_cid`='' AND `deny_gid`='' GROUP BY `resource-id`) AS `t1`
427                                 INNER JOIN `photo` ON `photo`.`resource-id`=`t1`.`resource-id` AND `photo`.`scale` = `t1`.`maxscale`,
428                                 `user` 
429                                 WHERE `user`.`uid` = `photo`.`uid`
430                                 AND `user`.`blockwall`=0
431                                 AND `user`.`hidewall`=0
432                                 ORDER BY `photo`.`edited` DESC
433                                 LIMIT 0, 9",
434                                 dbesc(t('Contact Photos')),
435                                 dbesc(t('Profile Photos'))
436                                 );
437                 if(count($r)) {
438                 $tpl = file_get_contents( dirname(__file__).'/ch_directory_item.tpl');
439                 foreach($r as $rr) {
440                         $photo_page = $a->get_baseurl() . '/photos/' . $rr['nickname'] . '/image/' . $rr['resource-id'];
441                         $photo_url = $a->get_baseurl() . '/photo/' .  $rr['resource-id'] . '-' . $rr['scale'] .'.jpg';
442                 
443                         $entry = replace_macros($tpl,array(
444                                 '$id' => $rr['id'],
445                                 '$profile-link' => $photo_page,
446                                 '$photo' => $photo_url,
447                                 '$alt-text' => $rr['username']." : ".$rr['desc'],
448                         ));
449
450                         $aside['$photos_items'][] = $entry;
451                 }
452         }}
453         
454    //right_aside FIND FRIENDS
455    if($_COOKIE['close_friends'] != "1") {
456         if(local_user()) {
457         $nv = array();
458         $nv['title'] = Array("", t('Find Friends'), "", "");
459         $nv['directory'] = Array('directory', t('Local Directory'), "", "");
460         $nv['global_directory'] = Array('http://dir.friendica.com/', t('Global Directory'), "", "");
461         $nv['match'] = Array('match', t('Similar Interests'), "", "");
462         $nv['suggest'] = Array('suggest', t('Friend Suggestions'), "", "");
463         $nv['invite'] = Array('invite', t('Invite Friends'), "", "");
464         
465         $nv['search'] = '<form name="simple_bar" method="get" action="http://dir.friendika.com/directory">
466                                                 <span class="sbox_l"></span>
467                                                 <span class="sbox">
468                                                 <input type="text" name="search" size="13" maxlength="50">
469                                                 </span>
470                                                 <span class="sbox_r" id="srch_clear"></span>';
471         
472         $aside['$nv'] = $nv;
473         }}
474    
475    //Community_Pages at right_aside
476    if($_COOKIE['close_pages'] != "1") {
477    if(local_user()) {
478    $page = '
479                         <h3 style="margin-top:0px;">'.t("Community Pages").'<a id="close_pages_icon"  onClick="close_pages()" class="icon close_box" title="close"></a></h3></div>
480                         <div id=""><ul style="margin-left: 7px;margin-top: 0px;padding-left: 0px;padding-top: 0px;">';
481
482         $pagelist = array();
483
484         $contacts = q("SELECT `id`, `url`, `name`, `micro`FROM `contact`
485                         WHERE `network`= 'dfrn' AND `forum` = 1 AND `uid` = %d
486                         ORDER BY `name` ASC",
487                         intval($a->user['uid'])
488         );
489
490         $pageD = array();
491
492         // Look if the profile is a community page
493         foreach($contacts as $contact) {
494                 $pageD[] = array("url"=>$contact["url"], "name"=>$contact["name"], "id"=>$contact["id"], "micro"=>$contact['micro']);
495         };
496         
497
498         $contacts = $pageD;
499
500         foreach($contacts as $contact) {
501                 $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; word-wrap: break-word; width: 132px;" title="' . $contact['url'] . '" class="label" target="external-link">'.
502                                 $contact["name"]."</a></li>";
503         }
504         $page .= '</ul></div>';
505         //if (sizeof($contacts) > 0)
506                 $aside['$page'] = $page;        
507         }}
508   //END Community Page  
509   
510   //helpers
511   if($_COOKIE['close_helpers'] != "1") {
512    $helpers = array();
513         $helpers['title'] = Array("", t('Help or @NewHere ?'), "", "");
514         $aside['$helpers'] = $helpers;
515         }
516    //end helpers
517    //connectable services
518    if($_COOKIE['close_services'] != "1") {
519    $con_services = array();
520         $con_services['title'] = Array("", t('Connect Services'), "", "");
521         $aside['$con_services'] = $con_services;
522         }
523    //end connectable services
524    //get_baseurl
525    $url = $a->get_baseurl($ssl_state);   
526    $aside['$url'] = $url;
527         //print right_aside
528         $tpl = file_get_contents(dirname(__file__).'/communityhome.tpl');
529         $a->page['right_aside'] = replace_macros($tpl, $aside);
530         
531  }
532
533  function js_in_foot() {
534         /** @purpose insert stuff in bottom of page
535          */
536         $a = get_app();
537         $baseurl = $a->get_baseurl($ssl_state);
538         $bottom['$baseurl'] = $baseurl;
539         $tpl = file_get_contents(dirname(__file__) . '/bottom.tpl');
540         $a->page['footer'] = $a->page['footer'].replace_macros($tpl, $bottom);
541  }
542
543
544
545
546
547
548
549  
550  
551
552  
553