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
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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']
|
||||
);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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';
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
Reference in a new issue