Beispiel #1
0
 public static function onActivate(Module_Register $module, $token, $byEmail)
 {
     $ua = GDO::table('GWF_UserActivation');
     if (false === ($row = $ua->getBy('token', $token))) {
         return $module->error('err_activate');
     }
     if ($module->hasIPActivatedRecently()) {
         return $module->error('err_ip_timeout');
     }
     $options = $byEmail === true ? GWF_User::MAIL_APPROVED : 0;
     $username = $row->getVar('username');
     $countryid = $row->getVar('countryid');
     $user = new GWF_User(array('user_id' => 0, 'user_options' => $options, 'user_name' => $username, 'user_password' => $row->getVar('password'), 'user_regdate' => GWF_Time::getDate(GWF_Date::LEN_SECOND), 'user_regip' => $row->getVar('ip'), 'user_email' => $row->getVar('email'), 'user_gender' => 'no_gender', 'user_lastlogin' => 0, 'user_lastactivity' => time(), 'user_birthdate' => $row->getVar('birthdate'), 'user_avatar_v' => 0, 'user_countryid' => $countryid, 'user_langid' => GWF_LangMap::getPrimaryLangID($countryid), 'user_langid2' => 0, 'user_level' => 0, 'user_title' => '', 'user_settings' => '', 'user_data' => '', 'user_credits' => '0.00'));
     if (false === $user->insert()) {
         return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
     }
     if (false === $ua->deleteWhere(sprintf('username=\'%s\'', $username))) {
         return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
     }
     return self::onActivated($module, $user);
 }
Beispiel #2
0
 public static function getCountryID()
 {
     return GWF_LangMap::getPrimaryCountryID(self::getLanguageID());
 }
Beispiel #3
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;
 }