瀏覽代碼

#104 - Integration with Comments.

AntonLV 12 年之前
父節點
當前提交
ecd7e45d1a

+ 1 - 0
inc/classes/BxDolCmts.php

@@ -27,6 +27,7 @@ define('BX_CMT_ORDER_BY_DATE', 'date');
 define('BX_CMT_ORDER_BY_POPULAR', 'popular');
 
 define('BX_CMT_FILTER_ALL', 'all');
+define('BX_CMT_FILTER_OTHERS', 'others');
 define('BX_CMT_FILTER_FRIENDS', 'friends');
 define('BX_CMT_FILTER_SUBSCRIPTIONS', 'subscriptions');
 

+ 19 - 12
inc/classes/BxDolCmtsQuery.php

@@ -49,24 +49,31 @@ class BxDolCmtsQuery extends BxDolDb
 
     function getCommentsCount ($iId, $iCmtVParentId = 0, $iAuthorId = 0, $sFilter = '')
     {
-        $sWhereParent = '';
+        $sWhereClause = '';
         if((int)$iCmtVParentId >= 0)
-            $sWhereParent = $this->prepare(" AND `{$this->_sTable}`.`cmt_vparent_id` = ?", $iCmtVParentId);
-
-        $sJoin = '';
-        if(in_array($sFilter, array(BX_CMT_FILTER_FRIENDS, BX_CMT_FILTER_SUBSCRIPTIONS))) {
-            bx_import('BxDolConnection');
-            $oConnection = BxDolConnection::getObjectInstance($this->_oMain->getConnectionObject($sFilter));
-
-            $aQueryParts = $oConnection->getConnectedContentAsSQLParts($this->_sTable, 'cmt_author_id', $iAuthorId);
-            $sJoin .= ' ' . $aQueryParts['join'];
+            $sWhereClause .= $this->prepare(" AND `{$this->_sTable}`.`cmt_vparent_id` = ?", $iCmtVParentId);
+
+        $sJoinClause = '';
+        switch($sFilter) {
+        	case BX_CMT_FILTER_FRIENDS:
+        	case BX_CMT_FILTER_SUBSCRIPTIONS:
+	            bx_import('BxDolConnection');
+	            $oConnection = BxDolConnection::getObjectInstance($this->_oMain->getConnectionObject($sFilter));
+	
+	            $aQueryParts = $oConnection->getConnectedContentAsSQLParts($this->_sTable, 'cmt_author_id', $iAuthorId);
+	            $sJoinClause .= ' ' . $aQueryParts['join'];
+	            break;
+
+        	case BX_CMT_FILTER_OTHERS:
+        		$sWhereClause .= $this->prepare(" AND `{$this->_sTable}`.`cmt_author_id` <> ?", $iAuthorId);
+        		break;
         }
 
         $sQuery = $this->prepare("SELECT
                 COUNT(*)
             FROM `{$this->_sTable}`
-            $sJoin
-            WHERE `{$this->_sTable}`.`cmt_object_id` = ?" . $sWhereParent, $iId);
+            $sJoinClause
+            WHERE `{$this->_sTable}`.`cmt_object_id` = ?" . $sWhereClause, $iId);
 
         return (int)$this->getOne($sQuery);
     }

+ 3 - 3
inc/classes/BxDolObject.php

@@ -23,12 +23,12 @@ class BxDolObject extends BxDol
     {
         parent::__construct();
 
-        $this->_aSystems = $this->getSystems();
-        if(!isset($this->_aSystems[$sSystem]))
+        $aSystems = $this->getSystems();
+        if(!isset($aSystems[$sSystem]))
             return;
 
         $this->_sSystem = $sSystem;
-        $this->_aSystem = $this->_aSystems[$sSystem];
+        $this->_aSystem = $aSystems[$sSystem];
 
         if(!$this->isEnabled())
             return;

+ 22 - 0
inc/js/classes/BxDolCmts.js

@@ -253,7 +253,29 @@ BxDolCmts.prototype.cmtChangeFilter = function(oLink, sType)
 		$this._cmtsReplaceContent($(sListId), sContent);
 	});
 };
+BxDolCmts.prototype.showLiveUpdate = function(oData)
+{
+	if(!oData.code)
+		return;
+
+	var iCountNew = parseInt(oData.count_new);
+	var iCountOld = parseInt(oData.count_old);
+	if(iCountNew <= iCountOld)
+		return;
 
+	var oNotification = $(oData.code);
+	oNotification.find('.cmt-message span').html(iCountNew - iCountOld);
+
+	var sId = oNotification.attr('id');
+	$('#' + sId).remove();
+
+    $(oNotification).prependTo('body').dolPopup({
+    	position: 'fixed',
+    	top: ($(window).height() - oNotification.height()) + 'px',
+    	left: ($(window).width() - oNotification.width())/2 + 'px',
+    	fog: false
+    });
+};
 BxDolCmts.prototype.showReplacement = function(iCmtId)
 {
     $('#cmt' + iCmtId + '-hidden').bx_anim('hide', this._sAnimationEffect, this._iAnimationSpeed, function(){

+ 9 - 0
modules/base/text/classes/BxBaseModTextModule.php

@@ -141,6 +141,15 @@ class BxBaseModTextModule extends BxBaseModGeneralModule
         $oCmts = BxDolCmts::getObjectInstance($this->_oConfig->CNF['OBJECT_COMMENTS'], $iContentId);
         if (!$oCmts || !$oCmts->isEnabled())
             return false;
+
+		//add transient live update
+		$sName = $this->_oConfig->getName();
+		$sServiceCall = BxDolService::getSerializedService('system', 'get_live_updates_comments', array($this->_oConfig->CNF['OBJECT_COMMENTS'], $iContentId, $this->_iProfileId), 'TemplCmtsServices');
+
+		bx_import('BxDolLiveUpdates');
+		BxDolLiveUpdates::getInstance()->add($sName . '_live_updates_cmts', 1, $sServiceCall);
+		//add transient live update
+
         return $oCmts->getCommentsBlock(0, 0, false);
     }
 

+ 7 - 0
modules/boonex/english/data/langs/system.xml

@@ -1302,7 +1302,14 @@
 	<string name="_cmt_err_cannot_perform_action"><![CDATA[Cannot perform action. Please report.]]></string>
 	<string name="_cmt_page_view_header"><![CDATA[Comment to {0}]]></string>
 	<string name="_cmt_page_view_title"><![CDATA[Comment to <a href="{0}">{1}</a>]]></string>
+	<string name="_cmt_txt_n_new_comments"><![CDATA[<span>{0}</span> new comment(s).]]></string>
 	<string name="_cmt_view_attached_image"><![CDATA[View image]]></string>
+	<string name="_cmt_load_more_comments_head"><![CDATA[See newer comments...]]></string>
+	<string name="_cmt_load_more_comments_tail"><![CDATA[See older comments...]]></string>
+	<string name="_cmt_load_more_comments_popular"><![CDATA[See more comments...]]></string>
+	<string name="_cmt_load_more_replies_head"><![CDATA[See newer replies...]]></string>
+	<string name="_cmt_load_more_replies_tail"><![CDATA[See older replies...]]></string>
+	<string name="_cmt_load_more_replies_popular"><![CDATA[See more replies...]]></string>
 	<string name="_copyright"><![CDATA[&copy; {0} Company]]></string>
 	<string name="_delete"><![CDATA[delete]]></string>
 	<string name="_error occured"><![CDATA[Error occurred]]></string>

+ 7 - 0
template/comments_notification.html

@@ -0,0 +1,7 @@
+<div id="__html_id__" class="__style_prefix__-notification bx-def-border bx-def-round-corners" style="display:none;">
+	<div class="__style_prefix__-cnt bx-def-padding-sec-topbottom">
+		<div class="__style_prefix__-message">
+			<a href="__url__">__message__</a>
+		</div>
+	</div>
+</div>

+ 21 - 0
template/css/cmts.css

@@ -195,4 +195,25 @@
     div.cmts-uploader-file-preview img {
 		background-position: center center;
 		background-repeat: no-repeat;
+    }
+
+    /*--- Live Update Notification Styles ---*/
+    div.cmt-notification {
+    	border-color: #616161;
+		border-bottom: none;
+
+    	border-bottom-right-radius: 0px;
+    	border-bottom-left-radius: 0px;
+
+    	background-color: rgba(97, 97, 97, .5);
+    }
+    div.cmt-notification div.cmt-cnt {
+		padding-left: 80px;
+    	padding-left: 5rem;
+    	padding-right: 80px;     	
+    	padding-right: 5rem;
+    }
+    div.cmt-notification a {
+		color: #ffffff;
+    	font-weight: bold;
     }

+ 13 - 1
template/scripts/BxBaseCmts.php

@@ -337,6 +337,18 @@ class BxBaseCmts extends BxDolCmts
         return $this->_getFormEdit($aCmt);
     }
 
+    function getNotification($iCount = 0)
+    {
+    	bx_import('BxDolTemplate');
+    	$sContent = BxDolTemplate::getInstance()->parseHtmlByName('comments_notification.html', array(
+    		'html_id' => 'cmts-notification-' . $this->_sSystem . '-' + $this->_iId,
+			'style_prefix' => $this->_sStylePrefix,
+    		'url' => $this->getBaseUrl(),
+			'message' => _t('_cmt_txt_n_new_comments', $iCount)
+		));
+
+		return $sContent;
+    }
     /**
      * private functions
      */
@@ -672,7 +684,7 @@ class BxBaseCmts extends BxDolCmts
             'parent_id' => $aBp['vparent_id'],
             'start' => $iStart,
             'per_view' => $iPerView,
-            'title' => _t('_load_more_' . ($aBp['vparent_id'] == 0 ? 'comments' : 'replies') . '_' . $aBp['type'])
+            'title' => _t('_cmt_load_more_' . ($aBp['vparent_id'] == 0 ? 'comments' : 'replies') . '_' . $aBp['type'])
         ));
 
         switch($aBp['type']) {

+ 16 - 0
template/scripts/BxBaseCmtsServices.php

@@ -28,6 +28,22 @@ class BxBaseCmtsServices extends BxDol
 
         return '';
     }
+
+    public function serviceGetLiveUpdatesComments($sSystem, $iContentId, $iProfileId)
+    {
+    	bx_import('BxDolCmts');
+        $oCmts = BxDolCmts::getObjectInstance($sSystem, $iContentId);
+        if(!$oCmts || !$oCmts->isEnabled())
+            return false;
+
+    	return array(
+    		'count' => $oCmts->getCommentsCount($iContentId, 0, BX_CMT_FILTER_OTHERS), // required
+    		'method' => $oCmts->getJsObjectName() . '.showLiveUpdate(oData)', // required
+    		'data' => array(
+    			'code' => $oCmts->getNotification()
+    		),  // optional, may have some additional data to be passed in JS method provided using 'method' param above.
+    	);
+    }
 }
 
 /** @} */