コード例 #1
0
ファイル: Form.php プロジェクト: sinfocol/gwf3
 private function onRegister()
 {
     $form = $this->getForm();
     $errorsA = $errorsB = '';
     if (false !== ($errorsA = $form->validate($this->module)) || false !== ($errorsB = $this->onRegisterB())) {
         return $errorsA . $errorsB . $this->templateForm();
     }
     $username = Common::getPost('username');
     $password = Common::getPost('password');
     $email = Common::getPost('email');
     $birthdate = sprintf('%04d%02d%02d', Common::getPost('birthdatey'), Common::getPost('birthdatem'), Common::getPost('birthdated'));
     $default_country = $this->module->cfgDetectCountry() ? GWF_IP2Country::detectCountryID() : 0;
     $countryid = $form->getVar('countryid', $default_country);
     require_once GWF_CORE_PATH . 'module/Register/GWF_UserActivation.php';
     $token = GWF_UserActivation::generateToken();
     $ua = new GWF_UserActivation(array('username' => $username, 'email' => $email, 'token' => $token, 'birthdate' => $birthdate, 'countryid' => $countryid, 'password' => GWF_Password::hashPasswordS($password), 'timestamp' => time(), 'ip' => GWF_IP6::getIP(GWF_IP_EXACT)));
     if (false === $ua->insert()) {
         return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)) . $this->templateForm();
     }
     if ($this->module->wantEmailActivation()) {
         return $this->sendEmail($username, $email, $token, $password);
     } else {
         GWF_Website::redirect(GWF_WEB_ROOT . 'quick_activate/' . $token);
     }
     return $this->module->message('msg_registered');
 }
コード例 #2
0
ファイル: RankingCountry.php プロジェクト: sinfocol/gwf3
 private function getHighlightCountry()
 {
     if (false === ($user = GWF_Session::getUser()) || '0' === ($cid = $user->getVar('user_countryid'))) {
         return GWF_IP2Country::detectCountryID();
     } else {
         return $cid;
     }
 }
コード例 #3
0
ファイル: GWF_IP2Country.php プロジェクト: sinfocol/gwf3
 public static function detectCountryID()
 {
     if (self::$detectedCountry === true) {
         $ip = GWF_IP6::getIP(GWF_IP6::UINT_32);
         self::$detectedCountry = self::table(__CLASS__)->selectVar('ip2c_cid', "ip2c_start<='{$ip}' AND ip2c_end>='{$ip}'");
     }
     return self::$detectedCountry;
 }
コード例 #4
0
ファイル: GWF_ClientInfo.php プロジェクト: sinfocol/gwf3
 public static function getCountryByIP()
 {
     return GWF_IP2Country::detectCountry();
 }
コード例 #5
0
 /**
  * Takes ages.
  * @return string
  * @todo integrate in design but do flushing and error handling
  */
 public static function createLanguage($__langs = true, $__cunts = true, $__ipmap = false)
 {
     $success = true;
     require_once GWF_CORE_PATH . 'inc/install/data/GWF_LanguageData.php';
     set_time_limit(0);
     # This function takes ages!
     $cache = array();
     $cache2 = array();
     # Language
     $i = 1;
     $linguas = GWF_LanguageData::getLanguages();
     $ret = 'Installing ' . count($linguas) . ' Languages';
     //	flush();
     $lang_t = new GWF_Language();
     $supported = explode(';', GWF_SUPPORTED_LANGS);
     foreach ($linguas as $lang) {
         //		$ret .= '.';
         //		flush();
         array_map('trim', $lang);
         list($name, $native, $short, $iso) = $lang;
         if (false !== ($langrow = $lang_t->selectFirst('lang_id', "lang_short='{$short}'"))) {
             #GWF_Language::getByShort($short))) {
             $cache[$short] = $langrow['lang_id'];
             #->getID();
             continue;
         }
         if ($__langs) {
             if (false === $lang_t->insertAssoc(array('lang_id' => $i, 'lang_name' => $name, 'lang_nativename' => $native, 'lang_short' => $short, 'lang_iso' => $iso, 'lang_options' => in_array($iso, $supported, true) ? GWF_Language::SUPPORTED : 0))) {
                 $ret .= GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
                 $success = false;
                 continue;
             }
         }
         $i++;
         $cache[$short] = $i;
         #langrow['lang_id'];
     }
     $ret .= PHP_EOL;
     # Country and Langmap
     $countries = GWF_LanguageData::getCountries();
     $country_t = new GWF_Country();
     $ret .= 'Installing ' . count($countries) . ' Countries';
     //	flush();
     foreach ($countries as $cid => $c) {
         //		$ret .= '.';
         //		flush();
         if (count($c) !== 5) {
             $ret .= GWF_HTML::error('Country error', sprintf('%s has error.', $c[0]), true, true);
         }
         array_map('trim', $c);
         list($name, $langs, $region, $tld, $pop) = $c;
         $tld = strtolower($tld);
         if ($__cunts) {
             if (false === $country_t->insertAssoc(array('country_id' => $cid, 'country_name' => $name, 'country_tld' => $tld, 'country_pop' => $pop))) {
                 $ret .= GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__), true, true);
                 $success = false;
                 continue;
             }
         }
         $cache2[$tld] = $cid;
         $langmap_t = new GWF_LangMap();
         if ($__cunts) {
             $langs = explode(':', $langs);
             foreach ($langs as $langshort) {
                 if (!isset($cache[$langshort])) {
                     $ret .= GWF_HTML::error('', 'Unknown iso-3: ' . $langshort . ' in country ' . $name, true, true);
                     $success = false;
                     $ret .= GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__), true, true);
                     continue;
                 }
                 $langid = $cache[$langshort];
                 if (false === $langmap_t->insertAssoc(array('langmap_cid' => $cid, 'langmap_lid' => $langid))) {
                     $ret .= GWF_HTML::err('ERR_DATABASE', array(array(__FILE__, __LINE__)), true, true);
                     $success = false;
                     continue;
                 }
             }
         }
     }
     $ret .= PHP_EOL;
     if (!$__ipmap) {
         //		return $success;
         return $ret;
     }
     $ret .= 'Installing ip2country' . PHP_EOL;
     # IP2Country
     $max = 89323;
     $now = 0;
     $filename = GWF_CORE_PATH . "inc/install/data/ip-to-country.csv";
     if (false === ($fp = fopen($filename, "r"))) {
         $ret .= GWF_HTML::err('ERR_FILE_NOT_FOUND', array($filename), true, true);
         //		return false;
         return $ret;
     }
     $ip2c = new GWF_IP2Country();
     while (false !== ($line = fgetcsv($fp, 2048))) {
         if (count($line) !== 5) {
             $ret .= GWF_HTML::error('', $filename . ' is corrupt!', true, true);
             $success = false;
             break;
         }
         list($ipstart, $ipend, $tld, $ccode2, $cname) = $line;
         $tld = strtolower($tld);
         if (!isset($cache2[$tld])) {
             $ret .= GWF_HTML::error('', 'Unknown TLD: ' . $tld, true, true);
             $ret .= GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__), true, true);
             $success = false;
             continue;
         }
         if (false === $ip2c->insertAssoc(array('ip2c_start' => $ipstart, 'ip2c_end' => $ipend, 'ip2c_cid' => $cache2[$tld]))) {
             $ret .= GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__), true, true);
             $success = false;
             continue;
         }
         $now++;
         if (!($now % 2500)) {
             $msg = sprintf('%d of %d...', $now, $max);
             $ret .= GWF_HTML::message('Progress', $msg, true, true);
             //			flush();
         }
     }
     return $ret;
 }