PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 3.0.9
JetFormBuilder — Dynamic Blocks Form Builder v3.0.9
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 1.1.6 1.1.7 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.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.1.0 2.1.1 2.1.10 2.1.11 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 3.0.0 3.0.0.1 3.0.0.2 3.0.0.3 3.0.1 3.0.1.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.0.1 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0 3.2.1 3.2.2 3.2.3 3.3.0 3.3.1 3.3.2 3.3.3 3.3.3.1 3.3.4 3.3.4.1 3.3.4.2 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.5.1 3.4.5.2 3.4.6 3.4.7 3.4.7.1 3.5.0 3.5.1 3.5.1.1 3.5.1.2 3.5.2 3.5.2.1 3.5.3 3.5.4 3.5.5 3.5.6 3.5.6.1 3.5.6.2 3.5.6.3 3.6.0
jetformbuilder / includes / classes / resources / upload-dir.php
jetformbuilder / includes / classes / resources Last commit date
file-collection.php 3 years ago file-tools.php 3 years ago file.php 3 years ago media-block-value.php 3 years ago sanitize-file-exception.php 3 years ago upload-dir.php 3 years ago upload-exception.php 3 years ago upload-permission-exception.php 3 years ago uploaded-collection.php 3 years ago uploaded-file-path.php 3 years ago uploaded-file.php 3 years ago
upload-dir.php
129 lines
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 $content = apply_filters(
99 'jet-form-builder/file-upload/htaccess-content',
100 self::htaccess_content()
101 );
102
103 if ( ! $content ) {
104 return false;
105 }
106
107 $path = trailingslashit( $path ) . '.htaccess';
108 $index = wp_normalize_path( $path );
109
110 if ( file_exists( $index ) ) {
111 return false;
112 }
113
114 // phpcs:ignore WordPress.WP.AlternativeFunctions
115 return file_put_contents( $index, $content );
116 }
117
118 protected static function htaccess_content(): string {
119 return '
120 # Disable directory browsing
121 Options -Indexes
122
123 # Hide the contents of directories
124 IndexIgnore *
125 ';
126 }
127
128 }
129