Merge branch 'feature/htmlfilter' into develop

This commit is contained in:
Jonny Barnes 2016-09-19 15:51:59 +01:00
commit dfedd64ed5
4 changed files with 21 additions and 69 deletions

View file

@ -6,6 +6,8 @@ use Cache;
use Twitter;
use App\Tag;
use App\Note;
use HTMLPurifier;
use HTMLPurifier_Config;
use Jonnybarnes\IndieWeb\Numbers;
use Illuminate\Filesystem\Filesystem;
use Jonnybarnes\WebmentionsParser\Authorship;
@ -103,7 +105,7 @@ class NotesController extends Controller
case 'in-reply-to':
$content['source'] = $webmention->source;
$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;
break;
@ -260,4 +262,19 @@ class NotesController extends Controller
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

@ -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);
}
});
//observer the webmention model
WebMention::observe(WebMentionObserver::class);
}
/**

View file

@ -1,5 +1,8 @@
# Changelog
## Version {next}
- Simplify how we filter/cache reply html
## Version 0.0.11.2 (2016-09-19)
- Update Typekits js sri hash