]> git.mxchange.org Git - friendica.git/blobdiff - include/items.php
change language dynamically - bound to F8 key
[friendica.git] / include / items.php
index 153debd7d321f803f2fa11a5fc934f0647092ae4..58fad99272a62dcb496b1cd9e7f3d0cdde01cad8 100644 (file)
@@ -350,7 +350,7 @@ function get_atom_elements($feed,$item) {
                        '[youtube]$1[/youtube]', $res['body']);
 
                $res['body'] = oembed_html2bbcode($res['body']);
-       
+
                $config = HTMLPurifier_Config::createDefault();
                $config->set('Cache.DefinitionImpl', null);
 
@@ -363,7 +363,7 @@ function get_atom_elements($feed,$item) {
 
                $res['body'] = html2bbcode($res['body']);
        }
-       
+
        $allow = $item->get_item_tags(NAMESPACE_DFRN,'comment-allow');
        if($allow && $allow[0]['data'] == 1)
                $res['last-child'] = 1;
@@ -401,6 +401,17 @@ function get_atom_elements($feed,$item) {
                $res['edited'] = $item->get_date('c');
 
 
+       // Disallow time travelling posts
+
+       $d1 = strtotime($res['created']);
+       $d2 = strtotime($res['edited']);
+       $d3 = strtotime('now');
+
+       if($d1 > $d3)
+               $res['created'] = datetime_convert();
+       if($d2 > $d3)
+               $res['edited'] = datetime_convert();
+
        $rawowner = $item->get_item_tags(NAMESPACE_DFRN, 'owner');
        if($rawowner[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'])
                $res['owner-name'] = unxmlify($rawowner[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data']);
@@ -609,6 +620,7 @@ function item_store($arr,$force_parent = false) {
        else { 
 
                // find the parent and snarf the item id and ACL's
+               // and anything else we need to inherit
 
                $r = q("SELECT * FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
                        dbesc($arr['parent-uri']),
@@ -632,6 +644,7 @@ function item_store($arr,$force_parent = false) {
                        $allow_gid      = $r[0]['allow_gid'];
                        $deny_cid       = $r[0]['deny_cid'];
                        $deny_gid       = $r[0]['deny_gid'];
+                       $arr['wall']    = $r[0]['wall'];
                }
                else {
 
@@ -700,6 +713,18 @@ function item_store($arr,$force_parent = false) {
                intval($current_post)
        );
 
+       /**
+        * If this is now the last-child, force all _other_ children of this parent to *not* be last-child
+        */
+
+       if($arr['last-child']) {
+               $r = q("UPDATE `item` SET `last-child` = 0 WHERE `parent-uri` = '%s' AND `uid` = %d AND `id` != %d",
+                       dbesc($arr['uri']),
+                       intval($arr['uid']),
+                       intval($current_post)
+               );
+       }
+
        return $current_post;
 }
 
@@ -737,7 +762,7 @@ function dfrn_deliver($owner,$contact,$atom, $dissolve = false) {
        if(! $rino_enable)
                $rino = 0;
 
-       $url = $contact['notify'] . '?dfrn_id=' . $idtosend . '&dfrn_version=' . DFRN_PROTOCOL_VERSION . (($rino) ? '&rino=1' : '');
+       $url = $contact['notify'] . '&dfrn_id=' . $idtosend . '&dfrn_version=' . DFRN_PROTOCOL_VERSION . (($rino) ? '&rino=1' : '');
 
        logger('dfrn_deliver: ' . $url);
 
@@ -1132,15 +1157,28 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0) {
 
                                // Have we seen it? If not, import it.
        
-                               $item_id = $item->get_id();
+                               $item_id  = $item->get_id();
+                               $datarray = get_atom_elements($feed,$item);
 
-                               $r = q("SELECT `uid`, `last-child`, `edited` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
+                               $r = q("SELECT `uid`, `last-child`, `edited`, `body` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
                                        dbesc($item_id),
                                        intval($importer['uid'])
                                );
 
-                               // FIXME update content if 'updated' changes
+                               // Update content if 'updated' changes
+
                                if(count($r)) {
+                                       if((x($datarray,'edited') !== false) && (datetime_convert('UTC','UTC',$datarray['edited']) !== $r[0]['edited'])) {  
+                                               $r = q("UPDATE `item` SET `body` = '%s', `edited` = '%s' WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
+                                                       dbesc($datarray['body']),
+                                                       dbesc(datetime_convert('UTC','UTC',$datarray['edited'])),
+                                                       dbesc($item_id),
+                                                       intval($importer['uid'])
+                                               );
+                                       }
+
+                                       // update last-child if it changes
+
                                        $allow = $item->get_item_tags( NAMESPACE_DFRN, 'comment-allow');
                                        if(($allow) && ($allow[0]['data'] != $r[0]['last-child'])) {
                                                $r = q("UPDATE `item` SET `last-child` = 0, `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
@@ -1158,7 +1196,6 @@ 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;
@@ -1189,14 +1226,31 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0) {
                        }
 
                        else {
+
                                // Head post of a conversation. Have we seen it? If not, import it.
 
-                               $item_id = $item->get_id();
-                               $r = q("SELECT `uid`, `last-child`, `edited` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
+                               $item_id  = $item->get_id();
+                               $datarray = get_atom_elements($feed,$item);
+
+                               $r = q("SELECT `uid`, `last-child`, `edited`, `body` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
                                        dbesc($item_id),
                                        intval($importer['uid'])
                                );
+
+                               // Update content if 'updated' changes
+
                                if(count($r)) {
+                                       if((x($datarray,'edited') !== false) && (datetime_convert('UTC','UTC',$datarray['edited']) !== $r[0]['edited'])) {  
+                                               $r = q("UPDATE `item` SET `body` = '%s', `edited` = '%s' WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
+                                                       dbesc($datarray['body']),
+                                                       dbesc(datetime_convert('UTC','UTC',$datarray['edited'])),
+                                                       dbesc($item_id),
+                                                       intval($importer['uid'])
+                                               );
+                                       }
+
+                                       // update last-child if it changes
+
                                        $allow = $item->get_item_tags( NAMESPACE_DFRN, 'comment-allow');
                                        if($allow && $allow[0]['data'] != $r[0]['last-child']) {
                                                $r = q("UPDATE `item` SET `last-child` = %d , `changed` = '%s' WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
@@ -1208,7 +1262,6 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0) {
                                        }
                                        continue;
                                }
-                               $datarray = get_atom_elements($feed,$item);
 
                                if(activity_match($datarray['verb'],ACTIVITY_FOLLOW)) {
                                        logger('consume-feed: New follower');
@@ -1454,3 +1507,49 @@ function atom_entry($item,$type,$author,$owner,$comment = false) {
        return $o;
 }
        
+function item_expire($uid,$days) {
+
+       if((! $uid) || (! $days))
+               return;
+
+       $r = q("SELECT * FROM `item` 
+               WHERE `uid` = %d 
+               AND `created` < UTC_TIMESTAMP() - INTERVAL %d DAY 
+               AND `id` = `parent` 
+               AND `deleted` = 0",
+               intval($uid),
+               intval($days)
+       );
+
+       if(! count($r))
+               return;
+       logger('expire: # items=' . count($r) );
+
+       foreach($r as $item) {
+
+               // Only expire posts, not photos and photo comments
+
+               if(strlen($item['resource-id']))
+                       continue;
+
+               $r = q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s' WHERE `id` = %d LIMIT 1",
+                       dbesc(datetime_convert()),
+                       dbesc(datetime_convert()),
+                       intval($item['id'])
+               );
+
+               // kill the kids
+
+               $r = q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d ",
+                       dbesc(datetime_convert()),
+                       dbesc(datetime_convert()),
+                       dbesc($item['parent-uri']),
+                       intval($item['uid'])
+               );
+
+       }
+
+       proc_run('php',"include/notifier.php","expire","$uid");
+
+}
\ No newline at end of file