diff options
| author | bitweaver.org <bitweaver@users.sourceforge.net> | 2005-06-19 04:55:51 +0000 |
|---|---|---|
| committer | bitweaver.org <bitweaver@users.sourceforge.net> | 2005-06-19 04:55:51 +0000 |
| commit | 9263d2df0226a118f4add4664d746a266ce5aa78 (patch) | |
| tree | 7bc560ee5a4111a80f7b4ecd23afe53278cfd352 /plugins/storage.bitfile.php | |
| download | liberty-9263d2df0226a118f4add4664d746a266ce5aa78.tar.gz liberty-9263d2df0226a118f4add4664d746a266ce5aa78.tar.bz2 liberty-9263d2df0226a118f4add4664d746a266ce5aa78.zip | |
IMPORT TikiPro CLYDE FINAL
Diffstat (limited to 'plugins/storage.bitfile.php')
| -rw-r--r-- | plugins/storage.bitfile.php | 114 |
1 files changed, 114 insertions, 0 deletions
diff --git a/plugins/storage.bitfile.php b/plugins/storage.bitfile.php new file mode 100644 index 0000000..97b9a19 --- /dev/null +++ b/plugins/storage.bitfile.php @@ -0,0 +1,114 @@ +<?php +global $gLibertySystem; + +define( 'PLUGIN_GUID_BIT_FILES', 'bitfile' ); + +$pluginParams = array ( + 'store_function' => 'bit_files_store', + 'verify_function' => 'bit_files_verify', + 'load_function' => 'bit_files_load', + 'expunge_function' => 'bit_files_expunge', + 'description' => 'Upload File To Server', + 'plugin_type' => STORAGE_PLUGIN, + 'edit_label' => 'Upload File', + 'edit_field' => '<input type="file" name="upload" size="40" />', + 'edit_help' => 'This file will be uploaded to your personal storage area.<br />After selecting the file you want to upload, please return to the edit area and click the save button.' +); + +//$gLibertySystem->registerPlugin( STORAGE_TYPE_BIT_FILES, $pluginParams ); +$gLibertySystem->registerPlugin( PLUGIN_GUID_BIT_FILES, $pluginParams ); + + +function bit_files_verify( &$pStoreRow ) { + $pStoreRow['plugin_guid'] = PLUGIN_GUID_BIT_FILES; + $pStoreRow['foreign_id'] = NULL; + $pStoreRow['dest_base_name'] = substr( $pStoreRow['upload']['name'], 0, strrpos( $pStoreRow['upload']['name'], '.' ) ); + $pStoreRow['source_file'] = $pStoreRow['upload']['tmp_name']; + + return( TRUE ); +} + +function bit_files_store( &$pStoreRow ) { + global $gBitSystem, $gBitUser; + $ret = NULL; + $pref = $gBitSystem->getPreference('centralized_upload_dir'); + if( isset( $pref ) ) { + if( !empty( $pStoreRow['foreign_id'] ) ) { + //$sql = "UPDATE tiki_attachment SET `binary_id`=NULL, `storage_path`=? WHERE `user_id`=? AND storage_id=?"; + $sql = "UPDATE `".BIT_DB_PREFIX."tiki_files SET `storage_path`=?, `mime_type`=?, `size`=? WHERE `file_id` = ?"; + $gBitSystem->query( $sql, array( $pStoreRow['dest_file_path'], $pStoreRow['type'], $pStoreRow['size'], $pStoreRow['foreign_id'] ) ); + } else { + $pStoreRow['file_id'] = $gBitSystem->GenID( 'bit_files_file_id_seq' ); + $sql = "INSERT INTO `".BIT_DB_PREFIX."tiki_files` ( `storage_path`, `file_id`, `mime_type`, `size`, `user_id` ) VALUES ( ?, ?, ?, ?, ? )"; + $userId = !empty( $pStoreRow['upload']['user_id'] ) ? $pStoreRow['upload']['user_id'] : $gBitUser->mUserId; + $gBitSystem->query($sql, array( $pStoreRow['upload']['dest_path'].$pStoreRow['upload']['name'], $pStoreRow['file_id'], $pStoreRow['upload']['type'], $pStoreRow['upload']['size'], $userId ) ); + } + $sql = "UPDATE `".BIT_DB_PREFIX."tiki_attachments` SET `foreign_id`=? WHERE `attachment_id` = ?"; + $gBitSystem->query( $sql, array( $pStoreRow['file_id'], $pStoreRow['attachment_id'] ) ); + } + return $ret; +} + +function bit_files_load( $pRow ) { +// this fuction broken, will fix soon - spiderr +// I think its fixed now - no promises though! - drewslater + global $gBitSystem, $gLibertySystem; + $ret = NULL; + if( !empty( $pRow['foreign_id'] ) && is_numeric( $pRow['foreign_id'] )) { + $query = "SELECT * + FROM `".BIT_DB_PREFIX."tiki_attachments` ta INNER JOIN `".BIT_DB_PREFIX."tiki_files` tf ON (tf.`file_id` = ta.`foreign_id`) + WHERE ta.`foreign_id` = ? AND ta.`content_id` = ?"; + if( $rs = $gBitSystem->query($query, array( $pRow['foreign_id'], $pRow['content_id'] )) ) { + $ret = $rs->fields; + if (preg_match ( '/image\//', $ret['mime_type'] )) { + $ret['thumbnail_url']['avatar'] = BIT_ROOT_URL.dirname( $ret['storage_path'] ).'/avatar.jpg'; + $ret['thumbnail_url']['small'] = BIT_ROOT_URL.dirname( $ret['storage_path'] ).'/small.jpg'; + $ret['thumbnail_url']['medium'] = BIT_ROOT_URL.dirname( $ret['storage_path'] ).'/medium.jpg'; + $ret['thumbnail_url']['large'] = BIT_ROOT_URL.dirname( $ret['storage_path'] ).'/large.jpg'; + } else { + $mime_thumbnail = $gLibertySystem->getMimeThumbnailURL($ret['mime_type']); + $ret['thumbnail_url']['avatar'] = $mime_thumbnail; + $ret['thumbnail_url']['small'] = $mime_thumbnail; + $ret['thumbnail_url']['medium'] = $mime_thumbnail; + $ret['thumbnail_url']['large'] = $mime_thumbnail; + } + $ret['filename'] = substr( $ret['storage_path'], strrpos($ret['storage_path'], '/')+1); + $ret['source_url'] = BIT_ROOT_URL.str_replace( '+', '%20', str_replace( '%2F', '/', urlencode( $ret['storage_path'] ) ) ); + $ret['wiki_plugin_link'] = "{attachment id=".$ret['attachment_id']."}"; + } + } + return( $ret ); +} + +function bit_files_expunge( $pStorageId ) { + global $gBitUser, $gBitSystem; + $ret = FALSE; + + if (is_numeric($pStorageId)) { + $sql = "SELECT * FROM `".BIT_DB_PREFIX."tiki_attachments` WHERE `attachment_id` = ?"; + $rs = $gBitSystem->query($sql, array($pStorageId)); + $row = &$rs->fields; + if ($row) { + $sql = "SELECT * FROM `".BIT_DB_PREFIX."tiki_files` WHERE `file_id` = ?"; + $fileRs = $gBitSystem->query($sql, array($row['foreign_id']) ); + $fileRow = &$fileRs->fields; + if ($fileRow) { + $absolutePath = BIT_ROOT_PATH.'/'.$fileRow['storage_path']; + + if ($gBitUser->isAdmin() || $gBitUser->mUserId == $row['user_id']) { + if (file_exists($absolutePath)) { + unlink($absolutePath); + } + $query = "DELETE FROM `".BIT_DB_PREFIX."tiki_attachments` WHERE `attachment_id` = ?"; + $gBitSystem->query($query, array($pStorageId)); + $query = "DELETE FROM `".BIT_DB_PREFIX."tiki_files` WHERE `file_id` = ?"; + $gBitSystem->query($query, array($row['foreign_id']) ); + $ret = TRUE; + } + } + } + } + return $ret; +} + +?> |
