]> git.mxchange.org Git - friendica.git/blobdiff - include/items.php
how the heck did favicon get into the repo? Gone now...
[friendica.git] / include / items.php
index 514bd1efa983c1442ca6d649d7e7e804415c7c2f..63e180f7611f8482f67ca139eb44f7d14eb6fc28 100644 (file)
@@ -336,6 +336,12 @@ function get_atom_elements($feed,$item) {
                }
        }
 
+       $apps = $item->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.
@@ -663,6 +669,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 +692,7 @@ 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']))           : '');
 
        if($arr['parent-uri'] === $arr['uri']) {
                $parent_id = 0;
@@ -987,7 +995,7 @@ 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');
 
        $feed = new SimplePie();
        $feed->set_raw_data($xml);
@@ -1338,6 +1346,9 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $secure_fee
                                        $ev = bbtoevent($datarray['body']);
                                        if(x($ev,'desc') && x($ev,'start')) {
                                                $ev['uid'] = $importer['uid'];
+                                               $ev['uri'] = $item_id;
+                                               $ev['edited'] = $datarray['edited'];
+
                                                if(is_array($contact))
                                                        $ev['cid'] = $contact['id'];
                                                $r = q("SELECT * FROM `event` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
@@ -1618,7 +1629,8 @@ function atom_entry($item,$type,$author,$owner,$comment = false) {
        if($item['extid'])
                $o .= '<dfrn:extid>' . $item['extid'] . '</dfrn:extid>' . "\r\n";
 
-
+       if($item['app'])
+               $o .= '<statusnet:notice_info local_id="' . $item['id'] . '" source="' . $item['app'] . '" ></statusnet:notice_info>';
        $verb = construct_verb($item);
        $o .= '<as:verb>' . xmlify($verb) . '</as:verb>' . "\r\n";
        $actobj = construct_activity_object($item);
@@ -1770,3 +1782,129 @@ function item_expire($uid,$days) {
 
 }
 
+
+function drop_items($items) {
+       $uid = 0;
+
+       if(count($items)) {
+               foreach($items as $item) {
+                       $owner = drop_item($item,false);
+                       if($owner && ! $uid)
+                               $uid = $owner;
+               }
+       }
+
+       // multiple threads may have been deleted, send an expire notification
+
+       if($uid)
+               proc_run('php',"include/notifier.php","expire","$uid");
+}
+
+
+function drop_item($id,$interactive = true) {
+
+       $a = get_app();
+
+       // locate item to be deleted
+
+       $r = q("SELECT * FROM `item` WHERE `id` = %d LIMIT 1",
+               intval($id)
+       );
+
+       if(! count($r)) {
+               if(! $interactive)
+                       return 0;
+               notice( t('Item not found.') . EOL);
+               goaway($a->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