@@ -160,7 +160,6 @@ |
||
| 160 | 160 | * @uses wl_shortcode_geomap_get_places() in order to retrieve places |
| 161 | 161 | * @uses wl_shortcode_geomap_prepare_map() in order to encode retireved places in a Leaflet friendly format |
| 162 | 162 | * |
| 163 | - * @param array $places An array of place posts. |
|
| 164 | 163 | * |
| 165 | 164 | * @return array An array of place posts. |
| 166 | 165 | */ |
@@ -16,35 +16,35 @@ discard block |
||
| 16 | 16 | * |
| 17 | 17 | * @return array An array of place posts. |
| 18 | 18 | */ |
| 19 | -function wl_shortcode_geomap_get_places( $post_id = null ) { |
|
| 19 | +function wl_shortcode_geomap_get_places($post_id = null) { |
|
| 20 | 20 | |
| 21 | 21 | // If $post_id is null or is not numeric it means this is a global geomap |
| 22 | - $is_global = is_null( $post_id ) || ! is_numeric( $post_id ); |
|
| 22 | + $is_global = is_null($post_id) || ! is_numeric($post_id); |
|
| 23 | 23 | |
| 24 | 24 | // If the current one is not a global geomap, retrieve related entities ids |
| 25 | - if ( $is_global ) { |
|
| 25 | + if ($is_global) { |
|
| 26 | 26 | $related_ids = array(); |
| 27 | 27 | } else { |
| 28 | - $related_ids = wl_core_get_related_entity_ids( $post_id, array( |
|
| 28 | + $related_ids = wl_core_get_related_entity_ids($post_id, array( |
|
| 29 | 29 | 'status' => 'publish', |
| 30 | - ) ); |
|
| 30 | + )); |
|
| 31 | 31 | |
| 32 | 32 | // Also include current entity |
| 33 | - if ( Wordlift_Entity_Service::get_instance()->is_entity( $post_id ) ) { |
|
| 33 | + if (Wordlift_Entity_Service::get_instance()->is_entity($post_id)) { |
|
| 34 | 34 | $related_ids[] = $post_id; |
| 35 | 35 | } |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | // If is not a global geomap, an empty $related_ids means that no entities are related to the post |
| 39 | 39 | // An empty array can be returned in this case |
| 40 | - if ( ! $is_global && empty( $related_ids ) ) { |
|
| 40 | + if ( ! $is_global && empty($related_ids)) { |
|
| 41 | 41 | return array(); |
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | // Retrieve all 'published' places with geo coordinates defined |
| 45 | 45 | // If $related_ids is not empty, it's used to limit query results to the current post related places |
| 46 | 46 | // Please note that when $place_ids is an empty array, the 'post__in' parameter is not considered in the query |
| 47 | - return get_posts( array( |
|
| 47 | + return get_posts(array( |
|
| 48 | 48 | 'post__in' => $related_ids, |
| 49 | 49 | 'post_type' => Wordlift_Entity_Service::valid_entity_post_types(), |
| 50 | 50 | 'nopaging' => true, |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | 'terms' => 'place', |
| 70 | 70 | ), |
| 71 | 71 | ), |
| 72 | - ) ); |
|
| 72 | + )); |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | /** |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | * |
| 83 | 83 | * @return array An array of markers and boundaries for Leaflet. |
| 84 | 84 | */ |
| 85 | -function wl_shortcode_geomap_prepare_map( $places ) { |
|
| 85 | +function wl_shortcode_geomap_prepare_map($places) { |
|
| 86 | 86 | |
| 87 | 87 | // Prepare for min/max lat/long in case we need to define a view boundary for the client JavaScript. |
| 88 | 88 | $min_latitude = PHP_INT_MAX; |
@@ -97,13 +97,13 @@ discard block |
||
| 97 | 97 | $boundaries = array(); |
| 98 | 98 | |
| 99 | 99 | // Add a POI for each entity that has coordinates. |
| 100 | - foreach ( $places as $entity ) { |
|
| 100 | + foreach ($places as $entity) { |
|
| 101 | 101 | |
| 102 | 102 | // Get the coordinates. |
| 103 | - $coordinates = wl_get_coordinates( $entity->ID ); |
|
| 103 | + $coordinates = wl_get_coordinates($entity->ID); |
|
| 104 | 104 | |
| 105 | 105 | // Don't show the widget if the coordinates aren't set. |
| 106 | - if ( $coordinates['latitude'] == 0 || $coordinates['longitude'] == 0 ) { |
|
| 106 | + if ($coordinates['latitude'] == 0 || $coordinates['longitude'] == 0) { |
|
| 107 | 107 | continue; |
| 108 | 108 | } |
| 109 | 109 | |
@@ -111,38 +111,38 @@ discard block |
||
| 111 | 111 | // This function should be focused on returning pure data instead |
| 112 | 112 | |
| 113 | 113 | // Get the title, URL and thumb of the entity. |
| 114 | - $title = esc_attr( $entity->post_title ); |
|
| 115 | - $link = esc_attr( get_permalink( $entity->ID ) ); |
|
| 116 | - if ( '' !== ( $thumbnail_id = get_post_thumbnail_id( $entity->ID ) ) && |
|
| 117 | - false !== ( $attachment = wp_get_attachment_image_src( $thumbnail_id ) ) |
|
| 114 | + $title = esc_attr($entity->post_title); |
|
| 115 | + $link = esc_attr(get_permalink($entity->ID)); |
|
| 116 | + if ('' !== ($thumbnail_id = get_post_thumbnail_id($entity->ID)) && |
|
| 117 | + false !== ($attachment = wp_get_attachment_image_src($thumbnail_id)) |
|
| 118 | 118 | ) { |
| 119 | - $img_src = esc_attr( $attachment[0] ); |
|
| 119 | + $img_src = esc_attr($attachment[0]); |
|
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | // Build HTML popup. TODO: move thumb width in css |
| 123 | 123 | $content = "<a href=$link><h6>$title</h6>"; |
| 124 | - if ( isset( $img_src ) ) { |
|
| 125 | - $content = $content . "<img src=$img_src style='width:100%'/>"; |
|
| 124 | + if (isset($img_src)) { |
|
| 125 | + $content = $content."<img src=$img_src style='width:100%'/>"; |
|
| 126 | 126 | } |
| 127 | - $content = $content . "</a><ul>"; |
|
| 127 | + $content = $content."</a><ul>"; |
|
| 128 | 128 | // Get the related posts (published) and print them in the popup. |
| 129 | - $related_posts = wl_core_get_related_post_ids( $entity->ID, array( |
|
| 129 | + $related_posts = wl_core_get_related_post_ids($entity->ID, array( |
|
| 130 | 130 | 'status' => 'publish', |
| 131 | - ) ); |
|
| 132 | - foreach ( $related_posts as $rp_id ) { |
|
| 131 | + )); |
|
| 132 | + foreach ($related_posts as $rp_id) { |
|
| 133 | 133 | |
| 134 | - $rp = get_post( $rp_id ); |
|
| 135 | - $title = esc_attr( $rp->post_title ); |
|
| 136 | - $link = esc_attr( get_permalink( $rp->ID ) ); |
|
| 137 | - $content = $content . "<li><a href=$link>$title</a></li>"; |
|
| 134 | + $rp = get_post($rp_id); |
|
| 135 | + $title = esc_attr($rp->post_title); |
|
| 136 | + $link = esc_attr(get_permalink($rp->ID)); |
|
| 137 | + $content = $content."<li><a href=$link>$title</a></li>"; |
|
| 138 | 138 | } |
| 139 | - $content = $content . "</ul>"; |
|
| 139 | + $content = $content."</ul>"; |
|
| 140 | 140 | |
| 141 | 141 | // Formatting POI in geoJSON. |
| 142 | 142 | // http://leafletjs.com/examples/geojson.html |
| 143 | 143 | $poi = array( |
| 144 | 144 | 'type' => 'Feature', |
| 145 | - 'properties' => array( 'popupContent' => $content ), |
|
| 145 | + 'properties' => array('popupContent' => $content), |
|
| 146 | 146 | 'geometry' => array( |
| 147 | 147 | 'type' => 'Point', |
| 148 | 148 | 'coordinates' => array( |
@@ -183,16 +183,16 @@ discard block |
||
| 183 | 183 | */ |
| 184 | 184 | function wl_shortcode_geomap_ajax() { |
| 185 | 185 | // Get the post Id. |
| 186 | - $post_id = ( isset( $_REQUEST['post_id'] ) ? $_REQUEST['post_id'] : null ); |
|
| 186 | + $post_id = (isset($_REQUEST['post_id']) ? $_REQUEST['post_id'] : null); |
|
| 187 | 187 | |
| 188 | - $places = wl_shortcode_geomap_get_places( $post_id ); |
|
| 189 | - $map_data = wl_shortcode_geomap_prepare_map( $places ); |
|
| 188 | + $places = wl_shortcode_geomap_get_places($post_id); |
|
| 189 | + $map_data = wl_shortcode_geomap_prepare_map($places); |
|
| 190 | 190 | |
| 191 | - wl_core_send_json( $map_data ); |
|
| 191 | + wl_core_send_json($map_data); |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | -add_action( 'wp_ajax_wl_geomap', 'wl_shortcode_geomap_ajax' ); |
|
| 195 | -add_action( 'wp_ajax_nopriv_wl_geomap', 'wl_shortcode_geomap_ajax' ); |
|
| 194 | +add_action('wp_ajax_wl_geomap', 'wl_shortcode_geomap_ajax'); |
|
| 195 | +add_action('wp_ajax_nopriv_wl_geomap', 'wl_shortcode_geomap_ajax'); |
|
| 196 | 196 | |
| 197 | 197 | ///** |
| 198 | 198 | // * Print geomap shortcode |
@@ -18,58 +18,58 @@ discard block |
||
| 18 | 18 | */ |
| 19 | 19 | function wl_shortcode_geomap_get_places( $post_id = null ) { |
| 20 | 20 | |
| 21 | - // If $post_id is null or is not numeric it means this is a global geomap |
|
| 22 | - $is_global = is_null( $post_id ) || ! is_numeric( $post_id ); |
|
| 21 | + // If $post_id is null or is not numeric it means this is a global geomap |
|
| 22 | + $is_global = is_null( $post_id ) || ! is_numeric( $post_id ); |
|
| 23 | 23 | |
| 24 | - // If the current one is not a global geomap, retrieve related entities ids |
|
| 25 | - if ( $is_global ) { |
|
| 26 | - $related_ids = array(); |
|
| 27 | - } else { |
|
| 28 | - $related_ids = wl_core_get_related_entity_ids( $post_id, array( |
|
| 29 | - 'status' => 'publish', |
|
| 30 | - ) ); |
|
| 24 | + // If the current one is not a global geomap, retrieve related entities ids |
|
| 25 | + if ( $is_global ) { |
|
| 26 | + $related_ids = array(); |
|
| 27 | + } else { |
|
| 28 | + $related_ids = wl_core_get_related_entity_ids( $post_id, array( |
|
| 29 | + 'status' => 'publish', |
|
| 30 | + ) ); |
|
| 31 | 31 | |
| 32 | - // Also include current entity |
|
| 33 | - if ( Wordlift_Entity_Service::get_instance()->is_entity( $post_id ) ) { |
|
| 34 | - $related_ids[] = $post_id; |
|
| 35 | - } |
|
| 36 | - } |
|
| 32 | + // Also include current entity |
|
| 33 | + if ( Wordlift_Entity_Service::get_instance()->is_entity( $post_id ) ) { |
|
| 34 | + $related_ids[] = $post_id; |
|
| 35 | + } |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | - // If is not a global geomap, an empty $related_ids means that no entities are related to the post |
|
| 39 | - // An empty array can be returned in this case |
|
| 40 | - if ( ! $is_global && empty( $related_ids ) ) { |
|
| 41 | - return array(); |
|
| 42 | - } |
|
| 38 | + // If is not a global geomap, an empty $related_ids means that no entities are related to the post |
|
| 39 | + // An empty array can be returned in this case |
|
| 40 | + if ( ! $is_global && empty( $related_ids ) ) { |
|
| 41 | + return array(); |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - // Retrieve all 'published' places with geo coordinates defined |
|
| 45 | - // If $related_ids is not empty, it's used to limit query results to the current post related places |
|
| 46 | - // Please note that when $place_ids is an empty array, the 'post__in' parameter is not considered in the query |
|
| 47 | - return get_posts( array( |
|
| 48 | - 'post__in' => $related_ids, |
|
| 49 | - 'post_type' => Wordlift_Entity_Service::valid_entity_post_types(), |
|
| 50 | - 'nopaging' => true, |
|
| 51 | - 'post_status' => 'publish', |
|
| 52 | - 'meta_query' => array( |
|
| 53 | - 'relation' => 'AND', |
|
| 54 | - array( |
|
| 55 | - 'key' => Wordlift_Schema_Service::FIELD_GEO_LATITUDE, |
|
| 56 | - 'value' => null, |
|
| 57 | - 'compare' => '!=', |
|
| 58 | - ), |
|
| 59 | - array( |
|
| 60 | - 'key' => Wordlift_Schema_Service::FIELD_GEO_LONGITUDE, |
|
| 61 | - 'value' => null, |
|
| 62 | - 'compare' => '!=', |
|
| 63 | - ), |
|
| 64 | - ), |
|
| 65 | - 'tax_query' => array( |
|
| 66 | - array( |
|
| 67 | - 'taxonomy' => Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, |
|
| 68 | - 'field' => 'slug', |
|
| 69 | - 'terms' => 'place', |
|
| 70 | - ), |
|
| 71 | - ), |
|
| 72 | - ) ); |
|
| 44 | + // Retrieve all 'published' places with geo coordinates defined |
|
| 45 | + // If $related_ids is not empty, it's used to limit query results to the current post related places |
|
| 46 | + // Please note that when $place_ids is an empty array, the 'post__in' parameter is not considered in the query |
|
| 47 | + return get_posts( array( |
|
| 48 | + 'post__in' => $related_ids, |
|
| 49 | + 'post_type' => Wordlift_Entity_Service::valid_entity_post_types(), |
|
| 50 | + 'nopaging' => true, |
|
| 51 | + 'post_status' => 'publish', |
|
| 52 | + 'meta_query' => array( |
|
| 53 | + 'relation' => 'AND', |
|
| 54 | + array( |
|
| 55 | + 'key' => Wordlift_Schema_Service::FIELD_GEO_LATITUDE, |
|
| 56 | + 'value' => null, |
|
| 57 | + 'compare' => '!=', |
|
| 58 | + ), |
|
| 59 | + array( |
|
| 60 | + 'key' => Wordlift_Schema_Service::FIELD_GEO_LONGITUDE, |
|
| 61 | + 'value' => null, |
|
| 62 | + 'compare' => '!=', |
|
| 63 | + ), |
|
| 64 | + ), |
|
| 65 | + 'tax_query' => array( |
|
| 66 | + array( |
|
| 67 | + 'taxonomy' => Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, |
|
| 68 | + 'field' => 'slug', |
|
| 69 | + 'terms' => 'place', |
|
| 70 | + ), |
|
| 71 | + ), |
|
| 72 | + ) ); |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | /** |
@@ -84,91 +84,91 @@ discard block |
||
| 84 | 84 | */ |
| 85 | 85 | function wl_shortcode_geomap_prepare_map( $places ) { |
| 86 | 86 | |
| 87 | - // Prepare for min/max lat/long in case we need to define a view boundary for the client JavaScript. |
|
| 88 | - $min_latitude = PHP_INT_MAX; |
|
| 89 | - $min_longitude = PHP_INT_MAX; |
|
| 90 | - $max_latitude = ~PHP_INT_MAX; |
|
| 91 | - $max_longitude = ~PHP_INT_MAX; |
|
| 87 | + // Prepare for min/max lat/long in case we need to define a view boundary for the client JavaScript. |
|
| 88 | + $min_latitude = PHP_INT_MAX; |
|
| 89 | + $min_longitude = PHP_INT_MAX; |
|
| 90 | + $max_latitude = ~PHP_INT_MAX; |
|
| 91 | + $max_longitude = ~PHP_INT_MAX; |
|
| 92 | 92 | |
| 93 | - // Prepare an empty array of POIs in geoJSON format. |
|
| 94 | - $pois = array(); |
|
| 95 | - // And store list of points to allow Leaflet compute the optimal bounding box. |
|
| 96 | - // The main reason for this is that geoJSON has swapped coordinates (lon. lat) |
|
| 97 | - $boundaries = array(); |
|
| 93 | + // Prepare an empty array of POIs in geoJSON format. |
|
| 94 | + $pois = array(); |
|
| 95 | + // And store list of points to allow Leaflet compute the optimal bounding box. |
|
| 96 | + // The main reason for this is that geoJSON has swapped coordinates (lon. lat) |
|
| 97 | + $boundaries = array(); |
|
| 98 | 98 | |
| 99 | - // Add a POI for each entity that has coordinates. |
|
| 100 | - foreach ( $places as $entity ) { |
|
| 99 | + // Add a POI for each entity that has coordinates. |
|
| 100 | + foreach ( $places as $entity ) { |
|
| 101 | 101 | |
| 102 | - // Get the coordinates. |
|
| 103 | - $coordinates = wl_get_coordinates( $entity->ID ); |
|
| 102 | + // Get the coordinates. |
|
| 103 | + $coordinates = wl_get_coordinates( $entity->ID ); |
|
| 104 | 104 | |
| 105 | - // Don't show the widget if the coordinates aren't set. |
|
| 106 | - if ( $coordinates['latitude'] == 0 || $coordinates['longitude'] == 0 ) { |
|
| 107 | - continue; |
|
| 108 | - } |
|
| 105 | + // Don't show the widget if the coordinates aren't set. |
|
| 106 | + if ( $coordinates['latitude'] == 0 || $coordinates['longitude'] == 0 ) { |
|
| 107 | + continue; |
|
| 108 | + } |
|
| 109 | 109 | |
| 110 | - // TODO Map html rendering should be delegated to the wordlift js ui layer |
|
| 111 | - // This function should be focused on returning pure data instead |
|
| 110 | + // TODO Map html rendering should be delegated to the wordlift js ui layer |
|
| 111 | + // This function should be focused on returning pure data instead |
|
| 112 | 112 | |
| 113 | - // Get the title, URL and thumb of the entity. |
|
| 114 | - $title = esc_attr( $entity->post_title ); |
|
| 115 | - $link = esc_attr( get_permalink( $entity->ID ) ); |
|
| 116 | - if ( '' !== ( $thumbnail_id = get_post_thumbnail_id( $entity->ID ) ) && |
|
| 117 | - false !== ( $attachment = wp_get_attachment_image_src( $thumbnail_id ) ) |
|
| 118 | - ) { |
|
| 119 | - $img_src = esc_attr( $attachment[0] ); |
|
| 120 | - } |
|
| 113 | + // Get the title, URL and thumb of the entity. |
|
| 114 | + $title = esc_attr( $entity->post_title ); |
|
| 115 | + $link = esc_attr( get_permalink( $entity->ID ) ); |
|
| 116 | + if ( '' !== ( $thumbnail_id = get_post_thumbnail_id( $entity->ID ) ) && |
|
| 117 | + false !== ( $attachment = wp_get_attachment_image_src( $thumbnail_id ) ) |
|
| 118 | + ) { |
|
| 119 | + $img_src = esc_attr( $attachment[0] ); |
|
| 120 | + } |
|
| 121 | 121 | |
| 122 | - // Build HTML popup. TODO: move thumb width in css |
|
| 123 | - $content = "<a href=$link><h6>$title</h6>"; |
|
| 124 | - if ( isset( $img_src ) ) { |
|
| 125 | - $content = $content . "<img src=$img_src style='width:100%'/>"; |
|
| 126 | - } |
|
| 127 | - $content = $content . "</a><ul>"; |
|
| 128 | - // Get the related posts (published) and print them in the popup. |
|
| 129 | - $related_posts = wl_core_get_related_post_ids( $entity->ID, array( |
|
| 130 | - 'status' => 'publish', |
|
| 131 | - ) ); |
|
| 132 | - foreach ( $related_posts as $rp_id ) { |
|
| 122 | + // Build HTML popup. TODO: move thumb width in css |
|
| 123 | + $content = "<a href=$link><h6>$title</h6>"; |
|
| 124 | + if ( isset( $img_src ) ) { |
|
| 125 | + $content = $content . "<img src=$img_src style='width:100%'/>"; |
|
| 126 | + } |
|
| 127 | + $content = $content . "</a><ul>"; |
|
| 128 | + // Get the related posts (published) and print them in the popup. |
|
| 129 | + $related_posts = wl_core_get_related_post_ids( $entity->ID, array( |
|
| 130 | + 'status' => 'publish', |
|
| 131 | + ) ); |
|
| 132 | + foreach ( $related_posts as $rp_id ) { |
|
| 133 | 133 | |
| 134 | - $rp = get_post( $rp_id ); |
|
| 135 | - $title = esc_attr( $rp->post_title ); |
|
| 136 | - $link = esc_attr( get_permalink( $rp->ID ) ); |
|
| 137 | - $content = $content . "<li><a href=$link>$title</a></li>"; |
|
| 138 | - } |
|
| 139 | - $content = $content . "</ul>"; |
|
| 134 | + $rp = get_post( $rp_id ); |
|
| 135 | + $title = esc_attr( $rp->post_title ); |
|
| 136 | + $link = esc_attr( get_permalink( $rp->ID ) ); |
|
| 137 | + $content = $content . "<li><a href=$link>$title</a></li>"; |
|
| 138 | + } |
|
| 139 | + $content = $content . "</ul>"; |
|
| 140 | 140 | |
| 141 | - // Formatting POI in geoJSON. |
|
| 142 | - // http://leafletjs.com/examples/geojson.html |
|
| 143 | - $poi = array( |
|
| 144 | - 'type' => 'Feature', |
|
| 145 | - 'properties' => array( 'popupContent' => $content ), |
|
| 146 | - 'geometry' => array( |
|
| 147 | - 'type' => 'Point', |
|
| 148 | - 'coordinates' => array( |
|
| 149 | - // Leaflet geoJSON wants them swapped |
|
| 150 | - $coordinates['longitude'], |
|
| 151 | - $coordinates['latitude'], |
|
| 152 | - ), |
|
| 153 | - ), |
|
| 154 | - ); |
|
| 141 | + // Formatting POI in geoJSON. |
|
| 142 | + // http://leafletjs.com/examples/geojson.html |
|
| 143 | + $poi = array( |
|
| 144 | + 'type' => 'Feature', |
|
| 145 | + 'properties' => array( 'popupContent' => $content ), |
|
| 146 | + 'geometry' => array( |
|
| 147 | + 'type' => 'Point', |
|
| 148 | + 'coordinates' => array( |
|
| 149 | + // Leaflet geoJSON wants them swapped |
|
| 150 | + $coordinates['longitude'], |
|
| 151 | + $coordinates['latitude'], |
|
| 152 | + ), |
|
| 153 | + ), |
|
| 154 | + ); |
|
| 155 | 155 | |
| 156 | - $pois[] = $poi; |
|
| 156 | + $pois[] = $poi; |
|
| 157 | 157 | |
| 158 | - // Formatting boundaries in a Leaflet-like format (see LatLngBounds). |
|
| 159 | - // http://leafletjs.com/reference.html#latlngbounds |
|
| 160 | - $boundaries[] = array( |
|
| 161 | - $coordinates['latitude'], |
|
| 162 | - $coordinates['longitude'], |
|
| 163 | - ); |
|
| 158 | + // Formatting boundaries in a Leaflet-like format (see LatLngBounds). |
|
| 159 | + // http://leafletjs.com/reference.html#latlngbounds |
|
| 160 | + $boundaries[] = array( |
|
| 161 | + $coordinates['latitude'], |
|
| 162 | + $coordinates['longitude'], |
|
| 163 | + ); |
|
| 164 | 164 | |
| 165 | - } |
|
| 165 | + } |
|
| 166 | 166 | |
| 167 | - $map_data = array(); |
|
| 168 | - $map_data['features'] = $pois; |
|
| 169 | - $map_data['boundaries'] = $boundaries; |
|
| 167 | + $map_data = array(); |
|
| 168 | + $map_data['features'] = $pois; |
|
| 169 | + $map_data['boundaries'] = $boundaries; |
|
| 170 | 170 | |
| 171 | - return $map_data; |
|
| 171 | + return $map_data; |
|
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | /** |
@@ -182,13 +182,13 @@ discard block |
||
| 182 | 182 | * @return array An array of place posts. |
| 183 | 183 | */ |
| 184 | 184 | function wl_shortcode_geomap_ajax() { |
| 185 | - // Get the post Id. |
|
| 186 | - $post_id = ( isset( $_REQUEST['post_id'] ) ? $_REQUEST['post_id'] : null ); |
|
| 185 | + // Get the post Id. |
|
| 186 | + $post_id = ( isset( $_REQUEST['post_id'] ) ? $_REQUEST['post_id'] : null ); |
|
| 187 | 187 | |
| 188 | - $places = wl_shortcode_geomap_get_places( $post_id ); |
|
| 189 | - $map_data = wl_shortcode_geomap_prepare_map( $places ); |
|
| 188 | + $places = wl_shortcode_geomap_get_places( $post_id ); |
|
| 189 | + $map_data = wl_shortcode_geomap_prepare_map( $places ); |
|
| 190 | 190 | |
| 191 | - wl_core_send_json( $map_data ); |
|
| 191 | + wl_core_send_json( $map_data ); |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | add_action( 'wp_ajax_wl_geomap', 'wl_shortcode_geomap_ajax' ); |
@@ -3,7 +3,7 @@ discard block |
||
| 3 | 3 | |
| 4 | 4 | class WL_Metabox_Field_coordinates extends WL_Metabox_Field { |
| 5 | 5 | |
| 6 | - public function __construct( $args ) { |
|
| 6 | + public function __construct($args) { |
|
| 7 | 7 | |
| 8 | 8 | // Just set up the necessary info without calling the parent constructor. |
| 9 | 9 | // TODO: write a parent class for grouped properties |
@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | |
| 16 | 16 | public function get_data() { |
| 17 | 17 | $entity_id = get_the_ID(); |
| 18 | - $this->data = wl_get_coordinates( $entity_id ); |
|
| 18 | + $this->data = wl_get_coordinates($entity_id); |
|
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | public function html() { |
@@ -33,20 +33,20 @@ discard block |
||
| 33 | 33 | $data = $this->data; |
| 34 | 34 | // TODO: We temporary use here 0,0 as default coordinates for the marker, but if no coordinates are given we |
| 35 | 35 | // want to use the current user location for the marker. |
| 36 | - $coordinates = ( ! empty( $data['latitude'] ) && ! empty( $data['longitude'] ) ? sprintf( '[%f,%f]', $data['latitude'], $data['longitude'] ) : '[0,0]' ); |
|
| 36 | + $coordinates = ( ! empty($data['latitude']) && ! empty($data['longitude']) ? sprintf('[%f,%f]', $data['latitude'], $data['longitude']) : '[0,0]'); |
|
| 37 | 37 | $map_init = '[0,0]' === $coordinates |
| 38 | 38 | ? 'locate( {setView: true, maxZoom: 16} )' |
| 39 | - : sprintf( "setView( [%f,%f], 9 )", $data['latitude'], $data['longitude'] ); |
|
| 39 | + : sprintf("setView( [%f,%f], 9 )", $data['latitude'], $data['longitude']); |
|
| 40 | 40 | |
| 41 | 41 | // Print input fields |
| 42 | - $html .= '<label for="wl_place_lat">' . __( 'Latitude', 'wordlift' ) . '</label>'; |
|
| 43 | - $html .= '<input type="text" id="wl_place_lat" name="wl_metaboxes[coordinates][]" value="' . $data['latitude'] . '" style="width:100%" />'; |
|
| 42 | + $html .= '<label for="wl_place_lat">'.__('Latitude', 'wordlift').'</label>'; |
|
| 43 | + $html .= '<input type="text" id="wl_place_lat" name="wl_metaboxes[coordinates][]" value="'.$data['latitude'].'" style="width:100%" />'; |
|
| 44 | 44 | |
| 45 | - $html .= '<label for="wl_place_lon">' . __( 'Longitude', 'wordlift' ) . '</label>'; |
|
| 46 | - $html .= '<input type="text" id="wl_place_lon" name="wl_metaboxes[coordinates][]" value="' . $data['longitude'] . '" style="width:100%" />'; |
|
| 45 | + $html .= '<label for="wl_place_lon">'.__('Longitude', 'wordlift').'</label>'; |
|
| 46 | + $html .= '<input type="text" id="wl_place_lon" name="wl_metaboxes[coordinates][]" value="'.$data['longitude'].'" style="width:100%" />'; |
|
| 47 | 47 | |
| 48 | 48 | // Show Leaflet map to pick coordinates |
| 49 | - $element_id = uniqid( 'wl-gep-map-' ); |
|
| 49 | + $element_id = uniqid('wl-gep-map-'); |
|
| 50 | 50 | $html .= <<<EOF |
| 51 | 51 | |
| 52 | 52 | <div id="$element_id"></div> |
@@ -84,23 +84,23 @@ discard block |
||
| 84 | 84 | return $html; |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | - public function save_data( $coords ) { |
|
| 87 | + public function save_data($coords) { |
|
| 88 | 88 | |
| 89 | - $this->sanitize_data( $coords ); |
|
| 89 | + $this->sanitize_data($coords); |
|
| 90 | 90 | |
| 91 | 91 | $entity_id = get_the_ID(); |
| 92 | 92 | |
| 93 | 93 | // Take away old values |
| 94 | - delete_post_meta( $entity_id, Wordlift_Schema_Service::FIELD_GEO_LATITUDE ); |
|
| 95 | - delete_post_meta( $entity_id, Wordlift_Schema_Service::FIELD_GEO_LONGITUDE ); |
|
| 94 | + delete_post_meta($entity_id, Wordlift_Schema_Service::FIELD_GEO_LATITUDE); |
|
| 95 | + delete_post_meta($entity_id, Wordlift_Schema_Service::FIELD_GEO_LONGITUDE); |
|
| 96 | 96 | |
| 97 | 97 | $latitude = $this->data[0]; |
| 98 | 98 | $longitude = $this->data[1]; |
| 99 | 99 | |
| 100 | 100 | // insert new coordinate values |
| 101 | - if ( ! empty( $latitude ) && ! empty( $longitude ) ) { |
|
| 102 | - add_post_meta( $entity_id, Wordlift_Schema_Service::FIELD_GEO_LATITUDE, $latitude, true ); |
|
| 103 | - add_post_meta( $entity_id, Wordlift_Schema_Service::FIELD_GEO_LONGITUDE, $longitude, true ); |
|
| 101 | + if ( ! empty($latitude) && ! empty($longitude)) { |
|
| 102 | + add_post_meta($entity_id, Wordlift_Schema_Service::FIELD_GEO_LATITUDE, $latitude, true); |
|
| 103 | + add_post_meta($entity_id, Wordlift_Schema_Service::FIELD_GEO_LONGITUDE, $longitude, true); |
|
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | } |
@@ -108,11 +108,11 @@ discard block |
||
| 108 | 108 | /** |
| 109 | 109 | * Only accept float numbers |
| 110 | 110 | */ |
| 111 | - public function sanitize_data_filter( $value ) { |
|
| 111 | + public function sanitize_data_filter($value) { |
|
| 112 | 112 | |
| 113 | 113 | // DO NOT set latitude/longitude to 0/0 as default values. It's a specific place on the globe: |
| 114 | 114 | // "The zero/zero point of this system is located in the Gulf of Guinea about 625 km (390 mi) south of Tema, Ghana." |
| 115 | - if ( ! is_numeric( $value ) ) { |
|
| 115 | + if ( ! is_numeric($value)) { |
|
| 116 | 116 | return ''; |
| 117 | 117 | } |
| 118 | 118 | |
@@ -3,51 +3,51 @@ discard block |
||
| 3 | 3 | |
| 4 | 4 | class WL_Metabox_Field_coordinates extends WL_Metabox_Field { |
| 5 | 5 | |
| 6 | - public function __construct( $args ) { |
|
| 6 | + public function __construct( $args ) { |
|
| 7 | 7 | |
| 8 | - // Just set up the necessary info without calling the parent constructor. |
|
| 9 | - // TODO: write a parent class for grouped properties |
|
| 8 | + // Just set up the necessary info without calling the parent constructor. |
|
| 9 | + // TODO: write a parent class for grouped properties |
|
| 10 | 10 | |
| 11 | - // we use 'coordinates' to namespace the Field in $_POST data. |
|
| 12 | - // In the DB the correct meta names will be used. |
|
| 13 | - $this->meta_name = 'coordinates'; |
|
| 14 | - } |
|
| 11 | + // we use 'coordinates' to namespace the Field in $_POST data. |
|
| 12 | + // In the DB the correct meta names will be used. |
|
| 13 | + $this->meta_name = 'coordinates'; |
|
| 14 | + } |
|
| 15 | 15 | |
| 16 | - public function get_data() { |
|
| 17 | - $entity_id = get_the_ID(); |
|
| 18 | - $this->data = wl_get_coordinates( $entity_id ); |
|
| 19 | - } |
|
| 16 | + public function get_data() { |
|
| 17 | + $entity_id = get_the_ID(); |
|
| 18 | + $this->data = wl_get_coordinates( $entity_id ); |
|
| 19 | + } |
|
| 20 | 20 | |
| 21 | - public function html() { |
|
| 21 | + public function html() { |
|
| 22 | 22 | |
| 23 | - // Open main <div> for the Field |
|
| 24 | - $html = $this->html_wrapper_open(); |
|
| 23 | + // Open main <div> for the Field |
|
| 24 | + $html = $this->html_wrapper_open(); |
|
| 25 | 25 | |
| 26 | - // Label |
|
| 27 | - $html .= '<h3>coordinates</h3>'; |
|
| 26 | + // Label |
|
| 27 | + $html .= '<h3>coordinates</h3>'; |
|
| 28 | 28 | |
| 29 | - // print nonce |
|
| 30 | - $html .= $this->html_nonce(); |
|
| 29 | + // print nonce |
|
| 30 | + $html .= $this->html_nonce(); |
|
| 31 | 31 | |
| 32 | - // Get coordinates |
|
| 33 | - $data = $this->data; |
|
| 34 | - // TODO: We temporary use here 0,0 as default coordinates for the marker, but if no coordinates are given we |
|
| 35 | - // want to use the current user location for the marker. |
|
| 36 | - $coordinates = ( ! empty( $data['latitude'] ) && ! empty( $data['longitude'] ) ? sprintf( '[%f,%f]', $data['latitude'], $data['longitude'] ) : '[0,0]' ); |
|
| 37 | - $map_init = '[0,0]' === $coordinates |
|
| 38 | - ? 'locate( {setView: true, maxZoom: 16} )' |
|
| 39 | - : sprintf( "setView( [%f,%f], 9 )", $data['latitude'], $data['longitude'] ); |
|
| 32 | + // Get coordinates |
|
| 33 | + $data = $this->data; |
|
| 34 | + // TODO: We temporary use here 0,0 as default coordinates for the marker, but if no coordinates are given we |
|
| 35 | + // want to use the current user location for the marker. |
|
| 36 | + $coordinates = ( ! empty( $data['latitude'] ) && ! empty( $data['longitude'] ) ? sprintf( '[%f,%f]', $data['latitude'], $data['longitude'] ) : '[0,0]' ); |
|
| 37 | + $map_init = '[0,0]' === $coordinates |
|
| 38 | + ? 'locate( {setView: true, maxZoom: 16} )' |
|
| 39 | + : sprintf( "setView( [%f,%f], 9 )", $data['latitude'], $data['longitude'] ); |
|
| 40 | 40 | |
| 41 | - // Print input fields |
|
| 42 | - $html .= '<label for="wl_place_lat">' . __( 'Latitude', 'wordlift' ) . '</label>'; |
|
| 43 | - $html .= '<input type="text" id="wl_place_lat" name="wl_metaboxes[coordinates][]" value="' . $data['latitude'] . '" style="width:100%" />'; |
|
| 41 | + // Print input fields |
|
| 42 | + $html .= '<label for="wl_place_lat">' . __( 'Latitude', 'wordlift' ) . '</label>'; |
|
| 43 | + $html .= '<input type="text" id="wl_place_lat" name="wl_metaboxes[coordinates][]" value="' . $data['latitude'] . '" style="width:100%" />'; |
|
| 44 | 44 | |
| 45 | - $html .= '<label for="wl_place_lon">' . __( 'Longitude', 'wordlift' ) . '</label>'; |
|
| 46 | - $html .= '<input type="text" id="wl_place_lon" name="wl_metaboxes[coordinates][]" value="' . $data['longitude'] . '" style="width:100%" />'; |
|
| 45 | + $html .= '<label for="wl_place_lon">' . __( 'Longitude', 'wordlift' ) . '</label>'; |
|
| 46 | + $html .= '<input type="text" id="wl_place_lon" name="wl_metaboxes[coordinates][]" value="' . $data['longitude'] . '" style="width:100%" />'; |
|
| 47 | 47 | |
| 48 | - // Show Leaflet map to pick coordinates |
|
| 49 | - $element_id = uniqid( 'wl-gep-map-' ); |
|
| 50 | - $html .= <<<EOF |
|
| 48 | + // Show Leaflet map to pick coordinates |
|
| 49 | + $element_id = uniqid( 'wl-gep-map-' ); |
|
| 50 | + $html .= <<<EOF |
|
| 51 | 51 | |
| 52 | 52 | <div id="$element_id"></div> |
| 53 | 53 | |
@@ -79,44 +79,44 @@ discard block |
||
| 79 | 79 | EOF; |
| 80 | 80 | |
| 81 | 81 | |
| 82 | - $html .= $this->html_wrapper_close(); |
|
| 82 | + $html .= $this->html_wrapper_close(); |
|
| 83 | 83 | |
| 84 | - return $html; |
|
| 85 | - } |
|
| 84 | + return $html; |
|
| 85 | + } |
|
| 86 | 86 | |
| 87 | - public function save_data( $coords ) { |
|
| 87 | + public function save_data( $coords ) { |
|
| 88 | 88 | |
| 89 | - $this->sanitize_data( $coords ); |
|
| 89 | + $this->sanitize_data( $coords ); |
|
| 90 | 90 | |
| 91 | - $entity_id = get_the_ID(); |
|
| 91 | + $entity_id = get_the_ID(); |
|
| 92 | 92 | |
| 93 | - // Take away old values |
|
| 94 | - delete_post_meta( $entity_id, Wordlift_Schema_Service::FIELD_GEO_LATITUDE ); |
|
| 95 | - delete_post_meta( $entity_id, Wordlift_Schema_Service::FIELD_GEO_LONGITUDE ); |
|
| 93 | + // Take away old values |
|
| 94 | + delete_post_meta( $entity_id, Wordlift_Schema_Service::FIELD_GEO_LATITUDE ); |
|
| 95 | + delete_post_meta( $entity_id, Wordlift_Schema_Service::FIELD_GEO_LONGITUDE ); |
|
| 96 | 96 | |
| 97 | - $latitude = $this->data[0]; |
|
| 98 | - $longitude = $this->data[1]; |
|
| 97 | + $latitude = $this->data[0]; |
|
| 98 | + $longitude = $this->data[1]; |
|
| 99 | 99 | |
| 100 | - // insert new coordinate values |
|
| 101 | - if ( ! empty( $latitude ) && ! empty( $longitude ) ) { |
|
| 102 | - add_post_meta( $entity_id, Wordlift_Schema_Service::FIELD_GEO_LATITUDE, $latitude, true ); |
|
| 103 | - add_post_meta( $entity_id, Wordlift_Schema_Service::FIELD_GEO_LONGITUDE, $longitude, true ); |
|
| 104 | - } |
|
| 100 | + // insert new coordinate values |
|
| 101 | + if ( ! empty( $latitude ) && ! empty( $longitude ) ) { |
|
| 102 | + add_post_meta( $entity_id, Wordlift_Schema_Service::FIELD_GEO_LATITUDE, $latitude, true ); |
|
| 103 | + add_post_meta( $entity_id, Wordlift_Schema_Service::FIELD_GEO_LONGITUDE, $longitude, true ); |
|
| 104 | + } |
|
| 105 | 105 | |
| 106 | - } |
|
| 106 | + } |
|
| 107 | 107 | |
| 108 | - /** |
|
| 109 | - * Only accept float numbers |
|
| 110 | - */ |
|
| 111 | - public function sanitize_data_filter( $value ) { |
|
| 108 | + /** |
|
| 109 | + * Only accept float numbers |
|
| 110 | + */ |
|
| 111 | + public function sanitize_data_filter( $value ) { |
|
| 112 | 112 | |
| 113 | - // DO NOT set latitude/longitude to 0/0 as default values. It's a specific place on the globe: |
|
| 114 | - // "The zero/zero point of this system is located in the Gulf of Guinea about 625 km (390 mi) south of Tema, Ghana." |
|
| 115 | - if ( ! is_numeric( $value ) ) { |
|
| 116 | - return ''; |
|
| 117 | - } |
|
| 113 | + // DO NOT set latitude/longitude to 0/0 as default values. It's a specific place on the globe: |
|
| 114 | + // "The zero/zero point of this system is located in the Gulf of Guinea about 625 km (390 mi) south of Tema, Ghana." |
|
| 115 | + if ( ! is_numeric( $value ) ) { |
|
| 116 | + return ''; |
|
| 117 | + } |
|
| 118 | 118 | |
| 119 | - return $value; |
|
| 120 | - } |
|
| 119 | + return $value; |
|
| 120 | + } |
|
| 121 | 121 | } |
| 122 | 122 | |
@@ -26,38 +26,38 @@ |
||
| 26 | 26 | */ |
| 27 | 27 | class Wordlift_i18n { |
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * The domain specified for this plugin. |
|
| 31 | - * |
|
| 32 | - * @since 1.0.0 |
|
| 33 | - * @access private |
|
| 34 | - * @var string $domain The domain identifier for this plugin. |
|
| 35 | - */ |
|
| 36 | - private $domain; |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * Load the plugin text domain for translation. |
|
| 40 | - * |
|
| 41 | - * @since 1.0.0 |
|
| 42 | - */ |
|
| 43 | - public function load_plugin_textdomain() { |
|
| 44 | - |
|
| 45 | - load_plugin_textdomain( |
|
| 46 | - $this->domain, |
|
| 47 | - false, |
|
| 48 | - dirname( dirname( plugin_basename( __FILE__ ) ) ) . '/languages/' |
|
| 49 | - ); |
|
| 50 | - |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * Set the domain equal to that of the specified domain. |
|
| 55 | - * |
|
| 56 | - * @since 1.0.0 |
|
| 57 | - * @param string $domain The domain that represents the locale of this plugin. |
|
| 58 | - */ |
|
| 59 | - public function set_domain( $domain ) { |
|
| 60 | - $this->domain = $domain; |
|
| 61 | - } |
|
| 29 | + /** |
|
| 30 | + * The domain specified for this plugin. |
|
| 31 | + * |
|
| 32 | + * @since 1.0.0 |
|
| 33 | + * @access private |
|
| 34 | + * @var string $domain The domain identifier for this plugin. |
|
| 35 | + */ |
|
| 36 | + private $domain; |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * Load the plugin text domain for translation. |
|
| 40 | + * |
|
| 41 | + * @since 1.0.0 |
|
| 42 | + */ |
|
| 43 | + public function load_plugin_textdomain() { |
|
| 44 | + |
|
| 45 | + load_plugin_textdomain( |
|
| 46 | + $this->domain, |
|
| 47 | + false, |
|
| 48 | + dirname( dirname( plugin_basename( __FILE__ ) ) ) . '/languages/' |
|
| 49 | + ); |
|
| 50 | + |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * Set the domain equal to that of the specified domain. |
|
| 55 | + * |
|
| 56 | + * @since 1.0.0 |
|
| 57 | + * @param string $domain The domain that represents the locale of this plugin. |
|
| 58 | + */ |
|
| 59 | + public function set_domain( $domain ) { |
|
| 60 | + $this->domain = $domain; |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | 63 | } |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | load_plugin_textdomain( |
| 46 | 46 | $this->domain, |
| 47 | 47 | false, |
| 48 | - dirname( dirname( plugin_basename( __FILE__ ) ) ) . '/languages/' |
|
| 48 | + dirname(dirname(plugin_basename(__FILE__))).'/languages/' |
|
| 49 | 49 | ); |
| 50 | 50 | |
| 51 | 51 | } |
@@ -56,7 +56,7 @@ discard block |
||
| 56 | 56 | * @since 1.0.0 |
| 57 | 57 | * @param string $domain The domain that represents the locale of this plugin. |
| 58 | 58 | */ |
| 59 | - public function set_domain( $domain ) { |
|
| 59 | + public function set_domain($domain) { |
|
| 60 | 60 | $this->domain = $domain; |
| 61 | 61 | } |
| 62 | 62 | |
@@ -23,107 +23,107 @@ |
||
| 23 | 23 | */ |
| 24 | 24 | class Wordlift_Loader { |
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * The array of actions registered with WordPress. |
|
| 28 | - * |
|
| 29 | - * @since 1.0.0 |
|
| 30 | - * @access protected |
|
| 31 | - * @var array $actions The actions registered with WordPress to fire when the plugin loads. |
|
| 32 | - */ |
|
| 33 | - protected $actions; |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * The array of filters registered with WordPress. |
|
| 37 | - * |
|
| 38 | - * @since 1.0.0 |
|
| 39 | - * @access protected |
|
| 40 | - * @var array $filters The filters registered with WordPress to fire when the plugin loads. |
|
| 41 | - */ |
|
| 42 | - protected $filters; |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * Initialize the collections used to maintain the actions and filters. |
|
| 46 | - * |
|
| 47 | - * @since 1.0.0 |
|
| 48 | - */ |
|
| 49 | - public function __construct() { |
|
| 50 | - |
|
| 51 | - $this->actions = array(); |
|
| 52 | - $this->filters = array(); |
|
| 53 | - |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * Add a new action to the collection to be registered with WordPress. |
|
| 58 | - * |
|
| 59 | - * @since 1.0.0 |
|
| 60 | - * @param string $hook The name of the WordPress action that is being registered. |
|
| 61 | - * @param object $component A reference to the instance of the object on which the action is defined. |
|
| 62 | - * @param string $callback The name of the function definition on the $component. |
|
| 63 | - * @param int $priority Optional. he priority at which the function should be fired. Default is 10. |
|
| 64 | - * @param int $accepted_args Optional. The number of arguments that should be passed to the $callback. Default is 1. |
|
| 65 | - */ |
|
| 66 | - public function add_action( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) { |
|
| 67 | - $this->actions = $this->add( $this->actions, $hook, $component, $callback, $priority, $accepted_args ); |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * Add a new filter to the collection to be registered with WordPress. |
|
| 72 | - * |
|
| 73 | - * @since 1.0.0 |
|
| 74 | - * @param string $hook The name of the WordPress filter that is being registered. |
|
| 75 | - * @param object $component A reference to the instance of the object on which the filter is defined. |
|
| 76 | - * @param string $callback The name of the function definition on the $component. |
|
| 77 | - * @param int $priority Optional. he priority at which the function should be fired. Default is 10. |
|
| 78 | - * @param int $accepted_args Optional. The number of arguments that should be passed to the $callback. Default is 1 |
|
| 79 | - */ |
|
| 80 | - public function add_filter( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) { |
|
| 81 | - $this->filters = $this->add( $this->filters, $hook, $component, $callback, $priority, $accepted_args ); |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * A utility function that is used to register the actions and hooks into a single |
|
| 86 | - * collection. |
|
| 87 | - * |
|
| 88 | - * @since 1.0.0 |
|
| 89 | - * @access private |
|
| 90 | - * @param array $hooks The collection of hooks that is being registered (that is, actions or filters). |
|
| 91 | - * @param string $hook The name of the WordPress filter that is being registered. |
|
| 92 | - * @param object $component A reference to the instance of the object on which the filter is defined. |
|
| 93 | - * @param string $callback The name of the function definition on the $component. |
|
| 94 | - * @param int $priority The priority at which the function should be fired. |
|
| 95 | - * @param int $accepted_args The number of arguments that should be passed to the $callback. |
|
| 96 | - * @return array The collection of actions and filters registered with WordPress. |
|
| 97 | - */ |
|
| 98 | - private function add( $hooks, $hook, $component, $callback, $priority, $accepted_args ) { |
|
| 99 | - |
|
| 100 | - $hooks[] = array( |
|
| 101 | - 'hook' => $hook, |
|
| 102 | - 'component' => $component, |
|
| 103 | - 'callback' => $callback, |
|
| 104 | - 'priority' => $priority, |
|
| 105 | - 'accepted_args' => $accepted_args |
|
| 106 | - ); |
|
| 107 | - |
|
| 108 | - return $hooks; |
|
| 109 | - |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * Register the filters and actions with WordPress. |
|
| 114 | - * |
|
| 115 | - * @since 1.0.0 |
|
| 116 | - */ |
|
| 117 | - public function run() { |
|
| 118 | - |
|
| 119 | - foreach ( $this->filters as $hook ) { |
|
| 120 | - add_filter( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] ); |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - foreach ( $this->actions as $hook ) { |
|
| 124 | - add_action( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] ); |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - } |
|
| 26 | + /** |
|
| 27 | + * The array of actions registered with WordPress. |
|
| 28 | + * |
|
| 29 | + * @since 1.0.0 |
|
| 30 | + * @access protected |
|
| 31 | + * @var array $actions The actions registered with WordPress to fire when the plugin loads. |
|
| 32 | + */ |
|
| 33 | + protected $actions; |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * The array of filters registered with WordPress. |
|
| 37 | + * |
|
| 38 | + * @since 1.0.0 |
|
| 39 | + * @access protected |
|
| 40 | + * @var array $filters The filters registered with WordPress to fire when the plugin loads. |
|
| 41 | + */ |
|
| 42 | + protected $filters; |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * Initialize the collections used to maintain the actions and filters. |
|
| 46 | + * |
|
| 47 | + * @since 1.0.0 |
|
| 48 | + */ |
|
| 49 | + public function __construct() { |
|
| 50 | + |
|
| 51 | + $this->actions = array(); |
|
| 52 | + $this->filters = array(); |
|
| 53 | + |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * Add a new action to the collection to be registered with WordPress. |
|
| 58 | + * |
|
| 59 | + * @since 1.0.0 |
|
| 60 | + * @param string $hook The name of the WordPress action that is being registered. |
|
| 61 | + * @param object $component A reference to the instance of the object on which the action is defined. |
|
| 62 | + * @param string $callback The name of the function definition on the $component. |
|
| 63 | + * @param int $priority Optional. he priority at which the function should be fired. Default is 10. |
|
| 64 | + * @param int $accepted_args Optional. The number of arguments that should be passed to the $callback. Default is 1. |
|
| 65 | + */ |
|
| 66 | + public function add_action( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) { |
|
| 67 | + $this->actions = $this->add( $this->actions, $hook, $component, $callback, $priority, $accepted_args ); |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * Add a new filter to the collection to be registered with WordPress. |
|
| 72 | + * |
|
| 73 | + * @since 1.0.0 |
|
| 74 | + * @param string $hook The name of the WordPress filter that is being registered. |
|
| 75 | + * @param object $component A reference to the instance of the object on which the filter is defined. |
|
| 76 | + * @param string $callback The name of the function definition on the $component. |
|
| 77 | + * @param int $priority Optional. he priority at which the function should be fired. Default is 10. |
|
| 78 | + * @param int $accepted_args Optional. The number of arguments that should be passed to the $callback. Default is 1 |
|
| 79 | + */ |
|
| 80 | + public function add_filter( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) { |
|
| 81 | + $this->filters = $this->add( $this->filters, $hook, $component, $callback, $priority, $accepted_args ); |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * A utility function that is used to register the actions and hooks into a single |
|
| 86 | + * collection. |
|
| 87 | + * |
|
| 88 | + * @since 1.0.0 |
|
| 89 | + * @access private |
|
| 90 | + * @param array $hooks The collection of hooks that is being registered (that is, actions or filters). |
|
| 91 | + * @param string $hook The name of the WordPress filter that is being registered. |
|
| 92 | + * @param object $component A reference to the instance of the object on which the filter is defined. |
|
| 93 | + * @param string $callback The name of the function definition on the $component. |
|
| 94 | + * @param int $priority The priority at which the function should be fired. |
|
| 95 | + * @param int $accepted_args The number of arguments that should be passed to the $callback. |
|
| 96 | + * @return array The collection of actions and filters registered with WordPress. |
|
| 97 | + */ |
|
| 98 | + private function add( $hooks, $hook, $component, $callback, $priority, $accepted_args ) { |
|
| 99 | + |
|
| 100 | + $hooks[] = array( |
|
| 101 | + 'hook' => $hook, |
|
| 102 | + 'component' => $component, |
|
| 103 | + 'callback' => $callback, |
|
| 104 | + 'priority' => $priority, |
|
| 105 | + 'accepted_args' => $accepted_args |
|
| 106 | + ); |
|
| 107 | + |
|
| 108 | + return $hooks; |
|
| 109 | + |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * Register the filters and actions with WordPress. |
|
| 114 | + * |
|
| 115 | + * @since 1.0.0 |
|
| 116 | + */ |
|
| 117 | + public function run() { |
|
| 118 | + |
|
| 119 | + foreach ( $this->filters as $hook ) { |
|
| 120 | + add_filter( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] ); |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + foreach ( $this->actions as $hook ) { |
|
| 124 | + add_action( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] ); |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + } |
|
| 128 | 128 | |
| 129 | 129 | } |
@@ -63,8 +63,8 @@ discard block |
||
| 63 | 63 | * @param int $priority Optional. he priority at which the function should be fired. Default is 10. |
| 64 | 64 | * @param int $accepted_args Optional. The number of arguments that should be passed to the $callback. Default is 1. |
| 65 | 65 | */ |
| 66 | - public function add_action( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) { |
|
| 67 | - $this->actions = $this->add( $this->actions, $hook, $component, $callback, $priority, $accepted_args ); |
|
| 66 | + public function add_action($hook, $component, $callback, $priority = 10, $accepted_args = 1) { |
|
| 67 | + $this->actions = $this->add($this->actions, $hook, $component, $callback, $priority, $accepted_args); |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | /** |
@@ -77,8 +77,8 @@ discard block |
||
| 77 | 77 | * @param int $priority Optional. he priority at which the function should be fired. Default is 10. |
| 78 | 78 | * @param int $accepted_args Optional. The number of arguments that should be passed to the $callback. Default is 1 |
| 79 | 79 | */ |
| 80 | - public function add_filter( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) { |
|
| 81 | - $this->filters = $this->add( $this->filters, $hook, $component, $callback, $priority, $accepted_args ); |
|
| 80 | + public function add_filter($hook, $component, $callback, $priority = 10, $accepted_args = 1) { |
|
| 81 | + $this->filters = $this->add($this->filters, $hook, $component, $callback, $priority, $accepted_args); |
|
| 82 | 82 | } |
| 83 | 83 | |
| 84 | 84 | /** |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | * @param int $accepted_args The number of arguments that should be passed to the $callback. |
| 96 | 96 | * @return array The collection of actions and filters registered with WordPress. |
| 97 | 97 | */ |
| 98 | - private function add( $hooks, $hook, $component, $callback, $priority, $accepted_args ) { |
|
| 98 | + private function add($hooks, $hook, $component, $callback, $priority, $accepted_args) { |
|
| 99 | 99 | |
| 100 | 100 | $hooks[] = array( |
| 101 | 101 | 'hook' => $hook, |
@@ -116,12 +116,12 @@ discard block |
||
| 116 | 116 | */ |
| 117 | 117 | public function run() { |
| 118 | 118 | |
| 119 | - foreach ( $this->filters as $hook ) { |
|
| 120 | - add_filter( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] ); |
|
| 119 | + foreach ($this->filters as $hook) { |
|
| 120 | + add_filter($hook['hook'], array($hook['component'], $hook['callback']), $hook['priority'], $hook['accepted_args']); |
|
| 121 | 121 | } |
| 122 | 122 | |
| 123 | - foreach ( $this->actions as $hook ) { |
|
| 124 | - add_action( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] ); |
|
| 123 | + foreach ($this->actions as $hook) { |
|
| 124 | + add_action($hook['hook'], array($hook['component'], $hook['callback']), $hook['priority'], $hook['accepted_args']); |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | } |
@@ -9,28 +9,28 @@ discard block |
||
| 9 | 9 | * @param array $atts An array of shortcode attributes. |
| 10 | 10 | * @return string A dom element with requested property value(s). |
| 11 | 11 | */ |
| 12 | -function wl_shortcode_field( $atts ) { |
|
| 12 | +function wl_shortcode_field($atts) { |
|
| 13 | 13 | |
| 14 | 14 | // Extract attributes and set default values. |
| 15 | - $field_atts = shortcode_atts( array( |
|
| 15 | + $field_atts = shortcode_atts(array( |
|
| 16 | 16 | 'id' => null, |
| 17 | 17 | 'name' => null |
| 18 | - ), $atts ); |
|
| 18 | + ), $atts); |
|
| 19 | 19 | |
| 20 | 20 | // Get id of the post |
| 21 | 21 | $entity_id = $field_atts['id']; |
| 22 | - if( is_null( $field_atts['id'] ) || !is_numeric( $field_atts['id'] ) ) { |
|
| 22 | + if (is_null($field_atts['id']) || ! is_numeric($field_atts['id'])) { |
|
| 23 | 23 | $entity_id = get_the_ID(); |
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | $property_name = $field_atts['name']; |
| 27 | - if( !is_null( $property_name ) ) { |
|
| 28 | - $values = wl_schema_get_value( $entity_id, $property_name ); |
|
| 27 | + if ( ! is_null($property_name)) { |
|
| 28 | + $values = wl_schema_get_value($entity_id, $property_name); |
|
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | // Return |
| 32 | - if( is_array( $values ) ) { |
|
| 33 | - return implode( ', ', $values ); |
|
| 32 | + if (is_array($values)) { |
|
| 33 | + return implode(', ', $values); |
|
| 34 | 34 | } else { |
| 35 | 35 | return null; |
| 36 | 36 | } |
@@ -40,5 +40,5 @@ discard block |
||
| 40 | 40 | add_shortcode('wl_field', 'wl_shortcode_field'); |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | -add_action( 'init', 'wl_register_shortcode_field'); |
|
| 43 | +add_action('init', 'wl_register_shortcode_field'); |
|
| 44 | 44 | |
@@ -27,15 +27,15 @@ discard block |
||
| 27 | 27 | * @param array $args |
| 28 | 28 | * @param array $instance |
| 29 | 29 | */ |
| 30 | - public function widget( $args, $instance ) |
|
| 30 | + public function widget($args, $instance) |
|
| 31 | 31 | { |
| 32 | 32 | // Get the widget's title. |
| 33 | 33 | $title = apply_filters('widget_title', $instance['title']); |
| 34 | 34 | |
| 35 | 35 | // Print the HTML output. |
| 36 | 36 | echo $args['before_widget']; |
| 37 | - if (!empty($title)) { |
|
| 38 | - echo $args['before_title'] . $title . $args['after_title']; |
|
| 37 | + if ( ! empty($title)) { |
|
| 38 | + echo $args['before_title'].$title.$args['after_title']; |
|
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | // Print the geomap shortcode |
@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | { |
| 82 | 82 | |
| 83 | 83 | $instance = array(); |
| 84 | - $instance['title'] = (!empty($new_instance['title'])) ? strip_tags($new_instance['title']) : ''; |
|
| 84 | + $instance['title'] = ( ! empty($new_instance['title'])) ? strip_tags($new_instance['title']) : ''; |
|
| 85 | 85 | |
| 86 | 86 | return $instance; |
| 87 | 87 | } |
@@ -7,80 +7,80 @@ |
||
| 7 | 7 | */ |
| 8 | 8 | class Wordlift_UI_Service { |
| 9 | 9 | |
| 10 | - /** |
|
| 11 | - * The button element HTML code. |
|
| 12 | - * |
|
| 13 | - * @since 3.2.0 |
|
| 14 | - */ |
|
| 15 | - const BUTTON_HTML = '<a id="%s" class="button wl-button">%s</a>'; |
|
| 10 | + /** |
|
| 11 | + * The button element HTML code. |
|
| 12 | + * |
|
| 13 | + * @since 3.2.0 |
|
| 14 | + */ |
|
| 15 | + const BUTTON_HTML = '<a id="%s" class="button wl-button">%s</a>'; |
|
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * The template HTML code. |
|
| 19 | - * |
|
| 20 | - * @since 3.2.0 |
|
| 21 | - */ |
|
| 22 | - const TEMPLATE_HTML = '<script id="%s" type="text/template">%s</script>'; |
|
| 17 | + /** |
|
| 18 | + * The template HTML code. |
|
| 19 | + * |
|
| 20 | + * @since 3.2.0 |
|
| 21 | + */ |
|
| 22 | + const TEMPLATE_HTML = '<script id="%s" type="text/template">%s</script>'; |
|
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * Get the button HTML. |
|
| 26 | - * |
|
| 27 | - * @since 3.2.0 |
|
| 28 | - * |
|
| 29 | - * @param string $element_id The button element id. |
|
| 30 | - * @param string $label The button (translated) label. |
|
| 31 | - * |
|
| 32 | - * @return string The button HTML code. |
|
| 33 | - */ |
|
| 34 | - public function get_button_html( $element_id, $label ) { |
|
| 24 | + /** |
|
| 25 | + * Get the button HTML. |
|
| 26 | + * |
|
| 27 | + * @since 3.2.0 |
|
| 28 | + * |
|
| 29 | + * @param string $element_id The button element id. |
|
| 30 | + * @param string $label The button (translated) label. |
|
| 31 | + * |
|
| 32 | + * @return string The button HTML code. |
|
| 33 | + */ |
|
| 34 | + public function get_button_html( $element_id, $label ) { |
|
| 35 | 35 | |
| 36 | - return sprintf( self::BUTTON_HTML, $element_id, esc_html( $label ) ); |
|
| 37 | - } |
|
| 36 | + return sprintf( self::BUTTON_HTML, $element_id, esc_html( $label ) ); |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * Echo the button HTML. |
|
| 41 | - * |
|
| 42 | - * @since 3.2.0 |
|
| 43 | - * |
|
| 44 | - * @param string $element_id The button element id. |
|
| 45 | - * @param string $label The button (translated) label. |
|
| 46 | - * |
|
| 47 | - * @return string The button HTML code. |
|
| 48 | - */ |
|
| 49 | - public function print_button( $element_id, $label ) { |
|
| 39 | + /** |
|
| 40 | + * Echo the button HTML. |
|
| 41 | + * |
|
| 42 | + * @since 3.2.0 |
|
| 43 | + * |
|
| 44 | + * @param string $element_id The button element id. |
|
| 45 | + * @param string $label The button (translated) label. |
|
| 46 | + * |
|
| 47 | + * @return string The button HTML code. |
|
| 48 | + */ |
|
| 49 | + public function print_button( $element_id, $label ) { |
|
| 50 | 50 | |
| 51 | - echo( $this->get_button_html( $element_id, $label ) ); |
|
| 51 | + echo( $this->get_button_html( $element_id, $label ) ); |
|
| 52 | 52 | |
| 53 | - } |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * Get the HTML code for a template tag. |
|
| 57 | - * |
|
| 58 | - * @since 3.2.0 |
|
| 59 | - * |
|
| 60 | - * @param string $element_id The element id. |
|
| 61 | - * @param string $body The element content. |
|
| 62 | - * |
|
| 63 | - * @return string The HTML code. |
|
| 64 | - */ |
|
| 65 | - public function get_template_html( $element_id, $body ) { |
|
| 55 | + /** |
|
| 56 | + * Get the HTML code for a template tag. |
|
| 57 | + * |
|
| 58 | + * @since 3.2.0 |
|
| 59 | + * |
|
| 60 | + * @param string $element_id The element id. |
|
| 61 | + * @param string $body The element content. |
|
| 62 | + * |
|
| 63 | + * @return string The HTML code. |
|
| 64 | + */ |
|
| 65 | + public function get_template_html( $element_id, $body ) { |
|
| 66 | 66 | |
| 67 | - return sprintf( self::TEMPLATE_HTML, $element_id, $body ); |
|
| 68 | - } |
|
| 67 | + return sprintf( self::TEMPLATE_HTML, $element_id, $body ); |
|
| 68 | + } |
|
| 69 | 69 | |
| 70 | - /** |
|
| 71 | - * Echo the HTML code for a template tag. |
|
| 72 | - * |
|
| 73 | - * @since 3.2.0 |
|
| 74 | - * |
|
| 75 | - * @param string $element_id The element id. |
|
| 76 | - * @param string $body The element content. |
|
| 77 | - * |
|
| 78 | - * @return string The HTML code. |
|
| 79 | - */ |
|
| 80 | - public function print_template( $element_id, $body ) { |
|
| 70 | + /** |
|
| 71 | + * Echo the HTML code for a template tag. |
|
| 72 | + * |
|
| 73 | + * @since 3.2.0 |
|
| 74 | + * |
|
| 75 | + * @param string $element_id The element id. |
|
| 76 | + * @param string $body The element content. |
|
| 77 | + * |
|
| 78 | + * @return string The HTML code. |
|
| 79 | + */ |
|
| 80 | + public function print_template( $element_id, $body ) { |
|
| 81 | 81 | |
| 82 | - echo( $this->get_template_html( $element_id, $body ) ); |
|
| 82 | + echo( $this->get_template_html( $element_id, $body ) ); |
|
| 83 | 83 | |
| 84 | - } |
|
| 84 | + } |
|
| 85 | 85 | |
| 86 | 86 | } |
@@ -31,9 +31,9 @@ discard block |
||
| 31 | 31 | * |
| 32 | 32 | * @return string The button HTML code. |
| 33 | 33 | */ |
| 34 | - public function get_button_html( $element_id, $label ) { |
|
| 34 | + public function get_button_html($element_id, $label) { |
|
| 35 | 35 | |
| 36 | - return sprintf( self::BUTTON_HTML, $element_id, esc_html( $label ) ); |
|
| 36 | + return sprintf(self::BUTTON_HTML, $element_id, esc_html($label)); |
|
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | /** |
@@ -46,9 +46,9 @@ discard block |
||
| 46 | 46 | * |
| 47 | 47 | * @return string The button HTML code. |
| 48 | 48 | */ |
| 49 | - public function print_button( $element_id, $label ) { |
|
| 49 | + public function print_button($element_id, $label) { |
|
| 50 | 50 | |
| 51 | - echo( $this->get_button_html( $element_id, $label ) ); |
|
| 51 | + echo($this->get_button_html($element_id, $label)); |
|
| 52 | 52 | |
| 53 | 53 | } |
| 54 | 54 | |
@@ -62,9 +62,9 @@ discard block |
||
| 62 | 62 | * |
| 63 | 63 | * @return string The HTML code. |
| 64 | 64 | */ |
| 65 | - public function get_template_html( $element_id, $body ) { |
|
| 65 | + public function get_template_html($element_id, $body) { |
|
| 66 | 66 | |
| 67 | - return sprintf( self::TEMPLATE_HTML, $element_id, $body ); |
|
| 67 | + return sprintf(self::TEMPLATE_HTML, $element_id, $body); |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | /** |
@@ -77,9 +77,9 @@ discard block |
||
| 77 | 77 | * |
| 78 | 78 | * @return string The HTML code. |
| 79 | 79 | */ |
| 80 | - public function print_template( $element_id, $body ) { |
|
| 80 | + public function print_template($element_id, $body) { |
|
| 81 | 81 | |
| 82 | - echo( $this->get_template_html( $element_id, $body ) ); |
|
| 82 | + echo($this->get_template_html($element_id, $body)); |
|
| 83 | 83 | |
| 84 | 84 | } |
| 85 | 85 | |
@@ -115,9 +115,8 @@ |
||
| 115 | 115 | * |
| 116 | 116 | * @since 3.2.0 |
| 117 | 117 | * |
| 118 | - * @param int $entity_id A post entity id. |
|
| 119 | 118 | * |
| 120 | - * @return string permalink. |
|
| 119 | + * @return string[] permalink. |
|
| 121 | 120 | */ |
| 122 | 121 | public function allowed_redirect_hosts( $content ) { |
| 123 | 122 | |
@@ -7,119 +7,119 @@ |
||
| 7 | 7 | */ |
| 8 | 8 | class Wordlift_Redirect_Service { |
| 9 | 9 | |
| 10 | - const LOD_ENDPOINT = 'http://www.lodview.it'; |
|
| 11 | - const LOD_HOST = 'www.lodview.it'; |
|
| 12 | - |
|
| 13 | - /** |
|
| 14 | - * The Log service. |
|
| 15 | - * |
|
| 16 | - * @since 3.2.0 |
|
| 17 | - * @access private |
|
| 18 | - * @var \Wordlift_Log_Service $log_service The Log service. |
|
| 19 | - */ |
|
| 20 | - private $log_service; |
|
| 21 | - |
|
| 22 | - /** |
|
| 23 | - * The Entity service. |
|
| 24 | - * |
|
| 25 | - * @since 3.2.0 |
|
| 26 | - * @access private |
|
| 27 | - * @var \Wordlift_Entity_Service $entity_service The Entity service. |
|
| 28 | - */ |
|
| 29 | - private $entity_service; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * A singleton instance of the Redirect service (useful for unit tests). |
|
| 33 | - * |
|
| 34 | - * @since 3.2.0 |
|
| 35 | - * @access private |
|
| 36 | - * @var \Wordlift_Redirect_Service $instance The singleton instance. |
|
| 37 | - */ |
|
| 38 | - private static $instance; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * Create a Wordlift_Redirect_Service instance. |
|
| 42 | - * |
|
| 43 | - * @since 3.2.0 |
|
| 44 | - * |
|
| 45 | - * @param \Wordlift_Entity_Service $entity_service The Entity service. |
|
| 46 | - */ |
|
| 47 | - public function __construct( $entity_service ) { |
|
| 48 | - |
|
| 49 | - $this->log_service = Wordlift_Log_Service::get_logger( 'Wordlift_Redirect_Service' ); |
|
| 50 | - |
|
| 51 | - $this->entity_service = $entity_service; |
|
| 52 | - |
|
| 53 | - self::$instance = $this; |
|
| 54 | - |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * Get the singleton instance of the Wordlift_Redirect_Service |
|
| 59 | - * |
|
| 60 | - * @since 3.2.0 |
|
| 61 | - * |
|
| 62 | - * @return \Wordlift_Redirect_Service The singleton instance of the Wordlift_Redirect_Service. |
|
| 63 | - */ |
|
| 64 | - public static function get_instance() { |
|
| 65 | - |
|
| 66 | - return self::$instance; |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * Perform redirect depending on entity uri and target |
|
| 71 | - * |
|
| 72 | - * @since 3.2.0 |
|
| 73 | - */ |
|
| 74 | - public function ajax_redirect() { |
|
| 75 | - |
|
| 76 | - if ( !isset( $_GET['uri'] ) ) { |
|
| 77 | - wp_die( 'Entity uri missing' ); |
|
| 78 | - } |
|
| 79 | - if ( !isset( $_GET['to'] ) ) { |
|
| 80 | - wp_die( 'Redirect target missing' ); |
|
| 81 | - } |
|
| 82 | - // Get the entity uri |
|
| 83 | - $entity_uri = $_GET['uri']; |
|
| 84 | - // Get the redirect target |
|
| 85 | - $target = $_GET['to']; |
|
| 10 | + const LOD_ENDPOINT = 'http://www.lodview.it'; |
|
| 11 | + const LOD_HOST = 'www.lodview.it'; |
|
| 12 | + |
|
| 13 | + /** |
|
| 14 | + * The Log service. |
|
| 15 | + * |
|
| 16 | + * @since 3.2.0 |
|
| 17 | + * @access private |
|
| 18 | + * @var \Wordlift_Log_Service $log_service The Log service. |
|
| 19 | + */ |
|
| 20 | + private $log_service; |
|
| 21 | + |
|
| 22 | + /** |
|
| 23 | + * The Entity service. |
|
| 24 | + * |
|
| 25 | + * @since 3.2.0 |
|
| 26 | + * @access private |
|
| 27 | + * @var \Wordlift_Entity_Service $entity_service The Entity service. |
|
| 28 | + */ |
|
| 29 | + private $entity_service; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * A singleton instance of the Redirect service (useful for unit tests). |
|
| 33 | + * |
|
| 34 | + * @since 3.2.0 |
|
| 35 | + * @access private |
|
| 36 | + * @var \Wordlift_Redirect_Service $instance The singleton instance. |
|
| 37 | + */ |
|
| 38 | + private static $instance; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * Create a Wordlift_Redirect_Service instance. |
|
| 42 | + * |
|
| 43 | + * @since 3.2.0 |
|
| 44 | + * |
|
| 45 | + * @param \Wordlift_Entity_Service $entity_service The Entity service. |
|
| 46 | + */ |
|
| 47 | + public function __construct( $entity_service ) { |
|
| 48 | + |
|
| 49 | + $this->log_service = Wordlift_Log_Service::get_logger( 'Wordlift_Redirect_Service' ); |
|
| 50 | + |
|
| 51 | + $this->entity_service = $entity_service; |
|
| 52 | + |
|
| 53 | + self::$instance = $this; |
|
| 54 | + |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * Get the singleton instance of the Wordlift_Redirect_Service |
|
| 59 | + * |
|
| 60 | + * @since 3.2.0 |
|
| 61 | + * |
|
| 62 | + * @return \Wordlift_Redirect_Service The singleton instance of the Wordlift_Redirect_Service. |
|
| 63 | + */ |
|
| 64 | + public static function get_instance() { |
|
| 65 | + |
|
| 66 | + return self::$instance; |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * Perform redirect depending on entity uri and target |
|
| 71 | + * |
|
| 72 | + * @since 3.2.0 |
|
| 73 | + */ |
|
| 74 | + public function ajax_redirect() { |
|
| 75 | + |
|
| 76 | + if ( !isset( $_GET['uri'] ) ) { |
|
| 77 | + wp_die( 'Entity uri missing' ); |
|
| 78 | + } |
|
| 79 | + if ( !isset( $_GET['to'] ) ) { |
|
| 80 | + wp_die( 'Redirect target missing' ); |
|
| 81 | + } |
|
| 82 | + // Get the entity uri |
|
| 83 | + $entity_uri = $_GET['uri']; |
|
| 84 | + // Get the redirect target |
|
| 85 | + $target = $_GET['to']; |
|
| 86 | 86 | |
| 87 | - if ( null === ( $entity_id = $this->entity_service->get_entity_post_by_uri( $entity_uri ) ) ) { |
|
| 88 | - wp_die( 'Entity not found' ); |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - switch ( $target ) { |
|
| 92 | - case 'edit': |
|
| 93 | - $redirect_url = get_edit_post_link( $entity_id, 'none' ); |
|
| 94 | - break; |
|
| 95 | - case 'lod': |
|
| 96 | - $redirect_url = self::LOD_ENDPOINT . '/lodview/?IRI=' . urlencode( $entity_uri ); |
|
| 97 | - break; |
|
| 98 | - case 'permalink': |
|
| 99 | - $redirect_url = get_permalink( $entity_id ); |
|
| 100 | - break; |
|
| 101 | - default: |
|
| 102 | - wp_die( 'Unsupported redirect target' ); |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - // Perform the redirect |
|
| 106 | - wp_safe_redirect( $redirect_url ); |
|
| 107 | - exit; |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * Register custom allowed hosts. |
|
| 112 | - * @see https://developer.wordpress.org/reference/functions/wp_safe_redirect/ |
|
| 113 | - * |
|
| 114 | - * @since 3.2.0 |
|
| 115 | - * |
|
| 116 | - * @param int $entity_id A post entity id. |
|
| 117 | - * |
|
| 118 | - * @return string permalink. |
|
| 119 | - */ |
|
| 120 | - public function allowed_redirect_hosts( $content ) { |
|
| 121 | - |
|
| 122 | - return array_merge( $content, array( self::LOD_HOST ) ); |
|
| 123 | - } |
|
| 87 | + if ( null === ( $entity_id = $this->entity_service->get_entity_post_by_uri( $entity_uri ) ) ) { |
|
| 88 | + wp_die( 'Entity not found' ); |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + switch ( $target ) { |
|
| 92 | + case 'edit': |
|
| 93 | + $redirect_url = get_edit_post_link( $entity_id, 'none' ); |
|
| 94 | + break; |
|
| 95 | + case 'lod': |
|
| 96 | + $redirect_url = self::LOD_ENDPOINT . '/lodview/?IRI=' . urlencode( $entity_uri ); |
|
| 97 | + break; |
|
| 98 | + case 'permalink': |
|
| 99 | + $redirect_url = get_permalink( $entity_id ); |
|
| 100 | + break; |
|
| 101 | + default: |
|
| 102 | + wp_die( 'Unsupported redirect target' ); |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + // Perform the redirect |
|
| 106 | + wp_safe_redirect( $redirect_url ); |
|
| 107 | + exit; |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * Register custom allowed hosts. |
|
| 112 | + * @see https://developer.wordpress.org/reference/functions/wp_safe_redirect/ |
|
| 113 | + * |
|
| 114 | + * @since 3.2.0 |
|
| 115 | + * |
|
| 116 | + * @param int $entity_id A post entity id. |
|
| 117 | + * |
|
| 118 | + * @return string permalink. |
|
| 119 | + */ |
|
| 120 | + public function allowed_redirect_hosts( $content ) { |
|
| 121 | + |
|
| 122 | + return array_merge( $content, array( self::LOD_HOST ) ); |
|
| 123 | + } |
|
| 124 | 124 | |
| 125 | 125 | } |
@@ -44,9 +44,9 @@ discard block |
||
| 44 | 44 | * |
| 45 | 45 | * @param \Wordlift_Entity_Service $entity_service The Entity service. |
| 46 | 46 | */ |
| 47 | - public function __construct( $entity_service ) { |
|
| 47 | + public function __construct($entity_service) { |
|
| 48 | 48 | |
| 49 | - $this->log_service = Wordlift_Log_Service::get_logger( 'Wordlift_Redirect_Service' ); |
|
| 49 | + $this->log_service = Wordlift_Log_Service::get_logger('Wordlift_Redirect_Service'); |
|
| 50 | 50 | |
| 51 | 51 | $this->entity_service = $entity_service; |
| 52 | 52 | |
@@ -73,37 +73,37 @@ discard block |
||
| 73 | 73 | */ |
| 74 | 74 | public function ajax_redirect() { |
| 75 | 75 | |
| 76 | - if ( !isset( $_GET['uri'] ) ) { |
|
| 77 | - wp_die( 'Entity uri missing' ); |
|
| 76 | + if ( ! isset($_GET['uri'])) { |
|
| 77 | + wp_die('Entity uri missing'); |
|
| 78 | 78 | } |
| 79 | - if ( !isset( $_GET['to'] ) ) { |
|
| 80 | - wp_die( 'Redirect target missing' ); |
|
| 79 | + if ( ! isset($_GET['to'])) { |
|
| 80 | + wp_die('Redirect target missing'); |
|
| 81 | 81 | } |
| 82 | 82 | // Get the entity uri |
| 83 | 83 | $entity_uri = $_GET['uri']; |
| 84 | 84 | // Get the redirect target |
| 85 | 85 | $target = $_GET['to']; |
| 86 | 86 | |
| 87 | - if ( null === ( $entity_id = $this->entity_service->get_entity_post_by_uri( $entity_uri ) ) ) { |
|
| 88 | - wp_die( 'Entity not found' ); |
|
| 87 | + if (null === ($entity_id = $this->entity_service->get_entity_post_by_uri($entity_uri))) { |
|
| 88 | + wp_die('Entity not found'); |
|
| 89 | 89 | } |
| 90 | 90 | |
| 91 | - switch ( $target ) { |
|
| 91 | + switch ($target) { |
|
| 92 | 92 | case 'edit': |
| 93 | - $redirect_url = get_edit_post_link( $entity_id, 'none' ); |
|
| 93 | + $redirect_url = get_edit_post_link($entity_id, 'none'); |
|
| 94 | 94 | break; |
| 95 | 95 | case 'lod': |
| 96 | - $redirect_url = self::LOD_ENDPOINT . '/lodview/?IRI=' . urlencode( $entity_uri ); |
|
| 96 | + $redirect_url = self::LOD_ENDPOINT.'/lodview/?IRI='.urlencode($entity_uri); |
|
| 97 | 97 | break; |
| 98 | 98 | case 'permalink': |
| 99 | - $redirect_url = get_permalink( $entity_id ); |
|
| 99 | + $redirect_url = get_permalink($entity_id); |
|
| 100 | 100 | break; |
| 101 | 101 | default: |
| 102 | - wp_die( 'Unsupported redirect target' ); |
|
| 102 | + wp_die('Unsupported redirect target'); |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | // Perform the redirect |
| 106 | - wp_safe_redirect( $redirect_url ); |
|
| 106 | + wp_safe_redirect($redirect_url); |
|
| 107 | 107 | exit; |
| 108 | 108 | } |
| 109 | 109 | |
@@ -117,9 +117,9 @@ discard block |
||
| 117 | 117 | * |
| 118 | 118 | * @return string permalink. |
| 119 | 119 | */ |
| 120 | - public function allowed_redirect_hosts( $content ) { |
|
| 120 | + public function allowed_redirect_hosts($content) { |
|
| 121 | 121 | |
| 122 | - return array_merge( $content, array( self::LOD_HOST ) ); |
|
| 122 | + return array_merge($content, array(self::LOD_HOST)); |
|
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | } |
@@ -7,33 +7,33 @@ |
||
| 7 | 7 | */ |
| 8 | 8 | class Wordlift_PrimaShop_Adapter { |
| 9 | 9 | |
| 10 | - /** |
|
| 11 | - * Create a Wordlift_PrimaShop_Adapter instance. |
|
| 12 | - * |
|
| 13 | - * @since 3.2.3 |
|
| 14 | - */ |
|
| 15 | - public function __construct() { |
|
| 10 | + /** |
|
| 11 | + * Create a Wordlift_PrimaShop_Adapter instance. |
|
| 12 | + * |
|
| 13 | + * @since 3.2.3 |
|
| 14 | + */ |
|
| 15 | + public function __construct() { |
|
| 16 | 16 | |
| 17 | - // Tell WP (and PrimaShop) that we support the *prima-layout-settings*. This will display the Content Settings |
|
| 18 | - // in the entity edit page. |
|
| 19 | - add_post_type_support( Wordlift_Entity_Service::TYPE_NAME, 'prima-layout-settings' ); |
|
| 17 | + // Tell WP (and PrimaShop) that we support the *prima-layout-settings*. This will display the Content Settings |
|
| 18 | + // in the entity edit page. |
|
| 19 | + add_post_type_support( Wordlift_Entity_Service::TYPE_NAME, 'prima-layout-settings' ); |
|
| 20 | 20 | |
| 21 | - } |
|
| 21 | + } |
|
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * Intercept the <em>prima_metabox_entity_header_args</em> filter and return what a call to the related <em>post</em> |
|
| 25 | - * would have returned. |
|
| 26 | - * |
|
| 27 | - * @since 3.2.3 |
|
| 28 | - * |
|
| 29 | - * @param array $meta The meta array. |
|
| 30 | - * @param string $ype The post type. |
|
| 31 | - * |
|
| 32 | - * @return array A meta array. |
|
| 33 | - */ |
|
| 34 | - function prima_metabox_entity_header_args( $meta, $ype ) { |
|
| 23 | + /** |
|
| 24 | + * Intercept the <em>prima_metabox_entity_header_args</em> filter and return what a call to the related <em>post</em> |
|
| 25 | + * would have returned. |
|
| 26 | + * |
|
| 27 | + * @since 3.2.3 |
|
| 28 | + * |
|
| 29 | + * @param array $meta The meta array. |
|
| 30 | + * @param string $ype The post type. |
|
| 31 | + * |
|
| 32 | + * @return array A meta array. |
|
| 33 | + */ |
|
| 34 | + function prima_metabox_entity_header_args( $meta, $ype ) { |
|
| 35 | 35 | |
| 36 | - return apply_filters( "prima_metabox_post_header_args", $meta, 'post' ); |
|
| 37 | - } |
|
| 36 | + return apply_filters( "prima_metabox_post_header_args", $meta, 'post' ); |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | 39 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | |
| 17 | 17 | // Tell WP (and PrimaShop) that we support the *prima-layout-settings*. This will display the Content Settings |
| 18 | 18 | // in the entity edit page. |
| 19 | - add_post_type_support( Wordlift_Entity_Service::TYPE_NAME, 'prima-layout-settings' ); |
|
| 19 | + add_post_type_support(Wordlift_Entity_Service::TYPE_NAME, 'prima-layout-settings'); |
|
| 20 | 20 | |
| 21 | 21 | } |
| 22 | 22 | |
@@ -31,9 +31,9 @@ discard block |
||
| 31 | 31 | * |
| 32 | 32 | * @return array A meta array. |
| 33 | 33 | */ |
| 34 | - function prima_metabox_entity_header_args( $meta, $ype ) { |
|
| 34 | + function prima_metabox_entity_header_args($meta, $ype) { |
|
| 35 | 35 | |
| 36 | - return apply_filters( "prima_metabox_post_header_args", $meta, 'post' ); |
|
| 36 | + return apply_filters("prima_metabox_post_header_args", $meta, 'post'); |
|
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | } |