From a50947a4bc3f779df8fa4e6777bc025fcefc8d21 Mon Sep 17 00:00:00 2001 From: Mike Macgirvin Date: Fri, 17 Sep 2010 03:10:19 -0700 Subject: [PATCH] like, dislike, activity streams, etc. --- boot.php | 25 ++++- images/dislike.gif | Bin 133 -> 119 bytes images/like.gif | Bin 1184 -> 119 bytes include/items.php | 88 ++++++++++++++--- include/main.js | 25 ++++- include/notifier.php | 18 ++-- include/poller.php | 5 + mod/dfrn_notify.php | 49 ++++++---- mod/dfrn_poll.php | 2 +- mod/display.php | 67 ++++++++++++- mod/like.php | 171 +++++++++++++++++++++++++++++++++ mod/network.php | 56 +++++++++-- mod/profile.php | 52 +++++++++- view/acl_selectors.php | 6 +- view/comment_item.tpl | 2 +- view/jot-header.tpl | 1 + view/jot.tpl | 25 ++--- view/like.tpl | 5 + view/profile_tabs.tpl | 1 + view/settings.tpl | 2 +- view/theme/default/style.css | 19 ++++ view/theme/goldenrod/style.css | 11 +++ view/wall_item.tpl | 4 +- view/wall_item_drop.tpl | 3 +- view/wallwall_item.tpl | 4 +- 25 files changed, 564 insertions(+), 77 deletions(-) create mode 100644 mod/like.php create mode 100644 view/like.tpl diff --git a/boot.php b/boot.php index 1a1a054187..537c7d73a1 100644 --- a/boot.php +++ b/boot.php @@ -47,7 +47,9 @@ define ( 'ACTIVITY_OBJ_PHOTO', NAMESPACE_ACTIVITY_SCHEMA . 'photo' ); define ( 'ACTIVITY_OBJ_P_PHOTO', NAMESPACE_ACTIVITY_SCHEMA . 'profile-photo' ); define ( 'ACTIVITY_OBJ_ALBUM', NAMESPACE_ACTIVITY_SCHEMA . 'photo-album' ); - +define ( 'GRAVITY_PARENT', 0); +define ( 'GRAVITY_LIKE', 3); +define ( 'GRAVITY_COMMENT', 6); if(! class_exists('App')) { @@ -850,3 +852,24 @@ function allowed_url($url) { return $found; }} +if(! function_exists('format_like')) { +function format_like($cnt,$arr,$type,$id) { + if($cnt == 1) + $o .= $arr[0] . (($type == 'like') ? t(' likes this.') : t(' doesn\'t like this.')) . EOL ; + else { + $o .= '' + . $cnt . ' ' . t('people') . ' ' . (($type == 'like') ? t('like this.') : t('don\'t like this.')) . EOL ; + $total = count($arr); + if($total >= 75) + $arr = array_slice($arr,0,74); + if($total < 75) + $arr[count($arr)-1] = t('and') . ' ' . $arr[count($arr)-1]; + $str = implode(', ', $arr); + if($total >= 75) + $str .= t(', and ') . $total - 75 . t(' other people'); + $str .= (($type == 'like') ? t(' like this.') : t(' don\'t like this.')); + $o .= ''; + } + return $o; +}} + diff --git a/images/dislike.gif b/images/dislike.gif index 2b6d01e3ae3c3469dace7415fd1b8c53baf63ba2..77779423c8867509cc1f79102b31deeb7387567d 100644 GIT binary patch delta 69 zcmV-L0J{H$0e6r%KRkH4+&v_UpduM-fDMAM!nY7y2@oMMnj9)t?B=R)OauXakfs%3 bicdu5aF8a&21%DxXn;*8GfJ&m9SHzCqc<6p delta 83 zcmV-Z0IdIag#nN_O-gvW+zf+A5de^6tYK{sm;iP}XI>)lji*JVg4?>VJgdQLo0v4j p0FY!CJOD|-N=INkl}aY&(Zb%BEA3s diff --git a/images/like.gif b/images/like.gif index 39b1c86d241fbc2fdefab9ad0efba8f20416b33c..f71d0324d25de39c7104af77d9c63f6248420e3a 100644 GIT binary patch literal 119 zcmZ?wbhEHb6krfwIK;s4|NsA)GtZ;}QQA!7w3$FI1StMwVPs%nXV75)0+3n;W}Av# zcm5fiay}Nqe8ZbzXXAsy26ur&Msspr_HhZa+ls47YguJQ{>uF6ifOi{A8Q?RM9 zs>m(KO)W`OsL0L9E4HezRZ2|BPfE1{vO&W7N(x{lCE2!0jvxsIke$x?MX3s=dIq}5 z24)5dW`=r(#wOnqF1_laHpait7C?(A*$i)q67m#PG zlu=SrV5P5LUS6(OZmgGIl&)`RX=w>E!^lV%s6w~6GOr}DLN~8i8D@e@YH@N=W?$S+WE z4mMTrO-#QEUIa|mjQ{`r z{qy_R&mZ5vef{$J)5j0*-@SeF`qj%9&!0Vg^7zri2lwyYy>t84%^TORUA=Po(!~qs z&z(JU`qar2$B!L7a`@1}1N-;w-Lrew&K=vgZQZhY)5ZeMTG_V zdAT{+S(zE>X{jm6Nr?&Zaj`McQIQehVWAmo_rKzE=rmCW>q^KY-Co3Z@B`F~;CMqH&FX#K^#)_>%=lvNGs^N(xXp!ochqvFnbM(kV@6L50_Ak3MBEERfsQ`#7w~#iLH@ z$*O{DZ7hjg&hMJd85IR~Fd84~nAm!S({Y '%s' OR `item`.`changed` > '%s' ) $sql_extra ORDER BY `parent` %s, `created` ASC LIMIT 0, 300", @@ -193,10 +211,23 @@ function construct_verb($item) { function construct_activity($item) { - if($item['type'] == 'activity') { - - + if($item['object']) { + $o = '' . "\r\n"; + $r = @simplexml_load_string($item['object']); + if($r->type) + $o .= '' . $r->type . '' . "\r\n"; + if($r->id) + $o .= '' . $r->id . '' . "\r\n"; + if($r->link) + $o .= '' . "\r\n"; + if($r->title) + $o .= '' . $r->title . '' . "\r\n"; + if($r->content) + $o .= '' . bbcode($r->content) . '' . "\r\n"; + $o .= '' . "\r\n"; + return $o; } + return ''; } @@ -300,9 +331,42 @@ function get_atom_elements($item) { $res['verb'] = unxmlify($rawverb[0]['data']); $rawobj = $item->get_item_tags(NAMESPACE_ACTIVITY, 'object'); + + if($rawobj) { - $res['object-type'] = $rawobj[0]['object-type'][0]['data']; - $res['object'] = $rawobj[0]; + $res['object'] = '' . "\n"; + if($rawobj[0]['child'][NAMESPACE_ACTIVITY]['object-type'][0]['data']) { + $res['object-type'] = $rawobj[0]['child'][NAMESPACE_ACTIVITY]['object-type'][0]['data']; + $res['object'] .= '' . $rawobj[0]['child'][NAMESPACE_ACTIVITY]['object-type'][0]['data'] . '' . "\n"; + } + if($rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['id'][0]['data']) + $res['object'] .= '' . $rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['id'][0]['data'] . '' . "\n"; + + if($rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link'][0]['attribs']['']['rel'] == 'alternate') + $res['object'] .= '' . $rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link'][0]['attribs']['']['href'] . '' . "\n"; + if($rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['title'][0]['data']) + $res['object'] .= '' . $rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['title'][0]['data'] . '' . "\n"; + if($rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['content'][0]['data']) { + $body = $rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['content'][0]['data']; + if(! $body) + $body = $rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['summary'][0]['data']; + if(strpos($body,'<')) { + + $body = preg_replace('#]+>.+?' . 'http://www.youtube.com/((?:v|cp)/[A-Za-z0-9\-_=]+).+?#s', + '[youtube]$1[/youtube]', $body); + + $config = HTMLPurifier_Config::createDefault(); + $config->set('Core.DefinitionCache', null); + + $purifier = new HTMLPurifier($config); + $body = $purifier->purify($body); + } + + $body = html2bbcode($body); + $res['object'] .= '' . $body . '' . "\n"; + } + + $res['object'] .= '' . "\n"; } return $res; diff --git a/include/main.js b/include/main.js index ca6d56d8b8..cc44db5d42 100644 --- a/include/main.js +++ b/include/main.js @@ -36,6 +36,7 @@ var livetime = null; var msie = false; var stopped = false; + var timer = null; $(document).ready(function() { $.ajaxSetup({cache: false}); @@ -77,12 +78,12 @@ }); }) ; } - setTimeout(NavUpdate,30000); + timer = setTimeout(NavUpdate,30000); } function liveUpdate() { - if((src == null) || (stopped)) { return; } + if((src == null) || (stopped)) { $('.like-rotator').hide(); return; } if($('.comment-edit-text-full').length) { livetime = setTimeout(liveUpdate, 10000); return; @@ -102,6 +103,8 @@ $('#' + ident + ' ' + '.wall-item-ago').replaceWith($(this).find('.wall-item-ago')); $('#' + ident + ' ' + '.wall-item-comment-wrapper').replaceWith($(this).find('.wall-item-comment-wrapper')); + $('#' + ident + ' ' + '.wall-item-like').replaceWith($(this).find('.wall-item-like')); + $('#' + ident + ' ' + '.wall-item-dislike').replaceWith($(this).find('.wall-item-dislike')); $('#' + ident + ' ' + '.my-comment-photo').each(function() { $(this).attr('src',$(this).attr('dst')); }); @@ -110,6 +113,7 @@ } prev = ident; }); + $('.like-rotator').hide(); }); } @@ -129,3 +133,20 @@ $(node).css('width',16); $(node).css('height',16); } + + // Since ajax is asynchronous, we will give a few seconds for + // the first ajax call (setting like/dislike), then run the + // updater to pick up any changes and display on the page. + // The updater will turn any rotators off when it's done. + // This function will have returned long before any of these + // events have completed and therefore there won't be any + // visible feedback that anything changed without all this + // trickery. This still could cause confusion if the "like" ajax call + // is delayed and NavUpdate runs before it completes. + + function dolike(ident,verb) { + $('#like-rotator-' + ident.toString()).show(); + $.get('like/' + ident.toString() + '?verb=' + verb ); + if(timer) clearTimeout(timer); + timer = setTimeout(NavUpdate,3000); + } diff --git a/include/notifier.php b/include/notifier.php index cc2846735f..5766747b8b 100644 --- a/include/notifier.php +++ b/include/notifier.php @@ -13,6 +13,7 @@ require_once("session.php"); require_once("datetime.php"); + require_once('include/items.php'); if($argc < 3) exit; @@ -114,6 +115,8 @@ $recipients = array_diff($recipients,$deny); $conversant_str = dbesc(implode(', ',$conversants)); + + } $r = q("SELECT * FROM `contact` WHERE `id` IN ( $conversant_str ) AND `blocked` = 0 AND `pending` = 0"); @@ -161,14 +164,13 @@ } else { - require_once('include/items.php'); - - $verb = construct_verb($item); - $actobj = construct_activity($item); - if($followup) { foreach($items as $item) { + + $verb = construct_verb($item); + $actobj = construct_activity($item); + if($item['id'] == $item_id) { $atom .= replace_macros($cmnt_template, array( '$name' => xmlify($owner['name']), @@ -203,6 +205,10 @@ else { foreach($contacts as $contact) { if($item['contact-id'] == $contact['id']) { + + $verb = construct_verb($item); + $actobj = construct_activity($item); + if($item['parent'] == $item['id']) { $atom .= replace_macros($item_template, array( '$name' => xmlify($contact['name']), @@ -220,7 +226,7 @@ '$verb' => xmlify($verb), '$actobj' => $actobj, '$content' => xmlify($item['body']), - '$comment_allow' => (($item['last-child'] && ($contact['rel']) && ($contact['rel'] != REL_FAN)) ? 1 : 0) + '$comment_allow' => (($item['last-child']) ? 1 : 0) )); } else { diff --git a/include/poller.php b/include/poller.php index 6024b18442..f116a56220 100644 --- a/include/poller.php +++ b/include/poller.php @@ -348,6 +348,11 @@ $datarray['parent-uri'] = $parent_uri; $datarray['uid'] = $importer['uid']; $datarray['contact-id'] = $contact['id']; + if(($datarray['verb'] == ACTIVITY_LIKE) || ($datarray['verb'] == ACTIVITY_DISLIKE)) { + $datarray['type'] = 'activity'; + $datarray['gravity'] = GRAVITY_LIKE; + } + $r = item_store($datarray); continue; } diff --git a/mod/dfrn_notify.php b/mod/dfrn_notify.php index 80cd1a2fdc..61ea77c29a 100644 --- a/mod/dfrn_notify.php +++ b/mod/dfrn_notify.php @@ -208,6 +208,10 @@ function dfrn_notify_post(&$a) { $datarray['parent-uri'] = $parent_uri; $datarray['uid'] = $importer['importer_uid']; $datarray['contact-id'] = $importer['id']; + if(($datarray['verb'] == ACTIVITY_LIKE) || ($datarray['verb'] == ACTIVITY_DISLIKE)) { + $datarray['type'] = 'activity'; + $datarray['gravity'] = GRAVITY_LIKE; + } $posted_id = item_store($datarray); if($posted_id) { @@ -228,26 +232,28 @@ function dfrn_notify_post(&$a) { intval($posted_id) ); - $php_path = ((strlen($a->config['php_path'])) ? $a->config['php_path'] : 'php'); + if($datarray['type'] == 'remote-comment') { + $php_path = ((strlen($a->config['php_path'])) ? $a->config['php_path'] : 'php'); - proc_close(proc_open("\"$php_path\" \"include/notifier.php\" \"comment-import\" \"$posted_id\" &", - array(),$foo)); + proc_close(proc_open("\"$php_path\" \"include/notifier.php\" \"comment-import\" \"$posted_id\" &", + array(),$foo)); - if(($importer['notify-flags'] & NOTIFY_COMMENT) && (! $importer['self'])) { - require_once('bbcode.php'); - $from = stripslashes($datarray['author-name']); - $tpl = file_get_contents('view/cmnt_received_eml.tpl'); - $email_tpl = replace_macros($tpl, array( - '$sitename' => $a->config['sitename'], - '$siteurl' => $a->get_baseurl(), - '$username' => $importer['username'], - '$email' => $importer['email'], - '$from' => $from, - '$body' => strip_tags(bbcode(stripslashes($datarray['body']))) - )); - - $res = mail($importer['email'], $from . t(" commented on your item at ") . $a->config['sitename'], - $email_tpl,t("From: Administrator@") . $a->get_hostname() ); + if(($importer['notify-flags'] & NOTIFY_COMMENT) && (! $importer['self'])) { + require_once('bbcode.php'); + $from = stripslashes($datarray['author-name']); + $tpl = file_get_contents('view/cmnt_received_eml.tpl'); + $email_tpl = replace_macros($tpl, array( + '$sitename' => $a->config['sitename'], + '$siteurl' => $a->get_baseurl(), + '$username' => $importer['username'], + '$email' => $importer['email'], + '$from' => $from, + '$body' => strip_tags(bbcode(stripslashes($datarray['body']))) + )); + + $res = mail($importer['email'], $from . t(" commented on your item at ") . $a->config['sitename'], + $email_tpl,t("From: Administrator@") . $a->get_hostname() ); + } } } xml_status(0); @@ -280,11 +286,16 @@ function dfrn_notify_post(&$a) { $datarray['parent-uri'] = $parent_uri; $datarray['uid'] = $importer['importer_uid']; $datarray['contact-id'] = $importer['id']; + if(($datarray['verb'] == ACTIVITY_LIKE) || ($datarray['verb'] == ACTIVITY_DISLIKE)) { + $datarray['type'] = 'activity'; + $datarray['gravity'] = GRAVITY_LIKE; + } + $r = item_store($datarray); // find out if our user is involved in this conversation and wants to be notified. - if($importer['notify-flags'] & NOTIFY_COMMENT) { + if(($datarray['type'] != 'activity') && ($importer['notify-flags'] & NOTIFY_COMMENT)) { $myconv = q("SELECT `author-link` FROM `item` WHERE `parent-uri` = '%s' AND `uid` = %d", dbesc($parent_uri), diff --git a/mod/dfrn_poll.php b/mod/dfrn_poll.php index 4b8a7f112c..66e1968442 100644 --- a/mod/dfrn_poll.php +++ b/mod/dfrn_poll.php @@ -201,7 +201,7 @@ function dfrn_poll_post(&$a) { } else { - $o = get_feed_for($a,$dfrn_id, $a->argv[1], $last_update); + $o = get_feed_for($a,$dfrn_id, $a->argv[1], $last_update, $direction); echo $o; killme(); diff --git a/mod/display.php b/mod/display.php index 639a30eb7d..6149c3d5b5 100644 --- a/mod/display.php +++ b/mod/display.php @@ -93,7 +93,7 @@ function display_content(&$a) { AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 AND `item`.`parent` = ( SELECT `parent` FROM `item` WHERE ( `id` = '%s' OR `uri` = '%s' )) $sql_extra - ORDER BY `parent` DESC, `id` ASC ", + ORDER BY `parent` DESC, `gravity` ASC, `id` ASC ", intval($a->profile['uid']), dbesc($item_id), dbesc($item_id) @@ -101,19 +101,49 @@ function display_content(&$a) { $cmnt_tpl = file_get_contents('view/comment_item.tpl'); - + $like_tpl = file_get_contents('view/like.tpl'); $tpl = file_get_contents('view/wall_item.tpl'); $wallwall = file_get_contents('view/wallwall_item.tpl'); $return_url = $_SESSION['return_url'] = $a->cmd; + $alike = array(); + $dlike = array(); + if(count($r)) { + + foreach($r as $item) { + + if(($item['verb'] == ACTIVITY_LIKE) && ($item['id'] != $item['parent'])) { + $url = $item['url']; + if(($item['rel'] == REL_VIP || $item['rel'] == REL_BUD) && (! $item['self'])) + $url = $a->get_baseurl() . '/redir/' . $item['contact-id']; + if(! is_array($alike[$item['parent'] . '-l'])) + $alike[$item['parent'] . '-l'] = array(); + $alike[$item['parent']] ++; + $alike[$item['parent'] . '-l'][] = '' . $item['name'] . ''; + } + if(($item['verb'] == ACTIVITY_DISLIKE) && ($item['id'] != $item['parent'])) { + $url = $item['url']; + if(($item['rel'] == REL_VIP || $item['rel'] == REL_BUD) && (! $item['self'])) + $url = $a->get_baseurl() . '/redir/' . $item['contact-id']; + if(! is_array($dlike[$item['parent'] . '-l'])) + $dlike[$item['parent'] . '-l'] = array(); + $dlike[$item['parent']] ++; + $dlike[$item['parent'] . '-l'][] = '' . $item['name'] . ''; + } + } + + + foreach($r as $item) { $comment = ''; $template = $tpl; $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ; + if((($item['verb'] == ACTIVITY_LIKE) || ($item['verb'] == ACTIVITY_DISLIKE)) && ($item['id'] != $item['parent'])) + continue; if(can_write_wall($a,$a->profile['uid'])) { if($item['last-child']) { @@ -175,6 +205,15 @@ function display_content(&$a) { if(($item['contact-id'] == $_SESSION['visitor_id']) || ($item['uid'] == get_uid())) $drop = replace_macros(file_get_contents('view/wall_item_drop.tpl'), array('$id' => $item['id'])); + $like = (($alike[$item['id']]) ? format_like($alike[$item['id']],$alike[$item['id'] . '-l'],'like',$item['id']) : ''); + $dislike = (($dlike[$item['id']]) ? format_like($dlike[$item['id']],$dlike[$item['id'] . '-l'],'dislike',$item['id']) : ''); + + $likebuttons = ''; + if($item['id'] == $item['parent']) { + $likebuttons = replace_macros($like_tpl,array('$id' => $item['id'])); + } + + $o .= replace_macros($template,array( '$id' => $item['item_id'], @@ -190,10 +229,32 @@ function display_content(&$a) { '$owner_photo' => $owner_photo, '$owner_name' => $owner_name, '$drop' => $drop, + '$vote' => $likebuttons, + '$like' => $like, + '$dislike' => $dislike, '$comment' => $comment )); } } + else { + $r = q("SELECT `id` FROM `item` WHERE `id` = '%s' OR `uri` = '%s' LIMIT 1", + dbesc($item_id), + dbesc($item_id) + ); + if(count($r)) { + if($r[0]['deleted']) { + notice( t('Item has been removed.') . EOL ); + } + else { + notice( t('Permission denied.') . EOL ); + } + } + else { + notice( t('Item not found.') . EOL ); + } + + } return $o; -} \ No newline at end of file +} + diff --git a/mod/like.php b/mod/like.php new file mode 100644 index 0000000000..d52b3a3243 --- /dev/null +++ b/mod/like.php @@ -0,0 +1,171 @@ +argc > 1) ? notags(trim($a->argv[1])) : 0); + + $r = q("SELECT * FROM `item` WHERE ( `id` = '%s' OR `uri` = '%s') AND `id` = `parent` LIMIT 1", + dbesc($item_id), + dbesc($item_id) + ); + + if(! $item_id || (! count($r))) { + return; + } + + $item = $r[0]; + + $owner_uid = $item['uid']; + + if(! can_write_wall($a,$owner_uid)) { + return; + } + + $r = q("SELECT `contact`.*, `user`.`nickname` FROM `contact` LEFT JOIN `user` ON `contact`.`uid` = `user`.`uid` + WHERE `contact`.`self` = 1 AND `contact`.`uid` = %d LIMIT 1", + intval($owner_uid) + ); + if(count($r)) + $owner = $r[0]; + + if(! $owner) { + return; + } + + + if((local_user()) && (get_uid() == $owner_uid)) { + $contact = $owner; + } + else { + $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1", + intval($_SESSION['visitor_id']), + intval($owner_uid) + ); + if(count($r)) + $contact = $r[0]; + } + if(! $contact) { + return; + } + + $r = q("SELECT `id` FROM `item` WHERE `verb` = '%s' AND `deleted` = 0 + AND `contact-id` = %d AND ( `parent` = '%s' OR `parent-uri` = '%s') LIMIT 1", + dbesc($activity), + intval($contact['id']), + dbesc($item_id), + dbesc($item_id) + ); + if(count($r)) { + // Already voted, undo it + $r = q("UPDATE `item` SET `deleted` = 1, `changed` = '%s' WHERE `id` = %d LIMIT 1", + dbesc(datetime_convert()), + intval($r[0]['id']) + ); + + $php_path = ((strlen($a->config['php_path'])) ? $a->config['php_path'] : 'php'); + + proc_close(proc_open("\"$php_path\" \"include/notifier.php\" \"like\" \"$post_id\" > notify.out &", + array(),$foo)); + return; + } + + $uri = item_new_uri($a->get_hostname(),$owner_uid); + + $post_type = (($item['resource-id']) ? t('photo') : t('status')); + $objtype = (($item['resource-id']) ? ACTIVITY_OBJ_PHOTO : ACTIVITY_OBJ_NOTE ); + $link = $a->get_baseurl() . '/display/' . $owner['nickname'] . '/' . $item['id']; + $body = $item['body']; + + $obj = <<< EOT + + + $objtype + 1 + {$item['uri']} + $link + + $body + +EOT; + if($verb == 'like') + $bodyverb = t('likes'); + if($verb == 'dislike') + $bodyverb = t('doesn\'t like'); + + if(! isset($bodyverb)) + return; + + $arr = array(); + + $arr['uri'] = $uri; + $arr['uid'] = $owner_uid; + $arr['contact-id'] = $contact['id']; + $arr['type'] = 'activity'; + $arr['wall'] = 1; + $arr['gravity'] = GRAVITY_LIKE; + $arr['parent'] = $item['id']; + $arr['parent-uri'] = $item['uri']; + $arr['owner-name'] = $owner['name']; + $arr['owner-link'] = $owner['url']; + $arr['owner-avatar'] = $owner['thumb']; + $arr['author-name'] = $contact['name']; + $arr['author-link'] = $contact['url']; + $arr['author-avatar'] = $contact['thumb']; + $arr['body'] = '[url=' . $contact['url'] . ']' . $contact['name'] . '[/url]' . ' ' . t('likes') . ' ' + . '[url=' . $owner['url'] . ']' . $owner['name'] . t('\'s') . '[/url]' . ' ' + . '[url=' . $a->get_baseurl() . '/display/' . $owner['nickname'] . '/' . $item['id'] . ']' . $post_type . '[/url]' ; + + $arr['verb'] = $activity; + $arr['object-type'] = $objtype; + $arr['object'] = $obj; + $arr['allow_cid'] = $item['allow_cid']; + $arr['allow_gid'] = $item['allow_gid']; + $arr['deny_cid'] = $item['deny_cid']; + $arr['deny_gid'] = $item['deny_gid']; + $arr['visible'] = 1; + $arr['unseen'] = 1; + $arr['last-child'] = 0; + + $post_id = item_store($arr); + + + $php_path = ((strlen($a->config['php_path'])) ? $a->config['php_path'] : 'php'); + + proc_close(proc_open("\"$php_path\" \"include/notifier.php\" \"like\" \"$post_id\" > notify.out &", + array(),$foo)); + + return; // NOTREACHED +} \ No newline at end of file diff --git a/mod/network.php b/mod/network.php index cdd8a4976b..7eb93f4359 100644 --- a/mod/network.php +++ b/mod/network.php @@ -66,7 +66,7 @@ function network_content(&$a, $update = false) { // that belongs to you, hence you can see all of it. We will filter by group if // desired. - $sql_extra = " AND `item`.`parent` IN ( SELECT `parent` FROM `item` WHERE `id` = `parent` AND `type` IN ('wall', 'photo', 'remote' )) "; + $sql_extra = " AND `item`.`parent` IN ( SELECT `parent` FROM `item` WHERE `id` = `parent` ) "; if($group) { $r = q("SELECT `name`, `id` FROM `group` WHERE `id` = %d AND `uid` = %d LIMIT 1", @@ -81,7 +81,7 @@ function network_content(&$a, $update = false) { $contacts = expand_groups(array($group)); $contact_str = implode(',',$contacts); - $sql_extra = " AND `item`.`parent` IN ( SELECT `parent` FROM `item` WHERE `id` = `parent` AND `type` IN ('wall', 'photo', 'remote') AND `contact-id` IN ( $contact_str )) "; + $sql_extra = " AND `item`.`parent` IN ( SELECT `parent` FROM `item` WHERE `id` = `parent` AND `contact-id` IN ( $contact_str )) "; $o = '

' . t('Group: ') . $r[0]['name'] . '

' . $o; } @@ -98,14 +98,14 @@ function network_content(&$a, $update = false) { $a->set_pager_total($r[0]['total']); $r = q("SELECT `item`.*, `item`.`id` AS `item_id`, - `contact`.`name`, `contact`.`photo`, `contact`.`url`, + `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`, `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid` FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id` WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 $sql_extra - ORDER BY `parent` DESC, `created` ASC LIMIT %d ,%d ", + ORDER BY `parent` DESC, `gravity` ASC, `created` ASC LIMIT %d ,%d ", intval($_SESSION['uid']), intval($a->pager['start']), intval($a->pager['itemspage']) @@ -113,11 +113,36 @@ function network_content(&$a, $update = false) { $cmnt_tpl = file_get_contents('view/comment_item.tpl'); - + $like_tpl = file_get_contents('view/like.tpl'); $tpl = file_get_contents('view/wall_item.tpl'); $wallwall = file_get_contents('view/wallwall_item.tpl'); + $alike = array(); + $dlike = array(); + if(count($r)) { + foreach($r as $item) { + + if(($item['verb'] == ACTIVITY_LIKE) && ($item['id'] != $item['parent'])) { + $url = $item['url']; + if(($item['rel'] == REL_VIP || $item['rel'] == REL_BUD) && (! $item['self'])) + $url = $a->get_baseurl() . '/redir/' . $item['contact-id']; + if(! is_array($alike[$item['parent'] . '-l'])) + $alike[$item['parent'] . '-l'] = array(); + $alike[$item['parent']] ++; + $alike[$item['parent'] . '-l'][] = '' . $item['name'] . ''; + } + if(($item['verb'] == ACTIVITY_DISLIKE) && ($item['id'] != $item['parent'])) { + $url = $item['url']; + if(($item['rel'] == REL_VIP || $item['rel'] == REL_BUD) && (! $item['self'])) + $url = $a->get_baseurl() . '/redir/' . $item['contact-id']; + if(! is_array($dlike[$item['parent'] . '-l'])) + $dlike[$item['parent'] . '-l'] = array(); + $dlike[$item['parent']] ++; + $dlike[$item['parent'] . '-l'][] = '' . $item['name'] . ''; + } + } + foreach($r as $item) { $comment = ''; @@ -127,12 +152,14 @@ function network_content(&$a, $update = false) { $profile_url = $item['url']; $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ; + if((($item['verb'] == ACTIVITY_LIKE) || ($item['verb'] == ACTIVITY_DISLIKE)) && ($item['id'] != $item['parent'])) + continue; // Top-level wall post not written by the wall owner (wall-to-wall) // First figure out who owns it. if(($item['parent'] == $item['item_id']) && (! $item['self'])) { - + if($item['type'] == 'wall') { // I do. Put me on the left of the wall-to-wall notice. $owner_url = $a->contact['url']; @@ -149,8 +176,7 @@ function network_content(&$a, $update = false) { $template = $wallwall; $commentww = 'ww'; // If it is our contact, use a friendly redirect link - if(($item['owner-link'] == $item['url']) && ($item['rel'] == DIRECTION_IN || $item['rel'] == DIRECTION_BOTH)) - $owner_url = $redirect_url; + if(($item['owner-link'] == $item['url']) && ($item['rel'] == REL_VIP || $item['rel'] == REL_BUD)) $owner_url = $redirect_url; } @@ -161,6 +187,10 @@ function network_content(&$a, $update = false) { else $return_url = $_SESSION['return_url'] = $a->cmd; + $likebuttons = ''; + if($item['id'] == $item['parent']) { + $likebuttons = replace_macros($like_tpl,array('$id' => $item['id'])); + } if($item['last-child']) { $comment = replace_macros($cmnt_tpl,array( @@ -181,7 +211,7 @@ function network_content(&$a, $update = false) { - if(($item['contact-uid'] == $_SESSION['uid']) && ($item['rel'] == DIRECTION_IN || $item['rel'] == DIRECTION_BOTH) && (! $item['self'] )) + if(($item['rel'] == REL_VIP || $item['rel'] == REL_BUD) && (! $item['self'] )) $profile_url = $redirect_url; $photo = $item['photo']; @@ -203,6 +233,11 @@ function network_content(&$a, $update = false) { $profile_link = $item['author-link']; } + + $like = (($alike[$item['id']]) ? format_like($alike[$item['id']],$alike[$item['id'] . '-l'],'like',$item['id']) : ''); + $dislike = (($dlike[$item['id']]) ? format_like($dlike[$item['id']],$dlike[$item['id'] . '-l'],'dislike',$item['id']) : ''); + + // Build the HTML $o .= replace_macros($template,array( @@ -219,6 +254,9 @@ function network_content(&$a, $update = false) { '$owner_photo' => $owner_photo, '$owner_name' => $owner_name, '$drop' => $drop, + '$vote' => $likebuttons, + '$like' => $like, + '$dislike' => $dislike, '$comment' => $comment )); } diff --git a/mod/profile.php b/mod/profile.php index 1520afff74..18201e821a 100644 --- a/mod/profile.php +++ b/mod/profile.php @@ -203,7 +203,7 @@ function profile_content(&$a, $update = false) { FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id` WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 - AND `item`.`parent` IN ( SELECT `parent` FROM `item` WHERE `id` = `parent` AND `type` != 'remote') + AND `item`.`parent` IN ( SELECT `parent` FROM `item` WHERE `id` = `parent` AND `wall` = 1 ) $sql_extra ", intval($a->profile['profile_uid']) @@ -219,9 +219,9 @@ function profile_content(&$a, $update = false) { FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id` WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 - AND `item`.`parent` IN ( SELECT `parent` FROM `item` WHERE `id` = `parent` AND `type` != 'remote') + AND `item`.`parent` IN ( SELECT `parent` FROM `item` WHERE `id` = `parent` AND `wall` = 1 ) $sql_extra - ORDER BY `parent` DESC, `id` ASC LIMIT %d ,%d ", + ORDER BY `parent` DESC, `gravity` ASC, `id` ASC LIMIT %d ,%d ", intval($a->profile['profile_uid']), intval($a->pager['start']), intval($a->pager['itemspage']) @@ -231,6 +231,8 @@ function profile_content(&$a, $update = false) { $cmnt_tpl = file_get_contents('view/comment_item.tpl'); + $like_tpl = file_get_contents('view/like.tpl'); + $tpl = file_get_contents('view/wall_item.tpl'); if($update) @@ -238,15 +240,50 @@ function profile_content(&$a, $update = false) { else $return_url = $_SESSION['return_url'] = $a->cmd; + $alike = array(); + $dlike = array(); + if(count($r)) { + foreach($r as $item) { + + if(($item['verb'] == ACTIVITY_LIKE) && ($item['id'] != $item['parent'])) { + $url = $item['url']; + if(($item['rel'] == REL_VIP || $item['rel'] == REL_BUD) && (! $item['self'])) + $url = $a->get_baseurl() . '/redir/' . $item['contact-id']; + if(! is_array($alike[$item['parent'] . '-l'])) + $alike[$item['parent'] . '-l'] = array(); + $alike[$item['parent']] ++; + $alike[$item['parent'] . '-l'][] = '' . $item['name'] . ''; + } + if(($item['verb'] == ACTIVITY_DISLIKE) && ($item['id'] != $item['parent'])) { + $url = $item['url']; + if(($item['rel'] == REL_VIP || $item['rel'] == REL_BUD) && (! $item['self'])) + $url = $a->get_baseurl() . '/redir/' . $item['contact-id']; + if(! is_array($dlike[$item['parent'] . '-l'])) + $dlike[$item['parent'] . '-l'] = array(); + $dlike[$item['parent']] ++; + $dlike[$item['parent'] . '-l'][] = '' . $item['name'] . ''; + } + } + + foreach($r as $item) { + + $comment = ''; + $likebuttons = ''; + $template = $tpl; $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ; - + + if((($item['verb'] == ACTIVITY_LIKE) || ($item['verb'] == ACTIVITY_DISLIKE)) && ($item['id'] != $item['parent'])) + continue; if(can_write_wall($a,$a->profile['profile_uid'])) { + if($item['id'] == $item['parent']) { + $likebuttons = replace_macros($like_tpl,array('$id' => $item['id'])); + } if($item['last-child']) { $comment = replace_macros($cmnt_tpl,array( '$return_path' => $_SESSION['return_url'], @@ -287,6 +324,10 @@ function profile_content(&$a, $update = false) { $drop = replace_macros(file_get_contents('view/wall_item_drop.tpl'), array('$id' => $item['id'])); + $like = (($alike[$item['id']]) ? format_like($alike[$item['id']],$alike[$item['id'] . '-l'],'like',$item['id']) : ''); + $dislike = (($dlike[$item['id']]) ? format_like($dlike[$item['id']],$dlike[$item['id'] . '-l'],'dislike',$item['id']) : ''); + + $o .= replace_macros($template,array( '$id' => $item['item_id'], '$profile_url' => $profile_link, @@ -298,6 +339,9 @@ function profile_content(&$a, $update = false) { '$location' => (($item['location']) ? '' . $item['location'] . '' : ''), '$indent' => (($item['parent'] != $item['item_id']) ? ' comment' : ''), '$drop' => $drop, + '$like' => $like, + '$vote' => $likebuttons, + '$dislike' => $dislike, '$comment' => $comment )); diff --git a/view/acl_selectors.php b/view/acl_selectors.php index 42cd7a9813..0366ab2a17 100644 --- a/view/acl_selectors.php +++ b/view/acl_selectors.php @@ -5,7 +5,7 @@ function group_select($selname,$selclass,$preselected = false,$size = 4) { $o = ''; - $o .= "\r\n"; $r = q("SELECT * FROM `group` WHERE `deleted` = 0 AND `uid` = %d ORDER BY `name` ASC", $_SESSION['uid'] @@ -39,11 +39,11 @@ function contact_select($selname, $selclass, $preselected = false, $size = 4, $p if($privmail) { $sql_extra = sprintf(" AND `rel` = %d ", intval(DIRECTION_BOTH)); - $o .= "\r\n"; } else { $sql_extra = ''; - $o .= "\r\n"; } $r = q("SELECT `id`, `name`, `url` FROM `contact` diff --git a/view/comment_item.tpl b/view/comment_item.tpl index 336ad3b33f..62b3ce18a7 100644 --- a/view/comment_item.tpl +++ b/view/comment_item.tpl @@ -18,6 +18,6 @@ -
+
diff --git a/view/jot-header.tpl b/view/jot-header.tpl index 8c7cce360d..bb95cd265f 100644 --- a/view/jot-header.tpl +++ b/view/jot-header.tpl @@ -107,5 +107,6 @@ tinyMCE.init({ } } + diff --git a/view/jot.tpl b/view/jot.tpl index 586274c35c..ec11f28611 100644 --- a/view/jot.tpl +++ b/view/jot.tpl @@ -1,19 +1,19 @@
-
-
What's on your mind?
-
-
-
-
- - - - +
+
What's on your mind?
+
+
+
- + + + + + + + -
@@ -35,6 +35,7 @@
+
diff --git a/view/like.tpl b/view/like.tpl new file mode 100644 index 0000000000..73cbb2d4ae --- /dev/null +++ b/view/like.tpl @@ -0,0 +1,5 @@ + diff --git a/view/profile_tabs.tpl b/view/profile_tabs.tpl index 0877edd737..9c6c54a1c5 100644 --- a/view/profile_tabs.tpl +++ b/view/profile_tabs.tpl @@ -4,3 +4,4 @@ Profile Photos
+ \ No newline at end of file diff --git a/view/settings.tpl b/view/settings.tpl index aa0bf17e03..84fc389268 100644 --- a/view/settings.tpl +++ b/view/settings.tpl @@ -45,7 +45,7 @@ $profile_in_dir $profile_in_net_dir
-
$permissions
+
$permissions
$title
@@ -17,7 +18,8 @@ $drop
- + +
$dislike
$comment
diff --git a/view/wall_item_drop.tpl b/view/wall_item_drop.tpl index 9ca1ec9680..84a2f3a8ef 100644 --- a/view/wall_item_drop.tpl +++ b/view/wall_item_drop.tpl @@ -1 +1,2 @@ -
Delete
+
Delete
+
diff --git a/view/wallwall_item.tpl b/view/wallwall_item.tpl index 30970f6aea..f3a803543c 100644 --- a/view/wallwall_item.tpl +++ b/view/wallwall_item.tpl @@ -12,7 +12,7 @@ $name to $owner_name via Wall-To-Wall:
$ago
$location
- + $vote
$title
@@ -21,6 +21,8 @@ $drop
+ +
$dislike
$comment