]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/Event.php
Issue 10506 - again. Improved check for pictured in body
[friendica.git] / src / Model / Event.php
index e6c60928320d4db60dde4d6b1ba208c586060902..ed1cff9c310e28930c7cf7bdb39a442d4f049f83 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2020, Friendica
+ * @copyright Copyright (C) 2010-2021, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
@@ -41,12 +41,14 @@ use Friendica\Util\XML;
 class Event
 {
 
-       public static function getHTML(array $event, $simple = false)
+       public static function getHTML(array $event, $simple = false, $uriid = 0)
        {
                if (empty($event)) {
                        return '';
                }
 
+               $uriid = $event['uri-id'] ?? $uriid;
+
                $bd_format = DI::l10n()->t('l F d, Y \@ g:i A'); // Friday January 18, 2011 @ 8 AM.
 
                $event_start = DI::l10n()->getDay(
@@ -67,11 +69,11 @@ class Event
                        $o = '';
 
                        if (!empty($event['summary'])) {
-                               $o .= "<h3>" . BBCode::convert(Strings::escapeHtml($event['summary']), false, $simple) . "</h3>";
+                               $o .= "<h3>" . BBCode::convertForUriId($uriid, Strings::escapeHtml($event['summary']), $simple) . "</h3>";
                        }
 
                        if (!empty($event['desc'])) {
-                               $o .= "<div>" . BBCode::convert(Strings::escapeHtml($event['desc']), false, $simple) . "</div>";
+                               $o .= "<div>" . BBCode::convertForUriId($uriid, Strings::escapeHtml($event['desc']), $simple) . "</div>";
                        }
 
                        $o .= "<h4>" . DI::l10n()->t('Starts:') . "</h4><p>" . $event_start . "</p>";
@@ -81,7 +83,7 @@ class Event
                        }
 
                        if (!empty($event['location'])) {
-                               $o .= "<h4>" . DI::l10n()->t('Location:') . "</h4><p>" . BBCode::convert(Strings::escapeHtml($event['location']), false, $simple) . "</p>";
+                               $o .= "<h4>" . DI::l10n()->t('Location:') . "</h4><p>" . BBCode::convertForUriId($uriid, Strings::escapeHtml($event['location']), $simple) . "</p>";
                        }
 
                        return $o;
@@ -89,7 +91,7 @@ class Event
 
                $o = '<div class="vevent">' . "\r\n";
 
-               $o .= '<div class="summary event-summary">' . BBCode::convert(Strings::escapeHtml($event['summary']), false, $simple) . '</div>' . "\r\n";
+               $o .= '<div class="summary event-summary">' . BBCode::convertForUriId($uriid, Strings::escapeHtml($event['summary']), $simple) . '</div>' . "\r\n";
 
                $o .= '<div class="event-start"><span class="event-label">' . DI::l10n()->t('Starts:') . '</span>&nbsp;<span class="dtstart" title="'
                        . DateTimeFormat::utc($event['start'], (!empty($event['adjust']) ? DateTimeFormat::ATOM : 'Y-m-d\TH:i:s'))
@@ -104,12 +106,12 @@ class Event
                }
 
                if (!empty($event['desc'])) {
-                       $o .= '<div class="description event-description">' . BBCode::convert(Strings::escapeHtml($event['desc']), false, $simple) . '</div>' . "\r\n";
+                       $o .= '<div class="description event-description">' . BBCode::convertForUriId($uriid, Strings::escapeHtml($event['desc']), $simple) . '</div>' . "\r\n";
                }
 
                if (!empty($event['location'])) {
                        $o .= '<div class="event-location"><span class="event-label">' . DI::l10n()->t('Location:') . '</span>&nbsp;<span class="location">'
-                               . BBCode::convert(Strings::escapeHtml($event['location']), false, $simple)
+                               . BBCode::convertForUriId($uriid, Strings::escapeHtml($event['location']), $simple)
                                . '</span></div>' . "\r\n";
 
                        // Include a map of the location if the [map] BBCode is used.
@@ -242,7 +244,7 @@ class Event
                        return;
                }
 
-               DBA::delete('event', ['id' => $event_id], ['cascade' => false]);
+               DBA::delete('event', ['id' => $event_id]);
                Logger::log("Deleted event ".$event_id, Logger::DEBUG);
        }
 
@@ -273,6 +275,7 @@ class Event
                $event['cid']       = intval($arr['cid']       ?? 0);
                $event['guid']      =       ($arr['guid']      ?? '') ?: System::createUUID();
                $event['uri']       =       ($arr['uri']       ?? '') ?: Item::newURI($event['uid'], $event['guid']);
+               $event['uri-id']    = ItemURI::insert(['uri' => $event['uri'], 'guid' => $event['guid']]);
                $event['type']      =       ($arr['type']      ?? '') ?: 'event';
                $event['summary']   =        $arr['summary']   ?? '';
                $event['desc']      =        $arr['desc']      ?? '';
@@ -293,11 +296,10 @@ class Event
                }
                $private = intval($arr['private'] ?? 0);
 
-               $conditions = ['uid' => $event['uid']];
                if ($event['cid']) {
-                       $conditions['id'] = $event['cid'];
+                       $conditions = ['id' => $event['cid']];
                } else {
-                       $conditions['self'] = true;
+                       $conditions = ['uid' => $event['uid'], 'self' => true];
                }
 
                $contact = DBA::selectFirst('contact', [], $conditions);
@@ -381,6 +383,7 @@ class Event
                                $item_arr['visible']       = 1;
                                $item_arr['verb']          = Activity::POST;
                                $item_arr['object-type']   = Activity\ObjectType::EVENT;
+                               $item_arr['post-type']     = Item::PT_EVENT;
                                $item_arr['origin']        = $event['cid'] === 0 ? 1 : 0;
                                $item_arr['body']          = self::getBBCode($event);
                                $item_arr['event-id']      = $event['id'];
@@ -516,9 +519,9 @@ class Event
                }
 
                // Query for the event by event id
-               $events = DBA::toArray(DBA::p("SELECT `event`.*, `post-view`.`id` AS `itemid` FROM `event`
-                       LEFT JOIN `post-view` ON `post-view`.`event-id` = `event`.`id` AND `post-view`.`uid` = `event`.`uid`
-                       WHERE `event`.`uid` = %d AND `event`.`id` = %d $sql_extra",
+               $events = DBA::toArray(DBA::p("SELECT `event`.*, `post-user-view`.`id` AS `itemid` FROM `event`
+                       LEFT JOIN `post-user-view` ON `post-user-view`.`event-id` = `event`.`id` AND `post-user-view`.`uid` = `event`.`uid`
+                       WHERE `event`.`uid` = ? AND `event`.`id` = ? $sql_extra",
                        $owner_uid, $event_id));
 
                if (DBA::isResult($events)) {
@@ -555,8 +558,8 @@ class Event
 
                // Query for the event by date.
                // @todo Slow query (518 seconds to run), to be optimzed
-               $events = DBA::toArray(DBA::p("SELECT `event`.*, `post-view`.`id` AS `itemid` FROM `event`
-                               LEFT JOIN `post-view` ON `post-view`.`event-id` = `event`.`id` AND `post-view`.`uid` = `event`.`uid`
+               $events = DBA::toArray(DBA::p("SELECT `event`.*, `post-user-view`.`id` AS `itemid` FROM `event`
+                               LEFT JOIN `post-user-view` ON `post-user-view`.`event-id` = `event`.`id` AND `post-user-view`.`uid` = `event`.`uid`
                                WHERE `event`.`uid` = ? AND `event`.`ignore` = ?
                                AND ((NOT `adjust` AND (`finish` >= ? OR (`nofinish` AND `start` >= ?)) AND `start` <= ?)
                                OR  (`adjust` AND (`finish` >= ? OR (`nofinish` AND `start` >= ?)) AND `start` <= ?))" . $sql_extra,
@@ -586,10 +589,10 @@ class Event
                $last_date = '';
                $fmt = DI::l10n()->t('l, F j');
                foreach ($event_result as $event) {
-                       $item = Post::selectFirst(['plink', 'author-name', 'author-avatar', 'author-link'], ['id' => $event['itemid']]);
+                       $item = Post::selectFirst(['plink', 'author-name', 'author-avatar', 'author-link', 'private', 'uri-id'], ['id' => $event['itemid']]);
                        if (!DBA::isResult($item)) {
                                // Using default values when no item had been found
-                               $item = ['plink' => '', 'author-name' => '', 'author-avatar' => '', 'author-link' => ''];
+                               $item = ['plink' => '', 'author-name' => '', 'author-avatar' => '', 'author-link' => '', 'private' => Item::PUBLIC, 'uri-id' => ($event['uri-id'] ?? 0)];
                        }
 
                        $event = array_merge($event, $item);
@@ -620,9 +623,9 @@ class Event
                                $drop =                  [DI::baseUrl() . '/events/drop/' . $event['id'] , DI::l10n()->t('Delete event')   , '', ''];
                        }
 
-                       $title = BBCode::convert(Strings::escapeHtml($event['summary']));
+                       $title = BBCode::convertForUriId($event['uri-id'], Strings::escapeHtml($event['summary']));
                        if (!$title) {
-                               list($title, $_trash) = explode("<br", BBCode::convert(Strings::escapeHtml($event['desc'])), BBCode::API);
+                               list($title, $_trash) = explode("<br", BBCode::convertForUriId($event['uri-id'], Strings::escapeHtml($event['desc'])), BBCode::API);
                        }
 
                        $author_link = $event['author-link'];
@@ -630,9 +633,9 @@ class Event
                        $event['author-link'] = Contact::magicLink($author_link);
 
                        $html = self::getHTML($event);
-                       $event['summary']  = BBCode::convert(Strings::escapeHtml($event['summary']));
-                       $event['desc']     = BBCode::convert(Strings::escapeHtml($event['desc']));
-                       $event['location'] = BBCode::convert(Strings::escapeHtml($event['location']));
+                       $event['summary']  = BBCode::convertForUriId($event['uri-id'], Strings::escapeHtml($event['summary']));
+                       $event['desc']     = BBCode::convertForUriId($event['uri-id'], Strings::escapeHtml($event['desc']));
+                       $event['location'] = BBCode::convertForUriId($event['uri-id'], Strings::escapeHtml($event['location']));
                        $event_list[] = [
                                'id'       => $event['id'],
                                'start'    => $start,
@@ -930,12 +933,14 @@ class Event
                $location = self::locationToArray($item['event-location']);
 
                // Construct the profile link (magic-auth).
-               $profile_link = Contact::magicLinkById($item['author-id']);
+               $author = ['uid' => 0, 'id' => $item['author-id'],
+                               'network' => $item['author-network'], 'url' => $item['author-link']];
+               $profile_link = Contact::magicLinkByContact($author);
 
                $tpl = Renderer::getMarkupTemplate('event_stream_item.tpl');
                $return = Renderer::replaceMacros($tpl, [
                        '$id'             => $item['event-id'],
-                       '$title'          => BBCode::convert($item['event-summary']),
+                       '$title'          => BBCode::convertForUriId($item['uri-id'], $item['event-summary']),
                        '$dtstart_label'  => DI::l10n()->t('Starts:'),
                        '$dtstart_title'  => $dtstart_title,
                        '$dtstart_dt'     => $dtstart_dt,
@@ -953,7 +958,7 @@ class Event
                        '$author_name'    => $item['author-name'],
                        '$author_link'    => $profile_link,
                        '$author_avatar'  => $item['author-avatar'],
-                       '$description'    => BBCode::convert($item['event-desc']),
+                       '$description'    => BBCode::convertForUriId($item['uri-id'], $item['event-desc']),
                        '$location_label' => DI::l10n()->t('Location:'),
                        '$show_map_label' => DI::l10n()->t('Show map'),
                        '$hide_map_label' => DI::l10n()->t('Hide map'),