1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace AppBundle\Controller; |
4
|
|
|
|
5
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; |
6
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
7
|
|
|
use Symfony\Component\Form\Extension\Core\Type\EmailType; |
8
|
|
|
use Symfony\Component\Form\Extension\Core\Type\SubmitType; |
9
|
|
|
use Symfony\Component\Form\Extension\Core\Type\TextareaType; |
10
|
|
|
use Symfony\Component\Form\Extension\Core\Type\TextType; |
11
|
|
|
use Symfony\Component\HttpFoundation\Request; |
12
|
|
|
use AppBundle\Entity\Contact; |
13
|
|
|
|
14
|
|
|
class DefaultController extends Controller |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @Route("/", name="homepage") |
18
|
|
|
*/ |
19
|
|
|
public function indexAction(Request $request) |
|
|
|
|
20
|
|
|
{ |
21
|
|
|
$repository = $this->getDoctrine()->getRepository('SymfonySiBlogBundle:Post'); |
22
|
|
|
|
23
|
|
|
$q = $repository->createQueryBuilder('p') |
24
|
|
|
->orderBy('p.created', 'DESC') |
25
|
|
|
->setMaxResults(10) |
26
|
|
|
->getQuery(); |
27
|
|
|
|
28
|
|
|
$posts = $q->getResult(); |
29
|
|
|
|
30
|
|
|
$jsonData = json_decode(file_get_contents('http://knpbundles.com/newest.json'), true); |
31
|
|
|
|
32
|
|
|
return $this->render('default/index.html.twig', [ |
33
|
|
|
'posts' => $posts, |
34
|
|
|
'bundles' => $jsonData['results'] |
35
|
|
|
]); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @Route("/copyrights", name="copyrights") |
40
|
|
|
* @param Request $request |
41
|
|
|
* @return \Symfony\Component\HttpFoundation\Response |
42
|
|
|
*/ |
43
|
|
|
public function copyrightAction(Request $request) |
|
|
|
|
44
|
|
|
{ |
45
|
|
|
return $this->render('default/copyright.html.twig'); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @Route("/join-us", name="join") |
50
|
|
|
* @param Request $request |
51
|
|
|
* @return \Symfony\Component\HttpFoundation\Response |
52
|
|
|
*/ |
53
|
|
|
public function joinAction(Request $request) |
|
|
|
|
54
|
|
|
{ |
55
|
|
|
return $this->render('default/join.html.twig'); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @Route("/contact", name="contact") |
60
|
|
|
* @param Request $request |
61
|
|
|
* @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response |
62
|
|
|
*/ |
63
|
|
|
public function contactAction(Request $request) |
64
|
|
|
{ |
65
|
|
|
$contact = new Contact(); |
66
|
|
|
|
67
|
|
|
$form = $this->createFormBuilder($contact) |
68
|
|
|
->add('name', TextType::class) |
69
|
|
|
->add('email', EmailType::class) |
70
|
|
|
->add('message', TextareaType::class) |
71
|
|
|
->add('send', SubmitType::class) |
72
|
|
|
->getForm(); |
73
|
|
|
|
74
|
|
|
$form->handleRequest($request); |
75
|
|
|
|
76
|
|
|
if($form->isValid()) { |
77
|
|
|
// send email to admin |
78
|
|
|
$message = \Swift_Message::newInstance() |
79
|
|
|
->setSubject('Message from Symfony.si') |
80
|
|
|
->setFrom($contact->getEmail()) |
81
|
|
|
->setTo($this->container->getParameter('symfonysi_admin_email')) |
82
|
|
|
->setBody( |
83
|
|
|
$this->renderView( |
84
|
|
|
'emails/email.txt.twig', |
85
|
|
|
array( |
86
|
|
|
'name' => $contact->getName(), |
87
|
|
|
'email' => $contact->getEmail(), |
88
|
|
|
'message' => $contact->getMessage() |
89
|
|
|
) |
90
|
|
|
) |
91
|
|
|
) |
92
|
|
|
; |
93
|
|
|
$this->get('mailer')->send($message); |
94
|
|
|
|
95
|
|
|
return $this->redirect($this->generateUrl('contact_success')); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
return $this->render('default/contact.html.twig', [ |
99
|
|
|
'form' => $form->createView(), |
100
|
|
|
]); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* @Route("/contact-succeeded", name="contact_success") |
105
|
|
|
* @param Request $request |
106
|
|
|
* @return \Symfony\Component\HttpFoundation\Response |
107
|
|
|
*/ |
108
|
|
|
public function contactSuccessAction(Request $request) |
|
|
|
|
109
|
|
|
{ |
110
|
|
|
return $this->render('default/contactSuccess.html.twig'); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* @Route("/contributors", name="contributors") |
115
|
|
|
* @param Request $request |
116
|
|
|
* @return \Symfony\Component\HttpFoundation\Response |
117
|
|
|
*/ |
118
|
|
|
public function contributorsAction(Request $request) |
|
|
|
|
119
|
|
|
{ |
120
|
|
|
$cache = $this->get('kernel')->getRootDir().'/../var/cache/github-api-cache'; |
121
|
|
|
$client = new \Github\Client( |
122
|
|
|
new \Github\HttpClient\CachedHttpClient(['cache_dir' => $cache]) |
123
|
|
|
); |
124
|
|
|
$srcContributors = $client->api('repo')->contributors('symfony-si', 'symfony.si'); |
|
|
|
|
125
|
|
|
$docsContributors = $client->api('repo')->contributors('symfony-si', 'symfony-docs-sl'); |
126
|
|
|
$contributors = []; |
127
|
|
|
|
128
|
|
|
foreach($srcContributors as $key=>$contributor) { |
129
|
|
|
$user = $client->api('user')->show($contributor['login']); |
|
|
|
|
130
|
|
|
$contributors[$contributor['login']] = [ |
131
|
|
|
'name' => ($user['name']) ? $user['name'] : $contributor['login'], |
132
|
|
|
'html_url' => $user['html_url'], |
133
|
|
|
'avatar_url' => $user['avatar_url'], |
134
|
|
|
]; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
foreach($docsContributors as $key=>$contributor) { |
138
|
|
|
$user = $client->api('user')->show($contributor['login']); |
|
|
|
|
139
|
|
|
$contributors[$contributor['login']] = [ |
140
|
|
|
'name' => ($user['name']) ? $user['name'] : $contributor['login'], |
141
|
|
|
'html_url' => $user['html_url'], |
142
|
|
|
'avatar_url' => $user['avatar_url'], |
143
|
|
|
]; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
return $this->render('default/contributors.html.twig', [ |
147
|
|
|
'contributors' => $contributors |
148
|
|
|
]); |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* @Route("/resources", name="resources") |
153
|
|
|
* @param Request $request |
154
|
|
|
* @return \Symfony\Component\HttpFoundation\Response |
155
|
|
|
*/ |
156
|
|
|
public function resourcesAction(Request $request) |
|
|
|
|
157
|
|
|
{ |
158
|
|
|
$file = __DIR__.'/../../../resources/README.md'; |
159
|
|
|
$content = (file_exists($file)) ? file_get_contents($file) : '<h1>Symfony resources</h1>'; |
160
|
|
|
$html = $this->container->get('markdown.parser')->transformMarkdown($content); |
161
|
|
|
|
162
|
|
|
return $this->render('default/resources.html.twig', ['html' => $html]); |
163
|
|
|
} |
164
|
|
|
} |
165
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.