]> git.mxchange.org Git - friendica.git/blobdiff - include/items.php
Merge branch 'friendika-master'
[friendica.git] / include / items.php
index c29ad9e44086df9315289320adb59c2c86ed6141..15fd262f4c0d35958f545f476d28c5698c893844 100644 (file)
@@ -144,7 +144,7 @@ function get_feed_for(&$a, $dfrn_id, $owner_nick, $last_update, $direction = 0)
                `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`, 
                `contact`.`id` AS `contact-id`, `contact`.`uid` AS `contact-uid`
                FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
-               WHERE `item`.`uid` = %d AND `item`.`visible` = 1 
+               WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`parent` != 0 
                AND `item`.`wall` = 1 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
                AND ( `item`.`edited` > '%s' OR `item`.`changed` > '%s' )
                $sql_extra
@@ -611,7 +611,7 @@ function encode_rel_links($links) {
        return xmlify($o);
 }
 
-function item_store($arr) {
+function item_store($arr,$force_parent = false) {
 
        if($arr['gravity'])
                $arr['gravity'] = intval($arr['gravity']);
@@ -688,15 +688,28 @@ function item_store($arr) {
                                $arr['parent-uri'] = $r[0]['parent-uri'];
                        }
 
-                       $parent_id = $r[0]['id'];
-                       $allow_cid = $r[0]['allow_cid'];
-                       $allow_gid = $r[0]['allow_gid'];
-                       $deny_cid  = $r[0]['deny_cid'];
-                       $deny_gid  = $r[0]['deny_gid'];
+                       $parent_id      = $r[0]['id'];
+                       $parent_deleted = $r[0]['deleted'];
+                       $allow_cid      = $r[0]['allow_cid'];
+                       $allow_gid      = $r[0]['allow_gid'];
+                       $deny_cid       = $r[0]['deny_cid'];
+                       $deny_gid       = $r[0]['deny_gid'];
                }
                else {
-                       logger('item_store: item parent was not found - ignoring item');
-                       return 0;
+
+                       // Allow one to see reply tweets from status.net even when
+                       // we don't have or can't see the original post.
+
+                       if($force_parent) {
+                               logger('item_store: $force_parent=true, reply converted to top-level post.');
+                               $parent_id = 0;
+                               $arr['thr-parent'] = $arr['parent-uri'];
+                               $arr['parent-uri'] = $arr['uri'];
+                       }
+                       else {
+                               logger('item_store: item parent was not found - ignoring item');
+                               return 0;
+                       }
                }
        }
 
@@ -727,10 +740,10 @@ function item_store($arr) {
                return 0;
        }
 
-       if($arr['parent-uri'] === $arr['uri'])
+       if((! $parent_id) || ($arr['parent-uri'] === $arr['uri']))      
                $parent_id = $current_post;
-       if(strlen($allow_cid) || strlen($allow_gid) || strlen($deny_cid) || strlen($deny_gid))
+
+       if(strlen($allow_cid) || strlen($allow_gid) || strlen($deny_cid) || strlen($deny_gid))
                $private = 1;
        else
                $private = $arr['private']; 
@@ -738,13 +751,14 @@ function item_store($arr) {
        // Set parent id - and also make sure to inherit the parent's ACL's.
 
        $r = q("UPDATE `item` SET `parent` = %d, `allow_cid` = '%s', `allow_gid` = '%s',
-               `deny_cid` = '%s', `deny_gid` = '%s', `private` = %d WHERE `id` = %d LIMIT 1",
+               `deny_cid` = '%s', `deny_gid` = '%s', `private` = %d, `deleted` = %d WHERE `id` = %d LIMIT 1",
                intval($parent_id),
                dbesc($allow_cid),
                dbesc($allow_gid),
                dbesc($deny_cid),
                dbesc($deny_gid),
                intval($private),
+               intval($parent_deleted),
                intval($current_post)
        );
 
@@ -768,7 +782,7 @@ function dfrn_deliver($owner,$contact,$atom, $dissolve = false) {
 
        $a = get_app();
 
-       if((! strlen($contact['dfrn-id'])) && (! $contact['duplex']) && (! ($owner['page-flags'] == PAGE_COMMUNITY)))
+       if((! strlen($contact['issued-id'])) && (! $contact['duplex']) && (! ($owner['page-flags'] == PAGE_COMMUNITY)))
                return 3;
 
        $idtosend = $orig_id = (($contact['dfrn-id']) ? $contact['dfrn-id'] : $contact['issued-id']);
@@ -800,6 +814,12 @@ function dfrn_deliver($owner,$contact,$atom, $dissolve = false) {
        if(! $xml)
                return 3;
 
+       if(strpos($xml,'<?xml') === false) {
+               logger('dfrn_deliver: no valid XML returned');
+               logger('dfrn_deliver: returned XML: ' . $xml, LOGGER_DATA);
+               return 3;
+       }
+
        $res = simplexml_load_string($xml);
 
        if((intval($res->status) != 0) || (! strlen($res->challenge)) || (! strlen($res->dfrn_id)))
@@ -808,19 +828,20 @@ function dfrn_deliver($owner,$contact,$atom, $dissolve = false) {
        $postvars     = array();
        $sent_dfrn_id = hex2bin((string) $res->dfrn_id);
        $challenge    = hex2bin((string) $res->challenge);
+       $dfrn_version = (float) (($res->dfrn_version) ? $res->dfrn_version : 2.0);
        $rino_allowed = ((intval($res->rino) === 1) ? 1 : 0);
 
        $final_dfrn_id = '';
 
 
-       if(($contact['duplex'] && strlen($contact['prvkey'])) || ($owner['page-flags'] == PAGE_COMMUNITY)) {
-               openssl_private_decrypt($sent_dfrn_id,$final_dfrn_id,$contact['prvkey']);
-               openssl_private_decrypt($challenge,$postvars['challenge'],$contact['prvkey']);
-       }
-       else {
+       if(($contact['duplex'] && strlen($contact['pubkey'])) || ($owner['page-flags'] == PAGE_COMMUNITY)) {
                openssl_public_decrypt($sent_dfrn_id,$final_dfrn_id,$contact['pubkey']);
                openssl_public_decrypt($challenge,$postvars['challenge'],$contact['pubkey']);
        }
+       else {
+               openssl_private_decrypt($sent_dfrn_id,$final_dfrn_id,$contact['prvkey']);
+               openssl_private_decrypt($challenge,$postvars['challenge'],$contact['prvkey']);
+       }
 
        $final_dfrn_id = substr($final_dfrn_id, 0, strpos($final_dfrn_id, '.'));
 
@@ -854,11 +875,22 @@ function dfrn_deliver($owner,$contact,$atom, $dissolve = false) {
                $postvars['data'] = $data;
                logger('rino: sent key = ' . $key);     
 
-               if(($contact['duplex'] && strlen($contact['prvkey'])) || ($owner['page-flags'] == PAGE_COMMUNITY)) {
-                       openssl_private_encrypt($key,$postvars['key'],$contact['prvkey']);
+
+               if($dfrn_version >= 2.1) {      
+                       if(($contact['duplex'] && strlen($contact['pubkey'])) || ($owner['page-flags'] == PAGE_COMMUNITY)) {
+                               openssl_public_encrypt($key,$postvars['key'],$contact['pubkey']);
+                       }
+                       else {
+                               openssl_private_encrypt($key,$postvars['key'],$contact['prvkey']);
+                       }
                }
                else {
-                       openssl_public_encrypt($key,$postvars['key'],$contact['pubkey']);
+                       if(($contact['duplex'] && strlen($contact['prvkey'])) || ($owner['page-flags'] == PAGE_COMMUNITY)) {
+                               openssl_private_encrypt($key,$postvars['key'],$contact['prvkey']);
+                       }
+                       else {
+                               openssl_public_encrypt($key,$postvars['key'],$contact['pubkey']);
+                       }
                }
 
                logger('md5 rawkey ' . md5($postvars['key']));
@@ -876,6 +908,13 @@ function dfrn_deliver($owner,$contact,$atom, $dissolve = false) {
        if((! $curl_stat) || (! strlen($xml)))
                return(-1); // timed out
 
+
+       if(strpos($xml,'<?xml') === false) {
+               logger('dfrn_deliver: phase 2: no valid XML returned');
+               logger('dfrn_deliver: phase 2: returned XML: ' . $xml, LOGGER_DATA);
+               return 3;
+       }
+
        $res = simplexml_load_string($xml);
 
        return $res->status;
@@ -1169,8 +1208,9 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0) {
                                        continue;
                                }
                                $datarray = get_atom_elements($feed,$item);
-
+                               $force_parent = false;
                                if($contact['network'] === 'stat') {
+                                       $force_parent = true;
                                        if(strlen($datarray['title']))
                                                unset($datarray['title']);
                                        $r = q("UPDATE `item` SET `last-child` = 0, `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
@@ -1193,7 +1233,7 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0) {
                                        $datarray['gravity'] = GRAVITY_LIKE;
                                }
 
-                               $r = item_store($datarray);
+                               $r = item_store($datarray,$force_parent);
                                continue;
                        }