Example #1
0
function elapsedtime($seconds, $start = 0, $wantarray = false)
{
    // total 'leap seconds' in a single year. This is not truly static and
    // changes slightly every few years.
    static $oneyear = 31556925.9936;
    $years = $months = $weeks = $days = $hours = $minutes = 0;
    if ($start <= 0) {
        $years = floor($seconds / $oneyear);
        if ($years) {
            $seconds -= $oneyear * $years;
        }
    }
    if ($start <= 1) {
        $months = floor($seconds / ($oneyear / 12));
        if ($months) {
            $seconds -= $oneyear / 12 * $months;
        }
    }
    if ($start <= 2) {
        $weeks = floor($seconds / ($oneyear / 52));
        if ($weeks) {
            $seconds -= $oneyear / 52 * $weeks;
        }
    }
    if ($start <= 3) {
        $days = floor($seconds / ($oneyear / 365));
        if ($days) {
            $seconds -= $oneyear / 365 * $days;
        }
    }
    if ($start <= 4) {
        $hours = floor($seconds / 3600);
        if ($hours) {
            $seconds -= 3600 * $hours;
        }
    }
    if ($start <= 5) {
        $minutes = floor($seconds / 60);
        $seconds = $seconds % 60;
    }
    if ($wantarray) {
        return array($years, $months, $weeks, $days, $hours, $minutes, $seconds);
    } else {
        $str = elapsedtime_str(array($years, $months, $weeks, $days, $hours, $minutes, $seconds));
        return $str;
    }
}
Example #2
0
 function theme_setup(&$theme)
 {
     global $cms;
     $is_admin = $cms->user->is_admin();
     $theme->assign(array('use_roles' => $this->use_roles, 'show_ips' => $this->conf['theme']['permissions']['show_ips'] || $is_admin, 'show_worldids' => $this->conf['theme']['permissions']['show_worldids'] || $is_admin, 'show_login' => $this->conf['theme']['permissions']['show_login'] || $is_admin, 'show_register' => $this->conf['theme']['permissions']['show_register'] || $is_admin, 'show_version' => $this->conf['theme']['permissions']['show_version'] || $is_admin, 'show_admin' => $this->conf['theme']['permissions']['show_admin'], 'show_benchmark' => $this->conf['theme']['permissions']['show_benchmark'], 'show_plr_icons' => $this->conf['theme']['permissions']['show_plr_icons'], 'show_plr_flags' => $this->conf['theme']['permissions']['show_plr_flags'], 'show_clan_icons' => $this->conf['theme']['permissions']['show_clan_icons'], 'show_clan_flags' => $this->conf['theme']['permissions']['show_clan_flags'], 'loggedin' => $cms->input['loggedin'] and $cms->user->logged_in(), 'shades' => $cms->session->opt('shades'), 'worldid_noun' => $this->worldid_noun(), 'worldid_noun_plural' => $this->worldid_noun(true)));
     $theme->assign_by_ref('conf', $this->conf);
     // allow templates to access some PS methods
     $theme->register_object('ps', $this, array('version', 'worldid_noun'), false);
     $theme->load_styles();
     if ($cms->input['loggedin'] and $cms->user->logged_in()) {
         $theme->add_js('js/loggedin.js');
     }
     // setup the elapsedtime_str static vars once, so all other calls to
     // it will automatically use the translated strings.
     // we ignore the return value.
     elapsedtime_str(array(), 0, array($cms->trans(' years'), $cms->trans(' months'), $cms->trans(' weeks'), $cms->trans(' days'), $cms->trans(' hours'), $cms->trans(' minutes'), $cms->trans(' seconds')), array($cms->trans(' year'), $cms->trans(' month'), $cms->trans(' week'), $cms->trans(' day'), $cms->trans(' hour'), $cms->trans(' minute'), $cms->trans(' second')), ' ' . $cms->trans('and'));
     $this->ob_start();
 }
Example #3
0
 function get_game_list($args = array())
 {
     $args['sort'] = trim(strtolower($args['sort']));
     $args['order'] = trim(strtolower($args['order']));
     if (!in_array($args['sort'], array('start_time', 'start_time,end_time', 'server_name', 'gametype', 'modtype', 'map'))) {
         $args['sort'] = 'start_time,end_time';
     }
     if (!in_array($args['order'], array('asc', 'desc'))) {
         $args['order'] = 'desc';
     }
     if (!is_numeric($args['start']) || $args['start'] < 0) {
         $args['start'] = 0;
     }
     if (!is_numeric($args['limit']) || $args['limit'] < 0) {
         $args['limit'] = 100;
     }
     $args['filter'] = trim($args['filter']);
     $cmd = "SELECT g.*, " . "IF(end_time, end_time - start_time, " . "(SELECT MAX(event_time) FROM {$this->ps->t_live_events} e " . "WHERE e.game_id=g.game_id) - start_time" . ") total_time, " . "(SELECT COUNT(*) FROM {$this->ps->t_live_entities} " . "WHERE game_id=g.game_id) total_players " . "FROM {$this->ps->t_live_games} g ";
     if ($args['filter']) {
         $q = $this->ps->db->escape($args['filter']);
         $cmd .= "WHERE map LIKE '{$q}' OR server_name LIKE '{$q}'";
         unset($q);
     }
     $cmd .= $this->ps->getsortorder($args);
     $list = $this->ps->db->fetch_rows(1, $cmd);
     for ($i = 0, $j = count($list); $i < $j; $i++) {
         // calculate the elapsed time
         if (!is_null($list[$i]['total_time'])) {
             $elapsed = elapsedtime($list[$i]['total_time'], 0, true);
             $list[$i]['elapsed_time'] = elapsedtime_str($elapsed);
         }
         // get the map thumbnail url (or false if not found)
         $list[$i]['map_url'] = $this->ps->mapimg($list[$i]['map'], array('gametype' => $list[$i]['gametype'], 'modtype' => $list[$i]['modtype'], 'urlonly' => true, 'noimg' => false));
     }
     return $list;
 }