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