Support » Plugin: BuddyPress Docs » [Plugin: BuddyPress Docs] Docs with attachments

Viewing 8 replies - 1 through 8 (of 8 total)
  • We at just recently added this functionality to our unnoficial branch.
    I added a new addon file in buddypress-docs/includes/addon-attachments.php containing the following code:

    <br />
    <p>class BP_Docs_Attachments {</p>
    <p>	function __construct() {<br />
    		global $bp;</p>
    <p>		// Hook into post saves to save any taxonomy terms.<br />
    		add_action( 'bp_docs_doc_saved', array( $this, 'save_post' ) );<br />
    		add_action('bp_docs_loop_additional_th',array($this,'add_loop_th'));<br />
    		add_action('bp_docs_loop_additional_td',array($this,'add_loop_td'));<br />
    		add_action('bp_docs_header_tabs',array($this,'add_print_doc_tab'));<br />
    		$bp->bp_docs->history =& $this;<br />
    <p>	function save_post($query){<br />
    		/*<br />
    		 * vardump and query in buddypress-docs/includes/addon-attachments.php 18object(BP_Docs_Query)#263 (12) { ["post_type_name"]=> string(6) "bp_doc" ["associated_item_tax_name"]=> string(23) "bp_docs_associated_item" ["item_type"]=> string(5) "group" ["item_id"]=> string(2) "23" ["item_name"]=> string(24) "Thenumber Public Library" ["item_slug"]=> string(19) "libraries/thenumber" ["doc_id"]=> int(239) ["doc_slug"]=> string(8) "testdoc1" ["current_view"]=> string(4) "edit" ["term_id"]=> string(2) "25" ["item_type_term_id"]=> string(1) "5" ["is_new_doc"]=> bool(false) }<br />
    		 */<br />
    		/*echo "vardump and query in buddypress-docs/includes/addon-attachments.php 18";<br />
    		var_dump($query);*/<br />
    		/*die;*/<br />
    		if(!empty($_FILES)){<br />
    			/*echo "handle file upload in bp-docs/../atacchemnts, attach to post {$query->doc_id}<br />";<br />
    			var_dump($_FILES);*/<br />
    			require_once('wp-admin/includes/file.php');<br />
    			require_once('wp-admin/includes/media.php');<br />
    			require_once('wp-admin/includes/image.php');<br />
    			foreach($_FILES as $file_id=>$file){<br />
    				$uploaded_attachment_id=media_handle_upload($file_id,$query->doc_id);<br />
    			}<br />
    			/*echo "uploaded attachment id: $uploaded_attachment_id";<br />
    			echo "and die";<br />
    			die;*/<br />
    <p>		$attachments=get_children(array('post_parent'=>$query->doc_id,'post_type'=>'attachment'));<br />
    		/*echo "<br />attachments:";<br />
    		var_dump($attachments);<br />
    		echo "<br />";<br />
    <p>		require_once('wp-includes/post.php');<br />
    		foreach($attachments as $attachment){<br />
    			if(isset($_REQUEST['bp-docs-existing-attachment-'.$attachment->ID])){<br />
    				wp_trash_post($attachment->ID);<br />
    				//echo "delete post ".$attachment->ID;<br />
    			}<br />
    <p>	}</p>
    <p>	function add_loop_th(){<br />
    		echo "<th>Attachments</th>";<br />
    	}<br />
    	function add_loop_td(){<br />
    		global $post;<br />
    		$attachments=get_children(array('post_parent'=>$post->ID,'post_type'=>'attachment'));<br />
    		echo "<td class='date-cell edited-date-cell'>".count($attachments)."</td>";<br />
    	}<br />
    	function add_print_doc_tab(){<br />
    		echo "
    <li><a href>Print Document</a></li>
    ";<br />
    	}<br />
    }<br />

    And then I edited buddypress-docs/bp-docs.php
    at about line 164 (where all the other ‘addon’s are included) to include this addon:

    <br />
    //load the file attachment addon<br />
    require_once( BP_DOCS_INCLUDES_PATH . 'addon-attachments.php' );<br />
    $this->attachments=new BP_Docs_Attachments;<br />

    Ah! And I also forgot about these edits to these two files which are also necessary:
    in buddypress-docs/includes/templates/edit-doc.php:
    line 20 (the one with the opening form tag)

    <br />
    <form action="" method="post" class="standard-form" id="doc-form" enctype="multipart/form-data"><br />

    and line 60 (just before the opening div of di ‘doc-meta’:

    <br />
    <div id='doc-attachments'><br />
            	<script><br />
    	    		jQuery(document).ready(function(){<br />
    		    		jQuery('#addAttachment-button').click(function(){<br />
    			    		addMetaRow();<br />
    			    	});<br />
    		    	});<br />
    		    	function addMetaRow(){<br />
    			    	var count=jQuery('.bp-docs-attachment').length;<br />
    			    	var htmlToAppend="\<br />
    				    			<div class='bp-docs-attachment-row'>\<br />
    				    			<input type='file' class='bp-docs-attachment' name='bp-docs-attachments-"+count+"' >\<br />
    				    			</div>";<br />
    			    	jQuery('#doc-attachments-box-new-attachments').append(htmlToAppend);<br />
    			    }<br />
            	</script><br />
            	<style><br />
            		.delete-button, .delete-button:hover{<br />
            			color:red;/*#BC0B0B;*/<br />
    <p>        		}<br />
            		.float-right{<br />
            			float:right;<br />
            		}<br />
            		a.spacey{<br />
            			line-height:2em;<br />
            		}<br />
    <p>        	<label>Attachments:</label><br />
            	<div id='doc-attachments-box'><br />
            		<div id='doc-attachments-box-old-attachments'><br />
            			<?<br />
    <p>	        		foreach($attachments as $attachment){<br />
    	        			?><br />
    	        			<div class='bp-docs-attachment-row bp-docs-old-attachment'><br />
    	        				<a>guid?>'><?=$attachment->post_name?></a><br />
    	        				<span style='float:right'><input type='checkbox' value='true' name='bp-docs-existing-attachment-<?=$attachment->ID?>'/>Delete?</span><br />
    	        			</div><br />
    	        			<?<br />
    	        		}<br />
    	        		?><br />
            		</div><br />
            		<div id='doc-attachments-box-new-attachments'><br />
    	        		<!-- <span class='bp-docs-attachment-row'><br />
    	        			<input type='file' class='bp-docs-attachment' name='bp-docs-attachments-0'><br />
    <p>        		</div><br />
            		<a>Select A New Attachment</a><br />
            	</div><br />
            </div><br />

    That’ll take care of adding attachments to the edit page, and then to show the docs in teh view page, edit buddypress-docs/includes/templates/single-doc.php on about line 26, just before the div of class ‘doc-meta’:

    <br />
    <div class='doc-attachments'><br />
    <h3>Attachments</h3><br />
    <?<br />
    <p>foreach($attachments as $attachment){<br />
    	?><br />
    	<div class='bp-docs-attachment-row bp-docs-old-attachment'></p>
    <p>		<a>guid?>'><?=$attachment->post_name?> </a><br />
    	</div><br />
    	<?<br />
    }<br />
    ?><br />
    </div><br />

    I just sent a pull request to the plugin author, hopefully it’ll check out…

    Clifford Paulick


    Just tagging along on this discussion. Looking forward to a plugin update. P.S. if needing something separate for now, try


    We have developed a plugin some time ago which adds file upload functionality to this plugin.
    – It adds an extra button in the wysiwyg editor. Pressing this button opens a file dialog
    – The file is added to the wiki as a link (or an image). The download is a protected URL (for private groups) and files saved in an directory
    – It includes extention filter and file size filter

    There is however a small bug in it. The system uses a very old version of a fileuploader which doesn’t function in Internet Explorer. I want to implement a new version of

    Someone willing to cooperate? And get this plugin released?

    Kind regards,

    Hi Ramon,
    Could you be kind and tell us what is the plugin you’ve developped to add the file upload functionnality to Buddypress Docs?



    yes, please help us know this promising plugin to help us upload docs to buddy docs;-) tx.

    Would also love to see this.

    Has anyone tried mnelson4’s hack?

    Hi all,

    I put the code here:

    It’s a basic working version and I’m looking for budget now for further development.
    Let me know what you think.

    Kind regards,

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘[Plugin: BuddyPress Docs] Docs with attachments’ is closed to new replies.