diff options
| author | Max Kremmel <xing@synapse.plus.com> | 2008-05-29 09:04:36 +0000 |
|---|---|---|
| committer | Max Kremmel <xing@synapse.plus.com> | 2008-05-29 09:04:36 +0000 |
| commit | b7273f93603c45cf9774506dc5f87a84db0b825e (patch) | |
| tree | a5c8a466af421639415b69c94457ed9dfe4bb6f7 | |
| parent | f2f8bd42911d29319464a2b41655240eea690bb8 (diff) | |
| download | liberty-b7273f93603c45cf9774506dc5f87a84db0b825e.tar.gz liberty-b7273f93603c45cf9774506dc5f87a84db0b825e.tar.bz2 liberty-b7273f93603c45cf9774506dc5f87a84db0b825e.zip | |
lots of updates, make it possible to update multiple attachments at once, better handling of attachment updates in LibertyMime
| -rw-r--r-- | LibertyMime.php | 59 | ||||
| -rw-r--r-- | mime_view.php | 28 | ||||
| -rw-r--r-- | plugins/mime.audio.php | 27 | ||||
| -rw-r--r-- | plugins/mime.default.php | 9 | ||||
| -rw-r--r-- | templates/mime_audio_edit_inc.tpl | 10 |
5 files changed, 85 insertions, 48 deletions
diff --git a/LibertyMime.php b/LibertyMime.php index c67c786..5c034e4 100644 --- a/LibertyMime.php +++ b/LibertyMime.php @@ -3,7 +3,7 @@ * Manages liberty Uploads * * @package liberty - * @version $Header: /cvsroot/bitweaver/_bit_liberty/LibertyMime.php,v 1.8 2008/05/27 14:46:47 squareing Exp $ + * @version $Header: /cvsroot/bitweaver/_bit_liberty/LibertyMime.php,v 1.9 2008/05/29 09:04:35 squareing Exp $ */ /** @@ -87,8 +87,15 @@ class LibertyMime extends LibertyAttachable { $this->mDb->StartTrans(); foreach( $pStoreHash['upload_store']['files'] as $upload ) { + // we might be updating attachments and they might have some additional data they need to process + if( @BitBase::verifyId( $upload['attachment_id'] ) && !empty( $pStoreHash['plugin'][$upload['attachment_id']] ) && is_array( $pStoreHash['plugin'][$upload['attachment_id']] )) { + foreach( $pStoreHash['plugin'][$upload['attachment_id']] as $guid => $params ) { + $this->updateAttachmentParams( $upload['attachment_id'], $guid, $params ); + } + } + // exit if $upload is empty - if( empty( $upload )) { + if( empty( $upload['tmp_name'] )) { break; } @@ -118,8 +125,8 @@ class LibertyMime extends LibertyAttachable { $function_name = 'store_function'; } - if( $store_function = LibertyMime::getPluginFunction( $guid, $function_name )) { - if( !$store_function( $storeRow, $this )) { + if( $process_function = LibertyMime::getPluginFunction( $guid, $function_name )) { + if( !$process_function( $storeRow )) { $this->mErrors = array_merge( $this->mErrors, $storeRow['errors'] ); } } else { @@ -148,23 +155,24 @@ class LibertyMime extends LibertyAttachable { * @Note: If one of the uploaded files is an update, place the attachment_id with the upload hash in $_FILES or in _files_override */ function verify( &$pParamHash ) { - global $gBitUser; + global $gBitUser, $gLibertySystem; // check to see if we have any files to upload if( isset( $pParamHash['_files_override'] )) { // we have been passed in a manually stuffed files attachment, such as a custom uploader would have done. // process this, and skip over $_FILES $uploads = $pParamHash['_files_override']; - } elseif( !empty( $_FILES ) ) { + } elseif( !empty( $_FILES )) { // we have some _FILES hanging around we will gobble up. This is inherently dagnerous chewing up a _FILES like this as // it can cause premature storing of a _FILE if you are trying to store multiple pieces of content at once. foreach( $_FILES as $key => $file ) { - if( !empty( $file['name'] )) { + if( !empty( $file['name'] ) || !empty( $file['attachment_id'] )) { $uploads[$key] = $file; } } } + // verify uploads if( !empty( $uploads ) ) { foreach( array_keys( $uploads ) as $file ) { $pParamHash['upload_store']['files'][$file] = LibertyMime::verifyAttachment( $uploads[$file] ); @@ -187,6 +195,41 @@ class LibertyMime extends LibertyAttachable { } /** + * updateAttachmentParams will update attachment parameters + * + * @param numeric $pAttachmentId attachment_id of the item we want the prefs from (optional) + * @param string $pPluginGuid GUID of the plugin that should process the data + * @param array $pParamHash Data to be processed by the plugin + * @access public + * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure + */ + function updateAttachmentParams( $pAttachmentId, $pPluginGuid, $pParamHash ) { + global $gLibertySystem; + $ret = FALSE; + + if( BitBase::verifyId( $pAttachmentId )) { + if( !empty( $this ) && !empty( $this->mStorage[$pAttachmentId] )) { + $file = $this->mStorage[$pAttachmentId]; + } else { + $file = LibertyMime::getAttachment( $pAttachmentId ); + } + + if( !empty( $file['attachment_id'] ) && !empty( $pPluginGuid ) && !empty( $pParamHash ) && $update_function = LibertyMime::getPluginFunction( $pPluginGuid, 'update_function' )) { + if( $update_function( $file, $pParamHash )) { + $ret = TRUE; + } else { + if( !empty( $file['errors'] )) { + $this->mErrors['param_update'] = $file['errors']; + } else { + $this->mErrors['param_update'] = tra( 'There was an unspecified error while updating the file.' ); + } + } + } + } + return $ret; + } + + /** * verifyAttachment will perform a generic check if a file is valid for processing * * @param array $pFile file array from $_FILES @@ -194,7 +237,7 @@ class LibertyMime extends LibertyAttachable { * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure */ function verifyAttachment( $pFile ) { - if( !empty( $pFile['tmp_name'] ) && is_file( $pFile['tmp_name'] ) && empty( $pFile['error'] )) { + if( !empty( $pFile['tmp_name'] ) && is_file( $pFile['tmp_name'] ) && empty( $pFile['error'] ) || !empty( $pFile['attachment_id'] )) { return $pFile; } } diff --git a/mime_view.php b/mime_view.php index df8fb29..c14d507 100644 --- a/mime_view.php +++ b/mime_view.php @@ -1,6 +1,6 @@ <?php /** - * @version $Header: /cvsroot/bitweaver/_bit_liberty/Attic/mime_view.php,v 1.3 2008/05/28 18:55:00 squareing Exp $ + * @version $Header: /cvsroot/bitweaver/_bit_liberty/Attic/mime_view.php,v 1.4 2008/05/29 09:04:35 squareing Exp $ * * @author xing <xing@synapse.plus.com> * @package treasury @@ -21,31 +21,25 @@ if( @!BitBase::verifyId( $_REQUEST['attachment_id'] ) || !( $attachment = Libert $gBitSystem->fatalError( tra( "The Attachment ID given is not valid" )); } +// first we need to check the permissions of the content the attachment belongs to since they inherit them +$gContent = LibertyBase::getLibertyObject( $attachment['content_id'] ); +$gContent->verifyViewPermission(); + if( !empty( $_REQUEST['plugin_submit'] )) { // now that we have data for a plugin, we'll simply feed it back to the update function of that plugin - foreach( $_REQUEST['plugin'] as $guid => $data ) { - if( $update_function = LibertyMime::getPluginFunction( $guid, 'update_function' )) { - // verify the uploaded file using the plugin - if( !$update_function( $attachment, $data )) { - if( !empty( $attachment['errors'] )) { - $feedback['error'] = $attachment['errors']; - } else { - $feedback['error'] = tra( 'There was an unspecified error while updating the file.' ); - } - } else { - $feedback['success'] = tra( "The data was successfully updated." ); - } + foreach( $_REQUEST['plugin'][$attachment['attachment_id']] as $guid => $data ) { + if( $gContent->updateAttachmentParams( $_REQUEST['attachment_id'], $guid, $data )) { + $feedback['success'] = tra( "The data was successfully updated." ); + } else { + $feedback['error'] = $gContent->mErrors; } } // reload the attachment $attachment = LibertyMime::getAttachment( $_REQUEST['attachment_id'] ); } -// first we need to check the permissions of the content the attachment belongs to since they inherit them -$gContent = LibertyBase::getLibertyObject( $attachment['content_id'] ); -$gContent->verifyViewPermission(); -$gBitSmarty->assign( 'gContent', $gContent ); $gBitSmarty->assign( 'attachment', $attachment ); +$gBitSmarty->assign( 'gContent', $gContent ); $gBitSmarty->assign( 'feedback', $feedback ); // what template are we going to use to display this attachment diff --git a/plugins/mime.audio.php b/plugins/mime.audio.php index bb7168b..79243d9 100644 --- a/plugins/mime.audio.php +++ b/plugins/mime.audio.php @@ -1,9 +1,9 @@ <?php /** - * @version $Header: /cvsroot/bitweaver/_bit_liberty/plugins/mime.audio.php,v 1.7 2008/05/28 18:55:00 squareing Exp $ + * @version $Header: /cvsroot/bitweaver/_bit_liberty/plugins/mime.audio.php,v 1.8 2008/05/29 09:04:36 squareing Exp $ * * @author xing <xing@synapse.plus.com> - * @version $Revision: 1.7 $ + * @version $Revision: 1.8 $ * created Thursday May 08, 2008 * @package liberty * @subpackage liberty_mime_handler @@ -88,6 +88,7 @@ function mime_audio_update( &$pStoreRow, $pParams = NULL ) { // if we have been passed a set of parameters, we're only interested in updating the meta data $ret = FALSE; if( BitBase::verifyId( $pStoreRow['attachment_id'] )) { + // now that the upload has been processed (if there was one), we'll deal with the additional params if( !empty( $pStoreRow['storage_path'] ) && !empty( $pParams )) { // update our local version of the file $file = BIT_ROOT_PATH.$pStoreRow['storage_path']; @@ -109,18 +110,18 @@ function mime_audio_update( &$pStoreRow, $pParams = NULL ) { } else { $pStoreRow['errors'] = $log; } - } else { - // this will set the correct pluign guid, even if we let default handle the store process - $pStoreRow['attachment_plugin_guid'] = PLUGIN_MIME_GUID_AUDIO; - $pStoreRow['log'] = array(); + } - // if storing works, we process the audio - if( $ret = mime_default_update( $pStoreRow )) { - if( !mime_audio_converter( $pStoreRow )) { - // if it all goes tits up, we'll know why - $pStoreRow['errors'] = $pStoreRow['log']; - $ret = FALSE; - } + // this will set the correct pluign guid, even if we let default handle the store process + $pStoreRow['attachment_plugin_guid'] = PLUGIN_MIME_GUID_AUDIO; + $pStoreRow['log'] = array(); + + // if storing works, we process the audio + if( !empty( $pStoreRow['upload'] ) && $ret = mime_default_update( $pStoreRow )) { + if( !mime_audio_converter( $pStoreRow )) { + // if it all goes tits up, we'll know why + $pStoreRow['errors'] = $pStoreRow['log']; + $ret = FALSE; } } } diff --git a/plugins/mime.default.php b/plugins/mime.default.php index 27088d5..f70c9e0 100644 --- a/plugins/mime.default.php +++ b/plugins/mime.default.php @@ -1,9 +1,9 @@ <?php /** - * @version $Header: /cvsroot/bitweaver/_bit_liberty/plugins/mime.default.php,v 1.8 2008/05/23 10:00:59 squareing Exp $ + * @version $Header: /cvsroot/bitweaver/_bit_liberty/plugins/mime.default.php,v 1.9 2008/05/29 09:04:36 squareing Exp $ * * @author xing <xing@synapse.plus.com> - * @version $Revision: 1.8 $ + * @version $Revision: 1.9 $ * created Thursday May 08, 2008 * @package liberty * @subpackage liberty_mime_handler @@ -117,9 +117,8 @@ function mime_default_verify( &$pStoreRow ) { function mime_default_update( &$pStoreRow ) { global $gBitSystem; - if( BitBase::verifyId( $pStoreRow['attachment_id'] )) { - // get the data we need to deal with - $query = "SELECT `storage_path` FROM `".BIT_DB_PREFIX."liberty_files` lf WHERE `file_id` = ?"; + // this will reset the uploaded file + if( BitBase::verifyId( $pStoreRow['attachment_id'] ) && !empty( $pStoreRow['upload'] )) { if( !empty( $pStoreRow['storage_path'] )) { // First we remove the old file $file = BIT_ROOT_PATH.$pStoreRow['storage_path']; diff --git a/templates/mime_audio_edit_inc.tpl b/templates/mime_audio_edit_inc.tpl index 5ab22dc..209c6ca 100644 --- a/templates/mime_audio_edit_inc.tpl +++ b/templates/mime_audio_edit_inc.tpl @@ -2,35 +2,35 @@ <div class="row"> {formlabel label="Title" for="title"} {forminput} - <input type="text" size="35" id="audio_title" name="plugin[mimeaudio][title]" value="{$attachment.meta.title}" /> + <input type="text" size="35" id="audio_title" name="plugin[{$attachment.attachment_id}][mimeaudio][title]" value="{$attachment.meta.title}" /> {/forminput} </div> <div class="row"> {formlabel label="Album" for="audio_album"} {forminput} - <input type="text" size="35" id="audio_album" name="plugin[mimeaudio][album]" value="{$attachment.meta.album}" /> + <input type="text" size="35" id="audio_album" name="plugin[{$attachment.attachment_id}][mimeaudio][album]" value="{$attachment.meta.album}" /> {/forminput} </div> <div class="row"> {formlabel label="Artist" for="audio_artist"} {forminput} - <input type="text" size="35" id="audio_artist" name="plugin[mimeaudio][artist]" value="{$attachment.meta.artist}" /> + <input type="text" size="35" id="audio_artist" name="plugin[{$attachment.attachment_id}][mimeaudio][artist]" value="{$attachment.meta.artist}" /> {/forminput} </div> <div class="row"> {formlabel label="Year" for="audio_year"} {forminput} - <input type="text" size="35" id="audio_year" name="plugin[mimeaudio][year]" value="{$attachment.meta.year}" /> + <input type="text" size="35" id="audio_year" name="plugin[{$attachment.attachment_id}][mimeaudio][year]" value="{$attachment.meta.year}" /> {/forminput} </div> <div class="row"> {formlabel label="Genre" for="audio_genre"} {forminput} - <input type="text" size="35" id="audio_genre" name="plugin[mimeaudio][genre]" value="{$attachment.meta.genre}" /> + <input type="text" size="35" id="audio_genre" name="plugin[{$attachment.attachment_id}][mimeaudio][genre]" value="{$attachment.meta.genre}" /> {/forminput} </div> {/strip} |
