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 $twitterJS = $a->get_baseurl($ssl_state)."/view/theme/diabook/js/jquery.twitter.search.js";
113 $a->page['htmlhead'] .= sprintf('<script language="JavaScript" src="%s" ></script>', $twitterJS);
115 $a->page['htmlhead'] .= '
119 $("a.lightbox").fancybox(); // Select all links with lightbox class
120 $("#twitter").twitterSearch({
125 colorExterior: "#fff",
126 title: "Last Tweets",
130 $(window).load(function() {
131 var footer_top = $(document).height() - 30;
132 $("div#footerbox").attr("style", "border-top: 1px solid #D2D2D2; width: 70%;right: 15%;position: absolute;top:"+footer_top+"px;");
135 //check if community_home-plugin is activated and change css
136 $nametocheck = "communityhome";
137 $r = q("select id from addon where name = '%s' and installed = 1", dbesc($nametocheck));
138 if(count($r) == "1") {
140 $a->page['htmlhead'] .= '
142 $(document).ready(function() {
143 $("div#login-submit-wrapper").attr("style","padding-top: 120px;");
147 //comment-edit-wrapper on photo_view
148 if ($a->argv[0].$a->argv[2] === "photos"."image"){
149 $a->page['htmlhead'] .= '
152 $(".comment-edit-form").css("display","table");
156 //restore right hand col at settingspage
157 if($a->argv[0] === "settings" && local_user()) {
158 $a->page['htmlhead'] .= '
160 function restore_boxes(){
161 $.cookie("close_pages","2", { expires: 365, path: "/" });
162 $.cookie("close_helpers","2", { expires: 365, path: "/" });
163 $.cookie("close_profiles","2", { expires: 365, path: "/" });
164 $.cookie("close_services","2", { expires: 365, path: "/" });
165 $.cookie("close_friends","2", { expires: 365, path: "/" });
166 $.cookie("close_twitter","2", { expires: 365, path: "/" });
167 $.cookie("close_lastusers","2", { expires: 365, path: "/" });
168 $.cookie("close_lastphotos","2", { expires: 365, path: "/" });
169 $.cookie("close_lastlikes","2", { expires: 365, path: "/" });
170 alert("Right-hand column was restored. Please refresh your browser");
174 if ($a->argv[0].$a->argv[1] === "profile".$a->user['nickname'] or $a->argv[0] === "network" && local_user()){
175 $a->page['htmlhead'] .= '
179 $(".oembed.photo img").aeImageResize({height: 400, width: 400});
183 if($ccCookie != "9") {
184 $a->page['htmlhead'] .= '
186 $("right_aside").ready(function(){
188 if($.cookie("close_pages") == "1")
190 document.getElementById( "close_pages" ).style.display = "none";
193 if($.cookie("close_profiles") == "1")
195 document.getElementById( "close_profiles" ).style.display = "none";
198 if($.cookie("close_helpers") == "1")
200 document.getElementById( "close_helpers" ).style.display = "none";
203 if($.cookie("close_services") == "1")
205 document.getElementById( "close_services" ).style.display = "none";
208 if($.cookie("close_friends") == "1")
210 document.getElementById( "close_friends" ).style.display = "none";
213 if($.cookie("close_twitter") == "1")
215 document.getElementById( "twitter" ).style.display = "none";
218 if($.cookie("close_lastusers") == "1")
220 document.getElementById( "close_lastusers" ).style.display = "none";
223 if($.cookie("close_lastphotos") == "1")
225 document.getElementById( "close_lastphotos" ).style.display = "none";
228 if($.cookie("close_lastlikes") == "1")
230 document.getElementById( "close_lastlikes" ).style.display = "none";
235 function close_pages(){
236 document.getElementById( "close_pages" ).style.display = "none";
237 $.cookie("close_pages","1", { expires: 365, path: "/" });
240 function close_profiles(){
241 document.getElementById( "close_profiles" ).style.display = "none";
242 $.cookie("close_profiles","1", { expires: 365, path: "/" });
245 function close_helpers(){
246 document.getElementById( "close_helpers" ).style.display = "none";
247 $.cookie("close_helpers","1", { expires: 365, path: "/" });
250 function close_services(){
251 document.getElementById( "close_services" ).style.display = "none";
252 $.cookie("close_services","1", { expires: 365, path: "/" });
255 function close_friends(){
256 document.getElementById( "close_friends" ).style.display = "none";
257 $.cookie("close_friends","1", { expires: 365, path: "/" });
260 function close_twitter(){
261 document.getElementById( "twitter" ).style.display = "none";
262 $.cookie("close_twitter","1", { expires: 365, path: "/" });
265 function close_lastusers(){
266 document.getElementById( "close_lastusers" ).style.display = "none";
267 $.cookie("close_lastusers","1", { expires: 365, path: "/" });
270 function close_lastphotos(){
271 document.getElementById( "close_lastphotos" ).style.display = "none";
272 $.cookie("close_lastphotos","1", { expires: 365, path: "/" });
275 function close_lastlikes(){
276 document.getElementById( "close_lastlikes" ).style.display = "none";
277 $.cookie("close_lastlikes","1", { expires: 365, path: "/" });
284 if (!is_null($cssFile)) $a->page['htmlhead'] .= sprintf('<link rel="stylesheet" type="text/css" href="%s" />', $cssFile);
287 $tpl = get_markup_template('footer.tpl');
288 $a->page['footer'] .= replace_macros($tpl, array());
295 function diabook_community_info() {
298 $aside['$comunity_profilest_title'] = t('Community Profiles');
299 $aside['$comunity_profiles_items'] = array();
300 $r = q("select gcontact.* from gcontact left join glink on glink.gcid = gcontact.id
301 where glink.cid = 0 and glink.uid = 0 order by rand() limit 9");
302 $tpl = file_get_contents( dirname(__file__).'/ch_directory_item.tpl');
306 $profile_link = $a->get_baseurl() . '/profile/' . ((strlen($rr['nickname'])) ? $rr['nickname'] : $rr['profile_uid']);
307 $entry = replace_macros($tpl,array(
309 '$profile-link' => zrl($rr['url']),
310 '$photo' => $rr[$photo],
311 '$alt-text' => $rr['name'],
313 $aside['$comunity_profiles_items'][] = $entry;
318 $aside['$lastusers_title'] = t('Last users');
319 $aside['$lastusers_items'] = array();
321 $publish = (get_config('system','publish_all') ? '' : " AND `publish` = 1 " );
322 $order = " ORDER BY `register_date` DESC ";
324 $r = q("SELECT `profile`.*, `profile`.`uid` AS `profile_uid`, `user`.`nickname`
325 FROM `profile` LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid`
326 WHERE `is-default` = 1 $publish AND `user`.`blocked` = 0 $sql_extra $order LIMIT %d , %d ",
330 $tpl = file_get_contents( dirname(__file__).'/ch_directory_item.tpl');
334 $profile_link = $a->get_baseurl() . '/profile/' . ((strlen($rr['nickname'])) ? $rr['nickname'] : $rr['profile_uid']);
335 $entry = replace_macros($tpl,array(
337 '$profile-link' => $profile_link,
338 '$photo' => $rr[$photo],
339 '$alt-text' => $rr['name'],
341 $aside['$lastusers_items'][] = $entry;
346 // last 10 liked items
347 $aside['$like_title'] = t('Last likes');
348 $aside['$like_items'] = array();
349 $r = q("SELECT `T1`.`created`, `T1`.`liker`, `T1`.`liker-link`, `item`.* FROM
350 (SELECT `parent-uri`, `created`, `author-name` AS `liker`,`author-link` AS `liker-link`
351 FROM `item` WHERE `verb`='http://activitystrea.ms/schema/1.0/like' GROUP BY `parent-uri` ORDER BY `created` DESC) AS T1
352 INNER JOIN `item` ON `item`.`uri`=`T1`.`parent-uri`
353 WHERE `T1`.`liker-link` LIKE '%s%%' OR `item`.`author-link` LIKE '%s%%'
355 ORDER BY `T1`.`created` DESC
357 $a->get_baseurl(),$a->get_baseurl()
360 foreach ($r as $rr) {
361 $author = '<a href="' . $rr['liker-link'] . '">' . $rr['liker'] . '</a>';
362 $objauthor = '<a href="' . $rr['author-link'] . '">' . $rr['author-name'] . '</a>';
364 //var_dump($rr['verb'],$rr['object-type']); killme();
366 case 'http://activitystrea.ms/schema/1.0/post':
367 switch ($rr['object-type']){
368 case 'http://activitystrea.ms/schema/1.0/event':
369 $post_type = t('event');
372 $post_type = t('status');
376 if ($rr['resource-id']){
377 $post_type = t('photo');
378 $m=array(); preg_match("/\[url=([^]]*)\]/", $rr['body'], $m);
379 $rr['plink'] = $m[1];
381 $post_type = t('status');
384 $plink = '<a href="' . $rr['plink'] . '">' . $post_type . '</a>';
386 $aside['$like_items'][] = sprintf( t('%1$s likes %2$s\'s %3$s'), $author, $objauthor, $plink);
392 $aside['$photos_title'] = t('Last photos');
393 $aside['$photos_items'] = array();
394 $r = q("SELECT `photo`.`id`, `photo`.`resource-id`, `photo`.`scale`, `photo`.`desc`, `user`.`nickname`, `user`.`username` FROM
395 (SELECT `resource-id`, MAX(`scale`) as maxscale FROM `photo`
396 WHERE `profile`=0 AND `contact-id`=0 AND `album` NOT IN ('Contact Photos', '%s', 'Profile Photos', '%s')
397 AND `allow_cid`='' AND `allow_gid`='' AND `deny_cid`='' AND `deny_gid`='' GROUP BY `resource-id`) AS `t1`
398 INNER JOIN `photo` ON `photo`.`resource-id`=`t1`.`resource-id` AND `photo`.`scale` = `t1`.`maxscale`,
400 WHERE `user`.`uid` = `photo`.`uid`
401 AND `user`.`blockwall`=0
402 AND `user`.`hidewall`=0
403 ORDER BY `photo`.`edited` DESC
405 dbesc(t('Contact Photos')),
406 dbesc(t('Profile Photos'))
409 $tpl = file_get_contents( dirname(__file__).'/ch_directory_item.tpl');
411 $photo_page = $a->get_baseurl() . '/photos/' . $rr['nickname'] . '/image/' . $rr['resource-id'];
412 $photo_url = $a->get_baseurl() . '/photo/' . $rr['resource-id'] . '-' . $rr['scale'] .'.jpg';
414 $entry = replace_macros($tpl,array(
416 '$profile-link' => $photo_page,
417 '$photo' => $photo_url,
418 '$alt-text' => $rr['username']." : ".$rr['desc'],
421 $aside['$photos_items'][] = $entry;
426 //right_aside FIND FRIENDS
429 $nv['title'] = Array("", t('Find Friends'), "", "");
430 $nv['directory'] = Array('directory', t('Local Directory'), "", "");
431 $nv['global_directory'] = Array('http://dir.friendica.com/', t('Global Directory'), "", "");
432 $nv['match'] = Array('match', t('Similar Interests'), "", "");
433 $nv['suggest'] = Array('suggest', t('Friend Suggestions'), "", "");
434 $nv['invite'] = Array('invite', t('Invite Friends'), "", "");
436 $nv['search'] = '<form name="simple_bar" method="get" action="http://dir.friendika.com/directory">
437 <span class="sbox_l"></span>
439 <input type="text" name="search" size="13" maxlength="50">
441 <span class="sbox_r" id="srch_clear"></span>';
446 //Community_Pages at right_aside
448 $page = '<div id="" >
449 <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>
450 <div id=""><ul style="margin-left: 7px;margin-top: 0px;padding-left: 0px;padding-top: 0px;">';
454 $contacts = q("SELECT `id`, `url`, `name`, `micro`FROM `contact`
455 WHERE `network`= 'dfrn' AND `forum` = 1 AND `uid` = %d
456 ORDER BY `name` ASC",
457 intval($a->user['uid'])
462 // Look if the profile is a community page
463 foreach($contacts as $contact) {
464 $pageD[] = array("url"=>$contact["url"], "name"=>$contact["name"], "id"=>$contact["id"], "micro"=>$contact['micro']);
470 foreach($contacts as $contact) {
471 $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">'.
472 $contact["name"]."</a></li>";
474 $page .= '</ul></div></div>';
475 //if (sizeof($contacts) > 0)
476 $aside['$page'] = $page;
481 $helpers['title'] = Array("", t('Help or @NewHere ?'), "", "");
482 $aside['$helpers'] = $helpers;
484 //connectable services
485 $con_services = array();
486 $con_services['title'] = Array("", t('Connect Services'), "", "");
487 $aside['$con_services'] = $con_services;
488 //end connectable services
490 $url = $a->get_baseurl($ssl_state);
491 $aside['$url'] = $url;
493 $tpl = file_get_contents(dirname(__file__).'/communityhome.tpl');
494 $a->page['right_aside'] = replace_macros($tpl, $aside);
498 function js_in_foot() {
499 /** @purpose insert stuff in bottom of page
502 $baseurl = $a->get_baseurl($ssl_state);
503 $bottom['$baseurl'] = $baseurl;
504 $tpl = file_get_contents(dirname(__file__) . '/bottom.tpl');
505 $a->page['footer'] = $a->page['footer'].replace_macros($tpl, $bottom);