@@ -14,19 +14,19 @@ discard block |
||
| 14 | 14 | */ |
| 15 | 15 | function wl_linked_data_save_post( $post_id ) { |
| 16 | 16 | |
| 17 | - // If it's not numeric exit from here. |
|
| 18 | - if ( ! is_numeric( $post_id ) || is_numeric( wp_is_post_revision( $post_id ) ) ) { |
|
| 19 | - return; |
|
| 20 | - } |
|
| 17 | + // If it's not numeric exit from here. |
|
| 18 | + if ( ! is_numeric( $post_id ) || is_numeric( wp_is_post_revision( $post_id ) ) ) { |
|
| 19 | + return; |
|
| 20 | + } |
|
| 21 | 21 | |
| 22 | - // unhook this function so it doesn't loop infinitely |
|
| 23 | - remove_action( 'save_post', 'wl_linked_data_save_post' ); |
|
| 22 | + // unhook this function so it doesn't loop infinitely |
|
| 23 | + remove_action( 'save_post', 'wl_linked_data_save_post' ); |
|
| 24 | 24 | |
| 25 | - // raise the *wl_linked_data_save_post* event. |
|
| 26 | - do_action( 'wl_linked_data_save_post', $post_id ); |
|
| 25 | + // raise the *wl_linked_data_save_post* event. |
|
| 26 | + do_action( 'wl_linked_data_save_post', $post_id ); |
|
| 27 | 27 | |
| 28 | - // re-hook this function |
|
| 29 | - add_action( 'save_post', 'wl_linked_data_save_post' ); |
|
| 28 | + // re-hook this function |
|
| 29 | + add_action( 'save_post', 'wl_linked_data_save_post' ); |
|
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | add_action( 'save_post', 'wl_linked_data_save_post' ); |
@@ -40,121 +40,121 @@ discard block |
||
| 40 | 40 | */ |
| 41 | 41 | function wl_linked_data_save_post_and_related_entities( $post_id ) { |
| 42 | 42 | |
| 43 | - // Ignore auto-saves |
|
| 44 | - if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { |
|
| 45 | - return; |
|
| 46 | - } |
|
| 47 | - |
|
| 48 | - // get the current post. |
|
| 49 | - $post = get_post( $post_id ); |
|
| 50 | - |
|
| 51 | - remove_action( 'wl_linked_data_save_post', 'wl_linked_data_save_post_and_related_entities' ); |
|
| 52 | - |
|
| 53 | - // wl_write_log( "[ post id :: $post_id ][ autosave :: false ][ post type :: $post->post_type ]" ); |
|
| 54 | - |
|
| 55 | - // Store mapping between tmp new entities uris and real new entities uri |
|
| 56 | - $entities_uri_mapping = array(); |
|
| 57 | - // Store classification box mapping |
|
| 58 | - $entities_predicates_mapping = null; |
|
| 59 | - |
|
| 60 | - // Save the entities coming with POST data. |
|
| 61 | - if ( isset( $_POST['wl_entities'] ) && isset( $_POST['wl_boxes'] ) ) { |
|
| 62 | - |
|
| 63 | - wl_write_log( "[ post id :: $post_id ][ POST(wl_entities) :: " ); |
|
| 64 | - wl_write_log( json_encode( $_POST['wl_entities'] ) ); |
|
| 65 | - wl_write_log( "]" ); |
|
| 66 | - wl_write_log( "[ post id :: $post_id ][ POST(wl_boxes) :: " ); |
|
| 67 | - wl_write_log( json_encode( $_POST['wl_boxes'], true ) ); |
|
| 68 | - wl_write_log( "]" ); |
|
| 69 | - |
|
| 70 | - $entities_via_post = $_POST['wl_entities']; |
|
| 71 | - $boxes_via_post = $_POST['wl_boxes']; |
|
| 72 | - |
|
| 73 | - foreach ( $entities_via_post as $entity_uri => $entity ) { |
|
| 74 | - // Local entities have a tmp uri with 'local-entity-' |
|
| 75 | - // These uris need to be rewritten here and replaced in the content |
|
| 76 | - if ( preg_match( '/^local-entity-.+/', $entity_uri ) > 0 ) { |
|
| 77 | - // Build the proper uri |
|
| 78 | - $uri = sprintf( '%s/%s/%s', wl_configuration_get_redlink_dataset_uri(), 'entity', wl_sanitize_uri_path( $entity['label'] ) ); |
|
| 79 | - // Populate the mapping |
|
| 80 | - $entities_uri_mapping[ $entity_uri ] = $uri; |
|
| 81 | - // Override the entity obj |
|
| 82 | - $entities_via_post[ $entity_uri ]['uri'] = $uri; |
|
| 83 | - } |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - // Populate the $entities_predicates_mapping |
|
| 87 | - // Local Redlink uris need to be used here |
|
| 88 | - foreach ( $boxes_via_post as $predicate => $entity_uris ) { |
|
| 89 | - foreach ( $entity_uris as $entity_uri ) { |
|
| 90 | - // wl_write_log("Going to map predicates for uri $entity_uri "); |
|
| 91 | - // Retrieve the entity label needed to build the uri |
|
| 92 | - $label = $entities_via_post[ stripslashes( $entity_uri ) ]['label']; |
|
| 93 | - $uri = sprintf( '%s/%s/%s', wl_configuration_get_redlink_dataset_uri(), 'entity', wl_sanitize_uri_path( $label ) ); |
|
| 94 | - // wl_write_log("Going to map predicate $predicate to uri $uri "); |
|
| 95 | - $entities_predicates_mapping[ $uri ][] = $predicate; |
|
| 96 | - } |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - // Save entities and push them to Redlink |
|
| 100 | - // TODO: pass also latitude, longitude, etc. |
|
| 101 | - wl_save_entities( array_values( $entities_via_post ), $post_id ); |
|
| 102 | - |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - // Replace tmp uris in content post if needed |
|
| 106 | - $updated_post_content = $post->post_content; |
|
| 107 | - // Save each entity and store the post id. |
|
| 108 | - foreach ( $entities_uri_mapping as $tmp_uri => $uri ) { |
|
| 109 | - $updated_post_content = str_replace( $tmp_uri, $uri, $updated_post_content ); |
|
| 110 | - } |
|
| 111 | - // Update the post content |
|
| 112 | - wp_update_post( array( |
|
| 113 | - 'ID' => $post->ID, |
|
| 114 | - 'post_content' => $updated_post_content, |
|
| 115 | - ) ); |
|
| 116 | - |
|
| 117 | - // Extract related/referenced entities from text. |
|
| 118 | - $disambiguated_entities = wl_linked_data_content_get_embedded_entities( $updated_post_content ); |
|
| 119 | - |
|
| 120 | - // Reset previously saved instances |
|
| 121 | - wl_core_delete_relation_instances( $post_id ); |
|
| 122 | - |
|
| 123 | - // Save relation instances |
|
| 124 | - foreach ( array_unique( $disambiguated_entities ) as $referenced_entity_id ) { |
|
| 125 | - |
|
| 126 | - // wl_write_log(" Going to manage relation between Post $post_id and $referenced_entity_id"); |
|
| 127 | - |
|
| 128 | - if ( $entities_predicates_mapping ) { |
|
| 129 | - |
|
| 130 | - // wl_write_log(" Going to manage relation instances according to the following mapping"); |
|
| 131 | - |
|
| 132 | - // Retrieve the entity uri |
|
| 133 | - $referenced_entity_uri = wl_get_entity_uri( $referenced_entity_id ); |
|
| 134 | - // Retrieve predicates for the current uri |
|
| 135 | - if ( isset( $entities_predicates_mapping[ $referenced_entity_uri ] ) ) { |
|
| 136 | - foreach ( $entities_predicates_mapping[ $referenced_entity_uri ] as $predicate ) { |
|
| 137 | - // wl_write_log(" Going to add relation with predicate $predicate"); |
|
| 138 | - wl_core_add_relation_instance( $post_id, $predicate, $referenced_entity_id ); |
|
| 139 | - } |
|
| 140 | - } else { |
|
| 141 | - wl_write_log( "Entity uri $referenced_entity_uri missing in the mapping" ); |
|
| 142 | - wl_write_log( $entities_predicates_mapping ); |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - } else { |
|
| 146 | - // Just for unit tests |
|
| 147 | - wl_core_add_relation_instance( $post_id, 'what', $referenced_entity_id ); |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - // TODO Check if is needed |
|
| 151 | - wl_linked_data_push_to_redlink( $referenced_entity_id ); |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - // Push the post to Redlink. |
|
| 155 | - wl_linked_data_push_to_redlink( $post->ID ); |
|
| 156 | - |
|
| 157 | - add_action( 'wl_linked_data_save_post', 'wl_linked_data_save_post_and_related_entities' ); |
|
| 43 | + // Ignore auto-saves |
|
| 44 | + if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { |
|
| 45 | + return; |
|
| 46 | + } |
|
| 47 | + |
|
| 48 | + // get the current post. |
|
| 49 | + $post = get_post( $post_id ); |
|
| 50 | + |
|
| 51 | + remove_action( 'wl_linked_data_save_post', 'wl_linked_data_save_post_and_related_entities' ); |
|
| 52 | + |
|
| 53 | + // wl_write_log( "[ post id :: $post_id ][ autosave :: false ][ post type :: $post->post_type ]" ); |
|
| 54 | + |
|
| 55 | + // Store mapping between tmp new entities uris and real new entities uri |
|
| 56 | + $entities_uri_mapping = array(); |
|
| 57 | + // Store classification box mapping |
|
| 58 | + $entities_predicates_mapping = null; |
|
| 59 | + |
|
| 60 | + // Save the entities coming with POST data. |
|
| 61 | + if ( isset( $_POST['wl_entities'] ) && isset( $_POST['wl_boxes'] ) ) { |
|
| 62 | + |
|
| 63 | + wl_write_log( "[ post id :: $post_id ][ POST(wl_entities) :: " ); |
|
| 64 | + wl_write_log( json_encode( $_POST['wl_entities'] ) ); |
|
| 65 | + wl_write_log( "]" ); |
|
| 66 | + wl_write_log( "[ post id :: $post_id ][ POST(wl_boxes) :: " ); |
|
| 67 | + wl_write_log( json_encode( $_POST['wl_boxes'], true ) ); |
|
| 68 | + wl_write_log( "]" ); |
|
| 69 | + |
|
| 70 | + $entities_via_post = $_POST['wl_entities']; |
|
| 71 | + $boxes_via_post = $_POST['wl_boxes']; |
|
| 72 | + |
|
| 73 | + foreach ( $entities_via_post as $entity_uri => $entity ) { |
|
| 74 | + // Local entities have a tmp uri with 'local-entity-' |
|
| 75 | + // These uris need to be rewritten here and replaced in the content |
|
| 76 | + if ( preg_match( '/^local-entity-.+/', $entity_uri ) > 0 ) { |
|
| 77 | + // Build the proper uri |
|
| 78 | + $uri = sprintf( '%s/%s/%s', wl_configuration_get_redlink_dataset_uri(), 'entity', wl_sanitize_uri_path( $entity['label'] ) ); |
|
| 79 | + // Populate the mapping |
|
| 80 | + $entities_uri_mapping[ $entity_uri ] = $uri; |
|
| 81 | + // Override the entity obj |
|
| 82 | + $entities_via_post[ $entity_uri ]['uri'] = $uri; |
|
| 83 | + } |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + // Populate the $entities_predicates_mapping |
|
| 87 | + // Local Redlink uris need to be used here |
|
| 88 | + foreach ( $boxes_via_post as $predicate => $entity_uris ) { |
|
| 89 | + foreach ( $entity_uris as $entity_uri ) { |
|
| 90 | + // wl_write_log("Going to map predicates for uri $entity_uri "); |
|
| 91 | + // Retrieve the entity label needed to build the uri |
|
| 92 | + $label = $entities_via_post[ stripslashes( $entity_uri ) ]['label']; |
|
| 93 | + $uri = sprintf( '%s/%s/%s', wl_configuration_get_redlink_dataset_uri(), 'entity', wl_sanitize_uri_path( $label ) ); |
|
| 94 | + // wl_write_log("Going to map predicate $predicate to uri $uri "); |
|
| 95 | + $entities_predicates_mapping[ $uri ][] = $predicate; |
|
| 96 | + } |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + // Save entities and push them to Redlink |
|
| 100 | + // TODO: pass also latitude, longitude, etc. |
|
| 101 | + wl_save_entities( array_values( $entities_via_post ), $post_id ); |
|
| 102 | + |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + // Replace tmp uris in content post if needed |
|
| 106 | + $updated_post_content = $post->post_content; |
|
| 107 | + // Save each entity and store the post id. |
|
| 108 | + foreach ( $entities_uri_mapping as $tmp_uri => $uri ) { |
|
| 109 | + $updated_post_content = str_replace( $tmp_uri, $uri, $updated_post_content ); |
|
| 110 | + } |
|
| 111 | + // Update the post content |
|
| 112 | + wp_update_post( array( |
|
| 113 | + 'ID' => $post->ID, |
|
| 114 | + 'post_content' => $updated_post_content, |
|
| 115 | + ) ); |
|
| 116 | + |
|
| 117 | + // Extract related/referenced entities from text. |
|
| 118 | + $disambiguated_entities = wl_linked_data_content_get_embedded_entities( $updated_post_content ); |
|
| 119 | + |
|
| 120 | + // Reset previously saved instances |
|
| 121 | + wl_core_delete_relation_instances( $post_id ); |
|
| 122 | + |
|
| 123 | + // Save relation instances |
|
| 124 | + foreach ( array_unique( $disambiguated_entities ) as $referenced_entity_id ) { |
|
| 125 | + |
|
| 126 | + // wl_write_log(" Going to manage relation between Post $post_id and $referenced_entity_id"); |
|
| 127 | + |
|
| 128 | + if ( $entities_predicates_mapping ) { |
|
| 129 | + |
|
| 130 | + // wl_write_log(" Going to manage relation instances according to the following mapping"); |
|
| 131 | + |
|
| 132 | + // Retrieve the entity uri |
|
| 133 | + $referenced_entity_uri = wl_get_entity_uri( $referenced_entity_id ); |
|
| 134 | + // Retrieve predicates for the current uri |
|
| 135 | + if ( isset( $entities_predicates_mapping[ $referenced_entity_uri ] ) ) { |
|
| 136 | + foreach ( $entities_predicates_mapping[ $referenced_entity_uri ] as $predicate ) { |
|
| 137 | + // wl_write_log(" Going to add relation with predicate $predicate"); |
|
| 138 | + wl_core_add_relation_instance( $post_id, $predicate, $referenced_entity_id ); |
|
| 139 | + } |
|
| 140 | + } else { |
|
| 141 | + wl_write_log( "Entity uri $referenced_entity_uri missing in the mapping" ); |
|
| 142 | + wl_write_log( $entities_predicates_mapping ); |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + } else { |
|
| 146 | + // Just for unit tests |
|
| 147 | + wl_core_add_relation_instance( $post_id, 'what', $referenced_entity_id ); |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + // TODO Check if is needed |
|
| 151 | + wl_linked_data_push_to_redlink( $referenced_entity_id ); |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + // Push the post to Redlink. |
|
| 155 | + wl_linked_data_push_to_redlink( $post->ID ); |
|
| 156 | + |
|
| 157 | + add_action( 'wl_linked_data_save_post', 'wl_linked_data_save_post_and_related_entities' ); |
|
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | add_action( 'wl_linked_data_save_post', 'wl_linked_data_save_post_and_related_entities' ); |
@@ -164,14 +164,14 @@ discard block |
||
| 164 | 164 | */ |
| 165 | 165 | function wordlift_save_post_add_default_schema_type( $entity_id ) { |
| 166 | 166 | |
| 167 | - $entity = get_post( $entity_id ); |
|
| 168 | - $entity_type = wl_schema_get_types( $entity_id ); |
|
| 167 | + $entity = get_post( $entity_id ); |
|
| 168 | + $entity_type = wl_schema_get_types( $entity_id ); |
|
| 169 | 169 | |
| 170 | - // Assign type 'Thing' if we are dealing with an entity without type |
|
| 171 | - if ( $entity->post_type == Wordlift_Entity_Service::TYPE_NAME && is_null( $entity_type ) ) { |
|
| 170 | + // Assign type 'Thing' if we are dealing with an entity without type |
|
| 171 | + if ( $entity->post_type == Wordlift_Entity_Service::TYPE_NAME && is_null( $entity_type ) ) { |
|
| 172 | 172 | |
| 173 | - wl_schema_set_types( $entity_id, 'Thing' ); |
|
| 174 | - } |
|
| 173 | + wl_schema_set_types( $entity_id, 'Thing' ); |
|
| 174 | + } |
|
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | // Priority 1 (default is 10) because we want the default type to be set as soon as possible |
@@ -188,59 +188,59 @@ discard block |
||
| 188 | 188 | */ |
| 189 | 189 | function wl_save_entities( $entities, $related_post_id = null ) { |
| 190 | 190 | |
| 191 | - // wl_write_log( "[ entities count :: " . count( $entities ) . " ][ related post id :: $related_post_id ]" ); |
|
| 192 | - |
|
| 193 | - // Prepare the return array. |
|
| 194 | - $posts = array(); |
|
| 195 | - |
|
| 196 | - // Save each entity and store the post id. |
|
| 197 | - foreach ( $entities as $entity ) { |
|
| 198 | - |
|
| 199 | - $uri = $entity['uri']; |
|
| 200 | - $label = $entity['label']; |
|
| 201 | - |
|
| 202 | - // This is the main type URI. |
|
| 203 | - $main_type_uri = $entity['main_type']; |
|
| 204 | - |
|
| 205 | - // the preferred type. |
|
| 206 | - $type_uris = ( isset( $entity['type'] ) ? |
|
| 207 | - $entity['type'] : |
|
| 208 | - array() ); |
|
| 209 | - |
|
| 210 | - $description = $entity['description']; |
|
| 211 | - $images = ( isset( $entity['image'] ) ? |
|
| 212 | - ( is_array( $entity['image'] ) |
|
| 213 | - ? $entity['image'] |
|
| 214 | - : array( $entity['image'] ) ) |
|
| 215 | - : array() ); |
|
| 216 | - $same_as = ( isset( $entity['sameas'] ) ? |
|
| 217 | - ( is_array( $entity['sameas'] ) |
|
| 218 | - ? $entity['sameas'] |
|
| 219 | - : array( $entity['sameas'] ) ) |
|
| 220 | - : array() ); |
|
| 221 | - |
|
| 222 | - // Bring properties inside an associative array |
|
| 223 | - $entity_properties = array( |
|
| 224 | - 'uri' => $uri, |
|
| 225 | - 'label' => $label, |
|
| 226 | - 'main_type_uri' => $main_type_uri, |
|
| 227 | - 'description' => $description, |
|
| 228 | - 'type_uris' => $type_uris, |
|
| 229 | - 'images' => $images, |
|
| 230 | - 'related_post_id' => $related_post_id, |
|
| 231 | - 'same_as' => $same_as |
|
| 232 | - ); |
|
| 233 | - |
|
| 234 | - // Save the entity. |
|
| 235 | - $entity_post = wl_save_entity( $entity_properties ); |
|
| 236 | - |
|
| 237 | - // Store the post in the return array if successful. |
|
| 238 | - if ( null !== $entity_post ) { |
|
| 239 | - array_push( $posts, $entity_post ); |
|
| 240 | - } |
|
| 241 | - } |
|
| 242 | - |
|
| 243 | - return $posts; |
|
| 191 | + // wl_write_log( "[ entities count :: " . count( $entities ) . " ][ related post id :: $related_post_id ]" ); |
|
| 192 | + |
|
| 193 | + // Prepare the return array. |
|
| 194 | + $posts = array(); |
|
| 195 | + |
|
| 196 | + // Save each entity and store the post id. |
|
| 197 | + foreach ( $entities as $entity ) { |
|
| 198 | + |
|
| 199 | + $uri = $entity['uri']; |
|
| 200 | + $label = $entity['label']; |
|
| 201 | + |
|
| 202 | + // This is the main type URI. |
|
| 203 | + $main_type_uri = $entity['main_type']; |
|
| 204 | + |
|
| 205 | + // the preferred type. |
|
| 206 | + $type_uris = ( isset( $entity['type'] ) ? |
|
| 207 | + $entity['type'] : |
|
| 208 | + array() ); |
|
| 209 | + |
|
| 210 | + $description = $entity['description']; |
|
| 211 | + $images = ( isset( $entity['image'] ) ? |
|
| 212 | + ( is_array( $entity['image'] ) |
|
| 213 | + ? $entity['image'] |
|
| 214 | + : array( $entity['image'] ) ) |
|
| 215 | + : array() ); |
|
| 216 | + $same_as = ( isset( $entity['sameas'] ) ? |
|
| 217 | + ( is_array( $entity['sameas'] ) |
|
| 218 | + ? $entity['sameas'] |
|
| 219 | + : array( $entity['sameas'] ) ) |
|
| 220 | + : array() ); |
|
| 221 | + |
|
| 222 | + // Bring properties inside an associative array |
|
| 223 | + $entity_properties = array( |
|
| 224 | + 'uri' => $uri, |
|
| 225 | + 'label' => $label, |
|
| 226 | + 'main_type_uri' => $main_type_uri, |
|
| 227 | + 'description' => $description, |
|
| 228 | + 'type_uris' => $type_uris, |
|
| 229 | + 'images' => $images, |
|
| 230 | + 'related_post_id' => $related_post_id, |
|
| 231 | + 'same_as' => $same_as |
|
| 232 | + ); |
|
| 233 | + |
|
| 234 | + // Save the entity. |
|
| 235 | + $entity_post = wl_save_entity( $entity_properties ); |
|
| 236 | + |
|
| 237 | + // Store the post in the return array if successful. |
|
| 238 | + if ( null !== $entity_post ) { |
|
| 239 | + array_push( $posts, $entity_post ); |
|
| 240 | + } |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + return $posts; |
|
| 244 | 244 | } |
| 245 | 245 | |
| 246 | 246 | /** |
@@ -261,172 +261,172 @@ discard block |
||
| 261 | 261 | */ |
| 262 | 262 | function wl_save_entity( $entity_properties ) { |
| 263 | 263 | |
| 264 | - $uri = $entity_properties['uri']; |
|
| 265 | - $label = $entity_properties['label']; |
|
| 266 | - $type_uri = $entity_properties['main_type_uri']; |
|
| 267 | - $description = $entity_properties['description']; |
|
| 268 | - $entity_types = $entity_properties['type_uris']; |
|
| 269 | - $images = $entity_properties['images']; |
|
| 270 | - $related_post_id = $entity_properties['related_post_id']; |
|
| 271 | - $same_as = $entity_properties['same_as']; |
|
| 272 | - |
|
| 273 | - // Avoid errors due to null. |
|
| 274 | - if ( is_null( $entity_types ) ) { |
|
| 275 | - $entity_types = array(); |
|
| 276 | - } |
|
| 277 | - |
|
| 278 | - // wl_write_log( "[ uri :: $uri ][ label :: $label ][ type uri :: $type_uri ]" ); |
|
| 279 | - |
|
| 280 | - // Prepare properties of the new entity. |
|
| 281 | - $params = array( |
|
| 282 | - 'post_status' => ( is_numeric( $related_post_id ) ? get_post_status( $related_post_id ) : 'draft' ), |
|
| 283 | - 'post_type' => Wordlift_Entity_Service::TYPE_NAME, |
|
| 284 | - 'post_title' => $label, |
|
| 285 | - 'post_content' => $description, |
|
| 286 | - 'post_excerpt' => '' |
|
| 287 | - ); |
|
| 288 | - |
|
| 289 | - // Check whether an entity already exists with the provided URI. |
|
| 290 | - $post = wl_get_entity_post_by_uri( $uri ); |
|
| 291 | - |
|
| 292 | - if ( null !== $post ) { |
|
| 293 | - // We insert into the params the entity ID, so it will be updated and not inserted. |
|
| 294 | - $params['ID'] = $post->ID; |
|
| 295 | - // Preserve the current entity status |
|
| 296 | - if ( 'public' == $post->post_status ) { |
|
| 297 | - $params['post_status'] = $post->post_status; |
|
| 298 | - } |
|
| 299 | - // Preserve the current entity content. Hotfix for issue #152 |
|
| 300 | - $params['post_content'] = $post->post_content; |
|
| 301 | - } |
|
| 302 | - |
|
| 303 | - // If Yoast is installed and active, we temporary remove the save_postdata hook which causes Yoast to "pass over" |
|
| 304 | - // the local SEO form values to the created entity (https://github.com/insideout10/wordlift-plugin/issues/156) |
|
| 305 | - // Same thing applies to SEO Ultimate (https://github.com/insideout10/wordlift-plugin/issues/148) |
|
| 306 | - // This does NOT affect saving an entity from the entity admin page since this function is called when an entity |
|
| 307 | - // is created when saving a post. |
|
| 308 | - global $wpseo_metabox, $seo_ultimate; |
|
| 309 | - if ( isset( $wpseo_metabox ) ) { |
|
| 310 | - remove_action( 'wp_insert_post', array( $wpseo_metabox, 'save_postdata' ) ); |
|
| 311 | - } |
|
| 312 | - |
|
| 313 | - if ( isset( $seo_ultimate ) ) { |
|
| 314 | - remove_action( 'save_post', array( $seo_ultimate, 'save_postmeta_box' ) ); |
|
| 315 | - } |
|
| 316 | - |
|
| 317 | - // The fact that we're calling here wp_insert_post is causing issues with plugins (and ourselves too) that hook to |
|
| 318 | - // save_post in order to save additional inputs from the edit page. In order to avoid issues, we pop all the hooks |
|
| 319 | - // to the save_post and restore them after we saved the entity. |
|
| 320 | - // see https://github.com/insideout10/wordlift-plugin/issues/203 |
|
| 321 | - // see https://github.com/insideout10/wordlift-plugin/issues/156 |
|
| 322 | - // see https://github.com/insideout10/wordlift-plugin/issues/148 |
|
| 323 | - global $wp_filter; |
|
| 324 | - $save_post_filters = $wp_filter['save_post']; |
|
| 325 | - $wp_filter['save_post'] = array(); |
|
| 326 | - |
|
| 327 | - // create or update the post. |
|
| 328 | - $post_id = wp_insert_post( $params, true ); |
|
| 329 | - |
|
| 330 | - // Restore all the existing filters. |
|
| 331 | - $wp_filter['save_post'] = $save_post_filters; |
|
| 332 | - |
|
| 333 | - // If Yoast is installed and active, we restore the Yoast save_postdata hook (https://github.com/insideout10/wordlift-plugin/issues/156) |
|
| 334 | - if ( isset( $wpseo_metabox ) ) { |
|
| 335 | - add_action( 'wp_insert_post', array( $wpseo_metabox, 'save_postdata' ) ); |
|
| 336 | - } |
|
| 337 | - |
|
| 338 | - // If SEO Ultimate is installed, add back the hook we removed a few lines above. |
|
| 339 | - if ( isset( $seo_ultimate ) ) { |
|
| 340 | - add_action( 'save_post', array( $seo_ultimate, 'save_postmeta_box' ), 10, 2 ); |
|
| 341 | - } |
|
| 342 | - |
|
| 343 | - // TODO: handle errors. |
|
| 344 | - if ( is_wp_error( $post_id ) ) { |
|
| 345 | - wl_write_log( ': error occurred' ); |
|
| 346 | - |
|
| 347 | - // inform an error occurred. |
|
| 348 | - return null; |
|
| 349 | - } |
|
| 350 | - |
|
| 351 | - wl_set_entity_main_type( $post_id, $type_uri ); |
|
| 352 | - |
|
| 353 | - // Save the entity types. |
|
| 354 | - wl_set_entity_rdf_types( $post_id, $entity_types ); |
|
| 355 | - |
|
| 356 | - // Get a dataset URI for the entity. |
|
| 357 | - $wl_uri = wl_build_entity_uri( $post_id ); |
|
| 358 | - |
|
| 359 | - // Save the entity URI. |
|
| 360 | - wl_set_entity_uri( $post_id, $wl_uri ); |
|
| 361 | - |
|
| 362 | - // Add the uri to the sameAs data if it's not a local URI. |
|
| 363 | - if ( $wl_uri !== $uri ) { |
|
| 364 | - array_push( $same_as, $uri ); |
|
| 365 | - } |
|
| 366 | - |
|
| 367 | - $new_uri = wl_get_entity_uri( $post_id ); |
|
| 368 | - |
|
| 369 | - // Save the sameAs data for the entity. |
|
| 370 | - wl_schema_set_value( $post_id, 'sameAs', $same_as ); |
|
| 371 | - |
|
| 372 | - // Call hooks. |
|
| 373 | - do_action( 'wl_save_entity', $post_id ); |
|
| 374 | - |
|
| 375 | - wl_write_log( "[ post id :: $post_id ][ uri :: $uri ][ label :: $label ][ wl uri :: $wl_uri ][ types :: " . implode( ',', $entity_types ) . " ][ images count :: " . count( $images ) . " ][ same_as count :: " . count( $same_as ) . " ]" ); |
|
| 376 | - |
|
| 377 | - foreach ( $images as $image_remote_url ) { |
|
| 378 | - |
|
| 379 | - // Check if image is already present in local DB |
|
| 380 | - if ( strpos( $image_remote_url, site_url() ) !== false ) { |
|
| 381 | - // Do nothing. |
|
| 382 | - continue; |
|
| 383 | - } |
|
| 384 | - |
|
| 385 | - // Check if there is an existing attachment for this post ID and source URL. |
|
| 386 | - $existing_image = wl_get_attachment_for_source_url( $post_id, $image_remote_url ); |
|
| 387 | - |
|
| 388 | - // Skip if an existing image is found. |
|
| 389 | - if ( null !== $existing_image ) { |
|
| 390 | - continue; |
|
| 391 | - } |
|
| 392 | - |
|
| 393 | - // Save the image and get the local path. |
|
| 394 | - $image = wl_save_image( $image_remote_url ); |
|
| 395 | - |
|
| 396 | - // Get the local URL. |
|
| 397 | - $filename = $image['path']; |
|
| 398 | - $url = $image['url']; |
|
| 399 | - $content_type = $image['content_type']; |
|
| 400 | - |
|
| 401 | - $attachment = array( |
|
| 402 | - 'guid' => $url, |
|
| 403 | - // post_title, post_content (the value for this key should be the empty string), post_status and post_mime_type |
|
| 404 | - 'post_title' => $label, |
|
| 405 | - // Set the title to the post title. |
|
| 406 | - 'post_content' => '', |
|
| 407 | - 'post_status' => 'inherit', |
|
| 408 | - 'post_mime_type' => $content_type |
|
| 409 | - ); |
|
| 264 | + $uri = $entity_properties['uri']; |
|
| 265 | + $label = $entity_properties['label']; |
|
| 266 | + $type_uri = $entity_properties['main_type_uri']; |
|
| 267 | + $description = $entity_properties['description']; |
|
| 268 | + $entity_types = $entity_properties['type_uris']; |
|
| 269 | + $images = $entity_properties['images']; |
|
| 270 | + $related_post_id = $entity_properties['related_post_id']; |
|
| 271 | + $same_as = $entity_properties['same_as']; |
|
| 272 | + |
|
| 273 | + // Avoid errors due to null. |
|
| 274 | + if ( is_null( $entity_types ) ) { |
|
| 275 | + $entity_types = array(); |
|
| 276 | + } |
|
| 277 | + |
|
| 278 | + // wl_write_log( "[ uri :: $uri ][ label :: $label ][ type uri :: $type_uri ]" ); |
|
| 279 | + |
|
| 280 | + // Prepare properties of the new entity. |
|
| 281 | + $params = array( |
|
| 282 | + 'post_status' => ( is_numeric( $related_post_id ) ? get_post_status( $related_post_id ) : 'draft' ), |
|
| 283 | + 'post_type' => Wordlift_Entity_Service::TYPE_NAME, |
|
| 284 | + 'post_title' => $label, |
|
| 285 | + 'post_content' => $description, |
|
| 286 | + 'post_excerpt' => '' |
|
| 287 | + ); |
|
| 288 | + |
|
| 289 | + // Check whether an entity already exists with the provided URI. |
|
| 290 | + $post = wl_get_entity_post_by_uri( $uri ); |
|
| 291 | + |
|
| 292 | + if ( null !== $post ) { |
|
| 293 | + // We insert into the params the entity ID, so it will be updated and not inserted. |
|
| 294 | + $params['ID'] = $post->ID; |
|
| 295 | + // Preserve the current entity status |
|
| 296 | + if ( 'public' == $post->post_status ) { |
|
| 297 | + $params['post_status'] = $post->post_status; |
|
| 298 | + } |
|
| 299 | + // Preserve the current entity content. Hotfix for issue #152 |
|
| 300 | + $params['post_content'] = $post->post_content; |
|
| 301 | + } |
|
| 302 | + |
|
| 303 | + // If Yoast is installed and active, we temporary remove the save_postdata hook which causes Yoast to "pass over" |
|
| 304 | + // the local SEO form values to the created entity (https://github.com/insideout10/wordlift-plugin/issues/156) |
|
| 305 | + // Same thing applies to SEO Ultimate (https://github.com/insideout10/wordlift-plugin/issues/148) |
|
| 306 | + // This does NOT affect saving an entity from the entity admin page since this function is called when an entity |
|
| 307 | + // is created when saving a post. |
|
| 308 | + global $wpseo_metabox, $seo_ultimate; |
|
| 309 | + if ( isset( $wpseo_metabox ) ) { |
|
| 310 | + remove_action( 'wp_insert_post', array( $wpseo_metabox, 'save_postdata' ) ); |
|
| 311 | + } |
|
| 312 | + |
|
| 313 | + if ( isset( $seo_ultimate ) ) { |
|
| 314 | + remove_action( 'save_post', array( $seo_ultimate, 'save_postmeta_box' ) ); |
|
| 315 | + } |
|
| 316 | + |
|
| 317 | + // The fact that we're calling here wp_insert_post is causing issues with plugins (and ourselves too) that hook to |
|
| 318 | + // save_post in order to save additional inputs from the edit page. In order to avoid issues, we pop all the hooks |
|
| 319 | + // to the save_post and restore them after we saved the entity. |
|
| 320 | + // see https://github.com/insideout10/wordlift-plugin/issues/203 |
|
| 321 | + // see https://github.com/insideout10/wordlift-plugin/issues/156 |
|
| 322 | + // see https://github.com/insideout10/wordlift-plugin/issues/148 |
|
| 323 | + global $wp_filter; |
|
| 324 | + $save_post_filters = $wp_filter['save_post']; |
|
| 325 | + $wp_filter['save_post'] = array(); |
|
| 326 | + |
|
| 327 | + // create or update the post. |
|
| 328 | + $post_id = wp_insert_post( $params, true ); |
|
| 329 | + |
|
| 330 | + // Restore all the existing filters. |
|
| 331 | + $wp_filter['save_post'] = $save_post_filters; |
|
| 332 | + |
|
| 333 | + // If Yoast is installed and active, we restore the Yoast save_postdata hook (https://github.com/insideout10/wordlift-plugin/issues/156) |
|
| 334 | + if ( isset( $wpseo_metabox ) ) { |
|
| 335 | + add_action( 'wp_insert_post', array( $wpseo_metabox, 'save_postdata' ) ); |
|
| 336 | + } |
|
| 337 | + |
|
| 338 | + // If SEO Ultimate is installed, add back the hook we removed a few lines above. |
|
| 339 | + if ( isset( $seo_ultimate ) ) { |
|
| 340 | + add_action( 'save_post', array( $seo_ultimate, 'save_postmeta_box' ), 10, 2 ); |
|
| 341 | + } |
|
| 342 | + |
|
| 343 | + // TODO: handle errors. |
|
| 344 | + if ( is_wp_error( $post_id ) ) { |
|
| 345 | + wl_write_log( ': error occurred' ); |
|
| 346 | + |
|
| 347 | + // inform an error occurred. |
|
| 348 | + return null; |
|
| 349 | + } |
|
| 350 | + |
|
| 351 | + wl_set_entity_main_type( $post_id, $type_uri ); |
|
| 352 | + |
|
| 353 | + // Save the entity types. |
|
| 354 | + wl_set_entity_rdf_types( $post_id, $entity_types ); |
|
| 355 | + |
|
| 356 | + // Get a dataset URI for the entity. |
|
| 357 | + $wl_uri = wl_build_entity_uri( $post_id ); |
|
| 358 | + |
|
| 359 | + // Save the entity URI. |
|
| 360 | + wl_set_entity_uri( $post_id, $wl_uri ); |
|
| 361 | + |
|
| 362 | + // Add the uri to the sameAs data if it's not a local URI. |
|
| 363 | + if ( $wl_uri !== $uri ) { |
|
| 364 | + array_push( $same_as, $uri ); |
|
| 365 | + } |
|
| 366 | + |
|
| 367 | + $new_uri = wl_get_entity_uri( $post_id ); |
|
| 368 | + |
|
| 369 | + // Save the sameAs data for the entity. |
|
| 370 | + wl_schema_set_value( $post_id, 'sameAs', $same_as ); |
|
| 371 | + |
|
| 372 | + // Call hooks. |
|
| 373 | + do_action( 'wl_save_entity', $post_id ); |
|
| 374 | + |
|
| 375 | + wl_write_log( "[ post id :: $post_id ][ uri :: $uri ][ label :: $label ][ wl uri :: $wl_uri ][ types :: " . implode( ',', $entity_types ) . " ][ images count :: " . count( $images ) . " ][ same_as count :: " . count( $same_as ) . " ]" ); |
|
| 376 | + |
|
| 377 | + foreach ( $images as $image_remote_url ) { |
|
| 378 | + |
|
| 379 | + // Check if image is already present in local DB |
|
| 380 | + if ( strpos( $image_remote_url, site_url() ) !== false ) { |
|
| 381 | + // Do nothing. |
|
| 382 | + continue; |
|
| 383 | + } |
|
| 384 | + |
|
| 385 | + // Check if there is an existing attachment for this post ID and source URL. |
|
| 386 | + $existing_image = wl_get_attachment_for_source_url( $post_id, $image_remote_url ); |
|
| 387 | + |
|
| 388 | + // Skip if an existing image is found. |
|
| 389 | + if ( null !== $existing_image ) { |
|
| 390 | + continue; |
|
| 391 | + } |
|
| 392 | + |
|
| 393 | + // Save the image and get the local path. |
|
| 394 | + $image = wl_save_image( $image_remote_url ); |
|
| 395 | + |
|
| 396 | + // Get the local URL. |
|
| 397 | + $filename = $image['path']; |
|
| 398 | + $url = $image['url']; |
|
| 399 | + $content_type = $image['content_type']; |
|
| 400 | + |
|
| 401 | + $attachment = array( |
|
| 402 | + 'guid' => $url, |
|
| 403 | + // post_title, post_content (the value for this key should be the empty string), post_status and post_mime_type |
|
| 404 | + 'post_title' => $label, |
|
| 405 | + // Set the title to the post title. |
|
| 406 | + 'post_content' => '', |
|
| 407 | + 'post_status' => 'inherit', |
|
| 408 | + 'post_mime_type' => $content_type |
|
| 409 | + ); |
|
| 410 | 410 | |
| 411 | - // Create the attachment in WordPress and generate the related metadata. |
|
| 412 | - $attachment_id = wp_insert_attachment( $attachment, $filename, $post_id ); |
|
| 411 | + // Create the attachment in WordPress and generate the related metadata. |
|
| 412 | + $attachment_id = wp_insert_attachment( $attachment, $filename, $post_id ); |
|
| 413 | 413 | |
| 414 | - // Set the source URL for the image. |
|
| 415 | - wl_set_source_url( $attachment_id, $image_remote_url ); |
|
| 414 | + // Set the source URL for the image. |
|
| 415 | + wl_set_source_url( $attachment_id, $image_remote_url ); |
|
| 416 | 416 | |
| 417 | - $attachment_data = wp_generate_attachment_metadata( $attachment_id, $filename ); |
|
| 418 | - wp_update_attachment_metadata( $attachment_id, $attachment_data ); |
|
| 417 | + $attachment_data = wp_generate_attachment_metadata( $attachment_id, $filename ); |
|
| 418 | + wp_update_attachment_metadata( $attachment_id, $attachment_data ); |
|
| 419 | 419 | |
| 420 | - // Set it as the featured image. |
|
| 421 | - set_post_thumbnail( $post_id, $attachment_id ); |
|
| 422 | - } |
|
| 420 | + // Set it as the featured image. |
|
| 421 | + set_post_thumbnail( $post_id, $attachment_id ); |
|
| 422 | + } |
|
| 423 | 423 | |
| 424 | - // The entity is pushed to Redlink on save by the function hooked to save_post. |
|
| 425 | - // save the entity in the triple store. |
|
| 426 | - wl_linked_data_push_to_redlink( $post_id ); |
|
| 424 | + // The entity is pushed to Redlink on save by the function hooked to save_post. |
|
| 425 | + // save the entity in the triple store. |
|
| 426 | + wl_linked_data_push_to_redlink( $post_id ); |
|
| 427 | 427 | |
| 428 | - // finally return the entity post. |
|
| 429 | - return get_post( $post_id ); |
|
| 428 | + // finally return the entity post. |
|
| 429 | + return get_post( $post_id ); |
|
| 430 | 430 | } |
| 431 | 431 | |
| 432 | 432 | /** |
@@ -440,41 +440,41 @@ discard block |
||
| 440 | 440 | */ |
| 441 | 441 | function wl_linked_data_content_get_embedded_entities( $content ) { |
| 442 | 442 | |
| 443 | - // Remove quote escapes. |
|
| 444 | - $content = str_replace( '\\"', '"', $content ); |
|
| 443 | + // Remove quote escapes. |
|
| 444 | + $content = str_replace( '\\"', '"', $content ); |
|
| 445 | 445 | |
| 446 | - // Match all itemid attributes. |
|
| 447 | - $pattern = '/<\w+[^>]*\sitemid="([^"]+)"[^>]*>/im'; |
|
| 446 | + // Match all itemid attributes. |
|
| 447 | + $pattern = '/<\w+[^>]*\sitemid="([^"]+)"[^>]*>/im'; |
|
| 448 | 448 | |
| 449 | - // wl_write_log( "Getting entities embedded into content [ pattern :: $pattern ]" ); |
|
| 449 | + // wl_write_log( "Getting entities embedded into content [ pattern :: $pattern ]" ); |
|
| 450 | 450 | |
| 451 | - // Remove the pattern while it is found (match nested annotations). |
|
| 452 | - $matches = array(); |
|
| 451 | + // Remove the pattern while it is found (match nested annotations). |
|
| 452 | + $matches = array(); |
|
| 453 | 453 | |
| 454 | - // In case of errors, return an empty array. |
|
| 455 | - if ( false === preg_match_all( $pattern, $content, $matches ) ) { |
|
| 456 | - wl_write_log( "Found no entities embedded in content" ); |
|
| 454 | + // In case of errors, return an empty array. |
|
| 455 | + if ( false === preg_match_all( $pattern, $content, $matches ) ) { |
|
| 456 | + wl_write_log( "Found no entities embedded in content" ); |
|
| 457 | 457 | |
| 458 | - return array(); |
|
| 459 | - } |
|
| 458 | + return array(); |
|
| 459 | + } |
|
| 460 | 460 | |
| 461 | 461 | // wl_write_log("wl_update_related_entities [ content :: $content ][ data :: " . var_export($data, true). " ][ matches :: " . var_export($matches, true) . " ]"); |
| 462 | 462 | |
| 463 | - // Collect the entities. |
|
| 464 | - $entities = array(); |
|
| 465 | - foreach ( $matches[1] as $uri ) { |
|
| 466 | - $uri_d = html_entity_decode( $uri ); |
|
| 467 | - $entity = wl_get_entity_post_by_uri( $uri_d ); |
|
| 463 | + // Collect the entities. |
|
| 464 | + $entities = array(); |
|
| 465 | + foreach ( $matches[1] as $uri ) { |
|
| 466 | + $uri_d = html_entity_decode( $uri ); |
|
| 467 | + $entity = wl_get_entity_post_by_uri( $uri_d ); |
|
| 468 | 468 | |
| 469 | - if ( null !== $entity ) { |
|
| 470 | - array_push( $entities, $entity->ID ); |
|
| 471 | - } |
|
| 472 | - } |
|
| 469 | + if ( null !== $entity ) { |
|
| 470 | + array_push( $entities, $entity->ID ); |
|
| 471 | + } |
|
| 472 | + } |
|
| 473 | 473 | |
| 474 | - // $count = sizeof( $entities ); |
|
| 475 | - // wl_write_log( "Found $count entities embedded in content" ); |
|
| 474 | + // $count = sizeof( $entities ); |
|
| 475 | + // wl_write_log( "Found $count entities embedded in content" ); |
|
| 476 | 476 | |
| 477 | - return $entities; |
|
| 477 | + return $entities; |
|
| 478 | 478 | } |
| 479 | 479 | |
| 480 | 480 | /** |
@@ -486,22 +486,22 @@ discard block |
||
| 486 | 486 | */ |
| 487 | 487 | function wl_linked_data_push_to_redlink( $post_id ) { |
| 488 | 488 | |
| 489 | - // Get the post. |
|
| 490 | - $post = get_post( $post_id ); |
|
| 489 | + // Get the post. |
|
| 490 | + $post = get_post( $post_id ); |
|
| 491 | 491 | |
| 492 | - // wl_write_log( "wl_linked_data_push_to_redlink [ post id :: $post_id ][ post type :: $post->post_type ]" ); |
|
| 492 | + // wl_write_log( "wl_linked_data_push_to_redlink [ post id :: $post_id ][ post type :: $post->post_type ]" ); |
|
| 493 | 493 | |
| 494 | - // Call the method on behalf of the post type. |
|
| 495 | - switch ( $post->post_type ) { |
|
| 496 | - case 'entity': |
|
| 497 | - wl_push_entity_post_to_redlink( $post ); |
|
| 498 | - break; |
|
| 499 | - default: |
|
| 500 | - wl_push_post_to_redlink( $post ); |
|
| 501 | - } |
|
| 494 | + // Call the method on behalf of the post type. |
|
| 495 | + switch ( $post->post_type ) { |
|
| 496 | + case 'entity': |
|
| 497 | + wl_push_entity_post_to_redlink( $post ); |
|
| 498 | + break; |
|
| 499 | + default: |
|
| 500 | + wl_push_post_to_redlink( $post ); |
|
| 501 | + } |
|
| 502 | 502 | |
| 503 | - // Reindex the triple store if buffering is turned off. |
|
| 504 | - if ( false === WL_ENABLE_SPARQL_UPDATE_QUERIES_BUFFERING ) { |
|
| 505 | - wordlift_reindex_triple_store(); |
|
| 506 | - } |
|
| 503 | + // Reindex the triple store if buffering is turned off. |
|
| 504 | + if ( false === WL_ENABLE_SPARQL_UPDATE_QUERIES_BUFFERING ) { |
|
| 505 | + wordlift_reindex_triple_store(); |
|
| 506 | + } |
|
| 507 | 507 | } |
@@ -3,7 +3,7 @@ discard block |
||
| 3 | 3 | * The Linked Data module provides synchronization of local WordPress data with the remote Linked Data store. |
| 4 | 4 | */ |
| 5 | 5 | |
| 6 | -require_once( 'wordlift_linked_data_images.php' ); |
|
| 6 | +require_once('wordlift_linked_data_images.php'); |
|
| 7 | 7 | |
| 8 | 8 | /** |
| 9 | 9 | * Receive events from post saves, and split them according to the post type. |
@@ -12,24 +12,24 @@ discard block |
||
| 12 | 12 | * |
| 13 | 13 | * @param int $post_id The post id. |
| 14 | 14 | */ |
| 15 | -function wl_linked_data_save_post( $post_id ) { |
|
| 15 | +function wl_linked_data_save_post($post_id) { |
|
| 16 | 16 | |
| 17 | 17 | // If it's not numeric exit from here. |
| 18 | - if ( ! is_numeric( $post_id ) || is_numeric( wp_is_post_revision( $post_id ) ) ) { |
|
| 18 | + if ( ! is_numeric($post_id) || is_numeric(wp_is_post_revision($post_id))) { |
|
| 19 | 19 | return; |
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | // unhook this function so it doesn't loop infinitely |
| 23 | - remove_action( 'save_post', 'wl_linked_data_save_post' ); |
|
| 23 | + remove_action('save_post', 'wl_linked_data_save_post'); |
|
| 24 | 24 | |
| 25 | 25 | // raise the *wl_linked_data_save_post* event. |
| 26 | - do_action( 'wl_linked_data_save_post', $post_id ); |
|
| 26 | + do_action('wl_linked_data_save_post', $post_id); |
|
| 27 | 27 | |
| 28 | 28 | // re-hook this function |
| 29 | - add_action( 'save_post', 'wl_linked_data_save_post' ); |
|
| 29 | + add_action('save_post', 'wl_linked_data_save_post'); |
|
| 30 | 30 | } |
| 31 | 31 | |
| 32 | -add_action( 'save_post', 'wl_linked_data_save_post' ); |
|
| 32 | +add_action('save_post', 'wl_linked_data_save_post'); |
|
| 33 | 33 | |
| 34 | 34 | /** |
| 35 | 35 | * Save the post to the triple store. Also saves the entities locally and on the triple store. |
@@ -38,17 +38,17 @@ discard block |
||
| 38 | 38 | * |
| 39 | 39 | * @param int $post_id The post id being saved. |
| 40 | 40 | */ |
| 41 | -function wl_linked_data_save_post_and_related_entities( $post_id ) { |
|
| 41 | +function wl_linked_data_save_post_and_related_entities($post_id) { |
|
| 42 | 42 | |
| 43 | 43 | // Ignore auto-saves |
| 44 | - if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { |
|
| 44 | + if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { |
|
| 45 | 45 | return; |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | // get the current post. |
| 49 | - $post = get_post( $post_id ); |
|
| 49 | + $post = get_post($post_id); |
|
| 50 | 50 | |
| 51 | - remove_action( 'wl_linked_data_save_post', 'wl_linked_data_save_post_and_related_entities' ); |
|
| 51 | + remove_action('wl_linked_data_save_post', 'wl_linked_data_save_post_and_related_entities'); |
|
| 52 | 52 | |
| 53 | 53 | // wl_write_log( "[ post id :: $post_id ][ autosave :: false ][ post type :: $post->post_type ]" ); |
| 54 | 54 | |
@@ -58,125 +58,125 @@ discard block |
||
| 58 | 58 | $entities_predicates_mapping = null; |
| 59 | 59 | |
| 60 | 60 | // Save the entities coming with POST data. |
| 61 | - if ( isset( $_POST['wl_entities'] ) && isset( $_POST['wl_boxes'] ) ) { |
|
| 61 | + if (isset($_POST['wl_entities']) && isset($_POST['wl_boxes'])) { |
|
| 62 | 62 | |
| 63 | - wl_write_log( "[ post id :: $post_id ][ POST(wl_entities) :: " ); |
|
| 64 | - wl_write_log( json_encode( $_POST['wl_entities'] ) ); |
|
| 65 | - wl_write_log( "]" ); |
|
| 66 | - wl_write_log( "[ post id :: $post_id ][ POST(wl_boxes) :: " ); |
|
| 67 | - wl_write_log( json_encode( $_POST['wl_boxes'], true ) ); |
|
| 68 | - wl_write_log( "]" ); |
|
| 63 | + wl_write_log("[ post id :: $post_id ][ POST(wl_entities) :: "); |
|
| 64 | + wl_write_log(json_encode($_POST['wl_entities'])); |
|
| 65 | + wl_write_log("]"); |
|
| 66 | + wl_write_log("[ post id :: $post_id ][ POST(wl_boxes) :: "); |
|
| 67 | + wl_write_log(json_encode($_POST['wl_boxes'], true)); |
|
| 68 | + wl_write_log("]"); |
|
| 69 | 69 | |
| 70 | 70 | $entities_via_post = $_POST['wl_entities']; |
| 71 | 71 | $boxes_via_post = $_POST['wl_boxes']; |
| 72 | 72 | |
| 73 | - foreach ( $entities_via_post as $entity_uri => $entity ) { |
|
| 73 | + foreach ($entities_via_post as $entity_uri => $entity) { |
|
| 74 | 74 | // Local entities have a tmp uri with 'local-entity-' |
| 75 | 75 | // These uris need to be rewritten here and replaced in the content |
| 76 | - if ( preg_match( '/^local-entity-.+/', $entity_uri ) > 0 ) { |
|
| 76 | + if (preg_match('/^local-entity-.+/', $entity_uri) > 0) { |
|
| 77 | 77 | // Build the proper uri |
| 78 | - $uri = sprintf( '%s/%s/%s', wl_configuration_get_redlink_dataset_uri(), 'entity', wl_sanitize_uri_path( $entity['label'] ) ); |
|
| 78 | + $uri = sprintf('%s/%s/%s', wl_configuration_get_redlink_dataset_uri(), 'entity', wl_sanitize_uri_path($entity['label'])); |
|
| 79 | 79 | // Populate the mapping |
| 80 | - $entities_uri_mapping[ $entity_uri ] = $uri; |
|
| 80 | + $entities_uri_mapping[$entity_uri] = $uri; |
|
| 81 | 81 | // Override the entity obj |
| 82 | - $entities_via_post[ $entity_uri ]['uri'] = $uri; |
|
| 82 | + $entities_via_post[$entity_uri]['uri'] = $uri; |
|
| 83 | 83 | } |
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | // Populate the $entities_predicates_mapping |
| 87 | 87 | // Local Redlink uris need to be used here |
| 88 | - foreach ( $boxes_via_post as $predicate => $entity_uris ) { |
|
| 89 | - foreach ( $entity_uris as $entity_uri ) { |
|
| 88 | + foreach ($boxes_via_post as $predicate => $entity_uris) { |
|
| 89 | + foreach ($entity_uris as $entity_uri) { |
|
| 90 | 90 | // wl_write_log("Going to map predicates for uri $entity_uri "); |
| 91 | 91 | // Retrieve the entity label needed to build the uri |
| 92 | - $label = $entities_via_post[ stripslashes( $entity_uri ) ]['label']; |
|
| 93 | - $uri = sprintf( '%s/%s/%s', wl_configuration_get_redlink_dataset_uri(), 'entity', wl_sanitize_uri_path( $label ) ); |
|
| 92 | + $label = $entities_via_post[stripslashes($entity_uri)]['label']; |
|
| 93 | + $uri = sprintf('%s/%s/%s', wl_configuration_get_redlink_dataset_uri(), 'entity', wl_sanitize_uri_path($label)); |
|
| 94 | 94 | // wl_write_log("Going to map predicate $predicate to uri $uri "); |
| 95 | - $entities_predicates_mapping[ $uri ][] = $predicate; |
|
| 95 | + $entities_predicates_mapping[$uri][] = $predicate; |
|
| 96 | 96 | } |
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | // Save entities and push them to Redlink |
| 100 | 100 | // TODO: pass also latitude, longitude, etc. |
| 101 | - wl_save_entities( array_values( $entities_via_post ), $post_id ); |
|
| 101 | + wl_save_entities(array_values($entities_via_post), $post_id); |
|
| 102 | 102 | |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | // Replace tmp uris in content post if needed |
| 106 | 106 | $updated_post_content = $post->post_content; |
| 107 | 107 | // Save each entity and store the post id. |
| 108 | - foreach ( $entities_uri_mapping as $tmp_uri => $uri ) { |
|
| 109 | - $updated_post_content = str_replace( $tmp_uri, $uri, $updated_post_content ); |
|
| 108 | + foreach ($entities_uri_mapping as $tmp_uri => $uri) { |
|
| 109 | + $updated_post_content = str_replace($tmp_uri, $uri, $updated_post_content); |
|
| 110 | 110 | } |
| 111 | 111 | // Update the post content |
| 112 | - wp_update_post( array( |
|
| 112 | + wp_update_post(array( |
|
| 113 | 113 | 'ID' => $post->ID, |
| 114 | 114 | 'post_content' => $updated_post_content, |
| 115 | - ) ); |
|
| 115 | + )); |
|
| 116 | 116 | |
| 117 | 117 | // Extract related/referenced entities from text. |
| 118 | - $disambiguated_entities = wl_linked_data_content_get_embedded_entities( $updated_post_content ); |
|
| 118 | + $disambiguated_entities = wl_linked_data_content_get_embedded_entities($updated_post_content); |
|
| 119 | 119 | |
| 120 | 120 | // Reset previously saved instances |
| 121 | - wl_core_delete_relation_instances( $post_id ); |
|
| 121 | + wl_core_delete_relation_instances($post_id); |
|
| 122 | 122 | |
| 123 | 123 | // Save relation instances |
| 124 | - foreach ( array_unique( $disambiguated_entities ) as $referenced_entity_id ) { |
|
| 124 | + foreach (array_unique($disambiguated_entities) as $referenced_entity_id) { |
|
| 125 | 125 | |
| 126 | 126 | // wl_write_log(" Going to manage relation between Post $post_id and $referenced_entity_id"); |
| 127 | 127 | |
| 128 | - if ( $entities_predicates_mapping ) { |
|
| 128 | + if ($entities_predicates_mapping) { |
|
| 129 | 129 | |
| 130 | 130 | // wl_write_log(" Going to manage relation instances according to the following mapping"); |
| 131 | 131 | |
| 132 | 132 | // Retrieve the entity uri |
| 133 | - $referenced_entity_uri = wl_get_entity_uri( $referenced_entity_id ); |
|
| 133 | + $referenced_entity_uri = wl_get_entity_uri($referenced_entity_id); |
|
| 134 | 134 | // Retrieve predicates for the current uri |
| 135 | - if ( isset( $entities_predicates_mapping[ $referenced_entity_uri ] ) ) { |
|
| 136 | - foreach ( $entities_predicates_mapping[ $referenced_entity_uri ] as $predicate ) { |
|
| 135 | + if (isset($entities_predicates_mapping[$referenced_entity_uri])) { |
|
| 136 | + foreach ($entities_predicates_mapping[$referenced_entity_uri] as $predicate) { |
|
| 137 | 137 | // wl_write_log(" Going to add relation with predicate $predicate"); |
| 138 | - wl_core_add_relation_instance( $post_id, $predicate, $referenced_entity_id ); |
|
| 138 | + wl_core_add_relation_instance($post_id, $predicate, $referenced_entity_id); |
|
| 139 | 139 | } |
| 140 | 140 | } else { |
| 141 | - wl_write_log( "Entity uri $referenced_entity_uri missing in the mapping" ); |
|
| 142 | - wl_write_log( $entities_predicates_mapping ); |
|
| 141 | + wl_write_log("Entity uri $referenced_entity_uri missing in the mapping"); |
|
| 142 | + wl_write_log($entities_predicates_mapping); |
|
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | } else { |
| 146 | 146 | // Just for unit tests |
| 147 | - wl_core_add_relation_instance( $post_id, 'what', $referenced_entity_id ); |
|
| 147 | + wl_core_add_relation_instance($post_id, 'what', $referenced_entity_id); |
|
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | // TODO Check if is needed |
| 151 | - wl_linked_data_push_to_redlink( $referenced_entity_id ); |
|
| 151 | + wl_linked_data_push_to_redlink($referenced_entity_id); |
|
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | // Push the post to Redlink. |
| 155 | - wl_linked_data_push_to_redlink( $post->ID ); |
|
| 155 | + wl_linked_data_push_to_redlink($post->ID); |
|
| 156 | 156 | |
| 157 | - add_action( 'wl_linked_data_save_post', 'wl_linked_data_save_post_and_related_entities' ); |
|
| 157 | + add_action('wl_linked_data_save_post', 'wl_linked_data_save_post_and_related_entities'); |
|
| 158 | 158 | } |
| 159 | 159 | |
| 160 | -add_action( 'wl_linked_data_save_post', 'wl_linked_data_save_post_and_related_entities' ); |
|
| 160 | +add_action('wl_linked_data_save_post', 'wl_linked_data_save_post_and_related_entities'); |
|
| 161 | 161 | |
| 162 | 162 | /** |
| 163 | 163 | * Adds default schema type "Thing" as soon as an entity is created. |
| 164 | 164 | */ |
| 165 | -function wordlift_save_post_add_default_schema_type( $entity_id ) { |
|
| 165 | +function wordlift_save_post_add_default_schema_type($entity_id) { |
|
| 166 | 166 | |
| 167 | - $entity = get_post( $entity_id ); |
|
| 168 | - $entity_type = wl_schema_get_types( $entity_id ); |
|
| 167 | + $entity = get_post($entity_id); |
|
| 168 | + $entity_type = wl_schema_get_types($entity_id); |
|
| 169 | 169 | |
| 170 | 170 | // Assign type 'Thing' if we are dealing with an entity without type |
| 171 | - if ( $entity->post_type == Wordlift_Entity_Service::TYPE_NAME && is_null( $entity_type ) ) { |
|
| 171 | + if ($entity->post_type == Wordlift_Entity_Service::TYPE_NAME && is_null($entity_type)) { |
|
| 172 | 172 | |
| 173 | - wl_schema_set_types( $entity_id, 'Thing' ); |
|
| 173 | + wl_schema_set_types($entity_id, 'Thing'); |
|
| 174 | 174 | } |
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | // Priority 1 (default is 10) because we want the default type to be set as soon as possible |
| 178 | 178 | // Attatched to save_post because *wl_linked_data_save_post* does not always fire |
| 179 | -add_action( 'save_post', 'wordlift_save_post_add_default_schema_type', 1 ); |
|
| 179 | +add_action('save_post', 'wordlift_save_post_add_default_schema_type', 1); |
|
| 180 | 180 | |
| 181 | 181 | /** |
| 182 | 182 | * Save the specified entities to the local storage. |
@@ -186,7 +186,7 @@ discard block |
||
| 186 | 186 | * |
| 187 | 187 | * @return array An array of posts. |
| 188 | 188 | */ |
| 189 | -function wl_save_entities( $entities, $related_post_id = null ) { |
|
| 189 | +function wl_save_entities($entities, $related_post_id = null) { |
|
| 190 | 190 | |
| 191 | 191 | // wl_write_log( "[ entities count :: " . count( $entities ) . " ][ related post id :: $related_post_id ]" ); |
| 192 | 192 | |
@@ -194,7 +194,7 @@ discard block |
||
| 194 | 194 | $posts = array(); |
| 195 | 195 | |
| 196 | 196 | // Save each entity and store the post id. |
| 197 | - foreach ( $entities as $entity ) { |
|
| 197 | + foreach ($entities as $entity) { |
|
| 198 | 198 | |
| 199 | 199 | $uri = $entity['uri']; |
| 200 | 200 | $label = $entity['label']; |
@@ -203,21 +203,20 @@ discard block |
||
| 203 | 203 | $main_type_uri = $entity['main_type']; |
| 204 | 204 | |
| 205 | 205 | // the preferred type. |
| 206 | - $type_uris = ( isset( $entity['type'] ) ? |
|
| 207 | - $entity['type'] : |
|
| 208 | - array() ); |
|
| 206 | + $type_uris = (isset($entity['type']) ? |
|
| 207 | + $entity['type'] : array()); |
|
| 209 | 208 | |
| 210 | 209 | $description = $entity['description']; |
| 211 | - $images = ( isset( $entity['image'] ) ? |
|
| 212 | - ( is_array( $entity['image'] ) |
|
| 210 | + $images = (isset($entity['image']) ? |
|
| 211 | + (is_array($entity['image']) |
|
| 213 | 212 | ? $entity['image'] |
| 214 | - : array( $entity['image'] ) ) |
|
| 215 | - : array() ); |
|
| 216 | - $same_as = ( isset( $entity['sameas'] ) ? |
|
| 217 | - ( is_array( $entity['sameas'] ) |
|
| 213 | + : array($entity['image'])) |
|
| 214 | + : array()); |
|
| 215 | + $same_as = (isset($entity['sameas']) ? |
|
| 216 | + (is_array($entity['sameas']) |
|
| 218 | 217 | ? $entity['sameas'] |
| 219 | - : array( $entity['sameas'] ) ) |
|
| 220 | - : array() ); |
|
| 218 | + : array($entity['sameas'])) |
|
| 219 | + : array()); |
|
| 221 | 220 | |
| 222 | 221 | // Bring properties inside an associative array |
| 223 | 222 | $entity_properties = array( |
@@ -232,11 +231,11 @@ discard block |
||
| 232 | 231 | ); |
| 233 | 232 | |
| 234 | 233 | // Save the entity. |
| 235 | - $entity_post = wl_save_entity( $entity_properties ); |
|
| 234 | + $entity_post = wl_save_entity($entity_properties); |
|
| 236 | 235 | |
| 237 | 236 | // Store the post in the return array if successful. |
| 238 | - if ( null !== $entity_post ) { |
|
| 239 | - array_push( $posts, $entity_post ); |
|
| 237 | + if (null !== $entity_post) { |
|
| 238 | + array_push($posts, $entity_post); |
|
| 240 | 239 | } |
| 241 | 240 | } |
| 242 | 241 | |
@@ -259,7 +258,7 @@ discard block |
||
| 259 | 258 | * |
| 260 | 259 | * @return null|WP_Post A post instance or null in case of failure. |
| 261 | 260 | */ |
| 262 | -function wl_save_entity( $entity_properties ) { |
|
| 261 | +function wl_save_entity($entity_properties) { |
|
| 263 | 262 | |
| 264 | 263 | $uri = $entity_properties['uri']; |
| 265 | 264 | $label = $entity_properties['label']; |
@@ -271,7 +270,7 @@ discard block |
||
| 271 | 270 | $same_as = $entity_properties['same_as']; |
| 272 | 271 | |
| 273 | 272 | // Avoid errors due to null. |
| 274 | - if ( is_null( $entity_types ) ) { |
|
| 273 | + if (is_null($entity_types)) { |
|
| 275 | 274 | $entity_types = array(); |
| 276 | 275 | } |
| 277 | 276 | |
@@ -279,7 +278,7 @@ discard block |
||
| 279 | 278 | |
| 280 | 279 | // Prepare properties of the new entity. |
| 281 | 280 | $params = array( |
| 282 | - 'post_status' => ( is_numeric( $related_post_id ) ? get_post_status( $related_post_id ) : 'draft' ), |
|
| 281 | + 'post_status' => (is_numeric($related_post_id) ? get_post_status($related_post_id) : 'draft'), |
|
| 283 | 282 | 'post_type' => Wordlift_Entity_Service::TYPE_NAME, |
| 284 | 283 | 'post_title' => $label, |
| 285 | 284 | 'post_content' => $description, |
@@ -287,13 +286,13 @@ discard block |
||
| 287 | 286 | ); |
| 288 | 287 | |
| 289 | 288 | // Check whether an entity already exists with the provided URI. |
| 290 | - $post = wl_get_entity_post_by_uri( $uri ); |
|
| 289 | + $post = wl_get_entity_post_by_uri($uri); |
|
| 291 | 290 | |
| 292 | - if ( null !== $post ) { |
|
| 291 | + if (null !== $post) { |
|
| 293 | 292 | // We insert into the params the entity ID, so it will be updated and not inserted. |
| 294 | 293 | $params['ID'] = $post->ID; |
| 295 | 294 | // Preserve the current entity status |
| 296 | - if ( 'public' == $post->post_status ) { |
|
| 295 | + if ('public' == $post->post_status) { |
|
| 297 | 296 | $params['post_status'] = $post->post_status; |
| 298 | 297 | } |
| 299 | 298 | // Preserve the current entity content. Hotfix for issue #152 |
@@ -306,12 +305,12 @@ discard block |
||
| 306 | 305 | // This does NOT affect saving an entity from the entity admin page since this function is called when an entity |
| 307 | 306 | // is created when saving a post. |
| 308 | 307 | global $wpseo_metabox, $seo_ultimate; |
| 309 | - if ( isset( $wpseo_metabox ) ) { |
|
| 310 | - remove_action( 'wp_insert_post', array( $wpseo_metabox, 'save_postdata' ) ); |
|
| 308 | + if (isset($wpseo_metabox)) { |
|
| 309 | + remove_action('wp_insert_post', array($wpseo_metabox, 'save_postdata')); |
|
| 311 | 310 | } |
| 312 | 311 | |
| 313 | - if ( isset( $seo_ultimate ) ) { |
|
| 314 | - remove_action( 'save_post', array( $seo_ultimate, 'save_postmeta_box' ) ); |
|
| 312 | + if (isset($seo_ultimate)) { |
|
| 313 | + remove_action('save_post', array($seo_ultimate, 'save_postmeta_box')); |
|
| 315 | 314 | } |
| 316 | 315 | |
| 317 | 316 | // The fact that we're calling here wp_insert_post is causing issues with plugins (and ourselves too) that hook to |
@@ -325,73 +324,73 @@ discard block |
||
| 325 | 324 | $wp_filter['save_post'] = array(); |
| 326 | 325 | |
| 327 | 326 | // create or update the post. |
| 328 | - $post_id = wp_insert_post( $params, true ); |
|
| 327 | + $post_id = wp_insert_post($params, true); |
|
| 329 | 328 | |
| 330 | 329 | // Restore all the existing filters. |
| 331 | 330 | $wp_filter['save_post'] = $save_post_filters; |
| 332 | 331 | |
| 333 | 332 | // If Yoast is installed and active, we restore the Yoast save_postdata hook (https://github.com/insideout10/wordlift-plugin/issues/156) |
| 334 | - if ( isset( $wpseo_metabox ) ) { |
|
| 335 | - add_action( 'wp_insert_post', array( $wpseo_metabox, 'save_postdata' ) ); |
|
| 333 | + if (isset($wpseo_metabox)) { |
|
| 334 | + add_action('wp_insert_post', array($wpseo_metabox, 'save_postdata')); |
|
| 336 | 335 | } |
| 337 | 336 | |
| 338 | 337 | // If SEO Ultimate is installed, add back the hook we removed a few lines above. |
| 339 | - if ( isset( $seo_ultimate ) ) { |
|
| 340 | - add_action( 'save_post', array( $seo_ultimate, 'save_postmeta_box' ), 10, 2 ); |
|
| 338 | + if (isset($seo_ultimate)) { |
|
| 339 | + add_action('save_post', array($seo_ultimate, 'save_postmeta_box'), 10, 2); |
|
| 341 | 340 | } |
| 342 | 341 | |
| 343 | 342 | // TODO: handle errors. |
| 344 | - if ( is_wp_error( $post_id ) ) { |
|
| 345 | - wl_write_log( ': error occurred' ); |
|
| 343 | + if (is_wp_error($post_id)) { |
|
| 344 | + wl_write_log(': error occurred'); |
|
| 346 | 345 | |
| 347 | 346 | // inform an error occurred. |
| 348 | 347 | return null; |
| 349 | 348 | } |
| 350 | 349 | |
| 351 | - wl_set_entity_main_type( $post_id, $type_uri ); |
|
| 350 | + wl_set_entity_main_type($post_id, $type_uri); |
|
| 352 | 351 | |
| 353 | 352 | // Save the entity types. |
| 354 | - wl_set_entity_rdf_types( $post_id, $entity_types ); |
|
| 353 | + wl_set_entity_rdf_types($post_id, $entity_types); |
|
| 355 | 354 | |
| 356 | 355 | // Get a dataset URI for the entity. |
| 357 | - $wl_uri = wl_build_entity_uri( $post_id ); |
|
| 356 | + $wl_uri = wl_build_entity_uri($post_id); |
|
| 358 | 357 | |
| 359 | 358 | // Save the entity URI. |
| 360 | - wl_set_entity_uri( $post_id, $wl_uri ); |
|
| 359 | + wl_set_entity_uri($post_id, $wl_uri); |
|
| 361 | 360 | |
| 362 | 361 | // Add the uri to the sameAs data if it's not a local URI. |
| 363 | - if ( $wl_uri !== $uri ) { |
|
| 364 | - array_push( $same_as, $uri ); |
|
| 362 | + if ($wl_uri !== $uri) { |
|
| 363 | + array_push($same_as, $uri); |
|
| 365 | 364 | } |
| 366 | 365 | |
| 367 | - $new_uri = wl_get_entity_uri( $post_id ); |
|
| 366 | + $new_uri = wl_get_entity_uri($post_id); |
|
| 368 | 367 | |
| 369 | 368 | // Save the sameAs data for the entity. |
| 370 | - wl_schema_set_value( $post_id, 'sameAs', $same_as ); |
|
| 369 | + wl_schema_set_value($post_id, 'sameAs', $same_as); |
|
| 371 | 370 | |
| 372 | 371 | // Call hooks. |
| 373 | - do_action( 'wl_save_entity', $post_id ); |
|
| 372 | + do_action('wl_save_entity', $post_id); |
|
| 374 | 373 | |
| 375 | - wl_write_log( "[ post id :: $post_id ][ uri :: $uri ][ label :: $label ][ wl uri :: $wl_uri ][ types :: " . implode( ',', $entity_types ) . " ][ images count :: " . count( $images ) . " ][ same_as count :: " . count( $same_as ) . " ]" ); |
|
| 374 | + wl_write_log("[ post id :: $post_id ][ uri :: $uri ][ label :: $label ][ wl uri :: $wl_uri ][ types :: ".implode(',', $entity_types)." ][ images count :: ".count($images)." ][ same_as count :: ".count($same_as)." ]"); |
|
| 376 | 375 | |
| 377 | - foreach ( $images as $image_remote_url ) { |
|
| 376 | + foreach ($images as $image_remote_url) { |
|
| 378 | 377 | |
| 379 | 378 | // Check if image is already present in local DB |
| 380 | - if ( strpos( $image_remote_url, site_url() ) !== false ) { |
|
| 379 | + if (strpos($image_remote_url, site_url()) !== false) { |
|
| 381 | 380 | // Do nothing. |
| 382 | 381 | continue; |
| 383 | 382 | } |
| 384 | 383 | |
| 385 | 384 | // Check if there is an existing attachment for this post ID and source URL. |
| 386 | - $existing_image = wl_get_attachment_for_source_url( $post_id, $image_remote_url ); |
|
| 385 | + $existing_image = wl_get_attachment_for_source_url($post_id, $image_remote_url); |
|
| 387 | 386 | |
| 388 | 387 | // Skip if an existing image is found. |
| 389 | - if ( null !== $existing_image ) { |
|
| 388 | + if (null !== $existing_image) { |
|
| 390 | 389 | continue; |
| 391 | 390 | } |
| 392 | 391 | |
| 393 | 392 | // Save the image and get the local path. |
| 394 | - $image = wl_save_image( $image_remote_url ); |
|
| 393 | + $image = wl_save_image($image_remote_url); |
|
| 395 | 394 | |
| 396 | 395 | // Get the local URL. |
| 397 | 396 | $filename = $image['path']; |
@@ -409,24 +408,24 @@ discard block |
||
| 409 | 408 | ); |
| 410 | 409 | |
| 411 | 410 | // Create the attachment in WordPress and generate the related metadata. |
| 412 | - $attachment_id = wp_insert_attachment( $attachment, $filename, $post_id ); |
|
| 411 | + $attachment_id = wp_insert_attachment($attachment, $filename, $post_id); |
|
| 413 | 412 | |
| 414 | 413 | // Set the source URL for the image. |
| 415 | - wl_set_source_url( $attachment_id, $image_remote_url ); |
|
| 414 | + wl_set_source_url($attachment_id, $image_remote_url); |
|
| 416 | 415 | |
| 417 | - $attachment_data = wp_generate_attachment_metadata( $attachment_id, $filename ); |
|
| 418 | - wp_update_attachment_metadata( $attachment_id, $attachment_data ); |
|
| 416 | + $attachment_data = wp_generate_attachment_metadata($attachment_id, $filename); |
|
| 417 | + wp_update_attachment_metadata($attachment_id, $attachment_data); |
|
| 419 | 418 | |
| 420 | 419 | // Set it as the featured image. |
| 421 | - set_post_thumbnail( $post_id, $attachment_id ); |
|
| 420 | + set_post_thumbnail($post_id, $attachment_id); |
|
| 422 | 421 | } |
| 423 | 422 | |
| 424 | 423 | // The entity is pushed to Redlink on save by the function hooked to save_post. |
| 425 | 424 | // save the entity in the triple store. |
| 426 | - wl_linked_data_push_to_redlink( $post_id ); |
|
| 425 | + wl_linked_data_push_to_redlink($post_id); |
|
| 427 | 426 | |
| 428 | 427 | // finally return the entity post. |
| 429 | - return get_post( $post_id ); |
|
| 428 | + return get_post($post_id); |
|
| 430 | 429 | } |
| 431 | 430 | |
| 432 | 431 | /** |
@@ -438,10 +437,10 @@ discard block |
||
| 438 | 437 | * |
| 439 | 438 | * @return array An array of entity posts. |
| 440 | 439 | */ |
| 441 | -function wl_linked_data_content_get_embedded_entities( $content ) { |
|
| 440 | +function wl_linked_data_content_get_embedded_entities($content) { |
|
| 442 | 441 | |
| 443 | 442 | // Remove quote escapes. |
| 444 | - $content = str_replace( '\\"', '"', $content ); |
|
| 443 | + $content = str_replace('\\"', '"', $content); |
|
| 445 | 444 | |
| 446 | 445 | // Match all itemid attributes. |
| 447 | 446 | $pattern = '/<\w+[^>]*\sitemid="([^"]+)"[^>]*>/im'; |
@@ -452,8 +451,8 @@ discard block |
||
| 452 | 451 | $matches = array(); |
| 453 | 452 | |
| 454 | 453 | // In case of errors, return an empty array. |
| 455 | - if ( false === preg_match_all( $pattern, $content, $matches ) ) { |
|
| 456 | - wl_write_log( "Found no entities embedded in content" ); |
|
| 454 | + if (false === preg_match_all($pattern, $content, $matches)) { |
|
| 455 | + wl_write_log("Found no entities embedded in content"); |
|
| 457 | 456 | |
| 458 | 457 | return array(); |
| 459 | 458 | } |
@@ -462,12 +461,12 @@ discard block |
||
| 462 | 461 | |
| 463 | 462 | // Collect the entities. |
| 464 | 463 | $entities = array(); |
| 465 | - foreach ( $matches[1] as $uri ) { |
|
| 466 | - $uri_d = html_entity_decode( $uri ); |
|
| 467 | - $entity = wl_get_entity_post_by_uri( $uri_d ); |
|
| 464 | + foreach ($matches[1] as $uri) { |
|
| 465 | + $uri_d = html_entity_decode($uri); |
|
| 466 | + $entity = wl_get_entity_post_by_uri($uri_d); |
|
| 468 | 467 | |
| 469 | - if ( null !== $entity ) { |
|
| 470 | - array_push( $entities, $entity->ID ); |
|
| 468 | + if (null !== $entity) { |
|
| 469 | + array_push($entities, $entity->ID); |
|
| 471 | 470 | } |
| 472 | 471 | } |
| 473 | 472 | |
@@ -484,24 +483,24 @@ discard block |
||
| 484 | 483 | * |
| 485 | 484 | * @param int $post_id The post ID. |
| 486 | 485 | */ |
| 487 | -function wl_linked_data_push_to_redlink( $post_id ) { |
|
| 486 | +function wl_linked_data_push_to_redlink($post_id) { |
|
| 488 | 487 | |
| 489 | 488 | // Get the post. |
| 490 | - $post = get_post( $post_id ); |
|
| 489 | + $post = get_post($post_id); |
|
| 491 | 490 | |
| 492 | 491 | // wl_write_log( "wl_linked_data_push_to_redlink [ post id :: $post_id ][ post type :: $post->post_type ]" ); |
| 493 | 492 | |
| 494 | 493 | // Call the method on behalf of the post type. |
| 495 | - switch ( $post->post_type ) { |
|
| 494 | + switch ($post->post_type) { |
|
| 496 | 495 | case 'entity': |
| 497 | - wl_push_entity_post_to_redlink( $post ); |
|
| 496 | + wl_push_entity_post_to_redlink($post); |
|
| 498 | 497 | break; |
| 499 | 498 | default: |
| 500 | - wl_push_post_to_redlink( $post ); |
|
| 499 | + wl_push_post_to_redlink($post); |
|
| 501 | 500 | } |
| 502 | 501 | |
| 503 | 502 | // Reindex the triple store if buffering is turned off. |
| 504 | - if ( false === WL_ENABLE_SPARQL_UPDATE_QUERIES_BUFFERING ) { |
|
| 503 | + if (false === WL_ENABLE_SPARQL_UPDATE_QUERIES_BUFFERING) { |
|
| 505 | 504 | wordlift_reindex_triple_store(); |
| 506 | 505 | } |
| 507 | 506 | } |
@@ -173,100 +173,100 @@ discard block |
||
| 173 | 173 | * The class responsible for orchestrating the actions and filters of the |
| 174 | 174 | * core plugin. |
| 175 | 175 | */ |
| 176 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-loader.php'; |
|
| 176 | + require_once plugin_dir_path(dirname(__FILE__)).'includes/class-wordlift-loader.php'; |
|
| 177 | 177 | |
| 178 | 178 | /** |
| 179 | 179 | * The class responsible for defining internationalization functionality |
| 180 | 180 | * of the plugin. |
| 181 | 181 | */ |
| 182 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-i18n.php'; |
|
| 182 | + require_once plugin_dir_path(dirname(__FILE__)).'includes/class-wordlift-i18n.php'; |
|
| 183 | 183 | |
| 184 | 184 | /** |
| 185 | 185 | * The Redirect service. |
| 186 | 186 | */ |
| 187 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-redirect-service.php'; |
|
| 187 | + require_once plugin_dir_path(dirname(__FILE__)).'includes/class-wordlift-redirect-service.php'; |
|
| 188 | 188 | |
| 189 | 189 | /** |
| 190 | 190 | * The Log service. |
| 191 | 191 | */ |
| 192 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-log-service.php'; |
|
| 192 | + require_once plugin_dir_path(dirname(__FILE__)).'includes/class-wordlift-log-service.php'; |
|
| 193 | 193 | |
| 194 | 194 | /** |
| 195 | 195 | * The Query builder. |
| 196 | 196 | */ |
| 197 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-query-builder.php'; |
|
| 197 | + require_once plugin_dir_path(dirname(__FILE__)).'includes/class-wordlift-query-builder.php'; |
|
| 198 | 198 | |
| 199 | 199 | /** |
| 200 | 200 | * The Schema service. |
| 201 | 201 | */ |
| 202 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-schema-service.php'; |
|
| 202 | + require_once plugin_dir_path(dirname(__FILE__)).'includes/class-wordlift-schema-service.php'; |
|
| 203 | 203 | |
| 204 | 204 | /** |
| 205 | 205 | * The UI service. |
| 206 | 206 | */ |
| 207 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-ui-service.php'; |
|
| 207 | + require_once plugin_dir_path(dirname(__FILE__)).'includes/class-wordlift-ui-service.php'; |
|
| 208 | 208 | |
| 209 | 209 | /** |
| 210 | 210 | * The Thumbnail service. |
| 211 | 211 | */ |
| 212 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-thumbnail-service.php'; |
|
| 212 | + require_once plugin_dir_path(dirname(__FILE__)).'includes/class-wordlift-thumbnail-service.php'; |
|
| 213 | 213 | |
| 214 | 214 | /** |
| 215 | 215 | * The Entity Types Taxonomy service. |
| 216 | 216 | */ |
| 217 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-entity-types-taxonomy-service.php'; |
|
| 217 | + require_once plugin_dir_path(dirname(__FILE__)).'includes/class-wordlift-entity-types-taxonomy-service.php'; |
|
| 218 | 218 | |
| 219 | 219 | /** |
| 220 | 220 | * The Entity service. |
| 221 | 221 | */ |
| 222 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-entity-service.php'; |
|
| 222 | + require_once plugin_dir_path(dirname(__FILE__)).'includes/class-wordlift-entity-service.php'; |
|
| 223 | 223 | |
| 224 | 224 | /** |
| 225 | 225 | * The User service. |
| 226 | 226 | */ |
| 227 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-user-service.php'; |
|
| 227 | + require_once plugin_dir_path(dirname(__FILE__)).'includes/class-wordlift-user-service.php'; |
|
| 228 | 228 | |
| 229 | 229 | /** |
| 230 | 230 | * The Timeline service. |
| 231 | 231 | */ |
| 232 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-timeline-service.php'; |
|
| 232 | + require_once plugin_dir_path(dirname(__FILE__)).'includes/class-wordlift-timeline-service.php'; |
|
| 233 | 233 | |
| 234 | 234 | /** |
| 235 | 235 | * The class responsible for defining all actions that occur in the admin area. |
| 236 | 236 | */ |
| 237 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin.php'; |
|
| 237 | + require_once plugin_dir_path(dirname(__FILE__)).'admin/class-wordlift-admin.php'; |
|
| 238 | 238 | |
| 239 | 239 | /** |
| 240 | 240 | * The Entity Types Taxonomy Walker (transforms checkboxes into radios). |
| 241 | 241 | */ |
| 242 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-entity-types-taxonomy-walker.php'; |
|
| 242 | + require_once plugin_dir_path(dirname(__FILE__)).'admin/class-wordlift-entity-types-taxonomy-walker.php'; |
|
| 243 | 243 | |
| 244 | 244 | /** |
| 245 | 245 | * The Notice service. |
| 246 | 246 | */ |
| 247 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-notice-service.php'; |
|
| 247 | + require_once plugin_dir_path(dirname(__FILE__)).'admin/class-wordlift-notice-service.php'; |
|
| 248 | 248 | |
| 249 | 249 | /** |
| 250 | 250 | * The class responsible for defining all actions that occur in the public-facing |
| 251 | 251 | * side of the site. |
| 252 | 252 | */ |
| 253 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-wordlift-public.php'; |
|
| 253 | + require_once plugin_dir_path(dirname(__FILE__)).'public/class-wordlift-public.php'; |
|
| 254 | 254 | |
| 255 | 255 | /** |
| 256 | 256 | * The Timeline shortcode. |
| 257 | 257 | */ |
| 258 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-wordlift-timeline-shortcode.php'; |
|
| 258 | + require_once plugin_dir_path(dirname(__FILE__)).'public/class-wordlift-timeline-shortcode.php'; |
|
| 259 | 259 | |
| 260 | 260 | /** |
| 261 | 261 | * The ShareThis service. |
| 262 | 262 | */ |
| 263 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-wordlift-sharethis-service.php'; |
|
| 263 | + require_once plugin_dir_path(dirname(__FILE__)).'public/class-wordlift-sharethis-service.php'; |
|
| 264 | 264 | |
| 265 | 265 | $this->loader = new Wordlift_Loader(); |
| 266 | 266 | |
| 267 | 267 | // Instantiate a global logger. |
| 268 | 268 | global $wl_logger; |
| 269 | - $wl_logger = Wordlift_Log_Service::get_logger( 'WordLift' ); |
|
| 269 | + $wl_logger = Wordlift_Log_Service::get_logger('WordLift'); |
|
| 270 | 270 | |
| 271 | 271 | // Create an instance of the UI service. |
| 272 | 272 | $this->ui_service = new Wordlift_UI_Service(); |
@@ -278,16 +278,16 @@ discard block |
||
| 278 | 278 | new Wordlift_Schema_Service(); |
| 279 | 279 | |
| 280 | 280 | // Create an instance of the Entity service, passing the UI service to draw parts of the Entity admin page. |
| 281 | - $this->entity_service = new Wordlift_Entity_Service( $this->ui_service ); |
|
| 281 | + $this->entity_service = new Wordlift_Entity_Service($this->ui_service); |
|
| 282 | 282 | |
| 283 | 283 | // Create an instance of the User service. |
| 284 | 284 | $this->user_service = new Wordlift_User_Service(); |
| 285 | 285 | |
| 286 | 286 | // Create a new instance of the Timeline service and Timeline shortcode. |
| 287 | - $this->timeline_service = new Wordlift_Timeline_Service( $this->entity_service ); |
|
| 287 | + $this->timeline_service = new Wordlift_Timeline_Service($this->entity_service); |
|
| 288 | 288 | |
| 289 | 289 | // Create a new instance of the Redirect service. |
| 290 | - $this->redirect_service = new Wordlift_Redirect_Service( $this->entity_service ); |
|
| 290 | + $this->redirect_service = new Wordlift_Redirect_Service($this->entity_service); |
|
| 291 | 291 | |
| 292 | 292 | // Create an instance of the Timeline shortcode. |
| 293 | 293 | new Wordlift_Timeline_Shortcode(); |
@@ -313,9 +313,9 @@ discard block |
||
| 313 | 313 | private function set_locale() { |
| 314 | 314 | |
| 315 | 315 | $plugin_i18n = new Wordlift_i18n(); |
| 316 | - $plugin_i18n->set_domain( $this->get_plugin_name() ); |
|
| 316 | + $plugin_i18n->set_domain($this->get_plugin_name()); |
|
| 317 | 317 | |
| 318 | - $this->loader->add_action( 'plugins_loaded', $plugin_i18n, 'load_plugin_textdomain' ); |
|
| 318 | + $this->loader->add_action('plugins_loaded', $plugin_i18n, 'load_plugin_textdomain'); |
|
| 319 | 319 | |
| 320 | 320 | } |
| 321 | 321 | |
@@ -328,34 +328,34 @@ discard block |
||
| 328 | 328 | */ |
| 329 | 329 | private function define_admin_hooks() { |
| 330 | 330 | |
| 331 | - $plugin_admin = new Wordlift_Admin( $this->get_plugin_name(), $this->get_version() ); |
|
| 331 | + $plugin_admin = new Wordlift_Admin($this->get_plugin_name(), $this->get_version()); |
|
| 332 | 332 | |
| 333 | - $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' ); |
|
| 334 | - $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' ); |
|
| 333 | + $this->loader->add_action('admin_enqueue_scripts', $plugin_admin, 'enqueue_styles'); |
|
| 334 | + $this->loader->add_action('admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts'); |
|
| 335 | 335 | |
| 336 | 336 | // Hook the deleted_post_meta action to the Thumbnail service. |
| 337 | - $this->loader->add_action( 'deleted_post_meta', $this->thumbnail_service, 'deleted_post_meta', 10, 4 ); |
|
| 337 | + $this->loader->add_action('deleted_post_meta', $this->thumbnail_service, 'deleted_post_meta', 10, 4); |
|
| 338 | 338 | |
| 339 | 339 | // Hook the added_post_meta action to the Thumbnail service. |
| 340 | - $this->loader->add_action( 'added_post_meta', $this->thumbnail_service, 'added_post_meta', 10, 4 ); |
|
| 340 | + $this->loader->add_action('added_post_meta', $this->thumbnail_service, 'added_post_meta', 10, 4); |
|
| 341 | 341 | |
| 342 | 342 | // Hook posts inserts (or updates) to the user service. |
| 343 | - $this->loader->add_action( 'wp_insert_post', $this->user_service, 'wp_insert_post', 10, 3 ); |
|
| 343 | + $this->loader->add_action('wp_insert_post', $this->user_service, 'wp_insert_post', 10, 3); |
|
| 344 | 344 | |
| 345 | 345 | // Hook the AJAX wl_timeline action to the Timeline service. |
| 346 | - $this->loader->add_action( 'wp_ajax_wl_timeline', $this->timeline_service, 'ajax_timeline' ); |
|
| 346 | + $this->loader->add_action('wp_ajax_wl_timeline', $this->timeline_service, 'ajax_timeline'); |
|
| 347 | 347 | |
| 348 | 348 | // Register custom allowed redirect hosts. |
| 349 | - $this->loader->add_filter( 'allowed_redirect_hosts' , $this->redirect_service, 'allowed_redirect_hosts' ); |
|
| 349 | + $this->loader->add_filter('allowed_redirect_hosts', $this->redirect_service, 'allowed_redirect_hosts'); |
|
| 350 | 350 | // Hook the AJAX wordlift_redirect action to the Redirect service. |
| 351 | - $this->loader->add_action( 'wp_ajax_wordlift_redirect', $this->redirect_service, 'ajax_redirect' ); |
|
| 351 | + $this->loader->add_action('wp_ajax_wordlift_redirect', $this->redirect_service, 'ajax_redirect'); |
|
| 352 | 352 | |
| 353 | 353 | // Hook save_post to the entity service to update custom fields (such as alternate labels). |
| 354 | 354 | // We have a priority of 9 because we want to be executed before data is sent to Redlink. |
| 355 | - $this->loader->add_action( 'save_post', $this->entity_service, 'save_post', 9, 3 ); |
|
| 356 | - $this->loader->add_action( 'edit_form_before_permalink', $this->entity_service, 'edit_form_before_permalink', 10, 1 ); |
|
| 355 | + $this->loader->add_action('save_post', $this->entity_service, 'save_post', 9, 3); |
|
| 356 | + $this->loader->add_action('edit_form_before_permalink', $this->entity_service, 'edit_form_before_permalink', 10, 1); |
|
| 357 | 357 | |
| 358 | - $this->loader->add_filter( 'wp_terms_checklist_args', $this->entity_types_taxonomy_walker, 'terms_checklist_args' ); |
|
| 358 | + $this->loader->add_filter('wp_terms_checklist_args', $this->entity_types_taxonomy_walker, 'terms_checklist_args'); |
|
| 359 | 359 | |
| 360 | 360 | } |
| 361 | 361 | |
@@ -368,17 +368,17 @@ discard block |
||
| 368 | 368 | */ |
| 369 | 369 | private function define_public_hooks() { |
| 370 | 370 | |
| 371 | - $plugin_public = new Wordlift_Public( $this->get_plugin_name(), $this->get_version() ); |
|
| 371 | + $plugin_public = new Wordlift_Public($this->get_plugin_name(), $this->get_version()); |
|
| 372 | 372 | |
| 373 | - $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_styles' ); |
|
| 374 | - $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts' ); |
|
| 373 | + $this->loader->add_action('wp_enqueue_scripts', $plugin_public, 'enqueue_styles'); |
|
| 374 | + $this->loader->add_action('wp_enqueue_scripts', $plugin_public, 'enqueue_scripts'); |
|
| 375 | 375 | |
| 376 | 376 | // Hook the AJAX wl_timeline action to the Timeline service. |
| 377 | - $this->loader->add_action( 'wp_ajax_nopriv_wl_timeline', $this->timeline_service, 'ajax_timeline' ); |
|
| 377 | + $this->loader->add_action('wp_ajax_nopriv_wl_timeline', $this->timeline_service, 'ajax_timeline'); |
|
| 378 | 378 | |
| 379 | 379 | // Hook the ShareThis service. |
| 380 | - $this->loader->add_filter( 'the_content', $this->sharethis_service, 'the_content', 99 ); |
|
| 381 | - $this->loader->add_filter( 'the_excerpt', $this->sharethis_service, 'the_excerpt', 99 ); |
|
| 380 | + $this->loader->add_filter('the_content', $this->sharethis_service, 'the_content', 99); |
|
| 381 | + $this->loader->add_filter('the_excerpt', $this->sharethis_service, 'the_excerpt', 99); |
|
| 382 | 382 | } |
| 383 | 383 | |
| 384 | 384 | /** |
@@ -29,396 +29,396 @@ |
||
| 29 | 29 | */ |
| 30 | 30 | class Wordlift { |
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * The loader that's responsible for maintaining and registering all hooks that power |
|
| 34 | - * the plugin. |
|
| 35 | - * |
|
| 36 | - * @since 1.0.0 |
|
| 37 | - * @access protected |
|
| 38 | - * @var Wordlift_Loader $loader Maintains and registers all hooks for the plugin. |
|
| 39 | - */ |
|
| 40 | - protected $loader; |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * The unique identifier of this plugin. |
|
| 44 | - * |
|
| 45 | - * @since 1.0.0 |
|
| 46 | - * @access protected |
|
| 47 | - * @var string $plugin_name The string used to uniquely identify this plugin. |
|
| 48 | - */ |
|
| 49 | - protected $plugin_name; |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * The current version of the plugin. |
|
| 53 | - * |
|
| 54 | - * @since 1.0.0 |
|
| 55 | - * @access protected |
|
| 56 | - * @var string $version The current version of the plugin. |
|
| 57 | - */ |
|
| 58 | - protected $version; |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * The Thumbnail service. |
|
| 62 | - * |
|
| 63 | - * @since 3.1.5 |
|
| 64 | - * @access private |
|
| 65 | - * @var \Wordlift_Thumbnail_Service $thumbnail_service The Thumbnail service. |
|
| 66 | - */ |
|
| 67 | - private $thumbnail_service; |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * The UI service. |
|
| 71 | - * |
|
| 72 | - * @since 3.2.0 |
|
| 73 | - * @access private |
|
| 74 | - * @var \Wordlift_UI_Service $ui_service The UI service. |
|
| 75 | - */ |
|
| 76 | - private $ui_service; |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * The Entity service. |
|
| 80 | - * |
|
| 81 | - * @since 3.1.0 |
|
| 82 | - * @access private |
|
| 83 | - * @var \Wordlift_Entity_Service $entity_service The Entity service. |
|
| 84 | - */ |
|
| 85 | - private $entity_service; |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * The User service. |
|
| 89 | - * |
|
| 90 | - * @since 3.1.7 |
|
| 91 | - * @access private |
|
| 92 | - * @var \Wordlift_User_Service $user_service The User service. |
|
| 93 | - */ |
|
| 94 | - private $user_service; |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * The Timeline service. |
|
| 98 | - * |
|
| 99 | - * @since 3.1.0 |
|
| 100 | - * @access private |
|
| 101 | - * @var \Wordlift_Timeline_Service $timeline_service The Timeline service. |
|
| 102 | - */ |
|
| 103 | - private $timeline_service; |
|
| 104 | - |
|
| 105 | - /** |
|
| 106 | - * The Redirect service. |
|
| 107 | - * |
|
| 108 | - * @since 3.2.0 |
|
| 109 | - * @access private |
|
| 110 | - * @var \Wordlift_Redirect_Service $redirect_service The Redirect service. |
|
| 111 | - */ |
|
| 112 | - private $redirect_service; |
|
| 113 | - |
|
| 114 | - /** |
|
| 115 | - * The Entity Types Taxonomy Walker. |
|
| 116 | - * |
|
| 117 | - * @since 3.1.0 |
|
| 118 | - * @access private |
|
| 119 | - * @var \Wordlift_Entity_Types_Taxonomy_Walker $entity_types_taxonomy_walker The Entity Types Taxonomy Walker |
|
| 120 | - */ |
|
| 121 | - private $entity_types_taxonomy_walker; |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * The ShareThis service. |
|
| 125 | - * |
|
| 126 | - * @since 3.2.0 |
|
| 127 | - * @access private |
|
| 128 | - * @var \Wordlift_ShareThis_Service $sharethis_service The ShareThis service. |
|
| 129 | - */ |
|
| 130 | - private $sharethis_service; |
|
| 131 | - |
|
| 132 | - /** |
|
| 133 | - * Define the core functionality of the plugin. |
|
| 134 | - * |
|
| 135 | - * Set the plugin name and the plugin version that can be used throughout the plugin. |
|
| 136 | - * Load the dependencies, define the locale, and set the hooks for the admin area and |
|
| 137 | - * the public-facing side of the site. |
|
| 138 | - * |
|
| 139 | - * @since 1.0.0 |
|
| 140 | - */ |
|
| 141 | - public function __construct() { |
|
| 142 | - |
|
| 143 | - $this->plugin_name = 'wordlift'; |
|
| 144 | - |
|
| 145 | - $this->version = '3.3.0-dev'; |
|
| 146 | - |
|
| 147 | - $this->load_dependencies(); |
|
| 148 | - $this->set_locale(); |
|
| 149 | - $this->define_admin_hooks(); |
|
| 150 | - $this->define_public_hooks(); |
|
| 151 | - |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - /** |
|
| 155 | - * Load the required dependencies for this plugin. |
|
| 156 | - * |
|
| 157 | - * Include the following files that make up the plugin: |
|
| 158 | - * |
|
| 159 | - * - Wordlift_Loader. Orchestrates the hooks of the plugin. |
|
| 160 | - * - Wordlift_i18n. Defines internationalization functionality. |
|
| 161 | - * - Wordlift_Admin. Defines all hooks for the admin area. |
|
| 162 | - * - Wordlift_Public. Defines all hooks for the public side of the site. |
|
| 163 | - * |
|
| 164 | - * Create an instance of the loader which will be used to register the hooks |
|
| 165 | - * with WordPress. |
|
| 166 | - * |
|
| 167 | - * @since 1.0.0 |
|
| 168 | - * @access private |
|
| 169 | - */ |
|
| 170 | - private function load_dependencies() { |
|
| 171 | - |
|
| 172 | - /** |
|
| 173 | - * The class responsible for orchestrating the actions and filters of the |
|
| 174 | - * core plugin. |
|
| 175 | - */ |
|
| 176 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-loader.php'; |
|
| 177 | - |
|
| 178 | - /** |
|
| 179 | - * The class responsible for defining internationalization functionality |
|
| 180 | - * of the plugin. |
|
| 181 | - */ |
|
| 182 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-i18n.php'; |
|
| 183 | - |
|
| 184 | - /** |
|
| 185 | - * The Redirect service. |
|
| 186 | - */ |
|
| 187 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-redirect-service.php'; |
|
| 188 | - |
|
| 189 | - /** |
|
| 190 | - * The Log service. |
|
| 191 | - */ |
|
| 192 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-log-service.php'; |
|
| 193 | - |
|
| 194 | - /** |
|
| 195 | - * The Query builder. |
|
| 196 | - */ |
|
| 197 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-query-builder.php'; |
|
| 198 | - |
|
| 199 | - /** |
|
| 200 | - * The Schema service. |
|
| 201 | - */ |
|
| 202 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-schema-service.php'; |
|
| 203 | - |
|
| 204 | - /** |
|
| 205 | - * The UI service. |
|
| 206 | - */ |
|
| 207 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-ui-service.php'; |
|
| 208 | - |
|
| 209 | - /** |
|
| 210 | - * The Thumbnail service. |
|
| 211 | - */ |
|
| 212 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-thumbnail-service.php'; |
|
| 213 | - |
|
| 214 | - /** |
|
| 215 | - * The Entity Types Taxonomy service. |
|
| 216 | - */ |
|
| 217 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-entity-types-taxonomy-service.php'; |
|
| 218 | - |
|
| 219 | - /** |
|
| 220 | - * The Entity service. |
|
| 221 | - */ |
|
| 222 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-entity-service.php'; |
|
| 223 | - |
|
| 224 | - /** |
|
| 225 | - * The User service. |
|
| 226 | - */ |
|
| 227 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-user-service.php'; |
|
| 228 | - |
|
| 229 | - /** |
|
| 230 | - * The Timeline service. |
|
| 231 | - */ |
|
| 232 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-timeline-service.php'; |
|
| 233 | - |
|
| 234 | - /** |
|
| 235 | - * The class responsible for defining all actions that occur in the admin area. |
|
| 236 | - */ |
|
| 237 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin.php'; |
|
| 238 | - |
|
| 239 | - /** |
|
| 240 | - * The Entity Types Taxonomy Walker (transforms checkboxes into radios). |
|
| 241 | - */ |
|
| 242 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-entity-types-taxonomy-walker.php'; |
|
| 243 | - |
|
| 244 | - /** |
|
| 245 | - * The Notice service. |
|
| 246 | - */ |
|
| 247 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-notice-service.php'; |
|
| 248 | - |
|
| 249 | - /** |
|
| 250 | - * The class responsible for defining all actions that occur in the public-facing |
|
| 251 | - * side of the site. |
|
| 252 | - */ |
|
| 253 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-wordlift-public.php'; |
|
| 254 | - |
|
| 255 | - /** |
|
| 256 | - * The Timeline shortcode. |
|
| 257 | - */ |
|
| 258 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-wordlift-timeline-shortcode.php'; |
|
| 259 | - |
|
| 260 | - /** |
|
| 261 | - * The ShareThis service. |
|
| 262 | - */ |
|
| 263 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-wordlift-sharethis-service.php'; |
|
| 264 | - |
|
| 265 | - $this->loader = new Wordlift_Loader(); |
|
| 266 | - |
|
| 267 | - // Instantiate a global logger. |
|
| 268 | - global $wl_logger; |
|
| 269 | - $wl_logger = Wordlift_Log_Service::get_logger( 'WordLift' ); |
|
| 270 | - |
|
| 271 | - // Create an instance of the UI service. |
|
| 272 | - $this->ui_service = new Wordlift_UI_Service(); |
|
| 273 | - |
|
| 274 | - // Create an instance of the Thumbnail service. Later it'll be hooked to post meta events. |
|
| 275 | - $this->thumbnail_service = new Wordlift_Thumbnail_Service(); |
|
| 276 | - |
|
| 277 | - // Create an instance of the Schema service. |
|
| 278 | - new Wordlift_Schema_Service(); |
|
| 279 | - |
|
| 280 | - // Create an instance of the Entity service, passing the UI service to draw parts of the Entity admin page. |
|
| 281 | - $this->entity_service = new Wordlift_Entity_Service( $this->ui_service ); |
|
| 282 | - |
|
| 283 | - // Create an instance of the User service. |
|
| 284 | - $this->user_service = new Wordlift_User_Service(); |
|
| 285 | - |
|
| 286 | - // Create a new instance of the Timeline service and Timeline shortcode. |
|
| 287 | - $this->timeline_service = new Wordlift_Timeline_Service( $this->entity_service ); |
|
| 288 | - |
|
| 289 | - // Create a new instance of the Redirect service. |
|
| 290 | - $this->redirect_service = new Wordlift_Redirect_Service( $this->entity_service ); |
|
| 291 | - |
|
| 292 | - // Create an instance of the Timeline shortcode. |
|
| 293 | - new Wordlift_Timeline_Shortcode(); |
|
| 294 | - |
|
| 295 | - $this->entity_types_taxonomy_walker = new Wordlift_Entity_Types_Taxonomy_Walker(); |
|
| 296 | - |
|
| 297 | - // Create an instance of the ShareThis service, later we hook it to the_content and the_excerpt filters. |
|
| 298 | - $this->sharethis_service = new Wordlift_ShareThis_Service(); |
|
| 299 | - |
|
| 300 | - // Create an instance of the Notice service. |
|
| 301 | - new Wordlift_Notice_Service(); |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - /** |
|
| 305 | - * Define the locale for this plugin for internationalization. |
|
| 306 | - * |
|
| 307 | - * Uses the Wordlift_i18n class in order to set the domain and to register the hook |
|
| 308 | - * with WordPress. |
|
| 309 | - * |
|
| 310 | - * @since 1.0.0 |
|
| 311 | - * @access private |
|
| 312 | - */ |
|
| 313 | - private function set_locale() { |
|
| 314 | - |
|
| 315 | - $plugin_i18n = new Wordlift_i18n(); |
|
| 316 | - $plugin_i18n->set_domain( $this->get_plugin_name() ); |
|
| 317 | - |
|
| 318 | - $this->loader->add_action( 'plugins_loaded', $plugin_i18n, 'load_plugin_textdomain' ); |
|
| 319 | - |
|
| 320 | - } |
|
| 321 | - |
|
| 322 | - /** |
|
| 323 | - * Register all of the hooks related to the admin area functionality |
|
| 324 | - * of the plugin. |
|
| 325 | - * |
|
| 326 | - * @since 1.0.0 |
|
| 327 | - * @access private |
|
| 328 | - */ |
|
| 329 | - private function define_admin_hooks() { |
|
| 330 | - |
|
| 331 | - $plugin_admin = new Wordlift_Admin( $this->get_plugin_name(), $this->get_version() ); |
|
| 332 | - |
|
| 333 | - $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' ); |
|
| 334 | - $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' ); |
|
| 335 | - |
|
| 336 | - // Hook the deleted_post_meta action to the Thumbnail service. |
|
| 337 | - $this->loader->add_action( 'deleted_post_meta', $this->thumbnail_service, 'deleted_post_meta', 10, 4 ); |
|
| 338 | - |
|
| 339 | - // Hook the added_post_meta action to the Thumbnail service. |
|
| 340 | - $this->loader->add_action( 'added_post_meta', $this->thumbnail_service, 'added_post_meta', 10, 4 ); |
|
| 341 | - |
|
| 342 | - // Hook posts inserts (or updates) to the user service. |
|
| 343 | - $this->loader->add_action( 'wp_insert_post', $this->user_service, 'wp_insert_post', 10, 3 ); |
|
| 344 | - |
|
| 345 | - // Hook the AJAX wl_timeline action to the Timeline service. |
|
| 346 | - $this->loader->add_action( 'wp_ajax_wl_timeline', $this->timeline_service, 'ajax_timeline' ); |
|
| 347 | - |
|
| 348 | - // Register custom allowed redirect hosts. |
|
| 349 | - $this->loader->add_filter( 'allowed_redirect_hosts' , $this->redirect_service, 'allowed_redirect_hosts' ); |
|
| 350 | - // Hook the AJAX wordlift_redirect action to the Redirect service. |
|
| 351 | - $this->loader->add_action( 'wp_ajax_wordlift_redirect', $this->redirect_service, 'ajax_redirect' ); |
|
| 352 | - |
|
| 353 | - // Hook save_post to the entity service to update custom fields (such as alternate labels). |
|
| 354 | - // We have a priority of 9 because we want to be executed before data is sent to Redlink. |
|
| 355 | - $this->loader->add_action( 'save_post', $this->entity_service, 'save_post', 9, 3 ); |
|
| 356 | - $this->loader->add_action( 'edit_form_before_permalink', $this->entity_service, 'edit_form_before_permalink', 10, 1 ); |
|
| 357 | - |
|
| 358 | - $this->loader->add_filter( 'wp_terms_checklist_args', $this->entity_types_taxonomy_walker, 'terms_checklist_args' ); |
|
| 359 | - |
|
| 360 | - } |
|
| 361 | - |
|
| 362 | - /** |
|
| 363 | - * Register all of the hooks related to the public-facing functionality |
|
| 364 | - * of the plugin. |
|
| 365 | - * |
|
| 366 | - * @since 1.0.0 |
|
| 367 | - * @access private |
|
| 368 | - */ |
|
| 369 | - private function define_public_hooks() { |
|
| 370 | - |
|
| 371 | - $plugin_public = new Wordlift_Public( $this->get_plugin_name(), $this->get_version() ); |
|
| 372 | - |
|
| 373 | - $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_styles' ); |
|
| 374 | - $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts' ); |
|
| 375 | - |
|
| 376 | - // Hook the AJAX wl_timeline action to the Timeline service. |
|
| 377 | - $this->loader->add_action( 'wp_ajax_nopriv_wl_timeline', $this->timeline_service, 'ajax_timeline' ); |
|
| 378 | - |
|
| 379 | - // Hook the ShareThis service. |
|
| 380 | - $this->loader->add_filter( 'the_content', $this->sharethis_service, 'the_content', 99 ); |
|
| 381 | - $this->loader->add_filter( 'the_excerpt', $this->sharethis_service, 'the_excerpt', 99 ); |
|
| 382 | - } |
|
| 383 | - |
|
| 384 | - /** |
|
| 385 | - * Run the loader to execute all of the hooks with WordPress. |
|
| 386 | - * |
|
| 387 | - * @since 1.0.0 |
|
| 388 | - */ |
|
| 389 | - public function run() { |
|
| 390 | - $this->loader->run(); |
|
| 391 | - } |
|
| 392 | - |
|
| 393 | - /** |
|
| 394 | - * The name of the plugin used to uniquely identify it within the context of |
|
| 395 | - * WordPress and to define internationalization functionality. |
|
| 396 | - * |
|
| 397 | - * @since 1.0.0 |
|
| 398 | - * @return string The name of the plugin. |
|
| 399 | - */ |
|
| 400 | - public function get_plugin_name() { |
|
| 401 | - return $this->plugin_name; |
|
| 402 | - } |
|
| 403 | - |
|
| 404 | - /** |
|
| 405 | - * The reference to the class that orchestrates the hooks with the plugin. |
|
| 406 | - * |
|
| 407 | - * @since 1.0.0 |
|
| 408 | - * @return Wordlift_Loader Orchestrates the hooks of the plugin. |
|
| 409 | - */ |
|
| 410 | - public function get_loader() { |
|
| 411 | - return $this->loader; |
|
| 412 | - } |
|
| 413 | - |
|
| 414 | - /** |
|
| 415 | - * Retrieve the version number of the plugin. |
|
| 416 | - * |
|
| 417 | - * @since 1.0.0 |
|
| 418 | - * @return string The version number of the plugin. |
|
| 419 | - */ |
|
| 420 | - public function get_version() { |
|
| 421 | - return $this->version; |
|
| 422 | - } |
|
| 32 | + /** |
|
| 33 | + * The loader that's responsible for maintaining and registering all hooks that power |
|
| 34 | + * the plugin. |
|
| 35 | + * |
|
| 36 | + * @since 1.0.0 |
|
| 37 | + * @access protected |
|
| 38 | + * @var Wordlift_Loader $loader Maintains and registers all hooks for the plugin. |
|
| 39 | + */ |
|
| 40 | + protected $loader; |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * The unique identifier of this plugin. |
|
| 44 | + * |
|
| 45 | + * @since 1.0.0 |
|
| 46 | + * @access protected |
|
| 47 | + * @var string $plugin_name The string used to uniquely identify this plugin. |
|
| 48 | + */ |
|
| 49 | + protected $plugin_name; |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * The current version of the plugin. |
|
| 53 | + * |
|
| 54 | + * @since 1.0.0 |
|
| 55 | + * @access protected |
|
| 56 | + * @var string $version The current version of the plugin. |
|
| 57 | + */ |
|
| 58 | + protected $version; |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * The Thumbnail service. |
|
| 62 | + * |
|
| 63 | + * @since 3.1.5 |
|
| 64 | + * @access private |
|
| 65 | + * @var \Wordlift_Thumbnail_Service $thumbnail_service The Thumbnail service. |
|
| 66 | + */ |
|
| 67 | + private $thumbnail_service; |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * The UI service. |
|
| 71 | + * |
|
| 72 | + * @since 3.2.0 |
|
| 73 | + * @access private |
|
| 74 | + * @var \Wordlift_UI_Service $ui_service The UI service. |
|
| 75 | + */ |
|
| 76 | + private $ui_service; |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * The Entity service. |
|
| 80 | + * |
|
| 81 | + * @since 3.1.0 |
|
| 82 | + * @access private |
|
| 83 | + * @var \Wordlift_Entity_Service $entity_service The Entity service. |
|
| 84 | + */ |
|
| 85 | + private $entity_service; |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * The User service. |
|
| 89 | + * |
|
| 90 | + * @since 3.1.7 |
|
| 91 | + * @access private |
|
| 92 | + * @var \Wordlift_User_Service $user_service The User service. |
|
| 93 | + */ |
|
| 94 | + private $user_service; |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * The Timeline service. |
|
| 98 | + * |
|
| 99 | + * @since 3.1.0 |
|
| 100 | + * @access private |
|
| 101 | + * @var \Wordlift_Timeline_Service $timeline_service The Timeline service. |
|
| 102 | + */ |
|
| 103 | + private $timeline_service; |
|
| 104 | + |
|
| 105 | + /** |
|
| 106 | + * The Redirect service. |
|
| 107 | + * |
|
| 108 | + * @since 3.2.0 |
|
| 109 | + * @access private |
|
| 110 | + * @var \Wordlift_Redirect_Service $redirect_service The Redirect service. |
|
| 111 | + */ |
|
| 112 | + private $redirect_service; |
|
| 113 | + |
|
| 114 | + /** |
|
| 115 | + * The Entity Types Taxonomy Walker. |
|
| 116 | + * |
|
| 117 | + * @since 3.1.0 |
|
| 118 | + * @access private |
|
| 119 | + * @var \Wordlift_Entity_Types_Taxonomy_Walker $entity_types_taxonomy_walker The Entity Types Taxonomy Walker |
|
| 120 | + */ |
|
| 121 | + private $entity_types_taxonomy_walker; |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * The ShareThis service. |
|
| 125 | + * |
|
| 126 | + * @since 3.2.0 |
|
| 127 | + * @access private |
|
| 128 | + * @var \Wordlift_ShareThis_Service $sharethis_service The ShareThis service. |
|
| 129 | + */ |
|
| 130 | + private $sharethis_service; |
|
| 131 | + |
|
| 132 | + /** |
|
| 133 | + * Define the core functionality of the plugin. |
|
| 134 | + * |
|
| 135 | + * Set the plugin name and the plugin version that can be used throughout the plugin. |
|
| 136 | + * Load the dependencies, define the locale, and set the hooks for the admin area and |
|
| 137 | + * the public-facing side of the site. |
|
| 138 | + * |
|
| 139 | + * @since 1.0.0 |
|
| 140 | + */ |
|
| 141 | + public function __construct() { |
|
| 142 | + |
|
| 143 | + $this->plugin_name = 'wordlift'; |
|
| 144 | + |
|
| 145 | + $this->version = '3.3.0-dev'; |
|
| 146 | + |
|
| 147 | + $this->load_dependencies(); |
|
| 148 | + $this->set_locale(); |
|
| 149 | + $this->define_admin_hooks(); |
|
| 150 | + $this->define_public_hooks(); |
|
| 151 | + |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + /** |
|
| 155 | + * Load the required dependencies for this plugin. |
|
| 156 | + * |
|
| 157 | + * Include the following files that make up the plugin: |
|
| 158 | + * |
|
| 159 | + * - Wordlift_Loader. Orchestrates the hooks of the plugin. |
|
| 160 | + * - Wordlift_i18n. Defines internationalization functionality. |
|
| 161 | + * - Wordlift_Admin. Defines all hooks for the admin area. |
|
| 162 | + * - Wordlift_Public. Defines all hooks for the public side of the site. |
|
| 163 | + * |
|
| 164 | + * Create an instance of the loader which will be used to register the hooks |
|
| 165 | + * with WordPress. |
|
| 166 | + * |
|
| 167 | + * @since 1.0.0 |
|
| 168 | + * @access private |
|
| 169 | + */ |
|
| 170 | + private function load_dependencies() { |
|
| 171 | + |
|
| 172 | + /** |
|
| 173 | + * The class responsible for orchestrating the actions and filters of the |
|
| 174 | + * core plugin. |
|
| 175 | + */ |
|
| 176 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-loader.php'; |
|
| 177 | + |
|
| 178 | + /** |
|
| 179 | + * The class responsible for defining internationalization functionality |
|
| 180 | + * of the plugin. |
|
| 181 | + */ |
|
| 182 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-i18n.php'; |
|
| 183 | + |
|
| 184 | + /** |
|
| 185 | + * The Redirect service. |
|
| 186 | + */ |
|
| 187 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-redirect-service.php'; |
|
| 188 | + |
|
| 189 | + /** |
|
| 190 | + * The Log service. |
|
| 191 | + */ |
|
| 192 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-log-service.php'; |
|
| 193 | + |
|
| 194 | + /** |
|
| 195 | + * The Query builder. |
|
| 196 | + */ |
|
| 197 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-query-builder.php'; |
|
| 198 | + |
|
| 199 | + /** |
|
| 200 | + * The Schema service. |
|
| 201 | + */ |
|
| 202 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-schema-service.php'; |
|
| 203 | + |
|
| 204 | + /** |
|
| 205 | + * The UI service. |
|
| 206 | + */ |
|
| 207 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-ui-service.php'; |
|
| 208 | + |
|
| 209 | + /** |
|
| 210 | + * The Thumbnail service. |
|
| 211 | + */ |
|
| 212 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-thumbnail-service.php'; |
|
| 213 | + |
|
| 214 | + /** |
|
| 215 | + * The Entity Types Taxonomy service. |
|
| 216 | + */ |
|
| 217 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-entity-types-taxonomy-service.php'; |
|
| 218 | + |
|
| 219 | + /** |
|
| 220 | + * The Entity service. |
|
| 221 | + */ |
|
| 222 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-entity-service.php'; |
|
| 223 | + |
|
| 224 | + /** |
|
| 225 | + * The User service. |
|
| 226 | + */ |
|
| 227 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-user-service.php'; |
|
| 228 | + |
|
| 229 | + /** |
|
| 230 | + * The Timeline service. |
|
| 231 | + */ |
|
| 232 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-timeline-service.php'; |
|
| 233 | + |
|
| 234 | + /** |
|
| 235 | + * The class responsible for defining all actions that occur in the admin area. |
|
| 236 | + */ |
|
| 237 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin.php'; |
|
| 238 | + |
|
| 239 | + /** |
|
| 240 | + * The Entity Types Taxonomy Walker (transforms checkboxes into radios). |
|
| 241 | + */ |
|
| 242 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-entity-types-taxonomy-walker.php'; |
|
| 243 | + |
|
| 244 | + /** |
|
| 245 | + * The Notice service. |
|
| 246 | + */ |
|
| 247 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-notice-service.php'; |
|
| 248 | + |
|
| 249 | + /** |
|
| 250 | + * The class responsible for defining all actions that occur in the public-facing |
|
| 251 | + * side of the site. |
|
| 252 | + */ |
|
| 253 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-wordlift-public.php'; |
|
| 254 | + |
|
| 255 | + /** |
|
| 256 | + * The Timeline shortcode. |
|
| 257 | + */ |
|
| 258 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-wordlift-timeline-shortcode.php'; |
|
| 259 | + |
|
| 260 | + /** |
|
| 261 | + * The ShareThis service. |
|
| 262 | + */ |
|
| 263 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-wordlift-sharethis-service.php'; |
|
| 264 | + |
|
| 265 | + $this->loader = new Wordlift_Loader(); |
|
| 266 | + |
|
| 267 | + // Instantiate a global logger. |
|
| 268 | + global $wl_logger; |
|
| 269 | + $wl_logger = Wordlift_Log_Service::get_logger( 'WordLift' ); |
|
| 270 | + |
|
| 271 | + // Create an instance of the UI service. |
|
| 272 | + $this->ui_service = new Wordlift_UI_Service(); |
|
| 273 | + |
|
| 274 | + // Create an instance of the Thumbnail service. Later it'll be hooked to post meta events. |
|
| 275 | + $this->thumbnail_service = new Wordlift_Thumbnail_Service(); |
|
| 276 | + |
|
| 277 | + // Create an instance of the Schema service. |
|
| 278 | + new Wordlift_Schema_Service(); |
|
| 279 | + |
|
| 280 | + // Create an instance of the Entity service, passing the UI service to draw parts of the Entity admin page. |
|
| 281 | + $this->entity_service = new Wordlift_Entity_Service( $this->ui_service ); |
|
| 282 | + |
|
| 283 | + // Create an instance of the User service. |
|
| 284 | + $this->user_service = new Wordlift_User_Service(); |
|
| 285 | + |
|
| 286 | + // Create a new instance of the Timeline service and Timeline shortcode. |
|
| 287 | + $this->timeline_service = new Wordlift_Timeline_Service( $this->entity_service ); |
|
| 288 | + |
|
| 289 | + // Create a new instance of the Redirect service. |
|
| 290 | + $this->redirect_service = new Wordlift_Redirect_Service( $this->entity_service ); |
|
| 291 | + |
|
| 292 | + // Create an instance of the Timeline shortcode. |
|
| 293 | + new Wordlift_Timeline_Shortcode(); |
|
| 294 | + |
|
| 295 | + $this->entity_types_taxonomy_walker = new Wordlift_Entity_Types_Taxonomy_Walker(); |
|
| 296 | + |
|
| 297 | + // Create an instance of the ShareThis service, later we hook it to the_content and the_excerpt filters. |
|
| 298 | + $this->sharethis_service = new Wordlift_ShareThis_Service(); |
|
| 299 | + |
|
| 300 | + // Create an instance of the Notice service. |
|
| 301 | + new Wordlift_Notice_Service(); |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + /** |
|
| 305 | + * Define the locale for this plugin for internationalization. |
|
| 306 | + * |
|
| 307 | + * Uses the Wordlift_i18n class in order to set the domain and to register the hook |
|
| 308 | + * with WordPress. |
|
| 309 | + * |
|
| 310 | + * @since 1.0.0 |
|
| 311 | + * @access private |
|
| 312 | + */ |
|
| 313 | + private function set_locale() { |
|
| 314 | + |
|
| 315 | + $plugin_i18n = new Wordlift_i18n(); |
|
| 316 | + $plugin_i18n->set_domain( $this->get_plugin_name() ); |
|
| 317 | + |
|
| 318 | + $this->loader->add_action( 'plugins_loaded', $plugin_i18n, 'load_plugin_textdomain' ); |
|
| 319 | + |
|
| 320 | + } |
|
| 321 | + |
|
| 322 | + /** |
|
| 323 | + * Register all of the hooks related to the admin area functionality |
|
| 324 | + * of the plugin. |
|
| 325 | + * |
|
| 326 | + * @since 1.0.0 |
|
| 327 | + * @access private |
|
| 328 | + */ |
|
| 329 | + private function define_admin_hooks() { |
|
| 330 | + |
|
| 331 | + $plugin_admin = new Wordlift_Admin( $this->get_plugin_name(), $this->get_version() ); |
|
| 332 | + |
|
| 333 | + $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' ); |
|
| 334 | + $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' ); |
|
| 335 | + |
|
| 336 | + // Hook the deleted_post_meta action to the Thumbnail service. |
|
| 337 | + $this->loader->add_action( 'deleted_post_meta', $this->thumbnail_service, 'deleted_post_meta', 10, 4 ); |
|
| 338 | + |
|
| 339 | + // Hook the added_post_meta action to the Thumbnail service. |
|
| 340 | + $this->loader->add_action( 'added_post_meta', $this->thumbnail_service, 'added_post_meta', 10, 4 ); |
|
| 341 | + |
|
| 342 | + // Hook posts inserts (or updates) to the user service. |
|
| 343 | + $this->loader->add_action( 'wp_insert_post', $this->user_service, 'wp_insert_post', 10, 3 ); |
|
| 344 | + |
|
| 345 | + // Hook the AJAX wl_timeline action to the Timeline service. |
|
| 346 | + $this->loader->add_action( 'wp_ajax_wl_timeline', $this->timeline_service, 'ajax_timeline' ); |
|
| 347 | + |
|
| 348 | + // Register custom allowed redirect hosts. |
|
| 349 | + $this->loader->add_filter( 'allowed_redirect_hosts' , $this->redirect_service, 'allowed_redirect_hosts' ); |
|
| 350 | + // Hook the AJAX wordlift_redirect action to the Redirect service. |
|
| 351 | + $this->loader->add_action( 'wp_ajax_wordlift_redirect', $this->redirect_service, 'ajax_redirect' ); |
|
| 352 | + |
|
| 353 | + // Hook save_post to the entity service to update custom fields (such as alternate labels). |
|
| 354 | + // We have a priority of 9 because we want to be executed before data is sent to Redlink. |
|
| 355 | + $this->loader->add_action( 'save_post', $this->entity_service, 'save_post', 9, 3 ); |
|
| 356 | + $this->loader->add_action( 'edit_form_before_permalink', $this->entity_service, 'edit_form_before_permalink', 10, 1 ); |
|
| 357 | + |
|
| 358 | + $this->loader->add_filter( 'wp_terms_checklist_args', $this->entity_types_taxonomy_walker, 'terms_checklist_args' ); |
|
| 359 | + |
|
| 360 | + } |
|
| 361 | + |
|
| 362 | + /** |
|
| 363 | + * Register all of the hooks related to the public-facing functionality |
|
| 364 | + * of the plugin. |
|
| 365 | + * |
|
| 366 | + * @since 1.0.0 |
|
| 367 | + * @access private |
|
| 368 | + */ |
|
| 369 | + private function define_public_hooks() { |
|
| 370 | + |
|
| 371 | + $plugin_public = new Wordlift_Public( $this->get_plugin_name(), $this->get_version() ); |
|
| 372 | + |
|
| 373 | + $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_styles' ); |
|
| 374 | + $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts' ); |
|
| 375 | + |
|
| 376 | + // Hook the AJAX wl_timeline action to the Timeline service. |
|
| 377 | + $this->loader->add_action( 'wp_ajax_nopriv_wl_timeline', $this->timeline_service, 'ajax_timeline' ); |
|
| 378 | + |
|
| 379 | + // Hook the ShareThis service. |
|
| 380 | + $this->loader->add_filter( 'the_content', $this->sharethis_service, 'the_content', 99 ); |
|
| 381 | + $this->loader->add_filter( 'the_excerpt', $this->sharethis_service, 'the_excerpt', 99 ); |
|
| 382 | + } |
|
| 383 | + |
|
| 384 | + /** |
|
| 385 | + * Run the loader to execute all of the hooks with WordPress. |
|
| 386 | + * |
|
| 387 | + * @since 1.0.0 |
|
| 388 | + */ |
|
| 389 | + public function run() { |
|
| 390 | + $this->loader->run(); |
|
| 391 | + } |
|
| 392 | + |
|
| 393 | + /** |
|
| 394 | + * The name of the plugin used to uniquely identify it within the context of |
|
| 395 | + * WordPress and to define internationalization functionality. |
|
| 396 | + * |
|
| 397 | + * @since 1.0.0 |
|
| 398 | + * @return string The name of the plugin. |
|
| 399 | + */ |
|
| 400 | + public function get_plugin_name() { |
|
| 401 | + return $this->plugin_name; |
|
| 402 | + } |
|
| 403 | + |
|
| 404 | + /** |
|
| 405 | + * The reference to the class that orchestrates the hooks with the plugin. |
|
| 406 | + * |
|
| 407 | + * @since 1.0.0 |
|
| 408 | + * @return Wordlift_Loader Orchestrates the hooks of the plugin. |
|
| 409 | + */ |
|
| 410 | + public function get_loader() { |
|
| 411 | + return $this->loader; |
|
| 412 | + } |
|
| 413 | + |
|
| 414 | + /** |
|
| 415 | + * Retrieve the version number of the plugin. |
|
| 416 | + * |
|
| 417 | + * @since 1.0.0 |
|
| 418 | + * @return string The version number of the plugin. |
|
| 419 | + */ |
|
| 420 | + public function get_version() { |
|
| 421 | + return $this->version; |
|
| 422 | + } |
|
| 423 | 423 | |
| 424 | 424 | } |