Skip to content

Commit 9f902fc

Browse files
committed
Make sidebar work
1 parent c49740a commit 9f902fc

10 files changed

+275
-25
lines changed

composer.json

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"ext-ctype": "*",
77
"ext-iconv": "*",
88
"ext-json": "*",
9+
"knplabs/knp-time-bundle": "^1.9",
910
"sensio/framework-extra-bundle": "^5.2",
1011
"symfony/asset": "4.2.*",
1112
"symfony/console": "4.2.*",

composer.lock

+195-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/bundles.php

+1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@
1111
Doctrine\Bundle\DoctrineBundle\DoctrineBundle::class => ['all' => true],
1212
Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle::class => ['all' => true],
1313
Symfony\Bundle\WebProfilerBundle\WebProfilerBundle::class => ['dev' => true, 'test' => true],
14+
Knp\Bundle\TimeBundle\KnpTimeBundle::class => ['all' => true],
1415
];

config/services.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# Put parameters here that don't need to change on each machine where the app is deployed
55
# https://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
66
parameters:
7+
locale: 'en'
78

89
services:
910
# default configuration for services in *this* file

src/Controller/PanelController.php

+5-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace App\Controller;
44

5+
use App\Repository\PasteRepository;
56
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
67
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
78
use Symfony\Component\Routing\Annotation\Route;
@@ -15,7 +16,9 @@ class PanelController extends AbstractController {
1516
* @IsGranted("ROLE_USER")
1617
* @Route("/", name="app_panel")
1718
*/
18-
public function root() {
19-
return $this->render("panel/panel.html.twig", []);
19+
public function root(PasteRepository $pasteRepository) {
20+
return $this->render("panel/panel.html.twig", [
21+
'sidebar' => $pasteRepository->getSidebar()
22+
]);
2023
}
2124
}

src/Controller/RootController.php

+16-11
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use App\Entity\Paste;
66
use App\Form\PasteType;
7+
use App\Repository\PasteRepository;
78
use App\Repository\UserRepository;
89
use App\Service\RecaptchaService;
910
use App\Utils\Utils;
@@ -20,25 +21,27 @@ class RootController extends AbstractController {
2021
/**
2122
* @Route("/", name="app_root")
2223
*/
23-
public function root(Request $request, RecaptchaService $recaptchaService) {
24+
public function root(Request $request, PasteRepository $pasteRepository, EntityManagerInterface $entityManager, RecaptchaService $recaptchaService) {
2425
$paste = new Paste();
2526
$form = $this->createForm(PasteType::class, $paste);
2627
$form->handleRequest($request);
2728

2829
if ($form->isSubmitted() && $form->isValid()) {
29-
if (!$recaptchaService->checkCaptcha($request->get('g-recaptcha-response'))) {
30+
/*if (!$recaptchaService->checkCaptcha($request->get('g-recaptcha-response'))) {
3031
$form->addError(new FormError('Are you a robot? Make captcha'));
3132
return $this->render('index.html.twig', [
3233
'form' => $form->createView(),
33-
'recaptcha' => getenv('RECAPTCHA_SITEKEY')
34+
'recaptcha' => getenv('RECAPTCHA_SITEKEY'),
35+
'sidebar' => $pasteRepository->getSidebar()
3436
]);
35-
}
37+
}*/
3638

3739
if (strlen(preg_replace('/\s/', '', $paste->getContent())) == 0) {
3840
$form->addError(new FormError('Content cant be empty'));
3941
return $this->render('index.html.twig', [
4042
'form' => $form->createView(),
41-
'recaptcha' => getenv('RECAPTCHA_SITEKEY')
43+
'recaptcha' => getenv('RECAPTCHA_SITEKEY'),
44+
'sidebar' => $pasteRepository->getSidebar()
4245
]);
4346
}
4447

@@ -48,7 +51,6 @@ public function root(Request $request, RecaptchaService $recaptchaService) {
4851
$paste->setContent(base64_encode(str_replace(array("\r\n", "\r", "\n"), "[new-line]", $paste->getContent())));
4952
$paste->setName(Utils::getRandomString(10));
5053

51-
$entityManager = $this->getDoctrine()->getManager();
5254
$entityManager->persist($paste);
5355
$entityManager->flush();
5456

@@ -59,25 +61,28 @@ public function root(Request $request, RecaptchaService $recaptchaService) {
5961

6062
return $this->render('index.html.twig', [
6163
'form' => $form->createView(),
62-
'recaptcha' => getenv('RECAPTCHA_SITEKEY')
64+
'recaptcha' => getenv('RECAPTCHA_SITEKEY'),
65+
'sidebar' => $pasteRepository->getSidebar()
6366
]);
6467
}
6568

6669
/**
6770
* @Route("/view/{name}", name="app_paste")
6871
*/
69-
public function paste(string $name, UserRepository $userRepository) {
70-
$paste = $this->getDoctrine()->getRepository(Paste::class)->findOneByName($name);
72+
public function paste(string $name, PasteRepository $pasteRepository, UserRepository $userRepository, LoggerInterface $logger) {
73+
$paste = $pasteRepository->findOneByName($name);
7174
if ($paste == null) {
7275
return $this->render('paste.html.twig', [
73-
'paste' => null
76+
'paste' => null,
77+
'sidebar' => $pasteRepository->getSidebar()
7478
]);
7579
}
7680

7781
return $this->render('paste.html.twig', [
7882
'content' => explode('[new-line]', base64_decode($paste->getContent())),
7983
'paste' => $paste,
80-
'username' => $paste->getOwner() != null ? $userRepository->findOneBy(['id' => $paste->getOwner()])->getUsername() : 'Guest'
84+
'username' => $paste->getOwner() != null ? $userRepository->findOneBy(['id' => $paste->getOwner()])->getUsername() : 'Guest',
85+
'sidebar' => $pasteRepository->getSidebar()
8186
]);
8287
}
8388
}

0 commit comments

Comments
 (0)