+ ]);
+}
+
+/**
+ * @brief Format an item array with event data to HTML.
+ *
+ * @param arr $item Array with item and event data.
+ * @return string HTML output.
+ */
+function format_event_item($item) {
+ $same_date = false;
+ $finish = false;
+
+ // Set the different time formats.
+ $dformat = L10n::t('l F d, Y \@ g:i A'); // Friday January 18, 2011 @ 8:01 AM.
+ $dformat_short = L10n::t('D g:i A'); // Fri 8:01 AM.
+ $tformat = L10n::t('g:i A'); // 8:01 AM.
+
+ // Convert the time to different formats.
+ $dtstart_dt = day_translate(
+ $item['event-adjust'] ?
+ Temporal::convert($item['event-start'], date_default_timezone_get(), 'UTC', $dformat)
+ : Temporal::utc($item['event-start'], $dformat)
+ );
+ $dtstart_title = Temporal::utc($item['event-start'], $item['event-adjust'] ? Temporal::ATOM : 'Y-m-d\TH:i:s');
+ // Format: Jan till Dec.
+ $month_short = day_short_translate(
+ $item['event-adjust'] ?
+ Temporal::convert($item['event-start'], date_default_timezone_get(), 'UTC', 'M')
+ : Temporal::utc($item['event-start'], 'M')
+ );
+ // Format: 1 till 31.
+ $date_short = $item['event-adjust'] ?
+ Temporal::convert($item['event-start'], date_default_timezone_get(), 'UTC', 'j')
+ : Temporal::utc($item['event-start'], 'j');
+ $start_time = $item['event-adjust'] ?
+ Temporal::convert($item['event-start'], date_default_timezone_get(), 'UTC', $tformat)
+ : Temporal::utc($item['event-start'], $tformat);
+ $start_short = day_short_translate(
+ $item['event-adjust'] ?
+ Temporal::convert($item['event-start'], date_default_timezone_get(), 'UTC', $dformat_short)
+ : Temporal::utc($item['event-start'], $dformat_short)
+ );
+
+ // If the option 'nofinisch' isn't set, we need to format the finish date/time.
+ if (!$item['event-nofinish']) {
+ $finish = true;
+ $dtend_dt = day_translate(
+ $item['event-adjust'] ?
+ Temporal::convert($item['event-finish'], date_default_timezone_get(), 'UTC', $dformat)
+ : Temporal::utc($item['event-finish'], $dformat)
+ );
+ $dtend_title = Temporal::utc($item['event-finish'], $item['event-adjust'] ? Temporal::ATOM : 'Y-m-d\TH:i:s');
+ $end_short = day_short_translate(
+ $item['event-adjust'] ?
+ Temporal::convert($item['event-finish'], date_default_timezone_get(), 'UTC', $dformat_short)
+ : Temporal::utc($item['event-finish'], $dformat_short)
+ );
+ $end_time = $item['event-adjust'] ?
+ Temporal::convert($item['event-finish'], date_default_timezone_get(), 'UTC', $tformat)
+ : Temporal::utc($item['event-finish'], $tformat);
+ // Check if start and finish time is at the same day.
+ if (substr($dtstart_title, 0, 10) === substr($dtend_title, 0, 10)) {
+ $same_date = true;
+ }
+ }
+
+ // Format the event location.
+ $evloc = event_location2array($item['event-location']);
+ $location = [];
+
+ if (isset($evloc['name'])) {
+ $location['name'] = prepare_text($evloc['name']);
+ }
+ // Construct the map HTML.
+ if (isset($evloc['address'])) {
+ $location['map'] = '<div class="map">' . Map::byLocation($evloc['address']) . '</div>';
+ } elseif (isset($evloc['coordinates'])) {
+ $location['map'] = '<div class="map">' . Map::byCoordinates(str_replace('/', ' ', $evloc['coordinates'])) . '</div>';
+ }
+
+ // Construct the profile link (magic-auth).
+ $sp = false;
+ $profile_link = best_link_url($item, $sp);
+
+ if (!$sp) {
+ $profile_link = Profile::zrl($profile_link);
+ }
+
+ $event = replace_macros(get_markup_template('event_stream_item.tpl'), [
+ '$id' => $item['event-id'],
+ '$title' => prepare_text($item['event-summary']),
+ '$dtstart_label' => L10n::t('Starts:'),
+ '$dtstart_title' => $dtstart_title,
+ '$dtstart_dt' => $dtstart_dt,
+ '$finish' => $finish,
+ '$dtend_label' => L10n::t('Finishes:'),
+ '$dtend_title' => $dtend_title,
+ '$dtend_dt' => $dtend_dt,
+ '$month_short' => $month_short,
+ '$date_short' => $date_short,
+ '$same_date' => $same_date,
+ '$start_time' => $start_time,
+ '$start_short' => $start_short,
+ '$end_time' => $end_time,
+ '$end_short' => $end_short,
+ '$author_name' => $item['author-name'],
+ '$author_link' => $profile_link,
+ '$author_avatar' => $item['author-avatar'],
+ '$description' => prepare_text($item['event-desc']),
+ '$location_label' => L10n::t('Location:'),
+ '$show_map_label' => L10n::t('Show map'),
+ '$hide_map_label' => L10n::t('Hide map'),
+ '$map_btn_label' => L10n::t('Show map'),
+ '$location' => $location
+ ]);
+
+ return $event;
+}
+
+/**
+ * @brief Format a string with map bbcode to an array with location data.
+ *
+ * Note: The string must only contain location data. A string with no bbcode will be
+ * handled as location name.
+ *
+ * @param string $s The string with the bbcode formatted location data.
+ *
+ * @return array The array with the location data.
+ * 'name' => The name of the location,<br>
+ * 'address' => The address of the location,<br>
+ * 'coordinates' => Latitude and longitude (e.g. '48.864716,2.349014').<br>
+ */
+function event_location2array($s = '') {
+ if ($s == '') {
+ return;
+ }
+
+ $location = ['name' => $s];
+
+ // Map tag with location name - e.g. [map]Paris[/map].
+ if (strpos($s, '[/map]') !== false) {
+ $found = preg_match("/\[map\](.*?)\[\/map\]/ism", $s, $match);
+ if (intval($found) > 0 && array_key_exists(1, $match)) {
+ $location['address'] = $match[1];
+ // Remove the map bbcode from the location name.
+ $location['name'] = str_replace($match[0], "", $s);
+ }
+ // Map tag with coordinates - e.g. [map=48.864716,2.349014].
+ } elseif (strpos($s, '[map=') !== false) {
+ $found = preg_match("/\[map=(.*?)\]/ism", $s, $match);
+ if (intval($found) > 0 && array_key_exists(1, $match)) {
+ $location['coordinates'] = $match[1];
+ // Remove the map bbcode from the location name.
+ $location['name'] = str_replace($match[0], "", $s);
+ }
+ }
+
+ return $location;