1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Mailcode\Translator\Syntax\ApacheVelocity; |
6
|
|
|
|
7
|
|
|
use AppUtils\ConvertHelper; |
8
|
|
|
use Mailcode\Mailcode; |
9
|
|
|
use Mailcode\Mailcode_Commands_Command_ShowURL; |
10
|
|
|
use Mailcode\Mailcode_Translator_Syntax_ApacheVelocity; |
11
|
|
|
use Mailcode\Translator\Command\ShowURLInterface; |
12
|
|
|
|
13
|
|
|
class ShowURL extends Mailcode_Translator_Syntax_ApacheVelocity implements ShowURLInterface |
14
|
|
|
{ |
15
|
|
|
public function translate(Mailcode_Commands_Command_ShowURL $command) : string |
16
|
|
|
{ |
17
|
|
|
$statements = array(); |
18
|
|
|
$statements[] = $this->renderURL($command); |
19
|
|
|
|
20
|
|
|
if($command->isTrackingEnabled()) |
21
|
|
|
{ |
22
|
|
|
$statements[] = $this->renderTracking($command); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
if($command->hasQueryParams()) |
26
|
|
|
{ |
27
|
|
|
$params = $command->getQueryParams(); |
28
|
|
|
|
29
|
|
|
foreach($params as $name => $value) |
30
|
|
|
{ |
31
|
|
|
$statements[] = $this->renderQueryParam($name, $value); |
32
|
|
|
} |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
return sprintf( |
36
|
|
|
'$tracking.%s', |
37
|
|
|
implode('.', $statements) |
38
|
|
|
); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
private function renderQueryParam(string $name, string $value) : string |
42
|
|
|
{ |
43
|
|
|
return sprintf( |
44
|
|
|
'query(%s, %s)', |
45
|
|
|
$this->renderQuotedValue($name), |
46
|
|
|
$this->renderQuotedValue($value) |
47
|
|
|
); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
private function renderTracking(Mailcode_Commands_Command_ShowURL $command) : string |
51
|
|
|
{ |
52
|
|
|
return sprintf( |
53
|
|
|
"lt(\${tracking_host}, \${envelope_hash}, %s)", |
54
|
|
|
$this->renderQuotedValue($command->getTrackingID()) |
55
|
|
|
); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
private function renderURL(Mailcode_Commands_Command_ShowURL $command) : string |
59
|
|
|
{ |
60
|
|
|
return sprintf( |
61
|
|
|
'url(%s)', |
62
|
|
|
$this->renderQuotedValue($this->resolveURL($command)) |
63
|
|
|
); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
private function resolveURL(Mailcode_Commands_Command_ShowURL $command) : string |
67
|
|
|
{ |
68
|
|
|
// Remove newlines in the content. |
69
|
|
|
$content = trim(str_replace(array("\r", "\n"), '', $command->getContent())); |
70
|
|
|
|
71
|
|
|
$safeguard = Mailcode::create()->createSafeguard($content); |
72
|
|
|
|
73
|
|
|
return Mailcode::create()->createTranslator() |
74
|
|
|
->createSyntax($this->getSyntaxName()) |
75
|
|
|
->translateSafeguard($safeguard); |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|