]> git.mxchange.org Git - friendica.git/blob - view/theme/diabook/theme.php
Merge branch 'master' of git://github.com/friendica/friendica
[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.027)
7  * Author: 
8  */
9
10 $a = get_app();
11
12
13 function diabook_init(&$a) {
14         
15 //print diabook-version for debugging
16 $diabook_version = "Diabook (Version: 1.027)";
17 $a->page['htmlhead'] .= sprintf('<META NAME=generator CONTENT="%s"/>', $diabook_version);
18
19 //init css on network and profilepages
20 $cssFile = null;
21
22 // Preload config
23 load_config("diabook");
24 load_pconfig(local_user(), "diabook");
25
26 //get statuses of boxes at right-hand-column
27 $close_pages = false;
28 $site_close_pages = get_config("diabook", "close_pages" );
29 if (local_user()) {$close_pages = get_pconfig(local_user(), "diabook", "close_pages");}
30 if ($close_pages===false) $close_pages=$site_close_pages;
31 if ($close_pages===false) $close_pages="1";
32
33 $close_profiles = false;
34 $site_close_profiles = get_config("diabook", "close_profiles" );
35 if (local_user()) {$close_profiles = get_pconfig(local_user(), "diabook", "close_profiles");}
36 if ($close_profiles===false) $close_profiles=$site_close_profiles;
37 if ($close_profiles===false) $close_profiles="0";
38
39 $close_helpers = false;
40 $site_close_helpers = get_config("diabook", "close_helpers" );
41 if (local_user()) {$close_helpers = get_pconfig(local_user(), "diabook", "close_helpers");}
42 if ($close_helpers===false) $close_helpers=$site_close_helpers;
43 if ($close_helpers===false) $close_helpers="0";
44
45 $close_services = false;
46 $site_close_services = get_config("diabook", "close_services" );
47 if (local_user()) {$close_services = get_pconfig(local_user(), "diabook", "close_services");}
48 if ($close_services===false) $close_services=$site_close_services;
49 if ($close_services===false) $close_services="0";
50
51 $close_friends = false;
52 $site_close_friends = get_config("diabook", "close_friends" );
53 if (local_user()) {$close_friends = get_pconfig(local_user(), "diabook", "close_friends");}
54 if ($close_friends===false) $close_friends=$site_close_friends;
55 if ($close_friends===false) $close_friends="0";
56
57 $close_lastusers = false;
58 $site_close_lastusers = get_config("diabook", "close_lastusers" );
59 if (local_user()) {$close_lastusers = get_pconfig(local_user(), "diabook", "close_lastusers");}
60 if ($close_lastusers===false) $close_lastusers=$site_close_lastusers;
61 if ($close_lastusers===false) $close_lastusers="0";
62
63 $close_lastphotos = false;
64 $site_close_lastphotos = get_config("diabook", "close_lastphotos" );
65 if (local_user()) {$close_lastphotos = get_pconfig(local_user(), "diabook", "close_lastphotos");}
66 if ($close_lastphotos===false) $close_lastphotos=$site_close_lastphotos;
67 if ($close_lastphotos===false) $close_lastphotos="0";
68
69 $close_lastlikes = false;
70 $site_close_lastlikes = get_config("diabook", "close_lastlikes" );
71 if (local_user()) {$close_lastlikes = get_pconfig(local_user(), "diabook", "close_lastlikes");}
72 if ($close_lastlikes===false) $close_lastlikes=$site_close_lastlikes;
73 if ($close_lastlikes===false) $close_lastlikes="0";
74
75 $close_twitter = false;
76 $site_close_twitter = get_config("diabook", "close_twitter" );
77 if (local_user()) {$close_twitter = get_pconfig(local_user(), "diabook", "close_twitter");}
78 if ($close_twitter===false) $close_twitter=$site_close_twitter;
79 if ($close_twitter===false) $close_twitter="1";
80
81 $close_mapquery = false;
82 $site_close_mapquery = get_config("diabook", "close_mapquery" );
83 if (local_user()) {$close_mapquery = get_pconfig(local_user(), "diabook", "close_mapquery");}
84 if ($close_mapquery===false) $close_mapquery=$site_close_mapquery;
85 if ($close_mapquery===false) $close_mapquery="1";
86
87 //get resolution (wide/normal)
88 $resolution=false;
89 $resolution = get_pconfig(local_user(), "diabook", "resolution");
90 if ($resolution===false) $resolution="normal";
91
92 //Add META viewport tag respecting the resolution to header for tablets
93 if ($resolution=="wide") {
94   $a->page['htmlhead'] .= '<meta name="viewport" content="width=1200" />';
95 } else {
96   $a->page['htmlhead'] .= '<meta name="viewport" content="width=980" />';
97 }
98 //get colour-scheme
99 $color = false;
100 $site_color = get_config("diabook", "color" );
101 if (local_user()) {$color = get_pconfig(local_user(), "diabook", "color");}
102 if ($color===false) $color=$site_color;
103 if ($color===false) $color="diabook";
104
105 if ($color=="diabook") $color_path = "/";
106 if ($color=="aerith") $color_path = "/diabook-aerith/";
107 if ($color=="blue") $color_path = "/diabook-blue/";
108 if ($color=="red") $color_path = "/diabook-red/";
109 if ($color=="pink") $color_path = "/diabook-pink/";
110 if ($color=="green") $color_path = "/diabook-green/";
111 if ($color=="dark") $color_path = "/diabook-dark/";
112
113         
114         //build personal menue at lefthand-col (id="profile_side") and boxes at right-hand-col at networkpages
115         if ($a->argv[0] === "network" && local_user()){
116
117         // USER MENU
118         if(local_user()) {
119                 
120                 $r = q("SELECT micro FROM contact WHERE uid=%d AND self=1", intval($a->user['uid']));
121                                 
122                 $userinfo = array(
123                                         'icon' => (count($r) ? $r[0]['micro']: $a->get_baseurl()."/images/default-profile-mm.jpg"),
124                                         'name' => $a->user['username'],
125                                 );      
126                 $ps = array('usermenu'=>array());
127                 $ps['usermenu']['status'] = Array('profile/' . $a->user['nickname'], t('Home'), "", t('Your posts and conversations'));
128                 $ps['usermenu']['profile'] = Array('profile/' . $a->user['nickname']. '?tab=profile', t('Profile'), "", t('Your profile page'));
129                 $ps['usermenu']['contacts'] = Array('contacts' , t('Contacts'), "", t('Your contacts'));                                
130                 $ps['usermenu']['photos'] = Array('photos/' . $a->user['nickname'], t('Photos'), "", t('Your photos'));
131                 $ps['usermenu']['events'] = Array('events/', t('Events'), "", t('Your events'));
132                 $ps['usermenu']['notes'] = Array('notes/', t('Personal notes'), "", t('Your personal photos'));
133                 $ps['usermenu']['community'] = Array('community/', t('Community'), "", "");
134                 $ps['usermenu']['pgroups'] = Array('http://dir.friendica.com/directory/forum', t('Community Pages'), "", "");
135
136                 $tpl = get_markup_template('profile_side.tpl');
137
138                 $a->page['aside'] = replace_macros($tpl, array(
139                                 '$userinfo' => $userinfo,
140                                 '$ps' => $ps,
141                         )).$a->page['aside'];
142
143         }
144         
145         $ccCookie = $close_pages + $close_mapquery + $close_profiles + $close_helpers + $close_services + $close_friends + $close_twitter + $close_lastusers + $close_lastphotos + $close_lastlikes;
146         //if all boxes closed, dont build right-hand-col and dont use special css
147         if($ccCookie != "10") {
148         // COMMUNITY
149         diabook_community_info();
150
151         // CUSTOM CSS
152         if($resolution == "normal") {$cssFile = $a->get_baseurl($ssl_state)."/view/theme/diabook".$color_path."style-network.css";}
153         if($resolution == "wide") {$cssFile = $a->get_baseurl($ssl_state)."/view/theme/diabook".$color_path."style-network-wide.css";}
154         }
155         }
156
157
158
159         //build boxes at right_aside at profile pages
160         if ($a->argv[0].$a->argv[1] === "profile".$a->user['nickname']){
161         if($ccCookie != "10") {
162         // COMMUNITY
163         diabook_community_info();
164         
165         // CUSTOM CSS
166         if($resolution == "normal") {$cssFile = $a->get_baseurl($ssl_state)."/view/theme/diabook".$color_path."style-profile.css";}
167         if($resolution == "wide") {$cssFile = $a->get_baseurl($ssl_state)."/view/theme/diabook".$color_path."style-profile-wide.css";}
168         
169         }
170         }
171         
172         //write js-scripts to the head-section:
173         //load jquery.cookie.js
174         $cookieJS = $a->get_baseurl($ssl_state)."/view/theme/diabook/js/jquery.cookie.js";
175         $a->page['htmlhead'] .= sprintf('<script type="text/javascript" src="%s"></script>', $cookieJS);
176         //load jquery.ae.image.resize.js
177         $imageresizeJS = $a->get_baseurl($ssl_state)."/view/theme/diabook/js/jquery.ae.image.resize.min.js";
178         $a->page['htmlhead'] .= sprintf('<script type="text/javascript" src="%s" ></script>', $imageresizeJS);
179         //load jquery.ui.js
180         if($ccCookie != "10") {
181         $jqueryuiJS = $a->get_baseurl($ssl_state)."/view/theme/diabook/js/jquery-ui-1.8.20.custom.min.js";
182         $a->page['htmlhead'] .= sprintf('<script type="text/javascript" src="%s" ></script>', $jqueryuiJS);
183         $jqueryuicssJS = $a->get_baseurl($ssl_state)."/view/theme/diabook/jquery-ui-1.8.20.custom.css";
184         $a->page['htmlhead'] .= sprintf('<link rel="stylesheet" type="text/css" href="%s" />', $jqueryuicssJS);
185         }       
186         //load jquery.twitter.search.js
187         if($close_twitter != "1") {
188         $twitterJS = $a->get_baseurl($ssl_state)."/view/theme/diabook/js/jquery.twitter.search.js";
189         $a->page['htmlhead'] .= sprintf('<script type="text/javascript" src="%s" ></script>', $twitterJS);
190         }
191         //load jquery.mapquery.js
192         if($close_mapquery != "1") {
193         $mqtmplJS = $a->get_baseurl($ssl_state)."/view/theme/diabook/js/jquery.tmpl.js";
194         $a->page['htmlhead'] .= sprintf('<script type="text/javascript" src="%s" ></script>', $mqtmplJS);
195         $mapqueryJS = $a->get_baseurl($ssl_state)."/view/theme/diabook/js/jquery.mapquery.core.js";
196         $a->page['htmlhead'] .= sprintf('<script type="text/javascript" src="%s" ></script>', $mapqueryJS);
197         $openlayersJS = $a->get_baseurl($ssl_state)."/view/theme/diabook/js/OpenLayers.js";
198         $a->page['htmlhead'] .= sprintf('<script type="text/javascript" src="%s" ></script>', $openlayersJS);
199         $mqmouseposJS = $a->get_baseurl($ssl_state)."/view/theme/diabook/js/jquery.mapquery.mqMousePosition.js";
200         $a->page['htmlhead'] .= sprintf('<script type="text/javascript" src="%s" ></script>', $mqmouseposJS);
201         $mousewheelJS = $a->get_baseurl($ssl_state)."/view/theme/diabook/js/jquery.mousewheel.js";
202         $a->page['htmlhead'] .= sprintf('<script type="text/javascript" src="%s" ></script>', $mousewheelJS);
203    $mqlegendJS = $a->get_baseurl($ssl_state)."/view/theme/diabook/js/jquery.mapquery.legend.js";
204         $a->page['htmlhead'] .= sprintf('<script type="text/javascript" src="%s" ></script>', $mqlegendJS);
205         $mqlayermanagerJS = $a->get_baseurl($ssl_state)."/view/theme/diabook/js/jquery.mapquery.mqLayerManager.js";
206         $a->page['htmlhead'] .= sprintf('<script type="text/javascript" src="%s" ></script>', $mqlayermanagerJS);
207         }
208         
209         $a->page['htmlhead'] .= '
210         <script>
211          $(function() {
212                 $("a.lightbox").fancybox(); // Select all links with lightbox class
213                 $("a#twittersettings-link").fancybox({onClosed: function() { $("#twittersettings").attr("style","display: none;");}} ); 
214            $("a#mapcontrol-link").fancybox({onClosed: function() { $("#mapcontrol").attr("style","display: none;");}} ); 
215            $("a#closeicon").fancybox({onClosed: function() { $("#boxsettings").attr("style","display: none;");}} );      
216                 });
217            
218          $(window).load(function() {
219                 var footer_top = $(document).height() - 30;
220                 $("div#footerbox").attr("style", "border-top: 1px solid #D2D2D2; width: 70%;right: 15%;position: absolute;top:"+footer_top+"px;");
221          });
222         </script>';
223         
224         //check if mapquerybox is active and print
225         if($close_mapquery != "1") {
226                 $ELZoom=false;
227                 $ELPosX=false;
228                 $ELPosy=false;
229                 $site_ELZoom = get_config("diabook", "ELZoom" );
230                 $site_ELPosX = get_config("diabook", "ELPosX" );
231                 $site_ELPosY = get_config("diabook", "ELPosY" );
232                 $ELZoom = get_pconfig(local_user(), "diabook", "ELZoom");
233                 $ELPosX = get_pconfig(local_user(), "diabook", "ELPosX");
234                 $ELPosY = get_pconfig(local_user(), "diabook", "ELPosY");
235                 if ($ELZoom===false) $ELZoom=$site_ELZoom;
236                 if ($ELPosX===false) $ELPosX=$site_ELPosX;
237                 if ($ELPosY===false) $ELPosY=$site_ELPosY;
238                 if ($ELZoom===false) $ELZoom="0";       
239                 if ($ELPosX===false) $ELPosX="0";               
240                 if ($ELPosY===false) $ELPosY="0";                       
241                 $a->page['htmlhead'] .= '
242                 <script>
243                 
244     $(function() {
245     $("#map").mapQuery({
246         layers:[{         //add layers to your map; you need to define at least one to be able to see anything on the map
247             type:"osm"  //add a layer of the type osm (OpenStreetMap)
248             }],
249         center:({zoom:'.$ELZoom.',position:['.$ELPosX.','.$ELPosY.']}),
250        });
251     
252     });
253          
254     function open_mapcontrol() {
255                 $("div#mapcontrol").attr("style","display: block;width:900px;height:900px;");
256                 $("#map2").mapQuery({
257                         layers:[{type:"osm", label:"OpenStreetMap" },
258                                           {type:"wms", label:"Population density 2010", legend:{url:"http://mapserver.edugis.nl/cgi-bin/mapserv?map=maps/edugis/cache/population.map&version=1.1.1&service=WMS&request=GetLegendGraphic&layer=Bevolkingsdichtheid_2010&format=image/png"}, url:"http://t1.edugis.nl/tiles/tilecache.py?map=maps/edugis/cache/population.map", 
259                                           layers:"Bevolkingsdichtheid_2010" },
260                                           {type:"wms", 
261                                                   label:"OpenLayers WMS", 
262                                                   url:"http://labs.metacarta.com/wms/vmap0", 
263                                                   layers:"basic" }],                    
264                         center:({zoom:'.$ELZoom.',position:['.$ELPosX.','.$ELPosY.']})}); 
265                                                                         
266                 $("#mouseposition").mqMousePosition({
267         map: "#map2",
268         x:"",
269         y:"",
270         precision:4
271                 }); 
272                 
273         $("#layermanager").mqLayerManager({map:"#map2"}); 
274         $( "div#layermanager" ).accordion({header: ".mq-layermanager-element-header"});  
275       $(".mq-layermanager-element-content").attr("style", "");          
276                 
277         map = $("#map2").mapQuery().data("mapQuery");
278         textarea = document.getElementById("id_diabook_ELZoom");
279         textarea.value = "'.$ELZoom.'";
280                 $("#map2").bind("mousewheel", function(event, delta) {
281                 if (delta > 0 && textarea.value < 18){
282                          textarea.value = textarea.value - delta*-1; }
283                 if (delta < 0 && textarea.value > "0"){
284                          textarea.value = textarea.value - delta*-1; }
285                         });
286                 };
287                 </script>';
288         }
289         //check if twitterbox is active and print
290         if($close_twitter != "1") {
291                 $TSearchTerm=false;
292                 $site_TSearchTerm = get_config("diabook", "TSearchTerm" );
293                 $TSearchTerm = get_pconfig(local_user(), "diabook", "TSearchTerm");
294                 if ($TSearchTerm===false) $TSearchTerm=$site_TSearchTerm;
295                 if ($TSearchTerm===false) $TSearchTerm="friendica";             
296                 $a->page['htmlhead'] .= '
297                 <script>
298                 $(function() {
299                 $("#twitter").twitterSearch({               
300                 term: "'.$TSearchTerm.'",
301                 animInSpeed: 250,
302                 bird:    false, 
303                 avatar:  false, 
304                 colorExterior: "#fff",
305                 timeout: 10000          });
306                 });
307                 function open_twittersettings() {
308                 $("div#twittersettings").attr("style","display: block;");
309                 };
310                 </script>';}
311                         
312         //check if community_home-plugin is activated and change css.. we need this, that the submit-wrapper doesn't overlay the login-panel if communityhome-plugin is active
313         $nametocheck = "communityhome";
314         $r = q("select id from addon where name = '%s' and installed = 1", dbesc($nametocheck));
315         if(count($r) == "1" && $a->argv[0] === "home" ) {
316         
317         $a->page['htmlhead'] .= '
318         <script>
319         $(function() {
320         $("div#login-submit-wrapper").attr("style","padding-top: 120px;");
321         });
322         </script>';     
323         }
324         //comment-edit-wrapper on photo_view... we need this to workaround a global bug in photoview, where the comment-box is between the last comment the the comment before the last
325         if ($a->argv[0].$a->argv[2] === "photos"."image"){
326         $a->page['htmlhead'] .= '
327         <script>
328                 $(function(){
329                 $(".comment-edit-form").css("display","table");
330                         });
331     </script>';
332         }
333         //restore (only) the order right hand col at settingspage
334         if($a->argv[0] === "settings" && local_user()) {
335         $a->page['htmlhead'] .= ' 
336         <script>
337         function restore_boxes(){
338         $.cookie("Boxorder",null, { expires: 365, path: "/" });
339         alert("Boxorder at right-hand column was restored. Please refresh your browser");
340    }
341         </script>';}
342         
343         if ($a->argv[0].$a->argv[1] === "profile".$a->user['nickname'] or $a->argv[0] === "network" && local_user()){
344         $a->page['htmlhead'] .= '
345         <script>
346         $(function() {
347         $(".oembed.photo img").aeImageResize({height: 400, width: 400});
348         });
349         </script>';
350         
351         if($ccCookie != "10") {
352         $a->page['htmlhead'] .= '
353         <script>
354         $("right_aside").ready(function(){
355         
356         if('.$close_pages.') 
357                 {
358                 document.getElementById( "close_pages" ).style.display = "none";
359                         };
360                         
361         if('.$close_mapquery.') 
362                 {
363                 document.getElementById( "close_mapquery" ).style.display = "none";
364                         };
365                         
366         if('.$close_profiles.') 
367                 {
368                 document.getElementById( "close_profiles" ).style.display = "none";
369                         };
370         
371         if('.$close_helpers.') 
372                 {
373                 document.getElementById( "close_helpers" ).style.display = "none";
374                         };
375                         
376         if('.$close_services.') 
377                 {
378                 document.getElementById( "close_services" ).style.display = "none";
379                         };
380                         
381         if('.$close_friends.') 
382                 {
383                 document.getElementById( "close_friends" ).style.display = "none";
384                         };
385         
386         if('.$close_twitter.') 
387                 {
388                 document.getElementById( "close_twitter" ).style.display = "none";
389                         };      
390                         
391         if('.$close_lastusers.') 
392                 {
393                 document.getElementById( "close_lastusers" ).style.display = "none";
394                         };
395                         
396         if('.$close_lastphotos.') 
397                 {
398                 document.getElementById( "close_lastphotos" ).style.display = "none";
399                         };
400                         
401         if('.$close_lastlikes.') 
402                 {
403                 document.getElementById( "close_lastlikes" ).style.display = "none";
404                         };}
405
406         );
407          
408         </script>';}
409         }
410         //end js scripts
411
412         // custom css
413         if (!is_null($cssFile)) $a->page['htmlhead'] .= sprintf('<link rel="stylesheet" type="text/css" href="%s" />', $cssFile);
414         
415         //footer
416         $tpl = get_markup_template('footer.tpl');
417         $a->page['footer'] .= replace_macros($tpl, array());
418         
419         //
420         js_diabook_footer();
421 }
422
423
424  function diabook_community_info() {
425         $a = get_app();
426         
427         $close_pages = false;
428         $site_close_pages = get_config("diabook", "close_pages" );
429         if (local_user()) {$close_pages = get_pconfig(local_user(), "diabook", "close_pages");}
430         if ($close_pages===false) $close_pages=$site_close_pages;
431         if ($close_pages===false) $close_pages="1";
432         
433         $close_profiles = false;
434         $site_close_profiles = get_config("diabook", "close_profiles" );
435         if (local_user()) {$close_profiles = get_pconfig(local_user(), "diabook", "close_profiles");}
436         if ($close_profiles===false) $close_profiles=$site_close_profiles;
437         if ($close_profiles===false) $close_profiles="0";
438         
439         $close_helpers = false;
440         $site_close_helpers = get_config("diabook", "close_helpers" );
441         if (local_user()) {$close_helpers = get_pconfig(local_user(), "diabook", "close_helpers");}
442         if ($close_helpers===false) $close_helpers=$site_close_helpers;
443         if ($close_helpers===false) $close_helpers="0";
444         
445         $close_services = false;
446         $site_close_services = get_config("diabook", "close_services" );
447         if (local_user()) {$close_services = get_pconfig(local_user(), "diabook", "close_services");}
448         if ($close_services===false) $close_services=$site_close_services;
449         if ($close_services===false) $close_services="0";
450         
451         $close_friends = false;
452         $site_close_friends = get_config("diabook", "close_friends" );
453         if (local_user()) {$close_friends = get_pconfig(local_user(), "diabook", "close_friends");}
454         if ($close_friends===false) $close_friends=$site_close_friends;
455         if ($close_friends===false) $close_friends="0";
456         
457         $close_lastusers = false;
458         $site_close_lastusers = get_config("diabook", "close_lastusers" );
459         if (local_user()) {$close_lastusers = get_pconfig(local_user(), "diabook", "close_lastusers");}
460         if ($close_lastusers===false) $close_lastusers=$site_close_lastusers;
461         if ($close_lastusers===false) $close_lastusers="0";
462         
463         $close_lastphotos = false;
464         $site_close_lastphotos = get_config("diabook", "close_lastphotos" );
465         if (local_user()) {$close_lastphotos = get_pconfig(local_user(), "diabook", "close_lastphotos");}
466         if ($close_lastphotos===false) $close_lastphotos=$site_close_lastphotos;
467         if ($close_lastphotos===false) $close_lastphotos="0";
468         
469         $close_lastlikes = false;
470         $site_close_lastlikes = get_config("diabook", "close_lastlikes" );
471         if (local_user()) {$close_lastlikes = get_pconfig(local_user(), "diabook", "close_lastlikes");}
472         if ($close_lastlikes===false) $close_lastlikes=$site_close_lastlikes;
473         if ($close_lastlikes===false) $close_lastlikes="0";
474         
475         $close_twitter = false;
476         $site_close_twitter = get_config("diabook", "close_twitter" );
477         if (local_user()) {$close_twitter = get_pconfig(local_user(), "diabook", "close_twitter");}
478         if ($close_twitter===false) $close_twitter=$site_close_twitter;
479         if ($close_twitter===false) $close_twitter="1";
480         
481         $close_mapquery = false;
482         $site_close_mapquery = get_config("diabook", "close_mapquery" );
483         if (local_user()) {$close_mapquery = get_pconfig(local_user(), "diabook", "close_mapquery");}
484         if ($close_mapquery===false) $close_mapquery=$site_close_mapquery;
485         if ($close_mapquery===false) $close_mapquery="1";
486         
487
488         // comunity_profiles
489         if($close_profiles != "1") {
490         $aside['$comunity_profiles_title'] = t('Community Profiles');
491         $aside['$comunity_profiles_items'] = array();
492         $r = q("select gcontact.* from gcontact left join glink on glink.gcid = gcontact.id 
493                           where glink.cid = 0 and glink.uid = 0 order by rand() limit 9");
494         $tpl = file_get_contents( dirname(__file__).'/ch_directory_item.tpl');
495         if(count($r)) {
496                 $photo = 'photo';
497                 foreach($r as $rr) {
498                         $profile_link = $a->get_baseurl() . '/profile/' . ((strlen($rr['nickname'])) ? $rr['nickname'] : $rr['profile_uid']);
499                         $entry = replace_macros($tpl,array(
500                                 '$id' => $rr['id'],
501                                 '$profile-link' => zrl($rr['url']),
502                                 '$photo' => $rr[$photo],
503                                 '$alt-text' => $rr['name'],
504                         ));
505                         $aside['$comunity_profiles_items'][] = $entry;
506                 }
507         }}
508         
509         // last 12 users
510         if($close_lastusers != "1") {
511         $aside['$lastusers_title'] = t('Last users');
512         $aside['$lastusers_items'] = array();
513         $sql_extra = "";
514         $publish = (get_config('system','publish_all') ? '' : " AND `publish` = 1 " );
515         $order = " ORDER BY `register_date` DESC ";
516
517         $r = q("SELECT `profile`.*, `profile`.`uid` AS `profile_uid`, `user`.`nickname`
518                         FROM `profile` LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid` 
519                         WHERE `is-default` = 1 $publish AND `user`.`blocked` = 0 $sql_extra $order LIMIT %d , %d ",
520                 0,
521                 9
522         );
523         $tpl = file_get_contents( dirname(__file__).'/ch_directory_item.tpl');
524         if(count($r)) {
525                 $photo = 'thumb';
526                 foreach($r as $rr) {
527                         $profile_link = $a->get_baseurl() . '/profile/' . ((strlen($rr['nickname'])) ? $rr['nickname'] : $rr['profile_uid']);
528                         $entry = replace_macros($tpl,array(
529                                 '$id' => $rr['id'],
530                                 '$profile-link' => $profile_link,
531                                 '$photo' => $rr[$photo],
532                                 '$alt-text' => $rr['name'],
533                         ));
534                         $aside['$lastusers_items'][] = $entry;
535                 }
536         }}
537         
538         // last 10 liked items
539         if($close_lastlikes != "1") {
540         $aside['$like_title'] = t('Last likes');
541         $aside['$like_items'] = array();
542         $r = q("SELECT `T1`.`created`, `T1`.`liker`, `T1`.`liker-link`, `item`.* FROM 
543                         (SELECT `parent-uri`, `created`, `author-name` AS `liker`,`author-link` AS `liker-link` 
544                                 FROM `item` WHERE `verb`='http://activitystrea.ms/schema/1.0/like' GROUP BY `parent-uri` ORDER BY `created` DESC) AS T1
545                         INNER JOIN `item` ON `item`.`uri`=`T1`.`parent-uri` 
546                         WHERE `T1`.`liker-link` LIKE '%s%%' OR `item`.`author-link` LIKE '%s%%'
547                         GROUP BY `uri`
548                         ORDER BY `T1`.`created` DESC
549                         LIMIT 0,5",
550                         $a->get_baseurl(),$a->get_baseurl()
551                         );
552
553         foreach ($r as $rr) {
554                 $author  = '<a href="' . $rr['liker-link'] . '">' . $rr['liker'] . '</a>';
555                 $objauthor =  '<a href="' . $rr['author-link'] . '">' . $rr['author-name'] . '</a>';
556                 
557                 //var_dump($rr['verb'],$rr['object-type']); killme();
558                 switch($rr['verb']){
559                         case 'http://activitystrea.ms/schema/1.0/post':
560                                 switch ($rr['object-type']){
561                                         case 'http://activitystrea.ms/schema/1.0/event':
562                                                 $post_type = t('event');
563                                                 break;
564                                         default:
565                                                 $post_type = t('status');
566                                 }
567                                 break;
568                         default:
569                                 if ($rr['resource-id']){
570                                         $post_type = t('photo');
571                                         $m=array();     preg_match("/\[url=([^]]*)\]/", $rr['body'], $m);
572                                         $rr['plink'] = $m[1];
573                                 } else {
574                                         $post_type = t('status');
575                                 }
576                 }
577                 $plink = '<a href="' . $rr['plink'] . '">' . $post_type . '</a>';
578
579                 $aside['$like_items'][] = sprintf( t('%1$s likes %2$s\'s %3$s'), $author, $objauthor, $plink);
580                 
581         }}
582         
583         // last 12 photos
584         if($close_lastphotos != "1") {
585         $aside['$photos_title'] = t('Last photos');
586         $aside['$photos_items'] = array();
587         $r = q("SELECT `photo`.`id`, `photo`.`resource-id`, `photo`.`scale`, `photo`.`desc`, `user`.`nickname`, `user`.`username` FROM 
588                                 (SELECT `resource-id`, MAX(`scale`) as maxscale FROM `photo` 
589                                         WHERE `profile`=0 AND `contact-id`=0 AND `album` NOT IN ('Contact Photos', '%s', 'Profile Photos', '%s')
590                                                 AND `allow_cid`='' AND `allow_gid`='' AND `deny_cid`='' AND `deny_gid`='' GROUP BY `resource-id`) AS `t1`
591                                 INNER JOIN `photo` ON `photo`.`resource-id`=`t1`.`resource-id` AND `photo`.`scale` = `t1`.`maxscale`,
592                                 `user` 
593                                 WHERE `user`.`uid` = `photo`.`uid`
594                                 AND `user`.`blockwall`=0
595                                 AND `user`.`hidewall`=0
596                                 ORDER BY `photo`.`edited` DESC
597                                 LIMIT 0, 9",
598                                 dbesc(t('Contact Photos')),
599                                 dbesc(t('Profile Photos'))
600                                 );
601                 if(count($r)) {
602                 $tpl = file_get_contents( dirname(__file__).'/ch_directory_item.tpl');
603                 foreach($r as $rr) {
604                         $photo_page = $a->get_baseurl() . '/photos/' . $rr['nickname'] . '/image/' . $rr['resource-id'];
605                         $photo_url = $a->get_baseurl() . '/photo/' .  $rr['resource-id'] . '-' . $rr['scale'] .'.jpg';
606                 
607                         $entry = replace_macros($tpl,array(
608                                 '$id' => $rr['id'],
609                                 '$profile-link' => $photo_page,
610                                 '$photo' => $photo_url,
611                                 '$alt-text' => $rr['username']." : ".$rr['desc'],
612                         ));
613
614                         $aside['$photos_items'][] = $entry;
615                 }
616         }}
617         
618    //right_aside FIND FRIENDS
619    if($close_friends != "1") {
620         if(local_user()) {
621         $nv = array();
622         $nv['title'] = Array("", t('Find Friends'), "", "");
623         $nv['directory'] = Array('directory', t('Local Directory'), "", "");
624         $nv['global_directory'] = Array('http://dir.friendica.com/', t('Global Directory'), "", "");
625         $nv['match'] = Array('match', t('Similar Interests'), "", "");
626         $nv['suggest'] = Array('suggest', t('Friend Suggestions'), "", "");
627         $nv['invite'] = Array('invite', t('Invite Friends'), "", "");
628         
629         $nv['search'] = '<form name="simple_bar" method="get" action="http://dir.friendika.com/directory">
630                                                 <span class="sbox_l"></span>
631                                                 <span class="sbox">
632                                                 <input type="text" name="search" size="13" maxlength="50">
633                                                 </span>
634                                                 <span class="sbox_r" id="srch_clear"></span>';
635         
636         $aside['$nv'] = $nv;
637         }}
638    
639    //Community_Pages at right_aside
640    if($close_pages != "1") {
641    if(local_user()) {
642    $page = '
643                         <h3 style="margin-top:0px;">'.t("Community Pages").'<a id="closeicon" href="#boxsettings" onClick="open_boxsettings(); return false;" style="text-decoration:none;" class="icon close_box" title="'.t("Settings").'"></a></h3>
644                         <div id=""><ul style="margin-left: 7px;margin-top: 0px;padding-left: 0px;padding-top: 0px;">';
645
646         $pagelist = array();
647
648         $contacts = q("SELECT `id`, `url`, `name`, `micro`FROM `contact`
649                         WHERE `network`= 'dfrn' AND `forum` = 1 AND `uid` = %d
650                         ORDER BY `name` ASC",
651                         intval($a->user['uid'])
652         );
653
654         $pageD = array();
655
656         // Look if the profile is a community page
657         foreach($contacts as $contact) {
658                 $pageD[] = array("url"=>$contact["url"], "name"=>$contact["name"], "id"=>$contact["id"], "micro"=>$contact['micro']);
659         };
660         
661
662         $contacts = $pageD;
663
664         foreach($contacts as $contact) {
665                 $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">'.
666                                 $contact["name"]."</a></li>";
667         }
668         $page .= '</ul></div>';
669         //if (sizeof($contacts) > 0)
670                 $aside['$page'] = $page;        
671         }}
672   //END Community Page  
673   
674    //mapquery
675
676   if($close_mapquery != "1") {
677    $mapquery = array();
678         $mapquery['title'] = Array("", "<a id='mapcontrol-link' href='#mapcontrol' style='text-decoration:none;' onclick='open_mapcontrol(); return false;'>".t('Earth Layers')."</a>", "", "");
679         $aside['$mapquery'] = $mapquery;
680         $ELZoom = get_pconfig(local_user(), 'diabook', 'ELZoom' );
681         $ELPosX = get_pconfig(local_user(), 'diabook', 'ELPosX' );
682         $ELPosY = get_pconfig(local_user(), 'diabook', 'ELPosY' );
683         $aside['$ELZoom'] = array('diabook_ELZoom', t('Set zoomfactor for Earth Layers'), $ELZoom, '', $ELZoom);
684         $aside['$ELPosX'] = array('diabook_ELPosX', t('Set longitude (X) for Earth Layers'), $ELPosX, '', $ELPosX);     
685         $aside['$ELPosY'] = array('diabook_ELPosY', t('Set latitude (Y) for Earth Layers'), $ELPosY, '', $ELPosY);      
686         if (isset($_POST['diabook-settings-map-sub']) && $_POST['diabook-settings-map-sub']!=''){       
687                 set_pconfig(local_user(), 'diabook', 'ELZoom', $_POST['diabook_ELZoom']);
688                 set_pconfig(local_user(), 'diabook', 'ELPosX', $_POST['diabook_ELPosX']);       
689                 set_pconfig(local_user(), 'diabook', 'ELPosY', $_POST['diabook_ELPosY']);               
690                 header("Location: network");
691                 }
692         }
693    //end mapquery
694                 
695   //helpers
696   if($close_helpers != "1") {
697    $helpers = array();
698         $helpers['title'] = Array("", t('Help or @NewHere ?'), "", "");
699         $aside['$helpers'] = $helpers;
700         }
701    //end helpers
702    //connectable services
703    if($close_services != "1") {
704    $con_services = array();
705         $con_services['title'] = Array("", t('Connect Services'), "", "");
706         $aside['$con_services'] = $con_services;
707         }
708    //end connectable services
709    //twitter
710    if($close_twitter != "1") {
711    $twitter = array();
712         $twitter['title'] = Array("", "<a id='twittersettings-link' href='#twittersettings' style='text-decoration:none;' onclick='open_twittersettings(); return false;'>".t('Last Tweets')."</a>", "", "");
713         $aside['$twitter'] = $twitter;
714         $TSearchTerm = get_pconfig(local_user(), 'diabook', 'TSearchTerm' );
715         $aside['$TSearchTerm'] = array('diabook_TSearchTerm', t('Set twitter search term'), $TSearchTerm, '', $TSearchTerm);
716         $baseurl = $a->get_baseurl($ssl_state); 
717         $aside['$baseurl'] = $baseurl;
718         if (isset($_POST['diabook-settings-sub']) && $_POST['diabook-settings-sub']!=''){       
719                 set_pconfig(local_user(), 'diabook', 'TSearchTerm', $_POST['diabook_TSearchTerm']);     
720                 header("Location: network");
721                 }
722         }
723    //end twitter
724    if($ccCookie != "10") {
725    $close_pages = get_pconfig(local_user(), 'diabook', 'close_pages' );
726         $close_mapquery = get_pconfig(local_user(), 'diabook', 'close_mapquery' );
727         $close_profiles = get_pconfig(local_user(), 'diabook', 'close_profiles' );
728         $close_helpers = get_pconfig(local_user(), 'diabook', 'close_helpers' );
729         $close_services = get_pconfig(local_user(), 'diabook', 'close_services' );
730         $close_friends = get_pconfig(local_user(), 'diabook', 'close_friends' );
731         $close_twitter = get_pconfig(local_user(), 'diabook', 'close_twitter' );
732         $close_lastusers = get_pconfig(local_user(), 'diabook', 'close_lastusers' );
733         $close_lastphotos = get_pconfig(local_user(), 'diabook', 'close_lastphotos' );
734         $close_lastlikes = get_pconfig(local_user(), 'diabook', 'close_lastlikes' );
735         $close_pagesC = array('1'=>t("don't show"),     '0'=>t("show"),);
736         $close_mapqueryC = array('1'=>t("don't show"),  '0'=>t("show"),);
737         $close_profilesC = array('1'=>t("don't show"),  '0'=>t("show"),);
738         $close_helpersC = array('1'=>t("don't show"),   '0'=>t("show"),);
739         $close_servicesC = array('1'=>t("don't show"),  '0'=>t("show"),);
740         $close_friendsC = array('1'=>t("don't show"),   '0'=>t("show"),);
741         $close_twitterC = array('1'=>t("don't show"),   '0'=>t("show"),);
742         $close_lastusersC = array('1'=>t("don't show"), '0'=>t("show"),);
743         $close_lastphotosC = array('1'=>t("don't show"),        '0'=>t("show"),);
744         $close_lastlikesC = array('1'=>t("don't show"), '0'=>t("show"),);
745         $boxsettings['title'] = Array("", t('Show/hide boxes at right-hand column:'), "", "");
746         $aside['$boxsettings'] = $boxsettings;
747         $aside['$close_pages'] = array('diabook_close_pages', t('Community Pages'), $close_pages, '', $close_pagesC);   
748         $aside['$close_mapquery'] = array('diabook_close_mapquery', t('Earth Layers'), $close_mapquery, '', $close_mapqueryC);          
749         $aside['$close_profiles'] = array('diabook_close_profiles', t('Community Profiles'), $close_profiles, '', $close_profilesC);            
750         $aside['$close_helpers'] = array('diabook_close_helpers', t('Help or @NewHere ?'), $close_helpers, '', $close_helpersC);
751         $aside['$close_services'] = array('diabook_close_services', t('Connect Services'), $close_services, '', $close_servicesC);                      
752         $aside['$close_friends'] = array('diabook_close_friends', t('Find Friends'), $close_friends, '', $close_friendsC);      
753         $aside['$close_twitter'] = array('diabook_close_twitter', t('Last Tweets'), $close_twitter, '', $close_twitterC);                       
754         $aside['$close_lastusers'] = array('diabook_close_lastusers', t('Last users'), $close_lastusers, '', $close_lastusersC);                                
755         $aside['$close_lastphotos'] = array('diabook_close_lastphotos', t('Last photos'), $close_lastphotos, '', $close_lastphotosC);                           
756         $aside['$close_lastlikes'] = array('diabook_close_lastlikes', t('Last likes'), $close_lastlikes, '', $close_lastlikesC);                
757    $aside['$sub'] = t('Submit');
758    $baseurl = $a->get_baseurl($ssl_state); 
759    $aside['$baseurl'] = $baseurl;
760    if (isset($_POST['diabook-settings-box-sub']) && $_POST['diabook-settings-box-sub']!=''){    
761                 set_pconfig(local_user(), 'diabook', 'close_pages', $_POST['diabook_close_pages']);
762                 set_pconfig(local_user(), 'diabook', 'close_mapquery', $_POST['diabook_close_mapquery']);
763                 set_pconfig(local_user(), 'diabook', 'close_profiles', $_POST['diabook_close_profiles']);
764                 set_pconfig(local_user(), 'diabook', 'close_helpers', $_POST['diabook_close_helpers']);
765                 set_pconfig(local_user(), 'diabook', 'close_services', $_POST['diabook_close_services']);
766                 set_pconfig(local_user(), 'diabook', 'close_friends', $_POST['diabook_close_friends']);
767                 set_pconfig(local_user(), 'diabook', 'close_twitter', $_POST['diabook_close_twitter']);
768                 set_pconfig(local_user(), 'diabook', 'close_lastusers', $_POST['diabook_close_lastusers']);
769                 set_pconfig(local_user(), 'diabook', 'close_lastphotos', $_POST['diabook_close_lastphotos']);
770                 set_pconfig(local_user(), 'diabook', 'close_lastlikes', $_POST['diabook_close_lastlikes']);     
771                 }
772         }
773    $close = t('Settings');
774    $aside['$close'] = $close;
775    //get_baseurl
776    $url = $a->get_baseurl($ssl_state);   
777    $aside['$url'] = $url;
778         //print right_aside
779         $tpl = file_get_contents(dirname(__file__).'/communityhome.tpl');
780         $a->page['right_aside'] = replace_macros($tpl, $aside);
781         
782  }
783
784  function js_diabook_footer() {
785         /** @purpose insert stuff in bottom of page
786          */
787         $a = get_app();
788         $baseurl = $a->get_baseurl($ssl_state);
789         $bottom['$baseurl'] = $baseurl;
790         $tpl = file_get_contents(dirname(__file__) . '/bottom.tpl');
791         $a->page['footer'] = $a->page['footer'].replace_macros($tpl, $bottom);
792  }
793
794