forked from GNUsocial/gnu-social
[Cover] Cover route, cover now renders
This commit is contained in:
parent
cf8b3b7b73
commit
aeec9149fc
@ -28,6 +28,7 @@ use App\Entity\Cover as CoverEntity;
|
|||||||
use App\Util\Common;
|
use App\Util\Common;
|
||||||
use App\Util\Exception\ClientException;
|
use App\Util\Exception\ClientException;
|
||||||
use Component\Media\Media;
|
use Component\Media\Media;
|
||||||
|
use Component\Media\Media as M;
|
||||||
use Symfony\Component\Form\Extension\Core\Type\FileType;
|
use Symfony\Component\Form\Extension\Core\Type\FileType;
|
||||||
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
|
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
|
||||||
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
||||||
@ -38,7 +39,7 @@ class Cover
|
|||||||
/**
|
/**
|
||||||
* Display and handle the cover edit page
|
* Display and handle the cover edit page
|
||||||
*/
|
*/
|
||||||
public function cover(Request $request)
|
public function coverSettings(Request $request)
|
||||||
{
|
{
|
||||||
$form = Form::create([
|
$form = Form::create([
|
||||||
['cover', FileType::class, ['label' => _m('Cover'), 'help' => _m('You can upload your personal cover. The maximum file size is 2MB.')]],
|
['cover', FileType::class, ['label' => _m('Cover'), 'help' => _m('You can upload your personal cover. The maximum file size is 2MB.')]],
|
||||||
@ -61,7 +62,9 @@ class Cover
|
|||||||
$cover = DB::find('cover', ['gsactor_id' => $actor_id]);
|
$cover = DB::find('cover', ['gsactor_id' => $actor_id]);
|
||||||
// Must get old id before inserting another one
|
// Must get old id before inserting another one
|
||||||
if ($cover != null) {
|
if ($cover != null) {
|
||||||
//$old_file = $avatar->delete();
|
var_dump('test');
|
||||||
|
$old_file = $cover->delete();
|
||||||
|
DB::remove($cover);
|
||||||
}
|
}
|
||||||
DB::persist($file);
|
DB::persist($file);
|
||||||
// Can only get new id after inserting
|
// Can only get new id after inserting
|
||||||
@ -74,8 +77,17 @@ class Cover
|
|||||||
if ($old_file != null) {
|
if ($old_file != null) {
|
||||||
@unlink($old_file);
|
@unlink($old_file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var_dump($cover->getFilePath());
|
||||||
}
|
}
|
||||||
|
|
||||||
return ['_template' => 'cover/cover.html.twig', 'form' => $form->createView()];
|
return ['_template' => 'cover/cover.html.twig', 'form' => $form->createView()];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function cover()
|
||||||
|
{
|
||||||
|
$cover = DB::find('cover', ['gsactor_id' => Common::user()->getId()]);
|
||||||
|
$file = $cover->getFile();
|
||||||
|
return M::sendFile($cover->getFilePath(), $file->getMimetype(), $file->getTitle());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
|
|
||||||
namespace Plugin\Cover;
|
namespace Plugin\Cover;
|
||||||
|
|
||||||
|
use App\Core\DB\DB;
|
||||||
use App\Core\Event;
|
use App\Core\Event;
|
||||||
use App\Core\Module;
|
use App\Core\Module;
|
||||||
use App\Core\Router\RouteLoader;
|
use App\Core\Router\RouteLoader;
|
||||||
@ -36,8 +37,9 @@ class Cover extends Module
|
|||||||
*/
|
*/
|
||||||
public function onAddRoute(RouteLoader $r): bool
|
public function onAddRoute(RouteLoader $r): bool
|
||||||
{
|
{
|
||||||
$r->connect('settings_cover', 'settings/cover', [Controller\Cover::class, 'cover']);
|
$r->connect('settings_cover', 'settings/cover', [Controller\Cover::class, 'coversettings']);
|
||||||
|
|
||||||
|
$r->connect('cover', '/cover', [Controller\Cover::class, 'cover']);
|
||||||
return Event::next;
|
return Event::next;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,17 +52,16 @@ class Cover extends Module
|
|||||||
*/
|
*/
|
||||||
public function onStartTwigPopulateVars(array &$vars): bool
|
public function onStartTwigPopulateVars(array &$vars): bool
|
||||||
{
|
{
|
||||||
/*
|
|
||||||
$vars['tabs'] = [['title' => 'Poll',
|
|
||||||
'href' => 'newpoll',
|
|
||||||
]];
|
|
||||||
*/
|
|
||||||
$vars['profile_tabs'] = [['title' => 'Cover',
|
$vars['profile_tabs'] = [['title' => 'Cover',
|
||||||
'href' => 'settings_cover',
|
'href' => 'settings_cover',
|
||||||
]];
|
]];
|
||||||
|
$vars['profile_temp'] = []; //fixme
|
||||||
|
|
||||||
if (Common::user() != null) {
|
if (Common::user() != null) {
|
||||||
$vars['profile_temp'][] = ['name' => 'cover', 'vars' => ['href' => 'test']];
|
$cover = DB::find('cover', ['gsactor_id' => Common::user()->getId()]);
|
||||||
|
if ($cover != null) {
|
||||||
|
$vars['profile_temp'][] = ['name' => 'cover', 'vars' => ['href' => '/cover']];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return Event::next;
|
return Event::next;
|
||||||
}
|
}
|
||||||
@ -74,7 +75,7 @@ class Cover extends Module
|
|||||||
*/
|
*/
|
||||||
public function onStartShowStyles(array &$styles): bool
|
public function onStartShowStyles(array &$styles): bool
|
||||||
{
|
{
|
||||||
//$styles[] = 'poll/poll.css';
|
//$styles[] = 'voer/poll.css';
|
||||||
return Event::next;
|
return Event::next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,9 @@
|
|||||||
|
|
||||||
namespace App\Entity;
|
namespace App\Entity;
|
||||||
|
|
||||||
|
use App\Core\DB\DB;
|
||||||
use App\Core\Entity;
|
use App\Core\Entity;
|
||||||
|
use App\Util\Common;
|
||||||
use DateTimeInterface;
|
use DateTimeInterface;
|
||||||
|
|
||||||
class Cover extends Entity
|
class Cover extends Entity
|
||||||
@ -79,6 +81,45 @@ class Cover extends Entity
|
|||||||
|
|
||||||
// }}} Autocode
|
// }}} Autocode
|
||||||
|
|
||||||
|
private ?File $file = null;
|
||||||
|
|
||||||
|
public function getFile(): File
|
||||||
|
{
|
||||||
|
$this->file = $this->file ?: DB::find('file', ['id' => $this->file_id]);
|
||||||
|
return $this->file;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getFilePathStatic(string $filename): string
|
||||||
|
{
|
||||||
|
return Common::config('cover', 'dir') . $filename;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getFilePath(): string
|
||||||
|
{
|
||||||
|
return Common::config('cover', 'dir') . $this->getFile()->getFileName();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete this cover and the corresponding file and thumbnails, which this owns
|
||||||
|
*/
|
||||||
|
public function delete(bool $flush = false, bool $delete_files_now = false, bool $cascading = false): array
|
||||||
|
{
|
||||||
|
// Don't go into a loop if we're deleting from File
|
||||||
|
if (!$cascading) {
|
||||||
|
$files = $this->getFile()->delete($cascade = true, $file_flush = false, $delete_files_now);
|
||||||
|
} else {
|
||||||
|
var_dump('test3');
|
||||||
|
DB::remove(DB::getReference('cover', ['gsactor_id' => $this->gsactor_id]));
|
||||||
|
$file_path = $this->getFilePath();
|
||||||
|
$files[] = $file_path;
|
||||||
|
if ($flush) {
|
||||||
|
DB::flush();
|
||||||
|
}
|
||||||
|
return $delete_files_now ? [] : $files;
|
||||||
|
}
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
public static function schemaDef(): array
|
public static function schemaDef(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
|
|
||||||
<div class="Cover">
|
<div class="Cover">
|
||||||
<h1> {{ vars.href }}</h1>
|
<a href="{{ path('settings_avatar') }}">
|
||||||
|
<img src='{{ vars.href }}' alt="Your cover." class="">
|
||||||
|
</a>
|
||||||
</div>
|
</div>
|
Loading…
Reference in New Issue
Block a user