Ejemplo n.º 1
0
 public static function isValidCountry($cid, $allow_zero = false)
 {
     $min = $allow_zero === true ? -1 : 0;
     if ($min >= ($cid = (int) $cid)) {
         return false;
     }
     return $cid === 0 ? true : GWF_Country::getByID($cid) !== false;
 }
Ejemplo n.º 2
0
 private function showUser(GWF_User $user, $api_key)
 {
     if (false !== ($error = $this->module->isExcludedFromAPI($user, $api_key))) {
         return $error;
     }
     $private_mode = $this->module->isAPIKeyCorrect($user, $api_key);
     require_once GWF_CORE_PATH . 'module/WeChall/WC_RegAt.php';
     if (false === ($regats = WC_RegAt::getRegats($user->getID(), 'regat_solved ASC'))) {
         return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
     }
     require_once GWF_CORE_PATH . 'module/Forum/GWF_ForumOptions.php';
     if (false === ($fopts = GWF_ForumOptions::getUserOptions($user, false))) {
         return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
     }
     $unknown = GWF_HTML::lang('unknown');
     if ('0' === ($countryid = $user->getVar('user_countryid'))) {
         $country = false;
         $cname = $unknown;
         $crank = $unknown;
     } else {
         $country = GWF_Country::getByID($countryid);
         $cname = $country->displayName();
         $crank = WC_RegAt::calcExactCountryRank($user);
     }
     $back = '';
     $back .= 'Username:'******'user_name') . PHP_EOL;
     $back .= 'Country:' . $cname . PHP_EOL;
     $back .= 'Totalscore:' . $user->getVar('user_level') . PHP_EOL;
     $back .= 'GlobalRank:' . WC_RegAt::calcExactRank($user) . PHP_EOL;
     $back .= 'CountryRank:' . $crank . PHP_EOL;
     $back .= $this->contactData($user);
     $back .= 'ForumPosts:' . $fopts->getVar('fopt_posts') . PHP_EOL;
     $back .= 'ForumThanks:' . $fopts->getVar('fopt_thanks') . PHP_EOL;
     $back .= 'ForumVoteUp:' . $fopts->getVar('fopt_upvotes') . PHP_EOL;
     $back .= 'ForumVoteDown:' . $fopts->getVar('fopt_downvotes') . PHP_EOL;
     $back .= $this->regatData($user, $regats);
     if ($private_mode === true) {
         $back .= $this->privateData($user);
     }
     return $back;
 }
Ejemplo n.º 3
0
 private function templateSingle($cid, $user)
 {
     if (false === ($country = GWF_Country::getByID($cid))) {
         return GWF_HTML::err('ERR_UNKNOWN_COUNTRY');
     }
     require_once GWF_CORE_PATH . 'module/WeChall/WC_RegAt.php';
     $cid = $country->getID();
     $ipp = 50;
     $nItems = GDO::table('GWF_User')->countRows("user_countryid={$cid}");
     $nPages = GWF_PageMenu::getPagecount($ipp, $nItems);
     list($page, $hlrank) = $this->getSinglePageRank($cid, $ipp, $user);
     $page = Common::clamp($page, 1, $nPages);
     $rank = ($page - 1) * $ipp + 1;
     $from = GWF_PageMenu::getFrom($page, $ipp);
     $cname = $country->display('country_name');
     GWF_Website::setPageTitle($this->module->lang('pt_crank', array($cname, $page)));
     GWF_Website::setMetaTags($this->module->lang('mt_crank', array($cname, $cname)));
     GWF_Website::setMetaDescr($this->module->lang('md_crank', array($cname, $page)));
     $tVars = array('country' => $country, 'cid' => $cid, 'cname' => $cname, 'rank' => $rank, 'hl_rank' => $hlrank, 'page' => $page, 'page_menu' => GWF_PageMenu::display($page, $nPages, GWF_WEB_ROOT . 'country_ranking/for/' . $cid . '/' . $country->urlencodeSEO('country_name') . '/page-%PAGE%'), 'data' => $this->getDataForCountry($country, $ipp, $from));
     return $this->module->templatePHP('ranking_country.php', $tVars);
 }
Ejemplo n.º 4
0
 public function validate_countryid(Module_Register $module, $arg)
 {
     $countryid = (int) $arg;
     if ($countryid !== 0) {
         if (GWF_Country::getByID($countryid) === false) {
             return $this->module->lang('err_country');
         }
     }
     return false;
 }
Ejemplo n.º 5
0
 public function onEdit(WC_Site $site, $is_admin)
 {
     $form = $this->getForm($site, $is_admin);
     if (false !== ($errors = $form->validate($this->module))) {
         return $errors;
     }
     $basescore_changed = $language_changed = $status_changed = $spc_changed = $powarg_changed = false;
     if ($is_admin) {
         $basescore_changed = $form->getVar('site_basescore') != $site->getBasescore();
         $language_changed = $form->getVar('site_language') !== $site->getLangID();
         $status_changed = $form->getVar('site_status') !== $site->getStatus();
         $spc_changed = $form->getVar('site_spc') !== $site->getVar('site_spc');
         $powarg_changed = $form->getVar('site_powarg') !== $site->getVar('site_powarg');
         $site->saveVars(array('site_classname' => $form->getVar('site_classname'), 'site_basescore' => $form->getVar('site_basescore'), 'site_usercount' => $form->getVar('site_usercount'), 'site_challcount' => $form->getVar('site_challcount'), 'site_joindate' => $form->getVar('site_joindate'), 'site_authkey' => $form->getVar('site_authkey'), 'site_status' => $form->getVar('site_status'), 'site_language' => $form->getVar('site_language'), 'site_spc' => $form->getVar('site_spc'), 'site_powarg' => $form->getVar('site_powarg'), 'site_color' => $form->getVar('site_color')));
     }
     $site->saveVars(array('site_name' => $form->getVar('site_name'), 'site_country' => $form->getVar('site_country'), 'site_launchdate' => $form->getVar('site_launchdate'), 'site_xauthkey' => $form->getVar('site_xauthkey'), 'site_irc' => $form->getVar('site_irc'), 'site_url' => $form->getVar('site_url'), 'site_url_mail' => $form->getVar('site_url_mail'), 'site_url_score' => $form->getVar('site_url_score'), 'site_url_profile' => $form->getVar('site_url_profile')));
     $site->setVar('site_country', GWF_Country::getByID($form->getVar('site_country')));
     $site->setVar('site_language', GWF_Language::getByID($form->getVar('site_language')));
     # Update tags if Admin
     if ($is_admin) {
         $new_tags = $form->getVar('site_tags');
         if ($site->getTags() !== $new_tags) {
             echo GWF_HTML::message('WeChall', 'Fixing challenge site tags..');
             $site->saveVar('site_tags', str_replace(' ', '', $new_tags));
             require_once GWF_CORE_PATH . 'module/WeChall/WC_SiteCats.php';
             WC_SiteCats::fixCatBits();
         }
     }
     // 		$out = $this->onEditWarflag($site, isset($_POST['warenbl']));
     $old_linear = $site->isLinear();
     $site->saveOption(WC_Site::LINEAR, isset($_POST['linear']));
     $linear_changed = $old_linear !== $site->isLinear();
     $site->saveOption(WC_Site::NO_URLENCODE, isset($_POST['no_urlencode']));
     $site->saveOption(WC_Site::AUTO_UPDATE, isset($_POST['auto_update']));
     $site->saveOption(WC_Site::HIDE_BY_DEFAULT, isset($_POST['default_hide']));
     $site->saveOption(WC_Site::ONSITE_RANK, isset($_POST['onsite_rank']));
     $site->saveOption(WC_Site::NO_V1_SCRIPTS, isset($_POST['no_v1']));
     # Trigger warbox config parsing.
     // 		if ($site->isWarBox())
     // 		{
     // // 			$site->getWarIP();
     // 			Module_WeChall::instance()->flushWarboxConfig();
     // 		}
     # Recalculate in case of a change
     //		if ($site->isScored())
     //		{
     if ($basescore_changed || $language_changed || $status_changed || $powarg_changed || $spc_changed || $linear_changed) {
         $site->recalcSite();
         WC_RegAt::calcTotalscores();
     }
     //		}
     return $this->module->message('msg_site_edited', array($site->displayName()));
     #.$out;
 }
Ejemplo n.º 6
0
 public static function detectCountry()
 {
     return GWF_Country::getByID(self::detectCountryID());
 }
Ejemplo n.º 7
0
 public function displayCountry()
 {
     return GWF_HTML::display(GWF_Country::getByID($this->getVar('countryid')));
 }