public static function insertFirstLink(GWF_User $user, WC_Site $site, $onsitename, $onsitescore) { $table = self::table(__CLASS__); $siteid = $site->getVar('site_id'); if (false !== $table->getRow($onsitename, $siteid)) { return true; } $entry = new self(array('fili_onsitename' => $onsitename, 'fili_sid' => $siteid, 'fili_date' => GWF_Time::getDate(GWF_Date::LEN_DAY), 'fili_uid' => $user->getVar('user_id'), 'fili_username' => $user->getVar('user_name'), 'fili_sitename' => $site->getVar('site_name'), 'fili_percent' => $site->getPercent($onsitescore))); // echo GWF_HTML::message('DEBUG', 'Insert First Link...'); return $entry->insert(); }
public function getForm(WC_Site $site, $is_admin) { $data = array(); $data['site_name'] = array(GWF_Form::STRING, $site->getVar('site_name'), $this->module->lang('th_site_name')); if ($is_admin) { $data['site_classname'] = array(GWF_Form::STRING, $site->getVar('site_classname'), $this->module->lang('th_site_classname')); $data['site_basescore'] = array(GWF_Form::INT, $site->getVar('site_basescore'), $this->module->lang('th_site_basescore')); $data['site_usercount'] = array(GWF_Form::INT, $site->getVar('site_usercount'), $this->module->lang('th_site_usercount')); $data['site_challcount'] = array(GWF_Form::INT, $site->getVar('site_challcount'), $this->module->lang('th_site_challcount')); $data['site_powarg'] = array(GWF_Form::INT, $site->getVar('site_powarg'), $this->module->lang('th_site_powarg')); $data['site_spc'] = array(GWF_Form::INT, $site->getVar('site_spc'), $this->module->lang('th_site_spc')); $data['site_color'] = array(GWF_Form::STRING, $site->getVar('site_color'), $this->module->lang('th_site_color')); } $data['site_status'] = array(GWF_Form::SELECT, $this->getStatusSelect($site), $this->module->lang('th_site_status')); $data['no_urlencode'] = array(GWF_Form::CHECKBOX, $site->isOptionEnabled(WC_Site::NO_URLENCODE), $this->module->lang('th_no_urlencode')); $data['auto_update'] = array(GWF_Form::CHECKBOX, $site->hasAutoUpdate(), $this->module->lang('th_autoupdate')); $data['onsite_rank'] = array(GWF_Form::CHECKBOX, $site->hasOnSiteRank(), $this->module->lang('th_site_has_osr')); $data['default_hide'] = array(GWF_Form::CHECKBOX, $site->isDefaultHidden(), $this->module->lang('th_default_hide')); if ($is_admin) { $data['linear'] = array(GWF_Form::CHECKBOX, $site->isLinear(), $this->module->lang('th_linear')); } $data['div0'] = array(GWF_Form::DIVIDER); if ($is_admin) { $data['divi0'] = array(GWF_Form::HEADLINE, $this->module->lang('pi_site_tags', array($site->displayTags(true)))); $data['site_tags'] = array(GWF_Form::STRING, $site->getVar('site_tags'), $this->module->lang('th_site_tags')); } $data['site_country'] = array(GWF_Form::SELECT, GWF_CountrySelect::single('site_country', Common::getPostString('site_country', $site->getCountryID())), $this->module->lang('th_site_country2')); if ($is_admin) { $data['site_language'] = array(GWF_Form::SELECT, GWF_LangSelect::single(0, 'site_language', $site->getLangID()), $this->module->lang('th_site_language2')); } if ($is_admin) { $data['site_joindate'] = array(GWF_Form::STRING, $site->getVar('site_joindate'), $this->module->lang('th_site_joindate'), '', GWF_Date::LEN_SECOND); } $data['site_launchdate'] = array(GWF_Form::DATE, $site->getVar('site_launchdate'), $this->module->lang('th_site_launchdate'), '', GWF_Date::LEN_DAY); if ($is_admin) { $data['site_authkey'] = array(GWF_Form::STRING, $site->getVar('site_authkey'), $this->module->lang('th_site_authkey')); } $data['site_xauthkey'] = array(GWF_Form::STRING, $site->getVar('site_xauthkey'), $this->module->lang('th_site_xauthkey')); $data['site_irc'] = array(GWF_Form::STRING, $site->getVar('site_irc'), $this->module->lang('th_site_irc')); $data['div2'] = array(GWF_Form::DIVIDER); $data['div3'] = array(GWF_Form::HEADLINE, $this->module->lang('pi_site_urls')); $data['site_url'] = array(GWF_Form::STRING, $site->getVar('site_url'), $this->module->lang('th_site_url')); $data['site_url_mail'] = array(GWF_Form::STRING, $site->getVar('site_url_mail'), $this->module->lang('th_site_url_mail')); $data['site_url_score'] = array(GWF_Form::STRING, $site->getVar('site_url_score'), $this->module->lang('th_site_url_score')); $data['site_url_profile'] = array(GWF_Form::STRING, $site->getVar('site_url_profile'), $this->module->lang('th_site_url_profile')); $data['div4'] = array(GWF_Form::DIVIDER); $data['div5'] = array(GWF_Form::HEADLINE, $this->l('pi_warboxes')); $data['no_v1'] = array(GWF_Form::CHECKBOX, $site->isNoV1(), $this->l('th_no_v1'), $this->l('tt_no_v1')); // $data['warenbl'] = array(GWF_Form::CHECKBOX, $site->isWarBox(), $this->l('th_warbox')); // $data['warhost'] = array(GWF_Form::STRING, $site->getWarHost(), $this->l('th_warhost')); // $data['warport'] = array(GWF_Form::INT, $site->getWarPort(), $this->l('th_warport')); // $data['warscrd'] = array(GWF_Form::INT, $site->getWarReduceScore(), $this->l('th_war_score_reduce')); // $data['site_description'] = array(GWF_Form::MESSAGE, $site->getVar('site_description'), $this->module->lang('th_site_description')); $data['edit'] = array(GWF_Form::SUBMIT, $this->module->lang('btn_edit_site')); return new GWF_Form($this, $data); }
public static function insertEntry(GWF_User $user, WC_Site $site, $onsitescore, $comment) { $user = GWF_User::getByID($user->getID()); $max = $site->getOnsiteScore(); $perc = $max <= 0 ? 0 : round($onsitescore / $max * 10000); $entry = new self(array('userhist_uid' => $user->getVar('user_id'), 'userhist_date' => time(), 'userhist_sid' => $site->getVar('site_id'), 'userhist_percent' => $perc, 'userhist_onsitescore' => $onsitescore, 'userhist_rank' => WC_RegAt::calcRank($user), 'userhist_totalscore' => $user->getVar('user_level'), 'userhist_comment' => $comment)); if (WECHALL_DEBUG_SCORING) { echo WC_HTML::message('Inserting User History entry...'); } return $entry->insert(); }
private function templateHistory(WC_Site $site) { require_once GWF_CORE_PATH . 'module/WeChall/WC_HistoryUser2.php'; $table = GDO::table('WC_HistoryUser2'); $orderby = 'userhist_date ASC'; $siteid = $site->getVar('site_id'); $conditions = "userhist_sid={$siteid}"; $ipp = 50; $nItems = $table->countRows($conditions); $nPages = GWF_PageMenu::getPagecount($ipp, $nItems); $page = Common::clamp(Common::getGetInt('page', $nPages), 1, $nPages); $from = GWF_PageMenu::getFrom($page, $ipp); $rows = $table->select('*', $conditions, $orderby, array('userhist_uid', 'userhist_sid'), 50, $from); $href_pagemenu = GWF_WEB_ROOT . 'site/history/' . $site->urlencode2('site_name') . '/page/%PAGE%'; $tVars = array('pagemenu' => GWF_PageMenu::display($page, $nPages, $href_pagemenu), 'result' => $rows, 'site_quickjump' => $this->module->templateSiteQuickjumpHistory()); return $this->module->templatePHP('site_history.php', $tVars); }
private function templateDDOS(WC_Site $site) { // require_once GWF_CORE_PATH.'module/WeChall/WC_RegAt.php'; $siteid = $site->getVar('site_id'); $regat = GWF_TABLE_PREFIX . 'wc_regat'; $users = GWF_TABLE_PREFIX . 'user'; $query = "SELECT u.* FROM {$regat} JOIN {$users} u ON regat_uid=user_id WHERE regat_sid={$siteid}"; $db = gdo_db(); if (false === ($result = $db->queryRead($query))) { return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)); } $user = new GWF_User(); while (false !== ($row = $db->fetchAssoc($result))) { $user->setGDOData($row); $site->onUpdateUser($user, false); } $db->free($result); $site->recalcSite(); }
private function showSite(WC_Site $site) { # Sitename::Classname::Status:: # URL::ProfileURL:: # Usercount::Linkcount::Challcount:: # Basescore::Average::Score return sprintf('%s::%s::%s::%s::%s::%s::%s::%s::%s::%.02f%%::%s', $this->escapeCSV($site->getVar('site_name')), $this->escapeCSV($site->getVar('site_classname')), $site->getVar('site_status'), $this->escapeCSV($site->getVar('site_url')), $this->escapeCSV($site->getVar('site_url_profile')), $site->getVar('site_usercount'), $site->getVar('site_linkcount'), $site->getVar('site_challcount'), $site->getVar('site_basescore'), $site->getVar('site_avg') * 100, $site->getVar('site_score')) . PHP_EOL; }
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]; }
echo sprintf('<form method="post" action="%s">', $tVars['action']) . PHP_EOL; echo sprintf('<div>%s</div>', GWF_CSRF::hiddenForm('0')) . PHP_EOL; echo GWF_Table::start(); echo GWF_Table::displayHeaders1($headers, $tVars['sort_url']); $userid = GWF_Session::getUserID(); $txtshow = $tLang->lang('btn_show'); $txthide = $tLang->lang('btn_hide'); $txtscored = $tLang->lang('btn_scored'); $txtunscore = $tLang->lang('btn_unscored'); $site = new WC_Site(array()); $regat = new WC_RegAt(array()); foreach ($tVars['linked'] as $data) { $site instanceof WC_Site; $site->setVars($data); $regat->setVars($data); $siteid = $site->getVar('site_id'); // $regat = WC_RegAt::getRegatRow($userid, $siteid); $btn_update = sprintf('<input type="submit" name="update[%s]" value="%s" />', $siteid, $tLang->lang('btn_update')); echo GWF_Table::rowStart(); echo GWF_Table::column($site->displayStatus()); echo GWF_Table::column($site->displayIcon(1.0) . ' ' . $site->displayLink()); echo GWF_Table::column($regat->getVar('regat_challsolved'), 'gwf_num'); echo GWF_Table::column($site->getVar('site_challcount'), 'gwf_num'); echo GWF_Table::column($site->displayAutoUpdate()); echo GWF_Table::column($btn_update); echo GWF_Table::column($regat->getVar('regat_score'), 'gwf_num'); $perc = $regat->getPercent($site->getOnsiteScore()); $color = WC_HTML::getColorForPercent($perc); echo GWF_Table::column(sprintf('<span style="color: #%s">%.02f%%</span>', $color, $perc), 'gwf_num'); echo GWF_Table::column($regat->displayLastDate(), 'gwf_date'); echo GWF_Table::column($regat->displayOnsiteName());
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); }
/** * Recalculate all scores for one site. * @param WC_Site $site * @return boolean */ public static function calcSite(WC_Site $site) { $regats = self::table(__CLASS__); $siteid = $site->getVar('site_id'); $maxscore = $site->getVar('site_maxscore'); $sitescore = $site->getVar('site_score'); # Clamp to max // $regats->update("regat_onsitescore={$maxscore}", "regat_onsitescore>{$maxscore} and regat_sid={$siteid}"); if ($site->isLinear()) { if ($site->isNoV1()) { self::calcLinearSite($site); } if (false === $regats->update("regat_solved=regat_onsitescore/{$maxscore}, regat_score=regat_onsitescore", "regat_sid={$siteid}")) { return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)); } } elseif (defined('WECHALL_CAESUM_PATCH')) { # Ceasum Patch $challcount = $site->getVar('site_challcount'); $powarg = $site->getPowArg(); if (false === $regats->update("regat_solved=regat_onsitescore/{$maxscore}, regat_score=POW((regat_onsitescore/{$maxscore}),(1+({$powarg}/{$challcount})))*{$sitescore} ", "regat_sid={$siteid}")) { return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)); } } else { # Original Code if (false === $regats->update("regat_solved=regat_onsitescore/{$maxscore}, regat_score=(regat_onsitescore/{$maxscore})*(regat_onsitescore/{$maxscore})*{$sitescore} ", "regat_sid={$siteid}")) { return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)); } } return false; }
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 getRankedUsers(WC_Site $site, $from, $ipp) { $db = gdo_db(); $sid = $site->getVar('site_id'); $bits = $site->getTagBits(); $users = GWF_TABLE_PREFIX . 'user'; $regat = GWF_TABLE_PREFIX . 'wc_regat'; $query = "SELECT user_id, user_name, user_countryid, user_level, regat_solved, regat_onsiterank, regat_score " . "FROM {$regat} " . "JOIN {$users} ON user_id=regat_uid " . "WHERE regat_sid={$sid} AND regat_options&4=0 " . "ORDER BY regat_solved DESC, user_level DESC " . "LIMIT {$from}, {$ipp}"; if (false === ($result = $db->queryRead($query))) { return array(); } $back = array(); while (false !== ($row = $db->fetchAssoc($result))) { $back[] = $this->getUserStuff($row, $db, $bits); } $db->free($result); return $back; }