5 * Description: Diabook-red: report bugs and request here: http://pad.toktan.org/p/diabook or contact me : thomas_bierey@friendica.eu
6 * Version: (Version: 1.019)
11 //print diabook-version for debugging
12 $diabook_version = "Diabook-red (Version: 1.019)";
13 $a->page['htmlhead'] .= sprintf('<script "%s" ></script>', $diabook_version);
15 //change css on network and profilepages
20 * prints last community activity
22 function diabook_red_community_info(){
26 $aside['$lastusers_title'] = t('Last users');
27 $aside['$lastusers_items'] = array();
29 $publish = (get_config('system','publish_all') ? '' : " AND `publish` = 1 " );
30 $order = " ORDER BY `register_date` DESC ";
32 $r = q("SELECT `profile`.*, `profile`.`uid` AS `profile_uid`, `user`.`nickname`
33 FROM `profile` LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid`
34 WHERE `is-default` = 1 $publish AND `user`.`blocked` = 0 $sql_extra $order LIMIT %d , %d ",
38 $tpl = file_get_contents( dirname(__file__).'/ch_directory_item.tpl');
42 $profile_link = $a->get_baseurl() . '/profile/' . ((strlen($rr['nickname'])) ? $rr['nickname'] : $rr['profile_uid']);
43 $entry = replace_macros($tpl,array(
45 '$profile-link' => $profile_link,
46 '$photo' => $rr[$photo],
47 '$alt-text' => $rr['name'],
49 $aside['$lastusers_items'][] = $entry;
54 // last 10 liked items
55 $aside['$like_title'] = t('Last likes');
56 $aside['$like_items'] = array();
57 $r = q("SELECT `T1`.`created`, `T1`.`liker`, `T1`.`liker-link`, `item`.* FROM
58 (SELECT `parent-uri`, `created`, `author-name` AS `liker`,`author-link` AS `liker-link`
59 FROM `item` WHERE `verb`='http://activitystrea.ms/schema/1.0/like' GROUP BY `parent-uri` ORDER BY `created` DESC) AS T1
60 INNER JOIN `item` ON `item`.`uri`=`T1`.`parent-uri`
61 WHERE `T1`.`liker-link` LIKE '%s%%' OR `item`.`author-link` LIKE '%s%%'
63 ORDER BY `T1`.`created` DESC
65 $a->get_baseurl(),$a->get_baseurl()
69 $author = '<a href="' . $rr['liker-link'] . '">' . $rr['liker'] . '</a>';
70 $objauthor = '<a href="' . $rr['author-link'] . '">' . $rr['author-name'] . '</a>';
72 //var_dump($rr['verb'],$rr['object-type']); killme();
74 case 'http://activitystrea.ms/schema/1.0/post':
75 switch ($rr['object-type']){
76 case 'http://activitystrea.ms/schema/1.0/event':
77 $post_type = t('event');
80 $post_type = t('status');
84 if ($rr['resource-id']){
85 $post_type = t('photo');
86 $m=array(); preg_match("/\[url=([^]]*)\]/", $rr['body'], $m);
89 $post_type = t('status');
92 $plink = '<a href="' . $rr['plink'] . '">' . $post_type . '</a>';
94 $aside['$like_items'][] = sprintf( t('%1$s likes %2$s\'s %3$s'), $author, $objauthor, $plink);
100 $aside['$photos_title'] = t('Last photos');
101 $aside['$photos_items'] = array();
102 $r = q("SELECT `photo`.`id`, `photo`.`resource-id`, `photo`.`scale`, `photo`.`desc`, `user`.`nickname`, `user`.`username` FROM
103 (SELECT `resource-id`, MAX(`scale`) as maxscale FROM `photo`
104 WHERE `profile`=0 AND `contact-id`=0 AND `album` NOT IN ('Contact Photos', '%s', 'Profile Photos', '%s')
105 AND `allow_cid`='' AND `allow_gid`='' AND `deny_cid`='' AND `deny_gid`='' GROUP BY `resource-id`) AS `t1`
106 INNER JOIN `photo` ON `photo`.`resource-id`=`t1`.`resource-id` AND `photo`.`scale` = `t1`.`maxscale`,
108 WHERE `user`.`uid` = `photo`.`uid`
109 AND `user`.`blockwall`=0
110 AND `user`.`hidewall`=0
111 ORDER BY `photo`.`edited` DESC
113 dbesc(t('Contact Photos')),
114 dbesc(t('Profile Photos'))
117 $tpl = file_get_contents( dirname(__file__).'/ch_directory_item.tpl');
119 $photo_page = $a->get_baseurl() . '/photos/' . $rr['nickname'] . '/image/' . $rr['resource-id'];
120 $photo_url = $a->get_baseurl() . '/photo/' . $rr['resource-id'] . '-' . $rr['scale'] .'.jpg';
122 $entry = replace_macros($tpl,array(
124 '$profile-link' => $photo_page,
125 '$photo' => $photo_url,
126 '$alt-text' => $rr['username']." : ".$rr['desc'],
129 $aside['$photos_items'][] = $entry;
133 $fostitJS = "javascript: (function() {
134 the_url = '".$a->get_baseurl($ssl_state)."/view/theme/diabook-red/fpostit/fpostit.php?url=' + encodeURIComponent(window.location.href) + '&title=' + encodeURIComponent(document.title) + '&text=' + encodeURIComponent(''+(window.getSelection ? window.getSelection() : document.getSelection ? document.getSelection() : document.selection.createRange().text));
135 a_funct = function() {
136 if (!window.open(the_url, 'fpostit', 'location=yes,links=no,scrollbars=no,toolbar=no,width=600,height=300')) location.href = the_url};
137 if (/Firefox/.test(navigator.userAgent)) {setTimeout(a_funct, 0)}
138 else {a_funct()}})()" ;
140 $aside['$fostitJS'] = $fostitJS;
145 $nv['title'] = Array("", t('Find Friends'), "", "");
146 $nv['directory'] = Array('directory', t('Local Directory'), "", "");
147 $nv['global_directory'] = Array('http://dir.friendica.com/', t('Global Directory'), "", "");
148 $nv['match'] = Array('match', t('Similar Interests'), "", "");
149 $nv['suggest'] = Array('suggest', t('Friend Suggestions'), "", "");
150 $nv['invite'] = Array('invite', t('Invite Friends'), "", "");
152 $nv['search'] = '<form name="simple_bar" method="get" action="http://dir.friendika.com/directory">
153 <span class="sbox_l"></span>
155 <input type="text" name="search" size="13" maxlength="50">
157 <span class="sbox_r" id="srch_clear"></span>';
163 $page = '<div id="page-sidebar-right_aside" class="widget">
164 <div class="title tool">
165 <h3>'.t("Community Pages").'<a id="close_pages_icon" onClick="close_pages()" class="icon close_box" title="close"></a></h3></div>
166 <div id="sidebar-page-list"><ul>';
170 $contacts = q("SELECT `id`, `url`, `name`, `micro`FROM `contact`
171 WHERE `network`= 'dfrn' AND `forum` = 1 AND `uid` = %d
172 ORDER BY `name` ASC",
173 intval($a->user['uid'])
178 // Look if the profile is a community page
179 foreach($contacts as $contact) {
180 $pageD[] = array("url"=>$contact["url"], "name"=>$contact["name"], "id"=>$contact["id"], "micro"=>$contact['micro']);
186 foreach($contacts as $contact) {
187 $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">'.
188 $contact["name"]."</a></li>";
190 $page .= '</ul></div></div>';
191 //if (sizeof($contacts) > 0)
193 $aside['$page'] = $page;
198 $helpers['title'] = Array("", t('Help or @NewHere ?'), "", "");
200 $aside['$helpers'] = $helpers;
202 //connectable services
203 $con_services = array();
204 $con_services['title'] = Array("", t('Connect Services'), "", "");
206 $aside['$con_services'] = $con_services;
207 //end connectable services
210 $postit['title'] = Array("", t('PostIt to Friendica'), t('Post to Friendica'), "");
211 $postit['text'] = Array("", t(' from anywhere by bookmarking this Link.'), "", "");
213 $aside['$postit'] = $postit;
217 $url = $a->get_baseurl($ssl_state);
218 $aside['$url'] = $url;
220 $tpl = file_get_contents(dirname(__file__).'/communityhome.tpl');
221 $a->page['right_aside'] = replace_macros($tpl, $aside);
226 //profile_side at networkpages
227 if ($a->argv[0] === "network" && local_user()){
232 $r = q("SELECT micro FROM contact WHERE uid=%d AND self=1", intval($a->user['uid']));
235 'icon' => (count($r) ? $r[0]['micro']: $a->get_baseurl()."/images/default-profile-mm.jpg"),
236 'name' => $a->user['username'],
238 $ps = array('usermenu'=>array());
239 $ps['usermenu']['status'] = Array('profile/' . $a->user['nickname'], t('Home'), "", t('Your posts and conversations'));
240 $ps['usermenu']['profile'] = Array('profile/' . $a->user['nickname']. '?tab=profile', t('Profile'), "", t('Your profile page'));
241 $ps['usermenu']['contacts'] = Array('contacts' , t('Contacts'), "", t('Your contacts'));
242 $ps['usermenu']['photos'] = Array('photos/' . $a->user['nickname'], t('Photos'), "", t('Your photos'));
243 $ps['usermenu']['events'] = Array('events/', t('Events'), "", t('Your events'));
244 $ps['usermenu']['notes'] = Array('notes/', t('Personal notes'), "", t('Your personal photos'));
245 $ps['usermenu']['community'] = Array('community/', t('Community'), "", "");
246 $ps['usermenu']['pgroups'] = Array('http://dir.friendika.com/directory/forum', t('Community Pages'), "", "");
248 $tpl = get_markup_template('profile_side.tpl');
250 $a->page['aside'] .= replace_macros($tpl, array(
251 '$userinfo' => $userinfo,
257 $ccCookie = $_COOKIE['close_pages'] + $_COOKIE['close_helpers'] + $_COOKIE['close_services'] + $_COOKIE['close_friends'] + $_COOKIE['close_postit'] + $_COOKIE['close_lastusers'] + $_COOKIE['close_lastphotos'] + $_COOKIE['close_lastlikes'];
259 if($ccCookie != "8") {
261 diabook_red_community_info();
264 $cssFile = $a->get_baseurl($ssl_state)."/view/theme/diabook-red/style-network.css";
270 //right_aside at profile pages
271 if ($a->argv[0].$a->argv[1] === "profile".$a->user['nickname']){
272 if($ccCookie != "8") {
274 diabook_red_community_info();
277 $cssFile = $a->get_baseurl($ssl_state)."/view/theme/diabook-red/style-profile.css";
282 if (!is_null($cssFile)) $a->page['htmlhead'] .= sprintf('<link rel="stylesheet" type="text/css" href="%s" />', $cssFile);
284 //load jquery.cookie.js
285 $cookieJS = $a->get_baseurl($ssl_state)."/view/theme/diabook-red/js/jquery.cookie.js";
286 $a->page['htmlhead'] .= sprintf('<script language="JavaScript" src="%s" ></script>', $cookieJS);
288 //load jquery.ae.image.resize.js
289 $imageresizeJS = $a->get_baseurl($ssl_state)."/view/theme/diabook-red/js/jquery.ae.image.resize.js";
290 $a->page['htmlhead'] .= sprintf('<script language="JavaScript" src="%s" ></script>', $imageresizeJS);
292 //load jquery.autogrow-textarea.js
293 $autogrowJS = $a->get_baseurl($ssl_state)."/view/theme/diabook-red/js/jquery.autogrow.textarea.js";
294 $a->page['htmlhead'] .= sprintf('<script language="JavaScript" src="%s" ></script>', $autogrowJS);
297 //comment-edit-wrapper on photo_view
298 if ($a->argv[0].$a->argv[2] === "photos"."image"){
300 $a->page['htmlhead'] .= '
304 $(".comment-edit-form").css("display","table");
311 $a->page['htmlhead'] .= '
315 $("a.lightbox").fancybox(); // Select all links with lightbox class
320 $a->page['htmlhead'] .= '
322 <script type="text/javascript">
324 function tautogrow(id){
325 $("textarea#comment-edit-text-" +id).autogrow();
329 $a->page['htmlhead'] .= '
332 $(document).ready(function() {
333 $("iframe").each(function(){
334 var ifr_source = $(this).attr("src");
335 var wmode = "wmode=transparent";
336 if(ifr_source.indexOf("?") != -1) {
337 var getQString = ifr_source.split("?");
338 var oldString = getQString[1];
339 var newString = getQString[0];
340 $(this).attr("src",newString+"?"+wmode+"&"+oldString);
342 else $(this).attr("src",ifr_source+"?"+wmode);
348 function yt_iframe() {
350 $("iframe").load(function() {
351 var ifr_src = $(this).contents().find("body iframe").attr("src");
352 $("iframe").contents().find("body iframe").attr("src", ifr_src+"&wmode=transparent");
360 if ($a->argv[0].$a->argv[1] === "profile".$a->user['nickname'] or $a->argv[0] === "network" && local_user()){
361 $a->page['htmlhead'] .= '
365 $(".oembed.photo img").aeImageResize({height: 400, width: 400});
370 if($ccCookie != "8") {
371 $a->page['htmlhead'] .= '
373 $("right_aside").ready(function(){
375 if($.cookie("close_pages") == "1")
377 document.getElementById( "close_pages" ).style.display = "none";
380 if($.cookie("close_helpers") == "1")
382 document.getElementById( "close_helpers" ).style.display = "none";
385 if($.cookie("close_services") == "1")
387 document.getElementById( "close_services" ).style.display = "none";
390 if($.cookie("close_friends") == "1")
392 document.getElementById( "close_friends" ).style.display = "none";
395 if($.cookie("close_postit") == "1")
397 document.getElementById( "close_postit" ).style.display = "none";
400 if($.cookie("close_lastusers") == "1")
402 document.getElementById( "close_lastusers" ).style.display = "none";
405 if($.cookie("close_lastphotos") == "1")
407 document.getElementById( "close_lastphotos" ).style.display = "none";
410 if($.cookie("close_lastlikes") == "1")
412 document.getElementById( "close_lastlikes" ).style.display = "none";
417 function close_pages(){
418 document.getElementById( "close_pages" ).style.display = "none";
419 $.cookie("close_pages","1", { expires: 365, path: "/" });
422 function close_helpers(){
423 document.getElementById( "close_helpers" ).style.display = "none";
424 $.cookie("close_helpers","1", { expires: 365, path: "/" });
427 function close_services(){
428 document.getElementById( "close_services" ).style.display = "none";
429 $.cookie("close_services","1", { expires: 365, path: "/" });
432 function close_friends(){
433 document.getElementById( "close_friends" ).style.display = "none";
434 $.cookie("close_friends","1", { expires: 365, path: "/" });
437 function close_postit(){
438 document.getElementById( "close_postit" ).style.display = "none";
439 $.cookie("close_postit","1", { expires: 365, path: "/" });
442 function close_lastusers(){
443 document.getElementById( "close_lastusers" ).style.display = "none";
444 $.cookie("close_lastusers","1", { expires: 365, path: "/" });
447 function close_lastphotos(){
448 document.getElementById( "close_lastphotos" ).style.display = "none";
449 $.cookie("close_lastphotos","1", { expires: 365, path: "/" });
452 function close_lastlikes(){
453 document.getElementById( "close_lastlikes" ).style.display = "none";
454 $.cookie("close_lastlikes","1", { expires: 365, path: "/" });
458 $a->page['htmlhead'] .= '
460 function restore_boxes(){
461 $.cookie("close_pages","2", { expires: 365, path: "/" });
462 $.cookie("close_helpers","2", { expires: 365, path: "/" });
463 $.cookie("close_services","2", { expires: 365, path: "/" });
464 $.cookie("close_friends","2", { expires: 365, path: "/" });
465 $.cookie("close_postit","2", { expires: 365, path: "/" });
466 $.cookie("close_lastusers","2", { expires: 365, path: "/" });
467 $.cookie("close_lastphotos","2", { expires: 365, path: "/" });
468 $.cookie("close_lastlikes","2", { expires: 365, path: "/" });
469 alert("Right-hand column was restored. Please refresh your browser");
473 $a->page['htmlhead'] .= '
475 <script type="text/javascript">
476 function insertFormatting(comment,BBcode,id) {
478 var tmpStr = $("#comment-edit-text-" + id).val();
479 if(tmpStr == comment) {
481 $("#comment-edit-text-" + id).addClass("comment-edit-text-full");
482 $("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
483 openMenu("comment-edit-submit-wrapper-" + id);
486 textarea = document.getElementById("comment-edit-text-" +id);
487 if (document.selection) {
489 selected = document.selection.createRange();
490 if (BBcode == "url"){
491 selected.text = "["+BBcode+"]" + "http://" + selected.text + "[/"+BBcode+"]";
493 selected.text = "["+BBcode+"]" + selected.text + "[/"+BBcode+"]";
494 } else if (textarea.selectionStart || textarea.selectionStart == "0") {
495 var start = textarea.selectionStart;
496 var end = textarea.selectionEnd;
497 if (BBcode == "url"){
498 textarea.value = textarea.value.substring(0, start) + "["+BBcode+"]" + "http://" + textarea.value.substring(start, end) + "[/"+BBcode+"]" + textarea.value.substring(end, textarea.value.length);
500 textarea.value = textarea.value.substring(0, start) + "["+BBcode+"]" + textarea.value.substring(start, end) + "[/"+BBcode+"]" + textarea.value.substring(end, textarea.value.length);