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

275 lines 8.8 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 Weblog Post.
6 Version: 2.05
7 Author: GaMerZ
8 Author URI: http://www.lesterchan.net
9 */
10
11
12 /* Copyright 2006 Lester Chan (email : gamerz84@hotmail.com)
13
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 2 of the License, or
17 (at your option) any later version.
18
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with this program; if not, write to the Free Software
26 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 */
28
29
30 ### Function: Print Option Menu
31 add_action('admin_menu', 'print_menu');
32 function print_menu() {
33 if (function_exists('add_options_page')) {
34 add_options_page(__('Print'), __('Print'), 'manage_options', 'print/print-options.php') ;
35 }
36 }
37
38
39 ### Function: Print htaccess ReWrite Rules
40 add_filter('generate_rewrite_rules', 'print_rewrite');
41 function print_rewrite($wp_rewrite) {
42 $r_rule = '';
43 $r_link = '';
44 $rewrite_rules2 = $wp_rewrite->generate_rewrite_rule($wp_rewrite->permalink_structure.'print');
45 array_splice($rewrite_rules2, 1);
46 $r_rule = array_shift(array_keys($rewrite_rules2));
47 $r_rule = str_replace('/trackback', '',$r_rule);
48 $r_link = array_shift(array_values($rewrite_rules2));
49 $r_link = str_replace('tb=1', 'print=1', $r_link);
50 $print_rules = array($r_rule => $r_link, '(.+)/printpage/?$' => 'index.php?pagename='.$wp_rewrite->preg_index(1).'&print=1');
51 $wp_rewrite->rules = $print_rules + $wp_rewrite->rules;
52 }
53
54
55 ### Function: Print Public Variables
56 add_filter('query_vars', 'print_variables');
57 function print_variables($public_query_vars) {
58 $public_query_vars[] = 'print';
59 return $public_query_vars;
60 }
61
62
63 ### Function: Display Print Link
64 function print_link($text_post = 'Print This Post', $text_page = 'Print This Page') {
65 global $id;
66 $using_permalink = get_settings('permalink_structure');
67 $permalink = get_permalink();
68 if(!empty($using_permalink)) {
69 if(is_page()) {
70 echo '<a href="'.$permalink.'printpage/" title="'.$text_page.'">'.$text_page.'</a>';
71 } else {
72 echo '<a href="'.$permalink.'print/" title="'.$text_post.'">'.$text_post.'</a>';
73 }
74 } else {
75 echo '<a href="'.$permalink.'&amp;print=1" title="'.$text_post.'">'.$text_post.'</a>';
76 }
77 }
78
79
80 ### Function: Display Print Image Link
81 function print_link_image() {
82 global $id;
83 $using_permalink = get_settings('permalink_structure');
84 $permalink = get_permalink();
85 if(file_exists(ABSPATH.'/wp-content/plugins/print/images/print.gif')) {
86 $print_image = '<img src="'.get_settings('siteurl').'/wp-content/plugins/print/images/print.gif" alt="Print This Post/Page" />';
87 } else {
88 $print_image = 'Print';
89 }
90 if(!empty($using_permalink)) {
91 if(is_page()) {
92 echo '<a href="'.$permalink.'printpage/" title="Print This Page">'.$print_image.'</a>';
93 } else {
94 echo '<a href="'.$permalink.'print/" title="Print This Post">'.$print_image.'</a>';
95 }
96 } else {
97 echo '<a href="'.$permalink.'&amp;print=1" title="Print This Post/Page">'.$print_image.'</a>';
98 }
99 }
100
101
102 ### Function: Print Content
103 function print_content($display = true) {
104 global $links_text, $link_number, $pages, $multipage, $numpages, $post;
105 $max_url_char = 80;
106 if(!empty($post->post_password) && stripslashes($_COOKIE['wp-postpass_'.COOKIEHASH]) != $post->post_password) {
107 $content = get_the_password_form();
108 } else {
109 if($multipage) {
110 for($page = 0; $page < $numpages; $page++) {
111 $content .= $pages[$page];
112 }
113 } else {
114 $content = $pages[0];
115 }
116 $content = apply_filters('the_content', $content);
117 $content = str_replace(']]>', ']]&gt;', $content);
118 if(!print_can('images')) {
119 $content = remove_image($content);
120 }
121 if(print_can('links')) {
122 preg_match_all('/<a(.+?)href=\"(.+?)\"(.*?)>(.+?)<\/a>/', $content, $matches);
123 for ($i=0; $i < count($matches[0]); $i++) {
124 $link_match = $matches[0][$i];
125 $link_number++;
126 $link_url = $matches[2][$i];
127 $link_url = (strtolower(substr($link_url,0,7)) != 'http://') ? get_settings('home') . $link_url : $link_url;
128 $link_text = $matches[4][$i];
129 $content = str_replace($link_match, '['.$link_number."] <a href=\"$link_url\" target=\"_blank\">".$link_text.'</a>', $content);
130 if(strlen($link_url) > $max_url_char) {
131 $link_url = substr($link_url, 0, $max_url_char).'<br />'.substr($link_url, $max_url_char, strlen($link_url));
132 }
133 if(preg_match('/<img(.+?)src=\"(.+?)\"(.*?)>/',$link_text)) {
134 $links_text .= '<br />['.$link_number.'] '.__('Image').': <b>'.$link_url.'</b>';
135 } else {
136 $links_text .= '<br />['.$link_number.'] '.$link_text.': <b>'.$link_url.'</b>';
137 }
138 }
139 }
140 }
141 if($display) {
142 echo $content;
143 } else {
144 return $content;
145 }
146 }
147
148
149 ### Function: Print Categories
150 function print_categories($before = '', $after = '') {
151 $temp_cat = strip_tags(get_the_category_list(',' , $parents));
152 $temp_cat = explode(', ', $temp_cat);
153 $temp_cat = implode($after.', '.$before, $temp_cat);
154 echo $before.$temp_cat.$after;
155 }
156
157
158 ### Function: Print Comments Content
159 function print_comments_content($display = true) {
160 global $links_text, $link_number;
161 $max_url_char = 100;
162 $content = get_comment_text();
163 $content = apply_filters('comment_text', $content);
164 if(!print_can('images')) {
165 $content = remove_image($content);
166 }
167 if(print_can('links')) {
168 preg_match_all('/<a(.+?)href=\"(.+?)\"(.*?)>(.+?)<\/a>/', $content, $matches);
169 for ($i=0; $i < count($matches[0]); $i++) {
170 $link_match = $matches[0][$i];
171 $link_number++;
172 $link_url = $matches[2][$i];
173 $link_url = (strtolower(substr($link_url,0,7)) != 'http://') ? get_settings('home') . $link_url : $link_url;
174 $link_text = $matches[4][$i];
175 $content = str_replace($link_match, '['.$link_number."] <a href=\"$link_url\" target=\"_blank\">".$link_text.'</a>', $content);
176 if(strlen($link_url) > $max_url_char) {
177 $link_url = substr($link_url, 0, $max_url_char).'<br />'.substr($link_url, $max_url_char, strlen($link_url));
178 }
179 if(preg_match('/<img(.+?)src=\"(.+?)\"(.*?)>/',$link_text)) {
180 $links_text .= '<br />['.$link_number.'] '.__('Image').': <b>'.$link_url.'</b>';
181 } else {
182 $links_text .= '<br />['.$link_number.'] '.$link_text.': <b>'.$link_url.'</b>';
183 }
184 }
185 }
186 if($display) {
187 echo $content;
188 } else {
189 return $content;
190 }
191 }
192
193
194 ### Function: Print Comments
195 function print_comments_number() {
196 global $post;
197 $comment_text = '';
198 $comment_status = $post->comment_status;
199 if($comment_status == 'open') {
200 $num_comments = get_comments_number();
201 if($num_comments == 0) {
202 $comment_text = __('No Comments');
203 } elseif($num_comments == 1) {
204 $comment_text = __('1 Comment');
205 } else {
206 $comment_text = __($num_comments.' Comments');
207 }
208 } else {
209 $comment_text = __('Comments Disabled');
210 }
211 if(!empty($post->post_password) && stripslashes($_COOKIE['wp-postpass_'.COOKIEHASH]) != $post->post_password) {
212 _e('Comments Hidden');
213 } else {
214 echo $comment_text;
215 }
216 }
217
218
219 ### Function: Print Links
220 function print_links($text_links = 'URLs in this post:') {
221 global $links_text;
222 if(!empty($links_text)) {
223 echo $text_links.$links_text;
224 }
225 }
226
227
228 ### Function: Load WP-Print
229 add_action('template_redirect', 'wp_print');
230 function wp_print() {
231 if(intval(get_query_var('print')) == 1) {
232 include(ABSPATH.'wp-content/plugins/print/wp-print.php');
233 exit;
234 }
235 }
236
237
238 ### Function: Add Print Comments Template
239 function print_template_comments($file = '') {
240 $file = ABSPATH.'wp-content/plugins/print/wp-print-comments.php';
241 return $file;
242 }
243
244
245 ### Function: Print Page Title
246 function print_pagetitle($print_pagetitle) {
247 return '&raquo; Print'.$print_pagetitle;
248 }
249
250
251 ### Function: Can Print?
252 function print_can($type) {
253 $print_options = get_settings('print_options');
254 return intval($print_options[$type]);
255 }
256
257
258 ### Function: Remove Image From Text
259 function remove_image($content) {
260 $content= preg_replace('/<img(.+?)src=\"(.+?)\"(.*?)>/', '',$content);
261 return $content;
262 }
263
264
265 ### Function: Print Options
266 add_action('activate_print/print.php', 'print_init');
267 function print_init() {
268 // Add Options
269 $print_options = array();
270 $print_options['comments'] = 0;
271 $print_options['links'] = 1;
272 $print_options['images'] = 1;
273 add_option('print_options', $print_options, 'Print Options');
274 }
275 ?>