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)
13 function diabook_init(&$a) {
15 //print diabook-version for debugging
16 $diabook_version = "Diabook (Version: 1.025)";
17 $a->page['htmlhead'] .= sprintf('<META NAME="theme" CONTENT="%s"/>', $diabook_version);
19 //change css on network and profilepages
23 $resolution = get_pconfig(local_user(), "diabook", "resolution");
24 if ($resolution===false) $resolution="normal";
26 //Add META viewport tag respecting the resolution to header for tablets
27 if ($resolution=="wide") {
28 $a->page['htmlhead'] .= '<meta name="viewport" content="width=1200" />';
30 $a->page['htmlhead'] .= '<meta name="viewport" content="width=980" />';
35 $site_color = get_config("diabook", "color" );
36 if (local_user()) {$color = get_pconfig(local_user(), "diabook", "color");}
37 if ($color===false) $color=$site_color;
38 if ($color===false) $color="diabook";
40 if ($color=="diabook") $color_path = "/";
41 if ($color=="aerith") $color_path = "/diabook-aerith/";
42 if ($color=="blue") $color_path = "/diabook-blue/";
43 if ($color=="red") $color_path = "/diabook-red/";
44 if ($color=="pink") $color_path = "/diabook-pink/";
45 if ($color=="green") $color_path = "/diabook-green/";
46 if ($color=="dark") $color_path = "/diabook-dark/";
49 //profile_side at networkpages
50 if ($a->argv[0] === "network" && local_user()){
55 $r = q("SELECT micro FROM contact WHERE uid=%d AND self=1", intval($a->user['uid']));
58 'icon' => (count($r) ? $r[0]['micro']: $a->get_baseurl()."/images/default-profile-mm.jpg"),
59 'name' => $a->user['username'],
61 $ps = array('usermenu'=>array());
62 $ps['usermenu']['status'] = Array('profile/' . $a->user['nickname'], t('Home'), "", t('Your posts and conversations'));
63 $ps['usermenu']['profile'] = Array('profile/' . $a->user['nickname']. '?tab=profile', t('Profile'), "", t('Your profile page'));
64 $ps['usermenu']['contacts'] = Array('contacts' , t('Contacts'), "", t('Your contacts'));
65 $ps['usermenu']['photos'] = Array('photos/' . $a->user['nickname'], t('Photos'), "", t('Your photos'));
66 $ps['usermenu']['events'] = Array('events/', t('Events'), "", t('Your events'));
67 $ps['usermenu']['notes'] = Array('notes/', t('Personal notes'), "", t('Your personal photos'));
68 $ps['usermenu']['community'] = Array('community/', t('Community'), "", "");
69 $ps['usermenu']['pgroups'] = Array('http://dir.friendica.com/directory/forum', t('Community Pages'), "", "");
71 $tpl = get_markup_template('profile_side.tpl');
73 $a->page['aside'] = replace_macros($tpl, array(
74 '$userinfo' => $userinfo,
80 $ccCookie = $_COOKIE['close_pages'] + $_COOKIE['close_mapquery'] + $_COOKIE['close_profiles'] + $_COOKIE['close_helpers'] + $_COOKIE['close_services'] + $_COOKIE['close_friends'] + $_COOKIE['close_twitter'] + $_COOKIE['close_lastusers'] + $_COOKIE['close_lastphotos'] + $_COOKIE['close_lastlikes'];
82 if($ccCookie != "10") {
84 diabook_community_info();
87 if($resolution == "normal") {$cssFile = $a->get_baseurl($ssl_state)."/view/theme/diabook".$color_path."style-network.css";}
88 if($resolution == "wide") {$cssFile = $a->get_baseurl($ssl_state)."/view/theme/diabook".$color_path."style-network-wide.css";}
94 //right_aside at profile pages
95 if ($a->argv[0].$a->argv[1] === "profile".$a->user['nickname']){
96 if($ccCookie != "10") {
98 diabook_community_info();
101 if($resolution == "normal") {$cssFile = $a->get_baseurl($ssl_state)."/view/theme/diabook".$color_path."style-profile.css";}
102 if($resolution == "wide") {$cssFile = $a->get_baseurl($ssl_state)."/view/theme/diabook".$color_path."style-profile-wide.css";}
108 //load jquery.cookie.js
109 $cookieJS = $a->get_baseurl($ssl_state)."/view/theme/diabook/js/jquery.cookie.js";
110 $a->page['htmlhead'] .= sprintf('<script language="JavaScript" src="%s"></script>', $cookieJS);
112 //load jquery.ae.image.resize.js
113 $imageresizeJS = $a->get_baseurl($ssl_state)."/view/theme/diabook/js/jquery.ae.image.resize.js";
114 $a->page['htmlhead'] .= sprintf('<script language="JavaScript" src="%s" ></script>', $imageresizeJS);
117 if($ccCookie != "9") {
118 $jqueryuiJS = $a->get_baseurl($ssl_state)."/view/theme/diabook/js/jquery-ui-1.8.20.custom.min.js";
119 $a->page['htmlhead'] .= sprintf('<script language="JavaScript" src="%s" ></script>', $jqueryuiJS);
122 //load jquery.twitter.search.js
123 if($_COOKIE['close_twitter'] != "1") {
124 $twitterJS = $a->get_baseurl($ssl_state)."/view/theme/diabook/js/jquery.twitter.search.js";
125 $a->page['htmlhead'] .= sprintf('<script language="JavaScript" src="%s" ></script>', $twitterJS);
128 //load jquery.mapquery.js
129 $_COOKIE['close_mapquery'] = "1";
130 if($_COOKIE['close_mapquery'] != "1") {
131 $mqtmplJS = $a->get_baseurl($ssl_state)."/view/theme/diabook/js/jquery.tmpl.js";
132 $a->page['htmlhead'] .= sprintf('<script language="JavaScript" src="%s" ></script>', $mqtmplJS);
133 $mapqueryJS = $a->get_baseurl($ssl_state)."/view/theme/diabook/js/jquery.mapquery.core.js";
134 $a->page['htmlhead'] .= sprintf('<script language="JavaScript" src="%s" ></script>', $mapqueryJS);
135 $openlayersJS = $a->get_baseurl($ssl_state)."/view/theme/diabook/js/OpenLayers.js";
136 $a->page['htmlhead'] .= sprintf('<script language="JavaScript" src="%s" ></script>', $openlayersJS);
137 $mqmouseposJS = $a->get_baseurl($ssl_state)."/view/theme/diabook/js/jquery.mapquery.mqMousePosition.js";
138 $a->page['htmlhead'] .= sprintf('<script language="JavaScript" src="%s" ></script>', $mqmouseposJS);
139 $mqzoomsliderJS = $a->get_baseurl($ssl_state)."/view/theme/diabook/js/jquery.mapquery.mqZoomSlider.js";
140 $a->page['htmlhead'] .= sprintf('<script language="JavaScript" src="%s" ></script>', $mqzoomsliderJS);
144 $a->page['htmlhead'] .= '
148 $("a.lightbox").fancybox(); // Select all links with lightbox class
149 $("a.#twittersettings-link").fancybox({onClosed: function() { $("#twittersettings").attr("style","display: none;");}} );
150 $("a.#mapcontrol-link").fancybox({onClosed: function() { $("#mapcontrol").attr("style","display: none;");}} );
153 $(window).load(function() {
154 var footer_top = $(document).height() - 30;
155 $("div#footerbox").attr("style", "border-top: 1px solid #D2D2D2; width: 70%;right: 15%;position: absolute;top:"+footer_top+"px;");
158 //check if mapquerybox is active and print
159 $_COOKIE['close_mapquery'] = "1";
160 if($_COOKIE['close_mapquery'] != "1") {
161 $a->page['htmlhead'] .= '
164 $(document).ready(function() {
166 layers:[{ //add layers to your map; you need to define at least one to be able to see anything on the map
167 type:"osm" //add a layer of the type osm (OpenStreetMap)
169 center:({zoom:8,position:[11.7,52.2]}),
174 function open_mapcontrol() {
175 $("div#mapcontrol").attr("style","display: block;width:900px;height:600px;");
176 $("#map2").mapQuery({layers:[{type:"osm"}],
177 center:({zoom:8,position:[11.7,52.2]})});
179 $("#mouseposition").mqMousePosition({
187 map = $("#map2").mapQuery().data("mapQuery");
188 alert(map.center().zoom);
194 //check if twitterbox is active and print
195 if($_COOKIE['close_twitter'] != "1") {
197 $site_TSearchTerm = get_config("diabook", "TSearchTerm" );
198 $TSearchTerm = get_pconfig(local_user(), "diabook", "TSearchTerm");
199 if ($TSearchTerm===false) $TSearchTerm=$site_TSearchTerm;
200 if ($TSearchTerm===false) $TSearchTerm="friendica";
201 $a->page['htmlhead'] .= '
204 $("#twitter").twitterSearch({
205 term: "'.$TSearchTerm.'",
209 colorExterior: "#fff",
212 function open_twittersettings() {
213 $("div#twittersettings").attr("style","display: block;");
217 //check if community_home-plugin is activated and change css
218 $nametocheck = "communityhome";
219 $r = q("select id from addon where name = '%s' and installed = 1", dbesc($nametocheck));
220 if(count($r) == "1") {
222 $a->page['htmlhead'] .= '
224 $(document).ready(function() {
225 $("div#login-submit-wrapper").attr("style","padding-top: 120px;");
230 //comment-edit-wrapper on photo_view
231 if ($a->argv[0].$a->argv[2] === "photos"."image"){
232 $a->page['htmlhead'] .= '
235 $(".comment-edit-form").css("display","table");
239 //restore right hand col at settingspage
240 if($a->argv[0] === "settings" && local_user()) {
241 $a->page['htmlhead'] .= '
243 function restore_boxes(){
244 $.cookie("close_pages","2", { expires: 365, path: "/" });
245 $.cookie("close_mapquery","2", { expires: 365, path: "/" });
246 $.cookie("close_helpers","2", { expires: 365, path: "/" });
247 $.cookie("close_profiles","2", { expires: 365, path: "/" });
248 $.cookie("close_services","2", { expires: 365, path: "/" });
249 $.cookie("close_friends","2", { expires: 365, path: "/" });
250 $.cookie("close_twitter","2", { expires: 365, path: "/" });
251 $.cookie("close_lastusers","2", { expires: 365, path: "/" });
252 $.cookie("close_lastphotos","2", { expires: 365, path: "/" });
253 $.cookie("close_lastlikes","2", { expires: 365, path: "/" });
254 $.cookie("Boxorder",null, { expires: 365, path: "/" });
255 alert("Right-hand column was restored. Please refresh your browser");
259 if ($a->argv[0].$a->argv[1] === "profile".$a->user['nickname'] or $a->argv[0] === "network" && local_user()){
260 $a->page['htmlhead'] .= '
264 $(".oembed.photo img").aeImageResize({height: 400, width: 400});
268 if($ccCookie != "9") {
269 $a->page['htmlhead'] .= '
271 $("right_aside").ready(function(){
273 if($.cookie("close_pages") == "1")
275 document.getElementById( "close_pages" ).style.display = "none";
278 if($.cookie("close_mapquery") == "1")
280 document.getElementById( "close_mapquery" ).style.display = "none";
283 if($.cookie("close_profiles") == "1")
285 document.getElementById( "close_profiles" ).style.display = "none";
288 if($.cookie("close_helpers") == "1")
290 document.getElementById( "close_helpers" ).style.display = "none";
293 if($.cookie("close_services") == "1")
295 document.getElementById( "close_services" ).style.display = "none";
298 if($.cookie("close_friends") == "1")
300 document.getElementById( "close_friends" ).style.display = "none";
303 if($.cookie("close_twitter") == "1")
305 document.getElementById( "close_twitter" ).style.display = "none";
308 if($.cookie("close_lastusers") == "1")
310 document.getElementById( "close_lastusers" ).style.display = "none";
313 if($.cookie("close_lastphotos") == "1")
315 document.getElementById( "close_lastphotos" ).style.display = "none";
318 if($.cookie("close_lastlikes") == "1")
320 document.getElementById( "close_lastlikes" ).style.display = "none";
325 function close_pages(){
326 document.getElementById( "close_pages" ).style.display = "none";
327 $.cookie("close_pages","1", { expires: 365, path: "/" });
330 function close_mapquery(){
331 document.getElementById( "close_mapquery" ).style.display = "none";
332 $.cookie("close_mapquery","1", { expires: 365, path: "/" });
335 function close_profiles(){
336 document.getElementById( "close_profiles" ).style.display = "none";
337 $.cookie("close_profiles","1", { expires: 365, path: "/" });
340 function close_helpers(){
341 document.getElementById( "close_helpers" ).style.display = "none";
342 $.cookie("close_helpers","1", { expires: 365, path: "/" });
345 function close_services(){
346 document.getElementById( "close_services" ).style.display = "none";
347 $.cookie("close_services","1", { expires: 365, path: "/" });
350 function close_friends(){
351 document.getElementById( "close_friends" ).style.display = "none";
352 $.cookie("close_friends","1", { expires: 365, path: "/" });
355 function close_twitter(){
356 document.getElementById( "close_twitter" ).style.display = "none";
357 $.cookie("close_twitter","1", { expires: 365, path: "/" });
360 function close_lastusers(){
361 document.getElementById( "close_lastusers" ).style.display = "none";
362 $.cookie("close_lastusers","1", { expires: 365, path: "/" });
365 function close_lastphotos(){
366 document.getElementById( "close_lastphotos" ).style.display = "none";
367 $.cookie("close_lastphotos","1", { expires: 365, path: "/" });
370 function close_lastlikes(){
371 document.getElementById( "close_lastlikes" ).style.display = "none";
372 $.cookie("close_lastlikes","1", { expires: 365, path: "/" });
379 if (!is_null($cssFile)) $a->page['htmlhead'] .= sprintf('<link rel="stylesheet" type="text/css" href="%s" />', $cssFile);
382 $tpl = get_markup_template('footer.tpl');
383 $a->page['footer'] .= replace_macros($tpl, array());
390 function diabook_community_info() {
393 if($_COOKIE['close_profiles'] != "1") {
394 $aside['$comunity_profiles_title'] = t('Community Profiles');
395 $aside['$comunity_profiles_items'] = array();
396 $r = q("select gcontact.* from gcontact left join glink on glink.gcid = gcontact.id
397 where glink.cid = 0 and glink.uid = 0 order by rand() limit 9");
398 $tpl = file_get_contents( dirname(__file__).'/ch_directory_item.tpl');
402 $profile_link = $a->get_baseurl() . '/profile/' . ((strlen($rr['nickname'])) ? $rr['nickname'] : $rr['profile_uid']);
403 $entry = replace_macros($tpl,array(
405 '$profile-link' => zrl($rr['url']),
406 '$photo' => $rr[$photo],
407 '$alt-text' => $rr['name'],
409 $aside['$comunity_profiles_items'][] = $entry;
414 if($_COOKIE['close_lastusers'] != "1") {
415 $aside['$lastusers_title'] = t('Last users');
416 $aside['$lastusers_items'] = array();
418 $publish = (get_config('system','publish_all') ? '' : " AND `publish` = 1 " );
419 $order = " ORDER BY `register_date` DESC ";
421 $r = q("SELECT `profile`.*, `profile`.`uid` AS `profile_uid`, `user`.`nickname`
422 FROM `profile` LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid`
423 WHERE `is-default` = 1 $publish AND `user`.`blocked` = 0 $sql_extra $order LIMIT %d , %d ",
427 $tpl = file_get_contents( dirname(__file__).'/ch_directory_item.tpl');
431 $profile_link = $a->get_baseurl() . '/profile/' . ((strlen($rr['nickname'])) ? $rr['nickname'] : $rr['profile_uid']);
432 $entry = replace_macros($tpl,array(
434 '$profile-link' => $profile_link,
435 '$photo' => $rr[$photo],
436 '$alt-text' => $rr['name'],
438 $aside['$lastusers_items'][] = $entry;
442 // last 10 liked items
443 if($_COOKIE['close_lastlikes'] != "1") {
444 $aside['$like_title'] = t('Last likes');
445 $aside['$like_items'] = array();
446 $r = q("SELECT `T1`.`created`, `T1`.`liker`, `T1`.`liker-link`, `item`.* FROM
447 (SELECT `parent-uri`, `created`, `author-name` AS `liker`,`author-link` AS `liker-link`
448 FROM `item` WHERE `verb`='http://activitystrea.ms/schema/1.0/like' GROUP BY `parent-uri` ORDER BY `created` DESC) AS T1
449 INNER JOIN `item` ON `item`.`uri`=`T1`.`parent-uri`
450 WHERE `T1`.`liker-link` LIKE '%s%%' OR `item`.`author-link` LIKE '%s%%'
452 ORDER BY `T1`.`created` DESC
454 $a->get_baseurl(),$a->get_baseurl()
457 foreach ($r as $rr) {
458 $author = '<a href="' . $rr['liker-link'] . '">' . $rr['liker'] . '</a>';
459 $objauthor = '<a href="' . $rr['author-link'] . '">' . $rr['author-name'] . '</a>';
461 //var_dump($rr['verb'],$rr['object-type']); killme();
463 case 'http://activitystrea.ms/schema/1.0/post':
464 switch ($rr['object-type']){
465 case 'http://activitystrea.ms/schema/1.0/event':
466 $post_type = t('event');
469 $post_type = t('status');
473 if ($rr['resource-id']){
474 $post_type = t('photo');
475 $m=array(); preg_match("/\[url=([^]]*)\]/", $rr['body'], $m);
476 $rr['plink'] = $m[1];
478 $post_type = t('status');
481 $plink = '<a href="' . $rr['plink'] . '">' . $post_type . '</a>';
483 $aside['$like_items'][] = sprintf( t('%1$s likes %2$s\'s %3$s'), $author, $objauthor, $plink);
488 if($_COOKIE['close_photos'] != "1") {
489 $aside['$photos_title'] = t('Last photos');
490 $aside['$photos_items'] = array();
491 $r = q("SELECT `photo`.`id`, `photo`.`resource-id`, `photo`.`scale`, `photo`.`desc`, `user`.`nickname`, `user`.`username` FROM
492 (SELECT `resource-id`, MAX(`scale`) as maxscale FROM `photo`
493 WHERE `profile`=0 AND `contact-id`=0 AND `album` NOT IN ('Contact Photos', '%s', 'Profile Photos', '%s')
494 AND `allow_cid`='' AND `allow_gid`='' AND `deny_cid`='' AND `deny_gid`='' GROUP BY `resource-id`) AS `t1`
495 INNER JOIN `photo` ON `photo`.`resource-id`=`t1`.`resource-id` AND `photo`.`scale` = `t1`.`maxscale`,
497 WHERE `user`.`uid` = `photo`.`uid`
498 AND `user`.`blockwall`=0
499 AND `user`.`hidewall`=0
500 ORDER BY `photo`.`edited` DESC
502 dbesc(t('Contact Photos')),
503 dbesc(t('Profile Photos'))
506 $tpl = file_get_contents( dirname(__file__).'/ch_directory_item.tpl');
508 $photo_page = $a->get_baseurl() . '/photos/' . $rr['nickname'] . '/image/' . $rr['resource-id'];
509 $photo_url = $a->get_baseurl() . '/photo/' . $rr['resource-id'] . '-' . $rr['scale'] .'.jpg';
511 $entry = replace_macros($tpl,array(
513 '$profile-link' => $photo_page,
514 '$photo' => $photo_url,
515 '$alt-text' => $rr['username']." : ".$rr['desc'],
518 $aside['$photos_items'][] = $entry;
522 //right_aside FIND FRIENDS
523 if($_COOKIE['close_friends'] != "1") {
526 $nv['title'] = Array("", t('Find Friends'), "", "");
527 $nv['directory'] = Array('directory', t('Local Directory'), "", "");
528 $nv['global_directory'] = Array('http://dir.friendica.com/', t('Global Directory'), "", "");
529 $nv['match'] = Array('match', t('Similar Interests'), "", "");
530 $nv['suggest'] = Array('suggest', t('Friend Suggestions'), "", "");
531 $nv['invite'] = Array('invite', t('Invite Friends'), "", "");
533 $nv['search'] = '<form name="simple_bar" method="get" action="http://dir.friendika.com/directory">
534 <span class="sbox_l"></span>
536 <input type="text" name="search" size="13" maxlength="50">
538 <span class="sbox_r" id="srch_clear"></span>';
543 //Community_Pages at right_aside
544 if($_COOKIE['close_pages'] != "1") {
547 <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>
548 <div id=""><ul style="margin-left: 7px;margin-top: 0px;padding-left: 0px;padding-top: 0px;">';
552 $contacts = q("SELECT `id`, `url`, `name`, `micro`FROM `contact`
553 WHERE `network`= 'dfrn' AND `forum` = 1 AND `uid` = %d
554 ORDER BY `name` ASC",
555 intval($a->user['uid'])
560 // Look if the profile is a community page
561 foreach($contacts as $contact) {
562 $pageD[] = array("url"=>$contact["url"], "name"=>$contact["name"], "id"=>$contact["id"], "micro"=>$contact['micro']);
568 foreach($contacts as $contact) {
569 $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">'.
570 $contact["name"]."</a></li>";
572 $page .= '</ul></div>';
573 //if (sizeof($contacts) > 0)
574 $aside['$page'] = $page;
579 $_COOKIE['close_mapquery'] = "1";
580 if($_COOKIE['close_mapquery'] != "1") {
582 $mapquery['title'] = Array("", "<a id='mapcontrol-link' href='#mapcontrol' style='text-decoration:none;' onclick='open_mapcontrol(); return false;'>".t('Earth View')."</a>", "", "");
583 $aside['$mapquery'] = $mapquery;
588 if($_COOKIE['close_helpers'] != "1") {
590 $helpers['title'] = Array("", t('Help or @NewHere ?'), "", "");
591 $aside['$helpers'] = $helpers;
594 //connectable services
595 if($_COOKIE['close_services'] != "1") {
596 $con_services = array();
597 $con_services['title'] = Array("", t('Connect Services'), "", "");
598 $aside['$con_services'] = $con_services;
600 //end connectable services
602 if($_COOKIE['close_twitter'] != "1") {
604 $twitter['title'] = Array("", "<a id='twittersettings-link' href='#twittersettings' style='text-decoration:none;' onclick='open_twittersettings(); return false;'>".t('Last Tweets')."</a>", "", "");
605 $aside['$twitter'] = $twitter;
606 $TSearchTerm = get_pconfig(local_user(), 'diabook', 'TSearchTerm' );
607 $aside['$sub'] = t('Submit');
608 $aside['$TSearchTerm'] = array('diabook_TSearchTerm', t('Set twitter search term'), $TSearchTerm, '', $TSearchTerm);
609 $baseurl = $a->get_baseurl($ssl_state);
610 $aside['$baseurl'] = $baseurl;
611 if (isset($_POST['diabook-settings-sub']) && $_POST['diabook-settings-sub']!=''){
612 set_pconfig(local_user(), 'diabook', 'TSearchTerm', $_POST['diabook_TSearchTerm']);
613 header("Location: network");
618 $aside['$close'] = $close;
620 $url = $a->get_baseurl($ssl_state);
621 $aside['$url'] = $url;
623 $tpl = file_get_contents(dirname(__file__).'/communityhome.tpl');
624 $a->page['right_aside'] = replace_macros($tpl, $aside);
628 function js_diabook_footer() {
629 /** @purpose insert stuff in bottom of page
632 $baseurl = $a->get_baseurl($ssl_state);
633 $bottom['$baseurl'] = $baseurl;
634 $tpl = file_get_contents(dirname(__file__) . '/bottom.tpl');
635 $a->page['footer'] = $a->page['footer'].replace_macros($tpl, $bottom);