Version Description
- FIXED: Notices
Download this release
Release Info
Developer | GamerZ |
Plugin | WP-Print |
Version | 2.57 |
Comparing to | |
See all releases |
Code changes from version 2.56 to 2.57
- print-options.php +19 -19
- readme.txt +6 -3
- wp-print.php +295 -301
print-options.php
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
### Variables Variables Variables
|
3 |
$base_name = plugin_basename('wp-print/print-options.php');
|
4 |
$base_page = 'admin.php?page='.$base_name;
|
5 |
-
$mode =
|
6 |
$print_settings = array('print_options');
|
7 |
|
8 |
|
@@ -11,34 +11,34 @@ $print_settings = array('print_options');
|
|
11 |
if(!empty($_POST['Submit'])) {
|
12 |
check_admin_referer('wp-print_options');
|
13 |
$print_options = array();
|
14 |
-
$print_options['post_text']
|
15 |
-
$print_options['page_text']
|
16 |
-
$print_options['print_icon']
|
17 |
-
$print_options['print_style']
|
18 |
-
$print_options['print_html']
|
19 |
-
$print_options['comments']
|
20 |
-
$print_options['links']
|
21 |
-
$print_options['images']
|
22 |
-
$print_options['videos']
|
23 |
-
$print_options['disclaimer']
|
24 |
$update_print_queries = array();
|
25 |
$update_print_text = array();
|
26 |
-
$update_print_queries[] = update_option('print_options', $print_options);
|
27 |
-
$update_print_text[] = __('Print Options', 'wp-print');
|
28 |
$i=0;
|
29 |
$text = '';
|
30 |
-
foreach($update_print_queries as $update_print_query) {
|
31 |
-
if($update_print_query) {
|
32 |
-
$text .= '<p style="color: green;">'
|
33 |
}
|
34 |
$i++;
|
35 |
}
|
36 |
-
if(empty($text)) {
|
37 |
-
$text = '<p style="color: red;">'.__('No Print Option Updated', 'wp-print').'</p>';
|
38 |
}
|
39 |
}
|
40 |
|
41 |
-
$print_options = get_option('print_options');
|
42 |
?>
|
43 |
<script type="text/javascript">
|
44 |
/* <![CDATA[*/
|
2 |
### Variables Variables Variables
|
3 |
$base_name = plugin_basename('wp-print/print-options.php');
|
4 |
$base_page = 'admin.php?page='.$base_name;
|
5 |
+
$mode = ! empty( $_GET['mode'] ) ? trim( $_GET['mode'] ) : '';
|
6 |
$print_settings = array('print_options');
|
7 |
|
8 |
|
11 |
if(!empty($_POST['Submit'])) {
|
12 |
check_admin_referer('wp-print_options');
|
13 |
$print_options = array();
|
14 |
+
$print_options['post_text'] = ! empty( $_POST['print_post_text'] ) ? addslashes( trim( wp_filter_kses( $_POST['print_post_text'] ) ) ) : '';
|
15 |
+
$print_options['page_text'] = ! empty( $_POST['print_page_text'] ) ? addslashes( trim( wp_filter_kses( $_POST['print_page_text'] ) ) ) : '';
|
16 |
+
$print_options['print_icon'] = ! empty( $_POST['print_icon'] ) ? trim( $_POST['print_icon'] ) : '';
|
17 |
+
$print_options['print_style'] = ! empty( $_POST['print_style'] ) ? intval($_POST['print_style']) : 1;
|
18 |
+
$print_options['print_html'] = ! empty( $_POST['print_html'] ) ? trim($_POST['print_html']) : '';
|
19 |
+
$print_options['comments'] = ! empty( $_POST['print_comments'] ) ? intval($_POST['print_comments']): 0;
|
20 |
+
$print_options['links'] = ! empty( $_POST['print_links'] ) ? intval($_POST['print_links']) : 1;
|
21 |
+
$print_options['images'] = ! empty( $_POST['print_images'] ) ? intval($_POST['print_images']) : 0;
|
22 |
+
$print_options['videos'] = ! empty( $_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();
|
25 |
$update_print_text = array();
|
26 |
+
$update_print_queries[] = update_option( 'print_options', $print_options );
|
27 |
+
$update_print_text[] = __( 'Print Options', 'wp-print' );
|
28 |
$i=0;
|
29 |
$text = '';
|
30 |
+
foreach( $update_print_queries as $update_print_query ) {
|
31 |
+
if( $update_print_query ) {
|
32 |
+
$text .= '<p style="color: green;">' . $update_print_text[$i] . ' ' .__('Updated', 'wp-print') . '</p>';
|
33 |
}
|
34 |
$i++;
|
35 |
}
|
36 |
+
if( empty( $text ) ) {
|
37 |
+
$text = '<p style="color: red;">' . __('No Print Option Updated', 'wp-print') . '</p>';
|
38 |
}
|
39 |
}
|
40 |
|
41 |
+
$print_options = get_option( 'print_options' );
|
42 |
?>
|
43 |
<script type="text/javascript">
|
44 |
/* <![CDATA[*/
|
readme.txt
CHANGED
@@ -3,8 +3,8 @@ 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.
|
7 |
-
Stable tag: 2.
|
8 |
|
9 |
Displays a printable version of your WordPress blog's post/page.
|
10 |
|
@@ -89,7 +89,10 @@ if(function_exists('wp_print')) {
|
|
89 |
|
90 |
|
91 |
== Changelog ==
|
92 |
-
= 2.
|
|
|
|
|
|
|
93 |
* NEW: Updated print HTML code. Props @Luanramos
|
94 |
|
95 |
= 2.55 =
|
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.4
|
7 |
+
Stable tag: 2.57
|
8 |
|
9 |
Displays a printable version of your WordPress blog's post/page.
|
10 |
|
89 |
|
90 |
|
91 |
== Changelog ==
|
92 |
+
= 2.57 =
|
93 |
+
* FIXED: Notices
|
94 |
+
|
95 |
+
= 2.56 =
|
96 |
* NEW: Updated print HTML code. Props @Luanramos
|
97 |
|
98 |
= 2.55 =
|
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.
|
7 |
Author: Lester 'GaMerZ' Chan
|
8 |
Author URI: http://lesterchan.net
|
9 |
Text Domain: wp-print
|
@@ -11,7 +11,7 @@ Text Domain: wp-print
|
|
11 |
|
12 |
|
13 |
/*
|
14 |
-
|
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
|
@@ -32,411 +32,405 @@ Text Domain: wp-print
|
|
32 |
### Create Text Domain For Translations
|
33 |
add_action( 'plugins_loaded', 'print_textdomain' );
|
34 |
function print_textdomain() {
|
35 |
-
|
36 |
}
|
37 |
|
38 |
|
39 |
### Function: Print Option Menu
|
40 |
add_action('admin_menu', 'print_menu');
|
41 |
function print_menu() {
|
42 |
-
|
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 |
-
|
50 |
}
|
51 |
|
52 |
|
53 |
### Function: Print Public Variables
|
54 |
add_filter('query_vars', 'print_variables');
|
55 |
function print_variables($public_query_vars) {
|
56 |
-
|
57 |
-
|
58 |
}
|
59 |
|
60 |
|
61 |
### Function: Display Print Link
|
62 |
function print_link($print_post_text = '', $print_page_text = '', $echo = true) {
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
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 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
}
|
146 |
function print_link_shortcode2($atts) {
|
147 |
-
|
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 |
-
|
155 |
}
|
156 |
function print_donotprint_shortcode2($atts, $content = null) {
|
157 |
-
|
158 |
}
|
159 |
|
160 |
|
161 |
### Function: Print Content
|
162 |
function print_content($display = true) {
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
}
|
236 |
|
237 |
|
238 |
### Function: Print Categories
|
239 |
function print_categories($before = '', $after = '') {
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
}
|
245 |
|
246 |
|
247 |
### Function: Print Comments Content
|
248 |
function print_comments_content($display = true) {
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
}
|
300 |
|
301 |
|
302 |
### Function: Print Comments
|
303 |
function print_comments_number() {
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
}
|
323 |
|
324 |
|
325 |
### Function: Print Links
|
326 |
function print_links($text_links = '') {
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
}
|
335 |
|
336 |
|
337 |
### Function: Load WP-Print
|
338 |
add_action('template_redirect', 'wp_print', 5);
|
339 |
function wp_print() {
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
}
|
346 |
|
347 |
|
348 |
### Function: Add Print Comments Template
|
349 |
function print_template_comments() {
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
}
|
357 |
|
358 |
|
359 |
### Function: Print Page Title
|
360 |
function print_pagetitle($page_title) {
|
361 |
-
|
362 |
-
|
363 |
}
|
364 |
|
365 |
|
366 |
### Function: Can Print?
|
367 |
function print_can($type) {
|
368 |
-
|
369 |
-
|
370 |
}
|
371 |
|
372 |
|
373 |
### Function: Remove Image From Text
|
374 |
function remove_image($content) {
|
375 |
-
|
376 |
-
|
377 |
}
|
378 |
|
379 |
|
380 |
### Function: Remove Video From Text
|
381 |
function remove_video($content) {
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
}
|
386 |
|
387 |
|
388 |
### Function: Replace One Time Only
|
389 |
function str_replace_one($search, $replace, $content){
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
}
|
396 |
|
397 |
|
398 |
### Function: Activate Plugin
|
399 |
register_activation_hook( __FILE__, 'print_activation' );
|
400 |
-
function print_activation( $network_wide )
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
}
|
433 |
-
else
|
434 |
-
{
|
435 |
-
add_option( $option_name, $option );
|
436 |
-
print_activate();
|
437 |
-
}
|
438 |
}
|
439 |
|
440 |
function print_activate() {
|
441 |
-
|
442 |
}
|
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
|
7 |
Author: Lester 'GaMerZ' Chan
|
8 |
Author URI: http://lesterchan.net
|
9 |
Text Domain: wp-print
|
11 |
|
12 |
|
13 |
/*
|
14 |
+
Copyright 2015 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
|
32 |
### Create Text Domain For Translations
|
33 |
add_action( 'plugins_loaded', 'print_textdomain' );
|
34 |
function print_textdomain() {
|
35 |
+
load_plugin_textdomain( 'wp-print', false, dirname( plugin_basename( __FILE__ ) ) );
|
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.'&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> <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(']]>', ']]>', $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 .= ' » '.__('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 © %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 |
}
|