1
0
Fork 0
mirror of https://github.com/Oreolek/ifhub.club.git synced 2024-06-26 11:40:48 +03:00

Доработка модуля Image - возможность переопределить удаление файлов изображений

This commit is contained in:
Mzhelskiy Maxim 2012-04-08 18:37:43 +04:00
parent d28a4c2693
commit ee04c7d2c6
5 changed files with 63 additions and 28 deletions

View file

@ -108,10 +108,12 @@ class ActionSettings extends Action {
$this->Session_Set('sFotoFileTmp',$sFile);
$this->Session_Set('sFotoFilePreviewTmp',$sFilePreview);
$this->Viewer_AssignAjax('sTmpFile',$this->Image_GetWebPath($sFilePreview));
unlink($sFileTmp);
return;
}
}
$this->Message_AddError($this->Image_GetLastError(),$this->Lang_Get('error'));
unlink($sFileTmp);
}
/**
@ -154,9 +156,8 @@ class ActionSettings extends Action {
$this->oUserCurrent->setProfileFoto($sFileWeb);
$this->User_Update($this->oUserCurrent);
if (file_exists($sFilePreview)) {
@unlink($sFilePreview);
}
$this->Image_RemoveFile($sFilePreview);
$this->Session_Drop('sFotoFileTmp');
$this->Session_Drop('sFotoFilePreviewTmp');
$this->Viewer_AssignAjax('sFile',$this->oUserCurrent->getProfileFoto());
@ -192,13 +193,11 @@ class ActionSettings extends Action {
* Достаем из сессии файл и удаляем
*/
$sFile=$this->Session_Get('sFotoFileTmp');
if (file_exists($sFile)) {
@unlink($sFile);
}
$this->Image_RemoveFile($sFile);
$sFile=$this->Session_Get('sFotoFilePreviewTmp');
if (file_exists($sFile)) {
@unlink($sFile);
}
$this->Image_RemoveFile($sFile);
$this->Session_Drop('sFotoFileTmp');
$this->Session_Drop('sFotoFilePreviewTmp');
}
@ -229,6 +228,7 @@ class ActionSettings extends Action {
} else {
$this->Message_AddError($this->Image_GetLastError(),$this->Lang_Get('error'));
}
unlink($sFileTmp);
}
/**
@ -296,9 +296,7 @@ class ActionSettings extends Action {
* Достаем из сессии файл и удаляем
*/
$sFileAvatar=$this->Session_Get('sAvatarFileTmp');
if (file_exists($sFileAvatar)) {
@unlink($sFileAvatar);
}
$this->Image_RemoveFile($sFileAvatar);
$this->Session_Drop('sAvatarFileTmp');
}

View file

@ -843,7 +843,7 @@ class ModuleBlog extends Module {
if($oBlog->getAvatar()) {
$aSize=array_merge(Config::Get('module.blog.avatar_size'),array(48));
foreach ($aSize as $iSize) {
@unlink($this->Image_GetServerPath($oBlog->getAvatarPath($iSize)));
$this->Image_RemoveFile($this->Image_GetServerPath($oBlog->getAvatarPath($iSize)));
}
}
}

View file

@ -1673,7 +1673,7 @@ class ModuleTopic extends Module {
$this->Cache_Clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG,array("photoset_photo_update"));
$this->oMapperTopic->deleteTopicPhoto($oPhoto->getId());
@unlink($this->Image_GetServerPath($oPhoto->getWebPath()));
$this->Image_RemoveFile($this->Image_GetServerPath($oPhoto->getWebPath()));
$aSizes=Config::Get('module.topic.photoset.size');
// Удаляем все сгенерированные миниатюры основываясь на данных из конфига.
foreach ($aSizes as $aSize) {
@ -1681,7 +1681,7 @@ class ModuleTopic extends Module {
if ($aSize['crop']) {
$sSize .= 'crop';
}
@unlink($this->Image_GetServerPath($oPhoto->getWebPath($sSize)));
$this->Image_RemoveFile($this->Image_GetServerPath($oPhoto->getWebPath($sSize)));
}
return;
}

View file

@ -1107,7 +1107,7 @@ class ModuleUser extends Module {
if($oUser->getProfileAvatar()) {
$aSize=array_merge(Config::Get('module.user.avatar_size'),array(100));
foreach ($aSize as $iSize) {
@unlink($this->Image_GetServerPath($oUser->getProfileAvatarPath($iSize)));
$this->Image_RemoveFile($this->Image_GetServerPath($oUser->getProfileAvatarPath($iSize)));
}
}
}
@ -1198,7 +1198,7 @@ class ModuleUser extends Module {
* @param ModuleUser_EntityUser $oUser
*/
public function DeleteFoto($oUser) {
@unlink($this->Image_GetServerPath($oUser->getProfileFoto()));
$this->Image_RemoveFile($this->Image_GetServerPath($oUser->getProfileFoto()));
}
/**
* Проверяет логин на корректность

View file

@ -142,8 +142,6 @@ class ModuleImage extends Module {
or ($oImage->get_image_params('height')>$iHeightMax)) {
return false;
}
$sFileFullPath=rtrim(Config::Get('path.root.server'),"/").'/'.trim($sDirDest,"/").'/'.$sFileDest;
$this->CreateDirectory($sDirDest);
if ($iWidthDest) {
if ($bForcedMinSize and ($iWidthDest>$oImage->get_image_params('width'))) {
@ -199,16 +197,13 @@ class ModuleImage extends Module {
if(isset($aParams['jpg_quality']) and $oImage->get_image_params('format')=='jpg') {
$oImage->set_jpg_quality($aParams['jpg_quality']);
}
$oImage->output(null,$sFileFullPath);
chmod($sFileFullPath,0666);
return $sFileFullPath;
} elseif (copy($sFileSrc,$sFileFullPath)) {
chmod($sFileFullPath,0666);
return $sFileFullPath;
$sFileTmp=Config::Get('sys.cache.dir').func_generator(20);
$oImage->output(null,$sFileTmp);
return $this->SaveFile($sFileTmp,$sDirDest,$sFileDest,0666,true);
} else{
return $this->SaveFile($sFileSrc,$sDirDest,$sFileDest,0666,false);
}
return false;
}
/**
@ -287,6 +282,48 @@ class ModuleImage extends Module {
*/
return $oImage;
}
/**
* Сохраняет(копирует) файл изображения
*
* @param $sFileSource Полный путь до исходного файла
* @param $sDirDest Каталог для сохранения файла относительно корня сайта
* @param $sFileDest
* @param null $iMode
* @param bool $bRemoveSource
* @return bool | string
*/
public function SaveFile($sFileSource,$sDirDest,$sFileDest,$iMode=null,$bRemoveSource=false) {
$sFileDestFullPath=rtrim(Config::Get('path.root.server'),"/").'/'.trim($sDirDest,"/").'/'.$sFileDest;
$this->CreateDirectory($sDirDest);
$bResult=copy($sFileSource,$sFileDestFullPath);
if ($bResult and !is_null($iMode)) {
chmod($sFileDestFullPath,$iMode);
}
if ($bRemoveSource) {
unlink($sFileSource);
}
/**
* Если копирование прошло успешно, возвращаем новый серверный путь до файла
*/
if ($bResult) {
return $sFileDestFullPath;
}
return false;
}
/**
* Удаление файла изображения
*
* @param $sFile
* @return bool
*/
public function RemoveFile($sFile) {
if (file_exists($sFile)) {
return unlink($sFile);
}
return false;
}
/**
* Создает каталог по указанному адресу (с учетом иерархии)
*