if($item['object']) {
$o = '<as:object>' . "\r\n";
- $r = @simplexml_load_string($item['object']);
+ $r = parse_xml_string($item['object']);
if($r->type)
$o .= '<as:object-type>' . xmlify($r->type) . '</as:object-type>' . "\r\n";
if($r->id)
if($item['target']) {
$o = '<as:target>' . "\r\n";
- $r = @simplexml_load_string($item['target']);
+ $r = parse_xml_string($item['target']);
if($r->type)
$o .= '<as:object-type>' . xmlify($r->type) . '</as:object-type>' . "\r\n";
if($r->id)
$res = array();
$author = $item->get_author();
- $res['author-name'] = unxmlify($author->get_name());
- $res['author-link'] = unxmlify($author->get_link());
+ if($author) {
+ $res['author-name'] = unxmlify($author->get_name());
+ $res['author-link'] = unxmlify($author->get_link());
+ }
+ else {
+ $res['author-name'] = unxmlify($feed->get_title());
+ $res['author-link'] = unxmlify($feed->get_permalink());
+ }
$res['uri'] = unxmlify($item->get_id());
$res['title'] = unxmlify($item->get_title());
$res['body'] = unxmlify($item->get_content());
// the wild, by sanitising it and converting supported tags to bbcode before we rip out any remaining
// html.
-
if((strpos($res['body'],'<') !== false) || (strpos($res['body'],'>') !== false)) {
$res['body'] = preg_replace('#<object[^>]+>.+?' . 'http://www.youtube.com/((?:v|cp)/[A-Za-z0-9\-_=]+).+?</object>#s',
'[youtube]$1[/youtube]', $res['body']);
$res['body'] = oembed_html2bbcode($res['body']);
-
+
$config = HTMLPurifier_Config::createDefault();
$config->set('Cache.DefinitionImpl', null);
$res['body'] = html2bbcode($res['body']);
}
-
+
$allow = $item->get_item_tags(NAMESPACE_DFRN,'comment-allow');
if($allow && $allow[0]['data'] == 1)
$res['last-child'] = 1;
$res['edited'] = $item->get_date('c');
+ // Disallow time travelling posts
+
+ $d1 = strtotime($res['created']);
+ $d2 = strtotime($res['edited']);
+ $d3 = strtotime('now');
+
+ if($d1 > $d3)
+ $res['created'] = datetime_convert();
+ if($d2 > $d3)
+ $res['edited'] = datetime_convert();
+
$rawowner = $item->get_item_tags(NAMESPACE_DFRN, 'owner');
if($rawowner[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'])
$res['owner-name'] = unxmlify($rawowner[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data']);
if((x($res,'verb')) && ($res['verb'] === 'http://ostatus.org/schema/1.0/unfollow'))
$res['verb'] = ACTIVITY_UNFOLLOW;
-
+
+ $cats = $item->get_categories();
+ if($cats) {
+ $tag_arr = array();
+ foreach($cats as $cat) {
+ $term = $cat->get_term();
+ if(! $term)
+ $term = $cat->get_label();
+ $scheme = $cat->get_scheme();
+ if($scheme && $term && stristr($scheme,'X-DFRN:'))
+ $tag_arr[] = substr($scheme,7,1) . '[url=' . unxmlify(substr($scheme,9)) . ']' . unxmlify($term) . '[/url]';
+ elseif($term)
+ $tag_arr[] = notags(trim($term));
+ }
+ $res['tag'] = implode(',', $tag_arr);
+ }
+
+ $attach = $item->get_enclosures();
+ if($attach) {
+ $att_arr = array();
+ foreach($attach as $att) {
+ $len = intval($att->get_length());
+ $link = str_replace(array(',','"'),array('%2D','%22'),notags(trim(unxmlify($att->get_link()))));
+ $title = str_replace(array(',','"'),array('%2D','%22'),notags(trim(unxmlify($att->get_title()))));
+ $type = str_replace(array(',','"'),array('%2D','%22'),notags(trim(unxmlify($att->get_type()))));
+ if(strpos($type,';'))
+ $type = substr($type,0,strpos($type,';'));
+ if((! $link) || (strpos($link,'http') !== 0))
+ continue;
+
+ if(! $title)
+ $title = ' ';
+ if(! $type)
+ $type = 'application/octet-stream';
+
+ $att_arr[] = '[attach]href="' . $link . '" size="' . $len . '" type="' . $type . '" title="' . $title . '"[/attach]';
+ }
+ $res['attach'] = implode(',', $att_arr);
+ }
$rawobj = $item->get_item_tags(NAMESPACE_ACTIVITY, 'object');
$arr['deny_gid'] = ((x($arr,'deny_gid')) ? trim($arr['deny_gid']) : '');
$arr['private'] = ((x($arr,'private')) ? intval($arr['private']) : 0 );
$arr['body'] = ((x($arr,'body')) ? trim($arr['body']) : '');
+ $arr['tag'] = ((x($arr,'tag')) ? notags(trim($arr['tag'])) : '');
+ $arr['attach'] = ((x($arr,'attach')) ? notags(trim($arr['attach'])) : '');
if($arr['parent-uri'] === $arr['uri']) {
$parent_id = 0;
else {
// find the parent and snarf the item id and ACL's
+ // and anything else we need to inherit
$r = q("SELECT * FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
dbesc($arr['parent-uri']),
$allow_gid = $r[0]['allow_gid'];
$deny_cid = $r[0]['deny_cid'];
$deny_gid = $r[0]['deny_gid'];
+ $arr['wall'] = $r[0]['wall'];
}
else {
$parent_id = 0;
$arr['thr-parent'] = $arr['parent-uri'];
$arr['parent-uri'] = $arr['uri'];
+ $arr['gravity'] = 0;
}
else {
logger('item_store: item parent was not found - ignoring item');
intval($current_post)
);
+ /**
+ * If this is now the last-child, force all _other_ children of this parent to *not* be last-child
+ */
+
+ if($arr['last-child']) {
+ $r = q("UPDATE `item` SET `last-child` = 0 WHERE `parent-uri` = '%s' AND `uid` = %d AND `id` != %d",
+ dbesc($arr['uri']),
+ intval($arr['uid']),
+ intval($current_post)
+ );
+ }
+
return $current_post;
}
if(! $rino_enable)
$rino = 0;
- $url = $contact['notify'] . '?dfrn_id=' . $idtosend . '&dfrn_version=' . DFRN_PROTOCOL_VERSION . (($rino) ? '&rino=1' : '');
+ $url = $contact['notify'] . '&dfrn_id=' . $idtosend . '&dfrn_version=' . DFRN_PROTOCOL_VERSION . (($rino) ? '&rino=1' : '');
logger('dfrn_deliver: ' . $url);
return 3;
}
- $res = simplexml_load_string($xml);
+ $res = parse_xml_string($xml);
if((intval($res->status) != 0) || (! strlen($res->challenge)) || (! strlen($res->dfrn_id)))
return (($res->status) ? $res->status : 3);
if($dissolve)
$postvars['dissolve'] = '1';
- if(($contact['rel']) && ($contact['rel'] != REL_FAN) && (! $contact['blocked']) && (! $contact['readonly'])) {
- $postvars['data'] = $atom;
- }
- elseif($owner['page-flags'] == PAGE_COMMUNITY) {
+
+ if((($contact['rel']) && ($contact['rel'] != REL_FAN) && (! $contact['blocked'])) || ($owner['page-flags'] == PAGE_COMMUNITY)) {
$postvars['data'] = $atom;
+ $postvars['perm'] = 'rw';
}
else {
$postvars['data'] = str_replace('<dfrn:comment-allow>1','<dfrn:comment-allow>0',$atom);
+ $postvars['perm'] = 'r';
}
if($rino && $rino_allowed && (! $dissolve)) {
if((! $curl_stat) || (! strlen($xml)))
return(-1); // timed out
-
if(strpos($xml,'<?xml') === false) {
logger('dfrn_deliver: phase 2: no valid XML returned');
logger('dfrn_deliver: phase 2: returned XML: ' . $xml, LOGGER_DATA);
return 3;
}
- $res = simplexml_load_string($xml);
+ $res = parse_xml_string($xml);
- return $res->status;
-
+ return $res->status;
}
*
*/
-function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0) {
+function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $secure_feed = false) {
require_once('simplepie/simplepie.inc');
if($feed->error())
logger('consume_feed: Error parsing XML: ' . $feed->error());
+ $permalink = $feed->get_permalink();
// Check at the feed level for updated contact name and/or photo
// Have we seen it? If not, import it.
- $item_id = $item->get_id();
+ $item_id = $item->get_id();
+ $datarray = get_atom_elements($feed,$item);
- $r = q("SELECT `uid`, `last-child`, `edited` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
+ $r = q("SELECT `uid`, `last-child`, `edited`, `body` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
dbesc($item_id),
intval($importer['uid'])
);
- // FIXME update content if 'updated' changes
+ // Update content if 'updated' changes
+
if(count($r)) {
+ if((x($datarray,'edited') !== false) && (datetime_convert('UTC','UTC',$datarray['edited']) !== $r[0]['edited'])) {
+ $r = q("UPDATE `item` SET `body` = '%s', `edited` = '%s' WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
+ dbesc($datarray['body']),
+ dbesc(datetime_convert('UTC','UTC',$datarray['edited'])),
+ dbesc($item_id),
+ intval($importer['uid'])
+ );
+ }
+
+ // update last-child if it changes
+
$allow = $item->get_item_tags( NAMESPACE_DFRN, 'comment-allow');
if(($allow) && ($allow[0]['data'] != $r[0]['last-child'])) {
$r = q("UPDATE `item` SET `last-child` = 0, `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
continue;
}
- $datarray = get_atom_elements($feed,$item);
$force_parent = false;
if($contact['network'] === 'stat') {
$force_parent = true;
}
else {
+
// Head post of a conversation. Have we seen it? If not, import it.
- $item_id = $item->get_id();
- $r = q("SELECT `uid`, `last-child`, `edited` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
+ $item_id = $item->get_id();
+
+ $datarray = get_atom_elements($feed,$item);
+
+ $r = q("SELECT `uid`, `last-child`, `edited`, `body` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
dbesc($item_id),
intval($importer['uid'])
);
+
+ // Update content if 'updated' changes
+
if(count($r)) {
+ if((x($datarray,'edited') !== false) && (datetime_convert('UTC','UTC',$datarray['edited']) !== $r[0]['edited'])) {
+ $r = q("UPDATE `item` SET `body` = '%s', `edited` = '%s' WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
+ dbesc($datarray['body']),
+ dbesc(datetime_convert('UTC','UTC',$datarray['edited'])),
+ dbesc($item_id),
+ intval($importer['uid'])
+ );
+ }
+
+ // update last-child if it changes
+
$allow = $item->get_item_tags( NAMESPACE_DFRN, 'comment-allow');
if($allow && $allow[0]['data'] != $r[0]['last-child']) {
$r = q("UPDATE `item` SET `last-child` = %d , `changed` = '%s' WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
}
continue;
}
- $datarray = get_atom_elements($feed,$item);
if(activity_match($datarray['verb'],ACTIVITY_FOLLOW)) {
logger('consume-feed: New follower');
if(! is_array($contact))
return;
- if($contact['network'] === 'stat') {
+ if($contact['network'] === 'stat' || stristr($permalink,'twitter.com')) {
if(strlen($datarray['title']))
unset($datarray['title']);
$datarray['last-child'] = 1;
// create contact record - set to readonly
$r = q("INSERT INTO `contact` ( `uid`, `created`, `url`, `name`, `nick`, `photo`, `network`, `rel`,
- `blocked`, `readonly`, `pending` )
- VALUES ( %d, '%s', '%s', '%s', '%s', '%s', '%s', %d, 0, 1, 1 ) ",
+ `blocked`, `readonly`, `pending`, `writable` )
+ VALUES ( %d, '%s', '%s', '%s', '%s', '%s', '%s', %d, 0, 1, 1, 1 ) ",
intval($importer['uid']),
dbesc(datetime_convert()),
dbesc($url),
$res = mail($r[0]['email'],
t("You have a new follower at ") . $a->config['sitename'],
$email,
- 'From: ' . t('Administrator') . '@' . $_SERVER['SERVER_NAME'] );
+ 'From: ' . t('Administrator') . '@' . $_SERVER['SERVER_NAME'] . "\n"
+ . 'Content-type: text/plain; charset=UTF-8' . "\n"
+ . 'Content-transfer-encoding: 8bit' );
}
}
function atom_entry($item,$type,$author,$owner,$comment = false) {
+ $a = get_app();
+
if($item['deleted'])
return '<at:deleted-entry ref="' . xmlify($item['uri']) . '" when="' . xmlify(datetime_convert('UTC','UTC',$item['edited'] . '+00:00',ATOM_TIME)) . '" />' . "\r\n";
- $a = get_app();
+
+ if($item['allow_cid'] || $item['allow_gid'] || $item['deny_cid'] || $item['deny_gid'])
+ $body = fix_private_photos($item['body'],$owner['uid']);
+ else
+ $body = $item['body'];
+
$o = "\r\n\r\n<entry>\r\n";
$o .= '<title>' . xmlify($item['title']) . '</title>' . "\r\n";
$o .= '<published>' . xmlify(datetime_convert('UTC','UTC',$item['created'] . '+00:00',ATOM_TIME)) . '</published>' . "\r\n";
$o .= '<updated>' . xmlify(datetime_convert('UTC','UTC',$item['edited'] . '+00:00',ATOM_TIME)) . '</updated>' . "\r\n";
- $o .= '<dfrn:env>' . base64url_encode($item['body'], true) . '</dfrn:env>' . "\r\n";
- $o .= '<content type="' . $type . '" >' . xmlify(($type === 'html') ? bbcode($item['body']) : $item['body']) . '</content>' . "\r\n";
+ $o .= '<dfrn:env>' . base64url_encode($body, true) . '</dfrn:env>' . "\r\n";
+ $o .= '<content type="' . $type . '" >' . xmlify(($type === 'html') ? bbcode($body) : $body) . '</content>' . "\r\n";
$o .= '<link rel="alternate" type="text/html" href="' . xmlify($a->get_baseurl() . '/display/' . $owner['nickname'] . '/' . $item['id']) . '" />' . "\r\n";
if($comment)
$o .= '<dfrn:comment-allow>' . intval($item['last-child']) . '</dfrn:comment-allow>' . "\r\n";
if(strlen($actarg))
$o .= $actarg;
+ $tags = item_getfeedtags($item);
+ if(count($tags)) {
+ foreach($tags as $t) {
+ $o .= '<category scheme="X-DFRN:' . xmlify($t[0]) . ':' . xmlify($t[1]) . '" term="' . xmlify($t[2]) . '" />' . "\r\n";
+ }
+ }
+
+ $o .= item_getfeedattach($item);
+
$mentioned = get_mentions($item);
if($mentioned)
$o .= $mentioned;
return $o;
}
+
+function fix_private_photos($s,$uid) {
+ $a = get_app();
+ logger('fix_private_photos');
+
+ 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/')) {
+ $i = basename($image);
+ $i = str_replace('.jpg','',$i);
+ $x = strpos($i,'-');
+ if($x) {
+ $res = substr($i,$x+1);
+ $i = substr($i,0,$x);
+ $r = q("SELECT * FROM `photo` WHERE `resource-id` = '%s' AND `scale` = %d AND `uid` = %d",
+ dbesc($i),
+ intval($res),
+ intval($uid)
+ );
+ if(count($r)) {
+ logger('replacing photo');
+ $s = str_replace($image, 'data:image/jpg;base64,' . base64_encode($r[0]['data']), $s);
+ }
+ }
+ logger('fix_private_photos: replaced: ' . $s, LOGGER_DATA);
+ }
+ }
+ return($s);
+}
+
+
+
+function item_getfeedtags($item) {
+ $ret = array();
+ $matches = false;
+ $cnt = preg_match_all('|\#\[url\=(.+?)\](.+?)\[\/url\]|',$item['tag'],$matches);
+ if($cnt) {
+ for($x = 0; $x < count($matches); $x ++) {
+ if($matches[1][$x])
+ $ret[] = array('#',$matches[1][$x], $matches[2][$x]);
+ }
+ }
+ $matches = false;
+ $cnt = preg_match_all('|\@\[url\=(.+?)\](.+?)\[\/url\]|',$item['tag'],$matches);
+ if($cnt) {
+ for($x = 0; $x < count($matches); $x ++) {
+ if($matches[1][$x])
+ $ret[] = array('#',$matches[1][$x], $matches[2][$x]);
+ }
+ }
+ return $ret;
+}
+
+function item_getfeedattach($item) {
+ $ret = '';
+ $arr = explode(',',$item['attach']);
+ if(count($arr)) {
+ foreach($arr as $r) {
+ $matches = false;
+ $cnt = preg_match('|\[attach\]href=\"(.+?)\" size=\"(.+?)\" type=\"(.+?)\" title=\"(.+?)\"\[\/attach\]|',$r,$matches);
+ if($cnt) {
+ $ret .= '<link rel="enclosure" href="' . xmlify($matches[1]) . '" type="' . xmlify($matches[3]) . '" ';
+ if(intval($matches[2]))
+ $ret .= 'size="' . intval($matches[2]) . '" ';
+ if($matches[4] !== ' ')
+ $ret .= 'title="' . xmlify(trim($matches[4])) . '" ';
+ $ret .= ' />' . "\r\n";
+ }
+ }
+ }
+ return $ret;
+}
+
+
+function item_expire($uid,$days) {
+
+ if((! $uid) || (! $days))
+ return;
+
+ $r = q("SELECT * FROM `item`
+ WHERE `uid` = %d
+ AND `created` < UTC_TIMESTAMP() - INTERVAL %d DAY
+ AND `id` = `parent`
+ AND `deleted` = 0",
+ intval($uid),
+ intval($days)
+ );
+
+ if(! count($r))
+ return;
+
+ logger('expire: # items=' . count($r) );
+
+ foreach($r as $item) {
+
+ // Only expire posts, not photos and photo comments
+
+ if(strlen($item['resource-id']))
+ continue;
+
+ $r = q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s' WHERE `id` = %d LIMIT 1",
+ dbesc(datetime_convert()),
+ dbesc(datetime_convert()),
+ intval($item['id'])
+ );
+
+ // kill the kids
+
+ $r = q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d ",
+ dbesc(datetime_convert()),
+ dbesc(datetime_convert()),
+ dbesc($item['parent-uri']),
+ intval($item['uid'])
+ );
+
+ }
+
+ proc_run('php',"include/notifier.php","expire","$uid");
+
+}
\ No newline at end of file