Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/wp-conte.../plugins/embedpre.../EmbedPre.../Provider...
File: SelfHosted.php
<?php
[0] Fix | Delete
[1] Fix | Delete
namespace EmbedPress\Providers;
[2] Fix | Delete
[3] Fix | Delete
use Embera\Provider\ProviderAdapter;
[4] Fix | Delete
use Embera\Provider\ProviderInterface;
[5] Fix | Delete
use Embera\Url;
[6] Fix | Delete
[7] Fix | Delete
(defined('ABSPATH') && defined('EMBEDPRESS_IS_LOADED')) or die("No direct script access allowed.");
[8] Fix | Delete
[9] Fix | Delete
/**
[10] Fix | Delete
* Entity responsible to support SelfHosted embeds.
[11] Fix | Delete
*
[12] Fix | Delete
* @package EmbedPress
[13] Fix | Delete
* @subpackage EmbedPress/Providers
[14] Fix | Delete
* @author EmbedPress <help@embedpress.com>
[15] Fix | Delete
* @copyright Copyright (C) 2020 WPDeveloper. All rights reserved.
[16] Fix | Delete
* @license GPLv3 or later
[17] Fix | Delete
* @since 1.0.0
[18] Fix | Delete
*/
[19] Fix | Delete
[20] Fix | Delete
class SelfHosted extends ProviderAdapter implements ProviderInterface
[21] Fix | Delete
{
[22] Fix | Delete
[23] Fix | Delete
public function __construct($url, array $config = [])
[24] Fix | Delete
{
[25] Fix | Delete
parent::__construct($url, $config);
[26] Fix | Delete
$hosts_url = parse_url($url);
[27] Fix | Delete
$this->addHost($hosts_url['host']);
[28] Fix | Delete
}
[29] Fix | Delete
[30] Fix | Delete
/** inline {@inheritdoc} */
[31] Fix | Delete
[32] Fix | Delete
[33] Fix | Delete
/**
[34] Fix | Delete
* Method that verifies if the embed URL belongs to SelfHosted.
[35] Fix | Delete
*
[36] Fix | Delete
* @param Url $url
[37] Fix | Delete
* @return boolean
[38] Fix | Delete
* @since 1.0.0
[39] Fix | Delete
*
[40] Fix | Delete
*/
[41] Fix | Delete
public function validateUrl(Url $url)
[42] Fix | Delete
{
[43] Fix | Delete
return (bool) preg_match(
[44] Fix | Delete
'/^(https?:\/\/)?(www\.)?[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$/i',
[45] Fix | Delete
(string) $url
[46] Fix | Delete
);
[47] Fix | Delete
}
[48] Fix | Delete
[49] Fix | Delete
public function validateSelfHostedVideo($url)
[50] Fix | Delete
{
[51] Fix | Delete
return (bool) preg_match(
[52] Fix | Delete
'/\.(mp4|mov|avi|wmv|flv|mkv|webm|mpeg|mpg)$/i',
[53] Fix | Delete
(string) $url
[54] Fix | Delete
);
[55] Fix | Delete
}
[56] Fix | Delete
public function validateSelfHostedAudio($url)
[57] Fix | Delete
{
[58] Fix | Delete
return (bool) preg_match(
[59] Fix | Delete
'/\.(mp3|wav|ogg|aac)$/i',
[60] Fix | Delete
(string) $url
[61] Fix | Delete
);
[62] Fix | Delete
}
[63] Fix | Delete
[64] Fix | Delete
public function validateWrapper($url)
[65] Fix | Delete
{
[66] Fix | Delete
return (bool) preg_match(
[67] Fix | Delete
'/^(https?:\/\/)?(www\.)?[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$/i',
[68] Fix | Delete
(string) $url
[69] Fix | Delete
);
[70] Fix | Delete
}
[71] Fix | Delete
[72] Fix | Delete
public function fileExtention($fileUrl)
[73] Fix | Delete
{
[74] Fix | Delete
$pathInfo = pathinfo($fileUrl);
[75] Fix | Delete
[76] Fix | Delete
if (isset($pathInfo['extension'])) {
[77] Fix | Delete
$fileExtension = $pathInfo['extension'];
[78] Fix | Delete
return $fileExtension;
[79] Fix | Delete
}
[80] Fix | Delete
}
[81] Fix | Delete
[82] Fix | Delete
[83] Fix | Delete
[84] Fix | Delete
/**
[85] Fix | Delete
* This method fakes an Oembed response.
[86] Fix | Delete
*
[87] Fix | Delete
* @since 1.0.0
[88] Fix | Delete
*
[89] Fix | Delete
* @return array
[90] Fix | Delete
*/
[91] Fix | Delete
public function fakeResponse()
[92] Fix | Delete
{
[93] Fix | Delete
$src_url = urldecode($this->url);
[94] Fix | Delete
$provider_name = 'Self Hosterd';
[95] Fix | Delete
[96] Fix | Delete
$width = isset($this->config['maxwidth']) ? $this->config['maxwidth'] : 600;
[97] Fix | Delete
$height = isset($this->config['maxheight']) ? $this->config['maxheight'] : 450;
[98] Fix | Delete
[99] Fix | Delete
// Check if the url is already converted to the embed format
[100] Fix | Delete
if ($this->fileExtention($src_url) === 'ppsx' || $this->fileExtention($src_url) === 'pptx' || $this->fileExtention($src_url) === 'ppt' || $this->fileExtention($src_url) === 'xlsx' || $this->fileExtention($src_url) === 'xls' || $this->fileExtention($src_url) === 'doc' || $this->fileExtention($src_url) === 'docx') {
[101] Fix | Delete
$src_url = '//view.officeapps.live.com/op/embed.aspx?src=' . $this->url;
[102] Fix | Delete
}
[103] Fix | Delete
[104] Fix | Delete
// Check if the url is already converted to the embed format
[105] Fix | Delete
$html = '';
[106] Fix | Delete
if ($this->validateSelfHostedVideo($this->url)) {
[107] Fix | Delete
[108] Fix | Delete
$html = '<video controls width="' . esc_attr($width) . '" height="' . esc_attr($height) . '"> <source src="' . esc_url($this->url) . '" > </video>';
[109] Fix | Delete
} else if ($this->validateSelfHostedAudio($this->url)) {
[110] Fix | Delete
$html = '<audio controls> <source src="' . esc_url($this->url) . '" ></audio>';
[111] Fix | Delete
} else if ($this->validateWrapper($this->url)) {
[112] Fix | Delete
$provider_name = 'Wrapper';
[113] Fix | Delete
[114] Fix | Delete
$html = '<iframe width="' . esc_attr($width) . '" height="' . esc_attr($height) . '" src="' . esc_url($src_url) . '" > </iframe>';
[115] Fix | Delete
} else {
[116] Fix | Delete
return [];
[117] Fix | Delete
}
[118] Fix | Delete
[119] Fix | Delete
return [
[120] Fix | Delete
'type' => 'rich',
[121] Fix | Delete
'provider_name' => $provider_name,
[122] Fix | Delete
'provider_url' => site_url(),
[123] Fix | Delete
'title' => 'Unknown title',
[124] Fix | Delete
'html' => $html,
[125] Fix | Delete
];
[126] Fix | Delete
}
[127] Fix | Delete
/** inline @inheritDoc */
[128] Fix | Delete
public function modifyResponse(array $response = [])
[129] Fix | Delete
{
[130] Fix | Delete
return $this->fakeResponse();
[131] Fix | Delete
}
[132] Fix | Delete
}
[133] Fix | Delete
[134] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function