| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | if ( ! defined( 'ABSPATH' ) ) exit; |
|---|
| 4 | |
|---|
| 5 | /** |
|---|
| 6 | * Class: WPGMP_Model_Map |
|---|
| 7 | * |
|---|
| 8 | * @author Flipper Code <hello@flippercode.com> |
|---|
| 9 | * @version 3.0.0 |
|---|
| 10 | * @package Maps |
|---|
| 11 | */ |
|---|
| 12 | |
|---|
| 13 | if ( ! class_exists( 'WPGMP_Model_Map' ) ) { |
|---|
| 14 | |
|---|
| 15 | /** |
|---|
| 16 | * Map model for CRUD operation. |
|---|
| 17 | * |
|---|
| 18 | * @package Maps |
|---|
| 19 | * @author Flipper Code <hello@flippercode.com> |
|---|
| 20 | */ |
|---|
| 21 | class WPGMP_Model_Map extends FlipperCode_Model_Base { |
|---|
| 22 | /** |
|---|
| 23 | * Validations on route properies. |
|---|
| 24 | * |
|---|
| 25 | * @var array |
|---|
| 26 | */ |
|---|
| 27 | protected $validations; |
|---|
| 28 | |
|---|
| 29 | /** |
|---|
| 30 | * Generate SQL query. |
|---|
| 31 | * |
|---|
| 32 | * @var string |
|---|
| 33 | */ |
|---|
| 34 | protected $query; |
|---|
| 35 | |
|---|
| 36 | /** |
|---|
| 37 | * Intialize map object. |
|---|
| 38 | */ |
|---|
| 39 | function __construct() { |
|---|
| 40 | $this->validations = array( |
|---|
| 41 | 'map_title' => array( |
|---|
| 42 | 'req' => esc_html__('Please enter map title.','wp-google-map-plugin'), |
|---|
| 43 | 'max=255' => esc_html__('Map title cannot contain more than 255 characters.','wp-google-map-plugin') |
|---|
| 44 | ), |
|---|
| 45 | 'map_height' => array( |
|---|
| 46 | 'req' => esc_html__('Please enter map height.','wp-google-map-plugin'), |
|---|
| 47 | 'num' => esc_html__('Please enter only numeric value for map height in pixels.','wp-google-map-plugin') |
|---|
| 48 | ) |
|---|
| 49 | ); |
|---|
| 50 | $this->table = TBL_MAP; |
|---|
| 51 | $this->unique = 'map_id'; |
|---|
| 52 | $this->load_columns(); |
|---|
| 53 | } |
|---|
| 54 | /** |
|---|
| 55 | * Admin menu for CRUD Operation |
|---|
| 56 | * |
|---|
| 57 | * @return array Admin menu navigation(s). |
|---|
| 58 | */ |
|---|
| 59 | function navigation() { |
|---|
| 60 | $nav = array( |
|---|
| 61 | 'wpgmp_form_map' => esc_html__( 'Add Map', 'wp-google-map-plugin' ), |
|---|
| 62 | 'wpgmp_manage_map' => esc_html__( 'Manage Maps', 'wp-google-map-plugin' ), |
|---|
| 63 | ); |
|---|
| 64 | return apply_filters('wpgmp_map_navigation', $nav); |
|---|
| 65 | } |
|---|
| 66 | /** |
|---|
| 67 | * Install table associated with map entity. |
|---|
| 68 | * |
|---|
| 69 | * @return string SQL query to install create_map table. |
|---|
| 70 | */ |
|---|
| 71 | function install() { |
|---|
| 72 | global $wpdb; |
|---|
| 73 | $charset_collate = $wpdb->get_charset_collate(); |
|---|
| 74 | |
|---|
| 75 | $create_map = 'CREATE TABLE ' . $wpdb->prefix . 'create_map ( |
|---|
| 76 | map_id int(11) NOT NULL AUTO_INCREMENT, |
|---|
| 77 | map_title varchar(255) DEFAULT NULL, |
|---|
| 78 | map_width varchar(255) DEFAULT NULL, |
|---|
| 79 | map_height varchar(255) DEFAULT NULL, |
|---|
| 80 | map_zoom_level varchar(255) DEFAULT NULL, |
|---|
| 81 | map_type varchar(255) DEFAULT NULL, |
|---|
| 82 | map_scrolling_wheel varchar(255) DEFAULT NULL, |
|---|
| 83 | map_visual_refresh varchar(255) DEFAULT NULL, |
|---|
| 84 | map_45imagery varchar(255) DEFAULT NULL, |
|---|
| 85 | map_street_view_setting text DEFAULT NULL, |
|---|
| 86 | map_route_direction_setting text DEFAULT NULL, |
|---|
| 87 | map_all_control text DEFAULT NULL, |
|---|
| 88 | map_info_window_setting text DEFAULT NULL, |
|---|
| 89 | style_google_map text DEFAULT NULL, |
|---|
| 90 | map_locations longtext DEFAULT NULL, |
|---|
| 91 | map_layer_setting text DEFAULT NULL, |
|---|
| 92 | map_polygon_setting longtext DEFAULT NULL, |
|---|
| 93 | map_polyline_setting longtext DEFAULT NULL, |
|---|
| 94 | map_cluster_setting text DEFAULT NULL, |
|---|
| 95 | map_overlay_setting text DEFAULT NULL, |
|---|
| 96 | map_geotags text DEFAULT NULL, |
|---|
| 97 | map_infowindow_setting text DEFAULT NULL, |
|---|
| 98 | PRIMARY KEY (map_id) |
|---|
| 99 | ) '.$charset_collate.';'; |
|---|
| 100 | |
|---|
| 101 | return $create_map; |
|---|
| 102 | } |
|---|
| 103 | |
|---|
| 104 | public function wpgmp_array_map( $element ) { |
|---|
| 105 | return $element['slug']; } |
|---|
| 106 | |
|---|
| 107 | public function clear_empty_array_values( $array ) { |
|---|
| 108 | |
|---|
| 109 | foreach ( $array as $k => &$v ) { |
|---|
| 110 | |
|---|
| 111 | if ( $k == 'extra_fields' ) { |
|---|
| 112 | continue; |
|---|
| 113 | } |
|---|
| 114 | |
|---|
| 115 | if ( is_array( $v ) ) { |
|---|
| 116 | $v = $this->clear_empty_array_values( $v ); |
|---|
| 117 | if ( ! sizeof( $v ) ) { |
|---|
| 118 | unset( $array[ $k ] ); |
|---|
| 119 | } |
|---|
| 120 | } elseif ( ! is_object( $v ) and ! @strlen( $v ) and ! is_bool( $v ) ) { |
|---|
| 121 | unset( $array[ $k ] ); |
|---|
| 122 | } |
|---|
| 123 | } |
|---|
| 124 | return $array; |
|---|
| 125 | |
|---|
| 126 | } |
|---|
| 127 | |
|---|
| 128 | public function replace_values($find,$replacements) { |
|---|
| 129 | return isset($replacements[$find]) ? $replacements[$find] : $find; |
|---|
| 130 | } |
|---|
| 131 | |
|---|
| 132 | public function find_font( $element ) { |
|---|
| 133 | |
|---|
| 134 | if ( strpos( $element, 'font-family' ) !== false ) { |
|---|
| 135 | $f_family = str_replace( 'font-family:', '', $element ); |
|---|
| 136 | if ( strpos( $f_family, 'Open Sans' ) === false ) { |
|---|
| 137 | return $f_family; |
|---|
| 138 | } |
|---|
| 139 | } |
|---|
| 140 | |
|---|
| 141 | } |
|---|
| 142 | /** |
|---|
| 143 | * Get Map(s) |
|---|
| 144 | * |
|---|
| 145 | * @param array $where Conditional statement. |
|---|
| 146 | * @return array Array of Map object(s). |
|---|
| 147 | */ |
|---|
| 148 | public function fetch($where = array()) { |
|---|
| 149 | $results = $this->get($this->table, $where); |
|---|
| 150 | return apply_filters('wpgmp_map_results', $results, $where); |
|---|
| 151 | } |
|---|
| 152 | /** |
|---|
| 153 | * Add or Edit Operation. |
|---|
| 154 | */ |
|---|
| 155 | function save() { |
|---|
| 156 | |
|---|
| 157 | $data = array(); |
|---|
| 158 | $entityID = ''; |
|---|
| 159 | |
|---|
| 160 | //Nonce Verification |
|---|
| 161 | if( !isset( $_REQUEST['_wpnonce'] ) || ( isset( $_REQUEST['_wpnonce'] ) && empty($_REQUEST['_wpnonce']) ) ) |
|---|
| 162 | die( 'You are not allowed to save changes!' ); |
|---|
| 163 | if ( isset( $_REQUEST['_wpnonce'] ) && ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'wpgmp-nonce' ) ) |
|---|
| 164 | die( 'You are not allowed to save changes!' ); |
|---|
| 165 | |
|---|
| 166 | if ( ! isset( $_POST['wpgmp_import_code'] ) or $_POST['wpgmp_import_code'] == '' ) { |
|---|
| 167 | $this->verify( $_POST ); |
|---|
| 168 | } |
|---|
| 169 | |
|---|
| 170 | $this->errors = apply_filters('wpgmp_map_validation',$this->errors,$_POST); |
|---|
| 171 | |
|---|
| 172 | foreach(['smartphones','ipads','large-screens'] as $screen){ |
|---|
| 173 | |
|---|
| 174 | if(isset($_POST['map_all_control']['screens'][$screen]['map_width_mobile']) && !empty($_POST['map_all_control']['screens'][$screen]['map_width_mobile'])){ |
|---|
| 175 | if(!is_numeric($_POST['map_all_control']['screens'][$screen]['map_width_mobile'])) |
|---|
| 176 | $this->errors[] = esc_html__( 'Please enter the map width in numeric pixel value only under screen settings section.', 'wp-google-map-plugin' ); |
|---|
| 177 | } |
|---|
| 178 | if(isset($_POST['map_all_control']['screens'][$screen]['map_height_mobile']) && !empty($_POST['map_all_control']['screens'][$screen]['map_height_mobile'])){ |
|---|
| 179 | if(!is_numeric($_POST['map_all_control']['screens'][$screen]['map_height_mobile'])) |
|---|
| 180 | $this->errors[] = esc_html__( 'Please enter the map height in numeric pixel value only under Screen Settings section.', 'wp-google-map-plugin' ); |
|---|
| 181 | } |
|---|
| 182 | |
|---|
| 183 | } |
|---|
| 184 | |
|---|
| 185 | if(isset($_POST['map_width']) && !empty($_POST['map_width'])){ |
|---|
| 186 | $map_width = str_replace("%","",$_POST['map_width']); |
|---|
| 187 | if(!is_numeric($map_width)) { |
|---|
| 188 | $this->errors[] = esc_html__( 'Please enter a numeric value for pixel widths and specify it with a % sign if you want it to be treated as a percentage (e.g., 90%). If you prefer to display the map at full width, you can leave the field blank to default to 100% width.', 'wp-google-map-plugin' ); |
|---|
| 189 | } |
|---|
| 190 | } |
|---|
| 191 | |
|---|
| 192 | |
|---|
| 193 | |
|---|
| 194 | if(isset($_POST['map_all_control']['center_circle_fillopacity']) && !empty($_POST['map_all_control']['center_circle_fillopacity']) ){ |
|---|
| 195 | |
|---|
| 196 | if(!is_numeric($_POST['map_all_control']['center_circle_fillopacity'])){ |
|---|
| 197 | $this->errors[] = esc_html__( 'Please enter a numeric value for circle fill opacity under the Map\'s Center > Display Circle section.', 'wp-google-map-plugin' ); |
|---|
| 198 | }else if( !($_POST['map_all_control']['center_circle_fillopacity'] >= 0 && $_POST['map_all_control']['center_circle_fillopacity'] <=1) ){ |
|---|
| 199 | $this->errors[] = esc_html__( 'The numeric value for circle fill opacity under the Map\'s Center > Display Circle section must be a valid float value between 0 to 1.', 'wp-google-map-plugin' ); |
|---|
| 200 | } |
|---|
| 201 | |
|---|
| 202 | } |
|---|
| 203 | |
|---|
| 204 | if(isset($_POST['map_all_control']['center_circle_strokeopacity']) && !empty($_POST['map_all_control']['center_circle_strokeopacity']) && !is_numeric($_POST['map_all_control']['center_circle_strokeopacity'])){ |
|---|
| 205 | |
|---|
| 206 | if(!is_numeric($_POST['map_all_control']['center_circle_strokeopacity'])){ |
|---|
| 207 | $this->errors[] = esc_html__( 'Please enter a numeric value for circle stroke opacity under the Map\'s Center > Display Circle section.', 'wp-google-map-plugin' ); |
|---|
| 208 | }else if( !($_POST['map_all_control']['center_circle_strokeopacity'] >= 0 && $_POST['map_all_control']['center_circle_strokeopacity'] <=1) ){ |
|---|
| 209 | $this->errors[] = esc_html__( 'The numeric value for circle stroke opacity under the Map\'s Center > Display Circle section must be a valid float value between 0 to 1.', 'wp-google-map-plugin' ); |
|---|
| 210 | } |
|---|
| 211 | |
|---|
| 212 | } |
|---|
| 213 | |
|---|
| 214 | if(isset($_POST['map_all_control']['center_circle_strokeweight']) && !empty($_POST['map_all_control']['center_circle_strokeweight']) && !is_numeric($_POST['map_all_control']['center_circle_strokeweight'])){ |
|---|
| 215 | $this->errors[] = esc_html__( 'Please enter a numeric value for circle stroke weight under the Map\'s Center > Display Circle section.', 'wp-google-map-plugin' ); |
|---|
| 216 | } |
|---|
| 217 | if(isset($_POST['map_all_control']['center_circle_radius']) && !empty($_POST['map_all_control']['center_circle_radius']) && !is_numeric($_POST['map_all_control']['center_circle_radius'])){ |
|---|
| 218 | $this->errors[] = esc_html__( 'Please enter a numeric value for circle\'s radius under the Map\'s Center > Display Circle section.', 'wp-google-map-plugin' ); |
|---|
| 219 | } |
|---|
| 220 | |
|---|
| 221 | |
|---|
| 222 | if(isset($_POST['map_overlay_setting']['overlay_width']) && !empty($_POST['map_overlay_setting']['overlay_width']) && !is_numeric($_POST['map_overlay_setting']['overlay_width'])){ |
|---|
| 223 | $this->errors[] = esc_html__( 'Please enter the overlay width in numeric pixel value only the under Overlay Settings section.', 'wp-google-map-plugin' ); |
|---|
| 224 | } |
|---|
| 225 | if(isset($_POST['map_overlay_setting']['overlay_height']) && !empty($_POST['map_overlay_setting']['overlay_height']) && !is_numeric($_POST['map_overlay_setting']['overlay_height'])){ |
|---|
| 226 | $this->errors[] = esc_html__( 'Please enter the overlay height in numeric pixel value only the under Overlay Settings section.', 'wp-google-map-plugin' ); |
|---|
| 227 | } |
|---|
| 228 | if(isset($_POST['map_overlay_setting']['overlay_fontsize']) && !empty($_POST['map_overlay_setting']['overlay_fontsize']) && !is_numeric($_POST['map_overlay_setting']['overlay_fontsize'])){ |
|---|
| 229 | $this->errors[] = esc_html__( 'Please enter the font size in numeric pixel value only the under Overlay Settings section.', 'wp-google-map-plugin' ); |
|---|
| 230 | } |
|---|
| 231 | if(isset($_POST['map_overlay_setting']['overlay_border_width']) && !empty($_POST['map_overlay_setting']['overlay_border_width']) && !is_numeric($_POST['map_overlay_setting']['overlay_border_width'])){ |
|---|
| 232 | $this->errors[] = esc_html__( 'Please enter the overlay border width in numeric pixel value only the under Overlay Settings section.', 'wp-google-map-plugin' ); |
|---|
| 233 | } |
|---|
| 234 | if(isset($_POST['map_all_control']['wpgmp_base_font_size']) && !empty($_POST['map_all_control']['wpgmp_base_font_size']) ){ |
|---|
| 235 | |
|---|
| 236 | if (!str_contains($_POST['map_all_control']['wpgmp_base_font_size'], 'px') && !is_numeric($_POST['map_all_control']['wpgmp_base_font_size']) ) { |
|---|
| 237 | $this->errors[] = esc_html__( 'Please enter the overlay font size numeric pixel value only the under Map Theme Settings section.', 'wp-google-map-plugin' ); |
|---|
| 238 | } |
|---|
| 239 | |
|---|
| 240 | if (!str_contains($_POST['map_all_control']['wpgmp_base_font_size'], 'px') && is_numeric($_POST['map_all_control']['wpgmp_base_font_size']) ) { |
|---|
| 241 | $_POST['map_all_control']['wpgmp_base_font_size'] .= 'px'; |
|---|
| 242 | } |
|---|
| 243 | |
|---|
| 244 | } |
|---|
| 245 | if(isset($_POST['map_all_control']['infowindow_width']) && !empty($_POST['map_all_control']['infowindow_width']) && !is_numeric($_POST['map_all_control']['infowindow_width'])){ |
|---|
| 246 | $this->errors[] = esc_html__( 'Please enter the infowindow width in numeric pixel value only the under Infowindow Customisation Settings section.', 'wp-google-map-plugin' ); |
|---|
| 247 | } |
|---|
| 248 | |
|---|
| 249 | if(isset($_POST['map_all_control']['gm_radius']) && !empty($_POST['map_all_control']['gm_radius']) && !is_numeric($_POST['map_all_control']['gm_radius'])){ |
|---|
| 250 | $this->errors[] = esc_html__( 'Please enter a numeric radius value under Google Maps Amenities section.', 'wp-google-map-plugin' ); |
|---|
| 251 | } |
|---|
| 252 | |
|---|
| 253 | if ( is_array( $this->errors ) and ! empty( $this->errors ) ) { |
|---|
| 254 | $this->throw_errors(); |
|---|
| 255 | } |
|---|
| 256 | |
|---|
| 257 | if ( isset( $_POST['entityID'] ) ) { |
|---|
| 258 | $entityID = intval( wp_unslash( $_POST['entityID'] ) ); |
|---|
| 259 | } |
|---|
| 260 | |
|---|
| 261 | if ( isset( $_POST['wpgmp_import_code'] ) and $_POST['wpgmp_import_code'] != '' ) { |
|---|
| 262 | $import_code = wp_unslash( $_POST['wpgmp_import_code'] ); |
|---|
| 263 | if ( trim( $import_code ) != '' ) { |
|---|
| 264 | $map_settings = maybe_unserialize( base64_decode( $import_code ) ); |
|---|
| 265 | if ( is_object( $map_settings ) ) { |
|---|
| 266 | $_POST = (array) $map_settings; |
|---|
| 267 | } |
|---|
| 268 | } |
|---|
| 269 | } |
|---|
| 270 | |
|---|
| 271 | if ( ! is_array( $_POST['map_locations'] ) and '' != sanitize_text_field( $_POST['map_locations'] ) ) { |
|---|
| 272 | $map_locations = explode( ',', sanitize_text_field( $_POST['map_locations'] ) ); |
|---|
| 273 | } elseif ( is_array( $_POST['map_locations'] ) and ! empty( $_POST['map_locations'] ) ) { |
|---|
| 274 | $map_locations = $_POST['map_locations']; |
|---|
| 275 | } else { |
|---|
| 276 | $map_locations = array(); } |
|---|
| 277 | |
|---|
| 278 | if ( isset( $_POST['extensions_fields'] ) ) { |
|---|
| 279 | $_POST['map_all_control']['extensions_fields'] = $_POST['extensions_fields']; |
|---|
| 280 | } |
|---|
| 281 | |
|---|
| 282 | if ( isset( $_POST['map_marker_spiderfier_setting'] ) ) { |
|---|
| 283 | $_POST['map_all_control']['map_marker_spiderfier_setting'] = $_POST['map_marker_spiderfier_setting']; |
|---|
| 284 | } |
|---|
| 285 | |
|---|
| 286 | if ( isset( $_POST['map_all_control']['map_control_settings'] ) ) { |
|---|
| 287 | $arr = array(); |
|---|
| 288 | $i = 0; |
|---|
| 289 | foreach ( $_POST['map_all_control']['map_control_settings'] as $key => $val ) { |
|---|
| 290 | if ( $val['html'] != '' ) { |
|---|
| 291 | $arr[ $i ]['html'] = $val['html']; |
|---|
| 292 | $arr[ $i ]['position'] = $val['position']; |
|---|
| 293 | $i++; |
|---|
| 294 | } |
|---|
| 295 | } |
|---|
| 296 | $_POST['map_all_control']['map_control_settings'] = $arr; |
|---|
| 297 | } |
|---|
| 298 | |
|---|
| 299 | if ( isset( $_POST['map_all_control']['custom_filters'] ) ) { |
|---|
| 300 | $custom_filters = array(); |
|---|
| 301 | foreach ( $_POST['map_all_control']['custom_filters'] as $k => $val ) { |
|---|
| 302 | if ( $val['slug'] == '' ) { |
|---|
| 303 | unset( $_POST['map_all_control']['custom_filters'][ $k ] ); |
|---|
| 304 | } else { |
|---|
| 305 | $custom_filters[] = $val; |
|---|
| 306 | } |
|---|
| 307 | } |
|---|
| 308 | $_POST['map_all_control']['custom_filters'] = $custom_filters; |
|---|
| 309 | } |
|---|
| 310 | |
|---|
| 311 | if ( isset( $_POST['map_all_control']['location_infowindow_skin']['sourcecode'] ) ) { |
|---|
| 312 | $_POST['map_all_control']['location_infowindow_skin']['sourcecode'] = esc_html(wp_unslash($_POST['map_all_control']['location_infowindow_skin']['sourcecode'] ) ); |
|---|
| 313 | $_POST['map_all_control']['infowindow_setting'] = $_POST['map_all_control']['location_infowindow_skin']['sourcecode']; |
|---|
| 314 | } |
|---|
| 315 | |
|---|
| 316 | if ( isset( $_POST['map_all_control']['post_infowindow_skin']['sourcecode'] ) ) { |
|---|
| 317 | $_POST['map_all_control']['post_infowindow_skin']['sourcecode'] = esc_html(wp_unslash($_POST['map_all_control']['post_infowindow_skin']['sourcecode'] ) ); |
|---|
| 318 | $_POST['map_all_control']['infowindow_geotags_setting'] = $_POST['map_all_control']['post_infowindow_skin']['sourcecode']; |
|---|
| 319 | } |
|---|
| 320 | |
|---|
| 321 | if ( isset( $_POST['map_all_control']['item_skin']['sourcecode'] ) ) { |
|---|
| 322 | $_POST['map_all_control']['item_skin']['sourcecode'] = esc_html(wp_unslash($_POST['map_all_control']['item_skin']['sourcecode'] ) ); |
|---|
| 323 | $_POST['map_all_control']['wpgmp_categorydisplayformat'] = $_POST['map_all_control']['item_skin']['sourcecode']; |
|---|
| 324 | } |
|---|
| 325 | |
|---|
| 326 | $data['map_title'] = sanitize_text_field( wp_unslash( $_POST['map_title'] ) ); |
|---|
| 327 | $data['map_width'] = str_replace( 'px', '', sanitize_text_field( wp_unslash( $_POST['map_width'] ) ) ); |
|---|
| 328 | $data['map_height'] = str_replace( 'px', '', sanitize_text_field( wp_unslash( $_POST['map_height'] ) ) ); |
|---|
| 329 | $data['map_zoom_level'] = intval( wp_unslash( $_POST['map_zoom_level'] ) ); |
|---|
| 330 | $data['map_type'] = sanitize_text_field( wp_unslash( $_POST['map_type'] ) ); |
|---|
| 331 | |
|---|
| 332 | if ( isset( $_POST['map_scrolling_wheel'] ) ) { |
|---|
| 333 | $data['map_scrolling_wheel'] = sanitize_text_field( wp_unslash( $_POST['map_scrolling_wheel'] ) ); |
|---|
| 334 | }else{ |
|---|
| 335 | $data['map_scrolling_wheel'] = 'false'; |
|---|
| 336 | } |
|---|
| 337 | |
|---|
| 338 | if ( isset( $_POST['map_45imagery'] ) ) { |
|---|
| 339 | $data['map_45imagery'] = sanitize_text_field( wp_unslash( $_POST['map_45imagery'] ) ); |
|---|
| 340 | }else{ |
|---|
| 341 | $data['map_45imagery'] = ''; |
|---|
| 342 | } |
|---|
| 343 | |
|---|
| 344 | $data['map_street_view_setting'] = serialize( wp_unslash( $_POST['map_street_view_setting'] ) ); |
|---|
| 345 | |
|---|
| 346 | if ( isset( $_POST['map_route_direction_setting'] ) ) { |
|---|
| 347 | $data['map_route_direction_setting'] = serialize( wp_unslash( $_POST['map_route_direction_setting'] ) ); |
|---|
| 348 | }else{ |
|---|
| 349 | $data['map_route_direction_setting'] = serialize( array('route_direction' => 'false') ); |
|---|
| 350 | } |
|---|
| 351 | |
|---|
| 352 | $data['map_all_control'] = serialize( wp_unslash( $_POST['map_all_control'] ) ); |
|---|
| 353 | |
|---|
| 354 | if ( isset( $_POST['map_info_window_setting'] ) ) { |
|---|
| 355 | $data['map_info_window_setting'] = serialize( wp_unslash( $_POST['map_info_window_setting'] ) ); |
|---|
| 356 | } |
|---|
| 357 | |
|---|
| 358 | $data['style_google_map'] = serialize( wp_unslash( $_POST['style_google_map'] ) ); |
|---|
| 359 | $data['map_locations'] = serialize( wp_unslash( $map_locations ) ); |
|---|
| 360 | $data['map_layer_setting'] = serialize( wp_unslash( $_POST['map_layer_setting'] ) ); |
|---|
| 361 | |
|---|
| 362 | if ( isset( $_POST['map_polygon_setting'] ) ) { |
|---|
| 363 | $data['map_polygon_setting'] = serialize( wp_unslash( $_POST['map_polygon_setting'] ) ); |
|---|
| 364 | } |
|---|
| 365 | |
|---|
| 366 | $data['map_cluster_setting'] = serialize( wp_unslash( $_POST['map_cluster_setting'] ) ); |
|---|
| 367 | $data['map_overlay_setting'] = serialize( wp_unslash( $_POST['map_overlay_setting'] ) ); |
|---|
| 368 | |
|---|
| 369 | if ( isset( $_POST['map_infowindow_setting'] ) ) { |
|---|
| 370 | $data['map_infowindow_setting'] = serialize( wp_unslash( $_POST['map_infowindow_setting'] ) ); |
|---|
| 371 | } |
|---|
| 372 | |
|---|
| 373 | $data['map_geotags'] = ''; |
|---|
| 374 | if ( $entityID > 0 ) { |
|---|
| 375 | $where[ $this->unique ] = $entityID; |
|---|
| 376 | } else { |
|---|
| 377 | $where = ''; |
|---|
| 378 | } |
|---|
| 379 | // Hook to insert/update extension data. |
|---|
| 380 | if ( isset( $_POST['fc_entity_type'] ) ) { |
|---|
| 381 | |
|---|
| 382 | $extension_name = strtolower( trim( sanitize_text_field( wp_unslash( $_POST['fc_entity_type'] ) ) ) ); |
|---|
| 383 | |
|---|
| 384 | if ( $extension_name != '' ) { |
|---|
| 385 | $data = apply_filters( $extension_name . '_save', $data, $this->table, $where ); // phpcs:ignore WordPress.Hooks.UnprefixedActionHookName -- Inline suppression for dynamic hook name; prefixing would break compatibility. Use a consistent plugin prefix in future updates. |
|---|
| 386 | } |
|---|
| 387 | } |
|---|
| 388 | |
|---|
| 389 | $data = apply_filters('wpgmp_map_save',$data,$where); |
|---|
| 390 | $result = FlipperCode_Database::insert_or_update( $this->table, $data, $where ); |
|---|
| 391 | if ( false === $result ) { |
|---|
| 392 | $response['error'] = esc_html__( 'Something went wrong. Please try again.', 'wp-google-map-plugin' ); |
|---|
| 393 | } elseif ( $entityID > 0 ) { |
|---|
| 394 | $response['success'] = esc_html__( 'Map was updated successfully.', 'wp-google-map-plugin' ); |
|---|
| 395 | } else { |
|---|
| 396 | |
|---|
| 397 | $response['success'] = esc_html__( 'Map was added successfully. ', 'wp-google-map-plugin' ).'<b>[put_wpgm id='.$result.']</b>'.esc_html__(' can be used to display the map anywhere.', 'wp-google-map-plugin' ); |
|---|
| 398 | } |
|---|
| 399 | |
|---|
| 400 | $response['last_db_id'] = $result; |
|---|
| 401 | |
|---|
| 402 | do_action( 'wpgmp_after_map_save', $response, $data, $entityID ); |
|---|
| 403 | |
|---|
| 404 | |
|---|
| 405 | return $response; |
|---|
| 406 | } |
|---|
| 407 | /** |
|---|
| 408 | * Delete map object by id. |
|---|
| 409 | */ |
|---|
| 410 | function delete() { |
|---|
| 411 | if ( isset( $_GET['map_id'] ) ) { |
|---|
| 412 | $id = intval( wp_unslash( $_GET['map_id'] ) ); |
|---|
| 413 | $connection = FlipperCode_Database::connect(); |
|---|
| 414 | $this->query = $connection->prepare( "DELETE FROM $this->table WHERE $this->unique='%d'", $id ); |
|---|
| 415 | |
|---|
| 416 | do_action( 'wpgmp_after_map_deleted', $id, $result ); |
|---|
| 417 | |
|---|
| 418 | return FlipperCode_Database::non_query( $this->query, $connection ); |
|---|
| 419 | } |
|---|
| 420 | } |
|---|
| 421 | /** |
|---|
| 422 | * Clone map object by id. |
|---|
| 423 | */ |
|---|
| 424 | function copy($map_id) { |
|---|
| 425 | if ($map_id) { |
|---|
| 426 | $map = $this->get($this->table, array(array('map_id', '=', intval($map_id)))); |
|---|
| 427 | $data = array(); |
|---|
| 428 | foreach ($map[0] as $column => $value) { |
|---|
| 429 | if( $column != 'map_id') |
|---|
| 430 | $data[$column] = ($column == 'map_title') ? $value . ' ' . esc_html__('Copy', 'wp-google-map-plugin') : $value; |
|---|
| 431 | } |
|---|
| 432 | return FlipperCode_Database::insert_or_update($this->table, $data); |
|---|
| 433 | } |
|---|
| 434 | } |
|---|
| 435 | |
|---|
| 436 | |
|---|
| 437 | function get_map_customizer_style(){ |
|---|
| 438 | |
|---|
| 439 | $font_families = array(); |
|---|
| 440 | $fc_skin_styles = ''; |
|---|
| 441 | |
|---|
| 442 | $map_obj = $this->fetch( array( array( 'map_id', '=', intval( wp_unslash( $_GET['map_id'] ) ) ) ) ); |
|---|
| 443 | $map = $map_obj[0]; |
|---|
| 444 | if ( ! empty( $map ) ) { |
|---|
| 445 | $map->map_all_control = maybe_unserialize( $map->map_all_control ); |
|---|
| 446 | } |
|---|
| 447 | |
|---|
| 448 | $data = (array) $map; |
|---|
| 449 | |
|---|
| 450 | if ( isset( $data['map_all_control']['fc_custom_styles'] ) ) { |
|---|
| 451 | $fc_custom_styles = json_decode( $data['map_all_control']['fc_custom_styles'], true ); |
|---|
| 452 | if ( ! empty( $fc_custom_styles ) && is_array( $fc_custom_styles ) ) { |
|---|
| 453 | $fc_skin_styles = ''; |
|---|
| 454 | foreach ( $fc_custom_styles as $fc_style ) { |
|---|
| 455 | if ( is_array( $fc_style ) ) { |
|---|
| 456 | foreach ( $fc_style as $skin => $class_style ) { |
|---|
| 457 | if ( is_array( $class_style ) ) { |
|---|
| 458 | foreach ( $class_style as $class => $style ) { |
|---|
| 459 | $ind_style = explode( ';', $style ); |
|---|
| 460 | |
|---|
| 461 | foreach ($ind_style as $css_value) { |
|---|
| 462 | if ( strpos( $css_value, 'font-family' ) !== false ) { |
|---|
| 463 | $font_family_properties = explode( ':', $css_value ); |
|---|
| 464 | if(!empty($font_family_properties['1'])){ |
|---|
| 465 | $multiple_family = explode( ',', $font_family_properties['1']); |
|---|
| 466 | if(count($multiple_family)==1){ |
|---|
| 467 | $font_families[] = $font_family_properties['1']; |
|---|
| 468 | } |
|---|
| 469 | } |
|---|
| 470 | } |
|---|
| 471 | } |
|---|
| 472 | |
|---|
| 473 | if ( strpos( $class, '.' ) !== 0 ) { |
|---|
| 474 | $class = '.' . $class; |
|---|
| 475 | } |
|---|
| 476 | $fc_skin_styles .= ' .fc-' . $skin . ' ' . $class . '{' . $style . '}'; |
|---|
| 477 | } |
|---|
| 478 | } |
|---|
| 479 | } |
|---|
| 480 | } |
|---|
| 481 | } |
|---|
| 482 | |
|---|
| 483 | } |
|---|
| 484 | } |
|---|
| 485 | |
|---|
| 486 | return array('font_families' => $font_families,'fc_skin_styles' => $fc_skin_styles ); |
|---|
| 487 | |
|---|
| 488 | } |
|---|
| 489 | |
|---|
| 490 | } |
|---|
| 491 | } |
|---|