1 | <?php |
||
36 | class PageController extends Controller { |
||
37 | |||
38 | use HttpError; |
||
39 | |||
40 | /** @var Environment */ |
||
41 | private $environment; |
||
42 | /** @var IURLGenerator */ |
||
43 | private $urlGenerator; |
||
44 | /** @var IConfig */ |
||
45 | private $appConfig; |
||
46 | /** @var IAppManager */ |
||
47 | private $appManager; |
||
48 | |||
49 | /** |
||
50 | * Constructor |
||
51 | * |
||
52 | * @param string $appName |
||
53 | * @param IRequest $request |
||
54 | * @param Environment $environment |
||
55 | * @param IURLGenerator $urlGenerator |
||
56 | * @param IConfig $appConfig |
||
57 | * @param IAppManager $appManager |
||
58 | */ |
||
59 | 12 | public function __construct( |
|
60 | $appName, |
||
61 | IRequest $request, |
||
62 | Environment $environment, |
||
63 | IURLGenerator $urlGenerator, |
||
64 | IConfig $appConfig, |
||
65 | IAppManager $appManager |
||
66 | ) { |
||
67 | 12 | parent::__construct($appName, $request); |
|
68 | |||
69 | 12 | $this->environment = $environment; |
|
70 | 12 | $this->urlGenerator = $urlGenerator; |
|
71 | 12 | $this->appConfig = $appConfig; |
|
72 | 12 | $this->appManager = $appManager; |
|
73 | 12 | } |
|
74 | |||
75 | /** |
||
76 | * @NoAdminRequired |
||
77 | * @NoCSRFRequired |
||
78 | * |
||
79 | * Shows the albums and pictures at the root folder or a message if |
||
80 | * there are no pictures. |
||
81 | * |
||
82 | * This is the entry page for logged-in users accessing the app from |
||
83 | * within ownCloud. |
||
84 | * A TemplateResponse response uses a template from the templates folder |
||
85 | * and parameters provided here to build the page users will see |
||
86 | * |
||
87 | * @return TemplateResponse |
||
88 | */ |
||
89 | 4 | public function index() { |
|
90 | 4 | $appName = $this->appName; |
|
91 | 4 | if ($this->appManager->isInstalled('gallery')) { |
|
92 | $message = |
||
93 | 1 | 'You need to disable the Gallery app before being able to use the Gallery+ app'; |
|
94 | |||
95 | 1 | return $this->htmlError($this->urlGenerator, $appName, new \Exception($message)); |
|
96 | } else { |
||
97 | // Parameters sent to the template |
||
98 | 3 | $params = $this->getIndexParameters($appName); |
|
99 | |||
100 | // Will render the page using the template found in templates/index.php |
||
101 | 3 | $response = new TemplateResponse($appName, 'index', $params); |
|
102 | 3 | $this->addContentSecurityToResponse($response); |
|
103 | |||
104 | 3 | return $response; |
|
105 | } |
||
106 | } |
||
107 | |||
108 | /** |
||
109 | * @PublicPage |
||
110 | * @NoCSRFRequired |
||
111 | * |
||
112 | * Shows the albums and pictures or redirects to the download location the token gives access to |
||
113 | * |
||
114 | * @param string $token |
||
115 | * @param null|string $filename |
||
116 | * |
||
117 | * @return TemplateResponse|ImageResponse|RedirectResponse |
||
118 | */ |
||
119 | 4 | public function publicIndex($token, $filename) { |
|
120 | 4 | $node = $this->environment->getSharedNode(); |
|
121 | 4 | if ($node->getType() === 'dir') { |
|
122 | 1 | return $this->showPublicPage($token); |
|
123 | } else { |
||
124 | 3 | $url = $this->urlGenerator->linkToRoute( |
|
125 | 3 | $this->appName . '.files_public.download', |
|
126 | [ |
||
127 | 3 | 'token' => $token, |
|
128 | 3 | 'fileId' => $node->getId(), |
|
129 | 3 | 'filename' => $filename |
|
130 | ] |
||
131 | ); |
||
132 | |||
133 | 3 | return new RedirectResponse($url); |
|
134 | } |
||
135 | } |
||
136 | |||
137 | /** |
||
138 | * @PublicPage |
||
139 | * @NoCSRFRequired |
||
140 | * @Guest |
||
141 | * |
||
142 | * Generates an error page based on the error code |
||
143 | * |
||
144 | * @param int $code |
||
145 | * |
||
146 | * @return TemplateResponse |
||
147 | */ |
||
148 | 3 | public function errorPage($code) { |
|
149 | 3 | $appName = $this->appName; |
|
150 | 3 | $message = $this->request->getCookie('galleryErrorMessage'); |
|
151 | $params = [ |
||
152 | 3 | 'appName' => $appName, |
|
153 | 3 | 'message' => $message, |
|
154 | 3 | 'code' => $code, |
|
155 | ]; |
||
156 | |||
157 | 3 | $errorTemplate = new TemplateResponse($appName, 'index', $params, 'guest'); |
|
158 | 3 | $errorTemplate->setStatus($code); |
|
159 | 3 | $errorTemplate->invalidateCookie('galleryErrorMessage'); |
|
160 | |||
161 | 3 | return $errorTemplate; |
|
162 | } |
||
163 | |||
164 | /** |
||
165 | * Adds the domain "data:" to the allowed image domains |
||
166 | * this function is called by reference |
||
167 | * |
||
168 | * @param TemplateResponse $response |
||
169 | */ |
||
170 | 4 | private function addContentSecurityToResponse($response) { |
|
176 | |||
177 | /** |
||
178 | * @PublicPage |
||
179 | * @NoCSRFRequired |
||
180 | * @Guest |
||
181 | * |
||
182 | * Returns the slideshow template |
||
183 | * |
||
184 | * @return TemplateResponse |
||
185 | */ |
||
186 | 1 | public function slideshow() { |
|
189 | |||
190 | /** |
||
191 | * Returns the parameters to be used in the index function |
||
192 | * |
||
193 | * @param $appName |
||
194 | * |
||
195 | * @return array<string,string> |
||
196 | */ |
||
197 | 3 | private function getIndexParameters($appName) { |
|
218 | |||
219 | /** |
||
220 | * Shows the albums and pictures the token gives access to |
||
221 | * |
||
222 | * @param $token |
||
223 | * |
||
224 | * @return TemplateResponse |
||
225 | */ |
||
226 | 1 | private function showPublicPage($token) { |
|
247 | |||
248 | /** |
||
249 | * Determines if we can add external shared to this instance |
||
250 | * |
||
251 | * @return array<bool,string> |
||
252 | */ |
||
253 | 1 | private function getServer2ServerProperties() { |
|
263 | } |
||
264 |