Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 192 lines (158 sloc) 4.871 kb
c28a238 @creativedutchmen Implemented the Core Email API, created by Huib Keemink and Michael E…
creativedutchmen authored
1 <?php
2
3 /**
4 * @package toolkit
5 */
6
7 /**
8 * A manager to standardize the finding and listing of installed gateways.
9 */
7ab86a6 @brendo The Merry Christmas Merge
brendo authored
10
11 require_once(TOOLKIT . '/class.emailgateway.php');
12 require_once(TOOLKIT . '/class.manager.php');
13
14 Class EmailGatewayManager extends Manager{
15
c28a238 @creativedutchmen Implemented the Core Email API, created by Huib Keemink and Michael E…
creativedutchmen authored
16 protected $_default_gateway = 'sendmail';
17
18 /**
19 * Sets the default gateway.
20 * Will throw an exception if the gateway can not be found.
21 *
22 * @param string $name
23 * @return void
24 */
7ab86a6 @brendo The Merry Christmas Merge
brendo authored
25 public function setDefaultGateway($name){
c28a238 @creativedutchmen Implemented the Core Email API, created by Huib Keemink and Michael E…
creativedutchmen authored
26 if($this->__find($name)){
27 Symphony::Configuration()->set('default_gateway', $name, 'Email');
28 $this->_Parent->saveConfig();
29 }
30 else{
31 throw new EmailGatewayException('This gateway can not be found. Can not save as default.');
32 }
33 }
34
35 /**
36 * Returns the default gateway.
37 * Will throw an exception if the gateway can not be found.
38 *
39 * @return string
40 */
7ab86a6 @brendo The Merry Christmas Merge
brendo authored
41 public function getDefaultGateway(){
c28a238 @creativedutchmen Implemented the Core Email API, created by Huib Keemink and Michael E…
creativedutchmen authored
42 $gateway = Symphony::Configuration()->get('default_gateway', 'Email');
43 if($gateway){
44 return $gateway;
45 }
46 else{
47 return $this->_default_gateway;
48 }
49 }
50
51 /**
52 * Finds the gateway by name
53 *
54 * @param string $name
55 * The gateway to look for
7ab86a6 @brendo The Merry Christmas Merge
brendo authored
56 * @return string|boolean
c28a238 @creativedutchmen Implemented the Core Email API, created by Huib Keemink and Michael E…
creativedutchmen authored
57 * If the gateway is found, the path to the folder containing the gateway is returned.
58 * If the gateway is not found, false is returned.
59 */
7ab86a6 @brendo The Merry Christmas Merge
brendo authored
60 public function __find($name){
c28a238 @creativedutchmen Implemented the Core Email API, created by Huib Keemink and Michael E…
creativedutchmen authored
61
7ab86a6 @brendo The Merry Christmas Merge
brendo authored
62 if(is_file(EMAILGATEWAYS . "/email.$name.php")) return EMAILGATEWAYS;
c28a238 @creativedutchmen Implemented the Core Email API, created by Huib Keemink and Michael E…
creativedutchmen authored
63 else{
64
65 $extensionManager = new ExtensionManager($this->_Parent);
66 $extensions = $extensionManager->listInstalledHandles();
67
68 if(is_array($extensions) && !empty($extensions)){
69 foreach($extensions as $e){
70 if(is_file(EXTENSIONS . "/$e/email-gateways/email.$name.php")) return EXTENSIONS . "/$e/email-gateways";
71 }
72 }
7ab86a6 @brendo The Merry Christmas Merge
brendo authored
73 }
c28a238 @creativedutchmen Implemented the Core Email API, created by Huib Keemink and Michael E…
creativedutchmen authored
74
7ab86a6 @brendo The Merry Christmas Merge
brendo authored
75 return false;
76 }
c28a238 @creativedutchmen Implemented the Core Email API, created by Huib Keemink and Michael E…
creativedutchmen authored
77
78 /**
79 * Returns the classname from the gateway name.
80 * Does not check if the gateway exists.
81 *
82 * @param string $name
83 * @return string
84 */
7ab86a6 @brendo The Merry Christmas Merge
brendo authored
85 public function __getClassName($name){
86 return $name . 'Gateway';
87 }
c28a238 @creativedutchmen Implemented the Core Email API, created by Huib Keemink and Michael E…
creativedutchmen authored
88
89 /**
90 * Alias for __find
91 *
92 * @param string $name
7ab86a6 @brendo The Merry Christmas Merge
brendo authored
93 * @return string|boolean
c28a238 @creativedutchmen Implemented the Core Email API, created by Huib Keemink and Michael E…
creativedutchmen authored
94 */
7ab86a6 @brendo The Merry Christmas Merge
brendo authored
95 public function __getClassPath($name){
96 return $this->__find($name);
97 }
c28a238 @creativedutchmen Implemented the Core Email API, created by Huib Keemink and Michael E…
creativedutchmen authored
98
99 /**
100 * Returns the path to the gateway file.
101 *
102 * @param string $name
103 * The gateway to look for
7ab86a6 @brendo The Merry Christmas Merge
brendo authored
104 * @return string|boolean
c28a238 @creativedutchmen Implemented the Core Email API, created by Huib Keemink and Michael E…
creativedutchmen authored
105 * @todo fix return if gateway does not exist.
106 */
7ab86a6 @brendo The Merry Christmas Merge
brendo authored
107 public function __getDriverPath($name){
108 return $this->__getClassPath($name) . "/email.$name.php";
109 }
c28a238 @creativedutchmen Implemented the Core Email API, created by Huib Keemink and Michael E…
creativedutchmen authored
110
111 /**
112 * Finds the name from the filename.
113 * Does not check if the gateway exists.
114 *
115 * @param string $filename
7ab86a6 @brendo The Merry Christmas Merge
brendo authored
116 * @return string|boolean
c28a238 @creativedutchmen Implemented the Core Email API, created by Huib Keemink and Michael E…
creativedutchmen authored
117 */
7ab86a6 @brendo The Merry Christmas Merge
brendo authored
118 public function __getHandleFromFilename($filename){
c28a238 @creativedutchmen Implemented the Core Email API, created by Huib Keemink and Michael E…
creativedutchmen authored
119 return preg_replace(array('/^email./i', '/.php$/i'), '', $filename);
120 }
121
122 /**
123 * Returns an array of all gateways.
124 * Each item in the array will contain the return value of the about() function of each gateway.
125 *
126 * @return array
127 */
7ab86a6 @brendo The Merry Christmas Merge
brendo authored
128 public function listAll(){
c28a238 @creativedutchmen Implemented the Core Email API, created by Huib Keemink and Michael E…
creativedutchmen authored
129
130 $result = array();
131 $people = array();
132
7ab86a6 @brendo The Merry Christmas Merge
brendo authored
133 $structure = General::listStructure(EMAILGATEWAYS, '/email.[\\w-]+.php/', false, 'ASC', EMAILGATEWAYS);
c28a238 @creativedutchmen Implemented the Core Email API, created by Huib Keemink and Michael E…
creativedutchmen authored
134
7ab86a6 @brendo The Merry Christmas Merge
brendo authored
135 if(is_array($structure['filelist']) && !empty($structure['filelist'])){
136 foreach($structure['filelist'] as $f){
137 $f = str_replace(array('email.', '.php'), '', $f);
c28a238 @creativedutchmen Implemented the Core Email API, created by Huib Keemink and Michael E…
creativedutchmen authored
138 $result[$f] = $this->about($f);
139 }
140 }
141
142 $extensionManager = new ExtensionManager($this->_Parent);
143 $extensions = $extensionManager->listInstalledHandles();
144
145 if(is_array($extensions) && !empty($extensions)){
146 foreach($extensions as $e){
147
148 if(!is_dir(EXTENSIONS . "/$e/email-gateways")) continue;
149
150 $tmp = General::listStructure(EXTENSIONS . "/$e/email-gateways", '/email.[\\w-]+.php/', false, 'ASC', EXTENSIONS . "/$e/email-gateways");
151
7ab86a6 @brendo The Merry Christmas Merge
brendo authored
152 if(is_array($tmp['filelist']) && !empty($tmp['filelist'])){
153 foreach($tmp['filelist'] as $f){
c28a238 @creativedutchmen Implemented the Core Email API, created by Huib Keemink and Michael E…
creativedutchmen authored
154 $f = preg_replace(array('/^email./i', '/.php$/i'), '', $f);
155 $result[$f] = $this->about($f);
156 }
157 }
158 }
159 }
160
161 ksort($result);
162 return $result;
7ab86a6 @brendo The Merry Christmas Merge
brendo authored
163 }
c28a238 @creativedutchmen Implemented the Core Email API, created by Huib Keemink and Michael E…
creativedutchmen authored
164
165 /**
166 * Creates a new object from a gateway name.
167 *
168 * @param string $name
169 * The gateway to look for
170 * @return EmailGateway
171 * If the gateway is found, an instantiated object is returned.
172 * If the gateway is not found, an error is triggered.
173 */
7ab86a6 @brendo The Merry Christmas Merge
brendo authored
174 public function &create($name){
c28a238 @creativedutchmen Implemented the Core Email API, created by Huib Keemink and Michael E…
creativedutchmen authored
175
7ab86a6 @brendo The Merry Christmas Merge
brendo authored
176 $classname = $this->__getClassName($name);
177 $path = $this->__getDriverPath($name);
c28a238 @creativedutchmen Implemented the Core Email API, created by Huib Keemink and Michael E…
creativedutchmen authored
178
7ab86a6 @brendo The Merry Christmas Merge
brendo authored
179 if(!is_file($path)){
180 trigger_error(__('Could not find Email Gateway <code>%s</code>. If the Email Gateway was provided by an Extensions, ensure that it is installed, and enabled.', array($name)), E_USER_ERROR);
181 return false;
182 }
c28a238 @creativedutchmen Implemented the Core Email API, created by Huib Keemink and Michael E…
creativedutchmen authored
183
184 if(!@class_exists($classname))
185 require_once($path);
186
187 return new $classname($this->_Parent);
188
7ab86a6 @brendo The Merry Christmas Merge
brendo authored
189 }
c28a238 @creativedutchmen Implemented the Core Email API, created by Huib Keemink and Michael E…
creativedutchmen authored
190
7ab86a6 @brendo The Merry Christmas Merge
brendo authored
191 }
Something went wrong with that request. Please try again.