Remove deprecated global helper functions (issue #99)
Squashed commit of the following: commit 8ff29a8ab51ee5057ef786614ab95b005bf8918c Author: Jonny Barnes <jonny@jonnybarnes.uk> Date: Fri Feb 1 18:42:05 2019 +0000 Replace deprecated global helpers with their facade equivalents
This commit is contained in:
parent
7a4ba43b4d
commit
fb44afd7ad
15 changed files with 104 additions and 90 deletions
|
@ -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];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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]);
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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';
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue