/*
Copyright 2009 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
Plugin Name: Friend Connect Commenting Plugin
Description: This plgin allows a user to leave comments using his or her Friend Connect (http://www.google.com/friendconnect/) id to signin. More description can be found in the attached README file
Version: 1.0
*/
include_once(ABSPATH . 'wp-includes/registration.php');
include_once(ABSPATH . 'wp-includes/user.php');
// The wordpress hooks:
// wp_head is where we put all the javascript and css code
add_action( 'wp_head', 'fc_wp_head');
// The comment form action gets called right after the comment block has been rendered
// and before closing the form
add_action( 'comment_form', 'fc_wp_comment_form');
// This filter takes care of pulling out the avatar image for us to be displayed
// beside the comment. For our plugin, the avatar image is the one that
// is obtained from the FC thumbnailUrl function call (see code below)
add_filter('get_avatar', 'fc_wp_get_avatar', 20, 5);
// Please modify the following function to return a value that
// you obtain after registering your site with FriendConnect
function fc_get_site_id () {
return '01283733828436432947';
}
// The fc_wp_get_avatar function.
// After wordpress renders each comment, it calls the filter get_avatar
// In this plugin, we have implemented this filter to return the FC url
// location that we have stored in the wp_metadata database table. The
// code to put it into the database is in server_code.php that comes
// with this plugin
// All that we are doing here is to get the email, lookup the userid from
// the user database and then get the image_url from the wp_metadata table
function fc_wp_get_avatar($avatar, $id_or_email, $size, $default, $alt) {
global $wpdb;
if (!empty($id_or_email->user_id)) {
$email = $id_or_email->comment_author_email;
$query = "SELECT * FROM `wp_users` WHERE user_email = '$email' LIMIT 1;";
$res = $wpdb->get_col($query);
// We dont know if this user, so return whatever was given to me
if (count($res) <= 0)
return $avatar;
// Do not change the admin's image
if ($res[0] == 1)
return $avatar;
// Get the image and return the altered $avatar
$image_url = get_usermeta( $res[0], "image_url");
return "";
}
}
// The fc_wp_comment_form function
// This just creates a div tag that will be replaced by the javascript code
// when the page gets loaded
function fc_wp_comment_form() {
?>