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)
11 $a->theme_info = array(
12 'family' => 'diabook',
16 function diabook_init(&$a) {
18 //print diabook-version for debugging
19 $diabook_version = "Diabook (Version: 1.025)";
20 $a->page['htmlhead'] .= sprintf('<script "%s" ></script>', $diabook_version);
22 //change css on network and profilepages
26 $resolution = get_pconfig(local_user(), "diabook", "resolution");
27 if ($resolution===false) $resolution="normal";
30 $site_color = get_config("diabook", "color" );
31 if (local_user()) {$color = get_pconfig(local_user(), "diabook", "color");}
32 if ($color===false) $color=$site_color;
33 if ($color===false) $color="diabook";
35 if ($color=="diabook") $color_path = "/";
36 if ($color=="aerith") $color_path = "/diabook-aerith/";
37 if ($color=="blue") $color_path = "/diabook-blue/";
38 if ($color=="red") $color_path = "/diabook-red/";
39 if ($color=="pink") $color_path = "/diabook-pink/";
40 if ($color=="green") $color_path = "/diabook-green/";
41 if ($color=="dark") $color_path = "/diabook-dark/";
44 //profile_side at networkpages
45 if ($a->argv[0] === "network" && local_user()){
50 $r = q("SELECT micro FROM contact WHERE uid=%d AND self=1", intval($a->user['uid']));
53 'icon' => (count($r) ? $r[0]['micro']: $a->get_baseurl()."/images/default-profile-mm.jpg"),
54 'name' => $a->user['username'],
56 $ps = array('usermenu'=>array());
57 $ps['usermenu']['status'] = Array('profile/' . $a->user['nickname'], t('Home'), "", t('Your posts and conversations'));
58 $ps['usermenu']['profile'] = Array('profile/' . $a->user['nickname']. '?tab=profile', t('Profile'), "", t('Your profile page'));
59 $ps['usermenu']['contacts'] = Array('contacts' , t('Contacts'), "", t('Your contacts'));
60 $ps['usermenu']['photos'] = Array('photos/' . $a->user['nickname'], t('Photos'), "", t('Your photos'));
61 $ps['usermenu']['events'] = Array('events/', t('Events'), "", t('Your events'));
62 $ps['usermenu']['notes'] = Array('notes/', t('Personal notes'), "", t('Your personal photos'));
63 $ps['usermenu']['community'] = Array('community/', t('Community'), "", "");
64 $ps['usermenu']['pgroups'] = Array('http://dir.friendica.com/directory/forum', t('Community Pages'), "", "");
66 $tpl = get_markup_template('profile_side.tpl');
68 $a->page['aside'] = replace_macros($tpl, array(
69 '$userinfo' => $userinfo,
75 $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'];
77 if($ccCookie != "9") {
79 diabook_community_info();
82 if($resolution == "normal") {$cssFile = $a->get_baseurl($ssl_state)."/view/theme/diabook".$color_path."style-network.css";}
83 if($resolution == "wide") {$cssFile = $a->get_baseurl($ssl_state)."/view/theme/diabook".$color_path."style-network-wide.css";}
89 //right_aside at profile pages
90 if ($a->argv[0].$a->argv[1] === "profile".$a->user['nickname']){
91 if($ccCookie != "9") {
93 diabook_community_info();
96 if($resolution == "normal") {$cssFile = $a->get_baseurl($ssl_state)."/view/theme/diabook".$color_path."style-profile.css";}
97 if($resolution == "wide") {$cssFile = $a->get_baseurl($ssl_state)."/view/theme/diabook".$color_path."style-profile-wide.css";}
103 //load jquery.cookie.js
104 $cookieJS = $a->get_baseurl($ssl_state)."/view/theme/diabook/js/jquery.cookie.js";
105 $a->page['htmlhead'] .= sprintf('<script language="JavaScript" src="%s"></script>', $cookieJS);
107 //load jquery.ae.image.resize.js
108 $imageresizeJS = $a->get_baseurl($ssl_state)."/view/theme/diabook/js/jquery.ae.image.resize.js";
109 $a->page['htmlhead'] .= sprintf('<script language="JavaScript" src="%s" ></script>', $imageresizeJS);
111 //load jquery.twitter.search.js
112 if($_COOKIE['close_twitter'] != "1") {
113 $twitterJS = $a->get_baseurl($ssl_state)."/view/theme/diabook/js/jquery.twitter.search.js";
114 $a->page['htmlhead'] .= sprintf('<script language="JavaScript" src="%s" ></script>', $twitterJS);
117 $a->page['htmlhead'] .= '
121 $("a.lightbox").fancybox(); // Select all links with lightbox class
124 $(window).load(function() {
125 var footer_top = $(document).height() - 30;
126 $("div#footerbox").attr("style", "border-top: 1px solid #D2D2D2; width: 70%;right: 15%;position: absolute;top:"+footer_top+"px;");
130 //check if twitterbox is active and print
131 if($_COOKIE['close_twitter'] != "1") {
132 $a->page['htmlhead'] .= '
135 $("#twitter").twitterSearch({
140 colorExterior: "#fff",
141 title: "Last Tweets",
146 //check if community_home-plugin is activated and change css
147 $nametocheck = "communityhome";
148 $r = q("select id from addon where name = '%s' and installed = 1", dbesc($nametocheck));
149 if(count($r) == "1") {
151 $a->page['htmlhead'] .= '
153 $(document).ready(function() {
154 $("div#login-submit-wrapper").attr("style","padding-top: 120px;");
158 //comment-edit-wrapper on photo_view
159 if ($a->argv[0].$a->argv[2] === "photos"."image"){
160 $a->page['htmlhead'] .= '
163 $(".comment-edit-form").css("display","table");
167 //restore right hand col at settingspage
168 if($a->argv[0] === "settings" && local_user()) {
169 $a->page['htmlhead'] .= '
171 function restore_boxes(){
172 $.cookie("close_pages","2", { expires: 365, path: "/" });
173 $.cookie("close_helpers","2", { expires: 365, path: "/" });
174 $.cookie("close_profiles","2", { expires: 365, path: "/" });
175 $.cookie("close_services","2", { expires: 365, path: "/" });
176 $.cookie("close_friends","2", { expires: 365, path: "/" });
177 $.cookie("close_twitter","2", { expires: 365, path: "/" });
178 $.cookie("close_lastusers","2", { expires: 365, path: "/" });
179 $.cookie("close_lastphotos","2", { expires: 365, path: "/" });
180 $.cookie("close_lastlikes","2", { expires: 365, path: "/" });
181 alert("Right-hand column was restored. Please refresh your browser");
185 if ($a->argv[0].$a->argv[1] === "profile".$a->user['nickname'] or $a->argv[0] === "network" && local_user()){
186 $a->page['htmlhead'] .= '
190 $(".oembed.photo img").aeImageResize({height: 400, width: 400});
194 if($ccCookie != "9") {
195 $a->page['htmlhead'] .= '
197 $("right_aside").ready(function(){
199 if($.cookie("close_pages") == "1")
201 document.getElementById( "close_pages" ).style.display = "none";
204 if($.cookie("close_profiles") == "1")
206 document.getElementById( "close_profiles" ).style.display = "none";
209 if($.cookie("close_helpers") == "1")
211 document.getElementById( "close_helpers" ).style.display = "none";
214 if($.cookie("close_services") == "1")
216 document.getElementById( "close_services" ).style.display = "none";
219 if($.cookie("close_friends") == "1")
221 document.getElementById( "close_friends" ).style.display = "none";
224 if($.cookie("close_twitter") == "1")
226 document.getElementById( "twitter" ).style.display = "none";
229 if($.cookie("close_lastusers") == "1")
231 document.getElementById( "close_lastusers" ).style.display = "none";
234 if($.cookie("close_lastphotos") == "1")
236 document.getElementById( "close_lastphotos" ).style.display = "none";
239 if($.cookie("close_lastlikes") == "1")
241 document.getElementById( "close_lastlikes" ).style.display = "none";
246 function close_pages(){
247 document.getElementById( "close_pages" ).style.display = "none";
248 $.cookie("close_pages","1", { expires: 365, path: "/" });
251 function close_profiles(){
252 document.getElementById( "close_profiles" ).style.display = "none";
253 $.cookie("close_profiles","1", { expires: 365, path: "/" });
256 function close_helpers(){
257 document.getElementById( "close_helpers" ).style.display = "none";
258 $.cookie("close_helpers","1", { expires: 365, path: "/" });
261 function close_services(){
262 document.getElementById( "close_services" ).style.display = "none";
263 $.cookie("close_services","1", { expires: 365, path: "/" });
266 function close_friends(){
267 document.getElementById( "close_friends" ).style.display = "none";
268 $.cookie("close_friends","1", { expires: 365, path: "/" });
271 function close_twitter(){
272 document.getElementById( "twitter" ).style.display = "none";
273 $.cookie("close_twitter","1", { expires: 365, path: "/" });
276 function close_lastusers(){
277 document.getElementById( "close_lastusers" ).style.display = "none";
278 $.cookie("close_lastusers","1", { expires: 365, path: "/" });
281 function close_lastphotos(){
282 document.getElementById( "close_lastphotos" ).style.display = "none";
283 $.cookie("close_lastphotos","1", { expires: 365, path: "/" });
286 function close_lastlikes(){
287 document.getElementById( "close_lastlikes" ).style.display = "none";
288 $.cookie("close_lastlikes","1", { expires: 365, path: "/" });
295 if (!is_null($cssFile)) $a->page['htmlhead'] .= sprintf('<link rel="stylesheet" type="text/css" href="%s" />', $cssFile);
298 $tpl = get_markup_template('footer.tpl');
299 $a->page['footer'] .= replace_macros($tpl, array());
306 function diabook_community_info() {
309 if($_COOKIE['close_profiles'] != "1") {
310 $aside['$comunity_profilest_title'] = t('Community Profiles');
311 $aside['$comunity_profiles_items'] = array();
312 $r = q("select gcontact.* from gcontact left join glink on glink.gcid = gcontact.id
313 where glink.cid = 0 and glink.uid = 0 order by rand() limit 9");
314 $tpl = file_get_contents( dirname(__file__).'/ch_directory_item.tpl');
318 $profile_link = $a->get_baseurl() . '/profile/' . ((strlen($rr['nickname'])) ? $rr['nickname'] : $rr['profile_uid']);
319 $entry = replace_macros($tpl,array(
321 '$profile-link' => zrl($rr['url']),
322 '$photo' => $rr[$photo],
323 '$alt-text' => $rr['name'],
325 $aside['$comunity_profiles_items'][] = $entry;
330 if($_COOKIE['close_lastusers'] != "1") {
331 $aside['$lastusers_title'] = t('Last users');
332 $aside['$lastusers_items'] = array();
334 $publish = (get_config('system','publish_all') ? '' : " AND `publish` = 1 " );
335 $order = " ORDER BY `register_date` DESC ";
337 $r = q("SELECT `profile`.*, `profile`.`uid` AS `profile_uid`, `user`.`nickname`
338 FROM `profile` LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid`
339 WHERE `is-default` = 1 $publish AND `user`.`blocked` = 0 $sql_extra $order LIMIT %d , %d ",
343 $tpl = file_get_contents( dirname(__file__).'/ch_directory_item.tpl');
347 $profile_link = $a->get_baseurl() . '/profile/' . ((strlen($rr['nickname'])) ? $rr['nickname'] : $rr['profile_uid']);
348 $entry = replace_macros($tpl,array(
350 '$profile-link' => $profile_link,
351 '$photo' => $rr[$photo],
352 '$alt-text' => $rr['name'],
354 $aside['$lastusers_items'][] = $entry;
358 // last 10 liked items
359 if($_COOKIE['close_lastlikes'] != "1") {
360 $aside['$like_title'] = t('Last likes');
361 $aside['$like_items'] = array();
362 $r = q("SELECT `T1`.`created`, `T1`.`liker`, `T1`.`liker-link`, `item`.* FROM
363 (SELECT `parent-uri`, `created`, `author-name` AS `liker`,`author-link` AS `liker-link`
364 FROM `item` WHERE `verb`='http://activitystrea.ms/schema/1.0/like' GROUP BY `parent-uri` ORDER BY `created` DESC) AS T1
365 INNER JOIN `item` ON `item`.`uri`=`T1`.`parent-uri`
366 WHERE `T1`.`liker-link` LIKE '%s%%' OR `item`.`author-link` LIKE '%s%%'
368 ORDER BY `T1`.`created` DESC
370 $a->get_baseurl(),$a->get_baseurl()
373 foreach ($r as $rr) {
374 $author = '<a href="' . $rr['liker-link'] . '">' . $rr['liker'] . '</a>';
375 $objauthor = '<a href="' . $rr['author-link'] . '">' . $rr['author-name'] . '</a>';
377 //var_dump($rr['verb'],$rr['object-type']); killme();
379 case 'http://activitystrea.ms/schema/1.0/post':
380 switch ($rr['object-type']){
381 case 'http://activitystrea.ms/schema/1.0/event':
382 $post_type = t('event');
385 $post_type = t('status');
389 if ($rr['resource-id']){
390 $post_type = t('photo');
391 $m=array(); preg_match("/\[url=([^]]*)\]/", $rr['body'], $m);
392 $rr['plink'] = $m[1];
394 $post_type = t('status');
397 $plink = '<a href="' . $rr['plink'] . '">' . $post_type . '</a>';
399 $aside['$like_items'][] = sprintf( t('%1$s likes %2$s\'s %3$s'), $author, $objauthor, $plink);
404 if($_COOKIE['close_photos'] != "1") {
405 $aside['$photos_title'] = t('Last photos');
406 $aside['$photos_items'] = array();
407 $r = q("SELECT `photo`.`id`, `photo`.`resource-id`, `photo`.`scale`, `photo`.`desc`, `user`.`nickname`, `user`.`username` FROM
408 (SELECT `resource-id`, MAX(`scale`) as maxscale FROM `photo`
409 WHERE `profile`=0 AND `contact-id`=0 AND `album` NOT IN ('Contact Photos', '%s', 'Profile Photos', '%s')
410 AND `allow_cid`='' AND `allow_gid`='' AND `deny_cid`='' AND `deny_gid`='' GROUP BY `resource-id`) AS `t1`
411 INNER JOIN `photo` ON `photo`.`resource-id`=`t1`.`resource-id` AND `photo`.`scale` = `t1`.`maxscale`,
413 WHERE `user`.`uid` = `photo`.`uid`
414 AND `user`.`blockwall`=0
415 AND `user`.`hidewall`=0
416 ORDER BY `photo`.`edited` DESC
418 dbesc(t('Contact Photos')),
419 dbesc(t('Profile Photos'))
422 $tpl = file_get_contents( dirname(__file__).'/ch_directory_item.tpl');
424 $photo_page = $a->get_baseurl() . '/photos/' . $rr['nickname'] . '/image/' . $rr['resource-id'];
425 $photo_url = $a->get_baseurl() . '/photo/' . $rr['resource-id'] . '-' . $rr['scale'] .'.jpg';
427 $entry = replace_macros($tpl,array(
429 '$profile-link' => $photo_page,
430 '$photo' => $photo_url,
431 '$alt-text' => $rr['username']." : ".$rr['desc'],
434 $aside['$photos_items'][] = $entry;
438 //right_aside FIND FRIENDS
439 if($_COOKIE['close_friends'] != "1") {
442 $nv['title'] = Array("", t('Find Friends'), "", "");
443 $nv['directory'] = Array('directory', t('Local Directory'), "", "");
444 $nv['global_directory'] = Array('http://dir.friendica.com/', t('Global Directory'), "", "");
445 $nv['match'] = Array('match', t('Similar Interests'), "", "");
446 $nv['suggest'] = Array('suggest', t('Friend Suggestions'), "", "");
447 $nv['invite'] = Array('invite', t('Invite Friends'), "", "");
449 $nv['search'] = '<form name="simple_bar" method="get" action="http://dir.friendika.com/directory">
450 <span class="sbox_l"></span>
452 <input type="text" name="search" size="13" maxlength="50">
454 <span class="sbox_r" id="srch_clear"></span>';
459 //Community_Pages at right_aside
460 if($_COOKIE['close_pages'] != "1") {
462 $page = '<div id="" >
463 <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>
464 <div id=""><ul style="margin-left: 7px;margin-top: 0px;padding-left: 0px;padding-top: 0px;">';
468 $contacts = q("SELECT `id`, `url`, `name`, `micro`FROM `contact`
469 WHERE `network`= 'dfrn' AND `forum` = 1 AND `uid` = %d
470 ORDER BY `name` ASC",
471 intval($a->user['uid'])
476 // Look if the profile is a community page
477 foreach($contacts as $contact) {
478 $pageD[] = array("url"=>$contact["url"], "name"=>$contact["name"], "id"=>$contact["id"], "micro"=>$contact['micro']);
484 foreach($contacts as $contact) {
485 $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">'.
486 $contact["name"]."</a></li>";
488 $page .= '</ul></div></div>';
489 //if (sizeof($contacts) > 0)
490 $aside['$page'] = $page;
495 if($_COOKIE['close_helpers'] != "1") {
497 $helpers['title'] = Array("", t('Help or @NewHere ?'), "", "");
498 $aside['$helpers'] = $helpers;
501 //connectable services
502 if($_COOKIE['close_services'] != "1") {
503 $con_services = array();
504 $con_services['title'] = Array("", t('Connect Services'), "", "");
505 $aside['$con_services'] = $con_services;
507 //end connectable services
509 $url = $a->get_baseurl($ssl_state);
510 $aside['$url'] = $url;
512 $tpl = file_get_contents(dirname(__file__).'/communityhome.tpl');
513 $a->page['right_aside'] = replace_macros($tpl, $aside);
517 function js_in_foot() {
518 /** @purpose insert stuff in bottom of page
521 $baseurl = $a->get_baseurl($ssl_state);
522 $bottom['$baseurl'] = $baseurl;
523 $tpl = file_get_contents(dirname(__file__) . '/bottom.tpl');
524 $a->page['footer'] = $a->page['footer'].replace_macros($tpl, $bottom);