Merge branch 'release/0.0.9'
This commit is contained in:
commit
4ac589528b
46 changed files with 1405 additions and 674 deletions
|
@ -1,33 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Foundation\Inspiring;
|
||||
|
||||
class Inspire extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'inspire';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Display an inspiring quote';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$this->comment(PHP_EOL.Inspiring::quote().PHP_EOL);
|
||||
}
|
||||
}
|
|
@ -13,7 +13,7 @@ class Kernel extends ConsoleKernel
|
|||
* @var array
|
||||
*/
|
||||
protected $commands = [
|
||||
// Commands\Inspire::class,
|
||||
//
|
||||
];
|
||||
|
||||
/**
|
||||
|
@ -27,4 +27,14 @@ class Kernel extends ConsoleKernel
|
|||
// $schedule->command('inspire')
|
||||
// ->hourly();
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the Closure based commands for the application.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function commands()
|
||||
{
|
||||
require base_path('routes/console.php');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
abstract class Event
|
||||
{
|
||||
//
|
||||
}
|
|
@ -3,12 +3,8 @@
|
|||
namespace App\Exceptions;
|
||||
|
||||
use Exception;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Illuminate\Session\TokenMismatchException;
|
||||
use Illuminate\Auth\Access\AuthorizationException;
|
||||
use Illuminate\Auth\AuthenticationException;
|
||||
use Symfony\Component\Debug\Exception\FlattenException;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
||||
|
||||
class Handler extends ExceptionHandler
|
||||
|
@ -19,10 +15,12 @@ class Handler extends ExceptionHandler
|
|||
* @var array
|
||||
*/
|
||||
protected $dontReport = [
|
||||
AuthorizationException::class,
|
||||
HttpException::class,
|
||||
ModelNotFoundException::class,
|
||||
ValidationException::class,
|
||||
\Illuminate\Auth\AuthenticationException::class,
|
||||
\Illuminate\Auth\Access\AuthorizationException::class,
|
||||
\Symfony\Component\HttpKernel\Exception\HttpException::class,
|
||||
\Illuminate\Database\Eloquent\ModelNotFoundException::class,
|
||||
\Illuminate\Session\TokenMismatchException::class,
|
||||
\Illuminate\Validation\ValidationException::class,
|
||||
];
|
||||
|
||||
/**
|
||||
|
@ -30,38 +28,40 @@ class Handler extends ExceptionHandler
|
|||
*
|
||||
* This is a great spot to send exceptions to Sentry, Bugsnag, etc.
|
||||
*
|
||||
* @param \Exception $exc
|
||||
* @param \Exception $exception
|
||||
* @return void
|
||||
*/
|
||||
public function report(Exception $exc)
|
||||
public function report(Exception $exception)
|
||||
{
|
||||
parent::report($exc);
|
||||
parent::report($exception);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render an exception into an HTTP response.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Exception $exc
|
||||
* @param \Exception $exception
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function render($request, Exception $exc)
|
||||
public function render($request, Exception $exception)
|
||||
{
|
||||
if (config('app.debug')) {
|
||||
return $this->renderExceptionWithWhoops($exc);
|
||||
return parent::render($request, $exception);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert an authentication exception into an unauthenticated response.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Illuminate\Auth\AuthenticationException $exception
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
protected function unauthenticated($request, AuthenticationException $exception)
|
||||
{
|
||||
if ($request->expectsJson()) {
|
||||
return response()->json(['error' => 'Unauthenticated.'], 401);
|
||||
}
|
||||
|
||||
if ($exc instanceof ModelNotFoundException) {
|
||||
$exc = new NotFoundHttpException($exc->getMessage(), $exc);
|
||||
}
|
||||
|
||||
if ($exc instanceof TokenMismatchException) {
|
||||
return redirect()->back()
|
||||
->withInput($request->except('password', '_token'))
|
||||
->withErrors('Validation Token has expired. Please try again', 'csrf');
|
||||
}
|
||||
|
||||
return parent::render($request, $exc);
|
||||
return redirect()->guest('login');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -70,7 +70,7 @@ class Handler extends ExceptionHandler
|
|||
* @param \Exception $exc
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
protected function renderExceptionWithWhoops(Exception $exc)
|
||||
protected function renderExceptionWithWhoops(Exception $exception)
|
||||
{
|
||||
$whoops = new \Whoops\Run;
|
||||
$handler = new \Whoops\Handler\PrettyPageHandler();
|
||||
|
@ -79,7 +79,7 @@ class Handler extends ExceptionHandler
|
|||
});
|
||||
$whoops->pushHandler($handler);
|
||||
|
||||
$flattened = FlattenException::create($exc);
|
||||
$flattened = FlattenException::create($exception);
|
||||
|
||||
return new \Illuminate\Http\Response(
|
||||
$whoops->handleException($exc),
|
||||
|
|
32
app/Http/Controllers/Auth/ForgotPasswordController.php
Normal file
32
app/Http/Controllers/Auth/ForgotPasswordController.php
Normal file
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Foundation\Auth\SendsPasswordResetEmails;
|
||||
|
||||
class ForgotPasswordController extends Controller
|
||||
{
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Password Reset Controller
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This controller is responsible for handling password reset emails and
|
||||
| includes a trait which assists in sending these notifications from
|
||||
| your application to your users. Feel free to explore this trait.
|
||||
|
|
||||
*/
|
||||
|
||||
use SendsPasswordResetEmails;
|
||||
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('guest');
|
||||
}
|
||||
}
|
39
app/Http/Controllers/Auth/LoginController.php
Normal file
39
app/Http/Controllers/Auth/LoginController.php
Normal file
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Foundation\Auth\AuthenticatesUsers;
|
||||
|
||||
class LoginController extends Controller
|
||||
{
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Login Controller
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This controller handles authenticating users for the application and
|
||||
| redirecting them to your home screen. The controller uses a trait
|
||||
| to conveniently provide its functionality to your applications.
|
||||
|
|
||||
*/
|
||||
|
||||
use AuthenticatesUsers;
|
||||
|
||||
/**
|
||||
* Where to redirect users after login / registration.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $redirectTo = '/home';
|
||||
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('guest', ['except' => 'logout']);
|
||||
}
|
||||
}
|
|
@ -5,39 +5,38 @@ namespace App\Http\Controllers\Auth;
|
|||
use App\User;
|
||||
use Validator;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Foundation\Auth\ThrottlesLogins;
|
||||
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;
|
||||
use Illuminate\Foundation\Auth\RegistersUsers;
|
||||
|
||||
class AuthController extends Controller
|
||||
class RegisterController extends Controller
|
||||
{
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Registration & Login Controller
|
||||
| Register Controller
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This controller handles the registration of new users, as well as the
|
||||
| authentication of existing users. By default, this controller uses
|
||||
| a simple trait to add these behaviors. Why don't you explore it?
|
||||
| This controller handles the registration of new users as well as their
|
||||
| validation and creation. By default this controller uses a trait to
|
||||
| provide this functionality without requiring any additional code.
|
||||
|
|
||||
*/
|
||||
|
||||
use AuthenticatesAndRegistersUsers, ThrottlesLogins;
|
||||
use RegistersUsers;
|
||||
|
||||
/**
|
||||
* Where to redirect users after login / registration.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $redirectTo = '/';
|
||||
protected $redirectTo = '/home';
|
||||
|
||||
/**
|
||||
* Create a new authentication controller instance.
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware($this->guestMiddleware(), ['except' => 'logout']);
|
||||
$this->middleware('guest');
|
||||
}
|
||||
|
||||
/**
|
|
@ -5,7 +5,7 @@ namespace App\Http\Controllers\Auth;
|
|||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Foundation\Auth\ResetsPasswords;
|
||||
|
||||
class PasswordController extends Controller
|
||||
class ResetPasswordController extends Controller
|
||||
{
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
|
@ -21,12 +21,12 @@ class PasswordController extends Controller
|
|||
use ResetsPasswords;
|
||||
|
||||
/**
|
||||
* Create a new password controller instance.
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware($this->guestMiddleware());
|
||||
$this->middleware('guest');
|
||||
}
|
||||
}
|
|
@ -6,9 +6,8 @@ use Illuminate\Foundation\Bus\DispatchesJobs;
|
|||
use Illuminate\Routing\Controller as BaseController;
|
||||
use Illuminate\Foundation\Validation\ValidatesRequests;
|
||||
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
||||
use Illuminate\Foundation\Auth\Access\AuthorizesResources;
|
||||
|
||||
class Controller extends BaseController
|
||||
{
|
||||
use AuthorizesRequests, AuthorizesResources, DispatchesJobs, ValidatesRequests;
|
||||
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
|
||||
}
|
||||
|
|
|
@ -7,6 +7,8 @@ use Twitter;
|
|||
use App\Tag;
|
||||
use App\Note;
|
||||
use Jonnybarnes\IndieWeb\Numbers;
|
||||
use Illuminate\Filesystem\Filesystem;
|
||||
use Jonnybarnes\WebmentionsParser\Authorship;
|
||||
|
||||
// Need to sort out Twitter and webmentions!
|
||||
|
||||
|
@ -23,8 +25,8 @@ class NotesController extends Controller
|
|||
foreach ($notes as $note) {
|
||||
$replies = 0;
|
||||
foreach ($note->webmentions as $webmention) {
|
||||
if ($webmention->type == 'reply') {
|
||||
$replies = $replies + 1;
|
||||
if ($webmention->type == 'in-reply-to') {
|
||||
$replies++;
|
||||
}
|
||||
}
|
||||
$note->replies = $replies;
|
||||
|
@ -67,31 +69,51 @@ class NotesController extends Controller
|
|||
public function singleNote($urlId)
|
||||
{
|
||||
$numbers = new Numbers();
|
||||
$authorship = new Authorship();
|
||||
$realId = $numbers->b60tonum($urlId);
|
||||
$note = Note::find($realId);
|
||||
$replies = [];
|
||||
$reposts = [];
|
||||
$likes = [];
|
||||
foreach ($note->webmentions as $webmention) {
|
||||
/*
|
||||
reply->url |
|
||||
reply->photo | Author
|
||||
reply->name |
|
||||
reply->source
|
||||
reply->date
|
||||
reply->reply
|
||||
|
||||
repost->url |
|
||||
repost->photo | Author
|
||||
repost->name |
|
||||
repost->date
|
||||
repost->source
|
||||
|
||||
like->url |
|
||||
like->photo | Author
|
||||
like->name |
|
||||
*/
|
||||
$microformats = json_decode($webmention->mf2);
|
||||
$authorHCard = $authorship->findAuthor($microformats);
|
||||
$content['url'] = $authorHCard['properties']['url'][0];
|
||||
$content['photo'] = $this->createPhotoLink($authorHCard['properties']['photo'][0]);
|
||||
$content['name'] = $authorHCard['properties']['name'][0];
|
||||
switch ($webmention->type) {
|
||||
case 'reply':
|
||||
$content = unserialize($webmention->content);
|
||||
$content['source'] = $this->bridgyReply($webmention->source);
|
||||
$content['photo'] = $this->createPhotoLink($content['photo']);
|
||||
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'];
|
||||
$replies[] = $content;
|
||||
break;
|
||||
|
||||
case 'repost':
|
||||
$content = unserialize($webmention->content);
|
||||
$content['photo'] = $this->createPhotoLink($content['photo']);
|
||||
case 'repost-of':
|
||||
$content['date'] = $carbon->parse($content['date'])->toDayDateTimeString();
|
||||
$content['source'] = $webmention->source;
|
||||
$reposts[] = $content;
|
||||
break;
|
||||
|
||||
case 'like':
|
||||
$content = unserialize($webmention->content);
|
||||
$content['photo'] = $this->createPhotoLink($content['photo']);
|
||||
case 'like-of':
|
||||
$likes[] = $content;
|
||||
break;
|
||||
}
|
||||
|
@ -164,41 +186,43 @@ class NotesController extends Controller
|
|||
return view('taggednotes', ['notes' => $notes, 'tag' => $tag]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Swap a brid.gy URL shim-ing a twitter reply to a real twitter link.
|
||||
*
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
public function bridgyReply($source)
|
||||
{
|
||||
$url = $source;
|
||||
if (mb_substr($source, 0, 28, 'UTF-8') == 'https://brid-gy.appspot.com/') {
|
||||
$parts = explode('/', $source);
|
||||
$tweetId = array_pop($parts);
|
||||
if ($tweetId) {
|
||||
$url = 'https://twitter.com/_/status/' . $tweetId;
|
||||
}
|
||||
}
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the photo link.
|
||||
*
|
||||
* We shall leave twitter.com and twimg.com links as they are. Then we shall
|
||||
* check for local copies, if that fails leave the link as is.
|
||||
*
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
public function createPhotoLink($url)
|
||||
{
|
||||
$host = parse_url($url)['host'];
|
||||
if ($host != 'twitter.com' && $host != 'pbs.twimg.com') {
|
||||
return '/assets/profile-images/' . $host . '/image';
|
||||
}
|
||||
if (mb_substr($url, 0, 20) == 'http://pbs.twimg.com') {
|
||||
$host = parse_url($url, PHP_URL_HOST);
|
||||
if ($host == 'pbs.twimg.com') {
|
||||
//make sure we use HTTPS, we know twitter supports it
|
||||
return str_replace('http://', 'https://', $url);
|
||||
}
|
||||
if ($host == 'twitter.com') {
|
||||
if (Cache::has($url)) {
|
||||
return Cache::get($url);
|
||||
}
|
||||
$username = parse_url($url, PHP_URL_PATH);
|
||||
try {
|
||||
$info = Twitter::getUsers(['screen_name' => $username]);
|
||||
$profile_image = $info->profile_image_url_https;
|
||||
Cache::put($url, $profile_image, 10080); //1 week
|
||||
} catch (Exception $e) {
|
||||
return $url; //not sure here
|
||||
}
|
||||
|
||||
return $profile_image;
|
||||
}
|
||||
$filesystem = new Filesystem();
|
||||
if ($filesystem->exists(public_path() . '/assets/profile-images/' . $host . '/image')) {
|
||||
return '/assets/profile-images/' . $host . '/image';
|
||||
}
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -28,7 +28,7 @@ class WebMentionsController extends Controller
|
|||
}
|
||||
|
||||
//next check the $target is valid
|
||||
$path = parse_url($request->input('target'))['path'];
|
||||
$path = parse_url($request->input('target'), PHP_URL_PATH);
|
||||
$pathParts = explode('/', $path);
|
||||
|
||||
switch ($pathParts[1]) {
|
||||
|
@ -36,9 +36,8 @@ class WebMentionsController extends Controller
|
|||
//we have a note
|
||||
$noteId = $pathParts[2];
|
||||
$numbers = new Numbers();
|
||||
$realId = $numbers->b60tonum($noteId);
|
||||
try {
|
||||
$note = Note::findOrFail($realId);
|
||||
$note = Note::findOrFail($numbers->b60tonum($noteId));
|
||||
$this->dispatch(new ProcessWebMention($note, $request->input('source')));
|
||||
} catch (ModelNotFoundException $e) {
|
||||
return new Response('This note doesn’t exist.', 400);
|
||||
|
|
|
@ -29,11 +29,13 @@ class Kernel extends HttpKernel
|
|||
\Illuminate\Session\Middleware\StartSession::class,
|
||||
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
|
||||
\App\Http\Middleware\VerifyCsrfToken::class,
|
||||
\Illuminate\Routing\Middleware\SubstituteBindings::class,
|
||||
\App\Http\Middleware\LinkHeadersMiddleware::class,
|
||||
],
|
||||
|
||||
'api' => [
|
||||
'throttle:60,1',
|
||||
'bindings',
|
||||
],
|
||||
];
|
||||
|
||||
|
@ -47,7 +49,7 @@ class Kernel extends HttpKernel
|
|||
protected $routeMiddleware = [
|
||||
'auth' => \App\Http\Middleware\Authenticate::class,
|
||||
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
|
||||
'can' => \Illuminate\Foundation\Http\Middleware\Authorize::class,
|
||||
'can' => \Illuminate\Auth\Middleware\Authorize::class,
|
||||
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
|
||||
'myauth' => \App\Http\Middleware\MyAuthMiddleware::class,
|
||||
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
|
||||
|
|
|
@ -1,30 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class Authenticate
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @param string|null $guard
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle($request, Closure $next, $guard = null)
|
||||
{
|
||||
if (Auth::guard($guard)->guest()) {
|
||||
if ($request->ajax() || $request->wantsJson()) {
|
||||
return response('Unauthorized.', 401);
|
||||
} else {
|
||||
return redirect()->guest('login');
|
||||
}
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
abstract class Request extends FormRequest
|
||||
{
|
||||
//
|
||||
}
|
|
@ -2,8 +2,8 @@
|
|||
|
||||
namespace App\Jobs;
|
||||
|
||||
use Mf2;
|
||||
use App\Note;
|
||||
use Mf2\parse;
|
||||
use HTMLPurifier;
|
||||
use App\WebMention;
|
||||
use GuzzleHttp\Client;
|
||||
|
@ -11,14 +11,18 @@ use HTMLPurifier_Config;
|
|||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Jonnybarnes\WebmentionsParser\Parser;
|
||||
use GuzzleHttp\Exception\RequestException;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\DispatchesJobs;
|
||||
use App\Exceptions\RemoteContentNotFoundException;
|
||||
|
||||
class ProcessWebMention extends Job implements ShouldQueue
|
||||
{
|
||||
use InteractsWithQueue, SerializesModels;
|
||||
use InteractsWithQueue, SerializesModels, DispatchesJobs;
|
||||
|
||||
protected $note;
|
||||
protected $source;
|
||||
protected $guzzle;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
|
@ -27,10 +31,11 @@ class ProcessWebMention extends Job implements ShouldQueue
|
|||
* @param string $source
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Note $note, $source)
|
||||
public function __construct(Note $note, $source, Client $guzzle = null)
|
||||
{
|
||||
$this->note = $note;
|
||||
$this->source = $source;
|
||||
$this->guzzle = $guzzle ?? new Client();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -44,113 +49,83 @@ class ProcessWebMention extends Job implements ShouldQueue
|
|||
$sourceURL = parse_url($this->source);
|
||||
$baseURL = $sourceURL['scheme'] . '://' . $sourceURL['host'];
|
||||
$remoteContent = $this->getRemoteContent($this->source);
|
||||
$microformats = $this->parseHTML($remoteContent, $baseURL);
|
||||
$count = WebMention::where('source', '=', $this->source)->count();
|
||||
if ($count > 0) {
|
||||
//we already have a webmention from this source
|
||||
$webmentions = WebMention::where('source', '=', $this->source)->get();
|
||||
foreach ($webmentions as $webmention) {
|
||||
//now check it still 'mentions' this target
|
||||
//we switch for each type of mention (reply/like/repost)
|
||||
switch ($webmention->type) {
|
||||
case 'reply':
|
||||
if ($parser->checkInReplyTo($microformats, $note->longurl) == false) {
|
||||
//it doesn't so delete
|
||||
$webmention->delete();
|
||||
if ($remoteContent === null) {
|
||||
throw new RemoteContentNotFoundException;
|
||||
}
|
||||
$microformats = Mf2\parse($remoteContent, $baseURL);
|
||||
$webmentions = WebMention::where('source', $this->source)->get();
|
||||
foreach ($webmentions as $webmention) {
|
||||
//check webmention still references target
|
||||
//we try each type of mention (reply/like/repost)
|
||||
if ($webmention->type == 'in-reply-to') {
|
||||
if ($parser->checkInReplyTo($microformats, $this->note->longurl) == false) {
|
||||
//it doesn't so delete
|
||||
$webmention->delete();
|
||||
|
||||
return true;
|
||||
}
|
||||
//webmenion is still a reply, so update content
|
||||
$content = $parser->replyContent($microformats);
|
||||
$this->saveImage($content);
|
||||
$content['reply'] = $this->filterHTML($content['reply']);
|
||||
$content = serialize($content);
|
||||
$webmention->content = $content;
|
||||
$webmention->save();
|
||||
return;
|
||||
}
|
||||
//webmenion is still a reply, so update content
|
||||
$microformats = $this->filterHTML($microformats);
|
||||
$this->dispatch(new SaveProfileImage($microformats));
|
||||
$webmention->mf2 = json_encode($microformats);
|
||||
$webmention->save();
|
||||
|
||||
return true;
|
||||
break;
|
||||
case 'like':
|
||||
if ($parser->checkLikeOf($microformats, $note->longurl) == false) {
|
||||
//it doesn't so delete
|
||||
$webmention->delete();
|
||||
return;
|
||||
}
|
||||
if ($webmention->type == 'like-of') {
|
||||
if ($parser->checkLikeOf($microformats, $note->longurl) == false) {
|
||||
//it doesn't so delete
|
||||
$webmention->delete();
|
||||
|
||||
return true;
|
||||
} //note we don't need to do anything if it still is a like
|
||||
break;
|
||||
case 'repost':
|
||||
if ($parser->checkRepostOf($microformats, $note->longurl) == false) {
|
||||
//it doesn't so delete
|
||||
$webmention->delete();
|
||||
return;
|
||||
} //note we don't need to do anything if it still is a like
|
||||
}
|
||||
if ($webmention->type == 'repost-of') {
|
||||
if ($parser->checkRepostOf($microformats, $note->longurl) == false) {
|
||||
//it doesn't so delete
|
||||
$webmention->delete();
|
||||
|
||||
return;
|
||||
} //again, we don't need to do anything if it still is a repost
|
||||
}
|
||||
}//foreach
|
||||
|
||||
return true;
|
||||
} //again, we don't need to do anything if it still is a repost
|
||||
break;
|
||||
}//switch
|
||||
}//foreach
|
||||
}//if
|
||||
//no wemention in db so create new one
|
||||
$webmention = new WebMention();
|
||||
//check it is in fact a reply
|
||||
if ($parser->checkInReplyTo($microformats, $note->longurl)) {
|
||||
$content = $parser->replyContent($microformats);
|
||||
$this->saveImage($content);
|
||||
$content['reply'] = $this->filterHTML($content['reply']);
|
||||
$content = serialize($content);
|
||||
$webmention->source = $this->source;
|
||||
$webmention->target = $note->longurl;
|
||||
$webmention->commentable_id = $this->note->id;
|
||||
$webmention->commentable_type = 'App\Note';
|
||||
$webmention->type = 'reply';
|
||||
$webmention->content = $content;
|
||||
$webmention->save();
|
||||
|
||||
return true;
|
||||
} elseif ($parser->checkLikeOf($microformats, $note->longurl)) {
|
||||
//it is a like
|
||||
$content = $parser->likeContent($microformats);
|
||||
$this->saveImage($content);
|
||||
$content = serialize($content);
|
||||
$webmention->source = $this->source;
|
||||
$webmention->target = $note->longurl;
|
||||
$webmention->commentable_id = $this->note->id;
|
||||
$webmention->commentable_type = 'App\Note';
|
||||
$webmention->type = 'like';
|
||||
$webmention->content = $content;
|
||||
$webmention->save();
|
||||
|
||||
return true;
|
||||
} elseif ($parser->checkRepostOf($microformats, $note->longurl)) {
|
||||
//it is a repost
|
||||
$content = $parser->repostContent($microformats);
|
||||
$this->saveImage($content);
|
||||
$content = serialize($content);
|
||||
$webmention->source = $this->source;
|
||||
$webmention->target = $note->longurl;
|
||||
$webmention->commentable_id = $this->note->id;
|
||||
$webmention->commentable_type = 'App\Note';
|
||||
$webmention->type = 'repost';
|
||||
$webmention->content = $content;
|
||||
$webmention->save();
|
||||
|
||||
return true;
|
||||
}
|
||||
$type = $parser->getMentionType($microformats); //throw error here?
|
||||
$this->dispatch(new SaveProfileImage($microformats));
|
||||
$microformats = $this->filterHTML($microformats);
|
||||
$webmention->source = $this->source;
|
||||
$webmention->target = $this->note->longurl;
|
||||
$webmention->commentable_id = $this->note->id;
|
||||
$webmention->commentable_type = 'App\Note';
|
||||
$webmention->type = $type;
|
||||
$webmention->mf2 = json_encode($microformats);
|
||||
$webmention->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retreive the remote content from a URL, and caches the result.
|
||||
*
|
||||
* @param string The URL to retreive content from
|
||||
* @return string The HTML from the URL
|
||||
* @param string The URL to retreive content from
|
||||
* @return string|null The HTML from the URL (or null if error)
|
||||
*/
|
||||
private function getRemoteContent($url)
|
||||
{
|
||||
$client = new Client();
|
||||
|
||||
$response = $client->get($url);
|
||||
try {
|
||||
$response = $this->guzzle->request('GET', $url);
|
||||
} catch (RequestException $e) {
|
||||
return;
|
||||
}
|
||||
$html = (string) $response->getBody();
|
||||
$path = storage_path() . '/HTML/' . $this->createFilenameFromURL($url);
|
||||
$this->fileForceContents($path, $html);
|
||||
$parts = explode('/', $path);
|
||||
$name = array_pop($parts);
|
||||
$dir = implode('/', $parts);
|
||||
if (! is_dir($dir)) {
|
||||
mkdir($dir, 0755, true);
|
||||
}
|
||||
file_put_contents("$dir/$name", $html);
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
@ -173,79 +148,29 @@ class ProcessWebMention extends Job implements ShouldQueue
|
|||
}
|
||||
|
||||
/**
|
||||
* Save a file, and create any necessary folders.
|
||||
* Filter the HTML in a reply webmention.
|
||||
*
|
||||
* @param string The directory to save to
|
||||
* @param binary The file to save
|
||||
* @param array The unfiltered microformats
|
||||
* @return array The filtered microformats
|
||||
*/
|
||||
private function fileForceContents($dir, $contents)
|
||||
private function filterHTML($microformats)
|
||||
{
|
||||
$parts = explode('/', $dir);
|
||||
$name = array_pop($parts);
|
||||
$dir = implode('/', $parts);
|
||||
if (! is_dir($dir)) {
|
||||
mkdir($dir, 0755, true);
|
||||
if (isset($microformats['items'][0]['properties']['content'][0]['html'])) {
|
||||
$microformats['items'][0]['properties']['content'][0]['html_purified'] = $this->useHTMLPurifier(
|
||||
$microformats['items'][0]['properties']['content'][0]['html']
|
||||
);
|
||||
}
|
||||
file_put_contents("$dir/$name", $contents);
|
||||
}
|
||||
|
||||
/**
|
||||
* A wrapper function for php-mf2’s parse method.
|
||||
*
|
||||
* @param string The HTML to parse
|
||||
* @param string The base URL to resolve relative URLs in the HTML against
|
||||
* @return array The porcessed microformats
|
||||
*/
|
||||
private function parseHTML($html, $baseurl)
|
||||
{
|
||||
$microformats = \Mf2\parse((string) $html, $baseurl);
|
||||
|
||||
return $microformats;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save a profile image to the local cache.
|
||||
*
|
||||
* @param array source content
|
||||
* @return bool wether image was saved or not (we don’t save twitter profiles)
|
||||
*/
|
||||
public function saveImage(array $content)
|
||||
{
|
||||
$photo = $content['photo'];
|
||||
$home = $content['url'];
|
||||
//dont save pbs.twimg.com links
|
||||
if (parse_url($photo)['host'] != 'pbs.twimg.com'
|
||||
&& parse_url($photo)['host'] != 'twitter.com') {
|
||||
$client = new Client();
|
||||
try {
|
||||
$response = $client->get($photo);
|
||||
$image = $response->getBody(true);
|
||||
$path = public_path() . '/assets/profile-images/' . parse_url($home)['host'] . '/image';
|
||||
$this->fileForceContents($path, $image);
|
||||
} catch (Exception $e) {
|
||||
// we are openning and reading the default image so that
|
||||
// fileForceContent work
|
||||
$default = public_path() . '/assets/profile-images/default-image';
|
||||
$handle = fopen($default, 'rb');
|
||||
$image = fread($handle, filesize($default));
|
||||
fclose($handle);
|
||||
$path = public_path() . '/assets/profile-images/' . parse_url($home)['host'] . '/image';
|
||||
$this->fileForceContents($path, $image);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Purify HTML received from a webmention.
|
||||
* Set up and use HTMLPurifer on some HTML.
|
||||
*
|
||||
* @param string The HTML to be processed
|
||||
* @return string The processed HTML
|
||||
*/
|
||||
public function filterHTML($html)
|
||||
private function useHTMLPurifier($html)
|
||||
{
|
||||
$config = HTMLPurifier_Config::createDefault();
|
||||
$config->set('Cache.SerializerPath', storage_path() . '/HTMLPurifier');
|
||||
|
|
66
app/Jobs/SaveProfileImage.php
Normal file
66
app/Jobs/SaveProfileImage.php
Normal file
|
@ -0,0 +1,66 @@
|
|||
<?php
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use GuzzleHttp\Exception\RequestException;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Jonnybarnes\WebmentionsParser\Authorship;
|
||||
use Jonnybarnes\WebmentionsParser\Exceptions\AuthorshipParserException;
|
||||
|
||||
class SaveProfileImage extends Job implements ShouldQueue
|
||||
{
|
||||
use InteractsWithQueue, SerializesModels;
|
||||
|
||||
protected $microformats;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($microformats)
|
||||
{
|
||||
$this->microformats = $microformats;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle(Authorship $authorship)
|
||||
{
|
||||
try {
|
||||
$author = $authorship->findAuthor($microformats);
|
||||
} catch (AuthorshipParserException $e) {
|
||||
return;
|
||||
}
|
||||
$photo = $author['properties'][0]['photo'][0];
|
||||
$home = $author['properties'][0]['url'][0];
|
||||
//dont save pbs.twimg.com links
|
||||
if (parse_url($photo, PHP_URL_HOST) != 'pbs.twimg.com'
|
||||
&& parse_url($photo, PHP_URL_HOST) != 'twitter.com') {
|
||||
$client = new Client();
|
||||
try {
|
||||
$response = $client->get($photo);
|
||||
$image = $response->getBody(true);
|
||||
} catch (RequestException $e) {
|
||||
// we are openning and reading the default image so that
|
||||
$default = public_path() . '/assets/profile-images/default-image';
|
||||
$handle = fopen($default, 'rb');
|
||||
$image = fread($handle, filesize($default));
|
||||
fclose($handle);
|
||||
}
|
||||
$path = public_path() . '/assets/profile-images/' . parse_url($home, PHP_URL_HOST) . '/image';
|
||||
$parts = explode('/', $path);
|
||||
$name = array_pop($parts);
|
||||
$dir = implode('/', $parts);
|
||||
if (! is_dir($dir)) {
|
||||
mkdir($dir, 0755, true);
|
||||
}
|
||||
file_put_contents("$dir/$name", $image);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -20,9 +20,10 @@ class SendWebMentions extends Job implements ShouldQueue
|
|||
* @param Note $note
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Note $note)
|
||||
public function __construct(Note $note, Client $guzzle = null)
|
||||
{
|
||||
$this->note = $note;
|
||||
$this->guzzle = $guzzle ?? new Client();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -31,16 +32,16 @@ class SendWebMentions extends Job implements ShouldQueue
|
|||
* @param \GuzzleHttp\Client $guzzle
|
||||
* @return void
|
||||
*/
|
||||
public function handle(Client $guzzle)
|
||||
public function handle()
|
||||
{
|
||||
//grab the URLs
|
||||
$urlsInReplyTo = explode(' ', $this->note->in_reply_to);
|
||||
$urlsNote = $this->getLinks($this->note->note);
|
||||
$urls = array_filter(array_merge($urlsInReplyTo, $urlsNote)); //filter out none URLs
|
||||
foreach ($urls as $url) {
|
||||
$endpoint = $this->discoverWebmentionEndpoint($url, $guzzle);
|
||||
$endpoint = $this->discoverWebmentionEndpoint($url, $this->guzzle);
|
||||
if ($endpoint) {
|
||||
$guzzle->post($endpoint, [
|
||||
$this->guzzle->post($endpoint, [
|
||||
'form_params' => [
|
||||
'source' => $this->note->longurl,
|
||||
'target' => $url,
|
||||
|
@ -73,8 +74,8 @@ class SendWebMentions extends Job implements ShouldQueue
|
|||
//check HTTP Headers for webmention endpoint
|
||||
$links = \GuzzleHttp\Psr7\parse_header($response->getHeader('Link'));
|
||||
foreach ($links as $link) {
|
||||
if ($link['rel'] == 'webmention') {
|
||||
return trim($link[0], '<>');
|
||||
if (mb_stristr($link['rel'], 'webmention')) {
|
||||
return $this->resolveUri($link[0], $url);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -89,11 +90,7 @@ class SendWebMentions extends Job implements ShouldQueue
|
|||
$endpoint = $rels[0]['http://webmention.org/'][0];
|
||||
}
|
||||
if ($endpoint) {
|
||||
if (filter_var($endpoint, FILTER_VALIDATE_URL)) {
|
||||
return $endpoint;
|
||||
}
|
||||
//it must be a relative url, so resolve with php-mf2
|
||||
return $mf2->resolveUrl($endpoint);
|
||||
return $this->resolveUri($endpoint, $url);
|
||||
}
|
||||
|
||||
return false;
|
||||
|
@ -105,7 +102,7 @@ class SendWebMentions extends Job implements ShouldQueue
|
|||
* @param string $html
|
||||
* @return array $urls
|
||||
*/
|
||||
private function getLinks($html)
|
||||
public function getLinks($html)
|
||||
{
|
||||
$urls = [];
|
||||
$dom = new \DOMDocument();
|
||||
|
@ -117,4 +114,24 @@ class SendWebMentions extends Job implements ShouldQueue
|
|||
|
||||
return $urls;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve a URI if necessary.
|
||||
*
|
||||
* @param string $url
|
||||
* @param string $base
|
||||
* @return string
|
||||
*/
|
||||
public function resolveUri(string $url, string $base): string
|
||||
{
|
||||
$endpoint = \GuzzleHttp\Psr7\uri_for($url);
|
||||
if ($endpoint->getScheme() !== null) {
|
||||
return (string) $endpoint;
|
||||
}
|
||||
|
||||
return (string) \GuzzleHttp\Psr7\Uri::resolve(
|
||||
\GuzzleHttp\Psr7\uri_for($base),
|
||||
$endpoint
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
|
|
@ -1 +0,0 @@
|
|||
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Contracts\Auth\Access\Gate as GateContract;
|
||||
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
|
||||
|
||||
class AuthServiceProvider extends ServiceProvider
|
||||
|
@ -19,12 +18,11 @@ class AuthServiceProvider extends ServiceProvider
|
|||
/**
|
||||
* Register any application authentication / authorization services.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Auth\Access\Gate $gate
|
||||
* @return void
|
||||
*/
|
||||
public function boot(GateContract $gate)
|
||||
public function boot()
|
||||
{
|
||||
$this->registerPolicies($gate);
|
||||
$this->registerPolicies();
|
||||
|
||||
//
|
||||
}
|
||||
|
|
26
app/Providers/BroadcastServiceProvider.php
Normal file
26
app/Providers/BroadcastServiceProvider.php
Normal file
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Illuminate\Support\Facades\Broadcast;
|
||||
|
||||
class BroadcastServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Bootstrap any application services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
Broadcast::routes();
|
||||
|
||||
/*
|
||||
* Authenticate the user's personal channel...
|
||||
*/
|
||||
Broadcast::channel('App.User.*', function ($user, $userId) {
|
||||
return (int) $user->id === (int) $userId;
|
||||
});
|
||||
}
|
||||
}
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Contracts\Events\Dispatcher as DispatcherContract;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
|
||||
|
||||
class EventServiceProvider extends ServiceProvider
|
||||
|
@ -21,12 +21,11 @@ class EventServiceProvider extends ServiceProvider
|
|||
/**
|
||||
* Register any other events for your application.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Events\Dispatcher $events
|
||||
* @return void
|
||||
*/
|
||||
public function boot(DispatcherContract $events)
|
||||
public function boot()
|
||||
{
|
||||
parent::boot($events);
|
||||
parent::boot();
|
||||
|
||||
//
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Routing\Router;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
|
||||
|
||||
class RouteServiceProvider extends ServiceProvider
|
||||
|
@ -22,22 +22,23 @@ class RouteServiceProvider extends ServiceProvider
|
|||
* @param \Illuminate\Routing\Router $router
|
||||
* @return void
|
||||
*/
|
||||
public function boot(Router $router)
|
||||
public function boot()
|
||||
{
|
||||
//
|
||||
|
||||
parent::boot($router);
|
||||
parent::boot();
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the routes for the application.
|
||||
*
|
||||
* @param \Illuminate\Routing\Router $router
|
||||
* @return void
|
||||
*/
|
||||
public function map(Router $router)
|
||||
public function map()
|
||||
{
|
||||
$this->mapWebRoutes($router);
|
||||
$this->mapWebRoutes();
|
||||
|
||||
$this->mapApiRoutes();
|
||||
|
||||
//
|
||||
}
|
||||
|
@ -47,15 +48,33 @@ class RouteServiceProvider extends ServiceProvider
|
|||
*
|
||||
* These routes all receive session state, CSRF protection, etc.
|
||||
*
|
||||
* @param \Illuminate\Routing\Router $router
|
||||
* @return void
|
||||
*/
|
||||
protected function mapWebRoutes(Router $router)
|
||||
protected function mapWebRoutes()
|
||||
{
|
||||
$router->group([
|
||||
'namespace' => $this->namespace, 'middleware' => 'web',
|
||||
Route::group([
|
||||
'middleware' => 'web',
|
||||
'namespace' => $this->namespace,
|
||||
], function ($router) {
|
||||
require app_path('Http/routes.php');
|
||||
require base_path('routes/web.php');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the "api" routes for the application.
|
||||
*
|
||||
* These routes are typically stateless.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function mapApiRoutes()
|
||||
{
|
||||
Route::group([
|
||||
'middleware' => 'api',
|
||||
'namespace' => $this->namespace,
|
||||
'prefix' => 'api',
|
||||
], function ($router) {
|
||||
require base_path('routes/api.php');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,10 +2,13 @@
|
|||
|
||||
namespace App;
|
||||
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
|
||||
class User extends Authenticatable
|
||||
{
|
||||
use Notifiable;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
|
|
|
@ -1,5 +1,12 @@
|
|||
# Changelog
|
||||
|
||||
## Version 0.0.9 (2016-09-06)
|
||||
- Adding jsonb column to store webmentions’ mf2.
|
||||
* As of L5.2 this needs a custom command to drop NOT NULL from content, L5.3 should allow a fix for this
|
||||
- Refactor receiving webmention code
|
||||
- Refactor sending webmention code to pass webmention.rocks
|
||||
- Update to use Laravel 5.3
|
||||
|
||||
## Version 0.0.8.5 (2016-07-18)
|
||||
- Set the size of the textarea in a form better
|
||||
- Update to latest Guzzle to fix CVE-2016-5385
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
{
|
||||
"name": "jonnybarnes/jonnybarnes.uk",
|
||||
"description": "The code for jonnybanres.uk, based on Laravel 5.2",
|
||||
"description": "The code for jonnybanres.uk, based on Laravel 5.3",
|
||||
"keywords": ["framework", "laravel", "indieweb"],
|
||||
"license": "CC0-1.0",
|
||||
"type": "project",
|
||||
"require": {
|
||||
"ext-intl": "*",
|
||||
"php": ">=7.0.0",
|
||||
"laravel/framework": "5.2.*",
|
||||
"laravel/framework": "5.3.*",
|
||||
"jonnybarnes/indieweb": "dev-master",
|
||||
"jonnybarnes/webmentions-parser": "dev-master",
|
||||
"guzzlehttp/guzzle": "~6.0",
|
||||
|
@ -27,8 +27,8 @@
|
|||
"fzaninotto/faker": "~1.4",
|
||||
"mockery/mockery": "0.9.*",
|
||||
"phpunit/phpunit": "~5.0",
|
||||
"symfony/css-selector": "2.8.*|3.0.*",
|
||||
"symfony/dom-crawler": "2.8.*|3.0.*",
|
||||
"symfony/css-selector": "3.1.*",
|
||||
"symfony/dom-crawler": "3.1.*",
|
||||
"barryvdh/laravel-debugbar": "~2.0",
|
||||
"filp/whoops": "~2.0"
|
||||
},
|
||||
|
|
920
composer.lock
generated
920
composer.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -2,6 +2,18 @@
|
|||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Application Name
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This value is the name of your application. This value is used when the
|
||||
| framework needs to place the application's name in a notification or
|
||||
| any other location as required by the application or its packages.
|
||||
*/
|
||||
|
||||
'name' => 'jonnybarnes.uk',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Application Environment
|
||||
|
@ -151,6 +163,7 @@ return [
|
|||
Illuminate\Foundation\Providers\FoundationServiceProvider::class,
|
||||
Illuminate\Hashing\HashServiceProvider::class,
|
||||
Illuminate\Mail\MailServiceProvider::class,
|
||||
Illuminate\Notifications\NotificationServiceProvider::class,
|
||||
Illuminate\Pagination\PaginationServiceProvider::class,
|
||||
Illuminate\Pipeline\PipelineServiceProvider::class,
|
||||
Illuminate\Queue\QueueServiceProvider::class,
|
||||
|
@ -166,6 +179,7 @@ return [
|
|||
*/
|
||||
App\Providers\AppServiceProvider::class,
|
||||
App\Providers\AuthServiceProvider::class,
|
||||
// App\Providers\BroadcastServiceProvider::class,
|
||||
App\Providers\EventServiceProvider::class,
|
||||
App\Providers\RouteServiceProvider::class,
|
||||
|
||||
|
@ -221,6 +235,7 @@ return [
|
|||
'Lang' => Illuminate\Support\Facades\Lang::class,
|
||||
'Log' => Illuminate\Support\Facades\Log::class,
|
||||
'Mail' => Illuminate\Support\Facades\Mail::class,
|
||||
'Notification' => Illuminate\Support\Facades\Notification::class,
|
||||
'Password' => Illuminate\Support\Facades\Password::class,
|
||||
'Queue' => Illuminate\Support\Facades\Queue::class,
|
||||
'Redirect' => Illuminate\Support\Facades\Redirect::class,
|
||||
|
|
|
@ -81,10 +81,6 @@ return [
|
|||
| Resetting Passwords
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may set the options for resetting passwords including the view
|
||||
| that is your password reset e-mail. You may also set the name of the
|
||||
| table that maintains all of the reset tokens for your application.
|
||||
|
|
||||
| You may specify multiple password reset configurations if you have more
|
||||
| than one user table or model in the application and you want to have
|
||||
| separate password reset settings based on the specific user types.
|
||||
|
@ -94,11 +90,9 @@ return [
|
|||
| they have less time to be guessed. You may change this as needed.
|
||||
|
|
||||
*/
|
||||
|
||||
'passwords' => [
|
||||
'users' => [
|
||||
'provider' => 'users',
|
||||
'email' => 'auth.emails.password',
|
||||
'table' => 'password_resets',
|
||||
'expire' => 60,
|
||||
],
|
||||
|
|
|
@ -11,11 +11,11 @@ return [
|
|||
| framework when an event needs to be broadcast. You may set this to
|
||||
| any of the connections defined in the "connections" array below.
|
||||
|
|
||||
| Supported: "pusher", "redis", "log"
|
||||
| Supported: "pusher", "redis", "log", "null"
|
||||
|
|
||||
*/
|
||||
|
||||
'default' => env('BROADCAST_DRIVER', 'pusher'),
|
||||
'default' => env('BROADCAST_DRIVER', 'null'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
|
@ -49,6 +49,10 @@ return [
|
|||
'driver' => 'log',
|
||||
],
|
||||
|
||||
'null' => [
|
||||
'driver' => 'null',
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
];
|
||||
|
|
|
@ -51,6 +51,14 @@ return [
|
|||
|
||||
'memcached' => [
|
||||
'driver' => 'memcached',
|
||||
'persistent_id' => env('MEMCACHED_PERSISTENT_ID'),
|
||||
'sasl' => [
|
||||
env('MEMCACHED_USERNAME'),
|
||||
env('MEMCACHED_PASSWORD'),
|
||||
],
|
||||
'options' => [
|
||||
// Memcached::OPT_CONNECT_TIMEOUT => 2000,
|
||||
],
|
||||
'servers' => [
|
||||
[
|
||||
'host' => env('MEMCACHED_HOST', '127.0.0.1'),
|
||||
|
|
|
@ -53,29 +53,30 @@ return [
|
|||
],
|
||||
|
||||
'mysql' => [
|
||||
'driver' => 'mysql',
|
||||
'host' => env('DB_HOST', 'localhost'),
|
||||
'port' => env('DB_PORT', '3306'),
|
||||
'database' => env('DB_DATABASE', 'forge'),
|
||||
'username' => env('DB_USERNAME', 'forge'),
|
||||
'password' => env('DB_PASSWORD', ''),
|
||||
'charset' => 'utf8mb4',
|
||||
'collation' => 'utf8mb4_unicode_ci',
|
||||
'prefix' => '',
|
||||
'strict' => false,
|
||||
'engine' => null,
|
||||
'driver' => 'mysql',
|
||||
'host' => env('DB_HOST', 'localhost'),
|
||||
'port' => env('DB_PORT', '3306'),
|
||||
'database' => env('DB_DATABASE', 'forge'),
|
||||
'username' => env('DB_USERNAME', 'forge'),
|
||||
'password' => env('DB_PASSWORD', ''),
|
||||
'charset' => 'utf8',
|
||||
'collation' => 'utf8_unicode_ci',
|
||||
'prefix' => '',
|
||||
'strict' => true,
|
||||
'engine' => null,
|
||||
],
|
||||
|
||||
'pgsql' => [
|
||||
'driver' => 'pgsql',
|
||||
'host' => env('DB_HOST', 'localhost'),
|
||||
'port' => env('DB_PORT', '5432'),
|
||||
'database' => env('DB_DATABASE', 'forge'),
|
||||
'username' => env('DB_USERNAME', 'forge'),
|
||||
'password' => env('DB_PASSWORD', ''),
|
||||
'charset' => 'utf8',
|
||||
'prefix' => '',
|
||||
'schema' => 'public',
|
||||
'driver' => 'pgsql',
|
||||
'host' => env('DB_HOST', 'localhost'),
|
||||
'port' => env('DB_PORT', '5432'),
|
||||
'database' => env('DB_DATABASE', 'forge'),
|
||||
'username' => env('DB_USERNAME', 'forge'),
|
||||
'password' => env('DB_PASSWORD', ''),
|
||||
'charset' => 'utf8',
|
||||
'prefix' => '',
|
||||
'schema' => 'public',
|
||||
'sslmode' => 'prefer',
|
||||
],
|
||||
|
||||
'travis' => [
|
||||
|
|
|
@ -54,8 +54,10 @@ return [
|
|||
| used globally for all e-mails that are sent by your application.
|
||||
|
|
||||
*/
|
||||
|
||||
'from' => ['address' => null, 'name' => null],
|
||||
'from' => [
|
||||
'address' => 'hello@example.com',
|
||||
'name' => 'Example',
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
|
@ -11,7 +11,7 @@ return [
|
|||
| API, giving you convenient access to each back-end using the same
|
||||
| syntax for each one. Here you may set the default queue driver.
|
||||
|
|
||||
| Supported: "null", "sync", "database", "beanstalkd", "sqs", "redis"
|
||||
| Supported: "sync", "database", "beanstalkd", "sqs", "redis", "null"
|
||||
|
|
||||
*/
|
||||
|
||||
|
@ -38,14 +38,14 @@ return [
|
|||
'driver' => 'database',
|
||||
'table' => 'jobs',
|
||||
'queue' => 'default',
|
||||
'expire' => 90,
|
||||
'retry_after' => 90,
|
||||
],
|
||||
|
||||
'beanstalkd' => [
|
||||
'driver' => 'beanstalkd',
|
||||
'host' => 'localhost',
|
||||
'queue' => 'default',
|
||||
'ttr' => 90,
|
||||
'retry_after' => 90,
|
||||
],
|
||||
|
||||
'sqs' => [
|
||||
|
@ -61,7 +61,7 @@ return [
|
|||
'driver' => 'redis',
|
||||
'connection' => 'default',
|
||||
'queue' => 'default',
|
||||
'expire' => 90,
|
||||
'retry_after' => 90,
|
||||
],
|
||||
|
||||
],
|
||||
|
|
|
@ -19,10 +19,6 @@ return [
|
|||
'secret' => env('MAILGUN_SECRET'),
|
||||
],
|
||||
|
||||
'mandrill' => [
|
||||
'secret' => env('MANDRILL_SECRET'),
|
||||
],
|
||||
|
||||
'ses' => [
|
||||
'key' => env('SES_KEY'),
|
||||
'secret' => env('SES_SECRET'),
|
||||
|
|
|
@ -44,7 +44,7 @@ return [
|
|||
|
|
||||
*/
|
||||
|
||||
'encrypt' => false,
|
||||
'encrypt' => true,
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
|
@ -7,5 +7,5 @@
|
|||
|
||||
return [
|
||||
'longurl' => env('APP_LONGURL', 'jonnybarnes.uk'),
|
||||
'shorturl' => env('APP_SHORTURL', 'jmb.so')
|
||||
];
|
||||
'shorturl' => env('APP_SHORTURL', 'jmb.lv')
|
||||
];
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class AddJsonbMf2ColumnToWebmentionsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('webmentions', function (Blueprint $table) {
|
||||
$table->jsonb('mf2')->nullable();
|
||||
$table->index(['mf2']);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('webmentions', function (Blueprint $table) {
|
||||
$table->dropIndex(['mf2']);
|
||||
$table->dropColumn('mf2');
|
||||
});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class AddExceptionColumnToFailedJobsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('failed_jobs', function (Blueprint $table) {
|
||||
$table->text('exception');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('failed_jobs', function (Blueprint $table) {
|
||||
$table->dropColumn('exception');
|
||||
});
|
||||
}
|
||||
}
|
|
@ -20,13 +20,13 @@
|
|||
</div>
|
||||
@if(count($likes) > 0)<h1 class="notes-subtitle">Likes</h1>@endif
|
||||
@foreach($likes as $like)
|
||||
<a href="{{ $like['url'] }}"><img src="{{ $like['photo'] }}" alt="" class="like-photo"></a>
|
||||
<a href="{{ $like['url'] }}"><img src="{{ $like['photo'] }}" alt="profile picture of {{ $like['name'] }}" class="like-photo"></a>
|
||||
@endforeach
|
||||
@if(count($reposts) > 0)<h1 class="notes-subtitle">Reposts</h1>@endif
|
||||
@foreach($reposts as $repost)
|
||||
<p><a class="h-card vcard mini-h-card p-author" href="{{ $repost['url'] }}">
|
||||
<img src="{{ $repost['photo'] }}" alt="profile picture of {{ $repost['name'] }}" class="photo u-photo logo"> <span class="fn">{{ $repost['name'] }}</span>
|
||||
</a> reposted this at <a href="{{ $repost['repost'] }}">{{ $repost['date'] }}</a>.</p>
|
||||
</a> reposted this at <a href="{{ $repost['source'] }}">{{ $repost['date'] }}</a>.</p>
|
||||
@endforeach
|
||||
@stop
|
||||
|
||||
|
|
18
routes/api.php
Normal file
18
routes/api.php
Normal file
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| API Routes
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here is where you can register API routes for your application. These
|
||||
| routes are loaded by the RouteServiceProvider within a group which
|
||||
| is assigned the "api" middleware group. Enjoy building your API!
|
||||
|
|
||||
*/
|
||||
|
||||
Route::get('/user', function (Request $request) {
|
||||
return $request->user();
|
||||
})->middleware('auth:api');
|
18
routes/console.php
Normal file
18
routes/console.php
Normal file
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Foundation\Inspiring;
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Console Routes
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This file is where you may define all of your Closure based console
|
||||
| commands. Each Closure is bound to a command instance allowing a
|
||||
| simple approach to interacting with each command's IO methods.
|
||||
|
|
||||
*/
|
||||
|
||||
Artisan::command('inspire', function () {
|
||||
$this->comment(Inspiring::quote());
|
||||
})->describe('Display an inspiring quote');
|
|
@ -2,12 +2,12 @@
|
|||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Application Routes
|
||||
| Web Routes
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here is where you can register all of the routes for an application.
|
||||
| It's a breeze. Simply tell Laravel the URIs it should respond to
|
||||
| and give it the controller to call when that URI is requested.
|
||||
| This file is where you may define all of the routes that are handled
|
||||
| by your application. Just tell Laravel the URIs it should respond
|
||||
| to using a Closure or controller method. Build something great!
|
||||
|
|
||||
*/
|
||||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace App\Tests;
|
||||
|
||||
use Cache;
|
||||
use TestCase;
|
||||
use Illuminate\Foundation\Testing\WithoutMiddleware;
|
||||
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
||||
|
@ -131,15 +132,15 @@ class NotesTest extends TestCase
|
|||
}
|
||||
|
||||
/**
|
||||
* Test the bridgy url shim method.
|
||||
* Test a correct profile link is formed from a generic URL.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testBridgy()
|
||||
public function testCreatePhotoLinkWithNonCachedImage()
|
||||
{
|
||||
$url = 'https://brid-gy.appspot.com/comment/twitter/jonnybarnes/497778866816299008/497781260937203712';
|
||||
$expected = 'https://twitter.com/_/status/497781260937203712';
|
||||
$this->assertEquals($expected, $this->notesController->bridgyReply($url));
|
||||
$homepage = 'https://example.org/profile.png';
|
||||
$expected = 'https://example.org/profile.png';
|
||||
$this->assertEquals($expected, $this->notesController->createPhotoLink($homepage));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -147,10 +148,10 @@ class NotesTest extends TestCase
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testCreatePhotoLinkWithGenericURL()
|
||||
public function testCreatePhotoLinkWithCachedImage()
|
||||
{
|
||||
$homepage = 'https://example.org';
|
||||
$expected = '/assets/profile-images/example.org/image';
|
||||
$homepage = 'https://aaronparecki.com/profile.png';
|
||||
$expected = '/assets/profile-images/aaronparecki.com/image';
|
||||
$this->assertEquals($expected, $this->notesController->createPhotoLink($homepage));
|
||||
}
|
||||
|
||||
|
@ -159,7 +160,7 @@ class NotesTest extends TestCase
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testCreatePhotoLinkWithTwitterProfileImageURL()
|
||||
public function testCreatePhotoLinkWithTwimgProfileImageURL()
|
||||
{
|
||||
$twitterProfileImage = 'http://pbs.twimg.com/1234';
|
||||
$expected = 'https://pbs.twimg.com/1234';
|
||||
|
@ -171,9 +172,11 @@ class NotesTest extends TestCase
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testCreatePhotoLinkWithTwitterURL()
|
||||
public function testCreatePhotoLinkWithCachedTwitterURL()
|
||||
{
|
||||
$twitterURL = 'https://twitter.com/example';
|
||||
$this->assertNull($this->notesController->createPhotoLink($twitterURL));
|
||||
$expected = 'https://pbs.twimg.com/static_profile_link.jpg';
|
||||
Cache::put($twitterURL, $expected, 1);
|
||||
$this->assertEquals($expected, $this->notesController->createPhotoLink($twitterURL));
|
||||
}
|
||||
}
|
||||
|
|
29
tests/ProcessWebMentionTest.php
Normal file
29
tests/ProcessWebMentionTest.php
Normal file
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
namespace App\Tests;
|
||||
|
||||
use TestCase;
|
||||
use Illuminate\Foundation\Testing\WithoutMiddleware;
|
||||
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
|
||||
class ProcessWebMentionTest extends TestCase
|
||||
{
|
||||
protected $appurl;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->appurl = config('app.url');
|
||||
}
|
||||
|
||||
/**
|
||||
* A basic test.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExample()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
92
tests/WebMentionsTest.php
Normal file
92
tests/WebMentionsTest.php
Normal file
|
@ -0,0 +1,92 @@
|
|||
<?php
|
||||
|
||||
namespace App\Tests;
|
||||
|
||||
use TestCase;
|
||||
use Illuminate\Foundation\Testing\WithoutMiddleware;
|
||||
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
|
||||
class WebMentionsTest extends TestCase
|
||||
{
|
||||
protected $appurl;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->appurl = config('app.url');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test webmentions without source and target are rejected.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testWebmentionsWithoutSourceAndTargetAreRejected()
|
||||
{
|
||||
$this->call('POST', $this->appurl . '/webmention', ['source' => 'https://example.org/post/123']);
|
||||
$this->assertResponseStatus(400)
|
||||
->see('You need both the target and source parameters');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test invalid target gets a 400 response.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testInvalidTargetReturns400Response()
|
||||
{
|
||||
$this->call('POST', $this->appurl . '/webmention', [
|
||||
'source' => 'https://example.org/post/123',
|
||||
'target' => $this->appurl . '/invalid/target'
|
||||
]);
|
||||
$this->assertResponseStatus(400)
|
||||
->see('Invalid request');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test blog target gets a 501 response.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testBlogpostTargetReturns501Response()
|
||||
{
|
||||
$this->call('POST', $this->appurl . '/webmention', [
|
||||
'source' => 'https://example.org/post/123',
|
||||
'target' => $this->appurl . '/blog/target'
|
||||
]);
|
||||
$this->assertResponseStatus(501)
|
||||
->see('I don’t accept webmentions for blog posts yet.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that a non-existant note gives a 400 response.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testNonexistantNoteReturns400Response()
|
||||
{
|
||||
$this->call('POST', $this->appurl . '/webmention', [
|
||||
'source' => 'https://example.org/post/123',
|
||||
'target' => $this->appurl . '/notes/ZZZZZ'
|
||||
]);
|
||||
$this->assertResponseStatus(400)
|
||||
->see('This note doesn’t exist.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test a legit webmention triggers the ProcessWebMention job.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testLegitimateWebmnetionTriggersProcessWebMentionJob()
|
||||
{
|
||||
$this->expectsJobs(\App\Jobs\ProcessWebMention::class);
|
||||
$this->call('POST', $this->appurl . '/webmention', [
|
||||
'source' => 'https://example.org/post/123',
|
||||
'target' => $this->appurl . '/notes/B'
|
||||
]);
|
||||
$this->assertResponseStatus(202)
|
||||
->see('Webmention received, it will be processed shortly');
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue