@@ -19,31 +19,31 @@ |
||
| 19 | 19 | */ |
| 20 | 20 | class Wordlift_Duration_Property_Service extends Wordlift_Simple_Property_Service { |
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * {@inheritdoc} |
|
| 24 | - */ |
|
| 25 | - public function get( $id, $meta_key, $type ) { |
|
| 22 | + /** |
|
| 23 | + * {@inheritdoc} |
|
| 24 | + */ |
|
| 25 | + public function get( $id, $meta_key, $type ) { |
|
| 26 | 26 | |
| 27 | - // Get the values and filter out the empty ones (or the ones with 00:00). |
|
| 28 | - $values = array_filter( |
|
| 29 | - parent::get( $id, $meta_key, $type ), |
|
| 30 | - function ( $item ) { |
|
| 31 | - return ! empty( $item ) && '00:00' !== $item; |
|
| 32 | - } |
|
| 33 | - ); |
|
| 27 | + // Get the values and filter out the empty ones (or the ones with 00:00). |
|
| 28 | + $values = array_filter( |
|
| 29 | + parent::get( $id, $meta_key, $type ), |
|
| 30 | + function ( $item ) { |
|
| 31 | + return ! empty( $item ) && '00:00' !== $item; |
|
| 32 | + } |
|
| 33 | + ); |
|
| 34 | 34 | |
| 35 | - /* |
|
| 35 | + /* |
|
| 36 | 36 | * Map the value in the meta |
| 37 | 37 | * The UI for the meta date enable two forms, a number of minutes |
| 38 | 38 | * or an h:mm format. |
| 39 | 39 | * Both needs to be adjusted to the iso format. |
| 40 | 40 | */ |
| 41 | - return array_map( |
|
| 42 | - function ( $value ) { |
|
| 43 | - return 'PT' . str_replace( ':', 'H', $value ) . 'M'; |
|
| 44 | - }, |
|
| 45 | - $values |
|
| 46 | - ); |
|
| 47 | - } |
|
| 41 | + return array_map( |
|
| 42 | + function ( $value ) { |
|
| 43 | + return 'PT' . str_replace( ':', 'H', $value ) . 'M'; |
|
| 44 | + }, |
|
| 45 | + $values |
|
| 46 | + ); |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | 49 | } |
@@ -22,13 +22,13 @@ discard block |
||
| 22 | 22 | /** |
| 23 | 23 | * {@inheritdoc} |
| 24 | 24 | */ |
| 25 | - public function get( $id, $meta_key, $type ) { |
|
| 25 | + public function get($id, $meta_key, $type) { |
|
| 26 | 26 | |
| 27 | 27 | // Get the values and filter out the empty ones (or the ones with 00:00). |
| 28 | 28 | $values = array_filter( |
| 29 | - parent::get( $id, $meta_key, $type ), |
|
| 30 | - function ( $item ) { |
|
| 31 | - return ! empty( $item ) && '00:00' !== $item; |
|
| 29 | + parent::get($id, $meta_key, $type), |
|
| 30 | + function($item) { |
|
| 31 | + return ! empty($item) && '00:00' !== $item; |
|
| 32 | 32 | } |
| 33 | 33 | ); |
| 34 | 34 | |
@@ -39,8 +39,8 @@ discard block |
||
| 39 | 39 | * Both needs to be adjusted to the iso format. |
| 40 | 40 | */ |
| 41 | 41 | return array_map( |
| 42 | - function ( $value ) { |
|
| 43 | - return 'PT' . str_replace( ':', 'H', $value ) . 'M'; |
|
| 42 | + function($value) { |
|
| 43 | + return 'PT'.str_replace(':', 'H', $value).'M'; |
|
| 44 | 44 | }, |
| 45 | 45 | $values |
| 46 | 46 | ); |
@@ -9,74 +9,74 @@ |
||
| 9 | 9 | */ |
| 10 | 10 | class Wordlift_Property_Getter { |
| 11 | 11 | |
| 12 | - /** |
|
| 13 | - * An array of {@link Wordlift_Simple_Property_Service}s which can access a |
|
| 14 | - * property. |
|
| 15 | - * |
|
| 16 | - * @since 3.8.0 |
|
| 17 | - * @access private |
|
| 18 | - * @var Wordlift_Simple_Property_Service[] $services An array of {@link Wordlift_Simple_Property_Service}s. |
|
| 19 | - */ |
|
| 20 | - private $services = array(); |
|
| 12 | + /** |
|
| 13 | + * An array of {@link Wordlift_Simple_Property_Service}s which can access a |
|
| 14 | + * property. |
|
| 15 | + * |
|
| 16 | + * @since 3.8.0 |
|
| 17 | + * @access private |
|
| 18 | + * @var Wordlift_Simple_Property_Service[] $services An array of {@link Wordlift_Simple_Property_Service}s. |
|
| 19 | + */ |
|
| 20 | + private $services = array(); |
|
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * The default {@link Wordlift_Simple_Property_Service} which is used to access |
|
| 24 | - * a property when no specific {@link Wordlift_Simple_Property_Service} is found |
|
| 25 | - * in the {@see $services} array. |
|
| 26 | - * |
|
| 27 | - * @var Wordlift_Simple_Property_Service |
|
| 28 | - */ |
|
| 29 | - private $default; |
|
| 22 | + /** |
|
| 23 | + * The default {@link Wordlift_Simple_Property_Service} which is used to access |
|
| 24 | + * a property when no specific {@link Wordlift_Simple_Property_Service} is found |
|
| 25 | + * in the {@see $services} array. |
|
| 26 | + * |
|
| 27 | + * @var Wordlift_Simple_Property_Service |
|
| 28 | + */ |
|
| 29 | + private $default; |
|
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * Create a property service with the provided {@link Wordlift_Simple_Property_Service} |
|
| 33 | - * as default. |
|
| 34 | - * |
|
| 35 | - * @param $default |
|
| 36 | - * |
|
| 37 | - * @since 3.8.0 |
|
| 38 | - */ |
|
| 39 | - public function __construct( $default ) { |
|
| 31 | + /** |
|
| 32 | + * Create a property service with the provided {@link Wordlift_Simple_Property_Service} |
|
| 33 | + * as default. |
|
| 34 | + * |
|
| 35 | + * @param $default |
|
| 36 | + * |
|
| 37 | + * @since 3.8.0 |
|
| 38 | + */ |
|
| 39 | + public function __construct( $default ) { |
|
| 40 | 40 | |
| 41 | - $this->default = $default; |
|
| 41 | + $this->default = $default; |
|
| 42 | 42 | |
| 43 | - } |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * Register a {@link Wordlift_Simple_Property_Service} for the specified meta keys. |
|
| 47 | - * |
|
| 48 | - * @param \Wordlift_Simple_Property_Service $property_service A {@link Wordlift_Simple_Property_Service} instance. |
|
| 49 | - * @param array $meta_keys An array of meta keys that the provided {@link Wordlift_Simple_Property_Service} will handle. |
|
| 50 | - * |
|
| 51 | - * @since 3.8.0 |
|
| 52 | - */ |
|
| 53 | - public function register( $property_service, $meta_keys ) { |
|
| 45 | + /** |
|
| 46 | + * Register a {@link Wordlift_Simple_Property_Service} for the specified meta keys. |
|
| 47 | + * |
|
| 48 | + * @param \Wordlift_Simple_Property_Service $property_service A {@link Wordlift_Simple_Property_Service} instance. |
|
| 49 | + * @param array $meta_keys An array of meta keys that the provided {@link Wordlift_Simple_Property_Service} will handle. |
|
| 50 | + * |
|
| 51 | + * @since 3.8.0 |
|
| 52 | + */ |
|
| 53 | + public function register( $property_service, $meta_keys ) { |
|
| 54 | 54 | |
| 55 | - // Register the specified property service for each meta key. |
|
| 56 | - foreach ( $meta_keys as $meta_key ) { |
|
| 57 | - $this->services[ $meta_key ] = $property_service; |
|
| 58 | - } |
|
| 55 | + // Register the specified property service for each meta key. |
|
| 56 | + foreach ( $meta_keys as $meta_key ) { |
|
| 57 | + $this->services[ $meta_key ] = $property_service; |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - } |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - /** |
|
| 63 | - * Get the value for the specified entity post id and WP's meta key. |
|
| 64 | - * |
|
| 65 | - * @param int $post_id The post id. |
|
| 66 | - * @param string $meta_key The meta key. |
|
| 67 | - * |
|
| 68 | - * @param int $type Term or Post, by default Post is used. |
|
| 69 | - * |
|
| 70 | - * @return mixed|null The property value or null. |
|
| 71 | - * @since 3.8.0 |
|
| 72 | - */ |
|
| 73 | - public function get( $post_id, $meta_key, $type ) { |
|
| 62 | + /** |
|
| 63 | + * Get the value for the specified entity post id and WP's meta key. |
|
| 64 | + * |
|
| 65 | + * @param int $post_id The post id. |
|
| 66 | + * @param string $meta_key The meta key. |
|
| 67 | + * |
|
| 68 | + * @param int $type Term or Post, by default Post is used. |
|
| 69 | + * |
|
| 70 | + * @return mixed|null The property value or null. |
|
| 71 | + * @since 3.8.0 |
|
| 72 | + */ |
|
| 73 | + public function get( $post_id, $meta_key, $type ) { |
|
| 74 | 74 | |
| 75 | - return isset( $this->services[ $meta_key ] ) |
|
| 76 | - // Use a specific property service. |
|
| 77 | - ? $this->services[ $meta_key ]->get( $post_id, $meta_key, $type ) |
|
| 78 | - // Use the default property service. |
|
| 79 | - : $this->default->get( $post_id, $meta_key, $type ); |
|
| 80 | - } |
|
| 75 | + return isset( $this->services[ $meta_key ] ) |
|
| 76 | + // Use a specific property service. |
|
| 77 | + ? $this->services[ $meta_key ]->get( $post_id, $meta_key, $type ) |
|
| 78 | + // Use the default property service. |
|
| 79 | + : $this->default->get( $post_id, $meta_key, $type ); |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | 82 | } |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | * |
| 37 | 37 | * @since 3.8.0 |
| 38 | 38 | */ |
| 39 | - public function __construct( $default ) { |
|
| 39 | + public function __construct($default) { |
|
| 40 | 40 | |
| 41 | 41 | $this->default = $default; |
| 42 | 42 | |
@@ -50,11 +50,11 @@ discard block |
||
| 50 | 50 | * |
| 51 | 51 | * @since 3.8.0 |
| 52 | 52 | */ |
| 53 | - public function register( $property_service, $meta_keys ) { |
|
| 53 | + public function register($property_service, $meta_keys) { |
|
| 54 | 54 | |
| 55 | 55 | // Register the specified property service for each meta key. |
| 56 | - foreach ( $meta_keys as $meta_key ) { |
|
| 57 | - $this->services[ $meta_key ] = $property_service; |
|
| 56 | + foreach ($meta_keys as $meta_key) { |
|
| 57 | + $this->services[$meta_key] = $property_service; |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | } |
@@ -70,13 +70,13 @@ discard block |
||
| 70 | 70 | * @return mixed|null The property value or null. |
| 71 | 71 | * @since 3.8.0 |
| 72 | 72 | */ |
| 73 | - public function get( $post_id, $meta_key, $type ) { |
|
| 73 | + public function get($post_id, $meta_key, $type) { |
|
| 74 | 74 | |
| 75 | - return isset( $this->services[ $meta_key ] ) |
|
| 75 | + return isset($this->services[$meta_key]) |
|
| 76 | 76 | // Use a specific property service. |
| 77 | - ? $this->services[ $meta_key ]->get( $post_id, $meta_key, $type ) |
|
| 77 | + ? $this->services[$meta_key]->get($post_id, $meta_key, $type) |
|
| 78 | 78 | // Use the default property service. |
| 79 | - : $this->default->get( $post_id, $meta_key, $type ); |
|
| 79 | + : $this->default->get($post_id, $meta_key, $type); |
|
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | } |
@@ -26,60 +26,60 @@ |
||
| 26 | 26 | */ |
| 27 | 27 | class Wordlift_Property_Getter_Factory { |
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * Create a {@link Wordlift_Property_Getter} instance. |
|
| 31 | - * |
|
| 32 | - * @return \Wordlift_Property_Getter A {@link Wordlift_Property_Getter} instance. |
|
| 33 | - * @since 3.8.0 |
|
| 34 | - */ |
|
| 35 | - public static function create() { |
|
| 29 | + /** |
|
| 30 | + * Create a {@link Wordlift_Property_Getter} instance. |
|
| 31 | + * |
|
| 32 | + * @return \Wordlift_Property_Getter A {@link Wordlift_Property_Getter} instance. |
|
| 33 | + * @since 3.8.0 |
|
| 34 | + */ |
|
| 35 | + public static function create() { |
|
| 36 | 36 | |
| 37 | - $property_getter = new Wordlift_Property_Getter( new Wordlift_Simple_Property_Service() ); |
|
| 38 | - $property_getter->register( |
|
| 39 | - new Wordlift_Entity_Property_Service(), |
|
| 40 | - array( |
|
| 41 | - Wordlift_Schema_Service::FIELD_FOUNDER, |
|
| 42 | - Wordlift_Schema_Service::FIELD_AUTHOR, |
|
| 43 | - Wordlift_Schema_Service::FIELD_KNOWS, |
|
| 44 | - Wordlift_Schema_Service::FIELD_BIRTH_PLACE, |
|
| 45 | - Wordlift_Schema_Service::FIELD_AFFILIATION, |
|
| 46 | - Wordlift_Schema_Service::FIELD_PERFORMER, |
|
| 47 | - Wordlift_Schema_Service::FIELD_OFFERS, |
|
| 48 | - Wordlift_Schema_Service::FIELD_ITEM_OFFERED, |
|
| 49 | - ) |
|
| 50 | - ); |
|
| 51 | - $property_getter->register( |
|
| 52 | - new Wordlift_Location_Property_Service(), |
|
| 53 | - array( |
|
| 54 | - Wordlift_Schema_Service::FIELD_LOCATION, |
|
| 55 | - ) |
|
| 56 | - ); |
|
| 57 | - $property_getter->register( new Wordlift_Url_Property_Service(), array( Wordlift_Url_Property_Service::META_KEY ) ); |
|
| 58 | - $property_getter->register( |
|
| 59 | - new Wordlift_Double_Property_Service(), |
|
| 60 | - array( |
|
| 61 | - Wordlift_Schema_Service::FIELD_GEO_LATITUDE, |
|
| 62 | - Wordlift_Schema_Service::FIELD_GEO_LONGITUDE, |
|
| 63 | - ) |
|
| 64 | - ); |
|
| 37 | + $property_getter = new Wordlift_Property_Getter( new Wordlift_Simple_Property_Service() ); |
|
| 38 | + $property_getter->register( |
|
| 39 | + new Wordlift_Entity_Property_Service(), |
|
| 40 | + array( |
|
| 41 | + Wordlift_Schema_Service::FIELD_FOUNDER, |
|
| 42 | + Wordlift_Schema_Service::FIELD_AUTHOR, |
|
| 43 | + Wordlift_Schema_Service::FIELD_KNOWS, |
|
| 44 | + Wordlift_Schema_Service::FIELD_BIRTH_PLACE, |
|
| 45 | + Wordlift_Schema_Service::FIELD_AFFILIATION, |
|
| 46 | + Wordlift_Schema_Service::FIELD_PERFORMER, |
|
| 47 | + Wordlift_Schema_Service::FIELD_OFFERS, |
|
| 48 | + Wordlift_Schema_Service::FIELD_ITEM_OFFERED, |
|
| 49 | + ) |
|
| 50 | + ); |
|
| 51 | + $property_getter->register( |
|
| 52 | + new Wordlift_Location_Property_Service(), |
|
| 53 | + array( |
|
| 54 | + Wordlift_Schema_Service::FIELD_LOCATION, |
|
| 55 | + ) |
|
| 56 | + ); |
|
| 57 | + $property_getter->register( new Wordlift_Url_Property_Service(), array( Wordlift_Url_Property_Service::META_KEY ) ); |
|
| 58 | + $property_getter->register( |
|
| 59 | + new Wordlift_Double_Property_Service(), |
|
| 60 | + array( |
|
| 61 | + Wordlift_Schema_Service::FIELD_GEO_LATITUDE, |
|
| 62 | + Wordlift_Schema_Service::FIELD_GEO_LONGITUDE, |
|
| 63 | + ) |
|
| 64 | + ); |
|
| 65 | 65 | |
| 66 | - $property_getter->register( |
|
| 67 | - new Wordlift_Duration_Property_Service(), |
|
| 68 | - array( |
|
| 69 | - Wordlift_Schema_Service::FIELD_PREP_TIME, |
|
| 70 | - Wordlift_Schema_Service::FIELD_COOK_TIME, |
|
| 71 | - Wordlift_Schema_Service::FIELD_TOTAL_TIME, |
|
| 72 | - ) |
|
| 73 | - ); |
|
| 66 | + $property_getter->register( |
|
| 67 | + new Wordlift_Duration_Property_Service(), |
|
| 68 | + array( |
|
| 69 | + Wordlift_Schema_Service::FIELD_PREP_TIME, |
|
| 70 | + Wordlift_Schema_Service::FIELD_COOK_TIME, |
|
| 71 | + Wordlift_Schema_Service::FIELD_TOTAL_TIME, |
|
| 72 | + ) |
|
| 73 | + ); |
|
| 74 | 74 | |
| 75 | - add_action( |
|
| 76 | - 'after_setup_theme', |
|
| 77 | - function () use ( $property_getter ) { |
|
| 78 | - $property_getter->register( new Wordlift_Required_Property_Service(), apply_filters( 'wl_required_property', array() ) ); |
|
| 79 | - } |
|
| 80 | - ); |
|
| 75 | + add_action( |
|
| 76 | + 'after_setup_theme', |
|
| 77 | + function () use ( $property_getter ) { |
|
| 78 | + $property_getter->register( new Wordlift_Required_Property_Service(), apply_filters( 'wl_required_property', array() ) ); |
|
| 79 | + } |
|
| 80 | + ); |
|
| 81 | 81 | |
| 82 | - return $property_getter; |
|
| 83 | - } |
|
| 82 | + return $property_getter; |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | 85 | } |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | */ |
| 35 | 35 | public static function create() { |
| 36 | 36 | |
| 37 | - $property_getter = new Wordlift_Property_Getter( new Wordlift_Simple_Property_Service() ); |
|
| 37 | + $property_getter = new Wordlift_Property_Getter(new Wordlift_Simple_Property_Service()); |
|
| 38 | 38 | $property_getter->register( |
| 39 | 39 | new Wordlift_Entity_Property_Service(), |
| 40 | 40 | array( |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | Wordlift_Schema_Service::FIELD_LOCATION, |
| 55 | 55 | ) |
| 56 | 56 | ); |
| 57 | - $property_getter->register( new Wordlift_Url_Property_Service(), array( Wordlift_Url_Property_Service::META_KEY ) ); |
|
| 57 | + $property_getter->register(new Wordlift_Url_Property_Service(), array(Wordlift_Url_Property_Service::META_KEY)); |
|
| 58 | 58 | $property_getter->register( |
| 59 | 59 | new Wordlift_Double_Property_Service(), |
| 60 | 60 | array( |
@@ -74,8 +74,8 @@ discard block |
||
| 74 | 74 | |
| 75 | 75 | add_action( |
| 76 | 76 | 'after_setup_theme', |
| 77 | - function () use ( $property_getter ) { |
|
| 78 | - $property_getter->register( new Wordlift_Required_Property_Service(), apply_filters( 'wl_required_property', array() ) ); |
|
| 77 | + function() use ($property_getter) { |
|
| 78 | + $property_getter->register(new Wordlift_Required_Property_Service(), apply_filters('wl_required_property', array())); |
|
| 79 | 79 | } |
| 80 | 80 | ); |
| 81 | 81 | |
@@ -12,33 +12,33 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | class Wordlift_Simple_Property_Service { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * The meta key for this property service. |
|
| 17 | - * |
|
| 18 | - * @since 3.8.0 |
|
| 19 | - */ |
|
| 20 | - const META_KEY = '*'; |
|
| 15 | + /** |
|
| 16 | + * The meta key for this property service. |
|
| 17 | + * |
|
| 18 | + * @since 3.8.0 |
|
| 19 | + */ |
|
| 20 | + const META_KEY = '*'; |
|
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * Get the property value for the specified post id and meta with the specified key. |
|
| 24 | - * |
|
| 25 | - * @param int $id The post id. |
|
| 26 | - * @param string $meta_key The meta key. |
|
| 27 | - * |
|
| 28 | - * @param $type int Post or Term |
|
| 29 | - * |
|
| 30 | - * @return mixed|null The property value. |
|
| 31 | - * @since 3.8.0 |
|
| 32 | - */ |
|
| 33 | - public function get( $id, $meta_key, $type ) { |
|
| 22 | + /** |
|
| 23 | + * Get the property value for the specified post id and meta with the specified key. |
|
| 24 | + * |
|
| 25 | + * @param int $id The post id. |
|
| 26 | + * @param string $meta_key The meta key. |
|
| 27 | + * |
|
| 28 | + * @param $type int Post or Term |
|
| 29 | + * |
|
| 30 | + * @return mixed|null The property value. |
|
| 31 | + * @since 3.8.0 |
|
| 32 | + */ |
|
| 33 | + public function get( $id, $meta_key, $type ) { |
|
| 34 | 34 | |
| 35 | - if ( Object_Type_Enum::POST === $type ) { |
|
| 36 | - // Get the value stored in WP. |
|
| 37 | - return get_post_meta( $id, $meta_key ); |
|
| 38 | - } elseif ( Object_Type_Enum::TERM === $type ) { |
|
| 39 | - return get_term_meta( $id, $meta_key ); |
|
| 40 | - } |
|
| 41 | - return null; |
|
| 42 | - } |
|
| 35 | + if ( Object_Type_Enum::POST === $type ) { |
|
| 36 | + // Get the value stored in WP. |
|
| 37 | + return get_post_meta( $id, $meta_key ); |
|
| 38 | + } elseif ( Object_Type_Enum::TERM === $type ) { |
|
| 39 | + return get_term_meta( $id, $meta_key ); |
|
| 40 | + } |
|
| 41 | + return null; |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | 44 | } |
@@ -30,13 +30,13 @@ |
||
| 30 | 30 | * @return mixed|null The property value. |
| 31 | 31 | * @since 3.8.0 |
| 32 | 32 | */ |
| 33 | - public function get( $id, $meta_key, $type ) { |
|
| 33 | + public function get($id, $meta_key, $type) { |
|
| 34 | 34 | |
| 35 | - if ( Object_Type_Enum::POST === $type ) { |
|
| 35 | + if (Object_Type_Enum::POST === $type) { |
|
| 36 | 36 | // Get the value stored in WP. |
| 37 | - return get_post_meta( $id, $meta_key ); |
|
| 38 | - } elseif ( Object_Type_Enum::TERM === $type ) { |
|
| 39 | - return get_term_meta( $id, $meta_key ); |
|
| 37 | + return get_post_meta($id, $meta_key); |
|
| 38 | + } elseif (Object_Type_Enum::TERM === $type) { |
|
| 39 | + return get_term_meta($id, $meta_key); |
|
| 40 | 40 | } |
| 41 | 41 | return null; |
| 42 | 42 | } |
@@ -16,18 +16,18 @@ |
||
| 16 | 16 | */ |
| 17 | 17 | class Wordlift_Double_Property_Service extends Wordlift_Simple_Property_Service { |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * @inheritdoc |
|
| 21 | - */ |
|
| 22 | - public function get( $id, $meta_key, $type ) { |
|
| 19 | + /** |
|
| 20 | + * @inheritdoc |
|
| 21 | + */ |
|
| 22 | + public function get( $id, $meta_key, $type ) { |
|
| 23 | 23 | |
| 24 | - // Map the result to a numeric value when possible. |
|
| 25 | - return array_map( |
|
| 26 | - function ( $value ) { |
|
| 27 | - return is_numeric( $value ) ? (float) $value : $value; |
|
| 28 | - }, |
|
| 29 | - parent::get( $id, $meta_key, $type ) |
|
| 30 | - ); |
|
| 31 | - } |
|
| 24 | + // Map the result to a numeric value when possible. |
|
| 25 | + return array_map( |
|
| 26 | + function ( $value ) { |
|
| 27 | + return is_numeric( $value ) ? (float) $value : $value; |
|
| 28 | + }, |
|
| 29 | + parent::get( $id, $meta_key, $type ) |
|
| 30 | + ); |
|
| 31 | + } |
|
| 32 | 32 | |
| 33 | 33 | } |
@@ -19,14 +19,14 @@ |
||
| 19 | 19 | /** |
| 20 | 20 | * @inheritdoc |
| 21 | 21 | */ |
| 22 | - public function get( $id, $meta_key, $type ) { |
|
| 22 | + public function get($id, $meta_key, $type) { |
|
| 23 | 23 | |
| 24 | 24 | // Map the result to a numeric value when possible. |
| 25 | 25 | return array_map( |
| 26 | - function ( $value ) { |
|
| 27 | - return is_numeric( $value ) ? (float) $value : $value; |
|
| 26 | + function($value) { |
|
| 27 | + return is_numeric($value) ? (float) $value : $value; |
|
| 28 | 28 | }, |
| 29 | - parent::get( $id, $meta_key, $type ) |
|
| 29 | + parent::get($id, $meta_key, $type) |
|
| 30 | 30 | ); |
| 31 | 31 | } |
| 32 | 32 | |
@@ -6,23 +6,23 @@ |
||
| 6 | 6 | */ |
| 7 | 7 | class Wordlift_Required_Property_Service extends Wordlift_Entity_Property_Service { |
| 8 | 8 | |
| 9 | - /** |
|
| 10 | - * {@inheritdoc} |
|
| 11 | - */ |
|
| 12 | - public function get( $id, $meta_key, $type ) { |
|
| 9 | + /** |
|
| 10 | + * {@inheritdoc} |
|
| 11 | + */ |
|
| 12 | + public function get( $id, $meta_key, $type ) { |
|
| 13 | 13 | |
| 14 | - return array_map( |
|
| 15 | - function ( $item ) { |
|
| 14 | + return array_map( |
|
| 15 | + function ( $item ) { |
|
| 16 | 16 | |
| 17 | - // If this is an entity reference, set that this entity is always required in SD output. |
|
| 18 | - if ( $item instanceof Wordlift_Property_Entity_Reference ) { |
|
| 19 | - $item->set_required( true ); |
|
| 20 | - } |
|
| 17 | + // If this is an entity reference, set that this entity is always required in SD output. |
|
| 18 | + if ( $item instanceof Wordlift_Property_Entity_Reference ) { |
|
| 19 | + $item->set_required( true ); |
|
| 20 | + } |
|
| 21 | 21 | |
| 22 | - return $item; |
|
| 23 | - }, |
|
| 24 | - parent::get( $id, $meta_key, $type ) |
|
| 25 | - ); |
|
| 26 | - } |
|
| 22 | + return $item; |
|
| 23 | + }, |
|
| 24 | + parent::get( $id, $meta_key, $type ) |
|
| 25 | + ); |
|
| 26 | + } |
|
| 27 | 27 | |
| 28 | 28 | } |
@@ -9,19 +9,19 @@ |
||
| 9 | 9 | /** |
| 10 | 10 | * {@inheritdoc} |
| 11 | 11 | */ |
| 12 | - public function get( $id, $meta_key, $type ) { |
|
| 12 | + public function get($id, $meta_key, $type) { |
|
| 13 | 13 | |
| 14 | 14 | return array_map( |
| 15 | - function ( $item ) { |
|
| 15 | + function($item) { |
|
| 16 | 16 | |
| 17 | 17 | // If this is an entity reference, set that this entity is always required in SD output. |
| 18 | - if ( $item instanceof Wordlift_Property_Entity_Reference ) { |
|
| 19 | - $item->set_required( true ); |
|
| 18 | + if ($item instanceof Wordlift_Property_Entity_Reference) { |
|
| 19 | + $item->set_required(true); |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | return $item; |
| 23 | 23 | }, |
| 24 | - parent::get( $id, $meta_key, $type ) |
|
| 24 | + parent::get($id, $meta_key, $type) |
|
| 25 | 25 | ); |
| 26 | 26 | } |
| 27 | 27 | |
@@ -15,28 +15,28 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | class Wordlift_Location_Property_Service extends Wordlift_Entity_Property_Service { |
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * {@inheritdoc} |
|
| 20 | - */ |
|
| 21 | - public function get( $id, $meta_key, $type ) { |
|
| 18 | + /** |
|
| 19 | + * {@inheritdoc} |
|
| 20 | + */ |
|
| 21 | + public function get( $id, $meta_key, $type ) { |
|
| 22 | 22 | |
| 23 | - return array_map( |
|
| 24 | - function ( $item ) { |
|
| 23 | + return array_map( |
|
| 24 | + function ( $item ) { |
|
| 25 | 25 | |
| 26 | - // If this is an entity reference, set that this entity is always required in SD output. |
|
| 27 | - if ( $item instanceof Wordlift_Property_Entity_Reference ) { |
|
| 28 | - $item->set_required( true ); |
|
| 26 | + // If this is an entity reference, set that this entity is always required in SD output. |
|
| 27 | + if ( $item instanceof Wordlift_Property_Entity_Reference ) { |
|
| 28 | + $item->set_required( true ); |
|
| 29 | 29 | |
| 30 | - return $item; |
|
| 31 | - } |
|
| 30 | + return $item; |
|
| 31 | + } |
|
| 32 | 32 | |
| 33 | - return array( |
|
| 34 | - '@type' => 'Place', |
|
| 35 | - 'name' => $item, |
|
| 36 | - ); |
|
| 37 | - }, |
|
| 38 | - parent::get( $id, $meta_key, $type ) |
|
| 39 | - ); |
|
| 40 | - } |
|
| 33 | + return array( |
|
| 34 | + '@type' => 'Place', |
|
| 35 | + 'name' => $item, |
|
| 36 | + ); |
|
| 37 | + }, |
|
| 38 | + parent::get( $id, $meta_key, $type ) |
|
| 39 | + ); |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | 42 | } |
@@ -18,14 +18,14 @@ discard block |
||
| 18 | 18 | /** |
| 19 | 19 | * {@inheritdoc} |
| 20 | 20 | */ |
| 21 | - public function get( $id, $meta_key, $type ) { |
|
| 21 | + public function get($id, $meta_key, $type) { |
|
| 22 | 22 | |
| 23 | 23 | return array_map( |
| 24 | - function ( $item ) { |
|
| 24 | + function($item) { |
|
| 25 | 25 | |
| 26 | 26 | // If this is an entity reference, set that this entity is always required in SD output. |
| 27 | - if ( $item instanceof Wordlift_Property_Entity_Reference ) { |
|
| 28 | - $item->set_required( true ); |
|
| 27 | + if ($item instanceof Wordlift_Property_Entity_Reference) { |
|
| 28 | + $item->set_required(true); |
|
| 29 | 29 | |
| 30 | 30 | return $item; |
| 31 | 31 | } |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | 'name' => $item, |
| 36 | 36 | ); |
| 37 | 37 | }, |
| 38 | - parent::get( $id, $meta_key, $type ) |
|
| 38 | + parent::get($id, $meta_key, $type) |
|
| 39 | 39 | ); |
| 40 | 40 | } |
| 41 | 41 | |
@@ -14,143 +14,143 @@ |
||
| 14 | 14 | */ |
| 15 | 15 | class Wordlift_Redirect_Service { |
| 16 | 16 | |
| 17 | - const LOD_ENDPOINT = 'http://www.lodview.it'; |
|
| 18 | - const LOD_HOST = 'www.lodview.it'; |
|
| 19 | - |
|
| 20 | - /** |
|
| 21 | - * The Log service. |
|
| 22 | - * |
|
| 23 | - * @since 3.2.0 |
|
| 24 | - * @access private |
|
| 25 | - * @var \Wordlift_Log_Service $log_service The Log service. |
|
| 26 | - */ |
|
| 27 | - private $log_service; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * The Entity URI service. |
|
| 31 | - * |
|
| 32 | - * @since 3.2.0 |
|
| 33 | - * @access private |
|
| 34 | - * @var Wordlift_Entity_Uri_Service $entity_uri_service The Entity service. |
|
| 35 | - */ |
|
| 36 | - private $entity_uri_service; |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * A singleton instance of the Redirect service (useful for unit tests). |
|
| 40 | - * |
|
| 41 | - * @since 3.2.0 |
|
| 42 | - * @access private |
|
| 43 | - * @var \Wordlift_Redirect_Service $instance The singleton instance. |
|
| 44 | - */ |
|
| 45 | - private static $instance; |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * Create a Wordlift_Redirect_Service instance. |
|
| 49 | - * |
|
| 50 | - * @param Wordlift_Entity_Uri_Service $entity_uri_service The Entity service. |
|
| 51 | - * |
|
| 52 | - * @since 3.2.0 |
|
| 53 | - */ |
|
| 54 | - public function __construct( $entity_uri_service ) { |
|
| 55 | - |
|
| 56 | - $this->log_service = Wordlift_Log_Service::get_logger( 'Wordlift_Redirect_Service' ); |
|
| 57 | - |
|
| 58 | - $this->entity_uri_service = $entity_uri_service; |
|
| 59 | - |
|
| 60 | - self::$instance = $this; |
|
| 61 | - |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * Get the singleton instance of the Wordlift_Redirect_Service |
|
| 66 | - * |
|
| 67 | - * @return \Wordlift_Redirect_Service The singleton instance of the Wordlift_Redirect_Service. |
|
| 68 | - * @since 3.2.0 |
|
| 69 | - */ |
|
| 70 | - public static function get_instance() { |
|
| 71 | - |
|
| 72 | - return self::$instance; |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * Perform redirect depending on entity uri and target |
|
| 77 | - * |
|
| 78 | - * @since 3.2.0 |
|
| 79 | - */ |
|
| 80 | - public function ajax_redirect() { |
|
| 81 | - |
|
| 82 | - // Check the `uri` parameter. |
|
| 83 | - $entity_uri = filter_input( INPUT_GET, 'uri', FILTER_VALIDATE_URL ); |
|
| 84 | - if ( ! $entity_uri ) { |
|
| 85 | - wp_die( |
|
| 86 | - esc_html__( 'Invalid URI.', 'wordlift' ), |
|
| 87 | - esc_html__( 'Invalid URI.', 'wordlift' ), |
|
| 88 | - array( |
|
| 89 | - 'response' => 400, |
|
| 90 | - 'back_link' => true, |
|
| 91 | - ) |
|
| 92 | - ); |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - // Check the `to` parameter. |
|
| 96 | - $target = filter_input( INPUT_GET, 'to' ); |
|
| 97 | - if ( ! $target ) { |
|
| 98 | - wp_die( |
|
| 99 | - esc_html__( 'Invalid `to` parameter.', 'wordlift' ), |
|
| 100 | - esc_html__( 'Invalid `to` parameter.', 'wordlift' ), |
|
| 101 | - array( |
|
| 102 | - 'response' => 400, |
|
| 103 | - 'back_link' => true, |
|
| 104 | - ) |
|
| 105 | - ); |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - /** @var Wordpress_Content $content */ |
|
| 109 | - $content = Wordpress_Content_Service::get_instance() |
|
| 110 | - ->get_by_entity_id_or_same_as( $entity_uri ); |
|
| 111 | - |
|
| 112 | - if ( ! isset( $content ) ) { |
|
| 113 | - wp_die( |
|
| 114 | - esc_html__( 'Entity not found.', 'wordlift' ), |
|
| 115 | - esc_html__( 'Entity not found.', 'wordlift' ), |
|
| 116 | - array( |
|
| 117 | - 'response' => 404, |
|
| 118 | - 'back_link' => true, |
|
| 119 | - ) |
|
| 120 | - ); |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - switch ( $target ) { |
|
| 124 | - case 'edit': |
|
| 125 | - $redirect_url = $content->get_edit_link(); |
|
| 126 | - break; |
|
| 127 | - case 'lod': |
|
| 128 | - $redirect_url = self::LOD_ENDPOINT . '/lodview/?IRI=' . rawurlencode( $entity_uri ); |
|
| 129 | - break; |
|
| 130 | - case 'permalink': |
|
| 131 | - $redirect_url = $content->get_permalink(); |
|
| 132 | - break; |
|
| 133 | - default: |
|
| 134 | - wp_die( 'Unsupported redirect target.' ); |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - // Perform the redirect |
|
| 138 | - wp_safe_redirect( $redirect_url ); |
|
| 139 | - exit; |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - /** |
|
| 143 | - * Register custom allowed hosts. |
|
| 144 | - * |
|
| 145 | - * @see https://developer.wordpress.org/reference/functions/wp_safe_redirect/ |
|
| 146 | - * |
|
| 147 | - * @since 3.2.0 |
|
| 148 | - * |
|
| 149 | - * @return array permalink. |
|
| 150 | - */ |
|
| 151 | - public function allowed_redirect_hosts( $content ) { |
|
| 152 | - |
|
| 153 | - return array_merge( $content, array( self::LOD_HOST ) ); |
|
| 154 | - } |
|
| 17 | + const LOD_ENDPOINT = 'http://www.lodview.it'; |
|
| 18 | + const LOD_HOST = 'www.lodview.it'; |
|
| 19 | + |
|
| 20 | + /** |
|
| 21 | + * The Log service. |
|
| 22 | + * |
|
| 23 | + * @since 3.2.0 |
|
| 24 | + * @access private |
|
| 25 | + * @var \Wordlift_Log_Service $log_service The Log service. |
|
| 26 | + */ |
|
| 27 | + private $log_service; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * The Entity URI service. |
|
| 31 | + * |
|
| 32 | + * @since 3.2.0 |
|
| 33 | + * @access private |
|
| 34 | + * @var Wordlift_Entity_Uri_Service $entity_uri_service The Entity service. |
|
| 35 | + */ |
|
| 36 | + private $entity_uri_service; |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * A singleton instance of the Redirect service (useful for unit tests). |
|
| 40 | + * |
|
| 41 | + * @since 3.2.0 |
|
| 42 | + * @access private |
|
| 43 | + * @var \Wordlift_Redirect_Service $instance The singleton instance. |
|
| 44 | + */ |
|
| 45 | + private static $instance; |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * Create a Wordlift_Redirect_Service instance. |
|
| 49 | + * |
|
| 50 | + * @param Wordlift_Entity_Uri_Service $entity_uri_service The Entity service. |
|
| 51 | + * |
|
| 52 | + * @since 3.2.0 |
|
| 53 | + */ |
|
| 54 | + public function __construct( $entity_uri_service ) { |
|
| 55 | + |
|
| 56 | + $this->log_service = Wordlift_Log_Service::get_logger( 'Wordlift_Redirect_Service' ); |
|
| 57 | + |
|
| 58 | + $this->entity_uri_service = $entity_uri_service; |
|
| 59 | + |
|
| 60 | + self::$instance = $this; |
|
| 61 | + |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * Get the singleton instance of the Wordlift_Redirect_Service |
|
| 66 | + * |
|
| 67 | + * @return \Wordlift_Redirect_Service The singleton instance of the Wordlift_Redirect_Service. |
|
| 68 | + * @since 3.2.0 |
|
| 69 | + */ |
|
| 70 | + public static function get_instance() { |
|
| 71 | + |
|
| 72 | + return self::$instance; |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * Perform redirect depending on entity uri and target |
|
| 77 | + * |
|
| 78 | + * @since 3.2.0 |
|
| 79 | + */ |
|
| 80 | + public function ajax_redirect() { |
|
| 81 | + |
|
| 82 | + // Check the `uri` parameter. |
|
| 83 | + $entity_uri = filter_input( INPUT_GET, 'uri', FILTER_VALIDATE_URL ); |
|
| 84 | + if ( ! $entity_uri ) { |
|
| 85 | + wp_die( |
|
| 86 | + esc_html__( 'Invalid URI.', 'wordlift' ), |
|
| 87 | + esc_html__( 'Invalid URI.', 'wordlift' ), |
|
| 88 | + array( |
|
| 89 | + 'response' => 400, |
|
| 90 | + 'back_link' => true, |
|
| 91 | + ) |
|
| 92 | + ); |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + // Check the `to` parameter. |
|
| 96 | + $target = filter_input( INPUT_GET, 'to' ); |
|
| 97 | + if ( ! $target ) { |
|
| 98 | + wp_die( |
|
| 99 | + esc_html__( 'Invalid `to` parameter.', 'wordlift' ), |
|
| 100 | + esc_html__( 'Invalid `to` parameter.', 'wordlift' ), |
|
| 101 | + array( |
|
| 102 | + 'response' => 400, |
|
| 103 | + 'back_link' => true, |
|
| 104 | + ) |
|
| 105 | + ); |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + /** @var Wordpress_Content $content */ |
|
| 109 | + $content = Wordpress_Content_Service::get_instance() |
|
| 110 | + ->get_by_entity_id_or_same_as( $entity_uri ); |
|
| 111 | + |
|
| 112 | + if ( ! isset( $content ) ) { |
|
| 113 | + wp_die( |
|
| 114 | + esc_html__( 'Entity not found.', 'wordlift' ), |
|
| 115 | + esc_html__( 'Entity not found.', 'wordlift' ), |
|
| 116 | + array( |
|
| 117 | + 'response' => 404, |
|
| 118 | + 'back_link' => true, |
|
| 119 | + ) |
|
| 120 | + ); |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + switch ( $target ) { |
|
| 124 | + case 'edit': |
|
| 125 | + $redirect_url = $content->get_edit_link(); |
|
| 126 | + break; |
|
| 127 | + case 'lod': |
|
| 128 | + $redirect_url = self::LOD_ENDPOINT . '/lodview/?IRI=' . rawurlencode( $entity_uri ); |
|
| 129 | + break; |
|
| 130 | + case 'permalink': |
|
| 131 | + $redirect_url = $content->get_permalink(); |
|
| 132 | + break; |
|
| 133 | + default: |
|
| 134 | + wp_die( 'Unsupported redirect target.' ); |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + // Perform the redirect |
|
| 138 | + wp_safe_redirect( $redirect_url ); |
|
| 139 | + exit; |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + /** |
|
| 143 | + * Register custom allowed hosts. |
|
| 144 | + * |
|
| 145 | + * @see https://developer.wordpress.org/reference/functions/wp_safe_redirect/ |
|
| 146 | + * |
|
| 147 | + * @since 3.2.0 |
|
| 148 | + * |
|
| 149 | + * @return array permalink. |
|
| 150 | + */ |
|
| 151 | + public function allowed_redirect_hosts( $content ) { |
|
| 152 | + |
|
| 153 | + return array_merge( $content, array( self::LOD_HOST ) ); |
|
| 154 | + } |
|
| 155 | 155 | |
| 156 | 156 | } |
@@ -51,9 +51,9 @@ discard block |
||
| 51 | 51 | * |
| 52 | 52 | * @since 3.2.0 |
| 53 | 53 | */ |
| 54 | - public function __construct( $entity_uri_service ) { |
|
| 54 | + public function __construct($entity_uri_service) { |
|
| 55 | 55 | |
| 56 | - $this->log_service = Wordlift_Log_Service::get_logger( 'Wordlift_Redirect_Service' ); |
|
| 56 | + $this->log_service = Wordlift_Log_Service::get_logger('Wordlift_Redirect_Service'); |
|
| 57 | 57 | |
| 58 | 58 | $this->entity_uri_service = $entity_uri_service; |
| 59 | 59 | |
@@ -80,11 +80,11 @@ discard block |
||
| 80 | 80 | public function ajax_redirect() { |
| 81 | 81 | |
| 82 | 82 | // Check the `uri` parameter. |
| 83 | - $entity_uri = filter_input( INPUT_GET, 'uri', FILTER_VALIDATE_URL ); |
|
| 84 | - if ( ! $entity_uri ) { |
|
| 83 | + $entity_uri = filter_input(INPUT_GET, 'uri', FILTER_VALIDATE_URL); |
|
| 84 | + if ( ! $entity_uri) { |
|
| 85 | 85 | wp_die( |
| 86 | - esc_html__( 'Invalid URI.', 'wordlift' ), |
|
| 87 | - esc_html__( 'Invalid URI.', 'wordlift' ), |
|
| 86 | + esc_html__('Invalid URI.', 'wordlift'), |
|
| 87 | + esc_html__('Invalid URI.', 'wordlift'), |
|
| 88 | 88 | array( |
| 89 | 89 | 'response' => 400, |
| 90 | 90 | 'back_link' => true, |
@@ -93,11 +93,11 @@ discard block |
||
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | // Check the `to` parameter. |
| 96 | - $target = filter_input( INPUT_GET, 'to' ); |
|
| 97 | - if ( ! $target ) { |
|
| 96 | + $target = filter_input(INPUT_GET, 'to'); |
|
| 97 | + if ( ! $target) { |
|
| 98 | 98 | wp_die( |
| 99 | - esc_html__( 'Invalid `to` parameter.', 'wordlift' ), |
|
| 100 | - esc_html__( 'Invalid `to` parameter.', 'wordlift' ), |
|
| 99 | + esc_html__('Invalid `to` parameter.', 'wordlift'), |
|
| 100 | + esc_html__('Invalid `to` parameter.', 'wordlift'), |
|
| 101 | 101 | array( |
| 102 | 102 | 'response' => 400, |
| 103 | 103 | 'back_link' => true, |
@@ -107,12 +107,12 @@ discard block |
||
| 107 | 107 | |
| 108 | 108 | /** @var Wordpress_Content $content */ |
| 109 | 109 | $content = Wordpress_Content_Service::get_instance() |
| 110 | - ->get_by_entity_id_or_same_as( $entity_uri ); |
|
| 110 | + ->get_by_entity_id_or_same_as($entity_uri); |
|
| 111 | 111 | |
| 112 | - if ( ! isset( $content ) ) { |
|
| 112 | + if ( ! isset($content)) { |
|
| 113 | 113 | wp_die( |
| 114 | - esc_html__( 'Entity not found.', 'wordlift' ), |
|
| 115 | - esc_html__( 'Entity not found.', 'wordlift' ), |
|
| 114 | + esc_html__('Entity not found.', 'wordlift'), |
|
| 115 | + esc_html__('Entity not found.', 'wordlift'), |
|
| 116 | 116 | array( |
| 117 | 117 | 'response' => 404, |
| 118 | 118 | 'back_link' => true, |
@@ -120,22 +120,22 @@ discard block |
||
| 120 | 120 | ); |
| 121 | 121 | } |
| 122 | 122 | |
| 123 | - switch ( $target ) { |
|
| 123 | + switch ($target) { |
|
| 124 | 124 | case 'edit': |
| 125 | 125 | $redirect_url = $content->get_edit_link(); |
| 126 | 126 | break; |
| 127 | 127 | case 'lod': |
| 128 | - $redirect_url = self::LOD_ENDPOINT . '/lodview/?IRI=' . rawurlencode( $entity_uri ); |
|
| 128 | + $redirect_url = self::LOD_ENDPOINT.'/lodview/?IRI='.rawurlencode($entity_uri); |
|
| 129 | 129 | break; |
| 130 | 130 | case 'permalink': |
| 131 | 131 | $redirect_url = $content->get_permalink(); |
| 132 | 132 | break; |
| 133 | 133 | default: |
| 134 | - wp_die( 'Unsupported redirect target.' ); |
|
| 134 | + wp_die('Unsupported redirect target.'); |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | // Perform the redirect |
| 138 | - wp_safe_redirect( $redirect_url ); |
|
| 138 | + wp_safe_redirect($redirect_url); |
|
| 139 | 139 | exit; |
| 140 | 140 | } |
| 141 | 141 | |
@@ -148,9 +148,9 @@ discard block |
||
| 148 | 148 | * |
| 149 | 149 | * @return array permalink. |
| 150 | 150 | */ |
| 151 | - public function allowed_redirect_hosts( $content ) { |
|
| 151 | + public function allowed_redirect_hosts($content) { |
|
| 152 | 152 | |
| 153 | - return array_merge( $content, array( self::LOD_HOST ) ); |
|
| 153 | + return array_merge($content, array(self::LOD_HOST)); |
|
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | } |
@@ -16,128 +16,128 @@ |
||
| 16 | 16 | */ |
| 17 | 17 | class Wordlift_Schemaorg_Sync_Service { |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * A {@link Wordlift_Log_Service} instance. |
|
| 21 | - * |
|
| 22 | - * @since 3.20.0 |
|
| 23 | - * @access private |
|
| 24 | - * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance. |
|
| 25 | - */ |
|
| 26 | - private $log; |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * The singleton instance. |
|
| 30 | - * |
|
| 31 | - * @since 3.20.0 |
|
| 32 | - * @access private |
|
| 33 | - * @var \Wordlift_Schemaorg_Sync_Service $instance The singleton instance. |
|
| 34 | - */ |
|
| 35 | - private static $instance; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * Create a {@link Wordlift_Schemaorg_Sync_Service} instance. |
|
| 39 | - * |
|
| 40 | - * @since 3.20.0 |
|
| 41 | - */ |
|
| 42 | - public function __construct() { |
|
| 43 | - |
|
| 44 | - $this->log = Wordlift_Log_Service::get_logger( get_class() ); |
|
| 45 | - |
|
| 46 | - // Hook the `wl_sync_schemaorg` ajax action. |
|
| 47 | - add_action( 'wp_ajax_wl_sync_schemaorg', array( $this, 'load' ) ); |
|
| 48 | - |
|
| 49 | - self::$instance = $this; |
|
| 50 | - |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * Get the singleton instance. |
|
| 55 | - * |
|
| 56 | - * @since 3.20.0 |
|
| 57 | - * |
|
| 58 | - * @return \Wordlift_Schemaorg_Sync_Service The singleton instance. |
|
| 59 | - */ |
|
| 60 | - public static function get_instance() { |
|
| 61 | - |
|
| 62 | - return self::$instance; |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * Load the Schema.org classes from a file. |
|
| 67 | - * |
|
| 68 | - * @since 3.20.0 |
|
| 69 | - * |
|
| 70 | - * @return bool True if successful otherwise false. |
|
| 71 | - */ |
|
| 72 | - public function load_from_file() { |
|
| 73 | - |
|
| 74 | - // Load the file contents. |
|
| 75 | - // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents |
|
| 76 | - $contents = file_get_contents( __DIR__ . '/schema-classes.json' ); |
|
| 77 | - |
|
| 78 | - // Load the file contents. |
|
| 79 | - return $this->load( $contents ); |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - /** |
|
| 83 | - * Load the Schema.org classes from the provided contents. |
|
| 84 | - * |
|
| 85 | - * @param $contents |
|
| 86 | - * |
|
| 87 | - * @return bool |
|
| 88 | - */ |
|
| 89 | - private function load( $contents ) { |
|
| 90 | - |
|
| 91 | - // Decode the JSON contents. |
|
| 92 | - $json = json_decode( $contents, true ); |
|
| 93 | - |
|
| 94 | - if ( null === $json ) { |
|
| 95 | - $this->log->error( 'Invalid json.' ); |
|
| 96 | - |
|
| 97 | - // Error: invalid body. |
|
| 98 | - return false; |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - if ( ! isset( $json['schemaClasses'] ) ) { |
|
| 102 | - $this->log->error( '`schemaClasses` missing from json.' ); |
|
| 103 | - |
|
| 104 | - // Error: invalid json. |
|
| 105 | - return false; |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - // Load the Schema.org classes. |
|
| 109 | - foreach ( $json['schemaClasses'] as $schema_class ) { |
|
| 110 | - $slug = $schema_class['dashname']; |
|
| 111 | - $term = term_exists( $slug, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ); |
|
| 112 | - |
|
| 113 | - $args = array( |
|
| 114 | - 'parent' => 0, |
|
| 115 | - 'description' => $schema_class['description'], |
|
| 116 | - 'slug' => $schema_class['dashname'], |
|
| 117 | - ); |
|
| 118 | - if ( null !== $term ) { |
|
| 119 | - wp_update_term( $term['term_id'], Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, $args ); |
|
| 120 | - } else { |
|
| 121 | - $term = wp_insert_term( $schema_class['name'], Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, $args ); |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - // Update the parents/children relationship. |
|
| 125 | - delete_term_meta( $term['term_id'], Wordlift_Schemaorg_Class_Service::PARENT_OF_META_KEY ); |
|
| 126 | - foreach ( $schema_class['children'] as $child ) { |
|
| 127 | - add_term_meta( $term['term_id'], Wordlift_Schemaorg_Class_Service::PARENT_OF_META_KEY, $child['dashname'] ); |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - // Update the term name. |
|
| 131 | - delete_term_meta( $term['term_id'], Wordlift_Schemaorg_Class_Service::NAME_META_KEY ); |
|
| 132 | - update_term_meta( $term['term_id'], Wordlift_Schemaorg_Class_Service::NAME_META_KEY, $schema_class['name'] ); |
|
| 133 | - |
|
| 134 | - // Update the term URI. |
|
| 135 | - delete_term_meta( $term['term_id'], Wordlift_Schemaorg_Class_Service::URI_META_KEY ); |
|
| 136 | - update_term_meta( $term['term_id'], Wordlift_Schemaorg_Class_Service::URI_META_KEY, "http://schema.org/{$schema_class['name']}" ); |
|
| 137 | - |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - return true; |
|
| 141 | - } |
|
| 19 | + /** |
|
| 20 | + * A {@link Wordlift_Log_Service} instance. |
|
| 21 | + * |
|
| 22 | + * @since 3.20.0 |
|
| 23 | + * @access private |
|
| 24 | + * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance. |
|
| 25 | + */ |
|
| 26 | + private $log; |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * The singleton instance. |
|
| 30 | + * |
|
| 31 | + * @since 3.20.0 |
|
| 32 | + * @access private |
|
| 33 | + * @var \Wordlift_Schemaorg_Sync_Service $instance The singleton instance. |
|
| 34 | + */ |
|
| 35 | + private static $instance; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * Create a {@link Wordlift_Schemaorg_Sync_Service} instance. |
|
| 39 | + * |
|
| 40 | + * @since 3.20.0 |
|
| 41 | + */ |
|
| 42 | + public function __construct() { |
|
| 43 | + |
|
| 44 | + $this->log = Wordlift_Log_Service::get_logger( get_class() ); |
|
| 45 | + |
|
| 46 | + // Hook the `wl_sync_schemaorg` ajax action. |
|
| 47 | + add_action( 'wp_ajax_wl_sync_schemaorg', array( $this, 'load' ) ); |
|
| 48 | + |
|
| 49 | + self::$instance = $this; |
|
| 50 | + |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * Get the singleton instance. |
|
| 55 | + * |
|
| 56 | + * @since 3.20.0 |
|
| 57 | + * |
|
| 58 | + * @return \Wordlift_Schemaorg_Sync_Service The singleton instance. |
|
| 59 | + */ |
|
| 60 | + public static function get_instance() { |
|
| 61 | + |
|
| 62 | + return self::$instance; |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * Load the Schema.org classes from a file. |
|
| 67 | + * |
|
| 68 | + * @since 3.20.0 |
|
| 69 | + * |
|
| 70 | + * @return bool True if successful otherwise false. |
|
| 71 | + */ |
|
| 72 | + public function load_from_file() { |
|
| 73 | + |
|
| 74 | + // Load the file contents. |
|
| 75 | + // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents |
|
| 76 | + $contents = file_get_contents( __DIR__ . '/schema-classes.json' ); |
|
| 77 | + |
|
| 78 | + // Load the file contents. |
|
| 79 | + return $this->load( $contents ); |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + /** |
|
| 83 | + * Load the Schema.org classes from the provided contents. |
|
| 84 | + * |
|
| 85 | + * @param $contents |
|
| 86 | + * |
|
| 87 | + * @return bool |
|
| 88 | + */ |
|
| 89 | + private function load( $contents ) { |
|
| 90 | + |
|
| 91 | + // Decode the JSON contents. |
|
| 92 | + $json = json_decode( $contents, true ); |
|
| 93 | + |
|
| 94 | + if ( null === $json ) { |
|
| 95 | + $this->log->error( 'Invalid json.' ); |
|
| 96 | + |
|
| 97 | + // Error: invalid body. |
|
| 98 | + return false; |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + if ( ! isset( $json['schemaClasses'] ) ) { |
|
| 102 | + $this->log->error( '`schemaClasses` missing from json.' ); |
|
| 103 | + |
|
| 104 | + // Error: invalid json. |
|
| 105 | + return false; |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + // Load the Schema.org classes. |
|
| 109 | + foreach ( $json['schemaClasses'] as $schema_class ) { |
|
| 110 | + $slug = $schema_class['dashname']; |
|
| 111 | + $term = term_exists( $slug, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ); |
|
| 112 | + |
|
| 113 | + $args = array( |
|
| 114 | + 'parent' => 0, |
|
| 115 | + 'description' => $schema_class['description'], |
|
| 116 | + 'slug' => $schema_class['dashname'], |
|
| 117 | + ); |
|
| 118 | + if ( null !== $term ) { |
|
| 119 | + wp_update_term( $term['term_id'], Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, $args ); |
|
| 120 | + } else { |
|
| 121 | + $term = wp_insert_term( $schema_class['name'], Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, $args ); |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + // Update the parents/children relationship. |
|
| 125 | + delete_term_meta( $term['term_id'], Wordlift_Schemaorg_Class_Service::PARENT_OF_META_KEY ); |
|
| 126 | + foreach ( $schema_class['children'] as $child ) { |
|
| 127 | + add_term_meta( $term['term_id'], Wordlift_Schemaorg_Class_Service::PARENT_OF_META_KEY, $child['dashname'] ); |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + // Update the term name. |
|
| 131 | + delete_term_meta( $term['term_id'], Wordlift_Schemaorg_Class_Service::NAME_META_KEY ); |
|
| 132 | + update_term_meta( $term['term_id'], Wordlift_Schemaorg_Class_Service::NAME_META_KEY, $schema_class['name'] ); |
|
| 133 | + |
|
| 134 | + // Update the term URI. |
|
| 135 | + delete_term_meta( $term['term_id'], Wordlift_Schemaorg_Class_Service::URI_META_KEY ); |
|
| 136 | + update_term_meta( $term['term_id'], Wordlift_Schemaorg_Class_Service::URI_META_KEY, "http://schema.org/{$schema_class['name']}" ); |
|
| 137 | + |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + return true; |
|
| 141 | + } |
|
| 142 | 142 | |
| 143 | 143 | } |
@@ -41,10 +41,10 @@ discard block |
||
| 41 | 41 | */ |
| 42 | 42 | public function __construct() { |
| 43 | 43 | |
| 44 | - $this->log = Wordlift_Log_Service::get_logger( get_class() ); |
|
| 44 | + $this->log = Wordlift_Log_Service::get_logger(get_class()); |
|
| 45 | 45 | |
| 46 | 46 | // Hook the `wl_sync_schemaorg` ajax action. |
| 47 | - add_action( 'wp_ajax_wl_sync_schemaorg', array( $this, 'load' ) ); |
|
| 47 | + add_action('wp_ajax_wl_sync_schemaorg', array($this, 'load')); |
|
| 48 | 48 | |
| 49 | 49 | self::$instance = $this; |
| 50 | 50 | |
@@ -73,10 +73,10 @@ discard block |
||
| 73 | 73 | |
| 74 | 74 | // Load the file contents. |
| 75 | 75 | // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents |
| 76 | - $contents = file_get_contents( __DIR__ . '/schema-classes.json' ); |
|
| 76 | + $contents = file_get_contents(__DIR__.'/schema-classes.json'); |
|
| 77 | 77 | |
| 78 | 78 | // Load the file contents. |
| 79 | - return $this->load( $contents ); |
|
| 79 | + return $this->load($contents); |
|
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | /** |
@@ -86,54 +86,54 @@ discard block |
||
| 86 | 86 | * |
| 87 | 87 | * @return bool |
| 88 | 88 | */ |
| 89 | - private function load( $contents ) { |
|
| 89 | + private function load($contents) { |
|
| 90 | 90 | |
| 91 | 91 | // Decode the JSON contents. |
| 92 | - $json = json_decode( $contents, true ); |
|
| 92 | + $json = json_decode($contents, true); |
|
| 93 | 93 | |
| 94 | - if ( null === $json ) { |
|
| 95 | - $this->log->error( 'Invalid json.' ); |
|
| 94 | + if (null === $json) { |
|
| 95 | + $this->log->error('Invalid json.'); |
|
| 96 | 96 | |
| 97 | 97 | // Error: invalid body. |
| 98 | 98 | return false; |
| 99 | 99 | } |
| 100 | 100 | |
| 101 | - if ( ! isset( $json['schemaClasses'] ) ) { |
|
| 102 | - $this->log->error( '`schemaClasses` missing from json.' ); |
|
| 101 | + if ( ! isset($json['schemaClasses'])) { |
|
| 102 | + $this->log->error('`schemaClasses` missing from json.'); |
|
| 103 | 103 | |
| 104 | 104 | // Error: invalid json. |
| 105 | 105 | return false; |
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | // Load the Schema.org classes. |
| 109 | - foreach ( $json['schemaClasses'] as $schema_class ) { |
|
| 109 | + foreach ($json['schemaClasses'] as $schema_class) { |
|
| 110 | 110 | $slug = $schema_class['dashname']; |
| 111 | - $term = term_exists( $slug, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ); |
|
| 111 | + $term = term_exists($slug, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME); |
|
| 112 | 112 | |
| 113 | 113 | $args = array( |
| 114 | 114 | 'parent' => 0, |
| 115 | 115 | 'description' => $schema_class['description'], |
| 116 | 116 | 'slug' => $schema_class['dashname'], |
| 117 | 117 | ); |
| 118 | - if ( null !== $term ) { |
|
| 119 | - wp_update_term( $term['term_id'], Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, $args ); |
|
| 118 | + if (null !== $term) { |
|
| 119 | + wp_update_term($term['term_id'], Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, $args); |
|
| 120 | 120 | } else { |
| 121 | - $term = wp_insert_term( $schema_class['name'], Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, $args ); |
|
| 121 | + $term = wp_insert_term($schema_class['name'], Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, $args); |
|
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | // Update the parents/children relationship. |
| 125 | - delete_term_meta( $term['term_id'], Wordlift_Schemaorg_Class_Service::PARENT_OF_META_KEY ); |
|
| 126 | - foreach ( $schema_class['children'] as $child ) { |
|
| 127 | - add_term_meta( $term['term_id'], Wordlift_Schemaorg_Class_Service::PARENT_OF_META_KEY, $child['dashname'] ); |
|
| 125 | + delete_term_meta($term['term_id'], Wordlift_Schemaorg_Class_Service::PARENT_OF_META_KEY); |
|
| 126 | + foreach ($schema_class['children'] as $child) { |
|
| 127 | + add_term_meta($term['term_id'], Wordlift_Schemaorg_Class_Service::PARENT_OF_META_KEY, $child['dashname']); |
|
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | // Update the term name. |
| 131 | - delete_term_meta( $term['term_id'], Wordlift_Schemaorg_Class_Service::NAME_META_KEY ); |
|
| 132 | - update_term_meta( $term['term_id'], Wordlift_Schemaorg_Class_Service::NAME_META_KEY, $schema_class['name'] ); |
|
| 131 | + delete_term_meta($term['term_id'], Wordlift_Schemaorg_Class_Service::NAME_META_KEY); |
|
| 132 | + update_term_meta($term['term_id'], Wordlift_Schemaorg_Class_Service::NAME_META_KEY, $schema_class['name']); |
|
| 133 | 133 | |
| 134 | 134 | // Update the term URI. |
| 135 | - delete_term_meta( $term['term_id'], Wordlift_Schemaorg_Class_Service::URI_META_KEY ); |
|
| 136 | - update_term_meta( $term['term_id'], Wordlift_Schemaorg_Class_Service::URI_META_KEY, "http://schema.org/{$schema_class['name']}" ); |
|
| 135 | + delete_term_meta($term['term_id'], Wordlift_Schemaorg_Class_Service::URI_META_KEY); |
|
| 136 | + update_term_meta($term['term_id'], Wordlift_Schemaorg_Class_Service::URI_META_KEY, "http://schema.org/{$schema_class['name']}"); |
|
| 137 | 137 | |
| 138 | 138 | } |
| 139 | 139 | |