]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/Event.php
Merge pull request #9807 from annando/postforuser
[friendica.git] / src / Model / Event.php
index ce2e9d53b2cc98b43a537bcb7db3e01af66dc209..c247d22a8086a2e3e954fa48f809d214fd98d367 100644 (file)
@@ -1,14 +1,30 @@
 <?php
 /**
- * @file src/Model/Event.php
+ * @copyright Copyright (C) 2020, Friendica
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ *
  */
 
 namespace Friendica\Model;
 
 use Friendica\Content\Text\BBCode;
 use Friendica\Core\Hook;
-use Friendica\Core\L10n;
 use Friendica\Core\Logger;
+use Friendica\Core\Protocol;
 use Friendica\Core\Renderer;
 use Friendica\Core\System;
 use Friendica\Database\DBA;
@@ -241,6 +257,16 @@ class Event
         */
        public static function store($arr)
        {
+               $network = $arr['network'] ?? Protocol::DFRN;
+               $protocol = $arr['protocol'] ?? Conversation::PARCEL_UNKNOWN;
+               $direction = $arr['direction'] ?? Conversation::UNKNOWN;
+               $source = $arr['source'] ?? '';
+
+               unset($arr['network']);
+               unset($arr['protocol']);
+               unset($arr['direction']);
+               unset($arr['source']);
+
                $event = [];
                $event['id']        = intval($arr['id']        ?? 0);
                $event['uid']       = intval($arr['uid']       ?? 0);
@@ -275,6 +301,9 @@ class Event
                }
 
                $contact = DBA::selectFirst('contact', [], $conditions);
+               if (!DBA::isResult($contact)) {
+                       Logger::warning('Contact not found', ['condition' => $conditions, 'callstack' => System::callstack(20)]);
+               }
 
                // Existing event being modified.
                if ($event['id']) {
@@ -282,7 +311,7 @@ class Event
                        $existing_event = DBA::selectFirst('event', ['edited'], ['id' => $event['id'], 'uid' => $event['uid']]);
                        if (!DBA::isResult($existing_event) || ($existing_event['edited'] === $event['edited'])) {
 
-                               $item = Item::selectFirst(['id'], ['event-id' => $event['id'], 'uid' => $event['uid']]);
+                               $item = Post::selectFirst(['id'], ['event-id' => $event['id'], 'uid' => $event['uid']]);
 
                                return DBA::isResult($item) ? $item['id'] : 0;
                        }
@@ -301,7 +330,7 @@ class Event
 
                        DBA::update('event', $updated_fields, ['id' => $event['id'], 'uid' => $event['uid']]);
 
-                       $item = Item::selectFirst(['id'], ['event-id' => $event['id'], 'uid' => $event['uid']]);
+                       $item = Post::selectFirst(['id'], ['event-id' => $event['id'], 'uid' => $event['uid']]);
                        if (DBA::isResult($item)) {
                                $object = '<object><type>' . XML::escape(Activity\ObjectType::EVENT) . '</type><title></title><id>' . XML::escape($event['uri']) . '</id>';
                                $object .= '<content>' . XML::escape(self::getBBCode($event)) . '</content>';
@@ -331,7 +360,6 @@ class Event
                                $item_arr['uid']           = $event['uid'];
                                $item_arr['contact-id']    = $event['cid'];
                                $item_arr['uri']           = $event['uri'];
-                               $item_arr['parent-uri']    = $event['uri'];
                                $item_arr['guid']          = $event['guid'];
                                $item_arr['plink']         = $arr['plink'] ?? '';
                                $item_arr['post-type']     = Item::PT_EVENT;
@@ -355,6 +383,10 @@ class Event
                                $item_arr['origin']        = $event['cid'] === 0 ? 1 : 0;
                                $item_arr['body']          = self::getBBCode($event);
                                $item_arr['event-id']      = $event['id'];
+                               $item_arr['network']       = $network;
+                               $item_arr['protocol']      = $protocol;
+                               $item_arr['direction']     = $direction;
+                               $item_arr['source']        = $source;
 
                                $item_arr['object']  = '<object><type>' . XML::escape(Activity\ObjectType::EVENT) . '</type><title></title><id>' . XML::escape($event['uri']) . '</id>';
                                $item_arr['object'] .= '<content>' . XML::escape(self::getBBCode($event)) . '</content>';
@@ -560,7 +592,7 @@ class Event
                $last_date = '';
                $fmt = DI::l10n()->t('l, F j');
                foreach ($event_result as $event) {
-                       $item = Item::selectFirst(['plink', 'author-name', 'author-avatar', 'author-link'], ['id' => $event['itemid']]);
+                       $item = Post::selectFirst(['plink', 'author-name', 'author-avatar', 'author-link'], ['id' => $event['itemid']]);
                        if (!DBA::isResult($item)) {
                                // Using default values when no item had been found
                                $item = ['plink' => '', 'author-name' => '', 'author-avatar' => '', 'author-link' => ''];
@@ -596,14 +628,12 @@ class Event
 
                        $title = BBCode::convert(Strings::escapeHtml($event['summary']));
                        if (!$title) {
-                               list($title, $_trash) = explode("<br", BBCode::convert(Strings::escapeHtml($event['desc'])), 2);
+                               list($title, $_trash) = explode("<br", BBCode::convert(Strings::escapeHtml($event['desc'])), BBCode::API);
                        }
 
                        $author_link = $event['author-link'];
-                       $plink       = $event['plink'];
 
                        $event['author-link'] = Contact::magicLink($author_link);
-                       $event['plink']       = Contact::magicLink($author_link, $plink);
 
                        $html = self::getHTML($event);
                        $event['summary']  = BBCode::convert(Strings::escapeHtml($event['summary']));
@@ -623,7 +653,7 @@ class Event
                                'is_first' => $is_first,
                                'item'     => $event,
                                'html'     => $html,
-                               'plink'    => [$event['plink'], DI::l10n()->t('link to source'), '', ''],
+                               'plink'    => Item::getPlink($event),
                        ];
                }