PluginProbe ʕ •ᴥ•ʔ
Everest Forms – Contact Form, Payment Form, Quiz, Survey & Custom Form Builder with AI / 1.6.3
Everest Forms – Contact Form, Payment Form, Quiz, Survey & Custom Form Builder with AI v1.6.3
3.5.2 3.5.1 3.5.0 3.4.8 3.4.7 3.4.6 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.5.1 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 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 1.4.9 1.5.0 1.5.1 1.5.10 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.6.1 1.6.7 1.7.0 1.7.0.1 1.7.0.2 1.7.0.3 1.7.1 1.7.2 1.7.2.1 1.7.2.2 1.7.3 1.7.4 1.7.5 1.7.5.1 1.7.5.2 1.7.6 1.7.7 1.7.7.1 1.7.7.2 1.7.8 1.7.9 1.8.0 1.8.0.1 1.8.1 1.8.2 1.8.2.1 1.8.2.2 1.8.2.3 1.8.3 1.8.4 1.8.5 1.8.6 1.8.7 1.8.8 1.8.9 1.9.0 1.9.0.1 1.9.1 1.9.2 1.9.3 1.9.4 1.9.4.1 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0.0 2.0.0.1 2.0.1 2.0.2 2.0.3 2.0.3.1 2.0.4 2.0.4.1 2.0.5 2.0.6 2.0.7 2.0.8 2.0.8.1 2.0.9 3.0.0 3.0.0.1 3.0.1 3.0.2 3.0.3 3.0.3.1 3.0.4 3.0.4.1 3.0.4.2 3.0.5 3.0.5.1 3.0.5.2 3.0.6 3.0.6.1 3.0.7.1 3.0.8 3.0.8.1 3.0.9 3.0.9.1 3.0.9.2 3.0.9.3 3.0.9.4 3.0.9.5 3.1.0 3.1.1 3.1.2 3.2.0 3.2.1 3.2.2 3.2.3 3.2.4 3.2.5 3.2.6 3.3.0 3.4.0 3.4.1 3.4.2 3.4.2.1 3.4.3 3.4.4 3.4.5 trunk 1.0 1.0.1 1.0.2 1.0.3
everest-forms / includes / admin / class-evf-admin-tools.php
everest-forms / includes / admin Last commit date
builder 6 years ago plugin-updates 8 years ago settings 6 years ago views 6 years ago class-evf-admin-addons.php 6 years ago class-evf-admin-assets.php 6 years ago class-evf-admin-builder.php 7 years ago class-evf-admin-editor.php 6 years ago class-evf-admin-entries-table-list.php 6 years ago class-evf-admin-entries.php 6 years ago class-evf-admin-forms-table-list.php 6 years ago class-evf-admin-forms.php 6 years ago class-evf-admin-import-export.php 6 years ago class-evf-admin-menus.php 6 years ago class-evf-admin-notices.php 6 years ago class-evf-admin-settings.php 6 years ago class-evf-admin-tools.php 6 years ago class-evf-admin-welcome.php 6 years ago class-evf-admin.php 6 years ago evf-admin-functions.php 6 years ago
class-evf-admin-tools.php
179 lines
1 <?php
2 /**
3 * Debug/Status page
4 *
5 * @package EverestForms/Admin/Tools
6 * @version 1.0.0
7 */
8
9 defined( 'ABSPATH' ) || exit;
10
11 /**
12 * EVF_Admin_Tools Class.
13 */
14 class EVF_Admin_Tools {
15
16 /**
17 * Handles output of the reports page in admin.
18 */
19 public static function output() {
20 include_once dirname( __FILE__ ) . '/views/html-admin-page-tools.php';
21 }
22
23 /**
24 * Show the logs page.
25 */
26 public static function status_logs() {
27 self::status_logs_file();
28 }
29
30 /**
31 * Show the import page.
32 */
33 public static function import() {
34 include_once dirname( __FILE__ ) . '/views/html-admin-page-import.php';
35 }
36
37 /**
38 * Show the export page.
39 */
40 public static function export() {
41 include_once dirname( __FILE__ ) . '/views/html-admin-page-export.php';
42 }
43
44 /**
45 * Show the log page contents for file log handler.
46 */
47 public static function status_logs_file() {
48 $logs = self::scan_log_files();
49
50 if ( ! empty( $_REQUEST['log_file'] ) && isset( $logs[ sanitize_title( wp_unslash( $_REQUEST['log_file'] ) ) ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
51 $viewed_log = $logs[ sanitize_title( wp_unslash( $_REQUEST['log_file'] ) ) ]; // phpcs:ignore WordPress.Security.NonceVerification
52 } elseif ( ! empty( $logs ) ) {
53 $viewed_log = current( $logs );
54 }
55
56 $handle = ! empty( $viewed_log ) ? self::get_log_file_handle( $viewed_log ) : '';
57
58 if ( ! empty( $_REQUEST['handle'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
59 self::remove_log();
60 }
61
62 include_once 'views/html-admin-page-tools-logs.php';
63 }
64
65 /**
66 * Retrieve metadata from a file. Based on WP Core's get_file_data function.
67 *
68 * @since 1.0.0
69 * @param string $file Path to the file.
70 * @return string
71 */
72 public static function get_file_version( $file ) {
73 // Avoid notices if file does not exist.
74 if ( ! file_exists( $file ) ) {
75 return '';
76 }
77
78 // We don't need to write to the file, so just open for reading.
79 $fp = fopen( $file, 'r' ); // @codingStandardsIgnoreLine
80
81 // Pull only the first 8kiB of the file in.
82 $file_data = fread( $fp, 8192 ); // @codingStandardsIgnoreLine
83
84 // PHP will close file handle, but we are good citizens.
85 fclose( $fp ); // @codingStandardsIgnoreLine
86
87 // Make sure we catch CR-only line endings.
88 $file_data = str_replace( "\r", "\n", $file_data );
89 $version = '';
90
91 if ( preg_match( '/^[ \t\/*#@]*' . preg_quote( '@version', '/' ) . '(.*)$/mi', $file_data, $match ) && $match[1] ) {
92 $version = _cleanup_header_comment( $match[1] );
93 }
94
95 return $version;
96 }
97
98 /**
99 * Return the log file handle.
100 *
101 * @param string $filename Filename to get the handle for.
102 * @return string
103 */
104 public static function get_log_file_handle( $filename ) {
105 return substr( $filename, 0, strlen( $filename ) > 37 ? strlen( $filename ) - 37 : strlen( $filename ) - 4 );
106 }
107
108 /**
109 * Scan the template files.
110 *
111 * @param string $template_path Path to the template directory.
112 * @return array
113 */
114 public static function scan_template_files( $template_path ) {
115 $files = @scandir( $template_path ); // @codingStandardsIgnoreLine
116 $result = array();
117
118 if ( ! empty( $files ) ) {
119
120 foreach ( $files as $key => $value ) {
121
122 if ( ! in_array( $value, array( '.', '..' ), true ) ) {
123
124 if ( is_dir( $template_path . DIRECTORY_SEPARATOR . $value ) ) {
125 $sub_files = self::scan_template_files( $template_path . DIRECTORY_SEPARATOR . $value );
126 foreach ( $sub_files as $sub_file ) {
127 $result[] = $value . DIRECTORY_SEPARATOR . $sub_file;
128 }
129 } else {
130 $result[] = $value;
131 }
132 }
133 }
134 }
135 return $result;
136 }
137
138 /**
139 * Scan the log files.
140 *
141 * @return array
142 */
143 public static function scan_log_files() {
144 $files = @scandir( EVF_LOG_DIR ); // @codingStandardsIgnoreLine
145 $result = array();
146
147 if ( ! empty( $files ) ) {
148
149 foreach ( $files as $key => $value ) {
150
151 if ( ! in_array( $value, array( '.', '..' ), true ) ) {
152 if ( ! is_dir( $value ) && strstr( $value, '.log' ) ) {
153 $result[ sanitize_title( $value ) ] = $value;
154 }
155 }
156 }
157 }
158
159 return $result;
160 }
161
162 /**
163 * Remove/delete the chosen file.
164 */
165 public static function remove_log() {
166 if ( empty( $_REQUEST['_wpnonce'] ) || ! wp_verify_nonce( wp_unslash( $_REQUEST['_wpnonce'] ), 'remove_log' ) ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
167 wp_die( esc_html__( 'Action failed. Please refresh the page and retry.', 'everest-forms' ) );
168 }
169
170 if ( ! empty( $_REQUEST['handle'] ) ) {
171 $log_handler = new EVF_Log_Handler_File();
172 $log_handler->remove( wp_unslash( $_REQUEST['handle'] ) ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
173 }
174
175 wp_safe_redirect( esc_url_raw( admin_url( 'admin.php?page=evf-tools&tab=logs' ) ) );
176 exit();
177 }
178 }
179