X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Fitems.php;h=dc177c468c9b21bc8e07ad3a08ea2363f2a70f64;hb=ae3c9b7b2b6f6b8bf7a5d5e72bd66f1bff3b081d;hp=6f15b6814b9a73377dbd33aec49160c888440482;hpb=0c51305c72acd244dc92bb18c393fdf8fba4889b;p=friendica.git diff --git a/include/items.php b/include/items.php index 6f15b6814b..dc177c468c 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"; } @@ -354,6 +371,9 @@ function get_atom_elements($feed,$item) { $res['body'] = preg_replace('#]+>.+?' . 'http://www.youtube.com/((?:v|cp)/[A-Za-z0-9\-_=]+).+?#s', '[youtube]$1[/youtube]', $res['body']); + $res['body'] = preg_replace('#].+?' . 'http://www.youtube.com/embed/([A-Za-z0-9\-_=]+).+?#s', + '[youtube]$1[/youtube]', $res['body']); + $res['body'] = oembed_html2bbcode($res['body']); $config = HTMLPurifier_Config::createDefault(); @@ -381,6 +401,9 @@ function get_atom_elements($feed,$item) { else $res['private'] = 0; + $extid = $item->get_item_tags(NAMESPACE_DFRN,'extid'); + if($extid && $extid[0]['data']) + $res['extid'] = $extid[0]['data']; $rawlocation = $item->get_item_tags(NAMESPACE_DFRN, 'location'); if($rawlocation) @@ -521,6 +544,10 @@ function get_atom_elements($feed,$item) { $body = preg_replace('#]+>.+?' . 'http://www.youtube.com/((?:v|cp)/[A-Za-z0-9\-_=]+).+?#s', '[youtube]$1[/youtube]', $body); + $res['body'] = preg_replace('#].+?' . 'http://www.youtube.com/embed/([A-Za-z0-9\-_=]+).+?#s', + '[youtube]$1[/youtube]', $res['body']); + + $config = HTMLPurifier_Config::createDefault(); $config->set('Cache.DefinitionImpl', null); @@ -560,6 +587,9 @@ function get_atom_elements($feed,$item) { $body = preg_replace('#]+>.+?' . 'http://www.youtube.com/((?:v|cp)/[A-Za-z0-9\-_=]+).+?#s', '[youtube]$1[/youtube]', $body); + $res['body'] = preg_replace('#].+?' . 'http://www.youtube.com/embed/([A-Za-z0-9\-_=]+).+?#s', + '[youtube]$1[/youtube]', $res['body']); + $config = HTMLPurifier_Config::createDefault(); $config->set('Cache.DefinitionImpl', null); @@ -624,6 +654,7 @@ function item_store($arr,$force_parent = false) { $arr['wall'] = ((x($arr,'wall')) ? intval($arr['wall']) : 0); $arr['uri'] = ((x($arr,'uri')) ? notags(trim($arr['uri'])) : random_string()); + $arr['extid'] = ((x($arr,'extid')) ? notags(trim($arr['extid'])) : ''); $arr['author-name'] = ((x($arr,'author-name')) ? notags(trim($arr['author-name'])) : ''); $arr['author-link'] = ((x($arr,'author-link')) ? notags(trim($arr['author-link'])) : ''); $arr['author-avatar'] = ((x($arr,'author-avatar')) ? notags(trim($arr['author-avatar'])) : ''); @@ -728,6 +759,15 @@ function item_store($arr,$force_parent = false) { $arr['uri'], // already dbesc'd intval($arr['uid']) ); + if(! count($r)) { + // This is not good, but perhaps we encountered a rare race/cache condition, so back off and try again. + sleep(3); + $r = q("SELECT `id` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1", + $arr['uri'], // already dbesc'd + intval($arr['uid']) + ); + } + if(count($r)) { $current_post = $r[0]['id']; logger('item_store: created item ' . $current_post); @@ -1294,6 +1334,25 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $secure_fee $datarray['author-avatar'] = $contact['thumb']; } + if((x($datarray,'object-type')) && ($datarray['object-type'] === ACTIVITY_OBJ_EVENT)) { + $ev = bbtoevent($datarray['body']); + if(x($ev,'desc') && x($ev,'start')) { + $ev['uid'] = $importer['uid']; + $ev['uri'] = $item_id; + + if(is_array($contact)) + $ev['cid'] = $contact['id']; + $r = q("SELECT * FROM `event` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1", + dbesc($item_id), + intval($importer['uid']) + ); + if(count($r)) + $ev['id'] = $r[0]['id']; + $xyz = event_store($ev); + continue; + } + } + $r = q("SELECT `uid`, `last-child`, `edited`, `body` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1", dbesc($item_id), intval($importer['uid']) @@ -1530,7 +1589,7 @@ function atom_entry($item,$type,$author,$owner,$comment = false) { if(is_array($author)) $o .= atom_author('author',$author['name'],$author['url'],80,80,$author['thumb']); else - $o .= atom_author('author',$item['name'],$item['url'],80,80,$item['thumb']); + $o .= atom_author('author',(($item['author-name']) ? $item['author-name'] : $item['name']),(($item['author-link']) ? $item['author-link'] : $item['url']),80,80,(($item['author-avatar']) ? $item['author-avatar'] : $item['thumb'])); if(strlen($item['owner-name'])) $o .= atom_author('dfrn:owner',$item['owner-name'],$item['owner-link'],80,80,$item['owner-avatar']); @@ -1558,6 +1617,10 @@ function atom_entry($item,$type,$author,$owner,$comment = false) { if(($item['private']) || strlen($item['allow_cid']) || strlen($item['allow_gid']) || strlen($item['deny_cid']) || strlen($item['deny_gid'])) $o .= '1' . "\r\n"; + if($item['extid']) + $o .= '' . $item['extid'] . '' . "\r\n"; + + $verb = construct_verb($item); $o .= '' . xmlify($verb) . '' . "\r\n"; $actobj = construct_activity_object($item); @@ -1591,7 +1654,7 @@ function fix_private_photos($s,$uid) { $a = get_app(); logger('fix_private_photos'); - if(preg_match("/\[img\](.+?)\[\/img\]/is",$s,$matches)) { + if(preg_match("/\[img\](.*?)\[\/img\]/is",$s,$matches)) { $image = $matches[1]; logger('fix_private_photos: found photo ' . $image); if(stristr($image ,$a->get_baseurl() . '/photo/')) { @@ -1622,7 +1685,7 @@ function fix_private_photos($s,$uid) { function item_getfeedtags($item) { $ret = array(); $matches = false; - $cnt = preg_match_all('|\#\[url\=(.+?)\](.+?)\[\/url\]|',$item['tag'],$matches); + $cnt = preg_match_all('|\#\[url\=(.*?)\](.*?)\[\/url\]|',$item['tag'],$matches); if($cnt) { for($x = 0; $x < count($matches); $x ++) { if($matches[1][$x]) @@ -1630,7 +1693,7 @@ function item_getfeedtags($item) { } } $matches = false; - $cnt = preg_match_all('|\@\[url\=(.+?)\](.+?)\[\/url\]|',$item['tag'],$matches); + $cnt = preg_match_all('|\@\[url\=(.*?)\](.*?)\[\/url\]|',$item['tag'],$matches); if($cnt) { for($x = 0; $x < count($matches); $x ++) { if($matches[1][$x]) @@ -1646,7 +1709,7 @@ function item_getfeedattach($item) { if(count($arr)) { foreach($arr as $r) { $matches = false; - $cnt = preg_match('|\[attach\]href=\"(.+?)\" size=\"(.+?)\" type=\"(.+?)\" title=\"(.+?)\"\[\/attach\]|',$r,$matches); + $cnt = preg_match('|\[attach\]href=\"(.*?)\" size=\"(.*?)\" type=\"(.*?)\" title=\"(.*?)\"\[\/attach\]|',$r,$matches); if($cnt) { $ret .= '