@@ -7,14 +7,14 @@ |
||
7 | 7 | */ |
8 | 8 | class Webhooks_Loader { |
9 | 9 | |
10 | - const URLS_OPTION_NAME = 'wl_webhooks_urls'; |
|
10 | + const URLS_OPTION_NAME = 'wl_webhooks_urls'; |
|
11 | 11 | |
12 | - public function init() { |
|
12 | + public function init() { |
|
13 | 13 | |
14 | - $settings_tab = new Webhooks_Settings(); |
|
15 | - $settings_tab->init(); |
|
14 | + $settings_tab = new Webhooks_Settings(); |
|
15 | + $settings_tab->init(); |
|
16 | 16 | |
17 | - new Webhooks_Manager(); |
|
18 | - } |
|
17 | + new Webhooks_Manager(); |
|
18 | + } |
|
19 | 19 | |
20 | 20 | } |
@@ -3,7 +3,7 @@ |
||
3 | 3 | use Wordlift\Features\Response_Adapter; |
4 | 4 | |
5 | 5 | if ( ! defined( 'ABSPATH' ) ) { |
6 | - exit; |
|
6 | + exit; |
|
7 | 7 | } |
8 | 8 | |
9 | 9 | new Response_Adapter(); |
@@ -2,7 +2,7 @@ |
||
2 | 2 | |
3 | 3 | use Wordlift\Features\Response_Adapter; |
4 | 4 | |
5 | -if ( ! defined( 'ABSPATH' ) ) { |
|
5 | +if ( ! defined('ABSPATH')) { |
|
6 | 6 | exit; |
7 | 7 | } |
8 | 8 |
@@ -21,23 +21,23 @@ |
||
21 | 21 | */ |
22 | 22 | private $type; |
23 | 23 | |
24 | - public static function create_post( $id ) { |
|
25 | - return new self( $id, Object_Type_Enum::POST ); |
|
24 | + public static function create_post($id) { |
|
25 | + return new self($id, Object_Type_Enum::POST); |
|
26 | 26 | } |
27 | 27 | |
28 | - public static function create_term( $id ) { |
|
29 | - return new self( $id, Object_Type_Enum::TERM ); |
|
28 | + public static function create_term($id) { |
|
29 | + return new self($id, Object_Type_Enum::TERM); |
|
30 | 30 | } |
31 | 31 | |
32 | - public static function create_user( $id ) { |
|
33 | - return new self( $id, Object_Type_Enum::USER ); |
|
32 | + public static function create_user($id) { |
|
33 | + return new self($id, Object_Type_Enum::USER); |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | /** |
37 | 37 | * @param int $id The post/page/term/user ID. |
38 | 38 | * @param int $type The content type, post/page/term/user. |
39 | 39 | */ |
40 | - public function __construct( $id, $type ) { |
|
40 | + public function __construct($id, $type) { |
|
41 | 41 | $this->id = $id; |
42 | 42 | $this->type = $type; |
43 | 43 | } |
@@ -12,43 +12,43 @@ |
||
12 | 12 | // phpcs:ignore WordPress.WP.CapitalPDangit.MisspelledClassName |
13 | 13 | class Wordpress_Content_Id implements Content_Id { |
14 | 14 | |
15 | - /** |
|
16 | - * @var int $id The post/page/term/user ID. |
|
17 | - */ |
|
18 | - private $id; |
|
19 | - |
|
20 | - /** |
|
21 | - * @var Object_Type_Enum $type The content type, post/page/term/user. |
|
22 | - */ |
|
23 | - private $type; |
|
24 | - |
|
25 | - public static function create_post( $id ) { |
|
26 | - return new self( $id, Object_Type_Enum::POST ); |
|
27 | - } |
|
28 | - |
|
29 | - public static function create_term( $id ) { |
|
30 | - return new self( $id, Object_Type_Enum::TERM ); |
|
31 | - } |
|
32 | - |
|
33 | - public static function create_user( $id ) { |
|
34 | - return new self( $id, Object_Type_Enum::USER ); |
|
35 | - } |
|
36 | - |
|
37 | - /** |
|
38 | - * @param int $id The post/page/term/user ID. |
|
39 | - * @param int $type The content type, post/page/term/user. |
|
40 | - */ |
|
41 | - public function __construct( $id, $type ) { |
|
42 | - $this->id = $id; |
|
43 | - $this->type = $type; |
|
44 | - } |
|
45 | - |
|
46 | - public function get_id() { |
|
47 | - return $this->id; |
|
48 | - } |
|
49 | - |
|
50 | - public function get_type() { |
|
51 | - return $this->type; |
|
52 | - } |
|
15 | + /** |
|
16 | + * @var int $id The post/page/term/user ID. |
|
17 | + */ |
|
18 | + private $id; |
|
19 | + |
|
20 | + /** |
|
21 | + * @var Object_Type_Enum $type The content type, post/page/term/user. |
|
22 | + */ |
|
23 | + private $type; |
|
24 | + |
|
25 | + public static function create_post( $id ) { |
|
26 | + return new self( $id, Object_Type_Enum::POST ); |
|
27 | + } |
|
28 | + |
|
29 | + public static function create_term( $id ) { |
|
30 | + return new self( $id, Object_Type_Enum::TERM ); |
|
31 | + } |
|
32 | + |
|
33 | + public static function create_user( $id ) { |
|
34 | + return new self( $id, Object_Type_Enum::USER ); |
|
35 | + } |
|
36 | + |
|
37 | + /** |
|
38 | + * @param int $id The post/page/term/user ID. |
|
39 | + * @param int $type The content type, post/page/term/user. |
|
40 | + */ |
|
41 | + public function __construct( $id, $type ) { |
|
42 | + $this->id = $id; |
|
43 | + $this->type = $type; |
|
44 | + } |
|
45 | + |
|
46 | + public function get_id() { |
|
47 | + return $this->id; |
|
48 | + } |
|
49 | + |
|
50 | + public function get_type() { |
|
51 | + return $this->type; |
|
52 | + } |
|
53 | 53 | |
54 | 54 | } |
@@ -13,33 +13,33 @@ |
||
13 | 13 | } |
14 | 14 | |
15 | 15 | protected function get_dataset_uri() { |
16 | - return trailingslashit( Wordlift_Configuration_Service::get_instance()->get_dataset_uri() ); |
|
16 | + return trailingslashit(Wordlift_Configuration_Service::get_instance()->get_dataset_uri()); |
|
17 | 17 | } |
18 | 18 | |
19 | - protected function is_absolute( $uri ) { |
|
20 | - return 1 === preg_match( '@^https?://@', $uri ); |
|
19 | + protected function is_absolute($uri) { |
|
20 | + return 1 === preg_match('@^https?://@', $uri); |
|
21 | 21 | } |
22 | 22 | |
23 | - protected function is_internal( $uri ) { |
|
23 | + protected function is_internal($uri) { |
|
24 | 24 | $dataset_uri = $this->get_dataset_uri(); |
25 | 25 | |
26 | - return ! empty( $dataset_uri ) && 0 === strpos( $uri, $dataset_uri ); |
|
26 | + return ! empty($dataset_uri) && 0 === strpos($uri, $dataset_uri); |
|
27 | 27 | } |
28 | 28 | |
29 | - protected function make_absolute( $uri ) { |
|
30 | - Assertions::not_empty( $this->get_dataset_uri(), '`dataset_uri` cannot be empty.' ); |
|
29 | + protected function make_absolute($uri) { |
|
30 | + Assertions::not_empty($this->get_dataset_uri(), '`dataset_uri` cannot be empty.'); |
|
31 | 31 | |
32 | - if ( 1 !== preg_match( '@^https?://@', $uri ) ) { |
|
33 | - return $this->get_dataset_uri() . $uri; |
|
32 | + if (1 !== preg_match('@^https?://@', $uri)) { |
|
33 | + return $this->get_dataset_uri().$uri; |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | return $uri; |
37 | 37 | } |
38 | 38 | |
39 | - protected function make_relative( $uri ) { |
|
39 | + protected function make_relative($uri) { |
|
40 | 40 | $dataset_uri = $this->get_dataset_uri(); |
41 | - if ( 0 === strpos( $uri, $dataset_uri ) ) { |
|
42 | - return substr( $uri, strlen( $dataset_uri ) ); |
|
41 | + if (0 === strpos($uri, $dataset_uri)) { |
|
42 | + return substr($uri, strlen($dataset_uri)); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | return $uri; |
@@ -9,41 +9,41 @@ |
||
9 | 9 | // phpcs:ignore WordPress.WP.CapitalPDangit.MisspelledClassName |
10 | 10 | abstract class Abstract_Wordpress_Content_Service implements Content_Service { |
11 | 11 | |
12 | - protected function __construct() { |
|
12 | + protected function __construct() { |
|
13 | 13 | |
14 | - } |
|
14 | + } |
|
15 | 15 | |
16 | - protected function get_dataset_uri() { |
|
17 | - return trailingslashit( Wordlift_Configuration_Service::get_instance()->get_dataset_uri() ); |
|
18 | - } |
|
16 | + protected function get_dataset_uri() { |
|
17 | + return trailingslashit( Wordlift_Configuration_Service::get_instance()->get_dataset_uri() ); |
|
18 | + } |
|
19 | 19 | |
20 | - protected function is_absolute( $uri ) { |
|
21 | - return 1 === preg_match( '@^https?://@', $uri ); |
|
22 | - } |
|
20 | + protected function is_absolute( $uri ) { |
|
21 | + return 1 === preg_match( '@^https?://@', $uri ); |
|
22 | + } |
|
23 | 23 | |
24 | - protected function is_internal( $uri ) { |
|
25 | - $dataset_uri = $this->get_dataset_uri(); |
|
24 | + protected function is_internal( $uri ) { |
|
25 | + $dataset_uri = $this->get_dataset_uri(); |
|
26 | 26 | |
27 | - return ! empty( $dataset_uri ) && 0 === strpos( $uri, $dataset_uri ); |
|
28 | - } |
|
27 | + return ! empty( $dataset_uri ) && 0 === strpos( $uri, $dataset_uri ); |
|
28 | + } |
|
29 | 29 | |
30 | - protected function make_absolute( $uri ) { |
|
31 | - Assertions::not_empty( $this->get_dataset_uri(), '`dataset_uri` cannot be empty.' ); |
|
30 | + protected function make_absolute( $uri ) { |
|
31 | + Assertions::not_empty( $this->get_dataset_uri(), '`dataset_uri` cannot be empty.' ); |
|
32 | 32 | |
33 | - if ( 1 !== preg_match( '@^https?://@', $uri ) ) { |
|
34 | - return $this->get_dataset_uri() . $uri; |
|
35 | - } |
|
33 | + if ( 1 !== preg_match( '@^https?://@', $uri ) ) { |
|
34 | + return $this->get_dataset_uri() . $uri; |
|
35 | + } |
|
36 | 36 | |
37 | - return $uri; |
|
38 | - } |
|
37 | + return $uri; |
|
38 | + } |
|
39 | 39 | |
40 | - protected function make_relative( $uri ) { |
|
41 | - $dataset_uri = $this->get_dataset_uri(); |
|
42 | - if ( 0 === strpos( $uri, $dataset_uri ) ) { |
|
43 | - return substr( $uri, strlen( $dataset_uri ) ); |
|
44 | - } |
|
40 | + protected function make_relative( $uri ) { |
|
41 | + $dataset_uri = $this->get_dataset_uri(); |
|
42 | + if ( 0 === strpos( $uri, $dataset_uri ) ) { |
|
43 | + return substr( $uri, strlen( $dataset_uri ) ); |
|
44 | + } |
|
45 | 45 | |
46 | - return $uri; |
|
47 | - } |
|
46 | + return $uri; |
|
47 | + } |
|
48 | 48 | |
49 | 49 | } |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | private static $instance = null; |
29 | 29 | |
30 | 30 | public static function get_instance() { |
31 | - if ( ! isset( self::$instance ) ) { |
|
31 | + if ( ! isset(self::$instance)) { |
|
32 | 32 | self::$instance = new self(); |
33 | 33 | |
34 | 34 | $providers = array( |
@@ -39,16 +39,16 @@ discard block |
||
39 | 39 | new Term_Entity_Provider(), |
40 | 40 | ); |
41 | 41 | |
42 | - foreach ( apply_filters( 'wl_analysis_entity_providers', $providers ) as $provider ) { |
|
43 | - self::$instance->register_provider( $provider ); |
|
42 | + foreach (apply_filters('wl_analysis_entity_providers', $providers) as $provider) { |
|
43 | + self::$instance->register_provider($provider); |
|
44 | 44 | } |
45 | 45 | } |
46 | 46 | |
47 | 47 | return self::$instance; |
48 | 48 | } |
49 | 49 | |
50 | - public function register_provider( $provider ) { |
|
51 | - Assertions::is_a( $provider, 'Wordlift\Analysis\Entity_Provider\Entity_Provider', '`provider` must implement the `Wordlift\Analysis\Entity_Provider` interface.' ); |
|
50 | + public function register_provider($provider) { |
|
51 | + Assertions::is_a($provider, 'Wordlift\Analysis\Entity_Provider\Entity_Provider', '`provider` must implement the `Wordlift\Analysis\Entity_Provider` interface.'); |
|
52 | 52 | |
53 | 53 | $this->entity_providers[] = $provider; |
54 | 54 | } |
@@ -59,15 +59,15 @@ discard block |
||
59 | 59 | * |
60 | 60 | * @return array|bool |
61 | 61 | */ |
62 | - public function get_local_entity( $uri ) { |
|
62 | + public function get_local_entity($uri) { |
|
63 | 63 | |
64 | - if ( count( $this->entity_providers ) === 0 ) { |
|
64 | + if (count($this->entity_providers) === 0) { |
|
65 | 65 | return false; |
66 | 66 | } |
67 | 67 | |
68 | - foreach ( $this->entity_providers as $entity_provider ) { |
|
69 | - $entity_data = $entity_provider->get_entity( $uri ); |
|
70 | - if ( $entity_data ) { |
|
68 | + foreach ($this->entity_providers as $entity_provider) { |
|
69 | + $entity_data = $entity_provider->get_entity($uri); |
|
70 | + if ($entity_data) { |
|
71 | 71 | return $entity_data; |
72 | 72 | } |
73 | 73 | } |
@@ -17,62 +17,62 @@ |
||
17 | 17 | |
18 | 18 | class Entity_Provider_Registry { |
19 | 19 | |
20 | - /** |
|
21 | - * @var Entity_Provider[] |
|
22 | - */ |
|
23 | - private $entity_providers = array(); |
|
24 | - |
|
25 | - protected function __construct() { |
|
26 | - } |
|
27 | - |
|
28 | - private static $instance = null; |
|
29 | - |
|
30 | - public static function get_instance() { |
|
31 | - if ( ! isset( self::$instance ) ) { |
|
32 | - self::$instance = new self(); |
|
33 | - |
|
34 | - $providers = array( |
|
35 | - new Post_Entity_Provider( |
|
36 | - Wordlift_Entity_Uri_Service::get_instance(), |
|
37 | - Wordlift_Entity_Type_Service::get_instance(), |
|
38 | - new Wordlift_Post_Image_Storage() |
|
39 | - ), |
|
40 | - new Term_Entity_Provider(), |
|
41 | - ); |
|
42 | - |
|
43 | - foreach ( apply_filters( 'wl_analysis_entity_providers', $providers ) as $provider ) { |
|
44 | - self::$instance->register_provider( $provider ); |
|
45 | - } |
|
46 | - } |
|
47 | - |
|
48 | - return self::$instance; |
|
49 | - } |
|
50 | - |
|
51 | - public function register_provider( $provider ) { |
|
52 | - Assertions::is_a( $provider, 'Wordlift\Analysis\Entity_Provider\Entity_Provider', '`provider` must implement the `Wordlift\Analysis\Entity_Provider` interface.' ); |
|
53 | - |
|
54 | - $this->entity_providers[] = $provider; |
|
55 | - } |
|
56 | - |
|
57 | - /** |
|
58 | - * @param $uri |
|
59 | - * |
|
60 | - * @return array|bool |
|
61 | - */ |
|
62 | - public function get_local_entity( $uri ) { |
|
63 | - |
|
64 | - if ( count( $this->entity_providers ) === 0 ) { |
|
65 | - return false; |
|
66 | - } |
|
67 | - |
|
68 | - foreach ( $this->entity_providers as $entity_provider ) { |
|
69 | - $entity_data = $entity_provider->get_entity( $uri ); |
|
70 | - if ( $entity_data ) { |
|
71 | - return $entity_data; |
|
72 | - } |
|
73 | - } |
|
74 | - |
|
75 | - return false; |
|
76 | - } |
|
20 | + /** |
|
21 | + * @var Entity_Provider[] |
|
22 | + */ |
|
23 | + private $entity_providers = array(); |
|
24 | + |
|
25 | + protected function __construct() { |
|
26 | + } |
|
27 | + |
|
28 | + private static $instance = null; |
|
29 | + |
|
30 | + public static function get_instance() { |
|
31 | + if ( ! isset( self::$instance ) ) { |
|
32 | + self::$instance = new self(); |
|
33 | + |
|
34 | + $providers = array( |
|
35 | + new Post_Entity_Provider( |
|
36 | + Wordlift_Entity_Uri_Service::get_instance(), |
|
37 | + Wordlift_Entity_Type_Service::get_instance(), |
|
38 | + new Wordlift_Post_Image_Storage() |
|
39 | + ), |
|
40 | + new Term_Entity_Provider(), |
|
41 | + ); |
|
42 | + |
|
43 | + foreach ( apply_filters( 'wl_analysis_entity_providers', $providers ) as $provider ) { |
|
44 | + self::$instance->register_provider( $provider ); |
|
45 | + } |
|
46 | + } |
|
47 | + |
|
48 | + return self::$instance; |
|
49 | + } |
|
50 | + |
|
51 | + public function register_provider( $provider ) { |
|
52 | + Assertions::is_a( $provider, 'Wordlift\Analysis\Entity_Provider\Entity_Provider', '`provider` must implement the `Wordlift\Analysis\Entity_Provider` interface.' ); |
|
53 | + |
|
54 | + $this->entity_providers[] = $provider; |
|
55 | + } |
|
56 | + |
|
57 | + /** |
|
58 | + * @param $uri |
|
59 | + * |
|
60 | + * @return array|bool |
|
61 | + */ |
|
62 | + public function get_local_entity( $uri ) { |
|
63 | + |
|
64 | + if ( count( $this->entity_providers ) === 0 ) { |
|
65 | + return false; |
|
66 | + } |
|
67 | + |
|
68 | + foreach ( $this->entity_providers as $entity_provider ) { |
|
69 | + $entity_data = $entity_provider->get_entity( $uri ); |
|
70 | + if ( $entity_data ) { |
|
71 | + return $entity_data; |
|
72 | + } |
|
73 | + } |
|
74 | + |
|
75 | + return false; |
|
76 | + } |
|
77 | 77 | |
78 | 78 | } |
@@ -17,9 +17,9 @@ |
||
17 | 17 | * @return Content_Service |
18 | 18 | */ |
19 | 19 | public static function get_instance() { |
20 | - if ( ! isset( self::$instance ) ) { |
|
20 | + if ( ! isset(self::$instance)) { |
|
21 | 21 | |
22 | - if ( apply_filters( 'wl_feature__enable__dataset', true ) ) { |
|
22 | + if (apply_filters('wl_feature__enable__dataset', true)) { |
|
23 | 23 | self::$instance = Wordpress_Dataset_Content_Service::get_instance(); |
24 | 24 | } else { |
25 | 25 | self::$instance = Wordpress_Permalink_Content_Service::get_instance(); |
@@ -7,27 +7,27 @@ |
||
7 | 7 | // phpcs:ignore WordPress.WP.CapitalPDangit.MisspelledClassName |
8 | 8 | class Wordpress_Content_Service { |
9 | 9 | |
10 | - protected function __construct() { |
|
11 | - } |
|
12 | - |
|
13 | - private static $instance = null; |
|
14 | - |
|
15 | - /** |
|
16 | - * The singleton instance. |
|
17 | - * |
|
18 | - * @return Content_Service |
|
19 | - */ |
|
20 | - public static function get_instance() { |
|
21 | - if ( ! isset( self::$instance ) ) { |
|
22 | - |
|
23 | - if ( apply_filters( 'wl_feature__enable__dataset', true ) ) { |
|
24 | - self::$instance = Wordpress_Dataset_Content_Service::get_instance(); |
|
25 | - } else { |
|
26 | - self::$instance = Wordpress_Permalink_Content_Service::get_instance(); |
|
27 | - } |
|
28 | - } |
|
29 | - |
|
30 | - return self::$instance; |
|
31 | - } |
|
10 | + protected function __construct() { |
|
11 | + } |
|
12 | + |
|
13 | + private static $instance = null; |
|
14 | + |
|
15 | + /** |
|
16 | + * The singleton instance. |
|
17 | + * |
|
18 | + * @return Content_Service |
|
19 | + */ |
|
20 | + public static function get_instance() { |
|
21 | + if ( ! isset( self::$instance ) ) { |
|
22 | + |
|
23 | + if ( apply_filters( 'wl_feature__enable__dataset', true ) ) { |
|
24 | + self::$instance = Wordpress_Dataset_Content_Service::get_instance(); |
|
25 | + } else { |
|
26 | + self::$instance = Wordpress_Permalink_Content_Service::get_instance(); |
|
27 | + } |
|
28 | + } |
|
29 | + |
|
30 | + return self::$instance; |
|
31 | + } |
|
32 | 32 | |
33 | 33 | } |
@@ -15,41 +15,41 @@ discard block |
||
15 | 15 | |
16 | 16 | class Post_Entity_Provider implements Entity_Provider { |
17 | 17 | |
18 | - /** |
|
19 | - * @var \Wordlift_Entity_Uri_Service |
|
20 | - */ |
|
21 | - private $entity_uri_service; |
|
22 | - /** |
|
23 | - * @var \Wordlift_Entity_Type_Service |
|
24 | - */ |
|
25 | - private $entity_type_service; |
|
26 | - /** |
|
27 | - * @var \Wordlift_Post_Image_Storage |
|
28 | - */ |
|
29 | - private $post_image_storage; |
|
18 | + /** |
|
19 | + * @var \Wordlift_Entity_Uri_Service |
|
20 | + */ |
|
21 | + private $entity_uri_service; |
|
22 | + /** |
|
23 | + * @var \Wordlift_Entity_Type_Service |
|
24 | + */ |
|
25 | + private $entity_type_service; |
|
26 | + /** |
|
27 | + * @var \Wordlift_Post_Image_Storage |
|
28 | + */ |
|
29 | + private $post_image_storage; |
|
30 | 30 | |
31 | - public function __construct( $entity_uri_service, $entity_type_service, $post_image_storage ) { |
|
32 | - $this->entity_uri_service = $entity_uri_service; |
|
33 | - $this->entity_type_service = $entity_type_service; |
|
34 | - $this->post_image_storage = $post_image_storage; |
|
35 | - } |
|
31 | + public function __construct( $entity_uri_service, $entity_type_service, $post_image_storage ) { |
|
32 | + $this->entity_uri_service = $entity_uri_service; |
|
33 | + $this->entity_type_service = $entity_type_service; |
|
34 | + $this->post_image_storage = $post_image_storage; |
|
35 | + } |
|
36 | 36 | |
37 | 37 | |
38 | - public function get_entity( $uri ) { |
|
39 | - $content = Wordpress_Content_Service::get_instance()->get_by_entity_id_or_same_as( $uri ); |
|
38 | + public function get_entity( $uri ) { |
|
39 | + $content = Wordpress_Content_Service::get_instance()->get_by_entity_id_or_same_as( $uri ); |
|
40 | 40 | |
41 | - if ( ! isset( $content ) || ! is_a( $content->get_bag(), '\WP_Post' ) ) { |
|
42 | - return false; |
|
43 | - } |
|
41 | + if ( ! isset( $content ) || ! is_a( $content->get_bag(), '\WP_Post' ) ) { |
|
42 | + return false; |
|
43 | + } |
|
44 | 44 | |
45 | - $entity = $content->get_bag(); |
|
46 | - $type = $this->entity_type_service->get( $entity->ID ); |
|
47 | - $images = $this->post_image_storage->get( $entity->ID ); |
|
45 | + $entity = $content->get_bag(); |
|
46 | + $type = $this->entity_type_service->get( $entity->ID ); |
|
47 | + $images = $this->post_image_storage->get( $entity->ID ); |
|
48 | 48 | |
49 | - return (object) array( |
|
50 | - 'id' => $uri, |
|
51 | - 'label' => $entity->post_title, |
|
52 | - /* |
|
49 | + return (object) array( |
|
50 | + 'id' => $uri, |
|
51 | + 'label' => $entity->post_title, |
|
52 | + /* |
|
53 | 53 | * As of 2020.06.29 we're comment out the `post_content` because Gutenberg posts will return here |
54 | 54 | * the whole Gutenberg source including potentially our own wordlift/classification block, which means |
55 | 55 | * that data may grow quickly to more than a 100 KBytes and could break web servers. |
@@ -61,13 +61,13 @@ discard block |
||
61 | 61 | * |
62 | 62 | * PS: We didn't test using the WordLift Post Excerpt Helper. |
63 | 63 | */ |
64 | - // 'description' => $entity->post_content, |
|
65 | - 'description' => '', |
|
66 | - 'sameAs' => wl_schema_get_value( $entity->ID, 'sameAs' ), |
|
67 | - 'mainType' => str_replace( 'wl-', '', $type['css_class'] ), |
|
68 | - 'types' => wl_get_entity_rdf_types( $entity->ID ), |
|
69 | - 'images' => $images, |
|
70 | - ); |
|
71 | - } |
|
64 | + // 'description' => $entity->post_content, |
|
65 | + 'description' => '', |
|
66 | + 'sameAs' => wl_schema_get_value( $entity->ID, 'sameAs' ), |
|
67 | + 'mainType' => str_replace( 'wl-', '', $type['css_class'] ), |
|
68 | + 'types' => wl_get_entity_rdf_types( $entity->ID ), |
|
69 | + 'images' => $images, |
|
70 | + ); |
|
71 | + } |
|
72 | 72 | |
73 | 73 | } |
@@ -28,23 +28,23 @@ discard block |
||
28 | 28 | */ |
29 | 29 | private $post_image_storage; |
30 | 30 | |
31 | - public function __construct( $entity_uri_service, $entity_type_service, $post_image_storage ) { |
|
31 | + public function __construct($entity_uri_service, $entity_type_service, $post_image_storage) { |
|
32 | 32 | $this->entity_uri_service = $entity_uri_service; |
33 | 33 | $this->entity_type_service = $entity_type_service; |
34 | 34 | $this->post_image_storage = $post_image_storage; |
35 | 35 | } |
36 | 36 | |
37 | 37 | |
38 | - public function get_entity( $uri ) { |
|
39 | - $content = Wordpress_Content_Service::get_instance()->get_by_entity_id_or_same_as( $uri ); |
|
38 | + public function get_entity($uri) { |
|
39 | + $content = Wordpress_Content_Service::get_instance()->get_by_entity_id_or_same_as($uri); |
|
40 | 40 | |
41 | - if ( ! isset( $content ) || ! is_a( $content->get_bag(), '\WP_Post' ) ) { |
|
41 | + if ( ! isset($content) || ! is_a($content->get_bag(), '\WP_Post')) { |
|
42 | 42 | return false; |
43 | 43 | } |
44 | 44 | |
45 | 45 | $entity = $content->get_bag(); |
46 | - $type = $this->entity_type_service->get( $entity->ID ); |
|
47 | - $images = $this->post_image_storage->get( $entity->ID ); |
|
46 | + $type = $this->entity_type_service->get($entity->ID); |
|
47 | + $images = $this->post_image_storage->get($entity->ID); |
|
48 | 48 | |
49 | 49 | return (object) array( |
50 | 50 | 'id' => $uri, |
@@ -63,9 +63,9 @@ discard block |
||
63 | 63 | */ |
64 | 64 | // 'description' => $entity->post_content, |
65 | 65 | 'description' => '', |
66 | - 'sameAs' => wl_schema_get_value( $entity->ID, 'sameAs' ), |
|
67 | - 'mainType' => str_replace( 'wl-', '', $type['css_class'] ), |
|
68 | - 'types' => wl_get_entity_rdf_types( $entity->ID ), |
|
66 | + 'sameAs' => wl_schema_get_value($entity->ID, 'sameAs'), |
|
67 | + 'mainType' => str_replace('wl-', '', $type['css_class']), |
|
68 | + 'types' => wl_get_entity_rdf_types($entity->ID), |
|
69 | 69 | 'images' => $images, |
70 | 70 | ); |
71 | 71 | } |
@@ -19,7 +19,7 @@ |
||
19 | 19 | * @param $last_update |
20 | 20 | * @param $state |
21 | 21 | */ |
22 | - public function __construct( $state, $started = null, $index = null, $count = null, $last_update = null ) { |
|
22 | + public function __construct($state, $started = null, $index = null, $count = null, $last_update = null) { |
|
23 | 23 | $this->started = $started; |
24 | 24 | $this->index = $index; |
25 | 25 | $this->count = (int) $count; |
@@ -4,27 +4,27 @@ |
||
4 | 4 | |
5 | 5 | class Background_Task_Info { |
6 | 6 | |
7 | - public $started; |
|
8 | - public $index; |
|
9 | - public $count; |
|
10 | - public $last_update; |
|
11 | - public $state; |
|
7 | + public $started; |
|
8 | + public $index; |
|
9 | + public $count; |
|
10 | + public $last_update; |
|
11 | + public $state; |
|
12 | 12 | |
13 | - /** |
|
14 | - * Sync_Model constructor. |
|
15 | - * |
|
16 | - * @param $started |
|
17 | - * @param $index |
|
18 | - * @param $count |
|
19 | - * @param $last_update |
|
20 | - * @param $state |
|
21 | - */ |
|
22 | - public function __construct( $state, $started = null, $index = null, $count = null, $last_update = null ) { |
|
23 | - $this->started = $started; |
|
24 | - $this->index = $index; |
|
25 | - $this->count = (int) $count; |
|
26 | - $this->last_update = $last_update; |
|
27 | - $this->state = $state; |
|
28 | - } |
|
13 | + /** |
|
14 | + * Sync_Model constructor. |
|
15 | + * |
|
16 | + * @param $started |
|
17 | + * @param $index |
|
18 | + * @param $count |
|
19 | + * @param $last_update |
|
20 | + * @param $state |
|
21 | + */ |
|
22 | + public function __construct( $state, $started = null, $index = null, $count = null, $last_update = null ) { |
|
23 | + $this->started = $started; |
|
24 | + $this->index = $index; |
|
25 | + $this->count = (int) $count; |
|
26 | + $this->last_update = $last_update; |
|
27 | + $this->state = $state; |
|
28 | + } |
|
29 | 29 | |
30 | 30 | } |
@@ -34,24 +34,24 @@ discard block |
||
34 | 34 | /** |
35 | 35 | * @param Task $task |
36 | 36 | */ |
37 | - public function __construct( $task ) { |
|
38 | - $this->action = sha1( get_class( $task ) ); |
|
37 | + public function __construct($task) { |
|
38 | + $this->action = sha1(get_class($task)); |
|
39 | 39 | $this->option_prefix = "_{$this->action}_"; |
40 | 40 | |
41 | 41 | parent::__construct(); |
42 | 42 | |
43 | 43 | // Set the current state. |
44 | - if ( self::STATE_STARTED === $this->get_state() ) { |
|
45 | - $this->state = new Background_Task_Started_State( $this, $task ); |
|
44 | + if (self::STATE_STARTED === $this->get_state()) { |
|
45 | + $this->state = new Background_Task_Started_State($this, $task); |
|
46 | 46 | } else { |
47 | - $this->state = new Background_Task_Stopped_State( $this ); |
|
47 | + $this->state = new Background_Task_Stopped_State($this); |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | $this->task = $task; |
51 | 51 | } |
52 | 52 | |
53 | - public static function create( $task ) { |
|
54 | - return new self( $task ); |
|
53 | + public static function create($task) { |
|
54 | + return new self($task); |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | public function get_option_prefix() { |
@@ -69,9 +69,9 @@ discard block |
||
69 | 69 | * |
70 | 70 | * @return int[]|false The next post IDs or false if there are no more. |
71 | 71 | */ |
72 | - protected function task( $item ) { |
|
72 | + protected function task($item) { |
|
73 | 73 | |
74 | - return $this->state->task( $item ); |
|
74 | + return $this->state->task($item); |
|
75 | 75 | } |
76 | 76 | |
77 | 77 | /** |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | */ |
80 | 80 | public function start() { |
81 | 81 | $this->state->leave(); |
82 | - $this->state = new Background_Task_Started_State( $this, $this->task ); |
|
82 | + $this->state = new Background_Task_Started_State($this, $this->task); |
|
83 | 83 | $this->state->enter(); |
84 | 84 | } |
85 | 85 | |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | */ |
89 | 89 | public function stop() { |
90 | 90 | $this->state->leave(); |
91 | - $this->state = new Background_Task_Stopped_State( $this ); |
|
91 | + $this->state = new Background_Task_Stopped_State($this); |
|
92 | 92 | $this->state->enter(); |
93 | 93 | } |
94 | 94 | |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | * @return string Either self::STARTED_STATE or self::STOPPED_STATE (default). |
103 | 103 | */ |
104 | 104 | public function get_state() { |
105 | - return get_option( $this->option_prefix . 'state', self::STATE_STOPPED ); |
|
105 | + return get_option($this->option_prefix.'state', self::STATE_STOPPED); |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | /** |
@@ -112,10 +112,10 @@ discard block |
||
112 | 112 | * |
113 | 113 | * @return bool |
114 | 114 | */ |
115 | - public function set_state( $value ) { |
|
115 | + public function set_state($value) { |
|
116 | 116 | return null === $value |
117 | - ? delete_option( $this->option_prefix . 'state' ) |
|
118 | - : update_option( $this->option_prefix . 'state', $value, true ); |
|
117 | + ? delete_option($this->option_prefix.'state') |
|
118 | + : update_option($this->option_prefix.'state', $value, true); |
|
119 | 119 | } |
120 | 120 | |
121 | 121 | public function get_info() { |
@@ -7,119 +7,119 @@ |
||
7 | 7 | |
8 | 8 | class Background_Task extends Wordlift_Plugin_WP_Background_Process { |
9 | 9 | |
10 | - const STATE_STARTED = 'started'; |
|
11 | - const STATE_STOPPED = 'stopped'; |
|
12 | - |
|
13 | - /** |
|
14 | - * The current state of the task, started or stopped. |
|
15 | - * |
|
16 | - * @var Background_Task_State $state |
|
17 | - */ |
|
18 | - private $state; |
|
19 | - |
|
20 | - /** |
|
21 | - * The actual task. |
|
22 | - * |
|
23 | - * @var Task $task |
|
24 | - */ |
|
25 | - private $task; |
|
26 | - |
|
27 | - /** |
|
28 | - * The prefix to store the state and other information in WP's options table, determined at instantiation. |
|
29 | - * |
|
30 | - * @var string $option_prefix |
|
31 | - */ |
|
32 | - private $option_prefix; |
|
33 | - |
|
34 | - /** |
|
35 | - * @param Task $task |
|
36 | - */ |
|
37 | - public function __construct( $task ) { |
|
38 | - $this->action = sha1( get_class( $task ) ); |
|
39 | - $this->option_prefix = "_{$this->action}_"; |
|
40 | - |
|
41 | - parent::__construct(); |
|
42 | - |
|
43 | - // Set the current state. |
|
44 | - if ( self::STATE_STARTED === $this->get_state() ) { |
|
45 | - $this->state = new Background_Task_Started_State( $this, $task ); |
|
46 | - } else { |
|
47 | - $this->state = new Background_Task_Stopped_State( $this ); |
|
48 | - } |
|
49 | - |
|
50 | - $this->task = $task; |
|
51 | - } |
|
52 | - |
|
53 | - public static function create( $task ) { |
|
54 | - return new self( $task ); |
|
55 | - } |
|
56 | - |
|
57 | - public function get_option_prefix() { |
|
58 | - return $this->option_prefix; |
|
59 | - } |
|
60 | - |
|
61 | - /** |
|
62 | - * This function is called: |
|
63 | - * - To start a new Synchronization, by passing a {@link Sync_Start_Message} instance. |
|
64 | - * - To synchronize a post, by passing a numeric ID. |
|
65 | - * |
|
66 | - * This function returns the parameter for the next call or NULL if there are no more posts to process. |
|
67 | - * |
|
68 | - * @param mixed $item Queue item to iterate over. |
|
69 | - * |
|
70 | - * @return int[]|false The next post IDs or false if there are no more. |
|
71 | - */ |
|
72 | - protected function task( $item ) { |
|
73 | - |
|
74 | - return $this->state->task( $item ); |
|
75 | - } |
|
76 | - |
|
77 | - /** |
|
78 | - * Transition to the started state. |
|
79 | - */ |
|
80 | - public function start() { |
|
81 | - $this->state->leave(); |
|
82 | - $this->state = new Background_Task_Started_State( $this, $this->task ); |
|
83 | - $this->state->enter(); |
|
84 | - } |
|
85 | - |
|
86 | - /** |
|
87 | - * Transition to the stopped state. |
|
88 | - */ |
|
89 | - public function stop() { |
|
90 | - $this->state->leave(); |
|
91 | - $this->state = new Background_Task_Stopped_State( $this ); |
|
92 | - $this->state->enter(); |
|
93 | - } |
|
94 | - |
|
95 | - public function resume() { |
|
96 | - $this->state->resume(); |
|
97 | - } |
|
98 | - |
|
99 | - /** |
|
100 | - * Get the current state. |
|
101 | - * |
|
102 | - * @return string Either self::STARTED_STATE or self::STOPPED_STATE (default). |
|
103 | - */ |
|
104 | - public function get_state() { |
|
105 | - return get_option( $this->option_prefix . 'state', self::STATE_STOPPED ); |
|
106 | - } |
|
107 | - |
|
108 | - /** |
|
109 | - * Persist the current state. |
|
110 | - * |
|
111 | - * @param string $value |
|
112 | - * |
|
113 | - * @return bool |
|
114 | - */ |
|
115 | - public function set_state( $value ) { |
|
116 | - return null === $value |
|
117 | - ? delete_option( $this->option_prefix . 'state' ) |
|
118 | - : update_option( $this->option_prefix . 'state', $value, true ); |
|
119 | - } |
|
120 | - |
|
121 | - public function get_info() { |
|
122 | - return $this->state->get_info(); |
|
123 | - } |
|
10 | + const STATE_STARTED = 'started'; |
|
11 | + const STATE_STOPPED = 'stopped'; |
|
12 | + |
|
13 | + /** |
|
14 | + * The current state of the task, started or stopped. |
|
15 | + * |
|
16 | + * @var Background_Task_State $state |
|
17 | + */ |
|
18 | + private $state; |
|
19 | + |
|
20 | + /** |
|
21 | + * The actual task. |
|
22 | + * |
|
23 | + * @var Task $task |
|
24 | + */ |
|
25 | + private $task; |
|
26 | + |
|
27 | + /** |
|
28 | + * The prefix to store the state and other information in WP's options table, determined at instantiation. |
|
29 | + * |
|
30 | + * @var string $option_prefix |
|
31 | + */ |
|
32 | + private $option_prefix; |
|
33 | + |
|
34 | + /** |
|
35 | + * @param Task $task |
|
36 | + */ |
|
37 | + public function __construct( $task ) { |
|
38 | + $this->action = sha1( get_class( $task ) ); |
|
39 | + $this->option_prefix = "_{$this->action}_"; |
|
40 | + |
|
41 | + parent::__construct(); |
|
42 | + |
|
43 | + // Set the current state. |
|
44 | + if ( self::STATE_STARTED === $this->get_state() ) { |
|
45 | + $this->state = new Background_Task_Started_State( $this, $task ); |
|
46 | + } else { |
|
47 | + $this->state = new Background_Task_Stopped_State( $this ); |
|
48 | + } |
|
49 | + |
|
50 | + $this->task = $task; |
|
51 | + } |
|
52 | + |
|
53 | + public static function create( $task ) { |
|
54 | + return new self( $task ); |
|
55 | + } |
|
56 | + |
|
57 | + public function get_option_prefix() { |
|
58 | + return $this->option_prefix; |
|
59 | + } |
|
60 | + |
|
61 | + /** |
|
62 | + * This function is called: |
|
63 | + * - To start a new Synchronization, by passing a {@link Sync_Start_Message} instance. |
|
64 | + * - To synchronize a post, by passing a numeric ID. |
|
65 | + * |
|
66 | + * This function returns the parameter for the next call or NULL if there are no more posts to process. |
|
67 | + * |
|
68 | + * @param mixed $item Queue item to iterate over. |
|
69 | + * |
|
70 | + * @return int[]|false The next post IDs or false if there are no more. |
|
71 | + */ |
|
72 | + protected function task( $item ) { |
|
73 | + |
|
74 | + return $this->state->task( $item ); |
|
75 | + } |
|
76 | + |
|
77 | + /** |
|
78 | + * Transition to the started state. |
|
79 | + */ |
|
80 | + public function start() { |
|
81 | + $this->state->leave(); |
|
82 | + $this->state = new Background_Task_Started_State( $this, $this->task ); |
|
83 | + $this->state->enter(); |
|
84 | + } |
|
85 | + |
|
86 | + /** |
|
87 | + * Transition to the stopped state. |
|
88 | + */ |
|
89 | + public function stop() { |
|
90 | + $this->state->leave(); |
|
91 | + $this->state = new Background_Task_Stopped_State( $this ); |
|
92 | + $this->state->enter(); |
|
93 | + } |
|
94 | + |
|
95 | + public function resume() { |
|
96 | + $this->state->resume(); |
|
97 | + } |
|
98 | + |
|
99 | + /** |
|
100 | + * Get the current state. |
|
101 | + * |
|
102 | + * @return string Either self::STARTED_STATE or self::STOPPED_STATE (default). |
|
103 | + */ |
|
104 | + public function get_state() { |
|
105 | + return get_option( $this->option_prefix . 'state', self::STATE_STOPPED ); |
|
106 | + } |
|
107 | + |
|
108 | + /** |
|
109 | + * Persist the current state. |
|
110 | + * |
|
111 | + * @param string $value |
|
112 | + * |
|
113 | + * @return bool |
|
114 | + */ |
|
115 | + public function set_state( $value ) { |
|
116 | + return null === $value |
|
117 | + ? delete_option( $this->option_prefix . 'state' ) |
|
118 | + : update_option( $this->option_prefix . 'state', $value, true ); |
|
119 | + } |
|
120 | + |
|
121 | + public function get_info() { |
|
122 | + return $this->state->get_info(); |
|
123 | + } |
|
124 | 124 | |
125 | 125 | } |