plugin update (wp-media-folder)
This commit is contained in:
@@ -201,22 +201,29 @@ class WpmfPdfEmbed
|
||||
$width = (!empty($attrs['width']) && strpos($attrs['width'], '%') === false) ? $attrs['width'] : '100%';
|
||||
$height = (!empty($attrs['height']) && strpos($attrs['height'], '%') === false) ? $attrs['height'] : '800';
|
||||
$download = (!empty($attrs['download'])) ? $attrs['download'] : 'off';
|
||||
$plugin_dir_url = plugin_dir_url(__DIR__);
|
||||
$viewer_base_url = $plugin_dir_url . 'class/templates/pdf-embed.php';
|
||||
|
||||
$response = wp_remote_head($url);
|
||||
if (is_wp_error($response)) {
|
||||
$url = $plugin_dir_url . 'assets/pdf-loading-error.pdf';
|
||||
}
|
||||
|
||||
$status_code = wp_remote_retrieve_response_code($response);
|
||||
if ($status_code === 404) {
|
||||
$url = $plugin_dir_url . 'assets/pdf-loading-error.pdf';
|
||||
}
|
||||
$wpmf_pdf_embed_old = apply_filters('wpmf_pdf_embed_old', false);
|
||||
if ($wpmf_pdf_embed_old) {
|
||||
$width = (!empty($attrs['width']) && strpos($attrs['width'], '%') === false) ? $attrs['width'] : '';
|
||||
$return = '<a class="wpmf-pdfemb-viewer" data-download="'. $download .'" data-width="'. (int)$width .'" data-height="'. ((int)$height - 31) .'" href="'.esc_url($url).'">'.esc_html($title).'</a>';
|
||||
} else {
|
||||
$plugin_dir_url = plugin_dir_url(__DIR__);
|
||||
$viewer_base_url = $plugin_dir_url . 'class/templates/pdf-embed.php';
|
||||
|
||||
$attachment_info = '?file=' . urlencode($url);
|
||||
$final_url = $viewer_base_url . $attachment_info . '&plugins_url=' . urlencode($plugin_dir_url);
|
||||
$return = '<div><iframe width="' . esc_attr($width) . '" height="' . esc_attr($height) . '" src="' . esc_url($final_url) . '" title="Embedded PDF" class="wpmf-pdfjs-iframe"></iframe></div>';
|
||||
$response = wp_remote_head($url);
|
||||
if (is_wp_error($response)) {
|
||||
$url = $plugin_dir_url . 'assets/pdf-loading-error.pdf';
|
||||
}
|
||||
|
||||
$status_code = wp_remote_retrieve_response_code($response);
|
||||
if ($status_code === 404) {
|
||||
$url = $plugin_dir_url . 'assets/pdf-loading-error.pdf';
|
||||
}
|
||||
|
||||
$attachment_info = '?file=' . urlencode($url);
|
||||
$final_url = $viewer_base_url . $attachment_info . '&plugins_url=' . urlencode($plugin_dir_url);
|
||||
$return = '<div><iframe width="' . esc_attr($width) . '" height="' . esc_attr($height) . '" src="' . esc_url($final_url) . '" title="Embedded PDF" class="wpmf-pdfjs-iframe"></iframe></div>';
|
||||
}
|
||||
} else {
|
||||
$return = '<a href="'.esc_url($url).'" '. (($attrs['target'] !== '') ? 'target="'.esc_attr($attrs['target']).'"' : '') .'>'.esc_html($title).'</a>';
|
||||
}
|
||||
@@ -257,7 +264,13 @@ class WpmfPdfEmbed
|
||||
*/
|
||||
public function enqueue()
|
||||
{
|
||||
wp_enqueue_script('wpmf_compat_js');
|
||||
$wpmf_pdf_embed_old = apply_filters('wpmf_pdf_embed_old', false);
|
||||
if ($wpmf_pdf_embed_old) {
|
||||
wp_enqueue_script('wpmf_embed_pdf_js');
|
||||
wp_enqueue_script('wpmf_compat_js');
|
||||
wp_enqueue_script('wpmf_pdf_js');
|
||||
wp_enqueue_style('pdfemb_embed_pdf_css');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -269,7 +282,6 @@ class WpmfPdfEmbed
|
||||
public function getTranslation()
|
||||
{
|
||||
$array = array(
|
||||
// 'worker_src' => plugins_url('assets/js/pdf-embed/pdf.worker.min.js', dirname(__FILE__)),
|
||||
'worker_src' => plugins_url('assets/js/pdf-embed/pdf.worker.js', dirname(__FILE__)),
|
||||
'cmap_url' => plugins_url('assets/js/pdf-embed/cmaps/', dirname(__FILE__)),
|
||||
'pdf_sandbox'=> plugins_url('assets/js/pdf-embed/pdf.sandbox.js', dirname(__FILE__)),
|
||||
@@ -292,6 +304,11 @@ class WpmfPdfEmbed
|
||||
'poweredby' => 1
|
||||
)
|
||||
);
|
||||
$wpmf_pdf_embed_old = apply_filters('wpmf_pdf_embed_old', false);
|
||||
if ($wpmf_pdf_embed_old) {
|
||||
$array['worker_src'] = plugins_url('assets/js/pdf-embed/pdf.worker.min.js', dirname(__FILE__));
|
||||
unset($array['pdf_sandbox']);
|
||||
}
|
||||
return $array;
|
||||
}
|
||||
|
||||
@@ -404,22 +421,33 @@ class WpmfPdfEmbed
|
||||
*/
|
||||
public function registerScript()
|
||||
{
|
||||
wp_register_script(
|
||||
'wpmf_compat_js',
|
||||
plugins_url('assets/js/pdf-embed/compatibility.js', dirname(__FILE__)),
|
||||
array('jquery')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add script
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function addCustomPdfL10nLink()
|
||||
{
|
||||
$locale_url = plugins_url('assets/js/pdf-embed/locale/locale.properties', dirname(__FILE__));
|
||||
echo '<link rel="resource" type="application/l10n" href="' . esc_url($locale_url) . '">';
|
||||
$wpmf_pdf_embed_old = apply_filters('wpmf_pdf_embed_old', false);
|
||||
if ($wpmf_pdf_embed_old) {
|
||||
wp_register_script(
|
||||
'wpmf_embed_pdf_js',
|
||||
plugins_url('assets/js/pdf-embed/all-pdfemb-basic.min.js', dirname(__FILE__)),
|
||||
array('jquery')
|
||||
);
|
||||
wp_localize_script(
|
||||
'wpmf_embed_pdf_js',
|
||||
'wpmf_pdfemb_trans',
|
||||
$this->getTranslation()
|
||||
);
|
||||
wp_register_script(
|
||||
'wpmf_compat_js',
|
||||
plugins_url('assets/js/pdf-embed/compatibility.js', dirname(__FILE__)),
|
||||
array('jquery')
|
||||
);
|
||||
wp_register_script(
|
||||
'wpmf_pdf_js',
|
||||
plugins_url('assets/js/pdf-embed/pdf-old.js', dirname(__FILE__)),
|
||||
array()
|
||||
);
|
||||
wp_register_style(
|
||||
'pdfemb_embed_pdf_css',
|
||||
plugins_url('assets/css/pdfemb-embed-pdf.css', dirname(__FILE__))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user