public function action_message() { Controller::$full_width = TRUE; if ($this->request->param('id') !== NULL and is_numeric($id_msg_thread = $this->request->param('id'))) { $messages = Model_Message::get_thread($id_msg_thread, $this->user->id_user); if ($messages !== FALSE) { $msg_thread = new Model_Message(); $msg_thread = $msg_thread->where('id_message', '=', $this->request->param('id'))->find(); // send reply message if ($this->request->post() and Form::token('reply_message', TRUE)) { $validation = Validation::factory($this->request->post())->rule('message', 'not_empty'); if ($validation->check()) { $ret = Model_Message::reply(core::post('message'), $this->user->id_user, $id_msg_thread, NULL); if ($ret !== FALSE) { //who is who? if from is the same then send to TO, else to from if ($msg_thread->id_user_from == $this->user->id_user) { $user_to = $msg_thread->to; $user_from = $msg_thread->from; } else { $user_to = $msg_thread->from; $user_from = $msg_thread->to; } //email title if ($msg_thread->id_ad !== NULL) { $email_title = $msg_thread->ad->title; } else { $email_title = sprintf(__('Direct message from %s'), $user_from->name); } $user_to->email('messaging-reply', array('[TITLE]' => $email_title, '[DESCRIPTION]' => core::post('message'), '[URL.QL]' => $user_to->ql('oc-panel', array('controller' => 'messages', 'action' => 'message', 'id' => $this->request->param('id'))))); // we are updating field of visit table (contact) if ($msg_thread->id_ad !== NULL) { $visit = new Model_Visit(); $visit->where('id_ad', '=', $msg_thread->id_ad)->where('id_user', '=', $user_from->id_user)->order_by('created', 'desc')->limit(1)->find(); if ($visit->loaded()) { $visit->contacted = 1; $visit->created = Date::unix2mysql(); try { $visit->save(); } catch (Exception $e) { //throw 500 throw HTTP_Exception::factory(500, $e->getMessage()); } } } Alert::set(Alert::SUCCESS, __('Reply created.')); $this->redirect(Route::url('oc-panel', array('controller' => 'messages', 'action' => 'message', 'id' => Request::current()->param('id')))); } else { Alert::set(Alert::ERROR, __('Message not sent')); } } else { $errors = $validation->errors('message'); } } Breadcrumbs::add(Breadcrumb::factory()->set_title(__('Messaging'))->set_url(Route::url('oc-panel', array('controller' => 'messages', 'action' => 'index')))); if ($msg_thread->id_ad !== NULL) { Breadcrumbs::add(Breadcrumb::factory()->set_title($msg_thread->ad->title)); } else { Breadcrumbs::add(Breadcrumb::factory()->set_title(__('Direct Message'))); } $this->template->styles = array('css/jquery.sceditor.default.theme.min.css' => 'screen'); $this->template->scripts['footer'] = array('js/jquery.sceditor.bbcode.min.js', 'js/messages.js'); $this->template->content = View::factory('oc-panel/pages/messages/message', array('msg_thread' => $msg_thread, 'messages' => $messages, 'user' => $this->user)); } else { Alert::set(Alert::ERROR, __('Message not found')); $this->redirect(Route::url('oc-panel', array('controller' => 'messages', 'action' => 'index'))); } } else { Alert::set(Alert::ERROR, __('Message not found')); $this->redirect(Route::url('oc-panel', array('controller' => 'messages', 'action' => 'index'))); } }
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) $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))); } } }