Squashed commit of the following:
commit 63912e4c20fc9b3d49670a0f547137d59aaa2ef4 Author: Jonny Barnes <jonny@jonnybarnes.uk> Date: Fri Oct 12 19:18:21 2018 +0100 Remove facebook syndication code
This commit is contained in:
parent
7c559860dc
commit
151072cd1b
10 changed files with 1 additions and 314 deletions
|
@ -1,59 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use GuzzleHttp\Client;
|
||||
use App\Models\Bookmark;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
|
||||
class SyndicateBookmarkToFacebook implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
protected $bookmark;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @param \App\Models\Bookmark $bookmark
|
||||
*/
|
||||
public function __construct(Bookmark $bookmark)
|
||||
{
|
||||
$this->bookmark = $bookmark;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @param \GuzzleHttp\Client $guzzle
|
||||
*/
|
||||
public function handle(Client $guzzle)
|
||||
{
|
||||
//send webmention
|
||||
$response = $guzzle->request(
|
||||
'POST',
|
||||
'https://brid.gy/publish/webmention',
|
||||
[
|
||||
'form_params' => [
|
||||
'source' => $this->bookmark->longurl,
|
||||
'target' => 'https://brid.gy/publish/facebook',
|
||||
'bridgy_omit_link' => 'maybe',
|
||||
],
|
||||
]
|
||||
);
|
||||
//parse for syndication URL
|
||||
if ($response->getStatusCode() == 201) {
|
||||
$json = json_decode((string) $response->getBody());
|
||||
$syndicates = $this->bookmark->syndicates;
|
||||
$syndicates['facebook'] = $json->url;
|
||||
$this->bookmark->syndicates = $syndicates;
|
||||
$this->bookmark->save();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,56 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use App\Models\Note;
|
||||
use GuzzleHttp\Client;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
|
||||
class SyndicateNoteToFacebook implements ShouldQueue
|
||||
{
|
||||
use InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
protected $note;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @param \App\Models\Note $note
|
||||
*/
|
||||
public function __construct(Note $note)
|
||||
{
|
||||
$this->note = $note;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @param \GuzzleHttp\Client $guzzle
|
||||
*/
|
||||
public function handle(Client $guzzle)
|
||||
{
|
||||
//send webmention
|
||||
$response = $guzzle->request(
|
||||
'POST',
|
||||
'https://brid.gy/publish/webmention',
|
||||
[
|
||||
'form_params' => [
|
||||
'source' => $this->note->longurl,
|
||||
'target' => 'https://brid.gy/publish/facebook',
|
||||
'bridgy_omit_link' => 'maybe',
|
||||
],
|
||||
]
|
||||
);
|
||||
//parse for syndication URL
|
||||
if ($response->getStatusCode() == 201) {
|
||||
$json = json_decode((string) $response->getBody());
|
||||
$this->note->facebook_url = $json->url;
|
||||
$this->note->save();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -400,50 +400,6 @@ class Note extends Model
|
|||
return $this->convertMarkdown($swapped);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show a specific form of the note for Facebook.
|
||||
*
|
||||
* That is we swap the contacts names for their known Facebook usernames.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getFacebookContentAttribute(): ?string
|
||||
{
|
||||
if ($this->contacts === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (count($this->contacts) === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (count(array_unique(array_values($this->contacts))) === 1
|
||||
&& array_unique(array_values($this->contacts))[0] === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// swap in facebook usernames
|
||||
$swapped = preg_replace_callback(
|
||||
self::USERNAMES_REGEX,
|
||||
function ($matches) {
|
||||
if (is_null($this->contacts[$matches[1]])) {
|
||||
return $matches[0];
|
||||
}
|
||||
|
||||
$contact = $this->contacts[$matches[1]];
|
||||
if ($contact->facebook) {
|
||||
return '<a class="u-category h-card" href="https://facebook.com/'
|
||||
. $contact->facebook . '">' . $contact->name . '</a>';
|
||||
}
|
||||
|
||||
return $contact->name;
|
||||
},
|
||||
$this->getOriginal('note')
|
||||
);
|
||||
|
||||
return $this->convertMarkdown($swapped);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope a query to select a note via a NewBase60 id.
|
||||
*
|
||||
|
|
|
@ -11,7 +11,6 @@ use App\Jobs\ProcessBookmark;
|
|||
use App\Models\{Bookmark, Tag};
|
||||
use Spatie\Browsershot\Browsershot;
|
||||
use App\Jobs\SyndicateBookmarkToTwitter;
|
||||
use App\Jobs\SyndicateBookmarkToFacebook;
|
||||
use GuzzleHttp\Exception\ClientException;
|
||||
use App\Exceptions\InternetArchiveException;
|
||||
|
||||
|
@ -63,9 +62,6 @@ class BookmarkService
|
|||
if ($service == 'Twitter') {
|
||||
SyndicateBookmarkToTwitter::dispatch($bookmark);
|
||||
}
|
||||
if ($service == 'Facebook') {
|
||||
SyndicateBookmarkToFacebook::dispatch($bookmark);
|
||||
}
|
||||
}
|
||||
if (is_array($mpSyndicateTo)) {
|
||||
foreach ($mpSyndicateTo as $uid) {
|
||||
|
@ -73,9 +69,6 @@ class BookmarkService
|
|||
if ($service == 'Twitter') {
|
||||
SyndicateBookmarkToTwitter::dispatch($bookmark);
|
||||
}
|
||||
if ($service == 'Facebook') {
|
||||
SyndicateBookmarkToFacebook::dispatch($bookmark);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ declare(strict_types=1);
|
|||
namespace App\Services;
|
||||
|
||||
use App\Models\{Media, Note, Place};
|
||||
use App\Jobs\{SendWebMentions, SyndicateNoteToFacebook, SyndicateNoteToTwitter};
|
||||
use App\Jobs\{SendWebMentions, SyndicateNoteToTwitter};
|
||||
|
||||
class NoteService
|
||||
{
|
||||
|
@ -52,9 +52,6 @@ class NoteService
|
|||
if (in_array('twitter', $this->getSyndicationTargets($request))) {
|
||||
dispatch(new SyndicateNoteToTwitter($note));
|
||||
}
|
||||
if (in_array('facebook', $this->getSyndicationTargets($request))) {
|
||||
dispatch(new SyndicateNoteToFacebook($note));
|
||||
}
|
||||
}
|
||||
|
||||
return $note;
|
||||
|
@ -211,9 +208,6 @@ class NoteService
|
|||
if ($service == 'Twitter') {
|
||||
$syndication[] = 'twitter';
|
||||
}
|
||||
if ($service == 'Facebook') {
|
||||
$syndication[] = 'facebook';
|
||||
}
|
||||
}
|
||||
if (is_array($mpSyndicateTo)) {
|
||||
foreach ($mpSyndicateTo as $uid) {
|
||||
|
@ -221,9 +215,6 @@ class NoteService
|
|||
if ($service == 'Twitter') {
|
||||
$syndication[] = 'twitter';
|
||||
}
|
||||
if ($service == 'Facebook') {
|
||||
$syndication[] = 'facebook';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue