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";
29 //Add META viewport tag respecting the resolution to header for tablets
30 if ($resolution=="wide") {
31 $a->page['htmlhead'] .= '<meta name="viewport" content="width=1200" />';
33 $a->page['htmlhead'] .= '<meta name="viewport" content="width=980" />';
38 $site_color = get_config("diabook", "color" );
39 if (local_user()) {$color = get_pconfig(local_user(), "diabook", "color");}
40 if ($color===false) $color=$site_color;
41 if ($color===false) $color="diabook";
43 if ($color=="diabook") $color_path = "/";
44 if ($color=="aerith") $color_path = "/diabook-aerith/";
45 if ($color=="blue") $color_path = "/diabook-blue/";
46 if ($color=="red") $color_path = "/diabook-red/";
47 if ($color=="pink") $color_path = "/diabook-pink/";
48 if ($color=="green") $color_path = "/diabook-green/";
49 if ($color=="dark") $color_path = "/diabook-dark/";
52 //profile_side at networkpages
53 if ($a->argv[0] === "network" && local_user()){
58 $r = q("SELECT micro FROM contact WHERE uid=%d AND self=1", intval($a->user['uid']));
61 'icon' => (count($r) ? $r[0]['micro']: $a->get_baseurl()."/images/default-profile-mm.jpg"),
62 'name' => $a->user['username'],
64 $ps = array('usermenu'=>array());
65 $ps['usermenu']['status'] = Array('profile/' . $a->user['nickname'], t('Home'), "", t('Your posts and conversations'));
66 $ps['usermenu']['profile'] = Array('profile/' . $a->user['nickname']. '?tab=profile', t('Profile'), "", t('Your profile page'));
67 $ps['usermenu']['contacts'] = Array('contacts' , t('Contacts'), "", t('Your contacts'));
68 $ps['usermenu']['photos'] = Array('photos/' . $a->user['nickname'], t('Photos'), "", t('Your photos'));
69 $ps['usermenu']['events'] = Array('events/', t('Events'), "", t('Your events'));
70 $ps['usermenu']['notes'] = Array('notes/', t('Personal notes'), "", t('Your personal photos'));
71 $ps['usermenu']['community'] = Array('community/', t('Community'), "", "");
72 $ps['usermenu']['pgroups'] = Array('http://dir.friendica.com/directory/forum', t('Community Pages'), "", "");
74 $tpl = get_markup_template('profile_side.tpl');
76 $a->page['aside'] = replace_macros($tpl, array(
77 '$userinfo' => $userinfo,
83 $ccCookie = $_COOKIE['close_pages'] + $_COOKIE['close_profiles'] + $_COOKIE['close_helpers'] + $_COOKIE['close_services'] + $_COOKIE['close_friends'] + $_COOKIE['close_twitter'] + $_COOKIE['close_lastusers'] + $_COOKIE['close_lastphotos'] + $_COOKIE['close_lastlikes'];
85 if($ccCookie != "9") {
87 diabook_community_info();
90 if($resolution == "normal") {$cssFile = $a->get_baseurl($ssl_state)."/view/theme/diabook".$color_path."style-network.css";}
91 if($resolution == "wide") {$cssFile = $a->get_baseurl($ssl_state)."/view/theme/diabook".$color_path."style-network-wide.css";}
97 //right_aside at profile pages
98 if ($a->argv[0].$a->argv[1] === "profile".$a->user['nickname']){
99 if($ccCookie != "9") {
101 diabook_community_info();
104 if($resolution == "normal") {$cssFile = $a->get_baseurl($ssl_state)."/view/theme/diabook".$color_path."style-profile.css";}
105 if($resolution == "wide") {$cssFile = $a->get_baseurl($ssl_state)."/view/theme/diabook".$color_path."style-profile-wide.css";}
111 //load jquery.cookie.js
112 $cookieJS = $a->get_baseurl($ssl_state)."/view/theme/diabook/js/jquery.cookie.js";
113 $a->page['htmlhead'] .= sprintf('<script language="JavaScript" src="%s"></script>', $cookieJS);
115 //load jquery.ae.image.resize.js
116 $imageresizeJS = $a->get_baseurl($ssl_state)."/view/theme/diabook/js/jquery.ae.image.resize.js";
117 $a->page['htmlhead'] .= sprintf('<script language="JavaScript" src="%s" ></script>', $imageresizeJS);
120 $jqueryuiJS = $a->get_baseurl($ssl_state)."/view/theme/diabook/js/jquery-ui-1.8.20.custom.min.js";
121 $a->page['htmlhead'] .= sprintf('<script language="JavaScript" src="%s" ></script>', $jqueryuiJS);
123 //load jquery.twitter.search.js
124 if($_COOKIE['close_twitter'] != "1") {
125 $twitterJS = $a->get_baseurl($ssl_state)."/view/theme/diabook/js/jquery.twitter.search.js";
126 $a->page['htmlhead'] .= sprintf('<script language="JavaScript" src="%s" ></script>', $twitterJS);
129 $a->page['htmlhead'] .= '
133 $("a.lightbox").fancybox(); // Select all links with lightbox class
136 $(window).load(function() {
137 var footer_top = $(document).height() - 30;
138 $("div#footerbox").attr("style", "border-top: 1px solid #D2D2D2; width: 70%;right: 15%;position: absolute;top:"+footer_top+"px;");
145 //check if twitterbox is active and print
146 if($_COOKIE['close_twitter'] != "1") {
147 $a->page['htmlhead'] .= '
150 $("#twitter").twitterSearch({
155 colorExterior: "#fff",
156 title: "Last Tweets",
161 //check if community_home-plugin is activated and change css
162 $nametocheck = "communityhome";
163 $r = q("select id from addon where name = '%s' and installed = 1", dbesc($nametocheck));
164 if(count($r) == "1") {
166 $a->page['htmlhead'] .= '
168 $(document).ready(function() {
169 $("div#login-submit-wrapper").attr("style","padding-top: 120px;");
173 //comment-edit-wrapper on photo_view
174 if ($a->argv[0].$a->argv[2] === "photos"."image"){
175 $a->page['htmlhead'] .= '
178 $(".comment-edit-form").css("display","table");
182 //restore right hand col at settingspage
183 if($a->argv[0] === "settings" && local_user()) {
184 $a->page['htmlhead'] .= '
186 function restore_boxes(){
187 $.cookie("close_pages","2", { expires: 365, path: "/" });
188 $.cookie("close_helpers","2", { expires: 365, path: "/" });
189 $.cookie("close_profiles","2", { expires: 365, path: "/" });
190 $.cookie("close_services","2", { expires: 365, path: "/" });
191 $.cookie("close_friends","2", { expires: 365, path: "/" });
192 $.cookie("close_twitter","2", { expires: 365, path: "/" });
193 $.cookie("close_lastusers","2", { expires: 365, path: "/" });
194 $.cookie("close_lastphotos","2", { expires: 365, path: "/" });
195 $.cookie("close_lastlikes","2", { expires: 365, path: "/" });
196 alert("Right-hand column was restored. Please refresh your browser");
200 if ($a->argv[0].$a->argv[1] === "profile".$a->user['nickname'] or $a->argv[0] === "network" && local_user()){
201 $a->page['htmlhead'] .= '
205 $(".oembed.photo img").aeImageResize({height: 400, width: 400});
209 if($ccCookie != "9") {
210 $a->page['htmlhead'] .= '
212 $("right_aside").ready(function(){
214 if($.cookie("close_pages") == "1")
216 document.getElementById( "close_pages" ).style.display = "none";
219 if($.cookie("close_profiles") == "1")
221 document.getElementById( "close_profiles" ).style.display = "none";
224 if($.cookie("close_helpers") == "1")
226 document.getElementById( "close_helpers" ).style.display = "none";
229 if($.cookie("close_services") == "1")
231 document.getElementById( "close_services" ).style.display = "none";
234 if($.cookie("close_friends") == "1")
236 document.getElementById( "close_friends" ).style.display = "none";
239 if($.cookie("close_twitter") == "1")
241 document.getElementById( "twitter" ).style.display = "none";
244 if($.cookie("close_lastusers") == "1")
246 document.getElementById( "close_lastusers" ).style.display = "none";
249 if($.cookie("close_lastphotos") == "1")
251 document.getElementById( "close_lastphotos" ).style.display = "none";
254 if($.cookie("close_lastlikes") == "1")
256 document.getElementById( "close_lastlikes" ).style.display = "none";
261 function close_pages(){
262 document.getElementById( "close_pages" ).style.display = "none";
263 $.cookie("close_pages","1", { expires: 365, path: "/" });
266 function close_profiles(){
267 document.getElementById( "close_profiles" ).style.display = "none";
268 $.cookie("close_profiles","1", { expires: 365, path: "/" });
271 function close_helpers(){
272 document.getElementById( "close_helpers" ).style.display = "none";
273 $.cookie("close_helpers","1", { expires: 365, path: "/" });
276 function close_services(){
277 document.getElementById( "close_services" ).style.display = "none";
278 $.cookie("close_services","1", { expires: 365, path: "/" });
281 function close_friends(){
282 document.getElementById( "close_friends" ).style.display = "none";
283 $.cookie("close_friends","1", { expires: 365, path: "/" });
286 function close_twitter(){
287 document.getElementById( "twitter" ).style.display = "none";
288 $.cookie("close_twitter","1", { expires: 365, path: "/" });
291 function close_lastusers(){
292 document.getElementById( "close_lastusers" ).style.display = "none";
293 $.cookie("close_lastusers","1", { expires: 365, path: "/" });
296 function close_lastphotos(){
297 document.getElementById( "close_lastphotos" ).style.display = "none";
298 $.cookie("close_lastphotos","1", { expires: 365, path: "/" });
301 function close_lastlikes(){
302 document.getElementById( "close_lastlikes" ).style.display = "none";
303 $.cookie("close_lastlikes","1", { expires: 365, path: "/" });
310 if (!is_null($cssFile)) $a->page['htmlhead'] .= sprintf('<link rel="stylesheet" type="text/css" href="%s" />', $cssFile);
313 $tpl = get_markup_template('footer.tpl');
314 $a->page['footer'] .= replace_macros($tpl, array());
321 function diabook_community_info() {
324 if($_COOKIE['close_profiles'] != "1") {
325 $aside['$comunity_profilest_title'] = t('Community Profiles');
326 $aside['$comunity_profiles_items'] = array();
327 $r = q("select gcontact.* from gcontact left join glink on glink.gcid = gcontact.id
328 where glink.cid = 0 and glink.uid = 0 order by rand() limit 9");
329 $tpl = file_get_contents( dirname(__file__).'/ch_directory_item.tpl');
333 $profile_link = $a->get_baseurl() . '/profile/' . ((strlen($rr['nickname'])) ? $rr['nickname'] : $rr['profile_uid']);
334 $entry = replace_macros($tpl,array(
336 '$profile-link' => zrl($rr['url']),
337 '$photo' => $rr[$photo],
338 '$alt-text' => $rr['name'],
340 $aside['$comunity_profiles_items'][] = $entry;
345 if($_COOKIE['close_lastusers'] != "1") {
346 $aside['$lastusers_title'] = t('Last users');
347 $aside['$lastusers_items'] = array();
349 $publish = (get_config('system','publish_all') ? '' : " AND `publish` = 1 " );
350 $order = " ORDER BY `register_date` DESC ";
352 $r = q("SELECT `profile`.*, `profile`.`uid` AS `profile_uid`, `user`.`nickname`
353 FROM `profile` LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid`
354 WHERE `is-default` = 1 $publish AND `user`.`blocked` = 0 $sql_extra $order LIMIT %d , %d ",
358 $tpl = file_get_contents( dirname(__file__).'/ch_directory_item.tpl');
362 $profile_link = $a->get_baseurl() . '/profile/' . ((strlen($rr['nickname'])) ? $rr['nickname'] : $rr['profile_uid']);
363 $entry = replace_macros($tpl,array(
365 '$profile-link' => $profile_link,
366 '$photo' => $rr[$photo],
367 '$alt-text' => $rr['name'],
369 $aside['$lastusers_items'][] = $entry;
373 // last 10 liked items
374 if($_COOKIE['close_lastlikes'] != "1") {
375 $aside['$like_title'] = t('Last likes');
376 $aside['$like_items'] = array();
377 $r = q("SELECT `T1`.`created`, `T1`.`liker`, `T1`.`liker-link`, `item`.* FROM
378 (SELECT `parent-uri`, `created`, `author-name` AS `liker`,`author-link` AS `liker-link`
379 FROM `item` WHERE `verb`='http://activitystrea.ms/schema/1.0/like' GROUP BY `parent-uri` ORDER BY `created` DESC) AS T1
380 INNER JOIN `item` ON `item`.`uri`=`T1`.`parent-uri`
381 WHERE `T1`.`liker-link` LIKE '%s%%' OR `item`.`author-link` LIKE '%s%%'
383 ORDER BY `T1`.`created` DESC
385 $a->get_baseurl(),$a->get_baseurl()
388 foreach ($r as $rr) {
389 $author = '<a href="' . $rr['liker-link'] . '">' . $rr['liker'] . '</a>';
390 $objauthor = '<a href="' . $rr['author-link'] . '">' . $rr['author-name'] . '</a>';
392 //var_dump($rr['verb'],$rr['object-type']); killme();
394 case 'http://activitystrea.ms/schema/1.0/post':
395 switch ($rr['object-type']){
396 case 'http://activitystrea.ms/schema/1.0/event':
397 $post_type = t('event');
400 $post_type = t('status');
404 if ($rr['resource-id']){
405 $post_type = t('photo');
406 $m=array(); preg_match("/\[url=([^]]*)\]/", $rr['body'], $m);
407 $rr['plink'] = $m[1];
409 $post_type = t('status');
412 $plink = '<a href="' . $rr['plink'] . '">' . $post_type . '</a>';
414 $aside['$like_items'][] = sprintf( t('%1$s likes %2$s\'s %3$s'), $author, $objauthor, $plink);
419 if($_COOKIE['close_photos'] != "1") {
420 $aside['$photos_title'] = t('Last photos');
421 $aside['$photos_items'] = array();
422 $r = q("SELECT `photo`.`id`, `photo`.`resource-id`, `photo`.`scale`, `photo`.`desc`, `user`.`nickname`, `user`.`username` FROM
423 (SELECT `resource-id`, MAX(`scale`) as maxscale FROM `photo`
424 WHERE `profile`=0 AND `contact-id`=0 AND `album` NOT IN ('Contact Photos', '%s', 'Profile Photos', '%s')
425 AND `allow_cid`='' AND `allow_gid`='' AND `deny_cid`='' AND `deny_gid`='' GROUP BY `resource-id`) AS `t1`
426 INNER JOIN `photo` ON `photo`.`resource-id`=`t1`.`resource-id` AND `photo`.`scale` = `t1`.`maxscale`,
428 WHERE `user`.`uid` = `photo`.`uid`
429 AND `user`.`blockwall`=0
430 AND `user`.`hidewall`=0
431 ORDER BY `photo`.`edited` DESC
433 dbesc(t('Contact Photos')),
434 dbesc(t('Profile Photos'))
437 $tpl = file_get_contents( dirname(__file__).'/ch_directory_item.tpl');
439 $photo_page = $a->get_baseurl() . '/photos/' . $rr['nickname'] . '/image/' . $rr['resource-id'];
440 $photo_url = $a->get_baseurl() . '/photo/' . $rr['resource-id'] . '-' . $rr['scale'] .'.jpg';
442 $entry = replace_macros($tpl,array(
444 '$profile-link' => $photo_page,
445 '$photo' => $photo_url,
446 '$alt-text' => $rr['username']." : ".$rr['desc'],
449 $aside['$photos_items'][] = $entry;
453 //right_aside FIND FRIENDS
454 if($_COOKIE['close_friends'] != "1") {
457 $nv['title'] = Array("", t('Find Friends'), "", "");
458 $nv['directory'] = Array('directory', t('Local Directory'), "", "");
459 $nv['global_directory'] = Array('http://dir.friendica.com/', t('Global Directory'), "", "");
460 $nv['match'] = Array('match', t('Similar Interests'), "", "");
461 $nv['suggest'] = Array('suggest', t('Friend Suggestions'), "", "");
462 $nv['invite'] = Array('invite', t('Invite Friends'), "", "");
464 $nv['search'] = '<form name="simple_bar" method="get" action="http://dir.friendika.com/directory">
465 <span class="sbox_l"></span>
467 <input type="text" name="search" size="13" maxlength="50">
469 <span class="sbox_r" id="srch_clear"></span>';
474 //Community_Pages at right_aside
475 if($_COOKIE['close_pages'] != "1") {
478 <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>
479 <div id=""><ul style="margin-left: 7px;margin-top: 0px;padding-left: 0px;padding-top: 0px;">';
483 $contacts = q("SELECT `id`, `url`, `name`, `micro`FROM `contact`
484 WHERE `network`= 'dfrn' AND `forum` = 1 AND `uid` = %d
485 ORDER BY `name` ASC",
486 intval($a->user['uid'])
491 // Look if the profile is a community page
492 foreach($contacts as $contact) {
493 $pageD[] = array("url"=>$contact["url"], "name"=>$contact["name"], "id"=>$contact["id"], "micro"=>$contact['micro']);
499 foreach($contacts as $contact) {
500 $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">'.
501 $contact["name"]."</a></li>";
503 $page .= '</ul></div>';
504 //if (sizeof($contacts) > 0)
505 $aside['$page'] = $page;
510 if($_COOKIE['close_helpers'] != "1") {
512 $helpers['title'] = Array("", t('Help or @NewHere ?'), "", "");
513 $aside['$helpers'] = $helpers;
516 //connectable services
517 if($_COOKIE['close_services'] != "1") {
518 $con_services = array();
519 $con_services['title'] = Array("", t('Connect Services'), "", "");
520 $aside['$con_services'] = $con_services;
522 //end connectable services
524 $url = $a->get_baseurl($ssl_state);
525 $aside['$url'] = $url;
527 $tpl = file_get_contents(dirname(__file__).'/communityhome.tpl');
528 $a->page['right_aside'] = replace_macros($tpl, $aside);
532 function js_in_foot() {
533 /** @purpose insert stuff in bottom of page
536 $baseurl = $a->get_baseurl($ssl_state);
537 $bottom['$baseurl'] = $baseurl;
538 $tpl = file_get_contents(dirname(__file__) . '/bottom.tpl');
539 $a->page['footer'] = $a->page['footer'].replace_macros($tpl, $bottom);