1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
class EmailReminder_ReplacerClassBase extends Object implements EmailReminder_ReplacerClassInterface |
4
|
|
|
{ |
5
|
|
|
protected $replaceArray = array( |
6
|
|
|
'[PASSWORD_REMINDER_LINK]' => array( |
7
|
|
|
'Title' => 'Password reminder page', |
8
|
|
|
'Method' => 'PasswordReminderLink' |
9
|
|
|
), |
10
|
|
|
'[LOGIN_LINK]' => array( |
11
|
|
|
'Title' => 'Login Page', |
12
|
|
|
'Method' => 'LoginLink' |
13
|
|
|
), |
14
|
|
|
'[DAYS]' => array( |
15
|
|
|
'Title' => 'Replaces with the number of days, as set', |
16
|
|
|
'Method' => 'Days' |
17
|
|
|
), |
18
|
|
|
'[BEFORE_OR_AFTER]' => array( |
19
|
|
|
'Title' => 'Replaces with before or after expiry date, as set', |
20
|
|
|
'Method' => 'BeforeOrAfter' |
21
|
|
|
) |
22
|
|
|
); |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* |
26
|
|
|
* @return array |
27
|
|
|
*/ |
28
|
|
|
public function getReplaceArray() |
29
|
|
|
{ |
30
|
|
|
return $this->replaceArray; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* |
35
|
|
|
* @param EmailReminder $reminder |
36
|
|
|
* @param DataObject $record |
37
|
|
|
* @param string $str |
38
|
|
|
* |
39
|
|
|
* @return string |
40
|
|
|
*/ |
41
|
|
|
public function replace($reminder, $record, $str) |
42
|
|
|
{ |
43
|
|
|
$newArray = array(); |
|
|
|
|
44
|
|
|
foreach ($this->replaceArray as $searchString => $moreInfoArray) { |
45
|
|
|
$method = $moreInfoArray['Method']; |
46
|
|
|
$str = $this->$method($reminder, $record, $searchString, $str); |
47
|
|
|
} |
48
|
|
|
return $str; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* |
54
|
|
|
* @param bool $asHTML |
55
|
|
|
* |
56
|
|
|
* @return array |
|
|
|
|
57
|
|
|
*/ |
58
|
|
|
public function replaceHelpList($asHTML = false) |
59
|
|
|
{ |
60
|
|
|
$newArray = array(); |
61
|
|
|
foreach ($this->replaceArray as $searchString => $moreInfoArray) { |
62
|
|
|
$newArray[$searchString] = $moreInfoArray['Title']; |
63
|
|
|
} |
64
|
|
|
if ($asHTML) { |
65
|
|
|
$html = ' |
66
|
|
|
<ul class="replace-help-list">'; |
67
|
|
|
foreach ($newArray as $searchString => $title) { |
68
|
|
|
$html .= ' |
69
|
|
|
<li><strong>'.$searchString.':</strong> <span>'.$title.'</span></li>'; |
70
|
|
|
} |
71
|
|
|
$html .= ' |
72
|
|
|
</ul>'; |
73
|
|
|
return $html; |
74
|
|
|
} |
75
|
|
|
return $newArray; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* |
80
|
|
|
* @param EmailReminder $reminder |
81
|
|
|
* @param DataObject $record |
82
|
|
|
* @param string $searchString |
83
|
|
|
* @param string $str |
84
|
|
|
* |
85
|
|
|
* @return string |
86
|
|
|
*/ |
87
|
|
|
protected function PasswordReminderLink($reminder, $record, $searchString, $str) |
|
|
|
|
88
|
|
|
{ |
89
|
|
|
$replace = Director::absoluteURL('Security/lostpassword'); |
90
|
|
|
$str = str_replace($searchString, $replace, $str); |
91
|
|
|
return $str; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* |
96
|
|
|
* @param EmailReminder $reminder |
97
|
|
|
* @param DataObject $record |
98
|
|
|
* @param string $searchString |
99
|
|
|
* @param string $str |
100
|
|
|
* |
101
|
|
|
* @return string |
102
|
|
|
*/ |
103
|
|
|
protected function LoginLink($reminder, $record, $searchString, $str) |
|
|
|
|
104
|
|
|
{ |
105
|
|
|
$replace = Director::absoluteURL('Security/login'); |
106
|
|
|
$str = str_replace($searchString, $replace, $str); |
107
|
|
|
return $str; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* |
112
|
|
|
* @param EmailReminder $reminder |
113
|
|
|
* @param DataObject $record |
114
|
|
|
* @param string $searchString |
115
|
|
|
* @param string $str |
116
|
|
|
* |
117
|
|
|
* @return string |
118
|
|
|
*/ |
119
|
|
|
protected function Days($reminder, $record, $searchString, $str) |
|
|
|
|
120
|
|
|
{ |
121
|
|
|
$replace = $reminder->Days; |
122
|
|
|
$str = str_replace($searchString, $replace, $str); |
123
|
|
|
return $str; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* |
128
|
|
|
* @param EmailReminder $reminder |
129
|
|
|
* @param DataObject $record |
130
|
|
|
* @param string $searchString |
131
|
|
|
* @param string $str |
132
|
|
|
* |
133
|
|
|
* @return string |
134
|
|
|
*/ |
135
|
|
|
protected function BeforeOrAfter($reminder, $record, $searchString, $str) |
|
|
|
|
136
|
|
|
{ |
137
|
|
|
$replace = $reminder->BeforeAfter; |
138
|
|
|
$str = str_replace($searchString, $replace, $str); |
139
|
|
|
return $str; |
140
|
|
|
} |
141
|
|
|
} |
142
|
|
|
|
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.