Esempio n. 1
0
 function mycred_render_shortcode_total_points($atts)
 {
     extract(shortcode_atts(array('type' => 'mycred_default', 'ref' => '', 'ref_id' => '', 'user_id' => 'current', 'formatted' => 1), $atts));
     if (!mycred_point_type_exists($type)) {
         $type = 'mycred_default';
     }
     if ($user_id == 'current') {
         if (!is_user_logged_in()) {
             return;
         }
         $user_id = get_current_user_id();
     }
     $mycred = mycred($type);
     global $wpdb;
     // Simple
     if ($ref == '' && $ref_id == '' && $user_id == '') {
         // Add up all balances
         $total = $wpdb->get_var($wpdb->prepare("SELECT SUM( meta_value ) FROM {$wpdb->usermeta} WHERE meta_key = %s", mycred_get_meta_key($type)));
     } else {
         $wheres = array();
         $wheres[] = $wpdb->prepare("ctype = %s", mycred_get_meta_key($type));
         $ref = sanitize_key($ref);
         if (strlen($ref) > 0) {
             // Either we have just one reference
             $multiple = explode(',', $ref);
             if (count($multiple) == 1) {
                 $wheres[] = $wpdb->prepare("ref = %s", $ref);
             } else {
                 $_clean = array();
                 foreach ($multiple as $ref) {
                     $ref = sanitize_key($ref);
                     if (strlen($ref) > 0) {
                         $_clean[] = $ref;
                     }
                 }
                 if (!empty($_clean)) {
                     $wheres[] = "ref IN ( '" . implode("', '", $_clean) . "' )";
                 }
             }
         }
         $ref_id = absint($ref_id);
         if ($ref_id > 0) {
             $wheres[] = $wpdb->prepare("ref_id = %d", $ref_id);
         }
         $user_id = absint($user_id);
         if ($user_id > 0) {
             $wheres[] = $wpdb->prepare("user_id = %d", $user_id);
         }
         $wheres = implode(" AND ", $wheres);
         $total = $wpdb->get_var("SELECT SUM( creds ) FROM {$mycred->log_table} WHERE {$wheres};");
     }
     if ($total === NULL) {
         $total = 0;
     }
     if ($formatted == 1) {
         return $mycred->format_creds($total);
     }
     return $total;
 }
Esempio n. 2
0
 /**
  * Get User ID from Ref ID
  * @since 1.4
  * @version 1.0.1
  */
 public function get_user_id_from_ref_id($string = '')
 {
     global $wpdb;
     $user_id = NULL;
     switch ($this->prefs['setup']['links']) {
         case 'username':
             $ref_id = trim(urldecode($string));
             $user_id = $wpdb->get_var($wpdb->prepare("\n\t\t\t\t\t\tSELECT ID \n\t\t\t\t\t\tFROM {$wpdb->users} \n\t\t\t\t\t\tWHERE user_login = %s;", $ref_id));
             break;
         case 'numeric':
             $referral_id_key = mycred_get_meta_key('mycred_affiliate_link');
             $ref_id = absint($string);
             $user_id = $wpdb->get_var($wpdb->prepare("\n\t\t\t\t\t\tSELECT user_id \n\t\t\t\t\t\tFROM {$wpdb->usermeta} \n\t\t\t\t\t\tWHERE meta_key = %s \n\t\t\t\t\t\t\tAND meta_value = %d;", $referral_id_key, $ref_id));
             break;
     }
     return apply_filters('mycred_affiliate_get_user_id', $user_id, $string, $this);
 }
Esempio n. 3
0
 function mycred_query_users_total($user_id, $type = 'mycred_default')
 {
     global $wpdb;
     $mycred = mycred($type);
     $total = $wpdb->get_var($wpdb->prepare("\n\t\t\tSELECT SUM( creds ) \n\t\t\tFROM {$mycred->log_table} \n\t\t\tWHERE user_id = %d\n\t\t\t\tAND ( ( creds > 0 ) OR ( creds < 0 AND ref = 'manual' ) )\n\t\t\t\tAND ctype = %s;", $user_id, mycred_get_meta_key($type)));
     if ($total === NULL) {
         $total = $wpdb->get_var($wpdb->prepare("\n\t\t\t\tSELECT meta_value \n\t\t\t\tFROM {$wpdb->usermeta} \n\t\t\t\tWHERE user_id = %d \n\t\t\t\t\tAND meta_key = %s;", $user_id, mycred_get_meta_key($type)));
         if ($total === NULL) {
             $total = 0;
         }
     }
     return apply_filters('mycred_query_users_total', $total, $user_id, $type, $mycred);
 }