@@ -21,65 +21,65 @@ discard block |
||
21 | 21 | */ |
22 | 22 | function __wl_dashboard__load() { |
23 | 23 | |
24 | - // Dashboard is available only for Food Kg and Gardening Kg atm |
|
25 | - // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
|
26 | - if ( ! apply_filters( 'wl_feature__enable__food-kg', false ) && ! apply_filters( 'wl_feature__enable__gardening-kg', false ) ) { |
|
27 | - return; |
|
28 | - } |
|
24 | + // Dashboard is available only for Food Kg and Gardening Kg atm |
|
25 | + // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
|
26 | + if ( ! apply_filters( 'wl_feature__enable__food-kg', false ) && ! apply_filters( 'wl_feature__enable__gardening-kg', false ) ) { |
|
27 | + return; |
|
28 | + } |
|
29 | 29 | |
30 | - // Autoloader for plugin itself. |
|
31 | - if ( file_exists( __DIR__ . '/vendor/autoload.php' ) ) { |
|
32 | - require_once __DIR__ . '/vendor/autoload.php'; |
|
33 | - } |
|
30 | + // Autoloader for plugin itself. |
|
31 | + if ( file_exists( __DIR__ . '/vendor/autoload.php' ) ) { |
|
32 | + require_once __DIR__ . '/vendor/autoload.php'; |
|
33 | + } |
|
34 | 34 | |
35 | - $container_builder = new ContainerBuilder(); |
|
36 | - $loader = new YamlFileLoader( $container_builder, new FileLocator( __DIR__ ) ); |
|
37 | - $loader->load( 'services.yml' ); |
|
38 | - $container_builder->compile(); |
|
35 | + $container_builder = new ContainerBuilder(); |
|
36 | + $loader = new YamlFileLoader( $container_builder, new FileLocator( __DIR__ ) ); |
|
37 | + $loader->load( 'services.yml' ); |
|
38 | + $container_builder->compile(); |
|
39 | 39 | |
40 | - /** |
|
41 | - * @var $rest_controller Rest_Controller |
|
42 | - */ |
|
43 | - $rest_controller = $container_builder->get( 'Wordlift\Modules\Dashboard\Synchronization\Rest_Controller' ); |
|
44 | - $rest_controller->register_hooks(); |
|
40 | + /** |
|
41 | + * @var $rest_controller Rest_Controller |
|
42 | + */ |
|
43 | + $rest_controller = $container_builder->get( 'Wordlift\Modules\Dashboard\Synchronization\Rest_Controller' ); |
|
44 | + $rest_controller->register_hooks(); |
|
45 | 45 | |
46 | - /** |
|
47 | - * @var $term_entity_match_rest_controller Term_Entity_Match_Rest_Controller |
|
48 | - */ |
|
49 | - $term_entity_match_rest_controller = $container_builder->get( Term_Entity_Match_Rest_Controller::class ); |
|
50 | - $term_entity_match_rest_controller->register_hooks(); |
|
46 | + /** |
|
47 | + * @var $term_entity_match_rest_controller Term_Entity_Match_Rest_Controller |
|
48 | + */ |
|
49 | + $term_entity_match_rest_controller = $container_builder->get( Term_Entity_Match_Rest_Controller::class ); |
|
50 | + $term_entity_match_rest_controller->register_hooks(); |
|
51 | 51 | |
52 | - /** |
|
53 | - * @var $term_entity_match_rest_controller \Wordlift\Modules\Dashboard\Post_Entity_Match\Post_Entity_Match_Rest_Controller |
|
54 | - */ |
|
55 | - $post_entity_match_rest_controller = $container_builder->get( \Wordlift\Modules\Dashboard\Post_Entity_Match\Post_Entity_Match_Rest_Controller::class ); |
|
56 | - $post_entity_match_rest_controller->register_hooks(); |
|
52 | + /** |
|
53 | + * @var $term_entity_match_rest_controller \Wordlift\Modules\Dashboard\Post_Entity_Match\Post_Entity_Match_Rest_Controller |
|
54 | + */ |
|
55 | + $post_entity_match_rest_controller = $container_builder->get( \Wordlift\Modules\Dashboard\Post_Entity_Match\Post_Entity_Match_Rest_Controller::class ); |
|
56 | + $post_entity_match_rest_controller->register_hooks(); |
|
57 | 57 | |
58 | - /** |
|
59 | - * @var $synchronization_service Synchronization_Service |
|
60 | - */ |
|
61 | - $synchronization_service = $container_builder->get( 'Wordlift\Modules\Dashboard\Synchronization\Synchronization_Service' ); |
|
62 | - $synchronization_service->register_hooks(); |
|
58 | + /** |
|
59 | + * @var $synchronization_service Synchronization_Service |
|
60 | + */ |
|
61 | + $synchronization_service = $container_builder->get( 'Wordlift\Modules\Dashboard\Synchronization\Synchronization_Service' ); |
|
62 | + $synchronization_service->register_hooks(); |
|
63 | 63 | |
64 | - $app_settings = $container_builder->get( App_Settings::class ); |
|
65 | - $app_settings->register_hooks(); |
|
64 | + $app_settings = $container_builder->get( App_Settings::class ); |
|
65 | + $app_settings->register_hooks(); |
|
66 | 66 | |
67 | - /** Admin Menu */ |
|
68 | - add_action( |
|
69 | - 'admin_menu', |
|
70 | - function () { |
|
71 | - add_submenu_page( 'wl_admin_menu', __( 'Dashboard', 'wordlift' ), __( 'Dashboard', 'wordlift' ), 'manage_options', 'wl_admin_menu', '_wl_dashboard__main' ); |
|
72 | - }, |
|
73 | - 9 |
|
74 | - ); |
|
67 | + /** Admin Menu */ |
|
68 | + add_action( |
|
69 | + 'admin_menu', |
|
70 | + function () { |
|
71 | + add_submenu_page( 'wl_admin_menu', __( 'Dashboard', 'wordlift' ), __( 'Dashboard', 'wordlift' ), 'manage_options', 'wl_admin_menu', '_wl_dashboard__main' ); |
|
72 | + }, |
|
73 | + 9 |
|
74 | + ); |
|
75 | 75 | |
76 | - add_action( |
|
77 | - '_wl_dashboard__main', |
|
78 | - function () { |
|
79 | - wp_enqueue_script( WL_ANGULAR_APP_SCRIPT_HANDLE ); |
|
80 | - $iframe_src = WL_ANGULAR_APP_URL . '#/admin/dashboard'; |
|
81 | - // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
|
82 | - echo " |
|
76 | + add_action( |
|
77 | + '_wl_dashboard__main', |
|
78 | + function () { |
|
79 | + wp_enqueue_script( WL_ANGULAR_APP_SCRIPT_HANDLE ); |
|
80 | + $iframe_src = WL_ANGULAR_APP_URL . '#/admin/dashboard'; |
|
81 | + // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
|
82 | + echo " |
|
83 | 83 | <style> |
84 | 84 | #wlx-plugin-app { |
85 | 85 | margin-left: -20px; |
@@ -90,8 +90,8 @@ discard block |
||
90 | 90 | <iframe id='wlx-plugin-app' src='$iframe_src'></iframe> |
91 | 91 | "; |
92 | 92 | |
93 | - } |
|
94 | - ); |
|
93 | + } |
|
94 | + ); |
|
95 | 95 | |
96 | 96 | } |
97 | 97 |
@@ -14,21 +14,21 @@ |
||
14 | 14 | use Wordlift\Modules\Common\Symfony\Component\DependencyInjection\Loader\YamlFileLoader; |
15 | 15 | |
16 | 16 | if ( ! defined( 'WL_ANGULAR_APP_URL' ) ) { |
17 | - define( 'WL_ANGULAR_APP_URL', esc_url( plugin_dir_url( __DIR__ ) . 'app/app/iframe.html' ) . '?v=' . WORDLIFT_VERSION ); |
|
17 | + define( 'WL_ANGULAR_APP_URL', esc_url( plugin_dir_url( __DIR__ ) . 'app/app/iframe.html' ) . '?v=' . WORDLIFT_VERSION ); |
|
18 | 18 | } |
19 | 19 | |
20 | 20 | if ( ! defined( 'WL_ANGULAR_APP_SCRIPT_HANDLE' ) ) { |
21 | - define( 'WL_ANGULAR_APP_SCRIPT_HANDLE', 'wl-angular-app' ); |
|
21 | + define( 'WL_ANGULAR_APP_SCRIPT_HANDLE', 'wl-angular-app' ); |
|
22 | 22 | } |
23 | 23 | |
24 | 24 | // Load the rest of the module only on admin calls. |
25 | 25 | if ( ! is_admin() ) { |
26 | - return; |
|
26 | + return; |
|
27 | 27 | } |
28 | 28 | |
29 | 29 | // Autoloader for plugin itself. |
30 | 30 | if ( file_exists( __DIR__ . '/vendor/autoload.php' ) ) { |
31 | - require_once __DIR__ . '/vendor/autoload.php'; |
|
31 | + require_once __DIR__ . '/vendor/autoload.php'; |
|
32 | 32 | } |
33 | 33 | |
34 | 34 | $container_builder = new ContainerBuilder(); |
@@ -17,117 +17,117 @@ |
||
17 | 17 | |
18 | 18 | class Post_Jsonld { |
19 | 19 | |
20 | - public function init() { |
|
21 | - add_filter( 'wl_post_jsonld_array', array( $this, 'wl_post_jsonld_array' ), 10, 2 ); |
|
22 | - } |
|
23 | - |
|
24 | - public function wl_post_jsonld_array( $data, $post_id ) { |
|
25 | - |
|
26 | - $relations = $data['relations']; |
|
27 | - |
|
28 | - if ( ! is_a( $relations, 'Wordlift\Relation\Relations' ) ) { |
|
29 | - return $data; |
|
30 | - } |
|
31 | - |
|
32 | - $term_relations = $this->get_term_relations( $post_id ); |
|
33 | - |
|
34 | - if ( ! $term_relations ) { |
|
35 | - return $data; |
|
36 | - } |
|
37 | - |
|
38 | - $references = $data['references']; |
|
39 | - $jsonld = $data['jsonld']; |
|
40 | - $references_infos = $data['references_infos']; |
|
41 | - |
|
42 | - $relations->add( ...$term_relations ); |
|
43 | - $term_mentions = $this->get_term_mentions( $term_relations ); |
|
44 | - |
|
45 | - if ( count( $term_mentions ) > 0 ) { |
|
46 | - $existing_mentions = array_key_exists( 'mentions', $jsonld ) ? $jsonld['mentions'] : array(); |
|
47 | - $jsonld['mentions'] = array_merge( $existing_mentions, $term_mentions ); |
|
48 | - } |
|
49 | - |
|
50 | - return array( |
|
51 | - 'jsonld' => $jsonld, |
|
52 | - 'references' => $references, |
|
53 | - 'references_infos' => $references_infos, |
|
54 | - 'relations' => $relations, |
|
55 | - ); |
|
56 | - } |
|
57 | - |
|
58 | - /** |
|
59 | - * @param $post_id |
|
60 | - * @param $relations Relations |
|
61 | - * |
|
62 | - * @return array<Relation> Returns a list of term relations. |
|
63 | - */ |
|
64 | - private function get_term_relations( $post_id ) { |
|
65 | - |
|
66 | - /** @var WP_Taxonomy[] $taxonomies_for_post */ |
|
67 | - $taxonomies_for_post = get_object_taxonomies( get_post_type( $post_id ), 'objects' ); |
|
68 | - |
|
69 | - // now we need to collect all terms attached to this post. |
|
70 | - $terms = array(); |
|
71 | - |
|
72 | - foreach ( $taxonomies_for_post as $taxonomy ) { |
|
73 | - // Please note that `$taxonomy->publicly_queryable is only WP 4.7+ |
|
74 | - if ( 'wl_entity_type' === $taxonomy->name || ! $taxonomy->public ) { |
|
75 | - continue; |
|
76 | - } |
|
77 | - |
|
78 | - $taxonomy_terms = get_the_terms( $post_id, $taxonomy->name ); |
|
79 | - if ( is_array( $taxonomy_terms ) ) { |
|
80 | - $terms = array_merge( $terms, $taxonomy_terms ); |
|
81 | - } |
|
82 | - } |
|
83 | - |
|
84 | - // Convert everything to the Term Reference. |
|
85 | - return array_filter( |
|
86 | - array_map( |
|
87 | - function ( $term ) use ( $post_id ) { |
|
88 | - |
|
89 | - if ( 1 === $term->term_id ) { |
|
90 | - return false; |
|
91 | - } |
|
92 | - |
|
93 | - /** |
|
94 | - * @var WP_Term $term |
|
95 | - */ |
|
96 | - if ( Wordpress_Term_Content_Service::get_instance() |
|
97 | - ->get_entity_id( Wordpress_Content_Id::create_term( $term->term_id ) ) |
|
98 | - ) { |
|
99 | - return new Relation( |
|
100 | - Wordpress_Content_Id::create_post( $post_id ), |
|
101 | - Wordpress_Content_Id::create_term( $term->term_id ), |
|
102 | - WL_WHAT_RELATION |
|
103 | - ); |
|
104 | - } |
|
105 | - |
|
106 | - return false; |
|
107 | - }, |
|
108 | - $terms |
|
109 | - ) |
|
110 | - ); |
|
111 | - |
|
112 | - } |
|
113 | - |
|
114 | - /** |
|
115 | - * @param $term_relations array<Relation> |
|
116 | - * |
|
117 | - * @return array |
|
118 | - */ |
|
119 | - private function get_term_mentions( $term_relations ) { |
|
120 | - |
|
121 | - return array_map( |
|
122 | - function ( $term_relation ) { |
|
123 | - return array( |
|
124 | - '@id' => Wordpress_Term_Content_Service::get_instance() |
|
125 | - ->get_entity_id( $term_relation->get_object() ), |
|
126 | - ); |
|
127 | - }, |
|
128 | - $term_relations |
|
129 | - ); |
|
130 | - |
|
131 | - } |
|
20 | + public function init() { |
|
21 | + add_filter( 'wl_post_jsonld_array', array( $this, 'wl_post_jsonld_array' ), 10, 2 ); |
|
22 | + } |
|
23 | + |
|
24 | + public function wl_post_jsonld_array( $data, $post_id ) { |
|
25 | + |
|
26 | + $relations = $data['relations']; |
|
27 | + |
|
28 | + if ( ! is_a( $relations, 'Wordlift\Relation\Relations' ) ) { |
|
29 | + return $data; |
|
30 | + } |
|
31 | + |
|
32 | + $term_relations = $this->get_term_relations( $post_id ); |
|
33 | + |
|
34 | + if ( ! $term_relations ) { |
|
35 | + return $data; |
|
36 | + } |
|
37 | + |
|
38 | + $references = $data['references']; |
|
39 | + $jsonld = $data['jsonld']; |
|
40 | + $references_infos = $data['references_infos']; |
|
41 | + |
|
42 | + $relations->add( ...$term_relations ); |
|
43 | + $term_mentions = $this->get_term_mentions( $term_relations ); |
|
44 | + |
|
45 | + if ( count( $term_mentions ) > 0 ) { |
|
46 | + $existing_mentions = array_key_exists( 'mentions', $jsonld ) ? $jsonld['mentions'] : array(); |
|
47 | + $jsonld['mentions'] = array_merge( $existing_mentions, $term_mentions ); |
|
48 | + } |
|
49 | + |
|
50 | + return array( |
|
51 | + 'jsonld' => $jsonld, |
|
52 | + 'references' => $references, |
|
53 | + 'references_infos' => $references_infos, |
|
54 | + 'relations' => $relations, |
|
55 | + ); |
|
56 | + } |
|
57 | + |
|
58 | + /** |
|
59 | + * @param $post_id |
|
60 | + * @param $relations Relations |
|
61 | + * |
|
62 | + * @return array<Relation> Returns a list of term relations. |
|
63 | + */ |
|
64 | + private function get_term_relations( $post_id ) { |
|
65 | + |
|
66 | + /** @var WP_Taxonomy[] $taxonomies_for_post */ |
|
67 | + $taxonomies_for_post = get_object_taxonomies( get_post_type( $post_id ), 'objects' ); |
|
68 | + |
|
69 | + // now we need to collect all terms attached to this post. |
|
70 | + $terms = array(); |
|
71 | + |
|
72 | + foreach ( $taxonomies_for_post as $taxonomy ) { |
|
73 | + // Please note that `$taxonomy->publicly_queryable is only WP 4.7+ |
|
74 | + if ( 'wl_entity_type' === $taxonomy->name || ! $taxonomy->public ) { |
|
75 | + continue; |
|
76 | + } |
|
77 | + |
|
78 | + $taxonomy_terms = get_the_terms( $post_id, $taxonomy->name ); |
|
79 | + if ( is_array( $taxonomy_terms ) ) { |
|
80 | + $terms = array_merge( $terms, $taxonomy_terms ); |
|
81 | + } |
|
82 | + } |
|
83 | + |
|
84 | + // Convert everything to the Term Reference. |
|
85 | + return array_filter( |
|
86 | + array_map( |
|
87 | + function ( $term ) use ( $post_id ) { |
|
88 | + |
|
89 | + if ( 1 === $term->term_id ) { |
|
90 | + return false; |
|
91 | + } |
|
92 | + |
|
93 | + /** |
|
94 | + * @var WP_Term $term |
|
95 | + */ |
|
96 | + if ( Wordpress_Term_Content_Service::get_instance() |
|
97 | + ->get_entity_id( Wordpress_Content_Id::create_term( $term->term_id ) ) |
|
98 | + ) { |
|
99 | + return new Relation( |
|
100 | + Wordpress_Content_Id::create_post( $post_id ), |
|
101 | + Wordpress_Content_Id::create_term( $term->term_id ), |
|
102 | + WL_WHAT_RELATION |
|
103 | + ); |
|
104 | + } |
|
105 | + |
|
106 | + return false; |
|
107 | + }, |
|
108 | + $terms |
|
109 | + ) |
|
110 | + ); |
|
111 | + |
|
112 | + } |
|
113 | + |
|
114 | + /** |
|
115 | + * @param $term_relations array<Relation> |
|
116 | + * |
|
117 | + * @return array |
|
118 | + */ |
|
119 | + private function get_term_mentions( $term_relations ) { |
|
120 | + |
|
121 | + return array_map( |
|
122 | + function ( $term_relation ) { |
|
123 | + return array( |
|
124 | + '@id' => Wordpress_Term_Content_Service::get_instance() |
|
125 | + ->get_entity_id( $term_relation->get_object() ), |
|
126 | + ); |
|
127 | + }, |
|
128 | + $term_relations |
|
129 | + ); |
|
130 | + |
|
131 | + } |
|
132 | 132 | |
133 | 133 | } |