Browse Source

show RSVP field when replying to events

closes #71
pull/82/head
Aaron Parecki 7 years ago
parent
commit
fa782167af
No known key found for this signature in database GPG Key ID: 276C2817346D6056
4 changed files with 90 additions and 29 deletions
  1. +1
    -1
      composer.json
  2. +10
    -6
      composer.lock
  3. +36
    -6
      controllers/controllers.php
  4. +43
    -16
      views/new-post.php

+ 1
- 1
composer.json View File

@ -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.*",

+ 10
- 6
composer.lock View File

@ -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",

+ 36
- 6
controllers/controllers.php View File

@ -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,'@'));
}
}
}

+ 43
- 16
views/new-post.php View File

@ -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) {

Loading…
Cancel
Save