Procházet zdrojové kódy

#1636 Anonymous posting: better way to display to admins and owners that post is posted as anonymous

Alex Trofimov před 8 roky
rodič
revize
a62506de7f

+ 0 - 3
inc/classes/BxDolCmts.php

@@ -1308,9 +1308,6 @@ class BxDolCmts extends BxDolFactory implements iBxDolReplaceable, iBxDolContent
     {
         $iUserId = $this->_getAuthorId();
         $iAuthorId = (int)$iAuthorId;
-        if($iAuthorId < 0  && (abs($iAuthorId) == $iUserId || $this->isModerator()))
-            $iAuthorId *= -1;
-
         $oProfile = $this->_getAuthorObject($iAuthorId);
 
         return array(

+ 1 - 1
inc/classes/BxDolProfile.php

@@ -101,7 +101,7 @@ class BxDolProfile extends BxDolFactory implements iBxDolProfile
     public static function getInstanceMagic($mixedProfileId = false, $bClearCache = false)
     {
         if ($mixedProfileId < 0)
-            return BxDolProfileAnonymous::getInstance();
+            return BxDolProfileAnonymous::getInstance($mixedProfileId);
 
         if (0 == $mixedProfileId || !($oProfile = self::getInstance($mixedProfileId, $bClearCache)))
             return BxDolProfileUndefined::getInstance();

+ 44 - 10
inc/classes/BxDolProfileAnonymous.php

@@ -22,24 +22,37 @@
  */
 class BxDolProfileAnonymous extends BxDolProfileUndefined
 {
+    protected $_oProfileOrig = null;
+    protected $_iProfileID = 0;
+    protected $_isShowRealProfile = null;
+
     /**
-     * Prevent cloning the instance
+     * Constructor
      */
-    public function __clone()
+    protected function __construct ($oProfile)
     {
-        $sClass = get_class($this);
+        $sClass = get_class($this) . '_' . $oProfile->id();
         if (isset($GLOBALS['bxDolClasses'][$sClass]))
-            trigger_error('Clone is not allowed for the class: ' . get_class($this), E_USER_ERROR);
+            trigger_error ('Multiple instances are not allowed for the class: ' . get_class($this), E_USER_ERROR);
+
+        parent::__construct();
+
+        $this->_iProfileID = $oProfile->id();
+        $this->_oProfileOrig = $oProfile;
     }
 
     /**
-     * Get singleton instance of the class
+     * Get singleton instance of Profile by profile id
      */
-    public static function getInstance()
+    public static function getInstance($mixedProfileId = false, $bClearCache = false)
     {
-        $sClass = __CLASS__;
-        if(!isset($GLOBALS['bxDolClasses'][$sClass]))
-            $GLOBALS['bxDolClasses'][$sClass] = new $sClass();
+        $oProfile = BxDolProfile::getInstance(abs($mixedProfileId));
+        if (!$oProfile)
+            return BxDolProfileUndefined::getInstance();
+
+        $sClass = __CLASS__ . '_' . $oProfile->id();
+        if (!isset($GLOBALS['bxDolClasses'][$sClass]))
+            $GLOBALS['bxDolClasses'][$sClass] = new BxDolProfileAnonymous($oProfile);
 
         return $GLOBALS['bxDolClasses'][$sClass];
     }
@@ -49,7 +62,28 @@ class BxDolProfileAnonymous extends BxDolProfileUndefined
      */
     public function getDisplayName()
     {
-        return _t('_anonymous');
+        if ($this->isShowRealProfile())
+            return _t('_anonymous_f', $this->_oProfileOrig->getDisplayName());
+        else
+            return _t('_anonymous');
+    }
+
+    public function getUrl()
+    {
+        if ($this->isShowRealProfile())
+            return $this->_oProfileOrig->getUrl();
+        else
+            return 'javascript:void(0);';
+    }
+    
+    protected function isShowRealProfile() 
+    {
+        if (null !== $this->_isShowRealProfile)
+            return $this->_isShowRealProfile;
+
+        $this->_isShowRealProfile = (isAdmin() || $this->_oProfileOrig->id() == bx_get_logged_profile_id() || BxDolAcl::getInstance()->isMemberLevelInSet(array(MEMBERSHIP_ID_ADMINISTRATOR, MEMBERSHIP_ID_MODERATOR)));
+
+        return $this->_isShowRealProfile;
     }
 }
 

+ 2 - 12
modules/base/text/classes/BxBaseModTextTemplate.php

@@ -38,20 +38,10 @@ class BxBaseModTextTemplate extends BxBaseModGeneralTemplate
 
         if (!$iProfileId)
             $iProfileId = $aData[$CNF['FIELD_AUTHOR']];
-
-        // if post is anonymous then don't show author block for regular members
-        if ($aData[$CNF['FIELD_AUTHOR']] < 0 && !$this->getModule()->_isModerator())
-            return '';
         
-        $oProfile = BxDolProfile::getInstance($iProfileId >= 0 ? $iProfileId : -$iProfileId);
-        if (!$oProfile || !$iProfileId) 
-            $oProfile = BxDolProfileUndefined::getInstance();
-
-        if (!$oProfile)
-            return '';
-
+        $oProfile = BxDolProfile::getInstanceMagic($iProfileId);
         $sName = $oProfile->getDisplayName();
-        $sAddon = $sFuncAuthorAddon ? $this->$sFuncAuthorAddon($aData, $oProfile) : '';        
+        $sAddon = $sFuncAuthorAddon && is_a($oProfile, 'BxDolProfile') ? $this->$sFuncAuthorAddon($aData, $oProfile) : '';        
 
         $aVars = array (
             'author_url' => $oProfile->getUrl(),

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

@@ -13,6 +13,7 @@
 	<string name="_Allowed Until"><![CDATA[Allowed Until]]></string>
     <string name="_Allowed actions"><![CDATA[Allowed actions]]></string>
     <string name="_anonymous"><![CDATA[anonymous]]></string>
+    <string name="_anonymous_f"><![CDATA[anonymous ({0})]]></string>
 	<string name="_Are_you_sure"><![CDATA[Are you sure?]]></string>
 	<string name="_Auth type"><![CDATA[Auth type]]></string>
 	<string name="_Basic"><![CDATA[Basic]]></string>

+ 1 - 0
modules/boonex/russian/data/langs/system/ru.xml

@@ -13,6 +13,7 @@
 	<string name="_Allowed Until"><![CDATA[Разрешено до]]></string>
     <string name="_Allowed actions"><![CDATA[Разрешённые действия]]></string>
     <string name="_anonymous"><![CDATA[Аноним]]></string>
+    <string name="_anonymous_f"><![CDATA[Аноним ({0})]]></string>
 	<string name="_Are_you_sure"><![CDATA[Вы уверены?]]></string>
 	<string name="_Auth type"><![CDATA[Тип авторизации]]></string>
 	<string name="_Basic"><![CDATA[Базовая]]></string>

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

@@ -2577,9 +2577,6 @@ class BxTimelineModule extends BxBaseModNotificationsModule implements iBxDolCon
     {
         $iLoggedId = $this->getUserId();
         $iUserId = (int)$iUserId;
-        if($iUserId < 0  && (abs($iUserId) == $iLoggedId || $this->isModerator()))
-            $iUserId *= -1;
-
         return parent::getUserInfo($iUserId);
     }