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