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