diff options
| -rw-r--r-- | LibertyAttachable.php | 55 | ||||
| -rw-r--r-- | templates/edit_storage.tpl | 10 | ||||
| -rw-r--r-- | templates/edit_storage_list.tpl | 44 |
3 files changed, 77 insertions, 32 deletions
diff --git a/LibertyAttachable.php b/LibertyAttachable.php index e140c3f..6eb452c 100644 --- a/LibertyAttachable.php +++ b/LibertyAttachable.php @@ -3,7 +3,7 @@ * Management of Liberty Content * * @package liberty - * @version $Header: /cvsroot/bitweaver/_bit_liberty/LibertyAttachable.php,v 1.124 2007/09/15 08:08:54 squareing Exp $ + * @version $Header: /cvsroot/bitweaver/_bit_liberty/LibertyAttachable.php,v 1.125 2007/09/15 11:34:32 squareing Exp $ * @author spider <spider@steelsun.com> */ // +----------------------------------------------------------------------+ @@ -120,9 +120,10 @@ class LibertyAttachable extends LibertyContent { // Process a JPEG if( function_exists( 'exif_read_data' ) && !empty( $pParamHash['upload']['tmp_name'] ) && stripos( $pParamHash['upload']['type'], 'jpeg' ) !== FALSE ) { $exifHash = @exif_read_data( $pParamHash['upload']['tmp_name'], 0, true); -//vd( $exifHash ); + //vd( $exifHash ); - require_once UTIL_PKG_PATH.'jpeg_metadata_tk/JPEG.php'; // Change: Allow this example file to be easily relocatable - as of version 1.11 + // Change: Allow this example file to be easily relocatable - as of version 1.11 + require_once UTIL_PKG_PATH.'jpeg_metadata_tk/JPEG.php'; require_once UTIL_PKG_PATH.'jpeg_metadata_tk/JFIF.php'; require_once UTIL_PKG_PATH.'jpeg_metadata_tk/PictureInfo.php'; require_once UTIL_PKG_PATH.'jpeg_metadata_tk/XMP.php'; @@ -186,7 +187,7 @@ class LibertyAttachable extends LibertyContent { } else { $storageGuid = $pParamHash['storage_guid']; } - + if( !empty( $pFile['size'] ) ) { $this->extractMetaData( $pParamHash ); // meta data may be stupid and have stuffed title with all spaces @@ -268,8 +269,6 @@ class LibertyAttachable extends LibertyContent { } // Support for single bitfile upload - - if( !empty( $_FILES ) ) { foreach( array_keys( $_FILES ) as $f ) { $this->verifyAttachment( $pParamHash, $_FILES[$f] ); @@ -280,7 +279,7 @@ class LibertyAttachable extends LibertyContent { } // Things to be stored should be shoved in the array $pParamHash['STORAGE'] - function store ( &$pParamHash ) { + function store( &$pParamHash ) { global $gLibertySystem, $gBitSystem; $this->mDb->StartTrans(); if( LibertyAttachable::verify( $pParamHash ) && LibertyContent::store( $pParamHash )) { @@ -358,6 +357,10 @@ class LibertyAttachable extends LibertyContent { } } } + + if( @BitBase::verifyId( $pParamHash['liberty_attachments']['primary'] )) { + $this->setPrimaryAttachment( $pParamHash['liberty_attachments']['primary'] ); + } } $this->mDb->CompleteTrans(); @@ -424,6 +427,7 @@ class LibertyAttachable extends LibertyContent { /** * Expunges the content deleting attachments if asked to do so, otherwise just detaching them + * TODO: this hasn't been updated yet since the liberty_attachments update */ function expunge ($pDeleteAttachments=FALSE) { if( !empty( $this->mStorage ) && count( $this->mStorage ) ) { @@ -497,7 +501,7 @@ class LibertyAttachable extends LibertyContent { $query = " SELECT * FROM `".BIT_DB_PREFIX."liberty_attachments` la - WHERE la.`content_id`=?"; + WHERE la.`content_id`=? ORDER BY la.`attachment_id` ASC"; if( $result = $this->mDb->query( $query,array( (int)$conId ))) { $this->mStorage = array(); while( $row = $result->fetchRow() ) { @@ -528,7 +532,7 @@ class LibertyAttachable extends LibertyContent { if( @$this->verifyId( $pAttachmentId ) ) { $query = "SELECT * FROM `".BIT_DB_PREFIX."liberty_attachments` a WHERE a.`attachment_id`=?"; - if( $result = $this->mDb->query($query,array((int) $pAttachmentId)) ) { + if( $result = $this->mDb->query( $query, array( (int)$pAttachmentId ))) { $ret = array(); if( $row = $result->fetchRow() ) { if( $func = $gLibertySystem->getPluginFunction( $row['attachment_plugin_guid'], 'load_function' ) ) { @@ -540,5 +544,38 @@ class LibertyAttachable extends LibertyContent { return $ret; } + /** + * setPrimary will set is_primary 'y' for the specified attachment and will ensure that all others are set to 'n' + * + * @param numeric $pAttachmentId attachment id of the item we want to set primary + * @access public + * @return TRUE on success, FALSE on failure + */ + function setPrimaryAttachment( $pAttachmentId = NULL ) { + $ret = FALSE; + + // we have been given an attachment_id. we'll use this to set the primary attachment_id + if( @BitBase::verifyId( $pAttachmentId )) { + + // get attachment we want to set primary + $attachment = $this->getAttachment( $pAttachmentId ); + + // set is_primary as 'n' first - there can only be one + $query = " + UPDATE `".BIT_DB_PREFIX."liberty_attachments` + SET `is_primary` = ? WHERE `content_id` = ?"; + $this->mDb->query( $query, array( NULL, $attachment['content_id'] )); + + // now update the attachment to is_primary + $query = " + UPDATE `".BIT_DB_PREFIX."liberty_attachments` + SET `is_primary` = ? WHERE `attachment_id` = ?"; + $this->mDb->query( $query, array( 'y', $pAttachmentId )); + + $ret = TRUE; + } + + return $ret; + } } ?> diff --git a/templates/edit_storage.tpl b/templates/edit_storage.tpl index 813060e..eb1981b 100644 --- a/templates/edit_storage.tpl +++ b/templates/edit_storage.tpl @@ -16,14 +16,18 @@ {/if} <div id="edit_storage_list_div"> - {include file="bitpackage:liberty/edit_storage_list.tpl"} + {include file="bitpackage:liberty/edit_storage_list.tpl" uploadTab=TRUE} </div> -{if $gBitUser->hasPermission('p_liberty_attach_attachments') } +{* The new attachment browser is supposd to only provide an easy means of +viewing existing content that can be inserted into the contnet using +{attachment} or {content} or similar. there is no means to attach and detach +content anymore *} +{*if $gBitUser->hasPermission('p_liberty_attach_attachments') } <h2 class="clear"><a href="javascript:ajax_updater( 'attbrowser', '{$smarty.const.LIBERTY_PKG_URL}ajax_attachment_browser.php', 'ajax=true&content_id={$gContent->mContentId}' );">{tr}Attachment Browser{/tr}</a></h2> <noscript><div class="warning">{tr}The attachment browser only works with javascript enabled.{/tr}</div></noscript> <div id="attbrowser" class="attbrowser"><p>{tr}Please click on the Attachement Browser link above to view available attachments.{/tr}</p></div> {else} <p>{tr}Sorry - you do not have permission to attach files to this content.{/tr}</p> -{/if} +{/if*} {/strip} diff --git a/templates/edit_storage_list.tpl b/templates/edit_storage_list.tpl index 449cc39..96dbb2c 100644 --- a/templates/edit_storage_list.tpl +++ b/templates/edit_storage_list.tpl @@ -4,44 +4,48 @@ <div class="row"> <table class="data" summary="List of attached files"> {if $attachmentBrowser} - <caption>{tr}Your Attachments{/tr}</caption> + <caption>{tr}Your Attachments{/tr}</caption> {else} - <caption>{tr}Items {if $libertyUploader && empty($gContent->mContentId)}That Will Be{/if} Attached Directly to this Content{/tr}</caption> + <caption>{tr}Items {if $libertyUploader && empty($gContent->mContentId)}That Will Be{/if} Attached Directly to this Content{/tr}</caption> {/if} <tr> - <th scope="col" title="{tr}Thumbnail{/tr}">{tr}Thumbnail{/tr}</th> - <th scope="col" title="{tr}File Properties{/tr}">{tr}File Properties{/tr}</th> - <th scope="col" title="{tr}Inclusion Code{/tr}">{tr}Inclusion Code{/tr}</th> + <th scope="col" style="width:30%:" title="{tr}Thumbnail{/tr}">{tr}Thumbnail{/tr}</th> + <th scope="col" style="width:40%:" title="{tr}Inclusion Code{/tr}">{tr}Inclusion Code{/tr}</th> + <th scope="col" style="width:30%:" title="{tr}Actions{/tr}">{tr}Actions{/tr}</th> </tr> {foreach from=$gContent->mStorage item=storage key=attachmentId name=atts} <tr class="{cycle values="odd,even"}"> <td style="text-align:center;"> {jspopup href=$storage.source_url title=$storage.title|default:$storage.filename notra=1 img=$storage.thumbnail_url.avatar} + <br />{$storage.filename} {if $smarty.foreach.atts.first} {formhelp note="click to see large preview"} {/if} </td> - <td> - {tr}Attachment ID{/tr}: {$attachmentId} {if $gContent->mInfo.primary_attachment_id eq $attachmentId}({tr}Primary{/tr}){/if} <br /> - {tr}Filename{/tr}: {$storage.filename} <br /> - {tr}Actions{/tr}: - {if $gBitUser->isAdmin() || ($storage.user_id == $gBitUser->mUserId && $gBitUser->hasPermission('p_liberty_delete_attachments') ) } - {if $attachmentBrowser} - <a href="javascript:ajax_updater('attbrowser', '{$attachmentActionBaseURL}', 'deleteAttachment={$attachmentId}');">{biticon ipackage="icons" iname="edit-delete" iexplain="delete"}</a> - {elseif $libertyUploader || $gBitSystem->getConfig('liberty_attachment_style') == 'ajax'} - <a href="javascript:ajax_updater('edit_storage_list_div', '{$attachmentActionBaseURL}', 'deleteAttachment={$attachmentId}');">{biticon ipackage="icons" iname="edit-delete" iexplain="delete"}</a> - {else} - <a href="{$attachmentActionBaseURL}&deleteAttachment={$attachmentId}">{biticon ipackage="icons" iname="edit-delete" iexplain="delete"}</a> - {/if} - {/if} - </td> - <td style="text-align:center; width:30%"> + <td style="text-align:center;"> {$storage.wiki_plugin_link} {if $smarty.foreach.atts.first} {formhelp note="copy this code into your edit window to embed the file into your text"} {/if} </td> + <td class="actionicon"> + {if $uploadTab} + {if $gBitUser->isAdmin() || ($storage.user_id == $gBitUser->mUserId && $gBitUser->hasPermission('p_liberty_delete_attachments') ) } + {if $attachmentBrowser} + <a href="javascript:ajax_updater('attbrowser', '{$attachmentActionBaseURL}', 'deleteAttachment={$attachmentId}');">{biticon ipackage="icons" iname="edit-delete" iexplain="delete"}</a> + {elseif $libertyUploader || $gBitSystem->getConfig('liberty_attachment_style') == 'ajax'} + <a href="javascript:ajax_updater('edit_storage_list_div', '{$attachmentActionBaseURL}', 'deleteAttachment={$attachmentId}');">{biticon ipackage="icons" iname="edit-delete" iexplain="delete"}</a> + {else} + <a href="{$attachmentActionBaseURL}&deleteAttachment={$attachmentId}">{biticon ipackage="icons" iname="edit-delete" iexplain="delete"}</a> + {/if} + {/if} + {else} + {* these radio buttons can not be displayed twice in the same form due to interference in $_REQUEST *} + <label>{tr}{$primary_label|default:"Primary"}{/tr}: <input type="radio" name="liberty_attachments[primary]" value="{$attachmentId}"{if $storage.is_primary eq 'y'} checked="checked"{/if}/></label> + <br /> + {/if} + </td> </tr> {/foreach} </table> |
