]> git.mxchange.org Git - friendica.git/blobdiff - mod/events.php
Merge https://github.com/friendica/friendica into pull
[friendica.git] / mod / events.php
old mode 100644 (file)
new mode 100755 (executable)
index e66a2dc..c13f31c
@@ -28,6 +28,9 @@ function events_post(&$a) {
        $adjust   = intval($_POST['adjust']);
        $nofinish = intval($_POST['nofinish']);
 
+       // The default setting for the `private` field in event_store() is false, so mirror that        
+       $private_event = false;
+
 
        $start    = sprintf('%d-%d-%d %d:%d:0',$startyear,$startmonth,$startday,$starthour,$startminute);
        if($nofinish)
@@ -54,25 +57,50 @@ function events_post(&$a) {
        if(strcmp($finish,$start) < 0)
                $finish = $start;
 
+       $summary  = escape_tags(trim($_POST['summary']));
        $desc     = escape_tags(trim($_POST['desc']));
        $location = escape_tags(trim($_POST['location']));
        $type     = 'event';
 
-       if((! $desc) || (! $start)) {
-               notice( t('Event description and start time are required.') . EOL);
+       if((! $summary) || (! $start)) {
+               notice( t('Event title and start time are required.') . EOL);
                goaway($a->get_baseurl() . '/events/new');
        }
 
        $share = ((intval($_POST['share'])) ? intval($_POST['share']) : 0);
 
+       $c = q("select id from contact where uid = %d and self = 1 limit 1",
+               intval(local_user())
+       );
+       if(count($c))
+               $self = $c[0]['id'];
+       else
+               $self = 0;
+
+
        if($share) {
                $str_group_allow   = perms2str($_POST['group_allow']);
                $str_contact_allow = perms2str($_POST['contact_allow']);
                $str_group_deny    = perms2str($_POST['group_deny']);
                $str_contact_deny  = perms2str($_POST['contact_deny']);
+
+               // Undo the pseudo-contact of self, since there are real contacts now
+               if( strpos($str_contact_allow, '<' . $self . '>') !== false )
+               {
+                       $str_contact_allow = str_replace('<' . $self . '>', '', $str_contact_allow);
+               }
+               // Make sure to set the `private` field as true. This is necessary to
+               // have the posts show up correctly in Diaspora if an event is created
+               // as visible only to self at first, but then edited to display to others.
+               if( strlen($str_group_allow) or strlen($str_contact_allow) or strlen($str_group_deny) or strlen($str_contact_deny) )
+               {
+                       $private_event = true;
+               }
        }
        else {
-               $str_contact_allow = '<' . local_user() . '>';
+               // Note: do not set `private` field for self-only events. It will
+               // keep even you from seeing them!
+               $str_contact_allow = '<' . $self . '>';
                $str_group_allow = $str_contact_deny = $str_group_deny = '';
        }
 
@@ -80,6 +108,7 @@ function events_post(&$a) {
        $datarray = array();
        $datarray['start'] = $start;
        $datarray['finish'] = $finish;
+       $datarray['summary'] = $summary;
        $datarray['desc'] = $desc;
        $datarray['location'] = $location;
        $datarray['type'] = $type;
@@ -91,6 +120,7 @@ function events_post(&$a) {
        $datarray['allow_gid'] = $str_group_allow;
        $datarray['deny_cid'] = $str_contact_deny;
        $datarray['deny_gid'] = $str_group_deny;
+       $datarray['private'] = (($private_event) ? 1 : 0);
        $datarray['id'] = $event_id;
        $datarray['created'] = $created;
        $datarray['edited'] = $edited;
@@ -111,9 +141,36 @@ function events_content(&$a) {
                return;
        }
 
+       if(($a->argc > 2) && ($a->argv[1] === 'ignore') && intval($a->argv[2])) {
+               $r = q("update event set ignore = 1 where id = %d and uid = %d limit 1",
+                       intval($a->argv[2]),
+                       intval(local_user())
+               );
+       }
+
+       if(($a->argc > 2) && ($a->argv[1] === 'unignore') && intval($a->argv[2])) {
+               $r = q("update event set ignore = 0 where id = %d and uid = %d limit 1",
+                       intval($a->argv[2]),
+                       intval(local_user())
+               );
+       }
+
+
+       $editselect = 'none';
+       if( feature_enabled(local_user(), 'richtext') )
+               $editselect = 'textareas';
 
        $htpl = get_markup_template('event_head.tpl');
-       $a->page['htmlhead'] .= replace_macros($htpl,array('$baseurl' => $a->get_baseurl()));
+       $a->page['htmlhead'] .= replace_macros($htpl,array(
+               '$baseurl' => $a->get_baseurl(),
+               '$editselect' => $editselect
+       ));
+
+       $etpl = get_markup_template('event_end.tpl');
+       $a->page['end'] .= replace_macros($etpl,array(
+               '$baseurl' => $a->get_baseurl(),
+               '$editselect' => $editselect
+       ));
 
        $o ="";
        // tabs
@@ -124,6 +181,7 @@ function events_content(&$a) {
        $mode = 'view';
        $y = 0;
        $m = 0;
+       $ignored = ((x($_REQUEST,'ignored')) ? intval($_REQUEST['ignored']) : 0);
 
        if($a->argc > 1) {
                if($a->argc > 2 && $a->argv[1] == 'event') {
@@ -201,13 +259,16 @@ function events_content(&$a) {
                } else {
                        $r = q("SELECT `event`.*, `item`.`id` AS `itemid`,`item`.`plink`,
                                `item`.`author-name`, `item`.`author-avatar`, `item`.`author-link` FROM `event` LEFT JOIN `item` ON `item`.`event-id` = `event`.`id` 
-                               WHERE `event`.`uid` = %d
-                               AND (( `adjust` = 0 AND `start` >= '%s' AND `start` <= '%s' ) 
-                               OR  (  `adjust` = 1 AND `start` >= '%s' AND `start` <= '%s' )) ",
+                               WHERE `event`.`uid` = %d and event.ignore = %d
+                               AND (( `adjust` = 0 AND ( `finish` >= '%s' OR ( nofinish AND start >= '%s' ) ) AND `start` <= '%s' ) 
+                               OR  (  `adjust` = 1 AND ( `finish` >= '%s' OR ( nofinish AND start >= '%s' ) ) AND `start` <= '%s' )) ",
                                intval(local_user()),
+                               intval($ignored),
+                               dbesc($start),
                                dbesc($start),
                                dbesc($finish),
                                dbesc($adjust_start),
+                               dbesc($adjust_start),
                                dbesc($adjust_finish)
                        );
                }
@@ -250,9 +311,11 @@ function events_content(&$a) {
                                        
                                $last_date = $d;
                                $edit = ((! $rr['cid']) ? array($a->get_baseurl().'/events/event/'.$rr['id'],t('Edit event'),'','') : null);
-
-                               list($title, $_trash) = explode("<br",bbcode($rr['desc']),2);
-                               $title = strip_tags($title);
+                               $title = strip_tags(html_entity_decode(bbcode($rr['summary']),ENT_QUOTES,'UTF-8'));
+                               if(! $title) {
+                                       list($title, $_trash) = explode("<br",bbcode($rr['desc']),2);
+                                       $title = strip_tags(html_entity_decode($title,ENT_QUOTES,'UTF-8'));
+                               }
                                $html = format_event_html($rr);
                                $rr['desc'] = bbcode($rr['desc']);
                                $rr['location'] = bbcode($rr['location']);
@@ -290,6 +353,17 @@ function events_content(&$a) {
 //                             $tpl = get_markup_template("events.tpl");
 //                     }
                }
+
+               // Get rid of dashes in key names, Smarty3 can't handle them
+               foreach($events as $key => $event) {
+                       $event_item = array();
+                       foreach($event['item'] as $k => $v) {
+                               $k = str_replace('-','_',$k);
+                               $event_item[$k] = $v;
+                       }
+                       $events[$key]['item'] = $event_item;
+               }
+
                $o = replace_macros($tpl, array(
                        '$baseurl'      => $a->get_baseurl(),
                        '$tabs'         => $tabs,
@@ -323,6 +397,7 @@ function events_content(&$a) {
 
                $n_checked = ((x($orig_event) && $orig_event['nofinish']) ? ' checked="checked" ' : '');
                $a_checked = ((x($orig_event) && $orig_event['adjust']) ? ' checked="checked" ' : '');
+               $t_orig = ((x($orig_event)) ? $orig_event['summary'] : '');
                $d_orig = ((x($orig_event)) ? $orig_event['desc'] : '');
                $l_orig = ((x($orig_event)) ? $orig_event['location'] : '');
                $eid = ((x($orig_event)) ? $orig_event['id'] : 0);
@@ -377,10 +452,11 @@ function events_content(&$a) {
                        '$eid' => $eid, 
                        '$cid' => $cid,
                        '$uri' => $uri,
+       
                        '$title' => t('Event details'),
-                       '$desc' => sprintf( t('Format is %s %s. Starting date and Description are required.'),$dateformat,$timeformat),
+                       '$desc' => sprintf( t('Format is %s %s. Starting date and Title are required.'),$dateformat,$timeformat),
                        
-                       '$s_text' => t('Event Starts:') . ' <span class="required">*</span> ',
+                       '$s_text' => t('Event Starts:') . ' <span class="required" title="' . t('Required') . '">*</span>',
                        '$s_dsel' => datesel($f,'start',$syear+5,$syear,false,$syear,$smonth,$sday),
                        '$s_tsel' => timesel('start',$shour,$sminute),
                        '$n_text' => t('Finish date/time is not known or not relevant'),
@@ -390,10 +466,12 @@ function events_content(&$a) {
                        '$f_tsel' => timesel('finish',$fhour,$fminute),
                        '$a_text' => t('Adjust for viewer timezone'),
                        '$a_checked' => $a_checked,
-                       '$d_text' => t('Description:') . ' <span class="required">*</span>',
+                       '$d_text' => t('Description:')
                        '$d_orig' => $d_orig,
                        '$l_text' => t('Location:'),
                        '$l_orig' => $l_orig,
+                       '$t_text' => t('Title:') . ' <span class="required" title="' . t('Required') . '">*</span>',
+                       '$t_orig' => $t_orig,
                        '$sh_text' => t('Share this event'),
                        '$sh_checked' => $sh_checked,
                        '$acl' => (($cid) ? '' : populate_acl(((x($orig_event)) ? $orig_event : $a->user),false)),