1
0

BxDolProfileAnonymous.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup UnaCore UNA Core
  7. * @{
  8. */
  9. /**
  10. * When profile is anonymous then use this special class.
  11. *
  12. * @section example Example of usage
  13. *
  14. * @code
  15. * if (0 > $iId)
  16. * $oProfile = BxDolProfileAnonymous::getInstance();
  17. * else
  18. * $oProfile = BxDolProfile::getInstance($iId);
  19. *
  20. * @endcode
  21. */
  22. class BxDolProfileAnonymous extends BxDolProfileUndefined
  23. {
  24. protected $_oProfileOrig = null;
  25. protected $_iProfileID = 0;
  26. protected $_isShowRealProfile = null;
  27. /**
  28. * Constructor
  29. */
  30. protected function __construct ($oProfile)
  31. {
  32. $sClass = get_class($this) . '_' . $oProfile->id();
  33. if (isset($GLOBALS['bxDolClasses'][$sClass]))
  34. trigger_error ('Multiple instances are not allowed for the class: ' . get_class($this), E_USER_ERROR);
  35. parent::__construct();
  36. $this->_iProfileID = $oProfile->id();
  37. $this->_oProfileOrig = $oProfile;
  38. }
  39. /**
  40. * Get singleton instance of Profile by profile id
  41. */
  42. public static function getInstance($mixedProfileId = false, $bClearCache = false)
  43. {
  44. $oProfile = BxDolProfile::getInstance(abs($mixedProfileId));
  45. if (!$oProfile)
  46. return BxDolProfileUndefined::getInstance();
  47. $sClass = __CLASS__ . '_' . $oProfile->id();
  48. if (!isset($GLOBALS['bxDolClasses'][$sClass]))
  49. $GLOBALS['bxDolClasses'][$sClass] = new BxDolProfileAnonymous($oProfile);
  50. return $GLOBALS['bxDolClasses'][$sClass];
  51. }
  52. /**
  53. * Get profile display name
  54. */
  55. public function getDisplayName()
  56. {
  57. if ($this->isShowRealProfile())
  58. return _t('_anonymous_f', $this->_oProfileOrig->getDisplayName());
  59. else
  60. return _t('_anonymous');
  61. }
  62. public function getUrl()
  63. {
  64. if ($this->isShowRealProfile())
  65. return $this->_oProfileOrig->getUrl();
  66. else
  67. return 'javascript:void(0);';
  68. }
  69. public function setShowRealProfile($bValue)
  70. {
  71. $this->_isShowRealProfile = $bValue;
  72. }
  73. protected function isShowRealProfile()
  74. {
  75. if (null !== $this->_isShowRealProfile)
  76. return $this->_isShowRealProfile;
  77. $this->_isShowRealProfile = (isAdmin() || $this->_oProfileOrig->id() == bx_get_logged_profile_id() || BxDolAcl::getInstance()->isMemberLevelInSet(array(MEMBERSHIP_ID_ADMINISTRATOR, MEMBERSHIP_ID_MODERATOR)));
  78. return $this->_isShowRealProfile;
  79. }
  80. }
  81. /** @} */