PluginProbe
Print, PDF & Email by PrintFriendly / 3.12.4
Print, PDF & Email by PrintFriendly v3.12.4
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.4, at pf.php

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