X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FModel%2FEvent.php;h=ec39cc7133d6efcdf1a555d87f71e7ba27f4a682;hb=6b8db5ad1333e2b430da3a771d9a962d44d4b6fc;hp=886f124153ac0a41bbbd1e7f58f6f4907aeba085;hpb=ced4911c4ab268c9e502a3c3e1aa43ebda837044;p=friendica.git
diff --git a/src/Model/Event.php b/src/Model/Event.php
index 886f124153..ec39cc7133 100644
--- a/src/Model/Event.php
+++ b/src/Model/Event.php
@@ -5,28 +5,25 @@
namespace Friendica\Model;
-use Friendica\BaseObject;
use Friendica\Content\Text\BBCode;
-use Friendica\Core\Addon;
+use Friendica\Core\Hook;
use Friendica\Core\L10n;
use Friendica\Core\Logger;
use Friendica\Core\PConfig;
use Friendica\Core\Renderer;
use Friendica\Core\System;
use Friendica\Database\DBA;
-use Friendica\Model\Contact;
+use Friendica\DI;
+use Friendica\Protocol\Activity;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Map;
+use Friendica\Util\Strings;
use Friendica\Util\XML;
-require_once 'boot.php';
-require_once 'include/dba.php';
-require_once 'include/items.php';
-
/**
* @brief functions for interacting with the event database table
*/
-class Event extends BaseObject
+class Event
{
public static function getHTML(array $event, $simple = false)
@@ -52,12 +49,14 @@ class Event extends BaseObject
}
if ($simple) {
+ $o = '';
+
if (!empty($event['summary'])) {
- $o = "
" . BBCode::convert($event['desc'], false, $simple) . "
";
+ $o .= "" . BBCode::convert(Strings::escapeHtml($event['desc']), false, $simple) . "
";
}
$o .= "" . $event_start . "
";
@@ -67,7 +66,7 @@ class Event extends BaseObject
}
if (!empty($event['location'])) {
- $o .= "" . BBCode::convert($event['location'], false, $simple) . "
";
+ $o .= "" . BBCode::convert(Strings::escapeHtml($event['location']), false, $simple) . "
";
}
return $o;
@@ -75,7 +74,7 @@ class Event extends BaseObject
$o = '' . "\r\n";
- $o .= '
' . BBCode::convert($event['summary'], false, $simple) . '
' . "\r\n";
+ $o .= '
' . BBCode::convert(Strings::escapeHtml($event['summary']), false, $simple) . '
' . "\r\n";
$o .= '
' . L10n::t('Starts:') . ' ' . BBCode::convert($event['desc'], false, $simple) . '
' . "\r\n";
+ $o .= '
' . BBCode::convert(Strings::escapeHtml($event['desc']), false, $simple) . '
' . "\r\n";
}
if (!empty($event['location'])) {
$o .= '
' . L10n::t('Location:') . ' '
- . BBCode::convert($event['location'], false, $simple)
+ . BBCode::convert(Strings::escapeHtml($event['location']), false, $simple)
. '
' . "\r\n";
// Include a map of the location if the [map] BBCode is used.
@@ -152,6 +151,7 @@ class Event extends BaseObject
* @brief Extract bbcode formatted event data from a string.
*
* @params: string $s The string which should be parsed for event data.
+ * @param $text
* @return array The array with the event information.
*/
public static function fromBBCode($text)
@@ -219,6 +219,7 @@ class Event extends BaseObject
*
* @param int $event_id Event ID.
* @return void
+ * @throws \Exception
*/
public static function delete($event_id)
{
@@ -226,7 +227,7 @@ class Event extends BaseObject
return;
}
- DBA::delete('event', ['id' => $event_id]);
+ DBA::delete('event', ['id' => $event_id], ['cascade' => false]);
Logger::log("Deleted event ".$event_id, Logger::DEBUG);
}
@@ -237,35 +238,35 @@ class Event extends BaseObject
*
* @param array $arr Array with event data.
* @return int The new event id.
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
public static function store($arr)
{
- $a = self::getApp();
-
$event = [];
- $event['id'] = intval(defaults($arr, 'id' , 0));
- $event['uid'] = intval(defaults($arr, 'uid' , 0));
- $event['cid'] = intval(defaults($arr, 'cid' , 0));
- $event['uri'] = defaults($arr, 'uri' , Item::newURI($event['uid']));
- $event['type'] = defaults($arr, 'type' , 'event');
- $event['summary'] = defaults($arr, 'summary' , '');
- $event['desc'] = defaults($arr, 'desc' , '');
- $event['location'] = defaults($arr, 'location' , '');
- $event['allow_cid'] = defaults($arr, 'allow_cid', '');
- $event['allow_gid'] = defaults($arr, 'allow_gid', '');
- $event['deny_cid'] = defaults($arr, 'deny_cid' , '');
- $event['deny_gid'] = defaults($arr, 'deny_gid' , '');
- $event['adjust'] = intval(defaults($arr, 'adjust' , 0));
- $event['nofinish'] = intval(defaults($arr, 'nofinish' , !empty($event['start']) && empty($event['finish'])));
-
- $event['created'] = DateTimeFormat::utc(defaults($arr, 'created' , 'now'));
- $event['edited'] = DateTimeFormat::utc(defaults($arr, 'edited' , 'now'));
- $event['start'] = DateTimeFormat::utc(defaults($arr, 'start' , DBA::NULL_DATETIME));
- $event['finish'] = DateTimeFormat::utc(defaults($arr, 'finish' , DBA::NULL_DATETIME));
+ $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);
if ($event['finish'] < DBA::NULL_DATETIME) {
$event['finish'] = DBA::NULL_DATETIME;
}
- $private = intval(defaults($arr, 'private', 0));
+ $private = intval($arr['private'] ?? 0);
$conditions = ['uid' => $event['uid']];
if ($event['cid']) {
@@ -303,7 +304,7 @@ class Event extends BaseObject
$item = Item::selectFirst(['id'], ['event-id' => $event['id'], 'uid' => $event['uid']]);
if (DBA::isResult($item)) {
- $object = '