X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Fitems.php;h=746e3b2944fc2769ec5090afc83042fe091c0238;hb=0739ae315bdc4d9d8d7c5021d34fc14860431c41;hp=a5d430aa22053a2a88961df0c4d2a981713c4033;hpb=7c60701efc091945dd2ee14728263d8dae0f88b0;p=friendica.git
diff --git a/include/items.php b/include/items.php
index a5d430aa22..746e3b2944 100644
--- a/include/items.php
+++ b/include/items.php
@@ -1,12 +1,12 @@
get_item_tags(NAMESPACE_STATUSNET,'notice_info');
+ if($apps && $apps[0]['attribs']['']['source']) {
+ $res['app'] = strip_tags(unxmlify($apps[0]['attribs']['']['source']));
+ if($res['app'] === 'web')
+ $res['app'] = 'OStatus';
+ }
/**
* If there's a copy of the body content which is guaranteed to have survived mangling in transit, use it.
@@ -479,7 +488,6 @@ function get_atom_elements($feed,$item) {
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();
@@ -514,7 +522,7 @@ function get_atom_elements($feed,$item) {
if(! $type)
$type = 'application/octet-stream';
- $att_arr[] = '[attach]href="' . $link . '" size="' . $len . '" type="' . $type . '" title="' . $title . '"[/attach]';
+ $att_arr[] = '[attach]href="' . $link . '" length="' . $len . '" type="' . $type . '" title="' . $title . '"[/attach]';
}
$res['attach'] = implode(',', $att_arr);
}
@@ -663,6 +671,7 @@ function item_store($arr,$force_parent = false) {
$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['received'] = datetime_convert();
$arr['changed'] = datetime_convert();
$arr['title'] = ((x($arr,'title')) ? notags(trim($arr['title'])) : '');
$arr['location'] = ((x($arr,'location')) ? notags(trim($arr['location'])) : '');
@@ -685,6 +694,8 @@ function item_store($arr,$force_parent = false) {
$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'])) : '');
+ $arr['app'] = ((x($arr,'app')) ? notags(trim($arr['app'])) : '');
+ $arr['guid'] = ((x($arr,'guid')) ? notags(trim($arr['guid'])) : get_guid());
if($arr['parent-uri'] === $arr['uri']) {
$parent_id = 0;
@@ -712,6 +723,13 @@ function item_store($arr,$force_parent = false) {
if($r[0]['uri'] != $r[0]['parent-uri']) {
$arr['thr-parent'] = $arr['parent-uri'];
$arr['parent-uri'] = $r[0]['parent-uri'];
+ $z = q("SELECT `id` FROM `item` WHERE `uri` = '%s' AND `parent-uri` = '%s' AND `uid` = %d LIMIT 1",
+ dbesc($r[0]['parent-uri']),
+ dbesc($r[0]['parent-uri']),
+ intval($arr['uid'])
+ );
+ if($z && count($z))
+ $r = $z;
}
$parent_id = $r[0]['id'];
@@ -741,6 +759,7 @@ function item_store($arr,$force_parent = false) {
}
}
+
call_hooks('post_remote',$arr);
dbesc_array($arr);
@@ -909,7 +928,7 @@ function dfrn_deliver($owner,$contact,$atom, $dissolve = false) {
$postvars['dissolve'] = '1';
- if((($contact['rel']) && ($contact['rel'] != REL_FAN) && (! $contact['blocked'])) || ($owner['page-flags'] == PAGE_COMMUNITY)) {
+ if((($contact['rel']) && ($contact['rel'] != CONTACT_IS_SHARING) && (! $contact['blocked'])) || ($owner['page-flags'] == PAGE_COMMUNITY)) {
$postvars['data'] = $atom;
$postvars['perm'] = 'rw';
}
@@ -987,8 +1006,13 @@ function dfrn_deliver($owner,$contact,$atom, $dissolve = false) {
function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $secure_feed = false) {
- require_once('simplepie/simplepie.inc');
+ require_once('library/simplepie/simplepie.inc');
+ if(! strlen($xml)) {
+ logger('consume_feed: empty input');
+ return;
+ }
+
$feed = new SimplePie();
$feed->set_raw_data($xml);
if($datedir)
@@ -1015,7 +1039,9 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $secure_fee
if(count($hubs))
$hub = implode(',', $hubs);
- $rawtags = $feed->get_feed_tags( SIMPLEPIE_NAMESPACE_ATOM_10, 'author');
+ $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']) {
@@ -1064,13 +1090,13 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $secure_fee
$img->scaleImageSquare(175);
$hash = $resource_id;
- $r = $img->store($contact['uid'], $contact['id'], $hash, basename($photo_url), t('Contact Photos') , 4);
+ $r = $img->store($contact['uid'], $contact['id'], $hash, basename($photo_url), 'Contact Photos', 4);
$img->scaleImage(80);
- $r = $img->store($contact['uid'], $contact['id'], $hash, basename($photo_url), t('Contact Photos') , 5);
+ $r = $img->store($contact['uid'], $contact['id'], $hash, basename($photo_url), 'Contact Photos', 5);
$img->scaleImage(48);
- $r = $img->store($contact['uid'], $contact['id'], $hash, basename($photo_url), t('Contact Photos') , 6);
+ $r = $img->store($contact['uid'], $contact['id'], $hash, basename($photo_url), 'Contact Photos', 6);
$a = get_app();
@@ -1252,6 +1278,7 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $secure_fee
if(! x($datarray,'author-avatar'))
$datarray['author-avatar'] = $contact['thumb'];
+
$r = q("SELECT `uid`, `last-child`, `edited`, `body` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
dbesc($item_id),
intval($importer['uid'])
@@ -1334,6 +1361,27 @@ 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;
+ $ev['edited'] = $datarray['edited'];
+ $ev['private'] = $datarray['private'];
+
+ 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'])
@@ -1388,6 +1436,12 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $secure_fee
$datarray['last-child'] = 0;
}
+ // This is my contact on another system, but it's really me.
+ // Turn this into a wall post.
+
+ if($contact['remote_self'])
+ $datarray['wall'] = 1;
+
$datarray['parent-uri'] = $item_id;
$datarray['uid'] = $importer['uid'];
$datarray['contact-id'] = $contact['id'];
@@ -1409,9 +1463,9 @@ function new_follower($importer,$contact,$datarray,$item) {
$nick = $rawtag[0]['child'][NAMESPACE_POCO]['preferredUsername'][0]['data'];
if(is_array($contact)) {
- if($contact['network'] == 'stat' && $contact['rel'] == REL_FAN) {
+ if($contact['network'] == 'stat' && $contact['rel'] == CONTACT_IS_SHARING) {
$r = q("UPDATE `contact` SET `rel` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
- intval(REL_BUD),
+ intval(CONTACT_IS_FRIEND),
intval($contact['id']),
intval($importer['uid'])
);
@@ -1421,11 +1475,11 @@ function new_follower($importer,$contact,$datarray,$item) {
}
else {
- // create contact record - set to readonly
+ // create contact record
$r = q("INSERT INTO `contact` ( `uid`, `created`, `url`, `name`, `nick`, `photo`, `network`, `rel`,
`blocked`, `readonly`, `pending`, `writable` )
- VALUES ( %d, '%s', '%s', '%s', '%s', '%s', '%s', %d, 0, 1, 1, 1 ) ",
+ VALUES ( %d, '%s', '%s', '%s', '%s', '%s', '%s', %d, 0, 0, 1, 1 ) ",
intval($importer['uid']),
dbesc(datetime_convert()),
dbesc($url),
@@ -1433,12 +1487,12 @@ function new_follower($importer,$contact,$datarray,$item) {
dbesc($nick),
dbesc($photo),
dbesc('stat'),
- intval(REL_VIP)
+ intval(CONTACT_IS_FOLLOWER)
);
$r = q("SELECT `id` FROM `contact` WHERE `uid` = %d AND `url` = '%s' AND `pending` = 1 AND `rel` = %d LIMIT 1",
intval($importer['uid']),
dbesc($url),
- intval(REL_VIP)
+ intval(CONTACT_IS_FOLLOWER)
);
if(count($r))
$contact_record = $r[0];
@@ -1483,9 +1537,9 @@ function new_follower($importer,$contact,$datarray,$item) {
function lose_follower($importer,$contact,$datarray,$item) {
- if(($contact['rel'] == REL_BUD) || ($contact['rel'] == REL_FAN)) {
+ if(($contact['rel'] == CONTACT_IS_FRIEND) || ($contact['rel'] == CONTACT_IS_SHARING)) {
q("UPDATE `contact` SET `rel` = %d WHERE `id` = %d LIMIT 1",
- intval(REL_FAN),
+ intval(CONTACT_IS_SHARING),
intval($contact['id'])
);
}
@@ -1582,7 +1636,7 @@ function atom_entry($item,$type,$author,$owner,$comment = false) {
$o .= '' . xmlify(datetime_convert('UTC','UTC',$item['created'] . '+00:00',ATOM_TIME)) . '' . "\r\n";
$o .= '' . xmlify(datetime_convert('UTC','UTC',$item['edited'] . '+00:00',ATOM_TIME)) . '' . "\r\n";
$o .= '' . base64url_encode($body, true) . '' . "\r\n";
- $o .= '' . xmlify(($type === 'html') ? bbcode($body) : $body) . '' . "\r\n";
+ $o .= '' . xmlify((($type === 'html') ? bbcode($body) : $body)) . '' . "\r\n";
$o .= '' . "\r\n";
if($comment)
$o .= '' . intval($item['last-child']) . '' . "\r\n";
@@ -1601,7 +1655,8 @@ function atom_entry($item,$type,$author,$owner,$comment = false) {
if($item['extid'])
$o .= '' . $item['extid'] . '' . "\r\n";
-
+ if($item['app'])
+ $o .= '';
$verb = construct_verb($item);
$o .= '' . xmlify($verb) . '' . "\r\n";
$actobj = construct_activity_object($item);
@@ -1690,11 +1745,11 @@ 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=\"(.*?)\" length=\"(.*?)\" type=\"(.*?)\" title=\"(.*?)\"\[\/attach\]|',$r,$matches);
if($cnt) {
$ret .= 'get_baseurl() . '/' . $_SESSION['return_url']);
+ }
+
+ $item = $r[0];
+
+ $owner = $item['uid'];
+
+ // check if logged in user is either the author or owner of this item
+
+ if((local_user() == $item['uid']) || (remote_user() == $item['contact-id'])) {
+
+ // delete the item
+
+ $r = q("UPDATE `item` SET `deleted` = 1, `body` = '', `edited` = '%s', `changed` = '%s' WHERE `id` = %d LIMIT 1",
+ dbesc(datetime_convert()),
+ dbesc(datetime_convert()),
+ intval($item['id'])
+ );
+
+ // If item is a link to a photo resource, nuke all the associated photos
+ // (visitors will not have photo resources)
+ // This only applies to photos uploaded from the photos page. Photos inserted into a post do not
+ // generate a resource-id and therefore aren't intimately linked to the item.
+
+ if(strlen($item['resource-id'])) {
+ q("DELETE FROM `photo` WHERE `resource-id` = '%s' AND `uid` = %d ",
+ dbesc($item['resource-id']),
+ intval($item['uid'])
+ );
+ // ignore the result
+ }
+
+ // If item is a link to an event, nuke the event record.
+
+ if(intval($item['event-id'])) {
+ q("DELETE FROM `event` WHERE `id` = %d AND `uid` = %d LIMIT 1",
+ intval($item['event-id']),
+ intval($item['uid'])
+ );
+ // ignore the result
+ }
+
+
+ // If it's the parent of a comment thread, kill all the kids
+
+ if($item['uri'] == $item['parent-uri']) {
+ $r = q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s', `body` = ''
+ WHERE `parent-uri` = '%s' AND `uid` = %d ",
+ dbesc(datetime_convert()),
+ dbesc(datetime_convert()),
+ dbesc($item['parent-uri']),
+ intval($item['uid'])
+ );
+ // ignore the result
+ }
+ else {
+ // ensure that last-child is set in case the comment that had it just got wiped.
+ q("UPDATE `item` SET `last-child` = 0, `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d ",
+ dbesc(datetime_convert()),
+ dbesc($item['parent-uri']),
+ intval($item['uid'])
+ );
+ // who is the last child now?
+ $r = q("SELECT `id` FROM `item` WHERE `parent-uri` = '%s' AND `type` != 'activity' AND `deleted` = 0 AND `uid` = %d ORDER BY `edited` DESC LIMIT 1",
+ dbesc($item['parent-uri']),
+ intval($item['uid'])
+ );
+ if(count($r)) {
+ q("UPDATE `item` SET `last-child` = 1 WHERE `id` = %d LIMIT 1",
+ intval($r[0]['id'])
+ );
+ }
+ }
+ $drop_id = intval($item['id']);
+
+ // send the notification upstream/downstream as the case may be
+
+ if(! $interactive)
+ return $owner;
+
+ proc_run('php',"include/notifier.php","drop","$drop_id");
+ goaway($a->get_baseurl() . '/' . $_SESSION['return_url']);
+ //NOTREACHED
+ }
+ else {
+ if(! $interactive)
+ return 0;
+ notice( t('Permission denied.') . EOL);
+ goaway($a->get_baseurl() . '/' . $_SESSION['return_url']);
+ //NOTREACHED
+ }
+
}
\ No newline at end of file