[Howto] Individual themes per domain

@RobiRob,

Its not tricky.

Add all Domains to $CONFIG[ā€˜trusted_domainsā€™][]. You can do this with config/config.php or in the first lines in config/domains.config.php.

'trusted_domains' =>
    array (
        0 => 'cloud.domain1.com',
        1 => 'cloud.domain2.com',
        2 => 'cloud.domain3.com',
        3 => 'cloud.domain4.com',
),

In config/domains.config.php

# if not set in config/config.php
$CONFIG['trusted_domains'] = array (
    0 => 'cloud.domain1.com',
    1 => 'cloud.domain2.com',
    2 => 'cloud.domain3.com',
    3 => 'cloud.domain4.com',
);

if (isset($_SERVER['HTTP_HOST'])) {
    switch ($_SERVER['HTTP_HOST']) {
        # Server called with cloud.domain1.com
        case 'cloud.domain1.com':
            # sure, we can do more stuff like checking an existing
            # directory in the themes directory

            # use this theme (must exists in themes/ )
            $CONFIG['theme']='cloud.domain1.com';
            # configure local-part of email address
            $CONFIG['mail_from_address'] = 'no-reply';
            # configure domain of email address
            $CONFIG['mail_domain'] = 'domain1.com';
            break;
        case 'cloud.domain2.com':
            $CONFIG['theme']='cloud.domain2.com';
            $CONFIG['mail_from_address'] = 'no-reply';
            $CONFIG['mail_domain'] = 'domain2.com';
            break;
        # and so on for other domains
    }
}

The directory ā€œthemes/domain1.comā€ contains the following files:
themes/domain1.com/defaults.php
themes/domain1.com/core/apps/img/favicon-touch.png
themes/domain1.com/core/css/server.css
themes/domain1.com/core/img/favicon.ico
themes/domain1.com/core/img/logo.svg
themes/domain1.com/core/img/domain1.com-norm.svg
themes/domain1.com/core/img/favicon-touch.png
themes/domain1.com/core/img/domain1.com-logo.svg
themes/domain1.com/core/img/favicon-64.png
themes/domain1.com/core/img/favicon-16.png
themes/domain1.com/core/img/domain1.com-logo-wide.svg
themes/domain1.com/core/img/favicon-128.png
themes/domain1.com/core/img/favicon-256.png
themes/domain1.com/core/img/favicon-32.png
themes/domain1.com/core/img/favicon.png

themes/domain1.com/defaults.php:

<?php
class OC_Theme {
    # for a list of functions see /lib/private/defaults.php
   function __construct() {
   }
   public function getTitle() {
       return "My Own Nextcloud";
   }
   public function getName() {
       return "Best-Cloud";
   }
   public function getHTMLName() {
       return "Best-Cloud";
   }
   public function getEntity() {
       // Footer-Name
       return "My Company";
   }
   public function getSlogan() {
       return "We do everything for you :-)";
   }
   public function getLongFooter() {
       return $this->getShortFooter();
   }
   public function getShortFooter() {
       return '<a href="https://domain1.com" target="_blank" rel="noreferrer">' . $this->getEntity() . '</a> - ' . $this->getSlogan();
   }
   public function getLogoClaim() {
       return '';
   }

}

6 Likes