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.022)
11 //print diabook-version for debugging
12 $diabook_version = "Diabook (Version: 1.022)";
13 $a->page['htmlhead'] .= sprintf('<script "%s" ></script>', $diabook_version);
15 //change css on network and profilepages
18 $resolution = get_pconfig(local_user(), "diabook", "resolution");
19 if ($resolution===false) $resolution="normal";
21 $color = get_pconfig(local_user(), "diabook", "color");
22 if ($color===false) $color="diabook";
23 if ($color=="diabook") $color_path = "/";
24 if ($color=="aerith") $color_path = "/diabook-aerith/";
25 if ($color=="blue") $color_path = "/diabook-blue/";
26 if ($color=="red") $color_path = "/diabook-red/";
27 if ($color=="pink") $color_path = "/diabook-pink/";
28 if ($color=="green") $color_path = "/diabook-green/";
29 if ($color=="dark") $color_path = "/diabook-dark/";
33 * prints last community activity
38 function diabook_community_info(){
43 $aside['$lastusers_title'] = t('Last users');
44 $aside['$lastusers_items'] = array();
46 $publish = (get_config('system','publish_all') ? '' : " AND `publish` = 1 " );
47 $order = " ORDER BY `register_date` DESC ";
49 $r = q("SELECT `profile`.*, `profile`.`uid` AS `profile_uid`, `user`.`nickname`
50 FROM `profile` LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid`
51 WHERE `is-default` = 1 $publish AND `user`.`blocked` = 0 $sql_extra $order LIMIT %d , %d ",
55 $tpl = file_get_contents( dirname(__file__).'/ch_directory_item.tpl');
59 $profile_link = $a->get_baseurl() . '/profile/' . ((strlen($rr['nickname'])) ? $rr['nickname'] : $rr['profile_uid']);
60 $entry = replace_macros($tpl,array(
62 '$profile-link' => $profile_link,
63 '$photo' => $rr[$photo],
64 '$alt-text' => $rr['name'],
66 $aside['$lastusers_items'][] = $entry;
71 // last 10 liked items
72 $aside['$like_title'] = t('Last likes');
73 $aside['$like_items'] = array();
74 $r = q("SELECT `T1`.`created`, `T1`.`liker`, `T1`.`liker-link`, `item`.* FROM
75 (SELECT `parent-uri`, `created`, `author-name` AS `liker`,`author-link` AS `liker-link`
76 FROM `item` WHERE `verb`='http://activitystrea.ms/schema/1.0/like' GROUP BY `parent-uri` ORDER BY `created` DESC) AS T1
77 INNER JOIN `item` ON `item`.`uri`=`T1`.`parent-uri`
78 WHERE `T1`.`liker-link` LIKE '%s%%' OR `item`.`author-link` LIKE '%s%%'
80 ORDER BY `T1`.`created` DESC
82 $a->get_baseurl(),$a->get_baseurl()
86 $author = '<a href="' . $rr['liker-link'] . '">' . $rr['liker'] . '</a>';
87 $objauthor = '<a href="' . $rr['author-link'] . '">' . $rr['author-name'] . '</a>';
89 //var_dump($rr['verb'],$rr['object-type']); killme();
91 case 'http://activitystrea.ms/schema/1.0/post':
92 switch ($rr['object-type']){
93 case 'http://activitystrea.ms/schema/1.0/event':
94 $post_type = t('event');
97 $post_type = t('status');
101 if ($rr['resource-id']){
102 $post_type = t('photo');
103 $m=array(); preg_match("/\[url=([^]]*)\]/", $rr['body'], $m);
104 $rr['plink'] = $m[1];
106 $post_type = t('status');
109 $plink = '<a href="' . $rr['plink'] . '">' . $post_type . '</a>';
111 $aside['$like_items'][] = sprintf( t('%1$s likes %2$s\'s %3$s'), $author, $objauthor, $plink);
117 $aside['$photos_title'] = t('Last photos');
118 $aside['$photos_items'] = array();
119 $r = q("SELECT `photo`.`id`, `photo`.`resource-id`, `photo`.`scale`, `photo`.`desc`, `user`.`nickname`, `user`.`username` FROM
120 (SELECT `resource-id`, MAX(`scale`) as maxscale FROM `photo`
121 WHERE `profile`=0 AND `contact-id`=0 AND `album` NOT IN ('Contact Photos', '%s', 'Profile Photos', '%s')
122 AND `allow_cid`='' AND `allow_gid`='' AND `deny_cid`='' AND `deny_gid`='' GROUP BY `resource-id`) AS `t1`
123 INNER JOIN `photo` ON `photo`.`resource-id`=`t1`.`resource-id` AND `photo`.`scale` = `t1`.`maxscale`,
125 WHERE `user`.`uid` = `photo`.`uid`
126 AND `user`.`blockwall`=0
127 AND `user`.`hidewall`=0
128 ORDER BY `photo`.`edited` DESC
130 dbesc(t('Contact Photos')),
131 dbesc(t('Profile Photos'))
134 $tpl = file_get_contents( dirname(__file__).'/ch_directory_item.tpl');
136 $photo_page = $a->get_baseurl() . '/photos/' . $rr['nickname'] . '/image/' . $rr['resource-id'];
137 $photo_url = $a->get_baseurl() . '/photo/' . $rr['resource-id'] . '-' . $rr['scale'] .'.jpg';
139 $entry = replace_macros($tpl,array(
141 '$profile-link' => $photo_page,
142 '$photo' => $photo_url,
143 '$alt-text' => $rr['username']." : ".$rr['desc'],
146 $aside['$photos_items'][] = $entry;
151 //right_aside FIND FRIENDS
154 $nv['title'] = Array("", t('Find Friends'), "", "");
155 $nv['directory'] = Array('directory', t('Local Directory'), "", "");
156 $nv['global_directory'] = Array('http://dir.friendica.com/', t('Global Directory'), "", "");
157 $nv['match'] = Array('match', t('Similar Interests'), "", "");
158 $nv['suggest'] = Array('suggest', t('Friend Suggestions'), "", "");
159 $nv['invite'] = Array('invite', t('Invite Friends'), "", "");
161 $nv['search'] = '<form name="simple_bar" method="get" action="http://dir.friendika.com/directory">
162 <span class="sbox_l"></span>
164 <input type="text" name="search" size="13" maxlength="50">
166 <span class="sbox_r" id="srch_clear"></span>';
173 $page = '<div id="page-sidebar-right_aside" class="widget">
174 <div class="title tool">
175 <h3>'.t("Community Pages").'<a id="close_pages_icon" onClick="close_pages()" class="icon close_box" title="close"></a></h3></div>
176 <div id="sidebar-page-list"><ul>';
180 $contacts = q("SELECT `id`, `url`, `name`, `micro`FROM `contact`
181 WHERE `network`= 'dfrn' AND `forum` = 1 AND `uid` = %d
182 ORDER BY `name` ASC",
183 intval($a->user['uid'])
188 // Look if the profile is a community page
189 foreach($contacts as $contact) {
190 $pageD[] = array("url"=>$contact["url"], "name"=>$contact["name"], "id"=>$contact["id"], "micro"=>$contact['micro']);
196 foreach($contacts as $contact) {
197 $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;" title="' . $contact['url'] . '" class="label" target="external-link">'.
198 $contact["name"]."</a></li>";
200 $page .= '</ul></div></div>';
201 //if (sizeof($contacts) > 0)
203 $aside['$page'] = $page;
208 $helpers['title'] = Array("", t('Help or @NewHere ?'), "", "");
210 $aside['$helpers'] = $helpers;
212 //connectable services
213 $con_services = array();
214 $con_services['title'] = Array("", t('Connect Services'), "", "");
216 $aside['$con_services'] = $con_services;
217 //end connectable services
221 $url = $a->get_baseurl($ssl_state);
222 $aside['$url'] = $url;
224 $tpl = file_get_contents(dirname(__file__).'/communityhome.tpl');
225 $a->page['right_aside'] = replace_macros($tpl, $aside);
233 //profile_side at networkpages
234 if ($a->argv[0] === "network" && local_user()){
239 $r = q("SELECT micro FROM contact WHERE uid=%d AND self=1", intval($a->user['uid']));
242 'icon' => (count($r) ? $r[0]['micro']: $a->get_baseurl()."/images/default-profile-mm.jpg"),
243 'name' => $a->user['username'],
245 $ps = array('usermenu'=>array());
246 $ps['usermenu']['status'] = Array('profile/' . $a->user['nickname'], t('Home'), "", t('Your posts and conversations'));
247 $ps['usermenu']['profile'] = Array('profile/' . $a->user['nickname']. '?tab=profile', t('Profile'), "", t('Your profile page'));
248 $ps['usermenu']['contacts'] = Array('contacts' , t('Contacts'), "", t('Your contacts'));
249 $ps['usermenu']['photos'] = Array('photos/' . $a->user['nickname'], t('Photos'), "", t('Your photos'));
250 $ps['usermenu']['events'] = Array('events/', t('Events'), "", t('Your events'));
251 $ps['usermenu']['notes'] = Array('notes/', t('Personal notes'), "", t('Your personal photos'));
252 $ps['usermenu']['community'] = Array('community/', t('Community'), "", "");
253 $ps['usermenu']['pgroups'] = Array('http://dir.friendica.com/directory/forum', t('Community Pages'), "", "");
255 $tpl = get_markup_template('profile_side.tpl');
257 $a->page['aside'] .= replace_macros($tpl, array(
258 '$userinfo' => $userinfo,
264 $ccCookie = $_COOKIE['close_pages'] + $_COOKIE['close_helpers'] + $_COOKIE['close_services'] + $_COOKIE['close_friends'] + $_COOKIE['close_lastusers'] + $_COOKIE['close_lastphotos'] + $_COOKIE['close_lastlikes'];
266 if($ccCookie != "7") {
268 diabook_community_info();
271 if($resolution == "normal") {$cssFile = $a->get_baseurl($ssl_state)."/view/theme/diabook".$color_path."style-network.css";}
272 if($resolution == "wide") {$cssFile = $a->get_baseurl($ssl_state)."/view/theme/diabook".$color_path."style-network-wide.css";}
278 //right_aside at profile pages
279 if ($a->argv[0].$a->argv[1] === "profile".$a->user['nickname']){
280 if($ccCookie != "7") {
282 diabook_community_info();
285 if($resolution == "normal") {$cssFile = $a->get_baseurl($ssl_state)."/view/theme/diabook".$color_path."style-profile.css";}
286 if($resolution == "wide") {$cssFile = $a->get_baseurl($ssl_state)."/view/theme/diabook".$color_path."style-profile-wide.css";}
292 if (!is_null($cssFile)) $a->page['htmlhead'] .= sprintf('<link rel="stylesheet" type="text/css" href="%s" />', $cssFile);
295 $tpl = get_markup_template('footer.tpl');
296 $a->page['footer'] .= replace_macros($tpl, array());
298 //load jquery.cookie.js
299 $cookieJS = $a->get_baseurl($ssl_state)."/view/theme/diabook/js/jquery.cookie.js";
300 $a->page['htmlhead'] .= sprintf('<script language="JavaScript" src="%s"></script>', $cookieJS);
302 //load jquery.ae.image.resize.js
303 $imageresizeJS = $a->get_baseurl($ssl_state)."/view/theme/diabook/js/jquery.ae.image.resize.js";
304 $a->page['htmlhead'] .= sprintf('<script language="JavaScript" src="%s" ></script>', $imageresizeJS);
306 //load jquery.autogrow-textarea.js
307 $autogrowJS = $a->get_baseurl($ssl_state)."/view/theme/diabook/js/jquery.autogrow.textarea.js";
308 $a->page['htmlhead'] .= sprintf('<script language="JavaScript" src="%s" ></script>', $autogrowJS);
311 //comment-edit-wrapper on photo_view
312 if ($a->argv[0].$a->argv[2] === "photos"."image"){
314 $a->page['htmlhead'] .= '
318 $(".comment-edit-form").css("display","table");
325 $a->page['htmlhead'] .= '
329 $("a.lightbox").fancybox(); // Select all links with lightbox class
335 $a->page['htmlhead'] .= '
337 <script type="text/javascript">
339 function tautogrow(id){
340 $("textarea#comment-edit-text-" +id).autogrow();
345 $a->page['htmlhead'] .= '
348 $(document).ready(function() {
349 $("iframe").each(function(){
350 var ifr_source = $(this).attr("src");
351 var wmode = "wmode=transparent";
352 if(ifr_source.indexOf("?") != -1) {
353 var getQString = ifr_source.split("?");
354 var oldString = getQString[1];
355 var newString = getQString[0];
356 $(this).attr("src",newString+"?"+wmode+"&"+oldString);
358 else $(this).attr("src",ifr_source+"?"+wmode);
364 function yt_iframe() {
366 $("iframe").load(function() {
367 var ifr_src = $(this).contents().find("body iframe").attr("src");
368 $("iframe").contents().find("body iframe").attr("src", ifr_src+"&wmode=transparent");
373 function scrolldown(){
374 $("html, body").animate({scrollTop:$(document).height()}, "slow");
378 function scrolltop(){
379 $("html, body").animate({scrollTop:0}, "slow");
383 $(window).scroll(function () {
386 var scrollInfo = $(window).scrollTop();
388 if (scrollInfo <= "900"){
389 $("a#top").attr("id","down");
390 $("a#down").attr("onclick","scrolldown()");
391 $("img#scroll_top_bottom").attr("src","view/theme/diabook/icons/scroll_bottom.png");
394 if (scrollInfo > "900"){
395 $("a#down").attr("id","top");
396 $("a#top").attr("onclick","scrolltop()");
397 $("img#scroll_top_bottom").attr("src","view/theme/diabook/icons/scroll_top.png");
404 if($a->argv[0] === "settings" && local_user()) {
405 $a->page['htmlhead'] .= '
407 function restore_boxes(){
408 $.cookie("close_pages","2", { expires: 365, path: "/" });
409 $.cookie("close_helpers","2", { expires: 365, path: "/" });
410 $.cookie("close_services","2", { expires: 365, path: "/" });
411 $.cookie("close_friends","2", { expires: 365, path: "/" });
412 $.cookie("close_lastusers","2", { expires: 365, path: "/" });
413 $.cookie("close_lastphotos","2", { expires: 365, path: "/" });
414 $.cookie("close_lastlikes","2", { expires: 365, path: "/" });
415 alert("Right-hand column was restored. Please refresh your browser");
421 if ($a->argv[0].$a->argv[1] === "profile".$a->user['nickname'] or $a->argv[0] === "network" && local_user()){
422 $a->page['htmlhead'] .= '
426 $(".oembed.photo img").aeImageResize({height: 400, width: 400});
431 if($ccCookie != "7") {
432 $a->page['htmlhead'] .= '
434 $("right_aside").ready(function(){
436 if($.cookie("close_pages") == "1")
438 document.getElementById( "close_pages" ).style.display = "none";
441 if($.cookie("close_helpers") == "1")
443 document.getElementById( "close_helpers" ).style.display = "none";
446 if($.cookie("close_services") == "1")
448 document.getElementById( "close_services" ).style.display = "none";
451 if($.cookie("close_friends") == "1")
453 document.getElementById( "close_friends" ).style.display = "none";
457 if($.cookie("close_lastusers") == "1")
459 document.getElementById( "close_lastusers" ).style.display = "none";
462 if($.cookie("close_lastphotos") == "1")
464 document.getElementById( "close_lastphotos" ).style.display = "none";
467 if($.cookie("close_lastlikes") == "1")
469 document.getElementById( "close_lastlikes" ).style.display = "none";
474 function close_pages(){
475 document.getElementById( "close_pages" ).style.display = "none";
476 $.cookie("close_pages","1", { expires: 365, path: "/" });
479 function close_helpers(){
480 document.getElementById( "close_helpers" ).style.display = "none";
481 $.cookie("close_helpers","1", { expires: 365, path: "/" });
484 function close_services(){
485 document.getElementById( "close_services" ).style.display = "none";
486 $.cookie("close_services","1", { expires: 365, path: "/" });
489 function close_friends(){
490 document.getElementById( "close_friends" ).style.display = "none";
491 $.cookie("close_friends","1", { expires: 365, path: "/" });
495 function close_lastusers(){
496 document.getElementById( "close_lastusers" ).style.display = "none";
497 $.cookie("close_lastusers","1", { expires: 365, path: "/" });
500 function close_lastphotos(){
501 document.getElementById( "close_lastphotos" ).style.display = "none";
502 $.cookie("close_lastphotos","1", { expires: 365, path: "/" });
505 function close_lastlikes(){
506 document.getElementById( "close_lastlikes" ).style.display = "none";
507 $.cookie("close_lastlikes","1", { expires: 365, path: "/" });
511 $a->page['htmlhead'] .= '
514 function insertFormatting(comment,BBcode,id) {
516 var tmpStr = $("#comment-edit-text-" + id).val();
517 if(tmpStr == comment) {
519 $("#comment-edit-text-" + id).addClass("comment-edit-text-full");
520 $("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
521 openMenu("comment-edit-submit-wrapper-" + id);
524 textarea = document.getElementById("comment-edit-text-" +id);
525 if (document.selection) {
527 selected = document.selection.createRange();
528 if (BBcode == "url"){
529 selected.text = "["+BBcode+"]" + "http://" + selected.text + "[/"+BBcode+"]";
531 selected.text = "["+BBcode+"]" + selected.text + "[/"+BBcode+"]";
532 } else if (textarea.selectionStart || textarea.selectionStart == "0") {
533 var start = textarea.selectionStart;
534 var end = textarea.selectionEnd;
535 if (BBcode == "url"){
536 textarea.value = textarea.value.substring(0, start) + "["+BBcode+"]" + "http://" + textarea.value.substring(start, end) + "[/"+BBcode+"]" + textarea.value.substring(end, textarea.value.length);
538 textarea.value = textarea.value.substring(0, start) + "["+BBcode+"]" + textarea.value.substring(start, end) + "[/"+BBcode+"]" + textarea.value.substring(end, textarea.value.length);
543 function cmtBbOpen(id) {
544 $(".comment-edit-bb-" + id).show();
546 function cmtBbClose(id) {
547 $(".comment-edit-bb-" + id).hide();