@@ -14,70 +14,70 @@ |
||
14 | 14 | */ |
15 | 15 | class Reconcile_Progress_Endpoint { |
16 | 16 | |
17 | - public function register_routes() { |
|
18 | - $that = $this; |
|
19 | - add_action( |
|
20 | - 'rest_api_init', |
|
21 | - function () use ( $that ) { |
|
22 | - $that->register_progress_route(); |
|
23 | - } |
|
24 | - ); |
|
25 | - } |
|
17 | + public function register_routes() { |
|
18 | + $that = $this; |
|
19 | + add_action( |
|
20 | + 'rest_api_init', |
|
21 | + function () use ( $that ) { |
|
22 | + $that->register_progress_route(); |
|
23 | + } |
|
24 | + ); |
|
25 | + } |
|
26 | 26 | |
27 | - public function progress() { |
|
27 | + public function progress() { |
|
28 | 28 | |
29 | - $total_tags = count( |
|
30 | - Terms_Compat::get_terms( |
|
31 | - Terms_Compat::get_public_taxonomies(), |
|
32 | - array( |
|
33 | - 'hide_empty' => false, |
|
34 | - 'fields' => 'ids', |
|
35 | - 'meta_query' => array( |
|
36 | - array( |
|
37 | - 'key' => Analysis_Background_Service::ENTITIES_PRESENT_FOR_TERM, |
|
38 | - 'compare' => '=', |
|
39 | - 'value' => '1', |
|
40 | - ), |
|
41 | - ), |
|
42 | - ) |
|
43 | - ) |
|
44 | - ); |
|
29 | + $total_tags = count( |
|
30 | + Terms_Compat::get_terms( |
|
31 | + Terms_Compat::get_public_taxonomies(), |
|
32 | + array( |
|
33 | + 'hide_empty' => false, |
|
34 | + 'fields' => 'ids', |
|
35 | + 'meta_query' => array( |
|
36 | + array( |
|
37 | + 'key' => Analysis_Background_Service::ENTITIES_PRESENT_FOR_TERM, |
|
38 | + 'compare' => '=', |
|
39 | + 'value' => '1', |
|
40 | + ), |
|
41 | + ), |
|
42 | + ) |
|
43 | + ) |
|
44 | + ); |
|
45 | 45 | |
46 | - $completed = count( |
|
47 | - Terms_Compat::get_terms( |
|
48 | - Terms_Compat::get_public_taxonomies(), |
|
49 | - array( |
|
50 | - 'hide_empty' => false, |
|
51 | - 'fields' => 'ids', |
|
52 | - 'meta_query' => array( |
|
53 | - array( |
|
54 | - 'key' => Entity_Rest_Endpoint::IGNORE_TAG_FROM_LISTING, |
|
55 | - 'compare' => '=', |
|
56 | - 'value' => '1', |
|
57 | - ), |
|
58 | - ), |
|
59 | - ) |
|
60 | - ) |
|
61 | - ); |
|
46 | + $completed = count( |
|
47 | + Terms_Compat::get_terms( |
|
48 | + Terms_Compat::get_public_taxonomies(), |
|
49 | + array( |
|
50 | + 'hide_empty' => false, |
|
51 | + 'fields' => 'ids', |
|
52 | + 'meta_query' => array( |
|
53 | + array( |
|
54 | + 'key' => Entity_Rest_Endpoint::IGNORE_TAG_FROM_LISTING, |
|
55 | + 'compare' => '=', |
|
56 | + 'value' => '1', |
|
57 | + ), |
|
58 | + ), |
|
59 | + ) |
|
60 | + ) |
|
61 | + ); |
|
62 | 62 | |
63 | - return array( |
|
64 | - 'completed' => $completed, |
|
65 | - 'total' => $total_tags, |
|
66 | - ); |
|
67 | - } |
|
63 | + return array( |
|
64 | + 'completed' => $completed, |
|
65 | + 'total' => $total_tags, |
|
66 | + ); |
|
67 | + } |
|
68 | 68 | |
69 | - private function register_progress_route() { |
|
70 | - register_rest_route( |
|
71 | - Api_Config::REST_NAMESPACE, |
|
72 | - '/reconcile_progress/progress', |
|
73 | - array( |
|
74 | - 'methods' => \WP_REST_Server::CREATABLE, |
|
75 | - 'callback' => array( $this, 'progress' ), |
|
76 | - 'permission_callback' => function () { |
|
77 | - return current_user_can( 'manage_options' ); |
|
78 | - }, |
|
79 | - ) |
|
80 | - ); |
|
81 | - } |
|
69 | + private function register_progress_route() { |
|
70 | + register_rest_route( |
|
71 | + Api_Config::REST_NAMESPACE, |
|
72 | + '/reconcile_progress/progress', |
|
73 | + array( |
|
74 | + 'methods' => \WP_REST_Server::CREATABLE, |
|
75 | + 'callback' => array( $this, 'progress' ), |
|
76 | + 'permission_callback' => function () { |
|
77 | + return current_user_can( 'manage_options' ); |
|
78 | + }, |
|
79 | + ) |
|
80 | + ); |
|
81 | + } |
|
82 | 82 | |
83 | 83 | } |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | $that = $this; |
19 | 19 | add_action( |
20 | 20 | 'rest_api_init', |
21 | - function () use ( $that ) { |
|
21 | + function() use ($that) { |
|
22 | 22 | $that->register_progress_route(); |
23 | 23 | } |
24 | 24 | ); |
@@ -72,9 +72,9 @@ discard block |
||
72 | 72 | '/reconcile_progress/progress', |
73 | 73 | array( |
74 | 74 | 'methods' => \WP_REST_Server::CREATABLE, |
75 | - 'callback' => array( $this, 'progress' ), |
|
76 | - 'permission_callback' => function () { |
|
77 | - return current_user_can( 'manage_options' ); |
|
75 | + 'callback' => array($this, 'progress'), |
|
76 | + 'permission_callback' => function() { |
|
77 | + return current_user_can('manage_options'); |
|
78 | 78 | }, |
79 | 79 | ) |
80 | 80 | ); |
@@ -8,19 +8,19 @@ |
||
8 | 8 | */ |
9 | 9 | class Api_Config { |
10 | 10 | |
11 | - const REST_NAMESPACE = 'cafemediakg/v1'; |
|
11 | + const REST_NAMESPACE = 'cafemediakg/v1'; |
|
12 | 12 | |
13 | - public static function get_api_config() { |
|
14 | - // Create ui settings array to be used by js client. |
|
15 | - $settings = array(); |
|
16 | - $settings['restUrl'] = get_rest_url( |
|
17 | - null, |
|
18 | - self::REST_NAMESPACE . '/tags' |
|
19 | - ); |
|
20 | - $settings['baseUrl'] = get_rest_url( null, self::REST_NAMESPACE ); |
|
21 | - $settings['nonce'] = wp_create_nonce( 'wp_rest' ); |
|
13 | + public static function get_api_config() { |
|
14 | + // Create ui settings array to be used by js client. |
|
15 | + $settings = array(); |
|
16 | + $settings['restUrl'] = get_rest_url( |
|
17 | + null, |
|
18 | + self::REST_NAMESPACE . '/tags' |
|
19 | + ); |
|
20 | + $settings['baseUrl'] = get_rest_url( null, self::REST_NAMESPACE ); |
|
21 | + $settings['nonce'] = wp_create_nonce( 'wp_rest' ); |
|
22 | 22 | |
23 | - return $settings; |
|
24 | - } |
|
23 | + return $settings; |
|
24 | + } |
|
25 | 25 | |
26 | 26 | } |
@@ -15,10 +15,10 @@ |
||
15 | 15 | $settings = array(); |
16 | 16 | $settings['restUrl'] = get_rest_url( |
17 | 17 | null, |
18 | - self::REST_NAMESPACE . '/tags' |
|
18 | + self::REST_NAMESPACE.'/tags' |
|
19 | 19 | ); |
20 | - $settings['baseUrl'] = get_rest_url( null, self::REST_NAMESPACE ); |
|
21 | - $settings['nonce'] = wp_create_nonce( 'wp_rest' ); |
|
20 | + $settings['baseUrl'] = get_rest_url(null, self::REST_NAMESPACE); |
|
21 | + $settings['nonce'] = wp_create_nonce('wp_rest'); |
|
22 | 22 | |
23 | 23 | return $settings; |
24 | 24 | } |
@@ -11,109 +11,109 @@ |
||
11 | 11 | |
12 | 12 | class Post_Jsonld { |
13 | 13 | |
14 | - public function enhance_post_jsonld() { |
|
15 | - add_filter( 'wl_post_jsonld_array', array( $this, 'wl_post_jsonld_array' ), 11, 2 ); |
|
16 | - add_filter( 'wl_after_get_jsonld', array( $this, 'wl_after_get_jsonld' ), 11 ); |
|
17 | - } |
|
14 | + public function enhance_post_jsonld() { |
|
15 | + add_filter( 'wl_post_jsonld_array', array( $this, 'wl_post_jsonld_array' ), 11, 2 ); |
|
16 | + add_filter( 'wl_after_get_jsonld', array( $this, 'wl_after_get_jsonld' ), 11 ); |
|
17 | + } |
|
18 | 18 | |
19 | - public function wl_post_jsonld_array( $arr, $post_id ) { |
|
19 | + public function wl_post_jsonld_array( $arr, $post_id ) { |
|
20 | 20 | |
21 | - $jsonld = $arr['jsonld']; |
|
22 | - $references = $arr['references']; |
|
21 | + $jsonld = $arr['jsonld']; |
|
22 | + $references = $arr['references']; |
|
23 | 23 | |
24 | - $this->add_mentions( $post_id, $jsonld ); |
|
24 | + $this->add_mentions( $post_id, $jsonld ); |
|
25 | 25 | |
26 | - return array( |
|
27 | - 'jsonld' => $jsonld, |
|
28 | - 'references' => $references, |
|
29 | - ); |
|
26 | + return array( |
|
27 | + 'jsonld' => $jsonld, |
|
28 | + 'references' => $references, |
|
29 | + ); |
|
30 | 30 | |
31 | - } |
|
31 | + } |
|
32 | 32 | |
33 | - public function add_mentions( $post_id, &$jsonld ) { |
|
33 | + public function add_mentions( $post_id, &$jsonld ) { |
|
34 | 34 | |
35 | - $taxonomies = Terms_Compat::get_public_taxonomies(); |
|
36 | - $terms = array(); |
|
35 | + $taxonomies = Terms_Compat::get_public_taxonomies(); |
|
36 | + $terms = array(); |
|
37 | 37 | |
38 | - foreach ( $taxonomies as $taxonomy ) { |
|
39 | - $taxonomy_terms = get_the_terms( $post_id, $taxonomy ); |
|
40 | - if ( ! $taxonomy_terms ) { |
|
41 | - continue; |
|
42 | - } |
|
43 | - $terms = array_merge( $taxonomy_terms, $terms ); |
|
44 | - } |
|
38 | + foreach ( $taxonomies as $taxonomy ) { |
|
39 | + $taxonomy_terms = get_the_terms( $post_id, $taxonomy ); |
|
40 | + if ( ! $taxonomy_terms ) { |
|
41 | + continue; |
|
42 | + } |
|
43 | + $terms = array_merge( $taxonomy_terms, $terms ); |
|
44 | + } |
|
45 | 45 | |
46 | - if ( ! $terms ) { |
|
47 | - return; |
|
48 | - } |
|
46 | + if ( ! $terms ) { |
|
47 | + return; |
|
48 | + } |
|
49 | 49 | |
50 | - if ( ! array_key_exists( 'mentions', $jsonld ) ) { |
|
51 | - $jsonld['mentions'] = array(); |
|
52 | - } |
|
50 | + if ( ! array_key_exists( 'mentions', $jsonld ) ) { |
|
51 | + $jsonld['mentions'] = array(); |
|
52 | + } |
|
53 | 53 | |
54 | - foreach ( $terms as $term ) { |
|
54 | + foreach ( $terms as $term ) { |
|
55 | 55 | |
56 | - $is_matched = intval( get_term_meta( $term->term_id, Entity_Rest_Endpoint::IGNORE_TAG_FROM_LISTING, true ) ) === 1; |
|
56 | + $is_matched = intval( get_term_meta( $term->term_id, Entity_Rest_Endpoint::IGNORE_TAG_FROM_LISTING, true ) ) === 1; |
|
57 | 57 | |
58 | - if ( ! $is_matched ) { |
|
59 | - continue; |
|
60 | - } |
|
58 | + if ( ! $is_matched ) { |
|
59 | + continue; |
|
60 | + } |
|
61 | 61 | |
62 | - $entities = Jsonld_Utils::get_matched_entities_for_term( $term->term_id ); |
|
62 | + $entities = Jsonld_Utils::get_matched_entities_for_term( $term->term_id ); |
|
63 | 63 | |
64 | - if ( count( $entities ) === 0 ) { |
|
65 | - continue; |
|
66 | - } |
|
64 | + if ( count( $entities ) === 0 ) { |
|
65 | + continue; |
|
66 | + } |
|
67 | 67 | |
68 | - $jsonld['mentions'] = array_merge( $jsonld['mentions'], self::add_additional_attrs( $term, $entities ) ); |
|
69 | - } |
|
68 | + $jsonld['mentions'] = array_merge( $jsonld['mentions'], self::add_additional_attrs( $term, $entities ) ); |
|
69 | + } |
|
70 | 70 | |
71 | - } |
|
71 | + } |
|
72 | 72 | |
73 | - /** |
|
74 | - * @param $term \WP_Term |
|
75 | - * @param $entities |
|
76 | - * |
|
77 | - * @return array |
|
78 | - */ |
|
79 | - public static function add_additional_attrs( $term, $entities ) { |
|
73 | + /** |
|
74 | + * @param $term \WP_Term |
|
75 | + * @param $entities |
|
76 | + * |
|
77 | + * @return array |
|
78 | + */ |
|
79 | + public static function add_additional_attrs( $term, $entities ) { |
|
80 | 80 | |
81 | - return array_map( |
|
82 | - function ( $entity ) use ( $term ) { |
|
83 | - $entity['@id'] = get_term_link( $term->term_id ) . '#id'; |
|
84 | - if ( ! empty( $term->description ) ) { |
|
85 | - $entity['description'] = $term->description; |
|
86 | - } |
|
81 | + return array_map( |
|
82 | + function ( $entity ) use ( $term ) { |
|
83 | + $entity['@id'] = get_term_link( $term->term_id ) . '#id'; |
|
84 | + if ( ! empty( $term->description ) ) { |
|
85 | + $entity['description'] = $term->description; |
|
86 | + } |
|
87 | 87 | |
88 | - return $entity; |
|
88 | + return $entity; |
|
89 | 89 | |
90 | - }, |
|
91 | - $entities |
|
92 | - ); |
|
90 | + }, |
|
91 | + $entities |
|
92 | + ); |
|
93 | 93 | |
94 | - } |
|
94 | + } |
|
95 | 95 | |
96 | - public function wl_after_get_jsonld( $jsonld ) { |
|
96 | + public function wl_after_get_jsonld( $jsonld ) { |
|
97 | 97 | |
98 | - if ( ! is_array( $jsonld ) || count( $jsonld ) === 0 ) { |
|
99 | - return $jsonld; |
|
100 | - } |
|
98 | + if ( ! is_array( $jsonld ) || count( $jsonld ) === 0 ) { |
|
99 | + return $jsonld; |
|
100 | + } |
|
101 | 101 | |
102 | - foreach ( $jsonld as $key => $value ) { |
|
103 | - if ( 'Article' === $value['@type'] && isset( $value['image'] ) ) { |
|
104 | - $image = $value['image']; |
|
105 | - } |
|
106 | - if ( 'Recipe' === $value['@type'] && ! isset( $value['image'] ) ) { |
|
107 | - $index = $key; |
|
108 | - } |
|
109 | - } |
|
102 | + foreach ( $jsonld as $key => $value ) { |
|
103 | + if ( 'Article' === $value['@type'] && isset( $value['image'] ) ) { |
|
104 | + $image = $value['image']; |
|
105 | + } |
|
106 | + if ( 'Recipe' === $value['@type'] && ! isset( $value['image'] ) ) { |
|
107 | + $index = $key; |
|
108 | + } |
|
109 | + } |
|
110 | 110 | |
111 | - if ( isset( $index ) && ! empty( $image ) ) { |
|
112 | - $jsonld[ $index ]['image'] = $image; |
|
113 | - } |
|
111 | + if ( isset( $index ) && ! empty( $image ) ) { |
|
112 | + $jsonld[ $index ]['image'] = $image; |
|
113 | + } |
|
114 | 114 | |
115 | - return $jsonld; |
|
115 | + return $jsonld; |
|
116 | 116 | |
117 | - } |
|
117 | + } |
|
118 | 118 | |
119 | 119 | } |
@@ -12,16 +12,16 @@ discard block |
||
12 | 12 | class Post_Jsonld { |
13 | 13 | |
14 | 14 | public function enhance_post_jsonld() { |
15 | - add_filter( 'wl_post_jsonld_array', array( $this, 'wl_post_jsonld_array' ), 11, 2 ); |
|
16 | - add_filter( 'wl_after_get_jsonld', array( $this, 'wl_after_get_jsonld' ), 11 ); |
|
15 | + add_filter('wl_post_jsonld_array', array($this, 'wl_post_jsonld_array'), 11, 2); |
|
16 | + add_filter('wl_after_get_jsonld', array($this, 'wl_after_get_jsonld'), 11); |
|
17 | 17 | } |
18 | 18 | |
19 | - public function wl_post_jsonld_array( $arr, $post_id ) { |
|
19 | + public function wl_post_jsonld_array($arr, $post_id) { |
|
20 | 20 | |
21 | 21 | $jsonld = $arr['jsonld']; |
22 | 22 | $references = $arr['references']; |
23 | 23 | |
24 | - $this->add_mentions( $post_id, $jsonld ); |
|
24 | + $this->add_mentions($post_id, $jsonld); |
|
25 | 25 | |
26 | 26 | return array( |
27 | 27 | 'jsonld' => $jsonld, |
@@ -30,42 +30,42 @@ discard block |
||
30 | 30 | |
31 | 31 | } |
32 | 32 | |
33 | - public function add_mentions( $post_id, &$jsonld ) { |
|
33 | + public function add_mentions($post_id, &$jsonld) { |
|
34 | 34 | |
35 | 35 | $taxonomies = Terms_Compat::get_public_taxonomies(); |
36 | 36 | $terms = array(); |
37 | 37 | |
38 | - foreach ( $taxonomies as $taxonomy ) { |
|
39 | - $taxonomy_terms = get_the_terms( $post_id, $taxonomy ); |
|
40 | - if ( ! $taxonomy_terms ) { |
|
38 | + foreach ($taxonomies as $taxonomy) { |
|
39 | + $taxonomy_terms = get_the_terms($post_id, $taxonomy); |
|
40 | + if ( ! $taxonomy_terms) { |
|
41 | 41 | continue; |
42 | 42 | } |
43 | - $terms = array_merge( $taxonomy_terms, $terms ); |
|
43 | + $terms = array_merge($taxonomy_terms, $terms); |
|
44 | 44 | } |
45 | 45 | |
46 | - if ( ! $terms ) { |
|
46 | + if ( ! $terms) { |
|
47 | 47 | return; |
48 | 48 | } |
49 | 49 | |
50 | - if ( ! array_key_exists( 'mentions', $jsonld ) ) { |
|
50 | + if ( ! array_key_exists('mentions', $jsonld)) { |
|
51 | 51 | $jsonld['mentions'] = array(); |
52 | 52 | } |
53 | 53 | |
54 | - foreach ( $terms as $term ) { |
|
54 | + foreach ($terms as $term) { |
|
55 | 55 | |
56 | - $is_matched = intval( get_term_meta( $term->term_id, Entity_Rest_Endpoint::IGNORE_TAG_FROM_LISTING, true ) ) === 1; |
|
56 | + $is_matched = intval(get_term_meta($term->term_id, Entity_Rest_Endpoint::IGNORE_TAG_FROM_LISTING, true)) === 1; |
|
57 | 57 | |
58 | - if ( ! $is_matched ) { |
|
58 | + if ( ! $is_matched) { |
|
59 | 59 | continue; |
60 | 60 | } |
61 | 61 | |
62 | - $entities = Jsonld_Utils::get_matched_entities_for_term( $term->term_id ); |
|
62 | + $entities = Jsonld_Utils::get_matched_entities_for_term($term->term_id); |
|
63 | 63 | |
64 | - if ( count( $entities ) === 0 ) { |
|
64 | + if (count($entities) === 0) { |
|
65 | 65 | continue; |
66 | 66 | } |
67 | 67 | |
68 | - $jsonld['mentions'] = array_merge( $jsonld['mentions'], self::add_additional_attrs( $term, $entities ) ); |
|
68 | + $jsonld['mentions'] = array_merge($jsonld['mentions'], self::add_additional_attrs($term, $entities)); |
|
69 | 69 | } |
70 | 70 | |
71 | 71 | } |
@@ -76,12 +76,12 @@ discard block |
||
76 | 76 | * |
77 | 77 | * @return array |
78 | 78 | */ |
79 | - public static function add_additional_attrs( $term, $entities ) { |
|
79 | + public static function add_additional_attrs($term, $entities) { |
|
80 | 80 | |
81 | 81 | return array_map( |
82 | - function ( $entity ) use ( $term ) { |
|
83 | - $entity['@id'] = get_term_link( $term->term_id ) . '#id'; |
|
84 | - if ( ! empty( $term->description ) ) { |
|
82 | + function($entity) use ($term) { |
|
83 | + $entity['@id'] = get_term_link($term->term_id).'#id'; |
|
84 | + if ( ! empty($term->description)) { |
|
85 | 85 | $entity['description'] = $term->description; |
86 | 86 | } |
87 | 87 | |
@@ -93,23 +93,23 @@ discard block |
||
93 | 93 | |
94 | 94 | } |
95 | 95 | |
96 | - public function wl_after_get_jsonld( $jsonld ) { |
|
96 | + public function wl_after_get_jsonld($jsonld) { |
|
97 | 97 | |
98 | - if ( ! is_array( $jsonld ) || count( $jsonld ) === 0 ) { |
|
98 | + if ( ! is_array($jsonld) || count($jsonld) === 0) { |
|
99 | 99 | return $jsonld; |
100 | 100 | } |
101 | 101 | |
102 | - foreach ( $jsonld as $key => $value ) { |
|
103 | - if ( 'Article' === $value['@type'] && isset( $value['image'] ) ) { |
|
102 | + foreach ($jsonld as $key => $value) { |
|
103 | + if ('Article' === $value['@type'] && isset($value['image'])) { |
|
104 | 104 | $image = $value['image']; |
105 | 105 | } |
106 | - if ( 'Recipe' === $value['@type'] && ! isset( $value['image'] ) ) { |
|
106 | + if ('Recipe' === $value['@type'] && ! isset($value['image'])) { |
|
107 | 107 | $index = $key; |
108 | 108 | } |
109 | 109 | } |
110 | 110 | |
111 | - if ( isset( $index ) && ! empty( $image ) ) { |
|
112 | - $jsonld[ $index ]['image'] = $image; |
|
111 | + if (isset($index) && ! empty($image)) { |
|
112 | + $jsonld[$index]['image'] = $image; |
|
113 | 113 | } |
114 | 114 | |
115 | 115 | return $jsonld; |
@@ -4,195 +4,195 @@ |
||
4 | 4 | |
5 | 5 | class Analysis_Background_Process extends \Wordlift_Plugin_WP_Background_Process { |
6 | 6 | |
7 | - const WL_CMKG_ANALYSIS_BACKGROUND_PROCESS = '_wl_cmkg_analysis_background_process'; |
|
8 | - |
|
9 | - protected $action = 'wl_cmkg_analysis_background__analysis'; |
|
10 | - |
|
11 | - /** |
|
12 | - * @var Analysis_Background_Service |
|
13 | - */ |
|
14 | - private $analysis_background_service; |
|
15 | - |
|
16 | - /** |
|
17 | - * @var \Wordlift_Log_Service |
|
18 | - */ |
|
19 | - private $log; |
|
20 | - |
|
21 | - /** |
|
22 | - * Analysis_Background_Process constructor. |
|
23 | - * |
|
24 | - * @param $analysis_background_service Analysis_Background_Service A {@link Analysis_Background_Service} instance providing the supporting functions to this background process. |
|
25 | - */ |
|
26 | - public function __construct( $analysis_background_service ) { |
|
27 | - parent::__construct(); |
|
28 | - |
|
29 | - $this->log = \Wordlift_Log_Service::get_logger( get_class() ); |
|
30 | - |
|
31 | - $this->analysis_background_service = $analysis_background_service; |
|
32 | - |
|
33 | - } |
|
34 | - |
|
35 | - /** |
|
36 | - * This function is called: |
|
37 | - * - To start a new Synchronization, by passing a {@link Sync_Start_Message} instance. |
|
38 | - * - To synchronize a post, by passing a numeric ID. |
|
39 | - * |
|
40 | - * This function returns the parameter for the next call or NULL if there are no more posts to process. |
|
41 | - * |
|
42 | - * @param int[] $term_ids An array of term IDs. |
|
43 | - * |
|
44 | - * @return int[]|false The next term IDs or false if there are no more. |
|
45 | - */ |
|
46 | - protected function task( $term_ids ) { |
|
47 | - |
|
48 | - // Check if we must cancel. |
|
49 | - if ( $this->must_cancel() ) { |
|
50 | - $this->cancel(); |
|
51 | - |
|
52 | - return false; |
|
53 | - } |
|
54 | - |
|
55 | - if ( ! $term_ids || ! is_array( $term_ids ) ) { |
|
56 | - $this->cancel(); |
|
57 | - return false; |
|
58 | - } |
|
59 | - |
|
60 | - $this->log->debug( sprintf( 'Synchronizing terms %s...', implode( ', ', $term_ids ) ) ); |
|
61 | - // Sync the item. |
|
62 | - return $this->sync_items( $term_ids ); |
|
63 | - } |
|
64 | - |
|
65 | - /** |
|
66 | - * Start the background processing. |
|
67 | - * |
|
68 | - * @return bool True if the process has been started, otherwise false. |
|
69 | - */ |
|
70 | - public function start() { |
|
71 | - $this->log->debug( 'Trying to start analysis bg service...' ); |
|
72 | - // Create a new Sync_Model state of `started`. |
|
73 | - if ( ! $this->is_started( self::get_state() ) ) { |
|
74 | - $this->log->debug( 'Starting...' ); |
|
75 | - |
|
76 | - $sync_state = new Sync_State( time(), 0, $this->analysis_background_service->count(), time(), 'started' ); |
|
77 | - update_option( self::WL_CMKG_ANALYSIS_BACKGROUND_PROCESS, $sync_state, false ); |
|
78 | - |
|
79 | - $next = $this->analysis_background_service->next(); |
|
80 | - |
|
81 | - $this->push_to_queue( $next ); |
|
82 | - $this->save()->dispatch(); |
|
83 | - |
|
84 | - if ( $next && is_array( $next ) ) { |
|
85 | - $this->log->debug( sprintf( 'Started with term IDs %s.', implode( ', ', $next ) ) ); |
|
86 | - } |
|
87 | - |
|
88 | - return true; |
|
89 | - } |
|
90 | - |
|
91 | - return false; |
|
92 | - } |
|
93 | - |
|
94 | - /** |
|
95 | - * Set the transient to cancel the process. The next time the process runs, it'll check whether this transient is |
|
96 | - * set and will stop processing. |
|
97 | - */ |
|
98 | - public function request_cancel() { |
|
99 | - |
|
100 | - set_transient( "{$this->action}__cancel", true ); |
|
101 | - |
|
102 | - } |
|
103 | - |
|
104 | - /** |
|
105 | - * Get the sync state. |
|
106 | - * |
|
107 | - * @return Sync_State The {@link Sync_State}. |
|
108 | - */ |
|
109 | - public static function get_state() { |
|
110 | - |
|
111 | - try { |
|
112 | - return get_option( self::WL_CMKG_ANALYSIS_BACKGROUND_PROCESS, Sync_State::unknown() ); |
|
113 | - } catch ( \Exception $e ) { |
|
114 | - return Sync_State::unknown(); |
|
115 | - } |
|
116 | - |
|
117 | - } |
|
118 | - |
|
119 | - /** |
|
120 | - * Check whether the provided state is `started` or not. |
|
121 | - * |
|
122 | - * @param Sync_State $state The {@link Sync_State}. |
|
123 | - * |
|
124 | - * @return bool True if the state is started. |
|
125 | - */ |
|
126 | - private function is_started( $state ) { |
|
127 | - return $state instanceof Sync_State && 'started' === $state->state && 30 > ( time() - $state->last_update ); |
|
128 | - } |
|
129 | - |
|
130 | - /** |
|
131 | - * Check whether the process must cancel or not. |
|
132 | - * |
|
133 | - * @return bool Whether to cancel or not the process. |
|
134 | - */ |
|
135 | - private function must_cancel() { |
|
136 | - |
|
137 | - return get_transient( "{$this->action}__cancel" ); |
|
138 | - } |
|
139 | - |
|
140 | - /** |
|
141 | - * Cancels the current process. |
|
142 | - */ |
|
143 | - public function cancel() { |
|
144 | - |
|
145 | - $this->log->debug( 'Cancelling synchronization...' ); |
|
146 | - |
|
147 | - // Cleanup the process data. |
|
148 | - $this->cancel_process(); |
|
149 | - |
|
150 | - // Set the state to cancelled. |
|
151 | - $state = self::get_state(); |
|
152 | - $state->set_state( 'cancelled' ); |
|
153 | - update_option( self::WL_CMKG_ANALYSIS_BACKGROUND_PROCESS, $state, false ); |
|
154 | - |
|
155 | - // Finally delete the transient. |
|
156 | - delete_transient( "{$this->action}__cancel" ); |
|
157 | - |
|
158 | - } |
|
159 | - |
|
160 | - /** |
|
161 | - * Push the post with the provided ID to the remote platform. |
|
162 | - * |
|
163 | - * @param int[] $term_ids The term IDs. |
|
164 | - * |
|
165 | - * @return int[]|false The next term ID to process or false if processing is complete. |
|
166 | - */ |
|
167 | - private function sync_items( $term_ids ) { |
|
168 | - |
|
169 | - // Sync this item. |
|
170 | - if ( $this->analysis_background_service->perform_analysis_for_terms( $term_ids ) ) { |
|
171 | - |
|
172 | - $next = $this->analysis_background_service->next(); |
|
173 | - $next_state = isset( $next ) ? 'started' : 'ended'; |
|
174 | - |
|
175 | - /** |
|
176 | - * Update the synchronization meta data, by increasing the current index. |
|
177 | - * |
|
178 | - * @var Sync_State $sync The {@link Sync_State}. |
|
179 | - */ |
|
180 | - $state = self::get_state() |
|
181 | - ->increment_index( $this->analysis_background_service->get_batch_size() ) |
|
182 | - ->set_state( $next_state ); |
|
183 | - update_option( self::WL_CMKG_ANALYSIS_BACKGROUND_PROCESS . '', $state, false ); |
|
184 | - |
|
185 | - // Return the next IDs or false if there aren't. |
|
186 | - return isset( $next ) ? $next : false; |
|
187 | - } else { |
|
188 | - // Retry. |
|
189 | - // @@todo: put a limit to the number of retries. |
|
190 | - |
|
191 | - $this->log->error( sprintf( 'Sync failed for terms %s.', implode( ', ', $term_ids ) ) ); |
|
192 | - |
|
193 | - return $term_ids; |
|
194 | - } |
|
195 | - |
|
196 | - } |
|
7 | + const WL_CMKG_ANALYSIS_BACKGROUND_PROCESS = '_wl_cmkg_analysis_background_process'; |
|
8 | + |
|
9 | + protected $action = 'wl_cmkg_analysis_background__analysis'; |
|
10 | + |
|
11 | + /** |
|
12 | + * @var Analysis_Background_Service |
|
13 | + */ |
|
14 | + private $analysis_background_service; |
|
15 | + |
|
16 | + /** |
|
17 | + * @var \Wordlift_Log_Service |
|
18 | + */ |
|
19 | + private $log; |
|
20 | + |
|
21 | + /** |
|
22 | + * Analysis_Background_Process constructor. |
|
23 | + * |
|
24 | + * @param $analysis_background_service Analysis_Background_Service A {@link Analysis_Background_Service} instance providing the supporting functions to this background process. |
|
25 | + */ |
|
26 | + public function __construct( $analysis_background_service ) { |
|
27 | + parent::__construct(); |
|
28 | + |
|
29 | + $this->log = \Wordlift_Log_Service::get_logger( get_class() ); |
|
30 | + |
|
31 | + $this->analysis_background_service = $analysis_background_service; |
|
32 | + |
|
33 | + } |
|
34 | + |
|
35 | + /** |
|
36 | + * This function is called: |
|
37 | + * - To start a new Synchronization, by passing a {@link Sync_Start_Message} instance. |
|
38 | + * - To synchronize a post, by passing a numeric ID. |
|
39 | + * |
|
40 | + * This function returns the parameter for the next call or NULL if there are no more posts to process. |
|
41 | + * |
|
42 | + * @param int[] $term_ids An array of term IDs. |
|
43 | + * |
|
44 | + * @return int[]|false The next term IDs or false if there are no more. |
|
45 | + */ |
|
46 | + protected function task( $term_ids ) { |
|
47 | + |
|
48 | + // Check if we must cancel. |
|
49 | + if ( $this->must_cancel() ) { |
|
50 | + $this->cancel(); |
|
51 | + |
|
52 | + return false; |
|
53 | + } |
|
54 | + |
|
55 | + if ( ! $term_ids || ! is_array( $term_ids ) ) { |
|
56 | + $this->cancel(); |
|
57 | + return false; |
|
58 | + } |
|
59 | + |
|
60 | + $this->log->debug( sprintf( 'Synchronizing terms %s...', implode( ', ', $term_ids ) ) ); |
|
61 | + // Sync the item. |
|
62 | + return $this->sync_items( $term_ids ); |
|
63 | + } |
|
64 | + |
|
65 | + /** |
|
66 | + * Start the background processing. |
|
67 | + * |
|
68 | + * @return bool True if the process has been started, otherwise false. |
|
69 | + */ |
|
70 | + public function start() { |
|
71 | + $this->log->debug( 'Trying to start analysis bg service...' ); |
|
72 | + // Create a new Sync_Model state of `started`. |
|
73 | + if ( ! $this->is_started( self::get_state() ) ) { |
|
74 | + $this->log->debug( 'Starting...' ); |
|
75 | + |
|
76 | + $sync_state = new Sync_State( time(), 0, $this->analysis_background_service->count(), time(), 'started' ); |
|
77 | + update_option( self::WL_CMKG_ANALYSIS_BACKGROUND_PROCESS, $sync_state, false ); |
|
78 | + |
|
79 | + $next = $this->analysis_background_service->next(); |
|
80 | + |
|
81 | + $this->push_to_queue( $next ); |
|
82 | + $this->save()->dispatch(); |
|
83 | + |
|
84 | + if ( $next && is_array( $next ) ) { |
|
85 | + $this->log->debug( sprintf( 'Started with term IDs %s.', implode( ', ', $next ) ) ); |
|
86 | + } |
|
87 | + |
|
88 | + return true; |
|
89 | + } |
|
90 | + |
|
91 | + return false; |
|
92 | + } |
|
93 | + |
|
94 | + /** |
|
95 | + * Set the transient to cancel the process. The next time the process runs, it'll check whether this transient is |
|
96 | + * set and will stop processing. |
|
97 | + */ |
|
98 | + public function request_cancel() { |
|
99 | + |
|
100 | + set_transient( "{$this->action}__cancel", true ); |
|
101 | + |
|
102 | + } |
|
103 | + |
|
104 | + /** |
|
105 | + * Get the sync state. |
|
106 | + * |
|
107 | + * @return Sync_State The {@link Sync_State}. |
|
108 | + */ |
|
109 | + public static function get_state() { |
|
110 | + |
|
111 | + try { |
|
112 | + return get_option( self::WL_CMKG_ANALYSIS_BACKGROUND_PROCESS, Sync_State::unknown() ); |
|
113 | + } catch ( \Exception $e ) { |
|
114 | + return Sync_State::unknown(); |
|
115 | + } |
|
116 | + |
|
117 | + } |
|
118 | + |
|
119 | + /** |
|
120 | + * Check whether the provided state is `started` or not. |
|
121 | + * |
|
122 | + * @param Sync_State $state The {@link Sync_State}. |
|
123 | + * |
|
124 | + * @return bool True if the state is started. |
|
125 | + */ |
|
126 | + private function is_started( $state ) { |
|
127 | + return $state instanceof Sync_State && 'started' === $state->state && 30 > ( time() - $state->last_update ); |
|
128 | + } |
|
129 | + |
|
130 | + /** |
|
131 | + * Check whether the process must cancel or not. |
|
132 | + * |
|
133 | + * @return bool Whether to cancel or not the process. |
|
134 | + */ |
|
135 | + private function must_cancel() { |
|
136 | + |
|
137 | + return get_transient( "{$this->action}__cancel" ); |
|
138 | + } |
|
139 | + |
|
140 | + /** |
|
141 | + * Cancels the current process. |
|
142 | + */ |
|
143 | + public function cancel() { |
|
144 | + |
|
145 | + $this->log->debug( 'Cancelling synchronization...' ); |
|
146 | + |
|
147 | + // Cleanup the process data. |
|
148 | + $this->cancel_process(); |
|
149 | + |
|
150 | + // Set the state to cancelled. |
|
151 | + $state = self::get_state(); |
|
152 | + $state->set_state( 'cancelled' ); |
|
153 | + update_option( self::WL_CMKG_ANALYSIS_BACKGROUND_PROCESS, $state, false ); |
|
154 | + |
|
155 | + // Finally delete the transient. |
|
156 | + delete_transient( "{$this->action}__cancel" ); |
|
157 | + |
|
158 | + } |
|
159 | + |
|
160 | + /** |
|
161 | + * Push the post with the provided ID to the remote platform. |
|
162 | + * |
|
163 | + * @param int[] $term_ids The term IDs. |
|
164 | + * |
|
165 | + * @return int[]|false The next term ID to process or false if processing is complete. |
|
166 | + */ |
|
167 | + private function sync_items( $term_ids ) { |
|
168 | + |
|
169 | + // Sync this item. |
|
170 | + if ( $this->analysis_background_service->perform_analysis_for_terms( $term_ids ) ) { |
|
171 | + |
|
172 | + $next = $this->analysis_background_service->next(); |
|
173 | + $next_state = isset( $next ) ? 'started' : 'ended'; |
|
174 | + |
|
175 | + /** |
|
176 | + * Update the synchronization meta data, by increasing the current index. |
|
177 | + * |
|
178 | + * @var Sync_State $sync The {@link Sync_State}. |
|
179 | + */ |
|
180 | + $state = self::get_state() |
|
181 | + ->increment_index( $this->analysis_background_service->get_batch_size() ) |
|
182 | + ->set_state( $next_state ); |
|
183 | + update_option( self::WL_CMKG_ANALYSIS_BACKGROUND_PROCESS . '', $state, false ); |
|
184 | + |
|
185 | + // Return the next IDs or false if there aren't. |
|
186 | + return isset( $next ) ? $next : false; |
|
187 | + } else { |
|
188 | + // Retry. |
|
189 | + // @@todo: put a limit to the number of retries. |
|
190 | + |
|
191 | + $this->log->error( sprintf( 'Sync failed for terms %s.', implode( ', ', $term_ids ) ) ); |
|
192 | + |
|
193 | + return $term_ids; |
|
194 | + } |
|
195 | + |
|
196 | + } |
|
197 | 197 | |
198 | 198 | } |
@@ -23,10 +23,10 @@ discard block |
||
23 | 23 | * |
24 | 24 | * @param $analysis_background_service Analysis_Background_Service A {@link Analysis_Background_Service} instance providing the supporting functions to this background process. |
25 | 25 | */ |
26 | - public function __construct( $analysis_background_service ) { |
|
26 | + public function __construct($analysis_background_service) { |
|
27 | 27 | parent::__construct(); |
28 | 28 | |
29 | - $this->log = \Wordlift_Log_Service::get_logger( get_class() ); |
|
29 | + $this->log = \Wordlift_Log_Service::get_logger(get_class()); |
|
30 | 30 | |
31 | 31 | $this->analysis_background_service = $analysis_background_service; |
32 | 32 | |
@@ -43,23 +43,23 @@ discard block |
||
43 | 43 | * |
44 | 44 | * @return int[]|false The next term IDs or false if there are no more. |
45 | 45 | */ |
46 | - protected function task( $term_ids ) { |
|
46 | + protected function task($term_ids) { |
|
47 | 47 | |
48 | 48 | // Check if we must cancel. |
49 | - if ( $this->must_cancel() ) { |
|
49 | + if ($this->must_cancel()) { |
|
50 | 50 | $this->cancel(); |
51 | 51 | |
52 | 52 | return false; |
53 | 53 | } |
54 | 54 | |
55 | - if ( ! $term_ids || ! is_array( $term_ids ) ) { |
|
55 | + if ( ! $term_ids || ! is_array($term_ids)) { |
|
56 | 56 | $this->cancel(); |
57 | 57 | return false; |
58 | 58 | } |
59 | 59 | |
60 | - $this->log->debug( sprintf( 'Synchronizing terms %s...', implode( ', ', $term_ids ) ) ); |
|
60 | + $this->log->debug(sprintf('Synchronizing terms %s...', implode(', ', $term_ids))); |
|
61 | 61 | // Sync the item. |
62 | - return $this->sync_items( $term_ids ); |
|
62 | + return $this->sync_items($term_ids); |
|
63 | 63 | } |
64 | 64 | |
65 | 65 | /** |
@@ -68,21 +68,21 @@ discard block |
||
68 | 68 | * @return bool True if the process has been started, otherwise false. |
69 | 69 | */ |
70 | 70 | public function start() { |
71 | - $this->log->debug( 'Trying to start analysis bg service...' ); |
|
71 | + $this->log->debug('Trying to start analysis bg service...'); |
|
72 | 72 | // Create a new Sync_Model state of `started`. |
73 | - if ( ! $this->is_started( self::get_state() ) ) { |
|
74 | - $this->log->debug( 'Starting...' ); |
|
73 | + if ( ! $this->is_started(self::get_state())) { |
|
74 | + $this->log->debug('Starting...'); |
|
75 | 75 | |
76 | - $sync_state = new Sync_State( time(), 0, $this->analysis_background_service->count(), time(), 'started' ); |
|
77 | - update_option( self::WL_CMKG_ANALYSIS_BACKGROUND_PROCESS, $sync_state, false ); |
|
76 | + $sync_state = new Sync_State(time(), 0, $this->analysis_background_service->count(), time(), 'started'); |
|
77 | + update_option(self::WL_CMKG_ANALYSIS_BACKGROUND_PROCESS, $sync_state, false); |
|
78 | 78 | |
79 | 79 | $next = $this->analysis_background_service->next(); |
80 | 80 | |
81 | - $this->push_to_queue( $next ); |
|
81 | + $this->push_to_queue($next); |
|
82 | 82 | $this->save()->dispatch(); |
83 | 83 | |
84 | - if ( $next && is_array( $next ) ) { |
|
85 | - $this->log->debug( sprintf( 'Started with term IDs %s.', implode( ', ', $next ) ) ); |
|
84 | + if ($next && is_array($next)) { |
|
85 | + $this->log->debug(sprintf('Started with term IDs %s.', implode(', ', $next))); |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | return true; |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | */ |
98 | 98 | public function request_cancel() { |
99 | 99 | |
100 | - set_transient( "{$this->action}__cancel", true ); |
|
100 | + set_transient("{$this->action}__cancel", true); |
|
101 | 101 | |
102 | 102 | } |
103 | 103 | |
@@ -109,8 +109,8 @@ discard block |
||
109 | 109 | public static function get_state() { |
110 | 110 | |
111 | 111 | try { |
112 | - return get_option( self::WL_CMKG_ANALYSIS_BACKGROUND_PROCESS, Sync_State::unknown() ); |
|
113 | - } catch ( \Exception $e ) { |
|
112 | + return get_option(self::WL_CMKG_ANALYSIS_BACKGROUND_PROCESS, Sync_State::unknown()); |
|
113 | + } catch (\Exception $e) { |
|
114 | 114 | return Sync_State::unknown(); |
115 | 115 | } |
116 | 116 | |
@@ -123,8 +123,8 @@ discard block |
||
123 | 123 | * |
124 | 124 | * @return bool True if the state is started. |
125 | 125 | */ |
126 | - private function is_started( $state ) { |
|
127 | - return $state instanceof Sync_State && 'started' === $state->state && 30 > ( time() - $state->last_update ); |
|
126 | + private function is_started($state) { |
|
127 | + return $state instanceof Sync_State && 'started' === $state->state && 30 > (time() - $state->last_update); |
|
128 | 128 | } |
129 | 129 | |
130 | 130 | /** |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | */ |
135 | 135 | private function must_cancel() { |
136 | 136 | |
137 | - return get_transient( "{$this->action}__cancel" ); |
|
137 | + return get_transient("{$this->action}__cancel"); |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | /** |
@@ -142,18 +142,18 @@ discard block |
||
142 | 142 | */ |
143 | 143 | public function cancel() { |
144 | 144 | |
145 | - $this->log->debug( 'Cancelling synchronization...' ); |
|
145 | + $this->log->debug('Cancelling synchronization...'); |
|
146 | 146 | |
147 | 147 | // Cleanup the process data. |
148 | 148 | $this->cancel_process(); |
149 | 149 | |
150 | 150 | // Set the state to cancelled. |
151 | 151 | $state = self::get_state(); |
152 | - $state->set_state( 'cancelled' ); |
|
153 | - update_option( self::WL_CMKG_ANALYSIS_BACKGROUND_PROCESS, $state, false ); |
|
152 | + $state->set_state('cancelled'); |
|
153 | + update_option(self::WL_CMKG_ANALYSIS_BACKGROUND_PROCESS, $state, false); |
|
154 | 154 | |
155 | 155 | // Finally delete the transient. |
156 | - delete_transient( "{$this->action}__cancel" ); |
|
156 | + delete_transient("{$this->action}__cancel"); |
|
157 | 157 | |
158 | 158 | } |
159 | 159 | |
@@ -164,13 +164,13 @@ discard block |
||
164 | 164 | * |
165 | 165 | * @return int[]|false The next term ID to process or false if processing is complete. |
166 | 166 | */ |
167 | - private function sync_items( $term_ids ) { |
|
167 | + private function sync_items($term_ids) { |
|
168 | 168 | |
169 | 169 | // Sync this item. |
170 | - if ( $this->analysis_background_service->perform_analysis_for_terms( $term_ids ) ) { |
|
170 | + if ($this->analysis_background_service->perform_analysis_for_terms($term_ids)) { |
|
171 | 171 | |
172 | 172 | $next = $this->analysis_background_service->next(); |
173 | - $next_state = isset( $next ) ? 'started' : 'ended'; |
|
173 | + $next_state = isset($next) ? 'started' : 'ended'; |
|
174 | 174 | |
175 | 175 | /** |
176 | 176 | * Update the synchronization meta data, by increasing the current index. |
@@ -178,17 +178,17 @@ discard block |
||
178 | 178 | * @var Sync_State $sync The {@link Sync_State}. |
179 | 179 | */ |
180 | 180 | $state = self::get_state() |
181 | - ->increment_index( $this->analysis_background_service->get_batch_size() ) |
|
182 | - ->set_state( $next_state ); |
|
183 | - update_option( self::WL_CMKG_ANALYSIS_BACKGROUND_PROCESS . '', $state, false ); |
|
181 | + ->increment_index($this->analysis_background_service->get_batch_size()) |
|
182 | + ->set_state($next_state); |
|
183 | + update_option(self::WL_CMKG_ANALYSIS_BACKGROUND_PROCESS.'', $state, false); |
|
184 | 184 | |
185 | 185 | // Return the next IDs or false if there aren't. |
186 | - return isset( $next ) ? $next : false; |
|
186 | + return isset($next) ? $next : false; |
|
187 | 187 | } else { |
188 | 188 | // Retry. |
189 | 189 | // @@todo: put a limit to the number of retries. |
190 | 190 | |
191 | - $this->log->error( sprintf( 'Sync failed for terms %s.', implode( ', ', $term_ids ) ) ); |
|
191 | + $this->log->error(sprintf('Sync failed for terms %s.', implode(', ', $term_ids))); |
|
192 | 192 | |
193 | 193 | return $term_ids; |
194 | 194 | } |
@@ -4,56 +4,56 @@ |
||
4 | 4 | |
5 | 5 | class Sync_State { |
6 | 6 | |
7 | - public $started; |
|
8 | - public $index; |
|
9 | - public $count; |
|
10 | - public $last_update; |
|
11 | - public $state; |
|
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( $started, $index, $count, $last_update, $state ) { |
|
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 | - |
|
30 | - public function increment_index( $count ) { |
|
31 | - $this->index += $count; |
|
32 | - $this->last_update = time(); |
|
33 | - |
|
34 | - return $this; |
|
35 | - } |
|
36 | - |
|
37 | - public function set_state( $value ) { |
|
38 | - $this->state = $value; |
|
39 | - $this->last_update = time(); |
|
40 | - |
|
41 | - return $this; |
|
42 | - } |
|
43 | - |
|
44 | - public function get_array() { |
|
45 | - return array( |
|
46 | - 'started' => $this->started, |
|
47 | - 'index' => $this->index, |
|
48 | - 'count' => $this->count, |
|
49 | - 'last_update' => $this->last_update, |
|
50 | - 'state' => $this->state, |
|
51 | - ); |
|
52 | - } |
|
53 | - |
|
54 | - public static function unknown() { |
|
55 | - |
|
56 | - return new self( time(), 0, 0, time(), 'unknown' ); |
|
57 | - } |
|
7 | + public $started; |
|
8 | + public $index; |
|
9 | + public $count; |
|
10 | + public $last_update; |
|
11 | + public $state; |
|
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( $started, $index, $count, $last_update, $state ) { |
|
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 | + |
|
30 | + public function increment_index( $count ) { |
|
31 | + $this->index += $count; |
|
32 | + $this->last_update = time(); |
|
33 | + |
|
34 | + return $this; |
|
35 | + } |
|
36 | + |
|
37 | + public function set_state( $value ) { |
|
38 | + $this->state = $value; |
|
39 | + $this->last_update = time(); |
|
40 | + |
|
41 | + return $this; |
|
42 | + } |
|
43 | + |
|
44 | + public function get_array() { |
|
45 | + return array( |
|
46 | + 'started' => $this->started, |
|
47 | + 'index' => $this->index, |
|
48 | + 'count' => $this->count, |
|
49 | + 'last_update' => $this->last_update, |
|
50 | + 'state' => $this->state, |
|
51 | + ); |
|
52 | + } |
|
53 | + |
|
54 | + public static function unknown() { |
|
55 | + |
|
56 | + return new self( time(), 0, 0, time(), 'unknown' ); |
|
57 | + } |
|
58 | 58 | |
59 | 59 | } |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | * @param $last_update |
20 | 20 | * @param $state |
21 | 21 | */ |
22 | - public function __construct( $started, $index, $count, $last_update, $state ) { |
|
22 | + public function __construct($started, $index, $count, $last_update, $state) { |
|
23 | 23 | $this->started = $started; |
24 | 24 | $this->index = $index; |
25 | 25 | $this->count = (int) $count; |
@@ -27,14 +27,14 @@ discard block |
||
27 | 27 | $this->state = $state; |
28 | 28 | } |
29 | 29 | |
30 | - public function increment_index( $count ) { |
|
30 | + public function increment_index($count) { |
|
31 | 31 | $this->index += $count; |
32 | 32 | $this->last_update = time(); |
33 | 33 | |
34 | 34 | return $this; |
35 | 35 | } |
36 | 36 | |
37 | - public function set_state( $value ) { |
|
37 | + public function set_state($value) { |
|
38 | 38 | $this->state = $value; |
39 | 39 | $this->last_update = time(); |
40 | 40 | |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | |
54 | 54 | public static function unknown() { |
55 | 55 | |
56 | - return new self( time(), 0, 0, time(), 'unknown' ); |
|
56 | + return new self(time(), 0, 0, time(), 'unknown'); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | } |
@@ -4,8 +4,8 @@ |
||
4 | 4 | |
5 | 5 | class Cache_Service_Factory { |
6 | 6 | |
7 | - public static function get_cache_service() { |
|
8 | - return new Options_Cache( 'wordlift-cmkg' ); |
|
9 | - } |
|
7 | + public static function get_cache_service() { |
|
8 | + return new Options_Cache( 'wordlift-cmkg' ); |
|
9 | + } |
|
10 | 10 | |
11 | 11 | } |
@@ -5,7 +5,7 @@ |
||
5 | 5 | class Cache_Service_Factory { |
6 | 6 | |
7 | 7 | public static function get_cache_service() { |
8 | - return new Options_Cache( 'wordlift-cmkg' ); |
|
8 | + return new Options_Cache('wordlift-cmkg'); |
|
9 | 9 | } |
10 | 10 | |
11 | 11 | } |
@@ -4,35 +4,35 @@ |
||
4 | 4 | |
5 | 5 | class Options_Cache implements Cache { |
6 | 6 | |
7 | - private $namespace; |
|
7 | + private $namespace; |
|
8 | 8 | |
9 | - /** |
|
10 | - * Options_Cache constructor. |
|
11 | - * |
|
12 | - * @param $namespace |
|
13 | - */ |
|
14 | - public function __construct( $namespace ) { |
|
15 | - $this->namespace = $namespace; |
|
16 | - } |
|
9 | + /** |
|
10 | + * Options_Cache constructor. |
|
11 | + * |
|
12 | + * @param $namespace |
|
13 | + */ |
|
14 | + public function __construct( $namespace ) { |
|
15 | + $this->namespace = $namespace; |
|
16 | + } |
|
17 | 17 | |
18 | - public function get( $cache_key ) { |
|
18 | + public function get( $cache_key ) { |
|
19 | 19 | |
20 | - return get_option( $this->namespace . '__' . $cache_key, false ); |
|
20 | + return get_option( $this->namespace . '__' . $cache_key, false ); |
|
21 | 21 | |
22 | - } |
|
22 | + } |
|
23 | 23 | |
24 | - public function put( $cache_key, $value ) { |
|
24 | + public function put( $cache_key, $value ) { |
|
25 | 25 | |
26 | - return update_option( $this->namespace . '__' . $cache_key, $value ); |
|
26 | + return update_option( $this->namespace . '__' . $cache_key, $value ); |
|
27 | 27 | |
28 | - } |
|
28 | + } |
|
29 | 29 | |
30 | - public function flush_all() { |
|
31 | - if ( '' !== $this->namespace ) { |
|
32 | - global $wpdb; |
|
33 | - $namespace_esc = $wpdb->esc_like( $this->namespace ) . '__%'; |
|
34 | - $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->options WHERE option_name LIKE %s", $namespace_esc ) ); |
|
35 | - } |
|
36 | - } |
|
30 | + public function flush_all() { |
|
31 | + if ( '' !== $this->namespace ) { |
|
32 | + global $wpdb; |
|
33 | + $namespace_esc = $wpdb->esc_like( $this->namespace ) . '__%'; |
|
34 | + $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->options WHERE option_name LIKE %s", $namespace_esc ) ); |
|
35 | + } |
|
36 | + } |
|
37 | 37 | |
38 | 38 | } |
@@ -11,27 +11,27 @@ |
||
11 | 11 | * |
12 | 12 | * @param $namespace |
13 | 13 | */ |
14 | - public function __construct( $namespace ) { |
|
14 | + public function __construct($namespace) { |
|
15 | 15 | $this->namespace = $namespace; |
16 | 16 | } |
17 | 17 | |
18 | - public function get( $cache_key ) { |
|
18 | + public function get($cache_key) { |
|
19 | 19 | |
20 | - return get_option( $this->namespace . '__' . $cache_key, false ); |
|
20 | + return get_option($this->namespace.'__'.$cache_key, false); |
|
21 | 21 | |
22 | 22 | } |
23 | 23 | |
24 | - public function put( $cache_key, $value ) { |
|
24 | + public function put($cache_key, $value) { |
|
25 | 25 | |
26 | - return update_option( $this->namespace . '__' . $cache_key, $value ); |
|
26 | + return update_option($this->namespace.'__'.$cache_key, $value); |
|
27 | 27 | |
28 | 28 | } |
29 | 29 | |
30 | 30 | public function flush_all() { |
31 | - if ( '' !== $this->namespace ) { |
|
31 | + if ('' !== $this->namespace) { |
|
32 | 32 | global $wpdb; |
33 | - $namespace_esc = $wpdb->esc_like( $this->namespace ) . '__%'; |
|
34 | - $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->options WHERE option_name LIKE %s", $namespace_esc ) ); |
|
33 | + $namespace_esc = $wpdb->esc_like($this->namespace).'__%'; |
|
34 | + $wpdb->query($wpdb->prepare("DELETE FROM $wpdb->options WHERE option_name LIKE %s", $namespace_esc)); |
|
35 | 35 | } |
36 | 36 | } |
37 | 37 |
@@ -16,47 +16,47 @@ |
||
16 | 16 | |
17 | 17 | class Term_Link extends Default_Link { |
18 | 18 | |
19 | - /** |
|
20 | - * @var Synonyms_Service |
|
21 | - */ |
|
22 | - private $synonyms_service; |
|
23 | - |
|
24 | - public function __construct() { |
|
25 | - parent::__construct(); |
|
26 | - $this->synonyms_service = Synonyms_Service::get_instance(); |
|
27 | - } |
|
28 | - |
|
29 | - /** |
|
30 | - * @throws Exception when the {@link Wordpress_Term_Content_Legacy_Service} throws one, i.e. when passing a non term content id. |
|
31 | - */ |
|
32 | - public function get_same_as_uris( $id ) { |
|
33 | - return array_merge( |
|
34 | - (array) Wordpress_Term_Content_Legacy_Service::get_instance() |
|
35 | - ->get_entity_id( Wordpress_Content_Id::create_term( $id ) ), |
|
36 | - get_term_meta( $id, Wordlift_Schema_Service::FIELD_SAME_AS ) |
|
37 | - ); |
|
38 | - } |
|
39 | - |
|
40 | - public function get_id( $uri ) { |
|
41 | - $content = Wordpress_Term_Content_Legacy_Service::get_instance() |
|
42 | - ->get_by_entity_id_or_same_as( $uri ); |
|
43 | - |
|
44 | - if ( ! isset( $content ) ) { |
|
45 | - return false; |
|
46 | - } |
|
47 | - |
|
48 | - return $content->get_bag()->term_id; |
|
49 | - } |
|
50 | - |
|
51 | - public function get_synonyms( $id ) { |
|
52 | - return $this->synonyms_service->get_synonyms( $id ); |
|
53 | - } |
|
54 | - |
|
55 | - public function get_permalink( $id ) { |
|
56 | - return get_term_link( $id ); |
|
57 | - } |
|
58 | - |
|
59 | - public function get_edit_page_link( $id ) { |
|
60 | - return get_edit_term_link( $id ); |
|
61 | - } |
|
19 | + /** |
|
20 | + * @var Synonyms_Service |
|
21 | + */ |
|
22 | + private $synonyms_service; |
|
23 | + |
|
24 | + public function __construct() { |
|
25 | + parent::__construct(); |
|
26 | + $this->synonyms_service = Synonyms_Service::get_instance(); |
|
27 | + } |
|
28 | + |
|
29 | + /** |
|
30 | + * @throws Exception when the {@link Wordpress_Term_Content_Legacy_Service} throws one, i.e. when passing a non term content id. |
|
31 | + */ |
|
32 | + public function get_same_as_uris( $id ) { |
|
33 | + return array_merge( |
|
34 | + (array) Wordpress_Term_Content_Legacy_Service::get_instance() |
|
35 | + ->get_entity_id( Wordpress_Content_Id::create_term( $id ) ), |
|
36 | + get_term_meta( $id, Wordlift_Schema_Service::FIELD_SAME_AS ) |
|
37 | + ); |
|
38 | + } |
|
39 | + |
|
40 | + public function get_id( $uri ) { |
|
41 | + $content = Wordpress_Term_Content_Legacy_Service::get_instance() |
|
42 | + ->get_by_entity_id_or_same_as( $uri ); |
|
43 | + |
|
44 | + if ( ! isset( $content ) ) { |
|
45 | + return false; |
|
46 | + } |
|
47 | + |
|
48 | + return $content->get_bag()->term_id; |
|
49 | + } |
|
50 | + |
|
51 | + public function get_synonyms( $id ) { |
|
52 | + return $this->synonyms_service->get_synonyms( $id ); |
|
53 | + } |
|
54 | + |
|
55 | + public function get_permalink( $id ) { |
|
56 | + return get_term_link( $id ); |
|
57 | + } |
|
58 | + |
|
59 | + public function get_edit_page_link( $id ) { |
|
60 | + return get_edit_term_link( $id ); |
|
61 | + } |
|
62 | 62 | } |
@@ -29,34 +29,34 @@ |
||
29 | 29 | /** |
30 | 30 | * @throws Exception when the {@link Wordpress_Term_Content_Legacy_Service} throws one, i.e. when passing a non term content id. |
31 | 31 | */ |
32 | - public function get_same_as_uris( $id ) { |
|
32 | + public function get_same_as_uris($id) { |
|
33 | 33 | return array_merge( |
34 | 34 | (array) Wordpress_Term_Content_Legacy_Service::get_instance() |
35 | - ->get_entity_id( Wordpress_Content_Id::create_term( $id ) ), |
|
36 | - get_term_meta( $id, Wordlift_Schema_Service::FIELD_SAME_AS ) |
|
35 | + ->get_entity_id(Wordpress_Content_Id::create_term($id)), |
|
36 | + get_term_meta($id, Wordlift_Schema_Service::FIELD_SAME_AS) |
|
37 | 37 | ); |
38 | 38 | } |
39 | 39 | |
40 | - public function get_id( $uri ) { |
|
40 | + public function get_id($uri) { |
|
41 | 41 | $content = Wordpress_Term_Content_Legacy_Service::get_instance() |
42 | - ->get_by_entity_id_or_same_as( $uri ); |
|
42 | + ->get_by_entity_id_or_same_as($uri); |
|
43 | 43 | |
44 | - if ( ! isset( $content ) ) { |
|
44 | + if ( ! isset($content)) { |
|
45 | 45 | return false; |
46 | 46 | } |
47 | 47 | |
48 | 48 | return $content->get_bag()->term_id; |
49 | 49 | } |
50 | 50 | |
51 | - public function get_synonyms( $id ) { |
|
52 | - return $this->synonyms_service->get_synonyms( $id ); |
|
51 | + public function get_synonyms($id) { |
|
52 | + return $this->synonyms_service->get_synonyms($id); |
|
53 | 53 | } |
54 | 54 | |
55 | - public function get_permalink( $id ) { |
|
56 | - return get_term_link( $id ); |
|
55 | + public function get_permalink($id) { |
|
56 | + return get_term_link($id); |
|
57 | 57 | } |
58 | 58 | |
59 | - public function get_edit_page_link( $id ) { |
|
60 | - return get_edit_term_link( $id ); |
|
59 | + public function get_edit_page_link($id) { |
|
60 | + return get_edit_term_link($id); |
|
61 | 61 | } |
62 | 62 | } |
@@ -9,93 +9,93 @@ |
||
9 | 9 | |
10 | 10 | class Link_Builder { |
11 | 11 | |
12 | - private $id; |
|
13 | - private $type; |
|
14 | - private $label; |
|
15 | - private $href; |
|
16 | - private $entity_url; |
|
17 | - /** |
|
18 | - * @var Object_Link_Provider |
|
19 | - */ |
|
20 | - private $object_link_provider; |
|
21 | - |
|
22 | - public function __construct( $entity_url, $id ) { |
|
23 | - $this->entity_url = $entity_url; |
|
24 | - $this->id = $id; |
|
25 | - $this->object_link_provider = Object_Link_Provider::get_instance(); |
|
26 | - $this->type = $this->object_link_provider->get_object_type( $entity_url ); |
|
27 | - } |
|
28 | - |
|
29 | - public static function create( $entity_url, $id ) { |
|
30 | - return new Link_Builder( $entity_url, $id ); |
|
31 | - } |
|
32 | - |
|
33 | - public function label( $label ) { |
|
34 | - $this->label = $label; |
|
35 | - |
|
36 | - return $this; |
|
37 | - } |
|
38 | - |
|
39 | - public function href( $href ) { |
|
40 | - $this->href = $href; |
|
41 | - |
|
42 | - return $this; |
|
43 | - } |
|
44 | - |
|
45 | - private function get_attributes_for_link() { |
|
46 | - /** |
|
47 | - * Allow 3rd parties to add additional attributes to the anchor link. |
|
48 | - * |
|
49 | - * @since 3.26.0 |
|
50 | - */ |
|
51 | - $default_attributes = array( |
|
52 | - 'id' => implode( ';', $this->object_link_provider->get_same_as_uris( $this->id, $this->type ) ), |
|
53 | - ); |
|
54 | - |
|
55 | - /** |
|
56 | - * @since 3.32.0 |
|
57 | - * Additional parameter {@link $this->type} is added to the filter denoting the type of |
|
58 | - * the entity url by the enum values {@link Object_Type_Enum} |
|
59 | - */ |
|
60 | - $attributes = apply_filters( 'wl_anchor_data_attributes', $default_attributes, $this->id, $this->type ); |
|
61 | - $attributes_html = ''; |
|
62 | - foreach ( $attributes as $key => $value ) { |
|
63 | - $attributes_html .= ' data-' . esc_html( $key ) . '="' . esc_attr( $value ) . '" '; |
|
64 | - } |
|
65 | - |
|
66 | - return $attributes_html; |
|
67 | - } |
|
68 | - |
|
69 | - /** |
|
70 | - * Get a `title` attribute with an alternative label for the link. |
|
71 | - * |
|
72 | - * If an alternative title isn't available an empty string is returned. |
|
73 | - * |
|
74 | - * @return string A `title` attribute with an alternative label or an empty |
|
75 | - * string if none available. |
|
76 | - * @since 3.32.0 |
|
77 | - */ |
|
78 | - private function get_title_attribute() { |
|
79 | - |
|
80 | - // Get an alternative title. |
|
81 | - $title = $this->object_link_provider->get_link_title( $this->id, $this->label, $this->type ); |
|
82 | - if ( ! empty( $title ) ) { |
|
83 | - return 'title="' . esc_attr( $title ) . '"'; |
|
84 | - } |
|
85 | - |
|
86 | - return ''; |
|
87 | - } |
|
88 | - |
|
89 | - /** |
|
90 | - * @return string |
|
91 | - */ |
|
92 | - public function generate_link() { |
|
93 | - // Get an alternative title attribute. |
|
94 | - $title_attribute = $this->get_title_attribute(); |
|
95 | - $attributes_html = $this->get_attributes_for_link(); |
|
96 | - |
|
97 | - // Return the link. |
|
98 | - return "<a class=\"wl-entity-page-link\" $title_attribute href=\"{$this->href}\"$attributes_html>{$this->label}</a>"; |
|
99 | - } |
|
12 | + private $id; |
|
13 | + private $type; |
|
14 | + private $label; |
|
15 | + private $href; |
|
16 | + private $entity_url; |
|
17 | + /** |
|
18 | + * @var Object_Link_Provider |
|
19 | + */ |
|
20 | + private $object_link_provider; |
|
21 | + |
|
22 | + public function __construct( $entity_url, $id ) { |
|
23 | + $this->entity_url = $entity_url; |
|
24 | + $this->id = $id; |
|
25 | + $this->object_link_provider = Object_Link_Provider::get_instance(); |
|
26 | + $this->type = $this->object_link_provider->get_object_type( $entity_url ); |
|
27 | + } |
|
28 | + |
|
29 | + public static function create( $entity_url, $id ) { |
|
30 | + return new Link_Builder( $entity_url, $id ); |
|
31 | + } |
|
32 | + |
|
33 | + public function label( $label ) { |
|
34 | + $this->label = $label; |
|
35 | + |
|
36 | + return $this; |
|
37 | + } |
|
38 | + |
|
39 | + public function href( $href ) { |
|
40 | + $this->href = $href; |
|
41 | + |
|
42 | + return $this; |
|
43 | + } |
|
44 | + |
|
45 | + private function get_attributes_for_link() { |
|
46 | + /** |
|
47 | + * Allow 3rd parties to add additional attributes to the anchor link. |
|
48 | + * |
|
49 | + * @since 3.26.0 |
|
50 | + */ |
|
51 | + $default_attributes = array( |
|
52 | + 'id' => implode( ';', $this->object_link_provider->get_same_as_uris( $this->id, $this->type ) ), |
|
53 | + ); |
|
54 | + |
|
55 | + /** |
|
56 | + * @since 3.32.0 |
|
57 | + * Additional parameter {@link $this->type} is added to the filter denoting the type of |
|
58 | + * the entity url by the enum values {@link Object_Type_Enum} |
|
59 | + */ |
|
60 | + $attributes = apply_filters( 'wl_anchor_data_attributes', $default_attributes, $this->id, $this->type ); |
|
61 | + $attributes_html = ''; |
|
62 | + foreach ( $attributes as $key => $value ) { |
|
63 | + $attributes_html .= ' data-' . esc_html( $key ) . '="' . esc_attr( $value ) . '" '; |
|
64 | + } |
|
65 | + |
|
66 | + return $attributes_html; |
|
67 | + } |
|
68 | + |
|
69 | + /** |
|
70 | + * Get a `title` attribute with an alternative label for the link. |
|
71 | + * |
|
72 | + * If an alternative title isn't available an empty string is returned. |
|
73 | + * |
|
74 | + * @return string A `title` attribute with an alternative label or an empty |
|
75 | + * string if none available. |
|
76 | + * @since 3.32.0 |
|
77 | + */ |
|
78 | + private function get_title_attribute() { |
|
79 | + |
|
80 | + // Get an alternative title. |
|
81 | + $title = $this->object_link_provider->get_link_title( $this->id, $this->label, $this->type ); |
|
82 | + if ( ! empty( $title ) ) { |
|
83 | + return 'title="' . esc_attr( $title ) . '"'; |
|
84 | + } |
|
85 | + |
|
86 | + return ''; |
|
87 | + } |
|
88 | + |
|
89 | + /** |
|
90 | + * @return string |
|
91 | + */ |
|
92 | + public function generate_link() { |
|
93 | + // Get an alternative title attribute. |
|
94 | + $title_attribute = $this->get_title_attribute(); |
|
95 | + $attributes_html = $this->get_attributes_for_link(); |
|
96 | + |
|
97 | + // Return the link. |
|
98 | + return "<a class=\"wl-entity-page-link\" $title_attribute href=\"{$this->href}\"$attributes_html>{$this->label}</a>"; |
|
99 | + } |
|
100 | 100 | |
101 | 101 | } |
@@ -19,24 +19,24 @@ discard block |
||
19 | 19 | */ |
20 | 20 | private $object_link_provider; |
21 | 21 | |
22 | - public function __construct( $entity_url, $id ) { |
|
22 | + public function __construct($entity_url, $id) { |
|
23 | 23 | $this->entity_url = $entity_url; |
24 | 24 | $this->id = $id; |
25 | 25 | $this->object_link_provider = Object_Link_Provider::get_instance(); |
26 | - $this->type = $this->object_link_provider->get_object_type( $entity_url ); |
|
26 | + $this->type = $this->object_link_provider->get_object_type($entity_url); |
|
27 | 27 | } |
28 | 28 | |
29 | - public static function create( $entity_url, $id ) { |
|
30 | - return new Link_Builder( $entity_url, $id ); |
|
29 | + public static function create($entity_url, $id) { |
|
30 | + return new Link_Builder($entity_url, $id); |
|
31 | 31 | } |
32 | 32 | |
33 | - public function label( $label ) { |
|
33 | + public function label($label) { |
|
34 | 34 | $this->label = $label; |
35 | 35 | |
36 | 36 | return $this; |
37 | 37 | } |
38 | 38 | |
39 | - public function href( $href ) { |
|
39 | + public function href($href) { |
|
40 | 40 | $this->href = $href; |
41 | 41 | |
42 | 42 | return $this; |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | * @since 3.26.0 |
50 | 50 | */ |
51 | 51 | $default_attributes = array( |
52 | - 'id' => implode( ';', $this->object_link_provider->get_same_as_uris( $this->id, $this->type ) ), |
|
52 | + 'id' => implode(';', $this->object_link_provider->get_same_as_uris($this->id, $this->type)), |
|
53 | 53 | ); |
54 | 54 | |
55 | 55 | /** |
@@ -57,10 +57,10 @@ discard block |
||
57 | 57 | * Additional parameter {@link $this->type} is added to the filter denoting the type of |
58 | 58 | * the entity url by the enum values {@link Object_Type_Enum} |
59 | 59 | */ |
60 | - $attributes = apply_filters( 'wl_anchor_data_attributes', $default_attributes, $this->id, $this->type ); |
|
60 | + $attributes = apply_filters('wl_anchor_data_attributes', $default_attributes, $this->id, $this->type); |
|
61 | 61 | $attributes_html = ''; |
62 | - foreach ( $attributes as $key => $value ) { |
|
63 | - $attributes_html .= ' data-' . esc_html( $key ) . '="' . esc_attr( $value ) . '" '; |
|
62 | + foreach ($attributes as $key => $value) { |
|
63 | + $attributes_html .= ' data-'.esc_html($key).'="'.esc_attr($value).'" '; |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | return $attributes_html; |
@@ -78,9 +78,9 @@ discard block |
||
78 | 78 | private function get_title_attribute() { |
79 | 79 | |
80 | 80 | // Get an alternative title. |
81 | - $title = $this->object_link_provider->get_link_title( $this->id, $this->label, $this->type ); |
|
82 | - if ( ! empty( $title ) ) { |
|
83 | - return 'title="' . esc_attr( $title ) . '"'; |
|
81 | + $title = $this->object_link_provider->get_link_title($this->id, $this->label, $this->type); |
|
82 | + if ( ! empty($title)) { |
|
83 | + return 'title="'.esc_attr($title).'"'; |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | return ''; |