1
0
Fork 0

Replace include/event function with method calls

- Updated scope of Model\Event methods
- Updated use list
This commit is contained in:
Hypolite Petovan 2018-03-16 21:45:02 -04:00
parent 5aecc758f9
commit f7e2071117
7 changed files with 55 additions and 53 deletions

View file

@ -14,6 +14,7 @@ use Friendica\Core\L10n;
use Friendica\Core\PConfig; use Friendica\Core\PConfig;
use Friendica\Core\System; use Friendica\Core\System;
use Friendica\Database\DBM; use Friendica\Database\DBM;
use Friendica\Model\Event;
use Friendica\Model\Item; use Friendica\Model\Item;
use Friendica\Model\Profile; use Friendica\Model\Profile;
use Friendica\Render\FriendicaSmarty; use Friendica\Render\FriendicaSmarty;
@ -1235,7 +1236,7 @@ function prepare_body(&$item, $attach = false, $preview = false) {
// In order to provide theme developers more possibilities, event items // In order to provide theme developers more possibilities, event items
// are treated differently. // are treated differently.
if ($item['object-type'] === ACTIVITY_OBJ_EVENT && isset($item['event-id'])) { if ($item['object-type'] === ACTIVITY_OBJ_EVENT && isset($item['event-id'])) {
$ev = format_event_item($item); $ev = Event::getItemHTML($item);
return $ev; return $ev;
} }

View file

@ -9,11 +9,13 @@
use Friendica\App; use Friendica\App;
use Friendica\Content\Feature; use Friendica\Content\Feature;
use Friendica\Content\Nav; use Friendica\Content\Nav;
use Friendica\Content\Widget;
use Friendica\Core\Config; use Friendica\Core\Config;
use Friendica\Core\L10n; use Friendica\Core\L10n;
use Friendica\Core\System; use Friendica\Core\System;
use Friendica\Database\DBM; use Friendica\Database\DBM;
use Friendica\Model\Contact; use Friendica\Model\Contact;
use Friendica\Model\Event;
use Friendica\Model\Group; use Friendica\Model\Group;
use Friendica\Model\Profile; use Friendica\Model\Profile;
use Friendica\Protocol\DFRN; use Friendica\Protocol\DFRN;
@ -64,7 +66,7 @@ function cal_init(App $a)
'$pdesc' => (($profile['pdesc'] != "") ? $profile['pdesc'] : ""), '$pdesc' => (($profile['pdesc'] != "") ? $profile['pdesc'] : ""),
]); ]);
$cal_widget = widget_events(); $cal_widget = Widget\CalendarExport::getHTML();
if (!x($a->page, 'aside')) { if (!x($a->page, 'aside')) {
$a->page['aside'] = ''; $a->page['aside'] = '';
@ -82,7 +84,7 @@ function cal_content(App $a)
Nav::setSelected('events'); Nav::setSelected('events');
// get the translation strings for the callendar // get the translation strings for the callendar
$i18n = get_event_strings(); $i18n = Event::getStrings();
$htpl = get_markup_template('event_head.tpl'); $htpl = get_markup_template('event_head.tpl');
$a->page['htmlhead'] .= replace_macros($htpl, [ $a->page['htmlhead'] .= replace_macros($htpl, [
@ -212,25 +214,25 @@ function cal_content(App $a)
// put the event parametes in an array so we can better transmit them // put the event parametes in an array so we can better transmit them
$event_params = [ $event_params = [
'event_id' => (x($_GET, 'id') ? $_GET["id"] : 0), 'event_id' => intval(defaults($_GET, 'id', 0)),
'start' => $start, 'start' => $start,
'finish' => $finish, 'finish' => $finish,
'adjust_start' => $adjust_start, 'adjust_start' => $adjust_start,
'adjust_finish' => $adjust_finish, 'adjust_finish' => $adjust_finish,
'ignored' => $ignored, 'ignore' => $ignored,
]; ];
// get events by id or by date // get events by id or by date
if (x($_GET, 'id')) { if ($event_params['event_id']) {
$r = event_by_id($owner_uid, $event_params, $sql_extra); $r = Event::getListById($owner_uid, $event_params['event-id'], $sql_extra);
} else { } else {
$r = events_by_date($owner_uid, $event_params, $sql_extra); $r = Event::getListByDate($owner_uid, $event_params, $sql_extra);
} }
$links = []; $links = [];
if (DBM::is_result($r)) { if (DBM::is_result($r)) {
$r = sort_by_date($r); $r = Event::sortByDate($r);
foreach ($r as $rr) { foreach ($r as $rr) {
$j = $rr['adjust'] ? DateTimeFormat::local($rr['start'], 'j') : DateTimeFormat::utc($rr['start'], 'j'); $j = $rr['adjust'] ? DateTimeFormat::local($rr['start'], 'j') : DateTimeFormat::utc($rr['start'], 'j');
if (!x($links, $j)) { if (!x($links, $j)) {
@ -240,7 +242,7 @@ function cal_content(App $a)
} }
// transform the event in a usable array // transform the event in a usable array
$events = process_events($r); $events = Event::prepareListForTemplate($r);
if ($a->argv[2] === 'json') { if ($a->argv[2] === 'json') {
echo json_encode($events); echo json_encode($events);
@ -306,7 +308,7 @@ function cal_content(App $a)
} }
// Get the export data by uid // Get the export data by uid
$evexport = event_export($owner_uid, $format); $evexport = Event::exportListByUserId($owner_uid, $format);
if (!$evexport["success"]) { if (!$evexport["success"]) {
if ($evexport["content"]) { if ($evexport["content"]) {

View file

@ -6,11 +6,13 @@
use Friendica\App; use Friendica\App;
use Friendica\Content\Nav; use Friendica\Content\Nav;
use Friendica\Content\Widget\CalendarExport;
use Friendica\Core\ACL; use Friendica\Core\ACL;
use Friendica\Core\L10n; use Friendica\Core\L10n;
use Friendica\Core\System; use Friendica\Core\System;
use Friendica\Core\Worker; use Friendica\Core\Worker;
use Friendica\Database\DBM; use Friendica\Database\DBM;
use Friendica\Model\Event;
use Friendica\Model\Item; use Friendica\Model\Item;
use Friendica\Model\Profile; use Friendica\Model\Profile;
use Friendica\Util\DateTimeFormat; use Friendica\Util\DateTimeFormat;
@ -31,7 +33,7 @@ function events_init(App $a) {
return; return;
} }
$cal_widget = widget_events(); $cal_widget = CalendarExport::getHTML();
if (! x($a->page,'aside')) { if (! x($a->page,'aside')) {
$a->page['aside'] = ''; $a->page['aside'] = '';
@ -155,7 +157,6 @@ function events_post(App $a) {
$datarray = []; $datarray = [];
$datarray['guid'] = get_guid(32);
$datarray['start'] = $start; $datarray['start'] = $start;
$datarray['finish'] = $finish; $datarray['finish'] = $finish;
$datarray['summary'] = $summary; $datarray['summary'] = $summary;
@ -172,16 +173,14 @@ function events_post(App $a) {
$datarray['deny_gid'] = $str_group_deny; $datarray['deny_gid'] = $str_group_deny;
$datarray['private'] = (($private_event) ? 1 : 0); $datarray['private'] = (($private_event) ? 1 : 0);
$datarray['id'] = $event_id; $datarray['id'] = $event_id;
$datarray['created'] = $created;
$datarray['edited'] = $edited;
if (intval($_REQUEST['preview'])) { if (intval($_REQUEST['preview'])) {
$html = format_event_html($datarray); $html = Event::getHTML($datarray);
echo $html; echo $html;
killme(); killme();
} }
$item_id = event_store($datarray); $item_id = Event::store($datarray);
if (! $cid) { if (! $cid) {
Worker::add(PRIORITY_HIGH, "Notifier", "event", $item_id); Worker::add(PRIORITY_HIGH, "Notifier", "event", $item_id);
@ -222,7 +221,7 @@ function events_content(App $a) {
} }
// get the translation strings for the callendar // get the translation strings for the callendar
$i18n = get_event_strings(); $i18n = Event::getStrings();
$htpl = get_markup_template('event_head.tpl'); $htpl = get_markup_template('event_head.tpl');
$a->page['htmlhead'] .= replace_macros($htpl, [ $a->page['htmlhead'] .= replace_macros($htpl, [
@ -331,25 +330,25 @@ function events_content(App $a) {
// put the event parametes in an array so we can better transmit them // put the event parametes in an array so we can better transmit them
$event_params = [ $event_params = [
'event_id' => (x($_GET, 'id') ? $_GET['id'] : 0), 'event_id' => intval(defaults($_GET, 'id', 0)),
'start' => $start, 'start' => $start,
'finish' => $finish, 'finish' => $finish,
'adjust_start' => $adjust_start, 'adjust_start' => $adjust_start,
'adjust_finish' => $adjust_finish, 'adjust_finish' => $adjust_finish,
'ignored' => $ignored, 'ignore' => $ignored,
]; ];
// get events by id or by date // get events by id or by date
if (x($_GET, 'id')) { if ($event_params['event_id']) {
$r = event_by_id(local_user(), $event_params); $r = Event::getListById(local_user(), $event_params['event-id']);
} else { } else {
$r = events_by_date(local_user(), $event_params); $r = Event::getListByDate(local_user(), $event_params);
} }
$links = []; $links = [];
if (DBM::is_result($r)) { if (DBM::is_result($r)) {
$r = sort_by_date($r); $r = Event::sortByDate($r);
foreach ($r as $rr) { foreach ($r as $rr) {
$j = $rr['adjust'] ? DateTimeFormat::local($rr['start'], 'j') : DateTimeFormat::utc($rr['start'], 'j'); $j = $rr['adjust'] ? DateTimeFormat::local($rr['start'], 'j') : DateTimeFormat::utc($rr['start'], 'j');
if (! x($links,$j)) { if (! x($links,$j)) {
@ -362,8 +361,8 @@ function events_content(App $a) {
// transform the event in a usable array // transform the event in a usable array
if (DBM::is_result($r)) { if (DBM::is_result($r)) {
$r = sort_by_date($r); $r = Event::sortByDate($r);
$events = process_events($r); $events = Event::prepareListForTemplate($r);
} }
if ($a->argc > 1 && $a->argv[1] === 'json'){ if ($a->argc > 1 && $a->argv[1] === 'json'){
@ -543,8 +542,7 @@ function events_content(App $a) {
if ($mode === 'drop' && $event_id) { if ($mode === 'drop' && $event_id) {
$del = 0; $del = 0;
$params = ['event_id' => ($event_id)]; $ev = Event::getListById(local_user(), $event_id);
$ev = event_by_id(local_user(), $params);
// Delete only real events (no birthdays) // Delete only real events (no birthdays)
if (DBM::is_result($ev) && $ev[0]['type'] == 'event') { if (DBM::is_result($ev) && $ev[0]['type'] == 'event') {

View file

@ -20,6 +20,7 @@ use Friendica\Core\PConfig;
use Friendica\Core\Protocol; use Friendica\Core\Protocol;
use Friendica\Core\System; use Friendica\Core\System;
use Friendica\Model\Contact; use Friendica\Model\Contact;
use Friendica\Model\Event;
use Friendica\Network\Probe; use Friendica\Network\Probe;
use Friendica\Object\Image; use Friendica\Object\Image;
use Friendica\Util\Map; use Friendica\Util\Map;
@ -1373,7 +1374,7 @@ class BBCode extends BaseObject
// After we're finished processing the bbcode we'll // After we're finished processing the bbcode we'll
// replace all of the event code with a reformatted version. // replace all of the event code with a reformatted version.
$ev = bbtoevent($text); $ev = Event::fromBBCode($text);
// Replace any html brackets with HTML Entities to prevent executing HTML or script // Replace any html brackets with HTML Entities to prevent executing HTML or script
// Don't use strip_tags here because it breaks [url] search by replacing & with amp // Don't use strip_tags here because it breaks [url] search by replacing & with amp
@ -1811,7 +1812,7 @@ class BBCode extends BaseObject
// start which is always required). Allow desc with a missing summary for compatibility. // start which is always required). Allow desc with a missing summary for compatibility.
if ((x($ev, 'desc') || x($ev, 'summary')) && x($ev, 'start')) { if ((x($ev, 'desc') || x($ev, 'summary')) && x($ev, 'start')) {
$sub = format_event_html($ev, $simple_html); $sub = Event::getHTML($ev, $simple_html);
$text = preg_replace("/\[event\-summary\](.*?)\[\/event\-summary\]/ism", '', $text); $text = preg_replace("/\[event\-summary\](.*?)\[\/event\-summary\]/ism", '', $text);
$text = preg_replace("/\[event\-description\](.*?)\[\/event\-description\]/ism", '', $text); $text = preg_replace("/\[event\-description\](.*?)\[\/event\-description\]/ism", '', $text);

View file

@ -105,7 +105,7 @@ class Event extends BaseObject
* @param array $event Array which contains the event data. * @param array $event Array which contains the event data.
* @return string The event as a bbcode formatted string. * @return string The event as a bbcode formatted string.
*/ */
public static function getBBCode(array $event) private static function getBBCode(array $event)
{ {
$o = ''; $o = '';
@ -289,10 +289,10 @@ class Event extends BaseObject
$item = dba::selectFirst('item', ['id'], ['event-id' => $event['id'], 'uid' => $event['uid']]); $item = dba::selectFirst('item', ['id'], ['event-id' => $event['id'], 'uid' => $event['uid']]);
if (DBM::is_result($item)) { if (DBM::is_result($item)) {
$object = '<object><type>' . xmlify(ACTIVITY_OBJ_EVENT) . '</type><title></title><id>' . xmlify($event['uri']) . '</id>'; $object = '<object><type>' . xmlify(ACTIVITY_OBJ_EVENT) . '</type><title></title><id>' . xmlify($event['uri']) . '</id>';
$object .= '<content>' . xmlify(format_event_bbcode($event)) . '</content>'; $object .= '<content>' . xmlify(self::getBBCode($event)) . '</content>';
$object .= '</object>' . "\n"; $object .= '</object>' . "\n";
$fields = ['body' => format_event_bbcode($event), 'object' => $object, 'edited' => $event['edited']]; $fields = ['body' => self::getBBCode($event), 'object' => $object, 'edited' => $event['edited']];
Item::update($fields, ['id' => $item['id']]); Item::update($fields, ['id' => $item['id']]);
$item_id = $item['id']; $item_id = $item['id'];
@ -335,11 +335,11 @@ class Event extends BaseObject
$item_arr['verb'] = ACTIVITY_POST; $item_arr['verb'] = ACTIVITY_POST;
$item_arr['object-type'] = ACTIVITY_OBJ_EVENT; $item_arr['object-type'] = ACTIVITY_OBJ_EVENT;
$item_arr['origin'] = $event['cid'] === 0 ? 1 : 0; $item_arr['origin'] = $event['cid'] === 0 ? 1 : 0;
$item_arr['body'] = format_event_bbcode($event); $item_arr['body'] = self::getBBCode($event);
$item_arr['event-id'] = $event['id']; $item_arr['event-id'] = $event['id'];
$item_arr['object'] = '<object><type>' . xmlify(ACTIVITY_OBJ_EVENT) . '</type><title></title><id>' . xmlify($event['uri']) . '</id>'; $item_arr['object'] = '<object><type>' . xmlify(ACTIVITY_OBJ_EVENT) . '</type><title></title><id>' . xmlify($event['uri']) . '</id>';
$item_arr['object'] .= '<content>' . xmlify(format_event_bbcode($event)) . '</content>'; $item_arr['object'] .= '<content>' . xmlify(self::getBBCode($event)) . '</content>';
$item_arr['object'] .= '</object>' . "\n"; $item_arr['object'] .= '</object>' . "\n";
$item_id = Item::insert($item_arr); $item_id = Item::insert($item_arr);
@ -429,7 +429,7 @@ class Event extends BaseObject
* *
* @todo We should replace this with a separate update function if there is some time left. * @todo We should replace this with a separate update function if there is some time left.
*/ */
public static function removeDuplicates(array $dates) private static function removeDuplicates(array $dates)
{ {
$dates2 = []; $dates2 = [];
@ -470,7 +470,7 @@ class Event extends BaseObject
); );
if (DBM::is_result($r)) { if (DBM::is_result($r)) {
$return = event_remove_duplicates($r); $return = self::removeDuplicates($r);
} }
return $return; return $return;
@ -519,7 +519,7 @@ class Event extends BaseObject
); );
if (DBM::is_result($r)) { if (DBM::is_result($r)) {
$return = event_remove_duplicates($r); $return = self::removeDuplicates($r);
} }
return $return; return $return;
@ -570,7 +570,7 @@ class Event extends BaseObject
$title = strip_tags(html_entity_decode($title, ENT_QUOTES, 'UTF-8')); $title = strip_tags(html_entity_decode($title, ENT_QUOTES, 'UTF-8'));
} }
$html = format_event_html($event); $html = self::getHTML($event);
$event['desc'] = BBCode::convert($event['desc']); $event['desc'] = BBCode::convert($event['desc']);
$event['location'] = BBCode::convert($event['location']); $event['location'] = BBCode::convert($event['location']);
$event_list[] = [ $event_list[] = [
@ -605,7 +605,7 @@ class Event extends BaseObject
* *
* @todo Implement timezone support * @todo Implement timezone support
*/ */
public static function formatListForExport(array $events, $format, $timezone) private static function formatListForExport(array $events, $format, $timezone)
{ {
if (!count($events)) { if (!count($events)) {
return ''; return '';
@ -712,7 +712,7 @@ class Event extends BaseObject
* *
* @return array Query results. * @return array Query results.
*/ */
public static function getListByUserId($uid = 0) private static function getListByUserId($uid = 0)
{ {
$return = []; $return = [];
@ -761,11 +761,11 @@ class Event extends BaseObject
} }
// Get all events which are owned by a uid (respects permissions). // Get all events which are owned by a uid (respects permissions).
$events = events_by_uid($uid); $events = self::getListByUserId($uid);
// We have the events that are available for the requestor. // We have the events that are available for the requestor.
// Now format the output according to the requested format. // Now format the output according to the requested format.
$res = event_format_export($events, $format, $timezone); $res = self::formatListForExport($events, $format, $timezone);
// If there are results the precess was successfull. // If there are results the precess was successfull.
if (!empty($res)) { if (!empty($res)) {
@ -861,7 +861,7 @@ class Event extends BaseObject
} }
// Format the event location. // Format the event location.
$location = event_location2array($item['event-location']); $location = self::locationToArray($item['event-location']);
// Construct the profile link (magic-auth). // Construct the profile link (magic-auth).
$sp = false; $sp = false;
@ -916,7 +916,7 @@ class Event extends BaseObject
* 'address' => The address of the location,<br> * 'address' => The address of the location,<br>
* 'coordinates' => Latitude and longitude (e.g. '48.864716,2.349014').<br> * 'coordinates' => Latitude and longitude (e.g. '48.864716,2.349014').<br>
*/ */
public static function locationToArray($s = '') { private static function locationToArray($s = '') {
if ($s == '') { if ($s == '') {
return []; return [];
} }

View file

@ -98,7 +98,7 @@ class Item extends BaseObject
* @param integer $item_id Item ID that should be delete * @param integer $item_id Item ID that should be delete
* @param integer $priority Priority for the notification * @param integer $priority Priority for the notification
* *
* @return $boolean success * @return boolean success
*/ */
public static function deleteById($item_id, $priority = PRIORITY_HIGH) public static function deleteById($item_id, $priority = PRIORITY_HIGH)
{ {
@ -153,7 +153,7 @@ class Item extends BaseObject
// If item is a link to an event, delete the event. // If item is a link to an event, delete the event.
if (intval($item['event-id'])) { if (intval($item['event-id'])) {
event_delete($item['event-id']); Event::delete($item['event-id']);
} }
// If item has attachments, drop them // If item has attachments, drop them

View file

@ -19,11 +19,11 @@ use Friendica\Core\System;
use Friendica\Core\Worker; use Friendica\Core\Worker;
use Friendica\Database\DBM; use Friendica\Database\DBM;
use Friendica\Model\Contact; use Friendica\Model\Contact;
use Friendica\Model\Event;
use Friendica\Model\GContact; use Friendica\Model\GContact;
use Friendica\Model\Group; use Friendica\Model\Group;
use Friendica\Model\Item; use Friendica\Model\Item;
use Friendica\Model\Profile; use Friendica\Model\Profile;
use Friendica\Model\Term;
use Friendica\Model\User; use Friendica\Model\User;
use Friendica\Object\Image; use Friendica\Object\Image;
use Friendica\Protocol\OStatus; use Friendica\Protocol\OStatus;
@ -2614,7 +2614,7 @@ class DFRN
// Is it an event? // Is it an event?
if ($item["object-type"] == ACTIVITY_OBJ_EVENT) { if ($item["object-type"] == ACTIVITY_OBJ_EVENT) {
logger("Item ".$item["uri"]." seems to contain an event.", LOGGER_DEBUG); logger("Item ".$item["uri"]." seems to contain an event.", LOGGER_DEBUG);
$ev = bbtoevent($item["body"]); $ev = Event::fromBBCode($item["body"]);
if ((x($ev, "desc") || x($ev, "summary")) && x($ev, "start")) { if ((x($ev, "desc") || x($ev, "summary")) && x($ev, "start")) {
logger("Event in item ".$item["uri"]." was found.", LOGGER_DEBUG); logger("Event in item ".$item["uri"]." was found.", LOGGER_DEBUG);
$ev["cid"] = $importer["id"]; $ev["cid"] = $importer["id"];
@ -2633,7 +2633,7 @@ class DFRN
$ev["id"] = $r[0]["id"]; $ev["id"] = $r[0]["id"];
} }
$event_id = event_store($ev); $event_id = Event::store($ev);
logger("Event ".$event_id." was stored", LOGGER_DEBUG); logger("Event ".$event_id." was stored", LOGGER_DEBUG);
return; return;
} }