PluginProbe
Property Hive / 2.3.0
Property Hive v2.3.0
2.3.1 2.3.0 2.2.6 2.2.5 2.2.4 2.2.3 2.2.2 1.4.46 1.4.47 1.4.48 1.4.49 1.4.5 1.4.50 1.4.51 1.4.52 1.4.53 1.4.54 1.4.55 1.4.56 1.4.57 1.4.58 1.4.59 1.4.6 1.4.60 1.4.61 All 261 releases
← All changes | includes/admin/ph-admin-functions.php +148 -2 1.4.622.3.0 View file →
@@ -1,5 +1,8 @@
1 1 <?php
2 +// phpcs:set WordPress.Security.ValidatedSanitizedInput customSanitizingFunctions[] ph_clean
3 +// ph_clean() recursively sanitizes text; presence, shape and unslashing checks remain separate.
4 +
2 5 /**
3 6 * PropertyHive Admin Functions
4 7 *
5 8 * @author PropertyHive
@@ -14,24 +17,31 @@
14 17 * Get all PropertyHive screen ids
15 18 *
16 19 * @return array
17 20 */
21 +// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound -- Legacy public global helper ph_get_screen_ids; the established callable name is part of the plugin/extension API and must remain stable.
18 22 function ph_get_screen_ids() {
19 - $ph_screen_id = sanitize_title( __( 'PropertyHive', 'propertyhive' ) );
20 -
21 23 return apply_filters( 'propertyhive_screen_ids', array(
22 24 'edit-property',
23 25 'property',
24 26 'edit-contact',
25 27 'contact',
28 + 'edit-enquiry',
26 29 'enquiry',
30 + 'edit-appraisal',
27 31 'appraisal',
32 + 'edit-viewing',
28 33 'viewing',
34 + 'edit-offer',
29 35 'offer',
36 + 'edit-sale',
30 37 'sale',
38 + 'tenancy',
39 + 'edit-key_date',
31 40 'dashboard_page_ph-installed',
32 41 'property-hive_page_ph-settings',
33 42 'admin_page_ph-generate-applicant-list',
43 + 'admin_page_ph-merge-duplicate-contacts',
34 44 ) );
35 45 }
36 46
37 47 /**
@@ -44,8 +54,9 @@
44 54 * @param string $page_content (default: '') Content for the new page
45 55 * @param int $post_parent (default: 0) Parent for the new page
46 56 * @return int page ID
47 57 */
58 +// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound -- Legacy public global helper ph_create_page; the established callable name is part of the plugin/extension API and must remain stable.
48 59 function ph_create_page( $slug, $option = '', $page_title = '', $page_content = '', $post_parent = 0 ) {
49 60 global $wpdb;
50 61
51 62 /*$option_value = get_option( $option );
@@ -189,4 +200,139 @@
189 200 wp_die( __( 'Could not compile propertyhive.less:', 'propertyhive' ) . ' ' . $ex->getMessage() );
190 201 }
191 202 }*/
192 203 }
204 +
205 +function propertyhive_is_location_in_address( $property, $location )
206 +{
207 + $address_keywords = array( $location );
208 + if ( strpos( $location, ' ' ) !== FALSE )
209 + {
210 + $address_keywords[] = str_replace(" ", "-", ph_clean($location));
211 + }
212 + if ( strpos( $location, '-' ) !== FALSE )
213 + {
214 + $address_keywords[] = str_replace("-", " ", ph_clean($location));
215 + }
216 +
217 + if ( strpos( $location, '.' ) !== FALSE )
218 + {
219 + $address_keywords[] = str_replace(".", "", ph_clean($location));
220 + }
221 + if ( stripos( $location, 'st ' ) !== FALSE )
222 + {
223 + $address_keywords[] = str_ireplace("st ", "st. ", ph_clean($location));
224 + }
225 +
226 + $location_address_fields = array(
227 + '_address_street',
228 + '_address_two',
229 + '_address_three',
230 + '_address_four',
231 + '_address_postcode'
232 + );
233 + $location_address_fields = apply_filters( 'propertyhive_address_fields_to_query', $location_address_fields );
234 +
235 + $address_keyword_compare = get_option( 'propertyhive_address_keyword_compare', '=' );
236 + if ( $address_keyword_compare == 'polygon' )
237 + {
238 + $address_keyword_compare = apply_filters('propertyhive_property_match_address_keyword_compare', '=');
239 + }
240 +
241 + foreach ( $address_keywords as $address_keyword )
242 + {
243 + foreach ( $location_address_fields as $address_field )
244 + {
245 + if ( $address_field == '_address_postcode' ) { continue; } // ignore postcode as that is handled differently afterwards
246 +
247 + if (
248 + ( $address_keyword_compare == '=' && strcasecmp($address_keyword, $property->{$address_field}) == 0 )
249 + ||
250 + ( $address_keyword_compare == 'LIKE' && stripos($property->{$address_field}, $address_keyword) !== false )
251 + )
252 + {
253 + return true;
254 + }
255 + }
256 + }
257 + if ( in_array('_address_postcode', $location_address_fields) )
258 + {
259 + if ( strlen($location) <= 4 )
260 + {
261 + // if location is just the first part of postcode, check if it is present at the start of the postcode
262 + if ( strcasecmp($address_keyword, substr($property->_address_postcode, 0, strlen($address_keyword))) == 0 )
263 + {
264 + return true;
265 + }
266 + }
267 + else
268 + {
269 + $postcode = ph_clean($location);
270 + $postcodes = array(strtolower($postcode));
271 +
272 + if ( preg_match('#^(GIR ?0AA|[A-PR-UWYZ]([0-9]{1,2}|([A-HK-Y][0-9]([0-9ABEHMNPRV-Y])?)|[0-9][A-HJKPS-UW])[0-9][ABD-HJLNP-UW-Z]{2})$#i', $postcode) )
273 + {
274 + // UK postcode found with no space
275 +
276 + if ( strlen($postcode) == 5 )
277 + {
278 + $first_part = substr($postcode, 0, 2);
279 + $last_part = substr($postcode, 2, 3);
280 +
281 + $postcodes[] = strtolower($first_part . ' ' . $last_part);
282 + }
283 + elseif ( strlen($postcode) == 6 )
284 + {
285 + $first_part = substr($postcode, 0, 3);
286 + $last_part = substr($postcode, 3, 3);
287 +
288 + $postcodes[] = strtolower($first_part . ' ' . $last_part);
289 + }
290 + elseif ( strlen($postcode) == 7 )
291 + {
292 + $first_part = substr($postcode, 0, 4);
293 + $last_part = substr($postcode, 4, 3);
294 +
295 + $postcodes[] = strtolower($first_part . ' ' . $last_part);
296 + }
297 + }
298 +
299 + if ( in_array(strtolower($property->_address_postcode), $postcodes) )
300 + {
301 + return true;
302 + }
303 + }
304 + }
305 +
306 + return false;
307 +}
308 +
309 +function propertyhive_human_time_difference( $timestamp )
310 +{
311 + $now = time();
312 +
313 + if ( !$timestamp )
314 + {
315 + return __( 'never', 'propertyhive' );
316 + }
317 +
318 + if ( $now - $timestamp > 0 )
319 + {
320 + return sprintf(
321 + /* translators: %s: human-readable time difference (e.g. "5 minutes") */
322 + __( '%s ago', 'propertyhive' ),
323 + human_time_diff( $timestamp, $now )
324 + );
325 + }
326 + elseif ( $now - $timestamp < 0 )
327 + {
328 + return sprintf(
329 + /* translators: %s: human-readable time difference (e.g. "5 minutes") */
330 + __( 'in %s', 'propertyhive' ),
331 + human_time_diff( $timestamp, $now )
332 + );
333 + }
334 + else
335 + {
336 + return __( 'now', 'propertyhive' );
337 + }
338 +}