/**
  * AJAX callback method
  *
  * @return void
  */
 public function run()
 {
     // check nonce
     $this->check_nonce();
     // @todo set filters
     $filters = array();
     // get filters from get vars
     foreach ($_GET as $get_key => $get_var) {
         if (0 === strpos($get_key, 'filter_')) {
             $filters[str_ireplace('filter_', '', $get_key)] = absint($get_var);
         }
     }
     // get vehicles
     $vehicle_manager = new Vehicle\Manager();
     $vehicles = $vehicle_manager->get_vehicles($filters);
     // check & loop
     if (count($vehicles) > 0) {
         foreach ($vehicles as $vehicle) {
             // title
             $title = get_the_title($vehicle->get_id());
             // get image
             $image = get_the_post_thumbnail($vehicle->get_id(), apply_filters('wpcm_listings_vehicle_thumbnail_size', 'wpcm_vehicle_listings_item'), array('title' => $title, 'alt' => $title, 'class' => 'wpcm-listings-item-image'));
             // load template
             wp_car_manager()->service('template_manager')->get_template_part('listings/item', '', array('url' => get_permalink($vehicle->get_id()), 'title' => $title, 'image' => $image, 'description' => $vehicle->get_short_description(), 'price' => $vehicle->get_formatted_price(), 'mileage' => $vehicle->get_formatted_mileage(), 'frdate' => $vehicle->get_formatted_frdate()));
         }
     } else {
         wp_car_manager()->service('template_manager')->get_template_part('listings/no-results', '', array());
     }
     // bye
     exit;
 }
 /**
  * AJAX callback method
  *
  * @return void
  */
 public function run()
 {
     // check nonce
     $this->check_nonce();
     // set sort
     $sort = isset($_GET['sort']) ? esc_attr($_GET['sort']) : 'price-desc';
     // get vehicles
     $vehicle_manager = new Vehicle\Manager();
     $vehicles = $vehicle_manager->get_vehicles(array(), $sort, -1, array('author' => get_current_user_id(), 'post_status' => apply_filters('wpcm_dashboard_post_status', array('publish', 'expired', 'pending'))));
     // check & loop
     if (count($vehicles) > 0) {
         // Today
         $today = new \DateTime();
         $today->setTime(0, 0, 0);
         foreach ($vehicles as $vehicle) {
             // title
             $title = get_the_title($vehicle->get_id());
             // check if there's a thumbnail
             if (has_post_thumbnail($vehicle->get_id())) {
                 // get image
                 $image = get_the_post_thumbnail($vehicle->get_id(), apply_filters('wpcm_dashboard_vehicle_thumbnail_size', 'wpcm_vehicle_listings_item'), array('title' => $title, 'alt' => $title, 'class' => 'wpcm-dashboard-item-image'));
             } else {
                 $placeholder = apply_filters('wpcm_dashboard_vehicle_thumbnail_placeholder', wp_car_manager()->service('file')->image_url('placeholder-list.png'), $vehicle);
                 $image = sprintf('<img src="%s" alt="%s" class="wpcm-dashboard-item-image" />', $placeholder, __('Placeholder', 'wp-car-manager'));
             }
             $expires = 'n/a';
             if (null != $vehicle->get_expiration()) {
                 if ($today > $vehicle->get_expiration()) {
                     $expires = __('Expired', 'wp-car-manager');
                 } else {
                     $expires = $vehicle->get_expiration()->format('d-m-Y');
                 }
             }
             // load template
             wp_car_manager()->service('template_manager')->get_template_part('dashboard/item', '', array('id' => $vehicle->get_id(), 'url' => $vehicle->get_url(), 'title' => $title, 'image' => $image, 'price' => $vehicle->get_formatted_price(), 'mileage' => $vehicle->get_formatted_mileage(), 'frdate' => $vehicle->get_formatted_frdate(), 'expires' => $expires, 'vehicle' => $vehicle));
         }
     } else {
         wp_car_manager()->service('template_manager')->get_template_part('dashboard/no-results', '', array());
     }
     // bye
     exit;
 }
Beispiel #3
0
 /**
  * Start loading classes on `plugins_loaded`, priority 20.
  */
 private function load()
 {
     $container = $this;
     // Load plugin text domain
     load_plugin_textdomain('wp-car-manager', false, $container['file']->dirname() . '/languages/');
     // register post type & taxonomies
     add_action('init', function () {
         Vehicle\PostType::register();
         Taxonomies::register_model_make();
         Taxonomies::register_features();
     });
     // register image sizes
     add_action('init', function () {
         add_image_size('wpcm_vehicle_single', 600, 400, true);
         add_image_size('wpcm_vehicle_thumbnail', 150, 150, true);
         add_image_size('wpcm_vehicle_listings_item', 100, 100, true);
     });
     // Post status object
     $post_status = new PostStatus();
     $post_status->setup();
     // expiration cron-job callback
     add_action('wpcm_crob_set_expired', function () {
         $manager = new Vehicle\Manager();
         $manager->mark_vehicles_expired();
     });
     if (is_admin()) {
         // add admin menu
         add_action('admin_menu', function () {
             // admin page Makes
             $page_makes = new Admin\Page\Makes();
             $page_makes->init();
             // admin page Settings
             $page_settings = new Admin\Page\Settings();
             $page_settings->init();
         });
         // add extensions page
         add_action('admin_menu', function () {
             $page_extensions = new Admin\Page\Extensions();
             $page_extensions->init();
         }, 20);
         // license AJAX callback
         add_action('wp_ajax_wpcm_extension', array('Never5\\WPCarManager\\Admin\\Page\\Extensions', 'ajax_license_action'));
         // add meta box
         add_action('admin_init', function () {
             // listing data
             $listing_data = new Admin\MetaBox\ListingData();
             $listing_data->init();
             // car data
             $car_data = new Admin\MetaBox\CarData();
             $car_data->init();
             // car gallery
             $gallery = new Admin\MetaBox\Gallery();
             $gallery->init();
             // short description
             if (function_exists('wp_editor')) {
                 $short_description = new Admin\MetaBox\ShortDescription();
                 $short_description->init();
             }
         });
         // admin settings
         add_action('admin_init', function () use($container) {
             $container['settings']->register_settings();
         });
         // admin assets
         add_action('admin_enqueue_scripts', array('Never5\\WPCarManager\\Assets', 'enqueue_backend'));
         // admin custom columns
         $custom_columns = new Admin\CustomColumns();
         $custom_columns->setup();
         // admin custom actions
         $custom_actions = new Admin\CustomActions();
         $custom_actions->listen();
         // upgrade manager
         add_action('admin_init', function () {
             $upgrade_manager = new Util\Upgrade();
             $upgrade_manager->run();
         });
         // setup onboarding
         $onboarding = new Util\Onboarding();
         $onboarding->setup();
         // setup rewrites util
         $rewrites = new Util\Rewrites();
         // listen to language changes
         $rewrites->listen_language_change();
         // flush when needed
         $rewrites->maybe_flush();
         // load extensions
         add_action('admin_init', function () {
             // Load the registered extensions
             $registered_extensions = apply_filters('wpcm_extensions', array());
             // Check if we've got extensions
             if (count($registered_extensions) > 0) {
                 // Don't block local requests
                 add_filter('block_local_requests', '__return_false');
                 // Load products
                 Extension\Manager::get()->load_extensions($registered_extensions);
             }
         });
     } else {
         // Include template functions
         require_once $container['file']->plugin_path() . '/includes/template-hooks.php';
         require_once $container['file']->plugin_path() . '/includes/template-functions.php';
         // init template manager to enable template overrides
         $container['template_manager']->init();
         // assets
         add_action('wp_enqueue_scripts', array('Never5\\WPCarManager\\Assets', 'enqueue_frontend'));
         // setup shortcode
         add_action('init', function () use($container) {
             $shortcode_cars = new Shortcode\Cars();
             $shortcode_submit_car_form = new Shortcode\SubmitCarForm();
             $shortcode_dashboard = new Shortcode\Dashboard();
         });
         // init submit car handler
         add_action('wp_loaded', function () use($container) {
             $container['submit_car_handler']->init();
         });
         // setup custom AJAX
         $ajax_manager = new Ajax\Manager();
         $ajax_manager->setup();
     }
 }
 /**
  * AJAX callback method
  *
  * @return void
  */
 public function run()
 {
     // check nonce
     $this->check_nonce();
     // set filters
     $filters = array();
     // get filters from get vars
     foreach ($_GET as $get_key => $get_var) {
         if (0 === strpos($get_key, 'filter_')) {
             $filters[str_ireplace('filter_', '', $get_key)] = $get_var;
         }
     }
     // set sort
     $sort = isset($_GET['sort']) ? esc_attr($_GET['sort']) : 'price-asc';
     // set per page
     $per_page = intval(wp_car_manager()->service('settings')->get_option('listings_ppp'));
     // correct any funky zero listings per page. I mean, who wants 0 listings per page ...
     if (0 === $per_page) {
         $per_page = -1;
     }
     // get current page
     $page = intval(!empty($_GET['page']) ? $_GET['page'] : 1);
     // check if we need to hide sold cars
     if ('1' == wp_car_manager()->service('settings')->get_option('listings_hide_sold')) {
         $filters['hide_sold'] = true;
     } else {
         $filters['hide_sold'] = false;
     }
     // extra args
     $extra_args = array();
     if ($page > 0) {
         $extra_args['paged'] = $page;
     }
     // get vehicles
     $vehicle_manager = new Vehicle\Manager();
     $vehicles = $vehicle_manager->get_vehicles($filters, $sort, $per_page, $extra_args);
     // get total vehicle count for pagination
     $total_vehicle_count = $vehicle_manager->get_total_vehicle_count_of_last_query();
     // start output buffer
     ob_start();
     // check & loop
     if (count($vehicles) > 0) {
         foreach ($vehicles as $vehicle) {
             // title
             $title = get_the_title($vehicle->get_id());
             // check if there's a thumbnail
             if (has_post_thumbnail($vehicle->get_id())) {
                 // get image
                 $image = get_the_post_thumbnail($vehicle->get_id(), apply_filters('wpcm_listings_vehicle_thumbnail_size', 'wpcm_vehicle_listings_item'), array('title' => $title, 'alt' => $title, 'class' => 'wpcm-listings-item-image'));
             } else {
                 $placeholder = apply_filters('wpcm_listings_vehicle_thumbnail_placeholder', wp_car_manager()->service('file')->image_url('placeholder-list.png'), $vehicle);
                 $image = sprintf('<img src="%s" alt="%s" class="wpcm-listings-item-image" />', $placeholder, __('Placeholder', 'wp-car-manager'));
             }
             // load template
             wp_car_manager()->service('template_manager')->get_template_part('listings/item', '', array('url' => $vehicle->get_url(), 'title' => $title, 'image' => $image, 'description' => $vehicle->get_short_description(), 'price' => $vehicle->get_formatted_price(), 'mileage' => $vehicle->get_formatted_mileage(), 'frdate' => $vehicle->get_formatted_frdate(), 'vehicle' => $vehicle));
         }
     } else {
         wp_car_manager()->service('template_manager')->get_template_part('listings/no-results', '', array());
     }
     // put listing content in variable
     $listing_content = ob_get_clean();
     // send JSON response
     wp_send_json(array('listings' => $listing_content, 'pagination' => \Never5\WPCarManager\Helper\Pagination::generate($page, \Never5\WPCarManager\Helper\Pagination::calc_total_pages($per_page, $total_vehicle_count))));
     // bye
     exit;
 }