From 3aff39c9011ba804e9aa13f7d3271f5bb3a42570 Mon Sep 17 00:00:00 2001 From: bhittani Date: Sun, 13 Mar 2016 04:11:42 +0000 Subject: [PATCH] Cleanup. Bump to version 2.5 git-svn-id: http://plugins.svn.wordpress.org/kk-star-ratings/trunk@1370018 b8457f37-d9ea-0310-8a92-e5e31aec5664 --- index.php | 156 +++++++++++++++++++++++++++--------------------------- 1 file changed, 78 insertions(+), 78 deletions(-) diff --git a/index.php b/index.php index 74d21da..89b8ed6 100644 --- a/index.php +++ b/index.php @@ -2,9 +2,9 @@ /* Plugin Name: kk Star Ratings -Plugin URI: http://wakeusup.com/2011/05/kk-star-ratings/ +Plugin URI: https://github.com/kamalkhan/kk-star-ratings Description: Renewed from the ground up(as of v2.0), clean, animated and light weight ratings feature for your blog. With kk Star Ratings, you can allow your blog posts to be rated by your blog visitors. It also includes a widget which you can add to your sidebar to show the top rated post. Wait! There is more to it. Enjoy the extensive options you can set to customize this plugin. -Version: 2.4.1 +Version: 2.5 Author: Kamal Khan Author URI: http://bhittani.com License: GPLv2 or later @@ -17,7 +17,7 @@ class BhittaniPlugin_kkStarRatings extends BhittaniPlugin { private $_Menus; - + public function __construct($id, $nick, $ver) { parent::__construct($id, $nick, $ver); @@ -129,7 +129,7 @@ public function css_custom() echo $star_gray ? '.kk-star-ratings .kksr-star.gray { background-image: url('.$star_gray.'); }' : ''; echo $star_yellow ? '.kk-star-ratings .kksr-star.yellow { background-image: url('.$star_yellow.'); }' : ''; echo $star_orange ? '.kk-star-ratings .kksr-star.orange { background-image: url('.$star_orange.'); }' : ''; - + echo ''; } /** function/method @@ -167,7 +167,7 @@ public function activate() $Options['kksr_legend'] = isset($Old_plugin['legend']) ? $Old_plugin['legend'] : $opt_legend; $Options['kksr_init_msg'] = isset($Old_plugin['init_msg']) ? $Old_plugin['init_msg'] : $opt_init_msg; $Options['kksr_column'] = isset($Old_plugin['column']) ? $Old_plugin['column'] : $opt_column; - + // Upgrade from old plugin(<2.0) to renewed plugin(>=2.0) if(!$ver_previous || version_compare($ver_previous, '2.0', '<')) { @@ -177,12 +177,12 @@ public function activate() // Update previous ratings global $wpdb; $table = $wpdb->prefix . 'postmeta'; - $Posts = $wpdb->get_results("SELECT a.ID, b.meta_key, b.meta_value - FROM " . $wpdb->posts . " a, $table b - WHERE a.ID=b.post_id AND + $Posts = $wpdb->get_results("SELECT a.ID, b.meta_key, b.meta_value + FROM " . $wpdb->posts . " a, $table b + WHERE a.ID=b.post_id AND ( - b.meta_key='_kk_ratings_ratings' OR - b.meta_key='_kk_ratings_casts' OR + b.meta_key='_kk_ratings_ratings' OR + b.meta_key='_kk_ratings_casts' OR b.meta_key='_kk_ratings_ips' ) ORDER BY a.ID ASC"); $Wrap = array(); @@ -241,56 +241,56 @@ public function menu() { // Create main menu tab $this->_Menus[] = add_menu_page( - $this->nick.' - Settings', - $this->nick, - 'manage_options', - $this->id.'_settings', + $this->nick.' - Settings', + $this->nick, + 'manage_options', + $this->id.'_settings', array(&$this, 'options_general'), self::file_uri('icon.png') ); // Create images menu tab $this->_Menus[] = add_submenu_page( - $this->id.'_settings', - $this->nick.' - Settings', - 'Settings', - 'manage_options', - $this->id.'_settings', + $this->id.'_settings', + $this->nick.' - Settings', + 'Settings', + 'manage_options', + $this->id.'_settings', array(&$this, 'options_general') ); // Create images menu tab $this->_Menus[] = add_submenu_page( - $this->id.'_settings', - $this->nick.' - Stars', - 'Stars', - 'manage_options', - $this->id.'_settings_stars', + $this->id.'_settings', + $this->nick.' - Stars', + 'Stars', + 'manage_options', + $this->id.'_settings_stars', array(&$this, 'options_stars') ); // Create tooltips menu tab $this->_Menus[] = add_submenu_page( - $this->id.'_settings', - $this->nick.' - Tooltips', - 'Tooltips', - 'manage_options', - $this->id.'_settings_tooltips', + $this->id.'_settings', + $this->nick.' - Tooltips', + 'Tooltips', + 'manage_options', + $this->id.'_settings_tooltips', array(&$this, 'options_tooltips') ); // Create reset menu tab $this->_Menus[] = add_submenu_page( - $this->id.'_settings', - $this->nick.' - Reset', - 'Reset', - 'manage_options', - $this->id.'_settings_reset', + $this->id.'_settings', + $this->nick.' - Reset', + 'Reset', + 'manage_options', + $this->id.'_settings_reset', array(&$this, 'options_reset') ); // Create info menu tab $this->_Menus[] = add_submenu_page( - $this->id.'_settings', - $this->nick.' - Help', - 'Help', - 'manage_options', - $this->id.'_settings_info', + $this->id.'_settings', + $this->nick.' - Help', + 'Help', + 'manage_options', + $this->id.'_settings_info', array(&$this, 'options_info') ); } @@ -300,22 +300,22 @@ public function menu() * Return: void */ public function options_page($opt) - { - if (!current_user_can('manage_options')) + { + if (!current_user_can('manage_options')) { wp_die( __('You do not have sufficient permissions to access this page.') ); } $sidebar = true; $h3 = 'kk Star Ratings'; $Url = array( - array( - 'title' => 'Home', - 'link' => 'http://wpapis.com/kk-star-ratings/' - ), - array( - 'title' => 'Changelog', - 'link' => 'http://wpapis.com/kk-star-ratings/#tab-1369077219827-3-8' - ) + // array( + // 'title' => 'Github Repository', + // 'link' => 'https://github.com/kamalkhan/kk-star-ratings' + // ), + // array( + // 'title' => 'Changelog', + // 'link' => '#' + // ) ); include self::file_path('admin.php'); } @@ -325,7 +325,7 @@ public function options_page($opt) * Return: void */ public function options_general() - { + { $this->options_page('general'); } /** function/method @@ -334,7 +334,7 @@ public function options_general() * Return: void */ public function options_stars() - { + { $this->options_page('stars'); } /** function/method @@ -343,7 +343,7 @@ public function options_stars() * Return: void */ public function options_tooltips() - { + { $this->options_page('tooltips'); } /** function/method @@ -352,7 +352,7 @@ public function options_tooltips() * Return: void */ public function options_reset() - { + { $this->options_page('reset'); } /** function/method @@ -361,7 +361,7 @@ public function options_reset() * Return: void */ public function options_info() - { + { $this->options_page('info'); } public function kksr_admin_reset_ajax() @@ -383,7 +383,7 @@ public function kksr_admin_reset_ajax() } } } - + $Response = array(); $Response['success'] = 'true'; echo json_encode($Response); @@ -396,7 +396,7 @@ public function kksr_ajax() $Response = array(); - $total_stars = is_numeric(parent::get_options('kksr_stars')) ? parent::get_options('kksr_stars') : 5; + $total_stars = is_numeric(parent::get_options('kksr_stars')) ? parent::get_options('kksr_stars') : 5; $stars = is_numeric($_POST['stars']) && ((int)$_POST['stars']>0) && ((int)$_POST['stars']<=$total_stars) ? $_POST['stars']: @@ -454,7 +454,7 @@ public function kksr_ajax() $Response[$pid]['success'] = true; endforeach; - + echo json_encode($Response); die(); } @@ -475,7 +475,7 @@ protected function exclude_cat($id) public function markup($id=false) { $id = !$id ? get_the_ID() : $id; - if($this->exclude_cat($id)) + if($this->exclude_cat($id)) { return ''; } @@ -491,7 +491,7 @@ public function markup($id=false) } } $pos = parent::get_options('kksr_position'); - + $markup = '
@@ -510,7 +510,7 @@ public function markup($id=false) { $markup .= apply_filters('kksr_legend', parent::get_options('kksr_legend'), $id); } - $markup .= + $markup .= '
@@ -541,13 +541,13 @@ public function manual($atts) } public function filter($content) { - if(parent::get_options('kksr_enable')) : + if(parent::get_options('kksr_enable')) : if( ((parent::get_options('kksr_show_in_home')) && (is_front_page() || is_home())) || ((parent::get_options('kksr_show_in_archives')) && (is_archive())) || ((parent::get_options('kksr_show_in_posts')) && (is_single())) || ((parent::get_options('kksr_show_in_pages')) && (is_page())) - ) : + ) : remove_shortcode('kkratings'); remove_shortcode('kkstarratings'); $content = str_replace('[kkratings]', '', $content); @@ -581,7 +581,7 @@ public function kk_star_ratings_get($total=5, $cat=false) $table3 = $wpdb->prefix . 'term_relationships'; $rated_posts = $wpdb->get_results("SELECT a.ID, a.post_title, b.meta_value AS 'ratings' FROM " . $wpdb->posts . " a, $table b, $table2 c, $table3 d, $table e WHERE c.term_taxonomy_id=d.term_taxonomy_id AND c.term_id=$cat AND d.object_id=a.ID AND a.post_status='publish' AND a.ID=b.post_id AND a.ID=e.post_id AND b.meta_key='_kksr_avg' AND e.meta_key='_kksr_casts' ORDER BY b.meta_value DESC, e.meta_value DESC LIMIT $total"); } - + return $rated_posts; } public function add_column($Columns) @@ -634,11 +634,11 @@ public function sort_columns_helper($Query) { return; } - $orderby = $Query->get( 'orderby'); + $orderby = $Query->get( 'orderby'); if($orderby=='kk_star_ratings') - { + { $Query->set('meta_key','_kksr_avg'); - $Query->set('orderby','meta_value_num'); + $Query->set('orderby','meta_value_num'); } } public function grs_legend($legend, $id) @@ -646,22 +646,22 @@ public function grs_legend($legend, $id) if(parent::get_options('kksr_grs')) { $title = get_the_title($id); - + $best = parent::get_options('kksr_stars'); $score = get_post_meta($id, '_kksr_ratings', true) ? get_post_meta($id, '_kksr_ratings', true) : 0; - + if($score) { $votes = get_post_meta($id, '_kksr_casts', true) ? get_post_meta($id, '_kksr_casts', true) : 0; $avg = $score ? number_format((float)($score/$votes), 2, '.', '') : 0; $per = $score ? number_format((float)((($score/$votes)/5)*100), 2, '.', '') : 0; - + $leg = str_replace('[total]', ''.$votes.'', $legend); $leg = str_replace('[avg]', ''.$avg.'/'.$best.'', $leg); $leg = str_replace('[per]',$per.'%', $leg); $leg = str_replace('[s]', $votes==1?'':'s', $leg); - - $snippet = '
'; + + $snippet = '
'; $snippet .= '' . $title . ''; $snippet .= ''; $snippet .= ' '; @@ -674,24 +674,24 @@ public function grs_legend($legend, $id) { $snippet = parent::get_options('kksr_init_msg'); } - + return $snippet; } return $legend; } } - $kkStarRatings_obj = new BhittaniPlugin_kkStarRatings('bhittani_plugin_kksr', 'kk Star Ratings', '2.4'); - + $kkStarRatings_obj = new BhittaniPlugin_kkStarRatings('bhittani_plugin_kksr', 'kk Star Ratings', '2.5'); + // Setup register_activation_hook(__FILE__, array($kkStarRatings_obj, 'activate')); - + // Scripts add_action('wp_enqueue_scripts', array($kkStarRatings_obj, 'js')); add_action('wp_enqueue_scripts', array($kkStarRatings_obj, 'css')); add_action('wp_head', array($kkStarRatings_obj, 'css_custom')); add_action('admin_init', array($kkStarRatings_obj, 'admin_scripts')); - + // Menu add_action('admin_menu', array($kkStarRatings_obj, 'menu')); @@ -704,7 +704,7 @@ public function grs_legend($legend, $id) add_filter('the_content', array($kkStarRatings_obj, 'filter')); add_shortcode('kkratings', array($kkStarRatings_obj, 'manual')); add_shortcode('kkstarratings', array($kkStarRatings_obj, 'manual')); - + // Google Rich Snippets add_filter('kksr_legend', array($kkStarRatings_obj, 'grs_legend'), 1, 2); @@ -739,4 +739,4 @@ function kk_star_ratings_get($lim=5, $cat=false) endif; -?> \ No newline at end of file +?>