public function action_get() { try { if (is_numeric($id_ad = $this->request->param('id'))) { $ad = new Model_Ad(); //get distance to the ad if (isset($this->_params['latitude']) and isset($this->_params['longitude'])) { $ad->select(array(DB::expr('degrees(acos(sin(radians(' . $this->_params['latitude'] . ')) * sin(radians(`latitude`)) + cos(radians(' . $this->_params['latitude'] . ')) * cos(radians(`latitude`)) * cos(radians(abs(' . $this->_params['longitude'] . ' - `longitude`))))) * 69.172'), 'distance')); } $ad->where('id_ad', '=', $id_ad)->where('status', '=', Model_Ad::STATUS_PUBLISHED)->cached()->find(); if ($ad->loaded()) { $a = $ad->as_array(); $a['price'] = i18n::money_format($ad->price); $a['images'] = array_values($ad->get_images()); $a['category'] = $ad->category->as_array(); $a['location'] = $ad->location->as_array(); $a['user'] = Controller_Api_Users::get_user_array($ad->user); $a['customfields'] = Model_Field::get_by_category($ad->id_category); //sorting by distance, lets add it! if (isset($ad->distance)) { $a['distance'] = i18n::format_measurement($ad->distance); } $a['url'] = Route::url('ad', array('category' => $ad->category->seoname, 'seotitle' => $ad->seotitle)); $this->rest_output(array('ad' => $a)); } else { $this->_error(__('Advertisement not found'), 404); } } else { $this->_error(__('Advertisement not found'), 404); } } catch (Kohana_HTTP_Exception $khe) { $this->_error($khe); return; } }
/** * Automatically executed before the widget action. Can be used to set * class properties, do authorization checks, and execute other custom code. * * @return void */ public function before() { $ad = new Model_Ad(); $ad->where('seotitle', '=', Request::current()->param('seotitle'))->limit(1)->find(); if ($ad->loaded()) { $this->id_ad = $ad->id_ad; } }
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))); } } }
/** * is favorite? * @param Model_User $user user * @param Model_Ad $ad ad * @return boolean */ public static function is_favorite(Model_User $user, Model_Ad $ad) { if ($user->loaded() and $ad->loaded()) { $fav = new Model_Favorite(); $fav->where('id_user', '=', $user->id_user)->where('id_ad', '=', $ad->id_ad)->find(); if ($fav->loaded()) { return TRUE; } } return FALSE; }
/** * Automatically executed before the widget action. Can be used to set * class properties, do authorization checks, and execute other custom code. * * @return void */ public function before() { $ad = new Model_Ad(); $user_ads = clone $ad; //get current ad do not filter by user since admin also can see $ad->where('seotitle', '=', Request::current()->param('seotitle'))->limit(1)->find(); if ($ad->loaded() and Auth::instance()->logged_in()) { $user = Auth::instance()->get_user(); if ($user->id_role == Model_Role::ROLE_ADMIN or $user->id_user == $ad->id_user) { $this->ad = $ad; $this->user_ads = $user_ads->where('id_user', '=', $ad->id_user)->find_all(); } } }
public function action_create() { try { if (!is_numeric(core::request('id_ad')) or !is_numeric(core::request('id_product')) or !is_numeric(core::request('id_user'))) { $this->_error(__('Missing parameters'), 501); } else { $user = new Model_User(core::request('id_user')); $ad = new Model_Ad(core::request('id_ad')); if ($user->loaded() and $ad->loaded()) { $id_product = core::request('id_product'); $amount = core::request('amount'); //in case not set by request if (!is_numeric($amount)) { //get original price for the product switch ($id_product) { case Model_Order::PRODUCT_CATEGORY: $amount = $ad->category->price; break; case Model_Order::PRODUCT_TO_TOP: $amount = core::config('payment.pay_to_go_on_top'); break; case Model_Order::PRODUCT_TO_FEATURED: $amount = Model_Order::get_featured_price(core::request('featured_days')); break; case Model_Order::PRODUCT_AD_SELL: $amount = $ad->price; break; default: $plan = new Model_Plan($id_product); $amount = $plan->loaded() ? $plan->price : 0; break; } } $order = Model_Order::new_order($ad, $user, $id_product, $amount, core::request('currency'), Model_Order::product_desc(core::request('id_product')), core::request('featured_days')); $order->confirm_payment(core::request('paymethod', 'API'), core::request('txn_id')); $order->save(); $this->rest_output(array('order' => self::get_order_array($order))); } else { $this->_error(__('User or Ad not loaded'), 501); } } } catch (Kohana_HTTP_Exception $khe) { $this->_error($khe); } }
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); if (captcha::check('contact')) { //akismet spam filter if (!core::akismet(core::post('name'), core::post('email'), core::post('message'))) { if (isset($_FILES['file'])) { $file = $_FILES['file']; } else { $file = NULL; } $ret = $user->email('user.contact', array('[EMAIL.BODY]' => core::post('message'), '[AD.NAME]' => $ad->title, '[EMAIL.SENDER]' => core::post('name'), '[EMAIL.FROM]' => core::post('email')), core::post('email'), core::post('name'), $file); //if succesfully sent if ($ret) { Alert::set(Alert::SUCCESS, __('Your message has been sent')); // we are updating field of visit table (contact) $visit_contact_obj = new Model_Visit(); $visit_contact_obj->where('id_ad', '=', $this->request->param('id'))->order_by('created', 'desc')->limit(1)->find(); try { $visit_contact_obj->contacted = 1; $visit_contact_obj->save(); } catch (Exception $e) { //throw 500 throw new HTTP_Exception_500($e->getMessage()); } } else { Alert::set(Alert::ERROR, __('Message not sent')); } Request::current()->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, __('You made some mistake')); } } }
public function multiple_mails($receivers) { foreach ($receivers as $num => $receiver_id) { if (is_numeric($receiver_id)) { $ad = new Model_Ad($receiver_id); if ($ad->loaded()) { $cat = $ad->category; $usr = $ad->user; //we get the QL, and force the regen of token for security $url_ql = $usr->ql('ad', array('category' => $cat->seoname, 'seotitle' => $ad->seotitle), TRUE); $ret = $usr->email('ads-activated', array('[USER.OWNER]' => $usr->name, '[URL.QL]' => $url_ql, '[AD.NAME]' => $ad->title)); } } } }
public function action_favorites() { $user = Auth::instance()->get_user(); //favs or unfavs if (is_numeric($id_ad = $this->request->param('id'))) { $this->auto_render = FALSE; $this->template = View::factory('js'); $ad = new Model_Ad($id_ad); //ad exists if ($ad->loaded()) { //if fav exists we delete if (Model_Favorite::unfavorite($user->id_user, $id_ad) === TRUE) { //fav existed deleting $this->template->content = __('Deleted'); } else { //create the fav Model_Favorite::favorite($user->id_user, $id_ad); $this->template->content = __('Saved'); } } else { $this->template->content = __('Ad Not Found'); } } else { $this->template->title = __('My Favorites'); Breadcrumbs::add(Breadcrumb::factory()->set_title($this->template->title)); Controller::$full_width = TRUE; $this->template->styles = array('//cdn.jsdelivr.net/sweetalert/1.1.3/sweetalert.css' => 'screen'); $this->template->scripts['footer'][] = '//cdn.jsdelivr.net/sweetalert/1.1.3/sweetalert.min.js'; $this->template->scripts['footer'][] = 'js/oc-panel/favorite.js'; $favorites = new Model_Favorite(); $favorites = $favorites->where('id_user', '=', $user->id_user)->order_by('created', 'desc')->find_all(); $this->template->bind('content', $content); $this->template->content = View::factory('oc-panel/profile/favorites', array('favorites' => $favorites)); } }
/** * thanks for publish * @return [type] [description] */ public function action_thanks() { $ad = new Model_Ad($this->request->param('id')); if ($ad->loaded()) { $page = Model_Content::get_by_title(Core::config('advertisement.thanks_page')); //template header $this->template->title = $page->loaded() ? $page->title : __('Thanks'); Breadcrumbs::add(Breadcrumb::factory()->set_title(__('Home'))->set_url(Route::url('default'))); Breadcrumbs::add(Breadcrumb::factory()->set_title($ad->title)->set_url(Route::url('ad', array('category' => $ad->category->seoname, 'seotitle' => $ad->seotitle)))); Breadcrumbs::add(Breadcrumb::factory()->set_title($this->template->title)); $this->template->bind('content', $content); $this->template->content = View::factory('pages/ad/thanks', array('ad' => $ad, 'page' => $page)); } else { //throw 404 throw HTTP_Exception::factory(404, __('Page not found')); } }
/** * creates an order * @param Model_Ad $ad * @param Model_User $user * @param integer $id_product * @param numeric $amount * @param string $currency * @param string $description * @return Model_Order */ public static function new_order(Model_Ad $ad = NULL, $user, $id_product, $amount, $currency = NULL, $description = NULL, $featured_days = NULL) { if ($currency === NULL) { $currency = core::config('payment.paypal_currency'); } if ($description === NULL) { $description = Model_Order::product_desc($id_product); } //get if theres an unpaid order for this product and this ad $order = new Model_Order(); if ($ad !== NULL and $ad->loaded()) { $order->where('id_ad', '=', $ad->id_ad); } $order->where('id_user', '=', $user->id_user)->where('status', '=', Model_Order::STATUS_CREATED)->where('id_product', '=', $id_product)->where('amount', '=', $amount)->where('currency', '=', $currency)->limit(1)->find(); //if no unpaid create order if (!$order->loaded()) { //add coupon ID and discount only if not AD_SELL if (Model_Coupon::valid($id_product)) { $amount = Model_Coupon::price($id_product, $amount); $order->id_coupon = Model_Coupon::current()->id_coupon; } //create order $order = new Model_Order(); $order->id_user = $user->id_user; if ($ad !== NULL and $ad->loaded()) { $order->id_ad = $ad->id_ad; } $order->id_product = $id_product; $order->currency = $currency; $order->amount = $amount; $order->description = $description; // check product if ($order->id_product == Model_Order::PRODUCT_AD_SELL) { // check if ad has VAT if (isset($order->ad->cf_vatnumber) and $order->ad->cf_vatnumber and isset($order->ad->cf_vatcountry) and $order->ad->cf_vatcountry) { $order->VAT_country = $order->ad->cf_vatcountry; $order->VAT_number = $order->ad->cf_vatnumber; $order->VAT = euvat::vat_by_country($order->ad->cf_vatcountry); } elseif (isset($order->user->cf_vatnumber) and $order->user->cf_vatnumber and isset($order->user->cf_vatcountry) and $order->user->cf_vatcountry) { $order->VAT_country = $order->user->cf_vatcountry; $order->VAT_number = $order->user->cf_vatnumber; $order->VAT = euvat::vat_by_country($order->user->cf_vatcountry); } } else { if (core::config('payment.vat_country') and core::config('payment.vat_number')) { $order->VAT_country = core::config('payment.vat_country'); $order->VAT_number = core::config('payment.vat_number'); $order->VAT = euvat::vat_by_country(core::config('payment.vat_country')); } } //store how many days the ad is featured if ($featured_days !== NULL and is_numeric($featured_days)) { $order->featured_days = $featured_days; } try { $order->save(); } catch (Exception $e) { throw HTTP_Exception::factory(500, $e->getMessage()); } //send email to user with link to pay $url_checkout = $user->ql('default', array('controller' => 'ad', 'action' => 'checkout', 'id' => $order->id_order)); $replace = array('[ORDER.ID]' => $order->id_order, '[ORDER.DESC]' => $order->description, '[URL.CHECKOUT]' => $url_checkout); //$user->email('new-order',$replace); } return $order; }
/** * unfavorite an ad * @param integer $id_user user * @param integer $id_ad ad * @return boolean */ public static function unfavorite($id_user, $id_ad) { //try to find the fav $fav = new Model_Favorite(); $fav->where('id_user', '=', $id_user)->where('id_ad', '=', $id_ad)->find(); if ($fav->loaded()) { $fav->delete(); // update ad favorite counter $ad = new Model_Ad($id_ad); if ($ad->loaded()) { $ad->favorited--; try { $ad->save(); } catch (Exception $e) { return FALSE; } } return TRUE; } else { return FALSE; } }
/** * cleans old pictures * @return [type] [description] */ public function action_cleanimages() { $count_deleted = 0; //loop for directory image $folder = DOCROOT . 'images'; //year foreach (new DirectoryIterator($folder) as $year) { if ($year->isDir() and !$year->isDot() and is_numeric($year->getFilename())) { //month foreach (new DirectoryIterator($year->getPathname()) as $month) { if ($month->isDir() and !$month->isDot() and is_numeric($month->getFilename())) { //day foreach (new DirectoryIterator($month->getPathname()) as $day) { if ($day->isDir() and !$day->isDot() and is_numeric($day->getFilename())) { //id_ad foreach (new DirectoryIterator($day->getPathname()) as $id_ad) { if ($id_ad->isDir() and !$id_ad->isDot() and is_numeric($id_ad->getFilename())) { $delete = TRUE; //if ad is available leave it, if not delete folder ID $ad = new Model_Ad($id_ad->getFilename()); if ($ad->loaded() and $ad->status == Model_Ad::STATUS_PUBLISHED) { $delete = FALSE; } //ok lets get rid of it! if ($delete === TRUE) { echo '<br>Deleting: ' . $id_ad->getFilename() . '---' . $id_ad->getPathname(); File::delete($id_ad->getPathname()); //if the ad was loaded means had a different status, put it like he doesnt have images. if ($ad->loaded()) { $ad->has_images = 0; $ad->save(); //$ad->delete();//optional } $count_deleted++; } } } } } } } } } echo '<br>deleted ' . $count_deleted; }
public function action_delete_image() { try { if (is_numeric($id_ad = $this->request->param('id')) and is_numeric($num_image = $this->_post_params['num_image'])) { $ad = new Model_Ad(); $ad->where('id_ad', '=', $id_ad)->where('id_user', '=', $this->user->id_user)->find(); if ($ad->loaded()) { if ($ret = $ad->delete_image($num_image)) { $this->rest_output($ret); } else { $this->_error($ret); } } else { $this->_error(__('Advertisement not found'), 404); } } else { $this->_error(__('Advertisement not found'), 404); } } catch (Kohana_HTTP_Exception $khe) { $this->_error($khe); return; } }
/** * send message to an advertisement * @param string $message * @param Model_User $user_from * @param integer $id_ad * @param integer $price negotiate price optionsl * @return bool / model_message */ public static function send_ad($message, $user_from, $id_ad, $price = NULL) { //get the ad if its available, and user to who we need to contact $ad = new Model_Ad(); $ad->where('id_ad', '=', $id_ad)->where('status', '=', Model_Ad::STATUS_PUBLISHED)->find(); //ad loaded and is not your ad.... if ($ad->loaded() == TRUE and $user_from->id_user != $ad->id_user) { //check if we already have a thread for that ad and user...then its a reply not a new message. $msg_thread = new Model_Message(); $msg_thread->where('id_message', '=', DB::expr('id_message_parent'))->where('id_ad', '=', $id_ad)->where('id_user_from', '=', $user_from->id_user)->limit(1)->find(); //actually reply not new thread.... if ($msg_thread->loaded()) { return self::reply($message, $user_from, $msg_thread->id_message, $price); } else { $ret = self::send($message, $user_from, $ad, $id_ad, NULL, $price); //send email only if no device ID since he got the push notification already if ($ret !== FALSE and !isset($ad->user->device_id)) { $ad->user->email('messaging-ad-contact', array('[AD.NAME]' => $ad->title, '[FROM.NAME]' => $user_from->name, '[TO.NAME]' => $ad->user->name, '[DESCRIPTION]' => $message, '[URL.QL]' => $ad->user->ql('oc-panel', array('controller' => 'messages', 'action' => 'message', 'id' => $ret->id_message)))); } return $ret; } } return FALSE; }
/** * Mark advertisement as active : STATUS = 1 */ public function action_activate() { $id = $this->request->param('id'); if (isset($id)) { $active_ad = new Model_Ad($id); if ($active_ad->loaded()) { if (Auth::instance()->get_user()->id_user !== $active_ad->id_user or Auth::instance()->get_user()->id_role !== Model_Role::ROLE_ADMIN and Auth::instance()->get_user()->id_user == 1) { Alert::set(Alert::ALERT, __("This is not your advertisement.")); Request::current()->redirect(Route::url('oc-panel', array('controller' => 'profile', 'action' => 'ads'))); } elseif ($active_ad->status != 1) { $active_ad->published = Date::unix2mysql(time()); $active_ad->status = 1; try { $active_ad->save(); } catch (Exception $e) { throw new HTTP_Exception_500($e->getMessage()); } } else { Alert::set(Alert::ALERT, __("Advertisement is already marked as 'active'")); Request::current()->redirect(Route::url('oc-panel', array('controller' => 'profile', 'action' => 'ads'))); } } else { //throw 404 throw new HTTP_Exception_404(); } } // send confirmation email $cat = new Model_Category($active_ad->id_category); $usr = new Model_User($active_ad->id_user); if ($usr->loaded()) { $edit_url = core::config('general.base_url') . 'oc-panel/profile/update/' . $active_ad->id_ad; $delete_url = core::config('general.base_url') . 'oc-panel/ad/delete/' . $active_ad->id_ad; //we get the QL, and force the regen of token for security $url_ql = $usr->ql('ad', array('category' => $cat->seoname, 'seotitle' => $active_ad->seotitle), TRUE); $ret = $usr->email('ads.activated', array('[USER.OWNER]' => $usr->name, '[URL.QL]' => $url_ql, '[AD.NAME]' => $active_ad->title, '[URL.EDITAD]' => $edit_url, '[URL.DELETEAD]' => $delete_url)); } if (Core::config('sitemap.on_post') == TRUE) { Sitemap::generate(); } Alert::set(Alert::SUCCESS, __('Advertisement is active and published')); Request::current()->redirect(Route::url('oc-panel', array('controller' => 'profile', 'action' => 'ads'))); }
public function action_stats() { Breadcrumbs::add(Breadcrumb::factory()->set_title(__('My ads'))->set_url(Route::url('oc-panel', array('controller' => 'myads', 'action' => 'index')))); Breadcrumbs::add(Breadcrumb::factory()->set_title(__('Stats'))); Controller::$full_width = TRUE; $this->template->scripts['footer'] = array('js/chart.min.js', 'js/chart.js-php.js', 'js/oc-panel/stats/dashboard.js'); $this->template->title = __('Stats'); $this->template->bind('content', $content); $content = View::factory('oc-panel/profile/stats'); $list_ad = array(); $advert = new Model_Ad(); //single stats for 1 ad if (is_numeric($id_ad = $this->request->param('id'))) { $advert = new Model_Ad($id_ad); if ($advert->loaded()) { //if admin or moderator user is the advert user ;) hack!! if ($this->user->id_role == Model_Role::ROLE_ADMIN or $this->user->id_role == Model_Role::ROLE_MODERATOR) { $user = $advert->user; } else { $user = $this->user; } if ($user->id_user !== $advert->id_user) { Alert::set(Alert::ALERT, __("This is not your advertisement.")); HTTP::redirect(Route::url('oc-panel', array('controller' => 'myads', 'action' => 'index'))); } Breadcrumbs::add(Breadcrumb::factory()->set_title($advert->title)); // make a list of 1 ad (array), and than pass this array to query (IN).. To get correct visits $list_ad[] = $id_ad; } } //we didnt filter by ad, so lets get them all! if (empty($list_ad)) { $ads = new Model_Ad(); $collection_of_user_ads = $ads->where('id_user', '=', $this->user->id_user)->find_all(); $list_ad = array(); foreach ($collection_of_user_ads as $key) { // make a list of ads (array), and than pass this array to query (IN).. To get correct visits $list_ad[] = $key->id_ad; } } // if user doesn't have any ads if (empty($list_ad)) { $list_ad = array(NULL); } $content->advert = $advert; //Getting the dates and range $from_date = Core::post('from_date', strtotime('-1 month')); $to_date = Core::post('to_date', time()); //we assure is a proper time stamp if not we transform it if (is_string($from_date) === TRUE) { $from_date = strtotime($from_date); } if (is_string($to_date) === TRUE) { $to_date = strtotime($to_date); } //mysql formated dates $my_from_date = Date::unix2mysql($from_date); $my_to_date = Date::unix2mysql($to_date); //dates range we are filtering $dates = Date::range($from_date, $to_date, '+1 day', 'Y-m-d', array('date' => 0, 'count' => 0), 'date'); //dates displayed in the form $content->from_date = date('Y-m-d', $from_date); $content->to_date = date('Y-m-d', $to_date); /////////////////////CONTACT STATS//////////////////////////////// //visits created last XX days $query = DB::select(DB::expr('DATE(created) date'))->select(DB::expr('COUNT(contacted) count'))->from('visits')->where('contacted', '=', 1)->where('id_ad', 'in', $list_ad)->where('created', 'between', array($my_from_date, $my_to_date))->group_by(DB::expr('DATE( created )'))->order_by('date', 'asc')->execute(); $contacts_dates = $query->as_array('date'); //Today $query = DB::select(DB::expr('COUNT(contacted) count'))->from('visits')->where('contacted', '=', 1)->where('id_ad', 'in', $list_ad)->where(DB::expr('DATE( created )'), '=', DB::expr('CURDATE()'))->group_by(DB::expr('DATE( created )'))->order_by('created', 'asc')->execute(); $contacts = $query->as_array(); $content->contacts_today = isset($contacts[0]['count']) ? $contacts[0]['count'] : 0; //Yesterday $query = DB::select(DB::expr('COUNT(contacted) count'))->from('visits')->where('contacted', '=', 1)->where('id_ad', 'in', $list_ad)->where(DB::expr('DATE( created )'), '=', date('Y-m-d', strtotime('-1 day')))->group_by(DB::expr('DATE( created )'))->order_by('created', 'asc')->execute(); $contacts = $query->as_array(); $content->contacts_yesterday = isset($contacts[0]['count']) ? $contacts[0]['count'] : 0; // //Last 30 days contacts $query = DB::select(DB::expr('COUNT(contacted) count'))->from('visits')->where('contacted', '=', 1)->where('id_ad', 'in', $list_ad)->where('created', 'between', array(date('Y-m-d', strtotime('-30 day')), date::unix2mysql()))->execute(); $contacts = $query->as_array(); $content->contacts_month = isset($contacts[0]['count']) ? $contacts[0]['count'] : 0; //total contacts $query = DB::select(DB::expr('COUNT(contacted) count'))->where('contacted', '=', 1)->where('id_ad', 'in', $list_ad)->from('visits')->execute(); $contacts = $query->as_array(); $content->contacts_total = isset($contacts[0]['count']) ? $contacts[0]['count'] : 0; /////////////////////VISITS STATS//////////////////////////////// //visits created last XX days $query = DB::select(DB::expr('DATE(created) date'))->select(DB::expr('COUNT(id_visit) count'))->from('visits')->where('id_ad', 'in', $list_ad)->where('created', 'between', array($my_from_date, $my_to_date))->group_by(DB::expr('DATE( created )'))->order_by('date', 'asc')->execute(); $visits = $query->as_array('date'); $stats_daily = array(); foreach ($dates as $date) { $count_contants = isset($contacts_dates[$date['date']]['count']) ? $contacts_dates[$date['date']]['count'] : 0; $count_visits = isset($visits[$date['date']]['count']) ? $visits[$date['date']]['count'] : 0; $stats_daily[] = array('date' => $date['date'], 'views' => $count_visits, 'contacts' => $count_contants); } $content->stats_daily = $stats_daily; //Today $query = DB::select(DB::expr('COUNT(id_visit) count'))->from('visits')->where('id_ad', 'in', $list_ad)->where(DB::expr('DATE( created )'), '=', DB::expr('CURDATE()'))->group_by(DB::expr('DATE( created )'))->order_by('created', 'asc')->execute(); $visits = $query->as_array(); $content->visits_today = isset($visits[0]['count']) ? $visits[0]['count'] : 0; //Yesterday $query = DB::select(DB::expr('COUNT(id_visit) count'))->from('visits')->where('id_ad', 'in', $list_ad)->where(DB::expr('DATE( created )'), '=', date('Y-m-d', strtotime('-1 day')))->group_by(DB::expr('DATE( created )'))->order_by('created', 'asc')->execute(); $visits = $query->as_array(); $content->visits_yesterday = isset($visits[0]['count']) ? $visits[0]['count'] : 0; //Last 30 days visits $query = DB::select(DB::expr('COUNT(id_visit) count'))->from('visits')->where('id_ad', 'in', $list_ad)->where('created', 'between', array(date('Y-m-d', strtotime('-30 day')), date::unix2mysql()))->execute(); $visits = $query->as_array(); $content->visits_month = isset($visits[0]['count']) ? $visits[0]['count'] : 0; //total visits $query = DB::select(DB::expr('COUNT(id_visit) count'))->where('id_ad', 'in', $list_ad)->from('visits')->execute(); $visits = $query->as_array(); $content->visits_total = isset($visits[0]['count']) ? $visits[0]['count'] : 0; }
public function action_confirm_post() { $advert_id = $this->request->param('id'); $advert = new Model_Ad($advert_id); if ($advert->loaded()) { if (core::config('general.moderation') == Model_Ad::EMAIL_CONFIRMATION) { $advert->status = 1; // status active $advert->published = Date::unix2mysql(time()); try { $advert->save(); //subscription is on $data = array('title' => $title = $advert->title, 'cat' => $cat = $advert->category, 'loc' => $loc = $advert->location); Model_Subscribe::find_subscribers($data, floatval(str_replace(',', '.', $advert->price)), $advert->seotitle, Auth::instance()->get_user()->email); // if subscription is on Alert::set(Alert::INFO, __('Your advertisement is successfully activated! Thank you!')); $this->request->redirect(Route::url('ad', array('category' => $advert->id_category, 'seotitle' => $advert->seotitle))); } catch (Exception $e) { throw new HTTP_Exception_500($e->getMessage()); } } if (core::config('general.moderation') == Model_Ad::EMAIL_MODERATION) { $advert->status = 0; // status active try { $advert->save(); Alert::set(Alert::INFO, __('Advertisement is received, but first administrator needs to validate. Thank you for being patient!')); $this->request->redirect(Route::url('ad', array('category' => $advert->id_category, 'seotitle' => $advert->seotitle))); } catch (Exception $e) { throw new HTTP_Exception_500($e->getMessage()); } } } }
/** * Mark advertisement as active : STATUS = 1 */ public function action_activate() { // First generate QR! $id = $this->request->param('id'); $param_current_url = $this->request->param('current_url'); $format_id = explode('_', $id); foreach ($format_id as $id) { if (isset($id) and $id !== '') { $active_ad = new Model_Ad($id); if ($active_ad->loaded()) { if ($active_ad->status != 1) { $active_ad->published = Date::unix2mysql(time()); $active_ad->status = Model_Ad::STATUS_PUBLISHED; try { $active_ad->save(); //subscription is on $data = array('title' => $title = $active_ad->title, 'cat' => $cat = $active_ad->category, 'loc' => $loc = $active_ad->location); Model_Subscribe::find_subscribers($data, floatval(str_replace(',', '.', $active_ad->price)), $active_ad->seotitle, Auth::instance()->get_user()->email); // if subscription is on } catch (Exception $e) { throw new HTTP_Exception_500($e->getMessage()); } } else { Alert::set(Alert::ALERT, __("Warning, Advertisement is already marked as 'active'")); if ($param_current_url == Model_Ad::STATUS_NOPUBLISHED) { Request::current()->redirect(Route::url('oc-panel', array('controller' => 'ad', 'action' => 'moderate'))); } elseif ($param_current_url == Model_Ad::STATUS_PUBLISHED) { Request::current()->redirect(Route::url('oc-panel', array('controller' => 'ad', 'action' => 'index'))); } else { Request::current()->redirect(Route::url('oc-panel', array('controller' => 'ad', 'action' => 'index')) . '?define=' . $param_current_url); } } } else { //throw 404 throw new HTTP_Exception_404(); } } } $this->multiple_mails($format_id); // sending many mails at the same time @TODO EMAIl if (Core::config('sitemap.on_post') == TRUE) { Sitemap::generate(); } Alert::set(Alert::SUCCESS, __('Advertisement is active and published')); if ($param_current_url == Model_Ad::STATUS_NOPUBLISHED) { Request::current()->redirect(Route::url('oc-panel', array('controller' => 'ad', 'action' => 'moderate'))); } elseif ($param_current_url == Model_Ad::STATUS_PUBLISHED) { Request::current()->redirect(Route::url('oc-panel', array('controller' => 'ad', 'action' => 'index'))); } else { Request::current()->redirect(Route::url('oc-panel', array('controller' => 'ad', 'action' => 'index')) . '?define=' . $param_current_url); } }
/** * send message to an advertisement * @param string $message * @param integer $id_user_from * @param integer $id_ad * @param integer $price negotiate price optionsl * @return bool / model_message */ public static function send_ad($message, $id_user_from, $id_ad, $price = NULL) { //get the ad if its available, and user to who we need to contact $ad = new Model_Ad(); $ad->where('id_ad', '=', $id_ad)->where('status', '=', Model_Ad::STATUS_PUBLISHED)->find(); //ad loaded and is not your ad.... if ($ad->loaded() == TRUE and $id_user_from != $ad->id_user) { return self::send($message, $id_user_from, $ad->id_user, $id_ad, NULL, $price); } return FALSE; }
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))); } } }