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 @@ 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 @@ Reply +
+