You can easily do this using a custom module that contains code similar to the following one.
function YOURMODULENAME_print_rating($nid, $fivestar_widget) {
$path = drupal_get_path('module', 'fivestar');
drupal_add_js($path . '/js/fivestar.js');
drupal_add_css($path . '/css/fivestar.css');
$voting_message = '';
$output = '';
$is_login = user_is_logged_in();
$rating = votingapi_select_single_result_value(array(
'entity_id' => $nid,
'entity_type' => 'node',
'tag' => 'vote',
'function' => 'average',
));
if ($is_login) {
if (isset($rating)) {
$voting_message = "<div>You have already rated this.</div>";
$output = theme('fivestar_static', array('rating' => $rating, 'stars' => 5, 'tag' => 'vote')) . $voting_message;
}
else {
$output = render($fivestar_widget);
}
}
else {
$fivestar_links = l('Login', 'user/login') . ' or ' . l('Register', 'user/register');
$voting_message = "<div>Only registered user can rate this content type.<br/>$fivestar_links to rate this content type.</div>";
$output = theme('fivestar_static', array('rating' => $rating, 'stars' => 5, 'tag' => 'vote')) . $voting_message;
}
return $output;
}
Use the below snippet in your node template file.
hide($content['field_fivestar_rating']);// This line will hide the stars which are coming from the fivestar module.
print YOURMODULENAME_print_rating($node->nid, $content['field_fivestar_rating']);// This will print the fivestar.