@@ -56,137 +56,12 @@ public function register_rest_endpoint() {
5656 *
5757 * This method handles a REST request and returns a REST response.
5858 *
59- * @param \WP_REST_Request $request The REST request object.
60- *
6159 * @return \WP_REST_Response The REST response object containing the stats.
6260 */
63- public function get_stats ( \WP_REST_Request $ request ) {
64- $ data = $ request ->get_json_params ();
65-
66- $ data = [];
67-
68- // Get the number of pending updates.
69- $ data ['pending_updates ' ] = \wp_get_update_data ()['counts ' ]['total ' ];
70-
71- // Get number of content from any public post-type, published in the past week.
72- $ data ['weekly_posts ' ] = count (
73- \get_posts (
74- [
75- 'post_status ' => 'publish ' ,
76- 'post_type ' => 'post ' ,
77- 'date_query ' => [ [ 'after ' => '1 week ago ' ] ],
78- 'posts_per_page ' => 10 ,
79- ]
80- )
81- );
82-
83- // Get the number of activities in the past week.
84- $ data ['activities ' ] = count (
85- \progress_planner ()->get_activities__query ()->query_activities (
86- [
87- 'start_date ' => new \DateTime ( '-7 days ' ),
88- ]
89- )
90- );
91-
92- // Get the website activity score.
93- $ activity_score = new Activity_Scores ();
94- $ data ['website_activity ' ] = [
95- 'score ' => $ activity_score ->get_score (),
96- 'checklist ' => $ activity_score ->get_checklist_results (),
97- ];
98-
99- // Get the badges.
100- $ badges = array_merge (
101- \progress_planner ()->get_badges ()->get_badges ( 'content ' ),
102- \progress_planner ()->get_badges ()->get_badges ( 'maintenance ' ),
103- \progress_planner ()->get_badges ()->get_badges ( 'monthly_flat ' )
104- );
105-
106- $ data ['badges ' ] = [];
107- foreach ( $ badges as $ badge ) {
108- $ data ['badges ' ][ $ badge ->get_id () ] = array_merge (
109- [
110- 'id ' => $ badge ->get_id (),
111- 'name ' => $ badge ->get_name (),
112- ],
113- $ badge ->progress_callback ()
114- );
115- }
116-
117- $ data ['latest_badge ' ] = \progress_planner ()->get_badges ()->get_latest_completed_badge ();
118-
119- $ scores = \progress_planner ()->get_ui__chart ()->get_chart_data (
120- [
121- 'items_callback ' => function ( $ start_date , $ end_date ) {
122- return \progress_planner ()->get_activities__query ()->query_activities (
123- [
124- 'start_date ' => $ start_date ,
125- 'end_date ' => $ end_date ,
126- ]
127- );
128- },
129- 'dates_params ' => [
130- 'start_date ' => \DateTime::createFromFormat ( 'Y-m-d ' , \gmdate ( 'Y-m-01 ' ) )->modify ( '-6 months ' ),
131- 'end_date ' => new \DateTime (),
132- 'frequency ' => 'monthly ' ,
133- 'format ' => 'M ' ,
134- ],
135- 'count_callback ' => function ( $ activities , $ date ) {
136- $ score = 0 ;
137- foreach ( $ activities as $ activity ) {
138- $ score += $ activity ->get_points ( $ date );
139- }
140- return $ score * 100 / Base::SCORE_TARGET ;
141- },
142- 'normalized ' => true ,
143- 'max ' => 100 ,
144- ]
145- );
146-
147- $ data ['scores ' ] = [];
148- foreach ( $ scores as $ item ) {
149- $ data ['scores ' ][] = [
150- 'label ' => $ item ['label ' ],
151- 'value ' => $ item ['score ' ],
152- ];
153- }
154-
155- // The website URL.
156- $ data ['website ' ] = \home_url ();
157-
158- // Timezone offset.
159- $ data ['timezone_offset ' ] = \wp_timezone ()->getOffset ( new \DateTime ( 'midnight ' ) ) / 3600 ;
160- $ ravis_recommendations = \progress_planner ()->get_suggested_tasks_db ()->get_tasks_by ( [ 'post_status ' => 'publish ' ] );
161- $ data ['recommendations ' ] = [];
162- foreach ( $ ravis_recommendations as $ recommendation ) {
163- $ r = [
164- 'id ' => $ recommendation ->task_id ,
165- 'title ' => $ recommendation ->post_title ,
166- 'url ' => $ recommendation ->url ,
167- 'provider_id ' => $ recommendation ->get_provider_id (),
168- ];
169-
170- if ( 'user ' === $ recommendation ->get_provider_id () ) {
171- $ r ['points ' ] = (int ) $ recommendation ->points ;
172- }
173- $ data ['recommendations ' ][] = $ r ;
174- }
175-
176- $ data ['plugin_url ' ] = \esc_url ( \get_admin_url ( null , 'admin.php?page=progress-planner ' ) );
177-
178- $ active_plugins = \get_option ( 'active_plugins ' );
179- $ data ['plugins ' ] = [];
180- foreach ( $ active_plugins as $ plugin ) {
181- $ plugin_data = \get_plugin_data ( \WP_PLUGIN_DIR . '/ ' . $ plugin );
182- $ data ['plugins ' ][] = [
183- 'plugin ' => $ plugin ,
184- 'name ' => $ plugin_data ['Name ' ] ?? 'N/A ' , // @phpstan-ignore-line nullCoalesce.offset
185- 'version ' => $ plugin_data ['Version ' ] ?? 'N/A ' , // @phpstan-ignore-line nullCoalesce.offset
186- ];
187- }
61+ public function get_stats () {
62+ $ system_status = new \Progress_Planner \Utils \System_Status ();
18863
189- return new \WP_REST_Response ( $ data );
64+ return new \WP_REST_Response ( $ system_status -> get_system_status () );
19065 }
19166
19267 /**
0 commit comments