@@ -7,278 +7,278 @@ |
||
| 7 | 7 | */ |
| 8 | 8 | class Wordlift_Query_Builder { |
| 9 | 9 | |
| 10 | - /** |
|
| 11 | - * The INSERT statement template. |
|
| 12 | - * |
|
| 13 | - * @since 3.1.7 |
|
| 14 | - */ |
|
| 15 | - const INSERT = 'INSERT DATA { %s };'; |
|
| 16 | - |
|
| 17 | - /** |
|
| 18 | - * The DELETE statement template (it repeats the statements in the WHERE clause. |
|
| 19 | - * |
|
| 20 | - * @since 3.1.7 |
|
| 21 | - */ |
|
| 22 | - const DELETE = 'DELETE { %s } WHERE { %1$s };'; |
|
| 23 | - |
|
| 24 | - /** |
|
| 25 | - * Tell the statement function to guess the object type (URI, value or parameter). |
|
| 26 | - * |
|
| 27 | - * @since 3.1.7 |
|
| 28 | - */ |
|
| 29 | - const OBJECT_AUTO = - 1; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * Tell the statement function that the object is a URI. |
|
| 33 | - * |
|
| 34 | - * @since 3.1.7 |
|
| 35 | - */ |
|
| 36 | - const OBJECT_URI = 0; |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * Tell the statement function that the object is a value. |
|
| 40 | - * |
|
| 41 | - * @since 3.1.7 |
|
| 42 | - */ |
|
| 43 | - const OBJECT_VALUE = 1; |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * Tell the statement function that the object is a parameter. |
|
| 47 | - * |
|
| 48 | - * @since 3.1.7 |
|
| 49 | - */ |
|
| 50 | - const OBJECT_PARAMETER = 2; |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * The RDFS type. |
|
| 54 | - * |
|
| 55 | - * @since 3.1.7 |
|
| 56 | - */ |
|
| 57 | - const RDFS_TYPE_URI = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type'; |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * The schema.org/Person type. |
|
| 61 | - * |
|
| 62 | - * @since 3.1.7 |
|
| 63 | - */ |
|
| 64 | - const SCHEMA_PERSON_URI = 'http://schema.org/Person'; |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * The schema.org given name predicate. |
|
| 68 | - * |
|
| 69 | - * @since 3.1.7 |
|
| 70 | - */ |
|
| 71 | - const SCHEMA_GIVEN_NAME_URI = 'http://schema.org/givenName'; |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * The schema.org family name predicate. |
|
| 75 | - * |
|
| 76 | - * @since 3.1.7 |
|
| 77 | - */ |
|
| 78 | - const SCHEMA_FAMILY_NAME_URI = 'http://schema.org/familyName'; |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * The schema.org url predicate. |
|
| 82 | - * |
|
| 83 | - * @since 3.1.7 |
|
| 84 | - */ |
|
| 85 | - const SCHEMA_URL_URI = 'http://schema.org/url'; |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * The RDF label. |
|
| 89 | - * |
|
| 90 | - * @since 3.1.7 |
|
| 91 | - */ |
|
| 92 | - const RDFS_LABEL_URI = 'http://www.w3.org/2000/01/rdf-schema#label'; |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * Hold the template (INSERT or DELETE). |
|
| 96 | - * |
|
| 97 | - * @since 3.1.7 |
|
| 98 | - * @access private |
|
| 99 | - * @var string $template The query template. |
|
| 100 | - */ |
|
| 101 | - private $template; |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * An array of statements (in the form of subject, predicate, object). |
|
| 105 | - * |
|
| 106 | - * @since 3.1.7 |
|
| 107 | - * @access private |
|
| 108 | - * @var array $statements An array of statements. |
|
| 109 | - */ |
|
| 110 | - private $statements = array(); |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * Create a new instance of the Query builder (compatible with PHP 5.3). |
|
| 114 | - * |
|
| 115 | - * @since 3.1.7 |
|
| 116 | - * @return Wordlift_Query_Builder A new instance of the Query builder. |
|
| 117 | - */ |
|
| 118 | - public static function new_instance() { |
|
| 119 | - |
|
| 120 | - return new Wordlift_Query_Builder(); |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * Set the query to INSERT. |
|
| 125 | - * |
|
| 126 | - * @since 3.1.7 |
|
| 127 | - * @return $this \Wordlift_Query_Builder The Query builder. |
|
| 128 | - */ |
|
| 129 | - public function insert() { |
|
| 130 | - |
|
| 131 | - $this->template = self::INSERT; |
|
| 132 | - |
|
| 133 | - return $this; |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - /** |
|
| 137 | - * Set the query to DELETE. |
|
| 138 | - * |
|
| 139 | - * @since 3.1.7 |
|
| 140 | - * @return $this \Wordlift_Query_Builder The Query builder. |
|
| 141 | - */ |
|
| 142 | - public function delete() { |
|
| 143 | - |
|
| 144 | - $this->template = self::DELETE; |
|
| 145 | - |
|
| 146 | - return $this; |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - /** |
|
| 150 | - * Add a statement. |
|
| 151 | - * |
|
| 152 | - * @since 3.1.7 |
|
| 153 | - * |
|
| 154 | - * @param string $subject The subject of the statement (must be a URI). |
|
| 155 | - * @param string $predicate The predicate (must be a URI). |
|
| 156 | - * @param string $object The object, can be a URI or a value. |
|
| 157 | - * @param int $object_type The object type, either a {@link OBJECT_URI} or a value {@link OBJECT_VALUE}. If set to {@link OBJECT_AUTO}, the Query builder will try to guess. |
|
| 158 | - * @param string|null $data_type The data type (or null). |
|
| 159 | - * @param string|null $language The language code (or null). |
|
| 160 | - * |
|
| 161 | - * @return $this \Wordlift_Query_Builder The Query builder. |
|
| 162 | - */ |
|
| 163 | - public function statement( $subject, $predicate, $object, $object_type = self::OBJECT_AUTO, $data_type = null, $language = null ) { |
|
| 164 | - |
|
| 165 | - // If no value has been provided, we don't set any statement. |
|
| 166 | - if ( empty( $object ) ) { |
|
| 167 | - return $this; |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - // Get the object type if set, otherwise try to guess it. |
|
| 171 | - $object_value_type = ( self::OBJECT_AUTO !== $object_type ?: $this->guess_object_type( $predicate, $object ) ); |
|
| 172 | - |
|
| 173 | - // Prepare the statement template. |
|
| 174 | - $template = '<%1$s> <%2$s> ' . ( |
|
| 175 | - self::OBJECT_URI === $object_value_type ? '<%3$s>' : ( |
|
| 176 | - self::OBJECT_PARAMETER === $object_value_type ? '%3$s' : |
|
| 177 | - // self::OBJECT_VALUE === $object_value_type |
|
| 178 | - '"%3$s"' . ( isset( $data_type ) ? '^^%4$s' : '' ) . ( isset( $language ) ? '@%5$s' : '' ) ) ); |
|
| 179 | - |
|
| 180 | - // Escape the subject, predicate and object. |
|
| 181 | - $escaped_subject = $this->escape_uri( $subject ); |
|
| 182 | - $escaped_predicate = $this->escape_uri( $predicate ); |
|
| 183 | - $escaped_object = ( self::OBJECT_URI === $object_value_type ? $this->escape_uri( $object ) : $this->escape_value( $object ) ); |
|
| 184 | - |
|
| 185 | - // Prepare the statement and add it to the list of statements. |
|
| 186 | - $this->statements[] = sprintf( $template, $escaped_subject, $escaped_predicate, $escaped_object, $data_type, $language ); |
|
| 187 | - |
|
| 188 | - return $this; |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - /** |
|
| 192 | - * Build the query. |
|
| 193 | - * |
|
| 194 | - * @since 3.1.7 |
|
| 195 | - * @return string The query string. |
|
| 196 | - */ |
|
| 197 | - public function build() { |
|
| 198 | - |
|
| 199 | - return sprintf( $this->template, implode( ' . ', $this->statements ) ) . "\n"; |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - /** |
|
| 203 | - * Guess the statement object type. |
|
| 204 | - * |
|
| 205 | - * @since 3.1.7 |
|
| 206 | - * |
|
| 207 | - * @param string $predicate The predicate. |
|
| 208 | - * @param string $object The object. |
|
| 209 | - * |
|
| 210 | - * @return int {@link Wordlift_Query_Builder::OBJECT_URI} if the Query builder thinks the object must be an URI, {@link Wordlift_Query_Builder::OBJECT_VALUE} otherwise. |
|
| 211 | - */ |
|
| 212 | - private function guess_object_type( $predicate, $object ) { |
|
| 213 | - |
|
| 214 | - // If the object starts with a question mark, it's a parameter. |
|
| 215 | - if ( 0 === strpos( $object, '?' ) ) { |
|
| 216 | - return self::OBJECT_PARAMETER; |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - // Guess based on the predicate. |
|
| 220 | - switch ( $predicate ) { |
|
| 221 | - |
|
| 222 | - case self::RDFS_TYPE_URI: |
|
| 223 | - case self::SCHEMA_URL_URI: |
|
| 224 | - return self::OBJECT_URI; |
|
| 225 | - |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - return self::OBJECT_VALUE; |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - /** |
|
| 232 | - * Escape a URI. |
|
| 233 | - * |
|
| 234 | - * @since 3.1.7 |
|
| 235 | - * |
|
| 236 | - * @param string $uri The URI to escape. |
|
| 237 | - * |
|
| 238 | - * @return string The escaped URI. |
|
| 239 | - */ |
|
| 240 | - private function escape_uri( $uri ) { |
|
| 241 | - |
|
| 242 | - // Should we validate the IRI? |
|
| 243 | - // http://www.w3.org/TR/sparql11-query/#QSynIRI |
|
| 244 | - |
|
| 245 | - $escaped_uri = str_replace( '<', '\<', $uri ); |
|
| 246 | - $escaped_uri = str_replace( '>', '\>', $escaped_uri ); |
|
| 247 | - |
|
| 248 | - return $escaped_uri; |
|
| 249 | - } |
|
| 250 | - |
|
| 251 | - /** |
|
| 252 | - * Escape a value. |
|
| 253 | - * |
|
| 254 | - * @since 3.1.7 |
|
| 255 | - * |
|
| 256 | - * @param string $value The value to escape. |
|
| 257 | - * |
|
| 258 | - * @return string The escaped value. |
|
| 259 | - */ |
|
| 260 | - private function escape_value( $value ) { |
|
| 261 | - |
|
| 262 | - // see http://www.w3.org/TR/rdf-sparql-query/ |
|
| 263 | - // '\t' U+0009 (tab) |
|
| 264 | - // '\n' U+000A (line feed) |
|
| 265 | - // '\r' U+000D (carriage return) |
|
| 266 | - // '\b' U+0008 (backspace) |
|
| 267 | - // '\f' U+000C (form feed) |
|
| 268 | - // '\"' U+0022 (quotation mark, double quote mark) |
|
| 269 | - // "\'" U+0027 (apostrophe-quote, single quote mark) |
|
| 270 | - // '\\' U+005C (backslash) |
|
| 271 | - |
|
| 272 | - $escaped_value = str_replace( '\\', '\\\\', $value ); |
|
| 273 | - $escaped_value = str_replace( '\'', '\\\'', $escaped_value ); |
|
| 274 | - $escaped_value = str_replace( '"', '\\"', $escaped_value ); |
|
| 275 | - $escaped_value = str_replace( "\f", '\\f', $escaped_value ); |
|
| 276 | - $escaped_value = str_replace( "\b", '\\b', $escaped_value ); |
|
| 277 | - $escaped_value = str_replace( "\r", '\\r', $escaped_value ); |
|
| 278 | - $escaped_value = str_replace( "\n", '\\n', $escaped_value ); |
|
| 279 | - $escaped_value = str_replace( "\t", '\\t', $escaped_value ); |
|
| 280 | - |
|
| 281 | - return $escaped_value; |
|
| 282 | - } |
|
| 10 | + /** |
|
| 11 | + * The INSERT statement template. |
|
| 12 | + * |
|
| 13 | + * @since 3.1.7 |
|
| 14 | + */ |
|
| 15 | + const INSERT = 'INSERT DATA { %s };'; |
|
| 16 | + |
|
| 17 | + /** |
|
| 18 | + * The DELETE statement template (it repeats the statements in the WHERE clause. |
|
| 19 | + * |
|
| 20 | + * @since 3.1.7 |
|
| 21 | + */ |
|
| 22 | + const DELETE = 'DELETE { %s } WHERE { %1$s };'; |
|
| 23 | + |
|
| 24 | + /** |
|
| 25 | + * Tell the statement function to guess the object type (URI, value or parameter). |
|
| 26 | + * |
|
| 27 | + * @since 3.1.7 |
|
| 28 | + */ |
|
| 29 | + const OBJECT_AUTO = - 1; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * Tell the statement function that the object is a URI. |
|
| 33 | + * |
|
| 34 | + * @since 3.1.7 |
|
| 35 | + */ |
|
| 36 | + const OBJECT_URI = 0; |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * Tell the statement function that the object is a value. |
|
| 40 | + * |
|
| 41 | + * @since 3.1.7 |
|
| 42 | + */ |
|
| 43 | + const OBJECT_VALUE = 1; |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * Tell the statement function that the object is a parameter. |
|
| 47 | + * |
|
| 48 | + * @since 3.1.7 |
|
| 49 | + */ |
|
| 50 | + const OBJECT_PARAMETER = 2; |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * The RDFS type. |
|
| 54 | + * |
|
| 55 | + * @since 3.1.7 |
|
| 56 | + */ |
|
| 57 | + const RDFS_TYPE_URI = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type'; |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * The schema.org/Person type. |
|
| 61 | + * |
|
| 62 | + * @since 3.1.7 |
|
| 63 | + */ |
|
| 64 | + const SCHEMA_PERSON_URI = 'http://schema.org/Person'; |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * The schema.org given name predicate. |
|
| 68 | + * |
|
| 69 | + * @since 3.1.7 |
|
| 70 | + */ |
|
| 71 | + const SCHEMA_GIVEN_NAME_URI = 'http://schema.org/givenName'; |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * The schema.org family name predicate. |
|
| 75 | + * |
|
| 76 | + * @since 3.1.7 |
|
| 77 | + */ |
|
| 78 | + const SCHEMA_FAMILY_NAME_URI = 'http://schema.org/familyName'; |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * The schema.org url predicate. |
|
| 82 | + * |
|
| 83 | + * @since 3.1.7 |
|
| 84 | + */ |
|
| 85 | + const SCHEMA_URL_URI = 'http://schema.org/url'; |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * The RDF label. |
|
| 89 | + * |
|
| 90 | + * @since 3.1.7 |
|
| 91 | + */ |
|
| 92 | + const RDFS_LABEL_URI = 'http://www.w3.org/2000/01/rdf-schema#label'; |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * Hold the template (INSERT or DELETE). |
|
| 96 | + * |
|
| 97 | + * @since 3.1.7 |
|
| 98 | + * @access private |
|
| 99 | + * @var string $template The query template. |
|
| 100 | + */ |
|
| 101 | + private $template; |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * An array of statements (in the form of subject, predicate, object). |
|
| 105 | + * |
|
| 106 | + * @since 3.1.7 |
|
| 107 | + * @access private |
|
| 108 | + * @var array $statements An array of statements. |
|
| 109 | + */ |
|
| 110 | + private $statements = array(); |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * Create a new instance of the Query builder (compatible with PHP 5.3). |
|
| 114 | + * |
|
| 115 | + * @since 3.1.7 |
|
| 116 | + * @return Wordlift_Query_Builder A new instance of the Query builder. |
|
| 117 | + */ |
|
| 118 | + public static function new_instance() { |
|
| 119 | + |
|
| 120 | + return new Wordlift_Query_Builder(); |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * Set the query to INSERT. |
|
| 125 | + * |
|
| 126 | + * @since 3.1.7 |
|
| 127 | + * @return $this \Wordlift_Query_Builder The Query builder. |
|
| 128 | + */ |
|
| 129 | + public function insert() { |
|
| 130 | + |
|
| 131 | + $this->template = self::INSERT; |
|
| 132 | + |
|
| 133 | + return $this; |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + /** |
|
| 137 | + * Set the query to DELETE. |
|
| 138 | + * |
|
| 139 | + * @since 3.1.7 |
|
| 140 | + * @return $this \Wordlift_Query_Builder The Query builder. |
|
| 141 | + */ |
|
| 142 | + public function delete() { |
|
| 143 | + |
|
| 144 | + $this->template = self::DELETE; |
|
| 145 | + |
|
| 146 | + return $this; |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + /** |
|
| 150 | + * Add a statement. |
|
| 151 | + * |
|
| 152 | + * @since 3.1.7 |
|
| 153 | + * |
|
| 154 | + * @param string $subject The subject of the statement (must be a URI). |
|
| 155 | + * @param string $predicate The predicate (must be a URI). |
|
| 156 | + * @param string $object The object, can be a URI or a value. |
|
| 157 | + * @param int $object_type The object type, either a {@link OBJECT_URI} or a value {@link OBJECT_VALUE}. If set to {@link OBJECT_AUTO}, the Query builder will try to guess. |
|
| 158 | + * @param string|null $data_type The data type (or null). |
|
| 159 | + * @param string|null $language The language code (or null). |
|
| 160 | + * |
|
| 161 | + * @return $this \Wordlift_Query_Builder The Query builder. |
|
| 162 | + */ |
|
| 163 | + public function statement( $subject, $predicate, $object, $object_type = self::OBJECT_AUTO, $data_type = null, $language = null ) { |
|
| 164 | + |
|
| 165 | + // If no value has been provided, we don't set any statement. |
|
| 166 | + if ( empty( $object ) ) { |
|
| 167 | + return $this; |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + // Get the object type if set, otherwise try to guess it. |
|
| 171 | + $object_value_type = ( self::OBJECT_AUTO !== $object_type ?: $this->guess_object_type( $predicate, $object ) ); |
|
| 172 | + |
|
| 173 | + // Prepare the statement template. |
|
| 174 | + $template = '<%1$s> <%2$s> ' . ( |
|
| 175 | + self::OBJECT_URI === $object_value_type ? '<%3$s>' : ( |
|
| 176 | + self::OBJECT_PARAMETER === $object_value_type ? '%3$s' : |
|
| 177 | + // self::OBJECT_VALUE === $object_value_type |
|
| 178 | + '"%3$s"' . ( isset( $data_type ) ? '^^%4$s' : '' ) . ( isset( $language ) ? '@%5$s' : '' ) ) ); |
|
| 179 | + |
|
| 180 | + // Escape the subject, predicate and object. |
|
| 181 | + $escaped_subject = $this->escape_uri( $subject ); |
|
| 182 | + $escaped_predicate = $this->escape_uri( $predicate ); |
|
| 183 | + $escaped_object = ( self::OBJECT_URI === $object_value_type ? $this->escape_uri( $object ) : $this->escape_value( $object ) ); |
|
| 184 | + |
|
| 185 | + // Prepare the statement and add it to the list of statements. |
|
| 186 | + $this->statements[] = sprintf( $template, $escaped_subject, $escaped_predicate, $escaped_object, $data_type, $language ); |
|
| 187 | + |
|
| 188 | + return $this; |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + /** |
|
| 192 | + * Build the query. |
|
| 193 | + * |
|
| 194 | + * @since 3.1.7 |
|
| 195 | + * @return string The query string. |
|
| 196 | + */ |
|
| 197 | + public function build() { |
|
| 198 | + |
|
| 199 | + return sprintf( $this->template, implode( ' . ', $this->statements ) ) . "\n"; |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + /** |
|
| 203 | + * Guess the statement object type. |
|
| 204 | + * |
|
| 205 | + * @since 3.1.7 |
|
| 206 | + * |
|
| 207 | + * @param string $predicate The predicate. |
|
| 208 | + * @param string $object The object. |
|
| 209 | + * |
|
| 210 | + * @return int {@link Wordlift_Query_Builder::OBJECT_URI} if the Query builder thinks the object must be an URI, {@link Wordlift_Query_Builder::OBJECT_VALUE} otherwise. |
|
| 211 | + */ |
|
| 212 | + private function guess_object_type( $predicate, $object ) { |
|
| 213 | + |
|
| 214 | + // If the object starts with a question mark, it's a parameter. |
|
| 215 | + if ( 0 === strpos( $object, '?' ) ) { |
|
| 216 | + return self::OBJECT_PARAMETER; |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + // Guess based on the predicate. |
|
| 220 | + switch ( $predicate ) { |
|
| 221 | + |
|
| 222 | + case self::RDFS_TYPE_URI: |
|
| 223 | + case self::SCHEMA_URL_URI: |
|
| 224 | + return self::OBJECT_URI; |
|
| 225 | + |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + return self::OBJECT_VALUE; |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + /** |
|
| 232 | + * Escape a URI. |
|
| 233 | + * |
|
| 234 | + * @since 3.1.7 |
|
| 235 | + * |
|
| 236 | + * @param string $uri The URI to escape. |
|
| 237 | + * |
|
| 238 | + * @return string The escaped URI. |
|
| 239 | + */ |
|
| 240 | + private function escape_uri( $uri ) { |
|
| 241 | + |
|
| 242 | + // Should we validate the IRI? |
|
| 243 | + // http://www.w3.org/TR/sparql11-query/#QSynIRI |
|
| 244 | + |
|
| 245 | + $escaped_uri = str_replace( '<', '\<', $uri ); |
|
| 246 | + $escaped_uri = str_replace( '>', '\>', $escaped_uri ); |
|
| 247 | + |
|
| 248 | + return $escaped_uri; |
|
| 249 | + } |
|
| 250 | + |
|
| 251 | + /** |
|
| 252 | + * Escape a value. |
|
| 253 | + * |
|
| 254 | + * @since 3.1.7 |
|
| 255 | + * |
|
| 256 | + * @param string $value The value to escape. |
|
| 257 | + * |
|
| 258 | + * @return string The escaped value. |
|
| 259 | + */ |
|
| 260 | + private function escape_value( $value ) { |
|
| 261 | + |
|
| 262 | + // see http://www.w3.org/TR/rdf-sparql-query/ |
|
| 263 | + // '\t' U+0009 (tab) |
|
| 264 | + // '\n' U+000A (line feed) |
|
| 265 | + // '\r' U+000D (carriage return) |
|
| 266 | + // '\b' U+0008 (backspace) |
|
| 267 | + // '\f' U+000C (form feed) |
|
| 268 | + // '\"' U+0022 (quotation mark, double quote mark) |
|
| 269 | + // "\'" U+0027 (apostrophe-quote, single quote mark) |
|
| 270 | + // '\\' U+005C (backslash) |
|
| 271 | + |
|
| 272 | + $escaped_value = str_replace( '\\', '\\\\', $value ); |
|
| 273 | + $escaped_value = str_replace( '\'', '\\\'', $escaped_value ); |
|
| 274 | + $escaped_value = str_replace( '"', '\\"', $escaped_value ); |
|
| 275 | + $escaped_value = str_replace( "\f", '\\f', $escaped_value ); |
|
| 276 | + $escaped_value = str_replace( "\b", '\\b', $escaped_value ); |
|
| 277 | + $escaped_value = str_replace( "\r", '\\r', $escaped_value ); |
|
| 278 | + $escaped_value = str_replace( "\n", '\\n', $escaped_value ); |
|
| 279 | + $escaped_value = str_replace( "\t", '\\t', $escaped_value ); |
|
| 280 | + |
|
| 281 | + return $escaped_value; |
|
| 282 | + } |
|
| 283 | 283 | |
| 284 | 284 | } |
@@ -160,30 +160,29 @@ discard block |
||
| 160 | 160 | * |
| 161 | 161 | * @return $this \Wordlift_Query_Builder The Query builder. |
| 162 | 162 | */ |
| 163 | - public function statement( $subject, $predicate, $object, $object_type = self::OBJECT_AUTO, $data_type = null, $language = null ) { |
|
| 163 | + public function statement($subject, $predicate, $object, $object_type = self::OBJECT_AUTO, $data_type = null, $language = null) { |
|
| 164 | 164 | |
| 165 | 165 | // If no value has been provided, we don't set any statement. |
| 166 | - if ( empty( $object ) ) { |
|
| 166 | + if (empty($object)) { |
|
| 167 | 167 | return $this; |
| 168 | 168 | } |
| 169 | 169 | |
| 170 | 170 | // Get the object type if set, otherwise try to guess it. |
| 171 | - $object_value_type = ( self::OBJECT_AUTO !== $object_type ?: $this->guess_object_type( $predicate, $object ) ); |
|
| 171 | + $object_value_type = (self::OBJECT_AUTO !== $object_type ?: $this->guess_object_type($predicate, $object)); |
|
| 172 | 172 | |
| 173 | 173 | // Prepare the statement template. |
| 174 | - $template = '<%1$s> <%2$s> ' . ( |
|
| 174 | + $template = '<%1$s> <%2$s> '.( |
|
| 175 | 175 | self::OBJECT_URI === $object_value_type ? '<%3$s>' : ( |
| 176 | - self::OBJECT_PARAMETER === $object_value_type ? '%3$s' : |
|
| 177 | - // self::OBJECT_VALUE === $object_value_type |
|
| 178 | - '"%3$s"' . ( isset( $data_type ) ? '^^%4$s' : '' ) . ( isset( $language ) ? '@%5$s' : '' ) ) ); |
|
| 176 | + self::OBJECT_PARAMETER === $object_value_type ? '%3$s' : // self::OBJECT_VALUE === $object_value_type |
|
| 177 | + '"%3$s"'.(isset($data_type) ? '^^%4$s' : '').(isset($language) ? '@%5$s' : '') ) ); |
|
| 179 | 178 | |
| 180 | 179 | // Escape the subject, predicate and object. |
| 181 | - $escaped_subject = $this->escape_uri( $subject ); |
|
| 182 | - $escaped_predicate = $this->escape_uri( $predicate ); |
|
| 183 | - $escaped_object = ( self::OBJECT_URI === $object_value_type ? $this->escape_uri( $object ) : $this->escape_value( $object ) ); |
|
| 180 | + $escaped_subject = $this->escape_uri($subject); |
|
| 181 | + $escaped_predicate = $this->escape_uri($predicate); |
|
| 182 | + $escaped_object = (self::OBJECT_URI === $object_value_type ? $this->escape_uri($object) : $this->escape_value($object)); |
|
| 184 | 183 | |
| 185 | 184 | // Prepare the statement and add it to the list of statements. |
| 186 | - $this->statements[] = sprintf( $template, $escaped_subject, $escaped_predicate, $escaped_object, $data_type, $language ); |
|
| 185 | + $this->statements[] = sprintf($template, $escaped_subject, $escaped_predicate, $escaped_object, $data_type, $language); |
|
| 187 | 186 | |
| 188 | 187 | return $this; |
| 189 | 188 | } |
@@ -196,7 +195,7 @@ discard block |
||
| 196 | 195 | */ |
| 197 | 196 | public function build() { |
| 198 | 197 | |
| 199 | - return sprintf( $this->template, implode( ' . ', $this->statements ) ) . "\n"; |
|
| 198 | + return sprintf($this->template, implode(' . ', $this->statements))."\n"; |
|
| 200 | 199 | } |
| 201 | 200 | |
| 202 | 201 | /** |
@@ -209,15 +208,15 @@ discard block |
||
| 209 | 208 | * |
| 210 | 209 | * @return int {@link Wordlift_Query_Builder::OBJECT_URI} if the Query builder thinks the object must be an URI, {@link Wordlift_Query_Builder::OBJECT_VALUE} otherwise. |
| 211 | 210 | */ |
| 212 | - private function guess_object_type( $predicate, $object ) { |
|
| 211 | + private function guess_object_type($predicate, $object) { |
|
| 213 | 212 | |
| 214 | 213 | // If the object starts with a question mark, it's a parameter. |
| 215 | - if ( 0 === strpos( $object, '?' ) ) { |
|
| 214 | + if (0 === strpos($object, '?')) { |
|
| 216 | 215 | return self::OBJECT_PARAMETER; |
| 217 | 216 | } |
| 218 | 217 | |
| 219 | 218 | // Guess based on the predicate. |
| 220 | - switch ( $predicate ) { |
|
| 219 | + switch ($predicate) { |
|
| 221 | 220 | |
| 222 | 221 | case self::RDFS_TYPE_URI: |
| 223 | 222 | case self::SCHEMA_URL_URI: |
@@ -237,13 +236,13 @@ discard block |
||
| 237 | 236 | * |
| 238 | 237 | * @return string The escaped URI. |
| 239 | 238 | */ |
| 240 | - private function escape_uri( $uri ) { |
|
| 239 | + private function escape_uri($uri) { |
|
| 241 | 240 | |
| 242 | 241 | // Should we validate the IRI? |
| 243 | 242 | // http://www.w3.org/TR/sparql11-query/#QSynIRI |
| 244 | 243 | |
| 245 | - $escaped_uri = str_replace( '<', '\<', $uri ); |
|
| 246 | - $escaped_uri = str_replace( '>', '\>', $escaped_uri ); |
|
| 244 | + $escaped_uri = str_replace('<', '\<', $uri); |
|
| 245 | + $escaped_uri = str_replace('>', '\>', $escaped_uri); |
|
| 247 | 246 | |
| 248 | 247 | return $escaped_uri; |
| 249 | 248 | } |
@@ -257,7 +256,7 @@ discard block |
||
| 257 | 256 | * |
| 258 | 257 | * @return string The escaped value. |
| 259 | 258 | */ |
| 260 | - private function escape_value( $value ) { |
|
| 259 | + private function escape_value($value) { |
|
| 261 | 260 | |
| 262 | 261 | // see http://www.w3.org/TR/rdf-sparql-query/ |
| 263 | 262 | // '\t' U+0009 (tab) |
@@ -269,14 +268,14 @@ discard block |
||
| 269 | 268 | // "\'" U+0027 (apostrophe-quote, single quote mark) |
| 270 | 269 | // '\\' U+005C (backslash) |
| 271 | 270 | |
| 272 | - $escaped_value = str_replace( '\\', '\\\\', $value ); |
|
| 273 | - $escaped_value = str_replace( '\'', '\\\'', $escaped_value ); |
|
| 274 | - $escaped_value = str_replace( '"', '\\"', $escaped_value ); |
|
| 275 | - $escaped_value = str_replace( "\f", '\\f', $escaped_value ); |
|
| 276 | - $escaped_value = str_replace( "\b", '\\b', $escaped_value ); |
|
| 277 | - $escaped_value = str_replace( "\r", '\\r', $escaped_value ); |
|
| 278 | - $escaped_value = str_replace( "\n", '\\n', $escaped_value ); |
|
| 279 | - $escaped_value = str_replace( "\t", '\\t', $escaped_value ); |
|
| 271 | + $escaped_value = str_replace('\\', '\\\\', $value); |
|
| 272 | + $escaped_value = str_replace('\'', '\\\'', $escaped_value); |
|
| 273 | + $escaped_value = str_replace('"', '\\"', $escaped_value); |
|
| 274 | + $escaped_value = str_replace("\f", '\\f', $escaped_value); |
|
| 275 | + $escaped_value = str_replace("\b", '\\b', $escaped_value); |
|
| 276 | + $escaped_value = str_replace("\r", '\\r', $escaped_value); |
|
| 277 | + $escaped_value = str_replace("\n", '\\n', $escaped_value); |
|
| 278 | + $escaped_value = str_replace("\t", '\\t', $escaped_value); |
|
| 280 | 279 | |
| 281 | 280 | return $escaped_value; |
| 282 | 281 | } |
@@ -10,245 +10,245 @@ |
||
| 10 | 10 | */ |
| 11 | 11 | class Wordlift_User_Service { |
| 12 | 12 | |
| 13 | - /** |
|
| 14 | - * The meta key where the user's URI is stored. |
|
| 15 | - * |
|
| 16 | - * @since 3.1.7 |
|
| 17 | - */ |
|
| 18 | - const URI_META_KEY = '_wl_uri'; |
|
| 19 | - |
|
| 20 | - /** |
|
| 21 | - * The Log service. |
|
| 22 | - * |
|
| 23 | - * @since 3.1.7 |
|
| 24 | - * @access private |
|
| 25 | - * @var \Wordlift_Log_Service $log_service The Log service. |
|
| 26 | - */ |
|
| 27 | - private $log_service; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * The singleton instance of the User service. |
|
| 31 | - * |
|
| 32 | - * @since 3.1.7 |
|
| 33 | - * @access private |
|
| 34 | - * @var \Wordlift_User_Service $user_service The singleton instance of the User service. |
|
| 35 | - */ |
|
| 36 | - private static $instance; |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * Create an instance of the User service. |
|
| 40 | - * |
|
| 41 | - * @since 3.1.7 |
|
| 42 | - */ |
|
| 43 | - public function __construct() { |
|
| 44 | - |
|
| 45 | - $this->log_service = Wordlift_Log_Service::get_logger( 'Wordlift_User_Service' ); |
|
| 46 | - |
|
| 47 | - self::$instance = $this; |
|
| 48 | - |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * Get the singleton instance of the User service. |
|
| 53 | - * |
|
| 54 | - * @since 3.1.7 |
|
| 55 | - * @return \Wordlift_User_Service The singleton instance of the User service. |
|
| 56 | - */ |
|
| 57 | - public static function get_instance() { |
|
| 58 | - |
|
| 59 | - return self::$instance; |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * Get the URI for a user. |
|
| 64 | - * |
|
| 65 | - * @since 3.1.7 |
|
| 66 | - * |
|
| 67 | - * @param int $user_id The user id |
|
| 68 | - * |
|
| 69 | - * @return false|string The user's URI or false in case of failure. |
|
| 70 | - */ |
|
| 71 | - public function get_uri( $user_id ) { |
|
| 72 | - |
|
| 73 | - // Try to get the URI stored in the user's meta and return it if available. |
|
| 74 | - if ( false !== ( $user_uri = $this->_get_uri( $user_id ) ) ) { |
|
| 75 | - return $user_uri; |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - // Try to build an URI, return false in case of failure. |
|
| 79 | - if ( false === ( $user_uri = $this->_build_uri( $user_id ) ) ) { |
|
| 80 | - return false; |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - // Store the URI for future requests (we need a "permanent" URI). |
|
| 84 | - $this->_set_uri( $user_id, $user_uri ); |
|
| 85 | - |
|
| 86 | - return $user_uri; |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * Receives wp_insert_post events. |
|
| 91 | - * |
|
| 92 | - * @since 3.1.7 |
|
| 93 | - * |
|
| 94 | - * @param int $post_id Post ID. |
|
| 95 | - * @param WP_Post $post Post object. |
|
| 96 | - * @param bool $update Whether this is an existing post being updated or not. |
|
| 97 | - */ |
|
| 98 | - public function wp_insert_post( $post_id, $post, $update ) { |
|
| 99 | - |
|
| 100 | - // If the post is not published, return. |
|
| 101 | - if ( 'publish' !== get_post_status( $post_id ) ) { |
|
| 102 | - return; |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - // We expect a numeric author id. |
|
| 106 | - if ( ! is_numeric( $post->post_author ) ) { |
|
| 107 | - return; |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - // Get the delete query,or return in case of failure. |
|
| 111 | - if ( false === ( $delete = $this->get_delete_query( $post->post_author ) ) ) { |
|
| 112 | - return; |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - // Get the insert query,or return in case of failure. |
|
| 116 | - if ( false === ( $insert = $this->get_insert_query( $post->post_author ) ) ) { |
|
| 117 | - return; |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - // Send the query to the triple store. |
|
| 121 | - rl_execute_sparql_update_query( $delete . $insert ); |
|
| 122 | - |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - /** |
|
| 126 | - * Get the user's URI stored in the user's meta. |
|
| 127 | - * |
|
| 128 | - * @since 3.1.7 |
|
| 129 | - * |
|
| 130 | - * @param int $user_id The user id. |
|
| 131 | - * |
|
| 132 | - * @return false|string The user's URI or false if not found. |
|
| 133 | - */ |
|
| 134 | - private function _get_uri( $user_id ) { |
|
| 135 | - |
|
| 136 | - $user_uri = get_user_meta( $user_id, self::URI_META_KEY, true ); |
|
| 137 | - |
|
| 138 | - if ( empty( $user_uri ) ) { |
|
| 139 | - return false; |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - return $user_uri; |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - /** |
|
| 146 | - * Build an URI for a user. |
|
| 147 | - * |
|
| 148 | - * @since 3.1.7 |
|
| 149 | - * |
|
| 150 | - * @param int $user_id The user's id. |
|
| 151 | - * |
|
| 152 | - * @return false|string The user's URI or false in case of failure. |
|
| 153 | - */ |
|
| 154 | - private function _build_uri( $user_id ) { |
|
| 155 | - |
|
| 156 | - // Get the user, return false in case of failure. |
|
| 157 | - if ( false === ( $user = get_userdata( $user_id ) ) ) { |
|
| 158 | - return false; |
|
| 159 | - }; |
|
| 160 | - |
|
| 161 | - // If the nicename is not set, return a failure. |
|
| 162 | - if ( empty( $user->user_nicename ) ) { |
|
| 163 | - return false; |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - return wl_configuration_get_redlink_dataset_uri() . "/user/$user->user_nicename"; |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - /** |
|
| 170 | - * Store the URI in user's meta. |
|
| 171 | - * |
|
| 172 | - * @since 3.1.7 |
|
| 173 | - * |
|
| 174 | - * @param int $user_id The user's id. |
|
| 175 | - * @param string $user_uri The user's uri. |
|
| 176 | - * |
|
| 177 | - * @return int|bool Meta ID if the key didn't exist, true on successful update, false on failure. |
|
| 178 | - */ |
|
| 179 | - private function _set_uri( $user_id, $user_uri ) { |
|
| 180 | - |
|
| 181 | - return update_user_meta( $user_id, self::URI_META_KEY, $user_uri ); |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - /** |
|
| 185 | - * Get the delete query. |
|
| 186 | - * |
|
| 187 | - * @since 3.1.7 |
|
| 188 | - * |
|
| 189 | - * @param int $user_id The user id. |
|
| 190 | - * |
|
| 191 | - * @return false|string The delete query or false in case of failure. |
|
| 192 | - */ |
|
| 193 | - private function get_delete_query( $user_id ) { |
|
| 194 | - |
|
| 195 | - // Get the URI, return if there's none. |
|
| 196 | - if ( false === ( $user_uri = $this->get_uri( $user_id ) ) ) { |
|
| 197 | - return false; |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - // Build the delete query. |
|
| 201 | - $query = Wordlift_Query_Builder::new_instance()->delete() |
|
| 202 | - ->statement( $user_uri, Wordlift_Query_Builder::RDFS_TYPE_URI, '?o' ) |
|
| 203 | - ->build() |
|
| 204 | - . Wordlift_Query_Builder::new_instance()->delete() |
|
| 205 | - ->statement( $user_uri, Wordlift_Query_Builder::RDFS_LABEL_URI, '?o' ) |
|
| 206 | - ->build() |
|
| 207 | - . Wordlift_Query_Builder::new_instance()->delete() |
|
| 208 | - ->statement( $user_uri, Wordlift_Query_Builder::SCHEMA_GIVEN_NAME_URI, '?o' ) |
|
| 209 | - ->build() |
|
| 210 | - . Wordlift_Query_Builder::new_instance()->delete() |
|
| 211 | - ->statement( $user_uri, Wordlift_Query_Builder::SCHEMA_FAMILY_NAME_URI, '?o' ) |
|
| 212 | - ->build() |
|
| 213 | - . Wordlift_Query_Builder::new_instance()->delete() |
|
| 214 | - ->statement( $user_uri, Wordlift_Query_Builder::SCHEMA_URL_URI, '?o' ) |
|
| 215 | - ->build(); |
|
| 216 | - |
|
| 217 | - return $query; |
|
| 218 | - } |
|
| 219 | - |
|
| 220 | - /** |
|
| 221 | - * Get the insert query. |
|
| 222 | - * |
|
| 223 | - * @since 3.1.7 |
|
| 224 | - * |
|
| 225 | - * @param int $user_id The user id. |
|
| 226 | - * |
|
| 227 | - * @return false|string The insert query or false in case of failure. |
|
| 228 | - */ |
|
| 229 | - private function get_insert_query( $user_id ) { |
|
| 230 | - |
|
| 231 | - // Get the URI, return if there's none. |
|
| 232 | - if ( false === ( $user_uri = $this->get_uri( $user_id ) ) ) { |
|
| 233 | - return false; |
|
| 234 | - } |
|
| 235 | - |
|
| 236 | - // Try to get the user data, in case of failure return false. |
|
| 237 | - if ( false === ( $user = get_userdata( $user_id ) ) ) { |
|
| 238 | - return false; |
|
| 239 | - }; |
|
| 240 | - |
|
| 241 | - // Build the insert query. |
|
| 242 | - $query = Wordlift_Query_Builder::new_instance() |
|
| 243 | - ->insert() |
|
| 244 | - ->statement( $user_uri, Wordlift_Query_Builder::RDFS_TYPE_URI, Wordlift_Query_Builder::SCHEMA_PERSON_URI ) |
|
| 245 | - ->statement( $user_uri, Wordlift_Query_Builder::RDFS_LABEL_URI, $user->display_name ) |
|
| 246 | - ->statement( $user_uri, Wordlift_Query_Builder::SCHEMA_GIVEN_NAME_URI, $user->user_firstname ) |
|
| 247 | - ->statement( $user_uri, Wordlift_Query_Builder::SCHEMA_FAMILY_NAME_URI, $user->user_lastname ) |
|
| 248 | - ->statement( $user_uri, Wordlift_Query_Builder::SCHEMA_URL_URI, ( ! empty( $user->user_url ) ? $user->user_url : get_author_posts_url( $user_id ) ) ) |
|
| 249 | - ->build(); |
|
| 250 | - |
|
| 251 | - return $query; |
|
| 252 | - } |
|
| 13 | + /** |
|
| 14 | + * The meta key where the user's URI is stored. |
|
| 15 | + * |
|
| 16 | + * @since 3.1.7 |
|
| 17 | + */ |
|
| 18 | + const URI_META_KEY = '_wl_uri'; |
|
| 19 | + |
|
| 20 | + /** |
|
| 21 | + * The Log service. |
|
| 22 | + * |
|
| 23 | + * @since 3.1.7 |
|
| 24 | + * @access private |
|
| 25 | + * @var \Wordlift_Log_Service $log_service The Log service. |
|
| 26 | + */ |
|
| 27 | + private $log_service; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * The singleton instance of the User service. |
|
| 31 | + * |
|
| 32 | + * @since 3.1.7 |
|
| 33 | + * @access private |
|
| 34 | + * @var \Wordlift_User_Service $user_service The singleton instance of the User service. |
|
| 35 | + */ |
|
| 36 | + private static $instance; |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * Create an instance of the User service. |
|
| 40 | + * |
|
| 41 | + * @since 3.1.7 |
|
| 42 | + */ |
|
| 43 | + public function __construct() { |
|
| 44 | + |
|
| 45 | + $this->log_service = Wordlift_Log_Service::get_logger( 'Wordlift_User_Service' ); |
|
| 46 | + |
|
| 47 | + self::$instance = $this; |
|
| 48 | + |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * Get the singleton instance of the User service. |
|
| 53 | + * |
|
| 54 | + * @since 3.1.7 |
|
| 55 | + * @return \Wordlift_User_Service The singleton instance of the User service. |
|
| 56 | + */ |
|
| 57 | + public static function get_instance() { |
|
| 58 | + |
|
| 59 | + return self::$instance; |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * Get the URI for a user. |
|
| 64 | + * |
|
| 65 | + * @since 3.1.7 |
|
| 66 | + * |
|
| 67 | + * @param int $user_id The user id |
|
| 68 | + * |
|
| 69 | + * @return false|string The user's URI or false in case of failure. |
|
| 70 | + */ |
|
| 71 | + public function get_uri( $user_id ) { |
|
| 72 | + |
|
| 73 | + // Try to get the URI stored in the user's meta and return it if available. |
|
| 74 | + if ( false !== ( $user_uri = $this->_get_uri( $user_id ) ) ) { |
|
| 75 | + return $user_uri; |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + // Try to build an URI, return false in case of failure. |
|
| 79 | + if ( false === ( $user_uri = $this->_build_uri( $user_id ) ) ) { |
|
| 80 | + return false; |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + // Store the URI for future requests (we need a "permanent" URI). |
|
| 84 | + $this->_set_uri( $user_id, $user_uri ); |
|
| 85 | + |
|
| 86 | + return $user_uri; |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * Receives wp_insert_post events. |
|
| 91 | + * |
|
| 92 | + * @since 3.1.7 |
|
| 93 | + * |
|
| 94 | + * @param int $post_id Post ID. |
|
| 95 | + * @param WP_Post $post Post object. |
|
| 96 | + * @param bool $update Whether this is an existing post being updated or not. |
|
| 97 | + */ |
|
| 98 | + public function wp_insert_post( $post_id, $post, $update ) { |
|
| 99 | + |
|
| 100 | + // If the post is not published, return. |
|
| 101 | + if ( 'publish' !== get_post_status( $post_id ) ) { |
|
| 102 | + return; |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + // We expect a numeric author id. |
|
| 106 | + if ( ! is_numeric( $post->post_author ) ) { |
|
| 107 | + return; |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + // Get the delete query,or return in case of failure. |
|
| 111 | + if ( false === ( $delete = $this->get_delete_query( $post->post_author ) ) ) { |
|
| 112 | + return; |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + // Get the insert query,or return in case of failure. |
|
| 116 | + if ( false === ( $insert = $this->get_insert_query( $post->post_author ) ) ) { |
|
| 117 | + return; |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + // Send the query to the triple store. |
|
| 121 | + rl_execute_sparql_update_query( $delete . $insert ); |
|
| 122 | + |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + /** |
|
| 126 | + * Get the user's URI stored in the user's meta. |
|
| 127 | + * |
|
| 128 | + * @since 3.1.7 |
|
| 129 | + * |
|
| 130 | + * @param int $user_id The user id. |
|
| 131 | + * |
|
| 132 | + * @return false|string The user's URI or false if not found. |
|
| 133 | + */ |
|
| 134 | + private function _get_uri( $user_id ) { |
|
| 135 | + |
|
| 136 | + $user_uri = get_user_meta( $user_id, self::URI_META_KEY, true ); |
|
| 137 | + |
|
| 138 | + if ( empty( $user_uri ) ) { |
|
| 139 | + return false; |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + return $user_uri; |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + /** |
|
| 146 | + * Build an URI for a user. |
|
| 147 | + * |
|
| 148 | + * @since 3.1.7 |
|
| 149 | + * |
|
| 150 | + * @param int $user_id The user's id. |
|
| 151 | + * |
|
| 152 | + * @return false|string The user's URI or false in case of failure. |
|
| 153 | + */ |
|
| 154 | + private function _build_uri( $user_id ) { |
|
| 155 | + |
|
| 156 | + // Get the user, return false in case of failure. |
|
| 157 | + if ( false === ( $user = get_userdata( $user_id ) ) ) { |
|
| 158 | + return false; |
|
| 159 | + }; |
|
| 160 | + |
|
| 161 | + // If the nicename is not set, return a failure. |
|
| 162 | + if ( empty( $user->user_nicename ) ) { |
|
| 163 | + return false; |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + return wl_configuration_get_redlink_dataset_uri() . "/user/$user->user_nicename"; |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + /** |
|
| 170 | + * Store the URI in user's meta. |
|
| 171 | + * |
|
| 172 | + * @since 3.1.7 |
|
| 173 | + * |
|
| 174 | + * @param int $user_id The user's id. |
|
| 175 | + * @param string $user_uri The user's uri. |
|
| 176 | + * |
|
| 177 | + * @return int|bool Meta ID if the key didn't exist, true on successful update, false on failure. |
|
| 178 | + */ |
|
| 179 | + private function _set_uri( $user_id, $user_uri ) { |
|
| 180 | + |
|
| 181 | + return update_user_meta( $user_id, self::URI_META_KEY, $user_uri ); |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + /** |
|
| 185 | + * Get the delete query. |
|
| 186 | + * |
|
| 187 | + * @since 3.1.7 |
|
| 188 | + * |
|
| 189 | + * @param int $user_id The user id. |
|
| 190 | + * |
|
| 191 | + * @return false|string The delete query or false in case of failure. |
|
| 192 | + */ |
|
| 193 | + private function get_delete_query( $user_id ) { |
|
| 194 | + |
|
| 195 | + // Get the URI, return if there's none. |
|
| 196 | + if ( false === ( $user_uri = $this->get_uri( $user_id ) ) ) { |
|
| 197 | + return false; |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + // Build the delete query. |
|
| 201 | + $query = Wordlift_Query_Builder::new_instance()->delete() |
|
| 202 | + ->statement( $user_uri, Wordlift_Query_Builder::RDFS_TYPE_URI, '?o' ) |
|
| 203 | + ->build() |
|
| 204 | + . Wordlift_Query_Builder::new_instance()->delete() |
|
| 205 | + ->statement( $user_uri, Wordlift_Query_Builder::RDFS_LABEL_URI, '?o' ) |
|
| 206 | + ->build() |
|
| 207 | + . Wordlift_Query_Builder::new_instance()->delete() |
|
| 208 | + ->statement( $user_uri, Wordlift_Query_Builder::SCHEMA_GIVEN_NAME_URI, '?o' ) |
|
| 209 | + ->build() |
|
| 210 | + . Wordlift_Query_Builder::new_instance()->delete() |
|
| 211 | + ->statement( $user_uri, Wordlift_Query_Builder::SCHEMA_FAMILY_NAME_URI, '?o' ) |
|
| 212 | + ->build() |
|
| 213 | + . Wordlift_Query_Builder::new_instance()->delete() |
|
| 214 | + ->statement( $user_uri, Wordlift_Query_Builder::SCHEMA_URL_URI, '?o' ) |
|
| 215 | + ->build(); |
|
| 216 | + |
|
| 217 | + return $query; |
|
| 218 | + } |
|
| 219 | + |
|
| 220 | + /** |
|
| 221 | + * Get the insert query. |
|
| 222 | + * |
|
| 223 | + * @since 3.1.7 |
|
| 224 | + * |
|
| 225 | + * @param int $user_id The user id. |
|
| 226 | + * |
|
| 227 | + * @return false|string The insert query or false in case of failure. |
|
| 228 | + */ |
|
| 229 | + private function get_insert_query( $user_id ) { |
|
| 230 | + |
|
| 231 | + // Get the URI, return if there's none. |
|
| 232 | + if ( false === ( $user_uri = $this->get_uri( $user_id ) ) ) { |
|
| 233 | + return false; |
|
| 234 | + } |
|
| 235 | + |
|
| 236 | + // Try to get the user data, in case of failure return false. |
|
| 237 | + if ( false === ( $user = get_userdata( $user_id ) ) ) { |
|
| 238 | + return false; |
|
| 239 | + }; |
|
| 240 | + |
|
| 241 | + // Build the insert query. |
|
| 242 | + $query = Wordlift_Query_Builder::new_instance() |
|
| 243 | + ->insert() |
|
| 244 | + ->statement( $user_uri, Wordlift_Query_Builder::RDFS_TYPE_URI, Wordlift_Query_Builder::SCHEMA_PERSON_URI ) |
|
| 245 | + ->statement( $user_uri, Wordlift_Query_Builder::RDFS_LABEL_URI, $user->display_name ) |
|
| 246 | + ->statement( $user_uri, Wordlift_Query_Builder::SCHEMA_GIVEN_NAME_URI, $user->user_firstname ) |
|
| 247 | + ->statement( $user_uri, Wordlift_Query_Builder::SCHEMA_FAMILY_NAME_URI, $user->user_lastname ) |
|
| 248 | + ->statement( $user_uri, Wordlift_Query_Builder::SCHEMA_URL_URI, ( ! empty( $user->user_url ) ? $user->user_url : get_author_posts_url( $user_id ) ) ) |
|
| 249 | + ->build(); |
|
| 250 | + |
|
| 251 | + return $query; |
|
| 252 | + } |
|
| 253 | 253 | |
| 254 | 254 | } |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | */ |
| 43 | 43 | public function __construct() { |
| 44 | 44 | |
| 45 | - $this->log_service = Wordlift_Log_Service::get_logger( 'Wordlift_User_Service' ); |
|
| 45 | + $this->log_service = Wordlift_Log_Service::get_logger('Wordlift_User_Service'); |
|
| 46 | 46 | |
| 47 | 47 | self::$instance = $this; |
| 48 | 48 | |
@@ -68,20 +68,20 @@ discard block |
||
| 68 | 68 | * |
| 69 | 69 | * @return false|string The user's URI or false in case of failure. |
| 70 | 70 | */ |
| 71 | - public function get_uri( $user_id ) { |
|
| 71 | + public function get_uri($user_id) { |
|
| 72 | 72 | |
| 73 | 73 | // Try to get the URI stored in the user's meta and return it if available. |
| 74 | - if ( false !== ( $user_uri = $this->_get_uri( $user_id ) ) ) { |
|
| 74 | + if (false !== ($user_uri = $this->_get_uri($user_id))) { |
|
| 75 | 75 | return $user_uri; |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | // Try to build an URI, return false in case of failure. |
| 79 | - if ( false === ( $user_uri = $this->_build_uri( $user_id ) ) ) { |
|
| 79 | + if (false === ($user_uri = $this->_build_uri($user_id))) { |
|
| 80 | 80 | return false; |
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | // Store the URI for future requests (we need a "permanent" URI). |
| 84 | - $this->_set_uri( $user_id, $user_uri ); |
|
| 84 | + $this->_set_uri($user_id, $user_uri); |
|
| 85 | 85 | |
| 86 | 86 | return $user_uri; |
| 87 | 87 | } |
@@ -95,30 +95,30 @@ discard block |
||
| 95 | 95 | * @param WP_Post $post Post object. |
| 96 | 96 | * @param bool $update Whether this is an existing post being updated or not. |
| 97 | 97 | */ |
| 98 | - public function wp_insert_post( $post_id, $post, $update ) { |
|
| 98 | + public function wp_insert_post($post_id, $post, $update) { |
|
| 99 | 99 | |
| 100 | 100 | // If the post is not published, return. |
| 101 | - if ( 'publish' !== get_post_status( $post_id ) ) { |
|
| 101 | + if ('publish' !== get_post_status($post_id)) { |
|
| 102 | 102 | return; |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | // We expect a numeric author id. |
| 106 | - if ( ! is_numeric( $post->post_author ) ) { |
|
| 106 | + if ( ! is_numeric($post->post_author)) { |
|
| 107 | 107 | return; |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | // Get the delete query,or return in case of failure. |
| 111 | - if ( false === ( $delete = $this->get_delete_query( $post->post_author ) ) ) { |
|
| 111 | + if (false === ($delete = $this->get_delete_query($post->post_author))) { |
|
| 112 | 112 | return; |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | // Get the insert query,or return in case of failure. |
| 116 | - if ( false === ( $insert = $this->get_insert_query( $post->post_author ) ) ) { |
|
| 116 | + if (false === ($insert = $this->get_insert_query($post->post_author))) { |
|
| 117 | 117 | return; |
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | // Send the query to the triple store. |
| 121 | - rl_execute_sparql_update_query( $delete . $insert ); |
|
| 121 | + rl_execute_sparql_update_query($delete.$insert); |
|
| 122 | 122 | |
| 123 | 123 | } |
| 124 | 124 | |
@@ -131,11 +131,11 @@ discard block |
||
| 131 | 131 | * |
| 132 | 132 | * @return false|string The user's URI or false if not found. |
| 133 | 133 | */ |
| 134 | - private function _get_uri( $user_id ) { |
|
| 134 | + private function _get_uri($user_id) { |
|
| 135 | 135 | |
| 136 | - $user_uri = get_user_meta( $user_id, self::URI_META_KEY, true ); |
|
| 136 | + $user_uri = get_user_meta($user_id, self::URI_META_KEY, true); |
|
| 137 | 137 | |
| 138 | - if ( empty( $user_uri ) ) { |
|
| 138 | + if (empty($user_uri)) { |
|
| 139 | 139 | return false; |
| 140 | 140 | } |
| 141 | 141 | |
@@ -151,19 +151,19 @@ discard block |
||
| 151 | 151 | * |
| 152 | 152 | * @return false|string The user's URI or false in case of failure. |
| 153 | 153 | */ |
| 154 | - private function _build_uri( $user_id ) { |
|
| 154 | + private function _build_uri($user_id) { |
|
| 155 | 155 | |
| 156 | 156 | // Get the user, return false in case of failure. |
| 157 | - if ( false === ( $user = get_userdata( $user_id ) ) ) { |
|
| 157 | + if (false === ($user = get_userdata($user_id))) { |
|
| 158 | 158 | return false; |
| 159 | 159 | }; |
| 160 | 160 | |
| 161 | 161 | // If the nicename is not set, return a failure. |
| 162 | - if ( empty( $user->user_nicename ) ) { |
|
| 162 | + if (empty($user->user_nicename)) { |
|
| 163 | 163 | return false; |
| 164 | 164 | } |
| 165 | 165 | |
| 166 | - return wl_configuration_get_redlink_dataset_uri() . "/user/$user->user_nicename"; |
|
| 166 | + return wl_configuration_get_redlink_dataset_uri()."/user/$user->user_nicename"; |
|
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | /** |
@@ -176,9 +176,9 @@ discard block |
||
| 176 | 176 | * |
| 177 | 177 | * @return int|bool Meta ID if the key didn't exist, true on successful update, false on failure. |
| 178 | 178 | */ |
| 179 | - private function _set_uri( $user_id, $user_uri ) { |
|
| 179 | + private function _set_uri($user_id, $user_uri) { |
|
| 180 | 180 | |
| 181 | - return update_user_meta( $user_id, self::URI_META_KEY, $user_uri ); |
|
| 181 | + return update_user_meta($user_id, self::URI_META_KEY, $user_uri); |
|
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | /** |
@@ -190,28 +190,28 @@ discard block |
||
| 190 | 190 | * |
| 191 | 191 | * @return false|string The delete query or false in case of failure. |
| 192 | 192 | */ |
| 193 | - private function get_delete_query( $user_id ) { |
|
| 193 | + private function get_delete_query($user_id) { |
|
| 194 | 194 | |
| 195 | 195 | // Get the URI, return if there's none. |
| 196 | - if ( false === ( $user_uri = $this->get_uri( $user_id ) ) ) { |
|
| 196 | + if (false === ($user_uri = $this->get_uri($user_id))) { |
|
| 197 | 197 | return false; |
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | // Build the delete query. |
| 201 | 201 | $query = Wordlift_Query_Builder::new_instance()->delete() |
| 202 | - ->statement( $user_uri, Wordlift_Query_Builder::RDFS_TYPE_URI, '?o' ) |
|
| 202 | + ->statement($user_uri, Wordlift_Query_Builder::RDFS_TYPE_URI, '?o') |
|
| 203 | 203 | ->build() |
| 204 | 204 | . Wordlift_Query_Builder::new_instance()->delete() |
| 205 | - ->statement( $user_uri, Wordlift_Query_Builder::RDFS_LABEL_URI, '?o' ) |
|
| 205 | + ->statement($user_uri, Wordlift_Query_Builder::RDFS_LABEL_URI, '?o') |
|
| 206 | 206 | ->build() |
| 207 | 207 | . Wordlift_Query_Builder::new_instance()->delete() |
| 208 | - ->statement( $user_uri, Wordlift_Query_Builder::SCHEMA_GIVEN_NAME_URI, '?o' ) |
|
| 208 | + ->statement($user_uri, Wordlift_Query_Builder::SCHEMA_GIVEN_NAME_URI, '?o') |
|
| 209 | 209 | ->build() |
| 210 | 210 | . Wordlift_Query_Builder::new_instance()->delete() |
| 211 | - ->statement( $user_uri, Wordlift_Query_Builder::SCHEMA_FAMILY_NAME_URI, '?o' ) |
|
| 211 | + ->statement($user_uri, Wordlift_Query_Builder::SCHEMA_FAMILY_NAME_URI, '?o') |
|
| 212 | 212 | ->build() |
| 213 | 213 | . Wordlift_Query_Builder::new_instance()->delete() |
| 214 | - ->statement( $user_uri, Wordlift_Query_Builder::SCHEMA_URL_URI, '?o' ) |
|
| 214 | + ->statement($user_uri, Wordlift_Query_Builder::SCHEMA_URL_URI, '?o') |
|
| 215 | 215 | ->build(); |
| 216 | 216 | |
| 217 | 217 | return $query; |
@@ -226,26 +226,26 @@ discard block |
||
| 226 | 226 | * |
| 227 | 227 | * @return false|string The insert query or false in case of failure. |
| 228 | 228 | */ |
| 229 | - private function get_insert_query( $user_id ) { |
|
| 229 | + private function get_insert_query($user_id) { |
|
| 230 | 230 | |
| 231 | 231 | // Get the URI, return if there's none. |
| 232 | - if ( false === ( $user_uri = $this->get_uri( $user_id ) ) ) { |
|
| 232 | + if (false === ($user_uri = $this->get_uri($user_id))) { |
|
| 233 | 233 | return false; |
| 234 | 234 | } |
| 235 | 235 | |
| 236 | 236 | // Try to get the user data, in case of failure return false. |
| 237 | - if ( false === ( $user = get_userdata( $user_id ) ) ) { |
|
| 237 | + if (false === ($user = get_userdata($user_id))) { |
|
| 238 | 238 | return false; |
| 239 | 239 | }; |
| 240 | 240 | |
| 241 | 241 | // Build the insert query. |
| 242 | 242 | $query = Wordlift_Query_Builder::new_instance() |
| 243 | 243 | ->insert() |
| 244 | - ->statement( $user_uri, Wordlift_Query_Builder::RDFS_TYPE_URI, Wordlift_Query_Builder::SCHEMA_PERSON_URI ) |
|
| 245 | - ->statement( $user_uri, Wordlift_Query_Builder::RDFS_LABEL_URI, $user->display_name ) |
|
| 246 | - ->statement( $user_uri, Wordlift_Query_Builder::SCHEMA_GIVEN_NAME_URI, $user->user_firstname ) |
|
| 247 | - ->statement( $user_uri, Wordlift_Query_Builder::SCHEMA_FAMILY_NAME_URI, $user->user_lastname ) |
|
| 248 | - ->statement( $user_uri, Wordlift_Query_Builder::SCHEMA_URL_URI, ( ! empty( $user->user_url ) ? $user->user_url : get_author_posts_url( $user_id ) ) ) |
|
| 244 | + ->statement($user_uri, Wordlift_Query_Builder::RDFS_TYPE_URI, Wordlift_Query_Builder::SCHEMA_PERSON_URI) |
|
| 245 | + ->statement($user_uri, Wordlift_Query_Builder::RDFS_LABEL_URI, $user->display_name) |
|
| 246 | + ->statement($user_uri, Wordlift_Query_Builder::SCHEMA_GIVEN_NAME_URI, $user->user_firstname) |
|
| 247 | + ->statement($user_uri, Wordlift_Query_Builder::SCHEMA_FAMILY_NAME_URI, $user->user_lastname) |
|
| 248 | + ->statement($user_uri, Wordlift_Query_Builder::SCHEMA_URL_URI, ( ! empty($user->user_url) ? $user->user_url : get_author_posts_url($user_id))) |
|
| 249 | 249 | ->build(); |
| 250 | 250 | |
| 251 | 251 | return $query; |
@@ -29,323 +29,323 @@ |
||
| 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 Entity service. |
|
| 71 | - * |
|
| 72 | - * @since 3.1.0 |
|
| 73 | - * @access private |
|
| 74 | - * @var \Wordlift_Entity_Service $entity_service The Entity service. |
|
| 75 | - */ |
|
| 76 | - private $entity_service; |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * The User service. |
|
| 80 | - * |
|
| 81 | - * @since 3.1.7 |
|
| 82 | - * @access private |
|
| 83 | - * @var \Wordlift_User_Service $user_service The User service. |
|
| 84 | - */ |
|
| 85 | - private $user_service; |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * The Timeline service. |
|
| 89 | - * |
|
| 90 | - * @since 3.1.0 |
|
| 91 | - * @access private |
|
| 92 | - * @var \Wordlift_Timeline_Service $timeline_service The Timeline service. |
|
| 93 | - */ |
|
| 94 | - private $timeline_service; |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * The Entity Types Taxonomy Walker. |
|
| 98 | - * |
|
| 99 | - * @since 3.1.0 |
|
| 100 | - * @access private |
|
| 101 | - * @var \Wordlift_Entity_Types_Taxonomy_Walker $entity_types_taxonomy_walker The Entity Types Taxonomy Walker |
|
| 102 | - */ |
|
| 103 | - private $entity_types_taxonomy_walker; |
|
| 104 | - |
|
| 105 | - /** |
|
| 106 | - * Define the core functionality of the plugin. |
|
| 107 | - * |
|
| 108 | - * Set the plugin name and the plugin version that can be used throughout the plugin. |
|
| 109 | - * Load the dependencies, define the locale, and set the hooks for the admin area and |
|
| 110 | - * the public-facing side of the site. |
|
| 111 | - * |
|
| 112 | - * @since 1.0.0 |
|
| 113 | - */ |
|
| 114 | - public function __construct() { |
|
| 115 | - |
|
| 116 | - $this->plugin_name = 'wordlift'; |
|
| 117 | - $this->version = '3.1.7'; |
|
| 118 | - |
|
| 119 | - $this->load_dependencies(); |
|
| 120 | - $this->set_locale(); |
|
| 121 | - $this->define_admin_hooks(); |
|
| 122 | - $this->define_public_hooks(); |
|
| 123 | - |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * Load the required dependencies for this plugin. |
|
| 128 | - * |
|
| 129 | - * Include the following files that make up the plugin: |
|
| 130 | - * |
|
| 131 | - * - Wordlift_Loader. Orchestrates the hooks of the plugin. |
|
| 132 | - * - Wordlift_i18n. Defines internationalization functionality. |
|
| 133 | - * - Wordlift_Admin. Defines all hooks for the admin area. |
|
| 134 | - * - Wordlift_Public. Defines all hooks for the public side of the site. |
|
| 135 | - * |
|
| 136 | - * Create an instance of the loader which will be used to register the hooks |
|
| 137 | - * with WordPress. |
|
| 138 | - * |
|
| 139 | - * @since 1.0.0 |
|
| 140 | - * @access private |
|
| 141 | - */ |
|
| 142 | - private function load_dependencies() { |
|
| 143 | - |
|
| 144 | - /** |
|
| 145 | - * The class responsible for orchestrating the actions and filters of the |
|
| 146 | - * core plugin. |
|
| 147 | - */ |
|
| 148 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-loader.php'; |
|
| 149 | - |
|
| 150 | - /** |
|
| 151 | - * The class responsible for defining internationalization functionality |
|
| 152 | - * of the plugin. |
|
| 153 | - */ |
|
| 154 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-i18n.php'; |
|
| 155 | - |
|
| 156 | - /** |
|
| 157 | - * The Log service. |
|
| 158 | - */ |
|
| 159 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-log-service.php'; |
|
| 160 | - |
|
| 161 | - /** |
|
| 162 | - * The Query builder. |
|
| 163 | - */ |
|
| 164 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-query-builder.php'; |
|
| 165 | - |
|
| 166 | - /** |
|
| 167 | - * The Schema service. |
|
| 168 | - */ |
|
| 169 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-schema-service.php'; |
|
| 170 | - |
|
| 171 | - /** |
|
| 172 | - * The Thumbnail service. |
|
| 173 | - */ |
|
| 174 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-thumbnail-service.php'; |
|
| 175 | - |
|
| 176 | - /** |
|
| 177 | - * The Entity Types Taxonomy service. |
|
| 178 | - */ |
|
| 179 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-entity-types-taxonomy-service.php'; |
|
| 180 | - |
|
| 181 | - /** |
|
| 182 | - * The Entity service. |
|
| 183 | - */ |
|
| 184 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-entity-service.php'; |
|
| 185 | - |
|
| 186 | - /** |
|
| 187 | - * The User service. |
|
| 188 | - */ |
|
| 189 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-user-service.php'; |
|
| 190 | - |
|
| 191 | - /** |
|
| 192 | - * The Timeline service. |
|
| 193 | - */ |
|
| 194 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-timeline-service.php'; |
|
| 195 | - |
|
| 196 | - /** |
|
| 197 | - * The class responsible for defining all actions that occur in the admin area. |
|
| 198 | - */ |
|
| 199 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin.php'; |
|
| 200 | - |
|
| 201 | - /** |
|
| 202 | - * The Entity Types Taxonomy Walker (transforms checkboxes into radios). |
|
| 203 | - */ |
|
| 204 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-entity-types-taxonomy-walker.php'; |
|
| 205 | - |
|
| 206 | - /** |
|
| 207 | - * The class responsible for defining all actions that occur in the public-facing |
|
| 208 | - * side of the site. |
|
| 209 | - */ |
|
| 210 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-wordlift-public.php'; |
|
| 211 | - |
|
| 212 | - /** |
|
| 213 | - * The Timeline shortcode. |
|
| 214 | - */ |
|
| 215 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-wordlift-timeline-shortcode.php'; |
|
| 216 | - |
|
| 217 | - $this->loader = new Wordlift_Loader(); |
|
| 218 | - |
|
| 219 | - // Instantiate a global logger. |
|
| 220 | - global $wl_logger; |
|
| 221 | - $wl_logger = Wordlift_Log_Service::get_logger( 'WordLift' ); |
|
| 222 | - |
|
| 223 | - // Create an instance of the Thumbnail service. Later it'll be hooked to post meta events. |
|
| 224 | - $this->thumbnail_service = new Wordlift_Thumbnail_Service(); |
|
| 225 | - |
|
| 226 | - // Create an instance of the Schema service. |
|
| 227 | - new Wordlift_Schema_Service(); |
|
| 228 | - |
|
| 229 | - $this->entity_service = new Wordlift_Entity_Service(); |
|
| 230 | - |
|
| 231 | - // Create an instance of the User service. |
|
| 232 | - $this->user_service = new Wordlift_User_Service(); |
|
| 233 | - |
|
| 234 | - // Create a new instance of the Timeline service and Timeline shortcode. |
|
| 235 | - $this->timeline_service = new Wordlift_Timeline_Service( $this->entity_service ); |
|
| 236 | - |
|
| 237 | - // Create an instance of the Timeline shortcode. |
|
| 238 | - new Wordlift_Timeline_Shortcode(); |
|
| 239 | - |
|
| 240 | - $this->entity_types_taxonomy_walker = new Wordlift_Entity_Types_Taxonomy_Walker(); |
|
| 241 | - |
|
| 242 | - } |
|
| 243 | - |
|
| 244 | - /** |
|
| 245 | - * Define the locale for this plugin for internationalization. |
|
| 246 | - * |
|
| 247 | - * Uses the Wordlift_i18n class in order to set the domain and to register the hook |
|
| 248 | - * with WordPress. |
|
| 249 | - * |
|
| 250 | - * @since 1.0.0 |
|
| 251 | - * @access private |
|
| 252 | - */ |
|
| 253 | - private function set_locale() { |
|
| 254 | - |
|
| 255 | - $plugin_i18n = new Wordlift_i18n(); |
|
| 256 | - $plugin_i18n->set_domain( $this->get_plugin_name() ); |
|
| 257 | - |
|
| 258 | - $this->loader->add_action( 'plugins_loaded', $plugin_i18n, 'load_plugin_textdomain' ); |
|
| 259 | - |
|
| 260 | - } |
|
| 261 | - |
|
| 262 | - /** |
|
| 263 | - * Register all of the hooks related to the admin area functionality |
|
| 264 | - * of the plugin. |
|
| 265 | - * |
|
| 266 | - * @since 1.0.0 |
|
| 267 | - * @access private |
|
| 268 | - */ |
|
| 269 | - private function define_admin_hooks() { |
|
| 270 | - |
|
| 271 | - $plugin_admin = new Wordlift_Admin( $this->get_plugin_name(), $this->get_version() ); |
|
| 272 | - |
|
| 273 | - $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' ); |
|
| 274 | - $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' ); |
|
| 275 | - |
|
| 276 | - // Hook the deleted_post_meta action to the Thumbnail service. |
|
| 277 | - $this->loader->add_action( 'deleted_post_meta', $this->thumbnail_service, 'deleted_post_meta', 10, 4 ); |
|
| 278 | - |
|
| 279 | - // Hook the added_post_meta action to the Thumbnail service. |
|
| 280 | - $this->loader->add_action( 'added_post_meta', $this->thumbnail_service, 'added_post_meta', 10, 4 ); |
|
| 281 | - |
|
| 282 | - // Hook posts inserts (or updates) to the user service. |
|
| 283 | - $this->loader->add_action( 'wp_insert_post', $this->user_service, 'wp_insert_post', 10, 3 ); |
|
| 284 | - |
|
| 285 | - // Hook the AJAX wl_timeline action to the Timeline service. |
|
| 286 | - $this->loader->add_action( 'wp_ajax_wl_timeline', $this->timeline_service, 'ajax_timeline' ); |
|
| 287 | - |
|
| 288 | - $this->loader->add_filter( 'wp_terms_checklist_args', $this->entity_types_taxonomy_walker, 'terms_checklist_args' ); |
|
| 289 | - |
|
| 290 | - } |
|
| 291 | - |
|
| 292 | - /** |
|
| 293 | - * Register all of the hooks related to the public-facing functionality |
|
| 294 | - * of the plugin. |
|
| 295 | - * |
|
| 296 | - * @since 1.0.0 |
|
| 297 | - * @access private |
|
| 298 | - */ |
|
| 299 | - private function define_public_hooks() { |
|
| 300 | - |
|
| 301 | - $plugin_public = new Wordlift_Public( $this->get_plugin_name(), $this->get_version() ); |
|
| 302 | - |
|
| 303 | - $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_styles' ); |
|
| 304 | - $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts' ); |
|
| 305 | - |
|
| 306 | - // Hook the AJAX wl_timeline action to the Timeline service. |
|
| 307 | - $this->loader->add_action( 'wp_ajax_nopriv_wl_timeline', $this->timeline_service, 'ajax_timeline' ); |
|
| 308 | - |
|
| 309 | - } |
|
| 310 | - |
|
| 311 | - /** |
|
| 312 | - * Run the loader to execute all of the hooks with WordPress. |
|
| 313 | - * |
|
| 314 | - * @since 1.0.0 |
|
| 315 | - */ |
|
| 316 | - public function run() { |
|
| 317 | - $this->loader->run(); |
|
| 318 | - } |
|
| 319 | - |
|
| 320 | - /** |
|
| 321 | - * The name of the plugin used to uniquely identify it within the context of |
|
| 322 | - * WordPress and to define internationalization functionality. |
|
| 323 | - * |
|
| 324 | - * @since 1.0.0 |
|
| 325 | - * @return string The name of the plugin. |
|
| 326 | - */ |
|
| 327 | - public function get_plugin_name() { |
|
| 328 | - return $this->plugin_name; |
|
| 329 | - } |
|
| 330 | - |
|
| 331 | - /** |
|
| 332 | - * The reference to the class that orchestrates the hooks with the plugin. |
|
| 333 | - * |
|
| 334 | - * @since 1.0.0 |
|
| 335 | - * @return Wordlift_Loader Orchestrates the hooks of the plugin. |
|
| 336 | - */ |
|
| 337 | - public function get_loader() { |
|
| 338 | - return $this->loader; |
|
| 339 | - } |
|
| 340 | - |
|
| 341 | - /** |
|
| 342 | - * Retrieve the version number of the plugin. |
|
| 343 | - * |
|
| 344 | - * @since 1.0.0 |
|
| 345 | - * @return string The version number of the plugin. |
|
| 346 | - */ |
|
| 347 | - public function get_version() { |
|
| 348 | - return $this->version; |
|
| 349 | - } |
|
| 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 Entity service. |
|
| 71 | + * |
|
| 72 | + * @since 3.1.0 |
|
| 73 | + * @access private |
|
| 74 | + * @var \Wordlift_Entity_Service $entity_service The Entity service. |
|
| 75 | + */ |
|
| 76 | + private $entity_service; |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * The User service. |
|
| 80 | + * |
|
| 81 | + * @since 3.1.7 |
|
| 82 | + * @access private |
|
| 83 | + * @var \Wordlift_User_Service $user_service The User service. |
|
| 84 | + */ |
|
| 85 | + private $user_service; |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * The Timeline service. |
|
| 89 | + * |
|
| 90 | + * @since 3.1.0 |
|
| 91 | + * @access private |
|
| 92 | + * @var \Wordlift_Timeline_Service $timeline_service The Timeline service. |
|
| 93 | + */ |
|
| 94 | + private $timeline_service; |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * The Entity Types Taxonomy Walker. |
|
| 98 | + * |
|
| 99 | + * @since 3.1.0 |
|
| 100 | + * @access private |
|
| 101 | + * @var \Wordlift_Entity_Types_Taxonomy_Walker $entity_types_taxonomy_walker The Entity Types Taxonomy Walker |
|
| 102 | + */ |
|
| 103 | + private $entity_types_taxonomy_walker; |
|
| 104 | + |
|
| 105 | + /** |
|
| 106 | + * Define the core functionality of the plugin. |
|
| 107 | + * |
|
| 108 | + * Set the plugin name and the plugin version that can be used throughout the plugin. |
|
| 109 | + * Load the dependencies, define the locale, and set the hooks for the admin area and |
|
| 110 | + * the public-facing side of the site. |
|
| 111 | + * |
|
| 112 | + * @since 1.0.0 |
|
| 113 | + */ |
|
| 114 | + public function __construct() { |
|
| 115 | + |
|
| 116 | + $this->plugin_name = 'wordlift'; |
|
| 117 | + $this->version = '3.1.7'; |
|
| 118 | + |
|
| 119 | + $this->load_dependencies(); |
|
| 120 | + $this->set_locale(); |
|
| 121 | + $this->define_admin_hooks(); |
|
| 122 | + $this->define_public_hooks(); |
|
| 123 | + |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + /** |
|
| 127 | + * Load the required dependencies for this plugin. |
|
| 128 | + * |
|
| 129 | + * Include the following files that make up the plugin: |
|
| 130 | + * |
|
| 131 | + * - Wordlift_Loader. Orchestrates the hooks of the plugin. |
|
| 132 | + * - Wordlift_i18n. Defines internationalization functionality. |
|
| 133 | + * - Wordlift_Admin. Defines all hooks for the admin area. |
|
| 134 | + * - Wordlift_Public. Defines all hooks for the public side of the site. |
|
| 135 | + * |
|
| 136 | + * Create an instance of the loader which will be used to register the hooks |
|
| 137 | + * with WordPress. |
|
| 138 | + * |
|
| 139 | + * @since 1.0.0 |
|
| 140 | + * @access private |
|
| 141 | + */ |
|
| 142 | + private function load_dependencies() { |
|
| 143 | + |
|
| 144 | + /** |
|
| 145 | + * The class responsible for orchestrating the actions and filters of the |
|
| 146 | + * core plugin. |
|
| 147 | + */ |
|
| 148 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-loader.php'; |
|
| 149 | + |
|
| 150 | + /** |
|
| 151 | + * The class responsible for defining internationalization functionality |
|
| 152 | + * of the plugin. |
|
| 153 | + */ |
|
| 154 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-i18n.php'; |
|
| 155 | + |
|
| 156 | + /** |
|
| 157 | + * The Log service. |
|
| 158 | + */ |
|
| 159 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-log-service.php'; |
|
| 160 | + |
|
| 161 | + /** |
|
| 162 | + * The Query builder. |
|
| 163 | + */ |
|
| 164 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-query-builder.php'; |
|
| 165 | + |
|
| 166 | + /** |
|
| 167 | + * The Schema service. |
|
| 168 | + */ |
|
| 169 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-schema-service.php'; |
|
| 170 | + |
|
| 171 | + /** |
|
| 172 | + * The Thumbnail service. |
|
| 173 | + */ |
|
| 174 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-thumbnail-service.php'; |
|
| 175 | + |
|
| 176 | + /** |
|
| 177 | + * The Entity Types Taxonomy service. |
|
| 178 | + */ |
|
| 179 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-entity-types-taxonomy-service.php'; |
|
| 180 | + |
|
| 181 | + /** |
|
| 182 | + * The Entity service. |
|
| 183 | + */ |
|
| 184 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-entity-service.php'; |
|
| 185 | + |
|
| 186 | + /** |
|
| 187 | + * The User service. |
|
| 188 | + */ |
|
| 189 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-user-service.php'; |
|
| 190 | + |
|
| 191 | + /** |
|
| 192 | + * The Timeline service. |
|
| 193 | + */ |
|
| 194 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-timeline-service.php'; |
|
| 195 | + |
|
| 196 | + /** |
|
| 197 | + * The class responsible for defining all actions that occur in the admin area. |
|
| 198 | + */ |
|
| 199 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin.php'; |
|
| 200 | + |
|
| 201 | + /** |
|
| 202 | + * The Entity Types Taxonomy Walker (transforms checkboxes into radios). |
|
| 203 | + */ |
|
| 204 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-entity-types-taxonomy-walker.php'; |
|
| 205 | + |
|
| 206 | + /** |
|
| 207 | + * The class responsible for defining all actions that occur in the public-facing |
|
| 208 | + * side of the site. |
|
| 209 | + */ |
|
| 210 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-wordlift-public.php'; |
|
| 211 | + |
|
| 212 | + /** |
|
| 213 | + * The Timeline shortcode. |
|
| 214 | + */ |
|
| 215 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-wordlift-timeline-shortcode.php'; |
|
| 216 | + |
|
| 217 | + $this->loader = new Wordlift_Loader(); |
|
| 218 | + |
|
| 219 | + // Instantiate a global logger. |
|
| 220 | + global $wl_logger; |
|
| 221 | + $wl_logger = Wordlift_Log_Service::get_logger( 'WordLift' ); |
|
| 222 | + |
|
| 223 | + // Create an instance of the Thumbnail service. Later it'll be hooked to post meta events. |
|
| 224 | + $this->thumbnail_service = new Wordlift_Thumbnail_Service(); |
|
| 225 | + |
|
| 226 | + // Create an instance of the Schema service. |
|
| 227 | + new Wordlift_Schema_Service(); |
|
| 228 | + |
|
| 229 | + $this->entity_service = new Wordlift_Entity_Service(); |
|
| 230 | + |
|
| 231 | + // Create an instance of the User service. |
|
| 232 | + $this->user_service = new Wordlift_User_Service(); |
|
| 233 | + |
|
| 234 | + // Create a new instance of the Timeline service and Timeline shortcode. |
|
| 235 | + $this->timeline_service = new Wordlift_Timeline_Service( $this->entity_service ); |
|
| 236 | + |
|
| 237 | + // Create an instance of the Timeline shortcode. |
|
| 238 | + new Wordlift_Timeline_Shortcode(); |
|
| 239 | + |
|
| 240 | + $this->entity_types_taxonomy_walker = new Wordlift_Entity_Types_Taxonomy_Walker(); |
|
| 241 | + |
|
| 242 | + } |
|
| 243 | + |
|
| 244 | + /** |
|
| 245 | + * Define the locale for this plugin for internationalization. |
|
| 246 | + * |
|
| 247 | + * Uses the Wordlift_i18n class in order to set the domain and to register the hook |
|
| 248 | + * with WordPress. |
|
| 249 | + * |
|
| 250 | + * @since 1.0.0 |
|
| 251 | + * @access private |
|
| 252 | + */ |
|
| 253 | + private function set_locale() { |
|
| 254 | + |
|
| 255 | + $plugin_i18n = new Wordlift_i18n(); |
|
| 256 | + $plugin_i18n->set_domain( $this->get_plugin_name() ); |
|
| 257 | + |
|
| 258 | + $this->loader->add_action( 'plugins_loaded', $plugin_i18n, 'load_plugin_textdomain' ); |
|
| 259 | + |
|
| 260 | + } |
|
| 261 | + |
|
| 262 | + /** |
|
| 263 | + * Register all of the hooks related to the admin area functionality |
|
| 264 | + * of the plugin. |
|
| 265 | + * |
|
| 266 | + * @since 1.0.0 |
|
| 267 | + * @access private |
|
| 268 | + */ |
|
| 269 | + private function define_admin_hooks() { |
|
| 270 | + |
|
| 271 | + $plugin_admin = new Wordlift_Admin( $this->get_plugin_name(), $this->get_version() ); |
|
| 272 | + |
|
| 273 | + $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' ); |
|
| 274 | + $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' ); |
|
| 275 | + |
|
| 276 | + // Hook the deleted_post_meta action to the Thumbnail service. |
|
| 277 | + $this->loader->add_action( 'deleted_post_meta', $this->thumbnail_service, 'deleted_post_meta', 10, 4 ); |
|
| 278 | + |
|
| 279 | + // Hook the added_post_meta action to the Thumbnail service. |
|
| 280 | + $this->loader->add_action( 'added_post_meta', $this->thumbnail_service, 'added_post_meta', 10, 4 ); |
|
| 281 | + |
|
| 282 | + // Hook posts inserts (or updates) to the user service. |
|
| 283 | + $this->loader->add_action( 'wp_insert_post', $this->user_service, 'wp_insert_post', 10, 3 ); |
|
| 284 | + |
|
| 285 | + // Hook the AJAX wl_timeline action to the Timeline service. |
|
| 286 | + $this->loader->add_action( 'wp_ajax_wl_timeline', $this->timeline_service, 'ajax_timeline' ); |
|
| 287 | + |
|
| 288 | + $this->loader->add_filter( 'wp_terms_checklist_args', $this->entity_types_taxonomy_walker, 'terms_checklist_args' ); |
|
| 289 | + |
|
| 290 | + } |
|
| 291 | + |
|
| 292 | + /** |
|
| 293 | + * Register all of the hooks related to the public-facing functionality |
|
| 294 | + * of the plugin. |
|
| 295 | + * |
|
| 296 | + * @since 1.0.0 |
|
| 297 | + * @access private |
|
| 298 | + */ |
|
| 299 | + private function define_public_hooks() { |
|
| 300 | + |
|
| 301 | + $plugin_public = new Wordlift_Public( $this->get_plugin_name(), $this->get_version() ); |
|
| 302 | + |
|
| 303 | + $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_styles' ); |
|
| 304 | + $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts' ); |
|
| 305 | + |
|
| 306 | + // Hook the AJAX wl_timeline action to the Timeline service. |
|
| 307 | + $this->loader->add_action( 'wp_ajax_nopriv_wl_timeline', $this->timeline_service, 'ajax_timeline' ); |
|
| 308 | + |
|
| 309 | + } |
|
| 310 | + |
|
| 311 | + /** |
|
| 312 | + * Run the loader to execute all of the hooks with WordPress. |
|
| 313 | + * |
|
| 314 | + * @since 1.0.0 |
|
| 315 | + */ |
|
| 316 | + public function run() { |
|
| 317 | + $this->loader->run(); |
|
| 318 | + } |
|
| 319 | + |
|
| 320 | + /** |
|
| 321 | + * The name of the plugin used to uniquely identify it within the context of |
|
| 322 | + * WordPress and to define internationalization functionality. |
|
| 323 | + * |
|
| 324 | + * @since 1.0.0 |
|
| 325 | + * @return string The name of the plugin. |
|
| 326 | + */ |
|
| 327 | + public function get_plugin_name() { |
|
| 328 | + return $this->plugin_name; |
|
| 329 | + } |
|
| 330 | + |
|
| 331 | + /** |
|
| 332 | + * The reference to the class that orchestrates the hooks with the plugin. |
|
| 333 | + * |
|
| 334 | + * @since 1.0.0 |
|
| 335 | + * @return Wordlift_Loader Orchestrates the hooks of the plugin. |
|
| 336 | + */ |
|
| 337 | + public function get_loader() { |
|
| 338 | + return $this->loader; |
|
| 339 | + } |
|
| 340 | + |
|
| 341 | + /** |
|
| 342 | + * Retrieve the version number of the plugin. |
|
| 343 | + * |
|
| 344 | + * @since 1.0.0 |
|
| 345 | + * @return string The version number of the plugin. |
|
| 346 | + */ |
|
| 347 | + public function get_version() { |
|
| 348 | + return $this->version; |
|
| 349 | + } |
|
| 350 | 350 | |
| 351 | 351 | } |
@@ -145,80 +145,80 @@ discard block |
||
| 145 | 145 | * The class responsible for orchestrating the actions and filters of the |
| 146 | 146 | * core plugin. |
| 147 | 147 | */ |
| 148 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-loader.php'; |
|
| 148 | + require_once plugin_dir_path(dirname(__FILE__)).'includes/class-wordlift-loader.php'; |
|
| 149 | 149 | |
| 150 | 150 | /** |
| 151 | 151 | * The class responsible for defining internationalization functionality |
| 152 | 152 | * of the plugin. |
| 153 | 153 | */ |
| 154 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-i18n.php'; |
|
| 154 | + require_once plugin_dir_path(dirname(__FILE__)).'includes/class-wordlift-i18n.php'; |
|
| 155 | 155 | |
| 156 | 156 | /** |
| 157 | 157 | * The Log service. |
| 158 | 158 | */ |
| 159 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-log-service.php'; |
|
| 159 | + require_once plugin_dir_path(dirname(__FILE__)).'includes/class-wordlift-log-service.php'; |
|
| 160 | 160 | |
| 161 | 161 | /** |
| 162 | 162 | * The Query builder. |
| 163 | 163 | */ |
| 164 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-query-builder.php'; |
|
| 164 | + require_once plugin_dir_path(dirname(__FILE__)).'includes/class-wordlift-query-builder.php'; |
|
| 165 | 165 | |
| 166 | 166 | /** |
| 167 | 167 | * The Schema service. |
| 168 | 168 | */ |
| 169 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-schema-service.php'; |
|
| 169 | + require_once plugin_dir_path(dirname(__FILE__)).'includes/class-wordlift-schema-service.php'; |
|
| 170 | 170 | |
| 171 | 171 | /** |
| 172 | 172 | * The Thumbnail service. |
| 173 | 173 | */ |
| 174 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-thumbnail-service.php'; |
|
| 174 | + require_once plugin_dir_path(dirname(__FILE__)).'includes/class-wordlift-thumbnail-service.php'; |
|
| 175 | 175 | |
| 176 | 176 | /** |
| 177 | 177 | * The Entity Types Taxonomy service. |
| 178 | 178 | */ |
| 179 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-entity-types-taxonomy-service.php'; |
|
| 179 | + require_once plugin_dir_path(dirname(__FILE__)).'includes/class-wordlift-entity-types-taxonomy-service.php'; |
|
| 180 | 180 | |
| 181 | 181 | /** |
| 182 | 182 | * The Entity service. |
| 183 | 183 | */ |
| 184 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-entity-service.php'; |
|
| 184 | + require_once plugin_dir_path(dirname(__FILE__)).'includes/class-wordlift-entity-service.php'; |
|
| 185 | 185 | |
| 186 | 186 | /** |
| 187 | 187 | * The User service. |
| 188 | 188 | */ |
| 189 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-user-service.php'; |
|
| 189 | + require_once plugin_dir_path(dirname(__FILE__)).'includes/class-wordlift-user-service.php'; |
|
| 190 | 190 | |
| 191 | 191 | /** |
| 192 | 192 | * The Timeline service. |
| 193 | 193 | */ |
| 194 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-timeline-service.php'; |
|
| 194 | + require_once plugin_dir_path(dirname(__FILE__)).'includes/class-wordlift-timeline-service.php'; |
|
| 195 | 195 | |
| 196 | 196 | /** |
| 197 | 197 | * The class responsible for defining all actions that occur in the admin area. |
| 198 | 198 | */ |
| 199 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin.php'; |
|
| 199 | + require_once plugin_dir_path(dirname(__FILE__)).'admin/class-wordlift-admin.php'; |
|
| 200 | 200 | |
| 201 | 201 | /** |
| 202 | 202 | * The Entity Types Taxonomy Walker (transforms checkboxes into radios). |
| 203 | 203 | */ |
| 204 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-entity-types-taxonomy-walker.php'; |
|
| 204 | + require_once plugin_dir_path(dirname(__FILE__)).'admin/class-wordlift-entity-types-taxonomy-walker.php'; |
|
| 205 | 205 | |
| 206 | 206 | /** |
| 207 | 207 | * The class responsible for defining all actions that occur in the public-facing |
| 208 | 208 | * side of the site. |
| 209 | 209 | */ |
| 210 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-wordlift-public.php'; |
|
| 210 | + require_once plugin_dir_path(dirname(__FILE__)).'public/class-wordlift-public.php'; |
|
| 211 | 211 | |
| 212 | 212 | /** |
| 213 | 213 | * The Timeline shortcode. |
| 214 | 214 | */ |
| 215 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-wordlift-timeline-shortcode.php'; |
|
| 215 | + require_once plugin_dir_path(dirname(__FILE__)).'public/class-wordlift-timeline-shortcode.php'; |
|
| 216 | 216 | |
| 217 | 217 | $this->loader = new Wordlift_Loader(); |
| 218 | 218 | |
| 219 | 219 | // Instantiate a global logger. |
| 220 | 220 | global $wl_logger; |
| 221 | - $wl_logger = Wordlift_Log_Service::get_logger( 'WordLift' ); |
|
| 221 | + $wl_logger = Wordlift_Log_Service::get_logger('WordLift'); |
|
| 222 | 222 | |
| 223 | 223 | // Create an instance of the Thumbnail service. Later it'll be hooked to post meta events. |
| 224 | 224 | $this->thumbnail_service = new Wordlift_Thumbnail_Service(); |
@@ -232,7 +232,7 @@ discard block |
||
| 232 | 232 | $this->user_service = new Wordlift_User_Service(); |
| 233 | 233 | |
| 234 | 234 | // Create a new instance of the Timeline service and Timeline shortcode. |
| 235 | - $this->timeline_service = new Wordlift_Timeline_Service( $this->entity_service ); |
|
| 235 | + $this->timeline_service = new Wordlift_Timeline_Service($this->entity_service); |
|
| 236 | 236 | |
| 237 | 237 | // Create an instance of the Timeline shortcode. |
| 238 | 238 | new Wordlift_Timeline_Shortcode(); |
@@ -253,9 +253,9 @@ discard block |
||
| 253 | 253 | private function set_locale() { |
| 254 | 254 | |
| 255 | 255 | $plugin_i18n = new Wordlift_i18n(); |
| 256 | - $plugin_i18n->set_domain( $this->get_plugin_name() ); |
|
| 256 | + $plugin_i18n->set_domain($this->get_plugin_name()); |
|
| 257 | 257 | |
| 258 | - $this->loader->add_action( 'plugins_loaded', $plugin_i18n, 'load_plugin_textdomain' ); |
|
| 258 | + $this->loader->add_action('plugins_loaded', $plugin_i18n, 'load_plugin_textdomain'); |
|
| 259 | 259 | |
| 260 | 260 | } |
| 261 | 261 | |
@@ -268,24 +268,24 @@ discard block |
||
| 268 | 268 | */ |
| 269 | 269 | private function define_admin_hooks() { |
| 270 | 270 | |
| 271 | - $plugin_admin = new Wordlift_Admin( $this->get_plugin_name(), $this->get_version() ); |
|
| 271 | + $plugin_admin = new Wordlift_Admin($this->get_plugin_name(), $this->get_version()); |
|
| 272 | 272 | |
| 273 | - $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' ); |
|
| 274 | - $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' ); |
|
| 273 | + $this->loader->add_action('admin_enqueue_scripts', $plugin_admin, 'enqueue_styles'); |
|
| 274 | + $this->loader->add_action('admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts'); |
|
| 275 | 275 | |
| 276 | 276 | // Hook the deleted_post_meta action to the Thumbnail service. |
| 277 | - $this->loader->add_action( 'deleted_post_meta', $this->thumbnail_service, 'deleted_post_meta', 10, 4 ); |
|
| 277 | + $this->loader->add_action('deleted_post_meta', $this->thumbnail_service, 'deleted_post_meta', 10, 4); |
|
| 278 | 278 | |
| 279 | 279 | // Hook the added_post_meta action to the Thumbnail service. |
| 280 | - $this->loader->add_action( 'added_post_meta', $this->thumbnail_service, 'added_post_meta', 10, 4 ); |
|
| 280 | + $this->loader->add_action('added_post_meta', $this->thumbnail_service, 'added_post_meta', 10, 4); |
|
| 281 | 281 | |
| 282 | 282 | // Hook posts inserts (or updates) to the user service. |
| 283 | - $this->loader->add_action( 'wp_insert_post', $this->user_service, 'wp_insert_post', 10, 3 ); |
|
| 283 | + $this->loader->add_action('wp_insert_post', $this->user_service, 'wp_insert_post', 10, 3); |
|
| 284 | 284 | |
| 285 | 285 | // Hook the AJAX wl_timeline action to the Timeline service. |
| 286 | - $this->loader->add_action( 'wp_ajax_wl_timeline', $this->timeline_service, 'ajax_timeline' ); |
|
| 286 | + $this->loader->add_action('wp_ajax_wl_timeline', $this->timeline_service, 'ajax_timeline'); |
|
| 287 | 287 | |
| 288 | - $this->loader->add_filter( 'wp_terms_checklist_args', $this->entity_types_taxonomy_walker, 'terms_checklist_args' ); |
|
| 288 | + $this->loader->add_filter('wp_terms_checklist_args', $this->entity_types_taxonomy_walker, 'terms_checklist_args'); |
|
| 289 | 289 | |
| 290 | 290 | } |
| 291 | 291 | |
@@ -298,13 +298,13 @@ discard block |
||
| 298 | 298 | */ |
| 299 | 299 | private function define_public_hooks() { |
| 300 | 300 | |
| 301 | - $plugin_public = new Wordlift_Public( $this->get_plugin_name(), $this->get_version() ); |
|
| 301 | + $plugin_public = new Wordlift_Public($this->get_plugin_name(), $this->get_version()); |
|
| 302 | 302 | |
| 303 | - $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_styles' ); |
|
| 304 | - $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts' ); |
|
| 303 | + $this->loader->add_action('wp_enqueue_scripts', $plugin_public, 'enqueue_styles'); |
|
| 304 | + $this->loader->add_action('wp_enqueue_scripts', $plugin_public, 'enqueue_scripts'); |
|
| 305 | 305 | |
| 306 | 306 | // Hook the AJAX wl_timeline action to the Timeline service. |
| 307 | - $this->loader->add_action( 'wp_ajax_nopriv_wl_timeline', $this->timeline_service, 'ajax_timeline' ); |
|
| 307 | + $this->loader->add_action('wp_ajax_nopriv_wl_timeline', $this->timeline_service, 'ajax_timeline'); |
|
| 308 | 308 | |
| 309 | 309 | } |
| 310 | 310 | |
@@ -25,16 +25,16 @@ discard block |
||
| 25 | 25 | */ |
| 26 | 26 | |
| 27 | 27 | // If this file is called directly, abort. |
| 28 | -if ( ! defined( 'WPINC' ) ) { |
|
| 28 | +if ( ! defined('WPINC')) { |
|
| 29 | 29 | die; |
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | // Include WordLift constants. |
| 33 | -require_once( 'wordlift_constants.php' ); |
|
| 33 | +require_once('wordlift_constants.php'); |
|
| 34 | 34 | |
| 35 | 35 | // Load modules |
| 36 | -require_once( 'modules/core/wordlift_core.php' ); |
|
| 37 | -require_once( 'modules/configuration/wordlift_configuration.php' ); |
|
| 36 | +require_once('modules/core/wordlift_core.php'); |
|
| 37 | +require_once('modules/configuration/wordlift_configuration.php'); |
|
| 38 | 38 | |
| 39 | 39 | /** |
| 40 | 40 | * Log to the debug.log file. |
@@ -45,20 +45,20 @@ discard block |
||
| 45 | 45 | * |
| 46 | 46 | * @param string|mixed $log The log data. |
| 47 | 47 | */ |
| 48 | -function wl_write_log( $log ) { |
|
| 48 | +function wl_write_log($log) { |
|
| 49 | 49 | |
| 50 | - $handler = apply_filters( 'wl_write_log_handler', null ); |
|
| 50 | + $handler = apply_filters('wl_write_log_handler', null); |
|
| 51 | 51 | |
| 52 | 52 | $callers = debug_backtrace(); |
| 53 | 53 | $caller_function = $callers[1]['function']; |
| 54 | 54 | |
| 55 | - if ( is_null( $handler ) ) { |
|
| 56 | - wl_write_log_handler( $log, $caller_function ); |
|
| 55 | + if (is_null($handler)) { |
|
| 56 | + wl_write_log_handler($log, $caller_function); |
|
| 57 | 57 | |
| 58 | 58 | return; |
| 59 | 59 | } |
| 60 | 60 | |
| 61 | - call_user_func( $handler, $log, $caller_function ); |
|
| 61 | + call_user_func($handler, $log, $caller_function); |
|
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | /** |
@@ -69,19 +69,19 @@ discard block |
||
| 69 | 69 | * @param string|array $log The log data. |
| 70 | 70 | * @param string $caller The calling function. |
| 71 | 71 | */ |
| 72 | -function wl_write_log_handler( $log, $caller = null ) { |
|
| 72 | +function wl_write_log_handler($log, $caller = null) { |
|
| 73 | 73 | |
| 74 | 74 | global $wl_logger; |
| 75 | 75 | |
| 76 | - if ( true === WP_DEBUG ) { |
|
| 76 | + if (true === WP_DEBUG) { |
|
| 77 | 77 | |
| 78 | - $message = ( isset( $caller ) ? sprintf( '[%-40.40s] ', $caller ) : '' ) . |
|
| 79 | - ( is_array( $log ) || is_object( $log ) ? print_r( $log, true ) : wl_write_log_hide_key( $log ) ); |
|
| 78 | + $message = (isset($caller) ? sprintf('[%-40.40s] ', $caller) : ''). |
|
| 79 | + (is_array($log) || is_object($log) ? print_r($log, true) : wl_write_log_hide_key($log)); |
|
| 80 | 80 | |
| 81 | - if ( isset( $wl_logger ) ) { |
|
| 82 | - $wl_logger->info( $message ); |
|
| 81 | + if (isset($wl_logger)) { |
|
| 82 | + $wl_logger->info($message); |
|
| 83 | 83 | } else { |
| 84 | - error_log( $message ); |
|
| 84 | + error_log($message); |
|
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | } |
@@ -97,9 +97,9 @@ discard block |
||
| 97 | 97 | * |
| 98 | 98 | * @return string A text with the key hidden. |
| 99 | 99 | */ |
| 100 | -function wl_write_log_hide_key( $text ) { |
|
| 100 | +function wl_write_log_hide_key($text) { |
|
| 101 | 101 | |
| 102 | - return str_ireplace( wl_configuration_get_key(), '<hidden>', $text ); |
|
| 102 | + return str_ireplace(wl_configuration_get_key(), '<hidden>', $text); |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | /** |
@@ -109,12 +109,12 @@ discard block |
||
| 109 | 109 | * |
| 110 | 110 | * @param string $query A SPARQL query. |
| 111 | 111 | */ |
| 112 | -function wl_queue_sparql_update_query( $query ) { |
|
| 112 | +function wl_queue_sparql_update_query($query) { |
|
| 113 | 113 | |
| 114 | - $filename = WL_TEMP_DIR . WL_REQUEST_ID . '.sparql'; |
|
| 115 | - file_put_contents( $filename, $query . "\n", FILE_APPEND ); |
|
| 114 | + $filename = WL_TEMP_DIR.WL_REQUEST_ID.'.sparql'; |
|
| 115 | + file_put_contents($filename, $query."\n", FILE_APPEND); |
|
| 116 | 116 | |
| 117 | - wl_write_log( "wl_queue_sparql_update_query [ filename :: $filename ]" ); |
|
| 117 | + wl_write_log("wl_queue_sparql_update_query [ filename :: $filename ]"); |
|
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | /** |
@@ -122,33 +122,33 @@ discard block |
||
| 122 | 122 | * |
| 123 | 123 | * @param int $request_id The request ID. |
| 124 | 124 | */ |
| 125 | -function wl_execute_saved_sparql_update_query( $request_id ) { |
|
| 125 | +function wl_execute_saved_sparql_update_query($request_id) { |
|
| 126 | 126 | |
| 127 | - $filename = WL_TEMP_DIR . $request_id . '.sparql'; |
|
| 127 | + $filename = WL_TEMP_DIR.$request_id.'.sparql'; |
|
| 128 | 128 | |
| 129 | 129 | // If the file doesn't exist, exit. |
| 130 | - if ( ! file_exists( $filename ) ) { |
|
| 131 | - wl_write_log( "wl_execute_saved_sparql_update_query : file doesn't exist [ filename :: $filename ]" ); |
|
| 130 | + if ( ! file_exists($filename)) { |
|
| 131 | + wl_write_log("wl_execute_saved_sparql_update_query : file doesn't exist [ filename :: $filename ]"); |
|
| 132 | 132 | |
| 133 | 133 | return; |
| 134 | 134 | } |
| 135 | 135 | |
| 136 | - wl_write_log( "wl_execute_saved_sparql_update_query [ filename :: $filename ]" ); |
|
| 136 | + wl_write_log("wl_execute_saved_sparql_update_query [ filename :: $filename ]"); |
|
| 137 | 137 | |
| 138 | 138 | // Get the query saved in the file. |
| 139 | - $query = file_get_contents( $filename ); |
|
| 139 | + $query = file_get_contents($filename); |
|
| 140 | 140 | |
| 141 | 141 | // Execute the SPARQL query. |
| 142 | - rl_execute_sparql_update_query( $query, false ); |
|
| 142 | + rl_execute_sparql_update_query($query, false); |
|
| 143 | 143 | |
| 144 | 144 | // Reindex the triple store. |
| 145 | 145 | wordlift_reindex_triple_store(); |
| 146 | 146 | |
| 147 | 147 | // Delete the temporary file. |
| 148 | - unlink( $filename ); |
|
| 148 | + unlink($filename); |
|
| 149 | 149 | } |
| 150 | 150 | |
| 151 | -add_action( 'wl_execute_saved_sparql_update_query', 'wl_execute_saved_sparql_update_query', 10, 1 ); |
|
| 151 | +add_action('wl_execute_saved_sparql_update_query', 'wl_execute_saved_sparql_update_query', 10, 1); |
|
| 152 | 152 | |
| 153 | 153 | /** |
| 154 | 154 | * Add buttons hook for the TinyMCE editor. This method is called by the WP init hook. |
@@ -156,8 +156,8 @@ discard block |
||
| 156 | 156 | function wordlift_buttonhooks() { |
| 157 | 157 | |
| 158 | 158 | // Only add hooks when the current user has permissions AND is in Rich Text editor mode |
| 159 | - if ( ( current_user_can( 'edit_posts' ) || current_user_can( 'edit_pages' ) ) && get_user_option( 'rich_editing' ) ) { |
|
| 160 | - add_filter( 'mce_external_plugins', 'wordlift_register_tinymce_javascript' ); |
|
| 159 | + if ((current_user_can('edit_posts') || current_user_can('edit_pages')) && get_user_option('rich_editing')) { |
|
| 160 | + add_filter('mce_external_plugins', 'wordlift_register_tinymce_javascript'); |
|
| 161 | 161 | } |
| 162 | 162 | } |
| 163 | 163 | |
@@ -168,10 +168,10 @@ discard block |
||
| 168 | 168 | * |
| 169 | 169 | * @return array The modified plugins array. |
| 170 | 170 | */ |
| 171 | -function wordlift_register_tinymce_javascript( $plugin_array ) { |
|
| 171 | +function wordlift_register_tinymce_javascript($plugin_array) { |
|
| 172 | 172 | |
| 173 | 173 | // add the wordlift plugin. |
| 174 | - $plugin_array['wordlift'] = plugin_dir_url( __FILE__ ) . 'js/wordlift-reloaded.js'; |
|
| 174 | + $plugin_array['wordlift'] = plugin_dir_url(__FILE__).'js/wordlift-reloaded.js'; |
|
| 175 | 175 | |
| 176 | 176 | return $plugin_array; |
| 177 | 177 | } |
@@ -183,7 +183,7 @@ discard block |
||
| 183 | 183 | function wordlift_allowed_post_tags() { |
| 184 | 184 | global $allowedposttags; |
| 185 | 185 | |
| 186 | - $tags = array( 'span' ); |
|
| 186 | + $tags = array('span'); |
|
| 187 | 187 | $new_attributes = array( |
| 188 | 188 | 'itemscope' => array(), |
| 189 | 189 | 'itemtype' => array(), |
@@ -191,17 +191,17 @@ discard block |
||
| 191 | 191 | 'itemid' => array() |
| 192 | 192 | ); |
| 193 | 193 | |
| 194 | - foreach ( $tags as $tag ) { |
|
| 195 | - if ( isset( $allowedposttags[ $tag ] ) && is_array( $allowedposttags[ $tag ] ) ) { |
|
| 196 | - $allowedposttags[ $tag ] = array_merge( $allowedposttags[ $tag ], $new_attributes ); |
|
| 194 | + foreach ($tags as $tag) { |
|
| 195 | + if (isset($allowedposttags[$tag]) && is_array($allowedposttags[$tag])) { |
|
| 196 | + $allowedposttags[$tag] = array_merge($allowedposttags[$tag], $new_attributes); |
|
| 197 | 197 | } |
| 198 | 198 | } |
| 199 | 199 | } |
| 200 | 200 | |
| 201 | 201 | // init process for button control |
| 202 | -add_action( 'init', 'wordlift_buttonhooks' ); |
|
| 202 | +add_action('init', 'wordlift_buttonhooks'); |
|
| 203 | 203 | // add allowed post tags. |
| 204 | -add_action( 'init', 'wordlift_allowed_post_tags' ); |
|
| 204 | +add_action('init', 'wordlift_allowed_post_tags'); |
|
| 205 | 205 | |
| 206 | 206 | |
| 207 | 207 | /** |
@@ -210,23 +210,23 @@ discard block |
||
| 210 | 210 | function wordlift_admin_enqueue_scripts() { |
| 211 | 211 | |
| 212 | 212 | // Added for compatibility with WordPress 3.9 (see http://make.wordpress.org/core/2014/04/16/jquery-ui-and-wpdialogs-in-wordpress-3-9/) |
| 213 | - wp_enqueue_script( 'wpdialogs' ); |
|
| 214 | - wp_enqueue_style( 'wp-jquery-ui-dialog' ); |
|
| 213 | + wp_enqueue_script('wpdialogs'); |
|
| 214 | + wp_enqueue_style('wp-jquery-ui-dialog'); |
|
| 215 | 215 | |
| 216 | - wp_enqueue_style( 'wordlift-reloaded', plugin_dir_url( __FILE__ ) . 'css/wordlift-reloaded.min.css' ); |
|
| 216 | + wp_enqueue_style('wordlift-reloaded', plugin_dir_url(__FILE__).'css/wordlift-reloaded.min.css'); |
|
| 217 | 217 | |
| 218 | - wp_enqueue_script( 'jquery-ui-autocomplete' ); |
|
| 219 | - wp_enqueue_script( 'angularjs', plugin_dir_url( __FILE__ ) . 'bower_components/angular/angular.min.js' ); |
|
| 218 | + wp_enqueue_script('jquery-ui-autocomplete'); |
|
| 219 | + wp_enqueue_script('angularjs', plugin_dir_url(__FILE__).'bower_components/angular/angular.min.js'); |
|
| 220 | 220 | |
| 221 | 221 | } |
| 222 | 222 | |
| 223 | -add_action( 'admin_enqueue_scripts', 'wordlift_admin_enqueue_scripts' ); |
|
| 223 | +add_action('admin_enqueue_scripts', 'wordlift_admin_enqueue_scripts'); |
|
| 224 | 224 | |
| 225 | 225 | function wl_enqueue_scripts() { |
| 226 | - wp_enqueue_style( 'wordlift-ui', plugin_dir_url( __FILE__ ) . 'css/wordlift-ui.min.css' ); |
|
| 226 | + wp_enqueue_style('wordlift-ui', plugin_dir_url(__FILE__).'css/wordlift-ui.min.css'); |
|
| 227 | 227 | } |
| 228 | 228 | |
| 229 | -add_action( 'wp_enqueue_scripts', 'wl_enqueue_scripts' ); |
|
| 229 | +add_action('wp_enqueue_scripts', 'wl_enqueue_scripts'); |
|
| 230 | 230 | |
| 231 | 231 | /** |
| 232 | 232 | * Hooked to *wp_kses_allowed_html* filter, adds microdata attributes. |
@@ -236,23 +236,23 @@ discard block |
||
| 236 | 236 | * |
| 237 | 237 | * @return array An array which contains allowed microdata attributes. |
| 238 | 238 | */ |
| 239 | -function wordlift_allowed_html( $allowedtags, $context ) { |
|
| 239 | +function wordlift_allowed_html($allowedtags, $context) { |
|
| 240 | 240 | |
| 241 | - if ( 'post' !== $context ) { |
|
| 241 | + if ('post' !== $context) { |
|
| 242 | 242 | return $allowedtags; |
| 243 | 243 | } |
| 244 | 244 | |
| 245 | - return array_merge_recursive( $allowedtags, array( |
|
| 245 | + return array_merge_recursive($allowedtags, array( |
|
| 246 | 246 | 'span' => array( |
| 247 | 247 | 'itemscope' => true, |
| 248 | 248 | 'itemtype' => true, |
| 249 | 249 | 'itemid' => true, |
| 250 | 250 | 'itemprop' => true |
| 251 | 251 | ) |
| 252 | - ) ); |
|
| 252 | + )); |
|
| 253 | 253 | } |
| 254 | 254 | |
| 255 | -add_filter( 'wp_kses_allowed_html', 'wordlift_allowed_html', 10, 2 ); |
|
| 255 | +add_filter('wp_kses_allowed_html', 'wordlift_allowed_html', 10, 2); |
|
| 256 | 256 | |
| 257 | 257 | /** |
| 258 | 258 | * Get the coordinates for the specified post ID. |
@@ -261,16 +261,16 @@ discard block |
||
| 261 | 261 | * |
| 262 | 262 | * @return array|null An array of coordinates or null. |
| 263 | 263 | */ |
| 264 | -function wl_get_coordinates( $post_id ) { |
|
| 264 | +function wl_get_coordinates($post_id) { |
|
| 265 | 265 | |
| 266 | - $latitude = wl_schema_get_value( $post_id, 'latitude' ); |
|
| 267 | - $longitude = wl_schema_get_value( $post_id, 'longitude' ); |
|
| 266 | + $latitude = wl_schema_get_value($post_id, 'latitude'); |
|
| 267 | + $longitude = wl_schema_get_value($post_id, 'longitude'); |
|
| 268 | 268 | |
| 269 | 269 | // DO NOT set latitude/longitude to 0/0 as default values. It's a specific place on the globe: |
| 270 | 270 | // "The zero/zero point of this system is located in the Gulf of Guinea about 625 km (390 mi) south of Tema, Ghana." |
| 271 | 271 | return array( |
| 272 | - 'latitude' => isset( $latitude[0] ) && is_numeric( $latitude[0] ) ? $latitude[0] : '', |
|
| 273 | - 'longitude' => isset( $longitude[0] ) && is_numeric( $longitude[0] ) ? $longitude[0] : '' |
|
| 272 | + 'latitude' => isset($latitude[0]) && is_numeric($latitude[0]) ? $latitude[0] : '', |
|
| 273 | + 'longitude' => isset($longitude[0]) && is_numeric($longitude[0]) ? $longitude[0] : '' |
|
| 274 | 274 | ); |
| 275 | 275 | } |
| 276 | 276 | |
@@ -281,12 +281,12 @@ discard block |
||
| 281 | 281 | * |
| 282 | 282 | * @return string A datetime. |
| 283 | 283 | */ |
| 284 | -function wl_get_post_modified_time( $post ) { |
|
| 284 | +function wl_get_post_modified_time($post) { |
|
| 285 | 285 | |
| 286 | - $date_modified = get_post_modified_time( 'c', true, $post ); |
|
| 286 | + $date_modified = get_post_modified_time('c', true, $post); |
|
| 287 | 287 | |
| 288 | - if ( '-' === substr( $date_modified, 0, 1 ) ) { |
|
| 289 | - return get_the_time( 'c', $post ); |
|
| 288 | + if ('-' === substr($date_modified, 0, 1)) { |
|
| 289 | + return get_the_time('c', $post); |
|
| 290 | 290 | } |
| 291 | 291 | |
| 292 | 292 | return $date_modified; |
@@ -299,18 +299,18 @@ discard block |
||
| 299 | 299 | * |
| 300 | 300 | * @return array An array of image URLs. |
| 301 | 301 | */ |
| 302 | -function wl_get_image_urls( $post_id ) { |
|
| 302 | +function wl_get_image_urls($post_id) { |
|
| 303 | 303 | |
| 304 | 304 | // wl_write_log( "wl_get_image_urls [ post id :: $post_id ]" ); |
| 305 | 305 | |
| 306 | - $images = get_children( array( |
|
| 306 | + $images = get_children(array( |
|
| 307 | 307 | 'post_parent' => $post_id, |
| 308 | 308 | 'post_type' => 'attachment', |
| 309 | 309 | 'post_mime_type' => 'image' |
| 310 | - ) ); |
|
| 310 | + )); |
|
| 311 | 311 | |
| 312 | 312 | // Return an empty array if no image is found. |
| 313 | - if ( empty( $images ) ) { |
|
| 313 | + if (empty($images)) { |
|
| 314 | 314 | return array(); |
| 315 | 315 | } |
| 316 | 316 | |
@@ -318,11 +318,11 @@ discard block |
||
| 318 | 318 | $image_urls = array(); |
| 319 | 319 | |
| 320 | 320 | // Collect the URLs. |
| 321 | - foreach ( $images as $attachment_id => $attachment ) { |
|
| 322 | - $image_url = wp_get_attachment_url( $attachment_id ); |
|
| 321 | + foreach ($images as $attachment_id => $attachment) { |
|
| 322 | + $image_url = wp_get_attachment_url($attachment_id); |
|
| 323 | 323 | // Ensure the URL isn't collected already. |
| 324 | - if ( ! in_array( $image_url, $image_urls ) ) { |
|
| 325 | - array_push( $image_urls, $image_url ); |
|
| 324 | + if ( ! in_array($image_url, $image_urls)) { |
|
| 325 | + array_push($image_urls, $image_url); |
|
| 326 | 326 | } |
| 327 | 327 | } |
| 328 | 328 | |
@@ -339,17 +339,17 @@ discard block |
||
| 339 | 339 | * |
| 340 | 340 | * @return string The SPARQL fragment. |
| 341 | 341 | */ |
| 342 | -function wl_get_sparql_images( $uri, $post_id ) { |
|
| 342 | +function wl_get_sparql_images($uri, $post_id) { |
|
| 343 | 343 | |
| 344 | 344 | $sparql = ''; |
| 345 | 345 | |
| 346 | 346 | // Get the escaped URI. |
| 347 | - $uri_e = esc_html( $uri ); |
|
| 347 | + $uri_e = esc_html($uri); |
|
| 348 | 348 | |
| 349 | 349 | // Add SPARQL stmts to write the schema:image. |
| 350 | - $image_urls = wl_get_image_urls( $post_id ); |
|
| 351 | - foreach ( $image_urls as $image_url ) { |
|
| 352 | - $image_url_esc = wl_sparql_escape_uri( $image_url ); |
|
| 350 | + $image_urls = wl_get_image_urls($post_id); |
|
| 351 | + foreach ($image_urls as $image_url) { |
|
| 352 | + $image_url_esc = wl_sparql_escape_uri($image_url); |
|
| 353 | 353 | $sparql .= " <$uri_e> schema:image <$image_url_esc> . \n"; |
| 354 | 354 | } |
| 355 | 355 | |
@@ -364,21 +364,21 @@ discard block |
||
| 364 | 364 | * |
| 365 | 365 | * @return WP_Post|null A post instance or null if not found. |
| 366 | 366 | */ |
| 367 | -function wl_get_attachment_for_source_url( $parent_post_id, $source_url ) { |
|
| 367 | +function wl_get_attachment_for_source_url($parent_post_id, $source_url) { |
|
| 368 | 368 | |
| 369 | 369 | // wl_write_log( "wl_get_attachment_for_source_url [ parent post id :: $parent_post_id ][ source url :: $source_url ]" ); |
| 370 | 370 | |
| 371 | - $posts = get_posts( array( |
|
| 371 | + $posts = get_posts(array( |
|
| 372 | 372 | 'post_type' => 'attachment', |
| 373 | 373 | 'posts_per_page' => 1, |
| 374 | 374 | 'post_status' => 'any', |
| 375 | 375 | 'post_parent' => $parent_post_id, |
| 376 | 376 | 'meta_key' => 'wl_source_url', |
| 377 | 377 | 'meta_value' => $source_url |
| 378 | - ) ); |
|
| 378 | + )); |
|
| 379 | 379 | |
| 380 | 380 | // Return the found post. |
| 381 | - if ( 1 === count( $posts ) ) { |
|
| 381 | + if (1 === count($posts)) { |
|
| 382 | 382 | return $posts[0]; |
| 383 | 383 | } |
| 384 | 384 | |
@@ -392,10 +392,10 @@ discard block |
||
| 392 | 392 | * @param int $post_id The post ID. |
| 393 | 393 | * @param string $source_url The source URL. |
| 394 | 394 | */ |
| 395 | -function wl_set_source_url( $post_id, $source_url ) { |
|
| 395 | +function wl_set_source_url($post_id, $source_url) { |
|
| 396 | 396 | |
| 397 | - delete_post_meta( $post_id, 'wl_source_url' ); |
|
| 398 | - add_post_meta( $post_id, 'wl_source_url', $source_url ); |
|
| 397 | + delete_post_meta($post_id, 'wl_source_url'); |
|
| 398 | + add_post_meta($post_id, 'wl_source_url', $source_url); |
|
| 399 | 399 | } |
| 400 | 400 | |
| 401 | 401 | |
@@ -411,14 +411,14 @@ discard block |
||
| 411 | 411 | * |
| 412 | 412 | * @param bool $hard True if the rewrite involves configuration updates in Apache/IIS. |
| 413 | 413 | */ |
| 414 | -function wl_flush_rewrite_rules_hard( $hard ) { |
|
| 414 | +function wl_flush_rewrite_rules_hard($hard) { |
|
| 415 | 415 | |
| 416 | 416 | // Get all published posts. |
| 417 | - $posts = get_posts( array( |
|
| 418 | - 'posts_per_page' => - 1, |
|
| 417 | + $posts = get_posts(array( |
|
| 418 | + 'posts_per_page' => -1, |
|
| 419 | 419 | 'post_type' => 'any', |
| 420 | 420 | 'post_status' => 'publish' |
| 421 | - ) ); |
|
| 421 | + )); |
|
| 422 | 422 | |
| 423 | 423 | // Holds the delete part of the query. |
| 424 | 424 | $delete_query = rl_sparql_prefixes(); |
@@ -426,18 +426,18 @@ discard block |
||
| 426 | 426 | $insert_query = 'INSERT DATA { '; |
| 427 | 427 | |
| 428 | 428 | // Cycle in each post to build the query. |
| 429 | - foreach ( $posts as $post ) { |
|
| 429 | + foreach ($posts as $post) { |
|
| 430 | 430 | |
| 431 | 431 | // Ignore revisions. |
| 432 | - if ( wp_is_post_revision( $post->ID ) ) { |
|
| 432 | + if (wp_is_post_revision($post->ID)) { |
|
| 433 | 433 | continue; |
| 434 | 434 | } |
| 435 | 435 | |
| 436 | 436 | // Get the entity URI. |
| 437 | - $uri = wl_sparql_escape_uri( wl_get_entity_uri( $post->ID ) ); |
|
| 437 | + $uri = wl_sparql_escape_uri(wl_get_entity_uri($post->ID)); |
|
| 438 | 438 | |
| 439 | 439 | // Get the post URL. |
| 440 | - $url = wl_sparql_escape_uri( get_permalink( $post->ID ) ); |
|
| 440 | + $url = wl_sparql_escape_uri(get_permalink($post->ID)); |
|
| 441 | 441 | |
| 442 | 442 | // Prepare the DELETE and INSERT commands. |
| 443 | 443 | $delete_query .= "DELETE { <$uri> schema:url ?u . } WHERE { <$uri> schema:url ?u . };\n"; |
@@ -449,10 +449,10 @@ discard block |
||
| 449 | 449 | $insert_query .= ' };'; |
| 450 | 450 | |
| 451 | 451 | // Execute the query. |
| 452 | - rl_execute_sparql_update_query( $delete_query . $insert_query ); |
|
| 452 | + rl_execute_sparql_update_query($delete_query.$insert_query); |
|
| 453 | 453 | } |
| 454 | 454 | |
| 455 | -add_filter( 'flush_rewrite_rules_hard', 'wl_flush_rewrite_rules_hard', 10, 1 ); |
|
| 455 | +add_filter('flush_rewrite_rules_hard', 'wl_flush_rewrite_rules_hard', 10, 1); |
|
| 456 | 456 | |
| 457 | 457 | /** |
| 458 | 458 | * Sanitizes an URI path by replacing the non allowed characters with an underscore. |
@@ -464,7 +464,7 @@ discard block |
||
| 464 | 464 | * |
| 465 | 465 | * @return The sanitized path. |
| 466 | 466 | */ |
| 467 | -function wl_sanitize_uri_path( $path, $char = '_' ) { |
|
| 467 | +function wl_sanitize_uri_path($path, $char = '_') { |
|
| 468 | 468 | |
| 469 | 469 | // wl_write_log( "wl_sanitize_uri_path [ path :: $path ][ char :: $char ]" ); |
| 470 | 470 | |
@@ -474,7 +474,7 @@ discard block |
||
| 474 | 474 | // Plus the ' ' (space). |
| 475 | 475 | // TODO: We shall use the same regex used by MediaWiki (http://stackoverflow.com/questions/23114983/mediawiki-wikipedia-url-sanitization-regex) |
| 476 | 476 | |
| 477 | - return sanitize_title( preg_replace( '/[;\/?:@&=+$,\s]/', $char, stripslashes( $path ) ) ); |
|
| 477 | + return sanitize_title(preg_replace('/[;\/?:@&=+$,\s]/', $char, stripslashes($path))); |
|
| 478 | 478 | } |
| 479 | 479 | |
| 480 | 480 | /** |
@@ -483,28 +483,28 @@ discard block |
||
| 483 | 483 | function wl_shutdown() { |
| 484 | 484 | |
| 485 | 485 | // Get the filename to the temporary SPARQL file. |
| 486 | - $filename = WL_TEMP_DIR . WL_REQUEST_ID . '.sparql'; |
|
| 486 | + $filename = WL_TEMP_DIR.WL_REQUEST_ID.'.sparql'; |
|
| 487 | 487 | |
| 488 | 488 | // If WordLift is buffering SPARQL queries, we're admins and a buffer exists, then schedule it. |
| 489 | - if ( WL_ENABLE_SPARQL_UPDATE_QUERIES_BUFFERING && is_admin() && file_exists( $filename ) ) { |
|
| 489 | + if (WL_ENABLE_SPARQL_UPDATE_QUERIES_BUFFERING && is_admin() && file_exists($filename)) { |
|
| 490 | 490 | |
| 491 | 491 | // The request ID. |
| 492 | - $args = array( WL_REQUEST_ID ); |
|
| 492 | + $args = array(WL_REQUEST_ID); |
|
| 493 | 493 | |
| 494 | 494 | // Schedule the execution of the SPARQL query with the request ID. |
| 495 | - wp_schedule_single_event( time(), 'wl_execute_saved_sparql_update_query', $args ); |
|
| 495 | + wp_schedule_single_event(time(), 'wl_execute_saved_sparql_update_query', $args); |
|
| 496 | 496 | |
| 497 | 497 | // Check that the request is scheduled. |
| 498 | - $timestamp = wp_next_scheduled( 'wl_execute_saved_sparql_update_query', $args ); |
|
| 498 | + $timestamp = wp_next_scheduled('wl_execute_saved_sparql_update_query', $args); |
|
| 499 | 499 | |
| 500 | 500 | // Spawn the cron. |
| 501 | 501 | spawn_cron(); |
| 502 | 502 | |
| 503 | - wl_write_log( "wl_shutdown [ request id :: " . WL_REQUEST_ID . " ][ timestamp :: $timestamp ]" ); |
|
| 503 | + wl_write_log("wl_shutdown [ request id :: ".WL_REQUEST_ID." ][ timestamp :: $timestamp ]"); |
|
| 504 | 504 | } |
| 505 | 505 | } |
| 506 | 506 | |
| 507 | -add_action( 'shutdown', 'wl_shutdown' ); |
|
| 507 | +add_action('shutdown', 'wl_shutdown'); |
|
| 508 | 508 | |
| 509 | 509 | /** |
| 510 | 510 | * Replaces the *itemid* attributes URIs with the WordLift URIs. |
@@ -513,129 +513,129 @@ discard block |
||
| 513 | 513 | * |
| 514 | 514 | * @return string The updated post content. |
| 515 | 515 | */ |
| 516 | -function wl_replace_item_id_with_uri( $content ) { |
|
| 516 | +function wl_replace_item_id_with_uri($content) { |
|
| 517 | 517 | |
| 518 | 518 | // wl_write_log( "wl_replace_item_id_with_uri" ); |
| 519 | 519 | |
| 520 | 520 | // Strip slashes, see https://core.trac.wordpress.org/ticket/21767 |
| 521 | - $content = stripslashes( $content ); |
|
| 521 | + $content = stripslashes($content); |
|
| 522 | 522 | |
| 523 | 523 | // If any match are found. |
| 524 | 524 | $matches = array(); |
| 525 | - if ( 0 < preg_match_all( '/ itemid="([^"]+)"/i', $content, $matches, PREG_SET_ORDER ) ) { |
|
| 525 | + if (0 < preg_match_all('/ itemid="([^"]+)"/i', $content, $matches, PREG_SET_ORDER)) { |
|
| 526 | 526 | |
| 527 | - foreach ( $matches as $match ) { |
|
| 527 | + foreach ($matches as $match) { |
|
| 528 | 528 | |
| 529 | 529 | // Get the item ID. |
| 530 | 530 | $item_id = $match[1]; |
| 531 | 531 | |
| 532 | 532 | // Get the post bound to that item ID (looking both in the 'official' URI and in the 'same-as' . |
| 533 | - $post = wl_get_entity_post_by_uri( $item_id ); |
|
| 533 | + $post = wl_get_entity_post_by_uri($item_id); |
|
| 534 | 534 | |
| 535 | 535 | // If no entity is found, continue to the next one. |
| 536 | - if ( null === $post ) { |
|
| 536 | + if (null === $post) { |
|
| 537 | 537 | continue; |
| 538 | 538 | } |
| 539 | 539 | |
| 540 | 540 | // Get the URI for that post. |
| 541 | - $uri = wl_get_entity_uri( $post->ID ); |
|
| 541 | + $uri = wl_get_entity_uri($post->ID); |
|
| 542 | 542 | |
| 543 | 543 | // wl_write_log( "wl_replace_item_id_with_uri [ item id :: $item_id ][ uri :: $uri ]" ); |
| 544 | 544 | |
| 545 | 545 | // If the item ID and the URI differ, replace the item ID with the URI saved in WordPress. |
| 546 | - if ( $item_id !== $uri ) { |
|
| 547 | - $uri_e = esc_html( $uri ); |
|
| 548 | - $content = str_replace( " itemid=\"$item_id\"", " itemid=\"$uri_e\"", $content ); |
|
| 546 | + if ($item_id !== $uri) { |
|
| 547 | + $uri_e = esc_html($uri); |
|
| 548 | + $content = str_replace(" itemid=\"$item_id\"", " itemid=\"$uri_e\"", $content); |
|
| 549 | 549 | } |
| 550 | 550 | } |
| 551 | 551 | } |
| 552 | 552 | |
| 553 | 553 | // Reapply slashes. |
| 554 | - $content = addslashes( $content ); |
|
| 554 | + $content = addslashes($content); |
|
| 555 | 555 | |
| 556 | 556 | return $content; |
| 557 | 557 | } |
| 558 | 558 | |
| 559 | -add_filter( 'content_save_pre', 'wl_replace_item_id_with_uri', 1, 1 ); |
|
| 559 | +add_filter('content_save_pre', 'wl_replace_item_id_with_uri', 1, 1); |
|
| 560 | 560 | |
| 561 | -require_once( 'wordlift_entity_functions.php' ); |
|
| 561 | +require_once('wordlift_entity_functions.php'); |
|
| 562 | 562 | |
| 563 | 563 | // add editor related methods. |
| 564 | -require_once( 'wordlift_editor.php' ); |
|
| 564 | +require_once('wordlift_editor.php'); |
|
| 565 | 565 | |
| 566 | 566 | // add the WordLift entity custom type. |
| 567 | -require_once( 'wordlift_entity_type.php' ); |
|
| 568 | -require_once( 'wordlift_entity_type_taxonomy.php' ); |
|
| 567 | +require_once('wordlift_entity_type.php'); |
|
| 568 | +require_once('wordlift_entity_type_taxonomy.php'); |
|
| 569 | 569 | |
| 570 | 570 | // filters the post content when saving posts. |
| 571 | -require_once( 'wordlift_content_filter.php' ); |
|
| 571 | +require_once('wordlift_content_filter.php'); |
|
| 572 | 572 | // add callbacks on post save to notify data changes from wp to redlink triple store |
| 573 | -require_once( 'wordlift_to_redlink_data_push_callbacks.php' ); |
|
| 573 | +require_once('wordlift_to_redlink_data_push_callbacks.php'); |
|
| 574 | 574 | |
| 575 | 575 | // Load modules |
| 576 | -require_once( 'modules/analyzer/wordlift_analyzer.php' ); |
|
| 577 | -require_once( 'modules/linked_data/wordlift_linked_data.php' ); |
|
| 578 | -require_once( 'modules/prefixes/wordlift_prefixes.php' ); |
|
| 579 | -require_once( 'modules/caching/wordlift_caching.php' ); |
|
| 580 | -require_once( 'modules/profiling/wordlift_profiling.php' ); |
|
| 581 | -require_once( 'modules/redirector/wordlift_redirector.php' ); |
|
| 582 | -require_once( 'modules/freebase_image_proxy/wordlift_freebase_image_proxy.php' ); |
|
| 576 | +require_once('modules/analyzer/wordlift_analyzer.php'); |
|
| 577 | +require_once('modules/linked_data/wordlift_linked_data.php'); |
|
| 578 | +require_once('modules/prefixes/wordlift_prefixes.php'); |
|
| 579 | +require_once('modules/caching/wordlift_caching.php'); |
|
| 580 | +require_once('modules/profiling/wordlift_profiling.php'); |
|
| 581 | +require_once('modules/redirector/wordlift_redirector.php'); |
|
| 582 | +require_once('modules/freebase_image_proxy/wordlift_freebase_image_proxy.php'); |
|
| 583 | 583 | |
| 584 | 584 | // Shortcodes |
| 585 | 585 | |
| 586 | 586 | // Entity view shortcode just with php >= 5.4 |
| 587 | -if ( version_compare( phpversion(), '5.4.0', '>=' ) ) { |
|
| 588 | - require_once( 'modules/entity_view/wordlift_entity_view.php' ); |
|
| 587 | +if (version_compare(phpversion(), '5.4.0', '>=')) { |
|
| 588 | + require_once('modules/entity_view/wordlift_entity_view.php'); |
|
| 589 | 589 | } |
| 590 | 590 | |
| 591 | -require_once( 'modules/geo_widget/wordlift_geo_widget.php' ); |
|
| 592 | -require_once( 'shortcodes/wordlift_shortcode_chord.php' ); |
|
| 593 | -require_once( 'shortcodes/wordlift_shortcode_geomap.php' ); |
|
| 594 | -require_once( 'shortcodes/wordlift_shortcode_field.php' ); |
|
| 595 | -require_once( 'shortcodes/wordlift_shortcode_faceted_search.php' ); |
|
| 596 | -require_once( 'shortcodes/wordlift_shortcode_navigator.php' ); |
|
| 597 | -require_once( 'shortcodes/wordlift_shortcode_blog_map.php' ); |
|
| 591 | +require_once('modules/geo_widget/wordlift_geo_widget.php'); |
|
| 592 | +require_once('shortcodes/wordlift_shortcode_chord.php'); |
|
| 593 | +require_once('shortcodes/wordlift_shortcode_geomap.php'); |
|
| 594 | +require_once('shortcodes/wordlift_shortcode_field.php'); |
|
| 595 | +require_once('shortcodes/wordlift_shortcode_faceted_search.php'); |
|
| 596 | +require_once('shortcodes/wordlift_shortcode_navigator.php'); |
|
| 597 | +require_once('shortcodes/wordlift_shortcode_blog_map.php'); |
|
| 598 | 598 | |
| 599 | 599 | // disable In-Depth Articles |
| 600 | 600 | //require_once('wordlift_indepth_articles.php'); |
| 601 | 601 | |
| 602 | -require_once( 'widgets/wordlift_widget_geo.php' ); |
|
| 603 | -require_once( 'widgets/wordlift_widget_chord.php' ); |
|
| 604 | -require_once( 'widgets/wordlift_widget_timeline.php' ); |
|
| 602 | +require_once('widgets/wordlift_widget_geo.php'); |
|
| 603 | +require_once('widgets/wordlift_widget_chord.php'); |
|
| 604 | +require_once('widgets/wordlift_widget_timeline.php'); |
|
| 605 | 605 | |
| 606 | -require_once( 'wordlift_sparql.php' ); |
|
| 607 | -require_once( 'wordlift_redlink.php' ); |
|
| 606 | +require_once('wordlift_sparql.php'); |
|
| 607 | +require_once('wordlift_redlink.php'); |
|
| 608 | 608 | |
| 609 | -require_once( 'modules/sparql/wordlift_sparql.php' ); |
|
| 609 | +require_once('modules/sparql/wordlift_sparql.php'); |
|
| 610 | 610 | |
| 611 | 611 | // Add admin functions. |
| 612 | 612 | // TODO: find a way to make 'admin' UI tests work. |
| 613 | 613 | //if ( is_admin() ) { |
| 614 | 614 | |
| 615 | -require_once( 'admin/wordlift_admin.php' ); |
|
| 616 | -require_once( 'admin/wordlift_admin_edit_post.php' ); |
|
| 617 | -require_once( 'admin/wordlift_admin_save_post.php' ); |
|
| 615 | +require_once('admin/wordlift_admin.php'); |
|
| 616 | +require_once('admin/wordlift_admin_edit_post.php'); |
|
| 617 | +require_once('admin/wordlift_admin_save_post.php'); |
|
| 618 | 618 | |
| 619 | 619 | // add the WordLift admin bar. |
| 620 | -require_once( 'admin/wordlift_admin_bar.php' ); |
|
| 620 | +require_once('admin/wordlift_admin_bar.php'); |
|
| 621 | 621 | |
| 622 | 622 | // add the entities meta box. |
| 623 | -require_once( 'admin/wordlift_admin_meta_box_entities.php' ); |
|
| 623 | +require_once('admin/wordlift_admin_meta_box_entities.php'); |
|
| 624 | 624 | |
| 625 | 625 | // add the entity creation AJAX. |
| 626 | -require_once( 'admin/wordlift_admin_ajax_related_posts.php' ); |
|
| 626 | +require_once('admin/wordlift_admin_ajax_related_posts.php'); |
|
| 627 | 627 | |
| 628 | 628 | // Load the wl_chord TinyMCE button and configuration dialog. |
| 629 | -require_once( 'admin/wordlift_admin_shortcodes.php' ); |
|
| 629 | +require_once('admin/wordlift_admin_shortcodes.php'); |
|
| 630 | 630 | |
| 631 | 631 | // Provide syncing features. |
| 632 | -require_once( 'admin/wordlift_admin_sync.php' ); |
|
| 632 | +require_once('admin/wordlift_admin_sync.php'); |
|
| 633 | 633 | //} |
| 634 | 634 | |
| 635 | 635 | // load languages. |
| 636 | 636 | // TODO: the following call gives for granted that the plugin is in the wordlift directory, |
| 637 | 637 | // we're currently doing this because wordlift is symbolic linked. |
| 638 | -load_plugin_textdomain( 'wordlift', false, '/wordlift/languages' ); |
|
| 638 | +load_plugin_textdomain('wordlift', false, '/wordlift/languages'); |
|
| 639 | 639 | |
| 640 | 640 | |
| 641 | 641 | /** |
@@ -643,7 +643,7 @@ discard block |
||
| 643 | 643 | * This action is documented in includes/class-wordlift-activator.php |
| 644 | 644 | */ |
| 645 | 645 | function activate_wordlift() { |
| 646 | - require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-activator.php'; |
|
| 646 | + require_once plugin_dir_path(__FILE__).'includes/class-wordlift-activator.php'; |
|
| 647 | 647 | Wordlift_Activator::activate(); |
| 648 | 648 | } |
| 649 | 649 | |
@@ -652,18 +652,18 @@ discard block |
||
| 652 | 652 | * This action is documented in includes/class-wordlift-deactivator.php |
| 653 | 653 | */ |
| 654 | 654 | function deactivate_wordlift() { |
| 655 | - require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-deactivator.php'; |
|
| 655 | + require_once plugin_dir_path(__FILE__).'includes/class-wordlift-deactivator.php'; |
|
| 656 | 656 | Wordlift_Deactivator::deactivate(); |
| 657 | 657 | } |
| 658 | 658 | |
| 659 | -register_activation_hook( __FILE__, 'activate_wordlift' ); |
|
| 660 | -register_deactivation_hook( __FILE__, 'deactivate_wordlift' ); |
|
| 659 | +register_activation_hook(__FILE__, 'activate_wordlift'); |
|
| 660 | +register_deactivation_hook(__FILE__, 'deactivate_wordlift'); |
|
| 661 | 661 | |
| 662 | 662 | /** |
| 663 | 663 | * The core plugin class that is used to define internationalization, |
| 664 | 664 | * admin-specific hooks, and public-facing site hooks. |
| 665 | 665 | */ |
| 666 | -require plugin_dir_path( __FILE__ ) . 'includes/class-wordlift.php'; |
|
| 666 | +require plugin_dir_path(__FILE__).'includes/class-wordlift.php'; |
|
| 667 | 667 | |
| 668 | 668 | /** |
| 669 | 669 | * Begins execution of the plugin. |
@@ -18,55 +18,55 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | function rl_execute_sparql_update_query( $query, $queue = WL_ENABLE_SPARQL_UPDATE_QUERIES_BUFFERING ) { |
| 20 | 20 | |
| 21 | - // Queue the update query. |
|
| 22 | - if ( $queue ) { |
|
| 21 | + // Queue the update query. |
|
| 22 | + if ( $queue ) { |
|
| 23 | 23 | |
| 24 | - if ( WP_DEBUG ) { |
|
| 25 | - global $wl_logger; |
|
| 26 | - $wl_logger->trace( "Buffering a query [ query :: $query ]" ); |
|
| 27 | - } |
|
| 24 | + if ( WP_DEBUG ) { |
|
| 25 | + global $wl_logger; |
|
| 26 | + $wl_logger->trace( "Buffering a query [ query :: $query ]" ); |
|
| 27 | + } |
|
| 28 | 28 | |
| 29 | - wl_queue_sparql_update_query( $query ); |
|
| 29 | + wl_queue_sparql_update_query( $query ); |
|
| 30 | 30 | |
| 31 | - return true; |
|
| 32 | - } |
|
| 31 | + return true; |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - // Get the update end-point. |
|
| 35 | - $url = wl_configuration_get_query_update_url(); |
|
| 34 | + // Get the update end-point. |
|
| 35 | + $url = wl_configuration_get_query_update_url(); |
|
| 36 | 36 | |
| 37 | - // Prepare the request. |
|
| 38 | - $args = array_merge_recursive( unserialize( WL_REDLINK_API_HTTP_OPTIONS ), array( |
|
| 39 | - 'method' => 'POST', |
|
| 40 | - 'headers' => array( |
|
| 41 | - 'Accept' => 'application/json', |
|
| 42 | - 'Content-type' => 'application/sparql-update; charset=utf-8' |
|
| 43 | - ), |
|
| 44 | - 'body' => $query |
|
| 45 | - ) ); |
|
| 37 | + // Prepare the request. |
|
| 38 | + $args = array_merge_recursive( unserialize( WL_REDLINK_API_HTTP_OPTIONS ), array( |
|
| 39 | + 'method' => 'POST', |
|
| 40 | + 'headers' => array( |
|
| 41 | + 'Accept' => 'application/json', |
|
| 42 | + 'Content-type' => 'application/sparql-update; charset=utf-8' |
|
| 43 | + ), |
|
| 44 | + 'body' => $query |
|
| 45 | + ) ); |
|
| 46 | 46 | |
| 47 | - // Send the request. |
|
| 48 | - $response = wp_remote_post( $url, $args ); |
|
| 47 | + // Send the request. |
|
| 48 | + $response = wp_remote_post( $url, $args ); |
|
| 49 | 49 | |
| 50 | - // If an error has been raised, return the error. |
|
| 51 | - if ( is_wp_error( $response ) || 200 !== (int) $response['response']['code'] ) { |
|
| 50 | + // If an error has been raised, return the error. |
|
| 51 | + if ( is_wp_error( $response ) || 200 !== (int) $response['response']['code'] ) { |
|
| 52 | 52 | |
| 53 | - $body = ( is_wp_error( $response ) ? $response->get_error_message() : $response['body'] ); |
|
| 53 | + $body = ( is_wp_error( $response ) ? $response->get_error_message() : $response['body'] ); |
|
| 54 | 54 | |
| 55 | - wl_write_log( "rl_execute_sparql_update_query : error [ url :: $url ][ args :: " ); |
|
| 56 | - wl_write_log( "\n" . var_export( $args, true ) ); |
|
| 57 | - wl_write_log( "[ response :: " ); |
|
| 58 | - wl_write_log( "\n" . var_export( $response, true ) ); |
|
| 59 | - wl_write_log( "][ body :: " ); |
|
| 60 | - wl_write_log( "\n" . $body ); |
|
| 61 | - wl_write_log( "]" ); |
|
| 55 | + wl_write_log( "rl_execute_sparql_update_query : error [ url :: $url ][ args :: " ); |
|
| 56 | + wl_write_log( "\n" . var_export( $args, true ) ); |
|
| 57 | + wl_write_log( "[ response :: " ); |
|
| 58 | + wl_write_log( "\n" . var_export( $response, true ) ); |
|
| 59 | + wl_write_log( "][ body :: " ); |
|
| 60 | + wl_write_log( "\n" . $body ); |
|
| 61 | + wl_write_log( "]" ); |
|
| 62 | 62 | |
| 63 | - return false; |
|
| 64 | - } |
|
| 63 | + return false; |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - if ( WP_DEBUG ) { |
|
| 67 | - global $wl_logger; |
|
| 68 | - $wl_logger->trace( "Query executed successfully [ query :: $query ]" ); |
|
| 69 | - } |
|
| 66 | + if ( WP_DEBUG ) { |
|
| 67 | + global $wl_logger; |
|
| 68 | + $wl_logger->trace( "Query executed successfully [ query :: $query ]" ); |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - return true; |
|
| 71 | + return true; |
|
| 72 | 72 | } |
@@ -16,17 +16,17 @@ discard block |
||
| 16 | 16 | * |
| 17 | 17 | * @return bool True if successful otherwise false. |
| 18 | 18 | */ |
| 19 | -function rl_execute_sparql_update_query( $query, $queue = WL_ENABLE_SPARQL_UPDATE_QUERIES_BUFFERING ) { |
|
| 19 | +function rl_execute_sparql_update_query($query, $queue = WL_ENABLE_SPARQL_UPDATE_QUERIES_BUFFERING) { |
|
| 20 | 20 | |
| 21 | 21 | // Queue the update query. |
| 22 | - if ( $queue ) { |
|
| 22 | + if ($queue) { |
|
| 23 | 23 | |
| 24 | - if ( WP_DEBUG ) { |
|
| 24 | + if (WP_DEBUG) { |
|
| 25 | 25 | global $wl_logger; |
| 26 | - $wl_logger->trace( "Buffering a query [ query :: $query ]" ); |
|
| 26 | + $wl_logger->trace("Buffering a query [ query :: $query ]"); |
|
| 27 | 27 | } |
| 28 | 28 | |
| 29 | - wl_queue_sparql_update_query( $query ); |
|
| 29 | + wl_queue_sparql_update_query($query); |
|
| 30 | 30 | |
| 31 | 31 | return true; |
| 32 | 32 | } |
@@ -35,37 +35,37 @@ discard block |
||
| 35 | 35 | $url = wl_configuration_get_query_update_url(); |
| 36 | 36 | |
| 37 | 37 | // Prepare the request. |
| 38 | - $args = array_merge_recursive( unserialize( WL_REDLINK_API_HTTP_OPTIONS ), array( |
|
| 38 | + $args = array_merge_recursive(unserialize(WL_REDLINK_API_HTTP_OPTIONS), array( |
|
| 39 | 39 | 'method' => 'POST', |
| 40 | 40 | 'headers' => array( |
| 41 | 41 | 'Accept' => 'application/json', |
| 42 | 42 | 'Content-type' => 'application/sparql-update; charset=utf-8' |
| 43 | 43 | ), |
| 44 | 44 | 'body' => $query |
| 45 | - ) ); |
|
| 45 | + )); |
|
| 46 | 46 | |
| 47 | 47 | // Send the request. |
| 48 | - $response = wp_remote_post( $url, $args ); |
|
| 48 | + $response = wp_remote_post($url, $args); |
|
| 49 | 49 | |
| 50 | 50 | // If an error has been raised, return the error. |
| 51 | - if ( is_wp_error( $response ) || 200 !== (int) $response['response']['code'] ) { |
|
| 51 | + if (is_wp_error($response) || 200 !== (int) $response['response']['code']) { |
|
| 52 | 52 | |
| 53 | - $body = ( is_wp_error( $response ) ? $response->get_error_message() : $response['body'] ); |
|
| 53 | + $body = (is_wp_error($response) ? $response->get_error_message() : $response['body']); |
|
| 54 | 54 | |
| 55 | - wl_write_log( "rl_execute_sparql_update_query : error [ url :: $url ][ args :: " ); |
|
| 56 | - wl_write_log( "\n" . var_export( $args, true ) ); |
|
| 57 | - wl_write_log( "[ response :: " ); |
|
| 58 | - wl_write_log( "\n" . var_export( $response, true ) ); |
|
| 59 | - wl_write_log( "][ body :: " ); |
|
| 60 | - wl_write_log( "\n" . $body ); |
|
| 61 | - wl_write_log( "]" ); |
|
| 55 | + wl_write_log("rl_execute_sparql_update_query : error [ url :: $url ][ args :: "); |
|
| 56 | + wl_write_log("\n".var_export($args, true)); |
|
| 57 | + wl_write_log("[ response :: "); |
|
| 58 | + wl_write_log("\n".var_export($response, true)); |
|
| 59 | + wl_write_log("][ body :: "); |
|
| 60 | + wl_write_log("\n".$body); |
|
| 61 | + wl_write_log("]"); |
|
| 62 | 62 | |
| 63 | 63 | return false; |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | - if ( WP_DEBUG ) { |
|
| 66 | + if (WP_DEBUG) { |
|
| 67 | 67 | global $wl_logger; |
| 68 | - $wl_logger->trace( "Query executed successfully [ query :: $query ]" ); |
|
| 68 | + $wl_logger->trace("Query executed successfully [ query :: $query ]"); |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | return true; |
@@ -8,67 +8,67 @@ discard block |
||
| 8 | 8 | function wl_push_post_to_redlink( $post ) { |
| 9 | 9 | |
| 10 | 10 | |
| 11 | - // Only handle published posts. |
|
| 12 | - if ( 'post' !== $post->post_type or 'publish' !== $post->post_status ) { |
|
| 13 | - wl_write_log( "wl_push_post_to_redlink : not a post or not published [ post type :: $post->post_type ][ post status :: $post->post_status ]" ); |
|
| 11 | + // Only handle published posts. |
|
| 12 | + if ( 'post' !== $post->post_type or 'publish' !== $post->post_status ) { |
|
| 13 | + wl_write_log( "wl_push_post_to_redlink : not a post or not published [ post type :: $post->post_type ][ post status :: $post->post_status ]" ); |
|
| 14 | 14 | |
| 15 | - return; |
|
| 16 | - } |
|
| 15 | + return; |
|
| 16 | + } |
|
| 17 | 17 | |
| 18 | - // Get the post URI. |
|
| 19 | - $uri = wl_sparql_escape_uri( wl_get_entity_uri( $post->ID ) ); |
|
| 18 | + // Get the post URI. |
|
| 19 | + $uri = wl_sparql_escape_uri( wl_get_entity_uri( $post->ID ) ); |
|
| 20 | 20 | |
| 21 | - // If the URI ends with a trailing slash, then we have a problem. |
|
| 22 | - if ( '/' === substr( $uri, - 1, 1 ) ) { |
|
| 21 | + // If the URI ends with a trailing slash, then we have a problem. |
|
| 22 | + if ( '/' === substr( $uri, - 1, 1 ) ) { |
|
| 23 | 23 | |
| 24 | - wl_write_log( "wl_push_post_to_redlink : the URI is invalid [ post ID :: $post->ID ][ URI :: $uri ]" ); |
|
| 24 | + wl_write_log( "wl_push_post_to_redlink : the URI is invalid [ post ID :: $post->ID ][ URI :: $uri ]" ); |
|
| 25 | 25 | |
| 26 | - return; |
|
| 27 | - } |
|
| 26 | + return; |
|
| 27 | + } |
|
| 28 | 28 | |
| 29 | - // wl_write_log( "wl_push_post_to_redlink [ post id :: $post->ID ][ uri :: $uri ]" ); |
|
| 29 | + // wl_write_log( "wl_push_post_to_redlink [ post id :: $post->ID ][ uri :: $uri ]" ); |
|
| 30 | 30 | |
| 31 | - // Get the site language in order to define the literals language. |
|
| 32 | - $site_language = wl_configuration_get_site_language(); |
|
| 31 | + // Get the site language in order to define the literals language. |
|
| 32 | + $site_language = wl_configuration_get_site_language(); |
|
| 33 | 33 | |
| 34 | - // save the author and get the author URI. |
|
| 35 | - $author_uri = wl_sparql_escape_uri( Wordlift_User_Service::get_instance()->get_uri( $post->post_author ) ); |
|
| 34 | + // save the author and get the author URI. |
|
| 35 | + $author_uri = wl_sparql_escape_uri( Wordlift_User_Service::get_instance()->get_uri( $post->post_author ) ); |
|
| 36 | 36 | |
| 37 | - // Get other post properties. |
|
| 38 | - $date_published = wl_get_sparql_time( get_the_time( 'c', $post ) ); |
|
| 39 | - $date_modified = wl_get_sparql_time( wl_get_post_modified_time( $post ) ); |
|
| 40 | - $title = wordlift_esc_sparql( $post->post_title ); |
|
| 41 | - $permalink = wl_sparql_escape_uri( get_permalink( $post->ID ) ); |
|
| 42 | - $user_comments_count = $post->comment_count; |
|
| 37 | + // Get other post properties. |
|
| 38 | + $date_published = wl_get_sparql_time( get_the_time( 'c', $post ) ); |
|
| 39 | + $date_modified = wl_get_sparql_time( wl_get_post_modified_time( $post ) ); |
|
| 40 | + $title = wordlift_esc_sparql( $post->post_title ); |
|
| 41 | + $permalink = wl_sparql_escape_uri( get_permalink( $post->ID ) ); |
|
| 42 | + $user_comments_count = $post->comment_count; |
|
| 43 | 43 | |
| 44 | - wl_write_log( "wl_push_post_to_redlink [ post_id :: $post->ID ][ type :: $post->post_type ][ slug :: $post->post_name ][ title :: $post->post_title ][ date modified :: $date_modified ][ date published :: $date_published ]" ); |
|
| 44 | + wl_write_log( "wl_push_post_to_redlink [ post_id :: $post->ID ][ type :: $post->post_type ][ slug :: $post->post_name ][ title :: $post->post_title ][ date modified :: $date_modified ][ date published :: $date_published ]" ); |
|
| 45 | 45 | |
| 46 | - // create the SPARQL query. |
|
| 47 | - $sparql = ''; |
|
| 48 | - if ( ! empty( $title ) ) { |
|
| 49 | - $sparql .= "<$uri> rdfs:label '$title'@$site_language . \n"; |
|
| 50 | - } |
|
| 46 | + // create the SPARQL query. |
|
| 47 | + $sparql = ''; |
|
| 48 | + if ( ! empty( $title ) ) { |
|
| 49 | + $sparql .= "<$uri> rdfs:label '$title'@$site_language . \n"; |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - $sparql .= "<$uri> a <http://schema.org/BlogPosting> . \n"; |
|
| 53 | - $sparql .= "<$uri> schema:url <$permalink> . \n"; |
|
| 54 | - $sparql .= "<$uri> schema:datePublished $date_published . \n"; |
|
| 55 | - $sparql .= "<$uri> schema:dateModified $date_modified . \n"; |
|
| 56 | - if ( ! empty( $author_uri ) ) { |
|
| 57 | - $sparql .= "<$uri> schema:author <$author_uri> . \n"; |
|
| 58 | - } |
|
| 59 | - $sparql .= "<$uri> schema:interactionCount 'UserComments:$user_comments_count' . \n"; |
|
| 52 | + $sparql .= "<$uri> a <http://schema.org/BlogPosting> . \n"; |
|
| 53 | + $sparql .= "<$uri> schema:url <$permalink> . \n"; |
|
| 54 | + $sparql .= "<$uri> schema:datePublished $date_published . \n"; |
|
| 55 | + $sparql .= "<$uri> schema:dateModified $date_modified . \n"; |
|
| 56 | + if ( ! empty( $author_uri ) ) { |
|
| 57 | + $sparql .= "<$uri> schema:author <$author_uri> . \n"; |
|
| 58 | + } |
|
| 59 | + $sparql .= "<$uri> schema:interactionCount 'UserComments:$user_comments_count' . \n"; |
|
| 60 | 60 | |
| 61 | 61 | |
| 62 | - // Add SPARQL stmts to write the schema:image. |
|
| 63 | - $sparql .= wl_get_sparql_images( $uri, $post->ID ); |
|
| 62 | + // Add SPARQL stmts to write the schema:image. |
|
| 63 | + $sparql .= wl_get_sparql_images( $uri, $post->ID ); |
|
| 64 | 64 | |
| 65 | - // Get the SPARQL fragment with the dcterms:references statement. |
|
| 66 | - $sparql .= wl_get_sparql_post_references( $post->ID ); |
|
| 65 | + // Get the SPARQL fragment with the dcterms:references statement. |
|
| 66 | + $sparql .= wl_get_sparql_post_references( $post->ID ); |
|
| 67 | 67 | |
| 68 | - // create the query: |
|
| 69 | - // - remove existing references to entities. |
|
| 70 | - // - set the new post information (including references). |
|
| 71 | - $query = rl_sparql_prefixes() . <<<EOF |
|
| 68 | + // create the query: |
|
| 69 | + // - remove existing references to entities. |
|
| 70 | + // - set the new post information (including references). |
|
| 71 | + $query = rl_sparql_prefixes() . <<<EOF |
|
| 72 | 72 | DELETE { <$uri> dct:references ?o . } |
| 73 | 73 | WHERE { <$uri> dct:references ?o . }; |
| 74 | 74 | DELETE { <$uri> schema:url ?o . } |
@@ -90,8 +90,8 @@ discard block |
||
| 90 | 90 | INSERT DATA { $sparql }; |
| 91 | 91 | EOF; |
| 92 | 92 | |
| 93 | - // execute the query. |
|
| 94 | - rl_execute_sparql_update_query( $query ); |
|
| 93 | + // execute the query. |
|
| 94 | + rl_execute_sparql_update_query( $query ); |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | /** |
@@ -101,143 +101,143 @@ discard block |
||
| 101 | 101 | */ |
| 102 | 102 | function wl_push_entity_post_to_redlink( $entity_post ) { |
| 103 | 103 | |
| 104 | - // Only handle published entities. |
|
| 105 | - if ( 'entity' !== $entity_post->post_type or 'publish' !== $entity_post->post_status ) { |
|
| 104 | + // Only handle published entities. |
|
| 105 | + if ( 'entity' !== $entity_post->post_type or 'publish' !== $entity_post->post_status ) { |
|
| 106 | 106 | |
| 107 | - wl_write_log( "wl_push_entity_post_to_redlink : not an entity or not published [ post type :: $entity_post->post_type ][ post status :: $entity_post->post_status ]" ); |
|
| 107 | + wl_write_log( "wl_push_entity_post_to_redlink : not an entity or not published [ post type :: $entity_post->post_type ][ post status :: $entity_post->post_status ]" ); |
|
| 108 | 108 | |
| 109 | - return; |
|
| 110 | - } |
|
| 109 | + return; |
|
| 110 | + } |
|
| 111 | 111 | |
| 112 | - // get the entity URI and the SPARQL escaped version. |
|
| 113 | - $uri = wl_get_entity_uri( $entity_post->ID ); |
|
| 114 | - $uri_e = wl_sparql_escape_uri( $uri ); |
|
| 112 | + // get the entity URI and the SPARQL escaped version. |
|
| 113 | + $uri = wl_get_entity_uri( $entity_post->ID ); |
|
| 114 | + $uri_e = wl_sparql_escape_uri( $uri ); |
|
| 115 | 115 | |
| 116 | - // If the URI ends with a trailing slash, then we have a problem. |
|
| 117 | - if ( '/' === substr( $uri, - 1, 1 ) ) { |
|
| 116 | + // If the URI ends with a trailing slash, then we have a problem. |
|
| 117 | + if ( '/' === substr( $uri, - 1, 1 ) ) { |
|
| 118 | 118 | |
| 119 | - wl_write_log( "wl_push_entity_post_to_redlink : the URI is invalid [ post ID :: $entity_post->ID ][ URI :: $uri ]" ); |
|
| 119 | + wl_write_log( "wl_push_entity_post_to_redlink : the URI is invalid [ post ID :: $entity_post->ID ][ URI :: $uri ]" ); |
|
| 120 | 120 | |
| 121 | - return; |
|
| 122 | - } |
|
| 121 | + return; |
|
| 122 | + } |
|
| 123 | 123 | |
| 124 | - // Get the site language in order to define the literals language. |
|
| 125 | - $site_language = wl_configuration_get_site_language(); |
|
| 124 | + // Get the site language in order to define the literals language. |
|
| 125 | + $site_language = wl_configuration_get_site_language(); |
|
| 126 | 126 | |
| 127 | - // get the title and content as label and description. |
|
| 128 | - $label = wordlift_esc_sparql( $entity_post->post_title ); |
|
| 129 | - $descr = wordlift_esc_sparql( wp_strip_all_tags( strip_shortcodes( $entity_post->post_content ) ) ); |
|
| 130 | - $permalink = wl_sparql_escape_uri( get_permalink( $entity_post->ID ) ); |
|
| 127 | + // get the title and content as label and description. |
|
| 128 | + $label = wordlift_esc_sparql( $entity_post->post_title ); |
|
| 129 | + $descr = wordlift_esc_sparql( wp_strip_all_tags( strip_shortcodes( $entity_post->post_content ) ) ); |
|
| 130 | + $permalink = wl_sparql_escape_uri( get_permalink( $entity_post->ID ) ); |
|
| 131 | 131 | |
| 132 | - // wl_write_log( "wl_push_entity_post_to_redlink [ entity post id :: $entity_post->ID ][ uri :: $uri ][ label :: $label ]" ); |
|
| 132 | + // wl_write_log( "wl_push_entity_post_to_redlink [ entity post id :: $entity_post->ID ][ uri :: $uri ][ label :: $label ]" ); |
|
| 133 | 133 | |
| 134 | - // create a new empty statement. |
|
| 135 | - $delete_stmt = ''; |
|
| 136 | - $sparql = ''; |
|
| 134 | + // create a new empty statement. |
|
| 135 | + $delete_stmt = ''; |
|
| 136 | + $sparql = ''; |
|
| 137 | 137 | |
| 138 | - // delete on RL all statements regarding properties set from WL (necessary when changing entity type) |
|
| 139 | - $all_custom_fields = wl_entity_taxonomy_get_custom_fields(); |
|
| 140 | - $predicates_to_be_deleted = array(); |
|
| 141 | - foreach ( $all_custom_fields as $type => $fields ) { |
|
| 142 | - foreach ( $fields as $cf ) { |
|
| 143 | - $predicate = $cf['predicate']; |
|
| 144 | - if ( ! in_array( $predicate, $predicates_to_be_deleted ) ) { |
|
| 145 | - $predicates_to_be_deleted[] = $predicate; |
|
| 146 | - $delete_stmt .= "DELETE { <$uri_e> <$predicate> ?o } WHERE { <$uri_e> <$predicate> ?o };\n"; |
|
| 147 | - } |
|
| 148 | - } |
|
| 149 | - } |
|
| 138 | + // delete on RL all statements regarding properties set from WL (necessary when changing entity type) |
|
| 139 | + $all_custom_fields = wl_entity_taxonomy_get_custom_fields(); |
|
| 140 | + $predicates_to_be_deleted = array(); |
|
| 141 | + foreach ( $all_custom_fields as $type => $fields ) { |
|
| 142 | + foreach ( $fields as $cf ) { |
|
| 143 | + $predicate = $cf['predicate']; |
|
| 144 | + if ( ! in_array( $predicate, $predicates_to_be_deleted ) ) { |
|
| 145 | + $predicates_to_be_deleted[] = $predicate; |
|
| 146 | + $delete_stmt .= "DELETE { <$uri_e> <$predicate> ?o } WHERE { <$uri_e> <$predicate> ?o };\n"; |
|
| 147 | + } |
|
| 148 | + } |
|
| 149 | + } |
|
| 150 | 150 | |
| 151 | - // set the same as. |
|
| 152 | - $same_as = wl_schema_get_value( $entity_post->ID, 'sameAs' ); |
|
| 153 | - foreach ( $same_as as $same_as_uri ) { |
|
| 154 | - $same_as_uri_esc = wl_sparql_escape_uri( $same_as_uri ); |
|
| 155 | - $sparql .= "<$uri_e> owl:sameAs <$same_as_uri_esc> . \n"; |
|
| 156 | - } |
|
| 151 | + // set the same as. |
|
| 152 | + $same_as = wl_schema_get_value( $entity_post->ID, 'sameAs' ); |
|
| 153 | + foreach ( $same_as as $same_as_uri ) { |
|
| 154 | + $same_as_uri_esc = wl_sparql_escape_uri( $same_as_uri ); |
|
| 155 | + $sparql .= "<$uri_e> owl:sameAs <$same_as_uri_esc> . \n"; |
|
| 156 | + } |
|
| 157 | 157 | |
| 158 | - // set the label |
|
| 159 | - $sparql .= "<$uri_e> rdfs:label \"$label\"@$site_language . \n"; |
|
| 160 | - // set the URL |
|
| 161 | - $sparql .= "<$uri_e> schema:url <$permalink> . \n"; |
|
| 158 | + // set the label |
|
| 159 | + $sparql .= "<$uri_e> rdfs:label \"$label\"@$site_language . \n"; |
|
| 160 | + // set the URL |
|
| 161 | + $sparql .= "<$uri_e> schema:url <$permalink> . \n"; |
|
| 162 | 162 | |
| 163 | - // set the description. |
|
| 164 | - if ( ! empty( $descr ) ) { |
|
| 165 | - $sparql .= "<$uri_e> schema:description \"$descr\"@$site_language . \n"; |
|
| 166 | - } |
|
| 163 | + // set the description. |
|
| 164 | + if ( ! empty( $descr ) ) { |
|
| 165 | + $sparql .= "<$uri_e> schema:description \"$descr\"@$site_language . \n"; |
|
| 166 | + } |
|
| 167 | 167 | |
| 168 | - $main_type = wl_entity_type_taxonomy_get_type( $entity_post->ID ); |
|
| 168 | + $main_type = wl_entity_type_taxonomy_get_type( $entity_post->ID ); |
|
| 169 | 169 | |
| 170 | - if ( null != $main_type ) { |
|
| 171 | - $main_type_uri = wl_sparql_escape_uri( $main_type['uri'] ); |
|
| 172 | - $sparql .= " <$uri_e> a <$main_type_uri> . \n"; |
|
| 170 | + if ( null != $main_type ) { |
|
| 171 | + $main_type_uri = wl_sparql_escape_uri( $main_type['uri'] ); |
|
| 172 | + $sparql .= " <$uri_e> a <$main_type_uri> . \n"; |
|
| 173 | 173 | |
| 174 | - // The type define custom fields that hold additional data about the entity. |
|
| 175 | - // For example Events may have start/end dates, Places may have coordinates. |
|
| 176 | - // The value in the export fields must be rewritten as triple predicates, this |
|
| 177 | - // is what we're going to do here. |
|
| 174 | + // The type define custom fields that hold additional data about the entity. |
|
| 175 | + // For example Events may have start/end dates, Places may have coordinates. |
|
| 176 | + // The value in the export fields must be rewritten as triple predicates, this |
|
| 177 | + // is what we're going to do here. |
|
| 178 | 178 | |
| 179 | 179 | // wl_write_log( 'wl_push_entity_post_to_redlink : checking if entity has export fields [ type :: ' . var_export( $main_type, true ) . ' ]' ); |
| 180 | 180 | |
| 181 | - if ( isset( $main_type['custom_fields'] ) ) { |
|
| 182 | - foreach ( $main_type['custom_fields'] as $field => $settings ) { |
|
| 183 | - |
|
| 184 | - // wl_write_log( "wl_push_entity_post_to_redlink : entity has export fields" ); |
|
| 185 | - |
|
| 186 | - $predicate = wordlift_esc_sparql( $settings['predicate'] ); |
|
| 187 | - if ( ! isset( $settings['export_type'] ) || empty( $settings['export_type'] ) ) { |
|
| 188 | - $type = null; |
|
| 189 | - } else { |
|
| 190 | - $type = $settings['export_type']; |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - foreach ( get_post_meta( $entity_post->ID, $field ) as $value ) { |
|
| 194 | - $sparql .= " <$uri_e> <$predicate> "; |
|
| 195 | - |
|
| 196 | - if ( ! is_null( $type ) && ( substr( $type, 0, 4 ) == 'http' ) ) { |
|
| 197 | - // Type is defined by a raw uri (es. http://schema.org/PostalAddress) |
|
| 198 | - |
|
| 199 | - // Extract uri if the value is numeric |
|
| 200 | - if ( is_numeric( $value ) ) { |
|
| 201 | - $value = wl_get_entity_uri( $value ); |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - $sparql .= '<' . wl_sparql_escape_uri( $value ) . '>'; |
|
| 205 | - } else { |
|
| 206 | - // Type is defined in another way (es. xsd:double) |
|
| 207 | - $sparql .= '"' . wordlift_esc_sparql( $value ) . '"^^' . wordlift_esc_sparql( $type ); |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - $sparql .= " . \n"; |
|
| 211 | - } |
|
| 212 | - } |
|
| 213 | - } |
|
| 214 | - } |
|
| 215 | - |
|
| 216 | - // Get the entity types. |
|
| 217 | - $type_uris = wl_get_entity_rdf_types( $entity_post->ID ); |
|
| 218 | - |
|
| 219 | - // Support type are only schema.org ones: it could be null |
|
| 220 | - foreach ( $type_uris as $type_uri ) { |
|
| 221 | - $type_uri = wl_sparql_escape_uri( $type_uri ); |
|
| 222 | - $sparql .= "<$uri_e> a <$type_uri> . \n"; |
|
| 223 | - } |
|
| 224 | - |
|
| 225 | - // get related entities. |
|
| 226 | - $related_entities_ids = wl_core_get_related_entity_ids( $entity_post->ID ); |
|
| 227 | - |
|
| 228 | - if ( is_array( $related_entities_ids ) ) { |
|
| 229 | - foreach ( $related_entities_ids as $entity_post_id ) { |
|
| 230 | - $related_entity_uri = wl_sparql_escape_uri( wl_get_entity_uri( $entity_post_id ) ); |
|
| 231 | - // create a two-way relationship. |
|
| 232 | - $sparql .= " <$uri_e> dct:relation <$related_entity_uri> . \n"; |
|
| 233 | - $sparql .= " <$related_entity_uri> dct:relation <$uri_e> . \n"; |
|
| 234 | - } |
|
| 235 | - } |
|
| 236 | - |
|
| 237 | - // Add SPARQL stmts to write the schema:image. |
|
| 238 | - $sparql .= wl_get_sparql_images( $uri, $entity_post->ID ); |
|
| 239 | - |
|
| 240 | - $query = rl_sparql_prefixes() . <<<EOF |
|
| 181 | + if ( isset( $main_type['custom_fields'] ) ) { |
|
| 182 | + foreach ( $main_type['custom_fields'] as $field => $settings ) { |
|
| 183 | + |
|
| 184 | + // wl_write_log( "wl_push_entity_post_to_redlink : entity has export fields" ); |
|
| 185 | + |
|
| 186 | + $predicate = wordlift_esc_sparql( $settings['predicate'] ); |
|
| 187 | + if ( ! isset( $settings['export_type'] ) || empty( $settings['export_type'] ) ) { |
|
| 188 | + $type = null; |
|
| 189 | + } else { |
|
| 190 | + $type = $settings['export_type']; |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + foreach ( get_post_meta( $entity_post->ID, $field ) as $value ) { |
|
| 194 | + $sparql .= " <$uri_e> <$predicate> "; |
|
| 195 | + |
|
| 196 | + if ( ! is_null( $type ) && ( substr( $type, 0, 4 ) == 'http' ) ) { |
|
| 197 | + // Type is defined by a raw uri (es. http://schema.org/PostalAddress) |
|
| 198 | + |
|
| 199 | + // Extract uri if the value is numeric |
|
| 200 | + if ( is_numeric( $value ) ) { |
|
| 201 | + $value = wl_get_entity_uri( $value ); |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + $sparql .= '<' . wl_sparql_escape_uri( $value ) . '>'; |
|
| 205 | + } else { |
|
| 206 | + // Type is defined in another way (es. xsd:double) |
|
| 207 | + $sparql .= '"' . wordlift_esc_sparql( $value ) . '"^^' . wordlift_esc_sparql( $type ); |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + $sparql .= " . \n"; |
|
| 211 | + } |
|
| 212 | + } |
|
| 213 | + } |
|
| 214 | + } |
|
| 215 | + |
|
| 216 | + // Get the entity types. |
|
| 217 | + $type_uris = wl_get_entity_rdf_types( $entity_post->ID ); |
|
| 218 | + |
|
| 219 | + // Support type are only schema.org ones: it could be null |
|
| 220 | + foreach ( $type_uris as $type_uri ) { |
|
| 221 | + $type_uri = wl_sparql_escape_uri( $type_uri ); |
|
| 222 | + $sparql .= "<$uri_e> a <$type_uri> . \n"; |
|
| 223 | + } |
|
| 224 | + |
|
| 225 | + // get related entities. |
|
| 226 | + $related_entities_ids = wl_core_get_related_entity_ids( $entity_post->ID ); |
|
| 227 | + |
|
| 228 | + if ( is_array( $related_entities_ids ) ) { |
|
| 229 | + foreach ( $related_entities_ids as $entity_post_id ) { |
|
| 230 | + $related_entity_uri = wl_sparql_escape_uri( wl_get_entity_uri( $entity_post_id ) ); |
|
| 231 | + // create a two-way relationship. |
|
| 232 | + $sparql .= " <$uri_e> dct:relation <$related_entity_uri> . \n"; |
|
| 233 | + $sparql .= " <$related_entity_uri> dct:relation <$uri_e> . \n"; |
|
| 234 | + } |
|
| 235 | + } |
|
| 236 | + |
|
| 237 | + // Add SPARQL stmts to write the schema:image. |
|
| 238 | + $sparql .= wl_get_sparql_images( $uri, $entity_post->ID ); |
|
| 239 | + |
|
| 240 | + $query = rl_sparql_prefixes() . <<<EOF |
|
| 241 | 241 | $delete_stmt |
| 242 | 242 | DELETE { <$uri_e> rdfs:label ?o } WHERE { <$uri_e> rdfs:label ?o }; |
| 243 | 243 | DELETE { <$uri_e> owl:sameAs ?o . } WHERE { <$uri_e> owl:sameAs ?o . }; |
@@ -249,7 +249,7 @@ discard block |
||
| 249 | 249 | INSERT DATA { $sparql }; |
| 250 | 250 | EOF; |
| 251 | 251 | |
| 252 | - rl_execute_sparql_update_query( $query ); |
|
| 252 | + rl_execute_sparql_update_query( $query ); |
|
| 253 | 253 | } |
| 254 | 254 | |
| 255 | 255 | /** |
@@ -261,20 +261,20 @@ discard block |
||
| 261 | 261 | */ |
| 262 | 262 | function wl_get_sparql_post_references( $post_id ) { |
| 263 | 263 | |
| 264 | - // Get the post URI. |
|
| 265 | - $post_uri = wordlift_esc_sparql( wl_get_entity_uri( $post_id ) ); |
|
| 264 | + // Get the post URI. |
|
| 265 | + $post_uri = wordlift_esc_sparql( wl_get_entity_uri( $post_id ) ); |
|
| 266 | 266 | |
| 267 | - // Get the related entities IDs. |
|
| 268 | - $related = wl_core_get_related_entity_ids( $post_id ); |
|
| 267 | + // Get the related entities IDs. |
|
| 268 | + $related = wl_core_get_related_entity_ids( $post_id ); |
|
| 269 | 269 | |
| 270 | - // Build the SPARQL fragment. |
|
| 271 | - $sparql = ''; |
|
| 272 | - foreach ( $related as $id ) { |
|
| 273 | - $uri = wordlift_esc_sparql( wl_get_entity_uri( $id ) ); |
|
| 274 | - $sparql .= "<$post_uri> dct:references <$uri> . "; |
|
| 275 | - } |
|
| 270 | + // Build the SPARQL fragment. |
|
| 271 | + $sparql = ''; |
|
| 272 | + foreach ( $related as $id ) { |
|
| 273 | + $uri = wordlift_esc_sparql( wl_get_entity_uri( $id ) ); |
|
| 274 | + $sparql .= "<$post_uri> dct:references <$uri> . "; |
|
| 275 | + } |
|
| 276 | 276 | |
| 277 | - return $sparql; |
|
| 277 | + return $sparql; |
|
| 278 | 278 | } |
| 279 | 279 | |
| 280 | 280 | /** |
@@ -284,12 +284,12 @@ discard block |
||
| 284 | 284 | */ |
| 285 | 285 | function rl_sparql_prefixes() { |
| 286 | 286 | |
| 287 | - $prefixes = ''; |
|
| 288 | - foreach ( wl_prefixes() as $prefix => $uri ) { |
|
| 289 | - $prefixes .= "PREFIX $prefix: <$uri>\n"; |
|
| 290 | - } |
|
| 287 | + $prefixes = ''; |
|
| 288 | + foreach ( wl_prefixes() as $prefix => $uri ) { |
|
| 289 | + $prefixes .= "PREFIX $prefix: <$uri>\n"; |
|
| 290 | + } |
|
| 291 | 291 | |
| 292 | - return $prefixes; |
|
| 292 | + return $prefixes; |
|
| 293 | 293 | } |
| 294 | 294 | |
| 295 | 295 | /** |
@@ -300,26 +300,26 @@ discard block |
||
| 300 | 300 | * @return string The escaped string. |
| 301 | 301 | */ |
| 302 | 302 | function wordlift_esc_sparql( $string ) { |
| 303 | - // see http://www.w3.org/TR/rdf-sparql-query/ |
|
| 304 | - // '\t' U+0009 (tab) |
|
| 305 | - // '\n' U+000A (line feed) |
|
| 306 | - // '\r' U+000D (carriage return) |
|
| 307 | - // '\b' U+0008 (backspace) |
|
| 308 | - // '\f' U+000C (form feed) |
|
| 309 | - // '\"' U+0022 (quotation mark, double quote mark) |
|
| 310 | - // "\'" U+0027 (apostrophe-quote, single quote mark) |
|
| 311 | - // '\\' U+005C (backslash) |
|
| 312 | - |
|
| 313 | - $string = str_replace( '\\', '\\\\', $string ); |
|
| 314 | - $string = str_replace( '\'', '\\\'', $string ); |
|
| 315 | - $string = str_replace( '"', '\\"', $string ); |
|
| 316 | - $string = str_replace( "\f", '\\f', $string ); |
|
| 317 | - $string = str_replace( "\b", '\\b', $string ); |
|
| 318 | - $string = str_replace( "\r", '\\r', $string ); |
|
| 319 | - $string = str_replace( "\n", '\\n', $string ); |
|
| 320 | - $string = str_replace( "\t", '\\t', $string ); |
|
| 321 | - |
|
| 322 | - return $string; |
|
| 303 | + // see http://www.w3.org/TR/rdf-sparql-query/ |
|
| 304 | + // '\t' U+0009 (tab) |
|
| 305 | + // '\n' U+000A (line feed) |
|
| 306 | + // '\r' U+000D (carriage return) |
|
| 307 | + // '\b' U+0008 (backspace) |
|
| 308 | + // '\f' U+000C (form feed) |
|
| 309 | + // '\"' U+0022 (quotation mark, double quote mark) |
|
| 310 | + // "\'" U+0027 (apostrophe-quote, single quote mark) |
|
| 311 | + // '\\' U+005C (backslash) |
|
| 312 | + |
|
| 313 | + $string = str_replace( '\\', '\\\\', $string ); |
|
| 314 | + $string = str_replace( '\'', '\\\'', $string ); |
|
| 315 | + $string = str_replace( '"', '\\"', $string ); |
|
| 316 | + $string = str_replace( "\f", '\\f', $string ); |
|
| 317 | + $string = str_replace( "\b", '\\b', $string ); |
|
| 318 | + $string = str_replace( "\r", '\\r', $string ); |
|
| 319 | + $string = str_replace( "\n", '\\n', $string ); |
|
| 320 | + $string = str_replace( "\t", '\\t', $string ); |
|
| 321 | + |
|
| 322 | + return $string; |
|
| 323 | 323 | } |
| 324 | 324 | |
| 325 | 325 | /** |
@@ -333,13 +333,13 @@ discard block |
||
| 333 | 333 | */ |
| 334 | 334 | function wl_sparql_escape_uri( $string ) { |
| 335 | 335 | |
| 336 | - // Should we validate the IRI? |
|
| 337 | - // http://www.w3.org/TR/sparql11-query/#QSynIRI |
|
| 336 | + // Should we validate the IRI? |
|
| 337 | + // http://www.w3.org/TR/sparql11-query/#QSynIRI |
|
| 338 | 338 | |
| 339 | - $string = str_replace( '<', '\<', $string ); |
|
| 340 | - $string = str_replace( '>', '\>', $string ); |
|
| 339 | + $string = str_replace( '<', '\<', $string ); |
|
| 340 | + $string = str_replace( '>', '\>', $string ); |
|
| 341 | 341 | |
| 342 | - return $string; |
|
| 342 | + return $string; |
|
| 343 | 343 | |
| 344 | 344 | } |
| 345 | 345 | |
@@ -348,35 +348,35 @@ discard block |
||
| 348 | 348 | */ |
| 349 | 349 | function wordlift_reindex_triple_store() { |
| 350 | 350 | |
| 351 | - // Get the reindex URL. |
|
| 352 | - $url = wl_configuration_get_dataset_index_url(); |
|
| 351 | + // Get the reindex URL. |
|
| 352 | + $url = wl_configuration_get_dataset_index_url(); |
|
| 353 | 353 | |
| 354 | - // Post the request. |
|
| 355 | - // wl_write_log( "wordlift_reindex_triple_store" ); |
|
| 354 | + // Post the request. |
|
| 355 | + // wl_write_log( "wordlift_reindex_triple_store" ); |
|
| 356 | 356 | |
| 357 | - // Prepare the request. |
|
| 358 | - $args = array_merge_recursive( unserialize( WL_REDLINK_API_HTTP_OPTIONS ), array( |
|
| 359 | - 'method' => 'POST', |
|
| 360 | - 'headers' => array() |
|
| 361 | - ) ); |
|
| 357 | + // Prepare the request. |
|
| 358 | + $args = array_merge_recursive( unserialize( WL_REDLINK_API_HTTP_OPTIONS ), array( |
|
| 359 | + 'method' => 'POST', |
|
| 360 | + 'headers' => array() |
|
| 361 | + ) ); |
|
| 362 | 362 | |
| 363 | - $response = wp_remote_request( $url, $args ); |
|
| 363 | + $response = wp_remote_request( $url, $args ); |
|
| 364 | 364 | |
| 365 | - // If an error has been raised, return the error. |
|
| 366 | - if ( is_wp_error( $response ) || 200 !== $response['response']['code'] ) { |
|
| 365 | + // If an error has been raised, return the error. |
|
| 366 | + if ( is_wp_error( $response ) || 200 !== $response['response']['code'] ) { |
|
| 367 | 367 | |
| 368 | - $body = ( is_wp_error( $response ) ? $response->get_error_message() : $response['body'] ); |
|
| 368 | + $body = ( is_wp_error( $response ) ? $response->get_error_message() : $response['body'] ); |
|
| 369 | 369 | |
| 370 | - wl_write_log( "wordlift_reindex_triple_store : error [ url :: $url ][ args :: " ); |
|
| 371 | - wl_write_log( "\n" . var_export( $args, true ) ); |
|
| 372 | - wl_write_log( "[ response :: " ); |
|
| 373 | - wl_write_log( "\n" . var_export( $response, true ) ); |
|
| 374 | - wl_write_log( "][ body :: " ); |
|
| 375 | - wl_write_log( "\n" . $body ); |
|
| 376 | - wl_write_log( "]" ); |
|
| 370 | + wl_write_log( "wordlift_reindex_triple_store : error [ url :: $url ][ args :: " ); |
|
| 371 | + wl_write_log( "\n" . var_export( $args, true ) ); |
|
| 372 | + wl_write_log( "[ response :: " ); |
|
| 373 | + wl_write_log( "\n" . var_export( $response, true ) ); |
|
| 374 | + wl_write_log( "][ body :: " ); |
|
| 375 | + wl_write_log( "\n" . $body ); |
|
| 376 | + wl_write_log( "]" ); |
|
| 377 | 377 | |
| 378 | - return false; |
|
| 379 | - } |
|
| 378 | + return false; |
|
| 379 | + } |
|
| 380 | 380 | |
| 381 | - return true; |
|
| 381 | + return true; |
|
| 382 | 382 | } |
| 383 | 383 | \ No newline at end of file |
@@ -5,23 +5,23 @@ discard block |
||
| 5 | 5 | * |
| 6 | 6 | * @param object $post A post instance. |
| 7 | 7 | */ |
| 8 | -function wl_push_post_to_redlink( $post ) { |
|
| 8 | +function wl_push_post_to_redlink($post) { |
|
| 9 | 9 | |
| 10 | 10 | |
| 11 | 11 | // Only handle published posts. |
| 12 | - if ( 'post' !== $post->post_type or 'publish' !== $post->post_status ) { |
|
| 13 | - wl_write_log( "wl_push_post_to_redlink : not a post or not published [ post type :: $post->post_type ][ post status :: $post->post_status ]" ); |
|
| 12 | + if ('post' !== $post->post_type or 'publish' !== $post->post_status) { |
|
| 13 | + wl_write_log("wl_push_post_to_redlink : not a post or not published [ post type :: $post->post_type ][ post status :: $post->post_status ]"); |
|
| 14 | 14 | |
| 15 | 15 | return; |
| 16 | 16 | } |
| 17 | 17 | |
| 18 | 18 | // Get the post URI. |
| 19 | - $uri = wl_sparql_escape_uri( wl_get_entity_uri( $post->ID ) ); |
|
| 19 | + $uri = wl_sparql_escape_uri(wl_get_entity_uri($post->ID)); |
|
| 20 | 20 | |
| 21 | 21 | // If the URI ends with a trailing slash, then we have a problem. |
| 22 | - if ( '/' === substr( $uri, - 1, 1 ) ) { |
|
| 22 | + if ('/' === substr($uri, - 1, 1)) { |
|
| 23 | 23 | |
| 24 | - wl_write_log( "wl_push_post_to_redlink : the URI is invalid [ post ID :: $post->ID ][ URI :: $uri ]" ); |
|
| 24 | + wl_write_log("wl_push_post_to_redlink : the URI is invalid [ post ID :: $post->ID ][ URI :: $uri ]"); |
|
| 25 | 25 | |
| 26 | 26 | return; |
| 27 | 27 | } |
@@ -32,20 +32,20 @@ discard block |
||
| 32 | 32 | $site_language = wl_configuration_get_site_language(); |
| 33 | 33 | |
| 34 | 34 | // save the author and get the author URI. |
| 35 | - $author_uri = wl_sparql_escape_uri( Wordlift_User_Service::get_instance()->get_uri( $post->post_author ) ); |
|
| 35 | + $author_uri = wl_sparql_escape_uri(Wordlift_User_Service::get_instance()->get_uri($post->post_author)); |
|
| 36 | 36 | |
| 37 | 37 | // Get other post properties. |
| 38 | - $date_published = wl_get_sparql_time( get_the_time( 'c', $post ) ); |
|
| 39 | - $date_modified = wl_get_sparql_time( wl_get_post_modified_time( $post ) ); |
|
| 40 | - $title = wordlift_esc_sparql( $post->post_title ); |
|
| 41 | - $permalink = wl_sparql_escape_uri( get_permalink( $post->ID ) ); |
|
| 38 | + $date_published = wl_get_sparql_time(get_the_time('c', $post)); |
|
| 39 | + $date_modified = wl_get_sparql_time(wl_get_post_modified_time($post)); |
|
| 40 | + $title = wordlift_esc_sparql($post->post_title); |
|
| 41 | + $permalink = wl_sparql_escape_uri(get_permalink($post->ID)); |
|
| 42 | 42 | $user_comments_count = $post->comment_count; |
| 43 | 43 | |
| 44 | - wl_write_log( "wl_push_post_to_redlink [ post_id :: $post->ID ][ type :: $post->post_type ][ slug :: $post->post_name ][ title :: $post->post_title ][ date modified :: $date_modified ][ date published :: $date_published ]" ); |
|
| 44 | + wl_write_log("wl_push_post_to_redlink [ post_id :: $post->ID ][ type :: $post->post_type ][ slug :: $post->post_name ][ title :: $post->post_title ][ date modified :: $date_modified ][ date published :: $date_published ]"); |
|
| 45 | 45 | |
| 46 | 46 | // create the SPARQL query. |
| 47 | 47 | $sparql = ''; |
| 48 | - if ( ! empty( $title ) ) { |
|
| 48 | + if ( ! empty($title)) { |
|
| 49 | 49 | $sparql .= "<$uri> rdfs:label '$title'@$site_language . \n"; |
| 50 | 50 | } |
| 51 | 51 | |
@@ -53,22 +53,22 @@ discard block |
||
| 53 | 53 | $sparql .= "<$uri> schema:url <$permalink> . \n"; |
| 54 | 54 | $sparql .= "<$uri> schema:datePublished $date_published . \n"; |
| 55 | 55 | $sparql .= "<$uri> schema:dateModified $date_modified . \n"; |
| 56 | - if ( ! empty( $author_uri ) ) { |
|
| 56 | + if ( ! empty($author_uri)) { |
|
| 57 | 57 | $sparql .= "<$uri> schema:author <$author_uri> . \n"; |
| 58 | 58 | } |
| 59 | 59 | $sparql .= "<$uri> schema:interactionCount 'UserComments:$user_comments_count' . \n"; |
| 60 | 60 | |
| 61 | 61 | |
| 62 | 62 | // Add SPARQL stmts to write the schema:image. |
| 63 | - $sparql .= wl_get_sparql_images( $uri, $post->ID ); |
|
| 63 | + $sparql .= wl_get_sparql_images($uri, $post->ID); |
|
| 64 | 64 | |
| 65 | 65 | // Get the SPARQL fragment with the dcterms:references statement. |
| 66 | - $sparql .= wl_get_sparql_post_references( $post->ID ); |
|
| 66 | + $sparql .= wl_get_sparql_post_references($post->ID); |
|
| 67 | 67 | |
| 68 | 68 | // create the query: |
| 69 | 69 | // - remove existing references to entities. |
| 70 | 70 | // - set the new post information (including references). |
| 71 | - $query = rl_sparql_prefixes() . <<<EOF |
|
| 71 | + $query = rl_sparql_prefixes().<<<EOF |
|
| 72 | 72 | DELETE { <$uri> dct:references ?o . } |
| 73 | 73 | WHERE { <$uri> dct:references ?o . }; |
| 74 | 74 | DELETE { <$uri> schema:url ?o . } |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | EOF; |
| 92 | 92 | |
| 93 | 93 | // execute the query. |
| 94 | - rl_execute_sparql_update_query( $query ); |
|
| 94 | + rl_execute_sparql_update_query($query); |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | /** |
@@ -99,24 +99,24 @@ discard block |
||
| 99 | 99 | * |
| 100 | 100 | * @param object $entity_post An entity post instance. |
| 101 | 101 | */ |
| 102 | -function wl_push_entity_post_to_redlink( $entity_post ) { |
|
| 102 | +function wl_push_entity_post_to_redlink($entity_post) { |
|
| 103 | 103 | |
| 104 | 104 | // Only handle published entities. |
| 105 | - if ( 'entity' !== $entity_post->post_type or 'publish' !== $entity_post->post_status ) { |
|
| 105 | + if ('entity' !== $entity_post->post_type or 'publish' !== $entity_post->post_status) { |
|
| 106 | 106 | |
| 107 | - wl_write_log( "wl_push_entity_post_to_redlink : not an entity or not published [ post type :: $entity_post->post_type ][ post status :: $entity_post->post_status ]" ); |
|
| 107 | + wl_write_log("wl_push_entity_post_to_redlink : not an entity or not published [ post type :: $entity_post->post_type ][ post status :: $entity_post->post_status ]"); |
|
| 108 | 108 | |
| 109 | 109 | return; |
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | // get the entity URI and the SPARQL escaped version. |
| 113 | - $uri = wl_get_entity_uri( $entity_post->ID ); |
|
| 114 | - $uri_e = wl_sparql_escape_uri( $uri ); |
|
| 113 | + $uri = wl_get_entity_uri($entity_post->ID); |
|
| 114 | + $uri_e = wl_sparql_escape_uri($uri); |
|
| 115 | 115 | |
| 116 | 116 | // If the URI ends with a trailing slash, then we have a problem. |
| 117 | - if ( '/' === substr( $uri, - 1, 1 ) ) { |
|
| 117 | + if ('/' === substr($uri, - 1, 1)) { |
|
| 118 | 118 | |
| 119 | - wl_write_log( "wl_push_entity_post_to_redlink : the URI is invalid [ post ID :: $entity_post->ID ][ URI :: $uri ]" ); |
|
| 119 | + wl_write_log("wl_push_entity_post_to_redlink : the URI is invalid [ post ID :: $entity_post->ID ][ URI :: $uri ]"); |
|
| 120 | 120 | |
| 121 | 121 | return; |
| 122 | 122 | } |
@@ -125,9 +125,9 @@ discard block |
||
| 125 | 125 | $site_language = wl_configuration_get_site_language(); |
| 126 | 126 | |
| 127 | 127 | // get the title and content as label and description. |
| 128 | - $label = wordlift_esc_sparql( $entity_post->post_title ); |
|
| 129 | - $descr = wordlift_esc_sparql( wp_strip_all_tags( strip_shortcodes( $entity_post->post_content ) ) ); |
|
| 130 | - $permalink = wl_sparql_escape_uri( get_permalink( $entity_post->ID ) ); |
|
| 128 | + $label = wordlift_esc_sparql($entity_post->post_title); |
|
| 129 | + $descr = wordlift_esc_sparql(wp_strip_all_tags(strip_shortcodes($entity_post->post_content))); |
|
| 130 | + $permalink = wl_sparql_escape_uri(get_permalink($entity_post->ID)); |
|
| 131 | 131 | |
| 132 | 132 | // wl_write_log( "wl_push_entity_post_to_redlink [ entity post id :: $entity_post->ID ][ uri :: $uri ][ label :: $label ]" ); |
| 133 | 133 | |
@@ -138,10 +138,10 @@ discard block |
||
| 138 | 138 | // delete on RL all statements regarding properties set from WL (necessary when changing entity type) |
| 139 | 139 | $all_custom_fields = wl_entity_taxonomy_get_custom_fields(); |
| 140 | 140 | $predicates_to_be_deleted = array(); |
| 141 | - foreach ( $all_custom_fields as $type => $fields ) { |
|
| 142 | - foreach ( $fields as $cf ) { |
|
| 141 | + foreach ($all_custom_fields as $type => $fields) { |
|
| 142 | + foreach ($fields as $cf) { |
|
| 143 | 143 | $predicate = $cf['predicate']; |
| 144 | - if ( ! in_array( $predicate, $predicates_to_be_deleted ) ) { |
|
| 144 | + if ( ! in_array($predicate, $predicates_to_be_deleted)) { |
|
| 145 | 145 | $predicates_to_be_deleted[] = $predicate; |
| 146 | 146 | $delete_stmt .= "DELETE { <$uri_e> <$predicate> ?o } WHERE { <$uri_e> <$predicate> ?o };\n"; |
| 147 | 147 | } |
@@ -149,9 +149,9 @@ discard block |
||
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | // set the same as. |
| 152 | - $same_as = wl_schema_get_value( $entity_post->ID, 'sameAs' ); |
|
| 153 | - foreach ( $same_as as $same_as_uri ) { |
|
| 154 | - $same_as_uri_esc = wl_sparql_escape_uri( $same_as_uri ); |
|
| 152 | + $same_as = wl_schema_get_value($entity_post->ID, 'sameAs'); |
|
| 153 | + foreach ($same_as as $same_as_uri) { |
|
| 154 | + $same_as_uri_esc = wl_sparql_escape_uri($same_as_uri); |
|
| 155 | 155 | $sparql .= "<$uri_e> owl:sameAs <$same_as_uri_esc> . \n"; |
| 156 | 156 | } |
| 157 | 157 | |
@@ -161,14 +161,14 @@ discard block |
||
| 161 | 161 | $sparql .= "<$uri_e> schema:url <$permalink> . \n"; |
| 162 | 162 | |
| 163 | 163 | // set the description. |
| 164 | - if ( ! empty( $descr ) ) { |
|
| 164 | + if ( ! empty($descr)) { |
|
| 165 | 165 | $sparql .= "<$uri_e> schema:description \"$descr\"@$site_language . \n"; |
| 166 | 166 | } |
| 167 | 167 | |
| 168 | - $main_type = wl_entity_type_taxonomy_get_type( $entity_post->ID ); |
|
| 168 | + $main_type = wl_entity_type_taxonomy_get_type($entity_post->ID); |
|
| 169 | 169 | |
| 170 | - if ( null != $main_type ) { |
|
| 171 | - $main_type_uri = wl_sparql_escape_uri( $main_type['uri'] ); |
|
| 170 | + if (null != $main_type) { |
|
| 171 | + $main_type_uri = wl_sparql_escape_uri($main_type['uri']); |
|
| 172 | 172 | $sparql .= " <$uri_e> a <$main_type_uri> . \n"; |
| 173 | 173 | |
| 174 | 174 | // The type define custom fields that hold additional data about the entity. |
@@ -178,33 +178,33 @@ discard block |
||
| 178 | 178 | |
| 179 | 179 | // wl_write_log( 'wl_push_entity_post_to_redlink : checking if entity has export fields [ type :: ' . var_export( $main_type, true ) . ' ]' ); |
| 180 | 180 | |
| 181 | - if ( isset( $main_type['custom_fields'] ) ) { |
|
| 182 | - foreach ( $main_type['custom_fields'] as $field => $settings ) { |
|
| 181 | + if (isset($main_type['custom_fields'])) { |
|
| 182 | + foreach ($main_type['custom_fields'] as $field => $settings) { |
|
| 183 | 183 | |
| 184 | 184 | // wl_write_log( "wl_push_entity_post_to_redlink : entity has export fields" ); |
| 185 | 185 | |
| 186 | - $predicate = wordlift_esc_sparql( $settings['predicate'] ); |
|
| 187 | - if ( ! isset( $settings['export_type'] ) || empty( $settings['export_type'] ) ) { |
|
| 186 | + $predicate = wordlift_esc_sparql($settings['predicate']); |
|
| 187 | + if ( ! isset($settings['export_type']) || empty($settings['export_type'])) { |
|
| 188 | 188 | $type = null; |
| 189 | 189 | } else { |
| 190 | 190 | $type = $settings['export_type']; |
| 191 | 191 | } |
| 192 | 192 | |
| 193 | - foreach ( get_post_meta( $entity_post->ID, $field ) as $value ) { |
|
| 193 | + foreach (get_post_meta($entity_post->ID, $field) as $value) { |
|
| 194 | 194 | $sparql .= " <$uri_e> <$predicate> "; |
| 195 | 195 | |
| 196 | - if ( ! is_null( $type ) && ( substr( $type, 0, 4 ) == 'http' ) ) { |
|
| 196 | + if ( ! is_null($type) && (substr($type, 0, 4) == 'http')) { |
|
| 197 | 197 | // Type is defined by a raw uri (es. http://schema.org/PostalAddress) |
| 198 | 198 | |
| 199 | 199 | // Extract uri if the value is numeric |
| 200 | - if ( is_numeric( $value ) ) { |
|
| 201 | - $value = wl_get_entity_uri( $value ); |
|
| 200 | + if (is_numeric($value)) { |
|
| 201 | + $value = wl_get_entity_uri($value); |
|
| 202 | 202 | } |
| 203 | 203 | |
| 204 | - $sparql .= '<' . wl_sparql_escape_uri( $value ) . '>'; |
|
| 204 | + $sparql .= '<'.wl_sparql_escape_uri($value).'>'; |
|
| 205 | 205 | } else { |
| 206 | 206 | // Type is defined in another way (es. xsd:double) |
| 207 | - $sparql .= '"' . wordlift_esc_sparql( $value ) . '"^^' . wordlift_esc_sparql( $type ); |
|
| 207 | + $sparql .= '"'.wordlift_esc_sparql($value).'"^^'.wordlift_esc_sparql($type); |
|
| 208 | 208 | } |
| 209 | 209 | |
| 210 | 210 | $sparql .= " . \n"; |
@@ -214,20 +214,20 @@ discard block |
||
| 214 | 214 | } |
| 215 | 215 | |
| 216 | 216 | // Get the entity types. |
| 217 | - $type_uris = wl_get_entity_rdf_types( $entity_post->ID ); |
|
| 217 | + $type_uris = wl_get_entity_rdf_types($entity_post->ID); |
|
| 218 | 218 | |
| 219 | 219 | // Support type are only schema.org ones: it could be null |
| 220 | - foreach ( $type_uris as $type_uri ) { |
|
| 221 | - $type_uri = wl_sparql_escape_uri( $type_uri ); |
|
| 220 | + foreach ($type_uris as $type_uri) { |
|
| 221 | + $type_uri = wl_sparql_escape_uri($type_uri); |
|
| 222 | 222 | $sparql .= "<$uri_e> a <$type_uri> . \n"; |
| 223 | 223 | } |
| 224 | 224 | |
| 225 | 225 | // get related entities. |
| 226 | - $related_entities_ids = wl_core_get_related_entity_ids( $entity_post->ID ); |
|
| 226 | + $related_entities_ids = wl_core_get_related_entity_ids($entity_post->ID); |
|
| 227 | 227 | |
| 228 | - if ( is_array( $related_entities_ids ) ) { |
|
| 229 | - foreach ( $related_entities_ids as $entity_post_id ) { |
|
| 230 | - $related_entity_uri = wl_sparql_escape_uri( wl_get_entity_uri( $entity_post_id ) ); |
|
| 228 | + if (is_array($related_entities_ids)) { |
|
| 229 | + foreach ($related_entities_ids as $entity_post_id) { |
|
| 230 | + $related_entity_uri = wl_sparql_escape_uri(wl_get_entity_uri($entity_post_id)); |
|
| 231 | 231 | // create a two-way relationship. |
| 232 | 232 | $sparql .= " <$uri_e> dct:relation <$related_entity_uri> . \n"; |
| 233 | 233 | $sparql .= " <$related_entity_uri> dct:relation <$uri_e> . \n"; |
@@ -235,9 +235,9 @@ discard block |
||
| 235 | 235 | } |
| 236 | 236 | |
| 237 | 237 | // Add SPARQL stmts to write the schema:image. |
| 238 | - $sparql .= wl_get_sparql_images( $uri, $entity_post->ID ); |
|
| 238 | + $sparql .= wl_get_sparql_images($uri, $entity_post->ID); |
|
| 239 | 239 | |
| 240 | - $query = rl_sparql_prefixes() . <<<EOF |
|
| 240 | + $query = rl_sparql_prefixes().<<<EOF |
|
| 241 | 241 | $delete_stmt |
| 242 | 242 | DELETE { <$uri_e> rdfs:label ?o } WHERE { <$uri_e> rdfs:label ?o }; |
| 243 | 243 | DELETE { <$uri_e> owl:sameAs ?o . } WHERE { <$uri_e> owl:sameAs ?o . }; |
@@ -249,7 +249,7 @@ discard block |
||
| 249 | 249 | INSERT DATA { $sparql }; |
| 250 | 250 | EOF; |
| 251 | 251 | |
| 252 | - rl_execute_sparql_update_query( $query ); |
|
| 252 | + rl_execute_sparql_update_query($query); |
|
| 253 | 253 | } |
| 254 | 254 | |
| 255 | 255 | /** |
@@ -259,18 +259,18 @@ discard block |
||
| 259 | 259 | * |
| 260 | 260 | * @return string The SPARQL fragment (or an empty string). |
| 261 | 261 | */ |
| 262 | -function wl_get_sparql_post_references( $post_id ) { |
|
| 262 | +function wl_get_sparql_post_references($post_id) { |
|
| 263 | 263 | |
| 264 | 264 | // Get the post URI. |
| 265 | - $post_uri = wordlift_esc_sparql( wl_get_entity_uri( $post_id ) ); |
|
| 265 | + $post_uri = wordlift_esc_sparql(wl_get_entity_uri($post_id)); |
|
| 266 | 266 | |
| 267 | 267 | // Get the related entities IDs. |
| 268 | - $related = wl_core_get_related_entity_ids( $post_id ); |
|
| 268 | + $related = wl_core_get_related_entity_ids($post_id); |
|
| 269 | 269 | |
| 270 | 270 | // Build the SPARQL fragment. |
| 271 | 271 | $sparql = ''; |
| 272 | - foreach ( $related as $id ) { |
|
| 273 | - $uri = wordlift_esc_sparql( wl_get_entity_uri( $id ) ); |
|
| 272 | + foreach ($related as $id) { |
|
| 273 | + $uri = wordlift_esc_sparql(wl_get_entity_uri($id)); |
|
| 274 | 274 | $sparql .= "<$post_uri> dct:references <$uri> . "; |
| 275 | 275 | } |
| 276 | 276 | |
@@ -285,7 +285,7 @@ discard block |
||
| 285 | 285 | function rl_sparql_prefixes() { |
| 286 | 286 | |
| 287 | 287 | $prefixes = ''; |
| 288 | - foreach ( wl_prefixes() as $prefix => $uri ) { |
|
| 288 | + foreach (wl_prefixes() as $prefix => $uri) { |
|
| 289 | 289 | $prefixes .= "PREFIX $prefix: <$uri>\n"; |
| 290 | 290 | } |
| 291 | 291 | |
@@ -299,7 +299,7 @@ discard block |
||
| 299 | 299 | * |
| 300 | 300 | * @return string The escaped string. |
| 301 | 301 | */ |
| 302 | -function wordlift_esc_sparql( $string ) { |
|
| 302 | +function wordlift_esc_sparql($string) { |
|
| 303 | 303 | // see http://www.w3.org/TR/rdf-sparql-query/ |
| 304 | 304 | // '\t' U+0009 (tab) |
| 305 | 305 | // '\n' U+000A (line feed) |
@@ -310,14 +310,14 @@ discard block |
||
| 310 | 310 | // "\'" U+0027 (apostrophe-quote, single quote mark) |
| 311 | 311 | // '\\' U+005C (backslash) |
| 312 | 312 | |
| 313 | - $string = str_replace( '\\', '\\\\', $string ); |
|
| 314 | - $string = str_replace( '\'', '\\\'', $string ); |
|
| 315 | - $string = str_replace( '"', '\\"', $string ); |
|
| 316 | - $string = str_replace( "\f", '\\f', $string ); |
|
| 317 | - $string = str_replace( "\b", '\\b', $string ); |
|
| 318 | - $string = str_replace( "\r", '\\r', $string ); |
|
| 319 | - $string = str_replace( "\n", '\\n', $string ); |
|
| 320 | - $string = str_replace( "\t", '\\t', $string ); |
|
| 313 | + $string = str_replace('\\', '\\\\', $string); |
|
| 314 | + $string = str_replace('\'', '\\\'', $string); |
|
| 315 | + $string = str_replace('"', '\\"', $string); |
|
| 316 | + $string = str_replace("\f", '\\f', $string); |
|
| 317 | + $string = str_replace("\b", '\\b', $string); |
|
| 318 | + $string = str_replace("\r", '\\r', $string); |
|
| 319 | + $string = str_replace("\n", '\\n', $string); |
|
| 320 | + $string = str_replace("\t", '\\t', $string); |
|
| 321 | 321 | |
| 322 | 322 | return $string; |
| 323 | 323 | } |
@@ -331,13 +331,13 @@ discard block |
||
| 331 | 331 | * |
| 332 | 332 | * @return string The escaped URI. |
| 333 | 333 | */ |
| 334 | -function wl_sparql_escape_uri( $string ) { |
|
| 334 | +function wl_sparql_escape_uri($string) { |
|
| 335 | 335 | |
| 336 | 336 | // Should we validate the IRI? |
| 337 | 337 | // http://www.w3.org/TR/sparql11-query/#QSynIRI |
| 338 | 338 | |
| 339 | - $string = str_replace( '<', '\<', $string ); |
|
| 340 | - $string = str_replace( '>', '\>', $string ); |
|
| 339 | + $string = str_replace('<', '\<', $string); |
|
| 340 | + $string = str_replace('>', '\>', $string); |
|
| 341 | 341 | |
| 342 | 342 | return $string; |
| 343 | 343 | |
@@ -355,25 +355,25 @@ discard block |
||
| 355 | 355 | // wl_write_log( "wordlift_reindex_triple_store" ); |
| 356 | 356 | |
| 357 | 357 | // Prepare the request. |
| 358 | - $args = array_merge_recursive( unserialize( WL_REDLINK_API_HTTP_OPTIONS ), array( |
|
| 358 | + $args = array_merge_recursive(unserialize(WL_REDLINK_API_HTTP_OPTIONS), array( |
|
| 359 | 359 | 'method' => 'POST', |
| 360 | 360 | 'headers' => array() |
| 361 | - ) ); |
|
| 361 | + )); |
|
| 362 | 362 | |
| 363 | - $response = wp_remote_request( $url, $args ); |
|
| 363 | + $response = wp_remote_request($url, $args); |
|
| 364 | 364 | |
| 365 | 365 | // If an error has been raised, return the error. |
| 366 | - if ( is_wp_error( $response ) || 200 !== $response['response']['code'] ) { |
|
| 366 | + if (is_wp_error($response) || 200 !== $response['response']['code']) { |
|
| 367 | 367 | |
| 368 | - $body = ( is_wp_error( $response ) ? $response->get_error_message() : $response['body'] ); |
|
| 368 | + $body = (is_wp_error($response) ? $response->get_error_message() : $response['body']); |
|
| 369 | 369 | |
| 370 | - wl_write_log( "wordlift_reindex_triple_store : error [ url :: $url ][ args :: " ); |
|
| 371 | - wl_write_log( "\n" . var_export( $args, true ) ); |
|
| 372 | - wl_write_log( "[ response :: " ); |
|
| 373 | - wl_write_log( "\n" . var_export( $response, true ) ); |
|
| 374 | - wl_write_log( "][ body :: " ); |
|
| 375 | - wl_write_log( "\n" . $body ); |
|
| 376 | - wl_write_log( "]" ); |
|
| 370 | + wl_write_log("wordlift_reindex_triple_store : error [ url :: $url ][ args :: "); |
|
| 371 | + wl_write_log("\n".var_export($args, true)); |
|
| 372 | + wl_write_log("[ response :: "); |
|
| 373 | + wl_write_log("\n".var_export($response, true)); |
|
| 374 | + wl_write_log("][ body :: "); |
|
| 375 | + wl_write_log("\n".$body); |
|
| 376 | + wl_write_log("]"); |
|
| 377 | 377 | |
| 378 | 378 | return false; |
| 379 | 379 | } |