| 1 |
<?php |
| 2 |
/** |
| 3 |
* PropertyHive Admin Functions |
| 4 |
* |
| 5 |
* @author PropertyHive |
| 6 |
* @category Core |
| 7 |
* @package PropertyHive/Admin/Functions |
| 8 |
* @version 1.0.0 |
| 9 |
*/ |
| 10 |
|
| 11 |
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
| 12 |
|
| 13 |
/** |
| 14 |
* Get all PropertyHive screen ids |
| 15 |
* |
| 16 |
* @return array |
| 17 |
*/ |
| 18 |
function ph_get_screen_ids() { |
| 19 |
$ph_screen_id = sanitize_title( __( 'PropertyHive', 'propertyhive' ) ); |
| 20 |
|
| 21 |
return apply_filters( 'propertyhive_screen_ids', array( |
| 22 |
'edit-property', |
| 23 |
'property', |
| 24 |
'edit-contact', |
| 25 |
'contact', |
| 26 |
'enquiry', |
| 27 |
'appraisal', |
| 28 |
'viewing', |
| 29 |
'offer', |
| 30 |
'sale', |
| 31 |
'dashboard_page_ph-installed', |
| 32 |
'property-hive_page_ph-settings', |
| 33 |
'admin_page_ph-generate-applicant-list', |
| 34 |
) ); |
| 35 |
} |
| 36 |
|
| 37 |
/** |
| 38 |
* Create a page and store the ID in an option. |
| 39 |
* |
| 40 |
* @access public |
| 41 |
* @param mixed $slug Slug for the new page |
| 42 |
* @param mixed $option Option name to store the page's ID |
| 43 |
* @param string $page_title (default: '') Title for the new page |
| 44 |
* @param string $page_content (default: '') Content for the new page |
| 45 |
* @param int $post_parent (default: 0) Parent for the new page |
| 46 |
* @return int page ID |
| 47 |
*/ |
| 48 |
function ph_create_page( $slug, $option = '', $page_title = '', $page_content = '', $post_parent = 0 ) { |
| 49 |
global $wpdb; |
| 50 |
|
| 51 |
/*$option_value = get_option( $option ); |
| 52 |
|
| 53 |
if ( $option_value > 0 && get_post( $option_value ) ) |
| 54 |
return -1; |
| 55 |
|
| 56 |
$page_found = null; |
| 57 |
|
| 58 |
if ( strlen( $page_content ) > 0 ) { |
| 59 |
// Search for an existing page with the specified page content (typically a shortcode) |
| 60 |
$page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM " . $wpdb->posts . " WHERE post_type='page' AND post_content LIKE %s LIMIT 1;", "%{$page_content}%" ) ); |
| 61 |
} else { |
| 62 |
// Search for an existing page with the specified page slug |
| 63 |
$page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM " . $wpdb->posts . " WHERE post_type='page' AND post_name = %s LIMIT 1;", $slug ) ); |
| 64 |
} |
| 65 |
|
| 66 |
if ( $page_found ) { |
| 67 |
if ( ! $option_value ) |
| 68 |
update_option( $option, $page_found ); |
| 69 |
|
| 70 |
return $page_found; |
| 71 |
} |
| 72 |
|
| 73 |
$page_data = array( |
| 74 |
'post_status' => 'publish', |
| 75 |
'post_type' => 'page', |
| 76 |
'post_author' => 1, |
| 77 |
'post_name' => $slug, |
| 78 |
'post_title' => $page_title, |
| 79 |
'post_content' => $page_content, |
| 80 |
'post_parent' => $post_parent, |
| 81 |
'comment_status' => 'closed' |
| 82 |
); |
| 83 |
$page_id = wp_insert_post( $page_data ); |
| 84 |
|
| 85 |
if ( $option ) |
| 86 |
update_option( $option, $page_id ); |
| 87 |
|
| 88 |
return $page_id;*/ |
| 89 |
} |
| 90 |
|
| 91 |
/** |
| 92 |
* Output admin fields. |
| 93 |
* |
| 94 |
* Loops though the PropertyHive options array and outputs each field. |
| 95 |
* |
| 96 |
* @param array $options Opens array to output |
| 97 |
*/ |
| 98 |
function propertyhive_admin_fields( $options ) { |
| 99 |
if ( ! class_exists( 'PH_Admin_Settings' ) ) |
| 100 |
include 'class-ph-admin-settings.php'; |
| 101 |
|
| 102 |
PH_Admin_Settings::output_fields( $options ); |
| 103 |
} |
| 104 |
|
| 105 |
/** |
| 106 |
* Update all settings which are passed. |
| 107 |
* |
| 108 |
* @access public |
| 109 |
* @param array $options |
| 110 |
* @return void |
| 111 |
*/ |
| 112 |
function propertyhive_update_options( $options ) { |
| 113 |
if ( ! class_exists( 'PH_Admin_Settings' ) ) |
| 114 |
include 'class-ph-admin-settings.php'; |
| 115 |
|
| 116 |
PH_Admin_Settings::save_fields( $options ); |
| 117 |
} |
| 118 |
|
| 119 |
/** |
| 120 |
* Get a setting from the settings API. |
| 121 |
* |
| 122 |
* @param mixed $option |
| 123 |
* @return string |
| 124 |
*/ |
| 125 |
function propertyhive_settings_get_option( $option_name, $default = '' ) { |
| 126 |
if ( ! class_exists( 'PH_Admin_Settings' ) ) |
| 127 |
include 'class-ph-admin-settings.php'; |
| 128 |
|
| 129 |
return PH_Admin_Settings::get_option( $option_name, $default ); |
| 130 |
} |
| 131 |
|
| 132 |
/** |
| 133 |
* Generate CSS from the less file when changing colours. |
| 134 |
* |
| 135 |
* @access public |
| 136 |
* @return void |
| 137 |
*/ |
| 138 |
function propertyhive_compile_less_styles() { |
| 139 |
/*global $propertyhive; |
| 140 |
|
| 141 |
$colors = array_map( 'esc_attr', (array) get_option( 'propertyhive_frontend_css_colors' ) ); |
| 142 |
$base_file = PH()->plugin_path() . '/assets/css/propertyhive-base.less'; |
| 143 |
$less_file = PH()->plugin_path() . '/assets/css/propertyhive.less'; |
| 144 |
$css_file = PH()->plugin_path() . '/assets/css/propertyhive.css'; |
| 145 |
|
| 146 |
// Write less file |
| 147 |
if ( is_writable( $base_file ) && is_writable( $css_file ) ) { |
| 148 |
|
| 149 |
// Colours changed - recompile less |
| 150 |
if ( ! class_exists( 'lessc' ) ) |
| 151 |
include_once( PH()->plugin_path() . '/includes/libraries/class-lessc.php' ); |
| 152 |
if ( ! class_exists( 'cssmin' ) ) |
| 153 |
include_once( PH()->plugin_path() . '/includes/libraries/class-cssmin.php' ); |
| 154 |
|
| 155 |
try { |
| 156 |
// Set default if colours not set |
| 157 |
if ( ! $colors['primary'] ) $colors['primary'] = '#ad74a2'; |
| 158 |
if ( ! $colors['secondary'] ) $colors['secondary'] = '#f7f6f7'; |
| 159 |
if ( ! $colors['highlight'] ) $colors['highlight'] = '#85ad74'; |
| 160 |
if ( ! $colors['content_bg'] ) $colors['content_bg'] = '#ffffff'; |
| 161 |
if ( ! $colors['subtext'] ) $colors['subtext'] = '#777777'; |
| 162 |
|
| 163 |
// Write new color to base file |
| 164 |
$color_rules = " |
| 165 |
@primary: " . $colors['primary'] . "; |
| 166 |
@primarytext: " . ph_light_or_dark( $colors['primary'], 'desaturate(darken(@primary,50%),18%)', 'desaturate(lighten(@primary,50%),18%)' ) . "; |
| 167 |
|
| 168 |
@secondary: " . $colors['secondary'] . "; |
| 169 |
@secondarytext: " . ph_light_or_dark( $colors['secondary'], 'desaturate(darken(@secondary,60%),18%)', 'desaturate(lighten(@secondary,60%),18%)' ) . "; |
| 170 |
|
| 171 |
@highlight: " . $colors['highlight'] . "; |
| 172 |
@highlightext: " . ph_light_or_dark( $colors['highlight'], 'desaturate(darken(@highlight,60%),18%)', 'desaturate(lighten(@highlight,60%),18%)' ) . "; |
| 173 |
|
| 174 |
@contentbg: " . $colors['content_bg'] . "; |
| 175 |
|
| 176 |
@subtext: " . $colors['subtext'] . "; |
| 177 |
"; |
| 178 |
|
| 179 |
file_put_contents( $base_file, $color_rules ); |
| 180 |
|
| 181 |
$less = new lessc; |
| 182 |
$compiled_css = $less->compileFile( $less_file ); |
| 183 |
$compiled_css = CssMin::minify( $compiled_css ); |
| 184 |
|
| 185 |
if ( $compiled_css ) |
| 186 |
file_put_contents( $css_file, $compiled_css ); |
| 187 |
|
| 188 |
} catch ( exception $ex ) { |
| 189 |
wp_die( __( 'Could not compile propertyhive.less:', 'propertyhive' ) . ' ' . $ex->getMessage() ); |
| 190 |
} |
| 191 |
}*/ |
| 192 |
} |
| 193 |
|