Exemplo n.º 1
0
 public function action_userprofile_contact()
 {
     $user_to = new Model_User($this->request->param('id'));
     //message to user
     if ($user_to->loaded() and $this->request->post()) {
         if (captcha::check('contact')) {
             //check if user is loged in
             if (Auth::instance()->logged_in()) {
                 $email_from = Auth::instance()->get_user()->email;
                 $name_from = Auth::instance()->get_user()->name;
             } else {
                 $email_from = core::post('email');
                 $name_from = core::post('name');
             }
             //require login to contact
             if (core::config('general.messaging') == TRUE and !Auth::instance()->logged_in()) {
                 Alert::set(Alert::INFO, __('Please, login before contacting'));
                 HTTP::redirect(Route::url('oc-panel'));
             }
             //akismet spam filter
             if (!core::akismet($name_from, $email_from, core::post('message'))) {
                 if (core::config('general.messaging')) {
                     $ret = Model_Message::send_user(core::post('message'), $this->user, $user_to);
                 } else {
                     $ret = $user_to->email('user-profile-contact', array('[EMAIL.BODY]' => core::post('message'), '[EMAIL.SENDER]' => $name_from, '[EMAIL.SUBJECT]' => core::post('subject'), '[EMAIL.FROM]' => $email_from), $email_from, $name_from);
                 }
                 //if succesfully sent
                 if ($ret) {
                     Alert::set(Alert::SUCCESS, __('Your message has been sent'));
                 } else {
                     Alert::set(Alert::ERROR, __('Message not sent'));
                 }
             } else {
                 Alert::set(Alert::SUCCESS, __('This email has been considered as spam! We are sorry but we can not send this email.'));
             }
         } else {
             Alert::set(Alert::ERROR, __('Captcha is not correct'));
         }
         HTTP::redirect(Route::url('profile', array('seoname' => $user_to->seoname)));
     }
 }
 /**
  * Handle POST requests for messages
  */
 public function action_create()
 {
     try {
         $user = $this->user;
         //get message
         if (isset($this->_post_params['message'])) {
             $message = $this->_post_params['message'];
         } else {
             $this->_error(__('Message not sent'));
         }
         //price?
         $price = (isset($this->_post_params['price']) and is_numeric($this->_post_params['price'])) ? $this->_post_params['price'] : NULL;
         //message to the user
         if (isset($this->_post_params['id_user']) and is_numeric($id_user_to = $this->_post_params['id_user'])) {
             $ret = Model_Message::send_user($message, $user->id_user, $id_user_to);
         } elseif (isset($this->_post_params['id_ad']) and is_numeric($id_ad = $this->_post_params['id_ad'])) {
             $ret = Model_Message::send_ad($message, $user->id_user, $id_ad, $price);
         } elseif (isset($this->_post_params['id_message_parent']) and is_numeric($id_message_parent = $this->_post_params['id_message_parent'])) {
             $ret = Model_Message::reply($message, $user->id_user, $id_message_parent, $price);
         }
         //good response!
         if ($ret !== FALSE) {
             $this->rest_output(array('message' => $ret->as_array()));
         } else {
             $this->_error(__('Message not sent'));
         }
     } catch (Kohana_HTTP_Exception $khe) {
         $this->_error($khe);
     }
 }
 public function action_userprofile_contact()
 {
     $user = new Model_User($this->request->param('id'));
     //message to user
     if ($user->loaded() and $this->request->post()) {
         if (captcha::check('contact')) {
             //check if user is loged in
             if (Auth::instance()->logged_in()) {
                 $email_from = Auth::instance()->get_user()->email;
                 $name_from = Auth::instance()->get_user()->name;
             } else {
                 $email_from = core::post('email');
                 $name_from = core::post('name');
             }
             //akismet spam filter
             if (!core::akismet($name_from, $email_from, core::post('message'))) {
                 if (core::config('general.messaging')) {
                     $ret = Model_Message::send_user(core::post('message'), $this->user->id_user, $user->id_user);
                     if ($ret !== FALSE) {
                         $user->email('messaging-user-contact', array('[FROM.NAME]' => $this->user->name, '[TO.NAME]' => $user->name, '[DESCRIPTION]' => core::post('message'), '[URL.QL]' => $user->ql('oc-panel', array('controller' => 'messages', 'action' => 'message', 'id' => $ret->id_message))));
                     }
                 } else {
                     $ret = $user->email('user-profile-contact', array('[EMAIL.BODY]' => core::post('message'), '[EMAIL.SENDER]' => $name_from, '[EMAIL.SUBJECT]' => core::post('subject'), '[EMAIL.FROM]' => $email_from), $email_from, core::post('name'));
                 }
                 //if succesfully sent
                 if ($ret) {
                     Alert::set(Alert::SUCCESS, __('Your message has been sent'));
                 } else {
                     Alert::set(Alert::ERROR, __('Message not sent'));
                 }
             } else {
                 Alert::set(Alert::SUCCESS, __('This email has been considered as spam! We are sorry but we can not send this email.'));
             }
         } else {
             Alert::set(Alert::ERROR, __('Captcha is not correct'));
         }
         HTTP::redirect(Route::url('profile', array('seoname' => $user->seoname)));
     }
 }