Browse Source

show RSVP field when replying to events

closes #71
pull/82/head
Aaron Parecki 8 years ago
parent
commit
fa782167af
No known key found for this signature in database GPG Key ID: 276C2817346D6056
  1. 2
      composer.json
  2. 16
      composer.lock
  3. 32
      controllers/controllers.php
  4. 29
      views/new-post.php

2
composer.json

@ -4,7 +4,7 @@
"saltybeagle/savant3": "dev-master", "saltybeagle/savant3": "dev-master",
"j4mie/idiorm": "1.4.*", "j4mie/idiorm": "1.4.*",
"mf2/mf2": "0.3.*", "mf2/mf2": "0.3.*",
"indieweb/date-formatter": "0.1.*",
"indieweb/date-formatter": "0.3.*",
"indieauth/client": ">=0.2.0", "indieauth/client": ">=0.2.0",
"mpratt/relativetime": ">=1.0", "mpratt/relativetime": ">=1.0",
"firebase/php-jwt": "2.*", "firebase/php-jwt": "2.*",

16
composer.lock

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "b7a5b281de45ad549d11a38464bdfb24",
"content-hash": "ea8898cc230a54e15b78444d0454961e",
"packages": [ "packages": [
{ {
"name": "abraham/twitteroauth", "name": "abraham/twitteroauth",
@ -317,21 +317,25 @@
}, },
{ {
"name": "indieweb/date-formatter", "name": "indieweb/date-formatter",
"version": "0.1.6",
"version": "0.3.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/indieweb/date-formatter-php.git", "url": "https://github.com/indieweb/date-formatter-php.git",
"reference": "9c12e0fda95f4b3119fcaf271d141305870c4350"
"reference": "282946ebae0efa5f9c00be88553d76d7a39824ab"
}, },
"dist": { "dist": {
"type": "zip", "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": "" "shasum": ""
}, },
"require": { "require": {
"php": ">=5.3.0" "php": ">=5.3.0"
}, },
"require-dev": {
"mf2/mf2": ">=0.2.12",
"phpunit/phpunit": "~4.0"
},
"type": "library", "type": "library",
"autoload": { "autoload": {
"psr-0": { "psr-0": {
@ -356,7 +360,7 @@
"microformats", "microformats",
"microformats2" "microformats2"
], ],
"time": "2015-10-28T00:32:39+00:00"
"time": "2016-04-05T15:13:00+00:00"
}, },
{ {
"name": "indieweb/link-rel-parser", "name": "indieweb/link-rel-parser",

32
controllers/controllers.php

@ -1,5 +1,6 @@
<?php <?php
use Abraham\TwitterOAuth\TwitterOAuth; use Abraham\TwitterOAuth\TwitterOAuth;
use IndieWeb\DateFormatter;
function require_login(&$app, $redirect=true) { function require_login(&$app, $redirect=true) {
$params = $app->request()->params(); $params = $app->request()->params();
@ -581,8 +582,35 @@ $app->get('/reply/preview', function() use($app) {
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($xray)); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($xray));
$response = curl_exec($ch); $response = curl_exec($ch);
$data = @json_decode($response, true); $data = @json_decode($response, true);
if($data && isset($data['data']) && $data['data']['type'] == 'entry') {
if($data && isset($data['data'])) {
if($data['data']['type'] == 'entry') {
$entry = $data['data']; $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 // Create a nickname based on the author URL
if(array_key_exists('author', $entry)) { if(array_key_exists('author', $entry)) {
if($entry['author']['url']) { if($entry['author']['url']) {
@ -599,12 +627,14 @@ $app->get('/reply/preview', function() use($app) {
$mentions[] = strtolower($entry['author']['nickname']); $mentions[] = strtolower($entry['author']['nickname']);
} }
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)) { if(preg_match_all('/(^|(?<=[\s\/]))@([a-z0-9_]+([a-z0-9_\.]*)?)/i', $entry['content']['text'], $matches)) {
foreach($matches[0] as $nick) { foreach($matches[0] as $nick) {
if(trim($nick,'@') != $user->twitter_username && trim($nick,'@') != display_url($user->url)) if(trim($nick,'@') != $user->twitter_username && trim($nick,'@') != display_url($user->url))
$mentions[] = strtolower(trim($nick,'@')); $mentions[] = strtolower(trim($nick,'@'));
} }
} }
}
$mentions = array_values(array_unique($mentions)); $mentions = array_values(array_unique($mentions));

29
views/new-post.php

@ -25,6 +25,17 @@
<a href="" id="expand-reply" class="btn btn-xs btn-info">Reply</a> <a href="" id="expand-reply" class="btn btn-xs btn-info">Reply</a>
</div> </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 class="form-group">
<div id="note_content_remaining" class="pcheck206"><img src="/images/twitter.ico"> <span>140</span></div> <div id="note_content_remaining" class="pcheck206"><img src="/images/twitter.ico"> <span>140</span></div>
<label for="note_content">Content</label> <label for="note_content">Content</label>
@ -544,6 +555,7 @@ $(function(){
$("#note_content").val(mentions); $("#note_content").val(mentions);
} }
if(data.entry) {
$(".reply-context .content").text(data.entry.content.text); $(".reply-context .content").text(data.entry.content.text);
if(data.entry.name) { if(data.entry.name) {
$(".reply-context .post-name").text(data.entry.name).removeClass('hidden'); $(".reply-context .post-name").text(data.entry.name).removeClass('hidden');
@ -554,15 +566,26 @@ $(function(){
$(".reply-context .author .name").text(data.entry.author.name); $(".reply-context .author .name").text(data.entry.author.name);
$(".reply-context .author .url").text(data.entry.author.url); $(".reply-context .author .url").text(data.entry.author.url);
$(".reply-context img.author-img").attr('src', data.entry.author.photo); $(".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) { if(data.entry.photo) {
$(".reply-context img.post-img").attr('src', data.entry.photo[0]).removeClass('hidden'); $(".reply-context img.post-img").attr('src', data.entry.photo[0]).removeClass('hidden');
} else { } else {
$(".reply-context img.post-img").addClass('hidden'); $(".reply-context img.post-img").addClass('hidden');
} }
if(data.entry.type == "event") {
$("#form_rsvp").removeClass("hidden");
} else {
$("#form_rsvp").addClass("hidden");
}
$(".reply-section .loading").addClass("hidden");
$(".reply-context").removeClass("hidden"); $(".reply-context").removeClass("hidden");
}
$(".reply-section .loading").addClass("hidden");
}); });
}); });
@ -624,6 +647,10 @@ $(function(){
formData.append("<?= $this->user->micropub_slug_field ?>", v); formData.append("<?= $this->user->micropub_slug_field ?>", v);
entry["<?= $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) { function appendPhotoToFormData(photo, prop) {
if(photo.external) { if(photo.external) {

Loading…
Cancel
Save