Пример #1
0
 /**
  * 
  */
 public function beforeSave()
 {
     if ($this->getIsNewRecord()) {
         // Assign the user_id 1 if is a guest
         ///TODO:add userid. Issue, cant make use of user component while other request is open(subject/fetch)		$this->user_id=(Yii::app()->user->getId()) ? Yii::app()->user->getId() : 1;
         $this->user_id = 0;
         //$this->time = SiteLibrary::utc_time();
         $this->user_ip = $_SERVER['REMOTE_ADDR'];
         $country_id = 1;
         $country_code = 'WW';
         if ($_SERVER['REMOTE_ADDR'] != '127.0.0.1') {
             Yii::import('ext.EGeoIP');
             $geoIp = new EGeoIP();
             $geoIp->locate($_SERVER['REMOTE_ADDR']);
             //http://www.iso.org/iso/english_country_names_and_code_elements
             $country = Country::model()->find('code=:code', array(':code' => $geoIp->countryCode));
             if ($country) {
                 $country_id = $country->id;
                 $country_code = $country->code;
             }
         }
         $this->country_id = $country_id;
         $this->time = SiteLibrary::utc_time();
         $this->user_id = Yii::app()->user->id;
     }
     return true;
 }
Пример #2
0
 public static function setLanguage($cookieDays = 180)
 {
     if (Yii::app()->request->getPost('languageSelector') !== null && in_array($_POST['languageSelector'], self::getLanguagesList(), true)) {
         Yii::app()->setLanguage($_POST['languageSelector']);
         $cookie = new CHttpCookie('language', $_POST['languageSelector']);
         $cookie->expire = time() + 60 * 60 * 24 * $cookieDays;
         Yii::app()->request->cookies['language'] = $cookie;
     } else {
         if (isset(Yii::app()->request->cookies['language']) && in_array(Yii::app()->request->cookies['language']->value, self::getLanguagesList(), true)) {
             Yii::app()->setLanguage(Yii::app()->request->cookies['language']->value);
         } else {
             if (isset(Yii::app()->request->cookies['language'])) {
                 // Invalid language
                 unset(Yii::app()->request->cookies['language']);
             } else {
                 Yii::import('ext.EGeoIP');
                 try {
                     $geoIp = new EGeoIP();
                     $geoIp->locate();
                     $countryCode = strtolower($geoIp->getCountryCode());
                     if (!in_array($countryCode, self::getLanguagesList(), true)) {
                         return;
                     }
                     Yii::app()->setLanguage($countryCode);
                     $cookie = new CHttpCookie('language', $countryCode);
                     $cookie->expire = time() + 60 * 60 * 24 * $cookieDays;
                     Yii::app()->request->cookies['language'] = $cookie;
                 } catch (Exception $exception) {
                     Yii::log($exception->__toString(), 'error', 'app.widgets.languageSelector');
                 }
             }
         }
     }
 }
Пример #3
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionRegister($sh = '', $t = '')
 {
     $this->model = new User('register');
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($this->model);
     if (isset($_POST['User'])) {
         $country_id = 1;
         if ($_SERVER['REMOTE_ADDR'] != '127.0.0.1') {
             Yii::import('ext.EGeoIP');
             $geoIp = new EGeoIP();
             $geoIp->locate($_SERVER['REMOTE_ADDR']);
             //http://www.iso.org/iso/english_country_names_and_code_elements
             $country = Country::model()->find('code=:code', array(':code' => $geoIp->countryCode));
             if ($country) {
                 $country_id = $country->id;
             }
         }
         $this->model->time_created = SiteLibrary::utc_time();
         $this->model->ip_created = $_SERVER['REMOTE_ADDR'];
         $this->model->country_id = $country_id;
         $this->model->country_id_created = $country_id;
         $this->model->attributes = $_POST['User'];
         if ($this->model->save()) {
             if ($sh and $t) {
                 //Allow asignment only within 15 minutes since subject added
                 if (SiteLibrary::utc_time() - $t < 900) {
                     Subject::model()->updateAll(array('user_id' => $this->model->id), 'time_submitted=:time_submitted AND hash=:hash', array(':time_submitted' => $t, ':hash' => $sh));
                 }
             }
             $mail_message = Yii::t('user', "Hi {username}, welcome to samesub!\n\nUsername:  {username}\nEmail: {email}\n\nThanks for registering.\n\nRemember that our mission:\nIs that there be a unique point of union on the internet where all users connected\nto it can interact with one 'Same Subject' synchronously, giving an impact in the way we stay in touch\nwith the world, a way in which everybody adapts to one thing in common, a subject in common:\nSamesub\n\nKnow that you can always help us to achive this goal in any of one of these ways:\nWith your visits.\nSharing to your friends.\nWith your submission of content.\nWith your code contribution.\n\nIf you want to become a moderator, authorizer, or help the samesub team in any way, please write to us\nwith the email you registered from.", array('{username}' => $this->model->username, '{email}' => $this->model->email));
             $mail_message .= "\n\n";
             $mail_message .= Yii::t('site', "Thanks\nSincerely\nSamesub Team\nwww.samesub.com");
             if (SiteLibrary::send_email($this->model->email, Yii::t('user', "Registration successful"), $mail_message)) {
                 $mail_sent = Yii::t('user', "An email has been sent to you.");
             } else {
                 $mail_sent = Yii::t('user', "Email could not be sent.");
             }
             $model2 = new LoginForm();
             $model2->username = $this->model->email;
             $model2->password = $_POST['User']['password'];
             // validate user input and redirect to the previous page if valid
             if ($model2->validate() && $model2->login()) {
                 Yii::app()->user->setFlash('layout_flash_success', Yii::t('user', 'Registration has been completed successfully. {mail_sent} You may now optionally add more information to your profile.', array('{mail_sent}' => $mail_sent)));
                 $this->redirect(array('update'));
             }
         } else {
             //Set back the password to its original as the view will receive it hashed
             $this->model->password = $_POST['User']['password'];
         }
     }
     $this->render('register', array('model' => $this->model, 'sh' => $sh, 't' => $t));
 }
Пример #4
0
 public function get_country_from_ip($ip = '')
 {
     if (!$ip) {
         $ip = $_SERVER['REMOTE_ADDR'];
     }
     Yii::import('ext.EGeoIP');
     $geoIp = new EGeoIP();
     $geoIp->locate($ip);
     //http://www.iso.org/iso/english_country_names_and_code_elements
     $country = Country::model()->find('code=:code', array(':code' => $geoIp->countryCode));
     if ($country) {
         return $country;
     } else {
         return false;
     }
 }
Пример #5
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionAdd()
 {
     if (Yii::app()->user->userModel->relProfile->use_multi_upload) {
         $model = new Holes('add');
     } else {
         $model = new Holes();
     }
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     $cs = Yii::app()->getClientScript();
     $cs->registerCssFile('/css/add_form.css');
     if (isset($_POST['Holes'])) {
         $model->attributes = $_POST['Holes'];
         $model->USER_ID = Yii::app()->user->id;
         $model->DATE_CREATED = time();
         $model->ADR_CITY = trim($model->ADR_CITY);
         if (Yii::app()->user->level > 50 || !$model->upploadedPictures) {
             $model->PREMODERATED = 1;
         } else {
             $model->PREMODERATED = 0;
         }
         if ($model->gibdd_id) {
             $subj = $model->gibdd->subject->id;
             if ($subj) {
                 $model->ADR_SUBJECTRF = $subj;
             }
         } else {
             $subj = RfSubjects::model()->SearchID(trim($model->STR_SUBJECTRF));
             if ($subj) {
                 $model->ADR_SUBJECTRF = $subj;
             } else {
                 $model->ADR_SUBJECTRF = 0;
             }
         }
         if ($model->save() && $model->savePictures()) {
             $this->redirect(array('view', 'id' => $model->ID, 'fromadd' => true));
         }
     } else {
         //выставляем центр на карте по координатам IP юзера
         $request = new CHttpRequest();
         $geoIp = new EGeoIP();
         $geoIp->locate($request->userHostAddress);
         //echo ($request->userHostAddress);
         if ($geoIp->longitude) {
             $model->LONGITUDE = $geoIp->longitude;
         }
         if ($geoIp->latitude) {
             $model->LATITUDE = $geoIp->latitude;
         }
     }
     $this->flushUploadDir();
     $this->render('add', array('model' => $model));
 }
Пример #6
0
 public function actionMap()
 {
     $this->layout = '//layouts/header_blank';
     $model = new Holes('search');
     $model->unsetAttributes();
     // clear any default values
     if (isset($_POST['Holes'])) {
         $model->attributes = $_POST['Holes'];
     }
     if ($model->ADR_CITY == "Город") {
         $model->ADR_CITY = '';
     }
     $hole = new Holes();
     //выставляем центр на карте по координатам IP юзера
     $request = new CHttpRequest();
     $geoIp = new EGeoIP();
     $geoIp->locate($request->userHostAddress);
     //echo ($request->userHostAddress);
     if ($geoIp->longitude) {
         $hole->LATITUDE = $geoIp->longitude;
     }
     if ($geoIp->latitude) {
         $hole->LONGITUDE = $geoIp->latitude;
     }
     $this->render('map', array('model' => $model, 'hole' => $hole, 'types' => HoleTypes::model()->findAll(array('condition' => 't.published=1 and t.lang="ua"'))));
 }
Пример #7
0
 public function actionmoneda()
 {
     Yii::import('ext.EGeoIP');
     $geoIp = new EGeoIP();
     $geoIp->locate(yii::app()->request->userHostAddress);
     // use your IP
     echo 'Information regarding IP: <b>' . $geoIp->ip . '</b><br/>';
     echo 'City: ' . $geoIp->city . '<br>';
     echo 'Region: ' . $geoIp->region . '<br>';
     echo 'Area Code: ' . $geoIp->areaCode . '<br>';
     echo 'DMA: ' . $geoIp->dma . '<br>';
     echo 'Country Code: ' . $geoIp->countryCode . '<br>';
     echo 'Country Name: ' . $geoIp->countryName . '<br>';
     echo 'Continent Code: ' . $geoIp->continentCode . '<br>';
     echo 'Latitude: ' . $geoIp->latitude . '<br>';
     echo 'Longitude: ' . $geoIp->longitude . '<br>';
     echo 'Currency Symbol: ' . $geoIp->currencySymbol . '<br>';
     echo 'Currency Code: ' . $geoIp->currencyCode . '<br>';
     echo 'Currency Converter: ' . $geoIp->currencyConverter . '<br/>';
     echo 'Converting $10.00 to ' . $geoIp->currencyCode . ': <b>' . $geoIp->currencyConvert(10) . '</b><br/>';
 }
Пример #8
0
 /**
  * Updates particular fields of a subject submitted by a user.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id the ID of the model to be updated
  */
 public function actionAuthorize($id)
 {
     if (Yii::app()->user->checkAccess('subject_authorize')) {
         $this->model = $this->loadModel($id);
         $this->model->scenario = 'authorize';
         // Uncomment the following line if AJAX validation is needed
         // $this->performAjaxValidation($this->model);
         if (isset($_POST['Subject'])) {
             $this->model->attributes = $_POST['Subject'];
             Yii::import('ext.EGeoIP');
             $geoIp = new EGeoIP();
             $geoIp->locate($_SERVER['REMOTE_ADDR']);
             //http://www.iso.org/iso/english_country_names_and_code_elements
             $country = Country::model()->find('code=:code', array(':code' => $geoIp->countryCode));
             $this->model->authorizer_country_id = $country->id;
             if ($this->model->save()) {
                 $user = User::model()->findByPk($this->model->user_id);
                 if ($user->notify_subject_authorized) {
                     $mail_message = Yii::t('subject', "Hi {username} \nThis is a automatic message to notify that your subject has been authorized.\nThat means it is going to get LIVE(homepage) very soon, so be alert.\nDetails\nSubject Title: {title}\nUploaded time: {uploaded_time} UTC\nCurrent time: {current_time} UTC (time of this message)\nNOTE: This message is supposed be received only by the uploader user. If you\nare not the uploader of this subject please notify us by replaying to this mail.", array('{username}' => $user->username, '{title}' => $this->model->title, '{uploaded_time}' => date("Y/m/d H:i", $this->model->time_submitted), '{current_time}' => date("Y/m/d H:i", SiteLibrary::utc_time())));
                     $mail_message .= "\n\n";
                     $mail_message .= Yii::t('site', "Thanks\nSincerely\nSamesub Team\nwww.samesub.com");
                     SiteLibrary::send_email($user->email, Yii::t('subject', "Subject Authorized"), $mail_message);
                 }
                 $this->redirect(array('manage'));
             }
         }
         $this->render('authorize', array('model' => $this->model));
     } else {
         throw new CHttpException(403, Yii::t('subject', 'You are not allowed to authorize this subject.'));
     }
 }
 public function getFlagImageLabel()
 {
     Yii::import('ext.EGeoIP.*');
     $imagePath = "";
     $geoIp = new EGeoIP();
     $countryLabel = "";
     $geoIp->locate($this->ip_address);
     $baseUrl = Yii::app()->theme->baseUrl;
     $imagePath .= $baseUrl . "/img/countries/" . strtolower($geoIp->countryCode) . "_16.png";
     $countryLabel .= " " . CHtml::image($imagePath, $geoIp->countryName);
     return $countryLabel . " " . $geoIp->countryName;
 }