<?php
require_once('bbcode.php');
+require_once('oembed.php');
+require_once('include/salmon.php');
-function get_feed_for(&$a, $dfrn_id, $owner_id, $last_update, $direction = 0) {
+function get_feed_for(&$a, $dfrn_id, $owner_nick, $last_update, $direction = 0) {
// default permissions - anonymous user
AND `deny_gid` = ''
";
- if(strlen($owner_id) && ! intval($owner_id)) {
- $r = q("SELECT `uid`, `nickname` FROM `user` WHERE `nickname` = '%s' LIMIT 1",
- dbesc($owner_id)
+ if(strlen($owner_nick) && ! intval($owner_nick)) {
+ $r = q("SELECT `uid`, `nickname`, `timezone` FROM `user` WHERE `nickname` = '%s' LIMIT 1",
+ dbesc($owner_nick)
);
if(count($r)) {
$owner_id = $r[0]['uid'];
$owner_nick = $r[0]['nickname'];
+ $owner_tz = $r[0]['timezone'];
}
}
else
killme();
+
+ /**
+ *
+ * Determine the next birthday, but only if the birthday is published
+ * in the default profile. We _could_ also look for a private profile that the
+ * recipient can see, but somebody could get mad at us if they start getting
+ * public birthday greetings when they haven't made this info public.
+ *
+ * Assuming we are able to publish this info, we are then going to convert
+ * the start time from the owner's timezone to UTC.
+ *
+ * This will potentially solve the problem found with some social networks
+ * where birthdays are converted to the viewer's timezone and salutations from
+ * elsewhere in the world show up on the wrong day. We will convert it to the
+ * viewer's timezone also, but first we are going to convert it from the birthday
+ * person's timezone to GMT - so the viewer may find the birthday starting at
+ * 6:00PM the day before, but that will correspond to midnight to the birthday person.
+ *
+ */
+
+ $birthday = '';
+
+ $p = q("SELECT `dob` FROM `profile` WHERE `is-default` = 1 AND `uid` = %d LIMIT 1",
+ intval($owner_id)
+ );
+
+ if($p && count($p)) {
+ $tmp_dob = substr($p[0]['dob'],5);
+ if(intval($tmp_dob)) {
+ $y = datetime_convert($owner_tz,$owner_tz,'now','Y');
+ $bd = $y . '-' . $tmp_dob . ' 00:00';
+ $t_dob = strtotime($bd);
+ $now = strtotime(datetime_convert($owner_tz,$owner_tz,'now'));
+ if($t_dob < $now)
+ $bd = $y + 1 . '-' . $tmp_dob . ' 00:00';
+ $birthday = datetime_convert($owner_tz,'UTC',$bd,ATOM_TIME);
+ }
+ }
+
if($dfrn_id && $dfrn_id != '*') {
$sql_extra = '';
$atom .= replace_macros($feed_template, array(
+ '$version' => xmlify(FRIENDIKA_VERSION),
'$feed_id' => xmlify($a->get_baseurl() . '/profile/' . $owner_nick),
'$feed_title' => xmlify($owner['name']),
'$feed_updated' => xmlify(datetime_convert('UTC', 'UTC', 'now' , ATOM_TIME)) ,
'$thumb' => xmlify($owner['thumb']),
'$picdate' => xmlify(datetime_convert('UTC','UTC',$owner['avatar-date'] . '+00:00' , ATOM_TIME)) ,
'$uridate' => xmlify(datetime_convert('UTC','UTC',$owner['uri-date'] . '+00:00' , ATOM_TIME)) ,
- '$namdate' => xmlify(datetime_convert('UTC','UTC',$owner['name-date'] . '+00:00' , ATOM_TIME))
+ '$namdate' => xmlify(datetime_convert('UTC','UTC',$owner['name-date'] . '+00:00' , ATOM_TIME)) ,
+ '$birthday' => ((strlen($birthday)) ? '<dfrn:birthday>' . xmlify($birthday) . '</dfrn:birthday>' : '')
));
+ call_hooks('atom_feed', $atom);
if(! count($items)) {
+
+ call_hooks('atom_feed_end', $atom);
+
$atom .= '</feed>' . "\r\n";
return $atom;
}
$atom .= atom_entry($item,$type,null,$owner,true);
}
+ call_hooks('atom_feed_end', $atom);
+
$atom .= '</feed>' . "\r\n";
+
return $atom;
}
// No photo/profile-link on the item - look at the feed level
- if((! $res['author-link']) || (! $res['author-avatar'])) {
+ if((! (x($res,'author-link'))) || (! (x($res,'author-avatar')))) {
$rawauthor = $feed->get_feed_tags(SIMPLEPIE_NAMESPACE_ATOM_10,'author');
if($rawauthor && $rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link']) {
$base = $rawauthor[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['link'];
foreach($base as $link) {
if($link['attribs']['']['rel'] === 'alternate' && (! $res['author-link']))
$res['author-link'] = unxmlify($link['attribs']['']['href']);
- if(! $res['author-avatar']) {
+ if(! (x($res,'author-avatar'))) {
if($link['attribs']['']['rel'] === 'avatar' || $link['attribs']['']['rel'] === 'photo')
$res['author-avatar'] = unxmlify($link['attribs']['']['href']);
}
}
+ /**
+ * If there's a copy of the body content which is guaranteed to have survived mangling in transit, use it.
+ */
+
+ $have_real_body = false;
+
+ $rawenv = $item->get_item_tags(NAMESPACE_DFRN, 'env');
+ if($rawenv) {
+ $have_real_body = true;
+ $res['body'] = $rawenv[0]['data'];
+ $res['body'] = str_replace(array(' ',"\t","\r","\n"), array('','','',''),$res['body']);
+ $res['body'] = base64url_decode($res['body']);
+ $res['realbody'] = true;
+ }
+
$maxlen = get_max_import_size();
if($maxlen && (strlen($res['body']) > $maxlen))
$res['body'] = substr($res['body'],0, $maxlen);
// It isn't certain at this point whether our content is plaintext or html and we'd be foolish to trust
// the content type. Our own network only emits text normally, though it might have been converted to
- // html if we used a pubsubhubbub transport. But if we see even one html open tag in our text, we will
+ // html if we used a pubsubhubbub transport. But if we see even one html tag in our text, we will
// have to assume it is all html and needs to be purified.
// It doesn't matter all that much security wise - because before this content is used anywhere, we are
// html.
- if(strpos($res['body'],'<')) {
+ if((! $have_real_body) || (strpos($res['body'],'<')) || (strpos($res['body'],'>'))) {
$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);
$purifier = new HTMLPurifier($config);
$res['body'] = $purifier->purify($res['body']);
- }
+ $res['body'] = html2bbcode($res['body']);
+ }
+ else
+ $res['body'] = escape_tags($res['body']);
- $res['body'] = html2bbcode($res['body']);
-
$allow = $item->get_item_tags(NAMESPACE_DFRN,'comment-allow');
if($allow && $allow[0]['data'] == 1)
else
$res['last-child'] = 0;
- $rawcreated = $item->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10,'published');
- if($rawcreated)
- $res['created'] = unxmlify($rawcreated[0]['data']);
+ $private = $item->get_item_tags(NAMESPACE_DFRN,'private');
+ if($private && $private[0]['data'] == 1)
+ $res['private'] = 1;
+ else
+ $res['private'] = 0;
+
$rawlocation = $item->get_item_tags(NAMESPACE_DFRN, 'location');
if($rawlocation)
$res['location'] = unxmlify($rawlocation[0]['data']);
+ $rawcreated = $item->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10,'published');
+ if($rawcreated)
+ $res['created'] = unxmlify($rawcreated[0]['data']);
+
+
$rawedited = $item->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10,'updated');
if($rawedited)
- $res['edited'] = unxmlify($rawcreated[0]['data']);
+ $res['edited'] = unxmlify($rawedited[0]['data']);
+
+ if((x($res,'edited')) && (! (x($res,'created'))))
+ $res['created'] = $res['edited'];
+
+ if(! $res['created'])
+ $res['created'] = $item->get_date('c');
+
+ if(! $res['edited'])
+ $res['edited'] = $item->get_date('c');
+
$rawowner = $item->get_item_tags(NAMESPACE_DFRN, 'owner');
if($rawowner[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'])
$rawverb = $item->get_item_tags(NAMESPACE_ACTIVITY, 'verb');
+
// select between supported verbs
- if($rawverb)
+
+ if($rawverb) {
$res['verb'] = unxmlify($rawverb[0]['data']);
+ }
+
+ // translate OStatus unfollow to activity streams if it happened to get selected
+
+ if((x($res,'verb')) && ($res['verb'] === 'http://ostatus.org/schema/1.0/unfollow'))
+ $res['verb'] = ACTIVITY_UNFOLLOW;
+
+
$rawobj = $item->get_item_tags(NAMESPACE_ACTIVITY, 'object');
$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,'<')) {
+ // preserve a copy of the original body content in case we later need to parse out any microformat information, e.g. events
+ $res['object'] .= '<orig>' . xmlify($body) . '</orig>' . "\n";
+ if((strpos($body,'<')) || (strpos($body,'>'))) {
$body = preg_replace('#<object[^>]+>.+?' . 'http://www.youtube.com/((?:v|cp)/[A-Za-z0-9\-_=]+).+?</object>#s',
'[youtube]$1[/youtube]', $body);
$purifier = new HTMLPurifier($config);
$body = $purifier->purify($body);
+ $body = html2bbcode($body);
}
+ else
+ $body = escape_tags($body);
- $body = html2bbcode($body);
$res['object'] .= '<content>' . $body . '</content>' . "\n";
}
$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,'<')) {
+ // preserve a copy of the original body content in case we later need to parse out any microformat information, e.g. events
+ $res['object'] .= '<orig>' . xmlify($body) . '</orig>' . "\n";
+ if((strpos($body,'<')) || (strpos($body,'>'))) {
$body = preg_replace('#<object[^>]+>.+?' . 'http://www.youtube.com/((?:v|cp)/[A-Za-z0-9\-_=]+).+?</object>#s',
'[youtube]$1[/youtube]', $body);
$purifier = new HTMLPurifier($config);
$body = $purifier->purify($body);
+ $body = html2bbcode($body);
}
+ else
+ $body = escape_tags($body);
- $body = html2bbcode($body);
$res['target'] .= '<content>' . $body . '</content>' . "\n";
}
$res['target'] .= '</target>' . "\n";
}
+ $arr = array('feed' => $feed, 'item' => $item, 'result' => $res);
+
+ call_hooks('parse_atom', $arr);
+
return $res;
}
if($link['attribs']['']['type'])
$o .= 'type="' . $link['attribs']['']['type'] . '" ';
if($link['attribs']['']['href'])
- $o .= 'type="' . $link['attribs']['']['href'] . '" ';
+ $o .= 'href="' . $link['attribs']['']['href'] . '" ';
if( (x($link['attribs'],NAMESPACE_MEDIA)) && $link['attribs'][NAMESPACE_MEDIA]['width'])
$o .= 'media:width="' . $link['attribs'][NAMESPACE_MEDIA]['width'] . '" ';
if( (x($link['attribs'],NAMESPACE_MEDIA)) && $link['attribs'][NAMESPACE_MEDIA]['height'])
$arr['gravity'] = 0;
elseif(activity_match($arr['verb'],ACTIVITY_POST))
$arr['gravity'] = 6;
+ else
+ $arr['gravity'] = 6; // extensible catchall
if(! x($arr,'type'))
- $arr['type'] = 'remote';
- $arr['wall'] = ((intval($arr['wall'])) ? 1 : 0);
- $arr['uri'] = notags(trim($arr['uri']));
- $arr['author-name'] = notags(trim($arr['author-name']));
- $arr['author-link'] = notags(trim($arr['author-link']));
- $arr['author-avatar'] = notags(trim($arr['author-avatar']));
- $arr['owner-name'] = notags(trim($arr['owner-name']));
- $arr['owner-link'] = notags(trim($arr['owner-link']));
- $arr['owner-avatar'] = notags(trim($arr['owner-avatar']));
- $arr['created'] = ((x($arr,'created') !== false) ? datetime_convert('UTC','UTC',$arr['created']) : datetime_convert());
- $arr['edited'] = ((x($arr,'edited') !== false) ? datetime_convert('UTC','UTC',$arr['edited']) : datetime_convert());
- $arr['changed'] = datetime_convert();
- $arr['title'] = notags(trim($arr['title']));
- $arr['location'] = notags(trim($arr['location']));
- $arr['coord'] = notags(trim($arr['coord']));
- $arr['body'] = escape_tags(trim($arr['body']));
- $arr['last-child'] = intval($arr['last-child']);
- $arr['visible'] = ((x($arr,'visible') !== false) ? intval($arr['visible']) : 1);
- $arr['deleted'] = 0;
- $arr['parent-uri'] = notags(trim($arr['parent-uri']));
- $arr['verb'] = notags(trim($arr['verb']));
- $arr['object-type'] = notags(trim($arr['object-type']));
- $arr['object'] = trim($arr['object']);
-
- $parent_id = 0;
- $parent_missing = false;
+ $arr['type'] = 'remote';
+ $arr['wall'] = ((x($arr,'wall')) ? intval($arr['wall']) : 0);
+ $arr['uri'] = ((x($arr,'uri')) ? notags(trim($arr['uri'])) : random_string());
+ $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'])) : '');
+ $arr['owner-name'] = ((x($arr,'owner-name')) ? notags(trim($arr['owner-name'])) : '');
+ $arr['owner-link'] = ((x($arr,'owner-link')) ? notags(trim($arr['owner-link'])) : '');
+ $arr['owner-avatar'] = ((x($arr,'owner-avatar')) ? notags(trim($arr['owner-avatar'])) : '');
+ $arr['created'] = ((x($arr,'created') !== false) ? datetime_convert('UTC','UTC',$arr['created']) : datetime_convert());
+ $arr['edited'] = ((x($arr,'edited') !== false) ? datetime_convert('UTC','UTC',$arr['edited']) : datetime_convert());
+ $arr['changed'] = datetime_convert();
+ $arr['title'] = ((x($arr,'title')) ? notags(trim($arr['title'])) : '');
+ $arr['location'] = ((x($arr,'location')) ? notags(trim($arr['location'])) : '');
+ $arr['coord'] = ((x($arr,'coord')) ? notags(trim($arr['coord'])) : '');
+ $arr['last-child'] = ((x($arr,'last-child')) ? intval($arr['last-child']) : 0 );
+ $arr['visible'] = ((x($arr,'visible') !== false) ? intval($arr['visible']) : 1 );
+ $arr['deleted'] = 0;
+ $arr['parent-uri'] = ((x($arr,'parent-uri')) ? notags(trim($arr['parent-uri'])) : '');
+ $arr['verb'] = ((x($arr,'verb')) ? notags(trim($arr['verb'])) : '');
+ $arr['object-type'] = ((x($arr,'object-type')) ? notags(trim($arr['object-type'])) : '');
+ $arr['object'] = ((x($arr,'object')) ? trim($arr['object']) : '');
+ $arr['target-type'] = ((x($arr,'target-type')) ? notags(trim($arr['target-type'])) : '');
+ $arr['target'] = ((x($arr,'target')) ? trim($arr['target']) : '');
+ $arr['allow_cid'] = ((x($arr,'allow_cid')) ? trim($arr['allow_cid']) : '');
+ $arr['allow_gid'] = ((x($arr,'allow_gid')) ? trim($arr['allow_gid']) : '');
+ $arr['deny_cid'] = ((x($arr,'deny_cid')) ? trim($arr['deny_cid']) : '');
+ $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')) ? escape_tags(trim($arr['body'])) : '');
+
+ // The content body may have been through a lot of filtering and transport escaping by now.
+ // We don't want to skip any filters, however a side effect of all this filtering
+ // is that ampersands and <> may have been double encoded, depending on which filter chain
+ // they came through. The presence of $res['realbody'] means we have something encoded in a
+ // transport safe manner at the source and does not require any filter corrections.
+
+ if(x($arr,'realbody'))
+ unset($arr['realbody']);
+ else {
+ $arr['body'] = str_replace(
+ array('&amp;', '&gt;', '&lt;', '&quot;'),
+ array('&' , '>' , '<', '"'),
+ $arr['body']
+ );
+ }
+
+ if($arr['parent-uri'] === $arr['uri']) {
+ $parent_id = 0;
+ $allow_cid = $arr['allow_cid'];
+ $allow_gid = $arr['allow_gid'];
+ $deny_cid = $arr['deny_cid'];
+ $deny_gid = $arr['deny_gid'];
+ }
+ else {
+
+ // find the parent and snarf the item id and ACL's
+
+ $r = q("SELECT * FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
+ dbesc($arr['parent-uri']),
+ intval($arr['uid'])
+ );
+
+ if(count($r)) {
+
+ // is the new message multi-level threaded?
+ // even though we don't support it now, preserve the info
+ // and re-attach to the conversation parent.
+
+ if($r[0]['uri'] != $r[0]['parent-uri']) {
+ $arr['thr-parent'] = $arr['parent-uri'];
+ $arr['parent-uri'] = $r[0]['parent-uri'];
+ }
+
+ $parent_id = $r[0]['id'];
+ $allow_cid = $r[0]['allow_cid'];
+ $allow_gid = $r[0]['allow_gid'];
+ $deny_cid = $r[0]['deny_cid'];
+ $deny_gid = $r[0]['deny_gid'];
+ }
+ else {
+ logger('item_store: item parent was not found - ignoring item');
+ return 0;
+ }
+ }
+
+ call_hooks('post_remote',$arr);
dbesc_array($arr);
. implode("', '", array_values($arr))
. "')" );
- // find the parent and snarf the item id and ACL's
-
- $r = q("SELECT * FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
- dbesc($arr['parent-uri']),
- intval($arr['uid'])
- );
-
- if(count($r)) {
- $parent_id = $r[0]['id'];
- $allow_cid = $r[0]['allow_cid'];
- $allow_gid = $r[0]['allow_gid'];
- $deny_cid = $r[0]['deny_cid'];
- $deny_gid = $r[0]['deny_gid'];
- }
- else {
- $parent_missing = true;
- }
+ // find the item we just created
$r = q("SELECT `id` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
$arr['uri'], // already dbesc'd
$current_post = $r[0]['id'];
logger('item_store: created item ' . $current_post);
}
- else
- return 0;
-
- if($parent_missing) {
-
- logger('item_store: item parent was not found - ignoring item');
-
- // perhaps the parent was deleted, but in any case, this thread is dead
- // and unfortunately our brand new item now has to be destroyed
-
- q("DELETE FROM `item` WHERE `id` = %d LIMIT 1",
- intval($current_post)
- );
+ else {
+ logger('item_store: could not locate created item');
return 0;
}
- // Set parent id - all of the parent's ACL's are also inherited by this post
+ if($arr['parent-uri'] === $arr['uri'])
+ $parent_id = $current_post;
+
+ if(strlen($allow_cid) || strlen($allow_gid) || strlen($deny_cid) || strlen($deny_gid))
+ $private = 1;
+ else
+ $private = $arr['private'];
+
+ // Set parent id - and also make sure to inherit the parent's ACL's.
$r = q("UPDATE `item` SET `parent` = %d, `allow_cid` = '%s', `allow_gid` = '%s',
- `deny_cid` = '%s', `deny_gid` = '%s' WHERE `id` = %d LIMIT 1",
+ `deny_cid` = '%s', `deny_gid` = '%s', `private` = %d WHERE `id` = %d LIMIT 1",
intval($parent_id),
dbesc($allow_cid),
dbesc($allow_gid),
dbesc($deny_cid),
dbesc($deny_gid),
+ intval($private),
intval($current_post)
);
}
-function dfrn_deliver($owner,$contact,$atom) {
+function dfrn_deliver($owner,$contact,$atom, $dissolve = false) {
+ $a = get_app();
if((! strlen($contact['dfrn-id'])) && (! $contact['duplex']) && (! ($owner['page-flags'] == PAGE_COMMUNITY)))
return 3;
if($contact['duplex'] && $contact['issued-id'])
$idtosend = '1:' . $orig_id;
- $url = $contact['notify'] . '?dfrn_id=' . $idtosend . '&dfrn_version=' . DFRN_PROTOCOL_VERSION ;
+ $rino = ((function_exists('mcrypt_encrypt')) ? 1 : 0);
+
+ $rino_enable = get_config('system','rino_encrypt');
+
+ if(! $rino_enable)
+ $rino = 0;
+
+ $url = $contact['notify'] . '?dfrn_id=' . $idtosend . '&dfrn_version=' . DFRN_PROTOCOL_VERSION . (($rino) ? '&rino=1' : '');
logger('dfrn_deliver: ' . $url);
$xml = fetch_url($url);
+ $curl_stat = $a->get_curl_code();
+ if(! $curl_stat)
+ return(-1); // timed out
+
logger('dfrn_deliver: ' . $xml);
if(! $xml)
return (($res->status) ? $res->status : 3);
$postvars = array();
- $sent_dfrn_id = hex2bin($res->dfrn_id);
- $challenge = hex2bin($res->challenge);
+ $sent_dfrn_id = hex2bin((string) $res->dfrn_id);
+ $challenge = hex2bin((string) $res->challenge);
+ $rino_allowed = ((intval($res->rino) === 1) ? 1 : 0);
$final_dfrn_id = '';
-
if(($contact['duplex'] && strlen($contact['prvkey'])) || ($owner['page-flags'] == PAGE_COMMUNITY)) {
openssl_private_decrypt($sent_dfrn_id,$final_dfrn_id,$contact['prvkey']);
openssl_private_decrypt($challenge,$postvars['challenge'],$contact['prvkey']);
$postvars['dfrn_id'] = $idtosend;
$postvars['dfrn_version'] = DFRN_PROTOCOL_VERSION;
+ if($dissolve)
+ $postvars['dissolve'] = '1';
if(($contact['rel']) && ($contact['rel'] != REL_FAN) && (! $contact['blocked']) && (! $contact['readonly'])) {
$postvars['data'] = $atom;
$postvars['data'] = str_replace('<dfrn:comment-allow>1','<dfrn:comment-allow>0',$atom);
}
+ if($rino && $rino_allowed && (! $dissolve)) {
+ $key = substr(random_string(),0,16);
+ $data = bin2hex(aes_encrypt($postvars['data'],$key));
+ $postvars['data'] = $data;
+ logger('rino: sent key = ' . $key);
+
+ if(($contact['duplex'] && strlen($contact['prvkey'])) || ($owner['page-flags'] == PAGE_COMMUNITY)) {
+ openssl_private_encrypt($key,$postvars['key'],$contact['prvkey']);
+ }
+ else {
+ openssl_public_encrypt($key,$postvars['key'],$contact['pubkey']);
+ }
+
+ logger('md5 rawkey ' . md5($postvars['key']));
+
+ $postvars['key'] = bin2hex($postvars['key']);
+ }
+
+ logger('dfrn_deliver: ' . "SENDING: " . print_r($postvars,true), LOGGER_DATA);
+
$xml = post_url($contact['notify'],$postvars);
- logger('dfrn_deliver: ' . "SENDING: " . print_r($postvars,true) . "\n" . "RECEIVING: " . $xml);
+ logger('dfrn_deliver: ' . "RECEIVED: " . $xml, LOGGER_DATA);
+
+ $curl_stat = $a->get_curl_code();
+ if((! $curl_stat) || (! strlen($xml)))
+ return(-1); // timed out
$res = simplexml_load_string($xml);
* $contact = the person who is sending us stuff. If not set, we MAY be processing a "follow" activity
* from an external network and MAY create an appropriate contact record. Otherwise, we MUST
* have a contact record.
- * $hub = should wefind ahub declation in the feed, pass it back to our calling process, who might (or
+ * $hub = should we find a hub declation in the feed, pass it back to our calling process, who might (or
* might not) try and subscribe to it.
*
*/
-function consume_feed($xml,$importer,$contact, &$hub, $datedir = 0) {
+function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0) {
require_once('simplepie/simplepie.inc');
$feed->enable_order_by_date(false);
$feed->init();
+ if($feed->error())
+ logger('consume_feed: Error parsing XML: ' . $feed->error());
+
+
// Check at the feed level for updated contact name and/or photo
- $debugging = get_config('system','debugging');
$name_updated = '';
$new_name = '';
$photo_timestamp = '';
$photo_url = '';
-
+ $birthday = '';
$hubs = $feed->get_links('hub');
$photo_timestamp = datetime_convert('UTC','UTC',$elems['link'][0]['attribs'][NAMESPACE_DFRN]['updated']);
$photo_url = $elems['link'][0]['attribs']['']['href'];
}
- }
- if(! $photo_timestamp) {
- $photo_rawupdate = $feed->get_feed_tags(NAMESPACE_DFRN,'icon-updated');
- if($photo_rawupdate) {
- $photo_timestamp = datetime_convert('UTC','UTC',$photo_rawupdate[0]['data']);
- $photo_url = $feed->get_image_url();
+
+ if((x($rawtags[0]['child'], NAMESPACE_DFRN)) && (x($rawtags[0]['child'][NAMESPACE_DFRN],'birthday'))) {
+ $birthday = datetime_convert('UTC','UTC', $rawtags[0]['child'][NAMESPACE_DFRN]['birthday'][0]['data']);
}
}
- if((is_array($contact)) && ($photo_timestamp) && (strlen($photo_url)) && ($photo_timestamp > $contact['avatar-date'])) {
+ if((is_array($contact)) && ($photo_timestamp) && (strlen($photo_url)) && ($photo_timestamp > $contact['avatar-date'])) {
+ logger('consume_feed: Updating photo for ' . $contact['name']);
require_once("Photo.php");
$photo_failure = false;
+ $have_photo = false;
$r = q("SELECT `resource-id` FROM `photo` WHERE `contact-id` = %d AND `uid` = %d LIMIT 1",
intval($contact['id']),
);
if(count($r)) {
$resource_id = $r[0]['resource-id'];
- $img_str = fetch_url($photo_url,true);
- $img = new Photo($img_str);
- if($img->is_valid()) {
- q("DELETE FROM `photo` WHERE `resource-id` = '%s' AND contact-id` = %d AND `uid` = %d",
+ $have_photo = true;
+ }
+ else {
+ $resource_id = photo_new_resource();
+ }
+
+ $img_str = fetch_url($photo_url,true);
+ $img = new Photo($img_str);
+ if($img->is_valid()) {
+ if($have_photo) {
+ q("DELETE FROM `photo` WHERE `resource-id` = '%s' AND `contact-id` = %d AND `uid` = %d",
dbesc($resource_id),
intval($contact['id']),
intval($contact['uid'])
);
-
- $img->scaleImageSquare(175);
+ }
- $hash = $resource_id;
- $r = $img->store($contact['uid'], $contact['id'], $hash, basename($photo_url), t('Contact Photos') , 4);
+ $img->scaleImageSquare(175);
- $img->scaleImage(80);
- $r = $img->store($contact['uid'], $contact['id'], $hash, basename($photo_url), t('Contact Photos') , 5);
-
- $img->scaleImage(48);
- $r = $img->store($contact['uid'], $contact['id'], $hash, basename($photo_url), t('Contact Photos') , 6);
-
- if($r)
- q("UPDATE `contact` SET `avatar-date` = '%s' WHERE `uid` = %d AND `id` = %d LIMIT 1",
- dbesc(datetime_convert()),
- intval($contact['uid']),
- intval($contact['id'])
- );
- }
+ $hash = $resource_id;
+ $r = $img->store($contact['uid'], $contact['id'], $hash, basename($photo_url), t('Contact Photos') , 4);
+
+ $img->scaleImage(80);
+ $r = $img->store($contact['uid'], $contact['id'], $hash, basename($photo_url), t('Contact Photos') , 5);
+
+ $img->scaleImage(48);
+ $r = $img->store($contact['uid'], $contact['id'], $hash, basename($photo_url), t('Contact Photos') , 6);
+
+ $a = get_app();
+
+ q("UPDATE `contact` SET `avatar-date` = '%s', `photo` = '%s', `thumb` = '%s', `micro` = '%s'
+ WHERE `uid` = %d AND `id` = %d LIMIT 1",
+ dbesc(datetime_convert()),
+ dbesc($a->get_baseurl() . '/photo/' . $hash . '-4.jpg'),
+ dbesc($a->get_baseurl() . '/photo/' . $hash . '-5.jpg'),
+ dbesc($a->get_baseurl() . '/photo/' . $hash . '-6.jpg'),
+ intval($contact['uid']),
+ intval($contact['id'])
+ );
}
}
);
}
+ if(strlen($birthday)) {
+ if(substr($birthday,0,4) != $contact['bdyear']) {
+ logger('consume_feed: updating birthday: ' . $birthday);
+
+ /**
+ *
+ * Add new birthday event for this person
+ *
+ * $bdtext is just a readable placeholder in case the event is shared
+ * with others. We will replace it during presentation to our $importer
+ * to contain a sparkle link and perhaps a photo.
+ *
+ */
+
+ $bdtext = t('Birthday:') . ' [url=' . $contact['url'] . ']' . $contact['name'] . '[/url]' ;
+
+
+ $r = q("INSERT INTO `event` (`uid`,`cid`,`created`,`edited`,`start`,`finish`,`desc`,`type`)
+ VALUES ( %d, %d, '%s', '%s', '%s', '%s', '%s', '%s' ) ",
+ intval($contact['uid']),
+ intval($contact['id']),
+ dbesc(datetime_convert()),
+ dbesc(datetime_convert()),
+ dbesc(datetime_convert('UTC','UTC', $birthday)),
+ dbesc(datetime_convert('UTC','UTC', $birthday . ' + 1 day ')),
+ dbesc($bdtext),
+ dbesc('birthday')
+ );
+
+
+ // update bdyear
+
+ q("UPDATE `contact` SET `bdyear` = '%s' WHERE `uid` = %d AND `id` = %d LIMIT 1",
+ dbesc(substr($birthday,0,4)),
+ intval($contact['uid']),
+ intval($contact['id'])
+ );
+
+ // This function is called twice without reloading the contact
+ // Make sure we only create one event. This is why &$contact
+ // is a reference var in this function
+
+ $contact['bdyear'] = substr($birthday,0,4);
+ }
+
+ }
+
// Now process the feed
if($feed->get_item_quantity()) {
- foreach($feed->get_items() as $item) {
+
+ // in inverse date order
+ if ($datedir)
+ $items = array_reverse($feed->get_items());
+ else
+ $items = $feed->get_items();
+
+ foreach($items as $item) {
$deleted = false;
continue;
}
$datarray = get_atom_elements($feed,$item);
+
if($contact['network'] === 'stat') {
if(strlen($datarray['title']))
unset($datarray['title']);
);
$datarray['last-child'] = 1;
}
+
+ if(($contact['network'] === 'feed') || (! strlen($contact['notify']))) {
+ // one way feed - no remote comment ability
+ $datarray['last-child'] = 0;
+ }
$datarray['parent-uri'] = $parent_uri;
$datarray['uid'] = $importer['uid'];
$datarray['contact-id'] = $contact['id'];
$datarray['last-child'] = 1;
}
+ if(($contact['network'] === 'feed') || (! strlen($contact['notify']))) {
+ // one way feed - no remote comment ability
+ $datarray['last-child'] = 0;
+ }
+
$datarray['parent-uri'] = $item_id;
$datarray['uid'] = $importer['uid'];
$datarray['contact-id'] = $contact['id'];
}
}
}
-
}
function new_follower($importer,$contact,$datarray,$item) {
$r = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1",
intval($importer['uid'])
);
+ $a = get_app();
if(count($r)) {
if(($r[0]['notify-flags'] & NOTIFY_INTRO) && ($r[0]['page-flags'] == PAGE_NORMAL)) {
$email_tpl = load_view_file('view/follow_notify_eml.tpl');
$o .= "<uri>$uri</uri>\r\n";
$o .= '<link rel="photo" type="image/jpeg" media:width="' . $w . '" media:height="' . $h . '" href="' . $photo . '" />' . "\r\n";
$o .= '<link rel="avatar" type="image/jpeg" media:width="' . $w . '" media:height="' . $h . '" href="' . $photo . '" />' . "\r\n";
+
+ call_hooks('atom_author', $o);
+
$o .= "</$tag>\r\n";
return $o;
}
$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 .= '<link rel="alternate" 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($item['location'])
+
+ if($item['location']) {
$o .= '<dfrn:location>' . xmlify($item['location']) . '</dfrn:location>' . "\r\n";
+ $o .= '<poco:address><poco:formatted>' . xmlify($item['location']) . '</poco:formatted></poco:address>' . "\r\n";
+ }
+
if($item['coord'])
$o .= '<georss:point>' . xmlify($item['coord']) . '</georss:point>' . "\r\n";
+ if(($item['private']) || strlen($item['allow_cid']) || strlen($item['allow_gid']) || strlen($item['deny_cid']) || strlen($item['deny_gid']))
+ $o .= '<dfrn:private>1</dfrn:private>' . "\r\n";
+
$verb = construct_verb($item);
$o .= '<as:verb>' . xmlify($verb) . '</as:verb>' . "\r\n";
$actobj = construct_activity_object($item);
if($mentioned)
$o .= $mentioned;
+ call_hooks('atom_entry', $o);
+
$o .= '</entry>' . "\r\n";
return $o;
}
-
\ No newline at end of file
+