Changeset View
Changeset View
Standalone View
Standalone View
src/applications/settings/storage/PhabricatorUserPreferences.php
| Show First 20 Lines • Show All 67 Lines • ▼ Show 20 Lines | final class PhabricatorUserPreferences | ||||
| public function getDefaultValue($key) { | public function getDefaultValue($key) { | ||||
| $setting = self::getSettingObject($key); | $setting = self::getSettingObject($key); | ||||
| if (!$setting) { | if (!$setting) { | ||||
| return null; | return null; | ||||
| } | } | ||||
| return $setting->getSettingDefaultValue(); | $setting = id(clone $setting) | ||||
| } | ->setViewer($this->getUser()); | ||||
| private static function getSettingObject($key) { | |||||
| $settings = PhabricatorSetting::getAllSettings(); | |||||
| return idx($settings, $key); | |||||
| } | |||||
| public function getPinnedApplications(array $apps, PhabricatorUser $viewer) { | |||||
| $pref_pinned = self::PREFERENCE_APP_PINNED; | |||||
| $pinned = $this->getPreference($pref_pinned); | |||||
| if ($pinned) { | return $setting->getSettingDefaultValue(); | ||||
| return $pinned; | |||||
| } | } | ||||
| $pref_tiles = self::PREFERENCE_APP_TILES; | public function getSettingValue($key) { | ||||
| $tiles = $this->getPreference($pref_tiles, array()); | if (array_key_exists($key, $this->preferences)) { | ||||
| $full_tile = 'full'; | return $this->preferences[$key]; | ||||
| $large = array(); | |||||
| foreach ($apps as $app) { | |||||
| $show = $app->isPinnedByDefault($viewer); | |||||
| // TODO: This is legacy stuff, clean it up eventually. This approximately | |||||
| // retains the old "tiles" preference. | |||||
| if (isset($tiles[get_class($app)])) { | |||||
| $show = ($tiles[get_class($app)] == $full_tile); | |||||
| } | } | ||||
| if ($show) { | // TODO: If this setting set inherits from another preference set, | ||||
| $large[] = get_class($app); | // we would look it up here. | ||||
| } | |||||
| } | |||||
| return $large; | return $this->getDefaultValue($key); | ||||
| } | } | ||||
| public static function filterMonospacedCSSRule($monospaced) { | private static function getSettingObject($key) { | ||||
| // Prevent the user from doing dangerous things. | $settings = PhabricatorSetting::getAllSettings(); | ||||
| return preg_replace('([^a-z0-9 ,"./]+)i', '', $monospaced); | return idx($settings, $key); | ||||
| } | } | ||||
| public function attachUser(PhabricatorUser $user = null) { | public function attachUser(PhabricatorUser $user = null) { | ||||
| $this->user = $user; | $this->user = $user; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function getUser() { | public function getUser() { | ||||
| ▲ Show 20 Lines • Show All 136 Lines • Show Last 20 Lines | |||||