| 1 |
<?php |
| 2 |
/** |
| 3 |
* PropertyHive Admin Reports Class. |
| 4 |
* |
| 5 |
* @author PropertyHive |
| 6 |
* @category Admin |
| 7 |
* @package PropertyHive/Admin |
| 8 |
* @version 1.0.0 |
| 9 |
*/ |
| 10 |
|
| 11 |
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
| 12 |
|
| 13 |
if ( ! class_exists( 'PH_Admin_Reports' ) ) : |
| 14 |
|
| 15 |
/** |
| 16 |
* PH_Admin_Reports |
| 17 |
*/ |
| 18 |
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedClassFound -- Legacy public global class PH_Admin_Reports; preserving the existing PH_* class name is required for plugin and extension compatibility. |
| 19 |
class PH_Admin_Reports { |
| 20 |
|
| 21 |
/** |
| 22 |
* Handles the display of the main Property Hive reports page in admin. |
| 23 |
* |
| 24 |
* @access public |
| 25 |
* @return void |
| 26 |
*/ |
| 27 |
public static function output() { |
| 28 |
|
| 29 |
if ( ! current_user_can( 'manage_propertyhive' ) ) { |
| 30 |
return; |
| 31 |
} |
| 32 |
|
| 33 |
$reports = self::get_reports(); |
| 34 |
if ( empty( $reports ) ) { |
| 35 |
return; |
| 36 |
} |
| 37 |
$first_tab = array_keys( $reports ); |
| 38 |
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Authorized read-only report navigation; no state-changing action is performed. |
| 39 |
$current_tab = ! empty( $_GET['tab'] ) && is_string( $_GET['tab'] ) ? sanitize_title( wp_unslash( $_GET['tab'] ) ) : $first_tab[0]; |
| 40 |
if ( ! isset( $reports[ $current_tab ] ) ) { |
| 41 |
$current_tab = $first_tab[0]; |
| 42 |
} |
| 43 |
$report_keys = array_keys( $reports[ $current_tab ]['reports'] ); |
| 44 |
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Authorized read-only report navigation; callbacks are selected only from registered reports. |
| 45 |
$current_report = isset( $_GET['report'] ) && is_string( $_GET['report'] ) ? sanitize_title( wp_unslash( $_GET['report'] ) ) : current( $report_keys ); |
| 46 |
|
| 47 |
include_once( 'reports/class-ph-admin-report.php' ); |
| 48 |
include_once( 'views/html-admin-page-reports.php' ); |
| 49 |
} |
| 50 |
|
| 51 |
/** |
| 52 |
* Returns the definitions for the reports to show in admin. |
| 53 |
* |
| 54 |
* @return array |
| 55 |
*/ |
| 56 |
public static function get_reports() |
| 57 |
{ |
| 58 |
$reports = array( |
| 59 |
'properties' => array( |
| 60 |
'title' => __( 'Properties', 'propertyhive' ), |
| 61 |
'reports' => array() |
| 62 |
) |
| 63 |
); |
| 64 |
|
| 65 |
if ( get_option('propertyhive_active_departments_sales', '') == 'yes' ) |
| 66 |
{ |
| 67 |
$reports['properties']['reports']['sales_property_stock_analysis'] = array( |
| 68 |
'title' => __( 'Sales Property Stock Analysis', 'propertyhive' ), |
| 69 |
'description' => '', |
| 70 |
'hide_title' => true, |
| 71 |
'callback' => array( __CLASS__, 'get_report' ) |
| 72 |
); |
| 73 |
$reports['properties']['reports']['sales_property_popularity'] = array( |
| 74 |
'title' => __( 'Sales Property Popularity', 'propertyhive' ), |
| 75 |
'description' => '', |
| 76 |
'hide_title' => true, |
| 77 |
'callback' => array( __CLASS__, 'get_report' ) |
| 78 |
); |
| 79 |
} |
| 80 |
|
| 81 |
if ( get_option('propertyhive_active_departments_lettings', '') == 'yes' ) |
| 82 |
{ |
| 83 |
$reports['properties']['reports']['lettings_property_stock_analysis'] = array( |
| 84 |
'title' => __( 'Lettings Property Stock Analysis', 'propertyhive' ), |
| 85 |
'description' => '', |
| 86 |
'hide_title' => true, |
| 87 |
'callback' => array( __CLASS__, 'get_report' ) |
| 88 |
); |
| 89 |
$reports['properties']['reports']['lettings_property_popularity'] = array( |
| 90 |
'title' => __( 'Lettings Property Popularity', 'propertyhive' ), |
| 91 |
'description' => '', |
| 92 |
'hide_title' => true, |
| 93 |
'callback' => array( __CLASS__, 'get_report' ) |
| 94 |
); |
| 95 |
} |
| 96 |
|
| 97 |
$reports['properties']['reports']['incomplete_properties'] = array( |
| 98 |
'title' => __( 'Incomplete Properties', 'propertyhive' ), |
| 99 |
'description' => '', |
| 100 |
'hide_title' => true, |
| 101 |
'callback' => array( __CLASS__, 'get_report' ) |
| 102 |
); |
| 103 |
|
| 104 |
/*if ( get_option('propertyhive_module_disabled_contacts', '') != 'yes' ) |
| 105 |
{ |
| 106 |
$reports['applicants'] = array( |
| 107 |
'title' => __( 'Applicants', 'propertyhive' ), |
| 108 |
'reports' => array( |
| 109 |
"applicant_demand_analysis" => array( |
| 110 |
'title' => __( 'Applicant Demand Analysis', 'propertyhive' ), |
| 111 |
'description' => '', |
| 112 |
'hide_title' => true, |
| 113 |
'callback' => array( __CLASS__, 'get_report' ) |
| 114 |
), |
| 115 |
) |
| 116 |
); |
| 117 |
}*/ |
| 118 |
|
| 119 |
$reports = apply_filters( 'propertyhive_admin_reports', $reports ); |
| 120 |
|
| 121 |
foreach ( $reports as $key => $report_group ) { |
| 122 |
if ( isset( $reports[ $key ]['charts'] ) ) { |
| 123 |
$reports[ $key ]['reports'] = $reports[ $key ]['charts']; |
| 124 |
} |
| 125 |
|
| 126 |
foreach ( $reports[ $key ]['reports'] as $report_key => $report ) { |
| 127 |
if ( isset( $reports[ $key ]['reports'][ $report_key ]['function'] ) ) { |
| 128 |
$reports[ $key ]['reports'][ $report_key ]['callback'] = $reports[ $key ]['reports'][ $report_key ]['function']; |
| 129 |
} |
| 130 |
} |
| 131 |
} |
| 132 |
|
| 133 |
return $reports; |
| 134 |
} |
| 135 |
|
| 136 |
/** |
| 137 |
* Get a report from our reports subfolder. |
| 138 |
*/ |
| 139 |
public static function get_report( $name ) { |
| 140 |
$name = sanitize_title( str_replace( '_', '-', $name ) ); |
| 141 |
$class = 'PH_Report_' . str_replace( '-', '_', $name ); |
| 142 |
|
| 143 |
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Existing public Property Hive extension hook ph_admin_reports_path; changing the established name would detach installed callbacks. |
| 144 |
include_once( apply_filters( 'ph_admin_reports_path', 'reports/class-ph-report-' . $name . '.php', $name, $class ) ); |
| 145 |
|
| 146 |
if ( ! class_exists( $class ) ) |
| 147 |
return; |
| 148 |
|
| 149 |
$report = new $class(); |
| 150 |
$report->output_report(); |
| 151 |
} |
| 152 |
} |
| 153 |
|
| 154 |
endif; |