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 +59 -49 1.1.0 → 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.min.css', [], BBPC_VERSION );
77 - wp_register_script( 'bbpc-attachments', BBPCATTACHMENT_URL . 'js/front.min.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,33 +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 - $opt = get_option( 'bbp_core_settings' );
261 -
262 264 if ( ! empty( $attachments ) ) {
263 265 $content .= '<div class="bbp-attachments">';
264 - $content .= '<h6>' . __( 'Attachments', 'bbp-core' ) . ':</h6>';
266 + $content .= '<h6>' . __( 'Attachments', 'forumax' ) . ':</h6>';
265 267
266 - $_download = ' download';
268 + $_download = ' download';
267 269
268 270 if ( ! is_user_logged_in() && BBPCATTCore::instance()->is_hidden_from_visitors() ) {
269 - $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() ) );
270 273 } else {
271 274 $listing = '<ol';
272 275 $thumbnails = '<ol';
273 276
@@ -285,11 +288,11 @@
285 288 $url = add_query_arg( 'att_id', $attachment->ID, $url );
286 289 $url = add_query_arg( 'bbp_id', $id, $url );
287 290
288 291 $allow = 'no';
289 - if ( bbpc_is_user_admin() ) {
292 + if ( forumax_is_user_admin() ) {
290 293 $allow = 'delete';
291 - } elseif ( bbpc_is_user_moderator() ) {
294 + } elseif ( forumax_is_user_moderator() ) {
292 295 $allow = 'delete';
293 296 } elseif ( $author_id == $user_ID ) {
294 297 $allow = false;
295 298 }
@@ -294,13 +297,13 @@
294 297 $allow = false;
295 298 }
296 299
297 300 if ( $allow == 'delete' || $allow == 'both' ) {
298 - $actions[] = '<a class="d4p-bba-action-delete" href="' . 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>';
299 302 }
300 -
303 +
301 304 if ( $allow == 'detach' || $allow == 'both' ) {
302 - $actions[] = '<a class="d4p-bba-action-detach" href="' . 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>';
303 306 }
304 307
305 308 if ( count( $actions ) > 0 ) {
306 309 $actions = ' <span class="d4p-bba-actions">[' . join( ' | ', $actions ) . ']</span>';
@@ -316,18 +319,24 @@
316 319 $html = $class_li = $class_a = $rel_a = '';
317 320 $a_title = $filename;
318 321 $caption = false;
319 322
323 + $is_lighbox = '';
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;
327 + }
328 +
320 329 $img = false;
321 - if ( ( $opt['attachment_image_x'] ?? false ) && ( $opt['attachment_image_y'] ?? false ) ) {
330 + if ( forumax_get_opt( 'attachment_image_x', false ) && forumax_get_opt( 'attachment_image_y', false ) ) {
322 331 $html = wp_get_attachment_image( $attachment->ID, 'bbpc-attachment-thumb' );
323 332
324 333 if ( $html != '' ) {
325 334 $img = true;
326 335
327 - $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';
328 337
329 - $caption = bbpc_bba_o( 'image_thumbnail_caption' ) == 1;
338 + $caption = forumax_bba_o( 'image_thumbnail_caption' ) == 1;
330 339 }
331 340 }
332 341
333 342 $item = '<li id="bbpcore-attach_' . $attachment->ID . '" class="bbpcore-attach bbpcore-attachment-' . $ext . ' ' . $class_li . '">';
@@ -333,26 +342,27 @@
333 342 $item = '<li id="bbpcore-attach_' . $attachment->ID . '" class="bbpcore-attach bbpcore-attachment-' . $ext . ' ' . $class_li . '">';
334 343
335 344 if ( $html == '' ) {
336 345 $html = $filename;
337 - $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 ) : '';
338 347 }
339 348
340 349 if ( $img ) {
350 +
341 351 if ( $caption ) {
342 - $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">';
343 353 }
344 354
345 - $item .= '<a class="' . $class_a . '" href="' . $file_url . '" title="' . $a_title . '">' . $html . '</a>';
355 + $item .= '<a class="' . $class_a . $is_lighbox . '" href="' . $file_url . '" title="' . $a_title .'" '. $_download .'>' . $html . '</a>';
346 356
347 357 if ( $caption ) {
348 - $a_title = '<a href="' . $file_url . '"' . $_download . '>' . $a_title . '</a>';
358 + $a_title = '<a class="' . $is_lighbox . '" href="' . $file_url . '"' . $_download . '>' . $a_title . '</a>';
349 359
350 360 $item .= '<p class="wp-caption-text">' . $a_title . '<br/>' . $actions . '</p></div>';
351 361 }
352 362 } else {
353 363 $item .= '<span role="presentation" class="' . $class_li . '"></span> ';
354 - $item .= '<div class="d4p-bbp-att-wrapper"><a class="' . $class_a . '"' . $rel_a . $_download . ' href="' . $file_url . '" title="' . $a_title . '">' . $html . '</a>' . $actions . '</div>';
364 + $item .= '<div class="d4p-bbp-att-wrapper"><a class="' . $class_a . $is_lighbox . '"' . $rel_a . $_download . ' href="' . $file_url . '" title="' . $a_title . '">' . $html . '</a>' . $actions . '</div>';
355 365 }
356 366
357 367 $item .= '</li>';
358 368
@@ -379,14 +389,14 @@
379 389
380 390 $content .= '</div>';
381 391 }
382 392
383 - if ( bbpc_is_user_admin() || bbpc_is_user_moderator() ) {
393 + if ( forumax_is_user_admin() || forumax_is_user_moderator() ) {
384 394 $errors = get_post_meta( $id, '_bbp_attachment_upload_error' );
385 395
386 396 if ( ! empty( $errors ) ) {
387 397 $content .= '<div class="bbp-attachments-errors">';
388 - $content .= '<h6>' . __( 'Upload Errors', 'bbp-core' ) . ':</h6>';
398 + $content .= '<h6>' . __( 'Upload Errors', 'forumax' ) . ':</h6>';
389 399 $content .= '<ol';
390 400
391 401 $class_li = 'bbp-file-error';
392 402
@@ -396,9 +406,9 @@
396 406 $content .= '>';
397 407
398 408 foreach ( $errors as $error ) {
399 409 $content .= '<li class="' . $class_li . '"><span role="presentation" class="' . $class_li . '"></span> ';
400 - $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>';
401 411 }
402 412
403 413 $content .= '</ol></div>';
404 414 }
@@ -407,19 +417,19 @@
407 417 return $content;
408 418 }
409 419
410 420 public function embed_form() {
411 - $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() );
412 422 if ( ! $can_upload ) {
413 423 return;
414 424 }
415 425
416 - $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() );
417 427 if ( ! $is_enabled ) {
418 428 return;
419 429 }
420 430
421 - $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() );
422 432
423 433 include BBPCATTACHMENTS_PATH . 'forms/uploader.php';
424 434 }
425 435 }