public function templateSiteDetail(WC_Site $site) { $this->module->includeVotes(); // $this->module->includeForums(); // GWF_Module::loadModuleDB('Forum', true, true); // GWF_ForumBoard::init(true, true); // GWF_Module::loadModuleDB('Votes', true); $time = $this->module->cfgLastPlayersTime(); $tVars = array('site' => $site, 'boxcount' => $site->getBoxCount(), 'descr' => WC_SiteDescr::getDescription($site->getID()), 'site_quickjump' => $this->module->templateSiteQuickjumpDetail(), 'latest_players_time' => GWF_Time::humanDuration($time), 'latest_players' => $this->getLatestPlayers($time, $site->getID()), 'jquery' => Common::getGet('ajax') !== false, 'can_vote' => $site->canVote(GWF_User::getStaticOrGuest())); $ajax = isset($_GET['ajax']) ? '_ajax' : ''; return $this->module->templatePHP('site_detail' . $ajax . '.php', $tVars); }
private function templateBoxes() { $this->module->includeClass('WC_Warbox'); $this->module->includeClass('WC_Warflag'); $this->module->includeClass('WC_SiteDescr'); $sid = $this->site->getID(); $_GET['sid'] = $sid; $_GET['bid'] = 0; $table = GDO::table('WC_Warbox'); $by = Common::getGetString('by'); $dir = Common::getGetString('dir'); $orderby = $table->getMultiOrderby($by, $dir); $tVars = array('site_quickjump' => $this->module->templateSiteQuickjump('boxdetails'), 'boxes' => WC_Warbox::getBoxes($this->site, $orderby), 'site' => $this->site, 'sort_url' => GWF_WEB_ROOT . 'index.php?mo=WeChall&me=WarboxesDetails&by=%BY%&dir=%DIR%&siteid=' . $sid); return $this->module->templatePHP('warboxes_details.php', $tVars); }
public function onAddSite() { $form = $this->getForm(); if (false !== ($error = $form->validate($this->module))) { return $error . $this->templateSiteAdd(); } $site = new WC_Site(array('site_status' => 'wanted', 'site_name' => $form->getVar('site_name'), 'site_classname' => $form->getVar('site_classname'), 'site_country' => 0, 'site_language' => 0, 'site_joindate' => GWF_Time::getDate(GWF_Date::LEN_SECOND), 'site_launchdate' => '', 'site_authkey' => GWF_Random::randomKey(32), 'site_xauthkey' => GWF_Random::randomKey(32), 'site_irc' => '', 'site_url' => '', 'site_url_mail' => '', 'site_url_score' => '', 'site_url_profile' => '', 'site_score' => 0, 'site_basescore' => 0, 'site_avg' => 0, 'site_vote_dif' => 0, 'site_vote_fun' => 0, 'site_challcount' => 0, 'site_usercount' => 0, 'site_visit_in' => 0, 'site_visit_out' => 0, 'site_options' => 0, 'site_boardid' => 0, 'site_threadid' => 0, 'site_tags' => '')); if (false === $site->insert()) { return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)); } Module_WeChall::includeVotes(); if (false === $site->onCreateVotes()) { return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)); } Module_WeChall::includeForums(); if (false === $site->onCreateBoard()) { return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)); } if (false === $site->onCreateThread($this->module)) { return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)); } require_once GWF_CORE_PATH . 'module/WeChall/WC_SiteDescr.php'; if (false === WC_SiteDescr::insertDescr($site->getID(), 1, 'Please edit me :)')) { return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)); } return $this->module->message('msg_site_added'); }
public function templateOutput($date, $amt) { $this->module->includeClass('WC_Warbox'); $this->module->includeClass('WC_Warflag'); $this->module->includeClass('WC_Warflags'); $table = GDO::table('WC_Warflags'); $joins = array('flag', 'solvers', 'flagsite', 'flagbox'); if (false === ($result = $table->selectAll('user_id, wf_id, wf_solved_at, wf_solved_at, wf_attempts, 0, 0, wf_attempts, user_name, wf_title, wf_solvers, IFNULL(wf_url, wb_weburl)', "wb_sid={$this->site->getID()} AND wf_solved_at>='{$date}'", 'wf_solved_at DESC', $joins, $amt, -1, GDO::ARRAY_N))) { return ''; } $back = ''; foreach ($result as $row) { $row = array_map(array(__CLASS__, 'escapeCSV'), $row); $back .= implode('::', $row) . PHP_EOL; } return $back; }
public static function getPlayercountForSite(WC_Site $site) { return self::table(__CLASS__)->selectVar('COUNT(DISTINCT(wf_uid))', "wb_sid={$site->getID()} AND wf_solved_at IS NOT NULL", '', array('flag', 'flagbox', 'flagsite')); }
public static function insertEntry(GWF_User $user, WC_Site $site, $type, $onsitescore_new = 0, $onsitescore_old = 0, $scoregain = 0, $onsiterank = 0) { $uid = $user->getID(); $user = GWF_User::getByID($uid); $max = $site->getOnsiteScore(); $perc_new = $max <= 0 ? 0 : round($onsitescore_new / $max * 10000); $perc_old = $max <= 0 ? 0 : round($onsitescore_old / $max * 10000); $perc_gain = $perc_new - $perc_old; $options = 0; $data = $user->getUserData(); if (isset($data['WC_NO_XSS'])) { $options |= self::NO_XSS; } $entry = new self(array('userhist_uid' => $uid, 'userhist_date' => time(), 'userhist_sid' => $site->getID(), 'userhist_percent' => $perc_new, 'userhist_onsitescore' => $onsitescore_new, 'userhist_rank' => WC_RegAt::calcExactRank($user), 'userhist_totalscore' => $user->getVar('user_level'), 'userhist_gain_perc' => $perc_gain, 'userhist_gain_score' => $scoregain, 'userhist_type' => $type, 'userhist_onsiterank' => $onsiterank, 'userhist_options' => $options)); if (WECHALL_DEBUG_SCORING) { echo WC_HTML::message('Inserting User History entry...'); } return $entry->insert(); }
private static function installSiteWeChall(Module_WeChall $module) { if (false !== ($site = WC_Site::getWeChall())) { return ''; } $options = WC_Site::AUTO_UPDATE; $site = new WC_Site(array('site_id' => 1, 'site_status' => WC_Site::UP, 'site_name' => 'WeChall', 'site_classname' => 'WC', 'site_logo_v' => 0, 'site_country' => 0, 'site_language' => GWF_Language::getEnglish()->getID(), 'site_joindate' => '20080218000000', 'site_launchdate' => '20080218', 'site_authkey' => 'iusdgsdgsiog3!s', 'site_xauthkey' => 'rw98t693g!9sg', 'site_irc' => 'irc://irc.idlemonkeys.net#wechall', 'site_url' => 'http://' . GWF_DOMAIN . GWF_WEB_ROOT, 'site_url_mail' => 'index.php?mo=WeChall&me=CrossSite&link=%USERNAME%&email=%EMAIL%&no_session=yes', 'site_url_score' => 'index.php?mo=WeChall&me=CrossSite&score=%USERNAME%&no_session=yes', 'site_url_profile' => 'profile/%USERNAME%', 'site_score' => 0, 'site_basescore' => 10000, 'site_avg' => 0.0, 'site_dif' => 3.0, 'site_fun' => 3.0, 'site_vote_dif' => 0, 'site_vote_fun' => 0, 'site_maxscore' => 0, 'site_challcount' => 0, 'site_usercount' => 0, 'site_linkcount' => 0, 'site_visit_in' => 0, 'site_visit_out' => 0, 'site_options' => $options, 'site_tags' => 'Exploit,Programming,Stegano,Crypto', 'site_boardid' => 0, 'site_threadid' => 0, 'site_tagbits' => 0, 'site_color' => '0000FF')); if (false === $site->onCreateSite($module, $back)) { return $back; } require_once GWF_CORE_PATH . 'module/WeChall/WC_SiteDescr.php'; if (false === WC_SiteDescr::insertDescr($site->getID(), 1, 'Please edit me :)')) { return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)); } return ''; }
public static function getTotalscoreForSite(WC_Site $site) { return self::table(__CLASS__)->selectVar('SUM(wf_score)', "wb_sid={$site->getID()}", '', array('warbox', 'site')); }
private function getColorAndStyle(WC_Site $site) { static $inc = 0; static $used = array(); $siteid = $site->getID(); if (isset($used[$siteid])) { return $used[$siteid]; } $nColors = count(self::$COLORS); $style = intval($inc / $nColors); $style = self::$STYLES[$style]; $color = $site->getVar('site_color'); if ($color === NULL) { $color = self::$COLORS[$inc % $nColors]; } $inc++; $used[$siteid] = array('#' . $color, $style); return $used[$siteid]; }
public static function getBoxCount(WC_Site $site) { return self::table(__CLASS__)->selectVar('COUNT(*)', "wb_sid={$site->getID()}"); }
private function graphB(WC_Site $site, $field) { $graphtitle = $this->module->lang('gt_site_' . $field, array($site->getVar('site_name'))); $siteid = $site->getID(); $history = GDO::table('WC_HistorySite'); if (false === ($result = $history->select("sitehist_date, {$field}", 'sitehist_sid=' . $siteid, 'sitehist_date ASC'))) { return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)); } // $db = gdo_db(); // $table = $history->getTableName(); // if (false === ($result = $db->query("SELECT sitehist_date, $field FROM $table WHERE sitehist_sid=$siteid ORDER BY sitehist_date ASC"))) { // return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)); // } //load in the data $xdataarray = array(); $ydataarray = array(); $highestvalue = 0; // while (false !== ($row = $db->fetchRow($result))) while (false !== ($row = $history->fetch($result, GDO::ARRAY_N))) { $value = (int) $row[1]; $xdataarray[] = $row[0]; $ydataarray[] = $value; if ($value > $highestvalue) { $highestvalue = $value; } } $history->free($result); // add current value $xdataarray[] = time(); $ydataarray[] = $value = $site->getVar(str_replace('hist_', '_', $field)); if ($value > $highestvalue) { $highestvalue = $value; } // var_dump($xdataarray); // var_dump($ydataarray); // var_dump($xticks); if ($highestvalue === 0) { $graph = new Graph($this->module->cfgGraphWidth(), $this->module->cfgGraphHeight()); $graph->SetScale('intlin', 1, 2, 1, 2); $caption = new Text($this->module->lang('err_graph_empty'), 0.1, 0.8); // $caption->SetFont(FS_BOLD); $graph->AddText($caption); $graph->stroke(); die(0); } # $dateformat = GWF_HTML::lang('df_8'); // $dateformat = "d.M.y-H:i"; $dateformat = "M.y"; $datemargin = strlen(date($dateformat)) * 11; //define the graph $graph = new Graph($this->module->cfgGraphWidth(), $this->module->cfgGraphHeight()); $graph->SetScale('datlin', 0, 1.05 * $highestvalue); $graph->title->Set($graphtitle); // $graph->title->SetFont(FF_ARIAL, FS_NORMAL, 12); $graph->SetColor(array(238, 238, 238)); $graph->SetMarginColor(array(208, 211, 237)); $graph->SetShadow(); $graph->xaxis->SetLabelAngle(90); // $graph->xaxis->SetTickPositions($xticks, NULL, $xdataarray); $graph->xaxis->scale->SetDateFormat($dateformat); $graph->img->SetMargin(50, 40, 40, $datemargin); $lineplot = new LinePlot($ydataarray, $xdataarray); $lineplot->SetColor("blue"); $lineplot->SetWeight(2); $graph->Add($lineplot); // $graph->img->SetAntiAliasing(); // Display the graph GWF_HTTP::noCache(); $graph->Stroke(); die(0); }
/** * Repair the site-tag-bits for all regat rows. * @param WC_Site $site * @param unknown_type $bits * @return unknown_type */ public static function fixTagBits(WC_Site $site, $bits) { $bits = (int) $bits; $siteid = $site->getID(); return self::table(__CLASS__)->update("regat_tagbits={$bits}", "regat_sid={$siteid}"); }
public function onLinkSiteAfterMail(WC_Site $site, GWF_User $user, $onsitename) { if (WC_Freeze::isUserFrozenOnSite($user->getID(), $site->getID())) { return $this->module->error('err_site_ban', array($site->displayName())); } if ($site->isUserLinked($user)) { return $this->module->error('err_already_linked', array($site->displayName())); } $siteid = $site->getVar('site_id'); $userid = $user->getVar('user_id'); if (false !== WC_RegAt::getUserByOnsiteName($onsitename, $siteid)) { return $this->module->error('err_already_linked2', array(GWF_HTML::display($onsitename), $site->displayName())); } $options = 0; $options |= $site->isDefaultHidden() ? WC_RegAt::HIDE_SITENAME : 0; $regat = new WC_RegAt(array('regat_uid' => $userid, 'regat_sid' => $siteid, 'regat_onsitename' => $onsitename, 'regat_onsitescore' => 0, 'regat_challcount' => $site->getVar('site_challcount'), 'regat_options' => $options, 'regat_langid' => $site->getLangID(), 'regat_tagbits' => $site->getTagBits(), 'regat_linkdate' => GWF_Time::getDate(GWF_Date::LEN_DAY))); if (false === $regat->insert()) { return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)); } if (false === $site->increase('site_linkcount', 1)) { return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)); } $error = $site->onUpdateUser($user, true, true); if (false === ($regat2 = WC_RegAt::getRegatRow($userid, $siteid))) { return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)); } require_once GWF_CORE_PATH . 'module/WeChall/WC_FirstLink.php'; if (false === WC_FirstLink::insertFirstLink($user, $site, $onsitename, $regat2->getOnsiteScore())) { return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)); } return $error->display($this->module->lang('btn_linked_sites')) . $this->module->message('msg_site_linked', array($site->displayName())); }
private function templateEdit(WC_Warbox $box) { $form = $this->formEdit($box); $tVars = array('href_site' => $this->module->getMethodURL('SiteEdit', '&siteid=' . $this->site->getID()), 'href_descr' => $this->module->getMethodURL('SiteEdit', '&siteid=' . $this->site->getID()), 'href_boxes' => $this->module->getMethodURL('Warboxes', '&siteid=' . $this->site->getID()), 'form' => $form->templateY($this->l('ft_edit_warbox'))); return $this->module->templatePHP('site_add_warbox.php', $tVars); }