/**
  * Localize scripts only when enqueued
  */
 public static function localize_printed_scripts()
 {
     global $wp;
     $assets_path = str_replace(array('http:', 'https:'), '', PH()->plugin_url()) . '/assets/';
     if (wp_script_is('propertyhive_make_enquiry')) {
         wp_localize_script('propertyhive_make_enquiry', 'propertyhive_make_property_enquiry_params', apply_filters('propertyhive_make_property_enquiry_params', array('ajax_url' => PH()->ajax_url())));
     }
 }
 /**
  * Add menu items
  */
 public function admin_menu()
 {
     global $menu, $propertyhive;
     //if ( current_user_can( 'manage_propertyhive' ) )
     $menu[] = array('', 'read', 'separator-propertyhive', '', 'wp-menu-separator propertyhive');
     add_menu_page(__('Property Hive', 'propertyhive'), __('Property Hive', 'propertyhive'), 'manage_propertyhive', 'propertyhive', array($this, 'settings_page'), PH()->plugin_url() . '/assets/images/menu-icon.png', '54.5');
     add_submenu_page('propertyhive', __('Properties', 'propertyhive'), __('Properties', 'propertyhive'), 'manage_propertyhive', 'edit.php?post_type=property');
     add_submenu_page('propertyhive', __('Property Owners and Landlords', 'propertyhive'), __('Owners & Landlords', 'propertyhive'), 'manage_propertyhive', 'edit.php?post_type=contact&_contact_type=owner');
     add_submenu_page('propertyhive', __('Applicants', 'propertyhive'), __('Applicants', 'propertyhive'), 'manage_propertyhive', 'edit.php?post_type=contact&_contact_type=applicant');
     add_submenu_page('propertyhive', __('Third Party Contacts', 'propertyhive'), __('Third Party Contacts', 'propertyhive'), 'manage_propertyhive', 'edit.php?post_type=contact&_contact_type=thirdparty');
     add_submenu_page('propertyhive', __('Enquiries', 'propertyhive'), __('Enquiries', 'propertyhive'), 'manage_propertyhive', 'edit.php?post_type=enquiry');
     //add_submenu_page( 'propertyhive', __( 'Reports', 'propertyhive' ), __( 'Reports', 'propertyhive' ), 'manage_propertyhive', 'edit.php?post_type=reports'/*, array( $this, 'attributes_page' )*/ );
     add_submenu_page(null, __('Applicant Matching Properties', 'propertyhive'), __('Applicant Matching Properties', 'propertyhive'), 'manage_propertyhive', 'ph-matching-properties', array($this, 'matching_properties_page'));
     //remove_submenu_page( 'propertyhive', 'ph-matching-properties' );
 }
 /**
  * Load a template.
  *
  * Handles template usage so that we can use our own templates instead of the themes.
  *
  * Templates are in the 'templates' folder. propertyhive looks for theme
  * overrides in /theme/propertyhive/ by default
  *
  * For beginners, it also looks for a propertyhive.php template first. If the user adds
  * this to the theme (containing a propertyhive() inside) this will be used for all
  * propertyhive templates.
  *
  * @param mixed $template
  * @return string
  */
 public function template_loader($template)
 {
     $find = array('propertyhive.php');
     $file = '';
     if (is_single() && get_post_type() == 'property') {
         $file = 'single-property.php';
         $find[] = $file;
         $find[] = PH_TEMPLATE_PATH . $file;
     } elseif (is_post_type_archive('property') || is_page(ph_get_page_id('search_results'))) {
         $file = 'archive-property.php';
         $find[] = $file;
         $find[] = PH_TEMPLATE_PATH . $file;
     }
     if ($file) {
         $template = locate_template(array_unique($find));
         $status_options = get_option('propertyhive_status_options', array());
         if (!$template || !empty($status_options['template_debug_mode']) && current_user_can('manage_options')) {
             $template = PH()->plugin_path() . '/templates/' . $file;
         }
     }
     return $template;
 }
 /**
  * View previously sent email
  *
  * @return string
  */
 public function view_email()
 {
     global $wpdb;
     if (isset($_GET['view_propertyhive_email'])) {
         if (!wp_verify_nonce($_REQUEST['_wpnonce'], 'view-email')) {
             die('Security check');
         }
         if (isset($_GET['email_id'])) {
             $email_log = $wpdb->get_row("SELECT * FROM " . $wpdb->prefix . "ph_email_log WHERE email_id = '" . esc_sql($_GET['email_id']) . "'");
             if (null !== $email_log) {
                 echo apply_filters('propertyhive_mail_content', PH()->email->style_inline(PH()->email->wrap_message($email_log->body)));
             } else {
                 die("Email not found");
             }
         }
         exit;
     }
 }
        /**
         * Output admin fields.
         *
         * Loops though the propertyhive options array and outputs each field.
         *
         * @access public
         * @param array $options Opens array to output
         */
        public static function output_fields($options)
        {
            foreach ($options as $value) {
                if (!isset($value['type'])) {
                    continue;
                }
                if (!isset($value['id'])) {
                    $value['id'] = '';
                }
                if (!isset($value['title'])) {
                    $value['title'] = isset($value['name']) ? $value['name'] : '';
                }
                if (!isset($value['class'])) {
                    $value['class'] = '';
                }
                if (!isset($value['css'])) {
                    $value['css'] = '';
                }
                if (!isset($value['default'])) {
                    $value['default'] = '';
                }
                if (!isset($value['desc'])) {
                    $value['desc'] = '';
                }
                if (!isset($value['desc_tip'])) {
                    $value['desc_tip'] = false;
                }
                // Custom attribute handling
                $custom_attributes = array();
                if (!empty($value['custom_attributes']) && is_array($value['custom_attributes'])) {
                    foreach ($value['custom_attributes'] as $attribute => $attribute_value) {
                        $custom_attributes[] = esc_attr($attribute) . '="' . esc_attr($attribute_value) . '"';
                    }
                }
                // Description handling
                if ($value['desc_tip'] === true) {
                    $description = '';
                    $tip = $value['desc'];
                } elseif (!empty($value['desc_tip'])) {
                    $description = $value['desc'];
                    $tip = $value['desc_tip'];
                } elseif (!empty($value['desc'])) {
                    $description = $value['desc'];
                    $tip = '';
                } else {
                    $description = $tip = '';
                }
                if ($description && in_array($value['type'], array('textarea', 'radio'))) {
                    $description = '<p style="margin-top:0">' . wp_kses_post($description) . '</p>';
                } elseif ($description && in_array($value['type'], array('checkbox'))) {
                    $description = wp_kses_post($description);
                } elseif ($description) {
                    $description = '<span class="description">' . wp_kses_post($description) . '</span>';
                }
                if ($tip && in_array($value['type'], array('checkbox'))) {
                    $tip = '<p class="description">' . $tip . '</p>';
                } elseif ($tip) {
                    $tip = '<img class="help_tip" data-tip="' . esc_attr($tip) . '" src="' . PH()->plugin_url() . '/assets/images/help.png" height="16" width="16" />';
                }
                // Switch based on type
                switch ($value['type']) {
                    // Section Titles
                    case 'title':
                        if (!empty($value['title'])) {
                            echo '<h3>' . esc_html($value['title']) . '</h3>';
                        }
                        if (!empty($value['desc'])) {
                            echo wpautop(wptexturize(wp_kses_post($value['desc'])));
                        }
                        echo '<table class="form-table">' . "\n\n";
                        if (!empty($value['id'])) {
                            do_action('propertyhive_settings_' . sanitize_title($value['id']));
                        }
                        break;
                        // Section Ends
                    // Section Ends
                    case 'sectionend':
                        if (!empty($value['id'])) {
                            do_action('propertyhive_settings_' . sanitize_title($value['id']) . '_end');
                        }
                        echo '</table>';
                        if (!empty($value['id'])) {
                            do_action('propertyhive_settings_' . sanitize_title($value['id']) . '_after');
                        }
                        break;
                    case 'html':
                        ?>
                <tr valign="top">
                        <th scope="row" class="titledesc">
                            <label for="<?php 
                        echo esc_attr($value['id']);
                        ?>
"><?php 
                        echo esc_html($value['title']);
                        ?>
</label>
                            <?php 
                        echo $tip;
                        ?>
                        </th>
                        <td class="forminp forminp-<?php 
                        echo sanitize_title($value['type']);
                        ?>
">
                            <?php 
                        echo $value['html'];
                        ?>
                        </td>
                    </tr>
                <?php 
                        break;
                        // Standard text inputs and subtypes like 'number'
                    // Standard text inputs and subtypes like 'number'
                    case 'text':
                    case 'email':
                    case 'number':
                    case 'color':
                    case 'password':
                        $type = $value['type'];
                        $class = '';
                        $option_value = self::get_option($value['id'], $value['default']);
                        if ($value['type'] == 'color') {
                            $type = 'text';
                            $value['class'] .= 'colorpick';
                            $description .= '<div id="colorPickerDiv_' . esc_attr($value['id']) . '" class="colorpickdiv" style="z-index: 100;background:#eee;border:1px solid #ccc;position:absolute;display:none;"></div>';
                        }
                        ?>
<tr valign="top">
						<th scope="row" class="titledesc">
							<label for="<?php 
                        echo esc_attr($value['id']);
                        ?>
"><?php 
                        echo esc_html($value['title']);
                        ?>
</label>
							<?php 
                        echo $tip;
                        ?>
						</th>
	                    <td class="forminp forminp-<?php 
                        echo sanitize_title($value['type']);
                        ?>
">
	                    	<input
	                    		name="<?php 
                        echo esc_attr($value['id']);
                        ?>
"
	                    		id="<?php 
                        echo esc_attr($value['id']);
                        ?>
"
	                    		type="<?php 
                        echo esc_attr($type);
                        ?>
"
	                    		style="<?php 
                        echo esc_attr($value['css']);
                        ?>
"
	                    		value="<?php 
                        echo esc_attr($option_value);
                        ?>
"
	                    		class="<?php 
                        echo esc_attr($value['class']);
                        ?>
"
	                    		<?php 
                        echo implode(' ', $custom_attributes);
                        ?>
	                    		/> <?php 
                        echo $description;
                        ?>
	                    </td>
	                </tr><?php 
                        break;
                        // Hidden
                    // Hidden
                    case 'hidden':
                        $option_value = self::get_option($value['id'], $value['default']);
                        ?>
<input type="hidden" 
                        name="<?php 
                        echo esc_attr($value['id']);
                        ?>
" 
                        value="<?php 
                        echo esc_attr($option_value);
                        ?>
"
                        /><?php 
                        break;
                        // Textarea
                    // Textarea
                    case 'textarea':
                        $option_value = self::get_option($value['id'], $value['default']);
                        ?>
<tr valign="top">
						<th scope="row" class="titledesc">
							<label for="<?php 
                        echo esc_attr($value['id']);
                        ?>
"><?php 
                        echo esc_html($value['title']);
                        ?>
</label>
							<?php 
                        echo $tip;
                        ?>
						</th>
	                    <td class="forminp forminp-<?php 
                        echo sanitize_title($value['type']);
                        ?>
">
	                    	<?php 
                        echo $description;
                        ?>

	                        <textarea
	                        	name="<?php 
                        echo esc_attr($value['id']);
                        ?>
"
	                        	id="<?php 
                        echo esc_attr($value['id']);
                        ?>
"
	                        	style="<?php 
                        echo esc_attr($value['css']);
                        ?>
"
	                        	class="<?php 
                        echo esc_attr($value['class']);
                        ?>
"
	                        	<?php 
                        echo implode(' ', $custom_attributes);
                        ?>
	                        	><?php 
                        echo esc_textarea($option_value);
                        ?>
</textarea>
	                    </td>
	                </tr><?php 
                        break;
                        // Select boxes
                    // Select boxes
                    case 'select':
                    case 'multiselect':
                        $option_value = self::get_option($value['id'], $value['default']);
                        ?>
<tr valign="top">
						<th scope="row" class="titledesc">
							<label for="<?php 
                        echo esc_attr($value['id']);
                        ?>
"><?php 
                        echo esc_html($value['title']);
                        ?>
</label>
							<?php 
                        echo $tip;
                        ?>
						</th>
	                    <td class="forminp forminp-<?php 
                        echo sanitize_title($value['type']);
                        ?>
">
	                    	<select
	                    		name="<?php 
                        echo esc_attr($value['id']);
                        if ($value['type'] == 'multiselect') {
                            echo '[]';
                        }
                        ?>
"
	                    		id="<?php 
                        echo esc_attr($value['id']);
                        ?>
"
	                    		style="<?php 
                        echo esc_attr($value['css']);
                        ?>
"
	                    		class="<?php 
                        echo esc_attr($value['class']);
                        ?>
"
	                    		<?php 
                        echo implode(' ', $custom_attributes);
                        ?>
	                    		<?php 
                        if ($value['type'] == 'multiselect') {
                            echo 'multiple="multiple"';
                        }
                        ?>
	                    		>
		                    	<?php 
                        foreach ($value['options'] as $key => $val) {
                            ?>
			                        	<option value="<?php 
                            echo esc_attr($key);
                            ?>
" <?php 
                            if (is_array($option_value)) {
                                selected(in_array($key, $option_value), true);
                            } else {
                                selected($option_value, $key);
                            }
                            ?>
><?php 
                            echo $val;
                            ?>
</option>
			                        	<?php 
                        }
                        ?>
	                       </select> <?php 
                        echo $description;
                        ?>
	                    </td>
	                </tr><?php 
                        break;
                        // Radio inputs
                    // Radio inputs
                    case 'radio':
                        $option_value = self::get_option($value['id'], $value['default']);
                        ?>
<tr valign="top">
						<th scope="row" class="titledesc">
							<label for="<?php 
                        echo esc_attr($value['id']);
                        ?>
"><?php 
                        echo esc_html($value['title']);
                        ?>
</label>
							<?php 
                        echo $tip;
                        ?>
						</th>
	                    <td class="forminp forminp-<?php 
                        echo sanitize_title($value['type']);
                        ?>
">
	                    	<fieldset>
	                    		<?php 
                        echo $description;
                        ?>
	                    		<ul>
	                    		<?php 
                        foreach ($value['options'] as $key => $val) {
                            ?>
			                        	<li>
			                        		<label><input
				                        		name="<?php 
                            echo esc_attr($value['id']);
                            ?>
"
				                        		value="<?php 
                            echo $key;
                            ?>
"
				                        		type="radio"
					                    		style="<?php 
                            echo esc_attr($value['css']);
                            ?>
"
					                    		class="<?php 
                            echo esc_attr($value['class']);
                            ?>
"
					                    		<?php 
                            echo implode(' ', $custom_attributes);
                            ?>
					                    		<?php 
                            checked($key, $option_value);
                            ?>
				                        		/> <?php 
                            echo $val;
                            ?>
</label>
			                        	</li>
			                        	<?php 
                        }
                        ?>
	                    		</ul>
	                    	</fieldset>
	                    </td>
	                </tr><?php 
                        break;
                        // Checkbox input
                    // Checkbox input
                    case 'checkbox':
                        $option_value = self::get_option($value['id'], $value['default']);
                        $visbility_class = array();
                        if (!isset($value['hide_if_checked'])) {
                            $value['hide_if_checked'] = false;
                        }
                        if (!isset($value['show_if_checked'])) {
                            $value['show_if_checked'] = false;
                        }
                        if ($value['hide_if_checked'] == 'yes' || $value['show_if_checked'] == 'yes') {
                            $visbility_class[] = 'hidden_option';
                        }
                        if ($value['hide_if_checked'] == 'option') {
                            $visbility_class[] = 'hide_options_if_checked';
                        }
                        if ($value['show_if_checked'] == 'option') {
                            $visbility_class[] = 'show_options_if_checked';
                        }
                        if (!isset($value['checkboxgroup']) || 'start' == $value['checkboxgroup']) {
                            ?>
		            		<tr valign="top" class="<?php 
                            echo esc_attr(implode(' ', $visbility_class));
                            ?>
">
								<th scope="row" class="titledesc"><?php 
                            echo esc_html($value['title']);
                            ?>
</th>
								<td class="forminp forminp-checkbox">
									<fieldset>
						<?php 
                        } else {
                            ?>
		            		<fieldset class="<?php 
                            echo esc_attr(implode(' ', $visbility_class));
                            ?>
">
	            		<?php 
                        }
                        if (!empty($value['title'])) {
                            ?>
	            			<legend class="screen-reader-text"><span><?php 
                            echo esc_html($value['title']);
                            ?>
</span></legend>
	            		<?php 
                        }
                        ?>
						<label for="<?php 
                        echo $value['id'];
                        ?>
">
							<input
								name="<?php 
                        echo esc_attr($value['id']);
                        ?>
"
								id="<?php 
                        echo esc_attr($value['id']);
                        ?>
"
								type="checkbox"
								value="1"
								<?php 
                        checked($option_value, 'yes');
                        ?>
								<?php 
                        echo implode(' ', $custom_attributes);
                        ?>
							/> <?php 
                        echo $description;
                        ?>
						</label> <?php 
                        echo $tip;
                        ?>
					<?php 
                        if (!isset($value['checkboxgroup']) || 'end' == $value['checkboxgroup']) {
                            ?>
									</fieldset>
								</td>
							</tr>
						<?php 
                        } else {
                            ?>
							</fieldset>
						<?php 
                        }
                        break;
                        // Image width settings
                    // Image width settings
                    case 'image_width':
                        $width = self::get_option($value['id'] . '[width]', $value['default']['width']);
                        $height = self::get_option($value['id'] . '[height]', $value['default']['height']);
                        $crop = checked(1, self::get_option($value['id'] . '[crop]', $value['default']['crop']), false);
                        ?>
<tr valign="top">
						<th scope="row" class="titledesc"><?php 
                        echo esc_html($value['title']);
                        ?>
 <?php 
                        echo $tip;
                        ?>
</th>
	                    <td class="forminp image_width_settings">

	                    	<input name="<?php 
                        echo esc_attr($value['id']);
                        ?>
[width]" id="<?php 
                        echo esc_attr($value['id']);
                        ?>
-width" type="text" size="3" value="<?php 
                        echo $width;
                        ?>
" /> &times; <input name="<?php 
                        echo esc_attr($value['id']);
                        ?>
[height]" id="<?php 
                        echo esc_attr($value['id']);
                        ?>
-height" type="text" size="3" value="<?php 
                        echo $height;
                        ?>
" />px

	                    	<label><input name="<?php 
                        echo esc_attr($value['id']);
                        ?>
[crop]" id="<?php 
                        echo esc_attr($value['id']);
                        ?>
-crop" type="checkbox" <?php 
                        echo $crop;
                        ?>
 /> <?php 
                        _e('Hard Crop?', 'propertyhive');
                        ?>
</label>

	                    	</td>
	                </tr><?php 
                        break;
                        // Single page selects
                    // Single page selects
                    case 'single_select_page':
                        $args = array('name' => $value['id'], 'id' => $value['id'], 'sort_column' => 'menu_order', 'sort_order' => 'ASC', 'show_option_none' => ' ', 'class' => $value['class'], 'echo' => false, 'selected' => absint(self::get_option($value['id'])));
                        if (isset($value['args'])) {
                            $args = wp_parse_args($value['args'], $args);
                        }
                        ?>
<tr valign="top" class="single_select_page">
	                    <th scope="row" class="titledesc"><?php 
                        echo esc_html($value['title']);
                        ?>
 <?php 
                        echo $tip;
                        ?>
</th>
	                    <td class="forminp">
				        	<?php 
                        echo str_replace(' id=', " data-placeholder='" . __('Select a page&hellip;', 'propertyhive') . "' style='" . $value['css'] . "' class='" . $value['class'] . "' id=", wp_dropdown_pages($args));
                        ?>
 <?php 
                        echo $description;
                        ?>
				        </td>
	               	</tr><?php 
                        break;
                        // Single country selects
                    // Single country selects
                    case 'single_select_country':
                        $country_setting = (string) self::get_option($value['id']);
                        $countries = PH()->countries->countries;
                        if (strstr($country_setting, ':')) {
                            $country_setting = explode(':', $country_setting);
                            $country = current($country_setting);
                        } else {
                            $country = $country_setting;
                        }
                        ?>
<tr valign="top">
						<th scope="row" class="titledesc">
							<label for="<?php 
                        echo esc_attr($value['id']);
                        ?>
"><?php 
                        echo esc_html($value['title']);
                        ?>
</label>
							<?php 
                        echo $tip;
                        ?>
						</th>
	                    <td class="forminp">
		                    <select name="<?php 
                        echo esc_attr($value['id']);
                        ?>
" style="<?php 
                        echo esc_attr($value['css']);
                        ?>
">
					        	<?php 
                        PH()->countries->country_dropdown_options($country);
                        ?>
					        </select>
					        <?php 
                        echo $description;
                        ?>
	               		</td>
	               	</tr><?php 
                        break;
                        // Country multiselects
                    // Country multiselects
                    case 'multi_select_countries':
                        $selections = (array) self::get_option($value['id']);
                        if (!empty($value['options'])) {
                            $countries = $value['options'];
                        } else {
                            $countries = PH()->countries->countries;
                        }
                        asort($countries);
                        ?>
<tr valign="top">
						<th scope="row" class="titledesc">
							<label for="<?php 
                        echo esc_attr($value['id']);
                        ?>
"><?php 
                        echo esc_html($value['title']);
                        ?>
</label>
							<?php 
                        echo $tip;
                        ?>
						</th>
	                    <td class="forminp">
		                    <select multiple="multiple" name="<?php 
                        echo esc_attr($value['id']);
                        ?>
[]" style="<?php 
                        echo esc_attr($value['css']);
                        ?>
">
					        	<?php 
                        if ($countries) {
                            foreach ($countries as $key => $val) {
                                echo '<option value="' . esc_attr($key) . '" ' . selected(in_array($key, $selections), true, false) . '>' . $val['name'] . '</option>';
                            }
                        }
                        ?>
					        </select> <?php 
                        if ($description) {
                            echo $description;
                        }
                        ?>
	               		</td>
	               	</tr><?php 
                        break;
                        // Default: run an action
                    // Default: run an action
                    default:
                        do_action('propertyhive_admin_field_' . $value['type'], $value);
                        break;
                }
            }
        }
/**
 * Output a radio input box.
 *
 * @access public
 * @param array $field
 * @return void
 */
function propertyhive_wp_radio($field)
{
    global $thepostid, $post, $propertyhive;
    $thepostid = empty($thepostid) ? $post->ID : $thepostid;
    $field['class'] = isset($field['class']) ? $field['class'] : 'select short';
    $field['wrapper_class'] = isset($field['wrapper_class']) ? $field['wrapper_class'] : '';
    $field['value'] = isset($field['value']) ? $field['value'] : get_post_meta($thepostid, $field['id'], true);
    $field['name'] = isset($field['name']) ? $field['name'] : $field['id'];
    echo '<fieldset class="form-field ' . esc_attr($field['id']) . '_field ' . esc_attr($field['wrapper_class']) . '"><legend>' . wp_kses_post($field['label']) . '</legend><ul class="ph-radios">';
    foreach ($field['options'] as $key => $value) {
        echo '<li><label><input
        		name="' . esc_attr($field['name']) . '"
        		value="' . esc_attr($key) . '"
        		type="radio"
        		class="' . esc_attr($field['class']) . '"
        		' . checked(esc_attr($field['value']), esc_attr($key), false) . '
        		/> ' . esc_html($value) . '</label>
    	</li>';
    }
    echo '</ul>';
    if (!empty($field['description'])) {
        if (isset($field['desc_tip']) && false !== $field['desc_tip']) {
            echo '<img class="help_tip" data-tip="' . esc_attr($field['description']) . '" src="' . esc_url(PH()->plugin_url()) . '/assets/images/help.png" height="16" width="16" />';
        } else {
            echo '<span class="description">' . wp_kses_post($field['description']) . '</span>';
        }
    }
    echo '</fieldset>';
}
    /**
     * Recent Properties shortcode
     *
     * @access public
     * @param array $atts
     * @return string
     */
    public static function recent_properties($atts)
    {
        global $propertyhive_loop;
        $atts = shortcode_atts(array('per_page' => '12', 'columns' => '4', 'department' => '', 'orderby' => 'date', 'order' => 'desc'), $atts);
        $meta_query = PH()->query->get_meta_query();
        if (isset($atts['department']) && $atts['department'] != '') {
            $meta_query[] = array('key' => '_department', 'value' => $atts['department'], 'compare' => '=');
        }
        $args = array('post_type' => 'property', 'post_status' => 'publish', 'ignore_sticky_posts' => 1, 'posts_per_page' => $atts['per_page'], 'orderby' => $atts['orderby'], 'order' => $atts['order'], 'meta_query' => $meta_query);
        ob_start();
        $properties = new WP_Query(apply_filters('propertyhive_shortcode_properties_query', $args, $atts));
        $propertyhive_loop['columns'] = $atts['columns'];
        if ($properties->have_posts()) {
            ?>

			<?php 
            propertyhive_property_loop_start();
            ?>

				<?php 
            while ($properties->have_posts()) {
                $properties->the_post();
                ?>

					<?php 
                ph_get_template_part('content', 'property-recent');
                ?>

				<?php 
            }
            // end of the loop.
            ?>

			<?php 
            propertyhive_property_loop_end();
            ?>

		<?php 
        }
        wp_reset_postdata();
        return '<div class="propertyhive columns-' . $atts['columns'] . '">' . ob_get_clean() . '</div>';
    }
 /**
  * Save settings.
  */
 public function save()
 {
     PH_Admin_Settings::save_fields($this->get_settings());
     PH()->license->ph_check_licenses(true);
 }
 /**
  * Handle updates
  */
 public function update()
 {
     // Do updates
     $current_db_version = get_option('propertyhive_db_version');
     /*if ( version_compare( $current_db_version, '1.4', '<' ) ) {
     			include( 'updates/propertyhive-update-1.4.php' );
     			update_option( 'propertyhive_db_version', '1.4' );
     		}
     
     		if ( version_compare( $current_db_version, '2.1.0', '<' ) || PH_VERSION == '2.1-bleeding' ) {
     			include( 'updates/propertyhive-update-2.1.php' );
     			update_option( 'propertyhive_db_version', '2.1.0' );
     		}*/
     update_option('propertyhive_db_version', PH()->version);
 }
/**
 * Locate a template and return the path for inclusion.
 *
 * This is the load order:
 *
 *      yourtheme       /   $template_path  /   $template_name
 *      yourtheme       /   $template_name
 *      $default_path   /   $template_name
 *
 * @access public
 * @param string $template_name
 * @param string $template_path (default: '')
 * @param string $default_path (default: '')
 * @return string
 */
function ph_locate_template($template_name, $template_path = '', $default_path = '')
{
    if (!$template_path) {
        $template_path = PH()->template_path();
    }
    if (!$default_path) {
        $default_path = PH()->plugin_path() . '/templates/';
    }
    // Look within passed path within the theme - this is priority
    $template = locate_template(array(trailingslashit($template_path) . $template_name, $template_name));
    // Get default template
    if (!$template) {
        $template = $default_path . $template_name;
    }
    // Return what we found
    return apply_filters('propertyhive_locate_template', $template, $template_name, $template_path);
}
 /**
  * Enqueue scripts
  */
 public function admin_scripts()
 {
     global $wp_query, $post;
     $screen = get_current_screen();
     $ph_screen_id = sanitize_title(__('PropertyHive', 'propertyhive'));
     $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
     // Register scripts
     wp_register_script('propertyhive_dashboard', PH()->plugin_url() . '/assets/js/admin/dashboard' . '.js', array('jquery'), PH_VERSION);
     wp_register_script('propertyhive_admin', PH()->plugin_url() . '/assets/js/admin/admin' . '.js', array('jquery', 'jquery-tiptip'), PH_VERSION);
     wp_register_script('jquery-tiptip', PH()->plugin_url() . '/assets/js/jquery-tiptip/jquery.tipTip' . '.js', array('jquery'), PH_VERSION, true);
     wp_register_script('propertyhive_admin_meta_boxes', PH()->plugin_url() . '/assets/js/admin/meta-boxes' . '.js', array('jquery', 'jquery-ui-datepicker', 'jquery-ui-sortable'), PH_VERSION);
     wp_register_script('propertyhive_admin_settings', PH()->plugin_url() . '/assets/js/admin/settings' . '.js', array('jquery', 'wp-color-picker'), PH_VERSION);
     wp_register_script('ajax-chosen', PH()->plugin_url() . '/assets/js/chosen/ajax-chosen.jquery' . '.js', array('jquery', 'chosen'), PH_VERSION);
     wp_register_script('chosen', PH()->plugin_url() . '/assets/js/chosen/chosen.jquery' . '.js', array('jquery'), PH_VERSION);
     // PropertyHive admin pages
     if (in_array($screen->id, array('dashboard'))) {
         wp_enqueue_script('propertyhive_dashboard');
         $params = array('ajax_url' => admin_url('admin-ajax.php'));
         wp_localize_script('propertyhive_dashboard', 'propertyhive_dashboard', $params);
     }
     if (in_array($screen->id, ph_get_screen_ids())) {
         wp_enqueue_script('propertyhive_admin');
         wp_enqueue_script('ajax-chosen');
         wp_enqueue_script('chosen');
         wp_enqueue_script('jquery-ui-sortable');
         $api_key = get_option('propertyhive_google_maps_api_key');
         wp_register_script('googlemaps', '//maps.googleapis.com/maps/api/js?' . ($api_key != '' && $api_key !== FALSE ? 'key=' . $api_key : ''), false, '3');
         wp_enqueue_script('googlemaps');
     }
     if (in_array($screen->id, array('property', 'contact', 'enquiry'))) {
         wp_enqueue_media();
         wp_enqueue_script('propertyhive_admin_meta_boxes');
         wp_enqueue_script('jquery-ui-datepicker');
         wp_enqueue_script('jquery-ui-autocomplete');
         wp_enqueue_script('ajax-chosen');
         wp_enqueue_script('chosen');
         $params = array('plugin_url' => PH()->plugin_url(), 'ajax_url' => admin_url('admin-ajax.php'), 'post_id' => isset($post->ID) ? $post->ID : '', 'add_note_nonce' => wp_create_nonce("add-note"), 'delete_note_nonce' => wp_create_nonce("delete-note"));
         wp_localize_script('propertyhive_admin_meta_boxes', 'propertyhive_admin_meta_boxes', $params);
         if (is_rtl()) {
             wp_enqueue_script('chosen-rtl', PH()->plugin_url() . '/assets/js/chosen/chosen-rtl' . '.js', array('jquery'), PH_VERSION, true);
         }
     }
     if (in_array($screen->id, array('property-hive_page_ph-settings'))) {
         wp_enqueue_script('propertyhive_admin_settings');
         $params = array('confirm_not_selected_warning' => __('Please check the box to confirm that you are happy to remove this term', 'propertyhive'), 'no_departments_selected_warning' => __('Please select at least one active department', 'propertyhive'), 'primary_department_not_active_warning' => __('The chosen primary department has not been selected as active', 'propertyhive'), 'no_countries_selected' => __('Please select which countries you operate in', 'propertyhive'), 'default_country_not_in_selected' => __('The default country hasn\'t been selected as a country you operate in', 'propertyhive'), 'admin_url' => admin_url(), 'taxonomy_section' => isset($_GET['section']) ? $_GET['section'] : '');
         wp_localize_script('propertyhive_admin_settings', 'propertyhive_admin_settings', $params);
     }
 }
/**
 * Get the placeholder image URL for properties
 *
 * @access public
 * @return string
 */
function ph_placeholder_img_src()
{
    return apply_filters('propertyhive_placeholder_img_src', PH()->plugin_url() . '/assets/images/placeholder.png');
}
        /**
         * Output a colour picker input box.
         *
         * @access public
         * @param mixed $name
         * @param mixed $id
         * @param mixed $value
         * @param string $desc (default: '')
         * @return void
         */
        function color_picker($name, $id, $value, $desc = '')
        {
            echo '<div class="color_box"><strong><img class="help_tip" data-tip="' . esc_attr($desc) . '" src="' . PH()->plugin_url() . '/assets/images/help.png" height="16" width="16" /> ' . esc_html($name) . '</strong>
			<input name="' . esc_attr($id) . '" id="' . esc_attr($id) . '" type="text" value="' . esc_attr($value) . '" class="colorpick" /> <div id="colorPickerDiv_' . esc_attr($id) . '" class="colorpickdiv"></div>
		</div>';
        }
 /**
  * Output the metabox
  */
 public static function output($post)
 {
     $thumbnail_width = get_option('thumbnail_size_w', 150);
     $thumbnail_height = get_option('thumbnail_size_h', 150);
     echo '<div class="propertyhive_meta_box">';
     echo '<div class="options_group">';
     echo '<div class="media_grid" id="property_brochures_grid"><ul>';
     $brochures = get_post_meta($post->ID, '_brochures', TRUE);
     $input_value = '';
     if (is_array($brochures) && !empty($brochures)) {
         $input_value = implode(",", $brochures);
         foreach ($brochures as $brochures_attachment_id) {
             $type = get_post_mime_type($brochures_attachment_id);
             $icon = 'text.png';
             switch ($type) {
                 case "application/pdf":
                 case "application/x-pdf":
                     $icon = 'pdf.png';
                     break;
                 case "application/msword":
                 case "application/vnd.openxmlformats-officedocument.wordprocessingml.document":
                     $icon = 'word.png';
                     break;
                 case "text/csv":
                 case "application/vnd.ms-excel":
                 case "text/csv":
                     $icon = 'excel.png';
                     break;
             }
             echo '<li id="brochure_' . $brochures_attachment_id . '">';
             echo '<div class="hover"><div class="attachment-delete"><a href=""></a></div><div class="attachment-edit"><a href=""></a></div></div>';
             echo '<a href="' . wp_get_attachment_url($brochures_attachment_id) . '" target="_blank"><img src="' . PH()->plugin_url() . '/assets/images/filetypes/' . $icon . '" alt="" width="' . $thumbnail_width . '" height="' . $thumbnail_height . '"></a>';
             echo '</li>';
         }
     } else {
         //echo '<p>' . __( 'No brochures have been uploaded yet', 'propertyhive' ) . '</p>';
     }
     echo '</ul></div>';
     echo '<a href="" class="button button-primary ph_upload_brochure_button">' . __('Add Brochures', 'propertyhive') . '</a>';
     do_action('propertyhive_property_brochures_fields');
     echo '<input type="hidden" name="brochure_attachment_ids" id="brochure_attachment_ids" value="' . $input_value . '">';
     echo '</div>';
     echo '</div>';
     echo '<script>
           // Uploading files
           var file_frame3;
           
           //var sortable_options = 
          
           jQuery(document).ready(function()
           {
               jQuery( \'#property_brochures_grid ul\' ).sortable({
                   update : function (event, ui) {
                         var new_order = \'\';
                         jQuery(\'#property_brochures_grid ul\').find(\'li\').each( function () {
                             if (new_order != \'\')
                             {
                                 new_order += \',\';
                             }
                             new_order = new_order + jQuery(this).attr(\'id\').replace(\'brochure_\', \'\');
                         });
                         jQuery(\'#brochure_attachment_ids\').val(new_order);
                   }
               });
               jQuery( \'#property_brochures_grid ul\' ).disableSelection();
               
               jQuery(\'body\').on(\'click\', \'#property_brochures_grid .attachment-delete a\', function()
               {
                   var container = jQuery(this).parent().parent().parent();
                   var brochure_id = container.attr(\'id\');
                   brochure_id = brochure_id.replace(\'brochure_\', \'\');
                   
                   var attachment_ids = jQuery(\'#brochure_attachment_ids\').val();
                   // Check it\'s not already in the list
                   attachment_ids = attachment_ids.split(\',\');
                   
                   var new_attachment_ids = \'\';
                   for (var i in attachment_ids)
                   {
                       if (attachment_ids[i] != brochure_id)
                       {
                           if (new_attachment_ids != \'\')
                           {
                               new_attachment_ids += \',\';
                           }
                           new_attachment_ids += attachment_ids[i];
                       }
                   }
                   jQuery(\'#brochure_attachment_ids\').val(new_attachment_ids);
                   
                   container.fadeOut(\'fast\', function()
                   {
                       container.remove();
                   });
                   
                   return false;
               });
               
               jQuery(\'body\').on(\'click\', \'#property_brochures_grid .attachment-edit a\', function()
               {
                   
               });
               
               jQuery(\'.ph_upload_brochure_button\').live(\'click\', function( event ){
              
                 event.preventDefault();
              
                 // If the media frame already exists, reopen it.
                 if ( file_frame3 ) {
                   file_frame3.open();
                   return;
                 }
              
                 // Create the media frame.
                 file_frame3 = wp.media.frames.file_frame3 = wp.media({
                   title: jQuery( this ).data( \'uploader_title\' ),
                   button: {
                     text: jQuery( this ).data( \'uploader_button_text\' ),
                   },
                   multiple: true  // Set to true to allow multiple files to be selected
                 });
              
                 // When an image is selected, run a callback.
                 file_frame3.on( \'select\', function() {
                     var selection = file_frame3.state().get(\'selection\');
  
                     selection.map( function( attachment ) {
                  
                         attachment = attachment.toJSON();
                  
                         // Do something with attachment.id and/or attachment.url here
                         console.log(attachment.url);
                         
                         // Add selected images to grid
                         add_brochure_attachment_to_grid(attachment);
                     });
                 });
              
                 // Finally, open the modal
                 file_frame3.open();
               });
           });
           
           function add_brochure_attachment_to_grid(attachment)
           {
               var attachment_ids = jQuery(\'#brochure_attachment_ids\').val();
               // Check it\'s not already in the list
               attachment_ids = attachment_ids.split(\',\');
               
               var ok_to_add = true;
               for (var i in attachment_ids)
               {
                   if (attachment.id == attachment_ids[i])
                   {
                       ok_to_add = false;
                   }
               }
               
               if (ok_to_add)
               {
                   // Append to hidden field
                   var new_attachment_ids = attachment_ids;
                   if (new_attachment_ids != \'\')
                   {
                       new_attachment_ids += \',\';
                   }
                   new_attachment_ids += attachment.id;
                   jQuery(\'#brochure_attachment_ids\').val(new_attachment_ids);
                   
                   // Add brochure to media grid
                   var mediaHTML = \'\';
                   
                   // get extension and icon
                   var icon = \'text.png\';
                   var attachment_url = attachment.url;
                   attachment_url = attachment_url.split(\'.\');
                   var extension = attachment_url[attachment_url.length-1].toLowerCase();
                   switch (extension)
                   {
                       case \'pdf\':
                       {
                           icon = \'pdf.png\';
                           break;
                       }
                       case \'doc\':
                       case \'docx\':
                       {
                           icon = \'word.png\';
                           break;
                       }
                       case \'csv\':
                       case \'xls\':
                       case \'xlsx\':
                       {
                           icon = \'excel.png\';
                           break;
                       }
                   }
                   
                   mediaHTML += \'<li id="brochure_\' + attachment.id + \'">\';
                   mediaHTML += \'<div class="hover"><div class="attachment-delete"><a href=""></a></div><div class="attachment-edit"><a href=""></a></div></div>\';
                   mediaHTML += \'<img src="' . PH()->plugin_url() . '/assets/images/filetypes/\' + icon + \'" alt="" width="' . $thumbnail_width . '" height="' . $thumbnail_height . '"></li>\';
                   
                   jQuery(\'#property_brochures_grid ul\').append(mediaHTML);
               }
           }
     </script>';
 }
예제 #15
0
         */
        public function api_request_url($request, $ssl = null)
        {
            if (is_null($ssl)) {
                $scheme = parse_url(get_option('home'), PHP_URL_SCHEME);
            } elseif ($ssl) {
                $scheme = 'https';
            } else {
                $scheme = 'http';
            }
            if (get_option('permalink_structure')) {
                return esc_url_raw(trailingslashit(home_url('/ph-api/' . $request, $scheme)));
            } else {
                return esc_url_raw(add_query_arg('ph-api', $request, trailingslashit(home_url('', $scheme))));
            }
        }
    }
}
/**
 * Returns the main instance of PH to prevent the need to use globals.
 *
 * @since  1.0.0
 * @return PropertyHive
 */
function PH()
{
    return PropertyHive::instance();
}
// Global for backwards compatibility.
$GLOBALS['propertyhive'] = PH();