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 +47 -44 1.4.1 → 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,12 +244,12 @@
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="' . esc_attr( $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 }
250 253
251 254 }
252 255
@@ -252,22 +255,22 @@
252 255
253 256 public function embed_attachments( $content, $id ) {
254 257 global $user_ID;
255 258
256 - $attachments = bbpc_get_post_attachments( $id );
259 + $attachments = forumax_get_post_attachments( $id );
257 260
258 261 $post = get_post( $id );
259 - $author_id = $post->post_author;
262 + $author_id = $post ? $post->post_author : 0;
260 263
261 264 if ( ! empty( $attachments ) ) {
262 265 $content .= '<div class="bbp-attachments">';
263 - $content .= '<h6>' . __( 'Attachments', 'bbp-core' ) . ':</h6>';
266 + $content .= '<h6>' . __( 'Attachments', 'forumax' ) . ':</h6>';
264 267
265 268 $_download = ' download';
266 269
267 270 if ( ! is_user_logged_in() && BBPCATTCore::instance()->is_hidden_from_visitors() ) {
268 271 /* translators: %s: Login URL */
269 - $content .= sprintf( __( "You must be <a href='%s'>logged in</a> to view attached files.", 'bbp-core' ), wp_login_url( get_permalink() ) );
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="' . 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>';
299 302 }
300 303
301 304 if ( $allow == 'detach' || $allow == 'both' ) {
302 - $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>';
303 306 }
304 307
305 308 if ( count( $actions ) > 0 ) {
306 309 $actions = ' <span class="d4p-bba-actions">[' . join( ' | ', $actions ) . ']</span>';
@@ -317,23 +320,23 @@
317 320 $a_title = $filename;
318 321 $caption = false;
319 322
320 323 $is_lighbox = '';
321 - if ( bbpc_is_premium() ) {
322 - $is_lighbox = bbpc_get_opt( 'image_link_type' ) == 'lightbox' ? ' bbpc-lightbox' : '';
323 - $_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;
324 327 }
325 328
326 329 $img = false;
327 - 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 ) ) {
328 331 $html = wp_get_attachment_image( $attachment->ID, 'bbpc-attachment-thumb' );
329 332
330 333 if ( $html != '' ) {
331 334 $img = true;
332 335
333 - $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';
334 337
335 - $caption = bbpc_bba_o( 'image_thumbnail_caption' ) == 1;
338 + $caption = forumax_bba_o( 'image_thumbnail_caption' ) == 1;
336 339 }
337 340 }
338 341
339 342 $item = '<li id="bbpcore-attach_' . $attachment->ID . '" class="bbpcore-attach bbpcore-attachment-' . $ext . ' ' . $class_li . '">';
@@ -339,15 +342,15 @@
339 342 $item = '<li id="bbpcore-attach_' . $attachment->ID . '" class="bbpcore-attach bbpcore-attachment-' . $ext . ' ' . $class_li . '">';
340 343
341 344 if ( $html == '' ) {
342 345 $html = $filename;
343 - $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 ) : '';
344 347 }
345 348
346 349 if ( $img ) {
347 350
348 351 if ( $caption ) {
349 - $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">';
350 353 }
351 354
352 355 $item .= '<a class="' . $class_a . $is_lighbox . '" href="' . $file_url . '" title="' . $a_title .'" '. $_download .'>' . $html . '</a>';
353 356
@@ -386,14 +389,14 @@
386 389
387 390 $content .= '</div>';
388 391 }
389 392
390 - if ( bbpc_is_user_admin() || bbpc_is_user_moderator() ) {
393 + if ( forumax_is_user_admin() || forumax_is_user_moderator() ) {
391 394 $errors = get_post_meta( $id, '_bbp_attachment_upload_error' );
392 395
393 396 if ( ! empty( $errors ) ) {
394 397 $content .= '<div class="bbp-attachments-errors">';
395 - $content .= '<h6>' . __( 'Upload Errors', 'bbp-core' ) . ':</h6>';
398 + $content .= '<h6>' . __( 'Upload Errors', 'forumax' ) . ':</h6>';
396 399 $content .= '<ol';
397 400
398 401 $class_li = 'bbp-file-error';
399 402
@@ -414,19 +417,19 @@
414 417 return $content;
415 418 }
416 419
417 420 public function embed_form() {
418 - $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() );
419 422 if ( ! $can_upload ) {
420 423 return;
421 424 }
422 425
423 - $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() );
424 427 if ( ! $is_enabled ) {
425 428 return;
426 429 }
427 430
428 - $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() );
429 432
430 433 include BBPCATTACHMENTS_PATH . 'forms/uploader.php';
431 434 }
432 435 }