- WordPress core y plugins - Tema Twenty Twenty-Four configurado - Plugin allow-unfiltered-html.php simplificado - .gitignore configurado para excluir wp-config.php y uploads 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
759 lines
25 KiB
PHP
Executable File
759 lines
25 KiB
PHP
Executable File
<?php
|
|
/**
|
|
* Plugin Name: PDF Embedder Premium Secure
|
|
* Plugin URI: http://wp-pdf.com/
|
|
* Description: Embed secure undownloadable PDFs straight into your posts and pages, with flexible width and height. No third-party services required.
|
|
* Version: 5.1.4
|
|
* Author: PDF Embedder Team
|
|
* Author URI: http://wp-pdf.com/
|
|
* Text Domain: pdf-embedder
|
|
* License: Premium Paid per WordPress site
|
|
*
|
|
* Do not copy, modify, or redistribute without authorization from author Lesterland Ltd (contact@wp-pdf.com)
|
|
*
|
|
* You need to have purchased a license to install this software on each website.
|
|
*
|
|
* You are not authorized to use, modify, or distribute this software beyond the single site license(s) that you
|
|
* have purchased.
|
|
*
|
|
* You must not remove or alter any copyright notices on any and all copies of this software.
|
|
*
|
|
* This software is NOT licensed under one of the public "open source" licenses you may be used to on the web.
|
|
*
|
|
* For full license details, and to understand your rights, please refer to the agreement you made when you purchased it
|
|
* from our website at https://wp-pdf.com/
|
|
*
|
|
* THIS SOFTWARE IS SUPPLIED "AS-IS" AND THE LIABILITY OF THE AUTHOR IS STRICTLY LIMITED TO THE PURCHASE PRICE YOU PAID
|
|
* FOR YOUR LICENSE.
|
|
*
|
|
* Please report violations to contact@wp-pdf.com
|
|
*
|
|
* Copyright LionShare Technologies, registered company in the United States of America
|
|
*
|
|
* @since 1.0.0
|
|
*
|
|
* @package WP-PDF-Secure
|
|
*/
|
|
|
|
require_once plugin_dir_path( __FILE__ ) . '/core/commercial_pdf_embedder.php';
|
|
|
|
if ( class_exists( 'WP_PDF_Commercial' ) ) {
|
|
|
|
/**
|
|
* PDFEmb Secure Core Class.
|
|
*
|
|
* @since 5.1.0
|
|
*/
|
|
final class WP_PDF_Secure extends WP_PDF_Commercial {
|
|
|
|
/**
|
|
* Singleton Instance
|
|
*
|
|
* @var object
|
|
*/
|
|
private static $instance = null;
|
|
|
|
/**
|
|
* Plugin Version
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $plugin_version = '5.1.4';
|
|
|
|
/**
|
|
* Store Url
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $wppdf_store_url = 'http://wp-pdf.com/';
|
|
|
|
/**
|
|
* Item Name
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $wppdf_item_name = 'PDF Embedder Secure';
|
|
|
|
/**
|
|
* WP PDF Item
|
|
*
|
|
* @var int
|
|
*/
|
|
protected $wppdf_item_id = 17;
|
|
|
|
/**
|
|
* Secure Uploader
|
|
*
|
|
* @var [type]
|
|
*/
|
|
protected $secure_uploader = null;
|
|
|
|
/**
|
|
* Undocumented variable
|
|
*
|
|
* @var string
|
|
*/
|
|
protected static $poweredby_optionname = 'poweredby';
|
|
|
|
/**
|
|
* Activation Hook
|
|
*
|
|
* @param bool $network_wide Network wide check.
|
|
* @return void
|
|
*/
|
|
public function pdfemb_activation_hook( $network_wide ) {
|
|
|
|
$su = $this->get_SecureUploader();
|
|
$su->create_protection_files( true );
|
|
parent::pdfemb_activation_hook( $network_wide );
|
|
|
|
$old_options = get_site_option( self::self_option_name() );
|
|
|
|
if ( ! $old_options ) {
|
|
update_site_option( self::$poweredby_optionname, 'off' );
|
|
}
|
|
|
|
$activation_time = get_option( 'wppdf_emb_activation', false );
|
|
|
|
if ( ! $activation_time ) {
|
|
update_option( 'wppdf_emb_activation', time() );
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
* Helper Method to get translations array
|
|
*
|
|
* @return array
|
|
*/
|
|
protected function get_translation_array() {
|
|
|
|
$su = $this->get_SecureUploader();
|
|
|
|
$options = $this->get_option_pdfemb();
|
|
|
|
return array_merge(
|
|
parent::get_translation_array(),
|
|
array(
|
|
'k' => $su->get_secret_key(),
|
|
'is_admin' => ( current_user_can( 'manage_options' ) ),
|
|
'ajaxurl' => admin_url( 'admin-ajax.php' ),
|
|
'watermark_map' => apply_filters( 'pdfemb_watermark_map', $this->calculate_watermark_map() ),
|
|
'watermark_evenpagesonly' => $options['pdfemb_wm_evenpages'],
|
|
)
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Watermark Map Calculator
|
|
*
|
|
* @return array
|
|
*/
|
|
protected function calculate_watermark_map() {
|
|
$options = $this->get_option_pdfemb();
|
|
|
|
$text_array = preg_split( '/(\r\n|\n\r|\n|\r)/', $options['pdfemb_wm_text'], -1 );
|
|
|
|
if ( count( $text_array ) === 0 ) {
|
|
return array();
|
|
}
|
|
|
|
$notloggedin_text = __( 'Not logged in', 'pdf-embedder' );
|
|
$var_names = array( '{fullname}', '{username}', '{email}' );
|
|
$var_values = array( $notloggedin_text, $notloggedin_text, $notloggedin_text );
|
|
|
|
$current_user = wp_get_current_user();
|
|
if ( ( $current_user instanceof WP_User ) && $current_user->ID ) {
|
|
$var_values = array(
|
|
$current_user->first_name . ' ' . $current_user->last_name,
|
|
$current_user->user_login,
|
|
$current_user->user_email,
|
|
);
|
|
}
|
|
|
|
$var_names = apply_filters( 'pdfemb_watermark_var_names', $var_names );
|
|
$var_values = apply_filters( 'pdfemb_watermark_var_values', $var_values );
|
|
|
|
$watermark_map = array();
|
|
$fontsize = $this->int_or_default( $options['pdfemb_wm_fontsize'], 20 );
|
|
|
|
$voffset = $this->int_or_default( $options['pdfemb_wm_voffset'], 30 );
|
|
$cssstyles = array(
|
|
'globalAlpha' => $this->int_or_default( $options['pdfemb_wm_opacity'], 20 ) / 100,
|
|
);
|
|
foreach ( $text_array as $text ) {
|
|
$watermark_map[] = array(
|
|
str_replace( $var_names, $var_values, $text ),
|
|
5,
|
|
$voffset,
|
|
$options['pdfemb_wm_halign'],
|
|
$options['pdfemb_wm_rotate'],
|
|
$fontsize,
|
|
$cssstyles,
|
|
);
|
|
|
|
$voffset += $fontsize / 6.5;
|
|
}
|
|
|
|
return $watermark_map;
|
|
}
|
|
|
|
/**
|
|
* Int or Default.
|
|
*
|
|
* @param mixed $val Value.
|
|
* @param mixed $default Default Option.
|
|
* @return mixed
|
|
*/
|
|
protected function int_or_default( $val, $default ) {
|
|
if ( is_numeric( $val ) ) {
|
|
return intval( $val );
|
|
}
|
|
return $default;
|
|
}
|
|
|
|
/**
|
|
* Modify PDF Url.
|
|
*
|
|
* @param string $url Url.
|
|
* @return string
|
|
*/
|
|
protected function modify_pdfurl( $url ) {
|
|
|
|
$su = $this->get_SecureUploader();
|
|
|
|
$securepdfpath = $su->get_secure_path( $url );
|
|
|
|
if ( '' !== $securepdfpath ) {
|
|
// Turn into a secure version of the URL.
|
|
$url = wp_parse_url( home_url( '/' ), PHP_URL_PATH ) . '?pdfemb-serveurl=' . rawurlencode( $url );
|
|
}
|
|
|
|
return parent::modify_pdfurl( $url );
|
|
}
|
|
|
|
/**
|
|
* Admin Init.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function pdfemb_admin_init() {
|
|
parent::pdfemb_admin_init();
|
|
$su = $this->get_SecureUploader();
|
|
$su->intercept_uploads();
|
|
$su->create_protection_files( false );
|
|
|
|
// For PDF Thumbnails mainly.
|
|
add_filter( 'pdfth_pdf_direct_download_url', array( $this, 'pdfth_pdf_direct_download_url' ), 1, 10 );
|
|
add_filter( 'pdfth_pdf_is_secure', array( $this, 'pdfth_pdf_is_secure' ), 2, 10 );
|
|
}
|
|
|
|
/**
|
|
* Init.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function pdfemb_init() {
|
|
$su = $this->get_SecureUploader();
|
|
$su->handle_downloads();
|
|
parent::pdfemb_init();
|
|
}
|
|
|
|
/**
|
|
* Undocumented function
|
|
*
|
|
* @return object
|
|
*/
|
|
public function get_SecureUploader() {
|
|
if ( is_null( $this->secure_uploader ) ) {
|
|
include_once dirname( __FILE__ ) . '/core/secure/uploads.php';
|
|
$options = $this->get_option_pdfemb();
|
|
$this->secure_uploader = new WP_PDF_Secure_Uploader( $options['pdfemb_secure'], $options['pdfemb_cacheencrypted'] );
|
|
}
|
|
return $this->secure_uploader;
|
|
}
|
|
|
|
/**
|
|
* Extra Shortcode Atts
|
|
*
|
|
* @param array $atts Shortcode atts.
|
|
* @param string $content Content.
|
|
* @return string
|
|
*/
|
|
protected function extra_shortcode_attrs( $atts, $content = null ) {
|
|
|
|
$options = $this->get_option_pdfemb();
|
|
|
|
$securemore = '';
|
|
$disablerightclick_html = '';
|
|
|
|
if ( isset( $atts['url'] ) ) {
|
|
|
|
$su = $this->get_SecureUploader();
|
|
|
|
$securepdfpath = $su->get_secure_path( $atts['url'] );
|
|
|
|
if ( '' !== $securepdfpath ) {
|
|
// Is a secure PDF.
|
|
$download = isset( $atts['download'] ) ? $atts['download'] : ( isset( $options['pdfemb_download'] ) && $options['pdfemb_download'] ? 'on' : 'off' );
|
|
if ( ! in_array( $download, array( 'on', 'off' ), true ) ) {
|
|
$download = 'off';
|
|
}
|
|
|
|
if ( 'on' === $download ) {
|
|
$securemore = ' data-download-nonce="' . wp_create_nonce( 'pdfemb-secure-download-' . $atts['url'] ) . '"';
|
|
}
|
|
|
|
$disablerightclick = isset( $atts['disablerightclick'] ) ? $atts['disablerightclick'] : ( isset( $options['pdfemb_disablerightclick'] ) && $options['pdfemb_disablerightclick'] ? 'on' : 'off' );
|
|
if ( ! in_array( $disablerightclick, array( 'on', 'off' ), true ) ) {
|
|
$disablerightclick = 'off';
|
|
}
|
|
|
|
if ( 'on' === $disablerightclick ) {
|
|
$disablerightclick_html = ' data-disablerightclick="on"';
|
|
}
|
|
}
|
|
}
|
|
|
|
return parent::extra_shortcode_attrs( $atts, $content ) . $securemore . $disablerightclick_html;
|
|
}
|
|
|
|
/**
|
|
* Helper method for output content.
|
|
*
|
|
* @param string $pdfurl PDF Url.
|
|
* @return string
|
|
*/
|
|
protected function output_the_content( $pdfurl ) {
|
|
$options = $this->get_option_pdfemb();
|
|
if ( ! $options['pdfemb_secureattpages'] && $this->is_secure( $pdfurl ) ) {
|
|
$content = '<p>' . esc_html__( 'Attachment Pages are disabled for secure PDFs (your admin can enable them in the Secure tab of PDF Embedder settings).', 'pdf-embedder' ) . '</p>';
|
|
} else {
|
|
$content = parent::output_the_content( $pdfurl );
|
|
}
|
|
return $content;
|
|
}
|
|
|
|
/**
|
|
* Is url Secure
|
|
*
|
|
* @param string $pdfurl PDF Url.
|
|
* @return bool
|
|
*/
|
|
protected function is_secure( $pdfurl ) {
|
|
$su = $this->get_SecureUploader();
|
|
$securepdfpath = $su->get_secure_path( $pdfurl );
|
|
return '' !== $securepdfpath;
|
|
}
|
|
|
|
/**
|
|
* Direct downloaad URl.
|
|
*
|
|
* @param string $pdfurl PDF Url.
|
|
* @return string
|
|
*/
|
|
public function pdfth_pdf_direct_download_url( $pdfurl ) {
|
|
|
|
$su = $this->get_SecureUploader();
|
|
$securepdfpath = $su->get_secure_path( $pdfurl );
|
|
|
|
if ( '' !== $securepdfpath ) {
|
|
$pdfurl = wp_parse_url( home_url( '/' ), PHP_URL_PATH ) . '?pdfemb-serveurl=' . rawurlencode( $pdfurl ) . '&pdfemb-nonce=' . wp_create_nonce( 'pdfemb-secure-download-' . $pdfurl );
|
|
}
|
|
|
|
return $pdfurl;
|
|
}
|
|
|
|
/**
|
|
* Undocumented function
|
|
*
|
|
* @param string $pdfurl PDF url.
|
|
* @return boolean
|
|
*/
|
|
public function pdfth_pdf_is_secure( $pdfurl ) {
|
|
|
|
$su = $this->get_SecureUploader();
|
|
$securepdfpath = $su->get_secure_path( $pdfurl );
|
|
|
|
return '' !== $securepdfpath;
|
|
|
|
}
|
|
|
|
/**
|
|
* Undocumented function
|
|
*
|
|
* @return void
|
|
*/
|
|
protected function pdfemb_securesection_text() {
|
|
$options = $this->get_option_pdfemb();
|
|
?>
|
|
|
|
<h2><?php esc_html_e( 'Secure PDFs', 'pdf-embedder' ); ?></h2>
|
|
|
|
<p><?php esc_html_e( 'Your server must be running Apache and supporting .htaccess rules to restrict access to files.', 'pdf-embedder' ); ?></p>
|
|
|
|
<label for="pdfemb_secure" class="textinput"><?php esc_html_e( 'Secure PDFs', 'pdf-embedder' ); ?></label>
|
|
|
|
<span>
|
|
<input type="checkbox" name='<?php echo esc_attr( $this->get_options_name() ); ?>[pdfemb_secure]' id='pdfemb_secure' class='checkbox' <?php checked( boolval( $options['pdfemb_secure'] ), 1 ); ?> />
|
|
<label for="pdfemb_secure" class="checkbox plain"><?php esc_html_e( "Send new PDF media uploads to 'securepdfs' folder", 'pdf-embedder' ); ?></label>
|
|
</span>
|
|
|
|
<br class="clear" />
|
|
|
|
|
|
<label for="pdfemb_disablerightclick" class="textinput"><?php esc_html_e( 'Disable Right Click', 'pdf-embedder' ); ?></label>
|
|
<span>
|
|
<input type="checkbox" name='<?php echo esc_attr( $this->get_options_name() ); ?>[pdfemb_disablerightclick]' id='pdfemb_disablerightclick' class='checkbox' <?php checked( boolval( $options['pdfemb_disablerightclick'] ), 1 ); ?> />
|
|
<label for="pdfemb_disablerightclick" class="checkbox plain"><?php esc_html_e( 'Disable right-click mouse menu (affects secure PDFs only)', 'pdf-embedder' ); ?></label>
|
|
</span>
|
|
|
|
<br class="clear" />
|
|
|
|
<label for="pdfemb_cacheencrypted" class="textinput"><?php esc_html_e( 'Cache Encrypted PDFs', 'pdf-embedder' ); ?></label>
|
|
<span>
|
|
<input type="checkbox" name='<?php echo esc_attr( $this->get_options_name() ); ?>[pdfemb_cacheencrypted]' id='pdfemb_cacheencrypted' class='checkbox' <?php checked( boolval( $options['pdfemb_cacheencrypted'] ), 1 ); ?> />
|
|
<label for="pdfemb_cacheencrypted" class="checkbox plain"><?php esc_html_e( 'Cache encrypted versions of secure PDFs on the server (increase download speed)', 'pdf-embedder' ); ?></label>
|
|
</span>
|
|
|
|
<br class="clear" />
|
|
|
|
<label for="pdfemb_secureattpages" class="textinput"><?php esc_html_e( 'Attachment Pages', 'pdf-embedder' ); ?></label>
|
|
<span>
|
|
<input type="checkbox" name='<?php echo esc_attr( $this->get_options_name() ); ?>[pdfemb_secureattpages]' id='pdfemb_secureattpages' class='checkbox' <?php checked( boolval( $options['pdfemb_secureattpages'] ), 1 ); ?> />
|
|
<label for="pdfemb_secureattpages" class="checkbox plain"><?php esc_html_e( 'Auto-generate Attachment Pages for Secure PDFs', 'pdf-embedder' ); ?></label>
|
|
</span>
|
|
|
|
<br class="clear" />
|
|
<br class="clear" />
|
|
|
|
<h2><?php esc_html_e( 'Watermark', 'pdf-embedder' ); ?></h2>
|
|
|
|
<label for="pdfemb_wm_text" class="textinput"><?php esc_html_e( 'Text to display on secure PDFs', 'pdf-embedder' ); ?></label>
|
|
<textarea id='pdfemb_wm_text' class='textinput' name='<?php echo esc_attr( $this->get_options_name() ); ?>[pdfemb_wm_text]'><?php echo wp_kses_post( htmlentities( $options['pdfemb_wm_text'] ) ); ?></textarea>
|
|
<br class="clear"/>
|
|
|
|
<p class="desc big"><i><?php esc_html_e( 'Leave blank for no watermark on secure PDFs.', 'pdf-embedder' ); ?>
|
|
<br /><?php esc_html_e( 'Variables you can use in the text (from a logged in user, otherwise will be blank): {fullname}, {username}, {email}', 'pdf-embedder' ); ?></i></p>
|
|
|
|
<label for="pdfemb_wm_halign" class="textinput"><?php esc_html_e( 'Horizontal alignment', 'pdf-embedder' ); ?></label>
|
|
<select name='<?php echo esc_attr( $this->get_options_name() ); ?>[pdfemb_wm_halign]' id='pdfemb_wm_halign' class='select'>
|
|
<option value="left" <?php echo 'left' === $options['pdfemb_wm_halign'] ? 'selected' : ''; ?>><?php esc_html_e( 'Left', 'pdf-embedder' ); ?></option>
|
|
<option value="center" <?php echo 'center' === $options['pdfemb_wm_halign'] ? 'selected' : ''; ?>><?php esc_html_e( 'Center', 'pdf-embedder' ); ?></option>
|
|
<option value="right" <?php echo 'right' === $options['pdfemb_wm_halign'] ? 'selected' : ''; ?>><?php esc_html_e( 'Right', 'pdf-embedder' ); ?></option>
|
|
</select>
|
|
|
|
<br class="clear"/>
|
|
|
|
<label for="pdfemb_wm_voffset" class="textinput"><?php esc_html_e( 'Vertical offset (%)', 'pdf-embedder' ); ?></label>
|
|
<input id='pdfemb_wm_voffset' class='textinput' name='<?php echo esc_attr( $this->get_options_name() ); ?>[pdfemb_wm_voffset]' size='10' type='text' value='<?php echo esc_attr( $options['pdfemb_wm_voffset'] ); ?>' />
|
|
|
|
<br class="clear"/>
|
|
|
|
<label for="pdfemb_wm_fontsize" class="textinput"><?php esc_html_e( 'Font Size (pt)', 'pdf-embedder' ); ?></label>
|
|
<input id='pdfemb_wm_fontsize' class='textinput' name='<?php echo esc_attr( $this->get_options_name() ); ?>[pdfemb_wm_fontsize]' size='10' type='text' value='<?php echo esc_attr( $options['pdfemb_wm_fontsize'] ); ?>' />
|
|
|
|
<br class="clear"/>
|
|
|
|
<label for="pdfemb_wm_opacity" class="textinput"><?php esc_html_e( 'Opacity (%)', 'pdf-embedder' ); ?></label>
|
|
<input id='pdfemb_wm_opacity' class='textinput' name='<?php echo esc_attr( $this->get_options_name() ); ?>[pdfemb_wm_opacity]' size='10' type='text' value='<?php echo esc_attr( $options['pdfemb_wm_opacity'] ); ?>' />
|
|
|
|
<br class="clear"/>
|
|
|
|
<label for="pdfemb_wm_rotate" class="textinput"><?php esc_html_e( 'Rotation (degrees)', 'pdf-embedder' ); ?></label>
|
|
<input id='pdfemb_wm_rotate' class='textinput' name='<?php echo esc_attr( $this->get_options_name() ); ?>[pdfemb_wm_rotate]' size='10' type='text' value='<?php echo esc_attr( $options['pdfemb_wm_rotate'] ); ?>' />
|
|
|
|
<br class="clear"/>
|
|
|
|
<label for="pdfemb_wm_evenpages" class="textinput"><?php esc_html_e( 'Page Display', 'pdf-embedder' ); ?></label>
|
|
<span>
|
|
<input type="checkbox" name='<?php echo esc_attr( $this->get_options_name() ); ?>[pdfemb_wm_evenpages]' id='pdfemb_wm_evenpages' class='checkbox' <?php echo $options['pdfemb_wm_evenpages'] ? 'checked' : ''; ?> />
|
|
<label for="pdfemb_wm_evenpages" class="checkbox plain"><?php esc_html_e( 'Show only on even page numbers', 'pdf-embedder' ); ?></label>
|
|
</span>
|
|
|
|
<br class="clear"/>
|
|
<br class="clear"/>
|
|
|
|
<hr />
|
|
|
|
<p>
|
|
<?php
|
|
esc_html_e(
|
|
"If 'Secure PDFs' is checked above, your PDF uploads will be 'secure' by default.
|
|
That is, they should be uploaded to a 'securepdfs' sub-folder of your uploads area. These files should not be accessible directly,
|
|
and the plugin provides a backdoor method for the embedded viewer to obtain the file contents.",
|
|
'pdf-embedder'
|
|
);
|
|
?>
|
|
</p>
|
|
|
|
<p>
|
|
<?php
|
|
esc_html_e(
|
|
'This means that your PDF is unlikely to be shared outside your site where you have no control over who views, prints, or shares it.
|
|
Please note that it is still always possible for a determined user to obtain the original file. Sensitive information should never be presented to viewers in any form.',
|
|
'pdf-embedder'
|
|
);
|
|
?>
|
|
</p>
|
|
|
|
<p><?php esc_html_e( 'See <a href="http://wp-pdf.com/secure-instructions/?utm_source=PDF%20Settings%20Secure&utm_medium=premium&utm_campaign=Premium" target="_blank">Instructions</a> for more details.', 'pdf-embedder' ); ?></p>
|
|
|
|
<?php
|
|
}
|
|
|
|
/**
|
|
* Helper method to get eddsl option name.
|
|
*
|
|
* @return string
|
|
*/
|
|
protected function get_eddsl_optname() {
|
|
return 'eddsl_pdfemb_secure_ls';
|
|
}
|
|
|
|
/**
|
|
* Hellper Method to get default options.
|
|
*
|
|
* @return array
|
|
*/
|
|
protected function get_default_options() {
|
|
return array_merge(
|
|
parent::get_default_options(),
|
|
array(
|
|
'pdfemb_download' => 'off',
|
|
'pdfemb_secure' => true,
|
|
'pdfemb_disablerightclick' => 'off',
|
|
'pdfemb_secureattpages' => false,
|
|
'pdfemb_cacheencrypted' => true,
|
|
'pdfemb_wm_text' => '',
|
|
'pdfemb_wm_halign' => 'center',
|
|
'pdfemb_wm_voffset' => '30',
|
|
'pdfemb_wm_fontsize' => '20',
|
|
'pdfemb_wm_opacity' => '20',
|
|
'pdfemb_wm_rotate' => '35',
|
|
'pdfemb_wm_evenpages' => false,
|
|
)
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Helper Method ti vakudate iotuib
|
|
*
|
|
* @param mixed $input Option input.
|
|
* @return array
|
|
*/
|
|
public function pdfemb_options_validate( $input ) {
|
|
$newinput = parent::pdfemb_options_validate( $input );
|
|
|
|
$newinput['pdfemb_secure'] = isset( $input['pdfemb_secure'] ) && ( true === $input['pdfemb_secure'] || 'on' === $input['pdfemb_secure'] );
|
|
$newinput['pdfemb_disablerightclick'] = isset( $input['pdfemb_disablerightclick'] ) && ( true === $input['pdfemb_disablerightclick'] || 'on' === $input['pdfemb_disablerightclick'] );
|
|
|
|
$newinput['pdfemb_cacheencrypted'] = isset( $input['pdfemb_cacheencrypted'] ) && ( true === $input['pdfemb_cacheencrypted'] || 'on' === $input['pdfemb_cacheencrypted'] );
|
|
|
|
$newinput['pdfemb_secureattpages'] = isset( $input['pdfemb_secureattpages'] ) && ( true === $input['pdfemb_secureattpages'] || 'on' === $input['pdfemb_secureattpages'] );
|
|
|
|
$newinput['pdfemb_wm_text'] = isset( $input['pdfemb_wm_text'] ) && ! preg_match( '/^[\n\r ]+$/', $input['pdfemb_wm_text'] ) ? $input['pdfemb_wm_text'] : '';
|
|
|
|
if ( isset( $input['pdfemb_wm_halign'] ) && in_array( $input['pdfemb_wm_halign'], array( 'left', 'center', 'right' ), true ) ) {
|
|
$newinput['pdfemb_wm_halign'] = $input['pdfemb_wm_halign'];
|
|
} else {
|
|
$newinput['pdfemb_wm_halign'] = 'center';
|
|
}
|
|
|
|
$newinput['pdfemb_wm_voffset'] = isset( $input['pdfemb_wm_voffset'] ) ? $input['pdfemb_wm_voffset'] : '5';
|
|
if ( ! is_numeric( $newinput['pdfemb_wm_voffset'] ) ) {
|
|
add_settings_error(
|
|
'pdfemb_wm_voffset',
|
|
'notnumeric',
|
|
self::get_error_string( 'pdfemb_wm_voffset|notnumeric' ),
|
|
'error'
|
|
);
|
|
}
|
|
|
|
$newinput['pdfemb_wm_fontsize'] = isset( $input['pdfemb_wm_fontsize'] ) ? $input['pdfemb_wm_fontsize'] : '20';
|
|
if ( ! is_numeric( $newinput['pdfemb_wm_fontsize'] ) ) {
|
|
add_settings_error(
|
|
'pdfemb_wm_fontsize',
|
|
'notnumeric',
|
|
self::get_error_string( 'pdfemb_wm_fontsize|notnumeric' ),
|
|
'error'
|
|
);
|
|
}
|
|
|
|
$newinput['pdfemb_wm_opacity'] = isset( $input['pdfemb_wm_opacity'] ) ? $input['pdfemb_wm_opacity'] : '20';
|
|
if ( ! is_numeric( $newinput['pdfemb_wm_opacity'] ) ) {
|
|
add_settings_error(
|
|
'pdfemb_wm_opacity',
|
|
'notnumeric',
|
|
self::get_error_string( 'pdfemb_wm_opacity|notnumeric' ),
|
|
'error'
|
|
);
|
|
}
|
|
|
|
$newinput['pdfemb_wm_rotate'] = isset( $input['pdfemb_wm_rotate'] ) ? $input['pdfemb_wm_rotate'] : '35';
|
|
if ( ! is_numeric( $newinput['pdfemb_wm_rotate'] ) ) {
|
|
add_settings_error(
|
|
'pdfemb_wm_rotate',
|
|
'notnumeric',
|
|
self::get_error_string( 'pdfemb_wm_rotate|notnumeric' ),
|
|
'error'
|
|
);
|
|
}
|
|
|
|
$newinput['pdfemb_wm_evenpages'] = isset( $input['pdfemb_wm_evenpages'] ) && ( true === $input['pdfemb_wm_evenpages'] || 'on' === $input['pdfemb_wm_evenpages'] );
|
|
|
|
return $newinput;
|
|
}
|
|
|
|
/**
|
|
* Helper Method to get string errods
|
|
*
|
|
* @param string $fielderror Field Error.
|
|
* @return string
|
|
*/
|
|
protected function get_error_string( $fielderror ) {
|
|
$secure_local_error_strings = array(
|
|
'pdfemb_wm_voffset|notnumeric' => __( 'Watermark Vertical offset should be a numerical value between 0 and 100', 'pdf-embedder' ),
|
|
'pdfemb_wm_fontsize|notnumeric' => __( 'Font Size should be a numerical value', 'pdf-embedder' ),
|
|
'pdfemb_wm_opacity|notnumeric' => __( 'Watermark Opacity should be a numerical value between 0 and 100', 'pdf-embedder' ),
|
|
'pdfemb_wm_rotate|notnumeric' => __( 'Watermark Rotation should be a numerical value in degrees (0 to 360)', 'pdf-embedder' ),
|
|
);
|
|
if ( isset( $secure_local_error_strings[ $fielderror ] ) ) {
|
|
return $secure_local_error_strings[ $fielderror ];
|
|
}
|
|
return parent::get_error_string( $fielderror );
|
|
}
|
|
|
|
/**
|
|
* Helper Method to get direct link
|
|
*
|
|
* @param array $atts Attributes.
|
|
* @param string $content Content.
|
|
* @return string
|
|
*/
|
|
public function pdfemb_shortcode_direct_link( $atts, $content = null ) {
|
|
if ( ! isset( $atts['url'] ) ) {
|
|
return '<b>pdf-direct-link requires a url attribute</b>';
|
|
}
|
|
|
|
$url = $this->pdfth_pdf_direct_download_url( set_url_scheme( $atts['url'] ) );
|
|
|
|
$innerhtml = '';
|
|
if ( ! empty( $content ) ) {
|
|
$innerhtml = do_shortcode( $content );
|
|
}
|
|
|
|
if ( strlen( $innerhtml ) === 0 ) {
|
|
$innerhtml = isset( $atts['text'] ) ? $atts['text'] : $atts['url'];
|
|
}
|
|
|
|
$returnhtml = '<a href="' . esc_attr( $url ) . '">' . $innerhtml . '</a>';
|
|
|
|
return $returnhtml;
|
|
}
|
|
/**
|
|
* Undocumented function
|
|
*
|
|
* @return void
|
|
*/
|
|
protected function add_actions() {
|
|
parent::add_actions();
|
|
|
|
add_shortcode( 'pdf-direct-link', array( $this, 'pdfemb_shortcode_direct_link' ) );
|
|
}
|
|
|
|
/**
|
|
* Helper Method to get basename
|
|
*
|
|
* @return string
|
|
*/
|
|
protected function pdf_plugin_basename() {
|
|
$basename = plugin_basename( __FILE__ );
|
|
if ( __FILE__ === '/' . $basename ) { // Maybe due to symlink.
|
|
$basename = basename( dirname( __FILE__ ) ) . '/' . basename( __FILE__ );
|
|
}
|
|
return $basename;
|
|
}
|
|
/**
|
|
* Helper Method to get plugin url
|
|
*
|
|
* @return string
|
|
*/
|
|
protected function pdf_plugin_url() {
|
|
$basename = plugin_basename( __FILE__ );
|
|
|
|
if ( __FILE__ === '/' . $basename ) { // Maybe due to symlink.
|
|
return plugins_url() . '/' . basename( dirname( __FILE__ ) ) . '/';
|
|
}
|
|
|
|
// Normal case (non symlink).
|
|
return plugin_dir_url( __FILE__ );
|
|
}
|
|
|
|
/**
|
|
* Helper method to include files.
|
|
*
|
|
* @since 4.6.5
|
|
*
|
|
* @return void
|
|
*/
|
|
public function includes() {
|
|
require_once plugin_dir_path( __FILE__ ) . '/core/review.php';
|
|
}
|
|
|
|
/**
|
|
* Helper to define
|
|
*
|
|
* @param string $name Define Name.
|
|
* @param mixed $value Value.
|
|
* @return void
|
|
*/
|
|
public function define( $name, $value ) {
|
|
|
|
if ( ! defined( $name ) ) {
|
|
define( $name, $value );
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Setup Globals.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function setup_globals() {
|
|
$this->define( 'WP_PDF_VERSION', $this->plugin_version );
|
|
$this->define( 'WP_PDF_SECURE_FILE', $this->file );
|
|
$this->define( 'WP_PDF_SECURE_DIR', plugin_dir_path( __FILE__ ) );
|
|
$this->define( 'WP_PDF_SECURE_URL', plugin_dir_url( __FILE__ ) );
|
|
}
|
|
|
|
/**
|
|
* Undocumented function
|
|
*
|
|
* @return object
|
|
*/
|
|
public static function get_instance() {
|
|
if ( null === self::$instance ) {
|
|
self::$instance = new self();
|
|
self::$instance->setup_globals();
|
|
self::$instance->includes();
|
|
}
|
|
|
|
return self::$instance;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Singleton Instance
|
|
*
|
|
* @return WP_PDF_Secure
|
|
*/
|
|
function init_pdf_emb_secure() {
|
|
return WP_PDF_Secure::get_instance();
|
|
}
|
|
|
|
// Initialise at least once.
|
|
init_pdf_emb_secure();
|
|
|
|
}
|