@@ -38,138 +38,138 @@ |
||
38 | 38 | * @since 6.0.0 |
39 | 39 | */ |
40 | 40 | class TemplateResponse extends Response { |
41 | - /** |
|
42 | - * @deprecated 20.0.0 use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent |
|
43 | - */ |
|
44 | - public const EVENT_LOAD_ADDITIONAL_SCRIPTS = self::class . '::loadAdditionalScripts'; |
|
45 | - /** |
|
46 | - * @deprecated 20.0.0 use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent |
|
47 | - */ |
|
48 | - public const EVENT_LOAD_ADDITIONAL_SCRIPTS_LOGGEDIN = self::class . '::loadAdditionalScriptsLoggedIn'; |
|
49 | - |
|
50 | - /** |
|
51 | - * name of the template |
|
52 | - * @var string |
|
53 | - */ |
|
54 | - protected $templateName; |
|
55 | - |
|
56 | - /** |
|
57 | - * parameters |
|
58 | - * @var array |
|
59 | - */ |
|
60 | - protected $params; |
|
61 | - |
|
62 | - /** |
|
63 | - * rendering type (admin, user, blank) |
|
64 | - * @var string |
|
65 | - */ |
|
66 | - protected $renderAs; |
|
67 | - |
|
68 | - /** |
|
69 | - * app name |
|
70 | - * @var string |
|
71 | - */ |
|
72 | - protected $appName; |
|
73 | - |
|
74 | - /** |
|
75 | - * constructor of TemplateResponse |
|
76 | - * @param string $appName the name of the app to load the template from |
|
77 | - * @param string $templateName the name of the template |
|
78 | - * @param array $params an array of parameters which should be passed to the |
|
79 | - * template |
|
80 | - * @param string $renderAs how the page should be rendered, defaults to user |
|
81 | - * @since 6.0.0 - parameters $params and $renderAs were added in 7.0.0 |
|
82 | - */ |
|
83 | - public function __construct($appName, $templateName, array $params=[], |
|
84 | - $renderAs='user') { |
|
85 | - parent::__construct(); |
|
86 | - |
|
87 | - $this->templateName = $templateName; |
|
88 | - $this->appName = $appName; |
|
89 | - $this->params = $params; |
|
90 | - $this->renderAs = $renderAs; |
|
91 | - |
|
92 | - $this->setContentSecurityPolicy(new ContentSecurityPolicy()); |
|
93 | - $this->setFeaturePolicy(new FeaturePolicy()); |
|
94 | - } |
|
95 | - |
|
96 | - |
|
97 | - /** |
|
98 | - * Sets template parameters |
|
99 | - * @param array $params an array with key => value structure which sets template |
|
100 | - * variables |
|
101 | - * @return TemplateResponse Reference to this object |
|
102 | - * @since 6.0.0 - return value was added in 7.0.0 |
|
103 | - */ |
|
104 | - public function setParams(array $params) { |
|
105 | - $this->params = $params; |
|
106 | - |
|
107 | - return $this; |
|
108 | - } |
|
109 | - |
|
110 | - |
|
111 | - /** |
|
112 | - * Used for accessing the set parameters |
|
113 | - * @return array the params |
|
114 | - * @since 6.0.0 |
|
115 | - */ |
|
116 | - public function getParams() { |
|
117 | - return $this->params; |
|
118 | - } |
|
119 | - |
|
120 | - |
|
121 | - /** |
|
122 | - * Used for accessing the name of the set template |
|
123 | - * @return string the name of the used template |
|
124 | - * @since 6.0.0 |
|
125 | - */ |
|
126 | - public function getTemplateName() { |
|
127 | - return $this->templateName; |
|
128 | - } |
|
129 | - |
|
130 | - |
|
131 | - /** |
|
132 | - * Sets the template page |
|
133 | - * @param string $renderAs admin, user or blank. Admin also prints the admin |
|
134 | - * settings header and footer, user renders the normal |
|
135 | - * normal page including footer and header and blank |
|
136 | - * just renders the plain template |
|
137 | - * @return TemplateResponse Reference to this object |
|
138 | - * @since 6.0.0 - return value was added in 7.0.0 |
|
139 | - */ |
|
140 | - public function renderAs($renderAs) { |
|
141 | - $this->renderAs = $renderAs; |
|
142 | - |
|
143 | - return $this; |
|
144 | - } |
|
145 | - |
|
146 | - |
|
147 | - /** |
|
148 | - * Returns the set renderAs |
|
149 | - * @return string the renderAs value |
|
150 | - * @since 6.0.0 |
|
151 | - */ |
|
152 | - public function getRenderAs() { |
|
153 | - return $this->renderAs; |
|
154 | - } |
|
155 | - |
|
156 | - |
|
157 | - /** |
|
158 | - * Returns the rendered html |
|
159 | - * @return string the rendered html |
|
160 | - * @since 6.0.0 |
|
161 | - */ |
|
162 | - public function render() { |
|
163 | - // \OCP\Template needs an empty string instead of 'blank' for an unwrapped response |
|
164 | - $renderAs = $this->renderAs === 'blank' ? '' : $this->renderAs; |
|
165 | - |
|
166 | - \OCP\Util::addHeader('meta', ['name' => 'robots', 'content' => 'noindex, nofollow']); |
|
167 | - $template = new \OCP\Template($this->appName, $this->templateName, $renderAs); |
|
168 | - |
|
169 | - foreach ($this->params as $key => $value) { |
|
170 | - $template->assign($key, $value); |
|
171 | - } |
|
172 | - |
|
173 | - return $template->fetchPage($this->params); |
|
174 | - } |
|
41 | + /** |
|
42 | + * @deprecated 20.0.0 use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent |
|
43 | + */ |
|
44 | + public const EVENT_LOAD_ADDITIONAL_SCRIPTS = self::class . '::loadAdditionalScripts'; |
|
45 | + /** |
|
46 | + * @deprecated 20.0.0 use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent |
|
47 | + */ |
|
48 | + public const EVENT_LOAD_ADDITIONAL_SCRIPTS_LOGGEDIN = self::class . '::loadAdditionalScriptsLoggedIn'; |
|
49 | + |
|
50 | + /** |
|
51 | + * name of the template |
|
52 | + * @var string |
|
53 | + */ |
|
54 | + protected $templateName; |
|
55 | + |
|
56 | + /** |
|
57 | + * parameters |
|
58 | + * @var array |
|
59 | + */ |
|
60 | + protected $params; |
|
61 | + |
|
62 | + /** |
|
63 | + * rendering type (admin, user, blank) |
|
64 | + * @var string |
|
65 | + */ |
|
66 | + protected $renderAs; |
|
67 | + |
|
68 | + /** |
|
69 | + * app name |
|
70 | + * @var string |
|
71 | + */ |
|
72 | + protected $appName; |
|
73 | + |
|
74 | + /** |
|
75 | + * constructor of TemplateResponse |
|
76 | + * @param string $appName the name of the app to load the template from |
|
77 | + * @param string $templateName the name of the template |
|
78 | + * @param array $params an array of parameters which should be passed to the |
|
79 | + * template |
|
80 | + * @param string $renderAs how the page should be rendered, defaults to user |
|
81 | + * @since 6.0.0 - parameters $params and $renderAs were added in 7.0.0 |
|
82 | + */ |
|
83 | + public function __construct($appName, $templateName, array $params=[], |
|
84 | + $renderAs='user') { |
|
85 | + parent::__construct(); |
|
86 | + |
|
87 | + $this->templateName = $templateName; |
|
88 | + $this->appName = $appName; |
|
89 | + $this->params = $params; |
|
90 | + $this->renderAs = $renderAs; |
|
91 | + |
|
92 | + $this->setContentSecurityPolicy(new ContentSecurityPolicy()); |
|
93 | + $this->setFeaturePolicy(new FeaturePolicy()); |
|
94 | + } |
|
95 | + |
|
96 | + |
|
97 | + /** |
|
98 | + * Sets template parameters |
|
99 | + * @param array $params an array with key => value structure which sets template |
|
100 | + * variables |
|
101 | + * @return TemplateResponse Reference to this object |
|
102 | + * @since 6.0.0 - return value was added in 7.0.0 |
|
103 | + */ |
|
104 | + public function setParams(array $params) { |
|
105 | + $this->params = $params; |
|
106 | + |
|
107 | + return $this; |
|
108 | + } |
|
109 | + |
|
110 | + |
|
111 | + /** |
|
112 | + * Used for accessing the set parameters |
|
113 | + * @return array the params |
|
114 | + * @since 6.0.0 |
|
115 | + */ |
|
116 | + public function getParams() { |
|
117 | + return $this->params; |
|
118 | + } |
|
119 | + |
|
120 | + |
|
121 | + /** |
|
122 | + * Used for accessing the name of the set template |
|
123 | + * @return string the name of the used template |
|
124 | + * @since 6.0.0 |
|
125 | + */ |
|
126 | + public function getTemplateName() { |
|
127 | + return $this->templateName; |
|
128 | + } |
|
129 | + |
|
130 | + |
|
131 | + /** |
|
132 | + * Sets the template page |
|
133 | + * @param string $renderAs admin, user or blank. Admin also prints the admin |
|
134 | + * settings header and footer, user renders the normal |
|
135 | + * normal page including footer and header and blank |
|
136 | + * just renders the plain template |
|
137 | + * @return TemplateResponse Reference to this object |
|
138 | + * @since 6.0.0 - return value was added in 7.0.0 |
|
139 | + */ |
|
140 | + public function renderAs($renderAs) { |
|
141 | + $this->renderAs = $renderAs; |
|
142 | + |
|
143 | + return $this; |
|
144 | + } |
|
145 | + |
|
146 | + |
|
147 | + /** |
|
148 | + * Returns the set renderAs |
|
149 | + * @return string the renderAs value |
|
150 | + * @since 6.0.0 |
|
151 | + */ |
|
152 | + public function getRenderAs() { |
|
153 | + return $this->renderAs; |
|
154 | + } |
|
155 | + |
|
156 | + |
|
157 | + /** |
|
158 | + * Returns the rendered html |
|
159 | + * @return string the rendered html |
|
160 | + * @since 6.0.0 |
|
161 | + */ |
|
162 | + public function render() { |
|
163 | + // \OCP\Template needs an empty string instead of 'blank' for an unwrapped response |
|
164 | + $renderAs = $this->renderAs === 'blank' ? '' : $this->renderAs; |
|
165 | + |
|
166 | + \OCP\Util::addHeader('meta', ['name' => 'robots', 'content' => 'noindex, nofollow']); |
|
167 | + $template = new \OCP\Template($this->appName, $this->templateName, $renderAs); |
|
168 | + |
|
169 | + foreach ($this->params as $key => $value) { |
|
170 | + $template->assign($key, $value); |
|
171 | + } |
|
172 | + |
|
173 | + return $template->fetchPage($this->params); |
|
174 | + } |
|
175 | 175 | } |
@@ -41,11 +41,11 @@ discard block |
||
41 | 41 | /** |
42 | 42 | * @deprecated 20.0.0 use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent |
43 | 43 | */ |
44 | - public const EVENT_LOAD_ADDITIONAL_SCRIPTS = self::class . '::loadAdditionalScripts'; |
|
44 | + public const EVENT_LOAD_ADDITIONAL_SCRIPTS = self::class.'::loadAdditionalScripts'; |
|
45 | 45 | /** |
46 | 46 | * @deprecated 20.0.0 use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent |
47 | 47 | */ |
48 | - public const EVENT_LOAD_ADDITIONAL_SCRIPTS_LOGGEDIN = self::class . '::loadAdditionalScriptsLoggedIn'; |
|
48 | + public const EVENT_LOAD_ADDITIONAL_SCRIPTS_LOGGEDIN = self::class.'::loadAdditionalScriptsLoggedIn'; |
|
49 | 49 | |
50 | 50 | /** |
51 | 51 | * name of the template |
@@ -80,8 +80,8 @@ discard block |
||
80 | 80 | * @param string $renderAs how the page should be rendered, defaults to user |
81 | 81 | * @since 6.0.0 - parameters $params and $renderAs were added in 7.0.0 |
82 | 82 | */ |
83 | - public function __construct($appName, $templateName, array $params=[], |
|
84 | - $renderAs='user') { |
|
83 | + public function __construct($appName, $templateName, array $params = [], |
|
84 | + $renderAs = 'user') { |
|
85 | 85 | parent::__construct(); |
86 | 86 | |
87 | 87 | $this->templateName = $templateName; |
@@ -35,22 +35,22 @@ |
||
35 | 35 | * @since 20.0.0 |
36 | 36 | */ |
37 | 37 | class BeforeTemplateRenderedEvent extends Event { |
38 | - /** @var bool */ |
|
39 | - private $loggedIn; |
|
38 | + /** @var bool */ |
|
39 | + private $loggedIn; |
|
40 | 40 | |
41 | - /** |
|
42 | - * @since 20.0.0 |
|
43 | - */ |
|
44 | - public function __construct(bool $loggedIn) { |
|
45 | - parent::__construct(); |
|
41 | + /** |
|
42 | + * @since 20.0.0 |
|
43 | + */ |
|
44 | + public function __construct(bool $loggedIn) { |
|
45 | + parent::__construct(); |
|
46 | 46 | |
47 | - $this->loggedIn = $loggedIn; |
|
48 | - } |
|
47 | + $this->loggedIn = $loggedIn; |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * @since 20.0.0 |
|
52 | - */ |
|
53 | - public function isLoggedIn(): bool { |
|
54 | - return $this->loggedIn; |
|
55 | - } |
|
50 | + /** |
|
51 | + * @since 20.0.0 |
|
52 | + */ |
|
53 | + public function isLoggedIn(): bool { |
|
54 | + return $this->loggedIn; |
|
55 | + } |
|
56 | 56 | } |
@@ -39,41 +39,41 @@ |
||
39 | 39 | use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
40 | 40 | |
41 | 41 | class AdditionalScriptsMiddleware extends Middleware { |
42 | - /** @var EventDispatcherInterface */ |
|
43 | - private $legacyDispatcher; |
|
44 | - /** @var IUserSession */ |
|
45 | - private $userSession; |
|
46 | - /** @var IEventDispatcher */ |
|
47 | - private $dispatcher; |
|
42 | + /** @var EventDispatcherInterface */ |
|
43 | + private $legacyDispatcher; |
|
44 | + /** @var IUserSession */ |
|
45 | + private $userSession; |
|
46 | + /** @var IEventDispatcher */ |
|
47 | + private $dispatcher; |
|
48 | 48 | |
49 | - public function __construct(EventDispatcherInterface $legacyDispatcher, IUserSession $userSession, IEventDispatcher $dispatcher) { |
|
50 | - $this->legacyDispatcher = $legacyDispatcher; |
|
51 | - $this->userSession = $userSession; |
|
52 | - $this->dispatcher = $dispatcher; |
|
53 | - } |
|
49 | + public function __construct(EventDispatcherInterface $legacyDispatcher, IUserSession $userSession, IEventDispatcher $dispatcher) { |
|
50 | + $this->legacyDispatcher = $legacyDispatcher; |
|
51 | + $this->userSession = $userSession; |
|
52 | + $this->dispatcher = $dispatcher; |
|
53 | + } |
|
54 | 54 | |
55 | - public function afterController($controller, $methodName, Response $response): Response { |
|
56 | - /* |
|
55 | + public function afterController($controller, $methodName, Response $response): Response { |
|
56 | + /* |
|
57 | 57 | * There is no need to emit these signals on a public share page |
58 | 58 | * There is a separate event for that already |
59 | 59 | */ |
60 | - if ($controller instanceof PublicShareController) { |
|
61 | - return $response; |
|
62 | - } |
|
60 | + if ($controller instanceof PublicShareController) { |
|
61 | + return $response; |
|
62 | + } |
|
63 | 63 | |
64 | - if ($response instanceof TemplateResponse) { |
|
65 | - $this->legacyDispatcher->dispatch(TemplateResponse::EVENT_LOAD_ADDITIONAL_SCRIPTS, new GenericEvent()); |
|
64 | + if ($response instanceof TemplateResponse) { |
|
65 | + $this->legacyDispatcher->dispatch(TemplateResponse::EVENT_LOAD_ADDITIONAL_SCRIPTS, new GenericEvent()); |
|
66 | 66 | |
67 | - if (!($response instanceof StandaloneTemplateResponse) && $this->userSession->isLoggedIn()) { |
|
68 | - $this->legacyDispatcher->dispatch(TemplateResponse::EVENT_LOAD_ADDITIONAL_SCRIPTS_LOGGEDIN, new GenericEvent()); |
|
69 | - $isLoggedIn = true; |
|
70 | - } else { |
|
71 | - $isLoggedIn = false; |
|
72 | - } |
|
67 | + if (!($response instanceof StandaloneTemplateResponse) && $this->userSession->isLoggedIn()) { |
|
68 | + $this->legacyDispatcher->dispatch(TemplateResponse::EVENT_LOAD_ADDITIONAL_SCRIPTS_LOGGEDIN, new GenericEvent()); |
|
69 | + $isLoggedIn = true; |
|
70 | + } else { |
|
71 | + $isLoggedIn = false; |
|
72 | + } |
|
73 | 73 | |
74 | - $this->dispatcher->dispatchTyped(new BeforeTemplateRenderedEvent($isLoggedIn)); |
|
75 | - } |
|
74 | + $this->dispatcher->dispatchTyped(new BeforeTemplateRenderedEvent($isLoggedIn)); |
|
75 | + } |
|
76 | 76 | |
77 | - return $response; |
|
78 | - } |
|
77 | + return $response; |
|
78 | + } |
|
79 | 79 | } |