WP-Print - Version 2.58

Version Description

  • NEW: Ability to print thumbnail. Props @MatthieuMota.
Download this release

Release Info

Developer GamerZ
Plugin Icon WP-Print
Version 2.58
Comparing to
See all releases

Code changes from version 2.57.2 to 2.58

Files changed (6) hide show
  1. print-css.css +5 -0
  2. print-options.php +10 -0
  3. print-posts.php +9 -1
  4. readme.txt +21 -125
  5. uninstall.php +3 -2
  6. wp-print.php +312 -305
print-css.css CHANGED
@@ -41,6 +41,11 @@ a { color: inherit; }
41
  padding: 0 2%;
42
  }
43
 
 
 
 
 
 
44
 
45
  /* content */
46
  .entry-content {
41
  padding: 0 2%;
42
  }
43
 
44
+ /* thumbnail */
45
+ .thumbnail {
46
+ text-align: center;
47
+ margin-bottom: 25px;
48
+ }
49
 
50
  /* content */
51
  .entry-content {
print-options.php CHANGED
@@ -18,6 +18,7 @@ if( ! empty( $_POST['Submit'] ) ) {
18
  $print_options['comments'] = isset( $_POST['print_comments'] ) ? intval( $_POST['print_comments'] ): 0;
19
  $print_options['links'] = isset( $_POST['print_links'] ) ? intval( $_POST['print_links'] ) : 1;
20
  $print_options['images'] = isset( $_POST['print_images'] ) ? intval( $_POST['print_images'] ) : 0;
 
21
  $print_options['videos'] = isset( $_POST['print_videos'] ) ? intval( $_POST['print_videos'] ) : 1;
22
  $print_options['disclaimer'] = ! empty( $_POST['print_disclaimer'] ) ? trim( $_POST['print_disclaimer'] ) : '';
23
  $update_print_queries = array();
@@ -162,6 +163,15 @@ $print_options = get_option( 'print_options' );
162
  </select>
163
  </td>
164
  </tr>
 
 
 
 
 
 
 
 
 
165
  <tr>
166
  <th scope="row" valign="top"><?php _e('Print Videos?', 'wp-print'); ?></th>
167
  <td>
18
  $print_options['comments'] = isset( $_POST['print_comments'] ) ? intval( $_POST['print_comments'] ): 0;
19
  $print_options['links'] = isset( $_POST['print_links'] ) ? intval( $_POST['print_links'] ) : 1;
20
  $print_options['images'] = isset( $_POST['print_images'] ) ? intval( $_POST['print_images'] ) : 0;
21
+ $print_options['thumbnail'] = isset( $_POST['print_thumbnail'] ) ? intval( $_POST['print_thumbnail'] ) : 0;
22
  $print_options['videos'] = isset( $_POST['print_videos'] ) ? intval( $_POST['print_videos'] ) : 1;
23
  $print_options['disclaimer'] = ! empty( $_POST['print_disclaimer'] ) ? trim( $_POST['print_disclaimer'] ) : '';
24
  $update_print_queries = array();
163
  </select>
164
  </td>
165
  </tr>
166
+ <tr>
167
+ <th scope="row" valign="top"><?php _e('Print Thumbnail?', 'wp-print'); ?></th>
168
+ <td>
169
+ <select name="print_thumbnail" size="1">
170
+ <option value="1"<?php selected('1', $print_options['thumbnail']); ?>><?php _e('Yes', 'wp-print'); ?></option>
171
+ <option value="0"<?php selected('0', $print_options['thumbnail']); ?>><?php _e('No', 'wp-print'); ?></option>
172
+ </select>
173
+ </td>
174
+ </tr>
175
  <tr>
176
  <th scope="row" valign="top"><?php _e('Print Videos?', 'wp-print'); ?></th>
177
  <td>
print-posts.php CHANGED
@@ -85,7 +85,15 @@ global $text_direction;
85
 
86
  </span>
87
 
88
- </header>
 
 
 
 
 
 
 
 
89
 
90
  <div class="entry-content">
91
 
85
 
86
  </span>
87
 
88
+ </header>
89
+
90
+ <?php if(print_can('thumbnail')): ?>
91
+ <?php if ( has_post_thumbnail() ) : ?>
92
+ <div class="thumbnail">
93
+ <?php the_post_thumbnail('medium'); ?>
94
+ </div>
95
+ <?php endif; ?>
96
+ <?php endif; ?>
97
 
98
  <div class="entry-content">
99
 
readme.txt CHANGED
@@ -2,37 +2,14 @@
2
  Contributors: GamerZ
3
  Donate link: http://lesterchan.net/site/donation/
4
  Tags: print, printer, wp-print
5
- Requires at least: 2.8
6
- Tested up to: 4.5
7
- Stable tag: 2.57.2
8
 
9
  Displays a printable version of your WordPress blog's post/page.
10
 
11
  == Description ==
12
 
13
- = Build Status =
14
- [![Build Status](https://travis-ci.org/lesterchan/wp-print.svg?branch=master)](https://travis-ci.org/lesterchan/wp-print)
15
-
16
- = Development =
17
- [https://github.com/lesterchan/wp-print](https://github.com/lesterchan/wp-print "https://github.com/lesterchan/wp-print")
18
-
19
- = Translations =
20
- [http://dev.wp-plugins.org/browser/wp-print/i18n/](http://dev.wp-plugins.org/browser/wp-print/i18n/ "http://dev.wp-plugins.org/browser/wp-print/i18n/")
21
-
22
- = Credits =
23
- * Plugin icon by [SimpleIcon](http://www.simpleicon.com) from [Flaticon](http://www.flaticon.com)
24
- * Icons courtesy of [FamFamFam](http://www.famfamfam.com/)
25
-
26
- = Donations =
27
- I spent most of my free time creating, updating, maintaining and supporting these plugins, if you really love my plugins and could spare me a couple of bucks as my school allowance, I will really appreciate it. If not feel free to use it without any obligations.
28
-
29
- == Installation ==
30
-
31
- You can either install it automatically from the WordPress admin, or do it manually:
32
-
33
- 1. Upload the whole `wp-print` directory into your plugins folder(`/wp-content/plugins/`)
34
- 1. Activate the plugin through the 'Plugins' menu in WordPress
35
-
36
  Once installed take the following steps to set it up:
37
 
38
  1. WP-Print settings page is located in WP-Admin -> Settings -> Print
@@ -51,6 +28,21 @@ Once installed take the following steps to set it up:
51
  * Alternatively, you can set the text in 'WP-Admin -> Settings -> Print'.
52
  * If you DO NOT want the print link to appear in every post/page, DO NOT use the code above. Just type in <strong>[print_link]</strong> into the selected post/page content and it will embed the print link into that post/page only.
53
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54
 
55
  == Screenshots ==
56
 
@@ -87,8 +79,10 @@ if(function_exists('wp_print')) {
87
  * If it doesn't exists, it will just load the respective default file that comes with WP-Print.
88
  * This will allow you to upgrade WP-Print without worrying about overwriting your printing styles or templates that you have created.
89
 
90
-
91
  == Changelog ==
 
 
 
92
  = 2.57.2 =
93
  * FIXED: Check both parent and child theme
94
 
@@ -128,101 +122,3 @@ if(function_exists('wp_print')) {
128
  * NEW: Use _n() Instead Of __ngettext() And _n_noop() Instead Of __ngettext_noop()
129
  * FIXED: Uses $_SERVER['PHP_SELF'] With plugin_basename(__FILE__) Instead Of Just $_SERVER['REQUEST_URI']
130
  * FIXED: Nested ShortCode Issues
131
-
132
- = 2.40 =
133
- * NEW: Works For WordPress 2.7 Only
134
- * NEW: Better Translation Using __ngetext() by Anna Ozeritskaya
135
- * NEW: Right To Left Language Support by Kambiz R. Khojasteh
136
- * NEW: Call print_textdomain() In print_init() by Kambiz R. Khojasteh
137
- * NEW: Replace "text_direction" Option With $text_direction And language_attributes() by Kambiz R. Khojasteh
138
- * NEW: Added "print-css-rtl.css" by Kambiz R. Khojasteh
139
- * NEW: Page Title Is Now "Post Title -> Print" Instead Of "Print -> Post Title" by Kambiz R. Khojasteh
140
- * NEW: Modified "print-css.css" To Hide "comments_controls" Element For Print by Kambiz R. Khojasteh
141
- * FIXED: Footnotes Referencing Is Now "link1 <sup>[1]</sup>" Instead Of "[1] link1" by Kambiz R. Khojasteh
142
- * FIXED: Remove chunk_split() As Browser Will Try To Wrap Word Boundaries Based On Page Width by Kambiz R. Khojasteh
143
- * FIXED: Remove [print_link] ShortCode In Print Pages
144
-
145
- = 2.31 =
146
- * NEW: Works For WordPress 2.6
147
- * NEW: Added donotprint ShortCode. See Usage Tab
148
- * NEW: WP-Print Will Load print-posts.php And print-comments.php Templates From Your Theme Directory First If The Exist
149
- * FIXED: Replace &lt;center&gt; With &lt;div style="margin: 0px auto 0px auto;"&gt;
150
-
151
- = 2.30 =
152
- * NEW: Works For WordPress 2.5 Only
153
- * NEW: WP-Print Will Load 'print-css.css' Inside Your Theme Directory If It Exists. If Not, It Will Just Load The Default 'print-css.css' By WP-Print
154
- * NEW: Uses Shortcode API
155
- * NEW: Added "Right To Left" And "Left To Right Text" Direction Option
156
- * NEW: Option To Remove Videos From Post
157
- * NEW: Duplicate Links Now Uses A Single Number And Printed Only Once By Constantinos Neophytou
158
- * NEW: &lt;IMG&gt; And &lt;A&gt; Tag Now Matches Single Quotes By Constantinos Neophytou
159
- * NEW: Uses /wp-print/ Folder Instead Of /print/
160
- * NEW: Uses wp-print.php Instead Of print.php
161
- * NEW: Changed wp-print.php To print-posts.php
162
- * NEW: Changed wp-print-comments.php To print-comments.php
163
- * NEW: Changed wp-print-css.css To print-css.css
164
- * FIXED: Comment Type Not Translated
165
-
166
- = 2.20 =
167
- * NEW: Works For WordPress 2.3 Only
168
- * NEW: Ability To Embed [print_link] Into Excerpt
169
- * NEW: wp-print-css.css Now Controls The CSS Styles For The Printer Friendly Page
170
- * NEW: Disclaimer/Copyright Text Option By Duane Craig
171
- * NEW: Anchor Link To Comments By Reinventia
172
- * NEW: Collapsable Comments By Reinventia
173
- * NEW: Ability To Uninstall WP-Print
174
- * FIXED: If There Is No Trailing Slash In Your Permalink, WP-Print Will Add It For You
175
-
176
- = 2.11 =
177
- * NEW: Putting [print_link] In Your Post/Page Content Will Display A Link To The Printable Post/Page
178
- * FIXED: Worked With Polyglot Plugin, Fixed By zeridon
179
- * FIXED: Wrong URL If Front Page Is A Static Page
180
-
181
- = 2.10 =
182
- * NEW: Added Fam Fam Fam's Printer Icon
183
- * NEW: Works For WordPress 2.1 Only
184
- * NEW: Localize WP-Print
185
- * NEW: Ability To Configure The Text For Print Links Via 'WP-Admin -> Options -> Print'
186
- * NEW: The Text For Print Links Can No Longer Be Pass To The Function print_link() or print_link_image()
187
- * FIXED: MUltiple URL Type Fixed By Virgil
188
- * FIXED: 'Click Here To Print' Will Be Hidden When Printing By Joe (Ttech)
189
-
190
- = 2.06 =
191
- * NEW: Used Default Date/Time Format Under WordPress Options
192
- * NEW: Added robots: noindex To Printer Friendly Pages
193
- * NEW: Added rel="nofollow" To All Links Generated By WP-Print
194
- * FIXED: &lt;abbr&gt; Tag Mixed Up With &lt;a&gt;
195
- * FIXED: PHP5 Compatibility Issue
196
- * FIXED: Long URL Will Not Break Into More Than 1 Line
197
-
198
- = 2.05 =
199
- * NEW: Added Print Options In WP Administration Panel Under 'Options -> Print'
200
- * NEW: Print Administration Panel And The Code That WP-Print Generated Is XHTML 1.0 Transitional
201
- * FIXED: Comment's Content Formatting
202
-
203
- = 2.04 =
204
- * NEW: Able To Print Comments Together With Post Using $can_print_comments In wp-print.php
205
- * NEW: Moved wp-print.php To Plugin Folder
206
- * FIXED: Removed Link From Post Comment Count And Post Category
207
-
208
- = 2.03 =
209
- * NEW: Added Print Image With print_link_image()
210
- * NEW: Automatically Break To Next Line If Link Contains More Than 100 Chars
211
- * FIXED: Comment Numbers Showing In Password Protected Post
212
-
213
- = 2.02 =
214
- * FIXED: Able To View Password Protected Blog
215
-
216
- = 2.01 =
217
- * NEW: Compatible With WordPress 2.0
218
- * NEW: Automatically Detect Whether You Are Using Nice Permalink
219
- * NEW: Automated Permalink
220
- * NEW: Now You Only Need To Insert 1 Line Into Your index.php Of Your Theme
221
- * NEW: GPL License Added
222
- * FIXED: Links Not Displaying Properly When Printing More Than 1 Post On A Single Page
223
-
224
- = 2.00a =
225
- * NEW: Permlink For The Page Feature
226
-
227
- = 2.00 =
228
- * NEW: Print Out A Summary Of URLS In The Post At The Bottom Of The Page
2
  Contributors: GamerZ
3
  Donate link: http://lesterchan.net/site/donation/
4
  Tags: print, printer, wp-print
5
+ Requires at least: 4.0
6
+ Tested up to: 4.7
7
+ Stable tag: 2.58
8
 
9
  Displays a printable version of your WordPress blog's post/page.
10
 
11
  == Description ==
12
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
  Once installed take the following steps to set it up:
14
 
15
  1. WP-Print settings page is located in WP-Admin -> Settings -> Print
28
  * Alternatively, you can set the text in 'WP-Admin -> Settings -> Print'.
29
  * If you DO NOT want the print link to appear in every post/page, DO NOT use the code above. Just type in <strong>[print_link]</strong> into the selected post/page content and it will embed the print link into that post/page only.
30
 
31
+ = Build Status =
32
+ [![Build Status](https://travis-ci.org/lesterchan/wp-print.svg?branch=master)](https://travis-ci.org/lesterchan/wp-print)
33
+
34
+ = Development =
35
+ [https://github.com/lesterchan/wp-print](https://github.com/lesterchan/wp-print "https://github.com/lesterchan/wp-print")
36
+
37
+ = Translations =
38
+ [http://dev.wp-plugins.org/browser/wp-print/i18n/](http://dev.wp-plugins.org/browser/wp-print/i18n/ "http://dev.wp-plugins.org/browser/wp-print/i18n/")
39
+
40
+ = Credits =
41
+ * Plugin icon by [SimpleIcon](http://www.simpleicon.com) from [Flaticon](http://www.flaticon.com)
42
+ * Icons courtesy of [FamFamFam](http://www.famfamfam.com/)
43
+
44
+ = Donations =
45
+ I spent most of my free time creating, updating, maintaining and supporting these plugins, if you really love my plugins and could spare me a couple of bucks as my school allowance, I will really appreciate it. If not feel free to use it without any obligations.
46
 
47
  == Screenshots ==
48
 
79
  * If it doesn't exists, it will just load the respective default file that comes with WP-Print.
80
  * This will allow you to upgrade WP-Print without worrying about overwriting your printing styles or templates that you have created.
81
 
 
82
  == Changelog ==
83
+ = 2.58 =
84
+ * NEW: Ability to print thumbnail. Props @MatthieuMota.
85
+
86
  = 2.57.2 =
87
  * FIXED: Check both parent and child theme
88
 
122
  * NEW: Use _n() Instead Of __ngettext() And _n_noop() Instead Of __ngettext_noop()
123
  * FIXED: Uses $_SERVER['PHP_SELF'] With plugin_basename(__FILE__) Instead Of Just $_SERVER['REQUEST_URI']
124
  * FIXED: Nested ShortCode Issues
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
uninstall.php CHANGED
@@ -8,11 +8,12 @@ if ( !defined( 'WP_UNINSTALL_PLUGIN' ) )
8
  $option_name = 'print_options';
9
 
10
  if ( is_multisite() ) {
11
- $ms_sites = wp_get_sites();
12
 
13
  if( 0 < sizeof( $ms_sites ) ) {
14
  foreach ( $ms_sites as $ms_site ) {
15
- switch_to_blog( $ms_site['blog_id'] );
 
16
  delete_option( $option_name );
17
  }
18
  }
8
  $option_name = 'print_options';
9
 
10
  if ( is_multisite() ) {
11
+ $ms_sites = function_exists( 'get_sites' ) ? get_sites() : wp_get_sites();
12
 
13
  if( 0 < sizeof( $ms_sites ) ) {
14
  foreach ( $ms_sites as $ms_site ) {
15
+ $blog_id = isset( $ms_site['blog_id'] ) ? $ms_site['blog_id'] : $ms_site->blog_id;
16
+ switch_to_blog( $blog_id );
17
  delete_option( $option_name );
18
  }
19
  }
wp-print.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: WP-Print
4
  Plugin URI: http://lesterchan.net/portfolio/programming/php/
5
  Description: Displays a printable version of your WordPress blog's post/page.
6
- Version: 2.57.2
7
  Author: Lester 'GaMerZ' Chan
8
  Author URI: http://lesterchan.net
9
  Text Domain: wp-print
@@ -11,426 +11,433 @@ Text Domain: wp-print
11
 
12
 
13
  /*
14
- Copyright 2016 Lester Chan (email : lesterchan@gmail.com)
15
 
16
- This program is free software; you can redistribute it and/or modify
17
- it under the terms of the GNU General Public License as published by
18
- the Free Software Foundation; either version 2 of the License, or
19
- (at your option) any later version.
20
 
21
- This program is distributed in the hope that it will be useful,
22
- but WITHOUT ANY WARRANTY; without even the implied warranty of
23
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24
- GNU General Public License for more details.
25
 
26
- You should have received a copy of the GNU General Public License
27
- along with this program; if not, write to the Free Software
28
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29
  */
30
 
31
 
32
  ### Create Text Domain For Translations
33
  add_action( 'plugins_loaded', 'print_textdomain' );
34
  function print_textdomain() {
35
- load_plugin_textdomain( 'wp-print' );
36
  }
37
 
38
 
39
  ### Function: Print Option Menu
40
  add_action('admin_menu', 'print_menu');
41
  function print_menu() {
42
- add_options_page(__('Print', 'wp-print'), __('Print', 'wp-print'), 'manage_options', 'wp-print/print-options.php') ;
43
  }
44
 
45
 
46
  ### Function: Add htaccess Rewrite Endpoint - this handles all the rules
47
  add_action( 'init', 'wp_print_endpoint' );
48
  function wp_print_endpoint() {
49
- add_rewrite_endpoint( 'print', EP_PERMALINK | EP_PAGES );
50
  }
51
 
52
 
53
  ### Function: Print Public Variables
54
  add_filter('query_vars', 'print_variables');
55
  function print_variables($public_query_vars) {
56
- $public_query_vars[] = 'print';
57
- return $public_query_vars;
58
  }
59
 
60
 
61
  ### Function: Display Print Link
62
  function print_link($print_post_text = '', $print_page_text = '', $echo = true) {
63
- $polyglot_append = '';
64
- if (function_exists('polyglot_get_lang')){
65
- global $polyglot_settings;
66
- $polyglot_append = $polyglot_settings['uri_helpers']['lang_view'].'/'.polyglot_get_lang().'/';
67
- }
68
- $output = '';
69
- $using_permalink = get_option('permalink_structure');
70
- $print_options = get_option('print_options');
71
- $print_style = intval($print_options['print_style']);
72
- if(empty($print_post_text)) {
73
- $print_text = stripslashes($print_options['post_text']);
74
- } else {
75
- $print_text = $print_post_text;
76
- }
77
- $print_icon = plugins_url('wp-print/images/'.$print_options['print_icon']);
78
- $print_link = get_permalink();
79
- $print_html = stripslashes($print_options['print_html']);
80
- // Fix For Static Page
81
- if(get_option('show_on_front') == 'page' && is_page()) {
82
- if(intval(get_option('page_on_front')) > 0) {
83
- $print_link = _get_page_link();
84
- }
85
- }
86
- if(!empty($using_permalink)) {
87
- if(substr($print_link, -1, 1) != '/') {
88
- $print_link = $print_link.'/';
89
- }
90
- if(is_page()) {
91
- if(empty($print_page_text)) {
92
- $print_text = stripslashes($print_options['page_text']);
93
- } else {
94
- $print_text = $print_page_text;
95
- }
96
- }
97
- $print_link = $print_link.'print/'.$polyglot_append;
98
- } else {
99
- if(is_page()) {
100
- if(empty($print_page_text)) {
101
- $print_text = stripslashes($print_options['page_text']);
102
- } else {
103
- $print_text = $print_page_text;
104
- }
105
- }
106
- $print_link = $print_link.'&amp;print=1';
107
- }
108
- unset($print_options);
109
- switch($print_style) {
110
- // Icon + Text Link
111
- case 1:
112
- $output = '<a href="'.$print_link.'" title="'.$print_text.'" rel="nofollow"><img class="WP-PrintIcon" src="'.$print_icon.'" alt="'.$print_text.'" title="'.$print_text.'" style="border: 0px;" /></a>&nbsp;<a href="'.$print_link.'" title="'.$print_text.'" rel="nofollow">'.$print_text.'</a>';
113
- break;
114
- // Icon Only
115
- case 2:
116
- $output = '<a href="'.$print_link.'" title="'.$print_text.'" rel="nofollow"><img class="WP-PrintIcon" src="'.$print_icon.'" alt="'.$print_text.'" title="'.$print_text.'" style="border: 0px;" /></a>';
117
- break;
118
- // Text Link Only
119
- case 3:
120
- $output = '<a href="'.$print_link.'" title="'.$print_text.'" rel="nofollow">'.$print_text.'</a>';
121
- break;
122
- case 4:
123
- $print_html = str_replace("%PRINT_URL%", $print_link, $print_html);
124
- $print_html = str_replace("%PRINT_TEXT%", $print_text, $print_html);
125
- $print_html = str_replace("%PRINT_ICON_URL%", $print_icon, $print_html);
126
- $output = $print_html;
127
- break;
128
- }
129
- if($echo) {
130
- echo $output."\n";
131
- } else {
132
- return $output;
133
- }
134
  }
135
 
136
 
137
  ### Function: Short Code For Inserting Prink Links Into Posts/Pages
138
  add_shortcode('print_link', 'print_link_shortcode');
139
  function print_link_shortcode($atts) {
140
- if(!is_feed()) {
141
- return print_link('', '', false);
142
- } else {
143
- return __('Note: There is a print link embedded within this post, please visit this post to print it.', 'wp-print');
144
- }
145
  }
146
  function print_link_shortcode2($atts) {
147
- return;
148
  }
149
 
150
 
151
  ### Function: Short Code For DO NOT PRINT Content
152
  add_shortcode('donotprint', 'print_donotprint_shortcode');
153
  function print_donotprint_shortcode($atts, $content = null) {
154
- return do_shortcode($content);
155
  }
156
  function print_donotprint_shortcode2($atts, $content = null) {
157
- return;
158
  }
159
 
160
 
161
  ### Function: Print Content
162
  function print_content($display = true) {
163
- global $links_text, $link_number, $max_link_number, $matched_links, $pages, $multipage, $numpages, $post;
164
- if (!isset($matched_links)) {
165
- $matched_links = array();
166
- }
167
- if(post_password_required()) {
168
- $content = get_the_password_form();
169
- } else {
170
- if($multipage) {
171
- for($page = 0; $page < $numpages; $page++) {
172
- $content .= $pages[$page];
173
- }
174
- } else {
175
- $content = $pages[0];
176
- }
177
- if(function_exists('email_rewrite')) {
178
- remove_shortcode('donotemail');
179
- add_shortcode('donotemail', 'email_donotemail_shortcode2');
180
- }
181
- remove_shortcode('donotprint');
182
- add_shortcode('donotprint', 'print_donotprint_shortcode2');
183
- remove_shortcode('print_link');
184
- add_shortcode('print_link', 'print_link_shortcode2');
185
- $content = apply_filters('the_content', $content);
186
- $content = str_replace(']]>', ']]&gt;', $content);
187
- if(!print_can('images')) {
188
- $content = remove_image($content);
189
- }
190
- if(!print_can('videos')) {
191
- $content = remove_video($content);
192
- }
193
- if(print_can('links')) {
194
- preg_match_all('/<a(.+?)href=[\"\'](.+?)[\"\'](.*?)>(.+?)<\/a>/', $content, $matches);
195
- for ($i=0; $i < count($matches[0]); $i++) {
196
- $link_match = $matches[0][$i];
197
- $link_url = $matches[2][$i];
198
- if(substr($link_url, 0, 2) == '//') {
199
- $link_url = (is_ssl() ? 'https:' : 'http:') . $link_url;
200
- } elseif(stristr($link_url, 'https://')) {
201
- $link_url =(strtolower(substr($link_url,0,8)) != 'https://') ?get_option('home') . $link_url : $link_url;
202
- } else if(stristr($link_url, 'mailto:')) {
203
- $link_url =(strtolower(substr($link_url,0,7)) != 'mailto:') ?get_option('home') . $link_url : $link_url;
204
- } else if($link_url[0] == '#') {
205
- $link_url = $link_url;
206
- } else {
207
- $link_url =(strtolower(substr($link_url,0,7)) != 'http://') ?get_option('home') . $link_url : $link_url;
208
- }
209
- $link_text = $matches[4][$i];
210
- $new_link = true;
211
- $link_url_hash = md5($link_url);
212
- if (!isset($matched_links[$link_url_hash])) {
213
- $link_number = ++$max_link_number;
214
- $matched_links[$link_url_hash] = $link_number;
215
- } else {
216
- $new_link = false;
217
- $link_number = $matched_links[$link_url_hash];
218
- }
219
- $content = str_replace_one($link_match, "<a href=\"$link_url\" rel=\"external\">".$link_text.'</a> <sup>['.number_format_i18n($link_number).']</sup>', $content);
220
- if ($new_link) {
221
- if(preg_match('/<img(.+?)src=[\"\'](.+?)[\"\'](.*?)>/',$link_text)) {
222
- $links_text .= '<p style="margin: 2px 0;">['.number_format_i18n($link_number).'] '.__('Image', 'wp-print').': <b><span dir="ltr">'.$link_url.'</span></b></p>';
223
- } else {
224
- $links_text .= '<p style="margin: 2px 0;">['.number_format_i18n($link_number).'] '.$link_text.': <b><span dir="ltr">'.$link_url.'</span></b></p>';
225
- }
226
- }
227
- }
228
- }
229
- }
230
- if($display) {
231
- echo $content;
232
- } else {
233
- return $content;
234
- }
 
235
  }
236
 
237
 
238
  ### Function: Print Categories
239
  function print_categories($before = '', $after = '') {
240
- $temp_cat = strip_tags(get_the_category_list(','));
241
- $temp_cat = explode(', ', $temp_cat);
242
- $temp_cat = implode($after.__(',', 'wp-print').' '.$before, $temp_cat);
243
- echo $before.$temp_cat.$after;
244
  }
245
 
246
 
247
  ### Function: Print Comments Content
248
  function print_comments_content($display = true) {
249
- global $links_text, $link_number, $max_link_number, $matched_links;
250
- if (!isset($matched_links)) {
251
- $matched_links = array();
252
- }
253
- $content = get_comment_text();
254
- $content = apply_filters('comment_text', $content);
255
- if(!print_can('images')) {
256
- $content = remove_image($content);
257
- }
258
- if(!print_can('videos')) {
259
- $content = remove_video($content);
260
- }
261
- if(print_can('links')) {
262
- preg_match_all('/<a(.+?)href=[\"\'](.+?)[\"\'](.*?)>(.+?)<\/a>/', $content, $matches);
263
- for ($i=0; $i < count($matches[0]); $i++) {
264
- $link_match = $matches[0][$i];
265
- $link_url = $matches[2][$i];
266
- if(stristr($link_url, 'https://')) {
267
- $link_url =(strtolower(substr($link_url,0,8)) != 'https://') ?get_option('home') . $link_url : $link_url;
268
- } else if(stristr($link_url, 'mailto:')) {
269
- $link_url =(strtolower(substr($link_url,0,7)) != 'mailto:') ?get_option('home') . $link_url : $link_url;
270
- } else if($link_url[0] == '#') {
271
- $link_url = $link_url;
272
- } else {
273
- $link_url =(strtolower(substr($link_url,0,7)) != 'http://') ?get_option('home') . $link_url : $link_url;
274
- }
275
- $new_link = true;
276
- $link_url_hash = md5($link_url);
277
- if (!isset($matched_links[$link_url_hash])) {
278
- $link_number = ++$max_link_number;
279
- $matched_links[$link_url_hash] = $link_number;
280
- } else {
281
- $new_link = false;
282
- $link_number = $matched_links[$link_url_hash];
283
- }
284
- $content = str_replace_one($link_match, "<a href=\"$link_url\" rel=\"external\">".$link_text.'</a> <sup>['.number_format_i18n($link_number).']</sup>', $content);
285
- if ($new_link) {
286
- if(preg_match('/<img(.+?)src=[\"\'](.+?)[\"\'](.*?)>/',$link_text)) {
287
- $links_text .= '<p style="margin: 2px 0;">['.number_format_i18n($link_number).'] '.__('Image', 'wp-print').': <b><span dir="ltr">'.$link_url.'</span></b></p>';
288
- } else {
289
- $links_text .= '<p style="margin: 2px 0;">['.number_format_i18n($link_number).'] '.$link_text.': <b><span dir="ltr">'.$link_url.'</span></b></p>';
290
- }
291
- }
292
- }
293
- }
294
- if($display) {
295
- echo $content;
296
- } else {
297
- return $content;
298
- }
299
  }
300
 
301
 
302
  ### Function: Print Comments
303
  function print_comments_number() {
304
- global $post;
305
- $comment_text = '';
306
- $comment_status = $post->comment_status;
307
- if($comment_status == 'open') {
308
- $num_comments = get_comments_number();
309
- if($num_comments == 0) {
310
- $comment_text = __('No Comments', 'wp-print');
311
- } else {
312
- $comment_text = sprintf(_n('%s Comment', '%s Comments', $num_comments, 'wp-print'), number_format_i18n($num_comments));
313
- }
314
- } else {
315
- $comment_text = __('Comments Disabled', 'wp-print');
316
- }
317
- if(post_password_required()) {
318
- _e('Comments Hidden', 'wp-print');
319
- } else {
320
- echo $comment_text;
321
- }
322
  }
323
 
324
 
325
  ### Function: Print Links
326
  function print_links($text_links = '') {
327
- global $links_text;
328
- if(empty($text_links)) {
329
- $text_links = __('URLs in this post:', 'wp-print');
330
- }
331
- if(!empty($links_text)) {
332
- echo $text_links.$links_text;
333
- }
334
  }
335
 
336
 
337
  ### Function: Load WP-Print
338
  add_action('template_redirect', 'wp_print', 5);
339
  function wp_print() {
340
- global $wp_query;
341
- if( array_key_exists( 'print' , $wp_query->query_vars ) ) {
342
- include(WP_PLUGIN_DIR.'/wp-print/print.php');
343
- exit();
344
- }
345
  }
346
 
347
 
348
  ### Function: Add Print Comments Template
349
  function print_template_comments() {
350
- if(file_exists(get_stylesheet_directory().'/print-comments.php')) {
351
- $file = get_stylesheet_directory().'/print-comments.php';
352
- } else {
353
- $file = WP_PLUGIN_DIR.'/wp-print/print-comments.php';
354
- }
355
- return $file;
356
  }
357
 
358
 
359
  ### Function: Print Page Title
360
  function print_pagetitle($page_title) {
361
- $page_title .= ' &raquo; '.__('Print', 'wp-print');
362
- return $page_title;
363
  }
364
 
365
 
366
  ### Function: Can Print?
367
  function print_can($type) {
368
- $print_options = get_option('print_options');
369
- return intval($print_options[$type]);
 
 
 
 
370
  }
371
 
372
 
373
  ### Function: Remove Image From Text
374
  function remove_image($content) {
375
- $content= preg_replace('/<img(.+?)src=[\"\'](.+?)[\"\'](.*?)>/', '',$content);
376
- return $content;
377
  }
378
 
379
 
380
  ### Function: Remove Video From Text
381
  function remove_video($content) {
382
- $content= preg_replace('/<object[^>]*?>.*?<\/object>/', '',$content);
383
- $content= preg_replace('/<embed[^>]*?>.*?<\/embed>/', '',$content);
384
- return $content;
385
  }
386
 
387
 
388
  ### Function: Replace One Time Only
389
  function str_replace_one($search, $replace, $content){
390
- if ($pos = strpos($content, $search)) {
391
- return substr($content, 0, $pos).$replace.substr($content, $pos+strlen($search));
392
- } else {
393
- return $content;
394
- }
395
  }
396
 
397
 
398
  ### Function: Activate Plugin
399
  register_activation_hook( __FILE__, 'print_activation' );
400
  function print_activation( $network_wide ) {
401
- // Add Options
402
- $option_name = 'print_options';
403
- $option = array(
404
- 'post_text' => __('Print This Post', 'wp-print'),
405
- 'page_text' => __('Print This Page', 'wp-print'),
406
- 'print_icon' => 'print.gif',
407
- 'print_style' => 1,
408
- 'print_html' => '<a href="%PRINT_URL%" rel="nofollow" title="%PRINT_TEXT%">%PRINT_TEXT%</a>',
409
- 'comments' => 0,
410
- 'links' => 1,
411
- 'images' => 1,
412
- 'videos' => 0,
413
- 'disclaimer' => sprintf(__('Copyright &copy; %s %s. All rights reserved.', 'wp-print'), date('Y'), get_option('blogname'))
414
- );
415
-
416
- if ( is_multisite() && $network_wide ) {
417
- $ms_sites = wp_get_sites();
418
-
419
- if( 0 < sizeof( $ms_sites ) ) {
420
- foreach ( $ms_sites as $ms_site ) {
421
- switch_to_blog( $ms_site['blog_id'] );
422
- add_option( $option_name, $option );
423
- print_activate();
424
- }
425
- }
426
-
427
- restore_current_blog();
428
- } else {
429
- add_option( $option_name, $option );
430
- print_activate();
431
- }
 
 
432
  }
433
 
434
  function print_activate() {
435
- flush_rewrite_rules();
436
  }
3
  Plugin Name: WP-Print
4
  Plugin URI: http://lesterchan.net/portfolio/programming/php/
5
  Description: Displays a printable version of your WordPress blog's post/page.
6
+ Version: 2.58
7
  Author: Lester 'GaMerZ' Chan
8
  Author URI: http://lesterchan.net
9
  Text Domain: wp-print
11
 
12
 
13
  /*
14
+ Copyright 2016 Lester Chan (email : lesterchan@gmail.com)
15
 
16
+ This program is free software; you can redistribute it and/or modify
17
+ it under the terms of the GNU General Public License as published by
18
+ the Free Software Foundation; either version 2 of the License, or
19
+ (at your option) any later version.
20
 
21
+ This program is distributed in the hope that it will be useful,
22
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
23
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24
+ GNU General Public License for more details.
25
 
26
+ You should have received a copy of the GNU General Public License
27
+ along with this program; if not, write to the Free Software
28
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29
  */
30
 
31
 
32
  ### Create Text Domain For Translations
33
  add_action( 'plugins_loaded', 'print_textdomain' );
34
  function print_textdomain() {
35
+ load_plugin_textdomain( 'wp-print' );
36
  }
37
 
38
 
39
  ### Function: Print Option Menu
40
  add_action('admin_menu', 'print_menu');
41
  function print_menu() {
42
+ add_options_page(__('Print', 'wp-print'), __('Print', 'wp-print'), 'manage_options', 'wp-print/print-options.php') ;
43
  }
44
 
45
 
46
  ### Function: Add htaccess Rewrite Endpoint - this handles all the rules
47
  add_action( 'init', 'wp_print_endpoint' );
48
  function wp_print_endpoint() {
49
+ add_rewrite_endpoint( 'print', EP_PERMALINK | EP_PAGES );
50
  }
51
 
52
 
53
  ### Function: Print Public Variables
54
  add_filter('query_vars', 'print_variables');
55
  function print_variables($public_query_vars) {
56
+ $public_query_vars[] = 'print';
57
+ return $public_query_vars;
58
  }
59
 
60
 
61
  ### Function: Display Print Link
62
  function print_link($print_post_text = '', $print_page_text = '', $echo = true) {
63
+ $polyglot_append = '';
64
+ if (function_exists('polyglot_get_lang')){
65
+ global $polyglot_settings;
66
+ $polyglot_append = $polyglot_settings['uri_helpers']['lang_view'].'/'.polyglot_get_lang().'/';
67
+ }
68
+ $output = '';
69
+ $using_permalink = get_option('permalink_structure');
70
+ $print_options = get_option('print_options');
71
+ $print_style = intval($print_options['print_style']);
72
+ if(empty($print_post_text)) {
73
+ $print_text = stripslashes($print_options['post_text']);
74
+ } else {
75
+ $print_text = $print_post_text;
76
+ }
77
+ $print_icon = plugins_url('wp-print/images/'.$print_options['print_icon']);
78
+ $print_link = get_permalink();
79
+ $print_html = stripslashes($print_options['print_html']);
80
+ // Fix For Static Page
81
+ if(get_option('show_on_front') == 'page' && is_page()) {
82
+ if(intval(get_option('page_on_front')) > 0) {
83
+ $print_link = _get_page_link();
84
+ }
85
+ }
86
+ if(!empty($using_permalink)) {
87
+ if(substr($print_link, -1, 1) != '/') {
88
+ $print_link = $print_link.'/';
89
+ }
90
+ if(is_page()) {
91
+ if(empty($print_page_text)) {
92
+ $print_text = stripslashes($print_options['page_text']);
93
+ } else {
94
+ $print_text = $print_page_text;
95
+ }
96
+ }
97
+ $print_link = $print_link.'print/'.$polyglot_append;
98
+ } else {
99
+ if(is_page()) {
100
+ if(empty($print_page_text)) {
101
+ $print_text = stripslashes($print_options['page_text']);
102
+ } else {
103
+ $print_text = $print_page_text;
104
+ }
105
+ }
106
+ $print_link = $print_link.'&amp;print=1';
107
+ }
108
+ unset($print_options);
109
+ switch($print_style) {
110
+ // Icon + Text Link
111
+ case 1:
112
+ $output = '<a href="'.$print_link.'" title="'.$print_text.'" rel="nofollow"><img class="WP-PrintIcon" src="'.$print_icon.'" alt="'.$print_text.'" title="'.$print_text.'" style="border: 0px;" /></a>&nbsp;<a href="'.$print_link.'" title="'.$print_text.'" rel="nofollow">'.$print_text.'</a>';
113
+ break;
114
+ // Icon Only
115
+ case 2:
116
+ $output = '<a href="'.$print_link.'" title="'.$print_text.'" rel="nofollow"><img class="WP-PrintIcon" src="'.$print_icon.'" alt="'.$print_text.'" title="'.$print_text.'" style="border: 0px;" /></a>';
117
+ break;
118
+ // Text Link Only
119
+ case 3:
120
+ $output = '<a href="'.$print_link.'" title="'.$print_text.'" rel="nofollow">'.$print_text.'</a>';
121
+ break;
122
+ case 4:
123
+ $print_html = str_replace("%PRINT_URL%", $print_link, $print_html);
124
+ $print_html = str_replace("%PRINT_TEXT%", $print_text, $print_html);
125
+ $print_html = str_replace("%PRINT_ICON_URL%", $print_icon, $print_html);
126
+ $output = $print_html;
127
+ break;
128
+ }
129
+ if($echo) {
130
+ echo $output."\n";
131
+ } else {
132
+ return $output;
133
+ }
134
  }
135
 
136
 
137
  ### Function: Short Code For Inserting Prink Links Into Posts/Pages
138
  add_shortcode('print_link', 'print_link_shortcode');
139
  function print_link_shortcode($atts) {
140
+ if(!is_feed()) {
141
+ return print_link('', '', false);
142
+ } else {
143
+ return __('Note: There is a print link embedded within this post, please visit this post to print it.', 'wp-print');
144
+ }
145
  }
146
  function print_link_shortcode2($atts) {
147
+ return;
148
  }
149
 
150
 
151
  ### Function: Short Code For DO NOT PRINT Content
152
  add_shortcode('donotprint', 'print_donotprint_shortcode');
153
  function print_donotprint_shortcode($atts, $content = null) {
154
+ return do_shortcode($content);
155
  }
156
  function print_donotprint_shortcode2($atts, $content = null) {
157
+ return;
158
  }
159
 
160
 
161
  ### Function: Print Content
162
  function print_content($display = true) {
163
+ global $links_text, $link_number, $max_link_number, $matched_links, $pages, $multipage, $numpages, $post;
164
+ if (!isset($matched_links)) {
165
+ $matched_links = array();
166
+ }
167
+ $content = '';
168
+ if(post_password_required()) {
169
+ $content = get_the_password_form();
170
+ } else {
171
+ if($multipage) {
172
+ for($page = 0; $page < $numpages; $page++) {
173
+ $content .= $pages[$page];
174
+ }
175
+ } else {
176
+ $content = $pages[0];
177
+ }
178
+ if(function_exists('email_rewrite')) {
179
+ remove_shortcode('donotemail');
180
+ add_shortcode('donotemail', 'email_donotemail_shortcode2');
181
+ }
182
+ remove_shortcode('donotprint');
183
+ add_shortcode('donotprint', 'print_donotprint_shortcode2');
184
+ remove_shortcode('print_link');
185
+ add_shortcode('print_link', 'print_link_shortcode2');
186
+ $content = apply_filters('the_content', $content);
187
+ $content = str_replace(']]>', ']]&gt;', $content);
188
+ if(!print_can('images')) {
189
+ $content = remove_image($content);
190
+ }
191
+ if(!print_can('videos')) {
192
+ $content = remove_video($content);
193
+ }
194
+ if(print_can('links')) {
195
+ preg_match_all('/<a(.+?)href=[\"\'](.+?)[\"\'](.*?)>(.+?)<\/a>/', $content, $matches);
196
+ for ($i=0; $i < count($matches[0]); $i++) {
197
+ $link_match = $matches[0][$i];
198
+ $link_url = $matches[2][$i];
199
+ if(substr($link_url, 0, 2) == '//') {
200
+ $link_url = (is_ssl() ? 'https:' : 'http:') . $link_url;
201
+ } elseif(stristr($link_url, 'https://')) {
202
+ $link_url =(strtolower(substr($link_url,0,8)) != 'https://') ?get_option('home') . $link_url : $link_url;
203
+ } else if(stristr($link_url, 'mailto:')) {
204
+ $link_url =(strtolower(substr($link_url,0,7)) != 'mailto:') ?get_option('home') . $link_url : $link_url;
205
+ } else if($link_url[0] == '#') {
206
+ $link_url = $link_url;
207
+ } else {
208
+ $link_url =(strtolower(substr($link_url,0,7)) != 'http://') ?get_option('home') . $link_url : $link_url;
209
+ }
210
+ $link_text = $matches[4][$i];
211
+ $new_link = true;
212
+ $link_url_hash = md5($link_url);
213
+ if (!isset($matched_links[$link_url_hash])) {
214
+ $link_number = ++$max_link_number;
215
+ $matched_links[$link_url_hash] = $link_number;
216
+ } else {
217
+ $new_link = false;
218
+ $link_number = $matched_links[$link_url_hash];
219
+ }
220
+ $content = str_replace_one($link_match, "<a href=\"$link_url\" rel=\"external\">".$link_text.'</a> <sup>['.number_format_i18n($link_number).']</sup>', $content);
221
+ if ($new_link) {
222
+ if(preg_match('/<img(.+?)src=[\"\'](.+?)[\"\'](.*?)>/',$link_text)) {
223
+ $links_text .= '<p style="margin: 2px 0;">['.number_format_i18n($link_number).'] '.__('Image', 'wp-print').': <b><span dir="ltr">'.$link_url.'</span></b></p>';
224
+ } else {
225
+ $links_text .= '<p style="margin: 2px 0;">['.number_format_i18n($link_number).'] '.$link_text.': <b><span dir="ltr">'.$link_url.'</span></b></p>';
226
+ }
227
+ }
228
+ }
229
+ }
230
+ }
231
+ if($display) {
232
+ echo $content;
233
+ } else {
234
+ return $content;
235
+ }
236
  }
237
 
238
 
239
  ### Function: Print Categories
240
  function print_categories($before = '', $after = '') {
241
+ $temp_cat = strip_tags(get_the_category_list(','));
242
+ $temp_cat = explode(', ', $temp_cat);
243
+ $temp_cat = implode($after.__(',', 'wp-print').' '.$before, $temp_cat);
244
+ echo $before.$temp_cat.$after;
245
  }
246
 
247
 
248
  ### Function: Print Comments Content
249
  function print_comments_content($display = true) {
250
+ global $links_text, $link_number, $max_link_number, $matched_links;
251
+ if (!isset($matched_links)) {
252
+ $matched_links = array();
253
+ }
254
+ $content = get_comment_text();
255
+ $content = apply_filters('comment_text', $content);
256
+ if(!print_can('images')) {
257
+ $content = remove_image($content);
258
+ }
259
+ if(!print_can('videos')) {
260
+ $content = remove_video($content);
261
+ }
262
+ if(print_can('links')) {
263
+ preg_match_all('/<a(.+?)href=[\"\'](.+?)[\"\'](.*?)>(.+?)<\/a>/', $content, $matches);
264
+ for ($i=0; $i < count($matches[0]); $i++) {
265
+ $link_match = $matches[0][$i];
266
+ $link_url = $matches[2][$i];
267
+ if(stristr($link_url, 'https://')) {
268
+ $link_url =(strtolower(substr($link_url,0,8)) != 'https://') ?get_option('home') . $link_url : $link_url;
269
+ } else if(stristr($link_url, 'mailto:')) {
270
+ $link_url =(strtolower(substr($link_url,0,7)) != 'mailto:') ?get_option('home') . $link_url : $link_url;
271
+ } else if($link_url[0] == '#') {
272
+ $link_url = $link_url;
273
+ } else {
274
+ $link_url =(strtolower(substr($link_url,0,7)) != 'http://') ?get_option('home') . $link_url : $link_url;
275
+ }
276
+ $new_link = true;
277
+ $link_url_hash = md5($link_url);
278
+ if (!isset($matched_links[$link_url_hash])) {
279
+ $link_number = ++$max_link_number;
280
+ $matched_links[$link_url_hash] = $link_number;
281
+ } else {
282
+ $new_link = false;
283
+ $link_number = $matched_links[$link_url_hash];
284
+ }
285
+ $content = str_replace_one($link_match, "<a href=\"$link_url\" rel=\"external\">".$link_text.'</a> <sup>['.number_format_i18n($link_number).']</sup>', $content);
286
+ if ($new_link) {
287
+ if(preg_match('/<img(.+?)src=[\"\'](.+?)[\"\'](.*?)>/',$link_text)) {
288
+ $links_text .= '<p style="margin: 2px 0;">['.number_format_i18n($link_number).'] '.__('Image', 'wp-print').': <b><span dir="ltr">'.$link_url.'</span></b></p>';
289
+ } else {
290
+ $links_text .= '<p style="margin: 2px 0;">['.number_format_i18n($link_number).'] '.$link_text.': <b><span dir="ltr">'.$link_url.'</span></b></p>';
291
+ }
292
+ }
293
+ }
294
+ }
295
+ if($display) {
296
+ echo $content;
297
+ } else {
298
+ return $content;
299
+ }
300
  }
301
 
302
 
303
  ### Function: Print Comments
304
  function print_comments_number() {
305
+ global $post;
306
+ $comment_text = '';
307
+ $comment_status = $post->comment_status;
308
+ if($comment_status == 'open') {
309
+ $num_comments = get_comments_number();
310
+ if($num_comments == 0) {
311
+ $comment_text = __('No Comments', 'wp-print');
312
+ } else {
313
+ $comment_text = sprintf(_n('%s Comment', '%s Comments', $num_comments, 'wp-print'), number_format_i18n($num_comments));
314
+ }
315
+ } else {
316
+ $comment_text = __('Comments Disabled', 'wp-print');
317
+ }
318
+ if(post_password_required()) {
319
+ _e('Comments Hidden', 'wp-print');
320
+ } else {
321
+ echo $comment_text;
322
+ }
323
  }
324
 
325
 
326
  ### Function: Print Links
327
  function print_links($text_links = '') {
328
+ global $links_text;
329
+ if(empty($text_links)) {
330
+ $text_links = __('URLs in this post:', 'wp-print');
331
+ }
332
+ if(!empty($links_text)) {
333
+ echo $text_links.$links_text;
334
+ }
335
  }
336
 
337
 
338
  ### Function: Load WP-Print
339
  add_action('template_redirect', 'wp_print', 5);
340
  function wp_print() {
341
+ global $wp_query;
342
+ if( array_key_exists( 'print' , $wp_query->query_vars ) ) {
343
+ include(WP_PLUGIN_DIR.'/wp-print/print.php');
344
+ exit();
345
+ }
346
  }
347
 
348
 
349
  ### Function: Add Print Comments Template
350
  function print_template_comments() {
351
+ if(file_exists(get_stylesheet_directory().'/print-comments.php')) {
352
+ $file = get_stylesheet_directory().'/print-comments.php';
353
+ } else {
354
+ $file = WP_PLUGIN_DIR.'/wp-print/print-comments.php';
355
+ }
356
+ return $file;
357
  }
358
 
359
 
360
  ### Function: Print Page Title
361
  function print_pagetitle($page_title) {
362
+ $page_title .= ' &raquo; '.__('Print', 'wp-print');
363
+ return $page_title;
364
  }
365
 
366
 
367
  ### Function: Can Print?
368
  function print_can($type) {
369
+ $print_options = get_option( 'print_options' );
370
+ if ( isset( $print_options[$type] ) ) {
371
+ return (int) $print_options[$type];
372
+ }
373
+
374
+ return 0;
375
  }
376
 
377
 
378
  ### Function: Remove Image From Text
379
  function remove_image($content) {
380
+ $content= preg_replace('/<img(.+?)src=[\"\'](.+?)[\"\'](.*?)>/', '',$content);
381
+ return $content;
382
  }
383
 
384
 
385
  ### Function: Remove Video From Text
386
  function remove_video($content) {
387
+ $content= preg_replace('/<object[^>]*?>.*?<\/object>/', '',$content);
388
+ $content= preg_replace('/<embed[^>]*?>.*?<\/embed>/', '',$content);
389
+ return $content;
390
  }
391
 
392
 
393
  ### Function: Replace One Time Only
394
  function str_replace_one($search, $replace, $content){
395
+ if ($pos = strpos($content, $search)) {
396
+ return substr($content, 0, $pos).$replace.substr($content, $pos+strlen($search));
397
+ } else {
398
+ return $content;
399
+ }
400
  }
401
 
402
 
403
  ### Function: Activate Plugin
404
  register_activation_hook( __FILE__, 'print_activation' );
405
  function print_activation( $network_wide ) {
406
+ // Add Options
407
+ $option_name = 'print_options';
408
+ $option = array(
409
+ 'post_text' => __('Print This Post', 'wp-print'),
410
+ 'page_text' => __('Print This Page', 'wp-print'),
411
+ 'print_icon' => 'print.gif',
412
+ 'print_style' => 1,
413
+ 'print_html' => '<a href="%PRINT_URL%" rel="nofollow" title="%PRINT_TEXT%">%PRINT_TEXT%</a>',
414
+ 'comments' => 0,
415
+ 'links' => 1,
416
+ 'images' => 1,
417
+ 'thumbnail' => 0,
418
+ 'videos' => 0,
419
+ 'disclaimer' => sprintf(__('Copyright &copy; %s %s. All rights reserved.', 'wp-print'), date('Y'), get_option('blogname'))
420
+ );
421
+
422
+ if ( is_multisite() && $network_wide ) {
423
+ $ms_sites = function_exists( 'get_sites' ) ? get_sites() : wp_get_sites();
424
+
425
+ if( 0 < sizeof( $ms_sites ) ) {
426
+ foreach ( $ms_sites as $ms_site ) {
427
+ $blog_id = isset( $ms_site['blog_id'] ) ? $ms_site['blog_id'] : $ms_site->blog_id;
428
+ switch_to_blog( $blog_id );
429
+ add_option( $option_name, $option );
430
+ print_activate();
431
+ }
432
+ }
433
+
434
+ restore_current_blog();
435
+ } else {
436
+ add_option( $option_name, $option );
437
+ print_activate();
438
+ }
439
  }
440
 
441
  function print_activate() {
442
+ flush_rewrite_rules();
443
  }