WP-Print - Version 2.01

Version Description

Download this release

Release Info

Developer GamerZ
Plugin Icon WP-Print
Version 2.01
Comparing to
See all releases

Version 2.01

Files changed (4) hide show
  1. print.php +129 -0
  2. readme-install.txt +43 -0
  3. readme.txt +22 -0
  4. wp-print.php +97 -0
print.php ADDED
@@ -0,0 +1,129 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.01
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;
78
+ if($multipage) {
79
+ for($page = 0; $page < $numpages; $page++) {
80
+ $content .= $pages[$page];
81
+ }
82
+ } else {
83
+ $content = $pages[0];
84
+ }
85
+ $content = wptexturize($content);
86
+ $content = convert_smilies($content);
87
+ $content = convert_chars($content);
88
+ $content = wpautop($content);
89
+ $content = str_replace(']]>', ']]&gt;', $content);
90
+ preg_match_all('/<a(.+?)href=\"(.+?)\"(.*?)>(.+?)<\/a>/', $content, $matches);
91
+ for ($i=0; $i < count($matches[0]); $i++) {
92
+ $link_match = $matches[0][$i];
93
+ $link_number++;
94
+ $link_url = $matches[2][$i];
95
+ $link_url = (strtolower(substr($link_url,0,7)) != 'http://') ? get_settings('home') . $link_url : $link_url;
96
+ $link_text = $matches[4][$i];
97
+ $content = str_replace($link_match, '['.$link_number."] <a href=\"$link_url\" target=\"_blank\">".$link_text.'</a>', $content);
98
+ if(preg_match('/<img(.+?)src=\"(.+?)\"(.*?)>/',$link_text)) {
99
+ $links_text .= '<br />['.$link_number.'] '.__('Image').': <b>'.$link_url.'</b>';
100
+ } else {
101
+ $links_text .= '<br />['.$link_number.'] '.$link_text.': <b>'.$link_url.'</b>';
102
+ }
103
+ }
104
+ if($display) {
105
+ echo $content;
106
+ } else {
107
+ return $content;
108
+ }
109
+ }
110
+
111
+
112
+ ### Function: Print Links
113
+ function print_links($text_links = 'URLs in this post:') {
114
+ global $links_text;
115
+ if(!empty($links_text)) {
116
+ echo $text_links.$links_text;
117
+ }
118
+ }
119
+
120
+
121
+ ### Function: Load WP-Print
122
+ add_action('template_redirect', 'wp_print');
123
+ function wp_print() {
124
+ if(intval(get_query_var('print')) == 1) {
125
+ include(ABSPATH . '/wp-print.php');
126
+ exit;
127
+ }
128
+ }
129
+ ?>
readme-install.txt ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ -> Installation Instructions
2
+ --------------------------------------------------
3
+ // Open wp-content/plugins folder
4
+
5
+ Put:
6
+ ------------------------------------------------------------------
7
+ print.php
8
+ ------------------------------------------------------------------
9
+
10
+
11
+ // Open root Wordpress folder
12
+
13
+ Put
14
+ ------------------------------------------------------------------
15
+ wp-print.php
16
+ ------------------------------------------------------------------
17
+
18
+
19
+ // Activate the polls plugin
20
+
21
+ Note:
22
+ ------------------------------------------------------------------
23
+ You MAY Need To Re-Generate The Permalink.
24
+ Options -> Permalinks Options -> Update Permalink Structure
25
+ ------------------------------------------------------------------
26
+
27
+
28
+ // Open wp-content/themes/<YOUR THEME NAME>/index.php
29
+
30
+ Find:
31
+ ------------------------------------------------------------------
32
+ <?php while (have_posts()) : the_post(); ?>
33
+ ------------------------------------------------------------------
34
+ Add Anywhere Below It:
35
+ ------------------------------------------------------------------
36
+ <?php if(function_exists('wp_print')) { print_link(); } ?>
37
+ ------------------------------------------------------------------
38
+ Note:
39
+ ------------------------------------------------------------------
40
+ The first value you pass in is the text for printing post.
41
+ The second value is the text for printing page.
42
+ Default: print_link('Print This Post', 'Print This Page')
43
+ ------------------------------------------------------------------
readme.txt ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ -> Print Plugin For WordPress
2
+ --------------------------------------------------
3
+ Author -> Lester 'GaMerZ' Chan
4
+ Email -> lesterch@singnet.com.sg
5
+ Website -> http://www.lesterchan.net/
6
+ Demo -> htp://www.lesterchan.net/blogs/wp-print.php?p=647
7
+ Updated -> 1st January 2006
8
+ --------------------------------------------------
9
+
10
+ // Version 2.01 (01-01-2006)
11
+ - NEW: Compatible With WordPress 2.0
12
+ - NEW: Automatically Detect Whether You Are Using Nice Permalink
13
+ - NEW: Automated Permalink
14
+ - NEW: Now You Only Need To Insert 1 Line Into Your index.php Of Your Theme
15
+ - NEW: GPL License Added
16
+ - FIXED: Links Not Displaying Properly When Printing More Than 1 Post On A Single Page
17
+
18
+ // Version 2.00a (17-11-2005)
19
+ - NEW: Permlink For The Page Feature
20
+
21
+ // Version 2.00 (10-11-2005)
22
+ - NEW: Print Out A Summary Of URLS In The Post At The Bottom Of The Page
wp-print.php ADDED
@@ -0,0 +1,97 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ +----------------------------------------------------------------+
4
+ | |
5
+ | WordPress 2.0 Plugin: WP-Print 2.01 |
6
+ | Copyright (c) 2005 Lester "GaMerZ" Chan |
7
+ | |
8
+ | File Written By: |
9
+ | - Lester "GaMerZ" Chan |
10
+ | - http://www.lesterchan.net |
11
+ | |
12
+ | File Information: |
13
+ | - Printer Friendly Page |
14
+ | - wp-print.php |
15
+ | |
16
+ +----------------------------------------------------------------+
17
+ */
18
+
19
+
20
+ ### If wp-print.php Loaded Directly, Load wp-blog-header.php
21
+ if(intval($_GET['p']) > 0 || !function_exists('single_post_title')) {
22
+ require(dirname(__FILE__).'/wp-blog-header.php');
23
+ }
24
+
25
+ ### Variables
26
+ $links_text = '';
27
+
28
+ ### Load Print Content Function
29
+ add_action('init', 'print_content');
30
+
31
+ ### Function: Print Page Title
32
+ add_filter('wp_title', 'print_pagetitle');
33
+ function print_pagetitle($print_pagetitle) {
34
+ return '&raquo; Print'.$print_pagetitle;
35
+ }
36
+ ?>
37
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
38
+ <html xmlns="http://www.w3.org/1999/xhtml">
39
+ <head>
40
+ <title><?php bloginfo('name'); ?> <?php wp_title(); ?></title>
41
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
42
+ <style type="text/css" media="screen, print">
43
+ Body {
44
+ font-family: Verdana, Arial, Tahoma;
45
+ font-size: 12px;
46
+ color: #000000;
47
+ }
48
+ #Outline {
49
+ text-align: left;
50
+ width: 90%;
51
+ margin-left: auto;
52
+ margin-right: auto;
53
+ padding: 10px;
54
+ border: 1px solid #000000;
55
+ }
56
+ #BlogTitle {
57
+ font-weight: bold;
58
+ font-size: 16px;
59
+ margin-bottom: 5px;
60
+ }
61
+ #BlogDate {
62
+ margin-top: 5px;
63
+ margin-bottom: 10px;
64
+ }
65
+ #BlogContent {
66
+ padding: 10px;
67
+ margin-top: 10px;
68
+ }
69
+ HR#Divider {
70
+ width: 80%;
71
+ height: 1px;
72
+ color: #000000;
73
+ }
74
+ </style>
75
+ </head>
76
+ <body>
77
+ <p align="center"><b>- <?php bloginfo('name'); ?> - <?php bloginfo('url')?> -</b></p>
78
+ <center>
79
+ <div id="Outline">
80
+ <?php if (have_posts()) : ?>
81
+ <?php while (have_posts()) : the_post(); ?>
82
+ <p id="BlogTitle"><?php the_title(); ?></p>
83
+ <p id="BlogDate">Posted By <?php the_author(); ?> On <?php the_time('jS F Y @ H:i'); ?> In <?php the_category(', '); ?> | <a href="<?php comments_link(); ?>"><?php comments_number(); ?></a></p>
84
+ <div id="BlogContent"><?php print_content(); ?></div>
85
+ <?php endwhile; ?>
86
+ <hr id="Divider" align="center" />
87
+ <p align="left">Article printed from <?php bloginfo('name'); ?>: <b><?php bloginfo('url'); ?></b></p>
88
+ <p align="left">URL to article: <b><?php the_permalink(); ?></b></p>
89
+ <p align="left"><?php print_links(); ?></p>
90
+ <p align="right">Click <a href="javascript:window.print();">here</a> to print.</p>
91
+ <?php else : ?>
92
+ <p align="center">No posts matched your criteria.</p>
93
+ <?php endif; ?>
94
+ </div>
95
+ </center>
96
+ </body>
97
+ </html>