PluginProbe
Property Hive / 1.4.5
Property Hive v1.4.5
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
propertyhive / includes / admin / class-ph-admin.php

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

371 lines 15.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 ( $_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 $_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 }
194 }
195
196 /**
197 * Include admin files conditionally
198 */
199 public function disable_propertyhive_meta_box_dragging()
200 {
201 $screen = get_current_screen();
202
203 if ( in_array( $screen->id, ph_get_screen_ids() ) )
204 {
205 //wp_deregister_script('postbox');
206 }
207 }
208
209 /**
210 * Remove PropertyHive meta boxes
211 */
212 public function remove_propertyhive_meta_boxes_from_screen_options()
213 {
214 global $wp_meta_boxes;
215
216 $screen = get_current_screen();
217
218 if ( in_array( $screen->id, array( 'property' ) ) )
219 {
220 //wp_deregister_script('postbox');
221 }
222 }
223
224 public function review_admin_notices()
225 {
226 if ( current_user_can( 'manage_options' ) )
227 {
228 $propertyhive_review_prompt_due_timestamp = get_option( 'propertyhive_review_prompt_due_timestamp', 0 );
229 if ( $propertyhive_review_prompt_due_timestamp != '' && $propertyhive_review_prompt_due_timestamp != 0 )
230 {
231 if ( $propertyhive_review_prompt_due_timestamp < time() )
232 {
233 echo "<div class=\"notice notice-info is-dismissible\" id=\"ph_leave_review_admin_notice\">
234 <p>
235 " . __( '<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 �
236 �
237 �
238 �
239 �
240 review</a>', 'propertyhive' ) . "
241 </p>
242 <p>
243 <a href=\"https://wordpress.org/support/plugin/propertyhive/reviews/?filter=5#new-post\" target=\"_blank\" class=\"button-primary\">Leave a Review</a>
244 <a href=\"\" class=\"button\">No Thanks</a>
245 </p>
246 </div>";
247
248 update_option( 'propertyhive_review_prompt_due_timestamp', 0 );
249 }
250 }
251 }
252 }
253
254 /**
255 * Handle redirects to welcome page after install.
256 */
257 public function admin_redirects()
258 {
259 // Setup wizard redirect
260 if ( get_transient( '_ph_activation_redirect' ) )
261 {
262 delete_transient( '_ph_activation_redirect' );
263
264 // Don't do redirect if part of multisite, doing batch-activate, or if no permission
265 if ( is_network_admin() || isset( $_GET['activate-multi'] ) || ! current_user_can( 'manage_propertyhive' ) ) {
266 return;
267 }
268
269 wp_safe_redirect( admin_url( 'index.php?page=ph-installed' ) );
270 exit;
271 }
272 }
273
274 public function prevent_access_to_admin()
275 {
276 global $current_user;
277
278 $user_roles = $current_user->roles;
279 $user_role = array_shift($user_roles);
280
281 // Check role, but also AJAX as request to admin-ajax.php will still need to be made
282 if ( !defined( 'DOING_AJAX' ) && $user_role === 'property_hive_contact' )
283 {
284 exit( wp_redirect( home_url( '/' ) ) );
285 }
286 }
287
288 /**
289 * View previously sent email
290 *
291 * @return string
292 */
293 public function view_email() {
294
295 global $wpdb;
296
297 if ( isset( $_GET['view_propertyhive_email'] ) )
298 {
299 if ( ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'view-email' ) )
300 {
301 die( 'Security check' );
302 }
303
304 if ( isset( $_GET['email_id'] ) )
305 {
306 $email_log = $wpdb->get_row( "SELECT * FROM " . $wpdb->prefix . "ph_email_log WHERE email_id = '" . esc_sql( $_GET['email_id'] ) . "'" );
307 if ( null !== $email_log )
308 {
309 echo apply_filters( 'propertyhive_mail_content', PH()->email->style_inline( PH()->email->wrap_message( $email_log->body ) ) );
310
311 }
312 else
313 {
314 die("Email not found");
315 }
316 }
317
318 exit;
319 }
320 }
321
322 /**
323 * Preview email template.
324 *
325 * @return string
326 */
327 public function preview_emails() {
328 if ( isset( $_GET['preview_propertyhive_email'] ) )
329 {
330 if ( ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'propertyhive-matching-properties' ) )
331 {
332 die( 'Security check' );
333 }
334
335 // get the preview email content
336 $email_property_ids = explode(",", $_POST['email_property_id']);
337
338 $body = stripslashes($_POST['body']);
339
340 $body = str_replace("[contact_name]", get_the_title($_GET['contact_id']), $body);
341 $body = str_replace("[property_count]", count($email_property_ids) . ' propert' . ( ( count($email_property_ids) != 1 ) ? 'ies' : 'y' ), $body);
342
343 if ( strpos($body, '[properties]') !== FALSE )
344 {
345 ob_start();
346
347 if ( !empty($email_property_ids) )
348 {
349 foreach ( $email_property_ids as $email_property_id )
350 {
351 $property = new PH_Property((int)$email_property_id);
352 ph_get_template( 'emails/applicant-match-property.php', array( 'property' => $property ) );
353 }
354 }
355 $body = str_replace("[properties]", ob_get_clean(), $body);
356 }
357
358 // create a new email
359 $email = new PH_Emails();
360
361 // wrap the content with the email template and then add styles
362 $message = apply_filters( 'propertyhive_mail_content', $email->style_inline( $email->wrap_message( $body ) ) );
363
364 // print the preview email
365 echo $message;
366 exit;
367 }
368 }
369 }
370
371 return new PH_Admin();