]> git.mxchange.org Git - friendica.git/blobdiff - mod/events.php
Better content detection for posts to Twitter
[friendica.git] / mod / events.php
index d66ae764cff31c792fecc170cf10579087316e0d..4e70c005690d686f3e74e1f9712e497bb6d2fd18 100644 (file)
@@ -3,6 +3,10 @@
  * @file mod/events.php
  * @brief The events module
  */
+
+use Friendica\App;
+use Friendica\Core\System;
+
 require_once 'include/bbcode.php';
 require_once 'include/datetime.php';
 require_once 'include/event.php';
@@ -14,7 +18,7 @@ function events_init(App $a) {
        }
 
        if ($a->argc == 1) {
-               // if it's a json request abort here becaus we don't
+               // If it's a json request abort here because we don't
                // need the widget data
                if ($a->argv[1] === 'json') {
                        return;
@@ -34,7 +38,7 @@ function events_init(App $a) {
 
 function events_post(App $a) {
 
-       logger('post: ' . print_r($_REQUEST, true));
+       logger('post: ' . print_r($_REQUEST, true), LOGGER_DATA);
 
        if (! local_user()) {
                return;
@@ -53,20 +57,15 @@ function events_post(App $a) {
        // The default setting for the `private` field in event_store() is false, so mirror that
        $private_event = false;
 
+       $start  = NULL_DATE;
+       $finish = NULL_DATE;
+
        if ($start_text) {
                $start = $start_text;
-       } else {
-               $start = sprintf('%d-%d-%d %d:%d:0', $startyear, $startmonth, $startday, $starthour, $startminute);
-       }
-
-       if ($nofinish) {
-               $finish = '0000-00-00 00:00:00';
        }
 
        if ($finish_text) {
                $finish = $finish_text;
-       } else {
-               $finish = sprintf('%d-%d-%d %d:%d:0', $finishyear, $finishmonth, $finishday, $finishhour, $finishminute);
        }
 
        if ($adjust) {
@@ -92,7 +91,7 @@ function events_post(App $a) {
        $type     = 'event';
 
        $action = ($event_id == '') ? 'new' : "event/" . $event_id;
-       $onerror_url = App::get_baseurl() . "/events/" . $action . "?summary=$summary&description=$desc&location=$location&start=$start_text&finish=$finish_text&adjust=$adjust&nofinish=$nofinish";
+       $onerror_url = System::baseUrl() . "/events/" . $action . "?summary=$summary&description=$desc&location=$location&start=$start_text&finish=$finish_text&adjust=$adjust&nofinish=$nofinish";
 
        if (strcmp($finish, $start) < 0 && !$nofinish) {
                notice(t('Event can not end before it has started.') . EOL);
@@ -103,7 +102,7 @@ function events_post(App $a) {
                goaway($onerror_url);
        }
 
-       if ((! $summary) || (! $start)) {
+       if ((! $summary) || ($start === NULL_DATE)) {
                notice(t('Event title and start time are required.') . EOL);
                if (intval($_REQUEST['preview'])) {
                        echo t('Event title and start time are required.');
@@ -184,8 +183,6 @@ function events_post(App $a) {
        goaway($_SESSION['return_url']);
 }
 
-
-
 function events_content(App $a) {
 
        if (! local_user()) {
@@ -194,7 +191,7 @@ function events_content(App $a) {
        }
 
        if ($a->argc == 1) {
-               $_SESSION['return_url'] = App::get_baseurl() . '/' . $a->cmd;
+               $_SESSION['return_url'] = System::baseUrl() . '/' . $a->cmd;
        }
 
        if (($a->argc > 2) && ($a->argv[1] === 'ignore') && intval($a->argv[2])) {
@@ -222,7 +219,7 @@ function events_content(App $a) {
 
        $htpl = get_markup_template('event_head.tpl');
        $a->page['htmlhead'] .= replace_macros($htpl, array(
-               '$baseurl' => App::get_baseurl(),
+               '$baseurl' => System::baseUrl(),
                '$module_url' => '/events',
                '$modparams' => 1,
                '$i18n' => $i18n,
@@ -230,7 +227,7 @@ function events_content(App $a) {
 
        $etpl = get_markup_template('event_end.tpl');
        $a->page['end'] .= replace_macros($etpl, array(
-               '$baseurl' => App::get_baseurl(),
+               '$baseurl' => System::baseUrl(),
        ));
 
        $o = '';
@@ -239,19 +236,17 @@ function events_content(App $a) {
                $tabs = profile_tabs($a, true);
        }
 
-
-
        $mode = 'view';
        $y = 0;
        $m = 0;
        $ignored = ((x($_REQUEST, 'ignored')) ? intval($_REQUEST['ignored']) : 0);
 
-       if($a->argc > 1) {
+       if ($a->argc > 1) {
                if ($a->argc > 2 && $a->argv[1] == 'event') {
                        $mode = 'edit';
                        $event_id = intval($a->argv[2]);
                }
-               if($a->argc > 2 && $a->argv[1] == 'drop') {
+               if ($a->argc > 2 && $a->argv[1] == 'drop') {
                        $mode = 'drop';
                        $event_id = intval($a->argv[2]);
                }
@@ -330,7 +325,7 @@ function events_content(App $a) {
                );
 
                // get events by id or by date
-               if (x($_GET, 'id')){
+               if (x($_GET, 'id')) {
                        $r = event_by_id(local_user(), $event_params);
                } else {
                        $r = events_by_date(local_user(), $event_params);
@@ -343,7 +338,7 @@ function events_content(App $a) {
                        foreach ($r as $rr) {
                                $j = (($rr['adjust']) ? datetime_convert('UTC', date_default_timezone_get(), $rr['start'], 'j') : datetime_convert('UTC', 'UTC', $rr['start'], 'j'));
                                if (! x($links,$j)) {
-                                       $links[$j] = App::get_baseurl() . '/' . $a->cmd . '#link-' . $j;
+                                       $links[$j] = System::baseUrl() . '/' . $a->cmd . '#link-' . $j;
                                }
                        }
                }
@@ -361,7 +356,7 @@ function events_content(App $a) {
                        killme();
                }
 
-               if (x($_GET, 'id')){
+               if (x($_GET, 'id')) {
                        $tpl =  get_markup_template("event.tpl");
                } else {
                        $tpl = get_markup_template("events_js.tpl");
@@ -378,13 +373,13 @@ function events_content(App $a) {
                }
 
                $o = replace_macros($tpl, array(
-                       '$baseurl'   => App::get_baseurl(),
+                       '$baseurl'   => System::baseUrl(),
                        '$tabs'      => $tabs,
                        '$title'     => t('Events'),
                        '$view'      => t('View'),
-                       '$new_event' => array(App::get_baseurl() . '/events/new', t('Create New Event'), '', ''),
-                       '$previous'  => array(App::get_baseurl() . '/events/$prevyear/$prevmonth', t('Previous'), '', ''),
-                       '$next'      => array(App::get_baseurl() . '/events/$nextyear/$nextmonth', t('Next'), '', ''),
+                       '$new_event' => array(System::baseUrl() . '/events/new', t('Create New Event'), '', ''),
+                       '$previous'  => array(System::baseUrl() . '/events/$prevyear/$prevmonth', t('Previous'), '', ''),
+                       '$next'      => array(System::baseUrl() . '/events/$nextyear/$nextmonth', t('Next'), '', ''),
                        '$calendar'  => cal($y, $m, $links, ' eventcal'),
 
                        '$events'    => $events,
@@ -425,9 +420,6 @@ function events_content(App $a) {
                if (x($_REQUEST, 'location'))    {$orig_event['location']    = $_REQUEST['location'];}
                if (x($_REQUEST, 'start'))       {$orig_event['start']       = $_REQUEST['start'];}
                if (x($_REQUEST, 'finish'))      {$orig_event['finish']      = $_REQUEST['finish'];}
-       }
-
-       if ($mode === 'edit' || $mode === 'new') {
 
                $n_checked = ((x($orig_event) && $orig_event['nofinish']) ? ' checked="checked" ' : '');
                $a_checked = ((x($orig_event) && $orig_event['adjust'])   ? ' checked="checked" ' : '');
@@ -439,18 +431,16 @@ function events_content(App $a) {
                $cid    = ((x($orig_event)) ? $orig_event['cid']      : 0);
                $uri    = ((x($orig_event)) ? $orig_event['uri']      : '');
 
-
                if (! x($orig_event)) {
                        $sh_checked = '';
                } else {
                        $sh_checked = (($orig_event['allow_cid'] === '<' . local_user() . '>' && (! $orig_event['allow_gid']) && (! $orig_event['deny_cid']) && (! $orig_event['deny_gid'])) ? '' : ' checked="checked" ');
                }
 
-               if ($cid OR ($mode !== 'new')) {
+               if ($cid || ($mode !== 'new')) {
                        $sh_checked .= ' disabled="disabled" ';
                }
 
-
                $sdt = ((x($orig_event)) ? $orig_event['start'] : 'now');
                $fdt = ((x($orig_event)) ? $orig_event['finish'] : 'now');
 
@@ -487,7 +477,7 @@ function events_content(App $a) {
                $tpl = get_markup_template('event_form.tpl');
 
                $o .= replace_macros($tpl,array(
-                       '$post' => App::get_baseurl() . '/events',
+                       '$post' => System::baseUrl() . '/events',
                        '$eid' => $eid,
                        '$cid' => $cid,
                        '$uri' => $uri,
@@ -544,6 +534,6 @@ function events_content(App $a) {
                        info(t('Event removed') . EOL);
                }
 
-               goaway(App::get_baseurl() . '/events');
+               goaway(System::baseUrl() . '/events');
        }
 }