Ejemplo n.º 1
0
 public static function fixCatBits()
 {
     self::table(__CLASS__)->truncate();
     require_once 'WC_RegAt.php';
     $sites = WC_Site::getSites();
     $tag_c = array();
     foreach ($sites as $site) {
         $site instanceof WC_Site;
         $tags = $site->getTagArray();
         $curr = array();
         foreach ($tags as $tag) {
             $tag = trim($tag);
             if ($tag === '') {
                 continue;
             }
             $curr[] = $tag;
             if (!isset($tag_c[$tag])) {
                 $tag_c[$tag] = 1;
             } else {
                 $tag_c[$tag]++;
             }
             self::addToCat($site->getID(), $tag);
         }
         $site->saveVars(array('site_tagbits' => self::calcTagBits($tags, $tag_c), 'site_tags' => implode(',', $curr)));
         WC_RegAt::fixTagBits($site, $site->getTagBits());
     }
     self::adjustBits($tag_c);
 }
Ejemplo n.º 2
0
 public function getPageForSession($ipp, $user)
 {
     if ($user === false || $user->isWebspider() || $user->isOptionEnabled(0x10000000)) {
         return array(1, 1);
     }
     $rank = WC_RegAt::calcExactRank($user);
     $page = GWF_PageMenu::getPageForPos($rank, $ipp);
     return array($page, WC_RegAt::calcRank($user));
 }
Ejemplo n.º 3
0
 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();
 }
Ejemplo n.º 4
0
 private function outputScore($username)
 {
     if (false === ($user = GWF_User::getByName($username))) {
         die('Unknown User');
     }
     if (false === ($site = WC_Site::getWeChall())) {
         die('Unknown Site');
     }
     require_once GWF_CORE_PATH . 'module/WeChall/WC_RegAt.php';
     require_once GWF_CORE_PATH . 'module/WeChall/WC_ChallSolved.php';
     $score = WC_Challenge::getScoreForUser($user);
     $maxscore = WC_Challenge::getMaxScore();
     $challs_solved = WC_ChallSolved::getChallsSolvedForUser($user);
     $challcount = WC_Challenge::getChallCount();
     $usercount = GDO::table('GWF_User')->countRows();
     $rank = WC_RegAt::calcExactRank($user);
     die(sprintf('%d:%s:%s:%s:%s:%s', $rank, $score, $maxscore, $challs_solved, $challcount, $usercount));
 }
Ejemplo n.º 5
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.º 6
0
 public function execute()
 {
     $syntax = 'syntax: ' . Common::getAbsoluteURL('remoteupdate.php') . '?sitename=FOO&username=BAR';
     $server = htmlspecialchars($_SERVER['SERVER_NAME'], ENT_QUOTES);
     $unknownsite = 'Join us: ' . Common::getAbsoluteURL('join_us');
     # "Join us: http://$server/join.php";
     $unknownuser = '******' . Common::getAbsoluteURL('register') . ' for global ranking. Please note that the username is case sensitive for remoteupdates.';
     // flag for images. 0=normal text, 1=default image, we can assign different image styles to higher numbers
     $img = (int) Common::getGet('img', 0);
     if ($img === 1) {
         header("Content-Type: image/png");
     }
     if (false === ($sitename = Common::getRequest('sitename'))) {
         $this->outDie($syntax);
     }
     if (false === ($onsitename = Common::getRequest('username'))) {
         $this->outDie($syntax);
     }
     if ($sitename === 'FOO' && $onsitename === 'BAR') {
         $this->outDie('Doh! Not literally!');
     }
     if (false === ($site = WC_Site::getByName($sitename)) && false === ($site = WC_Site::getByClassName($sitename))) {
         $this->outExit($unknownsite);
     }
     $this->module->includeClass('WC_RegAt');
     if (false === ($user = WC_RegAt::getUserByOnsiteName($onsitename, $site->getID()))) {
         $this->outExit($unknownuser);
     }
     # Update him
     $result = $site->onUpdateUser($user);
     $site->saveOption(WC_Site::AUTO_UPDATE, true);
     # Output result
     switch ($img) {
         case 0:
             $this->outResult($result);
             break;
         case 1:
             $this->imgDisplayText($result->getMessage());
             break;
     }
 }
Ejemplo n.º 7
0
 public function hookDeleteUser(GWF_User $user, array $args)
 {
     # TODO: delete a lot of stuff.
     # Let's start with unlinking all sites.
     $this->includeClass('WC_RegAt');
     $userid = $user->getID();
     if (false === WC_RegAt::unlinkAll($userid)) {
         return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
     }
     return true;
 }
Ejemplo n.º 8
0
if (count($boxes) > 0) {
    echo WC_HTML::button('btn_warboxes', $site->hrefWarboxes());
}
echo WC_HTML::button('btn_ranking', $site->hrefRanking(true));
echo WC_HTML::button('btn_site_history', $site->hrefHistory());
echo '</div></div>' . PHP_EOL;
?>

<?php 
if (false === ($user = GWF_User::getByName(Common::getGet('username', '')))) {
}
if ($user !== false) {
    $userid = $user->getID();
    if (false !== ($regat = WC_RegAt::getRegatRow($userid, $siteid))) {
        $max = $site->getOnsiteScore();
        echo GWF_Box::box($tLang->lang('site_detail_uinfo', array($user->displayUsername(), $regat->getOnsiteScore(), $max, $site->displayName(), round($regat->getPercent($max), 2), WC_RegAt::calcExactSiteRank($user, $siteid), $site->calcScore($regat))));
    }
}
?>

<div class="ib"><?php 
echo GWF_Box::box(GWF_Message::display($tVars['descr']));
?>
</div>

<table>
	<thead>
		<tr>
			<th colspan="2" id="wc_site_detail_head"><?php 
echo $site->displayLogo(32, $tLang->lang('hover_logo', array($site->displayName()))) . $site->displayLink();
?>
Ejemplo n.º 9
0
    if (GWF_Session::isLoggedIn()) {
        $buttons .= GWF_Button::generic($tLang->lang('btn_pm'), $u->getPMHref());
    }
    if ($buttons !== '') {
        echo GWF_Table::rowStart();
        echo "<td colspan=\"2\" class=\"ce\">{$buttons}</td>" . PHP_EOL;
        echo GWF_Table::rowEnd();
    }
}
# Fav Sites
echo wcProfileFavSites($u->getID());
echo wcProfileFavCats($u->getID());
echo '</table>' . PHP_EOL;
echo '</div>' . PHP_EOL;
# Regats
$regats = WC_RegAt::getRegats($u->getID(), $orderby);
if (count($regats) > 0) {
    echo '<div class="oa fl">' . PHP_EOL;
    wcProfileRegats($regats, GWF_WEB_ROOT . 'index.php?mo=Profile&me=Profile&username='******'user_name') . '&by=%BY%&dir=%DIR%', $priv, isset($data['WC_HIDE_SCORE']));
    echo '</div>' . PHP_EOL;
}
# Break on jquery
if ($tVars['jquery']) {
    echo '<div class="cb"></div>' . PHP_EOL;
    return;
}
require_once GWF_CORE_PATH . 'module/WeChall/WC_HistoryUser2.php';
# Graphs and Activity
if ($u->getLevel() > 0) {
    echo wcProfileLastActivity($u, 10, $priv);
    // 	echo '<div class="cb"></div>'.PHP_EOL;
Ejemplo n.º 10
0
 private function displayBanner(GWF_User $user, $format = self::FORMAT, $bg = self::BGCOLOR, $fg = self::FGCOLOR, $size, $spacingx = 1, $spacingy = 1, $mx, $my, $divider)
 {
     $this->box_logo = new GWF_GDRect();
     $this->box_stats = new GWF_GDRect(0, 0, self::WIDTH, self::HEIGHT);
     $this->box_avatar = new GWF_GDRect();
     // 		echo $this->box_stats->toString().PHP_EOL;
     # Image
     if (false === ($image = imagecreatetruecolor(self::WIDTH, self::HEIGHT))) {
         echo GWF_HTML::err('ERR_GENERAL', array(__FILE__, __LINE__));
         return false;
     }
     # Colors
     $bg = GWF_GDColor::fromHTML($image, $bg);
     $fg = GWF_GDColor::fromHTML($image, $fg);
     # BG
     imagefilledrectangle($image, 0, 0, self::WIDTH, self::HEIGHT, $bg);
     $format2 = '';
     for ($i = 0; $i < strlen($format); $i++) {
         $c = $format[$i];
         $pos = $this->parsePos($format, $i);
         switch ($c) {
             case 'L':
                 $this->copyLogo($image, $pos);
                 break;
             case 'A':
                 $this->copyAvatar($image, $user, $pos);
                 break;
             case 'S':
                 $this->copySites($image);
                 break;
             default:
                 $format2 .= $c;
                 break;
         }
     }
     // 		echo $this->box_stats->toString().PHP_EOL;
     $text = '';
     for ($i = 0; $i < strlen($format2); $i++) {
         $c = $format2[$i];
         switch ($c) {
             case 'U':
                 $text .= $divider . $user->getVar('user_name');
                 break;
             case 'R':
                 $text .= $divider . 'Registered: ' . GWF_Time::displayAge($user->getVar('user_regdate'));
                 break;
             case 'T':
                 $text .= $divider . $this->module->langUser($user, 'th_totalscore') . ': ' . $user->getVar('user_level');
                 break;
             case 'G':
                 $text .= $divider . $this->module->langUser($user, 'th_rank2') . ': ' . WC_RegAt::calcExactRank($user);
                 break;
             case 'C':
                 $text .= $divider . $this->module->langUser($user, 'th_crank') . ': ' . WC_RegAt::calcExactCountryRank($user);
                 break;
             case 'X':
                 $text .= $divider . $this->getSignature($user);
                 break;
         }
     }
     // 		die($this->getFontPath());
     $text = substr($text, strlen($divider));
     if (!GWF_GDText::write($image, $this->getFontPath(), $this->box_stats->x, $this->box_stats->y, $text, $fg, $this->box_stats->w, $size, $spacingx, $spacingy, $mx, $my)) {
         return false;
     }
     // 		die();
     # Output
     header('Content-Type: image/jpeg');
     imagejpeg($image);
     imagedestroy($image);
 }
Ejemplo n.º 11
0
 private function getSinglePageRank($cid, $ipp, $user)
 {
     # Guest or not your country
     if ($user === false || $user->getCountryID() !== $cid) {
         return array(Common::getGet('page', 1), 1);
     }
     # Requested a page, so use it
     if (false !== ($page = Common::getGet('page'))) {
         return array($page, 1);
     }
     # Oh, auto-page detection for the user!
     $rank = WC_RegAt::calcExactCountryRank($user);
     $page = GWF_PageMenu::getPageForPos($rank, $ipp);
     return array($page, $rank);
 }
Ejemplo n.º 12
0
 /**
  * Wechall internally bot response.
  * The advantage over the other method is accurate challcount.
  * @param string $input
  * @return string
  */
 public function wechallChalls($input)
 {
     if ($input === '') {
         return sprintf('Try wechallchalls.php?userame=blub');
     }
     require_once GWF_CORE_PATH . 'module/WeChall/WC_ChallSolved.php';
     $wechall = WC_Site::getWeChall();
     $siteid = $wechall->getID();
     if (false !== ($user = GWF_User::getByName($input))) {
         if ($user->isOptionEnabled(0x10000000)) {
             die('This user is not ranked!');
         }
         $rank = WC_RegAt::calcExactSiteRank($user, $siteid);
     } elseif (false !== ($user = WC_RegAt::getUserBySiteRank($siteid, $input))) {
         $rank = intval($input);
     } else {
         return sprintf('The user does not exist.');
     }
     //		if (false !== ($error = $this->module->isExcludedFromAPI($user))) {
     //			return $error;
     //		}
     $userid = $user->getID();
     $username = $user->displayUsername();
     $solvedCount = WC_ChallSolved::getSolvedCount($userid);
     $score = WC_Challenge::getScoreForUser($user);
     $challcount = WC_Challenge::getChallCount();
     $maxScore = WC_Challenge::getMaxScore();
     $percent = $score / $maxScore * 100;
     $out = sprintf('%s solved %d of %d Challenges with %d of %d possible points (%.02f%%).', $username, $solvedCount, $challcount, $score, $maxScore, $percent);
     if ($rank !== false) {
         $out .= sprintf(' Rank for the site WeChall: %d', $rank);
     }
     return $out;
 }
Ejemplo n.º 13
0
 private function getSites()
 {
     $sitesLow = $sitesMed = $sitesHigh = $sitesNull = $sitesVersus = $sitesHave = array();
     if ($this->user1 !== false) {
         if (false === ($regats1 = WC_RegAt::getRegats($this->user1->getID()))) {
             return false;
         }
         foreach ($regats1 as $r) {
             $r instanceof WC_RegAt;
             $solved = $r->getFloat('regat_solved') * 100;
             $site = $r->getSite();
             $siteid = $site->getID();
             //Var('site_id');
             if (isset($this->sel[$siteid])) {
                 $site->setVar('sel', true);
             }
             if ($solved <= 0.0) {
                 $sitesNull[] = $site;
             } elseif ($solved < 33.3) {
                 $sitesLow[] = $site;
             } elseif ($solved < 66.59999999999999) {
                 $sitesMed[] = $site;
             } else {
                 $sitesHigh[] = $site;
             }
             $sitesHave[] = $siteid;
             ##->getVar('regat_sid');
         }
     }
     if ($this->user2 !== false) {
         if (false !== ($regats2 = WC_RegAt::getRegats($this->user2->getID()))) {
             foreach ($regats2 as $r) {
                 $siteid = $r->getVar('regat_sid');
                 $site = $r->getSite();
                 if (!in_array($siteid, $sitesHave, true)) {
                     $sitesVersus[] = $r->getSite();
                     $sitesHave[] = $siteid;
                 }
                 if (isset($this->sel[$siteid])) {
                     $site->setVar('sel', true);
                 }
             }
         }
     }
     return array('high' => $sitesHigh, 'med' => $sitesMed, 'low' => $sitesLow, 'null' => $sitesNull, 'vs' => $sitesVersus);
 }
Ejemplo n.º 14
0
	<div class="gwf_post_uinfo gwf_tr_<?php 
echo $trd;
?>
">
		<?php 
echo GWF_HTML::div('<span>' . $user->displayCountryFlag() . $user->displayProfileLink() . '</span>');
?>
		<?php 
echo GWF_HTML::div($user->displayTitle(), $class);
/* don't htmlspecialchars */
?>
		<?php 
if (!$user->isOptionEnabled(0x10000000)) {
    ?>
		<?php 
    echo GWF_HTML::div(WC_HTML::lang('th_rank2') . ':&nbsp;' . WC_RegAt::calcExactRank($user));
    ?>
		<?php 
}
?>
		<?php 
if (!isset($data['WC_HIDE_SCORE'])) {
    ?>
		<?php 
    echo GWF_HTML::div(WC_HTML::lang('th_totalscore') . ':&nbsp;' . $user->getVar('user_level'));
    ?>
		<?php 
}
?>
		<?php 
echo GWF_HTML::div($tLang->lang('th_postcount') . ':&nbsp;' . $opts->getPostcount());
Ejemplo n.º 15
0
 private function onUpdateAll()
 {
     $form = $this->getFormAll();
     if (false !== ($error = $form->validate($this->module))) {
         return $error;
     }
     set_time_limit(600);
     $user = GWF_Session::getUser();
     $regats = WC_RegAt::getRegats(GWF_Session::getUserID());
     $back = '';
     foreach ($regats as $regat) {
         $site = $regat->getSite();
         $back .= $this->onUpdateB($site, $user);
     }
     return $back;
 }
Ejemplo n.º 16
0
if ($tVars['can_link']) {
    echo $tVars['form_link'];
}
if (count($tVars['linked']) > 0) {
    $headers = array(array(), array($tLang->lang('th_site_name'), 'site_name', 'ASC'), array($tLang->lang('th_regat_solved'), 'regat_challsolved', 'DESC'), array($tLang->lang('th_site_challcount'), 'site_challcount', 'DESC'), array($tLang->lang('th_auto_update')), array(), array($tLang->lang('th_site_score'), 'regat_score', 'DESC'), array($tLang->lang('th_regat_solved'), 'regat_solved', 'DESC'), array($tLang->lang('th_regat_lastdate'), 'regat_lastdate', 'DESC'), array($tLang->lang('th_regat_onsitename'), 'regat_onsitename', 'ASC'), array(), array());
    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) . '&nbsp;' . $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');
Ejemplo n.º 17
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.º 18
0
 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();
 }
Ejemplo n.º 19
0
 private function onUnFreeze($data)
 {
     if (false !== ($err = GWF_Form::validateCSRF_WeakS())) {
         return GWF_HTML::error('WeChall', $err);
     }
     if (!is_array($data)) {
         return GWF_HTML::err('ERR_GENERAL', array(__FILE__, __LINE__));
     }
     foreach ($data as $key => $value) {
         break;
     }
     $data = explode(',', $key);
     if (count($data) !== 2) {
         return GWF_HTML::err('ERR_GENERAL', array(__FILE__, __LINE__));
     }
     $userid = intval($data[0]);
     $siteid = intval($data[1]);
     if (false === ($user = GWF_User::getByID($userid))) {
         return GWF_HTML::err('ERR_UNKNOWN_USER');
     }
     if (false === ($site = WC_Site::getByID($siteid))) {
         return $this->module->error('err_site');
     }
     if (WC_Freeze::isUserFrozenOnSite($userid, $siteid)) {
         # Unfreeze
         if (false === WC_Freeze::unfreezeUser($userid, $siteid)) {
             return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
         }
         # Insert event.
         $rank = WC_RegAt::calcExactRank($user);
         WC_HistoryUser2::insertEntry($user, $site, 'unban');
     }
     # Done
     return $this->module->message('msg_unfrozen', array($user->displayUsername(), $site->displayName()));
 }
Ejemplo n.º 20
0
 private function onHardlink()
 {
     $form = $this->formHardlink();
     if (false !== ($error = $form->validate($this->module))) {
         return $error;
     }
     $onsitename = Common::getPost('onsitename');
     $site = $this->site;
     $user = $this->user;
     require_once GWF_CORE_PATH . 'module/WeChall/WC_RegAt.php';
     require_once GWF_CORE_PATH . 'module/WeChall/WC_Freeze.php';
     if (false !== WC_RegAt::getRegatRow($user->getID(), $site->getID())) {
         return $this->module->error('err_already_linked', array($site->displayName()));
     }
     if (WC_Freeze::isUserFrozenOnSite($user->getID(), $site->getID())) {
         return $this->module->error('err_site_ban', array($site->displayName()));
     }
     if (false !== ($regat = WC_RegAt::getByOnsitename($site->getID(), $onsitename))) {
         if (false === ($user = $regat->getUser())) {
             return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
         } else {
             return $this->module->error('err_onsitename_taken', array(htmlspecialchars($onsitename), $site->displayName(), $user->displayUsername()));
         }
     }
     $entry = new WC_RegAt(array('regat_uid' => $user->getID(), 'regat_sid' => $site->getID(), 'regat_onsitename' => $onsitename, 'regat_onsitescore' => 0, 'regat_challcount' => 0, 'regat_options' => 0, 'regat_lastdate' => '', 'regat_linkdate' => GWF_Time::getDate(GWF_Date::LEN_DAY), 'regat_solved' => 0.0, 'regat_score' => 0, 'regat_langid' => 0, 'regat_tagbits' => 0, 'regat_onsiterank' => 0, 'regat_challsolved' => 0));
     if (false === $entry->insert()) {
         return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
     }
     if (0 < ($percent = $form->getVar('percent'))) {
         $new_score = round($site->getOnsiteScore() * $percent / 100);
         $site->onUpdateUserB($user, $entry, $new_score, true, true);
     }
     return $this->module->message('msg_hardlinked', array($user->displayUsername(), $site->displayName(), GWF_HTML::display($onsitename)));
 }
Ejemplo n.º 21
0
 public function isUserLinked($userid)
 {
     return WC_RegAt::getRegatRow($userid, $this->getID()) !== false;
 }