Skip to content

Commit

Permalink
Cleanup. Bump to version 2.5
Browse files Browse the repository at this point in the history
git-svn-id: http://plugins.svn.wordpress.org/kk-star-ratings/trunk@1370018 b8457f37-d9ea-0310-8a92-e5e31aec5664
  • Loading branch information
bhittani committed Mar 13, 2016
1 parent ecca98a commit 3aff39c
Showing 1 changed file with 78 additions and 78 deletions.
156 changes: 78 additions & 78 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 <strong>allow your blog posts to be rated by your blog visitors</strong>. It also includes a <strong>widget</strong> 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
Expand All @@ -17,7 +17,7 @@
class BhittaniPlugin_kkStarRatings extends BhittaniPlugin
{
private $_Menus;

public function __construct($id, $nick, $ver)
{
parent::__construct($id, $nick, $ver);
Expand Down Expand Up @@ -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 '</style>';
}
/** function/method
Expand Down Expand Up @@ -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', '<'))
{
Expand All @@ -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();
Expand Down Expand Up @@ -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')
);
}
Expand All @@ -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');
}
Expand All @@ -325,7 +325,7 @@ public function options_page($opt)
* Return: void
*/
public function options_general()
{
{
$this->options_page('general');
}
/** function/method
Expand All @@ -334,7 +334,7 @@ public function options_general()
* Return: void
*/
public function options_stars()
{
{
$this->options_page('stars');
}
/** function/method
Expand All @@ -343,7 +343,7 @@ public function options_stars()
* Return: void
*/
public function options_tooltips()
{
{
$this->options_page('tooltips');
}
/** function/method
Expand All @@ -352,7 +352,7 @@ public function options_tooltips()
* Return: void
*/
public function options_reset()
{
{
$this->options_page('reset');
}
/** function/method
Expand All @@ -361,7 +361,7 @@ public function options_reset()
* Return: void
*/
public function options_info()
{
{
$this->options_page('info');
}
public function kksr_admin_reset_ajax()
Expand All @@ -383,7 +383,7 @@ public function kksr_admin_reset_ajax()
}
}
}

$Response = array();
$Response['success'] = 'true';
echo json_encode($Response);
Expand All @@ -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']:
Expand Down Expand Up @@ -454,7 +454,7 @@ public function kksr_ajax()
$Response[$pid]['success'] = true;

endforeach;

echo json_encode($Response);
die();
}
Expand All @@ -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 '';
}
Expand All @@ -491,7 +491,7 @@ public function markup($id=false)
}
}
$pos = parent::get_options('kksr_position');

$markup = '
<div class="kk-star-ratings '.($disabled || (is_archive() && parent::get_options('kksr_disable_in_archives')) ? 'disabled ' : ' ').$pos.($pos=='top-right'||$pos=='bottom-right' ? ' rgt' : ' lft').'" data-id="'.$id.'">
<div class="kksr-stars kksr-star gray">
Expand All @@ -510,7 +510,7 @@ public function markup($id=false)
{
$markup .= apply_filters('kksr_legend', parent::get_options('kksr_legend'), $id);
}
$markup .=
$markup .=
'</div>
<!-- kksr-legend -->
</div>
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -634,34 +634,34 @@ 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)
{
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]', '<span property="v:votes">'.$votes.'</span>', $legend);
$leg = str_replace('[avg]', '<span property="v:average">'.$avg.'</span>/<span property="v:best">'.$best.'</span>', $leg);
$leg = str_replace('[per]',$per.'%', $leg);
$leg = str_replace('[s]', $votes==1?'':'s', $leg);
$snippet = '<div xmlns:v="http://rdf.data-vocabulary.org/#" typeof="v:Review-aggregate">';

$snippet = '<div xmlns:v="http://rdf.data-vocabulary.org/#Rating" typeof="v:Review-aggregate">';
$snippet .= '<span property="v:itemreviewed" class="kksr-title">' . $title . '</span>';
$snippet .= '<span rel="v:rating">';
$snippet .= ' <span typeof="v:Rating">';
Expand All @@ -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'));

Expand All @@ -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);

Expand Down Expand Up @@ -739,4 +739,4 @@ function kk_star_ratings_get($lim=5, $cat=false)

endif;

?>
?>

0 comments on commit 3aff39c

Please sign in to comment.