Fixing various phpcs issues
This commit is contained in:
parent
21c89f721c
commit
ef03d2209f
18 changed files with 148 additions and 90 deletions
|
@ -21,7 +21,7 @@ class Kernel extends ConsoleKernel
|
||||||
/**
|
/**
|
||||||
* Define the application's command schedule.
|
* Define the application's command schedule.
|
||||||
*
|
*
|
||||||
* @param \Illuminate\Console\Scheduling\Schedule $schedule
|
* @param Schedule $schedule
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
protected function schedule(Schedule $schedule)
|
protected function schedule(Schedule $schedule)
|
||||||
|
@ -37,7 +37,7 @@ class Kernel extends ConsoleKernel
|
||||||
*/
|
*/
|
||||||
protected function commands()
|
protected function commands()
|
||||||
{
|
{
|
||||||
$this->load(__DIR__.'/Commands');
|
$this->load(__DIR__ . '/Commands');
|
||||||
|
|
||||||
require base_path('routes/console.php');
|
require base_path('routes/console.php');
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,9 +14,9 @@ class ArticlesController extends Controller
|
||||||
/**
|
/**
|
||||||
* Show all articles (with pagination).
|
* Show all articles (with pagination).
|
||||||
*
|
*
|
||||||
* @param int $year
|
* @param int $year
|
||||||
* @param int $month
|
* @param int $month
|
||||||
* @return \Illuminate\View\View
|
* @return View
|
||||||
*/
|
*/
|
||||||
public function index(int $year = null, int $month = null): View
|
public function index(int $year = null, int $month = null): View
|
||||||
{
|
{
|
||||||
|
@ -31,10 +31,10 @@ class ArticlesController extends Controller
|
||||||
/**
|
/**
|
||||||
* Show a single article.
|
* Show a single article.
|
||||||
*
|
*
|
||||||
* @param int $year
|
* @param int $year
|
||||||
* @param int $month
|
* @param int $month
|
||||||
* @param string $slug
|
* @param string $slug
|
||||||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\View\View
|
* @return RedirectResponse|View
|
||||||
*/
|
*/
|
||||||
public function show(int $year, int $month, string $slug)
|
public function show(int $year, int $month, string $slug)
|
||||||
{
|
{
|
||||||
|
@ -43,7 +43,7 @@ class ArticlesController extends Controller
|
||||||
return redirect('/blog/'
|
return redirect('/blog/'
|
||||||
. $article->updated_at->year
|
. $article->updated_at->year
|
||||||
. '/' . $article->updated_at->format('m')
|
. '/' . $article->updated_at->format('m')
|
||||||
.'/' . $slug);
|
. '/' . $slug);
|
||||||
}
|
}
|
||||||
|
|
||||||
return view('articles.show', compact('article'));
|
return view('articles.show', compact('article'));
|
||||||
|
@ -53,8 +53,8 @@ class ArticlesController extends Controller
|
||||||
* We only have the ID, work out post title, year and month
|
* We only have the ID, work out post title, year and month
|
||||||
* and redirect to it.
|
* and redirect to it.
|
||||||
*
|
*
|
||||||
* @param int $idFromUrl
|
* @param int $idFromUrl
|
||||||
* @return \Illuminte\Http\RedirectResponse
|
* @return RedirectResponse
|
||||||
*/
|
*/
|
||||||
public function onlyIdInUrl(int $idFromUrl): RedirectResponse
|
public function onlyIdInUrl(int $idFromUrl): RedirectResponse
|
||||||
{
|
{
|
||||||
|
|
|
@ -9,5 +9,7 @@ use Illuminate\Routing\Controller as BaseController;
|
||||||
|
|
||||||
class Controller extends BaseController
|
class Controller extends BaseController
|
||||||
{
|
{
|
||||||
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
|
use AuthorizesRequests;
|
||||||
|
use DispatchesJobs;
|
||||||
|
use ValidatesRequests;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,8 +6,10 @@ namespace App\Http\Controllers;
|
||||||
|
|
||||||
use App\Models\Note;
|
use App\Models\Note;
|
||||||
use App\Services\ActivityStreamsService;
|
use App\Services\ActivityStreamsService;
|
||||||
|
use Illuminate\Contracts\View\Factory as ViewFactory;
|
||||||
|
use Illuminate\Http\JsonResponse;
|
||||||
use Illuminate\Http\RedirectResponse;
|
use Illuminate\Http\RedirectResponse;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Response;
|
||||||
use Illuminate\View\View;
|
use Illuminate\View\View;
|
||||||
use Jonnybarnes\IndieWeb\Numbers;
|
use Jonnybarnes\IndieWeb\Numbers;
|
||||||
|
|
||||||
|
@ -18,12 +20,12 @@ class NotesController extends Controller
|
||||||
/**
|
/**
|
||||||
* Show all the notes. This is also the homepage.
|
* Show all the notes. This is also the homepage.
|
||||||
*
|
*
|
||||||
* @return \Illuminate\View\View|\Illuminate\Http\JsonResponse
|
* @return ViewFactory|View|Response
|
||||||
*/
|
*/
|
||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
if (request()->wantsActivityStream()) {
|
if (request()->wantsActivityStream()) {
|
||||||
return (new ActivityStreamsService)->siteOwnerResponse();
|
return (new ActivityStreamsService())->siteOwnerResponse();
|
||||||
}
|
}
|
||||||
|
|
||||||
$notes = Note::latest()
|
$notes = Note::latest()
|
||||||
|
@ -38,15 +40,15 @@ class NotesController extends Controller
|
||||||
/**
|
/**
|
||||||
* Show a single note.
|
* Show a single note.
|
||||||
*
|
*
|
||||||
* @param string $urlId The id of the note
|
* @param string $urlId The id of the note
|
||||||
* @return \Illuminate\View\View|\Illuminate\Http\JsonResponse
|
* @return View|JsonResponse|Response
|
||||||
*/
|
*/
|
||||||
public function show(string $urlId)
|
public function show(string $urlId)
|
||||||
{
|
{
|
||||||
$note = Note::nb60($urlId)->with('webmentions')->firstOrFail();
|
$note = Note::nb60($urlId)->with('webmentions')->firstOrFail();
|
||||||
|
|
||||||
if (request()->wantsActivityStream()) {
|
if (request()->wantsActivityStream()) {
|
||||||
return (new ActivityStreamsService)->singleNoteResponse($note);
|
return (new ActivityStreamsService())->singleNoteResponse($note);
|
||||||
}
|
}
|
||||||
|
|
||||||
return view('notes.show', compact('note'));
|
return view('notes.show', compact('note'));
|
||||||
|
@ -55,8 +57,8 @@ class NotesController extends Controller
|
||||||
/**
|
/**
|
||||||
* Redirect /note/{decID} to /notes/{nb60id}.
|
* Redirect /note/{decID} to /notes/{nb60id}.
|
||||||
*
|
*
|
||||||
* @param int $decId The decimal id of the note
|
* @param int $decId The decimal id of the note
|
||||||
* @return \Illuminate\Http\RedirectResponse
|
* @return RedirectResponse
|
||||||
*/
|
*/
|
||||||
public function redirect(int $decId): RedirectResponse
|
public function redirect(int $decId): RedirectResponse
|
||||||
{
|
{
|
||||||
|
@ -66,8 +68,8 @@ class NotesController extends Controller
|
||||||
/**
|
/**
|
||||||
* Show all notes tagged with {tag}.
|
* Show all notes tagged with {tag}.
|
||||||
*
|
*
|
||||||
* @param string $tag
|
* @param string $tag
|
||||||
* @return \Illuminate\View\View
|
* @return View
|
||||||
*/
|
*/
|
||||||
public function tagged(string $tag): View
|
public function tagged(string $tag): View
|
||||||
{
|
{
|
||||||
|
|
|
@ -65,12 +65,12 @@ block-all-mixed-content; \
|
||||||
report-to csp-endpoint; \
|
report-to csp-endpoint; \
|
||||||
report-uri https://jonnybarnes.report-uri.io/r/default/csp/enforce;")
|
report-uri https://jonnybarnes.report-uri.io/r/default/csp/enforce;")
|
||||||
)->header(
|
)->header(
|
||||||
'Report-To',
|
'Report-To',
|
||||||
'{' .
|
'{' .
|
||||||
"'url': 'https://jonnybarnes.report-uri.io/r/default/csp/enforce', " .
|
"'url': 'https://jonnybarnes.report-uri.io/r/default/csp/enforce', " .
|
||||||
"'group': 'csp-endpoint'," .
|
"'group': 'csp-endpoint'," .
|
||||||
"'max-age': 10886400" .
|
"'max-age': 10886400" .
|
||||||
'}'
|
'}'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,14 +13,17 @@ use Illuminate\Queue\SerializesModels;
|
||||||
|
|
||||||
class AddClientToDatabase implements ShouldQueue
|
class AddClientToDatabase implements ShouldQueue
|
||||||
{
|
{
|
||||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
use Dispatchable;
|
||||||
|
use InteractsWithQueue;
|
||||||
|
use Queueable;
|
||||||
|
use SerializesModels;
|
||||||
|
|
||||||
protected $client_id;
|
protected $client_id;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new job instance.
|
* Create a new job instance.
|
||||||
*
|
*
|
||||||
* @param string $client_id
|
* @param string $client_id
|
||||||
*/
|
*/
|
||||||
public function __construct(string $client_id)
|
public function __construct(string $client_id)
|
||||||
{
|
{
|
||||||
|
@ -35,7 +38,7 @@ class AddClientToDatabase implements ShouldQueue
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
if (MicropubClient::where('client_url', $this->client_id)->count() == 0) {
|
if (MicropubClient::where('client_url', $this->client_id)->count() == 0) {
|
||||||
$client = MicropubClient::create([
|
MicropubClient::create([
|
||||||
'client_url' => $this->client_id,
|
'client_url' => $this->client_id,
|
||||||
'client_name' => $this->client_id, // default client name is the URL
|
'client_name' => $this->client_id, // default client name is the URL
|
||||||
]);
|
]);
|
||||||
|
|
|
@ -5,7 +5,9 @@ declare(strict_types=1);
|
||||||
namespace App\Jobs;
|
namespace App\Jobs;
|
||||||
|
|
||||||
use GuzzleHttp\Client;
|
use GuzzleHttp\Client;
|
||||||
|
use GuzzleHttp\Exception\GuzzleException;
|
||||||
use Illuminate\Bus\Queueable;
|
use Illuminate\Bus\Queueable;
|
||||||
|
use Illuminate\Contracts\Filesystem\FileNotFoundException;
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
use Illuminate\FileSystem\FileSystem;
|
use Illuminate\FileSystem\FileSystem;
|
||||||
use Illuminate\Queue\InteractsWithQueue;
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
|
@ -13,19 +15,21 @@ use Illuminate\Queue\SerializesModels;
|
||||||
|
|
||||||
class DownloadWebMention implements ShouldQueue
|
class DownloadWebMention implements ShouldQueue
|
||||||
{
|
{
|
||||||
use InteractsWithQueue, Queueable, SerializesModels;
|
use InteractsWithQueue;
|
||||||
|
use Queueable;
|
||||||
|
use SerializesModels;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The webmention source URL.
|
* The webmention source URL.
|
||||||
*
|
*
|
||||||
* @var
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $source;
|
protected $source;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new job instance.
|
* Create a new job instance.
|
||||||
*
|
*
|
||||||
* @param string $source
|
* @param string $source
|
||||||
*/
|
*/
|
||||||
public function __construct(string $source)
|
public function __construct(string $source)
|
||||||
{
|
{
|
||||||
|
@ -35,7 +39,9 @@ class DownloadWebMention implements ShouldQueue
|
||||||
/**
|
/**
|
||||||
* Execute the job.
|
* Execute the job.
|
||||||
*
|
*
|
||||||
* @param \GuzzleHttp\Client $guzzle
|
* @param Client $guzzle
|
||||||
|
* @throws GuzzleException
|
||||||
|
* @throws FileNotFoundException
|
||||||
*/
|
*/
|
||||||
public function handle(Client $guzzle)
|
public function handle(Client $guzzle)
|
||||||
{
|
{
|
||||||
|
@ -73,13 +79,12 @@ class DownloadWebMention implements ShouldQueue
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a file path from a URL. This is used when caching the HTML
|
* Create a file path from a URL. This is used when caching the HTML response.
|
||||||
* response.
|
|
||||||
*
|
*
|
||||||
* @param string The URL
|
* @param string $url
|
||||||
* @return string The path name
|
* @return string The path name
|
||||||
*/
|
*/
|
||||||
private function createFilenameFromURL($url)
|
private function createFilenameFromURL(string $url)
|
||||||
{
|
{
|
||||||
$filepath = str_replace(['https://', 'http://'], ['https/', 'http/'], $url);
|
$filepath = str_replace(['https://', 'http://'], ['https/', 'http/'], $url);
|
||||||
if (substr($filepath, -1) == '/') {
|
if (substr($filepath, -1) == '/') {
|
||||||
|
|
|
@ -15,14 +15,18 @@ use Illuminate\Queue\SerializesModels;
|
||||||
|
|
||||||
class ProcessBookmark implements ShouldQueue
|
class ProcessBookmark implements ShouldQueue
|
||||||
{
|
{
|
||||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
use Dispatchable;
|
||||||
|
use InteractsWithQueue;
|
||||||
|
use Queueable;
|
||||||
|
use SerializesModels;
|
||||||
|
|
||||||
|
/** @var Bookmark */
|
||||||
protected $bookmark;
|
protected $bookmark;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new job instance.
|
* Create a new job instance.
|
||||||
*
|
*
|
||||||
* @param \App\Models\Bookmark $bookmark
|
* @param Bookmark $bookmark
|
||||||
*/
|
*/
|
||||||
public function __construct(Bookmark $bookmark)
|
public function __construct(Bookmark $bookmark)
|
||||||
{
|
{
|
||||||
|
|
|
@ -15,14 +15,18 @@ use Intervention\Image\ImageManager;
|
||||||
|
|
||||||
class ProcessMedia implements ShouldQueue
|
class ProcessMedia implements ShouldQueue
|
||||||
{
|
{
|
||||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
use Dispatchable;
|
||||||
|
use InteractsWithQueue;
|
||||||
|
use Queueable;
|
||||||
|
use SerializesModels;
|
||||||
|
|
||||||
|
/** @var string */
|
||||||
protected $filename;
|
protected $filename;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new job instance.
|
* Create a new job instance.
|
||||||
*
|
*
|
||||||
* @param string $filename
|
* @param string $filename
|
||||||
*/
|
*/
|
||||||
public function __construct(string $filename)
|
public function __construct(string $filename)
|
||||||
{
|
{
|
||||||
|
@ -32,7 +36,7 @@ class ProcessMedia implements ShouldQueue
|
||||||
/**
|
/**
|
||||||
* Execute the job.
|
* Execute the job.
|
||||||
*
|
*
|
||||||
* @param \Intervention\Image\ImageManager $manager
|
* @param ImageManager $manager
|
||||||
*/
|
*/
|
||||||
public function handle(ImageManager $manager)
|
public function handle(ImageManager $manager)
|
||||||
{
|
{
|
||||||
|
@ -49,7 +53,7 @@ class ProcessMedia implements ShouldQueue
|
||||||
if ($image->width() > 1000) {
|
if ($image->width() > 1000) {
|
||||||
$filenameParts = explode('.', $this->filename);
|
$filenameParts = explode('.', $this->filename);
|
||||||
$extension = array_pop($filenameParts);
|
$extension = array_pop($filenameParts);
|
||||||
// the following acheives this data flow
|
// the following achieves this data flow
|
||||||
// foo.bar.png => ['foo', 'bar', 'png'] => ['foo', 'bar'] => foo.bar
|
// foo.bar.png => ['foo', 'bar', 'png'] => ['foo', 'bar'] => foo.bar
|
||||||
$basename = ltrim(array_reduce($filenameParts, function ($carry, $item) {
|
$basename = ltrim(array_reduce($filenameParts, function ($carry, $item) {
|
||||||
return $carry . '.' . $item;
|
return $carry . '.' . $item;
|
||||||
|
@ -57,7 +61,7 @@ class ProcessMedia implements ShouldQueue
|
||||||
$medium = $image->resize(1000, null, function ($constraint) {
|
$medium = $image->resize(1000, null, function ($constraint) {
|
||||||
$constraint->aspectRatio();
|
$constraint->aspectRatio();
|
||||||
});
|
});
|
||||||
Storage::disk('s3')->put('media/'. $basename . '-medium.' . $extension, (string) $medium->encode());
|
Storage::disk('s3')->put('media/' . $basename . '-medium.' . $extension, (string) $medium->encode());
|
||||||
$small = $image->resize(500, null, function ($constraint) {
|
$small = $image->resize(500, null, function ($constraint) {
|
||||||
$constraint->aspectRatio();
|
$constraint->aspectRatio();
|
||||||
});
|
});
|
||||||
|
|
|
@ -5,6 +5,8 @@ declare(strict_types=1);
|
||||||
namespace App\Jobs;
|
namespace App\Jobs;
|
||||||
|
|
||||||
use App\Exceptions\RemoteContentNotFoundException;
|
use App\Exceptions\RemoteContentNotFoundException;
|
||||||
|
use GuzzleHttp\Exception\GuzzleException;
|
||||||
|
use Jonnybarnes\WebmentionsParser\Exceptions\InvalidMentionException;
|
||||||
use App\Models\{Note, WebMention};
|
use App\Models\{Note, WebMention};
|
||||||
use GuzzleHttp\Client;
|
use GuzzleHttp\Client;
|
||||||
use GuzzleHttp\Exception\RequestException;
|
use GuzzleHttp\Exception\RequestException;
|
||||||
|
@ -16,18 +18,23 @@ use Mf2;
|
||||||
|
|
||||||
class ProcessWebMention implements ShouldQueue
|
class ProcessWebMention implements ShouldQueue
|
||||||
{
|
{
|
||||||
use InteractsWithQueue, Queueable, SerializesModels;
|
use InteractsWithQueue;
|
||||||
|
use Queueable;
|
||||||
|
use SerializesModels;
|
||||||
|
|
||||||
|
/** @var Note */
|
||||||
protected $note;
|
protected $note;
|
||||||
|
|
||||||
|
/** @var string */
|
||||||
protected $source;
|
protected $source;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new job instance.
|
* Create a new job instance.
|
||||||
*
|
*
|
||||||
* @param \App\Note $note
|
* @param Note $note
|
||||||
* @param string $source
|
* @param string $source
|
||||||
*/
|
*/
|
||||||
public function __construct(Note $note, $source)
|
public function __construct(Note $note, string $source)
|
||||||
{
|
{
|
||||||
$this->note = $note;
|
$this->note = $note;
|
||||||
$this->source = $source;
|
$this->source = $source;
|
||||||
|
@ -36,15 +43,18 @@ class ProcessWebMention implements ShouldQueue
|
||||||
/**
|
/**
|
||||||
* Execute the job.
|
* Execute the job.
|
||||||
*
|
*
|
||||||
* @param \Jonnybarnes\WebmentionsParser\Parser $parser
|
* @param Parser $parser
|
||||||
* @param \GuzzleHttp\Client $guzzle
|
* @param Client $guzzle
|
||||||
|
* @throws RemoteContentNotFoundException
|
||||||
|
* @throws GuzzleException
|
||||||
|
* @throws InvalidMentionException
|
||||||
*/
|
*/
|
||||||
public function handle(Parser $parser, Client $guzzle)
|
public function handle(Parser $parser, Client $guzzle)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$response = $guzzle->request('GET', $this->source);
|
$response = $guzzle->request('GET', $this->source);
|
||||||
} catch (RequestException $e) {
|
} catch (RequestException $e) {
|
||||||
throw new RemoteContentNotFoundException;
|
throw new RemoteContentNotFoundException();
|
||||||
}
|
}
|
||||||
$this->saveRemoteContent((string) $response->getBody(), $this->source);
|
$this->saveRemoteContent((string) $response->getBody(), $this->source);
|
||||||
$microformats = Mf2\parse((string) $response->getBody(), $this->source);
|
$microformats = Mf2\parse((string) $response->getBody(), $this->source);
|
||||||
|
@ -59,7 +69,7 @@ class ProcessWebMention implements ShouldQueue
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// webmenion is still a reply, so update content
|
// webmention is still a reply, so update content
|
||||||
dispatch(new SaveProfileImage($microformats));
|
dispatch(new SaveProfileImage($microformats));
|
||||||
$webmention->mf2 = json_encode($microformats);
|
$webmention->mf2 = json_encode($microformats);
|
||||||
$webmention->save();
|
$webmention->save();
|
||||||
|
@ -91,7 +101,7 @@ class ProcessWebMention implements ShouldQueue
|
||||||
$webmention->source = $this->source;
|
$webmention->source = $this->source;
|
||||||
$webmention->target = $this->note->longurl;
|
$webmention->target = $this->note->longurl;
|
||||||
$webmention->commentable_id = $this->note->id;
|
$webmention->commentable_id = $this->note->id;
|
||||||
$webmention->commentable_type = 'App\Note';
|
$webmention->commentable_type = 'App\Model\Note';
|
||||||
$webmention->type = $type;
|
$webmention->type = $type;
|
||||||
$webmention->mf2 = json_encode($microformats);
|
$webmention->mf2 = json_encode($microformats);
|
||||||
$webmention->save();
|
$webmention->save();
|
||||||
|
|
|
@ -15,14 +15,17 @@ use Jonnybarnes\WebmentionsParser\Exceptions\AuthorshipParserException;
|
||||||
|
|
||||||
class SaveProfileImage implements ShouldQueue
|
class SaveProfileImage implements ShouldQueue
|
||||||
{
|
{
|
||||||
use InteractsWithQueue, Queueable, SerializesModels;
|
use InteractsWithQueue;
|
||||||
|
use Queueable;
|
||||||
|
use SerializesModels;
|
||||||
|
|
||||||
|
/** @var array */
|
||||||
protected $microformats;
|
protected $microformats;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new job instance.
|
* Create a new job instance.
|
||||||
*
|
*
|
||||||
* @param array $microformats
|
* @param array $microformats
|
||||||
*/
|
*/
|
||||||
public function __construct(array $microformats)
|
public function __construct(array $microformats)
|
||||||
{
|
{
|
||||||
|
@ -32,7 +35,7 @@ class SaveProfileImage implements ShouldQueue
|
||||||
/**
|
/**
|
||||||
* Execute the job.
|
* Execute the job.
|
||||||
*
|
*
|
||||||
* @param \Jonnybarnes\WebmentionsParser\Authorship $authorship
|
* @param Authorship $authorship
|
||||||
*/
|
*/
|
||||||
public function handle(Authorship $authorship)
|
public function handle(Authorship $authorship)
|
||||||
{
|
{
|
||||||
|
@ -44,14 +47,16 @@ class SaveProfileImage implements ShouldQueue
|
||||||
$photo = $author['properties']['photo'][0];
|
$photo = $author['properties']['photo'][0];
|
||||||
$home = $author['properties']['url'][0];
|
$home = $author['properties']['url'][0];
|
||||||
//dont save pbs.twimg.com links
|
//dont save pbs.twimg.com links
|
||||||
if (parse_url($photo, PHP_URL_HOST) != 'pbs.twimg.com'
|
if (
|
||||||
&& parse_url($photo, PHP_URL_HOST) != 'twitter.com') {
|
parse_url($photo, PHP_URL_HOST) != 'pbs.twimg.com'
|
||||||
|
&& parse_url($photo, PHP_URL_HOST) != 'twitter.com'
|
||||||
|
) {
|
||||||
$client = resolve(Client::class);
|
$client = resolve(Client::class);
|
||||||
try {
|
try {
|
||||||
$response = $client->get($photo);
|
$response = $client->get($photo);
|
||||||
$image = $response->getBody(true);
|
$image = $response->getBody(true);
|
||||||
} catch (RequestException $e) {
|
} catch (RequestException $e) {
|
||||||
// we are openning and reading the default image so that
|
// we are opening and reading the default image so that
|
||||||
$default = public_path() . '/assets/profile-images/default-image';
|
$default = public_path() . '/assets/profile-images/default-image';
|
||||||
$handle = fopen($default, 'rb');
|
$handle = fopen($default, 'rb');
|
||||||
$image = fread($handle, filesize($default));
|
$image = fread($handle, filesize($default));
|
||||||
|
|
|
@ -6,22 +6,28 @@ namespace App\Jobs;
|
||||||
|
|
||||||
use App\Models\Note;
|
use App\Models\Note;
|
||||||
use GuzzleHttp\Client;
|
use GuzzleHttp\Client;
|
||||||
|
use GuzzleHttp\Psr7\Uri;
|
||||||
use Illuminate\Bus\Queueable;
|
use Illuminate\Bus\Queueable;
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
use Illuminate\Queue\InteractsWithQueue;
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
use Illuminate\Queue\SerializesModels;
|
use Illuminate\Queue\SerializesModels;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
|
use function GuzzleHttp\Psr7\uri_for;
|
||||||
|
|
||||||
class SendWebMentions implements ShouldQueue
|
class SendWebMentions implements ShouldQueue
|
||||||
{
|
{
|
||||||
use InteractsWithQueue, Queueable, SerializesModels;
|
use InteractsWithQueue;
|
||||||
|
use Queueable;
|
||||||
|
use SerializesModels;
|
||||||
|
|
||||||
|
/** @var Note */
|
||||||
protected $note;
|
protected $note;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create the job instance, inject dependencies.
|
* Create the job instance, inject dependencies.
|
||||||
*
|
*
|
||||||
* @param Note $note
|
* @param Note $note
|
||||||
*/
|
*/
|
||||||
public function __construct(Note $note)
|
public function __construct(Note $note)
|
||||||
{
|
{
|
||||||
|
@ -58,7 +64,7 @@ class SendWebMentions implements ShouldQueue
|
||||||
/**
|
/**
|
||||||
* Discover if a URL has a webmention endpoint.
|
* Discover if a URL has a webmention endpoint.
|
||||||
*
|
*
|
||||||
* @param string $url
|
* @param string $url
|
||||||
* @return string|null
|
* @return string|null
|
||||||
*/
|
*/
|
||||||
public function discoverWebmentionEndpoint(string $url)
|
public function discoverWebmentionEndpoint(string $url)
|
||||||
|
@ -101,14 +107,15 @@ class SendWebMentions implements ShouldQueue
|
||||||
/**
|
/**
|
||||||
* Get the URLs from a note.
|
* Get the URLs from a note.
|
||||||
*
|
*
|
||||||
* @param string $html
|
* @param string $html
|
||||||
* @return array $urls
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function getLinks($html)
|
public function getLinks(string $html): array
|
||||||
{
|
{
|
||||||
if ($html == '' || is_null($html)) {
|
if ($html == '' || is_null($html)) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
$urls = [];
|
$urls = [];
|
||||||
$dom = new \DOMDocument();
|
$dom = new \DOMDocument();
|
||||||
$dom->loadHTML($html);
|
$dom->loadHTML($html);
|
||||||
|
@ -123,19 +130,21 @@ class SendWebMentions implements ShouldQueue
|
||||||
/**
|
/**
|
||||||
* Resolve a URI if necessary.
|
* Resolve a URI if necessary.
|
||||||
*
|
*
|
||||||
* @param string $url
|
* @todo Update deprecated resolve method
|
||||||
* @param string $base The base of the URL
|
*
|
||||||
|
* @param string $url
|
||||||
|
* @param string $base The base of the URL
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function resolveUri(string $url, string $base): string
|
public function resolveUri(string $url, string $base): string
|
||||||
{
|
{
|
||||||
$endpoint = \GuzzleHttp\Psr7\uri_for($url);
|
$endpoint = uri_for($url);
|
||||||
if ($endpoint->getScheme() != '') {
|
if ($endpoint->getScheme() != '') {
|
||||||
return (string) $endpoint;
|
return (string) $endpoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (string) \GuzzleHttp\Psr7\Uri::resolve(
|
return (string) Uri::resolve(
|
||||||
\GuzzleHttp\Psr7\uri_for($base),
|
uri_for($base),
|
||||||
$endpoint
|
$endpoint
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ namespace App\Jobs;
|
||||||
|
|
||||||
use App\Models\Bookmark;
|
use App\Models\Bookmark;
|
||||||
use GuzzleHttp\Client;
|
use GuzzleHttp\Client;
|
||||||
|
use GuzzleHttp\Exception\GuzzleException;
|
||||||
use Illuminate\Bus\Queueable;
|
use Illuminate\Bus\Queueable;
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
use Illuminate\Foundation\Bus\Dispatchable;
|
use Illuminate\Foundation\Bus\Dispatchable;
|
||||||
|
@ -14,14 +15,18 @@ use Illuminate\Queue\SerializesModels;
|
||||||
|
|
||||||
class SyndicateBookmarkToTwitter implements ShouldQueue
|
class SyndicateBookmarkToTwitter implements ShouldQueue
|
||||||
{
|
{
|
||||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
use Dispatchable;
|
||||||
|
use InteractsWithQueue;
|
||||||
|
use Queueable;
|
||||||
|
use SerializesModels;
|
||||||
|
|
||||||
|
/** @var Bookmark */
|
||||||
protected $bookmark;
|
protected $bookmark;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new job instance.
|
* Create a new job instance.
|
||||||
*
|
*
|
||||||
* @param \App\Models\Bookmark $bookmark
|
* @param Bookmark $bookmark
|
||||||
*/
|
*/
|
||||||
public function __construct(Bookmark $bookmark)
|
public function __construct(Bookmark $bookmark)
|
||||||
{
|
{
|
||||||
|
@ -31,7 +36,8 @@ class SyndicateBookmarkToTwitter implements ShouldQueue
|
||||||
/**
|
/**
|
||||||
* Execute the job.
|
* Execute the job.
|
||||||
*
|
*
|
||||||
* @param \GuzzleHttp\Client $guzzle
|
* @param Client $guzzle
|
||||||
|
* @throws GuzzleException
|
||||||
*/
|
*/
|
||||||
public function handle(Client $guzzle)
|
public function handle(Client $guzzle)
|
||||||
{
|
{
|
||||||
|
|
|
@ -6,6 +6,7 @@ namespace App\Jobs;
|
||||||
|
|
||||||
use App\Models\Note;
|
use App\Models\Note;
|
||||||
use GuzzleHttp\Client;
|
use GuzzleHttp\Client;
|
||||||
|
use GuzzleHttp\Exception\GuzzleException;
|
||||||
use Illuminate\Bus\Queueable;
|
use Illuminate\Bus\Queueable;
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
use Illuminate\Queue\InteractsWithQueue;
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
|
@ -13,14 +14,17 @@ use Illuminate\Queue\SerializesModels;
|
||||||
|
|
||||||
class SyndicateNoteToTwitter implements ShouldQueue
|
class SyndicateNoteToTwitter implements ShouldQueue
|
||||||
{
|
{
|
||||||
use InteractsWithQueue, Queueable, SerializesModels;
|
use InteractsWithQueue;
|
||||||
|
use Queueable;
|
||||||
|
use SerializesModels;
|
||||||
|
|
||||||
|
/** @var Note */
|
||||||
protected $note;
|
protected $note;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new job instance.
|
* Create a new job instance.
|
||||||
*
|
*
|
||||||
* @param \App\Models\Note $note
|
* @param Note $note
|
||||||
*/
|
*/
|
||||||
public function __construct(Note $note)
|
public function __construct(Note $note)
|
||||||
{
|
{
|
||||||
|
@ -30,7 +34,8 @@ class SyndicateNoteToTwitter implements ShouldQueue
|
||||||
/**
|
/**
|
||||||
* Execute the job.
|
* Execute the job.
|
||||||
*
|
*
|
||||||
* @param \GuzzleHttp\Client $guzzle
|
* @param Client $guzzle
|
||||||
|
* @throws GuzzleException
|
||||||
*/
|
*/
|
||||||
public function handle(Client $guzzle)
|
public function handle(Client $guzzle)
|
||||||
{
|
{
|
||||||
|
|
|
@ -387,8 +387,10 @@ class Note extends Model
|
||||||
|
|
||||||
// here we check the matched contact from the note corresponds to a contact
|
// here we check the matched contact from the note corresponds to a contact
|
||||||
// in the database
|
// in the database
|
||||||
if (count(array_unique(array_values($this->contacts))) === 1
|
if (
|
||||||
&& array_unique(array_values($this->contacts))[0] === null) {
|
count(array_unique(array_values($this->contacts))) === 1
|
||||||
|
&& array_unique(array_values($this->contacts))[0] === null
|
||||||
|
) {
|
||||||
throw new TwitterContentException('The matched contact is not in the database');
|
throw new TwitterContentException('The matched contact is not in the database');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,18 +10,18 @@ use App\Jobs\SyndicateBookmarkToTwitter;
|
||||||
use App\Models\{Bookmark, Tag};
|
use App\Models\{Bookmark, Tag};
|
||||||
use GuzzleHttp\Client;
|
use GuzzleHttp\Client;
|
||||||
use GuzzleHttp\Exception\ClientException;
|
use GuzzleHttp\Exception\ClientException;
|
||||||
use Illuminate\Http\Request;
|
|
||||||
use Illuminate\Support\{Arr, Str};
|
use Illuminate\Support\{Arr, Str};
|
||||||
use Ramsey\Uuid\Uuid;
|
use Ramsey\Uuid\Uuid;
|
||||||
use Spatie\Browsershot\Browsershot;
|
use Spatie\Browsershot\Browsershot;
|
||||||
|
use Spatie\Browsershot\Exceptions\CouldNotTakeBrowsershot;
|
||||||
|
|
||||||
class BookmarkService
|
class BookmarkService
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Create a new Bookmark.
|
* Create a new Bookmark.
|
||||||
*
|
*
|
||||||
* @param array $request Data from request()->all()
|
* @param array $request Data from request()->all()
|
||||||
* @return Bookmark $bookmark
|
* @return Bookmark
|
||||||
*/
|
*/
|
||||||
public function createBookmark(array $request): Bookmark
|
public function createBookmark(array $request): Bookmark
|
||||||
{
|
{
|
||||||
|
@ -81,8 +81,9 @@ class BookmarkService
|
||||||
/**
|
/**
|
||||||
* Given a URL, use browsershot to save an image of the page.
|
* Given a URL, use browsershot to save an image of the page.
|
||||||
*
|
*
|
||||||
* @param string $url
|
* @param string $url
|
||||||
* @return string The uuid for the screenshot
|
* @return string The uuid for the screenshot
|
||||||
|
* @throws CouldNotTakeBrowsershot
|
||||||
*/
|
*/
|
||||||
public function saveScreenshot(string $url): string
|
public function saveScreenshot(string $url): string
|
||||||
{
|
{
|
||||||
|
@ -102,8 +103,9 @@ class BookmarkService
|
||||||
/**
|
/**
|
||||||
* Given a URL, attempt to save it to the Internet Archive.
|
* Given a URL, attempt to save it to the Internet Archive.
|
||||||
*
|
*
|
||||||
* @param string $url
|
* @param string $url
|
||||||
* @return string
|
* @return string
|
||||||
|
* @throws InternetArchiveException
|
||||||
*/
|
*/
|
||||||
public function getArchiveLink(string $url): string
|
public function getArchiveLink(string $url): string
|
||||||
{
|
{
|
||||||
|
@ -112,7 +114,7 @@ class BookmarkService
|
||||||
$response = $client->request('GET', 'https://web.archive.org/save/' . $url);
|
$response = $client->request('GET', 'https://web.archive.org/save/' . $url);
|
||||||
} catch (ClientException $e) {
|
} catch (ClientException $e) {
|
||||||
//throw an exception to be caught
|
//throw an exception to be caught
|
||||||
throw new InternetArchiveException;
|
throw new InternetArchiveException();
|
||||||
}
|
}
|
||||||
if ($response->hasHeader('Content-Location')) {
|
if ($response->hasHeader('Content-Location')) {
|
||||||
if (Str::startsWith(Arr::get($response->getHeader('Content-Location'), 0), '/web')) {
|
if (Str::startsWith(Arr::get($response->getHeader('Content-Location'), 0), '/web')) {
|
||||||
|
@ -121,6 +123,6 @@ class BookmarkService
|
||||||
}
|
}
|
||||||
|
|
||||||
//throw an exception to be caught
|
//throw an exception to be caught
|
||||||
throw new InternetArchiveException;
|
throw new InternetArchiveException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
"php": "^7.2",
|
"php": "^7.2",
|
||||||
"ext-intl": "*",
|
"ext-intl": "*",
|
||||||
"ext-json": "*",
|
"ext-json": "*",
|
||||||
|
"ext-dom": "*",
|
||||||
"cviebrock/eloquent-sluggable": "~6.0",
|
"cviebrock/eloquent-sluggable": "~6.0",
|
||||||
"fideloper/proxy": "~4.0",
|
"fideloper/proxy": "~4.0",
|
||||||
"guzzlehttp/guzzle": "~6.0",
|
"guzzlehttp/guzzle": "~6.0",
|
||||||
|
|
|
@ -2,7 +2,5 @@
|
||||||
<ruleset name="jonnybarnes.uk">
|
<ruleset name="jonnybarnes.uk">
|
||||||
<description>Custom configuration for code running jonnybarnes.uk</description>
|
<description>Custom configuration for code running jonnybarnes.uk</description>
|
||||||
<file>./app/</file>
|
<file>./app/</file>
|
||||||
<rule ref="PSR2">
|
<rule ref="PSR12" />
|
||||||
<exclude name="PSR2.Namespaces.UseDeclaration" />
|
|
||||||
</rule>
|
|
||||||
</ruleset>
|
</ruleset>
|
||||||
|
|
Loading…
Add table
Reference in a new issue