| 1 |
<?php |
| 2 |
namespace Cbx\Googlemap\Helpers; |
| 3 |
// If this file is called directly, abort. |
| 4 |
if ( ! defined( 'WPINC' ) ) { |
| 5 |
die; |
| 6 |
} |
| 7 |
|
| 8 |
use Cbx\Googlemap\CBXGooglemapSettings; |
| 9 |
|
| 10 |
|
| 11 |
class CBXGooglemapHelper { |
| 12 |
/** |
| 13 |
* Is gutenberg edit page |
| 14 |
* |
| 15 |
* @return bool |
| 16 |
* |
| 17 |
* @since 1.1.5 |
| 18 |
*/ |
| 19 |
public static function is_gutenberg_page() { |
| 20 |
//if(!is_admin()) return false; |
| 21 |
if ( function_exists( 'is_gutenberg_page' ) && |
| 22 |
is_gutenberg_page() |
| 23 |
) { |
| 24 |
// The Gutenberg plugin is on. |
| 25 |
return true; |
| 26 |
} |
| 27 |
|
| 28 |
$current_screen = get_current_screen(); |
| 29 |
if ( method_exists( $current_screen, 'is_block_editor' ) && $current_screen->is_block_editor() ) { |
| 30 |
// Gutenberg page on 5+. |
| 31 |
return true; |
| 32 |
} |
| 33 |
|
| 34 |
return false; |
| 35 |
}//end is_gutenberg_page |
| 36 |
|
| 37 |
|
| 38 |
/** |
| 39 |
* Enqueue css and js when needed (for map render) |
| 40 |
* |
| 41 |
* @param bool $enqueue_js |
| 42 |
* @param bool $enqueue_css |
| 43 |
* |
| 44 |
* @since 1.1.5 |
| 45 |
*/ |
| 46 |
public static function enqueue_js_css( $enqueue_js = true, $enqueue_css = true ) { |
| 47 |
$settings = new CBXGooglemapSettings();; |
| 48 |
$api_key = $settings->get_field( 'apikey', 'cbxgooglemap_general', '' ); |
| 49 |
$map_source = absint( $settings->get_field( 'mapsource', 'cbxgooglemap_general', 1 ) ); |
| 50 |
|
| 51 |
if ( $enqueue_js ) { |
| 52 |
//handle enqueue js |
| 53 |
if ( ( $map_source == 1 && ! empty( $api_key ) ) || $map_source == 0 ) { |
| 54 |
if ( $map_source == 1 ) { |
| 55 |
wp_enqueue_script( 'coregooglemapapi' ); |
| 56 |
//wp_enqueue_script( 'jqcbxgooglemap' ); |
| 57 |
} else { |
| 58 |
wp_enqueue_script( 'coregooglemapapi' ); |
| 59 |
} |
| 60 |
|
| 61 |
wp_enqueue_script( 'cbxgooglemap-events' ); |
| 62 |
wp_enqueue_script( 'cbxgooglemap-public' ); |
| 63 |
} |
| 64 |
//end handle enqueue js |
| 65 |
} |
| 66 |
|
| 67 |
if ( $enqueue_css ) { |
| 68 |
//handle enqueue css |
| 69 |
if ( $map_source == 0 ) { |
| 70 |
wp_enqueue_style( 'leaflet' ); |
| 71 |
} else { |
| 72 |
// |
| 73 |
} |
| 74 |
|
| 75 |
wp_enqueue_style( 'cbxgooglemap-public' ); |
| 76 |
//end handle enqueue css |
| 77 |
} |
| 78 |
|
| 79 |
do_action( 'cbxgooglemap_enqueue_js_css', $enqueue_js, $enqueue_css ); |
| 80 |
|
| 81 |
}//end enqueue_js_css |
| 82 |
|
| 83 |
/** |
| 84 |
* Register Custom Post Type cbxgooglemap |
| 85 |
* |
| 86 |
* @since 3.7.0 |
| 87 |
*/ |
| 88 |
public static function create_googlemap_post_type() { |
| 89 |
$post_slug_default = 'cbxgooglemap'; |
| 90 |
|
| 91 |
$labels = [ |
| 92 |
'name' => _x( 'Maps', 'Post Type General Name', 'cbxgooglemap' ), |
| 93 |
'singular_name' => _x( 'Map', 'Post Type Singular Name', 'cbxgooglemap' ), |
| 94 |
'menu_name' => esc_html__( 'CBX Maps', 'cbxgooglemap' ), |
| 95 |
'parent_item_colon' => esc_html__( 'Parent Item:', 'cbxgooglemap' ), |
| 96 |
'all_items' => esc_html__( 'Maps', 'cbxgooglemap' ), |
| 97 |
'view_item' => esc_html__( 'View Map', 'cbxgooglemap' ), |
| 98 |
'add_new_item' => esc_html__( 'Add New Map', 'cbxgooglemap' ), |
| 99 |
'add_new' => esc_html__( 'Add New', 'cbxgooglemap' ), |
| 100 |
'edit_item' => esc_html__( 'Edit Map', 'cbxgooglemap' ), |
| 101 |
'update_item' => esc_html__( 'Update Map', 'cbxgooglemap' ), |
| 102 |
'search_items' => esc_html__( 'Search Map', 'cbxgooglemap' ), |
| 103 |
'not_found' => esc_html__( 'Not found', 'cbxgooglemap' ), |
| 104 |
'not_found_in_trash' => esc_html__( 'Not found in Trash', 'cbxgooglemap' ), |
| 105 |
]; |
| 106 |
|
| 107 |
$args = [ |
| 108 |
'label' => esc_html__( 'Maps', 'cbxgooglemap' ), |
| 109 |
'description' => esc_html__( 'Simple map using google map and openstreet map.', 'cbxgooglemap' ), |
| 110 |
'labels' => apply_filters( 'cbxgooglemap_post_type_labels', $labels ), |
| 111 |
'supports' => apply_filters( 'cbxgooglemap_post_type_supports', [ 'title' ] ), |
| 112 |
'hierarchical' => false, |
| 113 |
'public' => apply_filters( 'cbxgooglemap_post_type_public', false ), |
| 114 |
'show_ui' => true, |
| 115 |
'show_in_menu' => true, |
| 116 |
'show_in_nav_menus' => true, |
| 117 |
'show_in_admin_bar' => true, |
| 118 |
'rewrite' => [ 'slug' => apply_filters( 'cbxgooglemap_single_slug', $post_slug_default ) ], |
| 119 |
//'menu_icon' => 'dashicons-list-view', |
| 120 |
'menu_icon' => apply_filters( 'cbxgooglemap_menu_icon', 'dashicons-location' ), |
| 121 |
'can_export' => true, |
| 122 |
'has_archive' => apply_filters( 'cbxgooglemap_post_type_has_archive', false ), |
| 123 |
'exclude_from_search' => apply_filters( 'cbxgooglemap_post_type_exclude_from_search', true ), |
| 124 |
'publicly_queryable' => apply_filters( 'cbxgooglemap_post_type_publicly_queryable', false ), |
| 125 |
'capability_type' => 'post', |
| 126 |
]; |
| 127 |
|
| 128 |
register_post_type( 'cbxgooglemap', apply_filters( 'cbxgooglemap_post_type_args', $args ) ); |
| 129 |
}//end create_googlemap_post_type |
| 130 |
|
| 131 |
/** |
| 132 |
* Setup a post object and store the original loop item so we can reset it later |
| 133 |
* |
| 134 |
* @param obj $post_to_setup The post that we want to use from our custom loop |
| 135 |
*/ |
| 136 |
public static function setup_admin_postdata( $post_to_setup ) { |
| 137 |
//only on the admin side |
| 138 |
if ( is_admin() ) { |
| 139 |
|
| 140 |
//get the post for both setup_postdata() and to be cached |
| 141 |
global $post; |
| 142 |
|
| 143 |
//only cache $post the first time through the loop |
| 144 |
if ( ! isset( $GLOBALS['post_cache'] ) ) { |
| 145 |
$GLOBALS['post_cache'] = $post; //phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound |
| 146 |
} |
| 147 |
|
| 148 |
//setup the post data as usual |
| 149 |
$post = $post_to_setup; |
| 150 |
setup_postdata( $post ); |
| 151 |
} |
| 152 |
}//end setup_admin_postdata |
| 153 |
|
| 154 |
/** |
| 155 |
* Reset $post back to the original item |
| 156 |
* |
| 157 |
*/ |
| 158 |
public static function wp_reset_admin_postdata() { |
| 159 |
//only on the admin and if post_cache is set |
| 160 |
if ( is_admin() && ! empty( $GLOBALS['post_cache'] ) ) { |
| 161 |
|
| 162 |
//globalize post as usual |
| 163 |
global $post; |
| 164 |
|
| 165 |
//set $post back to the cached version and set it up |
| 166 |
$post = $GLOBALS['post_cache']; |
| 167 |
setup_postdata( $post ); |
| 168 |
|
| 169 |
//cleanup |
| 170 |
unset( $GLOBALS['post_cache'] ); |
| 171 |
} |
| 172 |
}//end wp_reset_admin_postdata |
| 173 |
|
| 174 |
public static function supported_post_types() { |
| 175 |
$allowed_post_types = [ 'cbxgooglemap' ]; |
| 176 |
return apply_filters( 'cbxgooglemap_post_types_support', $allowed_post_types ); |
| 177 |
}//end supported_post_types |
| 178 |
|
| 179 |
/** |
| 180 |
* Returns all post types that has public view and visually accessible |
| 181 |
* |
| 182 |
* @return array |
| 183 |
*/ |
| 184 |
public static function post_types() { |
| 185 |
$post_type_args = [ |
| 186 |
'builtin' => [ |
| 187 |
'options' => [ |
| 188 |
'public' => true, |
| 189 |
'_builtin' => true, |
| 190 |
'show_ui' => true, |
| 191 |
], |
| 192 |
'label' => esc_html__( 'Built in post types', 'cbxgooglemap' ), |
| 193 |
] |
| 194 |
]; |
| 195 |
|
| 196 |
$post_type_args = apply_filters( 'cbxgooglemap_post_types', $post_type_args ); |
| 197 |
|
| 198 |
$output = 'objects'; // names or objects, note names is the default |
| 199 |
$operator = 'and'; // 'and' or 'or' |
| 200 |
$postTypes = []; |
| 201 |
|
| 202 |
foreach ( $post_type_args as $postArgType => $postArgTypeArr ) { |
| 203 |
$types = get_post_types( $postArgTypeArr['options'], $output, $operator ); |
| 204 |
|
| 205 |
if ( ! empty( $types ) ) { |
| 206 |
foreach ( $types as $type ) { |
| 207 |
$postTypes[ $postArgType ]['label'] = $postArgTypeArr['label']; |
| 208 |
$postTypes[ $postArgType ]['data'][ $type->name ] = $type->labels->name; |
| 209 |
} |
| 210 |
} |
| 211 |
} |
| 212 |
|
| 213 |
return $postTypes; |
| 214 |
|
| 215 |
}//end post_types |
| 216 |
|
| 217 |
/** |
| 218 |
* Shortcode builder for display and copy paste purpose |
| 219 |
* |
| 220 |
* @param $general_settings |
| 221 |
* |
| 222 |
* @return string |
| 223 |
*/ |
| 224 |
public static function shortcode_builder( $general_settings = [] ) { |
| 225 |
$settings = new CBXGooglemapSettings(); |
| 226 |
$zoom_default = $settings->get_field( 'zoom', 'cbxgooglemap_general', '8' ); |
| 227 |
if ( $zoom_default == 0 ) { |
| 228 |
$zoom_default = 8; |
| 229 |
} |
| 230 |
|
| 231 |
$width_default = $settings->get_field( 'width', 'cbxgooglemap_general', '100%' ); |
| 232 |
if ( $width_default == '' || $width_default == 0 ) { |
| 233 |
$width_default = '100%'; |
| 234 |
} |
| 235 |
|
| 236 |
$height_default = intval( $settings->get_field( 'height', 'cbxgooglemap_general', '300' ) ); |
| 237 |
if ( $height_default == 0 ) { |
| 238 |
$height_default = 300; |
| 239 |
} |
| 240 |
|
| 241 |
$scrollwheel_default = intval( $settings->get_field( 'scrollwheel', 'cbxgooglemap_general', 1 ) ); |
| 242 |
$showinfo_default = intval( $settings->get_field( 'showinfo', 'cbxgooglemap_general', 1 ) ); |
| 243 |
$infow_open_default = intval( $settings->get_field( 'infow_open', 'cbxgooglemap_general', 1 ) ); |
| 244 |
$maptype_default = esc_attr( $settings->get_field( 'maptype', 'cbxgooglemap_general', 'roadmap' ) ); |
| 245 |
$mapicon_default = esc_url( $settings->get_field( 'mapicon', 'cbxgooglemap_general', '' ) ); |
| 246 |
|
| 247 |
$attr = [ |
| 248 |
'width' => $width_default, |
| 249 |
'height' => $height_default, |
| 250 |
'zoom' => $zoom_default, |
| 251 |
'scrollwheel' => $scrollwheel_default, |
| 252 |
'showinfo' => $showinfo_default, |
| 253 |
'infow_open' => $infow_open_default, |
| 254 |
'maptype' => $maptype_default, |
| 255 |
'heading' => 'Codeboxr(Sample)', |
| 256 |
'address' => '6H, Dilara Tower, 77 Bir Uttam C.R. Dutta Road, Dhaka 1205(Sample)', |
| 257 |
'website' => 'https://codeboxr.com/', |
| 258 |
'mapicon' => $mapicon_default, |
| 259 |
'lat' => '23.744825100000003', |
| 260 |
'lng' => '90.39219739999999' |
| 261 |
]; |
| 262 |
|
| 263 |
$attr = apply_filters( 'cbxgooglemap_builder_attr', $attr ); |
| 264 |
|
| 265 |
$attr_html = ''; |
| 266 |
|
| 267 |
foreach ( $attr as $key => $value ) { |
| 268 |
$attr_html .= ' ' . $key . '="' . $value . '" '; |
| 269 |
} |
| 270 |
|
| 271 |
return '[cbxgooglemap ' . $attr_html . ']'; |
| 272 |
}//end method shortcode_builder |
| 273 |
|
| 274 |
/** |
| 275 |
* Map type block compatible options |
| 276 |
* |
| 277 |
* @return mixed|void |
| 278 |
*/ |
| 279 |
public static function maptype_block_options() { |
| 280 |
$maptypes = [ |
| 281 |
'roadmap' => esc_html__( 'Road Map', 'cbxgooglemap' ), |
| 282 |
'satellite' => esc_html__( 'Satellite Map', 'cbxgooglemap' ), |
| 283 |
'hybrid' => esc_html__( 'Hybrid Map', 'cbxgooglemap' ), |
| 284 |
'terrain' => esc_html__( 'Terrain Map', 'cbxgooglemap' ), |
| 285 |
]; |
| 286 |
|
| 287 |
$maptype_arr = []; |
| 288 |
|
| 289 |
foreach ( $maptypes as $key => $value ) { |
| 290 |
$maptype_arr[] = [ |
| 291 |
'label' => $value, |
| 292 |
'value' => $key |
| 293 |
]; |
| 294 |
} |
| 295 |
|
| 296 |
return apply_filters( 'cbxgooglemap_maptype_block_options', $maptype_arr ); |
| 297 |
}//end maptype_block_options |
| 298 |
|
| 299 |
|
| 300 |
/** |
| 301 |
* @return mixed|void |
| 302 |
*/ |
| 303 |
public static function get_maptype() { |
| 304 |
$maptype = [ |
| 305 |
'roadmap' => esc_html__( 'Road Map', 'cbxgooglemap' ), |
| 306 |
'satellite' => esc_html__( 'Satellite Map', 'cbxgooglemap' ), |
| 307 |
'hybrid' => esc_html__( 'Hybrid Map', 'cbxgooglemap' ), |
| 308 |
'terrain' => esc_html__( 'Terrain Map', 'cbxgooglemap' ), |
| 309 |
]; |
| 310 |
|
| 311 |
return apply_filters( 'cbxgooglemap_maptype', $maptype ); |
| 312 |
}// end get_maptype |
| 313 |
|
| 314 |
/** |
| 315 |
* Get available map type reverser |
| 316 |
* |
| 317 |
* @return mixed|void |
| 318 |
*/ |
| 319 |
public static function get_maptype_r() { |
| 320 |
$maptype = CBXGooglemapHelper::get_maptype(); |
| 321 |
$maptype_r = []; |
| 322 |
|
| 323 |
foreach ( $maptype as $key => $value ) { |
| 324 |
$maptype_r[ $value ] = $key; |
| 325 |
} |
| 326 |
|
| 327 |
return apply_filters( 'cbxgooglemap_maptype_r', $maptype_r ); |
| 328 |
}//end get_maptype_r |
| 329 |
|
| 330 |
/** |
| 331 |
* Add utm params to any url |
| 332 |
* |
| 333 |
* @param string $url |
| 334 |
* |
| 335 |
* @return string |
| 336 |
*/ |
| 337 |
public static function url_utmy( $url = '' ) { |
| 338 |
if ( $url == '' ) { |
| 339 |
return $url; |
| 340 |
} |
| 341 |
|
| 342 |
$url = add_query_arg( [ |
| 343 |
'utm_source' => 'plgsidebarinfo', |
| 344 |
'utm_medium' => 'plgsidebar', |
| 345 |
'utm_campaign' => 'wpfreemium', |
| 346 |
], $url ); |
| 347 |
|
| 348 |
return $url; |
| 349 |
}//end url_utmy |
| 350 |
|
| 351 |
/** |
| 352 |
* Most needed common strings needed in js throughout the plugin |
| 353 |
* |
| 354 |
* @return array |
| 355 |
*/ |
| 356 |
public static function global_translation_strings() { |
| 357 |
$global_translation = [ |
| 358 |
'is_user_logged_in' => is_user_logged_in() ? 1 : 0, |
| 359 |
'ajax' => [ |
| 360 |
'ajax_url' => admin_url( 'admin-ajax.php' ), |
| 361 |
'rest_url' => esc_url_raw( rest_url() ), |
| 362 |
'ajax_fail' => esc_html__( 'Request failed, please reload the page.', 'cbxgooglemap' ), |
| 363 |
'ajax_nonce' => wp_create_nonce( 'cbxgooglemap_nonce' ), |
| 364 |
'rest_nonce' => wp_create_nonce( 'wp_rest' ), |
| 365 |
], |
| 366 |
'teeny_setting' => [ |
| 367 |
'teeny' => true, |
| 368 |
'media_buttons' => true, |
| 369 |
'editor_class' => '', |
| 370 |
'textarea_rows' => 5, |
| 371 |
'quicktags' => false, |
| 372 |
'menubar' => false, |
| 373 |
], |
| 374 |
'copycmds' => [ |
| 375 |
'copy' => esc_html__( 'Copy', 'cbxgooglemap' ), |
| 376 |
'copied' => esc_html__( 'Copied', 'cbxgooglemap' ), |
| 377 |
'copy_tip' => esc_html__( 'Click to copy', 'cbxgooglemap' ), |
| 378 |
'copied_tip' => esc_html__( 'Copied to clipboard', 'cbxgooglemap' ), |
| 379 |
], |
| 380 |
'delete_dialog' => [ |
| 381 |
'ok' => esc_attr_x( 'Ok', 'cbxgooglemap-dialog', 'cbxgooglemap' ), |
| 382 |
'cancel' => esc_attr_x( 'Cancel', 'cbxgooglemap-dialog', 'cbxgooglemap' ), |
| 383 |
'delete' => esc_attr_x( 'Delete', 'cbxgooglemap-dialog', 'cbxgooglemap' ), |
| 384 |
'are_you_sure_global' => esc_html__( 'Are you sure?', 'cbxgooglemap' ), |
| 385 |
'are_you_sure_delete_desc' => esc_html__( 'Once you delete, it\'s gone forever. You can not revert it back.', 'cbxgooglemap' ), |
| 386 |
], |
| 387 |
'pickr_i18n' => [ |
| 388 |
// Strings visible in the UI |
| 389 |
'ui:dialog' => esc_html__( 'color picker dialog', 'cbxgooglemap' ), |
| 390 |
'btn:toggle' => esc_html__( 'toggle color picker dialog', 'cbxgooglemap' ), |
| 391 |
'btn:swatch' => esc_html__( 'color swatch', 'cbxgooglemap' ), |
| 392 |
'btn:last-color' => esc_html__( 'use previous color', 'cbxgooglemap' ), |
| 393 |
'btn:save' => esc_html__( 'Save', 'cbxgooglemap' ), |
| 394 |
'btn:cancel' => esc_html__( 'Cancel', 'cbxgooglemap' ), |
| 395 |
'btn:clear' => esc_html__( 'Clear', 'cbxgooglemap' ), |
| 396 |
|
| 397 |
// Strings used for aria-labels |
| 398 |
'aria:btn:save' => esc_html__( 'save and close', 'cbxgooglemap' ), |
| 399 |
'aria:btn:cancel' => esc_html__( 'cancel and close', 'cbxgooglemap' ), |
| 400 |
'aria:btn:clear' => esc_html__( 'clear and close', 'cbxgooglemap' ), |
| 401 |
'aria:input' => esc_html__( 'color input field', 'cbxgooglemap' ), |
| 402 |
'aria:palette' => esc_html__( 'color selection area', 'cbxgooglemap' ), |
| 403 |
'aria:hue' => esc_html__( 'hue selection slider', 'cbxgooglemap' ), |
| 404 |
'aria:opacity' => esc_html__( 'selection slider', 'cbxgooglemap' ), |
| 405 |
], |
| 406 |
'awn_options' => [ |
| 407 |
'tip' => esc_html__( 'Tip', 'cbxgooglemap' ), |
| 408 |
'info' => esc_html__( 'Info', 'cbxgooglemap' ), |
| 409 |
'success' => esc_html__( 'Success', 'cbxgooglemap' ), |
| 410 |
'warning' => esc_html__( 'Attention', 'cbxgooglemap' ), |
| 411 |
'alert' => esc_html__( 'Error', 'cbxgooglemap' ), |
| 412 |
'async' => esc_html__( 'Loading', 'cbxgooglemap' ), |
| 413 |
'confirm' => esc_html__( 'Confirmation', 'cbxgooglemap' ), |
| 414 |
'confirmOk' => esc_html__( 'OK', 'cbxgooglemap' ), |
| 415 |
'confirmCancel' => esc_html__( 'Cancel', 'cbxgooglemap' ) |
| 416 |
], |
| 417 |
'validation' => [ |
| 418 |
'required' => esc_html__( 'This field is required.', 'cbxgooglemap' ), |
| 419 |
'remote' => esc_html__( 'Please fix this field.', 'cbxgooglemap' ), |
| 420 |
'email' => esc_html__( 'Please enter a valid email address.', 'cbxgooglemap' ), |
| 421 |
'url' => esc_html__( 'Please enter a valid URL.', 'cbxgooglemap' ), |
| 422 |
'date' => esc_html__( 'Please enter a valid date.', 'cbxgooglemap' ), |
| 423 |
'dateISO' => esc_html__( 'Please enter a valid date ( ISO ).', 'cbxgooglemap' ), |
| 424 |
'number' => esc_html__( 'Please enter a valid number.', 'cbxgooglemap' ), |
| 425 |
'digits' => esc_html__( 'Please enter only digits.', 'cbxgooglemap' ), |
| 426 |
'equalTo' => esc_html__( 'Please enter the same value again.', 'cbxgooglemap' ), |
| 427 |
'maxlength' => esc_html__( 'Please enter no more than {0} characters.', 'cbxgooglemap' ), |
| 428 |
'minlength' => esc_html__( 'Please enter at least {0} characters.', 'cbxgooglemap' ), |
| 429 |
'rangelength' => esc_html__( 'Please enter a value between {0} and {1} characters long.', 'cbxgooglemap' ), |
| 430 |
'range' => esc_html__( 'Please enter a value between {0} and {1}.', 'cbxgooglemap' ), |
| 431 |
'max' => esc_html__( 'Please enter a value less than or equal to {0}.', 'cbxgooglemap' ), |
| 432 |
'min' => esc_html__( 'Please enter a value greater than or equal to {0}.', 'cbxgooglemap' ), |
| 433 |
'recaptcha' => esc_html__( 'Please check the captcha.', 'cbxgooglemap' ), |
| 434 |
], |
| 435 |
'placeholder' => [ |
| 436 |
'select' => esc_html__( 'Please Select', 'cbxgooglemap' ), |
| 437 |
'search' => esc_html__( 'Search...', 'cbxgooglemap' ), |
| 438 |
], |
| 439 |
'upload' => [ |
| 440 |
'upload_btn' => esc_html__( 'Upload', 'cbxgooglemap' ), |
| 441 |
'upload_title' => esc_html__( 'Select Media', 'cbxgooglemap' ), |
| 442 |
], |
| 443 |
'lang' => get_user_locale(), |
| 444 |
'file_preview' => [ |
| 445 |
'browse' => esc_attr__( 'Choose', 'cbxgooglemap' ), |
| 446 |
'chooseFile' => esc_attr__( 'Take your pick...', 'cbxgooglemap' ), |
| 447 |
'label' => esc_attr__( 'Choose Files to Upload', 'cbxgooglemap' ), |
| 448 |
'selectedCount' => esc_attr__( 'files selected', 'cbxgooglemap' ) |
| 449 |
] |
| 450 |
]; |
| 451 |
|
| 452 |
return apply_filters( 'cbxgooglemap_global_translation', $global_translation ); |
| 453 |
}//end method global_translation_strings |
| 454 |
|
| 455 |
/** |
| 456 |
* Returns codeboxr news feeds using transient cache |
| 457 |
* |
| 458 |
* @return false|mixed|\SimplePie\Item[]|null |
| 459 |
*/ |
| 460 |
public static function codeboxr_news_feed() { |
| 461 |
$cache_key = 'codeboxr_news_feed_cache'; |
| 462 |
$cached_feed = get_transient( $cache_key ); |
| 463 |
|
| 464 |
$news = false; |
| 465 |
|
| 466 |
if ( false === $cached_feed ) { |
| 467 |
include_once ABSPATH . WPINC . '/feed.php'; // Ensure feed functions are available |
| 468 |
$feed = fetch_feed( 'https://codeboxr.com/feed?post_type=post' ); |
| 469 |
|
| 470 |
if ( is_wp_error( $feed ) ) { |
| 471 |
return false; // Return false if there's an error |
| 472 |
} |
| 473 |
|
| 474 |
$feed->init(); |
| 475 |
|
| 476 |
$feed->set_output_encoding( 'UTF-8' ); |
| 477 |
// this is the encoding parameter, and can be left unchanged in almost every case |
| 478 |
$feed->handle_content_type(); |
| 479 |
// this double-checks the encoding type |
| 480 |
$feed->set_cache_duration( 21600 ); |
| 481 |
// 21,600 seconds is six hours |
| 482 |
$limit = $feed->get_item_quantity( 10 ); |
| 483 |
// fetches the 18 most recent RSS feed stories |
| 484 |
$items = $feed->get_items( 0, $limit ); |
| 485 |
$blocks = array_slice( $items, 0, 10 ); |
| 486 |
|
| 487 |
$news = []; |
| 488 |
foreach ( $blocks as $block ) { |
| 489 |
$url = $block->get_permalink(); |
| 490 |
$url = CBXGooglemapHelper::url_utmy( esc_url( $url ) ); |
| 491 |
$title = $block->get_title(); |
| 492 |
|
| 493 |
$news[] = [ 'url' => $url, 'title' => $title ]; |
| 494 |
} |
| 495 |
|
| 496 |
set_transient( $cache_key, $news, HOUR_IN_SECONDS * 6 ); // Cache for 6 hours |
| 497 |
} else { |
| 498 |
$news = $cached_feed; |
| 499 |
} |
| 500 |
|
| 501 |
return $news; |
| 502 |
}//end method codeboxr_news_feed |
| 503 |
|
| 504 |
/** |
| 505 |
* Short Description. (use period) |
| 506 |
* |
| 507 |
* Long Description. |
| 508 |
* |
| 509 |
* @since 1.0.0 |
| 510 |
*/ |
| 511 |
public static function activate() { |
| 512 |
CBXGooglemapHelper::create_googlemap_post_type(); |
| 513 |
|
| 514 |
add_option( 'cbxgooglemap_flush_rewrite_rules', 'true' ); |
| 515 |
//set_transient( 'cbxgooglemap_activated_notice', 1 ); |
| 516 |
|
| 517 |
|
| 518 |
if ( ! function_exists( 'is_plugin_active' ) ) { |
| 519 |
include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); |
| 520 |
} |
| 521 |
|
| 522 |
//phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound |
| 523 |
if ( defined( 'CBXGOOGLEMAPPRO_PLUGIN_NAME' ) || in_array( 'cbxgooglemappro/cbxgooglemappro.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) { |
| 524 |
//plugin is activated |
| 525 |
|
| 526 |
$plugin_version = CBXGOOGLEMAPPRO_PLUGIN_VERSION; |
| 527 |
|
| 528 |
if ( version_compare( $plugin_version, '2.0.0', '<' ) ) { |
| 529 |
deactivate_plugins( 'cbxgooglemappro/cbxgooglemappro.php' ); |
| 530 |
set_transient( 'cbxgooglemappro_deactivated_notice', 1 ); |
| 531 |
} |
| 532 |
} |
| 533 |
|
| 534 |
}//end activate |
| 535 |
|
| 536 |
/** |
| 537 |
* Short Description. (use period) |
| 538 |
* |
| 539 |
* Long Description. |
| 540 |
* |
| 541 |
* @since 1.0.0 |
| 542 |
*/ |
| 543 |
public static function deactivate() { |
| 544 |
delete_option( 'cbxgooglemap_flush_rewrite_rules' ); |
| 545 |
}//end deactivate |
| 546 |
|
| 547 |
/** |
| 548 |
* Load reset option table html |
| 549 |
* |
| 550 |
* @return string |
| 551 |
*/ |
| 552 |
public static function setting_reset_html_table() { |
| 553 |
$option_values = self::getAllOptionNames(); |
| 554 |
|
| 555 |
$table_html = '<p style="margin-bottom: 10px;" class="grouped gapless grouped_buttons" id="cbxgooglemap_setting_options_check_actions"><a href="#" class="button primary cbxgooglemap_setting_options_check_action_call">' . esc_html__( 'Check All', |
| 556 |
'cbxgooglemap' ) . '</a><a href="#" class="button outline cbxgooglemap_setting_options_check_action_ucall">' . esc_html__( 'Uncheck All', |
| 557 |
'cbxgooglemap' ) . '</a></p>'; |
| 558 |
$table_html .= '<table class="widefat widethin cbxgooglemap_table_data" id="cbxgooglemap_setting_options_table"> |
| 559 |
<thead> |
| 560 |
<tr> |
| 561 |
<th class="row-title">' . esc_attr__( 'Option Name', 'cbxgooglemap' ) . '</th> |
| 562 |
<th>' . esc_attr__( 'Option ID', 'cbxgooglemap' ) . '</th> |
| 563 |
</tr> |
| 564 |
</thead>'; |
| 565 |
|
| 566 |
$table_html .= '<tbody>'; |
| 567 |
|
| 568 |
$i = 0; |
| 569 |
foreach ( $option_values as $key => $value ) { |
| 570 |
$alternate_class = ( $i % 2 == 0 ) ? 'alternate' : ''; |
| 571 |
$i ++; |
| 572 |
$table_html .= '<tr class="' . esc_attr( $alternate_class ) . '"> |
| 573 |
<td class="row-title"><input checked class="magic-checkbox reset_options" type="checkbox" name="reset_options[' . $value['option_name'] . ']" id="reset_options_' . esc_attr( $value['option_name'] ) . '" value="' . $value['option_name'] . '" /> |
| 574 |
<label for="reset_options_' . esc_attr( $value['option_name'] ) . '">' . esc_attr( $value['option_name'] ) . '</td> |
| 575 |
<td>' . esc_attr( $value['option_id'] ) . '</td> |
| 576 |
</tr>'; |
| 577 |
} |
| 578 |
|
| 579 |
$table_html .= '</tbody>'; |
| 580 |
$table_html .= '<tfoot> |
| 581 |
<tr> |
| 582 |
<th class="row-title">' . esc_attr__( 'Option Name', 'cbxgooglemap' ) . '</th> |
| 583 |
<th>' . esc_attr__( 'Option ID', 'cbxgooglemap' ) . '</th> |
| 584 |
</tr> |
| 585 |
</tfoot> |
| 586 |
</table>'; |
| 587 |
|
| 588 |
return $table_html; |
| 589 |
} //end method setting_reset_html_table |
| 590 |
|
| 591 |
/** |
| 592 |
* List all global option name with prefix cbxgooglemap_ |
| 593 |
* @since 1.0.0 |
| 594 |
*/ |
| 595 |
public static function getAllOptionNames() { |
| 596 |
global $wpdb; |
| 597 |
|
| 598 |
$prefix = 'cbxgooglemap_'; |
| 599 |
|
| 600 |
$wild = '%'; |
| 601 |
$like = $wpdb->esc_like( $prefix ) . $wild; |
| 602 |
|
| 603 |
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQL.InterpolatedNotPrepared |
| 604 |
$option_names = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->options} WHERE option_name LIKE %s", $like ), ARRAY_A ); |
| 605 |
|
| 606 |
return apply_filters( 'cbxgooglemap_option_names', $option_names ); |
| 607 |
}//end method getAllOptionNames |
| 608 |
|
| 609 |
/** |
| 610 |
* Get any plugin version number |
| 611 |
* |
| 612 |
* @param $plugin_slug |
| 613 |
* |
| 614 |
* @return mixed|string |
| 615 |
* @since 2.0.0 |
| 616 |
*/ |
| 617 |
public static function get_any_plugin_version( $plugin_slug = '' ) { |
| 618 |
if ( $plugin_slug == '' ) { |
| 619 |
return ''; |
| 620 |
} |
| 621 |
|
| 622 |
// Ensure the required file is loaded |
| 623 |
if ( ! function_exists( 'get_plugins' ) ) { |
| 624 |
require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
| 625 |
} |
| 626 |
|
| 627 |
// Get all installed plugins |
| 628 |
$all_plugins = get_plugins(); |
| 629 |
|
| 630 |
// Check if the plugin exists |
| 631 |
if ( isset( $all_plugins[ $plugin_slug ] ) ) { |
| 632 |
return $all_plugins[ $plugin_slug ]['Version']; |
| 633 |
} |
| 634 |
|
| 635 |
// Return false if the plugin is not found |
| 636 |
return ''; |
| 637 |
}//end method get_pro_addon_version |
| 638 |
}//end class CBXGooglemapHelper |