PluginProbe
WP-Print / 2.20
WP-Print v2.20
3.0.0 trunk 1.00 2.00 2.01 2.02 2.03 2.04 2.05 2.06 2.10 2.11 2.20 2.30 2.31 2.40 2.50 2.52 2.53 2.54 2.55 2.56 2.57 2.57.1 2.57.2 All 29 releases
wp-print / print / print.php

print.php in WP-Print 2.20, at print/print.php

371 lines 12.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
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.20
7 Author: Lester 'GaMerZ' Chan
8 Author URI: http://lesterchan.net
9 */
10
11
12 /*
13 Copyright 2007 Lester Chan (email : gamerz84@hotmail.com)
14
15 This program is free software; you can redistribute it and/or modify
16 it under the terms of the GNU General Public License as published by
17 the Free Software Foundation; either version 2 of the License, or
18 (at your option) any later version.
19
20 This program is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 GNU General Public License for more details.
24
25 You should have received a copy of the GNU General Public License
26 along with this program; if not, write to the Free Software
27 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 */
29
30
31 ### Create Text Domain For Translations
32 add_action('init', 'print_textdomain');
33 function print_textdomain() {
34 load_plugin_textdomain('wp-print', 'wp-content/plugins/print');
35 }
36
37
38 ### Function: Print Option Menu
39 add_action('admin_menu', 'print_menu');
40 function print_menu() {
41 if (function_exists('add_options_page')) {
42 add_options_page(__('Print', 'wp-print'), __('Print', 'wp-print'), 'manage_options', 'print/print-options.php') ;
43 }
44 }
45
46
47 ### Function: Print htaccess ReWrite Rules
48 add_filter('generate_rewrite_rules', 'print_rewrite');
49 function print_rewrite($wp_rewrite) {
50 $r_rule = '';
51 $r_link = '';
52 $print_link = get_permalink();
53 if(substr($print_link, -1, 1) != '/' && substr($wp_rewrite->permalink_structure, -1, 1) != '/') {
54 $print_link_text = '/print';
55 } else {
56 $print_link_text = 'print';
57 }
58 $rewrite_rules2 = $wp_rewrite->generate_rewrite_rule($wp_rewrite->permalink_structure.$print_link_text);
59 array_splice($rewrite_rules2, 1);
60 $r_rule = array_keys($rewrite_rules2);
61 $r_rule = array_shift($r_rule);
62 $r_rule = str_replace('/trackback', '',$r_rule);
63 $r_link = array_values($rewrite_rules2);
64 $r_link = array_shift($r_link);
65 $r_link = str_replace('tb=1', 'print=1', $r_link);
66 $print_rules = array($r_rule => $r_link, '(.+)/printpage/?$' => 'index.php?pagename='.$wp_rewrite->preg_index(1).'&print=1');
67 $wp_rewrite->rules = $print_rules + $wp_rewrite->rules;
68 }
69
70
71 ### Function: Print Public Variables
72 add_filter('query_vars', 'print_variables');
73 function print_variables($public_query_vars) {
74 $public_query_vars[] = 'print';
75 return $public_query_vars;
76 }
77
78
79 ### Function: Display Print Link
80 function print_link($deprecated = '', $deprecated2 ='', $echo = true) {
81 global $id;
82 if (function_exists('polyglot_get_lang')){
83 global $polyglot_settings;
84 $polyglot_append = $polyglot_settings['uri_helpers']['lang_view'].'/'.polyglot_get_lang().'/';
85 }
86 $output = '';
87 $using_permalink = get_option('permalink_structure');
88 $print_options = get_option('print_options');
89 $print_style = intval($print_options['print_style']);
90 $print_text = stripslashes($print_options['post_text']);
91 $print_icon = get_option('siteurl').'/wp-content/plugins/print/images/'.$print_options['print_icon'];
92 $print_link = get_permalink();
93 $print_html = stripslashes($print_options['print_html']);
94 // Fix For Static Page
95 if(get_option('show_on_front') == 'page' && is_page()) {
96 if(intval(get_option('page_on_front')) > 0) {
97 $print_link = _get_page_link();
98 }
99 }
100 if(!empty($using_permalink)) {
101 if(substr($print_link, -1, 1) != '/') {
102 $print_link = $print_link.'/';
103 }
104 if(is_page()) {
105 $print_text = stripslashes($print_options['page_text']);
106 $print_link = $print_link.'printpage/'.$polyglot_append;
107 } else {
108 $print_link = $print_link.'print/'.$polyglot_append;
109 }
110 } else {
111 if(is_page()) {
112 $print_text = stripslashes($print_options['page_text']);
113 }
114 $print_link = $print_link.'&amp;print=1';
115 }
116 unset($print_options);
117 switch($print_style) {
118 // Icon + Text Link
119 case 1:
120 $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>';
121 break;
122 // Icon Only
123 case 2:
124 $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>';
125 break;
126 // Text Link Only
127 case 3:
128 $output = '<a href="'.$print_link.'" title="'.$print_text.'" rel="nofollow">'.$print_text.'</a>';
129 break;
130 case 4:
131 $print_html = str_replace("%PRINT_URL%", $print_link, $print_html);
132 $print_html = str_replace("%PRINT_TEXT%", $print_text, $print_html);
133 $print_html = str_replace("%PRINT_ICON_URL%", $print_icon, $print_html);
134 $output = $print_html;
135 break;
136 }
137 if($echo) {
138 echo $output."\n";
139 } else {
140 return $output;
141 }
142 }
143
144
145 ### Function: Display Print Image Link (Deprecated)
146 function print_link_image() {
147 print_link();
148 }
149
150
151 ### Function: Place Print Link
152 add_filter('the_content', 'place_printlink', 7);
153 add_filter('the_excerpt', 'place_printlink', 7);
154 function place_printlink($content){
155 if(!is_feed()) {
156 $content = str_replace("[print_link]", print_link('', '', false), $content);
157 } else {
158 $content = str_replace("[print_link]", __('Note: There is a print link embedded within this post, please visit this post to print it.', 'wp-print'), $content);
159 }
160 return $content;
161 }
162
163
164 ### Function: Print Content
165 function print_content($display = true) {
166 global $links_text, $link_number, $pages, $multipage, $numpages, $post;
167 $max_url_char = 80;
168 if(!empty($post->post_password) && stripslashes($_COOKIE['wp-postpass_'.COOKIEHASH]) != $post->post_password) {
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 $content = apply_filters('the_content', $content);
179 $content = str_replace(']]>', ']]&gt;', $content);
180 if(!print_can('images')) {
181 $content = remove_image($content);
182 }
183 if(print_can('links')) {
184 preg_match_all('/<a(.+?)href=\"(.+?)\"(.*?)>(.+?)<\/a>/', $content, $matches);
185 for ($i=0; $i < count($matches[0]); $i++) {
186 $link_match = $matches[0][$i];
187 $link_number++;
188 $link_url = $matches[2][$i];
189 if(stristr($link_url, 'https://')) {
190 $link_url =(strtolower(substr($link_url,0,8)) != 'https://') ?get_option('home') . $link_url : $link_url;
191 } else if( stristr($link_url, 'mailto:')) {
192 $link_url =(strtolower(substr($link_url,0,7)) != 'mailto:') ?get_option('home') . $link_url : $link_url;
193 } else if( $link_url[0] == '#' ) {
194 $link_url = $link_url;
195 } else {
196 $link_url =(strtolower(substr($link_url,0,7)) != 'http://') ?get_option('home') . $link_url : $link_url;
197 }
198 $link_text = $matches[4][$i];
199 $content = str_replace_one($link_match, '['.$link_number."] <a href=\"$link_url\" rel=\"external\">".$link_text.'</a>', $content);
200 if(strlen($link_url) > 100) {
201 $link_url = chunk_split($link_url, 100, "<br />\n");
202 }
203 if(preg_match('/<img(.+?)src=\"(.+?)\"(.*?)>/',$link_text)) {
204 $links_text .= '<br />['.$link_number.'] '.__('Image', 'wp-print').': <b>'.$link_url.'</b>';
205 } else {
206 $links_text .= '<br />['.$link_number.'] '.$link_text.': <b>'.$link_url.'</b>';
207 }
208 }
209 }
210 }
211 if($display) {
212 echo $content;
213 } else {
214 return $content;
215 }
216 }
217
218
219 ### Function: Print Categories
220 function print_categories($before = '', $after = '') {
221 $temp_cat = strip_tags(get_the_category_list(',' , $parents));
222 $temp_cat = explode(', ', $temp_cat);
223 $temp_cat = implode($after.', '.$before, $temp_cat);
224 echo $before.$temp_cat.$after;
225 }
226
227
228 ### Function: Print Comments Content
229 function print_comments_content($display = true) {
230 global $links_text, $link_number;
231 $content = get_comment_text();
232 $content = apply_filters('comment_text', $content);
233 if(!print_can('images')) {
234 $content = remove_image($content);
235 }
236 if(print_can('links')) {
237 preg_match_all('/<a(.+?)href=\"(.+?)\"(.*?)>(.+?)<\/a>/', $content, $matches);
238 for ($i=0; $i < count($matches[0]); $i++) {
239 $link_match = $matches[0][$i];
240 $link_number++;
241 $link_url = $matches[2][$i];
242 if(stristr($link_url, 'https://')) {
243 $link_url =(strtolower(substr($link_url,0,8)) != 'https://') ?get_option('home') . $link_url : $link_url;
244 } else if(stristr($link_url, 'mailto:')) {
245 $link_url =(strtolower(substr($link_url,0,7)) != 'mailto:') ?get_option('home') . $link_url : $link_url;
246 } else if($link_url[0] == '#') {
247 $link_url = $link_url;
248 } else {
249 $link_url =(strtolower(substr($link_url,0,7)) != 'http://') ?get_option('home') . $link_url : $link_url;
250 }
251 $link_text = $matches[4][$i];
252 $content = str_replace_one($link_match, '['.$link_number."] <a href=\"$link_url\" rel=\"external\">".$link_text.'</a>', $content);
253 if(strlen($link_url) > 100) {
254 $link_url = chunk_split($link_url, 100, "<br />\n");
255 }
256 if(preg_match('/<img(.+?)src=\"(.+?)\"(.*?)>/',$link_text)) {
257 $links_text .= '<br />['.$link_number.'] '.__('Image', 'wp-print').': <b>'.$link_url.'</b>';
258 } else {
259 $links_text .= '<br />['.$link_number.'] '.$link_text.': <b>'.$link_url.'</b>';
260 }
261 }
262 }
263 if($display) {
264 echo $content;
265 } else {
266 return $content;
267 }
268 }
269
270
271 ### Function: Print Comments
272 function print_comments_number() {
273 global $post;
274 $comment_text = '';
275 $comment_status = $post->comment_status;
276 if($comment_status == 'open') {
277 $num_comments = get_comments_number();
278 if($num_comments == 0) {
279 $comment_text = __('No Comments', 'wp-print');
280 } elseif($num_comments == 1) {
281 $comment_text = __('1 Comment', 'wp-print');
282 } else {
283 $comment_text = sprintf(__('%s Comments', 'wp-print'), $num_comments);
284 }
285 } else {
286 $comment_text = __('Comments Disabled', 'wp-print');
287 }
288 if(!empty($post->post_password) && stripslashes($_COOKIE['wp-postpass_'.COOKIEHASH]) != $post->post_password) {
289 _e('Comments Hidden', 'wp-print');
290 } else {
291 echo $comment_text;
292 }
293 }
294
295
296 ### Function: Print Links
297 function print_links($text_links = '') {
298 global $links_text;
299 if(empty($text_links)) {
300 $text_links = __('URLs in this post:', 'wp-print');
301 }
302 if(!empty($links_text)) {
303 echo $text_links.$links_text;
304 }
305 }
306
307
308 ### Function: Load WP-Print
309 add_action('template_redirect', 'wp_print');
310 function wp_print() {
311 if(intval(get_query_var('print')) == 1) {
312 include(ABSPATH.'wp-content/plugins/print/wp-print.php');
313 exit;
314 }
315 }
316
317
318 ### Function: Add Print Comments Template
319 function print_template_comments($file = '') {
320 $file = ABSPATH.'wp-content/plugins/print/wp-print-comments.php';
321 return $file;
322 }
323
324
325 ### Function: Print Page Title
326 function print_pagetitle($print_pagetitle) {
327 return '&raquo; Print'.$print_pagetitle;
328 }
329
330
331 ### Function: Can Print?
332 function print_can($type) {
333 $print_options = get_option('print_options');
334 return intval($print_options[$type]);
335 }
336
337
338 ### Function: Remove Image From Text
339 function remove_image($content) {
340 $content= preg_replace('/<img(.+?)src=\"(.+?)\"(.*?)>/', '',$content);
341 return $content;
342 }
343
344
345 ### Function: Replace One Time Only
346 function str_replace_one($search, $replace, $content){
347 if ($pos = strpos($content, $search)) {
348 return substr($content, 0, $pos).$replace.substr($content, $pos+strlen($search));
349 } else {
350 return $content;
351 }
352 }
353
354
355 ### Function: Print Options
356 add_action('activate_print/print.php', 'print_init');
357 function print_init() {
358 // Add Options
359 $print_options = array();
360 $print_options['post_text'] = __('Print This Post', 'wp-print');
361 $print_options['page_text'] = __('Print This Page', 'wp-print');
362 $print_options['print_icon'] = 'print.gif';
363 $print_options['print_style'] = 1;
364 $print_options['print_html'] = '<a href="%PRINT_URL%" rel="nofollow" title="%PRINT_TEXT%">%PRINT_TEXT%</a>';
365 $print_options['comments'] = 0;
366 $print_options['links'] = 1;
367 $print_options['images'] = 1;
368 $print_options['disclaimer'] = sprintf(__('Copyright &copy; %s %s. All rights reserved.', 'wp-print'), date('Y'), get_option('blogname'));
369 add_option('print_options', $print_options, 'Print Options');
370 }
371 ?>