0){ $limit = ' LIMIT 0,'.$amt; }
$extraquery = '';
if (count($filter_users)>0){
$extraquery = ' AND '.$wpdb->base_prefix.'users.user_login != \'';
$extraquery .= implode("' AND ".$wpdb->base_prefix."users.user_login != '",$filter_users);
$extraquery .= '\' ';
}
$mktime_b = mktime( 0, 0, 0, $month, 1, $year );
$mktime_a = mktime( 0, 0, 0, $month, date('t'), $year );
$extraquery .= ' AND timestamp >= "' . $mktime_b . '"';
$extraquery .= ' AND timestamp <= "' . $mktime_a . '"';
$a = array();
$array = $wpdb->get_results('SELECT SUM('.$wpdb->base_prefix.'cp.points) AS meta_value, '.$wpdb->base_prefix.'users.ID, '.$wpdb->base_prefix.'users.user_login, '.$wpdb->base_prefix.'users.display_name
FROM `'.$wpdb->base_prefix.'users`, `'.$wpdb->base_prefix.'cp`
WHERE 1=1
AND '.$wpdb->base_prefix.'users.ID = '.$wpdb->base_prefix.'cp.uid
'.$extraquery.'
GROUP BY '.$wpdb->base_prefix.'cp.uid
ORDER BY SUM('.$wpdb->base_prefix.'cp.points)+0 DESC'
. $limit . ';'
,ARRAY_A);
foreach($array as $x=>$y){
if( $y['ID'] )
$a[$x] = array( "id"=>$y['ID'], "user"=>$y['user_login'], "display_name"=>$y['display_name'], "points"=>($y['meta_value']==0)?0:$y['meta_value'], "points_formatted"=>cp_formatPoints($y['meta_value']) );
}
return $a;
}
function month_cp_widgets(){
/** CubePoints Top Users Widget */
class month_cp_topUsersWidget extends WP_Widget {
// constructor
function month_cp_topUsersWidget() {
parent::WP_Widget('month_cp_topUsersWidget', 'CubePoints Top Users Month', array('description' => 'Use this widget to showcase the users with the most points of the month.'));
}
// widget main
function widget($args, $instance) {
extract($args, EXTR_SKIP);
echo $before_widget;
$title = empty($instance['title']) ? ' ' : apply_filters('widget_title', $instance['title']);
if ( !empty( $title ) ) { echo $before_title . $title . $after_title; };
$top = month_cp_getAllPoints($instance['num'],get_option('cp_topfilter'),$instance['months']);
do_action('month_cp_topUsersWidget_before');
echo apply_filters('month_cp_topUsersWidget_before','
');
$line = apply_filters('month_cp_topUsersWidget_line','- %string%
');
$line = str_replace('%style%', $instance['style'], $line);
foreach($top as $x=>$y){
$user = get_userdata($y['id']);
$string = str_replace('%string%', '', $instance['text']);
$string = str_replace('%string%',$string,$line);
$string = apply_filters('cp_displayUserInfo',$string,$y,$x+1);
echo $string;
}
echo apply_filters('month_cp_topUsersWidget_after','
');
do_action('month_cp_topUsersWidget_after');
echo $after_widget;
}
// widget settings update
function update($new_instance, $old_instance) {
$instance = $old_instance;
$instance['title'] = strip_tags($new_instance['title']);
$instance['num'] = ((int) $new_instance['num'] > 0 ) ? (int) $new_instance['num'] : 1 ;
$instance['text'] = trim($new_instance['text']);
$instance['months'] = intval($new_instance['months']);
$instance['style'] = trim($new_instance['style']);
return $instance;
}
// widget settings form
function form($instance) {
$default = array( 'title' => __('Month Top Users', 'cp') , 'num' => 3 , 'months' => 0, 'text' => '%user% (%points%)', 'style' => 'list-style:none;' );
$instance = wp_parse_args( (array) $instance, $default );
$field = 'title';
$field_id = $this->get_field_id($field);
$field_name = $this->get_field_name($field);
echo "\r\n".'';
$field = 'num';
$field_id = $this->get_field_id($field);
$field_name = $this->get_field_name($field);
echo "\r\n".''.__('Number of top users to show', 'cp').':
';
$field = 'months';
$field_id = $this->get_field_id($field);
$field_name = $this->get_field_name($field);
echo "\r\n".''.__('How much months back ?', 'cp').':
';
$field = 'text';
$field_id = $this->get_field_id($field);
$field_name = $this->get_field_name($field);
echo "\r\n".''.__('Text', 'cp').':
';
echo "\r\n".''.__('Shortcodes', 'cp') . ':
';
echo __('Number of points', 'cp') . ' - %points%' . '
';
echo __('Points (number only)', 'cp') . ' - %npoints%' . '
';
echo __('User display name', 'cp') . ' - %user%' . '
';
echo __('User login ID', 'cp') . ' - %username%' . '
';
echo __('User ID', 'cp') . ' - %userid%' . '
';
echo __('User ranking', 'cp') . ' - %place%' . '
';
echo __('Email MD5 hash', 'cp') . ' - %emailhash%' . '
';
echo '
';
$field = 'style';
$field_id = $this->get_field_id($field);
$field_name = $this->get_field_name($field);
echo "\r\n".''.__('Style', 'cp').':
';
echo "\r\n".''.__('Note', 'cp') . ': '.__('This adds the following style to the list element. Shortcodes from above may be used here. The %emailhash% shortcode, for example, could be used to display gravatars.', 'cp').'
';
}
}
// register widget
register_widget("month_cp_topUsersWidget");
}
function cubeshortcode( $atts, $content )
{
extract(shortcode_atts(array(
"month" => 0,
"year" => 0,
"users" => 3,
"style" => 'list-style:none;',
"title" => '%date%
'
), $atts));
$month = $month <= 0 ? date('n')+$month : $month;
$year = $year <= 0 ? date('Y')+$year : $year;
$adate = date('F Y', mktime( 0, 0, 0, $month, 1, $year ) );
$title = str_replace( array( '%date%' ), array( $adate ), $title);
$res = $title;
$top = month_cp_getAllPoints($users,get_option('cp_topfilter'),$month,$year);
$res.= '';
$line = apply_filters('month_cp_topUsersWidget_line','- %string%
');
$line = str_replace( array( '%style%' ), array( $style ), $line);
foreach($top as $x=>$y){
$user = get_userdata($y['id']);
$string = str_replace('%string%', '', $content);
$string = str_replace('%string%',$string,$line);
$string = apply_filters('cp_displayUserInfo',$string,$y,$x+1);
$res.= $string;
}
$res.= '
';
if( count( $top ) > 0 ){
return $res;
}else{
return '';
}
}
add_shortcode( 'cp', 'cubeshortcode' );
?>