| 1 | <?php |
|---|
| 2 | /** |
|---|
| 3 | * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/ |
|---|
| 4 | * CC-BY License - http://creativecommons.org/licenses/by/3.0/ |
|---|
| 5 | * |
|---|
| 6 | * @defgroup DolphinStudio Dolphin Studio |
|---|
| 7 | * @{ |
|---|
| 8 | */ |
|---|
| 9 | defined('BX_DOL') or die('hack attempt'); |
|---|
| 10 | |
|---|
| 11 | bx_import('BxDol'); |
|---|
| 12 | |
|---|
| 13 | define('BX_DOL_STUDIO_MODULE_SYSTEM', 'system'); |
|---|
| 14 | define('BX_DOL_STUDIO_MODULE_CUSTOM', 'custom'); |
|---|
| 15 | |
|---|
| 16 | define('BX_DOL_STUDIO_VISIBLE_ALL', 'all'); |
|---|
| 17 | define('BX_DOL_STUDIO_VISIBLE_SELECTED', 'selected'); |
|---|
| 18 | |
|---|
| 19 | class BxDolStudioUtils extends BxDol { |
|---|
| 20 | function __construct() { |
|---|
| 21 | parent::BxDol(); |
|---|
| 22 | } |
|---|
| 23 | |
|---|
| 24 | public static function getSystemName($sValue) { |
|---|
| 25 | return str_replace(' ', '_', strtolower($sValue)); |
|---|
| 26 | } |
|---|
| 27 | |
|---|
| 28 | public static function getClassName($sValue) { |
|---|
| 29 | return str_replace(' ', '', ucwords(str_replace('_', ' ', $sValue))); |
|---|
| 30 | } |
|---|
| 31 | |
|---|
| 32 | public static function getModuleIcon($sName, $sType = 'menu') { |
|---|
| 33 | $aType2Prefix = array('menu' => 'mi', 'page' => 'pi'); |
|---|
| 34 | |
|---|
| 35 | $oTemplate = BxDolStudioTemplate::getInstance(); |
|---|
| 36 | $sDefaultIcon = $oTemplate->getIconUrl($aType2Prefix[$sType] . '-mod-empty.png'); |
|---|
| 37 | |
|---|
| 38 | bx_import('BxDolModuleQuery'); |
|---|
| 39 | $aModule = BxDolModuleQuery::getInstance()->getModuleByName($sName); |
|---|
| 40 | if(empty($aModule)) |
|---|
| 41 | return $sDefaultIcon; |
|---|
| 42 | |
|---|
| 43 | $sModuleIcon = isset($aModule['path']) ? $oTemplate->getIconUrl($aModule['name'] . '@modules/' . $aModule['path'] . '|std-' . $aType2Prefix[$sType] . '.png') : ''; |
|---|
| 44 | return !empty($sModuleIcon) ? $sModuleIcon : $sDefaultIcon; |
|---|
| 45 | } |
|---|
| 46 | |
|---|
| 47 | public static function getModuleTitle($sName) { |
|---|
| 48 | $sPrefix = '_adm_txt_module_'; |
|---|
| 49 | |
|---|
| 50 | if(in_array($sName, array(BX_DOL_STUDIO_MODULE_SYSTEM, BX_DOL_STUDIO_MODULE_CUSTOM))) |
|---|
| 51 | return _t($sPrefix . $sName); |
|---|
| 52 | |
|---|
| 53 | bx_import('BxDolModuleQuery'); |
|---|
| 54 | $aModule = BxDolModuleQuery::getInstance()->getModuleByName($sName); |
|---|
| 55 | if(!empty($aModule)) |
|---|
| 56 | return $aModule['title']; |
|---|
| 57 | |
|---|
| 58 | return _t($sPrefix . strtolower($sName)); |
|---|
| 59 | } |
|---|
| 60 | |
|---|
| 61 | public static function getModules($bShowCustom = true, $bShowSystem = true) { |
|---|
| 62 | $aResult = array(); |
|---|
| 63 | |
|---|
| 64 | if($bShowSystem) |
|---|
| 65 | $aResult[BX_DOL_STUDIO_MODULE_SYSTEM] = self::getModuleTitle(BX_DOL_STUDIO_MODULE_SYSTEM); |
|---|
| 66 | |
|---|
| 67 | if($bShowCustom) |
|---|
| 68 | $aResult[BX_DOL_STUDIO_MODULE_CUSTOM] = self::getModuleTitle(BX_DOL_STUDIO_MODULE_CUSTOM); |
|---|
| 69 | |
|---|
| 70 | bx_import('BxDolModuleQuery'); |
|---|
| 71 | $aModules = BxDolModuleQuery::getInstance()->getModulesBy(array('type' => 'modules', 'active' => 1)); |
|---|
| 72 | foreach($aModules as $aModule) |
|---|
| 73 | $aResult[$aModule['name']] = $aModule['title']; |
|---|
| 74 | |
|---|
| 75 | return $aResult; |
|---|
| 76 | } |
|---|
| 77 | public static function getVisibilityTitle($iValue) { |
|---|
| 78 | $iCount = self::getVisibilityCount($iValue); |
|---|
| 79 | |
|---|
| 80 | $sResult = ""; |
|---|
| 81 | switch($iCount) { |
|---|
| 82 | case 1: |
|---|
| 83 | bx_import('BxDolAcl'); |
|---|
| 84 | $aLevel = BxDolAcl::getInstance()->getMembershipInfo(log($iValue, 2) + 1); |
|---|
| 85 | $sResult = _t($aLevel['name']); |
|---|
| 86 | break; |
|---|
| 87 | case 0: |
|---|
| 88 | $sResult = _t('_adm_prm_txt_visibility_items_nobody'); |
|---|
| 89 | break; |
|---|
| 90 | case -1: |
|---|
| 91 | $sResult = _t('_adm_prm_txt_visibility_items_anyone'); |
|---|
| 92 | break; |
|---|
| 93 | default: |
|---|
| 94 | $sResult = _t('_adm_prm_txt_visibility_items_n_user_levels', $iCount); |
|---|
| 95 | } |
|---|
| 96 | |
|---|
| 97 | return $sResult; |
|---|
| 98 | } |
|---|
| 99 | |
|---|
| 100 | public static function getVisibilityCount($iValue) { |
|---|
| 101 | $iResult = 0; |
|---|
| 102 | |
|---|
| 103 | $iValue = (int)$iValue; |
|---|
| 104 | if($iValue == 0) |
|---|
| 105 | return $iResult; |
|---|
| 106 | else if($iValue == BX_DOL_INT_MAX) |
|---|
| 107 | return -1; |
|---|
| 108 | |
|---|
| 109 | bx_import('BxDolAcl'); |
|---|
| 110 | $aLevels = BxDolAcl::getInstance()->getMemberships(false, true); |
|---|
| 111 | |
|---|
| 112 | $iIndex = 1; |
|---|
| 113 | do { |
|---|
| 114 | if(array_key_exists($iIndex++, $aLevels)) |
|---|
| 115 | $iResult += $iValue & 1; |
|---|
| 116 | } while(($iValue = $iValue >> 1) != 0); |
|---|
| 117 | |
|---|
| 118 | return $iResult; |
|---|
| 119 | } |
|---|
| 120 | |
|---|
| 121 | public static function getVisibilityValue($sVisibleFor, $aVisibleForLevels) { |
|---|
| 122 | if($sVisibleFor == BX_DOL_STUDIO_VISIBLE_ALL) |
|---|
| 123 | return BX_DOL_INT_MAX; |
|---|
| 124 | |
|---|
| 125 | $iVisibleFor = 0; |
|---|
| 126 | if(is_array($aVisibleForLevels)) |
|---|
| 127 | foreach($aVisibleForLevels as $iLevelId) |
|---|
| 128 | $iVisibleFor += pow(2, (int)$iLevelId - 1); |
|---|
| 129 | |
|---|
| 130 | return $iVisibleFor; |
|---|
| 131 | } |
|---|
| 132 | |
|---|
| 133 | public static function getVisibilityValues($iValue, &$aValuesAll, &$aValuesSelected) { |
|---|
| 134 | bx_import('BxDolAcl'); |
|---|
| 135 | $aLevels = BxDolAcl::getInstance()->getMemberships(false, true); |
|---|
| 136 | foreach($aLevels as $iKey => $sValue) { |
|---|
| 137 | if(((int)$iValue & pow(2, (int)$iKey - 1)) != 0) |
|---|
| 138 | $aValuesSelected[] = $iKey; |
|---|
| 139 | |
|---|
| 140 | $aValuesAll[$iKey] = _t($sValue); |
|---|
| 141 | } |
|---|
| 142 | } |
|---|
| 143 | |
|---|
| 144 | public static function addInArray($aInput, $sKey, $aValues) { |
|---|
| 145 | reset($aInput); |
|---|
| 146 | $iInput = count($aInput); |
|---|
| 147 | for($i = 0; $i < $iInput; $i++, next($aInput)) |
|---|
| 148 | if(key($aInput) == $sKey) |
|---|
| 149 | break; |
|---|
| 150 | |
|---|
| 151 | $aOutput = array_slice($aInput, 0, $i + 1); |
|---|
| 152 | $aOutput = array_merge($aOutput, $aValues); |
|---|
| 153 | $aOutput = array_merge($aOutput, array_slice($aInput, $i + 1)); |
|---|
| 154 | |
|---|
| 155 | return $aOutput; |
|---|
| 156 | } |
|---|
| 157 | } |
|---|
| 158 | /** @} */ |
|---|