@@ -10,95 +10,95 @@ |
||
| 10 | 10 | |
| 11 | 11 | class Link_Builder { |
| 12 | 12 | |
| 13 | - private $id; |
|
| 14 | - private $type; |
|
| 15 | - private $label; |
|
| 16 | - private $href; |
|
| 17 | - private $entity_url; |
|
| 18 | - /** |
|
| 19 | - * @var Object_Link_Provider |
|
| 20 | - */ |
|
| 21 | - private $object_link_provider; |
|
| 22 | - |
|
| 23 | - public function __construct( $entity_url, $id ) { |
|
| 24 | - $this->entity_url = $entity_url; |
|
| 25 | - $this->id = $id; |
|
| 26 | - $this->object_link_provider = Object_Link_Provider::get_instance(); |
|
| 27 | - $this->type = $this->object_link_provider->get_object_type( $entity_url ); |
|
| 28 | - } |
|
| 29 | - |
|
| 30 | - public static function create( $entity_url, $id ) { |
|
| 31 | - return new Link_Builder( $entity_url, $id ); |
|
| 32 | - } |
|
| 33 | - |
|
| 34 | - public function label( $label ) { |
|
| 35 | - $this->label = $label; |
|
| 36 | - |
|
| 37 | - return $this; |
|
| 38 | - } |
|
| 39 | - |
|
| 40 | - public function href( $href ) { |
|
| 41 | - $this->href = $href; |
|
| 42 | - |
|
| 43 | - return $this; |
|
| 44 | - } |
|
| 45 | - |
|
| 46 | - private function get_attributes_for_link() { |
|
| 47 | - /** |
|
| 48 | - * Allow 3rd parties to add additional attributes to the anchor link. |
|
| 49 | - * |
|
| 50 | - * @since 3.26.0 |
|
| 51 | - */ |
|
| 52 | - $default_attributes = array( |
|
| 53 | - 'id' => implode( ';', $this->object_link_provider->get_same_as_uris( $this->id, $this->type ) ) |
|
| 54 | - ); |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * @since 3.32.0 |
|
| 58 | - * Additional parameter {@link $this->type} is added to the filter denoting the type of |
|
| 59 | - * the entity url by the enum values {@link Object_Type_Enum} |
|
| 60 | - */ |
|
| 61 | - $attributes = apply_filters( 'wl_anchor_data_attributes', $default_attributes, $this->id, $this->type ); |
|
| 62 | - $attributes_html = ''; |
|
| 63 | - foreach ( $attributes as $key => $value ) { |
|
| 64 | - $attributes_html .= ' data-' . esc_html( $key ) . '="' . esc_attr( $value ) . '" '; |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - return $attributes_html; |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * Get a `title` attribute with an alternative label for the link. |
|
| 72 | - * |
|
| 73 | - * If an alternative title isn't available an empty string is returned. |
|
| 74 | - * |
|
| 75 | - * @return string A `title` attribute with an alternative label or an empty |
|
| 76 | - * string if none available. |
|
| 77 | - * @since 3.32.0 |
|
| 78 | - * |
|
| 79 | - */ |
|
| 80 | - private function get_title_attribute() { |
|
| 81 | - |
|
| 82 | - // Get an alternative title. |
|
| 83 | - $title = $this->object_link_provider->get_link_title( $this->id, $this->label, $this->type ); |
|
| 84 | - if ( ! empty( $title ) ) { |
|
| 85 | - return 'title="' . esc_attr( $title ) . '"'; |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - return ''; |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * @return string |
|
| 93 | - */ |
|
| 94 | - public function generate_link() { |
|
| 95 | - // Get an alternative title attribute. |
|
| 96 | - $title_attribute = $this->get_title_attribute(); |
|
| 97 | - $attributes_html = $this->get_attributes_for_link(); |
|
| 98 | - |
|
| 99 | - // Return the link. |
|
| 100 | - return "<a class=\"wl-entity-page-link\" $title_attribute href=\"{$this->href}\"$attributes_html>{$this->label}</a>"; |
|
| 101 | - } |
|
| 13 | + private $id; |
|
| 14 | + private $type; |
|
| 15 | + private $label; |
|
| 16 | + private $href; |
|
| 17 | + private $entity_url; |
|
| 18 | + /** |
|
| 19 | + * @var Object_Link_Provider |
|
| 20 | + */ |
|
| 21 | + private $object_link_provider; |
|
| 22 | + |
|
| 23 | + public function __construct( $entity_url, $id ) { |
|
| 24 | + $this->entity_url = $entity_url; |
|
| 25 | + $this->id = $id; |
|
| 26 | + $this->object_link_provider = Object_Link_Provider::get_instance(); |
|
| 27 | + $this->type = $this->object_link_provider->get_object_type( $entity_url ); |
|
| 28 | + } |
|
| 29 | + |
|
| 30 | + public static function create( $entity_url, $id ) { |
|
| 31 | + return new Link_Builder( $entity_url, $id ); |
|
| 32 | + } |
|
| 33 | + |
|
| 34 | + public function label( $label ) { |
|
| 35 | + $this->label = $label; |
|
| 36 | + |
|
| 37 | + return $this; |
|
| 38 | + } |
|
| 39 | + |
|
| 40 | + public function href( $href ) { |
|
| 41 | + $this->href = $href; |
|
| 42 | + |
|
| 43 | + return $this; |
|
| 44 | + } |
|
| 45 | + |
|
| 46 | + private function get_attributes_for_link() { |
|
| 47 | + /** |
|
| 48 | + * Allow 3rd parties to add additional attributes to the anchor link. |
|
| 49 | + * |
|
| 50 | + * @since 3.26.0 |
|
| 51 | + */ |
|
| 52 | + $default_attributes = array( |
|
| 53 | + 'id' => implode( ';', $this->object_link_provider->get_same_as_uris( $this->id, $this->type ) ) |
|
| 54 | + ); |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * @since 3.32.0 |
|
| 58 | + * Additional parameter {@link $this->type} is added to the filter denoting the type of |
|
| 59 | + * the entity url by the enum values {@link Object_Type_Enum} |
|
| 60 | + */ |
|
| 61 | + $attributes = apply_filters( 'wl_anchor_data_attributes', $default_attributes, $this->id, $this->type ); |
|
| 62 | + $attributes_html = ''; |
|
| 63 | + foreach ( $attributes as $key => $value ) { |
|
| 64 | + $attributes_html .= ' data-' . esc_html( $key ) . '="' . esc_attr( $value ) . '" '; |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + return $attributes_html; |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * Get a `title` attribute with an alternative label for the link. |
|
| 72 | + * |
|
| 73 | + * If an alternative title isn't available an empty string is returned. |
|
| 74 | + * |
|
| 75 | + * @return string A `title` attribute with an alternative label or an empty |
|
| 76 | + * string if none available. |
|
| 77 | + * @since 3.32.0 |
|
| 78 | + * |
|
| 79 | + */ |
|
| 80 | + private function get_title_attribute() { |
|
| 81 | + |
|
| 82 | + // Get an alternative title. |
|
| 83 | + $title = $this->object_link_provider->get_link_title( $this->id, $this->label, $this->type ); |
|
| 84 | + if ( ! empty( $title ) ) { |
|
| 85 | + return 'title="' . esc_attr( $title ) . '"'; |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + return ''; |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * @return string |
|
| 93 | + */ |
|
| 94 | + public function generate_link() { |
|
| 95 | + // Get an alternative title attribute. |
|
| 96 | + $title_attribute = $this->get_title_attribute(); |
|
| 97 | + $attributes_html = $this->get_attributes_for_link(); |
|
| 98 | + |
|
| 99 | + // Return the link. |
|
| 100 | + return "<a class=\"wl-entity-page-link\" $title_attribute href=\"{$this->href}\"$attributes_html>{$this->label}</a>"; |
|
| 101 | + } |
|
| 102 | 102 | |
| 103 | 103 | |
| 104 | 104 | } |
| 105 | 105 | \ No newline at end of file |
@@ -7,57 +7,57 @@ discard block |
||
| 7 | 7 | |
| 8 | 8 | class Wl_Metabox_Field_Coordinates extends Wl_Metabox_Field { |
| 9 | 9 | |
| 10 | - public function __construct( $args, $id, $type ) { |
|
| 11 | - |
|
| 12 | - // Just set up the necessary info without calling the parent constructor. |
|
| 13 | - // TODO: write a parent class for grouped properties |
|
| 14 | - parent::__construct( $args, $id, $type ); |
|
| 15 | - |
|
| 16 | - // we use 'coordinates' to namespace the Field in $_POST data. |
|
| 17 | - // In the DB the correct meta names will be used. |
|
| 18 | - $this->meta_name = 'coordinates'; |
|
| 19 | - } |
|
| 20 | - |
|
| 21 | - public function get_data() { |
|
| 22 | - $instance = Store_Factory::get_instance( $this->type ); |
|
| 23 | - $latitude = $instance::get_data( $this->id, Wordlift_Schema_Service::FIELD_GEO_LATITUDE ); |
|
| 24 | - $longitude = $instance::get_data( $this->id, Wordlift_Schema_Service::FIELD_GEO_LONGITUDE ); |
|
| 25 | - $this->data = array( |
|
| 26 | - 'latitude' => isset( $latitude[0] ) && is_numeric( $latitude[0] ) ? $latitude[0] : '', |
|
| 27 | - 'longitude' => isset( $longitude[0] ) && is_numeric( $longitude[0] ) ? $longitude[0] : '', |
|
| 28 | - ); |
|
| 29 | - } |
|
| 30 | - |
|
| 31 | - public function html() { |
|
| 32 | - |
|
| 33 | - // Open main <div> for the Field |
|
| 34 | - $html = $this->html_wrapper_open(); |
|
| 35 | - |
|
| 36 | - // Label |
|
| 37 | - $html .= '<h3>coordinates</h3>'; |
|
| 38 | - |
|
| 39 | - // print nonce |
|
| 40 | - $html .= $this->html_nonce(); |
|
| 41 | - |
|
| 42 | - // Get coordinates |
|
| 43 | - $data = $this->data; |
|
| 44 | - // TODO: We temporary use here 0,0 as default coordinates for the marker, but if no coordinates are given we |
|
| 45 | - // want to use the current user location for the marker. |
|
| 46 | - $coordinates = ( ! empty( $data['latitude'] ) && ! empty( $data['longitude'] ) ? sprintf( '[%f,%f]', $data['latitude'], $data['longitude'] ) : '[0,0]' ); |
|
| 47 | - $map_init = '[0,0]' === $coordinates |
|
| 48 | - ? 'locate( {setView: true, maxZoom: 16} )' |
|
| 49 | - : sprintf( "setView( [%f,%f], 9 )", $data['latitude'], $data['longitude'] ); |
|
| 50 | - |
|
| 51 | - // Print input fields |
|
| 52 | - $html .= '<label for="wl_place_lat">' . __( 'Latitude', 'wordlift' ) . '</label>'; |
|
| 53 | - $html .= '<input type="text" id="wl_place_lat" name="wl_metaboxes[coordinates][]" value="' . $data['latitude'] . '" style="width:100%" />'; |
|
| 54 | - |
|
| 55 | - $html .= '<label for="wl_place_lon">' . __( 'Longitude', 'wordlift' ) . '</label>'; |
|
| 56 | - $html .= '<input type="text" id="wl_place_lon" name="wl_metaboxes[coordinates][]" value="' . $data['longitude'] . '" style="width:100%" />'; |
|
| 57 | - |
|
| 58 | - // Show Leaflet map to pick coordinates |
|
| 59 | - $element_id = uniqid( 'wl-geo-map-' ); |
|
| 60 | - $html .= " |
|
| 10 | + public function __construct( $args, $id, $type ) { |
|
| 11 | + |
|
| 12 | + // Just set up the necessary info without calling the parent constructor. |
|
| 13 | + // TODO: write a parent class for grouped properties |
|
| 14 | + parent::__construct( $args, $id, $type ); |
|
| 15 | + |
|
| 16 | + // we use 'coordinates' to namespace the Field in $_POST data. |
|
| 17 | + // In the DB the correct meta names will be used. |
|
| 18 | + $this->meta_name = 'coordinates'; |
|
| 19 | + } |
|
| 20 | + |
|
| 21 | + public function get_data() { |
|
| 22 | + $instance = Store_Factory::get_instance( $this->type ); |
|
| 23 | + $latitude = $instance::get_data( $this->id, Wordlift_Schema_Service::FIELD_GEO_LATITUDE ); |
|
| 24 | + $longitude = $instance::get_data( $this->id, Wordlift_Schema_Service::FIELD_GEO_LONGITUDE ); |
|
| 25 | + $this->data = array( |
|
| 26 | + 'latitude' => isset( $latitude[0] ) && is_numeric( $latitude[0] ) ? $latitude[0] : '', |
|
| 27 | + 'longitude' => isset( $longitude[0] ) && is_numeric( $longitude[0] ) ? $longitude[0] : '', |
|
| 28 | + ); |
|
| 29 | + } |
|
| 30 | + |
|
| 31 | + public function html() { |
|
| 32 | + |
|
| 33 | + // Open main <div> for the Field |
|
| 34 | + $html = $this->html_wrapper_open(); |
|
| 35 | + |
|
| 36 | + // Label |
|
| 37 | + $html .= '<h3>coordinates</h3>'; |
|
| 38 | + |
|
| 39 | + // print nonce |
|
| 40 | + $html .= $this->html_nonce(); |
|
| 41 | + |
|
| 42 | + // Get coordinates |
|
| 43 | + $data = $this->data; |
|
| 44 | + // TODO: We temporary use here 0,0 as default coordinates for the marker, but if no coordinates are given we |
|
| 45 | + // want to use the current user location for the marker. |
|
| 46 | + $coordinates = ( ! empty( $data['latitude'] ) && ! empty( $data['longitude'] ) ? sprintf( '[%f,%f]', $data['latitude'], $data['longitude'] ) : '[0,0]' ); |
|
| 47 | + $map_init = '[0,0]' === $coordinates |
|
| 48 | + ? 'locate( {setView: true, maxZoom: 16} )' |
|
| 49 | + : sprintf( "setView( [%f,%f], 9 )", $data['latitude'], $data['longitude'] ); |
|
| 50 | + |
|
| 51 | + // Print input fields |
|
| 52 | + $html .= '<label for="wl_place_lat">' . __( 'Latitude', 'wordlift' ) . '</label>'; |
|
| 53 | + $html .= '<input type="text" id="wl_place_lat" name="wl_metaboxes[coordinates][]" value="' . $data['latitude'] . '" style="width:100%" />'; |
|
| 54 | + |
|
| 55 | + $html .= '<label for="wl_place_lon">' . __( 'Longitude', 'wordlift' ) . '</label>'; |
|
| 56 | + $html .= '<input type="text" id="wl_place_lon" name="wl_metaboxes[coordinates][]" value="' . $data['longitude'] . '" style="width:100%" />'; |
|
| 57 | + |
|
| 58 | + // Show Leaflet map to pick coordinates |
|
| 59 | + $element_id = uniqid( 'wl-geo-map-' ); |
|
| 60 | + $html .= " |
|
| 61 | 61 | <div id=\"$element_id\"></div> |
| 62 | 62 | |
| 63 | 63 | <script type=\"text/javascript\"> |
@@ -89,42 +89,42 @@ discard block |
||
| 89 | 89 | </script>"; |
| 90 | 90 | |
| 91 | 91 | |
| 92 | - $html .= $this->html_wrapper_close(); |
|
| 92 | + $html .= $this->html_wrapper_close(); |
|
| 93 | 93 | |
| 94 | - return $html; |
|
| 95 | - } |
|
| 94 | + return $html; |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | - public function save_data( $coords ) { |
|
| 97 | + public function save_data( $coords ) { |
|
| 98 | 98 | |
| 99 | - $data = $this->sanitize_data( $coords ); |
|
| 99 | + $data = $this->sanitize_data( $coords ); |
|
| 100 | 100 | |
| 101 | - $instance = Store_Factory::get_instance( $this->type ); |
|
| 102 | - // Take away old values |
|
| 103 | - $instance::delete_meta( $this->id, Wordlift_Schema_Service::FIELD_GEO_LATITUDE ); |
|
| 104 | - $instance::delete_meta( $this->id, Wordlift_Schema_Service::FIELD_GEO_LONGITUDE ); |
|
| 101 | + $instance = Store_Factory::get_instance( $this->type ); |
|
| 102 | + // Take away old values |
|
| 103 | + $instance::delete_meta( $this->id, Wordlift_Schema_Service::FIELD_GEO_LATITUDE ); |
|
| 104 | + $instance::delete_meta( $this->id, Wordlift_Schema_Service::FIELD_GEO_LONGITUDE ); |
|
| 105 | 105 | |
| 106 | - $latitude = $data[0]; |
|
| 107 | - $longitude = $data[1]; |
|
| 108 | - // insert new coordinate values |
|
| 109 | - if ( ! empty( $latitude ) && ! empty( $longitude ) ) { |
|
| 110 | - $instance::add_meta( $this->id, Wordlift_Schema_Service::FIELD_GEO_LATITUDE, $latitude, true ); |
|
| 111 | - $instance::add_meta( $this->id, Wordlift_Schema_Service::FIELD_GEO_LONGITUDE, $longitude, true ); |
|
| 112 | - } |
|
| 106 | + $latitude = $data[0]; |
|
| 107 | + $longitude = $data[1]; |
|
| 108 | + // insert new coordinate values |
|
| 109 | + if ( ! empty( $latitude ) && ! empty( $longitude ) ) { |
|
| 110 | + $instance::add_meta( $this->id, Wordlift_Schema_Service::FIELD_GEO_LATITUDE, $latitude, true ); |
|
| 111 | + $instance::add_meta( $this->id, Wordlift_Schema_Service::FIELD_GEO_LONGITUDE, $longitude, true ); |
|
| 112 | + } |
|
| 113 | 113 | |
| 114 | - } |
|
| 114 | + } |
|
| 115 | 115 | |
| 116 | - /** |
|
| 117 | - * Only accept float numbers |
|
| 118 | - */ |
|
| 119 | - public function sanitize_data_filter( $value ) { |
|
| 116 | + /** |
|
| 117 | + * Only accept float numbers |
|
| 118 | + */ |
|
| 119 | + public function sanitize_data_filter( $value ) { |
|
| 120 | 120 | |
| 121 | - // DO NOT set latitude/longitude to 0/0 as default values. It's a specific place on the globe: |
|
| 122 | - // "The zero/zero point of this system is located in the Gulf of Guinea about 625 km (390 mi) south of Tema, Ghana." |
|
| 123 | - if ( ! is_numeric( $value ) ) { |
|
| 124 | - return ''; |
|
| 125 | - } |
|
| 121 | + // DO NOT set latitude/longitude to 0/0 as default values. It's a specific place on the globe: |
|
| 122 | + // "The zero/zero point of this system is located in the Gulf of Guinea about 625 km (390 mi) south of Tema, Ghana." |
|
| 123 | + if ( ! is_numeric( $value ) ) { |
|
| 124 | + return ''; |
|
| 125 | + } |
|
| 126 | 126 | |
| 127 | - return $value; |
|
| 128 | - } |
|
| 127 | + return $value; |
|
| 128 | + } |
|
| 129 | 129 | } |
| 130 | 130 | |
@@ -7,11 +7,11 @@ discard block |
||
| 7 | 7 | |
| 8 | 8 | class Wl_Metabox_Field_Coordinates extends Wl_Metabox_Field { |
| 9 | 9 | |
| 10 | - public function __construct( $args, $id, $type ) { |
|
| 10 | + public function __construct($args, $id, $type) { |
|
| 11 | 11 | |
| 12 | 12 | // Just set up the necessary info without calling the parent constructor. |
| 13 | 13 | // TODO: write a parent class for grouped properties |
| 14 | - parent::__construct( $args, $id, $type ); |
|
| 14 | + parent::__construct($args, $id, $type); |
|
| 15 | 15 | |
| 16 | 16 | // we use 'coordinates' to namespace the Field in $_POST data. |
| 17 | 17 | // In the DB the correct meta names will be used. |
@@ -19,12 +19,12 @@ discard block |
||
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | public function get_data() { |
| 22 | - $instance = Store_Factory::get_instance( $this->type ); |
|
| 23 | - $latitude = $instance::get_data( $this->id, Wordlift_Schema_Service::FIELD_GEO_LATITUDE ); |
|
| 24 | - $longitude = $instance::get_data( $this->id, Wordlift_Schema_Service::FIELD_GEO_LONGITUDE ); |
|
| 22 | + $instance = Store_Factory::get_instance($this->type); |
|
| 23 | + $latitude = $instance::get_data($this->id, Wordlift_Schema_Service::FIELD_GEO_LATITUDE); |
|
| 24 | + $longitude = $instance::get_data($this->id, Wordlift_Schema_Service::FIELD_GEO_LONGITUDE); |
|
| 25 | 25 | $this->data = array( |
| 26 | - 'latitude' => isset( $latitude[0] ) && is_numeric( $latitude[0] ) ? $latitude[0] : '', |
|
| 27 | - 'longitude' => isset( $longitude[0] ) && is_numeric( $longitude[0] ) ? $longitude[0] : '', |
|
| 26 | + 'latitude' => isset($latitude[0]) && is_numeric($latitude[0]) ? $latitude[0] : '', |
|
| 27 | + 'longitude' => isset($longitude[0]) && is_numeric($longitude[0]) ? $longitude[0] : '', |
|
| 28 | 28 | ); |
| 29 | 29 | } |
| 30 | 30 | |
@@ -43,21 +43,21 @@ discard block |
||
| 43 | 43 | $data = $this->data; |
| 44 | 44 | // TODO: We temporary use here 0,0 as default coordinates for the marker, but if no coordinates are given we |
| 45 | 45 | // want to use the current user location for the marker. |
| 46 | - $coordinates = ( ! empty( $data['latitude'] ) && ! empty( $data['longitude'] ) ? sprintf( '[%f,%f]', $data['latitude'], $data['longitude'] ) : '[0,0]' ); |
|
| 46 | + $coordinates = ( ! empty($data['latitude']) && ! empty($data['longitude']) ? sprintf('[%f,%f]', $data['latitude'], $data['longitude']) : '[0,0]'); |
|
| 47 | 47 | $map_init = '[0,0]' === $coordinates |
| 48 | 48 | ? 'locate( {setView: true, maxZoom: 16} )' |
| 49 | - : sprintf( "setView( [%f,%f], 9 )", $data['latitude'], $data['longitude'] ); |
|
| 49 | + : sprintf("setView( [%f,%f], 9 )", $data['latitude'], $data['longitude']); |
|
| 50 | 50 | |
| 51 | 51 | // Print input fields |
| 52 | - $html .= '<label for="wl_place_lat">' . __( 'Latitude', 'wordlift' ) . '</label>'; |
|
| 53 | - $html .= '<input type="text" id="wl_place_lat" name="wl_metaboxes[coordinates][]" value="' . $data['latitude'] . '" style="width:100%" />'; |
|
| 52 | + $html .= '<label for="wl_place_lat">'.__('Latitude', 'wordlift').'</label>'; |
|
| 53 | + $html .= '<input type="text" id="wl_place_lat" name="wl_metaboxes[coordinates][]" value="'.$data['latitude'].'" style="width:100%" />'; |
|
| 54 | 54 | |
| 55 | - $html .= '<label for="wl_place_lon">' . __( 'Longitude', 'wordlift' ) . '</label>'; |
|
| 56 | - $html .= '<input type="text" id="wl_place_lon" name="wl_metaboxes[coordinates][]" value="' . $data['longitude'] . '" style="width:100%" />'; |
|
| 55 | + $html .= '<label for="wl_place_lon">'.__('Longitude', 'wordlift').'</label>'; |
|
| 56 | + $html .= '<input type="text" id="wl_place_lon" name="wl_metaboxes[coordinates][]" value="'.$data['longitude'].'" style="width:100%" />'; |
|
| 57 | 57 | |
| 58 | 58 | // Show Leaflet map to pick coordinates |
| 59 | - $element_id = uniqid( 'wl-geo-map-' ); |
|
| 60 | - $html .= " |
|
| 59 | + $element_id = uniqid('wl-geo-map-'); |
|
| 60 | + $html .= " |
|
| 61 | 61 | <div id=\"$element_id\"></div> |
| 62 | 62 | |
| 63 | 63 | <script type=\"text/javascript\"> |
@@ -94,21 +94,21 @@ discard block |
||
| 94 | 94 | return $html; |
| 95 | 95 | } |
| 96 | 96 | |
| 97 | - public function save_data( $coords ) { |
|
| 97 | + public function save_data($coords) { |
|
| 98 | 98 | |
| 99 | - $data = $this->sanitize_data( $coords ); |
|
| 99 | + $data = $this->sanitize_data($coords); |
|
| 100 | 100 | |
| 101 | - $instance = Store_Factory::get_instance( $this->type ); |
|
| 101 | + $instance = Store_Factory::get_instance($this->type); |
|
| 102 | 102 | // Take away old values |
| 103 | - $instance::delete_meta( $this->id, Wordlift_Schema_Service::FIELD_GEO_LATITUDE ); |
|
| 104 | - $instance::delete_meta( $this->id, Wordlift_Schema_Service::FIELD_GEO_LONGITUDE ); |
|
| 103 | + $instance::delete_meta($this->id, Wordlift_Schema_Service::FIELD_GEO_LATITUDE); |
|
| 104 | + $instance::delete_meta($this->id, Wordlift_Schema_Service::FIELD_GEO_LONGITUDE); |
|
| 105 | 105 | |
| 106 | 106 | $latitude = $data[0]; |
| 107 | 107 | $longitude = $data[1]; |
| 108 | 108 | // insert new coordinate values |
| 109 | - if ( ! empty( $latitude ) && ! empty( $longitude ) ) { |
|
| 110 | - $instance::add_meta( $this->id, Wordlift_Schema_Service::FIELD_GEO_LATITUDE, $latitude, true ); |
|
| 111 | - $instance::add_meta( $this->id, Wordlift_Schema_Service::FIELD_GEO_LONGITUDE, $longitude, true ); |
|
| 109 | + if ( ! empty($latitude) && ! empty($longitude)) { |
|
| 110 | + $instance::add_meta($this->id, Wordlift_Schema_Service::FIELD_GEO_LATITUDE, $latitude, true); |
|
| 111 | + $instance::add_meta($this->id, Wordlift_Schema_Service::FIELD_GEO_LONGITUDE, $longitude, true); |
|
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | } |
@@ -116,11 +116,11 @@ discard block |
||
| 116 | 116 | /** |
| 117 | 117 | * Only accept float numbers |
| 118 | 118 | */ |
| 119 | - public function sanitize_data_filter( $value ) { |
|
| 119 | + public function sanitize_data_filter($value) { |
|
| 120 | 120 | |
| 121 | 121 | // DO NOT set latitude/longitude to 0/0 as default values. It's a specific place on the globe: |
| 122 | 122 | // "The zero/zero point of this system is located in the Gulf of Guinea about 625 km (390 mi) south of Tema, Ghana." |
| 123 | - if ( ! is_numeric( $value ) ) { |
|
| 123 | + if ( ! is_numeric($value)) { |
|
| 124 | 124 | return ''; |
| 125 | 125 | } |
| 126 | 126 | |
@@ -9,38 +9,38 @@ |
||
| 9 | 9 | */ |
| 10 | 10 | class Term_Checklist { |
| 11 | 11 | |
| 12 | - /** |
|
| 13 | - * @param $input_name string The name of the input field assigned to checkbox. |
|
| 14 | - * @param $terms array<\WP_Term> |
|
| 15 | - * @param $selected_term_slugs array<string> The list of selected term slugs. |
|
| 16 | - * |
|
| 17 | - * @return string Html string to be rendered. |
|
| 18 | - */ |
|
| 19 | - public static function render( $input_name, $terms, $selected_term_slugs ) { |
|
| 12 | + /** |
|
| 13 | + * @param $input_name string The name of the input field assigned to checkbox. |
|
| 14 | + * @param $terms array<\WP_Term> |
|
| 15 | + * @param $selected_term_slugs array<string> The list of selected term slugs. |
|
| 16 | + * |
|
| 17 | + * @return string Html string to be rendered. |
|
| 18 | + */ |
|
| 19 | + public static function render( $input_name, $terms, $selected_term_slugs ) { |
|
| 20 | 20 | |
| 21 | 21 | |
| 22 | - $terms_html = ""; |
|
| 22 | + $terms_html = ""; |
|
| 23 | 23 | |
| 24 | - $input_name = esc_html( $input_name ); |
|
| 24 | + $input_name = esc_html( $input_name ); |
|
| 25 | 25 | |
| 26 | - foreach ( $terms as $term ) { |
|
| 26 | + foreach ( $terms as $term ) { |
|
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * @var $term \WP_Term |
|
| 30 | - */ |
|
| 31 | - $term_name = esc_html( $term->name ); |
|
| 32 | - $checked = in_array( $term->slug, $selected_term_slugs ) ? 'checked' : ''; |
|
| 33 | - $terms_html .= "<li id=\"wl_entity_type-{$term->term_id}\"> |
|
| 28 | + /** |
|
| 29 | + * @var $term \WP_Term |
|
| 30 | + */ |
|
| 31 | + $term_name = esc_html( $term->name ); |
|
| 32 | + $checked = in_array( $term->slug, $selected_term_slugs ) ? 'checked' : ''; |
|
| 33 | + $terms_html .= "<li id=\"wl_entity_type-{$term->term_id}\"> |
|
| 34 | 34 | <label class=\"selectit\"> |
| 35 | 35 | <input value=\"{$term->slug}\" type=\"checkbox\" name=\"{$input_name}[]\" id=\"in-wl_entity_type-{$term->term_id}\" $checked> |
| 36 | 36 | ${term_name} |
| 37 | 37 | </label> |
| 38 | 38 | </li>"; |
| 39 | 39 | |
| 40 | - } |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - return '<input type="text" id="wl_entity_type_search" placeholder="Search Entity Types.." /><ul id="wl-entity-type__ul">' . $terms_html . '</ul>'; |
|
| 43 | - } |
|
| 42 | + return '<input type="text" id="wl_entity_type_search" placeholder="Search Entity Types.." /><ul id="wl-entity-type__ul">' . $terms_html . '</ul>'; |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | 45 | |
| 46 | 46 | } |
@@ -16,20 +16,20 @@ discard block |
||
| 16 | 16 | * |
| 17 | 17 | * @return string Html string to be rendered. |
| 18 | 18 | */ |
| 19 | - public static function render( $input_name, $terms, $selected_term_slugs ) { |
|
| 19 | + public static function render($input_name, $terms, $selected_term_slugs) { |
|
| 20 | 20 | |
| 21 | 21 | |
| 22 | 22 | $terms_html = ""; |
| 23 | 23 | |
| 24 | - $input_name = esc_html( $input_name ); |
|
| 24 | + $input_name = esc_html($input_name); |
|
| 25 | 25 | |
| 26 | - foreach ( $terms as $term ) { |
|
| 26 | + foreach ($terms as $term) { |
|
| 27 | 27 | |
| 28 | 28 | /** |
| 29 | 29 | * @var $term \WP_Term |
| 30 | 30 | */ |
| 31 | - $term_name = esc_html( $term->name ); |
|
| 32 | - $checked = in_array( $term->slug, $selected_term_slugs ) ? 'checked' : ''; |
|
| 31 | + $term_name = esc_html($term->name); |
|
| 32 | + $checked = in_array($term->slug, $selected_term_slugs) ? 'checked' : ''; |
|
| 33 | 33 | $terms_html .= "<li id=\"wl_entity_type-{$term->term_id}\"> |
| 34 | 34 | <label class=\"selectit\"> |
| 35 | 35 | <input value=\"{$term->slug}\" type=\"checkbox\" name=\"{$input_name}[]\" id=\"in-wl_entity_type-{$term->term_id}\" $checked> |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | - return '<input type="text" id="wl_entity_type_search" placeholder="Search Entity Types.." /><ul id="wl-entity-type__ul">' . $terms_html . '</ul>'; |
|
| 42 | + return '<input type="text" id="wl_entity_type_search" placeholder="Search Entity Types.." /><ul id="wl-entity-type__ul">'.$terms_html.'</ul>'; |
|
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | |