]>
git.agnieray.net Git - galette.git/blob - galette/lib/Galette/Controllers/ImagesController.php
3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
6 * Galette images controller
10 * Copyright © 2020 The Galette Team
12 * This file is part of Galette (http://galette.tuxfamily.org).
14 * Galette is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation, either version 3 of the License, or
17 * (at your option) any later version.
19 * Galette is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with Galette. If not, see <http://www.gnu.org/licenses/>.
30 * @author Johan Cwiklinski <johan@x-tnd.be>
31 * @copyright 2020 The Galette Team
32 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
34 * @link http://galette.tuxfamily.org
35 * @since Available since 0.9.4dev - 2020-05-02
38 namespace Galette\Controllers
;
40 use Slim\Http\Request
;
41 use Slim\Http\Response
;
42 use Galette\Core\Picture
;
43 use Galette\Entity\Adherent
;
47 * Galette images controller
49 * @category Controllers
50 * @name ImageController
52 * @author Johan Cwiklinski <johan@x-tnd.be>
53 * @copyright 2020 The Galette Team
54 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
55 * @link http://galette.tuxfamily.org
56 * @since Available since 0.9.4dev - 2020-05-02
59 class ImagesController
extends AbstractController
65 * @param Response $response PSR Response
66 * @param Picture $picture Picture to output
70 protected function sendResponse(Response
$response, Picture
$picture): Response
72 $response = $response->withHeader('Content-Type', $picture->getMime())
73 ->withHeader('Content-Transfer-Encoding', 'binary')
74 ->withHeader('Expires', '0')
75 ->withHeader('Cache-Control', 'must-revalidate')
76 ->withHeader('Pragma', 'public');
78 $stream = fopen('php://memory', 'r+');
79 fwrite($stream, file_get_contents($picture->getPath()));
82 return $response->withBody(new \Slim\Http\
Stream($stream));
88 * @param Request $request PSR Request
89 * @param Response $response PSR Response
93 public function logo(Request
$request, Response
$response): Response
95 return $this->sendResponse($response, $this->logo
);
101 * @param Request $request PSR Request
102 * @param Response $response PSR Response
106 public function printLogo(Request
$request, Response
$response): Response
108 return $this->sendResponse($response, $this->print_logo
);
114 * @param Request $request PSR Request
115 * @param Response $response PSR Response
116 * @param array $args Request arguments ['id']
120 public function photo(Request
$request, Response
$response, array $args): Response
122 $id = (int)$args['id'];
129 //if loggedin user is a group manager, we have to check
130 //he manages a group requested member belongs to.
131 if ($this->login
->isGroupManager()) {
132 $deps['groups'] = true;
135 $adh = new Adherent($this->zdb
, (int)$id, $deps);
139 $adh->canEdit($this->login
)
140 ||
$this->preferences
->showPublicPages($this->login
)
141 && $adh->appearsInMembersList()
143 $picture = $adh->picture
;
145 $picture = new Picture();
148 return $this->sendResponse($response, $picture);