I love this plugin as it shows everything crisp unlike google docs embed. I was looking how to fix it and found that the problem is in pdf-viewer.php.
FILTER_VALIDATE_URL doesn’t work with protocol relative url. So I used following idea from someone on the internet:
public function validate($input)
{
$valid = filter_var($input, FILTER_VALIDATE_URL);
+ // Simple workaround for protocol relative urls.
+ // If sticking a protocol on the front makes it valid, assume it’s valid
+ if(!$valid)
+ $valid = filter_var(‘http:’.$input, FILTER_VALIDATE_URL);
return !!$valid;
}
Change the function add_shortcode() with following code (it’s works the same as the example above actually)
public function add_shortcode( $atts, $content = "" ) {
if ( !empty($content) && filter_var($content, FILTER_VALIDATE_URL) ) {
//TODO: filter URL to check if PDF only
if ( $this->older_ie($this->options['olderIE']) ) {
$notice = str_replace('%%PDF_URL%%', $content, $this->options['ta_notice']);
echo html_entity_decode($notice);
} else {
$atts = shortcode_atts(
array(
'width' => $this->options['tx_width'],
'height' => $this->options['tx_height'],
'beta' => empty($this->options['beta']) ? 0 : "true",
),
$atts,
'pdfviewer'
);
$pdfjs_mode = ( $atts['beta'] === "true" ) ? 'beta' : 'stable';
$pdfjs_url = plugin_dir_url( __FILE__ ).$pdfjs_mode.'/web/viewer.html?file='.$content;
$pdfjs_iframe = '<iframe class="pdfjs-viewer" width="'.$atts['width'].'" height="'.$atts['height'].'" src="'.$pdfjs_url.'"></iframe> ';
return $pdfjs_iframe;
}
} else {
if ( !empty($content) && filter_var('https:'.$content, FILTER_VALIDATE_URL) ) {
//TODO: filter URL to check if PDF only
if ( $this->older_ie($this->options['olderIE']) ) {
$notice = str_replace('%%PDF_URL%%', $content, $this->options['ta_notice']);
echo html_entity_decode($notice);
} else {
$atts = shortcode_atts(
array(
'width' => $this->options['tx_width'],
'height' => $this->options['tx_height'],
'beta' => empty($this->options['beta']) ? 0 : "true",
),
$atts,
'pdfviewer'
);
$pdfjs_mode = ( $atts['beta'] === "true" ) ? 'beta' : 'stable';
$pdfjs_url = plugin_dir_url( __FILE__ ).$pdfjs_mode.'/web/viewer.html?file='.$content;
$pdfjs_iframe = '<iframe class="pdfjs-viewer" width="'.$atts['width'].'" height="'.$atts['height'].'" src="'.$pdfjs_url.'"></iframe> ';
return $pdfjs_iframe;
}
} else {
if ( !empty($content) && filter_var('http:'.$content, FILTER_VALIDATE_URL) ) {
//TODO: filter URL to check if PDF only
if ( $this->older_ie($this->options['olderIE']) ) {
$notice = str_replace('%%PDF_URL%%', $content, $this->options['ta_notice']);
echo html_entity_decode($notice);
} else {
$atts = shortcode_atts(
array(
'width' => $this->options['tx_width'],
'height' => $this->options['tx_height'],
'beta' => empty($this->options['beta']) ? 0 : "true",
),
$atts,
'pdfviewer'
);
$pdfjs_mode = ( $atts['beta'] === "true" ) ? 'beta' : 'stable';
$pdfjs_url = plugin_dir_url( __FILE__ ).$pdfjs_mode.'/web/viewer.html?file='.$content;
$pdfjs_iframe = '<iframe class="pdfjs-viewer" width="'.$atts['width'].'" height="'.$atts['height'].'" src="'.$pdfjs_url.'"></iframe> ';
return $pdfjs_iframe;
}
} else {
return 'Invalid URL for PDF Viewer';
}
}
}
}
-
This reply was modified 7 years ago by chidoti.