|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Dynamic\Foxy\Parser\Tests; |
|
4
|
|
|
|
|
5
|
|
|
use Dynamic\Foxy\Model\FoxyHelper; |
|
6
|
|
|
use SilverStripe\Control\Controller; |
|
7
|
|
|
use SilverStripe\Core\Config\Configurable; |
|
8
|
|
|
use SilverStripe\Core\Injector\Injectable; |
|
9
|
|
|
use SilverStripe\Security\Member; |
|
10
|
|
|
use SilverStripe\Security\PasswordEncryptor; |
|
11
|
|
|
|
|
12
|
|
|
class FoxyXMLFeedFactory |
|
13
|
|
|
{ |
|
14
|
|
|
use Configurable; |
|
15
|
|
|
use Injectable; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @var Controller |
|
19
|
|
|
*/ |
|
20
|
|
|
private $controller; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @var array |
|
24
|
|
|
*/ |
|
25
|
|
|
private $feed_array = []; |
|
26
|
|
|
|
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @var array |
|
30
|
|
|
*/ |
|
31
|
|
|
private static $feed_array_config = []; |
|
|
|
|
|
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* FoxyXMLFeedFactory constructor. |
|
35
|
|
|
* @param Controller $controller |
|
36
|
|
|
* @param array $feedData |
|
37
|
|
|
*/ |
|
38
|
|
|
public function __construct(Controller $controller, $feedData = []) |
|
39
|
|
|
{ |
|
40
|
|
|
$this->setController($controller); |
|
41
|
|
|
|
|
42
|
|
|
if (is_array($feedData) && !empty($feedData)) { |
|
43
|
|
|
$this->setFeedArray($feedData); |
|
44
|
|
|
} |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @return string |
|
49
|
|
|
*/ |
|
50
|
|
|
public static function generate_email() |
|
51
|
|
|
{ |
|
52
|
|
|
$emails = Member::get()->filter([ |
|
53
|
|
|
'Email:EndsWith' => '@example.com', |
|
54
|
|
|
])->column('Email'); |
|
55
|
|
|
|
|
56
|
|
|
if ($emails && count($emails)) { |
|
57
|
|
|
$email = $emails[count($emails) - 1]; |
|
58
|
|
|
|
|
59
|
|
|
return preg_replace_callback( |
|
60
|
|
|
"|(\d+)|", |
|
61
|
|
|
function ($mathces) { |
|
62
|
|
|
return ++$mathces[1]; |
|
63
|
|
|
}, |
|
64
|
|
|
$email |
|
65
|
|
|
); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
return '[email protected]'; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @param string $algorithm |
|
73
|
|
|
* @param string $password |
|
74
|
|
|
* @param string $salt |
|
75
|
|
|
* @return String |
|
76
|
|
|
* @throws \SilverStripe\Security\PasswordEncryptor_NotFoundException |
|
77
|
|
|
*/ |
|
78
|
|
|
public static function get_hashed_password($algorithm, $password, $salt) |
|
79
|
|
|
{ |
|
80
|
|
|
$encryptor = PasswordEncryptor::create_for_algorithm($algorithm); |
|
81
|
|
|
|
|
82
|
|
|
return $encryptor->encrypt($password, $salt); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* @param $controller |
|
87
|
|
|
* @return $this |
|
88
|
|
|
*/ |
|
89
|
|
|
protected function setController($controller) |
|
90
|
|
|
{ |
|
91
|
|
|
$this->controller = $controller; |
|
92
|
|
|
|
|
93
|
|
|
return $this; |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* @return Controller |
|
98
|
|
|
*/ |
|
99
|
|
|
protected function getController() |
|
100
|
|
|
{ |
|
101
|
|
|
return $this->controller; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* @param array $feedData |
|
106
|
|
|
* @return $this |
|
107
|
|
|
*/ |
|
108
|
|
|
public function setFeedArray($feedData = []) |
|
109
|
|
|
{ |
|
110
|
|
|
if (is_array($feedData) && !empty($feedData)) { |
|
111
|
|
|
$this->feed_array = $feedData; |
|
112
|
|
|
} else { |
|
113
|
|
|
$this->feed_array = $this->config()->get('feed_array_config'); |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
return $this; |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
/** |
|
120
|
|
|
* @return array |
|
121
|
|
|
*/ |
|
122
|
|
|
public function getFeedArray() |
|
123
|
|
|
{ |
|
124
|
|
|
return $this->feed_array; |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
/** |
|
128
|
|
|
* @return mixed |
|
129
|
|
|
*/ |
|
130
|
|
|
public function getXML() |
|
131
|
|
|
{ |
|
132
|
|
|
$xml = Controller::curr()->renderWith('TestData', $this->getFeedArray()); |
|
133
|
|
|
|
|
134
|
|
|
return $xml->RAW(); |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
/** |
|
138
|
|
|
* @return string |
|
139
|
|
|
* @throws \SilverStripe\ORM\ValidationException |
|
140
|
|
|
* @throws \SilverStripe\Security\PasswordEncryptor_NotFoundException |
|
141
|
|
|
*/ |
|
142
|
|
|
public function encryptedXML() |
|
143
|
|
|
{ |
|
144
|
|
|
$helper = FoxyHelper::singleton(); |
|
145
|
|
|
|
|
146
|
|
|
return \rc4crypt::encrypt($helper->config()->get('secret'), $this->getXML()); |
|
147
|
|
|
} |
|
148
|
|
|
} |
|
149
|
|
|
|