From 7c60701efc091945dd2ee14728263d8dae0f88b0 Mon Sep 17 00:00:00 2001 From: Friendika Date: Fri, 10 Jun 2011 01:51:14 -0700 Subject: [PATCH] fixed a few feed problems affecting activity objects/targets --- addon/facebook/facebook.php | 2 +- boot.php | 19 +++++++++++++------ include/items.php | 25 +++++++++++++++++++++---- mod/events.php | 4 ++-- 4 files changed, 37 insertions(+), 13 deletions(-) diff --git a/addon/facebook/facebook.php b/addon/facebook/facebook.php index 9e41065dea..545779cd5f 100644 --- a/addon/facebook/facebook.php +++ b/addon/facebook/facebook.php @@ -908,7 +908,7 @@ function fb_consume_stream($uid,$j,$wall = false) { $likedata['body'] = sprintf( t('%1$s likes %2$s\'s %3$s'), $author, $objauthor, $plink); $likedata['object'] = '' . ACTIVITY_OBJ_NOTE . '1' . - '' . $orig_post['uri'] . '' . xmlify('') . '' . $orig_post['title'] . '' . $orig_post['body'] . ''; + '' . $orig_post['uri'] . '' . xmlify('') . '' . $orig_post['title'] . '' . $orig_post['body'] . ''; $item = item_store($likedata); } diff --git a/boot.php b/boot.php index 8e8a2bc210..b94000b607 100644 --- a/boot.php +++ b/boot.php @@ -2788,16 +2788,23 @@ function lang_selector() { if(! function_exists('parse_xml_string')) { -function parse_xml_string($s) { - if(! strstr($s,'code." at ".$err->line.":".$err->column." : ".$err->message, LOGGER_DATA); - libxml_clear_errors(); + libxml_clear_errors(); + } return $x; }} diff --git a/include/items.php b/include/items.php index dfe92378ae..a5d430aa22 100644 --- a/include/items.php +++ b/include/items.php @@ -180,7 +180,11 @@ function construct_activity_object($item) { if($item['object']) { $o = '' . "\r\n"; - $r = parse_xml_string($item['object']); + $r = parse_xml_string($item['object'],false); + + + if(! $r) + return ''; if($r->type) $o .= '' . xmlify($r->type) . '' . "\r\n"; if($r->id) @@ -188,8 +192,15 @@ function construct_activity_object($item) { if($r->title) $o .= '' . xmlify($r->title) . '' . "\r\n"; if($r->link) { - if(substr($r->link,0,1) === '<') + if(substr($r->link,0,1) === '<') { + // patch up some facebook "like" activity objects that got stored incorrectly + // for a couple of months prior to 9-Jun-2011 and generated bad XML. + // we can probably remove this hack here and in the following function in a few months time. + if(strstr($r->link,'&') && (! strstr($r->link,'&'))) + $r->link = str_replace('&','&', $r->link); + $r->link = preg_replace('/\/','',$r->link); $o .= $r->link; + } else $o .= '' . "\r\n"; } @@ -206,7 +217,9 @@ function construct_activity_target($item) { if($item['target']) { $o = '' . "\r\n"; - $r = parse_xml_string($item['target']); + $r = parse_xml_string($item['target'],false); + if(! $r) + return ''; if($r->type) $o .= '' . xmlify($r->type) . '' . "\r\n"; if($r->id) @@ -214,8 +227,12 @@ function construct_activity_target($item) { if($r->title) $o .= '' . xmlify($r->title) . '' . "\r\n"; if($r->link) { - if(substr($r->link,0,1) === '<') + if(substr($r->link,0,1) === '<') { + if(strstr($r->link,'&') && (! strstr($r->link,'&'))) + $r->link = str_replace('&','&', $r->link); + $r->link = preg_replace('/\/','',$r->link); $o .= $r->link; + } else $o .= '' . "\r\n"; } diff --git a/mod/events.php b/mod/events.php index 052c0ef603..bdc4b8d871 100644 --- a/mod/events.php +++ b/mod/events.php @@ -159,8 +159,8 @@ function events_post(&$a) { $arr['body'] = format_event_bbcode($event); - $arr['object'] = '' . ACTIVITY_OBJ_EVENT . '' . $uri . ''; - $arr['object'] .= '' . format_event_bbcode($event) . ''; + $arr['object'] = '' . xmlify(ACTIVITY_OBJ_EVENT) . '' . xmlify($uri) . ''; + $arr['object'] .= '' . xmlify(format_event_bbcode($event)) . ''; $arr['object'] .= '' . "\n"; $item_id = item_store($arr);