Completed
Push — develop ( 115b1c...53d398 )
by David
03:07
created
src/includes/class-wordlift-jsonld-service.php 1 patch
Indentation   +112 added lines, -112 removed lines patch added patch discarded remove patch
@@ -13,123 +13,123 @@
 block discarded – undo
13 13
  */
14 14
 class Wordlift_Jsonld_Service {
15 15
 
16
-	/**
17
-	 * A {@link Wordlift_Entity_Service} instance.
18
-	 *
19
-	 * @since  3.8.0
20
-	 * @access private
21
-	 * @var Wordlift_Entity_Service $entity_service A {@link Wordlift_Entity_Service} instance.
22
-	 */
23
-	private $entity_service;
24
-
25
-	/**
26
-	 * A {@link Wordlift_Entity_To_Jsonld_Converter} instance.
27
-	 *
28
-	 * @since  3.8.0
29
-	 * @access private
30
-	 * @var \Wordlift_Entity_Post_To_Jsonld_Converter A {@link Wordlift_Entity_To_Jsonld_Converter} instance.
31
-	 */
32
-	private $entity_to_jsonld_converter;
33
-
34
-	/**
35
-	 * Create a JSON-LD service.
36
-	 *
37
-	 * @since 3.8.0
38
-	 *
39
-	 * @param \Wordlift_Entity_Service                  $entity_service             A {@link Wordlift_Entity_Service} instance.
40
-	 * @param \Wordlift_Entity_Post_To_Jsonld_Converter $entity_to_jsonld_converter A {@link Wordlift_Entity_Post_To_Jsonld_Converter} instance.
41
-	 */
42
-	public function __construct( $entity_service, $entity_to_jsonld_converter ) {
43
-
44
-		$this->entity_service             = $entity_service;
45
-		$this->entity_to_jsonld_converter = $entity_to_jsonld_converter;
46
-
47
-		add_action( 'wp_footer', array( $this, 'wp_footer' ), PHP_INT_MAX );
48
-	}
49
-
50
-	/**
51
-	 * Hook to WP's wp_footer action and load the JSON-LD data.
52
-	 *
53
-	 * @since 3.8.0
54
-	 */
55
-	public function wp_footer() {
56
-
57
-		// We only care about singular pages.
58
-		if ( ! is_singular() ) {
59
-			return;
60
-		}
61
-
62
-		// Get the entities related to the current post (and that are published).
63
-		$post_id = get_the_ID();
64
-		$posts   = $this->entity_service->is_entity( $post_id )
65
-			? array( get_the_ID() )
66
-			: array_unique( wl_core_get_related_entity_ids( $post_id, array(
67
-				'status' => 'publish',
68
-			) ) );
69
-
70
-		// Build the URL to load the JSON-LD asynchronously.
71
-		$url            = admin_url( 'admin-ajax.php?action=wl_jsonld' );
72
-		$entity_service = $this->entity_service;
73
-		$data           = implode( '&', array_map( function ( $item ) use ( $entity_service ) {
74
-			return 'uri[]=' . rawurldecode( $entity_service->get_uri( $item ) );
75
-		}, $posts ) );
76
-
77
-		// Print the Javascript code.
78
-		echo <<<EOF
16
+    /**
17
+     * A {@link Wordlift_Entity_Service} instance.
18
+     *
19
+     * @since  3.8.0
20
+     * @access private
21
+     * @var Wordlift_Entity_Service $entity_service A {@link Wordlift_Entity_Service} instance.
22
+     */
23
+    private $entity_service;
24
+
25
+    /**
26
+     * A {@link Wordlift_Entity_To_Jsonld_Converter} instance.
27
+     *
28
+     * @since  3.8.0
29
+     * @access private
30
+     * @var \Wordlift_Entity_Post_To_Jsonld_Converter A {@link Wordlift_Entity_To_Jsonld_Converter} instance.
31
+     */
32
+    private $entity_to_jsonld_converter;
33
+
34
+    /**
35
+     * Create a JSON-LD service.
36
+     *
37
+     * @since 3.8.0
38
+     *
39
+     * @param \Wordlift_Entity_Service                  $entity_service             A {@link Wordlift_Entity_Service} instance.
40
+     * @param \Wordlift_Entity_Post_To_Jsonld_Converter $entity_to_jsonld_converter A {@link Wordlift_Entity_Post_To_Jsonld_Converter} instance.
41
+     */
42
+    public function __construct( $entity_service, $entity_to_jsonld_converter ) {
43
+
44
+        $this->entity_service             = $entity_service;
45
+        $this->entity_to_jsonld_converter = $entity_to_jsonld_converter;
46
+
47
+        add_action( 'wp_footer', array( $this, 'wp_footer' ), PHP_INT_MAX );
48
+    }
49
+
50
+    /**
51
+     * Hook to WP's wp_footer action and load the JSON-LD data.
52
+     *
53
+     * @since 3.8.0
54
+     */
55
+    public function wp_footer() {
56
+
57
+        // We only care about singular pages.
58
+        if ( ! is_singular() ) {
59
+            return;
60
+        }
61
+
62
+        // Get the entities related to the current post (and that are published).
63
+        $post_id = get_the_ID();
64
+        $posts   = $this->entity_service->is_entity( $post_id )
65
+            ? array( get_the_ID() )
66
+            : array_unique( wl_core_get_related_entity_ids( $post_id, array(
67
+                'status' => 'publish',
68
+            ) ) );
69
+
70
+        // Build the URL to load the JSON-LD asynchronously.
71
+        $url            = admin_url( 'admin-ajax.php?action=wl_jsonld' );
72
+        $entity_service = $this->entity_service;
73
+        $data           = implode( '&', array_map( function ( $item ) use ( $entity_service ) {
74
+            return 'uri[]=' . rawurldecode( $entity_service->get_uri( $item ) );
75
+        }, $posts ) );
76
+
77
+        // Print the Javascript code.
78
+        echo <<<EOF
79 79
 <script type="text/javascript"><!--
80 80
 (function($) { $( window ).on( 'load', function() { $.post('$url','$data').done(function(data) {
81 81
 	$('head').append( '<script type="application/ld+json">'+JSON.stringify(data)+'</s' + 'cript>' );
82 82
 }); }); })(jQuery);
83 83
 // --></script>
84 84
 EOF;
85
-	}
86
-
87
-	/**
88
-	 * Process calls to the AJAX 'wl_jsonld' endpoint.
89
-	 *
90
-	 * @since 3.8.0
91
-	 */
92
-	public function get() {
93
-
94
-		// Clear the buffer to be sure someone doesn't mess with our response.
95
-		//
96
-		// See https://github.com/insideout10/wordlift-plugin/issues/406.
97
-		// See https://codex.wordpress.org/AJAX_in_Plugins.
98
-		ob_clean();
99
-
100
-		// If no URI has been provided return an empty array.
101
-		if ( ! isset( $_REQUEST['uri'] ) ) {
102
-			wp_send_json( array() );
103
-		}
104
-
105
-		// Get an array of URIs to parse.
106
-		$uris = is_array( $_REQUEST['uri'] ) ? $_REQUEST['uri'] : array( $_REQUEST['uri'] );
107
-
108
-		// An array of references which is captured when converting an URI to a
109
-		// json which we gather to further expand our json-ld.
110
-		$references = array();
111
-
112
-		// Set a reference to the entity_to_jsonld_converter to use in the closures.
113
-		$entity_to_jsonld_converter = $this->entity_to_jsonld_converter;
114
-
115
-		// Convert each URI to a JSON-LD array, while gathering referenced entities.
116
-		// in the references array.
117
-		$jsonld = array_merge(
118
-			array_map( function ( $item ) use ( $entity_to_jsonld_converter, &$references ) {
119
-
120
-				return $entity_to_jsonld_converter->convert( $item, $references );
121
-			}, $uris ),
122
-			// Convert each URI in the references array to JSON-LD. We don't output
123
-			// entities already output above (hence the array_diff).
124
-			array_map( function ( $item ) use ( $entity_to_jsonld_converter, &$references ) {
125
-
126
-				return $entity_to_jsonld_converter->convert( $item, $references );
127
-			}, array_diff( $references, $uris ) )
128
-		);
129
-
130
-		// Finally send the JSON-LD.
131
-		wp_send_json( $jsonld );
132
-
133
-	}
85
+    }
86
+
87
+    /**
88
+     * Process calls to the AJAX 'wl_jsonld' endpoint.
89
+     *
90
+     * @since 3.8.0
91
+     */
92
+    public function get() {
93
+
94
+        // Clear the buffer to be sure someone doesn't mess with our response.
95
+        //
96
+        // See https://github.com/insideout10/wordlift-plugin/issues/406.
97
+        // See https://codex.wordpress.org/AJAX_in_Plugins.
98
+        ob_clean();
99
+
100
+        // If no URI has been provided return an empty array.
101
+        if ( ! isset( $_REQUEST['uri'] ) ) {
102
+            wp_send_json( array() );
103
+        }
104
+
105
+        // Get an array of URIs to parse.
106
+        $uris = is_array( $_REQUEST['uri'] ) ? $_REQUEST['uri'] : array( $_REQUEST['uri'] );
107
+
108
+        // An array of references which is captured when converting an URI to a
109
+        // json which we gather to further expand our json-ld.
110
+        $references = array();
111
+
112
+        // Set a reference to the entity_to_jsonld_converter to use in the closures.
113
+        $entity_to_jsonld_converter = $this->entity_to_jsonld_converter;
114
+
115
+        // Convert each URI to a JSON-LD array, while gathering referenced entities.
116
+        // in the references array.
117
+        $jsonld = array_merge(
118
+            array_map( function ( $item ) use ( $entity_to_jsonld_converter, &$references ) {
119
+
120
+                return $entity_to_jsonld_converter->convert( $item, $references );
121
+            }, $uris ),
122
+            // Convert each URI in the references array to JSON-LD. We don't output
123
+            // entities already output above (hence the array_diff).
124
+            array_map( function ( $item ) use ( $entity_to_jsonld_converter, &$references ) {
125
+
126
+                return $entity_to_jsonld_converter->convert( $item, $references );
127
+            }, array_diff( $references, $uris ) )
128
+        );
129
+
130
+        // Finally send the JSON-LD.
131
+        wp_send_json( $jsonld );
132
+
133
+    }
134 134
 
135 135
 }
Please login to merge, or discard this patch.
src/modules/linked_data/wordlift_linked_data.php 2 patches
Indentation   +320 added lines, -320 removed lines patch added patch discarded remove patch
@@ -14,19 +14,19 @@  discard block
 block discarded – undo
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,143 +40,143 @@  discard block
 block discarded – undo
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
-	}
43
+    // Ignore auto-saves
44
+    if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
45
+        return;
46
+    }
47 47
 
48
-	// get the current post.
49
-	$post = get_post( $post_id );
48
+    // get the current post.
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
-	// wl_write_log( "[ post id :: $post_id ][ autosave :: false ][ post type :: $post->post_type ]" );
53
+    // wl_write_log( "[ post id :: $post_id ][ autosave :: false ][ post type :: $post->post_type ]" );
54 54
 
55
-	// Store mapping between tmp new entities uris and real new entities uri
56
-	$entities_uri_mapping = array();
55
+    // Store mapping between tmp new entities uris and real new entities uri
56
+    $entities_uri_mapping = array();
57 57
 
58
-	// Save the entities coming with POST data.
59
-	if ( isset( $_POST['wl_entities'] ) && isset( $_POST['wl_boxes'] ) ) {
58
+    // Save the entities coming with POST data.
59
+    if ( isset( $_POST['wl_entities'] ) && isset( $_POST['wl_boxes'] ) ) {
60 60
 
61
-		wl_write_log( "[ post id :: $post_id ][ POST(wl_entities) :: " );
62
-		wl_write_log( json_encode( $_POST['wl_entities'] ) );
63
-		wl_write_log( "]" );
64
-		wl_write_log( "[ post id :: $post_id ][ POST(wl_boxes) :: " );
65
-		wl_write_log( json_encode( $_POST['wl_boxes'], true ) );
66
-		wl_write_log( "]" );
61
+        wl_write_log( "[ post id :: $post_id ][ POST(wl_entities) :: " );
62
+        wl_write_log( json_encode( $_POST['wl_entities'] ) );
63
+        wl_write_log( "]" );
64
+        wl_write_log( "[ post id :: $post_id ][ POST(wl_boxes) :: " );
65
+        wl_write_log( json_encode( $_POST['wl_boxes'], true ) );
66
+        wl_write_log( "]" );
67 67
 
68
-		$entities_via_post = $_POST['wl_entities'];
69
-		$boxes_via_post    = $_POST['wl_boxes'];
68
+        $entities_via_post = $_POST['wl_entities'];
69
+        $boxes_via_post    = $_POST['wl_boxes'];
70 70
 
71
-		foreach ( $entities_via_post as $entity_uri => $entity ) {
71
+        foreach ( $entities_via_post as $entity_uri => $entity ) {
72 72
 
73
-			// Only if the current entity is created from scratch let's avoid to create 
74
-			// more than one entity with same label & entity type
75
-			$entity_type = ( preg_match( '/^local-entity-.+/', $entity_uri ) > 0 ) ?
76
-				$entity[ 'main_type' ] : NULL;
73
+            // Only if the current entity is created from scratch let's avoid to create 
74
+            // more than one entity with same label & entity type
75
+            $entity_type = ( preg_match( '/^local-entity-.+/', $entity_uri ) > 0 ) ?
76
+                $entity[ 'main_type' ] : NULL;
77 77
 
78
-			// Look if current entity uri matchs an internal existing entity, meaning:
79
-			// 1. when $entity_uri is an internal uri 
80
-			// 2. when $entity_uri is an external uri used as sameAs of an internal entity	
81
-			$ie = Wordlift_Entity_Service::get_instance()->get_entity_post_by_uri( $entity_uri );
78
+            // Look if current entity uri matchs an internal existing entity, meaning:
79
+            // 1. when $entity_uri is an internal uri 
80
+            // 2. when $entity_uri is an external uri used as sameAs of an internal entity	
81
+            $ie = Wordlift_Entity_Service::get_instance()->get_entity_post_by_uri( $entity_uri );
82 82
 
83
-			// Detect the uri depending if is an existing or a new entity
84
-			$uri = ( NULL === $ie ) ?
85
-				Wordlift_Entity_Service::get_instance()->build_uri(
86
-					$entity[ 'label' ],
87
-					Wordlift_Entity_Service::TYPE_NAME,
88
-					$entity_type
89
-				) : wl_get_entity_uri( $ie->ID );
83
+            // Detect the uri depending if is an existing or a new entity
84
+            $uri = ( NULL === $ie ) ?
85
+                Wordlift_Entity_Service::get_instance()->build_uri(
86
+                    $entity[ 'label' ],
87
+                    Wordlift_Entity_Service::TYPE_NAME,
88
+                    $entity_type
89
+                ) : wl_get_entity_uri( $ie->ID );
90 90
 
91
-			wl_write_log("Map $entity_uri on $uri");
92
-			$entities_uri_mapping[ $entity_uri ] = $uri;
91
+            wl_write_log("Map $entity_uri on $uri");
92
+            $entities_uri_mapping[ $entity_uri ] = $uri;
93 93
 
94
-			// Local entities have a tmp uri with 'local-entity-' prefix
95
-			// These uris need to be rewritten here and replaced in the content
96
-			if ( preg_match( '/^local-entity-.+/', $entity_uri ) > 0 ) {
97
-				// Override the entity obj
98
-				$entity[ 'uri' ] = $uri;
99
-			}
94
+            // Local entities have a tmp uri with 'local-entity-' prefix
95
+            // These uris need to be rewritten here and replaced in the content
96
+            if ( preg_match( '/^local-entity-.+/', $entity_uri ) > 0 ) {
97
+                // Override the entity obj
98
+                $entity[ 'uri' ] = $uri;
99
+            }
100 100
 
101
-			// Update entity data with related post
102
-			$entity[ 'related_post_id' ] = $post_id;
101
+            // Update entity data with related post
102
+            $entity[ 'related_post_id' ] = $post_id;
103 103
 
104
-			// Save the entity if is a new entity
105
-			if ( NULL === $ie ) {
106
-				wl_save_entity( $entity );
107
-			}
104
+            // Save the entity if is a new entity
105
+            if ( NULL === $ie ) {
106
+                wl_save_entity( $entity );
107
+            }
108 108
 
109
-		}
109
+        }
110 110
 
111
-	}
111
+    }
112 112
 
113
-	// Replace tmp uris in content post if needed
114
-	$updated_post_content = $post->post_content;
115
-	// Save each entity and store the post id.
116
-	foreach ( $entities_uri_mapping as $tmp_uri => $uri ) {
117
-		$updated_post_content = str_replace( $tmp_uri, $uri, $updated_post_content );
118
-	}
113
+    // Replace tmp uris in content post if needed
114
+    $updated_post_content = $post->post_content;
115
+    // Save each entity and store the post id.
116
+    foreach ( $entities_uri_mapping as $tmp_uri => $uri ) {
117
+        $updated_post_content = str_replace( $tmp_uri, $uri, $updated_post_content );
118
+    }
119 119
 
120
-	// Update the post content
121
-	wp_update_post( array(
122
-		'ID'           => $post->ID,
123
-		'post_content' => $updated_post_content,
124
-	) );
120
+    // Update the post content
121
+    wp_update_post( array(
122
+        'ID'           => $post->ID,
123
+        'post_content' => $updated_post_content,
124
+    ) );
125 125
 
126
-	// Extract related/referenced entities from text.
127
-	$disambiguated_entities = wl_linked_data_content_get_embedded_entities( $updated_post_content );
126
+    // Extract related/referenced entities from text.
127
+    $disambiguated_entities = wl_linked_data_content_get_embedded_entities( $updated_post_content );
128 128
 
129
-	// Reset previously saved instances
130
-	wl_core_delete_relation_instances( $post_id );
129
+    // Reset previously saved instances
130
+    wl_core_delete_relation_instances( $post_id );
131 131
 
132
-	// Save relation instances
133
-	foreach ( array_unique( $disambiguated_entities ) as $referenced_entity_id ) {
132
+    // Save relation instances
133
+    foreach ( array_unique( $disambiguated_entities ) as $referenced_entity_id ) {
134 134
 
135
-		wl_core_add_relation_instance(
136
-			$post_id,
137
-			Wordlift_Entity_Service::get_instance()->get_classification_scope_for( $referenced_entity_id ),
138
-			$referenced_entity_id
139
-		);
135
+        wl_core_add_relation_instance(
136
+            $post_id,
137
+            Wordlift_Entity_Service::get_instance()->get_classification_scope_for( $referenced_entity_id ),
138
+            $referenced_entity_id
139
+        );
140 140
 
141
-	}
141
+    }
142 142
 
143 143
     if ( isset( $_POST['wl_entities'] ) ) {
144
-		// Save post metadata if available
145
-		$metadata_via_post    =  ( isset( $_POST['wl_metadata'] ) ) ?
146
-			$_POST['wl_metadata'] : array();
147
-
148
-		$fields = array(
149
-			Wordlift_Schema_Service::FIELD_LOCATION_CREATED,
150
-			Wordlift_Schema_Service::FIELD_TOPIC
151
-		);
152
-
153
-		// Unlink topic taxonomy terms
154
-		Wordlift_Topic_Taxonomy_Service::get_instance()->unlink_topic_for( $post->ID );
155
-
156
-		foreach ( $fields as $field ) {
157
-
158
-			// Delete current values
159
-			delete_post_meta( $post->ID, $field );
160
-			// Retrieve the entity uri
161
-			$uri 	= ( isset( $metadata_via_post[ $field ] ) ) ?
162
-				stripslashes( $metadata_via_post[ $field ] ) : '';
163
-
164
-			$entity = Wordlift_Entity_Service::get_instance()->get_entity_post_by_uri( $uri );
165
-
166
-			if ( $entity ) {
167
-				add_post_meta( $post->ID, $field, $entity->ID, true );
168
-				// Set also the topic taxonomy
169
-				if ( $field === Wordlift_Schema_Service::FIELD_TOPIC ) {
170
-					Wordlift_Topic_Taxonomy_Service::get_instance()->set_topic_for( $post->ID, $entity );
171
-				}
172
-			}
173
-		}
174
-	}
175
-
176
-	// Push the post to Redlink.
177
-	wl_linked_data_push_to_redlink( $post->ID );
178
-
179
-	add_action( 'wl_linked_data_save_post', 'wl_linked_data_save_post_and_related_entities' );
144
+        // Save post metadata if available
145
+        $metadata_via_post    =  ( isset( $_POST['wl_metadata'] ) ) ?
146
+            $_POST['wl_metadata'] : array();
147
+
148
+        $fields = array(
149
+            Wordlift_Schema_Service::FIELD_LOCATION_CREATED,
150
+            Wordlift_Schema_Service::FIELD_TOPIC
151
+        );
152
+
153
+        // Unlink topic taxonomy terms
154
+        Wordlift_Topic_Taxonomy_Service::get_instance()->unlink_topic_for( $post->ID );
155
+
156
+        foreach ( $fields as $field ) {
157
+
158
+            // Delete current values
159
+            delete_post_meta( $post->ID, $field );
160
+            // Retrieve the entity uri
161
+            $uri 	= ( isset( $metadata_via_post[ $field ] ) ) ?
162
+                stripslashes( $metadata_via_post[ $field ] ) : '';
163
+
164
+            $entity = Wordlift_Entity_Service::get_instance()->get_entity_post_by_uri( $uri );
165
+
166
+            if ( $entity ) {
167
+                add_post_meta( $post->ID, $field, $entity->ID, true );
168
+                // Set also the topic taxonomy
169
+                if ( $field === Wordlift_Schema_Service::FIELD_TOPIC ) {
170
+                    Wordlift_Topic_Taxonomy_Service::get_instance()->set_topic_for( $post->ID, $entity );
171
+                }
172
+            }
173
+        }
174
+    }
175
+
176
+    // Push the post to Redlink.
177
+    wl_linked_data_push_to_redlink( $post->ID );
178
+
179
+    add_action( 'wl_linked_data_save_post', 'wl_linked_data_save_post_and_related_entities' );
180 180
 }
181 181
 
182 182
 add_action( 'wl_linked_data_save_post', 'wl_linked_data_save_post_and_related_entities' );
@@ -186,13 +186,13 @@  discard block
 block discarded – undo
186 186
  */
187 187
 function wordlift_save_post_add_default_schema_type( $entity_id ) {
188 188
 
189
-	$entity      = get_post( $entity_id );
190
-	$entity_type = wl_schema_get_types( $entity_id );
189
+    $entity      = get_post( $entity_id );
190
+    $entity_type = wl_schema_get_types( $entity_id );
191 191
 
192
-	// Assign type 'Thing' if we are dealing with an entity without type
193
-	if ( $entity->post_type == Wordlift_Entity_Service::TYPE_NAME && is_null( $entity_type ) ) {
194
-		wl_schema_set_types( $entity_id, 'Thing' );
195
-	}
192
+    // Assign type 'Thing' if we are dealing with an entity without type
193
+    if ( $entity->post_type == Wordlift_Entity_Service::TYPE_NAME && is_null( $entity_type ) ) {
194
+        wl_schema_set_types( $entity_id, 'Thing' );
195
+    }
196 196
 
197 197
 }
198 198
 
@@ -218,166 +218,166 @@  discard block
 block discarded – undo
218 218
  */
219 219
 function wl_save_entity( $entity_data ) {
220 220
 
221
-	$uri              = $entity_data['uri'];
222
-	$label            = $entity_data['label'];
223
-	$type_uri         = $entity_data['main_type'];
224
-	$entity_types     = isset( $entity_data['type'] ) ? $entity_data['type'] : array();
225
-	$description      = $entity_data['description'];
226
-	$images           = isset( $entity_data['image'] ) ? wl_force_to_array( $entity_data['image'] ) : array();
227
-	$same_as          = isset( $entity_data['sameas'] ) ? wl_force_to_array( $entity_data['sameas'] ) : array();
228
-	$related_post_id  = isset( $entity_data['related_post_id'] ) ? $entity_data['related_post_id'] : null;
229
-	$other_properties = isset( $entity_data['properties'] ) ? $entity_data['properties'] : array();
230
-
231
-	// wl_write_log( "[ uri :: $uri ][ label :: $label ][ type uri :: $type_uri ]" );
232
-
233
-	// Prepare properties of the new entity.
234
-	$params = array(
235
-		'post_status'  => ( is_numeric( $related_post_id ) ? get_post_status( $related_post_id ) : 'draft' ),
236
-		'post_type'    => Wordlift_Entity_Service::TYPE_NAME,
237
-		'post_title'   => $label,
238
-		'post_content' => $description,
239
-		'post_excerpt' => ''
240
-	);
241
-
242
-	// Check whether an entity already exists with the provided URI.
243
-	$post = Wordlift_Entity_Service::get_instance()->get_entity_post_by_uri( $uri );
244
-
245
-	if ( null !== $post ) {
246
-		return $post;
247
-	}
248
-
249
-	// If Yoast is installed and active, we temporary remove the save_postdata hook which causes Yoast to "pass over"
250
-	// the local SEO form values to the created entity (https://github.com/insideout10/wordlift-plugin/issues/156)
251
-	// Same thing applies to SEO Ultimate (https://github.com/insideout10/wordlift-plugin/issues/148)
252
-	// This does NOT affect saving an entity from the entity admin page since this function is called when an entity
253
-	// is created when saving a post.
254
-	global $wpseo_metabox, $seo_ultimate;
255
-	if ( isset( $wpseo_metabox ) ) {
256
-		remove_action( 'wp_insert_post', array( $wpseo_metabox, 'save_postdata' ) );
257
-	}
258
-
259
-	if ( isset( $seo_ultimate ) ) {
260
-		remove_action( 'save_post', array( $seo_ultimate, 'save_postmeta_box' ) );
261
-	}
262
-
263
-	// The fact that we're calling here wp_insert_post is causing issues with plugins (and ourselves too) that hook to
264
-	// save_post in order to save additional inputs from the edit page. In order to avoid issues, we pop all the hooks
265
-	// to the save_post and restore them after we saved the entity.
266
-	// see https://github.com/insideout10/wordlift-plugin/issues/203
267
-	// see https://github.com/insideout10/wordlift-plugin/issues/156
268
-	// see https://github.com/insideout10/wordlift-plugin/issues/148
269
-	global $wp_filter;
270
-	$save_post_filters = is_array( $wp_filter['save_post'] ) ? $wp_filter['save_post'] : $wp_filter['save_post']->callbacks;
271
-	is_array( $wp_filter['save_post'] ) ? $wp_filter['save_post'] = array() : $wp_filter['save_post']->remove_all_filters();
272
-
273
-	// create or update the post.
274
-	$post_id = wp_insert_post( $params, TRUE );
275
-
276
-	// Restore all the existing filters.
277
-	is_array( $wp_filter['save_post'] ) ? $wp_filter['save_post'] = $save_post_filters : $wp_filter['save_post']->callbacks = $save_post_filters;
278
-
279
-	// If Yoast is installed and active, we restore the Yoast save_postdata hook (https://github.com/insideout10/wordlift-plugin/issues/156)
280
-	if ( isset( $wpseo_metabox ) ) {
281
-		add_action( 'wp_insert_post', array( $wpseo_metabox, 'save_postdata' ) );
282
-	}
283
-
284
-	// If SEO Ultimate is installed, add back the hook we removed a few lines above.
285
-	if ( isset( $seo_ultimate ) ) {
286
-		add_action( 'save_post', array( $seo_ultimate, 'save_postmeta_box' ), 10, 2 );
287
-	}
288
-
289
-	// TODO: handle errors.
290
-	if ( is_wp_error( $post_id ) ) {
291
-		wl_write_log( ': error occurred' );
292
-
293
-		// inform an error occurred.
294
-		return null;
295
-	}
296
-
297
-	wl_set_entity_main_type( $post_id, $type_uri );
298
-
299
-	// Save the entity types.
300
-	wl_set_entity_rdf_types( $post_id, $entity_types );
301
-
302
-	// Get a dataset URI for the entity.
303
-	$wl_uri = wl_build_entity_uri( $post_id );
304
-
305
-	// Save the entity URI.
306
-	wl_set_entity_uri( $post_id, $wl_uri );
307
-
308
-	// Add the uri to the sameAs data if it's not a local URI.
309
-	if ( $wl_uri !== $uri ) {
310
-		array_push( $same_as, $uri );
311
-	}
312
-
313
-	$new_uri = wl_get_entity_uri( $post_id );
314
-
315
-	// Save the sameAs data for the entity.
316
-	wl_schema_set_value( $post_id, 'sameAs', $same_as );
317
-
318
-	// Save the other properties (latitude, langitude, startDate, endDate, etc.)
319
-	foreach ( $other_properties as $property_name => $property_value ) {
320
-		wl_schema_set_value( $post_id, $property_name, $property_value );
321
-	}
322
-
323
-	// Call hooks.
324
-	do_action( 'wl_save_entity', $post_id );
325
-
326
-	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 ) . " ]" );
327
-
328
-	foreach ( $images as $image_remote_url ) {
329
-
330
-		// Check if image is already present in local DB
331
-		if ( strpos( $image_remote_url, site_url() ) !== false ) {
332
-			// Do nothing.
333
-			continue;
334
-		}
335
-
336
-		// Check if there is an existing attachment for this post ID and source URL.
337
-		$existing_image = wl_get_attachment_for_source_url( $post_id, $image_remote_url );
338
-
339
-		// Skip if an existing image is found.
340
-		if ( null !== $existing_image ) {
341
-			continue;
342
-		}
343
-
344
-		// Save the image and get the local path.
345
-		$image = wl_save_image( $image_remote_url );
346
-
347
-		// Get the local URL.
348
-		$filename     = $image['path'];
349
-		$url          = $image['url'];
350
-		$content_type = $image['content_type'];
351
-
352
-		$attachment = array(
353
-			'guid'           => $url,
354
-			// post_title, post_content (the value for this key should be the empty string), post_status and post_mime_type
355
-			'post_title'     => $label,
356
-			// Set the title to the post title.
357
-			'post_content'   => '',
358
-			'post_status'    => 'inherit',
359
-			'post_mime_type' => $content_type
360
-		);
221
+    $uri              = $entity_data['uri'];
222
+    $label            = $entity_data['label'];
223
+    $type_uri         = $entity_data['main_type'];
224
+    $entity_types     = isset( $entity_data['type'] ) ? $entity_data['type'] : array();
225
+    $description      = $entity_data['description'];
226
+    $images           = isset( $entity_data['image'] ) ? wl_force_to_array( $entity_data['image'] ) : array();
227
+    $same_as          = isset( $entity_data['sameas'] ) ? wl_force_to_array( $entity_data['sameas'] ) : array();
228
+    $related_post_id  = isset( $entity_data['related_post_id'] ) ? $entity_data['related_post_id'] : null;
229
+    $other_properties = isset( $entity_data['properties'] ) ? $entity_data['properties'] : array();
230
+
231
+    // wl_write_log( "[ uri :: $uri ][ label :: $label ][ type uri :: $type_uri ]" );
232
+
233
+    // Prepare properties of the new entity.
234
+    $params = array(
235
+        'post_status'  => ( is_numeric( $related_post_id ) ? get_post_status( $related_post_id ) : 'draft' ),
236
+        'post_type'    => Wordlift_Entity_Service::TYPE_NAME,
237
+        'post_title'   => $label,
238
+        'post_content' => $description,
239
+        'post_excerpt' => ''
240
+    );
241
+
242
+    // Check whether an entity already exists with the provided URI.
243
+    $post = Wordlift_Entity_Service::get_instance()->get_entity_post_by_uri( $uri );
244
+
245
+    if ( null !== $post ) {
246
+        return $post;
247
+    }
248
+
249
+    // If Yoast is installed and active, we temporary remove the save_postdata hook which causes Yoast to "pass over"
250
+    // the local SEO form values to the created entity (https://github.com/insideout10/wordlift-plugin/issues/156)
251
+    // Same thing applies to SEO Ultimate (https://github.com/insideout10/wordlift-plugin/issues/148)
252
+    // This does NOT affect saving an entity from the entity admin page since this function is called when an entity
253
+    // is created when saving a post.
254
+    global $wpseo_metabox, $seo_ultimate;
255
+    if ( isset( $wpseo_metabox ) ) {
256
+        remove_action( 'wp_insert_post', array( $wpseo_metabox, 'save_postdata' ) );
257
+    }
258
+
259
+    if ( isset( $seo_ultimate ) ) {
260
+        remove_action( 'save_post', array( $seo_ultimate, 'save_postmeta_box' ) );
261
+    }
262
+
263
+    // The fact that we're calling here wp_insert_post is causing issues with plugins (and ourselves too) that hook to
264
+    // save_post in order to save additional inputs from the edit page. In order to avoid issues, we pop all the hooks
265
+    // to the save_post and restore them after we saved the entity.
266
+    // see https://github.com/insideout10/wordlift-plugin/issues/203
267
+    // see https://github.com/insideout10/wordlift-plugin/issues/156
268
+    // see https://github.com/insideout10/wordlift-plugin/issues/148
269
+    global $wp_filter;
270
+    $save_post_filters = is_array( $wp_filter['save_post'] ) ? $wp_filter['save_post'] : $wp_filter['save_post']->callbacks;
271
+    is_array( $wp_filter['save_post'] ) ? $wp_filter['save_post'] = array() : $wp_filter['save_post']->remove_all_filters();
272
+
273
+    // create or update the post.
274
+    $post_id = wp_insert_post( $params, TRUE );
275
+
276
+    // Restore all the existing filters.
277
+    is_array( $wp_filter['save_post'] ) ? $wp_filter['save_post'] = $save_post_filters : $wp_filter['save_post']->callbacks = $save_post_filters;
278
+
279
+    // If Yoast is installed and active, we restore the Yoast save_postdata hook (https://github.com/insideout10/wordlift-plugin/issues/156)
280
+    if ( isset( $wpseo_metabox ) ) {
281
+        add_action( 'wp_insert_post', array( $wpseo_metabox, 'save_postdata' ) );
282
+    }
283
+
284
+    // If SEO Ultimate is installed, add back the hook we removed a few lines above.
285
+    if ( isset( $seo_ultimate ) ) {
286
+        add_action( 'save_post', array( $seo_ultimate, 'save_postmeta_box' ), 10, 2 );
287
+    }
288
+
289
+    // TODO: handle errors.
290
+    if ( is_wp_error( $post_id ) ) {
291
+        wl_write_log( ': error occurred' );
292
+
293
+        // inform an error occurred.
294
+        return null;
295
+    }
296
+
297
+    wl_set_entity_main_type( $post_id, $type_uri );
298
+
299
+    // Save the entity types.
300
+    wl_set_entity_rdf_types( $post_id, $entity_types );
301
+
302
+    // Get a dataset URI for the entity.
303
+    $wl_uri = wl_build_entity_uri( $post_id );
304
+
305
+    // Save the entity URI.
306
+    wl_set_entity_uri( $post_id, $wl_uri );
307
+
308
+    // Add the uri to the sameAs data if it's not a local URI.
309
+    if ( $wl_uri !== $uri ) {
310
+        array_push( $same_as, $uri );
311
+    }
312
+
313
+    $new_uri = wl_get_entity_uri( $post_id );
314
+
315
+    // Save the sameAs data for the entity.
316
+    wl_schema_set_value( $post_id, 'sameAs', $same_as );
317
+
318
+    // Save the other properties (latitude, langitude, startDate, endDate, etc.)
319
+    foreach ( $other_properties as $property_name => $property_value ) {
320
+        wl_schema_set_value( $post_id, $property_name, $property_value );
321
+    }
322
+
323
+    // Call hooks.
324
+    do_action( 'wl_save_entity', $post_id );
325
+
326
+    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 ) . " ]" );
327
+
328
+    foreach ( $images as $image_remote_url ) {
329
+
330
+        // Check if image is already present in local DB
331
+        if ( strpos( $image_remote_url, site_url() ) !== false ) {
332
+            // Do nothing.
333
+            continue;
334
+        }
335
+
336
+        // Check if there is an existing attachment for this post ID and source URL.
337
+        $existing_image = wl_get_attachment_for_source_url( $post_id, $image_remote_url );
338
+
339
+        // Skip if an existing image is found.
340
+        if ( null !== $existing_image ) {
341
+            continue;
342
+        }
343
+
344
+        // Save the image and get the local path.
345
+        $image = wl_save_image( $image_remote_url );
346
+
347
+        // Get the local URL.
348
+        $filename     = $image['path'];
349
+        $url          = $image['url'];
350
+        $content_type = $image['content_type'];
351
+
352
+        $attachment = array(
353
+            'guid'           => $url,
354
+            // post_title, post_content (the value for this key should be the empty string), post_status and post_mime_type
355
+            'post_title'     => $label,
356
+            // Set the title to the post title.
357
+            'post_content'   => '',
358
+            'post_status'    => 'inherit',
359
+            'post_mime_type' => $content_type
360
+        );
361 361
 
362
-		// Create the attachment in WordPress and generate the related metadata.
363
-		$attachment_id = wp_insert_attachment( $attachment, $filename, $post_id );
362
+        // Create the attachment in WordPress and generate the related metadata.
363
+        $attachment_id = wp_insert_attachment( $attachment, $filename, $post_id );
364 364
 
365
-		// Set the source URL for the image.
366
-		wl_set_source_url( $attachment_id, $image_remote_url );
365
+        // Set the source URL for the image.
366
+        wl_set_source_url( $attachment_id, $image_remote_url );
367 367
 
368
-		$attachment_data = wp_generate_attachment_metadata( $attachment_id, $filename );
369
-		wp_update_attachment_metadata( $attachment_id, $attachment_data );
368
+        $attachment_data = wp_generate_attachment_metadata( $attachment_id, $filename );
369
+        wp_update_attachment_metadata( $attachment_id, $attachment_data );
370 370
 
371
-		// Set it as the featured image.
372
-		set_post_thumbnail( $post_id, $attachment_id );
373
-	}
371
+        // Set it as the featured image.
372
+        set_post_thumbnail( $post_id, $attachment_id );
373
+    }
374 374
 
375
-	// The entity is pushed to Redlink on save by the function hooked to save_post.
376
-	// save the entity in the triple store.
377
-	wl_linked_data_push_to_redlink( $post_id );
375
+    // The entity is pushed to Redlink on save by the function hooked to save_post.
376
+    // save the entity in the triple store.
377
+    wl_linked_data_push_to_redlink( $post_id );
378 378
 
379
-	// finally return the entity post.
380
-	return get_post( $post_id );
379
+    // finally return the entity post.
380
+    return get_post( $post_id );
381 381
 }
382 382
 
383 383
 /**
@@ -391,42 +391,42 @@  discard block
 block discarded – undo
391 391
  */
392 392
 function wl_linked_data_content_get_embedded_entities( $content ) {
393 393
 
394
-	// Remove quote escapes.
395
-	$content = str_replace( '\\"', '"', $content );
394
+    // Remove quote escapes.
395
+    $content = str_replace( '\\"', '"', $content );
396 396
 
397
-	// Match all itemid attributes.
398
-	$pattern = '/<\w+[^>]*\sitemid="([^"]+)"[^>]*>/im';
397
+    // Match all itemid attributes.
398
+    $pattern = '/<\w+[^>]*\sitemid="([^"]+)"[^>]*>/im';
399 399
 
400
-	//	wl_write_log( "Getting entities embedded into content [ pattern :: $pattern ]" );
400
+    //	wl_write_log( "Getting entities embedded into content [ pattern :: $pattern ]" );
401 401
 
402
-	// Remove the pattern while it is found (match nested annotations).
403
-	$matches = array();
402
+    // Remove the pattern while it is found (match nested annotations).
403
+    $matches = array();
404 404
 
405
-	// In case of errors, return an empty array.
406
-	if ( false === preg_match_all( $pattern, $content, $matches ) ) {
407
-		wl_write_log( "Found no entities embedded in content" );
405
+    // In case of errors, return an empty array.
406
+    if ( false === preg_match_all( $pattern, $content, $matches ) ) {
407
+        wl_write_log( "Found no entities embedded in content" );
408 408
 
409
-		return array();
410
-	}
409
+        return array();
410
+    }
411 411
 
412 412
 //    wl_write_log("wl_update_related_entities [ content :: $content ][ data :: " . var_export($data, true). " ][ matches :: " . var_export($matches, true) . " ]");
413 413
 
414
-	// Collect the entities.
415
-	$entities = array();
416
-	foreach ( $matches[1] as $uri ) {
417
-		$uri_d  = html_entity_decode( $uri );
414
+    // Collect the entities.
415
+    $entities = array();
416
+    foreach ( $matches[1] as $uri ) {
417
+        $uri_d  = html_entity_decode( $uri );
418 418
 
419
-		$entity = Wordlift_Entity_Service::get_instance()->get_entity_post_by_uri( $uri_d );
419
+        $entity = Wordlift_Entity_Service::get_instance()->get_entity_post_by_uri( $uri_d );
420 420
 
421
-		if ( null !== $entity ) {
422
-			array_push( $entities, $entity->ID );
423
-		}
424
-	}
421
+        if ( null !== $entity ) {
422
+            array_push( $entities, $entity->ID );
423
+        }
424
+    }
425 425
 
426
-	// $count = sizeof( $entities );
427
-	// wl_write_log( "Found $count entities embedded in content" );
426
+    // $count = sizeof( $entities );
427
+    // wl_write_log( "Found $count entities embedded in content" );
428 428
 
429
-	return $entities;
429
+    return $entities;
430 430
 }
431 431
 
432 432
 /**
@@ -438,22 +438,22 @@  discard block
 block discarded – undo
438 438
  */
439 439
 function wl_linked_data_push_to_redlink( $post_id ) {
440 440
 
441
-	// Get the post.
442
-	$post = get_post( $post_id );
441
+    // Get the post.
442
+    $post = get_post( $post_id );
443 443
 
444
-	// wl_write_log( "wl_linked_data_push_to_redlink [ post id :: $post_id ][ post type :: $post->post_type ]" );
444
+    // wl_write_log( "wl_linked_data_push_to_redlink [ post id :: $post_id ][ post type :: $post->post_type ]" );
445 445
 
446
-	// Call the method on behalf of the post type.
447
-	switch ( $post->post_type ) {
448
-		case 'entity':
449
-			wl_push_entity_post_to_redlink( $post );
450
-			break;
451
-		default:
452
-			wl_push_post_to_redlink( $post );
453
-	}
446
+    // Call the method on behalf of the post type.
447
+    switch ( $post->post_type ) {
448
+        case 'entity':
449
+            wl_push_entity_post_to_redlink( $post );
450
+            break;
451
+        default:
452
+            wl_push_post_to_redlink( $post );
453
+    }
454 454
 
455
-	// Reindex the triple store if buffering is turned off.
456
-	if ( false === WL_ENABLE_SPARQL_UPDATE_QUERIES_BUFFERING ) {
457
-		wordlift_reindex_triple_store();
458
-	}
455
+    // Reindex the triple store if buffering is turned off.
456
+    if ( false === WL_ENABLE_SPARQL_UPDATE_QUERIES_BUFFERING ) {
457
+        wordlift_reindex_triple_store();
458
+    }
459 459
 }
Please login to merge, or discard this patch.
Spacing   +122 added lines, -122 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 
@@ -56,54 +56,54 @@  discard block
 block discarded – undo
56 56
 	$entities_uri_mapping = array();
57 57
 
58 58
 	// Save the entities coming with POST data.
59
-	if ( isset( $_POST['wl_entities'] ) && isset( $_POST['wl_boxes'] ) ) {
59
+	if (isset($_POST['wl_entities']) && isset($_POST['wl_boxes'])) {
60 60
 
61
-		wl_write_log( "[ post id :: $post_id ][ POST(wl_entities) :: " );
62
-		wl_write_log( json_encode( $_POST['wl_entities'] ) );
63
-		wl_write_log( "]" );
64
-		wl_write_log( "[ post id :: $post_id ][ POST(wl_boxes) :: " );
65
-		wl_write_log( json_encode( $_POST['wl_boxes'], true ) );
66
-		wl_write_log( "]" );
61
+		wl_write_log("[ post id :: $post_id ][ POST(wl_entities) :: ");
62
+		wl_write_log(json_encode($_POST['wl_entities']));
63
+		wl_write_log("]");
64
+		wl_write_log("[ post id :: $post_id ][ POST(wl_boxes) :: ");
65
+		wl_write_log(json_encode($_POST['wl_boxes'], true));
66
+		wl_write_log("]");
67 67
 
68 68
 		$entities_via_post = $_POST['wl_entities'];
69 69
 		$boxes_via_post    = $_POST['wl_boxes'];
70 70
 
71
-		foreach ( $entities_via_post as $entity_uri => $entity ) {
71
+		foreach ($entities_via_post as $entity_uri => $entity) {
72 72
 
73 73
 			// Only if the current entity is created from scratch let's avoid to create 
74 74
 			// more than one entity with same label & entity type
75
-			$entity_type = ( preg_match( '/^local-entity-.+/', $entity_uri ) > 0 ) ?
76
-				$entity[ 'main_type' ] : NULL;
75
+			$entity_type = (preg_match('/^local-entity-.+/', $entity_uri) > 0) ?
76
+				$entity['main_type'] : NULL;
77 77
 
78 78
 			// Look if current entity uri matchs an internal existing entity, meaning:
79 79
 			// 1. when $entity_uri is an internal uri 
80 80
 			// 2. when $entity_uri is an external uri used as sameAs of an internal entity	
81
-			$ie = Wordlift_Entity_Service::get_instance()->get_entity_post_by_uri( $entity_uri );
81
+			$ie = Wordlift_Entity_Service::get_instance()->get_entity_post_by_uri($entity_uri);
82 82
 
83 83
 			// Detect the uri depending if is an existing or a new entity
84
-			$uri = ( NULL === $ie ) ?
84
+			$uri = (NULL === $ie) ?
85 85
 				Wordlift_Entity_Service::get_instance()->build_uri(
86
-					$entity[ 'label' ],
86
+					$entity['label'],
87 87
 					Wordlift_Entity_Service::TYPE_NAME,
88 88
 					$entity_type
89
-				) : wl_get_entity_uri( $ie->ID );
89
+				) : wl_get_entity_uri($ie->ID);
90 90
 
91 91
 			wl_write_log("Map $entity_uri on $uri");
92
-			$entities_uri_mapping[ $entity_uri ] = $uri;
92
+			$entities_uri_mapping[$entity_uri] = $uri;
93 93
 
94 94
 			// Local entities have a tmp uri with 'local-entity-' prefix
95 95
 			// These uris need to be rewritten here and replaced in the content
96
-			if ( preg_match( '/^local-entity-.+/', $entity_uri ) > 0 ) {
96
+			if (preg_match('/^local-entity-.+/', $entity_uri) > 0) {
97 97
 				// Override the entity obj
98
-				$entity[ 'uri' ] = $uri;
98
+				$entity['uri'] = $uri;
99 99
 			}
100 100
 
101 101
 			// Update entity data with related post
102
-			$entity[ 'related_post_id' ] = $post_id;
102
+			$entity['related_post_id'] = $post_id;
103 103
 
104 104
 			// Save the entity if is a new entity
105
-			if ( NULL === $ie ) {
106
-				wl_save_entity( $entity );
105
+			if (NULL === $ie) {
106
+				wl_save_entity($entity);
107 107
 			}
108 108
 
109 109
 		}
@@ -113,36 +113,36 @@  discard block
 block discarded – undo
113 113
 	// Replace tmp uris in content post if needed
114 114
 	$updated_post_content = $post->post_content;
115 115
 	// Save each entity and store the post id.
116
-	foreach ( $entities_uri_mapping as $tmp_uri => $uri ) {
117
-		$updated_post_content = str_replace( $tmp_uri, $uri, $updated_post_content );
116
+	foreach ($entities_uri_mapping as $tmp_uri => $uri) {
117
+		$updated_post_content = str_replace($tmp_uri, $uri, $updated_post_content);
118 118
 	}
119 119
 
120 120
 	// Update the post content
121
-	wp_update_post( array(
121
+	wp_update_post(array(
122 122
 		'ID'           => $post->ID,
123 123
 		'post_content' => $updated_post_content,
124
-	) );
124
+	));
125 125
 
126 126
 	// Extract related/referenced entities from text.
127
-	$disambiguated_entities = wl_linked_data_content_get_embedded_entities( $updated_post_content );
127
+	$disambiguated_entities = wl_linked_data_content_get_embedded_entities($updated_post_content);
128 128
 
129 129
 	// Reset previously saved instances
130
-	wl_core_delete_relation_instances( $post_id );
130
+	wl_core_delete_relation_instances($post_id);
131 131
 
132 132
 	// Save relation instances
133
-	foreach ( array_unique( $disambiguated_entities ) as $referenced_entity_id ) {
133
+	foreach (array_unique($disambiguated_entities) as $referenced_entity_id) {
134 134
 
135 135
 		wl_core_add_relation_instance(
136 136
 			$post_id,
137
-			Wordlift_Entity_Service::get_instance()->get_classification_scope_for( $referenced_entity_id ),
137
+			Wordlift_Entity_Service::get_instance()->get_classification_scope_for($referenced_entity_id),
138 138
 			$referenced_entity_id
139 139
 		);
140 140
 
141 141
 	}
142 142
 
143
-    if ( isset( $_POST['wl_entities'] ) ) {
143
+    if (isset($_POST['wl_entities'])) {
144 144
 		// Save post metadata if available
145
-		$metadata_via_post    =  ( isset( $_POST['wl_metadata'] ) ) ?
145
+		$metadata_via_post = (isset($_POST['wl_metadata'])) ?
146 146
 			$_POST['wl_metadata'] : array();
147 147
 
148 148
 		$fields = array(
@@ -151,54 +151,54 @@  discard block
 block discarded – undo
151 151
 		);
152 152
 
153 153
 		// Unlink topic taxonomy terms
154
-		Wordlift_Topic_Taxonomy_Service::get_instance()->unlink_topic_for( $post->ID );
154
+		Wordlift_Topic_Taxonomy_Service::get_instance()->unlink_topic_for($post->ID);
155 155
 
156
-		foreach ( $fields as $field ) {
156
+		foreach ($fields as $field) {
157 157
 
158 158
 			// Delete current values
159
-			delete_post_meta( $post->ID, $field );
159
+			delete_post_meta($post->ID, $field);
160 160
 			// Retrieve the entity uri
161
-			$uri 	= ( isset( $metadata_via_post[ $field ] ) ) ?
162
-				stripslashes( $metadata_via_post[ $field ] ) : '';
161
+			$uri = (isset($metadata_via_post[$field])) ?
162
+				stripslashes($metadata_via_post[$field]) : '';
163 163
 
164
-			$entity = Wordlift_Entity_Service::get_instance()->get_entity_post_by_uri( $uri );
164
+			$entity = Wordlift_Entity_Service::get_instance()->get_entity_post_by_uri($uri);
165 165
 
166
-			if ( $entity ) {
167
-				add_post_meta( $post->ID, $field, $entity->ID, true );
166
+			if ($entity) {
167
+				add_post_meta($post->ID, $field, $entity->ID, true);
168 168
 				// Set also the topic taxonomy
169
-				if ( $field === Wordlift_Schema_Service::FIELD_TOPIC ) {
170
-					Wordlift_Topic_Taxonomy_Service::get_instance()->set_topic_for( $post->ID, $entity );
169
+				if ($field === Wordlift_Schema_Service::FIELD_TOPIC) {
170
+					Wordlift_Topic_Taxonomy_Service::get_instance()->set_topic_for($post->ID, $entity);
171 171
 				}
172 172
 			}
173 173
 		}
174 174
 	}
175 175
 
176 176
 	// Push the post to Redlink.
177
-	wl_linked_data_push_to_redlink( $post->ID );
177
+	wl_linked_data_push_to_redlink($post->ID);
178 178
 
179
-	add_action( 'wl_linked_data_save_post', 'wl_linked_data_save_post_and_related_entities' );
179
+	add_action('wl_linked_data_save_post', 'wl_linked_data_save_post_and_related_entities');
180 180
 }
181 181
 
182
-add_action( 'wl_linked_data_save_post', 'wl_linked_data_save_post_and_related_entities' );
182
+add_action('wl_linked_data_save_post', 'wl_linked_data_save_post_and_related_entities');
183 183
 
184 184
 /**
185 185
  * Adds default schema type "Thing" as soon as an entity is created.
186 186
  */
187
-function wordlift_save_post_add_default_schema_type( $entity_id ) {
187
+function wordlift_save_post_add_default_schema_type($entity_id) {
188 188
 
189
-	$entity      = get_post( $entity_id );
190
-	$entity_type = wl_schema_get_types( $entity_id );
189
+	$entity      = get_post($entity_id);
190
+	$entity_type = wl_schema_get_types($entity_id);
191 191
 
192 192
 	// Assign type 'Thing' if we are dealing with an entity without type
193
-	if ( $entity->post_type == Wordlift_Entity_Service::TYPE_NAME && is_null( $entity_type ) ) {
194
-		wl_schema_set_types( $entity_id, 'Thing' );
193
+	if ($entity->post_type == Wordlift_Entity_Service::TYPE_NAME && is_null($entity_type)) {
194
+		wl_schema_set_types($entity_id, 'Thing');
195 195
 	}
196 196
 
197 197
 }
198 198
 
199 199
 // Priority 1 (default is 10) because we want the default type to be set as soon as possible
200 200
 // Attatched to save_post because *wl_linked_data_save_post* does not always fire
201
-add_action( 'save_post', 'wordlift_save_post_add_default_schema_type', 1 );
201
+add_action('save_post', 'wordlift_save_post_add_default_schema_type', 1);
202 202
 
203 203
 /**
204 204
  * Save the specified data as an entity in WordPress. This method only create new entities. When an existing entity is
@@ -216,23 +216,23 @@  discard block
 block discarded – undo
216 216
  *
217 217
  * @return null|WP_Post A post instance or null in case of failure.
218 218
  */
219
-function wl_save_entity( $entity_data ) {
219
+function wl_save_entity($entity_data) {
220 220
 
221 221
 	$uri              = $entity_data['uri'];
222 222
 	$label            = $entity_data['label'];
223 223
 	$type_uri         = $entity_data['main_type'];
224
-	$entity_types     = isset( $entity_data['type'] ) ? $entity_data['type'] : array();
224
+	$entity_types     = isset($entity_data['type']) ? $entity_data['type'] : array();
225 225
 	$description      = $entity_data['description'];
226
-	$images           = isset( $entity_data['image'] ) ? wl_force_to_array( $entity_data['image'] ) : array();
227
-	$same_as          = isset( $entity_data['sameas'] ) ? wl_force_to_array( $entity_data['sameas'] ) : array();
228
-	$related_post_id  = isset( $entity_data['related_post_id'] ) ? $entity_data['related_post_id'] : null;
229
-	$other_properties = isset( $entity_data['properties'] ) ? $entity_data['properties'] : array();
226
+	$images           = isset($entity_data['image']) ? wl_force_to_array($entity_data['image']) : array();
227
+	$same_as          = isset($entity_data['sameas']) ? wl_force_to_array($entity_data['sameas']) : array();
228
+	$related_post_id  = isset($entity_data['related_post_id']) ? $entity_data['related_post_id'] : null;
229
+	$other_properties = isset($entity_data['properties']) ? $entity_data['properties'] : array();
230 230
 
231 231
 	// wl_write_log( "[ uri :: $uri ][ label :: $label ][ type uri :: $type_uri ]" );
232 232
 
233 233
 	// Prepare properties of the new entity.
234 234
 	$params = array(
235
-		'post_status'  => ( is_numeric( $related_post_id ) ? get_post_status( $related_post_id ) : 'draft' ),
235
+		'post_status'  => (is_numeric($related_post_id) ? get_post_status($related_post_id) : 'draft'),
236 236
 		'post_type'    => Wordlift_Entity_Service::TYPE_NAME,
237 237
 		'post_title'   => $label,
238 238
 		'post_content' => $description,
@@ -240,9 +240,9 @@  discard block
 block discarded – undo
240 240
 	);
241 241
 
242 242
 	// Check whether an entity already exists with the provided URI.
243
-	$post = Wordlift_Entity_Service::get_instance()->get_entity_post_by_uri( $uri );
243
+	$post = Wordlift_Entity_Service::get_instance()->get_entity_post_by_uri($uri);
244 244
 
245
-	if ( null !== $post ) {
245
+	if (null !== $post) {
246 246
 		return $post;
247 247
 	}
248 248
 
@@ -252,12 +252,12 @@  discard block
 block discarded – undo
252 252
 	// This does NOT affect saving an entity from the entity admin page since this function is called when an entity
253 253
 	// is created when saving a post.
254 254
 	global $wpseo_metabox, $seo_ultimate;
255
-	if ( isset( $wpseo_metabox ) ) {
256
-		remove_action( 'wp_insert_post', array( $wpseo_metabox, 'save_postdata' ) );
255
+	if (isset($wpseo_metabox)) {
256
+		remove_action('wp_insert_post', array($wpseo_metabox, 'save_postdata'));
257 257
 	}
258 258
 
259
-	if ( isset( $seo_ultimate ) ) {
260
-		remove_action( 'save_post', array( $seo_ultimate, 'save_postmeta_box' ) );
259
+	if (isset($seo_ultimate)) {
260
+		remove_action('save_post', array($seo_ultimate, 'save_postmeta_box'));
261 261
 	}
262 262
 
263 263
 	// The fact that we're calling here wp_insert_post is causing issues with plugins (and ourselves too) that hook to
@@ -267,82 +267,82 @@  discard block
 block discarded – undo
267 267
 	// see https://github.com/insideout10/wordlift-plugin/issues/156
268 268
 	// see https://github.com/insideout10/wordlift-plugin/issues/148
269 269
 	global $wp_filter;
270
-	$save_post_filters = is_array( $wp_filter['save_post'] ) ? $wp_filter['save_post'] : $wp_filter['save_post']->callbacks;
271
-	is_array( $wp_filter['save_post'] ) ? $wp_filter['save_post'] = array() : $wp_filter['save_post']->remove_all_filters();
270
+	$save_post_filters = is_array($wp_filter['save_post']) ? $wp_filter['save_post'] : $wp_filter['save_post']->callbacks;
271
+	is_array($wp_filter['save_post']) ? $wp_filter['save_post'] = array() : $wp_filter['save_post']->remove_all_filters();
272 272
 
273 273
 	// create or update the post.
274
-	$post_id = wp_insert_post( $params, TRUE );
274
+	$post_id = wp_insert_post($params, TRUE);
275 275
 
276 276
 	// Restore all the existing filters.
277
-	is_array( $wp_filter['save_post'] ) ? $wp_filter['save_post'] = $save_post_filters : $wp_filter['save_post']->callbacks = $save_post_filters;
277
+	is_array($wp_filter['save_post']) ? $wp_filter['save_post'] = $save_post_filters : $wp_filter['save_post']->callbacks = $save_post_filters;
278 278
 
279 279
 	// If Yoast is installed and active, we restore the Yoast save_postdata hook (https://github.com/insideout10/wordlift-plugin/issues/156)
280
-	if ( isset( $wpseo_metabox ) ) {
281
-		add_action( 'wp_insert_post', array( $wpseo_metabox, 'save_postdata' ) );
280
+	if (isset($wpseo_metabox)) {
281
+		add_action('wp_insert_post', array($wpseo_metabox, 'save_postdata'));
282 282
 	}
283 283
 
284 284
 	// If SEO Ultimate is installed, add back the hook we removed a few lines above.
285
-	if ( isset( $seo_ultimate ) ) {
286
-		add_action( 'save_post', array( $seo_ultimate, 'save_postmeta_box' ), 10, 2 );
285
+	if (isset($seo_ultimate)) {
286
+		add_action('save_post', array($seo_ultimate, 'save_postmeta_box'), 10, 2);
287 287
 	}
288 288
 
289 289
 	// TODO: handle errors.
290
-	if ( is_wp_error( $post_id ) ) {
291
-		wl_write_log( ': error occurred' );
290
+	if (is_wp_error($post_id)) {
291
+		wl_write_log(': error occurred');
292 292
 
293 293
 		// inform an error occurred.
294 294
 		return null;
295 295
 	}
296 296
 
297
-	wl_set_entity_main_type( $post_id, $type_uri );
297
+	wl_set_entity_main_type($post_id, $type_uri);
298 298
 
299 299
 	// Save the entity types.
300
-	wl_set_entity_rdf_types( $post_id, $entity_types );
300
+	wl_set_entity_rdf_types($post_id, $entity_types);
301 301
 
302 302
 	// Get a dataset URI for the entity.
303
-	$wl_uri = wl_build_entity_uri( $post_id );
303
+	$wl_uri = wl_build_entity_uri($post_id);
304 304
 
305 305
 	// Save the entity URI.
306
-	wl_set_entity_uri( $post_id, $wl_uri );
306
+	wl_set_entity_uri($post_id, $wl_uri);
307 307
 
308 308
 	// Add the uri to the sameAs data if it's not a local URI.
309
-	if ( $wl_uri !== $uri ) {
310
-		array_push( $same_as, $uri );
309
+	if ($wl_uri !== $uri) {
310
+		array_push($same_as, $uri);
311 311
 	}
312 312
 
313
-	$new_uri = wl_get_entity_uri( $post_id );
313
+	$new_uri = wl_get_entity_uri($post_id);
314 314
 
315 315
 	// Save the sameAs data for the entity.
316
-	wl_schema_set_value( $post_id, 'sameAs', $same_as );
316
+	wl_schema_set_value($post_id, 'sameAs', $same_as);
317 317
 
318 318
 	// Save the other properties (latitude, langitude, startDate, endDate, etc.)
319
-	foreach ( $other_properties as $property_name => $property_value ) {
320
-		wl_schema_set_value( $post_id, $property_name, $property_value );
319
+	foreach ($other_properties as $property_name => $property_value) {
320
+		wl_schema_set_value($post_id, $property_name, $property_value);
321 321
 	}
322 322
 
323 323
 	// Call hooks.
324
-	do_action( 'wl_save_entity', $post_id );
324
+	do_action('wl_save_entity', $post_id);
325 325
 
326
-	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 ) . " ]" );
326
+	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)." ]");
327 327
 
328
-	foreach ( $images as $image_remote_url ) {
328
+	foreach ($images as $image_remote_url) {
329 329
 
330 330
 		// Check if image is already present in local DB
331
-		if ( strpos( $image_remote_url, site_url() ) !== false ) {
331
+		if (strpos($image_remote_url, site_url()) !== false) {
332 332
 			// Do nothing.
333 333
 			continue;
334 334
 		}
335 335
 
336 336
 		// Check if there is an existing attachment for this post ID and source URL.
337
-		$existing_image = wl_get_attachment_for_source_url( $post_id, $image_remote_url );
337
+		$existing_image = wl_get_attachment_for_source_url($post_id, $image_remote_url);
338 338
 
339 339
 		// Skip if an existing image is found.
340
-		if ( null !== $existing_image ) {
340
+		if (null !== $existing_image) {
341 341
 			continue;
342 342
 		}
343 343
 
344 344
 		// Save the image and get the local path.
345
-		$image = wl_save_image( $image_remote_url );
345
+		$image = wl_save_image($image_remote_url);
346 346
 
347 347
 		// Get the local URL.
348 348
 		$filename     = $image['path'];
@@ -360,24 +360,24 @@  discard block
 block discarded – undo
360 360
 		);
361 361
 
362 362
 		// Create the attachment in WordPress and generate the related metadata.
363
-		$attachment_id = wp_insert_attachment( $attachment, $filename, $post_id );
363
+		$attachment_id = wp_insert_attachment($attachment, $filename, $post_id);
364 364
 
365 365
 		// Set the source URL for the image.
366
-		wl_set_source_url( $attachment_id, $image_remote_url );
366
+		wl_set_source_url($attachment_id, $image_remote_url);
367 367
 
368
-		$attachment_data = wp_generate_attachment_metadata( $attachment_id, $filename );
369
-		wp_update_attachment_metadata( $attachment_id, $attachment_data );
368
+		$attachment_data = wp_generate_attachment_metadata($attachment_id, $filename);
369
+		wp_update_attachment_metadata($attachment_id, $attachment_data);
370 370
 
371 371
 		// Set it as the featured image.
372
-		set_post_thumbnail( $post_id, $attachment_id );
372
+		set_post_thumbnail($post_id, $attachment_id);
373 373
 	}
374 374
 
375 375
 	// The entity is pushed to Redlink on save by the function hooked to save_post.
376 376
 	// save the entity in the triple store.
377
-	wl_linked_data_push_to_redlink( $post_id );
377
+	wl_linked_data_push_to_redlink($post_id);
378 378
 
379 379
 	// finally return the entity post.
380
-	return get_post( $post_id );
380
+	return get_post($post_id);
381 381
 }
382 382
 
383 383
 /**
@@ -389,10 +389,10 @@  discard block
 block discarded – undo
389 389
  *
390 390
  * @return array An array of entity posts.
391 391
  */
392
-function wl_linked_data_content_get_embedded_entities( $content ) {
392
+function wl_linked_data_content_get_embedded_entities($content) {
393 393
 
394 394
 	// Remove quote escapes.
395
-	$content = str_replace( '\\"', '"', $content );
395
+	$content = str_replace('\\"', '"', $content);
396 396
 
397 397
 	// Match all itemid attributes.
398 398
 	$pattern = '/<\w+[^>]*\sitemid="([^"]+)"[^>]*>/im';
@@ -403,8 +403,8 @@  discard block
 block discarded – undo
403 403
 	$matches = array();
404 404
 
405 405
 	// In case of errors, return an empty array.
406
-	if ( false === preg_match_all( $pattern, $content, $matches ) ) {
407
-		wl_write_log( "Found no entities embedded in content" );
406
+	if (false === preg_match_all($pattern, $content, $matches)) {
407
+		wl_write_log("Found no entities embedded in content");
408 408
 
409 409
 		return array();
410 410
 	}
@@ -413,13 +413,13 @@  discard block
 block discarded – undo
413 413
 
414 414
 	// Collect the entities.
415 415
 	$entities = array();
416
-	foreach ( $matches[1] as $uri ) {
417
-		$uri_d  = html_entity_decode( $uri );
416
+	foreach ($matches[1] as $uri) {
417
+		$uri_d  = html_entity_decode($uri);
418 418
 
419
-		$entity = Wordlift_Entity_Service::get_instance()->get_entity_post_by_uri( $uri_d );
419
+		$entity = Wordlift_Entity_Service::get_instance()->get_entity_post_by_uri($uri_d);
420 420
 
421
-		if ( null !== $entity ) {
422
-			array_push( $entities, $entity->ID );
421
+		if (null !== $entity) {
422
+			array_push($entities, $entity->ID);
423 423
 		}
424 424
 	}
425 425
 
@@ -436,24 +436,24 @@  discard block
 block discarded – undo
436 436
  *
437 437
  * @param int $post_id The post ID.
438 438
  */
439
-function wl_linked_data_push_to_redlink( $post_id ) {
439
+function wl_linked_data_push_to_redlink($post_id) {
440 440
 
441 441
 	// Get the post.
442
-	$post = get_post( $post_id );
442
+	$post = get_post($post_id);
443 443
 
444 444
 	// wl_write_log( "wl_linked_data_push_to_redlink [ post id :: $post_id ][ post type :: $post->post_type ]" );
445 445
 
446 446
 	// Call the method on behalf of the post type.
447
-	switch ( $post->post_type ) {
447
+	switch ($post->post_type) {
448 448
 		case 'entity':
449
-			wl_push_entity_post_to_redlink( $post );
449
+			wl_push_entity_post_to_redlink($post);
450 450
 			break;
451 451
 		default:
452
-			wl_push_post_to_redlink( $post );
452
+			wl_push_post_to_redlink($post);
453 453
 	}
454 454
 
455 455
 	// Reindex the triple store if buffering is turned off.
456
-	if ( false === WL_ENABLE_SPARQL_UPDATE_QUERIES_BUFFERING ) {
456
+	if (false === WL_ENABLE_SPARQL_UPDATE_QUERIES_BUFFERING) {
457 457
 		wordlift_reindex_triple_store();
458 458
 	}
459 459
 }
Please login to merge, or discard this patch.
src/admin/class-wordlift-admin-dashboard.php 2 patches
Indentation   +235 added lines, -235 removed lines patch added patch discarded remove patch
@@ -14,83 +14,83 @@  discard block
 block discarded – undo
14 14
 class Wordlift_Dashboard_Service {
15 15
 
16 16
 
17
-	/**
18
-	 * Transient Name
19
-	 *
20
-	 * @since  3.4.0
21
-	 */
22
-	const TRANSIENT_NAME = 'wl_dashboard_stats';
23
-
24
-	/**
25
-	 * Transient Expiration (in seconds)
26
-	 *
27
-	 * @since  3.4.0
28
-	 */
29
-	const TRANSIENT_EXPIRATION = 86400;
30
-
31
-	/**
32
-	 * The Entity service.
33
-	 *
34
-	 * @since  3.4.0
35
-	 * @access private
36
-	 * @var \Wordlift_Entity_Service $entity_service The Entity service.
37
-	 */
38
-	private $entity_service;
39
-
40
-	/**
41
-	 * Create a Wordlift_Entity_List_Service.
42
-	 *
43
-	 * @since 3.4.0
44
-	 *
45
-	 * @param \Wordlift_Entity_Service $entity_service The Entity service.
46
-	 */
47
-	public function __construct( $entity_service ) {
48
-
49
-		$this->log_service = Wordlift_Log_Service::get_logger( 'Wordlift_Dashboard_Service' );
50
-
51
-		$this->entity_service = $entity_service;
52
-
53
-	}
54
-
55
-	/**
56
-	 * Return stats layout
57
-	 *
58
-	 * @since 3.4.0
59
-	 *
60
-	 * @return string Dashboard widget html markup
61
-	 */
62
-	public function dashboard_widget_callback( $post ) {
63
-
64
-		$enriched_posts_title   = __( 'enriched posts', 'wordlift' );
65
-		$enriched_posts_caption = sprintf( wp_kses(
66
-			__( '%1$s, of your <a href="%2$s">posts</a> are annotated. This means %3$s annotated posts on %4$s.', 'wordlift' ),
67
-			array( 'a' => array( 'href' => array() ) ) ),
68
-			$this->render_stat_param( 'annotated_posts_percentage' ),
69
-			esc_url( admin_url( 'edit.php' ) ),
70
-			$this->render_stat_param( 'annotated_posts' ),
71
-			$this->render_stat_param( 'posts' )
72
-		);
73
-
74
-		$rating_title   = __( 'avarage entity rating', 'wordlift' );
75
-		$rating_caption = sprintf( wp_kses(
76
-			__( 'You have %1$s entities in your <a href="%2$s">vocabulary</a> with an avarage rating of %3$s.', 'wordlift' ),
77
-			array( 'a' => array( 'href' => array() ) ) ),
78
-			$this->render_stat_param( 'entities' ),
79
-			esc_url( admin_url( 'edit.php?post_type=entity' ) ),
80
-			$this->render_stat_param( 'rating' )
81
-		);
82
-
83
-		$graph_title   = __( 'triples in your graph', 'wordlift' );
84
-		$graph_caption = sprintf( wp_kses(
85
-			__( 'Your graphs size corresponds to %1$s of <a href="%2$s">Wikidata</a>.', 'wordlift' ),
86
-			array( 'a' => array( 'href' => array() ) ) ),
87
-			$this->render_stat_param( 'wikidata' ),
88
-			esc_url( 'https://www.wikidata.org/' )
89
-		);
90
-
91
-		$triples_label = __( 'triples', 'wordlift' );
92
-
93
-		echo <<<EOF
17
+    /**
18
+     * Transient Name
19
+     *
20
+     * @since  3.4.0
21
+     */
22
+    const TRANSIENT_NAME = 'wl_dashboard_stats';
23
+
24
+    /**
25
+     * Transient Expiration (in seconds)
26
+     *
27
+     * @since  3.4.0
28
+     */
29
+    const TRANSIENT_EXPIRATION = 86400;
30
+
31
+    /**
32
+     * The Entity service.
33
+     *
34
+     * @since  3.4.0
35
+     * @access private
36
+     * @var \Wordlift_Entity_Service $entity_service The Entity service.
37
+     */
38
+    private $entity_service;
39
+
40
+    /**
41
+     * Create a Wordlift_Entity_List_Service.
42
+     *
43
+     * @since 3.4.0
44
+     *
45
+     * @param \Wordlift_Entity_Service $entity_service The Entity service.
46
+     */
47
+    public function __construct( $entity_service ) {
48
+
49
+        $this->log_service = Wordlift_Log_Service::get_logger( 'Wordlift_Dashboard_Service' );
50
+
51
+        $this->entity_service = $entity_service;
52
+
53
+    }
54
+
55
+    /**
56
+     * Return stats layout
57
+     *
58
+     * @since 3.4.0
59
+     *
60
+     * @return string Dashboard widget html markup
61
+     */
62
+    public function dashboard_widget_callback( $post ) {
63
+
64
+        $enriched_posts_title   = __( 'enriched posts', 'wordlift' );
65
+        $enriched_posts_caption = sprintf( wp_kses(
66
+            __( '%1$s, of your <a href="%2$s">posts</a> are annotated. This means %3$s annotated posts on %4$s.', 'wordlift' ),
67
+            array( 'a' => array( 'href' => array() ) ) ),
68
+            $this->render_stat_param( 'annotated_posts_percentage' ),
69
+            esc_url( admin_url( 'edit.php' ) ),
70
+            $this->render_stat_param( 'annotated_posts' ),
71
+            $this->render_stat_param( 'posts' )
72
+        );
73
+
74
+        $rating_title   = __( 'avarage entity rating', 'wordlift' );
75
+        $rating_caption = sprintf( wp_kses(
76
+            __( 'You have %1$s entities in your <a href="%2$s">vocabulary</a> with an avarage rating of %3$s.', 'wordlift' ),
77
+            array( 'a' => array( 'href' => array() ) ) ),
78
+            $this->render_stat_param( 'entities' ),
79
+            esc_url( admin_url( 'edit.php?post_type=entity' ) ),
80
+            $this->render_stat_param( 'rating' )
81
+        );
82
+
83
+        $graph_title   = __( 'triples in your graph', 'wordlift' );
84
+        $graph_caption = sprintf( wp_kses(
85
+            __( 'Your graphs size corresponds to %1$s of <a href="%2$s">Wikidata</a>.', 'wordlift' ),
86
+            array( 'a' => array( 'href' => array() ) ) ),
87
+            $this->render_stat_param( 'wikidata' ),
88
+            esc_url( 'https://www.wikidata.org/' )
89
+        );
90
+
91
+        $triples_label = __( 'triples', 'wordlift' );
92
+
93
+        echo <<<EOF
94 94
 	<div id="wl-dashboard-widget-inner-wrapper">
95 95
 		<div class="wl-stat-card">
96 96
 			<div class="wl-stat-graph-wrapper">
@@ -119,166 +119,166 @@  discard block
 block discarded – undo
119 119
 	</div>
120 120
 EOF;
121 121
 
122
-	}
123
-
124
-	/**
125
-	 * Return stats
126
-	 *
127
-	 * @since 3.4.0
128
-	 *
129
-	 * @return string markup
130
-	 */
131
-	public function add_dashboard_widgets() {
132
-		wp_add_dashboard_widget( 'wordlift-dashboard-widget', 'WordLift Dashboard', array(
133
-			$this,
134
-			'dashboard_widget_callback',
135
-		) );
136
-	}
137
-
138
-	/**
139
-	 * Return stats
140
-	 * @uses  https://codex.wordpress.org/Function_Reference/set_transient
141
-	 *
142
-	 * @since 3.4.0
143
-	 *
144
-	 * @return string JSON obj with all available stats.
145
-	 */
146
-	public function ajax_get_stats() {
147
-
148
-		// If needed, the transient is force to reloaed
149
-		if ( isset( $_GET['force_reload'] ) ) {
150
-			delete_transient( self::TRANSIENT_NAME );
151
-		}
152
-
153
-		// Try to retrieve the transient
154
-		$stats = get_transient( self::TRANSIENT_NAME );
155
-
156
-		if ( ! $stats ) {
157
-			// Calculate stats
158
-			$stats = array(
159
-				'entities'        => $this->count_entities(),
160
-				'posts'           => $this->count_posts(),
161
-				'annotated_posts' => $this->count_annotated_posts(),
162
-				'triples'         => $this->count_triples() ?: '-',
163
-				'rating'          => $this->avarage_entities_rating(),
164
-			);
165
-			// Cache stats results trough transient
166
-			set_transient( self::TRANSIENT_NAME, $stats, self::TRANSIENT_EXPIRATION );
167
-		}
168
-		// Return stats as json object
169
-		wl_core_send_json( $stats );
170
-	}
171
-
172
-	/**
173
-	 * Calculate total number of published posts
174
-	 * @uses  https://codex.wordpress.org/it:Riferimento_funzioni/wp_count_posts
175
-	 * @since 3.4.0
176
-	 *
177
-	 * @return int Total number of published posts.
178
-	 */
179
-	public function count_posts() {
180
-
181
-		return (int) wp_count_posts()->publish;
182
-	}
183
-
184
-	/**
185
-	 * Calculate total number of annotated published posts
186
-	 * @since 3.4.0
187
-	 *
188
-	 * @return int Total number of annotated published posts.
189
-	 */
190
-	public function count_annotated_posts() {
191
-
192
-		// Prepare interaction with db
193
-		global $wpdb;
194
-		// Retrieve Wordlift relation instances table name
195
-		$table_name = wl_core_get_relation_instances_table_name();
196
-		// Calculate sql statement
197
-		$sql_statement = <<<EOF
122
+    }
123
+
124
+    /**
125
+     * Return stats
126
+     *
127
+     * @since 3.4.0
128
+     *
129
+     * @return string markup
130
+     */
131
+    public function add_dashboard_widgets() {
132
+        wp_add_dashboard_widget( 'wordlift-dashboard-widget', 'WordLift Dashboard', array(
133
+            $this,
134
+            'dashboard_widget_callback',
135
+        ) );
136
+    }
137
+
138
+    /**
139
+     * Return stats
140
+     * @uses  https://codex.wordpress.org/Function_Reference/set_transient
141
+     *
142
+     * @since 3.4.0
143
+     *
144
+     * @return string JSON obj with all available stats.
145
+     */
146
+    public function ajax_get_stats() {
147
+
148
+        // If needed, the transient is force to reloaed
149
+        if ( isset( $_GET['force_reload'] ) ) {
150
+            delete_transient( self::TRANSIENT_NAME );
151
+        }
152
+
153
+        // Try to retrieve the transient
154
+        $stats = get_transient( self::TRANSIENT_NAME );
155
+
156
+        if ( ! $stats ) {
157
+            // Calculate stats
158
+            $stats = array(
159
+                'entities'        => $this->count_entities(),
160
+                'posts'           => $this->count_posts(),
161
+                'annotated_posts' => $this->count_annotated_posts(),
162
+                'triples'         => $this->count_triples() ?: '-',
163
+                'rating'          => $this->avarage_entities_rating(),
164
+            );
165
+            // Cache stats results trough transient
166
+            set_transient( self::TRANSIENT_NAME, $stats, self::TRANSIENT_EXPIRATION );
167
+        }
168
+        // Return stats as json object
169
+        wl_core_send_json( $stats );
170
+    }
171
+
172
+    /**
173
+     * Calculate total number of published posts
174
+     * @uses  https://codex.wordpress.org/it:Riferimento_funzioni/wp_count_posts
175
+     * @since 3.4.0
176
+     *
177
+     * @return int Total number of published posts.
178
+     */
179
+    public function count_posts() {
180
+
181
+        return (int) wp_count_posts()->publish;
182
+    }
183
+
184
+    /**
185
+     * Calculate total number of annotated published posts
186
+     * @since 3.4.0
187
+     *
188
+     * @return int Total number of annotated published posts.
189
+     */
190
+    public function count_annotated_posts() {
191
+
192
+        // Prepare interaction with db
193
+        global $wpdb;
194
+        // Retrieve Wordlift relation instances table name
195
+        $table_name = wl_core_get_relation_instances_table_name();
196
+        // Calculate sql statement
197
+        $sql_statement = <<<EOF
198 198
     		SELECT COUNT(distinct(p.id)) FROM $wpdb->posts as p JOIN $table_name as r ON p.id = r.subject_id AND p.post_type = 'post' AND p.post_status = 'publish';
199 199
 EOF;
200 200
 
201
-		// Perform the query
202
-		return (int) $wpdb->get_var( $sql_statement );
203
-
204
-	}
205
-
206
-	/**
207
-	 * Calculate the avarage entities rating
208
-	 * @since 3.4.0
209
-	 *
210
-	 * @return int Avarage entities rating.
211
-	 */
212
-	public function avarage_entities_rating() {
213
-
214
-		// Prepare interaction with db
215
-		global $wpdb;
216
-		$query = $wpdb->prepare(
217
-			"SELECT AVG(meta_value) FROM $wpdb->postmeta where meta_key = %s",
218
-			Wordlift_Entity_Service::RATING_RAW_SCORE_META_KEY
219
-		);
220
-
221
-		// Perform the query
222
-		return $this->entity_service->convert_raw_score_to_percentage( $wpdb->get_var( $query ) );
223
-	}
224
-
225
-	/**
226
-	 * Calculate total number of published entities
227
-	 * @uses  https://codex.wordpress.org/it:Riferimento_funzioni/wp_count_posts
228
-	 * @since 3.4.0
229
-	 *
230
-	 * @return int Total number of posts.
231
-	 */
232
-	public function count_entities() {
233
-
234
-		return (int) wp_count_posts( Wordlift_Entity_Service::TYPE_NAME )->publish;
235
-	}
236
-
237
-	/**
238
-	 * Calculate total number of published rdf triples
239
-	 * @since 3.4.0
240
-	 *
241
-	 * @return int Total number of triples.
242
-	 */
243
-	public function count_triples() {
244
-
245
-		// Set the SPARQL query.
246
-		$sparql = 'SELECT (COUNT(*) AS ?no) { ?s ?p ?o  }';
247
-		// Send the request.
248
-		$response = $this->rl_sparql_select( $sparql );
249
-
250
-		// Return the error in case of failure.
251
-		if ( is_wp_error( $response ) || 200 !== (int) $response['response']['code'] ) {
252
-			return (int) FALSE;
253
-		}
254
-
255
-		// Get the body.
256
-		$body = $response['body'];
257
-		// Get the values.
258
-		$matches = array();
259
-		if ( 1 === preg_match( '/(\d+)/im', $body, $matches ) && 2 === count( $matches ) ) {
260
-			// Return the counts.
261
-			return (int) $matches[1];
262
-		}
263
-
264
-		return (int) FALSE;
265
-	}
266
-
267
-	private function rl_sparql_select( $query ) {
268
-
269
-		// Prepare the SPARQL statement by prepending the default namespaces.
270
-		$sparql = rl_sparql_prefixes() . "\n" . $query;
271
-		// Get the SPARQL SELECT URL.
272
-		$url = wl_configuration_get_query_select_url( 'csv' ) . urlencode( $sparql );
273
-		// Prepare the request.
274
-		$args = unserialize( WL_REDLINK_API_HTTP_OPTIONS );
275
-
276
-		return wp_remote_get( $url, $args );
277
-	}
278
-
279
-	private function render_stat_param( $param ) {
280
-
281
-		return '<span id="wl-dashboard-widget-' . $param . '" class="wl-stat-value"></span>';
282
-	}
201
+        // Perform the query
202
+        return (int) $wpdb->get_var( $sql_statement );
203
+
204
+    }
205
+
206
+    /**
207
+     * Calculate the avarage entities rating
208
+     * @since 3.4.0
209
+     *
210
+     * @return int Avarage entities rating.
211
+     */
212
+    public function avarage_entities_rating() {
213
+
214
+        // Prepare interaction with db
215
+        global $wpdb;
216
+        $query = $wpdb->prepare(
217
+            "SELECT AVG(meta_value) FROM $wpdb->postmeta where meta_key = %s",
218
+            Wordlift_Entity_Service::RATING_RAW_SCORE_META_KEY
219
+        );
220
+
221
+        // Perform the query
222
+        return $this->entity_service->convert_raw_score_to_percentage( $wpdb->get_var( $query ) );
223
+    }
224
+
225
+    /**
226
+     * Calculate total number of published entities
227
+     * @uses  https://codex.wordpress.org/it:Riferimento_funzioni/wp_count_posts
228
+     * @since 3.4.0
229
+     *
230
+     * @return int Total number of posts.
231
+     */
232
+    public function count_entities() {
233
+
234
+        return (int) wp_count_posts( Wordlift_Entity_Service::TYPE_NAME )->publish;
235
+    }
236
+
237
+    /**
238
+     * Calculate total number of published rdf triples
239
+     * @since 3.4.0
240
+     *
241
+     * @return int Total number of triples.
242
+     */
243
+    public function count_triples() {
244
+
245
+        // Set the SPARQL query.
246
+        $sparql = 'SELECT (COUNT(*) AS ?no) { ?s ?p ?o  }';
247
+        // Send the request.
248
+        $response = $this->rl_sparql_select( $sparql );
249
+
250
+        // Return the error in case of failure.
251
+        if ( is_wp_error( $response ) || 200 !== (int) $response['response']['code'] ) {
252
+            return (int) FALSE;
253
+        }
254
+
255
+        // Get the body.
256
+        $body = $response['body'];
257
+        // Get the values.
258
+        $matches = array();
259
+        if ( 1 === preg_match( '/(\d+)/im', $body, $matches ) && 2 === count( $matches ) ) {
260
+            // Return the counts.
261
+            return (int) $matches[1];
262
+        }
263
+
264
+        return (int) FALSE;
265
+    }
266
+
267
+    private function rl_sparql_select( $query ) {
268
+
269
+        // Prepare the SPARQL statement by prepending the default namespaces.
270
+        $sparql = rl_sparql_prefixes() . "\n" . $query;
271
+        // Get the SPARQL SELECT URL.
272
+        $url = wl_configuration_get_query_select_url( 'csv' ) . urlencode( $sparql );
273
+        // Prepare the request.
274
+        $args = unserialize( WL_REDLINK_API_HTTP_OPTIONS );
275
+
276
+        return wp_remote_get( $url, $args );
277
+    }
278
+
279
+    private function render_stat_param( $param ) {
280
+
281
+        return '<span id="wl-dashboard-widget-' . $param . '" class="wl-stat-value"></span>';
282
+    }
283 283
 
284 284
 }
Please login to merge, or discard this patch.
Spacing   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -44,9 +44,9 @@  discard block
 block discarded – undo
44 44
 	 *
45 45
 	 * @param \Wordlift_Entity_Service $entity_service The Entity service.
46 46
 	 */
47
-	public function __construct( $entity_service ) {
47
+	public function __construct($entity_service) {
48 48
 
49
-		$this->log_service = Wordlift_Log_Service::get_logger( 'Wordlift_Dashboard_Service' );
49
+		$this->log_service = Wordlift_Log_Service::get_logger('Wordlift_Dashboard_Service');
50 50
 
51 51
 		$this->entity_service = $entity_service;
52 52
 
@@ -59,36 +59,36 @@  discard block
 block discarded – undo
59 59
 	 *
60 60
 	 * @return string Dashboard widget html markup
61 61
 	 */
62
-	public function dashboard_widget_callback( $post ) {
63
-
64
-		$enriched_posts_title   = __( 'enriched posts', 'wordlift' );
65
-		$enriched_posts_caption = sprintf( wp_kses(
66
-			__( '%1$s, of your <a href="%2$s">posts</a> are annotated. This means %3$s annotated posts on %4$s.', 'wordlift' ),
67
-			array( 'a' => array( 'href' => array() ) ) ),
68
-			$this->render_stat_param( 'annotated_posts_percentage' ),
69
-			esc_url( admin_url( 'edit.php' ) ),
70
-			$this->render_stat_param( 'annotated_posts' ),
71
-			$this->render_stat_param( 'posts' )
62
+	public function dashboard_widget_callback($post) {
63
+
64
+		$enriched_posts_title   = __('enriched posts', 'wordlift');
65
+		$enriched_posts_caption = sprintf(wp_kses(
66
+			__('%1$s, of your <a href="%2$s">posts</a> are annotated. This means %3$s annotated posts on %4$s.', 'wordlift'),
67
+			array('a' => array('href' => array())) ),
68
+			$this->render_stat_param('annotated_posts_percentage'),
69
+			esc_url(admin_url('edit.php')),
70
+			$this->render_stat_param('annotated_posts'),
71
+			$this->render_stat_param('posts')
72 72
 		);
73 73
 
74
-		$rating_title   = __( 'avarage entity rating', 'wordlift' );
75
-		$rating_caption = sprintf( wp_kses(
76
-			__( 'You have %1$s entities in your <a href="%2$s">vocabulary</a> with an avarage rating of %3$s.', 'wordlift' ),
77
-			array( 'a' => array( 'href' => array() ) ) ),
78
-			$this->render_stat_param( 'entities' ),
79
-			esc_url( admin_url( 'edit.php?post_type=entity' ) ),
80
-			$this->render_stat_param( 'rating' )
74
+		$rating_title   = __('avarage entity rating', 'wordlift');
75
+		$rating_caption = sprintf(wp_kses(
76
+			__('You have %1$s entities in your <a href="%2$s">vocabulary</a> with an avarage rating of %3$s.', 'wordlift'),
77
+			array('a' => array('href' => array())) ),
78
+			$this->render_stat_param('entities'),
79
+			esc_url(admin_url('edit.php?post_type=entity')),
80
+			$this->render_stat_param('rating')
81 81
 		);
82 82
 
83
-		$graph_title   = __( 'triples in your graph', 'wordlift' );
84
-		$graph_caption = sprintf( wp_kses(
85
-			__( 'Your graphs size corresponds to %1$s of <a href="%2$s">Wikidata</a>.', 'wordlift' ),
86
-			array( 'a' => array( 'href' => array() ) ) ),
87
-			$this->render_stat_param( 'wikidata' ),
88
-			esc_url( 'https://www.wikidata.org/' )
83
+		$graph_title   = __('triples in your graph', 'wordlift');
84
+		$graph_caption = sprintf(wp_kses(
85
+			__('Your graphs size corresponds to %1$s of <a href="%2$s">Wikidata</a>.', 'wordlift'),
86
+			array('a' => array('href' => array())) ),
87
+			$this->render_stat_param('wikidata'),
88
+			esc_url('https://www.wikidata.org/')
89 89
 		);
90 90
 
91
-		$triples_label = __( 'triples', 'wordlift' );
91
+		$triples_label = __('triples', 'wordlift');
92 92
 
93 93
 		echo <<<EOF
94 94
 	<div id="wl-dashboard-widget-inner-wrapper">
@@ -129,10 +129,10 @@  discard block
 block discarded – undo
129 129
 	 * @return string markup
130 130
 	 */
131 131
 	public function add_dashboard_widgets() {
132
-		wp_add_dashboard_widget( 'wordlift-dashboard-widget', 'WordLift Dashboard', array(
132
+		wp_add_dashboard_widget('wordlift-dashboard-widget', 'WordLift Dashboard', array(
133 133
 			$this,
134 134
 			'dashboard_widget_callback',
135
-		) );
135
+		));
136 136
 	}
137 137
 
138 138
 	/**
@@ -146,14 +146,14 @@  discard block
 block discarded – undo
146 146
 	public function ajax_get_stats() {
147 147
 
148 148
 		// If needed, the transient is force to reloaed
149
-		if ( isset( $_GET['force_reload'] ) ) {
150
-			delete_transient( self::TRANSIENT_NAME );
149
+		if (isset($_GET['force_reload'])) {
150
+			delete_transient(self::TRANSIENT_NAME);
151 151
 		}
152 152
 
153 153
 		// Try to retrieve the transient
154
-		$stats = get_transient( self::TRANSIENT_NAME );
154
+		$stats = get_transient(self::TRANSIENT_NAME);
155 155
 
156
-		if ( ! $stats ) {
156
+		if ( ! $stats) {
157 157
 			// Calculate stats
158 158
 			$stats = array(
159 159
 				'entities'        => $this->count_entities(),
@@ -163,10 +163,10 @@  discard block
 block discarded – undo
163 163
 				'rating'          => $this->avarage_entities_rating(),
164 164
 			);
165 165
 			// Cache stats results trough transient
166
-			set_transient( self::TRANSIENT_NAME, $stats, self::TRANSIENT_EXPIRATION );
166
+			set_transient(self::TRANSIENT_NAME, $stats, self::TRANSIENT_EXPIRATION);
167 167
 		}
168 168
 		// Return stats as json object
169
-		wl_core_send_json( $stats );
169
+		wl_core_send_json($stats);
170 170
 	}
171 171
 
172 172
 	/**
@@ -199,7 +199,7 @@  discard block
 block discarded – undo
199 199
 EOF;
200 200
 
201 201
 		// Perform the query
202
-		return (int) $wpdb->get_var( $sql_statement );
202
+		return (int) $wpdb->get_var($sql_statement);
203 203
 
204 204
 	}
205 205
 
@@ -219,7 +219,7 @@  discard block
 block discarded – undo
219 219
 		);
220 220
 
221 221
 		// Perform the query
222
-		return $this->entity_service->convert_raw_score_to_percentage( $wpdb->get_var( $query ) );
222
+		return $this->entity_service->convert_raw_score_to_percentage($wpdb->get_var($query));
223 223
 	}
224 224
 
225 225
 	/**
@@ -231,7 +231,7 @@  discard block
 block discarded – undo
231 231
 	 */
232 232
 	public function count_entities() {
233 233
 
234
-		return (int) wp_count_posts( Wordlift_Entity_Service::TYPE_NAME )->publish;
234
+		return (int) wp_count_posts(Wordlift_Entity_Service::TYPE_NAME)->publish;
235 235
 	}
236 236
 
237 237
 	/**
@@ -245,10 +245,10 @@  discard block
 block discarded – undo
245 245
 		// Set the SPARQL query.
246 246
 		$sparql = 'SELECT (COUNT(*) AS ?no) { ?s ?p ?o  }';
247 247
 		// Send the request.
248
-		$response = $this->rl_sparql_select( $sparql );
248
+		$response = $this->rl_sparql_select($sparql);
249 249
 
250 250
 		// Return the error in case of failure.
251
-		if ( is_wp_error( $response ) || 200 !== (int) $response['response']['code'] ) {
251
+		if (is_wp_error($response) || 200 !== (int) $response['response']['code']) {
252 252
 			return (int) FALSE;
253 253
 		}
254 254
 
@@ -256,7 +256,7 @@  discard block
 block discarded – undo
256 256
 		$body = $response['body'];
257 257
 		// Get the values.
258 258
 		$matches = array();
259
-		if ( 1 === preg_match( '/(\d+)/im', $body, $matches ) && 2 === count( $matches ) ) {
259
+		if (1 === preg_match('/(\d+)/im', $body, $matches) && 2 === count($matches)) {
260 260
 			// Return the counts.
261 261
 			return (int) $matches[1];
262 262
 		}
@@ -264,21 +264,21 @@  discard block
 block discarded – undo
264 264
 		return (int) FALSE;
265 265
 	}
266 266
 
267
-	private function rl_sparql_select( $query ) {
267
+	private function rl_sparql_select($query) {
268 268
 
269 269
 		// Prepare the SPARQL statement by prepending the default namespaces.
270
-		$sparql = rl_sparql_prefixes() . "\n" . $query;
270
+		$sparql = rl_sparql_prefixes()."\n".$query;
271 271
 		// Get the SPARQL SELECT URL.
272
-		$url = wl_configuration_get_query_select_url( 'csv' ) . urlencode( $sparql );
272
+		$url = wl_configuration_get_query_select_url('csv').urlencode($sparql);
273 273
 		// Prepare the request.
274
-		$args = unserialize( WL_REDLINK_API_HTTP_OPTIONS );
274
+		$args = unserialize(WL_REDLINK_API_HTTP_OPTIONS);
275 275
 
276
-		return wp_remote_get( $url, $args );
276
+		return wp_remote_get($url, $args);
277 277
 	}
278 278
 
279
-	private function render_stat_param( $param ) {
279
+	private function render_stat_param($param) {
280 280
 
281
-		return '<span id="wl-dashboard-widget-' . $param . '" class="wl-stat-value"></span>';
281
+		return '<span id="wl-dashboard-widget-'.$param.'" class="wl-stat-value"></span>';
282 282
 	}
283 283
 
284 284
 }
Please login to merge, or discard this patch.
src/includes/class-wordlift.php 1 patch
Indentation   +722 added lines, -722 removed lines patch added patch discarded remove patch
@@ -29,784 +29,784 @@
 block discarded – undo
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 Schema service.
80
-	 *
81
-	 * @since  3.3.0
82
-	 * @access private
83
-	 * @var \Wordlift_Schema_Service $schema_service The Schema service.
84
-	 */
85
-	private $schema_service;
86
-
87
-	/**
88
-	 * The Entity service.
89
-	 *
90
-	 * @since  3.1.0
91
-	 * @access private
92
-	 * @var \Wordlift_Entity_Service $entity_service The Entity service.
93
-	 */
94
-	private $entity_service;
95
-
96
-	/**
97
-	 * The Topic Taxonomy service.
98
-	 *
99
-	 * @since  3.5.0
100
-	 * @access private
101
-	 * @var \Wordlift_Topic_Taxonomy_Service The Topic Taxonomy service.
102
-	 */
103
-	private $topic_taxonomy_service;
104
-
105
-	/**
106
-	 * The User service.
107
-	 *
108
-	 * @since  3.1.7
109
-	 * @access private
110
-	 * @var \Wordlift_User_Service $user_service The User service.
111
-	 */
112
-	private $user_service;
113
-
114
-	/**
115
-	 * The Timeline service.
116
-	 *
117
-	 * @since  3.1.0
118
-	 * @access private
119
-	 * @var \Wordlift_Timeline_Service $timeline_service The Timeline service.
120
-	 */
121
-	private $timeline_service;
122
-
123
-	/**
124
-	 * The Redirect service.
125
-	 *
126
-	 * @since  3.2.0
127
-	 * @access private
128
-	 * @var \Wordlift_Redirect_Service $redirect_service The Redirect service.
129
-	 */
130
-	private $redirect_service;
131
-
132
-	/**
133
-	 * The Notice service.
134
-	 *
135
-	 * @since  3.3.0
136
-	 * @access private
137
-	 * @var \Wordlift_Notice_Service $notice_service The Notice service.
138
-	 */
139
-	private $notice_service;
140
-
141
-	/**
142
-	 * The Entity list customization.
143
-	 *
144
-	 * @since  3.3.0
145
-	 * @access private
146
-	 * @var \Wordlift_List_Service $entity_list_service The Entity list service.
147
-	 */
148
-	private $entity_list_service;
149
-
150
-	/**
151
-	 * The Entity Types Taxonomy Walker.
152
-	 *
153
-	 * @since  3.1.0
154
-	 * @access private
155
-	 * @var \Wordlift_Entity_Types_Taxonomy_Walker $entity_types_taxonomy_walker The Entity Types Taxonomy Walker
156
-	 */
157
-	private $entity_types_taxonomy_walker;
158
-
159
-	/**
160
-	 * The ShareThis service.
161
-	 *
162
-	 * @since  3.2.0
163
-	 * @access private
164
-	 * @var \Wordlift_ShareThis_Service $sharethis_service The ShareThis service.
165
-	 */
166
-	private $sharethis_service;
167
-
168
-	/**
169
-	 * The PrimaShop adapter.
170
-	 *
171
-	 * @since  3.2.3
172
-	 * @access private
173
-	 * @var \Wordlift_PrimaShop_Adapter $primashop_adapter The PrimaShop adapter.
174
-	 */
175
-	private $primashop_adapter;
176
-
177
-	/**
178
-	 * The WordLift Dashboard adapter.
179
-	 *
180
-	 * @since  3.4.0
181
-	 * @access private
182
-	 * @var \Wordlift_Dashboard_Service $dashboard_service The WordLift Dashboard service;
183
-	 */
184
-	private $dashboard_service;
185
-
186
-	/**
187
-	 * The entity type service.
188
-	 *
189
-	 * @since  3.6.0
190
-	 * @access private
191
-	 * @var \Wordlift_Entity_Post_Type_Service
192
-	 */
193
-	private $entity_post_type_service;
194
-
195
-	/**
196
-	 * The entity link service used to mangle links to entities with a custom slug or even w/o a slug.
197
-	 *
198
-	 * @since  3.6.0
199
-	 * @access private
200
-	 * @var \Wordlift_Entity_Link_Service
201
-	 */
202
-	private $entity_link_service;
203
-
204
-	/**
205
-	 * The page service instance which processes the page output in order to insert schema.org microdata to export the
206
-	 * correct page title to Google+.
207
-	 *
208
-	 * @since  3.5.3
209
-	 * @access private
210
-	 * @var \Wordlift_Page_Service
211
-	 */
212
-	private $page_service;
213
-
214
-	/**
215
-	 * A {@link Wordlift_Sparql_Service} instance.
216
-	 *
217
-	 * @var    3.6.0
218
-	 * @access private
219
-	 * @var \Wordlift_Sparql_Service $sparql_service A {@link Wordlift_Sparql_Service} instance.
220
-	 */
221
-	private $sparql_service;
222
-
223
-	/**
224
-	 * A {@link Wordlift_Import_Service} instance.
225
-	 *
226
-	 * @since  3.6.0
227
-	 * @access private
228
-	 * @var \Wordlift_Import_Service $import_service A {@link Wordlift_Import_Service} instance.
229
-	 */
230
-	private $import_service;
231
-
232
-	/**
233
-	 * A {@link Wordlift_Rebuild_Service} instance.
234
-	 *
235
-	 * @since  3.6.0
236
-	 * @access private
237
-	 * @var \Wordlift_Rebuild_Service $rebuild_service A {@link Wordlift_Rebuild_Service} instance.
238
-	 */
239
-	private $rebuild_service;
240
-
241
-	/**
242
-	 * A {@link Wordlift_Jsonld_Service} instance.
243
-	 *
244
-	 * @since 3.7.0
245
-	 * @access private
246
-	 * @var \Wordlift_Jsonld_Service $jsonld_service A {@link Wordlift_Jsonld_Service} instance.
247
-	 */
248
-	private $jsonld_service;
249
-
250
-	/**
251
-	 *
252
-	 * @since 3.7.0
253
-	 * @access private
254
-	 * @var \Wordlift_Property_Factory $property_factory
255
-	 */
256
-	private $property_factory;
257
-
258
-	/**
259
-	 * The 'Download Your Data' page.
260
-	 *
261
-	 * @since  3.6.0
262
-	 * @access private
263
-	 * @var \Wordlift_Admin_Download_Your_Data_Page $download_your_data_page The 'Download Your Data' page.
264
-	 */
265
-	private $download_your_data_page;
266
-
267
-	/**
268
-	 * The Content Filter Service hooks up to the 'the_content' filter and provides
269
-	 * linking of entities to their pages.
270
-	 *
271
-	 * @since 3.8.0
272
-	 * @access private
273
-	 * @var \Wordlift_Content_Filter_Service $content_filter_service A {@link Wordlift_Content_Filter_Service} instance.
274
-	 */
275
-	private $content_filter_service;
276
-
277
-	/**
278
-	 * Define the core functionality of the plugin.
279
-	 *
280
-	 * Set the plugin name and the plugin version that can be used throughout the plugin.
281
-	 * Load the dependencies, define the locale, and set the hooks for the admin area and
282
-	 * the public-facing side of the site.
283
-	 *
284
-	 * @since    1.0.0
285
-	 */
286
-	public function __construct() {
287
-
288
-		$this->plugin_name = 'wordlift';
289
-		$this->version     = '3.9.0-dev';
290
-		$this->load_dependencies();
291
-		$this->set_locale();
292
-		$this->define_admin_hooks();
293
-		$this->define_public_hooks();
294
-
295
-	}
296
-
297
-	/**
298
-	 * Load the required dependencies for this plugin.
299
-	 *
300
-	 * Include the following files that make up the plugin:
301
-	 *
302
-	 * - Wordlift_Loader. Orchestrates the hooks of the plugin.
303
-	 * - Wordlift_i18n. Defines internationalization functionality.
304
-	 * - Wordlift_Admin. Defines all hooks for the admin area.
305
-	 * - Wordlift_Public. Defines all hooks for the public side of the site.
306
-	 *
307
-	 * Create an instance of the loader which will be used to register the hooks
308
-	 * with WordPress.
309
-	 *
310
-	 * @since    1.0.0
311
-	 * @access   private
312
-	 */
313
-	private function load_dependencies() {
314
-
315
-		/**
316
-		 * The class responsible for orchestrating the actions and filters of the
317
-		 * core plugin.
318
-		 */
319
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-loader.php';
320
-
321
-		/**
322
-		 * The class responsible for defining internationalization functionality
323
-		 * of the plugin.
324
-		 */
325
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-i18n.php';
326
-
327
-		/**
328
-		 * Provide support functions to sanitize data.
329
-		 */
330
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-sanitizer.php';
331
-
332
-		/**
333
-		 * The Redirect service.
334
-		 */
335
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-redirect-service.php';
336
-
337
-		/**
338
-		 * The Log service.
339
-		 */
340
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-log-service.php';
341
-
342
-		/**
343
-		 * The configuration service.
344
-		 */
345
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-configuration-service.php';
346
-
347
-		/**
348
-		 * The entity post type service (this is the WordPress post type, not the entity schema type).
349
-		 */
350
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-entity-post-type-service.php';
351
-
352
-		/**
353
-		 * The entity type service (i.e. the schema type).
354
-		 */
355
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-entity-type-service.php';
356
-
357
-		/**
358
-		 * The entity link service.
359
-		 */
360
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-entity-link-service.php';
361
-
362
-		/**
363
-		 * The Query builder.
364
-		 */
365
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-query-builder.php';
366
-
367
-		/**
368
-		 * The Schema service.
369
-		 */
370
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-schema-service.php';
371
-
372
-		/**
373
-		 * The schema:url property service.
374
-		 */
375
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-property-service.php';
376
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-schema-url-property-service.php';
377
-
378
-		/**
379
-		 * The UI service.
380
-		 */
381
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-ui-service.php';
382
-
383
-		/**
384
-		 * The Thumbnail service.
385
-		 */
386
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-thumbnail-service.php';
387
-
388
-		/**
389
-		 * The Entity Types Taxonomy service.
390
-		 */
391
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-entity-types-taxonomy-service.php';
392
-
393
-		/**
394
-		 * The Entity service.
395
-		 */
396
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-entity-service.php';
397
-
398
-		/**
399
-		 * The User service.
400
-		 */
401
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-user-service.php';
402
-
403
-		/**
404
-		 * The Timeline service.
405
-		 */
406
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-timeline-service.php';
407
-
408
-		/**
409
-		 * The Topic Taxonomy service.
410
-		 */
411
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-topic-taxonomy-service.php';
412
-
413
-
414
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-page-service.php';
415
-
416
-		/**
417
-		 * The SPARQL service.
418
-		 */
419
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-sparql-service.php';
420
-
421
-		/**
422
-		 * The WordLift import service.
423
-		 */
424
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-import-service.php';
425
-
426
-		/**
427
-		 * The WordLift URI service.
428
-		 */
429
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-uri-service.php';
430
-
431
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-listable.php';
432
-
433
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-property-factory.php';
434
-
435
-		/**
436
-		 * The WordLift rebuild service, used to rebuild the remote dataset using the local data.
437
-		 */
438
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-rebuild-service.php';
439
-
440
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/properties/class-wordlift-property-getter-factory.php';
441
-
442
-		/**
443
-		 * Load the converters.
444
-		 */
445
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-entity-post-to-jsonld-converter.php';
446
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-entity-uri-to-jsonld-converter.php';
447
-
448
-		/**
449
-		 * Load the content filter.
450
-		 */
451
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-content-filter-service.php';
452
-
453
-		/**
454
-		 * Load the JSON-LD service to publish entities using JSON-LD.s
455
-		 *
456
-		 * @since 3.8.0
457
-		 */
458
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-jsonld-service.php';
459
-
460
-		/**
461
-		 * The class responsible for defining all actions that occur in the admin area.
462
-		 */
463
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin.php';
464
-
465
-		/**
466
-		 * The class to customize the entity list admin page.
467
-		 */
468
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin-entity-list.php';
469
-
470
-		/**
471
-		 * The Entity Types Taxonomy Walker (transforms checkboxes into radios).
472
-		 */
473
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-entity-types-taxonomy-walker.php';
474
-
475
-		/**
476
-		 * The Notice service.
477
-		 */
478
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-notice-service.php';
479
-
480
-		/**
481
-		 * The PrimaShop adapter.
482
-		 */
483
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-primashop-adapter.php';
484
-
485
-		/**
486
-		 * The WordLift Dashboard service.
487
-		 */
488
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin-dashboard.php';
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 Schema service.
80
+     *
81
+     * @since  3.3.0
82
+     * @access private
83
+     * @var \Wordlift_Schema_Service $schema_service The Schema service.
84
+     */
85
+    private $schema_service;
86
+
87
+    /**
88
+     * The Entity service.
89
+     *
90
+     * @since  3.1.0
91
+     * @access private
92
+     * @var \Wordlift_Entity_Service $entity_service The Entity service.
93
+     */
94
+    private $entity_service;
95
+
96
+    /**
97
+     * The Topic Taxonomy service.
98
+     *
99
+     * @since  3.5.0
100
+     * @access private
101
+     * @var \Wordlift_Topic_Taxonomy_Service The Topic Taxonomy service.
102
+     */
103
+    private $topic_taxonomy_service;
104
+
105
+    /**
106
+     * The User service.
107
+     *
108
+     * @since  3.1.7
109
+     * @access private
110
+     * @var \Wordlift_User_Service $user_service The User service.
111
+     */
112
+    private $user_service;
113
+
114
+    /**
115
+     * The Timeline service.
116
+     *
117
+     * @since  3.1.0
118
+     * @access private
119
+     * @var \Wordlift_Timeline_Service $timeline_service The Timeline service.
120
+     */
121
+    private $timeline_service;
122
+
123
+    /**
124
+     * The Redirect service.
125
+     *
126
+     * @since  3.2.0
127
+     * @access private
128
+     * @var \Wordlift_Redirect_Service $redirect_service The Redirect service.
129
+     */
130
+    private $redirect_service;
131
+
132
+    /**
133
+     * The Notice service.
134
+     *
135
+     * @since  3.3.0
136
+     * @access private
137
+     * @var \Wordlift_Notice_Service $notice_service The Notice service.
138
+     */
139
+    private $notice_service;
140
+
141
+    /**
142
+     * The Entity list customization.
143
+     *
144
+     * @since  3.3.0
145
+     * @access private
146
+     * @var \Wordlift_List_Service $entity_list_service The Entity list service.
147
+     */
148
+    private $entity_list_service;
149
+
150
+    /**
151
+     * The Entity Types Taxonomy Walker.
152
+     *
153
+     * @since  3.1.0
154
+     * @access private
155
+     * @var \Wordlift_Entity_Types_Taxonomy_Walker $entity_types_taxonomy_walker The Entity Types Taxonomy Walker
156
+     */
157
+    private $entity_types_taxonomy_walker;
158
+
159
+    /**
160
+     * The ShareThis service.
161
+     *
162
+     * @since  3.2.0
163
+     * @access private
164
+     * @var \Wordlift_ShareThis_Service $sharethis_service The ShareThis service.
165
+     */
166
+    private $sharethis_service;
167
+
168
+    /**
169
+     * The PrimaShop adapter.
170
+     *
171
+     * @since  3.2.3
172
+     * @access private
173
+     * @var \Wordlift_PrimaShop_Adapter $primashop_adapter The PrimaShop adapter.
174
+     */
175
+    private $primashop_adapter;
176
+
177
+    /**
178
+     * The WordLift Dashboard adapter.
179
+     *
180
+     * @since  3.4.0
181
+     * @access private
182
+     * @var \Wordlift_Dashboard_Service $dashboard_service The WordLift Dashboard service;
183
+     */
184
+    private $dashboard_service;
185
+
186
+    /**
187
+     * The entity type service.
188
+     *
189
+     * @since  3.6.0
190
+     * @access private
191
+     * @var \Wordlift_Entity_Post_Type_Service
192
+     */
193
+    private $entity_post_type_service;
194
+
195
+    /**
196
+     * The entity link service used to mangle links to entities with a custom slug or even w/o a slug.
197
+     *
198
+     * @since  3.6.0
199
+     * @access private
200
+     * @var \Wordlift_Entity_Link_Service
201
+     */
202
+    private $entity_link_service;
203
+
204
+    /**
205
+     * The page service instance which processes the page output in order to insert schema.org microdata to export the
206
+     * correct page title to Google+.
207
+     *
208
+     * @since  3.5.3
209
+     * @access private
210
+     * @var \Wordlift_Page_Service
211
+     */
212
+    private $page_service;
213
+
214
+    /**
215
+     * A {@link Wordlift_Sparql_Service} instance.
216
+     *
217
+     * @var    3.6.0
218
+     * @access private
219
+     * @var \Wordlift_Sparql_Service $sparql_service A {@link Wordlift_Sparql_Service} instance.
220
+     */
221
+    private $sparql_service;
222
+
223
+    /**
224
+     * A {@link Wordlift_Import_Service} instance.
225
+     *
226
+     * @since  3.6.0
227
+     * @access private
228
+     * @var \Wordlift_Import_Service $import_service A {@link Wordlift_Import_Service} instance.
229
+     */
230
+    private $import_service;
231
+
232
+    /**
233
+     * A {@link Wordlift_Rebuild_Service} instance.
234
+     *
235
+     * @since  3.6.0
236
+     * @access private
237
+     * @var \Wordlift_Rebuild_Service $rebuild_service A {@link Wordlift_Rebuild_Service} instance.
238
+     */
239
+    private $rebuild_service;
240
+
241
+    /**
242
+     * A {@link Wordlift_Jsonld_Service} instance.
243
+     *
244
+     * @since 3.7.0
245
+     * @access private
246
+     * @var \Wordlift_Jsonld_Service $jsonld_service A {@link Wordlift_Jsonld_Service} instance.
247
+     */
248
+    private $jsonld_service;
249
+
250
+    /**
251
+     *
252
+     * @since 3.7.0
253
+     * @access private
254
+     * @var \Wordlift_Property_Factory $property_factory
255
+     */
256
+    private $property_factory;
257
+
258
+    /**
259
+     * The 'Download Your Data' page.
260
+     *
261
+     * @since  3.6.0
262
+     * @access private
263
+     * @var \Wordlift_Admin_Download_Your_Data_Page $download_your_data_page The 'Download Your Data' page.
264
+     */
265
+    private $download_your_data_page;
266
+
267
+    /**
268
+     * The Content Filter Service hooks up to the 'the_content' filter and provides
269
+     * linking of entities to their pages.
270
+     *
271
+     * @since 3.8.0
272
+     * @access private
273
+     * @var \Wordlift_Content_Filter_Service $content_filter_service A {@link Wordlift_Content_Filter_Service} instance.
274
+     */
275
+    private $content_filter_service;
276
+
277
+    /**
278
+     * Define the core functionality of the plugin.
279
+     *
280
+     * Set the plugin name and the plugin version that can be used throughout the plugin.
281
+     * Load the dependencies, define the locale, and set the hooks for the admin area and
282
+     * the public-facing side of the site.
283
+     *
284
+     * @since    1.0.0
285
+     */
286
+    public function __construct() {
287
+
288
+        $this->plugin_name = 'wordlift';
289
+        $this->version     = '3.9.0-dev';
290
+        $this->load_dependencies();
291
+        $this->set_locale();
292
+        $this->define_admin_hooks();
293
+        $this->define_public_hooks();
294
+
295
+    }
296
+
297
+    /**
298
+     * Load the required dependencies for this plugin.
299
+     *
300
+     * Include the following files that make up the plugin:
301
+     *
302
+     * - Wordlift_Loader. Orchestrates the hooks of the plugin.
303
+     * - Wordlift_i18n. Defines internationalization functionality.
304
+     * - Wordlift_Admin. Defines all hooks for the admin area.
305
+     * - Wordlift_Public. Defines all hooks for the public side of the site.
306
+     *
307
+     * Create an instance of the loader which will be used to register the hooks
308
+     * with WordPress.
309
+     *
310
+     * @since    1.0.0
311
+     * @access   private
312
+     */
313
+    private function load_dependencies() {
314
+
315
+        /**
316
+         * The class responsible for orchestrating the actions and filters of the
317
+         * core plugin.
318
+         */
319
+        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-loader.php';
320
+
321
+        /**
322
+         * The class responsible for defining internationalization functionality
323
+         * of the plugin.
324
+         */
325
+        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-i18n.php';
326
+
327
+        /**
328
+         * Provide support functions to sanitize data.
329
+         */
330
+        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-sanitizer.php';
331
+
332
+        /**
333
+         * The Redirect service.
334
+         */
335
+        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-redirect-service.php';
336
+
337
+        /**
338
+         * The Log service.
339
+         */
340
+        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-log-service.php';
341
+
342
+        /**
343
+         * The configuration service.
344
+         */
345
+        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-configuration-service.php';
346
+
347
+        /**
348
+         * The entity post type service (this is the WordPress post type, not the entity schema type).
349
+         */
350
+        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-entity-post-type-service.php';
351
+
352
+        /**
353
+         * The entity type service (i.e. the schema type).
354
+         */
355
+        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-entity-type-service.php';
356
+
357
+        /**
358
+         * The entity link service.
359
+         */
360
+        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-entity-link-service.php';
361
+
362
+        /**
363
+         * The Query builder.
364
+         */
365
+        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-query-builder.php';
366
+
367
+        /**
368
+         * The Schema service.
369
+         */
370
+        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-schema-service.php';
371
+
372
+        /**
373
+         * The schema:url property service.
374
+         */
375
+        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-property-service.php';
376
+        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-schema-url-property-service.php';
377
+
378
+        /**
379
+         * The UI service.
380
+         */
381
+        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-ui-service.php';
382
+
383
+        /**
384
+         * The Thumbnail service.
385
+         */
386
+        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-thumbnail-service.php';
387
+
388
+        /**
389
+         * The Entity Types Taxonomy service.
390
+         */
391
+        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-entity-types-taxonomy-service.php';
392
+
393
+        /**
394
+         * The Entity service.
395
+         */
396
+        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-entity-service.php';
397
+
398
+        /**
399
+         * The User service.
400
+         */
401
+        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-user-service.php';
402
+
403
+        /**
404
+         * The Timeline service.
405
+         */
406
+        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-timeline-service.php';
407
+
408
+        /**
409
+         * The Topic Taxonomy service.
410
+         */
411
+        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-topic-taxonomy-service.php';
412
+
413
+
414
+        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-page-service.php';
415
+
416
+        /**
417
+         * The SPARQL service.
418
+         */
419
+        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-sparql-service.php';
420
+
421
+        /**
422
+         * The WordLift import service.
423
+         */
424
+        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-import-service.php';
425
+
426
+        /**
427
+         * The WordLift URI service.
428
+         */
429
+        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-uri-service.php';
430
+
431
+        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-listable.php';
432
+
433
+        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-property-factory.php';
434
+
435
+        /**
436
+         * The WordLift rebuild service, used to rebuild the remote dataset using the local data.
437
+         */
438
+        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-rebuild-service.php';
439
+
440
+        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/properties/class-wordlift-property-getter-factory.php';
441
+
442
+        /**
443
+         * Load the converters.
444
+         */
445
+        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-entity-post-to-jsonld-converter.php';
446
+        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-entity-uri-to-jsonld-converter.php';
447
+
448
+        /**
449
+         * Load the content filter.
450
+         */
451
+        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-content-filter-service.php';
452
+
453
+        /**
454
+         * Load the JSON-LD service to publish entities using JSON-LD.s
455
+         *
456
+         * @since 3.8.0
457
+         */
458
+        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-jsonld-service.php';
459
+
460
+        /**
461
+         * The class responsible for defining all actions that occur in the admin area.
462
+         */
463
+        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin.php';
464
+
465
+        /**
466
+         * The class to customize the entity list admin page.
467
+         */
468
+        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin-entity-list.php';
469
+
470
+        /**
471
+         * The Entity Types Taxonomy Walker (transforms checkboxes into radios).
472
+         */
473
+        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-entity-types-taxonomy-walker.php';
474
+
475
+        /**
476
+         * The Notice service.
477
+         */
478
+        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-notice-service.php';
479
+
480
+        /**
481
+         * The PrimaShop adapter.
482
+         */
483
+        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-primashop-adapter.php';
484
+
485
+        /**
486
+         * The WordLift Dashboard service.
487
+         */
488
+        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin-dashboard.php';
489 489
 
490
-		/**
491
-		 * The admin 'Download Your Data' page.
492
-		 */
493
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-download-your-data-page.php';
490
+        /**
491
+         * The admin 'Download Your Data' page.
492
+         */
493
+        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-download-your-data-page.php';
494 494
 
495
-		/**
496
-		 * The class responsible for defining all actions that occur in the public-facing
497
-		 * side of the site.
498
-		 */
499
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-wordlift-public.php';
495
+        /**
496
+         * The class responsible for defining all actions that occur in the public-facing
497
+         * side of the site.
498
+         */
499
+        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-wordlift-public.php';
500 500
 
501
-		/**
502
-		 * The shortcode abstract class.
503
-		 */
504
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-wordlift-shortcode.php';
501
+        /**
502
+         * The shortcode abstract class.
503
+         */
504
+        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-wordlift-shortcode.php';
505 505
 
506
-		/**
507
-		 * The Timeline shortcode.
508
-		 */
509
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-wordlift-timeline-shortcode.php';
506
+        /**
507
+         * The Timeline shortcode.
508
+         */
509
+        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-wordlift-timeline-shortcode.php';
510 510
 
511
-		/**
512
-		 * The Navigator shortcode.
513
-		 */
514
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-wordlift-navigator-shortcode.php';
511
+        /**
512
+         * The Navigator shortcode.
513
+         */
514
+        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-wordlift-navigator-shortcode.php';
515 515
 
516
-		/**
517
-		 * The chord shortcode.
518
-		 */
519
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-wordlift-chord-shortcode.php';
516
+        /**
517
+         * The chord shortcode.
518
+         */
519
+        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-wordlift-chord-shortcode.php';
520 520
 
521
-		/**
522
-		 * The geomap shortcode.
523
-		 */
524
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-wordlift-geomap-shortcode.php';
521
+        /**
522
+         * The geomap shortcode.
523
+         */
524
+        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-wordlift-geomap-shortcode.php';
525 525
 
526
-		/**
527
-		 * The ShareThis service.
528
-		 */
529
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-wordlift-sharethis-service.php';
526
+        /**
527
+         * The ShareThis service.
528
+         */
529
+        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-wordlift-sharethis-service.php';
530 530
 
531
-		$this->loader = new Wordlift_Loader();
531
+        $this->loader = new Wordlift_Loader();
532 532
 
533
-		// Instantiate a global logger.
534
-		global $wl_logger;
535
-		$wl_logger = Wordlift_Log_Service::get_logger( 'WordLift' );
533
+        // Instantiate a global logger.
534
+        global $wl_logger;
535
+        $wl_logger = Wordlift_Log_Service::get_logger( 'WordLift' );
536 536
 
537
-		// Create the configuration service.
538
-		$configuration_service = new Wordlift_Configuration_Service();
537
+        // Create the configuration service.
538
+        $configuration_service = new Wordlift_Configuration_Service();
539 539
 
540
-		// Create an entity type service instance. It'll be later bound to the init action.
541
-		$this->entity_post_type_service = new Wordlift_Entity_Post_Type_Service( Wordlift_Entity_Service::TYPE_NAME, $configuration_service->get_entity_base_path() );
540
+        // Create an entity type service instance. It'll be later bound to the init action.
541
+        $this->entity_post_type_service = new Wordlift_Entity_Post_Type_Service( Wordlift_Entity_Service::TYPE_NAME, $configuration_service->get_entity_base_path() );
542 542
 
543
-		// Create an entity link service instance. It'll be later bound to the post_type_link and pre_get_posts actions.
544
-		$this->entity_link_service = new Wordlift_Entity_Link_Service( $this->entity_post_type_service, $configuration_service->get_entity_base_path() );
543
+        // Create an entity link service instance. It'll be later bound to the post_type_link and pre_get_posts actions.
544
+        $this->entity_link_service = new Wordlift_Entity_Link_Service( $this->entity_post_type_service, $configuration_service->get_entity_base_path() );
545 545
 
546
-		// Create an instance of the UI service.
547
-		$this->ui_service = new Wordlift_UI_Service();
546
+        // Create an instance of the UI service.
547
+        $this->ui_service = new Wordlift_UI_Service();
548 548
 
549
-		// Create an instance of the Thumbnail service. Later it'll be hooked to post meta events.
550
-		$this->thumbnail_service = new Wordlift_Thumbnail_Service();
549
+        // Create an instance of the Thumbnail service. Later it'll be hooked to post meta events.
550
+        $this->thumbnail_service = new Wordlift_Thumbnail_Service();
551 551
 
552
-		$this->sparql_service = new Wordlift_Sparql_Service();
552
+        $this->sparql_service = new Wordlift_Sparql_Service();
553 553
 
554
-		// Create an instance of the Schema service.
555
-		$schema_url_property_service = new Wordlift_Schema_Url_Property_Service( $this->sparql_service );
556
-		$this->schema_service        = new Wordlift_Schema_Service();
554
+        // Create an instance of the Schema service.
555
+        $schema_url_property_service = new Wordlift_Schema_Url_Property_Service( $this->sparql_service );
556
+        $this->schema_service        = new Wordlift_Schema_Service();
557 557
 
558
-		// Create an instance of the Notice service.
559
-		$this->notice_service = new Wordlift_Notice_Service();
558
+        // Create an instance of the Notice service.
559
+        $this->notice_service = new Wordlift_Notice_Service();
560 560
 
561
-		// Create an instance of the Entity service, passing the UI service to draw parts of the Entity admin page.
562
-		$this->entity_service = new Wordlift_Entity_Service( $this->ui_service, $this->schema_service, $this->notice_service );
561
+        // Create an instance of the Entity service, passing the UI service to draw parts of the Entity admin page.
562
+        $this->entity_service = new Wordlift_Entity_Service( $this->ui_service, $this->schema_service, $this->notice_service );
563 563
 
564
-		// Create an instance of the User service.
565
-		$this->user_service = new Wordlift_User_Service();
564
+        // Create an instance of the User service.
565
+        $this->user_service = new Wordlift_User_Service();
566 566
 
567
-		// Create a new instance of the Timeline service and Timeline shortcode.
568
-		$this->timeline_service = new Wordlift_Timeline_Service( $this->entity_service );
567
+        // Create a new instance of the Timeline service and Timeline shortcode.
568
+        $this->timeline_service = new Wordlift_Timeline_Service( $this->entity_service );
569 569
 
570
-		// Create a new instance of the Redirect service.
571
-		$this->redirect_service = new Wordlift_Redirect_Service( $this->entity_service );
570
+        // Create a new instance of the Redirect service.
571
+        $this->redirect_service = new Wordlift_Redirect_Service( $this->entity_service );
572 572
 
573
-		// Create a new instance of the Redirect service.
574
-		$this->dashboard_service = new Wordlift_Dashboard_Service( $this->entity_service );
573
+        // Create a new instance of the Redirect service.
574
+        $this->dashboard_service = new Wordlift_Dashboard_Service( $this->entity_service );
575 575
 
576
-		// Initialize the shortcodes.
577
-		new Wordlift_Navigator_Shortcode();
578
-		new Wordlift_Chord_Shortcode();
579
-		new Wordlift_Geomap_Shortcode();
580
-		new Wordlift_Timeline_Shortcode();
576
+        // Initialize the shortcodes.
577
+        new Wordlift_Navigator_Shortcode();
578
+        new Wordlift_Chord_Shortcode();
579
+        new Wordlift_Geomap_Shortcode();
580
+        new Wordlift_Timeline_Shortcode();
581 581
 
582
-		// Create entity list customization (wp-admin/edit.php)
583
-		$this->entity_list_service = new Wordlift_Entity_List_Service( $this->entity_service );
582
+        // Create entity list customization (wp-admin/edit.php)
583
+        $this->entity_list_service = new Wordlift_Entity_List_Service( $this->entity_service );
584 584
 
585
-		$this->entity_types_taxonomy_walker = new Wordlift_Entity_Types_Taxonomy_Walker();
585
+        $this->entity_types_taxonomy_walker = new Wordlift_Entity_Types_Taxonomy_Walker();
586 586
 
587
-		$this->topic_taxonomy_service = new Wordlift_Topic_Taxonomy_Service();
587
+        $this->topic_taxonomy_service = new Wordlift_Topic_Taxonomy_Service();
588 588
 
589
-		// Create an instance of the ShareThis service, later we hook it to the_content and the_excerpt filters.
590
-		$this->sharethis_service = new Wordlift_ShareThis_Service();
589
+        // Create an instance of the ShareThis service, later we hook it to the_content and the_excerpt filters.
590
+        $this->sharethis_service = new Wordlift_ShareThis_Service();
591 591
 
592
-		// Create an instance of the PrimaShop adapter.
593
-		$this->primashop_adapter = new Wordlift_PrimaShop_Adapter();
592
+        // Create an instance of the PrimaShop adapter.
593
+        $this->primashop_adapter = new Wordlift_PrimaShop_Adapter();
594 594
 
595
-		$this->page_service = new Wordlift_Page_Service();
595
+        $this->page_service = new Wordlift_Page_Service();
596 596
 
597
-		// Create an import service instance to hook later to WP's import function.
598
-		$this->import_service = new Wordlift_Import_Service( $this->entity_post_type_service, $this->entity_service, $this->schema_service, $this->sparql_service, wl_configuration_get_redlink_dataset_uri() );
597
+        // Create an import service instance to hook later to WP's import function.
598
+        $this->import_service = new Wordlift_Import_Service( $this->entity_post_type_service, $this->entity_service, $this->schema_service, $this->sparql_service, wl_configuration_get_redlink_dataset_uri() );
599 599
 
600
-		$uri_service = new Wordlift_Uri_Service( $GLOBALS['wpdb'] );
600
+        $uri_service = new Wordlift_Uri_Service( $GLOBALS['wpdb'] );
601 601
 
602
-		// Create a Rebuild Service instance, which we'll later bound to an ajax call.
603
-		$this->rebuild_service = new Wordlift_Rebuild_Service( $this->sparql_service, $uri_service );
602
+        // Create a Rebuild Service instance, which we'll later bound to an ajax call.
603
+        $this->rebuild_service = new Wordlift_Rebuild_Service( $this->sparql_service, $uri_service );
604 604
 
605
-		$entity_type_service = new Wordlift_Entity_Type_Service( $this->schema_service );
605
+        $entity_type_service = new Wordlift_Entity_Type_Service( $this->schema_service );
606 606
 
607
-		$this->property_factory = new Wordlift_Property_Factory( $schema_url_property_service );
608
-		$this->property_factory->register( Wordlift_Schema_Url_Property_Service::META_KEY, $schema_url_property_service );
607
+        $this->property_factory = new Wordlift_Property_Factory( $schema_url_property_service );
608
+        $this->property_factory->register( Wordlift_Schema_Url_Property_Service::META_KEY, $schema_url_property_service );
609 609
 
610
-		// Instantiate the JSON-LD service.
611
-		$property_getter                = Wordlift_Property_Getter_Factory::create( $this->entity_service );
612
-		$entity_uri_to_jsonld_converter = new Wordlift_Entity_Uri_To_Jsonld_Converter( $entity_type_service, $this->entity_service, $property_getter );
613
-		$this->jsonld_service           = new Wordlift_Jsonld_Service( $this->entity_service, $entity_uri_to_jsonld_converter );
610
+        // Instantiate the JSON-LD service.
611
+        $property_getter                = Wordlift_Property_Getter_Factory::create( $this->entity_service );
612
+        $entity_uri_to_jsonld_converter = new Wordlift_Entity_Uri_To_Jsonld_Converter( $entity_type_service, $this->entity_service, $property_getter );
613
+        $this->jsonld_service           = new Wordlift_Jsonld_Service( $this->entity_service, $entity_uri_to_jsonld_converter );
614 614
 
615
-		//** WordPress Admin */
616
-		$this->download_your_data_page = new Wordlift_Admin_Download_Your_Data_Page();
615
+        //** WordPress Admin */
616
+        $this->download_your_data_page = new Wordlift_Admin_Download_Your_Data_Page();
617 617
 
618
-		// Create an instance of the content filter service.
619
-		$this->content_filter_service = new Wordlift_Content_Filter_Service( $this->entity_service );
618
+        // Create an instance of the content filter service.
619
+        $this->content_filter_service = new Wordlift_Content_Filter_Service( $this->entity_service );
620 620
 
621
-		// Load the debug service if WP is in debug mode.
622
-		if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
623
-			require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-debug-service.php';
624
-			new Wordlift_Debug_Service( $this->entity_service );
625
-		}
621
+        // Load the debug service if WP is in debug mode.
622
+        if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
623
+            require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-debug-service.php';
624
+            new Wordlift_Debug_Service( $this->entity_service );
625
+        }
626 626
 
627
-	}
627
+    }
628 628
 
629
-	/**
630
-	 * Define the locale for this plugin for internationalization.
631
-	 *
632
-	 * Uses the Wordlift_i18n class in order to set the domain and to register the hook
633
-	 * with WordPress.
634
-	 *
635
-	 * @since    1.0.0
636
-	 * @access   private
637
-	 */
638
-	private function set_locale() {
629
+    /**
630
+     * Define the locale for this plugin for internationalization.
631
+     *
632
+     * Uses the Wordlift_i18n class in order to set the domain and to register the hook
633
+     * with WordPress.
634
+     *
635
+     * @since    1.0.0
636
+     * @access   private
637
+     */
638
+    private function set_locale() {
639 639
 
640
-		$plugin_i18n = new Wordlift_i18n();
641
-		$plugin_i18n->set_domain( $this->get_plugin_name() );
640
+        $plugin_i18n = new Wordlift_i18n();
641
+        $plugin_i18n->set_domain( $this->get_plugin_name() );
642 642
 
643
-		$this->loader->add_action( 'plugins_loaded', $plugin_i18n, 'load_plugin_textdomain' );
643
+        $this->loader->add_action( 'plugins_loaded', $plugin_i18n, 'load_plugin_textdomain' );
644 644
 
645
-	}
645
+    }
646 646
 
647
-	/**
648
-	 * Register all of the hooks related to the admin area functionality
649
-	 * of the plugin.
650
-	 *
651
-	 * @since    1.0.0
652
-	 * @access   private
653
-	 */
654
-	private function define_admin_hooks() {
647
+    /**
648
+     * Register all of the hooks related to the admin area functionality
649
+     * of the plugin.
650
+     *
651
+     * @since    1.0.0
652
+     * @access   private
653
+     */
654
+    private function define_admin_hooks() {
655 655
 
656
-		$plugin_admin = new Wordlift_Admin( $this->get_plugin_name(), $this->get_version() );
656
+        $plugin_admin = new Wordlift_Admin( $this->get_plugin_name(), $this->get_version() );
657 657
 
658
-		$this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' );
659
-		$this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' );
658
+        $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' );
659
+        $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' );
660 660
 
661
-		// Hook the init action to the Topic Taxonomy service.
662
-		$this->loader->add_action( 'init', $this->topic_taxonomy_service, 'init', 0 );
661
+        // Hook the init action to the Topic Taxonomy service.
662
+        $this->loader->add_action( 'init', $this->topic_taxonomy_service, 'init', 0 );
663 663
 
664
-		// Hook the deleted_post_meta action to the Thumbnail service.
665
-		$this->loader->add_action( 'deleted_post_meta', $this->thumbnail_service, 'deleted_post_meta', 10, 4 );
664
+        // Hook the deleted_post_meta action to the Thumbnail service.
665
+        $this->loader->add_action( 'deleted_post_meta', $this->thumbnail_service, 'deleted_post_meta', 10, 4 );
666 666
 
667
-		// Hook the added_post_meta action to the Thumbnail service.
668
-		$this->loader->add_action( 'added_post_meta', $this->thumbnail_service, 'added_or_updated_post_meta', 10, 4 );
667
+        // Hook the added_post_meta action to the Thumbnail service.
668
+        $this->loader->add_action( 'added_post_meta', $this->thumbnail_service, 'added_or_updated_post_meta', 10, 4 );
669 669
 
670
-		// Hook the updated_post_meta action to the Thumbnail service.
671
-		$this->loader->add_action( 'updated_post_meta', $this->thumbnail_service, 'added_or_updated_post_meta', 10, 4 );
670
+        // Hook the updated_post_meta action to the Thumbnail service.
671
+        $this->loader->add_action( 'updated_post_meta', $this->thumbnail_service, 'added_or_updated_post_meta', 10, 4 );
672 672
 
673
-		// Hook posts inserts (or updates) to the user service.
674
-		$this->loader->add_action( 'wp_insert_post', $this->user_service, 'wp_insert_post', 10, 3 );
673
+        // Hook posts inserts (or updates) to the user service.
674
+        $this->loader->add_action( 'wp_insert_post', $this->user_service, 'wp_insert_post', 10, 3 );
675 675
 
676
-		// Hook the AJAX wl_timeline action to the Timeline service.
677
-		$this->loader->add_action( 'wp_ajax_wl_timeline', $this->timeline_service, 'ajax_timeline' );
676
+        // Hook the AJAX wl_timeline action to the Timeline service.
677
+        $this->loader->add_action( 'wp_ajax_wl_timeline', $this->timeline_service, 'ajax_timeline' );
678 678
 
679
-		// Register custom allowed redirect hosts.
680
-		$this->loader->add_filter( 'allowed_redirect_hosts', $this->redirect_service, 'allowed_redirect_hosts' );
681
-		// Hook the AJAX wordlift_redirect action to the Redirect service.
682
-		$this->loader->add_action( 'wp_ajax_wordlift_redirect', $this->redirect_service, 'ajax_redirect' );
683
-		// Hook the AJAX wordlift_redirect action to the Redirect service.
684
-		$this->loader->add_action( 'wp_ajax_wordlift_get_stats', $this->dashboard_service, 'ajax_get_stats' );
685
-		// Hook the AJAX wordlift_redirect action to the Redirect service.
686
-		$this->loader->add_action( 'wp_dashboard_setup', $this->dashboard_service, 'add_dashboard_widgets' );
679
+        // Register custom allowed redirect hosts.
680
+        $this->loader->add_filter( 'allowed_redirect_hosts', $this->redirect_service, 'allowed_redirect_hosts' );
681
+        // Hook the AJAX wordlift_redirect action to the Redirect service.
682
+        $this->loader->add_action( 'wp_ajax_wordlift_redirect', $this->redirect_service, 'ajax_redirect' );
683
+        // Hook the AJAX wordlift_redirect action to the Redirect service.
684
+        $this->loader->add_action( 'wp_ajax_wordlift_get_stats', $this->dashboard_service, 'ajax_get_stats' );
685
+        // Hook the AJAX wordlift_redirect action to the Redirect service.
686
+        $this->loader->add_action( 'wp_dashboard_setup', $this->dashboard_service, 'add_dashboard_widgets' );
687 687
 
688
-		// Hook save_post to the entity service to update custom fields (such as alternate labels).
689
-		// We have a priority of 9 because we want to be executed before data is sent to Redlink.
690
-		$this->loader->add_action( 'save_post', $this->entity_service, 'save_post', 9, 3 );
691
-		$this->loader->add_action( 'save_post_entity', $this->entity_service, 'set_rating_for', 10, 1 );
688
+        // Hook save_post to the entity service to update custom fields (such as alternate labels).
689
+        // We have a priority of 9 because we want to be executed before data is sent to Redlink.
690
+        $this->loader->add_action( 'save_post', $this->entity_service, 'save_post', 9, 3 );
691
+        $this->loader->add_action( 'save_post_entity', $this->entity_service, 'set_rating_for', 10, 1 );
692 692
 
693
-		$this->loader->add_action( 'edit_form_before_permalink', $this->entity_service, 'edit_form_before_permalink', 10, 1 );
694
-		$this->loader->add_action( 'in_admin_header', $this->entity_service, 'in_admin_header' );
693
+        $this->loader->add_action( 'edit_form_before_permalink', $this->entity_service, 'edit_form_before_permalink', 10, 1 );
694
+        $this->loader->add_action( 'in_admin_header', $this->entity_service, 'in_admin_header' );
695 695
 
696
-		// Entity listing customization (wp-admin/edit.php)
697
-		// Add custom columns
698
-		$this->loader->add_filter( 'manage_entity_posts_columns', $this->entity_list_service, 'register_custom_columns' );
699
-		$this->loader->add_filter( 'manage_entity_posts_custom_column', $this->entity_list_service, 'render_custom_columns', 10, 2 );
700
-		// Add 4W selection
701
-		$this->loader->add_action( 'restrict_manage_posts', $this->entity_list_service, 'restrict_manage_posts_classification_scope' );
702
-		$this->loader->add_filter( 'posts_clauses', $this->entity_list_service, 'posts_clauses_classification_scope' );
703
-
704
-		$this->loader->add_filter( 'wp_terms_checklist_args', $this->entity_types_taxonomy_walker, 'terms_checklist_args' );
705
-
706
-		// Hook the PrimaShop adapter to <em>prima_metabox_entity_header_args</em> in order to add header support for
707
-		// entities.
708
-		$this->loader->add_filter( 'prima_metabox_entity_header_args', $this->primashop_adapter, 'prima_metabox_entity_header_args', 10, 2 );
709
-
710
-		// Filter imported post meta.
711
-		$this->loader->add_filter( 'wp_import_post_meta', $this->import_service, 'wp_import_post_meta', 10, 3 );
712
-
713
-		// Notify the import service when an import starts and ends.
714
-		$this->loader->add_action( 'import_start', $this->import_service, 'import_start', 10, 0 );
715
-		$this->loader->add_action( 'import_end', $this->import_service, 'import_end', 10, 0 );
716
-
717
-		// Hook the AJAX wl_rebuild action to the Rebuild Service.
718
-		$this->loader->add_action( 'wp_ajax_wl_rebuild', $this->rebuild_service, 'rebuild' );
719
-
720
-		// Hook the menu to the Download Your Data page.
721
-		$this->loader->add_action( 'admin_menu', $this->download_your_data_page, 'admin_menu', 100, 0 );
722
-
723
-		// Hook the admin-ajax.php?action=wl_download_your_data&out=xyz links.
724
-		$this->loader->add_action( 'wp_ajax_wl_download_your_data', $this->download_your_data_page, 'download_your_data', 10 );
725
-
726
-		// Hook the AJAX wl_jsonld action to the JSON-LD service.
727
-		$this->loader->add_action( 'wp_ajax_wl_jsonld', $this->jsonld_service, 'get' );
728
-
729
-	}
730
-
731
-	/**
732
-	 * Register all of the hooks related to the public-facing functionality
733
-	 * of the plugin.
734
-	 *
735
-	 * @since    1.0.0
736
-	 * @access   private
737
-	 */
738
-	private function define_public_hooks() {
739
-
740
-		$plugin_public = new Wordlift_Public( $this->get_plugin_name(), $this->get_version() );
741
-
742
-		// Register the entity post type.
743
-		$this->loader->add_action( 'init', $this->entity_post_type_service, 'register' );
744
-
745
-		// Bind the link generation and handling hooks to the entity link service.
746
-		$this->loader->add_filter( 'post_type_link', $this->entity_link_service, 'post_type_link', 10, 4 );
747
-		$this->loader->add_action( 'pre_get_posts', $this->entity_link_service, 'pre_get_posts', 10, 1 );
748
-		$this->loader->add_filter( 'wp_unique_post_slug_is_bad_flat_slug', $this->entity_link_service, 'wp_unique_post_slug_is_bad_flat_slug', 10, 3 );
749
-		$this->loader->add_filter( 'wp_unique_post_slug_is_bad_hierarchical_slug', $this->entity_link_service, 'wp_unique_post_slug_is_bad_hierarchical_slug', 10, 4 );
750
-
751
-		$this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_styles' );
752
-		$this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts' );
753
-
754
-		// Hook the content filter service to add entity links.
755
-		$this->loader->add_filter( 'the_content', $this->content_filter_service, 'the_content');
756
-
757
-		// Hook the AJAX wl_timeline action to the Timeline service.
758
-		$this->loader->add_action( 'wp_ajax_nopriv_wl_timeline', $this->timeline_service, 'ajax_timeline' );
759
-
760
-		// Hook the ShareThis service.
761
-		$this->loader->add_filter( 'the_content', $this->sharethis_service, 'the_content', 99 );
762
-		$this->loader->add_filter( 'the_excerpt', $this->sharethis_service, 'the_excerpt', 99 );
763
-
764
-		$this->loader->add_action( 'wp_head', $this->page_service, 'wp_head', PHP_INT_MAX );
765
-		$this->loader->add_action( 'wp_footer', $this->page_service, 'wp_head', - PHP_INT_MAX );
766
-
767
-		// Hook the AJAX wl_jsonld action to the JSON-LD service.
768
-		$this->loader->add_action( 'wp_ajax_nopriv_wl_jsonld', $this->jsonld_service, 'get' );
769
-
770
-	}
771
-
772
-	/**
773
-	 * Run the loader to execute all of the hooks with WordPress.
774
-	 *
775
-	 * @since    1.0.0
776
-	 */
777
-	public function run() {
778
-		$this->loader->run();
779
-	}
780
-
781
-	/**
782
-	 * The name of the plugin used to uniquely identify it within the context of
783
-	 * WordPress and to define internationalization functionality.
784
-	 *
785
-	 * @since     1.0.0
786
-	 * @return    string    The name of the plugin.
787
-	 */
788
-	public function get_plugin_name() {
789
-		return $this->plugin_name;
790
-	}
791
-
792
-	/**
793
-	 * The reference to the class that orchestrates the hooks with the plugin.
794
-	 *
795
-	 * @since     1.0.0
796
-	 * @return    Wordlift_Loader    Orchestrates the hooks of the plugin.
797
-	 */
798
-	public function get_loader() {
799
-		return $this->loader;
800
-	}
801
-
802
-	/**
803
-	 * Retrieve the version number of the plugin.
804
-	 *
805
-	 * @since     1.0.0
806
-	 * @return    string    The version number of the plugin.
807
-	 */
808
-	public function get_version() {
809
-		return $this->version;
810
-	}
696
+        // Entity listing customization (wp-admin/edit.php)
697
+        // Add custom columns
698
+        $this->loader->add_filter( 'manage_entity_posts_columns', $this->entity_list_service, 'register_custom_columns' );
699
+        $this->loader->add_filter( 'manage_entity_posts_custom_column', $this->entity_list_service, 'render_custom_columns', 10, 2 );
700
+        // Add 4W selection
701
+        $this->loader->add_action( 'restrict_manage_posts', $this->entity_list_service, 'restrict_manage_posts_classification_scope' );
702
+        $this->loader->add_filter( 'posts_clauses', $this->entity_list_service, 'posts_clauses_classification_scope' );
703
+
704
+        $this->loader->add_filter( 'wp_terms_checklist_args', $this->entity_types_taxonomy_walker, 'terms_checklist_args' );
705
+
706
+        // Hook the PrimaShop adapter to <em>prima_metabox_entity_header_args</em> in order to add header support for
707
+        // entities.
708
+        $this->loader->add_filter( 'prima_metabox_entity_header_args', $this->primashop_adapter, 'prima_metabox_entity_header_args', 10, 2 );
709
+
710
+        // Filter imported post meta.
711
+        $this->loader->add_filter( 'wp_import_post_meta', $this->import_service, 'wp_import_post_meta', 10, 3 );
712
+
713
+        // Notify the import service when an import starts and ends.
714
+        $this->loader->add_action( 'import_start', $this->import_service, 'import_start', 10, 0 );
715
+        $this->loader->add_action( 'import_end', $this->import_service, 'import_end', 10, 0 );
716
+
717
+        // Hook the AJAX wl_rebuild action to the Rebuild Service.
718
+        $this->loader->add_action( 'wp_ajax_wl_rebuild', $this->rebuild_service, 'rebuild' );
719
+
720
+        // Hook the menu to the Download Your Data page.
721
+        $this->loader->add_action( 'admin_menu', $this->download_your_data_page, 'admin_menu', 100, 0 );
722
+
723
+        // Hook the admin-ajax.php?action=wl_download_your_data&out=xyz links.
724
+        $this->loader->add_action( 'wp_ajax_wl_download_your_data', $this->download_your_data_page, 'download_your_data', 10 );
725
+
726
+        // Hook the AJAX wl_jsonld action to the JSON-LD service.
727
+        $this->loader->add_action( 'wp_ajax_wl_jsonld', $this->jsonld_service, 'get' );
728
+
729
+    }
730
+
731
+    /**
732
+     * Register all of the hooks related to the public-facing functionality
733
+     * of the plugin.
734
+     *
735
+     * @since    1.0.0
736
+     * @access   private
737
+     */
738
+    private function define_public_hooks() {
739
+
740
+        $plugin_public = new Wordlift_Public( $this->get_plugin_name(), $this->get_version() );
741
+
742
+        // Register the entity post type.
743
+        $this->loader->add_action( 'init', $this->entity_post_type_service, 'register' );
744
+
745
+        // Bind the link generation and handling hooks to the entity link service.
746
+        $this->loader->add_filter( 'post_type_link', $this->entity_link_service, 'post_type_link', 10, 4 );
747
+        $this->loader->add_action( 'pre_get_posts', $this->entity_link_service, 'pre_get_posts', 10, 1 );
748
+        $this->loader->add_filter( 'wp_unique_post_slug_is_bad_flat_slug', $this->entity_link_service, 'wp_unique_post_slug_is_bad_flat_slug', 10, 3 );
749
+        $this->loader->add_filter( 'wp_unique_post_slug_is_bad_hierarchical_slug', $this->entity_link_service, 'wp_unique_post_slug_is_bad_hierarchical_slug', 10, 4 );
750
+
751
+        $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_styles' );
752
+        $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts' );
753
+
754
+        // Hook the content filter service to add entity links.
755
+        $this->loader->add_filter( 'the_content', $this->content_filter_service, 'the_content');
756
+
757
+        // Hook the AJAX wl_timeline action to the Timeline service.
758
+        $this->loader->add_action( 'wp_ajax_nopriv_wl_timeline', $this->timeline_service, 'ajax_timeline' );
759
+
760
+        // Hook the ShareThis service.
761
+        $this->loader->add_filter( 'the_content', $this->sharethis_service, 'the_content', 99 );
762
+        $this->loader->add_filter( 'the_excerpt', $this->sharethis_service, 'the_excerpt', 99 );
763
+
764
+        $this->loader->add_action( 'wp_head', $this->page_service, 'wp_head', PHP_INT_MAX );
765
+        $this->loader->add_action( 'wp_footer', $this->page_service, 'wp_head', - PHP_INT_MAX );
766
+
767
+        // Hook the AJAX wl_jsonld action to the JSON-LD service.
768
+        $this->loader->add_action( 'wp_ajax_nopriv_wl_jsonld', $this->jsonld_service, 'get' );
769
+
770
+    }
771
+
772
+    /**
773
+     * Run the loader to execute all of the hooks with WordPress.
774
+     *
775
+     * @since    1.0.0
776
+     */
777
+    public function run() {
778
+        $this->loader->run();
779
+    }
780
+
781
+    /**
782
+     * The name of the plugin used to uniquely identify it within the context of
783
+     * WordPress and to define internationalization functionality.
784
+     *
785
+     * @since     1.0.0
786
+     * @return    string    The name of the plugin.
787
+     */
788
+    public function get_plugin_name() {
789
+        return $this->plugin_name;
790
+    }
791
+
792
+    /**
793
+     * The reference to the class that orchestrates the hooks with the plugin.
794
+     *
795
+     * @since     1.0.0
796
+     * @return    Wordlift_Loader    Orchestrates the hooks of the plugin.
797
+     */
798
+    public function get_loader() {
799
+        return $this->loader;
800
+    }
801
+
802
+    /**
803
+     * Retrieve the version number of the plugin.
804
+     *
805
+     * @since     1.0.0
806
+     * @return    string    The version number of the plugin.
807
+     */
808
+    public function get_version() {
809
+        return $this->version;
810
+    }
811 811
 
812 812
 }
Please login to merge, or discard this patch.