summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Parecki <aaron@parecki.com>2017-03-13 18:05:57 -0700
committerAaron Parecki <aaron@parecki.com>2017-03-13 18:05:57 -0700
commitfa782167af747ded42dd1278441035e0be0c36ea (patch)
treeff7b591050a3119d95138dc527e5804ec0db17b0
parentbd535204e44cb4a6aba3a5df70fe67f436d328a8 (diff)
show RSVP field when replying to events
closes #71
-rw-r--r--composer.json2
-rw-r--r--composer.lock16
-rw-r--r--controllers/controllers.php42
-rw-r--r--views/new-post.php59
4 files changed, 90 insertions, 29 deletions
diff --git a/composer.json b/composer.json
index 7c3336c..62b9426 100644
--- a/composer.json
+++ b/composer.json
@@ -4,7 +4,7 @@
"saltybeagle/savant3": "dev-master",
"j4mie/idiorm": "1.4.*",
"mf2/mf2": "0.3.*",
- "indieweb/date-formatter": "0.1.*",
+ "indieweb/date-formatter": "0.3.*",
"indieauth/client": ">=0.2.0",
"mpratt/relativetime": ">=1.0",
"firebase/php-jwt": "2.*",
diff --git a/composer.lock b/composer.lock
index a9244b4..fe3124f 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
- "content-hash": "b7a5b281de45ad549d11a38464bdfb24",
+ "content-hash": "ea8898cc230a54e15b78444d0454961e",
"packages": [
{
"name": "abraham/twitteroauth",
@@ -317,21 +317,25 @@
},
{
"name": "indieweb/date-formatter",
- "version": "0.1.6",
+ "version": "0.3.1",
"source": {
"type": "git",
"url": "https://github.com/indieweb/date-formatter-php.git",
- "reference": "9c12e0fda95f4b3119fcaf271d141305870c4350"
+ "reference": "282946ebae0efa5f9c00be88553d76d7a39824ab"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/indieweb/date-formatter-php/zipball/9c12e0fda95f4b3119fcaf271d141305870c4350",
- "reference": "9c12e0fda95f4b3119fcaf271d141305870c4350",
+ "url": "https://api.github.com/repos/indieweb/date-formatter-php/zipball/282946ebae0efa5f9c00be88553d76d7a39824ab",
+ "reference": "282946ebae0efa5f9c00be88553d76d7a39824ab",
"shasum": ""
},
"require": {
"php": ">=5.3.0"
},
+ "require-dev": {
+ "mf2/mf2": ">=0.2.12",
+ "phpunit/phpunit": "~4.0"
+ },
"type": "library",
"autoload": {
"psr-0": {
@@ -356,7 +360,7 @@
"microformats",
"microformats2"
],
- "time": "2015-10-28T00:32:39+00:00"
+ "time": "2016-04-05T15:13:00+00:00"
},
{
"name": "indieweb/link-rel-parser",
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,'@'));
+ }
}
}
diff --git a/views/new-post.php b/views/new-post.php
index ab98097..6e6eb0f 100644
--- a/views/new-post.php
+++ b/views/new-post.php
@@ -25,6 +25,17 @@
<a href="" id="expand-reply" class="btn btn-xs btn-info">Reply</a>
</div>
+ <div class="form-group hidden" id="form_rsvp">
+ <label for="note_rsvp">RSVP</label>
+ <select id="note_rsvp" class="form-control">
+ <option value="yes">Yes</option>
+ <option value="no">No</option>
+ <option value="maybe">Maybe</option>
+ <option value="interested">Interested</option>
+ <option value=""></option>
+ </select>
+ </div>
+
<div class="form-group">
<div id="note_content_remaining" class="pcheck206"><img src="/images/twitter.ico"> <span>140</span></div>
<label for="note_content">Content</label>
@@ -544,25 +555,37 @@ $(function(){
$("#note_content").val(mentions);
}
- $(".reply-context .content").text(data.entry.content.text);
- if(data.entry.name) {
- $(".reply-context .post-name").text(data.entry.name).removeClass('hidden');
- } else {
- $(".reply-context .post-name").addClass('hidden');
- }
- if(data.entry.author) {
- $(".reply-context .author .name").text(data.entry.author.name);
- $(".reply-context .author .url").text(data.entry.author.url);
- $(".reply-context img.author-img").attr('src', data.entry.author.photo);
- }
- if(data.entry.photo) {
- $(".reply-context img.post-img").attr('src', data.entry.photo[0]).removeClass('hidden');
- } else {
- $(".reply-context img.post-img").addClass('hidden');
+ if(data.entry) {
+ $(".reply-context .content").text(data.entry.content.text);
+ if(data.entry.name) {
+ $(".reply-context .post-name").text(data.entry.name).removeClass('hidden');
+ } else {
+ $(".reply-context .post-name").addClass('hidden');
+ }
+ if(data.entry.author) {
+ $(".reply-context .author .name").text(data.entry.author.name);
+ $(".reply-context .author .url").text(data.entry.author.url);
+ $(".reply-context img.author-img").attr('src', data.entry.author.photo);
+ $(".reply-context .reply-author").removeClass("hidden");
+ } else {
+ $(".reply-context .reply-author").addClass("hidden");
+ }
+ if(data.entry.photo) {
+ $(".reply-context img.post-img").attr('src', data.entry.photo[0]).removeClass('hidden');
+ } else {
+ $(".reply-context img.post-img").addClass('hidden');
+ }
+ if(data.entry.type == "event") {
+ $("#form_rsvp").removeClass("hidden");
+ } else {
+ $("#form_rsvp").addClass("hidden");
+ }
+
+ $(".reply-context").removeClass("hidden");
}
$(".reply-section .loading").addClass("hidden");
- $(".reply-context").removeClass("hidden");
+
});
});
@@ -624,6 +647,10 @@ $(function(){
formData.append("<?= $this->user->micropub_slug_field ?>", v);
entry["<?= $this->user->micropub_slug_field ?>"] = v;
}
+ if(!$("#form_rsvp").hasClass("hidden") && $("#note_rsvp").val()) {
+ formData.append("rsvp", $("#note_rsvp").val());
+ entry["rsvp"] = $("#note_rsvp").val();
+ }
function appendPhotoToFormData(photo, prop) {
if(photo.external) {