/** * Displays the contact page */ public function actionContact() { $this->model = new ContactForm(); if (isset($_POST['ContactForm'])) { $this->model->attributes = $_POST['ContactForm']; if ($this->model->validate()) { if ($this->model->email) { SiteLibrary::send_email(Yii::app()->params['contactEmail'], "SSCONTACT " . SiteLibrary::utc_time(), $this->model->text, $this->model->email); } else { SiteLibrary::send_email(Yii::app()->params['contactEmail'], "SSCONTACT " . SiteLibrary::utc_time(), $this->model->text); } Yii::app()->user->setFlash('contact', Yii::t('site', 'Thank you for contacting us. If you provided an email we will respond to you as soon as possible.')); } } $this->render('contact', array('model' => $this->model)); }
/** * Forgot password option. */ public function actionResetPassword() { $this->model = new User('resetpassword'); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($this->model); $this->model->unsetAttributes(); // clear any default values if (isset($_POST['User'])) { $this->model->attributes = $_POST['User']; if ($this->model->validate()) { if (!($model2 = User::model()->find('username=:username OR email=:email', array(':username' => $this->model->username, ':email' => $this->model->email)))) { $this->model->addError('username, email', Yii::t('user', 'The username or email was not found in our database.')); } else { $this->model = $model2; //to be able to log model id $this->model->reset_hash = md5(uniqid(rand(), true)); $this->model->reset_time = SiteLibrary::utc_time(); //Set up the mail message $mail_message = Yii::t('user', "Hi {username}!\n\t\t\t\t\tWe recently received a request to reset your password.\n\t\t\t\t\tIf you did not request this, please ignore this message and the steps described in it.\n\t\t\t\t\tUsername: {username}\n\t\t\t\t\tEmail: {email}\n\t\t\t\t\tTo reset your password please click or visit the link bellow and complete the steps \n\t\t\t\t\tdescribed there.\n\t\t\t\t\t{url}", array('{username}' => $this->model->username, '{email}' => $this->model->email, '{url}' => Yii::app()->getRequest()->getBaseUrl(true) . "/user/resetpasswordnext?reset_hash=" . $this->model->reset_hash)); $mail_message .= "\n\n"; $mail_message .= Yii::t('site', "Thanks\nSincerely\nSamesub Team\nwww.samesub.com"); if ($this->model->save()) { //User::model()->updateByPk($model2->id, array('reset_hash'=>md5(rand(100,9000)),'reset_time'=>SiteLibrary::utc_time())); if (SiteLibrary::send_email($this->model->email, "Password Reset", $mail_message)) { Yii::app()->user->setFlash('resetpassword_success', Yii::t('user', 'An email has been sent to your address ***{email} with the link to reset your password. Please verify your email spam folder if you do not see the message.', array('{email}' => substr($model2->email, 3)))); } else { Yii::app()->user->setFlash('resetpassword_success', Yii::t('user', 'Ooops!. We could not sent an email to your address. We need to send an email to your address to reset your password automatically. Please contact us to request a password reset manually.')); } } } } } $this->render('resetpassword', array('model' => $this->model)); }
/** * 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.')); } }
/** * This is a cron that sets the next subject to be showed * and the next subject to be cached(subject_id and subject_id_2) * */ public function actionSetNextSubject() { if ($_SERVER['REMOTE_ADDR'] != '127.0.0.1') { die; } //Only allow to run this locally $command = Yii::app()->db->createCommand(); //If the table its empty by any reason(initial import), insert something to make the UPDATE work if (!$command->select('count(*) as num')->from('live_subject')->queryScalar()) { $command->insert('live_subject', array('subject_id' => 0, 'subject_id_2' => 0)); } //Position all subs on its time Subject::reschedule_positions(); $round_utc_time = SiteLibrary::utc_time_interval(); //Remote case: This update is just in case cron didn't run in x times of interva(s) //This frees up subs that never were used because they were fixed position but cron failed to run and time passed by Subject::model()->updateAll(array('position' => '0', 'user_position' => '0', 'manager_position' => '0'), 'position < ' . $round_utc_time . ' AND user_position < ' . $round_utc_time . ' AND manager_position < ' . $round_utc_time); $subject = Subject::model()->find(array('condition' => 'position >= ' . $round_utc_time . ' AND content_type_id <> 2 AND approved=1 AND authorized=1 AND disabled=0 AND deleted=0', 'order' => 'position ASC')); $live_subject = Yii::app()->db->createCommand()->select('*')->from('live_subject')->queryRow(); $command->delete('live_comment'); $command->update('live_subject', array('comment_id' => 0, 'comment_number' => 0)); //TEMPORAL:Refill the live_comments table with old comments about this subject if this subject is repeated $past_comments = Yii::app()->db->createCommand()->select('t1.id,code,time,comment,comment_number,username,likes,dislikes')->from('comment t1')->where('subject_id =' . $subject->id)->leftJoin('country t2', 'country_id=t2.id')->leftJoin('user t3', 'user_id=t3.id')->order('time ASC')->queryAll(); echo "<br>gggg"; print_r($past_comments); $i = 0; foreach ($past_comments as $past_comment) { $i++; $country_code = $past_comment['code'] ? $past_comment['code'] : "WW"; $command->insert('live_comment', array('comment_id' => $past_comment['id'], 'username' => $past_comment['username'], 'subject_id' => $subject->id, 'comment_country' => $country_code, 'comment_time' => $past_comment['time'], 'comment_text' => $past_comment['comment'], 'comment_number' => $i, 'likes' => $past_comment['likes'], 'dislikes' => $past_comment['dislikes'])); //we neet to use our own sequence because there might be repeated numbers $comment_id = $past_comment['id']; } if ($i > 0) { $command->update('live_subject', array('comment_id' => $comment_id, 'comment_number' => $i)); } $command->update('live_subject', array('subject_id' => $subject->id, 'scheduled_time' => SiteLibrary::utc_time_interval(), 'subject_data' => serialize($subject))); //Reset position as subject is going to live now Subject::model()->updateByPk($subject->id, array('show_time' => SiteLibrary::utc_time(), 'user_position' => 0, 'manager_position' => 0)); //Notify subject owner via email that his subject its gonna get LIVE $user = User::model()->findByPk($subject->user_id); if ($user->id != 1 and $user->notify_subject_live == 1) { $mail_message = Yii::t('subject', "Hi {username}, \nWe are writing to notify you that your subject got approved and that it is\ngoing to be placed in the live stream(Homepage) in the next 5 minutes.\nDetails\nSubject Title: {title}\nUploaded time: {uploaded_time} UTC\nCurrent time: {current_time} UTC (time of this message)\nEstimated time: {estimated_time} UTC (about 5 minutes)\nIt is even more cool if you chat with your friends about your upcomming subject.\nSo, invite them to go to samesub.com now, you still have 4 minutes.\nIf you do not want to receive this type of notification you can update the settings in\nyour user profile anytime you want.", array('{username}' => $user->username, '{title}' => $subject->title, '{uploaded_time}' => date("Y/m/d H:i", $subject->time_submitted), '{current_time}' => date("Y/m/d H:i", SiteLibrary::utc_time()), '{estimated_time}' => date("Y/m/d H:i", SiteLibrary::utc_time() + 300))); $mail_message .= "\n\n"; $mail_message .= Yii::t('site', "Thanks\nSincerely\nSamesub Team\nwww.samesub.com"); if (SiteLibrary::send_email($user->email, "Your subject is going LIVE", $mail_message)) { echo "An email has been sent."; } else { echo "Email could not be sent."; } } echo 'Done setting next subject_id_2 : ' . $subject->id; //There are some pages that need to be refreshed from the cache such as /subject/index, so that it content reflects the updated data. $optional_prefix = "index.php"; $cmd = Yii::app()->params['cache_refresher'] . ' "' . $optional_prefix . '/subject/index' . '"'; if (Yii::app()->params['cache_refresher']) { exec($cmd); } }
/** * Saves a comments in database and do subsequent related operations. */ public function save_comment($model) { $live_subject = Yii::app()->db->createCommand()->select('subject_id, (comment_number+1)as next_sequence')->from('live_subject')->queryRow(); $model->comment_number = $live_subject['next_sequence']; $model->subject_id = $live_subject['subject_id']; if ($model->save()) { if ($model->update_live) { Yii::app()->db->createCommand()->insert('live_comment', array('comment_id' => $model->id, 'comment_number' => $model->comment_number, 'subject_id' => $model->subject_id, 'comment_text' => $model->comment, 'comment_time' => $model->time, 'comment_country' => $model->country->code, 'username' => Yii::app()->user->isGuest ? 'guest' : Yii::app()->user->name)); Yii::app()->db->createCommand()->update('live_subject', array('comment_id' => $model->id, 'comment_number' => $model->comment_number)); } $send_mail = true; if (!Yii::app()->user->isGuest) { $user = User::model()->findByPk(Yii::app()->user->id); if ($user->user_type_id > 2) { $send_mail = false; } //Dont notify managers themself } $last_one = Comment::model()->find(array('limit' => 2, 'offset' => 1, 'order' => 't.id DESC')); //offset is 0 based if (SiteLibrary::utc_time() < $last_one->time + 1500) { $send_mail = false; } if ($send_mail) { $mail_message .= "User: "******"\n"; $mail_message .= "Comment: {$model->comment}\n"; $mail_message .= "Current time: " . date("Y/m/d H:i", SiteLibrary::utc_time()) . " UTC (time of this message)\n\n"; $mail_message .= "www.samesub.com"; SiteLibrary::send_email(Yii::app()->params['contactEmail'], "Comment " . $model->id, $mail_message); } return true; } else { return false; } }