BxBaseAcl.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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 UnaBaseView UNA Base Representation Classes
  7. * @{
  8. */
  9. /**
  10. * Acl representation.
  11. * @see BxDolAcl
  12. */
  13. class BxBaseAcl extends BxDolAcl
  14. {
  15. public function __construct ()
  16. {
  17. parent::__construct ();
  18. }
  19. public function getProfileMembership ($iProfileId)
  20. {
  21. $aLevel = $this->getMemberMembershipInfo($iProfileId, 0, true);
  22. if(empty($aLevel) || !is_array($aLevel))
  23. return '';
  24. $iLoggedProfileId = bx_get_logged_profile_id();
  25. $aLevelInfo = $this->getMembershipInfo($aLevel['id']);
  26. $aCheck = checkActionModule($iLoggedProfileId, 'show membership private info', 'system', false);
  27. $oProfile = BxDolProfile::getInstance($iLoggedProfileId);
  28. $aTmplVarsPrivateInfo = array();
  29. $bTmplVarsPrivateInfo = ($oProfile && (BxDolProfile::getInstance($iProfileId)->getAccountId() == $oProfile->getAccountId() || $aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED) && !empty($aLevel['date_starts']));
  30. if($bTmplVarsPrivateInfo)
  31. $aTmplVarsPrivateInfo = array(
  32. 'date_start' => bx_time_js($aLevel['date_starts']),
  33. 'date_expire' => (int)$aLevel['date_expires'] > 0 ? bx_time_js($aLevel['date_expires']) : _t('_sys_acl_expire_never'),
  34. 'bx_if:show_state' => array(
  35. 'condition' => !empty($aLevel['state']),
  36. 'content' => array(
  37. 'state' => _t('_sys_acl_state_' . $aLevel['state'])
  38. )
  39. )
  40. );
  41. $oTemplate = BxDolTemplate::getInstance();
  42. $sContent = $oTemplate->parseHtmlByName('acl_membership.html', array(
  43. 'html_id' => 'sys-acl-profile-' . $iProfileId,
  44. 'level' => _t($aLevel['name']),
  45. 'thumbnail' => $oTemplate->getImage($aLevelInfo['icon'], array('class' => 'bx-acl-m-thumbnail')),
  46. 'bx_if:show_private_info' => array(
  47. 'condition' => $bTmplVarsPrivateInfo,
  48. 'content' => $aTmplVarsPrivateInfo
  49. )
  50. ));
  51. /**
  52. * @hooks
  53. * @hookdef hook-system-page_output_block_acl_level 'system', 'page_output_block_acl_level' - hook to override profile membership page block
  54. * - $unit_name - equals `system`
  55. * - $action - equals `page_output_block_acl_level`
  56. * - $object_id - not used
  57. * - $sender_id - not used
  58. * - $extra_params - array of additional params with the following array keys:
  59. * - `block_owner` - [int] profile id to show membership level for
  60. * - `block_code` - [string] by ref, block code, can be overridden in hook processing
  61. * @hook @ref hook-system-page_output_block_acl_level
  62. */
  63. bx_alert('system', 'page_output_block_acl_level', 0, false, [
  64. 'block_owner' => $iProfileId,
  65. 'block_code' => &$sContent
  66. ]);
  67. $oTemplate->addCss(array('acl.css'));
  68. return $sContent;
  69. }
  70. /**
  71. * Print code for membership status
  72. * $iProfileId - ID of profile
  73. * $offer_upgrade - will this code be printed at [c]ontrol [p]anel
  74. */
  75. function GetMembershipStatus($iProfileId, $bOfferUpgrade = true)
  76. {
  77. $aMembershipInfo = $this->getMemberMembershipInfo($iProfileId);
  78. $sViewMembershipActions = "<br />(<a onclick=\"javascript:window.open('explanation.php?explain=membership&amp;type=".$aMembershipInfo['ID']."', '', 'width=660, height=500, menubar=no, status=no, resizable=no, scrollbars=yes, toolbar=no, location=no');\" href=\"javascript:void(0);\">"._t("_VIEW_MEMBERSHIP_ACTIONS")."</a>)<br />";
  79. // Show colored membership name
  80. $ret = '';
  81. if ( $aMembershipInfo['ID'] == MEMBERSHIP_ID_STANDARD || $aMembershipInfo['ID'] == MEMBERSHIP_ID_AUTHENTICATED) {
  82. $ret .= _t( "_MEMBERSHIP_STANDARD" ). $sViewMembershipActions;
  83. if ( $bOfferUpgrade )
  84. $ret .= " ". _t( "_MEMBERSHIP_UPGRADE_FROM_STANDARD" );
  85. } else {
  86. $ret .= "<font color=\"red\">{$aMembershipInfo['Name']}</font>$sViewMembershipActions";
  87. $days_left = (int)( ($aMembershipInfo['DateExpires'] - time()) / (24 * 3600) );
  88. if(!is_null($aMembershipInfo['DateExpires'])) {
  89. $ret .= ( $days_left > 0 ) ? _t( "_MEMBERSHIP_EXPIRES_IN_DAYS", $days_left ) : _t( "_MEMBERSHIP_EXPIRES_TODAY", date( "H:i", $aMembershipInfo['DateExpires'] ), date( "H:i" ) );
  90. } else {
  91. $ret.= _t("_MEMBERSHIP_EXPIRES_NEVER");
  92. }
  93. }
  94. return $ret;
  95. }
  96. }
  97. /** @} */