This repository has been archived by the owner on May 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwpcasa-listings-map.php
257 lines (197 loc) · 7.04 KB
/
wpcasa-listings-map.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
<?php
/*
Plugin Name: WPCasa Listings Map
Plugin URI: https://wpcasa.com/downloads/wpcasa-listings-map
Description: Show listings as markers on a Google Map. This can be a central map with all listings or limited to a specific query.
Version: 1.2.2
Author: WPSight
Author URI: http://wpsight.com
Requires at least: 4.0
Tested up to: 5.3.2
Text Domain: wpcasa-listings-map
Domain Path: /languages
*/
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) )
exit;
/**
* WPSight_Listings_Map class
*/
class WPSight_Listings_Map {
/**
* Constructor
*/
public function __construct() {
// Define constants
if ( ! defined( 'WPSIGHT_NAME' ) )
define( 'WPSIGHT_NAME', 'WPCasa' );
if ( ! defined( 'WPSIGHT_DOMAIN' ) )
define( 'WPSIGHT_DOMAIN', 'wpcasa' );
define( 'WPSIGHT_LISTINGS_MAP_NAME', 'WPCasa Listings Map' );
define( 'WPSIGHT_LISTINGS_MAP_DOMAIN', 'wpcasa-listings-map' );
define( 'WPSIGHT_LISTINGS_MAP_VERSION', '1.2.2' );
define( 'WPSIGHT_LISTINGS_MAP_PLUGIN_DIR', untrailingslashit( plugin_dir_path( __FILE__ ) ) );
define( 'WPSIGHT_LISTINGS_MAP_PLUGIN_URL', untrailingslashit( plugins_url( basename( plugin_dir_path( __FILE__ ) ), basename( __FILE__ ) ) ) );
// Cookie constants
define( 'WPSIGHT_LISTINGS_MAP_COOKIE', WPSIGHT_DOMAIN . '_listings_map' );
// Include functions
include 'wpcasa-listings-map-functions.php';
// Include styles
include 'includes/class-wpsight-listings-map-styles.php';
// Include shortcode
include 'includes/class-wpsight-listings-map-shortcode.php';
// Include admin part
if ( is_admin() ) {
include( WPSIGHT_LISTINGS_MAP_PLUGIN_DIR . '/includes/admin/class-wpsight-listings-map-admin.php' );
$this->admin = new WPSight_Listings_Map_Admin();
}
// Actions
add_action( 'init', array( $this, 'load_plugin_textdomain' ) );
add_action( 'wp_enqueue_scripts', array( $this, 'frontend_scripts' ) );
// Display Show/hide map link in listings panel
add_action( 'wpsight_listings_panel_actions', array( $this, 'panel_map_link' ) );
// Add map after listings panel
add_filter( 'wpsight_get_panel', array( $this, 'panel_map' ), 10, 2 );
}
/**
* init()
*
* Initialize the plugin when WPCasa is loaded
*
* @param object $wpsight
* @return object $wpsight->listings_map
*
* @since 1.0.0
*/
public static function init( $wpsight ) {
if ( ! isset( $wpsight->listings_map ) )
$wpsight->listings_map = new self();
do_action_ref_array( 'wpsight_init_listings_map', array( &$wpsight ) );
return $wpsight->listings_map;
}
/**
* load_plugin_textdomain()
*
* Set up localization for this plugin
* loading the text domain.
*
* @uses load_plugin_textdomain()
*
* @since 1.0.0
*/
public function load_plugin_textdomain() {
load_plugin_textdomain( 'wpcasa-listings-map', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
}
/**
* frontend_scripts()
*
* Register and enqueue JS scripts and CSS styles.
* Also localize some JS to use PHP constants.
*
* @uses wp_enqueue_script()
* @uses wp_enqueue_style()
*
* @since 1.0.0
*/
public function frontend_scripts() {
// Script debugging?
$suffix = SCRIPT_DEBUG ? '' : '.min';
wp_enqueue_style( 'wpsight-listings-map', WPSIGHT_LISTINGS_MAP_PLUGIN_URL . '/assets/css/wpsight-listings-map' . $suffix . '.css', array(), WPSIGHT_LISTINGS_MAP_VERSION );
wp_register_script( 'wpsight-map-googleapi', '//maps.googleapis.com/maps/api/js', null, WPSIGHT_LISTINGS_MAP_VERSION );
wp_register_script( 'wpsight-map-infobox', WPSIGHT_LISTINGS_MAP_PLUGIN_URL . '/assets/js/infobox' . $suffix . '.js', array( 'wpsight-map-googleapi' ), WPSIGHT_LISTINGS_MAP_VERSION );
wp_register_script( 'wpsight-map-markerclusterer', WPSIGHT_LISTINGS_MAP_PLUGIN_URL . '/assets/js/markerclusterer' . $suffix . '.js', array( 'wpsight-map-googleapi' ), WPSIGHT_LISTINGS_MAP_VERSION );
wp_register_script( 'wpsight-listings-map', WPSIGHT_LISTINGS_MAP_PLUGIN_URL . '/assets/js/wpcasa-listings-map' . $suffix . '.js', array( 'wpsight-map-googleapi', 'wpsight-map-markerclusterer', 'wpsight-map-infobox' ), WPSIGHT_LISTINGS_MAP_VERSION );
}
/**
* panel_map_link()
*
* Add Show Map link to listings panel.
*
* @uses wpsight_get_option()
*
* @since 1.1.0
*/
public function panel_map_link() {
if( ! wpsight_get_option( 'listings_map_panel' ) )
return;
$link = sprintf( '<div class="listings-panel-action"><a href="#" class="toggle-map">%1$s</a></div>', apply_filters( 'wpsight_listings_panel_map_link_label', wpsight_get_option( 'listings_map_panel_link', __( 'Toggle Map', 'wpcasa-listings-map' ) ) ) );
echo apply_filters( 'wpsight_listings_panel_map_link', $link );
}
/**
* panel_map()
*
* Add map output after listings panel.
*
* @param string $panel Listings panel output
* @param object $query Listings query
* @uses wpsight_get_option()
* @uses wpsight_listings_map()
* @return string
*
* @since 1.1.0
*/
public function panel_map( $panel, $query ) {
if( isset( $query->post_count ) && $query->post_count >= 1 ) {
$args = array(
'map_id' => uniqid( 'listings-panel-' ),
'toggle' => false,
'toggle_button' => 'listings-panel',
);
$panel_map = wpsight_get_listings_map( $args, $query );
$panel = $panel . $panel_map;
}
return $panel;
}
/**
* activation()
*
* Callback for register_activation_hook
* to create a default favorites page with
* the [wpsight_favorites] shortcode and
* to create some default options to be
* used by this plugin.
*
* @uses wpsight_get_option()
* @uses wp_insert_post()
* @uses wpsight_add_option()
*
* @since 1.0.0
*/
public static function activation() {
// Create map page
$page_data = array(
'post_title' => _x( 'Listings Map', 'listings map page title', 'wpsight-listings-map' ),
'post_content' => '[wpsight_listings_map]',
'post_type' => 'page',
'post_status' => 'publish',
'comment_status' => 'closed',
'ping_status' => 'closed'
);
$page_id = ! wpsight_get_option( 'listings_map_page' ) ? wp_insert_post( $page_data ) : wpsight_get_option( 'listings_map_page' );
// Add some default options
$options = array(
'listings_map_page' => $page_id,
'listings_map_panel' => '1',
'listings_map_panel_link' => __( 'Toggle Map', 'wpcasa-listings-map' ),
'listings_map_nr' => 50,
'listings_map_width' => '100%',
'listings_map_height' => '800px',
'listings_map_type' => 'ROADMAP',
'listings_map_control_type' => '1',
'listings_map_control_nav' => '1',
'listings_map_scrollwheel' => '0',
'listings_map_streetview' => '1',
'listings_map_infobox_event' => 'mouseover',
'listings_map_infobox_close' => '1'
);
foreach ( $options as $option => $value ) {
if ( wpsight_get_option( $option ) )
continue;
wpsight_add_option( $option, $value );
}
}
}
// Activation Hook
register_activation_hook( __FILE__, array( 'WPSight_Listings_Map', 'activation' ) );
// Initialize plugin on wpsight_init
add_action( 'wpsight_init', array( 'WPSight_Listings_Map', 'init' ) );