PluginProbe
Property Hive / 1.4.53
Property Hive v1.4.53
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 1.4.62 All 260 releases
propertyhive / includes / admin / class-ph-admin.php

class-ph-admin.php in Property Hive 1.4.53, at includes/admin/class-ph-admin.php

483 lines 21.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 exit; // Exit if accessed directly
4 }
5
6 /**
7 * PropertyHive Admin.
8 *
9 * @class PH_Admin
10 * @author PropertyHive
11 * @category Admin
12 * @package PropertyHive/Admin
13 * @version 1.0.0
14 */
15 class PH_Admin {
16
17 /**
18 * Constructor
19 */
20 public function __construct()
21 {
22 add_action( 'init', array( $this, 'includes' ) );
23 add_action( 'current_screen', array( $this, 'conditional_includes' ) );
24 add_action( 'current_screen', array( $this, 'disable_propertyhive_meta_box_dragging' ) );
25 add_action( 'current_screen', array( $this, 'remove_propertyhive_meta_boxes_from_screen_options' ) );
26 add_action( 'admin_notices', array( $this, 'review_admin_notices') );
27 add_action( 'admin_menu', array( $this, 'admin_dashboard_pages' ) );
28 add_action( 'admin_head', array( $this, 'admin_head' ) );
29 add_action( 'admin_init', array( $this, 'admin_redirects' ) );
30 add_action( 'admin_init', array( $this, 'prevent_access_to_admin' ) );
31 add_action( 'admin_init', array( $this, 'view_email' ) );
32 add_action( 'admin_init', array( $this, 'preview_emails' ) );
33 }
34
35 public function admin_dashboard_pages()
36 {
37 if ( ! empty( $_GET['page'] ) )
38 {
39 switch ( sanitize_title($_GET['page']) )
40 {
41 case 'ph-installed':
42 {
43 add_dashboard_page(
44 __( 'Welcome to Property Hive', 'propertyhive' ),
45 __( 'Welcome to Property Hive', 'propertyhive' ),
46 'manage_propertyhive',
47 sanitize_title($_GET['page']),
48 array( $this, 'installed_screen' )
49 );
50
51 break;
52 }
53 }
54 }
55 }
56
57 public function installed_screen()
58 {
59 ?>
60 <div class="wrap propertyhive-installed-screen">
61
62 <h1><?php _e( 'Welcome to Property Hive', 'propertyhive' ); ?></h1>
63
64 <div class="intro-text">
65 <p>Thank you choosing Property Hive to power your next property website. Below you'll find useful links, tips on getting started, and more.</p>
66 </div>
67
68 <div class="panels">
69
70 <div class="panel">
71
72 <h2>Getting Started</h2>
73
74 <p>Now that you've installed Property Hive you'll notice a new 'Property Hive' item in the left hand menu of WordPress.</p>
75
76 <img src="<?php echo PH()->plugin_url(); ?>/assets/images/admin/installed-screen/wordpress-menu.png" style="margin:0 auto; display:block; max-width:100%;" alt="Property Hive menu in WordPress">
77
78 <p><strong>Configure Property Hive:</strong> We recommend that you start by navigating to the '<a href="<?php echo admin_url( 'admin.php?page=ph-settings' ); ?>" target="_blank">Settings</a>' area of Property Hive and configuring the options available.</p>
79
80 <p><strong>Add Your First Property:</strong> See for yourself how easy it is to use Property Hive by <a href="<?php echo admin_url( 'post-new.php?post_type=property' ); ?>" target="_blank">adding your first property</a>.</p>
81
82 </div>
83
84 <div class="panel">
85
86 <h2>Extending Property Hive</h2>
87
88 <p>We have a <a href="https://wp-property-hive.com/add-ons/" target="_blank">wide range of add ons</a> available to add extra functionality to your website.</p>
89
90 <a href="https://wp-property-hive.com/add-ons/" target="_blank"><img src="<?php echo PH()->plugin_url(); ?>/assets/images/admin/installed-screen/add-ons.png" style="margin:0 auto; border:1px solid #CCC; display:block; max-width:100%;" alt="Property Hive Free Add Ons"></a>
91
92 <p><strong style="font-size:14px;"><a href="https://wp-property-hive.com/add-ons/?category=free" target="_blank">Free Add Ons</a></strong><br>
93 From our template assistant add on to a variety of calculators, these free add ons are great additions to any property website.</p>
94
95 <p><strong style="font-size:14px;"><a href="https://wp-property-hive.com/add-ons/?category=enhancements" target="_blank">Website Enhancements</a></strong><br>
96 Map View, Radial Search, Property Shortlist, Infinite Scroll, and lots more. Wow your users with the functionality provided with these add ons.</p>
97
98 <p><strong style="font-size:14px;"><a href="https://wp-property-hive.com/add-ons/?category=tools" target="_blank">Internal Tools</a></strong><br>
99 Add ons aimed to make your life easier and to save you time. Includes Digital Window Displays, Address Lookup and more.</p>
100
101 <p><strong style="font-size:14px;"><a href="https://wp-property-hive.com/add-ons/?category=import-export" target="_blank">Import and Export</a></strong><br>
102 Send your properties to portals like Rightmove, Zoopla and more or import properties from thid party software. These add ons automate the import and export of property data.</p>
103
104 </div>
105
106 <div class="panel">
107
108 <h2>Support</h2>
109
110 We pride ourselves on great support at Property Hive and will always do what we can to help you make create the best site possible. Please find below some useful links relating to our support:
111
112 <p><strong style="font-size:14px;">Documentation</strong><br>
113 We have documentation <a href="https://wp-property-hive.com/documentation/" target="_blank">available on our website</a> covering setup advice, help with theming, and more.</p>
114
115 <p><strong style="font-size:14px;">Priority One-To-One Support</strong><br>
116 If you require help quickly, or wish to discuss a bespoke requirement, then <a href="https://wp-property-hive.com/product/12-month-license-key/" target="_blank">priority support</a> might be best for you. With a license key priced at just £49.99 per year you'll not only get priority support but also updates to any add ons you've purchased.</p>
117
118 <p><strong style="font-size:14px;">Our Support Policy</strong><br>
119 Our <a href="https://wp-property-hive.com/support-policy/" target="_blank">Support Policy is available to view here</a> and outlines how you can get in touch, how we will (and won't) help, and how to report bugs.</p>
120
121 </div>
122
123 <div class="panel">
124
125 <h2>Additional Information</h2>
126
127 <p><strong style="font-size:14px;">Need a Theme?</strong><br>
128 Property Hive does <a href="https://wp-property-hive.com/which-wordpress-themes-work-with-property-hive/" target="_blank">integrate with any new or existing theme</a>. If however you need to get up and running quickly, or just want to have a play before committing, then our free <a href="https://wp-property-hive.com/honeycomb" target="_blank">Honeycomb theme</a> might be right for you.</p>
129
130 <a href="https://wp-property-hive.com/honeycomb" target="_blank"><img src="<?php echo PH()->plugin_url(); ?>/assets/images/admin/installed-screen/honeycomb-screenshot.png" style="margin:0 auto; display:block; max-width:80%;" alt="Property Hive Free Honeycomb Theme"></a>
131
132 <p><strong style="font-size:14px;">Leave a Review</strong><br>
133 If you've found Property Hive useful we'd love it if you could spare a moment to tell others just how great we are by <a href="https://wordpress.org/support/plugin/propertyhive/reviews/?filter=5" target="_blank">leaving a review</a>.</p>
134
135 <p><strong style="font-size:14px;">Contribute</strong><br>
136 Property Hive is completely open-source meaning anyone can access and contribute to the code. Fixing bugs and adding functionality can be done by anyone with coding knowledge. <a href="https://github.com/propertyhive/WP-Property-Hive" target="_blank">Visit us on GitHub</a> to get started.</p>
137
138 <p><strong style="font-size:14px;">Our Feature Roadmap</strong><br>
139 View our <a href="https://trello.com/b/jb7bjB6j/property-hive-roadmap" target="_blank">feature roadmap</a> to see what's coming up, vote on feature, or submit your own ideas.</p>
140
141
142 </div>
143
144 </div>
145
146 </div>
147 <?php
148 }
149
150 /**
151 * Hide Individual Dashboard Pages
152 *
153 * @access public
154 * @since 1.0
155 * @return void
156 */
157 public function admin_head()
158 {
159 remove_submenu_page( 'index.php', 'ph-installed' );
160 }
161
162 /**
163 * Include any classes we need within admin.
164 */
165 public function includes() {
166 // Functions
167 include_once( 'ph-admin-functions.php' );
168 include_once( 'ph-meta-box-functions.php' );
169
170 // Classes
171 include_once( 'class-ph-admin-post-types.php' );
172 //include_once( 'class-ph-admin-taxonomies.php' );
173
174 // Classes we only need if the ajax is not-ajax
175 if ( ! is_ajax() ) {
176 include( 'class-ph-admin-menus.php' );
177 include( 'class-ph-admin-assets.php' );
178 }
179 }
180
181 /**
182 * Include admin files conditionally.
183 */
184 public function conditional_includes() {
185 if ( ! $screen = get_current_screen() ) {
186 return;
187 }
188
189 switch ( $screen->id ) {
190 case 'dashboard' :
191 include( 'class-ph-admin-dashboard.php' );
192 break;
193 case 'plugins' :
194 include( 'class-ph-admin-plugin-updates.php' );
195 break;
196 }
197 }
198
199 /**
200 * Include admin files conditionally
201 */
202 public function disable_propertyhive_meta_box_dragging()
203 {
204 $screen = get_current_screen();
205
206 if ( in_array( $screen->id, ph_get_screen_ids() ) )
207 {
208 //wp_deregister_script('postbox');
209 }
210 }
211
212 /**
213 * Remove PropertyHive meta boxes
214 */
215 public function remove_propertyhive_meta_boxes_from_screen_options()
216 {
217 global $wp_meta_boxes;
218
219 $screen = get_current_screen();
220
221 if ( in_array( $screen->id, array( 'property' ) ) )
222 {
223 //wp_deregister_script('postbox');
224 }
225 }
226
227 public function review_admin_notices()
228 {
229 if ( current_user_can( 'manage_options' ) )
230 {
231 $propertyhive_review_prompt_due_timestamp = get_option( 'propertyhive_review_prompt_due_timestamp', 0 );
232 if ( $propertyhive_review_prompt_due_timestamp != '' && $propertyhive_review_prompt_due_timestamp != 0 )
233 {
234 if ( $propertyhive_review_prompt_due_timestamp < time() )
235 {
236 echo "<div class=\"notice notice-info\" id=\"ph_notice_leave_review\">
237 <p>
238 " . __( '<strong>Finding Property Hive useful?</strong> Please take a minute to <a href="https://wordpress.org/support/plugin/propertyhive/reviews/?filter=5#new-post" target="_blank">leave us a �
239 �
240 �
241 �
242 �
243 review</a>', 'propertyhive' ) . "
244 </p>
245 <p>
246 <a href=\"https://wordpress.org/support/plugin/propertyhive/reviews/?filter=5#new-post\" target=\"_blank\" class=\"button-primary\">Leave a Review</a>
247 <a href=\"\" class=\"button\" id=\"ph_dismiss_notice_leave_review\">No Thanks</a>
248 </p>
249 </div>";
250 }
251 }
252
253 if (
254 get_option('propertyhive_search_results_page_id', '') == '' &&
255 (
256 !isset($_GET['page'])
257 ||
258 (
259 isset($_GET['page']) && sanitize_title($_GET['page']) != 'ph-installed' && sanitize_title($_GET['page']) != 'ph-settings'
260 )
261 ) &&
262 get_option( 'missing_search_results_notice_dismissed', '' ) != 'yes'
263 )
264 {
265 echo "<div class=\"notice notice-info\" id=\"ph_notice_missing_search_results\">
266 <p>
267 " . __( 'We noticed that you haven\'t assigned a page to be your \'Search Results\' page yet. We recommend that you do this in order to display properties on your site.', 'propertyhive' ) . "
268 </p>
269 <p>
270 <a href=\"". admin_url('admin.php?page=ph-settings&tab=general') . "\" class=\"button-primary\">Go To Property Hive Settings</a>
271 <a href=\"\" class=\"button\" id=\"ph_dismiss_notice_missing_search_results\">Dismiss</a>
272 </p>
273
274 </div>";
275 }
276
277 if (
278 get_option('propertyhive_google_maps_api_key', '') == '' &&
279 !isset($_POST['propertyhive_google_maps_api_key']) &&
280 (
281 !isset($_GET['page'])
282 ||
283 (
284 isset($_GET['page']) && sanitize_title($_GET['page']) != 'ph-installed'
285 )
286 ) &&
287 get_option( 'missing_google_maps_api_key_notice_dismissed', '' ) != 'yes'
288 )
289 {
290 echo "<div class=\"notice notice-info\" id=\"ph_notice_missing_google_maps_api_key\">
291 <p>
292 " . __( 'We noticed that you haven\'t entered a Google Maps API key yet. If wishing to display a map on your website it\'s recommended that you <a href="https://developers.google.com/maps/documentation/javascript/get-api-key" target="_blank">create one</a> and <a href="'. admin_url('admin.php?page=ph-settings&tab=general&section=map') . '">enter it</a>.', 'propertyhive' ) . "
293 </p>
294 <p>
295 <a href=\"". admin_url('admin.php?page=ph-settings&tab=general&section=map') . "\" class=\"button-primary\">Enter Google Maps API Key</a>
296 <a href=\"\" class=\"button\" id=\"ph_dismiss_notice_missing_google_maps_api_key\">Dismiss</a>
297 </p>
298
299 </div>";
300 }
301
302 if (
303 get_option('propertyhive_license_key', '') != '' &&
304 get_option( 'missing_invalid_expired_license_key_notice_dismissed', '' ) != 'yes' &&
305 (
306 !isset($_GET['page'])
307 ||
308 (
309 isset($_GET['page']) && sanitize_title($_GET['page']) != 'ph-installed' && sanitize_title($_GET['page']) != 'ph-settings'
310 )
311 )
312 )
313 {
314 $license = PH()->license->get_current_license();
315 $output = '';
316
317 if ( isset($license['active']) && $license['active'] != '1' )
318 {
319 $output = __( 'You\'re Property Hive license key is inactive.', 'propertyhive' );
320 }
321 else
322 {
323 if ( isset($license['expires_at']) && $license['expires_at'] != '' )
324 {
325 if ( strtotime($license['expires_at']) <= time() )
326 {
327 // Expired
328 $output = __( 'Your Property Hive license key expired on ' . date("jS F Y", strtotime($license['expires_at'])), 'propertyhive' ) . '. It\'s recommended that you renew it to ensure you continue to receive future updates to add ons you\'ve purchased.';
329 }
330 elseif (
331 strtotime($license['expires_at']) > time() &&
332 strtotime($license['expires_at']) < (time() + 30 * 24 * 60 * 60)
333 )
334 {
335 // Expires in less than 30 days
336 $output = __( 'Your Property Hive license key expires on ' . date("jS F Y", strtotime($license['expires_at'])), 'propertyhive' ) . '. It\'s recommended that you renew it to ensure you continue to receive future updates to add ons you\'ve purchased.';
337 }
338 elseif (strtotime($license['expires_at']) > time())
339 {
340 // Valid
341 }
342 }
343 }
344
345 if ( $output != '' )
346 {
347 echo "<div class=\"notice notice-info\" id=\"ph_notice_invalid_expired_license_key\">
348 <p>
349 " . $output . "
350 </p>
351 <p>
352 <a href=\"". admin_url('admin.php?page=ph-settings&tab=licensekey') . "\" class=\"button-primary\">Go To License Key Settings</a>
353 <a href=\"\" class=\"button\" id=\"ph_dismiss_notice_invalid_expired_license_key\">Dismiss</a>
354 </p>
355
356 </div>";
357 }
358 }
359 }
360 }
361
362 /**
363 * Handle redirects to welcome page after install.
364 */
365 public function admin_redirects()
366 {
367 // Setup wizard redirect
368 if ( get_transient( '_ph_activation_redirect' ) )
369 {
370 delete_transient( '_ph_activation_redirect' );
371
372 // Don't do redirect if part of multisite, doing batch-activate, or if no permission
373 if ( is_network_admin() || isset( $_GET['activate-multi'] ) || ! current_user_can( 'manage_propertyhive' ) ) {
374 return;
375 }
376
377 wp_safe_redirect( admin_url( 'index.php?page=ph-installed' ) );
378 exit;
379 }
380 }
381
382 public function prevent_access_to_admin()
383 {
384 global $current_user;
385
386 $user_roles = $current_user->roles;
387 $user_role = array_shift($user_roles);
388
389 // Check role, but also AJAX as request to admin-ajax.php will still need to be made
390 if ( !defined( 'DOING_AJAX' ) && $user_role === 'property_hive_contact' )
391 {
392 exit( wp_redirect( home_url( '/' ) ) );
393 }
394 }
395
396 /**
397 * View previously sent email
398 *
399 * @return string
400 */
401 public function view_email() {
402
403 global $wpdb;
404
405 if ( isset( $_GET['view_propertyhive_email'] ) )
406 {
407 if ( ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'view-email' ) )
408 {
409 die( 'Security check' );
410 }
411
412 if ( isset( $_GET['email_id'] ) )
413 {
414 $email_log = $wpdb->get_row( "SELECT * FROM " . $wpdb->prefix . "ph_email_log WHERE email_id = '" . esc_sql( (int)$_GET['email_id'] ) . "'" );
415 if ( null !== $email_log )
416 {
417 echo apply_filters( 'propertyhive_mail_content', PH()->email->style_inline( PH()->email->wrap_message( $email_log->body ) ) );
418
419 }
420 else
421 {
422 die("Email not found");
423 }
424 }
425
426 exit;
427 }
428 }
429
430 /**
431 * Preview email template.
432 *
433 * @return string
434 */
435 public function preview_emails() {
436 if ( isset( $_GET['preview_propertyhive_email'] ) )
437 {
438 if ( ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'propertyhive-matching-properties' ) && ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'propertyhive-matching-applicants' ) )
439 {
440 die( 'Security check' );
441 }
442
443 // get the preview email content
444 if ( isset($_GET['property_id']) )
445 {
446 $email_property_ids = array((int)$_GET['property_id']);
447 }
448 elseif ( isset($_POST['email_property_id']) )
449 {
450 $email_property_ids = explode(",", sanitize_text_field($_POST['email_property_id']));
451 }
452
453 $body = stripslashes(sanitize_textarea_field($_POST['body']));
454
455 $body = str_replace("[contact_name]", get_the_title((int)$_GET['contact_id']), $body);
456 $body = str_replace("[property_count]", count($email_property_ids) . ' propert' . ( ( count($email_property_ids) != 1 ) ? 'ies' : 'y' ), $body);
457
458 if ( strpos($body, '[properties]') !== FALSE )
459 {
460 ob_start();
461
462 if ( !empty($email_property_ids) )
463 {
464 foreach ( $email_property_ids as $email_property_id )
465 {
466 $property = new PH_Property((int)$email_property_id);
467 ph_get_template( 'emails/applicant-match-property.php', array( 'property' => $property ) );
468 }
469 }
470 $body = str_replace("[properties]", ob_get_clean(), $body);
471 }
472
473 // wrap the content with the email template and then add styles
474 $message = apply_filters( 'propertyhive_mail_content', PH()->email->style_inline( PH()->email->wrap_message( $body ) ) );
475
476 // print the preview email
477 echo $message;
478 exit;
479 }
480 }
481 }
482
483 return new PH_Admin();