AntonLV 8 лет назад
Родитель
Сommit
36f9f015b4

+ 7 - 0
modules/boonex/timeline/classes/BxTimelineConfig.php

@@ -276,11 +276,17 @@ class BxTimelineConfig extends BxBaseModNotificationsConfig
         return BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=timeline-item&id=' . $aEvent['id']);
     }
 
+    public function isCommon($sType, $sAction)
+    {
+        return !$this->isSystem($sType, $sAction);
+    }
+
     public function isSystem($sType, $sAction)
     {
         $sPrefix = $this->getPrefix('common_post');
         return strpos($sType, $sPrefix) === false && !empty($sAction);
     }
+
     public function getSystemData(&$aEvent, $aBrowseParams = array())
     {
 		$sHandler = $aEvent['type'] . '_' . $aEvent['action'];
@@ -293,6 +299,7 @@ class BxTimelineConfig extends BxBaseModNotificationsConfig
 
 		return BxDolService::call($aHandler['module_name'], $aHandler['module_method'], array($aEvent, $aBrowseParams), $aHandler['module_class']);
     }
+
     public function getSystemDataByDescriptor($sType, $sAction, $iObjectId)
     {
     	$aDescriptor = array(

+ 22 - 2
modules/boonex/timeline/classes/BxTimelineDb.php

@@ -390,7 +390,13 @@ class BxTimelineDb extends BxBaseModNotificationsDb
 				if(empty($aParams['owner_id']))
 					break;
 
-				$sWhereClause .= $this->prepareAsString("AND `{$this->_sTable}`.`owner_id`=? ", $aParams['owner_id']);
+                //--- Select Own (System and Direct) posts from Profile's Timeline.
+				$sWhereSubclause = "(`{$this->_sTable}`.`owner_id` = ?)";
+
+				//--- Select Own Public (Direct) posts from Home Page Timeline (Public Feed).
+				$sWhereSubclause .= " || (`{$this->_sTable}`.`owner_id` = '0' AND IF(SUBSTRING(`{$this->_sTable}`.`type`, 1, " . strlen($sCommonPostPrefix) . ") = '" . $sCommonPostPrefix . "', `{$this->_sTable}`.`object_id` = ?, 1))";
+
+				$sWhereClause .= $this->prepareAsString("AND (" . $sWhereSubclause . ") ", $aParams['owner_id'], $aParams['owner_id']);
 				break;
 
 			case BX_BASE_MOD_NTFS_TYPE_CONNECTIONS:
@@ -405,7 +411,10 @@ class BxTimelineDb extends BxBaseModNotificationsDb
 				$aQueryParts = $oConnection->getConnectedContentAsSQLPartsExt($this->_sPrefix . 'events', 'object_id', $aParams['owner_id']);
 				$aJoin2 = $aQueryParts['join'];
 
+				//--- Join System and Direct posts made by following members.  
 				$sJoinClause .= " " . $aJoin1['type'] . " JOIN `" . $aJoin1['table'] . "` AS `" . $aJoin1['table_alias'] . "` ON ((" . $aJoin1['condition'] . ") OR (SUBSTRING(`" . $this->_sTable . "`.`type`, 1, " . strlen($sCommonPostPrefix) . ") = '" . $sCommonPostPrefix . "' AND " . $aJoin2['condition'] . "))";
+
+				//--- Exclude Own (Direct) posts on timelines of following members. 
 				$sWhereClause .= $this->prepareAsString("AND IF(SUBSTRING(`{$this->_sTable}`.`type`, 1, " . strlen($sCommonPostPrefix) . ") = '" . $sCommonPostPrefix . "', `{$this->_sTable}`.`object_id` <> ?, 1) ", $aParams['owner_id']);
 				break;
 
@@ -421,8 +430,19 @@ class BxTimelineDb extends BxBaseModNotificationsDb
 				$aQueryParts = $oConnection->getConnectedContentAsSQLPartsExt($this->_sPrefix . 'events', 'object_id', $aParams['owner_id']);
 				$aJoin2 = $aQueryParts['join'];
 
+				//--- Join System and Direct posts made by following members. 'LEFT' join is essential to apply different conditions.
 				$sJoinClause .= " LEFT JOIN `" . $aJoin1['table'] . "` AS `" . $aJoin1['table_alias'] . "` ON ((" . $aJoin1['condition'] . ") OR (SUBSTRING(`" . $this->_sTable . "`.`type`, 1, " . strlen($sCommonPostPrefix) . ") = '" . $sCommonPostPrefix . "' AND " . $aJoin2['condition'] . "))";
-				$sWhereClause .= $this->prepareAsString("AND ((`{$this->_sTable}`.`owner_id`=?) || (NOT ISNULL(`c`.`content`) AND IF(SUBSTRING(`{$this->_sTable}`.`type`, 1, " . strlen($sCommonPostPrefix) . ") = '" . $sCommonPostPrefix . "', `{$this->_sTable}`.`object_id` <> ?, 1))) ", $aParams['owner_id'], $aParams['owner_id']);
+				
+				//--- Select Own (System and Direct) posts from Profile's Timeline.
+				$sWhereSubclause = "(`{$this->_sTable}`.`owner_id` = ?)";
+				
+				//--- Select Own Public (Direct) posts from Home Page Timeline (Public Feed).
+				$sWhereSubclause .= " || (`{$this->_sTable}`.`owner_id` = '0' AND IF(SUBSTRING(`{$this->_sTable}`.`type`, 1, " . strlen($sCommonPostPrefix) . ") = '" . $sCommonPostPrefix . "', `{$this->_sTable}`.`object_id` = ?, 1))";
+
+				//--- Exclude Own (Direct) posts on timelines of following members. 
+				$sWhereSubclause .= " || (NOT ISNULL(`c`.`content`) AND IF(SUBSTRING(`{$this->_sTable}`.`type`, 1, " . strlen($sCommonPostPrefix) . ") = '" . $sCommonPostPrefix . "', `{$this->_sTable}`.`object_id` <> ?, 1))";
+
+				$sWhereClause .= $this->prepareAsString("AND (" . $sWhereSubclause . ") ", $aParams['owner_id'], $aParams['owner_id'], $aParams['owner_id']);
 			    break;
 		}
 

+ 4 - 2
modules/boonex/timeline/classes/BxTimelineModule.php

@@ -1523,12 +1523,14 @@ class BxTimelineModule extends BxBaseModNotificationsModule implements iBxDolCon
             return true;
 
         $iUserId = (int)$this->getUserId();
-        if((int)$aEvent['owner_id'] == $iUserId && $this->_oConfig->isAllowDelete())
+        $iOwnerId = (int)$aEvent['owner_id'];
+        $iObjectId = (int)$aEvent['object_id'];
+        if((($iOwnerId == $iUserId) || ($iOwnerId == 0 && $this->_oConfig->isCommon($aEvent['type'], $aEvent['action']) && $iObjectId == $iUserId)) && $this->_oConfig->isAllowDelete())
            return true;
 
         $aCheckResult = checkActionModule($iUserId, 'delete', $this->getName(), $bPerform);
 
-        $oProfileOwner = BxDolProfile::getInstance((int)$aEvent['owner_id']);
+        $oProfileOwner = BxDolProfile::getInstance($iOwnerId);
         if($oProfileOwner !== false)
             bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_delete', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));