function mycred_get_users_rank($user_id = NULL, $return = 'post_title', $logo_size = 'post-thumbnail', $attr = NULL, $type = 'mycred_default') { // User ID is required if ($user_id === NULL) { return __('mycred_get_users_rank() : Missing required user id', 'mycred'); } $end = ''; if ($type != 'mycred_default') { $end = $type; } // Get users rank $rank_id = mycred_get_user_meta($user_id, 'mycred_rank', $end, true); // If empty, get the users rank now and save it if ($rank_id == '') { $rank_id = mycred_find_users_rank($user_id, true, $type); } $reply = __('no rank', 'mycred'); // Have rank if ($rank_id != '' && $rank_id !== NULL) { // If we want to see the logo if ($return == 'logo') { $reply = mycred_get_rank_logo((int) $rank_id, $logo_size, $attr); } else { // Not using master template if (!mycred_override_settings()) { $rank = get_post((int) $rank_id); } else { $original_blog_id = get_current_blog_id(); switch_to_blog(1); $rank = get_post((int) $rank_id); switch_to_blog($original_blog_id); } // If the requested detail exists, return it if (isset($rank->{$return})) { $reply = $rank->{$return}; } } } return apply_filters('mycred_get_users_rank', $reply, $user_id, $return, $logo_size); }
/** * Widget Output */ function widget($args, $instance) { extract($args, EXTR_SKIP); // If we are logged in if (is_user_logged_in()) { // Current user id $user_id = get_current_user_id(); // Load myCRED Now if (!isset($instance['type']) || empty($instance['type'])) { $instance['type'] = 'mycred_default'; } $mycred = mycred($instance['type']); // If this is an excluded user we bail if ($mycred->exclude_user($user_id)) { return; } // Start echo $before_widget; // Title if (!empty($instance['title'])) { echo $before_title; echo $mycred->template_tags_general($instance['title']); echo $after_title; } // Balance $balance = $mycred->get_users_cred($user_id, $instance['type']); if (empty($balance)) { $balance = 0; } $layout = $mycred->template_tags_amount($instance['cred_format'], $balance); $layout = $mycred->template_tags_user($layout, false, wp_get_current_user()); // Include Ranking if ($instance['show_rank']) { if (function_exists('mycred_get_users_rank')) { $rank_name = mycred_get_users_rank($user_id); $ranking = str_replace('%rank%', $rank_name, $instance['rank_format']); $ranking = str_replace('%rank_logo%', mycred_get_rank_logo($rank_name), $ranking); $ranking = str_replace('%ranking%', '', $ranking); } else { $ranking = str_replace(array('%rank%', '%ranking%'), '', $instance['rank_format']); } $ranking = '<div class="myCRED-rank">' . $ranking . '</div>'; $layout .= $ranking; } echo '<div class="myCRED-balance">' . $layout . '</div>'; // If we want to include history if ($instance['show_history']) { echo '<div class="myCRED-widget-history">'; // Query Log $log = new myCRED_Query_Log(array('user_id' => $user_id, 'number' => $instance['number'], 'ctype' => $instance['type'])); // Have results if ($log->have_entries()) { // Title if (!empty($instance['history_title'])) { $history_title = $instance['history_title']; echo $before_title . $mycred->template_tags_general($history_title) . $after_title; } // Organized List echo '<ol class="myCRED-history">'; $alt = 0; $date_format = get_option('date_format'); foreach ($log->results as $entry) { // Row Layout $layout = $instance['history_format']; $layout = str_replace('%date%', '<span class="date">' . date_i18n($date_format, $entry->time) . '</span>', $layout); $layout = str_replace('%entry%', $mycred->parse_template_tags($entry->entry, $entry), $layout); $layout = $mycred->allowed_tags($layout); $layout = $mycred->template_tags_general($layout); $layout = $mycred->template_tags_amount($layout, $entry->creds); // Alternating rows $alt = $alt + 1; if ($alt % 2 == 0) { $class = 'row alternate'; } else { $class = 'row'; } // Output list item echo '<li class="' . $class . '">' . $layout . '</li>'; } echo '</ol>'; } $log->reset_query(); echo '</div>'; } // End echo $after_widget; } else { // If we want to show a message, then do so if ($instance['show_visitors']) { echo $before_widget; $mycred = mycred($instance['type']); // Title if (!empty($instance['title'])) { echo $before_title; echo $mycred->template_tags_general($instance['title']); echo $after_title; } $message = $instance['message']; $message = $mycred->template_tags_general($message); $message = $mycred->allowed_tags($message); echo '<div class="myCRED-my-balance-message"><p>' . nl2br($message) . '</p></div>'; echo $after_widget; } } }
/** * Adjust Rank Column Content * @since 1.1 * @version 1.1 */ public function adjust_column_content($column_name, $post_id) { $type = get_post_meta($post_id, 'ctype', true); if ($type == '') { $type = 'mycred_default'; } // Rank Logo (thumbnail) if ($column_name == 'mycred-rank-logo') { $logo = mycred_get_rank_logo($post_id, 'thumbnail'); if (empty($logo)) { echo __('No Logo Set', 'mycred'); } else { echo $logo; } } elseif ($column_name == 'mycred-rank-req') { $mycred = $this->core; if ($type != 'mycred_default') { $mycred = mycred($type); } $min = get_post_meta($post_id, 'mycred_rank_min', true); if (empty($min) && (int) $min !== 0) { $min = __('Any Value', 'mycred'); } $min = $mycred->template_tags_general(__('Minimum %plural%', 'mycred')) . ': ' . $min; $max = get_post_meta($post_id, 'mycred_rank_max', true); if (empty($max)) { $max = __('Any Value', 'mycred'); } $max = $mycred->template_tags_general(__('Maximum %plural%', 'mycred')) . ': ' . $max; echo $min . '<br />' . $max; } elseif ($column_name == 'mycred-rank-users') { echo mycred_count_users_with_rank($post_id); } // Rank Point Type if ($column_name == 'mycred-rank-type') { if (isset($this->point_types[$type])) { echo $this->point_types[$type]; } else { echo $this->core->plural(); } } }
function mycred_render_rank_list($atts, $content = NULL) { extract(shortcode_atts(array('order' => 'DESC', 'wrap' => 'div'), $atts)); if ($content === NULL || empty($content)) { $content = '<p>%rank% <span class="min">%min%</span> - <span class="max">%max%</span></p>'; } $mycred = mycred(); $output = ''; $all_ranks = mycred_get_ranks('publish', '-1', $order); if (!empty($all_ranks)) { $output .= '<' . $wrap . ' class="mycred-rank-list">'; $content = apply_filters('mycred_rank_list', $content, $atts, $mycred); foreach ($all_ranks as $rank_id => $rank) { $row = str_replace('%rank%', $rank->post_title, $content); $row = str_replace('%rank_logo%', mycred_get_rank_logo($rank_id), $row); $row = str_replace('%min%', get_post_meta($rank_id, 'mycred_rank_min', true), $row); $row = str_replace('%max%', get_post_meta($rank_id, 'mycred_rank_max', true), $row); $row = str_replace('%count%', count(mycred_get_users_of_rank($rank_id)), $row); $row = $mycred->template_tags_general($row); $output .= $row . "\n"; } $output .= '</' . $wrap . '>'; } return $output; }
/** * Adjust Rank Column Content * @since 1.1 * @version 1.0 */ public function adjust_column_content($column_name, $post_id) { // Rank Logo (thumbnail) if ($column_name == 'mycred-rank-logo') { $logo = mycred_get_rank_logo($post_id, 'thumbnail'); if (empty($logo)) { echo '<p>' . __('No Logo Set', 'mycred'); } else { echo '<p>' . $logo . '</p>'; } } elseif ($column_name == 'mycred-rank-req') { $mycred = mycred(); $min = get_post_meta($post_id, 'mycred_rank_min', true); if (empty($min) && (int) $min !== 0) { $min = __('Any Value', 'mycred'); } $min = $mycred->template_tags_general(__('Minimum %plural%', 'mycred')) . ': ' . $min; $max = get_post_meta($post_id, 'mycred_rank_max', true); if (empty($max)) { $max = __('Any Value', 'mycred'); } $max = $mycred->template_tags_general(__('Maximum %plural%', 'mycred')) . ': ' . $max; echo '<p>' . $min . '<br />' . $max . '</p>'; } elseif ($column_name == 'mycred-rank-users') { $users = count(mycred_get_users_of_rank($post_id)); echo '<p>' . $users . '</p>'; } }
/** * Show Balance in Header * @since 0.1 * @version 1.4.1 */ public function show_balance($dump = NULL, $context = 'header') { // Prep $output = ''; $user_id = bp_displayed_user_id(); // Check for exclusion if ($this->core->exclude_user($user_id)) { return; } // Check visibility settings if (!$this->buddypress['visibility']['balance'] && !bp_is_my_profile() && !mycred_is_admin()) { return; } // Parse template $template = $this->buddypress['balance_template']; if (function_exists('mycred_get_users_rank')) { $rank_name = mycred_get_users_rank($user_id); $template = str_replace('%rank%', $rank_name, $template); $template = str_replace('%rank_logo%', mycred_get_rank_logo($rank_name), $template); $template = str_replace('%ranking%', mycred_leaderboard_position($user_id), $template); } $template = str_replace(array('%ranking%', '%rank%'), mycred_leaderboard_position($user_id), $template); // Loop though all post types $mycred_types = mycred_get_types(); if (!empty($mycred_types)) { $_template = $template; foreach ($mycred_types as $type => $label) { $template = $_template; // Load myCRED with this points type $mycred = mycred($type); // Check if user is excluded from this type if ($mycred->exclude_user($user_id)) { continue; } // Get users balance $balance = $mycred->get_users_cred($user_id, $type); // Output $template = str_replace('%label%', $label, $template); $template = $mycred->template_tags_general($template); $output .= '<div class="mycred-balance mycred-' . $type . '">' . $template . ' ' . $mycred->format_creds($balance) . '</div>'; } } echo apply_filters('mycred_bp_profile_header', $output, $this->buddypress['balance_template'], $this); }