]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/Item.php
Update src/Model/Photo.php
[friendica.git] / src / Model / Item.php
index 9046674e7b33afb1c65608c425f806eea283252d..6488e479e5bdae9a87a54d813d8def8c072bec41 100644 (file)
@@ -76,9 +76,9 @@ class Item
                'commented', 'created', 'edited', 'received', 'verb', 'object-type', 'postopts', 'plink',
                'wall', 'private', 'starred', 'origin', 'parent-origin', 'title', 'body', 'language',
                'content-warning', 'location', 'coord', 'app', 'rendered-hash', 'rendered-html', 'object',
-               'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid',
+               'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid', 'mention',
                'author-id', 'author-link', 'author-name', 'author-avatar', 'author-network',
-               'owner-id', 'owner-link', 'owner-name', 'owner-avatar', 'owner-network',
+               'owner-id', 'owner-link', 'owner-name', 'owner-avatar', 'owner-network', 'owner-contact-type',
                'causer-id', 'causer-link', 'causer-name', 'causer-avatar', 'causer-contact-type', 'causer-network',
                'contact-id', 'contact-uid', 'contact-link', 'contact-name', 'contact-avatar',
                'writable', 'self', 'cid', 'alias',
@@ -94,9 +94,9 @@ class Item
                        'private', 'title', 'body', 'raw-body', 'location', 'coord', 'app',
                        'inform', 'deleted', 'extid', 'post-type', 'gravity',
                        'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid',
-                       'author-id', 'author-link', 'owner-id', 'owner-link', 'contact-uid',
+                       'author-id', 'author-link', 'author-name', 'author-avatar', 'owner-id', 'owner-link', 'contact-uid',
                        'signed_text', 'network', 'wall', 'contact-id', 'plink', 'forum_mode', 'origin',
-                       'thr-parent-id', 'parent-uri-id', 'postopts', 'pubmail', 
+                       'thr-parent-id', 'parent-uri-id', 'postopts', 'pubmail',
                        'event-created', 'event-edited', 'event-start', 'event-finish',
                        'event-summary', 'event-desc', 'event-location', 'event-type',
                        'event-nofinish', 'event-adjust', 'event-ignore', 'event-id'];
@@ -115,22 +115,6 @@ class Item
                        'author-id', 'author-link', 'author-name', 'author-avatar', 'author-network',
                        'owner-id', 'owner-link', 'owner-name', 'owner-avatar', 'causer-id'];
 
-       // Item fields that still are in use
-       const USED_FIELDLIST = ['id', 'parent', 'guid', 'uri', 'uri-id', 'parent-uri', 'parent-uri-id',
-               'thr-parent', 'thr-parent-id', 'created', 'edited', 'commented', 'received', 'changed',
-               'gravity', 'network', 'owner-id', 'author-id', 'causer-id', 'vid', 'extid', 'post-type',
-               'global', 'private', 'visible', 'deleted', 'uid', 'contact-id',
-               'wall', 'origin', 'pubmail', 'starred', 'unseen', 'mention', 'forum_mode', 'psid',
-               'event-id'];
-
-       // Legacy item fields that aren't stored any more in the item table
-       const LEGACY_FIELDLIST = ['uri-hash', 'iaid', 'icid', 'attach',
-               'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid', 'postopts', 
-               'resource-id', 'inform', 'file', 'location', 'coord', 'tag', 'plink', 
-               'title', 'content-warning', 'body', 'app', 'verb', 'object-type', 'object', 
-               'target-type', 'target', 'author-name', 'author-link', 'author-avatar', 
-               'owner-name', 'owner-link', 'owner-avatar', 'rendered-hash', 'rendered-html'];
-
        // List of all verbs that don't need additional content data.
        // Never reorder or remove entries from this list. Just add new ones at the end, if needed.
        const ACTIVITIES = [
@@ -257,7 +241,7 @@ class Item
                        if ($item['uid'] == $uid) {
                                self::markForDeletionById($item['id'], PRIORITY_HIGH);
                        } elseif ($item['uid'] != 0) {
-                               Logger::log('Wrong ownership. Not deleting item ' . $item['id']);
+                               Logger::notice('Wrong ownership. Not deleting item', ['id' => $item['id']]);
                        }
                }
                DBA::close($items);
@@ -334,14 +318,6 @@ class Item
 
                Post\DeliveryData::delete($item['uri-id']);
 
-               // When the permission set will be used in photo and events as well,
-               // this query here needs to be extended.
-               // @todo Currently deactivated. We need the permission set in the deletion process.
-               // This is a reminder to add the removal somewhere else.
-               //if (!empty($item['psid']) && !self::exists(['psid' => $item['psid'], 'deleted' => false])) {
-               //      DBA::delete('permissionset', ['id' => $item['psid']], ['cascade' => false]);
-               //}
-
                // If it's the parent of a comment thread, kill all the kids
                if ($item['gravity'] == GRAVITY_PARENT) {
                        self::markForDeletion(['parent' => $item['parent'], 'deleted' => false], $priority);
@@ -882,6 +858,8 @@ class Item
                                $item['wall'] = $toplevel_parent['wall'];
                        } else {
                                $item['wall'] = false;
+                               // Participations are technical messages, so they are set to "seen" automatically
+                               $item['unseen'] = false;
                        }
 
                        /*
@@ -992,6 +970,10 @@ class Item
                        unset($item['event-id']);
                }
 
+               if (empty($item['causer-id'])) {
+                       unset($item['causer-id']);
+               }
+
                Post::insert($item['uri-id'], $item);
 
                if ($item['gravity'] == GRAVITY_PARENT) {
@@ -1204,7 +1186,7 @@ class Item
         */
        public static function distribute($itemid, $signed_text = '')
        {
-               $condition = ["`id` IN (SELECT `parent` FROM `post-view` WHERE `id` = ?)", $itemid];
+               $condition = ["`id` IN (SELECT `parent` FROM `post-user-view` WHERE `id` = ?)", $itemid];
                $parent = Post::selectFirst(['owner-id'], $condition);
                if (!DBA::isResult($parent)) {
                        Logger::warning('Item not found', ['condition' => $condition]);
@@ -1521,6 +1503,10 @@ class Item
         */
        private static function getLanguage(array $item)
        {
+               if (!empty($item['language'])) {
+                       return $item['language'];
+               }
+
                if (!in_array($item['gravity'], [GRAVITY_PARENT, GRAVITY_COMMENT]) || empty($item['body'])) {
                        return '';
                }
@@ -2191,9 +2177,15 @@ class Item
 
        public static function firstPostDate($uid, $wall = false)
        {
-               $condition = ['gravity' => GRAVITY_PARENT, 'uid' => $uid, 'wall' => $wall, 'deleted' => false, 'visible' => true];
+               $user = User::getById($uid, ['register_date']);
+               if (empty($user)) {
+                       return false;
+               }
+
+               $condition = ["`uid` = ? AND `wall` = ? AND NOT `deleted` AND `visible` AND `received` >= ?",
+                       $uid, $wall, $user['register_date']];
                $params = ['order' => ['received' => false]];
-               $thread = Post::selectFirst(['received'], $condition, $params);
+               $thread = Post::selectFirstThread(['received'], $condition, $params);
                if (DBA::isResult($thread)) {
                        $postdate = substr(DateTimeFormat::local($thread['received']), 0, 10);
                        return $postdate;
@@ -2489,22 +2481,23 @@ class Item
        /**
         * get translated item type
         *
-        * @param $item
+        * @param array                $item
+        * @param \Friendica\Core\L10n $l10n
         * @return string
         */
-       public static function postType($item)
+       public static function postType(array $item, \Friendica\Core\L10n $l10n)
        {
                if (!empty($item['event-id'])) {
-                       return DI::l10n()->t('event');
+                       return $l10n->t('event');
                } elseif (!empty($item['resource-id'])) {
-                       return DI::l10n()->t('photo');
+                       return $l10n->t('photo');
                } elseif ($item['gravity'] == GRAVITY_ACTIVITY) {
-                       return DI::l10n()->t('activity');
+                       return $l10n->t('activity');
                } elseif ($item['gravity'] == GRAVITY_COMMENT) {
-                       return DI::l10n()->t('comment');
+                       return $l10n->t('comment');
                }
 
-               return DI::l10n()->t('post');
+               return $l10n->t('post');
        }
 
        /**
@@ -2513,12 +2506,11 @@ class Item
         * Body is preserved to avoid side-effects as we modify it just-in-time for spoilers and private image links
         *
         * @param array $item
-        * @param bool  $update
         *
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         * @todo Remove reference, simply return "rendered-html" and "rendered-hash"
         */
-       public static function putInCache(&$item, $update = false)
+       public static function putInCache(&$item)
        {
                // Save original body to prevent addons to modify it
                $body = $item['body'];
@@ -2542,17 +2534,8 @@ class Item
                        $item['rendered-hash'] = $hook_data['rendered-hash'];
                        unset($hook_data);
 
-                       // Force an update if the generated values differ from the existing ones
-                       if ($rendered_hash != $item['rendered-hash']) {
-                               $update = true;
-                       }
-
-                       // Only compare the HTML when we forcefully ignore the cache
-                       if (DI::config()->get('system', 'ignore_cache') && ($rendered_html != $item['rendered-html'])) {
-                               $update = true;
-                       }
-
-                       if ($update && !empty($item['id'])) {
+                       // Update if the generated values differ from the existing ones
+                       if ((($rendered_hash != $item['rendered-hash']) || ($rendered_html != $item['rendered-html'])) && !empty($item['id'])) {
                                self::update(
                                        [
                                                'rendered-html' => $item['rendered-html'],
@@ -2640,15 +2623,7 @@ class Item
                        unset($hook_data);
                }
 
-               // Update the cached values if there is no "zrl=..." on the links.
-               $update = (!Session::isAuthenticated() && ($item["uid"] == 0));
-
-               // Or update it if the current viewer is the intented viewer.
-               if (($item["uid"] == local_user()) && ($item["uid"] != 0)) {
-                       $update = true;
-               }
-
-               self::putInCache($item, $update);
+               self::putInCache($item);
                $s = $item["rendered-html"];
 
                $hook_data = [