فهرست منبع

#1 - Comments
1. Comments list anchor.
2. Enable/Disable image uploading.
3. Post form initialization fix.

AntonLV 13 سال پیش
والد
کامیت
16c7ec5db0
5فایلهای تغییر یافته به همراه114 افزوده شده و 85 حذف شده
  1. 62 43
      inc/classes/BxDolCmts.php
  2. 8 6
      inc/js/classes/BxDolCmts.js
  3. 0 5
      template/comment_reply_box.html
  4. 1 0
      template/comments_block.html
  5. 43 31
      template/scripts/BxBaseCmtsView.php

+ 62 - 43
inc/classes/BxDolCmts.php

@@ -144,6 +144,7 @@ class BxDolCmts extends BxDol
 
 	protected $_sViewUrl = '';
 	protected $_sBaseUrl = '';
+	protected $_sListAnchor = '';
 
 	protected $_sSystem = 'profile'; ///< current comment system name
     protected $_aSystem = array (); ///< current comments system array
@@ -203,6 +204,7 @@ class BxDolCmts extends BxDol
         $this->_sBaseUrl = $this->_aSystem['base_url'];
         if(get_mb_substr($this->_sBaseUrl, 0, 4) != 'http')
         	$this->_sBaseUrl = BX_DOL_URL_ROOT . $this->_sBaseUrl;
+		$this->_sListAnchor = "cmts-anchor-%s-%d";
 
 		$this->_oQuery = new BxDolCmtsQuery($this);
 
@@ -285,7 +287,7 @@ class BxDolCmts extends BxDol
         return $GLOBALS['bx_dol_cmts_systems'];
     }
 
-    function init ($iId)
+    public function init ($iId)
     {
         if (!$this->isEnabled()) 
         	return;
@@ -299,63 +301,80 @@ class BxDolCmts extends BxDol
 		));
     }
 
-    function getId ()
+    public function getId ()
     {
         return $this->_iId;
     }
 
-    function isEnabled ()
+    public function isEnabled ()
     {
         return isset($this->_aSystem['is_on']) && $this->_aSystem['is_on'];
     }
 
-	function getSystemId()
+	public function getSystemId()
     {
         return $this->_aSystem['system_id'];
     }
 
-    function getSystemName()
+    public function getSystemName()
     {
         return $this->_sSystem;
     }
 
-	function getSystemInfo()
+	public function getSystemInfo()
     {
         return $this->_aSystem;
     }
-	function getMaxLevel()
+
+	public function getMaxLevel()
 	{
 		return $this->_iDpMaxLevel;
 	}
-    function getOrder ()
+
+    public function getOrder ()
     {
         return $this->_sOrder;
     }
 
-	function getPerView ($iCmtParentId = 0)
+	public function getPerView ($iCmtParentId = 0)
     {
         return $iCmtParentId == 0 ? $this->_aSystem['per_view'] : $this->_aSystem['per_view_replies'];
     }
 
-    function getBaseUrl()
+    public function getBaseUrl()
     {
     	return $this->_replaceMarkers($this->_sBaseUrl);
     }
 
-    function isNl2br ()
+    public function getListUrl()
+    {
+    	return $this->getBaseUrl() . '#' . $this->getListAnchor();
+    }
+
+    public function getListAnchor()
+    {
+    	return sprintf($this->_sListAnchor, str_replace('_', '-', $this->getSystemName()), $this->getId());
+    }
+
+    public function isNl2br ()
     {
         return $this->_aSystem['nl2br'];
     }
 
-    function isRatable ()
+    public function isRatable ()
     {
         return $this->_aSystem['is_ratable'];
     }
 
+    public function isAttachImageEnabled()
+    {
+    	return true;
+    }
+
     /**
      * set id to operate with votes
      */
-    function setId ($iId)
+    public function setId ($iId)
     {
         if ($iId == $this->getId()) return;
         $this->_iId = $iId;
@@ -364,7 +383,7 @@ class BxDolCmts extends BxDol
     /**
      * it is called on cron every day or similar period to clean old comment votes
      */
-    function maintenance () {
+    public function maintenance () {
         $iDeletedRecords = 0;
         foreach ($this->_aSystems as $aSystem) {
             if (!$aSystem['is_on'])                
@@ -391,37 +410,37 @@ class BxDolCmts extends BxDol
     /** 
      * Database functions
      */
-	function getCommentsTableName ()
+	public function getCommentsTableName ()
     {
         return $this->_oQuery->getTableName ();
     }
 
-    function getObjectTitle ($iObjectId = 0)
+    public function getObjectTitle ($iObjectId = 0)
     {
     	return $this->_oQuery->getObjectTitle ($iObjectId ? $iObjectId : $this->getId());
     }
 
-    function getObjectCommentsCount ($iObjectId = 0)
+    public function getObjectCommentsCount ($iObjectId = 0)
     {
         return $this->_oQuery->getObjectCommentsCount ($iObjectId ? $iObjectId : $this->getId());
     }
 
-    function getCommentsArray ($iVParentId, $aOrder, $iStart = 0, $iCount = -1)
+    public function getCommentsArray ($iVParentId, $aOrder, $iStart = 0, $iCount = -1)
     {
         return $this->_oQuery->getComments ($this->getId(), $iVParentId, $this->_getAuthorId(), $aOrder, $iStart, $iCount);
     }
 
-    function getCommentRow ($iCmtId)
+    public function getCommentRow ($iCmtId)
     {
         return $this->_oQuery->getComment ($this->getId(), $iCmtId, $this->_getAuthorId());
     }
 
-    function onObjectDelete ($iObjectId = 0)
+    public function onObjectDelete ($iObjectId = 0)
     {
         return $this->_oQuery->deleteObjectComments ($iObjectId ? $iObjectId : $this->getId());
     }
 
-    function onAuthorDelete ($iAuthorId)
+    public function onAuthorDelete ($iAuthorId)
     {
     	foreach($this->_aSystems as $sSystem => $aSystem) {
             $oQuery = new BxDolCmtsQuery($aSystem);
@@ -433,65 +452,65 @@ class BxDolCmts extends BxDol
     /** 
      * Permissions functions
      */
-    function checkAction ($iAction, $isPerformAction = false)
+    public function checkAction ($iAction, $isPerformAction = false)
     {
         $iId = $this->_getAuthorId();
         $check_res = checkAction($iId, $iAction, $isPerformAction);
         return $check_res[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED;
     }
 
-    function checkActionErrorMsg ($iAction)
+    public function checkActionErrorMsg ($iAction)
     {
         $iId = $this->_getAuthorId();
         $check_res = checkAction($iId, $iAction);
         return $check_res[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $check_res[CHECK_ACTION_MESSAGE] : '';
     }
 
-    function isRateAllowed ($isPerformAction = false)
+    public function isRateAllowed ($isPerformAction = false)
     {
         return $this->checkAction (ACTION_ID_COMMENTS_VOTE, $isPerformAction); 
     }
 
-    function msgErrRateAllowed ()
+    public function msgErrRateAllowed ()
     { 
         return $this->checkActionErrorMsg(ACTION_ID_COMMENTS_VOTE);
     }
 
-    function isPostReplyAllowed ($isPerformAction = false) {
+    public function isPostReplyAllowed ($isPerformAction = false) {
         return $this->checkAction (ACTION_ID_COMMENTS_POST, $isPerformAction);
     }
 
-    function msgErrPostReplyAllowed ()
+    public function msgErrPostReplyAllowed ()
     {
         return $this->checkActionErrorMsg(ACTION_ID_COMMENTS_POST);
     }
 
-    function isEditAllowed ($isPerformAction = false)
+    public function isEditAllowed ($isPerformAction = false)
     {
         return $this->checkAction (ACTION_ID_COMMENTS_EDIT_OWN, $isPerformAction);
     }
 
-    function msgErrEditAllowed ()
+    public function msgErrEditAllowed ()
     {
         return $this->checkActionErrorMsg (ACTION_ID_COMMENTS_EDIT_OWN);
     }
 
-    function isRemoveAllowed ($isPerformAction = false)
+    public function isRemoveAllowed ($isPerformAction = false)
     {
         return $this->checkAction (ACTION_ID_COMMENTS_REMOVE_OWN, $isPerformAction);
     }
 
-    function msgErrRemoveAllowed ()
+    public function msgErrRemoveAllowed ()
     {
         return $this->checkActionErrorMsg(ACTION_ID_COMMENTS_REMOVE_OWN);
     }
 
-    function isEditAllowedAll ($isPerformAction = false)
+    public function isEditAllowedAll ($isPerformAction = false)
     {
         return isAdmin() || $this->checkAction (ACTION_ID_COMMENTS_EDIT_ALL, $isPerformAction) ? true : false;
     }
 
-    function isRemoveAllowedAll ($isPerformAction = false)
+    public function isRemoveAllowedAll ($isPerformAction = false)
     {
         return isAdmin() || $this->checkAction (ACTION_ID_COMMENTS_REMOVE_ALL, $isPerformAction) ? true : false;
     }
@@ -499,7 +518,7 @@ class BxDolCmts extends BxDol
     /**
      * Actions functions
      */
-    function actionGetFormPost () {
+    public function actionGetFormPost () {
         if (!$this->isEnabled())
            return '';
 
@@ -510,7 +529,7 @@ class BxDolCmts extends BxDol
         return $this->getFormBoxPost(array('parent_id' => $iCmtParentId, 'type' => $sCmtBrowse), array('type' => $sCmtDisplay));
     }
 
-	function actionGetFormEdit ()
+	public function actionGetFormEdit ()
     {
         if (!$this->isEnabled()){
         	$this->_echoResultJson(array());
@@ -521,7 +540,7 @@ class BxDolCmts extends BxDol
         $this->_echoResultJson($this->getFormEdit($iCmtId));
     }
 
-	function actionGetPlusedBy () {
+	public function actionGetPlusedBy () {
         if (!$this->isEnabled())
            return '';
 
@@ -529,7 +548,7 @@ class BxDolCmts extends BxDol
         return $this->getPlusedBy($iCmtId);
     }
 
-    function actionGetCmt () {
+    public function actionGetCmt () {
         if (!$this->isEnabled())
            return '';
 
@@ -545,7 +564,7 @@ class BxDolCmts extends BxDol
         ));
     }
 
-    function actionGetCmts () {
+    public function actionGetCmts () {
         if (!$this->isEnabled())
            return '';
 
@@ -558,7 +577,7 @@ class BxDolCmts extends BxDol
         return $this->getComments(array('vparent_id' => $iCmtVParentId, 'start' => $iCmtStart, 'per_view' => $iCmtPerView, 'type' => $sCmtBrowse), array('type' => $sCmtDisplay));
     }
 
-	function actionGetImage ()
+	public function actionGetImage ()
     {
     	if (!$this->isEnabled())
            return '';
@@ -567,7 +586,7 @@ class BxDolCmts extends BxDol
         return $this->getImage($iImgId);
     }
 
-    function actionSubmitPostForm()
+    public function actionSubmitPostForm()
     {
         if(!$this->isEnabled() || !$this->isPostReplyAllowed()) {
         	$this->_echoResultJson(array());
@@ -581,7 +600,7 @@ class BxDolCmts extends BxDol
 		$this->_echoResultJson($this->getFormPost($iCmtParentId));
     }
 
-	function actionSubmitEditForm()
+	public function actionSubmitEditForm()
 	{
         if (!$this->isEnabled()) {
         	$this->_echoResultJson(array());
@@ -595,7 +614,7 @@ class BxDolCmts extends BxDol
         $this->_echoResultJson($this->getFormEdit($iCmtId));
     }
 
-    function actionRemove()
+    public function actionRemove()
     {
         if (!$this->isEnabled()) {
         	$this->_echoResultJson(array());
@@ -649,7 +668,7 @@ class BxDolCmts extends BxDol
         $this->_echoResultJson(array('msg' => _t('_cmt_err_cannot_perform_action')));
     }
 
-    function actionRate()
+    public function actionRate()
     {
         if (!$this->isEnabled() || !$this->isRatable()) {
         	$this->_echoResultJson(array('msg' => _t('_Error occured')));

+ 8 - 6
inc/js/classes/BxDolCmts.js

@@ -22,10 +22,10 @@ function BxDolCmts (options) {
     this._oSavedTexts = {};
     this._sRootId = '#cmts-box-' + this._sSystem + '-' + this._iObjId;
 
-    // init post comment form (because browser remeber last inputs, we need to clear it)
-    if ($('#cmts-box-' + this._sSystem + '-' + this._iObjId + ' .cmt-post-reply form').length) {
-    	$('#cmts-box-' + this._sSystem + '-' + this._iObjId + ' .cmt-post-reply form')[0].reset();
-    	$('#cmts-box-' + this._sSystem + '-' + this._iObjId + ' .cmt-post-reply form > [name=CmtParent]').val(0);    
+    // init post comment form
+    if ($(this._sRootId + ' .cmt-post-reply form').length) {
+    	var sFormId = $(this._sRootId + ' .cmt-post-reply form').attr('id');
+    	this.cmtInitFormPost(sFormId);
     }
 }
 
@@ -346,6 +346,10 @@ BxDolCmts.prototype.toggleReply = function(e, iCmtParentId)
         		oFormSibling.after(oForm);
         		break;
         }
+
+        var sFormId = oForm.find('form').attr('id');
+        $this.cmtInitFormPost(sFormId);
+
     	$(sParentId).children('.cmt-reply').bx_anim('toggle', $this._sAnimationEffect, $this._iAnimationSpeed, fOnShow);    		
 	});
 };
@@ -478,8 +482,6 @@ BxDolCmts.prototype._getForm = function (e, iCmtParentId, onLoad)
     oData['CmtBrowse'] = this._sBrowseType;
     oData['CmtDisplay'] = this._sDisplayType;
 
-    
-    
     if(e)
     	this._loadingInContent(e, true);
 

+ 0 - 5
template/comment_reply_box.html

@@ -18,11 +18,6 @@
 	<div class="__style_prefix__-cont __style_prefix__-post-reply bx-def-margin-sec-top bx-def-color-bg-box bx-def-border bx-def-round-corners bx-def-shadow">
 		<div class="__style_prefix__-cont-cnt bx-def-padding-leftright bx-def-padding-sec-topbottom">
 			<div class="__style_prefix__-body bx-def-margin-thd-topbottom">__form__</div>
-			<script type="text/javascript">
-            $(document).ready(function () {
-            	__js_object__.cmtInitFormPost("__form_id__");
-            });
-        </script>
 		</div>
 	</div>
 </div>

+ 1 - 0
template/comments_block.html

@@ -1,6 +1,7 @@
 <div id="cmts-box-__system__-__id__">
 	__post_form_top__
 	<div id="cmt0" class="cmts">
+		<a class="bx-anchor-invisible" name="__list_anchor__"></a>
 		<ul class="cmts">
 			<bx_if:show_empty>
 				<li class="__style_prefix__-no">

+ 43 - 31
template/scripts/BxBaseCmtsView.php

@@ -22,7 +22,7 @@ class BxBaseCmtsView extends BxDolCmts {
         if(empty($sSystem))
             return;
 
-        $this->_sJsObjName = 'oCmts' . ucfirst($sSystem) . $iId;
+        $this->_sJsObjName = 'oCmts' . str_replace(' ', '', ucwords(str_replace(array('_' , '-'), array(' ', ' '), $sSystem))) . $iId;
         $this->_sStylePrefix = isset($this->_aSystem['root_style_prefix']) ? $this->_aSystem['root_style_prefix'] : 'cmt';
 
         BxDolTemplate::getInstance()->addJsTranslation('_sys_txt_cmt_loading');
@@ -33,7 +33,7 @@ class BxBaseCmtsView extends BxDolCmts {
      *
      * @return string
      */
-    function getExtraCss ()
+    public static function getExtraCss ()
     {
         BxDolTemplate::getInstance()->addCss(array('cmts.css'));
     }
@@ -43,9 +43,14 @@ class BxBaseCmtsView extends BxDolCmts {
      *
      * @return string
      */
-    function getExtraJs ()
+    public static function getExtraJs ()
     {
-        BxDolTemplate::getInstance()->addJs(array('common_anim.js', 'jquery.form.js', 'BxDolCmts.js'));
+    	$oTemplate = BxDolTemplate::getInstance();
+        $oTemplate->addJs(array('common_anim.js', 'jquery.form.js', 'BxDolCmts.js'));
+        $oTemplate->addJsTranslation(array(
+        	'_Error occured',
+        	'_Are you sure?'
+        ));
     }
 
 	/**
@@ -72,13 +77,9 @@ class BxBaseCmtsView extends BxDolCmts {
     				sDisplayType: '" . $this->_sDisplayType . "'});\n";
         $ret .= "</script>";
 
-        $this->getExtraJs();
-        $this->getExtraCss();
-        BxDolTemplate::getInstance()->addJsTranslation(array(
-        	'_Error occured',
-        	'_Are you sure?'
-        ));
-        
+        self::getExtraJs();
+        self::getExtraCss();
+
         return $ret;
     }
 
@@ -93,6 +94,7 @@ class BxBaseCmtsView extends BxDolCmts {
     	$sCaption = _t('_cmt_block_comments_title', $this->_oQuery->getCommentsCount($this->_iId));
     	$sContent = BxDolTemplate::getInstance()->parseHtmlByName('comments_block.html', array(
     		'system' => $this->_sSystem,
+    		'list_anchor' => $this->getListAnchor(),
     		'id' => $this->getId(),
     		'bx_if:show_empty' => array(
 				'condition' => $sCmts == '',
@@ -209,18 +211,20 @@ class BxBaseCmtsView extends BxDolCmts {
 		}
 
 		$aTmplImages = array();
-		$aImages = $this->_oQuery->getImages($this->_aSystem['system_id'], $aCmt['cmt_id']);
-		if(!empty($aImages) && is_array($aImages)) {
-			bx_import('BxDolImageTranscoder');
-        	$oTranscoder = BxDolImageTranscoder::getObjectInstance($this->_sTranscoderPreview);
-
-        	foreach($aImages as $aImage)
-        		$aTmplImages[] = array(
-        			'style_prefix' => $this->_sStylePrefix,
-        			'js_object' => $this->_sJsObjName,
-        			'id' => $aImage['image_id'],
-        			'image' => $oTranscoder->getImageUrl($aImage['image_id'])
-        		);
+		if($this->isAttachImageEnabled()) {
+			$aImages = $this->_oQuery->getImages($this->_aSystem['system_id'], $aCmt['cmt_id']);
+			if(!empty($aImages) && is_array($aImages)) {
+				bx_import('BxDolImageTranscoder');
+	        	$oTranscoder = BxDolImageTranscoder::getObjectInstance($this->_sTranscoderPreview);
+	
+	        	foreach($aImages as $aImage)
+	        		$aTmplImages[] = array(
+	        			'style_prefix' => $this->_sStylePrefix,
+	        			'js_object' => $this->_sJsObjName,
+	        			'id' => $aImage['image_id'],
+	        			'image' => $oTranscoder->getImageUrl($aImage['image_id'])
+	        		);
+			}
 		}
 
 		$sReplies = '';
@@ -343,6 +347,9 @@ class BxBaseCmtsView extends BxDolCmts {
 
     function getImage($iImgId)
     {
+    	if(!$this->isAttachImageEnabled())
+    		return '';
+
     	$oTemplate = BxDolTemplate::getInstance();
 
     	bx_import('BxDolStorage');
@@ -570,14 +577,16 @@ class BxBaseCmtsView extends BxDolCmts {
 
 			$iCmtId = (int)$oForm->insert(array('cmt_vparent_id' => $iCmtVisualParentId, 'cmt_object_id' => $this->_iId, 'cmt_author_id' => $iCmtAuthorId, 'cmt_level' => $iLevel, 'cmt_time' => time()));
 			if($iCmtId != 0) {
-				$aImages = $oForm->getCleanValue('cmt_image');
-				if(!empty($aImages) || is_array($aImages)) {
-					bx_import('BxDolStorage');
-					$oStorage = BxDolStorage::getObjectInstance($this->_sStorageObject);
-
-					foreach($aImages as $iImageId)
-						if($this->_oQuery->saveImages($this->_aSystem['system_id'], $iCmtId, $iImageId))
-							$oStorage->afterUploadCleanup($iImageId, $iCmtAuthorId);
+				if($this->isAttachImageEnabled()) {
+					$aImages = $oForm->getCleanValue('cmt_image');
+					if(!empty($aImages) && is_array($aImages)) {
+						bx_import('BxDolStorage');
+						$oStorage = BxDolStorage::getObjectInstance($this->_sStorageObject);
+	
+						foreach($aImages as $iImageId)
+							if($this->_oQuery->saveImages($this->_aSystem['system_id'], $iCmtId, $iImageId))
+								$oStorage->afterUploadCleanup($iImageId, $iCmtAuthorId);
+					}
 				}
 
 				if($iCmtParentId) 
@@ -652,6 +661,9 @@ class BxBaseCmtsView extends BxDolCmts {
         $oForm->aInputs['id']['value'] = $this->_iId;
         $oForm->aInputs['action']['value'] = 'Submit' . $sActionCap . 'Form';
 
+        if(!$this->isAttachImageEnabled())
+        	unset($oForm->aInputs['cmt_image']);
+
 	    if(isset($oForm->aInputs['cmt_image'])) {
 	    	$aFormNested = array(
 	        	'params' =>array(