Example #1
0
 public static function onAccess(Module_Account $module, GWF_User $user)
 {
     $alert = false;
     $table = self::table(__CLASS__);
     # Check UA
     $ua = self::uahash();
     if ($user->isOptionEnabled(GWF_User::ALERT_UAS)) {
         if (!$table->selectVar('1', "accacc_uid={$user->getID()} AND accacc_ua=" . self::hashquote($ua))) {
             $alert = true;
         }
     }
     # Check exact IP
     $ip = GWF_IP6::getIP(GWF_IP_EXACT);
     if ($user->isOptionEnabled(GWF_User::ALERT_IPS)) {
         if (!$table->selectVar('1', "accacc_uid={$user->getID()} AND accacc_ip='" . $table->escape($ip) . "'")) {
             $alert = true;
         }
     }
     $isp = null;
     if ($user->isOptionEnabled(GWF_User::ALERT_ISPS)) {
         $isp = self::isphash();
         if (!$table->selectVar('1', "accacc_uid={$user->getID()} AND accacc_isp=" . self::hashquote($isp))) {
             $alert = true;
         }
     }
     if ($alert === true) {
         self::sendAlertMail($module, $user, 'record_alert');
     }
     $data = array('accacc_uid' => $user->getID(), 'accacc_ip' => $ip, 'accacc_isp' => $isp, 'accacc_ua' => $ua, 'accacc_time' => time());
     $table->insertAssoc($data);
 }
Example #2
0
 public static function markSolved(GWF_User $user, WC_Warchall $chall)
 {
     if (!self::table(__CLASS__)->insertAssoc(array('wc_wcid' => $chall->getID(), 'wc_uid' => $user->getID(), 'wc_solved_at' => GWF_Time::getDate(14)))) {
         return false;
     }
     return true;
 }
Example #3
0
 private function onUserVote(GWF_User $user)
 {
     if (false !== ($err = $this->votescore->onUserVoteSafe($this->score, $user->getID()))) {
         return $err;
     }
     return $this->onVoted($user);
 }
Example #4
0
 private function onSolved(WC_Warflag $flag)
 {
     if ($this->box->isMultisolve()) {
         if (false !== ($err = $this->onMultiSolved($flag))) {
             return $err;
         }
     } else {
         if (false !== ($err = $this->onSingleSolved($flag))) {
             return $err;
         }
     }
     if (!$this->box->recalcPlayersAndScore()) {
         return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
     }
     if (false === ($this->flags = WC_Warflag::getForBoxAndUser($this->box, $this->user, 'wf_order ASC'))) {
         return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
     }
     $this->module->includeClass('WC_RegAt');
     if ($this->site->isUserLinked($this->user->getID())) {
         $result = $this->site->onUpdateUser($this->user);
         return $result->display($this->site->displayName());
     } else {
         return '_YOU_ARE_NOT_LINKED_TO_THE_SITE,_BUT_WELL_DONE!';
     }
 }
Example #5
0
 public function onAssign(GWF_HelpdeskTicket $ticket, GWF_User $user)
 {
     if (false === $ticket->saveVars(array('hdt_worker' => $user->getID(), 'hdt_status' => 'working'))) {
         return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
     }
     return $this->module->message('msg_assigned', array($ticket->getID(), $user->displayUsername()));
 }
Example #6
0
 public static function mark(GWF_User $user, GWF_Links $link, $bool)
 {
     $userid = $user->getID();
     $linkid = $link->getID();
     $is_fav = self::table(__CLASS__)->getRow($userid, $linkid) !== false;
     if ($is_fav === $bool) {
         return true;
     }
     $row = new self(array('lf_uid' => $userid, 'lf_lid' => $linkid));
     if ($bool) {
         if (!$row->replace()) {
             return false;
         }
     } else {
         if (!$row->delete()) {
             return false;
         }
     }
     if (false === $link->increase('link_favcount', $bool ? 1 : -1)) {
         return false;
     }
     if (false === $link->onCalcPopularity()) {
         return false;
     }
     return true;
 }
Example #7
0
 public static function isEnabledLyrics(Slay_Song $song, GWF_User $user)
 {
     if (false === ($row = self::getByIDs($song->getID(), $user->getID()))) {
         return true;
     }
     return $row->isOptionEnabled(self::ENABLED);
 }
Example #8
0
 private function send()
 {
     $form = $this->getForm();
     if (false !== ($error = $form->validate($this->module))) {
         return $error . $this->templateSend();
     }
     # Get reply to field
     if (false !== ($otherid = Common::getGetInt('reply', false))) {
     } elseif (false !== ($otherid = Common::getGetInt('quote', false))) {
     }
     $parent1 = $parent2 = 0;
     if ($otherid !== false) {
         if (false !== ($otherpm = GWF_PM::getByID($otherid))) {
             $parent1 = $otherpm->getID();
             if (false !== ($p2 = $otherpm->getOtherPM())) {
                 $parent2 = $p2;
             }
         }
     }
     $result = $this->module->deliver($this->user->getID(), $this->getReceiver()->getID(), $form->getVar('title'), $form->getVar('message'), $parent1, $parent2);
     $mail = '';
     switch ($result) {
         case '1':
             return $this->module->message('msg_mail_sent', array($this->getReceiver()->display('user_name')));
         case '0':
             break;
         case '-4':
             return GWF_HTML::err('ERR_MAIL_SENT');
         default:
             return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__ . ' - Code: ' . $result));
     }
     return $mail . $this->module->message('msg_sent');
 }
Example #9
0
 private function contactData(GWF_User $user)
 {
     require_once GWF_CORE_PATH . 'module/Profile/GWF_Profile.php';
     if (false === ($p = GWF_Profile::getProfile($user->getID()))) {
         return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
     }
     if ($p->isGuestHidden() || $p->isHiddenLevel(0)) {
         return '';
     }
     $back = '';
     if ('' !== ($v = $p->getVar('prof_firstname'))) {
         $back .= 'FirstName:' . $v . PHP_EOL;
     }
     if ('' !== ($v = $p->getVar('prof_lastname'))) {
         $back .= 'LastName:' . $v . PHP_EOL;
     }
     if ('' !== ($v = $p->getVar('prof_street'))) {
         $back .= 'Street:' . $v . PHP_EOL;
     }
     if ('' !== ($v = $p->getVar('prof_city'))) {
         $back .= 'City:' . $v . PHP_EOL;
     }
     if ('' !== ($v = $p->getVar('prof_zip'))) {
         $back .= 'ZIPCode:' . $v . PHP_EOL;
     }
     if ($p->isContactHiddenLevel(0)) {
         return $back;
     }
     if ($user->isOptionEnabled(GWF_User::SHOW_EMAIL)) {
         if ('' !== ($v = $user->displayEMail())) {
             $back .= 'EMail:' . $v . PHP_EOL;
         }
     }
     if ('' !== ($v = $p->getVar('prof_tel'))) {
         $back .= 'Tel:' . $v . PHP_EOL;
     }
     if ('' !== ($v = $p->getVar('prof_mobile'))) {
         $back .= 'Mobile:' . $v . PHP_EOL;
     }
     if ('' !== ($v = $p->getVar('prof_icq'))) {
         $back .= 'ICQ:' . $v . PHP_EOL;
     }
     if ('' !== ($v = $p->getVar('prof_msn'))) {
         $back .= 'MSN:' . $v . PHP_EOL;
     }
     if ('' !== ($v = $p->getVar('prof_jabber'))) {
         $back .= 'Jabber:' . $v . PHP_EOL;
     }
     if ('' !== ($v = $p->getVar('prof_skype'))) {
         $back .= 'Skype:' . $v . PHP_EOL;
     }
     if ('' !== ($v = $p->getVar('prof_yahoo'))) {
         $back .= 'Yahoo!:' . $v . PHP_EOL;
     }
     if ('' !== ($v = $p->getVar('prof_aim'))) {
         $back .= 'AIM:' . $v . PHP_EOL;
     }
     return $back;
 }
Example #10
0
 public static function mayAddTag(GWF_User $user)
 {
     if ($user->isStaff()) {
         return true;
     }
     $uid = $user->getID();
     return self::table(__CLASS__)->selectFirst('1', "st_uid={$uid}") === false;
 }
Example #11
0
 /**
  * @param GWF_User $user
  * @return GWF_PMOptions
  */
 public static function getPMOptions(GWF_User $user)
 {
     $userid = $user->getID();
     //		if (false === ($back = self::table(__CLASS__)->selectFirstObject('*', "pmo_uid=$userid", '', array('pmo_user')))) {
     if (false === ($back = self::table(__CLASS__)->selectFirstObject('*', "pmo_uid={$userid}"))) {
         # , '', array('pmo_user')))) {
         return self::createPMOptions($user);
     }
     return $back;
 }
Example #12
0
 public function hasPermission(GWF_User $user)
 {
     if ($user->getID() === $this->getVar('hdt_uid')) {
         return true;
     }
     if ($user->isStaff() || $user->isAdmin()) {
         return true;
     }
     return false;
 }
Example #13
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 #14
0
 private static function installPMBot(Module_PM $module)
 {
     $user = new GWF_User(array('user_name' => '_GWF_PM_BOT_', 'user_password' => 'x', 'user_regdate' => GWF_Time::getDate(GWF_Date::LEN_SECOND), 'user_regip' => GWF_IP6::getIP(GWF_IP_EXACT, '127.0.0.1'), 'user_email' => GWF_BOT_EMAIL, 'user_birthdate' => GWF_Time::getDate(GWF_Time::LEN_DAY), 'user_countryid' => 0, 'user_langid' => 0, 'user_options' => GWF_User::BOT, 'user_lastactivity' => time()));
     if (false === $user->insert()) {
         return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
     }
     if (false === GWF_ModuleLoader::saveModuleVar($module, 'pm_bot_uid', $user->getID())) {
         return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
     }
     return '';
 }
Example #15
0
 public static function convert(GWF_User $user, $password)
 {
     if (false === ($row = self::table(__CLASS__)->getRow($user->getID()))) {
         return true;
     }
     $oldHash = self::oldHash($password);
     if ($oldHash !== $row->getVar('pmap_password')) {
         return GWF_Module::getModule('WeChall')->error('err_password');
     }
     $row->delete();
     $user->saveVar('user_password', GWF_Password::hashPasswordS($password));
     return true;
 }
Example #16
0
 private function onUnSubscribeExtThread($token)
 {
     if (false === $this->checkExternalToken($token)) {
         return $this->module->error('err_token');
     }
     if (!GWF_ForumSubscription::hasSubscribedManually($this->user, $this->thread->getID())) {
         return $this->module->error('err_sub_by_global');
     }
     if (false === GWF_ForumSubscription::unsubscribe($this->user->getID(), $this->thread->getID())) {
         return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
     }
     return $this->module->message('msg_unsubscribed', array($this->thread->getLastPageHREF()));
 }
Example #17
0
 private function profile(GWF_User $user)
 {
     if (false === ($profile = GWF_Profile::getProfile($user->getID()))) {
         return GWF_HTML::err('ERR_UNKNOWN_USER');
     }
     $watcher = GWF_User::getStaticOrGuest();
     if ($profile->isRobotHidden() && $watcher->isWebspider()) {
         return $this->module->error('err_no_spiders');
     }
     if (false === ($prof_view = GWF_Session::getOrDefault('prof_view', false))) {
         $prof_view = array();
     }
     $uid = $user->getID();
     if (!in_array($uid, $prof_view, true)) {
         $prof_view[] = $uid;
         if (false === $profile->increase('prof_views', 1)) {
             return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
         }
     }
     GWF_Session::set('prof_view', $prof_view);
     $tVars = array('user' => $user, 'profile' => $profile, 'jquery' => Common::getGet('ajax') !== false);
     return $this->module->templatePHP('profile.php', $tVars);
 }
Example #18
0
 /**
  * @todo create countUnread()
  * @param GWF_User $user
  * @param string $pattern
  * @param string $default
  * @return String
  */
 public static function getUnreadPM(GWF_User $user, $pattern = '[%s]', $default = '[0]')
 {
     if (false === self::loadModuleClass('PM', 'GWF_PM.php')) {
         return '';
     }
     if (false === $user->isGuest()) {
         $read = GWF_PM::READ;
         $userid = $user->getID();
         $count = GDO::table('GWF_PM')->countRows("pm_owner={$userid} AND pm_to={$userid} AND pm_options&{$read}=0");
         if ((int) $count > 0) {
             return sprintf($pattern, $count);
         }
     }
     return '';
 }
Example #19
0
 public static function addVotes(Slay_Song $song, GWF_User $user, array $tags)
 {
     $uid = $user->getID();
     $sid = $song->getID();
     $date = GWF_Time::getDate(GWF_Date::LEN_SECOND);
     $table = self::table(__CLASS__);
     foreach ($tags as $tag) {
         if (false === ($tid = Slay_Tag::getIDByName($tag))) {
             return false;
         }
         if (false === $table->insertAssoc(array('stv_uid' => $uid, 'stv_sid' => $sid, 'stv_tid' => $tid, 'stv_date' => $date), false)) {
             return false;
         }
     }
     return true;
 }
Example #20
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 #21
0
 private function onEditDeleteFlag($oldFlag, $newFlag)
 {
     $u = $this->user;
     if ($oldFlag === $newFlag) {
         return array();
     }
     if (false === $u->saveOption(GWF_User::DELETED, $newFlag)) {
         GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__), true, true);
         return array();
     }
     GWF_Hook::call(GWF_Hook::DELETE_USER, $u);
     if ($newFlag) {
         $uid = $this->user->getID();
         GDO::table('GWF_Session')->deleteWhere('sess_user='******'msg_deleted' : 'msg_undeleted';
     return array($this->module->lang($key));
 }
Example #22
0
 private function templateHistory(GWF_User $user)
 {
     require_once GWF_CORE_PATH . 'module/WeChall/WC_SiteDescr.php';
     require_once GWF_CORE_PATH . 'module/WeChall/WC_HistoryUser2.php';
     $uid = $user->getID();
     $ipp = 50;
     $history = GDO::table('WC_HistoryUser2');
     $nItems = $history->countRows("userhist_uid={$uid}");
     $nPages = GWF_PageMenu::getPagecount($ipp, $nItems);
     $page = Common::clamp(Common::getGet('page', 1), 1, $nPages);
     $from = GWF_PageMenu::getFrom($page, $ipp);
     $by = Common::getGet('by', '');
     $dir = Common::getGet('dir', '');
     $orderby = $history->getMultiOrderby($by, $dir);
     $uuname = $user->urlencode2('user_name');
     $duname = $user->displayUsername();
     GWF_Website::setPageTitle($this->module->lang('pt_texthis', array($duname)));
     GWF_Website::setMetaDescr($this->module->lang('md_texthis', array($duname)));
     GWF_Website::setMetaTags($this->module->lang('mt_texthis', array($duname)));
     $tVars = array('user' => $user, 'duname' => $duname, 'sites' => WC_Site::getSites('site_id'), 'data' => $history->selectObjects('*', "userhist_uid={$uid}", $orderby, $ipp, $from), 'sort_url' => GWF_WEB_ROOT . 'history/for/' . $uuname . '/by/%BY%/%DIR%/page-1', 'page_menu' => GWF_PageMenu::display($page, $nPages, GWF_WEB_ROOT . 'history/for/' . $uuname . '/by/' . urlencode($by) . '/' . urlencode($dir) . '/page-%PAGE%'));
     return $this->module->templatePHP('text_history.php', $tVars);
 }
Example #23
0
 public static function getLastAttemptTime(GWF_User $user)
 {
     return self::table(__CLASS__)->selectVar('MAX(wf_last_attempt)', 'wf_uid=' . $user->getID());
 }
Example #24
0
 private function getRequestLink(GWF_User $user)
 {
     $userid = $user->getID();
     require_once GWF_CORE_PATH . 'module/Account/GWF_AccountChange.php';
     if (false === ($token = GWF_AccountChange::createToken($userid, 'pass'))) {
         return 'ERR';
     }
     $url = Common::getAbsoluteURL(sprintf('change_password/%d/%s', $userid, $token));
     return sprintf('<a href="%s">%s</a>', $url, $url);
 }
Example #25
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();
 }
Example #26
0
 private static function fixWeChallUser(Module_WeChall $module)
 {
     if (false === ($user = GWF_User::getByName('WeChall'))) {
         $user = new GWF_User(array('user_name' => 'WeChall', 'user_email' => '*****@*****.**', 'user_password' => GWF_Password::hashPasswordS('wechallbot'), 'user_regdate' => GWF_Time::getDate(GWF_Date::LEN_SECOND), 'user_regip' => GWF_IP6::getIP(GWF_IP_EXACT, '127.0.0.1'), 'user_lastactivity' => time(), 'user_options' => GWF_User::BOT));
         if (false === $user->insert()) {
             echo GWF_HTML::error('WeChall Install', 'Can not find user WeChall');
             $uid = 0;
         } else {
             $uid = $user->getID();
         }
     } else {
         $uid = $user->getID();
     }
     if (false === $module->saveModuleVar('wc_uid', $uid)) {
         return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
     }
     return '';
 }
Example #27
0
 public function onVoteUser(GWF_User $user, array $chosen)
 {
     $pid = $this->getID();
     $uid = $user->getID();
     $choices = implode(':', $chosen);
     if (false !== ($row = GWF_VoteMultiRow::getVoteRowUser($pid, $uid))) {
         if (false === $this->onRevert($row)) {
             return false;
         }
         if (false === GDO::table('GWF_VoteMultiRow')->update("vmr_choices='{$choices}'", "vmr_vmid={$pid} AND vmr_uid={$uid}")) {
             return false;
         }
         if (count($chosen) > 0) {
             if (false === $this->onApply($chosen)) {
                 return false;
             }
         }
     } elseif (count($chosen) > 0) {
         $row = new GWF_VoteMultiRow(array('vmr_vmid' => $pid, 'vmr_uid' => $uid, 'vmr_ip' => 'NULL', 'vmr_time' => time(), 'vmr_choices' => $choices));
         if (false === $row->insert()) {
             return false;
         }
         if (false === $this->onApply($chosen)) {
             return false;
         }
     }
     return true;
 }
Example #28
0
 public static function hookDeleteUser(GWF_User $user)
 {
     return GDO::table(__CLASS__)->update('page_author=0, page_author_name=""', 'page_author=' . $user->getID());
 }
Example #29
0
 /**
  * @param GWF_User $user
  * @return BAIM_MC
  */
 public static function generate(GWF_User $user, $demo = false)
 {
     $userid = $user->getID();
     if (false === ($row = self::getByUID($userid))) {
         return self::createMCRow($userid, $demo);
     }
     if ($row->isDeleted()) {
         return false;
     }
     if ($demo === false) {
         if (false === $row->saveOption(self::DEMO, $demo)) {
             return false;
         }
     }
     return $row;
 }
Example #30
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;
 }