@@ -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' 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' 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' 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' 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' 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' 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' 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' 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 | */ |
@@ -14,19 +14,19 @@ discard block |
||
| 14 | 14 | ) ); |
| 15 | 15 | } |
| 16 | 16 | /** |
| 17 | - * Return an array of validation rules used by wl_core_get_posts |
|
| 18 | - * |
|
| 19 | - * @return array in the format field => (array) accepeted_values |
|
| 20 | - */ |
|
| 17 | + * Return an array of validation rules used by wl_core_get_posts |
|
| 18 | + * |
|
| 19 | + * @return array in the format field => (array) accepeted_values |
|
| 20 | + */ |
|
| 21 | 21 | function wl_core_get_validation_rules() { |
| 22 | 22 | |
| 23 | 23 | return unserialize( WL_CORE_GET_POSTS_VALIDATION_RULES ); |
| 24 | 24 | } |
| 25 | 25 | /** |
| 26 | - * Return the wordlift relation instances table name |
|
| 27 | - * |
|
| 28 | - * @return string Return the wordlift relation instances table name |
|
| 29 | - */ |
|
| 26 | + * Return the wordlift relation instances table name |
|
| 27 | + * |
|
| 28 | + * @return string Return the wordlift relation instances table name |
|
| 29 | + */ |
|
| 30 | 30 | function wl_core_get_relation_instances_table_name() { |
| 31 | 31 | |
| 32 | 32 | global $wpdb; |
@@ -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; |
@@ -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 |
@@ -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 | |
@@ -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,21 +176,21 @@ 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 | - // Build full schema uri if necessary |
|
| 190 | - $type_names = wl_build_full_schema_uri_from_schema_slug( $type_names ); |
|
| 189 | + // Build full schema uri if necessary |
|
| 190 | + $type_names = wl_build_full_schema_uri_from_schema_slug( $type_names ); |
|
| 191 | 191 | |
| 192 | - // Actually sets the taxonomy type |
|
| 193 | - wl_set_entity_main_type( $post_id, $type_names ); |
|
| 192 | + // Actually sets the taxonomy type |
|
| 193 | + wl_set_entity_main_type( $post_id, $type_names ); |
|
| 194 | 194 | } |
| 195 | 195 | |
| 196 | 196 | /** |
@@ -205,24 +205,24 @@ discard block |
||
| 205 | 205 | */ |
| 206 | 206 | function wl_schema_get_type_properties( $type_name ) { |
| 207 | 207 | |
| 208 | - // Build full schema uri if necessary |
|
| 209 | - $type_name = wl_build_full_schema_uri_from_schema_slug( $type_name ); |
|
| 208 | + // Build full schema uri if necessary |
|
| 209 | + $type_name = wl_build_full_schema_uri_from_schema_slug( $type_name ); |
|
| 210 | 210 | |
| 211 | - // Get all custom fields |
|
| 212 | - $all_types_and_fields = wl_entity_taxonomy_get_custom_fields(); |
|
| 211 | + // Get all custom fields |
|
| 212 | + $all_types_and_fields = wl_entity_taxonomy_get_custom_fields(); |
|
| 213 | 213 | |
| 214 | - $schema_root_address = 'http://schema.org/'; |
|
| 215 | - $type_properties = array(); |
|
| 214 | + $schema_root_address = 'http://schema.org/'; |
|
| 215 | + $type_properties = array(); |
|
| 216 | 216 | |
| 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 ) { |
|
| 220 | - // Convert to schema slug and store in array |
|
| 221 | - $type_properties[] = str_replace( $schema_root_address, '', $field['predicate'] ); |
|
| 222 | - } |
|
| 223 | - } |
|
| 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 ) { |
|
| 220 | + // Convert to schema slug and store in array |
|
| 221 | + $type_properties[] = str_replace( $schema_root_address, '', $field['predicate'] ); |
|
| 222 | + } |
|
| 223 | + } |
|
| 224 | 224 | |
| 225 | - return $type_properties; |
|
| 225 | + return $type_properties; |
|
| 226 | 226 | } |
| 227 | 227 | |
| 228 | 228 | /** |
@@ -234,11 +234,11 @@ discard block |
||
| 234 | 234 | */ |
| 235 | 235 | function wl_build_full_schema_uri_from_schema_slug( $schema_name ) { |
| 236 | 236 | |
| 237 | - $schema_root_address = 'http://schema.org/'; |
|
| 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; |
|
| 241 | - } |
|
| 239 | + if ( strpos( $schema_name, $schema_root_address ) === false ) { // === necessary |
|
| 240 | + $schema_name = $schema_root_address . $schema_name; |
|
| 241 | + } |
|
| 242 | 242 | |
| 243 | - return $schema_name; |
|
| 243 | + return $schema_name; |
|
| 244 | 244 | } |
| 245 | 245 | \ No newline at end of file |
@@ -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; |
@@ -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,48 +14,48 @@ 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 ); |
|
| 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 | - ) ); |
|
| 27 | - } |
|
| 28 | - |
|
| 29 | - // If is not a global geomap, an empty $related_ids means that no entities are related to the post |
|
| 30 | - // An empty array can be returned in this case |
|
| 31 | - if ( ! $is_global && empty( $related_ids ) ) { |
|
| 32 | - return array(); |
|
| 33 | - } |
|
| 34 | - |
|
| 35 | - // Retrieve all 'published' places with geo coordinates defined |
|
| 36 | - // If $place_ids is not empty, it's used to limit query results to the current post related places |
|
| 37 | - // Please note that when $place_ids is an empty array, the 'post__in' parameter is not considered in the query |
|
| 38 | - $places = get_posts( array( |
|
| 39 | - 'post__in' => $related_ids, |
|
| 40 | - 'post_type' => Wordlift_Entity_Service::TYPE_NAME, |
|
| 41 | - 'nopaging' => true, |
|
| 42 | - 'post_status' => 'published', |
|
| 43 | - 'meta_query' => array( |
|
| 44 | - 'relation' => 'AND', |
|
| 45 | - array( |
|
| 46 | - 'key' => Wordlift_Schema_Service::FIELD_GEO_LATITUDE, |
|
| 47 | - 'value' => null, |
|
| 48 | - 'compare' => '!=', |
|
| 49 | - ), |
|
| 50 | - array( |
|
| 51 | - 'key' => Wordlift_Schema_Service::FIELD_GEO_LONGITUDE, |
|
| 52 | - 'value' => null, |
|
| 53 | - 'compare' => '!=', |
|
| 54 | - ) |
|
| 55 | - ) |
|
| 56 | - ) ); |
|
| 57 | - |
|
| 58 | - return $places; |
|
| 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 | + |
|
| 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 | + } |
|
| 28 | + |
|
| 29 | + // If is not a global geomap, an empty $related_ids means that no entities are related to the post |
|
| 30 | + // An empty array can be returned in this case |
|
| 31 | + if ( ! $is_global && empty( $related_ids ) ) { |
|
| 32 | + return array(); |
|
| 33 | + } |
|
| 34 | + |
|
| 35 | + // Retrieve all 'published' places with geo coordinates defined |
|
| 36 | + // If $place_ids is not empty, it's used to limit query results to the current post related places |
|
| 37 | + // Please note that when $place_ids is an empty array, the 'post__in' parameter is not considered in the query |
|
| 38 | + $places = get_posts( array( |
|
| 39 | + 'post__in' => $related_ids, |
|
| 40 | + 'post_type' => Wordlift_Entity_Service::TYPE_NAME, |
|
| 41 | + 'nopaging' => true, |
|
| 42 | + 'post_status' => 'published', |
|
| 43 | + 'meta_query' => array( |
|
| 44 | + 'relation' => 'AND', |
|
| 45 | + array( |
|
| 46 | + 'key' => Wordlift_Schema_Service::FIELD_GEO_LATITUDE, |
|
| 47 | + 'value' => null, |
|
| 48 | + 'compare' => '!=', |
|
| 49 | + ), |
|
| 50 | + array( |
|
| 51 | + 'key' => Wordlift_Schema_Service::FIELD_GEO_LONGITUDE, |
|
| 52 | + 'value' => null, |
|
| 53 | + 'compare' => '!=', |
|
| 54 | + ) |
|
| 55 | + ) |
|
| 56 | + ) ); |
|
| 57 | + |
|
| 58 | + return $places; |
|
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | /** |
@@ -70,88 +70,88 @@ discard block |
||
| 70 | 70 | */ |
| 71 | 71 | function wl_shortcode_geomap_prepare_map( $places ) { |
| 72 | 72 | |
| 73 | - // Prepare for min/max lat/long in case we need to define a view boundary for the client JavaScript. |
|
| 74 | - $min_latitude = PHP_INT_MAX; |
|
| 75 | - $min_longitude = PHP_INT_MAX; |
|
| 76 | - $max_latitude = ~PHP_INT_MAX; |
|
| 77 | - $max_longitude = ~PHP_INT_MAX; |
|
| 78 | - |
|
| 79 | - // Prepare an empty array of POIs in geoJSON format. |
|
| 80 | - $pois = array(); |
|
| 81 | - // And store list of points to allow Leaflet compute the optimal bounding box. |
|
| 82 | - // The main reason for this is that geoJSON has swapped coordinates (lon. lat) |
|
| 83 | - $boundaries = array(); |
|
| 84 | - |
|
| 85 | - // Add a POI for each entity that has coordinates. |
|
| 86 | - foreach ( $places as $entity ) { |
|
| 87 | - |
|
| 88 | - // Get the coordinates. |
|
| 89 | - $coordinates = wl_get_coordinates( $entity->ID ); |
|
| 90 | - |
|
| 91 | - // Don't show the widget if the coordinates aren't set. |
|
| 92 | - if ( $coordinates['latitude'] == 0 || $coordinates['longitude'] == 0 ) { |
|
| 93 | - continue; |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - // TODO Map html rendering should be delegated to the wordlift js ui layer |
|
| 97 | - // This function should be focused on returning pure data instead |
|
| 98 | - |
|
| 99 | - // Get the title, URL and thumb of the entity. |
|
| 100 | - $title = esc_attr( $entity->post_title ); |
|
| 101 | - $link = esc_attr( get_permalink( $entity->ID ) ); |
|
| 102 | - if ( '' !== ( $thumbnail_id = get_post_thumbnail_id( $entity->ID ) ) && |
|
| 103 | - false !== ( $attachment = wp_get_attachment_image_src( $thumbnail_id ) ) |
|
| 104 | - ) { |
|
| 105 | - $img_src = esc_attr( $attachment[0] ); |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - // Build HTML popup. TODO: move thumb width in css |
|
| 109 | - $content = "<a href=$link><h6>$title</h6>"; |
|
| 110 | - if ( isset( $img_src ) ) { |
|
| 111 | - $content = $content . "<img src=$img_src style='width:100%'/>"; |
|
| 112 | - } |
|
| 113 | - $content = $content . "</a><ul>"; |
|
| 114 | - // Get the related posts (published) and print them in the popup. |
|
| 115 | - $related_posts = wl_core_get_related_post_ids( $entity->ID, array( |
|
| 116 | - 'status' => 'publish' |
|
| 117 | - ) ); |
|
| 118 | - foreach ( $related_posts as $rp_id ) { |
|
| 119 | - |
|
| 120 | - $rp = get_post( $rp_id ); |
|
| 121 | - $title = esc_attr( $rp->post_title ); |
|
| 122 | - $link = esc_attr( get_permalink( $rp->ID ) ); |
|
| 123 | - $content = $content . "<li><a href=$link>$title</a></li>"; |
|
| 124 | - } |
|
| 125 | - $content = $content . "</ul>"; |
|
| 126 | - |
|
| 127 | - // Formatting POI in geoJSON. |
|
| 128 | - // http://leafletjs.com/examples/geojson.html |
|
| 129 | - $poi = array( |
|
| 130 | - 'type' => 'Feature', |
|
| 131 | - 'properties' => array( 'popupContent' => $content ), |
|
| 132 | - 'geometry' => array( |
|
| 133 | - 'type' => 'Point', |
|
| 134 | - 'coordinates' => array( |
|
| 135 | - // Leaflet geoJSON wants them swapped |
|
| 136 | - $coordinates['longitude'], |
|
| 137 | - $coordinates['latitude'] |
|
| 138 | - ) |
|
| 139 | - ) |
|
| 140 | - ); |
|
| 141 | - |
|
| 142 | - $pois[] = $poi; |
|
| 143 | - |
|
| 144 | - // Formatting boundaries in a Leaflet-like format (see LatLngBounds). |
|
| 145 | - // http://leafletjs.com/reference.html#latlngbounds |
|
| 146 | - $boundaries[] = array( $coordinates['latitude'], $coordinates['longitude'] ); |
|
| 147 | - |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - $map_data = array(); |
|
| 151 | - $map_data['features'] = $pois; |
|
| 152 | - $map_data['boundaries'] = $boundaries; |
|
| 153 | - |
|
| 154 | - return $map_data; |
|
| 73 | + // Prepare for min/max lat/long in case we need to define a view boundary for the client JavaScript. |
|
| 74 | + $min_latitude = PHP_INT_MAX; |
|
| 75 | + $min_longitude = PHP_INT_MAX; |
|
| 76 | + $max_latitude = ~PHP_INT_MAX; |
|
| 77 | + $max_longitude = ~PHP_INT_MAX; |
|
| 78 | + |
|
| 79 | + // Prepare an empty array of POIs in geoJSON format. |
|
| 80 | + $pois = array(); |
|
| 81 | + // And store list of points to allow Leaflet compute the optimal bounding box. |
|
| 82 | + // The main reason for this is that geoJSON has swapped coordinates (lon. lat) |
|
| 83 | + $boundaries = array(); |
|
| 84 | + |
|
| 85 | + // Add a POI for each entity that has coordinates. |
|
| 86 | + foreach ( $places as $entity ) { |
|
| 87 | + |
|
| 88 | + // Get the coordinates. |
|
| 89 | + $coordinates = wl_get_coordinates( $entity->ID ); |
|
| 90 | + |
|
| 91 | + // Don't show the widget if the coordinates aren't set. |
|
| 92 | + if ( $coordinates['latitude'] == 0 || $coordinates['longitude'] == 0 ) { |
|
| 93 | + continue; |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + // TODO Map html rendering should be delegated to the wordlift js ui layer |
|
| 97 | + // This function should be focused on returning pure data instead |
|
| 98 | + |
|
| 99 | + // Get the title, URL and thumb of the entity. |
|
| 100 | + $title = esc_attr( $entity->post_title ); |
|
| 101 | + $link = esc_attr( get_permalink( $entity->ID ) ); |
|
| 102 | + if ( '' !== ( $thumbnail_id = get_post_thumbnail_id( $entity->ID ) ) && |
|
| 103 | + false !== ( $attachment = wp_get_attachment_image_src( $thumbnail_id ) ) |
|
| 104 | + ) { |
|
| 105 | + $img_src = esc_attr( $attachment[0] ); |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + // Build HTML popup. TODO: move thumb width in css |
|
| 109 | + $content = "<a href=$link><h6>$title</h6>"; |
|
| 110 | + if ( isset( $img_src ) ) { |
|
| 111 | + $content = $content . "<img src=$img_src style='width:100%'/>"; |
|
| 112 | + } |
|
| 113 | + $content = $content . "</a><ul>"; |
|
| 114 | + // Get the related posts (published) and print them in the popup. |
|
| 115 | + $related_posts = wl_core_get_related_post_ids( $entity->ID, array( |
|
| 116 | + 'status' => 'publish' |
|
| 117 | + ) ); |
|
| 118 | + foreach ( $related_posts as $rp_id ) { |
|
| 119 | + |
|
| 120 | + $rp = get_post( $rp_id ); |
|
| 121 | + $title = esc_attr( $rp->post_title ); |
|
| 122 | + $link = esc_attr( get_permalink( $rp->ID ) ); |
|
| 123 | + $content = $content . "<li><a href=$link>$title</a></li>"; |
|
| 124 | + } |
|
| 125 | + $content = $content . "</ul>"; |
|
| 126 | + |
|
| 127 | + // Formatting POI in geoJSON. |
|
| 128 | + // http://leafletjs.com/examples/geojson.html |
|
| 129 | + $poi = array( |
|
| 130 | + 'type' => 'Feature', |
|
| 131 | + 'properties' => array( 'popupContent' => $content ), |
|
| 132 | + 'geometry' => array( |
|
| 133 | + 'type' => 'Point', |
|
| 134 | + 'coordinates' => array( |
|
| 135 | + // Leaflet geoJSON wants them swapped |
|
| 136 | + $coordinates['longitude'], |
|
| 137 | + $coordinates['latitude'] |
|
| 138 | + ) |
|
| 139 | + ) |
|
| 140 | + ); |
|
| 141 | + |
|
| 142 | + $pois[] = $poi; |
|
| 143 | + |
|
| 144 | + // Formatting boundaries in a Leaflet-like format (see LatLngBounds). |
|
| 145 | + // http://leafletjs.com/reference.html#latlngbounds |
|
| 146 | + $boundaries[] = array( $coordinates['latitude'], $coordinates['longitude'] ); |
|
| 147 | + |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + $map_data = array(); |
|
| 151 | + $map_data['features'] = $pois; |
|
| 152 | + $map_data['boundaries'] = $boundaries; |
|
| 153 | + |
|
| 154 | + return $map_data; |
|
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | /** |
@@ -165,13 +165,13 @@ discard block |
||
| 165 | 165 | * @return array An array of place posts. |
| 166 | 166 | */ |
| 167 | 167 | function wl_shortcode_geomap_ajax() { |
| 168 | - // Get the post Id. |
|
| 169 | - $post_id = ( isset( $_REQUEST['post_id'] ) ? $_REQUEST['post_id'] : null ); |
|
| 168 | + // Get the post Id. |
|
| 169 | + $post_id = ( isset( $_REQUEST['post_id'] ) ? $_REQUEST['post_id'] : null ); |
|
| 170 | 170 | |
| 171 | - $places = wl_shortcode_geomap_get_places( $post_id ); |
|
| 172 | - $map_data = wl_shortcode_geomap_prepare_map( $places ); |
|
| 171 | + $places = wl_shortcode_geomap_get_places( $post_id ); |
|
| 172 | + $map_data = wl_shortcode_geomap_prepare_map( $places ); |
|
| 173 | 173 | |
| 174 | - wl_core_send_json( $map_data ); |
|
| 174 | + wl_core_send_json( $map_data ); |
|
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | add_action( 'wp_ajax_wl_geomap', 'wl_shortcode_geomap_ajax' ); |
@@ -186,54 +186,54 @@ discard block |
||
| 186 | 186 | */ |
| 187 | 187 | function wl_shortcode_geomap( $atts ) { |
| 188 | 188 | |
| 189 | - // Extract attributes and set default values. |
|
| 190 | - $geomap_atts = shortcode_atts( array( |
|
| 191 | - 'width' => '100%', |
|
| 192 | - 'height' => '300px', |
|
| 193 | - 'global' => false |
|
| 194 | - ), $atts ); |
|
| 195 | - |
|
| 196 | - // Get id of the post |
|
| 197 | - $post_id = get_the_ID(); |
|
| 198 | - |
|
| 199 | - if ( $geomap_atts['global'] || is_null( $post_id ) ) { |
|
| 200 | - // Global geomap |
|
| 201 | - $geomap_id = 'wl_geomap_global'; |
|
| 202 | - $post_id = null; |
|
| 203 | - } else { |
|
| 204 | - // Post-specific geomap |
|
| 205 | - $geomap_id = 'wl_geomap_' . $post_id; |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - // Add leaflet css and library. |
|
| 209 | - wp_enqueue_style( |
|
| 210 | - 'leaflet', |
|
| 211 | - dirname( plugin_dir_url( __FILE__ ) ) . '/bower_components/leaflet/dist/leaflet.css' |
|
| 212 | - ); |
|
| 213 | - wp_enqueue_script( |
|
| 214 | - 'leaflet', |
|
| 215 | - dirname( plugin_dir_url( __FILE__ ) ) . '/bower_components/leaflet/dist/leaflet.js' |
|
| 216 | - ); |
|
| 217 | - |
|
| 218 | - // Add wordlift-ui css and library. |
|
| 219 | - wp_enqueue_style( 'wordlift-ui-css', dirname( plugin_dir_url( __FILE__ ) ) . '/css/wordlift-ui.min.css' ); |
|
| 220 | - |
|
| 221 | - wp_enqueue_script( 'wordlift-ui', dirname( plugin_dir_url( __FILE__ ) ) . '/js/wordlift-ui.min.js', array( 'jquery' ) ); |
|
| 222 | - |
|
| 223 | - wp_localize_script( 'wordlift-ui', 'wl_geomap_params', array( |
|
| 224 | - 'ajax_url' => admin_url( 'admin-ajax.php' ), // Global param |
|
| 225 | - 'action' => 'wl_geomap' // Global param |
|
| 226 | - ) ); |
|
| 227 | - |
|
| 228 | - // Escaping atts. |
|
| 229 | - $esc_class = esc_attr( 'wl-geomap' ); |
|
| 230 | - $esc_id = esc_attr( $geomap_id ); |
|
| 231 | - $esc_width = esc_attr( $geomap_atts['width'] ); |
|
| 232 | - $esc_height = esc_attr( $geomap_atts['height'] ); |
|
| 233 | - $esc_post_id = esc_attr( $post_id ); |
|
| 234 | - |
|
| 235 | - // Return HTML template. |
|
| 236 | - return <<<EOF |
|
| 189 | + // Extract attributes and set default values. |
|
| 190 | + $geomap_atts = shortcode_atts( array( |
|
| 191 | + 'width' => '100%', |
|
| 192 | + 'height' => '300px', |
|
| 193 | + 'global' => false |
|
| 194 | + ), $atts ); |
|
| 195 | + |
|
| 196 | + // Get id of the post |
|
| 197 | + $post_id = get_the_ID(); |
|
| 198 | + |
|
| 199 | + if ( $geomap_atts['global'] || is_null( $post_id ) ) { |
|
| 200 | + // Global geomap |
|
| 201 | + $geomap_id = 'wl_geomap_global'; |
|
| 202 | + $post_id = null; |
|
| 203 | + } else { |
|
| 204 | + // Post-specific geomap |
|
| 205 | + $geomap_id = 'wl_geomap_' . $post_id; |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + // Add leaflet css and library. |
|
| 209 | + wp_enqueue_style( |
|
| 210 | + 'leaflet', |
|
| 211 | + dirname( plugin_dir_url( __FILE__ ) ) . '/bower_components/leaflet/dist/leaflet.css' |
|
| 212 | + ); |
|
| 213 | + wp_enqueue_script( |
|
| 214 | + 'leaflet', |
|
| 215 | + dirname( plugin_dir_url( __FILE__ ) ) . '/bower_components/leaflet/dist/leaflet.js' |
|
| 216 | + ); |
|
| 217 | + |
|
| 218 | + // Add wordlift-ui css and library. |
|
| 219 | + wp_enqueue_style( 'wordlift-ui-css', dirname( plugin_dir_url( __FILE__ ) ) . '/css/wordlift-ui.min.css' ); |
|
| 220 | + |
|
| 221 | + wp_enqueue_script( 'wordlift-ui', dirname( plugin_dir_url( __FILE__ ) ) . '/js/wordlift-ui.min.js', array( 'jquery' ) ); |
|
| 222 | + |
|
| 223 | + wp_localize_script( 'wordlift-ui', 'wl_geomap_params', array( |
|
| 224 | + 'ajax_url' => admin_url( 'admin-ajax.php' ), // Global param |
|
| 225 | + 'action' => 'wl_geomap' // Global param |
|
| 226 | + ) ); |
|
| 227 | + |
|
| 228 | + // Escaping atts. |
|
| 229 | + $esc_class = esc_attr( 'wl-geomap' ); |
|
| 230 | + $esc_id = esc_attr( $geomap_id ); |
|
| 231 | + $esc_width = esc_attr( $geomap_atts['width'] ); |
|
| 232 | + $esc_height = esc_attr( $geomap_atts['height'] ); |
|
| 233 | + $esc_post_id = esc_attr( $post_id ); |
|
| 234 | + |
|
| 235 | + // Return HTML template. |
|
| 236 | + return <<<EOF |
|
| 237 | 237 | <div class="$esc_class" |
| 238 | 238 | id="$esc_id" |
| 239 | 239 | data-post-id="$esc_post_id" |
@@ -12,30 +12,30 @@ 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 | |
| 29 | 29 | // If is not a global geomap, an empty $related_ids means that no entities are related to the post |
| 30 | 30 | // An empty array can be returned in this case |
| 31 | - if ( ! $is_global && empty( $related_ids ) ) { |
|
| 31 | + if ( ! $is_global && empty($related_ids)) { |
|
| 32 | 32 | return array(); |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | // Retrieve all 'published' places with geo coordinates defined |
| 36 | 36 | // If $place_ids is not empty, it's used to limit query results to the current post related places |
| 37 | 37 | // Please note that when $place_ids is an empty array, the 'post__in' parameter is not considered in the query |
| 38 | - $places = get_posts( array( |
|
| 38 | + $places = get_posts(array( |
|
| 39 | 39 | 'post__in' => $related_ids, |
| 40 | 40 | 'post_type' => Wordlift_Entity_Service::TYPE_NAME, |
| 41 | 41 | 'nopaging' => true, |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | 'compare' => '!=', |
| 54 | 54 | ) |
| 55 | 55 | ) |
| 56 | - ) ); |
|
| 56 | + )); |
|
| 57 | 57 | |
| 58 | 58 | return $places; |
| 59 | 59 | } |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | * |
| 69 | 69 | * @return array An array of markers and boundaries for Leaflet. |
| 70 | 70 | */ |
| 71 | -function wl_shortcode_geomap_prepare_map( $places ) { |
|
| 71 | +function wl_shortcode_geomap_prepare_map($places) { |
|
| 72 | 72 | |
| 73 | 73 | // Prepare for min/max lat/long in case we need to define a view boundary for the client JavaScript. |
| 74 | 74 | $min_latitude = PHP_INT_MAX; |
@@ -83,13 +83,13 @@ discard block |
||
| 83 | 83 | $boundaries = array(); |
| 84 | 84 | |
| 85 | 85 | // Add a POI for each entity that has coordinates. |
| 86 | - foreach ( $places as $entity ) { |
|
| 86 | + foreach ($places as $entity) { |
|
| 87 | 87 | |
| 88 | 88 | // Get the coordinates. |
| 89 | - $coordinates = wl_get_coordinates( $entity->ID ); |
|
| 89 | + $coordinates = wl_get_coordinates($entity->ID); |
|
| 90 | 90 | |
| 91 | 91 | // Don't show the widget if the coordinates aren't set. |
| 92 | - if ( $coordinates['latitude'] == 0 || $coordinates['longitude'] == 0 ) { |
|
| 92 | + if ($coordinates['latitude'] == 0 || $coordinates['longitude'] == 0) { |
|
| 93 | 93 | continue; |
| 94 | 94 | } |
| 95 | 95 | |
@@ -97,38 +97,38 @@ discard block |
||
| 97 | 97 | // This function should be focused on returning pure data instead |
| 98 | 98 | |
| 99 | 99 | // Get the title, URL and thumb of the entity. |
| 100 | - $title = esc_attr( $entity->post_title ); |
|
| 101 | - $link = esc_attr( get_permalink( $entity->ID ) ); |
|
| 102 | - if ( '' !== ( $thumbnail_id = get_post_thumbnail_id( $entity->ID ) ) && |
|
| 103 | - false !== ( $attachment = wp_get_attachment_image_src( $thumbnail_id ) ) |
|
| 100 | + $title = esc_attr($entity->post_title); |
|
| 101 | + $link = esc_attr(get_permalink($entity->ID)); |
|
| 102 | + if ('' !== ($thumbnail_id = get_post_thumbnail_id($entity->ID)) && |
|
| 103 | + false !== ($attachment = wp_get_attachment_image_src($thumbnail_id)) |
|
| 104 | 104 | ) { |
| 105 | - $img_src = esc_attr( $attachment[0] ); |
|
| 105 | + $img_src = esc_attr($attachment[0]); |
|
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | // Build HTML popup. TODO: move thumb width in css |
| 109 | 109 | $content = "<a href=$link><h6>$title</h6>"; |
| 110 | - if ( isset( $img_src ) ) { |
|
| 111 | - $content = $content . "<img src=$img_src style='width:100%'/>"; |
|
| 110 | + if (isset($img_src)) { |
|
| 111 | + $content = $content."<img src=$img_src style='width:100%'/>"; |
|
| 112 | 112 | } |
| 113 | - $content = $content . "</a><ul>"; |
|
| 113 | + $content = $content."</a><ul>"; |
|
| 114 | 114 | // Get the related posts (published) and print them in the popup. |
| 115 | - $related_posts = wl_core_get_related_post_ids( $entity->ID, array( |
|
| 115 | + $related_posts = wl_core_get_related_post_ids($entity->ID, array( |
|
| 116 | 116 | 'status' => 'publish' |
| 117 | - ) ); |
|
| 118 | - foreach ( $related_posts as $rp_id ) { |
|
| 117 | + )); |
|
| 118 | + foreach ($related_posts as $rp_id) { |
|
| 119 | 119 | |
| 120 | - $rp = get_post( $rp_id ); |
|
| 121 | - $title = esc_attr( $rp->post_title ); |
|
| 122 | - $link = esc_attr( get_permalink( $rp->ID ) ); |
|
| 123 | - $content = $content . "<li><a href=$link>$title</a></li>"; |
|
| 120 | + $rp = get_post($rp_id); |
|
| 121 | + $title = esc_attr($rp->post_title); |
|
| 122 | + $link = esc_attr(get_permalink($rp->ID)); |
|
| 123 | + $content = $content."<li><a href=$link>$title</a></li>"; |
|
| 124 | 124 | } |
| 125 | - $content = $content . "</ul>"; |
|
| 125 | + $content = $content."</ul>"; |
|
| 126 | 126 | |
| 127 | 127 | // Formatting POI in geoJSON. |
| 128 | 128 | // http://leafletjs.com/examples/geojson.html |
| 129 | 129 | $poi = array( |
| 130 | 130 | 'type' => 'Feature', |
| 131 | - 'properties' => array( 'popupContent' => $content ), |
|
| 131 | + 'properties' => array('popupContent' => $content), |
|
| 132 | 132 | 'geometry' => array( |
| 133 | 133 | 'type' => 'Point', |
| 134 | 134 | 'coordinates' => array( |
@@ -143,7 +143,7 @@ discard block |
||
| 143 | 143 | |
| 144 | 144 | // Formatting boundaries in a Leaflet-like format (see LatLngBounds). |
| 145 | 145 | // http://leafletjs.com/reference.html#latlngbounds |
| 146 | - $boundaries[] = array( $coordinates['latitude'], $coordinates['longitude'] ); |
|
| 146 | + $boundaries[] = array($coordinates['latitude'], $coordinates['longitude']); |
|
| 147 | 147 | |
| 148 | 148 | } |
| 149 | 149 | |
@@ -166,16 +166,16 @@ discard block |
||
| 166 | 166 | */ |
| 167 | 167 | function wl_shortcode_geomap_ajax() { |
| 168 | 168 | // Get the post Id. |
| 169 | - $post_id = ( isset( $_REQUEST['post_id'] ) ? $_REQUEST['post_id'] : null ); |
|
| 169 | + $post_id = (isset($_REQUEST['post_id']) ? $_REQUEST['post_id'] : null); |
|
| 170 | 170 | |
| 171 | - $places = wl_shortcode_geomap_get_places( $post_id ); |
|
| 172 | - $map_data = wl_shortcode_geomap_prepare_map( $places ); |
|
| 171 | + $places = wl_shortcode_geomap_get_places($post_id); |
|
| 172 | + $map_data = wl_shortcode_geomap_prepare_map($places); |
|
| 173 | 173 | |
| 174 | - wl_core_send_json( $map_data ); |
|
| 174 | + wl_core_send_json($map_data); |
|
| 175 | 175 | } |
| 176 | 176 | |
| 177 | -add_action( 'wp_ajax_wl_geomap', 'wl_shortcode_geomap_ajax' ); |
|
| 178 | -add_action( 'wp_ajax_nopriv_wl_geomap', 'wl_shortcode_geomap_ajax' ); |
|
| 177 | +add_action('wp_ajax_wl_geomap', 'wl_shortcode_geomap_ajax'); |
|
| 178 | +add_action('wp_ajax_nopriv_wl_geomap', 'wl_shortcode_geomap_ajax'); |
|
| 179 | 179 | |
| 180 | 180 | /** |
| 181 | 181 | * Print geomap shortcode |
@@ -184,53 +184,53 @@ discard block |
||
| 184 | 184 | * |
| 185 | 185 | * @return string A dom element represneting a geomap. |
| 186 | 186 | */ |
| 187 | -function wl_shortcode_geomap( $atts ) { |
|
| 187 | +function wl_shortcode_geomap($atts) { |
|
| 188 | 188 | |
| 189 | 189 | // Extract attributes and set default values. |
| 190 | - $geomap_atts = shortcode_atts( array( |
|
| 190 | + $geomap_atts = shortcode_atts(array( |
|
| 191 | 191 | 'width' => '100%', |
| 192 | 192 | 'height' => '300px', |
| 193 | 193 | 'global' => false |
| 194 | - ), $atts ); |
|
| 194 | + ), $atts); |
|
| 195 | 195 | |
| 196 | 196 | // Get id of the post |
| 197 | 197 | $post_id = get_the_ID(); |
| 198 | 198 | |
| 199 | - if ( $geomap_atts['global'] || is_null( $post_id ) ) { |
|
| 199 | + if ($geomap_atts['global'] || is_null($post_id)) { |
|
| 200 | 200 | // Global geomap |
| 201 | 201 | $geomap_id = 'wl_geomap_global'; |
| 202 | 202 | $post_id = null; |
| 203 | 203 | } else { |
| 204 | 204 | // Post-specific geomap |
| 205 | - $geomap_id = 'wl_geomap_' . $post_id; |
|
| 205 | + $geomap_id = 'wl_geomap_'.$post_id; |
|
| 206 | 206 | } |
| 207 | 207 | |
| 208 | 208 | // Add leaflet css and library. |
| 209 | 209 | wp_enqueue_style( |
| 210 | 210 | 'leaflet', |
| 211 | - dirname( plugin_dir_url( __FILE__ ) ) . '/bower_components/leaflet/dist/leaflet.css' |
|
| 211 | + dirname(plugin_dir_url(__FILE__)).'/bower_components/leaflet/dist/leaflet.css' |
|
| 212 | 212 | ); |
| 213 | 213 | wp_enqueue_script( |
| 214 | 214 | 'leaflet', |
| 215 | - dirname( plugin_dir_url( __FILE__ ) ) . '/bower_components/leaflet/dist/leaflet.js' |
|
| 215 | + dirname(plugin_dir_url(__FILE__)).'/bower_components/leaflet/dist/leaflet.js' |
|
| 216 | 216 | ); |
| 217 | 217 | |
| 218 | 218 | // Add wordlift-ui css and library. |
| 219 | - wp_enqueue_style( 'wordlift-ui-css', dirname( plugin_dir_url( __FILE__ ) ) . '/css/wordlift-ui.min.css' ); |
|
| 219 | + wp_enqueue_style('wordlift-ui-css', dirname(plugin_dir_url(__FILE__)).'/css/wordlift-ui.min.css'); |
|
| 220 | 220 | |
| 221 | - wp_enqueue_script( 'wordlift-ui', dirname( plugin_dir_url( __FILE__ ) ) . '/js/wordlift-ui.min.js', array( 'jquery' ) ); |
|
| 221 | + wp_enqueue_script('wordlift-ui', dirname(plugin_dir_url(__FILE__)).'/js/wordlift-ui.min.js', array('jquery')); |
|
| 222 | 222 | |
| 223 | - wp_localize_script( 'wordlift-ui', 'wl_geomap_params', array( |
|
| 224 | - 'ajax_url' => admin_url( 'admin-ajax.php' ), // Global param |
|
| 223 | + wp_localize_script('wordlift-ui', 'wl_geomap_params', array( |
|
| 224 | + 'ajax_url' => admin_url('admin-ajax.php'), // Global param |
|
| 225 | 225 | 'action' => 'wl_geomap' // Global param |
| 226 | - ) ); |
|
| 226 | + )); |
|
| 227 | 227 | |
| 228 | 228 | // Escaping atts. |
| 229 | - $esc_class = esc_attr( 'wl-geomap' ); |
|
| 230 | - $esc_id = esc_attr( $geomap_id ); |
|
| 231 | - $esc_width = esc_attr( $geomap_atts['width'] ); |
|
| 232 | - $esc_height = esc_attr( $geomap_atts['height'] ); |
|
| 233 | - $esc_post_id = esc_attr( $post_id ); |
|
| 229 | + $esc_class = esc_attr('wl-geomap'); |
|
| 230 | + $esc_id = esc_attr($geomap_id); |
|
| 231 | + $esc_width = esc_attr($geomap_atts['width']); |
|
| 232 | + $esc_height = esc_attr($geomap_atts['height']); |
|
| 233 | + $esc_post_id = esc_attr($post_id); |
|
| 234 | 234 | |
| 235 | 235 | // Return HTML template. |
| 236 | 236 | return <<<EOF |
@@ -246,4 +246,4 @@ discard block |
||
| 246 | 246 | |
| 247 | 247 | } |
| 248 | 248 | |
| 249 | -add_shortcode( 'wl_geomap', 'wl_shortcode_geomap' ); |
|
| 250 | 249 | \ No newline at end of file |
| 250 | +add_shortcode('wl_geomap', 'wl_shortcode_geomap'); |
|
| 251 | 251 | \ No newline at end of file |
@@ -93,7 +93,7 @@ |
||
| 93 | 93 | * |
| 94 | 94 | * @since 3.0.0 |
| 95 | 95 | * |
| 96 | - * @param $text string A text that may potentially contain a WL key. |
|
| 96 | + * @param string $text string A text that may potentially contain a WL key. |
|
| 97 | 97 | * |
| 98 | 98 | * @return string A text with the key hidden. |
| 99 | 99 | */ |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | |
| 27 | 27 | // If this file is called directly, abort. |
| 28 | 28 | if ( ! defined( 'WPINC' ) ) { |
| 29 | - die; |
|
| 29 | + die; |
|
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | // Include WordLift constants. |
@@ -47,18 +47,18 @@ discard block |
||
| 47 | 47 | */ |
| 48 | 48 | function wl_write_log( $log ) { |
| 49 | 49 | |
| 50 | - $handler = apply_filters( 'wl_write_log_handler', null ); |
|
| 50 | + $handler = apply_filters( 'wl_write_log_handler', null ); |
|
| 51 | 51 | |
| 52 | - $callers = debug_backtrace(); |
|
| 53 | - $caller_function = $callers[1]['function']; |
|
| 52 | + $callers = debug_backtrace(); |
|
| 53 | + $caller_function = $callers[1]['function']; |
|
| 54 | 54 | |
| 55 | - if ( is_null( $handler ) ) { |
|
| 56 | - wl_write_log_handler( $log, $caller_function ); |
|
| 55 | + if ( is_null( $handler ) ) { |
|
| 56 | + wl_write_log_handler( $log, $caller_function ); |
|
| 57 | 57 | |
| 58 | - return; |
|
| 59 | - } |
|
| 58 | + return; |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - call_user_func( $handler, $log, $caller_function ); |
|
| 61 | + call_user_func( $handler, $log, $caller_function ); |
|
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | /** |
@@ -71,20 +71,20 @@ discard block |
||
| 71 | 71 | */ |
| 72 | 72 | function wl_write_log_handler( $log, $caller = null ) { |
| 73 | 73 | |
| 74 | - global $wl_logger; |
|
| 74 | + global $wl_logger; |
|
| 75 | 75 | |
| 76 | - if ( true === WP_DEBUG ) { |
|
| 76 | + if ( true === WP_DEBUG ) { |
|
| 77 | 77 | |
| 78 | - $message = ( isset( $caller ) ? sprintf( '[%-40.40s] ', $caller ) : '' ) . |
|
| 79 | - ( is_array( $log ) || is_object( $log ) ? print_r( $log, true ) : wl_write_log_hide_key( $log ) ); |
|
| 78 | + $message = ( isset( $caller ) ? sprintf( '[%-40.40s] ', $caller ) : '' ) . |
|
| 79 | + ( is_array( $log ) || is_object( $log ) ? print_r( $log, true ) : wl_write_log_hide_key( $log ) ); |
|
| 80 | 80 | |
| 81 | - if ( isset( $wl_logger ) ) { |
|
| 82 | - $wl_logger->info( $message ); |
|
| 83 | - } else { |
|
| 84 | - error_log( $message ); |
|
| 85 | - } |
|
| 81 | + if ( isset( $wl_logger ) ) { |
|
| 82 | + $wl_logger->info( $message ); |
|
| 83 | + } else { |
|
| 84 | + error_log( $message ); |
|
| 85 | + } |
|
| 86 | 86 | |
| 87 | - } |
|
| 87 | + } |
|
| 88 | 88 | |
| 89 | 89 | } |
| 90 | 90 | |
@@ -99,7 +99,7 @@ discard block |
||
| 99 | 99 | */ |
| 100 | 100 | function wl_write_log_hide_key( $text ) { |
| 101 | 101 | |
| 102 | - return str_ireplace( wl_configuration_get_key(), '<hidden>', $text ); |
|
| 102 | + return str_ireplace( wl_configuration_get_key(), '<hidden>', $text ); |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | /** |
@@ -111,10 +111,10 @@ discard block |
||
| 111 | 111 | */ |
| 112 | 112 | function wl_queue_sparql_update_query( $query ) { |
| 113 | 113 | |
| 114 | - $filename = WL_TEMP_DIR . WL_REQUEST_ID . '.sparql'; |
|
| 115 | - file_put_contents( $filename, $query . "\n", FILE_APPEND ); |
|
| 114 | + $filename = WL_TEMP_DIR . WL_REQUEST_ID . '.sparql'; |
|
| 115 | + file_put_contents( $filename, $query . "\n", FILE_APPEND ); |
|
| 116 | 116 | |
| 117 | - wl_write_log( "wl_queue_sparql_update_query [ filename :: $filename ]" ); |
|
| 117 | + wl_write_log( "wl_queue_sparql_update_query [ filename :: $filename ]" ); |
|
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | /** |
@@ -124,28 +124,28 @@ discard block |
||
| 124 | 124 | */ |
| 125 | 125 | function wl_execute_saved_sparql_update_query( $request_id ) { |
| 126 | 126 | |
| 127 | - $filename = WL_TEMP_DIR . $request_id . '.sparql'; |
|
| 127 | + $filename = WL_TEMP_DIR . $request_id . '.sparql'; |
|
| 128 | 128 | |
| 129 | - // If the file doesn't exist, exit. |
|
| 130 | - if ( ! file_exists( $filename ) ) { |
|
| 131 | - wl_write_log( "wl_execute_saved_sparql_update_query : file doesn't exist [ filename :: $filename ]" ); |
|
| 129 | + // If the file doesn't exist, exit. |
|
| 130 | + if ( ! file_exists( $filename ) ) { |
|
| 131 | + wl_write_log( "wl_execute_saved_sparql_update_query : file doesn't exist [ filename :: $filename ]" ); |
|
| 132 | 132 | |
| 133 | - return; |
|
| 134 | - } |
|
| 133 | + return; |
|
| 134 | + } |
|
| 135 | 135 | |
| 136 | - wl_write_log( "wl_execute_saved_sparql_update_query [ filename :: $filename ]" ); |
|
| 136 | + wl_write_log( "wl_execute_saved_sparql_update_query [ filename :: $filename ]" ); |
|
| 137 | 137 | |
| 138 | - // Get the query saved in the file. |
|
| 139 | - $query = file_get_contents( $filename ); |
|
| 138 | + // Get the query saved in the file. |
|
| 139 | + $query = file_get_contents( $filename ); |
|
| 140 | 140 | |
| 141 | - // Execute the SPARQL query. |
|
| 142 | - rl_execute_sparql_update_query( $query, false ); |
|
| 141 | + // Execute the SPARQL query. |
|
| 142 | + rl_execute_sparql_update_query( $query, false ); |
|
| 143 | 143 | |
| 144 | - // Reindex the triple store. |
|
| 145 | - wordlift_reindex_triple_store(); |
|
| 144 | + // Reindex the triple store. |
|
| 145 | + wordlift_reindex_triple_store(); |
|
| 146 | 146 | |
| 147 | - // Delete the temporary file. |
|
| 148 | - unlink( $filename ); |
|
| 147 | + // Delete the temporary file. |
|
| 148 | + unlink( $filename ); |
|
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | add_action( 'wl_execute_saved_sparql_update_query', 'wl_execute_saved_sparql_update_query', 10, 1 ); |
@@ -155,10 +155,10 @@ discard block |
||
| 155 | 155 | */ |
| 156 | 156 | function wordlift_buttonhooks() { |
| 157 | 157 | |
| 158 | - // Only add hooks when the current user has permissions AND is in Rich Text editor mode |
|
| 159 | - if ( ( current_user_can( 'edit_posts' ) || current_user_can( 'edit_pages' ) ) && get_user_option( 'rich_editing' ) ) { |
|
| 160 | - add_filter( 'mce_external_plugins', 'wordlift_register_tinymce_javascript' ); |
|
| 161 | - } |
|
| 158 | + // Only add hooks when the current user has permissions AND is in Rich Text editor mode |
|
| 159 | + if ( ( current_user_can( 'edit_posts' ) || current_user_can( 'edit_pages' ) ) && get_user_option( 'rich_editing' ) ) { |
|
| 160 | + add_filter( 'mce_external_plugins', 'wordlift_register_tinymce_javascript' ); |
|
| 161 | + } |
|
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | /** |
@@ -170,10 +170,10 @@ discard block |
||
| 170 | 170 | */ |
| 171 | 171 | function wordlift_register_tinymce_javascript( $plugin_array ) { |
| 172 | 172 | |
| 173 | - // add the wordlift plugin. |
|
| 174 | - $plugin_array['wordlift'] = plugin_dir_url( __FILE__ ) . 'js/wordlift-reloaded.js'; |
|
| 173 | + // add the wordlift plugin. |
|
| 174 | + $plugin_array['wordlift'] = plugin_dir_url( __FILE__ ) . 'js/wordlift-reloaded.js'; |
|
| 175 | 175 | |
| 176 | - return $plugin_array; |
|
| 176 | + return $plugin_array; |
|
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | /** |
@@ -181,21 +181,21 @@ discard block |
||
| 181 | 181 | * see http://vip.wordpress.com/documentation/register-additional-html-attributes-for-tinymce-and-wp-kses/ |
| 182 | 182 | */ |
| 183 | 183 | function wordlift_allowed_post_tags() { |
| 184 | - global $allowedposttags; |
|
| 185 | - |
|
| 186 | - $tags = array( 'span' ); |
|
| 187 | - $new_attributes = array( |
|
| 188 | - 'itemscope' => array(), |
|
| 189 | - 'itemtype' => array(), |
|
| 190 | - 'itemprop' => array(), |
|
| 191 | - 'itemid' => array() |
|
| 192 | - ); |
|
| 193 | - |
|
| 194 | - foreach ( $tags as $tag ) { |
|
| 195 | - if ( isset( $allowedposttags[ $tag ] ) && is_array( $allowedposttags[ $tag ] ) ) { |
|
| 196 | - $allowedposttags[ $tag ] = array_merge( $allowedposttags[ $tag ], $new_attributes ); |
|
| 197 | - } |
|
| 198 | - } |
|
| 184 | + global $allowedposttags; |
|
| 185 | + |
|
| 186 | + $tags = array( 'span' ); |
|
| 187 | + $new_attributes = array( |
|
| 188 | + 'itemscope' => array(), |
|
| 189 | + 'itemtype' => array(), |
|
| 190 | + 'itemprop' => array(), |
|
| 191 | + 'itemid' => array() |
|
| 192 | + ); |
|
| 193 | + |
|
| 194 | + foreach ( $tags as $tag ) { |
|
| 195 | + if ( isset( $allowedposttags[ $tag ] ) && is_array( $allowedposttags[ $tag ] ) ) { |
|
| 196 | + $allowedposttags[ $tag ] = array_merge( $allowedposttags[ $tag ], $new_attributes ); |
|
| 197 | + } |
|
| 198 | + } |
|
| 199 | 199 | } |
| 200 | 200 | |
| 201 | 201 | // init process for button control |
@@ -209,21 +209,21 @@ discard block |
||
| 209 | 209 | */ |
| 210 | 210 | function wordlift_admin_enqueue_scripts() { |
| 211 | 211 | |
| 212 | - // Added for compatibility with WordPress 3.9 (see http://make.wordpress.org/core/2014/04/16/jquery-ui-and-wpdialogs-in-wordpress-3-9/) |
|
| 213 | - wp_enqueue_script( 'wpdialogs' ); |
|
| 214 | - wp_enqueue_style( 'wp-jquery-ui-dialog' ); |
|
| 212 | + // Added for compatibility with WordPress 3.9 (see http://make.wordpress.org/core/2014/04/16/jquery-ui-and-wpdialogs-in-wordpress-3-9/) |
|
| 213 | + wp_enqueue_script( 'wpdialogs' ); |
|
| 214 | + wp_enqueue_style( 'wp-jquery-ui-dialog' ); |
|
| 215 | 215 | |
| 216 | - wp_enqueue_style( 'wordlift-reloaded', plugin_dir_url( __FILE__ ) . 'css/wordlift-reloaded.min.css' ); |
|
| 216 | + wp_enqueue_style( 'wordlift-reloaded', plugin_dir_url( __FILE__ ) . 'css/wordlift-reloaded.min.css' ); |
|
| 217 | 217 | |
| 218 | - wp_enqueue_script( 'jquery-ui-autocomplete' ); |
|
| 219 | - wp_enqueue_script( 'angularjs', plugin_dir_url( __FILE__ ) . 'bower_components/angular/angular.min.js' ); |
|
| 218 | + wp_enqueue_script( 'jquery-ui-autocomplete' ); |
|
| 219 | + wp_enqueue_script( 'angularjs', plugin_dir_url( __FILE__ ) . 'bower_components/angular/angular.min.js' ); |
|
| 220 | 220 | |
| 221 | 221 | } |
| 222 | 222 | |
| 223 | 223 | add_action( 'admin_enqueue_scripts', 'wordlift_admin_enqueue_scripts' ); |
| 224 | 224 | |
| 225 | 225 | function wl_enqueue_scripts() { |
| 226 | - wp_enqueue_style( 'wordlift-ui', plugin_dir_url( __FILE__ ) . 'css/wordlift-ui.min.css' ); |
|
| 226 | + wp_enqueue_style( 'wordlift-ui', plugin_dir_url( __FILE__ ) . 'css/wordlift-ui.min.css' ); |
|
| 227 | 227 | } |
| 228 | 228 | |
| 229 | 229 | add_action( 'wp_enqueue_scripts', 'wl_enqueue_scripts' ); |
@@ -238,18 +238,18 @@ discard block |
||
| 238 | 238 | */ |
| 239 | 239 | function wordlift_allowed_html( $allowedtags, $context ) { |
| 240 | 240 | |
| 241 | - if ( 'post' !== $context ) { |
|
| 242 | - return $allowedtags; |
|
| 243 | - } |
|
| 244 | - |
|
| 245 | - return array_merge_recursive( $allowedtags, array( |
|
| 246 | - 'span' => array( |
|
| 247 | - 'itemscope' => true, |
|
| 248 | - 'itemtype' => true, |
|
| 249 | - 'itemid' => true, |
|
| 250 | - 'itemprop' => true |
|
| 251 | - ) |
|
| 252 | - ) ); |
|
| 241 | + if ( 'post' !== $context ) { |
|
| 242 | + return $allowedtags; |
|
| 243 | + } |
|
| 244 | + |
|
| 245 | + return array_merge_recursive( $allowedtags, array( |
|
| 246 | + 'span' => array( |
|
| 247 | + 'itemscope' => true, |
|
| 248 | + 'itemtype' => true, |
|
| 249 | + 'itemid' => true, |
|
| 250 | + 'itemprop' => true |
|
| 251 | + ) |
|
| 252 | + ) ); |
|
| 253 | 253 | } |
| 254 | 254 | |
| 255 | 255 | add_filter( 'wp_kses_allowed_html', 'wordlift_allowed_html', 10, 2 ); |
@@ -263,15 +263,15 @@ discard block |
||
| 263 | 263 | */ |
| 264 | 264 | function wl_get_coordinates( $post_id ) { |
| 265 | 265 | |
| 266 | - $latitude = wl_schema_get_value( $post_id, 'latitude' ); |
|
| 267 | - $longitude = wl_schema_get_value( $post_id, 'longitude' ); |
|
| 266 | + $latitude = wl_schema_get_value( $post_id, 'latitude' ); |
|
| 267 | + $longitude = wl_schema_get_value( $post_id, 'longitude' ); |
|
| 268 | 268 | |
| 269 | - // DO NOT set latitude/longitude to 0/0 as default values. It's a specific place on the globe: |
|
| 270 | - // "The zero/zero point of this system is located in the Gulf of Guinea about 625 km (390 mi) south of Tema, Ghana." |
|
| 271 | - return array( |
|
| 272 | - 'latitude' => isset( $latitude[0] ) && is_numeric( $latitude[0] ) ? $latitude[0] : '', |
|
| 273 | - 'longitude' => isset( $longitude[0] ) && is_numeric( $longitude[0] ) ? $longitude[0] : '' |
|
| 274 | - ); |
|
| 269 | + // DO NOT set latitude/longitude to 0/0 as default values. It's a specific place on the globe: |
|
| 270 | + // "The zero/zero point of this system is located in the Gulf of Guinea about 625 km (390 mi) south of Tema, Ghana." |
|
| 271 | + return array( |
|
| 272 | + 'latitude' => isset( $latitude[0] ) && is_numeric( $latitude[0] ) ? $latitude[0] : '', |
|
| 273 | + 'longitude' => isset( $longitude[0] ) && is_numeric( $longitude[0] ) ? $longitude[0] : '' |
|
| 274 | + ); |
|
| 275 | 275 | } |
| 276 | 276 | |
| 277 | 277 | /** |
@@ -283,13 +283,13 @@ discard block |
||
| 283 | 283 | */ |
| 284 | 284 | function wl_get_post_modified_time( $post ) { |
| 285 | 285 | |
| 286 | - $date_modified = get_post_modified_time( 'c', true, $post ); |
|
| 286 | + $date_modified = get_post_modified_time( 'c', true, $post ); |
|
| 287 | 287 | |
| 288 | - if ( '-' === substr( $date_modified, 0, 1 ) ) { |
|
| 289 | - return get_the_time( 'c', $post ); |
|
| 290 | - } |
|
| 288 | + if ( '-' === substr( $date_modified, 0, 1 ) ) { |
|
| 289 | + return get_the_time( 'c', $post ); |
|
| 290 | + } |
|
| 291 | 291 | |
| 292 | - return $date_modified; |
|
| 292 | + return $date_modified; |
|
| 293 | 293 | } |
| 294 | 294 | |
| 295 | 295 | /** |
@@ -301,34 +301,34 @@ discard block |
||
| 301 | 301 | */ |
| 302 | 302 | function wl_get_image_urls( $post_id ) { |
| 303 | 303 | |
| 304 | - // wl_write_log( "wl_get_image_urls [ post id :: $post_id ]" ); |
|
| 304 | + // wl_write_log( "wl_get_image_urls [ post id :: $post_id ]" ); |
|
| 305 | 305 | |
| 306 | - $images = get_children( array( |
|
| 307 | - 'post_parent' => $post_id, |
|
| 308 | - 'post_type' => 'attachment', |
|
| 309 | - 'post_mime_type' => 'image' |
|
| 310 | - ) ); |
|
| 306 | + $images = get_children( array( |
|
| 307 | + 'post_parent' => $post_id, |
|
| 308 | + 'post_type' => 'attachment', |
|
| 309 | + 'post_mime_type' => 'image' |
|
| 310 | + ) ); |
|
| 311 | 311 | |
| 312 | - // Return an empty array if no image is found. |
|
| 313 | - if ( empty( $images ) ) { |
|
| 314 | - return array(); |
|
| 315 | - } |
|
| 312 | + // Return an empty array if no image is found. |
|
| 313 | + if ( empty( $images ) ) { |
|
| 314 | + return array(); |
|
| 315 | + } |
|
| 316 | 316 | |
| 317 | - // Prepare the return array. |
|
| 318 | - $image_urls = array(); |
|
| 317 | + // Prepare the return array. |
|
| 318 | + $image_urls = array(); |
|
| 319 | 319 | |
| 320 | - // Collect the URLs. |
|
| 321 | - foreach ( $images as $attachment_id => $attachment ) { |
|
| 322 | - $image_url = wp_get_attachment_url( $attachment_id ); |
|
| 323 | - // Ensure the URL isn't collected already. |
|
| 324 | - if ( ! in_array( $image_url, $image_urls ) ) { |
|
| 325 | - array_push( $image_urls, $image_url ); |
|
| 326 | - } |
|
| 327 | - } |
|
| 320 | + // Collect the URLs. |
|
| 321 | + foreach ( $images as $attachment_id => $attachment ) { |
|
| 322 | + $image_url = wp_get_attachment_url( $attachment_id ); |
|
| 323 | + // Ensure the URL isn't collected already. |
|
| 324 | + if ( ! in_array( $image_url, $image_urls ) ) { |
|
| 325 | + array_push( $image_urls, $image_url ); |
|
| 326 | + } |
|
| 327 | + } |
|
| 328 | 328 | |
| 329 | - // wl_write_log( "wl_get_image_urls [ post id :: $post_id ][ image urls count :: " . count( $image_urls ) . " ]" ); |
|
| 329 | + // wl_write_log( "wl_get_image_urls [ post id :: $post_id ][ image urls count :: " . count( $image_urls ) . " ]" ); |
|
| 330 | 330 | |
| 331 | - return $image_urls; |
|
| 331 | + return $image_urls; |
|
| 332 | 332 | } |
| 333 | 333 | |
| 334 | 334 | /** |
@@ -341,19 +341,19 @@ discard block |
||
| 341 | 341 | */ |
| 342 | 342 | function wl_get_sparql_images( $uri, $post_id ) { |
| 343 | 343 | |
| 344 | - $sparql = ''; |
|
| 344 | + $sparql = ''; |
|
| 345 | 345 | |
| 346 | - // Get the escaped URI. |
|
| 347 | - $uri_e = esc_html( $uri ); |
|
| 346 | + // Get the escaped URI. |
|
| 347 | + $uri_e = esc_html( $uri ); |
|
| 348 | 348 | |
| 349 | - // Add SPARQL stmts to write the schema:image. |
|
| 350 | - $image_urls = wl_get_image_urls( $post_id ); |
|
| 351 | - foreach ( $image_urls as $image_url ) { |
|
| 352 | - $image_url_esc = wl_sparql_escape_uri( $image_url ); |
|
| 353 | - $sparql .= " <$uri_e> schema:image <$image_url_esc> . \n"; |
|
| 354 | - } |
|
| 349 | + // Add SPARQL stmts to write the schema:image. |
|
| 350 | + $image_urls = wl_get_image_urls( $post_id ); |
|
| 351 | + foreach ( $image_urls as $image_url ) { |
|
| 352 | + $image_url_esc = wl_sparql_escape_uri( $image_url ); |
|
| 353 | + $sparql .= " <$uri_e> schema:image <$image_url_esc> . \n"; |
|
| 354 | + } |
|
| 355 | 355 | |
| 356 | - return $sparql; |
|
| 356 | + return $sparql; |
|
| 357 | 357 | } |
| 358 | 358 | |
| 359 | 359 | /** |
@@ -366,24 +366,24 @@ discard block |
||
| 366 | 366 | */ |
| 367 | 367 | function wl_get_attachment_for_source_url( $parent_post_id, $source_url ) { |
| 368 | 368 | |
| 369 | - // wl_write_log( "wl_get_attachment_for_source_url [ parent post id :: $parent_post_id ][ source url :: $source_url ]" ); |
|
| 369 | + // wl_write_log( "wl_get_attachment_for_source_url [ parent post id :: $parent_post_id ][ source url :: $source_url ]" ); |
|
| 370 | 370 | |
| 371 | - $posts = get_posts( array( |
|
| 372 | - 'post_type' => 'attachment', |
|
| 373 | - 'posts_per_page' => 1, |
|
| 374 | - 'post_status' => 'any', |
|
| 375 | - 'post_parent' => $parent_post_id, |
|
| 376 | - 'meta_key' => 'wl_source_url', |
|
| 377 | - 'meta_value' => $source_url |
|
| 378 | - ) ); |
|
| 371 | + $posts = get_posts( array( |
|
| 372 | + 'post_type' => 'attachment', |
|
| 373 | + 'posts_per_page' => 1, |
|
| 374 | + 'post_status' => 'any', |
|
| 375 | + 'post_parent' => $parent_post_id, |
|
| 376 | + 'meta_key' => 'wl_source_url', |
|
| 377 | + 'meta_value' => $source_url |
|
| 378 | + ) ); |
|
| 379 | 379 | |
| 380 | - // Return the found post. |
|
| 381 | - if ( 1 === count( $posts ) ) { |
|
| 382 | - return $posts[0]; |
|
| 383 | - } |
|
| 380 | + // Return the found post. |
|
| 381 | + if ( 1 === count( $posts ) ) { |
|
| 382 | + return $posts[0]; |
|
| 383 | + } |
|
| 384 | 384 | |
| 385 | - // Return null. |
|
| 386 | - return null; |
|
| 385 | + // Return null. |
|
| 386 | + return null; |
|
| 387 | 387 | } |
| 388 | 388 | |
| 389 | 389 | /** |
@@ -394,8 +394,8 @@ discard block |
||
| 394 | 394 | */ |
| 395 | 395 | function wl_set_source_url( $post_id, $source_url ) { |
| 396 | 396 | |
| 397 | - delete_post_meta( $post_id, 'wl_source_url' ); |
|
| 398 | - add_post_meta( $post_id, 'wl_source_url', $source_url ); |
|
| 397 | + delete_post_meta( $post_id, 'wl_source_url' ); |
|
| 398 | + add_post_meta( $post_id, 'wl_source_url', $source_url ); |
|
| 399 | 399 | } |
| 400 | 400 | |
| 401 | 401 | |
@@ -413,43 +413,43 @@ discard block |
||
| 413 | 413 | */ |
| 414 | 414 | function wl_flush_rewrite_rules_hard( $hard ) { |
| 415 | 415 | |
| 416 | - // Get all published posts. |
|
| 417 | - $posts = get_posts( array( |
|
| 418 | - 'posts_per_page' => - 1, |
|
| 419 | - 'post_type' => 'any', |
|
| 420 | - 'post_status' => 'publish' |
|
| 421 | - ) ); |
|
| 416 | + // Get all published posts. |
|
| 417 | + $posts = get_posts( array( |
|
| 418 | + 'posts_per_page' => - 1, |
|
| 419 | + 'post_type' => 'any', |
|
| 420 | + 'post_status' => 'publish' |
|
| 421 | + ) ); |
|
| 422 | 422 | |
| 423 | - // Holds the delete part of the query. |
|
| 424 | - $delete_query = rl_sparql_prefixes(); |
|
| 425 | - // Holds the insert part of the query. |
|
| 426 | - $insert_query = 'INSERT DATA { '; |
|
| 423 | + // Holds the delete part of the query. |
|
| 424 | + $delete_query = rl_sparql_prefixes(); |
|
| 425 | + // Holds the insert part of the query. |
|
| 426 | + $insert_query = 'INSERT DATA { '; |
|
| 427 | 427 | |
| 428 | - // Cycle in each post to build the query. |
|
| 429 | - foreach ( $posts as $post ) { |
|
| 428 | + // Cycle in each post to build the query. |
|
| 429 | + foreach ( $posts as $post ) { |
|
| 430 | 430 | |
| 431 | - // Ignore revisions. |
|
| 432 | - if ( wp_is_post_revision( $post->ID ) ) { |
|
| 433 | - continue; |
|
| 434 | - } |
|
| 431 | + // Ignore revisions. |
|
| 432 | + if ( wp_is_post_revision( $post->ID ) ) { |
|
| 433 | + continue; |
|
| 434 | + } |
|
| 435 | 435 | |
| 436 | - // Get the entity URI. |
|
| 437 | - $uri = wl_sparql_escape_uri( wl_get_entity_uri( $post->ID ) ); |
|
| 436 | + // Get the entity URI. |
|
| 437 | + $uri = wl_sparql_escape_uri( wl_get_entity_uri( $post->ID ) ); |
|
| 438 | 438 | |
| 439 | - // Get the post URL. |
|
| 440 | - $url = wl_sparql_escape_uri( get_permalink( $post->ID ) ); |
|
| 439 | + // Get the post URL. |
|
| 440 | + $url = wl_sparql_escape_uri( get_permalink( $post->ID ) ); |
|
| 441 | 441 | |
| 442 | - // Prepare the DELETE and INSERT commands. |
|
| 443 | - $delete_query .= "DELETE { <$uri> schema:url ?u . } WHERE { <$uri> schema:url ?u . };\n"; |
|
| 444 | - $insert_query .= " <$uri> schema:url <$url> . \n"; |
|
| 442 | + // Prepare the DELETE and INSERT commands. |
|
| 443 | + $delete_query .= "DELETE { <$uri> schema:url ?u . } WHERE { <$uri> schema:url ?u . };\n"; |
|
| 444 | + $insert_query .= " <$uri> schema:url <$url> . \n"; |
|
| 445 | 445 | |
| 446 | - // wl_write_log( "[ uri :: $uri ][ url :: $url ]" ); |
|
| 447 | - } |
|
| 446 | + // wl_write_log( "[ uri :: $uri ][ url :: $url ]" ); |
|
| 447 | + } |
|
| 448 | 448 | |
| 449 | - $insert_query .= ' };'; |
|
| 449 | + $insert_query .= ' };'; |
|
| 450 | 450 | |
| 451 | - // Execute the query. |
|
| 452 | - rl_execute_sparql_update_query( $delete_query . $insert_query ); |
|
| 451 | + // Execute the query. |
|
| 452 | + rl_execute_sparql_update_query( $delete_query . $insert_query ); |
|
| 453 | 453 | } |
| 454 | 454 | |
| 455 | 455 | add_filter( 'flush_rewrite_rules_hard', 'wl_flush_rewrite_rules_hard', 10, 1 ); |
@@ -466,15 +466,15 @@ discard block |
||
| 466 | 466 | */ |
| 467 | 467 | function wl_sanitize_uri_path( $path, $char = '_' ) { |
| 468 | 468 | |
| 469 | - // wl_write_log( "wl_sanitize_uri_path [ path :: $path ][ char :: $char ]" ); |
|
| 469 | + // wl_write_log( "wl_sanitize_uri_path [ path :: $path ][ char :: $char ]" ); |
|
| 470 | 470 | |
| 471 | - // According to RFC2396 (http://www.ietf.org/rfc/rfc2396.txt) these characters are reserved: |
|
| 472 | - // ";" | "/" | "?" | ":" | "@" | "&" | "=" | "+" | |
|
| 473 | - // "$" | "," |
|
| 474 | - // Plus the ' ' (space). |
|
| 475 | - // TODO: We shall use the same regex used by MediaWiki (http://stackoverflow.com/questions/23114983/mediawiki-wikipedia-url-sanitization-regex) |
|
| 471 | + // According to RFC2396 (http://www.ietf.org/rfc/rfc2396.txt) these characters are reserved: |
|
| 472 | + // ";" | "/" | "?" | ":" | "@" | "&" | "=" | "+" | |
|
| 473 | + // "$" | "," |
|
| 474 | + // Plus the ' ' (space). |
|
| 475 | + // TODO: We shall use the same regex used by MediaWiki (http://stackoverflow.com/questions/23114983/mediawiki-wikipedia-url-sanitization-regex) |
|
| 476 | 476 | |
| 477 | - return sanitize_title( preg_replace( '/[;\/?:@&=+$,\s]/', $char, stripslashes( $path ) ) ); |
|
| 477 | + return sanitize_title( preg_replace( '/[;\/?:@&=+$,\s]/', $char, stripslashes( $path ) ) ); |
|
| 478 | 478 | } |
| 479 | 479 | |
| 480 | 480 | /** |
@@ -482,26 +482,26 @@ discard block |
||
| 482 | 482 | */ |
| 483 | 483 | function wl_shutdown() { |
| 484 | 484 | |
| 485 | - // Get the filename to the temporary SPARQL file. |
|
| 486 | - $filename = WL_TEMP_DIR . WL_REQUEST_ID . '.sparql'; |
|
| 485 | + // Get the filename to the temporary SPARQL file. |
|
| 486 | + $filename = WL_TEMP_DIR . WL_REQUEST_ID . '.sparql'; |
|
| 487 | 487 | |
| 488 | - // If WordLift is buffering SPARQL queries, we're admins and a buffer exists, then schedule it. |
|
| 489 | - if ( WL_ENABLE_SPARQL_UPDATE_QUERIES_BUFFERING && is_admin() && file_exists( $filename ) ) { |
|
| 488 | + // If WordLift is buffering SPARQL queries, we're admins and a buffer exists, then schedule it. |
|
| 489 | + if ( WL_ENABLE_SPARQL_UPDATE_QUERIES_BUFFERING && is_admin() && file_exists( $filename ) ) { |
|
| 490 | 490 | |
| 491 | - // The request ID. |
|
| 492 | - $args = array( WL_REQUEST_ID ); |
|
| 491 | + // The request ID. |
|
| 492 | + $args = array( WL_REQUEST_ID ); |
|
| 493 | 493 | |
| 494 | - // Schedule the execution of the SPARQL query with the request ID. |
|
| 495 | - wp_schedule_single_event( time(), 'wl_execute_saved_sparql_update_query', $args ); |
|
| 494 | + // Schedule the execution of the SPARQL query with the request ID. |
|
| 495 | + wp_schedule_single_event( time(), 'wl_execute_saved_sparql_update_query', $args ); |
|
| 496 | 496 | |
| 497 | - // Check that the request is scheduled. |
|
| 498 | - $timestamp = wp_next_scheduled( 'wl_execute_saved_sparql_update_query', $args ); |
|
| 497 | + // Check that the request is scheduled. |
|
| 498 | + $timestamp = wp_next_scheduled( 'wl_execute_saved_sparql_update_query', $args ); |
|
| 499 | 499 | |
| 500 | - // Spawn the cron. |
|
| 501 | - spawn_cron(); |
|
| 500 | + // Spawn the cron. |
|
| 501 | + spawn_cron(); |
|
| 502 | 502 | |
| 503 | - wl_write_log( "wl_shutdown [ request id :: " . WL_REQUEST_ID . " ][ timestamp :: $timestamp ]" ); |
|
| 504 | - } |
|
| 503 | + wl_write_log( "wl_shutdown [ request id :: " . WL_REQUEST_ID . " ][ timestamp :: $timestamp ]" ); |
|
| 504 | + } |
|
| 505 | 505 | } |
| 506 | 506 | |
| 507 | 507 | add_action( 'shutdown', 'wl_shutdown' ); |
@@ -515,45 +515,45 @@ discard block |
||
| 515 | 515 | */ |
| 516 | 516 | function wl_replace_item_id_with_uri( $content ) { |
| 517 | 517 | |
| 518 | - // wl_write_log( "wl_replace_item_id_with_uri" ); |
|
| 518 | + // wl_write_log( "wl_replace_item_id_with_uri" ); |
|
| 519 | 519 | |
| 520 | - // Strip slashes, see https://core.trac.wordpress.org/ticket/21767 |
|
| 521 | - $content = stripslashes( $content ); |
|
| 520 | + // Strip slashes, see https://core.trac.wordpress.org/ticket/21767 |
|
| 521 | + $content = stripslashes( $content ); |
|
| 522 | 522 | |
| 523 | - // If any match are found. |
|
| 524 | - $matches = array(); |
|
| 525 | - if ( 0 < preg_match_all( '/ itemid="([^"]+)"/i', $content, $matches, PREG_SET_ORDER ) ) { |
|
| 523 | + // If any match are found. |
|
| 524 | + $matches = array(); |
|
| 525 | + if ( 0 < preg_match_all( '/ itemid="([^"]+)"/i', $content, $matches, PREG_SET_ORDER ) ) { |
|
| 526 | 526 | |
| 527 | - foreach ( $matches as $match ) { |
|
| 527 | + foreach ( $matches as $match ) { |
|
| 528 | 528 | |
| 529 | - // Get the item ID. |
|
| 530 | - $item_id = $match[1]; |
|
| 529 | + // Get the item ID. |
|
| 530 | + $item_id = $match[1]; |
|
| 531 | 531 | |
| 532 | - // Get the post bound to that item ID (looking both in the 'official' URI and in the 'same-as' . |
|
| 533 | - $post = wl_get_entity_post_by_uri( $item_id ); |
|
| 532 | + // Get the post bound to that item ID (looking both in the 'official' URI and in the 'same-as' . |
|
| 533 | + $post = wl_get_entity_post_by_uri( $item_id ); |
|
| 534 | 534 | |
| 535 | - // If no entity is found, continue to the next one. |
|
| 536 | - if ( null === $post ) { |
|
| 537 | - continue; |
|
| 538 | - } |
|
| 535 | + // If no entity is found, continue to the next one. |
|
| 536 | + if ( null === $post ) { |
|
| 537 | + continue; |
|
| 538 | + } |
|
| 539 | 539 | |
| 540 | - // Get the URI for that post. |
|
| 541 | - $uri = wl_get_entity_uri( $post->ID ); |
|
| 540 | + // Get the URI for that post. |
|
| 541 | + $uri = wl_get_entity_uri( $post->ID ); |
|
| 542 | 542 | |
| 543 | - // wl_write_log( "wl_replace_item_id_with_uri [ item id :: $item_id ][ uri :: $uri ]" ); |
|
| 543 | + // wl_write_log( "wl_replace_item_id_with_uri [ item id :: $item_id ][ uri :: $uri ]" ); |
|
| 544 | 544 | |
| 545 | - // If the item ID and the URI differ, replace the item ID with the URI saved in WordPress. |
|
| 546 | - if ( $item_id !== $uri ) { |
|
| 547 | - $uri_e = esc_html( $uri ); |
|
| 548 | - $content = str_replace( " itemid=\"$item_id\"", " itemid=\"$uri_e\"", $content ); |
|
| 549 | - } |
|
| 550 | - } |
|
| 551 | - } |
|
| 545 | + // If the item ID and the URI differ, replace the item ID with the URI saved in WordPress. |
|
| 546 | + if ( $item_id !== $uri ) { |
|
| 547 | + $uri_e = esc_html( $uri ); |
|
| 548 | + $content = str_replace( " itemid=\"$item_id\"", " itemid=\"$uri_e\"", $content ); |
|
| 549 | + } |
|
| 550 | + } |
|
| 551 | + } |
|
| 552 | 552 | |
| 553 | - // Reapply slashes. |
|
| 554 | - $content = addslashes( $content ); |
|
| 553 | + // Reapply slashes. |
|
| 554 | + $content = addslashes( $content ); |
|
| 555 | 555 | |
| 556 | - return $content; |
|
| 556 | + return $content; |
|
| 557 | 557 | } |
| 558 | 558 | |
| 559 | 559 | add_filter( 'content_save_pre', 'wl_replace_item_id_with_uri', 1, 1 ); |
@@ -632,8 +632,8 @@ discard block |
||
| 632 | 632 | * This action is documented in includes/class-wordlift-activator.php |
| 633 | 633 | */ |
| 634 | 634 | function activate_wordlift() { |
| 635 | - require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-activator.php'; |
|
| 636 | - Wordlift_Activator::activate(); |
|
| 635 | + require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-activator.php'; |
|
| 636 | + Wordlift_Activator::activate(); |
|
| 637 | 637 | } |
| 638 | 638 | |
| 639 | 639 | /** |
@@ -641,8 +641,8 @@ discard block |
||
| 641 | 641 | * This action is documented in includes/class-wordlift-deactivator.php |
| 642 | 642 | */ |
| 643 | 643 | function deactivate_wordlift() { |
| 644 | - require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-deactivator.php'; |
|
| 645 | - Wordlift_Deactivator::deactivate(); |
|
| 644 | + require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-deactivator.php'; |
|
| 645 | + Wordlift_Deactivator::deactivate(); |
|
| 646 | 646 | } |
| 647 | 647 | |
| 648 | 648 | register_activation_hook( __FILE__, 'activate_wordlift' ); |
@@ -665,8 +665,8 @@ discard block |
||
| 665 | 665 | */ |
| 666 | 666 | function run_wordlift() { |
| 667 | 667 | |
| 668 | - $plugin = new Wordlift(); |
|
| 669 | - $plugin->run(); |
|
| 668 | + $plugin = new Wordlift(); |
|
| 669 | + $plugin->run(); |
|
| 670 | 670 | |
| 671 | 671 | } |
| 672 | 672 | |
@@ -25,16 +25,16 @@ discard block |
||
| 25 | 25 | */ |
| 26 | 26 | |
| 27 | 27 | // If this file is called directly, abort. |
| 28 | -if ( ! defined( 'WPINC' ) ) { |
|
| 28 | +if ( ! defined('WPINC')) { |
|
| 29 | 29 | die; |
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | // Include WordLift constants. |
| 33 | -require_once( 'wordlift_constants.php' ); |
|
| 33 | +require_once('wordlift_constants.php'); |
|
| 34 | 34 | |
| 35 | 35 | // Load modules |
| 36 | -require_once( 'modules/core/wordlift_core.php' ); |
|
| 37 | -require_once( 'modules/configuration/wordlift_configuration.php' ); |
|
| 36 | +require_once('modules/core/wordlift_core.php'); |
|
| 37 | +require_once('modules/configuration/wordlift_configuration.php'); |
|
| 38 | 38 | |
| 39 | 39 | /** |
| 40 | 40 | * Log to the debug.log file. |
@@ -45,20 +45,20 @@ discard block |
||
| 45 | 45 | * |
| 46 | 46 | * @param string|mixed $log The log data. |
| 47 | 47 | */ |
| 48 | -function wl_write_log( $log ) { |
|
| 48 | +function wl_write_log($log) { |
|
| 49 | 49 | |
| 50 | - $handler = apply_filters( 'wl_write_log_handler', null ); |
|
| 50 | + $handler = apply_filters('wl_write_log_handler', null); |
|
| 51 | 51 | |
| 52 | 52 | $callers = debug_backtrace(); |
| 53 | 53 | $caller_function = $callers[1]['function']; |
| 54 | 54 | |
| 55 | - if ( is_null( $handler ) ) { |
|
| 56 | - wl_write_log_handler( $log, $caller_function ); |
|
| 55 | + if (is_null($handler)) { |
|
| 56 | + wl_write_log_handler($log, $caller_function); |
|
| 57 | 57 | |
| 58 | 58 | return; |
| 59 | 59 | } |
| 60 | 60 | |
| 61 | - call_user_func( $handler, $log, $caller_function ); |
|
| 61 | + call_user_func($handler, $log, $caller_function); |
|
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | /** |
@@ -69,19 +69,19 @@ discard block |
||
| 69 | 69 | * @param string|array $log The log data. |
| 70 | 70 | * @param string $caller The calling function. |
| 71 | 71 | */ |
| 72 | -function wl_write_log_handler( $log, $caller = null ) { |
|
| 72 | +function wl_write_log_handler($log, $caller = null) { |
|
| 73 | 73 | |
| 74 | 74 | global $wl_logger; |
| 75 | 75 | |
| 76 | - if ( true === WP_DEBUG ) { |
|
| 76 | + if (true === WP_DEBUG) { |
|
| 77 | 77 | |
| 78 | - $message = ( isset( $caller ) ? sprintf( '[%-40.40s] ', $caller ) : '' ) . |
|
| 79 | - ( is_array( $log ) || is_object( $log ) ? print_r( $log, true ) : wl_write_log_hide_key( $log ) ); |
|
| 78 | + $message = (isset($caller) ? sprintf('[%-40.40s] ', $caller) : ''). |
|
| 79 | + (is_array($log) || is_object($log) ? print_r($log, true) : wl_write_log_hide_key($log)); |
|
| 80 | 80 | |
| 81 | - if ( isset( $wl_logger ) ) { |
|
| 82 | - $wl_logger->info( $message ); |
|
| 81 | + if (isset($wl_logger)) { |
|
| 82 | + $wl_logger->info($message); |
|
| 83 | 83 | } else { |
| 84 | - error_log( $message ); |
|
| 84 | + error_log($message); |
|
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | } |
@@ -97,9 +97,9 @@ discard block |
||
| 97 | 97 | * |
| 98 | 98 | * @return string A text with the key hidden. |
| 99 | 99 | */ |
| 100 | -function wl_write_log_hide_key( $text ) { |
|
| 100 | +function wl_write_log_hide_key($text) { |
|
| 101 | 101 | |
| 102 | - return str_ireplace( wl_configuration_get_key(), '<hidden>', $text ); |
|
| 102 | + return str_ireplace(wl_configuration_get_key(), '<hidden>', $text); |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | /** |
@@ -109,12 +109,12 @@ discard block |
||
| 109 | 109 | * |
| 110 | 110 | * @param string $query A SPARQL query. |
| 111 | 111 | */ |
| 112 | -function wl_queue_sparql_update_query( $query ) { |
|
| 112 | +function wl_queue_sparql_update_query($query) { |
|
| 113 | 113 | |
| 114 | - $filename = WL_TEMP_DIR . WL_REQUEST_ID . '.sparql'; |
|
| 115 | - file_put_contents( $filename, $query . "\n", FILE_APPEND ); |
|
| 114 | + $filename = WL_TEMP_DIR.WL_REQUEST_ID.'.sparql'; |
|
| 115 | + file_put_contents($filename, $query."\n", FILE_APPEND); |
|
| 116 | 116 | |
| 117 | - wl_write_log( "wl_queue_sparql_update_query [ filename :: $filename ]" ); |
|
| 117 | + wl_write_log("wl_queue_sparql_update_query [ filename :: $filename ]"); |
|
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | /** |
@@ -122,33 +122,33 @@ discard block |
||
| 122 | 122 | * |
| 123 | 123 | * @param int $request_id The request ID. |
| 124 | 124 | */ |
| 125 | -function wl_execute_saved_sparql_update_query( $request_id ) { |
|
| 125 | +function wl_execute_saved_sparql_update_query($request_id) { |
|
| 126 | 126 | |
| 127 | - $filename = WL_TEMP_DIR . $request_id . '.sparql'; |
|
| 127 | + $filename = WL_TEMP_DIR.$request_id.'.sparql'; |
|
| 128 | 128 | |
| 129 | 129 | // If the file doesn't exist, exit. |
| 130 | - if ( ! file_exists( $filename ) ) { |
|
| 131 | - wl_write_log( "wl_execute_saved_sparql_update_query : file doesn't exist [ filename :: $filename ]" ); |
|
| 130 | + if ( ! file_exists($filename)) { |
|
| 131 | + wl_write_log("wl_execute_saved_sparql_update_query : file doesn't exist [ filename :: $filename ]"); |
|
| 132 | 132 | |
| 133 | 133 | return; |
| 134 | 134 | } |
| 135 | 135 | |
| 136 | - wl_write_log( "wl_execute_saved_sparql_update_query [ filename :: $filename ]" ); |
|
| 136 | + wl_write_log("wl_execute_saved_sparql_update_query [ filename :: $filename ]"); |
|
| 137 | 137 | |
| 138 | 138 | // Get the query saved in the file. |
| 139 | - $query = file_get_contents( $filename ); |
|
| 139 | + $query = file_get_contents($filename); |
|
| 140 | 140 | |
| 141 | 141 | // Execute the SPARQL query. |
| 142 | - rl_execute_sparql_update_query( $query, false ); |
|
| 142 | + rl_execute_sparql_update_query($query, false); |
|
| 143 | 143 | |
| 144 | 144 | // Reindex the triple store. |
| 145 | 145 | wordlift_reindex_triple_store(); |
| 146 | 146 | |
| 147 | 147 | // Delete the temporary file. |
| 148 | - unlink( $filename ); |
|
| 148 | + unlink($filename); |
|
| 149 | 149 | } |
| 150 | 150 | |
| 151 | -add_action( 'wl_execute_saved_sparql_update_query', 'wl_execute_saved_sparql_update_query', 10, 1 ); |
|
| 151 | +add_action('wl_execute_saved_sparql_update_query', 'wl_execute_saved_sparql_update_query', 10, 1); |
|
| 152 | 152 | |
| 153 | 153 | /** |
| 154 | 154 | * Add buttons hook for the TinyMCE editor. This method is called by the WP init hook. |
@@ -156,8 +156,8 @@ discard block |
||
| 156 | 156 | function wordlift_buttonhooks() { |
| 157 | 157 | |
| 158 | 158 | // Only add hooks when the current user has permissions AND is in Rich Text editor mode |
| 159 | - if ( ( current_user_can( 'edit_posts' ) || current_user_can( 'edit_pages' ) ) && get_user_option( 'rich_editing' ) ) { |
|
| 160 | - add_filter( 'mce_external_plugins', 'wordlift_register_tinymce_javascript' ); |
|
| 159 | + if ((current_user_can('edit_posts') || current_user_can('edit_pages')) && get_user_option('rich_editing')) { |
|
| 160 | + add_filter('mce_external_plugins', 'wordlift_register_tinymce_javascript'); |
|
| 161 | 161 | } |
| 162 | 162 | } |
| 163 | 163 | |
@@ -168,10 +168,10 @@ discard block |
||
| 168 | 168 | * |
| 169 | 169 | * @return array The modified plugins array. |
| 170 | 170 | */ |
| 171 | -function wordlift_register_tinymce_javascript( $plugin_array ) { |
|
| 171 | +function wordlift_register_tinymce_javascript($plugin_array) { |
|
| 172 | 172 | |
| 173 | 173 | // add the wordlift plugin. |
| 174 | - $plugin_array['wordlift'] = plugin_dir_url( __FILE__ ) . 'js/wordlift-reloaded.js'; |
|
| 174 | + $plugin_array['wordlift'] = plugin_dir_url(__FILE__).'js/wordlift-reloaded.js'; |
|
| 175 | 175 | |
| 176 | 176 | return $plugin_array; |
| 177 | 177 | } |
@@ -183,7 +183,7 @@ discard block |
||
| 183 | 183 | function wordlift_allowed_post_tags() { |
| 184 | 184 | global $allowedposttags; |
| 185 | 185 | |
| 186 | - $tags = array( 'span' ); |
|
| 186 | + $tags = array('span'); |
|
| 187 | 187 | $new_attributes = array( |
| 188 | 188 | 'itemscope' => array(), |
| 189 | 189 | 'itemtype' => array(), |
@@ -191,17 +191,17 @@ discard block |
||
| 191 | 191 | 'itemid' => array() |
| 192 | 192 | ); |
| 193 | 193 | |
| 194 | - foreach ( $tags as $tag ) { |
|
| 195 | - if ( isset( $allowedposttags[ $tag ] ) && is_array( $allowedposttags[ $tag ] ) ) { |
|
| 196 | - $allowedposttags[ $tag ] = array_merge( $allowedposttags[ $tag ], $new_attributes ); |
|
| 194 | + foreach ($tags as $tag) { |
|
| 195 | + if (isset($allowedposttags[$tag]) && is_array($allowedposttags[$tag])) { |
|
| 196 | + $allowedposttags[$tag] = array_merge($allowedposttags[$tag], $new_attributes); |
|
| 197 | 197 | } |
| 198 | 198 | } |
| 199 | 199 | } |
| 200 | 200 | |
| 201 | 201 | // init process for button control |
| 202 | -add_action( 'init', 'wordlift_buttonhooks' ); |
|
| 202 | +add_action('init', 'wordlift_buttonhooks'); |
|
| 203 | 203 | // add allowed post tags. |
| 204 | -add_action( 'init', 'wordlift_allowed_post_tags' ); |
|
| 204 | +add_action('init', 'wordlift_allowed_post_tags'); |
|
| 205 | 205 | |
| 206 | 206 | |
| 207 | 207 | /** |
@@ -210,23 +210,23 @@ discard block |
||
| 210 | 210 | function wordlift_admin_enqueue_scripts() { |
| 211 | 211 | |
| 212 | 212 | // Added for compatibility with WordPress 3.9 (see http://make.wordpress.org/core/2014/04/16/jquery-ui-and-wpdialogs-in-wordpress-3-9/) |
| 213 | - wp_enqueue_script( 'wpdialogs' ); |
|
| 214 | - wp_enqueue_style( 'wp-jquery-ui-dialog' ); |
|
| 213 | + wp_enqueue_script('wpdialogs'); |
|
| 214 | + wp_enqueue_style('wp-jquery-ui-dialog'); |
|
| 215 | 215 | |
| 216 | - wp_enqueue_style( 'wordlift-reloaded', plugin_dir_url( __FILE__ ) . 'css/wordlift-reloaded.min.css' ); |
|
| 216 | + wp_enqueue_style('wordlift-reloaded', plugin_dir_url(__FILE__).'css/wordlift-reloaded.min.css'); |
|
| 217 | 217 | |
| 218 | - wp_enqueue_script( 'jquery-ui-autocomplete' ); |
|
| 219 | - wp_enqueue_script( 'angularjs', plugin_dir_url( __FILE__ ) . 'bower_components/angular/angular.min.js' ); |
|
| 218 | + wp_enqueue_script('jquery-ui-autocomplete'); |
|
| 219 | + wp_enqueue_script('angularjs', plugin_dir_url(__FILE__).'bower_components/angular/angular.min.js'); |
|
| 220 | 220 | |
| 221 | 221 | } |
| 222 | 222 | |
| 223 | -add_action( 'admin_enqueue_scripts', 'wordlift_admin_enqueue_scripts' ); |
|
| 223 | +add_action('admin_enqueue_scripts', 'wordlift_admin_enqueue_scripts'); |
|
| 224 | 224 | |
| 225 | 225 | function wl_enqueue_scripts() { |
| 226 | - wp_enqueue_style( 'wordlift-ui', plugin_dir_url( __FILE__ ) . 'css/wordlift-ui.min.css' ); |
|
| 226 | + wp_enqueue_style('wordlift-ui', plugin_dir_url(__FILE__).'css/wordlift-ui.min.css'); |
|
| 227 | 227 | } |
| 228 | 228 | |
| 229 | -add_action( 'wp_enqueue_scripts', 'wl_enqueue_scripts' ); |
|
| 229 | +add_action('wp_enqueue_scripts', 'wl_enqueue_scripts'); |
|
| 230 | 230 | |
| 231 | 231 | /** |
| 232 | 232 | * Hooked to *wp_kses_allowed_html* filter, adds microdata attributes. |
@@ -236,23 +236,23 @@ discard block |
||
| 236 | 236 | * |
| 237 | 237 | * @return array An array which contains allowed microdata attributes. |
| 238 | 238 | */ |
| 239 | -function wordlift_allowed_html( $allowedtags, $context ) { |
|
| 239 | +function wordlift_allowed_html($allowedtags, $context) { |
|
| 240 | 240 | |
| 241 | - if ( 'post' !== $context ) { |
|
| 241 | + if ('post' !== $context) { |
|
| 242 | 242 | return $allowedtags; |
| 243 | 243 | } |
| 244 | 244 | |
| 245 | - return array_merge_recursive( $allowedtags, array( |
|
| 245 | + return array_merge_recursive($allowedtags, array( |
|
| 246 | 246 | 'span' => array( |
| 247 | 247 | 'itemscope' => true, |
| 248 | 248 | 'itemtype' => true, |
| 249 | 249 | 'itemid' => true, |
| 250 | 250 | 'itemprop' => true |
| 251 | 251 | ) |
| 252 | - ) ); |
|
| 252 | + )); |
|
| 253 | 253 | } |
| 254 | 254 | |
| 255 | -add_filter( 'wp_kses_allowed_html', 'wordlift_allowed_html', 10, 2 ); |
|
| 255 | +add_filter('wp_kses_allowed_html', 'wordlift_allowed_html', 10, 2); |
|
| 256 | 256 | |
| 257 | 257 | /** |
| 258 | 258 | * Get the coordinates for the specified post ID. |
@@ -261,16 +261,16 @@ discard block |
||
| 261 | 261 | * |
| 262 | 262 | * @return array|null An array of coordinates or null. |
| 263 | 263 | */ |
| 264 | -function wl_get_coordinates( $post_id ) { |
|
| 264 | +function wl_get_coordinates($post_id) { |
|
| 265 | 265 | |
| 266 | - $latitude = wl_schema_get_value( $post_id, 'latitude' ); |
|
| 267 | - $longitude = wl_schema_get_value( $post_id, 'longitude' ); |
|
| 266 | + $latitude = wl_schema_get_value($post_id, 'latitude'); |
|
| 267 | + $longitude = wl_schema_get_value($post_id, 'longitude'); |
|
| 268 | 268 | |
| 269 | 269 | // DO NOT set latitude/longitude to 0/0 as default values. It's a specific place on the globe: |
| 270 | 270 | // "The zero/zero point of this system is located in the Gulf of Guinea about 625 km (390 mi) south of Tema, Ghana." |
| 271 | 271 | return array( |
| 272 | - 'latitude' => isset( $latitude[0] ) && is_numeric( $latitude[0] ) ? $latitude[0] : '', |
|
| 273 | - 'longitude' => isset( $longitude[0] ) && is_numeric( $longitude[0] ) ? $longitude[0] : '' |
|
| 272 | + 'latitude' => isset($latitude[0]) && is_numeric($latitude[0]) ? $latitude[0] : '', |
|
| 273 | + 'longitude' => isset($longitude[0]) && is_numeric($longitude[0]) ? $longitude[0] : '' |
|
| 274 | 274 | ); |
| 275 | 275 | } |
| 276 | 276 | |
@@ -281,12 +281,12 @@ discard block |
||
| 281 | 281 | * |
| 282 | 282 | * @return string A datetime. |
| 283 | 283 | */ |
| 284 | -function wl_get_post_modified_time( $post ) { |
|
| 284 | +function wl_get_post_modified_time($post) { |
|
| 285 | 285 | |
| 286 | - $date_modified = get_post_modified_time( 'c', true, $post ); |
|
| 286 | + $date_modified = get_post_modified_time('c', true, $post); |
|
| 287 | 287 | |
| 288 | - if ( '-' === substr( $date_modified, 0, 1 ) ) { |
|
| 289 | - return get_the_time( 'c', $post ); |
|
| 288 | + if ('-' === substr($date_modified, 0, 1)) { |
|
| 289 | + return get_the_time('c', $post); |
|
| 290 | 290 | } |
| 291 | 291 | |
| 292 | 292 | return $date_modified; |
@@ -299,18 +299,18 @@ discard block |
||
| 299 | 299 | * |
| 300 | 300 | * @return array An array of image URLs. |
| 301 | 301 | */ |
| 302 | -function wl_get_image_urls( $post_id ) { |
|
| 302 | +function wl_get_image_urls($post_id) { |
|
| 303 | 303 | |
| 304 | 304 | // wl_write_log( "wl_get_image_urls [ post id :: $post_id ]" ); |
| 305 | 305 | |
| 306 | - $images = get_children( array( |
|
| 306 | + $images = get_children(array( |
|
| 307 | 307 | 'post_parent' => $post_id, |
| 308 | 308 | 'post_type' => 'attachment', |
| 309 | 309 | 'post_mime_type' => 'image' |
| 310 | - ) ); |
|
| 310 | + )); |
|
| 311 | 311 | |
| 312 | 312 | // Return an empty array if no image is found. |
| 313 | - if ( empty( $images ) ) { |
|
| 313 | + if (empty($images)) { |
|
| 314 | 314 | return array(); |
| 315 | 315 | } |
| 316 | 316 | |
@@ -318,11 +318,11 @@ discard block |
||
| 318 | 318 | $image_urls = array(); |
| 319 | 319 | |
| 320 | 320 | // Collect the URLs. |
| 321 | - foreach ( $images as $attachment_id => $attachment ) { |
|
| 322 | - $image_url = wp_get_attachment_url( $attachment_id ); |
|
| 321 | + foreach ($images as $attachment_id => $attachment) { |
|
| 322 | + $image_url = wp_get_attachment_url($attachment_id); |
|
| 323 | 323 | // Ensure the URL isn't collected already. |
| 324 | - if ( ! in_array( $image_url, $image_urls ) ) { |
|
| 325 | - array_push( $image_urls, $image_url ); |
|
| 324 | + if ( ! in_array($image_url, $image_urls)) { |
|
| 325 | + array_push($image_urls, $image_url); |
|
| 326 | 326 | } |
| 327 | 327 | } |
| 328 | 328 | |
@@ -339,17 +339,17 @@ discard block |
||
| 339 | 339 | * |
| 340 | 340 | * @return string The SPARQL fragment. |
| 341 | 341 | */ |
| 342 | -function wl_get_sparql_images( $uri, $post_id ) { |
|
| 342 | +function wl_get_sparql_images($uri, $post_id) { |
|
| 343 | 343 | |
| 344 | 344 | $sparql = ''; |
| 345 | 345 | |
| 346 | 346 | // Get the escaped URI. |
| 347 | - $uri_e = esc_html( $uri ); |
|
| 347 | + $uri_e = esc_html($uri); |
|
| 348 | 348 | |
| 349 | 349 | // Add SPARQL stmts to write the schema:image. |
| 350 | - $image_urls = wl_get_image_urls( $post_id ); |
|
| 351 | - foreach ( $image_urls as $image_url ) { |
|
| 352 | - $image_url_esc = wl_sparql_escape_uri( $image_url ); |
|
| 350 | + $image_urls = wl_get_image_urls($post_id); |
|
| 351 | + foreach ($image_urls as $image_url) { |
|
| 352 | + $image_url_esc = wl_sparql_escape_uri($image_url); |
|
| 353 | 353 | $sparql .= " <$uri_e> schema:image <$image_url_esc> . \n"; |
| 354 | 354 | } |
| 355 | 355 | |
@@ -364,21 +364,21 @@ discard block |
||
| 364 | 364 | * |
| 365 | 365 | * @return WP_Post|null A post instance or null if not found. |
| 366 | 366 | */ |
| 367 | -function wl_get_attachment_for_source_url( $parent_post_id, $source_url ) { |
|
| 367 | +function wl_get_attachment_for_source_url($parent_post_id, $source_url) { |
|
| 368 | 368 | |
| 369 | 369 | // wl_write_log( "wl_get_attachment_for_source_url [ parent post id :: $parent_post_id ][ source url :: $source_url ]" ); |
| 370 | 370 | |
| 371 | - $posts = get_posts( array( |
|
| 371 | + $posts = get_posts(array( |
|
| 372 | 372 | 'post_type' => 'attachment', |
| 373 | 373 | 'posts_per_page' => 1, |
| 374 | 374 | 'post_status' => 'any', |
| 375 | 375 | 'post_parent' => $parent_post_id, |
| 376 | 376 | 'meta_key' => 'wl_source_url', |
| 377 | 377 | 'meta_value' => $source_url |
| 378 | - ) ); |
|
| 378 | + )); |
|
| 379 | 379 | |
| 380 | 380 | // Return the found post. |
| 381 | - if ( 1 === count( $posts ) ) { |
|
| 381 | + if (1 === count($posts)) { |
|
| 382 | 382 | return $posts[0]; |
| 383 | 383 | } |
| 384 | 384 | |
@@ -392,10 +392,10 @@ discard block |
||
| 392 | 392 | * @param int $post_id The post ID. |
| 393 | 393 | * @param string $source_url The source URL. |
| 394 | 394 | */ |
| 395 | -function wl_set_source_url( $post_id, $source_url ) { |
|
| 395 | +function wl_set_source_url($post_id, $source_url) { |
|
| 396 | 396 | |
| 397 | - delete_post_meta( $post_id, 'wl_source_url' ); |
|
| 398 | - add_post_meta( $post_id, 'wl_source_url', $source_url ); |
|
| 397 | + delete_post_meta($post_id, 'wl_source_url'); |
|
| 398 | + add_post_meta($post_id, 'wl_source_url', $source_url); |
|
| 399 | 399 | } |
| 400 | 400 | |
| 401 | 401 | |
@@ -411,14 +411,14 @@ discard block |
||
| 411 | 411 | * |
| 412 | 412 | * @param bool $hard True if the rewrite involves configuration updates in Apache/IIS. |
| 413 | 413 | */ |
| 414 | -function wl_flush_rewrite_rules_hard( $hard ) { |
|
| 414 | +function wl_flush_rewrite_rules_hard($hard) { |
|
| 415 | 415 | |
| 416 | 416 | // Get all published posts. |
| 417 | - $posts = get_posts( array( |
|
| 418 | - 'posts_per_page' => - 1, |
|
| 417 | + $posts = get_posts(array( |
|
| 418 | + 'posts_per_page' => -1, |
|
| 419 | 419 | 'post_type' => 'any', |
| 420 | 420 | 'post_status' => 'publish' |
| 421 | - ) ); |
|
| 421 | + )); |
|
| 422 | 422 | |
| 423 | 423 | // Holds the delete part of the query. |
| 424 | 424 | $delete_query = rl_sparql_prefixes(); |
@@ -426,18 +426,18 @@ discard block |
||
| 426 | 426 | $insert_query = 'INSERT DATA { '; |
| 427 | 427 | |
| 428 | 428 | // Cycle in each post to build the query. |
| 429 | - foreach ( $posts as $post ) { |
|
| 429 | + foreach ($posts as $post) { |
|
| 430 | 430 | |
| 431 | 431 | // Ignore revisions. |
| 432 | - if ( wp_is_post_revision( $post->ID ) ) { |
|
| 432 | + if (wp_is_post_revision($post->ID)) { |
|
| 433 | 433 | continue; |
| 434 | 434 | } |
| 435 | 435 | |
| 436 | 436 | // Get the entity URI. |
| 437 | - $uri = wl_sparql_escape_uri( wl_get_entity_uri( $post->ID ) ); |
|
| 437 | + $uri = wl_sparql_escape_uri(wl_get_entity_uri($post->ID)); |
|
| 438 | 438 | |
| 439 | 439 | // Get the post URL. |
| 440 | - $url = wl_sparql_escape_uri( get_permalink( $post->ID ) ); |
|
| 440 | + $url = wl_sparql_escape_uri(get_permalink($post->ID)); |
|
| 441 | 441 | |
| 442 | 442 | // Prepare the DELETE and INSERT commands. |
| 443 | 443 | $delete_query .= "DELETE { <$uri> schema:url ?u . } WHERE { <$uri> schema:url ?u . };\n"; |
@@ -449,10 +449,10 @@ discard block |
||
| 449 | 449 | $insert_query .= ' };'; |
| 450 | 450 | |
| 451 | 451 | // Execute the query. |
| 452 | - rl_execute_sparql_update_query( $delete_query . $insert_query ); |
|
| 452 | + rl_execute_sparql_update_query($delete_query.$insert_query); |
|
| 453 | 453 | } |
| 454 | 454 | |
| 455 | -add_filter( 'flush_rewrite_rules_hard', 'wl_flush_rewrite_rules_hard', 10, 1 ); |
|
| 455 | +add_filter('flush_rewrite_rules_hard', 'wl_flush_rewrite_rules_hard', 10, 1); |
|
| 456 | 456 | |
| 457 | 457 | /** |
| 458 | 458 | * Sanitizes an URI path by replacing the non allowed characters with an underscore. |
@@ -464,7 +464,7 @@ discard block |
||
| 464 | 464 | * |
| 465 | 465 | * @return The sanitized path. |
| 466 | 466 | */ |
| 467 | -function wl_sanitize_uri_path( $path, $char = '_' ) { |
|
| 467 | +function wl_sanitize_uri_path($path, $char = '_') { |
|
| 468 | 468 | |
| 469 | 469 | // wl_write_log( "wl_sanitize_uri_path [ path :: $path ][ char :: $char ]" ); |
| 470 | 470 | |
@@ -474,7 +474,7 @@ discard block |
||
| 474 | 474 | // Plus the ' ' (space). |
| 475 | 475 | // TODO: We shall use the same regex used by MediaWiki (http://stackoverflow.com/questions/23114983/mediawiki-wikipedia-url-sanitization-regex) |
| 476 | 476 | |
| 477 | - return sanitize_title( preg_replace( '/[;\/?:@&=+$,\s]/', $char, stripslashes( $path ) ) ); |
|
| 477 | + return sanitize_title(preg_replace('/[;\/?:@&=+$,\s]/', $char, stripslashes($path))); |
|
| 478 | 478 | } |
| 479 | 479 | |
| 480 | 480 | /** |
@@ -483,28 +483,28 @@ discard block |
||
| 483 | 483 | function wl_shutdown() { |
| 484 | 484 | |
| 485 | 485 | // Get the filename to the temporary SPARQL file. |
| 486 | - $filename = WL_TEMP_DIR . WL_REQUEST_ID . '.sparql'; |
|
| 486 | + $filename = WL_TEMP_DIR.WL_REQUEST_ID.'.sparql'; |
|
| 487 | 487 | |
| 488 | 488 | // If WordLift is buffering SPARQL queries, we're admins and a buffer exists, then schedule it. |
| 489 | - if ( WL_ENABLE_SPARQL_UPDATE_QUERIES_BUFFERING && is_admin() && file_exists( $filename ) ) { |
|
| 489 | + if (WL_ENABLE_SPARQL_UPDATE_QUERIES_BUFFERING && is_admin() && file_exists($filename)) { |
|
| 490 | 490 | |
| 491 | 491 | // The request ID. |
| 492 | - $args = array( WL_REQUEST_ID ); |
|
| 492 | + $args = array(WL_REQUEST_ID); |
|
| 493 | 493 | |
| 494 | 494 | // Schedule the execution of the SPARQL query with the request ID. |
| 495 | - wp_schedule_single_event( time(), 'wl_execute_saved_sparql_update_query', $args ); |
|
| 495 | + wp_schedule_single_event(time(), 'wl_execute_saved_sparql_update_query', $args); |
|
| 496 | 496 | |
| 497 | 497 | // Check that the request is scheduled. |
| 498 | - $timestamp = wp_next_scheduled( 'wl_execute_saved_sparql_update_query', $args ); |
|
| 498 | + $timestamp = wp_next_scheduled('wl_execute_saved_sparql_update_query', $args); |
|
| 499 | 499 | |
| 500 | 500 | // Spawn the cron. |
| 501 | 501 | spawn_cron(); |
| 502 | 502 | |
| 503 | - wl_write_log( "wl_shutdown [ request id :: " . WL_REQUEST_ID . " ][ timestamp :: $timestamp ]" ); |
|
| 503 | + wl_write_log("wl_shutdown [ request id :: ".WL_REQUEST_ID." ][ timestamp :: $timestamp ]"); |
|
| 504 | 504 | } |
| 505 | 505 | } |
| 506 | 506 | |
| 507 | -add_action( 'shutdown', 'wl_shutdown' ); |
|
| 507 | +add_action('shutdown', 'wl_shutdown'); |
|
| 508 | 508 | |
| 509 | 509 | /** |
| 510 | 510 | * Replaces the *itemid* attributes URIs with the WordLift URIs. |
@@ -513,118 +513,118 @@ discard block |
||
| 513 | 513 | * |
| 514 | 514 | * @return string The updated post content. |
| 515 | 515 | */ |
| 516 | -function wl_replace_item_id_with_uri( $content ) { |
|
| 516 | +function wl_replace_item_id_with_uri($content) { |
|
| 517 | 517 | |
| 518 | 518 | // wl_write_log( "wl_replace_item_id_with_uri" ); |
| 519 | 519 | |
| 520 | 520 | // Strip slashes, see https://core.trac.wordpress.org/ticket/21767 |
| 521 | - $content = stripslashes( $content ); |
|
| 521 | + $content = stripslashes($content); |
|
| 522 | 522 | |
| 523 | 523 | // If any match are found. |
| 524 | 524 | $matches = array(); |
| 525 | - if ( 0 < preg_match_all( '/ itemid="([^"]+)"/i', $content, $matches, PREG_SET_ORDER ) ) { |
|
| 525 | + if (0 < preg_match_all('/ itemid="([^"]+)"/i', $content, $matches, PREG_SET_ORDER)) { |
|
| 526 | 526 | |
| 527 | - foreach ( $matches as $match ) { |
|
| 527 | + foreach ($matches as $match) { |
|
| 528 | 528 | |
| 529 | 529 | // Get the item ID. |
| 530 | 530 | $item_id = $match[1]; |
| 531 | 531 | |
| 532 | 532 | // Get the post bound to that item ID (looking both in the 'official' URI and in the 'same-as' . |
| 533 | - $post = wl_get_entity_post_by_uri( $item_id ); |
|
| 533 | + $post = wl_get_entity_post_by_uri($item_id); |
|
| 534 | 534 | |
| 535 | 535 | // If no entity is found, continue to the next one. |
| 536 | - if ( null === $post ) { |
|
| 536 | + if (null === $post) { |
|
| 537 | 537 | continue; |
| 538 | 538 | } |
| 539 | 539 | |
| 540 | 540 | // Get the URI for that post. |
| 541 | - $uri = wl_get_entity_uri( $post->ID ); |
|
| 541 | + $uri = wl_get_entity_uri($post->ID); |
|
| 542 | 542 | |
| 543 | 543 | // wl_write_log( "wl_replace_item_id_with_uri [ item id :: $item_id ][ uri :: $uri ]" ); |
| 544 | 544 | |
| 545 | 545 | // If the item ID and the URI differ, replace the item ID with the URI saved in WordPress. |
| 546 | - if ( $item_id !== $uri ) { |
|
| 547 | - $uri_e = esc_html( $uri ); |
|
| 548 | - $content = str_replace( " itemid=\"$item_id\"", " itemid=\"$uri_e\"", $content ); |
|
| 546 | + if ($item_id !== $uri) { |
|
| 547 | + $uri_e = esc_html($uri); |
|
| 548 | + $content = str_replace(" itemid=\"$item_id\"", " itemid=\"$uri_e\"", $content); |
|
| 549 | 549 | } |
| 550 | 550 | } |
| 551 | 551 | } |
| 552 | 552 | |
| 553 | 553 | // Reapply slashes. |
| 554 | - $content = addslashes( $content ); |
|
| 554 | + $content = addslashes($content); |
|
| 555 | 555 | |
| 556 | 556 | return $content; |
| 557 | 557 | } |
| 558 | 558 | |
| 559 | -add_filter( 'content_save_pre', 'wl_replace_item_id_with_uri', 1, 1 ); |
|
| 559 | +add_filter('content_save_pre', 'wl_replace_item_id_with_uri', 1, 1); |
|
| 560 | 560 | |
| 561 | -require_once( 'wordlift_entity_functions.php' ); |
|
| 561 | +require_once('wordlift_entity_functions.php'); |
|
| 562 | 562 | |
| 563 | 563 | // add editor related methods. |
| 564 | -require_once( 'wordlift_editor.php' ); |
|
| 564 | +require_once('wordlift_editor.php'); |
|
| 565 | 565 | |
| 566 | 566 | // add the WordLift entity custom type. |
| 567 | -require_once( 'wordlift_entity_type.php' ); |
|
| 568 | -require_once( 'wordlift_entity_type_taxonomy.php' ); |
|
| 567 | +require_once('wordlift_entity_type.php'); |
|
| 568 | +require_once('wordlift_entity_type_taxonomy.php'); |
|
| 569 | 569 | |
| 570 | 570 | // filters the post content when saving posts. |
| 571 | -require_once( 'wordlift_content_filter.php' ); |
|
| 571 | +require_once('wordlift_content_filter.php'); |
|
| 572 | 572 | // add callbacks on post save to notify data changes from wp to redlink triple store |
| 573 | -require_once( 'wordlift_to_redlink_data_push_callbacks.php' ); |
|
| 573 | +require_once('wordlift_to_redlink_data_push_callbacks.php'); |
|
| 574 | 574 | |
| 575 | 575 | // Load modules |
| 576 | -require_once( 'modules/analyzer/wordlift_analyzer.php' ); |
|
| 577 | -require_once( 'modules/linked_data/wordlift_linked_data.php' ); |
|
| 578 | -require_once( 'modules/prefixes/wordlift_prefixes.php' ); |
|
| 579 | -require_once( 'modules/caching/wordlift_caching.php' ); |
|
| 580 | -require_once( 'modules/redirector/wordlift_redirector.php' ); |
|
| 581 | -require_once( 'modules/freebase_image_proxy/wordlift_freebase_image_proxy.php' ); |
|
| 576 | +require_once('modules/analyzer/wordlift_analyzer.php'); |
|
| 577 | +require_once('modules/linked_data/wordlift_linked_data.php'); |
|
| 578 | +require_once('modules/prefixes/wordlift_prefixes.php'); |
|
| 579 | +require_once('modules/caching/wordlift_caching.php'); |
|
| 580 | +require_once('modules/redirector/wordlift_redirector.php'); |
|
| 581 | +require_once('modules/freebase_image_proxy/wordlift_freebase_image_proxy.php'); |
|
| 582 | 582 | |
| 583 | 583 | // Shortcodes |
| 584 | 584 | |
| 585 | -require_once( 'modules/geo_widget/wordlift_geo_widget.php' ); |
|
| 586 | -require_once( 'shortcodes/wordlift_shortcode_chord.php' ); |
|
| 587 | -require_once( 'shortcodes/wordlift_shortcode_geomap.php' ); |
|
| 588 | -require_once( 'shortcodes/wordlift_shortcode_field.php' ); |
|
| 589 | -require_once( 'shortcodes/wordlift_shortcode_faceted_search.php' ); |
|
| 590 | -require_once( 'shortcodes/wordlift_shortcode_navigator.php' ); |
|
| 591 | -require_once( 'shortcodes/wordlift_shortcode_blog_map.php' ); |
|
| 585 | +require_once('modules/geo_widget/wordlift_geo_widget.php'); |
|
| 586 | +require_once('shortcodes/wordlift_shortcode_chord.php'); |
|
| 587 | +require_once('shortcodes/wordlift_shortcode_geomap.php'); |
|
| 588 | +require_once('shortcodes/wordlift_shortcode_field.php'); |
|
| 589 | +require_once('shortcodes/wordlift_shortcode_faceted_search.php'); |
|
| 590 | +require_once('shortcodes/wordlift_shortcode_navigator.php'); |
|
| 591 | +require_once('shortcodes/wordlift_shortcode_blog_map.php'); |
|
| 592 | 592 | |
| 593 | 593 | // disable In-Depth Articles |
| 594 | 594 | //require_once('wordlift_indepth_articles.php'); |
| 595 | 595 | |
| 596 | -require_once( 'widgets/wordlift_widget_geo.php' ); |
|
| 597 | -require_once( 'widgets/wordlift_widget_chord.php' ); |
|
| 598 | -require_once( 'widgets/wordlift_widget_timeline.php' ); |
|
| 596 | +require_once('widgets/wordlift_widget_geo.php'); |
|
| 597 | +require_once('widgets/wordlift_widget_chord.php'); |
|
| 598 | +require_once('widgets/wordlift_widget_timeline.php'); |
|
| 599 | 599 | |
| 600 | -require_once( 'wordlift_sparql.php' ); |
|
| 601 | -require_once( 'wordlift_redlink.php' ); |
|
| 600 | +require_once('wordlift_sparql.php'); |
|
| 601 | +require_once('wordlift_redlink.php'); |
|
| 602 | 602 | |
| 603 | 603 | // Add admin functions. |
| 604 | 604 | // TODO: find a way to make 'admin' UI tests work. |
| 605 | 605 | //if ( is_admin() ) { |
| 606 | 606 | |
| 607 | -require_once( 'admin/wordlift_admin.php' ); |
|
| 608 | -require_once( 'admin/wordlift_admin_edit_post.php' ); |
|
| 609 | -require_once( 'admin/wordlift_admin_save_post.php' ); |
|
| 607 | +require_once('admin/wordlift_admin.php'); |
|
| 608 | +require_once('admin/wordlift_admin_edit_post.php'); |
|
| 609 | +require_once('admin/wordlift_admin_save_post.php'); |
|
| 610 | 610 | |
| 611 | 611 | // add the entities meta box. |
| 612 | -require_once( 'admin/wordlift_admin_meta_box_entities.php' ); |
|
| 612 | +require_once('admin/wordlift_admin_meta_box_entities.php'); |
|
| 613 | 613 | |
| 614 | 614 | // add the entity creation AJAX. |
| 615 | -require_once( 'admin/wordlift_admin_ajax_related_posts.php' ); |
|
| 615 | +require_once('admin/wordlift_admin_ajax_related_posts.php'); |
|
| 616 | 616 | |
| 617 | 617 | // Load the wl_chord TinyMCE button and configuration dialog. |
| 618 | -require_once( 'admin/wordlift_admin_shortcodes.php' ); |
|
| 618 | +require_once('admin/wordlift_admin_shortcodes.php'); |
|
| 619 | 619 | |
| 620 | 620 | // Provide syncing features. |
| 621 | -require_once( 'admin/wordlift_admin_sync.php' ); |
|
| 621 | +require_once('admin/wordlift_admin_sync.php'); |
|
| 622 | 622 | //} |
| 623 | 623 | |
| 624 | 624 | // load languages. |
| 625 | 625 | // TODO: the following call gives for granted that the plugin is in the wordlift directory, |
| 626 | 626 | // we're currently doing this because wordlift is symbolic linked. |
| 627 | -load_plugin_textdomain( 'wordlift', false, '/wordlift/languages' ); |
|
| 627 | +load_plugin_textdomain('wordlift', false, '/wordlift/languages'); |
|
| 628 | 628 | |
| 629 | 629 | |
| 630 | 630 | /** |
@@ -632,7 +632,7 @@ discard block |
||
| 632 | 632 | * This action is documented in includes/class-wordlift-activator.php |
| 633 | 633 | */ |
| 634 | 634 | function activate_wordlift() { |
| 635 | - require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-activator.php'; |
|
| 635 | + require_once plugin_dir_path(__FILE__).'includes/class-wordlift-activator.php'; |
|
| 636 | 636 | Wordlift_Activator::activate(); |
| 637 | 637 | } |
| 638 | 638 | |
@@ -641,18 +641,18 @@ discard block |
||
| 641 | 641 | * This action is documented in includes/class-wordlift-deactivator.php |
| 642 | 642 | */ |
| 643 | 643 | function deactivate_wordlift() { |
| 644 | - require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-deactivator.php'; |
|
| 644 | + require_once plugin_dir_path(__FILE__).'includes/class-wordlift-deactivator.php'; |
|
| 645 | 645 | Wordlift_Deactivator::deactivate(); |
| 646 | 646 | } |
| 647 | 647 | |
| 648 | -register_activation_hook( __FILE__, 'activate_wordlift' ); |
|
| 649 | -register_deactivation_hook( __FILE__, 'deactivate_wordlift' ); |
|
| 648 | +register_activation_hook(__FILE__, 'activate_wordlift'); |
|
| 649 | +register_deactivation_hook(__FILE__, 'deactivate_wordlift'); |
|
| 650 | 650 | |
| 651 | 651 | /** |
| 652 | 652 | * The core plugin class that is used to define internationalization, |
| 653 | 653 | * admin-specific hooks, and public-facing site hooks. |
| 654 | 654 | */ |
| 655 | -require plugin_dir_path( __FILE__ ) . 'includes/class-wordlift.php'; |
|
| 655 | +require plugin_dir_path(__FILE__).'includes/class-wordlift.php'; |
|
| 656 | 656 | |
| 657 | 657 | /** |
| 658 | 658 | * Begins execution of the plugin. |
@@ -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 | |
@@ -2,16 +2,16 @@ |
||
| 2 | 2 | |
| 3 | 3 | class WL_Metabox_Field_sameas extends WL_Metabox_Field { |
| 4 | 4 | |
| 5 | - public function __construct( $args ) { |
|
| 6 | - parent::__construct( $args['sameas'] ); |
|
| 5 | + public function __construct($args) { |
|
| 6 | + parent::__construct($args['sameas']); |
|
| 7 | 7 | } |
| 8 | 8 | |
| 9 | 9 | /** |
| 10 | 10 | * Only accept URIs |
| 11 | 11 | */ |
| 12 | - public function sanitize_data_filter( $value ) { |
|
| 12 | + public function sanitize_data_filter($value) { |
|
| 13 | 13 | |
| 14 | - if( !is_null( $value ) && $value !== '' && filter_var($value, FILTER_VALIDATE_URL) ){ |
|
| 14 | + if ( ! is_null($value) && $value !== '' && filter_var($value, FILTER_VALIDATE_URL)) { |
|
| 15 | 15 | return $value; |
| 16 | 16 | } |
| 17 | 17 | return null; |
@@ -4,7 +4,7 @@ discard block |
||
| 4 | 4 | * Entity Types taxonomy. |
| 5 | 5 | */ |
| 6 | 6 | if ( ! class_exists( 'Walker_Category_Checklist' ) ) { |
| 7 | - require_once( ABSPATH . 'wp-admin/includes/template.php' ); |
|
| 7 | + require_once( ABSPATH . 'wp-admin/includes/template.php' ); |
|
| 8 | 8 | } |
| 9 | 9 | |
| 10 | 10 | /** |
@@ -14,77 +14,77 @@ discard block |
||
| 14 | 14 | */ |
| 15 | 15 | class Wordlift_Entity_Types_Taxonomy_Walker extends Walker_Category_Checklist { |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * The Log service. |
|
| 19 | - * |
|
| 20 | - * @since 3.1.0 |
|
| 21 | - * @access private |
|
| 22 | - * @var \Wordlift_Log_Service $log_service The Log service. |
|
| 23 | - */ |
|
| 24 | - private $log_service; |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * Create an instance of Wordlift_Entity_Types_Taxonomy_Walker. |
|
| 28 | - * |
|
| 29 | - * @since 3.1.0 |
|
| 30 | - */ |
|
| 31 | - public function __construct() { |
|
| 32 | - |
|
| 33 | - $this->log_service = Wordlift_Log_Service::get_logger( 'Wordlift_Entity_Types_Taxonomy_Walker' ); |
|
| 34 | - |
|
| 35 | - } |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * Entity taxonomy metabox must show exclusive options, no checkboxes. |
|
| 39 | - * |
|
| 40 | - * @since 3.1.0 |
|
| 41 | - * |
|
| 42 | - * @param $args |
|
| 43 | - * |
|
| 44 | - * @return array An array of arguments, with this walker in case the taxonomy is the Entity Type taxonomy. |
|
| 45 | - */ |
|
| 46 | - function terms_checklist_args( $args ) { |
|
| 47 | - |
|
| 48 | - if ( ! isset( $args['taxonomy'] ) || Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME !== $args['taxonomy'] ) { |
|
| 49 | - return $args; |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - // We override the way WP prints the taxonomy metabox HTML |
|
| 53 | - $args['walker'] = $this; |
|
| 54 | - $args['checked_ontop'] = false; |
|
| 55 | - |
|
| 56 | - return $args; |
|
| 57 | - |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * Change checkboxes to radios. |
|
| 63 | - * |
|
| 64 | - * $max_depth = -1 means flatly display every element. |
|
| 65 | - * $max_depth = 0 means display all levels. |
|
| 66 | - * $max_depth > 0 specifies the number of display levels. |
|
| 67 | - * |
|
| 68 | - * @since 3.1.0 |
|
| 69 | - * |
|
| 70 | - * @param array $elements An array of elements. |
|
| 71 | - * @param int $max_depth The maximum hierarchical depth. |
|
| 72 | - * |
|
| 73 | - * @param array $args Additional arguments. |
|
| 74 | - * |
|
| 75 | - * @return string The hierarchical item output. |
|
| 76 | - */ |
|
| 77 | - public function walk( $elements, $max_depth, $args = array() ) { |
|
| 78 | - |
|
| 79 | - $output = parent::walk( $elements, $max_depth, $args ); |
|
| 80 | - |
|
| 81 | - $output = str_replace( |
|
| 82 | - array( 'type="checkbox"', "type='checkbox'" ), |
|
| 83 | - array( 'type="radio"', "type='radio'" ), |
|
| 84 | - $output |
|
| 85 | - ); |
|
| 86 | - |
|
| 87 | - return $output; |
|
| 88 | - } |
|
| 17 | + /** |
|
| 18 | + * The Log service. |
|
| 19 | + * |
|
| 20 | + * @since 3.1.0 |
|
| 21 | + * @access private |
|
| 22 | + * @var \Wordlift_Log_Service $log_service The Log service. |
|
| 23 | + */ |
|
| 24 | + private $log_service; |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * Create an instance of Wordlift_Entity_Types_Taxonomy_Walker. |
|
| 28 | + * |
|
| 29 | + * @since 3.1.0 |
|
| 30 | + */ |
|
| 31 | + public function __construct() { |
|
| 32 | + |
|
| 33 | + $this->log_service = Wordlift_Log_Service::get_logger( 'Wordlift_Entity_Types_Taxonomy_Walker' ); |
|
| 34 | + |
|
| 35 | + } |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * Entity taxonomy metabox must show exclusive options, no checkboxes. |
|
| 39 | + * |
|
| 40 | + * @since 3.1.0 |
|
| 41 | + * |
|
| 42 | + * @param $args |
|
| 43 | + * |
|
| 44 | + * @return array An array of arguments, with this walker in case the taxonomy is the Entity Type taxonomy. |
|
| 45 | + */ |
|
| 46 | + function terms_checklist_args( $args ) { |
|
| 47 | + |
|
| 48 | + if ( ! isset( $args['taxonomy'] ) || Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME !== $args['taxonomy'] ) { |
|
| 49 | + return $args; |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + // We override the way WP prints the taxonomy metabox HTML |
|
| 53 | + $args['walker'] = $this; |
|
| 54 | + $args['checked_ontop'] = false; |
|
| 55 | + |
|
| 56 | + return $args; |
|
| 57 | + |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * Change checkboxes to radios. |
|
| 63 | + * |
|
| 64 | + * $max_depth = -1 means flatly display every element. |
|
| 65 | + * $max_depth = 0 means display all levels. |
|
| 66 | + * $max_depth > 0 specifies the number of display levels. |
|
| 67 | + * |
|
| 68 | + * @since 3.1.0 |
|
| 69 | + * |
|
| 70 | + * @param array $elements An array of elements. |
|
| 71 | + * @param int $max_depth The maximum hierarchical depth. |
|
| 72 | + * |
|
| 73 | + * @param array $args Additional arguments. |
|
| 74 | + * |
|
| 75 | + * @return string The hierarchical item output. |
|
| 76 | + */ |
|
| 77 | + public function walk( $elements, $max_depth, $args = array() ) { |
|
| 78 | + |
|
| 79 | + $output = parent::walk( $elements, $max_depth, $args ); |
|
| 80 | + |
|
| 81 | + $output = str_replace( |
|
| 82 | + array( 'type="checkbox"', "type='checkbox'" ), |
|
| 83 | + array( 'type="radio"', "type='radio'" ), |
|
| 84 | + $output |
|
| 85 | + ); |
|
| 86 | + |
|
| 87 | + return $output; |
|
| 88 | + } |
|
| 89 | 89 | |
| 90 | 90 | } |
@@ -3,8 +3,8 @@ discard block |
||
| 3 | 3 | * This file contains the Entity Types Taxonomy Walker whose main role is to turn checkboxes to radios for the |
| 4 | 4 | * Entity Types taxonomy. |
| 5 | 5 | */ |
| 6 | -if ( ! class_exists( 'Walker_Category_Checklist' ) ) { |
|
| 7 | - require_once( ABSPATH . 'wp-admin/includes/template.php' ); |
|
| 6 | +if ( ! class_exists('Walker_Category_Checklist')) { |
|
| 7 | + require_once(ABSPATH.'wp-admin/includes/template.php'); |
|
| 8 | 8 | } |
| 9 | 9 | |
| 10 | 10 | /** |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | */ |
| 31 | 31 | public function __construct() { |
| 32 | 32 | |
| 33 | - $this->log_service = Wordlift_Log_Service::get_logger( 'Wordlift_Entity_Types_Taxonomy_Walker' ); |
|
| 33 | + $this->log_service = Wordlift_Log_Service::get_logger('Wordlift_Entity_Types_Taxonomy_Walker'); |
|
| 34 | 34 | |
| 35 | 35 | } |
| 36 | 36 | |
@@ -43,9 +43,9 @@ discard block |
||
| 43 | 43 | * |
| 44 | 44 | * @return array An array of arguments, with this walker in case the taxonomy is the Entity Type taxonomy. |
| 45 | 45 | */ |
| 46 | - function terms_checklist_args( $args ) { |
|
| 46 | + function terms_checklist_args($args) { |
|
| 47 | 47 | |
| 48 | - if ( ! isset( $args['taxonomy'] ) || Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME !== $args['taxonomy'] ) { |
|
| 48 | + if ( ! isset($args['taxonomy']) || Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME !== $args['taxonomy']) { |
|
| 49 | 49 | return $args; |
| 50 | 50 | } |
| 51 | 51 | |
@@ -74,13 +74,13 @@ discard block |
||
| 74 | 74 | * |
| 75 | 75 | * @return string The hierarchical item output. |
| 76 | 76 | */ |
| 77 | - public function walk( $elements, $max_depth, $args = array() ) { |
|
| 77 | + public function walk($elements, $max_depth, $args = array()) { |
|
| 78 | 78 | |
| 79 | - $output = parent::walk( $elements, $max_depth, $args ); |
|
| 79 | + $output = parent::walk($elements, $max_depth, $args); |
|
| 80 | 80 | |
| 81 | 81 | $output = str_replace( |
| 82 | - array( 'type="checkbox"', "type='checkbox'" ), |
|
| 83 | - array( 'type="radio"', "type='radio'" ), |
|
| 82 | + array('type="checkbox"', "type='checkbox'"), |
|
| 83 | + array('type="radio"', "type='radio'"), |
|
| 84 | 84 | $output |
| 85 | 85 | ); |
| 86 | 86 | |
@@ -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'); |
|