Ejemplo n.º 1
0
 public function action_user_contact()
 {
     $ad = new Model_Ad($this->request->param('id'));
     //message to user
     if ($ad->loaded() and $this->request->post()) {
         $user = new Model_User($ad->id_user);
         //require login to contact
         if ((core::config('advertisement.login_to_contact') == TRUE or core::config('general.messaging') == TRUE) and !Auth::instance()->logged_in()) {
             Alert::set(Alert::INFO, __('Please, login before contacting'));
             HTTP::redirect(Route::url('ad', array('category' => $ad->category->seoname, 'seotitle' => $ad->seotitle)));
         }
         if (captcha::check('contact')) {
             //check if user is loged in
             if (Auth::instance()->logged_in()) {
                 $email_from = $this->user->email;
                 $name_from = $this->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')) {
                     //price?
                     $price = (core::post('price') !== NULL and is_numeric(core::post('price'))) ? core::post('price') : NULL;
                     $ret = Model_Message::send_ad(core::post('message'), $this->user, $ad->id_ad, $price);
                 } else {
                     if (isset($_FILES['file'])) {
                         $file = $_FILES['file'];
                     } else {
                         $file = NULL;
                     }
                     //contact email is set use that one
                     if (isset($ad->cf_contactemail) and Valid::email($ad->cf_contactemail)) {
                         $to = $ad->cf_contactemail;
                     } else {
                         $to = NULL;
                     }
                     $ret = $user->email('user-contact', array('[EMAIL.BODY]' => core::post('message'), '[AD.NAME]' => $ad->title, '[EMAIL.SENDER]' => $name_from, '[EMAIL.FROM]' => $email_from, '[URL.AD]' => Route::url('ad', array('category' => $ad->category->seoname, 'seotitle' => $ad->seotitle))), $email_from, $name_from, $file, $to);
                 }
                 //if succesfully sent
                 if ($ret) {
                     Alert::set(Alert::SUCCESS, __('Your message has been sent'));
                     // we are updating field of visit table (contact)
                     Model_Visit::contact_ad($ad->id_ad);
                 } else {
                     Alert::set(Alert::ERROR, __('Message not sent'));
                 }
                 HTTP::redirect(Route::url('ad', array('category' => $ad->category->seoname, 'seotitle' => $ad->seotitle)));
             } 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('ad', array('category' => $ad->category->seoname, 'seotitle' => $ad->seotitle)));
         }
     }
 }
 /**
  * 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);
     }
 }
Ejemplo n.º 3
0
 public function action_user_contact()
 {
     $ad = new Model_Ad($this->request->param('id'));
     //message to user
     if ($ad->loaded() and $this->request->post()) {
         $user = new Model_User($ad->id_user);
         //require login to contact
         if ((core::config('advertisement.login_to_contact') == TRUE or core::config('general.messaging') == TRUE) and !Auth::instance()->logged_in()) {
             Alert::set(Alert::INFO, __('Please, login before contacting'));
             HTTP::redirect(Route::url('ad', array('category' => $ad->category->seoname, 'seotitle' => $ad->seotitle)));
         }
         if (captcha::check('contact')) {
             //check if user is loged in
             if (Auth::instance()->logged_in()) {
                 $email_from = $this->user->email;
                 $name_from = $this->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')) {
                     //price?
                     $price = (core::post('price') !== NULL and is_numeric(core::post('price'))) ? core::post('price') : NULL;
                     $ret = Model_Message::send_ad(core::post('message'), $this->user->id_user, $ad->id_ad, $price);
                     if ($ret !== FALSE) {
                         $ad->user->email('messaging-ad-contact', array('[AD.NAME]' => $ad->title, '[FROM.NAME]' => $this->user->name, '[TO.NAME]' => $ad->user->name, '[DESCRIPTION]' => core::post('message'), '[URL.QL]' => $ad->user->ql('oc-panel', array('controller' => 'messages', 'action' => 'message', 'id' => $ret->id_message))));
                     }
                 } else {
                     if (isset($_FILES['file'])) {
                         $file = $_FILES['file'];
                     } else {
                         $file = NULL;
                     }
                     //contact email is set use that one
                     if (isset($ad->cf_contactemail) and Valid::email($ad->cf_contactemail)) {
                         $to = $ad->cf_contactemail;
                     } else {
                         $to = NULL;
                     }
                     $ret = $user->email('user-contact', array('[EMAIL.BODY]' => core::post('message'), '[AD.NAME]' => $ad->title, '[EMAIL.SENDER]' => $name_from, '[EMAIL.FROM]' => $email_from, '[URL.AD]' => Route::url('ad', array('category' => $ad->category->seoname, 'seotitle' => $ad->seotitle))), $email_from, $name_from, $file, $to);
                 }
                 //if succesfully sent
                 if ($ret) {
                     Alert::set(Alert::SUCCESS, __('Your message has been sent'));
                     // we are updating field of visit table (contact)
                     $visit = new Model_Visit();
                     $visit->where('id_ad', '=', $this->request->param('id'))->where('ip_address', '=', ip2long(Request::$client_ip))->order_by('created', 'desc')->limit(1)->find();
                     if ($visit->loaded()) {
                         $visit->contacted = 1;
                         try {
                             $visit->save();
                         } catch (Exception $e) {
                             //throw 500
                             throw HTTP_Exception::factory(500, $e->getMessage());
                         }
                     }
                 } else {
                     Alert::set(Alert::ERROR, __('Message not sent'));
                 }
                 HTTP::redirect(Route::url('ad', array('category' => $ad->category->seoname, 'seotitle' => $ad->seotitle)));
             } 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('ad', array('category' => $ad->category->seoname, 'seotitle' => $ad->seotitle)));
         }
     }
 }