From a50947a4bc3f779df8fa4e6777bc025fcefc8d21 Mon Sep 17 00:00:00 2001 From: Mike Macgirvin Date: Fri, 17 Sep 2010 03:10:19 -0700 Subject: like, dislike, activity streams, etc. --- include/items.php | 88 +++++++++++++++++++++++++++++++++++++++++++++------- include/main.js | 25 +++++++++++++-- include/notifier.php | 18 +++++++---- include/poller.php | 5 +++ 4 files changed, 116 insertions(+), 20 deletions(-) (limited to 'include') diff --git a/include/items.php b/include/items.php index f85a0e64b..8ca0eeb16 100644 --- a/include/items.php +++ b/include/items.php @@ -1,9 +1,9 @@ '%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 ca6d56d8b..cc44db5d4 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 cc2846735..5766747b8 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 6024b1844..f116a5622 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; } -- cgit v1.2.3