1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Application\Controller\MembersArea\Tools; |
4
|
|
|
|
5
|
|
|
use Application\Tool\Helpers; |
6
|
|
|
use Silex\Application; |
7
|
|
|
use Symfony\Component\HttpFoundation\Request; |
8
|
|
|
use Symfony\Component\HttpFoundation\Response; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @author Borut Balažek <[email protected]> |
12
|
|
|
*/ |
13
|
|
|
class EmailController |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @param Request $request |
17
|
|
|
* @param Application $app |
18
|
|
|
* |
19
|
|
|
* @return Response |
20
|
|
|
*/ |
21
|
|
View Code Duplication |
public function indexAction(Request $request, Application $app) |
|
|
|
|
22
|
|
|
{ |
23
|
|
|
$data = array(); |
24
|
|
|
|
25
|
|
|
if (!$app['security']->isGranted('ROLE_ADMIN')) { |
26
|
|
|
$app->abort(403); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
return new Response( |
30
|
|
|
$app['twig']->render( |
31
|
|
|
'contents/members-area/tools/email.html.twig', |
32
|
|
|
$data |
33
|
|
|
) |
34
|
|
|
); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @param Request $request |
39
|
|
|
* @param Application $app |
40
|
|
|
* |
41
|
|
|
* @return Response |
42
|
|
|
*/ |
43
|
|
|
public function previewTemplatesAction(Request $request, Application $app) |
44
|
|
|
{ |
45
|
|
|
if (!$app['security']->isGranted('ROLE_ADMIN')) { |
46
|
|
|
$app->abort(403); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
$data = array(); |
50
|
|
|
|
51
|
|
|
$templates = array(); |
52
|
|
|
$template = $request->query->get('template', false); |
53
|
|
|
$raw = $request->query->has('raw'); |
54
|
|
|
|
55
|
|
|
// Set some possible global defaults for the template |
56
|
|
|
$emailData = array( |
57
|
|
|
'app' => $app, |
58
|
|
|
'user' => $app['user'], |
59
|
|
|
'content' => 'Hello world!', |
60
|
|
|
'formData' => array( |
61
|
|
|
'message' => 'Just a test message!', |
62
|
|
|
), |
63
|
|
|
); |
64
|
|
|
|
65
|
|
|
if ($template && $raw) { |
66
|
|
|
$app['debug'] = false; |
67
|
|
|
$app['showProfiler'] = false; |
68
|
|
|
|
69
|
|
|
return $app['mailer.css_to_inline_styles_converter']( |
70
|
|
|
'emails/'.$template.'.html.twig', |
71
|
|
|
$emailData |
72
|
|
|
); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
$templatesArray = Helpers::rglob( |
76
|
|
|
APP_DIR.'/templates/emails/*.html.twig' |
77
|
|
|
); |
78
|
|
|
|
79
|
|
|
if ($templatesArray) { |
|
|
|
|
80
|
|
|
foreach ($templatesArray as $templatePath) { |
81
|
|
|
$templatePath = str_replace( |
82
|
|
|
APP_DIR.'/templates/emails/', |
83
|
|
|
'', |
84
|
|
|
$templatePath |
85
|
|
|
); |
86
|
|
|
|
87
|
|
|
$templates[] = str_replace( |
88
|
|
|
'.html.twig', |
89
|
|
|
'', |
90
|
|
|
$templatePath |
91
|
|
|
); |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
$data['template'] = $template; |
96
|
|
|
$data['templates'] = $templates; |
97
|
|
|
|
98
|
|
|
return new Response( |
99
|
|
|
$app['twig']->render( |
100
|
|
|
'contents/members-area/tools/email/preview-templates.html.twig', |
101
|
|
|
$data |
102
|
|
|
) |
103
|
|
|
); |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.