PHPFusion\Forums\ForumServer::show_forum_rank PHP Метод

show_forum_rank() публичный статический Метод

Get HTML source of forum rank images of a member
public static show_forum_rank ( integer $posts, integer $level, array $groups ) : string
$posts integer The number of posts of the member
$level integer The level of the member
$groups array The groups of the member
Результат string HTML source of forum rank images
    public static function show_forum_rank($posts, $level, $groups)
    {
        $forum_settings = self::get_forum_settings();
        $ranks = array();
        if (!$forum_settings['forum_ranks']) {
            return '';
        }
        $image = $forum_settings['forum_rank_style'] == 1;
        $forum_rank_cache = self::forum_rank_cache();
        $forum_rank_css_class = array('-101' => 'label-member', '-102' => 'label-mod', '-103' => 'label-super-admin');
        $forum_rank_icon_class = array('-101' => 'fa fa-legal fa-fw', '-102' => 'fa fa-legal fa-fw', '-103' => 'fa fa-legal fa-fw', '-104' => 'fa fa-legal fa-fw');
        // Moderator ranks
        if (!empty($forum_rank_cache['mod'])) {
            if ($level < USER_LEVEL_MEMBER) {
                foreach ($forum_rank_cache['mod'] as $rank) {
                    if (isset($rank['rank_apply']) && $level == $rank['rank_apply']) {
                        $ranks[] = $rank;
                        break;
                    }
                }
            }
        }
        // Special ranks
        if (!empty($forum_rank_cache['special'])) {
            if (!empty($groups)) {
                if (!is_array($groups)) {
                    $groups = explode(".", $groups);
                }
                foreach ($forum_rank_cache['special'] as $rank) {
                    if (!isset($rank['rank_apply'])) {
                        continue;
                    }
                    if (in_array($rank['rank_apply'], $groups)) {
                        $ranks[] = $rank;
                    }
                }
            }
        }
        // Post count ranks
        if (!empty($forum_rank_cache['post'])) {
            if (!$ranks) {
                foreach ($forum_rank_cache['post'] as $rank) {
                    if (!isset($rank['rank_apply'])) {
                        continue;
                    }
                    if ($posts >= $rank['rank_posts']) {
                        $ranks['post_rank'] = $rank;
                    }
                }
                if (!$ranks && isset($forum_rank_cache['post'][0])) {
                    $ranks['post_rank'] = $forum_rank_cache['post'][0];
                }
            }
        }
        // forum ranks must be the highest
        $res = '';
        foreach ($ranks as $rank) {
            if ($image) {
                if (isset($rank['rank_title']) && isset($rank['rank_image'])) {
                    $res .= $rank['rank_title'] . "<br />\n<img src='" . RANKS . $rank['rank_image'] . "' alt='' style='border:0' /><br />";
                }
            } else {
                if (isset($rank['rank_apply']) && isset($rank['rank_title'])) {
                    $res .= "<label class='forum label " . (isset($forum_rank_css_class[$rank['rank_apply']]) ? $forum_rank_css_class[$rank['rank_apply']] : "label-default") . " '><i class='" . (isset($forum_rank_icon_class[$rank['rank_apply']]) ? $forum_rank_icon_class[$rank['rank_apply']] : "fa fa-user fa-fw") . "'></i><div class='detail'>" . $rank['rank_title'] . "</div>\n</label>\n";
                }
            }
        }
        return $res;
    }

Usage Example

Пример #1
0
 /**
  * Ranks Listing
  * @return string
  */
 protected function displayRankList()
 {
     $rank_list_query = "\n        SELECT * FROM " . DB_FORUM_RANKS . "\n        " . (multilang_table("FR") ? "WHERE rank_language='" . LANGUAGE . "'" : "") . "\n        ORDER BY rank_type DESC, rank_apply DESC, rank_posts\n        ";
     $result = dbquery($rank_list_query);
     if (dbrows($result) > 0) {
         $html = "<table class='table table-responsive table-striped table-hover center m-t-20'>\n<thead>\n<tr>\n" . "<th class='col-xs-4'>" . self::$locale['430'] . "</th>\n" . "<th>" . self::$locale['431'] . "</th>\n" . "<th>" . self::$locale['432'] . "</th>\n" . "<th>" . self::$locale['438'] . "</th>\n" . "<th class='text-center'>" . self::$locale['434'] . "</th>\n" . "</tr>\n" . "</thead>\n<tbody>\n";
         $i = 0;
         while ($data = dbarray($result)) {
             $html .= "<tr>\n" . "<td '>" . $data['rank_title'] . "</td>\n" . "<td>" . ($data['rank_apply'] == 104 ? self::$locale['425'] : getgroupname($data['rank_apply'])) . "</td>\n" . "<td class='col-xs-2'>" . ForumServer::show_forum_rank($data['rank_posts'], $data['rank_apply'], $data['rank_apply']) . "</td>\n" . "<td>";
             if ($data['rank_type'] == 0) {
                 $html .= $data['rank_posts'];
             } elseif ($data['rank_type'] == 1) {
                 $html .= self::$locale['429b'];
             } else {
                 $html .= self::$locale['429a'];
             }
             $html .= "</td>\n<td width='1%' style='white-space:nowrap'>" . "<a href='" . clean_request("rank_id=" . $data['rank_id'] . "&section=fr&ref=rank_form", array("rank_id", "ref"), false) . "'>" . self::$locale['435'] . "</a> -\n" . "<a href='" . clean_request("delete=" . $data['rank_id'] . "&section=fr&ref=rank_form", array("rank_id", "ref"), false) . "'>" . self::$locale['436'] . "</a></td>\n</tr>\n";
             $i++;
         }
         $html .= "</tbody>\n</table>";
     } else {
         $html = "<div class='well text-center'>" . self::$locale['437'] . "</div>\n";
     }
     return $html;
 }