PluginProbe
Property Hive / 1.4.6
Property Hive v1.4.6
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 / ph-property-functions.php

ph-property-functions.php in Property Hive 1.4.6, at includes/ph-property-functions.php

285 lines 8.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * PropertyHive Property Functions
4 *
5 * Functions for property specific things.
6 *
7 * @author BISOTALL
8 * @category Core
9 * @package PropertyHive/Functions
10 * @version 1.0.0
11 */
12
13 /**
14 * Main function for returning properties, uses the PH_Property_Factory class.
15 *
16 * @param mixed $the_property Post object or post ID of the property.
17 * @param array $args (default: array()) Contains all arguments to be used to get this property.
18 * @return PH_Property
19 */
20 function get_property( $the_property = false, $args = array() ) {
21 return new PH_Property( $the_property );
22 }
23
24 /**
25 * Function that returns an array containing the IDs of the featured properties.
26 *
27 * @access public
28 * @return array
29 */
30 function ph_get_featured_property_ids() {
31
32 // Load from cache
33 $featured_property_ids = get_transient( 'ph_featured_properties' );
34
35 // Valid cache found
36 if ( false !== $featured_property_ids )
37 return $featured_property_ids;
38
39 $featured = get_posts( array(
40 'post_type' => 'property',
41 'posts_per_page' => -1,
42 'post_status' => 'publish',
43 'meta_query' => array(
44 array(
45 'key' => 'on_market',
46 'value' => 'yes'
47 ),
48 array(
49 'key' => 'featured',
50 'value' => 'yes'
51 )
52 ),
53 'fields' => 'id=>parent'
54 ) );
55
56 $featured_property_ids = array_keys( $property_ids );
57
58 set_transient( 'ph_featured_properties', $featured_property_ids, YEAR_IN_SECONDS );
59
60 return $featured_property_ids;
61 }
62
63 /**
64 * Get the placeholder image URL for properties
65 *
66 * @access public
67 * @return string
68 */
69 function ph_placeholder_img_src() {
70 return apply_filters( 'propertyhive_placeholder_img_src', PH()->plugin_url() . '/assets/images/placeholder.png' );
71 }
72
73 /**
74 * Get the placeholder image
75 *
76 * @access public
77 * @return string
78 */
79 function ph_placeholder_img( $size = 'thumbnail' ) {
80 $dimensions = ph_get_image_size( $size );
81
82 return apply_filters('propertyhive_placeholder_img', '<img src="' . ph_placeholder_img_src() . '" alt="Placeholder" width="' . esc_attr( $dimensions['width'] ) . '" class="property-placeholder wp-post-image" height="' . esc_attr( $dimensions['height'] ) . '" />' );
83 }
84
85 /**
86 * Track property views
87 */
88 function ph_track_property_view() {
89 if ( ! is_singular( 'property' ) )
90 return;
91
92 global $post;
93
94 // Track in cookie
95 if ( apply_filters( 'propertyhive_store_in_recently_viewed_cookie', true ) )
96 {
97 if ( empty( $_COOKIE['propertyhive_recently_viewed'] ) )
98 $viewed_properties = array();
99 else
100 $viewed_properties = (array) explode( '|', $_COOKIE['propertyhive_recently_viewed'] );
101
102 if ( ! in_array( $post->ID, $viewed_properties ) )
103 $viewed_properties[] = $post->ID;
104
105 if ( sizeof( $viewed_properties ) > 15 )
106 array_shift( $viewed_properties );
107
108 // Store for session only
109 ph_setcookie( 'propertyhive_recently_viewed', implode( '|', $viewed_properties ) );
110 }
111
112 // Track in database
113 if ( !is_user_logged_in() || ( is_user_logged_in() && !current_user_can('manage_propertyhive') ) )
114 {
115 // User isn't logged in
116
117 $view_counts = get_post_meta( $post->ID, '_view_statistics', TRUE );
118
119 if ( $view_counts == '' || !is_array($view_counts) )
120 {
121 $view_counts = array();
122 }
123
124 if ( !isset($view_counts[date("Y-m-d")]) )
125 {
126 $view_counts[date("Y-m-d")] = 0;
127 }
128
129 ++$view_counts[date("Y-m-d")];
130
131 update_post_meta( $post->ID, '_view_statistics', $view_counts );
132 }
133 }
134
135 add_action( 'template_redirect', 'ph_track_property_view', 20 );
136
137 function get_property_map( $args = array() )
138 {
139 global $property;
140
141 if ( $property->latitude != '' && $property->latitude != '0' && $property->longitude != '' && $property->longitude != '0' )
142 {
143 $api_key = get_option('propertyhive_google_maps_api_key');
144 wp_register_script('googlemaps', '//maps.googleapis.com/maps/api/js?' . ( ( $api_key != '' && $api_key !== FALSE ) ? 'key=' . $api_key : '' ), false, '3');
145 wp_enqueue_script('googlemaps');
146
147 echo '<div id="property_map_canvas" style="height:' . str_replace( "px", "", ( ( isset($args['height']) && !empty($args['height']) ) ? $args['height'] : '400' ) ) . 'px"></div>';
148 ?>
149 <script>
150
151 // We declare vars globally so developers can access them
152 var property_map; // Global declaration of the map
153 var property_marker; // Global declaration of the marker
154
155 function initialize_property_map() {
156
157 var myLatlng = new google.maps.LatLng(<?php echo $property->latitude; ?>, <?php echo $property->longitude; ?>);
158 var map_options = {
159 zoom: <?php echo ( ( isset($args['zoom']) && !empty($args['zoom']) ) ? $args['zoom'] : '14' ); ?>,
160 center: myLatlng,
161 mapTypeId: google.maps.MapTypeId.ROADMAP,
162 scrollwheel: <?php echo ( ( isset($args['scrollwheel']) && ($args['scrollwheel'] === 'false' || $args['scrollwheel'] === FALSE) ) ? 'false' : 'true' ); ?>
163 }
164 <?php
165 if ( class_exists( 'PH_Map_Search' ) )
166 {
167 $map_add_on_settings = get_option( 'propertyhive_map_search', array() );
168
169 if ( isset($map_add_on_settings['style_js']) && trim($map_add_on_settings['style_js']) != '' )
170 {
171 echo 'map_options.styles = ' . trim($map_add_on_settings['style_js']) . ';';
172 }
173 }
174
175 do_action( 'propertyhive_property_map_options' );
176 ?>
177 property_map = new google.maps.Map(document.getElementById("property_map_canvas"), map_options);
178
179 var myLatlng = new google.maps.LatLng(<?php echo $property->latitude; ?>, <?php echo $property->longitude; ?>);
180
181 var marker_options = {
182 map: property_map,
183 position: myLatlng
184 };
185
186 <?php do_action( 'propertyhive_property_map_marker_options' ); ?>
187
188 property_marker = new google.maps.Marker(marker_options);
189 }
190
191 if(window.addEventListener) {
192 window.addEventListener('load', initialize_property_map);
193 }else{
194 window.attachEvent('onload', initialize_property_map);
195 }
196
197 </script>
198 <?php
199 }
200 }
201
202 function get_property_street_view( $args = array() )
203 {
204 global $property;
205
206 if ( $property->latitude != '' && $property->latitude != '0' && $property->longitude != '' && $property->longitude != '0' )
207 {
208 $api_key = get_option('propertyhive_google_maps_api_key');
209 wp_register_script('googlemaps', '//maps.googleapis.com/maps/api/js?' . ( ( $api_key != '' && $api_key !== FALSE ) ? 'key=' . $api_key : '' ), false, '3');
210 wp_enqueue_script('googlemaps');
211
212 echo '<div id="property_street_view_canvas" style="height:' . str_replace( "px", "", ( ( isset($args['height']) && !empty($args['height']) ) ? $args['height'] : '400' ) ) . 'px"></div>';
213 ?>
214 <script>
215
216 // We declare vars globally so developers can access them
217 var property_street_view; // Global declaration of the map
218
219 function initialize_property_street_view() {
220
221 var myLatlng = new google.maps.LatLng(<?php echo $property->latitude; ?>, <?php echo $property->longitude; ?>);
222 var map_options = {
223 center: myLatlng
224 }
225
226 <?php do_action( 'propertyhive_property_street_view_map_options' ); ?>
227
228 property_street_view = new google.maps.Map(document.getElementById("property_street_view_canvas"), map_options);
229
230 var streetViewOptions = {
231 position: myLatlng,
232 pov: {
233 heading: 90,
234 pitch: 0,
235 zoom: 0
236 }
237 };
238
239 <?php do_action( 'propertyhive_property_street_view_options' ); ?>
240
241 var streetView = new google.maps.StreetViewPanorama(document.getElementById("property_street_view_canvas"), streetViewOptions);
242 streetView.setVisible(true);
243 }
244
245 if(window.addEventListener) {
246 window.addEventListener('load', initialize_property_street_view);
247 }else{
248 window.attachEvent('onload', initialize_property_street_view);
249 }
250
251 </script>
252 <?php
253 }
254 }
255
256 add_filter( 'get_post_metadata', function ( $value, $post_id, $meta_key, $single )
257 {
258 static $is_recursing = false; // Used to prevent infinite loop
259
260 // Only filter if we're not recursing and if it is a post thumbnail ID
261 if ( ! $is_recursing && $meta_key === '_thumbnail_id' && get_post_type( $post_id ) == 'property' )
262 {
263 $is_recursing = true;
264
265 $value = get_post_thumbnail_id( $post_id );
266
267 $is_recursing = false;
268
269 if ( $value == '' ) // If we haven't already get a thumbnail ID (i.e. in the case where someone has added theme support)
270 {
271 $photos = get_post_meta( $post_id, '_photos', TRUE );
272 if ( is_array($photos) && !empty($photos) )
273 {
274 $photos = array_filter( $photos );
275 $value = $photos[0];
276 }
277 }
278
279 if ( ! $single )
280 {
281 $value = array( $value );
282 }
283 }
284 return $value;
285 }, 10, 4);