]> git.mxchange.org Git - friendica.git/blobdiff - include/items.php
typo
[friendica.git] / include / items.php
index 6593647bacbe9625991d619520efea1c69980f69..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']) {
@@ -1349,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'];
@@ -1444,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'])
                        );
@@ -1468,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];
@@ -1518,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'])
                );
        }
@@ -1617,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";
@@ -1726,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";