summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/private/TemplateLayout.php13
-rw-r--r--lib/private/legacy/OC_Template.php5
-rw-r--r--lib/public/AppFramework/Http/TemplateResponse.php37
3 files changed, 44 insertions, 11 deletions
diff --git a/lib/private/TemplateLayout.php b/lib/private/TemplateLayout.php
index 1fbf0acb99c..69eb26ab8b2 100644
--- a/lib/private/TemplateLayout.php
+++ b/lib/private/TemplateLayout.php
@@ -48,6 +48,7 @@ use OC\AppFramework\Http\Request;
use OC\Template\JSCombiner;
use OC\Template\JSConfigHelper;
use OC\Template\SCSSCacher;
+use OCP\AppFramework\Http\TemplateResponse;
use OCP\Defaults;
use OCP\IInitialStateService;
use OCP\Support\Subscription\IRegistry;
@@ -74,7 +75,7 @@ class TemplateLayout extends \OC_Template {
}
// Decide which page we show
- if ($renderAs === 'user') {
+ if ($renderAs === TemplateResponse::RENDER_AS_USER) {
parent::__construct('core', 'layout.user');
if (in_array(\OC_App::getCurrentApp(), ['settings','admin', 'help']) !== false) {
$this->assign('bodyid', 'body-settings');
@@ -123,12 +124,12 @@ class TemplateLayout extends \OC_Template {
} catch (\OCP\AutoloadNotAllowedException $e) {
$this->assign('themingInvertMenu', false);
}
- } elseif ($renderAs === 'error') {
+ } elseif ($renderAs === TemplateResponse::RENDER_AS_ERROR) {
parent::__construct('core', 'layout.guest', '', false);
$this->assign('bodyid', 'body-login');
$this->assign('user_displayname', '');
$this->assign('user_uid', '');
- } elseif ($renderAs === 'guest') {
+ } elseif ($renderAs === TemplateResponse::RENDER_AS_GUEST) {
parent::__construct('core', 'layout.guest');
\OC_Util::addStyle('guest');
$this->assign('bodyid', 'body-login');
@@ -136,7 +137,7 @@ class TemplateLayout extends \OC_Template {
$userDisplayName = \OC_User::getDisplayName();
$this->assign('user_displayname', $userDisplayName);
$this->assign('user_uid', \OC_User::getUser());
- } elseif ($renderAs === 'public') {
+ } elseif ($renderAs === TemplateResponse::RENDER_AS_PUBLIC) {
parent::__construct('core', 'layout.public');
$this->assign('appid', $appId);
$this->assign('bodyid', 'body-public');
@@ -172,7 +173,7 @@ class TemplateLayout extends \OC_Template {
// Add the js files
$jsFiles = self::findJavascriptFiles(\OC_Util::$scripts);
$this->assign('jsfiles', []);
- if ($this->config->getSystemValue('installed', false) && $renderAs != 'error') {
+ if ($this->config->getSystemValue('installed', false) && $renderAs != TemplateResponse::RENDER_AS_ERROR) {
if (\OC::$server->getContentSecurityPolicyNonceManager()->browserSupportsCspV3()) {
$jsConfigHelper = new JSConfigHelper(
\OC::$server->getL10N('lib'),
@@ -210,7 +211,7 @@ class TemplateLayout extends \OC_Template {
&& !\OCP\Util::needUpgrade()
&& $pathInfo !== ''
&& !preg_match('/^\/login/', $pathInfo)
- && $renderAs !== 'error'
+ && $renderAs !== TemplateResponse::RENDER_AS_ERROR
) {
$cssFiles = self::findStylesheetFiles(\OC_Util::$styles);
} else {
diff --git a/lib/private/legacy/OC_Template.php b/lib/private/legacy/OC_Template.php
index 856d5491090..32d185d25fd 100644
--- a/lib/private/legacy/OC_Template.php
+++ b/lib/private/legacy/OC_Template.php
@@ -39,6 +39,7 @@
*/
use OC\TemplateLayout;
+use OCP\AppFramework\Http\TemplateResponse;
require_once __DIR__.'/template/functions.php';
@@ -72,7 +73,7 @@ class OC_Template extends \OC\Template\Base {
* "admin".
* @param bool $registerCall = true
*/
- public function __construct($app, $name, $renderAs = "", $registerCall = true) {
+ public function __construct($app, $name, $renderAs = TemplateResponse::RENDER_AS_BLANK, $registerCall = true) {
// Read the selected theme from the config file
self::initTemplateEngine($renderAs);
@@ -104,7 +105,7 @@ class OC_Template extends \OC\Template\Base {
//apps that started before the template initialization can load their own scripts/styles
//so to make sure this scripts/styles here are loaded first we use OC_Util::addScript() with $prepend=true
//meaning the last script/style in this list will be loaded first
- if (\OC::$server->getSystemConfig()->getValue('installed', false) && $renderAs !== 'error' && !\OCP\Util::needUpgrade()) {
+ if (\OC::$server->getSystemConfig()->getValue('installed', false) && $renderAs !== TemplateResponse::RENDER_AS_ERROR && !\OCP\Util::needUpgrade()) {
if (\OC::$server->getConfig()->getAppValue('core', 'backgroundjobs_mode', 'ajax') == 'ajax') {
OC_Util::addScript('backgroundjobs', null, true);
}
diff --git a/lib/public/AppFramework/Http/TemplateResponse.php b/lib/public/AppFramework/Http/TemplateResponse.php
index 48e6c43411f..9622d9696dc 100644
--- a/lib/public/AppFramework/Http/TemplateResponse.php
+++ b/lib/public/AppFramework/Http/TemplateResponse.php
@@ -39,6 +39,27 @@ namespace OCP\AppFramework\Http;
*/
class TemplateResponse extends Response {
/**
+ * @since 20.0.0
+ */
+ public const RENDER_AS_GUEST = 'guest';
+ /**
+ * @since 20.0.0
+ */
+ public const RENDER_AS_BLANK = '';
+ /**
+ * @since 20.0.0
+ */
+ public const RENDER_AS_USER = 'user';
+ /**
+ * @since 20.0.0
+ */
+ public const RENDER_AS_ERROR = 'error';
+ /**
+ * @since 20.0.0
+ */
+ public const RENDER_AS_PUBLIC = 'public';
+
+ /**
* @deprecated 20.0.0 use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent
*/
public const EVENT_LOAD_ADDITIONAL_SCRIPTS = self::class . '::loadAdditionalScripts';
@@ -81,7 +102,7 @@ class TemplateResponse extends Response {
* @since 6.0.0 - parameters $params and $renderAs were added in 7.0.0
*/
public function __construct($appName, $templateName, array $params=[],
- $renderAs='user') {
+ $renderAs = self::RENDER_AS_USER) {
parent::__construct();
$this->templateName = $templateName;
@@ -160,8 +181,18 @@ class TemplateResponse extends Response {
* @since 6.0.0
*/
public function render() {
- // \OCP\Template needs an empty string instead of 'blank' for an unwrapped response
- $renderAs = $this->renderAs === 'blank' ? '' : $this->renderAs;
+ $renderAs = self::RENDER_AS_USER;
+ if ($this->renderAs === 'blank') {
+ // Legacy fallback as \OCP\Template needs an empty string instead of 'blank' for an unwrapped response
+ $renderAs = self::RENDER_AS_BLANK;
+ } elseif (in_array($this->renderAs, [
+ self::RENDER_AS_GUEST,
+ self::RENDER_AS_BLANK,
+ self::RENDER_AS_ERROR,
+ self::RENDER_AS_PUBLIC,
+ self::RENDER_AS_USER], true)) {
+ $renderAs = $this->renderAs;
+ }
\OCP\Util::addHeader('meta', ['name' => 'robots', 'content' => 'noindex, nofollow']);
$template = new \OCP\Template($this->appName, $this->templateName, $renderAs);