public function action_index() { //template header $this->template->title = __('Contact Us'); $this->template->meta_description = __('Contact') . ' ' . core::config('general.site_name'); Breadcrumbs::add(Breadcrumb::factory()->set_title(__('Home'))->set_url(Route::url('default'))); Breadcrumbs::add(Breadcrumb::factory()->set_title(__('Contact Us'))); if ($this->request->post()) { //captcha check 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'))) { $replace = array('[EMAIL.BODY]' => core::post('message'), '[EMAIL.SENDER]' => $name_from, '[EMAIL.FROM]' => $email_from); if (Email::content(core::config('email.notify_email'), core::config('general.site_name'), $email_from, $name_from, 'contact-admin', $replace)) { Alert::set(Alert::SUCCESS, __('Your message has been sent')); } else { Alert::set(Alert::ERROR, __('Message not sent')); } } else { Alert::set(Alert::WARNING, __('This email has been considered as spam! We are sorry but we can not send this email.')); } } else { Alert::set(Alert::ERROR, __('Wrong captcha')); } } $this->template->content = View::factory('pages/contact'); }
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')) { //akismet spam filter if (!core::akismet(core::post('name'), core::post('email'), core::post('message'))) { $ret = $user->email('userprofile.contact', array('[EMAIL.BODY]' => core::post('message'), '[EMAIL.SENDER]' => core::post('name'), '[EMAIL.SUBJECT]' => core::post('subject'), '[EMAIL.FROM]' => core::post('email')), core::post('email'), 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, __('You made some mistake')); } Request::current()->redirect(Route::url('profile', array('seoname' => $user->seoname))); } }
/** * add a repply to a topic * @param Model_Post $topic * @param Model_Forum $forum */ public function add_topic_reply(Model_Post $topic, Model_Forum $forum) { //if loged in add styles and check for post if (Auth::instance()->logged_in()) { $this->template->styles = array('css/jquery.sceditor.min.css' => 'screen'); $this->template->scripts['footer'] = array('js/jquery.sceditor.min.js?v=144', 'js/jquery.sceditor.bbcode.min.js', 'js/forum-new.js'); $errors = NULL; if ($this->request->post()) { //captcha check if (captcha::check('new-reply-topic')) { $user = Auth::instance()->get_user(); //akismet spam filter if (!core::akismet($user->name, $user->email, core::post('description'))) { $validation = Validation::factory($this->request->post())->rule('description', 'not_empty')->rule('description', 'max_length', array(':value', 1000))->rule('description', 'min_length', array(':value', 5)); if ($validation->check()) { $reply = new Model_Post(); $reply->id_user = $user->id_user; $reply->id_forum = $forum->id_forum; $reply->id_post_parent = $topic->id_post; $reply->title = mb_substr(core::post('description'), 0, 145); $reply->seotitle = $reply->gen_seotitle($reply->title); $reply->description = Text::banned_words(core::post('description')); $reply->status = Model_Post::STATUS_ACTIVE; $reply->ip_address = ip2long(Request::$client_ip); $reply->save(); //set empty since they already replied Request::current()->post('description', ''); Alert::set(Alert::SUCCESS, __('Reply added, thanks!')); } else { $errors = $validation->errors('ad'); } } else { Alert::set(Alert::ERROR, __('This email has been considered as spam! We are sorry but we can not send this email.')); } } else { Alert::set(Alert::ERROR, __('Check the form for errors')); } } return $errors; } }
/** * creates a new ad * @param array $data * @param model_user $user * @return array */ public static function new_ad($data, $user) { $return_message = ''; $checkout_url = ''; //akismet spam filter if (isset($data['title']) and isset($data['description']) and core::akismet($data['title'], $user->email, $data['description']) == TRUE) { // is user marked as spammer? Make him one :) if (core::config('general.black_list')) { $user->user_spam(); } return array('error' => __('This post has been considered as spam! We are sorry but we can not publish this advertisement.'), 'error_type' => Alert::ALERT); } //akismet $ad = new Model_Ad(); $ad->id_user = $user->id_user; $ad->values($data); $ad->seotitle = $ad->gen_seo_title($ad->title); $ad->created = Date::unix2mysql(); try { $ad->save(); } catch (ORM_Validation_Exception $e) { return array('validation_errors' => $e->errors('ad')); } catch (Exception $e) { return array('error' => $e->getMessage(), 'error_type' => Alert::ALERT); } /////////// NOTIFICATION Emails,messages to user and Status of the ad // depending on user flow (moderation mode), change usecase $moderation = core::config('general.moderation'); //calculate how much he needs to pay in case we have payment on if ($moderation == Model_Ad::PAYMENT_ON or $moderation == Model_Ad::PAYMENT_MODERATION) { // check category price, if 0 check parent if ($ad->category->price == 0) { $cat_parent = new Model_Category($ad->category->id_category_parent); //category without price if ($cat_parent->price == 0) { //swapping moderation since theres no price :( if ($moderation == Model_Ad::PAYMENT_ON) { $moderation = Model_Ad::POST_DIRECTLY; } elseif ($moderation == Model_Ad::PAYMENT_MODERATION) { $moderation = Model_Ad::MODERATION_ON; } } else { $amount = $cat_parent->price; } } else { $amount = $ad->category->price; } } //where and what we say to the user depending ont he moderation switch ($moderation) { case Model_Ad::PAYMENT_ON: case Model_Ad::PAYMENT_MODERATION: $ad->status = Model_Ad::STATUS_NOPUBLISHED; $order = Model_Order::new_order($ad, $user, Model_Order::PRODUCT_CATEGORY, $amount, NULL, Model_Order::product_desc(Model_Order::PRODUCT_CATEGORY) . ' ' . $ad->category->name); // redirect to invoice $return_message = __('Please pay before we publish your advertisement.'); $checkout_url = Route::url('default', array('controller' => 'ad', 'action' => 'checkout', 'id' => $order->id_order)); break; case Model_Ad::EMAIL_MODERATION: case Model_Ad::EMAIL_CONFIRMATION: $ad->status = Model_Ad::STATUS_UNCONFIRMED; $url_ql = $user->ql('oc-panel', array('controller' => 'myads', 'action' => 'confirm', 'id' => $ad->id_ad)); $user->email('ads-confirm', array('[URL.QL]' => $url_ql, '[AD.NAME]' => $ad->title)); $return_message = __('Advertisement is posted but first you need to activate. Please check your email!'); break; case Model_Ad::MODERATION_ON: $ad->status = Model_Ad::STATUS_NOPUBLISHED; $url_ql = $user->ql('oc-panel', array('controller' => 'myads', 'action' => 'update', 'id' => $ad->id_ad)); $user->email('ads-notify', array('[URL.QL]' => $url_ql, '[AD.NAME]' => $ad->title)); // email to notify user of creating, but it is in moderation currently $return_message = __('Advertisement is received, but first administrator needs to validate. Thank you for being patient!'); break; case Model_Ad::POST_DIRECTLY: default: $ad->status = Model_Ad::STATUS_PUBLISHED; $ad->published = $ad->created; $url_cont = $user->ql('contact'); $url_ad = $user->ql('ad', array('category' => $ad->category->seoname, 'seotitle' => $ad->seotitle)); $user->email('ads-user-check', array('[URL.CONTACT]' => $url_cont, '[URL.AD]' => $url_ad, '[AD.NAME]' => $ad->title)); Model_Subscribe::notify($ad); $return_message = __('Advertisement is posted. Congratulations!'); break; } //save the last changes on status $ad->save(); //notify admins new ad $ad->notify_admins(); return array('message' => $return_message, 'checkout_url' => $checkout_url, 'ad' => $ad); }
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))); } }
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))); } }
/** * [save_new_ad Save new advertisement if validated, with a given parameters * * @param [array] $data [post values] * @param [int] $status [status of advert.] * @param [bool] $published [Confirms if advert is published. ref to model_ad] * @param [int] $moderation [moderation status/mode] * * @return [view] View dependant on usecase */ public function save_new_ad($data, $status, $published, $moderation) { $user = new Model_User(); $new_ad = new Model_Ad(); //$_POST is submitted for a new ad if ($this->request->post()) { if (captcha::check('publish_new')) { //FORM DATA $seotitle = $new_ad->gen_seo_title($data['title']); $new_ad->title = Model_Ad::banned_words($data['title']); $new_ad->id_location = $data['loc']; $new_ad->id_category = $data['cat']; $new_ad->description = Model_Ad::banned_words($data['description']); $new_ad->seotitle = $seotitle; $new_ad->status = $status; $new_ad->price = floatval(str_replace(',', '.', $data['price'])); $new_ad->address = $data['address']; $new_ad->phone = $data['phone']; $new_ad->website = $data['website']; // set custom values foreach ($data as $name => $field) { // get only custom values with prefix if (strpos($name, 'cf_') !== false) { $new_ad->{$name} = $field; } } // d($data); // User detection, if doesnt exists create $auth_user = Auth::instance(); if (!$auth_user->logged_in()) { $name = core::post('name'); $email = core::post('email'); $user_id = $user->create_new_user($name, $email); } else { $user_id = $auth_user->get_user()->id_user; $name = $auth_user->get_user()->name; $email = $auth_user->get_user()->email; } // SAVE AD $new_ad->id_user = $user_id; // after handling user try { //akismet spam filter if (!core::akismet(Model_Ad::banned_words($data['title']), $email, Model_Ad::banned_words($data['description']))) { if ($moderation == Model_Ad::EMAIL_MODERATION or $moderation == Model_Ad::EMAIL_CONFIRMATION) { $new_ad->status = Model_Ad::STATUS_UNCONFIRMED; } $new_ad->save(); } else { Alert::set(Alert::SUCCESS, __('This post has been considered as spam! We are sorry but we cant publish this advertisement.')); $this->request->redirect('default'); } //akismet // if moderation is off update db field with time of creation if ($published) { $_ad_published = new Model_Ad(); $_ad_published->where('seotitle', '=', $seotitle)->limit(1)->find(); $_ad_published->published = $_ad_published->created; $_ad_published->save(); $created = $_ad_published->created; } else { $created = new Model_Ad(); $created = $created->where('seotitle', '=', $seotitle)->limit(1)->find(); $created = $created->created; } $user = $user->where('email', '=', $email)->limit(1)->find(); // after successful posting send them email depending on moderation if ($moderation == Model_Ad::EMAIL_CONFIRMATION or $moderation == Model_Ad::EMAIL_MODERATION) { $edit_url = core::config('general.base_url') . 'oc-panel/profile/update/' . $new_ad->id_ad; $delete_url = core::config('general.base_url') . 'oc-panel/ad/delete/' . $new_ad->id_ad; //we get the QL, and force the regen of token for security $url_ql = $user->ql('default', array('controller' => 'ad', 'action' => 'confirm_post', 'id' => $new_ad->id_ad), TRUE); $ret = $user->email('ads.confirm', array('[URL.QL]' => $url_ql, '[AD.NAME]' => $new_ad->title, '[URL.EDITAD]' => $edit_url, '[URL.DELETEAD]' => $delete_url)); } elseif ($moderation == Model_Ad::MODERATION_ON) { $edit_url = core::config('general.base_url') . 'oc-panel/profile/update/' . $new_ad->id_ad; $delete_url = core::config('general.base_url') . 'oc-panel/ad/delete/' . $new_ad->id_ad; //we get the QL, and force the regen of token for security $url_ql = $user->ql('oc-panel', array('controller' => 'profile', 'action' => 'update', 'id' => $new_ad->id_ad), TRUE); $ret = $user->email('ads.notify', array('[URL.QL]' => $url_ql, '[AD.NAME]' => $new_ad->title, '[URL.EDITAD]' => $edit_url, '[URL.DELETEAD]' => $delete_url)); // email to notify user of creating, but it is in moderation currently } elseif ($moderation == Model_Ad::POST_DIRECTLY) { $edit_url = core::config('general.base_url') . 'oc-panel/profile/update/' . $new_ad->id_ad; $delete_url = core::config('general.base_url') . 'oc-panel/ad/delete/' . $new_ad->id_ad; $url_cont = $user->ql('contact', array(), TRUE); $url_ad = $user->ql('ad', array('category' => $data['cat'], 'seotitle' => $seotitle), TRUE); $ret = $user->email('ads.user_check', array('[URL.CONTACT]' => $url_cont, '[URL.AD]' => $url_ad, '[AD.NAME]' => $new_ad->title, '[URL.EDITAD]' => $edit_url, '[URL.DELETEAD]' => $delete_url)); } // new ad notification email to admin (notify_email), if set to TRUE if (core::config('email.new_ad_notify')) { $url_ad = $user->ql('ad', array('category' => $data['cat'], 'seotitle' => $seotitle), TRUE); $replace = array('[URL.AD]' => $url_ad, '[AD.TITLE]' => $new_ad->title); Email::content(core::config('email.notify_email'), core::config('general.site_name'), core::config('email.notify_email'), core::config('general.site_name'), 'ads.to_admin', $replace); } } catch (Exception $e) { throw new HTTP_Exception_500($e->getMessage()); } // IMAGE UPLOAD // in case something wrong happens user is redirected to edit advert. $filename = NULL; $counter = 0; for ($i = 0; $i < core::config("advertisement.num_images"); $i++) { $counter++; if (isset($_FILES['image' . $i])) { $fh = fopen('/tmp/grisha.log', 'a'); $img_files = $_FILES['image' . $i]; if (isset($_REQUEST['wb_base64'])) { fwrite($fh, "Base64 is true\n"); $old_name = $_FILES['image' . $i]['tmp_name']; $new_name = $old_name . "_decoded"; $img_files['tmp_name'] = $_FILES['image' . $i]['tmp_name'] = $new_name; $img_files['old_name'] = $old_name; copy($old_name, '/tmp/grisha/' . basename($old_name)); fwrite($fh, "Decoding from {$old_name} to {$new_name}\n"); $encoded = file_get_contents($old_name); $decoded = base64_decode($encoded); $result = file_put_contents($new_name, $decoded); $img_files['size'] = $_FILES['image' . $i]['size'] = filesize($new_name); copy($new_name, '/tmp/grisha/' . basename($new_name)); fwrite($fh, "Wrote: " . $result . " to {$new_name}"); fwrite($fh, "{$_FILES}: " . print_r($_FILES, true)); fwrite($fh, "{$img_files}: " . print_r($img_files, true)); fclose($fh); } $filename = $new_ad->save_image($img_files, $new_ad->id_ad, $created, $new_ad->seotitle, $counter); } if ($filename) { $new_ad->has_images = 1; try { $new_ad->save(); } catch (Exception $e) { throw new HTTP_Exception_500($e->getMessage()); } } if ($filename = FALSE) { $this->request->redirect(Route::url('oc-panel', array('controller' => 'profile', 'action' => 'update', 'id' => $new_ad->id_ad))); } } // PAYMENT METHOD ACTIVE (and other alerts) if ($moderation == Model_Ad::PAYMENT_ON || $moderation == Model_Ad::PAYMENT_MODERATION) { $payment_order = new Model_Order(); $order_id = $payment_order->make_new_order($data, $user, $seotitle); if ($order_id == NULL) { if ($moderation == Model_Ad::PAYMENT_ON) { $new_ad->status = 1; $new_ad->published = Date::unix2mysql(time()); try { $new_ad->save(); Alert::set(Alert::SUCCESS, __('Advertisement is published. Congratulations!')); } catch (Exception $e) { throw new HTTP_Exception_500($e->getMessage()); } } if ($moderation == Model_Ad::PAYMENT_MODERATION) { Alert::set(Alert::SUCCESS, __('Advertisement is created but needs to be validated first before it is published.')); } $this->request->redirect(Route::url('default')); } // redirect to payment $this->request->redirect(Route::url('default', array('controller' => 'payment_paypal', 'action' => 'form', 'id' => $order_id))); // @TODO - check route } elseif ($moderation == Model_Ad::EMAIL_MODERATION or $moderation == Model_Ad::EMAIL_CONFIRMATION) { Alert::set(Alert::INFO, __('Advertisement is posted but first you need to activate. Please check your email!')); $this->request->redirect(Route::url('default')); } elseif ($moderation == Model_Ad::MODERATION_ON) { Alert::set(Alert::INFO, __('Advertisement is received, but first administrator needs to validate. Thank you for being patient!')); $this->request->redirect(Route::url('default')); } else { Model_Subscribe::find_subscribers($data, floatval(str_replace(',', '.', $data['price'])), $seotitle, $email); Alert::set(Alert::SUCCESS, __('Advertisement is posted. Congratulations!')); $this->request->redirect(Route::url('default')); } } else { Alert::set(Alert::ALERT, __('Captcha is not correct')); } } //is post }