PluginProbe
Cool Timeline (Horizontal & Vertical Timeline) / trunk
Cool Timeline (Horizontal & Vertical Timeline) vtrunk
3.4.0 3.3.6 3.3.5 3.3.4 3.3.3 3.3.2 2.2.3 2.3.3 2.4 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.6.1 2.7.1 2.8.3 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 2.9.8 2.9.9 3.0.0 All 79 releases
cool-timeline / admin / codestar-framework / fields / map / map.php

map.php in Cool Timeline (Horizontal & Vertical Timeline) trunk, at admin/codestar-framework/fields/map/map.php

102 lines 3.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
2 // phpcs:ignoreFile WordPress.Security.EscapeOutput.OutputNotEscaped
3 /**
4 *
5 * Field: map
6 *
7 * @since 1.0.0
8 * @version 1.0.0
9 *
10 */
11 if ( ! class_exists( 'CSF_Field_map' ) ) {
12 class CSF_Field_map extends CSF_Fields {
13
14 public $version = '1.7.1';
15 public $cdn_url = 'https://cdn.jsdelivr.net/npm/leaflet@';
16
17 public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
18 parent::__construct( $field, $value, $unique, $where, $parent );
19 }
20
21 public function render() {
22
23 // phpcs:disable WordPress.WP.I18n.TextDomainMismatch
24 $args = wp_parse_args( $this->field, array(
25 'placeholder' => esc_html__( 'Search...', 'csf' ),
26 'latitude_text' => esc_html__( 'Latitude', 'csf' ),
27 'longitude_text' => esc_html__( 'Longitude', 'csf' ),
28 'address_field' => '',
29 'height' => '',
30 ) );
31 // phpcs:enable WordPress.WP.I18n.TextDomainMismatch
32
33 $value = wp_parse_args( $this->value, array(
34 'address' => '',
35 'latitude' => '20',
36 'longitude' => '0',
37 'zoom' => '2',
38 ) );
39
40 $default_settings = array(
41 'center' => array( $value['latitude'], $value['longitude'] ),
42 'zoom' => $value['zoom'],
43 'scrollWheelZoom' => false,
44 );
45
46 $settings = ( ! empty( $this->field['settings'] ) ) ? $this->field['settings'] : array();
47 $settings = wp_parse_args( $settings, $default_settings );
48
49 $style_attr = ( ! empty( $args['height'] ) ) ? ' style="min-height:'. esc_attr( $args['height'] ) .';"' : '';
50 $placeholder = ( ! empty( $args['placeholder'] ) ) ? array( 'placeholder' => $args['placeholder'] ) : '';
51
52 echo $this->field_before();
53
54 if ( empty( $args['address_field'] ) ) {
55 echo '<div class="csf--map-search">';
56 echo '<input type="text" name="'. esc_attr( $this->field_name( '[address]' ) ) .'" value="'. esc_attr( $value['address'] ) .'"'. $this->field_attributes( $placeholder ) .' />';
57 echo '</div>';
58 } else {
59 echo '<div class="csf--address-field" data-address-field="'. esc_attr( $args['address_field'] ) .'"></div>';
60 }
61
62 echo '<div class="csf--map-osm-wrap"><div class="csf--map-osm" data-map="'. esc_attr( json_encode( $settings ) ) .'"'. $style_attr .'></div></div>';
63
64 echo '<div class="csf--map-inputs">';
65
66 echo '<div class="csf--map-input">';
67 echo '<label>'. esc_attr( $args['latitude_text'] ) .'</label>';
68 echo '<input type="text" name="'. esc_attr( $this->field_name( '[latitude]' ) ) .'" value="'. esc_attr( $value['latitude'] ) .'" class="csf--latitude" />';
69 echo '</div>';
70
71 echo '<div class="csf--map-input">';
72 echo '<label>'. esc_attr( $args['longitude_text'] ) .'</label>';
73 echo '<input type="text" name="'. esc_attr( $this->field_name( '[longitude]' ) ) .'" value="'. esc_attr( $value['longitude'] ) .'" class="csf--longitude" />';
74 echo '</div>';
75
76 echo '</div>';
77
78 echo '<input type="hidden" name="'. esc_attr( $this->field_name( '[zoom]' ) ) .'" value="'. esc_attr( $value['zoom'] ) .'" class="csf--zoom" />';
79
80 echo $this->field_after();
81
82 }
83
84 public function enqueue() {
85
86 if ( ! wp_script_is( 'csf-leaflet' ) ) {
87 wp_enqueue_script( 'csf-leaflet', esc_url( $this->cdn_url . $this->version .'/dist/leaflet.js' ), array( 'csf' ), $this->version, true );
88 }
89
90 if ( ! wp_style_is( 'csf-leaflet' ) ) {
91 wp_enqueue_style( 'csf-leaflet', esc_url( $this->cdn_url . $this->version .'/dist/leaflet.css' ), array(), $this->version );
92 }
93
94 if ( ! wp_script_is( 'jquery-ui-autocomplete' ) ) {
95 wp_enqueue_script( 'jquery-ui-autocomplete' );
96 }
97
98 }
99
100 }
101 }
102