X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FModel%2FEvent.php;h=dc818d8f15715055392137f5151ed2e7b78fd88e;hb=e2e95f7d7207830a185d260b07f61c2cd9e7186e;hp=6f8ed123c17396bc4fd6e45f8405e13e33018967;hpb=dc42dbb68a50fb2c60f439393eb6d1fe80b327cf;p=friendica.git
diff --git a/src/Model/Event.php b/src/Model/Event.php
index 6f8ed123c1..dc818d8f15 100644
--- a/src/Model/Event.php
+++ b/src/Model/Event.php
@@ -1,6 +1,6 @@
t('l F d, Y \@ g:i A'); // Friday January 18, 2011 @ 8 AM.
+ $uriid = $event['uri-id'] ?? $uriid;
- $event_start = DI::l10n()->getDay(
- !empty($event['adjust']) ?
- DateTimeFormat::local($event['start'], $bd_format) : DateTimeFormat::utc($event['start'], $bd_format)
- );
+ $bd_format = DI::l10n()->t('l F d, Y \@ g:i A \G\M\TP (e)'); // Friday October 29, 2021 @ 9:15 AM GMT-04:00 (America/New_York)
+
+ $event_start = DI::l10n()->getDay(DateTimeFormat::local($event['start'], $bd_format));
if (!empty($event['finish'])) {
- $event_end = DI::l10n()->getDay(
- !empty($event['adjust']) ?
- DateTimeFormat::local($event['finish'], $bd_format) : DateTimeFormat::utc($event['finish'], $bd_format)
- );
+ $event_end = DI::l10n()->getDay(DateTimeFormat::local($event['finish'], $bd_format));
} else {
$event_end = '';
}
@@ -67,11 +65,11 @@ class Event
$o = '';
if (!empty($event['summary'])) {
- $o .= "
" . BBCode::convert(Strings::escapeHtml($event['desc']), false, $simple) . "
";
+ $o .= "" . BBCode::convertForUriId($uriid, Strings::escapeHtml($event['desc']), $simple) . "
";
}
$o .= "" . $event_start . "
";
@@ -81,7 +79,7 @@ class Event
}
if (!empty($event['location'])) {
- $o .= "" . BBCode::convert(Strings::escapeHtml($event['location']), false, $simple) . "
";
+ $o .= "" . BBCode::convertForUriId($uriid, Strings::escapeHtml($event['location']), $simple) . "
";
}
return $o;
@@ -89,27 +87,27 @@ class Event
$o = '' . "\r\n";
- $o .= '
' . BBCode::convert(Strings::escapeHtml($event['summary']), false, $simple) . '
' . "\r\n";
+ $o .= '
' . BBCode::convertForUriId($uriid, Strings::escapeHtml($event['summary']), $simple) . '
' . "\r\n";
$o .= '
' . DI::l10n()->t('Starts:') . ' ' . $event_start
. '
' . "\r\n";
if (!$event['nofinish']) {
$o .= '
' . DI::l10n()->t('Finishes:') . ' ' . $event_end
. '
' . "\r\n";
}
if (!empty($event['desc'])) {
- $o .= '
' . BBCode::convert(Strings::escapeHtml($event['desc']), false, $simple) . '
' . "\r\n";
+ $o .= '
' . BBCode::convertForUriId($uriid, Strings::escapeHtml($event['desc']), $simple) . '
' . "\r\n";
}
if (!empty($event['location'])) {
$o .= '
' . DI::l10n()->t('Location:') . ' '
- . BBCode::convert(Strings::escapeHtml($event['location']), false, $simple)
+ . BBCode::convertForUriId($uriid, Strings::escapeHtml($event['location']), $simple)
. '
' . "\r\n";
// Include a map of the location if the [map] BBCode is used.
@@ -131,7 +129,7 @@ class Event
* @param array $event Array which contains the event data.
* @return string The event as a bbcode formatted string.
*/
- private static function getBBCode(array $event)
+ private static function getBBCode(array $event): string
{
$o = '';
@@ -155,69 +153,59 @@ class Event
$o .= '[event-location]' . $event['location'] . '[/event-location]';
}
- if ($event['adjust']) {
- $o .= '[event-adjust]' . $event['adjust'] . '[/event-adjust]';
- }
-
return $o;
}
/**
* Extract bbcode formatted event data from a string.
*
- * @params: string $s The string which should be parsed for event data.
- * @param $text
+ * @param string $text The string which should be parsed for event data.
* @return array The array with the event information.
*/
- public static function fromBBCode($text)
+ public static function fromBBCode(string $text): array
{
$ev = [];
- $match = '';
+ $match = [];
if (preg_match("/\[event\-summary\](.*?)\[\/event\-summary\]/is", $text, $match)) {
$ev['summary'] = $match[1];
}
- $match = '';
+ $match = [];
if (preg_match("/\[event\-description\](.*?)\[\/event\-description\]/is", $text, $match)) {
$ev['desc'] = $match[1];
}
- $match = '';
+ $match = [];
if (preg_match("/\[event\-start\](.*?)\[\/event\-start\]/is", $text, $match)) {
$ev['start'] = $match[1];
}
- $match = '';
+ $match = [];
if (preg_match("/\[event\-finish\](.*?)\[\/event\-finish\]/is", $text, $match)) {
$ev['finish'] = $match[1];
}
- $match = '';
+ $match = [];
if (preg_match("/\[event\-location\](.*?)\[\/event\-location\]/is", $text, $match)) {
$ev['location'] = $match[1];
}
- $match = '';
- if (preg_match("/\[event\-adjust\](.*?)\[\/event\-adjust\]/is", $text, $match)) {
- $ev['adjust'] = $match[1];
- }
-
$ev['nofinish'] = !empty($ev['start']) && empty($ev['finish']) ? 1 : 0;
return $ev;
}
- public static function sortByDate($event_list)
+ public static function sortByDate(array $event_list): array
{
- usort($event_list, ['self', 'compareDatesCallback']);
+ usort($event_list, [self::class, 'compareDatesCallback']);
return $event_list;
}
- private static function compareDatesCallback($event_a, $event_b)
+ private static function compareDatesCallback(array $event_a, array $event_b)
{
- $date_a = (($event_a['adjust']) ? DateTimeFormat::local($event_a['start']) : $event_a['start']);
- $date_b = (($event_b['adjust']) ? DateTimeFormat::local($event_b['start']) : $event_b['start']);
+ $date_a = DateTimeFormat::local($event_a['start']);
+ $date_b = DateTimeFormat::local($event_b['start']);
if ($date_a === $date_b) {
return strcasecmp($event_a['desc'], $event_b['desc']);
@@ -236,14 +224,14 @@ class Event
* @return void
* @throws \Exception
*/
- public static function delete($event_id)
+ public static function delete(int $event_id)
{
if ($event_id == 0) {
return;
}
- DBA::delete('event', ['id' => $event_id], ['cascade' => false]);
- Logger::log("Deleted event ".$event_id, Logger::DEBUG);
+ DBA::delete('event', ['id' => $event_id]);
+ Logger::info("Deleted event", ['id' => $event_id]);
}
/**
@@ -255,52 +243,47 @@ class Event
* @return int The new event id.
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
- public static function store($arr)
+ public static function store(array $arr): int
{
- $event = [];
- $event['id'] = intval($arr['id'] ?? 0);
- $event['uid'] = intval($arr['uid'] ?? 0);
- $event['cid'] = intval($arr['cid'] ?? 0);
- $event['guid'] = ($arr['guid'] ?? '') ?: System::createUUID();
- $event['uri'] = ($arr['uri'] ?? '') ?: Item::newURI($event['uid'], $event['guid']);
- $event['type'] = ($arr['type'] ?? '') ?: 'event';
- $event['summary'] = $arr['summary'] ?? '';
- $event['desc'] = $arr['desc'] ?? '';
- $event['location'] = $arr['location'] ?? '';
- $event['allow_cid'] = $arr['allow_cid'] ?? '';
- $event['allow_gid'] = $arr['allow_gid'] ?? '';
- $event['deny_cid'] = $arr['deny_cid'] ?? '';
- $event['deny_gid'] = $arr['deny_gid'] ?? '';
- $event['adjust'] = intval($arr['adjust'] ?? 0);
- $event['nofinish'] = intval($arr['nofinish'] ?? (!empty($event['start']) && empty($event['finish'])));
-
- $event['created'] = DateTimeFormat::utc(($arr['created'] ?? '') ?: 'now');
- $event['edited'] = DateTimeFormat::utc(($arr['edited'] ?? '') ?: 'now');
- $event['start'] = DateTimeFormat::utc(($arr['start'] ?? '') ?: DBA::NULL_DATETIME);
- $event['finish'] = DateTimeFormat::utc(($arr['finish'] ?? '') ?: DBA::NULL_DATETIME);
+ $guid = $arr['guid'] ?? '' ?: System::createUUID();
+ $uri = $arr['uri'] ?? '' ?: Item::newURI($guid);
+ $event = [
+ 'id' => intval($arr['id'] ?? 0),
+ 'uid' => intval($arr['uid'] ?? 0),
+ 'cid' => intval($arr['cid'] ?? 0),
+ 'guid' => $guid,
+ 'uri' => $uri,
+ 'uri-id' => ItemURI::insert(['uri' => $uri, 'guid' => $guid]),
+ 'type' => ($arr['type'] ?? '') ?: 'event',
+ 'summary' => $arr['summary'] ?? '',
+ 'desc' => $arr['desc'] ?? '',
+ 'location' => $arr['location'] ?? '',
+ 'allow_cid' => $arr['allow_cid'] ?? '',
+ 'allow_gid' => $arr['allow_gid'] ?? '',
+ 'deny_cid' => $arr['deny_cid'] ?? '',
+ 'deny_gid' => $arr['deny_gid'] ?? '',
+ 'nofinish' => intval($arr['nofinish'] ?? (!empty($arr['start']) && empty($arr['finish']))),
+ 'created' => DateTimeFormat::utc(($arr['created'] ?? '') ?: 'now'),
+ 'edited' => DateTimeFormat::utc(($arr['edited'] ?? '') ?: 'now'),
+ 'start' => DateTimeFormat::utc(($arr['start'] ?? '') ?: DBA::NULL_DATETIME),
+ 'finish' => DateTimeFormat::utc(($arr['finish'] ?? '') ?: DBA::NULL_DATETIME),
+ ];
+
+
if ($event['finish'] < DBA::NULL_DATETIME) {
$event['finish'] = DBA::NULL_DATETIME;
}
- $private = intval($arr['private'] ?? 0);
-
- $conditions = ['uid' => $event['uid']];
- if ($event['cid']) {
- $conditions['id'] = $event['cid'];
- } else {
- $conditions['self'] = true;
- }
-
- $contact = DBA::selectFirst('contact', [], $conditions);
// Existing event being modified.
if ($event['id']) {
// has the event actually changed?
$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']]);
+ if (!DBA::isResult($existing_event)) {
+ return 0;
+ }
- return DBA::isResult($item) ? $item['id'] : 0;
+ if ($existing_event['edited'] === $event['edited']) {
+ return $event['id'];
}
$updated_fields = [
@@ -311,13 +294,12 @@ class Event
'desc' => $event['desc'],
'location' => $event['location'],
'type' => $event['type'],
- 'adjust' => $event['adjust'],
'nofinish' => $event['nofinish'],
];
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', 'uri-id'], ['event-id' => $event['id'], 'uid' => $event['uid']]);
if (DBA::isResult($item)) {
$object = '