mirror of
https://github.com/Oreolek/ifhub.club.git
synced 2024-06-16 23:00:51 +03:00
Перевод модуля Media на работу с новой версией модуля Image + обновление fw
This commit is contained in:
parent
4e747e7b58
commit
802b14dff6
|
@ -231,62 +231,56 @@ class ModuleMedia extends ModuleORM {
|
|||
public function ProcessingFileImage($sFileTmp,$sTargetType,$sTargetId,$sTargetTmp=null) {
|
||||
$aPathInfo=pathinfo($sFileTmp);
|
||||
$aParams=$this->Image_BuildParams('media.'.$sTargetType);
|
||||
$oImage =$this->Image_CreateImageObject($sFileTmp);
|
||||
/**
|
||||
* Если объект изображения не создан, возвращаем ошибку
|
||||
*/
|
||||
if($sError=$oImage->get_last_error()) {
|
||||
@unlink($sFileTmp);
|
||||
return $sError;
|
||||
if(!$oImage=$this->Image_Open($sFileTmp,$aParams)) {
|
||||
$this->Fs_RemoveFileLocal($sFileTmp);
|
||||
return $this->Image_GetLastError();
|
||||
}
|
||||
/**
|
||||
* Превышает максимальные размеры из конфига
|
||||
*/
|
||||
if (($oImage->get_image_params('width')>Config::Get('module.media.image_max_width')) or ($oImage->get_image_params('height')>Config::Get('module.media.image_max_height'))) {
|
||||
@unlink($sFileTmp);
|
||||
return 'Превышен максимальный размер изображения';
|
||||
}
|
||||
$iWidth=$oImage->get_image_params('width');
|
||||
$iHeight=$oImage->get_image_params('height');
|
||||
$iWidth=$oImage->getWidth();
|
||||
$iHeight=$oImage->getHeight();
|
||||
|
||||
$sPath=$this->GetSaveDir($sTargetType,$sTargetId);
|
||||
if (!is_dir(Config::Get('path.root.server').$sPath)) {
|
||||
@mkdir(Config::Get('path.root.server').$sPath,0777,true);
|
||||
}
|
||||
/**
|
||||
* Копируем файл в нужный каталог
|
||||
* Уникальное имя файла
|
||||
*/
|
||||
$sFileName=func_generator(20);
|
||||
$sFilePath=Config::Get('path.root.server').$sPath.$sFileName.'.'.$oImage->get_image_params('format');
|
||||
rename($sFileTmp,$sFilePath);
|
||||
/**
|
||||
* Сохраняем оригинальную копию
|
||||
*/
|
||||
if (!$sFileResult=$oImage->saveSmart($sPath,$sFileName)) {
|
||||
$this->Fs_RemoveFileLocal($sFileTmp);
|
||||
return $this->Image_GetLastError();
|
||||
}
|
||||
|
||||
$aSizes=Config::Get("module.media.type.{$sTargetType}.image_sizes");
|
||||
if (!$aSizes) {
|
||||
$aSizes=Config::Get("module.media.image_sizes");
|
||||
}
|
||||
foreach ($aSizes as $aSize) {
|
||||
/**
|
||||
* Для каждого указанного в конфиге размера генерируем картинку
|
||||
*/
|
||||
$sNewFileName = $sFileName.'_'.$aSize['w'];
|
||||
$oImage = $this->Image_CreateImageObject($sFilePath);
|
||||
if ($aSize['crop']) {
|
||||
$this->Image_CropProportion($oImage, $aSize['w'], $aSize['h'], true);
|
||||
$sNewFileName .= 'crop';
|
||||
}
|
||||
$this->Image_Resize($sFilePath,$sPath,$sNewFileName,Config::Get('module.media.image_max_width'),Config::Get('module.media.image_max_height'),$aSize['w'],$aSize['h'],true,$aParams,$oImage);
|
||||
}
|
||||
/**
|
||||
* Генерируем варианты с необходимыми размерами
|
||||
*/
|
||||
$this->GenerateImageBySizes($sFileTmp,$sPath,$sFileName,$aSizes,$aParams);
|
||||
/**
|
||||
* Сохраняем медиа
|
||||
*/
|
||||
$oMedia=Engine::GetEntity('ModuleMedia_EntityMedia');
|
||||
$oMedia->setUserId($this->oUserCurrent ? $this->oUserCurrent->getId() : null);
|
||||
$oMedia->setType(self::TYPE_IMAGE);
|
||||
$oMedia->setFilePath($this->Image_GetWebPath($sFilePath));
|
||||
$oMedia->setFilePath($this->Fs_GetPathRelative($sFileResult,true));
|
||||
$oMedia->setFileName($aPathInfo['filename']);
|
||||
$oMedia->setFileSize(filesize($sFilePath));
|
||||
$oMedia->setFileSize(filesize($sFileTmp));
|
||||
$oMedia->setWidth($iWidth);
|
||||
$oMedia->setHeight($iHeight);
|
||||
$oMedia->setDataOne('image_sizes',$aSizes);
|
||||
/**
|
||||
* Теперь можно удалить временный файл
|
||||
*/
|
||||
$this->Fs_RemoveFileLocal($sFileTmp);
|
||||
/**
|
||||
* Добавляем в БД
|
||||
*/
|
||||
if ($oMedia->Add()) {
|
||||
/**
|
||||
* Создаем связь с владельцем
|
||||
|
@ -302,6 +296,35 @@ class ModuleMedia extends ModuleORM {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Создает набор отресайзанных изображений
|
||||
*
|
||||
* @param $sFileSource
|
||||
* @param $sDirDist
|
||||
* @param $sFileName
|
||||
* @param $aSizes
|
||||
* @param null $aParams
|
||||
*/
|
||||
public function GenerateImageBySizes($sFileSource,$sDirDist,$sFileName,$aSizes,$aParams=null) {
|
||||
if (!$aSizes) {
|
||||
return;
|
||||
}
|
||||
foreach ($aSizes as $aSize) {
|
||||
/**
|
||||
* Для каждого указанного в конфиге размера генерируем картинку
|
||||
*/
|
||||
$sNewFileName = $sFileName.'_'.$aSize['w'];
|
||||
if($oImage=$this->Image_Open($sFileSource,$aParams)) {
|
||||
if ($aSize['crop']) {
|
||||
$oImage->cropProportion($aSize['w']/$aSize['h'],'center');
|
||||
$sNewFileName .= 'crop';
|
||||
}
|
||||
if (!$oImage->resize($aSize['w'],$aSize['h'],true)->saveSmart($sDirDist,$sNewFileName)) {
|
||||
// TODO: прерывать и возвращать false?
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Возвращает каталог для сохранения контента медиа
|
||||
*
|
||||
|
@ -422,8 +445,12 @@ class ModuleMedia extends ModuleORM {
|
|||
if ($aSize['crop']) {
|
||||
$sSize.='crop';
|
||||
}
|
||||
$this->Image_RemoveFile($this->Image_GetServerPath($oMedia->getFileWebPath($sSize)));
|
||||
$this->Image_RemoveFile($this->GetImagePathBySize($oMedia->getFilePath(),$sSize));
|
||||
}
|
||||
/**
|
||||
* Удаляем оригинал
|
||||
*/
|
||||
$this->Image_RemoveFile($oMedia->getFilePath());
|
||||
}
|
||||
/**
|
||||
* Удаляем все связи
|
||||
|
@ -518,7 +545,18 @@ class ModuleMedia extends ModuleORM {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function GetImageWebPath($sPath,$sWidth=null) {
|
||||
$sPath=$this->Fs_GetPathWeb($sPath);
|
||||
if ($sWidth) {
|
||||
return $this->GetImagePathBySize($sPath,$sWidth);
|
||||
} else {
|
||||
return $sPath;
|
||||
}
|
||||
}
|
||||
public function GetImagePathBySize($sPath,$sSize) {
|
||||
$aPathInfo=pathinfo($sPath);
|
||||
return $aPathInfo['dirname'].'/'.$aPathInfo['filename'].'_'.$sSize.'.'.$aPathInfo['extension'];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
@ -36,14 +36,9 @@ class ModuleMedia_EntityMedia extends EntityORM {
|
|||
return true;
|
||||
}
|
||||
|
||||
public function getFileWebPath($sWidth = null) {
|
||||
public function getFileWebPath($sWidth=null) {
|
||||
if ($this->getFilePath()) {
|
||||
if ($sWidth) {
|
||||
$aPathInfo=pathinfo($this->getFilePath());
|
||||
return $aPathInfo['dirname'].'/'.$aPathInfo['filename'].'_'.$sWidth.'.'.$aPathInfo['extension'];
|
||||
} else {
|
||||
return $this->getFilePath();
|
||||
}
|
||||
return $this->Media_GetImageWebPath($this->getFilePath(),$sWidth);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -163,32 +163,7 @@ $config['module']['notify']['insert_single'] = false; // Если опция
|
|||
$config['module']['notify']['per_process'] = 10; // Количество отложенных заданий, обрабатываемых одним крон-процессом
|
||||
$config['module']['notify']['dir'] = 'emails'; // Путь до папки с емэйлами относительно шаблона
|
||||
$config['module']['notify']['prefix'] = 'email'; // Префикс шаблонов емэйлов
|
||||
// Модуль Image
|
||||
$config['module']['image']['default']['watermark_use'] = false;
|
||||
$config['module']['image']['default']['watermark_type'] = 'text';
|
||||
$config['module']['image']['default']['watermark_position'] = '0,24';
|
||||
$config['module']['image']['default']['watermark_text'] = '(c) LiveStreet';
|
||||
$config['module']['image']['default']['watermark_font'] = 'arial';
|
||||
$config['module']['image']['default']['watermark_font_color'] = '255,255,255';
|
||||
$config['module']['image']['default']['watermark_font_size'] = '10';
|
||||
$config['module']['image']['default']['watermark_font_alfa'] = '0';
|
||||
$config['module']['image']['default']['watermark_back_color'] = '0,0,0';
|
||||
$config['module']['image']['default']['watermark_back_alfa'] = '40';
|
||||
$config['module']['image']['default']['watermark_image'] = false;
|
||||
$config['module']['image']['default']['watermark_min_width'] = 200;
|
||||
$config['module']['image']['default']['watermark_min_height'] = 130;
|
||||
$config['module']['image']['default']['round_corner'] = false;
|
||||
$config['module']['image']['default']['round_corner_radius'] = '18';
|
||||
$config['module']['image']['default']['round_corner_rate'] = '40';
|
||||
$config['module']['image']['default']['path']['watermarks'] = '___path.framework.libs_vendor.server___/LiveImage/watermarks/';
|
||||
$config['module']['image']['default']['path']['fonts'] = '___path.framework.libs_vendor.server___/LiveImage/fonts/';
|
||||
$config['module']['image']['default']['jpg_quality'] = 95; // Число от 0 до 100
|
||||
|
||||
$config['module']['image']['foto']['watermark_use'] = false;
|
||||
$config['module']['image']['foto']['round_corner'] = false;
|
||||
|
||||
$config['module']['image']['topic']['watermark_use'] = false;
|
||||
$config['module']['image']['topic']['round_corner'] = false;
|
||||
// Модуль Security
|
||||
$config['module']['security']['hash'] = "livestreet_security_key"; // "примесь" к строке, хешируемой в качестве security-кода
|
||||
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 83b12a8a265377592dd86d9006e6a4e5a9ada789
|
||||
Subproject commit a1e83e2aaac77468a2d48a95c334689000faef4a
|
Loading…
Reference in a new issue