diff options
| Commit | 1c86fe831289eee3d3c2c963885fd553f40f81d2 (patch) | |
|---|---|---|
| Author | 2020-07-15 20:43:05 +0300 | |
| Committer | 2020-07-15 20:43:05 +0300 | |
| Files | 1dc3d183affddf9c040eba8b9ec1e60c9e002d90 | |
| tues-interns-2020-feature/offers-grid.tar tues-interns-2020-feature/offers-grid.tar.gz tues-interns-2020-feature/offers-grid.zip | ||
| Parent | 333668c49e98cdfc84cf0702f289bd149fc5fd25 (diff) | |
[fix] bring changes from master feature/offers-grid
19 files changed, 824 insertions, 167 deletions
diff --git a/wp-content/plugins/dx-cars/class.cpt.php b/wp-content/plugins/dx-cars/class.cpt.php deleted file mode 100644 index 378a082..0000000 --- a/wp-content/plugins/dx-cars/class.cpt.php +++ /dev/null @@ -1,23 +0,0 @@ -<?php -class Vehicles { - function init() { - add_action( 'init', array( $this, 'cpt_create' ) ); - } - - public function labels() { - $arr = array( - 'labels' => array( - 'name' => __( 'Vehicles' ), - 'singular_name' => __( 'Vehicle' ) - ), - 'public' => true, - 'has_archive' => true, - 'rewrite' => array( 'slug' => 'vehicles' ), - 'show_in_rest' => true, ); - return $arr; - } - - function cpt_create() { - register_post_type( 'vehicles', $this->labels() ); - } -} diff --git a/wp-content/plugins/dx-cars/dx-cars.php b/wp-content/plugins/dx-cars/dx-cars.php deleted file mode 100644 index 90cc6ec..0000000 --- a/wp-content/plugins/dx-cars/dx-cars.php +++ /dev/null @@ -1,14 +0,0 @@ -<?php -/** - * Plugin Name: DX Cars - * Plugin URI: https://devrix.com - * Description: Plugin for handling cars - * Version: 0.1 - * Author: DevriX-interns-2020 - * Author URI: https://devrix.com - * Text Domain: dx-cars - */ - include 'class.cpt.php'; - - $cars = new Vehicles; - $cars->init(); diff --git a/wp-content/plugins/dx-users/dx-users.php b/wp-content/plugins/dx-users/dx-users.php new file mode 100644 index 0000000..2d47e6a --- /dev/null +++ b/wp-content/plugins/dx-users/dx-users.php @@ -0,0 +1,21 @@ +<?php +/** + * Plugin Name: DX Users + * Plugin URI: https://devrix.com + * Description: Plugin for handling user login and register + * Version: 0.1 + * Author: DevriX-interns-2020 + * Author URI: https://devrix.com + * Text Domain: dx-users + */ + +defined( 'ABSPATH' ) or die( 'No script kiddies please!' ); + +include 'login-user-class.php'; +include 'register-user-class.php'; + +$login_user = new LoginUser; +$register_user = new RegisterUser; + +$login_user->init(); +$register_user->init(); diff --git a/wp-content/plugins/dx-users/login-user-class.php b/wp-content/plugins/dx-users/login-user-class.php new file mode 100644 index 0000000..7bc4f1e --- /dev/null +++ b/wp-content/plugins/dx-users/login-user-class.php @@ -0,0 +1,24 @@ +<?php +class LoginUser { + function init() { + add_action( 'admin_post_nopriv_process_login', array($this, 'try_login_user' )); + } + + function try_login_user() { + $creds = array( + 'user_login' => sanitize_text_field( $_POST['email'] ), + 'user_password' => sanitize_text_field( $_POST['password'] ), + 'remember' => true + ); + + $user = wp_signon( $creds ); + + if ( is_wp_error( $user ) ) { + wp_die( $user->get_error_message() ); + } + + wp_set_current_user( $user->data->ID ); + + wp_redirect( home_url() ); exit; + } +} diff --git a/wp-content/plugins/dx-users/register-user-class.php b/wp-content/plugins/dx-users/register-user-class.php new file mode 100644 index 0000000..bbadf3c --- /dev/null +++ b/wp-content/plugins/dx-users/register-user-class.php @@ -0,0 +1,31 @@ +<?php +class RegisterUser { + function init() { + add_action( 'admin_post_nopriv_process_register', array( $this, 'process_register_data' )); + } + + function process_register_data() { + if( username_exists( sanitize_text_field( $_POST['password'] ) ) ) { + wp_die( 'User already exists!' ); + } + + $user_data = array( + 'user_pass' => sanitize_text_field( $_POST['password'] ), + 'user_login' => sanitize_text_field( $_POST['email'] ), + 'user_email' => sanitize_text_field( $_POST['email'] ), + 'display_name' => sanitize_text_field( $_POST['name'] ), + ); + + if( ! is_email( $user_data['user_email'] ) ) { + wp_die( 'Invaid email address!' ); + } + + $user_id = wp_insert_user( $user_data ); + + if( is_wp_error( $user_id ) ) { + wp_die( $user_id->get_error_message() ); + } + + wp_redirect( home_url() ); exit; + } +} diff --git a/wp-content/plugins/dx-vehicles/dx-vehicles.php b/wp-content/plugins/dx-vehicles/dx-vehicles.php new file mode 100644 index 0000000..8ad9496 --- /dev/null +++ b/wp-content/plugins/dx-vehicles/dx-vehicles.php @@ -0,0 +1,26 @@ +<?php +/** + * Plugin Name: DX Vehicles + * Plugin URI: https://devrix.com + * Description: Plugin for handling vehicles + * Version: 0.2 + * Author: DevriX-interns-2020 + * Author URI: https://devrix.com + * Text Domain: dx-vehicles + */ + +defined( 'ABSPATH' ) or die( 'No script kiddies please!' ); + +include 'taxonomies-non-hierarchical-class.php'; +include 'taxonomies-hierarchical-class.php'; +include 'vehicles-class.php'; +include 'search-class.php'; + +$cars = new Vehicles; +$tax = new Taxonomies; +$tax1 = new TaxonomiesHierarchical; +$search = new Search; +$cars->init(); +$tax->init(); +$tax1->init(); +$search->init(); diff --git a/wp-content/plugins/dx-vehicles/search-class.php b/wp-content/plugins/dx-vehicles/search-class.php new file mode 100644 index 0000000..cab5544 --- /dev/null +++ b/wp-content/plugins/dx-vehicles/search-class.php @@ -0,0 +1,111 @@ +<?php +class Search { + function init() { + add_action( 'pre_get_posts', array( $this, 'pre_get_posts' ), 1 ); + + add_filter( 'query_vars', array( $this, 'register_query_vars' ) ); + } + + static $tax_vars = array( // tax_name (what is in the request) => tax_key (what is in the database, only hierarchical taxonomies are different from tax_name ) + 'brand' => 'vehicle-type', + 'category' => 'vehicle-category', + 'color' => 'vehicle-color', + 'conditoin' => 'vehicle-condition', + 'fuel' => 'vehicle-fuel', + 'gearbox' => 'vehicle-gearbox', + 'location' => 'vehicle-location', + 'model' => 'vehicle-type', + 'type' => 'vehicle-category', + ); + + static $meta_vars = array( // meta_name (name of post meta, stored in the database) => meta_keys (what is in the request) + 'vehicle-horsepower' => array( + 'start_horsepower', 'end_horsepower' + ), + 'vehicle-price' => array( + 'start_price', 'end_price' + ), + 'vehicle-range' => array( + 'start_range', 'end_range' + ), + 'vehicle-year' => array( + 'start_year', 'end_year' + ), + ); + + function register_query_vars( $vars ) { // didn't use array_merge because it caused some problems + $vars[] = 'search'; + foreach( $this::$tax_vars as $key => $value ) { + $vars[] = $key; + } + foreach( $this::$meta_vars as $key => $value ) { + foreach( $value as $name ) { + $vars[] = $name; + } + } + return $vars; + } + + function get_slug_taxonomy_array( $name, $terms ) { + $taxonomy_arr = array( + 'taxonomy' => $name, + 'field' => 'slug', + 'terms' => $terms, + ); + return $taxonomy_arr; + } + + function get_num_meta_array( $key, $value1, $value2 ) { + $result; + if( ! empty( $value1 ) && ! empty( $value2 ) ) { + $result = array( + 'key' => $key, + 'value' => array( $value1, $value2 ), + 'type' => 'NUMERIC', + 'compare' => 'BETWEEN', + ); + } else if( ! empty( $value1 ) ) { + $result = array( + 'key' => $key, + 'value' => $value1, + 'type' => 'NUMERIC', + 'compare' => '>=', + ); + } else { + $result = array( + 'key' => $key, + 'value' => $value2, + 'type' => 'NUMERIC', + 'compare' => '<=', + ); + } + return $result; + } + + function pre_get_posts( $query ) { + if ( get_query_var( 'search' ) != 'vehicles' ) { + return; + } + + $query->set( 'post_type', 'vehicles' ); + + $tax_query = array(); + + foreach( $this::$tax_vars as $tax_name => $tax_key ) { + if ( ! empty( get_query_var( $tax_name ) ) ) { + $tax_query[] = $this->get_slug_taxonomy_array( $tax_key, get_query_var( $tax_name ) ); + } + } + + $meta_query = array(); + + foreach( $this::$meta_vars as $meta_name => $meta_keys ) { + if ( ! empty( get_query_var( $meta_keys[0] ) ) || ! empty( get_query_var( $meta_keys[1] ) ) ) { + $meta_query[] = $this->get_num_meta_array( $meta_name, get_query_var( $meta_keys[0] ), get_query_var( $meta_keys[1] ) ); + } + } + + $query->set( 'meta_query', $meta_query ); + $query->set( 'tax_query', $tax_query ); + } +} diff --git a/wp-content/plugins/dx-vehicles/taxonomies-hierarchical-class.php b/wp-content/plugins/dx-vehicles/taxonomies-hierarchical-class.php new file mode 100644 index 0000000..82c1089 --- /dev/null +++ b/wp-content/plugins/dx-vehicles/taxonomies-hierarchical-class.php @@ -0,0 +1,65 @@ +<?php + +class TaxonomiesHierarchical { + function init() { + add_action( 'init', array( $this, 'tax_create' ) , 999 ); + } + public function labels() { + $arr = array ( + 'name' => _x( 'Categories', 'taxonomy general name' ), + 'singular_name' => _x( 'Category', 'taxonomy singular name' ), + 'search_items' => __( 'Search Category', 'textdomain' ), + 'all_items' => __( 'All Categories', 'textdomain' ), + 'parent_item' => __( 'Parent Category', 'textdomain' ), + 'parent_item_colon' => __( 'Parent Category:', 'textdomain' ), + 'edit_item' => __( 'Edit Category' ), + 'update_item' => __( 'Update Category' ), + 'add_new_item' => __( 'Add New Category' ), + 'new_item_name' => __( 'New Category Name' ), + 'menu_name' => __( 'Category' ), + ); + return $arr; + } + + public function labels_types() { + $arr = array ( + 'name' => _x( 'Types', 'taxonomy general name' ), + 'singular_name' => _x( 'Type', 'taxonomy singular name' ), + 'search_items' => __( 'Search Type', 'textdomain' ), + 'all_items' => __( 'All Types', 'textdomain' ), + 'parent_item' => __( 'Parent Type', 'textdomain' ), + 'parent_item_colon' => __( 'Parent Type:', 'textdomain' ), + 'edit_item' => __( 'Edit Type' ), + 'update_item' => __( 'Update Type' ), + 'add_new_item' => __( 'Add New Type' ), + 'new_item_name' => __( 'New Type Name' ), + 'menu_name' => __( 'Type' ), + ); + return $arr; + } + + public function tax_create(){ + register_taxonomy( 'vehicle-category', 'vehicles', array( + 'hierarchical' => true, + 'labels' => $this->labels(), + 'show_ui' => true, + 'show_admin_column' => true, + 'show_in_rest' => true, + 'update_count_callback' => '_update_post_term_count', + 'query_var' => true, + 'rewrite' => array( 'slug' => 'vehicle-category' ), + ) + ); + register_taxonomy( 'vehicle-type', 'vehicles', array( + 'hierarchical' => true, + 'labels' => $this->labels_types(), + 'show_ui' => true, + 'show_admin_column' => true, + 'show_in_rest' => true, + 'update_count_callback' => '_update_post_term_count', + 'query_var' => true, + 'rewrite' => array( 'slug' => 'car-type' ), + ) + ); + } +} diff --git a/wp-content/plugins/dx-vehicles/taxonomies-non-hierarchical-class.php b/wp-content/plugins/dx-vehicles/taxonomies-non-hierarchical-class.php new file mode 100644 index 0000000..9ea1330 --- /dev/null +++ b/wp-content/plugins/dx-vehicles/taxonomies-non-hierarchical-class.php @@ -0,0 +1,93 @@ +<?php + +class Taxonomies { + function init() { + add_action( 'init', array( $this, 'tax_create' ) , 999 ); + } + + public function labels($name) { + $arr = array ( + 'name' => _x( $name.'s', 'taxonomy general name' ), + 'singular_name' => _x( $name, 'taxonomy singular name' ), + 'search_items' => __( 'Search '.$name.'s' ), + 'all_items' => __( 'All '.$name.'s' ), + 'parent_item' => null, + 'parent_item_colon' => null, + 'edit_item' => __( 'Edit '.$name ), + 'update_item' => __( 'Update '.$name ), + 'add_new_item' => __( 'Add New '.$name ), + 'new_item_name' => __( 'New '.$name.' Name' ), + 'menu_name' => __( $name.'s' ), + ); + return $arr; + } + + public function tax_create(){ + register_taxonomy( 'vehicle-location', 'vehicles', array( + 'hierarchical' => false, + 'labels' => $this->labels('Location'), + 'show_ui' => true, + 'show_admin_column' => true, + 'show_in_rest' => true, + 'update_count_callback' => '_update_post_term_count', + 'query_var' => true, + 'rewrite' => array( 'slug' => 'location' ), + ) + ); + register_taxonomy( 'vehicle-color', 'vehicles', array( + 'hierarchical' => false, + 'labels' => $this->labels('Color'), + 'show_ui' => true, + 'show_admin_column' => true, + 'show_in_rest' => true, + 'update_count_callback' => '_update_post_term_count', + 'query_var' => true, + 'rewrite' => array( 'slug' => 'color' ), + ) + ); + register_taxonomy( 'vehicle-condition', 'vehicles', array( + 'hierarchical' => false, + 'labels' => $this->labels('Condition'), + 'show_ui' => true, + 'show_admin_column' => true, + 'show_in_rest' => true, + 'update_count_callback' => '_update_post_term_count', + 'query_var' => true, + 'rewrite' => array( 'slug' => 'condition' ), + ) + ); + register_taxonomy( 'vehicle-gearbox', 'vehicles', array( + 'hierarchical' => false, + 'labels' => $this->labels('Gearbox'), + 'show_ui' => true, + 'show_admin_column' => true, + 'show_in_rest' => true, + 'update_count_callback' => '_update_post_term_count', + 'query_var' => true, + 'rewrite' => array( 'slug' => 'gearbox' ), + ) + ); + register_taxonomy( 'vehicle-fuel', 'vehicles', array( + 'hierarchical' => false, + 'labels' => $this->labels('Fuel'), + 'show_ui' => true, + 'show_admin_column' => true, + 'show_in_rest' => true, + 'update_count_callback' => '_update_post_term_count', + 'query_var' => true, + 'rewrite' => array( 'slug' => 'fuel' ), + ) + ); + register_taxonomy( 'vehicle-type', 'vehicles', array( + 'hierarchical' => false, + 'labels' => $this->labels('Type'), + 'show_ui' => true, + 'show_admin_column' => true, + 'show_in_rest' => true, + 'update_count_callback' => '_update_post_term_count', + 'query_var' => true, + 'rewrite' => array( 'slug' => 'car-type' ), + ) + ); + } +} diff --git a/wp-content/plugins/dx-vehicles/vehicle-info-display-callback.php b/wp-content/plugins/dx-vehicles/vehicle-info-display-callback.php new file mode 100644 index 0000000..02d3308 --- /dev/null +++ b/wp-content/plugins/dx-vehicles/vehicle-info-display-callback.php @@ -0,0 +1,35 @@ +<table> + <tr> + <td><?php _e( 'Year:' ) ?></td> + <td><input type="text" name="vehicle-year" value="<?php echo( sanitize_text_field( get_post_meta( get_the_ID(), __( 'vehicle-year' ), true ) ) ) ?>"></td> + </tr> + <tr> + <td><?php _e( 'Millage:' ) ?></td> + <td><input type="text" name="vehicle-millage" value="<?php echo( sanitize_text_field( get_post_meta( get_the_ID(), __( 'vehicle-millage' ), true ) ) ) ?>"></td> + </tr> + <tr> + <td><?php _e( 'Horsepower:' ) ?></td> + <td><input type="text" name="vehicle-horsepower" value="<?php echo( sanitize_text_field( get_post_meta( get_the_ID(), __( 'vehicle-horsepower' ), true ) ) ) ?>"></td> + </tr> + <tr> + <td><?php _e( 'Range:' ) ?></td> + <td><input type="text" name="vehicle-range" value="<?php echo( sanitize_text_field( get_post_meta( get_the_ID(), __( 'vehicle-range' ), true ) ) ) ?>"></td> + </tr> + <tr> + <td><?php _e( 'Price:' ) ?></td> + <td><input type="text" name="vehicle-price" value="<?php echo( sanitize_text_field( get_post_meta( get_the_ID(), __( 'vehicle-price' ), true ) ) ) ?>"></td> + </tr> + <tr> + <td><?php _e( 'Photo:' ) ?></td> + <td><input type="file" name="vehicle-images[]" value="" multiple></td> + </tr> + <tr> + <td><?php _e( 'Uploaded photos<br>(might need page refresh):' ) ?></td> + <?php + $images = ( array )json_decode( get_post_meta( get_the_ID(), __( 'vehicle-images' ), true ) ); + foreach ( $images as $image ) { + echo( '<td> <img src="' . $image . '" alt=""></td>' ); + } + ?> + </tr> +</table> diff --git a/wp-content/plugins/dx-vehicles/vehicles-class.php b/wp-content/plugins/dx-vehicles/vehicles-class.php new file mode 100644 index 0000000..3a0b127 --- /dev/null +++ b/wp-content/plugins/dx-vehicles/vehicles-class.php @@ -0,0 +1,124 @@ +<?php +class Vehicles { + function init() { + add_action( 'init', array( $this, 'cpt_create' ) ); + add_action( 'add_meta_boxes', array( $this, 'register_meta_boxes' ) ); + add_action( 'save_post', array( $this, 'vehicle_info_save_meta' ), 1, 2 ); + } + + public function labels() { + $arr = array( + 'labels' => array( + 'name' => __( 'Vehicles' ), + 'singular_name' => __( 'Vehicle' ), + ), + 'public' => true, + 'has_archive' => true, + 'rewrite' => array( 'slug' => 'vehicles' ), + 'show_in_rest' => true, + 'supports' => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', 'revisions', 'custom-fields', ), + ); + return $arr; + } + + function cpt_create( $post ) { + register_post_type( 'vehicles', $this->labels() ); + } + + function register_meta_boxes() { + add_meta_box( 'vehicle-info', __( 'Vehicle Information' ), array( $this, 'vehicle_info_display_callback' ), 'vehicles' ); + } + + function vehicle_info_display_callback( $post ) { + include 'vehicle-info-display-callback.php'; + } + + function remove_message( $location ) { + return remove_query_arg( 'message', $location ); + } + + function allowed_image_types() { + $mime_types = array( + 'jpg|jpeg|jpe' => 'image/jpeg', + 'gif' => 'image/gif', + 'png' => 'image/png', + 'bmp' => 'image/bmp', + 'tiff|tif' => 'image/tiff', + ); + return $mime_types; + } + + function get_enc_uploaded_img_urls( $images ) { + $uploaded_urls = array(); + for ( $i = 0; $i < sizeof( $images['name'] ); $i++ ) { + // Upload each valid file, throw error if file is not valid + if ( wp_check_filetype( $images['name'][ $i ], $this->allowed_image_types() )['ext'] ) { + $file = array( + 'name' => $images['name'][ $i ], + 'type' => $images['type'][ $i ], + 'tmp_name' => $images['tmp_name'][ $i ], + 'error' => $images['error'][ $i ], + 'size' => $images['size'][ $i ] + ); + // Note: images will not upload if you don't set 777 permission to wp-content folder and it's contents + $uploaded = wp_handle_upload( $file, array( 'test_form' => false ) ); + array_push( $uploaded_urls, $uploaded['url'] ); + } else { + wp_die( 'Invalid image' ); + } + } + return json_encode( $uploaded_urls ); + } + + function vehicle_info_save_meta( $post_id, $post ) { + // Return if the user doesn't have edit permissions. + if ( ! current_user_can( 'edit_post', $post_id ) ) { + return $post_id; + } + + // Now that we're authenticated, time to save the data. + // This sanitizes the data from the field and saves it into an array $events_meta. + $events_meta = array( + 'vehicle-year' => sanitize_text_field( isset( $_POST['vehicle-year'] ) ? $_POST['vehicle-year'] : null ), + 'vehicle-millage' => sanitize_text_field( isset( $_POST['vehicle-millage'] ) ? $_POST['vehicle-millage'] : null ), + 'vehicle-horsepower' => sanitize_text_field( isset( $_POST['vehicle-horsepower'] ) ? $_POST['vehicle-horsepower'] : null ), + 'vehicle-range' => sanitize_text_field( isset( $_POST['vehicle-range'] ) ? $_POST['vehicle-range'] : null ), + 'vehicle-price' => sanitize_text_field( isset( $_POST['vehicle-price'] ) ? $_POST['vehicle-price'] : null ), + 'vehicle-images' => isset( $_FILES['vehicle-images'] ) ? $this->get_enc_uploaded_img_urls( $_FILES['vehicle-images'] ): null, + ); + + // Cycle through the $events_meta array. + // Note, in this example we just have one item, but this is helpful if you have multiple. + foreach ( $events_meta as $key => $value ) { + if ( $value == null ) { + continue; + } + + switch ( $key ) { + case 'vehicle-year': + if( strcmp( "1769", $value ) > 0 || strcmp( "2020", $value ) < 0 ) wp_die( 'Invalid year' ); + break; + case 'vehicle-millage': + if( strcmp( "0", $value ) > 0 ) wp_die( 'Invalid millage.' ); + break; + case 'vehicle-horsepower': + if( strcmp( "0", $value ) > 0 ) wp_die( 'Invalid horsepower.' ); + break; + case 'vehicle-range': + if( strcmp( "0", $value ) > 0 ) wp_die( 'Invalid range.' ); + break; + case 'vehicle-price': + if( strcmp( "0", $value ) > 0 ) wp_die( 'Invalid price.' ); + break; + } + + if ( get_post_meta( $post_id, $key, false ) ) { + // If the custom field already has a value, update it. + update_post_meta( $post_id, $key, $value ); + } else { + // If the custom field doesn't have a value, add it. + add_post_meta( $post_id, $key, $value ); + } + } + } +} diff --git a/wp-content/plugins/hello.php b/wp-content/plugins/hello.php deleted file mode 100644 index ff55908..0000000 --- a/wp-content/plugins/hello.php +++ /dev/null @@ -1,100 +0,0 @@ -<?php -/** - * @package Hello_Dolly - * @version 1.7.2 - */ -/* -Plugin Name: Hello Dolly -Plugin URI: http://wordpress.org/plugins/hello-dolly/ -Description: This is not just a plugin, it symbolizes the hope and enthusiasm of an entire generation summed up in two words sung most famously by Louis Armstrong: Hello, Dolly. When activated you will randomly see a lyric from <cite>Hello, Dolly</cite> in the upper right of your admin screen on every page. -Author: Matt Mullenweg -Version: 1.7.2 -Author URI: http://ma.tt/ -*/ - -function hello_dolly_get_lyric() { - /** These are the lyrics to Hello Dolly */ - $lyrics = "Hello, Dolly -Well, hello, Dolly -It's so nice to have you back where you belong -You're lookin' swell, Dolly -I can tell, Dolly -You're still glowin', you're still crowin' -You're still goin' strong -I feel the room swayin' -While the band's playin' -One of our old favorite songs from way back when -So, take her wrap, fellas -Dolly, never go away again -Hello, Dolly -Well, hello, Dolly -It's so nice to have you back where you belong -You're lookin' swell, Dolly -I can tell, Dolly -You're still glowin', you're still crowin' -You're still goin' strong -I feel the room swayin' -While the band's playin' -One of our old favorite songs from way back when -So, golly, gee, fellas -Have a little faith in me, fellas -Dolly, never go away -Promise, you'll never go away -Dolly'll never go away again"; - - // Here we split it into lines. - $lyrics = explode( "\n", $lyrics ); - - // And then randomly choose a line. - return wptexturize( $lyrics[ mt_rand( 0, count( $lyrics ) - 1 ) ] ); -} - -// This just echoes the chosen line, we'll position it later. -function hello_dolly() { - $chosen = hello_dolly_get_lyric(); - $lang = ''; - if ( 'en_' !== substr( get_user_locale(), 0, 3 ) ) { - $lang = ' lang="en"'; - } - - printf( - '<p id="dolly"><span class="screen-reader-text">%s </span><span dir="ltr"%s>%s</span></p>', - __( 'Quote from Hello Dolly song, by Jerry Herman:' ), - $lang, - $chosen - ); -} - -// Now we set that function up to execute when the admin_notices action is called. -add_action( 'admin_notices', 'hello_dolly' ); - -// We need some CSS to position the paragraph. -function dolly_css() { - echo " - <style type='text/css'> - #dolly { - float: right; - padding: 5px 10px; - margin: 0; - font-size: 12px; - line-height: 1.6666; - } - .rtl #dolly { - float: left; - } - .block-editor-page #dolly { - display: none; - } - @media screen and (max-width: 782px) { - #dolly, - .rtl #dolly { - float: none; - padding-left: 0; - padding-right: 0; - } - } - </style> - "; -} - -add_action( 'admin_head', 'dolly_css' ); diff --git a/wp-content/plugins/index.php b/wp-content/plugins/index.php new file mode 100644 index 0000000..6220032 --- /dev/null +++ b/wp-content/plugins/index.php @@ -0,0 +1,2 @@ +<?php +// Silence is golden. diff --git a/wp-content/themes/carmag/assets/src/sass/components/_card.scss b/wp-content/themes/carmag/assets/src/sass/components/_card.scss index e3535e0..00ac903 100644 --- a/wp-content/themes/carmag/assets/src/sass/components/_card.scss +++ b/wp-content/themes/carmag/assets/src/sass/components/_card.scss @@ -5,6 +5,7 @@ width: 350px; height: 280px; position: relative; + margin: 1rem; .card-info { position: absolute; @@ -13,6 +14,7 @@ background-color: rgba(0, 0, 0, 0.6); color: white; padding: 20px 25px 0; + transition: 0.2s; * { margin: 0; @@ -54,4 +56,12 @@ } } } + + &:hover { + .card-info { + .info-readmore { + margin-top: calc(100% - 130px); + } + } + } } diff --git a/wp-content/themes/carmag/assets/src/sass/layout/_login-register.scss b/wp-content/themes/carmag/assets/src/sass/layout/_login-register.scss new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/wp-content/themes/carmag/assets/src/sass/layout/_login-register.scss diff --git a/wp-content/themes/carmag/assets/src/scripts/scripts.js b/wp-content/themes/carmag/assets/src/scripts/scripts.js index 93438c7..6d6347c 100644 --- a/wp-content/themes/carmag/assets/src/scripts/scripts.js +++ b/wp-content/themes/carmag/assets/src/scripts/scripts.js @@ -22,7 +22,7 @@ jQuery(document).ready(function ($) { const toggleDrawer = () => { const drawerClassList = event.target.classList; - const navClassList = document.querySelectorAll(".menu-primary-container")[0] + const navClassList = document.querySelectorAll(".menu-container")[0] .classList; drawerClassList.toggle("opened"); navClassList.toggle("opened"); @@ -31,9 +31,13 @@ const toggleDrawer = () => { const separator = document.createElement("span"); separator.className = "separator"; const loginLink = document.querySelectorAll(".login")[0]; +const profileDropdown = document.querySelectorAll(".profile")[0]; if (loginLink) { loginLink.before(separator); } +if (profileDropdown) { + profileDropdown.before(separator); +} const faqFields = document.querySelectorAll(".faq-field"); faqFields.forEach((field) => { @@ -42,3 +46,104 @@ faqFields.forEach((field) => { field.querySelector(".field-content").classList.toggle("opened"); }); }); + +let selectedBrand = document.getElementById("brands"); +let modelsNames = Object.keys(carModels); +modelsNames.forEach((model) => { + let option = document.createElement("option"); + option.value = model; + option.innerHTML = model; + selectedBrand.appendChild(option); +}); +const handleModels = () => { + const brand = event.target.value; + const modelsSelect = document.getElementById("models"); + const defaultOption = modelsSelect.firstElementChild; + modelsSelect.innerHTML = ""; + modelsSelect.append(defaultOption); + let models; + if (selectedType.value === "car") { + models = carModels; + } else if (selectedType.value === "truck") { + models = truckModels; + } else if (selectedType.value === "motorcycle") { + models = motorcycleModels; + } else if (selectedType.value === "tractor") { + models = agriculturalBrands; + } else if (selectedType.value === "bus") { + models = busModels; + } + if (brand) { + models[brand].forEach((model) => { + let option = document.createElement("option"); + option.value = model; + option.innerHTML = model; + modelsSelect.appendChild(option); + }); + } else { + let option = document.createElement("option"); + option.value = ""; + option.innerHTML = "Model"; + modelsSelect.appendChild(option); + } +}; +let selectedType = document.getElementById("category"); +let types = document.querySelectorAll(".type"); +types.forEach((type) => { + type.addEventListener("click", () => { + event.stopPropagation(); + types.forEach((type) => { + type.classList.remove("selected"); + }); + event.target.classList.add("selected"); + selectedType.value = event.target.id; + let models; + if (selectedType.value === "car") { + models = carModels; + } else if (selectedType.value === "truck") { + models = truckModels; + } else if (selectedType.value === "motorcycle") { + models = motorcycleModels; + } else if (selectedType.value === "tractor") { + models = agriculturalBrands; + } else if (selectedType.value === "bus") { + models = busModels; + } + modelsNames = Object.keys(models); + const defaultOption = selectedBrand.firstElementChild; + selectedBrand.innerHTML = ""; + selectedBrand.append(defaultOption); + modelsNames.forEach((model) => { + let option = document.createElement("option"); + option.value = model; + option.innerHTML = model; + selectedBrand.appendChild(option); + }); + }); +}); + +const switcher = document.querySelectorAll(".switcher")[0]; +if (switcher) { + switcher.addEventListener("click", () => { + event.stopPropagation(); + const firstPrice = document.querySelectorAll(".price-first")[0]; + const secondPrice = document.querySelectorAll(".price-second")[0]; + [firstPrice.value, secondPrice.value] = [ + secondPrice.value, + firstPrice.value, + ]; + }); +} +var password = document.getElementById("password"), + confirm_password = document.getElementById("confirm_password"); + +function validatePassword() { + if (password.value != confirm_password.value) { + confirm_password.setCustomValidity("Passwords don't match"); + } else { + confirm_password.setCustomValidity(""); + } +} + +password.onchange = validatePassword; +confirm_password.onkeyup = validatePassword; diff --git a/wp-content/themes/carmag/template-parts/content-card.php b/wp-content/themes/carmag/template-parts/content-card.php index e3d969e..e16d358 100644 --- a/wp-content/themes/carmag/template-parts/content-card.php +++ b/wp-content/themes/carmag/template-parts/content-card.php @@ -9,13 +9,19 @@ ?> -<div class="card"> - <div class="card-info"> - <p class="info-title">McLaren P1</p> - <p class="info-price">$75,000</p> - <button class="button info-readmore"> - <span>Read more</span> - <i class="fas fa-long-arrow-alt-right"></i> - </button> - </div> +<?php +$name = get_query_var('name'); +$price = get_query_var('price'); +$url = get_query_var('url'); +$image = get_query_var('image'); +?> +<div class="card" style="background-image: url('<?php echo $image ?>')"> + <div class="card-info"> + <p class="info-title"><?php echo $name ?></p> + <p class="info-price">$<?php echo $price ?></p> + <a href="<?php echo $url ?>" class="button info-readmore"> + <span>Read more</span> + <i class="fas fa-long-arrow-alt-right"></i> + </a> + </div> </div> diff --git a/wp-content/themes/carmag/templates/homepage.php b/wp-content/themes/carmag/templates/homepage.php index 96f4f11..7f0a94b 100644 --- a/wp-content/themes/carmag/templates/homepage.php +++ b/wp-content/themes/carmag/templates/homepage.php @@ -1,32 +1,136 @@ -<?php +<?php /** * Template Name: Homepage * * Custom homepage template for the theme - * + * * @since v1.0.0 * @package CarMag */ +get_header(); +?> + +<section class="section-fullwidth section-search"> + <div class="row"> + <div class="column small-12 medium-12"> + <div id="primary" class="content-area"> + <main id="main" class="site-main"> + <div class="simple-search"> + <h2>Find your dream car</h2> -get_header(); ?> + <form id="search-form" class="search-form" action="/" method="GET"> + <input type="hidden" name="search" value="vehicles"> + <div class="form-content"> + <select id="brands" name="brand" class="form-field brands" onChange="handleModels()"> + <option selected="" value="">Brand</option> + </select> + + <select name="model" id="models" class="form-field models"> + <option selected="" value="">Model</option> + </select> + + <select name="condition" class="form-field condition"> + <option selected="" value="">Condition</option> + <option value="new">Factory new</option> + <option value="used">Used</option> + <option value="for_parts">For parts</option> + </select> + + <select name="location" class="form-field location"> + <option selected="" value="">Location</option> + <option value="blagoevgrad">Благоевград</option> + <option value="burgas">Бургас</option> + <option value="varna">Варна</option> + <option value="velikoturnovo">Велико Търново</option> + <option value="vidin">Видин</option> + <option value="vratsa">Враца</option> + <option value="gabrovo">Габрово</option> + <option value="dobrich">Добрич</option> + <option value="dupnitsa">Дупница</option> + <option value="kurdjali">Кърджали</option> + <option value="kustendil">Кюстендил</option> + <option value="lovech">Ловеч</option> + <option value="montana">Монтана</option> + <option value="pazardjik">Пазарджик</option> + <option value="pernik">Перник</option> + <option value="pleven">Плевен</option> + <option value="plovdiv">Пловдив</option> + <option value="razgrad">Разград</option> + <option value="ruse">Русе</option> + <option value="silistra">Силистра</option> + <option value="sliven">Сливен</option> + <option value="smolqn">Смолян</option> + <option value="sofia">София</option> + <option value="starazagora">Стара Загора</option> + <option value="turgovishte">Търговище</option> + <option value="haskovo">Хасково</option> + <option value="shumen">Шумен</option> + <option value="qmbol">Ямбол</option> + </select> + + + + <div class="wrapper-price"> + <div class="price"><input type="number" class="form-field price-first" name="start_price" value="2000"></div> + <div class="switcher"><i class="fas fa-exchange-alt"></i> </div> + <div class="price"><input type="number" class="form-field price-second" name="end_price" value="16000"></div> + </div> + </div> + + <div class="form-actions"> + <div class="actions-vehicle-type"> + <span id="car" class="selected type"><i class="fas fa-car"></i></span> + <span id="truck" class="type"><i class="fas fa-truck"></i></span> + <span id="motorcycle" class="type"><i class="fas fa-motorcycle"></i></span> + <span id="tractor" class="type"><i class="fas fa-tractor"></i></span> + <span id="bus" class="type"><i class="fas fa-bus"></i></span> + <input type="hidden" name="category" id="category" value="car"> + </div> + + <div class="actions-buttons"> + <a href="<?php echo home_url( '/advanced-search/' ); ?>" class="advanced-button button secondary">Advanced Search</a> + <button type="submit" class="search-button button secondary" form="search-form">Search now</button> + </div> + </div> + </form> + </div> + </main><!-- #main --> + </div><!-- #primary --> + </div><!-- .column --> + </div><!-- .row --> +</section><!-- .section-fullwidth section-main --> <section class="section-fullwidth section-latestoffers"> - <div class="row"> - <div class="columns small-12 medium-8"> - <div id="primary" class="content-area"> - <main id="latestoffers" class="site-latestoffers"> - <div class="latestoffers" > - <?php - for($i = 0; $i < 5; $i++) : - get_template_part( 'template-parts/content', 'card' ); - endfor; - ?> - </div> - </main><!-- #main --> - </div><!-- #primary --> - </div><!-- .columns medium-8 --> - </div><!-- .row --> - </section><!-- .section-fullwidth section-main --> + <div class="row latestoffers-text"> + Check our latest deals + </div><!-- .row --> + <div class="view latestoffers-grid"> + <?php + $new_loop = new WP_Query( array( + 'post_type' => 'vehicles', + 'posts_per_page' => 6 + ) ); + ?> + + <?php if ( $new_loop->have_posts() ) : ?> + <?php while ( $new_loop->have_posts() ) : $new_loop->the_post(); ?> + <?php + $images = ( array )json_decode( get_post_meta( get_the_ID(), __( 'vehicle-images' ), true ) ); + set_query_var('name', sanitize_text_field( get_the_title() )); + set_query_var('price', sanitize_text_field( get_post_meta( get_the_ID(), __( 'vehicle-price' ), true ) ) ); + set_query_var('url', sanitize_text_field( get_post_permalink( get_the_ID() ) ) ); + set_query_var('image', sanitize_text_field( array_pop( $images ) )); + ?> + <?php get_template_part( 'template-parts/content', 'card' ); ?> + <?php endwhile;?> + <?php else: ?> + <?php endif; ?> + <?php wp_reset_query(); ?> + + </div> +</section><!-- .section-fullwidth section-main --> -<?php get_footer(); ?> +<?php +get_footer(); +?> diff --git a/wp-content/themes/carmag/templates/register.php b/wp-content/themes/carmag/templates/register.php new file mode 100644 index 0000000..e61f9cc --- /dev/null +++ b/wp-content/themes/carmag/templates/register.php @@ -0,0 +1,37 @@ +<?php +/** + * Template Name: Register + * + * Custom register template for the theme + * + * @since v1.0.0 + * @package CarMag + */ + + +get_header(); ?> + +<section class="section-fullwidth section-register"> + <div class="row"> + <div class="column small-12 medium-8"> + <div id="primary" class="content-area"> + <main id="main" class="site-main"> + <form method="POST" action="<?php echo admin_url('admin-post.php') ?>" class="register-form"> + <input type="hidden" name="action" value="process_register"> + <h1>Create Account</h1> + + <input class="form-input" type="email" name="email" id="email" placeholder="Email" required autofocus> + <input class="form-input" type="text" name="name" id="name" placeholder="Name" required> + <input class="form-input" type="password" name="password" id="password" placeholder="Password" required> + <input class="form-input" type="password" name="confirm_password" id="confirm_password" placeholder="Confirm password" required> + <button type="submit" class="form-submit">Register</button> + + <p class="form-suggestion">Already have an account? <a href="/login/">Login</a></p> + </form> + </main><!-- #main --> + </div><!-- #primary --> + </div><!-- .column --> + </div><!-- .row --> +</section><!-- .section-fullwidth --> + +<?php get_footer(); ?> |
