Przeglądaj źródła

#24 - Timeline: Rename Share to Repost and disable repeated Repost.

AntonLV 11 lat temu
rodzic
commit
147de02fcb

+ 11 - 0
modules/boonex/timeline/classes/BxTimelineDb.php

@@ -139,6 +139,17 @@ class BxTimelineDb extends BxBaseModNotificationsDb
         return $this->getColumn($sQuery);
     }
 
+    function isShared($iSharedId, $iOwnerId, $iAuthorId)
+    {
+    	$sQuery = $this->prepare("SELECT 
+    			`te`.`id`
+    		FROM `{$this->_sTableSharesTrack}` AS `tst` 
+    		LEFT JOIN `{$this->_sTable}` AS `te` ON `tst`.`event_id`=`te`.`id` 
+    		WHERE `tst`.`author_id`=? AND `tst`.`shared_id`=? AND `te`.`owner_id`=?", $iAuthorId, $iSharedId, $iOwnerId);
+
+    	return (int)$this->getOne($sQuery) > 0;
+    }
+
     //--- Photo uploader related methods ---//
     public function saveMedia($sType, $iEventId, $iItemId)
     {

+ 12 - 3
modules/boonex/timeline/classes/BxTimelineModule.php

@@ -92,6 +92,8 @@ class BxTimelineModule extends BxBaseModNotificationsModule
 
     public function actionShare()
     {
+    	$iAuthorId = $this->getUserId();
+
         $iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
         $aContent = array(
             'type' => bx_process_input(bx_get('type'), BX_DATA_TEXT),
@@ -111,11 +113,17 @@ class BxTimelineModule extends BxBaseModNotificationsModule
             return;
         }
 
+        $bShared = $this->_oDb->isShared($aShared['id'], $iOwnerId, $iAuthorId);
+		if($bShared) {
+        	$this->_echoResultJson(array('code' => 3, 'msg' => _t('_bx_timeline_txt_err_already_shared')));
+            return;
+        }
+
         $iId = $this->_oDb->insertEvent(array(
             'owner_id' => $iOwnerId,
             'type' => $this->_oConfig->getPrefix('common_post') . 'share',
             'action' => '',
-            'object_id' => $this->getUserId(),
+            'object_id' => $iAuthorId,
             'object_privacy_view' => $this->_oConfig->getPrivacyViewDefault(),
             'content' => serialize($aContent),
             'title' => '',
@@ -123,7 +131,7 @@ class BxTimelineModule extends BxBaseModNotificationsModule
         ));
 
         if(empty($iId)) {
-	        $this->_echoResultJson(array('code' => 3, 'msg' => _t('_bx_timeline_txt_err_cannot_share')));        
+	        $this->_echoResultJson(array('code' => 4, 'msg' => _t('_bx_timeline_txt_err_cannot_share')));        
 	        return;
         }
 
@@ -136,7 +144,8 @@ class BxTimelineModule extends BxBaseModNotificationsModule
 			'code' => 0, 
 			'msg' => _t('_bx_timeline_txt_msg_success_share'), 
 			'count' => $aShared['shares'], 
-			'counter' => $sCounter
+			'counter' => $sCounter,
+			'disabled' => !$bShared
 		));
     }
 

+ 3 - 2
modules/boonex/timeline/classes/BxTimelineTemplate.php

@@ -269,7 +269,8 @@ class BxTimelineTemplate extends BxBaseModNotificationsTemplate
         if(empty($aShared) || !is_array($aShared))
             return '';
 
-		$bDisabled = $this->getModule()->isAllowedShare($aShared) !== true;
+		$oModule = $this->getModule();
+		$bDisabled = $oModule->isAllowedShare($aShared) !== true || $this->_oDb->isShared($aShared['id'], $iOwnerId, $oModule->getUserId());
 		if($bDisabled && (int)$aShared['shares'] == 0)
             return '';
 
@@ -312,7 +313,7 @@ class BxTimelineTemplate extends BxBaseModNotificationsTemplate
 
 		$sDoShare = '';
         if($bShowDoShareIcon)
-            $sDoShare .= $this->parseHtmlByName('bx_icon.html', array('name' => 'share'));
+            $sDoShare .= $this->parseHtmlByName('bx_icon.html', array('name' => 'repeat'));
 
         if($bShowDoShareLabel)
             $sDoShare .= ($sDoShare != '' ? ' ' : '') . _t('_bx_timeline_txt_do_share');

+ 9 - 8
modules/boonex/timeline/install/langs/en.xml

@@ -46,7 +46,7 @@
 	<string name="_bx_timeline_acl_action_post"><![CDATA[Post]]></string>
 	<string name="_bx_timeline_acl_action_delete"><![CDATA[Delete]]></string>
 	<string name="_bx_timeline_acl_action_vote"><![CDATA[Vote]]></string>
-	<string name="_bx_timeline_acl_action_share"><![CDATA[Share]]></string>
+	<string name="_bx_timeline_acl_action_share"><![CDATA[Repost]]></string>
 
 	<string name="_bx_timeline_page_title_sys_view"><![CDATA[Timeline]]></string>
 	<string name="_bx_timeline_page_title_view"><![CDATA[Timeline]]></string>
@@ -80,7 +80,7 @@
     <string name="_bx_timeline_menu_item_title_system_item_comment"><![CDATA[Comment]]></string>
     <string name="_bx_timeline_menu_item_title_item_comment"><![CDATA[Comment]]></string>
     <string name="_bx_timeline_menu_item_title_system_item_vote"><![CDATA[Vote]]></string>
-    <string name="_bx_timeline_menu_item_title_system_item_share"><![CDATA[Share]]></string>
+    <string name="_bx_timeline_menu_item_title_system_item_share"><![CDATA[Repost]]></string>
 
 	<string name="_bx_timeline_menu_title_post_attachments"><![CDATA[Form Attachments]]></string>
     <string name="_bx_timeline_menu_set_title_post_attachments"><![CDATA[Form Attachments]]></string>
@@ -95,7 +95,7 @@
     <string name="_bx_timeline_menu_item_title_timeline"><![CDATA[Timeline]]></string>
 
 	<string name="_bx_timeline_alert_module_timeline_common_post"><![CDATA[Timeline (post)]]></string>
-	<string name="_bx_timeline_alert_module_timeline_common_share"><![CDATA[Timeline (share)]]></string>
+	<string name="_bx_timeline_alert_module_timeline_common_share"><![CDATA[Timeline (repost)]]></string>
 	<string name="_bx_timeline_alert_action_added"><![CDATA[add]]></string>
 
 	<string name="_bx_timeline_txt_msg_no_results"><![CDATA[Empty]]></string>
@@ -108,14 +108,15 @@
 
 	<string name="_bx_timeline_txt_rss_caption"><![CDATA[{0}'s timeline]]></string>
 	<string name="_bx_timeline_txt_user_added_sample"><![CDATA[{0} added {1}]]></string>
-	<string name="_bx_timeline_txt_user_shared_sample"><![CDATA[{0} shared {1}'s {2}]]></string>
+	<string name="_bx_timeline_txt_user_shared_sample"><![CDATA[{0} reposted {1}'s {2}]]></string>
 	<string name="_bx_timeline_txt_sample"><![CDATA[post]]></string>
 	<string name="_bx_timeline_txt_sample_ext"><![CDATA[timeline post]]></string>
 	<string name="_bx_timeline_txt_sample_comment_single"><![CDATA[timeline post's comment]]></string>
 
-	<string name="_bx_timeline_txt_do_share"><![CDATA[Share]]></string>
-	<string name="_bx_timeline_txt_shared"><![CDATA[Shared {0}'s {1}.]]></string>
-	<string name="_bx_timeline_txt_shared_by"><![CDATA[Shared by]]></string>
-	<string name="_bx_timeline_txt_err_cannot_share"><![CDATA[Cannot share. Please report.]]></string>
+	<string name="_bx_timeline_txt_do_share"><![CDATA[Repost]]></string>
+	<string name="_bx_timeline_txt_shared"><![CDATA[Reposted {0}'s {1}.]]></string>
+	<string name="_bx_timeline_txt_shared_by"><![CDATA[Reposted by]]></string>
+	<string name="_bx_timeline_txt_err_cannot_share"><![CDATA[Cannot repost. Please report.]]></string>
+	<string name="_bx_timeline_txt_err_already_shared"><![CDATA[You already reposted the item.]]></string>
 	<string name="_bx_timeline_txt_msg_success_share"><![CDATA[]]></string>	
 </resources>

+ 3 - 0
modules/boonex/timeline/js/share.js

@@ -38,6 +38,9 @@ BxTimelineShare.prototype.shareItem = function(oLink, iOwnerId, sType, sAction,
         		$('#' + sCounter).replaceWith(oData.counter);
         		$('#' + sCounter).parents('.' + $this.sSP + '-share-counter-holder:first').bx_anim(oData.count > 0 ? 'show' : 'hide');
         	}
+
+        	if(oData && oData.disabled)
+    			$(oLink).removeAttr('onclick').addClass($(oLink).hasClass('bx-btn') ? 'bx-btn-disabled' : $this.sSP + '-share-disabled');
         },
         'json'
     );