| 1 |
<?php |
| 2 |
/* |
| 3 |
Plugin Name: Print Friendly and PDF |
| 4 |
Plugin URI: http://www.printfriendly.com |
| 5 |
Description: PrintFriendly & PDF optimizes your pages for print. Help your readers save paper and ink, plus enjoy your content in printed form. Website |
| 6 |
Name and URL are included to ensure repeat visitors and new visitors when printed versions are shared. |
| 7 |
Version: 3.0 |
| 8 |
Author: Print Friendly |
| 9 |
Author URI: http://www.PrintFriendly.com |
| 10 |
|
| 11 |
Changelog : |
| 12 |
3.0 - Complete overhaul of the plugin by Joost de Valk. |
| 13 |
2.1.8 - The Print Button was showing up on printed, or PDF, pages. Junk! Print or PDF button no longer displayed on printed out page or PDF. |
| 14 |
2.1.7 - Changed button from span to div to support floating. |
| 15 |
2.1.6 - Added rel="nofollow" to links. Changed button from <a> to <span> to fix target_new or target_blank issues. |
| 16 |
2.1.5 - Fix conflict with link tracking plugins. Custom image support for hosted wordpress sites. |
| 17 |
2.1.4 - wp head fix. |
| 18 |
2.1.3 - Manual option for button placement. Security updates for multi-author sites. |
| 19 |
2.1.2 - Improvements to Setting page layout and PrintFriendly button launching from post pages. |
| 20 |
2.1.1 - Fixed admin settings bug. |
| 21 |
2.1 - Update for mult-author websites. Improvements to Settings page. |
| 22 |
2.0 - Customize the style, placement, and pages your printfriendly button appears. |
| 23 |
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. |
| 24 |
1.4 - Changed Name. |
| 25 |
1.3 - Added new buttons, removed redundant code. |
| 26 |
1.2 - User can choose to show or not show buttons on the listing page. |
| 27 |
*/ |
| 28 |
|
| 29 |
/** |
| 30 |
* PrintFriendly WordPress plugin. Allows easy embedding of printfriendly.com buttons. |
| 31 |
* @package PrintFriendly_WordPress |
| 32 |
* @author Joost de Valk <joost@yoast.com> |
| 33 |
* @copyright Copyright (C) 2011, Joost de Valk |
| 34 |
*/ |
| 35 |
if ( ! class_exists( 'PrintFriendly_WordPress' ) ) { |
| 36 |
|
| 37 |
/** |
| 38 |
* Class containing all the plugins functionality. |
| 39 |
* @package PrintFriendly_WordPress |
| 40 |
*/ |
| 41 |
class PrintFriendly_WordPress { |
| 42 |
/** |
| 43 |
* The hook, used for text domain as well as hooks on pages and in get requests for admin. |
| 44 |
* @var string |
| 45 |
*/ |
| 46 |
var $hook = 'printfriendly'; |
| 47 |
|
| 48 |
/** |
| 49 |
* The option name, used throughout to refer to the plugins option and option group. |
| 50 |
* @var string |
| 51 |
*/ |
| 52 |
var $option_name = 'printfriendly_option'; |
| 53 |
|
| 54 |
/** |
| 55 |
* The plugins options, loaded on init containing all the plugins settings. |
| 56 |
* @var array |
| 57 |
*/ |
| 58 |
var $options = array(); |
| 59 |
|
| 60 |
/** |
| 61 |
* Database version, used to allow for easy upgrades to / additions in plugin options between plugin versions. |
| 62 |
* @var int |
| 63 |
*/ |
| 64 |
var $db_version = 1; |
| 65 |
|
| 66 |
/** |
| 67 |
* Settings page, used within the plugin to reliably load the plugins admin JS and CSS files only on the admin page. |
| 68 |
* @var string |
| 69 |
*/ |
| 70 |
var $settings_page = ''; |
| 71 |
|
| 72 |
/** |
| 73 |
* Constructor |
| 74 |
* |
| 75 |
* @since 3.0 |
| 76 |
*/ |
| 77 |
function __construct() { |
| 78 |
// delete_option( $this->option_name ); |
| 79 |
|
| 80 |
// Retrieve the plugin options |
| 81 |
$this->options = get_option( $this->option_name ); |
| 82 |
|
| 83 |
// If the options array is empty, set defaults |
| 84 |
if ( ! is_array( $this->options ) ) |
| 85 |
$this->set_defaults(); |
| 86 |
|
| 87 |
// If the version number doesn't match, upgrade |
| 88 |
if ( $this->db_version > $this->options['db_version'] ) |
| 89 |
$this->upgrade(); |
| 90 |
|
| 91 |
// automaticaly add the link |
| 92 |
if( 'manual' != $this->options['show_list'] ) { |
| 93 |
add_action( 'wp_head', array( &$this, 'front_head' ) ); |
| 94 |
add_filter( 'the_content', array( &$this, 'show_link' ) ); |
| 95 |
add_filter( 'the_excerpt', array( &$this, 'show_link' ) ); |
| 96 |
} |
| 97 |
|
| 98 |
if ( !is_admin() ) |
| 99 |
return; |
| 100 |
|
| 101 |
// Hook into init for registration of the option and the language files |
| 102 |
add_action( 'admin_init', array( &$this, 'init' ) ); |
| 103 |
|
| 104 |
// Register the settings page |
| 105 |
add_action( 'admin_menu', array( &$this, 'add_config_page' ) ); |
| 106 |
|
| 107 |
// Register the contextual help |
| 108 |
add_filter( 'contextual_help', array( &$this, 'contextual_help' ), 10, 2 ); |
| 109 |
|
| 110 |
// Enqueue the needed scripts and styles |
| 111 |
add_action( 'admin_enqueue_scripts',array( &$this, 'admin_enqueue_scripts' ) ); |
| 112 |
|
| 113 |
// Register a link to the settings page on the plugins overview page |
| 114 |
add_filter( 'plugin_action_links', array( &$this, 'filter_plugin_actions' ), 10, 2 ); |
| 115 |
} |
| 116 |
|
| 117 |
/** |
| 118 |
* PHP 4 Compatible Constructor |
| 119 |
* |
| 120 |
* @since 3.0 |
| 121 |
*/ |
| 122 |
function PrintFriendly_WordPress() { |
| 123 |
$this->__construct(); |
| 124 |
} |
| 125 |
|
| 126 |
/** |
| 127 |
* Prints the PrintFriendly button CSS, in the header. Possible to disable this in the plugin settings. |
| 128 |
* |
| 129 |
* @since 3.0 |
| 130 |
*/ |
| 131 |
function front_head() { |
| 132 |
|
| 133 |
if ( !isset( $this->options['disable_css'] ) || $this->options['disable_css'] != 'on' ) |
| 134 |
return; |
| 135 |
|
| 136 |
?> |
| 137 |
<style type="text/css" media="screen"> |
| 138 |
.printfriendly { |
| 139 |
margin: <?php echo $this->options['margin_top'].'px '.$this->options['margin_right'].'px '.$this->options['margin_bottom'].'px '.$this->options['margin_left'].'px'; ?>; |
| 140 |
} |
| 141 |
.printfriendly a { |
| 142 |
text-decoration: none; |
| 143 |
} |
| 144 |
.printfriendly a:hover { |
| 145 |
cursor: pointer; |
| 146 |
} |
| 147 |
.printfriendly .printfriendly-text { |
| 148 |
margin-left: 3px; |
| 149 |
color: <?php echo $this->options['text_color']; ?>; |
| 150 |
} |
| 151 |
.printfriendly a img { |
| 152 |
border:none; |
| 153 |
padding:0; |
| 154 |
} |
| 155 |
</style> |
| 156 |
<style type="text/css" media="print"> |
| 157 |
.printfriendly { |
| 158 |
display: none; |
| 159 |
} |
| 160 |
</style> |
| 161 |
<?php |
| 162 |
} |
| 163 |
|
| 164 |
/** |
| 165 |
* Prints the PrintFriendly JavaScript, in the footer, and loads it asynchronously. |
| 166 |
* |
| 167 |
* @since 3.0 |
| 168 |
*/ |
| 169 |
function print_script_footer() { |
| 170 |
if ( !isset( $this->options['javascript_include'] ) || $this->options['javascript_include'] != 'on' ) |
| 171 |
return; |
| 172 |
|
| 173 |
if ( 'manual' == $this->options['show_list'] || 'all' == $this->options['show_list'] || |
| 174 |
( 'single' == $this->options['show_list'] && is_singular() ) || |
| 175 |
( 'posts' == $this->options['show_list'] && is_single() ) |
| 176 |
) { |
| 177 |
?> |
| 178 |
<script type="text/javascript"> |
| 179 |
// PrintFriendly |
| 180 |
var e = document.createElement('script'); e.type="text/javascript"; e.async = true; |
| 181 |
e.src = '//cdn.printfriendly.com/printfriendly.js'; |
| 182 |
document.getElementsByTagName('head')[0].appendChild(e); |
| 183 |
</script> |
| 184 |
<?php |
| 185 |
} |
| 186 |
} |
| 187 |
|
| 188 |
/** |
| 189 |
* Primary frontend function, used either as a filter for the_content, or directly using pf_show_link |
| 190 |
* |
| 191 |
* @since 3.0 |
| 192 |
* @param string $content the content of the post, when the function is used as a filter |
| 193 |
* @return string $button or $content with the button added to the content when appropriate, just the content when button shouldn't be added or just button when called manually. |
| 194 |
*/ |
| 195 |
function show_link( $content = false ) { |
| 196 |
if( !$content && 'manual' != $this->options['show_list'] ) |
| 197 |
return ""; |
| 198 |
|
| 199 |
$href = '#'; |
| 200 |
$onclick = 'onclick="window.print(); return false;"'; |
| 201 |
|
| 202 |
if ( !isset( $this->options['javascript_include'] ) || $this->options['javascript_include'] != 'on' || !isset( $this->options['javascript_fallback'] ) || $this->options['javascript_fallback'] ) |
| 203 |
$href = 'http://www.printfriendly.com/print/v2?url='.get_permalink(); |
| 204 |
|
| 205 |
if ( !isset( $this->options['javascript_include'] ) || $this->options['javascript_include'] != 'on' ) |
| 206 |
$onclick = ''; |
| 207 |
|
| 208 |
if ( !is_singular() && '' != $onclick ) { |
| 209 |
$onclick = ''; |
| 210 |
$href = get_permalink().'?pfstyle=wp'; |
| 211 |
} |
| 212 |
|
| 213 |
$align = ''; |
| 214 |
if ( 'none' != $this->options['content_position'] ) |
| 215 |
$align = ' align'.$this->options['content_position']; |
| 216 |
|
| 217 |
$button = apply_filters( 'printfriendly_button', '<div class="printfriendly'.$align.'"><a href="'.$href.'" rel="nofollow" '.$onclick.'>'.$this->button().'</a></div>' ); |
| 218 |
|
| 219 |
if ( 'manual' == $this->options['show_list'] ) { |
| 220 |
// Hook the script call now, so it only get's loaded when needed, and need is determined by the user calling pf_button |
| 221 |
add_action( 'wp_footer', array( &$this, 'print_script_footer' ) ); |
| 222 |
return $button; |
| 223 |
} else { |
| 224 |
if ( |
| 225 |
is_single() || |
| 226 |
( is_page() && 'posts' != $this->options['show_list'] ) || |
| 227 |
( is_home() && 'all' == $this->options['show_list'] ) |
| 228 |
) { |
| 229 |
// Hook the script call now, so it only get's loaded when needed |
| 230 |
add_action( 'wp_footer', array( &$this, 'print_script_footer' ) ); |
| 231 |
|
| 232 |
if ( $this->options['content_placement'] == 'before' ) |
| 233 |
return $button.$content; |
| 234 |
else |
| 235 |
return $content.$button; |
| 236 |
} else { |
| 237 |
return $content; |
| 238 |
} |
| 239 |
} |
| 240 |
} |
| 241 |
|
| 242 |
/** |
| 243 |
* Register the textdomain and the options array along with the validation function |
| 244 |
* |
| 245 |
* @since 3.0 |
| 246 |
*/ |
| 247 |
function init() { |
| 248 |
// Allow for localization |
| 249 |
load_plugin_textdomain( $this->hook, false, basename( dirname( __FILE__ ) ) . '/languages' ); |
| 250 |
|
| 251 |
// Register our option array |
| 252 |
register_setting( $this->option_name, $this->option_name, array( &$this, 'options_validate' ) ); |
| 253 |
} |
| 254 |
|
| 255 |
/** |
| 256 |
* Validate the saved options. |
| 257 |
* |
| 258 |
* @since 3.0 |
| 259 |
* @param array $input with unvalidated options. |
| 260 |
* @return array $valid_input with validated options. |
| 261 |
*/ |
| 262 |
function options_validate( $input ) { |
| 263 |
$valid_input = $input; |
| 264 |
|
| 265 |
// echo '<pre>'.print_r($input,1).'</pre>'; |
| 266 |
// die; |
| 267 |
|
| 268 |
if ( !in_array( $input['button_type'], array( 'pf-button.gif', 'pf-button-big.gif', 'pf-icon-small.gif', 'pf-icon.gif', 'pf-button-both.gif', 'pf-icon-both.gif', 'text-only', 'custom-image') ) ) |
| 269 |
$valid_input['button_type'] = 'pf-button.gif'; |
| 270 |
|
| 271 |
if ( !isset( $input['custom_image'] ) ) |
| 272 |
$valid_input['custom_image'] = ''; |
| 273 |
|
| 274 |
if ( !in_array( $input['show_list'], array( 'all', 'single', 'posts', 'manual') ) ) |
| 275 |
$valid_input['show_list'] = 'all'; |
| 276 |
|
| 277 |
if ( !in_array( $input['content_position'], array( 'none', 'left', 'center', 'right' ) ) ) |
| 278 |
$valid_input['content_position'] = 'left'; |
| 279 |
|
| 280 |
if ( !in_array( $input['content_placement'], array( 'before', 'after' ) ) ) |
| 281 |
$valid_input['content_placement'] = 'after'; |
| 282 |
|
| 283 |
foreach ( array( 'margin_top', 'margin_right', 'margin_bottom', 'margin_left' ) as $opt ) |
| 284 |
$valid_input[$opt] = (int) $input[$opt]; |
| 285 |
|
| 286 |
$valid_input['text_size'] = (int) $input['text_size']; |
| 287 |
|
| 288 |
if ( 25 < $valid_input['text_size'] ) { |
| 289 |
$valid_input['text_size'] = 14; |
| 290 |
add_settings_error( $this->option_name, 'invalid_color', __( 'The text size you entered is too high, please stay below 25px.', $this->hook ) ); |
| 291 |
} |
| 292 |
|
| 293 |
if ( ! preg_match('/^#[a-f0-9]{3,6}$/i', $input['text_color'] ) ) { |
| 294 |
// Revert to previous setting and throw error. |
| 295 |
$valid_input['text_color'] = $this->options['text_color']; |
| 296 |
add_settings_error( $this->option_name, 'invalid_color', __( 'The color you entered is not valid, it must be a valid hexadecimal RGB font color.', $this->hook ) ); |
| 297 |
} |
| 298 |
|
| 299 |
$valid_input['db_version'] = $this->db_version; |
| 300 |
|
| 301 |
return $valid_input; |
| 302 |
} |
| 303 |
|
| 304 |
/** |
| 305 |
* Register the config page for all users that have the manage_options capability |
| 306 |
* |
| 307 |
* @since 3.0 |
| 308 |
*/ |
| 309 |
function add_config_page() { |
| 310 |
$this->settings_page = add_options_page( __( 'PrintFriendly Options', $this->hook ), __( 'PrintFriendly', $this->hook ), 'manage_options', $this->hook, array( &$this, 'config_page' ) ); |
| 311 |
} |
| 312 |
|
| 313 |
/** |
| 314 |
* Shows help on the plugin page when clicking on the Help button, top right. |
| 315 |
* |
| 316 |
* @since 3.0 |
| 317 |
*/ |
| 318 |
function contextual_help( $contextual_help, $screen_id ) { |
| 319 |
if ( $this->settings_page == $screen_id ) { |
| 320 |
$contextual_help = '<strong>'.__( "Need Help?", $this->hook ).'</strong><br/>' |
| 321 |
.sprintf( __( "Be sure to check out the %s!"), '<a href="http://wordpress.org/extend/plugins/printfriendly/faq/">'.__( "Frequently Asked Questions", $this->hook ).'</a>' ); |
| 322 |
} |
| 323 |
return $contextual_help; |
| 324 |
} |
| 325 |
|
| 326 |
/** |
| 327 |
* Enqueue the scripts for the admin settings page |
| 328 |
* |
| 329 |
* @since 3.0 |
| 330 |
* @param string $hook_suffix hook to check against whether the current page is the PrintFriendly settings page. |
| 331 |
*/ |
| 332 |
function admin_enqueue_scripts( $screen_id ) { |
| 333 |
if ( $this->settings_page == $screen_id ) { |
| 334 |
wp_register_script( 'pf-color-picker', plugins_url( 'colorpicker.js', __FILE__ ), array( 'jquery', 'media-upload' ) ); |
| 335 |
wp_register_script( 'pf-admin-js', plugins_url( 'admin.js', __FILE__ ), array( 'jquery', 'media-upload' ) ); |
| 336 |
|
| 337 |
wp_enqueue_script( 'pf-color-picker' ); |
| 338 |
wp_enqueue_script( 'pf-admin-js' ); |
| 339 |
|
| 340 |
wp_enqueue_style( 'printfriendly-admin-css', plugins_url( 'admin.css', __FILE__ ) ); |
| 341 |
} |
| 342 |
} |
| 343 |
|
| 344 |
/** |
| 345 |
* Register the settings link for the plugins page |
| 346 |
* |
| 347 |
* @since 3.0 |
| 348 |
* @param array $links the links for the plugins. |
| 349 |
* @param string $file filename to check against plugins filename. |
| 350 |
* @return array $links the links with the settings link added to it if appropriate. |
| 351 |
*/ |
| 352 |
function filter_plugin_actions( $links, $file ){ |
| 353 |
// Static so we don't call plugin_basename on every plugin row. |
| 354 |
static $this_plugin; |
| 355 |
if ( ! $this_plugin ) $this_plugin = plugin_basename( __FILE__ ); |
| 356 |
|
| 357 |
if ( $file == $this_plugin ){ |
| 358 |
$settings_link = '<a href="options-general.php?page='.$this->hook.'">' . __( 'Settings', $this->hook ) . '</a>'; |
| 359 |
array_unshift( $links, $settings_link ); // before other links |
| 360 |
} |
| 361 |
return $links; |
| 362 |
} |
| 363 |
|
| 364 |
/** |
| 365 |
* Set default values for the plugin. If old, as in pre 1.0, settings are there, use them and then delete them. |
| 366 |
* |
| 367 |
* @since 3.0 |
| 368 |
*/ |
| 369 |
function set_defaults() { |
| 370 |
// Set some defaults |
| 371 |
$this->options = array( |
| 372 |
'button_type' => 'pf-button.gif', |
| 373 |
'content_position' => 'left', |
| 374 |
'content_placement' => 'after', |
| 375 |
'custom_image' => '', |
| 376 |
'custom_text' => 'Print Friendly', |
| 377 |
'disable_css' => false, |
| 378 |
'javascript_include' => 'on', |
| 379 |
'javascript_fallback' => 'on', |
| 380 |
'margin_top' => 0, |
| 381 |
'margin_right' => 0, |
| 382 |
'margin_bottom' => 0, |
| 383 |
'margin_left' => 0, |
| 384 |
'show_list' => 'all', |
| 385 |
'text_color' => '#55750C', |
| 386 |
'text_size' => 14, |
| 387 |
); |
| 388 |
|
| 389 |
// Check whether the old badly named singular options are there, if so, use the data and delete them. |
| 390 |
foreach ( array_keys( $this->options ) as $opt ) { |
| 391 |
$old_opt = get_option( 'pf_'.$opt ); |
| 392 |
if ( $old_opt !== false ) { |
| 393 |
$this->options[$opt] = $old_opt; |
| 394 |
delete_option( 'pf_'.$opt ); |
| 395 |
} |
| 396 |
} |
| 397 |
|
| 398 |
// This should always be set to the latest immediately when defaults are pushed in. |
| 399 |
$this->options['db_version'] = $this->db_version; |
| 400 |
|
| 401 |
update_option( $this->option_name, $this->options ); |
| 402 |
} |
| 403 |
|
| 404 |
/** |
| 405 |
* Upgrades the stored options, used to add new defaults if needed etc. |
| 406 |
* |
| 407 |
* @since 3.0 |
| 408 |
*/ |
| 409 |
function upgrade() { |
| 410 |
// Do stuff |
| 411 |
|
| 412 |
$this->options['db_version'] = $this->db_version; |
| 413 |
update_option( $this->option_name, $this->options ); |
| 414 |
} |
| 415 |
|
| 416 |
/** |
| 417 |
* Displays radio button in the admin area |
| 418 |
* |
| 419 |
* @since 3.0 |
| 420 |
* @param string $name the name of the radio button to generate. |
| 421 |
* @param boolean $br whether or not to add an HTML <br> tag, defaults to true. |
| 422 |
*/ |
| 423 |
function radio($name, $br = true){ |
| 424 |
$var = '<input id="'.$name.'" class="radio" name="'.$this->option_name.'[button_type]" type="radio" value="'.$name.'" '.$this->checked( 'button_type', $name, false ).'/>'; |
| 425 |
$button = $this->button( $name ); |
| 426 |
if ( '' != $button ) |
| 427 |
echo '<label for="'.$name.'">' . $var . $button . '</label>'; |
| 428 |
else |
| 429 |
echo $var; |
| 430 |
|
| 431 |
if ( $br ) |
| 432 |
echo '<br>'; |
| 433 |
} |
| 434 |
|
| 435 |
/** |
| 436 |
* Displays button image in the admin area |
| 437 |
* |
| 438 |
* @since 3.0 |
| 439 |
* @param string $name the name of the button to generate. |
| 440 |
*/ |
| 441 |
function button( $name = false ){ |
| 442 |
if( !$name ) |
| 443 |
$name = $this->options['button_type']; |
| 444 |
|
| 445 |
$text = $this->options['custom_text']; |
| 446 |
|
| 447 |
switch($name){ |
| 448 |
case "custom-image": |
| 449 |
if( '' == $this->options['custom_image'] ) |
| 450 |
return ''; |
| 451 |
|
| 452 |
$return = '<img src="'.$this->options['custom_image'].'" alt="Print Friendly" />'; |
| 453 |
|
| 454 |
if( $this->options['custom_text'] != '' ) |
| 455 |
$return .= '<span class="printfriendly-text">'.$this->options['custom_text'].'</span>'; |
| 456 |
|
| 457 |
return $return; |
| 458 |
break; |
| 459 |
|
| 460 |
case "text-only": |
| 461 |
return '<span class="printfriendly-text">'.$text.'</span>'; |
| 462 |
break; |
| 463 |
|
| 464 |
case "pf-icon-both.gif": |
| 465 |
return '<img src="//cdn.printfriendly.com/pf-print-icon.gif" alt="Print Friendly"/><span class="printandpdf printfriendly-text"> Print <img src="//cdn.printfriendly.com/pf-pdf-icon.gif" alt="Get a PDF version of this webpage" /> PDF </span>'; |
| 466 |
break; |
| 467 |
|
| 468 |
case "pf-icon-small.gif": |
| 469 |
case "pf-icon.gif": |
| 470 |
return '<img src="//cdn.printfriendly.com/'.$name.'" alt="Print Friendly"/><span class="printfriendly-text">'.$text.'</span>'; |
| 471 |
break; |
| 472 |
|
| 473 |
default: |
| 474 |
return '<img src="//cdn.printfriendly.com/'.$name.'" alt="Print Friendly" />'; |
| 475 |
break; |
| 476 |
} |
| 477 |
} |
| 478 |
|
| 479 |
/** |
| 480 |
* Convenience function to output a value for an input |
| 481 |
* |
| 482 |
* @since 3.0 |
| 483 |
* @param string $val value to check. |
| 484 |
*/ |
| 485 |
function val( $val ) { |
| 486 |
if ( isset( $this->options[$val] ) ) |
| 487 |
echo esc_attr( $this->options[$val] ); |
| 488 |
} |
| 489 |
|
| 490 |
/** |
| 491 |
* Like the WordPress checked() function but it doesn't throw notices when the array key isn't set and uses the plugins options array. |
| 492 |
* |
| 493 |
* @since 3.0 |
| 494 |
* @param mixed $val value to check. |
| 495 |
* @param mixed $check_against value to check against. |
| 496 |
* @param boolean $echo whether or not to echo the output. |
| 497 |
* @return string checked, when true, empty, when false. |
| 498 |
*/ |
| 499 |
function checked( $val, $check_against = true, $echo = true ) { |
| 500 |
if ( !isset( $this->options[$val] ) ) |
| 501 |
return; |
| 502 |
|
| 503 |
if ( $this->options[$val] == $check_against ) { |
| 504 |
if ( $echo ) |
| 505 |
echo ' checked="checked" '; |
| 506 |
else |
| 507 |
return ' checked="checked" '; |
| 508 |
} |
| 509 |
} |
| 510 |
|
| 511 |
/** |
| 512 |
* Output the config page |
| 513 |
* |
| 514 |
* @since 3.0 |
| 515 |
*/ |
| 516 |
function config_page() { |
| 517 |
|
| 518 |
// Since WP 3.2 outputs these errors by default, only display them when we're on versions older than 3.2 that do support the settings errors. |
| 519 |
global $wp_version; |
| 520 |
if ( version_compare( $wp_version, '3.2', '<' ) ) |
| 521 |
settings_errors(); |
| 522 |
|
| 523 |
// Show the content of the options array when debug is enabled |
| 524 |
if ( WP_DEBUG ) |
| 525 |
echo '<pre>Options:<br><br>' . print_r( $this->options, 1 ) . '</pre>'; |
| 526 |
?> |
| 527 |
<div id="pf_settings" class="wrap"> |
| 528 |
<div class="icon32" id="printfriendly"></div> |
| 529 |
<h2><?php _e( 'PrintFriendly Settings', $this->hook ); ?></h2> |
| 530 |
|
| 531 |
<form action="options.php" method="post"> |
| 532 |
<?php settings_fields( $this->option_name ); ?> |
| 533 |
|
| 534 |
<table class="form-table"> |
| 535 |
<tr> |
| 536 |
<th colspan="2"> |
| 537 |
<h3><?php _e( "Pick a Button and/or Text", $this->hook ); ?></h3> |
| 538 |
</th> |
| 539 |
</tr> |
| 540 |
<tr> |
| 541 |
<th scope="row"><?php _e( "Pick Your Button Style", $this->hook ); ?></th> |
| 542 |
<td class="defaultavatarpicker"> |
| 543 |
<fieldset> |
| 544 |
<?php $this->radio('pf-button.gif'); ?> |
| 545 |
<?php $this->radio('pf-button-both.gif'); ?> |
| 546 |
<?php $this->radio('pf-button-big.gif'); ?> |
| 547 |
<span class="button_preview"> |
| 548 |
<?php $this->radio('pf-icon-small.gif'); ?> |
| 549 |
<?php $this->radio('pf-icon-both.gif'); ?> |
| 550 |
<?php $this->radio('pf-icon.gif'); ?> |
| 551 |
<?php $this->radio('text-only'); ?> |
| 552 |
<?php $this->radio('custom-image', false); ?> |
| 553 |
</span> |
| 554 |
<label for="custom-image"><?php _e( "Custom Image URL", $this->hook ); ?></label> |
| 555 |
<input id="custom_image" type="text" class="regular-text" size="40" name="<?php echo $this->option_name; ?>[custom_image]" value="<?php $this->val( 'custom_image' ); ?>" /><br> |
| 556 |
<span class="description"><?php _e( ".JPG .GIF or .PNG Absolute (http://www.example.com/...), or Relative (/wp/wp-content/uploads/example.png)", $this->hook ); ?></span> |
| 557 |
<br> |
| 558 |
</fieldset> |
| 559 |
</td> |
| 560 |
</tr> |
| 561 |
<tr> |
| 562 |
<th scope="row"><label for="custom_text"><?php _e( "Button Text", $this->hook ); ?></label></th> |
| 563 |
<td><input type="text" class="text" name="<?php echo $this->option_name; ?>[custom_text]" id="custom_text" value="<?php $this->val( 'custom_text' ); ?>"></td> |
| 564 |
</tr> |
| 565 |
<tr class="css"> |
| 566 |
<th colspan="2"> |
| 567 |
<h3><?php _e( "Style the Button and Text", $this->hook ); ?></h3> |
| 568 |
</th> |
| 569 |
</tr> |
| 570 |
<tr class="css"> |
| 571 |
<th scope="row"><?php _e( "Text Color", $this->hook ); ?></th> |
| 572 |
<td> |
| 573 |
<div id="colorSelector"><div style="background-color: <?php echo $this->options['text_color']; ?>;"></div></div> |
| 574 |
<input type="hidden" name="<?php echo $this->option_name; ?>[text_color]" id="text_color" value="<?php $this->val( 'text_color' ); ?>"/><br> |
| 575 |
<span class="description"><?php _e( "Use the color picker, or enter a valid hex color in the color picker input box.", $this->hook ); ?></span> |
| 576 |
</td> |
| 577 |
</tr> |
| 578 |
<tr class="css"> |
| 579 |
<th scope="row"<label for="text_size"><?php _e( "Text Size", $this->hook ); ?></label></th> |
| 580 |
<td> |
| 581 |
<input type="number" id="text_size" min="9" max="25" class="small-text" name="<?php echo $this->option_name; ?>[text_size]" value="<?php $this->val( 'text_size' ); ?>"/> |
| 582 |
<span class="description"><?php _e( "In pixels (px)", $this->hook ); ?></span> |
| 583 |
</td> |
| 584 |
</tr> |
| 585 |
<tr class="css"> |
| 586 |
<th scope="row"><?php _e( "Margin", $this->hook ); ?></th> |
| 587 |
<td> |
| 588 |
<label><input class="small-text" type="number" name="<?php echo $this->option_name; ?>[margin_left]" value="<?php $this->val( 'margin_left' ); ?>" maxlength="3"/> <?php _e( "Left", $this->hook ); ?></label> <span class="description"><?php _e( "In pixels (px)", $this->hook ); ?></span><br> |
| 589 |
<label><input class="small-text" type="number" name="<?php echo $this->option_name; ?>[margin_right]" value="<?php $this->val( 'margin_right' ); ?>"/> <?php _e( "Right", $this->hook ); ?></label><br> |
| 590 |
<label><input class="small-text" type="number" name="<?php echo $this->option_name; ?>[margin_top]" value="<?php $this->val( 'margin_top' ); ?>" maxlength="3"/> <?php _e( "Top", $this->hook ); ?></label><br> |
| 591 |
<label><input class="small-text" type="number" name="<?php echo $this->option_name; ?>[margin_bottom]" value="<?php $this->val( 'margin_bottom' ); ?>" maxlength="3"/> <?php _e( "Bottom", $this->hook ); ?></label><br> |
| 592 |
</td> |
| 593 |
</tr> |
| 594 |
<tr> |
| 595 |
<th colspan="2"> |
| 596 |
<h3><?php _e( "Button Placement", $this->hook ); ?></h3> |
| 597 |
</th> |
| 598 |
</tr> |
| 599 |
<tr> |
| 600 |
<th scope="row"><?php _e( "Horizontal Alignment", $this->hook ); ?></th> |
| 601 |
<td> |
| 602 |
<label><input type="radio" name="<?php echo $this->option_name; ?>[content_position]" value="none" <?php $this->checked( 'content_position', 'none'); ?>/> <?php _e( "None", $this->hook ); ?></label><br> |
| 603 |
<label><input type="radio" name="<?php echo $this->option_name; ?>[content_position]" value="left" <?php $this->checked( 'content_position', 'left'); ?>/> <?php _e( "Left", $this->hook ); ?></label><br> |
| 604 |
<label><input type="radio" name="<?php echo $this->option_name; ?>[content_position]" value="right" <?php $this->checked( 'content_position', 'right') ?>/> <?php _e( "Right", $this->hook ); ?></label><br> |
| 605 |
<label><input type="radio" name="<?php echo $this->option_name; ?>[content_position]" value="center" <?php $this->checked( 'content_position', 'center') ?>/> <?php _e( "Center", $this->hook ); ?></label><br> |
| 606 |
</td> |
| 607 |
</tr> |
| 608 |
<tr class="content_placement"> |
| 609 |
<th scope="row"><?php _e( "Vertical Position", $this->hook ); ?></th> |
| 610 |
<td> |
| 611 |
<label><input type="radio" name="<?php echo $this->option_name; ?>[content_placement]" value="before" <?php $this->checked( 'content_placement', 'before'); ?> <?php if( $this->options['show_list']=='manual'){ echo 'disabled="disabled"'; } ?>/> <?php _e( "Before Content", $this->hook ); ?></label><br> |
| 612 |
<label><input type="radio" name="<?php echo $this->option_name; ?>[content_placement]" value="after" <?php $this->checked( 'content_placement', 'after'); ?> <?php if( $this->options['show_list']=='manual'){ echo 'disabled="disabled"'; } ?>/> <?php _e( "After Content", $this->hook ); ?></label><br> |
| 613 |
</td> |
| 614 |
</tr> |
| 615 |
<tr> |
| 616 |
<th scope="row"><?php _e( "Add PrintFriendly To", $this->hook ); ?></th> |
| 617 |
<td> |
| 618 |
<label><input type="radio" class="show_list" name="<?php echo $this->option_name; ?>[show_list]" value="all" <?php $this->checked( 'show_list', 'all'); ?>/> <?php _e( "Homepage, Archives, Posts, and Pages", $this->hook ); ?></label><br> |
| 619 |
<label><input type="radio" class="show_list" name="<?php echo $this->option_name; ?>[show_list]" value="single" <?php $this->checked( 'show_list', 'single'); ?>/> <?php _e( "Posts and Pages", $this->hook ); ?></label><br> |
| 620 |
<label><input type="radio" class="show_list" name="<?php echo $this->option_name; ?>[show_list]" value="posts" <?php $this->checked( 'show_list', 'posts'); ?>/> <?php _e( "Posts", $this->hook ); ?></label><br> |
| 621 |
<label><input type="radio" class="show_list" name="<?php echo $this->option_name; ?>[show_list]" value="manual" <?php $this->checked( 'show_list', 'manual'); ?> /> <?php _e( "Manual", $this->hook ); ?></label><br> |
| 622 |
<div id="addmanual-help"> |
| 623 |
<p><?php _e( "Copy and paste the code below anywhere in your template pages.", $this->hook ); ?></p> |
| 624 |
<code style="display:block;"><?php if(function_exists('pf_show_link')){echo pf_show_link();} ?></code> |
| 625 |
</div> |
| 626 |
</td> |
| 627 |
</tr> |
| 628 |
<tr> |
| 629 |
<th colspan="2"> |
| 630 |
<h3><?php _e( "Other Settings", $this->hook ); ?></h3> |
| 631 |
</th> |
| 632 |
</tr> |
| 633 |
<tr> |
| 634 |
<th scope="row"><?php _e( "CSS Stylesheet", $this->hook ); ?></th> |
| 635 |
<td> |
| 636 |
<label><input type="checkbox" id="disable_css" name="<?php echo $this->option_name; ?>[disable_css]" <?php $this->checked( 'disable_css', 'on' ); ?>/> <?php _e( "Add CSS to pages", $this->hook ); ?></label><br/> |
| 637 |
<p class="description"> |
| 638 |
<?php _e( "If you uncheck this box you have to add the styling for the PrintFriendly button to your theme's stylesheet.", $this->hook ); ?> |
| 639 |
</p> |
| 640 |
</td> |
| 641 |
</tr> |
| 642 |
<tr> |
| 643 |
<th scope="row"><?php _e( "JavaScript", $this->hook ); ?></th> |
| 644 |
<td> |
| 645 |
<label><input type="checkbox" name="<?php echo $this->option_name; ?>[javascript_fallback]" <?php $this->checked( 'javascript_fallback', 'on' ); ?>/> <?php _e( "JavaScript Fallback", $this->hook ); ?></label><br/> |
| 646 |
<p class="description"> |
| 647 |
<?php _e( "If you uncheck this box users without JavaScript will be unable to use the PrintFriendly service.", $this->hook ); ?> |
| 648 |
</p> |
| 649 |
<label><input type="checkbox" name="<?php echo $this->option_name; ?>[javascript_include]" <?php $this->checked( 'javascript_include', 'on' ); ?>/> <?php _e( "Include JavaScript", $this->hook ); ?></label><br/> |
| 650 |
<p class="description"> |
| 651 |
<?php _e( "If you uncheck this box, all buttons will become links to the PrintFriendly webservice and the PrintFriendly JavaScript will not be loaded on your site.", $this->hook ); ?> |
| 652 |
</p> |
| 653 |
</td> |
| 654 |
</tr> |
| 655 |
</table> |
| 656 |
|
| 657 |
<p class="submit"> |
| 658 |
<input type="submit" class="button-primary" value="<?php esc_attr_e( "Save Options", $this->hook ); ?>"/> |
| 659 |
<input type="reset" class="button-secondary" value="<?php esc_attr_e( "Cancel", $this->hook ); ?>"/> |
| 660 |
</p> |
| 661 |
<p> |
| 662 |
<?php _e( "Like PrintFriendly?", $this->hook ); ?> <a href="http://wordpress.org/extend/plugins/printfriendly/"><?php _e( "Give us a rating", $this->hook ); ?></a>. <?php _e( "Need help or have suggestions?", $this->hook ); ?> <a href="mailto:support@printfriendly.com?subject=Support%20for%20PrintFriendly%20WordPress%20plugin">support@PrintFriendly.com</a>. |
| 663 |
</p> |
| 664 |
</form> |
| 665 |
</div> |
| 666 |
<?php |
| 667 |
} |
| 668 |
} |
| 669 |
$printfriendly = new PrintFriendly_WordPress(); |
| 670 |
} |
| 671 |
|
| 672 |
/** |
| 673 |
* Convenience function for use in templates. |
| 674 |
* |
| 675 |
* @since 3.0 |
| 676 |
* @return string returns a button to be printed. |
| 677 |
*/ |
| 678 |
function pf_show_link() { |
| 679 |
global $printfriendly; |
| 680 |
return $printfriendly->show_link(); |
| 681 |
} |