2021-02-19 12:20:43 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2021-06-30 11:39:26 +02:00
|
|
|
use Illuminate\Support\Facades\Http;
|
2021-06-30 12:32:51 +02:00
|
|
|
use Illuminate\Support\Facades\App;
|
2021-02-19 12:20:43 +01:00
|
|
|
|
|
|
|
|
class Articles extends Model
|
|
|
|
|
{
|
2021-06-30 11:39:26 +02:00
|
|
|
protected $contentRender;
|
|
|
|
|
|
2021-02-19 12:20:43 +01:00
|
|
|
public function category()
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsTo(ArticlesCategories::class, 'category_id');
|
|
|
|
|
}
|
2021-06-30 11:39:26 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Mutator method to set priceHt's value
|
|
|
|
|
*/
|
|
|
|
|
public function setContentRenderAttribute($value)
|
|
|
|
|
{
|
|
|
|
|
$this->contentRender = $value;
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-21 15:24:32 +02:00
|
|
|
public function getContentRenderAttribute()
|
|
|
|
|
{
|
|
|
|
|
if (isset($this->contentRender)) {
|
2021-06-30 11:39:26 +02:00
|
|
|
return $this->contentRender;
|
|
|
|
|
} else {
|
2023-08-21 15:24:32 +02:00
|
|
|
// youtube
|
|
|
|
|
$content = preg_replace('/<oembed.+?url="https?:\/\/www\.youtube\.com\/watch\?v=([a-zA-Z0-9_-]{11})"><\/oembed>/', '<iframe width="560" height="315" src="https://www.youtube.com/embed/${1}" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>', $this->content);
|
|
|
|
|
// vimeo
|
|
|
|
|
$content = preg_replace('/<oembed.+?url="https?:\/\/vimeo\.com\/([a-zA-Z0-9_-]{9})"><\/oembed>/', '<iframe src="https://player.vimeo.com/video/${1}" width="640" height="480" frameborder="0" allow="autoplay; fullscreen; picture-in-picture" allowfullscreen></iframe>', $content);
|
|
|
|
|
// twitter
|
|
|
|
|
// tweet oembed
|
|
|
|
|
// match '/<figure class="media"><oembed.+?url="https?:\/\/twitter\.com\/([a-zA-Z0-9_-].*)\?.*"><\/oembed><\/figure>/'
|
|
|
|
|
// generate 'https://publish.twitter.com/oembed?url=https://twitter.com/${1}
|
2021-06-30 12:32:51 +02:00
|
|
|
if (!App::environment("local")) {
|
2023-08-21 15:24:32 +02:00
|
|
|
$tweets = preg_match_all('/<figure class="media"><oembed.+?url="https?:\/\/twitter\.com\/([a-zA-Z0-9\/_-]*)(?:\?[^"])*"><\/oembed><\/figure>/', $content, $tweet_urls);
|
2021-06-30 12:32:51 +02:00
|
|
|
foreach ($tweet_urls[1] as $onetweet) {
|
2023-08-21 15:24:32 +02:00
|
|
|
$oembed = 'https://publish.twitter.com/oembed?url=https://twitter.com/' . $onetweet;
|
|
|
|
|
$response = Http::get($oembed);
|
2021-06-30 12:32:51 +02:00
|
|
|
$html_for_tweet = $response->json()['html'];
|
2023-08-21 15:24:32 +02:00
|
|
|
$pattern = '/<figure class="media"><oembed.+?url="https?:\/\/twitter\.com\/' . preg_quote($onetweet, '/') . '(?:\?[^"])*"><\/oembed><\/figure>/';
|
|
|
|
|
$content = preg_replace($pattern, $html_for_tweet, $content);
|
2021-06-30 12:32:51 +02:00
|
|
|
}
|
|
|
|
|
} else {
|
2023-08-21 15:24:32 +02:00
|
|
|
$content = preg_replace('/<figure class="media"><oembed.+?url="https?:\/\/twitter\.com\/([a-zA-Z0-9\/_-]*)(?:\?[^"])*"><\/oembed><\/figure>/', '<a href="https://twitter.com/${1}" target="_twitter">BEHIND PROXY RENDER : Tweet</a>', $content);
|
2021-06-30 11:39:26 +02:00
|
|
|
}
|
|
|
|
|
|
2023-08-21 15:24:32 +02:00
|
|
|
// $this->contentRender = $content;
|
2021-06-30 11:39:26 +02:00
|
|
|
return $this->contentRender = $content;
|
2023-08-21 15:24:32 +02:00
|
|
|
}//end if
|
2021-06-30 11:39:26 +02:00
|
|
|
}
|
2021-02-19 12:20:43 +01:00
|
|
|
}
|