Print, PDF, Email by PrintFriendly - Version 3.3.10

Version Description

  • Implemented both Classic Google Analytics and Google Universal Analytics code
  • Fixed WP Slimstat conflict
Download this release

Release Info

Developer printfriendly
Plugin Icon 128x128 Print, PDF, Email by PrintFriendly
Version 3.3.10
Comparing to
See all releases

Code changes from version 3.3.9 to 3.3.10

Files changed (2) hide show
  1. pf.php +171 -172
  2. readme.txt +7 -2
pf.php CHANGED
@@ -5,12 +5,13 @@ Plugin Name: Print Friendly and PDF
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.3.9
9
  Author: Print Friendly
10
  Author URI: http://www.PrintFriendly.com
11
 
12
  Changelog :
13
- 3.3.9 - Removed the functionality that opens new window when JavaScript is disabled
 
14
  3.3.8 - Shortcode Bug fix, urlencode button href
15
  3.3.7 - Readme.txt update
16
  3.3.6 - Fixed JS optimization Bug
@@ -135,10 +136,10 @@ if ( ! class_exists( 'PrintFriendly_WordPress' ) ) {
135
  add_filter( 'the_content', array( &$this, 'show_link' ) );
136
  add_filter( 'the_excerpt', array( &$this, 'show_link' ) );
137
  }
138
-
139
- if($this->use_wp_content_hook()) {
140
- add_action('the_content', array(&$this, 'add_pf_content_class_around_content_hook'));
141
- }
142
 
143
  if ( is_admin() ) {
144
  // Hook into init for registration of the option and the language files
@@ -155,45 +156,45 @@ if ( ! class_exists( 'PrintFriendly_WordPress' ) ) {
155
 
156
  // Register a link to the settings page on the plugins overview page
157
  add_filter( 'plugin_action_links', array( &$this, 'filter_plugin_actions' ), 10, 2 );
158
- }
159
  }
160
 
161
 
162
- /**
163
- * Returns true if WP content hooks are to used to find content
164
- * @since 3.2.8
165
- *
166
- **/
167
  function use_wp_content_hook() {
168
- return (isset($this->options['pf_algo']) && $this->options['pf_algo'] == 'wp');
169
- }
170
-
171
- /**
172
- * Adds wraps content in pf-content class to help Printfriendly algo determine the content
173
- *
174
- * @since 3.2.8
175
- *
176
- **/
177
- function add_pf_content_class_around_content_hook($content = false) {
178
- if($content && !$this->print_only_override($content)) {
179
- add_action( 'wp_footer', array( &$this, 'print_script_footer' ));
180
- return '<div class="pf-content">'.$content.'</div>';
181
- }
182
- else
183
- return $content;
184
- }
185
-
186
- /**
187
- * Override to check if print-only command is being used
188
- *
189
- * @since 3.3.0
190
- **/
191
- function print_only_override($content) {
192
- $pattern = '/class=[\"]print-only|class=[\']print-only|print-only/';
193
- $pf_pattern = '/class=[\"]pf-content|class=[\']pf-content|pf-content/';
194
- return (preg_match($pattern, $content) || preg_match($pf_pattern, $content)) ;
195
- }
196
-
197
  /**
198
  * PHP 4 Compatible Constructor
199
  *
@@ -288,7 +289,7 @@ if ( ! class_exists( 'PrintFriendly_WordPress' ) ) {
288
 
289
  ?>
290
  <script type="text/javascript">
291
-
292
  var pfHeaderImgUrl = '<?php echo esc_js(esc_url_raw($image_url)); ?>';
293
  var pfHeaderTagline = '<?php echo esc_js($tagline); ?>';
294
  var pfdisableClickToDel = '<?php echo esc_js($this->options['click_to_delete']); ?>';
@@ -298,17 +299,17 @@ if ( ! class_exists( 'PrintFriendly_WordPress' ) ) {
298
  var pfDisablePDF = '<?php echo esc_js($this->options['pdf']); ?>';
299
  var pfDisablePrint = '<?php echo esc_js($this->options['print']); ?>';
300
  var pfCustomCSS = '<?php echo esc_js($this->options['custom_css_url']); ?>';
301
- (function() {
302
  var e = document.createElement('script'); e.type="text/javascript";
303
- if('https:' == document.location.protocol) {
304
- js='https://pf-cdn.printfriendly.com/ssl/main.js';
305
- }
306
- else{
307
- js='http://cdn.printfriendly.com/printfriendly.js';
308
- }
309
  e.src = js;
310
  document.getElementsByTagName('head')[0].appendChild(e);
311
- })();
312
  </script>
313
  <?php
314
  }
@@ -327,14 +328,14 @@ if ( ! class_exists( 'PrintFriendly_WordPress' ) ) {
327
  return "";
328
 
329
 
330
- $button = $this->getButton();
331
  if ( $is_manual )
332
  {
333
  // Hook the script call now, so it only get's loaded when needed, and need is determined by the user calling pf_button
334
  add_action( 'wp_footer', array( &$this, 'print_script_footer' ) );
335
  return $button;
336
  }
337
-
338
  else
339
  {
340
  if ( (is_page() && ( isset($this->options['show_on_pages']) && 'on' === $this->options['show_on_pages'] ) )
@@ -359,70 +360,69 @@ if ( ! class_exists( 'PrintFriendly_WordPress' ) ) {
359
  }
360
 
361
  }
362
-
363
-
364
- /**
365
- * @since 3.3.8
366
- * @returns Printfriendly Button HTML
367
- */
368
-
369
- function getButton($add_footer_script = false) {
370
- if($add_footer_script) {
371
- add_action( 'wp_footer', array( &$this, 'print_script_footer' ) );
372
- }
373
  $js_enabled = $this->js_enabled();
374
- $analytics_code = "";
375
-
376
- $title_var = "NULL";
377
- $analytics_code = "if(typeof(_gaq) != 'undefined') { _gaq.push(['_trackEvent','PRINTFRIENDLY', 'print', '".$title_var."']);}";
378
-
379
- if ( $this->google_analytics_enabled() ) {
380
  if( $js_enabled ) {
381
- $onclick = 'onclick="window.print();';
382
  } else {
383
  $onclick = '';
384
- }
385
- $onclick .= $analytics_code.' return false;"';
386
- } else if ( $js_enabled ) {
387
  $onclick = 'onclick="window.print(); return false;"';
388
  }
389
-
390
- $href = 'http://www.printfriendly.com/print?url='.urlencode(get_permalink());
391
-
392
- if (!$js_enabled) {
393
- if($this->google_analytics_enabled()) {
394
- $onclick = $onclick.' onclick="'.$analytics_code.'"';
395
- }
396
- $href = "http://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'])."&hideImages=".urlencode($this->options['hide-images'])."&url=".urlencode(get_permalink())."&redirect=wp";
397
  }
398
  if ( !is_singular() && '' != $onclick && $js_enabled) {
399
  $onclick = '';
400
  $href = add_query_arg('pfstyle','wp',get_permalink());
401
  }
402
-
403
  $align = '';
404
  if ( 'none' != $this->options['content_position'] )
405
  $align = ' pf-align'.$this->options['content_position'];
406
- $href = str_replace("&", "&amp;", $href );
407
- $button = apply_filters( 'printfriendly_button', '<div class="printfriendly'.$align.'"><a href="'.$href.'" rel="nofollow" '.$onclick.'>'.$this->button().'</a></div>' );
408
- return $button;
409
- }
410
-
411
-
412
- /**
413
- * @since 3.2.9
414
- * @returns if google analytics enabled
415
- */
416
- function google_analytics_enabled() {
417
- return isset( $this->options['enable_google_analytics'] ) && $this->options['enable_google_analytics'] == 'yes';
418
- }
419
  /**
420
- * @since 3.2.6
421
- * @return boolean true if JS is enabled for the plugin
422
- **/
423
- function js_enabled() {
424
- return isset( $this->options['javascript'] ) && $this->options['javascript'] == 'yes';
425
- }
426
 
427
  /**
428
  * Filter posts by category.
@@ -432,7 +432,7 @@ if ( ! class_exists( 'PrintFriendly_WordPress' ) ) {
432
  */
433
  function category_included() {
434
  // return ( 'all' === $this->options['category_ids'][0] || in_category($this->options['category_ids']) );
435
- return true;
436
  }
437
 
438
  /**
@@ -458,15 +458,15 @@ if ( ! class_exists( 'PrintFriendly_WordPress' ) ) {
458
  function options_validate( $input ) {
459
  $valid_input = $input;
460
 
461
- /* Section 1 options */
462
  if ( !isset( $input['button_type'] ) || !in_array( $input['button_type'], array(
463
- 'pf-button.gif', 'pf-button-both.gif', 'pf-button-big.gif', // buttongroup1
464
- 'button-print-grnw20.png', 'button-print-blu20.png', 'button-print-gry20.png', // buttongroup2
465
- 'pf-icon-small.gif', 'pf-icon-both.gif','pf-icon.gif', 'text-only', // buttongroup3
466
- 'custom-image', // custom
467
- 'button-print-whgn20.png', 'pf_button_sq_gry_m.png', 'pf_button_sq_gry_l.png', 'pf_button_sq_grn_m.png',
468
- 'pf_button_sq_grn_l.png', // backward compatibility
469
- ) ) )
470
  $valid_input['button_type'] = 'pf-button.gif';
471
 
472
  // @todo custom image url validation
@@ -475,7 +475,7 @@ if ( ! class_exists( 'PrintFriendly_WordPress' ) ) {
475
 
476
  // @todo validate optional custom text
477
  if ( !isset( $input['custom_text'] ) ) {
478
- $valid_input['custom_text'] = 'Print Friendly';
479
  }
480
  /* else {
481
 
@@ -506,7 +506,7 @@ if ( ! class_exists( 'PrintFriendly_WordPress' ) ) {
506
 
507
 
508
 
509
- /* Section 2 options */
510
  if ( !isset( $input['enable_css'] ) || 'off' !== $input['enable_css'] )
511
  $valid_input['enable_css'] = 'on';
512
 
@@ -522,7 +522,7 @@ if ( ! class_exists( 'PrintFriendly_WordPress' ) ) {
522
  unset( $opt );
523
 
524
 
525
- /* Section 3 options */
526
  foreach ( array( 'show_on_posts', 'show_on_pages', 'show_on_homepage', 'show_on_categories', 'show_on_taxonomies' ) as $opt ) {
527
  if ( !isset( $input[$opt] ) || 'on' !== $input[$opt] ) {
528
  unset( $valid_input[$opt] );
@@ -535,26 +535,26 @@ if ( ! class_exists( 'PrintFriendly_WordPress' ) ) {
535
  unset( $valid_input['show_on_template'] );
536
 
537
 
538
- if( isset( $input['category_ids'] ) ) {
539
- /**
540
- * Validate received category ids:
541
- * - Is there only one array item and does it contain the string text 'all' ? => pass
542
- * - Otherwise, make sure the ids are integer values
543
- */
544
  /* $valid_input['category_ids'] = explode(',', $input['category_ids']);
545
  $valid_input['category_ids'] = array_map( 'trim', $valid_input['category_ids'] );
546
  if( ( count( $valid_input['category_ids'] ) === 1 && 'all' === $valid_input['category_ids'][0] ) === false ) {
547
- foreach( $valid_input['category_ids'] as $k => $v ) {
548
- if( $v !== '' && ( ctype_digit( (string) $v ) === true && ( intval( $v ) == $v ) ) ) {
549
- $valid_input['category_ids'][$k] = intval( $v );
550
- }
551
- else {
552
- // Invalid input - Show error message ?
553
- unset( $valid_input['category_ids'][$k] );
554
- }
555
- }
556
- }*/
557
- unset( $valid_input['category_ids'] );
558
  }
559
 
560
  //echo '<pre>'.print_r($input,1).'</pre>';
@@ -562,7 +562,7 @@ if ( ! class_exists( 'PrintFriendly_WordPress' ) ) {
562
 
563
 
564
 
565
- /* Section 4 options */
566
  if ( !isset( $input['logo'] ) || !in_array( $input['logo'], array( 'favicon', 'upload-an-image' ) ) )
567
  $valid_input['logo'] = 'favicon';
568
 
@@ -572,7 +572,7 @@ if ( ! class_exists( 'PrintFriendly_WordPress' ) ) {
572
 
573
  // @todo validate optional tagline text
574
  if ( !isset( $input['tagline'] ) ) {
575
- $valid_input['tagline'] = '';
576
  }
577
  /* else {
578
 
@@ -592,7 +592,7 @@ if ( ! class_exists( 'PrintFriendly_WordPress' ) ) {
592
  foreach( array( 'click_to_delete', 'hide-images', 'email', 'pdf', 'print', ) as $opt ) {
593
  if( !isset( $input[$opt] ) || !in_array( $input[$opt], array( '0', '1' ) ) ) {
594
  $valid_input[$opt] = '0';
595
- }
596
  }
597
  unset( $opt );
598
 
@@ -603,7 +603,7 @@ if ( ! class_exists( 'PrintFriendly_WordPress' ) ) {
603
 
604
 
605
 
606
- /* Section 5 options */
607
  if ( !isset( $input['website_protocol'] ) || !in_array( $input['website_protocol'], array( 'http', 'https' ) ) )
608
  $valid_input['website_protocol'] = 'http';
609
 
@@ -613,16 +613,16 @@ if ( ! class_exists( 'PrintFriendly_WordPress' ) ) {
613
  if ( !isset( $input['javascript'] ) || !in_array( $input['javascript'], array( 'no', 'yes' ) ) )
614
  $valid_input['javascript'] = 'yes';
615
 
616
- /*Analytics Options */
617
- if ( !isset( $input['enable_google_analytics'] ) || !in_array( $input['enable_google_analytics'], array( 'no', 'yes' ) ) ) {
618
- $valid_input['enable_google_analytics'] = "no";
619
- }
620
-
621
- if ( !isset( $input['pf_algo'] ) || !in_array( $input['pf_algo'], array( 'wp', 'pf' ) ) ) {
622
- $valid_input['pf_algo'] = "wp";
623
- }
624
-
625
- /* Database version */
626
  $valid_input['db_version'] = $this->db_version;
627
 
628
  return $valid_input;
@@ -728,8 +728,8 @@ if ( ! class_exists( 'PrintFriendly_WordPress' ) ) {
728
  'password_protected' => 'no',
729
  'javascript' => 'yes',
730
  'custom_css_url' => '',
731
- 'enable_google_analytics' => 'no',
732
- 'pf_algo' => 'wp'
733
  // 'category_ids' => array('all'),
734
  );
735
 
@@ -851,9 +851,9 @@ if ( ! class_exists( 'PrintFriendly_WordPress' ) ) {
851
  'category_ids' => array(),
852
  );
853
 
854
- if( !isset( $this->options['category_ids'] ) || ( isset( $this->options['category_ids'] ) && 0 === count( $this->options['category_ids'] ) ) ) {
855
  $additional_options['category_ids'][] = 'all';
856
- }
857
 
858
  $this->options = array_merge($this->options, $additional_options);
859
  */
@@ -871,12 +871,12 @@ if ( ! class_exists( 'PrintFriendly_WordPress' ) ) {
871
  $this->options = array_merge($this->options, $additional_options);
872
  }
873
  if($this->options['db_version'] < 8) {
874
- $this->options['enable_google_analytics'] = 'no';
875
- }
876
 
877
  if($this->options['db_version'] < 9) {
878
- $this->options['pf_algo'] = 'wp';
879
- }
880
  $this->options['db_version'] = $this->db_version;
881
 
882
  update_option( $this->option_name, $this->options );
@@ -910,7 +910,7 @@ if ( ! class_exists( 'PrintFriendly_WordPress' ) ) {
910
  function button( $name = false ){
911
  if( !$name )
912
  $name = $this->options['button_type'];
913
- $button_css = $this->generic_button_css();
914
  $text = $this->options['custom_text'];
915
  $img_path = 'http://cdn.printfriendly.com/';
916
  if($this->options['website_protocol'] == 'https')
@@ -948,14 +948,14 @@ if ( ! class_exists( 'PrintFriendly_WordPress' ) ) {
948
  }
949
  }
950
 
951
- /**
952
- *
953
- *
954
- **/
955
-
956
- function generic_button_css() {
957
- return "border:none;-webkit-box-shadow:none; box-shadow:none;";
958
- }
959
 
960
 
961
  /**
@@ -1014,7 +1014,7 @@ if ( ! class_exists( 'PrintFriendly_WordPress' ) ) {
1014
  *
1015
  */
1016
  function create_checkbox($name, $label='', $labelid='' ) {
1017
- $label = ( !empty( $label) ? $label : __( ucfirst($name), $this->hook ) );
1018
  echo '<label' . ( !empty( $labelid ) ? ' id=' . $labelid : '' ) . '><input type="checkbox" class="show_list" name="' . $this->option_name . '[show_on_' . $name . ']" value="on" ';
1019
  $this->checked( 'show_on_' . $name, 'on');
1020
  echo ' />' . $label . "</label>\r\n";
@@ -1086,8 +1086,8 @@ if ( ! class_exists( 'PrintFriendly_WordPress' ) ) {
1086
  * @since 3.2.2
1087
  */
1088
  function create_category_metabox() {
1089
- $obj = new stdClass();
1090
- $obj->ID = 0;
1091
  do_meta_boxes('settings_page_' . $this->hook, 'normal', $obj);
1092
  }
1093
 
@@ -1122,9 +1122,9 @@ if ( ! class_exists( 'PrintFriendly_WordPress' ) ) {
1122
 
1123
  // Show the content of the options array when debug is enabled
1124
  if ( WP_DEBUG ) {
1125
- echo "<p>Currently in Debug Mode. Following information is visible in debug mode only:</p>";
1126
  echo '<pre>Options:<br><br>' . print_r( $this->options, 1 ) . '</pre>';
1127
- }
1128
  ?>
1129
  <div id="pf_settings" class="wrap">
1130
 
@@ -1270,9 +1270,9 @@ if ( ! class_exists( 'PrintFriendly_WordPress' ) ) {
1270
  </select>
1271
  </label>
1272
  <?php /* <div class="custom-logo">
1273
- <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' ); ?>" />
1274
- <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' ); ?>" />
1275
- </div> */ ?>
1276
  <div class="custom-logo"><label for="Enter_URL">Enter url</label><input id="upload-an-image" type="text" class="regular-text" name="<?php echo $this->option_name; ?>[image_url]" value="<?php $this->val( 'image_url' ); ?>" /><label for="Text__optional_">Text (optional)</label><input id="image-tagline" type="text" class="regular-text" name="<?php echo $this->option_name; ?>[tagline]" value="<?php $this->val( 'tagline' ); ?>" /></div>
1277
  <div id="pf-image-error"></div>
1278
  <div id="pf-image-preview"></div>
@@ -1362,11 +1362,11 @@ if ( ! class_exists( 'PrintFriendly_WordPress' ) ) {
1362
  <option value="no" <?php $this->selected( 'enable_google_analytics', 'no' ); ?>> <?php _e( "No", $this->hook ); ?></option>
1363
  </select>
1364
  </label>
1365
-
1366
  <label id="pf-algo-usage" <?php /*for="javascript"*/ ?>>My Page Content Selected By: <span class="description no-italics" > Change this setting if your content is not showing in the preview.</span><br>
1367
  <select id="pf-algo-usage" name="<?php echo $this->option_name; ?>[pf_algo]">
1368
  <option value="wp" <?php $this->selected( 'pf_algo', 'wp' ); ?>> <?php _e( 'WP "the_content" filter
1369
- ', $this->hook ); ?></option>
1370
  <option value="pf" <?php $this->selected( 'pf_algo', 'pf' ); ?>> <?php _e( "Content Algorithm", $this->hook ); ?></option>
1371
  </select>
1372
  </label>
@@ -1402,4 +1402,3 @@ function pf_show_link() {
1402
  global $printfriendly;
1403
  return $printfriendly->getButton(true);
1404
  }
1405
-
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.3.10
9
  Author: Print Friendly
10
  Author URI: http://www.PrintFriendly.com
11
 
12
  Changelog :
13
+ 3.3.10 - Implemented both Classic Google Analytics and Google Universal Analytics code.
14
+ 3.3.9 - Removed the functionality that opens new window when JavaScript is disabled.
15
  3.3.8 - Shortcode Bug fix, urlencode button href
16
  3.3.7 - Readme.txt update
17
  3.3.6 - Fixed JS optimization Bug
136
  add_filter( 'the_content', array( &$this, 'show_link' ) );
137
  add_filter( 'the_excerpt', array( &$this, 'show_link' ) );
138
  }
139
+
140
+ if($this->use_wp_content_hook()) {
141
+ add_action('the_content', array(&$this, 'add_pf_content_class_around_content_hook'));
142
+ }
143
 
144
  if ( is_admin() ) {
145
  // Hook into init for registration of the option and the language files
156
 
157
  // Register a link to the settings page on the plugins overview page
158
  add_filter( 'plugin_action_links', array( &$this, 'filter_plugin_actions' ), 10, 2 );
159
+ }
160
  }
161
 
162
 
163
+ /**
164
+ * Returns true if WP content hooks are to used to find content
165
+ * @since 3.2.8
166
+ *
167
+ **/
168
  function use_wp_content_hook() {
169
+ return (isset($this->options['pf_algo']) && $this->options['pf_algo'] == 'wp');
170
+ }
171
+
172
+ /**
173
+ * Adds wraps content in pf-content class to help Printfriendly algo determine the content
174
+ *
175
+ * @since 3.2.8
176
+ *
177
+ **/
178
+ function add_pf_content_class_around_content_hook($content = false) {
179
+ if($content && !$this->print_only_override($content)) {
180
+ add_action( 'wp_footer', array( &$this, 'print_script_footer' ));
181
+ return '<div class="pf-content">'.$content.'</div>';
182
+ }
183
+ else
184
+ return $content;
185
+ }
186
+
187
+ /**
188
+ * Override to check if print-only command is being used
189
+ *
190
+ * @since 3.3.0
191
+ **/
192
+ function print_only_override($content) {
193
+ $pattern = '/class=[\"]print-only|class=[\']print-only|print-only/';
194
+ $pf_pattern = '/class=[\"]pf-content|class=[\']pf-content|pf-content/';
195
+ return (preg_match($pattern, $content) || preg_match($pf_pattern, $content)) ;
196
+ }
197
+
198
  /**
199
  * PHP 4 Compatible Constructor
200
  *
289
 
290
  ?>
291
  <script type="text/javascript">
292
+
293
  var pfHeaderImgUrl = '<?php echo esc_js(esc_url_raw($image_url)); ?>';
294
  var pfHeaderTagline = '<?php echo esc_js($tagline); ?>';
295
  var pfdisableClickToDel = '<?php echo esc_js($this->options['click_to_delete']); ?>';
299
  var pfDisablePDF = '<?php echo esc_js($this->options['pdf']); ?>';
300
  var pfDisablePrint = '<?php echo esc_js($this->options['print']); ?>';
301
  var pfCustomCSS = '<?php echo esc_js($this->options['custom_css_url']); ?>';
302
+ (function() {
303
  var e = document.createElement('script'); e.type="text/javascript";
304
+ if('https:' == document.location.protocol) {
305
+ js='https://pf-cdn.printfriendly.com/ssl/main.js';
306
+ }
307
+ else{
308
+ js='http://cdn.printfriendly.com/printfriendly.js';
309
+ }
310
  e.src = js;
311
  document.getElementsByTagName('head')[0].appendChild(e);
312
+ })();
313
  </script>
314
  <?php
315
  }
328
  return "";
329
 
330
 
331
+ $button = $this->getButton();
332
  if ( $is_manual )
333
  {
334
  // Hook the script call now, so it only get's loaded when needed, and need is determined by the user calling pf_button
335
  add_action( 'wp_footer', array( &$this, 'print_script_footer' ) );
336
  return $button;
337
  }
338
+
339
  else
340
  {
341
  if ( (is_page() && ( isset($this->options['show_on_pages']) && 'on' === $this->options['show_on_pages'] ) )
360
  }
361
 
362
  }
363
+
364
+
365
+ /**
366
+ * @since 3.3.8
367
+ * @returns Printfriendly Button HTML
368
+ */
369
+
370
+ function getButton($add_footer_script = false) {
371
+ if($add_footer_script) {
372
+ add_action( 'wp_footer', array( &$this, 'print_script_footer' ) );
373
+ }
374
  $js_enabled = $this->js_enabled();
375
+ $analytics_code = "";
376
+
377
+ if ( $this->google_analytics_enabled() ) {
378
+ $title_var = "NULL";
379
+ $analytics_code = "if(typeof(_gaq) != 'undefined') { _gaq.push(['_trackEvent','PRINTFRIENDLY', 'print', '".$title_var."']);
380
+ }else if(typeof(ga) != 'undefined') { ga('send', 'event','PRINTFRIENDLY', 'print', '".$title_var."'); }";
381
  if( $js_enabled ) {
382
+ $onclick = 'onclick="window.print();'. $analytics_code .' return false;"';
383
  } else {
384
  $onclick = '';
385
+ }
386
+ } else if ( $js_enabled ) {
 
387
  $onclick = 'onclick="window.print(); return false;"';
388
  }
389
+
390
+ $href = 'http://www.printfriendly.com/print?url='.urlencode(get_permalink());
391
+
392
+ if (!$js_enabled) {
393
+ if($this->google_analytics_enabled()) {
394
+ $onclick = $onclick.' onclick="'.$analytics_code.'"';
395
+ }
396
+ $href = "http://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'])."&hideImages=".urlencode($this->options['hide-images'])."&url=".urlencode(get_permalink())."&source=wp";
397
  }
398
  if ( !is_singular() && '' != $onclick && $js_enabled) {
399
  $onclick = '';
400
  $href = add_query_arg('pfstyle','wp',get_permalink());
401
  }
402
+
403
  $align = '';
404
  if ( 'none' != $this->options['content_position'] )
405
  $align = ' pf-align'.$this->options['content_position'];
406
+ $href = str_replace("&", "&amp;", $href );
407
+ $button = apply_filters( 'printfriendly_button', '<div class="printfriendly'.$align.'"><a href="'.$href.'" rel="nofollow" '.$onclick.' class="noslimstat">'.$this->button().'</a></div>' );
408
+ return $button;
409
+ }
410
+
411
+
412
+ /**
413
+ * @since 3.2.9
414
+ * @returns if google analytics enabled
415
+ */
416
+ function google_analytics_enabled() {
417
+ return isset( $this->options['enable_google_analytics'] ) && $this->options['enable_google_analytics'] == 'yes';
418
+ }
419
  /**
420
+ * @since 3.2.6
421
+ * @return boolean true if JS is enabled for the plugin
422
+ **/
423
+ function js_enabled() {
424
+ return isset( $this->options['javascript'] ) && $this->options['javascript'] == 'yes';
425
+ }
426
 
427
  /**
428
  * Filter posts by category.
432
  */
433
  function category_included() {
434
  // return ( 'all' === $this->options['category_ids'][0] || in_category($this->options['category_ids']) );
435
+ return true;
436
  }
437
 
438
  /**
458
  function options_validate( $input ) {
459
  $valid_input = $input;
460
 
461
+ /* Section 1 options */
462
  if ( !isset( $input['button_type'] ) || !in_array( $input['button_type'], array(
463
+ 'pf-button.gif', 'pf-button-both.gif', 'pf-button-big.gif', // buttongroup1
464
+ 'button-print-grnw20.png', 'button-print-blu20.png', 'button-print-gry20.png', // buttongroup2
465
+ 'pf-icon-small.gif', 'pf-icon-both.gif','pf-icon.gif', 'text-only', // buttongroup3
466
+ 'custom-image', // custom
467
+ 'button-print-whgn20.png', 'pf_button_sq_gry_m.png', 'pf_button_sq_gry_l.png', 'pf_button_sq_grn_m.png',
468
+ 'pf_button_sq_grn_l.png', // backward compatibility
469
+ ) ) )
470
  $valid_input['button_type'] = 'pf-button.gif';
471
 
472
  // @todo custom image url validation
475
 
476
  // @todo validate optional custom text
477
  if ( !isset( $input['custom_text'] ) ) {
478
+ $valid_input['custom_text'] = 'Print Friendly';
479
  }
480
  /* else {
481
 
506
 
507
 
508
 
509
+ /* Section 2 options */
510
  if ( !isset( $input['enable_css'] ) || 'off' !== $input['enable_css'] )
511
  $valid_input['enable_css'] = 'on';
512
 
522
  unset( $opt );
523
 
524
 
525
+ /* Section 3 options */
526
  foreach ( array( 'show_on_posts', 'show_on_pages', 'show_on_homepage', 'show_on_categories', 'show_on_taxonomies' ) as $opt ) {
527
  if ( !isset( $input[$opt] ) || 'on' !== $input[$opt] ) {
528
  unset( $valid_input[$opt] );
535
  unset( $valid_input['show_on_template'] );
536
 
537
 
538
+ if( isset( $input['category_ids'] ) ) {
539
+ /**
540
+ * Validate received category ids:
541
+ * - Is there only one array item and does it contain the string text 'all' ? => pass
542
+ * - Otherwise, make sure the ids are integer values
543
+ */
544
  /* $valid_input['category_ids'] = explode(',', $input['category_ids']);
545
  $valid_input['category_ids'] = array_map( 'trim', $valid_input['category_ids'] );
546
  if( ( count( $valid_input['category_ids'] ) === 1 && 'all' === $valid_input['category_ids'][0] ) === false ) {
547
+ foreach( $valid_input['category_ids'] as $k => $v ) {
548
+ if( $v !== '' && ( ctype_digit( (string) $v ) === true && ( intval( $v ) == $v ) ) ) {
549
+ $valid_input['category_ids'][$k] = intval( $v );
550
+ }
551
+ else {
552
+ // Invalid input - Show error message ?
553
+ unset( $valid_input['category_ids'][$k] );
554
+ }
555
+ }
556
+ }*/
557
+ unset( $valid_input['category_ids'] );
558
  }
559
 
560
  //echo '<pre>'.print_r($input,1).'</pre>';
562
 
563
 
564
 
565
+ /* Section 4 options */
566
  if ( !isset( $input['logo'] ) || !in_array( $input['logo'], array( 'favicon', 'upload-an-image' ) ) )
567
  $valid_input['logo'] = 'favicon';
568
 
572
 
573
  // @todo validate optional tagline text
574
  if ( !isset( $input['tagline'] ) ) {
575
+ $valid_input['tagline'] = '';
576
  }
577
  /* else {
578
 
592
  foreach( array( 'click_to_delete', 'hide-images', 'email', 'pdf', 'print', ) as $opt ) {
593
  if( !isset( $input[$opt] ) || !in_array( $input[$opt], array( '0', '1' ) ) ) {
594
  $valid_input[$opt] = '0';
595
+ }
596
  }
597
  unset( $opt );
598
 
603
 
604
 
605
 
606
+ /* Section 5 options */
607
  if ( !isset( $input['website_protocol'] ) || !in_array( $input['website_protocol'], array( 'http', 'https' ) ) )
608
  $valid_input['website_protocol'] = 'http';
609
 
613
  if ( !isset( $input['javascript'] ) || !in_array( $input['javascript'], array( 'no', 'yes' ) ) )
614
  $valid_input['javascript'] = 'yes';
615
 
616
+ /*Analytics Options */
617
+ if ( !isset( $input['enable_google_analytics'] ) || !in_array( $input['enable_google_analytics'], array( 'no', 'yes' ) ) ) {
618
+ $valid_input['enable_google_analytics'] = "no";
619
+ }
620
+
621
+ if ( !isset( $input['pf_algo'] ) || !in_array( $input['pf_algo'], array( 'wp', 'pf' ) ) ) {
622
+ $valid_input['pf_algo'] = "wp";
623
+ }
624
+
625
+ /* Database version */
626
  $valid_input['db_version'] = $this->db_version;
627
 
628
  return $valid_input;
728
  'password_protected' => 'no',
729
  'javascript' => 'yes',
730
  'custom_css_url' => '',
731
+ 'enable_google_analytics' => 'no',
732
+ 'pf_algo' => 'wp'
733
  // 'category_ids' => array('all'),
734
  );
735
 
851
  'category_ids' => array(),
852
  );
853
 
854
+ if( !isset( $this->options['category_ids'] ) || ( isset( $this->options['category_ids'] ) && 0 === count( $this->options['category_ids'] ) ) ) {
855
  $additional_options['category_ids'][] = 'all';
856
+ }
857
 
858
  $this->options = array_merge($this->options, $additional_options);
859
  */
871
  $this->options = array_merge($this->options, $additional_options);
872
  }
873
  if($this->options['db_version'] < 8) {
874
+ $this->options['enable_google_analytics'] = 'no';
875
+ }
876
 
877
  if($this->options['db_version'] < 9) {
878
+ $this->options['pf_algo'] = 'wp';
879
+ }
880
  $this->options['db_version'] = $this->db_version;
881
 
882
  update_option( $this->option_name, $this->options );
910
  function button( $name = false ){
911
  if( !$name )
912
  $name = $this->options['button_type'];
913
+ $button_css = $this->generic_button_css();
914
  $text = $this->options['custom_text'];
915
  $img_path = 'http://cdn.printfriendly.com/';
916
  if($this->options['website_protocol'] == 'https')
948
  }
949
  }
950
 
951
+ /**
952
+ *
953
+ *
954
+ **/
955
+
956
+ function generic_button_css() {
957
+ return "border:none;-webkit-box-shadow:none; box-shadow:none;";
958
+ }
959
 
960
 
961
  /**
1014
  *
1015
  */
1016
  function create_checkbox($name, $label='', $labelid='' ) {
1017
+ $label = ( !empty( $label) ? $label : __( ucfirst($name), $this->hook ) );
1018
  echo '<label' . ( !empty( $labelid ) ? ' id=' . $labelid : '' ) . '><input type="checkbox" class="show_list" name="' . $this->option_name . '[show_on_' . $name . ']" value="on" ';
1019
  $this->checked( 'show_on_' . $name, 'on');
1020
  echo ' />' . $label . "</label>\r\n";
1086
  * @since 3.2.2
1087
  */
1088
  function create_category_metabox() {
1089
+ $obj = new stdClass();
1090
+ $obj->ID = 0;
1091
  do_meta_boxes('settings_page_' . $this->hook, 'normal', $obj);
1092
  }
1093
 
1122
 
1123
  // Show the content of the options array when debug is enabled
1124
  if ( WP_DEBUG ) {
1125
+ echo "<p>Currently in Debug Mode. Following information is visible in debug mode only:</p>";
1126
  echo '<pre>Options:<br><br>' . print_r( $this->options, 1 ) . '</pre>';
1127
+ }
1128
  ?>
1129
  <div id="pf_settings" class="wrap">
1130
 
1270
  </select>
1271
  </label>
1272
  <?php /* <div class="custom-logo">
1273
+ <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' ); ?>" />
1274
+ <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' ); ?>" />
1275
+ </div> */ ?>
1276
  <div class="custom-logo"><label for="Enter_URL">Enter url</label><input id="upload-an-image" type="text" class="regular-text" name="<?php echo $this->option_name; ?>[image_url]" value="<?php $this->val( 'image_url' ); ?>" /><label for="Text__optional_">Text (optional)</label><input id="image-tagline" type="text" class="regular-text" name="<?php echo $this->option_name; ?>[tagline]" value="<?php $this->val( 'tagline' ); ?>" /></div>
1277
  <div id="pf-image-error"></div>
1278
  <div id="pf-image-preview"></div>
1362
  <option value="no" <?php $this->selected( 'enable_google_analytics', 'no' ); ?>> <?php _e( "No", $this->hook ); ?></option>
1363
  </select>
1364
  </label>
1365
+
1366
  <label id="pf-algo-usage" <?php /*for="javascript"*/ ?>>My Page Content Selected By: <span class="description no-italics" > Change this setting if your content is not showing in the preview.</span><br>
1367
  <select id="pf-algo-usage" name="<?php echo $this->option_name; ?>[pf_algo]">
1368
  <option value="wp" <?php $this->selected( 'pf_algo', 'wp' ); ?>> <?php _e( 'WP "the_content" filter
1369
+ ', $this->hook ); ?></option>
1370
  <option value="pf" <?php $this->selected( 'pf_algo', 'pf' ); ?>> <?php _e( "Content Algorithm", $this->hook ); ?></option>
1371
  </select>
1372
  </label>
1402
  global $printfriendly;
1403
  return $printfriendly->getButton(true);
1404
  }
 
readme.txt CHANGED
@@ -2,8 +2,8 @@
2
  Contributors: printfriendly,joostdevalk, jrf
3
  Tags: print, pdf, printer, printing, printable, widget, plugin
4
  Requires at least: 2.8
5
- Tested up to: 4.1
6
- Stable tag: 3.3.9
7
 
8
 
9
  The #1 Print and PDF button for your WordPress site. Printer Friendly pages without coding, css, or print.css. Fast, easy, and professional.
@@ -140,6 +140,10 @@ If you have any other issues with the plugin or the PrintFriendly widget, please
140
 
141
  == Changelog ==
142
 
 
 
 
 
143
  = 3.3.9 =
144
  * Removed the functionality that opens new window when JavaScript is disabled
145
 
@@ -334,3 +338,4 @@ If you have any other issues with the plugin or the PrintFriendly widget, please
334
  * To avoid conflicts with Google Analytics widgets, changed link structure. No longer uses onclick to call PrintFriendly Javascript. Now the javascript is called in the href.
335
  * Custom image support for hosted solutions
336
 
 
2
  Contributors: printfriendly,joostdevalk, jrf
3
  Tags: print, pdf, printer, printing, printable, widget, plugin
4
  Requires at least: 2.8
5
+ Tested up to: 4.1.2
6
+ Stable tag: 3.3.10
7
 
8
 
9
  The #1 Print and PDF button for your WordPress site. Printer Friendly pages without coding, css, or print.css. Fast, easy, and professional.
140
 
141
  == Changelog ==
142
 
143
+ = 3.3.10 =
144
+ * Implemented both Classic Google Analytics and Google Universal Analytics code
145
+ * Fixed WP Slimstat conflict
146
+
147
  = 3.3.9 =
148
  * Removed the functionality that opens new window when JavaScript is disabled
149
 
338
  * To avoid conflicts with Google Analytics widgets, changed link structure. No longer uses onclick to call PrintFriendly Javascript. Now the javascript is called in the href.
339
  * Custom image support for hosted solutions
340
 
341
+