[pLog-svn] r5202 - in plog/branches/lifetype-1.2: class/file class/gallery/dao class/net locale/admin templates/admin
mark at devel.lifetype.net
mark at devel.lifetype.net
Tue Mar 27 16:18:53 EDT 2007
Author: mark
Date: 2007-03-27 16:18:53 -0400 (Tue, 27 Mar 2007)
New Revision: 5202
Modified:
plog/branches/lifetype-1.2/class/file/file.class.php
plog/branches/lifetype-1.2/class/file/fileuploads.class.php
plog/branches/lifetype-1.2/class/gallery/dao/galleryresource.class.php
plog/branches/lifetype-1.2/class/gallery/dao/galleryresourcestorage.class.php
plog/branches/lifetype-1.2/class/net/baserequestgenerator.class.php
plog/branches/lifetype-1.2/locale/admin/locale_en_UK.php
plog/branches/lifetype-1.2/locale/admin/locale_zh_CN.php
plog/branches/lifetype-1.2/locale/admin/locale_zh_TW.php
plog/branches/lifetype-1.2/templates/admin/globalsettings_resources.template
Log:
Fixed bug http://bugs.lifetype.net/view.php?id=1229
Now, LifeType 1.2 support two kind of resource file naming rule:
1. Original File Name: LifeType 1.2 will use the Original File name as the Resource File name. It is the default option.
2. Encoded Filename (as 1.1 implementation): For some stupid reasons. The multi-byte Microsoft Windows does not support utf-8 in file system very well. So, we have to use encoded name to replace the original file. The encoded naming rule is like following [BlogId-ResourceId.Extestion]
PS. I am still working on a option for wizard.php, it will let user choose convert the filename to realname or remained in encoded file name (1.1)
Modified: plog/branches/lifetype-1.2/class/file/file.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/file/file.class.php 2007-03-27 20:00:11 UTC (rev 5201)
+++ plog/branches/lifetype-1.2/class/file/file.class.php 2007-03-27 20:18:53 UTC (rev 5202)
@@ -392,7 +392,7 @@
// copy the file to the new location
if (!copy($inFile, $outFile)) {
// The copy failed, return false
- return FALSE;
+ return false;
}
// Now delete the old file
@@ -404,7 +404,7 @@
// but this call to unlink could just as easily fail
unlink( $inFile );
- return TRUE;
+ return true;;
}
/**
Modified: plog/branches/lifetype-1.2/class/file/fileuploads.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/file/fileuploads.class.php 2007-03-27 20:00:11 UTC (rev 5201)
+++ plog/branches/lifetype-1.2/class/file/fileuploads.class.php 2007-03-27 20:18:53 UTC (rev 5202)
@@ -2,6 +2,7 @@
lt_include( PLOG_CLASS_PATH."class/file/fileupload.class.php" );
+ lt_include( PLOG_CLASS_PATH."class/config/config.class.php" );
define( "FILE_UPLOADS_NOT_ENABLED", -200 );
@@ -43,6 +44,7 @@
{
// first, check if the upload feature is available
$config =& Config::getConfig();
+
if( !$config->getValue( "uploads_enabled" )) {
return FILE_UPLOADS_NOT_ENABLED;
}
@@ -50,17 +52,19 @@
if( $destinationFolder[strlen($destinationFolder)-1] != "/" )
$destinationFolder .= "/";
- //use basename of tmp_name istead of filename
- //because there is locale problem with filename
- //$fileName = $upload->getFileName();
- if( $this->my_move_uploaded_file( $upload->getTmpName(),
- $destinationFolder.basename($upload->getFileName()))){//$fileName)) {
+ // encoding the filename if "encoded_file_name" enabled
+ if( $config->getValue( "resources_naming_rule" ) == "encoded_file_name" )
+ $fileName = rawurlencode($upload->getFileName());
+ else
+ $fileName = $upload->getFileName();
+
+ if( $this->my_move_uploaded_file( $upload->getTmpName(), $destinationFolder.$fileName ) ) {
$upload->setFolder( $destinationFolder );
$error = 0;
}
else {
$error = 1;
- }
+ }
$upload->setError( $error );
@@ -79,6 +83,7 @@
{
// first, check if the upload feature is available
$config =& Config::getConfig();
+
if( !$config->getValue( "uploads_enabled" )) {
return FILE_UPLOADS_NOT_ENABLED;
}
@@ -91,8 +96,14 @@
foreach( $this->_files as $file ) {
$upload = new FileUpload( $file );
- $fileName = $upload->getFileName();
- if( $this->my_move_uploaded_file( $upload->getTmpName(), $destinationFolder.$fileName)) {
+
+ // encoding the filename if "encoded_file_name" enabled
+ if( $config->getValue( "resources_naming_rule" ) == "encoded_file_name" )
+ $fileName = rawurlencode($upload->getFileName());
+ else
+ $fileName = $upload->getFileName();
+
+ if( $this->my_move_uploaded_file( $upload->getTmpName(), $destinationFolder.$fileName ) ) {
$upload->setFolder( $destinationFolder );
$upload->setError( 0 );
}
Modified: plog/branches/lifetype-1.2/class/gallery/dao/galleryresource.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/gallery/dao/galleryresource.class.php 2007-03-27 20:00:11 UTC (rev 5201)
+++ plog/branches/lifetype-1.2/class/gallery/dao/galleryresource.class.php 2007-03-27 20:18:53 UTC (rev 5202)
@@ -199,6 +199,17 @@
}
/**
+ * @return the encoded name of the file in disk
+ */
+ function getEncodedFileName()
+ {
+ $fileParts = explode( ".", $this->_fileName );
+ $fileExt = strtolower($fileParts[count($fileParts)-1]);
+ $encodedFileName = $this->getOwnerId()."-".$this->getId().".".$fileExt;
+ return $encodedFileName;
+ }
+
+ /**
* @return the description of the resource
*/
function getDescription()
@@ -372,13 +383,20 @@
function getPreviewFileName()
{
lt_include( PLOG_CLASS_PATH."class/gallery/dao/galleryresourcestorage.class.php" );
+
+ $config =& Config::getConfig();
+
+ // encoding the filename if "encoded_file_name" enabled
+ if( $config->getValue( "resources_naming_rule" ) == "encoded_file_name" )
+ $fileName = $this->getEncodedFileName();
+ else
+ $fileName = $this->getFileName();
- if( $this->getThumbnailFormat() == THUMBNAIL_OUTPUT_FORMAT_SAME_AS_IMAGE ) {
- $previewFile = $this->getFileName();
- }
- else {
- $previewFile = str_replace( ".".$this->_getFileExtension(), ".".$this->getThumbnailFormat(), $this->getFileName());
- }
+ // change the file extension, if the thumbnail output format is different from the original file
+ if( $this->getThumbnailFormat() == THUMBNAIL_OUTPUT_FORMAT_SAME_AS_IMAGE )
+ $previewFile = $fileName;
+ else
+ $previewFile = str_replace( ".".$this->_getFileExtension(), ".".$this->getThumbnailFormat(), $fileName );
return $previewFile;
}
@@ -408,16 +426,43 @@
{
lt_include( PLOG_CLASS_PATH."class/gallery/dao/galleryresourcestorage.class.php" );
- if( $this->getThumbnailFormat() == THUMBNAIL_OUTPUT_FORMAT_SAME_AS_IMAGE ) {
- $previewFile = $this->getFileName();
- }
- else {
- $previewFile = str_replace( ".".$this->_getFileExtension(), ".".$this->getThumbnailFormat(), $this->getFileName());
- }
+ $config =& Config::getConfig();
+ // encoding the filename if "encoded_file_name" enabled
+ if( $config->getValue( "resources_naming_rule" ) == "encoded_file_name" )
+ $fileName = $this->getEncodedFileName();
+ else
+ $fileName = $this->getFileName();
+
+ // change the file extension, if the thumbnail output format is different from the original file
+ if( $this->getThumbnailFormat() == THUMBNAIL_OUTPUT_FORMAT_SAME_AS_IMAGE )
+ $previewFile = $fileName;
+ else
+ $previewFile = str_replace( ".".$this->_getFileExtension(), ".".$this->getThumbnailFormat(), $fileName );
+
return $previewFile;
}
+
+ /**
+ * returns the full path to the file with the original size
+ *
+ * @return full path to the original size
+ */
+ function getOriginalSizeFileName()
+ {
+ lt_include( PLOG_CLASS_PATH."class/gallery/dao/galleryresourcestorage.class.php" );
+ $config =& Config::getConfig();
+
+ // encoding the filename if "encoded_file_name" enabled
+ if( $config->getValue( "resources_naming_rule" ) == "encoded_file_name" )
+ $fileName = $this->getEncodedFileName();
+ else
+ $fileName = $this->getFileName();
+
+ return $fileName;
+ }
+
function getNormalizedDescription()
{
lt_include( PLOG_CLASS_PATH."class/data/textfilter.class.php" );
Modified: plog/branches/lifetype-1.2/class/gallery/dao/galleryresourcestorage.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/gallery/dao/galleryresourcestorage.class.php 2007-03-27 20:00:11 UTC (rev 5201)
+++ plog/branches/lifetype-1.2/class/gallery/dao/galleryresourcestorage.class.php 2007-03-27 20:18:53 UTC (rev 5202)
@@ -241,19 +241,29 @@
}
// rename it while it's there
- $origFile = $tmpFolder."/".basename($upload->getFileName());
+ if( $config->getValue( "resources_naming_rule" ) == "encoded_file_name" )
+ $origFile = $tmpFolder."/".rawurlencode($upload->getFileName());
+ else
+ $origFile = $tmpFolder."/".$upload->basename(getFileName());
+
//do not use storeFile method because I have change filename in $tmpFolder.
//$destFile = $this->storeFile( $resourceId, $ownerId, $origFile, RESOURCE_STORAGE_STORE_MOVE );
//$destFile use $filePath and $fileName generated above.
//$destFile = $filePath.$fileName;
- $destFile = $filePath.$upload->getFileName();
+ if( $config->getValue( "resources_naming_rule" ) == "encoded_file_name" ) {
+ $fileName = $upload->getFileName();
+ // new name for the file
+ $fileParts = explode( ".", $fileName);
+ $fileExt = strtolower($fileParts[count($fileParts)-1]);
+ $destFile = $filePath.$ownerId."-".$resourceId.".".$fileExt;
+ }
+ else {
+ $destFile = $filePath.$upload->getFileName();
+ }
-//=========================================
-//codes below are copy and modify from method storeFile
// first of all, check if the file is readable and if not, quit
if( !File::isReadable($origFile)) {
- print("dest file = ".$destFile." - orig file = ".$origFile."<br/>");
return false;
}
@@ -265,8 +275,6 @@
// check that the permissions are correct
File::chMod( $destFile, 0755 );
-//=========================================
-
return $destFile;
}
@@ -289,9 +297,18 @@
// new name for the file
$fileParts = explode( ".", $fileName);
- $fileExt = $fileParts[count($fileParts)-1];
+ $fileExt = strtolower($fileParts[count($fileParts)-1]);
+
//$destFile = "$ownerId-$resourceId.$fileExt";
- $destFile = basename( $fileName );
+ $config =& Config::getConfig();
+
+ // first of all, remove the resource file itself
+ $filePath = $this->getUserFolder( $resource->getOwnerId());
+ if( $config->getValue( "resources_naming_rule" ) == "encoded_file_name" )
+ $destFile = $ownerId."-".$resourceId.".".$fileExt;
+ else
+ $destFile = basename( $fileName );
+
$destPath = $this->getUserFolder( $ownerId );
// first of all, check if the file is readable and if not, quit
@@ -324,9 +341,14 @@
function remove( $resource )
{
if( $resource ) {
+ $config =& Config::getConfig();
+
// first of all, remove the resource file itself
$filePath = $this->getUserFolder( $resource->getOwnerId());
- $fullName = $filePath.$resource->getFileName();
+ if( $config->getValue( "resources_naming_rule" ) == "encoded_file_name" )
+ $fullName = $filePath.$resource->getEncodedFileName();
+ else
+ $fullName = $filePath.$resource->getFileName();
if( File::isReadable( $fullName)) {
$result = File::delete( $fullName );
@@ -361,7 +383,17 @@
*/
function getResourcePath( $resource )
{
- return( $this->getUserFolder( $resource->getOwnerId()).$resource->getFileName());
+ $config =& Config::getConfig();
+
+ // first of all, remove the resource file itself
+ $filePath = $this->getUserFolder( $resource->getOwnerId());
+ if( $config->getValue( "resources_naming_rule" ) == "encoded_file_name" )
+ $fileName = $resource->getEncodedFileName();
+ else
+ $fileName = $resource->getFileName();
+
+ $resourcePath = $this->getUserFolder( $resource->getOwnerId()).$fileName;
+ return $resourcePath;
}
}
?>
Modified: plog/branches/lifetype-1.2/class/net/baserequestgenerator.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/net/baserequestgenerator.class.php 2007-03-27 20:00:11 UTC (rev 5201)
+++ plog/branches/lifetype-1.2/class/net/baserequestgenerator.class.php 2007-03-27 20:18:53 UTC (rev 5202)
@@ -537,7 +537,7 @@
function resourceDownloadLink( $resource )
{
$blogId = ($resource->getOwnerId() ? $resource->getOwnerId() : $this->_blogInfo->getId());
- $resourceLink = $this->getResourcesBaseUrl().$blogId."/".rawurlencode($resource->getFileName());
+ $resourceLink = $this->getResourcesBaseUrl().$blogId."/".rawurlencode($resource->getOriginalSizeFileName());
return $resourceLink;
}
Modified: plog/branches/lifetype-1.2/locale/admin/locale_en_UK.php
===================================================================
--- plog/branches/lifetype-1.2/locale/admin/locale_en_UK.php 2007-03-27 20:00:11 UTC (rev 5201)
+++ plog/branches/lifetype-1.2/locale/admin/locale_en_UK.php 2007-03-27 20:18:53 UTC (rev 5202)
@@ -1158,4 +1158,8 @@
$messages['error_select_status'] = 'Please select a valid status';
$messages['error_invalid_blog_name'] = 'Sorry, the blog name is not valid';
+
+$messages['help_resources_naming_rule'] = 'The file naming rules for uploaded resources. \'Original File Name\' use original file for uploaded resources. \'Encoded File Name\' use the encoded file name for uploaded resources, the naming rule is [BlogId]-[ResourceId].[Ext]. Please use \'Encoded File Name\' if you install LifeType under Multi-Byte Microsoft Windows environment. <strong>And please don\'t change this option after users start uploading the files into LifeType. It will make uploaded files can\'t be accessed anymore.</strong> [Default = Original File Name]';
+$messages['original_file_name'] = 'Original File Name';
+$messages['encoded_file_name'] = 'Encoded File Name';
?>
\ No newline at end of file
Modified: plog/branches/lifetype-1.2/locale/admin/locale_zh_CN.php
===================================================================
--- plog/branches/lifetype-1.2/locale/admin/locale_zh_CN.php 2007-03-27 20:00:11 UTC (rev 5201)
+++ plog/branches/lifetype-1.2/locale/admin/locale_zh_CN.php 2007-03-27 20:18:53 UTC (rev 5202)
@@ -1157,6 +1157,9 @@
$messages['eror_updating_user2'] = '更新用户 "%s" 时发生错误。';
$messages['error_select_status'] = '请选择合法的状态。';
+$messages['error_invalid_blog_name'] = '网志博客“%s”不正确。';
-$messages['error_invalid_blog_name'] = 'Sorry, the blog name is not valid';
+$messages['help_resources_naming_rule'] = '选择档案上传后在主机的储存方式。“原始档案名称”使用原来的档案名称来储存上传的档案。“编码档案名称”使用编码过的档案名称 [BlogId]-[ResourceId].[Ext] 来储存上传的档案。在 Windows 多字元下安装 LifeType 请使用“编码档案名称”。<strong>另外,当使用者开始上传档案后,请勿修改此选项,这会造成以上传的档案无法再被读取。</strong> [预设 = 原始档案名称]';
+$messages['original_file_name'] = '原始档案名称';
+$messages['encoded_file_name'] = '编码档案名称';
?>
\ No newline at end of file
Modified: plog/branches/lifetype-1.2/locale/admin/locale_zh_TW.php
===================================================================
--- plog/branches/lifetype-1.2/locale/admin/locale_zh_TW.php 2007-03-27 20:00:11 UTC (rev 5201)
+++ plog/branches/lifetype-1.2/locale/admin/locale_zh_TW.php 2007-03-27 20:18:53 UTC (rev 5202)
@@ -1157,6 +1157,9 @@
$messages['eror_updating_user2'] = '更新使用者 "%s" 時發生錯誤。';
$messages['error_select_status'] = '請選擇合法的狀態。';
+$messages['error_invalid_blog_name'] = '網誌名稱「%s」不正確。';
-$messages['error_invalid_blog_name'] = 'Sorry, the blog name is not valid';
+$messages['help_resources_naming_rule'] = '選擇檔案上傳後在主機的儲存方式。「原始檔案名稱」使用原來的檔案名稱來儲存上傳的檔案。「編碼檔案名稱」使用編碼過的檔案名稱 [BlogId]-[ResourceId].[Ext] 來儲存上傳的檔案。在 Windows 多字元下安裝 LifeType 請使用「編碼檔案名稱」。<strong>另外,當使用者開始上傳檔案後,請勿修改此選項,這會造成以上傳的檔案無法再被讀取。</strong> [預設 = 原始檔案名稱]';
+$messages['original_file_name'] = '原始檔案名稱';
+$messages['encoded_file_name'] = '編碼檔案名稱';
?>
\ No newline at end of file
Modified: plog/branches/lifetype-1.2/templates/admin/globalsettings_resources.template
===================================================================
--- plog/branches/lifetype-1.2/templates/admin/globalsettings_resources.template 2007-03-27 20:00:11 UTC (rev 5201)
+++ plog/branches/lifetype-1.2/templates/admin/globalsettings_resources.template 2007-03-27 20:18:53 UTC (rev 5202)
@@ -11,7 +11,16 @@
<label for="config[resources_folder]">resources_folder</label>
<div class="formHelp">{$locale->tr("help_resources_folder")}</div>
<input style="width:100%" type="text" name="config[resources_folder]" value="{$resources_folder}"/>
- </div>
+ </div>
+ <!-- resources naming rule -->
+ <div class="field">
+ <label for="config[resources_naming_rule]">resources_naming_rule</label>
+ <div class="formHelp">{$locale->tr("help_resources_naming_rule")}</div>
+ <select name="config[resources_naming_rule]">
+ <option value="original_file_name" {if $resources_naming_rule == "original_file_name"} selected="selected" {/if} />{$locale->tr("original_file_name")}</option>
+ <option value="encoded_file_name" {if $resources_naming_rule == "encoded_file_name"} selected="selected" {/if} />{$locale->tr("encoded_file_name")}</option>
+ </select>
+ </div>
<!-- thumbnail_method -->
<div class="field">
<label for="config[thumbnail_method]">thumbnail_method</label>
More information about the pLog-svn
mailing list