aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfriendica <info@friendica.com>2013-08-07 03:54:47 -0700
committerfriendica <info@friendica.com>2013-08-07 03:54:47 -0700
commit38d9cf4327fe108df3c269b187f5ef633c651a80 (patch)
treee373da26dfbdfa94979b3125bb12d35d7a434f26
parent20b22421d3731bfcc8b349fbc082156d001a099a (diff)
downloadvolse-hubzilla-38d9cf4327fe108df3c269b187f5ef633c651a80.tar.gz
volse-hubzilla-38d9cf4327fe108df3c269b187f5ef633c651a80.tar.bz2
volse-hubzilla-38d9cf4327fe108df3c269b187f5ef633c651a80.zip
remove some un-needed code
-rwxr-xr-xinclude/items.php1330
1 files changed, 10 insertions, 1320 deletions
diff --git a/include/items.php b/include/items.php
index b02e27ce0..e71fd0350 100755
--- a/include/items.php
+++ b/include/items.php
@@ -2512,176 +2512,6 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0)
$photo_url = '';
$birthday = '';
- $hubs = $feed->get_links('hub');
- logger('consume_feed: hubs: ' . print_r($hubs,true), LOGGER_DATA);
-
- if(count($hubs))
- $hub = implode(',', $hubs);
-
- $rawtags = $feed->get_feed_tags( NAMESPACE_DFRN, 'owner');
- if(! $rawtags)
- $rawtags = $feed->get_feed_tags( SIMPLEPIE_NAMESPACE_ATOM_10, 'author');
- if($rawtags) {
- $elems = $rawtags[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10];
- if($elems['name'][0]['attribs'][NAMESPACE_DFRN]['updated']) {
- $name_updated = $elems['name'][0]['attribs'][NAMESPACE_DFRN]['updated'];
- $new_name = $elems['name'][0]['data'];
- }
- if((x($elems,'link')) && ($elems['link'][0]['attribs']['']['rel'] === 'photo') && ($elems['link'][0]['attribs'][NAMESPACE_DFRN]['updated'])) {
- $photo_timestamp = datetime_convert('UTC','UTC',$elems['link'][0]['attribs'][NAMESPACE_DFRN]['updated']);
- $photo_url = $elems['link'][0]['attribs']['']['href'];
- }
-
- 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'])) {
- logger('consume_feed: Updating photo for ' . $contact['name']);
-
- $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']),
- intval($contact['uid'])
- );
- if(count($r)) {
- $resource_id = $r[0]['resource_id'];
- $have_photo = true;
- }
- else {
- $resource_id = photo_new_resource();
- }
-
- $img_str = fetch_url($photo_url,true);
- // guess mimetype from headers or filename
- $type = guess_image_type($photo_url,true);
-
-
- $img = photo_factory($img_str, $type);
- 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(0, $contact['uid'], $contact['id'], $hash, basename($photo_url), 'Contact Photos', 4);
-
- $img->scaleImage(80);
- $r = $img->store(0, $contact['uid'], $contact['id'], $hash, basename($photo_url), 'Contact Photos', 5);
-
- $img->scaleImage(48);
- $r = $img->store(0, $contact['uid'], $contact['id'], $hash, basename($photo_url), '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.'.$img->getExt()),
- dbesc($a->get_baseurl() . '/photo/' . $hash . '-5.'.$img->getExt()),
- dbesc($a->get_baseurl() . '/photo/' . $hash . '-6.'.$img->getExt()),
- intval($contact['uid']),
- intval($contact['id'])
- );
- }
- }
-
- if((is_array($contact)) && ($name_updated) && (strlen($new_name)) && ($name_updated > $contact['name_date'])) {
- $r = q("select * from contact where uid = %d and id = %d limit 1",
- intval($contact['uid']),
- intval($contact['id'])
- );
-
- $x = q("UPDATE `contact` SET `name` = '%s', `name_date` = '%s' WHERE `uid` = %d AND `id` = %d LIMIT 1",
- dbesc(notags(trim($new_name))),
- dbesc(datetime_convert()),
- intval($contact['uid']),
- intval($contact['id'])
- );
-
- // do our best to update the name on content items
-
- if(count($r)) {
- q("update item set `author-name` = '%s' where `author-name` = '%s' and `author-link` = '%s' and uid = %d",
- dbesc(notags(trim($new_name))),
- dbesc($r[0]['name']),
- dbesc($r[0]['url']),
- intval($contact['uid'])
- );
- }
- }
-
- 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 = sprintf( t('%s\'s birthday'), $contact['name']);
- $bdtext2 = sprintf( t('Happy Birthday %s'), ' [zrl=' . $contact['url'] . ']' . $contact['name'] . '[/zrl]' ) ;
-
-
- $r = q("INSERT INTO `event` (`uid`,`cid`,`created`,`edited`,`start`,`finish`,`summary`,`desc`,`type`)
- VALUES ( %d, %d, '%s', '%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($bdtext2),
- 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);
- }
-
- }
-
- $community_page = 0;
- $rawtags = $feed->get_feed_tags( NAMESPACE_DFRN, 'community');
- if($rawtags) {
- $community_page = intval($rawtags[0]['data']);
- }
- if(is_array($contact) && intval($contact['forum']) != $community_page) {
- q("update contact set forum = %d where id = %d limit 1",
- intval($community_page),
- intval($contact['id'])
- );
- $contact['forum'] = (string) $community_page;
- }
-
// process any deleted entries
@@ -2700,57 +2530,24 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0)
$when = datetime_convert('UTC','UTC','now','Y-m-d H:i:s');
}
if($deleted && is_array($contact)) {
- $r = q("SELECT `item`.*, `contact`.`self` FROM `item` left join `contact` on `item`.`contact-id` = `contact`.`id`
+/* $r = q("SELECT `item`.*, `contact`.`self` FROM `item` left join `contact` on `item`.`contact-id` = `contact`.`id`
WHERE `mid` = '%s' AND `item`.`uid` = %d AND `contact-id` = %d AND NOT `item`.`file` LIKE '%%[%%' LIMIT 1",
dbesc($mid),
intval($importer['uid']),
intval($contact['id'])
);
+*/
if(count($r)) {
$item = $r[0];
if(! $item['deleted'])
logger('consume_feed: deleting item ' . $item['id'] . ' mid=' . $item['mid'], LOGGER_DEBUG);
- if(($item['verb'] === ACTIVITY_TAG) && ($item['obj_type'] === ACTIVITY_OBJ_TAGTERM)) {
- $xo = parse_xml_string($item['object'],false);
- $xt = parse_xml_string($item['target'],false);
- if($xt->type === ACTIVITY_OBJ_NOTE) {
- $i = q("select * from `item` where mid = '%s' and uid = %d limit 1",
- dbesc($xt->id),
- intval($importer['importer_uid'])
- );
- if(count($i)) {
-
- // For tags, the owner cannot remove the tag on the author's copy of the post.
-
- $owner_remove = (($item['contact-id'] == $i[0]['contact-id']) ? true: false);
- $author_remove = (($item['origin'] && $item['self']) ? true : false);
- $author_copy = (($item['origin']) ? true : false);
-
- if($owner_remove && $author_copy)
- continue;
- if($author_remove || $owner_remove) {
- $tags = explode(',',$i[0]['tag']);
- $newtags = array();
- if(count($tags)) {
- foreach($tags as $tag)
- if(trim($tag) !== trim($xo->body))
- $newtags[] = trim($tag);
- }
- q("update item set tag = '%s' where id = %d limit 1",
- dbesc(implode(',',$newtags)),
- intval($i[0]['id'])
- );
- }
- }
- }
- }
-
if($item['mid'] == $item['parent_mid']) {
- $r = q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s',
+ $r = q("UPDATE `item` SET item_restrict = (item_restrict | %d), `edited` = '%s', `changed` = '%s',
`body` = '', `title` = ''
WHERE `parent_mid` = '%s' AND `uid` = %d",
+ intval(ITEM_DELETED),
dbesc($when),
dbesc(datetime_convert()),
dbesc($item['mid']),
@@ -2758,9 +2555,10 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0)
);
}
else {
- $r = q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s',
+ $r = q("UPDATE `item` SET item_restrict = ( item_restrict | %d ), `edited` = '%s', `changed` = '%s',
`body` = '', `title` = ''
WHERE `mid` = '%s' AND `uid` = %d LIMIT 1",
+ intval(ITEM_DELETED),
dbesc($when),
dbesc(datetime_convert()),
dbesc($mid),
@@ -2795,15 +2593,15 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0)
$parent_mid = $rawthread[0]['attribs']['']['ref'];
}
- if(($is_reply) && is_array($contact)) {
+ if($is_reply) {
if($pass == 1)
continue;
// not allowed to post
-
- if($contact['rel'] == CONTACT_IS_FOLLOWER)
- continue;
+// FIXME - check permissions
+// if($contact['rel'] == CONTACT_IS_FOLLOWER)
+// continue;
// Have we seen it? If not, import it.
@@ -3032,1114 +2830,6 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0)
}
}
-function local_delivery($importer,$data) {
-
- $a = get_app();
-
- if($importer['readonly']) {
- // We aren't receiving stuff from this person. But we will quietly ignore them
- // rather than a blatant "go away" message.
- logger('local_delivery: ignoring');
- return 0;
- //NOTREACHED
- }
-
- // Consume notification feed. This may differ from consuming a public feed in several ways
- // - might contain email or friend suggestions
- // - might contain remote followup to our message
- // - in which case we need to accept it and then notify other conversants
- // - we may need to send various email notifications
-
- $feed = new SimplePie();
- $feed->set_raw_data($data);
- $feed->enable_order_by_date(false);
- $feed->init();
-
-
- if($feed->error())
- logger('local_delivery: Error parsing XML: ' . $feed->error());
-
-
- // Check at the feed level for updated contact name and/or photo
-
- $name_updated = '';
- $new_name = '';
- $photo_timestamp = '';
- $photo_url = '';
-
-
- $rawtags = $feed->get_feed_tags( NAMESPACE_DFRN, 'owner');
- if(! $rawtags)
- $rawtags = $feed->get_feed_tags( SIMPLEPIE_NAMESPACE_ATOM_10, 'author');
- if($rawtags) {
- $elems = $rawtags[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10];
- if($elems['name'][0]['attribs'][NAMESPACE_DFRN]['updated']) {
- $name_updated = $elems['name'][0]['attribs'][NAMESPACE_DFRN]['updated'];
- $new_name = $elems['name'][0]['data'];
- }
- if((x($elems,'link')) && ($elems['link'][0]['attribs']['']['rel'] === 'photo') && ($elems['link'][0]['attribs'][NAMESPACE_DFRN]['updated'])) {
- $photo_timestamp = datetime_convert('UTC','UTC',$elems['link'][0]['attribs'][NAMESPACE_DFRN]['updated']);
- $photo_url = $elems['link'][0]['attribs']['']['href'];
- }
- }
-
- if(($photo_timestamp) && (strlen($photo_url)) && ($photo_timestamp > $importer['avatar_date'])) {
- logger('local_delivery: Updating photo for ' . $importer['name']);
-
- $photo_failure = false;
- $have_photo = false;
-
- $r = q("SELECT `resource_id` FROM `photo` WHERE `contact-id` = %d AND `uid` = %d LIMIT 1",
- intval($importer['id']),
- intval($importer['importer_uid'])
- );
- if(count($r)) {
- $resource_id = $r[0]['resource_id'];
- $have_photo = true;
- }
- else {
- $resource_id = photo_new_resource();
- }
-
- $img_str = fetch_url($photo_url,true);
- // guess mimetype from headers or filename
- $type = guess_image_type($photo_url,true);
-
-
- $img = photo_factory($img_str, $type);
- 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($importer['id']),
- intval($importer['importer_uid'])
- );
- }
-
- $img->scaleImageSquare(175);
-
- $hash = $resource_id;
- $r = $img->store($importer['importer_uid'], $importer['id'], $hash, basename($photo_url), 'Contact Photos', 4);
-
- $img->scaleImage(80);
- $r = $img->store($importer['importer_uid'], $importer['id'], $hash, basename($photo_url), 'Contact Photos', 5);
-
- $img->scaleImage(48);
- $r = $img->store($importer['importer_uid'], $importer['id'], $hash, basename($photo_url), '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.'.$img->getExt()),
- dbesc($a->get_baseurl() . '/photo/' . $hash . '-5.'.$img->getExt()),
- dbesc($a->get_baseurl() . '/photo/' . $hash . '-6.'.$img->getExt()),
- intval($importer['importer_uid']),
- intval($importer['id'])
- );
- }
- }
-
- if(($name_updated) && (strlen($new_name)) && ($name_updated > $importer['name_date'])) {
- $r = q("select * from contact where uid = %d and id = %d limit 1",
- intval($importer['importer_uid']),
- intval($importer['id'])
- );
-
- $x = q("UPDATE `contact` SET `name` = '%s', `name_date` = '%s' WHERE `uid` = %d AND `id` = %d LIMIT 1",
- dbesc(notags(trim($new_name))),
- dbesc(datetime_convert()),
- intval($importer['importer_uid']),
- intval($importer['id'])
- );
-
- // do our best to update the name on content items
-
- if(count($r)) {
- q("update item set `author-name` = '%s' where `author-name` = '%s' and `author-link` = '%s' and uid = %d",
- dbesc(notags(trim($new_name))),
- dbesc($r[0]['name']),
- dbesc($r[0]['url']),
- intval($importer['importer_uid'])
- );
- }
- }
-
-
-/*
- // Currently unsupported - needs a lot of work
- $reloc = $feed->get_feed_tags( NAMESPACE_DFRN, 'relocate' );
- if(isset($reloc[0]['child'][NAMESPACE_DFRN])) {
- $base = $reloc[0]['child'][NAMESPACE_DFRN];
- $newloc = array();
- $newloc['uid'] = $importer['importer_uid'];
- $newloc['cid'] = $importer['id'];
- $newloc['name'] = notags(unxmlify($base['name'][0]['data']));
- $newloc['photo'] = notags(unxmlify($base['photo'][0]['data']));
- $newloc['url'] = notags(unxmlify($base['url'][0]['data']));
- $newloc['request'] = notags(unxmlify($base['request'][0]['data']));
- $newloc['confirm'] = notags(unxmlify($base['confirm'][0]['data']));
- $newloc['notify'] = notags(unxmlify($base['notify'][0]['data']));
- $newloc['poll'] = notags(unxmlify($base['poll'][0]['data']));
- $newloc['site_pubkey'] = notags(unxmlify($base['site_pubkey'][0]['data']));
- $newloc['pubkey'] = notags(unxmlify($base['pubkey'][0]['data']));
- $newloc['prvkey'] = notags(unxmlify($base['prvkey'][0]['data']));
-
- // TODO
- // merge with current record, current contents have priority
- // update record, set url-updated
- // update profile photos
- // schedule a scan?
-
- }
-*/
-
- // handle friend suggestion notification
-
- $sugg = $feed->get_feed_tags( NAMESPACE_DFRN, 'suggest' );
- if(isset($sugg[0]['child'][NAMESPACE_DFRN])) {
- $base = $sugg[0]['child'][NAMESPACE_DFRN];
- $fsugg = array();
- $fsugg['uid'] = $importer['importer_uid'];
- $fsugg['cid'] = $importer['id'];
- $fsugg['name'] = notags(unxmlify($base['name'][0]['data']));
- $fsugg['photo'] = notags(unxmlify($base['photo'][0]['data']));
- $fsugg['url'] = notags(unxmlify($base['url'][0]['data']));
- $fsugg['request'] = notags(unxmlify($base['request'][0]['data']));
- $fsugg['body'] = escape_tags(unxmlify($base['note'][0]['data']));
-
- // Does our member already have a friend matching this description?
-
- $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `nurl` = '%s' AND `uid` = %d LIMIT 1",
- dbesc($fsugg['name']),
- dbesc(normalise_link($fsugg['url'])),
- intval($fsugg['uid'])
- );
- if(count($r))
- return 0;
-
- // Do we already have an fcontact record for this person?
-
- $fid = 0;
- $r = q("SELECT * FROM `fcontact` WHERE `url` = '%s' AND `name` = '%s' AND `request` = '%s' LIMIT 1",
- dbesc($fsugg['url']),
- dbesc($fsugg['name']),
- dbesc($fsugg['request'])
- );
- if(count($r)) {
- $fid = $r[0]['id'];
-
- // OK, we do. Do we already have an introduction for this person ?
- $r = q("select id from intro where uid = %d and fid = %d limit 1",
- intval($fsugg['uid']),
- intval($fid)
- );
- if(count($r))
- return 0;
- }
- if(! $fid)
- $r = q("INSERT INTO `fcontact` ( `name`,`url`,`photo`,`request` ) VALUES ( '%s', '%s', '%s', '%s' ) ",
- dbesc($fsugg['name']),
- dbesc($fsugg['url']),
- dbesc($fsugg['photo']),
- dbesc($fsugg['request'])
- );
- $r = q("SELECT * FROM `fcontact` WHERE `url` = '%s' AND `name` = '%s' AND `request` = '%s' LIMIT 1",
- dbesc($fsugg['url']),
- dbesc($fsugg['name']),
- dbesc($fsugg['request'])
- );
- if(count($r)) {
- $fid = $r[0]['id'];
- }
- // database record did not get created. Quietly give up.
- else
- return 0;
-
-
- $hash = random_string();
-
- $r = q("INSERT INTO `intro` ( `uid`, `fid`, `contact-id`, `note`, `hash`, `datetime`, `blocked` )
- VALUES( %d, %d, %d, '%s', '%s', '%s', %d )",
- intval($fsugg['uid']),
- intval($fid),
- intval($fsugg['cid']),
- dbesc($fsugg['body']),
- dbesc($hash),
- dbesc(datetime_convert()),
- intval(0)
- );
-
- notification(array(
- 'type' => NOTIFY_SUGGEST,
- 'notify_flags' => $importer['notify-flags'],
- 'language' => $importer['language'],
- 'to_name' => $importer['username'],
- 'to_email' => $importer['email'],
- 'uid' => $importer['importer_uid'],
- 'item' => $fsugg,
- 'link' => $a->get_baseurl() . '/notifications/intros',
- 'source_name' => $importer['name'],
- 'source_link' => $importer['url'],
- 'source_photo' => $importer['photo'],
- 'verb' => ACTIVITY_REQ_FRIEND,
- 'otype' => 'intro'
- ));
-
- return 0;
- }
-
- $ismail = false;
-
- $rawmail = $feed->get_feed_tags( NAMESPACE_DFRN, 'mail' );
- if(isset($rawmail[0]['child'][NAMESPACE_DFRN])) {
-
- logger('local_delivery: private message received');
-
- $ismail = true;
- $base = $rawmail[0]['child'][NAMESPACE_DFRN];
-
- $msg = array();
- $msg['uid'] = $importer['importer_uid'];
- $msg['from-name'] = notags(unxmlify($base['sender'][0]['child'][NAMESPACE_DFRN]['name'][0]['data']));
- $msg['from-photo'] = notags(unxmlify($base['sender'][0]['child'][NAMESPACE_DFRN]['avatar'][0]['data']));
- $msg['from-url'] = notags(unxmlify($base['sender'][0]['child'][NAMESPACE_DFRN]['uri'][0]['data']));
- $msg['contact-id'] = $importer['id'];
- $msg['title'] = notags(unxmlify($base['subject'][0]['data']));
- $msg['body'] = escape_tags(unxmlify($base['content'][0]['data']));
- $msg['seen'] = 0;
- $msg['replied'] = 0;
- $msg['mid'] = notags(unxmlify($base['id'][0]['data']));
- $msg['parent_mid'] = notags(unxmlify($base['in-reply-to'][0]['data']));
- $msg['created'] = datetime_convert(notags(unxmlify('UTC','UTC',$base['sentdate'][0]['data'])));
-
- dbesc_array($msg);
-
- $r = dbq("INSERT INTO `mail` (`" . implode("`, `", array_keys($msg))
- . "`) VALUES ('" . implode("', '", array_values($msg)) . "')" );
-
- // send notifications.
-
- require_once('include/enotify.php');
-
- $notif_params = array(
- 'type' => NOTIFY_MAIL,
- 'notify_flags' => $importer['notify-flags'],
- 'language' => $importer['language'],
- 'to_name' => $importer['username'],
- 'to_email' => $importer['email'],
- 'uid' => $importer['importer_uid'],
- 'item' => $msg,
- 'source_name' => $msg['from-name'],
- 'source_link' => $importer['url'],
- 'source_photo' => $importer['thumb'],
- 'verb' => ACTIVITY_POST,
- 'otype' => 'mail'
- );
-
- notification($notif_params);
- return 0;
-
- // NOTREACHED
- }
-
- $community_page = 0;
- $rawtags = $feed->get_feed_tags( NAMESPACE_DFRN, 'community');
- if($rawtags) {
- $community_page = intval($rawtags[0]['data']);
- }
- if(intval($importer['forum']) != $community_page) {
- q("update contact set forum = %d where id = %d limit 1",
- intval($community_page),
- intval($importer['id'])
- );
- $importer['forum'] = (string) $community_page;
- }
-
- logger('local_delivery: feed item count = ' . $feed->get_item_quantity());
-
- // process any deleted entries
-
- $del_entries = $feed->get_feed_tags(NAMESPACE_TOMB, 'deleted-entry');
- if(is_array($del_entries) && count($del_entries)) {
- foreach($del_entries as $dentry) {
- $deleted = false;
- if(isset($dentry['attribs']['']['ref'])) {
- $mid = $dentry['attribs']['']['ref'];
- $deleted = true;
- if(isset($dentry['attribs']['']['when'])) {
- $when = $dentry['attribs']['']['when'];
- $when = datetime_convert('UTC','UTC', $when, 'Y-m-d H:i:s');
- }
- else
- $when = datetime_convert('UTC','UTC','now','Y-m-d H:i:s');
- }
- if($deleted) {
-
- // check for relayed deletes to our conversation
-
- $is_reply = false;
- $r = q("select * from item where mid = '%s' and uid = %d limit 1",
- dbesc($mid),
- intval($importer['importer_uid'])
- );
- if(count($r)) {
- $parent_mid = $r[0]['parent_mid'];
- if($r[0]['id'] != $r[0]['parent'])
- $is_reply = true;
- }
-
- if($is_reply) {
- $community = false;
-
- if($importer['page-flags'] == PAGE_COMMUNITY || $importer['page-flags'] == PAGE_PRVGROUP ) {
- $sql_extra = '';
- $community = true;
- logger('local_delivery: possible community delete');
- }
- else
- $sql_extra = " and contact.self = 1 and item.wall = 1 ";
-
- // was the top-level post for this reply written by somebody on this site?
- // Specifically, the recipient?
-
- $is_a_remote_delete = false;
-
- $r = q("select `item`.`id`, `item`.`mid`, `item`.`forum_mode`,`item`.`origin`,`item`.`wall`,
- `contact`.`name`, `contact`.`url`, `contact`.`thumb` from `item`
- LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
- WHERE `item`.`mid` = '%s' AND (`item`.`parent_mid` = '%s' or `item`.`thr_parent` = '%s')
- AND `item`.`uid` = %d
- $sql_extra
- LIMIT 1",
- dbesc($parent_mid),
- dbesc($parent_mid),
- dbesc($parent_mid),
- intval($importer['importer_uid'])
- );
- if($r && count($r))
- $is_a_remote_delete = true;
-
- // Does this have the characteristics of a community or private group comment?
- // If it's a reply to a wall post on a community/prvgroup page it's a
- // valid community comment. Also forum_mode makes it valid for sure.
- // If neither, it's not.
-
- if($is_a_remote_delete && $community) {
- if((! $r[0]['forum_mode']) && (! $r[0]['wall'])) {
- $is_a_remote_delete = false;
- logger('local_delivery: not a community delete');
- }
- }
-
- if($is_a_remote_delete) {
- logger('local_delivery: received remote delete');
- }
- }
-
- $r = q("SELECT `item`.*, `contact`.`self` FROM `item` left join contact on `item`.`contact-id` = `contact`.`id`
- WHERE `mid` = '%s' AND `item`.`uid` = %d AND `contact-id` = %d AND NOT `item`.`file` LIKE '%%[%%' LIMIT 1",
- dbesc($mid),
- intval($importer['importer_uid']),
- intval($importer['id'])
- );
-
- if(count($r)) {
- $item = $r[0];
-
- if($item['deleted'])
- continue;
-
- logger('local_delivery: deleting item ' . $item['id'] . ' mid=' . $item['mid'], LOGGER_DEBUG);
-
- if(($item['verb'] === ACTIVITY_TAG) && ($item['obj_type'] === ACTIVITY_OBJ_TAGTERM)) {
- $xo = parse_xml_string($item['object'],false);
- $xt = parse_xml_string($item['target'],false);
-
- if($xt->type === ACTIVITY_OBJ_NOTE) {
- $i = q("select * from `item` where mid = '%s' and uid = %d limit 1",
- dbesc($xt->id),
- intval($importer['importer_uid'])
- );
- if(count($i)) {
-
- // For tags, the owner cannot remove the tag on the author's copy of the post.
-
- $owner_remove = (($item['contact-id'] == $i[0]['contact-id']) ? true: false);
- $author_remove = (($item['origin'] && $item['self']) ? true : false);
- $author_copy = (($item['origin']) ? true : false);
-
- if($owner_remove && $author_copy)
- continue;
- if($author_remove || $owner_remove) {
-//FIXME
- $tags = explode(',',$i[0]['tag']);
- $newtags = array();
- if(count($tags)) {
- foreach($tags as $tag)
- if(trim($tag) !== trim($xo->body))
- $newtags[] = trim($tag);
- }
- q("update item set tag = '%s' where id = %d limit 1",
- dbesc(implode(',',$newtags)),
- intval($i[0]['id'])
- );
- }
- }
- }
- }
-
- if($item['mid'] == $item['parent_mid']) {
- $r = q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s',
- `body` = '', `title` = ''
- WHERE `parent_mid` = '%s' AND `uid` = %d",
- dbesc($when),
- dbesc(datetime_convert()),
- dbesc($item['mid']),
- intval($importer['importer_uid'])
- );
- }
- else {
- $r = q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s',
- `body` = '', `title` = ''
- WHERE `mid` = '%s' AND `uid` = %d LIMIT 1",
- dbesc($when),
- dbesc(datetime_convert()),
- dbesc($mid),
- intval($importer['importer_uid'])
- );
-
- // if this is a relayed delete, propagate it to other recipients
-
- if($is_a_remote_delete)
- proc_run('php',"include/notifier.php","drop",$item['id']);
- }
- }
- }
- }
- }
-
-
- foreach($feed->get_items() as $item) {
-
- $is_reply = false;
- $item_id = $item->get_id();
- $rawthread = $item->get_item_tags( NAMESPACE_THREAD, 'in-reply-to');
- if(isset($rawthread[0]['attribs']['']['ref'])) {
- $is_reply = true;
- $parent_mid = $rawthread[0]['attribs']['']['ref'];
- }
-
- if($is_reply) {
- $community = false;
-
- if($importer['page-flags'] == PAGE_COMMUNITY || $importer['page-flags'] == PAGE_PRVGROUP ) {
- $sql_extra = '';
- $community = true;
- logger('local_delivery: possible community reply');
- }
- else
- $sql_extra = " and contact.self = 1 and item.wall = 1 ";
-
- // was the top-level post for this reply written by somebody on this site?
- // Specifically, the recipient?
-
- $is_a_remote_comment = false;
-
- // POSSIBLE CLEANUP --> Why select so many fields when only forum_mode and wall are used?
- $r = q("select `item`.`id`, `item`.`mid`, `item`.`forum_mode`,`item`.`origin`,`item`.`wall`,
- `contact`.`name`, `contact`.`url`, `contact`.`thumb` from `item`
- LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
- WHERE `item`.`mid` = '%s' AND (`item`.`parent_mid` = '%s' or `item`.`thr_parent` = '%s')
- AND `item`.`uid` = %d
- $sql_extra
- LIMIT 1",
- dbesc($parent_mid),
- dbesc($parent_mid),
- dbesc($parent_mid),
- intval($importer['importer_uid'])
- );
- if($r && count($r))
- $is_a_remote_comment = true;
-
- // Does this have the characteristics of a community or private group comment?
- // If it's a reply to a wall post on a community/prvgroup page it's a
- // valid community comment. Also forum_mode makes it valid for sure.
- // If neither, it's not.
-
- if($is_a_remote_comment && $community) {
- if((! $r[0]['forum_mode']) && (! $r[0]['wall'])) {
- $is_a_remote_comment = false;
- logger('local_delivery: not a community reply');
- }
- }
-
- if($is_a_remote_comment) {
- logger('local_delivery: received remote comment');
- $is_like = false;
- // remote reply to our post. Import and then notify everybody else.
-
- $datarray = get_atom_elements($feed,$item);
-
- $r = q("SELECT `id`, `uid`, `edited`, `body` FROM `item` WHERE `mid` = '%s' AND `uid` = %d LIMIT 1",
- dbesc($item_id),
- intval($importer['importer_uid'])
- );
-
- // Update content if 'updated' changes
-
- if(count($r)) {
- $iid = $r[0]['id'];
- if((x($datarray,'edited') !== false) && (datetime_convert('UTC','UTC',$datarray['edited']) !== $r[0]['edited'])) {
-
- // do not accept (ignore) an earlier edit than one we currently have.
- if(datetime_convert('UTC','UTC',$datarray['edited']) < $r[0]['edited'])
- continue;
-
- logger('received updated comment' , LOGGER_DEBUG);
- $r = q("UPDATE `item` SET `title` = '%s', `body` = '%s', `edited` = '%s' WHERE `mid` = '%s' AND `uid` = %d LIMIT 1",
- dbesc($datarray['title']),
- dbesc($datarray['body']),
- dbesc(datetime_convert('UTC','UTC',$datarray['edited'])),
- dbesc($item_id),
- intval($importer['importer_uid'])
- );
-
- proc_run('php',"include/notifier.php","comment-import",$iid);
-
- }
-
- continue;
- }
-
-
-
- $own = q("select name,url,thumb from contact where uid = %d and self = 1 limit 1",
- intval($importer['importer_uid'])
- );
-
-
- $datarray['type'] = 'remote-comment';
- $datarray['wall'] = 1;
- $datarray['parent_mid'] = $parent_mid;
- $datarray['uid'] = $importer['importer_uid'];
- $datarray['owner-name'] = $own[0]['name'];
- $datarray['owner-link'] = $own[0]['url'];
- $datarray['owner-avatar'] = $own[0]['thumb'];
- $datarray['contact-id'] = $importer['id'];
-
- if(($datarray['verb'] === ACTIVITY_LIKE) || ($datarray['verb'] === ACTIVITY_DISLIKE)) {
- $is_like = true;
- $datarray['type'] = 'activity';
- $datarray['gravity'] = GRAVITY_LIKE;
-
- // only one like or dislike per person
- $r = q("select id from item where uid = %d and `contact-id` = %d and verb = '%s' and (`thr_parent` = '%s' or `parent_mid` = '%s') and deleted = 0 limit 1",
- intval($datarray['uid']),
- intval($datarray['contact-id']),
- dbesc($datarray['verb']),
- dbesc($datarray['parent_mid']),
- dbesc($datarray['parent_mid'])
-
- );
- if($r && count($r))
- continue;
- }
-
- if(($datarray['verb'] === ACTIVITY_TAG) && ($datarray['obj_type'] === ACTIVITY_OBJ_TAGTERM)) {
-
- $xo = parse_xml_string($datarray['object'],false);
- $xt = parse_xml_string($datarray['target'],false);
-
- if(($xt->type == ACTIVITY_OBJ_NOTE) && ($xt->id)) {
-
- // fetch the parent item
-
- $tagp = q("select * from item where mid = '%s' and uid = %d limit 1",
- dbesc($xt->id),
- intval($importer['importer_uid'])
- );
- if(! count($tagp))
- continue;
-
- // extract tag, if not duplicate, and this user allows tags, add to parent item
-//FIXME
- if($xo->id && $xo->content) {
- $newtag = '#[zrl=' . $xo->id . ']'. $xo->content . '[/zrl]';
- if(! (stristr($tagp[0]['tag'],$newtag))) {
- $i = q("SELECT `blocktags` FROM `user` where `uid` = %d LIMIT 1",
- intval($importer['importer_uid'])
- );
- if(count($i) && ! intval($i[0]['blocktags'])) {
- q("UPDATE item SET tag = '%s', `edited` = '%s' WHERE id = %d LIMIT 1",
- dbesc($tagp[0]['tag'] . (strlen($tagp[0]['tag']) ? ',' : '') . $newtag),
- intval($tagp[0]['id']),
- dbesc(datetime_convert())
- );
- }
- }
- }
- }
- }
-
-
- $posted_id = item_store($datarray);
- $parent = 0;
-
- if($posted_id) {
- $r = q("SELECT `parent`, `parent_mid` FROM `item` WHERE `id` = %d AND `uid` = %d LIMIT 1",
- intval($posted_id),
- intval($importer['importer_uid'])
- );
- if(count($r)) {
- $parent = $r[0]['parent'];
- $parent_mid = $r[0]['parent_mid'];
- }
-
- if(! $is_like) {
- $r1 = q("UPDATE `item` SET `changed` = '%s' WHERE `uid` = %d AND `parent` = %d",
- dbesc(datetime_convert()),
- intval($importer['importer_uid']),
- intval($r[0]['parent'])
- );
-
- $r2 = q("UPDATE `item` SET `changed` = '%s' WHERE `uid` = %d AND `id` = %d LIMIT 1",
- dbesc(datetime_convert()),
- intval($importer['importer_uid']),
- intval($posted_id)
- );
- }
-
- if($posted_id && $parent) {
-
- proc_run('php',"include/notifier.php","comment-import","$posted_id");
-
- if((! $is_like) && (! $importer['self'])) {
-
- require_once('include/enotify.php');
-
- notification(array(
- 'type' => NOTIFY_COMMENT,
- 'notify_flags' => $importer['notify-flags'],
- 'language' => $importer['language'],
- 'to_name' => $importer['username'],
- 'to_email' => $importer['email'],
- 'uid' => $importer['importer_uid'],
- 'item' => $datarray,
- 'link' => $a->get_baseurl() . '/display/' . $importer['nickname'] . '/' . $posted_id,
- 'source_name' => stripslashes($datarray['author-name']),
- 'source_link' => $datarray['author-link'],
- 'source_photo' => ((link_compare($datarray['author-link'],$importer['url']))
- ? $importer['thumb'] : $datarray['author-avatar']),
- 'verb' => ACTIVITY_POST,
- 'otype' => 'item',
- 'parent' => $parent,
- 'parent_mid' => $parent_mid,
- ));
-
- }
- }
-
- return 0;
- // NOTREACHED
- }
- }
- else {
-
- // regular comment that is part of this total conversation. Have we seen it? If not, import it.
-
- $item_id = $item->get_id();
- $datarray = get_atom_elements($feed,$item);
-
- if($importer['rel'] == CONTACT_IS_FOLLOWER)
- continue;
-
-
- $r = q("SELECT `uid`, `edited`, `body` FROM `item` WHERE `mid` = '%s' AND `uid` = %d LIMIT 1",
- dbesc($item_id),
- intval($importer['importer_uid'])
- );
-
- // Update content if 'updated' changes
-
- if(count($r)) {
- if((x($datarray,'edited') !== false) && (datetime_convert('UTC','UTC',$datarray['edited']) !== $r[0]['edited'])) {
-
- // do not accept (ignore) an earlier edit than one we currently have.
- if(datetime_convert('UTC','UTC',$datarray['edited']) < $r[0]['edited'])
- continue;
-
- $r = q("UPDATE `item` SET `title` = '%s', `body` = '%s', `edited` = '%s' WHERE `mid` = '%s' AND `uid` = %d LIMIT 1",
- dbesc($datarray['title']),
- dbesc($datarray['body']),
- dbesc(datetime_convert('UTC','UTC',$datarray['edited'])),
- dbesc($item_id),
- intval($importer['importer_uid'])
- );
- }
-
- continue;
- }
-
- $datarray['parent_mid'] = $parent_mid;
- $datarray['uid'] = $importer['importer_uid'];
- $datarray['contact-id'] = $importer['id'];
- if(($datarray['verb'] == ACTIVITY_LIKE) || ($datarray['verb'] == ACTIVITY_DISLIKE)) {
- $datarray['type'] = 'activity';
- $datarray['gravity'] = GRAVITY_LIKE;
- // only one like or dislike per person
- $r = q("select id from item where uid = %d and `contact-id` = %d and verb ='%s' and deleted = 0 and (`parent_mid` = '%s' OR `thr_parent` = '%s') limit 1",
- intval($datarray['uid']),
- intval($datarray['contact-id']),
- dbesc($datarray['verb']),
- dbesc($parent_mid),
- dbesc($parent_mid)
- );
- if($r && count($r))
- continue;
-
- }
-
- if(($datarray['verb'] === ACTIVITY_TAG) && ($datarray['obj_type'] === ACTIVITY_OBJ_TAGTERM)) {
-
- $xo = parse_xml_string($datarray['object'],false);
- $xt = parse_xml_string($datarray['target'],false);
-
- if($xt->type == ACTIVITY_OBJ_NOTE) {
- $r = q("select * from item where `mid` = '%s' AND `uid` = %d limit 1",
- dbesc($xt->id),
- intval($importer['importer_uid'])
- );
- if(! count($r))
- continue;
-
- // extract tag, if not duplicate, add to parent item
- if($xo->content) {
- if(! (stristr($r[0]['tag'],trim($xo->content)))) {
- q("UPDATE item SET tag = '%s' WHERE id = %d LIMIT 1",
- dbesc($r[0]['tag'] . (strlen($r[0]['tag']) ? ',' : '') . '#[zrl=' . $xo->id . ']'. $xo->content . '[/zrl]'),
- intval($r[0]['id'])
- );
- }
- }
- }
- }
-
- $posted_id = item_store($datarray);
-
- // find out if our user is involved in this conversation and wants to be notified.
-
- if(!x($datarray['type']) || $datarray['type'] != 'activity') {
-
- $myconv = q("SELECT `author-link`, `author-avatar`, `parent` FROM `item` WHERE `parent_mid` = '%s' AND `uid` = %d AND `parent` != 0 AND `deleted` = 0",
- dbesc($parent_mid),
- intval($importer['importer_uid'])
- );
-
- if(count($myconv)) {
- $importer_url = $a->get_baseurl() . '/channel/' . $importer['nickname'];
-
- // first make sure this isn't our own post coming back to us from a wall-to-wall event
- if(! link_compare($datarray['author-link'],$importer_url)) {
-
-
- foreach($myconv as $conv) {
-
- // now if we find a match, it means we're in this conversation
-
- if(! link_compare($conv['author-link'],$importer_url))
- continue;
-
- require_once('include/enotify.php');
-
- $conv_parent = $conv['parent'];
-
- notification(array(
- 'type' => NOTIFY_COMMENT,
- 'notify_flags' => $importer['notify-flags'],
- 'language' => $importer['language'],
- 'to_name' => $importer['username'],
- 'to_email' => $importer['email'],
- 'uid' => $importer['importer_uid'],
- 'item' => $datarray,
- 'link' => $a->get_baseurl() . '/display/' . $importer['nickname'] . '/' . $posted_id,
- 'source_name' => stripslashes($datarray['author-name']),
- 'source_link' => $datarray['author-link'],
- 'source_photo' => ((link_compare($datarray['author-link'],$importer['url']))
- ? $importer['thumb'] : $datarray['author-avatar']),
- 'verb' => ACTIVITY_POST,
- 'otype' => 'item',
- 'parent' => $conv_parent,
- 'parent_mid' => $parent_mid
-
- ));
-
- // only send one notification
- break;
- }
- }
- }
- }
- continue;
- }
- }
-
- else {
-
- // Head post of a conversation. Have we seen it? If not, import it.
-
-
- $item_id = $item->get_id();
- $datarray = get_atom_elements($feed,$item);
-
- if((x($datarray,'obj_type')) && ($datarray['obj_type'] === ACTIVITY_OBJ_EVENT)) {
- $ev = bbtoevent($datarray['body']);
- if(x($ev,'desc') && x($ev,'start')) {
- $ev['cid'] = $importer['id'];
- $ev['uid'] = $importer['uid'];
- $ev['mid'] = $item_id;
- $ev['edited'] = $datarray['edited'];
- $ev['private'] = $datarray['private'];
-
- $r = q("SELECT * FROM `event` WHERE `mid` = '%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`, `edited`, `body` FROM `item` WHERE `mid` = '%s' AND `uid` = %d LIMIT 1",
- dbesc($item_id),
- intval($importer['importer_uid'])
- );
-
- // Update content if 'updated' changes
-
- if(count($r)) {
- if((x($datarray,'edited') !== false) && (datetime_convert('UTC','UTC',$datarray['edited']) !== $r[0]['edited'])) {
-
- // do not accept (ignore) an earlier edit than one we currently have.
- if(datetime_convert('UTC','UTC',$datarray['edited']) < $r[0]['edited'])
- continue;
-
- $r = q("UPDATE `item` SET `title` = '%s', `body` = '%s', `edited` = '%s' WHERE `mid` = '%s' AND `uid` = %d LIMIT 1",
- dbesc($datarray['title']),
- dbesc($datarray['body']),
- dbesc(datetime_convert('UTC','UTC',$datarray['edited'])),
- dbesc($item_id),
- intval($importer['importer_uid'])
- );
- }
-
- continue;
- }
-
- // This is my contact on another system, but it's really me.
- // Turn this into a wall post.
-
- if($importer['remote_self'])
- $datarray['wall'] = 1;
-
- $datarray['parent_mid'] = $item_id;
- $datarray['uid'] = $importer['importer_uid'];
- $datarray['contact-id'] = $importer['id'];
-
-
- if(! link_compare($datarray['owner-link'],$importer['url'])) {
- // The item owner info is not our contact. It's OK and is to be expected if this is a tgroup delivery,
- // but otherwise there's a possible data mixup on the sender's system.
- // the tgroup delivery code called from item_store will correct it if it's a forum,
- // but we're going to unconditionally correct it here so that the post will always be owned by our contact.
- logger('local_delivery: Correcting item owner.', LOGGER_DEBUG);
- $datarray['owner-name'] = $importer['senderName'];
- $datarray['owner-link'] = $importer['url'];
- $datarray['owner-avatar'] = $importer['thumb'];
- }
-
- if(($importer['rel'] == CONTACT_IS_FOLLOWER) && (! tgroup_check($importer['importer_uid'],$datarray)))
- continue;
-
- $posted_id = item_store($datarray);
-
- if(stristr($datarray['verb'],ACTIVITY_POKE)) {
- $verb = urldecode(substr($datarray['verb'],strpos($datarray['verb'],'#')+1));
- if(! $verb)
- continue;
- $xo = parse_xml_string($datarray['object'],false);
-
- if(($xo->type == ACTIVITY_OBJ_PERSON) && ($xo->id)) {
-
- // somebody was poked/prodded. Was it me?
-
- $links = parse_xml_string("<links>".unxmlify($xo->link)."</links>",false);
-
- foreach($links->link as $l) {
- $atts = $l->attributes();
- switch($atts['rel']) {
- case "alternate":
- $Blink = $atts['href'];
- break;
- default:
- break;
- }
- }
- if($Blink && link_compare($Blink,$a->get_baseurl() . '/channel/' . $importer['nickname'])) {
-
- // send a notification
- require_once('include/enotify.php');
-
- notification(array(
- 'type' => NOTIFY_POKE,
- 'notify_flags' => $importer['notify-flags'],
- 'language' => $importer['language'],
- 'to_name' => $importer['username'],
- 'to_email' => $importer['email'],
- 'uid' => $importer['importer_uid'],
- 'item' => $datarray,
- 'link' => $a->get_baseurl() . '/display/' . $importer['nickname'] . '/' . $posted_id,
- 'source_name' => stripslashes($datarray['author-name']),
- 'source_link' => $datarray['author-link'],
- 'source_photo' => ((link_compare($datarray['author-link'],$importer['url']))
- ? $importer['thumb'] : $datarray['author-avatar']),
- 'verb' => $datarray['verb'],
- 'otype' => 'person',
- 'activity' => $verb,
-
- ));
- }
- }
- }
-
- continue;
- }
- }
-
- return 0;
- // NOTREACHED
-
-}
-
-
-function new_follower($importer,$contact,$datarray,$item,$sharing = false) {
- $url = notags(trim($datarray['author-link']));
- $name = notags(trim($datarray['author-name']));
- $photo = notags(trim($datarray['author-avatar']));
-
- $rawtag = $item->get_item_tags(NAMESPACE_ACTIVITY,'actor');
- if($rawtag && $rawtag[0]['child'][NAMESPACE_POCO]['preferredUsername'][0]['data'])
- $nick = $rawtag[0]['child'][NAMESPACE_POCO]['preferredUsername'][0]['data'];
-
- if(is_array($contact)) {
- if(($contact['network'] == NETWORK_OSTATUS && $contact['rel'] == CONTACT_IS_SHARING)
- || ($sharing && $contact['rel'] == CONTACT_IS_FOLLOWER)) {
- $r = q("UPDATE `contact` SET `rel` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
- intval(CONTACT_IS_FRIEND),
- intval($contact['id']),
- intval($importer['uid'])
- );
- }
- // send email notification to owner?
- }
- else {
-
- // create contact record
-
- $r = q("INSERT INTO `contact` ( `uid`, `created`, `url`, `nurl`, `name`, `nick`, `photo`, `network`, `rel`,
- `blocked`, `readonly`, `pending`, `writable` )
- VALUES ( %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, 0, 0, 1, 1 ) ",
- intval($importer['uid']),
- dbesc(datetime_convert()),
- dbesc($url),
- dbesc(normalise_link($url)),
- dbesc($name),
- dbesc($nick),
- dbesc($photo),
- dbesc(($sharing) ? NETWORK_ZOT : NETWORK_OSTATUS),
- intval(($sharing) ? CONTACT_IS_SHARING : CONTACT_IS_FOLLOWER)
- );
- $r = q("SELECT `id` FROM `contact` WHERE `uid` = %d AND `url` = '%s' AND `pending` = 1 LIMIT 1",
- intval($importer['uid']),
- dbesc($url)
- );
- if(count($r))
- $contact_record = $r[0];
-
- // create notification
- $hash = random_string();
-
- if(is_array($contact_record)) {
- $ret = q("INSERT INTO `intro` ( `uid`, `contact-id`, `blocked`, `knowyou`, `hash`, `datetime`)
- VALUES ( %d, %d, 0, 0, '%s', '%s' )",
- intval($importer['uid']),
- intval($contact_record['id']),
- dbesc($hash),
- dbesc(datetime_convert())
- );
- }
- $r = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1",
- intval($importer['uid'])
- );
- $a = get_app();
- if(count($r)) {
-
- if(intval($r[0]['def_gid'])) {
- require_once('include/group.php');
- group_add_member($r[0]['uid'],'',$contact_record['id'],$r[0]['def_gid']);
- }
-
- if(($r[0]['notify-flags'] & NOTIFY_INTRO) && ($r[0]['page-flags'] == PAGE_NORMAL)) {
-
- $email_tpl = get_intltext_template('follow_notify_eml.tpl');
- $email = replace_macros($email_tpl, array(
- '$requestor' => ((strlen($name)) ? $name : t('[Name Withheld]')),
- '$url' => $url,
- '$myname' => $r[0]['username'],
- '$siteurl' => $a->get_baseurl(),
- '$sitename' => $a->config['sitename']
- ));
-
- $res = mail($r[0]['email'],
- (($sharing) ? t('A new person is sharing with you at ') : t("You have a new follower at ")) . $a->config['sitename'],
- $email,
- 'From: ' . t('Administrator') . '@' . $_SERVER['SERVER_NAME'] . "\n"
- . 'Content-type: text/plain; charset=UTF-8' . "\n"
- . 'Content-transfer-encoding: 8bit' );
-
- }
- }
- }
-}
-
-function lose_follower($importer,$contact,$datarray,$item) {
-
- if(($contact['rel'] == CONTACT_IS_FRIEND) || ($contact['rel'] == CONTACT_IS_SHARING)) {
- q("UPDATE `contact` SET `rel` = %d WHERE `id` = %d LIMIT 1",
- intval(CONTACT_IS_SHARING),
- intval($contact['id'])
- );
- }
- else {
-// contact_remove($contact['id']);
- }
-}
-
-function lose_sharer($importer,$contact,$datarray,$item) {
-
- if(($contact['rel'] == CONTACT_IS_FRIEND) || ($contact['rel'] == CONTACT_IS_FOLLOWER)) {
- q("UPDATE `contact` SET `rel` = %d WHERE `id` = %d LIMIT 1",
- intval(CONTACT_IS_FOLLOWER),
- intval($contact['id'])
- );
- }
- else {
-// contact_remove($contact['id']);
- }
-}
function atom_author($tag,$name,$uri,$h,$w,$type,$photo) {