]> git.mxchange.org Git - friendica.git/blobdiff - include/items.php
Merge pull request #672 from cpfeiffer/email-notification-sitename-fix
[friendica.git] / include / items.php
index 8bd28f788de36643c0c56ac2f92bdd98be494105..f4f972e72d933f8518fc1689e13e2dbf2870b408 100755 (executable)
@@ -294,7 +294,7 @@ function construct_activity_target($item) {
 if(! function_exists('limit_body_size')) {
 function limit_body_size($body) {
 
-       logger('limit_body_size: start', LOGGER_DEBUG);
+//     logger('limit_body_size: start', LOGGER_DEBUG);
 
        $maxlen = get_max_import_size();
 
@@ -1180,19 +1180,23 @@ function item_store($arr,$force_parent = false) {
                );
        }
 
-       tag_deliver($arr['uid'],$current_post);
+       $deleted = tag_deliver($arr['uid'],$current_post);
 
-       // Store the fresh generated item into the cache
-       $cachefile = get_cachefile($arr["guid"]."-".hash("md5", $arr['body']));
+       // current post can be deleted if is for a communuty page and no mention are
+       // in it.
+       if (!$deleted) {
+               
+               // Store the fresh generated item into the cache
+               $cachefile = get_cachefile($arr["guid"]."-".hash("md5", $arr['body']));
 
-       if (($cachefile != '') AND !file_exists($cachefile)) {
-               $s = prepare_text($arr['body']);
-               $a = get_app();
-               $stamp1 = microtime(true);
-               file_put_contents($cachefile, $s);
-               $a->save_timestamp($stamp1, "file");
-               logger('item_store: put item '.$current_post.' into cachefile '.$cachefile);
-       }
+               if (($cachefile != '') AND !file_exists($cachefile)) {
+                       $s = prepare_text($arr['body']);
+                       $a = get_app();
+                       $stamp1 = microtime(true);
+                       file_put_contents($cachefile, $s);
+                       $a->save_timestamp($stamp1, "file");
+                       logger('item_store: put item '.$current_post.' into cachefile '.$cachefile);
+               }
 
         $r = q('SELECT * FROM `item` WHERE id = %d', intval($current_post));
         if (count($r) == 1) {
@@ -1201,7 +1205,7 @@ function item_store($arr,$force_parent = false) {
         else {
             logger('item_store: new item not found in DB, id ' . $current_post);
         }
-
+       }
        return $current_post;
 }
 
@@ -1217,10 +1221,15 @@ function get_item_contact($item,$contacts) {
        return false;
 }
 
-
+/**
+ * look for mention tags and setup a second delivery chain for forum/community posts if appropriate
+ * @param int $uid
+ * @param int $item_id
+ * @return bool true if item was deleted, else false
+ */
 function tag_deliver($uid,$item_id) {
 
-       // look for mention tags and setup a second delivery chain for forum/community posts if appropriate
+       // 
 
        $a = get_app();
 
@@ -1262,8 +1271,21 @@ function tag_deliver($uid,$item_id) {
                }
        }
 
-       if(! $mention)
+       if(! $mention){
+               if ( ($community_page || $prvgroup) &&
+                         (!$item['wall']) && (!$item['origin']) && ($item['id'] == $item['parent'])){
+                       // mmh.. no mention.. community page or private group... no wall.. no origin.. top-post (not a comment)
+                       // delete it!
+                       logger("tag_deliver: no-mention top-level post to communuty or private group. delete.");
+                       q("DELETE FROM item WHERE id = %d and uid = %d limit 1",
+                               intval($item_id),
+                               intval($uid)
+                       );
+                       return true;
+               }
                return;
+       }
+               
 
        // send a notification
 
@@ -1589,6 +1611,26 @@ function dfrn_deliver($owner,$contact,$atom, $dissolve = false) {
 }
 
 
+/*
+  This function returns true if $update has an edited timestamp newer
+  than $existing, i.e. $update contains new data which should override
+  what's already there.  If there is no timestamp yet, the update is
+  assumed to be newer.  If the update has no timestamp, the existing
+  item is assumed to be up-to-date.  If the timestamps are equal it
+  assumes the update has been seen before and should be ignored.
+  */
+function edited_timestamp_is_newer($existing, $update) {
+    if (!x($existing,'edited') || !$existing['edited']) {
+        return true;
+    }
+    if (!x($update,'edited') || !$update['edited']) {
+        return false;
+    }
+    $existing_edited = datetime_convert('UTC', 'UTC', $existing['edited']);
+    $update_edited = datetime_convert('UTC', 'UTC', $update['edited']);
+    return (strcmp($existing_edited, $update_edited) < 0);
+}
+
 /**
  *
  * consume_feed - process atom feed and update anything/everything we might need to update
@@ -2002,7 +2044,7 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0)
                                // Update content if 'updated' changes
 
                                if(count($r)) {
-                                       if((x($datarray,'edited') !== false) && (datetime_convert('UTC','UTC',$datarray['edited']) !== $r[0]['edited'])) {  
+                                       if (edited_timestamp_is_newer($r[0], $datarray)) {  
 
                                                // do not accept (ignore) an earlier edit than one we currently have.
                                                if(datetime_convert('UTC','UTC',$datarray['edited']) < $r[0]['edited'])
@@ -2151,7 +2193,7 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0)
                                // Update content if 'updated' changes
 
                                if(count($r)) {
-                                       if((x($datarray,'edited') !== false) && (datetime_convert('UTC','UTC',$datarray['edited']) !== $r[0]['edited'])) {  
+                                       if (edited_timestamp_is_newer($r[0], $datarray)) {  
 
                                                // do not accept (ignore) an earlier edit than one we currently have.
                                                if(datetime_convert('UTC','UTC',$datarray['edited']) < $r[0]['edited'])
@@ -2905,7 +2947,7 @@ function local_delivery($importer,$data) {
 
                                if(count($r)) {
                                        $iid = $r[0]['id'];
-                                       if((x($datarray,'edited') !== false) && (datetime_convert('UTC','UTC',$datarray['edited']) !== $r[0]['edited'])) {
+                                       if (edited_timestamp_is_newer($r[0], $datarray)) {
 
                                                // do not accept (ignore) an earlier edit than one we currently have.
                                                if(datetime_convert('UTC','UTC',$datarray['edited']) < $r[0]['edited'])
@@ -3080,7 +3122,7 @@ function local_delivery($importer,$data) {
                                // Update content if 'updated' changes
 
                                if(count($r)) {
-                                       if((x($datarray,'edited') !== false) && (datetime_convert('UTC','UTC',$datarray['edited']) !== $r[0]['edited'])) {  
+                                       if (edited_timestamp_is_newer($r[0], $datarray)) {  
 
                                                // do not accept (ignore) an earlier edit than one we currently have.
                                                if(datetime_convert('UTC','UTC',$datarray['edited']) < $r[0]['edited'])
@@ -3256,7 +3298,7 @@ function local_delivery($importer,$data) {
                        // Update content if 'updated' changes
 
                        if(count($r)) {
-                               if((x($datarray,'edited') !== false) && (datetime_convert('UTC','UTC',$datarray['edited']) !== $r[0]['edited'])) {  
+                               if (edited_timestamp_is_newer($r[0], $datarray)) {  
 
                                        // do not accept (ignore) an earlier edit than one we currently have.
                                        if(datetime_convert('UTC','UTC',$datarray['edited']) < $r[0]['edited'])