function widget($args, $instance) { extract($args, EXTR_SKIP); if (!(!is_user_logged_in() && $instance['text_alt'] == '')) { echo $before_widget; $title = empty($instance['title']) ? ' ' : apply_filters('widget_title', $instance['title']); if (!empty($title)) { echo $before_title . $title . $after_title; } if (is_user_logged_in()) { $string = str_replace('%points%', '<span class="cp_points_display">' . cp_displayPoints(0, 1, 1) . '</span>', $instance['text']); } else { $string = $instance['text_alt']; } ?> <?php do_action('cp_pointsWidget_before'); ?> <?php if ($instance['html'] == '') { ?> <ul> <li><?php echo $string; ?> </li> <?php do_action('cp_pointsWidget'); ?> </ul> <?php } else { echo str_replace('%text%', $string, $instance['html']); } ?> <?php do_action('cp_pointsWidget_after'); ?> <?php echo $after_widget; } }
function widget($args, $instance) { extract($args, EXTR_SKIP); if (!(!is_user_logged_in() && $instance['text_alt'] == '')) { echo $before_widget; $title = empty($instance['title']) ? ' ' : apply_filters('widget_title', $instance['title']); if (!empty($title)) { echo $before_title . $title . $after_title; } if (is_user_logged_in()) { // Set default text, in case something messes up and resets the text to display to be null if ($instance['text'] == '') { $instance['text'] = 'Points: %points%'; } $string = str_replace('%points%', '<span class="cp_points_display">' . cp_displayPoints(0, 1, 1) . '</span>', $instance['text']); } else { $string = $instance['text_alt']; } //start output do_action('cp_pointsWidget_before'); if ($instance['html'] == '') { ?> <ul> <li><?php echo $string; ?> </li> <?php do_action('cp_pointsWidget'); ?> </ul> <?php } else { echo str_replace('%text%', $string, $instance['html']); } do_action('cp_pointsWidget_after'); echo $after_widget; } }
function cp_manage_form_submit() { header("Content-Type: application/json"); if (!current_user_can('manage_options')) { $response = json_encode(array('error' => __('You do not have sufficient permission to manage points!', 'cp'))); echo $response; exit; } if ($_POST['points'] != '' && $_POST['user_id'] != '') { $points = (int) $_POST['points']; $uid = (int) $_POST['user_id']; $user = get_userdata($uid); if ($user->ID == NULL) { $response = json_encode(array('error' => __('User does not exist!', 'cp'))); echo $response; exit; } if ($points < 0) { $points = 0; } cp_points_set('admin', $uid, $points, cp_currentUser()); } else { $response = json_encode(array('error' => __('Invalid request!', 'cp'))); echo $response; exit; } $response = json_encode(array('error' => 'ok', 'points' => cp_displayPoints($uid, 1, 0), 'points_formatted' => cp_displayPoints($uid, 1, 1), 'username' => $user->user_login, 'user_id' => $user->ID)); echo $response; exit; }
function cp_module_donate_do() { $recipient = $_POST['recipient']; $points = $_POST['points']; $message = htmlentities(stripslashes($_POST['message']), ENT_QUOTES, 'UTF-8'); $user = get_userdatabylogin($recipient); if (!is_user_logged_in()) { $r['success'] = false; $r['message'] = __('You must be logged in to make a donation!', 'cp'); } else { if ($recipient == '') { $r['success'] = false; $r['message'] = __('Please enter the username of the recipient!', 'cp'); } else { if ($user->ID == '') { $r['success'] = false; $r['message'] = __('You have entered an invalid recipient!', 'cp'); } else { if ($user->ID == cp_currentUser()) { $r['success'] = false; $r['message'] = __('You cannot donate to yourself!', 'cp'); } else { if (!is_numeric($points)) { $r['success'] = false; $r['message'] = __('You have entered an invalid number of points!', 'cp'); } else { if ((int) $points < 1) { $r['success'] = false; $r['message'] = __('You have to donate at least one point!', 'cp'); } else { if ((int) $points != (double) $points) { $r['success'] = false; $r['message'] = __('You have entered an invalid number of points!', 'cp'); } else { if ((int) $points > (int) cp_getPoints(cp_currentUser())) { $r['success'] = false; $r['message'] = __('You do not have that many points to donate!', 'cp'); } else { if (strlen($message) > 160) { $r['success'] = false; $r['message'] = __('The message you have entered is too long!', 'cp'); } else { $message = mb_convert_encoding($message, 'HTML-ENTITIES', 'UTF-8'); $r['success'] = true; $r['message'] = __('Your donation is successful!', 'cp'); cp_points('donate_from', $user->ID, $points, serialize(array("from" => cp_currentUser(), "message" => $message))); cp_points('donate_to', cp_currentUser(), -$points, serialize(array("to" => $user->ID, "message" => $message))); $r['pointsd'] = cp_displayPoints(0, 1, 1); $r['points'] = cp_displayPoints(0, 1, 0); } } } } } } } } } echo json_encode($r); die; }
// Need both for grab data from pre-cubepoints 3.0 $cp_bp_donation_results = $wpdb->get_var("SELECT COUNT(*) FROM " . CUBEPTS3 . " WHERE type='donate_to' AND uid = " . $bp->displayed_user->id); $cp_bp_dailylogin_results = $wpdb->get_var("SELECT COUNT(*) FROM " . CUBEPTS3 . " WHERE type='dailypoints' AND uid = " . $bp->displayed_user->id); // Check if CubePoints 2 database exists, if it does a query on it. if ($wpdb->get_var("SHOW TABLES LIKE '" . CP_DB . "'") != CP_DB || (int) get_option('cp_db_version') < 1.3) { define('CUBEPTS2', $wpdb->prefix . 'cubepoints'); $cp_bp_donation_resultscp2 = $wpdb->get_var("SELECT COUNT(*) FROM " . CUBEPTS2 . " WHERE type='donate' AND uid = " . $bp->displayed_user->id); $cp_bp_dailylogin_resultscp2 = $wpdb->get_var("SELECT COUNT(*) FROM " . CUBEPTS2 . " WHERE type='login' AND uid = " . $bp->displayed_user->id); } else { // User Installed CubePoints 3.0 and never had Cubepoints 2 $cp_bp_donation_resultscp2 = 0; $cp_bp_dailylogin_resultscp2 = 0; } $cp_bp_donation_results = $cp_bp_donation_results + $cp_bp_donation_resultscp2; $cp_bp_dailylogin_results = $cp_bp_dailylogin_results + $cp_bp_dailylogin_resultscp2; $cb_bp_pointtotalaward_points = cp_displayPoints($bp->displayed_user->id, 1, $return, 0, $format); if (get_option('bp_spf_support_onoff_cp_bp')) { // Simple Press Forum Support if (function_exists('sf_get_member_item')) { $cp_bp_spf_postcount = sf_get_member_item($bp->displayed_user->id, 'posts'); } } // NOT WORKING YET do_action( 'log_verifications_screen', 'cb_bp_awards_remove_screen_notifications' ); echo '<p align="center"><a name="cbawards"></a>'; echo '<a href="#cbawards" id="cbgroups" class="cbawardslnk">' . __('Groups', 'cp_buddypress') . '</a> '; echo '<a href="#cbawards" id="cbfriend" class="cbawardslnk">' . __('Friends', 'cp_buddypress') . '</a> '; echo '<a href="#cbawards" id="cbupdate" class="cbawardslnk">' . __('Posting Updates', 'cp_buddypress') . '</a> '; echo '<a href="#cbawards" id="cpreply" class="cbawardslnk">' . __('Replies', 'cp_buddypress') . '</a> '; echo '<a href="#cbawards" id="cpgtopic" class="cbawardslnk">' . __('Group Forum Topics', 'cp_buddypress') . '</a><br /><br />'; echo '<a href="#cbawards" id="cpgreply" class="cbawardslnk">' . __('Group Forum Replies', 'cp_buddypress') . '</a> '; echo '<a href="#cbawards" id="cpcomment" class="cbawardslnk">' . __('Comments', 'cp_buddypress') . '</a> ';
/** * CubePoints admin page: manage */ function cp_admin_manage() { ?> <div class="wrap"> <h2>CubePoints - <?php _e('Manage', 'cp'); ?> </h2> <?php _e('Manage the points of your users.', 'cp'); ?> <br /><br /> <div class="updated" id="cp_manage_updated" style="display: none;"></div> <?php global $wpdb; $results = $wpdb->get_results("SELECT * FROM `" . $wpdb->users . "` ORDER BY user_login ASC"); ?> <table id="cp_manage_table" class="widefat datatables"> <thead><tr><th scope="col" width="35"></th><th scope="col"><?php _e('User', 'cp'); ?> </th><th scope="col" width="120"><?php _e('Points', 'cp'); ?> </th><th scope="col" width="180"><?php _e('Update', 'cp'); ?> </th></tr></thead> <tfoot><tr><th scope="col"></th><th scope="col"><?php _e('User', 'cp'); ?> </th><th scope="col"><?php _e('Points', 'cp'); ?> </th><th scope="col"><?php _e('Update', 'cp'); ?> </th></tr></tfoot> <?php foreach ($results as $result) { $user = get_userdata($result->ID); $username = $user->user_login; $user_nicename = $user->display_name; $gravatar = get_avatar($result->ID, $size = '32'); ?> <tr> <td> <?php echo $gravatar; ?> </td> <td title="<?php echo $user_nicename; ?> "> <strong><?php echo $username; ?> </strong><br /><i><?php echo $user->user_email; ?> </i> </td> <td class="cp_manage_form_points"> <span id="cp_manage_form_points_<?php echo $result->ID; ?> "><?php cp_displayPoints($result->ID); ?> </span> </td> <td class="cp_manage_form_update"> <form method="post" name="cp_manage_form_<?php echo $result->ID; ?> " id="cp_manage_form_<?php echo $result->ID; ?> "> <input type="hidden" name="cp_manage_form_id" value="<?php echo $result->ID; ?> " /> <input type="text" name="cp_manage_form_points" value="<?php echo cp_getPoints($result->ID); ?> " /> <input type="submit" value="<?php _e('Update', 'cp'); ?> " /> <img src="<?php echo WP_PLUGIN_URL . '/' . str_replace(basename(__FILE__), "", plugin_basename(__FILE__)) . 'assets/load.gif'; ?> " style="display: none;" /> </form> </td> </tr> <?php } ?> </table> </div> <script type="text/javascript"> jQuery(document).ready(function() { jQuery(".cp_manage_form_update form").submit(function() { user_id = jQuery(this).children('input[name=cp_manage_form_id]').val(); points = jQuery(this).children('input[name=cp_manage_form_points]').val(); submit = jQuery(this).children('input[type=submit]'); loadImg = jQuery(this).children('img'); jQuery(".cp_manage_form_update form").children('input').attr('disabled', true); submit.hide(); loadImg.css('display', 'inline-block'); jQuery(this).children('input[name=cp_manage_form_points]').attr('readonly', true); jQuery('#cp_manage_form_points_'+user_id).hide(100); jQuery.post( '<?php echo bloginfo('url') . '/wp-admin/admin-ajax.php'; ?> ', { action: 'cp_manage_form_submit', user_id: user_id, points: points }, function(data,status){ if(status!='success'){ message = '<?php _e('Connection problem. Please check that you are connected to the internet.', 'cp'); ?> '; } else if(data.error!='ok') { message = data.error; } else { jQuery("#cp_manage_form_points_"+user_id).html(data.points_formatted); jQuery("#cp_manage_form_points_"+user_id).show(100); jQuery('#cp_manage_form_'+data.user_id).children('input[name=cp_manage_form_points]').val(data.points); jQuery('#cp_manage_form_'+data.user_id).children('input[name=cp_manage_form_points]').removeAttr('readonly'); message = '<?php _e("Points updated for", 'cp'); ?> ' + ' "' + data.username + '"'; } jQuery("#cp_manage_updated").html('<p><strong>'+message+'</strong></p>'); jQuery("#cp_manage_updated").show(100); loadImg.hide(); submit.show(); jQuery(".cp_manage_form_update form").children('input').removeAttr('disabled'); }, "json" ); return false; }); jQuery('#cp_manage_table').dataTable({ "bStateSave": true, "bSort": false, "aoColumns": [ { "bSearchable": false },{},{},{ "bSearchable": false } ] }); }); </script> <?php do_action('cp_admin_manage'); ?> <?php }
/** * cubepoints_bp_profile() * * Adds CubePoints to Profile Page * * @version 1.9.8.2 * @since 1.0 */ function cubepoints_bp_profile() { global $bp; if (function_exists('cp_displayPoints')) { ?> <span class="cubepoints_buddypress"><?php echo cp_displayPoints($bp->displayed_user->id); ?> </span> <?php } if (cp_module_activated('donate')) { if (is_user_logged_in()) { ?> <span class="cupepoints_buddypress_donate"><a href="#" title="<?php _e('Donate', 'cp_buddypress'); ?> " onclick="Javascript:cp_module_donate();" class="thickbox cp_donateLink"><?php _e('Donate Points', 'cp_buddypress'); ?> </a></span> <?php } } if (cp_module_activated('ranks')) { ?> <span class="cupepoints_buddypress_rank"><?php _e('Rank', 'cp_buddypress'); ?> - <?php echo cp_module_ranks_getRank($bp->displayed_user->id); ?> </span> <?php } }