]> git.mxchange.org Git - friendica.git/blobdiff - include/items.php
typo
[friendica.git] / include / items.php
index 63e180f7611f8482f67ca139eb44f7d14eb6fc28..746e3b2944fc2769ec5090afc83042fe091c0238 100644 (file)
@@ -1,12 +1,12 @@
 <?php
 
-require_once('bbcode.php');
-require_once('oembed.php');
+require_once('include/bbcode.php');
+require_once('include/oembed.php');
 require_once('include/salmon.php');
+require_once('include/crypto.php');
 
 function get_feed_for(&$a, $dfrn_id, $owner_nick, $last_update, $direction = 0) {
 
-
        // default permissions - anonymous user
 
        if(! strlen($owner_nick))
@@ -113,7 +113,7 @@ function get_feed_for(&$a, $dfrn_id, $owner_nick, $last_update, $direction = 0)
 
        $items = $r;
 
-       $feed_template = get_markup_template('atom_feed.tpl');
+       $feed_template = get_markup_template(($dfrn_id) ? 'atom_feed_dfrn.tpl' : 'atom_feed.tpl');
 
        $atom = '';
 
@@ -154,6 +154,9 @@ function get_feed_for(&$a, $dfrn_id, $owner_nick, $last_update, $direction = 0)
 
                if($dfrn_id === '') {
                        $type = 'html';
+                       // catch any email that's in a public conversation and make sure it doesn't leak
+                       if($item['private'])
+                               continue;
                }
                else {
                        $type = 'text';
@@ -485,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();
@@ -520,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);
        }
@@ -693,6 +695,7 @@ function item_store($arr,$force_parent = false) {
        $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;
@@ -720,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'];
@@ -749,6 +759,7 @@ function item_store($arr,$force_parent = false) {
                }
        }
 
+
        call_hooks('post_remote',$arr);
 
        dbesc_array($arr);
@@ -917,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';
        }
@@ -997,6 +1008,11 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $secure_fee
 
        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)
@@ -1023,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']) {
@@ -1072,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();
 
@@ -1260,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'])
@@ -1348,6 +1367,7 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $secure_fee
                                                $ev['uid'] = $importer['uid'];
                                                $ev['uri'] = $item_id;
                                                $ev['edited'] = $datarray['edited'];
+                                               $ev['private'] = $datarray['private'];
 
                                                if(is_array($contact))
                                                        $ev['cid'] = $contact['id'];
@@ -1416,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'];
@@ -1437,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'])
                        );
@@ -1449,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),
@@ -1461,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];
@@ -1511,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'])
                );
        }
@@ -1610,7 +1636,7 @@ function atom_entry($item,$type,$author,$owner,$comment = false) {
        $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($body, true) . '</dfrn:env>' . "\r\n";
-       $o .= '<content type="' . $type . '" >' . xmlify(($type === 'html') ? bbcode($body) : $body) . '</content>' . "\r\n";
+       $o .= '<content type="' . $type . '" >' . xmlify((($type === 'html') ? bbcode($body) : $body)) . '</content>' . "\r\n";
        $o .= '<link rel="alternate" type="text/html" href="' . xmlify($a->get_baseurl() . '/display/' . $owner['nickname'] . '/' . $item['id']) . '" />' . "\r\n";
        if($comment)
                $o .= '<dfrn:comment-allow>' . intval($item['last-child']) . '</dfrn:comment-allow>' . "\r\n";
@@ -1719,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 .= '<link rel="enclosure" href="' . xmlify($matches[1]) . '" type="' . xmlify($matches[3]) . '" ';
                                if(intval($matches[2]))
-                                       $ret .= 'size="' . intval($matches[2]) . '" ';
+                                       $ret .= 'length="' . intval($matches[2]) . '" ';
                                if($matches[4] !== ' ')
                                        $ret .= 'title="' . xmlify(trim($matches[4])) . '" ';
                                $ret .= ' />' . "\r\n";