PluginProbe ʕ •ᴥ•ʔ
CloudSecure WP Security / 0.9.0
CloudSecure WP Security v0.9.0
1.4.10 1.4.9 trunk 0.9.0 1.0.2 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.3.1 1.3.10 1.3.11 1.3.12 1.3.13 1.3.14 1.3.15 1.3.16 1.3.17 1.3.18 1.3.19 1.3.2 1.3.20 1.3.21 1.3.22 1.3.23 1.3.24 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8
cloudsecure-wp-security / modules / admin / common.php
cloudsecure-wp-security / modules / admin Last commit date
captcha.php 2 years ago common.php 2 years ago dashboard.php 2 years ago disable-author-query.php 2 years ago disable-login.php 2 years ago disable-restapi.php 2 years ago disable-xmlrpc.php 2 years ago login-log-table.php 2 years ago login-log.php 2 years ago login-notification.php 2 years ago rename-login-page.php 2 years ago restrict-admin-page.php 2 years ago unify-messages.php 2 years ago update-notice.php 2 years ago
common.php
207 lines
1 <?php
2 class CloudSecureWP_Admin_Common extends CloudSecureWP_Common {
3 protected $datas;
4 protected $messages;
5 protected $errors;
6 protected $important_messages;
7 public const TF_VALIES = array( 't', 'f' );
8 private $allowed_notice_html;
9
10 function __construct( array $info ) {
11 parent::__construct( $info );
12 $this->datas = array();
13 $this->messages = array();
14 $this->errors = array();
15 $this->important_messages = array();
16 }
17
18 /**
19 * メッセージ行
20 *
21 * @param array $messages
22 * @return string
23 */
24 protected function get_message_view_lines( array $messages ): string {
25 $view_lines = '';
26
27 foreach ( $messages as $message ) {
28 $view_lines .= '<div>' . $message . '</div>';
29 }
30 return $view_lines;
31 }
32
33 /**
34 * メッセージ表示
35 *
36 * @param array $messages
37 * @return string
38 */
39 protected function get_message_notices( array $messages ): string {
40 if ( ! empty( $messages ) ) {
41 $view_lines = $this->get_message_view_lines( $messages );
42 return '<div id="settings_updated" class="success-box ">' . $view_lines . '</div>';
43 }
44 return '';
45 }
46
47 /**
48 * エラー表示
49 *
50 * @param array $error_messages
51 * @return string
52 */
53 protected function get_error_notices( array $messages ): string {
54 if ( ! empty( $messages ) ) {
55 $view_lines = $this->get_message_view_lines( $messages );
56 return '<div class="error-box">' . $view_lines . '</div>';
57 }
58 return '';
59 }
60
61 /**
62 * 重要メッセージ表示
63 *
64 * @param array $messages
65 * @return string
66 */
67 protected function get_important_message_notices( array $messages ): string {
68 if ( ! empty( $messages ) ) {
69 $view_lines = $this->get_message_view_lines( $messages );
70 return '<div id="settings_updated" class="success-box green">' . $view_lines . '</div>';
71 }
72 return '';
73 }
74
75 /**
76 * submitボタン取得
77 *
78 * @return string
79 * @param string $view_text
80 * @return void
81 */
82 protected function submit_button_wp( string $view_text = '' ): void {
83 if ( '' === $view_text ) {
84 $view_text = '変更を保存';
85 }
86 submit_button( $view_text );
87 }
88
89 /**
90 * wp_nonceのview
91 *
92 * @param string $feature_key
93 * @return void
94 */
95 protected function nonce_wp( string $feature_key ): void {
96 wp_nonce_field( $feature_key . '_csrf', '_wpnonce' );
97 }
98
99 /**
100 * wp_nonceのチェック
101 *
102 * @return bool
103 */
104 protected function check_admin_referer( string $feature_key ): bool {
105 if ( ! empty( $_POST ) ) {
106 check_admin_referer( $feature_key . '_csrf', '_wpnonce' );
107 return true;
108 }
109 return false;
110 }
111
112 /**
113 * checkbox radioのchecked
114 *
115 * @param array $datas
116 * @param array $names
117 * @return array
118 */
119 protected function get_checked( array $datas, array $names ): array {
120 $checks = array();
121
122 foreach ( $names as $name ) {
123 if ( ! empty( $datas[ $name ] ) ) {
124 $checks[ $name . '_' . $datas[ $name ] ] = 'checked';
125 }
126 }
127 $datas = array_merge( $checks, $datas );
128
129 return $datas;
130 }
131
132 /**
133 * レンダリング
134 *
135 * @return void
136 */
137 protected function render(): void {
138 $this->allowed_notice_html = array(
139 'div' => array(
140 'id' => array(),
141 'class' => array(),
142 ),
143 'a' => array(
144 'href' => array(),
145 'target' => array(),
146 ),
147 'br' => array(),
148 );
149
150 wp_enqueue_script( 'cloudsecurewp', $this->info['plugin_url'] . 'assets/js/script.js' );
151
152 if ( is_multisite() ) {
153 $this->errors[] = self::MESSAGES['error_multisite'];
154 }
155
156 $conflict_plugin_name = $this->get_conflict_plugin_name();
157 if ( '' != $conflict_plugin_name ) {
158 $this->errors[] = self::MESSAGES['error_conflict_plugin'] . "{$conflict_plugin_name}";
159 }
160
161 print( '<div id="cloudsecure-wp-security" class="wrap">' . "\n" . '<div class="header">' . "\n" . '<div class="header-logo">' . "\n" . '</div>' . "\n" . '</div>' . "\n" );
162 print( '<div class="top-area ">' . "\n" . '<div class="error-success-area ">' . "\n" );
163
164 if ( ! empty( $this->messages ) ) {
165 print( wp_kses( $this->get_message_notices( $this->messages ), $this->allowed_notice_html ) );
166 }
167
168 if ( ! empty( $this->important_messages ) ) {
169 print( wp_kses( $this->get_important_message_notices( $this->important_messages ), $this->allowed_notice_html ) );
170 }
171
172 if ( ! empty( $this->errors ) ) {
173 print( wp_kses( $this->get_error_notices( $this->errors ), $this->allowed_notice_html ) );
174 }
175
176 if ( ! is_multisite() ) {
177 print( '</div>' . "\n" );
178 $this->admin_description();
179 print( '</div>' . "\n" );
180
181 $this->page();
182 }
183
184 print( '</div>' . "\n" );
185 }
186
187 /* デスクリプション */
188 protected function admin_description(): void {}
189
190 /* ページコンテンツ */
191 protected function page(): void {}
192
193 /**
194 * 選択肢の値確認
195 *
196 * @param string $selected_value
197 * @param array $values
198 * @return bool
199 */
200 protected function is_selected( string $selected_value, array $values ): bool {
201 if ( empty( $selected_value ) ) {
202 return false;
203 }
204 return in_array( $selected_value, $values );
205 }
206 }
207