PluginProbe
Print, PDF & Email by PrintFriendly / 3.13.0
Print, PDF & Email by PrintFriendly v3.13.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 / trunk / pf.php

pf.php in Print, PDF & Email by PrintFriendly 3.13.0, at trunk/pf.php

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