1
|
|
|
<?php |
2
|
|
|
namespace Email; |
3
|
|
|
require_once('Autoload.php'); |
4
|
|
|
|
5
|
|
|
abstract class DBEmail extends \Email\Email |
6
|
|
|
{ |
7
|
|
|
protected $dbData; |
8
|
|
|
|
9
|
|
|
public function __construct($datasetName, $datatableName, $dataRowName) |
10
|
|
|
{ |
11
|
|
|
parent::__construct(); |
12
|
|
|
$dataTable = \DataSetFactory::getDataTableByNames($datasetName, $datatableName); |
13
|
|
|
$this->dbData = $dataTable->read(new \Data\Filter('id eq '.$dataRowName)); |
14
|
|
|
if($this->dbData === false) |
15
|
|
|
{ |
16
|
|
|
throw new \Exception('Unknown dataRow identified by ID '.$dataRowName); |
17
|
|
|
} |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
public function getFromAddress() |
21
|
|
|
{ |
22
|
|
|
if(isset($this->dbData['from'])) |
23
|
|
|
{ |
24
|
|
|
return $this->dbData['from'];; |
25
|
|
|
} |
26
|
|
|
return parent::getFromAddress(); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function getReplyTo() |
30
|
|
|
{ |
31
|
|
|
if(isset($this->dbData['replyTo'])) |
32
|
|
|
{ |
33
|
|
|
return $this->dbData['replyTo'];; |
34
|
|
|
} |
35
|
|
|
return parent::getReplyTo(); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function getSubject() |
39
|
|
|
{ |
40
|
|
|
if(isset($this->dbData['subject'])) |
41
|
|
|
{ |
42
|
|
|
return $this->dbData['subject']; |
43
|
|
|
} |
44
|
|
|
return parent::getSubject(); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public abstract function getSubstituteVars(); |
48
|
|
|
|
49
|
|
|
protected function getRawBodyText($html) |
50
|
|
|
{ |
51
|
|
|
if(isset($this->dbData['body'])) |
52
|
|
|
{ |
53
|
|
|
return $this->dbData; |
54
|
|
|
} |
55
|
|
|
if($html === true) |
56
|
|
|
{ |
57
|
|
|
return $this->htmlBody; |
58
|
|
|
} |
59
|
|
|
return $this->textBody; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
protected function getBodyFromDB($html=true) |
63
|
|
|
{ |
64
|
|
|
$vars = $this->getSubstituteVars(); |
65
|
|
|
$rawText = $this->getRawBodyText($html); |
|
|
|
|
66
|
|
|
if($html === true) |
67
|
|
|
{ |
68
|
|
|
$text = strtr($raw_text, $vars); |
|
|
|
|
69
|
|
|
return $text; |
70
|
|
|
} |
71
|
|
|
$index = strpos($raw_text, "<script"); |
|
|
|
|
72
|
|
|
if($index !== false) |
73
|
|
|
{ |
74
|
|
|
$end = strpos($raw_text, "</script>"); |
|
|
|
|
75
|
|
|
if($index === 0) |
76
|
|
|
{ |
77
|
|
|
$raw_text = substr($raw_text, $end+9); |
|
|
|
|
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
return strtr(strip_tags($raw_text), $vars); |
|
|
|
|
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
public function getHTMLBody() |
84
|
|
|
{ |
85
|
|
|
return $this->getBodyFromDB(); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
public function getTextBody() |
89
|
|
|
{ |
90
|
|
|
return $this->getBodyFromDB(false); |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
?> |
|
|
|
|
94
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.