'thanks_widget_latest_thanks', 'description' => __('the latest or the most thanked post titles with total thanks quant', 'thankyou'));
$this->WP_Widget('thanks-latest-thanks', __('Thanks Stat','thankyou'), $widget_ops);
$this->alt_option_name = 'thanks_widget_latest_thanks';
}
function widget($args, $instance) {
global $wpdb, $thanksCountersTable;
extract($args);
$title = apply_filters('widget_title', empty($instance['title']) ? __('Thanks Stat', 'thankyou') : $instance['title']);
// number of rows to show
if ( !$number = (int) $instance['number'] ) {
$number = 5;
} else if ( $number < 1 ) {
$number = 1;
} else if ( $number > 15 ) {
$number = 15;
}
// what content to show
$content = $instance['content'];
if ($content!='latest_thanked' && $content!='most_thanked') {
$content = 'latest_thanked';
}
if ($content=='latest_thanked') {
$order = 'counters.updated';
} else {
$order = 'counters.quant';
}
$query = "select posts.ID, posts.post_title, counters.quant, counters.updated
from $wpdb->posts posts
left join $thanksCountersTable counters on counters.post_id=posts.ID
where counters.quant>0 and posts.post_type='post'
order by $order desc limit 0, $number";
$records = $wpdb->get_results($query);
if ($wpdb->last_error) {
echo 'error: '.$wpdb->last_error;
return;
}
if (is_array($records) && count($records)) {
$date_format = get_option('date_format').' '.get_option('time_format');
$output = $before_widget;
if ($title) {
$output .= $before_title . $title . $after_title;
}
$output .= '
';
foreach ($records as $record) {
$updated = mysql2date($date_format, $record->updated, true);
$quant = ($record->quant) ? $record->quant : 0;
$output .= ''.$record->post_title.' ('.$quant.') ';
}
$output .= ' ';
$output .= $after_widget;
$output = apply_filters('thanks_stat_sidebar', $output);
echo $output;
}
}
// end of widget()
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['title'] = strip_tags($new_instance['title']);
$instance['number'] = (int) $new_instance['number'];
$instance['content'] = strip_tags($new_instance['content']);
return $instance;
}
function form( $instance ) {
$title = esc_attr($instance['title']);
if (!$number = (int) $instance['number']) {
$number = 5;
}
$content = esc_attr($instance['content']);
?>
>
>
15) {
$number = 15;
}
return $number;
}
// end of thanks_get_dashboard_rows()
function thanks_dashboard_content() {
global $wpdb, $thanksCountersTable;
// number of rows in result data set
$number = thanks_get_dashboard_rows();
// what content to show
$content = thanks_get_dashboard_content_kind();
if ($content=='latest_thanked') {
$order = 'counters.updated';
} else {
$order = 'counters.quant';
}
$ww_query = "select posts.ID, posts.post_title, counters.quant, counters.updated
from $wpdb->posts posts
left join $thanksCountersTable counters on counters.post_id=posts.ID
where counters.quant>0 and posts.post_type='post'
order by $order desc limit 0, $number";
$ww_records = $wpdb->get_results($ww_query);
if ($wpdb->last_error) {
echo 'error: '.$wpdb->last_error;
return;
}
$ww_foundPosts = count($ww_records);
if ($ww_foundPosts > 0) {
$output ='
';
$date_format = get_option('date_format').' '.get_option('time_format');
$i = 0;
foreach ($ww_records as $ww_record) {
if ($i & 1) {
$class = 'class="alternate"';
} else {
$class = '';
}
$i++;
$updated = mysql2date($date_format, $ww_record->updated, true);
$quant = ($ww_record->quant) ? $ww_record->quant : 0;
$output .= '
'.$quant.'
';
}
$output .= '
';
$showStatLink = get_option('thanks_dashboard_statistics_link_show');
if ($showStatLink==null || $showStatLink==1) {
$output .= '
';
}
$showAuthorLink = get_option('thanks_dashboard_author_link_show');
if ($showAuthorLink==null || $showAuthorLink==1) {
$output .= '
';
}
$output .= '
';
$output = apply_filters('thanks_stat_dashboard', $output);
echo $output;
} else {
_e('No thanks yet', 'thankyou');
}
}
// end of thanks_dashboard_content()
function thanks_dashboard_setup() {
// update options
if (isset($_POST['widget_id']) && $_POST['widget_id']=='dashboard_thanks') {
if (isset($_POST[TD_ROWS_NUMBER])) {
$option = stripslashes_deep($_POST[TD_ROWS_NUMBER]);
if (!is_numeric($option) || $option<0) {
$option = 5;
} else if ($option>15) {
$option = 15;
}
update_option(TD_ROWS_NUMBER, $option);
}
if (isset($_POST[TD_CONTENT])) {
$option = stripslashes_deep($_POST[TD_CONTENT]);
update_option(TD_CONTENT, $option);
}
if (isset($_POST[TD_STAT_LINK])) {
$option = (int) stripslashes_deep($_POST[TD_STAT_LINK]);
} else {
$option = 0;
}
update_option(TD_STAT_LINK, $option);
if (isset($_POST[TD_AUTHOR_LINK])) {
$option = (int) stripslashes_deep($_POST[TD_AUTHOR_LINK]);
} else {
$option = 0;
}
update_option(TD_AUTHOR_LINK, $option);
}
$number = thanks_get_dashboard_rows();
$content = get_option(TD_CONTENT);
$statLinkChecked = get_option(TD_STAT_LINK);
$authorLinkChecked = get_option(TD_AUTHOR_LINK);
?>
>
>
/>
/>
'."\n";
}
if (is_admin()) {
add_action('wp_dashboard_setup','add_thanks_dashboard_widget');
}
// end of thanks_cssAction()
?>