/wp-content/plugins/nycga-group-files/include/group-forum-attachments.php

https://github.com/OccupyWallStreet/nycga2 · PHP · 69 lines · 55 code · 10 blank · 4 comment · 6 complexity · 0b7d5a2cdbd1ccda5522e4d345816bbd MD5 · raw file

  1. <?php
  2. // Add group document uploading to new forum posts
  3. add_action( 'bp_after_group_forum_post_new', 'nycga_group_files_forum_attachments_upload_attachment' );
  4. add_action( 'groups_forum_new_reply_after', 'nycga_group_files_forum_attachments_upload_attachment' );
  5. function nycga_group_files_forum_attachments_upload_attachment() { ?>
  6. <div>
  7. <a id="nycga_group_files_forum_upload_toggle" href="#">Upload File (+)</a>
  8. </div>
  9. <div id="nycga_group_files_forum_upload">
  10. <label><?php _e('Choose File:','nycga-group-files'); ?></label>
  11. <input type="file" name="nycga_group_files_file" class="bp-group-files-file" />
  12. <div id="document-detail-clear" class="clear"></div>
  13. <div class="document-info">
  14. <label><?php _e('Display Name:','nycga-group-files'); ?></label>
  15. <input type="text" name="nycga_group_files_name" id="nycga-group-files-name" />
  16. <?php if( nycga_group_files_SHOW_DESCRIPTIONS ) { ?>
  17. <label><?php _e('Description:', 'nycga-group-files'); ?></label>
  18. <textarea name="nycga_group_files_description" id="nycga-group-files-description"></textarea>
  19. <?php } ?>
  20. </div>
  21. </div>
  22. <?php
  23. }
  24. // Save group documents and append link to forum topic text
  25. add_filter( 'group_forum_topic_text_before_save', 'nycga_group_files_forum_attachments_topic_text', 10, 1 );
  26. add_filter( 'group_forum_post_text_before_save', 'nycga_group_files_forum_attachments_topic_text', 10, 1 );
  27. function nycga_group_files_forum_attachments_topic_text( $topic_text ) {
  28. global $bp;
  29. if ( ! empty($_FILES) ) {
  30. $document = new NYCGA_Group_Files();
  31. $document->user_id = get_current_user_id();
  32. $document->group_id = $bp->groups->current_group->id;
  33. $document->name = $_POST['nycga_group_files_name'];
  34. $document->description = $_POST['nycga_group_files_description'];
  35. if( $document->save() ) {
  36. do_action('nycga_group_files_add_success',$document);
  37. bp_core_add_message( __('File successfully uploaded','nycga-group-files') );
  38. return $topic_text . nycga_group_files_forum_attachments_document_link( $document );
  39. }
  40. }
  41. return $topic_text;
  42. }
  43. // Returns html that links to a group document
  44. function nycga_group_files_forum_attachments_document_link( $document ) {
  45. $html = "<br /><a class='group-files-title' id='group-document-link-{$document->id}' href='{$document->get_url()}' target='_blank'>{$document->name}";
  46. if ( get_option( 'nycga_group_files_display_file_size' ) )
  47. $html .= " <span class='group-documents-filesize'>(" . get_file_size( $document ) . ")</span>";
  48. $html .= "</a>";
  49. if ( NYCGA_GROUP_FILES_SHOW_DESCRIPTIONS && $document->description ) {
  50. $html .= "<br /><span class='group-documents-description'>" . nl2br($document->description) . "</span>";
  51. }
  52. return apply_filters( 'nycga_group_files_forum_document_link', $html, $document );
  53. }
  54. // Allow the id attribute in <a> tags so download counting works.
  55. add_filter( 'bp_forums_allowed_tags', 'nycga_group_files_forum_attachments_allowed_tags', 10, 1 );
  56. function nycga_group_files_forum_attachments_allowed_tags( $forums_allowedtags ) {
  57. $forums_allowedtags['a']['id'] = array();
  58. return $forums_allowedtags;
  59. }