@@ -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 | - __( '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 | - __( '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 | + __( '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 | + __( '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', 10, 4 ); |
| 39 | 39 | \ No newline at end of file |
@@ -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 | - __( '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 | + __('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 | - __( '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 | + __('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', 10, 4 ); |
|
| 39 | 38 | \ No newline at end of file |
| 39 | +add_filter('get_sample_permalink_html', 'wl_admin_permalink_html', 10, 4); |
|
| 40 | 40 | \ No newline at end of file |
@@ -266,6 +266,8 @@ discard block |
||
| 266 | 266 | * @param int $subject_id The post ID | The entity post ID. |
| 267 | 267 | * @param string $predicate Name of the relation: null | 'what' | 'where' | 'when' | 'who' |
| 268 | 268 | * @param string $post_status Filter by post status null | 'publish' | 'draft' | 'pending' | 'trash'. null means *any* post status |
| 269 | +* @param string $get |
|
| 270 | +* @param integer $item_id |
|
| 269 | 271 | * |
| 270 | 272 | * @return (array) Array of ids. |
| 271 | 273 | */ |
@@ -337,6 +339,8 @@ discard block |
||
| 337 | 339 | * @param int $object_id The entity ID or the post ID. |
| 338 | 340 | * @param string $predicate Name of the relation: null | 'what' | 'where' | 'when' | 'who' |
| 339 | 341 | * @param string $post_status Filter by post status null | 'publish' | 'draft' | 'pending' | 'trash'. null means *any* post status |
| 342 | +* @param string $get |
|
| 343 | +* @param integer $item_id |
|
| 340 | 344 | * |
| 341 | 345 | * @return (array) Array of objects. |
| 342 | 346 | */ |
@@ -7,11 +7,11 @@ discard block |
||
| 7 | 7 | * |
| 8 | 8 | * @return boolean Return true if supported, false otherwise |
| 9 | 9 | */ |
| 10 | -function wl_core_check_relation_predicate_is_supported( $predicate ) { |
|
| 10 | +function wl_core_check_relation_predicate_is_supported($predicate) { |
|
| 11 | 11 | |
| 12 | - return in_array( $predicate, array( |
|
| 12 | + return in_array($predicate, array( |
|
| 13 | 13 | WL_WHAT_RELATION, WL_WHEN_RELATION, WL_WHERE_RELATION, WL_WHO_RELATION |
| 14 | - ) ); |
|
| 14 | + )); |
|
| 15 | 15 | } |
| 16 | 16 | /** |
| 17 | 17 | * Return an array of validation rules used by wl_core_get_posts |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | */ |
| 21 | 21 | function wl_core_get_validation_rules() { |
| 22 | 22 | |
| 23 | - return unserialize( WL_CORE_GET_POSTS_VALIDATION_RULES ); |
|
| 23 | + return unserialize(WL_CORE_GET_POSTS_VALIDATION_RULES); |
|
| 24 | 24 | } |
| 25 | 25 | /** |
| 26 | 26 | * Return the wordlift relation instances table name |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | function wl_core_get_relation_instances_table_name() { |
| 31 | 31 | |
| 32 | 32 | global $wpdb; |
| 33 | - $table_name = $wpdb->prefix . WL_DB_RELATION_INSTANCES_TABLE_NAME; |
|
| 33 | + $table_name = $wpdb->prefix.WL_DB_RELATION_INSTANCES_TABLE_NAME; |
|
| 34 | 34 | return $table_name; |
| 35 | 35 | } |
| 36 | 36 | |
@@ -44,15 +44,15 @@ discard block |
||
| 44 | 44 | * @uses $wpdb->replace() to perform the query |
| 45 | 45 | * @return (integer|boolean) Return then relation instance ID or false |
| 46 | 46 | */ |
| 47 | -function wl_core_add_relation_instance( $subject_id, $predicate, $object_id ) { |
|
| 47 | +function wl_core_add_relation_instance($subject_id, $predicate, $object_id) { |
|
| 48 | 48 | |
| 49 | 49 | // Checks on subject and object |
| 50 | - if( !is_numeric( $subject_id ) || !is_numeric( $object_id ) ) { |
|
| 50 | + if ( ! is_numeric($subject_id) || ! is_numeric($object_id)) { |
|
| 51 | 51 | return false; |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | // Checks on the given relation |
| 55 | - if( !wl_core_check_relation_predicate_is_supported( $predicate ) ) { |
|
| 55 | + if ( ! wl_core_check_relation_predicate_is_supported($predicate)) { |
|
| 56 | 56 | return false; |
| 57 | 57 | } |
| 58 | 58 | |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | 'predicate' => $predicate, |
| 69 | 69 | 'object_id' => $object_id |
| 70 | 70 | ), |
| 71 | - array( '%d', '%s', '%d' ) |
|
| 71 | + array('%d', '%s', '%d') |
|
| 72 | 72 | ); |
| 73 | 73 | |
| 74 | 74 | // Return record id |
@@ -85,22 +85,22 @@ discard block |
||
| 85 | 85 | * |
| 86 | 86 | * @return (boolean) False for failure. True for success. |
| 87 | 87 | */ |
| 88 | -function wl_core_delete_relation_instance( $subject_id, $predicate, $object_id ) { |
|
| 88 | +function wl_core_delete_relation_instance($subject_id, $predicate, $object_id) { |
|
| 89 | 89 | |
| 90 | 90 | // Checks on subject and object |
| 91 | - if( !is_numeric( $subject_id ) || !is_numeric( $object_id ) ) { |
|
| 91 | + if ( ! is_numeric($subject_id) || ! is_numeric($object_id)) { |
|
| 92 | 92 | return false; |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | // Checks on the given relation |
| 96 | - if( !wl_core_check_relation_predicate_is_supported( $predicate ) ) { |
|
| 96 | + if ( ! wl_core_check_relation_predicate_is_supported($predicate)) { |
|
| 97 | 97 | return false; |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | // Prepare interaction with db |
| 101 | 101 | global $wpdb; |
| 102 | 102 | |
| 103 | - wl_write_log( "Going to delete relation instace [ subject_id :: $subject_id ] [ object_id :: $object_id ] [ predicate :: $predicate ]"); |
|
| 103 | + wl_write_log("Going to delete relation instace [ subject_id :: $subject_id ] [ object_id :: $object_id ] [ predicate :: $predicate ]"); |
|
| 104 | 104 | |
| 105 | 105 | // @see ttps://codex.wordpress.org/it:Riferimento_classi/wpdb#DELETE_di_righe |
| 106 | 106 | $wpdb->delete( |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | 'predicate' => $predicate, |
| 111 | 111 | 'object_id' => $object_id |
| 112 | 112 | ), |
| 113 | - array( '%d', '%s', '%d' ) |
|
| 113 | + array('%d', '%s', '%d') |
|
| 114 | 114 | ); |
| 115 | 115 | |
| 116 | 116 | return true; |
@@ -126,27 +126,27 @@ discard block |
||
| 126 | 126 | * |
| 127 | 127 | * @return (integer|boolean) Return the relation instances IDs or false |
| 128 | 128 | */ |
| 129 | -function wl_core_add_relation_instances( $subject_id, $predicate, $object_ids ) { |
|
| 129 | +function wl_core_add_relation_instances($subject_id, $predicate, $object_ids) { |
|
| 130 | 130 | |
| 131 | 131 | // Checks on subject and object |
| 132 | - if( !is_numeric( $subject_id ) ) { |
|
| 132 | + if ( ! is_numeric($subject_id)) { |
|
| 133 | 133 | return false; |
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | // Checks on the given relation |
| 137 | - if( !wl_core_check_relation_predicate_is_supported( $predicate ) ) { |
|
| 137 | + if ( ! wl_core_check_relation_predicate_is_supported($predicate)) { |
|
| 138 | 138 | return false; |
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | // Check $object_ids is an array |
| 142 | - if( !is_array( $object_ids ) || empty( $object_ids ) ) { |
|
| 142 | + if ( ! is_array($object_ids) || empty($object_ids)) { |
|
| 143 | 143 | return false; |
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | // Call method to check and add each single relation |
| 147 | 147 | $inserted_records_ids = array(); |
| 148 | - foreach ( $object_ids as $object_id ) { |
|
| 149 | - $new_record_id = wl_core_add_relation_instance( $subject_id, $predicate, $object_id ); |
|
| 148 | + foreach ($object_ids as $object_id) { |
|
| 149 | + $new_record_id = wl_core_add_relation_instance($subject_id, $predicate, $object_id); |
|
| 150 | 150 | $inserted_records_ids[] = $new_record_id; |
| 151 | 151 | } |
| 152 | 152 | |
@@ -161,10 +161,10 @@ discard block |
||
| 161 | 161 | * |
| 162 | 162 | * @return (boolean) False for failure. True for success. |
| 163 | 163 | */ |
| 164 | -function wl_core_delete_relation_instances( $subject_id ) { |
|
| 164 | +function wl_core_delete_relation_instances($subject_id) { |
|
| 165 | 165 | |
| 166 | 166 | // Checks on subject and object |
| 167 | - if( !is_numeric( $subject_id ) ) { |
|
| 167 | + if ( ! is_numeric($subject_id)) { |
|
| 168 | 168 | return false; |
| 169 | 169 | } |
| 170 | 170 | |
@@ -179,7 +179,7 @@ discard block |
||
| 179 | 179 | array( |
| 180 | 180 | 'subject_id' => $subject_id, |
| 181 | 181 | ), |
| 182 | - array( '%d' ) |
|
| 182 | + array('%d') |
|
| 183 | 183 | ); |
| 184 | 184 | |
| 185 | 185 | return true; |
@@ -196,16 +196,16 @@ discard block |
||
| 196 | 196 | * 'status' => null |
| 197 | 197 | * ); |
| 198 | 198 | */ |
| 199 | -function wl_core_validate_filters_for_related( $filters ) { |
|
| 199 | +function wl_core_validate_filters_for_related($filters) { |
|
| 200 | 200 | |
| 201 | - if( !is_array( $filters ) ) { |
|
| 201 | + if ( ! is_array($filters)) { |
|
| 202 | 202 | $filters = array(); |
| 203 | 203 | } |
| 204 | 204 | |
| 205 | - if( !isset( $filters['predicate'] )) { |
|
| 205 | + if ( ! isset($filters['predicate'])) { |
|
| 206 | 206 | $filters['predicate'] = null; |
| 207 | 207 | } |
| 208 | - if( !isset( $filters['status'] )) { |
|
| 208 | + if ( ! isset($filters['status'])) { |
|
| 209 | 209 | $filters['status'] = null; |
| 210 | 210 | } |
| 211 | 211 | |
@@ -228,11 +228,11 @@ discard block |
||
| 228 | 228 | * |
| 229 | 229 | * @return (array) Array of post entity objects. |
| 230 | 230 | */ |
| 231 | -function wl_core_get_related_entities( $subject_id, $filters = array() ) { |
|
| 231 | +function wl_core_get_related_entities($subject_id, $filters = array()) { |
|
| 232 | 232 | |
| 233 | - $filters = wl_core_validate_filters_for_related( $filters ); |
|
| 233 | + $filters = wl_core_validate_filters_for_related($filters); |
|
| 234 | 234 | |
| 235 | - return wl_core_inner_get_related_entities( "posts", $subject_id, $filters['predicate'], $filters['status'] ); |
|
| 235 | + return wl_core_inner_get_related_entities("posts", $subject_id, $filters['predicate'], $filters['status']); |
|
| 236 | 236 | } |
| 237 | 237 | |
| 238 | 238 | /** |
@@ -251,11 +251,11 @@ discard block |
||
| 251 | 251 | * |
| 252 | 252 | * @return (array) Array of post entity objects. |
| 253 | 253 | */ |
| 254 | -function wl_core_get_related_entity_ids( $subject_id, $filters = array() ) { |
|
| 254 | +function wl_core_get_related_entity_ids($subject_id, $filters = array()) { |
|
| 255 | 255 | |
| 256 | - $filters = wl_core_validate_filters_for_related( $filters ); |
|
| 256 | + $filters = wl_core_validate_filters_for_related($filters); |
|
| 257 | 257 | |
| 258 | - return wl_core_inner_get_related_entities( "post_ids", $subject_id, $filters['predicate'], $filters['status'] ); |
|
| 258 | + return wl_core_inner_get_related_entities("post_ids", $subject_id, $filters['predicate'], $filters['status']); |
|
| 259 | 259 | } |
| 260 | 260 | |
| 261 | 261 | /** |
@@ -269,16 +269,16 @@ discard block |
||
| 269 | 269 | * |
| 270 | 270 | * @return (array) Array of ids. |
| 271 | 271 | */ |
| 272 | -function wl_core_inner_get_related_entities( $get, $item_id, $predicate = null, $post_status = null ) { |
|
| 272 | +function wl_core_inner_get_related_entities($get, $item_id, $predicate = null, $post_status = null) { |
|
| 273 | 273 | |
| 274 | - if ( $results = wl_core_get_posts( array( |
|
| 274 | + if ($results = wl_core_get_posts(array( |
|
| 275 | 275 | 'get' => $get, |
| 276 | 276 | 'post_type' => 'entity', |
| 277 | 277 | 'post_status' => $post_status, |
| 278 | 278 | 'related_to' => $item_id, |
| 279 | 279 | 'as' => 'object', |
| 280 | 280 | 'with_predicate' => $predicate, |
| 281 | - ) ) ) { |
|
| 281 | + ))) { |
|
| 282 | 282 | return $results; |
| 283 | 283 | } |
| 284 | 284 | // If wl_core_get_posts return false then an empty array is returned |
@@ -301,11 +301,11 @@ discard block |
||
| 301 | 301 | * |
| 302 | 302 | * @return (array) Array of objects. |
| 303 | 303 | */ |
| 304 | -function wl_core_get_related_posts( $object_id, $filters = array() ) { |
|
| 304 | +function wl_core_get_related_posts($object_id, $filters = array()) { |
|
| 305 | 305 | |
| 306 | - $filters = wl_core_validate_filters_for_related( $filters ); |
|
| 306 | + $filters = wl_core_validate_filters_for_related($filters); |
|
| 307 | 307 | |
| 308 | - return wl_core_inner_get_related_posts( "posts", $object_id, $filters[ 'predicate' ], $filters[ 'status' ] ); |
|
| 308 | + return wl_core_inner_get_related_posts("posts", $object_id, $filters['predicate'], $filters['status']); |
|
| 309 | 309 | } |
| 310 | 310 | /** |
| 311 | 311 | * Find all post ids related to a given $object_id |
@@ -322,11 +322,11 @@ discard block |
||
| 322 | 322 | * </code> |
| 323 | 323 | * @return (array) Array of objects. |
| 324 | 324 | */ |
| 325 | -function wl_core_get_related_post_ids( $object_id, $filters = array() ) { |
|
| 325 | +function wl_core_get_related_post_ids($object_id, $filters = array()) { |
|
| 326 | 326 | |
| 327 | - $filters = wl_core_validate_filters_for_related( $filters ); |
|
| 327 | + $filters = wl_core_validate_filters_for_related($filters); |
|
| 328 | 328 | |
| 329 | - return wl_core_inner_get_related_posts( "post_ids", $object_id, $filters[ 'predicate' ], $filters[ 'status' ] ); |
|
| 329 | + return wl_core_inner_get_related_posts("post_ids", $object_id, $filters['predicate'], $filters['status']); |
|
| 330 | 330 | } |
| 331 | 331 | |
| 332 | 332 | /** |
@@ -340,35 +340,35 @@ discard block |
||
| 340 | 340 | * |
| 341 | 341 | * @return (array) Array of objects. |
| 342 | 342 | */ |
| 343 | -function wl_core_inner_get_related_posts( $get, $item_id, $predicate = null, $post_status = null ) { |
|
| 343 | +function wl_core_inner_get_related_posts($get, $item_id, $predicate = null, $post_status = null) { |
|
| 344 | 344 | |
| 345 | 345 | // Retrieve the post object |
| 346 | - $post = get_post( $item_id ); |
|
| 347 | - if ( null === $post ) { |
|
| 346 | + $post = get_post($item_id); |
|
| 347 | + if (null === $post) { |
|
| 348 | 348 | return array(); |
| 349 | 349 | } |
| 350 | 350 | |
| 351 | - if ( "entity" === $post->post_type ) { |
|
| 352 | - if ( $results = wl_core_get_posts( array( |
|
| 351 | + if ("entity" === $post->post_type) { |
|
| 352 | + if ($results = wl_core_get_posts(array( |
|
| 353 | 353 | 'get' => $get, |
| 354 | 354 | 'post_type' => 'post', |
| 355 | 355 | 'post_status' => $post_status, |
| 356 | 356 | 'related_to' => $item_id, |
| 357 | 357 | 'as' => 'subject', |
| 358 | 358 | 'with_predicate' => $predicate, |
| 359 | - ) ) ) { |
|
| 359 | + ))) { |
|
| 360 | 360 | return $results; |
| 361 | 361 | } |
| 362 | 362 | } else { |
| 363 | - if ( $results = wl_core_get_posts( array( |
|
| 363 | + if ($results = wl_core_get_posts(array( |
|
| 364 | 364 | 'get' => $get, |
| 365 | 365 | 'post_type' => 'post', |
| 366 | 366 | 'post_status' => $post_status, |
| 367 | - 'post__not_in' => array( $item_id ), |
|
| 368 | - 'related_to__in' => wl_core_get_related_entity_ids( $post->ID ), |
|
| 367 | + 'post__not_in' => array($item_id), |
|
| 368 | + 'related_to__in' => wl_core_get_related_entity_ids($post->ID), |
|
| 369 | 369 | 'as' => 'subject', |
| 370 | 370 | 'with_predicate' => $predicate, |
| 371 | - ) ) ) { |
|
| 371 | + ))) { |
|
| 372 | 372 | return $results; |
| 373 | 373 | } |
| 374 | 374 | } |
@@ -401,7 +401,7 @@ discard block |
||
| 401 | 401 | * |
| 402 | 402 | * @return string | false String representing a sql statement, or false in case of error |
| 403 | 403 | */ |
| 404 | -function wl_core_sql_query_builder( $args ) { |
|
| 404 | +function wl_core_sql_query_builder($args) { |
|
| 405 | 405 | |
| 406 | 406 | // Prepare interaction with db |
| 407 | 407 | global $wpdb; |
@@ -411,7 +411,7 @@ discard block |
||
| 411 | 411 | // Sql Action |
| 412 | 412 | $sql = "SELECT "; |
| 413 | 413 | // Determine what has to be returned depending on 'get' argument value |
| 414 | - switch ( $args[ 'get' ] ) { |
|
| 414 | + switch ($args['get']) { |
|
| 415 | 415 | case 'posts': |
| 416 | 416 | $sql .= "p.*"; |
| 417 | 417 | break; |
@@ -421,16 +421,16 @@ discard block |
||
| 421 | 421 | } |
| 422 | 422 | |
| 423 | 423 | // If we look for posts related as objects the JOIN has to be done with the object_id column and viceversa |
| 424 | - $join_column = $args[ 'as' ] . "_id"; |
|
| 424 | + $join_column = $args['as']."_id"; |
|
| 425 | 425 | |
| 426 | 426 | $sql .= " FROM $wpdb->posts as p JOIN $table_name as r ON p.id = r.$join_column"; |
| 427 | 427 | |
| 428 | 428 | // Sql add post type filter |
| 429 | - $sql .= $wpdb->prepare( " AND p.post_type = %s AND", $args[ 'post_type' ] ); |
|
| 429 | + $sql .= $wpdb->prepare(" AND p.post_type = %s AND", $args['post_type']); |
|
| 430 | 430 | |
| 431 | 431 | // Sql add post status filter |
| 432 | - if( isset( $args['post_status'] ) && !is_null( $args['post_status'] ) ) { |
|
| 433 | - $sql .= $wpdb->prepare( " p.post_status = %s AND", $args[ 'post_status' ] ); |
|
| 432 | + if (isset($args['post_status']) && ! is_null($args['post_status'])) { |
|
| 433 | + $sql .= $wpdb->prepare(" p.post_status = %s AND", $args['post_status']); |
|
| 434 | 434 | } |
| 435 | 435 | |
| 436 | 436 | // Add filtering conditions |
@@ -439,34 +439,34 @@ discard block |
||
| 439 | 439 | // If we look for posts related as subject this means that |
| 440 | 440 | // related_to is reference for an object: object_id is the filtering column |
| 441 | 441 | |
| 442 | - $filtering_column = ( 'object' == $args[ 'as' ] ) ? "subject_id" : "object_id"; |
|
| 442 | + $filtering_column = ('object' == $args['as']) ? "subject_id" : "object_id"; |
|
| 443 | 443 | |
| 444 | - if( isset( $args[ 'related_to' ] ) ) { |
|
| 445 | - $sql .= $wpdb->prepare( " r.$filtering_column = %d", $args[ 'related_to' ] ); |
|
| 444 | + if (isset($args['related_to'])) { |
|
| 445 | + $sql .= $wpdb->prepare(" r.$filtering_column = %d", $args['related_to']); |
|
| 446 | 446 | } |
| 447 | - if( isset( $args[ 'related_to' ] ) && isset($args[ 'related_to__in' ] ) ) { |
|
| 447 | + if (isset($args['related_to']) && isset($args['related_to__in'])) { |
|
| 448 | 448 | $sql .= " AND"; |
| 449 | 449 | } |
| 450 | - if( isset($args[ 'related_to__in' ] ) ) { |
|
| 451 | - $sql .= " r.$filtering_column IN (" . implode(",", $args[ 'related_to__in' ] ) . ")"; |
|
| 450 | + if (isset($args['related_to__in'])) { |
|
| 451 | + $sql .= " r.$filtering_column IN (".implode(",", $args['related_to__in']).")"; |
|
| 452 | 452 | } |
| 453 | - if( isset( $args[ 'post__not_in' ] ) ) { |
|
| 454 | - $sql .= " AND r." . $args[ 'as' ] . "_id NOT IN (" . implode(",", $args[ 'post__not_in' ] ) . ")"; |
|
| 453 | + if (isset($args['post__not_in'])) { |
|
| 454 | + $sql .= " AND r.".$args['as']."_id NOT IN (".implode(",", $args['post__not_in']).")"; |
|
| 455 | 455 | } |
| 456 | - if( isset( $args[ 'post__in' ] ) ) { |
|
| 457 | - $sql .= " AND r." . $args[ 'as' ] . "_id IN (" . implode(",", $args[ 'post__in' ] ) . ")"; |
|
| 456 | + if (isset($args['post__in'])) { |
|
| 457 | + $sql .= " AND r.".$args['as']."_id IN (".implode(",", $args['post__in']).")"; |
|
| 458 | 458 | } |
| 459 | 459 | // Add predicate filter if required |
| 460 | - if ( isset( $args[ 'with_predicate' ] ) ) { |
|
| 460 | + if (isset($args['with_predicate'])) { |
|
| 461 | 461 | // Sql Inner Join clausole |
| 462 | - $sql .= $wpdb->prepare( " AND r.predicate = %s", $args[ 'with_predicate' ] ); |
|
| 462 | + $sql .= $wpdb->prepare(" AND r.predicate = %s", $args['with_predicate']); |
|
| 463 | 463 | } |
| 464 | 464 | // Add a group by clousole to avoid duplicated rows |
| 465 | 465 | $sql .= " GROUP BY p.id"; |
| 466 | 466 | |
| 467 | - if ( isset( $args[ 'first' ] ) && is_numeric( $args[ 'first' ] ) ) { |
|
| 467 | + if (isset($args['first']) && is_numeric($args['first'])) { |
|
| 468 | 468 | // Sql Inner Join clausole |
| 469 | - $sql .= $wpdb->prepare( " LIMIT %d", $args[ 'first'] ); |
|
| 469 | + $sql .= $wpdb->prepare(" LIMIT %d", $args['first']); |
|
| 470 | 470 | } |
| 471 | 471 | // Close sql statement |
| 472 | 472 | $sql .= ";"; |
@@ -485,10 +485,10 @@ discard block |
||
| 485 | 485 | * |
| 486 | 486 | * @return (array) List of WP_Post objects or list of WP_Post ids. False in case of error or invalid params |
| 487 | 487 | */ |
| 488 | -function wl_core_get_posts( $args, $returned_type = OBJECT ) { |
|
| 488 | +function wl_core_get_posts($args, $returned_type = OBJECT) { |
|
| 489 | 489 | |
| 490 | 490 | // Merge given args with defaults args value |
| 491 | - $args = array_merge( array( |
|
| 491 | + $args = array_merge(array( |
|
| 492 | 492 | 'with_predicate' => null, |
| 493 | 493 | 'as' => 'subject', |
| 494 | 494 | 'post_type' => 'post', |
@@ -498,29 +498,29 @@ discard block |
||
| 498 | 498 | |
| 499 | 499 | // Arguments validation rules |
| 500 | 500 | // At least one between related_to and related_to__in has to be set |
| 501 | - if ( !isset( $args[ 'related_to' ] ) && !isset( $args[ 'related_to__in' ] ) ) { |
|
| 501 | + if ( ! isset($args['related_to']) && ! isset($args['related_to__in'])) { |
|
| 502 | 502 | return false; |
| 503 | 503 | } |
| 504 | - if ( isset( $args[ 'related_to' ] ) && !is_numeric( $args[ 'related_to' ] ) ) { |
|
| 504 | + if (isset($args['related_to']) && ! is_numeric($args['related_to'])) { |
|
| 505 | 505 | return false; |
| 506 | 506 | } |
| 507 | 507 | |
| 508 | 508 | // The same check is applied to post_in, post__not_in and related_to__in options |
| 509 | 509 | // Only arrays with at least one numeric value are considerad valid |
| 510 | 510 | // The argument value is further sanitized in order to clean up not numeric values |
| 511 | - foreach ( array( 'post__in', 'post__not_in', 'related_to__in' ) as $option_name ) { |
|
| 512 | - if ( isset( $args[ $option_name ] ) ) { |
|
| 513 | - if ( !is_array( $args[ $option_name ] ) || 0 == count( array_filter( $args[ $option_name ], "is_numeric" ) ) ) { |
|
| 511 | + foreach (array('post__in', 'post__not_in', 'related_to__in') as $option_name) { |
|
| 512 | + if (isset($args[$option_name])) { |
|
| 513 | + if ( ! is_array($args[$option_name]) || 0 == count(array_filter($args[$option_name], "is_numeric"))) { |
|
| 514 | 514 | return false; |
| 515 | 515 | } |
| 516 | 516 | // Sanitize value removing non numeric values from the array |
| 517 | - $args[ $option_name ] = array_filter( $args[ $option_name ], "is_numeric" ); |
|
| 517 | + $args[$option_name] = array_filter($args[$option_name], "is_numeric"); |
|
| 518 | 518 | } |
| 519 | 519 | } |
| 520 | 520 | // Performing validation rules |
| 521 | - foreach ( wl_core_get_validation_rules() as $option_name => $accepeted_values ) { |
|
| 522 | - if ( isset( $args[ $option_name ] ) && !is_null( $args[ $option_name ] ) ) { |
|
| 523 | - if ( !in_array( $args[ $option_name ], $accepeted_values ) ) { |
|
| 521 | + foreach (wl_core_get_validation_rules() as $option_name => $accepeted_values) { |
|
| 522 | + if (isset($args[$option_name]) && ! is_null($args[$option_name])) { |
|
| 523 | + if ( ! in_array($args[$option_name], $accepeted_values)) { |
|
| 524 | 524 | return false; |
| 525 | 525 | } |
| 526 | 526 | } |
@@ -529,21 +529,21 @@ discard block |
||
| 529 | 529 | // Prepare interaction with db |
| 530 | 530 | global $wpdb; |
| 531 | 531 | // Build sql statement with given arguments |
| 532 | - $sql_statement = wl_core_sql_query_builder( $args ); |
|
| 532 | + $sql_statement = wl_core_sql_query_builder($args); |
|
| 533 | 533 | |
| 534 | 534 | // wl_write_log( "Going to execute sql statement: $sql_statement " ); |
| 535 | 535 | // $results = array(); |
| 536 | 536 | |
| 537 | 537 | // If ids are required, returns a one-dimensional array containing ids. |
| 538 | 538 | // Otherwise an array of associative arrays representing the post | relation object |
| 539 | - if ( 'post_ids' == $args[ 'get' ] ) { |
|
| 539 | + if ('post_ids' == $args['get']) { |
|
| 540 | 540 | # See https://codex.wordpress.org/Class_Reference/wpdb#SELECT_a_Column |
| 541 | - $results = $wpdb->get_col( $sql_statement ); |
|
| 541 | + $results = $wpdb->get_col($sql_statement); |
|
| 542 | 542 | } else { |
| 543 | - $results = $wpdb->get_results( $sql_statement, $returned_type ); |
|
| 543 | + $results = $wpdb->get_results($sql_statement, $returned_type); |
|
| 544 | 544 | } |
| 545 | 545 | // If there were an error performing the query then false is returned |
| 546 | - if ( !empty( $wpdb->last_error ) ) { |
|
| 546 | + if ( ! empty($wpdb->last_error)) { |
|
| 547 | 547 | return false; |
| 548 | 548 | } |
| 549 | 549 | // Finally |
@@ -62,13 +62,13 @@ discard block |
||
| 62 | 62 | // Checks passed. Add relation if not exists |
| 63 | 63 | // See https://codex.wordpress.org/Class_Reference/wpdb#REPLACE_row |
| 64 | 64 | $wpdb->replace( |
| 65 | - wl_core_get_relation_instances_table_name(), |
|
| 66 | - array( |
|
| 65 | + wl_core_get_relation_instances_table_name(), |
|
| 66 | + array( |
|
| 67 | 67 | 'subject_id' => $subject_id, |
| 68 | - 'predicate' => $predicate, |
|
| 69 | - 'object_id' => $object_id |
|
| 70 | - ), |
|
| 71 | - array( '%d', '%s', '%d' ) |
|
| 68 | + 'predicate' => $predicate, |
|
| 69 | + 'object_id' => $object_id |
|
| 70 | + ), |
|
| 71 | + array( '%d', '%s', '%d' ) |
|
| 72 | 72 | ); |
| 73 | 73 | |
| 74 | 74 | // Return record id |
@@ -104,13 +104,13 @@ discard block |
||
| 104 | 104 | |
| 105 | 105 | // @see ttps://codex.wordpress.org/it:Riferimento_classi/wpdb#DELETE_di_righe |
| 106 | 106 | $wpdb->delete( |
| 107 | - wl_core_get_relation_instances_table_name(), |
|
| 108 | - array( |
|
| 107 | + wl_core_get_relation_instances_table_name(), |
|
| 108 | + array( |
|
| 109 | 109 | 'subject_id' => $subject_id, |
| 110 | 110 | 'predicate' => $predicate, |
| 111 | 111 | 'object_id' => $object_id |
| 112 | - ), |
|
| 113 | - array( '%d', '%s', '%d' ) |
|
| 112 | + ), |
|
| 113 | + array( '%d', '%s', '%d' ) |
|
| 114 | 114 | ); |
| 115 | 115 | |
| 116 | 116 | return true; |
@@ -175,11 +175,11 @@ discard block |
||
| 175 | 175 | |
| 176 | 176 | // @see ttps://codex.wordpress.org/it:Riferimento_classi/wpdb#DELETE_di_righe |
| 177 | 177 | $wpdb->delete( |
| 178 | - wl_core_get_relation_instances_table_name(), |
|
| 179 | - array( |
|
| 178 | + wl_core_get_relation_instances_table_name(), |
|
| 179 | + array( |
|
| 180 | 180 | 'subject_id' => $subject_id, |
| 181 | - ), |
|
| 182 | - array( '%d' ) |
|
| 181 | + ), |
|
| 182 | + array( '%d' ) |
|
| 183 | 183 | ); |
| 184 | 184 | |
| 185 | 185 | return true; |
@@ -170,9 +170,9 @@ |
||
| 170 | 170 | * Sets the entity type(s) for the specified post ID. Support is now for only one type per entity. |
| 171 | 171 | * |
| 172 | 172 | * @param $post_id numeric The numeric post ID |
| 173 | - * @param $type_names array An array of strings, each defining a type (e.g. Type, for the http://schema.org/Type) |
|
| 173 | + * @param string $type_names array An array of strings, each defining a type (e.g. Type, for the http://schema.org/Type) |
|
| 174 | 174 | * |
| 175 | - * @return boolean True if everything went ok, an error string otherwise. |
|
| 175 | + * @return boolean|null True if everything went ok, an error string otherwise. |
|
| 176 | 176 | */ |
| 177 | 177 | function wl_schema_set_types( $post_id, $type_names ) { |
| 178 | 178 | |
@@ -8,24 +8,24 @@ discard block |
||
| 8 | 8 | * |
| 9 | 9 | * @return boolean The method returns true if everything went ok, false otherwise. |
| 10 | 10 | */ |
| 11 | -function wl_schema_reset_value( $post_id, $property_name ) { |
|
| 11 | +function wl_schema_reset_value($post_id, $property_name) { |
|
| 12 | 12 | |
| 13 | 13 | // Some checks on the parameters |
| 14 | - if ( ! is_numeric( $post_id ) || is_null( $property_name ) ) { |
|
| 14 | + if ( ! is_numeric($post_id) || is_null($property_name)) { |
|
| 15 | 15 | return false; |
| 16 | 16 | } |
| 17 | 17 | |
| 18 | 18 | // Build full schema uri if necessary |
| 19 | - $property_name = wl_build_full_schema_uri_from_schema_slug( $property_name ); |
|
| 19 | + $property_name = wl_build_full_schema_uri_from_schema_slug($property_name); |
|
| 20 | 20 | |
| 21 | 21 | // Get accepted properties |
| 22 | - $accepted_fields = wl_entity_taxonomy_get_custom_fields( $post_id ); |
|
| 22 | + $accepted_fields = wl_entity_taxonomy_get_custom_fields($post_id); |
|
| 23 | 23 | |
| 24 | 24 | // Find the name of the custom-field managing the schema property |
| 25 | - foreach ( $accepted_fields as $wl_constant => $field ) { |
|
| 26 | - if ( $field['predicate'] == $property_name ) { |
|
| 25 | + foreach ($accepted_fields as $wl_constant => $field) { |
|
| 26 | + if ($field['predicate'] == $property_name) { |
|
| 27 | 27 | |
| 28 | - delete_post_meta( $post_id, $wl_constant ); |
|
| 28 | + delete_post_meta($post_id, $wl_constant); |
|
| 29 | 29 | |
| 30 | 30 | return true; |
| 31 | 31 | } |
@@ -42,32 +42,32 @@ discard block |
||
| 42 | 42 | * |
| 43 | 43 | * @return array An array of values or NULL in case of no values (or error). |
| 44 | 44 | */ |
| 45 | -function wl_schema_get_value( $post_id, $property_name ) { |
|
| 45 | +function wl_schema_get_value($post_id, $property_name) { |
|
| 46 | 46 | |
| 47 | 47 | // Property name must be defined. |
| 48 | - if ( ! isset( $property_name ) || is_null( $property_name ) ) { |
|
| 48 | + if ( ! isset($property_name) || is_null($property_name)) { |
|
| 49 | 49 | return null; |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | // store eventual schema name in different variable |
| 53 | - $property_schema_name = wl_build_full_schema_uri_from_schema_slug( $property_name ); |
|
| 53 | + $property_schema_name = wl_build_full_schema_uri_from_schema_slug($property_name); |
|
| 54 | 54 | |
| 55 | 55 | // Establish entity id. |
| 56 | - if ( is_null( $post_id ) || ! is_numeric( $post_id ) ) { |
|
| 56 | + if (is_null($post_id) || ! is_numeric($post_id)) { |
|
| 57 | 57 | $post_id = get_the_ID(); |
| 58 | - if ( is_null( $post_id ) || ! is_numeric( $post_id ) ) { |
|
| 58 | + if (is_null($post_id) || ! is_numeric($post_id)) { |
|
| 59 | 59 | return null; |
| 60 | 60 | } |
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | // Get custom fields. |
| 64 | - $term_mapping = wl_entity_taxonomy_get_custom_fields( $post_id ); |
|
| 64 | + $term_mapping = wl_entity_taxonomy_get_custom_fields($post_id); |
|
| 65 | 65 | // Search for the required meta value (by constant name or schema name) |
| 66 | - foreach ( $term_mapping as $wl_constant => $property_info ) { |
|
| 67 | - $found_constant = ( $wl_constant == $property_name ); |
|
| 68 | - $found_predicate = ( isset( $property_info['predicate'] ) && $property_info['predicate'] == $property_schema_name ); |
|
| 69 | - if ( $found_constant || $found_predicate ) { |
|
| 70 | - return get_post_meta( $post_id, $wl_constant ); |
|
| 66 | + foreach ($term_mapping as $wl_constant => $property_info) { |
|
| 67 | + $found_constant = ($wl_constant == $property_name); |
|
| 68 | + $found_predicate = (isset($property_info['predicate']) && $property_info['predicate'] == $property_schema_name); |
|
| 69 | + if ($found_constant || $found_predicate) { |
|
| 70 | + return get_post_meta($post_id, $wl_constant); |
|
| 71 | 71 | } |
| 72 | 72 | } |
| 73 | 73 | |
@@ -83,17 +83,17 @@ discard block |
||
| 83 | 83 | * |
| 84 | 84 | * @return array An array of values or NULL in case of no values (or error). |
| 85 | 85 | */ |
| 86 | -function wl_schema_add_value( $post_id, $property_name, $property_value ) { |
|
| 86 | +function wl_schema_add_value($post_id, $property_name, $property_value) { |
|
| 87 | 87 | |
| 88 | - if ( ! is_array( $property_value ) ) { |
|
| 89 | - $property_value = array( $property_value ); |
|
| 88 | + if ( ! is_array($property_value)) { |
|
| 89 | + $property_value = array($property_value); |
|
| 90 | 90 | } |
| 91 | 91 | |
| 92 | - $old_values = wl_schema_get_value( $post_id, $property_name ); |
|
| 92 | + $old_values = wl_schema_get_value($post_id, $property_name); |
|
| 93 | 93 | |
| 94 | - $merged_property_value = array_unique( array_merge( $property_value, $old_values ) ); |
|
| 94 | + $merged_property_value = array_unique(array_merge($property_value, $old_values)); |
|
| 95 | 95 | |
| 96 | - wl_schema_set_value( $post_id, $property_name, $merged_property_value ); |
|
| 96 | + wl_schema_set_value($post_id, $property_name, $merged_property_value); |
|
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | /** |
@@ -105,33 +105,33 @@ discard block |
||
| 105 | 105 | * |
| 106 | 106 | * @return boolean The method returns true if everything went ok, an error string otherwise. |
| 107 | 107 | */ |
| 108 | -function wl_schema_set_value( $post_id, $property_name, $property_value ) { |
|
| 108 | +function wl_schema_set_value($post_id, $property_name, $property_value) { |
|
| 109 | 109 | |
| 110 | 110 | // Some checks on the parameters |
| 111 | - if ( ! is_numeric( $post_id ) || is_null( $property_name ) || empty( $property_value ) || is_null( $property_value ) ) { |
|
| 111 | + if ( ! is_numeric($post_id) || is_null($property_name) || empty($property_value) || is_null($property_value)) { |
|
| 112 | 112 | return false; |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | // Build full schema uri if necessary |
| 116 | - $property_name = wl_build_full_schema_uri_from_schema_slug( $property_name ); |
|
| 116 | + $property_name = wl_build_full_schema_uri_from_schema_slug($property_name); |
|
| 117 | 117 | |
| 118 | 118 | // Get accepted properties |
| 119 | - $accepted_fields = wl_entity_taxonomy_get_custom_fields( $post_id ); |
|
| 119 | + $accepted_fields = wl_entity_taxonomy_get_custom_fields($post_id); |
|
| 120 | 120 | |
| 121 | 121 | // Find the name of the custom-field managing the schema property |
| 122 | - foreach ( $accepted_fields as $wl_constant => $field ) { |
|
| 123 | - if ( $field['predicate'] == $property_name ) { |
|
| 122 | + foreach ($accepted_fields as $wl_constant => $field) { |
|
| 123 | + if ($field['predicate'] == $property_name) { |
|
| 124 | 124 | |
| 125 | 125 | // Deal with single values |
| 126 | - if ( ! is_array( $property_value ) ) { |
|
| 127 | - $property_value = array( $property_value ); |
|
| 126 | + if ( ! is_array($property_value)) { |
|
| 127 | + $property_value = array($property_value); |
|
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | // Delete present meta |
| 131 | - delete_post_meta( $post_id, $wl_constant ); |
|
| 131 | + delete_post_meta($post_id, $wl_constant); |
|
| 132 | 132 | |
| 133 | - foreach ( $property_value as $value ) { |
|
| 134 | - add_post_meta( $post_id, $wl_constant, $value ); |
|
| 133 | + foreach ($property_value as $value) { |
|
| 134 | + add_post_meta($post_id, $wl_constant, $value); |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | return true; |
@@ -150,17 +150,17 @@ discard block |
||
| 150 | 150 | * @return array Array of type(s) (e.g. Type, for the http://schema.org/Type) |
| 151 | 151 | * or NULL in case of no values (or error). |
| 152 | 152 | */ |
| 153 | -function wl_schema_get_types( $post_id ) { |
|
| 153 | +function wl_schema_get_types($post_id) { |
|
| 154 | 154 | |
| 155 | 155 | // Some checks on the parameters |
| 156 | - if ( ! is_numeric( $post_id ) ) { |
|
| 156 | + if ( ! is_numeric($post_id)) { |
|
| 157 | 157 | return null; |
| 158 | 158 | } |
| 159 | 159 | |
| 160 | - $type = wl_entity_type_taxonomy_get_type( $post_id ); |
|
| 160 | + $type = wl_entity_type_taxonomy_get_type($post_id); |
|
| 161 | 161 | |
| 162 | - if ( isset( $type['uri'] ) ) { |
|
| 163 | - return array( $type['uri'] ); |
|
| 162 | + if (isset($type['uri'])) { |
|
| 163 | + return array($type['uri']); |
|
| 164 | 164 | } |
| 165 | 165 | |
| 166 | 166 | return null; |
@@ -174,23 +174,23 @@ discard block |
||
| 174 | 174 | * |
| 175 | 175 | * @return boolean True if everything went ok, an error string otherwise. |
| 176 | 176 | */ |
| 177 | -function wl_schema_set_types( $post_id, $type_names ) { |
|
| 177 | +function wl_schema_set_types($post_id, $type_names) { |
|
| 178 | 178 | |
| 179 | 179 | // Some checks on the parameters |
| 180 | - if ( ! is_numeric( $post_id ) || empty( $type_names ) || is_null( $type_names ) ) { |
|
| 180 | + if ( ! is_numeric($post_id) || empty($type_names) || is_null($type_names)) { |
|
| 181 | 181 | return null; |
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | // TODO: support more than one type |
| 185 | - if ( is_array( $type_names ) ) { |
|
| 185 | + if (is_array($type_names)) { |
|
| 186 | 186 | $type_names = $type_names[0]; |
| 187 | 187 | } |
| 188 | 188 | |
| 189 | 189 | // Build full schema uri if necessary |
| 190 | - $type_names = wl_build_full_schema_uri_from_schema_slug( $type_names ); |
|
| 190 | + $type_names = wl_build_full_schema_uri_from_schema_slug($type_names); |
|
| 191 | 191 | |
| 192 | 192 | // Actually sets the taxonomy type |
| 193 | - wl_set_entity_main_type( $post_id, $type_names ); |
|
| 193 | + wl_set_entity_main_type($post_id, $type_names); |
|
| 194 | 194 | } |
| 195 | 195 | |
| 196 | 196 | /** |
@@ -203,10 +203,10 @@ discard block |
||
| 203 | 203 | * @return array The method returns an array of supported properties for the type, e.g. (‘startDate’, ‘endDate’) for an Event. |
| 204 | 204 | * You can call wl_schema_get_property_expected_type on each to know which data type they expect. |
| 205 | 205 | */ |
| 206 | -function wl_schema_get_type_properties( $type_name ) { |
|
| 206 | +function wl_schema_get_type_properties($type_name) { |
|
| 207 | 207 | |
| 208 | 208 | // Build full schema uri if necessary |
| 209 | - $type_name = wl_build_full_schema_uri_from_schema_slug( $type_name ); |
|
| 209 | + $type_name = wl_build_full_schema_uri_from_schema_slug($type_name); |
|
| 210 | 210 | |
| 211 | 211 | // Get all custom fields |
| 212 | 212 | $all_types_and_fields = wl_entity_taxonomy_get_custom_fields(); |
@@ -215,10 +215,10 @@ discard block |
||
| 215 | 215 | $type_properties = array(); |
| 216 | 216 | |
| 217 | 217 | // Search for the entity type which has the requested name as uri |
| 218 | - if ( isset( $all_types_and_fields[ $type_name ] ) ) { |
|
| 219 | - foreach ( $all_types_and_fields[ $type_name ] as $field ) { |
|
| 218 | + if (isset($all_types_and_fields[$type_name])) { |
|
| 219 | + foreach ($all_types_and_fields[$type_name] as $field) { |
|
| 220 | 220 | // Convert to schema slug and store in array |
| 221 | - $type_properties[] = str_replace( $schema_root_address, '', $field['predicate'] ); |
|
| 221 | + $type_properties[] = str_replace($schema_root_address, '', $field['predicate']); |
|
| 222 | 222 | } |
| 223 | 223 | } |
| 224 | 224 | |
@@ -232,12 +232,12 @@ discard block |
||
| 232 | 232 | * |
| 233 | 233 | * @return string The full schema uri (es. 'latitude' returns 'http://schema.org/latitude') |
| 234 | 234 | */ |
| 235 | -function wl_build_full_schema_uri_from_schema_slug( $schema_name ) { |
|
| 235 | +function wl_build_full_schema_uri_from_schema_slug($schema_name) { |
|
| 236 | 236 | |
| 237 | 237 | $schema_root_address = 'http://schema.org/'; |
| 238 | 238 | |
| 239 | - if ( strpos( $schema_name, $schema_root_address ) === false ) { // === necessary |
|
| 240 | - $schema_name = $schema_root_address . $schema_name; |
|
| 239 | + if (strpos($schema_name, $schema_root_address) === false) { // === necessary |
|
| 240 | + $schema_name = $schema_root_address.$schema_name; |
|
| 241 | 241 | } |
| 242 | 242 | |
| 243 | 243 | return $schema_name; |
@@ -10,28 +10,28 @@ discard block |
||
| 10 | 10 | */ |
| 11 | 11 | function wl_schema_reset_value( $post_id, $property_name ) { |
| 12 | 12 | |
| 13 | - // Some checks on the parameters |
|
| 14 | - if ( ! is_numeric( $post_id ) || is_null( $property_name ) ) { |
|
| 15 | - return false; |
|
| 16 | - } |
|
| 13 | + // Some checks on the parameters |
|
| 14 | + if ( ! is_numeric( $post_id ) || is_null( $property_name ) ) { |
|
| 15 | + return false; |
|
| 16 | + } |
|
| 17 | 17 | |
| 18 | - // Build full schema uri if necessary |
|
| 19 | - $property_name = wl_build_full_schema_uri_from_schema_slug( $property_name ); |
|
| 18 | + // Build full schema uri if necessary |
|
| 19 | + $property_name = wl_build_full_schema_uri_from_schema_slug( $property_name ); |
|
| 20 | 20 | |
| 21 | - // Get accepted properties |
|
| 22 | - $accepted_fields = wl_entity_taxonomy_get_custom_fields( $post_id ); |
|
| 21 | + // Get accepted properties |
|
| 22 | + $accepted_fields = wl_entity_taxonomy_get_custom_fields( $post_id ); |
|
| 23 | 23 | |
| 24 | - // Find the name of the custom-field managing the schema property |
|
| 25 | - foreach ( $accepted_fields as $wl_constant => $field ) { |
|
| 26 | - if ( $field['predicate'] == $property_name ) { |
|
| 24 | + // Find the name of the custom-field managing the schema property |
|
| 25 | + foreach ( $accepted_fields as $wl_constant => $field ) { |
|
| 26 | + if ( $field['predicate'] == $property_name ) { |
|
| 27 | 27 | |
| 28 | - delete_post_meta( $post_id, $wl_constant ); |
|
| 28 | + delete_post_meta( $post_id, $wl_constant ); |
|
| 29 | 29 | |
| 30 | - return true; |
|
| 31 | - } |
|
| 32 | - } |
|
| 30 | + return true; |
|
| 31 | + } |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - return false; |
|
| 34 | + return false; |
|
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | /** |
@@ -44,34 +44,34 @@ discard block |
||
| 44 | 44 | */ |
| 45 | 45 | function wl_schema_get_value( $post_id, $property_name ) { |
| 46 | 46 | |
| 47 | - // Property name must be defined. |
|
| 48 | - if ( ! isset( $property_name ) || is_null( $property_name ) ) { |
|
| 49 | - return null; |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - // store eventual schema name in different variable |
|
| 53 | - $property_schema_name = wl_build_full_schema_uri_from_schema_slug( $property_name ); |
|
| 54 | - |
|
| 55 | - // Establish entity id. |
|
| 56 | - if ( is_null( $post_id ) || ! is_numeric( $post_id ) ) { |
|
| 57 | - $post_id = get_the_ID(); |
|
| 58 | - if ( is_null( $post_id ) || ! is_numeric( $post_id ) ) { |
|
| 59 | - return null; |
|
| 60 | - } |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - // Get custom fields. |
|
| 64 | - $term_mapping = wl_entity_taxonomy_get_custom_fields( $post_id ); |
|
| 65 | - // Search for the required meta value (by constant name or schema name) |
|
| 66 | - foreach ( $term_mapping as $wl_constant => $property_info ) { |
|
| 67 | - $found_constant = ( $wl_constant == $property_name ); |
|
| 68 | - $found_predicate = ( isset( $property_info['predicate'] ) && $property_info['predicate'] == $property_schema_name ); |
|
| 69 | - if ( $found_constant || $found_predicate ) { |
|
| 70 | - return get_post_meta( $post_id, $wl_constant ); |
|
| 71 | - } |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - return null; |
|
| 47 | + // Property name must be defined. |
|
| 48 | + if ( ! isset( $property_name ) || is_null( $property_name ) ) { |
|
| 49 | + return null; |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + // store eventual schema name in different variable |
|
| 53 | + $property_schema_name = wl_build_full_schema_uri_from_schema_slug( $property_name ); |
|
| 54 | + |
|
| 55 | + // Establish entity id. |
|
| 56 | + if ( is_null( $post_id ) || ! is_numeric( $post_id ) ) { |
|
| 57 | + $post_id = get_the_ID(); |
|
| 58 | + if ( is_null( $post_id ) || ! is_numeric( $post_id ) ) { |
|
| 59 | + return null; |
|
| 60 | + } |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + // Get custom fields. |
|
| 64 | + $term_mapping = wl_entity_taxonomy_get_custom_fields( $post_id ); |
|
| 65 | + // Search for the required meta value (by constant name or schema name) |
|
| 66 | + foreach ( $term_mapping as $wl_constant => $property_info ) { |
|
| 67 | + $found_constant = ( $wl_constant == $property_name ); |
|
| 68 | + $found_predicate = ( isset( $property_info['predicate'] ) && $property_info['predicate'] == $property_schema_name ); |
|
| 69 | + if ( $found_constant || $found_predicate ) { |
|
| 70 | + return get_post_meta( $post_id, $wl_constant ); |
|
| 71 | + } |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + return null; |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | /** |
@@ -85,15 +85,15 @@ discard block |
||
| 85 | 85 | */ |
| 86 | 86 | function wl_schema_add_value( $post_id, $property_name, $property_value ) { |
| 87 | 87 | |
| 88 | - if ( ! is_array( $property_value ) ) { |
|
| 89 | - $property_value = array( $property_value ); |
|
| 90 | - } |
|
| 88 | + if ( ! is_array( $property_value ) ) { |
|
| 89 | + $property_value = array( $property_value ); |
|
| 90 | + } |
|
| 91 | 91 | |
| 92 | - $old_values = wl_schema_get_value( $post_id, $property_name ); |
|
| 92 | + $old_values = wl_schema_get_value( $post_id, $property_name ); |
|
| 93 | 93 | |
| 94 | - $merged_property_value = array_unique( array_merge( $property_value, $old_values ) ); |
|
| 94 | + $merged_property_value = array_unique( array_merge( $property_value, $old_values ) ); |
|
| 95 | 95 | |
| 96 | - wl_schema_set_value( $post_id, $property_name, $merged_property_value ); |
|
| 96 | + wl_schema_set_value( $post_id, $property_name, $merged_property_value ); |
|
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | /** |
@@ -107,38 +107,38 @@ discard block |
||
| 107 | 107 | */ |
| 108 | 108 | function wl_schema_set_value( $post_id, $property_name, $property_value ) { |
| 109 | 109 | |
| 110 | - // Some checks on the parameters |
|
| 111 | - if ( ! is_numeric( $post_id ) || is_null( $property_name ) || empty( $property_value ) || is_null( $property_value ) ) { |
|
| 112 | - return false; |
|
| 113 | - } |
|
| 110 | + // Some checks on the parameters |
|
| 111 | + if ( ! is_numeric( $post_id ) || is_null( $property_name ) || empty( $property_value ) || is_null( $property_value ) ) { |
|
| 112 | + return false; |
|
| 113 | + } |
|
| 114 | 114 | |
| 115 | - // Build full schema uri if necessary |
|
| 116 | - $property_name = wl_build_full_schema_uri_from_schema_slug( $property_name ); |
|
| 115 | + // Build full schema uri if necessary |
|
| 116 | + $property_name = wl_build_full_schema_uri_from_schema_slug( $property_name ); |
|
| 117 | 117 | |
| 118 | - // Get accepted properties |
|
| 119 | - $accepted_fields = wl_entity_taxonomy_get_custom_fields( $post_id ); |
|
| 118 | + // Get accepted properties |
|
| 119 | + $accepted_fields = wl_entity_taxonomy_get_custom_fields( $post_id ); |
|
| 120 | 120 | |
| 121 | - // Find the name of the custom-field managing the schema property |
|
| 122 | - foreach ( $accepted_fields as $wl_constant => $field ) { |
|
| 123 | - if ( $field['predicate'] == $property_name ) { |
|
| 121 | + // Find the name of the custom-field managing the schema property |
|
| 122 | + foreach ( $accepted_fields as $wl_constant => $field ) { |
|
| 123 | + if ( $field['predicate'] == $property_name ) { |
|
| 124 | 124 | |
| 125 | - // Deal with single values |
|
| 126 | - if ( ! is_array( $property_value ) ) { |
|
| 127 | - $property_value = array( $property_value ); |
|
| 128 | - } |
|
| 125 | + // Deal with single values |
|
| 126 | + if ( ! is_array( $property_value ) ) { |
|
| 127 | + $property_value = array( $property_value ); |
|
| 128 | + } |
|
| 129 | 129 | |
| 130 | - // Delete present meta |
|
| 131 | - delete_post_meta( $post_id, $wl_constant ); |
|
| 130 | + // Delete present meta |
|
| 131 | + delete_post_meta( $post_id, $wl_constant ); |
|
| 132 | 132 | |
| 133 | - foreach ( $property_value as $value ) { |
|
| 134 | - add_post_meta( $post_id, $wl_constant, $value ); |
|
| 135 | - } |
|
| 133 | + foreach ( $property_value as $value ) { |
|
| 134 | + add_post_meta( $post_id, $wl_constant, $value ); |
|
| 135 | + } |
|
| 136 | 136 | |
| 137 | - return true; |
|
| 138 | - } |
|
| 139 | - } |
|
| 137 | + return true; |
|
| 138 | + } |
|
| 139 | + } |
|
| 140 | 140 | |
| 141 | - return false; |
|
| 141 | + return false; |
|
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | |
@@ -152,18 +152,18 @@ discard block |
||
| 152 | 152 | */ |
| 153 | 153 | function wl_schema_get_types( $post_id ) { |
| 154 | 154 | |
| 155 | - // Some checks on the parameters |
|
| 156 | - if ( ! is_numeric( $post_id ) ) { |
|
| 157 | - return null; |
|
| 158 | - } |
|
| 155 | + // Some checks on the parameters |
|
| 156 | + if ( ! is_numeric( $post_id ) ) { |
|
| 157 | + return null; |
|
| 158 | + } |
|
| 159 | 159 | |
| 160 | - $type = wl_entity_type_taxonomy_get_type( $post_id ); |
|
| 160 | + $type = wl_entity_type_taxonomy_get_type( $post_id ); |
|
| 161 | 161 | |
| 162 | - if ( isset( $type['uri'] ) ) { |
|
| 163 | - return array( $type['uri'] ); |
|
| 164 | - } |
|
| 162 | + if ( isset( $type['uri'] ) ) { |
|
| 163 | + return array( $type['uri'] ); |
|
| 164 | + } |
|
| 165 | 165 | |
| 166 | - return null; |
|
| 166 | + return null; |
|
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | /** |
@@ -176,23 +176,23 @@ discard block |
||
| 176 | 176 | */ |
| 177 | 177 | function wl_schema_set_types( $post_id, $type_names ) { |
| 178 | 178 | |
| 179 | - // Some checks on the parameters |
|
| 180 | - if ( ! is_numeric( $post_id ) || empty( $type_names ) || is_null( $type_names ) ) { |
|
| 181 | - return null; |
|
| 182 | - } |
|
| 179 | + // Some checks on the parameters |
|
| 180 | + if ( ! is_numeric( $post_id ) || empty( $type_names ) || is_null( $type_names ) ) { |
|
| 181 | + return null; |
|
| 182 | + } |
|
| 183 | 183 | |
| 184 | - // TODO: support more than one type |
|
| 185 | - if ( is_array( $type_names ) ) { |
|
| 186 | - $type_names = $type_names[0]; |
|
| 187 | - } |
|
| 184 | + // TODO: support more than one type |
|
| 185 | + if ( is_array( $type_names ) ) { |
|
| 186 | + $type_names = $type_names[0]; |
|
| 187 | + } |
|
| 188 | 188 | |
| 189 | - // Get the schema URI (e.g. http://schema.org/Thing) |
|
| 190 | - $type_names = wl_build_full_schema_uri_from_schema_slug( $type_names ); |
|
| 189 | + // Get the schema URI (e.g. http://schema.org/Thing) |
|
| 190 | + $type_names = wl_build_full_schema_uri_from_schema_slug( $type_names ); |
|
| 191 | 191 | |
| 192 | - Wordlift_Log_Service::get_logger('wl_schema_set_types')->debug("[ type names :: $type_names ]"); |
|
| 192 | + Wordlift_Log_Service::get_logger('wl_schema_set_types')->debug("[ type names :: $type_names ]"); |
|
| 193 | 193 | |
| 194 | - // Actually sets the taxonomy type |
|
| 195 | - wl_set_entity_main_type( $post_id, $type_names ); |
|
| 194 | + // Actually sets the taxonomy type |
|
| 195 | + wl_set_entity_main_type( $post_id, $type_names ); |
|
| 196 | 196 | |
| 197 | 197 | } |
| 198 | 198 | |
@@ -208,24 +208,24 @@ discard block |
||
| 208 | 208 | */ |
| 209 | 209 | function wl_schema_get_type_properties( $type_name ) { |
| 210 | 210 | |
| 211 | - // Build full schema uri if necessary |
|
| 212 | - $type_name = wl_build_full_schema_uri_from_schema_slug( $type_name ); |
|
| 211 | + // Build full schema uri if necessary |
|
| 212 | + $type_name = wl_build_full_schema_uri_from_schema_slug( $type_name ); |
|
| 213 | 213 | |
| 214 | - // Get all custom fields |
|
| 215 | - $all_types_and_fields = wl_entity_taxonomy_get_custom_fields(); |
|
| 214 | + // Get all custom fields |
|
| 215 | + $all_types_and_fields = wl_entity_taxonomy_get_custom_fields(); |
|
| 216 | 216 | |
| 217 | - $schema_root_address = 'http://schema.org/'; |
|
| 218 | - $type_properties = array(); |
|
| 217 | + $schema_root_address = 'http://schema.org/'; |
|
| 218 | + $type_properties = array(); |
|
| 219 | 219 | |
| 220 | - // Search for the entity type which has the requested name as uri |
|
| 221 | - if ( isset( $all_types_and_fields[ $type_name ] ) ) { |
|
| 222 | - foreach ( $all_types_and_fields[ $type_name ] as $field ) { |
|
| 223 | - // Convert to schema slug and store in array |
|
| 224 | - $type_properties[] = str_replace( $schema_root_address, '', $field['predicate'] ); |
|
| 225 | - } |
|
| 226 | - } |
|
| 220 | + // Search for the entity type which has the requested name as uri |
|
| 221 | + if ( isset( $all_types_and_fields[ $type_name ] ) ) { |
|
| 222 | + foreach ( $all_types_and_fields[ $type_name ] as $field ) { |
|
| 223 | + // Convert to schema slug and store in array |
|
| 224 | + $type_properties[] = str_replace( $schema_root_address, '', $field['predicate'] ); |
|
| 225 | + } |
|
| 226 | + } |
|
| 227 | 227 | |
| 228 | - return $type_properties; |
|
| 228 | + return $type_properties; |
|
| 229 | 229 | } |
| 230 | 230 | |
| 231 | 231 | /** |
@@ -237,11 +237,11 @@ discard block |
||
| 237 | 237 | */ |
| 238 | 238 | function wl_build_full_schema_uri_from_schema_slug( $schema_name ) { |
| 239 | 239 | |
| 240 | - $schema_root_address = 'http://schema.org/'; |
|
| 240 | + $schema_root_address = 'http://schema.org/'; |
|
| 241 | 241 | |
| 242 | - if ( strpos( $schema_name, $schema_root_address ) === false ) { // === necessary |
|
| 243 | - $schema_name = $schema_root_address . $schema_name; |
|
| 244 | - } |
|
| 242 | + if ( strpos( $schema_name, $schema_root_address ) === false ) { // === necessary |
|
| 243 | + $schema_name = $schema_root_address . $schema_name; |
|
| 244 | + } |
|
| 245 | 245 | |
| 246 | - return $schema_name; |
|
| 246 | + return $schema_name; |
|
| 247 | 247 | } |
| 248 | 248 | \ No newline at end of file |
@@ -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 | */ |
@@ -14,56 +14,56 @@ discard block |
||
| 14 | 14 | */ |
| 15 | 15 | function wl_shortcode_geomap_get_places( $post_id = null ) { |
| 16 | 16 | |
| 17 | - // If $post_id is null or is not numeric it means this is a global geomap |
|
| 18 | - $is_global = is_null( $post_id ) || ! is_numeric( $post_id ); |
|
| 17 | + // If $post_id is null or is not numeric it means this is a global geomap |
|
| 18 | + $is_global = is_null( $post_id ) || ! is_numeric( $post_id ); |
|
| 19 | 19 | |
| 20 | - // If the current one is not a global geomap, retrieve related entities ids |
|
| 21 | - if ( $is_global ) { |
|
| 22 | - $related_ids = array(); |
|
| 23 | - } else { |
|
| 24 | - $related_ids = wl_core_get_related_entity_ids( $post_id, array( |
|
| 25 | - 'status' => 'publish' |
|
| 26 | - ) ); |
|
| 20 | + // If the current one is not a global geomap, retrieve related entities ids |
|
| 21 | + if ( $is_global ) { |
|
| 22 | + $related_ids = array(); |
|
| 23 | + } else { |
|
| 24 | + $related_ids = wl_core_get_related_entity_ids( $post_id, array( |
|
| 25 | + 'status' => 'publish' |
|
| 26 | + ) ); |
|
| 27 | 27 | |
| 28 | - // Also include current entity |
|
| 29 | - if ( Wordlift_Entity_Service::get_instance()->is_entity( $post_id ) ) { |
|
| 30 | - $related_ids[] = $post_id; |
|
| 31 | - } |
|
| 32 | - } |
|
| 28 | + // Also include current entity |
|
| 29 | + if ( Wordlift_Entity_Service::get_instance()->is_entity( $post_id ) ) { |
|
| 30 | + $related_ids[] = $post_id; |
|
| 31 | + } |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - // If is not a global geomap, an empty $related_ids means that no entities are related to the post |
|
| 35 | - // An empty array can be returned in this case |
|
| 36 | - if ( ! $is_global && empty( $related_ids ) ) { |
|
| 37 | - return array(); |
|
| 38 | - } |
|
| 34 | + // If is not a global geomap, an empty $related_ids means that no entities are related to the post |
|
| 35 | + // An empty array can be returned in this case |
|
| 36 | + if ( ! $is_global && empty( $related_ids ) ) { |
|
| 37 | + return array(); |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - // Retrieve all 'published' places with geo coordinates defined |
|
| 41 | - // If $related_ids is not empty, it's used to limit query results to the current post related places |
|
| 42 | - // Please note that when $place_ids is an empty array, the 'post__in' parameter is not considered in the query |
|
| 43 | - return get_posts( array( |
|
| 44 | - 'post__in' => $related_ids, |
|
| 45 | - 'post_type' => Wordlift_Entity_Service::TYPE_NAME, |
|
| 46 | - 'nopaging' => true, |
|
| 47 | - 'post_status' => 'publish', |
|
| 48 | - 'meta_query' => array( |
|
| 49 | - 'relation' => 'AND', |
|
| 50 | - array( |
|
| 51 | - 'key' => Wordlift_Schema_Service::FIELD_GEO_LATITUDE, |
|
| 52 | - 'value' => null, |
|
| 53 | - 'compare' => '!=', |
|
| 54 | - ), |
|
| 55 | - array( |
|
| 56 | - 'key' => Wordlift_Schema_Service::FIELD_GEO_LONGITUDE, |
|
| 57 | - 'value' => null, |
|
| 58 | - 'compare' => '!=', |
|
| 59 | - ) |
|
| 60 | - ), |
|
| 61 | - 'tax_query' => array( |
|
| 62 | - 'taxonomy' => Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, |
|
| 63 | - 'field' => 'slug', |
|
| 64 | - 'terms' => 'place' |
|
| 65 | - ) |
|
| 66 | - ) ); |
|
| 40 | + // Retrieve all 'published' places with geo coordinates defined |
|
| 41 | + // If $related_ids is not empty, it's used to limit query results to the current post related places |
|
| 42 | + // Please note that when $place_ids is an empty array, the 'post__in' parameter is not considered in the query |
|
| 43 | + return get_posts( array( |
|
| 44 | + 'post__in' => $related_ids, |
|
| 45 | + 'post_type' => Wordlift_Entity_Service::TYPE_NAME, |
|
| 46 | + 'nopaging' => true, |
|
| 47 | + 'post_status' => 'publish', |
|
| 48 | + 'meta_query' => array( |
|
| 49 | + 'relation' => 'AND', |
|
| 50 | + array( |
|
| 51 | + 'key' => Wordlift_Schema_Service::FIELD_GEO_LATITUDE, |
|
| 52 | + 'value' => null, |
|
| 53 | + 'compare' => '!=', |
|
| 54 | + ), |
|
| 55 | + array( |
|
| 56 | + 'key' => Wordlift_Schema_Service::FIELD_GEO_LONGITUDE, |
|
| 57 | + 'value' => null, |
|
| 58 | + 'compare' => '!=', |
|
| 59 | + ) |
|
| 60 | + ), |
|
| 61 | + 'tax_query' => array( |
|
| 62 | + 'taxonomy' => Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, |
|
| 63 | + 'field' => 'slug', |
|
| 64 | + 'terms' => 'place' |
|
| 65 | + ) |
|
| 66 | + ) ); |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | /** |
@@ -78,88 +78,88 @@ discard block |
||
| 78 | 78 | */ |
| 79 | 79 | function wl_shortcode_geomap_prepare_map( $places ) { |
| 80 | 80 | |
| 81 | - // Prepare for min/max lat/long in case we need to define a view boundary for the client JavaScript. |
|
| 82 | - $min_latitude = PHP_INT_MAX; |
|
| 83 | - $min_longitude = PHP_INT_MAX; |
|
| 84 | - $max_latitude = ~PHP_INT_MAX; |
|
| 85 | - $max_longitude = ~PHP_INT_MAX; |
|
| 81 | + // Prepare for min/max lat/long in case we need to define a view boundary for the client JavaScript. |
|
| 82 | + $min_latitude = PHP_INT_MAX; |
|
| 83 | + $min_longitude = PHP_INT_MAX; |
|
| 84 | + $max_latitude = ~PHP_INT_MAX; |
|
| 85 | + $max_longitude = ~PHP_INT_MAX; |
|
| 86 | 86 | |
| 87 | - // Prepare an empty array of POIs in geoJSON format. |
|
| 88 | - $pois = array(); |
|
| 89 | - // And store list of points to allow Leaflet compute the optimal bounding box. |
|
| 90 | - // The main reason for this is that geoJSON has swapped coordinates (lon. lat) |
|
| 91 | - $boundaries = array(); |
|
| 87 | + // Prepare an empty array of POIs in geoJSON format. |
|
| 88 | + $pois = array(); |
|
| 89 | + // And store list of points to allow Leaflet compute the optimal bounding box. |
|
| 90 | + // The main reason for this is that geoJSON has swapped coordinates (lon. lat) |
|
| 91 | + $boundaries = array(); |
|
| 92 | 92 | |
| 93 | - // Add a POI for each entity that has coordinates. |
|
| 94 | - foreach ( $places as $entity ) { |
|
| 93 | + // Add a POI for each entity that has coordinates. |
|
| 94 | + foreach ( $places as $entity ) { |
|
| 95 | 95 | |
| 96 | - // Get the coordinates. |
|
| 97 | - $coordinates = wl_get_coordinates( $entity->ID ); |
|
| 96 | + // Get the coordinates. |
|
| 97 | + $coordinates = wl_get_coordinates( $entity->ID ); |
|
| 98 | 98 | |
| 99 | - // Don't show the widget if the coordinates aren't set. |
|
| 100 | - if ( $coordinates['latitude'] == 0 || $coordinates['longitude'] == 0 ) { |
|
| 101 | - continue; |
|
| 102 | - } |
|
| 99 | + // Don't show the widget if the coordinates aren't set. |
|
| 100 | + if ( $coordinates['latitude'] == 0 || $coordinates['longitude'] == 0 ) { |
|
| 101 | + continue; |
|
| 102 | + } |
|
| 103 | 103 | |
| 104 | - // TODO Map html rendering should be delegated to the wordlift js ui layer |
|
| 105 | - // This function should be focused on returning pure data instead |
|
| 104 | + // TODO Map html rendering should be delegated to the wordlift js ui layer |
|
| 105 | + // This function should be focused on returning pure data instead |
|
| 106 | 106 | |
| 107 | - // Get the title, URL and thumb of the entity. |
|
| 108 | - $title = esc_attr( $entity->post_title ); |
|
| 109 | - $link = esc_attr( get_permalink( $entity->ID ) ); |
|
| 110 | - if ( '' !== ( $thumbnail_id = get_post_thumbnail_id( $entity->ID ) ) && |
|
| 111 | - false !== ( $attachment = wp_get_attachment_image_src( $thumbnail_id ) ) |
|
| 112 | - ) { |
|
| 113 | - $img_src = esc_attr( $attachment[0] ); |
|
| 114 | - } |
|
| 107 | + // Get the title, URL and thumb of the entity. |
|
| 108 | + $title = esc_attr( $entity->post_title ); |
|
| 109 | + $link = esc_attr( get_permalink( $entity->ID ) ); |
|
| 110 | + if ( '' !== ( $thumbnail_id = get_post_thumbnail_id( $entity->ID ) ) && |
|
| 111 | + false !== ( $attachment = wp_get_attachment_image_src( $thumbnail_id ) ) |
|
| 112 | + ) { |
|
| 113 | + $img_src = esc_attr( $attachment[0] ); |
|
| 114 | + } |
|
| 115 | 115 | |
| 116 | - // Build HTML popup. TODO: move thumb width in css |
|
| 117 | - $content = "<a href=$link><h6>$title</h6>"; |
|
| 118 | - if ( isset( $img_src ) ) { |
|
| 119 | - $content = $content . "<img src=$img_src style='width:100%'/>"; |
|
| 120 | - } |
|
| 121 | - $content = $content . "</a><ul>"; |
|
| 122 | - // Get the related posts (published) and print them in the popup. |
|
| 123 | - $related_posts = wl_core_get_related_post_ids( $entity->ID, array( |
|
| 124 | - 'status' => 'publish' |
|
| 125 | - ) ); |
|
| 126 | - foreach ( $related_posts as $rp_id ) { |
|
| 116 | + // Build HTML popup. TODO: move thumb width in css |
|
| 117 | + $content = "<a href=$link><h6>$title</h6>"; |
|
| 118 | + if ( isset( $img_src ) ) { |
|
| 119 | + $content = $content . "<img src=$img_src style='width:100%'/>"; |
|
| 120 | + } |
|
| 121 | + $content = $content . "</a><ul>"; |
|
| 122 | + // Get the related posts (published) and print them in the popup. |
|
| 123 | + $related_posts = wl_core_get_related_post_ids( $entity->ID, array( |
|
| 124 | + 'status' => 'publish' |
|
| 125 | + ) ); |
|
| 126 | + foreach ( $related_posts as $rp_id ) { |
|
| 127 | 127 | |
| 128 | - $rp = get_post( $rp_id ); |
|
| 129 | - $title = esc_attr( $rp->post_title ); |
|
| 130 | - $link = esc_attr( get_permalink( $rp->ID ) ); |
|
| 131 | - $content = $content . "<li><a href=$link>$title</a></li>"; |
|
| 132 | - } |
|
| 133 | - $content = $content . "</ul>"; |
|
| 128 | + $rp = get_post( $rp_id ); |
|
| 129 | + $title = esc_attr( $rp->post_title ); |
|
| 130 | + $link = esc_attr( get_permalink( $rp->ID ) ); |
|
| 131 | + $content = $content . "<li><a href=$link>$title</a></li>"; |
|
| 132 | + } |
|
| 133 | + $content = $content . "</ul>"; |
|
| 134 | 134 | |
| 135 | - // Formatting POI in geoJSON. |
|
| 136 | - // http://leafletjs.com/examples/geojson.html |
|
| 137 | - $poi = array( |
|
| 138 | - 'type' => 'Feature', |
|
| 139 | - 'properties' => array( 'popupContent' => $content ), |
|
| 140 | - 'geometry' => array( |
|
| 141 | - 'type' => 'Point', |
|
| 142 | - 'coordinates' => array( |
|
| 143 | - // Leaflet geoJSON wants them swapped |
|
| 144 | - $coordinates['longitude'], |
|
| 145 | - $coordinates['latitude'] |
|
| 146 | - ) |
|
| 147 | - ) |
|
| 148 | - ); |
|
| 135 | + // Formatting POI in geoJSON. |
|
| 136 | + // http://leafletjs.com/examples/geojson.html |
|
| 137 | + $poi = array( |
|
| 138 | + 'type' => 'Feature', |
|
| 139 | + 'properties' => array( 'popupContent' => $content ), |
|
| 140 | + 'geometry' => array( |
|
| 141 | + 'type' => 'Point', |
|
| 142 | + 'coordinates' => array( |
|
| 143 | + // Leaflet geoJSON wants them swapped |
|
| 144 | + $coordinates['longitude'], |
|
| 145 | + $coordinates['latitude'] |
|
| 146 | + ) |
|
| 147 | + ) |
|
| 148 | + ); |
|
| 149 | 149 | |
| 150 | - $pois[] = $poi; |
|
| 150 | + $pois[] = $poi; |
|
| 151 | 151 | |
| 152 | - // Formatting boundaries in a Leaflet-like format (see LatLngBounds). |
|
| 153 | - // http://leafletjs.com/reference.html#latlngbounds |
|
| 154 | - $boundaries[] = array( $coordinates['latitude'], $coordinates['longitude'] ); |
|
| 152 | + // Formatting boundaries in a Leaflet-like format (see LatLngBounds). |
|
| 153 | + // http://leafletjs.com/reference.html#latlngbounds |
|
| 154 | + $boundaries[] = array( $coordinates['latitude'], $coordinates['longitude'] ); |
|
| 155 | 155 | |
| 156 | - } |
|
| 156 | + } |
|
| 157 | 157 | |
| 158 | - $map_data = array(); |
|
| 159 | - $map_data['features'] = $pois; |
|
| 160 | - $map_data['boundaries'] = $boundaries; |
|
| 158 | + $map_data = array(); |
|
| 159 | + $map_data['features'] = $pois; |
|
| 160 | + $map_data['boundaries'] = $boundaries; |
|
| 161 | 161 | |
| 162 | - return $map_data; |
|
| 162 | + return $map_data; |
|
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | /** |
@@ -173,13 +173,13 @@ discard block |
||
| 173 | 173 | * @return array An array of place posts. |
| 174 | 174 | */ |
| 175 | 175 | function wl_shortcode_geomap_ajax() { |
| 176 | - // Get the post Id. |
|
| 177 | - $post_id = ( isset( $_REQUEST['post_id'] ) ? $_REQUEST['post_id'] : null ); |
|
| 176 | + // Get the post Id. |
|
| 177 | + $post_id = ( isset( $_REQUEST['post_id'] ) ? $_REQUEST['post_id'] : null ); |
|
| 178 | 178 | |
| 179 | - $places = wl_shortcode_geomap_get_places( $post_id ); |
|
| 180 | - $map_data = wl_shortcode_geomap_prepare_map( $places ); |
|
| 179 | + $places = wl_shortcode_geomap_get_places( $post_id ); |
|
| 180 | + $map_data = wl_shortcode_geomap_prepare_map( $places ); |
|
| 181 | 181 | |
| 182 | - wl_core_send_json( $map_data ); |
|
| 182 | + wl_core_send_json( $map_data ); |
|
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | add_action( 'wp_ajax_wl_geomap', 'wl_shortcode_geomap_ajax' ); |
@@ -12,35 +12,35 @@ discard block |
||
| 12 | 12 | * |
| 13 | 13 | * @return array An array of place posts. |
| 14 | 14 | */ |
| 15 | -function wl_shortcode_geomap_get_places( $post_id = null ) { |
|
| 15 | +function wl_shortcode_geomap_get_places($post_id = null) { |
|
| 16 | 16 | |
| 17 | 17 | // If $post_id is null or is not numeric it means this is a global geomap |
| 18 | - $is_global = is_null( $post_id ) || ! is_numeric( $post_id ); |
|
| 18 | + $is_global = is_null($post_id) || ! is_numeric($post_id); |
|
| 19 | 19 | |
| 20 | 20 | // If the current one is not a global geomap, retrieve related entities ids |
| 21 | - if ( $is_global ) { |
|
| 21 | + if ($is_global) { |
|
| 22 | 22 | $related_ids = array(); |
| 23 | 23 | } else { |
| 24 | - $related_ids = wl_core_get_related_entity_ids( $post_id, array( |
|
| 24 | + $related_ids = wl_core_get_related_entity_ids($post_id, array( |
|
| 25 | 25 | 'status' => 'publish' |
| 26 | - ) ); |
|
| 26 | + )); |
|
| 27 | 27 | |
| 28 | 28 | // Also include current entity |
| 29 | - if ( Wordlift_Entity_Service::get_instance()->is_entity( $post_id ) ) { |
|
| 29 | + if (Wordlift_Entity_Service::get_instance()->is_entity($post_id)) { |
|
| 30 | 30 | $related_ids[] = $post_id; |
| 31 | 31 | } |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | // If is not a global geomap, an empty $related_ids means that no entities are related to the post |
| 35 | 35 | // An empty array can be returned in this case |
| 36 | - if ( ! $is_global && empty( $related_ids ) ) { |
|
| 36 | + if ( ! $is_global && empty($related_ids)) { |
|
| 37 | 37 | return array(); |
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | // Retrieve all 'published' places with geo coordinates defined |
| 41 | 41 | // If $related_ids is not empty, it's used to limit query results to the current post related places |
| 42 | 42 | // Please note that when $place_ids is an empty array, the 'post__in' parameter is not considered in the query |
| 43 | - return get_posts( array( |
|
| 43 | + return get_posts(array( |
|
| 44 | 44 | 'post__in' => $related_ids, |
| 45 | 45 | 'post_type' => Wordlift_Entity_Service::TYPE_NAME, |
| 46 | 46 | 'nopaging' => true, |
@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | 'field' => 'slug', |
| 64 | 64 | 'terms' => 'place' |
| 65 | 65 | ) |
| 66 | - ) ); |
|
| 66 | + )); |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | /** |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | * |
| 77 | 77 | * @return array An array of markers and boundaries for Leaflet. |
| 78 | 78 | */ |
| 79 | -function wl_shortcode_geomap_prepare_map( $places ) { |
|
| 79 | +function wl_shortcode_geomap_prepare_map($places) { |
|
| 80 | 80 | |
| 81 | 81 | // Prepare for min/max lat/long in case we need to define a view boundary for the client JavaScript. |
| 82 | 82 | $min_latitude = PHP_INT_MAX; |
@@ -91,13 +91,13 @@ discard block |
||
| 91 | 91 | $boundaries = array(); |
| 92 | 92 | |
| 93 | 93 | // Add a POI for each entity that has coordinates. |
| 94 | - foreach ( $places as $entity ) { |
|
| 94 | + foreach ($places as $entity) { |
|
| 95 | 95 | |
| 96 | 96 | // Get the coordinates. |
| 97 | - $coordinates = wl_get_coordinates( $entity->ID ); |
|
| 97 | + $coordinates = wl_get_coordinates($entity->ID); |
|
| 98 | 98 | |
| 99 | 99 | // Don't show the widget if the coordinates aren't set. |
| 100 | - if ( $coordinates['latitude'] == 0 || $coordinates['longitude'] == 0 ) { |
|
| 100 | + if ($coordinates['latitude'] == 0 || $coordinates['longitude'] == 0) { |
|
| 101 | 101 | continue; |
| 102 | 102 | } |
| 103 | 103 | |
@@ -105,38 +105,38 @@ discard block |
||
| 105 | 105 | // This function should be focused on returning pure data instead |
| 106 | 106 | |
| 107 | 107 | // Get the title, URL and thumb of the entity. |
| 108 | - $title = esc_attr( $entity->post_title ); |
|
| 109 | - $link = esc_attr( get_permalink( $entity->ID ) ); |
|
| 110 | - if ( '' !== ( $thumbnail_id = get_post_thumbnail_id( $entity->ID ) ) && |
|
| 111 | - false !== ( $attachment = wp_get_attachment_image_src( $thumbnail_id ) ) |
|
| 108 | + $title = esc_attr($entity->post_title); |
|
| 109 | + $link = esc_attr(get_permalink($entity->ID)); |
|
| 110 | + if ('' !== ($thumbnail_id = get_post_thumbnail_id($entity->ID)) && |
|
| 111 | + false !== ($attachment = wp_get_attachment_image_src($thumbnail_id)) |
|
| 112 | 112 | ) { |
| 113 | - $img_src = esc_attr( $attachment[0] ); |
|
| 113 | + $img_src = esc_attr($attachment[0]); |
|
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | // Build HTML popup. TODO: move thumb width in css |
| 117 | 117 | $content = "<a href=$link><h6>$title</h6>"; |
| 118 | - if ( isset( $img_src ) ) { |
|
| 119 | - $content = $content . "<img src=$img_src style='width:100%'/>"; |
|
| 118 | + if (isset($img_src)) { |
|
| 119 | + $content = $content."<img src=$img_src style='width:100%'/>"; |
|
| 120 | 120 | } |
| 121 | - $content = $content . "</a><ul>"; |
|
| 121 | + $content = $content."</a><ul>"; |
|
| 122 | 122 | // Get the related posts (published) and print them in the popup. |
| 123 | - $related_posts = wl_core_get_related_post_ids( $entity->ID, array( |
|
| 123 | + $related_posts = wl_core_get_related_post_ids($entity->ID, array( |
|
| 124 | 124 | 'status' => 'publish' |
| 125 | - ) ); |
|
| 126 | - foreach ( $related_posts as $rp_id ) { |
|
| 125 | + )); |
|
| 126 | + foreach ($related_posts as $rp_id) { |
|
| 127 | 127 | |
| 128 | - $rp = get_post( $rp_id ); |
|
| 129 | - $title = esc_attr( $rp->post_title ); |
|
| 130 | - $link = esc_attr( get_permalink( $rp->ID ) ); |
|
| 131 | - $content = $content . "<li><a href=$link>$title</a></li>"; |
|
| 128 | + $rp = get_post($rp_id); |
|
| 129 | + $title = esc_attr($rp->post_title); |
|
| 130 | + $link = esc_attr(get_permalink($rp->ID)); |
|
| 131 | + $content = $content."<li><a href=$link>$title</a></li>"; |
|
| 132 | 132 | } |
| 133 | - $content = $content . "</ul>"; |
|
| 133 | + $content = $content."</ul>"; |
|
| 134 | 134 | |
| 135 | 135 | // Formatting POI in geoJSON. |
| 136 | 136 | // http://leafletjs.com/examples/geojson.html |
| 137 | 137 | $poi = array( |
| 138 | 138 | 'type' => 'Feature', |
| 139 | - 'properties' => array( 'popupContent' => $content ), |
|
| 139 | + 'properties' => array('popupContent' => $content), |
|
| 140 | 140 | 'geometry' => array( |
| 141 | 141 | 'type' => 'Point', |
| 142 | 142 | 'coordinates' => array( |
@@ -151,7 +151,7 @@ discard block |
||
| 151 | 151 | |
| 152 | 152 | // Formatting boundaries in a Leaflet-like format (see LatLngBounds). |
| 153 | 153 | // http://leafletjs.com/reference.html#latlngbounds |
| 154 | - $boundaries[] = array( $coordinates['latitude'], $coordinates['longitude'] ); |
|
| 154 | + $boundaries[] = array($coordinates['latitude'], $coordinates['longitude']); |
|
| 155 | 155 | |
| 156 | 156 | } |
| 157 | 157 | |
@@ -174,16 +174,16 @@ discard block |
||
| 174 | 174 | */ |
| 175 | 175 | function wl_shortcode_geomap_ajax() { |
| 176 | 176 | // Get the post Id. |
| 177 | - $post_id = ( isset( $_REQUEST['post_id'] ) ? $_REQUEST['post_id'] : null ); |
|
| 177 | + $post_id = (isset($_REQUEST['post_id']) ? $_REQUEST['post_id'] : null); |
|
| 178 | 178 | |
| 179 | - $places = wl_shortcode_geomap_get_places( $post_id ); |
|
| 180 | - $map_data = wl_shortcode_geomap_prepare_map( $places ); |
|
| 179 | + $places = wl_shortcode_geomap_get_places($post_id); |
|
| 180 | + $map_data = wl_shortcode_geomap_prepare_map($places); |
|
| 181 | 181 | |
| 182 | - wl_core_send_json( $map_data ); |
|
| 182 | + wl_core_send_json($map_data); |
|
| 183 | 183 | } |
| 184 | 184 | |
| 185 | -add_action( 'wp_ajax_wl_geomap', 'wl_shortcode_geomap_ajax' ); |
|
| 186 | -add_action( 'wp_ajax_nopriv_wl_geomap', 'wl_shortcode_geomap_ajax' ); |
|
| 185 | +add_action('wp_ajax_wl_geomap', 'wl_shortcode_geomap_ajax'); |
|
| 186 | +add_action('wp_ajax_nopriv_wl_geomap', 'wl_shortcode_geomap_ajax'); |
|
| 187 | 187 | |
| 188 | 188 | ///** |
| 189 | 189 | // * 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 | |
@@ -1,54 +1,54 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -function wordlift_ajax_related_posts( $http_raw_data = null ) { |
|
| 3 | +function wordlift_ajax_related_posts($http_raw_data = null) { |
|
| 4 | 4 | |
| 5 | 5 | // Extract filtering conditions |
| 6 | - if( !isset( $_GET["post_id"] ) || !is_numeric( $_GET["post_id"] ) ) { |
|
| 6 | + if ( ! isset($_GET["post_id"]) || ! is_numeric($_GET["post_id"])) { |
|
| 7 | 7 | wp_die('Post id missing or invalid!'); |
| 8 | 8 | return; |
| 9 | 9 | } |
| 10 | 10 | |
| 11 | 11 | $post_id = $_GET["post_id"]; |
| 12 | 12 | // Get the current post |
| 13 | - $post = get_post( $post_id ); |
|
| 13 | + $post = get_post($post_id); |
|
| 14 | 14 | |
| 15 | - wl_write_log( "Going to find posts related to current with post id: $post_id ..." ); |
|
| 15 | + wl_write_log("Going to find posts related to current with post id: $post_id ..."); |
|
| 16 | 16 | |
| 17 | 17 | // Extract filtering conditions |
| 18 | - $filtering_entity_uris = ( null == $http_raw_data ) ? file_get_contents("php://input") : $http_raw_data; |
|
| 19 | - $filtering_entity_uris = json_decode( $filtering_entity_uris ); |
|
| 18 | + $filtering_entity_uris = (null == $http_raw_data) ? file_get_contents("php://input") : $http_raw_data; |
|
| 19 | + $filtering_entity_uris = json_decode($filtering_entity_uris); |
|
| 20 | 20 | |
| 21 | - $filtering_entity_ids = wl_get_entity_post_ids_by_uris( $filtering_entity_uris ); |
|
| 21 | + $filtering_entity_ids = wl_get_entity_post_ids_by_uris($filtering_entity_uris); |
|
| 22 | 22 | $related_posts = array(); |
| 23 | 23 | |
| 24 | 24 | // If the current post is an antity |
| 25 | 25 | // related posts to the current entity are returned |
| 26 | - if ( Wordlift_Entity_Service::TYPE_NAME == $post->post_type ) { |
|
| 27 | - $filtering_entity_ids = array( $post_id ); |
|
| 26 | + if (Wordlift_Entity_Service::TYPE_NAME == $post->post_type) { |
|
| 27 | + $filtering_entity_ids = array($post_id); |
|
| 28 | 28 | } |
| 29 | 29 | |
| 30 | - if ( !empty( $filtering_entity_ids ) ) { |
|
| 30 | + if ( ! empty($filtering_entity_ids)) { |
|
| 31 | 31 | |
| 32 | - $related_posts = wl_core_get_posts( array( |
|
| 32 | + $related_posts = wl_core_get_posts(array( |
|
| 33 | 33 | 'get' => 'posts', |
| 34 | 34 | 'related_to__in' => $filtering_entity_ids, |
| 35 | - 'post__not_in' => array( $post_id ), |
|
| 35 | + 'post__not_in' => array($post_id), |
|
| 36 | 36 | 'post_type' => 'post', |
| 37 | 37 | 'post_status' => 'publish', |
| 38 | 38 | 'as' => 'subject', |
| 39 | - ) ); |
|
| 39 | + )); |
|
| 40 | 40 | |
| 41 | - foreach ( $related_posts as $post_obj ) { |
|
| 41 | + foreach ($related_posts as $post_obj) { |
|
| 42 | 42 | |
| 43 | - $thumbnail = wp_get_attachment_url( get_post_thumbnail_id( $post_obj->ID, 'thumbnail' ) ); |
|
| 44 | - $post_obj->thumbnail = ( $thumbnail ) ? $thumbnail : WL_DEFAULT_THUMBNAIL_PATH; |
|
| 45 | - $post_obj->link = get_edit_post_link( $post_obj->ID, 'none' ); |
|
| 46 | - $post_obj->permalink = get_post_permalink( $post_obj->ID ); |
|
| 43 | + $thumbnail = wp_get_attachment_url(get_post_thumbnail_id($post_obj->ID, 'thumbnail')); |
|
| 44 | + $post_obj->thumbnail = ($thumbnail) ? $thumbnail : WL_DEFAULT_THUMBNAIL_PATH; |
|
| 45 | + $post_obj->link = get_edit_post_link($post_obj->ID, 'none'); |
|
| 46 | + $post_obj->permalink = get_post_permalink($post_obj->ID); |
|
| 47 | 47 | |
| 48 | 48 | } |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | - wl_core_send_json( $related_posts ); |
|
| 51 | + wl_core_send_json($related_posts); |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | -add_action( 'wp_ajax_wordlift_related_posts', 'wordlift_ajax_related_posts' ); |
|
| 54 | +add_action('wp_ajax_wordlift_related_posts', 'wordlift_ajax_related_posts'); |
|
@@ -23,19 +23,19 @@ discard block |
||
| 23 | 23 | */ |
| 24 | 24 | function wl_transition_post_status( $new_status, $old_status, $post ) { |
| 25 | 25 | |
| 26 | - // wl_write_log( "wl_transition_post_status [ new status :: $new_status ][ old status :: $old_status ][ post ID :: $post->ID ]" ); |
|
| 27 | - |
|
| 28 | - // transition from *published* to any other status: delete the post. |
|
| 29 | - if ( 'publish' === $old_status && 'publish' !== $new_status ) { |
|
| 30 | - rl_delete_post( $post ); |
|
| 31 | - } |
|
| 32 | - |
|
| 33 | - // when a post is published, then all the referenced entities must be published. |
|
| 34 | - if ( 'publish' !== $old_status && 'publish' === $new_status ) { |
|
| 35 | - foreach ( wl_core_get_related_entity_ids( $post->ID ) as $entity_id ) { |
|
| 36 | - wl_update_post_status( $entity_id, 'publish' ); |
|
| 37 | - } |
|
| 38 | - } |
|
| 26 | + // wl_write_log( "wl_transition_post_status [ new status :: $new_status ][ old status :: $old_status ][ post ID :: $post->ID ]" ); |
|
| 27 | + |
|
| 28 | + // transition from *published* to any other status: delete the post. |
|
| 29 | + if ( 'publish' === $old_status && 'publish' !== $new_status ) { |
|
| 30 | + rl_delete_post( $post ); |
|
| 31 | + } |
|
| 32 | + |
|
| 33 | + // when a post is published, then all the referenced entities must be published. |
|
| 34 | + if ( 'publish' !== $old_status && 'publish' === $new_status ) { |
|
| 35 | + foreach ( wl_core_get_related_entity_ids( $post->ID ) as $entity_id ) { |
|
| 36 | + wl_update_post_status( $entity_id, 'publish' ); |
|
| 37 | + } |
|
| 38 | + } |
|
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | // hook save events. |
@@ -49,49 +49,49 @@ discard block |
||
| 49 | 49 | */ |
| 50 | 50 | function rl_delete_post( $post ) { |
| 51 | 51 | |
| 52 | - $post_id = ( is_numeric( $post ) ? $post : $post->ID ); |
|
| 52 | + $post_id = ( is_numeric( $post ) ? $post : $post->ID ); |
|
| 53 | 53 | |
| 54 | - // hide all entities that are not referenced by any published post. |
|
| 55 | - foreach ( wl_core_get_related_entity_ids( $post_id ) as $entity_id ) { |
|
| 54 | + // hide all entities that are not referenced by any published post. |
|
| 55 | + foreach ( wl_core_get_related_entity_ids( $post_id ) as $entity_id ) { |
|
| 56 | 56 | |
| 57 | - // check if there is at least one referencing post published. |
|
| 58 | - $is_published = array_reduce( wl_core_get_related_post_ids( $entity_id ), function ( $carry, $item ) { |
|
| 57 | + // check if there is at least one referencing post published. |
|
| 58 | + $is_published = array_reduce( wl_core_get_related_post_ids( $entity_id ), function ( $carry, $item ) { |
|
| 59 | 59 | $post = get_post( $item ); |
| 60 | 60 | return ( $carry || ( 'publish' === $post->post_status ) ); |
| 61 | - } ); |
|
| 62 | - // set the entity to draft if no referencing posts are published. |
|
| 63 | - if ( ! $is_published ) { |
|
| 64 | - wl_update_post_status( $entity_id, 'draft' ); |
|
| 65 | - } |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - // get the entity URI (valid also for posts) |
|
| 69 | - $uri_esc = wl_sparql_escape_uri( wl_get_entity_uri( $post_id ) ); |
|
| 70 | - |
|
| 71 | - wl_write_log( "rl_delete_post [ post id :: $post_id ][ uri esc :: $uri_esc ]" ); |
|
| 72 | - |
|
| 73 | - // create the SPARQL statement by joining the SPARQL prefixes and deleting any known predicate. |
|
| 74 | - $stmt = rl_sparql_prefixes(); |
|
| 75 | - foreach ( wl_predicates() as $predicate ) { |
|
| 76 | - $stmt .= "DELETE { <$uri_esc> $predicate ?o . } WHERE { <$uri_esc> $predicate ?o . };\n" . |
|
| 77 | - "DELETE { ?s $predicate <$uri_esc> . } WHERE { ?s $predicate <$uri_esc> . };\n"; |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - // if the post is an entity and has exported properties, delete the related predicates. |
|
| 81 | - if ( Wordlift_Entity_Service::TYPE_NAME === $post->post_type ) { |
|
| 82 | - $type = wl_entity_type_taxonomy_get_type( $post->ID ); |
|
| 83 | - |
|
| 84 | - if ( isset( $type['custom_fields'] ) ) { |
|
| 85 | - foreach ( $type['custom_fields'] as $field => $params ) { |
|
| 86 | - // TODO: enclose in <> only if predicate starts with http(s):// |
|
| 87 | - $predicate = '<' . $params['predicate'] . '>'; |
|
| 88 | - $stmt .= "DELETE { <$uri_esc> $predicate ?o . } WHERE { <$uri_esc> $predicate ?o . };\n"; |
|
| 89 | - } |
|
| 90 | - } |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - // finally execute the query. |
|
| 94 | - rl_execute_sparql_update_query( $stmt ); |
|
| 61 | + } ); |
|
| 62 | + // set the entity to draft if no referencing posts are published. |
|
| 63 | + if ( ! $is_published ) { |
|
| 64 | + wl_update_post_status( $entity_id, 'draft' ); |
|
| 65 | + } |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + // get the entity URI (valid also for posts) |
|
| 69 | + $uri_esc = wl_sparql_escape_uri( wl_get_entity_uri( $post_id ) ); |
|
| 70 | + |
|
| 71 | + wl_write_log( "rl_delete_post [ post id :: $post_id ][ uri esc :: $uri_esc ]" ); |
|
| 72 | + |
|
| 73 | + // create the SPARQL statement by joining the SPARQL prefixes and deleting any known predicate. |
|
| 74 | + $stmt = rl_sparql_prefixes(); |
|
| 75 | + foreach ( wl_predicates() as $predicate ) { |
|
| 76 | + $stmt .= "DELETE { <$uri_esc> $predicate ?o . } WHERE { <$uri_esc> $predicate ?o . };\n" . |
|
| 77 | + "DELETE { ?s $predicate <$uri_esc> . } WHERE { ?s $predicate <$uri_esc> . };\n"; |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + // if the post is an entity and has exported properties, delete the related predicates. |
|
| 81 | + if ( Wordlift_Entity_Service::TYPE_NAME === $post->post_type ) { |
|
| 82 | + $type = wl_entity_type_taxonomy_get_type( $post->ID ); |
|
| 83 | + |
|
| 84 | + if ( isset( $type['custom_fields'] ) ) { |
|
| 85 | + foreach ( $type['custom_fields'] as $field => $params ) { |
|
| 86 | + // TODO: enclose in <> only if predicate starts with http(s):// |
|
| 87 | + $predicate = '<' . $params['predicate'] . '>'; |
|
| 88 | + $stmt .= "DELETE { <$uri_esc> $predicate ?o . } WHERE { <$uri_esc> $predicate ?o . };\n"; |
|
| 89 | + } |
|
| 90 | + } |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + // finally execute the query. |
|
| 94 | + rl_execute_sparql_update_query( $stmt ); |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | /** |
@@ -102,34 +102,34 @@ discard block |
||
| 102 | 102 | */ |
| 103 | 103 | function wl_update_post_status( $post_id, $status ) { |
| 104 | 104 | |
| 105 | - wl_write_log( "wl_update_post_status [ post ID :: $post_id ][ status :: $status ]" ); |
|
| 105 | + wl_write_log( "wl_update_post_status [ post ID :: $post_id ][ status :: $status ]" ); |
|
| 106 | 106 | |
| 107 | - global $wpdb; |
|
| 107 | + global $wpdb; |
|
| 108 | 108 | |
| 109 | - if ( ! $post = get_post( $post_id ) ) { |
|
| 110 | - return; |
|
| 111 | - } |
|
| 109 | + if ( ! $post = get_post( $post_id ) ) { |
|
| 110 | + return; |
|
| 111 | + } |
|
| 112 | 112 | |
| 113 | - if ( $status === $post->post_status ) { |
|
| 114 | - return; |
|
| 115 | - } |
|
| 113 | + if ( $status === $post->post_status ) { |
|
| 114 | + return; |
|
| 115 | + } |
|
| 116 | 116 | |
| 117 | - $wpdb->update( $wpdb->posts, array( 'post_status' => $status ), array( 'ID' => $post->ID ) ); |
|
| 117 | + $wpdb->update( $wpdb->posts, array( 'post_status' => $status ), array( 'ID' => $post->ID ) ); |
|
| 118 | 118 | |
| 119 | - clean_post_cache( $post->ID ); |
|
| 119 | + clean_post_cache( $post->ID ); |
|
| 120 | 120 | |
| 121 | - $old_status = $post->post_status; |
|
| 122 | - $post->post_status = $status; |
|
| 121 | + $old_status = $post->post_status; |
|
| 122 | + $post->post_status = $status; |
|
| 123 | 123 | |
| 124 | - wp_transition_post_status( $status, $old_status, $post ); |
|
| 124 | + wp_transition_post_status( $status, $old_status, $post ); |
|
| 125 | 125 | |
| 126 | - /** This action is documented in wp-includes/post.php */ |
|
| 127 | - do_action( 'edit_post', $post->ID, $post ); |
|
| 128 | - /** This action is documented in wp-includes/post.php */ |
|
| 129 | - do_action( "save_post_{$post->post_type}", $post->ID, $post, true ); |
|
| 130 | - /** This action is documented in wp-includes/post.php */ |
|
| 131 | - do_action( 'wl_linked_data_save_post', $post->ID ); |
|
| 132 | - /** This action is documented in wp-includes/post.php */ |
|
| 133 | - do_action( 'wp_insert_post', $post->ID, $post, true ); |
|
| 126 | + /** This action is documented in wp-includes/post.php */ |
|
| 127 | + do_action( 'edit_post', $post->ID, $post ); |
|
| 128 | + /** This action is documented in wp-includes/post.php */ |
|
| 129 | + do_action( "save_post_{$post->post_type}", $post->ID, $post, true ); |
|
| 130 | + /** This action is documented in wp-includes/post.php */ |
|
| 131 | + do_action( 'wl_linked_data_save_post', $post->ID ); |
|
| 132 | + /** This action is documented in wp-includes/post.php */ |
|
| 133 | + do_action( 'wp_insert_post', $post->ID, $post, true ); |
|
| 134 | 134 | } |
| 135 | 135 | |
@@ -21,25 +21,25 @@ discard block |
||
| 21 | 21 | * @param string $old_status The old post status |
| 22 | 22 | * @param array $post An array with the post data |
| 23 | 23 | */ |
| 24 | -function wl_transition_post_status( $new_status, $old_status, $post ) { |
|
| 24 | +function wl_transition_post_status($new_status, $old_status, $post) { |
|
| 25 | 25 | |
| 26 | 26 | // wl_write_log( "wl_transition_post_status [ new status :: $new_status ][ old status :: $old_status ][ post ID :: $post->ID ]" ); |
| 27 | 27 | |
| 28 | 28 | // transition from *published* to any other status: delete the post. |
| 29 | - if ( 'publish' === $old_status && 'publish' !== $new_status ) { |
|
| 30 | - rl_delete_post( $post ); |
|
| 29 | + if ('publish' === $old_status && 'publish' !== $new_status) { |
|
| 30 | + rl_delete_post($post); |
|
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | // when a post is published, then all the referenced entities must be published. |
| 34 | - if ( 'publish' !== $old_status && 'publish' === $new_status ) { |
|
| 35 | - foreach ( wl_core_get_related_entity_ids( $post->ID ) as $entity_id ) { |
|
| 36 | - wl_update_post_status( $entity_id, 'publish' ); |
|
| 34 | + if ('publish' !== $old_status && 'publish' === $new_status) { |
|
| 35 | + foreach (wl_core_get_related_entity_ids($post->ID) as $entity_id) { |
|
| 36 | + wl_update_post_status($entity_id, 'publish'); |
|
| 37 | 37 | } |
| 38 | 38 | } |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | // hook save events. |
| 42 | -add_action( 'transition_post_status', 'wl_transition_post_status', 10, 3 ); |
|
| 42 | +add_action('transition_post_status', 'wl_transition_post_status', 10, 3); |
|
| 43 | 43 | |
| 44 | 44 | |
| 45 | 45 | /** |
@@ -47,51 +47,51 @@ discard block |
||
| 47 | 47 | * |
| 48 | 48 | * @param array|int $post An array of post data |
| 49 | 49 | */ |
| 50 | -function rl_delete_post( $post ) { |
|
| 50 | +function rl_delete_post($post) { |
|
| 51 | 51 | |
| 52 | - $post_id = ( is_numeric( $post ) ? $post : $post->ID ); |
|
| 52 | + $post_id = (is_numeric($post) ? $post : $post->ID); |
|
| 53 | 53 | |
| 54 | 54 | // hide all entities that are not referenced by any published post. |
| 55 | - foreach ( wl_core_get_related_entity_ids( $post_id ) as $entity_id ) { |
|
| 55 | + foreach (wl_core_get_related_entity_ids($post_id) as $entity_id) { |
|
| 56 | 56 | |
| 57 | 57 | // check if there is at least one referencing post published. |
| 58 | - $is_published = array_reduce( wl_core_get_related_post_ids( $entity_id ), function ( $carry, $item ) { |
|
| 59 | - $post = get_post( $item ); |
|
| 60 | - return ( $carry || ( 'publish' === $post->post_status ) ); |
|
| 58 | + $is_published = array_reduce(wl_core_get_related_post_ids($entity_id), function($carry, $item) { |
|
| 59 | + $post = get_post($item); |
|
| 60 | + return ($carry || ('publish' === $post->post_status)); |
|
| 61 | 61 | } ); |
| 62 | 62 | // set the entity to draft if no referencing posts are published. |
| 63 | - if ( ! $is_published ) { |
|
| 64 | - wl_update_post_status( $entity_id, 'draft' ); |
|
| 63 | + if ( ! $is_published) { |
|
| 64 | + wl_update_post_status($entity_id, 'draft'); |
|
| 65 | 65 | } |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | // get the entity URI (valid also for posts) |
| 69 | - $uri_esc = wl_sparql_escape_uri( wl_get_entity_uri( $post_id ) ); |
|
| 69 | + $uri_esc = wl_sparql_escape_uri(wl_get_entity_uri($post_id)); |
|
| 70 | 70 | |
| 71 | - wl_write_log( "rl_delete_post [ post id :: $post_id ][ uri esc :: $uri_esc ]" ); |
|
| 71 | + wl_write_log("rl_delete_post [ post id :: $post_id ][ uri esc :: $uri_esc ]"); |
|
| 72 | 72 | |
| 73 | 73 | // create the SPARQL statement by joining the SPARQL prefixes and deleting any known predicate. |
| 74 | 74 | $stmt = rl_sparql_prefixes(); |
| 75 | - foreach ( wl_predicates() as $predicate ) { |
|
| 76 | - $stmt .= "DELETE { <$uri_esc> $predicate ?o . } WHERE { <$uri_esc> $predicate ?o . };\n" . |
|
| 75 | + foreach (wl_predicates() as $predicate) { |
|
| 76 | + $stmt .= "DELETE { <$uri_esc> $predicate ?o . } WHERE { <$uri_esc> $predicate ?o . };\n". |
|
| 77 | 77 | "DELETE { ?s $predicate <$uri_esc> . } WHERE { ?s $predicate <$uri_esc> . };\n"; |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | // if the post is an entity and has exported properties, delete the related predicates. |
| 81 | - if ( Wordlift_Entity_Service::TYPE_NAME === $post->post_type ) { |
|
| 82 | - $type = wl_entity_type_taxonomy_get_type( $post->ID ); |
|
| 81 | + if (Wordlift_Entity_Service::TYPE_NAME === $post->post_type) { |
|
| 82 | + $type = wl_entity_type_taxonomy_get_type($post->ID); |
|
| 83 | 83 | |
| 84 | - if ( isset( $type['custom_fields'] ) ) { |
|
| 85 | - foreach ( $type['custom_fields'] as $field => $params ) { |
|
| 84 | + if (isset($type['custom_fields'])) { |
|
| 85 | + foreach ($type['custom_fields'] as $field => $params) { |
|
| 86 | 86 | // TODO: enclose in <> only if predicate starts with http(s):// |
| 87 | - $predicate = '<' . $params['predicate'] . '>'; |
|
| 87 | + $predicate = '<'.$params['predicate'].'>'; |
|
| 88 | 88 | $stmt .= "DELETE { <$uri_esc> $predicate ?o . } WHERE { <$uri_esc> $predicate ?o . };\n"; |
| 89 | 89 | } |
| 90 | 90 | } |
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | // finally execute the query. |
| 94 | - rl_execute_sparql_update_query( $stmt ); |
|
| 94 | + rl_execute_sparql_update_query($stmt); |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | /** |
@@ -100,36 +100,36 @@ discard block |
||
| 100 | 100 | * @param int $post_id The post ID |
| 101 | 101 | * @param string $status The new status |
| 102 | 102 | */ |
| 103 | -function wl_update_post_status( $post_id, $status ) { |
|
| 103 | +function wl_update_post_status($post_id, $status) { |
|
| 104 | 104 | |
| 105 | - wl_write_log( "wl_update_post_status [ post ID :: $post_id ][ status :: $status ]" ); |
|
| 105 | + wl_write_log("wl_update_post_status [ post ID :: $post_id ][ status :: $status ]"); |
|
| 106 | 106 | |
| 107 | 107 | global $wpdb; |
| 108 | 108 | |
| 109 | - if ( ! $post = get_post( $post_id ) ) { |
|
| 109 | + if ( ! $post = get_post($post_id)) { |
|
| 110 | 110 | return; |
| 111 | 111 | } |
| 112 | 112 | |
| 113 | - if ( $status === $post->post_status ) { |
|
| 113 | + if ($status === $post->post_status) { |
|
| 114 | 114 | return; |
| 115 | 115 | } |
| 116 | 116 | |
| 117 | - $wpdb->update( $wpdb->posts, array( 'post_status' => $status ), array( 'ID' => $post->ID ) ); |
|
| 117 | + $wpdb->update($wpdb->posts, array('post_status' => $status), array('ID' => $post->ID)); |
|
| 118 | 118 | |
| 119 | - clean_post_cache( $post->ID ); |
|
| 119 | + clean_post_cache($post->ID); |
|
| 120 | 120 | |
| 121 | 121 | $old_status = $post->post_status; |
| 122 | 122 | $post->post_status = $status; |
| 123 | 123 | |
| 124 | - wp_transition_post_status( $status, $old_status, $post ); |
|
| 124 | + wp_transition_post_status($status, $old_status, $post); |
|
| 125 | 125 | |
| 126 | 126 | /** This action is documented in wp-includes/post.php */ |
| 127 | - do_action( 'edit_post', $post->ID, $post ); |
|
| 127 | + do_action('edit_post', $post->ID, $post); |
|
| 128 | 128 | /** This action is documented in wp-includes/post.php */ |
| 129 | - do_action( "save_post_{$post->post_type}", $post->ID, $post, true ); |
|
| 129 | + do_action("save_post_{$post->post_type}", $post->ID, $post, true); |
|
| 130 | 130 | /** This action is documented in wp-includes/post.php */ |
| 131 | - do_action( 'wl_linked_data_save_post', $post->ID ); |
|
| 131 | + do_action('wl_linked_data_save_post', $post->ID); |
|
| 132 | 132 | /** This action is documented in wp-includes/post.php */ |
| 133 | - do_action( 'wp_insert_post', $post->ID, $post, true ); |
|
| 133 | + do_action('wp_insert_post', $post->ID, $post, true); |
|
| 134 | 134 | } |
| 135 | 135 | |
@@ -9,12 +9,12 @@ discard block |
||
| 9 | 9 | * Loads the buttons in TinyMCE. |
| 10 | 10 | */ |
| 11 | 11 | function wl_admin_shortcode_buttons() { |
| 12 | - // Only add hooks when the current user has permissions AND is in Rich Text editor mode |
|
| 13 | - if ( ( current_user_can( 'edit_posts' ) || current_user_can( 'edit_pages' ) ) && get_user_option( 'rich_editing' ) ) { |
|
| 14 | - add_filter( 'mce_external_plugins', 'wl_admin_shortcode_buttons_register_tinymce_javascript' ); |
|
| 15 | - add_filter( 'mce_buttons', 'wl_admin_shortcode_register_buttons' ); |
|
| 16 | - add_action( 'admin_footer', 'wl_admin_inject_chord_dialog_dependencies' ); |
|
| 17 | - } |
|
| 12 | + // Only add hooks when the current user has permissions AND is in Rich Text editor mode |
|
| 13 | + if ( ( current_user_can( 'edit_posts' ) || current_user_can( 'edit_pages' ) ) && get_user_option( 'rich_editing' ) ) { |
|
| 14 | + add_filter( 'mce_external_plugins', 'wl_admin_shortcode_buttons_register_tinymce_javascript' ); |
|
| 15 | + add_filter( 'mce_buttons', 'wl_admin_shortcode_register_buttons' ); |
|
| 16 | + add_action( 'admin_footer', 'wl_admin_inject_chord_dialog_dependencies' ); |
|
| 17 | + } |
|
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | /** |
@@ -26,9 +26,9 @@ discard block |
||
| 26 | 26 | */ |
| 27 | 27 | function wl_admin_shortcode_buttons_register_tinymce_javascript( $plugin_array ) { |
| 28 | 28 | |
| 29 | - $plugin_array['wl_shortcodes'] = plugin_dir_url( __FILE__ ) . 'js/wordlift_shortcode_tinymce_plugin.js'; |
|
| 29 | + $plugin_array['wl_shortcodes'] = plugin_dir_url( __FILE__ ) . 'js/wordlift_shortcode_tinymce_plugin.js'; |
|
| 30 | 30 | |
| 31 | - return $plugin_array; |
|
| 31 | + return $plugin_array; |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | /** |
@@ -39,9 +39,9 @@ discard block |
||
| 39 | 39 | * @return array The buttons array including the *wl_shortcodes_menu*. |
| 40 | 40 | */ |
| 41 | 41 | function wl_admin_shortcode_register_buttons( $buttons ) { |
| 42 | - array_push( $buttons, 'wl_shortcodes_menu' ); |
|
| 42 | + array_push( $buttons, 'wl_shortcodes_menu' ); |
|
| 43 | 43 | |
| 44 | - return $buttons; |
|
| 44 | + return $buttons; |
|
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | // init process for button control |
@@ -55,16 +55,16 @@ discard block |
||
| 55 | 55 | */ |
| 56 | 56 | function wl_admin_inject_chord_dialog_dependencies() { |
| 57 | 57 | |
| 58 | - wp_enqueue_style( 'wp-color-picker' ); |
|
| 59 | - wp_enqueue_script( 'wp-color-picker' ); |
|
| 60 | - wp_enqueue_style( 'jquery-ui-slider' ); |
|
| 61 | - // Not included by default :| |
|
| 62 | - // TODO include jquery ui css from the plugin creates css issues on the slider |
|
| 63 | - // wp_enqueue_style('jquery-ui-css', plugins_url( 'css/jquery-ui/jquery-ui.min.css', __FILE__ ) ); |
|
| 64 | - wp_enqueue_style( 'wp-jquery-ui-css', 'https://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery.ui.all.css' ); |
|
| 58 | + wp_enqueue_style( 'wp-color-picker' ); |
|
| 59 | + wp_enqueue_script( 'wp-color-picker' ); |
|
| 60 | + wp_enqueue_style( 'jquery-ui-slider' ); |
|
| 61 | + // Not included by default :| |
|
| 62 | + // TODO include jquery ui css from the plugin creates css issues on the slider |
|
| 63 | + // wp_enqueue_style('jquery-ui-css', plugins_url( 'css/jquery-ui/jquery-ui.min.css', __FILE__ ) ); |
|
| 64 | + wp_enqueue_style( 'wp-jquery-ui-css', 'https://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery.ui.all.css' ); |
|
| 65 | 65 | |
| 66 | - wp_enqueue_script( 'jquery' ); |
|
| 67 | - wp_enqueue_script( 'jquery-ui-core' ); |
|
| 68 | - wp_enqueue_script( 'jquery-ui-slider' ); |
|
| 66 | + wp_enqueue_script( 'jquery' ); |
|
| 67 | + wp_enqueue_script( 'jquery-ui-core' ); |
|
| 68 | + wp_enqueue_script( 'jquery-ui-slider' ); |
|
| 69 | 69 | |
| 70 | 70 | } |
@@ -10,10 +10,10 @@ discard block |
||
| 10 | 10 | */ |
| 11 | 11 | function wl_admin_shortcode_buttons() { |
| 12 | 12 | // Only add hooks when the current user has permissions AND is in Rich Text editor mode |
| 13 | - if ( ( current_user_can( 'edit_posts' ) || current_user_can( 'edit_pages' ) ) && get_user_option( 'rich_editing' ) ) { |
|
| 14 | - add_filter( 'mce_external_plugins', 'wl_admin_shortcode_buttons_register_tinymce_javascript' ); |
|
| 15 | - add_filter( 'mce_buttons', 'wl_admin_shortcode_register_buttons' ); |
|
| 16 | - add_action( 'admin_footer', 'wl_admin_inject_chord_dialog_dependencies' ); |
|
| 13 | + if ((current_user_can('edit_posts') || current_user_can('edit_pages')) && get_user_option('rich_editing')) { |
|
| 14 | + add_filter('mce_external_plugins', 'wl_admin_shortcode_buttons_register_tinymce_javascript'); |
|
| 15 | + add_filter('mce_buttons', 'wl_admin_shortcode_register_buttons'); |
|
| 16 | + add_action('admin_footer', 'wl_admin_inject_chord_dialog_dependencies'); |
|
| 17 | 17 | } |
| 18 | 18 | } |
| 19 | 19 | |
@@ -24,9 +24,9 @@ discard block |
||
| 24 | 24 | * |
| 25 | 25 | * @return array The TinyMCE plugins array including WordLift shortcodes plugin. |
| 26 | 26 | */ |
| 27 | -function wl_admin_shortcode_buttons_register_tinymce_javascript( $plugin_array ) { |
|
| 27 | +function wl_admin_shortcode_buttons_register_tinymce_javascript($plugin_array) { |
|
| 28 | 28 | |
| 29 | - $plugin_array['wl_shortcodes'] = plugin_dir_url( __FILE__ ) . 'js/wordlift_shortcode_tinymce_plugin.js'; |
|
| 29 | + $plugin_array['wl_shortcodes'] = plugin_dir_url(__FILE__).'js/wordlift_shortcode_tinymce_plugin.js'; |
|
| 30 | 30 | |
| 31 | 31 | return $plugin_array; |
| 32 | 32 | } |
@@ -38,14 +38,14 @@ discard block |
||
| 38 | 38 | * |
| 39 | 39 | * @return array The buttons array including the *wl_shortcodes_menu*. |
| 40 | 40 | */ |
| 41 | -function wl_admin_shortcode_register_buttons( $buttons ) { |
|
| 42 | - array_push( $buttons, 'wl_shortcodes_menu' ); |
|
| 41 | +function wl_admin_shortcode_register_buttons($buttons) { |
|
| 42 | + array_push($buttons, 'wl_shortcodes_menu'); |
|
| 43 | 43 | |
| 44 | 44 | return $buttons; |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | // init process for button control |
| 48 | -add_action( 'admin_init', 'wl_admin_shortcode_buttons' ); |
|
| 48 | +add_action('admin_init', 'wl_admin_shortcode_buttons'); |
|
| 49 | 49 | |
| 50 | 50 | |
| 51 | 51 | /** |
@@ -55,16 +55,16 @@ discard block |
||
| 55 | 55 | */ |
| 56 | 56 | function wl_admin_inject_chord_dialog_dependencies() { |
| 57 | 57 | |
| 58 | - wp_enqueue_style( 'wp-color-picker' ); |
|
| 59 | - wp_enqueue_script( 'wp-color-picker' ); |
|
| 60 | - wp_enqueue_style( 'jquery-ui-slider' ); |
|
| 58 | + wp_enqueue_style('wp-color-picker'); |
|
| 59 | + wp_enqueue_script('wp-color-picker'); |
|
| 60 | + wp_enqueue_style('jquery-ui-slider'); |
|
| 61 | 61 | // Not included by default :| |
| 62 | 62 | // TODO include jquery ui css from the plugin creates css issues on the slider |
| 63 | 63 | // wp_enqueue_style('jquery-ui-css', plugins_url( 'css/jquery-ui/jquery-ui.min.css', __FILE__ ) ); |
| 64 | - wp_enqueue_style( 'wp-jquery-ui-css', 'https://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery.ui.all.css' ); |
|
| 64 | + wp_enqueue_style('wp-jquery-ui-css', 'https://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery.ui.all.css'); |
|
| 65 | 65 | |
| 66 | - wp_enqueue_script( 'jquery' ); |
|
| 67 | - wp_enqueue_script( 'jquery-ui-core' ); |
|
| 68 | - wp_enqueue_script( 'jquery-ui-slider' ); |
|
| 66 | + wp_enqueue_script('jquery'); |
|
| 67 | + wp_enqueue_script('jquery-ui-core'); |
|
| 68 | + wp_enqueue_script('jquery-ui-slider'); |
|
| 69 | 69 | |
| 70 | 70 | } |
@@ -9,20 +9,20 @@ discard block |
||
| 9 | 9 | */ |
| 10 | 10 | function wl_admin_sync_to_redlink() { |
| 11 | 11 | |
| 12 | - $posts = get_posts( array( |
|
| 13 | - 'post_type' => 'any', |
|
| 14 | - 'posts_per_page' => - 1 |
|
| 15 | - ) ); |
|
| 12 | + $posts = get_posts( array( |
|
| 13 | + 'post_type' => 'any', |
|
| 14 | + 'posts_per_page' => - 1 |
|
| 15 | + ) ); |
|
| 16 | 16 | |
| 17 | - wl_write_log( "wl_admin_sync_to_redlink [ post count :: " . sizeof( $posts ) . " ]" ); |
|
| 17 | + wl_write_log( "wl_admin_sync_to_redlink [ post count :: " . sizeof( $posts ) . " ]" ); |
|
| 18 | 18 | |
| 19 | - foreach ( $posts as $post ) { |
|
| 20 | - echo esc_html( $post->post_title ) . '<br/>'; |
|
| 21 | - wl_linked_data_push_to_redlink( $post->ID ); |
|
| 22 | - } |
|
| 19 | + foreach ( $posts as $post ) { |
|
| 20 | + echo esc_html( $post->post_title ) . '<br/>'; |
|
| 21 | + wl_linked_data_push_to_redlink( $post->ID ); |
|
| 22 | + } |
|
| 23 | 23 | |
| 24 | - // Schedule the execution of SPARQL. |
|
| 25 | - wl_shutdown(); |
|
| 24 | + // Schedule the execution of SPARQL. |
|
| 25 | + wl_shutdown(); |
|
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | /** |
@@ -30,9 +30,9 @@ discard block |
||
| 30 | 30 | */ |
| 31 | 31 | function wl_admin_ajax_sync_to_redlink() { |
| 32 | 32 | |
| 33 | - // TODO: check appropriate permissions here. |
|
| 34 | - wl_admin_sync_to_redlink(); |
|
| 35 | - die(); |
|
| 33 | + // TODO: check appropriate permissions here. |
|
| 34 | + wl_admin_sync_to_redlink(); |
|
| 35 | + die(); |
|
| 36 | 36 | |
| 37 | 37 | } |
| 38 | 38 | |
@@ -9,16 +9,16 @@ discard block |
||
| 9 | 9 | */ |
| 10 | 10 | function wl_admin_sync_to_redlink() { |
| 11 | 11 | |
| 12 | - $posts = get_posts( array( |
|
| 12 | + $posts = get_posts(array( |
|
| 13 | 13 | 'post_type' => 'any', |
| 14 | - 'posts_per_page' => - 1 |
|
| 15 | - ) ); |
|
| 14 | + 'posts_per_page' => -1 |
|
| 15 | + )); |
|
| 16 | 16 | |
| 17 | - wl_write_log( "wl_admin_sync_to_redlink [ post count :: " . sizeof( $posts ) . " ]" ); |
|
| 17 | + wl_write_log("wl_admin_sync_to_redlink [ post count :: ".sizeof($posts)." ]"); |
|
| 18 | 18 | |
| 19 | - foreach ( $posts as $post ) { |
|
| 20 | - echo esc_html( $post->post_title ) . '<br/>'; |
|
| 21 | - wl_linked_data_push_to_redlink( $post->ID ); |
|
| 19 | + foreach ($posts as $post) { |
|
| 20 | + echo esc_html($post->post_title).'<br/>'; |
|
| 21 | + wl_linked_data_push_to_redlink($post->ID); |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | // Schedule the execution of SPARQL. |
@@ -36,4 +36,4 @@ discard block |
||
| 36 | 36 | |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | -add_action( 'wp_ajax_wl_sync_to_redlink', 'wl_admin_ajax_sync_to_redlink' ); |
|
| 39 | +add_action('wp_ajax_wl_sync_to_redlink', 'wl_admin_ajax_sync_to_redlink'); |
|