PluginProbe
Forumax – AI Powered Advanced Community Forum Plugin / 2.5.1
Forumax – AI Powered Advanced Community Forum Plugin v2.5.1
2.5.1 2.5.0 2.4.4 2.4.3 2.4.2 2.4.1 2.4.0 trunk 1.0.8 1.1.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 All 31 releases
← All changes | includes/features/bbpc_attachments/code/front.php +50 -45 1.3.2 → 2.5.1 View file →
@@ -40,9 +40,9 @@
40 40
41 41 public function load() {
42 42 add_action( 'wp_enqueue_scripts', [ $this, 'wp_enqueue_scripts' ] );
43 43
44 - add_action( 'bbp_theme_before_reply_form_submit_wrapper', [ $this, 'embed_form' ] );
44 + add_action( 'frmx_reply_attachments', [ $this, 'embed_form' ] );
45 45 add_action( 'bbp_theme_before_topic_form_submit_wrapper', [ $this, 'embed_form' ] );
46 46
47 47 add_action( 'bbp_edit_reply', [ $this, 'edit_reply' ], 10, 5 );
48 48 add_action( 'bbp_edit_topic', [ $this, 'edit_topic' ], 10, 4 );
@@ -51,9 +51,9 @@
51 51
52 52 add_filter( 'bbp_get_reply_content', [ $this, 'embed_attachments' ], 100, 2 );
53 53 add_filter( 'bbp_get_topic_content', [ $this, 'embed_attachments' ], 100, 2 );
54 54
55 - if ( bbpc_bba_o( 'is_attachment_icon' ) == 1 ) {
55 + if ( forumax_bba_o( 'is_attachment_icon' ) == 1 ) {
56 56 add_action( 'bbp_theme_before_topic_title', [ $this, 'show_attachments_icon' ] );
57 57 }
58 58
59 59 $this->register_scripts_and_styles();
@@ -71,11 +71,10 @@
71 71 return 'generic';
72 72 }
73 73
74 74 public function register_scripts_and_styles() {
75 - //TODO: Fix the constant for version
76 - wp_register_style( 'bbpc-attachments', BBPCATTACHMENT_URL . 'css/front.css', [], BBPC_VERSION );
77 - wp_register_script( 'bbpc-attachments', BBPCATTACHMENT_URL . 'js/front.js', [ 'jquery' ], BBPC_VERSION, true );
75 + wp_register_style( 'bbpc-attachments', BBPCATTACHMENT_URL . 'css/front.css', [], FORUMAX_VERSION );
76 + wp_register_script( 'bbpc-attachments', BBPCATTACHMENT_URL . 'js/front.js', [ 'jquery' ], FORUMAX_VERSION, true );
78 77 }
79 78
80 79 public function include_scripts_and_styles() {
81 80 wp_enqueue_style( 'bbpc-attachments' );
@@ -85,15 +84,15 @@
85 84 'bbpc-attachments',
86 85 'bbpcAttachmentsInit',
87 86 [
88 87 'max_files' => apply_filters( 'bbpc_bbpressattchment_allow_upload', BBPCATTCore::instance()->get_max_files(), bbp_get_forum_id() ),
89 - 'are_you_sure' => __( 'This operation is not reversible. Are you sure?', 'bbp-core' ),
88 + 'are_you_sure' => __( 'This operation is not reversible. Are you sure?', 'forumax' ),
90 89 ]
91 90 );
92 91 }
93 92
94 93 public function wp_enqueue_scripts() {
95 - if ( bbpc_is_bbpress() ) {
94 + if ( forumax_is_bbpress() ) {
96 95 $this->include_scripts_and_styles();
97 96 }
98 97 }
99 98
@@ -119,21 +118,26 @@
119 118
120 119 public function process_attachments( $reply_id, $topic_id, $forum_id, $anonymous_data = null, $reply_author = null ) {
121 120 $uploads = [];
122 121 $revision = false;
122 + $errors = new gdbbp_Error();
123 123
124 124 if ( ! empty( $_FILES ) && ! empty( $_FILES['bbpc_attachment'] ) ) {
125 125 require_once ABSPATH . 'wp-admin/includes/file.php';
126 126
127 - $errors = new gdbbp_Error();
128 127 $overrides = [
129 128 'test_form' => false,
130 - 'upload_error_handler' => 'bbpc_bbattachment_handle_upload_error',
129 + 'upload_error_handler' => 'forumax_bbattachment_handle_upload_error',
131 130 ];
132 131
133 - foreach ( $_FILES['bbpc_attachment']['error'] as $key => $error ) {
132 + foreach ( (array) $_FILES['bbpc_attachment']['error'] as $key => $error ) {
134 133 $file_name = $_FILES['bbpc_attachment']['name'][ $key ];
135 134
135 + // Empty file inputs are not errors.
136 + if ( UPLOAD_ERR_NO_FILE === (int) $error ) {
137 + continue;
138 + }
139 +
136 140 if ( $error == UPLOAD_ERR_OK ) {
137 141 $file = [
138 142 'name' => $file_name,
139 143 'type' => $_FILES['bbpc_attachment']['type'][ $key ],
@@ -155,31 +159,30 @@
155 159 } else {
156 160 $errors->add( 'bbpc_upload', 'File exceeds allowed file size.', $file_name );
157 161 }
158 162 } else {
159 - switch ( $error ) {
160 - default:
161 - case 'UPLOAD_ERR_NO_FILE':
162 - $errors->add( 'php_upload', 'File not uploaded.', $file_name );
163 - break;
164 - case 'UPLOAD_ERR_INI_SIZE':
163 + switch ( (int) $error ) {
164 + case UPLOAD_ERR_INI_SIZE:
165 165 $errors->add( 'php_upload', 'Upload file size exceeds PHP maximum file size allowed.', $file_name );
166 166 break;
167 - case 'UPLOAD_ERR_FORM_SIZE':
167 + case UPLOAD_ERR_FORM_SIZE:
168 168 $errors->add( 'php_upload', 'Upload file size exceeds FORM specified file size.', $file_name );
169 169 break;
170 - case 'UPLOAD_ERR_PARTIAL':
170 + case UPLOAD_ERR_PARTIAL:
171 171 $errors->add( 'php_upload', 'Upload file only partially uploaded.', $file_name );
172 172 break;
173 - case 'UPLOAD_ERR_CANT_WRITE':
173 + case UPLOAD_ERR_CANT_WRITE:
174 174 $errors->add( 'php_upload', 'Can\'t write file to the disk.', $file_name );
175 175 break;
176 - case 'UPLOAD_ERR_NO_TMP_DIR':
176 + case UPLOAD_ERR_NO_TMP_DIR:
177 177 $errors->add( 'php_upload', 'Temporary folder for upload is missing.', $file_name );
178 178 break;
179 - case 'UPLOAD_ERR_EXTENSION':
179 + case UPLOAD_ERR_EXTENSION:
180 180 $errors->add( 'php_upload', 'Server extension restriction stopped upload.', $file_name );
181 181 break;
182 + default:
183 + $errors->add( 'php_upload', 'File not uploaded.', $file_name );
184 + break;
182 185 }
183 186 }
184 187 }
185 188 }
@@ -241,31 +244,33 @@
241 244 }
242 245
243 246 public function show_attachments_icon() {
244 247 $topic_id = bbp_get_topic_id();
245 - $count = bbpc_topic_attachments_count( $topic_id, true );
248 + $count = forumax_topic_attachments_count( $topic_id, true );
246 249
247 250 if ( $count > 0 ) {
248 - echo '<span class="bbp-attachments-count" title="' . $count . ' ' . _n( 'attachment', 'attachments', $count, 'bbp-core' ) . '"></span>';
251 + echo '<span class="bbp-attachments-count" aria-hidden="true" title="' . esc_attr( $count . ' ' . _n( 'attachment', 'attachments', $count, 'forumax' ) ) . '"></span>';
249 252 }
253 +
250 254 }
251 255
252 256 public function embed_attachments( $content, $id ) {
253 257 global $user_ID;
254 258
255 - $attachments = bbpc_get_post_attachments( $id );
259 + $attachments = forumax_get_post_attachments( $id );
256 260
257 261 $post = get_post( $id );
258 - $author_id = $post->post_author;
262 + $author_id = $post ? $post->post_author : 0;
259 263
260 264 if ( ! empty( $attachments ) ) {
261 265 $content .= '<div class="bbp-attachments">';
262 - $content .= '<h6>' . __( 'Attachments', 'bbp-core' ) . ':</h6>';
266 + $content .= '<h6>' . __( 'Attachments', 'forumax' ) . ':</h6>';
263 267
264 268 $_download = ' download';
265 269
266 270 if ( ! is_user_logged_in() && BBPCATTCore::instance()->is_hidden_from_visitors() ) {
267 - $content .= sprintf( __( "You must be <a href='%s'>logged in</a> to view attached files.", 'bbp-core' ), wp_login_url( get_permalink() ) );
271 + /* translators: %s: Login URL */
272 + $content .= sprintf( __( "You must be <a href='%s'>logged in</a> to view attached files.", 'forumax' ), wp_login_url( get_permalink() ) );
268 273 } else {
269 274 $listing = '<ol';
270 275 $thumbnails = '<ol';
271 276
@@ -283,11 +288,11 @@
283 288 $url = add_query_arg( 'att_id', $attachment->ID, $url );
284 289 $url = add_query_arg( 'bbp_id', $id, $url );
285 290
286 291 $allow = 'no';
287 - if ( bbpc_is_user_admin() ) {
292 + if ( forumax_is_user_admin() ) {
288 293 $allow = 'delete';
289 - } elseif ( bbpc_is_user_moderator() ) {
294 + } elseif ( forumax_is_user_moderator() ) {
290 295 $allow = 'delete';
291 296 } elseif ( $author_id == $user_ID ) {
292 297 $allow = false;
293 298 }
@@ -292,13 +297,13 @@
292 297 $allow = false;
293 298 }
294 299
295 300 if ( $allow == 'delete' || $allow == 'both' ) {
296 - $actions[] = '<a class="d4p-bba-action-delete" href="' . esc_url( add_query_arg( 'd4pbbaction', 'delete', $url ) ) . '">' . __( 'delete', 'bbp-core' ) . '</a>';
301 + $actions[] = '<a class="d4p-bba-action-delete" href="' . esc_url( add_query_arg( 'd4pbbaction', 'delete', $url ) ) . '">' . __( 'delete', 'forumax' ) . '</a>';
297 302 }
298 303
299 304 if ( $allow == 'detach' || $allow == 'both' ) {
300 - $actions[] = '<a class="d4p-bba-action-detach" href="' . esc_url( add_query_arg( 'd4pbbaction', 'detach', $url ) ) . '">' . __( 'detach', 'bbp-core' ) . '</a>';
305 + $actions[] = '<a class="d4p-bba-action-detach" href="' . esc_url( add_query_arg( 'd4pbbaction', 'detach', $url ) ) . '">' . __( 'detach', 'forumax' ) . '</a>';
301 306 }
302 307
303 308 if ( count( $actions ) > 0 ) {
304 309 $actions = ' <span class="d4p-bba-actions">[' . join( ' | ', $actions ) . ']</span>';
@@ -315,23 +320,23 @@
315 320 $a_title = $filename;
316 321 $caption = false;
317 322
318 323 $is_lighbox = '';
319 - if ( bbpc_is_premium() ) {
320 - $is_lighbox = bbpc_get_opt( 'image_link_type' ) == 'lightbox' ? ' bbpc-lightbox' : '';
321 - $_download = bbpc_get_opt( 'image_link_type' ) == 'lightbox' ? '' : $_download;
324 + if ( forumax_is_premium() ) {
325 + $is_lighbox = forumax_get_opt( 'image_link_type' ) == 'lightbox' ? ' bbpc-lightbox' : '';
326 + $_download = forumax_get_opt( 'image_link_type' ) == 'lightbox' ? '' : $_download;
322 327 }
323 328
324 329 $img = false;
325 - if ( bbpc_get_opt( 'attachment_image_x', false ) && bbpc_get_opt( 'attachment_image_y', false ) ) {
330 + if ( forumax_get_opt( 'attachment_image_x', false ) && forumax_get_opt( 'attachment_image_y', false ) ) {
326 331 $html = wp_get_attachment_image( $attachment->ID, 'bbpc-attachment-thumb' );
327 332
328 333 if ( $html != '' ) {
329 334 $img = true;
330 335
331 - $class_li = 'bbp-atthumb';
336 + $class_li = forumax_bba_o( 'is_file_type_icon' ) == 1 ? 'bbp-atthumb bbp-atticon bbp-atticon-' . $this->icon( $ext ) : 'bbp-atthumb';
332 337
333 - $caption = bbpc_bba_o( 'image_thumbnail_caption' ) == 1;
338 + $caption = forumax_bba_o( 'image_thumbnail_caption' ) == 1;
334 339 }
335 340 }
336 341
337 342 $item = '<li id="bbpcore-attach_' . $attachment->ID . '" class="bbpcore-attach bbpcore-attachment-' . $ext . ' ' . $class_li . '">';
@@ -337,15 +342,15 @@
337 342 $item = '<li id="bbpcore-attach_' . $attachment->ID . '" class="bbpcore-attach bbpcore-attachment-' . $ext . ' ' . $class_li . '">';
338 343
339 344 if ( $html == '' ) {
340 345 $html = $filename;
341 - $class_li = 'bbp-atticon bbp-atticon-' . $this->icon( $ext );
346 + $class_li = forumax_bba_o( 'is_file_type_icon' ) == 1 ? 'bbp-atticon bbp-atticon-' . $this->icon( $ext ) : '';
342 347 }
343 348
344 349 if ( $img ) {
345 350
346 351 if ( $caption ) {
347 - $item .= '<div style="width: ' . bbpc_bba_o( 'attachment_image_x' ) . 'px" class="wp-caption">';
352 + $item .= '<div style="width: ' . forumax_bba_o( 'attachment_image_x' ) . 'px" class="wp-caption">';
348 353 }
349 354
350 355 $item .= '<a class="' . $class_a . $is_lighbox . '" href="' . $file_url . '" title="' . $a_title .'" '. $_download .'>' . $html . '</a>';
351 356
@@ -384,14 +389,14 @@
384 389
385 390 $content .= '</div>';
386 391 }
387 392
388 - if ( bbpc_is_user_admin() || bbpc_is_user_moderator() ) {
393 + if ( forumax_is_user_admin() || forumax_is_user_moderator() ) {
389 394 $errors = get_post_meta( $id, '_bbp_attachment_upload_error' );
390 395
391 396 if ( ! empty( $errors ) ) {
392 397 $content .= '<div class="bbp-attachments-errors">';
393 - $content .= '<h6>' . __( 'Upload Errors', 'bbp-core' ) . ':</h6>';
398 + $content .= '<h6>' . __( 'Upload Errors', 'forumax' ) . ':</h6>';
394 399 $content .= '<ol';
395 400
396 401 $class_li = 'bbp-file-error';
397 402
@@ -401,9 +406,9 @@
401 406 $content .= '>';
402 407
403 408 foreach ( $errors as $error ) {
404 409 $content .= '<li class="' . $class_li . '"><span role="presentation" class="' . $class_li . '"></span> ';
405 - $content .= '<div class="d4p-bbp-att-wrapper"><strong>' . esc_html( $error['file'] ) . '</strong>: ' . __( $error['message'], 'bbp-core' ) . '</div></li>';
410 + $content .= '<div class="d4p-bbp-att-wrapper"><strong>' . esc_html( $error['file'] ) . '</strong>: ' . esc_html( $error['message'] ) . '</div></li>';
406 411 }
407 412
408 413 $content .= '</ol></div>';
409 414 }
@@ -412,19 +417,19 @@
412 417 return $content;
413 418 }
414 419
415 420 public function embed_form() {
416 - $can_upload = apply_filters( 'bbpc_bbpressattchment_allow_upload', BBPCATTCore::instance()->is_user_allowed(), bbpc_get_forum_id() );
421 + $can_upload = apply_filters( 'bbpc_bbpressattchment_allow_upload', BBPCATTCore::instance()->is_user_allowed(), forumax_get_forum_id() );
417 422 if ( ! $can_upload ) {
418 423 return;
419 424 }
420 425
421 - $is_enabled = apply_filters( 'bbpc_bbpressattchment_forum_enabled', BBPCATTCore::instance()->enabled_for_forum(), bbpc_get_forum_id() );
426 + $is_enabled = apply_filters( 'bbpc_bbpressattchment_forum_enabled', BBPCATTCore::instance()->enabled_for_forum(), forumax_get_forum_id() );
422 427 if ( ! $is_enabled ) {
423 428 return;
424 429 }
425 430
426 - $file_size = apply_filters( 'bbpc_bbpressattchment_max_file_size', BBPCATTCore::instance()->get_file_size(), bbpc_get_forum_id() );
431 + $file_size = apply_filters( 'bbpc_bbpressattchment_max_file_size', BBPCATTCore::instance()->get_file_size(), forumax_get_forum_id() );
427 432
428 433 include BBPCATTACHMENTS_PATH . 'forms/uploader.php';
429 434 }
430 435 }