diff options
author | Aaron Parecki <aaron@parecki.com> | 2017-03-13 18:05:57 -0700 |
---|---|---|
committer | Aaron Parecki <aaron@parecki.com> | 2017-03-13 18:05:57 -0700 |
commit | fa782167af747ded42dd1278441035e0be0c36ea (patch) | |
tree | ff7b591050a3119d95138dc527e5804ec0db17b0 /controllers/controllers.php | |
parent | bd535204e44cb4a6aba3a5df70fe67f436d328a8 (diff) |
show RSVP field when replying to events
closes #71
Diffstat (limited to 'controllers/controllers.php')
-rw-r--r-- | controllers/controllers.php | 42 |
1 files changed, 36 insertions, 6 deletions
diff --git a/controllers/controllers.php b/controllers/controllers.php index 29ca247..fe4d89c 100644 --- a/controllers/controllers.php +++ b/controllers/controllers.php @@ -1,5 +1,6 @@ <?php use Abraham\TwitterOAuth\TwitterOAuth; +use IndieWeb\DateFormatter; function require_login(&$app, $redirect=true) { $params = $app->request()->params(); @@ -581,8 +582,35 @@ $app->get('/reply/preview', function() use($app) { curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($xray)); $response = curl_exec($ch); $data = @json_decode($response, true); - if($data && isset($data['data']) && $data['data']['type'] == 'entry') { - $entry = $data['data']; + if($data && isset($data['data'])) { + if($data['data']['type'] == 'entry') { + $entry = $data['data']; + } elseif($data['data']['type'] == 'event') { + $entry = $data['data']; + $content = ''; + if(isset($entry['start']) && isset($entry['end'])) { + $formatted = DateFormatter::format($entry['start'], $entry['end'], false); + if($formatted) + $content .= $formatted; + else { + $start = new DateTime($entry['start']); + $end = new DateTime($entry['end']); + if($start && $end) + $content .= 'from '.$start->format('Y-m-d g:ia').' to '.$end->format('Y-m-d g:ia'); + } + } elseif(isset($entry['start'])) { + $formatted = DateFormatter::format($entry['start'], false, false); + if($formatted) + $content .= $formatted; + else { + $start = new DateTime($entry['start']); + if($start) + $content .= $start->format('Y-m-d g:ia'); + } + } + + $entry['content']['text'] = $content; + } // Create a nickname based on the author URL if(array_key_exists('author', $entry)) { if($entry['author']['url']) { @@ -599,10 +627,12 @@ $app->get('/reply/preview', function() use($app) { $mentions[] = strtolower($entry['author']['nickname']); } - if(preg_match_all('/(^|(?<=[\s\/]))@([a-z0-9_]+([a-z0-9_\.]*)?)/i', $entry['content']['text'], $matches)) { - foreach($matches[0] as $nick) { - if(trim($nick,'@') != $user->twitter_username && trim($nick,'@') != display_url($user->url)) - $mentions[] = strtolower(trim($nick,'@')); + if(isset($entry['content']) && $entry['content'] && isset($entry['content']['text'])) { + if(preg_match_all('/(^|(?<=[\s\/]))@([a-z0-9_]+([a-z0-9_\.]*)?)/i', $entry['content']['text'], $matches)) { + foreach($matches[0] as $nick) { + if(trim($nick,'@') != $user->twitter_username && trim($nick,'@') != display_url($user->url)) + $mentions[] = strtolower(trim($nick,'@')); + } } } |