PluginProbe
WP-Print / 2.02
WP-Print v2.02
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.php

print.php in WP-Print 2.02, at print.php

134 lines 4.5 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.02
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('home').'/wp-print.php?page_id='.$id.'">'.$text_page.'</a>';
68 } else {
69 echo '<a href="'.get_settings('home').'/wp-print.php?p='.$id.'">'.$text_post.'</a>';
70 }
71 }
72 }
73
74
75 ### Function: Print Content
76 function print_content($display = true) {
77 global $links_text, $link_number, $pages, $multipage, $numpages, $post;
78 if (!empty($post->post_password) && stripslashes($_COOKIE['wp-postpass_'.COOKIEHASH]) != $post->post_password) {
79 $content = get_the_password_form();
80 } else {
81 if($multipage) {
82 for($page = 0; $page < $numpages; $page++) {
83 $content .= $pages[$page];
84 }
85 } else {
86 $content = $pages[0];
87 }
88 $content = wptexturize($content);
89 $content = convert_smilies($content);
90 $content = convert_chars($content);
91 $content = wpautop($content);
92 $content = apply_filters('the_content', $content);
93 $content = str_replace(']]>', ']]&gt;', $content);
94 preg_match_all('/<a(.+?)href=\"(.+?)\"(.*?)>(.+?)<\/a>/', $content, $matches);
95 for ($i=0; $i < count($matches[0]); $i++) {
96 $link_match = $matches[0][$i];
97 $link_number++;
98 $link_url = $matches[2][$i];
99 $link_url = (strtolower(substr($link_url,0,7)) != 'http://') ? get_settings('home') . $link_url : $link_url;
100 $link_text = $matches[4][$i];
101 $content = str_replace($link_match, '['.$link_number."] <a href=\"$link_url\" target=\"_blank\">".$link_text.'</a>', $content);
102 if(preg_match('/<img(.+?)src=\"(.+?)\"(.*?)>/',$link_text)) {
103 $links_text .= '<br />['.$link_number.'] '.__('Image').': <b>'.$link_url.'</b>';
104 } else {
105 $links_text .= '<br />['.$link_number.'] '.$link_text.': <b>'.$link_url.'</b>';
106 }
107 }
108 }
109 if($display) {
110 echo $content;
111 } else {
112 return $content;
113 }
114 }
115
116
117 ### Function: Print Links
118 function print_links($text_links = 'URLs in this post:') {
119 global $links_text;
120 if(!empty($links_text)) {
121 echo $text_links.$links_text;
122 }
123 }
124
125
126 ### Function: Load WP-Print
127 add_action('template_redirect', 'wp_print');
128 function wp_print() {
129 if(intval(get_query_var('print')) == 1) {
130 include(ABSPATH . '/wp-print.php');
131 exit;
132 }
133 }
134 ?>