web/wp-content/plugins/add-to-facebook-plugin/addtofacebook.php
branchwordpress
changeset 112 fb7cd02b9848
parent 111 6b96085291d7
child 123 561aa6d282f6
equal deleted inserted replaced
111:6b96085291d7 112:fb7cd02b9848
     1 <?php
       
     2 /*
       
     3 Plugin Name: Add To Facebook
       
     4 Version: 1.4.3
       
     5 Plugin URI: http://nothing.golddave.com/?page_id=108
       
     6 Description: Adds a footer link to add the current post or page to a Facebook Mini-Feed.
       
     7 Author: David Goldstein
       
     8 Author URI: http://nothing.golddave.com/
       
     9 */
       
    10 
       
    11 /*
       
    12 Change Log
       
    13 
       
    14 1.4.3
       
    15   * Improved option saving mechanism to avoid conflicts with other plugins.
       
    16   
       
    17 1.4.2
       
    18   * Added a title specs to the links.
       
    19 
       
    20 1.4.1
       
    21   * Added slashes at end of image tags per XHTML specification.
       
    22 
       
    23 1.4
       
    24   * Added CSS.
       
    25   * Fixed bug that prevented the Facebook icon to appear in version 1.3.
       
    26 
       
    27 1.3
       
    28   * Links now open in a new tab/window.
       
    29 
       
    30 1.2
       
    31   * Added option to use a template tag.
       
    32   * Fixed bug that prevented the Facebook icon to appear in version 1.1.
       
    33 
       
    34 1.1
       
    35   * Added options page to choose between text/image links.
       
    36 
       
    37 1.0
       
    38   * First public release.
       
    39 */ 
       
    40 
       
    41 function add_to_facebook($data){
       
    42 	global $post;
       
    43 	$current_options = get_option('add_to_facebook_options');
       
    44 	$linktype = $current_options['link_type'];
       
    45 	switch ($linktype) {
       
    46 		case "text":
       
    47 			$data=$data."<p class=\"facebook\"><a href=\"http://www.facebook.com/share.php?u=".get_permalink($post->ID)."\" target=\"_blank\" title=\"Share on Facebook\">Share on Facebook</a></p>";
       
    48 			break;
       
    49 		case "image":
       
    50 			$data=$data."<p class=\"facebook\"><a href=\"http://www.facebook.com/share.php?u=".get_permalink($post->ID)."\" target=\"_blank\"><img src=\"".get_bloginfo(wpurl)."/wp-content/plugins/add-to-facebook-plugin/facebook_share_icon.gif\" alt=\"Share on Facebook\" title=\"Share on Facebook\" /></a></p>";
       
    51 			break;
       
    52 		case "both":
       
    53 			$data=$data."<p class=\"facebook\"><a href=\"http://www.facebook.com/share.php?u=".get_permalink($post->ID)."\" target=\"_blank\"><img src=\"".get_bloginfo(wpurl)."/wp-content/plugins/add-to-facebook-plugin/facebook_share_icon.gif\" alt=\"Share on Facebook\" title=\"Share on Facebook\" /></a><a href=\"http://www.facebook.com/share.php?u=".get_permalink($post->ID)."\" target=\"_blank\" title=\"Share on Facebook\">Share on Facebook</a></p>";
       
    54 			break;
       
    55 		}
       
    56 		return $data;
       
    57 }
       
    58 
       
    59 function activate_add_to_facebook(){
       
    60 	global $post;
       
    61 	$current_options = get_option('add_to_facebook_options');
       
    62 	$insertiontype = $current_options['insertion_type'];
       
    63 	if ($insertiontype != 'template'){
       
    64 		add_filter('the_content', 'add_to_facebook', 10);
       
    65 		add_filter('the_excerpt', 'add_to_facebook', 10);
       
    66 	}
       
    67 }
       
    68 
       
    69 activate_add_to_facebook();
       
    70 
       
    71 function addtofacebook(){
       
    72 	global $post;
       
    73 	$current_options = get_option('add_to_facebook_options');
       
    74 	$insertiontype = $current_options['insertion_type'];
       
    75 	if ($insertiontype != 'auto'){
       
    76 		$linktype = $current_options['link_type'];
       
    77 		switch ($linktype) {
       
    78 			case "text":
       
    79 				echo "<p class=\"facebook\"><a href=\"http://www.facebook.com/share.php?u=".get_permalink($post->ID)."\" target=\"_blank\" title=\"Share on Facebook\">Share on Facebook</a></p>";
       
    80 				break;
       
    81 			case "image":
       
    82 				echo "<p class=\"facebook\"><a href=\"http://www.facebook.com/share.php?u=".get_permalink($post->ID)."\" target=\"_blank\"><img src=\"".get_bloginfo(wpurl)."/wp-content/plugins/add-to-facebook-plugin/facebook_share_icon.gif\" alt=\"Share on Facebook\" title=\"Share on Facebook\" /></a></p>";
       
    83 				break;
       
    84 			case "both":
       
    85 				echo "<p class=\"facebook\"><a href=\"http://www.facebook.com/share.php?u=".get_permalink($post->ID)."\" target=\"_blank\"><img src=\"".get_bloginfo(wpurl)."/wp-content/plugins/add-to-facebook-plugin/facebook_share_icon.gif\" alt=\"Share on Facebook\" title=\"Share on Facebook\" /></a><a href=\"http://www.facebook.com/share.php?u=".get_permalink($post->ID)."\" target=\"_blank\" title=\"Share on Facebook\">Share on Facebook</a></p>";
       
    86 				break;
       
    87 			}
       
    88 		}
       
    89 }
       
    90 
       
    91 // Create the options page
       
    92 function add_to_facebook_options_page() { 
       
    93 	$current_options = get_option('add_to_facebook_options');
       
    94 	$link = $current_options["link_type"];
       
    95 	$insert = $current_options["insertion_type"];
       
    96 	if ($_POST['action']){ ?>
       
    97 		<div id="message" class="updated fade"><p><strong>Options saved.</strong></p></div>
       
    98 	<?php } ?>
       
    99 	<div class="wrap" id="add-to-facebook-options">
       
   100 		<h2>Add to Facebook Options</h2>
       
   101 		
       
   102 		<form method="post" action="<?php echo $_SERVER['PHP_SELF']."?".$_SERVER['QUERY_STRING']; ?>">
       
   103 			<fieldset>
       
   104 				<legend>Options:</legend>
       
   105 				<input type="hidden" name="action" value="save_add_to_facebook_options" />
       
   106 				<table width="100%" cellspacing="2" cellpadding="5" class="editform">
       
   107 					<tr>
       
   108 						<th valign="top" scope="row"><label for="link_type">Link Type:</label></th>
       
   109 						<td><select name="link_type">
       
   110 						<option value ="text"<?php if ($link == "text") { print " selected"; } ?>>Text Only</option>
       
   111 						<option value ="image"<?php if ($link == "image") { print " selected"; } ?>>Image Only</option>
       
   112 						<option value ="both"<?php if ($link == "both") { print " selected"; } ?>>Image and Text</option>
       
   113 						</select></td>
       
   114 					</tr>
       
   115 					<tr>
       
   116 						<th valign="top" scope="row"><label for="insertion_type">Insertion Type:</label></th>
       
   117 						<td><select name="insertion_type">
       
   118 						<option value ="auto"<?php if ($insert == "auto") { print " selected"; } ?>>Auto</option>
       
   119 						<option value ="template"<?php if ($insert == "template") { print " selected"; } ?>>Template</option>
       
   120 						</select></td>
       
   121 					</tr>
       
   122 				</table>
       
   123 			</fieldset>
       
   124 			<p class="submit">
       
   125 				<input type="submit" name="Submit" value="Update Options &raquo;" />
       
   126 			</p>
       
   127 		</form>
       
   128 	</div>
       
   129 <?php 
       
   130 }
       
   131 
       
   132 function add_to_facebook_add_options_page() {
       
   133 	// Add a new menu under Options:
       
   134 	add_options_page('Add to Facebook', 'Add to Facebook', 10, __FILE__, 'add_to_facebook_options_page');
       
   135 }
       
   136 
       
   137 function add_to_facebook_save_options() {
       
   138 	// create array
       
   139 	$add_to_facebook_options["link_type"] = $_POST["link_type"];
       
   140 	$add_to_facebook_options["insertion_type"] = $_POST["insertion_type"];
       
   141 	
       
   142 	update_option('add_to_facebook_options', $add_to_facebook_options);
       
   143 	$options_saved = true;
       
   144 }
       
   145 
       
   146 add_action('admin_menu', 'add_to_facebook_add_options_page');
       
   147 
       
   148 if (!get_option('add_to_facebook_options')){
       
   149 	// create default options
       
   150 	$add_to_facebook_options["link_type"] = 'text';
       
   151 	$add_to_facebook_options["insertion_type"] = 'auto';
       
   152 	
       
   153 	update_option('add_to_facebook_options', $add_to_facebook_options);
       
   154 }
       
   155 
       
   156 if ($_POST['action'] == 'save_add_to_facebook_options'){
       
   157 	add_to_facebook_save_options();
       
   158 }
       
   159 
       
   160 function facebookcss() {
       
   161 	?>
       
   162 	<link rel="stylesheet" href="<?php bloginfo('wpurl'); ?>/wp-content/plugins/add-to-facebook-plugin/facebook.css" type="text/css" media="screen" />
       
   163 	<?php
       
   164 }
       
   165 
       
   166 add_action('wp_head', 'facebookcss');
       
   167 ?>