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;
}
// 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');
} 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');
$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');
// 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'),
&& !\OCP\Util::needUpgrade()
&& $pathInfo !== ''
&& !preg_match('/^\/login/', $pathInfo)
- && $renderAs !== 'error'
+ && $renderAs !== TemplateResponse::RENDER_AS_ERROR
) {
$cssFiles = self::findStylesheetFiles(\OC_Util::$styles);
} else {
*/
use OC\TemplateLayout;
+use OCP\AppFramework\Http\TemplateResponse;
require_once __DIR__.'/template/functions.php';
* "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);
//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);
}
* @since 6.0.0
*/
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
*/
* @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;
* @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);