PluginProbe
SweepPress: Website Cleanup and Optimization / trunk
SweepPress: Website Cleanup and Optimization vtrunk
trunk 1.1 1.2 1.3 1.4 1.4.1 1.5 1.6 1.7 1.8 2.0 2.1 2.1.1 2.2 2.3 2.3.1 2.4 2.4.1 2.4.2 2.5 2.6 3.0 3.1 3.1.1 3.2 All 39 releases
sweeppress / forms / content-sweep.php

content-sweep.php in SweepPress: Website Cleanup and Optimization trunk, at forms/content-sweep.php

249 lines 10.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 use Dev4Press\Plugin\SweepPress\Basic\Database;
4 use Dev4Press\v55\Core\Quick\Sanitize;
5 use function Dev4Press\v55\Functions\panel;
6
7 if ( ! defined( 'ABSPATH' ) ) {
8 exit;
9 }
10
11 $method = sweeppress_settings()->get_method();
12 $list = sweeppress_core()->available();
13
14 $total = 0;
15 $active = 0;
16 $items = array();
17 $categories = array();
18 $_status = array();
19
20 foreach ( $list as $category => $sweepers ) {
21 $active_for_category = 0;
22
23 foreach ( $sweepers as $sweeper ) {
24 $_status[ $sweeper->get_code() ] = $method == 'normal' || ( $method == 'partial' && ! $sweeper->has_high_system_requirements() );
25
26 if ( ! $_status[ $sweeper->get_code() ] && $sweeper->has_cached_data() ) {
27 $_status[ $sweeper->get_code() ] = true;
28 }
29
30 $total ++;
31
32 if ( $_status[ $sweeper->get_code() ] ) {
33 if ( $sweeper->is_sweepable() ) {
34 $active ++;
35 $active_for_category ++;
36 }
37 } else {
38 $active ++;
39 $active_for_category ++;
40 }
41 }
42
43 $categories[ $category ] = $active_for_category;
44 }
45
46 Database::i();
47
48 ?>
49 <div class="d4p-content d4p-sweeper-content">
50 <?php require SWEEPPRESS_PATH . 'forms/misc-notices-backup.php'; ?>
51
52 <div id="sweeppress-results-wrapper" class="d4p-group" style="max-width: 1000px" hidden>
53 <h3><?php esc_html_e( 'Sweep Progress Report', 'sweeppress' ); ?></h3>
54 <div class="d4p-group-inner">
55 <div id="sweeppress-results-sweeper">
56 <div class="sweeppress-results-loader">
57 <i class="d4p-icon d4p-ui-spinner d4p-icon-spin"></i>
58 <span><?php esc_html_e( 'Please wait for the sweeping to finish...', 'sweeppress' ); ?></span>
59 </div>
60 </div>
61 </div>
62 </div>
63 <div class="sweeppress-sweepers-wrapper">
64 <div class="sweeppress-sweepers-controls">
65 <dl class="sweeppress-list">
66 <dt><?php esc_html_e( 'Sweepers Available', 'sweeppress' ); ?></dt>
67 <dd>
68 <?php
69
70 printf( esc_html__( 'Active: %s / Total: %s', 'sweeppress' ), '<strong>' . esc_html( $active ) . '</strong>', '<strong>' . esc_html( $total ) . '</strong>' );
71
72 if ( $active < $total ) {
73 echo '<button class="toggle-empty-tasks" type="button" title="' . esc_attr__( 'Toggle Empty Sweepers', 'sweeppress' ) . '" aria-expanded="false"><i aria-hidden="true" class="d4p-icon d4p-ui-eye"></i></button>';
74 }
75
76 ?>
77 </dd>
78 </dl>
79 </div>
80
81 <?php
82
83 foreach ( $list as $category => $sweepers ) {
84 echo '<h4 data-cat="' . esc_attr( $category ) . '" id="sweeper-category-' . esc_attr( $category ) . '" class="sweeper-category-label ' . ( $categories[ $category ] == 0 ? 'empty-sweeper-category' : '' ) . '">' . esc_html( sweeppress_core()->get_category_label( $category ) ) . '</h4>';
85
86 foreach ( $sweepers as $sweeper ) {
87 $run = $_status[ $sweeper->get_code() ];
88 $is = $run && $sweeper->is_sweepable();
89
90 $classes = array(
91 'sweeppress-item-wrapper',
92 'sweeppress-item-cat-' . $sweeper->get_category(),
93 );
94
95 if ( $run && ! $is ) {
96 $classes[] = 'empty-sweeper';
97 }
98
99 $affected_tables = $sweeper->affected_tables();
100
101 ?>
102
103 <div class="<?php echo Sanitize::html_classes( $classes ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>">
104 <h5>
105 <?php
106
107 $_toggle = $is && $sweeper->has_empty_tasks() && ! $sweeper->is_no_size();
108
109 echo esc_html( $sweeper->title() );
110 echo '<button class="toggle-section toggle-help" type="button" title="' . esc_attr__( 'Toggle Help', 'sweeppress' ) . '" aria-expanded="false" aria-controls="sweeper-info-' . esc_attr( $sweeper->get_unique_id() ) . '"><i aria-hidden="true" class="d4p-icon d4p-ui-question-sqaure"></i></button>';
111
112 if ( ! empty( $sweeper->limitations() ) ) {
113 echo '<button class="toggle-section toggle-limits" type="button" title="' . esc_attr__( 'Toggle Limitations', 'sweeppress' ) . '" aria-expanded="false" aria-controls="sweeper-limit-' . esc_attr( $sweeper->get_unique_id() ) . '"><i aria-hidden="true" class="d4p-icon d4p-ui-exclamation-square"></i></button>';
114 }
115
116 if ( ! empty( $affected_tables ) ) {
117 echo '<button class="toggle-section toggle-tables" type="button" title="' . esc_attr__( 'Toggle Affected Tables', 'sweeppress' ) . '" aria-expanded="false" aria-controls="sweeper-tables-' . esc_attr( $sweeper->get_unique_id() ) . '"><i aria-hidden="true" class="d4p-icon d4p-ui-database"></i></button>';
118 }
119
120 echo '<button style="display: ' . ( $_toggle ? 'inline' : 'none' ) . '" class="toggle-empty" type="button" title="' . esc_attr__( 'Toggle Empty Tasks', 'sweeppress' ) . '" aria-expanded="false"><i aria-hidden="true" class="d4p-icon d4p-ui-eye"></i></button>';
121
122 if ( $sweeper->for_backup() ) {
123 echo '<span class="flat-system" title="' . esc_attr__( 'This sweeper supports data backup before removal.', 'sweeppress' ) . '"><i class="d4p-icon d4p-ui-archive" style="color: #00A"></i></span>';
124 }
125
126 if ( $sweeper->has_high_system_requirements() ) {
127 echo '<span class="flat-system" title="' . esc_attr__( 'This sweeper estimation process has high system requirements and it can be slow to estimate.', 'sweeppress' ) . '"><i class="d4p-icon d4p-ui-gauge-bolt"></i></span>';
128 }
129
130 if ( $sweeper->has_preview_url() ) {
131 echo '<span class="flat-system" title="' . esc_attr__( 'You can preview data that this sweeper will remove.', 'sweeppress' ) . '"><a target="_blank" href="' . $sweeper->get_preview_url() . '"><i aria-label="' . esc_attr__( 'Preview Data.', 'sweeppress' ) . '" class="d4p-icon d4p-ui-search" style="color: #00A"></i></a></span>';
132 }
133
134 echo '<input style="display: ' . ( $is ? 'block' : 'none' ) . '" class="sweeppress-sweeper-check" type="checkbox" />';
135
136 ?>
137 </h5>
138 <div class="sweeppress-item-help" hidden id="sweeper-info-<?php echo esc_attr( $sweeper->get_unique_id() ); ?>">
139 <p>
140 <?php echo esc_html( $sweeper->description() ); ?>
141 </p>
142 <?php
143
144 if ( ! empty( $sweeper->help() ) ) {
145 echo wp_kses_post( sweeppress_strings_array_to_list( $sweeper->help() ) );
146
147 $_last_used = sweeppress_settings()->get_sweeper_last_used_timestamp( $sweeper->get_code() );
148
149 if ( $_last_used > 0 ) {
150 echo '<div class="sweeppress-item-last-used">' . sprintf( esc_html__( 'This sweeper was last used: %s ago.', 'sweeppress' ), '<strong>' . esc_html( human_time_diff( time(), $_last_used ) ) . '</strong>' ) . '</div>';
151 }
152 }
153
154 ?>
155 </div>
156 <?php
157
158 if ( ! empty( $affected_tables ) ) {
159 ?>
160
161 <div class="sweeppress-item-tables" hidden id="sweeper-tables-<?php echo esc_attr( $sweeper->get_unique_id() ); ?>">
162 <p><?php esc_html_e( 'This sweeper affects database tables listed below.', 'sweeppress' ); ?></p>
163 <ul>
164 <li><?php echo join( '</li><li>', $affected_tables ); // phpcs:ignore WordPress.Security.EscapeOutput ?></li>
165 </ul>
166 </div>
167
168 <?php
169 }
170
171 if ( ! empty( $sweeper->limitations() ) ) {
172 ?>
173
174 <div class="sweeppress-item-limit" hidden id="sweeper-limit-<?php echo esc_attr( $sweeper->get_unique_id() ); ?>">
175 <p><?php esc_html_e( 'This sweeper has few limitations listed below.', 'sweeppress' ); ?></p>
176 <?php echo wp_kses_post( sweeppress_strings_array_to_list( $sweeper->limitations() ) ); ?>
177 </div>
178
179 <?php
180 }
181
182 if ( $sweeper->has_days_to_keep() && sweeppress_settings()->get( 'show_keep_days_notices', 'sweepers' ) ) {
183 ?>
184
185 <div class="sweeppress-item-days-notice">
186 <?php
187
188 if ( $sweeper->get_days_to_keep() > 0 ) {
189 echo sprintf( esc_html__( 'Only items older than %s days are included in the estimate, and will be affected by the sweeping. This is done to protect the latest items in case they are needed later.', 'sweeppress' ), $sweeper->get_days_to_keep() );
190 } else {
191 echo esc_html__( 'All items are included in the estimate, and will be affected by sweeping. This sweeper supports setting the number of days of items to keep from this sweeper.', 'sweeppress' );
192 }
193
194 echo ' ' . esc_html__( 'If you want to change the days limit, you can do it from plugin settings panel.', 'sweeppress' );
195 echo ' <a href="' . panel()->a()->panel_url( 'settings', 'sweepers' ) . '">' . esc_html__( 'Sweepers Settings', 'sweeppress' ) . '</a>';
196
197 ?>
198 </div>
199
200 <?php
201 }
202
203 ?>
204 <div class="sweeppress-item-inside">
205 <?php
206
207 if ( $run ) {
208 include 'misc-sweep-single.php';
209 } else {
210 ?>
211
212 <div class="notice inline notice-info sweeppress-item-run">
213 <p><strong><?php
214
215 if ( $sweeper->has_high_system_requirements() ) {
216 esc_html_e( 'This sweeper estimation query can be slow, and based on your plugin performance settings and database size, it is not run automatically.', 'sweeppress' );
217 } else {
218 esc_html_e( 'Based on your plugin performance settings and database size, this sweeper estimate has not been run.', 'sweeppress' );
219 }
220
221 ?></strong></p>
222 <p>
223 <?php esc_html_e( 'Click the button to run this sweeper in the background.', 'sweeppress' ); ?>
224 </p>
225 <p>
226 <button data-cache="skip" data-sweeper="<?php echo esc_attr( $sweeper->get_code() ); ?>" data-nonce="<?php echo esc_attr( wp_create_nonce( 'sweeppress-run-estimate-' . $sweeper->get_code() ) ); ?>" type="button" class="button-secondary"><?php esc_html_e( 'Estimate This Sweeper', 'sweeppress' ); ?></button>
227 </p>
228 </div>
229 <div class="sweeppress-item-run-loader">
230 <i class="d4p-icon d4p-ui-spinner d4p-icon-spin d4p-icon-fw"></i>
231 <span><?php esc_html_e( 'Please wait...', 'sweeppress' ); ?></span>
232 </div>
233
234 <?php
235 }
236
237 ?>
238 </div>
239 </div>
240
241 <?php
242 }
243 }
244
245 ?>
246 </div>
247 <input type="hidden" value="<?php echo wp_create_nonce( 'sweeppress-sweep-panel-sweeper' ); // phpcs:ignore WordPress.Security.EscapeOutput ?>" name="sweeppress[nonce]"/>
248 </div>
249