PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 4.01.02
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v4.01.02
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
← All changes | classes/models/FrmCreateFile.php +16 -43 6.254.01.02 View file →
@@ -1,5 +1,6 @@
1 1 <?php
2 +
2 3 if ( ! defined( 'ABSPATH' ) ) {
3 4 die( 'You are not allowed to call this page directly.' );
4 5 }
5 6
@@ -9,16 +10,16 @@
9 10 public $file_name;
10 11 public $error_message;
11 12 public $uploads;
12 13 private $new_file_path;
13 - public $chmod_dir = 0755;
14 - public $chmod_file = 0644;
14 + public $chmod_dir = 0755;
15 + public $chmod_file = 0644;
15 16 private $has_permission = false;
16 17
17 18 public function __construct( $atts ) {
18 - $this->folder_name = $atts['folder_name'] ?? '';
19 + $this->folder_name = isset( $atts['folder_name'] ) ? $atts['folder_name'] : '';
19 20 $this->file_name = $atts['file_name'];
20 - $this->error_message = $atts['error_message'] ?? '';
21 + $this->error_message = isset( $atts['error_message'] ) ? $atts['error_message'] : '';
21 22 $this->uploads = wp_upload_dir();
22 23 $this->set_new_file_path( $atts );
23 24 $this->chmod_dir = defined( 'FS_CHMOD_DIR' ) ? FS_CHMOD_DIR : ( fileperms( ABSPATH ) & 0777 | 0755 );
24 25 $this->chmod_file = defined( 'FS_CHMOD_FILE' ) ? FS_CHMOD_FILE : ( fileperms( ABSPATH . 'index.php' ) & 0777 | 0644 );
@@ -27,10 +28,8 @@
27 28 }
28 29
29 30 /**
30 31 * @since 3.0
31 - *
32 - * @return void
33 32 */
34 33 private function set_new_file_path( $atts ) {
35 34 if ( isset( $atts['new_file_path'] ) ) {
36 35 $this->new_file_path = $atts['new_file_path'] . '/' . $this->file_name;
@@ -38,21 +37,16 @@
38 37 $this->new_file_path = $this->uploads['basedir'] . '/' . $this->folder_name . '/' . $this->file_name;
39 38 }
40 39 }
41 40
42 - /**
43 - * @param string $file_content
44 - *
45 - * @return void
46 - */
47 41 public function create_file( $file_content ) {
48 42 if ( $this->has_permission ) {
49 43 $dirs_exist = true;
50 44
51 - // Create the directories if need be.
45 + // Create the directories if need be
52 46 $this->create_directories( $dirs_exist );
53 47
54 - // Only write the file if the folders exist.
48 + // only write the file if the folders exist
55 49 if ( $dirs_exist ) {
56 50 global $wp_filesystem;
57 51 $wp_filesystem->put_contents( $this->new_file_path, $file_content, $this->chmod_file );
58 52 }
@@ -60,10 +54,8 @@
60 54 }
61 55
62 56 /**
63 57 * @since 3.0
64 - *
65 - * @return void
66 58 */
67 59 public function append_file( $file_content ) {
68 60 if ( $this->has_permission ) {
69 61
@@ -81,11 +73,9 @@
81 73 * Combine an array of files into one
82 74 *
83 75 * @since 3.0
84 76 *
85 - * @param array $file_names And array of file paths.
86 - *
87 - * @return void
77 + * @param array $file_names And array of file paths
88 78 */
89 79 public function combine_files( $file_names ) {
90 80 if ( $this->has_permission ) {
91 81 $content = '';
@@ -122,10 +112,8 @@
122 112 }
123 113
124 114 /**
125 115 * @since 3.0
126 - *
127 - * @return void
128 116 */
129 117 private function check_permission() {
130 118 $creds = $this->get_creds();
131 119
@@ -136,13 +124,8 @@
136 124 $this->has_permission = false;
137 125 }
138 126 }
139 127
140 - /**
141 - * @param true $dirs_exist
142 - *
143 - * @return void
144 - */
145 128 private function create_directories( &$dirs_exist ) {
146 129 global $wp_filesystem;
147 130
148 131 $needed_dirs = $this->get_needed_dirs();
@@ -156,11 +139,8 @@
156 139 }
157 140 }
158 141 }
159 142
160 - /**
161 - * @return string[]
162 - */
163 143 private function get_needed_dirs() {
164 144 $dir_names = explode( '/', $this->folder_name );
165 145 $needed_dirs = array();
166 146
@@ -165,9 +145,9 @@
165 145 $needed_dirs = array();
166 146
167 147 $next_dir = '';
168 148 foreach ( $dir_names as $dir ) {
169 - $next_dir .= '/' . $dir;
149 + $next_dir .= '/' . $dir;
170 150 $needed_dirs[] = $this->uploads['basedir'] . $next_dir;
171 151 }
172 152
173 153 return $needed_dirs;
@@ -174,9 +154,9 @@
174 154 }
175 155
176 156 private function get_creds() {
177 157 if ( ! function_exists( 'get_filesystem_method' ) ) {
178 - include_once ABSPATH . 'wp-admin/includes/file.php';
158 + include_once( ABSPATH . 'wp-admin/includes/file.php' );
179 159 }
180 160
181 161 $access_type = get_filesystem_method();
182 162 if ( $access_type === 'direct' ) {
@@ -187,11 +167,8 @@
187 167
188 168 return $creds;
189 169 }
190 170
191 - /**
192 - * @param string $type
193 - */
194 171 private function get_ftp_creds( $type ) {
195 172 $credentials = get_option(
196 173 'ftp_credentials',
197 174 array(
@@ -203,15 +180,14 @@
203 180 $credentials['hostname'] = defined( 'FTP_HOST' ) ? FTP_HOST : $credentials['hostname'];
204 181 $credentials['username'] = defined( 'FTP_USER' ) ? FTP_USER : $credentials['username'];
205 182 $credentials['password'] = defined( 'FTP_PASS' ) ? FTP_PASS : '';
206 183
207 - // Check to see if we are setting the public/private keys for ssh.
184 + // Check to see if we are setting the public/private keys for ssh
208 185 $credentials['public_key'] = defined( 'FTP_PUBKEY' ) ? FTP_PUBKEY : '';
209 186 $credentials['private_key'] = defined( 'FTP_PRIKEY' ) ? FTP_PRIKEY : '';
210 187
211 - // Sanitize the hostname, Some people might pass in odd-data.
212 - // Strip any schemes off.
213 - $credentials['hostname'] = preg_replace( '|\w+://|', '', $credentials['hostname'] );
188 + // Sanitize the hostname, Some people might pass in odd-data:
189 + $credentials['hostname'] = preg_replace( '|\w+://|', '', $credentials['hostname'] ); //Strip any schemes off
214 190
215 191 if ( strpos( $credentials['hostname'], ':' ) ) {
216 192 list( $credentials['hostname'], $credentials['port'] ) = explode( ':', $credentials['hostname'], 2 );
217 193 if ( ! is_numeric( $credentials['port'] ) ) {
@@ -223,12 +199,12 @@
223 199
224 200 if ( ( defined( 'FTP_SSH' ) && FTP_SSH ) || ( defined( 'FS_METHOD' ) && 'ssh2' == FS_METHOD ) ) {
225 201 $credentials['connection_type'] = 'ssh';
226 202 } elseif ( ( defined( 'FTP_SSL' ) && FTP_SSL ) && 'ftpext' == $type ) {
227 - // Only the FTP Extension understands SSL.
203 + //Only the FTP Extension understands SSL
228 204 $credentials['connection_type'] = 'ftps';
229 205 } elseif ( ! isset( $credentials['connection_type'] ) ) {
230 - // All else fails (And it's not defaulted to something else saved), Default to FTP.
206 + //All else fails (And it's not defaulted to something else saved), Default to FTP
231 207 $credentials['connection_type'] = 'ftp';
232 208 }
233 209
234 210 $has_creds = ( ! empty( $credentials['password'] ) && ! empty( $credentials['username'] ) && ! empty( $credentials['hostname'] ) );
@@ -235,9 +211,9 @@
235 211 $can_ssh = ( 'ssh' == $credentials['connection_type'] && ! empty( $credentials['public_key'] ) && ! empty( $credentials['private_key'] ) );
236 212 if ( $has_creds || $can_ssh ) {
237 213 $stored_credentials = $credentials;
238 214 if ( ! empty( $stored_credentials['port'] ) ) {
239 - // Save port as part of hostname to simplify above code.
215 + //save port as part of hostname to simplify above code.
240 216 $stored_credentials['hostname'] .= ':' . $stored_credentials['port'];
241 217 }
242 218
243 219 unset( $stored_credentials['password'], $stored_credentials['port'], $stored_credentials['private_key'], $stored_credentials['public_key'] );
@@ -247,11 +223,8 @@
247 223
248 224 return false;
249 225 }
250 226
251 - /**
252 - * @return void
253 - */
254 227 private function show_error_message() {
255 228 if ( ! empty( $this->error_message ) ) {
256 229 echo '<div class="message">' . esc_html( $this->error_message ) . '</div>';
257 230 }