to to fix target_new or target_blank issues. 2.1.5 - Fix conflict with link tracking plugins. Custom image support for hosted wordpress sites. 2.1.4 - wp head fix. 2.1.3 - Manual option for button placement. Security updates for multi-author sites. 2.1.2 - Improvements to Setting page layout and PrintFriendly button launching from post pages. 2.1.1 - Fixed admin settings bug. 2.1 - Update for mult-author websites. Improvements to Settings page. 2.0 - Customize the style, placement, and pages your printfriendly button appears. 1.5 - Added developer ability to disable hook and use the pf_show_link() function to better be used in a custom theme & Uninstall cleanup. 1.4 - Changed Name. 1.3 - Added new buttons, removed redundant code. 1.2 - User can choose to show or not show buttons on the listing page. */ /** * PrintFriendly WordPress plugin. Allows easy embedding of printfriendly.com buttons. * @package PrintFriendly_WordPress * @author PrintFriendly * @copyright Copyright (C) 2012, PrintFriendly */ if ( ! class_exists( 'PrintFriendly_WordPress' ) ) { /** * Class containing all the plugins functionality. * @package PrintFriendly_WordPress */ class PrintFriendly_WordPress { /** * Current plugin version. * @var string */ var $plugin_version = '3.12.0'; /** * The hook, used for text domain as well as hooks on pages and in get requests for admin. * @var string */ var $hook = 'printfriendly'; /** * The option name, used throughout to refer to the plugins option and option group. * @var string */ var $option_name = 'printfriendly_option'; /** * The plugins options, loaded on init containing all the plugins settings. * @var array */ var $options = array(); /** * Database version, used to allow for easy upgrades to / additions in plugin options between plugin versions. * @var int */ var $db_version = 15; /** * Settings page, used within the plugin to reliably load the plugins admin JS and CSS files only on the admin page. * @var string */ var $settings_page = ''; /** * GetSentry error reporting client * @var Raven_Client */ var $raven_client = null; /** * Constructor * * @since 3.0 */ function __construct() { try { // delete_option( $this->option_name ); // Retrieve the plugin options $this->options = get_option( $this->option_name ); // If the options array is empty, set defaults if ( ! is_array( $this->options ) ) $this->set_defaults(); // Sentry PHP SDK supports PHP 5.3 and higher. if( isset( $this->options['enable_error_reporting'] ) && $this->options['enable_error_reporting'] == 'yes' && version_compare(PHP_VERSION, '5.3.0') >= 0) { $this->init_error_reporting(); } /** * Set page content selection option "Wordpress Standard/Strict" to "WP Template" */ if( isset( $this->options['pf_algo'] ) && $this->options['pf_algo'] == 'ws' ){ $this->options['pf_algo'] = 'wp'; update_option( $this->option_name, $this->options ); } // If the version number doesn't match, upgrade if ( $this->db_version > $this->options['db_version'] ) $this->upgrade(); add_action( 'wp_head', array( &$this, 'front_head' ) ); // automaticaly add the link if( !$this->is_manual() ) { add_filter( 'the_content', array( &$this, 'show_link' ) ); add_filter( 'the_excerpt', array( &$this, 'show_link' ) ); } add_action('the_content', array(&$this, 'add_pf_content_class_around_content_hook')); // Admin hooks if ( is_admin() ) { // Hook into init for registration of the option and the language files add_action( 'admin_init', array( &$this, 'init' ) ); // Register the settings page add_action( 'admin_menu', array( &$this, 'add_config_page' ) ); // Register the contextual help add_filter( 'contextual_help', array( &$this, 'contextual_help' ), 10, 2 ); // Enqueue the needed scripts and styles add_action( 'admin_enqueue_scripts',array( &$this, 'admin_enqueue_scripts' ) ); // Register a link to the settings page on the plugins overview page add_filter( 'plugin_action_links', array( &$this, 'filter_plugin_actions' ), 10, 2 ); } } catch(Exception $e) { $this->raven_catch($e); } } function init_error_reporting() { try { require_once 'vendor/PrintFriendly/Raven/Autoloader.php'; PrintFriendly_Raven_Autoloader::register(); $this->raven_client = new PrintFriendly_Raven_Client('https://46a55182ffbe477c8cf1cb0f1cee36c2:a32ee5b4fad940c4808845b618147f21@sentry.io/171161', array( 'release' => $this->plugin_version, 'timeout' => 4 )); $this->raven_client->tags_context(array( 'wordpress-version' => get_bloginfo('version'), 'php-version' => PHP_VERSION )); $this->raven_client->setSendCallback(array( &$this, 'raven_callback' )); } catch (Exception $e) { if (!ini_get('display_errors')) { error_log('PrintFriendly init_error_reporting Error: ' . $e); } $this->raven_catch($e); } } function raven_callback($data) { try { return isset($data) && preg_match('/printfriendly/', json_encode($data)); } catch (Exception $e) { return true; } } function raven_catch($e) { if (isset($this->raven_client)) { try { $this->raven_client->captureException($e); } catch(Exception $e) {} } } /** * Adds wraps content in pf-content class to help Printfriendly algo determine the content * * @since 3.2.8 * **/ function add_pf_content_class_around_content_hook($content = false) { try { if( $this->is_wp_algo_on($content) ) { add_action( 'wp_footer', array( &$this, 'print_script_footer' )); return '
'.$content.'
'; } else { return $content; } } catch (Exception $e) { $this->raven_catch($e); } } /** * Override to check if print-only command is being used * * @since 3.3.0 **/ function print_only_override($content) { $pattern = '/class\s*?=\s*?(["\']|["\']([^"\']*?)\s)print-only(["\']|\s([^"\']*?)["\'])/'; $pf_pattern = '/class\s*?=\s*?(["\']|["\']([^"\']*?)\s)pf-content(["\']|\s([^"\']*?)["\'])/'; return (preg_match($pattern, $content) || preg_match($pf_pattern, $content)) ; } /** * Check if WP Algorithm is selected and content doesn't use print-only * * @since 3.5.4 **/ function is_wp_algo_on($content) { return !class_exists('WooCommerce') && isset($this->options['pf_algo']) && $content && $this->options['pf_algo'] == 'wp' && !$this->print_only_override($content); } /** * PHP 4 Compatible Constructor * * @since 3.0 */ function PrintFriendly_WordPress() { $this->__construct(); } /** * Prints the PrintFriendly button CSS, in the header. * * @since 3.0 */ function front_head() { try { ?> options['enable_css'] ) && $this->options['enable_css'] != 'on' ) return; ?> raven_catch($e); } } /** * Prints the PrintFriendly JavaScript, in the footer, and loads it asynchronously. * * @since 3.0 */ function print_script_footer() { if (isset($this->options['javascript']) && $this->options['javascript'] == 'no') return; else { $tagline = $this->options['tagline']; $image_url = $this->options['image_url']; if( $this->options['logo'] == 'favicon' ) { $tagline = ''; $image_url = ''; } // Currently we use v3 for both: normal and password protected sites ?> is_manual(); if( !$content && !$is_manual ) return ""; $button = $this->getButton(); if ( $is_manual ) { // Hook the script call now, so it only get's loaded when needed, and need is determined by the user calling pf_button add_action( 'wp_footer', array( &$this, 'print_script_footer' ) ); return $button; } else { if ( (is_page() && ( isset($this->options['show_on_pages']) && 'on' === $this->options['show_on_pages'] ) ) || (is_home() && ( ( isset($this->options['show_on_homepage']) && 'on' === $this->options['show_on_homepage'] ) && $this->category_included() ) ) || (is_tax() && ( ( isset($this->options['show_on_taxonomies']) && 'on' === $this->options['show_on_taxonomies'] ) && $this->category_included() ) ) || (is_category() && ( ( isset($this->options['show_on_categories']) && 'on' === $this->options['show_on_categories'] ) && $this->category_included() ) ) || (is_single() && ( ( isset($this->options['show_on_posts']) && 'on' === $this->options['show_on_posts'] ) && $this->category_included() ) ) ) { // Hook the script call now, so it only get's loaded when needed, and need is determined by the user calling pf_button add_action( 'wp_footer', array( &$this, 'print_script_footer' ) ); if ( $this->options['content_placement'] == 'before' ) return $button.$content; else return $content.$button; } else { return $content; } } } catch (Exception $e) { $this->raven_catch($e); } } /** * @since 3.3.8 * @returns Printfriendly Button HTML */ function getButton($add_footer_script = false) { if($add_footer_script) { add_action( 'wp_footer', array( &$this, 'print_script_footer' ) ); } $js_enabled = $this->js_enabled(); $analytics_code = ""; $onclick = ''; if ( $this->google_analytics_enabled() ) { $title_var = "NULL"; $analytics_code = "if(typeof(_gaq) != 'undefined') { _gaq.push(['_trackEvent','PRINTFRIENDLY', 'print', '".$title_var."']); }else if(typeof(ga) != 'undefined') { ga('send', 'event','PRINTFRIENDLY', 'print', '".$title_var."'); }"; if( $js_enabled ) { $onclick = 'onclick="window.print();'. $analytics_code .' return false;"'; } else { $onclick = ''; } } else if ( $js_enabled ) { $onclick = 'onclick="window.print(); return false;"'; } if( $js_enabled ){ $href = '#'; } else { $href = 'https://www.printfriendly.com/print?url='.urlencode(get_permalink()); } if (!$js_enabled) { if($this->google_analytics_enabled()) { $onclick = $onclick.' onclick="'.$analytics_code.'"'; } $href = "https://www.printfriendly.com/print?headerImageUrl=".urlencode($this->options['image_url'])."&headerTagline=".urlencode($this->options['tagline'])."&pfCustomCSS=".urlencode($this->options['custom_css_url'])."&imageDisplayStyle=".urlencode($this->options['image-style'])."&disableClickToDel=".urlencode($this->options['click_to_delete'])."&disablePDF=".urlencode($this->options['pdf'])."&disablePrint=".urlencode($this->options['print'])."&disableEmail=".urlencode($this->options['email'])."&imagesSize=".urlencode($this->options['images-size'])."&url=".urlencode(get_permalink())."&source=wp"; } if ( !is_singular() && '' != $onclick && $js_enabled) { $onclick = ''; $href = add_query_arg('pfstyle','wp',get_permalink()); } $align = ''; if ( 'none' != $this->options['content_position'] ) $align = ' pf-align'.$this->options['content_position']; $href = str_replace("&", "&", $href ); $button = apply_filters( 'printfriendly_button', '' ); return $button; } /** * @since 3.2.9 * @returns if google analytics enabled */ function google_analytics_enabled() { return isset( $this->options['enable_google_analytics'] ) && $this->options['enable_google_analytics'] == 'yes'; } /** * @since 3.2.6 * @return boolean true if JS is enabled for the plugin **/ function js_enabled() { return isset( $this->options['javascript'] ) && $this->options['javascript'] == 'yes'; } /** * Filter posts by category. * * @since 3.2.2 * @return boolean true if post belongs to category selected for button display */ function category_included() { // return ( 'all' === $this->options['category_ids'][0] || in_category($this->options['category_ids']) ); return true; } /** * Register the textdomain and the options array along with the validation function * * @since 3.0 */ function init() { try { // Allow for localization load_plugin_textdomain( $this->hook, false, basename( dirname( __FILE__ ) ) . '/languages' ); // Register our option array register_setting( $this->option_name, $this->option_name, array( &$this, 'options_validate' ) ); } catch (Exception $e) { $this->raven_catch($e); } } /** * Validate the saved options. * * @since 3.0 * @param array $input with unvalidated options. * @return array $valid_input with validated options. */ function options_validate( $input ) { // Prevent CSRF attack check_admin_referer( 'pf-options', 'pf-nonce' ); $valid_input = $input; // Section 1 options if ( !isset( $input['button_type'] ) || !in_array( $input['button_type'], array( 'buttons/printfriendly-pdf-email-button.png', 'buttons/printfriendly-pdf-email-button-md.png', 'buttons/printfriendly-pdf-email-button-notext.png', // buttongroup1 'buttons/printfriendly-pdf-button.png', 'buttons/printfriendly-pdf-button-nobg.png', 'buttons/printfriendly-pdf-button-nobg-md.png', // buttongroup2 'buttons/printfriendly-button.png', 'buttons/printfriendly-button-nobg.png', 'buttons/printfriendly-button-md.png', 'buttons/printfriendly-button-lg.png', // buttongroup3 'buttons/print-button.png', 'buttons/print-button-nobg.png', 'buttons/print-button-gray.png', // buttongroup3 'custom-button' // custom ) ) ) { $valid_input['button_type'] = 'buttons/printfriendly-button.png'; } if ( !isset( $input['custom_button_icon'] ) || !in_array( $input['custom_button_icon'], array( 'https://cdn.printfriendly.com/icons/printfriendly-icon-sm.png', 'https://cdn.printfriendly.com/icons/printfriendly-icon-md.png', 'https://cdn.printfriendly.com/icons/printfriendly-icon-lg.png', 'custom-image', 'no-image' ) ) ) { $valid_input['custom_button_icon'] = 'icons/printfriendly-icon-md.png'; } // @todo custom image url validation if ( !isset( $input['custom_image'] ) || empty( $input['custom_image'] ) ) $valid_input['custom_image'] = ''; if ( !isset( $input['custom_button_text'] ) ) { $valid_input['custom_button_text'] = 'custom-text'; } // @todo validate optional custom text if ( !isset( $input['custom_text'] ) ) { $valid_input['custom_text'] = 'Print Friendly'; } // Custom button selected, but no url nor text given, reset button type to default if( 'custom-button' === $valid_input['button_type'] && ( '' === $valid_input['custom_image'] && '' === $input['custom_text'] ) ) { $valid_input['button_type'] = 'buttons/printfriendly-button.png'; add_settings_error( $this->option_name, 'invalid_custom_image', __( 'No valid custom image url received, please enter a valid url to use a custom image.', $this->hook ) ); } $valid_input['text_size'] = (int) $input['text_size']; if ( !isset($valid_input['text_size']) || 0 == $valid_input['text_size'] ) { $valid_input['text_size'] = 14; } else if ( 25 < $valid_input['text_size'] || 9 > $valid_input['text_size'] ) { $valid_input['text_size'] = 14; add_settings_error( $this->option_name, 'invalid_text_size', __( 'The text size you entered is invalid, please stay between 9px and 25px', $this->hook ) ); } if ( !isset( $input['text_color'] )) { $valid_input['text_color'] = $this->options['text_color']; } else if ( ! preg_match('/^#[a-f0-9]{3,6}$/i', $input['text_color'] ) ) { // Revert to previous setting and throw error. $valid_input['text_color'] = $this->options['text_color']; add_settings_error( $this->option_name, 'invalid_color', __( 'The color you entered is not valid, it must be a valid hexadecimal RGB font color.', $this->hook ) ); } /* Section 2 options */ if ( !isset( $input['enable_css'] ) || 'off' !== $input['enable_css'] ) $valid_input['enable_css'] = 'on'; if ( !isset( $input['content_position'] ) || !in_array( $input['content_position'], array( 'none', 'left', 'center', 'right' ) ) ) $valid_input['content_position'] = 'left'; if ( !isset( $input['content_placement'] ) || !in_array( $input['content_placement'], array( 'before', 'after' ) ) ) $valid_input['content_placement'] = 'after'; foreach ( array( 'margin_top', 'margin_right', 'margin_bottom', 'margin_left' ) as $opt ) $valid_input[$opt] = (int) $input[$opt]; unset( $opt ); /* Section 3 options */ foreach ( array( 'show_on_posts', 'show_on_pages', 'show_on_homepage', 'show_on_categories', 'show_on_taxonomies' ) as $opt ) { if ( !isset( $input[$opt] ) || 'on' !== $input[$opt] ) { unset( $valid_input[$opt] ); } } unset( $opt ); // Just in case if( isset( $input['show_on_template'] ) ) unset( $valid_input['show_on_template'] ); if( isset( $input['category_ids'] ) ) { /** * Validate received category ids: * - Is there only one array item and does it contain the string text 'all' ? => pass * - Otherwise, make sure the ids are integer values */ /* $valid_input['category_ids'] = explode(',', $input['category_ids']); $valid_input['category_ids'] = array_map( 'trim', $valid_input['category_ids'] ); if( ( count( $valid_input['category_ids'] ) === 1 && 'all' === $valid_input['category_ids'][0] ) === false ) { foreach( $valid_input['category_ids'] as $k => $v ) { if( $v !== '' && ( ctype_digit( (string) $v ) === true && ( intval( $v ) == $v ) ) ) { $valid_input['category_ids'][$k] = intval( $v ); } else { // Invalid input - Show error message ? unset( $valid_input['category_ids'][$k] ); } } }*/ unset( $valid_input['category_ids'] ); } //echo '
'.print_r($input,1).'
'; //die; /* Section 4 options */ if ( !isset( $input['logo'] ) || !in_array( $input['logo'], array( 'favicon', 'upload-an-image' ) ) ) $valid_input['logo'] = 'favicon'; // @todo custom logo url validation if ( !isset( $input['image_url'] ) || empty( $input['image_url'] ) ) $valid_input['image_url'] = ''; // @todo validate optional tagline text if ( !isset( $input['tagline'] ) ) { $valid_input['tagline'] = ''; } /* else { }*/ // Custom logo selected, but no valid url given, reset logo to default if( 'upload-an-image' === $valid_input['logo'] && '' === $valid_input['image_url'] ) { $valid_input['logo'] = 'favicon'; add_settings_error( $this->option_name, 'invalid_custom_logo', __( 'No valid custom logo url received, please enter a valid url to use a custom logo.', $this->hook ) ); } if ( !isset( $input['image-style'] ) || !in_array( $input['image-style'], array( 'right', 'left', 'none', 'block' ) ) ) $valid_input['image-style'] = 'right'; foreach( array( 'click_to_delete', 'email', 'pdf', 'print', ) as $opt ) { if( !isset( $input[$opt] ) || !in_array( $input[$opt], array( '0', '1' ) ) ) { $valid_input[$opt] = '0'; } } unset( $opt ); if( !isset( $input['images-size'] ) || !in_array( $input['images-size'], array( 'full-size', 'remove-images', 'large', 'medium', 'small' ) ) ) { $valid_input['images-size'] = 'full-size'; } // @todo custom css url validation if ( !isset( $input['custom_css_url'] ) || empty( $input['custom_css_url'] ) ) $valid_input['custom_css_url'] = ''; /* Section 5 options */ if ( !isset( $input['password_protected'] ) || !in_array( $input['password_protected'], array( 'no', 'yes' ) ) ) $valid_input['password_protected'] = 'no'; if ( !isset( $input['javascript'] ) || !in_array( $input['javascript'], array( 'no', 'yes' ) ) ) $valid_input['javascript'] = 'yes'; /*Analytics Options */ if ( !isset( $input['enable_google_analytics'] ) || !in_array( $input['enable_google_analytics'], array( 'no', 'yes' ) ) ) { $valid_input['enable_google_analytics'] = "no"; } if ( !isset( $input['pf_algo'] ) || !in_array( $input['pf_algo'], array( 'wp', 'pf' ) ) ) { $valid_input['pf_algo'] = "wp"; } /* Database version */ $valid_input['db_version'] = $this->db_version; return $valid_input; } /** * Register the config page for all users that have the manage_options capability * * @since 3.0 */ function add_config_page() { try { $this->settings_page = add_options_page( __( 'PrintFriendly Options', $this->hook ), __( 'Print Friendly & PDF', $this->hook ), 'manage_options', $this->hook, array( &$this, 'config_page' ) ); //register callback gets call prior your own page gets rendered add_action('load-'.$this->settings_page, array(&$this, 'on_load_printfriendly')); } catch (Exception $e) { $this->raven_catch($e); } } /** * Shows help on the plugin page when clicking on the Help button, top right. * * @since 3.0 */ function contextual_help( $contextual_help, $screen_id ) { try { if ( $this->settings_page == $screen_id ) { $contextual_help = ''.__( "Need Help?", $this->hook ).'
' .sprintf( __( "Be sure to check out the %s!", $this->hook), ''.__( "Frequently Asked Questions", $this->hook ).'' ); } return $contextual_help; } catch (Exception $e) { $this->raven_catch($e); } } /** * Enqueue the scripts for the admin settings page * * @since 3.0 * @param string $hook_suffix hook to check against whether the current page is the PrintFriendly settings page. */ function admin_enqueue_scripts( $screen_id ) { try { if ( $this->settings_page == $screen_id ) { $ver = '3.2.5'; wp_register_script( 'pf-color-picker', plugins_url( 'colorpicker.js', __FILE__ ), array( 'jquery', 'media-upload' ), $ver ); wp_register_script( 'pf-admin-js', plugins_url( 'admin.js', __FILE__ ), array( 'jquery', 'media-upload' ), $ver ); wp_enqueue_script( 'pf-color-picker' ); wp_enqueue_script( 'pf-admin-js' ); wp_enqueue_style( 'printfriendly-admin-css', plugins_url( 'admin.css', __FILE__ ), array(), $ver); } } catch (Exception $e) { $this->raven_catch($e); } } /** * Register the settings link for the plugins page * * @since 3.0 * @param array $links the links for the plugins. * @param string $file filename to check against plugins filename. * @return array $links the links with the settings link added to it if appropriate. */ function filter_plugin_actions( $links, $file ){ try { // Static so we don't call plugin_basename on every plugin row. static $this_plugin; if ( ! $this_plugin ) $this_plugin = plugin_basename( __FILE__ ); if ( $file == $this_plugin ){ $settings_link = '' . __( 'Settings', $this->hook ) . ''; array_unshift( $links, $settings_link ); // before other links } return $links; } catch (Exception $e) { $this->raven_catch($e); } } /** * Set default values for the plugin. If old, as in pre 1.0, settings are there, use them and then delete them. * * @since 3.0 */ function set_defaults() { try { // Set some defaults $this->options = array( 'button_type' => 'buttons/printfriendly-button.png', 'content_position' => 'left', 'content_placement' => 'after', 'custom_button_icon' => 'https://cdn.printfriendly.com/icons/printfriendly-icon-md.png', 'custom_button_text' => 'custom-text', 'custom_image' => '', 'custom_text' => 'PrintFriendly', 'enable_css' => 'on', 'margin_top' => '12', 'margin_right' => '12', 'margin_bottom' => '12', 'margin_left' => '12', 'show_on_posts' => 'on', 'show_on_pages' => 'on', 'text_color' => '#3AAA11', 'text_size' => 14, 'logo' => 'favicon', 'image_url' => '', 'tagline' => '', 'click_to_delete' => '0', // 0 - allow, 1 - do not allow 'hide-images' => '0', // 0 - show images, 1 - hide images 'image-style' => 'right', // 'right', 'left', 'none', 'block' 'email' => '0', // 0 - allow, 1 - do not allow 'pdf' => '0', // 0 - allow, 1 - do not allow 'print' => '0', // 0 - allow, 1 - do not allow 'password_protected' => 'no', 'javascript' => 'yes', 'custom_css_url' => '', 'enable_google_analytics' => 'no', 'enable_error_reporting' => 'yes', 'pf_algo' => 'wp', 'images-size' => 'full-size' ); // Check whether the old badly named singular options are there, if so, use the data and delete them. foreach ( array_keys( $this->options ) as $opt ) { $old_opt = get_option( 'pf_'.$opt ); if ( $old_opt !== false ) { $this->options[$opt] = $old_opt; delete_option( 'pf_'.$opt ); } } // This should always be set to the latest immediately when defaults are pushed in. $this->options['db_version'] = $this->db_version; update_option( $this->option_name, $this->options ); } catch (Exception $e) { $this->raven_catch($e); } } /** * Upgrades the stored options, used to add new defaults if needed etc. * * @since 3.0 */ function upgrade() { // update options to version 2 if($this->options['db_version'] < 2) { $additional_options = array( 'enable_css' => 'on', 'logo' => 'favicon', 'image_url' => '', 'tagline' => '', 'click_to_delete' => '0', 'password_protected' => 'no', 'javascript' => 'yes' ); // use old javascript_include value to initialize javascript if(!isset($this->options['javascript_include'])) $additional_options['javascript'] = 'no'; unset($this->options['javascript_include']); unset($this->options['javascript_fallback']); // correcting badly named option if(isset($this->options['disable_css'])) { $additional_options['enable_css'] = $this->options['disable_css']; unset($this->options['disable_css']); } // check whether image we do not list any more was used if(in_array($this->options['button_type'], array('button-print-whgn20.png', 'pf_button_sq_qry_m.png', 'pf_button_sq_qry_l.png', 'pf_button_sq_grn_m.png', 'pf_button_sq_grn_l.png'))) { // previous version had a bug with button name if(in_array($this->options['button_type'], array('pf_button_sq_qry_m.png', 'pf_button_sq_qry_l.png'))) $this->options['button_type'] = str_replace('qry', 'gry', $this->options['button_type']); $image_address = 'https://cdn.printfriendly.com/'.$this->options['button_type']; $this->options['button_type'] = 'custom-image'; $this->options['custom_text'] = ''; $this->options['custom_image'] = $image_address; } $this->options = array_merge($this->options, $additional_options); } // update options to version 3 if($this->options['db_version'] < 3) { $old_show_on = $this->options['show_list']; // 'manual' setting $additional_options = array('custom_css_url' => ''); if($old_show_on == 'all') { $additional_options = array( 'show_on_pages' => 'on', 'show_on_posts' => 'on', 'show_on_homepage' => 'on', 'show_on_categories' => 'on', 'show_on_taxonomies' => 'on' ); } if($old_show_on == 'single') { $additional_options = array( 'show_on_pages' => 'on', 'show_on_posts' => 'on' ); } if($old_show_on == 'posts') { $additional_options = array( 'show_on_posts' => 'on', ); } unset($this->options['show_list']); $this->options = array_merge($this->options, $additional_options); } // update options to version 4 if($this->options['db_version'] < 4) { $additional_options = array( 'email' => '0', 'pdf' => '0', 'print' => '0', ); $this->options = array_merge($this->options, $additional_options); } // update options to version 6 // Replacement for db version 5 - should also be run for those already upgraded if($this->options['db_version'] < 6) { unset($this->options['category_ids']); } if($this->options['db_version'] < 7) { $additional_options = array( 'hide-images' => '0', 'image-style' => 'right', ); $this->options = array_merge($this->options, $additional_options); } if($this->options['db_version'] < 8) { $this->options['enable_google_analytics'] = 'no'; } if($this->options['db_version'] < 9) { $this->options['pf_algo'] = 'wp'; } if($this->options['db_version'] < 10) { $this->options['enable_error_reporting'] = 'yes'; } if($this->options['db_version'] < 11) { if (!isset($this->options['custom_css_url'])) { $this->options['custom_css_url'] = ''; } } if($this->options['db_version'] < 12) { $this->options['images-size'] = $this->options['hide-images'] == '1' ? 'remove-images' : 'full-size'; } if ($this->options['db_version'] < 13) { switch ($this->options['button_type']) { case 'pf-button.gif': $this->options['button_type'] = 'buttons/printfriendly-button.png'; break; case 'pf-button-both.gif': $this->options['button_type'] = 'buttons/printfriendly-pdf-button.png'; break; case 'pf-button-big.gif': $this->options['button_type'] = 'buttons/printfriendly-button-lg.png'; break; case 'pf-button-print-pdf-mail.png': $this->options['button_type'] = 'buttons/printfriendly-pdf-email-button-notext.png'; break; case 'button-print-grnw20.png': $this->options['button_type'] = 'buttons/print-button.png'; break; case 'button-print-blu20.png': $this->options['button_type'] = 'buttons/print-button-nobg.png'; break; case 'button-print-gry20.png': $this->options['button_type'] = 'buttons/print-button-gray.png'; break; case 'pf-icon-small.gif': case 'pf-icon.gif': $this->options['button_type'] = 'custom-button'; $this->options['custom_button_icon'] = 'icons/printfriendly-icon-md.png'; $this->options['custom_button_text'] = 'custom-text'; $this->options['custom_image'] = 'icons/printfriendly-icon-md.png'; break; case 'text-only': $this->options['button_type'] = 'custom-button'; $this->options['custom_button_icon'] = 'no-image'; $this->options['custom_button_text'] = 'custom-text'; break; } } if ($this->options['db_version'] < 14) { if ($this->options['button_type'] == 'pf-icon-both.gif') { $this->options['button_type'] = 'buttons/printfriendly-pdf-button-nobg.png'; } } if ($this->options['db_version'] < 15) { if ($this->options['button_type'] == 'custom-image') { $this->options['button_type'] = 'custom-button'; switch ($this->options['custom_image']) { case 'icons/printfriendly-icon-sm.png': case 'icons/printfriendly-icon-md.png': case 'icons/printfriendly-icon-lg.png': $this->options['custom_button_icon'] = $this->options['custom_image']; break; case '': $this->options['custom_button_icon'] = 'no-image'; break; default: $this->options['custom_button_icon'] = 'custom-image'; } if ($this->options['custom_text'] == '') { $this->options['custom_button_text'] = 'no-text'; } else { $this->options['custom_button_text'] = 'custom-text'; } } } $this->options['db_version'] = $this->db_version; update_option( $this->option_name, $this->options ); } /** * Displays radio button in the admin area * * @since 3.0 * @param string $name the name of the radio button to generate. * @param boolean $br whether or not to add an HTML
tag, defaults to true. */ function radio($name, $br = false){ $var = 'checked( 'button_type', $name, false ).'/>'; $button = $this->button( $name ); if ( '' != $button ) echo ''; else echo $var; if ( $br ) echo '
'; } /** * Displays radio button in the admin area * * @since 3.12.0 * @param string $name the name of the radio button to generate. */ function radio_custom_image($value){ ?> options['button_type']; $button_css = $this->generic_button_css(); $img_path = 'https://cdn.printfriendly.com/'; if ($name == "custom-button") { if ($this->options['custom_button_icon'] == 'custom-image') { if( '' == trim($this->options['custom_image']) ) $return = ''; else $return = 'Print Friendly'; } else if ( $this->options['custom_button_icon'] != 'no-image' ) { $return = 'Print Friendly'; } /* esc_html was removerd to support custom html, CSRF prevents from attack by using this field */ if ($this->options['custom_button_text'] == 'custom-text') { $return .= $this->options['custom_text']; } return $return; } else { return 'Print Friendly'; } } /** * * **/ function generic_button_css() { return "border:none;-webkit-box-shadow:none; box-shadow:none;"; } /** * Convenience function to output a value custom button preview elements * * @since 3.0.9 */ function custom_button_preview() { if( $this->options['custom_button_icon'] == 'no-image' ) { $button_preview = ''; } else if ($this->options['custom_button_icon'] == 'custom-image') { $button_preview = 'Print Friendly'; } else { $button_preview = 'Print Friendly'; } if ($this->options['custom_button_text'] != 'no-text') { $button_text = $this->options['custom_text']; } else { $button_text = ''; } $button_preview .= ''.esc_html($button_text).''; echo $button_preview; } /** * Convenience function to output a value for an input * * @since 3.0 * @param string $val value to check. */ function val( $val ) { if ( isset( $this->options[$val] ) ) echo esc_attr( $this->options[$val] ); } /** * Like the WordPress checked() function but it doesn't throw notices when the array key isn't set and uses the plugins options array. * * @since 3.0 * @param mixed $val value to check. * @param mixed $check_against value to check against. * @param boolean $echo whether or not to echo the output. * @return string checked, when true, empty, when false. */ function checked( $val, $check_against = true, $echo = true ) { if ( !isset( $this->options[$val] ) ) return; if ( $this->options[$val] == $check_against ) { if ( $echo ) echo ' checked="checked" '; else return ' checked="checked" '; } } /** * Helper for creating checkboxes. * * @since 3.1.5 * @param string $name string used for various parts of checkbox * */ function create_checkbox($name, $label='', $labelid='' ) { $label = ( !empty( $label) ? $label : __( ucfirst($name), $this->hook ) ); echo 'checked( 'show_on_' . $name, 'on'); echo ' />' . $label . "\r\n"; } /** * Helper that checks if any of the content types is checked to display pf button. * * @since 3.1.5 * @return boolean true if none of the content types is checked * */ function is_manual() { try { return !(isset($this->options['show_on_posts']) || isset($this->options['show_on_pages']) || isset($this->options['show_on_homepage']) || isset($this->options['show_on_categories']) || // (isset($this->options['category_ids']) && count($this->options['category_ids']) > 0) || isset($this->options['show_on_taxonomies'])); } catch (Exception $e) { $this->raven_catch($e); } } /** * Like the WordPress selected() function but it doesn't throw notices when the array key isn't set and uses the plugins options array. * * @since 3.0.9 * @param mixed $val value to check. * @param mixed $check_against value to check against. * @return string checked, when true, empty, when false. */ function selected( $val, $check_against = true) { if ( !isset( $this->options[$val] ) ) return; return selected ($this->options[$val], $check_against); } /** * For use with page metabox. * * @since 3.2.2 */ function get_page_post_type() { $post_types = get_post_types( array( 'name' => 'page' ), 'object' ); //echo '
'.print_r($post_types,1).'
'; //die; return $post_types['page']; } /** * Helper that checks if wp versions is above 3.0. * * @since 3.2.2 * @return boolean true wp version is above 3.0 * */ function wp_version_gt30() { global $wp_version; return version_compare($wp_version, '3.0', '>='); } /** * Create box for picking individual categories. * * @since 3.2.2 */ function create_category_metabox() { $obj = new stdClass(); $obj->ID = 0; do_meta_boxes('settings_page_' . $this->hook, 'normal', $obj); } /** * Load metaboxes advanced button display settings. * * @since 3.2.2 */ function on_load_printfriendly() { global $wp_version; if($this->wp_version_gt30()) { require_once('includes/meta-boxes.php'); //require_once('includes/nav-menu.php'); wp_enqueue_script('post'); add_meta_box('categorydiv', __('Only display when post is in:', $this->hook), 'post_categories_meta_box', 'settings_page_'. $this->hook, 'normal', 'core'); } } function console_log( $data ) { echo ''; } /** * Output the config page * * @since 3.0 */ function config_page() { // Since WP 3.2 outputs these errors by default, only display them when we're on versions older than 3.2 that do support the settings errors. global $wp_version; if(version_compare($wp_version, '3.2', '<' ) && $this->wp_version_gt30() ) settings_errors(); // Show the content of the options array when debug is enabled if ( WP_DEBUG ) { echo "

" . __( 'Currently in Debug Mode. Following information is visible in debug mode only:', $this->hook ) . "

"; echo '
' . __( 'Options:', $this->hook ) . '

' . print_r( $this->options, 1 ) . '
'; } ?>

hook ); ?>

option_name ); ?>

hook ); ?>

radio('buttons/printfriendly-pdf-email-button.png'); ?> radio('buttons/printfriendly-pdf-email-button-md.png'); ?> radio('buttons/printfriendly-pdf-email-button-notext.png'); ?>
radio('buttons/printfriendly-pdf-button.png'); ?> radio('buttons/printfriendly-pdf-button-nobg.png'); ?> radio('buttons/printfriendly-pdf-button-nobg-md.png'); ?>
radio('buttons/printfriendly-button.png'); ?> radio('buttons/printfriendly-button-nobg.png'); ?> radio('buttons/printfriendly-button-md.png'); ?> radio('buttons/printfriendly-button-lg.png'); ?>
radio('buttons/print-button.png'); ?> radio('buttons/print-button-nobg.png'); ?> radio('buttons/print-button-gray.png'); ?>

Image


radio_custom_image('https://cdn.printfriendly.com/icons/printfriendly-icon-sm.png'); ?> radio_custom_image('https://cdn.printfriendly.com/icons/printfriendly-icon-md.png'); ?> radio_custom_image('https://cdn.printfriendly.com/icons/printfriendly-icon-lg.png'); ?>

Text

hook ); ?>
hook ); ?>

Preview

custom_button_preview(); ?>

hook ); ?> checked('enable_css', 'off'); ?> />Do not use CSS for button styles

>
>

hook ); ?>

create_checkbox('posts', __( 'Posts', $this->hook )); ?> create_checkbox('pages', __( 'Pages', $this->hook )); ?> create_checkbox('homepage', __( 'Homepage', $this->hook )); ?> create_checkbox('categories', __( 'Category Pages', $this->hook )); ?> create_checkbox('taxonomies', __( 'Taxonomy Pages', $this->hook )); ?> >hook ); ?> class="code" rows="2" cols="40">[printfriendly] option_name; ?>[category_ids]" id="category_ids" value="options['category_ids']); ? >" /> */ ?>
wp_version_gt30()) { ? >

Additional filter', $this->hook), ' href="javascript:void(0)" id="toggle-categories"' ); ?>

create_category_metabox(); ?>

*/ ?>

hook ); ?>

hook ); ?>"/> hook ); ?>"/>

PrintFriendly please leave us a %s rating. A huge thanks in advance!', 'printfriendly' ), '★★★★★' ), $this->hook ); ?>

hook ); ?> PrintFriendly Pro.

hook ); ?> support@PrintFriendly.com

getButton(true); }