diff options
| -rw-r--r-- | LibertyContent.php | 8 | ||||
| -rw-r--r-- | LibertyMime.php | 84 | ||||
| -rw-r--r-- | admin/schema_inc.php | 2 | ||||
| -rw-r--r-- | admin/upgrades/3.0.0.php | 25 | ||||
| -rw-r--r-- | liberty_lib.php | 54 | ||||
| -rw-r--r-- | plugins/data.attachment.php | 201 | ||||
| -rw-r--r-- | plugins/mime.default.php | 38 | ||||
| -rw-r--r-- | plugins/storage.bitfile.php | 41 |
8 files changed, 193 insertions, 260 deletions
diff --git a/LibertyContent.php b/LibertyContent.php index b2a52e3..dc026f5 100644 --- a/LibertyContent.php +++ b/LibertyContent.php @@ -914,13 +914,13 @@ class LibertyContent extends LibertyBase { LEFT OUTER JOIN `".BIT_DB_PREFIX."users_users` uue ON( uue.`user_id` = lc.`modifier_user_id` )"; } if( empty( $pJoins ) || in_array( 'avatar', $pJoins )) { - $pQueryHash['select']['sql'][] = "ulf.`storage_path` AS `avatar`, ulf.`storage_path` AS `avatar_attachment_path`"; + $pQueryHash['select']['sql'][] = "ulf.`file_name` AS `avatar_file_name`, ulf.`mime_type` AS `avatar_mime_type`, ula.`attachment_id` AS `avatar_attachment_id`"; $pQueryHash['join']['sql'][] = " LEFT OUTER JOIN `".BIT_DB_PREFIX."liberty_attachments` ula ON( uu.`user_id` = ula.`user_id` AND ula.`attachment_id` = uu.`avatar_attachment_id` ) LEFT OUTER JOIN `".BIT_DB_PREFIX."liberty_files` ulf ON( ulf.`file_id` = ula.`foreign_id` )"; } if( empty( $pJoins ) || in_array( 'primary', $pJoins )) { - $pQueryHash['select']['sql'][] = "pla.`attachment_id` AS `primary_attachment_id`, plf.`storage_path` AS `primary_attachment_path`"; + $pQueryHash['select']['sql'][] = "pla.`attachment_id` AS `primary_attachment_id`, plf.`file_name` AS `primary_file_name`, plf.`mime_type` AS `primary_mime_type`"; $pQueryHash['join']['sql'][] = " LEFT OUTER JOIN `".BIT_DB_PREFIX."liberty_attachments` pla ON( pla.`content_id` = lc.`content_id` AND pla.`is_primary` = 'y' ) LEFT OUTER JOIN `".BIT_DB_PREFIX."liberty_files` plf ON( plf.`file_id` = pla.`foreign_id` )"; @@ -2318,7 +2318,7 @@ class LibertyContent extends LibertyBase { // if we want the primary attachment for each object if( $gBitSystem->isFeatureActive( 'liberty_display_primary_attach' ) ){ - $selectSql .= ', lfp.storage_path AS `image_attachment_path`'; + $selectSql .= ', lfp.`file_name`, lfp.`mime_type`, la.`attachment_id`, '; $joinSql .= "LEFT OUTER JOIN `".BIT_DB_PREFIX."liberty_attachments` la ON( la.`content_id` = lc.`content_id` AND la.`is_primary` = 'y' ) LEFT OUTER JOIN `".BIT_DB_PREFIX."liberty_files` lfp ON( lfp.`file_id` = la.`foreign_id` )"; } @@ -2559,7 +2559,7 @@ class LibertyContent extends LibertyBase { * This ultimately might need to be more sophisticated to deal with different mime types. **/ if( $gBitSystem->isFeatureActive( 'liberty_display_primary_attach' ) ){ - $aux['thumbnail_urls'] = liberty_fetch_thumbnails( array( "storage_path" => $aux['image_attachment_path'] ) ); + $aux['thumbnail_urls'] = liberty_fetch_thumbnails( $aux ); } if( isset( $aux['hash_key'] ) ) { diff --git a/LibertyMime.php b/LibertyMime.php index 8a015bc..43f2b87 100644 --- a/LibertyMime.php +++ b/LibertyMime.php @@ -371,6 +371,23 @@ class LibertyMime extends LibertyContent { } // {{{ =================== Storage Directory Methods ==================== + function getSourceUrl( $pParamHash=array() ) { + $ret = NULL; + if( $fileName = $this->getParameter( $pParamHash, 'file_name', $this->getField( 'file_name' ) ) ) { + $ret = $this->getStorageUrl( $pParamHash ).basename( $fileName ); + } + return $ret; + } + + function getSourceFile( $pParamHash=array() ) { + $ret = NULL; + if( $fileName = $this->getParameter( $pParamHash, 'file_name', $this->getField( 'file_name' ) ) ) { + $ret = $this->getStoragePath( $pParamHash ).basename( $fileName ); + } + return $ret; + } + + /** * getStoragePath - get path to store files for the feature site_upload_dir. It creates a calculable hierarchy of directories * @@ -381,10 +398,10 @@ class LibertyMime extends LibertyContent { * @param $pRootDir override BIT_ROOT_DIR with a custom absolute path - useful for areas where no we access should be allowed * @return string full path on local filsystem to store files. */ - function getStoragePath( $pSubDir = NULL, $pUserId = NULL, $pPackage = ACTIVE_PACKAGE, $pPermissions = 0755, $pRootDir = NULL ) { + function getStoragePath( $pParamHash ) { // $pSubDir = NULL, $pUserId = NULL, $pPackage = ACTIVE_PACKAGE, $pPermissions = 0755, $pRootDir = NULL ) { $ret = null; - - if( $branch = liberty_mime_get_storage_branch( $pSubDir, $pUserId, $pPackage, $pPermissions, $pRootDir, empty($pRootDir) ) ) { + + if( $branch = liberty_mime_get_storage_branch( $pParamHash ) ) { $ret = ( !empty( $pRootDir ) ? $pRootDir : STORAGE_PKG_PATH ).$branch; mkdir_p($ret); } @@ -392,8 +409,22 @@ class LibertyMime extends LibertyContent { } - function getStorageUrl( $pSubDir = NULL, $pUserId = NULL, $pPackage = ACTIVE_PACKAGE, $pPermissions = 0755 ) { - return STORAGE_PKG_URL.liberty_mime_get_storage_branch( $pSubDir, $pUserId, $pPackage, $pPermissions ); + function getStorageUrl( $pParamHash ) { // $pSubDir = NULL, $pUserId = NULL, $pPackage = ACTIVE_PACKAGE, $pPermissions = 0755 ) { + return STORAGE_PKG_URL.liberty_mime_get_storage_branch( $pParamHash ); + } + + /** + * getStorageBranch - get url to store files for the feature site_upload_dir. It creates a calculable hierarchy of directories + * + * @access public + * @author Christian Fowler<spider@steelsun.com> + * @param $pSubDir any desired directory below the StoragePath. this will be created if it doesn't exist + * @param $pUserId indicates the 'users/.../<user_id>' branch or use the 'common' branch if null + * @param $pRootDir **deprecated, unused, will be removed in future relase**. + * @return string full path on local filsystem to store files. + */ + function getStorageBranch( $pParamHash ) { // $pSubDir = NULL, $pUserId = NULL, $pPackage = ACTIVE_PACKAGE, $pPermissions = 0755, $pCreateDir = true ) { + return liberty_mime_get_storage_branch( $pParamHash ); } /** @@ -437,19 +468,6 @@ class LibertyMime extends LibertyContent { } } - /** - * getStorageBranch - get url to store files for the feature site_upload_dir. It creates a calculable hierarchy of directories - * - * @access public - * @author Christian Fowler<spider@steelsun.com> - * @param $pSubDir any desired directory below the StoragePath. this will be created if it doesn't exist - * @param $pUserId indicates the 'users/.../<user_id>' branch or use the 'common' branch if null - * @param $pRootDir **deprecated, unused, will be removed in future relase**. - * @return string full path on local filsystem to store files. - */ - function getStorageBranch( $pSubDir = NULL, $pUserId = NULL, $pPackage = ACTIVE_PACKAGE, $pPermissions = 0755, $pCreateDir = true ) { - return liberty_mime_get_storage_branch( $pSubDir, $pUserId, $pPackage, $pPermissions, $pCreateDir ); - } // }}} @@ -1085,13 +1103,13 @@ if( !function_exists( 'liberty_mime_get_storage_sub_dir_name' )) { * @return string full path on local filsystem to store files. */ if( !function_exists( 'liberty_mime_get_storage_branch' )) { - function liberty_mime_get_storage_branch( $pSubDir = NULL, $pUserId = NULL, $pPackage = ACTIVE_PACKAGE, $pPermissions = 0755, $pCreateDir = true ) { + function liberty_mime_get_storage_branch( $pParamHash ) { // $pSubDir = NULL, $pUserId = NULL, $pPackage = ACTIVE_PACKAGE, $pPermissions = 0755, $pCreateDir = true ) { // *PRIVATE FUNCTION. GO AWAY! DO NOT CALL DIRECTLY!!! global $gBitSystem; $pathParts = array(); - if( !$pUserId ) { + if( !$pUserId = BitBase::getParameter( $pParamHash, 'user_id' ) ) { $pathParts[] = 'common'; } else { $pathParts[] = 'users'; @@ -1099,11 +1117,11 @@ if( !function_exists( 'liberty_mime_get_storage_branch' )) { $pathParts[] = $pUserId; } - if( $pPackage ) { + if( $pPackage = BitBase::getParameter( $pParamHash, 'package' ) ) { $pathParts[] = $pPackage; } // In case $pSubDir is multiple levels deep we'll need to mkdir each directory if they don't exist - if(!empty($pSubDir)){ + if( $pSubDir = BitBase::getParameter( $pParamHash, 'sub_dir' ) ){ $pSubDirParts = preg_split('#/#',$pSubDir); foreach ($pSubDirParts as $subDir) { $pathParts[] = $subDir; @@ -1111,7 +1129,7 @@ if( !function_exists( 'liberty_mime_get_storage_branch' )) { } $fullPath = implode( $pathParts, '/' ).'/'; - if($pCreateDir){ + if( BitBase::getParameter( $pParamHash, 'create_dir', TRUE ) ){ mkdir_p( $fullPath ); } @@ -1120,14 +1138,26 @@ if( !function_exists( 'liberty_mime_get_storage_branch' )) { } if( !function_exists( 'liberty_mime_get_storage_url' )) { - function liberty_mime_get_storage_url( $pSubDir = NULL, $pUserId = NULL, $pPackage = ACTIVE_PACKAGE, $pPermissions = 0755, $pCreateDir = true ) { - return STORAGE_PKG_URL.liberty_mime_get_storage_branch( $pSubDir, $pUserId, $pPackage, $pPermissions, $pCreateDir ); + function liberty_mime_get_storage_url( $pParamHash ) { // $pSubDir = NULL, $pUserId = NULL, $pPackage = ACTIVE_PACKAGE, $pPermissions = 0755, $pCreateDir = true ) { + return STORAGE_PKG_URL.liberty_mime_get_storage_branch( $pParamHash ); } } if( !function_exists( 'liberty_mime_get_storage_path' )) { - function liberty_mime_get_storage_path( $pSubDir = NULL, $pUserId = NULL, $pPackage = ACTIVE_PACKAGE, $pPermissions = 0755, $pCreateDir = true ) { - return STORAGE_PKG_PATH.liberty_mime_get_storage_branch( $pSubDir, $pUserId, $pPackage, $pPermissions, $pCreateDir ); + function liberty_mime_get_storage_path( $pParamHash ) { // $pSubDir = NULL, $pUserId = NULL, $pPackage = ACTIVE_PACKAGE, $pPermissions = 0755, $pCreateDir = true ) { + return STORAGE_PKG_PATH.liberty_mime_get_storage_branch( $pParamHash ); + } +} + +if( !function_exists( 'liberty_mime_get_source_file' )) { + function liberty_mime_get_source_file( $pParamHash ) { + if( empty( $pParamHash['package'] ) ) { + $pParamHash['package'] = liberty_mime_get_storage_sub_dir_name( array( 'type' => BitBase::getParameter( $pParamHash, 'mime_type' ), 'name' => BitBase::getParameter( $pParamHash, 'file_name' ) ) ); + } + if( empty( $pParamHash['sub_dir'] ) ) { + $pParamHash['sub_dir'] = BitBase::getParameter( $pParamHash, 'attachment_id' ); + } + return STORAGE_PKG_PATH.liberty_mime_get_storage_branch( $pParamHash ).basename( BitBase::getParameter( $pParamHash, 'file_name' ) ); } } diff --git a/admin/schema_inc.php b/admin/schema_inc.php index 71dc93e..b413794 100644 --- a/admin/schema_inc.php +++ b/admin/schema_inc.php @@ -155,7 +155,7 @@ $tables = array( 'liberty_files' => " file_id I4 PRIMARY, user_id I4 NOTNULL, - storage_path C(250), + file_name C(250), file_size I4, mime_type C(64) ", diff --git a/admin/upgrades/3.0.0.php b/admin/upgrades/3.0.0.php new file mode 100644 index 0000000..076da8c --- /dev/null +++ b/admin/upgrades/3.0.0.php @@ -0,0 +1,25 @@ +<?php +/** + * @version $Header$ + */ +global $gBitInstaller; + +$infoHash = array( + 'package' => LIBERTY_PKG_NAME, + 'version' => str_replace( '.php', '', basename( __FILE__ )), + 'description' => "Update content type guid table to have singular and plural names, deprecate content_description", + 'post_upgrade' => NULL, +); + +$gBitInstaller->registerPackageUpgrade( $infoHash, array( + +array( 'DATADICT' => array( + // rename original column + array( 'RENAMECOLUMN' => array( + 'liberty_files' => array( + '`storage_path`' => "`file_name` VARCHAR(250)", + ), + )), +)), + +)); diff --git a/liberty_lib.php b/liberty_lib.php index 3e9f93b..08b3b81 100644 --- a/liberty_lib.php +++ b/liberty_lib.php @@ -644,12 +644,12 @@ function liberty_process_image( &$pFileHash, $pMoveFile = TRUE ) { function liberty_clear_thumbnails( &$pFileHash ) { if( !empty( $pFileHash['dest_path'] )) { $thumbHash = array( - 'storage_path' => $pFileHash['dest_path'], + 'source_file' => $pFileHash['dest_path'], 'mime_image' => FALSE, ); // get thumbnails we want to remove - if( $thumbs = liberty_fetch_thumbnails( $thumbHash, NULL, NULL, TRUE, FALSE )) { + if( $thumbs = liberty_fetch_thumbnails( $thumbHash )) { foreach( $thumbs as $thumb ) { $thumb = BIT_ROOT_PATH.$thumb; if( is_writable( $thumb )) { @@ -726,7 +726,6 @@ function liberty_generate_thumbnails( &$pFileHash ) { } $initialDestPath = $pFileHash['dest_path']; -vd( $pFileHash ); foreach( $pFileHash['thumbnail_sizes'] as $thumbSize ) { if( isset( $gThumbSizes[$thumbSize] )) { $pFileHash['dest_base_name'] = $thumbSize; @@ -773,30 +772,16 @@ vd( $pFileHash ); /** * fetch all available thumbnails for a given item. if no thumbnails are present, get thumbnailing image or the appropriate mime type icon * - * @param array $pParamHash Hash of all settings used to fetch thumbnails - * @param string $pParamHash['storage_path'] Relative path to file we want to get thumbnails for (needs to include file name for mime icons) - * @param string $pParamHash['default_image'] URL to an alternative fallback image such as a background thumbnailer image - * @param array $pParamHash['thumbnail_sizes'] array of images to search for in the pFilePath - * @param boolean $pParamHash['mime_image specify if you want to fetch an alternative image or not (default TRUE) + * @param array $pParamHash Hash of all settings used to fetch thumbnails, including source_file, default_image, thumbnail_sizes, and mime_image * @access public * @return array of available thumbnails or mime icons * TODO: individual options are only for legacy reasons - remove options and deprecated() soon - xing - Monday Jun 23, 2008 22:36:53 CEST */ -function liberty_fetch_thumbnails( $pParamHash, $pAltImageUrl = NULL, $pThumbSizes = NULL, $pMimeImage = TRUE, $pReturnUri = TRUE ) { +function liberty_fetch_thumbnails( $pParamHash ) { global $gBitSystem, $gThumbSizes; $ret = array(); - if( !empty( $pParamHash['storage_path'] )) { - if( !is_array( $pParamHash )) { - $pParamHash = array( - 'storage_path' => $pParamHash, - 'default_image' => $pAltImageUrl, - 'thumbnail_sizes' => $pThumbSizes, - 'mime_image' => $pMimeImage, - ); - deprecated( "Please use an array of parameters to fetch thumbnails.\nUse something like this:\n\$thumbHash = ".var_export( $pParamHash, 1 )); - } - + if( !empty( $pParamHash['source_file'] )) { if( empty( $pParamHash['thumbnail_sizes'] )) { $pParamHash['thumbnail_sizes'] = array_keys( $gThumbSizes ); } @@ -806,7 +791,7 @@ function liberty_fetch_thumbnails( $pParamHash, $pAltImageUrl = NULL, $pThumbSiz $exts = array_unique( array( $gBitSystem->getConfig( 'liberty_thumbnail_format', 'jpg' ), 'jpg', 'png', 'gif', 'x-jpeg' )); // short hand - $path = &$pParamHash['storage_path']; + $path = &$pParamHash['source_file']; // $path might already be the absolute path or it might already contain BIT_ROOT_URL if( !( $path = preg_replace( "!^".preg_quote( STORAGE_PKG_PATH, "!" )."!", "", $path ))) { @@ -819,10 +804,9 @@ function liberty_fetch_thumbnails( $pParamHash, $pAltImageUrl = NULL, $pThumbSiz foreach( $pParamHash['thumbnail_sizes'] as $size ) { foreach( $exts as $ext ) { $image = $size.'.'.$ext; - if( is_readable( STORAGE_PKG_PATH.$dir.'thumbs/'.$image )) { - $ret[$size] = ( $pReturnUri ? storage_path_to_url( $dir.'thumbs/'.$image ) : STORAGE_PKG_URL.$dir.'thumbs/'.$image ); - } elseif( is_readable( STORAGE_PKG_PATH.$dir.$image )) { - $ret[$size] = ( $pReturnUri ? storage_path_to_url( $dir.$image ) : STORAGE_PKG_URL.$dir.'thumbs/'.$image ); + $thumbDir = is_dir( STORAGE_PKG_PATH.$dir.'thumbs/' ) ? $dir.'thumbs/' : $dir; + if( is_readable( STORAGE_PKG_PATH.$thumbDir.$image )) { + $ret[$size] = STORAGE_PKG_URL.$thumbDir.$image; } } // fetch mime image unless we set this to FALSE @@ -844,27 +828,13 @@ function liberty_fetch_thumbnails( $pParamHash, $pAltImageUrl = NULL, $pThumbSiz /** * fetch a single available thumbnail for a given item. if no thumbnail is present, return NULL * - * @param array $pParamHash Hash of all settings used to fetch thumbnails - * @param string $pParamHash['size'] Size of the desired thumbnail (needs to be key value of $gThumbSizes) (default 'small') - * @param string $pParamHash['storage_path'] Relative path to file we want to get thumbnails for (needs to include file name for mime icons) - * @param string $pParamHash['default_image'] URL to an alternative fallback image such as a background thumbnailer image - * @param boolean $pParamHash['mime_image specify if you want to fetch an alternative image or not (default TRUE) + * @param array $pParamHash Hash of all settings used to fetch thumbnails including: size, source_file, default_image, and mime_image * @access public * @return string url * TODO: individual options are only for legacy reasons - remove options and deprecated() soon - xing - Monday Jun 23, 2008 22:36:53 CEST */ -function liberty_fetch_thumbnail_url( $pParamHash, $pThumbSize = 'small', $pAltImageUrl = NULL, $pMimeImage = FALSE ) { - if( !is_array( $pParamHash )) { - $pParamHash = array( - 'storage_path' => $pParamHash, - 'size' => $pThumbSize, - 'default_image' => $pAltImageUrl, - 'mime_image' => $pMimeImage, - ); - deprecated( "Please use an array of parameters to fetch the thumbnail.\nUse something like this:\n\$thumbHash = ".var_export( $pParamHash, 1 )); - } - - if( !empty( $pParamHash['storage_path'] )) { +function liberty_fetch_thumbnail_url( $pParamHash ) { + if( !empty( $pParamHash['source_file'] )) { if( empty( $pParamHash['size'] )) { $pParamHash['size'] = 'small'; } diff --git a/plugins/data.attachment.php b/plugins/data.attachment.php index caff160..d4ceb0d 100644 --- a/plugins/data.attachment.php +++ b/plugins/data.attachment.php @@ -124,163 +124,76 @@ function data_attachment( $pData, $pParams, $pCommonObject, $pParseHash ) { $ret = tra( "The attachment id given is not valid." ); return $ret; } - // we will do slightly different stuff if this is using a mime plugin - if( !empty( $att['is_mime'] )) { - global $gBitSmarty, $gLibertySystem, $gContent; - // convert parameters into display properties - $wrapper = liberty_plugins_wrapper_style( $pParams ); - // work out custom display_url if there is one - if( @BitBase::verifyId( $pParams['page_id'] )) { - // link to page by page_id - // avoid endless loops - require_once( WIKI_PKG_PATH.'BitPage.php'); - $wp = new BitPage( $pParams['page_id'] ); - if( $wp->load() ) { - $wrapper['display_url'] = $wp->getDisplayUrl(); - } - } elseif( @BitBase::verifyId( $pParams['content_id'] )) { - // link to any content by content_id - if( $obj = LibertyBase::getLibertyObject( $pParams['content_id'] )) { - $wrapper['display_url'] = $obj->getDisplayUrl(); - } - } elseif( !empty( $pParams['page_name'] )) { - // link to page by page_name - require_once( WIKI_PKG_PATH.'BitPage.php'); - $wp = new BitPage(); - $wrapper['display_url'] = $wp->getDisplayUrl( $pParams['page_name'] ); - } elseif( !empty( $pParams['link'] ) && $pParams['link'] == 'false' ) { - // no link - } elseif( !empty( $pParams['link'] )) { - // Allow the use of icon, avatar, small, medium and large to link to certain size of image directly - if( !empty( $att['thumnail_url'][$pParams['link']] )) { - $pParams['link'] = $att['thumnail_url'][$pParams['link']]; + global $gBitSmarty, $gLibertySystem, $gContent; + // convert parameters into display properties + $wrapper = liberty_plugins_wrapper_style( $pParams ); + // work out custom display_url if there is one + if( @BitBase::verifyId( $pParams['page_id'] )) { + // link to page by page_id + // avoid endless loops - // Allow the use of 'original' to link to original file directly - } elseif( $pParams['link'] == 'original' && !empty( $att['source_url'] )) { - $pParams['link'] = $att['source_url']; - - // Allow the use of 'download' to link to download link. this will allow us to count downloads - } elseif( $pParams['link'] == 'download' && !empty( $att['download_url'] )) { - $pParams['link'] = $att['download_url']; - - // Adjust class name if we are leaving this server - } elseif( !strstr( $pParams['link'], $_SERVER["SERVER_NAME"] ) && strstr( $pParams['link'], '//' )) { - $wrapper['href_class'] = 'class="external"'; - } - $wrapper['display_url'] = $pParams['link']; - } else { - $wrapper['display_url'] = $att['display_url']; + require_once( WIKI_PKG_PATH.'BitPage.php'); + $wp = new BitPage( $pParams['page_id'] ); + if( $wp->load() ) { + $wrapper['display_url'] = $wp->getDisplayUrl(); } - - if( !empty( $wrapper['description'] )) { - $parseHash['content_id'] = $pParseHash['content_id']; - $parseHash['user_id'] = $pParseHash['user_id']; - $parseHash['no_cache'] = TRUE; - $parseHash['data'] = $wrapper['description']; - $wrapper['description_parsed'] = $pCommonObject->parseData( $parseHash ); + } elseif( @BitBase::verifyId( $pParams['content_id'] )) { + // link to any content by content_id + if( $obj = LibertyBase::getLibertyObject( $pParams['content_id'] )) { + $wrapper['display_url'] = $obj->getDisplayUrl(); } + } elseif( !empty( $pParams['page_name'] )) { + // link to page by page_name + require_once( WIKI_PKG_PATH.'BitPage.php'); + $wp = new BitPage(); + $wrapper['display_url'] = $wp->getDisplayUrl( $pParams['page_name'] ); + } elseif( !empty( $pParams['link'] ) && $pParams['link'] == 'false' ) { + // no link + } elseif( !empty( $pParams['link'] )) { + // Allow the use of icon, avatar, small, medium and large to link to certain size of image directly + if( !empty( $att['thumnail_url'][$pParams['link']] )) { + $pParams['link'] = $att['thumnail_url'][$pParams['link']]; - // pass stuff to the template - $gBitSmarty->assign( 'attachment', $att ); - $gBitSmarty->assign( 'wrapper', $wrapper ); - $gBitSmarty->assign( 'thumbsize', (( !empty( $pParams['size'] ) && ( $pParams['size'] == 'original' || !empty( $att['thumbnail_url'][$pParams['size']] ))) ? $pParams['size'] : 'medium' )); - - //Carry only these attributes to the image tags - $width = !empty( $pParams['width'] ) ? $pParams['width'] : ''; - $gBitSmarty->assign( 'width', $width ); + // Allow the use of 'original' to link to original file directly + } elseif( $pParams['link'] == 'original' && !empty( $att['source_url'] )) { + $pParams['link'] = $att['source_url']; - $height = !empty( $pParams['height'] ) ? $pParams['height'] : ''; - $gBitSmarty->assign( 'height', $height ); + // Allow the use of 'download' to link to download link. this will allow us to count downloads + } elseif( $pParams['link'] == 'download' && !empty( $att['download_url'] )) { + $pParams['link'] = $att['download_url']; - $mimehandler = (( !empty( $wrapper['output'] ) && $wrapper['output'] == 'thumbnail' ) ? LIBERTY_DEFAULT_MIME_HANDLER : $att['attachment_plugin_guid'] ); - $ret = $gBitSmarty->fetch( $gLibertySystem->getMimeTemplate( 'attachment', $mimehandler )); - } else { - // TODO: legacy code - should be faded out if possible - - - // insert source url if we need the original file - if( !empty( $pParams['size'] ) && $pParams['size'] == 'original' ) { - $thumburl = $att['source_url']; - } elseif( !empty( $att['thumbnail_url'] )) { - $thumburl = ( !empty( $pParams['size'] ) && !empty( $att['thumbnail_url'][$pParams['size']] ) ? $att['thumbnail_url'][$pParams['size']] : $att['thumbnail_url']['medium'] ); + // Adjust class name if we are leaving this server + } elseif( !strstr( $pParams['link'], $_SERVER["SERVER_NAME"] ) && strstr( $pParams['link'], '//' )) { + $wrapper['href_class'] = 'class="external"'; } + $wrapper['display_url'] = $pParams['link']; + } else { + $wrapper['display_url'] = $att['display_url']; + } - // Figure out alt attribute. - if( empty( $wrapper['alt'] )) { - if ( empty( $wrapper['description'] )) { - $alt = tra( 'Image' ); - } else { - $alt = $wrapper['description']; - } - } else { - $alt = $wrapper['alt']; - } - // check if we have a valid thumbnail - if( !empty( $thumburl ) ) { - $wrapper = liberty_plugins_wrapper_style( $pParams ); - // set up image first - $ret = '<img'. - ' alt="'. $alt .'"'. - ' title="'. ( empty($wrapper['description']) ? $alt : $wrapper['description'] ). '"'. - ' src="' .$thumburl.'"'. - ' />'; - - $ret .= ( !empty( $att['file_details'] ) ? '<br />'.$att['file_details'] : '' ); - - // link to page by page_id - if( @BitBase::verifyId( $pParams['page_id'] ) ) { - require_once( WIKI_PKG_PATH.'BitPage.php'); - $wp = new BitPage( $pParams['page_id'] ); - if( $wp->load() ) { - $pParams['link'] = $wp->getDisplayUrl(); - } - // link to any content by content_id - } elseif( isset( $pParams['content_id'] ) && is_numeric( $pParams['content_id'] ) ) { - if( $obj = LibertyBase::getLibertyObject( $pParams['content_id'] ) ) { - $pParams['link'] = $obj->getDisplayUrl(); - } - // link to page by page_name - } elseif( isset( $pParams['page_name'] ) ) { - require_once( WIKI_PKG_PATH.'BitPage.php'); - $wp = new BitPage(); - $pParams['link'] = $wp->getDisplayUrl( $pParams['page_name'] ); - } + if( !empty( $wrapper['description'] )) { + $parseHash['content_id'] = $pParseHash['content_id']; + $parseHash['user_id'] = $pParseHash['user_id']; + $parseHash['no_cache'] = TRUE; + $parseHash['data'] = $wrapper['description']; + $wrapper['description_parsed'] = $pCommonObject->parseData( $parseHash ); + } - if( !empty( $pParams['output'] ) && ( $pParams['output'] == 'desc' || $pParams['output'] == 'description' )) { - $ret = ( !empty( $wrapper['description'] ) ? $wrapper['description'] : $att['filename'] ); - $nowrapper = TRUE; - } else { - $ret .= ( !empty( $wrapper['description'] ) ? '<br />'.$wrapper['description'] : '' ); - } + // pass stuff to the template + $gBitSmarty->assign( 'attachment', $att ); + $gBitSmarty->assign( 'wrapper', $wrapper ); + $gBitSmarty->assign( 'thumbsize', (( !empty( $pParams['size'] ) && ( $pParams['size'] == 'original' || !empty( $att['thumbnail_url'][$pParams['size']] ))) ? $pParams['size'] : 'medium' )); - // use specified link as href. insert default link to source only when - // source not already displayed - if( !empty( $pParams['link'] ) && $pParams['link'] == 'false' ) { - } elseif( !empty( $pParams['link'] ) ) { - if(( strstr( $pParams['link'], $_SERVER["SERVER_NAME"] )) || (!strstr( $pParams['link'], '//' ))) { - $class = ''; - } else { - $class = 'class="external"'; - } + //Carry only these attributes to the image tags + $width = !empty( $pParams['width'] ) ? $pParams['width'] : ''; + $gBitSmarty->assign( 'width', $width ); - $ret = '<a '.$class.' href="'.trim( $pParams['link'] ).'">'.$ret.'</a>'; - } elseif( !empty( $att['download_url'] ) ) { - $ret = '<a href="'.trim( $att['download_url'] ).'">'.$ret.'</a>'; - } elseif( !empty( $att['display_url'] ) ) { - $ret = '<a href="'.trim( $att['display_url'] ).'">'.$ret.'</a>'; - } elseif( empty( $pParams['size'] ) || $pParams['size'] != 'original' ) { - $ret = '<a href="'.trim( $att['source_url'] ).'">'.$ret.'</a>'; - } + $height = !empty( $pParams['height'] ) ? $pParams['height'] : ''; + $gBitSmarty->assign( 'height', $height ); - // finally, wrap the output. - if( empty( $nowrapper )) { - $ret = '<'.$wrapper['wrapper'].' class="'.( isset( $wrapper ) && !empty( $wrapper['class'] ) ? $wrapper['class'] : "att-plugin" ).'" style="'.$wrapper['style'].'">'.$ret.'</'.$wrapper['wrapper'].'>'; - } - } else { - $ret = tra( "The attachment id given is not valid." ); - } - } + $mimehandler = (( !empty( $wrapper['output'] ) && $wrapper['output'] == 'thumbnail' ) ? LIBERTY_DEFAULT_MIME_HANDLER : $att['attachment_plugin_guid'] ); + $ret = $gBitSmarty->fetch( $gLibertySystem->getMimeTemplate( 'attachment', $mimehandler )); return $ret; } ?> diff --git a/plugins/mime.default.php b/plugins/mime.default.php index 68ab2ee..be7860d 100644 --- a/plugins/mime.default.php +++ b/plugins/mime.default.php @@ -92,7 +92,7 @@ if( !function_exists( 'mime_default_verify' )) { if( @BitBase::verifyId( $pStoreRow['upload']['attachment_id'] )) { // if a new file has been uploaded, we need to get some information from the database for the file update $fileInfo = $gBitSystem->mDb->getRow( " - SELECT la.`attachment_id`, lf.`file_id`, lf.`storage_path` + SELECT la.`attachment_id`, lf.`file_id`, lf.`file_name` FROM `".BIT_DB_PREFIX."liberty_attachments` la INNER JOIN `".BIT_DB_PREFIX."liberty_files` lf ON ( lf.`file_id` = la.`foreign_id` ) WHERE la.`attachment_id` = ?", array( $pStoreRow['upload']['attachment_id'] )); @@ -142,10 +142,10 @@ if( !function_exists( 'mime_default_update' )) { $pStoreRow['dest_path'] = liberty_mime_get_storage_branch( $pStoreRow['attachment_id'], $pStoreRow['user_id'], liberty_mime_get_storage_sub_dir_name( $pStoreRow['upload'] )); } - if( !empty( $pStoreRow['dest_path'] ) && !empty( $pStoreRow['storage_path'] ) ) { + if( !empty( $pStoreRow['dest_path'] ) && !empty( $pStoreRow['file_name'] ) ) { // First we remove the old file $path = STORAGE_PKG_PATH.$pStoreRow['dest_path']; - $file = $path.$pStoreRow['storage_path']; + $file = $path.$pStoreRow['file_name']; if(( $nuke = LibertyMime::validateStoragePath( $path )) && is_dir( $nuke )) { if( !empty( $pStoreRow['unlink_dir'] )) { @unlink_r( $path ); @@ -166,7 +166,7 @@ if( !function_exists( 'mime_default_update' )) { // Now we process the uploaded file if( $storagePath = liberty_process_upload( $pStoreRow )) { - $sql = "UPDATE `".BIT_DB_PREFIX."liberty_files` SET `storage_path` = ?, `mime_type` = ?, `file_size` = ?, `user_id` = ? WHERE `file_id` = ?"; + $sql = "UPDATE `".BIT_DB_PREFIX."liberty_files` SET `file_name` = ?, `mime_type` = ?, `file_size` = ?, `user_id` = ? WHERE `file_id` = ?"; $gBitSystem->mDb->query( $sql, array( $pStoreRow['upload']['name'], $pStoreRow['upload']['type'], $pStoreRow['upload']['size'], $pStoreRow['user_id'], $pStoreRow['file_id'] )); } @@ -201,7 +201,7 @@ if( !function_exists( 'mime_default_store' )) { if( $storagePath = liberty_process_upload( $pStoreRow, empty( $pStoreRow['upload']['copy_file'] ))) { // add row to liberty_files $storeHash = array( - "storage_path" => $pStoreRow['upload']['name'], + "file_name" => $pStoreRow['upload']['name'], "file_id" => $gBitSystem->mDb->GenID( 'liberty_files_id_seq' ), "mime_type" => $pStoreRow['upload']['type'], "file_size" => $pStoreRow['upload']['size'], @@ -241,20 +241,20 @@ if( !function_exists( 'mime_default_load' )) { if( @BitBase::verifyId( $pFileHash['attachment_id'] )) { $query = " SELECT la.`attachment_id`, la.`content_id`, la.`attachment_plugin_guid`, la.`foreign_id`, la.`user_id`, la.`is_primary`, la.`pos`, la.`error_code`, la.`caption`, la.`hits` AS `downloads`, - lf.`file_id`, lf.`user_id`, lf.`storage_path`, lf.`file_size`, lf.`mime_type` + lf.`file_id`, lf.`user_id`, lf.`file_name`, lf.`file_size`, lf.`mime_type` FROM `".BIT_DB_PREFIX."liberty_attachments` la LEFT OUTER JOIN `".BIT_DB_PREFIX."liberty_files` lf ON( la.`foreign_id` = lf.`file_id` ) WHERE la.`attachment_id`=?"; if( $row = $gBitSystem->mDb->getRow( $query, array( $pFileHash['attachment_id'] ))) { $ret = array_merge( $pFileHash, $row ); - $storageName = basename( $row['storage_path'] ); + $storageName = basename( $row['file_name'] ); // compatibility with _FILES hash $row['name'] = $storageName; $row['type'] = $row['mime_type']; - $storageBranch = liberty_mime_get_storage_branch( $row['attachment_id'], $row['user_id'], liberty_mime_get_storage_sub_dir_name( $row ) ).$storageName; + $storageBranch = liberty_mime_get_storage_branch( array( 'sub_dir' => $row['attachment_id'], 'user_id' =>$row['user_id'], 'package' => liberty_mime_get_storage_sub_dir_name( $row ) ) ).$storageName; // this will fetch the correct thumbnails - $thumbHash['storage_path'] = STORAGE_PKG_PATH.$storageBranch; - $row['storage_path'] = $storageBranch; + $thumbHash['source_file'] = STORAGE_PKG_PATH.$storageBranch; + $row['source_file'] = STORAGE_PKG_PATH.$storageBranch; $canThumbFunc = liberty_get_function( 'can_thumbnail' ); if( $canThumbFunc && $canThumbFunc( $row['mime_type'] )) { $thumbHash['default_image'] = LIBERTY_PKG_URL.'icons/generating_thumbnails.png'; @@ -272,15 +272,16 @@ if( !function_exists( 'mime_default_load' )) { $ret['display_url'] = LIBERTY_PKG_URL."view_file.php?attachment_id=".$row['attachment_id']; } - $ret['filename'] = basename( $row['storage_path'] ); + // legacy table data was named storage_path and included a partial path. strip out any path just in case + $ret['file_name'] = basename( $row['file_name'] ); $ret['preferences'] = $pPrefs; // some stuff is only available if we have a source file // make sure to check for these when you use them. frequently the original might not be available // e.g.: video files are large and the original might be deleted after conversion - if( is_file( STORAGE_PKG_PATH.$row['storage_path'] )) { - $ret['source_file'] = STORAGE_PKG_PATH.$row['storage_path']; - $ret['source_url'] = storage_path_to_url( $row['storage_path'] ); + if( is_file( STORAGE_PKG_PATH.$storageBranch )) { + $ret['source_file'] = STORAGE_PKG_PATH.$storageBranch; + $ret['source_url'] = STORAGE_PKG_URL.$storageBranch; $ret['last_modified'] = filemtime( $ret['source_file'] ); if( $gBitSystem->isFeatureActive( "pretty_urls" ) || $gBitSystem->isFeatureActive( "pretty_urls_extended" )) { $ret['download_url'] = LIBERTY_PKG_URL."download/file/".$row['attachment_id']; @@ -293,12 +294,9 @@ if( !function_exists( 'mime_default_load' )) { if( $gLibertySystem->isPluginActive( 'dataattachment' )) { $ret['wiki_plugin_link'] = "{attachment id=".$row['attachment_id']."}"; } - - // additionally we'll add this to distinguish between old plugins and new ones - // TODO: this should hopefully not be necessary for too long - $ret['is_mime'] = TRUE; } } + return $ret; } } @@ -384,9 +382,9 @@ if( !function_exists( 'mime_default_expunge' )) { $ret = FALSE; if( @BitBase::verifyId( $pAttachmentId )) { if( $fileHash = LibertyMime::getAttachment( $pAttachmentId )) { - if( $gBitUser->isAdmin() || $gBitUser->mUserId == $fileHash['user_id'] && !empty( $fileHash['storage_path'] )) { + if( $gBitUser->isAdmin() || $gBitUser->mUserId == $fileHash['user_id'] && !empty( $fileHash['source_file'] )) { // make sure this is a valid storage directory before removing it - if(( $nuke = LibertyMime::validateStoragePath( STORAGE_PKG_PATH.$fileHash['storage_path'] )) && is_file( $nuke )) { + if(( $nuke = LibertyMime::validateStoragePath( $fileHash['source_file'] )) && is_file( $nuke )) { unlink_r( dirname( $nuke )); } $query = "DELETE FROM `".BIT_DB_PREFIX."liberty_files` WHERE `file_id` = ?"; diff --git a/plugins/storage.bitfile.php b/plugins/storage.bitfile.php index eb63e9c..92d1227 100644 --- a/plugins/storage.bitfile.php +++ b/plugins/storage.bitfile.php @@ -75,11 +75,11 @@ function bit_files_store( &$pStoreRow ) { } if( @BitBase::verifyId( $pStoreRow['foreign_id'] ) ) { - $sql = "UPDATE `".BIT_DB_PREFIX."liberty_files` SET `storage_path`=?, `mime_type`=?, `file_size`=? WHERE `file_id` = ?"; + $sql = "UPDATE `".BIT_DB_PREFIX."liberty_files` SET `file_name`=?, `mime_type`=?, `file_size`=? WHERE `file_id` = ?"; $gBitSystem->mDb->query( $sql, array( $pStoreRow['upload']['dest_path'].$pStoreRow['upload']['name'], $pStoreRow['upload']['type'], $pStoreRow['upload']['size'], $pStoreRow['foreign_id'] ) ); } else { $pStoreRow['foreign_id'] = $gBitSystem->mDb->GenID( 'liberty_files_id_seq' ); - $sql = "INSERT INTO `".BIT_DB_PREFIX."liberty_files` ( `storage_path`, `file_id`, `mime_type`, `file_size`, `user_id` ) VALUES ( ?, ?, ?, ?, ? )"; + $sql = "INSERT INTO `".BIT_DB_PREFIX."liberty_files` ( `file_name`, `file_id`, `mime_type`, `file_size`, `user_id` ) VALUES ( ?, ?, ?, ?, ? )"; $userId = !empty( $pStoreRow['upload']['user_id'] ) ? $pStoreRow['upload']['user_id'] : $gBitUser->mUserId; $gBitSystem->mDb->query($sql, array( $pStoreRow['upload']['dest_path'].$pStoreRow['upload']['name'], $pStoreRow['foreign_id'], $pStoreRow['upload']['type'], $pStoreRow['upload']['size'], $userId ) ); } @@ -98,14 +98,13 @@ function bit_files_load( $pRow ) { INNER JOIN `".BIT_DB_PREFIX."liberty_files` lf ON (lf.`file_id` = la.`foreign_id`) WHERE la.`foreign_id` = ? AND `attachment_plugin_guid` = ?"; if( $ret = $gBitSystem->mDb->getRow( $query, array( $pRow['foreign_id'], PLUGIN_GUID_BIT_FILES ))) { - $thumbHash['storage_path'] = $ret['storage_path']; + $ret['source_file'] = liberty_mime_get_source_file( $ret ); $canThumbFunc = liberty_get_function( 'can_thumbnail' ); if( $canThumbFunc( $ret['mime_type'] )) { $thumbHash['default_image'] = LIBERTY_PKG_URL.'icons/generating_thumbnails.png'; } - $ret['thumbnail_url'] = liberty_fetch_thumbnails( $thumbHash ); - $ret['filename'] = str_replace('//', '/', substr( $ret['storage_path'], strrpos($ret['storage_path'], '/')+1) ); - $ret['source_url'] = storage_path_to_url( $ret['storage_path'] ); + $ret['source_url'] = liberty_mime_get_storage_url( $ret ).basename( $ret['file_name'] ); + $ret['thumbnail_url'] = liberty_fetch_thumbnails( $ret ); $ret['wiki_plugin_link'] = "{attachment id=".$ret['attachment_id']."}"; } } @@ -117,25 +116,23 @@ function bit_files_expunge( $pStorageId ) { $ret = FALSE; if (is_numeric($pStorageId)) { - $sql = "SELECT * FROM `".BIT_DB_PREFIX."liberty_attachments` WHERE `attachment_id` = ?"; + $sql = "SELECT * FROM `".BIT_DB_PREFIX."liberty_attachments` la + INNER JOIN `".BIT_DB_PREFIX."liberty_files` lf ON (lf.`file_id`=la.`foreign_id`) + WHERE la.`attachment_id` = ?"; if( $row = $gBitSystem->mDb->getRow( $sql, array( $pStorageId ))) { - $sql = "SELECT * FROM `".BIT_DB_PREFIX."liberty_files` WHERE `file_id` = ?"; - if( $fileRow = $gBitSystem->mDb->getRow( $sql, array( $row['foreign_id'] ))) { - $absolutePath = STORAGE_PKG_PATH.'/'.$fileRow['storage_path']; - - if( $gBitUser->isAdmin() || $gBitUser->mUserId == $row['user_id'] ) { - if( file_exists( $absolutePath )) { - // make sure this is a valid storage directory before removing it - if( preg_match( '!/users/\d+/\d+/\w+/\d+/.+!', $fileRow['storage_path'] )) { - unlink_r( dirname( $absolutePath )); - } else { - unlink( $absolutePath ); - } + $sourceFile = liberty_mime_get_source_file( $row ); + if( $gBitUser->isAdmin() || $gBitUser->mUserId == $row['user_id'] ) { + if( file_exists( $sourceFile )) { + // make sure this is a valid storage directory before removing it + if( preg_match( '!/users/\d+/\d+/\w+/\d+/.+!', $sourceFile )) { + unlink_r( dirname( $sourceFile )); + } else { + unlink( $sourceFile ); } - $query = "DELETE FROM `".BIT_DB_PREFIX."liberty_files` WHERE `file_id` = ?"; - $gBitSystem->mDb->query($query, array($row['foreign_id']) ); - $ret = TRUE; } + $query = "DELETE FROM `".BIT_DB_PREFIX."liberty_files` WHERE `file_id` = ?"; + $gBitSystem->mDb->query($query, array($row['foreign_id']) ); + $ret = TRUE; } } } |
