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

188 lines 6.1 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.03
7 Author: GaMerZ
8 Author URI: http://www.lesterchan.net
9 */
10
11
12 /* Copyright 2005 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 htaccess ReWrite Rules
31 add_filter('generate_rewrite_rules', 'print_rewrite');
32 function print_rewrite($wp_rewrite) {
33 $r_rule = '';
34 $r_link = '';
35 $rewrite_rules2 = $wp_rewrite->generate_rewrite_rule($wp_rewrite->permalink_structure.'print');
36 array_splice($rewrite_rules2, 1);
37 $r_rule = array_shift(array_keys($rewrite_rules2));
38 $r_rule = str_replace('/trackback', '',$r_rule);
39 $r_link = array_shift(array_values($rewrite_rules2));
40 $r_link = str_replace('tb=1', 'print=1', $r_link);
41 $print_rules = array($r_rule => $r_link, '(.+)/printpage/?$' => 'index.php?pagename='.$wp_rewrite->preg_index(1).'&print=1');
42 $wp_rewrite->rules = $print_rules + $wp_rewrite->rules;
43 }
44
45
46 ### Function: Print Public Variables
47 add_filter('query_vars', 'print_variables');
48 function print_variables($public_query_vars) {
49 $public_query_vars[] = 'print';
50 return $public_query_vars;
51 }
52
53
54 ### Function: Display Print Link
55 function print_link($text_post = 'Print This Post', $text_page = 'Print This Page') {
56 global $id;
57 $using_permalink = get_settings('permalink_structure');
58 $permalink = get_permalink();
59 if(!empty($using_permalink)) {
60 if(is_page()) {
61 echo '<a href="'.$permalink.'printpage/">'.$text_page.'</a>';
62 } else {
63 echo '<a href="'.$permalink.'print/">'.$text_post.'</a>';
64 }
65 } else {
66 if(is_page()) {
67 echo '<a href="'.get_settings('siteurl').'/wp-print.php?page_id='.$id.'">'.$text_page.'</a>';
68 } else {
69 echo '<a href="'.get_settings('siteurl').'/wp-print.php?p='.$id.'">'.$text_post.'</a>';
70 }
71 }
72 }
73
74
75 ### Function: Display Print Image Link
76 function print_link_image() {
77 global $id;
78 $using_permalink = get_settings('permalink_structure');
79 $permalink = get_permalink();
80 if(file_exists(ABSPATH.'/wp-content/plugins/print/images/print.gif')) {
81 $print_image = '<img src="'.get_settings('siteurl').'/wp-content/plugins/print/images/print.gif" alt="Print This Post/Page" />';
82 } else {
83 $print_image = 'Print';
84 }
85 if(!empty($using_permalink)) {
86 if(is_page()) {
87 echo '<a href="'.$permalink.'printpage/">'.$print_image.'</a>';
88 } else {
89 echo '<a href="'.$permalink.'print/">'.$print_image.'</a>';
90 }
91 } else {
92 if(is_page()) {
93 echo '<a href="'.get_settings('siteurl').'/wp-print.php?page_id='.$id.'">'.$print_image.'</a>';
94 } else {
95 echo '<a href="'.get_settings('siteurl').'/wp-print.php?p='.$id.'">'.$print_image.'</a>';
96 }
97 }
98 }
99
100
101 ### Function: Print Content
102 function print_content($display = true) {
103 global $links_text, $link_number, $pages, $multipage, $numpages, $post;
104 $max_url_char = 100;
105 if(!empty($post->post_password) && stripslashes($_COOKIE['wp-postpass_'.COOKIEHASH]) != $post->post_password) {
106 $content = get_the_password_form();
107 } else {
108 if($multipage) {
109 for($page = 0; $page < $numpages; $page++) {
110 $content .= $pages[$page];
111 }
112 } else {
113 $content = $pages[0];
114 }
115 $content = wptexturize($content);
116 $content = convert_smilies($content);
117 $content = convert_chars($content);
118 $content = wpautop($content);
119 $content = apply_filters('the_content', $content);
120 $content = str_replace(']]>', ']]&gt;', $content);
121 preg_match_all('/<a(.+?)href=\"(.+?)\"(.*?)>(.+?)<\/a>/', $content, $matches);
122 for ($i=0; $i < count($matches[0]); $i++) {
123 $link_match = $matches[0][$i];
124 $link_number++;
125 $link_url = $matches[2][$i];
126 $link_url = (strtolower(substr($link_url,0,7)) != 'http://') ? get_settings('home') . $link_url : $link_url;
127 $link_text = $matches[4][$i];
128 $content = str_replace($link_match, '['.$link_number."] <a href=\"$link_url\" target=\"_blank\">".$link_text.'</a>', $content);
129 if(strlen($link_url) > $max_url_char) {
130 $link_url = substr($link_url, 0, $max_url_char).'<br />'.substr($link_url, $max_url_char, strlen($link_url));
131 }
132 if(preg_match('/<img(.+?)src=\"(.+?)\"(.*?)>/',$link_text)) {
133 $links_text .= '<br />['.$link_number.'] '.__('Image').': <b>'.$link_url.'</b>';
134 } else {
135 $links_text .= '<br />['.$link_number.'] '.$link_text.': <b>'.$link_url.'</b>';
136 }
137 }
138 }
139 if($display) {
140 echo $content;
141 } else {
142 return $content;
143 }
144 }
145
146
147 ### Function: Print Comments
148 function print_comments($link = true) {
149 global $post;
150 $comment_text = '';
151 $num_comments = get_comments_number();
152 if($num_comments == 0) {
153 $comment_text = __('No Comments');
154 } elseif($num_comments == 1) {
155 $comment_text = __('1 Comment');
156 } else {
157 $comment_text = __($num_comments.' Comments');
158 }
159 if(!empty($post->post_password) && stripslashes($_COOKIE['wp-postpass_'.COOKIEHASH]) != $post->post_password) {
160 _e('Comments Hidden');
161 } else {
162 if($link) {
163 echo '<a href="'.get_comments_link().'">'.$comment_text.'</a>';
164 } else {
165 echo $comment_text;
166 }
167 }
168 }
169
170
171 ### Function: Print Links
172 function print_links($text_links = 'URLs in this post:') {
173 global $links_text;
174 if(!empty($links_text)) {
175 echo $text_links.$links_text;
176 }
177 }
178
179
180 ### Function: Load WP-Print
181 add_action('template_redirect', 'wp_print');
182 function wp_print() {
183 if(intval(get_query_var('print')) == 1) {
184 include(ABSPATH . '/wp-print.php');
185 exit;
186 }
187 }
188 ?>