| 1 |
<?php |
| 2 |
/* |
| 3 |
Plugin Name: PrintFriendly |
| 4 |
Plugin URI: http://www.printfriendly.com/button |
| 5 |
Description: Creates PrintFriendly.com button for easy printing. [<a href="options-general.php?page=printfriendly/pf.php">Settings</a>]. |
| 6 |
Version: 0.2 |
| 7 |
Author: Vamsee Kanakala |
| 8 |
Author URI: http://kanakala.net |
| 9 |
*/ |
| 10 |
|
| 11 |
function pf_show_link($content) |
| 12 |
{ |
| 13 |
if (is_single() || is_page()) { |
| 14 |
$button_type = get_option('pf_button_type'); |
| 15 |
|
| 16 |
if ($button_type != 'text-only') |
| 17 |
return $content.'<div><script src="http://www.printfriendly.com/javascripts/printfriendly.js" type="text/javascript"></script><a href="http://www.printfriendly.com" onclick="window.print(); return false;" title="Print an optimized version of this web page"><img id="printfriendly" style="border:none;" src="http://www.printfriendly.com/images/'.$button_type.'" alt="Print"/></a></div>'; |
| 18 |
else |
| 19 |
return $content.'<script src="http://www.printfriendly.com/javascripts/printfriendly.js" type="text/javascript"></script><a href="http://www.printfriendly.com" id="printfriendly" onclick="window.print(); return false;" title="Print an optimized version of this web page">Print</a>'; |
| 20 |
} else { |
| 21 |
return $content; |
| 22 |
} |
| 23 |
} |
| 24 |
|
| 25 |
remove_action('the_content', 'pf_show_link'); |
| 26 |
add_action('the_content', 'pf_show_link', 98); |
| 27 |
|
| 28 |
add_action('admin_menu', 'pf_menu'); |
| 29 |
|
| 30 |
function pf_menu() { |
| 31 |
add_options_page('PrintFriendly Options', 'PrintFriendly', 8, __FILE__, 'pf_options'); |
| 32 |
} |
| 33 |
|
| 34 |
function pf_options() { |
| 35 |
$option_name = 'pf_button_type'; |
| 36 |
if (isset($_POST['pf_button_type'])) { |
| 37 |
if (get_option($option_name)) |
| 38 |
update_option($option_name, $_POST['pf_button_type']); |
| 39 |
else |
| 40 |
add_option($option_name, 'printfriendly.gif'); |
| 41 |
?> |
| 42 |
<div class="updated"><p><strong><?php _e('Option saved.'); ?></strong></p></div> |
| 43 |
<?php |
| 44 |
} |
| 45 |
$option_value = get_option($option_name); |
| 46 |
?> |
| 47 |
<div class="wrap"> |
| 48 |
<h2>PrintFriendly Options</h2> |
| 49 |
<h3>Choose your button</h3> |
| 50 |
<form method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>"> |
| 51 |
<?php wp_nonce_field('update-options'); ?> |
| 52 |
<table cellspacing="20" cellpadding="20"> |
| 53 |
<tr valign="top"> |
| 54 |
<td><input name="pf_button_type" type="radio" value="printfriendly.gif" |
| 55 |
<?php if ($option_value == 'printfriendly.gif') _e('checked="checked"') ?>/></td> |
| 56 |
<td><img src="http://www.printfriendly.com/images/printfriendly.gif" width="75" height="16" alt="Select This Button Style" /></td> |
| 57 |
</tr> |
| 58 |
<tr valign="top"> |
| 59 |
<td><input name="pf_button_type" type="radio" value="printfriendly-med-txt.gif" |
| 60 |
<?php if ($option_value == 'printfriendly-med-txt.gif') _e('checked="checked"') ?>/></td> |
| 61 |
<td><img src="http://www.printfriendly.com/images/printfriendly-med-txt.gif" alt="Select this button style" width="76" height="28" /></td> |
| 62 |
</tr> |
| 63 |
<tr valign="top"> |
| 64 |
<td><input name="pf_button_type" type="radio" value="printfriendly-nobg.gif" |
| 65 |
<?php if ($option_value == 'printfriendly-nobg.gif') _e('checked="checked"') ?>/></td> |
| 66 |
<td><img src="http://www.printfriendly.com/images/printfriendly-nobg.gif" width="75" height="16" alt="Select this button style" /></td> |
| 67 |
</tr> |
| 68 |
<tr> |
| 69 |
<td><input name="pf_button_type" type="radio" value="printfriendly-med.gif" |
| 70 |
<?php if ($option_value == 'printfriendly-med.gif') _e('checked="checked"') ?>/></td> |
| 71 |
<td><img src="http://www.printfriendly.com/images/printfriendly-med.gif" width="25" height="29" alt="Select this button style" /></td> |
| 72 |
</tr> |
| 73 |
<tr> |
| 74 |
<td><input name="pf_button_type" type="radio" value="text-only" |
| 75 |
<?php if ($option_value == 'text-only') _e('checked="checked"') ?>/></td> |
| 76 |
<td><a href="#" onclick="return false;" style="text-decoration: none;">Print</a> (text only)</td> |
| 77 |
</tr> |
| 78 |
</table> |
| 79 |
<input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" /> |
| 80 |
</form> |
| 81 |
</div> |
| 82 |
<?php |
| 83 |
} |
| 84 |
?> |
| 85 |
|