]> git.mxchange.org Git - friendica.git/blobdiff - mod/events.php
missing $submit
[friendica.git] / mod / events.php
index e66a2dc4423953a80b9fd2dbb1fdf1d4d81f3871..2a6fb692eb6b947de9b828d8d99db7556d87e3bb 100755 (executable)
@@ -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)
@@ -65,14 +68,38 @@ function events_post(&$a) {
 
        $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 = '';
        }
 
@@ -91,6 +118,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;
        $datarray['id'] = $event_id;
        $datarray['created'] = $created;
        $datarray['edited'] = $edited;
@@ -202,8 +230,8 @@ function events_content(&$a) {
                        $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' )) ",
+                               AND (( `adjust` = 0 AND `finish` >= '%s' AND `start` <= '%s' ) 
+                               OR  (  `adjust` = 1 AND `finish` >= '%s' AND `start` <= '%s' )) ",
                                intval(local_user()),
                                dbesc($start),
                                dbesc($finish),