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 = '

' . esc_html__( 'Attachment Pages are disabled for secure PDFs (your admin can enable them in the Secure tab of PDF Embedder settings).', 'pdf-embedder' ) . '

'; } 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(); ?>

/>
/>
/>
/>




' />
' />
' />
' />
/>


Instructions for more details.', 'pdf-embedder' ); ?>

'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 'pdf-direct-link requires a url attribute'; } $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 = '' . $innerhtml . ''; 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(); }