digidownload.nl Author: pete scheepens Author URI: http://digidownload.nl Version: 1.7 Contact developer Pete Scheepens at info-at-portaljumper-dot-com */ add_action("wp_ajax_al_vote", "al_vote_func"); add_action("wp_ajax_nopriv_al_vote", "al_vote_func"); // create/update database tables register_activation_hook(__FILE__,'al_db_init'); // create database function al_db_init() { global $wpdb; require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); $sql2 = "CREATE TABLE " .$wpdb->prefix . "author_love ( `id` int(11) NOT NULL auto_increment, `author_id` int(11) NOT NULL, `ip_address` varchar(50) NOT NULL, `rating` int(11) NOT NULL, `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP, PRIMARY KEY (`id`), UNIQUE ( `author_id` , `ip_address`) ) AUTO_INCREMENT=1 ;"; dbDelta($sql2); al_check_options(); } // fill options with default values function al_check_options() { $checkoptions = get_option('author_love_opts',''); // fill defaults if empty if (empty($checkoptions)) { $aloptions['location'] = "br"; $aloptions['amount'] = "6"; $aloptions['image'] = "stars"; $aloptions["title"] = ''; $aloptions["single"] = 'no'; $aloptions['trans_author'] = 'Author'; $aloptions['trans_rating'] = 'Rating :'; $aloptions['trans_votes'] = 'vote(s)'; $aloptions['trans_yav'] = 'You have already voted!'; update_option('author_love_opts', $aloptions); } } // load css & js function moomoo_load() { wp_enqueue_script('jratings',plugins_url('/jquery/jRating.jquery.js', __FILE__)); wp_enqueue_style('al_css',plugins_url('/jquery/jRating.jquery.css', __FILE__)); } function jc_load() { wp_enqueue_script('jquery'); } add_action('wp_enqueue_scripts', 'jc_load'); add_action('wp_footer', 'moomoo_load'); // insert the div block add_filter('the_content', 'show_love'); function show_love ($content) { $singlecheck = 'if (is_single() ) '; $aloptions = get_option('author_love_opts'); if ($aloptions["single"] == "yes") $show = 1; else $show = ''; if ($aloptions['location'] == 'tl') $display = return_author_love('0','left',$aloptions["title"] , $show ) . $content; elseif ($aloptions['location'] == 'tr') $display = return_author_love('0','right',$aloptions["title"] , $show ) . $content; elseif ($aloptions['location'] == 'bl') $display = $content . return_author_love('0','left',$aloptions["title"] , $show ); elseif ($aloptions['location'] == 'br') $display = $content . return_author_love('0','right',$aloptions["title"] , $show ); else $display = $content; return $display; } // insert the dynamic jq code add_action('wp_footer', 'author_love_jq'); // admin options add_action('admin_menu', 'author_love_menu'); function author_love_menu() { add_options_page('author love', 'author love', 'manage_options', 'author_lovers','author_love_options_page'); } function author_love_options_page() { ?>

your settings were saved !

"; } $aloptions = get_option('author_love_opts'); ?>

Author_love Settings Menu (free version)

An AUTHOR rating system for WordPress

Where shall we show the rating blocks ?
when unchecked the ratings only show on single posts
when checked the ratings also show on the main pages.

> Show ratings on all posts/pages

Where should the rating block show up (in relation to your post content) ?
> -DISABLED > -bottom right ( More options in the PREMIUM version. )

How many start would you like to show ? (1-30)
Regardless of how many stars you choose, the total value is always 100%.
so with 3 stars 33% would fill 1 star. with 6 stars 33% would fill 2 stars etc.



Which image do you want in the rating bar ?
More options in the PREMIUM version.


What do you want to show above the rating bar ?
More options in the PREMIUM version.


Translation
This options is available in the PREMIUM version.



Helpful

Use the settings on the left to automatically show a rating block near your post content.
To modify your themes yourself you can set automatic rendering at 'DISABLED' and insert the php function
<?PHP render_author_love('author_id'); ?>
You can leave the author-id empty, but only if used inside the loop. If used inside the loop the function will automatically pull the post-author of the post displayed at that time.

Another option is the function :
<?PHP return_author_love( $author_id="FALSE", $pos="left" ,$author_info=""); ?>
$author_id = empty || (or) Any valid author ID
$pos = left || right
$author_info = empty || author_nicename


Live demo (takes you to digidownload.nl)
Other versions (takes you to digidownload.nl)

Coding & style by: Pete Scheepens

"; ?>
"; query($wpdb->prepare( "INSERT INTO " .$wpdb->prefix . "author_love (author_id,ip_address,rating) VALUES ('$id','$ip','$rate') " )) ) $W = "YOU ALREADY VOTED"; else $W = "thanks for voting"; $aResponse['type'] = 'success'; $aResponse['server'] = $W; echo json_encode($aResponse); die(); } // create dynamic JS in footer function author_love_jq($content) { $aloptions = get_option('author_love_opts'); if ($aloptions['image'] == 'hearts') $images = ",bigStarsPath:'/author-love/jquery/icons/heart.png'"; if ($aloptions['image'] == "stars") $images = ",bigStarsPath:'/author-love/jquery/icons/star.png'"; if ($aloptions['image'] == "arrows") $images = ",bigStarsPath:'/author-love/jquery/icons/arrow.png'"; if ($aloptions['image'] == "balls") $images = ",bigStarsPath:'/author-love/jquery/icons/ball.png'"; $link = admin_url('admin-ajax.php?action=al_vote'); $nonce= wp_create_nonce ('al_vote'); echo ' '; } // render rating block function render_author_love( $author_id="FALSE" ) { global $wpdb; if (empty($author_id) || $author_id == "FALSE") $author_id = get_the_author_meta('ID'); $average_rating = $wpdb->get_var( $wpdb->prepare(" SELECT AVG(rating) FROM " .$wpdb->prefix . "author_love WHERE author_id='$author_id' ") ); $average_rating = number_format($average_rating); $count_rating = $wpdb->get_var( $wpdb->prepare(" SELECT COUNT(rating) FROM " .$wpdb->prefix . "author_love WHERE author_id='$author_id' ") ); $visitor_ip = str_replace(".","",getIp() ); $path = plugins_url(); $id = $average_rating . "_" . $author_id . "|" . $visitor_ip . "|" . $path; echo "Author : $author_id
"; echo "
"; echo "
"; echo "

rating: $average_rating% - $count_rating votes

"; } function return_author_love( $author_id="FALSE", $pos="left" ,$author_info="",$single="no") { $data = ""; global $wpdb; if (empty($author_id) || $author_id == "FALSE") $author_id = get_the_author_meta('ID'); $author_info = get_the_author_meta('user_nicename'); $average_rating = $wpdb->get_var( $wpdb->prepare(" SELECT AVG(rating) FROM " .$wpdb->prefix . "author_love WHERE author_id='$author_id' ") ); $average_rating = number_format($average_rating); $count_rating = $wpdb->get_var( $wpdb->prepare(" SELECT COUNT(rating) FROM " .$wpdb->prefix . "author_love WHERE author_id='$author_id' ") ); $visitor_ip = str_replace(".","",getIp() ); $path = plugins_url(); $id = $average_rating . "_" . $author_id . "|" . $visitor_ip . "|" . $path; if ($single == "no" || empty($single)) { if (is_single() ) { $data .= "
"; if (!empty($author_info)) $data .= "
Author : $author_info
"; $data .= "
"; $data .= "

rating: $average_rating% - $count_rating votes

"; $data .= "
"; } else $data = ''; } else { $data .= "
"; if (!empty($author_info)) $data .= "
Author : $author_info
"; $data .= "
"; $data .= "

rating: $average_rating% - $count_rating votes

"; $data .= "
"; } return $data; } function getIp() { $ip = $_SERVER['REMOTE_ADDR']; if (!empty($_SERVER['HTTP_CLIENT_IP'])) { $ip = $_SERVER['HTTP_CLIENT_IP']; } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; } return $ip; } ?>