PluginProbe
Property Hive / 2.2.3
Property Hive v2.2.3
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 / class-ph-install.php

class-ph-install.php in Property Hive 2.2.3, at includes/class-ph-install.php

970 lines 31.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Installation related functions and actions.
4 *
5 * @author PropertyHive
6 * @category Admin
7 * @package PropertyHive/Classes
8 * @version 1.0.0
9 */
10
11 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
12
13 if ( ! class_exists( 'PH_Install' ) ) :
14
15 /**
16 * PH_Install Class
17 */
18 class PH_Install {
19
20 /**
21 * DB updates and callbacks that need to be run per version.
22 *
23 * @var array
24 */
25 private static $db_updates = array(
26 '1.4.68' => array(
27 'propertyhive_update_1468_on_market_change_dates',
28 ),
29 '2.0.0' => array(
30 'propertyhive_update_200_pre_pro_record_installed_plugins',
31 ),
32 '2.2.0' => array(
33 'propertyhive_deactivate_template_assistant', // different naming convention as needs to be run elsewhere too
34 ),
35 );
36
37 /**
38 * Hook in tabs.
39 */
40 public function __construct() {
41 register_activation_hook( PH_PLUGIN_FILE, array( $this, 'install' ) );
42 register_deactivation_hook( PH_PLUGIN_FILE, array( $this, 'deactivate' ) );
43
44 add_action( 'admin_init', array( $this, 'install_actions' ) );
45 add_action( 'admin_init', array( $this, 'check_version' ), 5 );
46
47 add_filter( 'cron_schedules', array( $this, 'custom_cron_recurrence' ) );
48 //add_action( 'in_plugin_update_message-propertyhive/propertyhive.php', array( $this, 'in_plugin_update_message' ) );
49 }
50
51 /**
52 * check_version function.
53 *
54 * @access public
55 * @return void
56 */
57 public function check_version() {
58 if ( ! defined( 'IFRAME_REQUEST' ) && ( get_option( 'propertyhive_version' ) != PH()->version || get_option( 'propertyhive_db_version' ) != PH()->version ) ) {
59 $this->install();
60
61 do_action( 'propertyhive_updated' );
62 }
63 }
64
65 /**
66 * Install actions such as installing pages when a button is clicked.
67 */
68 public function install_actions() {
69
70
71 }
72
73 /**
74 * Install Property Hive
75 */
76 public function install() {
77
78 $this->create_options();
79 $this->create_tables();
80 $this->create_roles();
81
82 // Register post types
83 include_once( 'class-ph-post-types.php' );
84 PH_Post_types::register_post_types();
85 PH_Post_types::register_taxonomies();
86
87 $this->create_primary_office();
88 $this->create_cron_jobs();
89
90 $this->update();
91
92 // Clear transient cache
93
94 // Queue upgrades
95 $current_version = get_option( 'propertyhive_version', null );
96 $current_db_version = get_option( 'propertyhive_db_version', null );
97
98 // No existing version set. This must be a new fresh install
99 if ( is_null( $current_version ) && is_null( $current_db_version ) )
100 {
101 $this->create_terms();
102 $this->create_pages();
103 set_transient( '_ph_activation_redirect', 1, 30 );
104 }
105
106 update_option( 'propertyhive_db_version', PH()->version );
107
108 // Check if pages are needed
109 if ( ph_get_page_id( 'search_results' ) < 1 ) {
110 update_option( '_ph_needs_pages', 1 );
111 }
112
113 // Update version
114 update_option( 'propertyhive_version', PH()->version );
115
116 // Flush rules after install
117 flush_rewrite_rules();
118 }
119
120 /**
121 * Deactivate Property Hive
122 */
123 public function deactivate() {
124 // Cron jobs
125 wp_clear_scheduled_hook( 'propertyhive_update_currency_exchange_rates' );
126 wp_clear_scheduled_hook( 'propertyhive_process_email_log' );
127 wp_clear_scheduled_hook( 'propertyhive_auto_email_match' );
128 wp_clear_scheduled_hook( 'propertyhive_check_licenses' );
129 wp_clear_scheduled_hook( 'propertyhive_update_address_concatenated' );
130 }
131
132 /**
133 * Get list of DB update callbacks.
134 *
135 * @return array
136 */
137 public static function get_db_update_callbacks() {
138 return self::$db_updates;
139 }
140
141 /**
142 * Handle updates
143 */
144 public function update() {
145 // Do updates
146 $current_db_version = get_option( 'propertyhive_db_version' );
147
148 foreach ( self::get_db_update_callbacks() as $version => $update_callbacks ) {
149 if ( version_compare( $current_db_version, $version, '<' ) ) {
150 foreach ( $update_callbacks as $update_callback ) {
151 add_action('property_run_update_actions', $update_callback);
152 }
153 }
154 }
155 do_action('property_run_update_actions');
156 }
157
158 /**
159 * Create cron jobs (clear them first)
160 */
161 private function create_cron_jobs() {
162
163 // Cron jobs
164 wp_clear_scheduled_hook( 'propertyhive_update_currency_exchange_rates' );
165 wp_clear_scheduled_hook( 'propertyhive_process_email_log' );
166 wp_clear_scheduled_hook( 'propertyhive_auto_email_match' );
167 wp_clear_scheduled_hook( 'propertyhive_check_licenses' );
168 wp_clear_scheduled_hook( 'propertyhive_update_address_concatenated' );
169
170 // Schedule for midnight as it's likely traffic will be quieter at that time
171 wp_schedule_event( strtotime( 'tomorrow' ) - ( (int)get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ), 'daily', 'propertyhive_update_currency_exchange_rates' );
172
173 wp_schedule_event( time(), 'every_fifteen_minutes', 'propertyhive_process_email_log' );
174
175 $auto_property_match_enabled = get_option( 'propertyhive_auto_property_match', '' );
176
177 if ( $auto_property_match_enabled == 'yes' )
178 {
179 $recurrence = apply_filters( 'propertyhive_auto_email_match_cron_recurrence', 'daily' );
180 if ( $recurrence != 'hourly' )
181 {
182 $timestamp = strtotime( 'tomorrow +2hours') - ( (int)get_option( 'gmt_offset' ) * HOUR_IN_SECONDS );
183 }
184 else
185 {
186 $timestamp = strtotime( '+1 hours' );
187 }
188 wp_schedule_event(
189 apply_filters( 'propertyhive_auto_email_match_cron_timestamp', $timestamp ),
190 $recurrence,
191 'propertyhive_auto_email_match'
192 );
193 }
194
195 // Schedule for 1am as it's likely traffic will be quieter at that time
196 // 1am so it doesn't run at exactly the same time as the exchange rate cron
197 wp_schedule_event( strtotime( 'tomorrow +1hours' ) - ( (int)get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ), 'daily', 'propertyhive_check_licenses' );
198
199 wp_schedule_event( strtotime( 'tomorrow +3hours' ) - ( (int)get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ), 'daily', 'propertyhive_update_address_concatenated' );
200 }
201
202 public function custom_cron_recurrence( $schedules )
203 {
204 $schedules['every_fifteen_minutes'] = array(
205 'interval' => 900,
206 'display' => __( 'Every 15 Minutes', 'propertyhive' )
207 );
208
209 return $schedules;
210 }
211
212 /**
213 * Create pages that the plugin relies on
214 *
215 * @access public
216 * @return void
217 */
218 public function create_pages() {
219
220 // Create page object
221 $my_post = array(
222 'post_title' => __( 'Property Search', 'propertyhive' ),
223 'post_content' => '',
224 'post_status' => 'publish',
225 'post_type' => 'page',
226 'comment_status' => 'closed',
227 'ping_status' => 'closed',
228 );
229
230 // Insert the post into the database
231 $page_id = wp_insert_post( $my_post, true );
232
233 if ( !is_wp_error($page_id) )
234 {
235 update_option( 'propertyhive_search_results_page_id', $page_id );
236 }
237 }
238
239 /**
240 * Add the default terms for PH taxonomies - property types, tenures etc. Modify this at your own risk.
241 *
242 * @access public
243 * @return void
244 */
245 private function create_terms() {
246
247 $taxonomies = array(
248 'availability' => array(
249 array(
250 'name' => 'For Sale',
251 'departments' => array('residential-sales', 'commercial')
252 ),
253 array(
254 'name' => 'Under Offer',
255 'departments' => array('residential-sales', 'commercial')
256 ),
257 array(
258 'name' => 'Sold STC',
259 'departments' => array('residential-sales', 'commercial')
260 ),
261 array(
262 'name' => 'Sold',
263 'departments' => array('residential-sales', 'commercial')
264 ),
265 array(
266 'name' => 'To Let',
267 'departments' => array('residential-lettings', 'commercial')
268 ),
269 array(
270 'name' => 'Let Agreed',
271 'departments' => array('residential-lettings', 'commercial')
272 ),
273 array(
274 'name' => 'Let',
275 'departments' => array('residential-lettings', 'commercial')
276 ),
277 ),
278 'property_type' => array(
279 // HOUSE
280 array(
281 'name' => 'House'
282 ),
283 array(
284 'name' => 'Detached House',
285 'child_of_previous' => true
286 ),
287 array(
288 'name' => 'Semi-Detached House',
289 'child_of_previous' => true
290 ),
291 array(
292 'name' => 'Terraced House',
293 'child_of_previous' => true
294 ),
295 array(
296 'name' => 'End of Terrace House',
297 'child_of_previous' => true
298 ),
299 array(
300 'name' => 'Mews',
301 'child_of_previous' => true
302 ),
303 array(
304 'name' => 'Link Detached House',
305 'child_of_previous' => true
306 ),
307 array(
308 'name' => 'Town House',
309 'child_of_previous' => true
310 ),
311 array(
312 'name' => 'Cottage',
313 'child_of_previous' => true
314 ),
315 // BUNGALOW
316 array(
317 'name' => 'Bungalow'
318 ),
319 array(
320 'name' => 'Detached Bungalow',
321 'child_of_previous' => true
322 ),
323 array(
324 'name' => 'Semi-Detached Bungalow',
325 'child_of_previous' => true
326 ),
327 array(
328 'name' => 'Terraced Bungalow',
329 'child_of_previous' => true
330 ),
331 array(
332 'name' => 'End of Terrace Bungalow',
333 'child_of_previous' => true
334 ),
335 // FLATS
336 array(
337 'name' => 'Flat / Apartment'
338 ),
339 array(
340 'name' => 'Flat',
341 'child_of_previous' => true
342 ),
343 array(
344 'name' => 'Apartment',
345 'child_of_previous' => true
346 ),
347 array(
348 'name' => 'Maisonette',
349 'child_of_previous' => true
350 ),
351 array(
352 'name' => 'Studio',
353 'child_of_previous' => true
354 ),
355 array(
356 'name' => 'Penthouse',
357 'child_of_previous' => true
358 ),
359 array(
360 'name' => 'Duplex',
361 'child_of_previous' => true
362 ),
363 array(
364 'name' => 'Triplex',
365 'child_of_previous' => true
366 ),
367 // OTHER
368 array(
369 'name' => 'Other'
370 ),
371 array(
372 'name' => 'Commercial',
373 'child_of_previous' => true
374 ),
375 array(
376 'name' => 'Land',
377 'child_of_previous' => true
378 ),
379 array(
380 'name' => 'Garage',
381 'child_of_previous' => true
382 ),
383 ),
384 'commercial_property_type' => array(
385 array(
386 'name' => 'Office'
387 ),
388 array(
389 'name' => 'Industrial'
390 ),
391 array(
392 'name' => 'Retail'
393 ),
394 array(
395 'name' => 'Land'
396 ),
397 array(
398 'name' => 'Health'
399 ),
400 array(
401 'name' => 'Motoring'
402 ),
403 array(
404 'name' => 'Leisure'
405 ),
406 array(
407 'name' => 'Investment'
408 ),
409 ),
410 'outside_space' => array(
411 array(
412 'name' => 'Balcony'
413 ),
414 array(
415 'name' => 'South Facing Garden'
416 ),
417 ),
418 'parking' => array(
419 array(
420 'name' => 'On Road Parking'
421 ),
422 array(
423 'name' => 'Off Road Parking'
424 ),
425 array(
426 'name' => 'Driveway'
427 ),
428 array(
429 'name' => 'Single Garage'
430 ),
431 array(
432 'name' => 'Double Garage'
433 ),
434 array(
435 'name' => 'Triple Garage'
436 ),
437 array(
438 'name' => 'Carport'
439 ),
440 ),
441 'price_qualifier' => array(
442 array(
443 'name' => 'Guide Price'
444 ),
445 array(
446 'name' => 'Fixed Price'
447 ),
448 array(
449 'name' => 'Offers Over'
450 ),
451 array(
452 'name' => 'OIRO'
453 )
454 ),
455 'sale_by' => array(
456 array(
457 'name' => 'Tender'
458 ),
459 array(
460 'name' => 'Private Treaty'
461 ),
462 array(
463 'name' => 'Auction'
464 ),
465 ),
466 'tenure' => array(
467 array(
468 'name' => 'Freehold'
469 ),
470 array(
471 'name' => 'Leasehold'
472 ),
473 array(
474 'name' => 'Share of Freehold'
475 ),
476 array(
477 'name' => 'Commonhold'
478 )
479 ),
480 'commercial_tenure' => array(
481 array(
482 'name' => 'Freehold'
483 ),
484 array(
485 'name' => 'Leasehold'
486 ),
487 array(
488 'name' => 'Share of Freehold'
489 ),
490 array(
491 'name' => 'Commonhold'
492 )
493 ),
494 'furnished' => array(
495 array(
496 'name' => 'Furnished'
497 ),
498 array(
499 'name' => 'Part Furnished'
500 ),
501 array(
502 'name' => 'Unfurnished'
503 )
504 ),
505 'marketing_flag' => array(
506 array(
507 'name' => 'New Instruction'
508 ),
509 array(
510 'name' => 'Chain Free'
511 )
512 ),
513 'management_key_date_type' => array(
514 array(
515 'name' => 'Initial Inventory',
516 'recurrence_type' => 'tenancy_management',
517 'recurrence_rule' => 'FREQ=ONCE',
518 ),
519 array(
520 'name' => 'Inspection',
521 'recurrence_type' => 'tenancy_management',
522 'recurrence_rule' => 'FREQ=MONTHLY;INTERVAL=3',
523 ),
524 array(
525 'name' => 'Gas Safety Check',
526 'recurrence_type' => 'property_management',
527 'recurrence_rule' => 'FREQ=YEARLY;INTERVAL=1',
528 ),
529 ),
530 );
531
532 $availability_departments = get_option( 'propertyhive_availability_departments', array() );
533 if ( !is_array($availability_departments) ) { $availability_departments = array(); }
534
535 $previous_term_id = '';
536 foreach ( $taxonomies as $taxonomy => $terms )
537 {
538 // Make sure no terms for this taxonomy exist already
539 $existing_terms = get_terms( $taxonomy );
540 if ( is_wp_error( $existing_terms ) || (!is_wp_error( $existing_terms ) && empty( $existing_terms ) ) )
541 {
542 foreach ( $terms as $term )
543 {
544 if ( ! get_term_by( 'slug', sanitize_title( $term['name'] ), $taxonomy ) )
545 {
546 $args = array();
547 if ( isset($term['child_of_previous']) && $term['child_of_previous'] === true )
548 {
549 $args = array('parent' => $previous_term_id);
550 }
551 $return = wp_insert_term( $term['name'], $taxonomy, $args );
552 if ( !is_wp_error($return) )
553 {
554 if ( !isset($term['child_of_previous']) || (isset($term['child_of_previous']) && !$term['child_of_previous']) )
555 {
556 $previous_term_id = $return['term_id'];
557 }
558
559 if ( $taxonomy == 'availability' && is_array($term['departments']) && !empty($term['departments']) )
560 {
561 $availability_departments[$return['term_id']] = $term['departments'];
562 }
563
564 if ( $taxonomy == 'management_key_date_type' && isset($term['recurrence_type']) && isset($term['recurrence_rule']) )
565 {
566 $options = get_option( 'propertyhive_key_date_type', array() );
567 if ( !is_array($options) ) { $options = array(); }
568
569 $options[$return['term_id']] = array(
570 'recurrence_rule' => $term['recurrence_rule'],
571 'recurrence_type' => $term['recurrence_type'],
572 );
573
574 update_option( 'propertyhive_key_date_type', $options );
575 }
576 }
577 else
578 {
579 // Hmm... an error occurred
580 // $error_string = $result->get_error_message(); // do something with this?
581 }
582 }
583 }
584 }
585 }
586
587 update_option( 'propertyhive_availability_departments', $availability_departments );
588 }
589
590 /**
591 * Add the first office so at least one exists
592 *
593 * @access public
594 * @return void
595 */
596 function create_primary_office() {
597
598 $args = array(
599 'post_type' => 'office'
600 );
601 $office_query = new WP_Query($args);
602 if (!$office_query->have_posts())
603 {
604 // Insert office
605 $office_post = array(
606 'post_title' => 'My Office',
607 'post_content' => '',
608 'post_status' => 'publish',
609 'post_type' => 'office',
610 );
611
612 // Insert the post into the database
613 $office_post_id = wp_insert_post( $office_post );
614
615 update_post_meta($office_post_id, 'primary', '1');
616 }
617 }
618
619 /**
620 * Default options
621 *
622 * Sets up the default options used on the settings page
623 *
624 * @access public
625 */
626 function create_options() {
627
628 add_option( 'propertyhive_active_departments_sales', 'yes', '', 'yes' );
629 add_option( 'propertyhive_active_departments_lettings', 'yes', '', 'yes' );
630 add_option( 'propertyhive_primary_department', 'residential-sales', '', 'yes' );
631
632 add_option( 'propertyhive_maps_provider', 'osm', '', 'no' );
633 add_option( 'propertyhive_geocoding_provider', 'osm', '', 'no' );
634
635 add_option( 'propertyhive_default_country', 'GB', '', 'yes' );
636 add_option( 'propertyhive_countries', array('GB'), '', 'yes' );
637
638 add_option( 'propertyhive_applicant_match_price_range_percentage_lower', 20, '', 'no' );
639 add_option( 'propertyhive_applicant_match_price_range_percentage_higher', 5, '', 'no' );
640
641 add_option( 'propertyhive_license_type', 'pro', '', 'yes' );
642
643 add_option( 'propertyhive_install_timestamp', time(), '', 'no' );
644 add_option( 'propertyhive_review_prompt_due_timestamp', strtotime('+30 days'), '', 'no' );
645
646 add_option( 'propertyhive_enquiry_auto_responder_email_subject', __( 'Thank you for your enquiry', 'propertyhive' ), '', 'no' );
647 add_option( 'propertyhive_enquiry_auto_responder_email_body', sprintf(
648 /* translators: %s: blog name shown in the email sign-off */
649 __( "Thank you for your recent property enquiry about [property_address_hyperlinked]. A member of our team will be in touch shortly.
650
651 Kind regards,
652
653 %s
654
655 [similar_properties]", 'propertyhive' ),
656 get_bloginfo('name')
657 ), '', 'no' );
658
659 add_option( 'propertyhive_property_match_default_email_subject', __( 'We found [property_count] that might be of interest to you', 'propertyhive' ), '', 'no' );
660 add_option( 'propertyhive_property_match_default_email_body', __( "Hi [contact_dear],
661
662 Based on your requirements, we've found [property_count] below that we believe might be suitable for you:
663
664 [properties]
665
666 If you have any questions or require more information about any of the properties shown above please let me know.
667
668 Kind regards,
669
670 ", 'propertyhive' ) . get_bloginfo('name'), '', 'no' );
671
672 // Applicant Viewing Booking Confirmation
673 add_option( 'propertyhive_viewing_applicant_booking_confirmation_email_subject', __( 'Your Viewing On [property_address]', 'propertyhive' ), '', 'no' );
674 add_option( 'propertyhive_viewing_applicant_booking_confirmation_email_body', __( "Dear [applicant_dear],
675
676 This is confirmation that your viewing on [property_address] has been booked for [viewing_time] on [viewing_date].
677
678 Should you need to cancel or amend your booking please do not hesitate to contact us.
679
680 ", 'propertyhive' ) . get_bloginfo('name'), '', 'no' );
681
682 // Applicant Viewing Cancellation Notification
683 add_option( 'propertyhive_viewing_applicant_cancellation_notification_email_subject', __( 'Your Viewing On [property_address] Has Been Cancelled', 'propertyhive' ), '', 'no' );
684 add_option( 'propertyhive_viewing_applicant_cancellation_notification_email_body', __( "Dear [applicant_dear],
685
686 This is confirmation that a viewing on [property_address] that was booked for [viewing_time] on [viewing_date] has been cancelled. [cancelled_reason]
687
688 Should you have any questions please do not hesitate to contact us.
689
690 ", 'propertyhive' ) . get_bloginfo('name'), '', 'no' );
691
692 // Owner/Landlord Viewing Booking Confirmation
693 add_option( 'propertyhive_viewing_owner_booking_confirmation_email_subject', __( 'Viewing Booked On [property_address]', 'propertyhive' ), '', 'no' );
694 add_option( 'propertyhive_viewing_owner_booking_confirmation_email_body', __( "Dear [owner_dear],
695
696 This is confirmation that a viewing has been booked at your property, [property_address], for [viewing_time] on [viewing_date].
697
698 Should you need to cancel or amend this viewing please do not hesitate to contact us.
699
700 ", 'propertyhive' ) . get_bloginfo('name'), '', 'no' );
701
702 // Owner/Landlord Viewing Cancellation Notification
703 add_option( 'propertyhive_viewing_owner_cancellation_notification_email_subject', __( 'Viewing Cancelled On [property_address]', 'propertyhive' ), '', 'no' );
704 add_option( 'propertyhive_viewing_owner_cancellation_notification_email_body', __( "Dear [owner_dear],
705
706 This is confirmation that a viewing on [property_address] that was booked for [viewing_time] on [viewing_date] has been cancelled. [cancelled_reason]
707
708 Should you have any questions please do not hesitate to contact us.
709
710 ", 'propertyhive' ) . get_bloginfo('name'), '', 'no' );
711
712 // Attending Negotiator Viewing Booking Confirmation
713 add_option( 'propertyhive_viewing_attending_negotiator_booking_confirmation_email_subject', __( 'Viewing Booked On [property_address]', 'propertyhive' ), '', 'no' );
714 add_option( 'propertyhive_viewing_attending_negotiator_booking_confirmation_email_body', __( "This is confirmation you've been assigned to attend a viewing at property, [property_address], for [viewing_time] on [viewing_date].
715
716 Applicant Details:
717 [applicant_details]
718
719 Owner Details:
720 [owner_details]
721
722 ", 'propertyhive' ) . get_bloginfo('name'), '', 'no' );
723
724 // Attending Negotiator Viewing Cancellation Notification
725 add_option( 'propertyhive_viewing_attending_negotiator_cancellation_notification_email_subject', __( 'Viewing Cancelled On [property_address]', 'propertyhive' ), '', 'no' );
726 add_option( 'propertyhive_viewing_attending_negotiator_cancellation_notification_email_body', __( "This is confirmation that a viewing you were assigned to carry out on [property_address] that was booked for [viewing_time] on [viewing_date] has been cancelled. [cancelled_reason]
727
728 Applicant Details:
729 [applicant_details]
730
731 Owner Details:
732 [owner_details]
733
734 ", 'propertyhive' ) . get_bloginfo('name'), '', 'no' );
735
736 // Owner/Landlord Appraisal Booking Confirmation
737 add_option( 'propertyhive_appraisal_owner_booking_confirmation_email_subject', __( 'Appraisal Booked On [property_address]', 'propertyhive' ), '', 'no' );
738 add_option( 'propertyhive_appraisal_owner_booking_confirmation_email_body', __( "Dear [owner_dear],
739
740 This is confirmation that an appraisal has been booked for your property, [property_address], for [appraisal_time] on [appraisal_date].
741
742 Should you need to cancel or amend this appraisal, please do not hesitate to contact us.
743
744 ", 'propertyhive' ) . get_bloginfo('name'), '', 'no' );
745
746 }
747
748 /**
749 * Set up the database tables which the plugin needs to function.
750 *
751 * Tables:
752 * ph_email_log - Queueing table for emails
753 *
754 * @access public
755 * @return void
756 */
757 private function create_tables() {
758 global $wpdb, $propertyhive;
759
760 $wpdb->hide_errors();
761
762 $collate = '';
763
764 if ( $wpdb->has_cap( 'collation' ) ) {
765 $collate = $wpdb->get_charset_collate();
766 }
767
768 require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
769
770 $tables = "
771 CREATE TABLE {$wpdb->prefix}ph_email_log (
772 email_id bigint(20) unsigned NOT NULL AUTO_INCREMENT,
773 contact_id bigint(20) unsigned NOT NULL,
774 property_ids text NOT NULL,
775 applicant_profile_id tinyint(3) unsigned NOT NULL,
776 to_email_address varchar(255) NOT NULL,
777 cc_email_address varchar(255) NOT NULL,
778 bcc_email_address varchar(255) NOT NULL,
779 from_name varchar(255) NOT NULL,
780 from_email_address varchar(255) NOT NULL,
781 subject varchar(255) NOT NULL,
782 body blob NOT NULL,
783 lock_id varchar(23) NOT NULL,
784 locked_at datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
785 status varchar(5) NOT NULL,
786 send_at datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
787 sent_by bigint(20) unsigned NOT NULL,
788 PRIMARY KEY (email_id)
789 ) $collate;";
790
791 $tables .= "
792 CREATE TABLE {$wpdb->prefix}ph_address_keyword_polygon (
793 address_keyword varchar(255) NOT NULL,
794 polygon_coordinates longtext NOT NULL
795 ) $collate;";
796
797 dbDelta( $tables );
798 }
799
800 /**
801 * Create roles and capabilities
802 */
803 public function create_roles() {
804 global $wp_roles;
805
806 if ( ! class_exists( 'WP_Roles' ) ) {
807 return;
808 }
809
810 if ( ! isset( $wp_roles ) ) {
811 $wp_roles = new WP_Roles();
812 }
813
814 // Property Hive Contact role
815 add_role( 'property_hive_contact', __( 'Property Hive Contact', 'propertyhive' ), array(
816 'read' => true,
817 ) );
818
819 if ( is_object( $wp_roles ) ) {
820
821 $capabilities = $this->get_core_capabilities();
822
823 foreach ( $capabilities as $cap_group ) {
824 foreach ( $cap_group as $cap ) {
825 $wp_roles->add_cap( 'administrator', $cap );
826 $wp_roles->add_cap( 'editor', $cap );
827 }
828 }
829 }
830 }
831
832 /**
833 * Get capabilities for PropertyHive - these are assigned to admin/shop manager during installation or reset
834 *
835 * @access public
836 * @return array
837 */
838 public function get_core_capabilities() {
839 $capabilities = array();
840
841 $capabilities['core'] = array(
842 'manage_propertyhive'/*,
843 'view_propertyhive_reports'*/
844 );
845
846 return $capabilities;
847 }
848
849 /**
850 * propertyhive_remove_roles function.
851 *
852 * @access public
853 * @return void
854 */
855 public function remove_roles() {
856 /*global $wp_roles;
857
858 if ( class_exists( 'WP_Roles' ) ) {
859 if ( ! isset( $wp_roles ) ) {
860 $wp_roles = new WP_Roles();
861 }
862 }*/
863 }
864
865 /**
866 * Create files/directories
867 */
868 private function create_files() {
869 // Install files and folders for uploading files and prevent hotlinking
870 $upload_dir = wp_upload_dir();
871
872 /*$files = array(
873 array(
874 'base' => $upload_dir['basedir'] . '/propertyhive_uploads',
875 'file' => '.htaccess',
876 'content' => 'deny from all'
877 ),
878 array(
879 'base' => $upload_dir['basedir'] . '/propertyhive_uploads',
880 'file' => 'index.html',
881 'content' => ''
882 ),
883 array(
884 'base' => WP_PLUGIN_DIR . "/" . plugin_basename( dirname( dirname( __FILE__ ) ) ) . '/logs',
885 'file' => '.htaccess',
886 'content' => 'deny from all'
887 ),
888 array(
889 'base' => WP_PLUGIN_DIR . "/" . plugin_basename( dirname( dirname( __FILE__ ) ) ) . '/logs',
890 'file' => 'index.html',
891 'content' => ''
892 )
893 );
894
895 foreach ( $files as $file ) {
896 if ( wp_mkdir_p( $file['base'] ) && ! file_exists( trailingslashit( $file['base'] ) . $file['file'] ) ) {
897 if ( $file_handle = @fopen( trailingslashit( $file['base'] ) . $file['file'], 'w' ) ) {
898 fwrite( $file_handle, $file['content'] );
899 fclose( $file_handle );
900 }
901 }
902 }*/
903 }
904
905 /**
906 * Active plugins pre update option filter
907 *
908 * @param string $new_value
909 * @return string
910 */
911 function pre_update_option_active_plugins( $new_value ) {
912 /*$old_value = (array) get_option( 'active_plugins' );
913
914 if ( $new_value !== $old_value && in_array( W3TC_FILE, (array) $new_value ) && in_array( W3TC_FILE, (array) $old_value ) ) {
915 $this->_config->set( 'notes.plugins_updated', true );
916 try {
917 $this->_config->save();
918 } catch( Exception $ex ) {}
919 }
920
921 return $new_value;*/
922 }
923
924 /**
925 * Show plugin changes. Code adapted from W3 Total Cache.
926 *
927 * @return void
928 */
929 function in_plugin_update_message( $args ) {
930 /*$transient_name = 'ph_upgrade_notice_' . $args['Version'];
931
932 if ( false === ( $upgrade_notice = get_transient( $transient_name ) ) ) {
933
934 $response = wp_remote_get( 'https://plugins.svn.wordpress.org/propertyhive/trunk/readme.txt' );
935
936 if ( ! is_wp_error( $response ) && ! empty( $response['body'] ) ) {
937
938 // Output Upgrade Notice
939 $matches = null;
940 $regexp = '~==\s*Upgrade Notice\s*==\s*=\s*(.*)\s*=(.*)(=\s*' . preg_quote( PH_VERSION ) . '\s*=|$)~Uis';
941 $upgrade_notice = '';
942
943 if ( preg_match( $regexp, $response['body'], $matches ) ) {
944 $version = trim( $matches[1] );
945 $notices = (array) preg_split('~[\r\n]+~', trim( $matches[2] ) );
946
947 if ( version_compare( PH_VERSION, $version, '<' ) ) {
948
949 $upgrade_notice .= '<div class="ph_plugin_upgrade_notice">';
950
951 foreach ( $notices as $index => $line ) {
952 $upgrade_notice .= wp_kses_post( preg_replace( '~\[([^\]]*)\]\(([^\)]*)\)~', '<a href="${2}">${1}</a>', $line ) );
953 }
954
955 $upgrade_notice .= '</div> ';
956 }
957 }
958
959 set_transient( $transient_name, $upgrade_notice, DAY_IN_SECONDS );
960 }
961 }
962
963 echo wp_kses_post( $upgrade_notice );*/
964 }
965 }
966
967 endif;
968
969 return new PH_Install();
970