]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/Item.php
Added brackets
[friendica.git] / src / Model / Item.php
index 970c5f4a569149c8c010b7a6ab30a6ff4d0d8fd2..8af14e8243c3bd46966b4089a1880020ef28e6d4 100644 (file)
@@ -43,8 +43,8 @@ use Friendica\Util\Map;
 use Friendica\Util\Network;
 use Friendica\Util\Strings;
 use Friendica\Worker\Delivery;
-use Text_LanguageDetect;
 use Friendica\Repository\PermissionSet as RepPermissionSet;
+use LanguageDetection\Language;
 
 class Item
 {
@@ -775,7 +775,7 @@ class Item
                        }
                }
                if (strpos($sql_commands, "`causer`.") !== false) {
-                       $joins .= " LEFT JOIN `contact` AS `causer` ON `causer`.`id` = $master_table.`causer-id`";
+                       $joins .= " LEFT JOIN `contact` AS `causer` ON `causer`.`id` = `item`.`causer-id`";
                }
 
                if (strpos($sql_commands, "`group_member`.") !== false) {
@@ -1699,10 +1699,10 @@ class Item
 
                $item['plink'] = ($item['plink'] ?? '') ?: DI::baseUrl() . '/display/' . urlencode($item['guid']);
 
-               $item['language'] = self::getLanguage($item);
-
                $item['gravity'] = self::getGravity($item);
 
+               $item['language'] = self::getLanguage($item);
+
                $default = ['url' => $item['author-link'], 'name' => $item['author-name'],
                        'photo' => $item['author-avatar'], 'network' => $item['network']];
                $item['author-id'] = ($item['author-id'] ?? 0) ?: Contact::getIdForURL($item['author-link'], 0, null, $default);
@@ -1712,7 +1712,7 @@ class Item
                $item['owner-id'] = ($item['owner-id'] ?? 0) ?: Contact::getIdForURL($item['owner-link'], 0, null, $default);
 
                $actor = ($item['gravity'] == GRAVITY_PARENT) ? $item['owner-id'] : $item['author-id'];
-               if (!$item['origin'] && in_array($item['post-type'], [self::PT_ARTICLE, self::PT_COMMENT, self::PT_RELAY, self::PT_GLOBAL]) && Contact::isSharing($actor, $item['uid'])) {
+               if (!$item['origin'] && ($item['uid'] != 0) && Contact::isSharing($actor, $item['uid'])) {
                        $item['post-type'] = self::PT_FOLLOWER;
                }
 
@@ -1834,6 +1834,11 @@ class Item
 
                if (!in_array($item['verb'], self::ACTIVITIES)) {
                        $item['icid'] = self::insertContent($item);
+                       if (empty($item['icid'])) {
+                               // This most likely happens when identical posts arrives from different sources at the same time
+                               Logger::warning('No content stored, quitting', ['guid' => $item['guid'], 'uri-id' => $item['uri-id'], 'causer-id' => ($item['causer-id'] ?? 0), 'post-type' => $item['post-type'], 'network' => $item['network']]);
+                               return 0;
+                       }
                }
 
                $body = $item['body'];
@@ -2037,8 +2042,7 @@ class Item
                }
 
                if ($author['contact-type'] != Contact::TYPE_COMMUNITY) {
-                       if (!in_array($parent['post-type'], [self::PT_ARTICLE, self::PT_COMMENT, self::PT_STORED, self::PT_GLOBAL, self::PT_RELAY, self::PT_FETCHED])
-                               || Contact::isSharing($parent['owner-id'], $item['uid'])) {
+                       if (Contact::isSharing($parent['owner-id'], $item['uid'])) {
                                Logger::info('The resharer is no forum: quit', ['resharer' => $item['author-id'], 'owner' => $parent['owner-id'], 'author' => $parent['author-id'], 'uid' => $item['uid']]);
                                return;
                        }
@@ -2381,6 +2385,7 @@ class Item
                        unset($item['starred']);
                        unset($item['postopts']);
                        unset($item['inform']);
+                       unset($item['post-type']);
                        if ($item['uri'] == $item['parent-uri']) {
                                $item['contact-id'] = $item['owner-id'];
                        } else {
@@ -2443,6 +2448,7 @@ class Item
                unset($item['starred']);
                unset($item['postopts']);
                unset($item['inform']);
+               unset($item['post-type']);
                $item['contact-id'] = Contact::getIdForURL($item['author-link']);
 
                $public_shadow = self::insert($item, false, true);
@@ -2466,11 +2472,14 @@ class Item
         */
        private static function getLanguage(array $item)
        {
+               if (!in_array($item['gravity'], [GRAVITY_PARENT, GRAVITY_COMMENT])) {
+                       return '';
+               }
+
                $naked_body = BBCode::toPlaintext($item['body'], false);
 
-               $ld = new Text_LanguageDetect();
-               $ld->setNameMode(2);
-               $languages = $ld->detect($naked_body, 3);
+               $ld = new Language();
+               $languages = $ld->detect($naked_body)->limit(0, 3)->close();
                if (is_array($languages)) {
                        return json_encode($languages);
                }
@@ -3589,11 +3598,9 @@ class Item
                                        DI::page()['htmlhead'] .= Renderer::replaceMacros(Renderer::getMarkupTemplate('videos_head.tpl'));
                                }
 
-                               $url_parts = explode('/', $the_url);
-                               $id = end($url_parts);
                                $as .= Renderer::replaceMacros(Renderer::getMarkupTemplate('video_top.tpl'), [
                                        '$video' => [
-                                               'id'     => $id,
+                                               'id'     => $item['author-id'],
                                                'title'  => DI::l10n()->t('View Video'),
                                                'src'    => $the_url,
                                                'mime'   => $mime,