upload.php
5.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
<?php
/**
* LearnDash LD30 Display lesson/topic assignment uploads form.
*
* If the lesson/topic is set to be an assignment there will be an upload form displayed to the user.
*
* Available Variables:
*
* $course_step_post: WP_Post object for the Lesson/Topic being shown
* $user_id: Current user ID
* $assignment_upload_error_message: string of previous upload error. Will be empty if no previous upload attempt
*
* @since 3.0.0
*
* @package LearnDash\Templates\LD30
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Identify the max upload file size. Compares the server enviornment limit to what's configured through LD
*
* @var $php_max_upload (int)
*/
$php_max_upload = ini_get( 'upload_max_filesize' );
if ( isset( $post_settings['assignment_upload_limit_size'] ) && ! empty( $post_settings['assignment_upload_limit_size'] ) ) {
if ( learndash_return_bytes_from_shorthand( $post_settings['assignment_upload_limit_size'] ) < learndash_return_bytes_from_shorthand( $php_max_upload ) ) {
$php_max_upload = $post_settings['assignment_upload_limit_size'];
}
}
/**
* Set the upload message based on upload size limit and limit of approved file extensions
*
* @var $upload_message (string)
*/
$upload_message = sprintf(
// translators: placeholder: PHP file upload size.
esc_html_x( 'Maximum upload file size: %s', 'placeholder: PHP file upload size', 'learndash' ),
$php_max_upload
);
if ( isset( $post_settings['assignment_upload_limit_extensions'] ) && ! empty( $post_settings['assignment_upload_limit_extensions'] ) ) {
$limit_file_exts = learndash_validate_extensions( $post_settings['assignment_upload_limit_extensions'] );
if ( ! empty( $limit_file_exts ) ) {
$upload_message .= ' ' . sprintf(
// translators: placeholder: Comma separated list of file extentions.
esc_html_x( 'Allowed file types: %s', 'placeholder: Comma separated list of file extentions', 'learndash' ),
implode( ', ', $limit_file_exts )
);
}
}
/**
* Check to see if the user has uploaded the maximium number of assignments
*
* @var null
*/
if ( isset( $post_settings['assignment_upload_limit_count'] ) ) {
$assignment_upload_limit_count = intval( $post_settings['assignment_upload_limit_count'] );
if ( $assignment_upload_limit_count > 0 ) {
$assignments = learndash_get_user_assignments( $course_step_post->ID, $user_id );
if ( ! empty( $assignments ) && count( $assignments ) >= $assignment_upload_limit_count ) {
return;
}
}
}
/**
* Fires before the assignment uploads.
*
* @since 3.0.0
*
* @param int $course_step_post_id Post ID for the Lesson/Topic being shown.
* @param int $course_id Course ID.
* @param int $user_id User ID.
*/
do_action( 'learndash-assignment-uploads-before', $course_step_post->ID, $course_id, $user_id ); ?>
<div class="ld-file-upload">
<div class="ld-file-upload-heading">
<?php
/**
* Fires before the assignment upload heading.
*
* @since 3.0.0
*
* @param int $course_step_post_id Post ID for the Lesson/Topic being shown.
* @param int $course_id Course ID.
* @param int $user_id User ID.
*/
do_action( 'learndash-assignment-uploads-heading-before', $course_step_post->ID, $course_id, $user_id );
esc_html_e( 'Upload Assignment', 'learndash' );
?>
<span><?php echo esc_html( '(' . $upload_message . ')' ); ?></span>
<?php
/**
* Fires after the assignment uploads heading.
*
* @since 3.0.0
*
* @param int $course_step_post_id Post ID for the Lesson/Topic being shown.
* @param int $course_id Course ID.
* @param int $user_id User ID.
*/
do_action( 'learndash-assignment-uploads-heading-after', $course_step_post->ID, $course_id, $user_id );
?>
</div>
<form name="uploadfile" id="uploadfile_form" class="ld-file-upload-form" method="POST" enctype="multipart/form-data" action="" accept-charset="utf-8" >
<input type="file" class="ld-file-input" name="uploadfiles[]" id="uploadfiles">
<label for="uploadfiles">
<strong><?php echo esc_html_e( 'Browse', 'learndash' ); ?></strong>
<span><?php echo esc_html_e( 'No file selected', 'learndash' ); ?></span>
</label>
<?php
/**
* Fires inside the assignment upload form.
*
* @since 3.0.0
*
* @param int $course_step_post_id Post ID for the Lesson/Topic being shown.
* @param int $course_id Course ID.
* @param int $user_id User ID.
*/
do_action( 'learndash-assignment-uploads-form', $course_step_post->ID, $course_id, $user_id );
?>
<input class="ld-button" type="submit" value="<?php esc_html_e( 'Upload', 'learndash' ); ?>" id="uploadfile_btn" disabled="true">
<input type="hidden" name="MAX_FILE_SIZE" value="<?php echo learndash_return_bytes_from_shorthand( $php_max_upload ); ?>" />
<input type="hidden" value="<?php echo esc_attr( $course_step_post->ID ); ?>" name="post"/>
<input type="hidden" value="<?php echo esc_attr( learndash_get_course_id( $course_step_post->ID ) ); ?>" name="course_id"/>
<input type="hidden" name="uploadfile" value="<?php echo esc_attr( wp_create_nonce( 'uploadfile_' . get_current_user_id() . '_' . $course_step_post->ID ) ); ?>" />
</form>
<div class="ld-file-upload-message">
<?php
/**
* Fires inside assignment upload message wrapper.
*
* @since 3.0.0
*
* @param int $course_step_post_id Post ID for the Lesson/Topic being shown.
* @param int $course_id Course ID.
* @param int $user_id User ID.
*/
do_action( 'learndash-assignment-uploads-message', $course_step_post->ID, $course_id, $user_id );
?>
</div>
<?php
/**
* Fires after the assignments upload message.
*
* @since 3.0.0
*
* @param int $course_step_post_id Post ID for the Lesson/Topic being shown.
* @param int $course_id Course ID.
* @param int $user_id User ID.
*/
do_action( 'learndash-assignment-uploads-message-after', $course_step_post->ID, $course_id, $user_id );
?>
</div> <!--/.ld-file-upload-->