@@ -28,260 +28,260 @@ discard block |
||
28 | 28 | |
29 | 29 | if (!class_exists('Tax_Meta_Class')) : |
30 | 30 | |
31 | - /** |
|
32 | - * All Types Meta Box class. |
|
33 | - * |
|
34 | - * @package All Types Meta Box |
|
35 | - * @since 1.0 |
|
36 | - * |
|
37 | - * @todo Nothing. |
|
38 | - */ |
|
39 | - |
|
40 | - |
|
41 | - class Tax_Meta_Class |
|
42 | - { |
|
43 | - |
|
44 | - /** |
|
45 | - * Holds meta box object |
|
46 | - * |
|
47 | - * @var object |
|
48 | - * @access protected |
|
49 | - */ |
|
50 | - protected $_meta_box; |
|
51 | - |
|
52 | - /** |
|
53 | - * Holds meta box fields. |
|
54 | - * |
|
55 | - * @var array |
|
56 | - * @access protected |
|
57 | - */ |
|
58 | - protected $_prefix; |
|
59 | - |
|
60 | - /** |
|
61 | - * Holds Prefix for meta box fields. |
|
62 | - * |
|
63 | - * @var array |
|
64 | - * @access protected |
|
65 | - */ |
|
66 | - protected $_fields; |
|
67 | - |
|
68 | - /** |
|
69 | - * Use local images. |
|
70 | - * |
|
71 | - * @var bool |
|
72 | - * @access protected |
|
73 | - */ |
|
74 | - protected $_Local_images; |
|
75 | - |
|
76 | - /** |
|
77 | - * What form is this? edit or new term. |
|
78 | - * |
|
79 | - * @var string |
|
80 | - * @access protected |
|
81 | - * $since 1.0 |
|
82 | - */ |
|
83 | - protected $_form_type; |
|
84 | - /** |
|
85 | - * SelfPath to allow themes as well as plugins. |
|
86 | - * |
|
87 | - * @var string |
|
88 | - * @access protected |
|
89 | - * $since 1.0 |
|
90 | - */ |
|
91 | - protected $SelfPath; |
|
92 | - |
|
93 | - /** |
|
94 | - * Constructor |
|
95 | - * |
|
96 | - * @since 1.0 |
|
97 | - * @access public |
|
98 | - * |
|
99 | - * @param array $meta_box |
|
100 | - */ |
|
101 | - public function __construct($meta_box) |
|
102 | - { |
|
103 | - |
|
104 | - // If we are not in admin area exit. |
|
105 | - if (!is_admin()) |
|
106 | - return; |
|
107 | - |
|
108 | - // Assign meta box values to local variables and add it's missed values. |
|
109 | - $this->_meta_box = $meta_box; |
|
110 | - $this->_prefix = (isset($meta_box['prefix'])) ? $meta_box['prefix'] : ''; |
|
111 | - $this->_fields = &$this->_meta_box['fields']; |
|
112 | - $this->_Local_images = (isset($meta_box['local_images'])) ? true : false; |
|
113 | - $this->add_missed_values(); |
|
114 | - if (isset($meta_box['use_with_theme'])) |
|
115 | - if ($meta_box['use_with_theme'] === true) { |
|
116 | - $this->SelfPath = get_stylesheet_directory_uri() . '/library/cat-meta'; |
|
117 | - } elseif ($meta_box['use_with_theme'] === false) { |
|
118 | - $this->SelfPath = plugins_url('cat-meta-functions', plugin_basename(dirname(__FILE__))); |
|
119 | - } else { |
|
120 | - $this->SelfPath = $meta_box['use_with_theme']; |
|
121 | - } |
|
122 | - else { |
|
123 | - $this->SelfPath = plugins_url('cat-meta-functions', plugin_basename(dirname(__FILE__))); |
|
124 | - } |
|
125 | - |
|
126 | - |
|
127 | - // Add Actions |
|
128 | - add_action('admin_init', array(&$this, 'add')); |
|
129 | - |
|
130 | - // Check for special fields and add needed actions for them. |
|
131 | - $this->check_field_upload(); |
|
132 | - $this->check_field_color(); |
|
133 | - $this->check_field_date(); |
|
134 | - $this->check_field_time(); |
|
135 | - |
|
136 | - // Load common js, css files |
|
137 | - // Must enqueue for all pages as we need js for the media upload, too. |
|
138 | - add_action('admin_print_styles', array(&$this, 'load_scripts_styles')); |
|
139 | - |
|
140 | - } |
|
141 | - |
|
142 | - /** |
|
143 | - * Load all Javascript and CSS |
|
144 | - * |
|
145 | - * @since 1.0 |
|
146 | - * @access public |
|
147 | - */ |
|
148 | - public function load_scripts_styles() |
|
149 | - { |
|
150 | - |
|
151 | - // Get Plugin Path |
|
152 | - $plugin_path = $this->SelfPath; |
|
153 | - //only load styles and js when needed |
|
154 | - /* |
|
31 | + /** |
|
32 | + * All Types Meta Box class. |
|
33 | + * |
|
34 | + * @package All Types Meta Box |
|
35 | + * @since 1.0 |
|
36 | + * |
|
37 | + * @todo Nothing. |
|
38 | + */ |
|
39 | + |
|
40 | + |
|
41 | + class Tax_Meta_Class |
|
42 | + { |
|
43 | + |
|
44 | + /** |
|
45 | + * Holds meta box object |
|
46 | + * |
|
47 | + * @var object |
|
48 | + * @access protected |
|
49 | + */ |
|
50 | + protected $_meta_box; |
|
51 | + |
|
52 | + /** |
|
53 | + * Holds meta box fields. |
|
54 | + * |
|
55 | + * @var array |
|
56 | + * @access protected |
|
57 | + */ |
|
58 | + protected $_prefix; |
|
59 | + |
|
60 | + /** |
|
61 | + * Holds Prefix for meta box fields. |
|
62 | + * |
|
63 | + * @var array |
|
64 | + * @access protected |
|
65 | + */ |
|
66 | + protected $_fields; |
|
67 | + |
|
68 | + /** |
|
69 | + * Use local images. |
|
70 | + * |
|
71 | + * @var bool |
|
72 | + * @access protected |
|
73 | + */ |
|
74 | + protected $_Local_images; |
|
75 | + |
|
76 | + /** |
|
77 | + * What form is this? edit or new term. |
|
78 | + * |
|
79 | + * @var string |
|
80 | + * @access protected |
|
81 | + * $since 1.0 |
|
82 | + */ |
|
83 | + protected $_form_type; |
|
84 | + /** |
|
85 | + * SelfPath to allow themes as well as plugins. |
|
86 | + * |
|
87 | + * @var string |
|
88 | + * @access protected |
|
89 | + * $since 1.0 |
|
90 | + */ |
|
91 | + protected $SelfPath; |
|
92 | + |
|
93 | + /** |
|
94 | + * Constructor |
|
95 | + * |
|
96 | + * @since 1.0 |
|
97 | + * @access public |
|
98 | + * |
|
99 | + * @param array $meta_box |
|
100 | + */ |
|
101 | + public function __construct($meta_box) |
|
102 | + { |
|
103 | + |
|
104 | + // If we are not in admin area exit. |
|
105 | + if (!is_admin()) |
|
106 | + return; |
|
107 | + |
|
108 | + // Assign meta box values to local variables and add it's missed values. |
|
109 | + $this->_meta_box = $meta_box; |
|
110 | + $this->_prefix = (isset($meta_box['prefix'])) ? $meta_box['prefix'] : ''; |
|
111 | + $this->_fields = &$this->_meta_box['fields']; |
|
112 | + $this->_Local_images = (isset($meta_box['local_images'])) ? true : false; |
|
113 | + $this->add_missed_values(); |
|
114 | + if (isset($meta_box['use_with_theme'])) |
|
115 | + if ($meta_box['use_with_theme'] === true) { |
|
116 | + $this->SelfPath = get_stylesheet_directory_uri() . '/library/cat-meta'; |
|
117 | + } elseif ($meta_box['use_with_theme'] === false) { |
|
118 | + $this->SelfPath = plugins_url('cat-meta-functions', plugin_basename(dirname(__FILE__))); |
|
119 | + } else { |
|
120 | + $this->SelfPath = $meta_box['use_with_theme']; |
|
121 | + } |
|
122 | + else { |
|
123 | + $this->SelfPath = plugins_url('cat-meta-functions', plugin_basename(dirname(__FILE__))); |
|
124 | + } |
|
125 | + |
|
126 | + |
|
127 | + // Add Actions |
|
128 | + add_action('admin_init', array(&$this, 'add')); |
|
129 | + |
|
130 | + // Check for special fields and add needed actions for them. |
|
131 | + $this->check_field_upload(); |
|
132 | + $this->check_field_color(); |
|
133 | + $this->check_field_date(); |
|
134 | + $this->check_field_time(); |
|
135 | + |
|
136 | + // Load common js, css files |
|
137 | + // Must enqueue for all pages as we need js for the media upload, too. |
|
138 | + add_action('admin_print_styles', array(&$this, 'load_scripts_styles')); |
|
139 | + |
|
140 | + } |
|
141 | + |
|
142 | + /** |
|
143 | + * Load all Javascript and CSS |
|
144 | + * |
|
145 | + * @since 1.0 |
|
146 | + * @access public |
|
147 | + */ |
|
148 | + public function load_scripts_styles() |
|
149 | + { |
|
150 | + |
|
151 | + // Get Plugin Path |
|
152 | + $plugin_path = $this->SelfPath; |
|
153 | + //only load styles and js when needed |
|
154 | + /* |
|
155 | 155 | * since 1.0 |
156 | 156 | */ |
157 | - $taxnow = isset($_REQUEST['taxonomy']) ? $_REQUEST['taxonomy'] : ''; |
|
158 | - |
|
159 | - if (!empty($this->_meta_box['pages'])) { |
|
160 | - if (in_array($taxnow, $this->_meta_box['pages'])) { |
|
161 | - // Enqueue Meta Box Style |
|
162 | - //wp_enqueue_style( 'tax-meta-clss', $plugin_path . '/css/Tax-meta-class.css' ); |
|
163 | - // Enqueue Meta Box Scripts |
|
164 | - //wp_enqueue_script( 'tax-meta-clss', $plugin_path . '/js/tax-meta-clss.js', array( 'jquery' ), null, true ); |
|
165 | - |
|
166 | - } |
|
167 | - } |
|
168 | - |
|
169 | - } |
|
170 | - |
|
171 | - /** |
|
172 | - * Check the Field Upload, Add needed Actions |
|
173 | - * |
|
174 | - * @since 1.0 |
|
175 | - * @access public |
|
176 | - */ |
|
177 | - public function enqueue_tax_meta_scripts() |
|
178 | - { |
|
179 | - // Make upload feature work event when custom post type doesn't support 'editor' |
|
180 | - wp_enqueue_script('media-upload'); |
|
181 | - wp_enqueue_script('thickbox'); |
|
182 | - add_thickbox(); |
|
183 | - wp_enqueue_script('jquery-ui-core'); |
|
184 | - wp_enqueue_script('jquery-ui-sortable'); |
|
185 | - |
|
186 | - |
|
187 | - } |
|
188 | - |
|
189 | - public function check_field_upload() |
|
190 | - { |
|
191 | - |
|
192 | - // Check if the field is an image or file. If not, return. |
|
193 | - if (!$this->has_field('image') && !$this->has_field('file')) |
|
194 | - return; |
|
195 | - |
|
196 | - |
|
197 | - add_action('wp_enqueue_scripts', array(&$this, 'enqueue_tax_meta_scripts'), 100); |
|
198 | - |
|
199 | - // Add data encoding type for file uploading. |
|
200 | - add_action('post_edit_form_tag', array(&$this, 'add_enctype')); |
|
201 | - |
|
202 | - |
|
203 | - // Add filters for media upload. |
|
204 | - add_filter('media_upload_gallery', array(&$this, 'insert_images')); |
|
205 | - add_filter('media_upload_library', array(&$this, 'insert_images')); |
|
206 | - add_filter('media_upload_image', array(&$this, 'insert_images')); |
|
207 | - |
|
208 | - // Delete all attachments when delete custom post type. |
|
209 | - add_action('wp_ajax_at_delete_file', array(&$this, 'delete_file')); |
|
210 | - add_action('wp_ajax_at_reorder_images', array(&$this, 'reorder_images')); |
|
211 | - // Delete file via Ajax |
|
212 | - add_action('wp_ajax_at_delete_mupload', array($this, 'wp_ajax_delete_image')); |
|
213 | - } |
|
214 | - |
|
215 | - /** |
|
216 | - * Add data encoding type for file uploading |
|
217 | - * |
|
218 | - * @since 1.0 |
|
219 | - * @access public |
|
220 | - */ |
|
221 | - public function add_enctype() |
|
222 | - { |
|
223 | - echo ' enctype="multipart/form-data"'; |
|
224 | - } |
|
225 | - |
|
226 | - /** |
|
227 | - * Process images added to meta field. |
|
228 | - * |
|
229 | - * Modified from Faster Image Insert plugin. |
|
230 | - * |
|
231 | - * @return void |
|
232 | - * @author Cory Crowley |
|
233 | - */ |
|
234 | - public function insert_images() |
|
235 | - { |
|
236 | - |
|
237 | - // If post variables are empty, return. |
|
238 | - if (!isset($_POST['at-insert']) || empty($_POST['attachments'])) |
|
239 | - return; |
|
240 | - |
|
241 | - // Security Check |
|
242 | - check_admin_referer('media-form'); |
|
243 | - |
|
244 | - // Create Security Nonce |
|
245 | - $nonce = wp_create_nonce('at_ajax_delete'); |
|
246 | - |
|
247 | - // Get Post Id and Field Id |
|
248 | - $term_id = $_POST['post_id']; |
|
249 | - $id = $_POST['field_id']; |
|
250 | - |
|
251 | - // Modify the insertion string |
|
252 | - $html = ''; |
|
253 | - foreach ($_POST['attachments'] as $attachment_id => $attachment) { |
|
254 | - |
|
255 | - // Strip Slashes |
|
256 | - $attachment = stripslashes_deep($attachment); |
|
257 | - |
|
258 | - // If not selected or url is empty, continue in loop. |
|
259 | - if (empty($attachment['selected']) || empty($attachment['url'])) |
|
260 | - continue; |
|
261 | - |
|
262 | - $li = "<li id='item_{$attachment_id}'>"; |
|
263 | - $li .= "<img src='{$attachment['url']}' alt='image_{$attachment_id}' />"; |
|
264 | - //$li .= "<a title='" . __( 'Delete this image' ) . "' class='at-delete-file' href='#' rel='{$nonce}|{$term_id}|{$id}|{$attachment_id}'>" . __( 'Delete' ) . "</a>"; |
|
265 | - $li .= "<a title='" . __('Remove this image', 'geodirectory') . "' class='at-delete-file' href='#' rel='{$nonce}|{$term_id}|{$id}|{$attachment_id}'><img src='" . $this->SelfPath . "/images/delete-16.png' alt='" . __('Remove', 'geodirectory') . "' /></a>"; |
|
266 | - $li .= "<input type='hidden' name='{$id}[]' value='{$attachment_id}' />"; |
|
267 | - $li .= "</li>"; |
|
268 | - $html .= $li; |
|
269 | - |
|
270 | - } // End For Each |
|
271 | - |
|
272 | - return media_send_to_editor($html); |
|
273 | - |
|
274 | - } |
|
275 | - |
|
276 | - /** |
|
277 | - * Delete attachments associated with the post. |
|
278 | - * |
|
279 | - * @since 1.0 |
|
280 | - * @access public |
|
281 | - * |
|
282 | - * @param int|string $term_id The term ID. |
|
283 | - */ |
|
284 | - /*public function delete_attachments( $term_id ) { |
|
157 | + $taxnow = isset($_REQUEST['taxonomy']) ? $_REQUEST['taxonomy'] : ''; |
|
158 | + |
|
159 | + if (!empty($this->_meta_box['pages'])) { |
|
160 | + if (in_array($taxnow, $this->_meta_box['pages'])) { |
|
161 | + // Enqueue Meta Box Style |
|
162 | + //wp_enqueue_style( 'tax-meta-clss', $plugin_path . '/css/Tax-meta-class.css' ); |
|
163 | + // Enqueue Meta Box Scripts |
|
164 | + //wp_enqueue_script( 'tax-meta-clss', $plugin_path . '/js/tax-meta-clss.js', array( 'jquery' ), null, true ); |
|
165 | + |
|
166 | + } |
|
167 | + } |
|
168 | + |
|
169 | + } |
|
170 | + |
|
171 | + /** |
|
172 | + * Check the Field Upload, Add needed Actions |
|
173 | + * |
|
174 | + * @since 1.0 |
|
175 | + * @access public |
|
176 | + */ |
|
177 | + public function enqueue_tax_meta_scripts() |
|
178 | + { |
|
179 | + // Make upload feature work event when custom post type doesn't support 'editor' |
|
180 | + wp_enqueue_script('media-upload'); |
|
181 | + wp_enqueue_script('thickbox'); |
|
182 | + add_thickbox(); |
|
183 | + wp_enqueue_script('jquery-ui-core'); |
|
184 | + wp_enqueue_script('jquery-ui-sortable'); |
|
185 | + |
|
186 | + |
|
187 | + } |
|
188 | + |
|
189 | + public function check_field_upload() |
|
190 | + { |
|
191 | + |
|
192 | + // Check if the field is an image or file. If not, return. |
|
193 | + if (!$this->has_field('image') && !$this->has_field('file')) |
|
194 | + return; |
|
195 | + |
|
196 | + |
|
197 | + add_action('wp_enqueue_scripts', array(&$this, 'enqueue_tax_meta_scripts'), 100); |
|
198 | + |
|
199 | + // Add data encoding type for file uploading. |
|
200 | + add_action('post_edit_form_tag', array(&$this, 'add_enctype')); |
|
201 | + |
|
202 | + |
|
203 | + // Add filters for media upload. |
|
204 | + add_filter('media_upload_gallery', array(&$this, 'insert_images')); |
|
205 | + add_filter('media_upload_library', array(&$this, 'insert_images')); |
|
206 | + add_filter('media_upload_image', array(&$this, 'insert_images')); |
|
207 | + |
|
208 | + // Delete all attachments when delete custom post type. |
|
209 | + add_action('wp_ajax_at_delete_file', array(&$this, 'delete_file')); |
|
210 | + add_action('wp_ajax_at_reorder_images', array(&$this, 'reorder_images')); |
|
211 | + // Delete file via Ajax |
|
212 | + add_action('wp_ajax_at_delete_mupload', array($this, 'wp_ajax_delete_image')); |
|
213 | + } |
|
214 | + |
|
215 | + /** |
|
216 | + * Add data encoding type for file uploading |
|
217 | + * |
|
218 | + * @since 1.0 |
|
219 | + * @access public |
|
220 | + */ |
|
221 | + public function add_enctype() |
|
222 | + { |
|
223 | + echo ' enctype="multipart/form-data"'; |
|
224 | + } |
|
225 | + |
|
226 | + /** |
|
227 | + * Process images added to meta field. |
|
228 | + * |
|
229 | + * Modified from Faster Image Insert plugin. |
|
230 | + * |
|
231 | + * @return void |
|
232 | + * @author Cory Crowley |
|
233 | + */ |
|
234 | + public function insert_images() |
|
235 | + { |
|
236 | + |
|
237 | + // If post variables are empty, return. |
|
238 | + if (!isset($_POST['at-insert']) || empty($_POST['attachments'])) |
|
239 | + return; |
|
240 | + |
|
241 | + // Security Check |
|
242 | + check_admin_referer('media-form'); |
|
243 | + |
|
244 | + // Create Security Nonce |
|
245 | + $nonce = wp_create_nonce('at_ajax_delete'); |
|
246 | + |
|
247 | + // Get Post Id and Field Id |
|
248 | + $term_id = $_POST['post_id']; |
|
249 | + $id = $_POST['field_id']; |
|
250 | + |
|
251 | + // Modify the insertion string |
|
252 | + $html = ''; |
|
253 | + foreach ($_POST['attachments'] as $attachment_id => $attachment) { |
|
254 | + |
|
255 | + // Strip Slashes |
|
256 | + $attachment = stripslashes_deep($attachment); |
|
257 | + |
|
258 | + // If not selected or url is empty, continue in loop. |
|
259 | + if (empty($attachment['selected']) || empty($attachment['url'])) |
|
260 | + continue; |
|
261 | + |
|
262 | + $li = "<li id='item_{$attachment_id}'>"; |
|
263 | + $li .= "<img src='{$attachment['url']}' alt='image_{$attachment_id}' />"; |
|
264 | + //$li .= "<a title='" . __( 'Delete this image' ) . "' class='at-delete-file' href='#' rel='{$nonce}|{$term_id}|{$id}|{$attachment_id}'>" . __( 'Delete' ) . "</a>"; |
|
265 | + $li .= "<a title='" . __('Remove this image', 'geodirectory') . "' class='at-delete-file' href='#' rel='{$nonce}|{$term_id}|{$id}|{$attachment_id}'><img src='" . $this->SelfPath . "/images/delete-16.png' alt='" . __('Remove', 'geodirectory') . "' /></a>"; |
|
266 | + $li .= "<input type='hidden' name='{$id}[]' value='{$attachment_id}' />"; |
|
267 | + $li .= "</li>"; |
|
268 | + $html .= $li; |
|
269 | + |
|
270 | + } // End For Each |
|
271 | + |
|
272 | + return media_send_to_editor($html); |
|
273 | + |
|
274 | + } |
|
275 | + |
|
276 | + /** |
|
277 | + * Delete attachments associated with the post. |
|
278 | + * |
|
279 | + * @since 1.0 |
|
280 | + * @access public |
|
281 | + * |
|
282 | + * @param int|string $term_id The term ID. |
|
283 | + */ |
|
284 | + /*public function delete_attachments( $term_id ) { |
|
285 | 285 | |
286 | 286 | // Get Attachments |
287 | 287 | $attachments = get_posts( array( 'numberposts' => -1, 'post_type' => 'attachment', 'post_parent' => $term_id ) ); |
@@ -295,349 +295,349 @@ discard block |
||
295 | 295 | |
296 | 296 | }*/ |
297 | 297 | |
298 | - /** |
|
299 | - * Ajax callback for deleting files. |
|
300 | - * |
|
301 | - * Modified from a function used by "Verve Meta Boxes" plugin ( http://goo.gl/aw64H ) |
|
302 | - * |
|
303 | - * @since 1.0 |
|
304 | - * @access public |
|
305 | - */ |
|
306 | - public function delete_file() |
|
307 | - { |
|
308 | - |
|
309 | - |
|
310 | - // If data is not set, die. |
|
311 | - if (!isset($_POST['data'])) |
|
312 | - die(); |
|
313 | - |
|
314 | - list($nonce, $term_id, $key, $attach_id) = explode('|', $_POST['data']); |
|
315 | - |
|
316 | - if (!wp_verify_nonce($nonce, 'at_ajax_delete')) |
|
317 | - die('1'); |
|
318 | - |
|
319 | - $this->delete_tax_meta($term_id, $key, $attach_id); |
|
320 | - |
|
321 | - die('0'); |
|
322 | - |
|
323 | - } |
|
324 | - |
|
325 | - /** |
|
326 | - * Ajax callback for deleting files. |
|
327 | - * Modified from a function used by "Verve Meta Boxes" plugin (http://goo.gl/LzYSq) |
|
328 | - * @since 1.0 |
|
329 | - * @access public |
|
330 | - */ |
|
331 | - public function wp_ajax_delete_image() |
|
332 | - { |
|
333 | - $term_id = isset($_GET['post_id']) ? intval($_GET['post_id']) : 0; |
|
334 | - $field_id = isset($_GET['field_id']) ? $_GET['field_id'] : 0; |
|
335 | - $attachment_id = isset($_GET['attachment_id']) ? intval($_GET['attachment_id']) : 0; |
|
336 | - $ok = false; |
|
337 | - if (strpos($field_id, '[') === false) { |
|
338 | - check_admin_referer("at-delete-mupload_" . urldecode($field_id)); |
|
339 | - if ($term_id > 0) |
|
340 | - $this->delete_tax_meta($term_id, $field_id); |
|
341 | - //$ok = wp_delete_attachment( $attachment_id ); |
|
342 | - $ok = 1; |
|
343 | - } else { |
|
344 | - $f = explode('[', urldecode($field_id)); |
|
345 | - $f_fiexed = array(); |
|
346 | - foreach ($f as $k => $v) { |
|
347 | - $f[$k] = str_replace(']', '', $v); |
|
348 | - } |
|
349 | - $saved = $this->get_tax_meta($term_id, $f[0], true); |
|
350 | - if (isset($saved[$f[1]][$f[2]])) { |
|
351 | - unset($saved[$f[1]][$f[2]]); |
|
352 | - if ($term_id > 0) |
|
353 | - update_post_meta($term_id, $f[0], $saved); |
|
354 | - //$ok = wp_delete_attachment( $attachment_id ); |
|
355 | - $ok = 1; |
|
356 | - } |
|
357 | - } |
|
358 | - |
|
359 | - |
|
360 | - if ($ok) { |
|
361 | - echo json_encode(array('status' => 'success')); |
|
362 | - die(); |
|
363 | - } else { |
|
364 | - echo json_encode(array('message' => __('Cannot delete file. Something\'s wrong.', 'geodirectory'))); |
|
365 | - die(); |
|
366 | - } |
|
367 | - } |
|
368 | - |
|
369 | - /** |
|
370 | - * Ajax callback for reordering Images. |
|
371 | - * |
|
372 | - * @since 1.0 |
|
373 | - * @access public |
|
374 | - */ |
|
375 | - public function reorder_images() |
|
376 | - { |
|
377 | - |
|
378 | - if (!isset($_POST['data'])) |
|
379 | - die(); |
|
380 | - |
|
381 | - list($order, $term_id, $key, $nonce) = explode('|', $_POST['data']); |
|
382 | - |
|
383 | - if (!wp_verify_nonce($nonce, 'at_ajax_reorder')) |
|
384 | - die('1'); |
|
385 | - |
|
386 | - parse_str($order, $items); |
|
387 | - $items = $items['item']; |
|
388 | - $order = 1; |
|
389 | - foreach ($items as $item) { |
|
390 | - wp_update_post(array('ID' => $item, 'post_parent' => $term_id, 'menu_order' => $order)); |
|
391 | - $order++; |
|
392 | - } |
|
393 | - |
|
394 | - die('0'); |
|
395 | - |
|
396 | - } |
|
397 | - |
|
398 | - /** |
|
399 | - * Check Field Color |
|
400 | - * |
|
401 | - * @since 1.0 |
|
402 | - * @access public |
|
403 | - */ |
|
404 | - public function check_field_color() |
|
405 | - { |
|
406 | - |
|
407 | - if ($this->has_field('color') && $this->is_edit_page()) { |
|
408 | - // Enqueu built-in script and style for color picker. |
|
409 | - wp_enqueue_style('farbtastic'); |
|
410 | - wp_enqueue_script('farbtastic'); |
|
411 | - } |
|
412 | - |
|
413 | - } |
|
414 | - |
|
415 | - /** |
|
416 | - * Check Field Date |
|
417 | - * |
|
418 | - * @since 1.0 |
|
419 | - * @access public |
|
420 | - */ |
|
421 | - public function check_field_date() |
|
422 | - { |
|
423 | - |
|
424 | - if ($this->has_field('date') && $this->is_edit_page()) { |
|
425 | - // Enqueu JQuery UI, use proper version. |
|
426 | - wp_enqueue_style('tmc-jquery-ui-css', 'https://ajax.googleapis.com/ajax/libs/jqueryui/' . $this->get_jqueryui_ver() . '/themes/base/jquery-ui.css'); |
|
427 | - wp_enqueue_script('tmc-jquery-ui', 'https://ajax.googleapis.com/ajax/libs/jqueryui/' . $this->get_jqueryui_ver() . '/jquery-ui.min.js', array('jquery')); |
|
428 | - } |
|
429 | - |
|
430 | - } |
|
431 | - |
|
432 | - /** |
|
433 | - * Check Field Time |
|
434 | - * |
|
435 | - * @since 1.0 |
|
436 | - * @access public |
|
437 | - */ |
|
438 | - public function check_field_time() |
|
439 | - { |
|
440 | - |
|
441 | - if ($this->has_field('time') && $this->is_edit_page()) { |
|
442 | - |
|
443 | - // Enqueu JQuery UI, use proper version. |
|
444 | - wp_enqueue_style('tmc-jquery-ui-css', 'https://ajax.googleapis.com/ajax/libs/jqueryui/' . $this->get_jqueryui_ver() . '/themes/base/jquery-ui.css', array(), false, true); |
|
445 | - wp_enqueue_script('tmc-jquery-ui', 'https://ajax.googleapis.com/ajax/libs/jqueryui/' . $this->get_jqueryui_ver() . '/jquery-ui.min.js', array('jquery'), false, true); |
|
446 | - wp_enqueue_script('at-timepicker', 'https://github.com/trentrichardson/jQuery-Timepicker-Addon/raw/master/jquery-ui-timepicker-addon.js', array('tmc-jquery-ui'), false, true); |
|
447 | - |
|
448 | - } |
|
449 | - |
|
450 | - } |
|
451 | - |
|
452 | - /** |
|
453 | - * Add Meta Box for multiple post types. |
|
454 | - * |
|
455 | - * @since 1.0 |
|
456 | - * @access public |
|
457 | - */ |
|
458 | - public function add() |
|
459 | - { |
|
460 | - |
|
461 | - // Loop through array |
|
462 | - if (!empty($this->_meta_box['pages'])) { |
|
463 | - foreach ($this->_meta_box['pages'] as $page) { |
|
464 | - //add fields to edit form |
|
465 | - add_action($page . '_edit_form_fields', array(&$this, 'show_edit_form')); |
|
466 | - //add fields to add new form |
|
467 | - add_action($page . '_add_form_fields', array(&$this, 'show_new_form')); |
|
468 | - // this saves the edit fields |
|
469 | - add_action('edited_' . $page, array(&$this, 'save'), 10, 2); |
|
470 | - // this saves the add fields |
|
471 | - add_action('created_' . $page, array(&$this, 'save'), 10, 2); |
|
472 | - } |
|
473 | - } |
|
474 | - |
|
475 | - } |
|
476 | - |
|
477 | - /** |
|
478 | - * Callback function to show fields on add new taxonomy term form. |
|
479 | - * |
|
480 | - * @since 1.0 |
|
481 | - * @access public |
|
482 | - */ |
|
483 | - public function show_new_form($term_id) |
|
484 | - { |
|
485 | - $this->_form_type = 'new'; |
|
486 | - $this->show($term_id); |
|
487 | - } |
|
488 | - |
|
489 | - /** |
|
490 | - * Callback function to show fields on term edit form. |
|
491 | - * |
|
492 | - * @since 1.0 |
|
493 | - * @access public |
|
494 | - */ |
|
495 | - public function show_edit_form($term_id) |
|
496 | - { |
|
497 | - $this->_form_type = 'edit'; |
|
498 | - $this->show($term_id); |
|
499 | - } |
|
500 | - |
|
501 | - |
|
502 | - /** |
|
503 | - * Callback function to show fields in meta box. |
|
504 | - * |
|
505 | - * @since 1.0 |
|
506 | - * @access public |
|
507 | - */ |
|
508 | - public function show($term_id) |
|
509 | - { |
|
510 | - |
|
511 | - wp_nonce_field(basename(__FILE__), 'tax_meta_class_nonce'); |
|
512 | - |
|
513 | - foreach ($this->_fields as $field) { |
|
514 | - $meta = $this->get_tax_meta($term_id, $field['id'], !$field['multiple']); |
|
515 | - $meta = ($meta !== '') ? $meta : $field['std']; |
|
516 | - if ('image' != $field['type'] && $field['type'] != 'repeater') |
|
517 | - $meta = is_array($meta) ? array_map('esc_attr', $meta) : esc_attr($meta); |
|
518 | - |
|
519 | - if ($field['validate_func']) { |
|
520 | - echo '<tr class="form-field form-required ' . $field['style'] . '">'; |
|
521 | - } else { |
|
522 | - echo '<tr class="form-field ' . $field['style'] . '">'; |
|
523 | - } |
|
524 | - |
|
525 | - // Call Separated methods for displaying each type of field. |
|
526 | - call_user_func(array(&$this, 'show_field_' . $field['type']), $field, $meta); |
|
527 | - echo '</tr>'; |
|
528 | - } |
|
529 | - echo '</table>'; |
|
530 | - } |
|
531 | - |
|
532 | - /** |
|
533 | - * Show Repeater Fields. |
|
534 | - * |
|
535 | - * @param string $field |
|
536 | - * @param string $meta |
|
537 | - * @since 1.0 |
|
538 | - * @access public |
|
539 | - */ |
|
540 | - public function show_field_repeater($field, $meta) |
|
541 | - { |
|
542 | - // Get Plugin Path |
|
543 | - $plugin_path = $this->SelfPath; |
|
544 | - $this->show_field_begin($field, $meta); |
|
545 | - echo "<div class='at-repeat' id='{$field['id']}'>"; |
|
546 | - |
|
547 | - $c = 0; |
|
548 | - |
|
549 | - if (count($meta) > 0 && is_array($meta)) { |
|
550 | - foreach ($meta as $me) { |
|
551 | - //for labling toggles |
|
552 | - $mmm = $me[$field['fields'][0]['id']]; |
|
553 | - echo '<div class="at-repater-block">' . $mmm . '<br/><table class="repeater-table" style="display: none;">'; |
|
554 | - if ($field['inline']) { |
|
555 | - echo '<tr class="at-inline" VALIGN="top">'; |
|
556 | - } |
|
557 | - foreach ($field['fields'] as $f) { |
|
558 | - //reset var $id for repeater |
|
559 | - $id = ''; |
|
560 | - $id = $field['id'] . '[' . $c . '][' . $f['id'] . ']'; |
|
561 | - $m = $me[$f['id']]; |
|
562 | - $m = ($m !== '') ? $m : $f['std']; |
|
563 | - if ('image' != $f['type'] && $f['type'] != 'repeater') |
|
564 | - $m = is_array($m) ? array_map('esc_attr', $m) : esc_attr($m); |
|
565 | - //set new id for field in array format |
|
566 | - $f['id'] = $id; |
|
567 | - if (!$field['inline']) { |
|
568 | - echo '<tr>'; |
|
569 | - } |
|
570 | - call_user_func(array(&$this, 'show_field_' . $f['type']), $f, $m); |
|
571 | - if (!$field['inline']) { |
|
572 | - echo '</tr>'; |
|
573 | - } |
|
574 | - } |
|
575 | - if ($field['inline']) { |
|
576 | - echo '</tr>'; |
|
577 | - } |
|
578 | - echo '</table> |
|
298 | + /** |
|
299 | + * Ajax callback for deleting files. |
|
300 | + * |
|
301 | + * Modified from a function used by "Verve Meta Boxes" plugin ( http://goo.gl/aw64H ) |
|
302 | + * |
|
303 | + * @since 1.0 |
|
304 | + * @access public |
|
305 | + */ |
|
306 | + public function delete_file() |
|
307 | + { |
|
308 | + |
|
309 | + |
|
310 | + // If data is not set, die. |
|
311 | + if (!isset($_POST['data'])) |
|
312 | + die(); |
|
313 | + |
|
314 | + list($nonce, $term_id, $key, $attach_id) = explode('|', $_POST['data']); |
|
315 | + |
|
316 | + if (!wp_verify_nonce($nonce, 'at_ajax_delete')) |
|
317 | + die('1'); |
|
318 | + |
|
319 | + $this->delete_tax_meta($term_id, $key, $attach_id); |
|
320 | + |
|
321 | + die('0'); |
|
322 | + |
|
323 | + } |
|
324 | + |
|
325 | + /** |
|
326 | + * Ajax callback for deleting files. |
|
327 | + * Modified from a function used by "Verve Meta Boxes" plugin (http://goo.gl/LzYSq) |
|
328 | + * @since 1.0 |
|
329 | + * @access public |
|
330 | + */ |
|
331 | + public function wp_ajax_delete_image() |
|
332 | + { |
|
333 | + $term_id = isset($_GET['post_id']) ? intval($_GET['post_id']) : 0; |
|
334 | + $field_id = isset($_GET['field_id']) ? $_GET['field_id'] : 0; |
|
335 | + $attachment_id = isset($_GET['attachment_id']) ? intval($_GET['attachment_id']) : 0; |
|
336 | + $ok = false; |
|
337 | + if (strpos($field_id, '[') === false) { |
|
338 | + check_admin_referer("at-delete-mupload_" . urldecode($field_id)); |
|
339 | + if ($term_id > 0) |
|
340 | + $this->delete_tax_meta($term_id, $field_id); |
|
341 | + //$ok = wp_delete_attachment( $attachment_id ); |
|
342 | + $ok = 1; |
|
343 | + } else { |
|
344 | + $f = explode('[', urldecode($field_id)); |
|
345 | + $f_fiexed = array(); |
|
346 | + foreach ($f as $k => $v) { |
|
347 | + $f[$k] = str_replace(']', '', $v); |
|
348 | + } |
|
349 | + $saved = $this->get_tax_meta($term_id, $f[0], true); |
|
350 | + if (isset($saved[$f[1]][$f[2]])) { |
|
351 | + unset($saved[$f[1]][$f[2]]); |
|
352 | + if ($term_id > 0) |
|
353 | + update_post_meta($term_id, $f[0], $saved); |
|
354 | + //$ok = wp_delete_attachment( $attachment_id ); |
|
355 | + $ok = 1; |
|
356 | + } |
|
357 | + } |
|
358 | + |
|
359 | + |
|
360 | + if ($ok) { |
|
361 | + echo json_encode(array('status' => 'success')); |
|
362 | + die(); |
|
363 | + } else { |
|
364 | + echo json_encode(array('message' => __('Cannot delete file. Something\'s wrong.', 'geodirectory'))); |
|
365 | + die(); |
|
366 | + } |
|
367 | + } |
|
368 | + |
|
369 | + /** |
|
370 | + * Ajax callback for reordering Images. |
|
371 | + * |
|
372 | + * @since 1.0 |
|
373 | + * @access public |
|
374 | + */ |
|
375 | + public function reorder_images() |
|
376 | + { |
|
377 | + |
|
378 | + if (!isset($_POST['data'])) |
|
379 | + die(); |
|
380 | + |
|
381 | + list($order, $term_id, $key, $nonce) = explode('|', $_POST['data']); |
|
382 | + |
|
383 | + if (!wp_verify_nonce($nonce, 'at_ajax_reorder')) |
|
384 | + die('1'); |
|
385 | + |
|
386 | + parse_str($order, $items); |
|
387 | + $items = $items['item']; |
|
388 | + $order = 1; |
|
389 | + foreach ($items as $item) { |
|
390 | + wp_update_post(array('ID' => $item, 'post_parent' => $term_id, 'menu_order' => $order)); |
|
391 | + $order++; |
|
392 | + } |
|
393 | + |
|
394 | + die('0'); |
|
395 | + |
|
396 | + } |
|
397 | + |
|
398 | + /** |
|
399 | + * Check Field Color |
|
400 | + * |
|
401 | + * @since 1.0 |
|
402 | + * @access public |
|
403 | + */ |
|
404 | + public function check_field_color() |
|
405 | + { |
|
406 | + |
|
407 | + if ($this->has_field('color') && $this->is_edit_page()) { |
|
408 | + // Enqueu built-in script and style for color picker. |
|
409 | + wp_enqueue_style('farbtastic'); |
|
410 | + wp_enqueue_script('farbtastic'); |
|
411 | + } |
|
412 | + |
|
413 | + } |
|
414 | + |
|
415 | + /** |
|
416 | + * Check Field Date |
|
417 | + * |
|
418 | + * @since 1.0 |
|
419 | + * @access public |
|
420 | + */ |
|
421 | + public function check_field_date() |
|
422 | + { |
|
423 | + |
|
424 | + if ($this->has_field('date') && $this->is_edit_page()) { |
|
425 | + // Enqueu JQuery UI, use proper version. |
|
426 | + wp_enqueue_style('tmc-jquery-ui-css', 'https://ajax.googleapis.com/ajax/libs/jqueryui/' . $this->get_jqueryui_ver() . '/themes/base/jquery-ui.css'); |
|
427 | + wp_enqueue_script('tmc-jquery-ui', 'https://ajax.googleapis.com/ajax/libs/jqueryui/' . $this->get_jqueryui_ver() . '/jquery-ui.min.js', array('jquery')); |
|
428 | + } |
|
429 | + |
|
430 | + } |
|
431 | + |
|
432 | + /** |
|
433 | + * Check Field Time |
|
434 | + * |
|
435 | + * @since 1.0 |
|
436 | + * @access public |
|
437 | + */ |
|
438 | + public function check_field_time() |
|
439 | + { |
|
440 | + |
|
441 | + if ($this->has_field('time') && $this->is_edit_page()) { |
|
442 | + |
|
443 | + // Enqueu JQuery UI, use proper version. |
|
444 | + wp_enqueue_style('tmc-jquery-ui-css', 'https://ajax.googleapis.com/ajax/libs/jqueryui/' . $this->get_jqueryui_ver() . '/themes/base/jquery-ui.css', array(), false, true); |
|
445 | + wp_enqueue_script('tmc-jquery-ui', 'https://ajax.googleapis.com/ajax/libs/jqueryui/' . $this->get_jqueryui_ver() . '/jquery-ui.min.js', array('jquery'), false, true); |
|
446 | + wp_enqueue_script('at-timepicker', 'https://github.com/trentrichardson/jQuery-Timepicker-Addon/raw/master/jquery-ui-timepicker-addon.js', array('tmc-jquery-ui'), false, true); |
|
447 | + |
|
448 | + } |
|
449 | + |
|
450 | + } |
|
451 | + |
|
452 | + /** |
|
453 | + * Add Meta Box for multiple post types. |
|
454 | + * |
|
455 | + * @since 1.0 |
|
456 | + * @access public |
|
457 | + */ |
|
458 | + public function add() |
|
459 | + { |
|
460 | + |
|
461 | + // Loop through array |
|
462 | + if (!empty($this->_meta_box['pages'])) { |
|
463 | + foreach ($this->_meta_box['pages'] as $page) { |
|
464 | + //add fields to edit form |
|
465 | + add_action($page . '_edit_form_fields', array(&$this, 'show_edit_form')); |
|
466 | + //add fields to add new form |
|
467 | + add_action($page . '_add_form_fields', array(&$this, 'show_new_form')); |
|
468 | + // this saves the edit fields |
|
469 | + add_action('edited_' . $page, array(&$this, 'save'), 10, 2); |
|
470 | + // this saves the add fields |
|
471 | + add_action('created_' . $page, array(&$this, 'save'), 10, 2); |
|
472 | + } |
|
473 | + } |
|
474 | + |
|
475 | + } |
|
476 | + |
|
477 | + /** |
|
478 | + * Callback function to show fields on add new taxonomy term form. |
|
479 | + * |
|
480 | + * @since 1.0 |
|
481 | + * @access public |
|
482 | + */ |
|
483 | + public function show_new_form($term_id) |
|
484 | + { |
|
485 | + $this->_form_type = 'new'; |
|
486 | + $this->show($term_id); |
|
487 | + } |
|
488 | + |
|
489 | + /** |
|
490 | + * Callback function to show fields on term edit form. |
|
491 | + * |
|
492 | + * @since 1.0 |
|
493 | + * @access public |
|
494 | + */ |
|
495 | + public function show_edit_form($term_id) |
|
496 | + { |
|
497 | + $this->_form_type = 'edit'; |
|
498 | + $this->show($term_id); |
|
499 | + } |
|
500 | + |
|
501 | + |
|
502 | + /** |
|
503 | + * Callback function to show fields in meta box. |
|
504 | + * |
|
505 | + * @since 1.0 |
|
506 | + * @access public |
|
507 | + */ |
|
508 | + public function show($term_id) |
|
509 | + { |
|
510 | + |
|
511 | + wp_nonce_field(basename(__FILE__), 'tax_meta_class_nonce'); |
|
512 | + |
|
513 | + foreach ($this->_fields as $field) { |
|
514 | + $meta = $this->get_tax_meta($term_id, $field['id'], !$field['multiple']); |
|
515 | + $meta = ($meta !== '') ? $meta : $field['std']; |
|
516 | + if ('image' != $field['type'] && $field['type'] != 'repeater') |
|
517 | + $meta = is_array($meta) ? array_map('esc_attr', $meta) : esc_attr($meta); |
|
518 | + |
|
519 | + if ($field['validate_func']) { |
|
520 | + echo '<tr class="form-field form-required ' . $field['style'] . '">'; |
|
521 | + } else { |
|
522 | + echo '<tr class="form-field ' . $field['style'] . '">'; |
|
523 | + } |
|
524 | + |
|
525 | + // Call Separated methods for displaying each type of field. |
|
526 | + call_user_func(array(&$this, 'show_field_' . $field['type']), $field, $meta); |
|
527 | + echo '</tr>'; |
|
528 | + } |
|
529 | + echo '</table>'; |
|
530 | + } |
|
531 | + |
|
532 | + /** |
|
533 | + * Show Repeater Fields. |
|
534 | + * |
|
535 | + * @param string $field |
|
536 | + * @param string $meta |
|
537 | + * @since 1.0 |
|
538 | + * @access public |
|
539 | + */ |
|
540 | + public function show_field_repeater($field, $meta) |
|
541 | + { |
|
542 | + // Get Plugin Path |
|
543 | + $plugin_path = $this->SelfPath; |
|
544 | + $this->show_field_begin($field, $meta); |
|
545 | + echo "<div class='at-repeat' id='{$field['id']}'>"; |
|
546 | + |
|
547 | + $c = 0; |
|
548 | + |
|
549 | + if (count($meta) > 0 && is_array($meta)) { |
|
550 | + foreach ($meta as $me) { |
|
551 | + //for labling toggles |
|
552 | + $mmm = $me[$field['fields'][0]['id']]; |
|
553 | + echo '<div class="at-repater-block">' . $mmm . '<br/><table class="repeater-table" style="display: none;">'; |
|
554 | + if ($field['inline']) { |
|
555 | + echo '<tr class="at-inline" VALIGN="top">'; |
|
556 | + } |
|
557 | + foreach ($field['fields'] as $f) { |
|
558 | + //reset var $id for repeater |
|
559 | + $id = ''; |
|
560 | + $id = $field['id'] . '[' . $c . '][' . $f['id'] . ']'; |
|
561 | + $m = $me[$f['id']]; |
|
562 | + $m = ($m !== '') ? $m : $f['std']; |
|
563 | + if ('image' != $f['type'] && $f['type'] != 'repeater') |
|
564 | + $m = is_array($m) ? array_map('esc_attr', $m) : esc_attr($m); |
|
565 | + //set new id for field in array format |
|
566 | + $f['id'] = $id; |
|
567 | + if (!$field['inline']) { |
|
568 | + echo '<tr>'; |
|
569 | + } |
|
570 | + call_user_func(array(&$this, 'show_field_' . $f['type']), $f, $m); |
|
571 | + if (!$field['inline']) { |
|
572 | + echo '</tr>'; |
|
573 | + } |
|
574 | + } |
|
575 | + if ($field['inline']) { |
|
576 | + echo '</tr>'; |
|
577 | + } |
|
578 | + echo '</table> |
|
579 | 579 | <span class="at-re-toggle"><img src="'; |
580 | - if ($this->_Local_images) { |
|
581 | - echo $plugin_path . '/images/edit.png'; |
|
582 | - } else { |
|
583 | - echo 'http://i.imgur.com/ka0E2.png'; |
|
584 | - } |
|
585 | - echo '" alt="Edit" title="Edit"/></span> |
|
580 | + if ($this->_Local_images) { |
|
581 | + echo $plugin_path . '/images/edit.png'; |
|
582 | + } else { |
|
583 | + echo 'http://i.imgur.com/ka0E2.png'; |
|
584 | + } |
|
585 | + echo '" alt="Edit" title="Edit"/></span> |
|
586 | 586 | <img src="'; |
587 | - if ($this->_Local_images) { |
|
588 | - echo $plugin_path . '/images/remove.png'; |
|
589 | - } else { |
|
590 | - echo 'http://i.imgur.com/g8Duj.png'; |
|
591 | - } |
|
592 | - echo '" alt="' . __('Remove', 'geodirectory') . '" title="' . __('Remove', 'geodirectory') . '" id="remove-' . $field['id'] . '"></div>'; |
|
593 | - $c = $c + 1; |
|
594 | - |
|
595 | - } |
|
596 | - $this->show_field_end($field, $meta); |
|
597 | - } |
|
598 | - |
|
599 | - echo '<img src="'; |
|
600 | - if ($this->_Local_images) { |
|
601 | - echo $plugin_path . '/images/add.png'; |
|
602 | - } else { |
|
603 | - echo 'http://i.imgur.com/w5Tuc.png'; |
|
604 | - } |
|
605 | - echo '" alt="' . __('Add', 'geodirectory') . '" title="' . __('Add', 'geodirectory') . '" id="add-' . $field['id'] . '"><br/></div>'; |
|
606 | - |
|
607 | - //create all fields once more for js function and catch with object buffer |
|
608 | - ob_start(); |
|
609 | - echo '<div class="at-repater-block"><table class="repeater-table">'; |
|
610 | - if ($field['inline']) { |
|
611 | - echo '<tr class="at-inline" VALIGN="top">'; |
|
612 | - } |
|
613 | - foreach ($field['fields'] as $f) { |
|
614 | - //reset var $id for repeater |
|
615 | - $id = ''; |
|
616 | - $id = $field['id'] . '[CurrentCounter][' . $f['id'] . ']'; |
|
617 | - $f['id'] = $id; |
|
618 | - if (!$field['inline']) { |
|
619 | - echo '<tr>'; |
|
620 | - } |
|
621 | - call_user_func(array(&$this, 'show_field_' . $f['type']), $f, ''); |
|
622 | - if (!$field['inline']) { |
|
623 | - echo '</tr>'; |
|
624 | - } |
|
625 | - } |
|
626 | - if ($field['inline']) { |
|
627 | - echo '</tr>'; |
|
628 | - } |
|
629 | - echo '</table><img src="'; |
|
630 | - if ($this->_Local_images) { |
|
631 | - echo $plugin_path . '/images/remove.png'; |
|
632 | - } else { |
|
633 | - echo 'http://i.imgur.com/g8Duj.png'; |
|
634 | - } |
|
635 | - echo '" alt="' . __('Remove', 'geodirectory') . '" title="' . __('Remove', 'geodirectory') . '" id="remove-' . $field['id'] . '"></div>'; |
|
636 | - $counter = 'countadd_' . $field['id']; |
|
637 | - $js_code = ob_get_clean(); |
|
638 | - $js_code = str_replace("'", "\"", $js_code); |
|
639 | - $js_code = str_replace("CurrentCounter", "' + " . $counter . " + '", $js_code); |
|
640 | - echo '<script> |
|
587 | + if ($this->_Local_images) { |
|
588 | + echo $plugin_path . '/images/remove.png'; |
|
589 | + } else { |
|
590 | + echo 'http://i.imgur.com/g8Duj.png'; |
|
591 | + } |
|
592 | + echo '" alt="' . __('Remove', 'geodirectory') . '" title="' . __('Remove', 'geodirectory') . '" id="remove-' . $field['id'] . '"></div>'; |
|
593 | + $c = $c + 1; |
|
594 | + |
|
595 | + } |
|
596 | + $this->show_field_end($field, $meta); |
|
597 | + } |
|
598 | + |
|
599 | + echo '<img src="'; |
|
600 | + if ($this->_Local_images) { |
|
601 | + echo $plugin_path . '/images/add.png'; |
|
602 | + } else { |
|
603 | + echo 'http://i.imgur.com/w5Tuc.png'; |
|
604 | + } |
|
605 | + echo '" alt="' . __('Add', 'geodirectory') . '" title="' . __('Add', 'geodirectory') . '" id="add-' . $field['id'] . '"><br/></div>'; |
|
606 | + |
|
607 | + //create all fields once more for js function and catch with object buffer |
|
608 | + ob_start(); |
|
609 | + echo '<div class="at-repater-block"><table class="repeater-table">'; |
|
610 | + if ($field['inline']) { |
|
611 | + echo '<tr class="at-inline" VALIGN="top">'; |
|
612 | + } |
|
613 | + foreach ($field['fields'] as $f) { |
|
614 | + //reset var $id for repeater |
|
615 | + $id = ''; |
|
616 | + $id = $field['id'] . '[CurrentCounter][' . $f['id'] . ']'; |
|
617 | + $f['id'] = $id; |
|
618 | + if (!$field['inline']) { |
|
619 | + echo '<tr>'; |
|
620 | + } |
|
621 | + call_user_func(array(&$this, 'show_field_' . $f['type']), $f, ''); |
|
622 | + if (!$field['inline']) { |
|
623 | + echo '</tr>'; |
|
624 | + } |
|
625 | + } |
|
626 | + if ($field['inline']) { |
|
627 | + echo '</tr>'; |
|
628 | + } |
|
629 | + echo '</table><img src="'; |
|
630 | + if ($this->_Local_images) { |
|
631 | + echo $plugin_path . '/images/remove.png'; |
|
632 | + } else { |
|
633 | + echo 'http://i.imgur.com/g8Duj.png'; |
|
634 | + } |
|
635 | + echo '" alt="' . __('Remove', 'geodirectory') . '" title="' . __('Remove', 'geodirectory') . '" id="remove-' . $field['id'] . '"></div>'; |
|
636 | + $counter = 'countadd_' . $field['id']; |
|
637 | + $js_code = ob_get_clean(); |
|
638 | + $js_code = str_replace("'", "\"", $js_code); |
|
639 | + $js_code = str_replace("CurrentCounter", "' + " . $counter . " + '", $js_code); |
|
640 | + echo '<script> |
|
641 | 641 | jQuery(document).ready(function() { |
642 | 642 | var ' . $counter . ' = ' . $c . '; |
643 | 643 | jQuery("#add-' . $field['id'] . '").live(\'click\', function() { |
@@ -650,7 +650,7 @@ discard block |
||
650 | 650 | }); |
651 | 651 | }); |
652 | 652 | </script>'; |
653 | - echo '<br/><style> |
|
653 | + echo '<br/><style> |
|
654 | 654 | .at-inline{line-height: 1 !important;} |
655 | 655 | .at-inline .at-field{border: 0px !important;} |
656 | 656 | .at-inline .at-label{margin: 0 0 1px !important;} |
@@ -658,531 +658,531 @@ discard block |
||
658 | 658 | .at-inline .at-textarea{width: 100px; height: 75px;} |
659 | 659 | .at-repater-block{background-color: #FFFFFF;border: 1px solid;margin: 2px;} |
660 | 660 | </style>'; |
661 | - $this->show_field_end($field, $meta); |
|
662 | - } |
|
663 | - |
|
664 | - /** |
|
665 | - * Begin Field. |
|
666 | - * |
|
667 | - * @param string $field |
|
668 | - * @param string $meta |
|
669 | - * @since 1.0 |
|
670 | - * @access public |
|
671 | - */ |
|
672 | - public function show_field_begin($field, $meta) |
|
673 | - { |
|
674 | - if (isset($field['group'])) { |
|
675 | - if ($field['group'] == "start") { |
|
676 | - echo "<td class='at-field'>"; |
|
677 | - } |
|
678 | - } else { |
|
679 | - if ($this->_form_type == 'edit') { |
|
680 | - echo '<th valign="top" scope="row">'; |
|
681 | - } else { |
|
682 | - if ($field['validate_func']) { |
|
683 | - echo '<td><div class="form-field form-required">'; |
|
684 | - } else { |
|
685 | - echo '<td><div class="form-field">'; |
|
686 | - } |
|
687 | - } |
|
688 | - } |
|
689 | - if ($field['name'] != '' || $field['name'] != FALSE) { |
|
690 | - //echo "<div class='at-label'>"; |
|
691 | - echo "<label for='{$field['id']}'>{$field['name']}</label>"; |
|
692 | - //echo "</div>"; |
|
693 | - } |
|
694 | - if ($this->_form_type == 'edit') { |
|
695 | - echo '</th><td>'; |
|
696 | - } |
|
697 | - } |
|
698 | - |
|
699 | - /** |
|
700 | - * End Field. |
|
701 | - * |
|
702 | - * @param string $field |
|
703 | - * @param string $meta |
|
704 | - * @since 1.0 |
|
705 | - * @access public |
|
706 | - */ |
|
707 | - public function show_field_end($field, $meta = NULL, $group = false) |
|
708 | - { |
|
709 | - if (isset($field['group'])) { |
|
710 | - if ($group == 'end') { |
|
711 | - if ($field['desc'] != '') { |
|
712 | - echo "<p class='desc-field'>{$field['desc']}</p></td>"; |
|
713 | - } else { |
|
714 | - echo "</td>"; |
|
715 | - } |
|
716 | - } else { |
|
717 | - if ($field['desc'] != '') { |
|
718 | - echo "<p class='desc-field'>{$field['desc']}</p><br/>"; |
|
719 | - } else { |
|
720 | - echo '<br/>'; |
|
721 | - } |
|
722 | - } |
|
723 | - } else { |
|
724 | - if ($field['desc'] != '') { |
|
725 | - echo "<p class='desc-field'>{$field['desc']}</p>"; |
|
726 | - } |
|
727 | - if ($this->_form_type == 'edit') { |
|
728 | - echo '</td>'; |
|
729 | - } else { |
|
730 | - echo '</td></div>'; |
|
731 | - } |
|
732 | - } |
|
733 | - } |
|
734 | - |
|
735 | - /** |
|
736 | - * Show Field Text. |
|
737 | - * |
|
738 | - * @param string $field |
|
739 | - * @param string $meta |
|
740 | - * @since 1.0 |
|
741 | - * @access public |
|
742 | - */ |
|
743 | - public function show_field_text($field, $meta) |
|
744 | - { |
|
745 | - $this->show_field_begin($field, $meta); |
|
746 | - echo "<input type='text' class='at-text' name='{$field['id']}' id='{$field['id']}' value='{$meta}' size='30' />"; |
|
747 | - $this->show_field_end($field, $meta); |
|
748 | - } |
|
749 | - |
|
750 | - /** |
|
751 | - * Show Field hidden. |
|
752 | - * |
|
753 | - * @param string $field |
|
754 | - * @param string|mixed $meta |
|
755 | - * @since 0.1.3 |
|
756 | - * @access public |
|
757 | - */ |
|
758 | - public function show_field_hidden($field, $meta) |
|
759 | - { |
|
760 | - //$this->show_field_begin( $field, $meta ); |
|
761 | - echo "<input type='hidden' class='at-text' name='{$field['id']}' id='{$field['id']}' value='{$meta}'/>"; |
|
762 | - //$this->show_field_end( $field, $meta ); |
|
763 | - } |
|
764 | - |
|
765 | - /** |
|
766 | - * Show Field Paragraph. |
|
767 | - * |
|
768 | - * @param string $field |
|
769 | - * @since 0.1.3 |
|
770 | - * @access public |
|
771 | - */ |
|
772 | - public function show_field_paragraph($field) |
|
773 | - { |
|
774 | - //$this->show_field_begin( $field, $meta ); |
|
775 | - echo '<p>' . $field['value'] . '</p>'; |
|
776 | - //$this->show_field_end( $field, $meta ); |
|
777 | - } |
|
778 | - |
|
779 | - /** |
|
780 | - * Show Field Textarea. |
|
781 | - * |
|
782 | - * @param string $field |
|
783 | - * @param string $meta |
|
784 | - * @since 1.0 |
|
785 | - * @access public |
|
786 | - */ |
|
787 | - public function show_field_textarea($field, $meta) |
|
788 | - { |
|
789 | - $this->show_field_begin($field, $meta); |
|
790 | - echo "<textarea class='at-textarea large-text' name='{$field['id']}' id='{$field['id']}' cols='60' rows='10'>{$meta}</textarea>"; |
|
791 | - $this->show_field_end($field, $meta); |
|
792 | - } |
|
793 | - |
|
794 | - /** |
|
795 | - * Show Field Select. |
|
796 | - * |
|
797 | - * @param string $field |
|
798 | - * @param string $meta |
|
799 | - * @since 1.0 |
|
800 | - * @access public |
|
801 | - */ |
|
802 | - public function show_field_select($field, $meta) |
|
803 | - { |
|
804 | - |
|
805 | - if (!is_array($meta)) |
|
806 | - $meta = (array)$meta; |
|
807 | - |
|
808 | - $this->show_field_begin($field, $meta); |
|
809 | - echo "<select class='at-select' name='{$field['id']}" . ($field['multiple'] ? "[]' id='{$field['id']}' multiple='multiple'" : "'") . ">"; |
|
810 | - foreach ($field['options'] as $key => $value) { |
|
811 | - echo "<option value='{$key}'" . selected(in_array($key, $meta), true, false) . ">{$value}</option>"; |
|
812 | - } |
|
813 | - echo "</select>"; |
|
814 | - $this->show_field_end($field, $meta); |
|
815 | - |
|
816 | - } |
|
817 | - |
|
818 | - /** |
|
819 | - * Show Radio Field. |
|
820 | - * |
|
821 | - * @param string $field |
|
822 | - * @param string $meta |
|
823 | - * @since 1.0 |
|
824 | - * @access public |
|
825 | - */ |
|
826 | - public function show_field_radio($field, $meta) |
|
827 | - { |
|
828 | - |
|
829 | - if (!is_array($meta)) |
|
830 | - $meta = (array)$meta; |
|
831 | - |
|
832 | - $this->show_field_begin($field, $meta); |
|
833 | - foreach ($field['options'] as $key => $value) { |
|
834 | - echo "<input type='radio' class='at-radio' name='{$field['id']}' value='{$key}'" . checked(in_array($key, $meta), true, false) . " /> <span class='at-radio-label'>{$value}</span>"; |
|
835 | - } |
|
836 | - $this->show_field_end($field, $meta); |
|
837 | - } |
|
838 | - |
|
839 | - /** |
|
840 | - * Show Checkbox Field. |
|
841 | - * |
|
842 | - * @param string $field |
|
843 | - * @param string $meta |
|
844 | - * @since 1.0 |
|
845 | - * @access public |
|
846 | - */ |
|
847 | - public function show_field_checkbox($field, $meta) |
|
848 | - { |
|
849 | - |
|
850 | - $this->show_field_begin($field, $meta); |
|
851 | - echo "<input type='checkbox' class='rw-checkbox' name='{$field['id']}' id='{$field['id']}'" . checked(!empty($meta), true, false) . " /> {$field['desc']}"; |
|
852 | - $this->show_field_end($field, $meta); |
|
853 | - } |
|
854 | - |
|
855 | - /** |
|
856 | - * Show Wysiwig Field. |
|
857 | - * |
|
858 | - * @param string $field |
|
859 | - * @param string $meta |
|
860 | - * @since 1.0 |
|
861 | - * @access public |
|
862 | - */ |
|
863 | - public function show_field_wysiwyg($field, $meta) |
|
864 | - { |
|
865 | - $this->show_field_begin($field, $meta); |
|
866 | - // Add TinyMCE script for WP version < 3.3 |
|
867 | - global $wp_version; |
|
868 | - |
|
869 | - if (version_compare($wp_version, '3.2.1') < 1) { |
|
870 | - echo "<textarea class='at-wysiwyg theEditor large-text' name='{$field['id']}' id='{$field['id']}' cols='60' rows='10'>{$meta}</textarea>"; |
|
871 | - } else { |
|
872 | - // Use new wp_editor() since WP 3.3 |
|
873 | - wp_editor(stripslashes(html_entity_decode($meta)), $field['id'], array('editor_class' => 'at-wysiwyg')); |
|
874 | - } |
|
875 | - $this->show_field_end($field, $meta); |
|
876 | - } |
|
877 | - |
|
878 | - /** |
|
879 | - * Show File Field. |
|
880 | - * |
|
881 | - * @global object $post The current post object. |
|
882 | - * @param string $field |
|
883 | - * @param string $meta |
|
884 | - * @since 1.0 |
|
885 | - * @access public |
|
886 | - */ |
|
887 | - public function show_field_file($field, $meta) |
|
888 | - { |
|
889 | - |
|
890 | - global $post; |
|
891 | - |
|
892 | - if (!is_array($meta)) |
|
893 | - $meta = (array)$meta; |
|
894 | - |
|
895 | - $this->show_field_begin($field, $meta); |
|
896 | - echo "{$field['desc']}<br />"; |
|
897 | - |
|
898 | - if (!empty($meta)) { |
|
899 | - $nonce = wp_create_nonce('at_ajax_delete'); |
|
900 | - echo '<div style="margin-bottom: 10px"><strong>' . __('Uploaded files', 'geodirectory') . '</strong></div>'; |
|
901 | - echo '<ol class="at-upload">'; |
|
902 | - foreach ($meta as $att) { |
|
903 | - // if (wp_attachment_is_image($att)) continue; // what's image uploader for? |
|
904 | - echo "<li>" . wp_get_attachment_link($att, '', false, false, ' ') . " (<a class='at-delete-file' href='#' rel='{$nonce}|{$post->ID}|{$field['id']}|{$att}'>" . __('Remove', 'geodirectory') . "</a>)</li>"; |
|
905 | - } |
|
906 | - echo '</ol>'; |
|
907 | - } |
|
908 | - |
|
909 | - // show form upload |
|
910 | - |
|
911 | - echo "<div class='at-file-upload-label'>"; |
|
912 | - echo "<strong>" . __('Upload new files', 'geodirectory') . "</strong>"; |
|
913 | - echo "</div>"; |
|
914 | - echo "<div class='new-files'>"; |
|
915 | - echo "<div class='file-input'>"; |
|
916 | - echo "<input type='file' name='{$field['id']}[]' />"; |
|
917 | - echo "</div><!-- End .file-input -->"; |
|
918 | - echo "<a class='at-add-file button' href='#'>" . __('Add more files', 'geodirectory') . "</a>"; |
|
919 | - echo "</div><!-- End .new-files -->"; |
|
920 | - echo "</td>"; |
|
921 | - $this->show_field_end($field, $meta); |
|
922 | - } |
|
923 | - |
|
924 | - /** |
|
925 | - * Show Image Field. |
|
926 | - * |
|
927 | - * @param array $field |
|
928 | - * @param array $meta |
|
929 | - * @since 1.0 |
|
930 | - * @access public |
|
931 | - */ |
|
932 | - public function show_field_image($field, $meta) |
|
933 | - { |
|
934 | - $this->show_field_begin($field, $meta); |
|
935 | - $html = wp_nonce_field("at-delete-mupload_{$field['id']}", "nonce-delete-mupload_" . $field['id'], false, false); |
|
936 | - if (is_array($meta)) { |
|
937 | - if (isset($meta[0]) && is_array($meta[0])) |
|
938 | - $meta = $meta[0]; |
|
939 | - } |
|
940 | - |
|
941 | - $uploads = wp_upload_dir(); |
|
942 | - if (is_array($meta) && isset($meta['src']) && $meta['src'] != '') { |
|
943 | - $file_info = pathinfo($meta['src']); |
|
944 | - |
|
945 | - if ($file_info['dirname'] != '.' && $file_info['dirname'] != '..') |
|
946 | - $sub_dir = $file_info['dirname']; |
|
947 | - |
|
948 | - $uploads = wp_upload_dir(trim($sub_dir, '/')); // Array of key => value pairs |
|
949 | - $uploads_baseurl = $uploads['baseurl']; |
|
950 | - $uploads_path = $uploads['path']; |
|
951 | - |
|
952 | - $file_name = $file_info['basename']; |
|
953 | - |
|
954 | - if (strpos($sub_dir, 'https://') !== false) { |
|
955 | - $uploads['baseurl'] = str_replace('http://', 'https://', $uploads['baseurl']); |
|
956 | - } else { |
|
957 | - $uploads['baseurl'] = str_replace('https://', 'http://', $uploads['baseurl']); |
|
958 | - } |
|
959 | - $sub_dir = str_replace($uploads['baseurl'], '', $sub_dir); |
|
960 | - |
|
961 | - $uploads_url = $uploads_baseurl . $sub_dir; |
|
962 | - |
|
963 | - $meta['src'] = $uploads_url . '/' . $file_name; |
|
964 | - |
|
965 | - $html .= "<span class='mupload_img_holder'><img src='" . $meta['src'] . "' style='max-height: 150px;max-width: 150px;' /></span>"; |
|
966 | - $html .= "<input type='hidden' name='" . $field['id'] . "[id]' id='" . $field['id'] . "[id]' value='" . $meta['id'] . "' />"; |
|
967 | - $html .= "<input type='hidden' class='" . $field['id'] . "[src]' name='" . $field['id'] . "[src]' id='" . $field['id'] . "[src]' value='" . $meta['src'] . "' />"; |
|
968 | - $html .= "<input class='at-delete_image_button' type='button' rel='" . $field['id'] . "' value='" . __('Remove Image', 'geodirectory') . "' />"; |
|
969 | - } else { |
|
970 | - $html .= "<span class='mupload_img_holder'></span>"; |
|
971 | - $html .= "<input type='hidden' name='" . $field['id'] . "[id]' id='" . $field['id'] . "[id]' value='' />"; |
|
972 | - $html .= "<input class='" . $field['id'] . "[src]' style='position:absolute;left:-500px;width:50px;' type='text' name='" . $field['id'] . "[src]' id='" . $field['id'] . "[src]' value='' />"; |
|
973 | - $html .= "<input class='at-upload_image_button' type='button' rel='" . $field['id'] . "' value='" . __('Upload Image', 'geodirectory') . "' />"; |
|
974 | - } |
|
975 | - echo $html; |
|
976 | - $this->show_field_end($field, $meta); |
|
977 | - } |
|
978 | - |
|
979 | - /** |
|
980 | - * Show Color Field. |
|
981 | - * |
|
982 | - * @param string $field |
|
983 | - * @param string $meta |
|
984 | - * @since 1.0 |
|
985 | - * @access public |
|
986 | - */ |
|
987 | - public function show_field_color($field, $meta) |
|
988 | - { |
|
989 | - |
|
990 | - if (empty($meta)) |
|
991 | - $meta = '#'; |
|
992 | - |
|
993 | - $this->show_field_begin($field, $meta); |
|
994 | - |
|
995 | - echo "<input class='at-color' type='text' name='{$field['id']}' id='{$field['id']}' value='{$meta}' size='8' />"; |
|
996 | - // echo "<a href='#' class='at-color-select button' rel='{$field['id']}'>" . __( 'Select a color' ) . "</a>"; |
|
997 | - echo "<input type='button' class='at-color-select button' rel='{$field['id']}' value='" . __('Select a color', 'geodirectory') . "'/>"; |
|
998 | - echo "<div style='display:none' class='at-color-picker' rel='{$field['id']}'></div>"; |
|
999 | - $this->show_field_end($field, $meta); |
|
1000 | - |
|
1001 | - } |
|
1002 | - |
|
1003 | - /** |
|
1004 | - * Show Checkbox List Field |
|
1005 | - * |
|
1006 | - * @param string $field |
|
1007 | - * @param string $meta |
|
1008 | - * @since 1.0 |
|
1009 | - * @access public |
|
1010 | - */ |
|
1011 | - public function show_field_checkbox_list($field, $meta) |
|
1012 | - { |
|
1013 | - |
|
1014 | - if (!is_array($meta)) |
|
1015 | - $meta = (array)$meta; |
|
1016 | - |
|
1017 | - $this->show_field_begin($field, $meta); |
|
1018 | - |
|
1019 | - $html = array(); |
|
1020 | - |
|
1021 | - foreach ($field['options'] as $key => $value) { |
|
1022 | - $html[] = "<input type='checkbox' class='at-checkbox_list' name='{$field['id']}[]' value='{$key}'" . checked(in_array($key, $meta), true, false) . " /> {$value}"; |
|
1023 | - } |
|
1024 | - |
|
1025 | - echo implode('<br />', $html); |
|
1026 | - |
|
1027 | - $this->show_field_end($field, $meta); |
|
1028 | - |
|
1029 | - } |
|
1030 | - |
|
1031 | - /** |
|
1032 | - * Show Date Field. |
|
1033 | - * |
|
1034 | - * @param string $field |
|
1035 | - * @param string $meta |
|
1036 | - * @since 1.0 |
|
1037 | - * @access public |
|
1038 | - */ |
|
1039 | - public function show_field_date($field, $meta) |
|
1040 | - { |
|
1041 | - $this->show_field_begin($field, $meta); |
|
1042 | - echo "<input type='text' class='at-date' name='{$field['id']}' id='{$field['id']}' rel='{$field['format']}' value='{$meta}' size='30' />"; |
|
1043 | - $this->show_field_end($field, $meta); |
|
1044 | - } |
|
1045 | - |
|
1046 | - /** |
|
1047 | - * Show time field. |
|
1048 | - * |
|
1049 | - * @param string $field |
|
1050 | - * @param string $meta |
|
1051 | - * @since 1.0 |
|
1052 | - * @access public |
|
1053 | - */ |
|
1054 | - public function show_field_time($field, $meta) |
|
1055 | - { |
|
1056 | - $this->show_field_begin($field, $meta); |
|
1057 | - echo "<input type='text' class='at-time' name='{$field['id']}' id='{$field['id']}' rel='{$field['format']}' value='{$meta}' size='30' />"; |
|
1058 | - $this->show_field_end($field, $meta); |
|
1059 | - } |
|
1060 | - |
|
1061 | - /** |
|
1062 | - * Show Posts field. |
|
1063 | - * used creating a posts/pages/custom types checkboxlist or a select dropdown |
|
1064 | - * |
|
1065 | - * @global object $post The current post object. |
|
1066 | - * @param string $field |
|
1067 | - * @param string $meta |
|
1068 | - * @since 1.0 |
|
1069 | - * @access public |
|
1070 | - */ |
|
1071 | - public function show_field_posts($field, $meta) |
|
1072 | - { |
|
1073 | - global $post; |
|
1074 | - |
|
1075 | - if (!is_array($meta)) $meta = (array)$meta; |
|
1076 | - $this->show_field_begin($field, $meta); |
|
1077 | - $options = $field['options']; |
|
1078 | - $posts = get_posts($options['args']); |
|
1079 | - |
|
1080 | - // checkbox_list |
|
1081 | - if ('checkbox_list' == $options['type']) { |
|
1082 | - foreach ($posts as $p) { |
|
1083 | - echo "<input type='checkbox' name='{$field['id']}[]' value='$p->ID'" . checked(in_array($p->ID, $meta), true, false) . " /> $p->post_title<br/>"; |
|
1084 | - } |
|
1085 | - } // select |
|
1086 | - else { |
|
1087 | - echo "<select name='{$field['id']}" . ($field['multiple'] ? "[]' multiple='multiple' style='height:auto'" : "'") . ">"; |
|
1088 | - foreach ($posts as $p) { |
|
1089 | - echo "<option value='$p->ID'" . selected(in_array($p->ID, $meta), true, false) . ">$p->post_title</option>"; |
|
1090 | - } |
|
1091 | - echo "</select>"; |
|
1092 | - } |
|
1093 | - |
|
1094 | - $this->show_field_end($field, $meta); |
|
1095 | - } |
|
1096 | - |
|
1097 | - /** |
|
1098 | - * Show Taxonomy field. |
|
1099 | - * used creating a category/tags/custom taxonomy checkboxlist or a select dropdown |
|
1100 | - * |
|
1101 | - * @global object $post The current post object. |
|
1102 | - * @param string $field |
|
1103 | - * @param string $meta |
|
1104 | - * @since 1.0 |
|
1105 | - * @access public |
|
1106 | - * |
|
1107 | - * @uses get_terms() |
|
1108 | - */ |
|
1109 | - public function show_field_taxonomy($field, $meta) |
|
1110 | - { |
|
1111 | - global $post; |
|
1112 | - |
|
1113 | - if (!is_array($meta)) $meta = (array)$meta; |
|
1114 | - $this->show_field_begin($field, $meta); |
|
1115 | - $options = $field['options']; |
|
1116 | - $terms = get_terms($options['taxonomy'], $options['args']); |
|
1117 | - |
|
1118 | - // checkbox_list |
|
1119 | - if ('checkbox_list' == $options['type']) { |
|
1120 | - foreach ($terms as $term) { |
|
1121 | - echo "<input type='checkbox' name='{$field['id']}[]' value='$term->slug'" . checked(in_array($term->slug, $meta), true, false) . " /> $term->name<br/>"; |
|
1122 | - } |
|
1123 | - } // select |
|
1124 | - else { |
|
1125 | - echo "<select name='{$field['id']}" . ($field['multiple'] ? "[]' multiple='multiple' style='height:auto'" : "'") . ">"; |
|
1126 | - foreach ($terms as $term) { |
|
1127 | - echo "<option value='$term->slug'" . selected(in_array($term->slug, $meta), true, false) . ">$term->name</option>"; |
|
1128 | - } |
|
1129 | - echo "</select>"; |
|
1130 | - } |
|
1131 | - |
|
1132 | - $this->show_field_end($field, $meta); |
|
1133 | - } |
|
1134 | - |
|
1135 | - /** |
|
1136 | - * Save Data from Metabox |
|
1137 | - * |
|
1138 | - * @param string $term_id The term ID. |
|
1139 | - * @since 1.0 |
|
1140 | - * @access public |
|
1141 | - * @return string |
|
1142 | - */ |
|
1143 | - public function save($term_id) |
|
1144 | - { |
|
1145 | - |
|
1146 | - $taxnow = ''; |
|
1147 | - if (isset($_POST['taxonomy'])) |
|
1148 | - $taxnow = $_POST['taxonomy']; |
|
1149 | - |
|
1150 | - if (!isset($term_id) // Check Revision |
|
1151 | - || (!in_array($taxnow, $this->_meta_box['pages'])) // Check if current taxonomy type is supported. |
|
1152 | - || (!check_admin_referer(basename(__FILE__), 'tax_meta_class_nonce')) // Check nonce - Security |
|
1153 | - || (!current_user_can('manage_categories')) |
|
1154 | - ) // Check permission |
|
1155 | - { |
|
1156 | - return $term_id; |
|
1157 | - } |
|
1158 | - |
|
1159 | - |
|
1160 | - foreach ($this->_fields as $field) { |
|
1161 | - |
|
1162 | - $name = $field['id']; |
|
1163 | - $type = $field['type']; |
|
1164 | - $old = $this->get_tax_meta($term_id, $name, !$field['multiple']); |
|
1165 | - $new = (isset($_POST[$name])) ? $_POST[$name] : (($field['multiple']) ? array() : ''); |
|
1166 | - |
|
1167 | - // Validate meta value |
|
1168 | - if (class_exists('Tax_Meta_Validate') && method_exists('Tax_Meta_Validate', $field['validate_func'])) { |
|
1169 | - $new = call_user_func(array('Tax_Meta_Validate', $field['validate_func']), $new); |
|
1170 | - } |
|
1171 | - |
|
1172 | - |
|
1173 | - if ($name == 'ct_cat_icon') { |
|
1174 | - |
|
1175 | - $upload_dir = wp_upload_dir(); |
|
1176 | - |
|
1177 | - $image_name_arr = explode('/', $new['src']); |
|
1178 | - //$old_filename = end($image_name_arr); |
|
1179 | - //$img_name_arr = explode('.',$old_filename); |
|
1180 | - |
|
1181 | - //$old_filename = $upload_dir['path'].'/'.$old_filename; |
|
1182 | - |
|
1183 | - $new_filename = $upload_dir['path'] . '/' . 'cat_icon_' . $term_id . '.png'; |
|
1184 | - |
|
1185 | - /*rename($old_filename, $new_filename); |
|
661 | + $this->show_field_end($field, $meta); |
|
662 | + } |
|
663 | + |
|
664 | + /** |
|
665 | + * Begin Field. |
|
666 | + * |
|
667 | + * @param string $field |
|
668 | + * @param string $meta |
|
669 | + * @since 1.0 |
|
670 | + * @access public |
|
671 | + */ |
|
672 | + public function show_field_begin($field, $meta) |
|
673 | + { |
|
674 | + if (isset($field['group'])) { |
|
675 | + if ($field['group'] == "start") { |
|
676 | + echo "<td class='at-field'>"; |
|
677 | + } |
|
678 | + } else { |
|
679 | + if ($this->_form_type == 'edit') { |
|
680 | + echo '<th valign="top" scope="row">'; |
|
681 | + } else { |
|
682 | + if ($field['validate_func']) { |
|
683 | + echo '<td><div class="form-field form-required">'; |
|
684 | + } else { |
|
685 | + echo '<td><div class="form-field">'; |
|
686 | + } |
|
687 | + } |
|
688 | + } |
|
689 | + if ($field['name'] != '' || $field['name'] != FALSE) { |
|
690 | + //echo "<div class='at-label'>"; |
|
691 | + echo "<label for='{$field['id']}'>{$field['name']}</label>"; |
|
692 | + //echo "</div>"; |
|
693 | + } |
|
694 | + if ($this->_form_type == 'edit') { |
|
695 | + echo '</th><td>'; |
|
696 | + } |
|
697 | + } |
|
698 | + |
|
699 | + /** |
|
700 | + * End Field. |
|
701 | + * |
|
702 | + * @param string $field |
|
703 | + * @param string $meta |
|
704 | + * @since 1.0 |
|
705 | + * @access public |
|
706 | + */ |
|
707 | + public function show_field_end($field, $meta = NULL, $group = false) |
|
708 | + { |
|
709 | + if (isset($field['group'])) { |
|
710 | + if ($group == 'end') { |
|
711 | + if ($field['desc'] != '') { |
|
712 | + echo "<p class='desc-field'>{$field['desc']}</p></td>"; |
|
713 | + } else { |
|
714 | + echo "</td>"; |
|
715 | + } |
|
716 | + } else { |
|
717 | + if ($field['desc'] != '') { |
|
718 | + echo "<p class='desc-field'>{$field['desc']}</p><br/>"; |
|
719 | + } else { |
|
720 | + echo '<br/>'; |
|
721 | + } |
|
722 | + } |
|
723 | + } else { |
|
724 | + if ($field['desc'] != '') { |
|
725 | + echo "<p class='desc-field'>{$field['desc']}</p>"; |
|
726 | + } |
|
727 | + if ($this->_form_type == 'edit') { |
|
728 | + echo '</td>'; |
|
729 | + } else { |
|
730 | + echo '</td></div>'; |
|
731 | + } |
|
732 | + } |
|
733 | + } |
|
734 | + |
|
735 | + /** |
|
736 | + * Show Field Text. |
|
737 | + * |
|
738 | + * @param string $field |
|
739 | + * @param string $meta |
|
740 | + * @since 1.0 |
|
741 | + * @access public |
|
742 | + */ |
|
743 | + public function show_field_text($field, $meta) |
|
744 | + { |
|
745 | + $this->show_field_begin($field, $meta); |
|
746 | + echo "<input type='text' class='at-text' name='{$field['id']}' id='{$field['id']}' value='{$meta}' size='30' />"; |
|
747 | + $this->show_field_end($field, $meta); |
|
748 | + } |
|
749 | + |
|
750 | + /** |
|
751 | + * Show Field hidden. |
|
752 | + * |
|
753 | + * @param string $field |
|
754 | + * @param string|mixed $meta |
|
755 | + * @since 0.1.3 |
|
756 | + * @access public |
|
757 | + */ |
|
758 | + public function show_field_hidden($field, $meta) |
|
759 | + { |
|
760 | + //$this->show_field_begin( $field, $meta ); |
|
761 | + echo "<input type='hidden' class='at-text' name='{$field['id']}' id='{$field['id']}' value='{$meta}'/>"; |
|
762 | + //$this->show_field_end( $field, $meta ); |
|
763 | + } |
|
764 | + |
|
765 | + /** |
|
766 | + * Show Field Paragraph. |
|
767 | + * |
|
768 | + * @param string $field |
|
769 | + * @since 0.1.3 |
|
770 | + * @access public |
|
771 | + */ |
|
772 | + public function show_field_paragraph($field) |
|
773 | + { |
|
774 | + //$this->show_field_begin( $field, $meta ); |
|
775 | + echo '<p>' . $field['value'] . '</p>'; |
|
776 | + //$this->show_field_end( $field, $meta ); |
|
777 | + } |
|
778 | + |
|
779 | + /** |
|
780 | + * Show Field Textarea. |
|
781 | + * |
|
782 | + * @param string $field |
|
783 | + * @param string $meta |
|
784 | + * @since 1.0 |
|
785 | + * @access public |
|
786 | + */ |
|
787 | + public function show_field_textarea($field, $meta) |
|
788 | + { |
|
789 | + $this->show_field_begin($field, $meta); |
|
790 | + echo "<textarea class='at-textarea large-text' name='{$field['id']}' id='{$field['id']}' cols='60' rows='10'>{$meta}</textarea>"; |
|
791 | + $this->show_field_end($field, $meta); |
|
792 | + } |
|
793 | + |
|
794 | + /** |
|
795 | + * Show Field Select. |
|
796 | + * |
|
797 | + * @param string $field |
|
798 | + * @param string $meta |
|
799 | + * @since 1.0 |
|
800 | + * @access public |
|
801 | + */ |
|
802 | + public function show_field_select($field, $meta) |
|
803 | + { |
|
804 | + |
|
805 | + if (!is_array($meta)) |
|
806 | + $meta = (array)$meta; |
|
807 | + |
|
808 | + $this->show_field_begin($field, $meta); |
|
809 | + echo "<select class='at-select' name='{$field['id']}" . ($field['multiple'] ? "[]' id='{$field['id']}' multiple='multiple'" : "'") . ">"; |
|
810 | + foreach ($field['options'] as $key => $value) { |
|
811 | + echo "<option value='{$key}'" . selected(in_array($key, $meta), true, false) . ">{$value}</option>"; |
|
812 | + } |
|
813 | + echo "</select>"; |
|
814 | + $this->show_field_end($field, $meta); |
|
815 | + |
|
816 | + } |
|
817 | + |
|
818 | + /** |
|
819 | + * Show Radio Field. |
|
820 | + * |
|
821 | + * @param string $field |
|
822 | + * @param string $meta |
|
823 | + * @since 1.0 |
|
824 | + * @access public |
|
825 | + */ |
|
826 | + public function show_field_radio($field, $meta) |
|
827 | + { |
|
828 | + |
|
829 | + if (!is_array($meta)) |
|
830 | + $meta = (array)$meta; |
|
831 | + |
|
832 | + $this->show_field_begin($field, $meta); |
|
833 | + foreach ($field['options'] as $key => $value) { |
|
834 | + echo "<input type='radio' class='at-radio' name='{$field['id']}' value='{$key}'" . checked(in_array($key, $meta), true, false) . " /> <span class='at-radio-label'>{$value}</span>"; |
|
835 | + } |
|
836 | + $this->show_field_end($field, $meta); |
|
837 | + } |
|
838 | + |
|
839 | + /** |
|
840 | + * Show Checkbox Field. |
|
841 | + * |
|
842 | + * @param string $field |
|
843 | + * @param string $meta |
|
844 | + * @since 1.0 |
|
845 | + * @access public |
|
846 | + */ |
|
847 | + public function show_field_checkbox($field, $meta) |
|
848 | + { |
|
849 | + |
|
850 | + $this->show_field_begin($field, $meta); |
|
851 | + echo "<input type='checkbox' class='rw-checkbox' name='{$field['id']}' id='{$field['id']}'" . checked(!empty($meta), true, false) . " /> {$field['desc']}"; |
|
852 | + $this->show_field_end($field, $meta); |
|
853 | + } |
|
854 | + |
|
855 | + /** |
|
856 | + * Show Wysiwig Field. |
|
857 | + * |
|
858 | + * @param string $field |
|
859 | + * @param string $meta |
|
860 | + * @since 1.0 |
|
861 | + * @access public |
|
862 | + */ |
|
863 | + public function show_field_wysiwyg($field, $meta) |
|
864 | + { |
|
865 | + $this->show_field_begin($field, $meta); |
|
866 | + // Add TinyMCE script for WP version < 3.3 |
|
867 | + global $wp_version; |
|
868 | + |
|
869 | + if (version_compare($wp_version, '3.2.1') < 1) { |
|
870 | + echo "<textarea class='at-wysiwyg theEditor large-text' name='{$field['id']}' id='{$field['id']}' cols='60' rows='10'>{$meta}</textarea>"; |
|
871 | + } else { |
|
872 | + // Use new wp_editor() since WP 3.3 |
|
873 | + wp_editor(stripslashes(html_entity_decode($meta)), $field['id'], array('editor_class' => 'at-wysiwyg')); |
|
874 | + } |
|
875 | + $this->show_field_end($field, $meta); |
|
876 | + } |
|
877 | + |
|
878 | + /** |
|
879 | + * Show File Field. |
|
880 | + * |
|
881 | + * @global object $post The current post object. |
|
882 | + * @param string $field |
|
883 | + * @param string $meta |
|
884 | + * @since 1.0 |
|
885 | + * @access public |
|
886 | + */ |
|
887 | + public function show_field_file($field, $meta) |
|
888 | + { |
|
889 | + |
|
890 | + global $post; |
|
891 | + |
|
892 | + if (!is_array($meta)) |
|
893 | + $meta = (array)$meta; |
|
894 | + |
|
895 | + $this->show_field_begin($field, $meta); |
|
896 | + echo "{$field['desc']}<br />"; |
|
897 | + |
|
898 | + if (!empty($meta)) { |
|
899 | + $nonce = wp_create_nonce('at_ajax_delete'); |
|
900 | + echo '<div style="margin-bottom: 10px"><strong>' . __('Uploaded files', 'geodirectory') . '</strong></div>'; |
|
901 | + echo '<ol class="at-upload">'; |
|
902 | + foreach ($meta as $att) { |
|
903 | + // if (wp_attachment_is_image($att)) continue; // what's image uploader for? |
|
904 | + echo "<li>" . wp_get_attachment_link($att, '', false, false, ' ') . " (<a class='at-delete-file' href='#' rel='{$nonce}|{$post->ID}|{$field['id']}|{$att}'>" . __('Remove', 'geodirectory') . "</a>)</li>"; |
|
905 | + } |
|
906 | + echo '</ol>'; |
|
907 | + } |
|
908 | + |
|
909 | + // show form upload |
|
910 | + |
|
911 | + echo "<div class='at-file-upload-label'>"; |
|
912 | + echo "<strong>" . __('Upload new files', 'geodirectory') . "</strong>"; |
|
913 | + echo "</div>"; |
|
914 | + echo "<div class='new-files'>"; |
|
915 | + echo "<div class='file-input'>"; |
|
916 | + echo "<input type='file' name='{$field['id']}[]' />"; |
|
917 | + echo "</div><!-- End .file-input -->"; |
|
918 | + echo "<a class='at-add-file button' href='#'>" . __('Add more files', 'geodirectory') . "</a>"; |
|
919 | + echo "</div><!-- End .new-files -->"; |
|
920 | + echo "</td>"; |
|
921 | + $this->show_field_end($field, $meta); |
|
922 | + } |
|
923 | + |
|
924 | + /** |
|
925 | + * Show Image Field. |
|
926 | + * |
|
927 | + * @param array $field |
|
928 | + * @param array $meta |
|
929 | + * @since 1.0 |
|
930 | + * @access public |
|
931 | + */ |
|
932 | + public function show_field_image($field, $meta) |
|
933 | + { |
|
934 | + $this->show_field_begin($field, $meta); |
|
935 | + $html = wp_nonce_field("at-delete-mupload_{$field['id']}", "nonce-delete-mupload_" . $field['id'], false, false); |
|
936 | + if (is_array($meta)) { |
|
937 | + if (isset($meta[0]) && is_array($meta[0])) |
|
938 | + $meta = $meta[0]; |
|
939 | + } |
|
940 | + |
|
941 | + $uploads = wp_upload_dir(); |
|
942 | + if (is_array($meta) && isset($meta['src']) && $meta['src'] != '') { |
|
943 | + $file_info = pathinfo($meta['src']); |
|
944 | + |
|
945 | + if ($file_info['dirname'] != '.' && $file_info['dirname'] != '..') |
|
946 | + $sub_dir = $file_info['dirname']; |
|
947 | + |
|
948 | + $uploads = wp_upload_dir(trim($sub_dir, '/')); // Array of key => value pairs |
|
949 | + $uploads_baseurl = $uploads['baseurl']; |
|
950 | + $uploads_path = $uploads['path']; |
|
951 | + |
|
952 | + $file_name = $file_info['basename']; |
|
953 | + |
|
954 | + if (strpos($sub_dir, 'https://') !== false) { |
|
955 | + $uploads['baseurl'] = str_replace('http://', 'https://', $uploads['baseurl']); |
|
956 | + } else { |
|
957 | + $uploads['baseurl'] = str_replace('https://', 'http://', $uploads['baseurl']); |
|
958 | + } |
|
959 | + $sub_dir = str_replace($uploads['baseurl'], '', $sub_dir); |
|
960 | + |
|
961 | + $uploads_url = $uploads_baseurl . $sub_dir; |
|
962 | + |
|
963 | + $meta['src'] = $uploads_url . '/' . $file_name; |
|
964 | + |
|
965 | + $html .= "<span class='mupload_img_holder'><img src='" . $meta['src'] . "' style='max-height: 150px;max-width: 150px;' /></span>"; |
|
966 | + $html .= "<input type='hidden' name='" . $field['id'] . "[id]' id='" . $field['id'] . "[id]' value='" . $meta['id'] . "' />"; |
|
967 | + $html .= "<input type='hidden' class='" . $field['id'] . "[src]' name='" . $field['id'] . "[src]' id='" . $field['id'] . "[src]' value='" . $meta['src'] . "' />"; |
|
968 | + $html .= "<input class='at-delete_image_button' type='button' rel='" . $field['id'] . "' value='" . __('Remove Image', 'geodirectory') . "' />"; |
|
969 | + } else { |
|
970 | + $html .= "<span class='mupload_img_holder'></span>"; |
|
971 | + $html .= "<input type='hidden' name='" . $field['id'] . "[id]' id='" . $field['id'] . "[id]' value='' />"; |
|
972 | + $html .= "<input class='" . $field['id'] . "[src]' style='position:absolute;left:-500px;width:50px;' type='text' name='" . $field['id'] . "[src]' id='" . $field['id'] . "[src]' value='' />"; |
|
973 | + $html .= "<input class='at-upload_image_button' type='button' rel='" . $field['id'] . "' value='" . __('Upload Image', 'geodirectory') . "' />"; |
|
974 | + } |
|
975 | + echo $html; |
|
976 | + $this->show_field_end($field, $meta); |
|
977 | + } |
|
978 | + |
|
979 | + /** |
|
980 | + * Show Color Field. |
|
981 | + * |
|
982 | + * @param string $field |
|
983 | + * @param string $meta |
|
984 | + * @since 1.0 |
|
985 | + * @access public |
|
986 | + */ |
|
987 | + public function show_field_color($field, $meta) |
|
988 | + { |
|
989 | + |
|
990 | + if (empty($meta)) |
|
991 | + $meta = '#'; |
|
992 | + |
|
993 | + $this->show_field_begin($field, $meta); |
|
994 | + |
|
995 | + echo "<input class='at-color' type='text' name='{$field['id']}' id='{$field['id']}' value='{$meta}' size='8' />"; |
|
996 | + // echo "<a href='#' class='at-color-select button' rel='{$field['id']}'>" . __( 'Select a color' ) . "</a>"; |
|
997 | + echo "<input type='button' class='at-color-select button' rel='{$field['id']}' value='" . __('Select a color', 'geodirectory') . "'/>"; |
|
998 | + echo "<div style='display:none' class='at-color-picker' rel='{$field['id']}'></div>"; |
|
999 | + $this->show_field_end($field, $meta); |
|
1000 | + |
|
1001 | + } |
|
1002 | + |
|
1003 | + /** |
|
1004 | + * Show Checkbox List Field |
|
1005 | + * |
|
1006 | + * @param string $field |
|
1007 | + * @param string $meta |
|
1008 | + * @since 1.0 |
|
1009 | + * @access public |
|
1010 | + */ |
|
1011 | + public function show_field_checkbox_list($field, $meta) |
|
1012 | + { |
|
1013 | + |
|
1014 | + if (!is_array($meta)) |
|
1015 | + $meta = (array)$meta; |
|
1016 | + |
|
1017 | + $this->show_field_begin($field, $meta); |
|
1018 | + |
|
1019 | + $html = array(); |
|
1020 | + |
|
1021 | + foreach ($field['options'] as $key => $value) { |
|
1022 | + $html[] = "<input type='checkbox' class='at-checkbox_list' name='{$field['id']}[]' value='{$key}'" . checked(in_array($key, $meta), true, false) . " /> {$value}"; |
|
1023 | + } |
|
1024 | + |
|
1025 | + echo implode('<br />', $html); |
|
1026 | + |
|
1027 | + $this->show_field_end($field, $meta); |
|
1028 | + |
|
1029 | + } |
|
1030 | + |
|
1031 | + /** |
|
1032 | + * Show Date Field. |
|
1033 | + * |
|
1034 | + * @param string $field |
|
1035 | + * @param string $meta |
|
1036 | + * @since 1.0 |
|
1037 | + * @access public |
|
1038 | + */ |
|
1039 | + public function show_field_date($field, $meta) |
|
1040 | + { |
|
1041 | + $this->show_field_begin($field, $meta); |
|
1042 | + echo "<input type='text' class='at-date' name='{$field['id']}' id='{$field['id']}' rel='{$field['format']}' value='{$meta}' size='30' />"; |
|
1043 | + $this->show_field_end($field, $meta); |
|
1044 | + } |
|
1045 | + |
|
1046 | + /** |
|
1047 | + * Show time field. |
|
1048 | + * |
|
1049 | + * @param string $field |
|
1050 | + * @param string $meta |
|
1051 | + * @since 1.0 |
|
1052 | + * @access public |
|
1053 | + */ |
|
1054 | + public function show_field_time($field, $meta) |
|
1055 | + { |
|
1056 | + $this->show_field_begin($field, $meta); |
|
1057 | + echo "<input type='text' class='at-time' name='{$field['id']}' id='{$field['id']}' rel='{$field['format']}' value='{$meta}' size='30' />"; |
|
1058 | + $this->show_field_end($field, $meta); |
|
1059 | + } |
|
1060 | + |
|
1061 | + /** |
|
1062 | + * Show Posts field. |
|
1063 | + * used creating a posts/pages/custom types checkboxlist or a select dropdown |
|
1064 | + * |
|
1065 | + * @global object $post The current post object. |
|
1066 | + * @param string $field |
|
1067 | + * @param string $meta |
|
1068 | + * @since 1.0 |
|
1069 | + * @access public |
|
1070 | + */ |
|
1071 | + public function show_field_posts($field, $meta) |
|
1072 | + { |
|
1073 | + global $post; |
|
1074 | + |
|
1075 | + if (!is_array($meta)) $meta = (array)$meta; |
|
1076 | + $this->show_field_begin($field, $meta); |
|
1077 | + $options = $field['options']; |
|
1078 | + $posts = get_posts($options['args']); |
|
1079 | + |
|
1080 | + // checkbox_list |
|
1081 | + if ('checkbox_list' == $options['type']) { |
|
1082 | + foreach ($posts as $p) { |
|
1083 | + echo "<input type='checkbox' name='{$field['id']}[]' value='$p->ID'" . checked(in_array($p->ID, $meta), true, false) . " /> $p->post_title<br/>"; |
|
1084 | + } |
|
1085 | + } // select |
|
1086 | + else { |
|
1087 | + echo "<select name='{$field['id']}" . ($field['multiple'] ? "[]' multiple='multiple' style='height:auto'" : "'") . ">"; |
|
1088 | + foreach ($posts as $p) { |
|
1089 | + echo "<option value='$p->ID'" . selected(in_array($p->ID, $meta), true, false) . ">$p->post_title</option>"; |
|
1090 | + } |
|
1091 | + echo "</select>"; |
|
1092 | + } |
|
1093 | + |
|
1094 | + $this->show_field_end($field, $meta); |
|
1095 | + } |
|
1096 | + |
|
1097 | + /** |
|
1098 | + * Show Taxonomy field. |
|
1099 | + * used creating a category/tags/custom taxonomy checkboxlist or a select dropdown |
|
1100 | + * |
|
1101 | + * @global object $post The current post object. |
|
1102 | + * @param string $field |
|
1103 | + * @param string $meta |
|
1104 | + * @since 1.0 |
|
1105 | + * @access public |
|
1106 | + * |
|
1107 | + * @uses get_terms() |
|
1108 | + */ |
|
1109 | + public function show_field_taxonomy($field, $meta) |
|
1110 | + { |
|
1111 | + global $post; |
|
1112 | + |
|
1113 | + if (!is_array($meta)) $meta = (array)$meta; |
|
1114 | + $this->show_field_begin($field, $meta); |
|
1115 | + $options = $field['options']; |
|
1116 | + $terms = get_terms($options['taxonomy'], $options['args']); |
|
1117 | + |
|
1118 | + // checkbox_list |
|
1119 | + if ('checkbox_list' == $options['type']) { |
|
1120 | + foreach ($terms as $term) { |
|
1121 | + echo "<input type='checkbox' name='{$field['id']}[]' value='$term->slug'" . checked(in_array($term->slug, $meta), true, false) . " /> $term->name<br/>"; |
|
1122 | + } |
|
1123 | + } // select |
|
1124 | + else { |
|
1125 | + echo "<select name='{$field['id']}" . ($field['multiple'] ? "[]' multiple='multiple' style='height:auto'" : "'") . ">"; |
|
1126 | + foreach ($terms as $term) { |
|
1127 | + echo "<option value='$term->slug'" . selected(in_array($term->slug, $meta), true, false) . ">$term->name</option>"; |
|
1128 | + } |
|
1129 | + echo "</select>"; |
|
1130 | + } |
|
1131 | + |
|
1132 | + $this->show_field_end($field, $meta); |
|
1133 | + } |
|
1134 | + |
|
1135 | + /** |
|
1136 | + * Save Data from Metabox |
|
1137 | + * |
|
1138 | + * @param string $term_id The term ID. |
|
1139 | + * @since 1.0 |
|
1140 | + * @access public |
|
1141 | + * @return string |
|
1142 | + */ |
|
1143 | + public function save($term_id) |
|
1144 | + { |
|
1145 | + |
|
1146 | + $taxnow = ''; |
|
1147 | + if (isset($_POST['taxonomy'])) |
|
1148 | + $taxnow = $_POST['taxonomy']; |
|
1149 | + |
|
1150 | + if (!isset($term_id) // Check Revision |
|
1151 | + || (!in_array($taxnow, $this->_meta_box['pages'])) // Check if current taxonomy type is supported. |
|
1152 | + || (!check_admin_referer(basename(__FILE__), 'tax_meta_class_nonce')) // Check nonce - Security |
|
1153 | + || (!current_user_can('manage_categories')) |
|
1154 | + ) // Check permission |
|
1155 | + { |
|
1156 | + return $term_id; |
|
1157 | + } |
|
1158 | + |
|
1159 | + |
|
1160 | + foreach ($this->_fields as $field) { |
|
1161 | + |
|
1162 | + $name = $field['id']; |
|
1163 | + $type = $field['type']; |
|
1164 | + $old = $this->get_tax_meta($term_id, $name, !$field['multiple']); |
|
1165 | + $new = (isset($_POST[$name])) ? $_POST[$name] : (($field['multiple']) ? array() : ''); |
|
1166 | + |
|
1167 | + // Validate meta value |
|
1168 | + if (class_exists('Tax_Meta_Validate') && method_exists('Tax_Meta_Validate', $field['validate_func'])) { |
|
1169 | + $new = call_user_func(array('Tax_Meta_Validate', $field['validate_func']), $new); |
|
1170 | + } |
|
1171 | + |
|
1172 | + |
|
1173 | + if ($name == 'ct_cat_icon') { |
|
1174 | + |
|
1175 | + $upload_dir = wp_upload_dir(); |
|
1176 | + |
|
1177 | + $image_name_arr = explode('/', $new['src']); |
|
1178 | + //$old_filename = end($image_name_arr); |
|
1179 | + //$img_name_arr = explode('.',$old_filename); |
|
1180 | + |
|
1181 | + //$old_filename = $upload_dir['path'].'/'.$old_filename; |
|
1182 | + |
|
1183 | + $new_filename = $upload_dir['path'] . '/' . 'cat_icon_' . $term_id . '.png'; |
|
1184 | + |
|
1185 | + /*rename($old_filename, $new_filename); |
|
1186 | 1186 | |
1187 | 1187 | //subdir |
1188 | 1188 | $new['src'] = $upload_dir['url'].'/'.'cat_icon_'.$term_id.'.png'; |
@@ -1190,7 +1190,7 @@ discard block |
||
1190 | 1190 | update_attached_file( $new['id'], $new['src'] );*/ |
1191 | 1191 | |
1192 | 1192 | |
1193 | - /* |
|
1193 | + /* |
|
1194 | 1194 | |
1195 | 1195 | $new['src'] = $upload_dir['url'].'/'.'cat_icon_'.$term_id.'.png'; |
1196 | 1196 | |
@@ -1215,67 +1215,67 @@ discard block |
||
1215 | 1215 | $attach_id = wp_insert_attachment( $attachment, $filename);*/ |
1216 | 1216 | |
1217 | 1217 | |
1218 | - } |
|
1219 | - |
|
1220 | - |
|
1221 | - //skip on Paragraph field |
|
1222 | - if ($type != "paragraph") { |
|
1223 | - |
|
1224 | - // Call defined method to save meta value, if there's no methods, call common one. |
|
1225 | - $save_func = 'save_field_' . $type; |
|
1226 | - if (method_exists($this, $save_func)) { |
|
1227 | - call_user_func(array(&$this, 'save_field_' . $type), $term_id, $field, $old, $new); |
|
1228 | - } else { |
|
1229 | - $this->save_field($term_id, $field, $old, $new); |
|
1230 | - } |
|
1231 | - } |
|
1232 | - |
|
1233 | - } // End foreach |
|
1234 | - |
|
1235 | - } |
|
1236 | - |
|
1237 | - /** |
|
1238 | - * Common function for saving fields. |
|
1239 | - * |
|
1240 | - * @param string $term_id The term ID. |
|
1241 | - * @param string $field |
|
1242 | - * @param string $old |
|
1243 | - * @param string|mixed $new |
|
1244 | - * @since 1.0 |
|
1245 | - * @access public |
|
1246 | - */ |
|
1247 | - public function save_field($term_id, $field, $old, $new) |
|
1248 | - { |
|
1249 | - $name = $field['id']; |
|
1250 | - $this->delete_tax_meta($term_id, $name); |
|
1251 | - if ($new === '' || $new === array()) |
|
1252 | - return; |
|
1253 | - |
|
1254 | - $this->update_tax_meta($term_id, $name, $new); |
|
1255 | - } |
|
1256 | - |
|
1257 | - /** |
|
1258 | - * function for saving image field. |
|
1259 | - * |
|
1260 | - * @param string $term_id The term ID. |
|
1261 | - * @param string $field |
|
1262 | - * @param string $old |
|
1263 | - * @param string|mixed $new |
|
1264 | - * @since 1.0 |
|
1265 | - * @access public |
|
1266 | - */ |
|
1267 | - public function save_field_image($term_id, $field, $old, $new) |
|
1268 | - { |
|
1269 | - $name = $field['id']; |
|
1270 | - |
|
1271 | - $this->delete_tax_meta($term_id, $name); |
|
1272 | - if ($new === '' || $new === array() || $new['id'] == '' || $new['src'] == '') |
|
1273 | - return; |
|
1274 | - |
|
1275 | - $this->update_tax_meta($term_id, $name, $new); |
|
1276 | - } |
|
1277 | - |
|
1278 | - /* |
|
1218 | + } |
|
1219 | + |
|
1220 | + |
|
1221 | + //skip on Paragraph field |
|
1222 | + if ($type != "paragraph") { |
|
1223 | + |
|
1224 | + // Call defined method to save meta value, if there's no methods, call common one. |
|
1225 | + $save_func = 'save_field_' . $type; |
|
1226 | + if (method_exists($this, $save_func)) { |
|
1227 | + call_user_func(array(&$this, 'save_field_' . $type), $term_id, $field, $old, $new); |
|
1228 | + } else { |
|
1229 | + $this->save_field($term_id, $field, $old, $new); |
|
1230 | + } |
|
1231 | + } |
|
1232 | + |
|
1233 | + } // End foreach |
|
1234 | + |
|
1235 | + } |
|
1236 | + |
|
1237 | + /** |
|
1238 | + * Common function for saving fields. |
|
1239 | + * |
|
1240 | + * @param string $term_id The term ID. |
|
1241 | + * @param string $field |
|
1242 | + * @param string $old |
|
1243 | + * @param string|mixed $new |
|
1244 | + * @since 1.0 |
|
1245 | + * @access public |
|
1246 | + */ |
|
1247 | + public function save_field($term_id, $field, $old, $new) |
|
1248 | + { |
|
1249 | + $name = $field['id']; |
|
1250 | + $this->delete_tax_meta($term_id, $name); |
|
1251 | + if ($new === '' || $new === array()) |
|
1252 | + return; |
|
1253 | + |
|
1254 | + $this->update_tax_meta($term_id, $name, $new); |
|
1255 | + } |
|
1256 | + |
|
1257 | + /** |
|
1258 | + * function for saving image field. |
|
1259 | + * |
|
1260 | + * @param string $term_id The term ID. |
|
1261 | + * @param string $field |
|
1262 | + * @param string $old |
|
1263 | + * @param string|mixed $new |
|
1264 | + * @since 1.0 |
|
1265 | + * @access public |
|
1266 | + */ |
|
1267 | + public function save_field_image($term_id, $field, $old, $new) |
|
1268 | + { |
|
1269 | + $name = $field['id']; |
|
1270 | + |
|
1271 | + $this->delete_tax_meta($term_id, $name); |
|
1272 | + if ($new === '' || $new === array() || $new['id'] == '' || $new['src'] == '') |
|
1273 | + return; |
|
1274 | + |
|
1275 | + $this->update_tax_meta($term_id, $name, $new); |
|
1276 | + } |
|
1277 | + |
|
1278 | + /* |
|
1279 | 1279 | * Save Wysiwyg Field. |
1280 | 1280 | * |
1281 | 1281 | * @param string $term_id The term ID. |
@@ -1285,806 +1285,806 @@ discard block |
||
1285 | 1285 | * @since 1.0 |
1286 | 1286 | * @access public |
1287 | 1287 | */ |
1288 | - public function save_field_wysiwyg($term_id, $field, $old, $new) |
|
1289 | - { |
|
1290 | - $this->save_field($term_id, $field, $old, $new); |
|
1291 | - } |
|
1292 | - |
|
1293 | - /** |
|
1294 | - * Save repeater Fields. |
|
1295 | - * |
|
1296 | - * @param string $term_id The term ID. |
|
1297 | - * @param string $field |
|
1298 | - * @param string|mixed $old |
|
1299 | - * @param string|mixed $new |
|
1300 | - * @since 1.0 |
|
1301 | - * @access public |
|
1302 | - */ |
|
1303 | - public function save_field_repeater($term_id, $field, $old, $new) |
|
1304 | - { |
|
1305 | - if (is_array($new) && count($new) > 0) { |
|
1306 | - foreach ($new as $n) { |
|
1307 | - foreach ($field['fields'] as $f) { |
|
1308 | - $type = $f['type']; |
|
1309 | - switch ($type) { |
|
1310 | - case 'wysiwyg': |
|
1311 | - $n[$f['id']] = wpautop($n[$f['id']]); |
|
1312 | - break; |
|
1313 | - case 'file': |
|
1314 | - $n[$f['id']] = $this->save_field_file_repeater($term_id, $f, '', $n[$f['id']]); |
|
1315 | - break; |
|
1316 | - default: |
|
1317 | - break; |
|
1318 | - } |
|
1319 | - } |
|
1320 | - if (!$this->is_array_empty($n)) |
|
1321 | - $temp[] = $n; |
|
1322 | - } |
|
1323 | - if (isset($temp) && count($temp) > 0 && !$this->is_array_empty($temp)) { |
|
1324 | - $this->update_tax_meta($term_id, $field['id'], $temp); |
|
1325 | - } else { |
|
1326 | - // remove old meta if exists |
|
1327 | - delete_post_meta($term_id, $field['id']); |
|
1328 | - } |
|
1329 | - } else { |
|
1330 | - // remove old meta if exists |
|
1331 | - delete_post_meta($term_id, $field['id']); |
|
1332 | - } |
|
1333 | - } |
|
1334 | - |
|
1335 | - /** |
|
1336 | - * Save File Field. |
|
1337 | - * |
|
1338 | - * @param string $term_id The term ID. |
|
1339 | - * @param string $field |
|
1340 | - * @param string $old |
|
1341 | - * @param string $new |
|
1342 | - * @since 1.0 |
|
1343 | - * @access public |
|
1344 | - */ |
|
1345 | - public function save_field_file($term_id, $field, $old, $new) |
|
1346 | - { |
|
1347 | - |
|
1348 | - $name = $field['id']; |
|
1349 | - if (empty($_FILES[$name])) |
|
1350 | - return; |
|
1351 | - $this->fix_file_array($_FILES[$name]); |
|
1352 | - foreach ($_FILES[$name] as $position => $fileitem) { |
|
1353 | - |
|
1354 | - $file = wp_handle_upload($fileitem, array('test_form' => false)); |
|
1355 | - if (empty($file['file'])) |
|
1356 | - continue; |
|
1357 | - $filename = $file['file']; |
|
1358 | - |
|
1359 | - $attachment = array( |
|
1360 | - 'post_mime_type' => $file['type'], |
|
1361 | - 'guid' => $file['url'], |
|
1362 | - 'post_parent' => $term_id, |
|
1363 | - 'post_title' => preg_replace('/\.[^.]+$/', '', basename($filename)), |
|
1364 | - 'post_content' => '' |
|
1365 | - ); |
|
1366 | - |
|
1367 | - $id = wp_insert_attachment($attachment, $filename, $term_id); |
|
1368 | - |
|
1369 | - if (!is_wp_error($id)) { |
|
1370 | - |
|
1371 | - wp_update_attachment_metadata($id, wp_generate_attachment_metadata($id, $filename)); |
|
1372 | - add_post_meta($term_id, $name, $id, false); // save file's url in meta fields |
|
1373 | - |
|
1374 | - } // End if |
|
1375 | - |
|
1376 | - } // End foreach |
|
1377 | - |
|
1378 | - } |
|
1379 | - |
|
1380 | - /** |
|
1381 | - * Save repeater File Field. |
|
1382 | - * @param string $term_id The term ID. |
|
1383 | - * @param string $field |
|
1384 | - * @param string $old |
|
1385 | - * @param string $new |
|
1386 | - * @since 1.0 |
|
1387 | - * @access public |
|
1388 | - * @return int|void |
|
1389 | - */ |
|
1390 | - public function save_field_file_repeater($term_id, $field, $old, $new) |
|
1391 | - { |
|
1392 | - |
|
1393 | - $name = $field['id']; |
|
1394 | - if (empty($_FILES[$name])) |
|
1395 | - return; |
|
1396 | - $this->fix_file_array($_FILES[$name]); |
|
1397 | - foreach ($_FILES[$name] as $position => $fileitem) { |
|
1398 | - |
|
1399 | - $file = wp_handle_upload($fileitem, array('test_form' => false)); |
|
1400 | - if (empty($file['file'])) |
|
1401 | - continue; |
|
1402 | - $filename = $file['file']; |
|
1403 | - |
|
1404 | - $attachment = array( |
|
1405 | - 'post_mime_type' => $file['type'], |
|
1406 | - 'guid' => $file['url'], |
|
1407 | - 'post_parent' => $term_id, |
|
1408 | - 'post_title' => preg_replace('/\.[^.]+$/', '', basename($filename)), |
|
1409 | - 'post_content' => '' |
|
1410 | - ); |
|
1411 | - |
|
1412 | - $id = wp_insert_attachment($attachment, $filename); |
|
1413 | - |
|
1414 | - if (!is_wp_error($id)) { |
|
1415 | - |
|
1416 | - wp_update_attachment_metadata($id, wp_generate_attachment_metadata($id, $filename)); |
|
1417 | - return $id; // return file's url in meta fields |
|
1418 | - } // End if |
|
1419 | - } // End foreach |
|
1420 | - } |
|
1421 | - |
|
1422 | - /** |
|
1423 | - * Add missed values for meta box. |
|
1424 | - * |
|
1425 | - * @since 1.0 |
|
1426 | - * @access public |
|
1427 | - */ |
|
1428 | - public function add_missed_values() |
|
1429 | - { |
|
1430 | - |
|
1431 | - // Default values for meta box |
|
1432 | - $this->_meta_box = array_merge(array('context' => 'normal', 'priority' => 'high', 'pages' => array('post')), (array)$this->_meta_box); |
|
1433 | - |
|
1434 | - if(is_array($this->_fields)) { |
|
1435 | - // Default values for fields |
|
1436 | - foreach ($this->_fields as &$field) { |
|
1437 | - $multiple = in_array($field['type'], array('checkbox_list', 'file', 'image')); |
|
1438 | - $std = $multiple ? array() : ''; |
|
1439 | - $format = 'date' == $field['type'] ? 'yy-mm-dd' : ('time' == $field['type'] ? 'hh:mm' : ''); |
|
1440 | - $field = array_merge(array('multiple' => $multiple, 'std' => $std, 'desc' => '', 'format' => $format, 'validate_func' => ''), $field); |
|
1441 | - } // End foreach |
|
1442 | - } |
|
1443 | - } |
|
1444 | - |
|
1445 | - /** |
|
1446 | - * Check if field with $type exists. |
|
1447 | - * |
|
1448 | - * @param string $type |
|
1449 | - * @since 1.0 |
|
1450 | - * @access public |
|
1451 | - */ |
|
1452 | - public function has_field($type) |
|
1453 | - { |
|
1454 | - if(is_array($this->_fields)) { |
|
1455 | - foreach ($this->_fields as $field) { |
|
1456 | - if ($type == $field['type']) |
|
1457 | - return true; |
|
1458 | - } |
|
1459 | - } |
|
1460 | - return false; |
|
1461 | - } |
|
1462 | - |
|
1463 | - /** |
|
1464 | - * Check if current page is edit page. |
|
1465 | - * |
|
1466 | - * @since 1.0 |
|
1467 | - * @access public |
|
1468 | - */ |
|
1469 | - public function is_edit_page() |
|
1470 | - { |
|
1471 | - global $pagenow; |
|
1472 | - return ($pagenow == 'edit-tags.php' || $pagenow == 'term.php'); |
|
1473 | - } |
|
1474 | - |
|
1475 | - /** |
|
1476 | - * Fixes the odd indexing of multiple file uploads. |
|
1477 | - * |
|
1478 | - * Goes from the format: |
|
1479 | - * $_FILES['field']['key']['index'] |
|
1480 | - * to |
|
1481 | - * The More standard and appropriate: |
|
1482 | - * $_FILES['field']['index']['key'] |
|
1483 | - * |
|
1484 | - * @param string $files |
|
1485 | - * @since 1.0 |
|
1486 | - * @access public |
|
1487 | - */ |
|
1488 | - public function fix_file_array(&$files) |
|
1489 | - { |
|
1490 | - |
|
1491 | - $output = array(); |
|
1492 | - |
|
1493 | - foreach ($files as $key => $list) { |
|
1494 | - foreach ($list as $index => $value) { |
|
1495 | - $output[$index][$key] = $value; |
|
1496 | - } |
|
1497 | - } |
|
1498 | - |
|
1499 | - return $files = $output; |
|
1500 | - |
|
1501 | - } |
|
1502 | - |
|
1503 | - /** |
|
1504 | - * Get proper JQuery UI version. |
|
1505 | - * |
|
1506 | - * Used in order to not conflict with WP Admin Scripts. |
|
1507 | - * |
|
1508 | - * @since 1.0 |
|
1509 | - * @access public |
|
1510 | - */ |
|
1511 | - public function get_jqueryui_ver() |
|
1512 | - { |
|
1513 | - |
|
1514 | - global $wp_version; |
|
1515 | - |
|
1516 | - if (version_compare($wp_version, '3.1', '>=')) { |
|
1517 | - return '1.8.10'; |
|
1518 | - } |
|
1519 | - |
|
1520 | - return '1.7.3'; |
|
1521 | - |
|
1522 | - } |
|
1523 | - |
|
1524 | - /** |
|
1525 | - * Add Field to meta box (generic function) |
|
1526 | - * @author Ohad Raz |
|
1527 | - * @since 1.0 |
|
1528 | - * @access public |
|
1529 | - * @param $id string field id, i.e. the meta key |
|
1530 | - * @param $args mixed|array |
|
1531 | - */ |
|
1532 | - public function addField($id, $args) |
|
1533 | - { |
|
1534 | - $new_field = array('id' => $id, 'std' => '', 'desc' => '', 'style' => ''); |
|
1535 | - $new_field = array_merge($new_field, $args); |
|
1536 | - $this->_fields[] = $new_field; |
|
1537 | - } |
|
1538 | - |
|
1539 | - |
|
1540 | - /** |
|
1541 | - * Add Text Field to meta box |
|
1542 | - * @author Ohad Raz |
|
1543 | - * @since 1.0 |
|
1544 | - * @access public |
|
1545 | - * @param $id string field id, i.e. the meta key |
|
1546 | - * @param $args mixed|array |
|
1547 | - * 'name' => // field name/label string optional |
|
1548 | - * 'desc' => // field description, string optional |
|
1549 | - * 'std' => // default value, string optional |
|
1550 | - * 'style' => // custom style for field, string optional |
|
1551 | - * 'validate_func' => // validate function, string optional |
|
1552 | - * @param $repeater bool is this a field inside a repeatr? true|false(default) |
|
1553 | - */ |
|
1554 | - public function addText($id, $args, $repeater = false) |
|
1555 | - { |
|
1556 | - $new_field = array('type' => 'text', 'id' => $id, 'std' => '', 'desc' => '', 'style' => '', 'name' => __('Text Field', 'geodirectory')); |
|
1557 | - $new_field = array_merge($new_field, $args); |
|
1558 | - if (false === $repeater) { |
|
1559 | - $this->_fields[] = $new_field; |
|
1560 | - } else { |
|
1561 | - return $new_field; |
|
1562 | - } |
|
1563 | - } |
|
1564 | - |
|
1565 | - /** |
|
1566 | - * Add Hidden Field to meta box |
|
1567 | - * @author Ohad Raz |
|
1568 | - * @since 0.1.3 |
|
1569 | - * @access public |
|
1570 | - * @param $id string field id, i.e. the meta key |
|
1571 | - * @param $args mixed|array |
|
1572 | - * 'name' => // field name/label string optional |
|
1573 | - * 'desc' => // field description, string optional |
|
1574 | - * 'std' => // default value, string optional |
|
1575 | - * 'style' => // custom style for field, string optional |
|
1576 | - * 'validate_func' => // validate function, string optional |
|
1577 | - * @param $repeater bool is this a field inside a repeatr? true|false(default) |
|
1578 | - */ |
|
1579 | - public function addHidden($id, $args, $repeater = false) |
|
1580 | - { |
|
1581 | - $new_field = array('type' => 'hidden', 'id' => $id, 'std' => '', 'desc' => '', 'style' => '', 'name' => __('Text Field', 'geodirectory')); |
|
1582 | - $new_field = array_merge($new_field, $args); |
|
1583 | - if (false === $repeater) { |
|
1584 | - $this->_fields[] = $new_field; |
|
1585 | - } else { |
|
1586 | - return $new_field; |
|
1587 | - } |
|
1588 | - } |
|
1589 | - |
|
1590 | - /** |
|
1591 | - * Add Paragraph to meta box |
|
1592 | - * @author Ohad Raz |
|
1593 | - * @since 0.1.3 |
|
1594 | - * @access public |
|
1595 | - * @param $id string field id, i.e. the meta key |
|
1596 | - * @param $value paragraph html |
|
1597 | - * @param $repeater bool is this a field inside a repeatr? true|false(default) |
|
1598 | - */ |
|
1599 | - public function addParagraph($id, $args, $repeater = false) |
|
1600 | - { |
|
1601 | - $new_field = array('type' => 'paragraph', 'id' => $id, 'value' => '', 'style' => ''); |
|
1602 | - $new_field = array_merge($new_field, $args); |
|
1603 | - if (false === $repeater) { |
|
1604 | - $this->_fields[] = $new_field; |
|
1605 | - } else { |
|
1606 | - return $new_field; |
|
1607 | - } |
|
1608 | - } |
|
1609 | - |
|
1610 | - /** |
|
1611 | - * Add Checkbox Field to meta box |
|
1612 | - * @author Ohad Raz |
|
1613 | - * @since 1.0 |
|
1614 | - * @access public |
|
1615 | - * @param $id string field id, i.e. the meta key |
|
1616 | - * @param $args mixed|array |
|
1617 | - * 'name' => // field name/label string optional |
|
1618 | - * 'desc' => // field description, string optional |
|
1619 | - * 'std' => // default value, string optional |
|
1620 | - * 'validate_func' => // validate function, string optional |
|
1621 | - * @param $repeater bool is this a field inside a repeatr? true|false(default) |
|
1622 | - */ |
|
1623 | - public function addCheckbox($id, $args, $repeater = false) |
|
1624 | - { |
|
1625 | - $new_field = array('type' => 'checkbox', 'id' => $id, 'std' => '', 'desc' => '', 'style' => '', 'name' => __('Checkbox Field', 'geodirectory')); |
|
1626 | - $new_field = array_merge($new_field, $args); |
|
1627 | - if (false === $repeater) { |
|
1628 | - $this->_fields[] = $new_field; |
|
1629 | - } else { |
|
1630 | - return $new_field; |
|
1631 | - } |
|
1632 | - } |
|
1633 | - |
|
1634 | - /** |
|
1635 | - * Add CheckboxList Field to meta box |
|
1636 | - * @author Ohad Raz |
|
1637 | - * @since 1.0 |
|
1638 | - * @access public |
|
1639 | - * @param $id string field id, i.e. the meta key |
|
1640 | - * @param $options (array) array of key => value pairs for select options |
|
1641 | - * @param $args mixed|array |
|
1642 | - * 'name' => // field name/label string optional |
|
1643 | - * 'desc' => // field description, string optional |
|
1644 | - * 'std' => // default value, string optional |
|
1645 | - * 'validate_func' => // validate function, string optional |
|
1646 | - * @param $repeater bool is this a field inside a repeatr? true|false(default) |
|
1647 | - * |
|
1648 | - * @return : remember to call: $checkbox_list = $this->get_tax_meta(get_the_ID(), 'meta_name', false); |
|
1649 | - * which means the last param as false to get the values in an array |
|
1650 | - */ |
|
1651 | - public function addCheckboxList($id, $options, $args, $repeater = false) |
|
1652 | - { |
|
1653 | - $new_field = array('type' => 'checkbox_list', 'id' => $id, 'std' => '', 'desc' => '', 'style' => '', 'name' => __('Checkbox List Field', 'geodirectory')); |
|
1654 | - $new_field = array_merge($new_field, $args); |
|
1655 | - if (false === $repeater) { |
|
1656 | - $this->_fields[] = $new_field; |
|
1657 | - } else { |
|
1658 | - return $new_field; |
|
1659 | - } |
|
1660 | - } |
|
1661 | - |
|
1662 | - /** |
|
1663 | - * Add Textarea Field to meta box |
|
1664 | - * @author Ohad Raz |
|
1665 | - * @since 1.0 |
|
1666 | - * @access public |
|
1667 | - * @param $id string field id, i.e. the meta key |
|
1668 | - * @param $args mixed|array |
|
1669 | - * 'name' => // field name/label string optional |
|
1670 | - * 'desc' => // field description, string optional |
|
1671 | - * 'std' => // default value, string optional |
|
1672 | - * 'style' => // custom style for field, string optional |
|
1673 | - * 'validate_func' => // validate function, string optional |
|
1674 | - * @param $repeater bool is this a field inside a repeatr? true|false(default) |
|
1675 | - */ |
|
1676 | - public function addTextarea($id, $args, $repeater = false) |
|
1677 | - { |
|
1678 | - $new_field = array('type' => 'textarea', 'id' => $id, 'std' => '', 'desc' => '', 'style' => '', 'name' => __('Textarea Field', 'geodirectory')); |
|
1679 | - $new_field = array_merge($new_field, $args); |
|
1680 | - if (false === $repeater) { |
|
1681 | - $this->_fields[] = $new_field; |
|
1682 | - } else { |
|
1683 | - return $new_field; |
|
1684 | - } |
|
1685 | - } |
|
1686 | - |
|
1687 | - /** |
|
1688 | - * Add Select Field to meta box |
|
1689 | - * @author Ohad Raz |
|
1690 | - * @since 1.0 |
|
1691 | - * @access public |
|
1692 | - * @param $id string field id, i.e. the meta key |
|
1693 | - * @param $options (array) array of key => value pairs for select options |
|
1694 | - * @param $args mixed|array |
|
1695 | - * 'name' => // field name/label string optional |
|
1696 | - * 'desc' => // field description, string optional |
|
1697 | - * 'std' => // default value, (array) optional |
|
1698 | - * 'multiple' => // select multiple values, optional. Default is false. |
|
1699 | - * 'validate_func' => // validate function, string optional |
|
1700 | - * @param $repeater bool is this a field inside a repeatr? true|false(default) |
|
1701 | - */ |
|
1702 | - public function addSelect($id, $options, $args, $repeater = false) |
|
1703 | - { |
|
1704 | - $new_field = array('type' => 'select', 'id' => $id, 'std' => array(), 'desc' => '', 'style' => '', 'name' => __('Select Field', 'geodirectory'), 'multiple' => false, 'options' => $options); |
|
1705 | - $new_field = array_merge($new_field, $args); |
|
1706 | - if (false === $repeater) { |
|
1707 | - $this->_fields[] = $new_field; |
|
1708 | - } else { |
|
1709 | - return $new_field; |
|
1710 | - } |
|
1711 | - } |
|
1712 | - |
|
1713 | - |
|
1714 | - /** |
|
1715 | - * Add Radio Field to meta box |
|
1716 | - * @author Ohad Raz |
|
1717 | - * @since 1.0 |
|
1718 | - * @access public |
|
1719 | - * @param $id string field id, i.e. the meta key |
|
1720 | - * @param $options (array) array of key => value pairs for radio options |
|
1721 | - * @param $args mixed|array |
|
1722 | - * 'name' => // field name/label string optional |
|
1723 | - * 'desc' => // field description, string optional |
|
1724 | - * 'std' => // default value, string optional |
|
1725 | - * 'validate_func' => // validate function, string optional |
|
1726 | - * @param $repeater bool is this a field inside a repeatr? true|false(default) |
|
1727 | - */ |
|
1728 | - public function addRadio($id, $options, $args, $repeater = false) |
|
1729 | - { |
|
1730 | - $new_field = array('type' => 'radio', 'id' => $id, 'std' => array(), 'desc' => '', 'style' => '', 'name' => __('Radio Field', 'geodirectory'), 'options' => $options); |
|
1731 | - $new_field = array_merge($new_field, $args); |
|
1732 | - if (false === $repeater) { |
|
1733 | - $this->_fields[] = $new_field; |
|
1734 | - } else { |
|
1735 | - return $new_field; |
|
1736 | - } |
|
1737 | - } |
|
1738 | - |
|
1739 | - /** |
|
1740 | - * Add Date Field to meta box |
|
1741 | - * @author Ohad Raz |
|
1742 | - * @since 1.0 |
|
1743 | - * @access public |
|
1744 | - * @param $id string field id, i.e. the meta key |
|
1745 | - * @param $args mixed|array |
|
1746 | - * 'name' => // field name/label string optional |
|
1747 | - * 'desc' => // field description, string optional |
|
1748 | - * 'std' => // default value, string optional |
|
1749 | - * 'validate_func' => // validate function, string optional |
|
1750 | - * 'format' => // date format, default yy-mm-dd. Optional. Default "'d MM, yy'" See more formats here: http://goo.gl/Wcwxn |
|
1751 | - * @param $repeater bool is this a field inside a repeatr? true|false(default) |
|
1752 | - */ |
|
1753 | - public function addDate($id, $args, $repeater = false) |
|
1754 | - { |
|
1755 | - $new_field = array('type' => 'date', 'id' => $id, 'std' => '', 'desc' => '', 'format' => 'yy-mm-dd', 'name' => __('Date Field', 'geodirectory')); |
|
1756 | - $new_field = array_merge($new_field, $args); |
|
1757 | - if (false === $repeater) { |
|
1758 | - $this->_fields[] = $new_field; |
|
1759 | - } else { |
|
1760 | - return $new_field; |
|
1761 | - } |
|
1762 | - } |
|
1763 | - |
|
1764 | - /** |
|
1765 | - * Add Time Field to meta box |
|
1766 | - * @author Ohad Raz |
|
1767 | - * @since 1.0 |
|
1768 | - * @access public |
|
1769 | - * @param $id string- field id, i.e. the meta key |
|
1770 | - * @param $args mixed|array |
|
1771 | - * 'name' => // field name/label string optional |
|
1772 | - * 'desc' => // field description, string optional |
|
1773 | - * 'std' => // default value, string optional |
|
1774 | - * 'validate_func' => // validate function, string optional |
|
1775 | - * 'format' => // time format, default hh:mm. Optional. See more formats here: http://goo.gl/83woX |
|
1776 | - * @param $repeater bool is this a field inside a repeatr? true|false(default) |
|
1777 | - */ |
|
1778 | - public function addTime($id, $args, $repeater = false) |
|
1779 | - { |
|
1780 | - $new_field = array('type' => 'time', 'id' => $id, 'std' => '', 'desc' => '', 'format' => 'hh:mm', 'name' => __('Time Field', 'geodirectory')); |
|
1781 | - $new_field = array_merge($new_field, $args); |
|
1782 | - if (false === $repeater) { |
|
1783 | - $this->_fields[] = $new_field; |
|
1784 | - } else { |
|
1785 | - return $new_field; |
|
1786 | - } |
|
1787 | - } |
|
1788 | - |
|
1789 | - /** |
|
1790 | - * Add Color Field to meta box |
|
1791 | - * @author Ohad Raz |
|
1792 | - * @since 1.0 |
|
1793 | - * @access public |
|
1794 | - * @param $id string field id, i.e. the meta key |
|
1795 | - * @param $args mixed|array |
|
1796 | - * 'name' => // field name/label string optional |
|
1797 | - * 'desc' => // field description, string optional |
|
1798 | - * 'std' => // default value, string optional |
|
1799 | - * 'validate_func' => // validate function, string optional |
|
1800 | - * @param $repeater bool is this a field inside a repeatr? true|false(default) |
|
1801 | - */ |
|
1802 | - public function addColor($id, $args, $repeater = false) |
|
1803 | - { |
|
1804 | - $new_field = array('type' => 'color', 'id' => $id, 'std' => '', 'desc' => '', 'name' => __('ColorPicker Field', 'geodirectory')); |
|
1805 | - $new_field = array_merge($new_field, $args); |
|
1806 | - if (false === $repeater) { |
|
1807 | - $this->_fields[] = $new_field; |
|
1808 | - } else { |
|
1809 | - return $new_field; |
|
1810 | - } |
|
1811 | - } |
|
1812 | - |
|
1813 | - /** |
|
1814 | - * Add Image Field to meta box |
|
1815 | - * @author Ohad Raz |
|
1816 | - * @since 1.0 |
|
1817 | - * @access public |
|
1818 | - * @param $id string field id, i.e. the meta key |
|
1819 | - * @param $args mixed|array |
|
1820 | - * 'name' => // field name/label string optional |
|
1821 | - * 'desc' => // field description, string optional |
|
1822 | - * 'validate_func' => // validate function, string optional |
|
1823 | - * @param $repeater bool is this a field inside a repeatr? true|false(default) |
|
1824 | - */ |
|
1825 | - public function addImage($id, $args, $repeater = false) |
|
1826 | - { |
|
1827 | - $new_field = array('type' => 'image', 'id' => $id, 'desc' => '', 'style' => '', 'name' => __('Image Field', 'geodirectory')); |
|
1828 | - $new_field = array_merge($new_field, $args); |
|
1829 | - |
|
1830 | - if (false === $repeater) { |
|
1831 | - $this->_fields[] = $new_field; |
|
1832 | - } else { |
|
1833 | - return $new_field; |
|
1834 | - } |
|
1835 | - } |
|
1836 | - |
|
1837 | - /** |
|
1838 | - * Add File Field to meta box |
|
1839 | - * @author Ohad Raz |
|
1840 | - * @since 1.0 |
|
1841 | - * @access public |
|
1842 | - * @param $id string field id, i.e. the meta key |
|
1843 | - * @param $args mixed|array |
|
1844 | - * 'name' => // field name/label string optional |
|
1845 | - * 'desc' => // field description, string optional |
|
1846 | - * 'validate_func' => // validate function, string optional |
|
1847 | - * @param $repeater bool is this a field inside a repeatr? true|false(default) |
|
1848 | - */ |
|
1849 | - public function addFile($id, $args, $repeater = false) |
|
1850 | - { |
|
1851 | - $new_field = array('type' => 'file', 'id' => $id, 'desc' => '', 'style' => '', 'name' => __('File Field', 'geodirectory')); |
|
1852 | - $new_field = array_merge($new_field, $args); |
|
1853 | - if (false === $repeater) { |
|
1854 | - $this->_fields[] = $new_field; |
|
1855 | - } else { |
|
1856 | - return $new_field; |
|
1857 | - } |
|
1858 | - } |
|
1859 | - |
|
1860 | - /** |
|
1861 | - * Add WYSIWYG Field to meta box |
|
1862 | - * @author Ohad Raz |
|
1863 | - * @since 1.0 |
|
1864 | - * @access public |
|
1865 | - * @param $id string field id, i.e. the meta key |
|
1866 | - * @param $args mixed|array |
|
1867 | - * 'name' => // field name/label string optional |
|
1868 | - * 'desc' => // field description, string optional |
|
1869 | - * 'std' => // default value, string optional |
|
1870 | - * 'style' => // custom style for field, string optional Default 'width: 300px; height: 400px' |
|
1871 | - * 'validate_func' => // validate function, string optional |
|
1872 | - * @param $repeater bool is this a field inside a repeatr? true|false(default) |
|
1873 | - */ |
|
1874 | - public function addWysiwyg($id, $args, $repeater = false) |
|
1875 | - { |
|
1876 | - $new_field = array('type' => 'wysiwyg', 'id' => $id, 'std' => '', 'desc' => '', 'style' => 'width: 300px; height: 400px', 'name' => __('WYSIWYG Editor Field', 'geodirectory')); |
|
1877 | - $new_field = array_merge($new_field, $args); |
|
1878 | - if (false === $repeater) { |
|
1879 | - $this->_fields[] = $new_field; |
|
1880 | - } else { |
|
1881 | - return $new_field; |
|
1882 | - } |
|
1883 | - } |
|
1884 | - |
|
1885 | - /** |
|
1886 | - * Add Taxonomy Field to meta box |
|
1887 | - * @author Ohad Raz |
|
1888 | - * @since 1.0 |
|
1889 | - * @access public |
|
1890 | - * @param $id string field id, i.e. the meta key |
|
1891 | - * @param $options mixed|array options of taxonomy field |
|
1892 | - * 'taxonomy' => // taxonomy name can be category,post_tag or any custom taxonomy default is category |
|
1893 | - * 'type' => // how to show taxonomy? 'select' (default) or 'checkbox_list' |
|
1894 | - * 'args' => // arguments to query taxonomy, see http://goo.gl/uAANN default ('hide_empty' => false) |
|
1895 | - * @param $args mixed|array |
|
1896 | - * 'name' => // field name/label string optional |
|
1897 | - * 'desc' => // field description, string optional |
|
1898 | - * 'std' => // default value, string optional |
|
1899 | - * 'validate_func' => // validate function, string optional |
|
1900 | - * @param $repeater bool is this a field inside a repeatr? true|false(default) |
|
1901 | - */ |
|
1902 | - public function addTaxonomy($id, $options, $args, $repeater = false) |
|
1903 | - { |
|
1904 | - $q = array('hide_empty' => 0); |
|
1905 | - $tax = 'category'; |
|
1906 | - $type = 'select'; |
|
1907 | - $temp = array($tax, $type, $q); |
|
1908 | - $options = array_merge($temp, $options); |
|
1909 | - $new_field = array('type' => 'taxonomy', 'id' => $id, 'desc' => '', 'name' => __('Taxonomy Field', 'geodirectory'), 'options' => $options); |
|
1910 | - $new_field = array_merge($new_field, $args); |
|
1911 | - if (false === $repeater) { |
|
1912 | - $this->_fields[] = $new_field; |
|
1913 | - } else { |
|
1914 | - return $new_field; |
|
1915 | - } |
|
1916 | - } |
|
1917 | - |
|
1918 | - /** |
|
1919 | - * Add posts Field to meta box |
|
1920 | - * @author Ohad Raz |
|
1921 | - * @since 1.0 |
|
1922 | - * @access public |
|
1923 | - * @param $id string field id, i.e. the meta key |
|
1924 | - * @param $options mixed|array options of taxonomy field |
|
1925 | - * 'post_type' => // post type name, 'post' (default) 'page' or any custom post type |
|
1926 | - * 'type' => // how to show posts? 'select' (default) or 'checkbox_list' |
|
1927 | - * 'args' => // arguments to query posts, see http://goo.gl/is0yK default ('posts_per_page' => -1) |
|
1928 | - * @param $args mixed|array |
|
1929 | - * 'name' => // field name/label string optional |
|
1930 | - * 'desc' => // field description, string optional |
|
1931 | - * 'std' => // default value, string optional |
|
1932 | - * 'validate_func' => // validate function, string optional |
|
1933 | - * @param $repeater bool is this a field inside a repeatr? true|false(default) |
|
1934 | - */ |
|
1935 | - public function addPosts($id, $options, $args, $repeater = false) |
|
1936 | - { |
|
1937 | - $q = array('posts_per_page' => -1); |
|
1938 | - $temp = array('post_type' => 'post', 'type' => 'select', 'args' => $q); |
|
1939 | - $options = array_merge($temp, $options); |
|
1940 | - $new_field = array('type' => 'posts', 'id' => $id, 'desc' => '', 'name' => __('Posts Field', 'geodirectory'), 'options' => $options); |
|
1941 | - $new_field = array_merge($new_field, $args); |
|
1942 | - if (false === $repeater) { |
|
1943 | - $this->_fields[] = $new_field; |
|
1944 | - } else { |
|
1945 | - return $new_field; |
|
1946 | - } |
|
1947 | - } |
|
1948 | - |
|
1949 | - /** |
|
1950 | - * Add repeater Field Block to meta box |
|
1951 | - * @author Ohad Raz |
|
1952 | - * @since 1.0 |
|
1953 | - * @access public |
|
1954 | - * @param $id string field id, i.e. the meta key |
|
1955 | - * @param $args mixed|array |
|
1956 | - * 'name' => // field name/label string optional |
|
1957 | - * 'desc' => // field description, string optional |
|
1958 | - * 'std' => // default value, string optional |
|
1959 | - * 'style' => // custom style for field, string optional |
|
1960 | - * 'validate_func' => // validate function, string optional |
|
1961 | - * 'fields' => //fields to repeater |
|
1962 | - */ |
|
1963 | - public function addRepeaterBlock($id, $args) |
|
1964 | - { |
|
1965 | - $new_field = array('type' => 'repeater', 'id' => $id, 'name' => __('Reapeater Field', 'geodirectory'), 'fields' => array(), 'inline' => false); |
|
1966 | - $new_field = array_merge($new_field, $args); |
|
1967 | - $this->_fields[] = $new_field; |
|
1968 | - } |
|
1969 | - |
|
1970 | - |
|
1971 | - /** |
|
1972 | - * Finish Declaration of Meta Box |
|
1973 | - * @author Ohad Raz |
|
1974 | - * @since 1.0 |
|
1975 | - * @access public |
|
1976 | - */ |
|
1977 | - public function Finish() |
|
1978 | - { |
|
1979 | - $this->add_missed_values(); |
|
1980 | - $this->check_field_upload(); |
|
1981 | - $this->check_field_color(); |
|
1982 | - $this->check_field_date(); |
|
1983 | - $this->check_field_time(); |
|
1984 | - } |
|
1985 | - |
|
1986 | - /** |
|
1987 | - * Helper function to check for empty arrays |
|
1988 | - * @author Ohad Raz |
|
1989 | - * @since 1.0 |
|
1990 | - * @access public |
|
1991 | - * @param $args mixed|array |
|
1992 | - */ |
|
1993 | - public function is_array_empty($array) |
|
1994 | - { |
|
1995 | - if (!is_array($array)) |
|
1996 | - return true; |
|
1997 | - |
|
1998 | - foreach ($array as $a) { |
|
1999 | - if (is_array($a)) { |
|
2000 | - foreach ($a as $sub_a) { |
|
2001 | - if (!empty($sub_a) && $sub_a != '') |
|
2002 | - return false; |
|
2003 | - } |
|
2004 | - } else { |
|
2005 | - if (!empty($a) && $a != '') |
|
2006 | - return false; |
|
2007 | - } |
|
2008 | - } |
|
2009 | - return true; |
|
2010 | - } |
|
2011 | - |
|
2012 | - |
|
2013 | - //get term meta field |
|
2014 | - public function get_tax_meta($term_id, $key, $multi = false, $post_type = '') |
|
2015 | - { |
|
2016 | - |
|
2017 | - if (empty($post_type) && isset($_REQUEST['taxonomy'])) { |
|
2018 | - $taxObject = get_taxonomy($_REQUEST['taxonomy']); |
|
2019 | - $post_type = $taxObject->object_type[0]; |
|
2020 | - } |
|
2021 | - |
|
2022 | - if($post_type=='post'){$post_type='';} |
|
2023 | - if($post_type){$post_type = $post_type.'_';} |
|
2024 | - |
|
2025 | - $t_id = (is_object($term_id)) ? $term_id->term_id : $term_id; |
|
2026 | - |
|
2027 | - $m = get_option('tax_meta_' . $post_type . $t_id); |
|
2028 | - if (isset($m[$key])) { |
|
2029 | - return $m[$key]; |
|
2030 | - } else { |
|
2031 | - return ''; |
|
2032 | - } |
|
2033 | - } |
|
2034 | - |
|
2035 | - //delete meta |
|
2036 | - public function delete_tax_meta($term_id, $key, $post_type = '') |
|
2037 | - { |
|
2038 | - |
|
2039 | - if (empty($post_type) && isset($_REQUEST['taxonomy'])) { |
|
2040 | - $taxObject = get_taxonomy($_REQUEST['taxonomy']); |
|
2041 | - $post_type = $taxObject->object_type[0]; |
|
2042 | - } |
|
2043 | - |
|
2044 | - if($post_type=='post'){$post_type='';} |
|
2045 | - if($post_type){$post_type = $post_type.'_';} |
|
2046 | - |
|
2047 | - $m = get_option('tax_meta_' . $post_type . $term_id); |
|
2048 | - |
|
2049 | - if (isset($m[$key])) { |
|
2050 | - unset($m[$key]); |
|
2051 | - } |
|
2052 | - update_option('tax_meta_' . $post_type . $term_id, $m); |
|
2053 | - } |
|
2054 | - |
|
2055 | - //update meta |
|
2056 | - public function update_tax_meta($term_id, $key, $value, $post_type = '') |
|
2057 | - { |
|
2058 | - |
|
2059 | - if (empty($post_type) && isset($_REQUEST['taxonomy'])) { |
|
2060 | - $taxObject = get_taxonomy($_REQUEST['taxonomy']); |
|
2061 | - $post_type = $taxObject->object_type[0]; |
|
2062 | - } |
|
2063 | - |
|
2064 | - if($post_type=='post'){$post_type='';} |
|
2065 | - if($post_type){$post_type = $post_type.'_';} |
|
2066 | - |
|
2067 | - $m = get_option('tax_meta_' . $post_type . $term_id); |
|
2068 | - |
|
2069 | - $m[$key] = $value; |
|
2070 | - update_option('tax_meta_' . $post_type . $term_id, $m); |
|
2071 | - |
|
2072 | - /** |
|
2073 | - * Called after the tax meta is updated. |
|
2074 | - * |
|
2075 | - * Used to update things after a GD category is saved. |
|
2076 | - * |
|
2077 | - * @since 1.0.0 |
|
2078 | - * @param bool $false False. |
|
2079 | - * @param bool $true True. |
|
2080 | - * @param int $term_id The term id being updated. |
|
2081 | - * @param string $post_type The post type of the cat being updated. |
|
2082 | - */ |
|
2083 | - do_action('gd_tax_meta_updated', false, true, $term_id, $post_type); |
|
2084 | - } |
|
2085 | - |
|
2086 | - |
|
2087 | - } // End Class |
|
1288 | + public function save_field_wysiwyg($term_id, $field, $old, $new) |
|
1289 | + { |
|
1290 | + $this->save_field($term_id, $field, $old, $new); |
|
1291 | + } |
|
1292 | + |
|
1293 | + /** |
|
1294 | + * Save repeater Fields. |
|
1295 | + * |
|
1296 | + * @param string $term_id The term ID. |
|
1297 | + * @param string $field |
|
1298 | + * @param string|mixed $old |
|
1299 | + * @param string|mixed $new |
|
1300 | + * @since 1.0 |
|
1301 | + * @access public |
|
1302 | + */ |
|
1303 | + public function save_field_repeater($term_id, $field, $old, $new) |
|
1304 | + { |
|
1305 | + if (is_array($new) && count($new) > 0) { |
|
1306 | + foreach ($new as $n) { |
|
1307 | + foreach ($field['fields'] as $f) { |
|
1308 | + $type = $f['type']; |
|
1309 | + switch ($type) { |
|
1310 | + case 'wysiwyg': |
|
1311 | + $n[$f['id']] = wpautop($n[$f['id']]); |
|
1312 | + break; |
|
1313 | + case 'file': |
|
1314 | + $n[$f['id']] = $this->save_field_file_repeater($term_id, $f, '', $n[$f['id']]); |
|
1315 | + break; |
|
1316 | + default: |
|
1317 | + break; |
|
1318 | + } |
|
1319 | + } |
|
1320 | + if (!$this->is_array_empty($n)) |
|
1321 | + $temp[] = $n; |
|
1322 | + } |
|
1323 | + if (isset($temp) && count($temp) > 0 && !$this->is_array_empty($temp)) { |
|
1324 | + $this->update_tax_meta($term_id, $field['id'], $temp); |
|
1325 | + } else { |
|
1326 | + // remove old meta if exists |
|
1327 | + delete_post_meta($term_id, $field['id']); |
|
1328 | + } |
|
1329 | + } else { |
|
1330 | + // remove old meta if exists |
|
1331 | + delete_post_meta($term_id, $field['id']); |
|
1332 | + } |
|
1333 | + } |
|
1334 | + |
|
1335 | + /** |
|
1336 | + * Save File Field. |
|
1337 | + * |
|
1338 | + * @param string $term_id The term ID. |
|
1339 | + * @param string $field |
|
1340 | + * @param string $old |
|
1341 | + * @param string $new |
|
1342 | + * @since 1.0 |
|
1343 | + * @access public |
|
1344 | + */ |
|
1345 | + public function save_field_file($term_id, $field, $old, $new) |
|
1346 | + { |
|
1347 | + |
|
1348 | + $name = $field['id']; |
|
1349 | + if (empty($_FILES[$name])) |
|
1350 | + return; |
|
1351 | + $this->fix_file_array($_FILES[$name]); |
|
1352 | + foreach ($_FILES[$name] as $position => $fileitem) { |
|
1353 | + |
|
1354 | + $file = wp_handle_upload($fileitem, array('test_form' => false)); |
|
1355 | + if (empty($file['file'])) |
|
1356 | + continue; |
|
1357 | + $filename = $file['file']; |
|
1358 | + |
|
1359 | + $attachment = array( |
|
1360 | + 'post_mime_type' => $file['type'], |
|
1361 | + 'guid' => $file['url'], |
|
1362 | + 'post_parent' => $term_id, |
|
1363 | + 'post_title' => preg_replace('/\.[^.]+$/', '', basename($filename)), |
|
1364 | + 'post_content' => '' |
|
1365 | + ); |
|
1366 | + |
|
1367 | + $id = wp_insert_attachment($attachment, $filename, $term_id); |
|
1368 | + |
|
1369 | + if (!is_wp_error($id)) { |
|
1370 | + |
|
1371 | + wp_update_attachment_metadata($id, wp_generate_attachment_metadata($id, $filename)); |
|
1372 | + add_post_meta($term_id, $name, $id, false); // save file's url in meta fields |
|
1373 | + |
|
1374 | + } // End if |
|
1375 | + |
|
1376 | + } // End foreach |
|
1377 | + |
|
1378 | + } |
|
1379 | + |
|
1380 | + /** |
|
1381 | + * Save repeater File Field. |
|
1382 | + * @param string $term_id The term ID. |
|
1383 | + * @param string $field |
|
1384 | + * @param string $old |
|
1385 | + * @param string $new |
|
1386 | + * @since 1.0 |
|
1387 | + * @access public |
|
1388 | + * @return int|void |
|
1389 | + */ |
|
1390 | + public function save_field_file_repeater($term_id, $field, $old, $new) |
|
1391 | + { |
|
1392 | + |
|
1393 | + $name = $field['id']; |
|
1394 | + if (empty($_FILES[$name])) |
|
1395 | + return; |
|
1396 | + $this->fix_file_array($_FILES[$name]); |
|
1397 | + foreach ($_FILES[$name] as $position => $fileitem) { |
|
1398 | + |
|
1399 | + $file = wp_handle_upload($fileitem, array('test_form' => false)); |
|
1400 | + if (empty($file['file'])) |
|
1401 | + continue; |
|
1402 | + $filename = $file['file']; |
|
1403 | + |
|
1404 | + $attachment = array( |
|
1405 | + 'post_mime_type' => $file['type'], |
|
1406 | + 'guid' => $file['url'], |
|
1407 | + 'post_parent' => $term_id, |
|
1408 | + 'post_title' => preg_replace('/\.[^.]+$/', '', basename($filename)), |
|
1409 | + 'post_content' => '' |
|
1410 | + ); |
|
1411 | + |
|
1412 | + $id = wp_insert_attachment($attachment, $filename); |
|
1413 | + |
|
1414 | + if (!is_wp_error($id)) { |
|
1415 | + |
|
1416 | + wp_update_attachment_metadata($id, wp_generate_attachment_metadata($id, $filename)); |
|
1417 | + return $id; // return file's url in meta fields |
|
1418 | + } // End if |
|
1419 | + } // End foreach |
|
1420 | + } |
|
1421 | + |
|
1422 | + /** |
|
1423 | + * Add missed values for meta box. |
|
1424 | + * |
|
1425 | + * @since 1.0 |
|
1426 | + * @access public |
|
1427 | + */ |
|
1428 | + public function add_missed_values() |
|
1429 | + { |
|
1430 | + |
|
1431 | + // Default values for meta box |
|
1432 | + $this->_meta_box = array_merge(array('context' => 'normal', 'priority' => 'high', 'pages' => array('post')), (array)$this->_meta_box); |
|
1433 | + |
|
1434 | + if(is_array($this->_fields)) { |
|
1435 | + // Default values for fields |
|
1436 | + foreach ($this->_fields as &$field) { |
|
1437 | + $multiple = in_array($field['type'], array('checkbox_list', 'file', 'image')); |
|
1438 | + $std = $multiple ? array() : ''; |
|
1439 | + $format = 'date' == $field['type'] ? 'yy-mm-dd' : ('time' == $field['type'] ? 'hh:mm' : ''); |
|
1440 | + $field = array_merge(array('multiple' => $multiple, 'std' => $std, 'desc' => '', 'format' => $format, 'validate_func' => ''), $field); |
|
1441 | + } // End foreach |
|
1442 | + } |
|
1443 | + } |
|
1444 | + |
|
1445 | + /** |
|
1446 | + * Check if field with $type exists. |
|
1447 | + * |
|
1448 | + * @param string $type |
|
1449 | + * @since 1.0 |
|
1450 | + * @access public |
|
1451 | + */ |
|
1452 | + public function has_field($type) |
|
1453 | + { |
|
1454 | + if(is_array($this->_fields)) { |
|
1455 | + foreach ($this->_fields as $field) { |
|
1456 | + if ($type == $field['type']) |
|
1457 | + return true; |
|
1458 | + } |
|
1459 | + } |
|
1460 | + return false; |
|
1461 | + } |
|
1462 | + |
|
1463 | + /** |
|
1464 | + * Check if current page is edit page. |
|
1465 | + * |
|
1466 | + * @since 1.0 |
|
1467 | + * @access public |
|
1468 | + */ |
|
1469 | + public function is_edit_page() |
|
1470 | + { |
|
1471 | + global $pagenow; |
|
1472 | + return ($pagenow == 'edit-tags.php' || $pagenow == 'term.php'); |
|
1473 | + } |
|
1474 | + |
|
1475 | + /** |
|
1476 | + * Fixes the odd indexing of multiple file uploads. |
|
1477 | + * |
|
1478 | + * Goes from the format: |
|
1479 | + * $_FILES['field']['key']['index'] |
|
1480 | + * to |
|
1481 | + * The More standard and appropriate: |
|
1482 | + * $_FILES['field']['index']['key'] |
|
1483 | + * |
|
1484 | + * @param string $files |
|
1485 | + * @since 1.0 |
|
1486 | + * @access public |
|
1487 | + */ |
|
1488 | + public function fix_file_array(&$files) |
|
1489 | + { |
|
1490 | + |
|
1491 | + $output = array(); |
|
1492 | + |
|
1493 | + foreach ($files as $key => $list) { |
|
1494 | + foreach ($list as $index => $value) { |
|
1495 | + $output[$index][$key] = $value; |
|
1496 | + } |
|
1497 | + } |
|
1498 | + |
|
1499 | + return $files = $output; |
|
1500 | + |
|
1501 | + } |
|
1502 | + |
|
1503 | + /** |
|
1504 | + * Get proper JQuery UI version. |
|
1505 | + * |
|
1506 | + * Used in order to not conflict with WP Admin Scripts. |
|
1507 | + * |
|
1508 | + * @since 1.0 |
|
1509 | + * @access public |
|
1510 | + */ |
|
1511 | + public function get_jqueryui_ver() |
|
1512 | + { |
|
1513 | + |
|
1514 | + global $wp_version; |
|
1515 | + |
|
1516 | + if (version_compare($wp_version, '3.1', '>=')) { |
|
1517 | + return '1.8.10'; |
|
1518 | + } |
|
1519 | + |
|
1520 | + return '1.7.3'; |
|
1521 | + |
|
1522 | + } |
|
1523 | + |
|
1524 | + /** |
|
1525 | + * Add Field to meta box (generic function) |
|
1526 | + * @author Ohad Raz |
|
1527 | + * @since 1.0 |
|
1528 | + * @access public |
|
1529 | + * @param $id string field id, i.e. the meta key |
|
1530 | + * @param $args mixed|array |
|
1531 | + */ |
|
1532 | + public function addField($id, $args) |
|
1533 | + { |
|
1534 | + $new_field = array('id' => $id, 'std' => '', 'desc' => '', 'style' => ''); |
|
1535 | + $new_field = array_merge($new_field, $args); |
|
1536 | + $this->_fields[] = $new_field; |
|
1537 | + } |
|
1538 | + |
|
1539 | + |
|
1540 | + /** |
|
1541 | + * Add Text Field to meta box |
|
1542 | + * @author Ohad Raz |
|
1543 | + * @since 1.0 |
|
1544 | + * @access public |
|
1545 | + * @param $id string field id, i.e. the meta key |
|
1546 | + * @param $args mixed|array |
|
1547 | + * 'name' => // field name/label string optional |
|
1548 | + * 'desc' => // field description, string optional |
|
1549 | + * 'std' => // default value, string optional |
|
1550 | + * 'style' => // custom style for field, string optional |
|
1551 | + * 'validate_func' => // validate function, string optional |
|
1552 | + * @param $repeater bool is this a field inside a repeatr? true|false(default) |
|
1553 | + */ |
|
1554 | + public function addText($id, $args, $repeater = false) |
|
1555 | + { |
|
1556 | + $new_field = array('type' => 'text', 'id' => $id, 'std' => '', 'desc' => '', 'style' => '', 'name' => __('Text Field', 'geodirectory')); |
|
1557 | + $new_field = array_merge($new_field, $args); |
|
1558 | + if (false === $repeater) { |
|
1559 | + $this->_fields[] = $new_field; |
|
1560 | + } else { |
|
1561 | + return $new_field; |
|
1562 | + } |
|
1563 | + } |
|
1564 | + |
|
1565 | + /** |
|
1566 | + * Add Hidden Field to meta box |
|
1567 | + * @author Ohad Raz |
|
1568 | + * @since 0.1.3 |
|
1569 | + * @access public |
|
1570 | + * @param $id string field id, i.e. the meta key |
|
1571 | + * @param $args mixed|array |
|
1572 | + * 'name' => // field name/label string optional |
|
1573 | + * 'desc' => // field description, string optional |
|
1574 | + * 'std' => // default value, string optional |
|
1575 | + * 'style' => // custom style for field, string optional |
|
1576 | + * 'validate_func' => // validate function, string optional |
|
1577 | + * @param $repeater bool is this a field inside a repeatr? true|false(default) |
|
1578 | + */ |
|
1579 | + public function addHidden($id, $args, $repeater = false) |
|
1580 | + { |
|
1581 | + $new_field = array('type' => 'hidden', 'id' => $id, 'std' => '', 'desc' => '', 'style' => '', 'name' => __('Text Field', 'geodirectory')); |
|
1582 | + $new_field = array_merge($new_field, $args); |
|
1583 | + if (false === $repeater) { |
|
1584 | + $this->_fields[] = $new_field; |
|
1585 | + } else { |
|
1586 | + return $new_field; |
|
1587 | + } |
|
1588 | + } |
|
1589 | + |
|
1590 | + /** |
|
1591 | + * Add Paragraph to meta box |
|
1592 | + * @author Ohad Raz |
|
1593 | + * @since 0.1.3 |
|
1594 | + * @access public |
|
1595 | + * @param $id string field id, i.e. the meta key |
|
1596 | + * @param $value paragraph html |
|
1597 | + * @param $repeater bool is this a field inside a repeatr? true|false(default) |
|
1598 | + */ |
|
1599 | + public function addParagraph($id, $args, $repeater = false) |
|
1600 | + { |
|
1601 | + $new_field = array('type' => 'paragraph', 'id' => $id, 'value' => '', 'style' => ''); |
|
1602 | + $new_field = array_merge($new_field, $args); |
|
1603 | + if (false === $repeater) { |
|
1604 | + $this->_fields[] = $new_field; |
|
1605 | + } else { |
|
1606 | + return $new_field; |
|
1607 | + } |
|
1608 | + } |
|
1609 | + |
|
1610 | + /** |
|
1611 | + * Add Checkbox Field to meta box |
|
1612 | + * @author Ohad Raz |
|
1613 | + * @since 1.0 |
|
1614 | + * @access public |
|
1615 | + * @param $id string field id, i.e. the meta key |
|
1616 | + * @param $args mixed|array |
|
1617 | + * 'name' => // field name/label string optional |
|
1618 | + * 'desc' => // field description, string optional |
|
1619 | + * 'std' => // default value, string optional |
|
1620 | + * 'validate_func' => // validate function, string optional |
|
1621 | + * @param $repeater bool is this a field inside a repeatr? true|false(default) |
|
1622 | + */ |
|
1623 | + public function addCheckbox($id, $args, $repeater = false) |
|
1624 | + { |
|
1625 | + $new_field = array('type' => 'checkbox', 'id' => $id, 'std' => '', 'desc' => '', 'style' => '', 'name' => __('Checkbox Field', 'geodirectory')); |
|
1626 | + $new_field = array_merge($new_field, $args); |
|
1627 | + if (false === $repeater) { |
|
1628 | + $this->_fields[] = $new_field; |
|
1629 | + } else { |
|
1630 | + return $new_field; |
|
1631 | + } |
|
1632 | + } |
|
1633 | + |
|
1634 | + /** |
|
1635 | + * Add CheckboxList Field to meta box |
|
1636 | + * @author Ohad Raz |
|
1637 | + * @since 1.0 |
|
1638 | + * @access public |
|
1639 | + * @param $id string field id, i.e. the meta key |
|
1640 | + * @param $options (array) array of key => value pairs for select options |
|
1641 | + * @param $args mixed|array |
|
1642 | + * 'name' => // field name/label string optional |
|
1643 | + * 'desc' => // field description, string optional |
|
1644 | + * 'std' => // default value, string optional |
|
1645 | + * 'validate_func' => // validate function, string optional |
|
1646 | + * @param $repeater bool is this a field inside a repeatr? true|false(default) |
|
1647 | + * |
|
1648 | + * @return : remember to call: $checkbox_list = $this->get_tax_meta(get_the_ID(), 'meta_name', false); |
|
1649 | + * which means the last param as false to get the values in an array |
|
1650 | + */ |
|
1651 | + public function addCheckboxList($id, $options, $args, $repeater = false) |
|
1652 | + { |
|
1653 | + $new_field = array('type' => 'checkbox_list', 'id' => $id, 'std' => '', 'desc' => '', 'style' => '', 'name' => __('Checkbox List Field', 'geodirectory')); |
|
1654 | + $new_field = array_merge($new_field, $args); |
|
1655 | + if (false === $repeater) { |
|
1656 | + $this->_fields[] = $new_field; |
|
1657 | + } else { |
|
1658 | + return $new_field; |
|
1659 | + } |
|
1660 | + } |
|
1661 | + |
|
1662 | + /** |
|
1663 | + * Add Textarea Field to meta box |
|
1664 | + * @author Ohad Raz |
|
1665 | + * @since 1.0 |
|
1666 | + * @access public |
|
1667 | + * @param $id string field id, i.e. the meta key |
|
1668 | + * @param $args mixed|array |
|
1669 | + * 'name' => // field name/label string optional |
|
1670 | + * 'desc' => // field description, string optional |
|
1671 | + * 'std' => // default value, string optional |
|
1672 | + * 'style' => // custom style for field, string optional |
|
1673 | + * 'validate_func' => // validate function, string optional |
|
1674 | + * @param $repeater bool is this a field inside a repeatr? true|false(default) |
|
1675 | + */ |
|
1676 | + public function addTextarea($id, $args, $repeater = false) |
|
1677 | + { |
|
1678 | + $new_field = array('type' => 'textarea', 'id' => $id, 'std' => '', 'desc' => '', 'style' => '', 'name' => __('Textarea Field', 'geodirectory')); |
|
1679 | + $new_field = array_merge($new_field, $args); |
|
1680 | + if (false === $repeater) { |
|
1681 | + $this->_fields[] = $new_field; |
|
1682 | + } else { |
|
1683 | + return $new_field; |
|
1684 | + } |
|
1685 | + } |
|
1686 | + |
|
1687 | + /** |
|
1688 | + * Add Select Field to meta box |
|
1689 | + * @author Ohad Raz |
|
1690 | + * @since 1.0 |
|
1691 | + * @access public |
|
1692 | + * @param $id string field id, i.e. the meta key |
|
1693 | + * @param $options (array) array of key => value pairs for select options |
|
1694 | + * @param $args mixed|array |
|
1695 | + * 'name' => // field name/label string optional |
|
1696 | + * 'desc' => // field description, string optional |
|
1697 | + * 'std' => // default value, (array) optional |
|
1698 | + * 'multiple' => // select multiple values, optional. Default is false. |
|
1699 | + * 'validate_func' => // validate function, string optional |
|
1700 | + * @param $repeater bool is this a field inside a repeatr? true|false(default) |
|
1701 | + */ |
|
1702 | + public function addSelect($id, $options, $args, $repeater = false) |
|
1703 | + { |
|
1704 | + $new_field = array('type' => 'select', 'id' => $id, 'std' => array(), 'desc' => '', 'style' => '', 'name' => __('Select Field', 'geodirectory'), 'multiple' => false, 'options' => $options); |
|
1705 | + $new_field = array_merge($new_field, $args); |
|
1706 | + if (false === $repeater) { |
|
1707 | + $this->_fields[] = $new_field; |
|
1708 | + } else { |
|
1709 | + return $new_field; |
|
1710 | + } |
|
1711 | + } |
|
1712 | + |
|
1713 | + |
|
1714 | + /** |
|
1715 | + * Add Radio Field to meta box |
|
1716 | + * @author Ohad Raz |
|
1717 | + * @since 1.0 |
|
1718 | + * @access public |
|
1719 | + * @param $id string field id, i.e. the meta key |
|
1720 | + * @param $options (array) array of key => value pairs for radio options |
|
1721 | + * @param $args mixed|array |
|
1722 | + * 'name' => // field name/label string optional |
|
1723 | + * 'desc' => // field description, string optional |
|
1724 | + * 'std' => // default value, string optional |
|
1725 | + * 'validate_func' => // validate function, string optional |
|
1726 | + * @param $repeater bool is this a field inside a repeatr? true|false(default) |
|
1727 | + */ |
|
1728 | + public function addRadio($id, $options, $args, $repeater = false) |
|
1729 | + { |
|
1730 | + $new_field = array('type' => 'radio', 'id' => $id, 'std' => array(), 'desc' => '', 'style' => '', 'name' => __('Radio Field', 'geodirectory'), 'options' => $options); |
|
1731 | + $new_field = array_merge($new_field, $args); |
|
1732 | + if (false === $repeater) { |
|
1733 | + $this->_fields[] = $new_field; |
|
1734 | + } else { |
|
1735 | + return $new_field; |
|
1736 | + } |
|
1737 | + } |
|
1738 | + |
|
1739 | + /** |
|
1740 | + * Add Date Field to meta box |
|
1741 | + * @author Ohad Raz |
|
1742 | + * @since 1.0 |
|
1743 | + * @access public |
|
1744 | + * @param $id string field id, i.e. the meta key |
|
1745 | + * @param $args mixed|array |
|
1746 | + * 'name' => // field name/label string optional |
|
1747 | + * 'desc' => // field description, string optional |
|
1748 | + * 'std' => // default value, string optional |
|
1749 | + * 'validate_func' => // validate function, string optional |
|
1750 | + * 'format' => // date format, default yy-mm-dd. Optional. Default "'d MM, yy'" See more formats here: http://goo.gl/Wcwxn |
|
1751 | + * @param $repeater bool is this a field inside a repeatr? true|false(default) |
|
1752 | + */ |
|
1753 | + public function addDate($id, $args, $repeater = false) |
|
1754 | + { |
|
1755 | + $new_field = array('type' => 'date', 'id' => $id, 'std' => '', 'desc' => '', 'format' => 'yy-mm-dd', 'name' => __('Date Field', 'geodirectory')); |
|
1756 | + $new_field = array_merge($new_field, $args); |
|
1757 | + if (false === $repeater) { |
|
1758 | + $this->_fields[] = $new_field; |
|
1759 | + } else { |
|
1760 | + return $new_field; |
|
1761 | + } |
|
1762 | + } |
|
1763 | + |
|
1764 | + /** |
|
1765 | + * Add Time Field to meta box |
|
1766 | + * @author Ohad Raz |
|
1767 | + * @since 1.0 |
|
1768 | + * @access public |
|
1769 | + * @param $id string- field id, i.e. the meta key |
|
1770 | + * @param $args mixed|array |
|
1771 | + * 'name' => // field name/label string optional |
|
1772 | + * 'desc' => // field description, string optional |
|
1773 | + * 'std' => // default value, string optional |
|
1774 | + * 'validate_func' => // validate function, string optional |
|
1775 | + * 'format' => // time format, default hh:mm. Optional. See more formats here: http://goo.gl/83woX |
|
1776 | + * @param $repeater bool is this a field inside a repeatr? true|false(default) |
|
1777 | + */ |
|
1778 | + public function addTime($id, $args, $repeater = false) |
|
1779 | + { |
|
1780 | + $new_field = array('type' => 'time', 'id' => $id, 'std' => '', 'desc' => '', 'format' => 'hh:mm', 'name' => __('Time Field', 'geodirectory')); |
|
1781 | + $new_field = array_merge($new_field, $args); |
|
1782 | + if (false === $repeater) { |
|
1783 | + $this->_fields[] = $new_field; |
|
1784 | + } else { |
|
1785 | + return $new_field; |
|
1786 | + } |
|
1787 | + } |
|
1788 | + |
|
1789 | + /** |
|
1790 | + * Add Color Field to meta box |
|
1791 | + * @author Ohad Raz |
|
1792 | + * @since 1.0 |
|
1793 | + * @access public |
|
1794 | + * @param $id string field id, i.e. the meta key |
|
1795 | + * @param $args mixed|array |
|
1796 | + * 'name' => // field name/label string optional |
|
1797 | + * 'desc' => // field description, string optional |
|
1798 | + * 'std' => // default value, string optional |
|
1799 | + * 'validate_func' => // validate function, string optional |
|
1800 | + * @param $repeater bool is this a field inside a repeatr? true|false(default) |
|
1801 | + */ |
|
1802 | + public function addColor($id, $args, $repeater = false) |
|
1803 | + { |
|
1804 | + $new_field = array('type' => 'color', 'id' => $id, 'std' => '', 'desc' => '', 'name' => __('ColorPicker Field', 'geodirectory')); |
|
1805 | + $new_field = array_merge($new_field, $args); |
|
1806 | + if (false === $repeater) { |
|
1807 | + $this->_fields[] = $new_field; |
|
1808 | + } else { |
|
1809 | + return $new_field; |
|
1810 | + } |
|
1811 | + } |
|
1812 | + |
|
1813 | + /** |
|
1814 | + * Add Image Field to meta box |
|
1815 | + * @author Ohad Raz |
|
1816 | + * @since 1.0 |
|
1817 | + * @access public |
|
1818 | + * @param $id string field id, i.e. the meta key |
|
1819 | + * @param $args mixed|array |
|
1820 | + * 'name' => // field name/label string optional |
|
1821 | + * 'desc' => // field description, string optional |
|
1822 | + * 'validate_func' => // validate function, string optional |
|
1823 | + * @param $repeater bool is this a field inside a repeatr? true|false(default) |
|
1824 | + */ |
|
1825 | + public function addImage($id, $args, $repeater = false) |
|
1826 | + { |
|
1827 | + $new_field = array('type' => 'image', 'id' => $id, 'desc' => '', 'style' => '', 'name' => __('Image Field', 'geodirectory')); |
|
1828 | + $new_field = array_merge($new_field, $args); |
|
1829 | + |
|
1830 | + if (false === $repeater) { |
|
1831 | + $this->_fields[] = $new_field; |
|
1832 | + } else { |
|
1833 | + return $new_field; |
|
1834 | + } |
|
1835 | + } |
|
1836 | + |
|
1837 | + /** |
|
1838 | + * Add File Field to meta box |
|
1839 | + * @author Ohad Raz |
|
1840 | + * @since 1.0 |
|
1841 | + * @access public |
|
1842 | + * @param $id string field id, i.e. the meta key |
|
1843 | + * @param $args mixed|array |
|
1844 | + * 'name' => // field name/label string optional |
|
1845 | + * 'desc' => // field description, string optional |
|
1846 | + * 'validate_func' => // validate function, string optional |
|
1847 | + * @param $repeater bool is this a field inside a repeatr? true|false(default) |
|
1848 | + */ |
|
1849 | + public function addFile($id, $args, $repeater = false) |
|
1850 | + { |
|
1851 | + $new_field = array('type' => 'file', 'id' => $id, 'desc' => '', 'style' => '', 'name' => __('File Field', 'geodirectory')); |
|
1852 | + $new_field = array_merge($new_field, $args); |
|
1853 | + if (false === $repeater) { |
|
1854 | + $this->_fields[] = $new_field; |
|
1855 | + } else { |
|
1856 | + return $new_field; |
|
1857 | + } |
|
1858 | + } |
|
1859 | + |
|
1860 | + /** |
|
1861 | + * Add WYSIWYG Field to meta box |
|
1862 | + * @author Ohad Raz |
|
1863 | + * @since 1.0 |
|
1864 | + * @access public |
|
1865 | + * @param $id string field id, i.e. the meta key |
|
1866 | + * @param $args mixed|array |
|
1867 | + * 'name' => // field name/label string optional |
|
1868 | + * 'desc' => // field description, string optional |
|
1869 | + * 'std' => // default value, string optional |
|
1870 | + * 'style' => // custom style for field, string optional Default 'width: 300px; height: 400px' |
|
1871 | + * 'validate_func' => // validate function, string optional |
|
1872 | + * @param $repeater bool is this a field inside a repeatr? true|false(default) |
|
1873 | + */ |
|
1874 | + public function addWysiwyg($id, $args, $repeater = false) |
|
1875 | + { |
|
1876 | + $new_field = array('type' => 'wysiwyg', 'id' => $id, 'std' => '', 'desc' => '', 'style' => 'width: 300px; height: 400px', 'name' => __('WYSIWYG Editor Field', 'geodirectory')); |
|
1877 | + $new_field = array_merge($new_field, $args); |
|
1878 | + if (false === $repeater) { |
|
1879 | + $this->_fields[] = $new_field; |
|
1880 | + } else { |
|
1881 | + return $new_field; |
|
1882 | + } |
|
1883 | + } |
|
1884 | + |
|
1885 | + /** |
|
1886 | + * Add Taxonomy Field to meta box |
|
1887 | + * @author Ohad Raz |
|
1888 | + * @since 1.0 |
|
1889 | + * @access public |
|
1890 | + * @param $id string field id, i.e. the meta key |
|
1891 | + * @param $options mixed|array options of taxonomy field |
|
1892 | + * 'taxonomy' => // taxonomy name can be category,post_tag or any custom taxonomy default is category |
|
1893 | + * 'type' => // how to show taxonomy? 'select' (default) or 'checkbox_list' |
|
1894 | + * 'args' => // arguments to query taxonomy, see http://goo.gl/uAANN default ('hide_empty' => false) |
|
1895 | + * @param $args mixed|array |
|
1896 | + * 'name' => // field name/label string optional |
|
1897 | + * 'desc' => // field description, string optional |
|
1898 | + * 'std' => // default value, string optional |
|
1899 | + * 'validate_func' => // validate function, string optional |
|
1900 | + * @param $repeater bool is this a field inside a repeatr? true|false(default) |
|
1901 | + */ |
|
1902 | + public function addTaxonomy($id, $options, $args, $repeater = false) |
|
1903 | + { |
|
1904 | + $q = array('hide_empty' => 0); |
|
1905 | + $tax = 'category'; |
|
1906 | + $type = 'select'; |
|
1907 | + $temp = array($tax, $type, $q); |
|
1908 | + $options = array_merge($temp, $options); |
|
1909 | + $new_field = array('type' => 'taxonomy', 'id' => $id, 'desc' => '', 'name' => __('Taxonomy Field', 'geodirectory'), 'options' => $options); |
|
1910 | + $new_field = array_merge($new_field, $args); |
|
1911 | + if (false === $repeater) { |
|
1912 | + $this->_fields[] = $new_field; |
|
1913 | + } else { |
|
1914 | + return $new_field; |
|
1915 | + } |
|
1916 | + } |
|
1917 | + |
|
1918 | + /** |
|
1919 | + * Add posts Field to meta box |
|
1920 | + * @author Ohad Raz |
|
1921 | + * @since 1.0 |
|
1922 | + * @access public |
|
1923 | + * @param $id string field id, i.e. the meta key |
|
1924 | + * @param $options mixed|array options of taxonomy field |
|
1925 | + * 'post_type' => // post type name, 'post' (default) 'page' or any custom post type |
|
1926 | + * 'type' => // how to show posts? 'select' (default) or 'checkbox_list' |
|
1927 | + * 'args' => // arguments to query posts, see http://goo.gl/is0yK default ('posts_per_page' => -1) |
|
1928 | + * @param $args mixed|array |
|
1929 | + * 'name' => // field name/label string optional |
|
1930 | + * 'desc' => // field description, string optional |
|
1931 | + * 'std' => // default value, string optional |
|
1932 | + * 'validate_func' => // validate function, string optional |
|
1933 | + * @param $repeater bool is this a field inside a repeatr? true|false(default) |
|
1934 | + */ |
|
1935 | + public function addPosts($id, $options, $args, $repeater = false) |
|
1936 | + { |
|
1937 | + $q = array('posts_per_page' => -1); |
|
1938 | + $temp = array('post_type' => 'post', 'type' => 'select', 'args' => $q); |
|
1939 | + $options = array_merge($temp, $options); |
|
1940 | + $new_field = array('type' => 'posts', 'id' => $id, 'desc' => '', 'name' => __('Posts Field', 'geodirectory'), 'options' => $options); |
|
1941 | + $new_field = array_merge($new_field, $args); |
|
1942 | + if (false === $repeater) { |
|
1943 | + $this->_fields[] = $new_field; |
|
1944 | + } else { |
|
1945 | + return $new_field; |
|
1946 | + } |
|
1947 | + } |
|
1948 | + |
|
1949 | + /** |
|
1950 | + * Add repeater Field Block to meta box |
|
1951 | + * @author Ohad Raz |
|
1952 | + * @since 1.0 |
|
1953 | + * @access public |
|
1954 | + * @param $id string field id, i.e. the meta key |
|
1955 | + * @param $args mixed|array |
|
1956 | + * 'name' => // field name/label string optional |
|
1957 | + * 'desc' => // field description, string optional |
|
1958 | + * 'std' => // default value, string optional |
|
1959 | + * 'style' => // custom style for field, string optional |
|
1960 | + * 'validate_func' => // validate function, string optional |
|
1961 | + * 'fields' => //fields to repeater |
|
1962 | + */ |
|
1963 | + public function addRepeaterBlock($id, $args) |
|
1964 | + { |
|
1965 | + $new_field = array('type' => 'repeater', 'id' => $id, 'name' => __('Reapeater Field', 'geodirectory'), 'fields' => array(), 'inline' => false); |
|
1966 | + $new_field = array_merge($new_field, $args); |
|
1967 | + $this->_fields[] = $new_field; |
|
1968 | + } |
|
1969 | + |
|
1970 | + |
|
1971 | + /** |
|
1972 | + * Finish Declaration of Meta Box |
|
1973 | + * @author Ohad Raz |
|
1974 | + * @since 1.0 |
|
1975 | + * @access public |
|
1976 | + */ |
|
1977 | + public function Finish() |
|
1978 | + { |
|
1979 | + $this->add_missed_values(); |
|
1980 | + $this->check_field_upload(); |
|
1981 | + $this->check_field_color(); |
|
1982 | + $this->check_field_date(); |
|
1983 | + $this->check_field_time(); |
|
1984 | + } |
|
1985 | + |
|
1986 | + /** |
|
1987 | + * Helper function to check for empty arrays |
|
1988 | + * @author Ohad Raz |
|
1989 | + * @since 1.0 |
|
1990 | + * @access public |
|
1991 | + * @param $args mixed|array |
|
1992 | + */ |
|
1993 | + public function is_array_empty($array) |
|
1994 | + { |
|
1995 | + if (!is_array($array)) |
|
1996 | + return true; |
|
1997 | + |
|
1998 | + foreach ($array as $a) { |
|
1999 | + if (is_array($a)) { |
|
2000 | + foreach ($a as $sub_a) { |
|
2001 | + if (!empty($sub_a) && $sub_a != '') |
|
2002 | + return false; |
|
2003 | + } |
|
2004 | + } else { |
|
2005 | + if (!empty($a) && $a != '') |
|
2006 | + return false; |
|
2007 | + } |
|
2008 | + } |
|
2009 | + return true; |
|
2010 | + } |
|
2011 | + |
|
2012 | + |
|
2013 | + //get term meta field |
|
2014 | + public function get_tax_meta($term_id, $key, $multi = false, $post_type = '') |
|
2015 | + { |
|
2016 | + |
|
2017 | + if (empty($post_type) && isset($_REQUEST['taxonomy'])) { |
|
2018 | + $taxObject = get_taxonomy($_REQUEST['taxonomy']); |
|
2019 | + $post_type = $taxObject->object_type[0]; |
|
2020 | + } |
|
2021 | + |
|
2022 | + if($post_type=='post'){$post_type='';} |
|
2023 | + if($post_type){$post_type = $post_type.'_';} |
|
2024 | + |
|
2025 | + $t_id = (is_object($term_id)) ? $term_id->term_id : $term_id; |
|
2026 | + |
|
2027 | + $m = get_option('tax_meta_' . $post_type . $t_id); |
|
2028 | + if (isset($m[$key])) { |
|
2029 | + return $m[$key]; |
|
2030 | + } else { |
|
2031 | + return ''; |
|
2032 | + } |
|
2033 | + } |
|
2034 | + |
|
2035 | + //delete meta |
|
2036 | + public function delete_tax_meta($term_id, $key, $post_type = '') |
|
2037 | + { |
|
2038 | + |
|
2039 | + if (empty($post_type) && isset($_REQUEST['taxonomy'])) { |
|
2040 | + $taxObject = get_taxonomy($_REQUEST['taxonomy']); |
|
2041 | + $post_type = $taxObject->object_type[0]; |
|
2042 | + } |
|
2043 | + |
|
2044 | + if($post_type=='post'){$post_type='';} |
|
2045 | + if($post_type){$post_type = $post_type.'_';} |
|
2046 | + |
|
2047 | + $m = get_option('tax_meta_' . $post_type . $term_id); |
|
2048 | + |
|
2049 | + if (isset($m[$key])) { |
|
2050 | + unset($m[$key]); |
|
2051 | + } |
|
2052 | + update_option('tax_meta_' . $post_type . $term_id, $m); |
|
2053 | + } |
|
2054 | + |
|
2055 | + //update meta |
|
2056 | + public function update_tax_meta($term_id, $key, $value, $post_type = '') |
|
2057 | + { |
|
2058 | + |
|
2059 | + if (empty($post_type) && isset($_REQUEST['taxonomy'])) { |
|
2060 | + $taxObject = get_taxonomy($_REQUEST['taxonomy']); |
|
2061 | + $post_type = $taxObject->object_type[0]; |
|
2062 | + } |
|
2063 | + |
|
2064 | + if($post_type=='post'){$post_type='';} |
|
2065 | + if($post_type){$post_type = $post_type.'_';} |
|
2066 | + |
|
2067 | + $m = get_option('tax_meta_' . $post_type . $term_id); |
|
2068 | + |
|
2069 | + $m[$key] = $value; |
|
2070 | + update_option('tax_meta_' . $post_type . $term_id, $m); |
|
2071 | + |
|
2072 | + /** |
|
2073 | + * Called after the tax meta is updated. |
|
2074 | + * |
|
2075 | + * Used to update things after a GD category is saved. |
|
2076 | + * |
|
2077 | + * @since 1.0.0 |
|
2078 | + * @param bool $false False. |
|
2079 | + * @param bool $true True. |
|
2080 | + * @param int $term_id The term id being updated. |
|
2081 | + * @param string $post_type The post type of the cat being updated. |
|
2082 | + */ |
|
2083 | + do_action('gd_tax_meta_updated', false, true, $term_id, $post_type); |
|
2084 | + } |
|
2085 | + |
|
2086 | + |
|
2087 | + } // End Class |
|
2088 | 2088 | |
2089 | 2089 | endif; // End Check Class Exists |
2090 | 2090 | |
@@ -2094,67 +2094,67 @@ discard block |
||
2094 | 2094 | |
2095 | 2095 | //get term meta field |
2096 | 2096 | if (!function_exists('get_tax_meta')) { |
2097 | - function get_tax_meta($term_id, $key, $multi = false, $post_type = '') |
|
2098 | - { |
|
2099 | - |
|
2100 | - if (empty($post_type) && isset($_REQUEST['taxonomy'])) { |
|
2101 | - $taxObject = get_taxonomy($_REQUEST['taxonomy']); |
|
2102 | - $post_type = $taxObject->object_type[0]; |
|
2103 | - } |
|
2104 | - |
|
2105 | - if($post_type=='post'){$post_type='';} |
|
2106 | - if($post_type){$post_type = $post_type.'_';} |
|
2107 | - |
|
2108 | - $t_id = (is_object($term_id)) ? $term_id->term_id : $term_id; |
|
2109 | - |
|
2110 | - $m = get_option('tax_meta_' . $post_type . $t_id); |
|
2111 | - if (isset($m[$key])) { |
|
2112 | - return $m[$key]; |
|
2113 | - } else { |
|
2114 | - return ''; |
|
2115 | - } |
|
2116 | - } |
|
2097 | + function get_tax_meta($term_id, $key, $multi = false, $post_type = '') |
|
2098 | + { |
|
2099 | + |
|
2100 | + if (empty($post_type) && isset($_REQUEST['taxonomy'])) { |
|
2101 | + $taxObject = get_taxonomy($_REQUEST['taxonomy']); |
|
2102 | + $post_type = $taxObject->object_type[0]; |
|
2103 | + } |
|
2104 | + |
|
2105 | + if($post_type=='post'){$post_type='';} |
|
2106 | + if($post_type){$post_type = $post_type.'_';} |
|
2107 | + |
|
2108 | + $t_id = (is_object($term_id)) ? $term_id->term_id : $term_id; |
|
2109 | + |
|
2110 | + $m = get_option('tax_meta_' . $post_type . $t_id); |
|
2111 | + if (isset($m[$key])) { |
|
2112 | + return $m[$key]; |
|
2113 | + } else { |
|
2114 | + return ''; |
|
2115 | + } |
|
2116 | + } |
|
2117 | 2117 | } |
2118 | 2118 | |
2119 | 2119 | //delete meta |
2120 | 2120 | if (!function_exists('delete_tax_meta')) { |
2121 | - function delete_tax_meta($term_id, $key) |
|
2122 | - { |
|
2121 | + function delete_tax_meta($term_id, $key) |
|
2122 | + { |
|
2123 | 2123 | |
2124 | - $taxObject = get_taxonomy($_REQUEST['taxonomy']); |
|
2125 | - $post_type = $taxObject->object_type[0]; |
|
2124 | + $taxObject = get_taxonomy($_REQUEST['taxonomy']); |
|
2125 | + $post_type = $taxObject->object_type[0]; |
|
2126 | 2126 | |
2127 | - if($post_type=='post'){$post_type='';} |
|
2128 | - if($post_type){$post_type = $post_type.'_';} |
|
2127 | + if($post_type=='post'){$post_type='';} |
|
2128 | + if($post_type){$post_type = $post_type.'_';} |
|
2129 | 2129 | |
2130 | - $m = get_option('tax_meta_' . $post_type . $term_id); |
|
2130 | + $m = get_option('tax_meta_' . $post_type . $term_id); |
|
2131 | 2131 | |
2132 | - if (isset($m[$key])) { |
|
2133 | - unset($m[$key]); |
|
2134 | - } |
|
2135 | - update_option('tax_meta_' . $post_type . $term_id, $m); |
|
2136 | - } |
|
2132 | + if (isset($m[$key])) { |
|
2133 | + unset($m[$key]); |
|
2134 | + } |
|
2135 | + update_option('tax_meta_' . $post_type . $term_id, $m); |
|
2136 | + } |
|
2137 | 2137 | } |
2138 | 2138 | |
2139 | 2139 | //update meta |
2140 | 2140 | if (!function_exists('update_tax_meta')) { |
2141 | - function update_tax_meta($term_id, $key, $value, $post_type = '') |
|
2142 | - { |
|
2141 | + function update_tax_meta($term_id, $key, $value, $post_type = '') |
|
2142 | + { |
|
2143 | 2143 | |
2144 | - if (empty($post_type) && isset($_REQUEST['taxonomy'])) { |
|
2145 | - $taxObject = get_taxonomy($_REQUEST['taxonomy']); |
|
2146 | - $post_type = $taxObject->object_type[0]; |
|
2147 | - } |
|
2144 | + if (empty($post_type) && isset($_REQUEST['taxonomy'])) { |
|
2145 | + $taxObject = get_taxonomy($_REQUEST['taxonomy']); |
|
2146 | + $post_type = $taxObject->object_type[0]; |
|
2147 | + } |
|
2148 | 2148 | |
2149 | - if($post_type=='post'){$post_type='';} |
|
2150 | - if($post_type){$post_type = $post_type.'_';} |
|
2149 | + if($post_type=='post'){$post_type='';} |
|
2150 | + if($post_type){$post_type = $post_type.'_';} |
|
2151 | 2151 | |
2152 | - $m = get_option('tax_meta_' . $post_type . $term_id); |
|
2152 | + $m = get_option('tax_meta_' . $post_type . $term_id); |
|
2153 | 2153 | |
2154 | - $m[$key] = $value; |
|
2155 | - update_option('tax_meta_' . $post_type . $term_id, $m); |
|
2154 | + $m[$key] = $value; |
|
2155 | + update_option('tax_meta_' . $post_type . $term_id, $m); |
|
2156 | 2156 | |
2157 | - /** This action is documented in geodirectory-functions/cat-meta-functions/Tax-meta-class.php */ |
|
2158 | - do_action('gd_tax_meta_updated', false, true, $term_id, $post_type); |
|
2159 | - } |
|
2157 | + /** This action is documented in geodirectory-functions/cat-meta-functions/Tax-meta-class.php */ |
|
2158 | + do_action('gd_tax_meta_updated', false, true, $term_id, $post_type); |
|
2159 | + } |
|
2160 | 2160 | } |
2161 | 2161 | \ No newline at end of file |
@@ -11,142 +11,142 @@ discard block |
||
11 | 11 | //include the main class file |
12 | 12 | require_once("Tax-meta-class.php"); |
13 | 13 | if (is_admin()) { |
14 | - /* |
|
14 | + /* |
|
15 | 15 | * prefix of meta keys, optional |
16 | 16 | * use underscore (_) at the beginning to make keys hidden, for example $prefix = '_ba_'; |
17 | 17 | * you also can make prefix empty to disable it |
18 | 18 | * |
19 | 19 | */ |
20 | 20 | |
21 | - $prefix = 'ct_'; |
|
22 | - /* |
|
21 | + $prefix = 'ct_'; |
|
22 | + /* |
|
23 | 23 | * configure your meta box |
24 | 24 | */ |
25 | 25 | |
26 | - $config = array( |
|
27 | - 'id' => 'demo_meta_box', // meta box id, unique per meta box |
|
28 | - 'title' => __('Demo Meta Box', 'geodirectory'), // meta box title |
|
29 | - 'pages' => geodir_get_taxonomies(), // taxonomy name, accept categories, post_tag and custom taxonomies |
|
30 | - 'context' => 'normal', // where the meta box appear: normal (default), advanced, side; optional |
|
31 | - 'fields' => array(), // list of meta fields (can be added by field arrays) |
|
32 | - 'local_images' => false, // Use local or hosted images (meta box images for add/remove) |
|
33 | - 'use_with_theme' => true //change path if used with theme set to true, false for a plugin or anything else for a custom path(default false). |
|
34 | - ); |
|
26 | + $config = array( |
|
27 | + 'id' => 'demo_meta_box', // meta box id, unique per meta box |
|
28 | + 'title' => __('Demo Meta Box', 'geodirectory'), // meta box title |
|
29 | + 'pages' => geodir_get_taxonomies(), // taxonomy name, accept categories, post_tag and custom taxonomies |
|
30 | + 'context' => 'normal', // where the meta box appear: normal (default), advanced, side; optional |
|
31 | + 'fields' => array(), // list of meta fields (can be added by field arrays) |
|
32 | + 'local_images' => false, // Use local or hosted images (meta box images for add/remove) |
|
33 | + 'use_with_theme' => true //change path if used with theme set to true, false for a plugin or anything else for a custom path(default false). |
|
34 | + ); |
|
35 | 35 | |
36 | 36 | |
37 | - /* |
|
37 | + /* |
|
38 | 38 | * Initiate your meta box |
39 | 39 | */ |
40 | - $my_meta = new Tax_Meta_Class($config); |
|
41 | - $my_meta->addWysiwyg($prefix . 'cat_top_desc', array('name' => __('Category Top Description', 'geodirectory'), 'desc' => __('This will appear at the top of the category listing.', 'geodirectory'))); |
|
42 | - $my_meta->addImage($prefix . 'cat_default_img', array('name' => __('Default Listing Image', 'geodirectory'), 'desc' => __('Choose a default "no image"', 'geodirectory'))); |
|
43 | - $my_meta->addImage($prefix . 'cat_icon', array('name' => __('Category Icon', 'geodirectory'), 'desc' => __('Choose a category icon', 'geodirectory'), 'validate_func' => '!empty')); |
|
44 | - /*$my_meta->addCheckbox($prefix.'pointless',array('name'=> __('<b>Exclude</b> Rating sort option','geodirectory'),'style'=>'hidden'));*/// hidden setting to trick WPML |
|
45 | - |
|
46 | - $my_meta->addSelect($prefix . 'cat_schema', |
|
47 | - /* |
|
40 | + $my_meta = new Tax_Meta_Class($config); |
|
41 | + $my_meta->addWysiwyg($prefix . 'cat_top_desc', array('name' => __('Category Top Description', 'geodirectory'), 'desc' => __('This will appear at the top of the category listing.', 'geodirectory'))); |
|
42 | + $my_meta->addImage($prefix . 'cat_default_img', array('name' => __('Default Listing Image', 'geodirectory'), 'desc' => __('Choose a default "no image"', 'geodirectory'))); |
|
43 | + $my_meta->addImage($prefix . 'cat_icon', array('name' => __('Category Icon', 'geodirectory'), 'desc' => __('Choose a category icon', 'geodirectory'), 'validate_func' => '!empty')); |
|
44 | + /*$my_meta->addCheckbox($prefix.'pointless',array('name'=> __('<b>Exclude</b> Rating sort option','geodirectory'),'style'=>'hidden'));*/// hidden setting to trick WPML |
|
45 | + |
|
46 | + $my_meta->addSelect($prefix . 'cat_schema', |
|
47 | + /* |
|
48 | 48 | * Allows you to add/filter the cat schema types. |
49 | 49 | * |
50 | 50 | * @since 1.5.7 |
51 | 51 | */ |
52 | - apply_filters('geodir_cat_schemas',array( |
|
53 | - '' => __('Default (LocalBusiness)', 'geodirectory'), |
|
54 | - 'AccountingService' => 'AccountingService', |
|
55 | - 'Attorney' => 'Attorney', |
|
56 | - 'AutoBodyShop' => 'AutoBodyShop', |
|
57 | - 'AutoDealer' => 'AutoDealer', |
|
58 | - 'AutoPartsStore' => 'AutoPartsStore', |
|
59 | - 'AutoRental' => 'AutoRental', |
|
60 | - 'AutoRepair' => 'AutoRepair', |
|
61 | - 'AutoWash' => 'AutoWash', |
|
62 | - 'Bakery' => 'Bakery', |
|
63 | - 'BarOrPub' => 'BarOrPub', |
|
64 | - 'BeautySalon' => 'BeautySalon', |
|
65 | - 'BedAndBreakfast' => 'BedAndBreakfast', |
|
66 | - 'BikeStore' => 'BikeStore', |
|
67 | - 'BookStore' => 'BookStore', |
|
68 | - 'CafeOrCoffeeShop' => 'CafeOrCoffeeShop', |
|
69 | - 'Campground' => 'Campground', |
|
70 | - 'ChildCare' => 'ChildCare', |
|
71 | - 'ClothingStore' => 'ClothingStore', |
|
72 | - 'ComputerStore' => 'ComputerStore', |
|
73 | - 'DaySpa' => 'DaySpa', |
|
74 | - 'Dentist' => 'Dentist', |
|
75 | - 'DryCleaningOrLaundry' => 'DryCleaningOrLaundry', |
|
76 | - 'Electrician' => 'Electrician', |
|
77 | - 'ElectronicsStore' => 'ElectronicsStore', |
|
78 | - 'EmergencyService' => 'EmergencyService', |
|
79 | - 'EntertainmentBusiness' => 'EntertainmentBusiness', |
|
80 | - 'Event' => 'Event', |
|
81 | - 'EventVenue' => 'EventVenue', |
|
82 | - 'ExerciseGym' => 'ExerciseGym', |
|
83 | - 'FinancialService' => 'FinancialService', |
|
84 | - 'Florist' => 'Florist', |
|
85 | - 'FoodEstablishment' => 'FoodEstablishment', |
|
86 | - 'FurnitureStore' => 'FurnitureStore', |
|
87 | - 'GardenStore' => 'GardenStore', |
|
88 | - 'GeneralContractor' => 'GeneralContractor', |
|
89 | - 'GolfCourse' => 'GolfCourse', |
|
90 | - 'HairSalon' => 'HairSalon', |
|
91 | - 'HardwareStore' => 'HardwareStore', |
|
92 | - 'HealthAndBeautyBusiness' => 'HealthAndBeautyBusiness', |
|
93 | - 'HobbyShop' => 'HobbyShop', |
|
94 | - 'HomeAndConstructionBusiness' => 'HomeAndConstructionBusiness', |
|
95 | - 'HomeGoodsStore' => 'HomeGoodsStore', |
|
96 | - 'Hospital' => 'Hospital', |
|
97 | - 'Hostel' => 'Hostel', |
|
98 | - 'Hotel' => 'Hotel', |
|
99 | - 'HousePainter' => 'HousePainter', |
|
100 | - 'HVACBusiness' => 'HVACBusiness', |
|
101 | - 'InsuranceAgency' => 'InsuranceAgency', |
|
102 | - 'JewelryStore' => 'JewelryStore', |
|
103 | - 'LiquorStore' => 'LiquorStore', |
|
104 | - 'Locksmith' => 'Locksmith', |
|
105 | - 'LodgingBusiness' => 'LodgingBusiness', |
|
106 | - 'MedicalClinic' => 'MedicalClinic', |
|
107 | - 'MensClothingStore' => 'MensClothingStore', |
|
108 | - 'MobilePhoneStore' => 'MobilePhoneStore', |
|
109 | - 'Motel' => 'Motel', |
|
110 | - 'MotorcycleDealer' => 'MotorcycleDealer', |
|
111 | - 'MotorcycleRepair' => 'MotorcycleRepair', |
|
112 | - 'MovingCompany' => 'MovingCompany', |
|
113 | - 'MusicStore' => 'MusicStore', |
|
114 | - 'NailSalon' => 'NailSalon', |
|
115 | - 'NightClub' => 'NightClub', |
|
116 | - 'Notary' => 'Notary', |
|
117 | - 'OfficeEquipmentStore' => 'OfficeEquipmentStore', |
|
118 | - 'Optician' => 'Optician', |
|
119 | - 'PetStore' => 'PetStore', |
|
120 | - 'Physician' => 'Physician', |
|
121 | - 'Plumber' => 'Plumber', |
|
122 | - 'ProfessionalService' => 'ProfessionalService', |
|
123 | - 'RealEstateAgent' => 'RealEstateAgent', |
|
124 | - 'Residence' => 'Residence', |
|
125 | - 'Restaurant' => 'Restaurant', |
|
126 | - 'RoofingContractor' => 'RoofingContractor', |
|
127 | - 'RVPark' => 'RVPark', |
|
128 | - 'School' => 'School', |
|
129 | - 'SelfStorage' => 'SelfStorage', |
|
130 | - 'ShoeStore' => 'ShoeStore', |
|
131 | - 'SkiResort' => 'SkiResort', |
|
132 | - 'SportingGoodsStore' => 'SportingGoodsStore', |
|
133 | - 'SportsClub' => 'SportsClub', |
|
134 | - 'Store' => 'Store', |
|
135 | - 'TattooParlor' => 'TattooParlor', |
|
136 | - 'Taxi' => 'Taxi', |
|
137 | - 'TennisComplex' => 'TennisComplex', |
|
138 | - 'TireShop' => 'TireShop', |
|
139 | - 'TouristAttraction' => 'TouristAttraction', |
|
140 | - 'ToyStore' => 'ToyStore', |
|
141 | - 'TravelAgency' => 'TravelAgency', |
|
142 | - //'VacationRentals' => 'VacationRentals', // Not recognised by google yet |
|
143 | - 'VeterinaryCare' => 'VeterinaryCare', |
|
144 | - 'WholesaleStore' => 'WholesaleStore', |
|
145 | - 'Winery' => 'Winery' |
|
146 | - )), |
|
147 | - array('name' => __('Schema Type', 'geodirectory'), 'desc' => __('Select the Schema to use for this category', 'geodirectory') . "", 'std' => array('selectkey2'))); |
|
148 | - |
|
149 | - /*$my_meta->addSelect($prefix.'cat_sort',array(''=>__('Default' , 'geodirectory'), |
|
52 | + apply_filters('geodir_cat_schemas',array( |
|
53 | + '' => __('Default (LocalBusiness)', 'geodirectory'), |
|
54 | + 'AccountingService' => 'AccountingService', |
|
55 | + 'Attorney' => 'Attorney', |
|
56 | + 'AutoBodyShop' => 'AutoBodyShop', |
|
57 | + 'AutoDealer' => 'AutoDealer', |
|
58 | + 'AutoPartsStore' => 'AutoPartsStore', |
|
59 | + 'AutoRental' => 'AutoRental', |
|
60 | + 'AutoRepair' => 'AutoRepair', |
|
61 | + 'AutoWash' => 'AutoWash', |
|
62 | + 'Bakery' => 'Bakery', |
|
63 | + 'BarOrPub' => 'BarOrPub', |
|
64 | + 'BeautySalon' => 'BeautySalon', |
|
65 | + 'BedAndBreakfast' => 'BedAndBreakfast', |
|
66 | + 'BikeStore' => 'BikeStore', |
|
67 | + 'BookStore' => 'BookStore', |
|
68 | + 'CafeOrCoffeeShop' => 'CafeOrCoffeeShop', |
|
69 | + 'Campground' => 'Campground', |
|
70 | + 'ChildCare' => 'ChildCare', |
|
71 | + 'ClothingStore' => 'ClothingStore', |
|
72 | + 'ComputerStore' => 'ComputerStore', |
|
73 | + 'DaySpa' => 'DaySpa', |
|
74 | + 'Dentist' => 'Dentist', |
|
75 | + 'DryCleaningOrLaundry' => 'DryCleaningOrLaundry', |
|
76 | + 'Electrician' => 'Electrician', |
|
77 | + 'ElectronicsStore' => 'ElectronicsStore', |
|
78 | + 'EmergencyService' => 'EmergencyService', |
|
79 | + 'EntertainmentBusiness' => 'EntertainmentBusiness', |
|
80 | + 'Event' => 'Event', |
|
81 | + 'EventVenue' => 'EventVenue', |
|
82 | + 'ExerciseGym' => 'ExerciseGym', |
|
83 | + 'FinancialService' => 'FinancialService', |
|
84 | + 'Florist' => 'Florist', |
|
85 | + 'FoodEstablishment' => 'FoodEstablishment', |
|
86 | + 'FurnitureStore' => 'FurnitureStore', |
|
87 | + 'GardenStore' => 'GardenStore', |
|
88 | + 'GeneralContractor' => 'GeneralContractor', |
|
89 | + 'GolfCourse' => 'GolfCourse', |
|
90 | + 'HairSalon' => 'HairSalon', |
|
91 | + 'HardwareStore' => 'HardwareStore', |
|
92 | + 'HealthAndBeautyBusiness' => 'HealthAndBeautyBusiness', |
|
93 | + 'HobbyShop' => 'HobbyShop', |
|
94 | + 'HomeAndConstructionBusiness' => 'HomeAndConstructionBusiness', |
|
95 | + 'HomeGoodsStore' => 'HomeGoodsStore', |
|
96 | + 'Hospital' => 'Hospital', |
|
97 | + 'Hostel' => 'Hostel', |
|
98 | + 'Hotel' => 'Hotel', |
|
99 | + 'HousePainter' => 'HousePainter', |
|
100 | + 'HVACBusiness' => 'HVACBusiness', |
|
101 | + 'InsuranceAgency' => 'InsuranceAgency', |
|
102 | + 'JewelryStore' => 'JewelryStore', |
|
103 | + 'LiquorStore' => 'LiquorStore', |
|
104 | + 'Locksmith' => 'Locksmith', |
|
105 | + 'LodgingBusiness' => 'LodgingBusiness', |
|
106 | + 'MedicalClinic' => 'MedicalClinic', |
|
107 | + 'MensClothingStore' => 'MensClothingStore', |
|
108 | + 'MobilePhoneStore' => 'MobilePhoneStore', |
|
109 | + 'Motel' => 'Motel', |
|
110 | + 'MotorcycleDealer' => 'MotorcycleDealer', |
|
111 | + 'MotorcycleRepair' => 'MotorcycleRepair', |
|
112 | + 'MovingCompany' => 'MovingCompany', |
|
113 | + 'MusicStore' => 'MusicStore', |
|
114 | + 'NailSalon' => 'NailSalon', |
|
115 | + 'NightClub' => 'NightClub', |
|
116 | + 'Notary' => 'Notary', |
|
117 | + 'OfficeEquipmentStore' => 'OfficeEquipmentStore', |
|
118 | + 'Optician' => 'Optician', |
|
119 | + 'PetStore' => 'PetStore', |
|
120 | + 'Physician' => 'Physician', |
|
121 | + 'Plumber' => 'Plumber', |
|
122 | + 'ProfessionalService' => 'ProfessionalService', |
|
123 | + 'RealEstateAgent' => 'RealEstateAgent', |
|
124 | + 'Residence' => 'Residence', |
|
125 | + 'Restaurant' => 'Restaurant', |
|
126 | + 'RoofingContractor' => 'RoofingContractor', |
|
127 | + 'RVPark' => 'RVPark', |
|
128 | + 'School' => 'School', |
|
129 | + 'SelfStorage' => 'SelfStorage', |
|
130 | + 'ShoeStore' => 'ShoeStore', |
|
131 | + 'SkiResort' => 'SkiResort', |
|
132 | + 'SportingGoodsStore' => 'SportingGoodsStore', |
|
133 | + 'SportsClub' => 'SportsClub', |
|
134 | + 'Store' => 'Store', |
|
135 | + 'TattooParlor' => 'TattooParlor', |
|
136 | + 'Taxi' => 'Taxi', |
|
137 | + 'TennisComplex' => 'TennisComplex', |
|
138 | + 'TireShop' => 'TireShop', |
|
139 | + 'TouristAttraction' => 'TouristAttraction', |
|
140 | + 'ToyStore' => 'ToyStore', |
|
141 | + 'TravelAgency' => 'TravelAgency', |
|
142 | + //'VacationRentals' => 'VacationRentals', // Not recognised by google yet |
|
143 | + 'VeterinaryCare' => 'VeterinaryCare', |
|
144 | + 'WholesaleStore' => 'WholesaleStore', |
|
145 | + 'Winery' => 'Winery' |
|
146 | + )), |
|
147 | + array('name' => __('Schema Type', 'geodirectory'), 'desc' => __('Select the Schema to use for this category', 'geodirectory') . "", 'std' => array('selectkey2'))); |
|
148 | + |
|
149 | + /*$my_meta->addSelect($prefix.'cat_sort',array(''=>__('Default' , 'geodirectory'), |
|
150 | 150 | 'random'=>__('Random','geodirectory'), |
151 | 151 | 'az'=>__('Alphabetical' , 'geodirectory'), |
152 | 152 | 'newest'=>__('Newest','geodirectory'), |
@@ -157,8 +157,8 @@ discard block |
||
157 | 157 | 'low_review'=>__('Lowest Reviews','geodirectory')), |
158 | 158 | array('name'=> __('Sort By','geodirectory'),'desc' => __('Select the default sort option.' ,'geodirectory'), 'std'=> array('selectkey2')));*/ |
159 | 159 | |
160 | - // Show options for placecategories only |
|
161 | - /* if(isset($_REQUEST['taxonomy']) && in_array($_REQUEST['taxonomy'],$config['pages']) ){ |
|
160 | + // Show options for placecategories only |
|
161 | + /* if(isset($_REQUEST['taxonomy']) && in_array($_REQUEST['taxonomy'],$config['pages']) ){ |
|
162 | 162 | // Exclude sort options |
163 | 163 | $my_meta->addCheckbox($prefix.'cat_exclude_rating',array('name'=> __('<b>Exclude</b> Rating sort option','geodirectory'))); |
164 | 164 | $my_meta->addCheckbox($prefix.'cat_exclude_reviews',array('name'=> __('<b>Exclude</b> Reviews sort option','geodirectory'))); |
@@ -170,8 +170,8 @@ discard block |
||
170 | 170 | |
171 | 171 | }*/ |
172 | 172 | |
173 | - //Finish Meta Box Declaration |
|
174 | - $my_meta->Finish(); |
|
173 | + //Finish Meta Box Declaration |
|
174 | + $my_meta->Finish(); |
|
175 | 175 | } |
176 | 176 | |
177 | 177 | |
@@ -180,87 +180,87 @@ discard block |
||
180 | 180 | ############################################################## |
181 | 181 | $gd_taxonomies = geodir_get_taxonomies(); |
182 | 182 | if (!empty($gd_taxonomies)) { |
183 | - foreach ($gd_taxonomies as $gd_taxonomy) { |
|
183 | + foreach ($gd_taxonomies as $gd_taxonomy) { |
|
184 | 184 | |
185 | - add_filter('manage_edit-' . $gd_taxonomy . '_columns', 'addCat_column', 10, 2); |
|
186 | - add_action('manage_' . $gd_taxonomy . '_custom_column', 'manage_category_custom_fields', 10, 3); |
|
185 | + add_filter('manage_edit-' . $gd_taxonomy . '_columns', 'addCat_column', 10, 2); |
|
186 | + add_action('manage_' . $gd_taxonomy . '_custom_column', 'manage_category_custom_fields', 10, 3); |
|
187 | 187 | |
188 | - } |
|
188 | + } |
|
189 | 189 | } |
190 | 190 | |
191 | 191 | function addCat_column($columns) |
192 | 192 | { |
193 | - if (isset($columns['description']) && $posts = $columns['description']) { |
|
194 | - unset($columns['description']); |
|
195 | - } |
|
196 | - |
|
197 | - $columns['cat_icon'] = 'Icon'; |
|
198 | - $columns['cat_default_img'] = __('Default Image', 'geodirectory'); |
|
199 | - $columns['cat_ID_num'] = __('Cat ID', 'geodirectory'); |
|
200 | - return $columns; |
|
193 | + if (isset($columns['description']) && $posts = $columns['description']) { |
|
194 | + unset($columns['description']); |
|
195 | + } |
|
196 | + |
|
197 | + $columns['cat_icon'] = 'Icon'; |
|
198 | + $columns['cat_default_img'] = __('Default Image', 'geodirectory'); |
|
199 | + $columns['cat_ID_num'] = __('Cat ID', 'geodirectory'); |
|
200 | + return $columns; |
|
201 | 201 | } |
202 | 202 | |
203 | 203 | ############################################################# |
204 | 204 | function manage_category_custom_fields($deprecated, $column_name, $term_id) |
205 | 205 | { |
206 | - if ($column_name == 'cat_ID_num') |
|
207 | - echo $term_id; |
|
206 | + if ($column_name == 'cat_ID_num') |
|
207 | + echo $term_id; |
|
208 | 208 | |
209 | - if ($column_name == 'cat_icon') { |
|
210 | - $term_icon_url = get_tax_meta($term_id, 'ct_cat_icon'); |
|
209 | + if ($column_name == 'cat_icon') { |
|
210 | + $term_icon_url = get_tax_meta($term_id, 'ct_cat_icon'); |
|
211 | 211 | |
212 | - if ($term_icon_url != '') { |
|
213 | - $file_info = pathinfo($term_icon_url['src']); |
|
212 | + if ($term_icon_url != '') { |
|
213 | + $file_info = pathinfo($term_icon_url['src']); |
|
214 | 214 | |
215 | - if (isset($file_info['dirname'] ) && $file_info['dirname'] != '.' && $file_info['dirname'] != '..') { |
|
216 | - $sub_dir = $file_info['dirname']; |
|
217 | - } else { |
|
218 | - $sub_dir = ''; |
|
219 | - } |
|
215 | + if (isset($file_info['dirname'] ) && $file_info['dirname'] != '.' && $file_info['dirname'] != '..') { |
|
216 | + $sub_dir = $file_info['dirname']; |
|
217 | + } else { |
|
218 | + $sub_dir = ''; |
|
219 | + } |
|
220 | 220 | |
221 | - $uploads = wp_upload_dir(trim($sub_dir, '/')); // Array of key => value pairs |
|
222 | - $uploads_baseurl = $uploads['baseurl']; |
|
223 | - $uploads_path = $uploads['path']; |
|
221 | + $uploads = wp_upload_dir(trim($sub_dir, '/')); // Array of key => value pairs |
|
222 | + $uploads_baseurl = $uploads['baseurl']; |
|
223 | + $uploads_path = $uploads['path']; |
|
224 | 224 | |
225 | - $file_name = $file_info['basename']; |
|
225 | + $file_name = $file_info['basename']; |
|
226 | 226 | |
227 | - if (strpos($sub_dir, 'https://') !== false) { |
|
228 | - $uploads['baseurl'] = str_replace('http://', 'https://', $uploads['baseurl']); |
|
229 | - } else { |
|
230 | - $uploads['baseurl'] = str_replace('https://', 'http://', $uploads['baseurl']); |
|
231 | - } |
|
232 | - $sub_dir = str_replace($uploads['baseurl'], '', $sub_dir); |
|
227 | + if (strpos($sub_dir, 'https://') !== false) { |
|
228 | + $uploads['baseurl'] = str_replace('http://', 'https://', $uploads['baseurl']); |
|
229 | + } else { |
|
230 | + $uploads['baseurl'] = str_replace('https://', 'http://', $uploads['baseurl']); |
|
231 | + } |
|
232 | + $sub_dir = str_replace($uploads['baseurl'], '', $sub_dir); |
|
233 | 233 | |
234 | - $uploads_url = $uploads_baseurl . $sub_dir; |
|
234 | + $uploads_url = $uploads_baseurl . $sub_dir; |
|
235 | 235 | |
236 | - $term_icon_url['src'] = $uploads_url . '/' . $file_name; |
|
237 | - echo '<img src="' . $term_icon_url['src'] . '" />'; |
|
238 | - } |
|
239 | - } |
|
236 | + $term_icon_url['src'] = $uploads_url . '/' . $file_name; |
|
237 | + echo '<img src="' . $term_icon_url['src'] . '" />'; |
|
238 | + } |
|
239 | + } |
|
240 | 240 | |
241 | - if ($column_name == 'cat_default_img') { |
|
242 | - $cat_default_img = get_tax_meta($term_id, 'ct_cat_default_img'); |
|
243 | - if ($cat_default_img != '') |
|
244 | - echo '<img src="' . $cat_default_img['src'] . '" style="max-height:60px;max-width:60px;"/>'; |
|
241 | + if ($column_name == 'cat_default_img') { |
|
242 | + $cat_default_img = get_tax_meta($term_id, 'ct_cat_default_img'); |
|
243 | + if ($cat_default_img != '') |
|
244 | + echo '<img src="' . $cat_default_img['src'] . '" style="max-height:60px;max-width:60px;"/>'; |
|
245 | 245 | |
246 | - } |
|
246 | + } |
|
247 | 247 | } |
248 | 248 | |
249 | 249 | function geodir_get_default_catimage($term_id, $post_type = 'gd_place') |
250 | 250 | { |
251 | 251 | |
252 | - if ($cat_default_img = get_tax_meta($term_id, 'ct_cat_default_img', '', $post_type)) |
|
253 | - return $cat_default_img; |
|
254 | - else |
|
255 | - return false; |
|
252 | + if ($cat_default_img = get_tax_meta($term_id, 'ct_cat_default_img', '', $post_type)) |
|
253 | + return $cat_default_img; |
|
254 | + else |
|
255 | + return false; |
|
256 | 256 | } |
257 | 257 | |
258 | 258 | //Clear custom fields |
259 | 259 | add_action('in_admin_footer', 'geodir_tax_meta_clear_custom_field'); |
260 | 260 | function geodir_tax_meta_clear_custom_field() |
261 | 261 | { |
262 | - if (isset($_REQUEST['taxonomy']) && !empty($_REQUEST['taxonomy'])): |
|
263 | - ?> |
|
262 | + if (isset($_REQUEST['taxonomy']) && !empty($_REQUEST['taxonomy'])): |
|
263 | + ?> |
|
264 | 264 | <script type="text/javascript"> |
265 | 265 | jQuery(document).ready(function () { |
266 | 266 | jQuery('#addtag #submit').click(function () { |
@@ -281,5 +281,5 @@ discard block |
||
281 | 281 | }); |
282 | 282 | </script> |
283 | 283 | <?php |
284 | - endif; |
|
284 | + endif; |
|
285 | 285 | } |
@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | |
10 | 10 | // If this file is called directly, abort. |
11 | 11 | if (!defined('WPINC')) { |
12 | - die; |
|
12 | + die; |
|
13 | 13 | } |
14 | 14 | |
15 | 15 | /** |
@@ -22,22 +22,22 @@ discard block |
||
22 | 22 | */ |
23 | 23 | function gdsc_validate_measurements($value) |
24 | 24 | { |
25 | - if ((strlen($value) - 1) == strpos(trim($value), '%')) { |
|
26 | - // $value is entered as a percent, so it can't be less than 0 or more than 100 |
|
27 | - $value = preg_replace('/\D/', '', $value); |
|
28 | - if (100 < $value) { |
|
29 | - $value = 100; |
|
30 | - } |
|
31 | - // Re-add the percent symbol |
|
32 | - $value = $value . '%'; |
|
33 | - } elseif ((strlen($value) - 2) == strpos(trim($value), 'px')) { |
|
34 | - // Get the absint & re-add the 'px' |
|
35 | - $value = preg_replace('/\D/', '', $value) . 'px'; |
|
36 | - } else { |
|
37 | - $value = preg_replace('/\D/', '', $value); |
|
38 | - } |
|
25 | + if ((strlen($value) - 1) == strpos(trim($value), '%')) { |
|
26 | + // $value is entered as a percent, so it can't be less than 0 or more than 100 |
|
27 | + $value = preg_replace('/\D/', '', $value); |
|
28 | + if (100 < $value) { |
|
29 | + $value = 100; |
|
30 | + } |
|
31 | + // Re-add the percent symbol |
|
32 | + $value = $value . '%'; |
|
33 | + } elseif ((strlen($value) - 2) == strpos(trim($value), 'px')) { |
|
34 | + // Get the absint & re-add the 'px' |
|
35 | + $value = preg_replace('/\D/', '', $value) . 'px'; |
|
36 | + } else { |
|
37 | + $value = preg_replace('/\D/', '', $value); |
|
38 | + } |
|
39 | 39 | |
40 | - return $value; |
|
40 | + return $value; |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | /** |
@@ -52,35 +52,35 @@ discard block |
||
52 | 52 | function gdsc_validate_map_args($params) |
53 | 53 | { |
54 | 54 | |
55 | - $params['width'] = gdsc_validate_measurements($params['width']); |
|
56 | - $params['height'] = gdsc_validate_measurements($params['height']); |
|
55 | + $params['width'] = gdsc_validate_measurements($params['width']); |
|
56 | + $params['height'] = gdsc_validate_measurements($params['height']); |
|
57 | 57 | |
58 | - // Only accept our 4 maptypes. Otherwise, revert to the default. |
|
59 | - if (!(in_array(geodir_strtoupper($params['maptype']), array('HYBRID', 'SATELLITE', 'ROADMAP', 'TERRAIN')))) { |
|
60 | - $params['maptype'] = 'ROADMAP'; |
|
61 | - } else { |
|
62 | - $params['maptype'] = geodir_strtoupper($params['maptype']); |
|
63 | - } |
|
58 | + // Only accept our 4 maptypes. Otherwise, revert to the default. |
|
59 | + if (!(in_array(geodir_strtoupper($params['maptype']), array('HYBRID', 'SATELLITE', 'ROADMAP', 'TERRAIN')))) { |
|
60 | + $params['maptype'] = 'ROADMAP'; |
|
61 | + } else { |
|
62 | + $params['maptype'] = geodir_strtoupper($params['maptype']); |
|
63 | + } |
|
64 | 64 | |
65 | - // Zoom accepts a value between 1 and 19 |
|
66 | - $params['zoom'] = absint($params['zoom']); |
|
67 | - if (19 < $params['zoom']) { |
|
68 | - $params['zoom'] = '19'; |
|
69 | - } |
|
70 | - if (0 == $params['zoom']) { |
|
71 | - $params['zoom'] = '1'; |
|
72 | - } |
|
65 | + // Zoom accepts a value between 1 and 19 |
|
66 | + $params['zoom'] = absint($params['zoom']); |
|
67 | + if (19 < $params['zoom']) { |
|
68 | + $params['zoom'] = '19'; |
|
69 | + } |
|
70 | + if (0 == $params['zoom']) { |
|
71 | + $params['zoom'] = '1'; |
|
72 | + } |
|
73 | 73 | |
74 | - // Child_collapse must be boolean |
|
75 | - $params['child_collapse'] = gdsc_to_bool_val($params['child_collapse']); |
|
74 | + // Child_collapse must be boolean |
|
75 | + $params['child_collapse'] = gdsc_to_bool_val($params['child_collapse']); |
|
76 | 76 | |
77 | - // Scrollwheel must be boolean |
|
78 | - $params['scrollwheel'] = gdsc_to_bool_val($params['scrollwheel']); |
|
77 | + // Scrollwheel must be boolean |
|
78 | + $params['scrollwheel'] = gdsc_to_bool_val($params['scrollwheel']); |
|
79 | 79 | |
80 | - // Scrollwheel must be boolean |
|
81 | - $params['autozoom'] = gdsc_to_bool_val($params['autozoom']); |
|
80 | + // Scrollwheel must be boolean |
|
81 | + $params['autozoom'] = gdsc_to_bool_val($params['autozoom']); |
|
82 | 82 | |
83 | - return $params; |
|
83 | + return $params; |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | /** |
@@ -99,52 +99,52 @@ discard block |
||
99 | 99 | */ |
100 | 100 | function gdsc_to_bool_val($in, $strict = false) |
101 | 101 | { |
102 | - $out = null; |
|
103 | - |
|
104 | - // if not strict, we only have to check if something is false |
|
105 | - if (in_array($in, array( |
|
106 | - 'false', |
|
107 | - 'False', |
|
108 | - 'FALSE', |
|
109 | - 'no', |
|
110 | - 'No', |
|
111 | - 'n', |
|
112 | - 'N', |
|
113 | - '0', |
|
114 | - 'off', |
|
115 | - 'Off', |
|
116 | - 'OFF', |
|
117 | - false, |
|
118 | - 0, |
|
119 | - null |
|
120 | - ), true)) { |
|
121 | - $out = false; |
|
122 | - } else if ($strict) { |
|
123 | - // if strict, check the equivalent true values |
|
124 | - if (in_array($in, array( |
|
125 | - 'true', |
|
126 | - 'True', |
|
127 | - 'TRUE', |
|
128 | - 'yes', |
|
129 | - 'Yes', |
|
130 | - 'y', |
|
131 | - 'Y', |
|
132 | - '1', |
|
133 | - 'on', |
|
134 | - 'On', |
|
135 | - 'ON', |
|
136 | - true, |
|
137 | - 1 |
|
138 | - ), true)) { |
|
139 | - $out = true; |
|
140 | - } |
|
141 | - } else { |
|
142 | - // not strict? let the regular php bool check figure it out (will |
|
143 | - // largely default to true) |
|
144 | - $out = ($in ? true : false); |
|
145 | - } |
|
102 | + $out = null; |
|
103 | + |
|
104 | + // if not strict, we only have to check if something is false |
|
105 | + if (in_array($in, array( |
|
106 | + 'false', |
|
107 | + 'False', |
|
108 | + 'FALSE', |
|
109 | + 'no', |
|
110 | + 'No', |
|
111 | + 'n', |
|
112 | + 'N', |
|
113 | + '0', |
|
114 | + 'off', |
|
115 | + 'Off', |
|
116 | + 'OFF', |
|
117 | + false, |
|
118 | + 0, |
|
119 | + null |
|
120 | + ), true)) { |
|
121 | + $out = false; |
|
122 | + } else if ($strict) { |
|
123 | + // if strict, check the equivalent true values |
|
124 | + if (in_array($in, array( |
|
125 | + 'true', |
|
126 | + 'True', |
|
127 | + 'TRUE', |
|
128 | + 'yes', |
|
129 | + 'Yes', |
|
130 | + 'y', |
|
131 | + 'Y', |
|
132 | + '1', |
|
133 | + 'on', |
|
134 | + 'On', |
|
135 | + 'ON', |
|
136 | + true, |
|
137 | + 1 |
|
138 | + ), true)) { |
|
139 | + $out = true; |
|
140 | + } |
|
141 | + } else { |
|
142 | + // not strict? let the regular php bool check figure it out (will |
|
143 | + // largely default to true) |
|
144 | + $out = ($in ? true : false); |
|
145 | + } |
|
146 | 146 | |
147 | - return $out; |
|
147 | + return $out; |
|
148 | 148 | } |
149 | 149 | |
150 | 150 | /** |
@@ -157,16 +157,16 @@ discard block |
||
157 | 157 | */ |
158 | 158 | function gdsc_is_post_type_valid($incoming_post_type) |
159 | 159 | { |
160 | - $post_types = geodir_get_posttypes(); |
|
161 | - $post_types = array_map('geodir_strtolower', $post_types); |
|
162 | - $post_type_found = false; |
|
163 | - foreach ($post_types as $type) { |
|
164 | - if (geodir_strtolower($incoming_post_type) == geodir_strtolower($type)) { |
|
165 | - $post_type_found = true; |
|
166 | - } |
|
167 | - } |
|
160 | + $post_types = geodir_get_posttypes(); |
|
161 | + $post_types = array_map('geodir_strtolower', $post_types); |
|
162 | + $post_type_found = false; |
|
163 | + foreach ($post_types as $type) { |
|
164 | + if (geodir_strtolower($incoming_post_type) == geodir_strtolower($type)) { |
|
165 | + $post_type_found = true; |
|
166 | + } |
|
167 | + } |
|
168 | 168 | |
169 | - return $post_type_found; |
|
169 | + return $post_type_found; |
|
170 | 170 | } |
171 | 171 | |
172 | 172 | /** |
@@ -186,52 +186,52 @@ discard block |
||
186 | 186 | */ |
187 | 187 | function gdsc_listing_loop_filter($query) |
188 | 188 | { |
189 | - global $wp_query, $geodir_post_type, $table, $plugin_prefix, $term; |
|
190 | - |
|
191 | - $geodir_post_type = geodir_get_current_posttype(); |
|
192 | - |
|
193 | - if (isset($wp_query->tax_query->queries) && $wp_query->tax_query->queries) { |
|
194 | - $taxonomies = wp_list_pluck($wp_query->tax_query->queries, 'taxonomy'); |
|
195 | - |
|
196 | - if (isset($wp_query->query[$taxonomies[0]])) { |
|
197 | - $request_term = explode("/", $wp_query->query[$taxonomies[0]]); |
|
198 | - $request_term = end($request_term); |
|
199 | - if (!term_exists($request_term)) { |
|
200 | - $args = array('number' => '1',); |
|
201 | - $terms_arr = get_terms($taxonomies[0], $args); |
|
202 | - foreach ($terms_arr as $location_term) { |
|
203 | - $term_arr = $location_term; |
|
204 | - $term_arr->name = geodir_ucwords(str_replace('-', ' ', $request_term)); |
|
205 | - } |
|
206 | - $wp_query->queried_object_id = 1; |
|
207 | - $wp_query->queried_object = $term_arr; |
|
208 | - } |
|
209 | - } |
|
189 | + global $wp_query, $geodir_post_type, $table, $plugin_prefix, $term; |
|
190 | + |
|
191 | + $geodir_post_type = geodir_get_current_posttype(); |
|
192 | + |
|
193 | + if (isset($wp_query->tax_query->queries) && $wp_query->tax_query->queries) { |
|
194 | + $taxonomies = wp_list_pluck($wp_query->tax_query->queries, 'taxonomy'); |
|
195 | + |
|
196 | + if (isset($wp_query->query[$taxonomies[0]])) { |
|
197 | + $request_term = explode("/", $wp_query->query[$taxonomies[0]]); |
|
198 | + $request_term = end($request_term); |
|
199 | + if (!term_exists($request_term)) { |
|
200 | + $args = array('number' => '1',); |
|
201 | + $terms_arr = get_terms($taxonomies[0], $args); |
|
202 | + foreach ($terms_arr as $location_term) { |
|
203 | + $term_arr = $location_term; |
|
204 | + $term_arr->name = geodir_ucwords(str_replace('-', ' ', $request_term)); |
|
205 | + } |
|
206 | + $wp_query->queried_object_id = 1; |
|
207 | + $wp_query->queried_object = $term_arr; |
|
208 | + } |
|
209 | + } |
|
210 | 210 | |
211 | - } |
|
212 | - if (isset($query->query_vars['is_geodir_loop']) && $query->query_vars['is_geodir_loop']) { |
|
211 | + } |
|
212 | + if (isset($query->query_vars['is_geodir_loop']) && $query->query_vars['is_geodir_loop']) { |
|
213 | 213 | |
214 | - $table = $plugin_prefix . $geodir_post_type . '_detail'; |
|
214 | + $table = $plugin_prefix . $geodir_post_type . '_detail'; |
|
215 | 215 | |
216 | - add_filter('posts_fields', 'geodir_posts_fields', 1); |
|
217 | - add_filter('posts_join', 'geodir_posts_join', 1); |
|
218 | - geodir_post_where(); |
|
219 | - if (!is_admin()) { |
|
220 | - add_filter('posts_orderby', 'geodir_posts_orderby', 1); |
|
221 | - } |
|
216 | + add_filter('posts_fields', 'geodir_posts_fields', 1); |
|
217 | + add_filter('posts_join', 'geodir_posts_join', 1); |
|
218 | + geodir_post_where(); |
|
219 | + if (!is_admin()) { |
|
220 | + add_filter('posts_orderby', 'geodir_posts_orderby', 1); |
|
221 | + } |
|
222 | 222 | |
223 | - // advanced filter for popular post view widget |
|
224 | - global $wp_query; |
|
225 | - if (!is_admin()) { |
|
226 | - if (!empty($wp_query->query['with_pics_only'])) { |
|
227 | - add_filter('posts_join', 'geodir_filter_widget_join', 1000); |
|
228 | - } |
|
229 | - add_filter('posts_where', 'geodir_filter_widget_where', 1000); |
|
230 | - } |
|
223 | + // advanced filter for popular post view widget |
|
224 | + global $wp_query; |
|
225 | + if (!is_admin()) { |
|
226 | + if (!empty($wp_query->query['with_pics_only'])) { |
|
227 | + add_filter('posts_join', 'geodir_filter_widget_join', 1000); |
|
228 | + } |
|
229 | + add_filter('posts_where', 'geodir_filter_widget_where', 1000); |
|
230 | + } |
|
231 | 231 | |
232 | - } |
|
232 | + } |
|
233 | 233 | |
234 | - return $query; |
|
234 | + return $query; |
|
235 | 235 | } |
236 | 236 | |
237 | 237 | /** |
@@ -245,40 +245,40 @@ discard block |
||
245 | 245 | */ |
246 | 246 | function gdsc_manage_category_choice($post_type, $category) |
247 | 247 | { |
248 | - if (0 == $category || '' == $category) { |
|
249 | - return ''; |
|
250 | - } |
|
248 | + if (0 == $category || '' == $category) { |
|
249 | + return ''; |
|
250 | + } |
|
251 | 251 | |
252 | - if (!(gdsc_is_post_type_valid($post_type))) { |
|
253 | - return ''; |
|
254 | - } |
|
252 | + if (!(gdsc_is_post_type_valid($post_type))) { |
|
253 | + return ''; |
|
254 | + } |
|
255 | 255 | |
256 | - $taxonomies = geodir_get_taxonomies($post_type); |
|
256 | + $taxonomies = geodir_get_taxonomies($post_type); |
|
257 | 257 | |
258 | - $categories = get_terms(array('taxonomy' => $taxonomies[0])); |
|
258 | + $categories = get_terms(array('taxonomy' => $taxonomies[0])); |
|
259 | 259 | |
260 | - $cat_id = 0; |
|
260 | + $cat_id = 0; |
|
261 | 261 | |
262 | - foreach ($categories as $cat) { |
|
263 | - if (is_numeric($category)) { |
|
264 | - if (absint($category) == $cat->term_id) { |
|
265 | - $cat_id = $cat->term_id; |
|
266 | - break; |
|
267 | - } |
|
268 | - } else { |
|
269 | - if ($category == $cat->slug) { |
|
270 | - $cat_id = $cat->term_id; |
|
271 | - break; |
|
272 | - } |
|
262 | + foreach ($categories as $cat) { |
|
263 | + if (is_numeric($category)) { |
|
264 | + if (absint($category) == $cat->term_id) { |
|
265 | + $cat_id = $cat->term_id; |
|
266 | + break; |
|
267 | + } |
|
268 | + } else { |
|
269 | + if ($category == $cat->slug) { |
|
270 | + $cat_id = $cat->term_id; |
|
271 | + break; |
|
272 | + } |
|
273 | 273 | |
274 | - if ($category == $cat->name) { |
|
275 | - $cat_id = $cat->term_id; |
|
276 | - break; |
|
277 | - } |
|
278 | - } |
|
279 | - } |
|
274 | + if ($category == $cat->name) { |
|
275 | + $cat_id = $cat->term_id; |
|
276 | + break; |
|
277 | + } |
|
278 | + } |
|
279 | + } |
|
280 | 280 | |
281 | - return $cat_id; |
|
281 | + return $cat_id; |
|
282 | 282 | } |
283 | 283 | |
284 | 284 | // @todo: Extract this |
@@ -288,11 +288,11 @@ discard block |
||
288 | 288 | * Adds the script in the page footer for the home page google map. |
289 | 289 | * |
290 | 290 | * @since 1.0.0 |
291 | - * @return string Print the script in page footer. |
|
291 | + * @return string Print the script in page footer. |
|
292 | 292 | */ |
293 | 293 | function geodir_home_map_add_script() |
294 | - { |
|
295 | - ?> |
|
294 | + { |
|
295 | + ?> |
|
296 | 296 | <script type="text/javascript"> |
297 | 297 | jQuery(document).ready(function () { |
298 | 298 | geoDirMapSlide(); |
@@ -365,7 +365,7 @@ discard block |
||
365 | 365 | } |
366 | 366 | </script> |
367 | 367 | <?php |
368 | - } |
|
368 | + } |
|
369 | 369 | } |
370 | 370 | |
371 | 371 | /** |
@@ -376,7 +376,7 @@ discard block |
||
376 | 376 | */ |
377 | 377 | function geodir_popular_category_add_scripts() |
378 | 378 | { |
379 | - ?> |
|
379 | + ?> |
|
380 | 380 | <script type="text/javascript"> |
381 | 381 | jQuery(function ($) { |
382 | 382 | $('.geodir-showcat').click(function () { |
@@ -406,56 +406,56 @@ discard block |
||
406 | 406 | */ |
407 | 407 | function gdsc_validate_layout_choice($layout_choice) |
408 | 408 | { |
409 | - switch (geodir_strtolower($layout_choice)) { |
|
410 | - case 'list'; |
|
411 | - case 'one'; |
|
412 | - case 'one_column'; |
|
413 | - case 'onecolumn'; |
|
414 | - case '1'; |
|
415 | - $layout_choice = 'list'; |
|
416 | - break; |
|
417 | - case 'gridview_onehalf'; |
|
418 | - case 'two'; |
|
419 | - case 'two_column'; |
|
420 | - case 'two_columns'; |
|
421 | - case 'twocolumn'; |
|
422 | - case 'twocolumns'; |
|
423 | - case '2'; |
|
424 | - $layout_choice = 'gridview_onehalf'; |
|
425 | - break; |
|
426 | - case 'gridview_onethird'; |
|
427 | - case 'three'; |
|
428 | - case 'three_column'; |
|
429 | - case 'three_columns'; |
|
430 | - case 'threecolumn'; |
|
431 | - case 'threecolumns'; |
|
432 | - case '3'; |
|
433 | - $layout_choice = 'gridview_onethird'; |
|
434 | - break; |
|
435 | - case 'gridview_onefourth'; |
|
436 | - case 'four'; |
|
437 | - case 'four_column'; |
|
438 | - case 'four_columns'; |
|
439 | - case 'fourcolumn'; |
|
440 | - case 'fourcolumns'; |
|
441 | - case '4'; |
|
442 | - $layout_choice = 'gridview_onefourth'; |
|
443 | - break; |
|
444 | - case 'gridview_onefifth'; |
|
445 | - case 'five'; |
|
446 | - case 'five_column'; |
|
447 | - case 'five_columns'; |
|
448 | - case 'fivecolumn'; |
|
449 | - case 'fivecolumns'; |
|
450 | - case '5'; |
|
451 | - $layout_choice = 'gridview_onefifth'; |
|
452 | - break; |
|
453 | - default: |
|
454 | - $layout_choice = 'gridview_onehalf'; |
|
455 | - break; |
|
456 | - } |
|
409 | + switch (geodir_strtolower($layout_choice)) { |
|
410 | + case 'list'; |
|
411 | + case 'one'; |
|
412 | + case 'one_column'; |
|
413 | + case 'onecolumn'; |
|
414 | + case '1'; |
|
415 | + $layout_choice = 'list'; |
|
416 | + break; |
|
417 | + case 'gridview_onehalf'; |
|
418 | + case 'two'; |
|
419 | + case 'two_column'; |
|
420 | + case 'two_columns'; |
|
421 | + case 'twocolumn'; |
|
422 | + case 'twocolumns'; |
|
423 | + case '2'; |
|
424 | + $layout_choice = 'gridview_onehalf'; |
|
425 | + break; |
|
426 | + case 'gridview_onethird'; |
|
427 | + case 'three'; |
|
428 | + case 'three_column'; |
|
429 | + case 'three_columns'; |
|
430 | + case 'threecolumn'; |
|
431 | + case 'threecolumns'; |
|
432 | + case '3'; |
|
433 | + $layout_choice = 'gridview_onethird'; |
|
434 | + break; |
|
435 | + case 'gridview_onefourth'; |
|
436 | + case 'four'; |
|
437 | + case 'four_column'; |
|
438 | + case 'four_columns'; |
|
439 | + case 'fourcolumn'; |
|
440 | + case 'fourcolumns'; |
|
441 | + case '4'; |
|
442 | + $layout_choice = 'gridview_onefourth'; |
|
443 | + break; |
|
444 | + case 'gridview_onefifth'; |
|
445 | + case 'five'; |
|
446 | + case 'five_column'; |
|
447 | + case 'five_columns'; |
|
448 | + case 'fivecolumn'; |
|
449 | + case 'fivecolumns'; |
|
450 | + case '5'; |
|
451 | + $layout_choice = 'gridview_onefifth'; |
|
452 | + break; |
|
453 | + default: |
|
454 | + $layout_choice = 'gridview_onehalf'; |
|
455 | + break; |
|
456 | + } |
|
457 | 457 | |
458 | - return $layout_choice; |
|
458 | + return $layout_choice; |
|
459 | 459 | } |
460 | 460 | |
461 | 461 | /** |
@@ -472,34 +472,34 @@ discard block |
||
472 | 472 | */ |
473 | 473 | function gdsc_validate_sort_choice($sort_choice, $post_type = '') |
474 | 474 | { |
475 | - global $plugin_prefix; |
|
476 | - |
|
477 | - $sorts = array( |
|
478 | - 'az', |
|
479 | - 'latest', |
|
480 | - 'featured', |
|
481 | - 'high_review', |
|
482 | - 'high_rating', |
|
483 | - 'random', |
|
484 | - ); |
|
485 | - |
|
486 | - if (in_array($sort_choice, $sorts)) { |
|
487 | - return $sort_choice; |
|
488 | - } |
|
475 | + global $plugin_prefix; |
|
476 | + |
|
477 | + $sorts = array( |
|
478 | + 'az', |
|
479 | + 'latest', |
|
480 | + 'featured', |
|
481 | + 'high_review', |
|
482 | + 'high_rating', |
|
483 | + 'random', |
|
484 | + ); |
|
485 | + |
|
486 | + if (in_array($sort_choice, $sorts)) { |
|
487 | + return $sort_choice; |
|
488 | + } |
|
489 | 489 | |
490 | - if (!empty($post_type)) { |
|
491 | - $table = $plugin_prefix . $post_type . '_detail'; |
|
490 | + if (!empty($post_type)) { |
|
491 | + $table = $plugin_prefix . $post_type . '_detail'; |
|
492 | 492 | |
493 | - if (!geodir_prepare_custom_sorting($sort_choice, $table)) { |
|
494 | - $sort_choice = ''; |
|
495 | - } |
|
496 | - } |
|
493 | + if (!geodir_prepare_custom_sorting($sort_choice, $table)) { |
|
494 | + $sort_choice = ''; |
|
495 | + } |
|
496 | + } |
|
497 | 497 | |
498 | - if (empty($post_type) || empty($sort_choice)) { |
|
499 | - $sort_choice = 'latest'; |
|
500 | - } |
|
498 | + if (empty($post_type) || empty($sort_choice)) { |
|
499 | + $sort_choice = 'latest'; |
|
500 | + } |
|
501 | 501 | |
502 | - return $sort_choice; |
|
502 | + return $sort_choice; |
|
503 | 503 | } |
504 | 504 | |
505 | 505 | /** |
@@ -512,22 +512,22 @@ discard block |
||
512 | 512 | */ |
513 | 513 | function gdsc_validate_listing_width($width_choice) |
514 | 514 | { |
515 | - if (!(empty($width_choice))) { |
|
516 | - $width_choice = absint($width_choice); |
|
517 | - } else { |
|
518 | - return ''; |
|
519 | - } |
|
515 | + if (!(empty($width_choice))) { |
|
516 | + $width_choice = absint($width_choice); |
|
517 | + } else { |
|
518 | + return ''; |
|
519 | + } |
|
520 | 520 | |
521 | - if (100 < $width_choice) { |
|
522 | - $width_choice = 100; |
|
523 | - } |
|
521 | + if (100 < $width_choice) { |
|
522 | + $width_choice = 100; |
|
523 | + } |
|
524 | 524 | |
525 | - // If listing_width is too narrow, it won't work, arbitrarily set to 10% here |
|
526 | - if (10 > $width_choice) { |
|
527 | - $width_choice = 10; |
|
528 | - } |
|
525 | + // If listing_width is too narrow, it won't work, arbitrarily set to 10% here |
|
526 | + if (10 > $width_choice) { |
|
527 | + $width_choice = 10; |
|
528 | + } |
|
529 | 529 | |
530 | - return $width_choice; |
|
530 | + return $width_choice; |
|
531 | 531 | } |
532 | 532 | |
533 | 533 | /** |
@@ -540,18 +540,18 @@ discard block |
||
540 | 540 | */ |
541 | 541 | function gdsc_validate_list_filter_choice($filter_choice) |
542 | 542 | { |
543 | - $filters = array( |
|
544 | - 'all', |
|
545 | - 'today', |
|
546 | - 'upcoming', |
|
547 | - 'past', |
|
548 | - ); |
|
549 | - |
|
550 | - if (!(in_array($filter_choice, $filters))) { |
|
551 | - $filter_choice = 'all'; |
|
552 | - } |
|
543 | + $filters = array( |
|
544 | + 'all', |
|
545 | + 'today', |
|
546 | + 'upcoming', |
|
547 | + 'past', |
|
548 | + ); |
|
549 | + |
|
550 | + if (!(in_array($filter_choice, $filters))) { |
|
551 | + $filter_choice = 'all'; |
|
552 | + } |
|
553 | 553 | |
554 | - return $filter_choice; |
|
554 | + return $filter_choice; |
|
555 | 555 | } |
556 | 556 | |
557 | 557 | /** |
@@ -573,7 +573,7 @@ discard block |
||
573 | 573 | * @return string Listings HTML content. |
574 | 574 | */ |
575 | 575 | function geodir_sc_gd_listings_output($args = array()) { |
576 | - $title = !empty($args['title']) ? __($args['title'], 'geodirectory') : ''; |
|
576 | + $title = !empty($args['title']) ? __($args['title'], 'geodirectory') : ''; |
|
577 | 577 | $post_type = !empty($args['post_type']) ? $args['post_type'] : 'gd_place'; |
578 | 578 | $category = !empty($args['category']) ? $args['category'] : '0'; |
579 | 579 | $post_number = !empty($args['post_number']) ? $args['post_number'] : 10; |
@@ -583,17 +583,17 @@ discard block |
||
583 | 583 | $layout = !empty($args['layout']) ? $args['layout'] : 'gridview_onehalf'; |
584 | 584 | $with_pagination = !empty($args['with_pagination']) ? true : false; |
585 | 585 | $event_type = !empty($args['event_type']) ? $args['event_type'] : ''; |
586 | - $shortcode_content = !empty($args['shortcode_content']) ? trim($args['shortcode_content']) : ''; |
|
587 | - $tags = !empty($args['tags']) ? $args['tags'] : array(); |
|
588 | - /** |
|
589 | - * Filter the content text displayed when no listings found. |
|
590 | - * |
|
591 | - * @since 1.6.0 |
|
592 | - * |
|
593 | - * @param string $shortcode_content The shortcode content text. |
|
594 | - * @param array $args Array of arguements to filter listings. |
|
595 | - */ |
|
596 | - $shortcode_content = apply_filters('geodir_sc_gd_listings_not_found_content', $shortcode_content, $args); |
|
586 | + $shortcode_content = !empty($args['shortcode_content']) ? trim($args['shortcode_content']) : ''; |
|
587 | + $tags = !empty($args['tags']) ? $args['tags'] : array(); |
|
588 | + /** |
|
589 | + * Filter the content text displayed when no listings found. |
|
590 | + * |
|
591 | + * @since 1.6.0 |
|
592 | + * |
|
593 | + * @param string $shortcode_content The shortcode content text. |
|
594 | + * @param array $args Array of arguements to filter listings. |
|
595 | + */ |
|
596 | + $shortcode_content = apply_filters('geodir_sc_gd_listings_not_found_content', $shortcode_content, $args); |
|
597 | 597 | |
598 | 598 | $top_pagination = $with_pagination && !empty($args['top_pagination']) ? true : false; |
599 | 599 | $bottom_pagination = $with_pagination && !empty($args['bottom_pagination']) ? true : false; |
@@ -605,92 +605,92 @@ discard block |
||
605 | 605 | $pageno = $geodir_ajax && !empty($args['pageno']) ? $args['pageno'] : 1; |
606 | 606 | |
607 | 607 | $query_args = array( |
608 | - 'posts_per_page' => $post_number, |
|
609 | - 'is_geodir_loop' => true, |
|
610 | - 'gd_location' => $add_location_filter, |
|
611 | - 'post_type' => $post_type, |
|
612 | - 'order_by' => $list_sort, |
|
608 | + 'posts_per_page' => $post_number, |
|
609 | + 'is_geodir_loop' => true, |
|
610 | + 'gd_location' => $add_location_filter, |
|
611 | + 'post_type' => $post_type, |
|
612 | + 'order_by' => $list_sort, |
|
613 | 613 | 'pageno' => $pageno |
614 | - ); |
|
614 | + ); |
|
615 | 615 | |
616 | - if ($character_count >= 0) { |
|
617 | - $query_args['excerpt_length'] = $character_count; |
|
618 | - } |
|
616 | + if ($character_count >= 0) { |
|
617 | + $query_args['excerpt_length'] = $character_count; |
|
618 | + } |
|
619 | 619 | |
620 | - if (!empty($args['post_author'])) { |
|
621 | - $query_args['post_author'] = $args['post_author']; |
|
622 | - } |
|
620 | + if (!empty($args['post_author'])) { |
|
621 | + $query_args['post_author'] = $args['post_author']; |
|
622 | + } |
|
623 | 623 | |
624 | - if (!empty($args['show_featured_only'])) { |
|
625 | - $query_args['show_featured_only'] = 1; |
|
626 | - } |
|
624 | + if (!empty($args['show_featured_only'])) { |
|
625 | + $query_args['show_featured_only'] = 1; |
|
626 | + } |
|
627 | 627 | |
628 | - if (!empty($args['show_special_only'])) { |
|
629 | - $query_args['show_special_only'] = 1; |
|
630 | - } |
|
628 | + if (!empty($args['show_special_only'])) { |
|
629 | + $query_args['show_special_only'] = 1; |
|
630 | + } |
|
631 | 631 | |
632 | - if (!empty($args['with_pics_only'])) { |
|
633 | - $query_args['with_pics_only'] = 0; |
|
634 | - $query_args['featured_image_only'] = 1; |
|
635 | - } |
|
632 | + if (!empty($args['with_pics_only'])) { |
|
633 | + $query_args['with_pics_only'] = 0; |
|
634 | + $query_args['featured_image_only'] = 1; |
|
635 | + } |
|
636 | 636 | |
637 | - if (!empty($args['with_videos_only'])) { |
|
638 | - $query_args['with_videos_only'] = 1; |
|
639 | - } |
|
637 | + if (!empty($args['with_videos_only'])) { |
|
638 | + $query_args['with_videos_only'] = 1; |
|
639 | + } |
|
640 | 640 | |
641 | - if (!empty($args['show_favorites_only'])) { |
|
642 | - $query_args['show_favorites_only'] = 1; |
|
643 | - $query_args['favorites_by_user'] = !empty($args['favorites_by_user']) ? $args['favorites_by_user'] : 0; |
|
644 | - } |
|
645 | - $with_no_results = !empty($args['without_no_results']) ? false : true; |
|
641 | + if (!empty($args['show_favorites_only'])) { |
|
642 | + $query_args['show_favorites_only'] = 1; |
|
643 | + $query_args['favorites_by_user'] = !empty($args['favorites_by_user']) ? $args['favorites_by_user'] : 0; |
|
644 | + } |
|
645 | + $with_no_results = !empty($args['without_no_results']) ? false : true; |
|
646 | 646 | |
647 | - if (!empty($category) && isset($category[0]) && $category[0] != '0') { |
|
648 | - $category_taxonomy = geodir_get_taxonomies($post_type); |
|
647 | + if (!empty($category) && isset($category[0]) && $category[0] != '0') { |
|
648 | + $category_taxonomy = geodir_get_taxonomies($post_type); |
|
649 | 649 | |
650 | - ######### WPML ######### |
|
651 | - if (function_exists('icl_object_id')) { |
|
652 | - $category = gd_lang_object_ids($category, $category_taxonomy[0]); |
|
653 | - } |
|
654 | - ######### WPML ######### |
|
650 | + ######### WPML ######### |
|
651 | + if (function_exists('icl_object_id')) { |
|
652 | + $category = gd_lang_object_ids($category, $category_taxonomy[0]); |
|
653 | + } |
|
654 | + ######### WPML ######### |
|
655 | 655 | |
656 | - $tax_query = array( |
|
657 | - 'taxonomy' => $category_taxonomy[0], |
|
658 | - 'field' => 'id', |
|
659 | - 'terms' => $category |
|
660 | - ); |
|
656 | + $tax_query = array( |
|
657 | + 'taxonomy' => $category_taxonomy[0], |
|
658 | + 'field' => 'id', |
|
659 | + 'terms' => $category |
|
660 | + ); |
|
661 | 661 | |
662 | - $query_args['tax_query'] = array($tax_query); |
|
663 | - } |
|
662 | + $query_args['tax_query'] = array($tax_query); |
|
663 | + } |
|
664 | 664 | |
665 | - if (!empty($tags)) { |
|
666 | - // Clean tags |
|
667 | - if (!is_array($tags)) { |
|
668 | - $comma = _x(',', 'tag delimiter'); |
|
669 | - if ( ',' !== $comma ) { |
|
670 | - $tags = str_replace($comma, ',', $tags); |
|
671 | - } |
|
672 | - $tags = explode(',', trim($tags, " \n\t\r\0\x0B,")); |
|
673 | - $tags = array_map('trim', $tags); |
|
674 | - } |
|
665 | + if (!empty($tags)) { |
|
666 | + // Clean tags |
|
667 | + if (!is_array($tags)) { |
|
668 | + $comma = _x(',', 'tag delimiter'); |
|
669 | + if ( ',' !== $comma ) { |
|
670 | + $tags = str_replace($comma, ',', $tags); |
|
671 | + } |
|
672 | + $tags = explode(',', trim($tags, " \n\t\r\0\x0B,")); |
|
673 | + $tags = array_map('trim', $tags); |
|
674 | + } |
|
675 | 675 | |
676 | - if (!empty($tags)) { |
|
677 | - $tag_query = array( |
|
678 | - 'taxonomy' => $post_type . '_tags', |
|
679 | - 'field' => 'name', |
|
680 | - 'terms' => $tags |
|
681 | - ); |
|
682 | - |
|
683 | - if (!empty($query_args['tax_query'])) { |
|
684 | - $query_args['tax_query'][] = $tag_query; |
|
685 | - } else { |
|
686 | - $query_args['tax_query'] = array($tag_query); |
|
687 | - } |
|
688 | - } |
|
689 | - } |
|
676 | + if (!empty($tags)) { |
|
677 | + $tag_query = array( |
|
678 | + 'taxonomy' => $post_type . '_tags', |
|
679 | + 'field' => 'name', |
|
680 | + 'terms' => $tags |
|
681 | + ); |
|
682 | + |
|
683 | + if (!empty($query_args['tax_query'])) { |
|
684 | + $query_args['tax_query'][] = $tag_query; |
|
685 | + } else { |
|
686 | + $query_args['tax_query'] = array($tag_query); |
|
687 | + } |
|
688 | + } |
|
689 | + } |
|
690 | 690 | |
691 | - global $gridview_columns_widget, $geodir_is_widget_listing; |
|
691 | + global $gridview_columns_widget, $geodir_is_widget_listing; |
|
692 | 692 | |
693 | - if ($post_type == 'gd_event' && function_exists('geodir_event_get_widget_events')) { |
|
693 | + if ($post_type == 'gd_event' && function_exists('geodir_event_get_widget_events')) { |
|
694 | 694 | global $geodir_event_widget_listview; |
695 | 695 | $geodir_event_widget_listview = true; |
696 | 696 | |
@@ -705,16 +705,16 @@ discard block |
||
705 | 705 | $widget_listings = $total_posts > 0 ? geodir_get_widget_listings($query_args) : array(); |
706 | 706 | } |
707 | 707 | $current_gridview_columns_widget = $gridview_columns_widget; |
708 | - $identifier = ' gd-wgt-pagi-' . mt_rand(); |
|
709 | - ob_start(); |
|
708 | + $identifier = ' gd-wgt-pagi-' . mt_rand(); |
|
709 | + ob_start(); |
|
710 | 710 | if (!empty($widget_listings) || $with_no_results) { |
711 | 711 | if (!$geodir_ajax) { |
712 | - /** |
|
713 | - * Called before the shortcode [gd_listings] content is output. |
|
714 | - * |
|
715 | - * @since 1.0.0 |
|
716 | - */ |
|
717 | - do_action('geodir_before_sc_gd_listings'); |
|
712 | + /** |
|
713 | + * Called before the shortcode [gd_listings] content is output. |
|
714 | + * |
|
715 | + * @since 1.0.0 |
|
716 | + */ |
|
717 | + do_action('geodir_before_sc_gd_listings'); |
|
718 | 718 | ?> |
719 | 719 | <div class="geodir_locations geodir_location_listing geodir-sc-gd-listings <?php echo $identifier;?>"> |
720 | 720 | <?php if ($title != '') { ?> |
@@ -725,63 +725,63 @@ discard block |
||
725 | 725 | <div class="gd-sc-loader"> |
726 | 726 | <div class="gd-sc-content"> |
727 | 727 | <?php } |
728 | - if (!(empty($widget_listings) && !empty($shortcode_content))) { |
|
729 | - if (strstr($layout, 'gridview')) { |
|
730 | - $listing_view_exp = explode('_', $layout); |
|
731 | - $gridview_columns_widget = $layout; |
|
732 | - $layout = $listing_view_exp[0]; |
|
733 | - } else { |
|
734 | - $gridview_columns_widget = ''; |
|
735 | - } |
|
736 | - |
|
737 | - /** |
|
738 | - * Filter the widget listing listview template. |
|
739 | - * |
|
740 | - * @since 1.0.0 |
|
741 | - * |
|
742 | - * @param string The template file to display listing. |
|
743 | - */ |
|
744 | - $template = apply_filters("geodir_template_part-widget-listing-listview", geodir_locate_template('widget-listing-listview')); |
|
728 | + if (!(empty($widget_listings) && !empty($shortcode_content))) { |
|
729 | + if (strstr($layout, 'gridview')) { |
|
730 | + $listing_view_exp = explode('_', $layout); |
|
731 | + $gridview_columns_widget = $layout; |
|
732 | + $layout = $listing_view_exp[0]; |
|
733 | + } else { |
|
734 | + $gridview_columns_widget = ''; |
|
735 | + } |
|
736 | + |
|
737 | + /** |
|
738 | + * Filter the widget listing listview template. |
|
739 | + * |
|
740 | + * @since 1.0.0 |
|
741 | + * |
|
742 | + * @param string The template file to display listing. |
|
743 | + */ |
|
744 | + $template = apply_filters("geodir_template_part-widget-listing-listview", geodir_locate_template('widget-listing-listview')); |
|
745 | 745 | |
746 | - global $post, $map_jason, $map_canvas_arr, $gd_session; |
|
747 | - |
|
748 | - $current_post = $post; |
|
749 | - $current_map_jason = $map_jason; |
|
750 | - $current_map_canvas_arr = $map_canvas_arr; |
|
751 | - $geodir_is_widget_listing = true; |
|
752 | - $gd_session->un_set('gd_listing_view'); |
|
753 | - |
|
754 | - if ($with_pagination && $top_pagination) { |
|
755 | - echo geodir_sc_listings_pagination($total_posts, $post_number, $pageno); |
|
756 | - } |
|
757 | - |
|
758 | - /** |
|
759 | - * Includes listing listview template. |
|
760 | - * |
|
761 | - * @since 1.0.0 |
|
762 | - */ |
|
763 | - include($template); |
|
746 | + global $post, $map_jason, $map_canvas_arr, $gd_session; |
|
747 | + |
|
748 | + $current_post = $post; |
|
749 | + $current_map_jason = $map_jason; |
|
750 | + $current_map_canvas_arr = $map_canvas_arr; |
|
751 | + $geodir_is_widget_listing = true; |
|
752 | + $gd_session->un_set('gd_listing_view'); |
|
753 | + |
|
754 | + if ($with_pagination && $top_pagination) { |
|
755 | + echo geodir_sc_listings_pagination($total_posts, $post_number, $pageno); |
|
756 | + } |
|
757 | + |
|
758 | + /** |
|
759 | + * Includes listing listview template. |
|
760 | + * |
|
761 | + * @since 1.0.0 |
|
762 | + */ |
|
763 | + include($template); |
|
764 | 764 | |
765 | - if ($with_pagination && $bottom_pagination) { |
|
766 | - echo geodir_sc_listings_pagination($total_posts, $post_number, $pageno); |
|
767 | - } |
|
768 | - |
|
769 | - $geodir_is_widget_listing = false; |
|
770 | - |
|
771 | - $GLOBALS['post'] = $current_post; |
|
772 | - if (!empty($current_post)) { |
|
773 | - setup_postdata($current_post); |
|
774 | - } |
|
775 | - $map_jason = $current_map_jason; |
|
776 | - $map_canvas_arr = $current_map_canvas_arr; |
|
777 | - global $gridview_columns_widget; |
|
778 | - $gridview_columns_widget = $current_gridview_columns_widget; |
|
779 | - } else { |
|
780 | - echo $shortcode_content; |
|
781 | - } |
|
765 | + if ($with_pagination && $bottom_pagination) { |
|
766 | + echo geodir_sc_listings_pagination($total_posts, $post_number, $pageno); |
|
767 | + } |
|
768 | + |
|
769 | + $geodir_is_widget_listing = false; |
|
770 | + |
|
771 | + $GLOBALS['post'] = $current_post; |
|
772 | + if (!empty($current_post)) { |
|
773 | + setup_postdata($current_post); |
|
774 | + } |
|
775 | + $map_jason = $current_map_jason; |
|
776 | + $map_canvas_arr = $current_map_canvas_arr; |
|
777 | + global $gridview_columns_widget; |
|
778 | + $gridview_columns_widget = $current_gridview_columns_widget; |
|
779 | + } else { |
|
780 | + echo $shortcode_content; |
|
781 | + } |
|
782 | 782 | ?> |
783 | 783 | <?php |
784 | - if (!$geodir_ajax) { |
|
784 | + if (!$geodir_ajax) { |
|
785 | 785 | ?> |
786 | 786 | </div><p class="geodir-sclisting-loading" style="display:none;"><i class="fa fa-cog fa-spin"></i></p></div> |
787 | 787 | <script type="text/javascript"> |
@@ -819,10 +819,10 @@ discard block |
||
819 | 819 | loading.hide(); |
820 | 820 | jQuery(items).html(response); |
821 | 821 | <?php |
822 | - /** |
|
823 | - * if lazyload images enabled then refresh them once ajax page changed. |
|
824 | - */ |
|
825 | - if (get_option('geodir_lazy_load', 1)) { ?> |
|
822 | + /** |
|
823 | + * if lazyload images enabled then refresh them once ajax page changed. |
|
824 | + */ |
|
825 | + if (get_option('geodir_lazy_load', 1)) { ?> |
|
826 | 826 | geodir_init_lazy_load(); |
827 | 827 | <?php } ?> |
828 | 828 | } |
@@ -832,11 +832,11 @@ discard block |
||
832 | 832 | </div> |
833 | 833 | <?php } ?> |
834 | 834 | <?php |
835 | - } |
|
835 | + } |
|
836 | 836 | $output = ob_get_contents(); |
837 | - ob_end_clean(); |
|
837 | + ob_end_clean(); |
|
838 | 838 | |
839 | - return trim($output); |
|
839 | + return trim($output); |
|
840 | 840 | } |
841 | 841 | |
842 | 842 | /** |
@@ -863,15 +863,15 @@ discard block |
||
863 | 863 | * @return string Listings pagination HTML content. |
864 | 864 | */ |
865 | 865 | function geodir_sc_listings_pagination($total_posts, $posts_per_page, $pageno, $before = '', $after = '', $prelabel = '', $nxtlabel = '', $pages_to_show = 5, $always_show = false) { |
866 | - if (empty($prelabel)) { |
|
867 | - $prelabel = '<strong>«</strong>'; |
|
868 | - } |
|
866 | + if (empty($prelabel)) { |
|
867 | + $prelabel = '<strong>«</strong>'; |
|
868 | + } |
|
869 | 869 | |
870 | - if (empty($nxtlabel)) { |
|
871 | - $nxtlabel = '<strong>»</strong>'; |
|
872 | - } |
|
870 | + if (empty($nxtlabel)) { |
|
871 | + $nxtlabel = '<strong>»</strong>'; |
|
872 | + } |
|
873 | 873 | |
874 | - $half_pages_to_show = round($pages_to_show / 2); |
|
874 | + $half_pages_to_show = round($pages_to_show / 2); |
|
875 | 875 | |
876 | 876 | $numposts = $total_posts; |
877 | 877 | |
@@ -904,7 +904,7 @@ discard block |
||
904 | 904 | } |
905 | 905 | |
906 | 906 | if (($pageno - 1) > 0) { |
907 | - echo '<a class="gd-page-sc-prev gd-wgt-page" data-page="' . (int)($pageno - 1) . '" href="javascript:void(0);">' . $prelabel . '</a> '; |
|
907 | + echo '<a class="gd-page-sc-prev gd-wgt-page" data-page="' . (int)($pageno - 1) . '" href="javascript:void(0);">' . $prelabel . '</a> '; |
|
908 | 908 | } |
909 | 909 | |
910 | 910 | for ($i = $pageno - $half_pages_to_show; $i <= $pageno + $half_pages_to_show; $i++) { |
@@ -927,9 +927,9 @@ discard block |
||
927 | 927 | echo "</div> $after </div>"; |
928 | 928 | } |
929 | 929 | $output = ob_get_contents(); |
930 | - ob_end_clean(); |
|
930 | + ob_end_clean(); |
|
931 | 931 | |
932 | - return trim($output); |
|
932 | + return trim($output); |
|
933 | 933 | } |
934 | 934 | |
935 | 935 | /** |
@@ -940,10 +940,10 @@ discard block |
||
940 | 940 | * @return string Listings HTML content. |
941 | 941 | */ |
942 | 942 | function geodir_sclistings_callback() { |
943 | - check_ajax_referer('geodir-sclistings-nonce', 'geodir_sclistings_nonce'); |
|
944 | - //set variables |
|
945 | - $scatts = isset($_POST['scatts']) ? $_POST['scatts'] : NULL; |
|
946 | - $pageno = isset($_POST['pageno']) ? absint($_POST['pageno']) : 1; |
|
943 | + check_ajax_referer('geodir-sclistings-nonce', 'geodir_sclistings_nonce'); |
|
944 | + //set variables |
|
945 | + $scatts = isset($_POST['scatts']) ? $_POST['scatts'] : NULL; |
|
946 | + $pageno = isset($_POST['pageno']) ? absint($_POST['pageno']) : 1; |
|
947 | 947 | |
948 | 948 | $shortcode_atts = !empty($scatts) ? (array)json_decode(stripslashes_deep($scatts)) : NULL; |
949 | 949 | |
@@ -955,7 +955,7 @@ discard block |
||
955 | 955 | } else { |
956 | 956 | echo 0; |
957 | 957 | } |
958 | - wp_die(); |
|
958 | + wp_die(); |
|
959 | 959 | } |
960 | 960 | add_action('wp_ajax_geodir_sclistings', 'geodir_sclistings_callback'); |
961 | 961 | add_action('wp_ajax_nopriv_geodir_sclistings', 'geodir_sclistings_callback'); |
962 | 962 | \ No newline at end of file |
@@ -16,10 +16,10 @@ discard block |
||
16 | 16 | */ |
17 | 17 | function geodir_session_start() |
18 | 18 | { |
19 | - if (!session_id()) session_start(); |
|
20 | - global $geodir_add_location_url; |
|
19 | + if (!session_id()) session_start(); |
|
20 | + global $geodir_add_location_url; |
|
21 | 21 | |
22 | - $geodir_add_location_url = NULL; |
|
22 | + $geodir_add_location_url = NULL; |
|
23 | 23 | } |
24 | 24 | |
25 | 25 | /** |
@@ -33,18 +33,18 @@ discard block |
||
33 | 33 | */ |
34 | 34 | function geodir_modified_query($query) |
35 | 35 | { |
36 | - if ($query->is_main_query() && ( |
|
37 | - (geodir_is_page('add-listing') && isset($_REQUEST['pid']) && $_REQUEST['pid'] != '') |
|
38 | - || geodir_is_page('listing') |
|
39 | - || geodir_is_page('author') |
|
40 | - || geodir_is_page('search') |
|
41 | - || geodir_is_page('detail')) |
|
42 | - ) { |
|
43 | - |
|
44 | - $query->set('is_geodir_loop', true); |
|
45 | - } |
|
36 | + if ($query->is_main_query() && ( |
|
37 | + (geodir_is_page('add-listing') && isset($_REQUEST['pid']) && $_REQUEST['pid'] != '') |
|
38 | + || geodir_is_page('listing') |
|
39 | + || geodir_is_page('author') |
|
40 | + || geodir_is_page('search') |
|
41 | + || geodir_is_page('detail')) |
|
42 | + ) { |
|
43 | + |
|
44 | + $query->set('is_geodir_loop', true); |
|
45 | + } |
|
46 | 46 | |
47 | - return $query; |
|
47 | + return $query; |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | /** |
@@ -67,81 +67,81 @@ discard block |
||
67 | 67 | */ |
68 | 68 | function set_listing_request($query ) |
69 | 69 | { |
70 | - global $wp_query, $wpdb, $geodir_post_type, $table, $dist, $mylat, $mylon, $s, $snear, $s, $s_A, $s_SA; |
|
70 | + global $wp_query, $wpdb, $geodir_post_type, $table, $dist, $mylat, $mylon, $s, $snear, $s, $s_A, $s_SA; |
|
71 | 71 | |
72 | 72 | |
73 | - // fix woocommerce shop products filtered by language for GD + WPML + Woocommerce |
|
74 | - if (!geodir_is_geodir_page()) { |
|
75 | - return; |
|
76 | - } |
|
73 | + // fix woocommerce shop products filtered by language for GD + WPML + Woocommerce |
|
74 | + if (!geodir_is_geodir_page()) { |
|
75 | + return; |
|
76 | + } |
|
77 | 77 | |
78 | - /* remove all pre filters */ |
|
79 | - remove_all_filters('query'); |
|
80 | - remove_all_filters('posts_search'); |
|
81 | - remove_all_filters('posts_fields'); |
|
82 | - remove_all_filters('posts_join'); |
|
83 | - remove_all_filters('posts_orderby'); |
|
84 | - remove_all_filters('posts_where'); |
|
78 | + /* remove all pre filters */ |
|
79 | + remove_all_filters('query'); |
|
80 | + remove_all_filters('posts_search'); |
|
81 | + remove_all_filters('posts_fields'); |
|
82 | + remove_all_filters('posts_join'); |
|
83 | + remove_all_filters('posts_orderby'); |
|
84 | + remove_all_filters('posts_where'); |
|
85 | 85 | |
86 | 86 | |
87 | - if ((is_search() && isset($_REQUEST['geodir_search']) && $_REQUEST['geodir_search'] != '')): |
|
87 | + if ((is_search() && isset($_REQUEST['geodir_search']) && $_REQUEST['geodir_search'] != '')): |
|
88 | 88 | |
89 | - if (isset($_REQUEST['scat']) && $_REQUEST['scat'] == 'all') $_REQUEST['scat'] = ''; |
|
90 | - //if(isset($_REQUEST['s']) && $_REQUEST['s'] == '+') $_REQUEST['s'] = ''; |
|
89 | + if (isset($_REQUEST['scat']) && $_REQUEST['scat'] == 'all') $_REQUEST['scat'] = ''; |
|
90 | + //if(isset($_REQUEST['s']) && $_REQUEST['s'] == '+') $_REQUEST['s'] = ''; |
|
91 | 91 | |
92 | - if (isset($_REQUEST['sdist'])) { |
|
93 | - ($_REQUEST['sdist'] != '0' && $_REQUEST['sdist'] != '') ? $dist = esc_attr($_REQUEST['sdist']) : $dist = 25000; |
|
94 | - } elseif (get_option('geodir_search_dist') != '') { |
|
95 | - $dist = get_option('geodir_search_dist'); |
|
92 | + if (isset($_REQUEST['sdist'])) { |
|
93 | + ($_REQUEST['sdist'] != '0' && $_REQUEST['sdist'] != '') ? $dist = esc_attr($_REQUEST['sdist']) : $dist = 25000; |
|
94 | + } elseif (get_option('geodir_search_dist') != '') { |
|
95 | + $dist = get_option('geodir_search_dist'); |
|
96 | 96 | |
97 | - } else { |
|
98 | - $dist = 25000; |
|
99 | - } // Distance |
|
97 | + } else { |
|
98 | + $dist = 25000; |
|
99 | + } // Distance |
|
100 | 100 | |
101 | - if (isset($_REQUEST['sgeo_lat'])) { |
|
102 | - $mylat = (float)esc_attr($_REQUEST['sgeo_lat']); |
|
103 | - } else { |
|
104 | - $mylat = (float)geodir_get_current_city_lat(); |
|
105 | - } // Latitude |
|
101 | + if (isset($_REQUEST['sgeo_lat'])) { |
|
102 | + $mylat = (float)esc_attr($_REQUEST['sgeo_lat']); |
|
103 | + } else { |
|
104 | + $mylat = (float)geodir_get_current_city_lat(); |
|
105 | + } // Latitude |
|
106 | 106 | |
107 | - if (isset($_REQUEST['sgeo_lon'])) { |
|
108 | - $mylon = (float)esc_attr($_REQUEST['sgeo_lon']); |
|
109 | - } else { |
|
110 | - $mylon = (float)geodir_get_current_city_lng(); |
|
111 | - } // Distance |
|
107 | + if (isset($_REQUEST['sgeo_lon'])) { |
|
108 | + $mylon = (float)esc_attr($_REQUEST['sgeo_lon']); |
|
109 | + } else { |
|
110 | + $mylon = (float)geodir_get_current_city_lng(); |
|
111 | + } // Distance |
|
112 | 112 | |
113 | - if (isset($_REQUEST['snear'])) { |
|
114 | - $snear = trim(esc_attr($_REQUEST['snear'])); |
|
115 | - } |
|
113 | + if (isset($_REQUEST['snear'])) { |
|
114 | + $snear = trim(esc_attr($_REQUEST['snear'])); |
|
115 | + } |
|
116 | 116 | |
117 | - if (isset($_REQUEST['s'])) { |
|
118 | - $s = trim(esc_attr(wp_strip_all_tags($_REQUEST['s']))); |
|
119 | - } |
|
117 | + if (isset($_REQUEST['s'])) { |
|
118 | + $s = trim(esc_attr(wp_strip_all_tags($_REQUEST['s']))); |
|
119 | + } |
|
120 | 120 | |
121 | - if ($snear == 'NEAR ME') { |
|
122 | - $ip = $_SERVER['REMOTE_ADDR']; |
|
123 | - $addr_details = unserialize(file_get_contents('http://www.geoplugin.net/php.gp?ip=' . $ip)); |
|
124 | - $mylat = stripslashes(geodir_utf8_ucfirst($addr_details[geoplugin_latitude])); |
|
125 | - $mylon = stripslashes(geodir_utf8_ucfirst($addr_details[geoplugin_longitude])); |
|
126 | - } |
|
121 | + if ($snear == 'NEAR ME') { |
|
122 | + $ip = $_SERVER['REMOTE_ADDR']; |
|
123 | + $addr_details = unserialize(file_get_contents('http://www.geoplugin.net/php.gp?ip=' . $ip)); |
|
124 | + $mylat = stripslashes(geodir_utf8_ucfirst($addr_details[geoplugin_latitude])); |
|
125 | + $mylon = stripslashes(geodir_utf8_ucfirst($addr_details[geoplugin_longitude])); |
|
126 | + } |
|
127 | 127 | |
128 | 128 | |
129 | - if (strstr($s, ',')) { |
|
130 | - $s_AA = str_replace(" ", "", $s); |
|
131 | - $s_A = explode(",", $s_AA); |
|
132 | - $s_A = implode('","', $s_A); |
|
133 | - $s_A = '"' . $s_A . '"'; |
|
134 | - } else { |
|
135 | - $s_A = '"' . $s . '"'; |
|
136 | - } |
|
129 | + if (strstr($s, ',')) { |
|
130 | + $s_AA = str_replace(" ", "", $s); |
|
131 | + $s_A = explode(",", $s_AA); |
|
132 | + $s_A = implode('","', $s_A); |
|
133 | + $s_A = '"' . $s_A . '"'; |
|
134 | + } else { |
|
135 | + $s_A = '"' . $s . '"'; |
|
136 | + } |
|
137 | 137 | |
138 | - if (strstr($s, ' ')) { |
|
139 | - $s_SA = explode(" ", $s); |
|
140 | - } else { |
|
141 | - $s_SA = ''; |
|
142 | - } |
|
138 | + if (strstr($s, ' ')) { |
|
139 | + $s_SA = explode(" ", $s); |
|
140 | + } else { |
|
141 | + $s_SA = ''; |
|
142 | + } |
|
143 | 143 | |
144 | - endif; |
|
144 | + endif; |
|
145 | 145 | |
146 | 146 | |
147 | 147 | |
@@ -162,56 +162,56 @@ discard block |
||
162 | 162 | */ |
163 | 163 | function geodir_listing_loop_filter($query) |
164 | 164 | { |
165 | - global $wp_query, $geodir_post_type, $table, $plugin_prefix, $table, $term; |
|
165 | + global $wp_query, $geodir_post_type, $table, $plugin_prefix, $table, $term; |
|
166 | 166 | |
167 | - // fix wp_reset_query for popular post view widget |
|
168 | - if (!geodir_is_geodir_page()) { |
|
169 | - return; |
|
170 | - } |
|
167 | + // fix wp_reset_query for popular post view widget |
|
168 | + if (!geodir_is_geodir_page()) { |
|
169 | + return; |
|
170 | + } |
|
171 | 171 | |
172 | - $geodir_post_type = geodir_get_current_posttype(); |
|
173 | - |
|
174 | - if (isset($wp_query->tax_query->queries) && $wp_query->tax_query->queries) { |
|
175 | - $taxonomies = wp_list_pluck($wp_query->tax_query->queries, 'taxonomy'); |
|
176 | - |
|
177 | - if (isset($wp_query->query[$taxonomies[0]])) { |
|
178 | - $request_term = explode("/", $wp_query->query[$taxonomies[0]]); |
|
179 | - $request_term = end($request_term); |
|
180 | - if (!term_exists($request_term)) { |
|
181 | - $args = array('number' => '1',); |
|
182 | - $terms_arr = get_terms($taxonomies[0], $args); |
|
183 | - foreach ($terms_arr as $location_term) { |
|
184 | - $term_arr = $location_term; |
|
185 | - $term_arr->name = geodir_ucwords(str_replace('-', ' ', $request_term)); |
|
186 | - } |
|
187 | - $wp_query->queried_object_id = 1; |
|
188 | - $wp_query->queried_object = $term_arr; |
|
189 | - //print_r($wp_query) ; |
|
190 | - } |
|
191 | - } |
|
172 | + $geodir_post_type = geodir_get_current_posttype(); |
|
173 | + |
|
174 | + if (isset($wp_query->tax_query->queries) && $wp_query->tax_query->queries) { |
|
175 | + $taxonomies = wp_list_pluck($wp_query->tax_query->queries, 'taxonomy'); |
|
176 | + |
|
177 | + if (isset($wp_query->query[$taxonomies[0]])) { |
|
178 | + $request_term = explode("/", $wp_query->query[$taxonomies[0]]); |
|
179 | + $request_term = end($request_term); |
|
180 | + if (!term_exists($request_term)) { |
|
181 | + $args = array('number' => '1',); |
|
182 | + $terms_arr = get_terms($taxonomies[0], $args); |
|
183 | + foreach ($terms_arr as $location_term) { |
|
184 | + $term_arr = $location_term; |
|
185 | + $term_arr->name = geodir_ucwords(str_replace('-', ' ', $request_term)); |
|
186 | + } |
|
187 | + $wp_query->queried_object_id = 1; |
|
188 | + $wp_query->queried_object = $term_arr; |
|
189 | + //print_r($wp_query) ; |
|
190 | + } |
|
191 | + } |
|
192 | 192 | |
193 | - } |
|
194 | - if (isset($query->query_vars['is_geodir_loop']) && $query->query_vars['is_geodir_loop']) { |
|
195 | - |
|
196 | - $table = $plugin_prefix . $geodir_post_type . '_detail'; |
|
197 | - |
|
198 | - add_filter('posts_fields', 'geodir_posts_fields', 1); |
|
199 | - add_filter('posts_join', 'geodir_posts_join', 1); |
|
200 | - geodir_post_where(); |
|
201 | - if (!is_admin()) |
|
202 | - add_filter('posts_orderby', 'geodir_posts_orderby', 1); |
|
203 | - |
|
204 | - // advanced filter for popular post view widget |
|
205 | - global $wp_query; |
|
206 | - if (!is_admin()) { |
|
207 | - if (!empty($wp_query->query['with_pics_only'])) { |
|
208 | - add_filter('posts_join', 'geodir_filter_widget_join', 1000); |
|
209 | - } |
|
210 | - add_filter('posts_where', 'geodir_filter_widget_where', 1000); |
|
211 | - } |
|
193 | + } |
|
194 | + if (isset($query->query_vars['is_geodir_loop']) && $query->query_vars['is_geodir_loop']) { |
|
212 | 195 | |
213 | - } |
|
214 | - return $query; |
|
196 | + $table = $plugin_prefix . $geodir_post_type . '_detail'; |
|
197 | + |
|
198 | + add_filter('posts_fields', 'geodir_posts_fields', 1); |
|
199 | + add_filter('posts_join', 'geodir_posts_join', 1); |
|
200 | + geodir_post_where(); |
|
201 | + if (!is_admin()) |
|
202 | + add_filter('posts_orderby', 'geodir_posts_orderby', 1); |
|
203 | + |
|
204 | + // advanced filter for popular post view widget |
|
205 | + global $wp_query; |
|
206 | + if (!is_admin()) { |
|
207 | + if (!empty($wp_query->query['with_pics_only'])) { |
|
208 | + add_filter('posts_join', 'geodir_filter_widget_join', 1000); |
|
209 | + } |
|
210 | + add_filter('posts_where', 'geodir_filter_widget_where', 1000); |
|
211 | + } |
|
212 | + |
|
213 | + } |
|
214 | + return $query; |
|
215 | 215 | } |
216 | 216 | |
217 | 217 | |
@@ -230,67 +230,67 @@ discard block |
||
230 | 230 | * @return string Modified fields query string. |
231 | 231 | */ |
232 | 232 | function geodir_posts_fields($fields) { |
233 | - global $wp_query, $wpdb, $geodir_post_type, $table, $plugin_prefix, $dist, $mylat, $mylon, $snear, $gd_session; |
|
233 | + global $wp_query, $wpdb, $geodir_post_type, $table, $plugin_prefix, $dist, $mylat, $mylon, $snear, $gd_session; |
|
234 | 234 | |
235 | - // Filter-Location-Manager to add location table. |
|
236 | - $fields .= ", " . $table . ".* "; |
|
235 | + // Filter-Location-Manager to add location table. |
|
236 | + $fields .= ", " . $table . ".* "; |
|
237 | 237 | |
238 | 238 | if ($snear != '' || $gd_session->get('all_near_me')) { |
239 | - $DistanceRadius = geodir_getDistanceRadius(get_option('geodir_search_dist_1')); |
|
239 | + $DistanceRadius = geodir_getDistanceRadius(get_option('geodir_search_dist_1')); |
|
240 | 240 | |
241 | 241 | if ($gd_session->get('all_near_me')) { |
242 | - $mylat = $gd_session->get('user_lat'); |
|
243 | - $mylon = $gd_session->get('user_lon'); |
|
244 | - } |
|
245 | - |
|
246 | - $fields .= " , (" . $DistanceRadius . " * 2 * ASIN(SQRT( POWER(SIN((ABS($mylat) - ABS(" . $table . ".post_latitude)) * pi()/180 / 2), 2) +COS(ABS($mylat) * pi()/180) * COS( ABS(" . $table . ".post_latitude) * pi()/180) *POWER(SIN(($mylon - " . $table . ".post_longitude) * pi()/180 / 2), 2) )))as distance "; |
|
247 | - } |
|
248 | - |
|
249 | - global $s; |
|
250 | - if (is_search() && isset($_REQUEST['geodir_search']) && $s && trim($s) != '') { |
|
251 | - $keywords = explode(" ", $s); |
|
252 | - |
|
253 | - if(is_array($keywords) && $klimit = get_option('geodir_search_word_limit')){ |
|
254 | - foreach($keywords as $kkey=>$kword){ |
|
255 | - if(geodir_utf8_strlen($kword)<=$klimit){ |
|
256 | - unset($keywords[$kkey]); |
|
257 | - } |
|
258 | - } |
|
259 | - } |
|
242 | + $mylat = $gd_session->get('user_lat'); |
|
243 | + $mylon = $gd_session->get('user_lon'); |
|
244 | + } |
|
260 | 245 | |
246 | + $fields .= " , (" . $DistanceRadius . " * 2 * ASIN(SQRT( POWER(SIN((ABS($mylat) - ABS(" . $table . ".post_latitude)) * pi()/180 / 2), 2) +COS(ABS($mylat) * pi()/180) * COS( ABS(" . $table . ".post_latitude) * pi()/180) *POWER(SIN(($mylon - " . $table . ".post_longitude) * pi()/180 / 2), 2) )))as distance "; |
|
247 | + } |
|
261 | 248 | |
262 | - if (count($keywords) > 1) { |
|
263 | - $parts = array( |
|
264 | - 'AND' => 'gd_alltitlematch_part', |
|
265 | - 'OR' => 'gd_titlematch_part' |
|
266 | - ); |
|
267 | - $gd_titlematch_part = ""; |
|
268 | - foreach ($parts as $key => $part) { |
|
269 | - $gd_titlematch_part .= " CASE WHEN "; |
|
270 | - $count = 0; |
|
271 | - foreach ($keywords as $keyword) { |
|
272 | - $keyword = trim($keyword); |
|
273 | - $keyword = wp_specialchars_decode($keyword ,ENT_QUOTES); |
|
249 | + global $s; |
|
250 | + if (is_search() && isset($_REQUEST['geodir_search']) && $s && trim($s) != '') { |
|
251 | + $keywords = explode(" ", $s); |
|
252 | + |
|
253 | + if(is_array($keywords) && $klimit = get_option('geodir_search_word_limit')){ |
|
254 | + foreach($keywords as $kkey=>$kword){ |
|
255 | + if(geodir_utf8_strlen($kword)<=$klimit){ |
|
256 | + unset($keywords[$kkey]); |
|
257 | + } |
|
258 | + } |
|
259 | + } |
|
260 | + |
|
261 | + |
|
262 | + if (count($keywords) > 1) { |
|
263 | + $parts = array( |
|
264 | + 'AND' => 'gd_alltitlematch_part', |
|
265 | + 'OR' => 'gd_titlematch_part' |
|
266 | + ); |
|
267 | + $gd_titlematch_part = ""; |
|
268 | + foreach ($parts as $key => $part) { |
|
269 | + $gd_titlematch_part .= " CASE WHEN "; |
|
270 | + $count = 0; |
|
271 | + foreach ($keywords as $keyword) { |
|
272 | + $keyword = trim($keyword); |
|
273 | + $keyword = wp_specialchars_decode($keyword ,ENT_QUOTES); |
|
274 | 274 | $count++; |
275 | - if ($count < count($keywords)) { |
|
276 | - // $gd_titlematch_part .= $wpdb->posts . ".post_title LIKE '%%" . $keyword . "%%' " . $key . " "; |
|
275 | + if ($count < count($keywords)) { |
|
276 | + // $gd_titlematch_part .= $wpdb->posts . ".post_title LIKE '%%" . $keyword . "%%' " . $key . " "; |
|
277 | 277 | $gd_titlematch_part .= "( " . $wpdb->posts . ".post_title LIKE '" . $keyword . "' OR " . $wpdb->posts . ".post_title LIKE '" . $keyword . "%%' OR " . $wpdb->posts . ".post_title LIKE '%% " . $keyword . "%%' ) " . $key . " "; |
278 | - } else { |
|
279 | - //$gd_titlematch_part .= $wpdb->posts . ".post_title LIKE '%%" . $keyword . "%%' "; |
|
278 | + } else { |
|
279 | + //$gd_titlematch_part .= $wpdb->posts . ".post_title LIKE '%%" . $keyword . "%%' "; |
|
280 | 280 | $gd_titlematch_part .= "( " . $wpdb->posts . ".post_title LIKE '" . $keyword . "' OR " . $wpdb->posts . ".post_title LIKE '" . $keyword . "%%' OR " . $wpdb->posts . ".post_title LIKE '%% " . $keyword . "%%' ) "; |
281 | - } |
|
282 | - } |
|
283 | - $gd_titlematch_part .= "THEN 1 ELSE 0 END AS " . $part . ","; |
|
284 | - } |
|
285 | - } else { |
|
286 | - $gd_titlematch_part = ""; |
|
287 | - } |
|
288 | - $s = stripslashes_deep( $s ); |
|
289 | - $s = wp_specialchars_decode($s,ENT_QUOTES); |
|
281 | + } |
|
282 | + } |
|
283 | + $gd_titlematch_part .= "THEN 1 ELSE 0 END AS " . $part . ","; |
|
284 | + } |
|
285 | + } else { |
|
286 | + $gd_titlematch_part = ""; |
|
287 | + } |
|
288 | + $s = stripslashes_deep( $s ); |
|
289 | + $s = wp_specialchars_decode($s,ENT_QUOTES); |
|
290 | 290 | $fields .= $wpdb->prepare(", CASE WHEN " . $table . ".is_featured='1' THEN 1 ELSE 0 END AS gd_featured, CASE WHEN " . $wpdb->posts . ".post_title LIKE %s THEN 1 ELSE 0 END AS gd_exacttitle," . $gd_titlematch_part . " CASE WHEN ( " . $wpdb->posts . ".post_title LIKE %s OR " . $wpdb->posts . ".post_title LIKE %s OR " . $wpdb->posts . ".post_title LIKE %s ) THEN 1 ELSE 0 END AS gd_titlematch, CASE WHEN ( " . $wpdb->posts . ".post_content LIKE %s OR " . $wpdb->posts . ".post_content LIKE %s OR " . $wpdb->posts . ".post_content LIKE %s OR " . $wpdb->posts . ".post_content LIKE %s ) THEN 1 ELSE 0 END AS gd_content", array($s, $s, $s . '%', '% ' . $s . '%', $s, $s . ' %', '% ' . $s . ' %', '% ' . $s)); |
291 | - } |
|
291 | + } |
|
292 | 292 | |
293 | - return $fields; |
|
293 | + return $fields; |
|
294 | 294 | } |
295 | 295 | |
296 | 296 | |
@@ -307,26 +307,26 @@ discard block |
||
307 | 307 | */ |
308 | 308 | function geodir_posts_join($join) |
309 | 309 | { |
310 | - global $wpdb, $geodir_post_type, $table, $table_prefix, $plugin_prefix; |
|
310 | + global $wpdb, $geodir_post_type, $table, $table_prefix, $plugin_prefix; |
|
311 | 311 | |
312 | - ########### WPML ########### |
|
312 | + ########### WPML ########### |
|
313 | 313 | |
314 | - if (function_exists('icl_object_id')) { |
|
315 | - global $sitepress; |
|
316 | - $lang_code = ICL_LANGUAGE_CODE; |
|
317 | - $default_lang_code = $sitepress->get_default_language(); |
|
318 | - if ($lang_code) { |
|
319 | - $join .= "JOIN " . $table_prefix . "icl_translations icl_t ON icl_t.element_id = " . $table_prefix . "posts.ID"; |
|
320 | - } |
|
314 | + if (function_exists('icl_object_id')) { |
|
315 | + global $sitepress; |
|
316 | + $lang_code = ICL_LANGUAGE_CODE; |
|
317 | + $default_lang_code = $sitepress->get_default_language(); |
|
318 | + if ($lang_code) { |
|
319 | + $join .= "JOIN " . $table_prefix . "icl_translations icl_t ON icl_t.element_id = " . $table_prefix . "posts.ID"; |
|
320 | + } |
|
321 | 321 | |
322 | - } |
|
323 | - ########### WPML ########### |
|
322 | + } |
|
323 | + ########### WPML ########### |
|
324 | 324 | |
325 | - $join .= " INNER JOIN " . $table . " ON (" . $table . ".post_id = $wpdb->posts.ID) "; |
|
326 | - //===old code start |
|
327 | - //$join .= " INNER JOIN ".POST_LOCATION_TABLE." ON (".$table.".post_location_id = ".POST_LOCATION_TABLE.".location_id) " ;//===old code end |
|
325 | + $join .= " INNER JOIN " . $table . " ON (" . $table . ".post_id = $wpdb->posts.ID) "; |
|
326 | + //===old code start |
|
327 | + //$join .= " INNER JOIN ".POST_LOCATION_TABLE." ON (".$table.".post_location_id = ".POST_LOCATION_TABLE.".location_id) " ;//===old code end |
|
328 | 328 | |
329 | - return $join; |
|
329 | + return $join; |
|
330 | 330 | } |
331 | 331 | |
332 | 332 | |
@@ -344,15 +344,15 @@ discard block |
||
344 | 344 | */ |
345 | 345 | function geodir_posts_orderby($orderby) |
346 | 346 | { |
347 | - global $wpdb, $wp_query, $geodir_post_type, $table, $plugin_prefix, $snear, $default_sort; |
|
347 | + global $wpdb, $wp_query, $geodir_post_type, $table, $plugin_prefix, $snear, $default_sort; |
|
348 | 348 | |
349 | - $sort_by = ''; |
|
350 | - $orderby = ' '; |
|
349 | + $sort_by = ''; |
|
350 | + $orderby = ' '; |
|
351 | 351 | |
352 | - if (get_query_var('order_by')) |
|
353 | - $sort_by = get_query_var('order_by'); |
|
352 | + if (get_query_var('order_by')) |
|
353 | + $sort_by = get_query_var('order_by'); |
|
354 | 354 | |
355 | - /*if(isset($wp_query->tax_query->queries) && $wp_query->tax_query->queries){ |
|
355 | + /*if(isset($wp_query->tax_query->queries) && $wp_query->tax_query->queries){ |
|
356 | 356 | $current_term = $wp_query->get_queried_object(); |
357 | 357 | } |
358 | 358 | |
@@ -366,133 +366,133 @@ discard block |
||
366 | 366 | }*/ |
367 | 367 | |
368 | 368 | |
369 | - if ($snear != '') { |
|
370 | - $orderby .= " distance,"; |
|
371 | - } |
|
369 | + if ($snear != '') { |
|
370 | + $orderby .= " distance,"; |
|
371 | + } |
|
372 | 372 | |
373 | - if (isset($_REQUEST['sort_by']) && $_REQUEST['sort_by'] != '' && is_main_query()) |
|
374 | - $sort_by = esc_attr($_REQUEST['sort_by']); |
|
373 | + if (isset($_REQUEST['sort_by']) && $_REQUEST['sort_by'] != '' && is_main_query()) |
|
374 | + $sort_by = esc_attr($_REQUEST['sort_by']); |
|
375 | 375 | |
376 | 376 | |
377 | - if ($sort_by == '') { |
|
378 | - $default_sort = geodir_get_posts_default_sort($geodir_post_type); |
|
379 | - if (!empty($default_sort)) |
|
380 | - $sort_by = $default_sort; |
|
381 | - } |
|
377 | + if ($sort_by == '') { |
|
378 | + $default_sort = geodir_get_posts_default_sort($geodir_post_type); |
|
379 | + if (!empty($default_sort)) |
|
380 | + $sort_by = $default_sort; |
|
381 | + } |
|
382 | 382 | |
383 | - /* |
|
383 | + /* |
|
384 | 384 | if search by term & no location then order always "relevance" |
385 | 385 | if search by location then order always "nearest" |
386 | 386 | */ |
387 | - if (is_main_query() && geodir_is_page('search')) { |
|
388 | - $search_term = get_query_var('s'); |
|
387 | + if (is_main_query() && geodir_is_page('search')) { |
|
388 | + $search_term = get_query_var('s'); |
|
389 | 389 | |
390 | - if (trim($search_term) != '' && !isset($_REQUEST['sort_by'])) { |
|
391 | - $sort_by = 'az'; |
|
392 | - } |
|
390 | + if (trim($search_term) != '' && !isset($_REQUEST['sort_by'])) { |
|
391 | + $sort_by = 'az'; |
|
392 | + } |
|
393 | 393 | |
394 | - if ($snear != '' && $sort_by!='farthest') { |
|
395 | - $sort_by = 'nearest'; |
|
396 | - } |
|
397 | - } |
|
398 | - |
|
399 | - switch ($sort_by): |
|
400 | - case 'newest': |
|
401 | - $orderby = "$wpdb->posts.post_date desc, "; |
|
402 | - break; |
|
403 | - case 'oldest': |
|
404 | - $orderby = "$wpdb->posts.post_date asc, "; |
|
405 | - break; |
|
406 | - case 'low_review': |
|
407 | - case 'rating_count_asc': |
|
408 | - $orderby = $table . ".rating_count ASC, " . $table . ".overall_rating ASC, "; |
|
409 | - break; |
|
410 | - case 'high_review': |
|
411 | - case 'rating_count_desc': |
|
412 | - $orderby = $table . ".rating_count DESC, " . $table . ".overall_rating DESC, "; |
|
413 | - break; |
|
414 | - case 'low_rating': |
|
415 | - $orderby = "( " . $table . ".overall_rating ) ASC, " . $table . ".rating_count ASC, "; |
|
416 | - break; |
|
417 | - case 'high_rating': |
|
418 | - $orderby = " " . $table . ".overall_rating DESC, " . $table . ".rating_count DESC, "; |
|
419 | - break; |
|
420 | - case 'featured': |
|
421 | - $orderby = $table . ".is_featured asc, "; |
|
422 | - break; |
|
423 | - case 'nearest': |
|
424 | - $orderby = " distance asc, "; |
|
425 | - break; |
|
426 | - case 'farthest': |
|
427 | - $orderby = " distance desc, "; |
|
428 | - break; |
|
429 | - case 'random': |
|
430 | - $orderby = " rand(), "; |
|
431 | - break; |
|
432 | - case 'az': |
|
433 | - $orderby = "$wpdb->posts.post_title asc, "; |
|
434 | - break; |
|
435 | - // sort by rating |
|
436 | - case 'overall_rating_desc': |
|
437 | - $orderby = " " . $table . ".overall_rating DESC, " . $table . ".rating_count DESC, "; |
|
438 | - break; |
|
439 | - case 'overall_rating_asc': |
|
440 | - $orderby = " " . $table . ".overall_rating ASC, " . $table . ".rating_count ASC, "; |
|
441 | - break; |
|
442 | - default: |
|
443 | - |
|
444 | - break; |
|
445 | - endswitch; |
|
446 | - |
|
447 | - if ($sort_by != '' && geodir_cpt_has_rating_disabled($geodir_post_type)) { |
|
448 | - if (in_array($sort_by, array('high_review', 'rating_count_desc', 'high_rating', 'overall_rating_desc'))) { |
|
449 | - $orderby = "$wpdb->posts.comment_count DESC, "; |
|
450 | - $sort_by = 'comment_count_desc'; |
|
451 | - } else if (in_array($sort_by, array('low_review', 'rating_count_asc', 'low_rating', 'overall_rating_asc'))) { |
|
452 | - $orderby = "$wpdb->posts.comment_count ASC, "; |
|
453 | - $sort_by = 'comment_count_asc'; |
|
454 | - } |
|
455 | - } |
|
394 | + if ($snear != '' && $sort_by!='farthest') { |
|
395 | + $sort_by = 'nearest'; |
|
396 | + } |
|
397 | + } |
|
456 | 398 | |
457 | - global $s; |
|
399 | + switch ($sort_by): |
|
400 | + case 'newest': |
|
401 | + $orderby = "$wpdb->posts.post_date desc, "; |
|
402 | + break; |
|
403 | + case 'oldest': |
|
404 | + $orderby = "$wpdb->posts.post_date asc, "; |
|
405 | + break; |
|
406 | + case 'low_review': |
|
407 | + case 'rating_count_asc': |
|
408 | + $orderby = $table . ".rating_count ASC, " . $table . ".overall_rating ASC, "; |
|
409 | + break; |
|
410 | + case 'high_review': |
|
411 | + case 'rating_count_desc': |
|
412 | + $orderby = $table . ".rating_count DESC, " . $table . ".overall_rating DESC, "; |
|
413 | + break; |
|
414 | + case 'low_rating': |
|
415 | + $orderby = "( " . $table . ".overall_rating ) ASC, " . $table . ".rating_count ASC, "; |
|
416 | + break; |
|
417 | + case 'high_rating': |
|
418 | + $orderby = " " . $table . ".overall_rating DESC, " . $table . ".rating_count DESC, "; |
|
419 | + break; |
|
420 | + case 'featured': |
|
421 | + $orderby = $table . ".is_featured asc, "; |
|
422 | + break; |
|
423 | + case 'nearest': |
|
424 | + $orderby = " distance asc, "; |
|
425 | + break; |
|
426 | + case 'farthest': |
|
427 | + $orderby = " distance desc, "; |
|
428 | + break; |
|
429 | + case 'random': |
|
430 | + $orderby = " rand(), "; |
|
431 | + break; |
|
432 | + case 'az': |
|
433 | + $orderby = "$wpdb->posts.post_title asc, "; |
|
434 | + break; |
|
435 | + // sort by rating |
|
436 | + case 'overall_rating_desc': |
|
437 | + $orderby = " " . $table . ".overall_rating DESC, " . $table . ".rating_count DESC, "; |
|
438 | + break; |
|
439 | + case 'overall_rating_asc': |
|
440 | + $orderby = " " . $table . ".overall_rating ASC, " . $table . ".rating_count ASC, "; |
|
441 | + break; |
|
442 | + default: |
|
443 | + |
|
444 | + break; |
|
445 | + endswitch; |
|
446 | + |
|
447 | + if ($sort_by != '' && geodir_cpt_has_rating_disabled($geodir_post_type)) { |
|
448 | + if (in_array($sort_by, array('high_review', 'rating_count_desc', 'high_rating', 'overall_rating_desc'))) { |
|
449 | + $orderby = "$wpdb->posts.comment_count DESC, "; |
|
450 | + $sort_by = 'comment_count_desc'; |
|
451 | + } else if (in_array($sort_by, array('low_review', 'rating_count_asc', 'low_rating', 'overall_rating_asc'))) { |
|
452 | + $orderby = "$wpdb->posts.comment_count ASC, "; |
|
453 | + $sort_by = 'comment_count_asc'; |
|
454 | + } |
|
455 | + } |
|
458 | 456 | |
459 | - if (is_search() && isset($_REQUEST['geodir_search']) && $s && trim($s) != '') { |
|
460 | - $keywords = explode(" ", $s); |
|
461 | - if(is_array($keywords) && $klimit = get_option('geodir_search_word_limit')){ |
|
462 | - foreach($keywords as $kkey=>$kword){ |
|
463 | - if(geodir_utf8_strlen($kword)<=$klimit){ |
|
464 | - unset($keywords[$kkey]); |
|
465 | - } |
|
466 | - } |
|
467 | - } |
|
468 | - if ($sort_by == 'nearest' || $sort_by == 'farthest') { |
|
469 | - if (count($keywords) > 1) { |
|
470 | - $orderby = $orderby . " ( gd_titlematch * 2 + gd_featured * 5 + gd_exacttitle * 10 + gd_alltitlematch_part * 100 + gd_titlematch_part * 50 + gd_content * 1.5) DESC, "; |
|
471 | - } else { |
|
472 | - $orderby = $orderby . " ( gd_titlematch * 2 + gd_featured * 5 + gd_exacttitle * 10 + gd_content * 1.5) DESC, "; |
|
473 | - } |
|
474 | - } else { |
|
475 | - if (count($keywords) > 1) { |
|
476 | - $orderby = "( gd_titlematch * 2 + gd_featured * 5 + gd_exacttitle * 10 + gd_alltitlematch_part * 100 + gd_titlematch_part * 50 + gd_content * 1.5) DESC, " . $orderby; |
|
477 | - } else { |
|
478 | - $orderby = "( gd_titlematch * 2 + gd_featured * 5 + gd_exacttitle * 10 + gd_content * 1.5) DESC, " . $orderby; |
|
479 | - } |
|
480 | - } |
|
481 | - } |
|
457 | + global $s; |
|
458 | + |
|
459 | + if (is_search() && isset($_REQUEST['geodir_search']) && $s && trim($s) != '') { |
|
460 | + $keywords = explode(" ", $s); |
|
461 | + if(is_array($keywords) && $klimit = get_option('geodir_search_word_limit')){ |
|
462 | + foreach($keywords as $kkey=>$kword){ |
|
463 | + if(geodir_utf8_strlen($kword)<=$klimit){ |
|
464 | + unset($keywords[$kkey]); |
|
465 | + } |
|
466 | + } |
|
467 | + } |
|
468 | + if ($sort_by == 'nearest' || $sort_by == 'farthest') { |
|
469 | + if (count($keywords) > 1) { |
|
470 | + $orderby = $orderby . " ( gd_titlematch * 2 + gd_featured * 5 + gd_exacttitle * 10 + gd_alltitlematch_part * 100 + gd_titlematch_part * 50 + gd_content * 1.5) DESC, "; |
|
471 | + } else { |
|
472 | + $orderby = $orderby . " ( gd_titlematch * 2 + gd_featured * 5 + gd_exacttitle * 10 + gd_content * 1.5) DESC, "; |
|
473 | + } |
|
474 | + } else { |
|
475 | + if (count($keywords) > 1) { |
|
476 | + $orderby = "( gd_titlematch * 2 + gd_featured * 5 + gd_exacttitle * 10 + gd_alltitlematch_part * 100 + gd_titlematch_part * 50 + gd_content * 1.5) DESC, " . $orderby; |
|
477 | + } else { |
|
478 | + $orderby = "( gd_titlematch * 2 + gd_featured * 5 + gd_exacttitle * 10 + gd_content * 1.5) DESC, " . $orderby; |
|
479 | + } |
|
480 | + } |
|
481 | + } |
|
482 | 482 | |
483 | - /** |
|
484 | - * Filter order by SQL. |
|
485 | - * |
|
486 | - * @since 1.0.0 |
|
487 | - * @param string $orderby The orderby query string. |
|
488 | - * @param string $sort_by Sortby query string. |
|
489 | - * @param string $table Listing table name. |
|
490 | - */ |
|
491 | - $orderby = apply_filters('geodir_posts_order_by_sort', $orderby, $sort_by, $table); |
|
483 | + /** |
|
484 | + * Filter order by SQL. |
|
485 | + * |
|
486 | + * @since 1.0.0 |
|
487 | + * @param string $orderby The orderby query string. |
|
488 | + * @param string $sort_by Sortby query string. |
|
489 | + * @param string $table Listing table name. |
|
490 | + */ |
|
491 | + $orderby = apply_filters('geodir_posts_order_by_sort', $orderby, $sort_by, $table); |
|
492 | 492 | |
493 | - $orderby .= $table . ".is_featured asc, $wpdb->posts.post_date desc, $wpdb->posts.post_title "; |
|
493 | + $orderby .= $table . ".is_featured asc, $wpdb->posts.post_date desc, $wpdb->posts.post_title "; |
|
494 | 494 | |
495 | - return $orderby; |
|
495 | + return $orderby; |
|
496 | 496 | } |
497 | 497 | |
498 | 498 | |
@@ -510,53 +510,53 @@ discard block |
||
510 | 510 | function geodir_posts_order_by_custom_sort($orderby, $sort_by, $table) |
511 | 511 | { |
512 | 512 | |
513 | - global $wpdb; |
|
513 | + global $wpdb; |
|
514 | 514 | |
515 | - if ($sort_by != '' && (!is_search() || ( isset($_REQUEST['s']) && isset($_REQUEST['snear']) && $_REQUEST['snear']=='' && ( $_REQUEST['s']=='' || $_REQUEST['s']==' ') ) )) { |
|
515 | + if ($sort_by != '' && (!is_search() || ( isset($_REQUEST['s']) && isset($_REQUEST['snear']) && $_REQUEST['snear']=='' && ( $_REQUEST['s']=='' || $_REQUEST['s']==' ') ) )) { |
|
516 | 516 | |
517 | - $sort_array = explode('_', $sort_by); |
|
517 | + $sort_array = explode('_', $sort_by); |
|
518 | 518 | |
519 | - $sort_by_count = count($sort_array); |
|
519 | + $sort_by_count = count($sort_array); |
|
520 | 520 | |
521 | - $order = $sort_array[$sort_by_count - 1]; |
|
521 | + $order = $sort_array[$sort_by_count - 1]; |
|
522 | 522 | |
523 | - if ($sort_by_count > 1 && ($order == 'asc' || $order == 'desc')) { |
|
523 | + if ($sort_by_count > 1 && ($order == 'asc' || $order == 'desc')) { |
|
524 | 524 | |
525 | - $sort_by = str_replace('_' . $order, '', $sort_by); |
|
525 | + $sort_by = str_replace('_' . $order, '', $sort_by); |
|
526 | 526 | |
527 | - switch ($sort_by): |
|
527 | + switch ($sort_by): |
|
528 | 528 | |
529 | - case 'post_date': |
|
530 | - case 'comment_count': |
|
529 | + case 'post_date': |
|
530 | + case 'comment_count': |
|
531 | 531 | |
532 | - $orderby = "$wpdb->posts." . $sort_by . " " . $order . ", ".$table . ".overall_rating " . $order . ", "; |
|
533 | - break; |
|
532 | + $orderby = "$wpdb->posts." . $sort_by . " " . $order . ", ".$table . ".overall_rating " . $order . ", "; |
|
533 | + break; |
|
534 | 534 | |
535 | - case 'distance': |
|
536 | - $orderby = $sort_by . " " . $order . ", "; |
|
537 | - break; |
|
535 | + case 'distance': |
|
536 | + $orderby = $sort_by . " " . $order . ", "; |
|
537 | + break; |
|
538 | 538 | |
539 | 539 | |
540 | - // sort by rating |
|
541 | - case 'overall_rating': |
|
542 | - $orderby = " " . $table . "." . $sort_by . " " . $order . ", " . $table . ".rating_count " . $order . ", "; |
|
540 | + // sort by rating |
|
541 | + case 'overall_rating': |
|
542 | + $orderby = " " . $table . "." . $sort_by . " " . $order . ", " . $table . ".rating_count " . $order . ", "; |
|
543 | 543 | |
544 | - break; |
|
544 | + break; |
|
545 | 545 | |
546 | 546 | |
547 | - default: |
|
548 | - if (geodir_column_exist($table, $sort_by)) { |
|
547 | + default: |
|
548 | + if (geodir_column_exist($table, $sort_by)) { |
|
549 | 549 | $orderby = $table . "." . $sort_by . " " . $order . ", "; |
550 | 550 | } |
551 | - break; |
|
551 | + break; |
|
552 | 552 | |
553 | - endswitch; |
|
553 | + endswitch; |
|
554 | 554 | |
555 | - } |
|
555 | + } |
|
556 | 556 | |
557 | - } |
|
557 | + } |
|
558 | 558 | |
559 | - return $orderby; |
|
559 | + return $orderby; |
|
560 | 560 | } |
561 | 561 | |
562 | 562 | /** |
@@ -571,34 +571,34 @@ discard block |
||
571 | 571 | { |
572 | 572 | |
573 | 573 | |
574 | - global $wpdb, $geodir_post_type, $table, $s, $snear; |
|
574 | + global $wpdb, $geodir_post_type, $table, $s, $snear; |
|
575 | 575 | |
576 | - if (!is_admin()) { |
|
576 | + if (!is_admin()) { |
|
577 | 577 | |
578 | - if (geodir_is_page('add-listing') && isset($_REQUEST['pid']) && $_REQUEST['pid'] != '') { |
|
579 | - add_filter('posts_where', 'geodir_edit_listing_where', 1); |
|
578 | + if (geodir_is_page('add-listing') && isset($_REQUEST['pid']) && $_REQUEST['pid'] != '') { |
|
579 | + add_filter('posts_where', 'geodir_edit_listing_where', 1); |
|
580 | 580 | |
581 | - } elseif ((is_search() && $_REQUEST['geodir_search'])) { |
|
581 | + } elseif ((is_search() && $_REQUEST['geodir_search'])) { |
|
582 | 582 | |
583 | - add_filter('posts_where', 'searching_filter_where', 1); |
|
583 | + add_filter('posts_where', 'searching_filter_where', 1); |
|
584 | 584 | |
585 | - if ($snear != '') |
|
586 | - add_filter('posts_where', 'searching_filter_where', 1); |
|
585 | + if ($snear != '') |
|
586 | + add_filter('posts_where', 'searching_filter_where', 1); |
|
587 | 587 | |
588 | - add_filter('posts_orderby', 'geodir_posts_orderby', 1); |
|
588 | + add_filter('posts_orderby', 'geodir_posts_orderby', 1); |
|
589 | 589 | |
590 | - } elseif (geodir_is_page('author')) { |
|
590 | + } elseif (geodir_is_page('author')) { |
|
591 | 591 | |
592 | - add_filter('posts_where', 'author_filter_where', 1); |
|
592 | + add_filter('posts_where', 'author_filter_where', 1); |
|
593 | 593 | |
594 | - } |
|
594 | + } |
|
595 | 595 | |
596 | - //if (!geodir_is_page('detail')) |
|
597 | - add_filter('posts_where', 'geodir_default_where', 1);/**/ |
|
596 | + //if (!geodir_is_page('detail')) |
|
597 | + add_filter('posts_where', 'geodir_default_where', 1);/**/ |
|
598 | 598 | |
599 | - //add_filter( 'user_has_cap', 'geodir_preview_post_cap', 10, 3 );// let subscribers edit their own posts |
|
599 | + //add_filter( 'user_has_cap', 'geodir_preview_post_cap', 10, 3 );// let subscribers edit their own posts |
|
600 | 600 | |
601 | - } |
|
601 | + } |
|
602 | 602 | } |
603 | 603 | |
604 | 604 | /** |
@@ -613,13 +613,13 @@ discard block |
||
613 | 613 | */ |
614 | 614 | function geodir_preview_post_cap($allcaps, $caps, $args) |
615 | 615 | { |
616 | - $user_id = get_current_user_id(); |
|
617 | - if ($user_id && isset($_REQUEST['post_type']) && $_REQUEST['post_type'] != '' && isset($_REQUEST['p']) && $_REQUEST['p'] != '' && $args[0] == 'edit_post' && $_REQUEST['p'] == $args[2]) { |
|
616 | + $user_id = get_current_user_id(); |
|
617 | + if ($user_id && isset($_REQUEST['post_type']) && $_REQUEST['post_type'] != '' && isset($_REQUEST['p']) && $_REQUEST['p'] != '' && $args[0] == 'edit_post' && $_REQUEST['p'] == $args[2]) { |
|
618 | 618 | |
619 | - $allcaps['edit_posts'] = true; |
|
620 | - } |
|
621 | - //print_r($allcaps); |
|
622 | - return $allcaps; |
|
619 | + $allcaps['edit_posts'] = true; |
|
620 | + } |
|
621 | + //print_r($allcaps); |
|
622 | + return $allcaps; |
|
623 | 623 | } |
624 | 624 | |
625 | 625 | |
@@ -634,9 +634,9 @@ discard block |
||
634 | 634 | */ |
635 | 635 | function geodir_edit_listing_where($where) |
636 | 636 | { |
637 | - global $wpdb; |
|
638 | - $where = $wpdb->prepare(" AND $wpdb->posts.ID = %d ", $_REQUEST['pid']); |
|
639 | - return $where; |
|
637 | + global $wpdb; |
|
638 | + $where = $wpdb->prepare(" AND $wpdb->posts.ID = %d ", $_REQUEST['pid']); |
|
639 | + return $where; |
|
640 | 640 | } |
641 | 641 | |
642 | 642 | |
@@ -653,29 +653,29 @@ discard block |
||
653 | 653 | */ |
654 | 654 | function geodir_default_where($where) |
655 | 655 | { |
656 | - global $wp_query, $wpdb; |
|
657 | - |
|
658 | - //print_r($wp_query); |
|
659 | - ########### WPML ########### |
|
660 | - |
|
661 | - if (function_exists('icl_object_id')) { |
|
662 | - global $sitepress, $table_prefix; |
|
663 | - $lang_code = ICL_LANGUAGE_CODE; |
|
664 | - $default_lang_code = $sitepress->get_default_language(); |
|
665 | - $q_post_type = isset($wp_query->query['post_type']) ? $wp_query->query['post_type'] : ''; |
|
666 | - //echo '##########'.$q_post_type; |
|
667 | - if ($lang_code && $q_post_type) { |
|
668 | - $where .= " AND icl_t.language_code = '$lang_code' AND icl_t.element_type IN('post_" . $q_post_type . "') "; |
|
669 | - //$where .= " AND icl_t.language_code = '$lang_code' "; |
|
670 | - } |
|
656 | + global $wp_query, $wpdb; |
|
671 | 657 | |
672 | - } |
|
673 | - ########### WPML ########### |
|
658 | + //print_r($wp_query); |
|
659 | + ########### WPML ########### |
|
674 | 660 | |
661 | + if (function_exists('icl_object_id')) { |
|
662 | + global $sitepress, $table_prefix; |
|
663 | + $lang_code = ICL_LANGUAGE_CODE; |
|
664 | + $default_lang_code = $sitepress->get_default_language(); |
|
665 | + $q_post_type = isset($wp_query->query['post_type']) ? $wp_query->query['post_type'] : ''; |
|
666 | + //echo '##########'.$q_post_type; |
|
667 | + if ($lang_code && $q_post_type) { |
|
668 | + $where .= " AND icl_t.language_code = '$lang_code' AND icl_t.element_type IN('post_" . $q_post_type . "') "; |
|
669 | + //$where .= " AND icl_t.language_code = '$lang_code' "; |
|
670 | + } |
|
675 | 671 | |
676 | - return $where = str_replace("0 = 1", "1=1", $where); |
|
672 | + } |
|
673 | + ########### WPML ########### |
|
674 | + |
|
675 | + |
|
676 | + return $where = str_replace("0 = 1", "1=1", $where); |
|
677 | 677 | |
678 | - /* ====== old code start === |
|
678 | + /* ====== old code start === |
|
679 | 679 | $where = str_replace("0 = 1", "1=1", $where); |
680 | 680 | $country = get_query_var('gd_country'); |
681 | 681 | $region = get_query_var('gd_region'); |
@@ -716,108 +716,108 @@ discard block |
||
716 | 716 | * @return string Modified where query string. |
717 | 717 | */ |
718 | 718 | function searching_filter_where($where) { |
719 | - global $wpdb, $geodir_post_type, $table, $plugin_prefix, $dist, $mylat, $mylon, $s, $snear, $s_A, $s_SA, $search_term, $gd_session; |
|
719 | + global $wpdb, $geodir_post_type, $table, $plugin_prefix, $dist, $mylat, $mylon, $s, $snear, $s_A, $s_SA, $search_term, $gd_session; |
|
720 | 720 | |
721 | - $search_term = 'OR'; |
|
722 | - $search_term = 'AND'; |
|
723 | - $geodir_custom_search = ''; |
|
724 | - $category_search_range = ''; |
|
721 | + $search_term = 'OR'; |
|
722 | + $search_term = 'AND'; |
|
723 | + $geodir_custom_search = ''; |
|
724 | + $category_search_range = ''; |
|
725 | 725 | |
726 | - if (is_single() && get_query_var('post_type')) { |
|
726 | + if (is_single() && get_query_var('post_type')) { |
|
727 | 727 | return $where; |
728 | 728 | } |
729 | 729 | |
730 | - if (is_tax()) { |
|
730 | + if (is_tax()) { |
|
731 | 731 | return $where; |
732 | 732 | } |
733 | 733 | |
734 | 734 | $s = trim($s); |
735 | - $s = wp_specialchars_decode($s ,ENT_QUOTES); |
|
736 | - $s_A = wp_specialchars_decode($s_A ,ENT_QUOTES); |
|
737 | - |
|
738 | - $where = ''; |
|
739 | - $better_search_terms = ''; |
|
740 | - if (isset($_REQUEST['stype'])) |
|
741 | - $post_types = esc_attr(wp_strip_all_tags($_REQUEST['stype'])); |
|
742 | - else |
|
743 | - $post_types = 'gd_place'; |
|
744 | - |
|
745 | - if ($s != '') { |
|
746 | - $keywords = explode(" ", $s); |
|
747 | - if(is_array($keywords) && $klimit = get_option('geodir_search_word_limit')){ |
|
748 | - foreach($keywords as $kkey=>$kword){ |
|
749 | - if(geodir_utf8_strlen($kword)<=$klimit){ |
|
750 | - unset($keywords[$kkey]); |
|
751 | - } |
|
752 | - } |
|
753 | - } |
|
735 | + $s = wp_specialchars_decode($s ,ENT_QUOTES); |
|
736 | + $s_A = wp_specialchars_decode($s_A ,ENT_QUOTES); |
|
737 | + |
|
738 | + $where = ''; |
|
739 | + $better_search_terms = ''; |
|
740 | + if (isset($_REQUEST['stype'])) |
|
741 | + $post_types = esc_attr(wp_strip_all_tags($_REQUEST['stype'])); |
|
742 | + else |
|
743 | + $post_types = 'gd_place'; |
|
754 | 744 | |
755 | - if (!empty($keywords)) { |
|
756 | - foreach ($keywords as $keyword) { |
|
757 | - $keyword = trim($keyword); |
|
758 | - $keyword = wp_specialchars_decode($keyword ,ENT_QUOTES); |
|
759 | - if ($keyword != '') { |
|
760 | - /** |
|
761 | - * Filter the search query keywords SQL. |
|
762 | - * |
|
763 | - * @since 1.5.9 |
|
764 | - * @package GeoDirectory |
|
765 | - * @param string $better_search_terms The query values, default: `' OR ( ' . $wpdb->posts . '.post_title LIKE "' . $keyword . '" OR ' . $wpdb->posts . '.post_title LIKE "' . $keyword . '%" OR ' . $wpdb->posts . '.post_title LIKE "% ' . $keyword . '%" )'`. |
|
766 | - * @param array $keywords The array of keywords for the query. |
|
767 | - * @param string $keyword The single keyword being searched. |
|
768 | - */ |
|
745 | + if ($s != '') { |
|
746 | + $keywords = explode(" ", $s); |
|
747 | + if(is_array($keywords) && $klimit = get_option('geodir_search_word_limit')){ |
|
748 | + foreach($keywords as $kkey=>$kword){ |
|
749 | + if(geodir_utf8_strlen($kword)<=$klimit){ |
|
750 | + unset($keywords[$kkey]); |
|
751 | + } |
|
752 | + } |
|
753 | + } |
|
754 | + |
|
755 | + if (!empty($keywords)) { |
|
756 | + foreach ($keywords as $keyword) { |
|
757 | + $keyword = trim($keyword); |
|
758 | + $keyword = wp_specialchars_decode($keyword ,ENT_QUOTES); |
|
759 | + if ($keyword != '') { |
|
760 | + /** |
|
761 | + * Filter the search query keywords SQL. |
|
762 | + * |
|
763 | + * @since 1.5.9 |
|
764 | + * @package GeoDirectory |
|
765 | + * @param string $better_search_terms The query values, default: `' OR ( ' . $wpdb->posts . '.post_title LIKE "' . $keyword . '" OR ' . $wpdb->posts . '.post_title LIKE "' . $keyword . '%" OR ' . $wpdb->posts . '.post_title LIKE "% ' . $keyword . '%" )'`. |
|
766 | + * @param array $keywords The array of keywords for the query. |
|
767 | + * @param string $keyword The single keyword being searched. |
|
768 | + */ |
|
769 | 769 | $better_search_terms .= apply_filters("geodir_search_better_search_terms",' OR ( ' . $wpdb->posts . '.post_title LIKE "' . $keyword . '" OR ' . $wpdb->posts . '.post_title LIKE "' . $keyword . '%" OR ' . $wpdb->posts . '.post_title LIKE "% ' . $keyword . '%" )',$keywords,$keyword); |
770 | - } |
|
771 | - } |
|
772 | - } |
|
773 | - } |
|
770 | + } |
|
771 | + } |
|
772 | + } |
|
773 | + } |
|
774 | 774 | |
775 | - /* get taxonomy */ |
|
776 | - $taxonomies = geodir_get_taxonomies($post_types, true); |
|
777 | - if($taxonomies) { |
|
778 | - $taxonomies = implode("','", $taxonomies); |
|
779 | - $taxonomies = "'" . $taxonomies . "'"; |
|
780 | - }else{$taxonomies='';} |
|
775 | + /* get taxonomy */ |
|
776 | + $taxonomies = geodir_get_taxonomies($post_types, true); |
|
777 | + if($taxonomies) { |
|
778 | + $taxonomies = implode("','", $taxonomies); |
|
779 | + $taxonomies = "'" . $taxonomies . "'"; |
|
780 | + }else{$taxonomies='';} |
|
781 | 781 | |
782 | - $content_where = $terms_where = ''; |
|
782 | + $content_where = $terms_where = ''; |
|
783 | 783 | if ($s != '') { |
784 | - /** |
|
785 | - * Filter the search query content where values. |
|
786 | - * |
|
787 | - * @since 1.5.0 |
|
788 | - * @package GeoDirectory |
|
789 | - * @param string $content_where The query values, default: `" OR ($wpdb->posts.post_content LIKE \"$s\" OR $wpdb->posts.post_content LIKE \"$s%\" OR $wpdb->posts.post_content LIKE \"% $s%\" OR $wpdb->posts.post_content LIKE \"%>$s%\" OR $wpdb->posts.post_content LIKE \"%\n$s%\") ") "`. |
|
790 | - */ |
|
784 | + /** |
|
785 | + * Filter the search query content where values. |
|
786 | + * |
|
787 | + * @since 1.5.0 |
|
788 | + * @package GeoDirectory |
|
789 | + * @param string $content_where The query values, default: `" OR ($wpdb->posts.post_content LIKE \"$s\" OR $wpdb->posts.post_content LIKE \"$s%\" OR $wpdb->posts.post_content LIKE \"% $s%\" OR $wpdb->posts.post_content LIKE \"%>$s%\" OR $wpdb->posts.post_content LIKE \"%\n$s%\") ") "`. |
|
790 | + */ |
|
791 | 791 | $content_where = apply_filters("geodir_search_content_where"," OR ($wpdb->posts.post_content LIKE \"$s\" OR $wpdb->posts.post_content LIKE \"$s%\" OR $wpdb->posts.post_content LIKE \"% $s%\" OR $wpdb->posts.post_content LIKE \"%>$s%\" OR $wpdb->posts.post_content LIKE \"%\n$s%\") "); |
792 | - /** |
|
793 | - * Filter the search query term values. |
|
794 | - * |
|
795 | - * @since 1.5.0 |
|
796 | - * @package GeoDirectory |
|
797 | - * @param string $terms_where The separator, default: `" AND ($wpdb->terms.name LIKE \"$s\" OR $wpdb->terms.name LIKE \"$s%\" OR $wpdb->terms.name LIKE \"% $s%\" OR $wpdb->terms.name IN ($s_A)) "`. |
|
798 | - */ |
|
799 | - $terms_where = apply_filters("geodir_search_terms_where"," AND ($wpdb->terms.name LIKE \"$s\" OR $wpdb->terms.name LIKE \"$s%\" OR $wpdb->terms.name LIKE \"% $s%\" OR $wpdb->terms.name IN ($s_A)) "); |
|
792 | + /** |
|
793 | + * Filter the search query term values. |
|
794 | + * |
|
795 | + * @since 1.5.0 |
|
796 | + * @package GeoDirectory |
|
797 | + * @param string $terms_where The separator, default: `" AND ($wpdb->terms.name LIKE \"$s\" OR $wpdb->terms.name LIKE \"$s%\" OR $wpdb->terms.name LIKE \"% $s%\" OR $wpdb->terms.name IN ($s_A)) "`. |
|
798 | + */ |
|
799 | + $terms_where = apply_filters("geodir_search_terms_where"," AND ($wpdb->terms.name LIKE \"$s\" OR $wpdb->terms.name LIKE \"$s%\" OR $wpdb->terms.name LIKE \"% $s%\" OR $wpdb->terms.name IN ($s_A)) "); |
|
800 | 800 | } |
801 | 801 | |
802 | - if ($snear != '') { |
|
802 | + if ($snear != '') { |
|
803 | 803 | |
804 | 804 | |
805 | - if (is_numeric($gd_session->get('near_me_range')) && !isset($_REQUEST['sdist'])) { |
|
806 | - $dist = $gd_session->get('near_me_range'); |
|
807 | - } |
|
808 | - $lon1 = $mylon - $dist / abs(cos(deg2rad($mylat)) * 69); |
|
809 | - $lon2 = $mylon + $dist / abs(cos(deg2rad($mylat)) * 69); |
|
810 | - $lat1 = $mylat - ($dist / 69); |
|
811 | - $lat2 = $mylat + ($dist / 69); |
|
805 | + if (is_numeric($gd_session->get('near_me_range')) && !isset($_REQUEST['sdist'])) { |
|
806 | + $dist = $gd_session->get('near_me_range'); |
|
807 | + } |
|
808 | + $lon1 = $mylon - $dist / abs(cos(deg2rad($mylat)) * 69); |
|
809 | + $lon2 = $mylon + $dist / abs(cos(deg2rad($mylat)) * 69); |
|
810 | + $lat1 = $mylat - ($dist / 69); |
|
811 | + $lat2 = $mylat + ($dist / 69); |
|
812 | 812 | |
813 | - $rlon1 = is_numeric(min($lon1, $lon2)) ? min($lon1, $lon2) : ''; |
|
814 | - $rlon2 = is_numeric(max($lon1, $lon2)) ? max($lon1, $lon2) : ''; |
|
815 | - $rlat1 = is_numeric(min($lat1, $lat2)) ? min($lat1, $lat2) : ''; |
|
816 | - $rlat2 = is_numeric(max($lat1, $lat2)) ? max($lat1, $lat2) : ''; |
|
813 | + $rlon1 = is_numeric(min($lon1, $lon2)) ? min($lon1, $lon2) : ''; |
|
814 | + $rlon2 = is_numeric(max($lon1, $lon2)) ? max($lon1, $lon2) : ''; |
|
815 | + $rlat1 = is_numeric(min($lat1, $lat2)) ? min($lat1, $lat2) : ''; |
|
816 | + $rlat2 = is_numeric(max($lat1, $lat2)) ? max($lat1, $lat2) : ''; |
|
817 | 817 | |
818 | 818 | |
819 | 819 | |
820 | - $where .= " AND ( ( $wpdb->posts.post_title LIKE \"$s\" $better_search_terms) |
|
820 | + $where .= " AND ( ( $wpdb->posts.post_title LIKE \"$s\" $better_search_terms) |
|
821 | 821 | $content_where |
822 | 822 | OR ($wpdb->posts.ID IN( |
823 | 823 | SELECT $wpdb->term_relationships.object_id as post_id |
@@ -834,13 +834,13 @@ discard block |
||
834 | 834 | AND ( " . $table . ".post_latitude between $rlat1 and $rlat2 ) |
835 | 835 | AND ( " . $table . ".post_longitude between $rlon1 and $rlon2 ) "; |
836 | 836 | |
837 | - if (isset($_REQUEST['sdist']) && $_REQUEST['sdist'] != 'all') { |
|
838 | - $DistanceRadius = geodir_getDistanceRadius(get_option('geodir_search_dist_1')); |
|
839 | - $where .= " AND CONVERT((" . $DistanceRadius . " * 2 * ASIN(SQRT( POWER(SIN((ABS($mylat) - ABS(" . $table . ".post_latitude)) * pi()/180 / 2), 2) +COS(ABS($mylat) * pi()/180) * COS( ABS(" . $table . ".post_latitude) * pi()/180) *POWER(SIN(($mylon - " . $table . ".post_longitude) * pi()/180 / 2), 2) ))),DECIMAL(64,4)) <= " . $dist; |
|
840 | - } |
|
837 | + if (isset($_REQUEST['sdist']) && $_REQUEST['sdist'] != 'all') { |
|
838 | + $DistanceRadius = geodir_getDistanceRadius(get_option('geodir_search_dist_1')); |
|
839 | + $where .= " AND CONVERT((" . $DistanceRadius . " * 2 * ASIN(SQRT( POWER(SIN((ABS($mylat) - ABS(" . $table . ".post_latitude)) * pi()/180 / 2), 2) +COS(ABS($mylat) * pi()/180) * COS( ABS(" . $table . ".post_latitude) * pi()/180) *POWER(SIN(($mylon - " . $table . ".post_longitude) * pi()/180 / 2), 2) ))),DECIMAL(64,4)) <= " . $dist; |
|
840 | + } |
|
841 | 841 | |
842 | - } else { |
|
843 | - $where .= " AND ( ( $wpdb->posts.post_title LIKE \"$s\" $better_search_terms) |
|
842 | + } else { |
|
843 | + $where .= " AND ( ( $wpdb->posts.post_title LIKE \"$s\" $better_search_terms) |
|
844 | 844 | $content_where |
845 | 845 | OR ( $wpdb->posts.ID IN( |
846 | 846 | SELECT $wpdb->term_relationships.object_id as post_id |
@@ -854,19 +854,19 @@ discard block |
||
854 | 854 | ) |
855 | 855 | AND $wpdb->posts.post_type in ('$post_types') |
856 | 856 | AND ($wpdb->posts.post_status = 'publish') "; |
857 | - } |
|
857 | + } |
|
858 | 858 | |
859 | 859 | ########### WPML ########### |
860 | - if ( function_exists( 'icl_object_id' ) ) { |
|
860 | + if ( function_exists( 'icl_object_id' ) ) { |
|
861 | 861 | $lang_code = ICL_LANGUAGE_CODE; |
862 | 862 | |
863 | 863 | if ($lang_code && $post_types) { |
864 | - $where .= " AND icl_t.language_code = '".$lang_code."' AND icl_t.element_type IN('post_" . $post_types . "') "; |
|
865 | - } |
|
866 | - } |
|
867 | - ########### WPML ########### |
|
864 | + $where .= " AND icl_t.language_code = '".$lang_code."' AND icl_t.element_type IN('post_" . $post_types . "') "; |
|
865 | + } |
|
866 | + } |
|
867 | + ########### WPML ########### |
|
868 | 868 | |
869 | - return $where; |
|
869 | + return $where; |
|
870 | 870 | } |
871 | 871 | |
872 | 872 | |
@@ -881,45 +881,45 @@ discard block |
||
881 | 881 | * @return string Modified where query string. |
882 | 882 | */ |
883 | 883 | function author_filter_where($where) { |
884 | - global $wpdb, $geodir_post_type, $table, $curr; |
|
884 | + global $wpdb, $geodir_post_type, $table, $curr; |
|
885 | 885 | |
886 | - $curauth = (get_query_var('author_name')) ? get_user_by('slug', get_query_var('author_name')) : get_userdata(get_query_var('author')); |
|
887 | - $user_id = !empty($curauth->ID) ? (int)$curauth->ID : 0; |
|
886 | + $curauth = (get_query_var('author_name')) ? get_user_by('slug', get_query_var('author_name')) : get_userdata(get_query_var('author')); |
|
887 | + $user_id = !empty($curauth->ID) ? (int)$curauth->ID : 0; |
|
888 | 888 | |
889 | - if (isset($_REQUEST['stype'])) { |
|
890 | - $where = $wpdb->prepare(" AND $wpdb->posts.post_type IN (%s) ",$_REQUEST['stype']); |
|
891 | - } else { |
|
892 | - $where = " AND $wpdb->posts.post_type IN ('gd_place') "; |
|
893 | - } |
|
889 | + if (isset($_REQUEST['stype'])) { |
|
890 | + $where = $wpdb->prepare(" AND $wpdb->posts.post_type IN (%s) ",$_REQUEST['stype']); |
|
891 | + } else { |
|
892 | + $where = " AND $wpdb->posts.post_type IN ('gd_place') "; |
|
893 | + } |
|
894 | 894 | |
895 | - if ($user_id > 0) { |
|
896 | - if (isset($_REQUEST['list']) && $_REQUEST['list'] == 'favourite') { |
|
897 | - $user_fav_posts = get_user_meta($user_id, 'gd_user_favourite_post', true); |
|
898 | - $user_fav_posts = !empty($user_fav_posts) && is_array($user_fav_posts) ? implode("','", $user_fav_posts) : '-1'; |
|
899 | - $where .= " AND $wpdb->posts.ID IN ('$user_fav_posts')"; |
|
900 | - } else |
|
901 | - $where .= " AND $wpdb->posts.post_author = $user_id"; |
|
902 | - |
|
903 | - if ($user_id == (int)get_current_user_id()) { |
|
904 | - $where .= " AND $wpdb->posts.post_status IN ('publish','draft','pending') "; |
|
905 | - } else { |
|
906 | - $where .= " AND $wpdb->posts.post_status = 'publish' "; |
|
907 | - } |
|
908 | - } else { |
|
909 | - $where .= " AND $wpdb->posts.post_author = '-1' AND $wpdb->posts.post_status = 'publish' "; |
|
910 | - } |
|
895 | + if ($user_id > 0) { |
|
896 | + if (isset($_REQUEST['list']) && $_REQUEST['list'] == 'favourite') { |
|
897 | + $user_fav_posts = get_user_meta($user_id, 'gd_user_favourite_post', true); |
|
898 | + $user_fav_posts = !empty($user_fav_posts) && is_array($user_fav_posts) ? implode("','", $user_fav_posts) : '-1'; |
|
899 | + $where .= " AND $wpdb->posts.ID IN ('$user_fav_posts')"; |
|
900 | + } else |
|
901 | + $where .= " AND $wpdb->posts.post_author = $user_id"; |
|
902 | + |
|
903 | + if ($user_id == (int)get_current_user_id()) { |
|
904 | + $where .= " AND $wpdb->posts.post_status IN ('publish','draft','pending') "; |
|
905 | + } else { |
|
906 | + $where .= " AND $wpdb->posts.post_status = 'publish' "; |
|
907 | + } |
|
908 | + } else { |
|
909 | + $where .= " AND $wpdb->posts.post_author = '-1' AND $wpdb->posts.post_status = 'publish' "; |
|
910 | + } |
|
911 | 911 | |
912 | - ########### WPML ########### |
|
913 | - if (function_exists('icl_object_id')) { |
|
914 | - $lang_code = ICL_LANGUAGE_CODE; |
|
915 | - if ($lang_code) { |
|
916 | - $where .= " AND icl_t.language_code='" . $lang_code . "' "; |
|
917 | - } |
|
912 | + ########### WPML ########### |
|
913 | + if (function_exists('icl_object_id')) { |
|
914 | + $lang_code = ICL_LANGUAGE_CODE; |
|
915 | + if ($lang_code) { |
|
916 | + $where .= " AND icl_t.language_code='" . $lang_code . "' "; |
|
917 | + } |
|
918 | 918 | |
919 | - } |
|
920 | - ########### WPML ########### |
|
919 | + } |
|
920 | + ########### WPML ########### |
|
921 | 921 | |
922 | - return $where; |
|
922 | + return $where; |
|
923 | 923 | } |
924 | 924 | |
925 | 925 | /** |
@@ -934,11 +934,11 @@ discard block |
||
934 | 934 | */ |
935 | 935 | function geodir_filter_widget_join($join) |
936 | 936 | { |
937 | - global $wp_query, $table; |
|
938 | - if (!empty($wp_query->query['with_pics_only'])) { |
|
939 | - $join .= " LEFT JOIN " . GEODIR_ATTACHMENT_TABLE . " ON ( " . GEODIR_ATTACHMENT_TABLE . ".post_id=" . $table . ".post_id AND " . GEODIR_ATTACHMENT_TABLE . ".mime_type LIKE '%image%' )"; |
|
940 | - } |
|
941 | - return $join; |
|
937 | + global $wp_query, $table; |
|
938 | + if (!empty($wp_query->query['with_pics_only'])) { |
|
939 | + $join .= " LEFT JOIN " . GEODIR_ATTACHMENT_TABLE . " ON ( " . GEODIR_ATTACHMENT_TABLE . ".post_id=" . $table . ".post_id AND " . GEODIR_ATTACHMENT_TABLE . ".mime_type LIKE '%image%' )"; |
|
940 | + } |
|
941 | + return $join; |
|
942 | 942 | } |
943 | 943 | |
944 | 944 | /** |
@@ -953,43 +953,43 @@ discard block |
||
953 | 953 | */ |
954 | 954 | function geodir_filter_widget_where($where) |
955 | 955 | { |
956 | - global $wp_query, $table; |
|
957 | - if (!empty($wp_query->query['show_featured_only'])) { |
|
958 | - $where .= " AND " . $table . ".is_featured = '1'"; |
|
959 | - } |
|
960 | - if (!empty($wp_query->query['show_special_only'])) { |
|
961 | - $where .= " AND ( " . $table . ".geodir_special_offers != '' AND " . $table . ".geodir_special_offers IS NOT NULL )"; |
|
962 | - } |
|
963 | - if (!empty($wp_query->query['with_pics_only'])) { |
|
964 | - $where .= " AND " . GEODIR_ATTACHMENT_TABLE . ".ID IS NOT NULL GROUP BY " . $table . ".post_id"; |
|
965 | - } |
|
966 | - if (!empty($wp_query->query['with_videos_only'])) { |
|
967 | - $where .= " AND ( " . $table . ".geodir_video != '' AND " . $table . ".geodir_video IS NOT NULL )"; |
|
968 | - } |
|
969 | - return $where; |
|
956 | + global $wp_query, $table; |
|
957 | + if (!empty($wp_query->query['show_featured_only'])) { |
|
958 | + $where .= " AND " . $table . ".is_featured = '1'"; |
|
959 | + } |
|
960 | + if (!empty($wp_query->query['show_special_only'])) { |
|
961 | + $where .= " AND ( " . $table . ".geodir_special_offers != '' AND " . $table . ".geodir_special_offers IS NOT NULL )"; |
|
962 | + } |
|
963 | + if (!empty($wp_query->query['with_pics_only'])) { |
|
964 | + $where .= " AND " . GEODIR_ATTACHMENT_TABLE . ".ID IS NOT NULL GROUP BY " . $table . ".post_id"; |
|
965 | + } |
|
966 | + if (!empty($wp_query->query['with_videos_only'])) { |
|
967 | + $where .= " AND ( " . $table . ".geodir_video != '' AND " . $table . ".geodir_video IS NOT NULL )"; |
|
968 | + } |
|
969 | + return $where; |
|
970 | 970 | } |
971 | 971 | |
972 | 972 | |
973 | 973 | function geodir_related_posts_fields($fields) { |
974 | - global $wp_query, $wpdb, $table, $post; |
|
974 | + global $wp_query, $wpdb, $table, $post; |
|
975 | 975 | |
976 | - $fields .= ", " . $table . ".* "; |
|
976 | + $fields .= ", " . $table . ".* "; |
|
977 | 977 | |
978 | - $DistanceRadius = geodir_getDistanceRadius(get_option('geodir_search_dist_1')); |
|
978 | + $DistanceRadius = geodir_getDistanceRadius(get_option('geodir_search_dist_1')); |
|
979 | 979 | |
980 | - $mylat = $post->post_latitude; |
|
981 | - $mylon = $post->post_longitude; |
|
980 | + $mylat = $post->post_latitude; |
|
981 | + $mylon = $post->post_longitude; |
|
982 | 982 | |
983 | - $fields .= " , (" . $DistanceRadius . " * 2 * ASIN(SQRT( POWER(SIN((ABS($mylat) - ABS(" . $table . ".post_latitude)) * pi()/180 / 2), 2) +COS(ABS($mylat) * pi()/180) * COS( ABS(" . $table . ".post_latitude) * pi()/180) *POWER(SIN(($mylon - " . $table . ".post_longitude) * pi()/180 / 2), 2) )))as distance "; |
|
984 | - return $fields; |
|
983 | + $fields .= " , (" . $DistanceRadius . " * 2 * ASIN(SQRT( POWER(SIN((ABS($mylat) - ABS(" . $table . ".post_latitude)) * pi()/180 / 2), 2) +COS(ABS($mylat) * pi()/180) * COS( ABS(" . $table . ".post_latitude) * pi()/180) *POWER(SIN(($mylon - " . $table . ".post_longitude) * pi()/180 / 2), 2) )))as distance "; |
|
984 | + return $fields; |
|
985 | 985 | } |
986 | 986 | function geodir_related_posts_fields_filter($query) { |
987 | - if ( isset($query->query_vars['is_geodir_loop']) && $query->query_vars['is_geodir_loop'] |
|
988 | - && isset($query->query_vars['order_by']) && $query->query_vars['order_by'] == 'nearest' |
|
989 | - && isset($query->query_vars['related_listings']) && $query->query_vars['related_listings'] |
|
990 | - ) { |
|
991 | - add_filter('posts_fields', 'geodir_related_posts_fields', 1); |
|
992 | - } |
|
987 | + if ( isset($query->query_vars['is_geodir_loop']) && $query->query_vars['is_geodir_loop'] |
|
988 | + && isset($query->query_vars['order_by']) && $query->query_vars['order_by'] == 'nearest' |
|
989 | + && isset($query->query_vars['related_listings']) && $query->query_vars['related_listings'] |
|
990 | + ) { |
|
991 | + add_filter('posts_fields', 'geodir_related_posts_fields', 1); |
|
992 | + } |
|
993 | 993 | } |
994 | 994 | add_action('pre_get_posts', 'geodir_related_posts_fields_filter', 1); |
995 | 995 | |
@@ -1004,28 +1004,28 @@ discard block |
||
1004 | 1004 | * @return string|null If field exists in table returns order by clause else returns empty. |
1005 | 1005 | */ |
1006 | 1006 | function geodir_prepare_custom_sorting( $sorting, $table ) { |
1007 | - $orderby = ''; |
|
1007 | + $orderby = ''; |
|
1008 | 1008 | |
1009 | - if ( empty( $sorting ) || empty( $table ) ) { |
|
1010 | - return $orderby; |
|
1011 | - } |
|
1009 | + if ( empty( $sorting ) || empty( $table ) ) { |
|
1010 | + return $orderby; |
|
1011 | + } |
|
1012 | 1012 | |
1013 | - if ( strpos( strtoupper( $sorting ), '_ASC' ) !== false || strpos( strtoupper( $sorting ), '_DESC') !== false ) { |
|
1014 | - $sorting_array = explode( '_', $sorting ); |
|
1013 | + if ( strpos( strtoupper( $sorting ), '_ASC' ) !== false || strpos( strtoupper( $sorting ), '_DESC') !== false ) { |
|
1014 | + $sorting_array = explode( '_', $sorting ); |
|
1015 | 1015 | |
1016 | - if ( ( $count = count( $sorting_array ) ) > 1 ) { |
|
1017 | - $order = !empty( $sorting_array[$count - 1] ) ? strtoupper( $sorting_array[$count - 1] ) : ''; |
|
1018 | - array_pop( $sorting_array ); |
|
1016 | + if ( ( $count = count( $sorting_array ) ) > 1 ) { |
|
1017 | + $order = !empty( $sorting_array[$count - 1] ) ? strtoupper( $sorting_array[$count - 1] ) : ''; |
|
1018 | + array_pop( $sorting_array ); |
|
1019 | 1019 | |
1020 | - if ( !empty( $sorting_array ) && ( $order == 'ASC' || $order == 'DESC' ) ) { |
|
1021 | - $sort_by = implode( '_', $sorting_array ); |
|
1020 | + if ( !empty( $sorting_array ) && ( $order == 'ASC' || $order == 'DESC' ) ) { |
|
1021 | + $sort_by = implode( '_', $sorting_array ); |
|
1022 | 1022 | |
1023 | - if ( geodir_column_exist( $table, $sort_by ) ) { |
|
1024 | - $orderby = $table . "." . $sort_by . " " . $order; |
|
1025 | - } |
|
1026 | - } |
|
1027 | - } |
|
1028 | - } |
|
1023 | + if ( geodir_column_exist( $table, $sort_by ) ) { |
|
1024 | + $orderby = $table . "." . $sort_by . " " . $order; |
|
1025 | + } |
|
1026 | + } |
|
1027 | + } |
|
1028 | + } |
|
1029 | 1029 | |
1030 | - return $orderby; |
|
1030 | + return $orderby; |
|
1031 | 1031 | } |
1032 | 1032 | \ No newline at end of file |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | */ |
8 | 8 | // If this file is called directly, abort. |
9 | 9 | if (!defined('WPINC')) { |
10 | - die; |
|
10 | + die; |
|
11 | 11 | } |
12 | 12 | require_once('geodirectory-functions/shortcode_functions.php'); |
13 | 13 | |
@@ -32,43 +32,43 @@ discard block |
||
32 | 32 | */ |
33 | 33 | function geodir_sc_add_listing($atts) |
34 | 34 | { |
35 | - ob_start(); |
|
36 | - $defaults = array( |
|
37 | - 'pid' => '', |
|
38 | - 'listing_type' => 'gd_place', |
|
39 | - 'login_msg' => __('You must login to post.', 'geodirectory'), |
|
40 | - 'show_login' => false, |
|
41 | - ); |
|
42 | - $params = shortcode_atts($defaults, $atts); |
|
43 | - |
|
44 | - foreach ($params as $key => $value) { |
|
45 | - $_REQUEST[$key] = $value; |
|
46 | - } |
|
47 | - |
|
48 | - $user_id = get_current_user_id(); |
|
49 | - if (!$user_id) { |
|
50 | - echo $params['login_msg']; |
|
51 | - if ($params['show_login']) { |
|
52 | - echo "<br />"; |
|
53 | - $defaults = array( |
|
54 | - 'before_widget' => '', |
|
55 | - 'after_widget' => '', |
|
56 | - 'before_title' => '', |
|
57 | - 'after_title' => '', |
|
58 | - ); |
|
59 | - |
|
60 | - geodir_loginwidget_output($defaults, $defaults); |
|
61 | - } |
|
62 | - |
|
63 | - |
|
64 | - } else { |
|
65 | - // Add listing page will be used if shortcode is detected in page content, no need to call it here |
|
66 | - } |
|
67 | - $output = ob_get_contents(); |
|
68 | - |
|
69 | - ob_end_clean(); |
|
70 | - |
|
71 | - return $output; |
|
35 | + ob_start(); |
|
36 | + $defaults = array( |
|
37 | + 'pid' => '', |
|
38 | + 'listing_type' => 'gd_place', |
|
39 | + 'login_msg' => __('You must login to post.', 'geodirectory'), |
|
40 | + 'show_login' => false, |
|
41 | + ); |
|
42 | + $params = shortcode_atts($defaults, $atts); |
|
43 | + |
|
44 | + foreach ($params as $key => $value) { |
|
45 | + $_REQUEST[$key] = $value; |
|
46 | + } |
|
47 | + |
|
48 | + $user_id = get_current_user_id(); |
|
49 | + if (!$user_id) { |
|
50 | + echo $params['login_msg']; |
|
51 | + if ($params['show_login']) { |
|
52 | + echo "<br />"; |
|
53 | + $defaults = array( |
|
54 | + 'before_widget' => '', |
|
55 | + 'after_widget' => '', |
|
56 | + 'before_title' => '', |
|
57 | + 'after_title' => '', |
|
58 | + ); |
|
59 | + |
|
60 | + geodir_loginwidget_output($defaults, $defaults); |
|
61 | + } |
|
62 | + |
|
63 | + |
|
64 | + } else { |
|
65 | + // Add listing page will be used if shortcode is detected in page content, no need to call it here |
|
66 | + } |
|
67 | + $output = ob_get_contents(); |
|
68 | + |
|
69 | + ob_end_clean(); |
|
70 | + |
|
71 | + return $output; |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | /** |
@@ -96,136 +96,136 @@ discard block |
||
96 | 96 | */ |
97 | 97 | function geodir_sc_home_map($atts) |
98 | 98 | { |
99 | - ob_start(); |
|
100 | - $defaults = array( |
|
101 | - 'width' => '960', |
|
102 | - 'height' => '425', |
|
103 | - 'maptype' => 'ROADMAP', |
|
104 | - 'zoom' => '13', |
|
105 | - 'autozoom' => '', |
|
106 | - 'child_collapse' => '0', |
|
107 | - 'scrollwheel' => '0', |
|
99 | + ob_start(); |
|
100 | + $defaults = array( |
|
101 | + 'width' => '960', |
|
102 | + 'height' => '425', |
|
103 | + 'maptype' => 'ROADMAP', |
|
104 | + 'zoom' => '13', |
|
105 | + 'autozoom' => '', |
|
106 | + 'child_collapse' => '0', |
|
107 | + 'scrollwheel' => '0', |
|
108 | 108 | 'marker_cluster' => false, |
109 | - 'latitude' => '', |
|
110 | - 'longitude' => '' |
|
111 | - ); |
|
112 | - |
|
113 | - $params = shortcode_atts($defaults, $atts); |
|
114 | - |
|
115 | - $params = gdsc_validate_map_args($params); |
|
116 | - |
|
117 | - $map_args = array( |
|
118 | - 'map_canvas_name' => 'gd_home_map', |
|
119 | - 'latitude' => $params['latitude'], |
|
120 | - 'longitude' => $params['longitude'], |
|
121 | - |
|
122 | - /** |
|
123 | - * Filter the widget width of the map on home/listings page. |
|
124 | - * |
|
125 | - * @since 1.0.0 |
|
126 | - * @param mixed(string|int|float) $params['width'] The map width. |
|
127 | - */ |
|
128 | - 'width' => apply_filters('widget_width', $params['width']), |
|
129 | - /** |
|
130 | - * Filter the widget height of the map on home/listings page. |
|
131 | - * |
|
132 | - * @since 1.0.0 |
|
133 | - * @param mixed(string|int|float) $params['height'] The map height. |
|
134 | - */ |
|
135 | - 'height' => apply_filters('widget_heigh', $params['height']), |
|
136 | - /** |
|
137 | - * Filter the widget maptype of the map on home/listings page. |
|
138 | - * |
|
139 | - * @since 1.0.0 |
|
109 | + 'latitude' => '', |
|
110 | + 'longitude' => '' |
|
111 | + ); |
|
112 | + |
|
113 | + $params = shortcode_atts($defaults, $atts); |
|
114 | + |
|
115 | + $params = gdsc_validate_map_args($params); |
|
116 | + |
|
117 | + $map_args = array( |
|
118 | + 'map_canvas_name' => 'gd_home_map', |
|
119 | + 'latitude' => $params['latitude'], |
|
120 | + 'longitude' => $params['longitude'], |
|
121 | + |
|
122 | + /** |
|
123 | + * Filter the widget width of the map on home/listings page. |
|
124 | + * |
|
125 | + * @since 1.0.0 |
|
126 | + * @param mixed(string|int|float) $params['width'] The map width. |
|
127 | + */ |
|
128 | + 'width' => apply_filters('widget_width', $params['width']), |
|
129 | + /** |
|
130 | + * Filter the widget height of the map on home/listings page. |
|
131 | + * |
|
132 | + * @since 1.0.0 |
|
133 | + * @param mixed(string|int|float) $params['height'] The map height. |
|
134 | + */ |
|
135 | + 'height' => apply_filters('widget_heigh', $params['height']), |
|
136 | + /** |
|
137 | + * Filter the widget maptype of the map on home/listings page. |
|
138 | + * |
|
139 | + * @since 1.0.0 |
|
140 | 140 | * @since 1.5.2 Added TERRAIN map type. |
141 | - * @param string $params['maptype'] The map type. Can be ROADMAP | SATELLITE | HYBRID | TERRAIN. |
|
142 | - */ |
|
143 | - 'maptype' => apply_filters('widget_maptype', $params['maptype']), |
|
144 | - /** |
|
145 | - * Filter the widget scrollwheel value of the map on home/listings page. |
|
146 | - * |
|
147 | - * Should the scrollwheel zoom the map or not. |
|
148 | - * |
|
149 | - * @since 1.0.0 |
|
150 | - * @param bool $params['scrollwheel'] True to allow scroll wheel to scroll map or false if not. |
|
151 | - */ |
|
152 | - 'scrollwheel' => apply_filters('widget_scrollwheel', $params['scrollwheel']), |
|
153 | - /** |
|
154 | - * Filter the widget zoom level of the map on home/listings page. |
|
155 | - * |
|
156 | - * @since 1.0.0 |
|
157 | - * @param int $params['zoom'] The zoom level of the map. Between 1-19. |
|
158 | - */ |
|
159 | - 'zoom' => apply_filters('widget_zoom', $params['zoom']), |
|
160 | - /** |
|
161 | - * Filter the widget auto zoom value of the map on home/listings page. |
|
162 | - * |
|
163 | - * If the map should autozoom to fit the markers shown. |
|
164 | - * |
|
165 | - * @since 1.0.0 |
|
166 | - * @param bool $params['autozoom'] True if the map should autozoom, false if not. |
|
167 | - */ |
|
168 | - 'autozoom' => apply_filters('widget_autozoom', $params['autozoom']), |
|
169 | - /** |
|
170 | - * Filter the widget child_collapse value of the map on home/listings page. |
|
171 | - * |
|
172 | - * If the map should auto collapse the child categories if the category bar is present. |
|
173 | - * |
|
174 | - * @since 1.0.0 |
|
175 | - * @param bool $params['child_collapse'] True if the map should collapse the categories, false if not. |
|
176 | - */ |
|
177 | - 'child_collapse' => apply_filters('widget_child_collapse', $params['child_collapse']), |
|
178 | - 'enable_cat_filters' => true, |
|
179 | - 'enable_text_search' => true, |
|
180 | - 'enable_post_type_filters' => true, |
|
181 | - /** |
|
182 | - * Filter the widget enable_location_filters value of the map on home/listings page. |
|
183 | - * |
|
184 | - * This is used when the location addon is used. |
|
185 | - * |
|
186 | - * @since 1.0.0 |
|
187 | - * @param bool $val True if location filters should be used, false if not. |
|
188 | - */ |
|
189 | - 'enable_location_filters' => apply_filters('geodir_home_map_enable_location_filters', false), |
|
190 | - 'enable_jason_on_load' => false, |
|
191 | - 'enable_marker_cluster' => false, |
|
192 | - 'enable_map_resize_button' => true, |
|
193 | - 'map_class_name' => 'geodir-map-home-page', |
|
194 | - 'is_geodir_home_map_widget' => true, |
|
195 | - ); |
|
141 | + * @param string $params['maptype'] The map type. Can be ROADMAP | SATELLITE | HYBRID | TERRAIN. |
|
142 | + */ |
|
143 | + 'maptype' => apply_filters('widget_maptype', $params['maptype']), |
|
144 | + /** |
|
145 | + * Filter the widget scrollwheel value of the map on home/listings page. |
|
146 | + * |
|
147 | + * Should the scrollwheel zoom the map or not. |
|
148 | + * |
|
149 | + * @since 1.0.0 |
|
150 | + * @param bool $params['scrollwheel'] True to allow scroll wheel to scroll map or false if not. |
|
151 | + */ |
|
152 | + 'scrollwheel' => apply_filters('widget_scrollwheel', $params['scrollwheel']), |
|
153 | + /** |
|
154 | + * Filter the widget zoom level of the map on home/listings page. |
|
155 | + * |
|
156 | + * @since 1.0.0 |
|
157 | + * @param int $params['zoom'] The zoom level of the map. Between 1-19. |
|
158 | + */ |
|
159 | + 'zoom' => apply_filters('widget_zoom', $params['zoom']), |
|
160 | + /** |
|
161 | + * Filter the widget auto zoom value of the map on home/listings page. |
|
162 | + * |
|
163 | + * If the map should autozoom to fit the markers shown. |
|
164 | + * |
|
165 | + * @since 1.0.0 |
|
166 | + * @param bool $params['autozoom'] True if the map should autozoom, false if not. |
|
167 | + */ |
|
168 | + 'autozoom' => apply_filters('widget_autozoom', $params['autozoom']), |
|
169 | + /** |
|
170 | + * Filter the widget child_collapse value of the map on home/listings page. |
|
171 | + * |
|
172 | + * If the map should auto collapse the child categories if the category bar is present. |
|
173 | + * |
|
174 | + * @since 1.0.0 |
|
175 | + * @param bool $params['child_collapse'] True if the map should collapse the categories, false if not. |
|
176 | + */ |
|
177 | + 'child_collapse' => apply_filters('widget_child_collapse', $params['child_collapse']), |
|
178 | + 'enable_cat_filters' => true, |
|
179 | + 'enable_text_search' => true, |
|
180 | + 'enable_post_type_filters' => true, |
|
181 | + /** |
|
182 | + * Filter the widget enable_location_filters value of the map on home/listings page. |
|
183 | + * |
|
184 | + * This is used when the location addon is used. |
|
185 | + * |
|
186 | + * @since 1.0.0 |
|
187 | + * @param bool $val True if location filters should be used, false if not. |
|
188 | + */ |
|
189 | + 'enable_location_filters' => apply_filters('geodir_home_map_enable_location_filters', false), |
|
190 | + 'enable_jason_on_load' => false, |
|
191 | + 'enable_marker_cluster' => false, |
|
192 | + 'enable_map_resize_button' => true, |
|
193 | + 'map_class_name' => 'geodir-map-home-page', |
|
194 | + 'is_geodir_home_map_widget' => true, |
|
195 | + ); |
|
196 | 196 | |
197 | 197 | // Add marker cluster |
198 | 198 | if (isset($params['marker_cluster']) && gdsc_to_bool_val($params['marker_cluster']) && defined('GDCLUSTER_VERSION')) { |
199 | - $map_args['enable_marker_cluster'] = true; |
|
200 | - if(get_option('geodir_marker_cluster_type')) { |
|
201 | - if ($map_args['autozoom']) { |
|
202 | - $map_args['enable_marker_cluster_no_reposition'] = false; |
|
203 | - } else { |
|
204 | - $map_args['enable_marker_cluster_no_reposition'] = true; |
|
205 | - } |
|
199 | + $map_args['enable_marker_cluster'] = true; |
|
200 | + if(get_option('geodir_marker_cluster_type')) { |
|
201 | + if ($map_args['autozoom']) { |
|
202 | + $map_args['enable_marker_cluster_no_reposition'] = false; |
|
203 | + } else { |
|
204 | + $map_args['enable_marker_cluster_no_reposition'] = true; |
|
205 | + } |
|
206 | 206 | |
207 | - $map_args['enable_marker_cluster_server'] = true ; |
|
207 | + $map_args['enable_marker_cluster_server'] = true ; |
|
208 | 208 | |
209 | - } |
|
209 | + } |
|
210 | 210 | } else { |
211 | 211 | $map_args['enable_marker_cluster'] = false; |
212 | 212 | } |
213 | 213 | |
214 | - // if lat and long set in shortcode, hack it so the map is not repositioned |
|
215 | - if(!empty($params['latitude']) && !empty($params['longitude']) ){ |
|
216 | - $map_args['enable_marker_cluster_no_reposition'] = true; |
|
217 | - } |
|
214 | + // if lat and long set in shortcode, hack it so the map is not repositioned |
|
215 | + if(!empty($params['latitude']) && !empty($params['longitude']) ){ |
|
216 | + $map_args['enable_marker_cluster_no_reposition'] = true; |
|
217 | + } |
|
218 | 218 | |
219 | 219 | |
220 | - geodir_draw_map($map_args); |
|
220 | + geodir_draw_map($map_args); |
|
221 | 221 | |
222 | - add_action('wp_footer', 'geodir_home_map_add_script', 100); |
|
222 | + add_action('wp_footer', 'geodir_home_map_add_script', 100); |
|
223 | 223 | |
224 | - $output = ob_get_contents(); |
|
224 | + $output = ob_get_contents(); |
|
225 | 225 | |
226 | - ob_end_clean(); |
|
226 | + ob_end_clean(); |
|
227 | 227 | |
228 | - return $output; |
|
228 | + return $output; |
|
229 | 229 | } |
230 | 230 | add_shortcode('gd_homepage_map', 'geodir_sc_home_map'); |
231 | 231 | |
@@ -264,243 +264,243 @@ discard block |
||
264 | 264 | */ |
265 | 265 | function geodir_sc_listing_map($atts) { |
266 | 266 | |
267 | - // if some params are set then we need a new query, if not then we can use the main query |
|
268 | - if( isset($atts['post_type']) || isset($atts['category']) || isset($atts['event_type']) ) { |
|
269 | - |
|
270 | - global $add_post_in_marker_array, $gd_sc_map_params; |
|
271 | - $backup_globals = array(); |
|
272 | - $backup_globals['add_post_in_marker_array'] = $add_post_in_marker_array; |
|
273 | - $backup_globals['gd_sc_map_params'] = $gd_sc_map_params; |
|
274 | - |
|
275 | - $defaults = array( |
|
276 | - 'width' => '294', |
|
277 | - 'height' => '370', |
|
278 | - 'zoom' => '13', |
|
279 | - 'autozoom' => '', |
|
280 | - 'sticky' => '', |
|
281 | - 'showall' => '0', |
|
282 | - 'scrollwheel' => '0', |
|
283 | - 'maptype' => 'ROADMAP', |
|
284 | - 'child_collapse' => 0, |
|
285 | - 'marker_cluster' => false, |
|
286 | - 'post_type' => 'gd_place', |
|
287 | - 'category' => '0', |
|
288 | - 'event_type' => 'all' |
|
289 | - ); |
|
290 | - |
|
291 | - $params = shortcode_atts( $defaults, $atts ); |
|
292 | - |
|
293 | - if ( ! ( gdsc_is_post_type_valid( $params['post_type'] ) ) ) { |
|
294 | - $params['post_type'] = 'gd_place'; |
|
295 | - } |
|
296 | - |
|
297 | - // Validate the selected category/ies - Grab the current list based on post_type |
|
298 | - $category_taxonomy = geodir_get_taxonomies( $params['post_type'] ); |
|
299 | - $categories = get_terms( $category_taxonomy, array( |
|
300 | - 'orderby' => 'count', |
|
301 | - 'order' => 'DESC', |
|
302 | - 'fields' => 'ids' |
|
303 | - ) ); |
|
304 | - |
|
305 | - // Make sure we have an array |
|
306 | - if ( ! ( is_array( $params['category'] ) ) ) { |
|
307 | - $params['category'] = explode( ',', $params['category'] ); |
|
308 | - } |
|
309 | - |
|
310 | - // Array_intersect returns only the items in $params['category'] that are also in our category list |
|
311 | - // Otherwise it becomes empty and later on that will mean "All" |
|
312 | - $params['category'] = array_intersect( $params['category'], $categories ); |
|
313 | - |
|
314 | - if ( $params['post_type'] == 'gd_event' ) { |
|
315 | - $params['event_type'] = gdsc_validate_list_filter_choice( $params['event_type'] ); |
|
316 | - } |
|
317 | - |
|
318 | - $params = gdsc_validate_map_args( $params ); |
|
319 | - |
|
320 | - $gd_sc_map_params = $params; |
|
321 | - |
|
322 | - $query_args = array( |
|
323 | - 'posts_per_page' => 1000000, //@todo kiran why was this added? |
|
324 | - 'is_geodir_loop' => true, |
|
325 | - 'gd_location' => false, |
|
326 | - 'post_type' => $params['post_type'], |
|
327 | - ); |
|
328 | - |
|
329 | - if ( ! empty( $params['category'] ) && isset( $params['category'][0] ) && (int) $params['category'][0] != 0 ) { |
|
330 | - $category_taxonomy = geodir_get_taxonomies( $params['post_type'] ); |
|
331 | - |
|
332 | - ######### WPML ######### |
|
333 | - if ( function_exists( 'icl_object_id' ) ) { |
|
334 | - $category = gd_lang_object_ids( $params['category'], $category_taxonomy[0] ); |
|
335 | - } |
|
336 | - ######### WPML ######### |
|
337 | - |
|
338 | - $tax_query = array( |
|
339 | - 'taxonomy' => $category_taxonomy[0], |
|
340 | - 'field' => 'id', |
|
341 | - 'terms' => $params['category'] |
|
342 | - ); |
|
343 | - |
|
344 | - $query_args['tax_query'] = array( $tax_query ); |
|
345 | - } |
|
346 | - |
|
347 | - $add_post_in_marker_array = true; |
|
348 | - |
|
349 | - if ( $params['post_type'] == 'gd_event' && function_exists( 'geodir_event_get_widget_events' ) ) { |
|
350 | - global $geodir_event_widget_listview; |
|
351 | - $geodir_event_widget_listview = true; |
|
352 | - |
|
353 | - $query_args['geodir_event_type'] = $params['event_type']; |
|
354 | - |
|
355 | - $listings = geodir_event_get_widget_events( $query_args ); |
|
356 | - |
|
357 | - $geodir_event_widget_listview = false; |
|
358 | - } else { |
|
359 | - $listings = geodir_get_widget_listings( $query_args ); |
|
360 | - } |
|
361 | - |
|
362 | - if ( ! empty( $listings ) ) { |
|
363 | - foreach ( $listings as $listing ) { |
|
364 | - create_marker_jason_of_posts( $listing ); |
|
365 | - } |
|
366 | - } |
|
367 | - |
|
368 | - ob_start(); |
|
369 | - add_action( 'wp_head', 'init_listing_map_script' ); // Initialize the map object and marker array |
|
370 | - |
|
371 | - add_action( 'the_post', 'create_list_jsondata' ); // Add marker in json array |
|
372 | - |
|
373 | - add_action( 'wp_footer', 'show_listing_widget_map' ); // Show map for listings with markers |
|
374 | - |
|
375 | - $default_location = geodir_get_default_location(); |
|
376 | - |
|
377 | - $map_args = array( |
|
378 | - 'map_canvas_name' => 'gd_listing_map', |
|
379 | - 'width' => $params['width'], |
|
380 | - 'height' => $params['height'], |
|
381 | - 'zoom' => $params['zoom'], |
|
382 | - 'autozoom' => $params['autozoom'], |
|
383 | - 'sticky' => $params['sticky'], |
|
384 | - 'showall' => $params['showall'], |
|
385 | - 'scrollwheel' => $params['scrollwheel'], |
|
386 | - 'maptype' => $params['maptype'], |
|
387 | - 'child_collapse' => 0, |
|
388 | - 'enable_cat_filters' => false, |
|
389 | - 'enable_text_search' => false, |
|
390 | - 'enable_post_type_filters' => false, |
|
391 | - 'enable_location_filters' => false, |
|
392 | - 'enable_jason_on_load' => true, |
|
393 | - 'ajax_url' => geodir_get_ajax_url(), |
|
394 | - 'latitude' => isset( $default_location->city_latitude ) ? $default_location->city_latitude : '', |
|
395 | - 'longitude' => isset( $default_location->city_longitude ) ? $default_location->city_longitude : '', |
|
396 | - 'streetViewControl' => true, |
|
397 | - 'showPreview' => '0', |
|
398 | - 'maxZoom' => 21, |
|
399 | - 'bubble_size' => 'small', |
|
400 | - ); |
|
401 | - |
|
402 | - if ( is_single() ) { |
|
403 | - global $post; |
|
404 | - if ( isset( $post->post_latitude ) ) { |
|
405 | - $map_args['latitude'] = $post->post_latitude; |
|
406 | - $map_args['longitude'] = $post->post_longitude; |
|
407 | - } |
|
408 | - |
|
409 | - $map_args['map_class_name'] = 'geodir-map-listing-page-single'; |
|
410 | - } else { |
|
411 | - $map_args['map_class_name'] = 'geodir-map-listing-page'; |
|
412 | - } |
|
413 | - |
|
414 | - // Add marker cluster |
|
415 | - if ( isset( $params['marker_cluster'] ) && gdsc_to_bool_val( $params['marker_cluster'] ) && defined( 'GDCLUSTER_VERSION' ) ) { |
|
416 | - $map_args['enable_marker_cluster'] = true; |
|
417 | - } else { |
|
418 | - $map_args['enable_marker_cluster'] = false; |
|
419 | - } |
|
420 | - |
|
421 | - geodir_draw_map( $map_args ); |
|
422 | - |
|
423 | - $output = ob_get_contents(); |
|
424 | - |
|
425 | - ob_end_clean(); |
|
426 | - |
|
427 | - foreach ( $backup_globals as $global => $value ) { |
|
428 | - ${$global} = $value; |
|
429 | - } |
|
430 | - |
|
431 | - return $output; |
|
432 | - }else{ |
|
433 | - ob_start(); |
|
434 | - add_action('wp_head', 'init_listing_map_script'); // Initialize the map object and marker array |
|
435 | - add_action('the_post', 'create_list_jsondata'); // Add marker in json array |
|
436 | - add_action('wp_footer', 'show_listing_widget_map'); // Show map for listings with markers |
|
437 | - $defaults = array( |
|
438 | - 'width' => '294', |
|
439 | - 'height' => '370', |
|
440 | - 'zoom' => '13', |
|
441 | - 'autozoom' => '', |
|
442 | - 'sticky' => '', |
|
443 | - 'showall' => '0', |
|
444 | - 'scrollwheel' => '0', |
|
445 | - 'maptype' => 'ROADMAP', |
|
446 | - 'child_collapse' => 0, |
|
447 | - 'marker_cluster' => false |
|
448 | - ); |
|
449 | - $params = shortcode_atts($defaults, $atts); |
|
450 | - $params = gdsc_validate_map_args($params); |
|
451 | - $map_args = array( |
|
452 | - 'map_canvas_name' => 'gd_listing_map', |
|
453 | - 'width' => $params['width'], |
|
454 | - 'height' => $params['height'], |
|
455 | - 'zoom' => $params['zoom'], |
|
456 | - 'autozoom' => $params['autozoom'], |
|
457 | - 'sticky' => $params['sticky'], |
|
458 | - 'showall' => $params['showall'], |
|
459 | - 'scrollwheel' => $params['scrollwheel'], |
|
460 | - 'child_collapse' => 0, |
|
461 | - 'enable_cat_filters' => false, |
|
462 | - 'enable_text_search' => false, |
|
463 | - 'enable_post_type_filters' => false, |
|
464 | - 'enable_location_filters' => false, |
|
465 | - 'enable_jason_on_load' => true, |
|
466 | - ); |
|
467 | - if (is_single()) { |
|
468 | - global $post; |
|
469 | - $map_default_lat = $address_latitude = $post->post_latitude; |
|
470 | - $map_default_lng = $address_longitude = $post->post_longitude; |
|
471 | - $mapview = $post->post_mapview; |
|
472 | - $map_args['zoom'] = $post->post_mapzoom; |
|
473 | - $map_args['map_class_name'] = 'geodir-map-listing-page-single'; |
|
474 | - } else { |
|
475 | - $default_location = geodir_get_default_location(); |
|
476 | - $map_default_lat = isset($default_location->city_latitude) ? $default_location->city_latitude : ''; |
|
477 | - $map_default_lng = isset($default_location->city_longitude) ? $default_location->city_longitude : ''; |
|
478 | - $map_args['map_class_name'] = 'geodir-map-listing-page'; |
|
479 | - } |
|
480 | - if (empty($mapview)) { |
|
481 | - $mapview = 'ROADMAP'; |
|
482 | - } |
|
483 | - // Set default map options |
|
484 | - $map_args['ajax_url'] = geodir_get_ajax_url(); |
|
485 | - $map_args['latitude'] = $map_default_lat; |
|
486 | - $map_args['longitude'] = $map_default_lng; |
|
487 | - $map_args['streetViewControl'] = true; |
|
488 | - $map_args['maptype'] = $mapview; |
|
489 | - $map_args['showPreview'] = '0'; |
|
490 | - $map_args['maxZoom'] = 21; |
|
491 | - $map_args['bubble_size'] = 'small'; |
|
492 | - |
|
493 | - // Add marker cluster |
|
494 | - if (isset($params['marker_cluster']) && gdsc_to_bool_val($params['marker_cluster']) && defined('GDCLUSTER_VERSION')) { |
|
495 | - $map_args['enable_marker_cluster'] = true; |
|
496 | - } else { |
|
497 | - $map_args['enable_marker_cluster'] = false; |
|
498 | - } |
|
499 | - geodir_draw_map($map_args); |
|
500 | - $output = ob_get_contents(); |
|
501 | - ob_end_clean(); |
|
502 | - return $output; |
|
503 | - } |
|
267 | + // if some params are set then we need a new query, if not then we can use the main query |
|
268 | + if( isset($atts['post_type']) || isset($atts['category']) || isset($atts['event_type']) ) { |
|
269 | + |
|
270 | + global $add_post_in_marker_array, $gd_sc_map_params; |
|
271 | + $backup_globals = array(); |
|
272 | + $backup_globals['add_post_in_marker_array'] = $add_post_in_marker_array; |
|
273 | + $backup_globals['gd_sc_map_params'] = $gd_sc_map_params; |
|
274 | + |
|
275 | + $defaults = array( |
|
276 | + 'width' => '294', |
|
277 | + 'height' => '370', |
|
278 | + 'zoom' => '13', |
|
279 | + 'autozoom' => '', |
|
280 | + 'sticky' => '', |
|
281 | + 'showall' => '0', |
|
282 | + 'scrollwheel' => '0', |
|
283 | + 'maptype' => 'ROADMAP', |
|
284 | + 'child_collapse' => 0, |
|
285 | + 'marker_cluster' => false, |
|
286 | + 'post_type' => 'gd_place', |
|
287 | + 'category' => '0', |
|
288 | + 'event_type' => 'all' |
|
289 | + ); |
|
290 | + |
|
291 | + $params = shortcode_atts( $defaults, $atts ); |
|
292 | + |
|
293 | + if ( ! ( gdsc_is_post_type_valid( $params['post_type'] ) ) ) { |
|
294 | + $params['post_type'] = 'gd_place'; |
|
295 | + } |
|
296 | + |
|
297 | + // Validate the selected category/ies - Grab the current list based on post_type |
|
298 | + $category_taxonomy = geodir_get_taxonomies( $params['post_type'] ); |
|
299 | + $categories = get_terms( $category_taxonomy, array( |
|
300 | + 'orderby' => 'count', |
|
301 | + 'order' => 'DESC', |
|
302 | + 'fields' => 'ids' |
|
303 | + ) ); |
|
304 | + |
|
305 | + // Make sure we have an array |
|
306 | + if ( ! ( is_array( $params['category'] ) ) ) { |
|
307 | + $params['category'] = explode( ',', $params['category'] ); |
|
308 | + } |
|
309 | + |
|
310 | + // Array_intersect returns only the items in $params['category'] that are also in our category list |
|
311 | + // Otherwise it becomes empty and later on that will mean "All" |
|
312 | + $params['category'] = array_intersect( $params['category'], $categories ); |
|
313 | + |
|
314 | + if ( $params['post_type'] == 'gd_event' ) { |
|
315 | + $params['event_type'] = gdsc_validate_list_filter_choice( $params['event_type'] ); |
|
316 | + } |
|
317 | + |
|
318 | + $params = gdsc_validate_map_args( $params ); |
|
319 | + |
|
320 | + $gd_sc_map_params = $params; |
|
321 | + |
|
322 | + $query_args = array( |
|
323 | + 'posts_per_page' => 1000000, //@todo kiran why was this added? |
|
324 | + 'is_geodir_loop' => true, |
|
325 | + 'gd_location' => false, |
|
326 | + 'post_type' => $params['post_type'], |
|
327 | + ); |
|
328 | + |
|
329 | + if ( ! empty( $params['category'] ) && isset( $params['category'][0] ) && (int) $params['category'][0] != 0 ) { |
|
330 | + $category_taxonomy = geodir_get_taxonomies( $params['post_type'] ); |
|
331 | + |
|
332 | + ######### WPML ######### |
|
333 | + if ( function_exists( 'icl_object_id' ) ) { |
|
334 | + $category = gd_lang_object_ids( $params['category'], $category_taxonomy[0] ); |
|
335 | + } |
|
336 | + ######### WPML ######### |
|
337 | + |
|
338 | + $tax_query = array( |
|
339 | + 'taxonomy' => $category_taxonomy[0], |
|
340 | + 'field' => 'id', |
|
341 | + 'terms' => $params['category'] |
|
342 | + ); |
|
343 | + |
|
344 | + $query_args['tax_query'] = array( $tax_query ); |
|
345 | + } |
|
346 | + |
|
347 | + $add_post_in_marker_array = true; |
|
348 | + |
|
349 | + if ( $params['post_type'] == 'gd_event' && function_exists( 'geodir_event_get_widget_events' ) ) { |
|
350 | + global $geodir_event_widget_listview; |
|
351 | + $geodir_event_widget_listview = true; |
|
352 | + |
|
353 | + $query_args['geodir_event_type'] = $params['event_type']; |
|
354 | + |
|
355 | + $listings = geodir_event_get_widget_events( $query_args ); |
|
356 | + |
|
357 | + $geodir_event_widget_listview = false; |
|
358 | + } else { |
|
359 | + $listings = geodir_get_widget_listings( $query_args ); |
|
360 | + } |
|
361 | + |
|
362 | + if ( ! empty( $listings ) ) { |
|
363 | + foreach ( $listings as $listing ) { |
|
364 | + create_marker_jason_of_posts( $listing ); |
|
365 | + } |
|
366 | + } |
|
367 | + |
|
368 | + ob_start(); |
|
369 | + add_action( 'wp_head', 'init_listing_map_script' ); // Initialize the map object and marker array |
|
370 | + |
|
371 | + add_action( 'the_post', 'create_list_jsondata' ); // Add marker in json array |
|
372 | + |
|
373 | + add_action( 'wp_footer', 'show_listing_widget_map' ); // Show map for listings with markers |
|
374 | + |
|
375 | + $default_location = geodir_get_default_location(); |
|
376 | + |
|
377 | + $map_args = array( |
|
378 | + 'map_canvas_name' => 'gd_listing_map', |
|
379 | + 'width' => $params['width'], |
|
380 | + 'height' => $params['height'], |
|
381 | + 'zoom' => $params['zoom'], |
|
382 | + 'autozoom' => $params['autozoom'], |
|
383 | + 'sticky' => $params['sticky'], |
|
384 | + 'showall' => $params['showall'], |
|
385 | + 'scrollwheel' => $params['scrollwheel'], |
|
386 | + 'maptype' => $params['maptype'], |
|
387 | + 'child_collapse' => 0, |
|
388 | + 'enable_cat_filters' => false, |
|
389 | + 'enable_text_search' => false, |
|
390 | + 'enable_post_type_filters' => false, |
|
391 | + 'enable_location_filters' => false, |
|
392 | + 'enable_jason_on_load' => true, |
|
393 | + 'ajax_url' => geodir_get_ajax_url(), |
|
394 | + 'latitude' => isset( $default_location->city_latitude ) ? $default_location->city_latitude : '', |
|
395 | + 'longitude' => isset( $default_location->city_longitude ) ? $default_location->city_longitude : '', |
|
396 | + 'streetViewControl' => true, |
|
397 | + 'showPreview' => '0', |
|
398 | + 'maxZoom' => 21, |
|
399 | + 'bubble_size' => 'small', |
|
400 | + ); |
|
401 | + |
|
402 | + if ( is_single() ) { |
|
403 | + global $post; |
|
404 | + if ( isset( $post->post_latitude ) ) { |
|
405 | + $map_args['latitude'] = $post->post_latitude; |
|
406 | + $map_args['longitude'] = $post->post_longitude; |
|
407 | + } |
|
408 | + |
|
409 | + $map_args['map_class_name'] = 'geodir-map-listing-page-single'; |
|
410 | + } else { |
|
411 | + $map_args['map_class_name'] = 'geodir-map-listing-page'; |
|
412 | + } |
|
413 | + |
|
414 | + // Add marker cluster |
|
415 | + if ( isset( $params['marker_cluster'] ) && gdsc_to_bool_val( $params['marker_cluster'] ) && defined( 'GDCLUSTER_VERSION' ) ) { |
|
416 | + $map_args['enable_marker_cluster'] = true; |
|
417 | + } else { |
|
418 | + $map_args['enable_marker_cluster'] = false; |
|
419 | + } |
|
420 | + |
|
421 | + geodir_draw_map( $map_args ); |
|
422 | + |
|
423 | + $output = ob_get_contents(); |
|
424 | + |
|
425 | + ob_end_clean(); |
|
426 | + |
|
427 | + foreach ( $backup_globals as $global => $value ) { |
|
428 | + ${$global} = $value; |
|
429 | + } |
|
430 | + |
|
431 | + return $output; |
|
432 | + }else{ |
|
433 | + ob_start(); |
|
434 | + add_action('wp_head', 'init_listing_map_script'); // Initialize the map object and marker array |
|
435 | + add_action('the_post', 'create_list_jsondata'); // Add marker in json array |
|
436 | + add_action('wp_footer', 'show_listing_widget_map'); // Show map for listings with markers |
|
437 | + $defaults = array( |
|
438 | + 'width' => '294', |
|
439 | + 'height' => '370', |
|
440 | + 'zoom' => '13', |
|
441 | + 'autozoom' => '', |
|
442 | + 'sticky' => '', |
|
443 | + 'showall' => '0', |
|
444 | + 'scrollwheel' => '0', |
|
445 | + 'maptype' => 'ROADMAP', |
|
446 | + 'child_collapse' => 0, |
|
447 | + 'marker_cluster' => false |
|
448 | + ); |
|
449 | + $params = shortcode_atts($defaults, $atts); |
|
450 | + $params = gdsc_validate_map_args($params); |
|
451 | + $map_args = array( |
|
452 | + 'map_canvas_name' => 'gd_listing_map', |
|
453 | + 'width' => $params['width'], |
|
454 | + 'height' => $params['height'], |
|
455 | + 'zoom' => $params['zoom'], |
|
456 | + 'autozoom' => $params['autozoom'], |
|
457 | + 'sticky' => $params['sticky'], |
|
458 | + 'showall' => $params['showall'], |
|
459 | + 'scrollwheel' => $params['scrollwheel'], |
|
460 | + 'child_collapse' => 0, |
|
461 | + 'enable_cat_filters' => false, |
|
462 | + 'enable_text_search' => false, |
|
463 | + 'enable_post_type_filters' => false, |
|
464 | + 'enable_location_filters' => false, |
|
465 | + 'enable_jason_on_load' => true, |
|
466 | + ); |
|
467 | + if (is_single()) { |
|
468 | + global $post; |
|
469 | + $map_default_lat = $address_latitude = $post->post_latitude; |
|
470 | + $map_default_lng = $address_longitude = $post->post_longitude; |
|
471 | + $mapview = $post->post_mapview; |
|
472 | + $map_args['zoom'] = $post->post_mapzoom; |
|
473 | + $map_args['map_class_name'] = 'geodir-map-listing-page-single'; |
|
474 | + } else { |
|
475 | + $default_location = geodir_get_default_location(); |
|
476 | + $map_default_lat = isset($default_location->city_latitude) ? $default_location->city_latitude : ''; |
|
477 | + $map_default_lng = isset($default_location->city_longitude) ? $default_location->city_longitude : ''; |
|
478 | + $map_args['map_class_name'] = 'geodir-map-listing-page'; |
|
479 | + } |
|
480 | + if (empty($mapview)) { |
|
481 | + $mapview = 'ROADMAP'; |
|
482 | + } |
|
483 | + // Set default map options |
|
484 | + $map_args['ajax_url'] = geodir_get_ajax_url(); |
|
485 | + $map_args['latitude'] = $map_default_lat; |
|
486 | + $map_args['longitude'] = $map_default_lng; |
|
487 | + $map_args['streetViewControl'] = true; |
|
488 | + $map_args['maptype'] = $mapview; |
|
489 | + $map_args['showPreview'] = '0'; |
|
490 | + $map_args['maxZoom'] = 21; |
|
491 | + $map_args['bubble_size'] = 'small'; |
|
492 | + |
|
493 | + // Add marker cluster |
|
494 | + if (isset($params['marker_cluster']) && gdsc_to_bool_val($params['marker_cluster']) && defined('GDCLUSTER_VERSION')) { |
|
495 | + $map_args['enable_marker_cluster'] = true; |
|
496 | + } else { |
|
497 | + $map_args['enable_marker_cluster'] = false; |
|
498 | + } |
|
499 | + geodir_draw_map($map_args); |
|
500 | + $output = ob_get_contents(); |
|
501 | + ob_end_clean(); |
|
502 | + return $output; |
|
503 | + } |
|
504 | 504 | } |
505 | 505 | |
506 | 506 | add_shortcode('gd_listing_slider', 'geodir_sc_listing_slider'); |
@@ -533,120 +533,120 @@ discard block |
||
533 | 533 | */ |
534 | 534 | function geodir_sc_listing_slider($atts) |
535 | 535 | { |
536 | - ob_start(); |
|
537 | - $defaults = array( |
|
538 | - 'post_type' => 'gd_place', |
|
539 | - 'category' => '0', |
|
540 | - 'post_number' => '5', |
|
541 | - 'slideshow' => '0', |
|
542 | - 'animation_loop' => 0, |
|
543 | - 'direction_nav' => 0, |
|
544 | - 'slideshow_speed' => 5000, |
|
545 | - 'animation_speed' => 600, |
|
546 | - 'animation' => 'slide', |
|
547 | - 'order_by' => 'latest', |
|
548 | - 'show_title' => '', |
|
549 | - 'show_featured_only' => '', |
|
550 | - 'title' => '', |
|
551 | - ); |
|
552 | - |
|
553 | - $params = shortcode_atts($defaults, $atts); |
|
554 | - |
|
555 | - |
|
556 | - /* |
|
536 | + ob_start(); |
|
537 | + $defaults = array( |
|
538 | + 'post_type' => 'gd_place', |
|
539 | + 'category' => '0', |
|
540 | + 'post_number' => '5', |
|
541 | + 'slideshow' => '0', |
|
542 | + 'animation_loop' => 0, |
|
543 | + 'direction_nav' => 0, |
|
544 | + 'slideshow_speed' => 5000, |
|
545 | + 'animation_speed' => 600, |
|
546 | + 'animation' => 'slide', |
|
547 | + 'order_by' => 'latest', |
|
548 | + 'show_title' => '', |
|
549 | + 'show_featured_only' => '', |
|
550 | + 'title' => '', |
|
551 | + ); |
|
552 | + |
|
553 | + $params = shortcode_atts($defaults, $atts); |
|
554 | + |
|
555 | + |
|
556 | + /* |
|
557 | 557 | * |
558 | 558 | * Now we begin the validation of the attributes. |
559 | 559 | */ |
560 | - // Check we have a valid post_type |
|
561 | - if (!(gdsc_is_post_type_valid($params['post_type']))) { |
|
562 | - $params['post_type'] = 'gd_place'; |
|
563 | - } |
|
564 | - |
|
565 | - // Check we have a valid sort_order |
|
566 | - $params['order_by'] = gdsc_validate_sort_choice($params['order_by']); |
|
567 | - |
|
568 | - // Match the chosen animation to our options |
|
569 | - $animation_list = array('slide', 'fade'); |
|
570 | - if (!(in_array($params['animation'], $animation_list))) { |
|
571 | - $params['animation'] = 'slide'; |
|
572 | - } |
|
573 | - |
|
574 | - // Post_number needs to be a positive integer |
|
575 | - $params['post_number'] = absint($params['post_number']); |
|
576 | - if (0 == $params['post_number']) { |
|
577 | - $params['post_number'] = 1; |
|
578 | - } |
|
579 | - |
|
580 | - // Manage the entered categories |
|
581 | - if (0 != $params['category'] || '' != $params['category']) { |
|
582 | - $params['category'] = gdsc_manage_category_choice($params['post_type'], $params['category']); |
|
583 | - } |
|
584 | - // Convert show_title to a bool |
|
585 | - $params['show_title'] = intval(gdsc_to_bool_val($params['show_title'])); |
|
586 | - |
|
587 | - // Convert show_featured_only to a bool |
|
588 | - $params['show_featured_only'] = intval(gdsc_to_bool_val($params['show_featured_only'])); |
|
589 | - |
|
590 | - /* |
|
560 | + // Check we have a valid post_type |
|
561 | + if (!(gdsc_is_post_type_valid($params['post_type']))) { |
|
562 | + $params['post_type'] = 'gd_place'; |
|
563 | + } |
|
564 | + |
|
565 | + // Check we have a valid sort_order |
|
566 | + $params['order_by'] = gdsc_validate_sort_choice($params['order_by']); |
|
567 | + |
|
568 | + // Match the chosen animation to our options |
|
569 | + $animation_list = array('slide', 'fade'); |
|
570 | + if (!(in_array($params['animation'], $animation_list))) { |
|
571 | + $params['animation'] = 'slide'; |
|
572 | + } |
|
573 | + |
|
574 | + // Post_number needs to be a positive integer |
|
575 | + $params['post_number'] = absint($params['post_number']); |
|
576 | + if (0 == $params['post_number']) { |
|
577 | + $params['post_number'] = 1; |
|
578 | + } |
|
579 | + |
|
580 | + // Manage the entered categories |
|
581 | + if (0 != $params['category'] || '' != $params['category']) { |
|
582 | + $params['category'] = gdsc_manage_category_choice($params['post_type'], $params['category']); |
|
583 | + } |
|
584 | + // Convert show_title to a bool |
|
585 | + $params['show_title'] = intval(gdsc_to_bool_val($params['show_title'])); |
|
586 | + |
|
587 | + // Convert show_featured_only to a bool |
|
588 | + $params['show_featured_only'] = intval(gdsc_to_bool_val($params['show_featured_only'])); |
|
589 | + |
|
590 | + /* |
|
591 | 591 | * Hopefully all attributes are now valid, and safe to pass forward |
592 | 592 | */ |
593 | 593 | |
594 | - // redeclare vars after validation |
|
595 | - |
|
596 | - if (isset($params['direction_nav'])) { |
|
597 | - $params['directionNav'] = $params['direction_nav']; |
|
598 | - } |
|
599 | - if (isset($params['animation_loop'])) { |
|
600 | - $params['animationLoop'] = $params['animation_loop']; |
|
601 | - } |
|
602 | - if (isset($params['slideshow_speed'])) { |
|
603 | - $params['slideshowSpeed'] = $params['slideshow_speed']; |
|
604 | - } |
|
605 | - if (isset($params['animation_speed'])) { |
|
606 | - $params['animationSpeed'] = $params['animation_speed']; |
|
607 | - } |
|
608 | - if (isset($params['order_by'])) { |
|
609 | - $params['list_sort'] = $params['order_by']; |
|
610 | - } |
|
611 | - |
|
612 | - $query_args = array( |
|
613 | - 'post_number' => $params['post_number'], |
|
614 | - 'is_geodir_loop' => true, |
|
615 | - 'post_type' => $params['post_type'], |
|
616 | - 'order_by' => $params['order_by'] |
|
617 | - ); |
|
618 | - |
|
619 | - if (1 == $params['show_featured_only']) { |
|
620 | - $query_args['show_featured_only'] = 1; |
|
621 | - } |
|
622 | - |
|
623 | - if (0 != $params['category'] && '' != $params['category']) { |
|
624 | - $category_taxonomy = geodir_get_taxonomies($params['post_type']); |
|
625 | - $tax_query = array( |
|
626 | - 'taxonomy' => $category_taxonomy[0], |
|
627 | - 'field' => 'id', |
|
628 | - 'terms' => $params['category'], |
|
629 | - ); |
|
630 | - |
|
631 | - $query_args['tax_query'] = array($tax_query); |
|
632 | - } |
|
633 | - |
|
634 | - $defaults = array( |
|
635 | - 'before_widget' => '', |
|
636 | - 'after_widget' => '', |
|
637 | - 'before_title' => '', |
|
638 | - 'after_title' => '', |
|
639 | - ); |
|
640 | - |
|
641 | - $query_args = array_merge($query_args, $params); |
|
642 | - |
|
643 | - geodir_listing_slider_widget_output($defaults, $query_args); |
|
644 | - |
|
645 | - $output = ob_get_contents(); |
|
646 | - |
|
647 | - ob_end_clean(); |
|
648 | - |
|
649 | - return $output; |
|
594 | + // redeclare vars after validation |
|
595 | + |
|
596 | + if (isset($params['direction_nav'])) { |
|
597 | + $params['directionNav'] = $params['direction_nav']; |
|
598 | + } |
|
599 | + if (isset($params['animation_loop'])) { |
|
600 | + $params['animationLoop'] = $params['animation_loop']; |
|
601 | + } |
|
602 | + if (isset($params['slideshow_speed'])) { |
|
603 | + $params['slideshowSpeed'] = $params['slideshow_speed']; |
|
604 | + } |
|
605 | + if (isset($params['animation_speed'])) { |
|
606 | + $params['animationSpeed'] = $params['animation_speed']; |
|
607 | + } |
|
608 | + if (isset($params['order_by'])) { |
|
609 | + $params['list_sort'] = $params['order_by']; |
|
610 | + } |
|
611 | + |
|
612 | + $query_args = array( |
|
613 | + 'post_number' => $params['post_number'], |
|
614 | + 'is_geodir_loop' => true, |
|
615 | + 'post_type' => $params['post_type'], |
|
616 | + 'order_by' => $params['order_by'] |
|
617 | + ); |
|
618 | + |
|
619 | + if (1 == $params['show_featured_only']) { |
|
620 | + $query_args['show_featured_only'] = 1; |
|
621 | + } |
|
622 | + |
|
623 | + if (0 != $params['category'] && '' != $params['category']) { |
|
624 | + $category_taxonomy = geodir_get_taxonomies($params['post_type']); |
|
625 | + $tax_query = array( |
|
626 | + 'taxonomy' => $category_taxonomy[0], |
|
627 | + 'field' => 'id', |
|
628 | + 'terms' => $params['category'], |
|
629 | + ); |
|
630 | + |
|
631 | + $query_args['tax_query'] = array($tax_query); |
|
632 | + } |
|
633 | + |
|
634 | + $defaults = array( |
|
635 | + 'before_widget' => '', |
|
636 | + 'after_widget' => '', |
|
637 | + 'before_title' => '', |
|
638 | + 'after_title' => '', |
|
639 | + ); |
|
640 | + |
|
641 | + $query_args = array_merge($query_args, $params); |
|
642 | + |
|
643 | + geodir_listing_slider_widget_output($defaults, $query_args); |
|
644 | + |
|
645 | + $output = ob_get_contents(); |
|
646 | + |
|
647 | + ob_end_clean(); |
|
648 | + |
|
649 | + return $output; |
|
650 | 650 | } |
651 | 651 | |
652 | 652 | add_shortcode('gd_login_box', 'geodir_sc_login_box'); |
@@ -670,22 +670,22 @@ discard block |
||
670 | 670 | */ |
671 | 671 | function geodir_sc_login_box($atts) |
672 | 672 | { |
673 | - ob_start(); |
|
673 | + ob_start(); |
|
674 | 674 | |
675 | - $defaults = array( |
|
676 | - 'before_widget' => '', |
|
677 | - 'after_widget' => '', |
|
678 | - 'before_title' => '', |
|
679 | - 'after_title' => '', |
|
680 | - ); |
|
675 | + $defaults = array( |
|
676 | + 'before_widget' => '', |
|
677 | + 'after_widget' => '', |
|
678 | + 'before_title' => '', |
|
679 | + 'after_title' => '', |
|
680 | + ); |
|
681 | 681 | |
682 | - geodir_loginwidget_output($defaults, $defaults); |
|
682 | + geodir_loginwidget_output($defaults, $defaults); |
|
683 | 683 | |
684 | - $output = ob_get_contents(); |
|
684 | + $output = ob_get_contents(); |
|
685 | 685 | |
686 | - ob_end_clean(); |
|
686 | + ob_end_clean(); |
|
687 | 687 | |
688 | - return $output; |
|
688 | + return $output; |
|
689 | 689 | } |
690 | 690 | |
691 | 691 | add_shortcode('gd_popular_post_category', 'geodir_sc_popular_post_category'); |
@@ -716,31 +716,31 @@ discard block |
||
716 | 716 | */ |
717 | 717 | function geodir_sc_popular_post_category($atts) |
718 | 718 | { |
719 | - ob_start(); |
|
720 | - global $geodir_post_category_str; |
|
721 | - $defaults = array( |
|
722 | - 'category_limit' => 15, |
|
723 | - 'category_restrict' => false, |
|
724 | - 'before_widget' => '', |
|
725 | - 'after_widget' => '', |
|
726 | - 'before_title' => '', |
|
727 | - 'after_title' => '', |
|
728 | - 'title' => '', |
|
729 | - 'default_post_type' => '', |
|
730 | - 'parent_only' => false, |
|
731 | - ); |
|
732 | - |
|
733 | - $params = shortcode_atts($defaults, $atts, 'popular_post_category'); |
|
734 | - $params['category_limit'] = absint($params['category_limit']); |
|
735 | - $params['default_post_type'] = gdsc_is_post_type_valid($params['default_post_type']) ? $params['default_post_type'] : ''; |
|
736 | - $params['parent_only'] = gdsc_to_bool_val($params['parent_only']); |
|
737 | - geodir_popular_post_category_output($params, $params); |
|
738 | - |
|
739 | - $output = ob_get_contents(); |
|
740 | - |
|
741 | - ob_end_clean(); |
|
742 | - |
|
743 | - return $output; |
|
719 | + ob_start(); |
|
720 | + global $geodir_post_category_str; |
|
721 | + $defaults = array( |
|
722 | + 'category_limit' => 15, |
|
723 | + 'category_restrict' => false, |
|
724 | + 'before_widget' => '', |
|
725 | + 'after_widget' => '', |
|
726 | + 'before_title' => '', |
|
727 | + 'after_title' => '', |
|
728 | + 'title' => '', |
|
729 | + 'default_post_type' => '', |
|
730 | + 'parent_only' => false, |
|
731 | + ); |
|
732 | + |
|
733 | + $params = shortcode_atts($defaults, $atts, 'popular_post_category'); |
|
734 | + $params['category_limit'] = absint($params['category_limit']); |
|
735 | + $params['default_post_type'] = gdsc_is_post_type_valid($params['default_post_type']) ? $params['default_post_type'] : ''; |
|
736 | + $params['parent_only'] = gdsc_to_bool_val($params['parent_only']); |
|
737 | + geodir_popular_post_category_output($params, $params); |
|
738 | + |
|
739 | + $output = ob_get_contents(); |
|
740 | + |
|
741 | + ob_end_clean(); |
|
742 | + |
|
743 | + return $output; |
|
744 | 744 | } |
745 | 745 | |
746 | 746 | add_shortcode('gd_popular_post_view', 'geodir_sc_popular_post_view'); |
@@ -781,96 +781,96 @@ discard block |
||
781 | 781 | */ |
782 | 782 | function geodir_sc_popular_post_view($atts) |
783 | 783 | { |
784 | - ob_start(); |
|
785 | - $defaults = array( |
|
786 | - 'post_type' => 'gd_place', |
|
787 | - 'category' => '0', |
|
788 | - 'post_number' => '5', |
|
789 | - 'layout' => 'gridview_onehalf', |
|
790 | - 'add_location_filter' => '0', |
|
791 | - 'list_sort' => 'latest', |
|
792 | - 'use_viewing_post_type' => '1', |
|
793 | - 'character_count' => '20', |
|
794 | - 'listing_width' => '', |
|
795 | - 'show_featured_only' => '0', |
|
796 | - 'show_special_only' => '0', |
|
797 | - 'with_pics_only' => '0', |
|
798 | - 'with_videos_only' => '0', |
|
799 | - 'before_widget' => '', |
|
800 | - 'after_widget' => '', |
|
801 | - 'before_title' => '<h3 class="widget-title">', |
|
802 | - 'after_title' => '</h3>', |
|
803 | - 'title' => '', |
|
804 | - 'category_title' => '', |
|
805 | - ); |
|
806 | - |
|
807 | - $params = shortcode_atts($defaults, $atts); |
|
808 | - |
|
809 | - /** |
|
810 | - * Validate our incoming params |
|
811 | - */ |
|
784 | + ob_start(); |
|
785 | + $defaults = array( |
|
786 | + 'post_type' => 'gd_place', |
|
787 | + 'category' => '0', |
|
788 | + 'post_number' => '5', |
|
789 | + 'layout' => 'gridview_onehalf', |
|
790 | + 'add_location_filter' => '0', |
|
791 | + 'list_sort' => 'latest', |
|
792 | + 'use_viewing_post_type' => '1', |
|
793 | + 'character_count' => '20', |
|
794 | + 'listing_width' => '', |
|
795 | + 'show_featured_only' => '0', |
|
796 | + 'show_special_only' => '0', |
|
797 | + 'with_pics_only' => '0', |
|
798 | + 'with_videos_only' => '0', |
|
799 | + 'before_widget' => '', |
|
800 | + 'after_widget' => '', |
|
801 | + 'before_title' => '<h3 class="widget-title">', |
|
802 | + 'after_title' => '</h3>', |
|
803 | + 'title' => '', |
|
804 | + 'category_title' => '', |
|
805 | + ); |
|
812 | 806 | |
813 | - // Validate the selected post type, default to gd_place on fail |
|
814 | - if (!(gdsc_is_post_type_valid($params['post_type']))) { |
|
815 | - $params['post_type'] = 'gd_place'; |
|
816 | - } |
|
817 | - |
|
818 | - // Validate the selected category/ies - Grab the current list based on post_type |
|
819 | - $category_taxonomy = geodir_get_taxonomies($params['post_type']); |
|
820 | - $categories = get_terms($category_taxonomy, array('orderby' => 'count', 'order' => 'DESC', 'fields' => 'ids')); |
|
821 | - |
|
822 | - // Make sure we have an array |
|
823 | - if (!(is_array($params['category']))) { |
|
824 | - $params['category'] = explode(',', $params['category']); |
|
825 | - } |
|
826 | - |
|
827 | - // Array_intersect returns only the items in $params['category'] that are also in our category list |
|
828 | - // Otherwise it becomes empty and later on that will mean "All" |
|
829 | - $params['category'] = array_intersect($params['category'], $categories); |
|
830 | - |
|
831 | - // Post_number needs to be a positive integer |
|
832 | - $params['post_number'] = absint($params['post_number']); |
|
833 | - if (0 == $params['post_number']) { |
|
834 | - $params['post_number'] = 1; |
|
835 | - } |
|
836 | - |
|
837 | - // Validate our layout choice |
|
838 | - // Outside of the norm, I added some more simple terms to match the existing |
|
839 | - // So now I just run the switch to set it properly. |
|
840 | - $params['layout'] = gdsc_validate_layout_choice($params['layout']); |
|
841 | - |
|
842 | - // Validate our sorting choice |
|
843 | - $params['list_sort'] = gdsc_validate_sort_choice($params['list_sort'], $params['post_type']); |
|
844 | - |
|
845 | - // Validate character_count |
|
846 | - if ($params['character_count'] !== '') { |
|
847 | - $params['character_count'] = absint($params['character_count']); |
|
848 | - } |
|
849 | - |
|
850 | - // Validate Listing width, used in the template widget-listing-listview.php |
|
851 | - // The context is in width=$listing_width% - So we need a positive number between 0 & 100 |
|
852 | - $params['listing_width'] = gdsc_validate_listing_width($params['listing_width']); |
|
853 | - |
|
854 | - // Validate the checkboxes used on the widget |
|
855 | - $params['add_location_filter'] = gdsc_to_bool_val($params['add_location_filter']); |
|
856 | - $params['show_featured_only'] = gdsc_to_bool_val($params['show_featured_only']); |
|
857 | - $params['show_special_only'] = gdsc_to_bool_val($params['show_special_only']); |
|
858 | - $params['with_pics_only'] = gdsc_to_bool_val($params['with_pics_only']); |
|
859 | - $params['with_videos_only'] = gdsc_to_bool_val($params['with_videos_only']); |
|
860 | - $params['use_viewing_post_type'] = gdsc_to_bool_val($params['use_viewing_post_type']); |
|
861 | - |
|
862 | - /** |
|
863 | - * End of validation |
|
864 | - */ |
|
807 | + $params = shortcode_atts($defaults, $atts); |
|
808 | + |
|
809 | + /** |
|
810 | + * Validate our incoming params |
|
811 | + */ |
|
812 | + |
|
813 | + // Validate the selected post type, default to gd_place on fail |
|
814 | + if (!(gdsc_is_post_type_valid($params['post_type']))) { |
|
815 | + $params['post_type'] = 'gd_place'; |
|
816 | + } |
|
817 | + |
|
818 | + // Validate the selected category/ies - Grab the current list based on post_type |
|
819 | + $category_taxonomy = geodir_get_taxonomies($params['post_type']); |
|
820 | + $categories = get_terms($category_taxonomy, array('orderby' => 'count', 'order' => 'DESC', 'fields' => 'ids')); |
|
821 | + |
|
822 | + // Make sure we have an array |
|
823 | + if (!(is_array($params['category']))) { |
|
824 | + $params['category'] = explode(',', $params['category']); |
|
825 | + } |
|
865 | 826 | |
866 | - geodir_popular_postview_output($params, $params); |
|
827 | + // Array_intersect returns only the items in $params['category'] that are also in our category list |
|
828 | + // Otherwise it becomes empty and later on that will mean "All" |
|
829 | + $params['category'] = array_intersect($params['category'], $categories); |
|
867 | 830 | |
831 | + // Post_number needs to be a positive integer |
|
832 | + $params['post_number'] = absint($params['post_number']); |
|
833 | + if (0 == $params['post_number']) { |
|
834 | + $params['post_number'] = 1; |
|
835 | + } |
|
836 | + |
|
837 | + // Validate our layout choice |
|
838 | + // Outside of the norm, I added some more simple terms to match the existing |
|
839 | + // So now I just run the switch to set it properly. |
|
840 | + $params['layout'] = gdsc_validate_layout_choice($params['layout']); |
|
841 | + |
|
842 | + // Validate our sorting choice |
|
843 | + $params['list_sort'] = gdsc_validate_sort_choice($params['list_sort'], $params['post_type']); |
|
844 | + |
|
845 | + // Validate character_count |
|
846 | + if ($params['character_count'] !== '') { |
|
847 | + $params['character_count'] = absint($params['character_count']); |
|
848 | + } |
|
849 | + |
|
850 | + // Validate Listing width, used in the template widget-listing-listview.php |
|
851 | + // The context is in width=$listing_width% - So we need a positive number between 0 & 100 |
|
852 | + $params['listing_width'] = gdsc_validate_listing_width($params['listing_width']); |
|
868 | 853 | |
869 | - $output = ob_get_contents(); |
|
854 | + // Validate the checkboxes used on the widget |
|
855 | + $params['add_location_filter'] = gdsc_to_bool_val($params['add_location_filter']); |
|
856 | + $params['show_featured_only'] = gdsc_to_bool_val($params['show_featured_only']); |
|
857 | + $params['show_special_only'] = gdsc_to_bool_val($params['show_special_only']); |
|
858 | + $params['with_pics_only'] = gdsc_to_bool_val($params['with_pics_only']); |
|
859 | + $params['with_videos_only'] = gdsc_to_bool_val($params['with_videos_only']); |
|
860 | + $params['use_viewing_post_type'] = gdsc_to_bool_val($params['use_viewing_post_type']); |
|
870 | 861 | |
871 | - ob_end_clean(); |
|
862 | + /** |
|
863 | + * End of validation |
|
864 | + */ |
|
872 | 865 | |
873 | - return $output; |
|
866 | + geodir_popular_postview_output($params, $params); |
|
867 | + |
|
868 | + |
|
869 | + $output = ob_get_contents(); |
|
870 | + |
|
871 | + ob_end_clean(); |
|
872 | + |
|
873 | + return $output; |
|
874 | 874 | } |
875 | 875 | |
876 | 876 | add_shortcode('gd_recent_reviews', 'geodir_sc_recent_reviews'); |
@@ -892,37 +892,37 @@ discard block |
||
892 | 892 | * @return string Recent reviews HTML. |
893 | 893 | */ |
894 | 894 | function geodir_sc_recent_reviews($atts) { |
895 | - ob_start(); |
|
896 | - $defaults = array( |
|
895 | + ob_start(); |
|
896 | + $defaults = array( |
|
897 | 897 | 'title' => '', |
898 | 898 | 'count' => 5, |
899 | - ); |
|
899 | + ); |
|
900 | 900 | |
901 | - $params = shortcode_atts($defaults, $atts); |
|
901 | + $params = shortcode_atts($defaults, $atts); |
|
902 | 902 | |
903 | - $count = absint($params['count']); |
|
904 | - if (0 == $count) { |
|
905 | - $count = 1; |
|
906 | - } |
|
903 | + $count = absint($params['count']); |
|
904 | + if (0 == $count) { |
|
905 | + $count = 1; |
|
906 | + } |
|
907 | 907 | |
908 | 908 | $title = !empty($params['title']) ? __($params['title'], 'geodirectory') : ''; |
909 | 909 | |
910 | - $comments_li = geodir_get_recent_reviews(30, $count, 100, false); |
|
910 | + $comments_li = geodir_get_recent_reviews(30, $count, 100, false); |
|
911 | 911 | |
912 | - if ($comments_li) { |
|
913 | - if ($title != '') { ?> |
|
912 | + if ($comments_li) { |
|
913 | + if ($title != '') { ?> |
|
914 | 914 | <h3 class="geodir-sc-recent-reviews-title widget-title"><?php echo $title; ?></h3> |
915 | 915 | <?php } ?> |
916 | 916 | <div class="geodir_sc_recent_reviews_section"> |
917 | 917 | <ul class="geodir_sc_recent_reviews"><?php echo $comments_li; ?></ul> |
918 | 918 | </div> |
919 | 919 | <?php |
920 | - } |
|
921 | - $output = ob_get_contents(); |
|
920 | + } |
|
921 | + $output = ob_get_contents(); |
|
922 | 922 | |
923 | - ob_end_clean(); |
|
923 | + ob_end_clean(); |
|
924 | 924 | |
925 | - return $output; |
|
925 | + return $output; |
|
926 | 926 | } |
927 | 927 | |
928 | 928 | add_shortcode('gd_related_listings', 'geodir_sc_related_listings'); |
@@ -952,63 +952,63 @@ discard block |
||
952 | 952 | */ |
953 | 953 | function geodir_sc_related_listings($atts) |
954 | 954 | { |
955 | - ob_start(); |
|
956 | - $defaults = array( |
|
957 | - 'post_number' => 5, |
|
958 | - 'relate_to' => 'category', |
|
959 | - 'layout' => 'gridview_onehalf', |
|
960 | - 'add_location_filter' => 0, |
|
961 | - 'listing_width' => '', |
|
962 | - 'list_sort' => 'latest', |
|
963 | - 'character_count' => 20, |
|
964 | - 'is_widget' => 1, |
|
965 | - 'before_title' => '<style type="text/css">.geodir_category_list_view li{margin:0px!important}</style>', |
|
966 | - ); |
|
967 | - // The "before_title" code is an ugly & terrible hack. But it works for now. I should enqueue a new stylesheet. |
|
968 | - |
|
969 | - $params = shortcode_atts($defaults, $atts); |
|
970 | - |
|
971 | - /** |
|
972 | - * Begin validating parameters |
|
973 | - */ |
|
955 | + ob_start(); |
|
956 | + $defaults = array( |
|
957 | + 'post_number' => 5, |
|
958 | + 'relate_to' => 'category', |
|
959 | + 'layout' => 'gridview_onehalf', |
|
960 | + 'add_location_filter' => 0, |
|
961 | + 'listing_width' => '', |
|
962 | + 'list_sort' => 'latest', |
|
963 | + 'character_count' => 20, |
|
964 | + 'is_widget' => 1, |
|
965 | + 'before_title' => '<style type="text/css">.geodir_category_list_view li{margin:0px!important}</style>', |
|
966 | + ); |
|
967 | + // The "before_title" code is an ugly & terrible hack. But it works for now. I should enqueue a new stylesheet. |
|
974 | 968 | |
975 | - // Validate that post_number is a number and is 1 or higher |
|
976 | - $params['post_number'] = absint($params['post_number']); |
|
977 | - if (0 === $params['post_number']) { |
|
978 | - $params['post_number'] = 1; |
|
979 | - } |
|
969 | + $params = shortcode_atts($defaults, $atts); |
|
980 | 970 | |
981 | - // Validate relate_to - only category or tags |
|
982 | - $params['relate_to'] = geodir_strtolower($params['relate_to']); |
|
983 | - if ('category' != $params['relate_to'] && 'tags' != $params['relate_to']) { |
|
984 | - $params['relate_to'] = 'category'; |
|
985 | - } |
|
971 | + /** |
|
972 | + * Begin validating parameters |
|
973 | + */ |
|
986 | 974 | |
987 | - // Validate layout selection |
|
988 | - $params['layout'] = gdsc_validate_layout_choice($params['layout']); |
|
975 | + // Validate that post_number is a number and is 1 or higher |
|
976 | + $params['post_number'] = absint($params['post_number']); |
|
977 | + if (0 === $params['post_number']) { |
|
978 | + $params['post_number'] = 1; |
|
979 | + } |
|
989 | 980 | |
990 | - // Validate sorting option |
|
991 | - $params['list_sort'] = gdsc_validate_sort_choice($params['list_sort']); |
|
981 | + // Validate relate_to - only category or tags |
|
982 | + $params['relate_to'] = geodir_strtolower($params['relate_to']); |
|
983 | + if ('category' != $params['relate_to'] && 'tags' != $params['relate_to']) { |
|
984 | + $params['relate_to'] = 'category'; |
|
985 | + } |
|
986 | + |
|
987 | + // Validate layout selection |
|
988 | + $params['layout'] = gdsc_validate_layout_choice($params['layout']); |
|
992 | 989 | |
993 | - // Validate add_location_filter |
|
994 | - $params['add_location_filter'] = gdsc_to_bool_val($params['add_location_filter']); |
|
990 | + // Validate sorting option |
|
991 | + $params['list_sort'] = gdsc_validate_sort_choice($params['list_sort']); |
|
995 | 992 | |
996 | - // Validate listing_width |
|
997 | - $params['listing_width'] = gdsc_validate_listing_width($params['listing_width']); |
|
993 | + // Validate add_location_filter |
|
994 | + $params['add_location_filter'] = gdsc_to_bool_val($params['add_location_filter']); |
|
998 | 995 | |
999 | - // Validate character_count |
|
1000 | - if ($params['character_count'] !== '') { |
|
1001 | - $params['character_count'] = absint($params['character_count']); |
|
1002 | - } |
|
996 | + // Validate listing_width |
|
997 | + $params['listing_width'] = gdsc_validate_listing_width($params['listing_width']); |
|
1003 | 998 | |
1004 | - if ($related_display = geodir_related_posts_display($params)) { |
|
1005 | - echo $related_display; |
|
1006 | - } |
|
1007 | - $output = ob_get_contents(); |
|
999 | + // Validate character_count |
|
1000 | + if ($params['character_count'] !== '') { |
|
1001 | + $params['character_count'] = absint($params['character_count']); |
|
1002 | + } |
|
1003 | + |
|
1004 | + if ($related_display = geodir_related_posts_display($params)) { |
|
1005 | + echo $related_display; |
|
1006 | + } |
|
1007 | + $output = ob_get_contents(); |
|
1008 | 1008 | |
1009 | - ob_end_clean(); |
|
1009 | + ob_end_clean(); |
|
1010 | 1010 | |
1011 | - return $output; |
|
1011 | + return $output; |
|
1012 | 1012 | } |
1013 | 1013 | |
1014 | 1014 | /** |
@@ -1032,13 +1032,13 @@ discard block |
||
1032 | 1032 | * @return string Advanced search widget HTML. |
1033 | 1033 | */ |
1034 | 1034 | function geodir_sc_advanced_search($atts) { |
1035 | - $defaults = array( |
|
1035 | + $defaults = array( |
|
1036 | 1036 | 'title' => '', |
1037 | 1037 | 'before_widget' => '<section id="geodir_advanced_search-1" class="widget geodir-widget geodir_advance_search_widget">', |
1038 | - 'after_widget' => '</section>', |
|
1039 | - 'before_title' => '<h3 class="widget-title">', |
|
1040 | - 'after_title' => '</h3>', |
|
1041 | - 'show_adv_search' => 'default', |
|
1038 | + 'after_widget' => '</section>', |
|
1039 | + 'before_title' => '<h3 class="widget-title">', |
|
1040 | + 'after_title' => '</h3>', |
|
1041 | + 'show_adv_search' => 'default', |
|
1042 | 1042 | 'post_type' => '' |
1043 | 1043 | ); |
1044 | 1044 | |
@@ -1062,9 +1062,9 @@ discard block |
||
1062 | 1062 | the_widget('geodir_advance_search_widget', $params, $params ); |
1063 | 1063 | |
1064 | 1064 | $output = ob_get_contents(); |
1065 | - ob_end_clean(); |
|
1065 | + ob_end_clean(); |
|
1066 | 1066 | |
1067 | - return $output; |
|
1067 | + return $output; |
|
1068 | 1068 | } |
1069 | 1069 | add_shortcode('gd_advanced_search', 'geodir_sc_advanced_search'); |
1070 | 1070 | |
@@ -1110,48 +1110,48 @@ discard block |
||
1110 | 1110 | 'add_location_filter' => '1', |
1111 | 1111 | 'tab_layout' => 'bestof-tabs-on-top', |
1112 | 1112 | 'before_widget' => '<section id="bestof_widget-1" class="widget geodir-widget geodir_bestof_widget geodir_sc_bestof_widget">', |
1113 | - 'after_widget' => '</section>', |
|
1114 | - 'before_title' => '<h3 class="widget-title">', |
|
1115 | - 'after_title' => '</h3>', |
|
1113 | + 'after_widget' => '</section>', |
|
1114 | + 'before_title' => '<h3 class="widget-title">', |
|
1115 | + 'after_title' => '</h3>', |
|
1116 | 1116 | ); |
1117 | 1117 | $params = shortcode_atts($defaults, $atts); |
1118 | 1118 | |
1119 | - /** |
|
1120 | - * Validate our incoming params |
|
1121 | - */ |
|
1119 | + /** |
|
1120 | + * Validate our incoming params |
|
1121 | + */ |
|
1122 | 1122 | |
1123 | - // Validate the selected post type, default to gd_place on fail |
|
1124 | - if (!(gdsc_is_post_type_valid($params['post_type']))) { |
|
1125 | - $params['post_type'] = 'gd_place'; |
|
1126 | - } |
|
1123 | + // Validate the selected post type, default to gd_place on fail |
|
1124 | + if (!(gdsc_is_post_type_valid($params['post_type']))) { |
|
1125 | + $params['post_type'] = 'gd_place'; |
|
1126 | + } |
|
1127 | 1127 | |
1128 | 1128 | // Post limit needs to be a positive integer |
1129 | - $params['post_limit'] = absint($params['post_limit']); |
|
1130 | - if (0 == $params['post_limit']) { |
|
1131 | - $params['post_limit'] = 5; |
|
1132 | - } |
|
1129 | + $params['post_limit'] = absint($params['post_limit']); |
|
1130 | + if (0 == $params['post_limit']) { |
|
1131 | + $params['post_limit'] = 5; |
|
1132 | + } |
|
1133 | 1133 | |
1134 | 1134 | // Category limit needs to be a positive integer |
1135 | - $params['categ_limit'] = absint($params['categ_limit']); |
|
1136 | - if (0 == $params['categ_limit']) { |
|
1137 | - $params['categ_limit'] = 3; |
|
1138 | - } |
|
1135 | + $params['categ_limit'] = absint($params['categ_limit']); |
|
1136 | + if (0 == $params['categ_limit']) { |
|
1137 | + $params['categ_limit'] = 3; |
|
1138 | + } |
|
1139 | 1139 | |
1140 | 1140 | // Tab layout validation |
1141 | - $params['tab_layout'] = $params['tab_layout']; |
|
1142 | - if (!in_array($params['tab_layout'], array('bestof-tabs-on-top', 'bestof-tabs-on-left', 'bestof-tabs-as-dropdown'))) { |
|
1143 | - $params['tab_layout'] = 'bestof-tabs-on-top'; |
|
1144 | - } |
|
1141 | + $params['tab_layout'] = $params['tab_layout']; |
|
1142 | + if (!in_array($params['tab_layout'], array('bestof-tabs-on-top', 'bestof-tabs-on-left', 'bestof-tabs-as-dropdown'))) { |
|
1143 | + $params['tab_layout'] = 'bestof-tabs-on-top'; |
|
1144 | + } |
|
1145 | 1145 | |
1146 | 1146 | // Validate character_count |
1147 | - $params['character_count'] = $params['character_count']; |
|
1147 | + $params['character_count'] = $params['character_count']; |
|
1148 | 1148 | |
1149 | 1149 | ob_start(); |
1150 | 1150 | the_widget('geodir_bestof_widget', $params, $params); |
1151 | - $output = ob_get_contents(); |
|
1152 | - ob_end_clean(); |
|
1151 | + $output = ob_get_contents(); |
|
1152 | + ob_end_clean(); |
|
1153 | 1153 | |
1154 | - return $output; |
|
1154 | + return $output; |
|
1155 | 1155 | } |
1156 | 1156 | add_shortcode('gd_bestof_widget', 'geodir_sc_bestof_widget'); |
1157 | 1157 | |
@@ -1204,143 +1204,143 @@ discard block |
||
1204 | 1204 | * @return string HTML content to display geodirectory listings. |
1205 | 1205 | */ |
1206 | 1206 | function geodir_sc_gd_listings($atts, $content = '') { |
1207 | - global $post; |
|
1208 | - $defaults = array( |
|
1209 | - 'title' => '', |
|
1210 | - 'post_type' => 'gd_place', |
|
1211 | - 'category' => 0, |
|
1212 | - 'list_sort' => 'latest', |
|
1213 | - 'event_type' => '', |
|
1214 | - 'post_number' => 10, |
|
1215 | - 'post_author' => '', |
|
1216 | - 'layout' => 'gridview_onehalf', |
|
1217 | - 'listing_width' => '', |
|
1218 | - 'character_count' => 20, |
|
1219 | - 'add_location_filter' => 1, |
|
1220 | - 'show_featured_only' => '', |
|
1221 | - 'show_special_only' => '', |
|
1222 | - 'with_pics_only' => '', |
|
1223 | - 'with_videos_only' => '', |
|
1224 | - 'with_pagination' => '1', |
|
1225 | - 'top_pagination' => '0', |
|
1226 | - 'bottom_pagination' => '1', |
|
1227 | - 'without_no_results' => 0, |
|
1228 | - 'tags' => '', |
|
1229 | - 'show_favorites_only' => '', |
|
1230 | - 'favorites_by_user' => '', |
|
1231 | - ); |
|
1232 | - $params = shortcode_atts($defaults, $atts); |
|
1233 | - |
|
1234 | - $params['title'] = wp_strip_all_tags($params['title']); |
|
1235 | - $params['post_type'] = gdsc_is_post_type_valid($params['post_type']) ? $params['post_type'] : 'gd_place'; |
|
1236 | - |
|
1237 | - // Validate the selected category/ies - Grab the current list based on post_type |
|
1238 | - $category_taxonomy = geodir_get_taxonomies($params['post_type']); |
|
1239 | - $categories = get_terms($category_taxonomy, array('orderby' => 'count', 'order' => 'DESC', 'fields' => 'ids', 'hide_empty' => 0)); |
|
1240 | - |
|
1241 | - // Make sure we have an array |
|
1242 | - if (!(is_array($params['category']))) { |
|
1243 | - $params['category'] = explode(',', $params['category']); |
|
1244 | - } |
|
1245 | - |
|
1246 | - // Array_intersect returns only the items in $params['category'] that are also in our category list |
|
1247 | - // Otherwise it becomes empty and later on that will mean "All" |
|
1248 | - $params['category'] = array_intersect($params['category'], $categories); |
|
1249 | - |
|
1250 | - // Post_number needs to be a positive integer |
|
1251 | - $params['post_number'] = absint($params['post_number']); |
|
1252 | - $params['post_number'] = $params['post_number'] > 0 ? $params['post_number'] : 10; |
|
1207 | + global $post; |
|
1208 | + $defaults = array( |
|
1209 | + 'title' => '', |
|
1210 | + 'post_type' => 'gd_place', |
|
1211 | + 'category' => 0, |
|
1212 | + 'list_sort' => 'latest', |
|
1213 | + 'event_type' => '', |
|
1214 | + 'post_number' => 10, |
|
1215 | + 'post_author' => '', |
|
1216 | + 'layout' => 'gridview_onehalf', |
|
1217 | + 'listing_width' => '', |
|
1218 | + 'character_count' => 20, |
|
1219 | + 'add_location_filter' => 1, |
|
1220 | + 'show_featured_only' => '', |
|
1221 | + 'show_special_only' => '', |
|
1222 | + 'with_pics_only' => '', |
|
1223 | + 'with_videos_only' => '', |
|
1224 | + 'with_pagination' => '1', |
|
1225 | + 'top_pagination' => '0', |
|
1226 | + 'bottom_pagination' => '1', |
|
1227 | + 'without_no_results' => 0, |
|
1228 | + 'tags' => '', |
|
1229 | + 'show_favorites_only' => '', |
|
1230 | + 'favorites_by_user' => '', |
|
1231 | + ); |
|
1232 | + $params = shortcode_atts($defaults, $atts); |
|
1233 | + |
|
1234 | + $params['title'] = wp_strip_all_tags($params['title']); |
|
1235 | + $params['post_type'] = gdsc_is_post_type_valid($params['post_type']) ? $params['post_type'] : 'gd_place'; |
|
1236 | + |
|
1237 | + // Validate the selected category/ies - Grab the current list based on post_type |
|
1238 | + $category_taxonomy = geodir_get_taxonomies($params['post_type']); |
|
1239 | + $categories = get_terms($category_taxonomy, array('orderby' => 'count', 'order' => 'DESC', 'fields' => 'ids', 'hide_empty' => 0)); |
|
1240 | + |
|
1241 | + // Make sure we have an array |
|
1242 | + if (!(is_array($params['category']))) { |
|
1243 | + $params['category'] = explode(',', $params['category']); |
|
1244 | + } |
|
1245 | + |
|
1246 | + // Array_intersect returns only the items in $params['category'] that are also in our category list |
|
1247 | + // Otherwise it becomes empty and later on that will mean "All" |
|
1248 | + $params['category'] = array_intersect($params['category'], $categories); |
|
1249 | + |
|
1250 | + // Post_number needs to be a positive integer |
|
1251 | + $params['post_number'] = absint($params['post_number']); |
|
1252 | + $params['post_number'] = $params['post_number'] > 0 ? $params['post_number'] : 10; |
|
1253 | 1253 | |
1254 | - // Post_number needs to be a positive integer |
|
1255 | - if (!empty($atts['post_author'])) { |
|
1256 | - if ($atts['post_author'] == 'current' && !empty($post) && isset($post->post_author) && $post->post_type != 'page') { |
|
1257 | - $params['post_author'] = $post->post_author; |
|
1258 | - } else if ($atts['post_author'] != 'current' && absint($atts['post_author']) > 0) { |
|
1259 | - $params['post_author'] = absint($atts['post_author']); |
|
1260 | - } else { |
|
1261 | - unset($params['post_author']); |
|
1262 | - } |
|
1263 | - } else { |
|
1264 | - unset($params['post_author']); |
|
1265 | - } |
|
1266 | - |
|
1267 | - // Validate character_count |
|
1268 | - //todo: is this necessary? |
|
1269 | - $params['character_count'] = $params['character_count']; |
|
1270 | - |
|
1271 | - // Validate our layout choice |
|
1272 | - // Outside of the norm, I added some more simple terms to match the existing |
|
1273 | - // So now I just run the switch to set it properly. |
|
1274 | - $params['layout'] = gdsc_validate_layout_choice($params['layout']); |
|
1275 | - |
|
1276 | - // Validate our sorting choice |
|
1277 | - $params['list_sort'] = gdsc_validate_sort_choice($params['list_sort'], $params['post_type']); |
|
1278 | - |
|
1279 | - // Validate Listing width, used in the template widget-listing-listview.php |
|
1280 | - // The context is in width=$listing_width% - So we need a positive number between 0 & 100 |
|
1281 | - $params['listing_width'] = gdsc_validate_listing_width($params['listing_width']); |
|
1282 | - |
|
1283 | - // Validate the checkboxes used on the widget |
|
1284 | - $params['add_location_filter'] = gdsc_to_bool_val($params['add_location_filter']); |
|
1285 | - $params['show_featured_only'] = gdsc_to_bool_val($params['show_featured_only']); |
|
1286 | - $params['show_special_only'] = gdsc_to_bool_val($params['show_special_only']); |
|
1287 | - $params['with_pics_only'] = gdsc_to_bool_val($params['with_pics_only']); |
|
1288 | - $params['with_videos_only'] = gdsc_to_bool_val($params['with_videos_only']); |
|
1289 | - $params['with_pagination'] = gdsc_to_bool_val($params['with_pagination']); |
|
1290 | - $params['top_pagination'] = gdsc_to_bool_val($params['top_pagination']); |
|
1291 | - $params['bottom_pagination'] = gdsc_to_bool_val($params['bottom_pagination']); |
|
1254 | + // Post_number needs to be a positive integer |
|
1255 | + if (!empty($atts['post_author'])) { |
|
1256 | + if ($atts['post_author'] == 'current' && !empty($post) && isset($post->post_author) && $post->post_type != 'page') { |
|
1257 | + $params['post_author'] = $post->post_author; |
|
1258 | + } else if ($atts['post_author'] != 'current' && absint($atts['post_author']) > 0) { |
|
1259 | + $params['post_author'] = absint($atts['post_author']); |
|
1260 | + } else { |
|
1261 | + unset($params['post_author']); |
|
1262 | + } |
|
1263 | + } else { |
|
1264 | + unset($params['post_author']); |
|
1265 | + } |
|
1266 | + |
|
1267 | + // Validate character_count |
|
1268 | + //todo: is this necessary? |
|
1269 | + $params['character_count'] = $params['character_count']; |
|
1270 | + |
|
1271 | + // Validate our layout choice |
|
1272 | + // Outside of the norm, I added some more simple terms to match the existing |
|
1273 | + // So now I just run the switch to set it properly. |
|
1274 | + $params['layout'] = gdsc_validate_layout_choice($params['layout']); |
|
1275 | + |
|
1276 | + // Validate our sorting choice |
|
1277 | + $params['list_sort'] = gdsc_validate_sort_choice($params['list_sort'], $params['post_type']); |
|
1278 | + |
|
1279 | + // Validate Listing width, used in the template widget-listing-listview.php |
|
1280 | + // The context is in width=$listing_width% - So we need a positive number between 0 & 100 |
|
1281 | + $params['listing_width'] = gdsc_validate_listing_width($params['listing_width']); |
|
1282 | + |
|
1283 | + // Validate the checkboxes used on the widget |
|
1284 | + $params['add_location_filter'] = gdsc_to_bool_val($params['add_location_filter']); |
|
1285 | + $params['show_featured_only'] = gdsc_to_bool_val($params['show_featured_only']); |
|
1286 | + $params['show_special_only'] = gdsc_to_bool_val($params['show_special_only']); |
|
1287 | + $params['with_pics_only'] = gdsc_to_bool_val($params['with_pics_only']); |
|
1288 | + $params['with_videos_only'] = gdsc_to_bool_val($params['with_videos_only']); |
|
1289 | + $params['with_pagination'] = gdsc_to_bool_val($params['with_pagination']); |
|
1290 | + $params['top_pagination'] = gdsc_to_bool_val($params['top_pagination']); |
|
1291 | + $params['bottom_pagination'] = gdsc_to_bool_val($params['bottom_pagination']); |
|
1292 | 1292 | |
1293 | - // User favorites |
|
1294 | - $params['show_favorites_only'] = gdsc_to_bool_val($params['show_favorites_only']); |
|
1295 | - if (!empty($params['show_favorites_only'])) { |
|
1296 | - if ($params['favorites_by_user'] == 'current' && !empty($post) && isset($post->post_author) && $post->post_type != 'page') { |
|
1297 | - $params['favorites_by_user'] = $post->post_author; |
|
1298 | - } else if ($params['favorites_by_user'] != 'current' && absint($params['favorites_by_user']) > 0) { |
|
1299 | - $params['favorites_by_user'] = absint($atts['favorites_by_user']); |
|
1300 | - } else if ($params['favorites_by_user'] != 'current' && $current_user_id = get_current_user_id()) { |
|
1301 | - $params['favorites_by_user'] = $current_user_id; |
|
1302 | - } else { |
|
1303 | - $params['favorites_by_user'] = 0; |
|
1304 | - } |
|
1305 | - } |
|
1306 | - |
|
1307 | - // Clean tags |
|
1308 | - if (!empty($params['tags'])) { |
|
1309 | - if (!is_array($params['tags'])) { |
|
1310 | - $comma = _x(',', 'tag delimiter'); |
|
1311 | - if ( ',' !== $comma ) { |
|
1312 | - $params['tags'] = str_replace($comma, ',', $params['tags']); |
|
1313 | - } |
|
1314 | - $params['tags'] = explode(',', trim($params['tags'], " \n\t\r\0\x0B,")); |
|
1315 | - $params['tags'] = array_map('trim', $params['tags']); |
|
1316 | - } |
|
1317 | - } else { |
|
1318 | - $params['tags'] = array(); |
|
1319 | - } |
|
1320 | - |
|
1321 | - /** |
|
1322 | - * End of validation |
|
1323 | - */ |
|
1324 | - if (isset($atts['geodir_ajax'])) { |
|
1325 | - $params['geodir_ajax'] = $atts['geodir_ajax']; |
|
1326 | - unset($atts['geodir_ajax']); |
|
1327 | - } |
|
1328 | - if (isset($atts['pageno'])) { |
|
1329 | - $params['pageno'] = $atts['pageno']; |
|
1330 | - unset($atts['pageno']); |
|
1331 | - } |
|
1332 | - |
|
1333 | - if ( !empty($atts['shortcode_content']) ) { |
|
1334 | - $content = $atts['shortcode_content']; |
|
1335 | - } |
|
1336 | - $params['shortcode_content'] = trim($content); |
|
1337 | - $atts['shortcode_content'] = trim($content); |
|
1293 | + // User favorites |
|
1294 | + $params['show_favorites_only'] = gdsc_to_bool_val($params['show_favorites_only']); |
|
1295 | + if (!empty($params['show_favorites_only'])) { |
|
1296 | + if ($params['favorites_by_user'] == 'current' && !empty($post) && isset($post->post_author) && $post->post_type != 'page') { |
|
1297 | + $params['favorites_by_user'] = $post->post_author; |
|
1298 | + } else if ($params['favorites_by_user'] != 'current' && absint($params['favorites_by_user']) > 0) { |
|
1299 | + $params['favorites_by_user'] = absint($atts['favorites_by_user']); |
|
1300 | + } else if ($params['favorites_by_user'] != 'current' && $current_user_id = get_current_user_id()) { |
|
1301 | + $params['favorites_by_user'] = $current_user_id; |
|
1302 | + } else { |
|
1303 | + $params['favorites_by_user'] = 0; |
|
1304 | + } |
|
1305 | + } |
|
1306 | + |
|
1307 | + // Clean tags |
|
1308 | + if (!empty($params['tags'])) { |
|
1309 | + if (!is_array($params['tags'])) { |
|
1310 | + $comma = _x(',', 'tag delimiter'); |
|
1311 | + if ( ',' !== $comma ) { |
|
1312 | + $params['tags'] = str_replace($comma, ',', $params['tags']); |
|
1313 | + } |
|
1314 | + $params['tags'] = explode(',', trim($params['tags'], " \n\t\r\0\x0B,")); |
|
1315 | + $params['tags'] = array_map('trim', $params['tags']); |
|
1316 | + } |
|
1317 | + } else { |
|
1318 | + $params['tags'] = array(); |
|
1319 | + } |
|
1320 | + |
|
1321 | + /** |
|
1322 | + * End of validation |
|
1323 | + */ |
|
1324 | + if (isset($atts['geodir_ajax'])) { |
|
1325 | + $params['geodir_ajax'] = $atts['geodir_ajax']; |
|
1326 | + unset($atts['geodir_ajax']); |
|
1327 | + } |
|
1328 | + if (isset($atts['pageno'])) { |
|
1329 | + $params['pageno'] = $atts['pageno']; |
|
1330 | + unset($atts['pageno']); |
|
1331 | + } |
|
1332 | + |
|
1333 | + if ( !empty($atts['shortcode_content']) ) { |
|
1334 | + $content = $atts['shortcode_content']; |
|
1335 | + } |
|
1336 | + $params['shortcode_content'] = trim($content); |
|
1337 | + $atts['shortcode_content'] = trim($content); |
|
1338 | 1338 | |
1339 | - $params['shortcode_atts'] = $atts; |
|
1339 | + $params['shortcode_atts'] = $atts; |
|
1340 | 1340 | |
1341 | - $output = geodir_sc_gd_listings_output($params); |
|
1341 | + $output = geodir_sc_gd_listings_output($params); |
|
1342 | 1342 | |
1343 | - return $output; |
|
1343 | + return $output; |
|
1344 | 1344 | } |
1345 | 1345 | add_shortcode('gd_listings', 'geodir_sc_gd_listings'); |
1346 | 1346 | |
@@ -1380,56 +1380,56 @@ discard block |
||
1380 | 1380 | * @return string HTML content to display CPT categories. |
1381 | 1381 | */ |
1382 | 1382 | function geodir_sc_cpt_categories_widget($atts, $content = '') { |
1383 | - $defaults = array( |
|
1384 | - 'title' => '', |
|
1385 | - 'post_type' => '', // NULL for all |
|
1386 | - 'hide_empty' => '', |
|
1387 | - 'show_count' => '', |
|
1388 | - 'hide_icon' => '', |
|
1389 | - 'cpt_left' => '', |
|
1390 | - 'sort_by' => 'count', |
|
1391 | - 'max_count' => 'all', |
|
1392 | - 'max_level' => '1', |
|
1393 | - 'no_cpt_filter' => '', |
|
1394 | - 'no_cat_filter' => '', |
|
1395 | - 'before_widget' => '<section id="geodir_cpt_categories_widget-1" class="widget geodir-widget geodir_cpt_categories_widget geodir_sc_cpt_categories_widget">', |
|
1396 | - 'after_widget' => '</section>', |
|
1397 | - 'before_title' => '<h3 class="widget-title">', |
|
1398 | - 'after_title' => '</h3>', |
|
1399 | - ); |
|
1400 | - $params = shortcode_atts($defaults, $atts); |
|
1401 | - |
|
1402 | - /** |
|
1403 | - * Validate our incoming params |
|
1404 | - */ |
|
1405 | - // Make sure we have an array |
|
1406 | - $params['post_type'] = !is_array($params['post_type']) && trim($params['post_type']) != '' ? explode(',', trim($params['post_type'])) : array(); |
|
1407 | - |
|
1408 | - // Validate the checkboxes used on the widget |
|
1409 | - $params['hide_empty'] = gdsc_to_bool_val($params['hide_empty']); |
|
1410 | - $params['show_count'] = gdsc_to_bool_val($params['show_count']); |
|
1411 | - $params['hide_icon'] = gdsc_to_bool_val($params['hide_icon']); |
|
1412 | - $params['cpt_left'] = gdsc_to_bool_val($params['cpt_left']); |
|
1383 | + $defaults = array( |
|
1384 | + 'title' => '', |
|
1385 | + 'post_type' => '', // NULL for all |
|
1386 | + 'hide_empty' => '', |
|
1387 | + 'show_count' => '', |
|
1388 | + 'hide_icon' => '', |
|
1389 | + 'cpt_left' => '', |
|
1390 | + 'sort_by' => 'count', |
|
1391 | + 'max_count' => 'all', |
|
1392 | + 'max_level' => '1', |
|
1393 | + 'no_cpt_filter' => '', |
|
1394 | + 'no_cat_filter' => '', |
|
1395 | + 'before_widget' => '<section id="geodir_cpt_categories_widget-1" class="widget geodir-widget geodir_cpt_categories_widget geodir_sc_cpt_categories_widget">', |
|
1396 | + 'after_widget' => '</section>', |
|
1397 | + 'before_title' => '<h3 class="widget-title">', |
|
1398 | + 'after_title' => '</h3>', |
|
1399 | + ); |
|
1400 | + $params = shortcode_atts($defaults, $atts); |
|
1413 | 1401 | |
1414 | - if ($params['max_count'] != 'all') { |
|
1415 | - $params['max_count'] = absint($params['max_count']); |
|
1416 | - } |
|
1402 | + /** |
|
1403 | + * Validate our incoming params |
|
1404 | + */ |
|
1405 | + // Make sure we have an array |
|
1406 | + $params['post_type'] = !is_array($params['post_type']) && trim($params['post_type']) != '' ? explode(',', trim($params['post_type'])) : array(); |
|
1407 | + |
|
1408 | + // Validate the checkboxes used on the widget |
|
1409 | + $params['hide_empty'] = gdsc_to_bool_val($params['hide_empty']); |
|
1410 | + $params['show_count'] = gdsc_to_bool_val($params['show_count']); |
|
1411 | + $params['hide_icon'] = gdsc_to_bool_val($params['hide_icon']); |
|
1412 | + $params['cpt_left'] = gdsc_to_bool_val($params['cpt_left']); |
|
1413 | + |
|
1414 | + if ($params['max_count'] != 'all') { |
|
1415 | + $params['max_count'] = absint($params['max_count']); |
|
1416 | + } |
|
1417 | 1417 | |
1418 | - if ($params['max_level'] != 'all') { |
|
1419 | - $params['max_level'] = absint($params['max_level']); |
|
1420 | - } |
|
1418 | + if ($params['max_level'] != 'all') { |
|
1419 | + $params['max_level'] = absint($params['max_level']); |
|
1420 | + } |
|
1421 | 1421 | |
1422 | - $params['no_cpt_filter'] = gdsc_to_bool_val($params['no_cpt_filter']); |
|
1423 | - $params['no_cat_filter'] = gdsc_to_bool_val($params['no_cat_filter']); |
|
1422 | + $params['no_cpt_filter'] = gdsc_to_bool_val($params['no_cpt_filter']); |
|
1423 | + $params['no_cat_filter'] = gdsc_to_bool_val($params['no_cat_filter']); |
|
1424 | 1424 | |
1425 | - $params['sort_by'] = $params['sort_by'] == 'az' ? 'az' : 'count'; |
|
1425 | + $params['sort_by'] = $params['sort_by'] == 'az' ? 'az' : 'count'; |
|
1426 | 1426 | |
1427 | - ob_start(); |
|
1428 | - the_widget('geodir_cpt_categories_widget', $params, $params); |
|
1429 | - $output = ob_get_contents(); |
|
1430 | - ob_end_clean(); |
|
1427 | + ob_start(); |
|
1428 | + the_widget('geodir_cpt_categories_widget', $params, $params); |
|
1429 | + $output = ob_get_contents(); |
|
1430 | + ob_end_clean(); |
|
1431 | 1431 | |
1432 | - return $output; |
|
1432 | + return $output; |
|
1433 | 1433 | } |
1434 | 1434 | add_shortcode('gd_cpt_categories', 'geodir_sc_cpt_categories_widget'); |
1435 | 1435 | |
@@ -1444,6 +1444,6 @@ discard block |
||
1444 | 1444 | * @return string HTML code. |
1445 | 1445 | */ |
1446 | 1446 | function geodir_sc_responsive_videos($atts, $content) { |
1447 | - return '<div class="geodir-video-wrapper">'.$content.'</div>'; |
|
1447 | + return '<div class="geodir-video-wrapper">'.$content.'</div>'; |
|
1448 | 1448 | } |
1449 | 1449 | add_shortcode('gd_video', 'geodir_sc_responsive_videos'); |
1450 | 1450 | \ No newline at end of file |