Merge branch 'release/0.0.11.3'

This commit is contained in:
Jonny Barnes 2016-09-19 17:29:08 +01:00
commit 8fb584a8ed
7 changed files with 68 additions and 103 deletions

View file

@ -41,13 +41,15 @@ class ParseCachedWebMentions extends Command
{ {
$HTMLfiles = $filesystem->allFiles(storage_path() . '/HTML'); $HTMLfiles = $filesystem->allFiles(storage_path() . '/HTML');
foreach ($HTMLfiles as $file) { foreach ($HTMLfiles as $file) {
$filepath = $file->getPathname(); if ($file->getExtension() != 'backup') { //we dont want to parse.backup files
$html = $filesystem->get($filepath); $filepath = $file->getPathname();
$url = $this->URLFromFilename($filepath); $html = $filesystem->get($filepath);
$microformats = \Mf2\parse($html, $url); $url = $this->URLFromFilename($filepath);
$webmention = WebMention::where('source', $url)->firstOrFail(); $microformats = \Mf2\parse($html, $url);
$webmention->mf2 = json_encode($microformats); $webmention = WebMention::where('source', $url)->firstOrFail();
$webmention->save(); $webmention->mf2 = json_encode($microformats);
$webmention->save();
}
} }
} }

View file

@ -6,6 +6,8 @@ use Cache;
use Twitter; use Twitter;
use App\Tag; use App\Tag;
use App\Note; use App\Note;
use HTMLPurifier;
use HTMLPurifier_Config;
use Jonnybarnes\IndieWeb\Numbers; use Jonnybarnes\IndieWeb\Numbers;
use Illuminate\Filesystem\Filesystem; use Illuminate\Filesystem\Filesystem;
use Jonnybarnes\WebmentionsParser\Authorship; use Jonnybarnes\WebmentionsParser\Authorship;
@ -103,7 +105,7 @@ class NotesController extends Controller
case 'in-reply-to': case 'in-reply-to':
$content['source'] = $webmention->source; $content['source'] = $webmention->source;
$content['date'] = $carbon->parse($content['date'])->toDayDateTimeString(); $content['date'] = $carbon->parse($content['date'])->toDayDateTimeString();
$content['reply'] = $microformats['items'][0]['properties']['content'][0]['html_purified']; $content['reply'] = $this->filterHTML($microformats['items'][0]['properties']['content'][0]['html']);
$replies[] = $content; $replies[] = $content;
break; break;
@ -260,4 +262,19 @@ class NotesController extends Controller
return $oEmbed; return $oEmbed;
} }
/**
* Filter the HTML in a reply webmention.
*
* @param string The reply HTML
* @return string The filtered HTML
*/
private function filterHTML($html)
{
$config = HTMLPurifier_Config::createDefault();
$config->set('Cache.SerializerPath', storage_path() . '/HTMLPurifier');
$purifier = new HTMLPurifier($config);
return $purifier->purify($html);
}
} }

View file

@ -41,10 +41,21 @@ class DownloadWebMention implements ShouldQueue
//Laravel should catch and retry these automatically. //Laravel should catch and retry these automatically.
if ($response->getStatusCode() == '200') { if ($response->getStatusCode() == '200') {
$filesystem = \Illuminate\FileSystem\FileSystem(); $filesystem = \Illuminate\FileSystem\FileSystem();
$filename = $this->createFilenameFromURL($source);
//backup file first
$filenameBackup = $filename . '.' . date('Y-m-d') . '.backup';
if ($filesystem->exists($filename)) {
$filesystem->copy($filename, $filenameBackup);
}
//save new HTML
$filesystem->put( $filesystem->put(
$this->createFilenameFromURL($source), $filename,
(string) $response->getBody() (string) $response->getBody()
); );
//remove backup if the same
if ($filesystem->get($filename) == $filesystem->get($filenameBackup)) {
$filesystem->delete($filenameBackup);
}
} }
} }

View file

@ -1,65 +0,0 @@
<?php
namespace App\Observers;
use HTMLPurifier;
use App\WebMention;
use HTMLPurifier_Config;
class WebMentionObserver
{
/**
* Listen for the created event.
*
* @param WebMention $webmention
* @return void
*/
public function created(WebMention $webmention)
{
$this->addFilteredHTML($webmention);
}
/**
* Listen for the updated event.
*
* @param WebMention $webmention
* @return void
*/
public function updated(WebMention $webmention)
{
$this->addFilteredHTML($webmention);
}
/**
* Filter the HTML in a reply webmention.
*
* @param WebMention The WebMention model
* @return void
*/
private function addFilteredHTML(WebMention $webmention)
{
$mf2 = json_decode($webmention->mf2);
if (isset($mf2['items'][0]['properties']['content'][0]['html'])) {
$mf2['items'][0]['properties']['content'][0]['html_purified'] = $this->useHTMLPurifier(
$mf2['items'][0]['properties']['content'][0]['html']
);
}
$webmention->mf2 = json_encode($mf2);
$webmetion->save();
}
/**
* Set up and use HTMLPurifer on some HTML.
*
* @param string The HTML to be processed
* @return string The processed HTML
*/
private function useHTMLPurifier($html)
{
$config = HTMLPurifier_Config::createDefault();
$config->set('Cache.SerializerPath', storage_path() . '/HTMLPurifier');
$purifier = new HTMLPurifier($config);
return $purifier->purify($html);
}
}

View file

@ -47,9 +47,6 @@ class AppServiceProvider extends ServiceProvider
$note->tags()->attach($tagsToAdd); $note->tags()->attach($tagsToAdd);
} }
}); });
//observer the webmention model
WebMention::observe(WebMentionObserver::class);
} }
/** /**

View file

@ -1,5 +1,9 @@
# Changelog # Changelog
## Version 0.0.11.3 (2016-09-19)
- Simplify how we filter/cache reply html
- Better handling of webmention reply HTML cache
## Version 0.0.11.2 (2016-09-19) ## Version 0.0.11.2 (2016-09-19)
- Update Typekits js sri hash - Update Typekits js sri hash

51
composer.lock generated
View file

@ -4,7 +4,6 @@
"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"
], ],
"hash": "b65fffcf4b32d065494b01ada5391976",
"content-hash": "86faec8ac49549630fc60578bcd085cc", "content-hash": "86faec8ac49549630fc60578bcd085cc",
"packages": [ "packages": [
{ {
@ -59,16 +58,16 @@
}, },
{ {
"name": "aws/aws-sdk-php", "name": "aws/aws-sdk-php",
"version": "3.19.6", "version": "3.19.8",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/aws/aws-sdk-php.git", "url": "https://github.com/aws/aws-sdk-php.git",
"reference": "34060bf0db260031697b17dbb37fa1bbec92f1c4" "reference": "4e976ef6750bb177f493f3b01476136213b8d0b9"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/34060bf0db260031697b17dbb37fa1bbec92f1c4", "url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/4e976ef6750bb177f493f3b01476136213b8d0b9",
"reference": "34060bf0db260031697b17dbb37fa1bbec92f1c4", "reference": "4e976ef6750bb177f493f3b01476136213b8d0b9",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -135,7 +134,7 @@
"s3", "s3",
"sdk" "sdk"
], ],
"time": "2016-09-08 20:27:15" "time": "2016-09-15 21:43:53"
}, },
{ {
"name": "barnabywalters/mf-cleaner", "name": "barnabywalters/mf-cleaner",
@ -1533,16 +1532,16 @@
}, },
{ {
"name": "laravel/framework", "name": "laravel/framework",
"version": "v5.3.8", "version": "v5.3.9",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/laravel/framework.git", "url": "https://github.com/laravel/framework.git",
"reference": "99c74afc0b99e1af1984cb55dc242ab28a0e496b" "reference": "f6fbb481672f8dc4bc6882d5d654bbfa3588c8ec"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/laravel/framework/zipball/99c74afc0b99e1af1984cb55dc242ab28a0e496b", "url": "https://api.github.com/repos/laravel/framework/zipball/f6fbb481672f8dc4bc6882d5d654bbfa3588c8ec",
"reference": "99c74afc0b99e1af1984cb55dc242ab28a0e496b", "reference": "f6fbb481672f8dc4bc6882d5d654bbfa3588c8ec",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -1656,7 +1655,7 @@
"framework", "framework",
"laravel" "laravel"
], ],
"time": "2016-09-09 16:33:59" "time": "2016-09-12 14:08:29"
}, },
{ {
"name": "lcobucci/jwt", "name": "lcobucci/jwt",
@ -2297,16 +2296,16 @@
}, },
{ {
"name": "nikic/php-parser", "name": "nikic/php-parser",
"version": "v2.1.0", "version": "v2.1.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/nikic/PHP-Parser.git", "url": "https://github.com/nikic/PHP-Parser.git",
"reference": "47b254ea51f1d6d5dc04b9b299e88346bf2369e3" "reference": "4dd659edadffdc2143e4753df655d866dbfeedf0"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/47b254ea51f1d6d5dc04b9b299e88346bf2369e3", "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/4dd659edadffdc2143e4753df655d866dbfeedf0",
"reference": "47b254ea51f1d6d5dc04b9b299e88346bf2369e3", "reference": "4dd659edadffdc2143e4753df655d866dbfeedf0",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -2344,7 +2343,7 @@
"parser", "parser",
"php" "php"
], ],
"time": "2016-04-19 13:41:41" "time": "2016-09-16 12:04:44"
}, },
{ {
"name": "paragonie/random_compat", "name": "paragonie/random_compat",
@ -2882,16 +2881,16 @@
}, },
{ {
"name": "spatie/laravel-medialibrary", "name": "spatie/laravel-medialibrary",
"version": "4.8.3", "version": "4.8.4",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/spatie/laravel-medialibrary.git", "url": "https://github.com/spatie/laravel-medialibrary.git",
"reference": "7fcb591ff0ef2d28b9b622f84f972c642ff3e8f9" "reference": "8c862e270d49e8bbff6f0993900c8bb59ea165ea"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/spatie/laravel-medialibrary/zipball/7fcb591ff0ef2d28b9b622f84f972c642ff3e8f9", "url": "https://api.github.com/repos/spatie/laravel-medialibrary/zipball/8c862e270d49e8bbff6f0993900c8bb59ea165ea",
"reference": "7fcb591ff0ef2d28b9b622f84f972c642ff3e8f9", "reference": "8c862e270d49e8bbff6f0993900c8bb59ea165ea",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -2945,7 +2944,7 @@
"media", "media",
"spatie" "spatie"
], ],
"time": "2016-08-25 08:08:10" "time": "2016-09-14 16:31:49"
}, },
{ {
"name": "spatie/pdf-to-image", "name": "spatie/pdf-to-image",
@ -4349,16 +4348,16 @@
}, },
{ {
"name": "myclabs/deep-copy", "name": "myclabs/deep-copy",
"version": "1.5.2", "version": "1.5.4",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/myclabs/DeepCopy.git", "url": "https://github.com/myclabs/DeepCopy.git",
"reference": "da8529775f14f4fdae33f916eb0cf65f6afbddbc" "reference": "ea74994a3dc7f8d2f65a06009348f2d63c81e61f"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/da8529775f14f4fdae33f916eb0cf65f6afbddbc", "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/ea74994a3dc7f8d2f65a06009348f2d63c81e61f",
"reference": "da8529775f14f4fdae33f916eb0cf65f6afbddbc", "reference": "ea74994a3dc7f8d2f65a06009348f2d63c81e61f",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -4387,7 +4386,7 @@
"object", "object",
"object graph" "object graph"
], ],
"time": "2016-09-06 16:07:05" "time": "2016-09-16 13:37:59"
}, },
{ {
"name": "phpdocumentor/reflection-common", "name": "phpdocumentor/reflection-common",