mirror of
https://github.com/ad-aures/castopod.git
synced 2026-04-12 03:06:43 +02:00
feat(settings): add general config for instance (site name, description and icon)
This commit is contained in:
parent
193b373bc9
commit
5c56f3e6f0
41 changed files with 533 additions and 52 deletions
|
|
@ -18,6 +18,21 @@ $routes->group(
|
|||
'as' => 'admin',
|
||||
]);
|
||||
|
||||
$routes->group('settings', function ($routes): void {
|
||||
$routes->get('/', 'SettingsController', [
|
||||
'as' => 'settings-general',
|
||||
'filter' => 'permission:settings-manage',
|
||||
]);
|
||||
$routes->post('instance', 'SettingsController::attemptInstanceEdit', [
|
||||
'as' => 'settings-instance',
|
||||
'filter' => 'permission:settings-manage',
|
||||
]);
|
||||
$routes->get('instance-delete-icon', 'SettingsController::deleteIcon', [
|
||||
'as' => 'settings-instance-delete-icon',
|
||||
'filter' => 'permission:settings-manage',
|
||||
]);
|
||||
});
|
||||
|
||||
$routes->group('persons', function ($routes): void {
|
||||
$routes->get('/', 'PersonController', [
|
||||
'as' => 'person-list',
|
||||
|
|
|
|||
105
modules/Admin/Controllers/SettingsController.php
Normal file
105
modules/Admin/Controllers/SettingsController.php
Normal file
|
|
@ -0,0 +1,105 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @copyright 2020 Podlibre
|
||||
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
|
||||
* @link https://castopod.org/
|
||||
*/
|
||||
|
||||
namespace Modules\Admin\Controllers;
|
||||
|
||||
use CodeIgniter\HTTP\RedirectResponse;
|
||||
use PHP_ICO;
|
||||
|
||||
class SettingsController extends BaseController
|
||||
{
|
||||
public function index(): string
|
||||
{
|
||||
helper('form');
|
||||
return view('settings/general');
|
||||
}
|
||||
|
||||
public function attemptInstanceEdit(): RedirectResponse
|
||||
{
|
||||
$rules = [
|
||||
'site_icon' =>
|
||||
'is_image[site_icon]|ext_in[site_icon,png,jpeg]|is_image_squared[site_icon]|min_dims[image,512,512]|permit_empty',
|
||||
];
|
||||
|
||||
if (! $this->validate($rules)) {
|
||||
return redirect()
|
||||
->back()
|
||||
->withInput()
|
||||
->with('errors', $this->validator->getErrors());
|
||||
}
|
||||
|
||||
$siteName = $this->request->getPost('site_name');
|
||||
if ($siteName !== service('settings')->get('App.siteName')) {
|
||||
service('settings')->set('App.siteName', $siteName);
|
||||
}
|
||||
|
||||
$siteDescription = $this->request->getPost('site_description');
|
||||
if ($siteDescription !== service('settings')->get('App.siteDescription')) {
|
||||
service('settings')->set('App.siteDescription', $siteDescription);
|
||||
}
|
||||
|
||||
$siteIconFile = $this->request->getFile('site_icon');
|
||||
if ($siteIconFile !== null && $siteIconFile->isValid()) {
|
||||
helper(['filesystem', 'media']);
|
||||
|
||||
// delete site folder in media before repopulating it
|
||||
delete_files(ROOTPATH . 'public/media/site/');
|
||||
|
||||
// save original in disk
|
||||
$originalFilename = save_media($siteIconFile, 'site', 'icon');
|
||||
|
||||
// convert jpeg image to png if not
|
||||
if ($siteIconFile->getClientMimeType() !== 'image/png') {
|
||||
service('image')->withFile(ROOTPATH . 'public/media/' . $originalFilename)
|
||||
->convert(IMAGETYPE_JPEG)
|
||||
->save(ROOTPATH . 'public/media/site/icon.png');
|
||||
}
|
||||
|
||||
// generate random hash to use as a suffix to renew browser cache
|
||||
$randomHash = substr(bin2hex(random_bytes(18)), 0, 8);
|
||||
|
||||
// generate ico
|
||||
$ico_lib = new PHP_ICO();
|
||||
$ico_lib->add_image(ROOTPATH . 'public/media/site/icon.png', [[32, 32], [64, 64]]);
|
||||
$ico_lib->save_ico(ROOTPATH . "public/media/site/favicon.{$randomHash}.ico");
|
||||
|
||||
// resize original to needed sizes
|
||||
foreach ([64, 180, 192, 512] as $size) {
|
||||
service('image')
|
||||
->withFile(ROOTPATH . 'public/media/site/icon.png')
|
||||
->resize($size, $size)
|
||||
->save(ROOTPATH . "public/media/site/icon-{$size}.{$randomHash}.png");
|
||||
}
|
||||
|
||||
service('settings')
|
||||
->set('App.siteIcon', [
|
||||
'ico' => "/media/site/favicon.{$randomHash}.ico",
|
||||
'64' => "/media/site/icon-64.{$randomHash}.png",
|
||||
'180' => "/media/site/icon-180.{$randomHash}.png",
|
||||
'192' => "/media/site/icon-192.{$randomHash}.png",
|
||||
'512' => "/media/site/icon-512.{$randomHash}.png",
|
||||
]);
|
||||
}
|
||||
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
public function deleteIcon(): RedirectResponse
|
||||
{
|
||||
helper('filesystem');
|
||||
// delete site folder in media
|
||||
delete_files(ROOTPATH . 'public/media/site/');
|
||||
|
||||
service('settings')
|
||||
->forget('App.siteIcon');
|
||||
|
||||
return redirect()->back();
|
||||
}
|
||||
}
|
||||
|
|
@ -29,6 +29,8 @@ return [
|
|||
'pages' => 'Pages',
|
||||
'page-list' => 'All pages',
|
||||
'page-create' => 'New Page',
|
||||
'settings' => 'Settings',
|
||||
'settings-general' => 'General',
|
||||
'account' => [
|
||||
'my-account' => 'My account',
|
||||
'change-password' => 'Change password',
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ return [
|
|||
'episodes' => 'episodes',
|
||||
'contributors' => 'contributors',
|
||||
'pages' => 'pages',
|
||||
'settings' => 'settings',
|
||||
'add' => 'add',
|
||||
'new' => 'new',
|
||||
'edit' => 'edit',
|
||||
|
|
|
|||
23
modules/Admin/Language/en/Settings.php
Normal file
23
modules/Admin/Language/en/Settings.php
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @copyright 2020 Podlibre
|
||||
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
|
||||
* @link https://castopod.org/
|
||||
*/
|
||||
|
||||
return [
|
||||
'title' => 'General settings',
|
||||
'form' => [
|
||||
'site_section_title' => 'Instance',
|
||||
'site_icon' => 'Site icon',
|
||||
'site_icon_delete' => 'Delete site icon',
|
||||
'site_icon_hint' => 'Site icons are what you see on your browser tabs, bookmarks bar, and when you add a website as a shortcut on mobile devices.',
|
||||
'site_icon_helper' => 'Icon must be squared with at least 512px wide and tall.',
|
||||
'site_name' => 'Site name',
|
||||
'site_description' => 'Site description',
|
||||
'submit' => 'Save',
|
||||
],
|
||||
];
|
||||
|
|
@ -28,6 +28,8 @@ return [
|
|||
'pages' => 'Pages',
|
||||
'page-list' => 'Toutes les pages',
|
||||
'page-create' => 'Créer une page',
|
||||
'settings' => 'Paramètres',
|
||||
'settings-general' => 'Général',
|
||||
'account' => [
|
||||
'my-account' => 'Mon compte',
|
||||
'change-password' => 'Modifier le mot de passe',
|
||||
|
|
|
|||
24
modules/Admin/Language/fr/Settings.php
Normal file
24
modules/Admin/Language/fr/Settings.php
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @copyright 2020 Podlibre
|
||||
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
|
||||
* @link https://castopod.org/
|
||||
*/
|
||||
|
||||
return [
|
||||
'title' => 'Paramètres généraux',
|
||||
'form' => [
|
||||
'site_section_title' => 'Instance',
|
||||
'site_section_subtitle' => 'configuration de l’instance',
|
||||
'site_icon' => 'Favicon du site',
|
||||
'site_icon_delete' => 'Supprimer la favicon du site',
|
||||
'site_icon_hint' => 'Les favicons sont ce que vous voyez sur les onglets de votre navigateur, dans votre barre de favoris, et lorsque vous ajoutez un site web en raccourci sur des appareils mobiles.',
|
||||
'site_icon_helper' => 'La favicon doit être carrée et avoir au moins 512px de largeur et de hauteur.',
|
||||
'site_name' => 'Titre du site',
|
||||
'site_description' => 'Description du site',
|
||||
'submit' => 'Save',
|
||||
],
|
||||
];
|
||||
|
|
@ -243,6 +243,8 @@ class InstallController extends Controller
|
|||
{
|
||||
$migrations = Services::migrations();
|
||||
|
||||
$migrations->setNamespace('Sparks\Settings')
|
||||
->latest();
|
||||
$migrations->setNamespace('Myth\Auth')
|
||||
->latest();
|
||||
$migrations->setNamespace('Modules\Fediverse')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue