Changeset 2978340
- Timestamp:
- 10/12/2023 08:05:32 PM (2 years ago)
- Location:
- vistawp
- Files:
-
- 12 added
- 16 edited
- 1 copied
-
tags/1.2.2 (copied) (copied from vistawp/trunk)
-
tags/1.2.2/css/forms.css (modified) (1 diff)
-
tags/1.2.2/includes/forms/Form.php (modified) (1 diff)
-
tags/1.2.2/includes/forms/advanced.php (modified) (3 diffs)
-
tags/1.2.2/includes/forms/basic.php (modified) (1 diff)
-
tags/1.2.2/includes/forms/search.php (modified) (1 diff)
-
tags/1.2.2/includes/functions.php (modified) (2 diffs)
-
tags/1.2.2/readme.txt (modified) (1 diff)
-
tags/1.2.2/templates (added)
-
tags/1.2.2/templates/fields (added)
-
tags/1.2.2/templates/fields/checkbox.php (added)
-
tags/1.2.2/templates/fields/number-field.php (added)
-
tags/1.2.2/templates/fields/select.php (added)
-
tags/1.2.2/templates/fields/text-field.php (added)
-
tags/1.2.2/vista.php (modified) (3 diffs)
-
trunk/css/forms.css (modified) (1 diff)
-
trunk/includes/forms/Form.php (modified) (1 diff)
-
trunk/includes/forms/advanced.php (modified) (3 diffs)
-
trunk/includes/forms/basic.php (modified) (1 diff)
-
trunk/includes/forms/search.php (modified) (1 diff)
-
trunk/includes/functions.php (modified) (2 diffs)
-
trunk/readme.txt (modified) (1 diff)
-
trunk/templates (added)
-
trunk/templates/fields (added)
-
trunk/templates/fields/checkbox.php (added)
-
trunk/templates/fields/number-field.php (added)
-
trunk/templates/fields/select.php (added)
-
trunk/templates/fields/text-field.php (added)
-
trunk/vista.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
vistawp/tags/1.2.2/css/forms.css
r2949654 r2978340 1 button[type=submit] { 2 width: 100%; 1 .vwp-form-container { 2 display: grid; 3 grid-template-columns: repeat(auto-fill, minmax(min(100%, 15rem), 1fr)); 4 grid-auto-rows: auto; 5 grid-auto-flow: dense; 6 padding: 10px; 3 7 } 4 8 5 .grid-container { 6 padding: 10px; 7 display: grid; 9 .vwp-form-row { 10 grid-column: span 2; 8 11 } 9 12 10 .grid-row { 11 display: grid; 12 grid-template-columns: 50% 50%; 13 13 .vwp-form-row-button-sm { 14 grid-column: 1; 14 15 } 15 16 16 .grid-item { 17 .vwp-form-row-button-sm > .vwp-form-item > button[type=submit] { 18 width: 100%; 19 } 20 21 .vwp-form-item { 17 22 padding: 20px; 18 font-size: 30px;23 font-size: 15px; 19 24 text-align: left; 20 25 } 21 26 22 23 24 .vistawp-form-grid-container { 25 padding: 10px; 27 .vwp-form-item.vwp-checkbox { 26 28 display: grid; 29 grid-template-columns: repeat(auto-fill, minmax(min(100%, 13rem), 1fr)); 30 grid-auto-columns: auto; 31 grid-auto-rows: 1.5rem; 27 32 } 28 29 .vistawp-form-grid-row {30 display: grid;31 grid-template-columns: 50% 50%;32 }33 34 35 .vistawp-form-grid-row-3 {36 display: grid;37 grid-template-columns: 33% 33% 33%;38 text-align: right !important;39 }40 41 .vistawp-form-grid-item {42 padding: 20px;43 font-size: 30px;44 text-align: left;45 }46 -
vistawp/tags/1.2.2/includes/forms/Form.php
r2949654 r2978340 15 15 abstract class Form { 16 16 17 /** 18 * The default separator for array values in a query string 19 */ 20 public const DEFAULT_SEPARATOR = "%2C+"; 21 22 /** 23 * Render the shortcode. 24 * This method generates the HTML markup for the form. 25 * Generally, this method should start with a call to 26 * ob_start() and return the result of ob_get_clean(), 27 * since most of the helper functions for rending the form 28 * output HTML directly. 29 * 30 * @param $atts The shortcode attributes 31 * 32 * @return string The HTML markup for the form. 33 */ 34 abstract function render($atts): string; 35 36 /** 37 * Get the shortcode tag for this form 38 * @return string The shortcode tag 39 */ 40 abstract function get_tag(): string; 41 42 /** 43 * Registers the stylesheet and shortcode 44 * @param string $shortcode_tag The shortcode tag to be used 45 * to display the form 46 */ 47 public function __construct() { 48 // Register the shortcode and associate it with the render_shortcode method of this class 49 \add_shortcode($this->get_tag(), array($this, 'shortcode_handler')); 50 51 // Register the 'forms-styles' stylesheet with the Main class of the VSTA namespace 52 \VSTA\Main::get_instance()->register_style('forms-styles', \vista_plugin_url('/css/forms.css')); 17 /** 18 * The default separator for array values in a query string 19 */ 20 public const DEFAULT_SEPARATOR = "%2C+"; 21 22 /** 23 * Render the shortcode. 24 * This method generates the HTML markup for the form. 25 * Generally, this method should start with a call to 26 * ob_start() and return the result of ob_get_clean(), 27 * since most of the helper functions for rending the form 28 * output HTML directly. 29 * 30 * @param $atts The shortcode attributes 31 * 32 * @return string The HTML markup for the form. 33 */ 34 abstract function render($atts): string; 35 36 /** 37 * Get the shortcode tag for this form 38 * @return string The shortcode tag 39 */ 40 abstract function get_tag(): string; 41 42 /** 43 * Registers the stylesheet and shortcode 44 * @param string $shortcode_tag The shortcode tag to be used to display the form 45 */ 46 public function __construct() { 47 // Register the shortcode and associate it with the render_shortcode method of this class 48 \add_shortcode($this->get_tag(), array($this, 'shortcode_handler')); 49 50 // Register the 'forms-styles' stylesheet with the Main class of the VSTA namespace 51 \VSTA\Main::get_instance()->register_style('forms-styles', \vista_plugin_url('/css/forms.css')); 52 } 53 54 /** 55 * Shortcode callback. Enqueues styles and calls the render method 56 */ 57 public function shortcode_handler($atts): string { 58 $this->enqueue_styles(); 59 return $this->render($atts); 60 } 61 62 /** 63 * Enqueue the 'forms-styles' stylesheet on the front-end. 64 */ 65 private function enqueue_styles() { 66 \VSTA\Main::get_instance()->enqueue_style('forms-styles'); 67 } 68 69 /** 70 * Outputs the HTML for the form header, 71 * and gives the <form> tag the specified id 72 * 73 * @param string $id The id to give the <form> tag 74 * @param string $dest The URL to submit the form to. esc_attr() is run on this value before outputting, 75 * so query params cannot be included. 76 */ 77 protected function form_header(string $id, string $dest) { 78 ?> 79 <form method="GET" id="<?php echo \esc_attr($id); ?>" action="<?php echo \esc_attr($dest) ?>"> 80 <div class="vwp-form-container"> 81 <?php 82 } 83 84 /** 85 * Adds a hidden field setting status to active if the allStatus attribute is not set. 86 * This should be added to all forms which want to have a default status=Active. 87 * 88 * @param $atts The shortcode attributes- should be passed from the param to render(). 89 * If the 'allStatus' field is set in $atts, this function does nothing. 90 */ 91 protected function maybe_add_status($atts) { 92 if (is_array($atts) && !empty($atts['allStatus'])) { 93 return; // We don't want to add the hidden field if allStatus is set 94 } else { 95 ?> 96 <input type="hidden" name="status" value="Active"> 97 <?php 53 98 } 54 55 /** 56 * Shortcode callback. Enqueues styles and calls the render method 57 */ 58 public function shortcode_handler($atts): string { 59 $this->enqueue_styles(); 60 return $this->render($atts); 61 } 62 63 /** 64 * Enqueue the 'forms-styles' stylesheet on the front-end. 65 */ 66 private function enqueue_styles() { 67 \VSTA\Main::get_instance()->enqueue_style('forms-styles'); 68 } 69 70 /** 71 * Outputs the HTML for the form header, 72 * and gives the <form> tag the specified id 73 * 74 * @param string $id The id to give the <form> tag 75 * @param string $dest The URL to submit the form to. esc_attr() is run on this value before outputting, 76 * so query params cannot be included. 77 */ 78 protected function form_header(string $id, string $dest) { 79 ?> 80 <form method="GET" id="<?php echo \esc_attr($id); ?>" action="<?php echo \esc_attr($dest) ?>"> 81 <div class="vistawp-form-grid-container"> 82 <?php 83 } 84 85 /** 86 * Adds a hidden field setting status to active if the allStatus attribute is not set. 87 * This should be added to all forms which want to have a default status=Active. 88 * 89 * @param $atts The shortcode attributes- should be passed from the param to render(). 90 * If the 'allStatus' field is set in $atts, this function does nothing. 91 */ 92 protected function maybe_add_status($atts) { 93 if (is_array($atts) && !empty($atts['allStatus'])) { 94 return; // We don't want to add the hidden field if allStatus is set 95 } else { 96 ?> 97 <input type="hidden" name="status" value="Active"> 98 <?php 99 } 100 } 101 102 /** 103 * Outputs the HTML for the form footer 104 */ 105 protected function form_footer() { 106 ?> 107 </div> 108 </form> 109 <?php 110 } 111 112 /** 113 * Outputs the HTML for a text input field 114 * @param string $id The id to give the <input> tag 115 * @param string $name The name to give the <input> tag 116 * @param string $label The label for the field 117 * @param string $value The value to give the <input> tag 118 * @param string $placeholder The placeholder to give the <input> tag 119 */ 120 protected function text_field(string $id, string $name, string $label, 121 string $value = '', string $placeholder = '') { 122 ?> 123 <div class="vistawp-form-grid-item"> 124 <label for="<?php echo $id; ?>"><?php echo $label; ?></label> 125 <input type="text" id="<?php echo $id; ?>" name="<?php echo $name; ?>" 126 value="<?php echo $value; ?>" placeholder="<?php echo $placeholder; ?>"> 99 } 100 101 /** 102 * Outputs the HTML for the form footer 103 */ 104 protected function form_footer() { 105 ?> 127 106 </div> 128 <?php 129 } 130 131 /** 132 * Outputs HTML for the submit button 133 * @param string $text The text to display on the button 134 */ 135 protected function submit_button(string $text) { 136 ?> 137 <div class="grid-item"> 138 <button type="submit" value="Submit"><?php echo $text; ?></button> 139 </div> 140 <?php 141 } 142 143 /** 144 * Outputs HTML for a <select> field 145 * The options are specified as an array of key => value mappings, 146 * and one can be selected by default. 147 * 148 * @param string $id The id to give the <select> tag 149 * @param string $name The name to give the <select> tag 150 * @param string $label The label for the field 151 * @param array $options The options to display in the multiselect. 152 * Each entry should be a key => value mapping, 153 * where the key is displayed to the user and 154 * the value is the value of the <option> tag. 155 * @param string $selected The VALUE of option to select by default 156 */ 157 protected function select_field(string $id, string $name, string $label, 158 array $options, string $selected = "") { 159 ?> 160 <div class="vistawp-form-grid-item"> 161 <label for="<?php echo $id; ?>"><?php echo $label; ?></label> 162 <select id="<?php echo $id; ?>" name="<?php echo $name; ?>[]"> 163 <?php 164 foreach ($options as $key => $value) { 165 ?> 166 <option value="<?php echo $value; ?>" 167 <?php echo $value === $selected ? 'selected' : ''; ?>> 168 <?php echo $key; ?> 169 </option> 170 <?php 171 } 172 ?> 173 </select> 174 </div> 175 <?php 176 } 177 178 /** 179 * Outputs HTML for a series of checkboxes whose results 180 * are grouped into an array. The options are specified as 181 * an array of key => value mappings, where the key is displayed 182 * to the user as the label and the value is the value of the checkbox. 183 * The ID of each checkbox is the prefix followed by the value. 184 * 185 * @param string $title The title to use for the field label 186 * @param string $prefix The prefix to use for the ID of each checkbox 187 * @param string $name The name of the field, which will be the key in $_POST 188 * @param array $options The options to display in the multiselect. 189 */ 190 protected function multicheck_field(string $title, string $prefix, string $name, array $options) { 191 ?> 192 <div class="vistawp-form-grid-item"> 193 <label for="<?php echo $name; ?>"><?php echo $title; ?></label> 194 <br /> 195 <?php 196 foreach ($options as $key => $value) { 197 ?> 198 <input type="checkbox" id="<?php echo $prefix . $value; ?>" name="<?php echo $name; ?>[]" value="<?php echo $value; ?>"> 199 <label for="<?php echo $prefix . $value; ?>"><?php echo $key; ?></label> 200 <?php 201 } 202 ?></div><?php 203 } 204 205 /** 206 * Outputs HTML for a number field 207 * @param string $id The id to give the <input> tag 208 * @param string $name The name to give the <input> tag 209 * @param string $label The label for the field 210 * @param string $value The value to give the <input> tag 211 * @param string $placeholder The placeholder to give the <input> tag 212 */ 213 protected function number_field(string $id, string $name, string $label, 214 string $value = '', string $placeholder = '') { 215 ?> 216 <div class="vistawp-form-grid-item"> 217 <label for="<?php echo $id; ?>"><?php echo $label; ?></label> 218 <input type="number" id="<?php echo $id; ?>" name="<?php echo $name; ?>" 219 value="<?php echo $value; ?>" placeholder="<?php echo $placeholder; ?>"> 220 </div> 221 <?php 222 } 107 </form> 108 <?php 109 } 110 111 /** 112 * Outputs the HTML for a text input field 113 * @param string $id The id to give the <input> tag 114 * @param string $name The name to give the <input> tag 115 * @param string $label The label for the field 116 * @param string $value The value to give the <input> tag 117 * @param string $placeholder The placeholder to give the <input> tag 118 */ 119 protected function text_field( 120 string $id, 121 string $name, 122 string $label, 123 string $value = '', 124 string $placeholder = '' 125 ) { 126 ob_start(); 127 \vista_get_template( 128 'fields/text-field.php', 129 array( 130 'id' => $id, 131 'name' => $name, 132 'label' => $label, 133 'value' => $value, 134 'placeholder' => $placeholder, 135 ), 136 ); 137 138 echo ob_get_clean(); 139 } 140 141 /** 142 * Outputs HTML for the submit button 143 * @param string $text The text to display on the button 144 */ 145 protected function submit_button(string $text) { 146 echo sprintf( 147 '<div class="vwp-form-row-button-sm"><div class="vwp-form-item"><button type="submit" value="Submit">%s</button></div></div>', 148 esc_html($text) 149 ); 150 } 151 152 /** 153 * Outputs HTML for a <select> field 154 * The options are specified as an array of key => value mappings, 155 * and one can be selected by default. 156 * 157 * @param string $id The id to give the <select> tag 158 * @param string $name The name to give the <select> tag 159 * @param string $label The label for the field 160 * @param array $options The options to display in the multiselect. 161 * Each entry should be a key => value mapping, 162 * where the key is displayed to the user and 163 * the value is the value of the <option> tag. 164 * @param string $selected The VALUE of option to select by default 165 */ 166 protected function select_field( 167 string $id, 168 string $name, 169 string $label, 170 array $options, 171 string $placeholder = '', 172 string $selected = '' 173 ) { 174 ob_start(); 175 \vista_get_template( 176 'fields/select.php', 177 array( 178 'id' => $id, 179 'name' => $name, 180 'label' => $label, 181 'options' => $options, 182 'placeholder' => $placeholder, 183 'selected' => $selected, 184 ), 185 ); 186 187 echo ob_get_clean(); 188 } 189 190 /** 191 * Outputs HTML for a series of checkboxes whose results 192 * are grouped into an array. The options are specified as 193 * an array of key => value mappings, where the key is displayed 194 * to the user as the label and the value is the value of the checkbox. 195 * The ID of each checkbox is the prefix followed by the value. 196 * 197 * @param string $title The title to use for the field label 198 * @param string $prefix The prefix to use for the ID of each checkbox 199 * @param string $name The name of the field, which will be the key in $_POST 200 * @param array $options The options to display in the multiselect. 201 */ 202 protected function checkbox_field( 203 string $title, 204 string $prefix, 205 string $name, 206 array $options 207 ) { 208 ob_start(); 209 \vista_get_template( 210 'fields/checkbox.php', 211 array( 212 'title' => $title, 213 'prefix' => $prefix, 214 'name' => $name, 215 'options' => $options, 216 ), 217 ); 218 219 echo ob_get_clean(); 220 } 221 222 /** 223 * Outputs HTML for a number field 224 * @param string $id The id to give the <input> tag 225 * @param string $name The name to give the <input> tag 226 * @param string $label The label for the field 227 * @param string $value The value to give the <input> tag 228 * @param string $placeholder The placeholder to give the <input> tag 229 */ 230 protected function number_field( 231 string $id, 232 string $name, 233 string $label, 234 string $value = '', 235 string $placeholder = '' 236 ) { 237 ob_start(); 238 \vista_get_template( 239 'fields/number-field.php', 240 array( 241 'id' => $id, 242 'name' => $name, 243 'label' => $label, 244 'value' => $value, 245 'placeholder' => $placeholder, 246 ), 247 ); 248 249 echo ob_get_clean(); 250 } 223 251 } 224 252 -
vistawp/tags/1.2.2/includes/forms/advanced.php
r2949654 r2978340 45 45 public function render($atts): string { 46 46 ob_start(); 47 48 47 $this->form_header(self::FORM_ID, \sanitize_text_field($atts['dest'] ?? "")); 49 48 $this->maybe_add_status($atts); 50 49 51 echo '<div class="vistawp-form-grid-row">'; 52 $this->text_field('q', 'q', 'Search Query'); 53 $this->multicheck_field('Property Type', 'R', 'type', array( 50 $this->text_field('q', 'q', 'Location', '', 'City, Zip Code, or Street Name'); 51 $this->checkbox_field('Property Type', 'R', 'type', array( 54 52 'Residential' => 'residential', 55 53 'Condominium' => 'condominium', … … 58 56 )); 59 57 60 $this->number_field('minprice', 'minprice', 'Minimum Price' );61 $this->number_field('maxprice', 'maxprice', 'Maximum Price' );58 $this->number_field('minprice', 'minprice', 'Minimum Price', '', '$ Min Price...'); 59 $this->number_field('maxprice', 'maxprice', 'Maximum Price', '', '$ Max Price...'); 62 60 63 61 // Min Beds and Baths … … 75 73 '10' => '10' 76 74 ); 77 $this->select_field('minbeds', 'minbeds', 'Minimum Beds', $options); 78 $this->select_field('minbaths', 'minbaths', 'Minimum Baths', $options); 79 80 echo '</div>'; 81 echo '<div class="vistawp-form-grid-row-3">'; 82 75 $this->select_field('minbeds', 'minbeds', 'Minimum Beds', $options, 'How many beds?'); 76 $this->select_field('minbaths', 'minbaths', 'Minimum Baths', $options, 'How many bathrooms?'); 83 77 $this->number_field('minsqft', 'minsqft', 'Minimum Sqft'); 84 78 $this->number_field('minacres', 'minacres', 'Minimum Lot Acres'); 85 79 $this->number_field('minyear', 'minyear', 'Minimum Year Built'); 86 87 echo '</div>'; 88 echo '<div class="vistawp-form-grid-row">'; 89 90 $this->select_field('mingarage', 'mingarage', 'Minimum Garage Spaces', array( 80 $this->select_field('mingarage', 'mingarage', 'Minimum Garage Spaces', 81 array( 91 82 '' => '', 92 83 '1' => '1', 93 84 '2' => '2', 94 85 '3' => '3', 95 '4' => '4' 96 )); 86 '4' => '4', 87 ), 88 ); 97 89 $this->number_field('limit', 'limit', 'Listings Per Page'); 98 99 echo '</div>';100 90 $this->submit_button('Submit'); 101 91 $this->form_footer(); -
vistawp/tags/1.2.2/includes/forms/basic.php
r2949654 r2978340 63 63 ); 64 64 65 echo '<div class="vistawp-form-grid-row">'; 66 $this->text_field('q', 'q', 'Search Query:'); 67 $this->multicheck_field("Property Type: ", "ptype-", "type", array( 68 "Residential" => "Residential", 69 "Condominium" => "Condominium", 70 "Multifamily" => "Multifamily", 71 "Land" => "Land", 72 )); 73 $this->number_field('minprice', 'minprice', 'Minimum Price:'); 74 $this->number_field('maxprice', 'maxprice', 'Maximum Price:'); 75 $this->select_field('minbeds', 'minbeds', 'Minimum Beds', $options, ""); 76 $this->select_field('minbaths', 'minbaths', 'Minimum Baths', $options, ""); 77 echo '</div>'; 65 $this->text_field('q', 'q', 'Location', '', 'City, Zip Code, or Street Name'); 66 $this->checkbox_field( 67 'Property Type ', 68 'ptype-', 69 'type', 70 array( 71 'Residential' => 'residential', 72 'Condominium' => 'condominium', 73 'Multifamily' => 'multifamily', 74 'Land' => 'land', 75 ), 76 ); 77 $this->number_field('minprice', 'minprice', 'Minimum Price', '', '$ Min Price...'); 78 $this->number_field('maxprice', 'maxprice', 'Maximum Price', '', '$ Max Price...'); 79 $this->select_field('minbeds', 'minbeds', 'Minimum Beds', $options, 'How many beds?'); 80 $this->select_field('minbaths', 'minbaths', 'Minimum Baths', $options, 'How many bathrooms?'); 78 81 79 82 $this->submit_button('Submit'); -
vistawp/tags/1.2.2/includes/forms/search.php
r2949654 r2978340 46 46 */ 47 47 public function render($atts): string { 48 ob_start();49 $this->form_header(self::FORM_ID, \sanitize_text_field($atts['dest'] ?? ""));50 $this->maybe_add_status($atts);51 $this->text_field('q', 'q', 'Search Query:');52 $this->submit_button('Submit');53 $this->form_footer();54 return ob_get_clean();48 ob_start(); 49 $this->form_header(self::FORM_ID, \sanitize_text_field($atts['dest'] ?? "")); 50 $this->maybe_add_status($atts); 51 $this->text_field('q', 'q', 'Location', '', 'City, Zip Code, or Street Name'); 52 $this->submit_button('Submit'); 53 $this->form_footer(); 54 return ob_get_clean(); 55 55 } 56 56 } 57 ?> -
vistawp/tags/1.2.2/includes/functions.php
r2964274 r2978340 3 3 // Exit if accessed directly. 4 4 defined( 'ABSPATH' ) || exit; 5 6 if(! function_exists('vista_get_template')) { 7 /** 8 * Loads a template file from the specified template directory. 9 * 10 * This function attempts to include the specified template file from the template 11 * directory defined by the VISTA__PLUGIN_DIR constant. If the file does not exist, 12 * it returns an error message. 13 * 14 * Each template includes specifications for the variables used therein. 15 * 16 * @param string $template_name The name of the template file to load. 17 * @param array $args Optional. An associative array of variables to pass to the template. 18 * 19 * @return string|void The content of the template if it's found, or an exception if the template is missing. 20 * 21 * @throws \Exception If the specified template is not found at the given path. 22 */ 23 function vista_get_template(string $template_name, array $args = array()): void { 24 $default_path = VISTA__PLUGIN_DIR . 'templates/'; 25 $template = $default_path . $template_name; 26 27 if (! file_exists( $template )) { 28 throw new \Exception('The template file is missing.'); 29 } 30 31 if (! empty( $args )) { 32 extract( $args ); 33 } 34 35 include $template; 36 } 37 } 5 38 6 39 // Add the str_contains function from php 8 … … 43 76 */ 44 77 function vista_plugin_url(string $path): string { 45 return plugins_url($path, dirname(__FILE__)); 78 return plugins_url( 79 $path, 80 VISTA__PLUGIN_DIR . '/vista' 81 ); 46 82 } 47 83 } -
vistawp/tags/1.2.2/readme.txt
r2973600 r2978340 5 5 Requires at least: 4.7 6 6 Tested up to: 6.3 7 Stable tag: 1.2. 17 Stable tag: 1.2.2 8 8 Requires PHP: 7.0 9 9 License: GPLv2 or later -
vistawp/tags/1.2.2/vista.php
r2973600 r2978340 3 3 * Plugin Name: VistaWP 4 4 * Description: Retrieves and displays real estate listings 5 * Version: 1.2. 15 * Version: 1.2.2 6 6 * Author: VistaWP 7 7 * Author URI: https://vistawp.com/ … … 13 13 // Exit if accessed directly. 14 14 defined( 'ABSPATH' ) || exit; 15 16 // general constants 17 define( 'VISTA__PLUGIN_VERSION', '1.2.2' ); 18 define( 'VISTA__PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); 19 define( 'VISTA__PLUGIN_URL', plugin_dir_url( __FILE__ ) ); 20 define( 'VISTA__PLUGIN_TEXTDOMAIN', 'crm' ); 15 21 16 22 /** … … 184 190 // Abstract class for forms 185 191 if ( !class_exists("\\VSTA\\Forms\\Form") ) { 186 require_once 'includes/forms/ Form.php';192 require_once 'includes/forms/form.php'; 187 193 } 188 194 // Class for Vistawp Advanced form -
vistawp/trunk/css/forms.css
r2949654 r2978340 1 button[type=submit] { 2 width: 100%; 1 .vwp-form-container { 2 display: grid; 3 grid-template-columns: repeat(auto-fill, minmax(min(100%, 15rem), 1fr)); 4 grid-auto-rows: auto; 5 grid-auto-flow: dense; 6 padding: 10px; 3 7 } 4 8 5 .grid-container { 6 padding: 10px; 7 display: grid; 9 .vwp-form-row { 10 grid-column: span 2; 8 11 } 9 12 10 .grid-row { 11 display: grid; 12 grid-template-columns: 50% 50%; 13 13 .vwp-form-row-button-sm { 14 grid-column: 1; 14 15 } 15 16 16 .grid-item { 17 .vwp-form-row-button-sm > .vwp-form-item > button[type=submit] { 18 width: 100%; 19 } 20 21 .vwp-form-item { 17 22 padding: 20px; 18 font-size: 30px;23 font-size: 15px; 19 24 text-align: left; 20 25 } 21 26 22 23 24 .vistawp-form-grid-container { 25 padding: 10px; 27 .vwp-form-item.vwp-checkbox { 26 28 display: grid; 29 grid-template-columns: repeat(auto-fill, minmax(min(100%, 13rem), 1fr)); 30 grid-auto-columns: auto; 31 grid-auto-rows: 1.5rem; 27 32 } 28 29 .vistawp-form-grid-row {30 display: grid;31 grid-template-columns: 50% 50%;32 }33 34 35 .vistawp-form-grid-row-3 {36 display: grid;37 grid-template-columns: 33% 33% 33%;38 text-align: right !important;39 }40 41 .vistawp-form-grid-item {42 padding: 20px;43 font-size: 30px;44 text-align: left;45 }46 -
vistawp/trunk/includes/forms/Form.php
r2949654 r2978340 15 15 abstract class Form { 16 16 17 /** 18 * The default separator for array values in a query string 19 */ 20 public const DEFAULT_SEPARATOR = "%2C+"; 21 22 /** 23 * Render the shortcode. 24 * This method generates the HTML markup for the form. 25 * Generally, this method should start with a call to 26 * ob_start() and return the result of ob_get_clean(), 27 * since most of the helper functions for rending the form 28 * output HTML directly. 29 * 30 * @param $atts The shortcode attributes 31 * 32 * @return string The HTML markup for the form. 33 */ 34 abstract function render($atts): string; 35 36 /** 37 * Get the shortcode tag for this form 38 * @return string The shortcode tag 39 */ 40 abstract function get_tag(): string; 41 42 /** 43 * Registers the stylesheet and shortcode 44 * @param string $shortcode_tag The shortcode tag to be used 45 * to display the form 46 */ 47 public function __construct() { 48 // Register the shortcode and associate it with the render_shortcode method of this class 49 \add_shortcode($this->get_tag(), array($this, 'shortcode_handler')); 50 51 // Register the 'forms-styles' stylesheet with the Main class of the VSTA namespace 52 \VSTA\Main::get_instance()->register_style('forms-styles', \vista_plugin_url('/css/forms.css')); 17 /** 18 * The default separator for array values in a query string 19 */ 20 public const DEFAULT_SEPARATOR = "%2C+"; 21 22 /** 23 * Render the shortcode. 24 * This method generates the HTML markup for the form. 25 * Generally, this method should start with a call to 26 * ob_start() and return the result of ob_get_clean(), 27 * since most of the helper functions for rending the form 28 * output HTML directly. 29 * 30 * @param $atts The shortcode attributes 31 * 32 * @return string The HTML markup for the form. 33 */ 34 abstract function render($atts): string; 35 36 /** 37 * Get the shortcode tag for this form 38 * @return string The shortcode tag 39 */ 40 abstract function get_tag(): string; 41 42 /** 43 * Registers the stylesheet and shortcode 44 * @param string $shortcode_tag The shortcode tag to be used to display the form 45 */ 46 public function __construct() { 47 // Register the shortcode and associate it with the render_shortcode method of this class 48 \add_shortcode($this->get_tag(), array($this, 'shortcode_handler')); 49 50 // Register the 'forms-styles' stylesheet with the Main class of the VSTA namespace 51 \VSTA\Main::get_instance()->register_style('forms-styles', \vista_plugin_url('/css/forms.css')); 52 } 53 54 /** 55 * Shortcode callback. Enqueues styles and calls the render method 56 */ 57 public function shortcode_handler($atts): string { 58 $this->enqueue_styles(); 59 return $this->render($atts); 60 } 61 62 /** 63 * Enqueue the 'forms-styles' stylesheet on the front-end. 64 */ 65 private function enqueue_styles() { 66 \VSTA\Main::get_instance()->enqueue_style('forms-styles'); 67 } 68 69 /** 70 * Outputs the HTML for the form header, 71 * and gives the <form> tag the specified id 72 * 73 * @param string $id The id to give the <form> tag 74 * @param string $dest The URL to submit the form to. esc_attr() is run on this value before outputting, 75 * so query params cannot be included. 76 */ 77 protected function form_header(string $id, string $dest) { 78 ?> 79 <form method="GET" id="<?php echo \esc_attr($id); ?>" action="<?php echo \esc_attr($dest) ?>"> 80 <div class="vwp-form-container"> 81 <?php 82 } 83 84 /** 85 * Adds a hidden field setting status to active if the allStatus attribute is not set. 86 * This should be added to all forms which want to have a default status=Active. 87 * 88 * @param $atts The shortcode attributes- should be passed from the param to render(). 89 * If the 'allStatus' field is set in $atts, this function does nothing. 90 */ 91 protected function maybe_add_status($atts) { 92 if (is_array($atts) && !empty($atts['allStatus'])) { 93 return; // We don't want to add the hidden field if allStatus is set 94 } else { 95 ?> 96 <input type="hidden" name="status" value="Active"> 97 <?php 53 98 } 54 55 /** 56 * Shortcode callback. Enqueues styles and calls the render method 57 */ 58 public function shortcode_handler($atts): string { 59 $this->enqueue_styles(); 60 return $this->render($atts); 61 } 62 63 /** 64 * Enqueue the 'forms-styles' stylesheet on the front-end. 65 */ 66 private function enqueue_styles() { 67 \VSTA\Main::get_instance()->enqueue_style('forms-styles'); 68 } 69 70 /** 71 * Outputs the HTML for the form header, 72 * and gives the <form> tag the specified id 73 * 74 * @param string $id The id to give the <form> tag 75 * @param string $dest The URL to submit the form to. esc_attr() is run on this value before outputting, 76 * so query params cannot be included. 77 */ 78 protected function form_header(string $id, string $dest) { 79 ?> 80 <form method="GET" id="<?php echo \esc_attr($id); ?>" action="<?php echo \esc_attr($dest) ?>"> 81 <div class="vistawp-form-grid-container"> 82 <?php 83 } 84 85 /** 86 * Adds a hidden field setting status to active if the allStatus attribute is not set. 87 * This should be added to all forms which want to have a default status=Active. 88 * 89 * @param $atts The shortcode attributes- should be passed from the param to render(). 90 * If the 'allStatus' field is set in $atts, this function does nothing. 91 */ 92 protected function maybe_add_status($atts) { 93 if (is_array($atts) && !empty($atts['allStatus'])) { 94 return; // We don't want to add the hidden field if allStatus is set 95 } else { 96 ?> 97 <input type="hidden" name="status" value="Active"> 98 <?php 99 } 100 } 101 102 /** 103 * Outputs the HTML for the form footer 104 */ 105 protected function form_footer() { 106 ?> 107 </div> 108 </form> 109 <?php 110 } 111 112 /** 113 * Outputs the HTML for a text input field 114 * @param string $id The id to give the <input> tag 115 * @param string $name The name to give the <input> tag 116 * @param string $label The label for the field 117 * @param string $value The value to give the <input> tag 118 * @param string $placeholder The placeholder to give the <input> tag 119 */ 120 protected function text_field(string $id, string $name, string $label, 121 string $value = '', string $placeholder = '') { 122 ?> 123 <div class="vistawp-form-grid-item"> 124 <label for="<?php echo $id; ?>"><?php echo $label; ?></label> 125 <input type="text" id="<?php echo $id; ?>" name="<?php echo $name; ?>" 126 value="<?php echo $value; ?>" placeholder="<?php echo $placeholder; ?>"> 99 } 100 101 /** 102 * Outputs the HTML for the form footer 103 */ 104 protected function form_footer() { 105 ?> 127 106 </div> 128 <?php 129 } 130 131 /** 132 * Outputs HTML for the submit button 133 * @param string $text The text to display on the button 134 */ 135 protected function submit_button(string $text) { 136 ?> 137 <div class="grid-item"> 138 <button type="submit" value="Submit"><?php echo $text; ?></button> 139 </div> 140 <?php 141 } 142 143 /** 144 * Outputs HTML for a <select> field 145 * The options are specified as an array of key => value mappings, 146 * and one can be selected by default. 147 * 148 * @param string $id The id to give the <select> tag 149 * @param string $name The name to give the <select> tag 150 * @param string $label The label for the field 151 * @param array $options The options to display in the multiselect. 152 * Each entry should be a key => value mapping, 153 * where the key is displayed to the user and 154 * the value is the value of the <option> tag. 155 * @param string $selected The VALUE of option to select by default 156 */ 157 protected function select_field(string $id, string $name, string $label, 158 array $options, string $selected = "") { 159 ?> 160 <div class="vistawp-form-grid-item"> 161 <label for="<?php echo $id; ?>"><?php echo $label; ?></label> 162 <select id="<?php echo $id; ?>" name="<?php echo $name; ?>[]"> 163 <?php 164 foreach ($options as $key => $value) { 165 ?> 166 <option value="<?php echo $value; ?>" 167 <?php echo $value === $selected ? 'selected' : ''; ?>> 168 <?php echo $key; ?> 169 </option> 170 <?php 171 } 172 ?> 173 </select> 174 </div> 175 <?php 176 } 177 178 /** 179 * Outputs HTML for a series of checkboxes whose results 180 * are grouped into an array. The options are specified as 181 * an array of key => value mappings, where the key is displayed 182 * to the user as the label and the value is the value of the checkbox. 183 * The ID of each checkbox is the prefix followed by the value. 184 * 185 * @param string $title The title to use for the field label 186 * @param string $prefix The prefix to use for the ID of each checkbox 187 * @param string $name The name of the field, which will be the key in $_POST 188 * @param array $options The options to display in the multiselect. 189 */ 190 protected function multicheck_field(string $title, string $prefix, string $name, array $options) { 191 ?> 192 <div class="vistawp-form-grid-item"> 193 <label for="<?php echo $name; ?>"><?php echo $title; ?></label> 194 <br /> 195 <?php 196 foreach ($options as $key => $value) { 197 ?> 198 <input type="checkbox" id="<?php echo $prefix . $value; ?>" name="<?php echo $name; ?>[]" value="<?php echo $value; ?>"> 199 <label for="<?php echo $prefix . $value; ?>"><?php echo $key; ?></label> 200 <?php 201 } 202 ?></div><?php 203 } 204 205 /** 206 * Outputs HTML for a number field 207 * @param string $id The id to give the <input> tag 208 * @param string $name The name to give the <input> tag 209 * @param string $label The label for the field 210 * @param string $value The value to give the <input> tag 211 * @param string $placeholder The placeholder to give the <input> tag 212 */ 213 protected function number_field(string $id, string $name, string $label, 214 string $value = '', string $placeholder = '') { 215 ?> 216 <div class="vistawp-form-grid-item"> 217 <label for="<?php echo $id; ?>"><?php echo $label; ?></label> 218 <input type="number" id="<?php echo $id; ?>" name="<?php echo $name; ?>" 219 value="<?php echo $value; ?>" placeholder="<?php echo $placeholder; ?>"> 220 </div> 221 <?php 222 } 107 </form> 108 <?php 109 } 110 111 /** 112 * Outputs the HTML for a text input field 113 * @param string $id The id to give the <input> tag 114 * @param string $name The name to give the <input> tag 115 * @param string $label The label for the field 116 * @param string $value The value to give the <input> tag 117 * @param string $placeholder The placeholder to give the <input> tag 118 */ 119 protected function text_field( 120 string $id, 121 string $name, 122 string $label, 123 string $value = '', 124 string $placeholder = '' 125 ) { 126 ob_start(); 127 \vista_get_template( 128 'fields/text-field.php', 129 array( 130 'id' => $id, 131 'name' => $name, 132 'label' => $label, 133 'value' => $value, 134 'placeholder' => $placeholder, 135 ), 136 ); 137 138 echo ob_get_clean(); 139 } 140 141 /** 142 * Outputs HTML for the submit button 143 * @param string $text The text to display on the button 144 */ 145 protected function submit_button(string $text) { 146 echo sprintf( 147 '<div class="vwp-form-row-button-sm"><div class="vwp-form-item"><button type="submit" value="Submit">%s</button></div></div>', 148 esc_html($text) 149 ); 150 } 151 152 /** 153 * Outputs HTML for a <select> field 154 * The options are specified as an array of key => value mappings, 155 * and one can be selected by default. 156 * 157 * @param string $id The id to give the <select> tag 158 * @param string $name The name to give the <select> tag 159 * @param string $label The label for the field 160 * @param array $options The options to display in the multiselect. 161 * Each entry should be a key => value mapping, 162 * where the key is displayed to the user and 163 * the value is the value of the <option> tag. 164 * @param string $selected The VALUE of option to select by default 165 */ 166 protected function select_field( 167 string $id, 168 string $name, 169 string $label, 170 array $options, 171 string $placeholder = '', 172 string $selected = '' 173 ) { 174 ob_start(); 175 \vista_get_template( 176 'fields/select.php', 177 array( 178 'id' => $id, 179 'name' => $name, 180 'label' => $label, 181 'options' => $options, 182 'placeholder' => $placeholder, 183 'selected' => $selected, 184 ), 185 ); 186 187 echo ob_get_clean(); 188 } 189 190 /** 191 * Outputs HTML for a series of checkboxes whose results 192 * are grouped into an array. The options are specified as 193 * an array of key => value mappings, where the key is displayed 194 * to the user as the label and the value is the value of the checkbox. 195 * The ID of each checkbox is the prefix followed by the value. 196 * 197 * @param string $title The title to use for the field label 198 * @param string $prefix The prefix to use for the ID of each checkbox 199 * @param string $name The name of the field, which will be the key in $_POST 200 * @param array $options The options to display in the multiselect. 201 */ 202 protected function checkbox_field( 203 string $title, 204 string $prefix, 205 string $name, 206 array $options 207 ) { 208 ob_start(); 209 \vista_get_template( 210 'fields/checkbox.php', 211 array( 212 'title' => $title, 213 'prefix' => $prefix, 214 'name' => $name, 215 'options' => $options, 216 ), 217 ); 218 219 echo ob_get_clean(); 220 } 221 222 /** 223 * Outputs HTML for a number field 224 * @param string $id The id to give the <input> tag 225 * @param string $name The name to give the <input> tag 226 * @param string $label The label for the field 227 * @param string $value The value to give the <input> tag 228 * @param string $placeholder The placeholder to give the <input> tag 229 */ 230 protected function number_field( 231 string $id, 232 string $name, 233 string $label, 234 string $value = '', 235 string $placeholder = '' 236 ) { 237 ob_start(); 238 \vista_get_template( 239 'fields/number-field.php', 240 array( 241 'id' => $id, 242 'name' => $name, 243 'label' => $label, 244 'value' => $value, 245 'placeholder' => $placeholder, 246 ), 247 ); 248 249 echo ob_get_clean(); 250 } 223 251 } 224 252 -
vistawp/trunk/includes/forms/advanced.php
r2949654 r2978340 45 45 public function render($atts): string { 46 46 ob_start(); 47 48 47 $this->form_header(self::FORM_ID, \sanitize_text_field($atts['dest'] ?? "")); 49 48 $this->maybe_add_status($atts); 50 49 51 echo '<div class="vistawp-form-grid-row">'; 52 $this->text_field('q', 'q', 'Search Query'); 53 $this->multicheck_field('Property Type', 'R', 'type', array( 50 $this->text_field('q', 'q', 'Location', '', 'City, Zip Code, or Street Name'); 51 $this->checkbox_field('Property Type', 'R', 'type', array( 54 52 'Residential' => 'residential', 55 53 'Condominium' => 'condominium', … … 58 56 )); 59 57 60 $this->number_field('minprice', 'minprice', 'Minimum Price' );61 $this->number_field('maxprice', 'maxprice', 'Maximum Price' );58 $this->number_field('minprice', 'minprice', 'Minimum Price', '', '$ Min Price...'); 59 $this->number_field('maxprice', 'maxprice', 'Maximum Price', '', '$ Max Price...'); 62 60 63 61 // Min Beds and Baths … … 75 73 '10' => '10' 76 74 ); 77 $this->select_field('minbeds', 'minbeds', 'Minimum Beds', $options); 78 $this->select_field('minbaths', 'minbaths', 'Minimum Baths', $options); 79 80 echo '</div>'; 81 echo '<div class="vistawp-form-grid-row-3">'; 82 75 $this->select_field('minbeds', 'minbeds', 'Minimum Beds', $options, 'How many beds?'); 76 $this->select_field('minbaths', 'minbaths', 'Minimum Baths', $options, 'How many bathrooms?'); 83 77 $this->number_field('minsqft', 'minsqft', 'Minimum Sqft'); 84 78 $this->number_field('minacres', 'minacres', 'Minimum Lot Acres'); 85 79 $this->number_field('minyear', 'minyear', 'Minimum Year Built'); 86 87 echo '</div>'; 88 echo '<div class="vistawp-form-grid-row">'; 89 90 $this->select_field('mingarage', 'mingarage', 'Minimum Garage Spaces', array( 80 $this->select_field('mingarage', 'mingarage', 'Minimum Garage Spaces', 81 array( 91 82 '' => '', 92 83 '1' => '1', 93 84 '2' => '2', 94 85 '3' => '3', 95 '4' => '4' 96 )); 86 '4' => '4', 87 ), 88 ); 97 89 $this->number_field('limit', 'limit', 'Listings Per Page'); 98 99 echo '</div>';100 90 $this->submit_button('Submit'); 101 91 $this->form_footer(); -
vistawp/trunk/includes/forms/basic.php
r2949654 r2978340 63 63 ); 64 64 65 echo '<div class="vistawp-form-grid-row">'; 66 $this->text_field('q', 'q', 'Search Query:'); 67 $this->multicheck_field("Property Type: ", "ptype-", "type", array( 68 "Residential" => "Residential", 69 "Condominium" => "Condominium", 70 "Multifamily" => "Multifamily", 71 "Land" => "Land", 72 )); 73 $this->number_field('minprice', 'minprice', 'Minimum Price:'); 74 $this->number_field('maxprice', 'maxprice', 'Maximum Price:'); 75 $this->select_field('minbeds', 'minbeds', 'Minimum Beds', $options, ""); 76 $this->select_field('minbaths', 'minbaths', 'Minimum Baths', $options, ""); 77 echo '</div>'; 65 $this->text_field('q', 'q', 'Location', '', 'City, Zip Code, or Street Name'); 66 $this->checkbox_field( 67 'Property Type ', 68 'ptype-', 69 'type', 70 array( 71 'Residential' => 'residential', 72 'Condominium' => 'condominium', 73 'Multifamily' => 'multifamily', 74 'Land' => 'land', 75 ), 76 ); 77 $this->number_field('minprice', 'minprice', 'Minimum Price', '', '$ Min Price...'); 78 $this->number_field('maxprice', 'maxprice', 'Maximum Price', '', '$ Max Price...'); 79 $this->select_field('minbeds', 'minbeds', 'Minimum Beds', $options, 'How many beds?'); 80 $this->select_field('minbaths', 'minbaths', 'Minimum Baths', $options, 'How many bathrooms?'); 78 81 79 82 $this->submit_button('Submit'); -
vistawp/trunk/includes/forms/search.php
r2949654 r2978340 46 46 */ 47 47 public function render($atts): string { 48 ob_start();49 $this->form_header(self::FORM_ID, \sanitize_text_field($atts['dest'] ?? ""));50 $this->maybe_add_status($atts);51 $this->text_field('q', 'q', 'Search Query:');52 $this->submit_button('Submit');53 $this->form_footer();54 return ob_get_clean();48 ob_start(); 49 $this->form_header(self::FORM_ID, \sanitize_text_field($atts['dest'] ?? "")); 50 $this->maybe_add_status($atts); 51 $this->text_field('q', 'q', 'Location', '', 'City, Zip Code, or Street Name'); 52 $this->submit_button('Submit'); 53 $this->form_footer(); 54 return ob_get_clean(); 55 55 } 56 56 } 57 ?> -
vistawp/trunk/includes/functions.php
r2964274 r2978340 3 3 // Exit if accessed directly. 4 4 defined( 'ABSPATH' ) || exit; 5 6 if(! function_exists('vista_get_template')) { 7 /** 8 * Loads a template file from the specified template directory. 9 * 10 * This function attempts to include the specified template file from the template 11 * directory defined by the VISTA__PLUGIN_DIR constant. If the file does not exist, 12 * it returns an error message. 13 * 14 * Each template includes specifications for the variables used therein. 15 * 16 * @param string $template_name The name of the template file to load. 17 * @param array $args Optional. An associative array of variables to pass to the template. 18 * 19 * @return string|void The content of the template if it's found, or an exception if the template is missing. 20 * 21 * @throws \Exception If the specified template is not found at the given path. 22 */ 23 function vista_get_template(string $template_name, array $args = array()): void { 24 $default_path = VISTA__PLUGIN_DIR . 'templates/'; 25 $template = $default_path . $template_name; 26 27 if (! file_exists( $template )) { 28 throw new \Exception('The template file is missing.'); 29 } 30 31 if (! empty( $args )) { 32 extract( $args ); 33 } 34 35 include $template; 36 } 37 } 5 38 6 39 // Add the str_contains function from php 8 … … 43 76 */ 44 77 function vista_plugin_url(string $path): string { 45 return plugins_url($path, dirname(__FILE__)); 78 return plugins_url( 79 $path, 80 VISTA__PLUGIN_DIR . '/vista' 81 ); 46 82 } 47 83 } -
vistawp/trunk/readme.txt
r2973600 r2978340 5 5 Requires at least: 4.7 6 6 Tested up to: 6.3 7 Stable tag: 1.2. 17 Stable tag: 1.2.2 8 8 Requires PHP: 7.0 9 9 License: GPLv2 or later -
vistawp/trunk/vista.php
r2973600 r2978340 3 3 * Plugin Name: VistaWP 4 4 * Description: Retrieves and displays real estate listings 5 * Version: 1.2. 15 * Version: 1.2.2 6 6 * Author: VistaWP 7 7 * Author URI: https://vistawp.com/ … … 13 13 // Exit if accessed directly. 14 14 defined( 'ABSPATH' ) || exit; 15 16 // general constants 17 define( 'VISTA__PLUGIN_VERSION', '1.2.2' ); 18 define( 'VISTA__PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); 19 define( 'VISTA__PLUGIN_URL', plugin_dir_url( __FILE__ ) ); 20 define( 'VISTA__PLUGIN_TEXTDOMAIN', 'crm' ); 15 21 16 22 /** … … 184 190 // Abstract class for forms 185 191 if ( !class_exists("\\VSTA\\Forms\\Form") ) { 186 require_once 'includes/forms/ Form.php';192 require_once 'includes/forms/form.php'; 187 193 } 188 194 // Class for Vistawp Advanced form
Note: See TracChangeset
for help on using the changeset viewer.