Ejemplo n.º 1
0
 /**
  * Action MODERATION
  */
 public function action_moderate()
 {
     //template header
     $this->template->title = __('Moderation');
     $this->template->meta_description = __('Moderation');
     $this->template->scripts['footer'][] = '/js/oc-panel/moderation.js';
     //find all tables
     $ads = new Model_Ad();
     $res_count = $ads->where('status', '=', Model_Ad::STATUS_NOPUBLISHED)->count_all();
     if ($res_count > 0) {
         $pagination = Pagination::factory(array('view' => 'pagination', 'total_items' => $res_count, 'items_per_page' => core::config('general.advertisements_per_page')))->route_params(array('controller' => $this->request->controller(), 'action' => $this->request->action()));
         $ads = $ads->where('ad.status', '=', Model_Ad::STATUS_NOPUBLISHED)->order_by('created', 'desc')->limit($pagination->items_per_page)->offset($pagination->offset)->find_all();
         //find all tables
         $hits = new Model_Visit();
         $hits->find_all();
         $list_cat = Model_Category::get_all();
         $list_loc = Model_Location::get_all();
         $arr_hits = array();
         // array of hit integers
         // fill array with hit integers
         foreach ($ads as $key_ads) {
             // match hits with ad
             $h = $hits->where('id_ad', '=', $key_ads->id_ad);
             $count = count($h->find_all());
             // count individual hits
             array_push($arr_hits, $count);
         }
         $this->template->content = View::factory('oc-panel/pages/moderate', array('ads' => $ads, 'pagination' => $pagination, 'category' => $list_cat, 'location' => $list_loc, 'hits' => $arr_hits));
         // create view, and insert list with data
     } else {
         Alert::set(Alert::INFO, __('You do not have any advertisements waiting to be published'));
         $this->template->content = View::factory('oc-panel/pages/moderate', array('ads' => NULL));
     }
 }
Ejemplo n.º 2
0
 public function action_index()
 {
     //template header
     $this->template->title = '';
     // $this->template->meta_keywords    = 'keywords';
     $this->template->meta_description = Core::config('general.site_description');
     //setting main view/template and render pages
     // swith to decide on ads_in_home
     $ads = new Model_Ad();
     $ads->where('status', '=', Model_Ad::STATUS_PUBLISHED);
     switch (core::config('advertisement.ads_in_home')) {
         case 2:
             $id_ads = array_keys(Model_Visit::popular_ads());
             if (count($id_ads) > 0) {
                 $ads->where('id_ad', 'IN', $id_ads);
             }
             break;
         case 1:
             $ads->where('featured', 'IS NOT', NULL)->where('featured', 'BETWEEN', array(DB::expr('NOW()'), Date::unix2mysql(time() + core::config('payment.featured_days') * 24 * 60 * 60)))->order_by('featured', 'desc');
             break;
         case 0:
         default:
             $ads->order_by('published', 'desc');
             break;
     }
     //if ad have passed expiration time dont show
     if (core::config('advertisement.expire_date') > 0) {
         $ads->where(DB::expr('DATE_ADD( published, INTERVAL ' . core::config('advertisement.expire_date') . ' DAY)'), '>', DB::expr('NOW()'));
     }
     $ads = $ads->limit(Theme::get('num_home_latest_ads', 4))->cached()->find_all();
     $this->ads = $ads;
     $categs = Model_Category::get_category_count();
     $this->template->bind('content', $content);
     $this->template->content = View::factory('pages/home', array('ads' => $ads, 'categs' => $categs));
 }
Ejemplo n.º 3
0
 /**
  * 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()
 {
     $ads = new Model_Ad();
     $ads->where('status', '=', Model_Ad::STATUS_PUBLISHED);
     //if ad have passed expiration time dont show
     if (core::config('advertisement.expire_date') > 0) {
         $ads->where(DB::expr('DATE_ADD( published, INTERVAL ' . core::config('advertisement.expire_date') . ' DAY)'), '>', Date::unix2mysql());
     }
     switch ($this->ads_type) {
         case 'popular':
             $id_ads = array_keys(Model_Visit::popular_ads());
             if (count($id_ads) > 0) {
                 $ads->where('id_ad', 'IN', $id_ads);
             }
             break;
         case 'featured':
             $ads->where('featured', 'IS NOT', NULL)->where('featured', '>', Date::unix2mysql())->order_by('featured', 'desc');
             break;
         case 'latest':
         default:
             $ads->order_by('published', 'desc');
             break;
     }
     $ads = $ads->limit($this->ads_limit)->cached()->find_all();
     //die(print_r($ads));
     $this->ads = $ads;
 }
Ejemplo n.º 4
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)));
         }
     }
 }
Ejemplo n.º 5
0
 public function action_index()
 {
     if (core::config('general.auto_locate')) {
         Theme::$scripts['footer'][] = '//maps.google.com/maps/api/js?sensor=false&libraries=geometry&v=3.7';
         Theme::$scripts['footer'][] = '//cdn.jsdelivr.net/gmaps/0.4.15/gmaps.min.js';
     }
     //template header
     $this->template->title = '';
     // $this->template->meta_keywords    = 'keywords';
     if (core::config('general.site_description') != '') {
         $this->template->meta_description = core::config('general.site_description');
     } else {
         $this->template->meta_description = core::config('general.site_name') . ' ' . __('official homepage, get your post listed now.');
     }
     //setting main view/template and render pages
     // swith to decide on ads_in_home
     $ads = new Model_Ad();
     $ads->where('status', '=', Model_Ad::STATUS_PUBLISHED);
     $ads_in_home = core::config('advertisement.ads_in_home');
     //in case we do not count visits we cant show popular
     if (core::config('advertisement.count_visits') == 0 and $ads_in_home == 2) {
         $ads_in_home = 0;
     }
     switch ($ads_in_home) {
         case 2:
             $id_ads = array_keys(Model_Visit::popular_ads());
             if (count($id_ads) > 0) {
                 $ads->where('id_ad', 'IN', $id_ads);
             }
             break;
         case 1:
             $ads->where('featured', 'IS NOT', NULL)->where('featured', '>=', Date::unix2mysql())->order_by('featured', 'desc');
             break;
         case 4:
             $ads->where('featured', 'IS NOT', NULL)->where('featured', '>=', Date::unix2mysql())->order_by(DB::expr('RAND()'));
             break;
         case 0:
         default:
             $ads->order_by('published', 'desc');
             break;
     }
     //if ad have passed expiration time dont show
     if (core::config('advertisement.expire_date') > 0) {
         $ads->where(DB::expr('DATE_ADD( published, INTERVAL ' . core::config('advertisement.expire_date') . ' DAY)'), '>', Date::unix2mysql());
     }
     $ads = $ads->limit(Theme::get('num_home_latest_ads', 4))->cached()->find_all();
     $categs = Model_Category::get_category_count();
     $locats = Model_Location::get_location_count();
     $auto_locats = NULL;
     if (core::config('general.auto_locate') and Model_User::get_userlatlng()) {
         $auto_locats = new Model_Location();
         $auto_locats = $auto_locats->select(array(DB::expr('degrees(acos(sin(radians(' . $_COOKIE['mylat'] . ')) * sin(radians(`latitude`)) + cos(radians(' . $_COOKIE['mylat'] . ')) * cos(radians(`latitude`)) * cos(radians(abs(' . $_COOKIE['mylng'] . ' - `longitude`))))) * 111.321'), 'distance'))->where('latitude', 'IS NOT', NULL)->where('longitude', 'IS NOT', NULL)->having('distance', '<=', '100')->order_by('distance', 'desc')->find_all()->as_array();
     }
     $this->template->bind('content', $content);
     $this->template->content = View::factory('pages/home', array('ads' => $ads, 'categs' => $categs, 'locats' => $locats, 'auto_locats' => $auto_locats));
 }
Ejemplo n.º 6
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);
         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'));
         }
     }
 }
Ejemplo n.º 7
0
 public function action_info()
 {
     //try to get the info from the cache
     $info = Core::cache('action_info', NULL);
     //not cached :(
     if ($info === NULL) {
         $ads = new Model_Ad();
         $total_ads = $ads->count_all();
         $last_ad = $ads->select('published')->order_by('published', 'desc')->limit(1)->find();
         $last_ad = $last_ad->published;
         $ads = new Model_Ad();
         $first_ad = $ads->select('published')->order_by('published', 'asc')->limit(1)->find();
         $first_ad = $first_ad->published;
         $views = new Model_Visit();
         $total_views = $views->count_all();
         $users = new Model_User();
         $total_users = $users->count_all();
         $info = array('site_url' => Core::config('general.base_url'), 'site_name' => Core::config('general.site_name'), 'site_description' => Core::config('general.site_description'), 'created' => $first_ad, 'updated' => $last_ad, 'email' => Core::config('email.notify_email'), 'version' => Core::VERSION, 'theme' => Core::config('appearance.theme'), 'theme_mobile' => Core::config('appearance.theme_mobile'), 'charset' => Kohana::$charset, 'timezone' => Core::config('i18n.timezone'), 'locale' => Core::config('i18n.locale'), 'currency' => '', 'ads' => $total_ads, 'views' => $total_views, 'users' => $total_users);
         Core::cache('action_info', $info);
     }
     $this->response->headers('Content-type', 'application/javascript');
     $this->response->body(json_encode($info));
 }
Ejemplo n.º 8
0
 public function action_index()
 {
     //template header
     $this->template->title = '';
     // $this->template->meta_keywords    = 'keywords';
     $this->template->meta_description = Core::config('general.site_name') . ' ' . __('official homepage for the online store');
     $products = new Model_Product();
     $products->where('status', '=', Model_Product::STATUS_ACTIVE);
     switch (core::config('product.products_in_home')) {
         case 3:
             $id_products = Model_Review::best_rated();
             $array_ids = array();
             foreach ($id_products as $id => $id_product) {
                 $array_ids = $id_product;
             }
             if (count($id_products) > 0) {
                 $products->where('id_product', 'IN', $array_ids);
             }
             break;
         case 2:
             $id_products = array_keys(Model_Visit::popular_products());
             if (count($id_products) > 0) {
                 $products->where('id_product', 'IN', $id_products);
             }
             break;
         case 1:
             $products->where('featured', 'IS NOT', NULL)->where('featured', '>', Date::unix2mysql())->order_by('featured', 'desc');
             break;
         case 0:
         default:
             $products->order_by('created', 'desc');
             break;
     }
     $products = $products->limit(Theme::get('num_home_products', 21))->cached()->find_all();
     $categs = Model_Category::get_category_count();
     $this->template->bind('content', $content);
     $this->template->content = View::factory('pages/home', array('products' => $products, 'categs' => $categs));
 }
Ejemplo n.º 9
0
 /**
  * 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()
 {
     $products = new Model_Product();
     $products->where('status', '=', Model_Product::STATUS_ACTIVE);
     switch ($this->products_type) {
         case 'popular':
             $id_products = array_keys(Model_Visit::popular_products());
             if (count($id_products) > 0) {
                 $products->where('id_product', 'IN', $id_products);
             }
             break;
         case 'featured':
             $products->where('featured', 'IS NOT', NULL)->where('featured', '>', Date::unix2mysql())->order_by('featured', 'desc');
             break;
         case 'latest':
         default:
             $products->order_by('created', 'desc');
             break;
     }
     $products = $products->limit($this->products_limit)->cached()->find_all();
     //die(print_r($products));
     $this->products = $products;
 }
Ejemplo n.º 10
0
 /**
  * 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()
 {
     $ads = new Model_Ad();
     $ads->where('status', '=', Model_Ad::STATUS_PUBLISHED);
     switch ($this->ads_type) {
         case 'popular':
             $id_ads = array_keys(Model_Visit::popular_ads());
             if (count($id_ads) > 0) {
                 $ads->where('id_ad', 'IN', $id_ads);
             }
             break;
         case 'featured':
             $ads->where('featured', 'IS NOT', NULL)->where('featured', 'BETWEEN', array(DB::expr('NOW()'), Date::unix2mysql(time() + core::config('payment.featured_days') * 24 * 60 * 60)))->order_by('featured', 'desc');
             break;
         case 'latest':
         default:
             $ads->order_by('published', 'desc');
             break;
     }
     $ads = $ads->limit($this->ads_limit)->cached()->find_all();
     //die(print_r($ads));
     $this->ads = $ads;
 }
Ejemplo n.º 11
0
 /**
  * 
  * Display single advert. 
  * @throws HTTP_Exception_404
  * 
  */
 public function action_view()
 {
     $seotitle = $this->request->param('seotitle', NULL);
     if ($seotitle !== NULL) {
         $ad = new Model_Ad();
         $ad->where('seotitle', '=', $seotitle)->where('status', '!=', Model_Ad::STATUS_SPAM)->limit(1)->cached()->find();
         if ($ad->loaded()) {
             //throw 404
             if ($ad->status == Model_Ad::STATUS_UNAVAILABLE or $ad->status == Model_Ad::STATUS_NOPUBLISHED) {
                 throw HTTP_Exception::factory(404, __('This advertisement doesn´t exist, or is not yet published!'));
             }
             Breadcrumbs::add(Breadcrumb::factory()->set_title(__('Home'))->set_url(Route::url('default')));
             $location = NULL;
             $location_parent = NULL;
             if ($ad->location->loaded() and $ad->id_location != 1) {
                 $location = $ad->location;
                 //adding the location parent
                 if ($location->id_location_parent != 1 and $location->parent->loaded()) {
                     $location_parent = $location->parent;
                 }
             }
             $category = NULL;
             $category_parent = NULL;
             if ($ad->category->loaded()) {
                 $category = $ad->category;
                 //adding the category parent
                 if ($category->id_category_parent != 1 and $category->parent->loaded()) {
                     $category_parent = $category->parent;
                 }
             }
             //base category  title
             if ($category !== NULL) {
                 $this->template->title = $category->name;
             } else {
                 $this->template->title = '';
             }
             //adding location titles and breadcrumbs
             if ($location !== NULL) {
                 $this->template->title .= ' - ' . $location->name;
                 if ($location_parent !== NULL) {
                     $this->template->title .= ' (' . $location_parent->name . ')';
                     Breadcrumbs::add(Breadcrumb::factory()->set_title($location_parent->name)->set_url(Route::url('list', array('location' => $location_parent->seoname))));
                 }
                 Breadcrumbs::add(Breadcrumb::factory()->set_title($location->name)->set_url(Route::url('list', array('location' => $location->seoname))));
                 if ($category_parent !== NULL) {
                     Breadcrumbs::add(Breadcrumb::factory()->set_title($category_parent->name)->set_url(Route::url('list', array('category' => $category_parent->seoname, 'location' => $location->seoname))));
                 }
                 if ($category !== NULL) {
                     Breadcrumbs::add(Breadcrumb::factory()->set_title($category->name)->set_url(Route::url('list', array('category' => $category->seoname, 'location' => $location->seoname))));
                 }
             } else {
                 if ($category_parent !== NULL) {
                     $this->template->title .= ' (' . $category_parent->name . ')';
                     Breadcrumbs::add(Breadcrumb::factory()->set_title($category_parent->name)->set_url(Route::url('list', array('category' => $category_parent->seoname))));
                 }
                 if ($category !== NULL) {
                     Breadcrumbs::add(Breadcrumb::factory()->set_title($category->name)->set_url(Route::url('list', array('category' => $category->seoname))));
                 }
             }
             $this->template->title = $ad->title . ' - ' . $this->template->title;
             Breadcrumbs::add(Breadcrumb::factory()->set_title($ad->title));
             $this->template->meta_description = $ad->title . ' ' . __('in') . ' ' . $category->name . ' ' . __('on') . ' ' . core::config('general.site_name');
             $permission = TRUE;
             //permission to add hit to advert and give access rights.
             $auth_user = Auth::instance();
             if (!$auth_user->logged_in() or $auth_user->get_user()->id_user != $ad->id_user and (!$auth_user->get_user()->is_admin() and !$auth_user->get_user()->is_moderator()) or !$auth_user->get_user()->is_admin() and !$auth_user->get_user()->is_moderator()) {
                 $permission = FALSE;
                 $user = NULL;
             } else {
                 $user = $auth_user->get_user()->id_user;
             }
             Model_Visit::hit_ad($ad->id_ad);
             $hits = $ad->count_ad_hit();
             $captcha_show = core::config('advertisement.captcha');
             if ($ad->get_first_image() !== NULL) {
                 Controller::$image = $ad->get_first_image();
             }
             $view_file = 'pages/ad/single';
             if (Core::get('amp') == '1') {
                 $this->template = 'amp/main';
                 $this->before();
                 $this->template->canonical = Route::url('ad', array('controller' => 'ad', 'category' => $ad->category->seoname, 'seotitle' => $ad->seotitle));
                 $this->template->structured_data = $ad->structured_data();
                 $view_file = 'amp/pages/ad/single';
             }
             $cf_list = $ad->custom_columns();
             $this->template->amphtml = Route::url('ad', array('controller' => 'ad', 'category' => $ad->category->seoname, 'seotitle' => $ad->seotitle)) . '?amp=1';
             $this->template->bind('content', $content);
             $this->template->content = View::factory($view_file, compact('ad', 'permission', 'hits', 'captcha_show', 'user', 'cf_list'));
         } else {
             //throw 404
             throw HTTP_Exception::factory(404, __('Page not found'));
         }
     } else {
         //throw 404
         throw HTTP_Exception::factory(404, __('Page not found'));
     }
 }
Ejemplo n.º 12
0
 /**
  * ads a contact to table visits to an ad
  * @param  integer $id_ad id of the ad
  * @return integger        
  */
 public static function contact_ad($id_ad)
 {
     if (core::config('advertisement.count_visits') == TRUE and !self::is_bot()) {
         //see if exists the visit
         $hit = new Model_Visit();
         $hit = $hit->where('id_ad', '=', $id_ad)->where('created', '=', date('Y-m-d'))->limit(1)->cached()->find();
         //didnt...so create it!
         if (!$hit->loaded()) {
             $hit->invalidate_cache();
             $hit = new Model_Visit();
             $hit->id_ad = $id_ad;
             $hit->contacts = 1;
             $hit->created = date('Y-m-d');
         } else {
             $hit->contacts++;
         }
         try {
             $hit->save();
         } catch (Exception $e) {
         }
         return $hit->contacts;
     }
     return 0;
 }
Ejemplo n.º 13
0
 /**
  *  returns the count of visits
  * 
  */
 public function count_ad_hit()
 {
     if ($this->loaded() and $this->status == Model_Ad::STATUS_PUBLISHED) {
         return Model_Visit::count_all_visits($this->id_ad);
     }
     return 0;
 }
Ejemplo n.º 14
0
 public function action_index()
 {
     if (core::config('general.auto_locate')) {
         if ($user_location = Core::post('user_location')) {
             Cookie::set('user_location', $user_location);
             $this->auto_render = FALSE;
             $this->template = View::factory('js');
             $this->template->content = TRUE;
             return;
         } elseif (Core::get('user_location') == '0') {
             Cookie::delete('user_location');
         }
         Theme::$scripts['async_defer'][] = '//maps.google.com/maps/api/js?libraries=geometry&v=3&key=' . core::config("advertisement.gm_api_key") . '&callback=initAutoLocate';
     }
     //template header
     $this->template->title = '';
     // $this->template->meta_keywords    = 'keywords';
     if (core::config('general.site_description') != '') {
         $this->template->meta_description = core::config('general.site_description');
     } else {
         $this->template->meta_description = core::config('general.site_name') . ' ' . __('official homepage, get your post listed now.');
     }
     //setting main view/template and render pages
     // get user location if any
     $user_location = NULL;
     if (is_numeric($user_id_location = Cookie::get('user_location'))) {
         $user_location = new Model_Location($user_id_location);
         if (!$user_location->loaded()) {
             $user_location = NULL;
         }
     }
     // swith to decide on ads_in_home
     $ads = new Model_Ad();
     $ads->where('status', '=', Model_Ad::STATUS_PUBLISHED);
     if ($user_location) {
         $ads->where('id_location', 'in', $user_location->get_siblings_ids());
     }
     $ads_in_home = core::config('advertisement.ads_in_home');
     //in case we do not count visits we cant show popular
     if (core::config('advertisement.count_visits') == 0 and $ads_in_home == 2) {
         $ads_in_home = 0;
     }
     switch ($ads_in_home) {
         case 2:
             $id_ads = array_keys(Model_Visit::popular_ads());
             if (count($id_ads) > 0) {
                 $ads->where('id_ad', 'IN', $id_ads);
             }
             break;
         case 1:
             $ads->where('featured', 'IS NOT', NULL)->where('featured', '>=', Date::unix2mysql())->order_by('featured', 'desc');
             break;
         case 4:
             $ads->where('featured', 'IS NOT', NULL)->where('featured', '>=', Date::unix2mysql())->order_by(DB::expr('RAND()'));
             break;
         case 0:
         default:
             $ads->order_by('published', 'desc');
             break;
     }
     //if ad have passed expiration time dont show
     if (core::config('advertisement.expire_date') > 0) {
         $ads->where(DB::expr('DATE_ADD( published, INTERVAL ' . core::config('advertisement.expire_date') . ' DAY)'), '>', Date::unix2mysql());
     }
     $ads = $ads->limit(Theme::get('num_home_latest_ads', 4))->cached()->find_all();
     $categs = Model_Category::get_category_count(TRUE, $user_location);
     $hide_categories = json_decode(Core::config('general.hide_homepage_categories'), TRUE);
     $auto_locats = NULL;
     $auto_location_distance = Core::config('general.measurement') == 'imperial' ? Num::round(Core::config('advertisement.auto_locate_distance') * 1.60934) : Core::config('advertisement.auto_locate_distance');
     if (core::config('general.auto_locate') and !isset($_COOKIE['cancel_auto_locate']) and Model_User::get_userlatlng()) {
         $auto_locats = new Model_Location();
         $auto_locats = $auto_locats->select(array(DB::expr('degrees(acos(sin(radians(' . $_COOKIE['mylat'] . ')) * sin(radians(`latitude`)) + cos(radians(' . $_COOKIE['mylat'] . ')) * cos(radians(`latitude`)) * cos(radians(abs(' . $_COOKIE['mylng'] . ' - `longitude`))))) * 111.321'), 'distance'))->where('latitude', 'IS NOT', NULL)->where('longitude', 'IS NOT', NULL)->having('distance', '<=', $auto_location_distance)->order_by('distance', 'asc')->find_all()->as_array();
     }
     $this->template->bind('content', $content);
     $this->template->content = View::factory('pages/home', compact('ads', 'categs', 'auto_locats', 'user_location', 'hide_categories'));
 }
Ejemplo n.º 15
0
 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')));
     }
 }
Ejemplo n.º 16
0
 /**
  * ads a new hit in visits DB and counts how many visits has
  * @return integer count
  */
 public function count_hit()
 {
     if (!Model_Visit::is_bot() and $this->loaded() and core::config('product.count_visits') == 1) {
         //adding a visit only if not the owner
         if (!Auth::instance()->logged_in()) {
             $visitor_id = NULL;
         } else {
             $visitor_id = Auth::instance()->get_user()->id_user;
         }
         //adding affiliate if any
         $id_affiliate = NULL;
         if (Model_Affiliate::current()->loaded()) {
             $id_affiliate = Model_Affiliate::current()->id_user;
         }
         //new visit if not owner nad not bot
         if ($this->id_user != $visitor_id) {
             $new_hit = DB::insert('visits', array('id_product', 'id_user', 'id_affiliate', 'ip_address'))->values(array($this->id_product, $visitor_id, $id_affiliate, ip2long(Request::$client_ip)))->execute();
         }
         //count how many visits has
         $hits = new Model_Visit();
         return $hits->where('id_product', '=', $this->id_product)->count_all();
     }
     return 0;
 }
Ejemplo n.º 17
0
 /**
  *  Create single table for each advertisement hit
  * 
  */
 public function count_ad_hit()
 {
     $hits = 0;
     if (!Model_Visit::is_bot() and $this->loaded() and $this->status == Model_Ad::STATUS_PUBLISHED and core::config('advertisement.count_visits') == 1) {
         if (!Auth::instance()->logged_in()) {
             $visitor_id = NULL;
         } else {
             $visitor_id = Auth::instance()->get_user()->id_user;
         }
         //insert new visit
         if ($this->id_user != $visitor_id) {
             $new_hit = DB::insert('visits', array('id_ad', 'id_user'))->values(array($this->id_ad, $visitor_id))->execute();
         }
         //count how many matches are found
         $hits = new Model_Visit();
         $hits = $hits->where('id_ad', '=', $this->id_ad)->count_all();
     }
     return $hits;
 }
Ejemplo n.º 18
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)));
         }
     }
 }