WordPress Wrench Version: 2.0 Author: PrintFriendly Author URI: http://www.PrintFriendly.com Changelog : 2.0 - New Revision by WordPressWrench.com with a plethora of changes. You may now style your print button much easier. 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 1.4 - Changed Name 1.3 - Added new buttons, removed redundant code. 1.2 - User can choose to show or not show buttons on the listing page. */ ////////////////////////////// Wordpress hooks // add the settings page add_action('admin_menu', 'pf_menu'); function pf_menu() { add_options_page('PrintFriendly Options', 'PrintFriendly', 'publish_posts', 'printfriendly', 'pf_options'); } // add the settings link to the plugin page function pf_settings_link($links) { $settings_link = 'Settings'; array_unshift($links, $settings_link); return $links; } // add css, js, and check for updates if (isset($_GET['page']) && $_GET['page'] == 'printfriendly') { add_action('admin_print_scripts', 'pf_admin_scripts'); add_action('admin_print_styles', 'pf_admin_styles'); add_action('admin_head', 'pf_css_in_admin_head'); if(get_option('pf_text_color')==null){ //old install or something is fishy! lets run the install! printfriendly_activation_handler(); } } $pf_pluginbase = plugin_basename(__FILE__); add_filter('plugin_action_links_'.$pf_pluginbase, 'pf_settings_link'); // automaticaly add the link add_action('the_content', 'pf_show_link'); // lets start our mess! function printfriendly_activation_handler(){ update_option('pf_margin_top',0); update_option('pf_margin_right',0); update_option('pf_margin_bottom',0); update_option('pf_margin_left',0); update_option('pf_text_color','#55750C'); update_option('pf_text_size','12'); if(get_option('pf_show_list')==0){ update_option('pf_show_list','all'); }elseif(get_option('pf_show_list')==1){ update_option('pf_show_list','single'); } if(get_option('pf_disable_prepend')==1){ update_option('pf_show_list','manual'); } delete_option('pf_disable_prepend'); } // lets clean our mess when we are done and properly function printfriendly_deactivation_handler(){ delete_option('pf_button_type'); delete_option('pf_custom_text'); delete_option('pf_custom_image'); delete_option('pf_show_list'); delete_option('pf_content_placement'); delete_option('pf_content_position'); delete_option('pf_margin_top'); delete_option('pf_margin_right'); delete_option('pf_margin_bottom'); delete_option('pf_margin_left'); } register_activation_hook(__FILE__, 'printfriendly_activation_handler'); register_uninstall_hook(__FILE__, 'printfriendly_deactivation_handler'); // add CSS into admin panel function pf_css_in_admin_head() { $url = plugins_url().'/'.str_replace(basename( __FILE__),"",plugin_basename(__FILE__)).'/admin.css'; echo "\n"; } ////////////////////////////// Admin Settings function pf_options(){ include_once('pf_admin.php'); } // setup for uploads function pf_admin_scripts() { wp_enqueue_script('media-upload'); wp_enqueue_script('thickbox'); wp_register_script('pf-color-picker', plugins_url().'/'.str_replace(basename( __FILE__),"",plugin_basename(__FILE__)).'/colorpicker.js', array('jquery','media-upload','thickbox')); wp_register_script('pf-admin-js', plugins_url().'/'.str_replace(basename( __FILE__),"",plugin_basename(__FILE__)).'/admin.js', array('jquery','media-upload','thickbox')); wp_enqueue_script('pf-color-picker'); wp_enqueue_script('pf-admin-js'); } function pf_admin_styles() { wp_enqueue_style('thickbox'); } ////////////////////////////// Where all the magic happens // add js into the head function pf_js(){ return ''; } function pf_radio($name){ $var = ''; if( get_option('pf_custom_text') != null){ $return .=''.$text.''; } return $return; break; case "text-only": return ''.$text.''; break; case "pf-icon-both.gif": return 'Print Friendly Print Get a PDF version of this webpage PDF '; break; case "pf-icon-small.gif": case "pf-icon.gif": $size = get_option('pf_text_size'); if($name=="pf-icon.gif" && $size==12){ $size= 'font-size:'.($size+3).'px; '; }else{ $size ='font-size:'.$size.'px; '; } return 'Print Friendly'.$text.''; break; case "pf-button.gif": case "pf-button-big.gif": case "pf-button-both.gif": return 'PrintFriendly'; break; } } function pf_margin_down($dir){ $margin = get_option('pf_margin_'.$dir); if($margin == null){ return '0'; }else{ return $margin; } } // add button function pf_show_link($content=false){ $pf_display = get_option('pf_show_list'); if( ($pf_display=='all' || $pf_display == null) || ($pf_display=='single' && (is_single() || is_page()) ) || ($pf_display=='manual' && $content==false) ){ if($content==false){$content = '';} // now lets get options setup before we start ouputting data $style=' style="text-align:'; // position $pos = get_option('pf_content_position'); if($pos==null){$pos='left';} $style.=$pos.';'; //margin $style.=' margin: '.pf_margin_down('top').'px '.pf_margin_down('right').'px '.pf_margin_down('bottom').'px '.pf_margin_down('left').'px;'; $style.='" '; if(is_single() || is_page()){ $add = pf_js(); }else{ $add = ''; } $post_url = get_permalink(); $separator = "?pfstyle=wp"; if (strpos($post_url,"?")!=false){ $separator = "&pfstyle=wp"; } $plink_url = $post_url . $separator; $button = ''.$add.''.pf_button().''; if(get_option('pf_content_placement')==null){ return $content.$button; }else{ return $button.$content; } }else{ return $content; } }