BxDolProfileUndefined.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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 not available (for example profile is deleted) then use this special class.
  11. *
  12. * @section example Example of usage
  13. *
  14. * @code
  15. * $oProfile = BxDolProfile::getInstance($iId);
  16. * if (!$oProfile)
  17. * $oProfile = BxDolProfileUndefined::getInstance();
  18. * @endcode
  19. */
  20. class BxDolProfileUndefined extends BxDolFactory implements iBxDolSingleton, iBxDolProfile
  21. {
  22. /**
  23. * Constructor
  24. */
  25. protected function __construct ()
  26. {
  27. parent::__construct();
  28. }
  29. /**
  30. * Prevent cloning the instance
  31. */
  32. public function __clone()
  33. {
  34. $sClass = get_class($this);
  35. if (isset($GLOBALS['bxDolClasses'][$sClass]))
  36. trigger_error('Clone is not allowed for the class: ' . get_class($this), E_USER_ERROR);
  37. }
  38. /**
  39. * Get singleton instance of the class
  40. */
  41. public static function getInstance()
  42. {
  43. $sClass = __CLASS__;
  44. if(!isset($GLOBALS['bxDolClasses'][$sClass]))
  45. $GLOBALS['bxDolClasses'][$sClass] = new $sClass();
  46. return $GLOBALS['bxDolClasses'][$sClass];
  47. }
  48. /**
  49. * Get profile id
  50. */
  51. public function id()
  52. {
  53. return 0;
  54. }
  55. /**
  56. * Get profile display name
  57. */
  58. public function getDisplayName()
  59. {
  60. return _t('_uknown');
  61. }
  62. /**
  63. * Get profile url
  64. */
  65. public function getUrl()
  66. {
  67. return 'javascript:void(0);';
  68. }
  69. /**
  70. * Get profile unit
  71. */
  72. public function getUnit($iProfileId = 0, $aParams = array())
  73. {
  74. $aSize2Method = array(
  75. 'icon' => 'Icon',
  76. 'thumb' => 'Thumb',
  77. 'ava' => 'Avatar',
  78. 'ava-big' => 'Picture'
  79. );
  80. $sTemplate = 'profile_unit.html';
  81. $sTemplateSize = 'thumb';
  82. $aTemplateVars = array();
  83. if(!empty($aParams['template'])) {
  84. if(is_string($aParams['template']))
  85. $sTemplate = 'profile_' . $aParams['template'] . '.html';
  86. else if(is_array($aParams['template'])) {
  87. if(!empty($aParams['template']['name']))
  88. $sTemplate = 'profile_' . $aParams['template']['name'] . '.html';
  89. if(!empty($aParams['template']['size']))
  90. $sTemplateSize = $aParams['template']['size'];
  91. if(!empty($aParams['template']['vars']))
  92. $aTemplateVars = $aParams['template']['vars'];
  93. }
  94. }
  95. if(empty($sTemplateSize) || !isset($aSize2Method[$sTemplateSize]))
  96. $sTemplateSize = 'thumb';
  97. if(empty($aTemplateVars) || !is_array($aTemplateVars))
  98. $aTemplateVars = array();
  99. return BxDolTemplate::getInstance()->parseHtmlByName($sTemplate, array_merge(array(
  100. 'size' => $sTemplateSize,
  101. 'thumb_url' => $this->{'get' . $aSize2Method[$sTemplateSize]}(),
  102. 'title' => $this->getDisplayName()
  103. ), $aTemplateVars));
  104. }
  105. /**
  106. * Get profile unit for API calls
  107. */
  108. public function getUnitAPI($iProfileId = 0, $aParams = [])
  109. {
  110. return [];
  111. }
  112. /**
  113. * Get badges
  114. */
  115. public function getBadges()
  116. {
  117. return "";
  118. }
  119. /**
  120. * Check whether a profile has real image uploaded by user.
  121. */
  122. public function hasImage()
  123. {
  124. return false;
  125. }
  126. /**
  127. * Get picture url
  128. */
  129. public function getPicture()
  130. {
  131. return BxDolTemplate::getInstance()->getImageUrl('account.svg');
  132. }
  133. /**
  134. * Get big (2x) avatar url
  135. */
  136. public function getAvatarBig()
  137. {
  138. return BxDolTemplate::getInstance()->getImageUrl('account.svg');
  139. }
  140. /**
  141. * Get profile avatar
  142. */
  143. public function getAvatar()
  144. {
  145. return BxDolTemplate::getInstance()->getImageUrl('account.svg');
  146. }
  147. /**
  148. * Get profile cover
  149. */
  150. public function getCover()
  151. {
  152. return BxDolTemplate::getInstance()->getImageUrl('cover.svg');
  153. }
  154. /**
  155. * Get profile thumb
  156. */
  157. public function getThumb()
  158. {
  159. return BxDolTemplate::getInstance()->getImageUrl('account.svg');
  160. }
  161. /**
  162. * Get profile icon
  163. */
  164. public function getIcon()
  165. {
  166. return BxDolTemplate::getInstance()->getImageUrl('account.svg');
  167. }
  168. /**
  169. * Get module icon
  170. */
  171. public function getIconModule($iProfileId = 0)
  172. {
  173. return 'user';
  174. }
  175. /**
  176. * Get profile edit url
  177. */
  178. public function getEditUrl()
  179. {
  180. return '';
  181. }
  182. /**
  183. * @see iBxDolProfile::checkAllowedProfileView
  184. */
  185. public function checkAllowedProfileView($iProfileId = 0)
  186. {
  187. return CHECK_ACTION_RESULT_ALLOWED;
  188. }
  189. /**
  190. * @see iBxDolProfile::checkAllowedProfileContact
  191. */
  192. public function checkAllowedProfileContact($iProfileId = 0)
  193. {
  194. return _t('_sys_txt_access_denied');
  195. }
  196. /**
  197. * @see iBxDolProfile::checkAllowedPostInProfile
  198. */
  199. public function checkAllowedPostInProfile($iProfileId = 0)
  200. {
  201. return _t('_sys_txt_access_denied');
  202. }
  203. /**
  204. * Check if profile is active
  205. */
  206. public function isActive($iProfileId = false)
  207. {
  208. return true;
  209. }
  210. /**
  211. * Is profile online
  212. */
  213. public function isOnline($iProfileId = false)
  214. {
  215. return false;
  216. }
  217. public function getStatus($iProfileId = false)
  218. {
  219. return 'active';
  220. }
  221. public function getModule($iProfileId = false)
  222. {
  223. return 'system';
  224. }
  225. }
  226. /** @} */