AntonLV 6 лет назад
Родитель
Сommit
b2fd8bfab2

+ 16 - 3
inc/classes/BxDolCmts.php

@@ -611,7 +611,7 @@ class BxDolCmts extends BxDolFactory implements iBxDolReplaceable, iBxDolContent
         return $this->_oQuery->getTableName ();
     }
 
-	public function getObjectAuthorId ($iObjectId = 0)
+    public function getObjectAuthorId ($iObjectId = 0)
     {
     	if(empty($this->_aSystem['trigger_field_author']))
     		return 0;
@@ -646,6 +646,14 @@ class BxDolCmts extends BxDolFactory implements iBxDolReplaceable, iBxDolContent
         return $this->_oQuery->getComments ($this->getId(), $iVParentId, $this->_getAuthorId(), $sFilter, $aOrder, $iStart, $iCount);
     }
 
+    /**
+     * Get comment's unique id.
+     */
+    public function getCommentUniqId($iCmtId, $iAuthorId = 0)
+    {
+        return $this->_oQuery->getUniqId($this->getSystemId(), $iCmtId, $iAuthorId);
+    }
+
     /**
      * Get comment's short info.
      */
@@ -778,6 +786,11 @@ class BxDolCmts extends BxDolFactory implements iBxDolReplaceable, iBxDolContent
     /**
      * Permissions functions
      */
+    public function isAdmin($iCmtAuthorId)
+    {
+        return BxDolAcl::getInstance()->isMemberLevelInSet(array(MEMBERSHIP_ID_MODERATOR, MEMBERSHIP_ID_ADMINISTRATOR), $iCmtAuthorId);
+    }
+
     public function checkAction ($sAction, $isPerformAction = false)
     {
         $iId = $this->_getAuthorId();
@@ -1243,7 +1256,7 @@ class BxDolCmts extends BxDolFactory implements iBxDolReplaceable, iBxDolContent
         $iObjId = (int)$this->getId();
     	$iObjAthrId = $this->getObjectAuthorId($iObjId);
 
-    	$aCmt = $this->_oQuery->getCommentSimple($iObjId, $iCmtId);
+    	$aCmt = $this->getCommentRow($iCmtId);
         if(empty($aCmt) || !is_array($aCmt))
             return false;
 
@@ -1272,7 +1285,7 @@ class BxDolCmts extends BxDolFactory implements iBxDolReplaceable, iBxDolContent
             'comment_text' => $aCmt['cmt_text']
         ));
 
-        return array('id' => $iCmtId, 'text' => $this->_prepareTextForOutput($aCmt['cmt_text'], $iCmtId));
+        return array('id' => $iCmtId, 'content' => $this->_getContent($aCmt));
     }
 
     public function serviceGetAuthor ($iContentId)

+ 18 - 8
inc/classes/BxDolCmtsQuery.php

@@ -386,20 +386,30 @@ class BxDolCmtsQuery extends BxDolDb
         return $this->getAll($sQuery, $aBindings);
     }
 
-    function deleteImages($iSystemId, $iCmtId)
+    function deleteImages($iSystemId, $iCmtId, $iImageId = false)
     {
-    	$aBindings = array(
-    		'system_id' => $iSystemId
-    	);
-
         $sWhereAddon = "";
+        $aBindings = array();
+
+        if ($iSystemId !== false) {
+            $aBindings['system_id'] = $iSystemId;
+
+            $sWhereAddon .= " AND `system_id` = :system_id ";
+        }
+
         if ($iCmtId !== false) {
-        	$aBindings['cmt_id'] = $iCmtId;
+            $aBindings['cmt_id'] = $iCmtId;
+
+            $sWhereAddon .= " AND `cmt_id` = :cmt_id ";
+        }
+
+        if ($iImageId !== false) {
+            $aBindings['image_id'] = $iImageId;
 
-            $sWhereAddon = " AND `cmt_id` = :cmt_id ";
+            $sWhereAddon .= " AND `image_id` = :image_id ";
         }
 
-        return $this->query("DELETE FROM `{$this->_sTableFiles2Entries}` WHERE `system_id` = :system_id" . $sWhereAddon, $aBindings);
+        return $this->query("DELETE FROM `{$this->_sTableFiles2Entries}` WHERE 1" . $sWhereAddon, $aBindings);
     }
 
     function updateRepliesCount($iCmtId, $iCount)

+ 27 - 25
inc/js/classes/BxDolCmts.js

@@ -141,28 +141,28 @@ BxDolCmts.prototype.cmtInitFormEdit = function(sCmtFormId)
 	oCmtForm.ajaxForm({
         dataType: "json",
         beforeSubmit: function (formData, jqForm, options) {
-        	window[$this._sObjName].cmtBeforeEditSubmit(oCmtForm);
+            window[$this._sObjName].cmtBeforeEditSubmit(oCmtForm);
         },
         success: function (oData) {
-        	window[$this._sObjName].cmtAfterEditSubmit(oCmtForm, oData);
+            window[$this._sObjName].cmtAfterEditSubmit(oCmtForm, oData);
         }
     });
 };
 
 BxDolCmts.prototype.cmtBeforeEditSubmit = function(oCmtForm)
 {
-	this._loadingInButton($(oCmtForm).children().find(':submit'), true);
+    this._loadingInButton($(oCmtForm).children().find(':submit'), true);
 };
 
 BxDolCmts.prototype.cmtAfterEditSubmit = function (oCmtForm, oData, onComplete)
 {
     var $this = this;
     var fContinue = function() {
-        if(oData && oData.id != undefined && oData.text != undefined) {
+        if(oData && oData.id != undefined && oData.content != undefined) {
             var iCmtId = parseInt(oData.id);
             if(iCmtId > 0) {
-                $('#cmt' + iCmtId + ' .cmt-body').bx_anim('hide', $this._sAnimationEffect, $this._iAnimationSpeed, function() {
-                    $(this).html(oData.text).bx_anim('show', $this._sAnimationEffect, $this._iAnimationSpeed);
+                $('#cmt' + iCmtId + ' .cmt-cont-cnt:first').bx_anim('hide', $this._sAnimationEffect, $this._iAnimationSpeed, function() {
+                    $(this).html(oData.content).bx_anim('show', $this._sAnimationEffect, $this._iAnimationSpeed);
                 });
             }
         }
@@ -181,49 +181,51 @@ BxDolCmts.prototype.cmtAfterEditSubmit = function (oCmtForm, oData, onComplete)
     if(oData && oData.msg != undefined)
         bx_alert(oData.msg, fContinue);
     else 
-            fContinue();
+        fContinue();
 };
 
 BxDolCmts.prototype.cmtEdit = function(oLink, iCmtId) {
     var $this = this;
-    var oParams = this._getDefaultActions();
-    oParams['action'] = 'GetFormEdit';
-    oParams['Cmt'] = iCmtId;
 
     $(oLink).parents('.bx-popup-applied:first:visible').dolPopupHide();
 
-    var sBodyId = this._sRootId + ' #cmt' + iCmtId + ' .cmt-body:first';
-    if ($(sBodyId + ' > form').length) {
-        $(sBodyId).bx_anim('hide', $this._sAnimationEffect, $this._iAnimationSpeed, function() {
+    var sContentId = this._sRootId + ' #cmt' + iCmtId + ' .cmt-cont-cnt:first';
+    if ($(sContentId + ' > form').length) {
+        $(sContentId).bx_anim('hide', $this._sAnimationEffect, $this._iAnimationSpeed, function() {
             $(this).html($this._oSavedTexts[iCmtId]).bx_anim('show', $this._sAnimationEffect, $this._iAnimationSpeed);
         });
+
         return;
     }
-    else
-        this._oSavedTexts[iCmtId] = $(sBodyId).html();
 
-    this._loadingInContent (oLink, true);
+    var oParams = this._getDefaultActions();
+    oParams['action'] = 'GetFormEdit';
+    oParams['Cmt'] = iCmtId;
+
+    this._oSavedTexts[iCmtId] = $(sContentId).html();
+
+    this._loadingInContent(oLink, true);
 
     jQuery.post (
         this._sActionsUrl,
         oParams,
         function (oData) {
-        	var fContinue = function() {
-        		if(oData && oData.form != undefined && oData.form_id != undefined) {
-            		$(sBodyId).bx_anim('hide', $this._sAnimationEffect, $this._iAnimationSpeed, function() {
+            var fContinue = function() {
+                if(oData && oData.form != undefined && oData.form_id != undefined) {
+                    $(sContentId).bx_anim('hide', $this._sAnimationEffect, $this._iAnimationSpeed, function() {
                         $(this).html(oData.form).bx_anim('show', $this._sAnimationEffect, $this._iAnimationSpeed, function() {
-                        	$this.cmtInitFormEdit(oData.form_id);
+                            $this.cmtInitFormEdit(oData.form_id);
                         });
                     });
             	}
-        	};
+            };
 
-        	$this._loadingInContent (oLink, false);
+            $this._loadingInContent(oLink, false);
 
-        	if(oData && oData.msg != undefined)
+            if(oData && oData.msg != undefined)
                 bx_alert(oData.msg, fContinue);
-        	else
-        		fContinue();
+            else
+                fContinue();
         },
         'json'
     );

Разница между файлами не показана из-за своего большого размера
+ 18 - 13
install/sql/system.sql


+ 1 - 7
template/comment.html

@@ -15,13 +15,7 @@
                 <bx_if:meta><span class="__style_prefix__-meta">__meta__</span></bx_if:meta>
             </div>
             <div class="__style_prefix__-cont bx-def-margin-sec-topbottom">
-                <div class="__style_prefix__-cont-cnt">
-                    <div class="__style_prefix__-body bx-def-margin-sec-top">__text__<bx_if:show_more><span class="__style_prefix__-body-see-more">... <a class="bx-def-font-small" href="javascript:void(0)" onclick="__js_object__.showMore(this);"><bx_text:_see_more /></a></span><span style="display:none;"> __text_more__</span></bx_if:show_more></div>
-                    <bx_if:show_attached>
-                        <div class="__style_prefix__-attached bx-def-margin-thd-leftright-neg bx-clearfix">__attached__</div>
-                    </bx_if:show_attached>
-                    <div class="__style_prefix__-reactions">__reactions__</div>
-                </div>
+                <div class="__style_prefix__-cont-cnt">__content__</div>
             </div>
             __actions__
         </div>

+ 5 - 0
template/comment_content.html

@@ -0,0 +1,5 @@
+<div class="__style_prefix__-body bx-def-margin-sec-top">__text__<bx_if:show_more><span class="__style_prefix__-body-see-more">... <a class="bx-def-font-small" href="javascript:void(0)" onclick="__js_object__.showMore(this);"><bx_text:_see_more /></a></span><span style="display:none;"> __text_more__</span></bx_if:show_more></div>
+<bx_if:show_attached>
+    <div class="__style_prefix__-attached bx-def-margin-thd-leftright-neg bx-clearfix">__attached__</div>
+</bx_if:show_attached>
+<div class="__style_prefix__-reactions">__reactions__</div>

+ 6 - 6
template/comments_uploader_nfw.html

@@ -1,9 +1,9 @@
-<div id="bx-uploader-file-{storage_object}-{file_id}" class="cmts-uploader-file bx-def-margin-sec-top bx-def-margin-sec-left-auto">
-    <div class="cmts-uploader-file-preview bx-def-round-corners">
-    	<img src="<bx_image_url:spacer.gif />" style="background-image:url({file_icon})" />
+<div id="bx-uploader-file-{storage_object}-{file_id}" class="bx-uploader-ghost cmts-uploader-file bx-def-margin-sec-top bx-def-margin-sec-left-auto">
+    <input type="hidden" name="__name__[]" value="{file_id}" />
+    <div class="cmts-uploader-file-preview bx-def-round-corners bx-def-margin-sec-right">
+        <img src="{file_icon}" class="bx-def-round-corners bx-base-general-icon bx-base-general-icon-{file_id}" />
     </div>
     <div class="cmts-uploader-file-actions bx-def-margin-thd-top bx-clearfix">
-    	<a class="bx-btn bx-btn-small" href="javascript:void(0);" onclick="{js_instance_name}.deleteGhost('{file_id}')"><bx_text:_Delete /></a>
-    	__nested_form__
+        <a class="bx-btn bx-btn-small bx-def-margin-sec-right" href="javascript:void(0);" onclick="{js_instance_name}.deleteGhost('{file_id}');"><bx_text:_Delete /></a>
     </div>
-</div>
+</div>

+ 57 - 49
template/scripts/BxBaseCmts.php

@@ -18,6 +18,7 @@ class BxBaseCmts extends BxDolCmts
     protected static $_sTmplContentCounter;
 
     protected $_sTmplNameItem;
+    protected $_sTmplNameItemContent;
 
     protected $_sJsObjClass;
     protected $_sJsObjName;
@@ -34,7 +35,8 @@ class BxBaseCmts extends BxDolCmts
             return;
 
         $this->_sTmplNameItem = 'comment.html';
-                
+        $this->_sTmplNameItemContent = 'comment_content.html';
+
         $this->_sJsObjClass = 'BxDolCmts';
         $this->_sJsObjName = 'oCmts' . bx_gen_method_name($sSystem, array('_' , '-')) . $iId;
         $this->_sStylePrefix = isset($this->_aSystem['root_style_prefix']) ? $this->_aSystem['root_style_prefix'] : 'cmt';
@@ -265,8 +267,6 @@ class BxBaseCmts extends BxDolCmts
             );
         }
 
-        $sAttachments = $this->_getAttachments($aCmt);
-
         $sReplies = '';
         if((int)$aCmt['cmt_replies'] > 0 && !empty($aDp) && $aDp['type'] == BX_CMT_DISPLAY_THREADED) {
         	$aDp['show_empty'] = false;
@@ -286,11 +286,7 @@ class BxBaseCmts extends BxDolCmts
             }
         }
 
-        $sReactions = '';
-        if(($oReaction = $this->getReactionObject($aCmt['cmt_unique_id'])) !== false)
-            $sReactions = $oReaction->getCounter(array(
-                'show_counter' => true
-            ));
+        $sContent = $this->_getContent($aCmt);
 
         return $this->_oTemplate->parseHtmlByName($this->_sTmplNameItem, array_merge(array(
             'system' => $this->_sSystem,
@@ -308,17 +304,10 @@ class BxBaseCmts extends BxDolCmts
                 'condition' => !empty($aTmplVarsMeta),
                 'content' => $aTmplVarsMeta
             ),
-            'bx_if:show_attached' => array(
-                'condition' => !empty($sAttachments),
-                'content' => array(
-                    'style_prefix' => $this->_sStylePrefix,
-                    'attached' => $sAttachments
-                )
-            ),
-            'reactions' => $sReactions,
+            'content' => $sContent,
             'actions' => $sActions,
             'replies' =>  $sReplies,
-        ), $this->_getTmplVarsAuthor($aCmt), $this->_getTmplVarsText($aCmt)));
+        ), $this->_getTmplVarsAuthor($aCmt)));
     }
 
     function getCommentSearch($iCmtId, &$sAddon)
@@ -880,16 +869,8 @@ class BxBaseCmts extends BxDolCmts
             if($iCmtId != 0) {
                 $iCmtUniqId = $this->_oQuery->getUniqId($this->_aSystem['system_id'], $iCmtId, $iCmtAuthorId);
 
-                if($this->isAttachImageEnabled()) {
-                    $aImages = $oForm->getCleanValue('cmt_image');
-                    if(!empty($aImages) && is_array($aImages)) {
-                        $oStorage = BxDolStorage::getObjectInstance($this->getStorageObjectName());
-
-                        foreach($aImages as $iImageId)
-                            if($this->_oQuery->saveImages($this->_aSystem['system_id'], $iCmtId, $iImageId))
-                                $oStorage->afterUploadCleanup($iImageId, $iCmtAuthorId);
-                    }
-                }
+                if($this->isAttachImageEnabled())
+                    $oForm->processImages($this, 'cmt_image', $iCmtUniqId, $iCmtId, $iCmtAuthorId, true);
 
                 if($iCmtParentId) {
                     $this->_oQuery->updateRepliesCount($iCmtParentId, 1);
@@ -939,6 +920,9 @@ class BxBaseCmts extends BxDolCmts
             if($oForm->update($iCmtId) !== false) {
                 $iCmtUniqId = $this->_oQuery->getUniqId($this->_aSystem['system_id'], $iCmtId, (int)$aCmt['cmt_author_id']);
 
+                if($this->isAttachImageEnabled())
+                    $oForm->processImages($this, 'cmt_image', $iCmtUniqId, $iCmtId, $iCmtAuthorId, false);
+
                 $this->isEditAllowed($aCmt, true);
 
                 if($this->_sMetatagsObj && ($oMetatags = BxDolMetatags::getObjectInstance($this->_sMetatagsObj)) !== false)
@@ -980,6 +964,30 @@ class BxBaseCmts extends BxDolCmts
         return $oForm;
     }
 
+    protected function _getContent($aCmt)
+    {
+        $sAttachments = $this->_getAttachments($aCmt);
+
+        $sReactions = '';
+        if(($oReaction = $this->getReactionObject($aCmt['cmt_unique_id'])) !== false)
+            $sReactions = $oReaction->getCounter(array(
+                'show_counter' => true
+            ));
+
+        return $this->_oTemplate->parseHtmlByName($this->_sTmplNameItemContent, array_merge(array(
+            'style_prefix' => $this->_sStylePrefix,
+            'js_object' => $this->_sJsObjName,
+            'bx_if:show_attached' => array(
+                'condition' => !empty($sAttachments),
+                'content' => array(
+                    'style_prefix' => $this->_sStylePrefix,
+                    'attached' => $sAttachments
+                )
+            ),
+            'reactions' => $sReactions,
+        ), $this->_getTmplVarsText($aCmt)));
+    }
+
     protected function _getMoreLink($sCmts, $aBp = array(), $aDp = array())
     {
         $iStart = $iPerView = 0;
@@ -1057,7 +1065,7 @@ class BxBaseCmts extends BxDolCmts
     {
     	$sViewImagePopupId = 'cmts-box-' . $this->_sSystem . '-' . $this->getId() . '-view-image-popup' ;
         $sViewImagePopupContent = $this->_oTemplate->parseHtmlByName('popup_image.html', array(
-    		'image_url' => ''
+            'image_url' => ''
     	));
 
     	return BxTemplFunctions::getInstance()->transBox($sViewImagePopupId, $sViewImagePopupContent, true);
@@ -1071,38 +1079,38 @@ class BxBaseCmts extends BxDolCmts
 
         $aFiles = $this->_oQuery->getFiles($this->_aSystem['system_id'], $aCmt['cmt_id']);
         if(!empty($aFiles) && is_array($aFiles)) {
-    		$oStorage = BxDolStorage::getObjectInstance($this->getStorageObjectName());
+            $oStorage = BxDolStorage::getObjectInstance($this->getStorageObjectName());
             $oTranscoder = BxDolTranscoderImage::getObjectInstance($this->getTranscoderPreviewName());
 
             foreach($aFiles as $aFile) {
-            	$bImage = $oTranscoder && $oTranscoder->isMimeTypeSupported($aFile['mime_type']);
+                $bImage = $oTranscoder && $oTranscoder->isMimeTypeSupported($aFile['mime_type']);
 
-            	$sPreview = '';
-            	if($oTranscoder && $bImage)
-            		$sPreview = $oTranscoder->getFileUrl($aFile['image_id']);
+                $sPreview = '';
+                if($oTranscoder && $bImage)
+                    $sPreview = $oTranscoder->getFileUrl($aFile['image_id']);
 
-        		if(!$sPreview)
-            		$sPreview = $this->_oTemplate->getIconUrl($oStorage->getIconNameByFileName($aFile['file_name']));
+                if(!$sPreview)
+                    $sPreview = $this->_oTemplate->getIconUrl($oStorage->getIconNameByFileName($aFile['file_name']));
 
-				$aTmplVarsFile = array(
-				    'js_object' => $this->_sJsObjName,
-					'preview' => $sPreview,
-					'file' => $oStorage->getFileUrlById($aFile['image_id']),
-        			'file_name' => $aFile['file_name'],
+                $aTmplVarsFile = array(
+                    'js_object' => $this->_sJsObjName,
+                    'preview' => $sPreview,
+                    'file' => $oStorage->getFileUrlById($aFile['image_id']),
+                    'file_name' => $aFile['file_name'],
                     'file_icon' => $oStorage->getFontIconNameByFileName($aFile['file_name']),
-				    'file_size' => _t_format_size($aFile['size']),
-				);
+                    'file_size' => _t_format_size($aFile['size']),
+                );
 
                 $aTmplImages[] = array(
                     'style_prefix' => $this->_sStylePrefix,
-                	'bx_if:show_image' => array(
-                		'condition' => $bImage,
-                		'content' => $aTmplVarsFile
-                	),
+                    'bx_if:show_image' => array(
+                        'condition' => $bImage,
+                        'content' => $aTmplVarsFile
+                    ),
                     'bx_if:show_file' => array(
-                		'condition' => !$bImage,
-                		'content' => $aTmplVarsFile
-                	),
+                        'condition' => !$bImage,
+                        'content' => $aTmplVarsFile
+                    ),
                 );
             }
         }

+ 86 - 13
template/scripts/BxBaseCmtsForm.php

@@ -11,7 +11,11 @@ class BxBaseCmtsForm extends BxTemplFormView
 {
     protected static $_sAttributeMaskId;
     protected static $_sAttributeMaskName;
-    
+
+    protected $_oObject;
+
+    protected $_sGhostTemplateImage;
+
     public function __construct($aInfo, $oTemplate)
     {
         parent::__construct($aInfo, $oTemplate);
@@ -22,22 +26,19 @@ class BxBaseCmtsForm extends BxTemplFormView
         if(empty(self::$_sAttributeMaskName))
             self::$_sAttributeMaskName = $this->aFormAttrs['name'];
 
-    	if(isset($this->aInputs['cmt_image'])) {
-            $aFormNested = array(
-                'params' =>array(
-                    'nested_form_template' => 'comments_uploader_nfw.html'
-                ),
-                'inputs' => array(),
-            );
+        $this->_oObject = null;
 
-            $oFormNested = new BxDolFormNested('cmt_image', $aFormNested, 'cmt_submit');
+        $this->_sGhostTemplateImage = 'comments_uploader_nfw.html';
 
+    	if(isset($this->aInputs['cmt_image'])) {
             $this->aInputs['cmt_image']['storage_object'] = 'sys_cmts_images';
             $this->aInputs['cmt_image']['images_transcoder'] = 'sys_cmts_images_preview';
             $this->aInputs['cmt_image']['uploaders'] = !empty($this->aInputs['cmt_image']['value']) ? unserialize($this->aInputs['cmt_image']['value']) : array('sys_cmts_simple');
             $this->aInputs['cmt_image']['upload_buttons_titles'] = array('Simple' => 'camera');
+            $this->aInputs['cmt_image']['storage_private'] = 0;
             $this->aInputs['cmt_image']['multiple'] = true;
-            $this->aInputs['cmt_image']['ghost_template'] = $oFormNested;
+            $this->aInputs['cmt_image']['content_id'] = 0;
+            $this->aInputs['cmt_image']['ghost_template'] = '';
         }
     }
 
@@ -47,7 +48,7 @@ class BxBaseCmtsForm extends BxTemplFormView
         return isset(self::$$sName) ? self::$$sName : '';
     }
 
-	public function getStorageObjectName()
+    public function getStorageObjectName()
     {
         return isset($this->aInputs['cmt_image']['storage_object']) ? $this->aInputs['cmt_image']['storage_object'] : '';
     }
@@ -59,6 +60,16 @@ class BxBaseCmtsForm extends BxTemplFormView
     
     function initChecker ($aValues = array (), $aSpecificValues = array())
     {
+        if(isset($this->aInputs['cmt_image'])) {
+            if(!empty($this->aInputs['sys']['value']) && !empty($this->aInputs['id']['value']) && !empty($aValues['cmt_id'])) {
+                $oObject = $this->_getObject(bx_process_input($this->aInputs['sys']['value']), (int)$this->aInputs['id']['value']);
+                if($oObject)
+                    $this->aInputs['cmt_image']['content_id'] = $oObject->getCommentUniqId($aValues['cmt_id']);
+            }
+
+            $this->aInputs['cmt_image']['ghost_template'] = $this->oTemplate->parseHtmlByName($this->_sGhostTemplateImage, $this->_getGhostTmplVarsImage());
+        }
+
         if (isset($this->aInputs['cmt_anonymous']) && isset($aValues['cmt_author_id']))
             $this->aInputs['cmt_anonymous']['checked'] = $aValues['cmt_author_id'] < 0;
         
@@ -72,16 +83,78 @@ class BxBaseCmtsForm extends BxTemplFormView
         return parent::insert ($aValsToAdd, $isIgnore);
     }
 
-    function update ($iCmtId, $aValsToAdd = array(), &$aTrackTextFieldsChanges = null)
+    public function update ($iCmtId, $aValsToAdd = array(), &$aTrackTextFieldsChanges = null)
     {
         if (isset($this->aInputs['cmt_anonymous'])) {
-            $aCmt = BxDolCmts::getObjectInstance($this->getCleanValue('sys'), $this->getCleanValue('id'))->getCommentRow($iCmtId);
+            $aCmt = $this->_getObject($this->getCleanValue('sys'), $this->getCleanValue('id'))->getCommentRow($iCmtId);
 
             $aValsToAdd['cmt_author_id'] = ($this->getCleanValue('cmt_anonymous') ? -1 : 1) * abs($aCmt['cmt_author_id']);
         }
 
         return parent::update ($iCmtId, $aValsToAdd, $aTrackTextFieldsChanges);
     }
+    
+    public function processImages ($oCmts, $sFieldName, $iCmtUniqId, $iCmtId, $iCmtAuthorId, $isAssociateWithContent = false)
+    {
+        if(!isset($this->aInputs[$sFieldName]))
+            return true;
+
+        $mixedFileIds = $this->getCleanValue($sFieldName);
+        if(!$mixedFileIds)
+            return true;
+
+        $oStorage = BxDolStorage::getObjectInstance($this->aInputs[$sFieldName]['storage_object']);
+        if(!$oStorage)
+            return false;
+
+        $aGhostImages = $oStorage->getGhosts($iCmtAuthorId, $isAssociateWithContent ? 0 : $iCmtUniqId, true, $oCmts->isAdmin($iCmtAuthorId));
+        if(!$aGhostImages)
+            return true;
+
+        foreach($aGhostImages as $aImage) {
+            if(is_array($mixedFileIds) && !in_array($aImage['id'], $mixedFileIds))
+                continue;
+
+            if($aImage['private'])
+                $oStorage->setFilePrivate($aImage['id'], 1);
+
+            if($iCmtId)
+                $this->_associalImageWithContent($oCmts, $sFieldName, $iCmtUniqId, $iCmtId, $iCmtAuthorId, $aImage['id']);
+        }
+
+        return true;
+    }
+
+    protected function _getObject($sSystem, $iId)
+    {
+        if(empty($this->_oObject))
+            $this->_oObject = BxDolCmts::getObjectInstance($sSystem, $iId);
+
+        return $this->_oObject;
+    }
+
+    protected function _getGhostTmplVarsImage($aCmt = array())
+    {
+    	return array (
+            'name' => $this->aInputs['cmt_image']['name'],
+            'content_id' => (int)$this->aInputs['cmt_image']['content_id'],
+            'editor_id' => '',
+        );
+    }
+
+    protected function _associalImageWithContent($oCmts, $sFieldName, $iCmtUniqId, $iCmtId, $iCmtAuthorId, $iImageId)
+    {
+        $oStorage = BxDolStorage::getObjectInstance($this->aInputs[$sFieldName]['storage_object']);
+        if(!$oStorage)
+            return false;
+
+        $oStorage->updateGhostsContentId($iImageId, $iCmtAuthorId, $iCmtUniqId, $oCmts->isAdmin($iCmtAuthorId));
+
+        $aSystem = $oCmts->getSystemInfo();
+        $oCmts->getQueryObject()->saveImages($aSystem['system_id'], $iCmtId, $iImageId);
+
+        return true;
+    }
 }
 
 /** @} */

+ 15 - 0
template/scripts/BxBaseCmtsServices.php

@@ -17,6 +17,21 @@ class BxBaseCmtsServices extends BxDol
         parent::__construct();
     }
 
+    public function serviceAlertResponseSysCmtsImagesFileDeleted($oAlert)
+    {
+        $iUniqId = (int)$oAlert->aExtras['ghost']['content_id'];
+
+        $aCmt = BxDolCmts::getGlobalInfo($iUniqId);
+        if(empty($aCmt) || !is_array($aCmt))
+            return;
+
+        $oCmts = BxDolCmts::getObjectInstance($aCmt['system_name'], 0, false);
+        if(!$oCmts)
+            return;
+
+        $oCmts->getQueryObject()->deleteImages($aCmt['system_id'], false, $oAlert->iObject);
+    }
+
     public function serviceGetMenuItemAddonVote($sSystem, $iId, $iCmtId)
     {
         $oCmts = BxDolCmts::getObjectInstance($sSystem, $iId);

Некоторые файлы не были показаны из-за большого количества измененных файлов