PluginProbe
JetFormBuilder — Dynamic Blocks Form Builder / 2.1.3
JetFormBuilder — Dynamic Blocks Form Builder v2.1.3
3.6.5.2 3.6.5.1 3.6.5 3.6.4.2 3.6.4.1 3.6.4 3.6.3.1 3.6.3 3.6.2.2 3.6.2.1 3.6.2 3.6.1.1 3.6.1 3.6.0.1 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 All 130 releases
jetformbuilder / includes / classes / resources / upload-dir.php
upload-dir.php
121 lines 2.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3
4 namespace Jet_Form_Builder\Classes\Resources;
5
6 use Jet_Form_Builder\Live_Form;
7
8 class Upload_Dir {
9
10 /**
11 * Change upload directory for JetEngine uploads
12 *
13 * @param [type] $pathdata [description]
14 *
15 * @return [type] [description]
16 */
17 public static function apply_upload_dir( $pathdata ) {
18 // jet-form-builder
19 $base = static::upload_base();
20
21 // user-based dynamic dirname
22 $dir = static::get_upload_dir();
23
24 if ( empty( $pathdata['subdir'] ) ) {
25 $path = $pathdata['path'] . '/' . $base;
26
27 $pathdata['subdir'] = '/' . $base . '/' . $dir;
28 $pathdata['path'] = $pathdata['path'] . $pathdata['subdir'];
29 $pathdata['url'] = $pathdata['url'] . $pathdata['subdir'];
30 } else {
31 $path = $pathdata['basedir'] . '/' . $base;
32
33 $pathdata['subdir'] = '/' . $base . '/' . $dir . $pathdata['subdir'];
34 $pathdata['path'] = $pathdata['basedir'] . $pathdata['subdir'];
35 $pathdata['url'] = $pathdata['baseurl'] . $pathdata['subdir'];
36 }
37 self::create_index( $path );
38 self::create_index( $pathdata['path'] );
39
40 self::create_htaccess( $path );
41
42 return $pathdata;
43 }
44
45 public static function apply_temp_dir( $pathdata ) {
46 // jet-form-builder
47 $base = static::upload_base();
48
49 $pathdata['subdir'] = '/' . $base . '/temp';
50 $pathdata['path'] = $pathdata['path'] . $pathdata['subdir'];
51 $pathdata['url'] = $pathdata['url'] . $pathdata['subdir'];
52
53 return $pathdata;
54 }
55
56 /**
57 * Returns upload subdirectory
58 *
59 * @return [type] [description]
60 */
61 public static function get_upload_dir() {
62 $user_id = get_current_user_id();
63 $user_dir_name = md5( $user_id . Live_Form::instance()->form_id );
64
65 return apply_filters( 'jet-form-builder/file-upload/user-dir-name', $user_dir_name );
66 }
67
68 /**
69 * Returns upload base directory
70 *
71 * @return [type] [description]
72 */
73 public static function upload_base() {
74 return apply_filters( 'jet-form-builder/file-upload/dir', 'jet-form-builder' );
75 }
76
77 public static function create_index( $path ) {
78 if ( ! is_dir( $path ) ) {
79 return false;
80 }
81
82 $path = trailingslashit( $path ) . 'index.html';
83 $index = wp_normalize_path( $path );
84
85 if ( file_exists( $index ) ) {
86 return false;
87 }
88
89 // phpcs:ignore WordPress.WP.AlternativeFunctions
90 return file_put_contents( $index, '' );
91 }
92
93 public static function create_htaccess( $path ) {
94 if ( ! is_dir( $path ) ) {
95 return false;
96 }
97
98
99 $path = trailingslashit( $path ) . '.htaccess';
100 $index = wp_normalize_path( $path );
101
102 if ( file_exists( $index ) ) {
103 return false;
104 }
105
106 // phpcs:ignore WordPress.WP.AlternativeFunctions
107 return file_put_contents( $index, static::htaccess_content() );
108 }
109
110 protected static function htaccess_content(): string {
111 return '
112 # Disable directory browsing
113 Options -Indexes
114
115 # Hide the contents of directories
116 IndexIgnore *
117 ';
118 }
119
120 }
121