summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2017-04-07 15:42:43 -0500
committerMorris Jobke <hey@morrisjobke.de>2017-04-09 21:43:01 -0500
commit5b4adf66e51e21b3ecbd683397a362b60f792a50 (patch)
tree8bdc129ac9fd6575ee41be438ff667e49f7110a2 /lib
parentca9d25169dcdd2923a356e2a797d8704506a3787 (diff)
downloadnextcloud-server-5b4adf66e51e21b3ecbd683397a362b60f792a50.tar.gz
nextcloud-server-5b4adf66e51e21b3ecbd683397a362b60f792a50.zip
Move OC_Defaults to OCP\Defaults
* currently there are two ways to access default values: OCP\Defaults or OC_Defaults (which is extended by OCA\Theming\ThemingDefaults) * our code used a mixture of both of them, which made it hard to work on theme values * this extended the public interface with the missing methods and uses them everywhere to only rely on the public interface Signed-off-by: Morris Jobke <hey@morrisjobke.de>
Diffstat (limited to 'lib')
-rw-r--r--lib/base.php2
-rw-r--r--lib/private/Mail/EMailTemplate.php10
-rw-r--r--lib/private/Mail/IEMailTemplate.php8
-rw-r--r--lib/private/Mail/Mailer.php7
-rw-r--r--lib/private/Server.php10
-rw-r--r--lib/private/Setup.php12
-rw-r--r--lib/private/Share/MailNotifications.php1
-rw-r--r--lib/private/Template/Base.php6
-rw-r--r--lib/private/Template/JSConfigHelper.php7
-rw-r--r--lib/private/TemplateLayout.php3
-rw-r--r--lib/private/legacy/defaults.php18
-rw-r--r--lib/private/legacy/template.php3
-rw-r--r--lib/private/legacy/util.php2
-rw-r--r--lib/public/Defaults.php45
14 files changed, 104 insertions, 30 deletions
diff --git a/lib/base.php b/lib/base.php
index a6601a2dd67..feb54ec0331 100644
--- a/lib/base.php
+++ b/lib/base.php
@@ -912,7 +912,7 @@ class OC {
if (!$systemConfig->getValue('installed', false)) {
\OC::$server->getSession()->clear();
$setupHelper = new OC\Setup(\OC::$server->getSystemConfig(), \OC::$server->getIniWrapper(),
- \OC::$server->getL10N('lib'), \OC::$server->getThemingDefaults(), \OC::$server->getLogger(),
+ \OC::$server->getL10N('lib'), \OC::$server->query(\OCP\Defaults::class), \OC::$server->getLogger(),
\OC::$server->getSecureRandom());
$controller = new OC\Core\Controller\SetupController($setupHelper);
$controller->run($_POST);
diff --git a/lib/private/Mail/EMailTemplate.php b/lib/private/Mail/EMailTemplate.php
index 7d3ca51c50e..c84af6331dc 100644
--- a/lib/private/Mail/EMailTemplate.php
+++ b/lib/private/Mail/EMailTemplate.php
@@ -25,7 +25,7 @@
namespace OC\Mail;
-use OCA\Theming\ThemingDefaults;
+use OCP\Defaults;
use OCP\IL10N;
use OCP\IURLGenerator;
@@ -38,7 +38,7 @@ use OCP\IURLGenerator;
* @package OC\Mail
*/
class EMailTemplate implements IEMailTemplate {
- /** @var ThemingDefaults */
+ /** @var Defaults */
protected $themingDefaults;
/** @var IURLGenerator */
protected $urlGenerator;
@@ -264,11 +264,11 @@ EOF;
EOF;
/**
- * @param ThemingDefaults $themingDefaults
+ * @param Defaults $themingDefaults
* @param IURLGenerator $urlGenerator
* @param IL10N $l10n
*/
- public function __construct(ThemingDefaults $themingDefaults,
+ public function __construct(Defaults $themingDefaults,
IURLGenerator $urlGenerator,
IL10N $l10n) {
$this->themingDefaults = $themingDefaults;
@@ -286,7 +286,7 @@ EOF;
}
$this->headerAdded = true;
- $logoUrl = $this->urlGenerator->getAbsoluteURL($this->themingDefaults->getLogo()) . '?v='. $this->themingDefaults->getCacheBusterCounter();
+ $logoUrl = $this->urlGenerator->getAbsoluteURL($this->themingDefaults->getLogo());
$this->htmlBody .= vsprintf($this->header, [$this->themingDefaults->getColorPrimary(), $logoUrl]);
}
diff --git a/lib/private/Mail/IEMailTemplate.php b/lib/private/Mail/IEMailTemplate.php
index 0d660a35516..baa29735988 100644
--- a/lib/private/Mail/IEMailTemplate.php
+++ b/lib/private/Mail/IEMailTemplate.php
@@ -23,6 +23,8 @@
namespace OC\Mail;
+use OCP\Defaults;
+
/**
* Interface IEMailTemplate
*
@@ -32,7 +34,7 @@ namespace OC\Mail;
*
* <?php
*
- * $emailTemplate = new EMailTemplate($this->defaults);
+ * $emailTemplate = new EMailTemplate($this->defaults, $this->urlGenerator, $this->l10n);
*
* $emailTemplate->addHeader();
* $emailTemplate->addHeading('Welcome aboard');
@@ -50,11 +52,11 @@ namespace OC\Mail;
*/
interface IEMailTemplate {
/**
- * @param \OCA\Theming\ThemingDefaults $themingDefaults
+ * @param Defaults $themingDefaults
* @param \OCP\IURLGenerator $urlGenerator
* @param \OCP\IL10N $l10n
*/
- public function __construct(\OCA\Theming\ThemingDefaults $themingDefaults,
+ public function __construct(Defaults $themingDefaults,
\OCP\IURLGenerator $urlGenerator,
\OCP\IL10N $l10n);
diff --git a/lib/private/Mail/Mailer.php b/lib/private/Mail/Mailer.php
index e704e8e3490..8a6b6fce899 100644
--- a/lib/private/Mail/Mailer.php
+++ b/lib/private/Mail/Mailer.php
@@ -22,6 +22,7 @@
namespace OC\Mail;
+use OCP\Defaults;
use OCP\IConfig;
use OCP\Mail\IMailer;
use OCP\ILogger;
@@ -51,17 +52,17 @@ class Mailer implements IMailer {
private $config;
/** @var ILogger */
private $logger;
- /** @var \OC_Defaults */
+ /** @var Defaults */
private $defaults;
/**
* @param IConfig $config
* @param ILogger $logger
- * @param \OC_Defaults $defaults
+ * @param Defaults $defaults
*/
function __construct(IConfig $config,
ILogger $logger,
- \OC_Defaults $defaults) {
+ Defaults $defaults) {
$this->config = $config;
$this->logger = $logger;
$this->defaults = $defaults;
diff --git a/lib/private/Server.php b/lib/private/Server.php
index 0d05bfe0dc8..9b2380ac7ac 100644
--- a/lib/private/Server.php
+++ b/lib/private/Server.php
@@ -95,6 +95,7 @@ use OC\Session\CryptoWrapper;
use OC\Tagging\TagMapper;
use OCA\Theming\ThemingDefaults;
use OCP\App\IAppManager;
+use OCP\Defaults;
use OCP\Federation\ICloudIdManager;
use OCP\Authentication\LoginCredentials\IStore;
use OCP\ICacheFactory;
@@ -726,7 +727,7 @@ class Server extends ServerContainer implements IServerContainer {
return new Mailer(
$c->getConfig(),
$c->getLogger(),
- $c->getThemingDefaults()
+ $c->query(Defaults::class)
);
});
$this->registerAlias('Mailer', \OCP\Mail\IMailer::class);
@@ -955,6 +956,13 @@ class Server extends ServerContainer implements IServerContainer {
$this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class);
$this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class);
+ $this->registerService(Defaults::class, function (Server $c) {
+ return new Defaults(
+ $c->getThemingDefaults()
+ );
+ });
+ $this->registerAlias('Defaults', \OCP\Defaults::class);
+
$this->registerService(\OCP\ISession::class, function(SimpleContainer $c) {
return $c->query(\OCP\IUserSession::class)->getSession();
});
diff --git a/lib/private/Setup.php b/lib/private/Setup.php
index 7a2957b5fb3..e2806efad48 100644
--- a/lib/private/Setup.php
+++ b/lib/private/Setup.php
@@ -41,7 +41,7 @@ namespace OC;
use bantu\IniGetWrapper\IniGetWrapper;
use Exception;
-use OCP\IConfig;
+use OCP\Defaults;
use OCP\IL10N;
use OCP\ILogger;
use OCP\Security\ISecureRandom;
@@ -53,7 +53,7 @@ class Setup {
protected $iniWrapper;
/** @var IL10N */
protected $l10n;
- /** @var \OC_Defaults */
+ /** @var Defaults */
protected $defaults;
/** @var ILogger */
protected $logger;
@@ -63,12 +63,14 @@ class Setup {
/**
* @param SystemConfig $config
* @param IniGetWrapper $iniWrapper
- * @param \OC_Defaults $defaults
+ * @param Defaults $defaults
+ * @param ILogger $logger
+ * @param ISecureRandom $random
*/
function __construct(SystemConfig $config,
IniGetWrapper $iniWrapper,
IL10N $l10n,
- \OC_Defaults $defaults,
+ Defaults $defaults,
ILogger $logger,
ISecureRandom $random
) {
@@ -422,7 +424,7 @@ class Setup {
}
$setupHelper = new \OC\Setup($config, \OC::$server->getIniWrapper(),
- \OC::$server->getL10N('lib'), \OC::$server->getThemingDefaults(), \OC::$server->getLogger(),
+ \OC::$server->getL10N('lib'), \OC::$server->query(Defaults::class), \OC::$server->getLogger(),
\OC::$server->getSecureRandom());
$htaccessContent = file_get_contents($setupHelper->pathToHtaccess());
diff --git a/lib/private/Share/MailNotifications.php b/lib/private/Share/MailNotifications.php
index 1bbd365699c..1ea053fc499 100644
--- a/lib/private/Share/MailNotifications.php
+++ b/lib/private/Share/MailNotifications.php
@@ -30,7 +30,6 @@
namespace OC\Share;
-use DateTime;
use OCP\IL10N;
use OCP\IURLGenerator;
use OCP\IUser;
diff --git a/lib/private/Template/Base.php b/lib/private/Template/Base.php
index 6af679f0a66..18cf6324089 100644
--- a/lib/private/Template/Base.php
+++ b/lib/private/Template/Base.php
@@ -28,6 +28,8 @@
namespace OC\Template;
+use OCP\Defaults;
+
class Base {
private $template; // The template
private $vars; // Vars
@@ -35,14 +37,14 @@ class Base {
/** @var \OCP\IL10N */
private $l10n;
- /** @var \OC_Defaults */
+ /** @var Defaults */
private $theme;
/**
* @param string $template
* @param string $requestToken
* @param \OCP\IL10N $l10n
- * @param \OC_Defaults $theme
+ * @param Defaults $theme
*/
public function __construct($template, $requestToken, $l10n, $theme ) {
$this->vars = array();
diff --git a/lib/private/Template/JSConfigHelper.php b/lib/private/Template/JSConfigHelper.php
index 4fc21680211..9a11e84f8d9 100644
--- a/lib/private/Template/JSConfigHelper.php
+++ b/lib/private/Template/JSConfigHelper.php
@@ -24,6 +24,7 @@ namespace OC\Template;
use bantu\IniGetWrapper\IniGetWrapper;
use OCP\App\IAppManager;
+use OCP\Defaults;
use OCP\IConfig;
use OCP\IGroupManager;
use OCP\IL10N;
@@ -36,7 +37,7 @@ class JSConfigHelper {
/** @var IL10N */
private $l;
- /** @var \OC_Defaults */
+ /** @var Defaults */
private $defaults;
/** @var IAppManager */
@@ -62,7 +63,7 @@ class JSConfigHelper {
/**
* @param IL10N $l
- * @param \OC_Defaults $defaults
+ * @param Defaults $defaults
* @param IAppManager $appManager
* @param ISession $session
* @param IUser|null $currentUser
@@ -72,7 +73,7 @@ class JSConfigHelper {
* @param IURLGenerator $urlGenerator
*/
public function __construct(IL10N $l,
- \OC_Defaults $defaults,
+ Defaults $defaults,
IAppManager $appManager,
ISession $session,
$currentUser,
diff --git a/lib/private/TemplateLayout.php b/lib/private/TemplateLayout.php
index 6dc925f8f8c..7a5984a4924 100644
--- a/lib/private/TemplateLayout.php
+++ b/lib/private/TemplateLayout.php
@@ -38,6 +38,7 @@ namespace OC;
use OC\Template\JSCombiner;
use OC\Template\JSConfigHelper;
use OC\Template\SCSSCacher;
+use OCP\Defaults;
class TemplateLayout extends \OC_Template {
@@ -135,7 +136,7 @@ class TemplateLayout extends \OC_Template {
if (\OC::$server->getContentSecurityPolicyNonceManager()->browserSupportsCspV3()) {
$jsConfigHelper = new JSConfigHelper(
\OC::$server->getL10N('core'),
- \OC::$server->getThemingDefaults(),
+ \OC::$server->query(Defaults::class),
\OC::$server->getAppManager(),
\OC::$server->getSession(),
\OC::$server->getUserSession()->getUser(),
diff --git a/lib/private/legacy/defaults.php b/lib/private/legacy/defaults.php
index 9fd9b621a14..10dd935d26b 100644
--- a/lib/private/legacy/defaults.php
+++ b/lib/private/legacy/defaults.php
@@ -47,6 +47,8 @@ class OC_Defaults {
private $defaultSlogan;
private $defaultLogoClaim;
private $defaultColorPrimary;
+ private $defaultLogoUrl;
+ private $defaultCacheBuster;
function __construct() {
$this->l = \OC::$server->getL10N('lib');
@@ -64,6 +66,8 @@ class OC_Defaults {
$this->defaultSlogan = $this->l->t('a safe home for all your data');
$this->defaultLogoClaim = '';
$this->defaultColorPrimary = '#0082c9';
+ $this->defaultLogoUrl = \OC::$server->getURLGenerator()->imagePath('core','logo.svg');
+ $this->defaultLogoUrl .= '?v=' . hash('sha1', implode('.', \OCP\Util::getVersion()));
$themePath = OC::$SERVERROOT . '/themes/' . OC_Util::getTheme() . '/defaults.php';
if (file_exists($themePath)) {
@@ -263,6 +267,7 @@ class OC_Defaults {
/**
* @param string $key
+ * @return string URL to doc with key
*/
public function buildDocLinkToKey($key) {
if ($this->themeExist('buildDocLinkToKey')) {
@@ -289,4 +294,17 @@ class OC_Defaults {
public function shouldReplaceIcons() {
return false;
}
+
+ /**
+ * Themed logo url
+ *
+ * @return string
+ */
+ public function getLogo() {
+ if ($this->themeExist('getLogo')) {
+ return $this->theme->getLogo();
+ }
+
+ return $this->defaultLogoUrl;
+ }
}
diff --git a/lib/private/legacy/template.php b/lib/private/legacy/template.php
index 969f5174278..19b5e418110 100644
--- a/lib/private/legacy/template.php
+++ b/lib/private/legacy/template.php
@@ -79,7 +79,8 @@ class OC_Template extends \OC\Template\Base {
$parts = explode('/', $app); // fix translation when app is something like core/lostpassword
$l10n = \OC::$server->getL10N($parts[0]);
- $themeDefaults = \OC::$server->getThemingDefaults();
+ /** @var \OCP\Defaults $themeDefaults */
+ $themeDefaults = \OC::$server->query(\OCP\Defaults::class);
list($path, $template) = $this->findTemplate($theme, $app, $name);
diff --git a/lib/private/legacy/util.php b/lib/private/legacy/util.php
index 0672fefbe0c..f067a12cb76 100644
--- a/lib/private/legacy/util.php
+++ b/lib/private/legacy/util.php
@@ -651,7 +651,7 @@ class OC_Util {
$webServerRestart = false;
$setup = new \OC\Setup($config, \OC::$server->getIniWrapper(), \OC::$server->getL10N('lib'),
- \OC::$server->getThemingDefaults(), \OC::$server->getLogger(), \OC::$server->getSecureRandom());
+ \OC::$server->query(\OCP\Defaults::class), \OC::$server->getLogger(), \OC::$server->getSecureRandom());
$urlGenerator = \OC::$server->getURLGenerator();
diff --git a/lib/public/Defaults.php b/lib/public/Defaults.php
index ae873831b8b..591da18c7ee 100644
--- a/lib/public/Defaults.php
+++ b/lib/public/Defaults.php
@@ -42,7 +42,6 @@ class Defaults {
/**
* \OC_Defaults instance to retrieve the defaults
- * @return string
* @since 6.0.0
*/
private $defaults;
@@ -52,8 +51,11 @@ class Defaults {
* actual defaults
* @since 6.0.0
*/
- function __construct() {
- $this->defaults = \OC::$server->getThemingDefaults();
+ function __construct(\OC_Defaults $defaults = null) {
+ if ($defaults === null) {
+ $defaults = \OC::$server->getThemingDefaults();
+ }
+ $this->defaults = $defaults;
}
/**
@@ -172,4 +174,41 @@ class Defaults {
public function getiTunesAppId() {
return $this->defaults->getiTunesAppId();
}
+
+ /**
+ * Themed logo url
+ *
+ * @return string
+ * @since 12.0.0
+ */
+ public function getLogo() {
+ return $this->defaults->getLogo();
+ }
+
+ /**
+ * Returns primary color
+ * @return string
+ * @since 12.0.0
+ */
+ public function getColorPrimary() {
+ return $this->defaults->getColorPrimary();
+ }
+
+ /**
+ * @param string $key
+ * @return string URL to doc with key
+ * @since 12.0.0
+ */
+ public function buildDocLinkToKey($key) {
+ return $this->defaults->buildDocLinkToKey($key);
+ }
+
+ /**
+ * Returns the title
+ * @return string title
+ * @since 12.0.0
+ */
+ public function getTitle() {
+ return $this->defaults->getTitle();
+ }
}