summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--LibertyAttachable.php530
-rw-r--r--admin/schema_inc.php29
-rw-r--r--templates/edit_primary_attachment_inc.tpl7
-rw-r--r--templates/edit_storage_list.tpl11
4 files changed, 127 insertions, 450 deletions
diff --git a/LibertyAttachable.php b/LibertyAttachable.php
index 54d4db7..ab60b59 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.121 2007/08/10 18:52:53 spiderr Exp $
+ * @version $Header: /cvsroot/bitweaver/_bit_liberty/LibertyAttachable.php,v 1.122 2007/09/15 06:18:05 spiderr Exp $
* @author spider <spider@steelsun.com>
*/
// +----------------------------------------------------------------------+
@@ -176,104 +176,57 @@ class LibertyAttachable extends LibertyContent {
}
- function verifyAttachment( &$pParamHash, $file ) {
+ function verifyAttachment( &$pParamHash, $pFile ) {
global $gBitSystem, $gBitUser, $gLibertySystem;
- if( !empty( $_FILES[$file] ) ) {
- // tiki files upload
- $pParamHash[$file] = $_FILES[$file];
- }
-
- if( !empty( $pParamHash[$file]['size'] ) && !empty( $pParamHash[$file] ) && is_array( $pParamHash[$file] ) ) {
- $save = TRUE;
- if( $save ) {
- if( empty( $pParamHash['storage_guid'] )) {
- // only file format storage available at present
- $pParamHash['storage_guid'] = $storageGuid = PLUGIN_GUID_BIT_FILES;
- } else {
- $storageGuid = $pParamHash['storage_guid'];
+ if( !empty( $pFile['size'] ) && !empty( $pFile ) ) {
+ if( empty( $pParamHash['storage_guid'] )) {
+ // only file format storage available at present
+ $pParamHash['storage_guid'] = $storageGuid = PLUGIN_GUID_BIT_FILES;
+ } else {
+ $storageGuid = $pParamHash['storage_guid'];
+ }
+
+ if( !empty( $pFile['size'] ) ) {
+ $this->extractMetaData( $pParamHash );
+ // meta data may be stupid and have stuffed title with all spaces
+ if( !empty( $pParamHash['title'] ) ) {
+ $pParamHash['title'] = trim( $pParamHash['title'] );
}
-
- if( !empty( $pParamHash[$file]['size'] ) ) {
- $this->extractMetaData( $pParamHash );
- // meta data may be stupid and have stuffed title with all spaces
- if( !empty( $pParamHash['title'] ) ) {
- $pParamHash['title'] = trim( $pParamHash['title'] );
- }
-
- // let's add a default title
- if( empty( $pParamHash['title'] ) && !empty( $pParamHash['upload']['name'] ) ) {
- if( preg_match( '/^[A-Z]:\\\/', $pParamHash['upload']['name'] ) ) {
- // MSIE shit file names if passthrough via gigaupload, etc.
- // basename will not work - see http://us3.php.net/manual/en/function.basename.php
- $tmp = preg_split("[\\\]",$pParamHash['upload']['name']);
- $defaultName = $tmp[count($tmp) - 1];
- } elseif( strpos( '.', $pParamHash['upload']['name'] ) ) {
- list( $defaultName, $ext ) = explode( '.', $pParamHash['upload']['name'] );
- } else {
- $defaultName = $pParamHash['upload']['name'];
- }
- $pParamHash['title'] = str_replace( '_', ' ', substr( $defaultName, 0, strrpos( $defaultName, '.' ) ) );
- }
-
- if ( !is_windows() ) {
- list( $pParamHash[$file]['name'], $pParamHash[$file]['type'] ) = $gBitSystem->verifyFileExtension( $pParamHash[$file]['tmp_name'], $pParamHash[$file]['name'] );
+ // let's add a default title
+ if( empty( $pParamHash['title'] ) && !empty( $pParamHash['upload']['name'] ) ) {
+ if( preg_match( '/^[A-Z]:\\\/', $pParamHash['upload']['name'] ) ) {
+ // MSIE shit file names if passthrough via gigaupload, etc.
+ // basename will not work - see http://us3.php.net/manual/en/function.basename.php
+ $tmp = preg_split("[\\\]",$pParamHash['upload']['name']);
+ $defaultName = $tmp[count($tmp) - 1];
+ } elseif( strpos( '.', $pParamHash['upload']['name'] ) ) {
+ list( $defaultName, $ext ) = explode( '.', $pParamHash['upload']['name'] );
} else {
-// $pParamHash[$file]['type'] = $gBitSystem->verifyMimeType( $pParamHash[$file]['tmp_name'] );
- }
- // clean out crap that can make life difficult in server maintenance
- $cleanedBaseName = preg_replace( '/[&\%:\/\\\]/', '', substr( $pParamHash[$file]['name'], 0, strrpos( $pParamHash[$file]['name'], '.' ) ) );
- $pParamHash[$file]['dest_base_name'] = $cleanedBaseName;
- $pParamHash[$file]['source_file'] = $pParamHash[$file]['tmp_name'];
- // lowercase all file extensions
- $pParamHash[$file]['name'] = $cleanedBaseName.strtolower( substr( $pParamHash[$file]['name'], strrpos( $pParamHash[$file]['name'], '.' ) ) );
- if (!isset($pParamHash['STORAGE'][$storageGuid])) {
- $pParamHash['STORAGE'][$storageGuid] = array();
+ $defaultName = $pParamHash['upload']['name'];
}
- $pParamHash['STORAGE'][$storageGuid][$file] = array('upload' => &$pParamHash[$file]);
+ $pParamHash['title'] = str_replace( '_', ' ', substr( $defaultName, 0, strrpos( $defaultName, '.' ) ) );
}
- }
- }
- }
-
- function verifyAttachments( &$pParamHash ) {
- global $gBitSystem;
- // Support for single bitfile upload
- $this->verifyAttachment( $pParamHash, 'upload' );
- // Auto add uploads for multiple attachment style
- if ($gBitSystem->getConfig('liberty_attachment_style') == "multiple") {
- if (empty($pParamHash['upload_arrays'])) {
- $pParamHash['upload_arrays'] = 'uploads';
- }
- else {
- $pParamHash['upload_arrays'] .= ',uploads';
- }
- }
- // Support for primary attachment
- $this->verifyAttachment( $pParamHash, 'primary_attachment' );
- // Support for multiple arrays of uploads.
- if (!empty($pParamHash['upload_arrays'])) {
- $other_uploads = split(',',$pParamHash['upload_arrays']);
- foreach ($other_uploads as $upload_array) {
- // We need a max to guard against infinite loop.
- // multifile.js sets this for us.
- $max_name = $upload_array.'_max';
- if (isset($pParamHash[$max_name])) {
- for ($i = 0; $i <= $pParamHash[$max_name]; $i++) {
- $field = $upload_array."_".$i;
- if(isset($_FILES[$field]) &&
- $_FILES[$field]['error'] == 0) {
- $this->verifyAttachment($pParamHash, $field);
- }
- }
+ if ( !is_windows() ) {
+ list( $pFile['name'], $pFile['type'] ) = $gBitSystem->verifyFileExtension( $pFile['tmp_name'], $pFile['name'] );
+ } else {
+// $pFile['type'] = $gBitSystem->verifyMimeType( $pFile['tmp_name'] );
}
+ // clean out crap that can make life difficult in server maintenance
+ $cleanedBaseName = preg_replace( '/[&\%:\/\\\]/', '', substr( $pFile['name'], 0, strrpos( $pFile['name'], '.' ) ) );
+ $pFile['dest_base_name'] = $cleanedBaseName;
+ $pFile['source_file'] = $pFile['tmp_name'];
+ // lowercase all file extensions
+ $pFile['name'] = $cleanedBaseName.strtolower( substr( $pFile['name'], strrpos( $pFile['name'], '.' ) ) );
+ if (!isset($pParamHash['STORAGE'][$storageGuid])) {
+ $pParamHash['STORAGE'][$storageGuid] = array();
+ }
+ $pParamHash['STORAGE'][$storageGuid][] = array('upload' => &$pFile);
}
}
-
- return ( count( $this->mErrors ) == 0 );
}
function verify( &$pParamHash ) {
@@ -314,201 +267,96 @@ class LibertyAttachable extends LibertyContent {
$pParamHash['subdir'] = 'files';
}
- $this->verifyAttachments( $pParamHash );
- $this->verifyPrimaryAttachmentId( $pParamHash );
-
- return( count( $this->mErrors ) == 0 );
- }
+ // Support for single bitfile upload
- function storeNewAttachments(&$pParamHash) {
- global $gLibertySystem, $gBitSystem, $gBitUser;
- foreach( array_keys( $pParamHash['STORAGE'] ) as $guid ) {
- $storeRows = &$pParamHash['STORAGE'][$guid]; // short hand variable assignment
- // If it is empty then nothing more to do. Avoid error in foreach.
- if (empty($storeRows)) {
- continue;
+
+ if( !empty( $_FILES ) ) {
+ foreach( array_keys( $_FILES ) as $f ) {
+ $this->verifyAttachment( $pParamHash, $_FILES[$f] );
}
- foreach( $storeRows as $key => $value ) {
- $storeRow = &$pParamHash['STORAGE'][$guid][$key];
- $storeRow['plugin_guid'] = $guid;
- if (empty($pParamHash['content_id'])) {
- $storeRow['content_id'] = $gBitUser->mContentId;
- } else {
- $storeRow['content_id'] = $pParamHash['content_id']; // copy in content_id
- }
+ }
- if (!empty($pParamHash['content_id'])) {
- $storeRow['content_id'] = $pParamHash['content_id']; // copy in content_id
- }
+ return ( count( $this->mErrors ) == 0 );
+ }
- if (!empty($pParamHash['user_id'])) {
- $storeRow['user_id'] = $pParamHash['user_id']; // copy in the user_id
- } else {
- $storeRow['user_id'] = $gBitUser->mUserId;
- }
+ // Things to be stored should be shoved in the array $pParamHash['STORAGE']
+ function store ( &$pParamHash ) {
+ global $gLibertySystem, $gBitSystem;
+ $this->mDb->StartTrans();
+ if( LibertyAttachable::verify( $pParamHash ) && LibertyContent::store( $pParamHash )) {
+ if(!empty( $pParamHash['STORAGE'] ) && count( $pParamHash['STORAGE'] ) ) {
- // do we have a verify function for this storage type, and do things verify?
- $verifyFunc = $gLibertySystem->getPluginFunction( $guid, 'verify_function' );
- if( $verifyFunc && $verifyFunc( $storeRow ) ) {
- // For backwards compatibility with a single upload.
- if( @BitBase::verifyId( $pParamHash['attachment_id'] )) {
- $storeRow['upload']['attachment_id'] = $storeRow['attachment_id'] = $pParamHash['attachment_id'];
- } else {
- if ( defined( 'LINKED_ATTACHMENTS' ) && @BitBase::verifyId( $pParamHash['content_id'] ) ) {
- $storeRow['upload']['attachment_id'] = $storeRow['attachment_id'] = $pParamHash['content_id'];
- } else {
- $storeRow['upload']['attachment_id'] = $storeRow['attachment_id'] =
- defined( 'LINKED_ATTACHMENTS' ) ? $this->mDb->GenID( 'liberty_content_id_seq') : $this->mDb->GenID( 'liberty_attachments_id_seq' );
- }
+ foreach( array_keys( $pParamHash['STORAGE'] ) as $guid ) {
+ $storeRows = &$pParamHash['STORAGE'][$guid]; // short hand variable assignment
+ // If it is empty then nothing more to do. Avoid error in foreach.
+ if (empty($storeRows)) {
+ continue;
}
- // if we have uploaded a file, we can take care of that generically
- if( is_array( $storeRow['upload'] ) && !empty( $storeRow['upload']['size'] ) ) {
- if( empty( $storeRow['upload']['type'] ) ) {
- $ext = substr( $storeRow['upload']['name'], strrpos( $storeRow['upload']['name'], '.' ) + 1 );
- $storeRow['upload']['type'] = $gBitSystem->lookupMimeType( $ext );
- }
- $storeRow['upload']['dest_path'] = $this->getStorageBranch( $storeRow['attachment_id'], $storeRow['user_id'], $this->getStorageSubDirName() );
- if (!empty( $pParamHash['thumbnail_sizes'] ) ) {
- $storeRow['upload']['thumbnail_sizes'] = $pParamHash['thumbnail_sizes'];
- }
- $storagePath = liberty_process_upload( $storeRow );
- // We're gonna store to local file system & liberty_files table
- if( empty( $storagePath ) ) {
- $this->mErrors['file'] = tra( "Could not store file" ).": ".$storeRow['upload']['name'].'.';
- $storeRow['attachment_id'] = NULL;
- $storeRow['upload']['attachment_id'] = NULL;
+ foreach( $storeRows as $key => $value ) {
+ $storeRow = &$pParamHash['STORAGE'][$guid][$key];
+ $storeRow['plugin_guid'] = $guid;
+ if (empty($pParamHash['content_id'])) {
+ $storeRow['content_id'] = $gBitUser->mContentId;
} else {
- $storeRow['upload']['dest_file_path'] = $storagePath;
+ $storeRow['content_id'] = $pParamHash['content_id']; // copy in content_id
}
- }
- if( @BitBase::verifyId( $storeRow['attachment_id'] ) && $storeFunc = $gLibertySystem->getPluginFunction( $storeRow['plugin_guid'], 'store_function' )) {
- $this->mStorage = $storeFunc( $storeRow );
- }
-
- if( !@BitBase::verifyId( $pParamHash['attachment_id'] )) {
- $sql = "INSERT INTO `".BIT_DB_PREFIX."liberty_attachments` ( `attachment_id`, `attachment_plugin_guid`, `foreign_id`, `user_id` ) VALUES ( ?, ?, ?, ? )";
- $rs = $this->mDb->query( $sql, array( $storeRow['attachment_id'], $storeRow['plugin_guid'], (int)$storeRow['foreign_id'], $storeRow['user_id'] ) );
- if (!empty($storeRow['content_id'])) {
- $sql = "INSERT INTO `".BIT_DB_PREFIX."liberty_attachments_map` (attachment_id, content_id) VALUES (?, ?)";
- $rs = $this->mDb->query($sql, array( $storeRow['attachment_id'], $storeRow['content_id']));
+ if (!empty($pParamHash['content_id'])) {
+ $storeRow['content_id'] = $pParamHash['content_id']; // copy in content_id
}
- }
- }
- }
- // For backwards compatibility with a single upload.
- if (empty($pParamHash['attachment_id']) && !empty($storeRows['upload']['attachment_id'])) {
- $pParamHash['attachment_id'] = $storeRows['upload']['attachment_id'];
- }
- }
- }
+ if (!empty($pParamHash['user_id'])) {
+ $storeRow['user_id'] = $pParamHash['user_id']; // copy in the user_id
+ } else {
+ $storeRow['user_id'] = $gBitUser->mUserId;
+ }
- function storeExistingAttachments(&$pParamHash) {
- if( @$this->verifyId( $this->mContentId ) && !empty( $pParamHash['existing_attachment_id'] )) {
- // Allow for an array of attachment ids
- foreach( $pParamHash['existing_attachment_id'] as $existingAttachmentId ) {
- // allow for multiple values separated by any non numeric character
- $ids = preg_split( '/\D/', $existingAttachmentId );
- foreach( $ids as $id ) {
- $id = ( int )$id;
- $bindVars = array($id, $this->mContentId);
- if( @$this->verifyId( $id ) ) {
- // Is it already attached?
- $query = "SELECT COUNT(*) from `".BIT_DB_PREFIX."liberty_attachments_map` WHERE attachment_id = ? AND content_id = ?";
- if($this->mDb->getOne( $query, $bindVars ) == 0) {
- // Does the attachment exist?
- $query = "SELECT COUNT(*) from `".BIT_DB_PREFIX."liberty_attachments` WHERE attachment_id = ?";
- if ($this->mDb->getOne($query, array($id)) == 1) {
- // Okay insert it.
- $query = "INSERT INTO `".BIT_DB_PREFIX."liberty_attachments_map` (attachment_id, content_id) VALUES (?, ?)";
- $this->mDb->query($query, $bindVars);
+ // do we have a verify function for this storage type, and do things verify?
+ $verifyFunc = $gLibertySystem->getPluginFunction( $guid, 'verify_function' );
+ if( $verifyFunc && $verifyFunc( $storeRow ) ) {
+ // For backwards compatibility with a single upload.
+ if( @BitBase::verifyId( $pParamHash['attachment_id'] )) {
+ $storeRow['upload']['attachment_id'] = $storeRow['attachment_id'] = $pParamHash['attachment_id'];
} else {
- $this->mErrors[] = tra("No such attachment: ") . $id;
+ if ( defined( 'LINKED_ATTACHMENTS' ) && @BitBase::verifyId( $pParamHash['content_id'] ) ) {
+ $storeRow['upload']['attachment_id'] = $storeRow['attachment_id'] = $pParamHash['content_id'];
+ } else {
+ $storeRow['upload']['attachment_id'] = $storeRow['attachment_id'] =
+ defined( 'LINKED_ATTACHMENTS' ) ? $this->mDb->GenID( 'liberty_content_id_seq') : $this->mDb->GenID( 'liberty_attachments_id_seq' );
+ }
+ }
+ // if we have uploaded a file, we can take care of that generically
+ if( is_array( $storeRow['upload'] ) && !empty( $storeRow['upload']['size'] ) ) {
+ if( empty( $storeRow['upload']['type'] ) ) {
+ $ext = substr( $storeRow['upload']['name'], strrpos( $storeRow['upload']['name'], '.' ) + 1 );
+ $storeRow['upload']['type'] = $gBitSystem->lookupMimeType( $ext );
+ }
+ $storeRow['upload']['dest_path'] = $this->getStorageBranch( $storeRow['attachment_id'], $storeRow['user_id'], $this->getStorageSubDirName() );
+ if (!empty( $pParamHash['thumbnail_sizes'] ) ) {
+ $storeRow['upload']['thumbnail_sizes'] = $pParamHash['thumbnail_sizes'];
+ }
+ $storagePath = liberty_process_upload( $storeRow );
+ // We're gonna store to local file system & liberty_files table
+ if( empty( $storagePath ) ) {
+ $this->mErrors['file'] = tra( "Could not store file" ).": ".$storeRow['upload']['name'].'.';
+ $storeRow['attachment_id'] = NULL;
+ $storeRow['upload']['attachment_id'] = NULL;
+ } else {
+ $storeRow['upload']['dest_file_path'] = $storagePath;
+ }
}
- }
- } elseif( !empty( $id )) {
- $this->mErrors[] = tra("Invalid attachment id: ") . $id;
- }
- }
- }
- }
- }
- /**
- * Verify that if somebody is setting the primary_attachment[attachment_id] that they are refering to an existing attachment
- * @param pParamHash Array with primary_attachment[attachment_id] set.
- **/
- function verifyPrimaryAttachmentId(&$pParamHash) {
- if (!empty($pParamHash['detach_primary_attachment'])) {
- $pParamHash['content_store']['primary_attachment_id'] = NULL;
- }
- if (!empty($pParamHash['primary_attachment_id'])) {
- if ($this->verifyId($pParamHash['primary_attachment_id'])) {
- $sql = "SELECT count(*) FROM `".BIT_DB_PREFIX."liberty_attachments` WHERE attachment_id = ?";
+ if( @BitBase::verifyId( $storeRow['attachment_id'] ) && $storeFunc = $gLibertySystem->getPluginFunction( $storeRow['plugin_guid'], 'store_function' )) {
+ $this->mStorage = $storeFunc( $storeRow );
+ }
- $count = $this->mDb->getOne($sql, array($pParamHash['primary_attachment_id']));
- if (!$count) {
- $this->mErrors['primary_attachment'] = tra("Could not set the primary attachment because there is no attachment with the given id.");
- } else {
- $pParamHash['content_store']['primary_attachment_id'] = $pParamHash['primary_attachment_id'];
- $pParamHash['existing_attachment_id'][] = $pParamHash['primary_attachment_id'];
+ if( !@BitBase::verifyId( $pParamHash['attachment_id'] ) ) {
+ $sql = "INSERT INTO `".BIT_DB_PREFIX."liberty_attachments` ( `content_id`, `attachment_id`, `attachment_plugin_guid`, `foreign_id`, `user_id` ) VALUES ( ?, ?, ?, ?, ? )";
+ $rs = $this->mDb->query( $sql, array( $storeRow['content_id'], $storeRow['attachment_id'], $storeRow['plugin_guid'], (int)$storeRow['foreign_id'], $storeRow['user_id'] ) );
+ }
+ }
+ }
}
- } else {
- $this->mErrors['primary_attachment'] = tra("Invalid primary attachment id.");
- }
- }
- }
-
- /**
- * Store the primary attachment id if we need to. This function can be called statically
- *
- * @param array $pParamHash should contain the primary_attachment_id and the content_id the attachment_id should be linked to
- * @access public
- * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
- */
- function storePrimaryAttachmentId( $pParamHash ) {
- global $gBitSystem;
- $ret = FALSE;
- if( !empty( $pParamHash['primary_attachment_id'] ) && empty( $pParamHash['primary_attachment']['attachment_id'] )) {
- $pParamHash['primary_attachment']['attachment_id'] = $pParamHash['primary_attachment_id'];
- }
-
- if( !empty( $pParamHash['primary_attachment']['attachment_id'] ) && !empty( $pParamHash['content_id'] )) {
- $query = "UPDATE liberty_content SET primary_attachment_id = ? WHERE content_id = ?";
- if( $gBitSystem->mDb->query( $query, array( $pParamHash['primary_attachment']['attachment_id'], $pParamHash['content_id'] ))) {
- $ret = TRUE;
- }
- }
- return $ret;
- }
-
- // Things to be stored should be shoved in the array $pParamHash['STORAGE']
- function store ( &$pParamHash ) {
- global $gLibertySystem, $gBitSystem;
- $this->mDb->StartTrans();
- if( LibertyAttachable::verify( $pParamHash ) && LibertyContent::store( $pParamHash )) {
- if(!empty( $pParamHash['STORAGE'] ) && count( $pParamHash['STORAGE'] ) ) {
- $this->storeNewAttachments($pParamHash);
- // We have to do this after LibertyContent::store so we can get the content_id and after storeNewAttachments so we can get the attachment id.
- $this->storePrimaryAttachmentId($pParamHash);
- }
- $this->storeExistingAttachments($pParamHash);
- }
- $this->mDb->CompleteTrans();
-
- return( count( $this->mErrors ) == 0 );
- }
-
- // Store attachments only not the LibertyContent bits
- function storeAttachments( &$pParamHash, $pExisting = TRUE ) {
- $this->mDb->StartTrans();
- if ($this->verifyAttachments( $pParamHash )) {
- if( !empty( $pParamHash['STORAGE'] ) && count( $pParamHash['STORAGE'] )) {
- $this->storeNewAttachments($pParamHash);
- }
- if ($pExisting) {
- $this->storeExistingAttachments($pParamHash);
}
}
$this->mDb->CompleteTrans();
@@ -545,9 +393,8 @@ class LibertyAttachable extends LibertyContent {
if( !empty( $pListHash['content_id'] ) ) {
$whereSql .= empty( $whereSql ) ? ' WHERE ' : ' AND ';
- $whereSql .= " lam.content_id = ? ";
- $selectSql .= " , lam.content_id ";
- $joinSql .= " INNER JOIN `".BIT_DB_PREFIX."liberty_attachments_map` lam ON (la.`attachment_id` = lam.`attachment_id`) ";
+ $whereSql .= " la.`content_id` = ? ";
+ $selectSql .= " , la.`content_id` ";
$bindVars[] = $pListHash['content_id'];
}
$query = "SELECT la.* $selectSql FROM `".BIT_DB_PREFIX."liberty_attachments` la INNER JOIN `".BIT_DB_PREFIX."users_users` uu ON(la.`user_id` = uu.`user_id`) $joinSql $whereSql";
@@ -560,11 +407,6 @@ class LibertyAttachable extends LibertyContent {
if( $loadFunc = $gLibertySystem->getPluginFunction( $attachment['attachment_plugin_guid'], 'load_function' )) {
$ret[$attachment['attachment_id']] = $loadFunc( $attachment );
}
- if( !empty( $pListHash['load_attached_to'] ) ) {
- $sql = "SELECT lam.`content_id` FROM `".BIT_DB_PREFIX."liberty_attachments_map` lam WHERE lam.`attachment_id` = ?";
- $attached = $this->mDb->getCol($sql, array($attachment['attachment_id']));
- $ret[$attachment['attachment_id']]['attached_to'] = $attached;
- }
}
// count all entries
@@ -618,43 +460,10 @@ class LibertyAttachable extends LibertyContent {
if( $guid && ( $this->isOwner( $row ) || $gBitUser->isAdmin() )) {
// check if we have the means available to remove this attachment
if( $expungeFunc = $gLibertySystem->getPluginFunction( $guid,'expunge_function' )) {
-
- // Find all the content that will care.
- $sql = "
- SELECT lc.`content_type_guid`, lc.`content_id`
- FROM `".BIT_DB_PREFIX."liberty_content` lc
- LEFT JOIN `".BIT_DB_PREFIX."liberty_attachments_map` lam ON (lc.`content_id`=lam.`content_id`)
- WHERE lc.`primary_attachment_id`=? OR lam.`attachment_id`=? ORDER BY `content_type_guid`";
- $ret = $this->mDb->getArray( $sql, array( $pAttachmentId, $pAttachmentId ), TRUE );
-
- // Delete the entry from the attachments map first due to the contraint set on liberty_content
- // this is needed for packages such as treasury which handle their attachments and content sepatately from LibertyAttachable
- // this information is not needed in the table anymore since we are passing content_ids on to the expunge functions
- $sql = "DELETE FROM `".BIT_DB_PREFIX."liberty_attachments_map` WHERE `attachment_id`=?";
- $this->mDb->query( $sql, array( $pAttachmentId ));
-
- // Inform all the content that will care.
- if( !empty( $ret ) && is_array( $ret )) {
- // Collect by content_type_guid into a single array to cut down construction costs
- foreach( $ret as $match ) {
- $contentTypes[$match['content_type_guid']][] = $match['content_id'];
- }
-
- // this can get pretty expensive if an attachment is attached to a ton of content
- foreach( $contentTypes as $content_type_guid => $contentIds ) {
- // expungingAttachment is a class oriented method not an object oriented method in order to save loading objects that may not care.
- $cls = $this->getLibertyClass( $content_type_guid );
-
- // calling this function should leave all liberty related tables untouched that we can remove these below
- $cls->expungingAttachment( $pAttachmentId, $contentIds );
- }
- }
-
// --- Do the final cleanup of liberty related tables ---
+vd( "$expungeFunc( $pAttachmentId )" );
if( $expungeFunc( $pAttachmentId )) {
- // Remove the primary ID from any content if it is this attachment
- $sql = "UPDATE `".BIT_DB_PREFIX."liberty_content` SET `primary_attachment_id`=NULL WHERE `primary_attachment_id` = ?";
- $this->mDb->query( $sql, array( $pAttachmentId ) );
+bt();
// Delete the attachment record.
$sql = "DELETE FROM `".BIT_DB_PREFIX."liberty_attachments` WHERE `attachment_id`=?";
$this->mDb->query( $sql, array( $pAttachmentId ) );
@@ -673,52 +482,6 @@ class LibertyAttachable extends LibertyContent {
}
/**
- * Called during attachment deletion to notify a content type that an attachment for content of that type is going away so
- * it can take appropriate action. Note that it is VITAL that content NOT call expunge(TRUE) as part of handling this
- * notification or else the universe will implode.
- *
- * @param the id of the attachment being deleted
- * @param an array of content_ids that reference this attachment that are of this type.
- */
- function expungingAttachment($pAttachmentId, $pContentIds) {
- // The default is to ignore this notification.
- }
-
- /**
- * detach attachment from content
- *
- * @param array $pAttachmentId Attachment id that needs to be detached from the content loaded
- * @param array $pContentId Optional content ID that the attachment should be detached from
- * @access public
- * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
- */
- function detachAttachment( $pAttachmentId, $pContentId = NULL ) {
- $ret = TRUE;
- if( @$this->verifyId( $pAttachmentId )) {
- if (empty($pContentId)) {
- $contentId = $this->mContentId;
- }
- if (@$this->verifyId( $contentId) ) {
- $query = "DELETE FROM `".BIT_DB_PREFIX."liberty_attachments_map` WHERE attachment_id = ? AND content_id = ?";
- $bindVars = array($pAttachmentId, $contentId);
- $ret = $this->mDb->query($query, $bindVars);
- // Remove the primary ID if it is this attachment
- $query = "UPDATE `".BIT_DB_PREFIX."liberty_content` SET primary_attachment_id=NULL WHERE primary_attachment_id = ? AND content_id = ?";
- $ret = $this->mDb->query($query, $bindVars);
- } else {
- $this->mErrors[] = tra("Unable to detach due to an invalid content id: ").$contentId;
- $ret = FALSE;
- }
- }
- else {
- $this->mErrors[] = tra("Unable to detach due to an invalid attachment id: ") . $pAttachmentId;
- $ret = FALSE;
- }
-
- return $ret;
- }
-
- /**
* fully load content and insert any attachments in $this->mStorage
* allow an optional content_id to be passed in to ease legacy lib style objects (like blogs, articles, etc.)
*
@@ -734,11 +497,9 @@ class LibertyAttachable extends LibertyContent {
if( @$this->verifyId( $conId ) ) {
LibertyContent::load( $conId );
$query = "
- SELECT lam.`content_id`, la.*, lc.`primary_attachment_id`
- FROM `".BIT_DB_PREFIX."liberty_attachments_map` lam
- INNER JOIN `".BIT_DB_PREFIX."liberty_attachments` la ON( lam.`attachment_id` = la.`attachment_id` )
- LEFT OUTER JOIN `".BIT_DB_PREFIX."liberty_content` lc ON( lam.`attachment_id` = lc.`primary_attachment_id` AND lc.`content_id` = lam.`content_id` )
- WHERE lam.`content_id`=?";
+ SELECT *
+ FROM `".BIT_DB_PREFIX."liberty_attachments` la
+ WHERE la.`content_id`=?";
if( $result = $this->mDb->query( $query,array( (int)$conId ))) {
$this->mStorage = array();
while( $row = $result->fetchRow() ) {
@@ -781,56 +542,5 @@ class LibertyAttachable extends LibertyContent {
return $ret;
}
- /**
- * This function will scan through liberty_content.data and will search for any occurrances of {attachemt id=<id>}
- *
- * @param array $pAttachmentId Attachment id of interest
- * @access public
- * @return array of content using a given attachment
- */
- function scanForAttchmentUse( $pAttachmentId ) {
- global $gLibertySystem, $gBitSystem;
- if( @BitBase::verifyId( $pAttachmentId )) {
- $ret = array();
- $query = "
- SELECT
- uue.`login` AS `modifier_user`, uue.`real_name` AS `modifier_real_name`, uue.`user_id` AS `modifier_user_id`,
- uuc.`login` AS `creator_user`, uuc.`real_name` AS `creator_real_name`, uuc.`user_id` AS `creator_user_id`,
- lc.`title`, lc.`data`, lc.`last_modified`, lc.`content_type_guid`, lc.`ip`, lc.`created`, lc.`content_id`
- FROM `".BIT_DB_PREFIX."liberty_content` lc
- INNER JOIN `".BIT_DB_PREFIX."users_users` uuc ON (lc.`modifier_user_id`=uuc.`user_id`)
- INNER JOIN `".BIT_DB_PREFIX."users_users` uue ON (lc.`modifier_user_id`=uue.`user_id`)
- LEFT OUTER JOIN `".BIT_DB_PREFIX."liberty_content_hits` lch ON( lc.`content_id` = lch.`content_id`)
- ORDER BY ".$this->mDb->convertSortmode( 'last_modified_desc' );
-
- $result = $this->mDb->query( $query );
- $contentTypes = $gLibertySystem->mContentTypes;
- while( $aux = $result->fetchRow() ) {
- if( preg_match( "#\{attachment[^\}]*\bid\s*=\s*$pAttachmentId\b[^\}]*\}#", $aux['data'] ) && !empty( $contentTypes[$aux['content_type_guid']] )) {
- // quick alias for code readability
- $type = &$contentTypes[$aux['content_type_guid']];
- $aux['content_description'] = tra( $type['content_description'] );
- $aux['creator'] = ( isset( $aux['creator_real_name'] ) ? $aux['creator_real_name'] : $aux['creator_user'] );
- $aux['real_name'] = ( isset( $aux['creator_real_name'] ) ? $aux['creator_real_name'] : $aux['creator_user'] );
- $aux['editor'] = ( isset( $aux['modifier_real_name'] ) ? $aux['modifier_real_name'] : $aux['modifier_user'] );
- $aux['user'] = $aux['creator_user'];
- $aux['user_id'] = $aux['creator_user_id'];
- // create *one* object for each object *type* to call virtual methods.
- if( empty( $type['content_object'] )) {
- include_once( $gBitSystem->mPackages[$type['handler_package']]['path'].$type['handler_file'] );
- $type['content_object'] = new $type['handler_class']();
- }
-
- if( !empty( $gBitSystem->mPackages[$type['handler_package']] )) {
- $aux['display_link'] = $type['content_object']->getDisplayLink( $aux['title'], $aux );
- $aux['title'] = $type['content_object']->getTitle( $aux );
- $aux['display_url'] = $type['content_object']->getDisplayUrl( $aux['content_id'], $aux );
- }
- $ret[] = $aux;
- }
- }
- }
- return $ret;
- }
}
?>
diff --git a/admin/schema_inc.php b/admin/schema_inc.php
index d26a323..2655475 100644
--- a/admin/schema_inc.php
+++ b/admin/schema_inc.php
@@ -27,7 +27,6 @@ $tables = array(
format_guid C(16) NOTNULL,
content_status_id I4 NOTNULL,
event_time I8 NOTNULL DEFAULT 0,
- primary_attachment_id I4,
version I4,
lang_code C(32),
title C(160),
@@ -89,7 +88,8 @@ $tables = array(
'liberty_content_links' => "
from_content_id I4,
to_content_id I4,
- to_title C(160)
+ to_title C(160),
+ pos F
CONSTRAINT ', CONSTRAINT `lib_content_links_from_ref` FOREIGN KEY (`from_content_id`) REFERENCES `".BIT_DB_PREFIX."liberty_content` (`content_id`)
, CONSTRAINT `lib_content_links_to_ref` FOREIGN KEY (`to_content_id`) REFERENCES `".BIT_DB_PREFIX."liberty_content` (`content_id`)'
",
@@ -123,22 +123,18 @@ $tables = array(
'liberty_attachments' => "
attachment_id I4 PRIMARY,
+ content_id I4 NOTNULL,
attachment_plugin_guid C(16) NOTNULL,
foreign_id I4 NOTNULL,
user_id I4 NOTNULL,
+ is_primary I4,
pos I4,
hits I4,
error_code I4,
caption C(250)
-",
-
-'liberty_attachments_map' => "
- attachment_id I4 PRIMARY,
- content_id I4 PRIMARY,
- item_position I4
- CONSTRAINT
- ', CONSTRAINT `liberty_attachments_map_con_ref` FOREIGN KEY (`content_id`) REFERENCES `".BIT_DB_PREFIX."liberty_content`( `content_id` )
- , CONSTRAINT `liberty_attachments_map_att_ref` FOREIGN KEY (`attachment_id`) REFERENCES `".BIT_DB_PREFIX."liberty_attachments`( `attachment_id` ) '
+ CONSTRAINT '
+ , CONSTRAINT `liberty_attachments_con_ref` FOREIGN KEY (`content_id`) REFERENCES `".BIT_DB_PREFIX."liberty_content`( `content_id` )
+ '
",
'liberty_files' => "
@@ -191,15 +187,6 @@ $tables = array(
, CONSTRAINT `liberty_content_perm_perm_ref` FOREIGN KEY (`perm_name`) REFERENCES `".BIT_DB_PREFIX."users_permissions` (`perm_name`)
*/
-'liberty_content_connection_map' => "
- from_content_id I4 PRIMARY,
- to_content_id I4 PRIMARY,
- item_position F
- CONSTRAINT '
- , CONSTRAINT `liberty_from_content_id_ref` FOREIGN KEY (`from_content_id`) REFERENCES `".BIT_DB_PREFIX."liberty_content` (`content_id`)
- , CONSTRAINT `liberty_to_content_id_ref` FOREIGN KEY (`to_content_id`) REFERENCES `".BIT_DB_PREFIX."liberty_content` (`content_id`)'
-",
-
'liberty_meta_types' => "
meta_type_guid C(16) PRIMARY,
meta_type_title C(250) NOTNULL
@@ -232,7 +219,6 @@ foreach( array_keys( $tables ) AS $tableName ) {
// Constraints which must be installed after table creation
$constraints = array(
- 'liberty_content' => array('liberty_content_attachment_ref' => 'FOREIGN KEY (`primary_attachment_id`) REFERENCES `'.BIT_DB_PREFIX.'liberty_attachments`( `attachment_id` )'),
'liberty_content_permissions' => array('liberty_content_perm_group_ref' => 'FOREIGN KEY (`group_id`) REFERENCES `'.BIT_DB_PREFIX.'users_groups` (`group_id`)'),
);
foreach( array_keys($constraints) AS $tableName ) {
@@ -257,7 +243,6 @@ $indices = array (
'comments_parent_idx' => array( 'table' => 'liberty_comments', 'cols' => 'parent_id', 'opts' => NULL ),
'attachments_hits_idx' => array( 'table' => 'liberty_attachments', 'cols' => 'hits', 'opts' => NULL ),
'attachments_user_id_idx' => array( 'table' => 'liberty_attachments', 'cols' => 'user_id', 'opts' => NULL ),
- 'attachments_content_id_idx' => array( 'table' => 'liberty_attachments_map', 'cols' => 'content_id', 'opts' => NULL ),
'st_co_foreign_guid_idx' => array( 'table' => 'liberty_attachments', 'cols' => 'foreign_id, attachment_plugin_guid', 'opts' => array( 'UNIQUE' ) ),
'structures_root_idx' => array( 'table' => 'liberty_structures', 'cols' => 'root_structure_id', 'opts' => NULL),
'structures_parent_idx' => array( 'table' => 'liberty_structures', 'cols' => 'parent_id', 'opts' => NULL),
diff --git a/templates/edit_primary_attachment_inc.tpl b/templates/edit_primary_attachment_inc.tpl
index 68bfc5c..f7d57e7 100644
--- a/templates/edit_primary_attachment_inc.tpl
+++ b/templates/edit_primary_attachment_inc.tpl
@@ -18,13 +18,6 @@
{/forminput}
</div>
- <div class="row">
- {formlabel label="Detach Attachment" for=""}
- {forminput}
- <input type="checkbox" name="detach_primary_attachment">{biticon ipackage=icons iname="edit-cut" iexplain="Detach"}
- {formhelp note="Remove the association with this attachment."}
- {/forminput}
- </div>
{/if}
{* $no_plugins is set by the including template *}
diff --git a/templates/edit_storage_list.tpl b/templates/edit_storage_list.tpl
index 357d808..449cc39 100644
--- a/templates/edit_storage_list.tpl
+++ b/templates/edit_storage_list.tpl
@@ -26,17 +26,6 @@
{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() || $gBitUser->hasPermission( 'p_liberty_detach_attachment' ) || $storage.user_id == $gBitUser->mUserId) && !empty($gContent->mContentId)}
- {if $attachmentBrowser}
- {if in_array($gContent->mContentId, $storage.attached_to)}
- <a href="javascript:ajax_updater('attbrowser', '{$attachmentActionBaseURL}', 'content_id={$gContent->mContentId}&amp;detachAttachment={$attachmentId}')">{biticon ipackage=icons iname="edit-cut" iexplain="detach"}</a>
- {/if}
- {elseif $libertyUploader or $gBitSystem->getConfig('liberty_attachment_style') == 'ajax'}
- <a href="javascript:ajax_updater('edit_storage_list_div', '{$attachmentActionBaseURL}', 'content_id={$gContent->mContentId}&amp;detachAttachment={$attachmentId}');">{biticon ipackage=icons iname="edit-cut" iexplain="detach"}</a>
- {else}
- <a href="{$attachmentActionBaseURL}&amp;content_id={$gContent->mContentId}&amp;detachAttachment={$attachmentId}">{biticon ipackage=icons iname="edit-cut" iexplain="detach"}</a>
- {/if}
- {/if}
{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>