123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 |
- <?php
- defined('GNUSOCIAL') || die();
- class overwritethemebackgroundcssAction extends Action
- {
- protected $needLogin = false;
- protected $canPost = false;
-
- private $_theme_background_url = false;
- private $_background_colour = false;
- private $_background_colour_important = false;
-
- protected function prepare(array $args = []): bool
- {
- parent::prepare($args);
- if (GNUsocial::isHTTPS()) {
- $background_url = common_config('overwritethemebackground', 'sslbackground-image');
- if (empty($background_url)) {
-
- $http_url = common_config('overwritethemebackground', 'background-image');
- if (!empty($http_url)) {
- try {
- $f = File::getByUrl($http_url);
- if (!empty($f->filename)) {
-
- $background_url = File::url($f->filename);
- }
- } catch (NoResultException $e) {
-
- }
- }
- }
- } else {
- $background_url = common_config('overwritethemebackground', 'background-image');
- }
- $this->_background_colour = common_config('overwritethemebackground', 'background-color');
- if (empty($background_url)) {
- if (!empty($this->_background_colour)) {
- $this->_background_colour_important = true;
- return true;
- }
-
- } else {
- $this->_theme_background_url = $background_url;
- }
- return true;
- }
-
- public function isReadOnly($args): bool
- {
- return true;
- }
-
- public function handle(): void
- {
- $background_position_options = [
- 'initial',
- 'left top',
- 'left center',
- 'left bottom',
- 'right top',
- 'right center',
- 'right bottom',
- 'center top',
- 'center center',
- 'center bottom'
- ];
- header("Content-type: text/css", true);
- $background_color = $this->_background_colour;
- $background_image = $this->_theme_background_url;
- $background_repeat = ['repeat', 'repeat-x', 'repeat-y', 'no-repeat'][common_config('overwritethemebackground', 'background-repeat')];
- $background_position = $background_position_options[common_config('overwritethemebackground', 'background-position')];
- $background_attachment = ['scroll', 'fixed'][common_config('overwritethemebackground', 'background-attachment')];
- $css = 'body {';
- if ($background_color) {
- if (!$this->_background_colour_important) {
- $css .= 'background-color: ' . $background_color . ';';
- } else {
- $css .= 'background: ' . $background_color . ' !important;';
- }
- }
- if ($background_image) {
- $css .= 'background-image: url(' . $background_image . ');';
- }
- if ($background_repeat) {
- $css .= 'background-repeat: ' . $background_repeat . ';';
- }
- if ($background_position) {
- $css .= 'background-position: ' . $background_position . ';';
- }
- if ($background_attachment) {
- $css .= 'background-attachment: ' . $background_attachment . ';';
- }
- $css .= '}';
- echo $css;
- }
- }
|