mirror of
https://github.com/Oreolek/ifhub.club.git
synced 2024-06-26 03:30:48 +03:00
Доработка вставки изображения по ссылке
This commit is contained in:
parent
f56d685062
commit
97ca8c0a2c
|
@ -221,9 +221,10 @@ class ActionAjax extends Action
|
|||
/**
|
||||
* Корректность ID вариантов
|
||||
*/
|
||||
$aAnswerItems = $this->Poll_GetAnswerItemsByFilter(array('id in' => $aAnswerIds,
|
||||
'poll_id' => $oPoll->getId()
|
||||
));
|
||||
$aAnswerItems = $this->Poll_GetAnswerItemsByFilter(array(
|
||||
'id in' => $aAnswerIds,
|
||||
'poll_id' => $oPoll->getId()
|
||||
));
|
||||
if (count($aAnswerItems) != count($aAnswerIds)) {
|
||||
return $this->EventErrorDebug();
|
||||
}
|
||||
|
@ -511,47 +512,64 @@ class ActionAjax extends Action
|
|||
return $this->EventErrorDebug();
|
||||
}
|
||||
/**
|
||||
* Проверяем корректность target'а
|
||||
* Необходимо выполнить загрузку файла
|
||||
*/
|
||||
$sTargetType = getRequestStr('target_type');
|
||||
$sTargetId = getRequestStr('target_id');
|
||||
if (getRequest('upload')) {
|
||||
/**
|
||||
* Проверяем корректность target'а
|
||||
*/
|
||||
$sTargetType = getRequestStr('target_type');
|
||||
$sTargetId = getRequestStr('target_id');
|
||||
|
||||
$sTargetTmp = empty($_COOKIE['media_target_tmp_' . $sTargetType]) ? getRequestStr('target_tmp') : $_COOKIE['media_target_tmp_' . $sTargetType];
|
||||
if ($sTargetId) {
|
||||
$sTargetTmp = null;
|
||||
if (true !== $res = $this->Media_CheckTarget($sTargetType, $sTargetId, ModuleMedia::TYPE_CHECK_ALLOW_ADD,
|
||||
array('user' => $this->oUserCurrent))
|
||||
$sTargetTmp = empty($_COOKIE['media_target_tmp_' . $sTargetType]) ? getRequestStr('target_tmp') : $_COOKIE['media_target_tmp_' . $sTargetType];
|
||||
if ($sTargetId) {
|
||||
$sTargetTmp = null;
|
||||
if (true !== $res = $this->Media_CheckTarget($sTargetType, $sTargetId,
|
||||
ModuleMedia::TYPE_CHECK_ALLOW_ADD,
|
||||
array('user' => $this->oUserCurrent))
|
||||
) {
|
||||
$this->Message_AddError(is_string($res) ? $res : $this->Lang_Get('system_error'),
|
||||
$this->Lang_Get('error'));
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
$sTargetId = null;
|
||||
if (!$sTargetTmp) {
|
||||
return $this->EventErrorDebug();
|
||||
}
|
||||
if (true !== $res = $this->Media_CheckTarget($sTargetType, null, ModuleMedia::TYPE_CHECK_ALLOW_ADD,
|
||||
array('user' => $this->oUserCurrent))
|
||||
) {
|
||||
$this->Message_AddError(is_string($res) ? $res : $this->Lang_Get('system_error'),
|
||||
$this->Lang_Get('error'));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Выполняем загрузку файла
|
||||
*/
|
||||
if ($mResult = $this->Media_UploadUrl($sUrl, $sTargetType, $sTargetId, $sTargetTmp) and is_object($mResult)
|
||||
) {
|
||||
$this->Message_AddError(is_string($res) ? $res : $this->Lang_Get('system_error'),
|
||||
$aParams = array(
|
||||
'align' => getRequestStr('align'),
|
||||
'title' => getRequestStr('title')
|
||||
);
|
||||
$this->Viewer_AssignAjax('sText', $this->Media_BuildCodeForEditor($mResult, $aParams));
|
||||
} else {
|
||||
$this->Message_AddError(is_string($mResult) ? $mResult : $this->Lang_Get('system_error'),
|
||||
$this->Lang_Get('error'));
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
$sTargetId = null;
|
||||
if (!$sTargetTmp) {
|
||||
return $this->EventErrorDebug();
|
||||
}
|
||||
if (true !== $res = $this->Media_CheckTarget($sTargetType, null, ModuleMedia::TYPE_CHECK_ALLOW_ADD,
|
||||
array('user' => $this->oUserCurrent))
|
||||
) {
|
||||
$this->Message_AddError(is_string($res) ? $res : $this->Lang_Get('system_error'),
|
||||
$this->Lang_Get('error'));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Выполняем загрузку файла
|
||||
*/
|
||||
if ($mResult = $this->Media_UploadUrl($sUrl, $sTargetType, $sTargetId, $sTargetTmp) and is_object($mResult)) {
|
||||
/**
|
||||
* Формируем параметры для билдера HTML
|
||||
*/
|
||||
$aParams = array(
|
||||
'align' => getRequestStr('align'),
|
||||
'title' => getRequestStr('title')
|
||||
'align' => getRequestStr('align'),
|
||||
'title' => getRequestStr('title'),
|
||||
'image_url' => $sUrl
|
||||
);
|
||||
$this->Viewer_AssignAjax('sText', $this->Media_BuildCodeForEditor($mResult, $aParams));
|
||||
} else {
|
||||
$this->Message_AddError(is_string($mResult) ? $mResult : $this->Lang_Get('system_error'),
|
||||
$this->Lang_Get('error'));
|
||||
$this->Viewer_AssignAjax('sText', $this->Media_BuildImageCodeForEditor($aParams));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1984,7 +2002,7 @@ class ActionAjax extends Action
|
|||
|
||||
$oViewerLocal->Assign('oComment', $oComment, true);
|
||||
$sHtml = $oViewerLocal->Fetch($this->Comment_GetTemplateCommentByTarget($oComment->getTargetId(),
|
||||
$oComment->getTargetType()));
|
||||
$oComment->getTargetType()));
|
||||
$this->Viewer_AssignAjax('sHtml', $sHtml);
|
||||
} else {
|
||||
return $this->EventErrorDebug();
|
||||
|
|
|
@ -520,47 +520,63 @@ class ModuleMedia extends ModuleORM
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
$sPath = $oMedia->getFileWebPath($sSize == 'original' ? null : $sSize);
|
||||
|
||||
$sCode = '<img src="' . $sPath . '" ';
|
||||
$aParams['image_url'] = $sPath;
|
||||
$aParams['href_url'] = $oMedia->getFileWebPath();
|
||||
$aParams['need_href'] = $bNeedHref;
|
||||
if (!isset($aParams['title'])) {
|
||||
$aParams['title'] = $oMedia->getDataOne('title');
|
||||
}
|
||||
if (!isset($aParams['skip_title']) and $aParams['title']) {
|
||||
$sCode .= ' title="' . htmlspecialchars($aParams['title']) . '" ';
|
||||
$sCode .= ' alt="' . htmlspecialchars($aParams['title']) . '" ';
|
||||
}
|
||||
if (isset($aParams['align']) and in_array($aParams['align'], array('left', 'right', 'center'))) {
|
||||
if ($aParams['align'] == 'center') {
|
||||
$sCode .= ' class="image-center"';
|
||||
} else {
|
||||
$sCode .= ' align="' . htmlspecialchars($aParams['align']) . '" ';
|
||||
}
|
||||
}
|
||||
$sDataParams = '';
|
||||
if (isset($aParams['data']) and is_array($aParams['data'])) {
|
||||
foreach ($aParams['data'] as $sDataName => $sDataValue) {
|
||||
if ($sDataValue) {
|
||||
$sDataParams .= ' data-' . $sDataName . '="' . htmlspecialchars($sDataValue) . '"';
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($bNeedHref) {
|
||||
$sCode .= ' />';
|
||||
$sLbxGroup = '';
|
||||
if (isset($aParams['lbx_group'])) {
|
||||
$sLbxGroup = ' data-rel="' . htmlspecialchars($aParams['lbx_group']) . '"';
|
||||
}
|
||||
$sCode = '<a class="js-lbx" ' . $sLbxGroup . ' href="' . $oMedia->getFileWebPath() . '" ' . $sDataParams . '>' . $sCode . '</a>';
|
||||
} else {
|
||||
$sCode .= $sDataParams . ' />';
|
||||
}
|
||||
/**
|
||||
* Формируем HTML изображения
|
||||
*/
|
||||
$sCode = $this->BuildImageCodeForEditor($aParams);
|
||||
}
|
||||
|
||||
return $sCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Формирует HTML изображения
|
||||
*
|
||||
* @param $aParams
|
||||
* @return string
|
||||
*/
|
||||
public function BuildImageCodeForEditor($aParams)
|
||||
{
|
||||
$sCode = '<img src="' . htmlspecialchars($aParams['image_url']) . '" ';
|
||||
if (!isset($aParams['skip_title']) and isset($aParams['title']) and $aParams['title']) {
|
||||
$sCode .= ' title="' . htmlspecialchars($aParams['title']) . '" ';
|
||||
$sCode .= ' alt="' . htmlspecialchars($aParams['title']) . '" ';
|
||||
}
|
||||
if (isset($aParams['align']) and in_array($aParams['align'], array('left', 'right', 'center'))) {
|
||||
if ($aParams['align'] == 'center') {
|
||||
$sCode .= ' class="image-center"';
|
||||
} else {
|
||||
$sCode .= ' align="' . htmlspecialchars($aParams['align']) . '" ';
|
||||
}
|
||||
}
|
||||
$sDataParams = '';
|
||||
if (isset($aParams['data']) and is_array($aParams['data'])) {
|
||||
foreach ($aParams['data'] as $sDataName => $sDataValue) {
|
||||
if ($sDataValue) {
|
||||
$sDataParams .= ' data-' . $sDataName . '="' . htmlspecialchars($sDataValue) . '"';
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isset($aParams['need_href']) and $aParams['need_href']) {
|
||||
$sCode .= ' />';
|
||||
$sLbxGroup = '';
|
||||
if (isset($aParams['lbx_group'])) {
|
||||
$sLbxGroup = ' data-rel="' . htmlspecialchars($aParams['lbx_group']) . '"';
|
||||
}
|
||||
$sCode = '<a class="js-lbx" ' . $sLbxGroup . ' href="' . htmlspecialchars($aParams['href_url']) . '" ' . $sDataParams . '>' . $sCode . '</a>';
|
||||
} else {
|
||||
$sCode .= $sDataParams . ' />';
|
||||
}
|
||||
return $sCode;
|
||||
}
|
||||
|
||||
public function GetMediaByTarget($sTargetType, $iTargetId, $iUserId = null)
|
||||
{
|
||||
return $this->oMapper->GetMediaByTarget($sTargetType, $iTargetId, $iUserId);
|
||||
|
@ -711,9 +727,9 @@ class ModuleMedia extends ModuleORM
|
|||
$aMediaIds[] = $oMediaItem->getId();
|
||||
}
|
||||
$aTargetItems = $this->GetTargetItemsByFilter(array(
|
||||
'media_id in' => $aMediaIds,
|
||||
'#index-group' => 'media_id'
|
||||
));
|
||||
'media_id in' => $aMediaIds,
|
||||
'#index-group' => 'media_id'
|
||||
));
|
||||
/**
|
||||
* Удаляем медиа данные без оставшихся связей
|
||||
*/
|
||||
|
@ -745,7 +761,7 @@ class ModuleMedia extends ModuleORM
|
|||
*/
|
||||
if ($this->GetConfigParam('image.autoresize',
|
||||
$oMedia->getTargetType()) and !$this->Image_IsExistsFile($this->GetImagePathBySize($oMedia->getFilePath(),
|
||||
$sSize))
|
||||
$sSize))
|
||||
) {
|
||||
/**
|
||||
* Запускаем генерацию изображения нужного размера
|
||||
|
|
Loading…
Reference in a new issue