PluginProbe
Print, PDF & Email by PrintFriendly / 2.0
Print, PDF & Email by PrintFriendly v2.0
5.5.12 5.5.11 trunk 0.2 0.9 1.0 2.0 2.1.8 3.0 3.0.9 3.1.6 3.10.0 3.11.0 3.11.1 3.11.2 3.12.0 3.12.1 3.12.2 3.12.3 3.12.4 3.12.5 3.13.0 3.14.0 3.14.1 3.14.2 All 94 releases
printfriendly / pf.php

pf.php in Print, PDF & Email by PrintFriendly 2.0, at pf.php

229 lines 8.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Plugin Name: Print Friendly &amp; PDF
4 Plugin URI: http://www.printfriendly.com/button
5 Description: Adds a Print Friendly &amp; PDF button for your pages. Help your users save paper and ink, and engage with your content. Developed by <a href="http://wordpresswrench.com?ref=printfriendly" target="_blank">WordPress Wrench</a>
6 Version: 2.0
7 Author: PrintFriendly
8 Author URI: http://www.PrintFriendly.com
9
10 Changelog :
11 2.0 - New Revision by WordPressWrench.com with a plethora of changes. You may now style your print button much easier.
12 1.5 - Added developer ability to disable hook and use the pf_show_link() function to better be used in a custom theme & Uninstall cleanup - by WordpressWrench.com
13 1.4 - Changed Name
14 1.3 - Added new buttons, removed redundant code.
15 1.2 - User can choose to show or not show buttons on the listing page.
16
17 */
18
19
20
21 ////////////////////////////// Wordpress hooks
22
23 // add the settings page
24 add_action('admin_menu', 'pf_menu');
25 function pf_menu() {
26 add_options_page('PrintFriendly Options', 'PrintFriendly', 'publish_posts', 'printfriendly', 'pf_options');
27 }
28
29 // add the settings link to the plugin page
30
31 function pf_settings_link($links) {
32 $settings_link = '<a href="options-general.php?page=printfriendly">Settings</a>';
33 array_unshift($links, $settings_link);
34 return $links;
35 }
36
37 // add css, js, and check for updates
38 if (isset($_GET['page']) && $_GET['page'] == 'printfriendly') {
39 add_action('admin_print_scripts', 'pf_admin_scripts');
40 add_action('admin_print_styles', 'pf_admin_styles');
41 add_action('admin_head', 'pf_css_in_admin_head');
42 if(get_option('pf_text_color')==null){
43 //old install or something is fishy! lets run the install!
44 printfriendly_activation_handler();
45 }
46 }
47
48 $pf_pluginbase = plugin_basename(__FILE__);
49 add_filter('plugin_action_links_'.$pf_pluginbase, 'pf_settings_link');
50
51 // automaticaly add the link
52 add_action('the_content', 'pf_show_link');
53
54 // lets start our mess!
55 function printfriendly_activation_handler(){
56 update_option('pf_margin_top',0);
57 update_option('pf_margin_right',0);
58 update_option('pf_margin_bottom',0);
59 update_option('pf_margin_left',0);
60
61
62 update_option('pf_text_color','#55750C');
63 update_option('pf_text_size','12');
64 if(get_option('pf_show_list')==0){
65 update_option('pf_show_list','all');
66 }elseif(get_option('pf_show_list')==1){
67 update_option('pf_show_list','single');
68 }
69 if(get_option('pf_disable_prepend')==1){
70 update_option('pf_show_list','manual');
71 }
72 delete_option('pf_disable_prepend');
73 }
74
75 // lets clean our mess when we are done and properly
76 function printfriendly_deactivation_handler(){
77 delete_option('pf_button_type');
78 delete_option('pf_custom_text');
79
80 delete_option('pf_custom_image');
81
82 delete_option('pf_show_list');
83 delete_option('pf_content_placement');
84 delete_option('pf_content_position');
85
86 delete_option('pf_margin_top');
87 delete_option('pf_margin_right');
88 delete_option('pf_margin_bottom');
89 delete_option('pf_margin_left');
90 }
91 register_activation_hook(__FILE__, 'printfriendly_activation_handler');
92 register_uninstall_hook(__FILE__, 'printfriendly_deactivation_handler');
93
94 // add CSS into admin panel
95 function pf_css_in_admin_head() {
96 $url = plugins_url().'/'.str_replace(basename( __FILE__),"",plugin_basename(__FILE__)).'/admin.css';
97 echo "<link rel='stylesheet' type='text/css' href='$url' />\n";
98 }
99
100 ////////////////////////////// Admin Settings
101
102 function pf_options(){
103 include_once('pf_admin.php');
104 }
105
106 // setup for uploads
107 function pf_admin_scripts() {
108 wp_enqueue_script('media-upload');
109 wp_enqueue_script('thickbox');
110 wp_register_script('pf-color-picker', plugins_url().'/'.str_replace(basename( __FILE__),"",plugin_basename(__FILE__)).'/colorpicker.js', array('jquery','media-upload','thickbox'));
111 wp_register_script('pf-admin-js', plugins_url().'/'.str_replace(basename( __FILE__),"",plugin_basename(__FILE__)).'/admin.js', array('jquery','media-upload','thickbox'));
112 wp_enqueue_script('pf-color-picker');
113 wp_enqueue_script('pf-admin-js');
114 }
115 function pf_admin_styles() {
116 wp_enqueue_style('thickbox');
117 }
118
119 ////////////////////////////// Where all the magic happens
120
121 // add js into the head
122 function pf_js(){
123 return '<script src="http://cdn.printfriendly.com/printfriendly.js" type="text/javascript"></script>';
124 }
125
126 function pf_radio($name){
127 $var = '<input name="pf_button_type" type="radio" value="'.$name.'"'; if($name=="pf-button-big.gif"){$var .= ' class="bigger"';} if( get_option('pf_button_type') == $name || ($name=="pf-button.gif" && get_option('pf_button_type')==null) ){$var .= ' checked="checked"'; } $var .= '/>';
128 return $var.pf_button($name);
129 }
130
131 function pf_button($name=false){
132 if($name==false){
133 $name = get_option('pf_button_type');
134 //null
135 if($name==null){
136 $name='pf-button.gif';
137 }
138 }
139 $text = get_option('pf_custom_text');
140 if( $text == null){
141 $text = 'Print Friendly';
142 }
143 switch($name){
144 case "custom-image":
145 $custom_image = get_option('pf_custom_image');
146 if($custom_image==null){
147 return '';
148 }
149 $return = '<img class="printfriendly" src="'.$custom_image.'" />';
150 if( get_option('pf_custom_text') != null){
151 $return .='<span class="printfriendly" style="font-size:'.get_option('pf_text_size').'px; margin-left:3px; color: '.get_option('pf_text_color').';">'.$text.'</span>';
152 }
153 return $return;
154 break;
155
156 case "text-only":
157 return '<span class="printfriendly" style="font-size: '.get_option('pf_text_size').'px; margin-left:3px; color: '.get_option('pf_text_color').';">'.$text.'</span>';
158 break;
159
160 case "pf-icon-both.gif":
161 return '<img class="printfriendly" style="border:none; padding:0;" src="http://cdn.printfriendly.com/pf-print-icon.gif" alt="Print Friendly"/><span class="printandpdf" style="font-size:'.get_option('pf_text_size').'; margin-left:3px; color:'.get_option('pf_text_color').';"> Print <img src="http://cdn.printfriendly.com/pf-pdf-icon.gif" alt="Get a PDF version of this webpage" /> PDF </span>';
162 break;
163
164 case "pf-icon-small.gif":
165 case "pf-icon.gif":
166 $size = get_option('pf_text_size');
167 if($name=="pf-icon.gif" && $size==12){
168 $size= 'font-size:'.($size+3).'px; ';
169 }else{
170 $size ='font-size:'.$size.'px; ';
171 }
172 return '<img class="printfriendly" src="http://cdn.printfriendly.com/'.$name.'" alt="Print Friendly"/><span style="'.$size.'margin-left:3px; color: '.get_option('pf_text_color').';">'.$text.'</span>';
173 break;
174
175 case "pf-button.gif":
176 case "pf-button-big.gif":
177 case "pf-button-both.gif":
178 return '<img class="printfriendly" src="http://cdn.printfriendly.com/'.$name.'" alt="PrintFriendly" />';
179 break;
180 }
181 }
182
183 function pf_margin_down($dir){
184 $margin = get_option('pf_margin_'.$dir);
185 if($margin == null){
186 return '0';
187 }else{
188 return $margin;
189 }
190 }
191
192 // add button
193 function pf_show_link($content=false){
194 $pf_display = get_option('pf_show_list');
195 if( ($pf_display=='all' || $pf_display == null) || ($pf_display=='single' && (is_single() || is_page()) ) || ($pf_display=='manual' && $content==false) ){
196 if($content==false){$content = '';}
197 // now lets get options setup before we start ouputting data
198 $style=' style="text-align:';
199 // position
200 $pos = get_option('pf_content_position');
201 if($pos==null){$pos='left';}
202 $style.=$pos.';';
203
204 //margin
205 $style.=' margin: '.pf_margin_down('top').'px '.pf_margin_down('right').'px '.pf_margin_down('bottom').'px '.pf_margin_down('left').'px;';
206
207 $style.='" ';
208
209 if(is_single() || is_page()){
210 $add = pf_js();
211 }else{
212 $add = '';
213 }
214 $post_url = get_permalink();
215 $separator = "?pfstyle=wp";
216 if (strpos($post_url,"?")!=false){
217 $separator = "&pfstyle=wp";
218 }
219 $plink_url = $post_url . $separator;
220 $button = '<div'.$style.'class="pfButton">'.$add.'<a href="'.$plink_url.'">'.pf_button().'</a></div>';
221 if(get_option('pf_content_placement')==null){
222 return $content.$button;
223 }else{
224 return $button.$content;
225 }
226 }else{
227 return $content;
228 }
229 }