2010-09-26 19:23:23 +03:00
< ? php
/*-------------------------------------------------------
*
* LiveStreet Engine Social Networking
* Copyright © 2008 Mzhelskiy Maxim
*
*--------------------------------------------------------
*
* Official site : www . livestreet . ru
* Contact e - mail : rus . engine @ gmail . com
*
* GNU General Public License , version 2 :
* http :// www . gnu . org / licenses / old - licenses / gpl - 2.0 . html
*
---------------------------------------------------------
*/
/**
2012-04-29 17:58:36 +03:00
* Экшен обработки ajax запросов
* Ответ отдает в JSON фомате
2010-09-26 19:23:23 +03:00
*
2012-04-29 17:58:36 +03:00
* @ package actions
* @ since 1.0
2010-09-26 19:23:23 +03:00
*/
2011-06-06 14:58:19 +03:00
class ActionAjax extends Action {
2012-04-29 17:58:36 +03:00
/**
* Текущий пользователь
*
* @ var ModuleUser_EntityUser | null
*/
protected $oUserCurrent = null ;
/**
* Инициализация
*/
2010-09-26 19:23:23 +03:00
public function Init () {
2012-04-29 17:58:36 +03:00
/**
* Устанавливаем формат ответа
*/
2010-09-26 19:23:23 +03:00
$this -> Viewer_SetResponseAjax ( 'json' );
2012-04-29 17:58:36 +03:00
/**
* Получаем текущего пользователя
*/
2010-09-26 19:23:23 +03:00
$this -> oUserCurrent = $this -> User_GetUserCurrent ();
}
2012-04-29 17:58:36 +03:00
/**
* Регистрация евентов
*/
2011-06-06 14:58:19 +03:00
protected function RegisterEvent () {
2010-09-26 19:23:23 +03:00
$this -> AddEventPreg ( '/^vote$/i' , '/^comment$/' , 'EventVoteComment' );
$this -> AddEventPreg ( '/^vote$/i' , '/^topic$/' , 'EventVoteTopic' );
$this -> AddEventPreg ( '/^vote$/i' , '/^blog$/' , 'EventVoteBlog' );
$this -> AddEventPreg ( '/^vote$/i' , '/^user$/' , 'EventVoteUser' );
2014-01-30 11:51:14 +02:00
$this -> AddEventPreg ( '/^vote$/i' , '/^get$/' , '/^info$/' , '/^topic$/' , 'EventVoteGetInfoTopic' );
2011-06-06 14:58:19 +03:00
2012-03-27 13:45:52 +03:00
$this -> AddEventPreg ( '/^favourite$/i' , '/^save-tags/' , 'EventFavouriteSaveTags' );
2010-09-26 20:15:49 +03:00
$this -> AddEventPreg ( '/^favourite$/i' , '/^topic$/' , 'EventFavouriteTopic' );
$this -> AddEventPreg ( '/^favourite$/i' , '/^comment$/' , 'EventFavouriteComment' );
$this -> AddEventPreg ( '/^favourite$/i' , '/^talk$/' , 'EventFavouriteTalk' );
2011-06-06 14:58:19 +03:00
2010-10-02 13:56:46 +03:00
$this -> AddEventPreg ( '/^stream$/i' , '/^comment$/' , 'EventStreamComment' );
$this -> AddEventPreg ( '/^stream$/i' , '/^topic$/' , 'EventStreamTopic' );
2011-06-06 14:58:19 +03:00
2010-10-02 13:56:46 +03:00
$this -> AddEventPreg ( '/^blogs$/i' , '/^top$/' , 'EventBlogsTop' );
$this -> AddEventPreg ( '/^blogs$/i' , '/^self$/' , 'EventBlogsSelf' );
$this -> AddEventPreg ( '/^blogs$/i' , '/^join$/' , 'EventBlogsJoin' );
2013-04-12 06:44:36 +03:00
$this -> AddEventPreg ( '/^blogs$/i' , '/^get-by-category$/' , 'EventBlogsGetByCategory' );
2011-06-06 14:58:19 +03:00
2010-10-02 17:33:51 +03:00
$this -> AddEventPreg ( '/^preview$/i' , '/^text$/' , 'EventPreviewText' );
2011-06-06 14:58:19 +03:00
2010-10-03 14:47:14 +03:00
$this -> AddEventPreg ( '/^autocompleter$/i' , '/^tag$/' , 'EventAutocompleterTag' );
$this -> AddEventPreg ( '/^autocompleter$/i' , '/^user$/' , 'EventAutocompleterUser' );
2011-06-06 14:58:19 +03:00
2010-10-03 15:48:39 +03:00
$this -> AddEventPreg ( '/^comment$/i' , '/^delete$/' , 'EventCommentDelete' );
2012-03-23 06:46:13 +02:00
2013-12-25 14:19:33 +02:00
$this -> AddEventPreg ( '/^geo$/i' , '/^get/' , '/^regions$/' , 'EventGeoGetRegions' );
$this -> AddEventPreg ( '/^geo$/i' , '/^get/' , '/^cities$/' , 'EventGeoGetCities' );
2012-03-29 09:23:13 +03:00
2013-12-25 14:19:33 +02:00
$this -> AddEventPreg ( '/^infobox$/i' , '/^info$/' , '/^blog$/' , 'EventInfoboxInfoBlog' );
$this -> AddEventPreg ( '/^media$/i' , '/^upload$/' , '/^$/' , 'EventMediaUpload' );
2014-01-06 16:52:49 +02:00
$this -> AddEventPreg ( '/^media$/i' , '/^upload-link$/' , '/^$/' , 'EventMediaUploadLink' );
2013-12-25 14:19:33 +02:00
$this -> AddEventPreg ( '/^media$/i' , '/^generate-target-tmp$/' , '/^$/' , 'EventMediaGenerateTargetTmp' );
$this -> AddEventPreg ( '/^media$/i' , '/^submit-insert$/' , '/^$/' , 'EventMediaSubmitInsert' );
$this -> AddEventPreg ( '/^media$/i' , '/^submit-create-photoset$/' , '/^$/' , 'EventMediaSubmitCreatePhotoset' );
$this -> AddEventPreg ( '/^media$/i' , '/^load-gallery$/' , '/^$/' , 'EventMediaLoadGallery' );
$this -> AddEventPreg ( '/^media$/i' , '/^remove-file$/' , '/^$/' , 'EventMediaRemoveFile' );
2013-12-30 19:09:13 +02:00
$this -> AddEventPreg ( '/^media$/i' , '/^save-data-file$/' , '/^$/' , 'EventMediaSaveDataFile' );
2014-01-08 13:15:46 +02:00
$this -> AddEventPreg ( '/^property$/i' , '/^tags$/' , '/^autocompleter$/' , '/^$/' , 'EventPropertyTagsAutocompleter' );
2014-01-25 15:20:02 +02:00
$this -> AddEventPreg ( '/^validate$/i' , '/^captcha$/' , '/^$/' , 'EventValidateCaptcha' );
2014-02-04 15:48:53 +02:00
$this -> AddEventPreg ( '/^poll$/i' , '/^modal-create$/' , '/^$/' , 'EventPollModalCreate' );
$this -> AddEventPreg ( '/^poll$/i' , '/^modal-update/' , '/^$/' , 'EventPollModalUpdate' );
$this -> AddEventPreg ( '/^poll$/i' , '/^create$/' , '/^$/' , 'EventPollCreate' );
$this -> AddEventPreg ( '/^poll$/i' , '/^update$/' , '/^$/' , 'EventPollUpdate' );
$this -> AddEventPreg ( '/^poll$/i' , '/^remove$/' , '/^$/' , 'EventPollRemove' );
2014-02-05 15:06:04 +02:00
$this -> AddEventPreg ( '/^poll$/i' , '/^vote$/' , '/^$/' , 'EventPollVote' );
2010-09-26 19:23:23 +03:00
}
2011-06-06 14:58:19 +03:00
2010-09-26 19:23:23 +03:00
/**********************************************************************************
************************ РЕАЛИЗАЦИЯ ЭКШЕНА ***************************************
**********************************************************************************
2011-06-06 14:58:19 +03:00
*/
2014-02-05 15:06:04 +02:00
protected function EventPollVote () {
if ( ! $this -> oUserCurrent ) {
return $this -> EventErrorDebug ();
}
if ( ! $oPoll = $this -> Poll_GetPollById ( getRequestStr ( 'id' ))) {
return $this -> EventErrorDebug ();
}
/**
* Истекло время голосования ?
*/
if ( ! $oPoll -> isAllowVote ()) {
$this -> Message_AddErrorSingle ( 'В этом опросе уже нельзя голосовать' );
return ;
}
/**
* Пользователь уже голосовал ?
*/
if ( $this -> Poll_GetVoteByUserIdAndPollId ( $this -> oUserCurrent -> getId (), $oPoll -> getId ())) {
$this -> Message_AddErrorSingle ( 'Вы уже голосовали' );
return ;
}
$aAnswerIds = array ();
$aAnswerItems = array ();
if ( ! getRequest ( 'abstain' )) {
/**
* Проверяем варианты ответов
*/
if ( ! $aAnswer = ( array ) getRequest ( 'answers' )) {
$this -> Message_AddErrorSingle ( 'Необходимо выбрать вариант' );
return ;
}
foreach ( $aAnswer as $iAnswerId ) {
if ( ! is_numeric ( $iAnswerId )) {
return $this -> EventErrorDebug ();
}
$aAnswerIds [] = $iAnswerId ;
}
/**
* Корректность ID вариантов
*/
$aAnswerItems = $this -> Poll_GetAnswerItemsByFilter ( array ( 'id in' => $aAnswerIds , 'poll_id' => $oPoll -> getId ()));
if ( count ( $aAnswerItems ) != count ( $aAnswerIds )) {
return $this -> EventErrorDebug ();
}
}
/**
* Голосуем
*/
$oVote = Engine :: GetEntity ( 'ModulePoll_EntityVote' );
$oVote -> setPollId ( $oPoll -> getId ());
$oVote -> setPoll ( $oPoll ); // для быстродействия/оптимизации
$oVote -> setUserId ( $this -> oUserCurrent -> getId ());
$oVote -> setAnswers ( $aAnswerIds );
$oVote -> setAnswersObject ( $aAnswerItems ); // передаем для быстродействия, чтобы не запрашивать варианты еще раз после сохранения голоса
if ( $oVote -> Add ()) {
$oViewer = $this -> Viewer_GetLocalViewer ();
$oViewer -> Assign ( 'oPoll' , $oPoll );
$this -> Viewer_AssignAjax ( 'sText' , $oViewer -> Fetch ( " polls/poll.result.tpl " ));
} else {
return $this -> EventErrorDebug ();
}
}
2014-02-04 15:48:53 +02:00
protected function EventPollCreate () {
if ( ! $this -> oUserCurrent ) {
2014-02-05 15:06:04 +02:00
return $this -> EventErrorDebug ();
2014-02-04 15:48:53 +02:00
}
/**
* Создаем
*/
$oPoll = Engine :: GetEntity ( 'ModulePoll_EntityPoll' );
$oPoll -> _setValidateScenario ( 'create' );
$oPoll -> _setDataSafe ( getRequest ( 'poll' ));
$oPoll -> setAnswersRaw ( getRequest ( 'answers' ));
$oPoll -> setTargetRaw ( getRequest ( 'target' ));
$oPoll -> setUserId ( $this -> oUserCurrent -> getId ());
if ( $oPoll -> _Validate ()) {
if ( $oPoll -> Add ()) {
$oViewer = $this -> Viewer_GetLocalViewer ();
$oViewer -> Assign ( 'oPoll' , $oPoll );
$this -> Viewer_AssignAjax ( 'sPollItem' , $oViewer -> Fetch ( " polls/poll.form.item.tpl " ));
return true ;
} else {
$this -> Message_AddError ( $this -> Lang_Get ( 'common.error.save' ), $this -> Lang_Get ( 'error' ));
}
} else {
$this -> Message_AddError ( $oPoll -> _getValidateError (), $this -> Lang_Get ( 'error' ));
}
}
protected function EventPollUpdate () {
if ( ! $this -> oUserCurrent ) {
2014-02-05 15:06:04 +02:00
return $this -> EventErrorDebug ();
2014-02-04 15:48:53 +02:00
}
if ( ! $oPoll = $this -> Poll_GetPollById ( getRequestStr ( 'poll_id' ))) {
return $this -> EventErrorDebug ();
}
/**
* Проверяем корректность target ' а
*/
if ( $oPoll -> getTargetId ()) {
if ( ! $this -> Poll_CheckTarget ( $oPoll -> getTargetType (), $oPoll -> getTargetId ())) {
return $this -> EventErrorDebug ();
}
} else {
$sTarget = isset ( $_REQUEST [ 'target' ][ 'tmp' ]) ? $_REQUEST [ 'target' ][ 'tmp' ] : '' ;
if ( ! $this -> Poll_IsAllowTargetType ( $oPoll -> getTargetType ()) or $oPoll -> getTargetTmp () != $sTarget ) {
return $this -> EventErrorDebug ();
}
}
/**
* Обновляем
*/
$oPoll -> _setValidateScenario ( 'update' );
$oPoll -> _setDataSafe ( getRequest ( 'poll' ));
$oPoll -> setAnswersRaw ( getRequest ( 'answers' ));
if ( $oPoll -> _Validate ()) {
if ( $oPoll -> Update ()) {
$oViewer = $this -> Viewer_GetLocalViewer ();
$oViewer -> Assign ( 'oPoll' , $oPoll );
$this -> Viewer_AssignAjax ( 'sPollItem' , $oViewer -> Fetch ( " polls/poll.form.item.tpl " ));
$this -> Viewer_AssignAjax ( 'iPollId' , $oPoll -> getId ());
return true ;
} else {
$this -> Message_AddError ( $this -> Lang_Get ( 'common.error.save' ), $this -> Lang_Get ( 'error' ));
}
} else {
$this -> Message_AddError ( $oPoll -> _getValidateError (), $this -> Lang_Get ( 'error' ));
}
}
protected function EventPollRemove () {
if ( ! $this -> oUserCurrent ) {
2014-02-05 15:06:04 +02:00
return $this -> EventErrorDebug ();
2014-02-04 15:48:53 +02:00
}
if ( ! $oPoll = $this -> Poll_GetPollById ( getRequestStr ( 'id' ))) {
return $this -> EventErrorDebug ();
}
/**
* Проверяем корректность target ' а
*/
if ( $oPoll -> getTargetId ()) {
if ( ! $this -> Poll_CheckTarget ( $oPoll -> getTargetType (), $oPoll -> getTargetId ())) {
return $this -> EventErrorDebug ();
}
} else {
if ( ! $this -> Poll_IsAllowTargetType ( $oPoll -> getTargetType ()) or $oPoll -> getTargetTmp () != getRequestStr ( 'tmp' )) {
return $this -> EventErrorDebug ();
}
}
if ( ! $oPoll -> isAllowRemove ()) {
$this -> Message_AddError ( 'Этот опрос уже нельзя удалить' );
}
/**
* Удаляем
*/
if ( $oPoll -> Delete ()) {
return true ;
} else {
$this -> Message_AddError ( $this -> Lang_Get ( 'common.error.save' ), $this -> Lang_Get ( 'error' ));
}
}
protected function EventPollModalCreate () {
if ( ! $this -> oUserCurrent ) {
return $this -> EventErrorDebug ();
}
/**
* Проверяем корректность target ' а
*/
$sTargetType = getRequestStr ( 'target_type' );
$sTargetId = getRequestStr ( 'target_id' );
$sTargetTmp = empty ( $_COOKIE [ 'poll_target_tmp_' . $sTargetType ]) ? getRequestStr ( 'target_tmp' ) : $_COOKIE [ 'poll_target_tmp_' . $sTargetType ];
if ( $sTargetId ) {
$sTargetTmp = null ;
if ( ! $this -> Poll_CheckTarget ( $sTargetType , $sTargetId )) {
return $this -> EventErrorDebug ();
}
} else {
$sTargetId = null ;
if ( ! $this -> Poll_IsAllowTargetType ( $sTargetType )) {
return $this -> EventErrorDebug ();
}
if ( ! $sTargetTmp ) {
$sTargetTmp = func_generator ();
setcookie ( 'poll_target_tmp_' . $sTargetType , $sTargetTmp , time () + 24 * 3600 , Config :: Get ( 'sys.cookie.path' ), Config :: Get ( 'sys.cookie.host' ));
}
}
$oViewer = $this -> Viewer_GetLocalViewer ();
$oViewer -> Assign ( 'sTargetType' , $sTargetType );
$oViewer -> Assign ( 'sTargetId' , $sTargetId );
$oViewer -> Assign ( 'sTargetTmp' , $sTargetTmp );
$this -> Viewer_AssignAjax ( 'sText' , $oViewer -> Fetch ( " modals/modal.poll_create.tpl " ));
}
protected function EventPollModalUpdate () {
if ( ! $this -> oUserCurrent ) {
return $this -> EventErrorDebug ();
}
if ( ! $oPoll = $this -> Poll_GetPollById ( getRequestStr ( 'id' ))) {
return $this -> EventErrorDebug ();
}
/**
* Проверяем корректность target ' а
*/
if ( $oPoll -> getTargetId ()) {
if ( ! $this -> Poll_CheckTarget ( $oPoll -> getTargetType (), $oPoll -> getTargetId ())) {
return $this -> EventErrorDebug ();
}
} else {
if ( ! $this -> Poll_IsAllowTargetType ( $oPoll -> getTargetType ()) or $oPoll -> getTargetTmp () != getRequestStr ( 'target_tmp' )) {
return $this -> EventErrorDebug ();
}
}
$oViewer = $this -> Viewer_GetLocalViewer ();
$oViewer -> Assign ( 'oPoll' , $oPoll );
$oViewer -> Assign ( 'sTargetTmp' , getRequestStr ( 'target_tmp' ));
$this -> Viewer_AssignAjax ( 'sText' , $oViewer -> Fetch ( " modals/modal.poll_create.tpl " ));
}
2014-01-25 15:20:02 +02:00
/**
* Ajax валидация каптчи
*/
protected function EventValidateCaptcha () {
/**
* Устанавливаем формат Ajax ответа
*/
$this -> Viewer_SetResponseAjax ( 'json' );
$sName = isset ( $_REQUEST [ 'params' ][ 'name' ]) ? $_REQUEST [ 'params' ][ 'name' ] : '' ;
$sValue = isset ( $_REQUEST [ 'fields' ][ 0 ][ 'value' ]) ? $_REQUEST [ 'fields' ][ 0 ][ 'value' ] : '' ;
$sField = isset ( $_REQUEST [ 'fields' ][ 0 ][ 'field' ]) ? $_REQUEST [ 'fields' ][ 0 ][ 'field' ] : '' ;
if ( ! $this -> Validate_Validate ( 'captcha' , $sValue , array ( 'name' => $sName ))) {
$aErrors = $this -> Validate_GetErrors ();
$this -> Viewer_AssignAjax ( 'aErrors' , array ( htmlspecialchars ( $sField ) => array ( reset ( $aErrors ))));
}
}
2014-01-06 16:52:49 +02:00
2014-01-08 13:15:46 +02:00
protected function EventPropertyTagsAutocompleter () {
/**
* Первые буквы тега переданы ?
*/
if ( ! ( $sValue = getRequest ( 'value' , null , 'post' )) or ! is_string ( $sValue )) {
return ;
}
$aItems = array ();
/**
* Формируем список тегов
*/
$aTags = $this -> Property_GetPropertyTagsByLike ( $sValue , getRequestStr ( 'property_id' ), 10 );
foreach ( $aTags as $oTag ) {
$aItems [] = $oTag -> getText ();
}
/**
* Передаем результат в ajax ответ
*/
$this -> Viewer_AssignAjax ( 'aItems' , $aItems );
}
2014-01-06 16:52:49 +02:00
protected function EventMediaUploadLink () {
/**
* Пользователь авторизован ?
*/
if ( ! $this -> oUserCurrent ) {
$this -> Message_AddErrorSingle ( $this -> Lang_Get ( 'need_authorization' ), $this -> Lang_Get ( 'error' ));
return ;
}
/**
* URL передали ?
*/
if ( ! ( $sUrl = getRequestStr ( 'url' ))) {
2014-01-28 09:47:36 +02:00
return $this -> EventErrorDebug ();
2014-01-06 16:52:49 +02:00
}
/**
* Проверяем корректность 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 ( ! $this -> Media_CheckTarget ( $sTargetType , $sTargetId )) {
$this -> Message_AddError ( $this -> Lang_Get ( 'system_error' ), $this -> Lang_Get ( 'error' ));
return false ;
}
} else {
$sTargetId = null ;
if ( ! $sTargetTmp or ! $this -> Media_IsAllowTargetType ( $sTargetType )) {
$this -> Message_AddError ( $this -> Lang_Get ( 'system_error' ), $this -> Lang_Get ( 'error' ));
return false ;
}
}
/**
* Выполняем загрузку файла
*/
if ( $mResult = $this -> Media_UploadUrl ( $sUrl , $sTargetType , $sTargetId , $sTargetTmp ) and is_object ( $mResult )) {
$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' ));
}
}
2013-12-30 19:09:13 +02:00
protected function EventMediaSaveDataFile () {
/**
* Пользователь авторизован ?
*/
if ( ! $this -> oUserCurrent ) {
$this -> Message_AddErrorSingle ( $this -> Lang_Get ( 'need_authorization' ), $this -> Lang_Get ( 'error' ));
return ;
}
$aAllowData = array ( 'title' );
$sName = getRequestStr ( 'name' );
$sValue = getRequestStr ( 'value' );
if ( ! in_array ( $sName , $aAllowData )) {
2014-01-28 09:47:36 +02:00
return $this -> EventErrorDebug ();
2013-12-30 19:09:13 +02:00
}
$sId = getRequestStr ( 'id' );
if ( $oMedia = $this -> Media_GetMediaByIdAndUserId ( $sId , $this -> oUserCurrent -> getId ())) {
$oMedia -> setDataOne ( $sName , $sValue );
$oMedia -> Update ();
} else {
$this -> Message_AddErrorSingle ( $this -> Lang_Get ( 'system_error' ));
}
}
2013-12-25 14:19:33 +02:00
protected function EventMediaRemoveFile () {
/**
* Пользователь авторизован ?
*/
if ( ! $this -> oUserCurrent ) {
$this -> Message_AddErrorSingle ( $this -> Lang_Get ( 'need_authorization' ), $this -> Lang_Get ( 'error' ));
return ;
}
$sId = getRequestStr ( 'id' );
if ( $oMedia = $this -> Media_GetMediaByIdAndUserId ( $sId , $this -> oUserCurrent -> getId ())) {
$this -> Media_DeleteFile ( $oMedia );
} else {
$this -> Message_AddErrorSingle ( $this -> Lang_Get ( 'system_error' ));
}
}
protected function EventMediaLoadGallery () {
/**
* Пользователь авторизован ?
*/
if ( ! $this -> oUserCurrent ) {
$this -> Message_AddErrorSingle ( $this -> Lang_Get ( 'need_authorization' ), $this -> Lang_Get ( 'error' ));
return ;
}
$sType = getRequestStr ( 'target_type' );
$sId = getRequestStr ( 'target_id' );
$sTmp = getRequestStr ( 'target_tmp' );
$aMediaItems = array ();
if ( $sId ) {
$aMediaItems = $this -> Media_GetMediaByTarget ( $sType , $sId , $this -> oUserCurrent -> getId ());
} elseif ( $sTmp ) {
$aMediaItems = $this -> Media_GetMediaByTargetTmp ( $sTmp , $this -> oUserCurrent -> getId ());
}
$oViewer = $this -> Viewer_GetLocalViewer ();
$sTemplate = '' ;
foreach ( $aMediaItems as $oMediaItem ) {
$oViewer -> Assign ( 'oMediaItem' , $oMediaItem );
$sTemplate .= $oViewer -> Fetch ( 'modals/modal.upload_image.gallery.item.tpl' );
}
$this -> Viewer_AssignAjax ( 'sTemplate' , $sTemplate );
}
protected function EventMediaSubmitInsert () {
$aIds = array ( 0 );
foreach (( array ) getRequest ( 'ids' ) as $iId ) {
$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 ) {
$this -> Message_AddError ( 'Необходимо выбрать элементы' );
return false ;
}
$aParams = array (
'align' => getRequestStr ( 'align' ),
'size' => getRequestStr ( 'size' )
);
$sTextResult = '' ;
foreach ( $aMediaItems as $oMedia ) {
$sTextResult .= $this -> Media_BuildCodeForEditor ( $oMedia , $aParams ) . " \r \n " ;
}
$this -> Viewer_AssignAjax ( 'sTextResult' , $sTextResult );
}
protected function EventMediaSubmitCreatePhotoset () {
2014-01-05 15:28:53 +02:00
$aMediaItems = $this -> Media_GetAllowMediaItemsById ( getRequest ( 'ids' ));
2013-12-25 14:19:33 +02:00
if ( ! $aMediaItems ) {
$this -> Message_AddError ( 'Необходимо выбрать элементы' );
return false ;
}
2014-01-05 15:28:53 +02:00
$aItems = array ();
foreach ( $aMediaItems as $oMedia ) {
$aItems [] = $oMedia -> getId ();
}
$sTextResult = '<gallery items="' . join ( ',' , $aItems ) . '"' ;
2013-12-30 19:09:13 +02:00
if ( getRequest ( 'use_thumbs' )) {
2014-01-05 15:28:53 +02:00
$sTextResult .= ' nav="thumbs" ' ;
2013-12-30 19:09:13 +02:00
}
2014-01-05 15:28:53 +02:00
if ( getRequest ( 'show_caption' )) {
$sTextResult .= ' caption="1" ' ;
2013-12-25 14:19:33 +02:00
}
2014-01-05 15:28:53 +02:00
$sTextResult .= ' />' ;
2013-12-25 14:19:33 +02:00
$this -> Viewer_AssignAjax ( 'sTextResult' , $sTextResult );
}
protected function EventMediaGenerateTargetTmp () {
$sType = getRequestStr ( 'type' );
if ( $this -> Media_IsAllowTargetType ( $sType )) {
$sTmp = func_generator ();
setcookie ( 'media_target_tmp_' . $sType , $sTmp , time () + 24 * 3600 , Config :: Get ( 'sys.cookie.path' ), Config :: Get ( 'sys.cookie.host' ));
$this -> Viewer_AssignAjax ( 'sTmpKey' , $sTmp );
}
}
protected function EventMediaUpload () {
if ( getRequest ( 'is_iframe' )) {
$this -> Viewer_SetResponseAjax ( 'jsonIframe' , false );
} else {
$this -> Viewer_SetResponseAjax ( 'json' );
}
/**
* Пользователь авторизован ?
*/
if ( ! $this -> oUserCurrent ) {
$this -> Message_AddErrorSingle ( $this -> Lang_Get ( 'need_authorization' ), $this -> Lang_Get ( 'error' ));
return ;
}
/**
* Файл был загружен ?
*/
if ( ! isset ( $_FILES [ 'filedata' ][ 'tmp_name' ])) {
2014-01-28 09:47:36 +02:00
return $this -> EventErrorDebug ();
2013-12-25 14:19:33 +02:00
}
/**
* Проверяем корректность 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 ( ! $this -> Media_CheckTarget ( $sTargetType , $sTargetId )) {
2014-01-28 09:47:36 +02:00
return $this -> EventErrorDebug ();
2013-12-25 14:19:33 +02:00
}
} else {
$sTargetId = null ;
if ( ! $sTargetTmp or ! $this -> Media_IsAllowTargetType ( $sTargetType )) {
2014-01-28 09:47:36 +02:00
return $this -> EventErrorDebug ();
2013-12-25 14:19:33 +02:00
}
}
/**
* TODO : необходима проверка на максимальное общее количество файлов , на максимальный размер файла
* Эти настройки можно хранить в конфиге : module . media . type . topic . max_file_count = 30 и т . п .
*/
/**
* Выполняем загрузку файла
*/
if ( $mResult = $this -> Media_Upload ( $_FILES [ 'filedata' ], $sTargetType , $sTargetId , $sTargetTmp ) and is_object ( $mResult )) {
$oViewer = $this -> Viewer_GetLocalViewer ();
$oViewer -> Assign ( 'oMediaItem' , $mResult );
$sTemplateFile = $oViewer -> Fetch ( 'modals/modal.upload_image.gallery.item.tpl' );
$this -> Viewer_AssignAjax ( 'sTemplateFile' , $sTemplateFile );
} else {
$this -> Message_AddError ( is_string ( $mResult ) ? $mResult : $this -> Lang_Get ( 'system_error' ), $this -> Lang_Get ( 'error' ));
}
}
2012-03-29 09:23:13 +03:00
/**
* Вывод информации о блоге
*/
protected function EventInfoboxInfoBlog () {
2012-04-29 17:58:36 +03:00
/**
* Если блог существует и он не персональный
*/
2012-07-08 11:50:36 +03:00
if ( ! is_string ( getRequest ( 'iBlogId' ))) {
2014-01-28 09:47:36 +02:00
return $this -> EventErrorDebug ();
2012-07-08 11:50:36 +03:00
}
2012-03-29 09:23:13 +03:00
if ( ! ( $oBlog = $this -> Blog_GetBlogById ( getRequest ( 'iBlogId' ))) or $oBlog -> getType () == 'personal' ) {
2014-01-28 09:47:36 +02:00
return $this -> EventErrorDebug ();
2012-03-29 09:23:13 +03:00
}
2012-04-29 17:58:36 +03:00
/**
* Получаем локальный вьюер для рендеринга шаблона
*/
2012-03-29 09:23:13 +03:00
$oViewer = $this -> Viewer_GetLocalViewer ();
$oViewer -> Assign ( 'oBlog' , $oBlog );
if ( $oBlog -> getType () != 'close' or $oBlog -> getUserIsJoin ()) {
/**
* Получаем последний топик
*/
$aResult = $this -> Topic_GetTopicsByFilter ( array ( 'blog_id' => $oBlog -> getId (), 'topic_publish' => 1 ), 1 , 1 );
$oViewer -> Assign ( 'oTopicLast' , reset ( $aResult [ 'collection' ]));
}
$oViewer -> Assign ( 'oUserCurrent' , $this -> oUserCurrent );
2012-04-29 17:58:36 +03:00
/**
* Устанавливаем переменные для ajax ответа
*/
2013-07-02 05:58:58 +03:00
$this -> Viewer_AssignAjax ( 'sText' , $oViewer -> Fetch ( " actions/ActionBlogs/popover.blog.info.tpl " ));
2012-03-29 09:23:13 +03:00
}
2013-04-30 12:19:00 +03:00
/**
* Получение информации о голосовании за топик
*/
2014-01-30 11:51:14 +02:00
protected function EventVoteGetInfoTopic () {
if ( ! ( $oTopic = $this -> Topic_GetTopicById ( getRequestStr ( 'id' , null , 'post' ))) ) {
2014-01-28 09:47:36 +02:00
return $this -> EventErrorDebug ();
2013-04-30 12:19:00 +03:00
}
2014-01-30 11:51:14 +02:00
if ( ! $oTopic -> getVote () && ( $this -> oUserCurrent && $oTopic -> getUserId () != $this -> oUserCurrent -> getId ()) && ( strtotime ( $oTopic -> getDateAdd ()) + Config :: Get ( 'acl.vote.topic.limit_time' ) > time ())) {
2014-01-28 09:47:36 +02:00
return $this -> EventErrorDebug ();
2013-04-30 12:19:00 +03:00
}
$oViewer = $this -> Viewer_GetLocalViewer ();
$oViewer -> Assign ( 'oTopic' , $oTopic );
$oViewer -> Assign ( 'oUserCurrent' , $this -> oUserCurrent );
2014-01-28 13:44:57 +02:00
$this -> Viewer_AssignAjax ( 'sText' , $oViewer -> Fetch ( " vote.info.tpl " ));
2013-04-30 12:19:00 +03:00
}
2012-03-23 06:46:13 +02:00
/**
* Получение списка регионов по стране
*/
protected function EventGeoGetRegions () {
2012-12-12 08:06:38 +02:00
$iCountryId = getRequestStr ( 'country' );
2012-03-23 06:46:13 +02:00
$iLimit = 200 ;
if ( is_numeric ( getRequest ( 'limit' )) and getRequest ( 'limit' ) > 0 ) {
$iLimit = getRequest ( 'limit' );
}
2012-04-29 17:58:36 +03:00
/**
* Находим страну
*/
2012-03-23 06:46:13 +02:00
if ( ! ( $oCountry = $this -> Geo_GetGeoObject ( 'country' , $iCountryId ))) {
2014-01-28 09:47:36 +02:00
return $this -> EventErrorDebug ();
2012-03-23 06:46:13 +02:00
}
2012-04-29 17:58:36 +03:00
/**
* Получаем список регионов
*/
2012-03-23 06:46:13 +02:00
$aResult = $this -> Geo_GetRegions ( array ( 'country_id' => $oCountry -> getId ()), array ( 'sort' => 'asc' ), 1 , $iLimit );
$aRegions = array ();
foreach ( $aResult [ 'collection' ] as $oObject ) {
$aRegions [] = array (
'id' => $oObject -> getId (),
'name' => $oObject -> getName (),
);
}
2012-04-29 17:58:36 +03:00
/**
* Устанавливаем переменные для ajax ответа
*/
2012-03-23 06:46:13 +02:00
$this -> Viewer_AssignAjax ( 'aRegions' , $aRegions );
}
/**
* Получение списка городов по региону
*/
protected function EventGeoGetCities () {
2012-12-12 08:06:38 +02:00
$iRegionId = getRequestStr ( 'region' );
2012-03-23 06:46:13 +02:00
$iLimit = 500 ;
if ( is_numeric ( getRequest ( 'limit' )) and getRequest ( 'limit' ) > 0 ) {
$iLimit = getRequest ( 'limit' );
}
2012-04-29 17:58:36 +03:00
/**
* Находим регион
*/
2012-03-23 06:46:13 +02:00
if ( ! ( $oRegion = $this -> Geo_GetGeoObject ( 'region' , $iRegionId ))) {
2014-01-28 09:47:36 +02:00
return $this -> EventErrorDebug ();
2012-03-23 06:46:13 +02:00
}
2012-04-29 17:58:36 +03:00
/**
* Получаем города
*/
2012-03-23 06:46:13 +02:00
$aResult = $this -> Geo_GetCities ( array ( 'region_id' => $oRegion -> getId ()), array ( 'sort' => 'asc' ), 1 , $iLimit );
$aCities = array ();
foreach ( $aResult [ 'collection' ] as $oObject ) {
$aCities [] = array (
'id' => $oObject -> getId (),
'name' => $oObject -> getName (),
);
}
2012-04-29 17:58:36 +03:00
/**
* Устанавливаем переменные для ajax ответа
*/
2012-03-23 06:46:13 +02:00
$this -> Viewer_AssignAjax ( 'aCities' , $aCities );
}
2010-09-26 19:23:23 +03:00
/**
* Голосование за комментарий
*
*/
protected function EventVoteComment () {
2012-04-29 17:58:36 +03:00
/**
* Пользователь авторизован ?
*/
2010-09-26 19:23:23 +03:00
if ( ! $this -> oUserCurrent ) {
$this -> Message_AddErrorSingle ( $this -> Lang_Get ( 'need_authorization' ), $this -> Lang_Get ( 'error' ));
return ;
}
2012-04-29 17:58:36 +03:00
/**
* Комментарий существует ?
*/
2012-12-12 08:06:38 +02:00
if ( ! ( $oComment = $this -> Comment_GetCommentById ( getRequestStr ( 'idComment' , null , 'post' )))) {
2014-01-28 09:47:36 +02:00
return $this -> EventErrorDebug ();
2010-09-26 19:23:23 +03:00
}
2012-04-29 17:58:36 +03:00
/**
* Голосует автор комментария ?
*/
2010-09-26 19:23:23 +03:00
if ( $oComment -> getUserId () == $this -> oUserCurrent -> getId ()) {
$this -> Message_AddErrorSingle ( $this -> Lang_Get ( 'comment_vote_error_self' ), $this -> Lang_Get ( 'attention' ));
return ;
}
2012-04-29 17:58:36 +03:00
/**
* Пользователь уже голосовал ?
*/
2010-09-26 19:23:23 +03:00
if ( $oTopicCommentVote = $this -> Vote_GetVote ( $oComment -> getId (), 'comment' , $this -> oUserCurrent -> getId ())) {
$this -> Message_AddErrorSingle ( $this -> Lang_Get ( 'comment_vote_error_already' ), $this -> Lang_Get ( 'attention' ));
return ;
}
2012-04-29 17:58:36 +03:00
/**
* Время голосования истекло ?
*/
2010-09-26 19:23:23 +03:00
if ( strtotime ( $oComment -> getDate ()) <= time () - Config :: Get ( 'acl.vote.comment.limit_time' )) {
$this -> Message_AddErrorSingle ( $this -> Lang_Get ( 'comment_vote_error_time' ), $this -> Lang_Get ( 'attention' ));
return ;
}
2012-04-29 17:58:36 +03:00
/**
* Пользователь имеет право голоса ?
*/
2010-09-26 19:23:23 +03:00
if ( ! $this -> ACL_CanVoteComment ( $this -> oUserCurrent , $oComment )) {
$this -> Message_AddErrorSingle ( $this -> Lang_Get ( 'comment_vote_error_acl' ), $this -> Lang_Get ( 'attention' ));
return ;
}
2012-04-29 17:58:36 +03:00
/**
* Как именно голосует пользователь
*/
2012-12-12 08:06:38 +02:00
$iValue = getRequestStr ( 'value' , null , 'post' );
2010-09-26 19:23:23 +03:00
if ( ! in_array ( $iValue , array ( '1' , '-1' ))) {
2014-01-28 09:47:36 +02:00
return $this -> EventErrorDebug ();
2010-09-26 19:23:23 +03:00
}
2012-04-29 17:58:36 +03:00
/**
* Голосуем
*/
2010-09-26 19:23:23 +03:00
$oTopicCommentVote = Engine :: GetEntity ( 'Vote' );
$oTopicCommentVote -> setTargetId ( $oComment -> getId ());
$oTopicCommentVote -> setTargetType ( 'comment' );
$oTopicCommentVote -> setVoterId ( $this -> oUserCurrent -> getId ());
$oTopicCommentVote -> setDirection ( $iValue );
$oTopicCommentVote -> setDate ( date ( " Y-m-d H:i:s " ));
$iVal = ( float ) $this -> Rating_VoteComment ( $this -> oUserCurrent , $oComment , $iValue );
$oTopicCommentVote -> setValue ( $iVal );
$oComment -> setCountVote ( $oComment -> getCountVote () + 1 );
2011-06-06 14:58:19 +03:00
if ( $this -> Vote_AddVote ( $oTopicCommentVote ) and $this -> Comment_UpdateComment ( $oComment )) {
2010-09-26 19:23:23 +03:00
$this -> Message_AddNoticeSingle ( $this -> Lang_Get ( 'comment_vote_ok' ), $this -> Lang_Get ( 'attention' ));
$this -> Viewer_AssignAjax ( 'iRating' , $oComment -> getRating ());
2012-04-29 17:58:36 +03:00
/**
* Добавляем событие в ленту
*/
$this -> Stream_write ( $oTopicCommentVote -> getVoterId (), 'vote_comment' , $oComment -> getId ());
2010-09-26 19:23:23 +03:00
} else {
$this -> Message_AddErrorSingle ( $this -> Lang_Get ( 'comment_vote_error' ), $this -> Lang_Get ( 'error' ));
return ;
}
}
/**
* Голосование за топик
*
*/
protected function EventVoteTopic () {
2012-04-29 17:58:36 +03:00
/**
* Пользователь авторизован ?
*/
2010-09-26 19:23:23 +03:00
if ( ! $this -> oUserCurrent ) {
$this -> Message_AddErrorSingle ( $this -> Lang_Get ( 'need_authorization' ), $this -> Lang_Get ( 'error' ));
return ;
}
2012-04-29 17:58:36 +03:00
/**
* Топик существует ?
*/
2012-12-12 08:06:38 +02:00
if ( ! ( $oTopic = $this -> Topic_GetTopicById ( getRequestStr ( 'idTopic' , null , 'post' )))) {
2014-01-28 09:47:36 +02:00
return $this -> EventErrorDebug ();
2010-09-26 19:23:23 +03:00
}
2012-04-29 17:58:36 +03:00
/**
* Голосует автор топика ?
*/
2010-09-26 19:23:23 +03:00
if ( $oTopic -> getUserId () == $this -> oUserCurrent -> getId ()) {
$this -> Message_AddErrorSingle ( $this -> Lang_Get ( 'topic_vote_error_self' ), $this -> Lang_Get ( 'attention' ));
return ;
}
2012-04-29 17:58:36 +03:00
/**
* Пользователь уже голосовал ?
*/
2010-09-26 19:23:23 +03:00
if ( $oTopicVote = $this -> Vote_GetVote ( $oTopic -> getId (), 'topic' , $this -> oUserCurrent -> getId ())) {
$this -> Message_AddErrorSingle ( $this -> Lang_Get ( 'topic_vote_error_already' ), $this -> Lang_Get ( 'attention' ));
return ;
}
2012-04-29 17:58:36 +03:00
/**
* Время голосования истекло ?
*/
2010-09-26 19:23:23 +03:00
if ( strtotime ( $oTopic -> getDateAdd ()) <= time () - Config :: Get ( 'acl.vote.topic.limit_time' )) {
$this -> Message_AddErrorSingle ( $this -> Lang_Get ( 'topic_vote_error_time' ), $this -> Lang_Get ( 'attention' ));
return ;
}
2012-04-29 17:58:36 +03:00
/**
* Как проголосовал пользователь
*/
2012-12-12 08:06:38 +02:00
$iValue = getRequestStr ( 'value' , null , 'post' );
2010-09-26 19:23:23 +03:00
if ( ! in_array ( $iValue , array ( '1' , '-1' , '0' ))) {
2014-01-28 09:47:36 +02:00
return $this -> EventErrorDebug ();
2010-09-26 19:23:23 +03:00
}
2012-04-29 17:58:36 +03:00
/**
* Права на голосование
*/
2010-12-25 10:57:29 +02:00
if ( ! $this -> ACL_CanVoteTopic ( $this -> oUserCurrent , $oTopic ) and $iValue ) {
$this -> Message_AddErrorSingle ( $this -> Lang_Get ( 'topic_vote_error_acl' ), $this -> Lang_Get ( 'attention' ));
return ;
}
2012-04-29 17:58:36 +03:00
/**
* Голосуем
*/
2010-09-26 19:23:23 +03:00
$oTopicVote = Engine :: GetEntity ( 'Vote' );
$oTopicVote -> setTargetId ( $oTopic -> getId ());
$oTopicVote -> setTargetType ( 'topic' );
$oTopicVote -> setVoterId ( $this -> oUserCurrent -> getId ());
$oTopicVote -> setDirection ( $iValue );
$oTopicVote -> setDate ( date ( " Y-m-d H:i:s " ));
$iVal = 0 ;
if ( $iValue != 0 ) {
$iVal = ( float ) $this -> Rating_VoteTopic ( $this -> oUserCurrent , $oTopic , $iValue );
}
$oTopicVote -> setValue ( $iVal );
$oTopic -> setCountVote ( $oTopic -> getCountVote () + 1 );
2012-03-10 07:45:19 +02:00
if ( $iValue == 1 ) {
$oTopic -> setCountVoteUp ( $oTopic -> getCountVoteUp () + 1 );
} elseif ( $iValue ==- 1 ) {
$oTopic -> setCountVoteDown ( $oTopic -> getCountVoteDown () + 1 );
} elseif ( $iValue == 0 ) {
$oTopic -> setCountVoteAbstain ( $oTopic -> getCountVoteAbstain () + 1 );
}
2011-06-06 14:58:19 +03:00
if ( $this -> Vote_AddVote ( $oTopicVote ) and $this -> Topic_UpdateTopic ( $oTopic )) {
2010-09-26 19:23:23 +03:00
if ( $iValue ) {
$this -> Message_AddNoticeSingle ( $this -> Lang_Get ( 'topic_vote_ok' ), $this -> Lang_Get ( 'attention' ));
} else {
$this -> Message_AddNoticeSingle ( $this -> Lang_Get ( 'topic_vote_ok_abstain' ), $this -> Lang_Get ( 'attention' ));
}
$this -> Viewer_AssignAjax ( 'iRating' , $oTopic -> getRating ());
2012-04-29 17:58:36 +03:00
/**
* Добавляем событие в ленту
*/
$this -> Stream_write ( $oTopicVote -> getVoterId (), 'vote_topic' , $oTopic -> getId ());
2010-09-26 19:23:23 +03:00
} else {
$this -> Message_AddErrorSingle ( $this -> Lang_Get ( 'system_error' ), $this -> Lang_Get ( 'error' ));
return ;
2011-06-06 14:58:19 +03:00
}
2010-09-26 19:23:23 +03:00
}
/**
* Голосование за блог
*
*/
protected function EventVoteBlog () {
2012-04-29 17:58:36 +03:00
/**
* Пользователь авторизован ?
*/
2010-09-26 19:23:23 +03:00
if ( ! $this -> oUserCurrent ) {
$this -> Message_AddErrorSingle ( $this -> Lang_Get ( 'need_authorization' ), $this -> Lang_Get ( 'error' ));
return ;
}
2012-04-29 17:58:36 +03:00
/**
* Блог существует ?
*/
2012-12-12 08:06:38 +02:00
if ( ! ( $oBlog = $this -> Blog_GetBlogById ( getRequestStr ( 'idBlog' , null , 'post' )))) {
2014-01-28 09:47:36 +02:00
return $this -> EventErrorDebug ();
2010-09-26 19:23:23 +03:00
}
2012-04-29 17:58:36 +03:00
/**
* Голосует за свой блог ?
*/
2010-09-26 19:23:23 +03:00
if ( $oBlog -> getOwnerId () == $this -> oUserCurrent -> getId ()) {
2014-01-25 14:39:19 +02:00
$this -> Message_AddErrorSingle ( $this -> Lang_Get ( 'blog.vote.notices.error_self' ), $this -> Lang_Get ( 'attention' ));
2010-09-26 19:23:23 +03:00
return ;
}
2012-04-29 17:58:36 +03:00
/**
* Уже голосовал ?
*/
2010-09-26 19:23:23 +03:00
if ( $oBlogVote = $this -> Vote_GetVote ( $oBlog -> getId (), 'blog' , $this -> oUserCurrent -> getId ())) {
2014-01-25 14:39:19 +02:00
$this -> Message_AddErrorSingle ( $this -> Lang_Get ( 'blog.vote.notices.error_already' ), $this -> Lang_Get ( 'attention' ));
2010-09-26 19:23:23 +03:00
return ;
}
2012-04-29 17:58:36 +03:00
/**
* Имеет право на голосование ?
*/
2010-09-26 19:23:23 +03:00
switch ( $this -> ACL_CanVoteBlog ( $this -> oUserCurrent , $oBlog )) {
case ModuleACL :: CAN_VOTE_BLOG_TRUE :
2012-12-12 08:06:38 +02:00
$iValue = getRequestStr ( 'value' , null , 'post' );
2010-09-26 19:23:23 +03:00
if ( in_array ( $iValue , array ( '1' , '-1' ))) {
$oBlogVote = Engine :: GetEntity ( 'Vote' );
$oBlogVote -> setTargetId ( $oBlog -> getId ());
$oBlogVote -> setTargetType ( 'blog' );
$oBlogVote -> setVoterId ( $this -> oUserCurrent -> getId ());
$oBlogVote -> setDirection ( $iValue );
$oBlogVote -> setDate ( date ( " Y-m-d H:i:s " ));
$iVal = ( float ) $this -> Rating_VoteBlog ( $this -> oUserCurrent , $oBlog , $iValue );
$oBlogVote -> setValue ( $iVal );
$oBlog -> setCountVote ( $oBlog -> getCountVote () + 1 );
2011-06-06 14:58:19 +03:00
if ( $this -> Vote_AddVote ( $oBlogVote ) and $this -> Blog_UpdateBlog ( $oBlog )) {
2010-09-26 19:23:23 +03:00
$this -> Viewer_AssignAjax ( 'iCountVote' , $oBlog -> getCountVote ());
$this -> Viewer_AssignAjax ( 'iRating' , $oBlog -> getRating ());
2014-01-25 14:39:19 +02:00
$this -> Message_AddNoticeSingle ( $this -> Lang_Get ( 'vote.notices.success' ), $this -> Lang_Get ( 'attention' ));
2012-04-29 17:58:36 +03:00
/**
* Добавляем событие в ленту
*/
$this -> Stream_write ( $oBlogVote -> getVoterId (), 'vote_blog' , $oBlog -> getId ());
2010-09-26 19:23:23 +03:00
} else {
$this -> Message_AddErrorSingle ( $this -> Lang_Get ( 'system_error' ), $this -> Lang_Get ( 'attention' ));
return ;
}
} else {
2014-01-28 09:47:36 +02:00
return $this -> EventErrorDebug ();
2010-09-26 19:23:23 +03:00
}
break ;
case ModuleACL :: CAN_VOTE_BLOG_ERROR_CLOSE :
2014-01-25 14:39:19 +02:00
$this -> Message_AddErrorSingle ( $this -> Lang_Get ( 'blog.vote.notices.error_close' ), $this -> Lang_Get ( 'attention' ));
2010-09-26 19:23:23 +03:00
return ;
break ;
default :
case ModuleACL :: CAN_VOTE_BLOG_FALSE :
2014-01-25 14:39:19 +02:00
$this -> Message_AddErrorSingle ( $this -> Lang_Get ( 'blog.vote.notices.error_acl' ), $this -> Lang_Get ( 'attention' ));
2010-09-26 19:23:23 +03:00
return ;
break ;
}
}
/**
2012-04-29 17:58:36 +03:00
* Голосование за пользователя
2010-09-26 19:23:23 +03:00
*
*/
protected function EventVoteUser () {
2012-04-29 17:58:36 +03:00
/**
* Пользователь авторизован ?
*/
2010-09-26 19:23:23 +03:00
if ( ! $this -> oUserCurrent ) {
$this -> Message_AddErrorSingle ( $this -> Lang_Get ( 'need_authorization' ), $this -> Lang_Get ( 'error' ));
return ;
}
2012-04-29 17:58:36 +03:00
/**
* Пользователь существует ?
*/
2012-12-12 08:06:38 +02:00
if ( ! ( $oUser = $this -> User_GetUserById ( getRequestStr ( 'idUser' , null , 'post' )))) {
2014-01-28 09:47:36 +02:00
return $this -> EventErrorDebug ();
2010-09-26 19:23:23 +03:00
}
2012-04-29 17:58:36 +03:00
/**
* Голосует за себя ?
*/
2010-09-26 19:23:23 +03:00
if ( $oUser -> getId () == $this -> oUserCurrent -> getId ()) {
$this -> Message_AddErrorSingle ( $this -> Lang_Get ( 'user_vote_error_self' ), $this -> Lang_Get ( 'attention' ));
return ;
}
2012-04-29 17:58:36 +03:00
/**
* Уже голосовал ?
*/
2010-09-26 19:23:23 +03:00
if ( $oUserVote = $this -> Vote_GetVote ( $oUser -> getId (), 'user' , $this -> oUserCurrent -> getId ())) {
$this -> Message_AddErrorSingle ( $this -> Lang_Get ( 'user_vote_error_already' ), $this -> Lang_Get ( 'attention' ));
return ;
}
2012-04-29 17:58:36 +03:00
/**
* Имеет право на голосование ?
*/
2010-09-26 19:23:23 +03:00
if ( ! $this -> ACL_CanVoteUser ( $this -> oUserCurrent , $oUser )) {
$this -> Message_AddErrorSingle ( $this -> Lang_Get ( 'user_vote_error_acl' ), $this -> Lang_Get ( 'attention' ));
return ;
}
2012-04-29 17:58:36 +03:00
/**
* Как проголосовал
*/
2012-12-12 08:06:38 +02:00
$iValue = getRequestStr ( 'value' , null , 'post' );
2010-09-26 19:23:23 +03:00
if ( ! in_array ( $iValue , array ( '1' , '-1' ))) {
2014-01-28 09:47:36 +02:00
return $this -> EventErrorDebug ();
2010-09-26 19:23:23 +03:00
}
2012-04-29 17:58:36 +03:00
/**
* Голосуем
*/
2010-09-26 19:23:23 +03:00
$oUserVote = Engine :: GetEntity ( 'Vote' );
$oUserVote -> setTargetId ( $oUser -> getId ());
$oUserVote -> setTargetType ( 'user' );
$oUserVote -> setVoterId ( $this -> oUserCurrent -> getId ());
$oUserVote -> setDirection ( $iValue );
$oUserVote -> setDate ( date ( " Y-m-d H:i:s " ));
$iVal = ( float ) $this -> Rating_VoteUser ( $this -> oUserCurrent , $oUser , $iValue );
$oUserVote -> setValue ( $iVal );
//$oUser->setRating($oUser->getRating()+$iValue);
$oUser -> setCountVote ( $oUser -> getCountVote () + 1 );
2011-06-06 14:58:19 +03:00
if ( $this -> Vote_AddVote ( $oUserVote ) and $this -> User_Update ( $oUser )) {
$this -> Message_AddNoticeSingle ( $this -> Lang_Get ( 'user_vote_ok' ), $this -> Lang_Get ( 'attention' ));
2010-09-26 19:23:23 +03:00
$this -> Viewer_AssignAjax ( 'iRating' , $oUser -> getRating ());
$this -> Viewer_AssignAjax ( 'iSkill' , $oUser -> getSkill ());
2011-06-06 14:58:19 +03:00
$this -> Viewer_AssignAjax ( 'iCountVote' , $oUser -> getCountVote ());
2012-04-29 17:58:36 +03:00
/**
* Добавляем событие в ленту
*/
$this -> Stream_write ( $oUserVote -> getVoterId (), 'vote_user' , $oUser -> getId ());
2010-09-26 19:23:23 +03:00
} else {
$this -> Message_AddErrorSingle ( $this -> Lang_Get ( 'system_error' ), $this -> Lang_Get ( 'error' ));
return ;
}
}
2012-03-27 13:45:52 +03:00
/**
* Сохраняет теги для избранного
*
*/
protected function EventFavouriteSaveTags () {
2012-04-29 17:58:36 +03:00
/**
* Пользователь авторизован ?
*/
2012-03-27 13:45:52 +03:00
if ( ! $this -> oUserCurrent ) {
$this -> Message_AddErrorSingle ( $this -> Lang_Get ( 'need_authorization' ), $this -> Lang_Get ( 'error' ));
return ;
}
2012-04-29 17:58:36 +03:00
/**
* Объект уже должен быть в избранном
*/
2012-12-12 08:06:38 +02:00
if ( $oFavourite = $this -> Favourite_GetFavourite ( getRequestStr ( 'target_id' ), getRequestStr ( 'target_type' ), $this -> oUserCurrent -> getId ())) {
2012-04-29 17:58:36 +03:00
/**
* Обрабатываем теги
*/
2012-12-12 08:06:38 +02:00
$aTags = explode ( ',' , trim ( getRequestStr ( 'tags' ), " \r \n \t \0 \x0B . " ));
2012-03-27 13:45:52 +03:00
$aTagsNew = array ();
$aTagsNewLow = array ();
$aTagsReturn = array ();
foreach ( $aTags as $sTag ) {
$sTag = trim ( $sTag );
if ( func_check ( $sTag , 'text' , 2 , 50 ) and ! in_array ( mb_strtolower ( $sTag , 'UTF-8' ), $aTagsNewLow )) {
$sTagEsc = htmlspecialchars ( $sTag );
$aTagsNew [] = $sTagEsc ;
$aTagsReturn [] = array (
'tag' => $sTagEsc ,
'url' => $this -> oUserCurrent -> getUserWebPath () . 'favourites/' . $oFavourite -> getTargetType () . 's/tag/' . $sTagEsc . '/' , // костыль для URL с множественным числом
);
$aTagsNewLow [] = mb_strtolower ( $sTag , 'UTF-8' );
}
}
if ( ! count ( $aTagsNew )) {
$oFavourite -> setTags ( '' );
} else {
$oFavourite -> setTags ( join ( ',' , $aTagsNew ));
}
$this -> Viewer_AssignAjax ( 'aTags' , $aTagsReturn );
$this -> Favourite_UpdateFavourite ( $oFavourite );
return ;
}
2014-01-28 09:47:36 +02:00
return $this -> EventErrorDebug ();
2012-03-27 13:45:52 +03:00
}
2010-09-26 20:15:49 +03:00
/**
* Обработка избранного - топик
*
*/
protected function EventFavouriteTopic () {
2012-04-29 17:58:36 +03:00
/**
* Пользователь авторизован ?
*/
2010-09-26 20:15:49 +03:00
if ( ! $this -> oUserCurrent ) {
$this -> Message_AddErrorSingle ( $this -> Lang_Get ( 'need_authorization' ), $this -> Lang_Get ( 'error' ));
return ;
}
2012-04-29 17:58:36 +03:00
/**
* Можно только добавить или удалить из избранного
*/
2012-12-12 08:06:38 +02:00
$iType = getRequestStr ( 'type' , null , 'post' );
2010-09-26 20:15:49 +03:00
if ( ! in_array ( $iType , array ( '1' , '0' ))) {
2014-01-28 09:47:36 +02:00
return $this -> EventErrorDebug ();
2010-09-26 20:15:49 +03:00
}
2012-04-29 17:58:36 +03:00
/**
* Топик существует ?
*/
2013-12-26 12:31:41 +02:00
if ( ! ( $oTopic = $this -> Topic_GetTopicById ( getRequestStr ( 'id' , null , 'post' )))) {
2014-01-28 09:47:36 +02:00
return $this -> EventErrorDebug ();
2010-09-26 20:15:49 +03:00
}
2012-04-29 17:58:36 +03:00
/**
* Пропускаем топик из черновиков
*/
if ( ! $oTopic -> getPublish ()) {
2011-07-01 11:16:48 +03:00
$this -> Message_AddErrorSingle ( $this -> Lang_Get ( 'error_favorite_topic_is_draft' ), $this -> Lang_Get ( 'error' ));
return ;
}
2012-04-29 17:58:36 +03:00
/**
* Топик уже в избранном ?
*/
2010-09-26 20:15:49 +03:00
$oFavouriteTopic = $this -> Topic_GetFavouriteTopic ( $oTopic -> getId (), $this -> oUserCurrent -> getId ());
if ( ! $oFavouriteTopic and $iType ) {
$oFavouriteTopicNew = Engine :: GetEntity ( 'Favourite' ,
2012-04-29 17:58:36 +03:00
array (
'target_id' => $oTopic -> getId (),
'user_id' => $this -> oUserCurrent -> getId (),
'target_type' => 'topic' ,
'target_publish' => $oTopic -> getPublish ()
)
2010-09-26 20:15:49 +03:00
);
2012-04-29 17:58:36 +03:00
$oTopic -> setCountFavourite ( $oTopic -> getCountFavourite () + 1 );
2011-10-09 20:23:38 +03:00
if ( $this -> Topic_AddFavouriteTopic ( $oFavouriteTopicNew ) and $this -> Topic_UpdateTopic ( $oTopic )) {
2011-06-06 14:58:19 +03:00
$this -> Message_AddNoticeSingle ( $this -> Lang_Get ( 'topic_favourite_add_ok' ), $this -> Lang_Get ( 'attention' ));
2010-09-26 20:15:49 +03:00
$this -> Viewer_AssignAjax ( 'bState' , true );
2012-04-29 17:58:36 +03:00
$this -> Viewer_AssignAjax ( 'iCount' , $oTopic -> getCountFavourite ());
2010-09-26 20:15:49 +03:00
} else {
2014-01-28 09:47:36 +02:00
return $this -> EventErrorDebug ();
2010-09-26 20:15:49 +03:00
}
}
2011-06-06 14:58:19 +03:00
if ( ! $oFavouriteTopic and ! $iType ) {
2010-09-26 20:15:49 +03:00
$this -> Message_AddErrorSingle ( $this -> Lang_Get ( 'topic_favourite_add_no' ), $this -> Lang_Get ( 'error' ));
return ;
}
2011-06-06 14:58:19 +03:00
if ( $oFavouriteTopic and $iType ) {
2010-09-26 20:15:49 +03:00
$this -> Message_AddErrorSingle ( $this -> Lang_Get ( 'topic_favourite_add_already' ), $this -> Lang_Get ( 'error' ));
return ;
}
if ( $oFavouriteTopic and ! $iType ) {
2012-04-29 17:58:36 +03:00
$oTopic -> setCountFavourite ( $oTopic -> getCountFavourite () - 1 );
2011-10-09 20:23:38 +03:00
if ( $this -> Topic_DeleteFavouriteTopic ( $oFavouriteTopic ) and $this -> Topic_UpdateTopic ( $oTopic )) {
2010-09-26 20:15:49 +03:00
$this -> Message_AddNoticeSingle ( $this -> Lang_Get ( 'topic_favourite_del_ok' ), $this -> Lang_Get ( 'attention' ));
$this -> Viewer_AssignAjax ( 'bState' , false );
2012-04-29 17:58:36 +03:00
$this -> Viewer_AssignAjax ( 'iCount' , $oTopic -> getCountFavourite ());
2011-06-06 14:58:19 +03:00
} else {
2014-01-28 09:47:36 +02:00
return $this -> EventErrorDebug ();
2010-09-26 20:15:49 +03:00
}
2011-06-06 14:58:19 +03:00
}
2010-09-26 20:15:49 +03:00
}
/**
* Обработка избранного - комментарий
*
*/
protected function EventFavouriteComment () {
2012-04-29 17:58:36 +03:00
/**
* Пользователь авторизован ?
*/
2010-09-26 20:15:49 +03:00
if ( ! $this -> oUserCurrent ) {
$this -> Message_AddErrorSingle ( $this -> Lang_Get ( 'need_authorization' ), $this -> Lang_Get ( 'error' ));
return ;
}
2012-04-29 17:58:36 +03:00
/**
* Можно только добавить или удалить из избранного
*/
2012-12-12 08:06:38 +02:00
$iType = getRequestStr ( 'type' , null , 'post' );
2010-09-26 20:15:49 +03:00
if ( ! in_array ( $iType , array ( '1' , '0' ))) {
2014-01-28 09:47:36 +02:00
return $this -> EventErrorDebug ();
2010-09-26 20:15:49 +03:00
}
2012-04-29 17:58:36 +03:00
/**
* Комментарий существует ?
*/
2013-12-26 12:31:41 +02:00
if ( ! ( $oComment = $this -> Comment_GetCommentById ( getRequestStr ( 'id' , null , 'post' )))) {
2014-01-28 09:47:36 +02:00
return $this -> EventErrorDebug ();
2010-09-26 20:15:49 +03:00
}
2012-04-29 17:58:36 +03:00
/**
* Комментарий уже в избранном ?
*/
2010-09-26 20:15:49 +03:00
$oFavouriteComment = $this -> Comment_GetFavouriteComment ( $oComment -> getId (), $this -> oUserCurrent -> getId ());
if ( ! $oFavouriteComment and $iType ) {
$oFavouriteCommentNew = Engine :: GetEntity ( 'Favourite' ,
2012-04-29 17:58:36 +03:00
array (
'target_id' => $oComment -> getId (),
'target_type' => 'comment' ,
'user_id' => $this -> oUserCurrent -> getId (),
'target_publish' => $oComment -> getPublish ()
)
2010-09-26 20:15:49 +03:00
);
2012-04-29 17:58:36 +03:00
$oComment -> setCountFavourite ( $oComment -> getCountFavourite () + 1 );
2011-10-09 20:23:38 +03:00
if ( $this -> Comment_AddFavouriteComment ( $oFavouriteCommentNew ) and $this -> Comment_UpdateComment ( $oComment )) {
2010-09-26 20:15:49 +03:00
$this -> Message_AddNoticeSingle ( $this -> Lang_Get ( 'comment_favourite_add_ok' ), $this -> Lang_Get ( 'attention' ));
$this -> Viewer_AssignAjax ( 'bState' , true );
2012-04-29 17:58:36 +03:00
$this -> Viewer_AssignAjax ( 'iCount' , $oComment -> getCountFavourite ());
2010-09-26 20:15:49 +03:00
} else {
2014-01-28 09:47:36 +02:00
return $this -> EventErrorDebug ();
2010-09-26 20:15:49 +03:00
}
}
2011-06-06 14:58:19 +03:00
if ( ! $oFavouriteComment and ! $iType ) {
2010-09-26 20:15:49 +03:00
$this -> Message_AddErrorSingle ( $this -> Lang_Get ( 'comment_favourite_add_no' ), $this -> Lang_Get ( 'error' ));
return ;
}
2011-06-06 14:58:19 +03:00
if ( $oFavouriteComment and $iType ) {
2010-09-26 20:15:49 +03:00
$this -> Message_AddErrorSingle ( $this -> Lang_Get ( 'comment_favourite_add_already' ), $this -> Lang_Get ( 'error' ));
return ;
}
if ( $oFavouriteComment and ! $iType ) {
2012-04-29 17:58:36 +03:00
$oComment -> setCountFavourite ( $oComment -> getCountFavourite () - 1 );
2011-10-09 20:23:38 +03:00
if ( $this -> Comment_DeleteFavouriteComment ( $oFavouriteComment ) and $this -> Comment_UpdateComment ( $oComment )) {
2010-09-26 20:15:49 +03:00
$this -> Message_AddNoticeSingle ( $this -> Lang_Get ( 'comment_favourite_del_ok' ), $this -> Lang_Get ( 'attention' ));
$this -> Viewer_AssignAjax ( 'bState' , false );
2012-04-29 17:58:36 +03:00
$this -> Viewer_AssignAjax ( 'iCount' , $oComment -> getCountFavourite ());
2010-09-26 20:15:49 +03:00
} else {
2014-01-28 09:47:36 +02:00
return $this -> EventErrorDebug ();
2010-09-26 20:15:49 +03:00
}
}
}
/**
2012-04-29 17:58:36 +03:00
* Обработка избранного - личное сообщение
2010-09-26 20:15:49 +03:00
*
*/
protected function EventFavouriteTalk () {
2012-04-29 17:58:36 +03:00
/**
* Пользователь авторизован ?
*/
2010-09-26 20:15:49 +03:00
if ( ! $this -> oUserCurrent ) {
$this -> Message_AddErrorSingle ( $this -> Lang_Get ( 'need_authorization' ), $this -> Lang_Get ( 'error' ));
return ;
}
2012-04-29 17:58:36 +03:00
/**
* Можно только добавить или удалить из избранного
*/
2012-12-12 08:06:38 +02:00
$iType = getRequestStr ( 'type' , null , 'post' );
2010-09-26 20:15:49 +03:00
if ( ! in_array ( $iType , array ( '1' , '0' ))) {
2014-01-28 09:47:36 +02:00
return $this -> EventErrorDebug ();
2010-09-26 20:15:49 +03:00
}
2012-04-29 17:58:36 +03:00
/**
* Сообщение существует ?
*/
2013-12-26 12:31:41 +02:00
if ( ! ( $oTalk = $this -> Talk_GetTalkById ( getRequestStr ( 'id' , null , 'post' )))) {
2014-01-28 09:47:36 +02:00
return $this -> EventErrorDebug ();
2010-09-26 20:15:49 +03:00
}
2012-04-29 17:58:36 +03:00
/**
* Сообщение уже в избранном ?
*/
2010-09-26 20:15:49 +03:00
$oFavouriteTalk = $this -> Talk_GetFavouriteTalk ( $oTalk -> getId (), $this -> oUserCurrent -> getId ());
if ( ! $oFavouriteTalk and $iType ) {
$oFavouriteTalkNew = Engine :: GetEntity ( 'Favourite' ,
2012-04-29 17:58:36 +03:00
array (
'target_id' => $oTalk -> getId (),
'target_type' => 'talk' ,
'user_id' => $this -> oUserCurrent -> getId (),
'target_publish' => '1'
)
2010-09-26 20:15:49 +03:00
);
2011-06-06 14:58:19 +03:00
if ( $this -> Talk_AddFavouriteTalk ( $oFavouriteTalkNew )) {
2010-09-26 20:15:49 +03:00
$this -> Message_AddNoticeSingle ( $this -> Lang_Get ( 'talk_favourite_add_ok' ), $this -> Lang_Get ( 'attention' ));
$this -> Viewer_AssignAjax ( 'bState' , true );
} else {
2014-01-28 09:47:36 +02:00
return $this -> EventErrorDebug ();
2010-09-26 20:15:49 +03:00
}
}
2011-06-06 14:58:19 +03:00
if ( ! $oFavouriteTalk and ! $iType ) {
2010-09-26 20:15:49 +03:00
$this -> Message_AddErrorSingle ( $this -> Lang_Get ( 'talk_favourite_add_no' ), $this -> Lang_Get ( 'error' ));
return ;
}
2011-06-06 14:58:19 +03:00
if ( $oFavouriteTalk and $iType ) {
2010-09-26 20:15:49 +03:00
$this -> Message_AddErrorSingle ( $this -> Lang_Get ( 'talk_favourite_add_already' ), $this -> Lang_Get ( 'error' ));
return ;
}
if ( $oFavouriteTalk and ! $iType ) {
2011-06-06 14:58:19 +03:00
if ( $this -> Talk_DeleteFavouriteTalk ( $oFavouriteTalk )) {
2010-09-26 20:15:49 +03:00
$this -> Message_AddNoticeSingle ( $this -> Lang_Get ( 'talk_favourite_del_ok' ), $this -> Lang_Get ( 'attention' ));
$this -> Viewer_AssignAjax ( 'bState' , false );
} else {
2014-01-28 09:47:36 +02:00
return $this -> EventErrorDebug ();
2010-09-26 20:15:49 +03:00
}
}
2011-06-06 14:58:19 +03:00
2010-09-26 20:15:49 +03:00
}
2010-10-02 13:56:46 +03:00
/**
* Обработка получения последних комментов
2012-04-29 17:58:36 +03:00
* Используется в блоке " Прямой эфир "
2010-10-02 13:56:46 +03:00
*
*/
protected function EventStreamComment () {
if ( $aComments = $this -> Comment_GetCommentsOnline ( 'topic' , Config :: Get ( 'block.stream.row' ))) {
$oViewer = $this -> Viewer_GetLocalViewer ();
2011-06-06 14:58:19 +03:00
$oViewer -> Assign ( 'aComments' , $aComments );
2012-04-21 07:40:14 +03:00
$sTextResult = $oViewer -> Fetch ( " blocks/block.stream_comment.tpl " );
2010-10-02 13:56:46 +03:00
$this -> Viewer_AssignAjax ( 'sText' , $sTextResult );
2011-06-06 14:58:19 +03:00
} else {
2010-10-02 13:56:46 +03:00
$this -> Message_AddErrorSingle ( $this -> Lang_Get ( 'block_stream_comments_no' ), $this -> Lang_Get ( 'attention' ));
return ;
}
}
/**
* Обработка получения последних топиков
2012-04-29 17:58:36 +03:00
* Используется в блоке " Прямой эфир "
2010-10-02 13:56:46 +03:00
*
*/
protected function EventStreamTopic () {
if ( $oTopics = $this -> Topic_GetTopicsLast ( Config :: Get ( 'block.stream.row' ))) {
$oViewer = $this -> Viewer_GetLocalViewer ();
2011-06-06 14:58:19 +03:00
$oViewer -> Assign ( 'oTopics' , $oTopics );
2012-04-21 07:40:14 +03:00
$sTextResult = $oViewer -> Fetch ( " blocks/block.stream_topic.tpl " );
2010-10-02 13:56:46 +03:00
$this -> Viewer_AssignAjax ( 'sText' , $sTextResult );
2011-06-06 14:58:19 +03:00
} else {
2010-10-02 13:56:46 +03:00
$this -> Message_AddErrorSingle ( $this -> Lang_Get ( 'block_stream_topics_no' ), $this -> Lang_Get ( 'attention' ));
return ;
}
}
/**
* Обработка получения TOP блогов
2012-04-29 17:58:36 +03:00
* Используется в блоке " TOP блогов "
2010-10-02 13:56:46 +03:00
*
*/
protected function EventBlogsTop () {
2012-04-29 17:58:36 +03:00
/**
* Получаем список блогов и формируем ответ
*/
2010-10-02 13:56:46 +03:00
if ( $aResult = $this -> Blog_GetBlogsRating ( 1 , Config :: Get ( 'block.blogs.row' ))) {
$aBlogs = $aResult [ 'collection' ];
$oViewer = $this -> Viewer_GetLocalViewer ();
2011-06-06 14:58:19 +03:00
$oViewer -> Assign ( 'aBlogs' , $aBlogs );
2012-04-21 07:40:14 +03:00
$sTextResult = $oViewer -> Fetch ( " blocks/block.blogs_top.tpl " );
2010-10-02 13:56:46 +03:00
$this -> Viewer_AssignAjax ( 'sText' , $sTextResult );
2011-06-06 14:58:19 +03:00
} else {
2010-10-02 13:56:46 +03:00
$this -> Message_AddErrorSingle ( $this -> Lang_Get ( 'system_error' ), $this -> Lang_Get ( 'error' ));
return ;
}
}
/**
* Обработка получения своих блогов
2012-04-29 17:58:36 +03:00
* Используется в блоке " TOP блогов "
2010-10-02 13:56:46 +03:00
*
*/
protected function EventBlogsSelf () {
2012-04-29 17:58:36 +03:00
/**
* Пользователь авторизован ?
*/
2010-10-02 13:56:46 +03:00
if ( ! $this -> oUserCurrent ) {
$this -> Message_AddErrorSingle ( $this -> Lang_Get ( 'need_authorization' ), $this -> Lang_Get ( 'error' ));
return ;
}
2012-04-29 17:58:36 +03:00
/**
* Получаем список блогов и формируем ответ
*/
2010-10-02 13:56:46 +03:00
if ( $aBlogs = $this -> Blog_GetBlogsRatingSelf ( $this -> oUserCurrent -> getId (), Config :: Get ( 'block.blogs.row' ))) {
$oViewer = $this -> Viewer_GetLocalViewer ();
2011-06-06 14:58:19 +03:00
$oViewer -> Assign ( 'aBlogs' , $aBlogs );
2012-04-21 07:40:14 +03:00
$sTextResult = $oViewer -> Fetch ( " blocks/block.blogs_top.tpl " );
2010-10-02 13:56:46 +03:00
$this -> Viewer_AssignAjax ( 'sText' , $sTextResult );
2011-06-06 14:58:19 +03:00
} else {
2010-10-02 13:56:46 +03:00
$this -> Message_AddErrorSingle ( $this -> Lang_Get ( 'block_blogs_self_error' ), $this -> Lang_Get ( 'attention' ));
return ;
2011-06-06 14:58:19 +03:00
}
2010-10-02 13:56:46 +03:00
}
/**
* Обработка получения подключенных блогов
2012-04-29 17:58:36 +03:00
* Используется в блоке " TOP блогов "
2010-10-02 13:56:46 +03:00
*
*/
protected function EventBlogsJoin () {
2012-04-29 17:58:36 +03:00
/**
* Пользователь авторизован ?
*/
2010-10-02 13:56:46 +03:00
if ( ! $this -> oUserCurrent ) {
$this -> Message_AddErrorSingle ( $this -> Lang_Get ( 'need_authorization' ), $this -> Lang_Get ( 'error' ));
return ;
}
2012-04-29 17:58:36 +03:00
/**
* Получаем список блогов и формируем ответ
*/
2010-10-02 13:56:46 +03:00
if ( $aBlogs = $this -> Blog_GetBlogsRatingJoin ( $this -> oUserCurrent -> getId (), Config :: Get ( 'block.blogs.row' ))) {
$oViewer = $this -> Viewer_GetLocalViewer ();
2011-06-06 14:58:19 +03:00
$oViewer -> Assign ( 'aBlogs' , $aBlogs );
2012-04-21 07:40:14 +03:00
$sTextResult = $oViewer -> Fetch ( " blocks/block.blogs_top.tpl " );
2010-10-02 13:56:46 +03:00
$this -> Viewer_AssignAjax ( 'sText' , $sTextResult );
2011-06-06 14:58:19 +03:00
} else {
2010-10-02 13:56:46 +03:00
$this -> Message_AddErrorSingle ( $this -> Lang_Get ( 'block_blogs_join_error' ), $this -> Lang_Get ( 'attention' ));
return ;
2011-06-06 14:58:19 +03:00
}
2010-10-02 13:56:46 +03:00
}
2013-04-12 06:44:36 +03:00
/**
* Загружает список блогов конкретной категории
*/
protected function EventBlogsGetByCategory () {
if ( ! ( $oCategory = $this -> Blog_GetCategoryById ( getRequestStr ( 'id' )))) {
2014-01-28 09:47:36 +02:00
return $this -> EventErrorDebug ();
2013-04-12 06:44:36 +03:00
}
/**
* Получаем все дочерние категории
*/
$aCategoriesId = $this -> Blog_GetChildrenCategoriesById ( $oCategory -> getId (), true );
$aCategoriesId [] = $oCategory -> getId ();
/**
* Формируем фильтр для получения списка блогов
*/
$aFilter = array (
'exclude_type' => 'personal' ,
'category_id' => $aCategoriesId
);
/**
* Получаем список блогов ( все по фильтру )
*/
$aResult = $this -> Blog_GetBlogsByFilter ( $aFilter , array ( 'blog_title' => 'asc' ), 1 , PHP_INT_MAX );
$aBlogs = $aResult [ 'collection' ];
/**
* Получаем список блогов и формируем ответ
*/
if ( $aBlogs ) {
$aResult = array ();
foreach ( $aBlogs as $oBlog ) {
$aResult [] = array (
'id' => $oBlog -> getId (),
'title' => htmlspecialchars ( $oBlog -> getTitle ()),
'category_id' => $oBlog -> getCategoryId (),
'type' => $oBlog -> getType (),
'rating' => $oBlog -> getRating (),
'url' => $oBlog -> getUrl (),
'url_full' => $oBlog -> getUrlFull (),
);
}
$this -> Viewer_AssignAjax ( 'aBlogs' , $aResult );
} else {
2014-01-25 14:39:19 +02:00
$this -> Message_AddErrorSingle ( $this -> Lang_Get ( 'blog.categories.empty' ), $this -> Lang_Get ( 'attention' ));
2013-04-12 06:44:36 +03:00
return ;
}
}
2010-10-02 17:33:51 +03:00
/**
* Предпросмотр текста
*
*/
protected function EventPreviewText () {
2012-12-12 08:06:38 +02:00
$sText = getRequestStr ( 'text' , null , 'post' );
2010-10-02 17:33:51 +03:00
$bSave = getRequest ( 'save' , null , 'post' );
2012-04-29 17:58:36 +03:00
/**
* Экранировать или нет HTML теги
*/
2010-10-02 17:33:51 +03:00
if ( $bSave ) {
$sTextResult = htmlspecialchars ( $sText );
} else {
$sTextResult = $this -> Text_Parser ( $sText );
}
2012-04-29 17:58:36 +03:00
/**
* Передаем результат в ajax ответ
*/
2010-10-02 17:33:51 +03:00
$this -> Viewer_AssignAjax ( 'sText' , $sTextResult );
}
2010-10-03 14:47:14 +03:00
/**
* Автоподставновка тегов
*
*/
protected function EventAutocompleterTag () {
2012-04-29 17:58:36 +03:00
/**
* Первые буквы тега переданы ?
*/
2012-07-08 11:50:36 +03:00
if ( ! ( $sValue = getRequest ( 'value' , null , 'post' )) or ! is_string ( $sValue )) {
2010-10-03 14:47:14 +03:00
return ;
}
$aItems = array ();
2012-04-29 17:58:36 +03:00
/**
* Формируем список тегов
*/
2010-10-03 14:47:14 +03:00
$aTags = $this -> Topic_GetTopicTagsByLike ( $sValue , 10 );
foreach ( $aTags as $oTag ) {
$aItems [] = $oTag -> getText ();
}
2012-04-29 17:58:36 +03:00
/**
* Передаем результат в ajax ответ
*/
2010-10-03 14:47:14 +03:00
$this -> Viewer_AssignAjax ( 'aItems' , $aItems );
}
/**
* Автоподставновка пользователей
*
*/
protected function EventAutocompleterUser () {
2012-04-29 17:58:36 +03:00
/**
* Первые буквы логина переданы ?
*/
2012-07-08 11:50:36 +03:00
if ( ! ( $sValue = getRequest ( 'value' , null , 'post' )) or ! is_string ( $sValue )) {
2010-10-03 14:47:14 +03:00
return ;
}
$aItems = array ();
2012-04-29 17:58:36 +03:00
/**
* Формируем список пользователей
*/
2010-10-03 14:47:14 +03:00
$aUsers = $this -> User_GetUsersByLoginLike ( $sValue , 10 );
foreach ( $aUsers as $oUser ) {
$aItems [] = $oUser -> getLogin ();
}
2012-04-29 17:58:36 +03:00
/**
* Передаем результат в ajax ответ
*/
2010-10-03 14:47:14 +03:00
$this -> Viewer_AssignAjax ( 'aItems' , $aItems );
}
2010-10-03 15:48:39 +03:00
/**
* Удаление / восстановление комментария
*
*/
protected function EventCommentDelete () {
2012-04-29 17:58:36 +03:00
/**
* Есть права на удаление комментария ?
*/
2011-09-26 16:00:27 +03:00
if ( ! $this -> ACL_CanDeleteComment ( $this -> oUserCurrent )) {
2010-10-03 15:48:39 +03:00
$this -> Message_AddErrorSingle ( $this -> Lang_Get ( 'not_access' ), $this -> Lang_Get ( 'error' ));
return ;
}
2012-04-29 17:58:36 +03:00
/**
* Комментарий существует ?
*/
2012-12-12 08:06:38 +02:00
$idComment = getRequestStr ( 'idComment' , null , 'post' );
2010-10-03 15:48:39 +03:00
if ( ! ( $oComment = $this -> Comment_GetCommentById ( $idComment ))) {
2014-01-28 09:47:36 +02:00
return $this -> EventErrorDebug ();
2010-10-03 15:48:39 +03:00
}
2012-04-29 17:58:36 +03:00
/**
* Устанавливаем пометку о том , что комментарий удален
*/
2010-10-03 15:48:39 +03:00
$oComment -> setDelete (( $oComment -> getDelete () + 1 ) % 2 );
2012-04-28 11:47:46 +03:00
$this -> Hook_Run ( 'comment_delete_before' , array ( 'oComment' => $oComment ));
2010-10-03 15:48:39 +03:00
if ( ! $this -> Comment_UpdateCommentStatus ( $oComment )) {
$this -> Message_AddErrorSingle ( $this -> Lang_Get ( 'system_error' ), $this -> Lang_Get ( 'error' ));
return ;
}
2012-04-28 11:47:46 +03:00
$this -> Hook_Run ( 'comment_delete_after' , array ( 'oComment' => $oComment ));
2012-04-29 17:58:36 +03:00
/**
* Формируем текст ответа
*/
2010-10-03 15:48:39 +03:00
if ( $bState = ( bool ) $oComment -> getDelete ()) {
$sMsg = $this -> Lang_Get ( 'comment_delete_ok' );
$sTextToggle = $this -> Lang_Get ( 'comment_repair' );
} else {
$sMsg = $this -> Lang_Get ( 'comment_repair_ok' );
$sTextToggle = $this -> Lang_Get ( 'comment_delete' );
}
2011-09-16 15:05:42 +03:00
/**
* Обновление события в ленте активности
*/
$this -> Stream_write ( $oComment -> getUserId (), 'add_comment' , $oComment -> getId (), ! $oComment -> getDelete ());
2012-04-29 17:58:36 +03:00
/**
* Показываем сообщение и передаем переменные в ajax ответ
*/
2010-10-03 15:48:39 +03:00
$this -> Message_AddNoticeSingle ( $sMsg , $this -> Lang_Get ( 'attention' ));
$this -> Viewer_AssignAjax ( 'bState' , $bState );
$this -> Viewer_AssignAjax ( 'sTextToggle' , $sTextToggle );
}
2014-01-28 09:47:36 +02:00
}