PluginProbe
WP-Print / 2.11
WP-Print v2.11
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.11, at print/print.php

362 lines 11.9 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://www.lesterchan.net/portfolio/programming.php
5 Description: Displays a printable version of your WordPress blog's post/page.
6 Version: 2.11
7 Author: Lester 'GaMerZ' Chan
8 Author URI: http://www.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 load_plugin_textdomain('wp-print', 'wp-content/plugins/print');
33
34
35 ### Function: Print Option Menu
36 add_action('admin_menu', 'print_menu');
37 function print_menu() {
38 if (function_exists('add_options_page')) {
39 add_options_page(__('Print', 'wp-print'), __('Print', 'wp-print'), 'manage_options', 'print/print-options.php') ;
40 }
41 }
42
43
44 ### Function: Print htaccess ReWrite Rules
45 add_filter('generate_rewrite_rules', 'print_rewrite');
46 function print_rewrite($wp_rewrite) {
47 $r_rule = '';
48 $r_link = '';
49 $rewrite_rules2 = $wp_rewrite->generate_rewrite_rule($wp_rewrite->permalink_structure.'print');
50 array_splice($rewrite_rules2, 1);
51 $r_rule = array_keys($rewrite_rules2);
52 $r_rule = array_shift($r_rule);
53 $r_rule = str_replace('/trackback', '',$r_rule);
54 $r_link = array_values($rewrite_rules2);
55 $r_link = array_shift($r_link);
56 $r_link = str_replace('tb=1', 'print=1', $r_link);
57 $print_rules = array($r_rule => $r_link, '(.+)/printpage/?$' => 'index.php?pagename='.$wp_rewrite->preg_index(1).'&print=1');
58 $wp_rewrite->rules = $print_rules + $wp_rewrite->rules;
59 }
60
61
62 ### Function: Print Public Variables
63 add_filter('query_vars', 'print_variables');
64 function print_variables($public_query_vars) {
65 $public_query_vars[] = 'print';
66 return $public_query_vars;
67 }
68
69
70 ### Function: Display Print Link
71 function print_link($deprecated = '', $deprecated2 ='', $echo = true) {
72 global $id;
73 if (function_exists('polyglot_get_lang')){
74 global $polyglot_settings;
75 $polyglot_append = $polyglot_settings['uri_helpers']['lang_view'].'/'.polyglot_get_lang().'/';
76 }
77 $output = '';
78 $using_permalink = get_option('permalink_structure');
79 $print_options = get_option('print_options');
80 $print_style = intval($print_options['print_style']);
81 $print_text = stripslashes($print_options['post_text']);
82 $print_icon = get_option('siteurl').'/wp-content/plugins/print/images/'.$print_options['print_icon'];
83 $print_link = get_permalink();
84 $print_html = stripslashes($print_options['print_html']);
85 // Fix For Static Page
86 if(get_option('show_on_front') == 'page' && is_page()) {
87 if(intval(get_option('page_on_front')) > 0) {
88 $print_link = _get_page_link();
89 }
90 }
91 if(!empty($using_permalink)) {
92 if(is_page()) {
93 if(substr($print_link, -1, 1) != '/') {
94 $print_link = $print_link.'/';
95 }
96 $print_text = stripslashes($print_options['page_text']);
97 $print_link = $print_link.'printpage/'.$polyglot_append;
98 } else {
99 $print_link = $print_link.'print/'.$polyglot_append;
100 }
101 } else {
102 if(is_page()) {
103 $print_text = stripslashes($print_options['page_text']);
104 }
105 $print_link = $print_link.'&amp;print=1';
106 }
107 unset($print_options);
108 switch($print_style) {
109 // Icon + Text Link
110 case 1:
111 $output = '<img class="WP-PrintIcon" src="'.$print_icon.'" alt="'.$print_text.'" title="'.$print_text.'" style="border: 0px;" />&nbsp;<a href="'.$print_link.'" title="'.$print_text.'" rel="nofollow">'.$print_text.'</a>';
112 break;
113 // Icon Only
114 case 2:
115 $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>';
116 break;
117 // Text Link Only
118 case 3:
119 $output = '<a href="'.$print_link.'" title="'.$print_text.'" rel="nofollow">'.$print_text.'</a>';
120 break;
121 case 4:
122 $print_html = str_replace("%PRINT_URL%", $print_link, $print_html);
123 $print_html = str_replace("%PRINT_TEXT%", $print_text, $print_html);
124 $print_html = str_replace("%PRINT_ICON_URL%", $print_icon, $print_html);
125 $output = $print_html;
126 break;
127 }
128 if($echo) {
129 echo $output."\n";
130 } else {
131 return $output;
132 }
133 }
134
135
136 ### Function: Display Print Image Link (Deprecated)
137 function print_link_image() {
138 print_link();
139 }
140
141
142 ### Function: Place Print Link
143 add_filter('the_content', 'place_printlink', 7);
144 function place_printlink($content){
145 if(!is_feed()) {
146 $content = str_replace("[print_link]", print_link('', '', false), $content);
147 } else {
148 $content = str_replace("[print_link]", __('Note: You can print this post by visiting the site.', 'wp-print'), $content);
149 }
150 return $content;
151 }
152
153
154 ### Function: Print Content
155 function print_content($display = true) {
156 global $links_text, $link_number, $pages, $multipage, $numpages, $post;
157 $max_url_char = 80;
158 if(!empty($post->post_password) && stripslashes($_COOKIE['wp-postpass_'.COOKIEHASH]) != $post->post_password) {
159 $content = get_the_password_form();
160 } else {
161 if($multipage) {
162 for($page = 0; $page < $numpages; $page++) {
163 $content .= $pages[$page];
164 }
165 } else {
166 $content = $pages[0];
167 }
168 $content = apply_filters('the_content', $content);
169 $content = str_replace(']]>', ']]&gt;', $content);
170 if(!print_can('images')) {
171 $content = remove_image($content);
172 }
173 if(print_can('links')) {
174 preg_match_all('/<a(.+?)href=\"(.+?)\"(.*?)>(.+?)<\/a>/', $content, $matches);
175 for ($i=0; $i < count($matches[0]); $i++) {
176 $link_match = $matches[0][$i];
177 $link_number++;
178 $link_url = $matches[2][$i];
179 if(stristr($link_url, 'https://')) {
180 $link_url =(strtolower(substr($link_url,0,8)) != 'https://') ?get_option('home') . $link_url : $link_url;
181 } else if( stristr($link_url, 'mailto:')) {
182 $link_url =(strtolower(substr($link_url,0,7)) != 'mailto:') ?get_option('home') . $link_url : $link_url;
183 } else if( $link_url[0] == '#' ) {
184 $link_url = $link_url;
185 } else {
186 $link_url =(strtolower(substr($link_url,0,7)) != 'http://') ?get_option('home') . $link_url : $link_url;
187 }
188 $link_text = $matches[4][$i];
189 $content = str_replace_one($link_match, '['.$link_number."] <a href=\"$link_url\" rel=\"external\">".$link_text.'</a>', $content);
190 if(strlen($link_url) > 100) {
191 $link_url = chunk_split($link_url, 100, "<br />\n");
192 }
193 if(preg_match('/<img(.+?)src=\"(.+?)\"(.*?)>/',$link_text)) {
194 $links_text .= '<br />['.$link_number.'] '.__('Image', 'wp-print').': <b>'.$link_url.'</b>';
195 } else {
196 $links_text .= '<br />['.$link_number.'] '.$link_text.': <b>'.$link_url.'</b>';
197 }
198 }
199 }
200 }
201 if($display) {
202 echo $content;
203 } else {
204 return $content;
205 }
206 }
207
208
209 ### Function: Print Categories
210 function print_categories($before = '', $after = '') {
211 $temp_cat = strip_tags(get_the_category_list(',' , $parents));
212 $temp_cat = explode(', ', $temp_cat);
213 $temp_cat = implode($after.', '.$before, $temp_cat);
214 echo $before.$temp_cat.$after;
215 }
216
217
218 ### Function: Print Comments Content
219 function print_comments_content($display = true) {
220 global $links_text, $link_number;
221 $content = get_comment_text();
222 $content = apply_filters('comment_text', $content);
223 if(!print_can('images')) {
224 $content = remove_image($content);
225 }
226 if(print_can('links')) {
227 preg_match_all('/<a(.+?)href=\"(.+?)\"(.*?)>(.+?)<\/a>/', $content, $matches);
228 for ($i=0; $i < count($matches[0]); $i++) {
229 $link_match = $matches[0][$i];
230 $link_number++;
231 $link_url = $matches[2][$i];
232 if(stristr($link_url, 'https://')) {
233 $link_url =(strtolower(substr($link_url,0,8)) != 'https://') ?get_option('home') . $link_url : $link_url;
234 } else if(stristr($link_url, 'mailto:')) {
235 $link_url =(strtolower(substr($link_url,0,7)) != 'mailto:') ?get_option('home') . $link_url : $link_url;
236 } else if($link_url[0] == '#') {
237 $link_url = $link_url;
238 } else {
239 $link_url =(strtolower(substr($link_url,0,7)) != 'http://') ?get_option('home') . $link_url : $link_url;
240 }
241 $link_text = $matches[4][$i];
242 $content = str_replace_one($link_match, '['.$link_number."] <a href=\"$link_url\" rel=\"external\">".$link_text.'</a>', $content);
243 if(strlen($link_url) > 100) {
244 $link_url = chunk_split($link_url, 100, "<br />\n");
245 }
246 if(preg_match('/<img(.+?)src=\"(.+?)\"(.*?)>/',$link_text)) {
247 $links_text .= '<br />['.$link_number.'] '.__('Image', 'wp-print').': <b>'.$link_url.'</b>';
248 } else {
249 $links_text .= '<br />['.$link_number.'] '.$link_text.': <b>'.$link_url.'</b>';
250 }
251 }
252 }
253 if($display) {
254 echo $content;
255 } else {
256 return $content;
257 }
258 }
259
260
261 ### Function: Print Comments
262 function print_comments_number() {
263 global $post;
264 $comment_text = '';
265 $comment_status = $post->comment_status;
266 if($comment_status == 'open') {
267 $num_comments = get_comments_number();
268 if($num_comments == 0) {
269 $comment_text = __('No Comments', 'wp-print');
270 } elseif($num_comments == 1) {
271 $comment_text = __('1 Comment', 'wp-print');
272 } else {
273 $comment_text = sprintf(__('%s Comments', 'wp-print'), $num_comments);
274 }
275 } else {
276 $comment_text = __('Comments Disabled', 'wp-print');
277 }
278 if(!empty($post->post_password) && stripslashes($_COOKIE['wp-postpass_'.COOKIEHASH]) != $post->post_password) {
279 _e('Comments Hidden', 'wp-print');
280 } else {
281 echo $comment_text;
282 }
283 }
284
285
286 ### Function: Print Links
287 function print_links($text_links = '') {
288 global $links_text;
289 if(empty($text_links)) {
290 $text_links = __('URLs in this post:', 'wp-print');
291 }
292 if(!empty($links_text)) {
293 echo $text_links.$links_text;
294 }
295 }
296
297
298 ### Function: Load WP-Print
299 add_action('template_redirect', 'wp_print');
300 function wp_print() {
301 if(intval(get_query_var('print')) == 1) {
302 include(ABSPATH.'wp-content/plugins/print/wp-print.php');
303 exit;
304 }
305 }
306
307
308 ### Function: Add Print Comments Template
309 function print_template_comments($file = '') {
310 $file = ABSPATH.'wp-content/plugins/print/wp-print-comments.php';
311 return $file;
312 }
313
314
315 ### Function: Print Page Title
316 function print_pagetitle($print_pagetitle) {
317 return '&raquo; Print'.$print_pagetitle;
318 }
319
320
321 ### Function: Can Print?
322 function print_can($type) {
323 $print_options = get_option('print_options');
324 return intval($print_options[$type]);
325 }
326
327
328 ### Function: Remove Image From Text
329 function remove_image($content) {
330 $content= preg_replace('/<img(.+?)src=\"(.+?)\"(.*?)>/', '',$content);
331 return $content;
332 }
333
334
335 ### Function: Replace One Time Only
336 function str_replace_one($search, $replace, $content){
337 if ($pos = strpos($content, $search)) {
338 return substr($content, 0, $pos).$replace.substr($content, $pos+strlen($search));
339 } else {
340 return $content;
341 }
342 }
343
344
345 ### Function: Print Options
346 add_action('activate_print/print.php', 'print_init');
347 function print_init() {
348 // Delete Options First
349 delete_option('print_options');
350 // Add Options
351 $print_options = array();
352 $print_options['post_text'] = __('Print This Post', 'wp-print');
353 $print_options['page_text'] = __('Print This Page', 'wp-print');
354 $print_options['print_icon'] = 'print.gif';
355 $print_options['print_style'] = 1;
356 $print_options['print_html'] = '<a href="%PRINT_URL%" rel="nofollow" title="%PRINT_TEXT%">%PRINT_TEXT%</a>';
357 $print_options['comments'] = 0;
358 $print_options['links'] = 1;
359 $print_options['images'] = 1;
360 add_option('print_options', $print_options, 'Print Options');
361 }
362 ?>