/** * verifies a licese @todo * @param string $license * @param string $domain name * @return bool */ public static function verify($license_num, $domain) { //removing the www. so we accept both for same domain //$domain = preg_replace('#^www\.(.+\.)#i', '$1', $domain); //since 1.6 licenses are for an entire domain $domain = URL::get_domain($domain); $license = self::get_license($license_num); if ($license->loaded()) { //this means the license was at some point activated if ($license->active_date != NULL and $license->active_date != '') { //if license expired return false if ($license->valid_date != NULL and $license->valid_date != '' and Date::mysql2unix($license->valid_date) < time()) { return FALSE; } //check domain for the license. if matched if (URL::get_domain($license->domain) != $domain) { return FALSE; } } else { $license->active_date = Date::unix2mysql(); $license->domain = $domain; } $license->license_check_date = Date::unix2mysql(); $license->ip_address = ip2long(Request::$client_ip); $license->save(); return TRUE; } return FALSE; }
public function action_blog() { $this->auto_render = FALSE; $info = array('title' => 'RSS Blog ' . Core::config('general.site_name'), 'pubDate' => date("D, d M Y H:i:s T"), 'description' => __('Latest post published'), 'generator' => 'Open Classifieds'); $items = array(); $posts = new Model_Post(); $posts = $posts->where('status', '=', 1)->order_by('created', 'desc')->limit(Core::config('general.feed_elements'))->cached()->find_all(); foreach ($posts as $post) { $url = Route::url('blog', array('seotitle' => $post->seotitle)); $items[] = array('title' => preg_replace('/&(?!\\w+;)/', '&', $post->title), 'link' => $url, 'pubDate' => Date::mysql2unix($post->created), 'description' => Text::removebbcode(preg_replace('/&(?!\\w+;)/', '&', $post->description))); } $xml = Feed::create($info, $items); $this->response->headers('Content-type', 'text/xml'); $this->response->body($xml); }
/** * gets all the crons from crontab and executes them * @return string info */ public static function run() { $time_start = microtime(true); //get active crons and due to execute now or next execute is NULL $crontab = new Cron(); $crontab = $crontab->where('active', '=', 1)->where_open()->or_where('date_next', '<=', Date::unix2mysql())->or_where('date_next', 'IS', NULL)->where_close()->find_all(); $crons_executed = 0; foreach ($crontab as $cron) { //check if cron is running, if running but passed treshold, lets launch it again... if ($cron->running == 0 or $cron->running == 1 and time() - Date::mysql2unix($cron->date_started) >= self::TRESHOLD) { $cron->execute(); $crons_executed++; } } $seconds = microtime(true) - $time_start; return sprintf('Executed %d cronjobs in %d seconds', $crons_executed, $seconds); }
public function action_forum() { $this->auto_render = FALSE; $info = array('title' => 'RSS Forum ' . Core::config('general.site_name'), 'pubDate' => date("r"), 'description' => __('Latest post published'), 'generator' => 'Open Classifieds'); $items = array(); $topics = new Model_Topic(); if (Model_Forum::current()->loaded()) { $topics->where('id_forum', '=', Model_Forum::current()->id_forum); } else { $topics->where('id_forum', '!=', NULL); } //any forum $topics = $topics->where('status', '=', Model_Topic::STATUS_ACTIVE)->where('id_post_parent', 'IS', NULL)->order_by('created', 'desc')->limit(Core::config('advertisement.feed_elements'))->cached()->find_all(); foreach ($topics as $topic) { $url = Route::url('forum-topic', array('seotitle' => $topic->seotitle, 'forum' => $topic->forum->seoname)); $items[] = array('title' => htmlspecialchars($topic->title, ENT_QUOTES), 'link' => $url, 'pubDate' => Date::mysql2unix($topic->created), 'description' => htmlspecialchars(Text::removebbcode($topic->description), ENT_QUOTES), 'guid' => $url); } $xml = Feed::create($info, $items); $this->response->headers('Content-type', 'text/xml'); $this->response->body($xml); }
?> " onclick="return confirm('<?php echo __('Make featured?'); ?> ');" rel="tooltip" title="<?php echo __('Featured'); ?> " data-id="tr1" data-text="<?php echo __('Are you sure you want to make it featured?'); ?> "> <i class="glyphicon glyphicon-bookmark"></i> </a> <?elseif(Date::mysql2unix($ad->featured) > time()):?> <a class="btn btn-primary " href="<?php echo Route::url('oc-panel', array('controller' => 'ad', 'action' => 'unfeature', 'id' => $ad->id_ad)); ?> " onclick="return confirm('<?php echo __('Remove featured?'); ?> ');" rel="tooltip" title="<?php echo __('Remove Featured'); ?> " data-id="tr1" data-text="<?php echo __('Are you sure you want to remove featured ad?'); ?>
?> " alt="<?php echo __('Profile image'); ?> " height="140px"></a> </div> <div class="col-xs-12 col-sm-12 col-md-9 span6"> <div class="row"> <div class="col-xs-12 col-sm-12 col-md-12 span6"> <ul class="meta-search list-inline"> <li><i class="glyphicon glyphicon-calendar"></i> <span><?php echo $review->created; ?> </span></li> <li><i class="glyphicon glyphicon-time"></i> <span><?php echo Date::fuzzy_span(Date::mysql2unix($review->created)); ?> </span></li> <li><i class="glyphicon glyphicon-user"></i> <span><?php echo $review->user->name; ?> </span></li> <?php if ($review->rate !== NULL) { ?> <div class="rating"> <h1 class="rating-num"><?php echo round($review->rate, 2); ?> .0</h1>
/** * Gets all images * @return [array] [array with image names] */ public function get_images() { $image_path = array(); if ($this->loaded() and $this->has_images > 0) { $base = Core::S3_domain(); $route = $this->image_path(); $folder = DOCROOT . $route; $seotitle = $this->seotitle; $version = $this->last_modified ? '?v=' . Date::mysql2unix($this->last_modified) : NULL; for ($i = 1; $i <= $this->has_images; $i++) { $filename_thumb = 'thumb_' . $seotitle . '_' . $i . '.jpg'; $filename_original = $seotitle . '_' . $i . '.jpg'; $image_path[$i]['image'] = $base . $route . $filename_original . $version; $image_path[$i]['thumb'] = $base . $route . $filename_thumb . $version; } } return $image_path; }
/** * verifies a license in a certain device * @param string $license * @param string $device_id name * @return bool */ public static function verify_device($license_num, $device_id) { $license = self::get_license($license_num); if ($license->loaded()) { //this means the license was at some point activated if ($license->active_date != NULL and $license->active_date != '') { //if license expired return false if ($license->valid_date != NULL and $license->valid_date != '' and Date::mysql2unix($license->valid_date) < time()) { return FALSE; } //check device_id for the license. if matched if ($license->device_id != $device_id) { return FALSE; } } else { $license->active_date = Date::unix2mysql(); $license->device_id = $device_id; } $license->license_check_date = Date::unix2mysql(); $license->ip_address = ip2long(Request::$client_ip); $license->save(); return TRUE; } return FALSE; }
/** * Gets all images * @return [array] [array with image names] */ public function get_images() { $image_path = array(); if ($this->loaded() and $this->has_images > 0) { if (core::config('image.aws_s3_active')) { $protocol = Core::is_HTTPS() ? 'https://' : 'http://'; $base = $protocol . core::config('image.aws_s3_domain'); } else { $base = URL::base(); } $route = $this->gen_img_path($this->id_product, $this->created); $folder = DOCROOT . $route; $seotitle = $this->seotitle; $version = $this->updated ? '?v=' . Date::mysql2unix($this->updated) : NULL; for ($i = 1; $i <= $this->has_images; $i++) { $filename_thumb = 'thumb_' . $seotitle . '_' . $i . '.jpg'; $filename_original = $seotitle . '_' . $i . '.jpg'; $image_path[$i]['image'] = $route . $filename_original . $version; $image_path[$i]['thumb'] = $route . $filename_thumb . $version; $image_path[$i]['base'] = $base; } } return $image_path; }
/** * verifies pricing in an existing order * @return void */ public function check_pricing() { //original coupon so we dont lose it while we do operations $orig_coupon = $this->id_coupon; //remove the coupon forced by get/post if (core::request('coupon_delete') != NULL) { $this->id_coupon = NULL; } elseif ($this->product->valid_coupon() and $this->id_coupon != Model_Coupon::current()->id_coupon) { $this->id_coupon = Model_Coupon::current()->id_coupon; } elseif ($this->coupon->loaded() and (Date::mysql2unix($this->coupon->valid_date) < time() or $this->coupon->status == 0 or $this->coupon->number_coupons == 0)) { Alert::set(Alert::INFO, __('Coupon not valid, expired or already used.')); $this->coupon->clear(); $this->id_coupon = NULL; } $user = $this->user; //recalculate price since it change the coupon or user info if ($orig_coupon != $this->id_coupon or $this->country != $user->country or $this->city != $user->city or $this->VAT_number != $user->VAT_number or $this->postal_code != $user->postal_code or $this->address != $user->address) { //set variables just in case... $this->amount = $this->product->final_price(); $this->VAT = euvat::vat_percentage(); $this->VAT_number = $user->VAT_number; $this->country = $user->country; $this->city = $user->city; $this->postal_code = $user->postal_code; $this->address = $user->address; try { $this->save(); } catch (Exception $e) { throw HTTP_Exception::factory(500, $e->getMessage()); } } }
/** * returns the url of the location icon * @return string url */ public function get_icon() { if ($this->has_image) { if (core::config('image.aws_s3_active')) { $protocol = Core::is_HTTPS() ? 'https://' : 'http://'; $version = $this->last_modified ? '?v=' . Date::mysql2unix($this->last_modified) : NULL; return $protocol . core::config('image.aws_s3_domain') . 'images/locations/' . $this->seoname . '.png' . $version; } else { return URL::base() . 'images/locations/' . $this->seoname . '.png' . ($this->last_modified ? '?v=' . Date::mysql2unix($this->last_modified) : NULL); } } return FALSE; }
public function action_profile() { $this->auto_render = FALSE; $xml = 'FALSE'; $seoname = $this->request->param('seoname', NULL); if ($seoname !== NULL) { $user = new Model_User(); $user->where('seoname', '=', $seoname)->where('status', '=', Model_User::STATUS_ACTIVE)->limit(1)->cached()->find(); if ($user->loaded()) { $info = array('title' => 'RSS ' . htmlspecialchars($user->name, ENT_QUOTES), 'pubDate' => date("r"), 'description' => htmlspecialchars($user->name . ' - ' . $user->description, ENT_QUOTES), 'generator' => 'Yclas', 'link' => Route::url('profile', array('seoname' => $seoname))); $items = array(); //last ads, you can modify this value at: advertisement.feed_elements $ads = new Model_Ad(); $ads->where('status', '=', Model_Ad::STATUS_PUBLISHED)->where('id_user', '=', $user->id_user)->order_by('published', 'desc')->limit(Core::config('advertisement.feed_elements')); $ads = $ads->cached()->find_all(); foreach ($ads as $a) { $url = Route::url('ad', array('category' => $a->category->seoname, 'seotitle' => $a->seotitle)); $item = array('title' => htmlspecialchars($a->title, ENT_QUOTES), 'link' => $url, 'pubDate' => Date::mysql2unix($a->published), 'description' => htmlspecialchars(Text::removebbcode($a->description), ENT_QUOTES), 'guid' => $url); if ($a->get_first_image() !== NULL) { $item['description'] = '<img src="' . $a->get_first_image() . '" />' . $item['description']; } $items[] = $item; } $xml = Feed::create($info, $items); } } $this->response->headers('Content-type', 'text/xml'); $this->response->body($xml); }
<p> <strong><?php echo __('Price'); ?> </strong>: <?php echo i18n::money_format($message->price); ?> </p> <?php } ?> </div> </div> <div class="text-right mess-date"><small><?php echo Date::fuzzy_span(Date::mysql2unix($message->created)); ?> - <?php echo $message->created; ?> </small></div> </div> </div> <?php } ?> <div> <form method="post" action="<?php echo Route::url('oc-panel', array('controller' => 'messages', 'action' => 'message', 'id' => Request::current()->param('id'))); ?>
/** * * generate sitemap */ public static function generate($force = FALSE) { //start time $start_time = microtime(TRUE); $site_url = Core::config('general.base_url'); // include class require Kohana::find_file('vendor/sitemap', 'SitemapGenerator'); // create object $sitemap = new SitemapGenerator($site_url, DOCROOT); // will create also compressed (gzipped) sitemap $sitemap->createGZipFile = TRUE; // determine how many urls should be put into one file $sitemap->maxURLsPerSitemap = 10000; // sitemap file name $sitemap->sitemapFileName = 'sitemap.xml'; // sitemap index file name $sitemap->sitemapIndexFileName = 'sitemap-index.xml'; // robots file name //$sitemap->robotsFileName = 'robots.txt'; //users $users = new Model_User(); $users = $users->select('seoname')->select('created')->where('status', '=', Model_User::STATUS_ACTIVE)->find_all(); foreach ($users as $user) { $url = Route::url('profile', array('seoname' => $user->seoname)); $sitemap->addUrl($url, date('c', Date::mysql2unix($user->created)), 'monthly', '0.5'); } //pages CMS $pages = new Model_Content(); $pages = $pages->select('seotitle')->where('type', '=', 'page')->where('status', '=', '1')->find_all(); foreach ($pages as $page) { $url = Route::url('page', array('seotitle' => $page->seotitle)); $sitemap->addUrl($url, date('c', Date::mysql2unix($page->created)), 'monthly', '0.5'); } //FAQ CMS if (core::config('general.faq') == 1) { $pages = new Model_Content(); $pages = $pages->select('seotitle')->where('type', '=', 'help')->where('status', '=', '1')->find_all(); $sitemap->addUrl(Route::url('faq'), date('c'), 'monthly', '0.5'); foreach ($pages as $page) { $url = Route::url('faq', array('seotitle' => $page->seotitle)); $sitemap->addUrl($url, date('c', Date::mysql2unix($page->created)), 'monthly', '0.5'); } } //locations $locs = new Model_Location(); $locs = $locs->select('seoname')->where('id_location', '!=', 1)->find_all(); //categories $cats = new Model_Category(); $cats = $cats->select('seoname')->where('id_category', '!=', 1)->find_all(); foreach ($cats as $cat) { $url = Route::url('list', array('category' => $cat->seoname)); $sitemap->addUrl($url, date('c'), 'daily', '0.7'); //adding the categories->locations foreach ($locs as $loc) { $url = Route::url('list', array('category' => $cat->seoname, 'location' => $loc->seoname)); $sitemap->addUrl($url, date('c'), 'weekly', '0.5'); } } //all the ads $ads = DB::select('a.seotitle')->select(array('c.seoname', 'category'))->from(array('ads', 'a'))->join(array('categories', 'c'), 'INNER')->on('a.id_category', '=', 'c.id_category')->where('a.status', '=', Model_Ad::STATUS_PUBLISHED)->as_object()->execute(); foreach ($ads as $a) { $url = Route::url('ad', array('category' => $a->category, 'seotitle' => $a->seotitle)); $sitemap->addUrl($url, date('c'), 'monthly', '0.5'); } //all the blog posts if (core::config('general.blog') == 1) { $sitemap->addUrl(Route::url('blog'), date('c'), 'daily', '0.7'); $posts = new Model_Post(); $posts = $posts->where('status', '=', 1)->where('id_forum', 'IS', NULL)->order_by('created', 'desc')->find_all(); foreach ($posts as $post) { $url = Route::url('blog', array('seotitle' => $post->seotitle)); $sitemap->addUrl($url, date('c'), 'monthly', '0.5'); } } //all the forums and topics if (core::config('general.forums') == 1) { $sitemap->addUrl(Route::url('forum-home'), date('c'), 'monthly', '0.5'); $forums = new Model_Forum(); $forums = $forums->select('seoname')->find_all(); foreach ($forums as $forum) { $url = Route::url('forum-list', array('forum' => $forum->seoname)); $sitemap->addUrl($url, date('c'), 'daily', '0.7'); } //all the topics $posts = new Model_Post(); $posts = $posts->where('status', '=', Model_Post::STATUS_ACTIVE)->where('id_forum', 'IS NOT', NULL)->where('id_post_parent', 'IS', NULL)->order_by('created', 'desc')->find_all(); foreach ($posts as $post) { $url = Route::url('forum-topic', array('seotitle' => $post->seotitle, 'forum' => $post->forum->seoname)); $sitemap->addUrl($url, date('c'), 'daily', '0.7'); } } try { // create sitemap $sitemap->createSitemap(); // write sitemap as file $sitemap->writeSitemap(); // update robots.txt file //$sitemap->updateRobots(); // submit sitemaps to search engines $result = $sitemap->submitSitemap(); // shows each search engine submitting status // echo '<pre>'.print_r($result,1).'</pre>'; } catch (Exception $exc) { echo $exc->getTraceAsString(); } $ret = 'Memory peak ' . round(memory_get_peak_usage() / (1024 * 1024), 2) . ' MB -'; return $ret . ' Time: ' . round(microtime(TRUE) - $start_time, 2) . 's'; }
/** * @dataProvider provider_unix2mysql */ public function test_mysql2unix($time, $mysql) { $this->assertEquals(Date::mysql2unix($mysql), $time); }
/** * API that return the products. * Allows api/products/<category_optional>?order1=rate&sort=asc&order2=version&sort=desc * @return [type] [description] */ public function action_products() { $this->auto_render = FALSE; $sort_allowed = array('asc', 'desc'); $order_allowed = array('id_category', 'created', 'updated', 'price', 'title', 'rate'); $order1 = Core::get('order1'); //default value if (!in_array($order1, $order_allowed) or $order1 === NULL) { $order1 = 'id_category'; } $sort1 = Core::get('sort1'); //default value if (!in_array($sort1, $sort_allowed) or $sort1 === NULL) { $sort1 = 'asc'; } $order2 = Core::get('order2'); //default value if (!in_array($order2, $order_allowed) or $order2 === NULL) { $order2 = 'price'; } $sort2 = Core::get('sort2'); //default value if (!in_array($sort2, $sort_allowed) or $sort2 === NULL) { $sort2 = 'asc'; } $items = array(); //products filtered $products = new Model_Product(); $products = $products->where('status', '=', Model_Product::STATUS_ACTIVE)->order_by($order1, $sort1)->order_by($order2, $sort2); //filter by category $seo_category = $this->request->param('id'); if ($seo_category !== NULL) { $category = new Model_Category(); $category->where('seoname', '=', $seo_category)->limit(1)->find(); if ($category->loaded()) { $products->where('id_category', '=', $category->id_category); } } $products = $products->cached()->find_all(); $i = 0; foreach ($products as $p) { $url = Route::url('product', array('seotitle' => $p->seotitle, 'category' => $p->category->seoname)); $urlmin = Route::url('product-minimal', array('seotitle' => $p->seotitle, 'category' => $p->category->seoname)); $in_offer = Date::mysql2unix($p->offer_valid) > time() ? TRUE : FALSE; $items[] = array('id_product' => $p->id_product, 'order' => $i, 'title' => $p->title, 'seoname' => $p->seotitle, 'skins' => $p->skins, 'url_more' => $url, 'url_buy' => $url, 'url_demo' => !empty($p->url_demo) ? Route::url('product-demo', array('seotitle' => $p->seotitle, 'category' => $p->category->seoname)) : '', 'url_screenshot' => URL::base() . $p->get_first_image('image'), 'type' => $p->category->seoname, 'price' => $p->price, 'currency' => $p->currency, 'price_offer' => $in_offer === TRUE ? $p->price_offer : NULL, 'offer_valid' => $in_offer === TRUE ? $p->offer_valid : NULL, 'rate' => $p->rate, 'created' => $p->created, 'updated' => $p->updated, 'version' => $p->version, 'description' => Text::removebbcode(preg_replace('/&(?!\\w+;)/', '&', $p->description))); $i++; } $this->response->headers('Content-type', 'application/javascript'); $this->response->body(json_encode($items)); }
/** * * NEW ADVERTISEMENT * */ public function action_index() { //advertisement.only_admin_post if (Core::config('advertisement.only_admin_post') == TRUE and (!Auth::instance()->logged_in() or Auth::instance()->logged_in() and !$this->user->is_admin())) { $this->redirect(Route::url('default')); } elseif ((Core::config('advertisement.login_to_post') == TRUE or Core::config('payment.stripe_connect') == TRUE or Core::config('general.subscriptions') == TRUE) and !Auth::instance()->logged_in()) { Alert::set(Alert::INFO, __('Please, login before posting advertisement!')); HTTP::redirect(Route::url('oc-panel', array('controller' => 'auth', 'action' => 'login')) . '?auth_redirect=' . URL::current()); } elseif (core::config('general.black_list') == TRUE and Model_User::is_spam(Core::post('email')) === TRUE) { Alert::set(Alert::ALERT, __('Your profile has been disable for posting, due to recent spam content! If you think this is a mistake please contact us.')); $this->redirect(Route::url('default')); } elseif (Core::config('payment.stripe_connect') == TRUE and empty($this->user->stripe_user_id)) { Alert::set(Alert::INFO, __('Please, connect with Stripe')); $this->redirect(Route::url('oc-panel', array('controller' => 'profile', 'action' => 'edit'))); } elseif (Core::config('general.subscriptions') == TRUE and Theme::get('premium') == TRUE) { $subscription = $this->user->subscription(); //if theres no subscription or expired or without free ads if (!$subscription->loaded() or $subscription->loaded() and (Date::mysql2unix($subscription->expire_date) < time() or $subscription->amount_ads_left == 0)) { Alert::set(Alert::INFO, __('Please, choose a plan first')); HTTP::redirect(Route::url('pricing')); } } //validates captcha if (Core::post('ajaxValidateCaptcha')) { $this->auto_render = FALSE; $this->template = View::factory('js'); if (captcha::check('publish_new', TRUE)) { $this->template->content = 'true'; } else { $this->template->content = 'false'; } return; } Controller::$full_width = TRUE; //template header $this->template->title = __('Publish new advertisement'); $this->template->meta_description = __('Publish new advertisement'); $this->template->styles = array('css/jquery.sceditor.default.theme.min.css' => 'screen', 'css/jasny-bootstrap.min.css' => 'screen', '//cdnjs.cloudflare.com/ajax/libs/selectize.js/0.12.1/css/selectize.bootstrap3.min.css' => 'screen', '//cdn.jsdelivr.net/sweetalert/1.1.3/sweetalert.css' => 'screen'); $this->template->scripts['footer'][] = 'js/jquery.sceditor.bbcode.min.js'; $this->template->scripts['footer'][] = 'js/jasny-bootstrap.min.js'; $this->template->scripts['footer'][] = '//cdn.jsdelivr.net/sweetalert/1.1.3/sweetalert.min.js'; $this->template->scripts['footer'][] = '//cdnjs.cloudflare.com/ajax/libs/selectize.js/0.12.1/js/standalone/selectize.min.js'; $this->template->scripts['footer'][] = '//cdnjs.cloudflare.com/ajax/libs/ouibounce/0.0.10/ouibounce.min.js'; $this->template->scripts['footer'][] = 'js/canvasResize.js'; if (core::config('advertisement.map_pub_new')) { $this->template->scripts['async_defer'][] = '//maps.google.com/maps/api/js?libraries=geometry&v=3&key=' . core::config("advertisement.gm_api_key") . '&callback=initLocationsGMap'; } $this->template->scripts['footer'][] = 'js/new.js?v=' . Core::VERSION; $categories = new Model_Category(); $categories = $categories->where('id_category_parent', '=', '1'); // NO categories redirect ADMIN to categories panel if ($categories->count_all() == 0) { if (Auth::instance()->logged_in() and Auth::instance()->get_user()->is_admin()) { Alert::set(Alert::INFO, __('Please, first create some categories.')); $this->redirect(Route::url('oc-panel', array('controller' => 'category', 'action' => 'index'))); } else { Alert::set(Alert::INFO, __('Posting advertisements is not yet available.')); $this->redirect(Route::url('default')); } } //get locations $locations = new Model_Location(); $locations = $locations->where('id_location', '!=', '1'); // bool values from DB, to show or hide this fields in view $form_show = array('captcha' => core::config('advertisement.captcha'), 'website' => core::config('advertisement.website'), 'phone' => core::config('advertisement.phone'), 'location' => core::config('advertisement.location'), 'description' => core::config('advertisement.description'), 'address' => core::config('advertisement.address'), 'price' => core::config('advertisement.price')); $id_category = NULL; $selected_category = new Model_Category(); //if theres a category by post or by get if (Core::request('category') !== NULL) { if (is_numeric(Core::request('category'))) { $selected_category->where('id_category', '=', core::request('category'))->limit(1)->find(); } else { $selected_category->where('seoname', '=', core::request('category'))->limit(1)->find(); } if ($selected_category->loaded()) { $id_category = $selected_category->id_category; } } $id_location = NULL; $selected_location = new Model_Location(); //if theres a location by post or by get if (Core::request('location') !== NULL) { if (is_numeric(Core::request('location'))) { $selected_location->where('id_location', '=', core::request('location'))->limit(1)->find(); } else { $selected_location->where('seoname', '=', core::request('location'))->limit(1)->find(); } if ($selected_location->loaded()) { $id_location = $selected_location->id_location; } } //render view publish new $this->template->content = View::factory('pages/ad/new', array('form_show' => $form_show, 'id_category' => $id_category, 'selected_category' => $selected_category, 'id_location' => $id_location, 'selected_location' => $selected_location, 'fields' => Model_Field::get_all())); if ($this->request->post()) { if (captcha::check('publish_new')) { $data = $this->request->post(); $validation = Validation::factory($data); //validate location since its optional if (core::config('advertisement.location')) { if ($locations->count_all() > 1) { $validation = $validation->rule('location', 'not_empty')->rule('location', 'digit'); } } //user is not logged in validate input if (!Auth::instance()->logged_in()) { $validation = $validation->rule('email', 'not_empty')->rule('email', 'email')->rule('email', 'email_domain')->rule('name', 'not_empty')->rule('name', 'min_length', array(':value', 2))->rule('name', 'max_length', array(':value', 145)); } // Optional banned words validation if (core::config('advertisement.validate_banned_words')) { $validation = $validation->rule('title', 'no_banned_words'); $validation = $validation->rule('description', 'no_banned_words'); } if ($validation->check()) { // User detection, if doesnt exists create if (!Auth::instance()->logged_in()) { $user = Model_User::create_email(core::post('email'), core::post('name')); } else { $user = Auth::instance()->get_user(); } //to make it backward compatible with older themes: UGLY!! if (isset($data['category']) and is_numeric($data['category'])) { $data['id_category'] = $data['category']; unset($data['category']); } if (isset($data['location']) and is_numeric($data['location'])) { $data['id_location'] = $data['location']; unset($data['location']); } //lets create!! $return = Model_Ad::new_ad($data, $user); //there was an error on the validation if (isset($return['validation_errors']) and is_array($return['validation_errors'])) { foreach ($return['validation_errors'] as $f => $err) { Alert::set(Alert::ALERT, $err); } } elseif (isset($return['error'])) { Alert::set($return['error_type'], $return['error']); } elseif (isset($return['message']) and isset($return['ad'])) { $new_ad = $return['ad']; // IMAGE UPLOAD $filename = NULL; for ($i = 0; $i < core::config('advertisement.num_images'); $i++) { if (Core::post('base64_image' . $i)) { $filename = $new_ad->save_base64_image(Core::post('base64_image' . $i)); } elseif (isset($_FILES['image' . $i])) { $filename = $new_ad->save_image($_FILES['image' . $i]); } } Alert::set(Alert::SUCCESS, $return['message']); //redirect user if (isset($return['checkout_url']) and !empty($return['checkout_url'])) { $this->redirect($return['checkout_url']); } else { $this->redirect(Route::url('default', array('action' => 'thanks', 'controller' => 'ad', 'id' => $new_ad->id_ad))); } } } else { $errors = $validation->errors('ad'); foreach ($errors as $f => $err) { Alert::set(Alert::ALERT, $err); } } } else { Alert::set(Alert::ALERT, __('Captcha is not correct')); } } }
/** * reurns the url of the users profile image * @return string url */ public function get_profile_image() { if ($this->has_image) { if (core::config('image.aws_s3_active')) { $protocol = Core::is_HTTPS() ? 'https://' : 'http://'; $version = $this->last_modified ? '?v=' . Date::mysql2unix($this->last_modified) : NULL; return $protocol . core::config('image.aws_s3_domain') . 'images/users/' . $this->id_user . '.png' . $version; } else { return URL::base() . 'images/users/' . $this->id_user . '.png' . ($this->last_modified ? '?v=' . Date::mysql2unix($this->last_modified) : NULL); } } else { return '//www.gravatar.com/avatar/' . md5(strtolower(trim($this->email))) . '?s=200'; } }
/** * verifies pricing in an existing order * @return void */ public function check_pricing() { //update order based on the price and the amount of $days = core::get('featured_days'); if (is_numeric($days) and ($price = Model_Order::get_featured_price($days)) !== FALSE) { $this->amount = $price; //get price from config $this->featured_days = $days; $this->save(); } //original coupon so we dont lose it while we do operations $orig_coupon = $this->id_coupon; //remove the coupon forced by get/post if (core::request('coupon_delete') != NULL) { $this->id_coupon = NULL; } elseif (Model_Coupon::valid($this->id_product) and $this->id_coupon != Model_Coupon::current()->id_coupon) { $this->id_coupon = Model_Coupon::current()->id_coupon; } elseif ($this->coupon->loaded() and (Date::mysql2unix($this->coupon->valid_date) < time() or $this->coupon->status == 0 or $this->coupon->number_coupons == 0)) { Alert::set(Alert::INFO, __('Coupon not valid, expired or already used.')); $this->coupon->clear(); $this->id_coupon = NULL; } //add new discount $new_amount = Model_Coupon::price($this->id_product, $this->original_price()); //recalculate price since it change the coupon if ($orig_coupon != $this->id_coupon or $this->amount != $new_amount) { $this->amount = $new_amount; try { $this->save(); } catch (Exception $e) { throw HTTP_Exception::factory(500, $e->getMessage()); } } }
</td> <td class="col-md-2"> </td> <td class="col-md-2 text-center text-danger"> -<?php echo i18n::format_currency($discount, $order->currency); ?> </td> </tr> <?php } ?> <?php if ($order->VAT > 0 or euvat::is_eu_country($order->country) and core::config('general.eu_vat') == TRUE and Date::mysql2unix($order->created) >= strtotime(euvat::$date_start)) { ?> <tr> <td></td> <td></td> <td class="text-right"><h4><strong><?php echo __('Sub Total'); ?> : </strong></h4></td> <td class="text-center"> <h4> <?php if (!$order->coupon->loaded()) { ?> <?php