1
0
Fork 0
mirror of https://github.com/Oreolek/ifhub.club.git synced 2024-06-26 03:30:48 +03:00
Conflicts:
	application/frontend/skin/developer/components/field/js/field.image-ajax.js
This commit is contained in:
Denis Shakhov 2015-01-27 21:10:16 +07:00
commit 2207f1369a
10 changed files with 110 additions and 42 deletions

View file

@ -750,7 +750,11 @@ class ActionAjax extends Action
$aMediaItems = array();
if ($sId) {
$aMediaItems = $this->Media_GetMediaByTarget($sType, $sId, $this->oUserCurrent->getId());
if (!$this->Media_CheckTarget($sType, $sId, ModuleMedia::TYPE_CHECK_ALLOW_VIEW_LIST)) {
$this->Message_AddErrorSingle($this->Lang_Get('not_access'), $this->Lang_Get('error'));
return;
}
$aMediaItems = $this->Media_GetMediaByTarget($sType, $sId);
} elseif ($sTmp) {
$aMediaItems = $this->Media_GetMediaByTargetTmp($sTmp, $this->oUserCurrent->getId());
}
@ -801,13 +805,7 @@ class ActionAjax extends Action
$aIds[] = (int)$iId;
}
$iUserId = $this->oUserCurrent ? $this->oUserCurrent->getId() : null;
$aMediaItems = $this->Media_GetMediaItemsByFilter(array(
'#where' => array('id in (?a) AND ( user_id is null OR user_id = ?d )' => array($aIds, $iUserId))
)
);
if (!$aMediaItems) {
if (!($aMediaItems = $this->Media_GetAllowMediaItemsById($aIds))) {
$this->Message_AddError('Необходимо выбрать элементы');
return false;
}

View file

@ -39,7 +39,8 @@ class ModuleMedia extends ModuleORM
const TYPE_CHECK_ALLOW_ADD = 'add';
const TYPE_CHECK_ALLOW_REMOVE = 'remove';
const TYPE_CHECK_ALLOW_UPDATE = 'update';
const TYPE_CHECK_ALLOW_PREVIEW = 'preview';
const TYPE_CHECK_ALLOW_PREVIEW = 'preview'; // возможность создания превью для объекта
const TYPE_CHECK_ALLOW_VIEW_LIST = 'view_list'; // просмотр списка медиа у объекта
/**
* Объект текущего пользователя
*
@ -605,7 +606,9 @@ class ModuleMedia extends ModuleORM
/**
* Возвращает список media с учетов прав доступа текущего пользователя
*
* В методе происходит проверка на права:
* 1. разрешаем объекты, которые создал пользователь
* 2. разрешаем объекты, которые связаны таргетом, к которому у пользователя есть доступ на редактирование
* @param array $aId
*
* @return array
@ -616,18 +619,64 @@ class ModuleMedia extends ModuleORM
foreach ((array)$aId as $iId) {
$aIdItems[] = (int)$iId;
}
$aIdItemsAll = $aIdItems;
if (is_array($aIdItems) and count($aIdItems)) {
$iUserId = $this->oUserCurrent ? $this->oUserCurrent->getId() : null;
return $this->Media_GetMediaItemsByFilter(array(
$aMediaItems = $this->Media_GetMediaItemsByFilter(array(
'#where' => array(
'id in (?a) AND ( user_id is null OR user_id = ?d )' => array(
$aIdItems,
$iUserId
)
)
),
'#index-from-primary'
)
);
/**
* Смотрим что осталось
*/
if (!is_null($iUserId) and $aIdItems = array_diff($aIdItems, array_keys($aMediaItems))) {
$aMediaAllowIds = array();
$aTargetMediaGroup = $this->GetTargetItemsByFilter(array(
'media_id in' => $aIdItems,
'#index-group' => 'media_id'
));
$_this = $this;
foreach ($aTargetMediaGroup as $iMediaId => $aTargetMedia) {
/**
* Проверяем каждый таргет
*/
foreach ($aTargetMedia as $oTargetMedia) {
if ($this->Cache_Remember("media_check_target_{$oTargetMedia->getTargetType()}_{$oTargetMedia->getTargetId()}",
function () use ($_this, $oTargetMedia) {
return $_this->CheckTarget($oTargetMedia->getTargetType(), $oTargetMedia->getTargetId(),
self::TYPE_CHECK_ALLOW_ADD);
}, false, array(), 'life', true)
) {
$aMediaAllowIds[] = $oTargetMedia->getMediaId();
break;
}
}
}
if ($aMediaAllowIds) {
$aMediaItems = $aMediaItems + $this->GetMediaItemsByFilter(array(
'id in' => $aMediaAllowIds,
'#index-from-primary'
));
}
}
/**
* Нужно отсортировать по первоначальному массиву $aIdItems
*/
$aReturn = array();
foreach ($aIdItemsAll as $iId) {
if (isset($aMediaItems[$iId])) {
$aReturn[$iId] = $aMediaItems[$iId];
}
}
return $aReturn;
}
return array();
}
@ -646,9 +695,12 @@ class ModuleMedia extends ModuleORM
{
if (isset($aParams['items'])) {
$aItems = explode(',', $aParams['items']);
$aItems = array_unique($aItems);
} else {
return '';
}
if (!(isset($aItems) and $aMediaItems = $this->Media_GetAllowMediaItemsById($aItems))) {
if (!($aMediaItems = $this->GetAllowMediaItemsById($aItems))) {
return '';
}
@ -665,7 +717,7 @@ class ModuleMedia extends ModuleORM
if (isset($aParams['caption']) and $aParams['caption']) {
$aParamsMedia['data']['caption'] = htmlspecialchars($oMedia->getDataOne('title'));
}
$sTextResult .= "\t" . $this->Media_BuildCodeForEditor($oMedia, $aParamsMedia) . "\r\n";
$sTextResult .= "\t" . $this->BuildCodeForEditor($oMedia, $aParamsMedia) . "\r\n";
}
$sTextResult .= "</div>\r\n";
return $sTextResult;
@ -1068,7 +1120,8 @@ class ModuleMedia extends ModuleORM
if (!$oUser = $aParams['user']) {
return false;
}
if (in_array($sAllowType, array(self::TYPE_CHECK_ALLOW_ADD, self::TYPE_CHECK_ALLOW_PREVIEW))) {
if (in_array($sAllowType,
array(self::TYPE_CHECK_ALLOW_ADD, self::TYPE_CHECK_ALLOW_PREVIEW, self::TYPE_CHECK_ALLOW_VIEW_LIST))) {
if (is_null($iTargetId)) {
/**
* Разрешаем для всех новых топиков
@ -1104,7 +1157,7 @@ class ModuleMedia extends ModuleORM
if (!$oUser = $aParams['user']) {
return false;
}
if ($sAllowType == self::TYPE_CHECK_ALLOW_ADD) {
if (in_array($sAllowType, array(self::TYPE_CHECK_ALLOW_ADD, self::TYPE_CHECK_ALLOW_VIEW_LIST))) {
if (is_null($iTargetId)) {
/**
* Разрешаем для всех новых комментариев
@ -1140,7 +1193,7 @@ class ModuleMedia extends ModuleORM
if (!$oUser = $aParams['user']) {
return false;
}
if ($sAllowType == self::TYPE_CHECK_ALLOW_ADD) {
if (in_array($sAllowType, array(self::TYPE_CHECK_ALLOW_ADD, self::TYPE_CHECK_ALLOW_VIEW_LIST))) {
if (is_null($iTargetId)) {
/**
* Разрешаем для всех новых блогов
@ -1176,10 +1229,10 @@ class ModuleMedia extends ModuleORM
if (!$oUser = $aParams['user']) {
return false;
}
if ($sAllowType == self::TYPE_CHECK_ALLOW_ADD) {
if (in_array($sAllowType, array(self::TYPE_CHECK_ALLOW_ADD, self::TYPE_CHECK_ALLOW_VIEW_LIST))) {
if (is_null($iTargetId)) {
/**
* Разрешаем для всех новых блогов
* Разрешаем для всех новых сообщений
*/
return true;
}

View file

@ -11,7 +11,7 @@
{block 'layout_content'}
{* Топик *}
{component 'topic' topic=$topic}
{component 'topic' template='topic-type' topic=$topic}
{* Комментарии *}
{component 'comment' template='comments'

View file

@ -62,7 +62,7 @@ $.widget( "livestreet.lsEditorMarkup", {
{ name: ls.lang.get('panel_clear_tags'), className: 'editor-clean', replaceWith: function( markitup ) { return markitup.selection.replace(/<(.*?)>/g, "") } }
]
}
},
}
},
/**

View file

@ -20,7 +20,7 @@
urls: {
create: aRouter['ajax'] + 'media/create-preview-file/',
remove: aRouter['ajax'] + 'media/remove-preview-file/',
load: aRouter['ajax'] + 'media/load-preview-items/',
load: aRouter['ajax'] + 'media/load-preview-items/'
},
// Селекторы
selectors: {
@ -29,7 +29,7 @@
image: '.js-field-image-ajax-image',
modal: '.js-field-image-ajax-modal',
uploader: '.js-field-image-ajax-modal .js-uploader-modal',
choose: '.js-field-image-ajax-modal .js-uploader-modal-choose',
choose: '.js-field-image-ajax-modal .js-uploader-modal-choose'
},
params: {}
},
@ -48,6 +48,8 @@
this.elements.modal.lsModal({
aftershow: function () {
_this.elements.uploader.lsUploader( 'getElement', 'list' ).lsUploaderFileList( 'load' );
// т.к. генерация происходит после инициализации
_this._setParam( 'target_tmp', _this.elements.uploader.lsUploader( 'option', 'params.target_tmp' ) );
}
});
@ -63,7 +65,6 @@
this.elements.remove.on( 'click' + this.eventNamespace, this.remove.bind( this ) );
this.elements.choose.on( 'click' + this.eventNamespace, this.createPreview.bind( this ) );
this._setParam( 'target_tmp', this.elements.uploader.lsUploader( 'option', 'params.target_tmp' ) );
},
/**
@ -102,6 +103,6 @@
this._load( 'load', function( response ) {
this.elements.image.removeClass( 'loading' ).show().html( $.trim( response.sTemplatePreview ) );
});
},
}
});
})(jQuery);

View file

@ -30,7 +30,7 @@
// Загрузка файла по ссылке
url_upload: aRouter.ajax + 'media/upload-link/',
// Вставка файла по ссылке
url_insert: aRouter.ajax + 'media/upload-insert/',
url_insert: aRouter.ajax + 'media/upload-insert/'
},
// Селекторы
@ -86,7 +86,7 @@
submit_upload: this.element.find( this.option( 'selectors.url.submit_upload' ) ),
submit_insert: this.element.find( this.option( 'selectors.url.submit_insert' ) ),
image_preview: this.element.find( this.option( 'selectors.url.image_preview' ) )
},
}
};
this.elements.url.blocks = this.elements.url.block_container.find( this.option( 'selectors.block' ) );
@ -301,6 +301,6 @@
validate: false,
submitButton: this.elements.url[ upload ? 'submit_upload' : 'submit_insert' ]
});
},
}
});
})(jQuery);

View file

@ -9,7 +9,7 @@
{$type = $topic->getType()}
{if $LS->Topic_IsAllowTopicType( $type )}
{$template = "./topic.type.{$type}.tpl"}
{$template = $smarty.current_dir|cat:"/topic.type.{$type}.tpl"}
{* Если для указанного типа существует шаблон, то подключаем его *}
{* Иначе подключаем дефолтный шаблон топика *}

View file

@ -21,7 +21,7 @@
// Загрузка файла
upload: aRouter['ajax'] + 'media/upload/',
// Генерация временного хэша
generate_target_tmp: aRouter['ajax'] + 'media/generate-target-tmp/',
generate_target_tmp: aRouter['ajax'] + 'media/generate-target-tmp/'
},
// Селекторы
@ -42,7 +42,7 @@
// Drag & drop зона
upload_zone: '.js-uploader-area',
// Инпут
upload_input: '.js-uploader-file',
upload_input: '.js-uploader-file'
},
// Классы
@ -86,8 +86,14 @@
// Получение параметров
this.option( 'params', $.extend( {}, this.option( 'params' ), ls.utils.getDataOptions( this.element, 'param' ) ) );
// Генерация временного хэша для привязки
// TODO: Перенести в media
/**
* Генерация временного хэша для привязки
* TODO: Перенести в media
*
* Может быть ситуация, когда на странице несколько аплоадеров для одного типа таргета медиа
* В итоге они все делают запрос на получение временного ключа и перезаписывают его
* Нужно использовать внешний триггер для фиксации первого запроса
*/
if ( ! this.option( 'params.target_id' ) ) {
this.option( 'params.target_tmp', this.element.data( 'tmp' ) || $.cookie( 'media_target_tmp_' + this.option( 'params.target_type' ) ) );
@ -186,13 +192,23 @@
/**
* Генерация хэша для привязки к нему загруженных файлов
* Суть в том, чтобы не делать несколько запросов на генерацию для одного типа (когда на одной странице несколько аплоадеров)
*/
generateTargetTmp: function() {
ls.ajax.load( this.option( 'urls.generate_target_tmp' ), {
type: this.option( 'params.target_type' )
}, function( response ) {
this.option( 'params.target_tmp', response.sTmpKey || null );
}.bind( this ));
var key='ls.media.target_tmp_create_request_' + this.option( 'params.target_type' );
if (ls.registry.get(key)) {
$(window).bind(key, function(e, sTmpKey){
this.option( 'params.target_tmp', sTmpKey || null );
}.bind( this ));
} else {
ls.registry.set(key, true);
ls.ajax.load( this.option( 'urls.generate_target_tmp' ), {
type: this.option( 'params.target_type' )
}, function( response ) {
$(window).trigger(key,[response.sTmpKey]);
this.option( 'params.target_tmp', response.sTmpKey || null );
}.bind( this ));
}
},
/**
@ -239,6 +255,6 @@
*/
getElement: function( name ) {
return this.elements[ name ];
},
}
});
})(jQuery);

View file

@ -127,7 +127,7 @@ return array(
'errors' => array(
'db_connect' => 'Не удалось установить соединение с БД. Проверьте параметры подключения к БД.',
'db_version' => 'Версия сервера БД должна быть от 5.0.0',
'db_query' => 'Неудалось выполнить запрос к БД',
'db_query' => 'Не удалось выполнить запрос к БД',
),
),
'console' => array(
@ -144,4 +144,4 @@ return array(
'install_reset' => 'Начать сначала',
'yes' => 'Да',
'no' => 'Нет',
);
);

@ -1 +1 @@
Subproject commit 73037ec28e48d9e1cd7c648386d822cf68971fcc
Subproject commit 0d4967faa800171b82cc82ec4f11f4eef2464272