Beispiel #1
0
    public static function format_data($data, $type = "bb", $args = null)
    {
        global $_base;
        switch ($type) {
            case "bb":
            case "signature":
                // bb kode
                return game::bb_to_html($data);
                // bb-kode eller egendefinert tekst hvis bb-kode er tom
            // bb-kode eller egendefinert tekst hvis bb-kode er tom
            case "bb-opt":
                $bb = trim(game::bb_to_html($data));
                if ($bb == "") {
                    return $args;
                }
                return $bb;
            case "music_pre":
                return preg_replace('~\\[music\\](https?://.+?)\\[/music\\]~ieu', 'game::music_add(\'$1\')', $data);
            case "music_post":
                return game::music_replace($data);
            case "profile":
                $data = game::format_data($data, "music_pre");
                // sett opp ranken
                $rank = game::rank_info($args->data['up_points'], $args->data['upr_rank_pos'], $args->data['up_access_level']);
                // diverse bb koder
                $data = str_replace(array("[counter]", "[visits]", "[visitor]", "[rank]", "[bank]", "[cash]", "[money]", "[renter]", "[pm_ulest]", "[pengerank]"), array('<img src="&rpath;/counter?count=' . $args->data['up_profile_hits'] . '" alt="Antall visninger: ' . $args->data['up_profile_hits'] . '" />', $args->data['up_profile_hits'], game::profile_link(), $rank['orig'] ? $rank['orig'] : $rank['name'], game::format_cash($args->data['up_bank']), game::format_cash($args->data['up_cash']), game::format_cash($args->data['up_cash'] + $args->data['up_bank']), game::format_cash($args->data['up_interest_last']), game::format_number($args->user->data['u_inbox_new']), game::cash_name($args->data['up_cash'] + $args->data['up_bank'])), game::bb_to_html($data));
                // rankbar
                $type = false;
                $match_rank = preg_match("~\\[rank_(neste_tid|neste_dato|tid|dato)\\]~iu", $data);
                if (preg_match("~\\[rankbar( type=(1|2))?\\]~iu", $data, $type) || $match_rank) {
                    // høyeste rank?
                    if ($rank['need_points'] == 0) {
                        global $_game;
                        $prosent = $args->data['up_points'] / game::$ranks['items_number'][count(game::$ranks['items_number'])]['points'] * 100;
                        $rankbar_total = '
<div class="progressbar">
	<div class="progress"><p>' . game::format_num($prosent, 3) . ' %</p></div>
</div>';
                        $rankbar_total2 = '
<div class="progressbar" style="margin-top: 1em">
	<div class="progress"><p>' . game::format_num($prosent, 3) . ' %</p></div>
</div>';
                        $data = str_replace(array("[rankbar]", "[rankbar type=1]", "[rankbar type=2]", "[rank_tid]", "[rank_dato]", "[rank_neste_tid]", "[rank_neste_dato]"), array($rankbar_total . $rankbar_total2, $rankbar_total, $rankbar_total, "Oppnådd", "Oppnådd", "Oppnådd", "Oppnådd"), $data);
                    } else {
                        // i forhold til den høyeste ranken
                        global $_game;
                        // antall poeng for den høyeste ranken
                        $points_max = game::$ranks['items'];
                        end($points_max);
                        $points_max = current($points_max);
                        $points_max = $points_max['points'];
                        // hvor langt ifra er vi?
                        $percent_total = round($args->data['up_points'] / $points_max, 2) * 100;
                        #if ($percent_total > 100) $percent_total = 100;
                        if ($percent_total == 0) {
                            $percent_total = 0.01;
                        }
                        $rankbar_total = '
<div class="progressbar">
	<div class="progress" style="width: ' . floor($percent_total) . '%"><p>' . game::format_num($percent_total, 2) . ' % i forhold til høyeste rank.</p></div>
</div>';
                        // i forhold til neste rank
                        $points_rank = $args->data['up_points'] - $rank['points'];
                        $percent = round($points_rank / $rank['need_points'] * 100, 2);
                        #if ($percent  )
                        $rankbar_next = '
<div class="progressbar">
	<div class="progress" style="width: ' . floor($percent) . '%"><p>' . game::format_num($percent, 2) . ' % i forhold til neste rank</p></div>
</div>';
                        $rankbar_next2 = '
<div class="progressbar" style="margin-top: 1em">
	<div class="progress" style="width: ' . floor($percent) . '%"><p>' . game::format_num($percent, 2) . ' % i forhold til neste rank</p></div>
</div>';
                        // fiks bb kodene
                        $data = str_replace(array("[rankbar]", "[rankbar type=1]", "[rankbar type=2]"), array($rankbar_total . $rankbar_next2, $rankbar_total, $rankbar_next), $data);
                        // beregn antatt tid det tar å nå høyeste rank
                        if ($match_rank) {
                            // hent ut aktiviteten de siste X dagene
                            $expire = ess::$b->date->get();
                            $expire->modify("-21 days");
                            $expire = max($args->data['up_created_time'], $expire->format("U"));
                            // maks tid: siste 21 dager eller siden reg (om registrert innen 30 dager)
                            $result = \Kofradia\DB::get()->query("SELECT SUM(uhi_points) FROM users_hits WHERE uhi_up_id = {$args->id} AND uhi_secs_hour >= {$expire}");
                            $points = (int) $result->fetchColumn(0);
                            if ($points == 0) {
                                $data = str_replace(array("[rank_tid]", "[rank_dato]", "[rank_neste_tid]", "[rank_neste_dato]"), array("ukjent", "ukjent", "ukjent", "ukjent"), $data);
                            } else {
                                // antall sekunder poengene skal fordeles på
                                $time_elapsed = time() - $expire;
                                // beregn til neste rank og erstatt BB-kode
                                $need = $rank['points'] + $rank['need_points'] - $args->data['up_points'];
                                $time_left = $need / $points * $time_elapsed;
                                if ($time_left > 63072000) {
                                    $text_left = "over 2 år";
                                    $text_date = "om over 2 år";
                                } else {
                                    $text_left = game::timespan($time_left);
                                    $text_date = ess::$b->date->get($time_left + time())->format(date::FORMAT_NOTIME);
                                }
                                $data = str_replace(array("[rank_neste_tid]", "[rank_neste_dato]"), array($text_left, $text_date), $data);
                                // beregn til øverste rank og erstatt BB-kode
                                $need = $points_max - $args->data['up_points'];
                                $time_left = $need / $points * $time_elapsed;
                                if ($time_left > 63072000) {
                                    $text_left = "over 2 år";
                                    $text_date = "om over 2 år";
                                } else {
                                    $text_left = game::timespan($time_left);
                                    $text_date = ess::$b->date->get($time_left + time())->format(date::FORMAT_NOTIME);
                                }
                                $data = str_replace(array("[rank_tid]", "[rank_dato]"), array($text_left, $text_date), $data);
                            }
                        }
                    }
                }
                // kontaktliste?
                if (mb_strpos($data, "[kontakter]") !== false) {
                    // hent kontaktliste
                    $result = \Kofradia\DB::get()->query("SELECT uc_contact_up_id, up_name, up_access_level, up_last_online FROM users_contacts LEFT JOIN users_players ON uc_contact_up_id = up_id WHERE uc_u_id = {$args->data['up_u_id']} AND uc_type = 1 ORDER BY up_name");
                    $html = '
<table class="table l tablem">
	<thead>
		<tr>
			<th>Spiller</th>
			<th>Sist pålogget</th>
		</tr>
	</thead>
	<tbody>';
                    while ($row = $result->fetch()) {
                        $html .= '
		<tr>
			<td>' . game::profile_link($row['uc_contact_up_id'], $row['up_name'], $row['up_access_level']) . '</td>
			<td class="r">' . game::timespan($row['up_last_online'], game::TIME_ABS) . '</td>
		</tr>';
                    }
                    $html .= '
	</tbody>
</table>';
                    // sett inn som bb kode
                    $data = str_replace("[kontakter]", $html, $data);
                }
                // blokkeringliste?
                if (mb_strpos($data, "[blokkert]") !== false) {
                    // hent blokkeringliste
                    $result = \Kofradia\DB::get()->query("SELECT uc_contact_up_id, up_name, up_access_level, up_last_online FROM users_contacts LEFT JOIN users_players ON uc_contact_up_id = up_id WHERE uc_u_id = {$args->data['up_u_id']} AND uc_type = 2 ORDER BY up_name");
                    $html = '
<table class="table l tablem">
	<thead>
		<tr>
			<th>Spiller</th>
			<th>Sist pålogget</th>
		</tr>
	</thead>
	<tbody>';
                    while ($row = $result->fetch()) {
                        $html .= '
		<tr>
			<td>' . game::profile_link($row['uc_contact_up_id'], $row['up_name'], $row['up_access_level']) . '</td>
			<td class="r">' . game::timespan($row['up_last_online'], game::TIME_ABS) . '</td>
		</tr>';
                    }
                    $html .= '
	</thead>
</table>';
                    // sett inn som bb kode
                    $data = str_replace("[blokkert]", $html, $data);
                }
                return game::format_data($data, "music_post");
            default:
                // ukjent!
                throw new HSException("Ukjent type ({$type})");
        }
        return false;
    }