Update Laravel to v12
This commit is contained in:
parent
f2025b801b
commit
1dfa17abca
83 changed files with 1324 additions and 2323 deletions
|
@ -37,7 +37,7 @@ class ParseCachedWebMentions extends Command
|
|||
{
|
||||
$htmlFiles = $filesystem->allFiles(storage_path() . '/HTML');
|
||||
foreach ($htmlFiles as $file) {
|
||||
if ($file->getExtension() !== 'backup') { //we don’t want to parse `.backup` files
|
||||
if ($file->getExtension() !== 'backup') { // we don’t want to parse `.backup` files
|
||||
$filepath = $file->getPathname();
|
||||
$this->info('Loading HTML from: ' . $filepath);
|
||||
$html = $filesystem->get($filepath);
|
||||
|
|
|
@ -6,5 +6,5 @@ use Exception;
|
|||
|
||||
class RemoteContentNotFoundException extends Exception
|
||||
{
|
||||
//used when guzzle can’t find the remote content
|
||||
// used when guzzle can’t find the remote content
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ class ArticlesController extends Controller
|
|||
|
||||
public function store(): RedirectResponse
|
||||
{
|
||||
//if a `.md` is attached use that for the main content.
|
||||
// if a `.md` is attached use that for the main content.
|
||||
if (request()->hasFile('article')) {
|
||||
$file = request()->file('article')->openFile();
|
||||
$content = $file->fread($file->getSize());
|
||||
|
|
|
@ -67,7 +67,7 @@ class NotesController extends Controller
|
|||
*/
|
||||
public function update(int $noteId): RedirectResponse
|
||||
{
|
||||
//update note data
|
||||
// update note data
|
||||
$note = Note::findOrFail($noteId);
|
||||
$note->note = request()->input('content');
|
||||
$note->in_reply_to = request()->input('in-reply-to');
|
||||
|
|
|
@ -26,8 +26,8 @@ class IndieAuthController extends Controller
|
|||
'authorization_endpoint' => route('indieauth.start'),
|
||||
'token_endpoint' => route('indieauth.token'),
|
||||
'code_challenge_methods_supported' => ['S256'],
|
||||
//'introspection_endpoint' => route('indieauth.introspection'),
|
||||
//'introspection_endpoint_auth_methods_supported' => ['none'],
|
||||
// 'introspection_endpoint' => route('indieauth.introspection'),
|
||||
// 'introspection_endpoint_auth_methods_supported' => ['none'],
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
|
@ -191,7 +191,7 @@ class MicropubMediaController extends Controller
|
|||
*/
|
||||
private function getFileTypeFromMimeType(string $mimeType): string
|
||||
{
|
||||
//try known images
|
||||
// try known images
|
||||
$imageMimeTypes = [
|
||||
'image/gif',
|
||||
'image/jpeg',
|
||||
|
@ -203,7 +203,7 @@ class MicropubMediaController extends Controller
|
|||
if (in_array($mimeType, $imageMimeTypes)) {
|
||||
return 'image';
|
||||
}
|
||||
//try known video
|
||||
// try known video
|
||||
$videoMimeTypes = [
|
||||
'video/mp4',
|
||||
'video/mpeg',
|
||||
|
@ -214,7 +214,7 @@ class MicropubMediaController extends Controller
|
|||
if (in_array($mimeType, $videoMimeTypes)) {
|
||||
return 'video';
|
||||
}
|
||||
//try known audio types
|
||||
// try known audio types
|
||||
$audioMimeTypes = [
|
||||
'audio/midi',
|
||||
'audio/mpeg',
|
||||
|
|
|
@ -33,7 +33,7 @@ class WebMentionsController extends Controller
|
|||
*/
|
||||
public function receive(Request $request): Response
|
||||
{
|
||||
//first we trivially reject requests that lack all required inputs
|
||||
// first we trivially reject requests that lack all required inputs
|
||||
if (($request->has('target') !== true) || ($request->has('source') !== true)) {
|
||||
return response(
|
||||
'You need both the target and source parameters',
|
||||
|
@ -41,12 +41,12 @@ class WebMentionsController extends Controller
|
|||
);
|
||||
}
|
||||
|
||||
//next check the $target is valid
|
||||
// next check the $target is valid
|
||||
$path = parse_url($request->input('target'), PHP_URL_PATH);
|
||||
$pathParts = explode('/', $path);
|
||||
|
||||
if ($pathParts[1] === 'notes') {
|
||||
//we have a note
|
||||
// we have a note
|
||||
$noteId = $pathParts[2];
|
||||
try {
|
||||
$note = Note::findOrFail(resolve(Numbers::class)->b60tonum($noteId));
|
||||
|
|
|
@ -35,30 +35,30 @@ class DownloadWebMention implements ShouldQueue
|
|||
public function handle(Client $guzzle): void
|
||||
{
|
||||
$response = $guzzle->request('GET', $this->source);
|
||||
//4XX and 5XX responses should get Guzzle to throw an exception,
|
||||
//Laravel should catch and retry these automatically.
|
||||
// 4XX and 5XX responses should get Guzzle to throw an exception,
|
||||
// Laravel should catch and retry these automatically.
|
||||
if ($response->getStatusCode() === 200) {
|
||||
$filesystem = new FileSystem;
|
||||
$filename = storage_path('HTML') . '/' . $this->createFilenameFromURL($this->source);
|
||||
//backup file first
|
||||
// backup file first
|
||||
$filenameBackup = $filename . '.' . date('Y-m-d') . '.backup';
|
||||
if ($filesystem->exists($filename)) {
|
||||
$filesystem->copy($filename, $filenameBackup);
|
||||
}
|
||||
//check if base directory exists
|
||||
// check if base directory exists
|
||||
if (! $filesystem->exists($filesystem->dirname($filename))) {
|
||||
$filesystem->makeDirectory(
|
||||
$filesystem->dirname($filename),
|
||||
0755, //mode
|
||||
true //recursive
|
||||
0755, // mode
|
||||
true // recursive
|
||||
);
|
||||
}
|
||||
//save new HTML
|
||||
// save new HTML
|
||||
$filesystem->put(
|
||||
$filename,
|
||||
(string) $response->getBody()
|
||||
);
|
||||
//remove backup if the same
|
||||
// remove backup if the same
|
||||
if ($filesystem->exists($filenameBackup)) {
|
||||
if ($filesystem->get($filename) === $filesystem->get($filenameBackup)) {
|
||||
$filesystem->delete($filenameBackup);
|
||||
|
|
|
@ -49,7 +49,7 @@ class ProcessLike implements ShouldQueue
|
|||
$this->like->content = $tweet->html;
|
||||
$this->like->save();
|
||||
|
||||
//POSSE like
|
||||
// POSSE like
|
||||
try {
|
||||
$client->request(
|
||||
'POST',
|
||||
|
|
|
@ -32,18 +32,21 @@ class ProcessMedia implements ShouldQueue
|
|||
*/
|
||||
public function handle(ImageManager $manager): void
|
||||
{
|
||||
// Load file
|
||||
$file = Storage::disk('local')->get('media/' . $this->filename);
|
||||
|
||||
// Open file
|
||||
try {
|
||||
$image = $manager->read(storage_path('app/media/') . $this->filename);
|
||||
$image = $manager->read($file);
|
||||
} catch (DecoderException) {
|
||||
// not an image; delete file and end job
|
||||
unlink(storage_path('app/media/') . $this->filename);
|
||||
Storage::disk('local')->delete('media/' . $this->filename);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Save the file publicly
|
||||
Storage::disk('local')->copy('media/' . $this->filename, 'public/media/' . $this->filename);
|
||||
Storage::disk('public')->put('media/' . $this->filename, $file);
|
||||
|
||||
// Create smaller versions if necessary
|
||||
if ($image->width() > 1000) {
|
||||
|
@ -54,13 +57,13 @@ class ProcessMedia implements ShouldQueue
|
|||
$basename = trim(implode('.', $filenameParts), '.');
|
||||
|
||||
$medium = $image->resize(width: 1000);
|
||||
Storage::disk('local')->put('public/media/' . $basename . '-medium.' . $extension, (string) $medium->encode());
|
||||
Storage::disk('public')->put('media/' . $basename . '-medium.' . $extension, (string) $medium->encode());
|
||||
|
||||
$small = $image->resize(width: 500);
|
||||
Storage::disk('local')->put('public/media/' . $basename . '-small.' . $extension, (string) $small->encode());
|
||||
Storage::disk('public')->put('media/' . $basename . '-small.' . $extension, (string) $small->encode());
|
||||
}
|
||||
|
||||
// Now we can delete the locally saved image
|
||||
unlink(storage_path('app/media/') . $this->filename);
|
||||
Storage::disk('local')->delete('media/' . $this->filename);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,7 +49,7 @@ class SaveProfileImage implements ShouldQueue
|
|||
$home = array_shift($home);
|
||||
}
|
||||
|
||||
//dont save pbs.twimg.com links
|
||||
// dont save pbs.twimg.com links
|
||||
if (
|
||||
$photo
|
||||
&& parse_url($photo, PHP_URL_HOST) !== 'pbs.twimg.com'
|
||||
|
|
|
@ -72,7 +72,7 @@ class SendWebMentions implements ShouldQueue
|
|||
|
||||
$guzzle = resolve(Client::class);
|
||||
$response = $guzzle->get($url);
|
||||
//check HTTP Headers for webmention endpoint
|
||||
// check HTTP Headers for webmention endpoint
|
||||
$links = Header::parse($response->getHeader('Link'));
|
||||
foreach ($links as $link) {
|
||||
if (array_key_exists('rel', $link) && mb_stristr($link['rel'], 'webmention')) {
|
||||
|
@ -80,7 +80,7 @@ class SendWebMentions implements ShouldQueue
|
|||
}
|
||||
}
|
||||
|
||||
//failed to find a header so parse HTML
|
||||
// failed to find a header so parse HTML
|
||||
$html = (string) $response->getBody();
|
||||
|
||||
$mf2 = new \Mf2\Parser($html, $url);
|
||||
|
|
|
@ -111,7 +111,7 @@ class Note extends Model
|
|||
{
|
||||
if ($value !== null) {
|
||||
$normalized = normalizer_normalize($value, Normalizer::FORM_C);
|
||||
if ($normalized === '') { //we don’t want to save empty strings to the db
|
||||
if ($normalized === '') { // we don’t want to save empty strings to the db
|
||||
$normalized = null;
|
||||
}
|
||||
$this->attributes['note'] = $normalized;
|
||||
|
|
|
@ -59,7 +59,7 @@ class Place extends Model
|
|||
* sin(radians(places.latitude))))";
|
||||
|
||||
return $query
|
||||
->select() //pick the columns you want here.
|
||||
->select() // pick the columns you want here.
|
||||
->selectRaw("{$haversine} AS distance")
|
||||
->whereRaw("{$haversine} < ?", [$distance]);
|
||||
}
|
||||
|
|
|
@ -123,7 +123,7 @@ class WebMention extends Model
|
|||
$host = parse_url($url, PHP_URL_HOST);
|
||||
|
||||
if ($host === 'pbs.twimg.com') {
|
||||
//make sure we use HTTPS, we know twitter supports it
|
||||
// make sure we use HTTPS, we know twitter supports it
|
||||
return str_replace('http://', 'https://', $url);
|
||||
}
|
||||
|
||||
|
@ -135,7 +135,7 @@ class WebMention extends Model
|
|||
$codebird = resolve(Codebird::class);
|
||||
$info = $codebird->users_show(['screen_name' => $username]);
|
||||
$profile_image = $info->profile_image_url_https;
|
||||
Cache::put($url, $profile_image, 10080); //1 week
|
||||
Cache::put($url, $profile_image, 10080); // 1 week
|
||||
|
||||
return $profile_image;
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ class BookmarkService extends Service
|
|||
public function create(array $request, ?string $client = null): Bookmark
|
||||
{
|
||||
if (Arr::get($request, 'properties.bookmark-of.0')) {
|
||||
//micropub request
|
||||
// micropub request
|
||||
$url = normalize_url(Arr::get($request, 'properties.bookmark-of.0'));
|
||||
$name = Arr::get($request, 'properties.name.0');
|
||||
$content = Arr::get($request, 'properties.content.0');
|
||||
|
@ -61,7 +61,7 @@ class BookmarkService extends Service
|
|||
try {
|
||||
$response = $client->request('GET', 'https://web.archive.org/save/' . $url);
|
||||
} catch (ClientException $e) {
|
||||
//throw an exception to be caught
|
||||
// throw an exception to be caught
|
||||
throw new InternetArchiveException;
|
||||
}
|
||||
if ($response->hasHeader('Content-Location')) {
|
||||
|
@ -70,7 +70,7 @@ class BookmarkService extends Service
|
|||
}
|
||||
}
|
||||
|
||||
//throw an exception to be caught
|
||||
// throw an exception to be caught
|
||||
throw new InternetArchiveException;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ class LikeService extends Service
|
|||
public function create(array $request, ?string $client = null): Like
|
||||
{
|
||||
if (Arr::get($request, 'properties.like-of.0')) {
|
||||
//micropub request
|
||||
// micropub request
|
||||
$url = normalize_url(Arr::get($request, 'properties.like-of.0'));
|
||||
}
|
||||
if (Arr::get($request, 'like-of')) {
|
||||
|
|
|
@ -20,7 +20,7 @@ class UpdateService
|
|||
{
|
||||
$urlPath = parse_url(Arr::get($request, 'url'), PHP_URL_PATH);
|
||||
|
||||
//is it a note we are updating?
|
||||
// is it a note we are updating?
|
||||
if (mb_substr($urlPath, 1, 5) !== 'notes') {
|
||||
return response()->json([
|
||||
'error' => 'invalid',
|
||||
|
@ -37,7 +37,7 @@ class UpdateService
|
|||
], 404);
|
||||
}
|
||||
|
||||
//got the note, are we dealing with a “replace” request?
|
||||
// got the note, are we dealing with a “replace” request?
|
||||
if (Arr::get($request, 'replace')) {
|
||||
foreach (Arr::get($request, 'replace') as $property => $value) {
|
||||
if ($property === 'content') {
|
||||
|
@ -64,7 +64,7 @@ class UpdateService
|
|||
]);
|
||||
}
|
||||
|
||||
//how about “add”
|
||||
// how about “add”
|
||||
if (Arr::get($request, 'add')) {
|
||||
foreach (Arr::get($request, 'add') as $property => $value) {
|
||||
if ($property === 'syndication') {
|
||||
|
|
|
@ -14,8 +14,8 @@ class PlaceService
|
|||
*/
|
||||
public function createPlace(array $data): Place
|
||||
{
|
||||
//obviously a place needs a lat/lng, but this could be sent in a geo-url
|
||||
//if no geo array key, we assume the array already has lat/lng values
|
||||
// obviously a place needs a lat/lng, but this could be sent in a geo-url
|
||||
// if no geo array key, we assume the array already has lat/lng values
|
||||
if (array_key_exists('geo', $data) && $data['geo'] !== null) {
|
||||
preg_match_all(
|
||||
'/([0-9\.\-]+)/',
|
||||
|
@ -40,7 +40,7 @@ class PlaceService
|
|||
*/
|
||||
public function createPlaceFromCheckin(array $checkin): Place
|
||||
{
|
||||
//check if the place exists if from swarm
|
||||
// check if the place exists if from swarm
|
||||
if (Arr::has($checkin, 'properties.url')) {
|
||||
$place = Place::whereExternalURL(Arr::get($checkin, 'properties.url.0'))->get();
|
||||
if (count($place) === 1) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue