1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Starkerxp\CampagneBundle\Render; |
4
|
|
|
|
5
|
|
|
class OctosendHtmlRender extends AbstractRender |
6
|
|
|
{ |
7
|
|
|
public function render() |
8
|
|
|
{ |
9
|
|
|
// Gestion des liens mirror |
10
|
|
|
$contenu = $this->renderMirror($this->contenu); |
11
|
|
|
// Gestion des liens pixels |
12
|
|
|
$contenu = $this->renderPixel($contenu); |
13
|
|
|
// Gestion des liens de desinscriptions. |
14
|
|
|
$contenu = $this->renderLien("unsub", $contenu); |
15
|
|
|
// Gestion des liens click:http:// |
16
|
|
|
$contenu = $this->renderLien("click", $contenu); |
17
|
|
|
$contenu = str_replace(' ', ' ', str_replace(' ', ' ', $contenu)); |
18
|
|
|
|
19
|
|
|
return $contenu; |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
protected function renderMirror($contenu) |
23
|
|
|
{ |
24
|
|
|
$contenuReplace = preg_replace('/\[\{\@mirror\}\]/', '{{mirror}}', $contenu); |
25
|
|
|
|
26
|
|
|
return $contenuReplace; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
protected function renderPixel($contenu) |
30
|
|
|
{ |
31
|
|
|
$contenuReplace = preg_replace('/\[\{\@pixel\}\]/', '{{pixel}}', $contenu); |
32
|
|
|
|
33
|
|
|
return $contenuReplace; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
protected function renderLien($key, $contenu) |
37
|
|
|
{ |
38
|
|
|
if (!in_array($key, ["unsub", "click"])) { |
39
|
|
|
throw new \InvalidArgumentException(); |
40
|
|
|
} |
41
|
|
|
$arrayContenu = []; |
42
|
|
|
preg_match_all("#<a data-id=\"".$key."\" target=\"__blank\" href=\"(.*?)\" style=\"(.*?)\">(.*?)</a>#", $contenu, $arrayContenu); |
43
|
|
|
if (empty($arrayContenu[0])) { |
44
|
|
|
return $contenu; |
45
|
|
|
} |
46
|
|
|
if ($key == "unsub") { |
47
|
|
|
return $this->renderDesinscription($contenu, $arrayContenu); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
return $this->renderClick($contenu, $arrayContenu); |
51
|
|
|
|
52
|
|
|
} |
53
|
|
|
|
54
|
|
View Code Duplication |
protected function renderDesinscription($contenu, $arrayContenu) |
|
|
|
|
55
|
|
|
{ |
56
|
|
|
foreach ($arrayContenu[0] as $key => $chaineARemplacer) { |
57
|
|
|
$chaineOctoSend = "<a href='{{unsubscribe:".$arrayContenu[1][$key]."}}' style='".$arrayContenu[2][$key]."' title='Désinscription'>".$arrayContenu[3][$key].'</a>'; |
58
|
|
|
$contenu = str_replace($chaineARemplacer, $chaineOctoSend, $contenu); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
return $contenu; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
View Code Duplication |
protected function renderClick($contenu, $arrayContenu) |
|
|
|
|
65
|
|
|
{ |
66
|
|
|
foreach ($arrayContenu[0] as $key => $chaineARemplacer) { |
67
|
|
|
$chaineOctoSend = "<a href='{{click:".$arrayContenu[1][$key]."}}' style='".$arrayContenu[2][$key]."'>".$arrayContenu[3][$key].'</a>'; |
68
|
|
|
$contenu = str_replace($chaineARemplacer, $chaineOctoSend, $contenu); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
return $contenu; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function getSupport($api, $version) |
75
|
|
|
{ |
76
|
|
|
return strtolower($api) == 'octosend' && $version == 'html'; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
} |
80
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.