#1331 커버 이미지를 선택할 수 있는 기능 추가

- files 테이블에 cover_image 컬럼 추가
- 썸네일 생성 로직에 cover_image 값을 참조하여 이미지 선택 사용
- 파일 업로드 기능에 UI 추가
This commit is contained in:
bnu 2015-07-07 15:04:06 +09:00
parent cc5207423e
commit 4faa291880
14 changed files with 225 additions and 39 deletions

View file

@ -543,6 +543,11 @@ class commentItem extends Object
return;
}
if($this->isSecret() && !$this->isGranted())
{
return;
}
// If signiture height setting is omitted, create a square
if(!$height)
{
@ -587,30 +592,33 @@ class commentItem extends Object
if($this->hasUploadedFiles())
{
$file_list = $this->getUploadedFiles();
if(count($file_list))
{
foreach($file_list as $file)
{
if($file->direct_download != 'Y')
{
continue;
}
if(!preg_match("/\.(jpg|png|jpeg|gif|bmp)$/i", $file->source_filename))
{
continue;
}
$first_image = null;
foreach($file_list as $file)
{
if($file->direct_download !== 'Y') continue;
if($file->cover_image === 'Y' && file_exists($file->uploaded_filename))
{
$source_file = $file->uploaded_filename;
if(!file_exists($source_file))
break;
}
if($first_image) continue;
if(preg_match("/\.(jpe?g|png|gif|bmp)$/i", $file->source_filename))
{
if(file_exists($file->uploaded_filename))
{
$source_file = NULL;
}
else
{
break;
$first_image = $file->uploaded_filename;
}
}
}
if(!$source_file && $first_image)
{
$source_file = $first_image;
}
}
// get an image file from the doc content if no file attached.

View file

@ -773,6 +773,12 @@ class documentItem extends Object
{
// Return false if the document doesn't exist
if(!$this->document_srl) return;
if($this->isSecret() && !$this->isGranted())
{
return;
}
// If not specify its height, create a square
if(!$height) $height = $width;
// Return false if neither attachement nor image files in the document
@ -799,27 +805,44 @@ class documentItem extends Object
if(filesize($thumbnail_file)<1) return false;
else return $thumbnail_url;
}
// Target File
$source_file = null;
$is_tmp_file = false;
// Find an iamge file among attached files if exists
if($this->get('uploaded_count'))
{
$oFileModel = getModel('file');
$file_list = $oFileModel->getFiles($this->document_srl, array(), 'file_srl', true);
if(count($file_list))
{
foreach($file_list as $file)
{
if($file->direct_download!='Y') continue;
if(!preg_match("/\.(jpg|png|jpeg|gif|bmp)$/i",$file->source_filename)) continue;
// Find an iamge file among attached files if exists
if($this->hasUploadedFiles())
{
$file_list = $this->getUploadedFiles();
$first_image = null;
foreach($file_list as $file)
{
if($file->direct_download !== 'Y') continue;
if($file->cover_image === 'Y' && file_exists($file->uploaded_filename))
{
$source_file = $file->uploaded_filename;
if(!file_exists($source_file)) $source_file = null;
else break;
break;
}
if($first_image) continue;
if(preg_match("/\.(jpe?g|png|gif|bmp)$/i", $file->source_filename))
{
if(file_exists($file->uploaded_filename))
{
$first_image = $file->uploaded_filename;
}
}
}
if(!$source_file && $first_image)
{
$source_file = $first_image;
}
}
// If not exists, file an image file from the content
if(!$source_file)
{

View file

@ -19,6 +19,7 @@
<action name="procFileAdminInsertModuleConfig" type="controller" ruleset="fileModuleConfig" />
<action name="procFileAdminAddCart" type="controller" />
<action name="procFileGetList" type="controller" />
<action name="procFileSetCoverImage" type="controller" />
</actions>
<menus>
<menu name="file">

View file

@ -78,6 +78,8 @@ class file extends ModuleObject
// 2012. 08. 29 Add a trigger to copy additional setting when the module is copied
if(!$oModuleModel->getTrigger('module.procModuleAdminCopyModule', 'file', 'controller', 'triggerCopyModule', 'after')) return true;
if(!$oDB->isColumnExists('files', 'cover_image')) return true;
return false;
}
@ -139,6 +141,8 @@ class file extends ModuleObject
$oModuleController->insertTrigger('module.procModuleAdminCopyModule', 'file', 'controller', 'triggerCopyModule', 'after');
}
if(!$oDB->isColumnExists('files', 'cover_image')) $oDB->addColumn('files', 'cover_image', 'char', '1', 'N');
return new Object(0, 'success_updated');
}

View file

@ -935,6 +935,68 @@ class fileController extends file
}
}
public function procFileSetCoverImage()
{
$vars = Context::getRequestVars();
$upload_target_srl = null;
$oFileModel = &getModel('file');
$oDocumentModel = &getModel('document');
$oCommentModel = &getModel('comment');
$file_info = $oFileModel->getFile($vars->file_srl);
if(!$file_info) return new Object(-1, 'msg_not_founded');
$oDocument = $oDocumentModel->getDocument($file_info->upload_target_srl);
if($oDocument->isExists())
{
if(!$oDocument->isGranted()) return new Object(-1, 'msg_not_permitted');
$upload_target_srl = $oDocument->document_srl;
}
else
{
$oComment = $oCommentModel->getComment($file_info->upload_target_srl);
if($oDocument->isExists())
{
if(!$oComment->isGranted()) return new Object(-1, 'msg_not_permitted');
$upload_target_srl = $oComment->document_srl;
}
}
if(!$upload_target_srl) return new Object(-1, 'msg_not_founded');
$args = new stdClass();
$args->file_srl = $vars->file_srl;
$args->upload_target_srl = $upload_target_srl;
$oDB = &DB::getInstance();
$oDB->begin();
$args->cover_image = 'N';
$output = executeQuery('file.updateClearCoverImage', $args);
if(!$output->toBool())
{
$oDB->rollback();
return $output;
}
$args->cover_image = 'Y';
$output = executeQuery('file.updateCoverImage', $args);
if(!$output->toBool())
{
$oDB->rollback();
return $output;
}
$oDB->commit();
// 썸네일 삭제
$thumbnail_path = sprintf('files/thumbnails/%s', getNumberingPath($upload_target_srl, 3));
Filehandler::removeFilesInDir($thumbnail_path);
}
/**
* Find the attachment where a key is upload_target_srl and then return java script code
*
@ -965,3 +1027,4 @@ class fileController extends file
}
/* End of file file.controller.php */
/* Location: ./modules/file/file.controller.php */

View file

@ -49,6 +49,7 @@ class fileModel extends file
if($file_info->direct_download=='N') $obj->download_url = $this->getDownloadUrl($file_info->file_srl, $file_info->sid, $file_info->module_srl);
else $obj->download_url = str_replace('./', '', $file_info->uploaded_filename);
$obj->direct_download = $file_info->direct_download;
$obj->cover_image = ($file_info->cover_image === 'Y') ? true : false;
$files[] = $obj;
$attached_size += $file_info->file_size;
}

View file

@ -0,0 +1,9 @@
<query id="getCoverImage" action="select">
<tables>
<table name="files" />
</tables>
<conditions>
<condition operation="equal" column="upload_target_srl" var="upload_target_srl" filter="number" notnull="notnull" />
<condition operation="equal" column="cover_image" default="Y" notnull="notnull" />
</conditions>
</query>

View file

@ -14,6 +14,7 @@
<column name="comment" var="comment" />
<column name="download_count" var="download_count" default="0" />
<column name="member_srl" var="member_srl" default="0" />
<column name="cover_image" var="is_cover" default="N" />
<column name="regdate" var="regdate" default="curdate()" />
<column name="ipaddress" var="ipaddress" default="ipaddress()" />
<column name="isvalid" var="isvalid" default="N" />

View file

@ -0,0 +1,13 @@
<query id="updateClearCoverImage" action="update">
<tables>
<table name="files" />
</tables>
<columns>
<column name="cover_image" default="N" notnull="notnull" />
</columns>
<conditions>
<condition operation="equal" column="upload_target_srl" var="upload_target_srl" notnull="notnull" />
<condition operation="equal" column="cover_image" default="Y" notnull="notnull" pipe="and" />
<condition operation="notequal" column="file_srl" var="cover_file_srl" pipe="and" />
</conditions>
</query>

View file

@ -0,0 +1,11 @@
<query id="updateCoverImage" action="update">
<tables>
<table name="files" />
</tables>
<columns>
<column name="cover_image" var="cover_image" default="Y" notnull="notnull" />
</columns>
<conditions>
<condition operation="equal" column="file_srl" var="file_srl" filter="number" notnull="notnull" />
</conditions>
</query>

View file

@ -7,6 +7,7 @@
<column name="upload_target_type" var="upload_target_type" />
<column name="module_srl" var="module_srl" filter="number" notnull="notnull" />
<column name="uploaded_filename" var="uploaded_filename" notnull="notnull" minlength="1" maxlength="250" />
<column name="cover_image" var="is_cover" default="N" />
</columns>
<conditions>
<condition operation="equal" column="file_srl" var="file_srl" filter="number" notnull="notnull" />

View file

@ -12,6 +12,7 @@
<column name="file_size" type="number" size="11" default="0" notnull="notnull" index="idx_file_size" />
<column name="comment" type="varchar" size="250" />
<column name="isvalid" type="char" size="1" default="N" index="idx_is_valid" />
<column name="cover_image" type="char" size="1" default="N" notnull="notnull" index="idx_list_order" />
<column name="regdate" type="date" index="idx_regdate" />
<column name="ipaddress" type="varchar" size="128" notnull="notnull" index="idx_ipaddress"/>
</table>