2020-12-17 04:27:41 +09:00
|
|
|
<?php
|
|
|
|
|
|
|
|
// {{{ License
|
|
|
|
|
|
|
|
// This file is part of GNU social - https://www.gnu.org/software/social
|
|
|
|
//
|
|
|
|
// GNU social is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// GNU social is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
// }}}
|
|
|
|
|
|
|
|
namespace Plugin\ProfileColor\Controller;
|
|
|
|
|
2020-12-17 08:19:52 +09:00
|
|
|
use App\Core\DB\DB;
|
2020-12-17 04:27:41 +09:00
|
|
|
use App\Core\Form;
|
2021-09-25 22:06:58 +09:00
|
|
|
use App\Util\Exception\DuplicateFoundException;
|
|
|
|
use App\Util\Exception\NotFoundException;
|
2021-09-25 20:51:25 +09:00
|
|
|
use App\Util\Exception\ServerException;
|
2020-12-17 04:27:41 +09:00
|
|
|
use function App\Core\I18n\_m;
|
2020-12-17 08:19:52 +09:00
|
|
|
use App\Util\Common;
|
2020-12-19 04:45:45 +09:00
|
|
|
use App\Util\Exception\RedirectException;
|
2021-09-07 03:49:03 +09:00
|
|
|
use Plugin\ProfileColor\Entity;
|
2020-12-17 08:19:52 +09:00
|
|
|
use Symfony\Component\Form\Extension\Core\Type\ColorType;
|
2020-12-17 04:27:41 +09:00
|
|
|
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
|
|
|
|
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
|
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
|
|
|
|
|
|
/**
|
2020-12-17 08:19:52 +09:00
|
|
|
* Profile Color controller
|
2020-12-17 04:27:41 +09:00
|
|
|
*
|
|
|
|
* @package GNUsocial
|
2020-12-17 08:19:52 +09:00
|
|
|
* @category ProfileColor
|
2020-12-17 04:27:41 +09:00
|
|
|
*
|
|
|
|
* @author Daniel Brandao <up201705812@fe.up.pt>
|
2021-09-25 20:51:25 +09:00
|
|
|
* @author Eliseu Amaro <mail@eliseuama.ro>
|
2020-12-17 04:27:41 +09:00
|
|
|
* @copyright 2020 Free Software Foundation, Inc http://www.fsf.org
|
|
|
|
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
|
|
|
|
*/
|
|
|
|
class ProfileColor
|
|
|
|
{
|
2021-09-25 20:51:25 +09:00
|
|
|
|
2020-12-17 04:27:41 +09:00
|
|
|
/**
|
2021-09-25 20:51:25 +09:00
|
|
|
* Change Profile color background
|
2020-12-17 04:27:41 +09:00
|
|
|
* @param Request $request
|
2021-09-25 20:51:25 +09:00
|
|
|
* @return array
|
2020-12-20 05:52:36 +09:00
|
|
|
* @throws RedirectException
|
2021-09-25 20:51:25 +09:00
|
|
|
* @throws ServerException
|
2020-12-17 04:27:41 +09:00
|
|
|
*/
|
2021-07-30 04:20:32 +09:00
|
|
|
public static function profileColorSettings(Request $request)
|
2020-12-17 04:27:41 +09:00
|
|
|
{
|
2021-09-25 22:06:58 +09:00
|
|
|
$actor = Common::actor();
|
|
|
|
$actor_id = $actor->getId();
|
|
|
|
|
|
|
|
$current_profile_color = DB::find('profile_color', ['actor_id' => $actor_id]);
|
2020-12-17 08:19:52 +09:00
|
|
|
|
2020-12-17 04:27:41 +09:00
|
|
|
$form = Form::create([
|
2021-10-06 03:04:30 +09:00
|
|
|
['background_color', ColorType::class, [
|
|
|
|
'html5' => true,
|
|
|
|
'data' => $current_profile_color ? $current_profile_color->getBackground() : "#000000",
|
|
|
|
'label' => _m('Profile background color'),
|
|
|
|
'help' => _m('Choose your Profile background color')]
|
|
|
|
],
|
|
|
|
['foreground_color', ColorType::class, [
|
2021-09-25 20:51:25 +09:00
|
|
|
'html5' => true,
|
2021-09-25 22:06:58 +09:00
|
|
|
'data' => $current_profile_color ? $current_profile_color->getColor() : "#000000",
|
2021-10-06 03:04:30 +09:00
|
|
|
'label' => _m('Profile foreground color'),
|
|
|
|
'help' => _m('Choose your Profile foreground color')]
|
2021-09-25 20:51:25 +09:00
|
|
|
],
|
2020-12-17 04:27:41 +09:00
|
|
|
['hidden', HiddenType::class, []],
|
2021-08-19 02:38:54 +09:00
|
|
|
['save_profile_color', SubmitType::class, ['label' => _m('Submit')]],
|
2020-12-17 04:27:41 +09:00
|
|
|
]);
|
|
|
|
|
|
|
|
$form->handleRequest($request);
|
2021-09-25 20:51:25 +09:00
|
|
|
|
2020-12-17 04:27:41 +09:00
|
|
|
if ($form->isSubmitted() && $form->isValid()) {
|
2020-12-17 08:19:52 +09:00
|
|
|
|
2021-09-25 22:06:58 +09:00
|
|
|
if ($current_profile_color !== null) {
|
|
|
|
DB::remove($current_profile_color);
|
2020-12-17 08:19:52 +09:00
|
|
|
DB::flush();
|
|
|
|
}
|
|
|
|
|
2021-09-25 20:51:25 +09:00
|
|
|
$data = $form->getData();
|
2021-10-06 03:04:30 +09:00
|
|
|
$current_profile_color = Entity\ProfileColor::create(['actor_id' => $actor_id, 'color' => $data['foreground_color'], 'background' => $data['background_color']]);
|
2021-09-25 22:06:58 +09:00
|
|
|
DB::persist($current_profile_color);
|
2020-12-17 08:19:52 +09:00
|
|
|
DB::flush();
|
2021-09-25 20:51:25 +09:00
|
|
|
|
2020-12-19 04:45:45 +09:00
|
|
|
throw new RedirectException();
|
2020-12-17 04:27:41 +09:00
|
|
|
}
|
|
|
|
|
2021-09-25 20:51:25 +09:00
|
|
|
return ['_template' => 'profileColor/profileColorSettings.html.twig', 'profile_color' => $form->createView()];
|
2020-12-17 04:27:41 +09:00
|
|
|
}
|
|
|
|
}
|