@@ -25,5 +25,5 @@ |
||
| 25 | 25 | style('accessibility', 'style'); |
| 26 | 26 | ?> |
| 27 | 27 | |
| 28 | -<span id="serverData" data-server="<?php p(json_encode($_['serverData']));?>"></span> |
|
| 28 | +<span id="serverData" data-server="<?php p(json_encode($_['serverData'])); ?>"></span> |
|
| 29 | 29 | <span id="accessibility"></span> |
| 30 | 30 | \ No newline at end of file |
@@ -29,72 +29,72 @@ |
||
| 29 | 29 | |
| 30 | 30 | class PersonalSection implements IIconSection { |
| 31 | 31 | |
| 32 | - /** @var string */ |
|
| 33 | - protected $appName; |
|
| 32 | + /** @var string */ |
|
| 33 | + protected $appName; |
|
| 34 | 34 | |
| 35 | - /** @var IURLGenerator */ |
|
| 36 | - private $urlGenerator; |
|
| 35 | + /** @var IURLGenerator */ |
|
| 36 | + private $urlGenerator; |
|
| 37 | 37 | |
| 38 | - /** @var IL10N */ |
|
| 39 | - private $l; |
|
| 38 | + /** @var IL10N */ |
|
| 39 | + private $l; |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * Personal Section constructor. |
|
| 43 | - * |
|
| 44 | - * @param string $appName |
|
| 45 | - * @param IURLGenerator $urlGenerator |
|
| 46 | - * @param IL10N $l |
|
| 47 | - */ |
|
| 48 | - public function __construct(string $appName, |
|
| 49 | - IURLGenerator $urlGenerator, |
|
| 50 | - IL10N $l) { |
|
| 51 | - $this->appName = $appName; |
|
| 52 | - $this->urlGenerator = $urlGenerator; |
|
| 53 | - $this->l = $l; |
|
| 54 | - } |
|
| 41 | + /** |
|
| 42 | + * Personal Section constructor. |
|
| 43 | + * |
|
| 44 | + * @param string $appName |
|
| 45 | + * @param IURLGenerator $urlGenerator |
|
| 46 | + * @param IL10N $l |
|
| 47 | + */ |
|
| 48 | + public function __construct(string $appName, |
|
| 49 | + IURLGenerator $urlGenerator, |
|
| 50 | + IL10N $l) { |
|
| 51 | + $this->appName = $appName; |
|
| 52 | + $this->urlGenerator = $urlGenerator; |
|
| 53 | + $this->l = $l; |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * returns the relative path to an 16*16 icon describing the section. |
|
| 58 | - * e.g. '/core/img/places/files.svg' |
|
| 59 | - * |
|
| 60 | - * @returns string |
|
| 61 | - * @since 13.0.0 |
|
| 62 | - */ |
|
| 63 | - public function getIcon() { |
|
| 64 | - return $this->urlGenerator->imagePath($this->appName, 'app-dark.svg'); |
|
| 65 | - } |
|
| 56 | + /** |
|
| 57 | + * returns the relative path to an 16*16 icon describing the section. |
|
| 58 | + * e.g. '/core/img/places/files.svg' |
|
| 59 | + * |
|
| 60 | + * @returns string |
|
| 61 | + * @since 13.0.0 |
|
| 62 | + */ |
|
| 63 | + public function getIcon() { |
|
| 64 | + return $this->urlGenerator->imagePath($this->appName, 'app-dark.svg'); |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - /** |
|
| 68 | - * returns the ID of the section. It is supposed to be a lower case string, |
|
| 69 | - * e.g. 'ldap' |
|
| 70 | - * |
|
| 71 | - * @returns string |
|
| 72 | - * @since 9.1 |
|
| 73 | - */ |
|
| 74 | - public function getID() { |
|
| 75 | - return $this->appName; |
|
| 76 | - } |
|
| 67 | + /** |
|
| 68 | + * returns the ID of the section. It is supposed to be a lower case string, |
|
| 69 | + * e.g. 'ldap' |
|
| 70 | + * |
|
| 71 | + * @returns string |
|
| 72 | + * @since 9.1 |
|
| 73 | + */ |
|
| 74 | + public function getID() { |
|
| 75 | + return $this->appName; |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | - /** |
|
| 79 | - * returns the translated name as it should be displayed, e.g. 'LDAP / AD |
|
| 80 | - * integration'. Use the L10N service to translate it. |
|
| 81 | - * |
|
| 82 | - * @return string |
|
| 83 | - * @since 9.1 |
|
| 84 | - */ |
|
| 85 | - public function getName() { |
|
| 86 | - return $this->l->t('Accessibility'); |
|
| 87 | - } |
|
| 78 | + /** |
|
| 79 | + * returns the translated name as it should be displayed, e.g. 'LDAP / AD |
|
| 80 | + * integration'. Use the L10N service to translate it. |
|
| 81 | + * |
|
| 82 | + * @return string |
|
| 83 | + * @since 9.1 |
|
| 84 | + */ |
|
| 85 | + public function getName() { |
|
| 86 | + return $this->l->t('Accessibility'); |
|
| 87 | + } |
|
| 88 | 88 | |
| 89 | - /** |
|
| 90 | - * @return int whether the form should be rather on the top or bottom of |
|
| 91 | - * the settings navigation. The sections are arranged in ascending order of |
|
| 92 | - * the priority values. It is required to return a value between 0 and 99. |
|
| 93 | - * |
|
| 94 | - * E.g.: 70 |
|
| 95 | - * @since 9.1 |
|
| 96 | - */ |
|
| 97 | - public function getPriority() { |
|
| 98 | - return 15; |
|
| 99 | - } |
|
| 89 | + /** |
|
| 90 | + * @return int whether the form should be rather on the top or bottom of |
|
| 91 | + * the settings navigation. The sections are arranged in ascending order of |
|
| 92 | + * the priority values. It is required to return a value between 0 and 99. |
|
| 93 | + * |
|
| 94 | + * E.g.: 70 |
|
| 95 | + * @since 9.1 |
|
| 96 | + */ |
|
| 97 | + public function getPriority() { |
|
| 98 | + return 15; |
|
| 99 | + } |
|
| 100 | 100 | } |
@@ -29,55 +29,55 @@ |
||
| 29 | 29 | |
| 30 | 30 | class AccessibilityProvider { |
| 31 | 31 | |
| 32 | - /** @var string */ |
|
| 33 | - protected $appName; |
|
| 32 | + /** @var string */ |
|
| 33 | + protected $appName; |
|
| 34 | 34 | |
| 35 | - /** @var IURLGenerator */ |
|
| 36 | - private $urlGenerator; |
|
| 35 | + /** @var IURLGenerator */ |
|
| 36 | + private $urlGenerator; |
|
| 37 | 37 | |
| 38 | - /** @var IL10N */ |
|
| 39 | - private $l; |
|
| 38 | + /** @var IL10N */ |
|
| 39 | + private $l; |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * Account constructor. |
|
| 43 | - * |
|
| 44 | - * @param string $appName |
|
| 45 | - * @param IURLGenerator $urlGenerator |
|
| 46 | - * @param IL10N $l |
|
| 47 | - */ |
|
| 48 | - public function __construct(string $appName, |
|
| 49 | - IURLGenerator $urlGenerator, |
|
| 50 | - IL10N $l) { |
|
| 51 | - $this->appName = $appName; |
|
| 52 | - $this->urlGenerator = $urlGenerator; |
|
| 53 | - $this->l = $l; |
|
| 54 | - } |
|
| 41 | + /** |
|
| 42 | + * Account constructor. |
|
| 43 | + * |
|
| 44 | + * @param string $appName |
|
| 45 | + * @param IURLGenerator $urlGenerator |
|
| 46 | + * @param IL10N $l |
|
| 47 | + */ |
|
| 48 | + public function __construct(string $appName, |
|
| 49 | + IURLGenerator $urlGenerator, |
|
| 50 | + IL10N $l) { |
|
| 51 | + $this->appName = $appName; |
|
| 52 | + $this->urlGenerator = $urlGenerator; |
|
| 53 | + $this->l = $l; |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - public function getThemes() { |
|
| 57 | - return array( |
|
| 58 | - [ |
|
| 59 | - 'id' => 'highcontrast', |
|
| 60 | - 'img' => $this->urlGenerator->imagePath($this->appName, 'theme-highcontrast.jpg'), |
|
| 61 | - 'title' => $this->l->t('High Contrast theme'), |
|
| 62 | - 'text' => $this->l->t('A high contrast theme to ease your navigation. Visual quality will be reduced but clarity will be increased.') |
|
| 63 | - ], [ |
|
| 64 | - 'id' => 'dark', |
|
| 65 | - 'img' => $this->urlGenerator->imagePath($this->appName, 'theme-dark.jpg'), |
|
| 66 | - 'title' => $this->l->t('Dark theme'), |
|
| 67 | - 'text' => $this->l->t('A dark theme to ease your eyes by reducing the overall luminosity and brightness of your navigation. This is suitable for people who use computes a lot or in low luminosity spaces.') |
|
| 68 | - ] |
|
| 69 | - ); |
|
| 70 | - } |
|
| 56 | + public function getThemes() { |
|
| 57 | + return array( |
|
| 58 | + [ |
|
| 59 | + 'id' => 'highcontrast', |
|
| 60 | + 'img' => $this->urlGenerator->imagePath($this->appName, 'theme-highcontrast.jpg'), |
|
| 61 | + 'title' => $this->l->t('High Contrast theme'), |
|
| 62 | + 'text' => $this->l->t('A high contrast theme to ease your navigation. Visual quality will be reduced but clarity will be increased.') |
|
| 63 | + ], [ |
|
| 64 | + 'id' => 'dark', |
|
| 65 | + 'img' => $this->urlGenerator->imagePath($this->appName, 'theme-dark.jpg'), |
|
| 66 | + 'title' => $this->l->t('Dark theme'), |
|
| 67 | + 'text' => $this->l->t('A dark theme to ease your eyes by reducing the overall luminosity and brightness of your navigation. This is suitable for people who use computes a lot or in low luminosity spaces.') |
|
| 68 | + ] |
|
| 69 | + ); |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - public function getFonts() { |
|
| 73 | - return array( |
|
| 74 | - [ |
|
| 75 | - 'id' => 'dyslexic', |
|
| 76 | - 'img' => $this->urlGenerator->imagePath($this->appName, 'font-opendyslexic.jpg'), |
|
| 77 | - 'title' => $this->l->t('Dyslexia font'), |
|
| 78 | - 'text' => $this->l->t('OpenDyslexic is a free typeface/font designed to mitigate some of the common reading errors caused by dyslexia. The typeface was created by Abelardo Gonzalez, who released it through an open-source license.') |
|
| 79 | - ] |
|
| 80 | - ); |
|
| 81 | - } |
|
| 72 | + public function getFonts() { |
|
| 73 | + return array( |
|
| 74 | + [ |
|
| 75 | + 'id' => 'dyslexic', |
|
| 76 | + 'img' => $this->urlGenerator->imagePath($this->appName, 'font-opendyslexic.jpg'), |
|
| 77 | + 'title' => $this->l->t('Dyslexia font'), |
|
| 78 | + 'text' => $this->l->t('OpenDyslexic is a free typeface/font designed to mitigate some of the common reading errors caused by dyslexia. The typeface was created by Abelardo Gonzalez, who released it through an open-source license.') |
|
| 79 | + ] |
|
| 80 | + ); |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | 83 | } |
| 84 | 84 | \ No newline at end of file |
@@ -33,81 +33,81 @@ |
||
| 33 | 33 | |
| 34 | 34 | class Personal implements ISettings { |
| 35 | 35 | |
| 36 | - /** @var string */ |
|
| 37 | - protected $appName; |
|
| 36 | + /** @var string */ |
|
| 37 | + protected $appName; |
|
| 38 | 38 | |
| 39 | - /** @var IConfig */ |
|
| 40 | - private $config; |
|
| 39 | + /** @var IConfig */ |
|
| 40 | + private $config; |
|
| 41 | 41 | |
| 42 | - /** @var IUserSession */ |
|
| 43 | - private $userSession; |
|
| 42 | + /** @var IUserSession */ |
|
| 43 | + private $userSession; |
|
| 44 | 44 | |
| 45 | - /** @var IL10N */ |
|
| 46 | - private $l; |
|
| 45 | + /** @var IL10N */ |
|
| 46 | + private $l; |
|
| 47 | 47 | |
| 48 | - /** @var IURLGenerator */ |
|
| 49 | - private $urlGenerator; |
|
| 48 | + /** @var IURLGenerator */ |
|
| 49 | + private $urlGenerator; |
|
| 50 | 50 | |
| 51 | - /** @var AccessibilityProvider */ |
|
| 52 | - private $accessibilityProvider; |
|
| 51 | + /** @var AccessibilityProvider */ |
|
| 52 | + private $accessibilityProvider; |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * Settings constructor. |
|
| 56 | - * |
|
| 57 | - * @param string $appName |
|
| 58 | - * @param IConfig $config |
|
| 59 | - * @param IUserSession $userSession |
|
| 60 | - * @param IL10N $l |
|
| 61 | - * @param IURLGenerator $urlGenerator |
|
| 62 | - * @param AccessibilityProvider $accessibilityProvider |
|
| 63 | - */ |
|
| 64 | - public function __construct(string $appName, |
|
| 65 | - IConfig $config, |
|
| 66 | - IUserSession $userSession, |
|
| 67 | - IL10N $l, |
|
| 68 | - IURLGenerator $urlGenerator, |
|
| 69 | - AccessibilityProvider $accessibilityProvider) { |
|
| 70 | - $this->appName = $appName; |
|
| 71 | - $this->config = $config; |
|
| 72 | - $this->userSession = $userSession; |
|
| 73 | - $this->l = $l; |
|
| 74 | - $this->urlGenerator = $urlGenerator; |
|
| 75 | - $this->accessibilityProvider = $accessibilityProvider; |
|
| 76 | - } |
|
| 54 | + /** |
|
| 55 | + * Settings constructor. |
|
| 56 | + * |
|
| 57 | + * @param string $appName |
|
| 58 | + * @param IConfig $config |
|
| 59 | + * @param IUserSession $userSession |
|
| 60 | + * @param IL10N $l |
|
| 61 | + * @param IURLGenerator $urlGenerator |
|
| 62 | + * @param AccessibilityProvider $accessibilityProvider |
|
| 63 | + */ |
|
| 64 | + public function __construct(string $appName, |
|
| 65 | + IConfig $config, |
|
| 66 | + IUserSession $userSession, |
|
| 67 | + IL10N $l, |
|
| 68 | + IURLGenerator $urlGenerator, |
|
| 69 | + AccessibilityProvider $accessibilityProvider) { |
|
| 70 | + $this->appName = $appName; |
|
| 71 | + $this->config = $config; |
|
| 72 | + $this->userSession = $userSession; |
|
| 73 | + $this->l = $l; |
|
| 74 | + $this->urlGenerator = $urlGenerator; |
|
| 75 | + $this->accessibilityProvider = $accessibilityProvider; |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | - /** |
|
| 79 | - * @return TemplateResponse returns the instance with all parameters set, ready to be rendered |
|
| 80 | - * @since 9.1 |
|
| 81 | - */ |
|
| 82 | - public function getForm() { |
|
| 78 | + /** |
|
| 79 | + * @return TemplateResponse returns the instance with all parameters set, ready to be rendered |
|
| 80 | + * @since 9.1 |
|
| 81 | + */ |
|
| 82 | + public function getForm() { |
|
| 83 | 83 | |
| 84 | - $serverData = [ |
|
| 85 | - 'themes' => $this->accessibilityProvider->getThemes(), |
|
| 86 | - 'fonts' => $this->accessibilityProvider->getFonts(), |
|
| 87 | - 'theme' => $this->config->getUserValue($this->userSession->getUser()->getUID(), $this->appName, 'theme', false), |
|
| 88 | - 'font' => $this->config->getUserValue($this->userSession->getUser()->getUID(), $this->appName, 'font', false) |
|
| 89 | - ]; |
|
| 84 | + $serverData = [ |
|
| 85 | + 'themes' => $this->accessibilityProvider->getThemes(), |
|
| 86 | + 'fonts' => $this->accessibilityProvider->getFonts(), |
|
| 87 | + 'theme' => $this->config->getUserValue($this->userSession->getUser()->getUID(), $this->appName, 'theme', false), |
|
| 88 | + 'font' => $this->config->getUserValue($this->userSession->getUser()->getUID(), $this->appName, 'font', false) |
|
| 89 | + ]; |
|
| 90 | 90 | |
| 91 | - return new TemplateResponse($this->appName, 'settings-personal', ['serverData' => $serverData]); |
|
| 92 | - } |
|
| 91 | + return new TemplateResponse($this->appName, 'settings-personal', ['serverData' => $serverData]); |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - /** |
|
| 95 | - * @return string the section ID, e.g. 'sharing' |
|
| 96 | - * @since 9.1 |
|
| 97 | - */ |
|
| 98 | - public function getSection() { |
|
| 99 | - return $this->appName; |
|
| 100 | - } |
|
| 94 | + /** |
|
| 95 | + * @return string the section ID, e.g. 'sharing' |
|
| 96 | + * @since 9.1 |
|
| 97 | + */ |
|
| 98 | + public function getSection() { |
|
| 99 | + return $this->appName; |
|
| 100 | + } |
|
| 101 | 101 | |
| 102 | - /** |
|
| 103 | - * @return int whether the form should be rather on the top or bottom of |
|
| 104 | - * the admin section. The forms are arranged in ascending order of the |
|
| 105 | - * priority values. It is required to return a value between 0 and 100. |
|
| 106 | - * |
|
| 107 | - * E.g.: 70 |
|
| 108 | - * @since 9.1 |
|
| 109 | - */ |
|
| 110 | - public function getPriority() { |
|
| 111 | - return 40; |
|
| 112 | - } |
|
| 102 | + /** |
|
| 103 | + * @return int whether the form should be rather on the top or bottom of |
|
| 104 | + * the admin section. The forms are arranged in ascending order of the |
|
| 105 | + * priority values. It is required to return a value between 0 and 100. |
|
| 106 | + * |
|
| 107 | + * E.g.: 70 |
|
| 108 | + * @since 9.1 |
|
| 109 | + */ |
|
| 110 | + public function getPriority() { |
|
| 111 | + return 40; |
|
| 112 | + } |
|
| 113 | 113 | } |
@@ -38,129 +38,129 @@ |
||
| 38 | 38 | |
| 39 | 39 | class AccessibilityController extends Controller { |
| 40 | 40 | |
| 41 | - /** @var string */ |
|
| 42 | - protected $appName; |
|
| 43 | - |
|
| 44 | - /** @var string */ |
|
| 45 | - protected $serverRoot; |
|
| 46 | - |
|
| 47 | - /** @var IConfig */ |
|
| 48 | - private $config; |
|
| 49 | - |
|
| 50 | - /** @var IUserManager */ |
|
| 51 | - private $userManager; |
|
| 52 | - |
|
| 53 | - /** @var ILogger */ |
|
| 54 | - private $logger; |
|
| 55 | - |
|
| 56 | - /** @var IURLGenerator */ |
|
| 57 | - private $urlGenerator; |
|
| 58 | - |
|
| 59 | - /** @var ITimeFactory */ |
|
| 60 | - protected $timeFactory; |
|
| 61 | - |
|
| 62 | - /** @var IUserSession */ |
|
| 63 | - private $userSession; |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * Account constructor. |
|
| 67 | - * |
|
| 68 | - * @param string $appName |
|
| 69 | - * @param IRequest $request |
|
| 70 | - * @param IConfig $config |
|
| 71 | - * @param IUserManager $userManager |
|
| 72 | - * @param ILogger $logger |
|
| 73 | - * @param IURLGenerator $urlGenerator |
|
| 74 | - * @param ITimeFactory $timeFactory |
|
| 75 | - * @param IUserSession $userSession |
|
| 76 | - */ |
|
| 77 | - public function __construct(string $appName, |
|
| 78 | - IRequest $request, |
|
| 79 | - IConfig $config, |
|
| 80 | - IUserManager $userManager, |
|
| 81 | - ILogger $logger, |
|
| 82 | - IURLGenerator $urlGenerator, |
|
| 83 | - ITimeFactory $timeFactory, |
|
| 84 | - IUserSession $userSession) { |
|
| 85 | - parent::__construct($appName, $request); |
|
| 86 | - $this->appName = $appName; |
|
| 87 | - $this->config = $config; |
|
| 88 | - $this->userManager = $userManager; |
|
| 89 | - $this->logger = $logger; |
|
| 90 | - $this->urlGenerator = $urlGenerator; |
|
| 91 | - $this->timeFactory = $timeFactory; |
|
| 92 | - $this->userSession = $userSession; |
|
| 93 | - |
|
| 94 | - $this->serverRoot = \OC::$SERVERROOT; |
|
| 95 | - $this->appRoot = \OC_App::getAppPath($this->appName); |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * @NoAdminRequired |
|
| 100 | - * @NoCSRFRequired |
|
| 101 | - * |
|
| 102 | - * @return DataDisplayResponse |
|
| 103 | - */ |
|
| 104 | - public function getCss(): DataDisplayResponse { |
|
| 105 | - |
|
| 106 | - $css = ''; |
|
| 107 | - $imports = ''; |
|
| 108 | - |
|
| 109 | - foreach ($this->getUserValues() as $key => $scssFile) { |
|
| 110 | - if ($scssFile !== false) { |
|
| 111 | - $imports .= '@import "' . $scssFile . '";'; |
|
| 112 | - } |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - if ($imports !== '') { |
|
| 116 | - $scss = new Compiler(); |
|
| 117 | - $scss->setImportPaths([ |
|
| 118 | - $this->appRoot . '/css/', |
|
| 119 | - $this->serverRoot . '/core/css/' |
|
| 120 | - ]); |
|
| 121 | - |
|
| 122 | - // Continue after throw |
|
| 123 | - $scss->setIgnoreErrors(true); |
|
| 124 | - $scss->setFormatter(Crunched::class); |
|
| 125 | - |
|
| 126 | - // Import theme, variables and compile css4 variables |
|
| 127 | - try { |
|
| 128 | - $css .= $scss->compile( |
|
| 129 | - $imports . |
|
| 130 | - '@import "variables.scss";' . |
|
| 131 | - '@import "css-variables.scss";' |
|
| 132 | - ); |
|
| 133 | - } catch (ParserException $e) { |
|
| 134 | - $this->logger->error($e->getMessage(), ['app' => 'core']); |
|
| 135 | - } |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - // We don't want to override vars with url since path is different |
|
| 139 | - $css = $this->filterOutRule('/--[a-z-:]+url\([^;]+\)/mi', $css); |
|
| 140 | - |
|
| 141 | - $response = new DataDisplayResponse($css, Http::STATUS_OK, ['Content-Type' => 'text/css']); |
|
| 142 | - |
|
| 143 | - // Set cache control |
|
| 144 | - $ttl = 31536000; |
|
| 145 | - $response->addHeader('Cache-Control', 'max-age=' . $ttl . ', immutable'); |
|
| 146 | - $expires = new \DateTime(); |
|
| 147 | - $expires->setTimestamp($this->timeFactory->getTime()); |
|
| 148 | - $expires->add(new \DateInterval('PT' . $ttl . 'S')); |
|
| 149 | - $response->addHeader('Expires', $expires->format(\DateTime::RFC1123)); |
|
| 150 | - $response->addHeader('Pragma', 'cache'); |
|
| 151 | - |
|
| 152 | - return $response; |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - private function getUserValues() { |
|
| 156 | - $userTheme = $this->config->getUserValue($this->userSession->getUser()->getUID(), $this->appName, 'theme', false); |
|
| 157 | - $userFont = $this->config->getUserValue($this->userSession->getUser()->getUID(), $this->appName, 'font', false); |
|
| 158 | - |
|
| 159 | - return [$userTheme, $userFont]; |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - private function filterOutRule(string $rule, string $css) { |
|
| 163 | - return preg_replace($rule, '', $css); |
|
| 164 | - } |
|
| 41 | + /** @var string */ |
|
| 42 | + protected $appName; |
|
| 43 | + |
|
| 44 | + /** @var string */ |
|
| 45 | + protected $serverRoot; |
|
| 46 | + |
|
| 47 | + /** @var IConfig */ |
|
| 48 | + private $config; |
|
| 49 | + |
|
| 50 | + /** @var IUserManager */ |
|
| 51 | + private $userManager; |
|
| 52 | + |
|
| 53 | + /** @var ILogger */ |
|
| 54 | + private $logger; |
|
| 55 | + |
|
| 56 | + /** @var IURLGenerator */ |
|
| 57 | + private $urlGenerator; |
|
| 58 | + |
|
| 59 | + /** @var ITimeFactory */ |
|
| 60 | + protected $timeFactory; |
|
| 61 | + |
|
| 62 | + /** @var IUserSession */ |
|
| 63 | + private $userSession; |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * Account constructor. |
|
| 67 | + * |
|
| 68 | + * @param string $appName |
|
| 69 | + * @param IRequest $request |
|
| 70 | + * @param IConfig $config |
|
| 71 | + * @param IUserManager $userManager |
|
| 72 | + * @param ILogger $logger |
|
| 73 | + * @param IURLGenerator $urlGenerator |
|
| 74 | + * @param ITimeFactory $timeFactory |
|
| 75 | + * @param IUserSession $userSession |
|
| 76 | + */ |
|
| 77 | + public function __construct(string $appName, |
|
| 78 | + IRequest $request, |
|
| 79 | + IConfig $config, |
|
| 80 | + IUserManager $userManager, |
|
| 81 | + ILogger $logger, |
|
| 82 | + IURLGenerator $urlGenerator, |
|
| 83 | + ITimeFactory $timeFactory, |
|
| 84 | + IUserSession $userSession) { |
|
| 85 | + parent::__construct($appName, $request); |
|
| 86 | + $this->appName = $appName; |
|
| 87 | + $this->config = $config; |
|
| 88 | + $this->userManager = $userManager; |
|
| 89 | + $this->logger = $logger; |
|
| 90 | + $this->urlGenerator = $urlGenerator; |
|
| 91 | + $this->timeFactory = $timeFactory; |
|
| 92 | + $this->userSession = $userSession; |
|
| 93 | + |
|
| 94 | + $this->serverRoot = \OC::$SERVERROOT; |
|
| 95 | + $this->appRoot = \OC_App::getAppPath($this->appName); |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * @NoAdminRequired |
|
| 100 | + * @NoCSRFRequired |
|
| 101 | + * |
|
| 102 | + * @return DataDisplayResponse |
|
| 103 | + */ |
|
| 104 | + public function getCss(): DataDisplayResponse { |
|
| 105 | + |
|
| 106 | + $css = ''; |
|
| 107 | + $imports = ''; |
|
| 108 | + |
|
| 109 | + foreach ($this->getUserValues() as $key => $scssFile) { |
|
| 110 | + if ($scssFile !== false) { |
|
| 111 | + $imports .= '@import "' . $scssFile . '";'; |
|
| 112 | + } |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + if ($imports !== '') { |
|
| 116 | + $scss = new Compiler(); |
|
| 117 | + $scss->setImportPaths([ |
|
| 118 | + $this->appRoot . '/css/', |
|
| 119 | + $this->serverRoot . '/core/css/' |
|
| 120 | + ]); |
|
| 121 | + |
|
| 122 | + // Continue after throw |
|
| 123 | + $scss->setIgnoreErrors(true); |
|
| 124 | + $scss->setFormatter(Crunched::class); |
|
| 125 | + |
|
| 126 | + // Import theme, variables and compile css4 variables |
|
| 127 | + try { |
|
| 128 | + $css .= $scss->compile( |
|
| 129 | + $imports . |
|
| 130 | + '@import "variables.scss";' . |
|
| 131 | + '@import "css-variables.scss";' |
|
| 132 | + ); |
|
| 133 | + } catch (ParserException $e) { |
|
| 134 | + $this->logger->error($e->getMessage(), ['app' => 'core']); |
|
| 135 | + } |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + // We don't want to override vars with url since path is different |
|
| 139 | + $css = $this->filterOutRule('/--[a-z-:]+url\([^;]+\)/mi', $css); |
|
| 140 | + |
|
| 141 | + $response = new DataDisplayResponse($css, Http::STATUS_OK, ['Content-Type' => 'text/css']); |
|
| 142 | + |
|
| 143 | + // Set cache control |
|
| 144 | + $ttl = 31536000; |
|
| 145 | + $response->addHeader('Cache-Control', 'max-age=' . $ttl . ', immutable'); |
|
| 146 | + $expires = new \DateTime(); |
|
| 147 | + $expires->setTimestamp($this->timeFactory->getTime()); |
|
| 148 | + $expires->add(new \DateInterval('PT' . $ttl . 'S')); |
|
| 149 | + $response->addHeader('Expires', $expires->format(\DateTime::RFC1123)); |
|
| 150 | + $response->addHeader('Pragma', 'cache'); |
|
| 151 | + |
|
| 152 | + return $response; |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + private function getUserValues() { |
|
| 156 | + $userTheme = $this->config->getUserValue($this->userSession->getUser()->getUID(), $this->appName, 'theme', false); |
|
| 157 | + $userFont = $this->config->getUserValue($this->userSession->getUser()->getUID(), $this->appName, 'font', false); |
|
| 158 | + |
|
| 159 | + return [$userTheme, $userFont]; |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + private function filterOutRule(string $rule, string $css) { |
|
| 163 | + return preg_replace($rule, '', $css); |
|
| 164 | + } |
|
| 165 | 165 | |
| 166 | 166 | } |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -declare (strict_types = 1); |
|
| 2 | +declare(strict_types=1); |
|
| 3 | 3 | /** |
| 4 | 4 | * @copyright Copyright (c) 2018 John Molakvoæ (skjnldsv) <[email protected]> |
| 5 | 5 | * |
@@ -108,15 +108,15 @@ discard block |
||
| 108 | 108 | |
| 109 | 109 | foreach ($this->getUserValues() as $key => $scssFile) { |
| 110 | 110 | if ($scssFile !== false) { |
| 111 | - $imports .= '@import "' . $scssFile . '";'; |
|
| 111 | + $imports .= '@import "'.$scssFile.'";'; |
|
| 112 | 112 | } |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | if ($imports !== '') { |
| 116 | 116 | $scss = new Compiler(); |
| 117 | 117 | $scss->setImportPaths([ |
| 118 | - $this->appRoot . '/css/', |
|
| 119 | - $this->serverRoot . '/core/css/' |
|
| 118 | + $this->appRoot.'/css/', |
|
| 119 | + $this->serverRoot.'/core/css/' |
|
| 120 | 120 | ]); |
| 121 | 121 | |
| 122 | 122 | // Continue after throw |
@@ -126,8 +126,8 @@ discard block |
||
| 126 | 126 | // Import theme, variables and compile css4 variables |
| 127 | 127 | try { |
| 128 | 128 | $css .= $scss->compile( |
| 129 | - $imports . |
|
| 130 | - '@import "variables.scss";' . |
|
| 129 | + $imports. |
|
| 130 | + '@import "variables.scss";'. |
|
| 131 | 131 | '@import "css-variables.scss";' |
| 132 | 132 | ); |
| 133 | 133 | } catch (ParserException $e) { |
@@ -142,10 +142,10 @@ discard block |
||
| 142 | 142 | |
| 143 | 143 | // Set cache control |
| 144 | 144 | $ttl = 31536000; |
| 145 | - $response->addHeader('Cache-Control', 'max-age=' . $ttl . ', immutable'); |
|
| 145 | + $response->addHeader('Cache-Control', 'max-age='.$ttl.', immutable'); |
|
| 146 | 146 | $expires = new \DateTime(); |
| 147 | 147 | $expires->setTimestamp($this->timeFactory->getTime()); |
| 148 | - $expires->add(new \DateInterval('PT' . $ttl . 'S')); |
|
| 148 | + $expires->add(new \DateInterval('PT'.$ttl.'S')); |
|
| 149 | 149 | $response->addHeader('Expires', $expires->format(\DateTime::RFC1123)); |
| 150 | 150 | $response->addHeader('Pragma', 'cache'); |
| 151 | 151 | |
@@ -29,27 +29,27 @@ |
||
| 29 | 29 | |
| 30 | 30 | class Application extends App { |
| 31 | 31 | |
| 32 | - /** @var string */ |
|
| 33 | - protected $appName = 'accessibility'; |
|
| 34 | - |
|
| 35 | - /** @var IConfig */ |
|
| 36 | - private $config; |
|
| 37 | - |
|
| 38 | - /** @var IUserSession */ |
|
| 39 | - private $userSession; |
|
| 40 | - |
|
| 41 | - public function __construct() { |
|
| 42 | - parent::__construct($this->appName); |
|
| 43 | - $this->config = \OC::$server->getConfig(); |
|
| 44 | - $this->userSession = \OC::$server->getUserSession(); |
|
| 45 | - |
|
| 46 | - // Inject the fake css on all pages if enabled and user is logged |
|
| 47 | - $loggedUser = $this->userSession->getUser(); |
|
| 48 | - if (!is_null($loggedUser)) { |
|
| 49 | - $userValues = $this->config->getUserKeys($loggedUser->getUID(), $this->appName); |
|
| 50 | - if(count($userValues) > 0) { |
|
| 51 | - \OCP\Util::addStyle($this->appName, 'user-' . md5(implode('-', $userValues)), true); |
|
| 52 | - } |
|
| 53 | - } |
|
| 54 | - } |
|
| 32 | + /** @var string */ |
|
| 33 | + protected $appName = 'accessibility'; |
|
| 34 | + |
|
| 35 | + /** @var IConfig */ |
|
| 36 | + private $config; |
|
| 37 | + |
|
| 38 | + /** @var IUserSession */ |
|
| 39 | + private $userSession; |
|
| 40 | + |
|
| 41 | + public function __construct() { |
|
| 42 | + parent::__construct($this->appName); |
|
| 43 | + $this->config = \OC::$server->getConfig(); |
|
| 44 | + $this->userSession = \OC::$server->getUserSession(); |
|
| 45 | + |
|
| 46 | + // Inject the fake css on all pages if enabled and user is logged |
|
| 47 | + $loggedUser = $this->userSession->getUser(); |
|
| 48 | + if (!is_null($loggedUser)) { |
|
| 49 | + $userValues = $this->config->getUserKeys($loggedUser->getUID(), $this->appName); |
|
| 50 | + if(count($userValues) > 0) { |
|
| 51 | + \OCP\Util::addStyle($this->appName, 'user-' . md5(implode('-', $userValues)), true); |
|
| 52 | + } |
|
| 53 | + } |
|
| 54 | + } |
|
| 55 | 55 | } |
@@ -47,8 +47,8 @@ |
||
| 47 | 47 | $loggedUser = $this->userSession->getUser(); |
| 48 | 48 | if (!is_null($loggedUser)) { |
| 49 | 49 | $userValues = $this->config->getUserKeys($loggedUser->getUID(), $this->appName); |
| 50 | - if(count($userValues) > 0) { |
|
| 51 | - \OCP\Util::addStyle($this->appName, 'user-' . md5(implode('-', $userValues)), true); |
|
| 50 | + if (count($userValues) > 0) { |
|
| 51 | + \OCP\Util::addStyle($this->appName, 'user-'.md5(implode('-', $userValues)), true); |
|
| 52 | 52 | } |
| 53 | 53 | } |
| 54 | 54 | } |