Example #1
0
 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();
 }
Example #2
0
 public function validate_username(Module_Admin $module, $arg)
 {
     $_POST['username'] = $arg = trim($arg);
     if ($this->user->getVar('user_name') === $arg) {
         return false;
     }
     if (GWF_User::getByName($arg) !== false) {
         return $this->module->lang('err_username_taken');
     }
     if (!GWF_Validator::isValidUsername($arg)) {
         return $this->module->lang('err_username');
     }
     return false;
 }
Example #3
0
 /**
  * Get the translation for a user.
  * A user can have two languages set, and there is browser lang as third fallback;
  * Enter description here ...
  * @param GWF_User $user
  * @param unknown_type $key
  * @param unknown_type $args
  */
 public function langUser(GWF_User $user, $key, $args)
 {
     // Primary
     $iso1 = $user->getVar('user_langid');
     if (false !== $this->loadLanguage($iso1)) {
         return $this->translate($iso1, $key, $args);
     }
     // Secondary
     $iso2 = $user->getVar('user_langid2');
     if (false !== $this->loadLanguage($iso2)) {
         return $this->translate($iso2, $key, $args);
     }
     // Browser
     return $this->translate(self::getBrowserISO(), $key, $args);
 }
Example #4
0
 private function getGraphTitle()
 {
     if ($this->user2 === false) {
         return $this->module->lang('pt_stats', array($this->user1->getVar('user_name')));
     } else {
         return $this->module->lang('pt_stats2', array($this->user1->getVar('user_name'), $this->user2->getVar('user_name')));
     }
 }
Example #5
0
 private static function createPMOptions(GWF_User $user)
 {
     $row = new self(array('pmo_uid' => $user->getVar('user_id'), 'pmo_options' => 0, 'pmo_auto_folder' => 0, 'pmo_signature' => '', 'pmo_level' => 0));
     if (false === $row->replace()) {
         return false;
     }
     //		$row->setVar('pmo_uid', $user);
     return $row;
 }
Example #6
0
 private static function sendMail(Module_Account $module, GWF_User $user, array $data)
 {
     $token = GWF_AccountChange::createToken($user->getID(), 'demo', serialize($data));
     $mail = new GWF_Mail();
     $mail->setSender($module->cfgMailSender());
     $mail->setReceiver($user->getVar('user_email'));
     $mail->setSubject($module->lang('chdemo_subj'));
     $username = $user->display('user_name');
     $timeout = GWF_Time::humanDuration($module->cfgChangeTime());
     $gender = GWF_HTML::display($user->getVar('user_gender'));
     $country = GWF_Country::getByIDOrUnknown($data['user_countryid'])->display('country_name');
     $lang1 = GWF_Language::getByIDOrUnknown($data['user_langid'])->display('lang_nativename');
     $lang2 = GWF_Language::getByIDOrUnknown($data['user_langid2'])->display('lang_nativename');
     $gender = GWF_HTML::lang('gender_' . $data['user_gender']);
     $birthdate = $data['user_birthdate'] > 0 ? GWF_Time::displayDate($data['user_birthdate'], true, 1) : GWF_HTML::lang('unknown');
     $link = self::getChangeLink($user->getID(), $token);
     $mail->setBody($module->lang('chdemo_body', array($username, $timeout, $gender, $country, $lang1, $lang2, $birthdate, $link)));
     return $mail->sendToUser($user) ? $module->message('msg_mail_sent') : GWF_HTML::err('ERR_MAIL_SENT');
 }
Example #7
0
 public static function insertNote(GWF_User $user, $note)
 {
     # no empty notes
     if ($note === '') {
         return false;
     }
     # insert it
     $entry = new self(array('accrm_uid' => $user->getVar('user_id'), 'accrm_note' => $note));
     if (false === $entry->replace()) {
         return false;
     }
     return $note;
 }
Example #8
0
 private static function sendEmail(Module_Account $module, GWF_User $user, $newMail)
 {
     $mail = new GWF_Mail();
     $mail->setReceiver($user->getVar('user_email'));
     $mail->setSender($module->cfgMailSender());
     $mail->setSubject($module->lang('chmaila_subj'));
     $newmail = trim(Common::getPost('email'));
     $link = self::createLink($module, $user, $newMail);
     $mail->setBody($module->lang('chmaila_body', array($user->display('user_name'), $link)));
     if ($mail->sendToUser($user)) {
         return $module->message('msg_mail_sent');
     } else {
         return GWF_HTML::err('ERR_MAIL_SENT');
     }
 }
Example #9
0
 private function calcRank(GWF_User $user, $bit)
 {
     $db = gdo_db();
     $bit = (int) $bit;
     $uid = $user->getVar('user_id');
     $score = $this->calcScore($user, $bit);
     $regat = GWF_TABLE_PREFIX . 'wc_regat';
     $query = "SELECT regat_uid, SUM(regat_score) AS sum " . "FROM {$regat} " . "WHERE regat_tagbits&{$bit} AND regat_options&4=0 " . "GROUP BY regat_uid " . "HAVING sum>{$score} OR (sum={$score} AND regat_uid<{$uid})";
     if (false === ($result = $db->queryRead($query, false))) {
         return -1;
     }
     $back = (int) $db->numRows($result);
     $db->free($result);
     return $back + 1;
 }
Example #10
0
 public function templateChalls(GWF_User $user)
 {
     $whitelist = array('chall_score', 'chall_title', 'chall_creator_name', 'chall_solvecount', 'chall_date', 'chall_dif', 'chall_edu', 'chall_fun', 'csolve_date', 'csolve_time_taken');
     require_once GWF_CORE_PATH . 'module/WeChall/WC_ChallSolved.php';
     $challs = GDO::table('WC_Challenge');
     $db = gdo_db();
     $uid = $user->getVar('user_id');
     $challs = GWF_TABLE_PREFIX . 'wc_chall';
     $solved = GWF_TABLE_PREFIX . 'wc_chall_solved';
     $by = GDO::getWhitelistedByS(Common::getGet('pcby'), $whitelist, self::DEFAULT_BY);
     $dir = GDO::getWhitelistedDirS(Common::getGet('pcdir'), self::DEFAULT_DIR);
     $orderby = "ORDER BY {$by} {$dir}";
     $query = "SELECT c.*, s.* FROM {$challs} c LEFT JOIN {$solved} s ON c.chall_id=s.csolve_cid AND s.csolve_uid={$uid} {$orderby}";
     $tVars = array('data' => $db->queryAll($query), 'sort_url' => GWF_WEB_ROOT . 'index.php?mo=Profile&me=Profile&username='******'user_name') . '&pcby=%BY%&pcdir=%DIR%#wc_profile_challenges', 'table_title' => $this->module->lang('tt_challs_for', array('', $user->display('user_name'))));
     return $this->module->templatePHP('challs_profile.php', $tVars);
 }
Example #11
0
 public static function onViewed(GWF_User $user)
 {
     $userid = $user->getID();
     $av = $user->getVar('user_avatar_v');
     if (false === ($row = self::getByID($userid))) {
         $row = new self(array('ag_uid' => $userid, 'ag_hits' => 1, 'ag_version' => $av));
         if (false === $row->insert()) {
             return false;
         }
         $row->setVar('ag_uid', $user);
         return true;
     }
     if ($row->getVar('ag_version') !== $av) {
         return $row->saveVars(array('ag_hits' => 1, 'ag_version' => $av));
     }
     return $row->increase('ag_hits', 1);
 }
Example #12
0
 /**
  * Get Forum Unread Counter - Quickhook for topmenu.
  * @param array(GWF_User $user)
  * @return string the counter enclosed in [counter]
  * @todo create countUnread()
  */
 public static function getUnreadForum(GWF_User $user, $pattern = '[%s]', $default = '[0]')
 {
     if (false === self::loadModuleClass('Forum', 'GWF_ForumThread.php')) {
         return '';
     }
     if (true === $user->isGuest() || true === $user->isWebspider()) {
         return '';
     }
     $uid = $user->getID();
     $data = $user->getUserData();
     $grp = GWF_TABLE_PREFIX . 'usergroup';
     $permquery = "(thread_gid=0 OR (SELECT 1 FROM {$grp} WHERE ug_userid={$uid} AND ug_groupid=thread_gid))";
     $stamp = isset($data['GWF_FORUM_STAMP']) ? $data['GWF_FORUM_STAMP'] : $user->getVar('user_regdate');
     $regtimequery = sprintf('thread_lastdate>=\'%s\'', $stamp);
     $conditions = "( (thread_postcount>0) AND ({$permquery}) AND ({$regtimequery} OR thread_force_unread LIKE '%:{$uid}:%') AND (thread_unread NOT LIKE '%:{$uid}:%') AND (thread_options&4=0) )";
     if (false === ($count = GDO::table('GWF_ForumThread')->selectVar('COUNT(*)', $conditions))) {
         return '';
         # DB Error
     }
     return $count === '0' ? $default : sprintf($pattern, $count);
 }
Example #13
0
 public static function hookDeleteUser(GWF_User $user)
 {
     $uid = $user->getVar('user_id');
     $pms = self::table(__CLASS__);
     $del = self::OWNER_DELETED;
     if (false === $pms->update("pm_options=pm_options|{$del}", "pm_owner={$uid}")) {
         return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
     }
     $del = self::OTHER_DELETED;
     if (false === $pms->update("pm_options=pm_options|{$del}", "pm_from={$uid}")) {
         return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
     }
     return '';
 }
Example #14
0
function wcProfileUsergroup(GWF_User $user, $is_logged_in)
{
    $ug = GWF_TABLE_PREFIX . 'usergroup';
    $userid = $user->getVar('user_id');
    if (false === gdo_db()->queryFirst("SELECT 1 FROM {$ug} WHERE ug_userid={$userid}")) {
        return '';
    }
    if (false === ($mod_ug = GWF_Module::loadModuleDB('Usergroups'))) {
        return '';
    }
    $mod_ug instanceof Module_Usergroups;
    $groups = $mod_ug->getGroups($user);
    foreach ($groups as $group) {
        if ($group->isAskToJoin()) {
            echo sprintf('<h2>%s</h2>', WC_HTML::lang('pi_ug_info', array($user->displayUsername(), $group->display('group_name'), $group->getVar('group_memberc'))));
            if ($is_logged_in) {
                echo sprintf('<h3>%s</h3>', WC_HTML::lang('pi_ug_join', array(GWF_WEB_ROOT . 'index.php?mo=Usergroups&amp;me=Join&amp;gid=' . $group->getID())));
            } else {
                echo sprintf('<h3>%s</h3>', WC_HTML::lang('pi_ug_register', array(GWF_WEB_ROOT . 'register')));
            }
        } else {
        }
    }
    return '';
}
Example #15
0
 public function onThanks(Module_Forum $module, GWF_User $user)
 {
     $data = array('post_thanks_by' => $this->getVar('post_thanks_by') . $user->getVar('user_id') . ':', 'post_thanks_txt' => $this->getVar('post_thanks_txt') . $user->getVar('user_name') . ':', 'post_thanks' => $this->getThanksCount() + 1);
     if (false === $this->saveVars($data)) {
         return false;
         # DB error
     }
     if (false === $this->getThread()->increase('thread_thanks', 1)) {
         return false;
     }
     # Increase Users total thanks counter
     if (false !== ($user = $this->getUser(false))) {
         if (false !== ($options = GWF_ForumOptions::getUserOptions($this->getUser(false)))) {
             $options->increase('fopt_thanks', 1);
         }
     }
     return true;
 }
Example #16
0
 public static function calcExactCountryRank(GWF_User $user)
 {
     if ('0' === ($cid = $user->getVar('user_countryid'))) {
         return -1;
     }
     $deleted = GWF_User::DELETED;
     $rank = self::calcCountryRank($user);
     $score = $user->getVar('user_level');
     $uid = $user->getVar('user_id');
     $rank += $user->countRows("user_options&0x10000000=0 AND user_options&{$deleted}=0 AND user_level={$score} AND user_countryid={$cid} AND user_id<{$uid}");
     return $rank;
 }
Example #17
0
 private function getGPGMailBody(GWF_User $user, $fingerprint)
 {
     $href = Common::getAbsoluteURL(sprintf('index.php?mo=Account&me=SetupGPGKey&userid=%s&token=%s', $user->getVar('user_id'), $fingerprint), true);
     $link = GWF_HTML::anchor($href, $href);
     return $this->module->langUser($user, 'mailb_gpg', array($user->displayUsername(), $link));
 }
Example #18
0
 public static function getUnreadPMCount(GWF_User $user)
 {
     $db = gdo_db();
     $pms = GWF_TABLE_PREFIX . 'pm';
     $uid = $user->getVar('user_id');
     $query = "SELECT COUNT(*) c FROM {$pms} WHERE pm_to={$uid} AND (pm_options&1=0)";
     $result = $db->queryFirst($query, false);
     return (int) $result['c'];
 }
Example #19
0
 public static function displayIcons(GWF_User $user)
 {
     $back = '';
     $db = gdo_db();
     $uid = $user->getInt('user_id');
     $regats = GWF_TABLE_PREFIX . 'wc_regat';
     $query = "SELECT regat_sid, regat_solved FROM {$regats} WHERE regat_uid={$uid}";
     if (false === ($result = $db->queryRead($query))) {
         return '';
     }
     $i = 0;
     while (false !== ($row = $db->fetchRow($result))) {
         if (0.05 > ($solved = floatval($row[1]))) {
             continue;
         }
         if (++$i % 5 === 0) {
             $back .= '<br/>' . PHP_EOL;
         }
         $siteid = (int) $row[0];
         $site = WC_Site::getByID($siteid);
         $back .= $site->displayLogoUN($user->getVar('user_name'), $solved, 6, 28, true) . PHP_EOL;
     }
     $db->free($result);
     return $back;
 }
Example #20
0
 private function countUnreadPM(GWF_User $user)
 {
     require_once 'GWF_PM.php';
     $pms = GDO::table('GWF_PM');
     $uid = $user->getVar('user_id');
     $read = GWF_PM::READ;
     return $pms->countRows("pm_to={$uid} AND (pm_options&{$read}=0)");
 }
Example #21
0
 /**
  * Select Users For Global Ranking.
  * @param int $count
  * @param int $from
  * @return array
  */
 private function selectUsers($count, $from)
 {
     $db = gdo_db();
     $count = (int) $count;
     $from = (int) $from;
     $regat = GDO::table('WC_RegAt')->getTableName();
     $users = GDO::table('GWF_User')->getTableName();
     $query = "SELECT user_id,user_name,user_level,SUM(regat_score) AS lts, COUNT(regat_score) AS nlinks, regat_langid,user_countryid FROM {$regat} AS B JOIN (SELECT user_id,user_name,user_level,user_countryid FROM {$users} WHERE user_options&0x10000000=0 ORDER BY user_level DESC, user_id ASC LIMIT {$from}, {$count}) AS C ON user_id=regat_uid GROUP by user_id,regat_langid ORDER BY user_level DESC, user_id ASC";
     $back = array();
     if (false === ($result = $db->queryRead($query))) {
         return $back;
     }
     $current = false;
     while (false !== ($row = $db->fetchAssoc($result))) {
         if ($current === false) {
             $current = new GWF_User($row);
             $current->setVar('nlinks', 0);
             $back[] = $current;
         } elseif ($current->getVar('user_id') !== $row['user_id']) {
             if (count($back) === $count) {
                 break;
             }
             $current = new GWF_User($row);
             $current->setVar('nlinks', 0);
             $back[] = $current;
         }
         $current->setVar('grank_' . $row['regat_langid'], $row['lts']);
         $current->setVar('nlinks', $current->getVar('nlinks') + $row['nlinks']);
         //			var_dump($current->getGDOData());
     }
     $db->free($result);
     //		var_dump($back);
     return $back;
 }
Example #22
0
 public static function hookDeleteUser(GWF_User $user)
 {
     $uid = $user->getID();
     $threads = self::table(__CLASS__);
     $username = $threads->escape($user->getVar('user_name'));
     if (false === $threads->update("thread_firstposter=''", "thread_firstposter='{$username}'")) {
         return GWF_HTML::err('ERR_DATABASE', __FILE__, __LINE__);
     }
     if (false === $threads->update("thread_lastposter=''", "thread_lastposter='{$username}'")) {
         return GWF_HTML::err('ERR_DATABASE', __FILE__, __LINE__);
     }
     if (false === $threads->update("thread_uid=0", "thread_uid={$uid}")) {
         return GWF_HTML::err('ERR_DATABASE', __FILE__, __LINE__);
     }
     return true;
 }
Example #23
0
 private static function getMailBodyDone(Module_Audit $module, GWF_User $user, GWF_AuditLog $log)
 {
     $url = Common::getAbsoluteURL($log->hrefReplay(), false);
     $link = GWF_HTML::anchor($url, $url);
     return sprintf("Hello %s\n\nThere is a new warchall script that needs audit\nReplay: %s\n\nFrom: %s-%s (%s)\n", $user->getVar('user_name'), $link, $log->getVar('al_eusername'), $log->getVar('al_username'), $log->displayDate());
 }
Example #24
0
 public function isSiteAdmin(GWF_User $user)
 {
     return WC_SiteAdmin::isSiteAdmin($user->getVar('user_id'), $this->getID());
 }