@@ -12,7 +12,7 @@ |
||
| 12 | 12 | * @param string $new_title Optional. New title. |
| 13 | 13 | * @param string $new_slug Optional. New slug. |
| 14 | 14 | * |
| 15 | - * @return The enhanced html. |
|
| 15 | + * @return string enhanced html. |
|
| 16 | 16 | */ |
| 17 | 17 | function wl_admin_permalink_html( $html, $post_id, $new_title, $new_slug ) { |
| 18 | 18 | |
@@ -16,23 +16,23 @@ |
||
| 16 | 16 | */ |
| 17 | 17 | function wl_admin_permalink_html( $html, $post_id, $new_title, $new_slug ) { |
| 18 | 18 | |
| 19 | - // If the post is published, add the button to view Redlink's linked data. |
|
| 20 | - if ( 'publish' == get_post_status( $post_id ) ) { |
|
| 21 | - if ( $uri = wl_get_entity_uri( $post_id ) ) { |
|
| 22 | - $uri_esc = esc_attr( wl_get_entity_uri( $post_id ) ); |
|
| 23 | - $lod_view_href = 'http://lodview.it/lodview/?IRI=' . $uri_esc; |
|
| 24 | - $html .= "<span id='view-post-btn'><a href='$lod_view_href' class='button button-small wl-button' target='_blank'>" . |
|
| 25 | - esc_html__( 'View Linked Data', 'wordlift' ) . |
|
| 26 | - "</a></span>\n"; |
|
| 27 | - } |
|
| 28 | - $html .= "<span id='view-post-btn'><a href='" . WL_CONFIG_TEST_GOOGLE_RICH_SNIPPETS_URL . |
|
| 29 | - urlencode( get_permalink( $post_id ) ) . |
|
| 30 | - "' class='button button-small wl-button' target='_blank'>" . |
|
| 31 | - esc_html__( 'Test Google Rich Snippets', 'wordlift' ) . |
|
| 32 | - "</a></span>\n"; |
|
| 33 | - } |
|
| 19 | + // If the post is published, add the button to view Redlink's linked data. |
|
| 20 | + if ( 'publish' == get_post_status( $post_id ) ) { |
|
| 21 | + if ( $uri = wl_get_entity_uri( $post_id ) ) { |
|
| 22 | + $uri_esc = esc_attr( wl_get_entity_uri( $post_id ) ); |
|
| 23 | + $lod_view_href = 'http://lodview.it/lodview/?IRI=' . $uri_esc; |
|
| 24 | + $html .= "<span id='view-post-btn'><a href='$lod_view_href' class='button button-small wl-button' target='_blank'>" . |
|
| 25 | + esc_html__( 'View Linked Data', 'wordlift' ) . |
|
| 26 | + "</a></span>\n"; |
|
| 27 | + } |
|
| 28 | + $html .= "<span id='view-post-btn'><a href='" . WL_CONFIG_TEST_GOOGLE_RICH_SNIPPETS_URL . |
|
| 29 | + urlencode( get_permalink( $post_id ) ) . |
|
| 30 | + "' class='button button-small wl-button' target='_blank'>" . |
|
| 31 | + esc_html__( 'Test Google Rich Snippets', 'wordlift' ) . |
|
| 32 | + "</a></span>\n"; |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | - return $html; |
|
| 35 | + return $html; |
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | add_filter( 'get_sample_permalink_html', 'wl_admin_permalink_html', PHP_INT_MAX, 4 ); |
@@ -14,25 +14,25 @@ |
||
| 14 | 14 | * |
| 15 | 15 | * @return The enhanced html. |
| 16 | 16 | */ |
| 17 | -function wl_admin_permalink_html( $html, $post_id, $new_title, $new_slug ) { |
|
| 17 | +function wl_admin_permalink_html($html, $post_id, $new_title, $new_slug) { |
|
| 18 | 18 | |
| 19 | 19 | // If the post is published, add the button to view Redlink's linked data. |
| 20 | - if ( 'publish' == get_post_status( $post_id ) ) { |
|
| 21 | - if ( $uri = wl_get_entity_uri( $post_id ) ) { |
|
| 22 | - $uri_esc = esc_attr( wl_get_entity_uri( $post_id ) ); |
|
| 23 | - $lod_view_href = 'http://lodview.it/lodview/?IRI=' . $uri_esc; |
|
| 24 | - $html .= "<span id='view-post-btn'><a href='$lod_view_href' class='button button-small wl-button' target='_blank'>" . |
|
| 25 | - esc_html__( 'View Linked Data', 'wordlift' ) . |
|
| 20 | + if ('publish' == get_post_status($post_id)) { |
|
| 21 | + if ($uri = wl_get_entity_uri($post_id)) { |
|
| 22 | + $uri_esc = esc_attr(wl_get_entity_uri($post_id)); |
|
| 23 | + $lod_view_href = 'http://lodview.it/lodview/?IRI='.$uri_esc; |
|
| 24 | + $html .= "<span id='view-post-btn'><a href='$lod_view_href' class='button button-small wl-button' target='_blank'>". |
|
| 25 | + esc_html__('View Linked Data', 'wordlift'). |
|
| 26 | 26 | "</a></span>\n"; |
| 27 | 27 | } |
| 28 | - $html .= "<span id='view-post-btn'><a href='" . WL_CONFIG_TEST_GOOGLE_RICH_SNIPPETS_URL . |
|
| 29 | - urlencode( get_permalink( $post_id ) ) . |
|
| 30 | - "' class='button button-small wl-button' target='_blank'>" . |
|
| 31 | - esc_html__( 'Test Google Rich Snippets', 'wordlift' ) . |
|
| 28 | + $html .= "<span id='view-post-btn'><a href='".WL_CONFIG_TEST_GOOGLE_RICH_SNIPPETS_URL. |
|
| 29 | + urlencode(get_permalink($post_id)). |
|
| 30 | + "' class='button button-small wl-button' target='_blank'>". |
|
| 31 | + esc_html__('Test Google Rich Snippets', 'wordlift'). |
|
| 32 | 32 | "</a></span>\n"; |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | return $html; |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | -add_filter( 'get_sample_permalink_html', 'wl_admin_permalink_html', PHP_INT_MAX, 4 ); |
|
| 38 | +add_filter('get_sample_permalink_html', 'wl_admin_permalink_html', PHP_INT_MAX, 4); |
|
@@ -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 | */ |
@@ -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_Types_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_Types_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' ); |
@@ -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 |
@@ -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 | |
@@ -22,15 +22,15 @@ |
||
| 22 | 22 | */ |
| 23 | 23 | class Wordlift_Deactivator { |
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * Short Description. (use period) |
|
| 27 | - * |
|
| 28 | - * Long Description. |
|
| 29 | - * |
|
| 30 | - * @since 1.0.0 |
|
| 31 | - */ |
|
| 32 | - public static function deactivate() { |
|
| 25 | + /** |
|
| 26 | + * Short Description. (use period) |
|
| 27 | + * |
|
| 28 | + * Long Description. |
|
| 29 | + * |
|
| 30 | + * @since 1.0.0 |
|
| 31 | + */ |
|
| 32 | + public static function deactivate() { |
|
| 33 | 33 | |
| 34 | - } |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | 36 | } |
@@ -7,6 +7,6 @@ |
||
| 7 | 7 | */ |
| 8 | 8 | class Wordlift_Entity_Types_Taxonomy_Service { |
| 9 | 9 | |
| 10 | - const TAXONOMY_NAME = 'wl_entity_type'; |
|
| 10 | + const TAXONOMY_NAME = 'wl_entity_type'; |
|
| 11 | 11 | |
| 12 | 12 | } |
@@ -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 | } |
@@ -1,19 +1,19 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | // Include constants |
| 4 | -require_once( 'wordlift_core_constants.php' ); |
|
| 4 | +require_once('wordlift_core_constants.php'); |
|
| 5 | 5 | |
| 6 | 6 | // Include methods that deal with post/entity relations |
| 7 | -require_once( 'wordlift_core_post_entity_relations.php' ); |
|
| 7 | +require_once('wordlift_core_post_entity_relations.php'); |
|
| 8 | 8 | |
| 9 | 9 | // Include wl_schema api |
| 10 | -require_once( 'wordlift_core_schema_api.php' ); |
|
| 10 | +require_once('wordlift_core_schema_api.php'); |
|
| 11 | 11 | |
| 12 | 12 | // Include the Entity API which allow to query for entity posts. |
| 13 | -require_once( 'wordlift_core_entity_api.php' ); |
|
| 13 | +require_once('wordlift_core_entity_api.php'); |
|
| 14 | 14 | |
| 15 | 15 | // Include methods for Wordlift plugin install |
| 16 | -require_once( 'wordlift_core_install.php' ); |
|
| 16 | +require_once('wordlift_core_install.php'); |
|
| 17 | 17 | |
| 18 | 18 | // Include utility global functions |
| 19 | -require_once( 'wordlift_core_functions.php' ); |
|
| 20 | 19 | \ No newline at end of file |
| 20 | +require_once('wordlift_core_functions.php'); |
|
| 21 | 21 | \ No newline at end of file |
@@ -9,18 +9,18 @@ discard block |
||
| 9 | 9 | * @return array An array with information about the saved image (*path*: the local path to the image, *url*: the local |
| 10 | 10 | * url, *content_type*: the image content type) |
| 11 | 11 | */ |
| 12 | -function wl_save_image( $url ) { |
|
| 12 | +function wl_save_image($url) { |
|
| 13 | 13 | |
| 14 | - $parts = parse_url( $url ); |
|
| 14 | + $parts = parse_url($url); |
|
| 15 | 15 | $path = $parts['path']; |
| 16 | 16 | |
| 17 | 17 | // Get the bare filename (filename w/o the extension). |
| 18 | 18 | // Sanitize filename before saving the current image as attachment |
| 19 | 19 | // See https://codex.wordpress.org/Function_Reference/sanitize_file_name |
| 20 | - $basename = sanitize_file_name( pathinfo( $path, PATHINFO_FILENAME ) . '-' . uniqid( date( 'YmdH-' ) ) ); |
|
| 20 | + $basename = sanitize_file_name(pathinfo($path, PATHINFO_FILENAME).'-'.uniqid(date('YmdH-'))); |
|
| 21 | 21 | |
| 22 | 22 | // Chunk the bare name to get a subpath. |
| 23 | - $chunks = chunk_split( strtolower( $basename ), 3, DIRECTORY_SEPARATOR ); |
|
| 23 | + $chunks = chunk_split(strtolower($basename), 3, DIRECTORY_SEPARATOR); |
|
| 24 | 24 | |
| 25 | 25 | // Get the base dir. |
| 26 | 26 | $wp_upload_dir = wp_upload_dir(); |
@@ -28,22 +28,22 @@ discard block |
||
| 28 | 28 | $base_url = $wp_upload_dir['baseurl']; |
| 29 | 29 | |
| 30 | 30 | // Get the full path to the local filename. |
| 31 | - $image_path = '/' . $chunks; |
|
| 32 | - $image_full_path = $base_dir . $image_path; |
|
| 33 | - $image_full_url = $base_url . $image_path; |
|
| 31 | + $image_path = '/'.$chunks; |
|
| 32 | + $image_full_path = $base_dir.$image_path; |
|
| 33 | + $image_full_url = $base_url.$image_path; |
|
| 34 | 34 | |
| 35 | 35 | // Create the folders. |
| 36 | - if ( ! ( file_exists( $image_full_path ) && is_dir( $image_full_path ) ) ) { |
|
| 37 | - if ( false === mkdir( $image_full_path, 0777, true ) ) { |
|
| 38 | - wl_write_log( "wl_save_image : failed creating dir [ image full path :: $image_full_path ]\n" ); |
|
| 36 | + if ( ! (file_exists($image_full_path) && is_dir($image_full_path))) { |
|
| 37 | + if (false === mkdir($image_full_path, 0777, true)) { |
|
| 38 | + wl_write_log("wl_save_image : failed creating dir [ image full path :: $image_full_path ]\n"); |
|
| 39 | 39 | } |
| 40 | 40 | }; |
| 41 | 41 | |
| 42 | 42 | // Request the remote file. |
| 43 | - $response = wp_remote_get( $url ); |
|
| 44 | - $content_type = wp_remote_retrieve_header( $response, 'content-type' ); |
|
| 43 | + $response = wp_remote_get($url); |
|
| 44 | + $content_type = wp_remote_retrieve_header($response, 'content-type'); |
|
| 45 | 45 | |
| 46 | - switch ( $content_type ) { |
|
| 46 | + switch ($content_type) { |
|
| 47 | 47 | case 'image/jpeg': |
| 48 | 48 | case 'image/jpg': |
| 49 | 49 | $extension = ".jpg"; |
@@ -62,11 +62,11 @@ discard block |
||
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | // Complete the local filename. |
| 65 | - $image_full_path .= $basename . $extension; |
|
| 66 | - $image_full_url .= $basename . $extension; |
|
| 65 | + $image_full_path .= $basename.$extension; |
|
| 66 | + $image_full_url .= $basename.$extension; |
|
| 67 | 67 | |
| 68 | 68 | // Store the data locally. |
| 69 | - file_put_contents( $image_full_path, wp_remote_retrieve_body( $response ) ); |
|
| 69 | + file_put_contents($image_full_path, wp_remote_retrieve_body($response)); |
|
| 70 | 70 | |
| 71 | 71 | // wl_write_log( "wl_save_image [ url :: $url ][ content type :: $content_type ][ image full path :: $image_full_path ][ image full url :: $image_full_url ]\n" ); |
| 72 | 72 | |
@@ -10,69 +10,69 @@ |
||
| 10 | 10 | */ |
| 11 | 11 | function wl_save_image( $url ) { |
| 12 | 12 | |
| 13 | - $parts = parse_url( $url ); |
|
| 14 | - $path = $parts['path']; |
|
| 13 | + $parts = parse_url( $url ); |
|
| 14 | + $path = $parts['path']; |
|
| 15 | 15 | |
| 16 | - // Get the bare filename (filename w/o the extension). |
|
| 17 | - // Sanitize filename before saving the current image as attachment |
|
| 18 | - // See https://codex.wordpress.org/Function_Reference/sanitize_file_name |
|
| 19 | - $basename = sanitize_file_name( pathinfo( $path, PATHINFO_FILENAME ) . '-' . uniqid( date( 'YmdH-' ) ) ); |
|
| 16 | + // Get the bare filename (filename w/o the extension). |
|
| 17 | + // Sanitize filename before saving the current image as attachment |
|
| 18 | + // See https://codex.wordpress.org/Function_Reference/sanitize_file_name |
|
| 19 | + $basename = sanitize_file_name( pathinfo( $path, PATHINFO_FILENAME ) . '-' . uniqid( date( 'YmdH-' ) ) ); |
|
| 20 | 20 | |
| 21 | - // Chunk the bare name to get a subpath. |
|
| 22 | - $chunks = chunk_split( strtolower( $basename ), 3, DIRECTORY_SEPARATOR ); |
|
| 21 | + // Chunk the bare name to get a subpath. |
|
| 22 | + $chunks = chunk_split( strtolower( $basename ), 3, DIRECTORY_SEPARATOR ); |
|
| 23 | 23 | |
| 24 | - // Get the base dir. |
|
| 25 | - $wp_upload_dir = wp_upload_dir(); |
|
| 26 | - $base_dir = $wp_upload_dir['basedir']; |
|
| 27 | - $base_url = $wp_upload_dir['baseurl']; |
|
| 24 | + // Get the base dir. |
|
| 25 | + $wp_upload_dir = wp_upload_dir(); |
|
| 26 | + $base_dir = $wp_upload_dir['basedir']; |
|
| 27 | + $base_url = $wp_upload_dir['baseurl']; |
|
| 28 | 28 | |
| 29 | - // Get the full path to the local filename. |
|
| 30 | - $image_path = '/' . $chunks; |
|
| 31 | - $image_full_path = $base_dir . $image_path; |
|
| 32 | - $image_full_url = $base_url . $image_path; |
|
| 29 | + // Get the full path to the local filename. |
|
| 30 | + $image_path = '/' . $chunks; |
|
| 31 | + $image_full_path = $base_dir . $image_path; |
|
| 32 | + $image_full_url = $base_url . $image_path; |
|
| 33 | 33 | |
| 34 | - // Create the folders. |
|
| 35 | - if ( ! ( file_exists( $image_full_path ) && is_dir( $image_full_path ) ) ) { |
|
| 36 | - if ( false === mkdir( $image_full_path, 0777, true ) ) { |
|
| 37 | - wl_write_log( "wl_save_image : failed creating dir [ image full path :: $image_full_path ]\n" ); |
|
| 38 | - } |
|
| 39 | - }; |
|
| 34 | + // Create the folders. |
|
| 35 | + if ( ! ( file_exists( $image_full_path ) && is_dir( $image_full_path ) ) ) { |
|
| 36 | + if ( false === mkdir( $image_full_path, 0777, true ) ) { |
|
| 37 | + wl_write_log( "wl_save_image : failed creating dir [ image full path :: $image_full_path ]\n" ); |
|
| 38 | + } |
|
| 39 | + }; |
|
| 40 | 40 | |
| 41 | - // Request the remote file. |
|
| 42 | - $response = wp_remote_get( $url ); |
|
| 43 | - $content_type = wp_remote_retrieve_header( $response, 'content-type' ); |
|
| 41 | + // Request the remote file. |
|
| 42 | + $response = wp_remote_get( $url ); |
|
| 43 | + $content_type = wp_remote_retrieve_header( $response, 'content-type' ); |
|
| 44 | 44 | |
| 45 | - switch ( $content_type ) { |
|
| 46 | - case 'image/jpeg': |
|
| 47 | - case 'image/jpg': |
|
| 48 | - $extension = ".jpg"; |
|
| 49 | - break; |
|
| 50 | - case 'image/svg+xml': |
|
| 51 | - $extension = ".svg"; |
|
| 52 | - break; |
|
| 53 | - case 'image/gif': |
|
| 54 | - $extension = ".gif"; |
|
| 55 | - break; |
|
| 56 | - case 'image/png': |
|
| 57 | - $extension = ".png"; |
|
| 58 | - break; |
|
| 59 | - default: |
|
| 60 | - $extension = ''; |
|
| 61 | - } |
|
| 45 | + switch ( $content_type ) { |
|
| 46 | + case 'image/jpeg': |
|
| 47 | + case 'image/jpg': |
|
| 48 | + $extension = ".jpg"; |
|
| 49 | + break; |
|
| 50 | + case 'image/svg+xml': |
|
| 51 | + $extension = ".svg"; |
|
| 52 | + break; |
|
| 53 | + case 'image/gif': |
|
| 54 | + $extension = ".gif"; |
|
| 55 | + break; |
|
| 56 | + case 'image/png': |
|
| 57 | + $extension = ".png"; |
|
| 58 | + break; |
|
| 59 | + default: |
|
| 60 | + $extension = ''; |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - // Complete the local filename. |
|
| 64 | - $image_full_path .= $basename . $extension; |
|
| 65 | - $image_full_url .= $basename . $extension; |
|
| 63 | + // Complete the local filename. |
|
| 64 | + $image_full_path .= $basename . $extension; |
|
| 65 | + $image_full_url .= $basename . $extension; |
|
| 66 | 66 | |
| 67 | - // Store the data locally. |
|
| 68 | - file_put_contents( $image_full_path, wp_remote_retrieve_body( $response ) ); |
|
| 67 | + // Store the data locally. |
|
| 68 | + file_put_contents( $image_full_path, wp_remote_retrieve_body( $response ) ); |
|
| 69 | 69 | |
| 70 | - // wl_write_log( "wl_save_image [ url :: $url ][ content type :: $content_type ][ image full path :: $image_full_path ][ image full url :: $image_full_url ]\n" ); |
|
| 70 | + // wl_write_log( "wl_save_image [ url :: $url ][ content type :: $content_type ][ image full path :: $image_full_path ][ image full url :: $image_full_url ]\n" ); |
|
| 71 | 71 | |
| 72 | - // Return the path. |
|
| 73 | - return array( |
|
| 74 | - 'path' => $image_full_path, |
|
| 75 | - 'url' => $image_full_url, |
|
| 76 | - 'content_type' => $content_type, |
|
| 77 | - ); |
|
| 72 | + // Return the path. |
|
| 73 | + return array( |
|
| 74 | + 'path' => $image_full_path, |
|
| 75 | + 'url' => $image_full_url, |
|
| 76 | + 'content_type' => $content_type, |
|
| 77 | + ); |
|
| 78 | 78 | } |