PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 5.2.2
MainWP Dashboard: Self-hosted WordPress Management for Agencies v5.2.2
6.2 6.1.8 6.1.7 6.1.6 6.1.5 6.1.4 6.1.3 6.1.2 6.1.1 6.1 6.0.12 6.0.11 4.6.0.1 5.0 5.0.1 5.0.2 5.0.3 5.0.3.1 5.0.3.2 5.1 5.1.1 5.2 5.2.1 5.2.2 5.3 All 153 releases
mainwp / widgets / widget-mainwp-security-issues-widget.php

widget-mainwp-security-issues-widget.php in MainWP Dashboard: Self-hosted WordPress Management for Agencies 5.2.2, at widgets/widget-mainwp-security-issues-widget.php

234 lines 12.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * MainWP Security Widget
4 *
5 * Displays detected security issues on Child Sites.
6 *
7 * @package MainWP/Dashboard
8 */
9
10 namespace MainWP\Dashboard;
11
12 /**
13 * Class MainWP_Security_Issues_Widget
14 *
15 * Detect security issues on CHild Sites & Build Widget.
16 */
17 class MainWP_Security_Issues_Widget { // phpcs:ignore Generic.Classes.OpeningBraceSameLine.ContentAfterBrace -- NOSONAR.
18
19 /**
20 * Method get_class_name()
21 *
22 * @return string __CLASS__ Class Name
23 */
24 public static function get_class_name() {
25 return __CLASS__;
26 }
27
28 /**
29 * Method render_widget()
30 *
31 * Fetch Child Site issues from db & build widget.
32 *
33 * @uses \MainWP\Dashboard\MainWP_DB::query()
34 * @uses \MainWP\Dashboard\MainWP_DB::get_sql_website_by_id()
35 * @uses \MainWP\Dashboard\MainWP_DB::get_sql_search_websites_for_current_user()
36 * @uses \MainWP\Dashboard\MainWP_DB::fetch_object()
37 * @uses \MainWP\Dashboard\MainWP_DB::data_seek()
38 * @uses \MainWP\Dashboard\MainWP_System_Utility::get_current_wpid()
39 * @uses \MainWP\Dashboard\MainWP_Utility::ctype_digit()
40 */
41 public static function render_widget() {
42 $current_wpid = MainWP_System_Utility::get_current_wpid();
43
44 if ( $current_wpid ) {
45 $sql = MainWP_DB::instance()->get_sql_website_by_id( $current_wpid );
46 } else {
47 $sql = MainWP_DB::instance()->get_sql_websites_for_current_user();
48 }
49
50 $websites = MainWP_DB::instance()->query( $sql );
51
52 $total_securityIssues = 0;
53
54 MainWP_DB::data_seek( $websites, 0 );
55 while ( $websites && ( $website = MainWP_DB::fetch_object( $websites ) ) ) {
56 if ( MainWP_Utility::ctype_digit( $website->securityIssues ) ) {
57 $total_securityIssues += $website->securityIssues;
58 }
59 }
60
61 static::render_issues( $websites, $total_securityIssues );
62 }
63
64 /**
65 *
66 * Method render_html_widget().
67 *
68 * Render html themes widget for current site
69 *
70 * @param mixed $websites Array of websites.
71 * @param mixed $total_securityIssues Total security Issues.
72 *
73 * @uses \MainWP\Dashboard\MainWP_DB::fetch_object()
74 * @uses \MainWP\Dashboard\MainWP_DB::data_seek()
75 */
76 public static function render_issues( $websites, $total_securityIssues ) { // phpcs:ignore -- NOSONAR - complex.
77 $is_demo = MainWP_Demo_Handle::is_demo_mode();
78 ?>
79 <div class="mainwp-widget-header">
80 <h3 class="ui header handle-drag">
81 <?php
82 /**
83 * Filter: mainwp_security_issues_widget_title
84 *
85 * Filters the Security Issues widget title text.
86 *
87 * @since 4.1
88 */
89 echo esc_html( apply_filters( 'mainwp_security_issues_widget_title', esc_html__( 'Site Hardening', 'mainwp' ) ) );
90 ?>
91 <div class="sub header"><?php esc_html_e( 'Identify and strengthen weak spots to boost site hardening', 'mainwp' ); ?></div>
92 </h3>
93 </div>
94
95 <?php
96 /**
97 * Action: mainwp_security_issues_widget_top
98 *
99 * Fires at the bottom of the Security Issues widget.
100 *
101 * @since 4.1
102 */
103 do_action( 'mainwp_security_issues_widget_top' );
104 if ( $total_securityIssues > 0 ) {
105 ?>
106 <div class="ui compact grid">
107 <div class="eight wide column">
108 <div class="ui horizontal statistics">
109 <div class="statistic" style="margin: 0px;">
110 <div class="value">
111 <?php echo intval( $total_securityIssues ); ?>
112 </div>
113 <div class="label">
114 <?php echo esc_html( _n( 'Recommendation', 'Recommendations', $total_securityIssues, 'mainwp' ) ); ?>
115 </div>
116 </div>
117 </div>
118 </div>
119 <div class="right aligned middle aligned four wide column">
120 <a href="javascript:void(0)" class="ui fluid button mini basic" id="mainwp-show-security-issues-widget-list" data-tooltip="<?php esc_attr_e( 'Click here to see the list of all sites and detected security issues.', 'mainwp' ); ?>" data-inverted="" data-position="bottom center"><?php esc_html_e( 'See Details', 'mainwp' ); ?></a>
121 </div>
122 <div class="right aligned middle aligned four wide column">
123 <a href="javascript:void(0)" class="<?php echo $is_demo ? 'disabled' : ''; ?> fix-all-security-issues ui fluid button mini green" id="mainwp-fix-all-security-issues-widget-list" data-tooltip="<?php esc_attr_e( 'Clicking this buttin will resolve all detected security issue on all your child sites.', 'mainwp' ); ?>" data-inverted="" data-position="bottom right"><?php esc_html_e( 'Fix All Issues', 'mainwp' ); ?></a>
124 </div>
125 </div>
126 <div class="mainwp-scrolly-overflow">
127 <div id="mainwp-security-issues-widget-list" class="ui middle aligned divided selection list" style="display: none;">
128 <?php
129 $count_security_issues = '';
130 MainWP_DB::data_seek( $websites, 0 );
131 while ( $websites && ( $website = MainWP_DB::fetch_object( $websites ) ) ) {
132 if ( '[]' === $website->securityIssues ) {
133 $count_security_issues = '';
134 } else {
135 $count_security_issues = intval( $website->securityIssues );
136 }
137 ?>
138 <div class="item" <?php echo '' !== $count_security_issues && $count_security_issues > 0 ? 'status="queue"' : ''; ?> siteid="<?php echo intval( $website->id ); ?>">
139 <div class="ui compact grid">
140 <div class="one wide center aligned middle aligned column">
141 <?php if ( 0 === $count_security_issues ) : ?>
142 <span class="ui green small empty circular label"></span>
143 <?php elseif ( '' === $count_security_issues ) : ?>
144 <span class="ui grey small empty circular label"></span>
145 <?php else : ?>
146 <span class="ui red small empty circular label"></span>
147 <?php endif; ?>
148 </div>
149 <div class="twelve wide middle aligned column">
150
151 <a href="
152 <?php
153 /**
154 * Filter: mainwp_security_issues_list_item_title_url
155 *
156 * Filters the Security Issues widget list item title URL.
157 *
158 * @since 4.1
159 */
160 echo esc_url( apply_filters( 'mainwp_security_issues_list_item_title_url', 'admin.php?page=managesites&dashboard=' . $website->id, $website ) );
161 ?>
162 ">
163 <?php
164 /**
165 * Filter: mainwp_security_issues_list_item_title
166 *
167 * Filters the Security Issues widget list item title text.
168 *
169 * @since 4.1
170 */
171 echo esc_attr( stripslashes( apply_filters( 'mainwp_security_issues_list_item_title', $website->name, $website ) ) );
172 ?>
173 </a>
174 <?php if ( 0 === $count_security_issues ) : ?>
175 <div><span class="ui small text"><?php esc_html_e( 'No issues detected', 'mainwp' ); ?></span></div>
176 <?php elseif ( '' === $count_security_issues ) : ?>
177 <div><span class="ui small text"><?php esc_html_e( 'No data available', 'mainwp' ); ?></span></div>
178 <?php else : ?>
179 <div><span class="ui small text"><?php echo esc_html( $count_security_issues ); ?> <?php echo esc_html( _n( 'issue detected', 'issues detected', $count_security_issues, 'mainwp' ) ); ?></span></div>
180 <?php endif; ?>
181 </div>
182 <?php
183 /**
184 * Action: mainwp_security_issues_list_item_column
185 *
186 * Fires before the last (actions) colum in the security issues list.
187 *
188 * Preferred HTML structure:
189 *
190 * <div class="column middle aligned">
191 * Your content here!
192 * </div>
193 *
194 * @param object $website Object containing the child site info.
195 *
196 * @since 4.1
197 */
198 do_action( 'mainwp_security_issues_list_item_column', $website );
199 ?>
200 <div class="three wide middle aligned column">
201 <div class="ui mini icon fluid buttons">
202 <a href="admin.php?page=managesites&scanid=<?php echo esc_attr( $website->id ); ?>" class="ui button basic" data-tooltip="<?php esc_attr_e( 'Click here to see details.', 'mainwp' ); ?>" data-position="left center" data-inverted=""><i class="info icon"></i></a>
203 <?php if ( empty( $count_security_issues ) ) { ?>
204 <a href="javascript:void(0)" class="<?php echo $is_demo ? 'disabled' : ''; ?> unfix-all-site-security-issues ui button basic green" data-position="left center" data-tooltip="<?php esc_attr_e( 'Click here to unfix all security issues on the child site.', 'mainwp' ); ?>" data-inverted=""><i class="wrench horizontally flipped icon"></i></a>
205 <?php } else { ?>
206 <a href="javascript:void(0)" class="<?php echo $is_demo ? 'disabled' : ''; ?> fix-all-site-security-issues ui button green" data-position="left center" data-tooltip="<?php esc_attr_e( 'Click here to fix all security issues on the child site.', 'mainwp' ); ?>" data-inverted=""><i class="wrench icon"></i></a>
207 <?php } ?>
208 </div>
209 </div>
210 </div>
211 </div>
212 <?php } ?>
213 </div>
214 </div>
215 <div class="ui active inverted dimmer" style="display:none" id="mainwp-secuirty-issues-loader"><div class="ui text loader"><?php esc_html_e( 'Please wait...', 'mainwp' ); ?></div></div>
216 <?php
217 } else {
218 ?>
219 <div class="mainwp-scrolly-overflow">
220 <?php MainWP_UI::render_empty_element_placeholder(); ?>
221 </div>
222 <?php
223 }
224 /**
225 * Action: mainwp_security_issues_widget_bottom
226 *
227 * Fires at the bottom of the Security Issues widget.
228 *
229 * @since 4.1
230 */
231 do_action( 'mainwp_security_issues_widget_bottom' );
232 }
233 }
234