diff --git a/app/Http/Controllers/Admin/ContactsController.php b/app/Http/Controllers/Admin/ContactsController.php index c32aa610..44a86f88 100644 --- a/app/Http/Controllers/Admin/ContactsController.php +++ b/app/Http/Controllers/Admin/ContactsController.php @@ -7,6 +7,7 @@ namespace App\Http\Controllers\Admin; use GuzzleHttp\Client; use App\Models\Contact; use Illuminate\View\View; +use Illuminate\Support\Arr; use Illuminate\Http\Request; use App\Http\Controllers\Controller; use Illuminate\Filesystem\Filesystem; @@ -137,8 +138,8 @@ class ContactsController extends Controller } $mf2 = \Mf2\parse((string) $response->getBody(), $contact->homepage); foreach ($mf2['items'] as $microformat) { - if (array_get($microformat, 'type.0') == 'h-card') { - $avatarURL = array_get($microformat, 'properties.photo.0'); + if (Arr::get($microformat, 'type.0') == 'h-card') { + $avatarURL = Arr::get($microformat, 'properties.photo.0'); break; } } diff --git a/app/Jobs/ProcessLike.php b/app/Jobs/ProcessLike.php index 66ba32bf..e0394c87 100644 --- a/app/Jobs/ProcessLike.php +++ b/app/Jobs/ProcessLike.php @@ -6,6 +6,7 @@ namespace App\Jobs; use App\Models\Like; use GuzzleHttp\Client; +use Illuminate\Support\Arr; use Illuminate\Bus\Queueable; use Thujohn\Twitter\Facades\Twitter; use Illuminate\Queue\SerializesModels; @@ -69,15 +70,15 @@ class ProcessLike implements ShouldQueue $response = $client->request('GET', $this->like->url); $mf2 = \Mf2\parse((string) $response->getBody(), $this->like->url); - if (array_has($mf2, 'items.0.properties.content')) { + if (Arr::has($mf2, 'items.0.properties.content')) { $this->like->content = $mf2['items'][0]['properties']['content'][0]['html']; } try { $author = $authorship->findAuthor($mf2); if (is_array($author)) { - $this->like->author_name = array_get($author, 'properties.name.0'); - $this->like->author_url = array_get($author, 'properties.url.0'); + $this->like->author_name = Arr::get($author, 'properties.name.0'); + $this->like->author_url = Arr::get($author, 'properties.url.0'); } if (is_string($author) && $author !== '') { $this->like->author_name = $author; diff --git a/app/Jobs/SendWebMentions.php b/app/Jobs/SendWebMentions.php index e60946ff..bbbd6f5c 100644 --- a/app/Jobs/SendWebMentions.php +++ b/app/Jobs/SendWebMentions.php @@ -6,6 +6,7 @@ namespace App\Jobs; use App\Models\Note; use GuzzleHttp\Client; +use Illuminate\Support\Str; use Illuminate\Bus\Queueable; use Illuminate\Queue\SerializesModels; use Illuminate\Queue\InteractsWithQueue; @@ -66,7 +67,7 @@ class SendWebMentions implements ShouldQueue if (parse_url($url, PHP_URL_HOST) == config('app.longurl')) { return; } - if (starts_with($url, '/notes/tagged/')) { + if (Str::startsWith($url, '/notes/tagged/')) { return; } diff --git a/app/Models/Like.php b/app/Models/Like.php index e73f6829..f200816f 100644 --- a/app/Models/Like.php +++ b/app/Models/Like.php @@ -6,6 +6,7 @@ namespace App\Models; use Mf2; use App\Traits\FilterHtml; +use Illuminate\Support\Arr; use Illuminate\Database\Eloquent\Model; class Like extends Model @@ -48,7 +49,7 @@ class Like extends Model $mf2 = Mf2\parse($value, $this->url); - if (array_get($mf2, 'items.0.properties.content.0.html')) { + if (Arr::get($mf2, 'items.0.properties.content.0.html')) { return $this->filterHtml( $mf2['items'][0]['properties']['content'][0]['html'] ); diff --git a/app/Models/Media.php b/app/Models/Media.php index 4d25c74f..a564adb9 100644 --- a/app/Models/Media.php +++ b/app/Models/Media.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace App\Models; +use Illuminate\Support\Str; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; @@ -40,7 +41,7 @@ class Media extends Model */ public function getUrlAttribute(): string { - if (starts_with($this->path, 'https://')) { + if (Str::startsWith($this->path, 'https://')) { return $this->path; } diff --git a/app/Models/Place.php b/app/Models/Place.php index 05a75f2e..7b0ea0d8 100644 --- a/app/Models/Place.php +++ b/app/Models/Place.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace App\Models; +use Illuminate\Support\Str; use Illuminate\Support\Facades\DB; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Builder; @@ -171,10 +172,10 @@ class Place extends Model private function getType(string $url): string { $host = parse_url($url, PHP_URL_HOST); - if (ends_with($host, 'foursquare.com') === true) { + if (Str::endsWith($host, 'foursquare.com') === true) { return 'foursquare'; } - if (ends_with($host, 'openstreetmap.org') === true) { + if (Str::endsWith($host, 'openstreetmap.org') === true) { return 'osm'; } diff --git a/app/Observers/NoteObserver.php b/app/Observers/NoteObserver.php index d74d9e47..28867836 100644 --- a/app/Observers/NoteObserver.php +++ b/app/Observers/NoteObserver.php @@ -5,7 +5,7 @@ declare(strict_types=1); namespace App\Observers; use App\Models\{Note, Tag}; -use Illuminate\Support\Collection; +use Illuminate\Support\{Arr, Collection}; class NoteObserver { @@ -40,7 +40,7 @@ class NoteObserver */ public function updated(Note $note) { - $text = array_get($note->getAttributes(), 'note'); + $text = Arr::get($note->getAttributes(), 'note'); if ($text === null) { return; } diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 2e398e62..8c472721 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -3,6 +3,7 @@ namespace App\Providers; use App\Models\Note; +use Illuminate\Support\Str; use Illuminate\Http\Request; use App\Observers\NoteObserver; use Laravel\Dusk\DuskServiceProvider; @@ -21,7 +22,7 @@ class AppServiceProvider extends ServiceProvider // Request AS macro Request::macro('wantsActivityStream', function () { - return str_contains(mb_strtolower($this->header('Accept')), 'application/activity+json'); + return Str::contains(mb_strtolower($this->header('Accept')), 'application/activity+json'); }); // configure Intervention/Image diff --git a/app/Services/BookmarkService.php b/app/Services/BookmarkService.php index abadd633..1e565af7 100644 --- a/app/Services/BookmarkService.php +++ b/app/Services/BookmarkService.php @@ -9,6 +9,7 @@ use GuzzleHttp\Client; use Illuminate\Http\Request; use App\Jobs\ProcessBookmark; use App\Models\{Bookmark, Tag}; +use Illuminate\Support\{Arr, Str}; use Spatie\Browsershot\Browsershot; use App\Jobs\SyndicateBookmarkToTwitter; use GuzzleHttp\Exception\ClientException; @@ -24,18 +25,18 @@ class BookmarkService */ public function createBookmark(array $request): Bookmark { - if (array_get($request, 'properties.bookmark-of.0')) { + if (Arr::get($request, 'properties.bookmark-of.0')) { //micropub request - $url = normalize_url(array_get($request, 'properties.bookmark-of.0')); - $name = array_get($request, 'properties.name.0'); - $content = array_get($request, 'properties.content.0'); - $categories = array_get($request, 'properties.category'); + $url = normalize_url(Arr::get($request, 'properties.bookmark-of.0')); + $name = Arr::get($request, 'properties.name.0'); + $content = Arr::get($request, 'properties.content.0'); + $categories = Arr::get($request, 'properties.category'); } - if (array_get($request, 'bookmark-of')) { - $url = normalize_url(array_get($request, 'bookmark-of')); - $name = array_get($request, 'name'); - $content = array_get($request, 'content'); - $categories = array_get($request, 'category'); + if (Arr::get($request, 'bookmark-of')) { + $url = normalize_url(Arr::get($request, 'bookmark-of')); + $name = Arr::get($request, 'name'); + $content = Arr::get($request, 'content'); + $categories = Arr::get($request, 'category'); } $bookmark = Bookmark::create([ @@ -49,13 +50,13 @@ class BookmarkService $bookmark->tags()->save($tag); } - $targets = array_pluck(config('syndication.targets'), 'uid', 'service.name'); + $targets = Arr::pluck(config('syndication.targets'), 'uid', 'service.name'); $mpSyndicateTo = null; - if (array_get($request, 'mp-syndicate-to')) { - $mpSyndicateTo = array_get($request, 'mp-syndicate-to'); + if (Arr::get($request, 'mp-syndicate-to')) { + $mpSyndicateTo = Arr::get($request, 'mp-syndicate-to'); } - if (array_get($request, 'properties.mp-syndicate-to')) { - $mpSyndicateTo = array_get($request, 'properties.mp-syndicate-to'); + if (Arr::get($request, 'properties.mp-syndicate-to')) { + $mpSyndicateTo = Arr::get($request, 'properties.mp-syndicate-to'); } if (is_string($mpSyndicateTo)) { $service = array_search($mpSyndicateTo, $targets); @@ -114,7 +115,7 @@ class BookmarkService throw new InternetArchiveException; } if ($response->hasHeader('Content-Location')) { - if (starts_with(array_get($response->getHeader('Content-Location'), 0), '/web')) { + if (Str::startsWith(Arr::get($response->getHeader('Content-Location'), 0), '/web')) { return $response->getHeader('Content-Location')[0]; } } diff --git a/app/Services/LikeService.php b/app/Services/LikeService.php index fd43a37f..237e776c 100644 --- a/app/Services/LikeService.php +++ b/app/Services/LikeService.php @@ -6,6 +6,7 @@ namespace App\Services; use App\Models\Like; use App\Jobs\ProcessLike; +use Illuminate\Support\Arr; class LikeService { @@ -17,12 +18,12 @@ class LikeService */ public function createLike(array $request): Like { - if (array_get($request, 'properties.like-of.0')) { + if (Arr::get($request, 'properties.like-of.0')) { //micropub request - $url = normalize_url(array_get($request, 'properties.like-of.0')); + $url = normalize_url(Arr::get($request, 'properties.like-of.0')); } - if (array_get($request, 'like-of')) { - $url = normalize_url(array_get($request, 'like-of')); + if (Arr::get($request, 'like-of')) { + $url = normalize_url(Arr::get($request, 'like-of')); } $like = Like::create(['url' => $url]); diff --git a/app/Services/Micropub/HCardService.php b/app/Services/Micropub/HCardService.php index f3d1ff3c..c478d239 100644 --- a/app/Services/Micropub/HCardService.php +++ b/app/Services/Micropub/HCardService.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace App\Services\Micropub; +use Illuminate\Support\Arr; use App\Services\PlaceService; class HCardService @@ -17,16 +18,16 @@ class HCardService public function process(array $request): string { $data = []; - if (array_get($request, 'properties.name')) { - $data['name'] = array_get($request, 'properties.name'); - $data['description'] = array_get($request, 'properties.description'); - $data['geo'] = array_get($request, 'properties.geo'); + if (Arr::get($request, 'properties.name')) { + $data['name'] = Arr::get($request, 'properties.name'); + $data['description'] = Arr::get($request, 'properties.description'); + $data['geo'] = Arr::get($request, 'properties.geo'); } else { - $data['name'] = array_get($request, 'name'); - $data['description'] = array_get($request, 'description'); - $data['geo'] = array_get($request, 'geo'); - $data['latitude'] = array_get($request, 'latitude'); - $data['longitude'] = array_get($request, 'longitude'); + $data['name'] = Arr::get($request, 'name'); + $data['description'] = Arr::get($request, 'description'); + $data['geo'] = Arr::get($request, 'geo'); + $data['latitude'] = Arr::get($request, 'latitude'); + $data['longitude'] = Arr::get($request, 'longitude'); } $place = resolve(PlaceService::class)->createPlace($data); diff --git a/app/Services/Micropub/HEntryService.php b/app/Services/Micropub/HEntryService.php index edb054ab..8d4564b7 100644 --- a/app/Services/Micropub/HEntryService.php +++ b/app/Services/Micropub/HEntryService.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace App\Services\Micropub; +use Illuminate\Support\Arr; use App\Services\{BookmarkService, LikeService, NoteService}; class HEntryService @@ -17,13 +18,13 @@ class HEntryService */ public function process(array $request, ?string $client = null): ?string { - if (array_get($request, 'properties.like-of') || array_get($request, 'like-of')) { + if (Arr::get($request, 'properties.like-of') || Arr::get($request, 'like-of')) { $like = resolve(LikeService::class)->createLike($request); return $like->longurl; } - if (array_get($request, 'properties.bookmark-of') || array_get($request, 'bookmark-of')) { + if (Arr::get($request, 'properties.bookmark-of') || Arr::get($request, 'bookmark-of')) { $bookmark = resolve(BookmarkService::class)->createBookmark($request); return $bookmark->longurl; diff --git a/app/Services/Micropub/UpdateService.php b/app/Services/Micropub/UpdateService.php index b4f81085..f19c615b 100644 --- a/app/Services/Micropub/UpdateService.php +++ b/app/Services/Micropub/UpdateService.php @@ -5,6 +5,7 @@ declare(strict_types=1); namespace App\Services\Micropub; use App\Models\{Media, Note}; +use Illuminate\Support\{Arr, Str}; use Illuminate\Database\Eloquent\ModelNotFoundException; class UpdateService @@ -17,7 +18,7 @@ class UpdateService */ public function process(array $request) { - $urlPath = parse_url(array_get($request, 'url'), PHP_URL_PATH); + $urlPath = parse_url(Arr::get($request, 'url'), PHP_URL_PATH); //is it a note we are updating? if (mb_substr($urlPath, 1, 5) !== 'notes') { @@ -37,20 +38,20 @@ class UpdateService } //got the note, are we dealing with a “replace” request? - if (array_get($request, 'replace')) { - foreach (array_get($request, 'replace') as $property => $value) { + if (Arr::get($request, 'replace')) { + foreach (Arr::get($request, 'replace') as $property => $value) { if ($property == 'content') { $note->note = $value[0]; } if ($property == 'syndication') { foreach ($value as $syndicationURL) { - if (starts_with($syndicationURL, 'https://www.facebook.com')) { + if (Str::startsWith($syndicationURL, 'https://www.facebook.com')) { $note->facebook_url = $syndicationURL; } - if (starts_with($syndicationURL, 'https://www.swarmapp.com')) { + if (Str::startsWith($syndicationURL, 'https://www.swarmapp.com')) { $note->swarm_url = $syndicationURL; } - if (starts_with($syndicationURL, 'https://twitter.com')) { + if (Str::startsWith($syndicationURL, 'https://twitter.com')) { $note->tweet_id = basename(parse_url($syndicationURL, PHP_URL_PATH)); } } @@ -64,24 +65,24 @@ class UpdateService } //how about “add” - if (array_get($request, 'add')) { - foreach (array_get($request, 'add') as $property => $value) { + if (Arr::get($request, 'add')) { + foreach (Arr::get($request, 'add') as $property => $value) { if ($property == 'syndication') { foreach ($value as $syndicationURL) { - if (starts_with($syndicationURL, 'https://www.facebook.com')) { + if (Str::startsWith($syndicationURL, 'https://www.facebook.com')) { $note->facebook_url = $syndicationURL; } - if (starts_with($syndicationURL, 'https://www.swarmapp.com')) { + if (Str::startsWith($syndicationURL, 'https://www.swarmapp.com')) { $note->swarm_url = $syndicationURL; } - if (starts_with($syndicationURL, 'https://twitter.com')) { + if (Str::startsWith($syndicationURL, 'https://twitter.com')) { $note->tweet_id = basename(parse_url($syndicationURL, PHP_URL_PATH)); } } } if ($property == 'photo') { foreach ($value as $photoURL) { - if (starts_with($photoURL, 'https://')) { + if (Str::startsWith($photoURL, 'https://')) { $media = new Media(); $media->path = $photoURL; $media->type = 'image'; diff --git a/app/Services/NoteService.php b/app/Services/NoteService.php index fc589a75..c8f9b4ee 100644 --- a/app/Services/NoteService.php +++ b/app/Services/NoteService.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace App\Services; +use Illuminate\Support\{Arr, Str}; use App\Models\{Media, Note, Place}; use App\Jobs\{SendWebMentions, SyndicateNoteToTwitter}; @@ -65,14 +66,14 @@ class NoteService */ private function getContent(array $request): ?string { - if (array_get($request, 'properties.content.0.html')) { - return array_get($request, 'properties.content.0.html'); + if (Arr::get($request, 'properties.content.0.html')) { + return Arr::get($request, 'properties.content.0.html'); } - if (is_string(array_get($request, 'properties.content.0'))) { - return array_get($request, 'properties.content.0'); + if (is_string(Arr::get($request, 'properties.content.0'))) { + return Arr::get($request, 'properties.content.0'); } - return array_get($request, 'content'); + return Arr::get($request, 'content'); } /** @@ -83,11 +84,11 @@ class NoteService */ private function getInReplyTo(array $request): ?string { - if (array_get($request, 'properties.in-reply-to.0')) { - return array_get($request, 'properties.in-reply-to.0'); + if (Arr::get($request, 'properties.in-reply-to.0')) { + return Arr::get($request, 'properties.in-reply-to.0'); } - return array_get($request, 'in-reply-to'); + return Arr::get($request, 'in-reply-to'); } /** @@ -98,12 +99,12 @@ class NoteService */ private function getPublished(array $request): ?string { - if (array_get($request, 'properties.published.0')) { - return carbon(array_get($request, 'properties.published.0')) + if (Arr::get($request, 'properties.published.0')) { + return carbon(Arr::get($request, 'properties.published.0')) ->toDateTimeString(); } - if (array_get($request, 'published')) { - return carbon(array_get($request, 'published'))->toDateTimeString(); + if (Arr::get($request, 'published')) { + return carbon(Arr::get($request, 'published'))->toDateTimeString(); } return null; @@ -117,7 +118,7 @@ class NoteService */ private function getLocation(array $request): ?string { - $location = array_get($request, 'properties.location.0') ?? array_get($request, 'location'); + $location = Arr::get($request, 'properties.location.0') ?? Arr::get($request, 'location'); if (is_string($location) && substr($location, 0, 4) == 'geo:') { preg_match_all( '/([0-9\.\-]+)/', @@ -139,8 +140,8 @@ class NoteService */ private function getCheckin(array $request): ?Place { - $location = array_get($request, 'location'); - if (is_string($location) && starts_with($location, config('app.url'))) { + $location = Arr::get($request, 'location'); + if (is_string($location) && Str::startsWith($location, config('app.url'))) { return Place::where( 'slug', basename( @@ -151,10 +152,10 @@ class NoteService ) )->first(); } - if (array_get($request, 'checkin')) { + if (Arr::get($request, 'checkin')) { try { $place = resolve(PlaceService::class)->createPlaceFromCheckin( - array_get($request, 'checkin') + Arr::get($request, 'checkin') ); } catch (\InvalidArgumentException $e) { return null; @@ -162,7 +163,7 @@ class NoteService return $place; } - if (array_get($location, 'type.0') === 'h-card') { + if (Arr::get($location, 'type.0') === 'h-card') { try { $place = resolve(PlaceService::class)->createPlaceFromCheckin( $location @@ -185,8 +186,8 @@ class NoteService */ private function getSwarmUrl(array $request): ?string { - if (stristr(array_get($request, 'properties.syndication.0', ''), 'swarmapp')) { - return array_get($request, 'properties.syndication.0'); + if (stristr(Arr::get($request, 'properties.syndication.0', ''), 'swarmapp')) { + return Arr::get($request, 'properties.syndication.0'); } return null; @@ -201,8 +202,8 @@ class NoteService private function getSyndicationTargets(array $request): array { $syndication = []; - $targets = array_pluck(config('syndication.targets'), 'uid', 'service.name'); - $mpSyndicateTo = array_get($request, 'mp-syndicate-to') ?? array_get($request, 'properties.mp-syndicate-to'); + $targets = Arr::pluck(config('syndication.targets'), 'uid', 'service.name'); + $mpSyndicateTo = Arr::get($request, 'mp-syndicate-to') ?? Arr::get($request, 'properties.mp-syndicate-to'); if (is_string($mpSyndicateTo)) { $service = array_search($mpSyndicateTo, $targets); if ($service == 'Twitter') { @@ -230,12 +231,12 @@ class NoteService private function getMedia(array $request): array { $media = []; - $photos = array_get($request, 'photo') ?? array_get($request, 'properties.photo'); + $photos = Arr::get($request, 'photo') ?? Arr::get($request, 'properties.photo'); if (isset($photos)) { foreach ((array) $photos as $photo) { // check the media was uploaded to my endpoint, and use path - if (starts_with($photo, config('filesystems.disks.s3.url'))) { + if (Str::startsWith($photo, config('filesystems.disks.s3.url'))) { $path = substr($photo, strlen(config('filesystems.disks.s3.url'))); $media[] = Media::where('path', ltrim($path, '/'))->firstOrFail(); } else { @@ -259,8 +260,8 @@ class NoteService */ private function getInstagramUrl(array $request): ?string { - if (starts_with(array_get($request, 'properties.syndication.0'), 'https://www.instagram.com')) { - return array_get($request, 'properties.syndication.0'); + if (Str::startsWith(Arr::get($request, 'properties.syndication.0'), 'https://www.instagram.com')) { + return Arr::get($request, 'properties.syndication.0'); } return null; diff --git a/app/Services/PlaceService.php b/app/Services/PlaceService.php index f8a15de8..fb0972b9 100644 --- a/app/Services/PlaceService.php +++ b/app/Services/PlaceService.php @@ -5,6 +5,7 @@ declare(strict_types=1); namespace App\Services; use App\Models\Place; +use Illuminate\Support\Arr; use Phaza\LaravelPostgis\Geometries\Point; class PlaceService @@ -46,24 +47,24 @@ class PlaceService public function createPlaceFromCheckin(array $checkin): Place { //check if the place exists if from swarm - if (array_has($checkin, 'properties.url')) { - $place = Place::whereExternalURL(array_get($checkin, 'properties.url.0'))->get(); + if (Arr::has($checkin, 'properties.url')) { + $place = Place::whereExternalURL(Arr::get($checkin, 'properties.url.0'))->get(); if (count($place) === 1) { return $place->first(); } } - if (array_has($checkin, 'properties.name') === false) { + if (Arr::has($checkin, 'properties.name') === false) { throw new \InvalidArgumentException('Missing required name'); } - if (array_has($checkin, 'properties.latitude') === false) { + if (Arr::has($checkin, 'properties.latitude') === false) { throw new \InvalidArgumentException('Missing required longitude/latitude'); } $place = new Place(); - $place->name = array_get($checkin, 'properties.name.0'); - $place->external_urls = array_get($checkin, 'properties.url.0'); + $place->name = Arr::get($checkin, 'properties.name.0'); + $place->external_urls = Arr::get($checkin, 'properties.url.0'); $place->location = new Point( - (float) array_get($checkin, 'properties.latitude.0'), - (float) array_get($checkin, 'properties.longitude.0') + (float) Arr::get($checkin, 'properties.latitude.0'), + (float) Arr::get($checkin, 'properties.longitude.0') ); $place->save();