PluginProbe
Print, PDF & Email by PrintFriendly / 3.12.0
Print, PDF & Email by PrintFriendly v3.12.0
5.5.13 5.5.12 5.5.11 trunk 0.2 0.9 1.0 2.0 2.1.8 3.0 3.0.9 3.1.6 3.10.0 3.11.0 3.11.1 3.11.2 3.12.0 3.12.1 3.12.2 3.12.3 3.12.4 3.12.5 3.13.0 3.14.0 3.14.1 All 95 releases
printfriendly / pf.php

pf.php in Print, PDF & Email by PrintFriendly 3.12.0, at pf.php

1,724 lines 72.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /*
4 Plugin Name: Print, PDF & Email by PrintFriendly
5 Plugin URI: http://www.printfriendly.com
6 Description: PrintFriendly & PDF button for your website. Optimizes your pages and brand for print, pdf, and email.
7 Name and URL are included to ensure repeat visitors and new visitors when printed versions are shared.
8 Version: 3.12.0
9 Author: Print, PDF, & Email by PrintFriendly
10 Author URI: http://www.PrintFriendly.com
11
12 Changelog :
13 3.12.0 - Update custom button UI
14 3.11.2 - Fix button upgrade for pf-icon-both.gif
15 3.11.1 - Bug fix
16 3.11.0 - Update buttons
17 3.10.0 - Change "leave us a rating" message.
18 3.9.2 - Correctly handle spaces in print-only detection
19 3.9.1 - Better print-only detection
20 3.9.0 - Add new button
21 3.8.7 - Bug fix.
22 3.8.6 - Allow default image setting to be small medium or large.
23 3.8.5 - Bug fix.
24 3.8.4 - Bug fix.
25 3.8.1 - Improve automatic error reporting.
26 3.8.0 - Add automatic error reporting.
27 3.7.6 - WooCommerce support improvments: remove upsells from print preview.
28 3.7.5 - WooCommerce support improvments: fix DOMDocument.loadHTML warnings.
29 3.7.4 - Added CSS Relative Position and Z-Index to button to avoid content covering the button.
30 3.7.3 - Always use https
31 3.7.2 - Use schema less URLs for loading icons
32 3.7.1 - Use www.printfriendly.com instead of app.printfriendly.com for redirects
33 3.7.0 - Remove http/https option, use current schema
34 3.6.0 - Allow custom HTML in Custom Button Text
35 3.5.4 - WooCommerce 'Content Algorithm' fix
36 3.5.3 - Fix security issues
37 3.5.2 - Fix code to support PHP 5.2
38 3.5.0 - WooCommerce product page improvements. Better support for product images, price, and description.
39 3.4.8 - Fix button images style
40 3.4.7 - Fix button style to remove underline
41 3.4.6 - Always removed PrintFriendly button underline regardless plugin CSS for button styles option
42 3.4.4 - Removed page content selection option - Wordpress Standard/Strict
43 3.4.2 - Fixed the issue occured due to new changes made in the page content selection options
44 3.4.1 - Improved page content selection options
45 3.4.0 - Fixed the admin javascript error and increased plugin text boxes size
46 3.3.10 - Implemented both Classic Google Analytics and Google Universal Analytics code.
47 3.3.9 - Removed the functionality that opens new window when JavaScript is disabled.
48 3.3.8 - Shortcode Bug fix, urlencode button href
49 3.3.7 - Readme.txt update
50 3.3.6 - Fixed JS optimization Bug
51 3.3.5 - Wordpress 3.8 support
52 3.3.4 - Provided Algorithm Options
53 3.3.3 - Using WP content hook for all Buttons
54 3.3.2 - Algorithm update
55 3.3.1 - SSL support issue.
56 3.3.0 - Printfriendly custom commands support and PF Algo V6 release.
57 3.2.10 - Fixed Bug.
58 3.2.9 - Added Support for Google Analytics
59 3.2.8 - Algorithm Update
60 3.2.7 - Removed Break tag from button code.
61 3.2.6 - Fixed Button behavior when displayed on Homepage for NON-JS version. Fixed CSS issue with Button when placed above content. Fixed box-shadow issue with button. Custom print and pdf options now available for Non-JS version (custom header, custom css, image alignment, etc.). Fixed custom header bug.
62 3.2.5 - Added hide images and image style options. Improved input validation. Improved output escaping. Removed printfriendly post_class. Small i8n fix. Few small HTML fixes.
63 3.2.4 - Add printfriendly post_class. Fixed minor JS bug. Added redundancy to uninstall script.
64 3.2.3 - Rolling back to version 3.2.1
65 3.2.2 - Add printfriendly post_class. Add printfriendly button display settings per individual category. Fixed minor JS bug. Added redundancy to uninstall script.
66 3.2.1 - Improve script loading.
67 3.2.0 - Important chrome issue fix. Ie syntax error fix.
68 3.1.9 - Minor css detail.
69 3.1.8 - Add printfriendly options to allow/not allow print, pdf, email from the Printfriendly and PDF dialog.
70 3.1.7 - Revert default print button show settings. Prevent easy override of print button text-decoration and border style properties.
71 3.1.6 - Adding PrintFriendly and PDF alignment style classes.
72 3.1.5 - Set button appearance in more flexible way. Remove styles that interfered with wordpress themes. Add shortcode for printfriendly button. Fix redirect to printfriendly.com link. Added custom css feature.
73 3.1.4 - Changed https url. Don't hide text change box when disabling css.
74 3.1.3 - Fixed bug with disable css option
75 3.1.2 - Added disable css option to admin settings.
76 3.1.1 - Fixed admin js caching.
77 3.1.0 - Fixed admin css caching.
78 3.0.9 - New features: Custom header, disable click-to-delete, https support (beta), PrintFriendly Pro (ad-free).
79 3.0.8 - Reordered PrintFriendly & PDF buttons. CSS stylesheet option is now checked by default.
80 3.0.7 - Added additional images for print button.
81 3.0.6 - Fix bug that would display button on category pages when not wanted.
82 3.0.5 - Include button on category pages if user has selected "All pages".
83 3.0.4 - Align-right and align-center support for themes that remove WordPress core css.
84 3.0.3 - Support for bad themes that alter template tags and prevent JavaScript from loading in footer.
85 3.0.2 - Fixed JS bug with Google Chrome not submitting and fixed input validation issues.
86 3.0.1 - Fixed minor JS bug.
87 3.0 - Complete overhaul of the plugin by Joost de Valk.
88 2.1.8 - The Print Button was showing up on printed, or PDF, pages. Junk! Print or PDF button no longer displayed on printed out page or PDF.
89 2.1.7 - Changed button from span to div to support floating.
90 2.1.6 - Added rel="nofollow" to links. Changed button from <a> to <span> to fix target_new or target_blank issues.
91 2.1.5 - Fix conflict with link tracking plugins. Custom image support for hosted wordpress sites.
92 2.1.4 - wp head fix.
93 2.1.3 - Manual option for button placement. Security updates for multi-author sites.
94 2.1.2 - Improvements to Setting page layout and PrintFriendly button launching from post pages.
95 2.1.1 - Fixed admin settings bug.
96 2.1 - Update for mult-author websites. Improvements to Settings page.
97 2.0 - Customize the style, placement, and pages your printfriendly button appears.
98 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.
99 1.4 - Changed Name.
100 1.3 - Added new buttons, removed redundant code.
101 1.2 - User can choose to show or not show buttons on the listing page.
102 */
103
104 /**
105 * PrintFriendly WordPress plugin. Allows easy embedding of printfriendly.com buttons.
106 * @package PrintFriendly_WordPress
107 * @author PrintFriendly <support@printfriendly.com>
108 * @copyright Copyright (C) 2012, PrintFriendly
109 */
110 if ( ! class_exists( 'PrintFriendly_WordPress' ) ) {
111
112 /**
113 * Class containing all the plugins functionality.
114 * @package PrintFriendly_WordPress
115 */
116 class PrintFriendly_WordPress {
117 /**
118 * Current plugin version.
119 * @var string
120 */
121 var $plugin_version = '3.12.0';
122
123 /**
124 * The hook, used for text domain as well as hooks on pages and in get requests for admin.
125 * @var string
126 */
127 var $hook = 'printfriendly';
128
129 /**
130 * The option name, used throughout to refer to the plugins option and option group.
131 * @var string
132 */
133 var $option_name = 'printfriendly_option';
134
135 /**
136 * The plugins options, loaded on init containing all the plugins settings.
137 * @var array
138 */
139 var $options = array();
140
141 /**
142 * Database version, used to allow for easy upgrades to / additions in plugin options between plugin versions.
143 * @var int
144 */
145 var $db_version = 15;
146
147 /**
148 * Settings page, used within the plugin to reliably load the plugins admin JS and CSS files only on the admin page.
149 * @var string
150 */
151 var $settings_page = '';
152
153 /**
154 * GetSentry error reporting client
155 * @var Raven_Client
156 */
157 var $raven_client = null;
158
159 /**
160 * Constructor
161 *
162 * @since 3.0
163 */
164 function __construct() {
165 try {
166 // delete_option( $this->option_name );
167
168 // Retrieve the plugin options
169 $this->options = get_option( $this->option_name );
170
171 // If the options array is empty, set defaults
172 if ( ! is_array( $this->options ) )
173 $this->set_defaults();
174
175 // Sentry PHP SDK supports PHP 5.3 and higher.
176 if( isset( $this->options['enable_error_reporting'] ) && $this->options['enable_error_reporting'] == 'yes' && version_compare(PHP_VERSION, '5.3.0') >= 0) {
177 $this->init_error_reporting();
178 }
179
180 /**
181 * Set page content selection option "Wordpress Standard/Strict" to "WP Template"
182 */
183 if( isset( $this->options['pf_algo'] ) && $this->options['pf_algo'] == 'ws' ){
184 $this->options['pf_algo'] = 'wp';
185 update_option( $this->option_name, $this->options );
186 }
187
188 // If the version number doesn't match, upgrade
189 if ( $this->db_version > $this->options['db_version'] )
190 $this->upgrade();
191
192 add_action( 'wp_head', array( &$this, 'front_head' ) );
193 // automaticaly add the link
194 if( !$this->is_manual() ) {
195 add_filter( 'the_content', array( &$this, 'show_link' ) );
196 add_filter( 'the_excerpt', array( &$this, 'show_link' ) );
197 }
198
199 add_action('the_content', array(&$this, 'add_pf_content_class_around_content_hook'));
200
201 // Admin hooks
202 if ( is_admin() ) {
203 // Hook into init for registration of the option and the language files
204 add_action( 'admin_init', array( &$this, 'init' ) );
205
206 // Register the settings page
207 add_action( 'admin_menu', array( &$this, 'add_config_page' ) );
208
209 // Register the contextual help
210 add_filter( 'contextual_help', array( &$this, 'contextual_help' ), 10, 2 );
211
212 // Enqueue the needed scripts and styles
213 add_action( 'admin_enqueue_scripts',array( &$this, 'admin_enqueue_scripts' ) );
214
215 // Register a link to the settings page on the plugins overview page
216 add_filter( 'plugin_action_links', array( &$this, 'filter_plugin_actions' ), 10, 2 );
217 }
218 } catch(Exception $e) {
219 $this->raven_catch($e);
220 }
221 }
222
223 function init_error_reporting() {
224 try {
225 require_once 'vendor/PrintFriendly/Raven/Autoloader.php';
226
227 PrintFriendly_Raven_Autoloader::register();
228
229 $this->raven_client = new PrintFriendly_Raven_Client('https://46a55182ffbe477c8cf1cb0f1cee36c2:a32ee5b4fad940c4808845b618147f21@sentry.io/171161', array(
230 'release' => $this->plugin_version,
231 'timeout' => 4
232 ));
233
234 $this->raven_client->tags_context(array(
235 'wordpress-version' => get_bloginfo('version'),
236 'php-version' => PHP_VERSION
237 ));
238
239 $this->raven_client->setSendCallback(array( &$this, 'raven_callback' ));
240 } catch (Exception $e) {
241 if (!ini_get('display_errors')) {
242 error_log('PrintFriendly init_error_reporting Error: ' . $e);
243 }
244
245 $this->raven_catch($e);
246 }
247 }
248
249 function raven_callback($data) {
250 try {
251 return isset($data) && preg_match('/printfriendly/', json_encode($data));
252 } catch (Exception $e) {
253 return true;
254 }
255 }
256
257 function raven_catch($e) {
258 if (isset($this->raven_client)) {
259 try {
260 $this->raven_client->captureException($e);
261 } catch(Exception $e) {}
262 }
263 }
264
265 /**
266 * Adds wraps content in pf-content class to help Printfriendly algo determine the content
267 *
268 * @since 3.2.8
269 *
270 **/
271 function add_pf_content_class_around_content_hook($content = false) {
272 try {
273 if( $this->is_wp_algo_on($content) ) {
274 add_action( 'wp_footer', array( &$this, 'print_script_footer' ));
275 return '<div class="pf-content">'.$content.'</div>';
276 } else {
277 return $content;
278 }
279 } catch (Exception $e) {
280 $this->raven_catch($e);
281 }
282 }
283
284 /**
285 * Override to check if print-only command is being used
286 *
287 * @since 3.3.0
288 **/
289 function print_only_override($content) {
290 $pattern = '/class\s*?=\s*?(["\']|["\']([^"\']*?)\s)print-only(["\']|\s([^"\']*?)["\'])/';
291 $pf_pattern = '/class\s*?=\s*?(["\']|["\']([^"\']*?)\s)pf-content(["\']|\s([^"\']*?)["\'])/';
292
293 return (preg_match($pattern, $content) || preg_match($pf_pattern, $content)) ;
294 }
295
296 /**
297 * Check if WP Algorithm is selected and content doesn't use print-only
298 *
299 * @since 3.5.4
300 **/
301 function is_wp_algo_on($content) {
302 return !class_exists('WooCommerce') && isset($this->options['pf_algo']) && $content && $this->options['pf_algo'] == 'wp' && !$this->print_only_override($content);
303 }
304
305 /**
306 * PHP 4 Compatible Constructor
307 *
308 * @since 3.0
309 */
310 function PrintFriendly_WordPress() {
311 $this->__construct();
312 }
313
314 /**
315 * Prints the PrintFriendly button CSS, in the header.
316 *
317 * @since 3.0
318 */
319 function front_head() {
320 try {
321 ?>
322 <style type="text/css" media="screen">
323 div.printfriendly a, div.printfriendly a:link, div.printfriendly a:hover, div.printfriendly a:visited {
324 text-decoration: none;
325 border: none;
326 }
327 </style>
328 <?php
329
330 if ( isset( $this->options['enable_css'] ) && $this->options['enable_css'] != 'on' )
331 return;
332 ?>
333 <style type="text/css" media="screen">
334 div.printfriendly {
335 margin: <?php echo $this->options['margin_top'].'px '.$this->options['margin_right'].'px '.$this->options['margin_bottom'].'px '.$this->options['margin_left'].'px'; ?>;
336 position: relative;
337 z-index: 1000;
338 }
339 div.printfriendly a, div.printfriendly a:link, div.printfriendly a:visited {
340 font-size: <?php echo $this->options['text_size']; ?>px;
341 color: <?php echo $this->options['text_color']; ?>;
342 vertical-align: bottom;
343 }
344 .printfriendly a {
345 box-shadow:none;
346 }
347 .printfriendly a:hover {
348 cursor: pointer;
349 }
350 .printfriendly a img {
351 border: none;
352 padding:0;
353 margin-right: 6px;
354 box-shadow: none;
355 -webkit-box-shadow: none;
356 -moz-box-shadow: none;
357 }
358 .printfriendly a span{
359 vertical-align: bottom;
360 }
361 .pf-alignleft {
362 float: left;
363 }
364 .pf-alignright {
365 float: right;
366 }
367 div.pf-aligncenter {
368 display: block;
369 margin-left: auto;
370 margin-right: auto;
371 text-align: center;
372 }
373 </style>
374 <style type="text/css" media="print">
375 .printfriendly {
376 display: none;
377 }
378 </style>
379 <?php
380 } catch (Exception $e) {
381 $this->raven_catch($e);
382 }
383 }
384
385 /**
386 * Prints the PrintFriendly JavaScript, in the footer, and loads it asynchronously.
387 *
388 * @since 3.0
389 */
390 function print_script_footer() {
391 if (isset($this->options['javascript']) && $this->options['javascript'] == 'no')
392 return;
393
394 else {
395 $tagline = $this->options['tagline'];
396 $image_url = $this->options['image_url'];
397 if( $this->options['logo'] == 'favicon' ) {
398 $tagline = '';
399 $image_url = '';
400 }
401
402 // Currently we use v3 for both: normal and password protected sites
403 ?>
404 <script type="text/javascript">
405
406 var pfHeaderImgUrl = '<?php echo esc_js(esc_url($image_url)); ?>';
407 var pfHeaderTagline = '<?php echo esc_js($tagline); ?>';
408 var pfdisableClickToDel = '<?php echo esc_js($this->options['click_to_delete']); ?>';
409 var pfImagesSize = '<?php echo esc_js($this->options['images-size']); ?>';
410 var pfImageDisplayStyle = '<?php echo esc_js($this->options['image-style']); ?>';
411 var pfDisableEmail = '<?php echo esc_js($this->options['email']); ?>';
412 var pfDisablePDF = '<?php echo esc_js($this->options['pdf']); ?>';
413 var pfDisablePrint = '<?php echo esc_js($this->options['print']); ?>';
414 var pfCustomCSS = '<?php echo esc_js(esc_url($this->options['custom_css_url'])); ?>';
415 (function() {
416 var e = document.createElement('script'); e.type="text/javascript";
417 e.src = 'https://cdn.printfriendly.com/printfriendly.js';
418 document.getElementsByTagName('head')[0].appendChild(e);
419 })();
420 </script>
421 <?php
422 }
423 }
424
425 /**
426 * Primary frontend function, used either as a filter for the_content, or directly using pf_show_link
427 *
428 * @since 3.0
429 * @param string $content the content of the post, when the function is used as a filter
430 * @return string $button or $content with the button added to the content when appropriate, just the content when button shouldn't be added or just button when called manually.
431 */
432 function show_link( $content = false ) {
433 try {
434 $is_manual = $this->is_manual();
435
436 if( !$content && !$is_manual )
437 return "";
438
439 $button = $this->getButton();
440 if ( $is_manual )
441 {
442 // Hook the script call now, so it only get's loaded when needed, and need is determined by the user calling pf_button
443 add_action( 'wp_footer', array( &$this, 'print_script_footer' ) );
444 return $button;
445 }
446
447 else
448 {
449 if ( (is_page() && ( isset($this->options['show_on_pages']) && 'on' === $this->options['show_on_pages'] ) )
450 || (is_home() && ( ( isset($this->options['show_on_homepage']) && 'on' === $this->options['show_on_homepage'] ) && $this->category_included() ) )
451 || (is_tax() && ( ( isset($this->options['show_on_taxonomies']) && 'on' === $this->options['show_on_taxonomies'] ) && $this->category_included() ) )
452 || (is_category() && ( ( isset($this->options['show_on_categories']) && 'on' === $this->options['show_on_categories'] ) && $this->category_included() ) )
453 || (is_single() && ( ( isset($this->options['show_on_posts']) && 'on' === $this->options['show_on_posts'] ) && $this->category_included() ) ) )
454 {
455 // Hook the script call now, so it only get's loaded when needed, and need is determined by the user calling pf_button
456 add_action( 'wp_footer', array( &$this, 'print_script_footer' ) );
457
458 if ( $this->options['content_placement'] == 'before' )
459 return $button.$content;
460 else
461 return $content.$button;
462 }
463 else
464 {
465 return $content;
466 }
467 }
468 } catch (Exception $e) {
469 $this->raven_catch($e);
470 }
471 }
472
473
474 /**
475 * @since 3.3.8
476 * @returns Printfriendly Button HTML
477 */
478
479 function getButton($add_footer_script = false) {
480 if($add_footer_script) {
481 add_action( 'wp_footer', array( &$this, 'print_script_footer' ) );
482 }
483 $js_enabled = $this->js_enabled();
484 $analytics_code = "";
485 $onclick = '';
486
487 if ( $this->google_analytics_enabled() ) {
488 $title_var = "NULL";
489 $analytics_code = "if(typeof(_gaq) != 'undefined') { _gaq.push(['_trackEvent','PRINTFRIENDLY', 'print', '".$title_var."']);
490 }else if(typeof(ga) != 'undefined') { ga('send', 'event','PRINTFRIENDLY', 'print', '".$title_var."'); }";
491 if( $js_enabled ) {
492 $onclick = 'onclick="window.print();'. $analytics_code .' return false;"';
493 } else {
494 $onclick = '';
495 }
496 } else if ( $js_enabled ) {
497 $onclick = 'onclick="window.print(); return false;"';
498 }
499
500 if( $js_enabled ){
501 $href = '#';
502 } else {
503 $href = 'https://www.printfriendly.com/print?url='.urlencode(get_permalink());
504 }
505
506 if (!$js_enabled) {
507 if($this->google_analytics_enabled()) {
508 $onclick = $onclick.' onclick="'.$analytics_code.'"';
509 }
510 $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";
511 }
512 if ( !is_singular() && '' != $onclick && $js_enabled) {
513 $onclick = '';
514 $href = add_query_arg('pfstyle','wp',get_permalink());
515 }
516
517 $align = '';
518 if ( 'none' != $this->options['content_position'] )
519 $align = ' pf-align'.$this->options['content_position'];
520 $href = str_replace("&", "&amp;", $href );
521 $button = apply_filters( 'printfriendly_button', '<div class="printfriendly'.$align.'"><a href="'.$href.'" rel="nofollow" '.$onclick.' class="noslimstat">'.$this->button().'</a></div>' );
522 return $button;
523 }
524
525
526 /**
527 * @since 3.2.9
528 * @returns if google analytics enabled
529 */
530 function google_analytics_enabled() {
531 return isset( $this->options['enable_google_analytics'] ) && $this->options['enable_google_analytics'] == 'yes';
532 }
533 /**
534 * @since 3.2.6
535 * @return boolean true if JS is enabled for the plugin
536 **/
537 function js_enabled() {
538 return isset( $this->options['javascript'] ) && $this->options['javascript'] == 'yes';
539 }
540
541 /**
542 * Filter posts by category.
543 *
544 * @since 3.2.2
545 * @return boolean true if post belongs to category selected for button display
546 */
547 function category_included() {
548 // return ( 'all' === $this->options['category_ids'][0] || in_category($this->options['category_ids']) );
549 return true;
550 }
551
552 /**
553 * Register the textdomain and the options array along with the validation function
554 *
555 * @since 3.0
556 */
557 function init() {
558 try {
559 // Allow for localization
560 load_plugin_textdomain( $this->hook, false, basename( dirname( __FILE__ ) ) . '/languages' );
561
562 // Register our option array
563 register_setting( $this->option_name, $this->option_name, array( &$this, 'options_validate' ) );
564 } catch (Exception $e) {
565 $this->raven_catch($e);
566 }
567 }
568
569 /**
570 * Validate the saved options.
571 *
572 * @since 3.0
573 * @param array $input with unvalidated options.
574 * @return array $valid_input with validated options.
575 */
576 function options_validate( $input ) {
577 // Prevent CSRF attack
578 check_admin_referer( 'pf-options', 'pf-nonce' );
579
580 $valid_input = $input;
581
582 // Section 1 options
583 if ( !isset( $input['button_type'] ) || !in_array( $input['button_type'], array(
584 'buttons/printfriendly-pdf-email-button.png',
585 'buttons/printfriendly-pdf-email-button-md.png',
586 'buttons/printfriendly-pdf-email-button-notext.png', // buttongroup1
587 'buttons/printfriendly-pdf-button.png',
588 'buttons/printfriendly-pdf-button-nobg.png',
589 'buttons/printfriendly-pdf-button-nobg-md.png', // buttongroup2
590 'buttons/printfriendly-button.png',
591 'buttons/printfriendly-button-nobg.png',
592 'buttons/printfriendly-button-md.png',
593 'buttons/printfriendly-button-lg.png', // buttongroup3
594 'buttons/print-button.png',
595 'buttons/print-button-nobg.png',
596 'buttons/print-button-gray.png', // buttongroup3
597 'custom-button' // custom
598 ) ) ) {
599 $valid_input['button_type'] = 'buttons/printfriendly-button.png';
600 }
601
602 if ( !isset( $input['custom_button_icon'] ) || !in_array( $input['custom_button_icon'], array(
603 'https://cdn.printfriendly.com/icons/printfriendly-icon-sm.png',
604 'https://cdn.printfriendly.com/icons/printfriendly-icon-md.png',
605 'https://cdn.printfriendly.com/icons/printfriendly-icon-lg.png',
606 'custom-image',
607 'no-image'
608 ) ) ) {
609 $valid_input['custom_button_icon'] = 'icons/printfriendly-icon-md.png';
610 }
611
612 // @todo custom image url validation
613 if ( !isset( $input['custom_image'] ) || empty( $input['custom_image'] ) )
614 $valid_input['custom_image'] = '';
615
616 if ( !isset( $input['custom_button_text'] ) ) {
617 $valid_input['custom_button_text'] = 'custom-text';
618 }
619
620 // @todo validate optional custom text
621 if ( !isset( $input['custom_text'] ) ) {
622 $valid_input['custom_text'] = 'Print Friendly';
623 }
624
625 // Custom button selected, but no url nor text given, reset button type to default
626 if( 'custom-button' === $valid_input['button_type'] && ( '' === $valid_input['custom_image'] && '' === $input['custom_text'] ) ) {
627 $valid_input['button_type'] = 'buttons/printfriendly-button.png';
628 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 ) );
629 }
630
631
632 $valid_input['text_size'] = (int) $input['text_size'];
633 if ( !isset($valid_input['text_size']) || 0 == $valid_input['text_size'] ) {
634 $valid_input['text_size'] = 14;
635 } else if ( 25 < $valid_input['text_size'] || 9 > $valid_input['text_size'] ) {
636 $valid_input['text_size'] = 14;
637 add_settings_error( $this->option_name, 'invalid_text_size', __( 'The text size you entered is invalid, please stay between 9px and 25px', $this->hook ) );
638 }
639
640 if ( !isset( $input['text_color'] )) {
641 $valid_input['text_color'] = $this->options['text_color'];
642 } else if ( ! preg_match('/^#[a-f0-9]{3,6}$/i', $input['text_color'] ) ) {
643 // Revert to previous setting and throw error.
644 $valid_input['text_color'] = $this->options['text_color'];
645 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 ) );
646 }
647
648
649
650 /* Section 2 options */
651 if ( !isset( $input['enable_css'] ) || 'off' !== $input['enable_css'] )
652 $valid_input['enable_css'] = 'on';
653
654 if ( !isset( $input['content_position'] ) || !in_array( $input['content_position'], array( 'none', 'left', 'center', 'right' ) ) )
655 $valid_input['content_position'] = 'left';
656
657 if ( !isset( $input['content_placement'] ) || !in_array( $input['content_placement'], array( 'before', 'after' ) ) )
658 $valid_input['content_placement'] = 'after';
659
660 foreach ( array( 'margin_top', 'margin_right', 'margin_bottom', 'margin_left' ) as $opt )
661 $valid_input[$opt] = (int) $input[$opt];
662
663 unset( $opt );
664
665
666 /* Section 3 options */
667 foreach ( array( 'show_on_posts', 'show_on_pages', 'show_on_homepage', 'show_on_categories', 'show_on_taxonomies' ) as $opt ) {
668 if ( !isset( $input[$opt] ) || 'on' !== $input[$opt] ) {
669 unset( $valid_input[$opt] );
670 }
671 }
672 unset( $opt );
673
674 // Just in case
675 if( isset( $input['show_on_template'] ) )
676 unset( $valid_input['show_on_template'] );
677
678
679 if( isset( $input['category_ids'] ) ) {
680 /**
681 * Validate received category ids:
682 * - Is there only one array item and does it contain the string text 'all' ? => pass
683 * - Otherwise, make sure the ids are integer values
684 */
685 /* $valid_input['category_ids'] = explode(',', $input['category_ids']);
686 $valid_input['category_ids'] = array_map( 'trim', $valid_input['category_ids'] );
687 if( ( count( $valid_input['category_ids'] ) === 1 && 'all' === $valid_input['category_ids'][0] ) === false ) {
688 foreach( $valid_input['category_ids'] as $k => $v ) {
689 if( $v !== '' && ( ctype_digit( (string) $v ) === true && ( intval( $v ) == $v ) ) ) {
690 $valid_input['category_ids'][$k] = intval( $v );
691 }
692 else {
693 // Invalid input - Show error message ?
694 unset( $valid_input['category_ids'][$k] );
695 }
696 }
697 }*/
698 unset( $valid_input['category_ids'] );
699 }
700
701 //echo '<pre>'.print_r($input,1).'</pre>';
702 //die;
703
704
705
706 /* Section 4 options */
707 if ( !isset( $input['logo'] ) || !in_array( $input['logo'], array( 'favicon', 'upload-an-image' ) ) )
708 $valid_input['logo'] = 'favicon';
709
710 // @todo custom logo url validation
711 if ( !isset( $input['image_url'] ) || empty( $input['image_url'] ) )
712 $valid_input['image_url'] = '';
713
714 // @todo validate optional tagline text
715 if ( !isset( $input['tagline'] ) ) {
716 $valid_input['tagline'] = '';
717 }
718 /* else {
719
720 }*/
721
722 // Custom logo selected, but no valid url given, reset logo to default
723 if( 'upload-an-image' === $valid_input['logo'] && '' === $valid_input['image_url'] ) {
724 $valid_input['logo'] = 'favicon';
725 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 ) );
726 }
727
728
729 if ( !isset( $input['image-style'] ) || !in_array( $input['image-style'], array( 'right', 'left', 'none', 'block' ) ) )
730 $valid_input['image-style'] = 'right';
731
732
733 foreach( array( 'click_to_delete', 'email', 'pdf', 'print', ) as $opt ) {
734 if( !isset( $input[$opt] ) || !in_array( $input[$opt], array( '0', '1' ) ) ) {
735 $valid_input[$opt] = '0';
736 }
737 }
738 unset( $opt );
739
740 if( !isset( $input['images-size'] ) || !in_array( $input['images-size'], array( 'full-size', 'remove-images', 'large', 'medium', 'small' ) ) ) {
741 $valid_input['images-size'] = 'full-size';
742 }
743
744 // @todo custom css url validation
745 if ( !isset( $input['custom_css_url'] ) || empty( $input['custom_css_url'] ) )
746 $valid_input['custom_css_url'] = '';
747
748
749
750 /* Section 5 options */
751 if ( !isset( $input['password_protected'] ) || !in_array( $input['password_protected'], array( 'no', 'yes' ) ) )
752 $valid_input['password_protected'] = 'no';
753
754 if ( !isset( $input['javascript'] ) || !in_array( $input['javascript'], array( 'no', 'yes' ) ) )
755 $valid_input['javascript'] = 'yes';
756
757 /*Analytics Options */
758 if ( !isset( $input['enable_google_analytics'] ) || !in_array( $input['enable_google_analytics'], array( 'no', 'yes' ) ) ) {
759 $valid_input['enable_google_analytics'] = "no";
760 }
761
762 if ( !isset( $input['pf_algo'] ) || !in_array( $input['pf_algo'], array( 'wp', 'pf' ) ) ) {
763 $valid_input['pf_algo'] = "wp";
764 }
765
766 /* Database version */
767 $valid_input['db_version'] = $this->db_version;
768
769 return $valid_input;
770 }
771
772 /**
773 * Register the config page for all users that have the manage_options capability
774 *
775 * @since 3.0
776 */
777 function add_config_page() {
778 try {
779 $this->settings_page = add_options_page( __( 'PrintFriendly Options', $this->hook ), __( 'Print Friendly & PDF', $this->hook ), 'manage_options', $this->hook, array( &$this, 'config_page' ) );
780
781 //register callback gets call prior your own page gets rendered
782 add_action('load-'.$this->settings_page, array(&$this, 'on_load_printfriendly'));
783 } catch (Exception $e) {
784 $this->raven_catch($e);
785 }
786 }
787
788 /**
789 * Shows help on the plugin page when clicking on the Help button, top right.
790 *
791 * @since 3.0
792 */
793 function contextual_help( $contextual_help, $screen_id ) {
794 try {
795 if ( $this->settings_page == $screen_id ) {
796 $contextual_help = '<strong>'.__( "Need Help?", $this->hook ).'</strong><br/>'
797 .sprintf( __( "Be sure to check out the %s!", $this->hook), '<a href="https://wordpress.org/extend/plugins/printfriendly/faq/">'.__( "Frequently Asked Questions", $this->hook ).'</a>' );
798 }
799 return $contextual_help;
800 } catch (Exception $e) {
801 $this->raven_catch($e);
802 }
803 }
804
805 /**
806 * Enqueue the scripts for the admin settings page
807 *
808 * @since 3.0
809 * @param string $hook_suffix hook to check against whether the current page is the PrintFriendly settings page.
810 */
811 function admin_enqueue_scripts( $screen_id ) {
812 try {
813 if ( $this->settings_page == $screen_id ) {
814 $ver = '3.2.5';
815 wp_register_script( 'pf-color-picker', plugins_url( 'colorpicker.js', __FILE__ ), array( 'jquery', 'media-upload' ), $ver );
816 wp_register_script( 'pf-admin-js', plugins_url( 'admin.js', __FILE__ ), array( 'jquery', 'media-upload' ), $ver );
817
818 wp_enqueue_script( 'pf-color-picker' );
819 wp_enqueue_script( 'pf-admin-js' );
820
821
822 wp_enqueue_style( 'printfriendly-admin-css', plugins_url( 'admin.css', __FILE__ ), array(), $ver);
823 }
824 } catch (Exception $e) {
825 $this->raven_catch($e);
826 }
827 }
828
829 /**
830 * Register the settings link for the plugins page
831 *
832 * @since 3.0
833 * @param array $links the links for the plugins.
834 * @param string $file filename to check against plugins filename.
835 * @return array $links the links with the settings link added to it if appropriate.
836 */
837 function filter_plugin_actions( $links, $file ){
838 try {
839 // Static so we don't call plugin_basename on every plugin row.
840 static $this_plugin;
841 if ( ! $this_plugin ) $this_plugin = plugin_basename( __FILE__ );
842
843 if ( $file == $this_plugin ){
844 $settings_link = '<a href="options-general.php?page='.$this->hook.'">' . __( 'Settings', $this->hook ) . '</a>';
845 array_unshift( $links, $settings_link ); // before other links
846 }
847
848 return $links;
849 } catch (Exception $e) {
850 $this->raven_catch($e);
851 }
852 }
853
854 /**
855 * Set default values for the plugin. If old, as in pre 1.0, settings are there, use them and then delete them.
856 *
857 * @since 3.0
858 */
859 function set_defaults() {
860 try {
861 // Set some defaults
862 $this->options = array(
863 'button_type' => 'buttons/printfriendly-button.png',
864 'content_position' => 'left',
865 'content_placement' => 'after',
866 'custom_button_icon' => 'https://cdn.printfriendly.com/icons/printfriendly-icon-md.png',
867 'custom_button_text' => 'custom-text',
868 'custom_image' => '',
869 'custom_text' => 'PrintFriendly',
870 'enable_css' => 'on',
871 'margin_top' => '12',
872 'margin_right' => '12',
873 'margin_bottom' => '12',
874 'margin_left' => '12',
875 'show_on_posts' => 'on',
876 'show_on_pages' => 'on',
877 'text_color' => '#3AAA11',
878 'text_size' => 14,
879 'logo' => 'favicon',
880 'image_url' => '',
881 'tagline' => '',
882 'click_to_delete' => '0', // 0 - allow, 1 - do not allow
883 'hide-images' => '0', // 0 - show images, 1 - hide images
884 'image-style' => 'right', // 'right', 'left', 'none', 'block'
885 'email' => '0', // 0 - allow, 1 - do not allow
886 'pdf' => '0', // 0 - allow, 1 - do not allow
887 'print' => '0', // 0 - allow, 1 - do not allow
888 'password_protected' => 'no',
889 'javascript' => 'yes',
890 'custom_css_url' => '',
891 'enable_google_analytics' => 'no',
892 'enable_error_reporting' => 'yes',
893 'pf_algo' => 'wp',
894 'images-size' => 'full-size'
895 );
896
897 // Check whether the old badly named singular options are there, if so, use the data and delete them.
898 foreach ( array_keys( $this->options ) as $opt ) {
899 $old_opt = get_option( 'pf_'.$opt );
900 if ( $old_opt !== false ) {
901 $this->options[$opt] = $old_opt;
902 delete_option( 'pf_'.$opt );
903 }
904 }
905
906 // This should always be set to the latest immediately when defaults are pushed in.
907 $this->options['db_version'] = $this->db_version;
908
909 update_option( $this->option_name, $this->options );
910 } catch (Exception $e) {
911 $this->raven_catch($e);
912 }
913 }
914
915 /**
916 * Upgrades the stored options, used to add new defaults if needed etc.
917 *
918 * @since 3.0
919 */
920 function upgrade() {
921 // update options to version 2
922 if($this->options['db_version'] < 2) {
923
924 $additional_options = array(
925 'enable_css' => 'on',
926 'logo' => 'favicon',
927 'image_url' => '',
928 'tagline' => '',
929 'click_to_delete' => '0',
930 'password_protected' => 'no',
931 'javascript' => 'yes'
932 );
933
934 // use old javascript_include value to initialize javascript
935 if(!isset($this->options['javascript_include']))
936 $additional_options['javascript'] = 'no';
937
938 unset($this->options['javascript_include']);
939 unset($this->options['javascript_fallback']);
940
941 // correcting badly named option
942 if(isset($this->options['disable_css'])) {
943 $additional_options['enable_css'] = $this->options['disable_css'];
944 unset($this->options['disable_css']);
945 }
946
947 // check whether image we do not list any more was used
948 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'))) {
949 // previous version had a bug with button name
950 if(in_array($this->options['button_type'], array('pf_button_sq_qry_m.png', 'pf_button_sq_qry_l.png')))
951 $this->options['button_type'] = str_replace('qry', 'gry', $this->options['button_type']);
952
953 $image_address = 'https://cdn.printfriendly.com/'.$this->options['button_type'];
954 $this->options['button_type'] = 'custom-image';
955 $this->options['custom_text'] = '';
956 $this->options['custom_image'] = $image_address;
957 }
958
959 $this->options = array_merge($this->options, $additional_options);
960 }
961
962 // update options to version 3
963 if($this->options['db_version'] < 3) {
964
965 $old_show_on = $this->options['show_list'];
966 // 'manual' setting
967 $additional_options = array('custom_css_url' => '');
968
969 if($old_show_on == 'all') {
970 $additional_options = array(
971 'show_on_pages' => 'on',
972 'show_on_posts' => 'on',
973 'show_on_homepage' => 'on',
974 'show_on_categories' => 'on',
975 'show_on_taxonomies' => 'on'
976 );
977 }
978
979 if($old_show_on == 'single') {
980 $additional_options = array(
981 'show_on_pages' => 'on',
982 'show_on_posts' => 'on'
983 );
984 }
985
986 if($old_show_on == 'posts') {
987 $additional_options = array(
988 'show_on_posts' => 'on',
989 );
990 }
991
992 unset($this->options['show_list']);
993
994 $this->options = array_merge($this->options, $additional_options);
995 }
996
997 // update options to version 4
998 if($this->options['db_version'] < 4) {
999
1000 $additional_options = array(
1001 'email' => '0',
1002 'pdf' => '0',
1003 'print' => '0',
1004 );
1005
1006 $this->options = array_merge($this->options, $additional_options);
1007 }
1008
1009 // update options to version 6
1010 // Replacement for db version 5 - should also be run for those already upgraded
1011 if($this->options['db_version'] < 6) {
1012 unset($this->options['category_ids']);
1013 }
1014
1015 if($this->options['db_version'] < 7) {
1016 $additional_options = array(
1017 'hide-images' => '0',
1018 'image-style' => 'right',
1019 );
1020
1021 $this->options = array_merge($this->options, $additional_options);
1022 }
1023
1024 if($this->options['db_version'] < 8) {
1025 $this->options['enable_google_analytics'] = 'no';
1026 }
1027
1028 if($this->options['db_version'] < 9) {
1029 $this->options['pf_algo'] = 'wp';
1030 }
1031
1032 if($this->options['db_version'] < 10) {
1033 $this->options['enable_error_reporting'] = 'yes';
1034 }
1035
1036 if($this->options['db_version'] < 11) {
1037 if (!isset($this->options['custom_css_url'])) {
1038 $this->options['custom_css_url'] = '';
1039 }
1040 }
1041
1042 if($this->options['db_version'] < 12) {
1043 $this->options['images-size'] = $this->options['hide-images'] == '1' ? 'remove-images' : 'full-size';
1044 }
1045
1046 if ($this->options['db_version'] < 13) {
1047 switch ($this->options['button_type']) {
1048 case 'pf-button.gif':
1049 $this->options['button_type'] = 'buttons/printfriendly-button.png';
1050 break;
1051 case 'pf-button-both.gif':
1052 $this->options['button_type'] = 'buttons/printfriendly-pdf-button.png';
1053 break;
1054 case 'pf-button-big.gif':
1055 $this->options['button_type'] = 'buttons/printfriendly-button-lg.png';
1056 break;
1057 case 'pf-button-print-pdf-mail.png':
1058 $this->options['button_type'] = 'buttons/printfriendly-pdf-email-button-notext.png';
1059 break;
1060 case 'button-print-grnw20.png':
1061 $this->options['button_type'] = 'buttons/print-button.png';
1062 break;
1063 case 'button-print-blu20.png':
1064 $this->options['button_type'] = 'buttons/print-button-nobg.png';
1065 break;
1066 case 'button-print-gry20.png':
1067 $this->options['button_type'] = 'buttons/print-button-gray.png';
1068 break;
1069 case 'pf-icon-small.gif':
1070 case 'pf-icon.gif':
1071 $this->options['button_type'] = 'custom-button';
1072 $this->options['custom_button_icon'] = 'icons/printfriendly-icon-md.png';
1073 $this->options['custom_button_text'] = 'custom-text';
1074 $this->options['custom_image'] = 'icons/printfriendly-icon-md.png';
1075 break;
1076 case 'text-only':
1077 $this->options['button_type'] = 'custom-button';
1078 $this->options['custom_button_icon'] = 'no-image';
1079 $this->options['custom_button_text'] = 'custom-text';
1080 break;
1081 }
1082 }
1083
1084 if ($this->options['db_version'] < 14) {
1085 if ($this->options['button_type'] == 'pf-icon-both.gif') {
1086 $this->options['button_type'] = 'buttons/printfriendly-pdf-button-nobg.png';
1087 }
1088 }
1089
1090 if ($this->options['db_version'] < 15) {
1091 if ($this->options['button_type'] == 'custom-image') {
1092 $this->options['button_type'] = 'custom-button';
1093
1094 switch ($this->options['custom_image']) {
1095 case 'icons/printfriendly-icon-sm.png':
1096 case 'icons/printfriendly-icon-md.png':
1097 case 'icons/printfriendly-icon-lg.png':
1098 $this->options['custom_button_icon'] = $this->options['custom_image'];
1099 break;
1100 case '':
1101 $this->options['custom_button_icon'] = 'no-image';
1102 break;
1103 default:
1104 $this->options['custom_button_icon'] = 'custom-image';
1105 }
1106
1107 if ($this->options['custom_text'] == '') {
1108 $this->options['custom_button_text'] = 'no-text';
1109 } else {
1110 $this->options['custom_button_text'] = 'custom-text';
1111 }
1112 }
1113 }
1114
1115 $this->options['db_version'] = $this->db_version;
1116
1117 update_option( $this->option_name, $this->options );
1118 }
1119
1120 /**
1121 * Displays radio button in the admin area
1122 *
1123 * @since 3.0
1124 * @param string $name the name of the radio button to generate.
1125 * @param boolean $br whether or not to add an HTML <br> tag, defaults to true.
1126 */
1127 function radio($name, $br = false){
1128 $var = '<input id="'.$name.'" class="radio" name="'.$this->option_name.'[button_type]" type="radio" value="'.$name.'" '.$this->checked( 'button_type', $name, false ).'/>';
1129 $button = $this->button( $name );
1130 if ( '' != $button )
1131 echo '<label for="'.$name.'">' . $var . $button . '</label>';
1132 else
1133 echo $var;
1134
1135 if ( $br )
1136 echo '<br>';
1137 }
1138
1139 /**
1140 * Displays radio button in the admin area
1141 *
1142 * @since 3.12.0
1143 * @param string $name the name of the radio button to generate.
1144 */
1145 function radio_custom_image($value){
1146 ?>
1147 <label class="radio-custom-btn">
1148 <input type="radio" name="<?php echo $this->option_name ?>[custom_button_icon]" value="<?php echo $value ?>" <?php $this->checked( 'custom_button_icon', $value ) ?>>
1149 <img src="<?php echo $value ?>" alt="Print Friendly" style="display: inline" />
1150 </label>
1151 <?php
1152 }
1153
1154 /**
1155 * Displays button image in the admin area
1156 *
1157 * @since 3.0
1158 * @param string $name the name of the button to generate.
1159 */
1160 function button( $name = false ){
1161 if( !$name )
1162 $name = $this->options['button_type'];
1163
1164 $button_css = $this->generic_button_css();
1165
1166 $img_path = 'https://cdn.printfriendly.com/';
1167
1168 if ($name == "custom-button") {
1169 if ($this->options['custom_button_icon'] == 'custom-image') {
1170 if( '' == trim($this->options['custom_image']) )
1171 $return = '';
1172 else
1173 $return = '<img src="'.esc_url($this->options['custom_image']).'" alt="Print Friendly" style="display: inline" />';
1174 } else if ( $this->options['custom_button_icon'] != 'no-image' ) {
1175 $return = '<img src="'.esc_url($this->options['custom_button_icon']).'" alt="Print Friendly" style="display: inline" />';
1176 }
1177
1178 /* esc_html was removerd to support custom html, CSRF prevents from attack by using this field */
1179 if ($this->options['custom_button_text'] == 'custom-text') {
1180 $return .= $this->options['custom_text'];
1181 }
1182
1183 return $return;
1184 } else {
1185 return '<img style="'.$button_css.'" src="'.$img_path.$name.'" alt="Print Friendly" />';
1186 }
1187 }
1188
1189 /**
1190 *
1191 *
1192 **/
1193
1194 function generic_button_css() {
1195 return "border:none;-webkit-box-shadow:none; box-shadow:none;";
1196 }
1197
1198
1199 /**
1200 * Convenience function to output a value custom button preview elements
1201 *
1202 * @since 3.0.9
1203 */
1204 function custom_button_preview() {
1205 if( $this->options['custom_button_icon'] == 'no-image' ) {
1206 $button_preview = '<span id="pf-custom-button-preview"></span>';
1207 } else if ($this->options['custom_button_icon'] == 'custom-image') {
1208 $button_preview = '<span id="pf-custom-button-preview"><img src="'.esc_url($this->options['custom_image']).'" alt="Print Friendly" /></span>';
1209 } else {
1210 $button_preview = '<span id="pf-custom-button-preview"><img src="'.esc_url($this->options['custom_button_icon']).'" alt="Print Friendly" /></span>';
1211 }
1212
1213 if ($this->options['custom_button_text'] != 'no-text') {
1214 $button_text = $this->options['custom_text'];
1215 } else {
1216 $button_text = '';
1217 }
1218
1219 $button_preview .= '<span class="printfriendly-text2">'.esc_html($button_text).'</span>';
1220
1221 echo $button_preview;
1222 }
1223
1224 /**
1225 * Convenience function to output a value for an input
1226 *
1227 * @since 3.0
1228 * @param string $val value to check.
1229 */
1230 function val( $val ) {
1231 if ( isset( $this->options[$val] ) )
1232 echo esc_attr( $this->options[$val] );
1233 }
1234
1235 /**
1236 * Like the WordPress checked() function but it doesn't throw notices when the array key isn't set and uses the plugins options array.
1237 *
1238 * @since 3.0
1239 * @param mixed $val value to check.
1240 * @param mixed $check_against value to check against.
1241 * @param boolean $echo whether or not to echo the output.
1242 * @return string checked, when true, empty, when false.
1243 */
1244 function checked( $val, $check_against = true, $echo = true ) {
1245 if ( !isset( $this->options[$val] ) )
1246 return;
1247
1248 if ( $this->options[$val] == $check_against ) {
1249 if ( $echo )
1250 echo ' checked="checked" ';
1251 else
1252 return ' checked="checked" ';
1253 }
1254 }
1255
1256 /**
1257 * Helper for creating checkboxes.
1258 *
1259 * @since 3.1.5
1260 * @param string $name string used for various parts of checkbox
1261 *
1262 */
1263 function create_checkbox($name, $label='', $labelid='' ) {
1264 $label = ( !empty( $label) ? $label : __( ucfirst($name), $this->hook ) );
1265 echo '<label' . ( !empty( $labelid ) ? ' id=' . $labelid : '' ) . '><input type="checkbox" class="show_list" name="' . $this->option_name . '[show_on_' . $name . ']" value="on" ';
1266 $this->checked( 'show_on_' . $name, 'on');
1267 echo ' />' . $label . "</label>\r\n";
1268 }
1269
1270
1271 /**
1272 * Helper that checks if any of the content types is checked to display pf button.
1273 *
1274 * @since 3.1.5
1275 * @return boolean true if none of the content types is checked
1276 *
1277 */
1278 function is_manual() {
1279 try {
1280 return !(isset($this->options['show_on_posts']) ||
1281 isset($this->options['show_on_pages']) ||
1282 isset($this->options['show_on_homepage']) ||
1283 isset($this->options['show_on_categories']) ||
1284 // (isset($this->options['category_ids']) && count($this->options['category_ids']) > 0) ||
1285 isset($this->options['show_on_taxonomies']));
1286 } catch (Exception $e) {
1287 $this->raven_catch($e);
1288 }
1289 }
1290
1291
1292 /**
1293 * Like the WordPress selected() function but it doesn't throw notices when the array key isn't set and uses the plugins options array.
1294 *
1295 * @since 3.0.9
1296 * @param mixed $val value to check.
1297 * @param mixed $check_against value to check against.
1298 * @return string checked, when true, empty, when false.
1299 */
1300 function selected( $val, $check_against = true) {
1301 if ( !isset( $this->options[$val] ) )
1302 return;
1303
1304 return selected ($this->options[$val], $check_against);
1305 }
1306
1307 /**
1308 * For use with page metabox.
1309 *
1310 * @since 3.2.2
1311 */
1312 function get_page_post_type() {
1313 $post_types = get_post_types( array( 'name' => 'page' ), 'object' );
1314 //echo '<pre>'.print_r($post_types,1).'</pre>';
1315 //die;
1316
1317 return $post_types['page'];
1318 }
1319
1320
1321 /**
1322 * Helper that checks if wp versions is above 3.0.
1323 *
1324 * @since 3.2.2
1325 * @return boolean true wp version is above 3.0
1326 *
1327 */
1328 function wp_version_gt30() {
1329 global $wp_version;
1330 return version_compare($wp_version, '3.0', '>=');
1331 }
1332
1333
1334 /**
1335 * Create box for picking individual categories.
1336 *
1337 * @since 3.2.2
1338 */
1339 function create_category_metabox() {
1340 $obj = new stdClass();
1341 $obj->ID = 0;
1342 do_meta_boxes('settings_page_' . $this->hook, 'normal', $obj);
1343 }
1344
1345
1346 /**
1347 * Load metaboxes advanced button display settings.
1348 *
1349 * @since 3.2.2
1350 */
1351 function on_load_printfriendly() {
1352 global $wp_version;
1353 if($this->wp_version_gt30()) {
1354 require_once('includes/meta-boxes.php');
1355 //require_once('includes/nav-menu.php');
1356 wp_enqueue_script('post');
1357
1358 add_meta_box('categorydiv', __('Only display when post is in:', $this->hook), 'post_categories_meta_box', 'settings_page_'. $this->hook, 'normal', 'core');
1359 }
1360 }
1361
1362 function console_log( $data ) {
1363 echo '<script>';
1364 echo 'console.log(' . json_encode( $data ) . ')';
1365 echo '</script>';
1366 }
1367
1368 /**
1369 * Output the config page
1370 *
1371 * @since 3.0
1372 */
1373 function config_page() {
1374
1375
1376 // 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.
1377 global $wp_version;
1378 if(version_compare($wp_version, '3.2', '<' ) && $this->wp_version_gt30() )
1379 settings_errors();
1380
1381 // Show the content of the options array when debug is enabled
1382 if ( WP_DEBUG ) {
1383 echo "<p>" . __( 'Currently in Debug Mode. Following information is visible in debug mode only:', $this->hook ) . "</p>";
1384 echo '<pre>' . __( 'Options:', $this->hook ) . '<br><br>' . print_r( $this->options, 1 ) . '</pre>';
1385 }
1386 ?>
1387
1388 <style type="text/css">
1389 input[type="radio"], img {
1390 vertical-align: middle;
1391 }
1392 </style>
1393
1394 <div id="pf_settings" class="wrap">
1395
1396 <div class="icon32" id="printfriendly"></div>
1397 <h2><?php _e( 'Print Friendly & PDF Settings', $this->hook ); ?></h2>
1398
1399 <form action="options.php" method="post">
1400 <?php wp_nonce_field( 'pf-options', 'pf-nonce' ); ?>
1401 <?php settings_fields( $this->option_name ); ?>
1402
1403 <h3><?php _e( "Pick Your Button Style", $this->hook ); ?></h3>
1404
1405 <fieldset id="button-style">
1406 <div id="buttongroup1">
1407 <?php $this->radio('buttons/printfriendly-pdf-email-button.png'); ?>
1408 <?php $this->radio('buttons/printfriendly-pdf-email-button-md.png'); ?>
1409 <?php $this->radio('buttons/printfriendly-pdf-email-button-notext.png'); ?>
1410 </div>
1411 <div id="buttongroup2">
1412 <?php $this->radio('buttons/printfriendly-pdf-button.png'); ?>
1413 <?php $this->radio('buttons/printfriendly-pdf-button-nobg.png'); ?>
1414 <?php $this->radio('buttons/printfriendly-pdf-button-nobg-md.png'); ?>
1415 </div>
1416 <div id="buttongroup3">
1417 <?php $this->radio('buttons/printfriendly-button.png'); ?>
1418 <?php $this->radio('buttons/printfriendly-button-nobg.png'); ?>
1419 <?php $this->radio('buttons/printfriendly-button-md.png'); ?>
1420 <?php $this->radio('buttons/printfriendly-button-lg.png'); ?>
1421 </div>
1422 <div id="buttongroup4">
1423 <?php $this->radio('buttons/print-button.png'); ?>
1424 <?php $this->radio('buttons/print-button-nobg.png'); ?>
1425 <?php $this->radio('buttons/print-button-gray.png'); ?>
1426 </div>
1427
1428 <div id="custom-btn-group" class="clear">
1429 <label>
1430 <?php echo '<input id="custom-btn" class="radio" name="'.$this->option_name.'[button_type]" type="radio" value="custom-button" '.$this->checked( 'button_type', 'custom-button', false ).'/>'; ?>
1431 <?php _e( "Custom Button", $this->hook ); ?>
1432 </label>
1433
1434 <div id="custom-img" style="float: left;">
1435 <h2>Image</h2><br>
1436 <?php $this->radio_custom_image('https://cdn.printfriendly.com/icons/printfriendly-icon-sm.png'); ?>
1437 <?php $this->radio_custom_image('https://cdn.printfriendly.com/icons/printfriendly-icon-md.png'); ?>
1438 <?php $this->radio_custom_image('https://cdn.printfriendly.com/icons/printfriendly-icon-lg.png'); ?>
1439
1440 <label class="radio-custom-btn">
1441 <input id="custom-image-rb" type="radio" name="<?php echo $this->option_name ?>[custom_button_icon]" value="custom-image" <?php $this->checked( 'custom_button_icon', 'custom-image'); ?>>
1442 <b>Use Your Image</b>
1443 <div id="enter-image-url" style="margin: 10px 0 0 30px">
1444 Enter Image URL<br>
1445 <input id="custom_image" type="text" class="clear regular-text" name="<?php echo $this->option_name; ?>[custom_image]" value="<?php $this->val( 'custom_image' ); ?>" />
1446 <div id="pf-custom-button-error"></div>
1447 <div class="description"><?php _e( "Ex: https://www.example.com/<br>Ex: /wp/wp-content/uploads/example.png", $this->hook ); ?>
1448 </div>
1449 </div>
1450 </label>
1451
1452 <label class="radio-custom-btn">
1453 <input type="radio" name="<?php echo $this->option_name ?>[custom_button_icon]" value="no-image" <?php $this->checked( 'custom_button_icon', 'no-image'); ?>>
1454 <b>No Image</b>
1455 </label>
1456 </div>
1457
1458 <div id="custom-txt" style="float: left;">
1459 <h2>Text</h2>
1460 <div id="txt-enter">
1461 <label>
1462 <input id="custom-text-rb" type="radio" name="<?php echo $this->option_name; ?>[custom_button_text]" value="custom-text" <?php $this->checked( 'custom_button_text', 'custom-text'); ?>>
1463 <input type="text" size="10" class="clear regular-text" name="<?php echo $this->option_name; ?>[custom_text]" id="custom_text" value="<?php $this->val( 'custom_text' ); ?>">
1464 </label>
1465 <label>
1466 <input type="radio" name="<?php echo $this->option_name; ?>[custom_button_text]" value="no-text" <?php $this->checked( 'custom_button_text', 'no-text'); ?>>
1467 <b>No Text</b>
1468 </label>
1469 </div>
1470 <div>
1471 <div id="txt-color">
1472 <?php _e( "Text Color", $this->hook ); ?>
1473 <input type="hidden" name="<?php echo $this->option_name; ?>[text_color]" id="text_color" value="<?php $this->val( 'text_color' ); ?>"/><br>
1474 <div id="colorSelector">
1475 <div style="background-color: <?php echo $this->options['text_color']; ?>;"></div>
1476 </div>
1477 </div>
1478 <div id="txt-size">
1479 <?php _e( "Text Size", $this->hook ); ?><br>
1480 <input type="number" id="text_size" min="9" max="25" class="small-text" name="<?php echo $this->option_name; ?>[text_size]" value="<?php $this->val( 'text_size' ); ?>"/>
1481 </div>
1482 </div>
1483 </div>
1484
1485 <div id="custom-button-preview" style="float: left;">
1486 <h2>Preview</h2>
1487 <?php $this->custom_button_preview(); ?>
1488 </div>
1489 </div>
1490 </fieldset>
1491 <br class="clear">
1492
1493 <!--Section 2 Button Positioning-->
1494 <div id="button-positioning">
1495 <h3><?php _e( "Button Positioning", $this->hook ); ?>
1496 <span id="css"><input type="checkbox" name="<?php echo $this->option_name; ?>[enable_css]" value="<?php $this->val('enable_css');?>" <?php $this->checked('enable_css', 'off'); ?> />Do not use CSS for button styles</span>
1497 </h3>
1498 <div id="button-positioning-options">
1499 <div id="alignment">
1500 <label<?php /*for="pf_content_position"*/ ?>>
1501 <select id="pf_content_position" name="<?php echo $this->option_name; ?>[content_position]" >
1502 <option value="left" <?php selected( $this->options['content_position'], 'left' ); ?>><?php _e( "Left Align", $this->hook ); ?></option>
1503 <option value="right" <?php selected( $this->options['content_position'], 'right' ); ?>><?php _e( "Right Align", $this->hook ); ?></option>
1504 <option value="center" <?php selected( $this->options['content_position'], 'center' ); ?>><?php _e( "Center", $this->hook ); ?></option>
1505 <option value="none" <?php selected( $this->options['content_position'], 'none' ); ?>><?php _e( "None", $this->hook ); ?></option>
1506 </select>
1507 </label>
1508 </div>
1509 <div class="content_placement">
1510 <label<?php /* for="pf_content_placement"*/ ?>>
1511 <select id="pf_content_placement" name="<?php echo $this->option_name; ?>[content_placement]" >
1512 <option value="before" <?php selected( $this->options['content_placement'], 'before' ); ?>><?php _e( "Above Content", $this->hook ); ?></option>
1513 <option value="after" <?php selected( $this->options['content_placement'], 'after' ); ?>><?php _e( "Below Content", $this->hook ); ?></option>
1514 </select>
1515 </label>
1516 </div>
1517 <div id="margin">
1518 <label for="pf-margin_left">
1519 <input type="number" name="<?php echo $this->option_name; ?>[margin_left]" id="pf-margin_left" value="<?php $this->val( 'margin_left' ); ?>" maxlength="3"/>
1520 <?php _e( "Margin Left", $this->hook ); ?>
1521 </label>
1522 <label for="pf-margin_right">
1523 <input type="number" name="<?php echo $this->option_name; ?>[margin_right]" id="pf-margin_right" value="<?php $this->val( 'margin_right' ); ?>"/> <?php _e( "Margin Right", $this->hook ); ?>
1524 </label>
1525 <label for="pf-margin_top">
1526 <input type="number" name="<?php echo $this->option_name; ?>[margin_top]" id="pf-margin_top" value="<?php $this->val( 'margin_top' ); ?>" maxlength="3"/> <?php _e( "Margin Top", $this->hook ); ?>
1527 </label>
1528 <label for="pf-margin_bottom">
1529 <input type="number" name="<?php echo $this->option_name; ?>[margin_bottom]" id="pf-margin_bottom" value="<?php $this->val( 'margin_bottom' ); ?>" maxlength="3"/> <?php _e( "Margin Bottom", $this->hook ); ?>
1530 </label>
1531 </div>
1532 </div>
1533 </div>
1534 <br class="clear">
1535
1536 <!--Section 3 Button Placement-->
1537 <div id="button-placement">
1538 <h3><?php _e( "Display button on:", $this->hook ); ?></h3>
1539 <div id="pages">
1540 <?php $this->create_checkbox('posts', __( 'Posts', $this->hook )); ?>
1541 <?php $this->create_checkbox('pages', __( 'Pages', $this->hook )); ?>
1542 <?php $this->create_checkbox('homepage', __( 'Homepage', $this->hook )); ?>
1543 <?php $this->create_checkbox('categories', __( 'Category Pages', $this->hook )); ?>
1544 <?php $this->create_checkbox('taxonomies', __( 'Taxonomy Pages', $this->hook )); ?>
1545 <label for="show_on_template"><input type="checkbox" class="show_template" name="show_on_template" id="show_on_template" /><?php echo _e( 'Add direct to template', $this->hook ); ?></label>
1546 <textarea id="pf-shortcode" class="code" rows="2" cols="40">&lt;?php if(function_exists('pf_show_link')){echo pf_show_link();} ?&gt;</textarea>
1547 <label<?php /* for="pf-shortcode2"*/ ?>><?php _e( "or use shortcode inside your page/article", $this->hook ); ?></label>
1548 <textarea<?php /* id="pf-shortcode2"*/ ?> class="code" rows="2" cols="40">[printfriendly]</textarea>
1549 <?php /* <input type="hidden" name="<? php echo $this->option_name; ?>[category_ids]" id="category_ids" value="<?php echo implode(',', $this->options['category_ids']); ? >" /> */ ?>
1550 </div>
1551 </div>
1552 <?php /*if($this->wp_version_gt30()) { ? >
1553 <div id="pf-categories">
1554 <h4><?php printf( __( '<a %s>Additional filter</a>', $this->hook), ' href="javascript:void(0)" id="toggle-categories"' ); ?></h4>
1555 <div id="pf-categories-metabox">
1556 <?php $this->create_category_metabox(); ?>
1557 </div>
1558 </div>
1559 <? php } */ ?>
1560
1561 <br class="clear">
1562
1563 <!--Section 4 Button Print Options-->
1564 <div id="print-options">
1565 <h3><?php _e( "Print PDF Options", $this->hook ); ?></h3>
1566 <label id="pf-favicon" for="favicon"<?php /*for="pf-logo"*/ ?>>
1567 <?php _e( "Page header", $this->hook ); ?>
1568 <select id="pf-logo" name="<?php echo $this->option_name; ?>[logo]" >
1569 <option value="favicon" <?php selected( $this->options['logo'], 'favicon' ); ?>><?php _e( "My Website Icon", $this->hook ); ?></option>
1570 <option value="upload-an-image" <?php selected( $this->options['logo'], 'upload-an-image' ); ?>><?php _e( "Upload an Image", $this->hook ); ?></option>
1571 </select>
1572 </label>
1573 <?php /* <div class="custom-logo">
1574 <label for="upload-an-image"><?php _e( "Enter url", $this->hook ); ?></label><input id="upload-an-image" type="text" class="regular-text" name="<?php echo $this->option_name; ?>[image_url]" value="<?php $this->val( 'image_url' ); ?>" />
1575 <label for="image-tagline"><?php _e( "Text (optional)", $this->hook ); ?></label><input id="image-tagline" type="text" class="regular-text" name="<?php echo $this->option_name; ?>[tagline]" value="<?php $this->val( 'tagline' ); ?>" />
1576 </div> */ ?>
1577 <div class="custom-logo"><label for="Enter_URL">Enter url</label><input id="upload-an-image" type="text" class="regular-text" name="<?php echo $this->option_name; ?>[image_url]" value="<?php $this->val( 'image_url' ); ?>" /><label for="Text__optional_">Text (optional)</label><input id="image-tagline" type="text" class="regular-text" name="<?php echo $this->option_name; ?>[tagline]" value="<?php $this->val( 'tagline' ); ?>" /></div>
1578 <div id="pf-image-error"></div>
1579 <div id="pf-image-preview"></div>
1580 <label for="click_to_delete">
1581 <?php _e( "Click-to-delete", $this->hook ); ?>
1582 <select name="<?php echo $this->option_name; ?>[click_to_delete]" id="click-to-delete">
1583 <option value="0" <?php selected( $this->options['click_to_delete'], '0' ); ?>><?php _e( "Allow", $this->hook ); ?></option>
1584 <option value="1" <?php selected( $this->options['click_to_delete'], '1' ); ?>><?php _e( "Not Allow", $this->hook ); ?></option>
1585 </select>
1586 </label>
1587 <label for="images-size">
1588 <?php _e( "Images", $this->hook ); ?>
1589 <select name="<?php echo $this->option_name; ?>[images-size]" id="images-size">
1590 <option value="full-size" <?php selected( $this->options['images-size'], 'full-size' ); ?>><?php _e( "Full Size", $this->hook ); ?></option>
1591 <option value="large" <?php selected( $this->options['images-size'], 'large' ); ?>><?php _e( "Large", $this->hook ); ?></option>
1592 <option value="medium" <?php selected( $this->options['images-size'], 'medium' ); ?>><?php _e( "Medium", $this->hook ); ?></option>
1593 <option value="small" <?php selected( $this->options['images-size'], 'small' ); ?>><?php _e( "Small", $this->hook ); ?></option>
1594 <option value="remove-images" <?php selected( $this->options['images-size'], 'remove-images' ); ?>><?php _e( "Remove Images", $this->hook ); ?></option>
1595 </select>
1596 </label>
1597 <label for="image-style">
1598 <?php _e( "Image style", $this->hook ); ?>
1599 <select name="<?php echo $this->option_name; ?>[image-style]" id="image-style">
1600 <option value="right" <?php selected( $this->options['image-style'], 'right' ); ?>><?php _e( "Align Right", $this->hook ); ?></option>
1601 <option value="left" <?php selected( $this->options['image-style'], 'left' ); ?>><?php _e( "Align Left", $this->hook ); ?></option>
1602 <option value="none" <?php selected( $this->options['image-style'], 'none' ); ?>><?php _e( "Align None", $this->hook ); ?></option>
1603 <option value="block" <?php selected( $this->options['image-style'], 'block' ); ?>><?php _e( "Center/Block", $this->hook ); ?></option>
1604 </select>
1605 </label>
1606 <label for="email">
1607 <?php _e( "Email", $this->hook ); ?>
1608 <select name="<?php echo $this->option_name; ?>[email]" id="email">
1609 <option value="0" <?php selected( $this->options['email'], '0' ); ?>><?php _e( "Allow", $this->hook ); ?></option>
1610 <option value="1" <?php selected( $this->options['email'], '1' ); ?>><?php _e( "Not Allow", $this->hook ); ?></option>
1611 </select>
1612 </label>
1613 <label for="pdf">
1614 <span class="alignleft"><?php _e( "PDF", $this->hook ); ?></span>
1615 <select name="<?php echo $this->option_name; ?>[pdf]" id="pdf" class="alignleft clear">
1616 <option value="0" <?php selected( $this->options['pdf'], '0' ); ?>><?php _e( "Allow", $this->hook ); ?></option>
1617 <option value="1" <?php selected( $this->options['pdf'], '1' ); ?>><?php _e( "Not Allow", $this->hook ); ?></option>
1618 </select>
1619 <p class="alignleft">
1620 <h4 class="alignleft notice"><abbr class="required"><?php _e( "Developer Note: ", $this->hook ); ?></abbr><?php _e( "On localhost the images can not be included in the PDF. Once the website is live/public images will be included in the PDF.", $this->hook ); ?></h4>
1621 </p>
1622 </label>
1623 <label for="print" class="clear">
1624 <?php _e( "Print", $this->hook ); ?>
1625 <select name="<?php echo $this->option_name; ?>[print]" id="print">
1626 <option value="0" <?php selected( $this->options['print'], '0' ); ?>><?php _e( "Allow", $this->hook ); ?></option>
1627 <option value="1" <?php selected( $this->options['print'], '1' ); ?>><?php _e( "Not Allow", $this->hook ); ?></option>
1628 </select>
1629 </label>
1630 <label for="custom_css_url">
1631 <?php _e( "Custom css url", $this->hook ); ?>
1632 <input id="custom_css_url" type="text" class="regular-text" name="<?php echo $this->option_name; ?>[custom_css_url]" value="<?php $this->val( 'custom_css_url' ); ?>" />
1633 <span class="description pf-help-link"><a target="_howto" href="https://support.printfriendly.com/customer/portal/articles/895256-custom-css-styles"><?php _e( '?', $this->hook ); ?></a></span>
1634 </label>
1635 </div>
1636
1637 <!--Section 5 WebMaster-->
1638 <h3><?php _e( "Webmaster Settings", $this->hook ); ?></h3>
1639
1640 <label for="password_protected"><?php _e( 'Password Protected Content', $this->hook ); ?>
1641 <select id="password_protected" name="<?php echo $this->option_name; ?>[password_protected]">
1642 <option value="no" <?php selected( $this->options['password_protected'], 'no' ); ?>><?php _e( "No", $this->hook ); ?></option>
1643 <option value="yes" <?php selected( $this->options['password_protected'], 'yes' ); ?>><?php _e( "Yes", $this->hook ); ?></option>
1644 </select>
1645 </label>
1646 <label for="javascript"><?php _e( 'Use JavaScript', $this->hook ); ?><br>
1647 <select id="javascript" name="<?php echo $this->option_name; ?>[javascript]>">
1648 <option value="yes" <?php $this->selected( 'javascript', 'yes' ); ?>> <?php _e( "Yes", $this->hook ); ?></option>
1649 <option value="no" <?php $this->selected( 'javascript', 'no' ); ?>> <?php _e( "No", $this->hook ); ?></option>
1650 </select>
1651 <span class="description javascript no-italics">
1652 <?php _e( "Preview appears on the page in a Lightbox.", $this->hook ); ?>
1653 </span>
1654 <span class="description no-javascript no-italics">
1655 <?php _e( "Preview opens a new browser tab.", $this->hook ); ?>
1656 </span>
1657 </label>
1658 <label for="pf-analytics-tracking"><?php _e( 'Track in Google Analytics', $this->hook ); ?><br>
1659 <select id="pf-analytics-tracking" name="<?php echo $this->option_name; ?>[enable_google_analytics]">
1660 <option value="yes" <?php $this->selected( 'enable_google_analytics', 'yes' ); ?>> <?php _e( "Yes", $this->hook ); ?></option>
1661 <option value="no" <?php $this->selected( 'enable_google_analytics', 'no' ); ?>> <?php _e( "No", $this->hook ); ?></option>
1662 </select>
1663 </label>
1664 <label for="pf-error-reporting"><?php _e( 'Error Reporting', $this->hook ); ?>
1665 <span class="description no-italics" ><?php _e( 'Ensure PrintFriendly is working - Automatically send anonymous alert if PrintFriendly encounters an error.', $this->hook ); ?>
1666 <br>
1667 <select id="pf-error-reporting" name="<?php echo $this->option_name; ?>[enable_error_reporting]">
1668 <option value="yes" <?php $this->selected( 'enable_error_reporting', 'yes' ); ?>> <?php _e( "Yes", $this->hook ); ?></option>
1669 <option value="no" <?php $this->selected( 'enable_error_reporting', 'no' ); ?>> <?php _e( "No", $this->hook ); ?></option>
1670 </select>
1671 </label>
1672 <label for="pf-algo-usage"><?php _e( 'My Page Content Selected By:', $this->hook ); ?> <span class="description no-italics" ><?php _e( 'Change this setting if your content is not showing in the preview.', $this->hook ); ?></span><br>
1673
1674 <?php
1675 if (class_exists('WooCommerce')) {
1676 ?>
1677 <span><strong>Not available for woocommerce</strong></span>
1678 <?php
1679 } else {
1680 ?>
1681 <select id="pf-algo-usage" name="<?php echo $this->option_name; ?>[pf_algo]">
1682 <option value="wp" <?php $this->selected( 'pf_algo', 'wp' ); ?>> <?php _e( 'WP Template', $this->hook ); ?></option>
1683 <option value="pf" <?php $this->selected( 'pf_algo', 'pf' ); ?>> <?php _e( "Content Algorithm", $this->hook ); ?></option>
1684 </select>
1685 <?php
1686 }
1687 ?>
1688
1689 </label>
1690
1691 <p class="submit">
1692 <input type="submit" class="button-primary" value="<?php esc_attr_e( "Save Options", $this->hook ); ?>"/>
1693 <input type="reset" class="button-secondary" value="<?php esc_attr_e( "Cancel", $this->hook ); ?>"/>
1694 </p>
1695 <div id="after-submit">
1696 <p>
1697 <?php _e( sprintf( __( 'If you like <strong>PrintFriendly</strong> please leave us a %s rating. A huge thanks in advance!', 'printfriendly' ), '<a href="https://wordpress.org/support/plugin/printfriendly/reviews?rate=5#new-post" target="_blank">&#9733;&#9733;&#9733;&#9733;&#9733;</a>' ), $this->hook ); ?>
1698 </p>
1699 <p><?php _e( "Need professional options for your corporate, education, or agency developed website? Check out", $this->hook ); ?> <a href="https://www.printfriendly.com/pro">PrintFriendly Pro</a>.</p>
1700 <p>
1701 <?php _e( "Need help or have suggestions?", $this->hook ); ?> <a href="mailto:support@printfriendly.com?subject=Support%20for%20PrintFriendly%20WordPress%20plugin">support@PrintFriendly.com</a>
1702 </p>
1703 </div>
1704 </form>
1705 <?php
1706 }
1707 }
1708 $printfriendly = new PrintFriendly_WordPress();
1709 }
1710
1711 // Add shortcode for printfriendly button
1712 add_shortcode( 'printfriendly', 'pf_show_link' );
1713
1714 /**
1715 * Convenience function for use in templates.
1716 *
1717 * @since 3.0
1718 * @return string returns a button to be printed.
1719 */
1720 function pf_show_link() {
1721 global $printfriendly;
1722 return $printfriendly->getButton(true);
1723 }
1724