: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
namespace EmbedPress\Providers;
use Embera\Provider\ProviderAdapter;
use Embera\Provider\ProviderInterface;
(defined('ABSPATH') && defined('EMBEDPRESS_IS_LOADED')) or die("No direct script access allowed.");
* Entity responsible to support GoogleDocs embeds.
* @subpackage EmbedPress/Providers
* @author EmbedPress <help@embedpress.com>
* @copyright Copyright (C) 2023 WPDeveloper. All rights reserved.
* @license GPLv3 or later
class GoogleDocs extends ProviderAdapter implements ProviderInterface
* Method that verifies if the embed URL belongs to GoogleDocs.
public function validateUrl(Url $url)
return (bool) preg_match('~http[s]?:\/\/((?:www\.)?docs\.google\.com\/(?:.*/)?(?:document|presentation|spreadsheets|forms|drawings)\/[a-z0-9\/\?=_\-\.\,&%\$#\@\!\+]*)~i',
* This method fakes an Oembed response.
public function fakeResponse()
$iframeSrc = html_entity_decode($this->url);
// Check the type of document
preg_match('~google\.com/(?:.+/)?(document|presentation|spreadsheets|forms|drawings)/~i', $iframeSrc, $matches);
// Check if the url still doesn't have the embedded param, and add if needed
if ( ! preg_match('~([?&])embedded=true~i', $iframeSrc, $matches)) {
if (substr_count($iframeSrc, '?')) {
$iframeSrc .= '&embedded=true';
$iframeSrc .= '?embedded=true';
// Convert the /pub to /embed if needed
if (preg_match('~/pub\?~i', $iframeSrc)) {
$iframeSrc = str_replace('/pub?', '/embed?', $iframeSrc);
if (substr_count($iframeSrc, '?')) {
$query = explode('?', $iframeSrc);
$query = explode('&', $query);
$hasHeadersParam = false;
foreach ($query as $param) {
if (substr_count($param, 'widget=')) {
} elseif (substr_count($param, 'headers=')) {
if ( ! $hasWidgetParam) {
$iframeSrc .= '&widget=true';
if ( ! $hasHeadersParam) {
$iframeSrc .= '&headers=false';
$iframeSrc .= '?widget=true&headers=false';
$width = isset( $this->config['maxwidth']) ? $this->config['maxwidth']: 600;
$height = isset( $this->config['maxheight']) ? $this->config['maxheight']: 450;
if ($type !== 'drawings') {
$html = '<iframe src="' . esc_url($iframeSrc) . '" frameborder="0" width="'.$width.'" height="'.$height.'" allowfullscreen="true" mozallowfullscreen="true" webkitallowfullscreen="true"></iframe>';
$width = isset( $this->config['maxwidth']) ? $this->config['maxwidth']: 960;
$height = isset( $this->config['maxheight']) ? $this->config['maxheight']: 720;
$html = '<img src="' . esc_url($iframeSrc) . '" width="'.esc_attr($width).'" height="'.esc_attr($height).'" />';
'provider_name' => 'Google Docs',
'provider_url' => 'https://docs.google.com',
'title' => 'Unknown title',
'wrapper_class' => 'ose-google-docs-' . $type,
/** inline @inheritDoc */
public function modifyResponse( array $response = [])
return $this->fakeResponse();