GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Pull Request — develop (#163)
by
unknown
09:22
created
myth/Mail/CIMailService.php 1 patch
Indentation   +222 added lines, -222 removed lines patch added patch discarded remove patch
@@ -40,226 +40,226 @@
 block discarded – undo
40 40
  */
41 41
 class CIMailService implements MailServiceInterface {
42 42
 
43
-    protected $ci = null;
44
-
45
-    protected $format = 'html';
46
-
47
-    //--------------------------------------------------------------------
48
-
49
-    public function __construct()
50
-    {
51
-        $this->ci =& get_instance();
52
-
53
-        $this->ci->load->library('email');
54
-    }
55
-
56
-    //--------------------------------------------------------------------
57
-
58
-
59
-    /**
60
-     * Does the actual delivery of a message.
61
-     *
62
-     * @param bool  $clear_after    If TRUE, will reset the class after sending.
63
-     *
64
-     * @return mixed
65
-     */
66
-    public function send($clear_after=true)
67
-    {
68
-        $this->ci->email->mailtype = $this->format;
69
-
70
-        $result = $this->ci->email->send(false);
71
-
72
-        return $result;
73
-    }
74
-
75
-    //--------------------------------------------------------------------
76
-
77
-    /**
78
-     * Adds an attachment to the current email that is being built.
79
-     *
80
-     * @param string    $filename
81
-     * @param string    $disposition    like 'inline'. Default is 'attachment'
82
-     * @param string    $newname        If you'd like to rename the file for delivery
83
-     * @param string    $mime           Custom defined mime type.
84
-     */
85
-    public function attach($filename, $disposition=null, $newname=null, $mime=null)
86
-    {
87
-        $this->ci->email->attach($filename, $disposition, $newname, $mime);
88
-    }
89
-
90
-    //--------------------------------------------------------------------
91
-
92
-    /**
93
-     * Sets a header value for the email. Not every service will provide this.
94
-     *
95
-     * @param $field
96
-     * @param $value
97
-     * @return mixed
98
-     */
99
-    public function setHeader($field, $value)
100
-    {
101
-        $this->ci->email->set_header($field, $value);
102
-
103
-        return $this;
104
-    }
105
-
106
-    //--------------------------------------------------------------------
107
-
108
-    //--------------------------------------------------------------------
109
-    // Options
110
-    //--------------------------------------------------------------------
111
-
112
-    /**
113
-     * Sets the email address to send the email to.
114
-     *
115
-     * @param $email
116
-     * @return mixed
117
-     */
118
-    public function to($email)
119
-    {
120
-        $this->ci->email->to($email);
121
-
122
-        return $this;
123
-    }
124
-
125
-    //--------------------------------------------------------------------
126
-
127
-    /**
128
-     * Sets who the email is coming from.
129
-     *
130
-     * @param $email
131
-     * @param null $name
132
-     * @return mixed
133
-     */
134
-    public function from($email, $name=null)
135
-    {
136
-        $this->ci->email->from($email, $name);
137
-
138
-        return $this;
139
-    }
140
-
141
-    //--------------------------------------------------------------------
142
-
143
-    /**
144
-     * Sets a single additional email address to 'cc'.
145
-     *
146
-     * @param $email
147
-     * @return mixed
148
-     */
149
-    public function cc($email)
150
-    {
151
-        $this->ci->email->cc($email);
152
-
153
-        return $this;
154
-    }
155
-
156
-    //--------------------------------------------------------------------
157
-
158
-    /**
159
-     * Sets a single email address to 'bcc' to.
160
-     *
161
-     * @param $email
162
-     * @return mixed
163
-     */
164
-    public function bcc($email)
165
-    {
166
-        $this->ci->email->bcc($email);
167
-
168
-        return $this;
169
-    }
170
-
171
-    //--------------------------------------------------------------------
172
-
173
-    /**
174
-     * Sets the reply to address.
175
-     *
176
-     * @param $email
177
-     * @return mixed
178
-     */
179
-    public function reply_to($email, $name=null)
180
-    {
181
-        $this->ci->email->reply_to($email, $name);
182
-    }
183
-
184
-    //--------------------------------------------------------------------
185
-
186
-    /**
187
-     * Sets the subject line of the email.
188
-     *
189
-     * @param $subject
190
-     * @return mixed
191
-     */
192
-    public function subject($subject)
193
-    {
194
-        $this->ci->email->subject($subject);
195
-
196
-        return $this;
197
-    }
198
-
199
-    //--------------------------------------------------------------------
200
-
201
-    /**
202
-     * Sets the HTML portion of the email address. Optional.
203
-     *
204
-     * @param $message
205
-     * @return mixed
206
-     */
207
-    public function html_message($message)
208
-    {
209
-        $this->ci->email->message($message);
210
-
211
-        $this->format = 'html';
212
-
213
-        return $this;
214
-    }
215
-
216
-    //--------------------------------------------------------------------
217
-
218
-    /**
219
-     * Sets the text portion of the email address. Optional.
220
-     *
221
-     * @param $message
222
-     * @return mixed
223
-     */
224
-    public function text_message($message)
225
-    {
226
-        $this->ci->email->set_alt_message($message);
227
-
228
-        $this->format = 'text';
229
-
230
-        return $this;
231
-    }
232
-
233
-    //--------------------------------------------------------------------
234
-
235
-    /**
236
-     * Sets the format to send the email in. Either 'html' or 'text'.
237
-     *
238
-     * @param $format
239
-     * @return mixed
240
-     */
241
-    public function format($format)
242
-    {
243
-        $this->format = $format;
244
-
245
-        return $this;
246
-    }
247
-
248
-    //--------------------------------------------------------------------
249
-    /**
250
-     * Resets the state to blank, ready for a new email. Useful when
251
-     * sending emails in a loop and you need to make sure that the
252
-     * email is reset.
253
-     *
254
-     * @param bool $clear_attachments
255
-     * @return mixed
256
-     */
257
-    public function reset($clear_attachments=true)
258
-    {
259
-        $this->ci->email->clear($clear_attachments);
260
-
261
-        return $this;
262
-    }
263
-
264
-    //--------------------------------------------------------------------
43
+	protected $ci = null;
44
+
45
+	protected $format = 'html';
46
+
47
+	//--------------------------------------------------------------------
48
+
49
+	public function __construct()
50
+	{
51
+		$this->ci =& get_instance();
52
+
53
+		$this->ci->load->library('email');
54
+	}
55
+
56
+	//--------------------------------------------------------------------
57
+
58
+
59
+	/**
60
+	 * Does the actual delivery of a message.
61
+	 *
62
+	 * @param bool  $clear_after    If TRUE, will reset the class after sending.
63
+	 *
64
+	 * @return mixed
65
+	 */
66
+	public function send($clear_after=true)
67
+	{
68
+		$this->ci->email->mailtype = $this->format;
69
+
70
+		$result = $this->ci->email->send(false);
71
+
72
+		return $result;
73
+	}
74
+
75
+	//--------------------------------------------------------------------
76
+
77
+	/**
78
+	 * Adds an attachment to the current email that is being built.
79
+	 *
80
+	 * @param string    $filename
81
+	 * @param string    $disposition    like 'inline'. Default is 'attachment'
82
+	 * @param string    $newname        If you'd like to rename the file for delivery
83
+	 * @param string    $mime           Custom defined mime type.
84
+	 */
85
+	public function attach($filename, $disposition=null, $newname=null, $mime=null)
86
+	{
87
+		$this->ci->email->attach($filename, $disposition, $newname, $mime);
88
+	}
89
+
90
+	//--------------------------------------------------------------------
91
+
92
+	/**
93
+	 * Sets a header value for the email. Not every service will provide this.
94
+	 *
95
+	 * @param $field
96
+	 * @param $value
97
+	 * @return mixed
98
+	 */
99
+	public function setHeader($field, $value)
100
+	{
101
+		$this->ci->email->set_header($field, $value);
102
+
103
+		return $this;
104
+	}
105
+
106
+	//--------------------------------------------------------------------
107
+
108
+	//--------------------------------------------------------------------
109
+	// Options
110
+	//--------------------------------------------------------------------
111
+
112
+	/**
113
+	 * Sets the email address to send the email to.
114
+	 *
115
+	 * @param $email
116
+	 * @return mixed
117
+	 */
118
+	public function to($email)
119
+	{
120
+		$this->ci->email->to($email);
121
+
122
+		return $this;
123
+	}
124
+
125
+	//--------------------------------------------------------------------
126
+
127
+	/**
128
+	 * Sets who the email is coming from.
129
+	 *
130
+	 * @param $email
131
+	 * @param null $name
132
+	 * @return mixed
133
+	 */
134
+	public function from($email, $name=null)
135
+	{
136
+		$this->ci->email->from($email, $name);
137
+
138
+		return $this;
139
+	}
140
+
141
+	//--------------------------------------------------------------------
142
+
143
+	/**
144
+	 * Sets a single additional email address to 'cc'.
145
+	 *
146
+	 * @param $email
147
+	 * @return mixed
148
+	 */
149
+	public function cc($email)
150
+	{
151
+		$this->ci->email->cc($email);
152
+
153
+		return $this;
154
+	}
155
+
156
+	//--------------------------------------------------------------------
157
+
158
+	/**
159
+	 * Sets a single email address to 'bcc' to.
160
+	 *
161
+	 * @param $email
162
+	 * @return mixed
163
+	 */
164
+	public function bcc($email)
165
+	{
166
+		$this->ci->email->bcc($email);
167
+
168
+		return $this;
169
+	}
170
+
171
+	//--------------------------------------------------------------------
172
+
173
+	/**
174
+	 * Sets the reply to address.
175
+	 *
176
+	 * @param $email
177
+	 * @return mixed
178
+	 */
179
+	public function reply_to($email, $name=null)
180
+	{
181
+		$this->ci->email->reply_to($email, $name);
182
+	}
183
+
184
+	//--------------------------------------------------------------------
185
+
186
+	/**
187
+	 * Sets the subject line of the email.
188
+	 *
189
+	 * @param $subject
190
+	 * @return mixed
191
+	 */
192
+	public function subject($subject)
193
+	{
194
+		$this->ci->email->subject($subject);
195
+
196
+		return $this;
197
+	}
198
+
199
+	//--------------------------------------------------------------------
200
+
201
+	/**
202
+	 * Sets the HTML portion of the email address. Optional.
203
+	 *
204
+	 * @param $message
205
+	 * @return mixed
206
+	 */
207
+	public function html_message($message)
208
+	{
209
+		$this->ci->email->message($message);
210
+
211
+		$this->format = 'html';
212
+
213
+		return $this;
214
+	}
215
+
216
+	//--------------------------------------------------------------------
217
+
218
+	/**
219
+	 * Sets the text portion of the email address. Optional.
220
+	 *
221
+	 * @param $message
222
+	 * @return mixed
223
+	 */
224
+	public function text_message($message)
225
+	{
226
+		$this->ci->email->set_alt_message($message);
227
+
228
+		$this->format = 'text';
229
+
230
+		return $this;
231
+	}
232
+
233
+	//--------------------------------------------------------------------
234
+
235
+	/**
236
+	 * Sets the format to send the email in. Either 'html' or 'text'.
237
+	 *
238
+	 * @param $format
239
+	 * @return mixed
240
+	 */
241
+	public function format($format)
242
+	{
243
+		$this->format = $format;
244
+
245
+		return $this;
246
+	}
247
+
248
+	//--------------------------------------------------------------------
249
+	/**
250
+	 * Resets the state to blank, ready for a new email. Useful when
251
+	 * sending emails in a loop and you need to make sure that the
252
+	 * email is reset.
253
+	 *
254
+	 * @param bool $clear_attachments
255
+	 * @return mixed
256
+	 */
257
+	public function reset($clear_attachments=true)
258
+	{
259
+		$this->ci->email->clear($clear_attachments);
260
+
261
+		return $this;
262
+	}
263
+
264
+	//--------------------------------------------------------------------
265 265
 }
Please login to merge, or discard this patch.
myth/Mail/LogMailService.php 1 patch
Indentation   +314 added lines, -314 removed lines patch added patch discarded remove patch
@@ -1,34 +1,34 @@  discard block
 block discarded – undo
1 1
 <?php namespace Myth\Mail;
2 2
 /**
3
- * Sprint
4
- *
5
- * A set of power tools to enhance the CodeIgniter framework and provide consistent workflow.
6
- *
7
- * Permission is hereby granted, free of charge, to any person obtaining a copy
8
- * of this software and associated documentation files (the "Software"), to deal
9
- * in the Software without restriction, including without limitation the rights
10
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
- * copies of the Software, and to permit persons to whom the Software is
12
- * furnished to do so, subject to the following conditions:
13
- *
14
- * The above copyright notice and this permission notice shall be included in
15
- * all copies or substantial portions of the Software.
16
- *
17
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
- * THE SOFTWARE.
24
- *
25
- * @package     Sprint
26
- * @author      Lonnie Ezell
27
- * @copyright   Copyright 2014-2015, New Myth Media, LLC (http://newmythmedia.com)
28
- * @license     http://opensource.org/licenses/MIT  (MIT)
29
- * @link        http://sprintphp.com
30
- * @since       Version 1.0
31
- */
3
+	 * Sprint
4
+	 *
5
+	 * A set of power tools to enhance the CodeIgniter framework and provide consistent workflow.
6
+	 *
7
+	 * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+	 * of this software and associated documentation files (the "Software"), to deal
9
+	 * in the Software without restriction, including without limitation the rights
10
+	 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+	 * copies of the Software, and to permit persons to whom the Software is
12
+	 * furnished to do so, subject to the following conditions:
13
+	 *
14
+	 * The above copyright notice and this permission notice shall be included in
15
+	 * all copies or substantial portions of the Software.
16
+	 *
17
+	 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+	 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+	 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+	 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+	 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+	 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
+	 * THE SOFTWARE.
24
+	 *
25
+	 * @package     Sprint
26
+	 * @author      Lonnie Ezell
27
+	 * @copyright   Copyright 2014-2015, New Myth Media, LLC (http://newmythmedia.com)
28
+	 * @license     http://opensource.org/licenses/MIT  (MIT)
29
+	 * @link        http://sprintphp.com
30
+	 * @since       Version 1.0
31
+	 */
32 32
 
33 33
 /**
34 34
  * Class LogMailService
@@ -40,289 +40,289 @@  discard block
 block discarded – undo
40 40
  */
41 41
 class LogMailService implements MailServiceInterface {
42 42
 
43
-    protected $ci = null;
44
-
45
-    protected $format = 'html';
46
-    protected $headers = [];
47
-    protected $subject = null;
48
-
49
-    protected $html_message = null;
50
-    protected $text_message = null;
51
-
52
-    //--------------------------------------------------------------------
53
-
54
-    public function __construct()
55
-    {
56
-        $this->ci =& get_instance();
57
-
58
-        $this->ci->load->library('email');
59
-    }
60
-
61
-    //--------------------------------------------------------------------
62
-
63
-
64
-    /**
65
-     * Does the actual delivery of a message. In this case, though, we simply
66
-     * write the html and text files out to the log folder/emails.
67
-     *
68
-     * The filename format is: yyyymmddhhiiss_email.{format}
69
-     *
70
-     * @param bool  $clear_after    If TRUE, will reset the class after sending.
71
-     *
72
-     * @return mixed
73
-     */
74
-    public function send($clear_after=true)
75
-    {
76
-
77
-        // Ensure we have enough data
78
-        if (empty($this->to) || empty($this->subject) ||
79
-            (empty($this->html_message) && empty($this->text_message))
80
-        )
81
-        {
82
-            throw new \RuntimeException( lang('mail.invalid_log_data') );
83
-        }
84
-
85
-        $symbols = ['#', '%', '&', '{', '}', '\\', '/', '<', '>', '*', '?', ' ', '$', '!', '\'', '"', ':', '@', '+', '`', '='];
86
-
87
-        $email = str_replace($symbols, '.', strtolower($this->to) );
88
-
89
-        $filename = date('YmdHis_'). $email;
90
-
91
-        // Ensure the emails folder exists in the log folder.
92
-        $path = config_item('log_path');
93
-        $path = ! empty( $path ) ? $path : APPPATH .'logs/';
94
-        $path = rtrim($path, '/ ') .'/email/';
95
-
96
-        if (! is_dir($path))
97
-        {
98
-            mkdir($path, 0777, true);
99
-        }
100
-
101
-        get_instance()->load->helper('file');
102
-
103
-        // Write our HTML file out
104
-        if (! empty($this->html_message) && ! write_file( $path . $filename . '.html', $this->html_message ) )
105
-        {
106
-            throw new \RuntimeException( sprintf( lang('mail.error_html_log'), $path, $filename) );
107
-        }
108
-
109
-        // Write our TEXT file out
110
-        if (! empty($this->text_message) && ! write_file( $path . $filename . '.txt', $this->text_message ) )
111
-        {
112
-            throw new \RuntimeException( sprintf( lang('mail.error_text_log'), $path, $filename) );
113
-        }
114
-
115
-        return true;
116
-    }
117
-
118
-    //--------------------------------------------------------------------
119
-
120
-    /**
121
-     * Adds an attachment to the current email that is being built.
122
-     *
123
-     * @param string    $filename
124
-     * @param string    $disposition    like 'inline'. Default is 'attachment'
125
-     * @param string    $newname        If you'd like to rename the file for delivery
126
-     * @param string    $mime           Custom defined mime type.
127
-     */
128
-    public function attach($filename, $disposition=null, $newname=null, $mime=null)
129
-    {
130
-        return;
131
-    }
132
-
133
-    //--------------------------------------------------------------------
134
-
135
-    /**
136
-     * Sets a header value for the email. Not every service will provide this.
137
-     *
138
-     * @param $field
139
-     * @param $value
140
-     * @return mixed
141
-     */
142
-    public function setHeader($field, $value)
143
-    {
144
-        $this->headers[$field] = $value;
145
-
146
-        return $this;
147
-    }
148
-
149
-    //--------------------------------------------------------------------
150
-
151
-    //--------------------------------------------------------------------
152
-    // Options
153
-    //--------------------------------------------------------------------
154
-
155
-    /**
156
-     * Sets the email address to send the email to.
157
-     *
158
-     * @param $email
159
-     * @return mixed
160
-     */
161
-    public function to($email)
162
-    {
163
-        $this->to = $email;
164
-
165
-        return $this;
166
-    }
167
-
168
-    //--------------------------------------------------------------------
169
-
170
-    /**
171
-     * Sets who the email is coming from.
172
-     *
173
-     * @param $email
174
-     * @param null $name
175
-     * @return mixed
176
-     */
177
-    public function from($email, $name=null)
178
-    {
179
-        if (! empty($name))
180
-        {
181
-            $this->from = [$email, $name];
182
-        }
183
-        else
184
-        {
185
-            $this->from = $email;
186
-        }
187
-
188
-        return $this;
189
-    }
190
-
191
-    //--------------------------------------------------------------------
192
-
193
-    /**
194
-     * Sets a single additional email address to 'cc'.
195
-     *
196
-     * @param $email
197
-     * @return mixed
198
-     */
199
-    public function cc($email)
200
-    {
201
-        $this->cc = $email;
202
-
203
-        return $this;
204
-    }
205
-
206
-    //--------------------------------------------------------------------
207
-
208
-    /**
209
-     * Sets a single email address to 'bcc' to.
210
-     *
211
-     * @param $email
212
-     * @return mixed
213
-     */
214
-    public function bcc($email)
215
-    {
216
-        $this->bcc = $email;
217
-
218
-        return $this;
219
-    }
220
-
221
-    //--------------------------------------------------------------------
222
-
223
-    /**
224
-     * Sets the reply to address.
225
-     *
226
-     * @param $email
227
-     * @return mixed
228
-     */
229
-    public function reply_to($email, $name=null)
230
-    {
231
-        if (! empty($name))
232
-        {
233
-            $this->reply_to = [$email, $name];
234
-        }
235
-        else
236
-        {
237
-            $this->reply_to = $email;
238
-        }
239
-
240
-        return $this;
241
-    }
242
-
243
-    //--------------------------------------------------------------------
244
-
245
-    /**
246
-     * Sets the subject line of the email.
247
-     *
248
-     * @param $subject
249
-     * @return mixed
250
-     */
251
-    public function subject($subject)
252
-    {
253
-        $this->subject = $subject;
254
-
255
-        return $this;
256
-    }
257
-
258
-    //--------------------------------------------------------------------
259
-
260
-    /**
261
-     * Sets the HTML portion of the email address. Optional.
262
-     *
263
-     * @param $message
264
-     * @return mixed
265
-     */
266
-    public function html_message($message)
267
-    {
268
-        $this->html_message = $message;
269
-
270
-        return $this;
271
-    }
272
-
273
-    //--------------------------------------------------------------------
274
-
275
-    /**
276
-     * Sets the text portion of the email address. Optional.
277
-     *
278
-     * @param $message
279
-     * @return mixed
280
-     */
281
-    public function text_message($message)
282
-    {
283
-        $this->text_message = $message;
284
-
285
-        return $this;
286
-    }
287
-
288
-    //--------------------------------------------------------------------
289
-
290
-    /**
291
-     * Sets the format to send the email in. Either 'html' or 'text'.
292
-     *
293
-     * @param $format
294
-     * @return mixed
295
-     */
296
-    public function format($format)
297
-    {
298
-        $this->format = $format;
299
-
300
-        return $this;
301
-    }
302
-
303
-    //--------------------------------------------------------------------
304
-    /**
305
-     * Resets the state to blank, ready for a new email. Useful when
306
-     * sending emails in a loop and you need to make sure that the
307
-     * email is reset.
308
-     *
309
-     * @param bool $clear_attachments
310
-     * @return mixed
311
-     */
312
-    public function reset($clear_attachments=true)
313
-    {
314
-        $this->to = null;
315
-        $this->from = null;
316
-        $this->reply_to = null;
317
-        $this->cc = null;
318
-        $this->bcc = null;
319
-        $this->subject = null;
320
-        $this->html_message = null;
321
-        $this->text_message = null;
322
-        $this->headers = [];
323
-
324
-        return $this;
325
-    }
326
-
327
-    //--------------------------------------------------------------------
43
+	protected $ci = null;
44
+
45
+	protected $format = 'html';
46
+	protected $headers = [];
47
+	protected $subject = null;
48
+
49
+	protected $html_message = null;
50
+	protected $text_message = null;
51
+
52
+	//--------------------------------------------------------------------
53
+
54
+	public function __construct()
55
+	{
56
+		$this->ci =& get_instance();
57
+
58
+		$this->ci->load->library('email');
59
+	}
60
+
61
+	//--------------------------------------------------------------------
62
+
63
+
64
+	/**
65
+	 * Does the actual delivery of a message. In this case, though, we simply
66
+	 * write the html and text files out to the log folder/emails.
67
+	 *
68
+	 * The filename format is: yyyymmddhhiiss_email.{format}
69
+	 *
70
+	 * @param bool  $clear_after    If TRUE, will reset the class after sending.
71
+	 *
72
+	 * @return mixed
73
+	 */
74
+	public function send($clear_after=true)
75
+	{
76
+
77
+		// Ensure we have enough data
78
+		if (empty($this->to) || empty($this->subject) ||
79
+			(empty($this->html_message) && empty($this->text_message))
80
+		)
81
+		{
82
+			throw new \RuntimeException( lang('mail.invalid_log_data') );
83
+		}
84
+
85
+		$symbols = ['#', '%', '&', '{', '}', '\\', '/', '<', '>', '*', '?', ' ', '$', '!', '\'', '"', ':', '@', '+', '`', '='];
86
+
87
+		$email = str_replace($symbols, '.', strtolower($this->to) );
88
+
89
+		$filename = date('YmdHis_'). $email;
90
+
91
+		// Ensure the emails folder exists in the log folder.
92
+		$path = config_item('log_path');
93
+		$path = ! empty( $path ) ? $path : APPPATH .'logs/';
94
+		$path = rtrim($path, '/ ') .'/email/';
95
+
96
+		if (! is_dir($path))
97
+		{
98
+			mkdir($path, 0777, true);
99
+		}
100
+
101
+		get_instance()->load->helper('file');
102
+
103
+		// Write our HTML file out
104
+		if (! empty($this->html_message) && ! write_file( $path . $filename . '.html', $this->html_message ) )
105
+		{
106
+			throw new \RuntimeException( sprintf( lang('mail.error_html_log'), $path, $filename) );
107
+		}
108
+
109
+		// Write our TEXT file out
110
+		if (! empty($this->text_message) && ! write_file( $path . $filename . '.txt', $this->text_message ) )
111
+		{
112
+			throw new \RuntimeException( sprintf( lang('mail.error_text_log'), $path, $filename) );
113
+		}
114
+
115
+		return true;
116
+	}
117
+
118
+	//--------------------------------------------------------------------
119
+
120
+	/**
121
+	 * Adds an attachment to the current email that is being built.
122
+	 *
123
+	 * @param string    $filename
124
+	 * @param string    $disposition    like 'inline'. Default is 'attachment'
125
+	 * @param string    $newname        If you'd like to rename the file for delivery
126
+	 * @param string    $mime           Custom defined mime type.
127
+	 */
128
+	public function attach($filename, $disposition=null, $newname=null, $mime=null)
129
+	{
130
+		return;
131
+	}
132
+
133
+	//--------------------------------------------------------------------
134
+
135
+	/**
136
+	 * Sets a header value for the email. Not every service will provide this.
137
+	 *
138
+	 * @param $field
139
+	 * @param $value
140
+	 * @return mixed
141
+	 */
142
+	public function setHeader($field, $value)
143
+	{
144
+		$this->headers[$field] = $value;
145
+
146
+		return $this;
147
+	}
148
+
149
+	//--------------------------------------------------------------------
150
+
151
+	//--------------------------------------------------------------------
152
+	// Options
153
+	//--------------------------------------------------------------------
154
+
155
+	/**
156
+	 * Sets the email address to send the email to.
157
+	 *
158
+	 * @param $email
159
+	 * @return mixed
160
+	 */
161
+	public function to($email)
162
+	{
163
+		$this->to = $email;
164
+
165
+		return $this;
166
+	}
167
+
168
+	//--------------------------------------------------------------------
169
+
170
+	/**
171
+	 * Sets who the email is coming from.
172
+	 *
173
+	 * @param $email
174
+	 * @param null $name
175
+	 * @return mixed
176
+	 */
177
+	public function from($email, $name=null)
178
+	{
179
+		if (! empty($name))
180
+		{
181
+			$this->from = [$email, $name];
182
+		}
183
+		else
184
+		{
185
+			$this->from = $email;
186
+		}
187
+
188
+		return $this;
189
+	}
190
+
191
+	//--------------------------------------------------------------------
192
+
193
+	/**
194
+	 * Sets a single additional email address to 'cc'.
195
+	 *
196
+	 * @param $email
197
+	 * @return mixed
198
+	 */
199
+	public function cc($email)
200
+	{
201
+		$this->cc = $email;
202
+
203
+		return $this;
204
+	}
205
+
206
+	//--------------------------------------------------------------------
207
+
208
+	/**
209
+	 * Sets a single email address to 'bcc' to.
210
+	 *
211
+	 * @param $email
212
+	 * @return mixed
213
+	 */
214
+	public function bcc($email)
215
+	{
216
+		$this->bcc = $email;
217
+
218
+		return $this;
219
+	}
220
+
221
+	//--------------------------------------------------------------------
222
+
223
+	/**
224
+	 * Sets the reply to address.
225
+	 *
226
+	 * @param $email
227
+	 * @return mixed
228
+	 */
229
+	public function reply_to($email, $name=null)
230
+	{
231
+		if (! empty($name))
232
+		{
233
+			$this->reply_to = [$email, $name];
234
+		}
235
+		else
236
+		{
237
+			$this->reply_to = $email;
238
+		}
239
+
240
+		return $this;
241
+	}
242
+
243
+	//--------------------------------------------------------------------
244
+
245
+	/**
246
+	 * Sets the subject line of the email.
247
+	 *
248
+	 * @param $subject
249
+	 * @return mixed
250
+	 */
251
+	public function subject($subject)
252
+	{
253
+		$this->subject = $subject;
254
+
255
+		return $this;
256
+	}
257
+
258
+	//--------------------------------------------------------------------
259
+
260
+	/**
261
+	 * Sets the HTML portion of the email address. Optional.
262
+	 *
263
+	 * @param $message
264
+	 * @return mixed
265
+	 */
266
+	public function html_message($message)
267
+	{
268
+		$this->html_message = $message;
269
+
270
+		return $this;
271
+	}
272
+
273
+	//--------------------------------------------------------------------
274
+
275
+	/**
276
+	 * Sets the text portion of the email address. Optional.
277
+	 *
278
+	 * @param $message
279
+	 * @return mixed
280
+	 */
281
+	public function text_message($message)
282
+	{
283
+		$this->text_message = $message;
284
+
285
+		return $this;
286
+	}
287
+
288
+	//--------------------------------------------------------------------
289
+
290
+	/**
291
+	 * Sets the format to send the email in. Either 'html' or 'text'.
292
+	 *
293
+	 * @param $format
294
+	 * @return mixed
295
+	 */
296
+	public function format($format)
297
+	{
298
+		$this->format = $format;
299
+
300
+		return $this;
301
+	}
302
+
303
+	//--------------------------------------------------------------------
304
+	/**
305
+	 * Resets the state to blank, ready for a new email. Useful when
306
+	 * sending emails in a loop and you need to make sure that the
307
+	 * email is reset.
308
+	 *
309
+	 * @param bool $clear_attachments
310
+	 * @return mixed
311
+	 */
312
+	public function reset($clear_attachments=true)
313
+	{
314
+		$this->to = null;
315
+		$this->from = null;
316
+		$this->reply_to = null;
317
+		$this->cc = null;
318
+		$this->bcc = null;
319
+		$this->subject = null;
320
+		$this->html_message = null;
321
+		$this->text_message = null;
322
+		$this->headers = [];
323
+
324
+		return $this;
325
+	}
326
+
327
+	//--------------------------------------------------------------------
328 328
 }
Please login to merge, or discard this patch.
myth/Mail/Mail.php 1 patch
Indentation   +165 added lines, -165 removed lines patch added patch discarded remove patch
@@ -1,172 +1,172 @@
 block discarded – undo
1 1
 <?php namespace Myth\Mail;
2 2
 /**
3
- * Sprint
4
- *
5
- * A set of power tools to enhance the CodeIgniter framework and provide consistent workflow.
6
- *
7
- * Permission is hereby granted, free of charge, to any person obtaining a copy
8
- * of this software and associated documentation files (the "Software"), to deal
9
- * in the Software without restriction, including without limitation the rights
10
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
- * copies of the Software, and to permit persons to whom the Software is
12
- * furnished to do so, subject to the following conditions:
13
- *
14
- * The above copyright notice and this permission notice shall be included in
15
- * all copies or substantial portions of the Software.
16
- *
17
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
- * THE SOFTWARE.
24
- *
25
- * @package     Sprint
26
- * @author      Lonnie Ezell
27
- * @copyright   Copyright 2014-2015, New Myth Media, LLC (http://newmythmedia.com)
28
- * @license     http://opensource.org/licenses/MIT  (MIT)
29
- * @link        http://sprintphp.com
30
- * @since       Version 1.0
31
- */
3
+	 * Sprint
4
+	 *
5
+	 * A set of power tools to enhance the CodeIgniter framework and provide consistent workflow.
6
+	 *
7
+	 * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+	 * of this software and associated documentation files (the "Software"), to deal
9
+	 * in the Software without restriction, including without limitation the rights
10
+	 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+	 * copies of the Software, and to permit persons to whom the Software is
12
+	 * furnished to do so, subject to the following conditions:
13
+	 *
14
+	 * The above copyright notice and this permission notice shall be included in
15
+	 * all copies or substantial portions of the Software.
16
+	 *
17
+	 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+	 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+	 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+	 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+	 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+	 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
+	 * THE SOFTWARE.
24
+	 *
25
+	 * @package     Sprint
26
+	 * @author      Lonnie Ezell
27
+	 * @copyright   Copyright 2014-2015, New Myth Media, LLC (http://newmythmedia.com)
28
+	 * @license     http://opensource.org/licenses/MIT  (MIT)
29
+	 * @link        http://sprintphp.com
30
+	 * @since       Version 1.0
31
+	 */
32 32
 
33 33
 class Mail {
34 34
 
35
-    /**
36
-     * Sends an email, using an existing Mailer, which can
37
-     * be found in application/mailers/. The mailer is the one responsible
38
-     * for determining whether the email will be sent immediately or queued
39
-     * to be sent later.
40
-     *
41
-     * The $mailer_name must include both the mailer name as well as the
42
-     * task, separated by a single colon:
43
-     *      'UserMailer:newUser'
44
-     *
45
-     * @param $mailer_name
46
-     * @param array $params
47
-     * @param array $options
48
-     * @return mixed
49
-     */
50
-    public static function deliver($mailer_name, $params=[], $options=[])
51
-    {
52
-        // Protect users from themselves here.
53
-        str_replace('::', ':', $mailer_name);
54
-
55
-        // Try to load our mailer class.
56
-        list($class, $method) = explode(':', $mailer_name);
57
-
58
-        if (! is_file(APPPATH .'mailers/'. $class .'.php'))
59
-        {
60
-            throw new \RuntimeException( sprintf( lang('mail.cant_find_mailer'), $class) );
61
-        }
62
-
63
-        require_once APPPATH .'mailers/'. $class .'.php';
64
-
65
-        if (! class_exists($class, false))
66
-        {
67
-            throw new \RuntimeException( sprintf( lang('errors.cant_instantiate'), $class) );
68
-        }
69
-
70
-        $mailer = new $class( $options );
71
-
72
-        if (! method_exists($mailer, $method))
73
-        {
74
-            throw new \BadMethodCallException( sprintf( lang('mail.invalid_mailer_method'), $class, $method) );
75
-        }
76
-
77
-        // try to deliver the mail, but don't send back the contents
78
-        // since we don't want to force the mailers to return anything.
79
-        if (call_user_func_array([$mailer, $method], $params) )
80
-        {
81
-            return true;
82
-        }
83
-
84
-        return false;
85
-    }
86
-
87
-    //--------------------------------------------------------------------
88
-
89
-    /**
90
-     * Adds an item to the email queue to be sent out next time.
91
-     *
92
-     * @param string $mailer_name
93
-     * @param array $params
94
-     * @param array $options
95
-     * @param \Myth\Mail\Queue $queue
96
-     *
97
-     * @return mixed
98
-     */
99
-    public static function queue($mailer_name, $params=[], $options=[], &$queue=null)
100
-    {
101
-        $data = [
102
-            'mailer'    => $mailer_name,
103
-            'params'    => serialize($params),
104
-            'options'   => serialize($options)
105
-        ];
106
-
107
-        if (empty($queue))
108
-        {
109
-            $queue = new \Myth\Mail\Queue();
110
-        }
111
-
112
-        return $queue->insert($data);
113
-    }
114
-
115
-    //--------------------------------------------------------------------
116
-
117
-    /**
118
-     * Processes the Email queue sending out emails in chunks.
119
-     * Typically used in a cronjob to send out all queued emails.
120
-     *
121
-     * @param int $chunk_size   // How many emails to send per batch.
122
-     * @return string           // The output of the cronjob...
123
-     */
124
-    public static function process($chunk_size=50, &$db=null)
125
-    {
126
-        if (empty($db))
127
-        {
128
-            $db = new \Myth\Mail\Queue();
129
-        }
130
-
131
-        // Grab our batch of emails to process
132
-        $queue = $db->find_many_by('sent', 0);
133
-
134
-        if (! $queue)
135
-        {
136
-            // We didn't have an error, we simply
137
-            // didn't have anything to do.
138
-            return true;
139
-        }
140
-
141
-        $output = 'Started processing email Queue at '. date('Y-m-d H:i:s') .".\n\n";
142
-
143
-        foreach ($queue as $item)
144
-        {
145
-            try {
146
-                if (! Mail::deliver($item->mailer, unserialize($item->params), unserialize($item->options))) {
147
-                    $output .= '[FAILED] ';
148
-                } else {
149
-                    $data = [
150
-                        'sent'    => 1,
151
-                        'sent_on' => date('Y-m-d H:i:s')
152
-                    ];
153
-
154
-                    $db->update($item->id, $data);
155
-                }
156
-
157
-                $output .= "ID: {$item->id}, Mailer: {$item->mailer}. \n";
158
-            }
159
-            catch (\Exception $e)
160
-            {
161
-                $output .= "[EXCEPTION] ". $e->getMessage() ."\n";
162
-            }
163
-        }
164
-
165
-        $output .= "Done processing email Queue at ". date('H:i:s') .".\n";
166
-
167
-        return $output;
168
-    }
169
-
170
-    //--------------------------------------------------------------------
35
+	/**
36
+	 * Sends an email, using an existing Mailer, which can
37
+	 * be found in application/mailers/. The mailer is the one responsible
38
+	 * for determining whether the email will be sent immediately or queued
39
+	 * to be sent later.
40
+	 *
41
+	 * The $mailer_name must include both the mailer name as well as the
42
+	 * task, separated by a single colon:
43
+	 *      'UserMailer:newUser'
44
+	 *
45
+	 * @param $mailer_name
46
+	 * @param array $params
47
+	 * @param array $options
48
+	 * @return mixed
49
+	 */
50
+	public static function deliver($mailer_name, $params=[], $options=[])
51
+	{
52
+		// Protect users from themselves here.
53
+		str_replace('::', ':', $mailer_name);
54
+
55
+		// Try to load our mailer class.
56
+		list($class, $method) = explode(':', $mailer_name);
57
+
58
+		if (! is_file(APPPATH .'mailers/'. $class .'.php'))
59
+		{
60
+			throw new \RuntimeException( sprintf( lang('mail.cant_find_mailer'), $class) );
61
+		}
62
+
63
+		require_once APPPATH .'mailers/'. $class .'.php';
64
+
65
+		if (! class_exists($class, false))
66
+		{
67
+			throw new \RuntimeException( sprintf( lang('errors.cant_instantiate'), $class) );
68
+		}
69
+
70
+		$mailer = new $class( $options );
71
+
72
+		if (! method_exists($mailer, $method))
73
+		{
74
+			throw new \BadMethodCallException( sprintf( lang('mail.invalid_mailer_method'), $class, $method) );
75
+		}
76
+
77
+		// try to deliver the mail, but don't send back the contents
78
+		// since we don't want to force the mailers to return anything.
79
+		if (call_user_func_array([$mailer, $method], $params) )
80
+		{
81
+			return true;
82
+		}
83
+
84
+		return false;
85
+	}
86
+
87
+	//--------------------------------------------------------------------
88
+
89
+	/**
90
+	 * Adds an item to the email queue to be sent out next time.
91
+	 *
92
+	 * @param string $mailer_name
93
+	 * @param array $params
94
+	 * @param array $options
95
+	 * @param \Myth\Mail\Queue $queue
96
+	 *
97
+	 * @return mixed
98
+	 */
99
+	public static function queue($mailer_name, $params=[], $options=[], &$queue=null)
100
+	{
101
+		$data = [
102
+			'mailer'    => $mailer_name,
103
+			'params'    => serialize($params),
104
+			'options'   => serialize($options)
105
+		];
106
+
107
+		if (empty($queue))
108
+		{
109
+			$queue = new \Myth\Mail\Queue();
110
+		}
111
+
112
+		return $queue->insert($data);
113
+	}
114
+
115
+	//--------------------------------------------------------------------
116
+
117
+	/**
118
+	 * Processes the Email queue sending out emails in chunks.
119
+	 * Typically used in a cronjob to send out all queued emails.
120
+	 *
121
+	 * @param int $chunk_size   // How many emails to send per batch.
122
+	 * @return string           // The output of the cronjob...
123
+	 */
124
+	public static function process($chunk_size=50, &$db=null)
125
+	{
126
+		if (empty($db))
127
+		{
128
+			$db = new \Myth\Mail\Queue();
129
+		}
130
+
131
+		// Grab our batch of emails to process
132
+		$queue = $db->find_many_by('sent', 0);
133
+
134
+		if (! $queue)
135
+		{
136
+			// We didn't have an error, we simply
137
+			// didn't have anything to do.
138
+			return true;
139
+		}
140
+
141
+		$output = 'Started processing email Queue at '. date('Y-m-d H:i:s') .".\n\n";
142
+
143
+		foreach ($queue as $item)
144
+		{
145
+			try {
146
+				if (! Mail::deliver($item->mailer, unserialize($item->params), unserialize($item->options))) {
147
+					$output .= '[FAILED] ';
148
+				} else {
149
+					$data = [
150
+						'sent'    => 1,
151
+						'sent_on' => date('Y-m-d H:i:s')
152
+					];
153
+
154
+					$db->update($item->id, $data);
155
+				}
156
+
157
+				$output .= "ID: {$item->id}, Mailer: {$item->mailer}. \n";
158
+			}
159
+			catch (\Exception $e)
160
+			{
161
+				$output .= "[EXCEPTION] ". $e->getMessage() ."\n";
162
+			}
163
+		}
164
+
165
+		$output .= "Done processing email Queue at ". date('H:i:s') .".\n";
166
+
167
+		return $output;
168
+	}
169
+
170
+	//--------------------------------------------------------------------
171 171
 
172 172
 }
Please login to merge, or discard this patch.
myth/Mail/MailServiceInterface.php 1 patch
Indentation   +140 added lines, -140 removed lines patch added patch discarded remove patch
@@ -42,145 +42,145 @@
 block discarded – undo
42 42
  */
43 43
 interface MailServiceInterface {
44 44
 
45
-    /**
46
-     * Does the actual delivery of a message.
47
-     *
48
-     * @param bool  $clear_after    If TRUE, will reset the class after sending.
49
-     *
50
-     * @return mixed
51
-     */
52
-    public function send($clear_after=true);
53
-
54
-    //--------------------------------------------------------------------
55
-
56
-    /**
57
-     * Adds an attachment to the current email that is being built.
58
-     *
59
-     * @param string    $filename
60
-     * @param string    $disposition    like 'inline'. Default is 'attachment'
61
-     * @param string    $newname        If you'd like to rename the file for delivery
62
-     * @param string    $mime           Custom defined mime type.
63
-     */
64
-    public function attach($filename, $disposition=null, $newname=null, $mime=null);
65
-
66
-    //--------------------------------------------------------------------
67
-
68
-    /**
69
-     * Sets a header value for the email. Not every service will provide this.
70
-     *
71
-     * @param $field
72
-     * @param $value
73
-     * @return mixed
74
-     */
75
-    public function setHeader($field, $value);
76
-
77
-    //--------------------------------------------------------------------
78
-
79
-    //--------------------------------------------------------------------
80
-    // Options
81
-    //--------------------------------------------------------------------
82
-
83
-    /**
84
-     * Sets the email address to send the email to.
85
-     *
86
-     * @param $email
87
-     * @return mixed
88
-     */
89
-    public function to($email);
45
+	/**
46
+	 * Does the actual delivery of a message.
47
+	 *
48
+	 * @param bool  $clear_after    If TRUE, will reset the class after sending.
49
+	 *
50
+	 * @return mixed
51
+	 */
52
+	public function send($clear_after=true);
53
+
54
+	//--------------------------------------------------------------------
55
+
56
+	/**
57
+	 * Adds an attachment to the current email that is being built.
58
+	 *
59
+	 * @param string    $filename
60
+	 * @param string    $disposition    like 'inline'. Default is 'attachment'
61
+	 * @param string    $newname        If you'd like to rename the file for delivery
62
+	 * @param string    $mime           Custom defined mime type.
63
+	 */
64
+	public function attach($filename, $disposition=null, $newname=null, $mime=null);
65
+
66
+	//--------------------------------------------------------------------
67
+
68
+	/**
69
+	 * Sets a header value for the email. Not every service will provide this.
70
+	 *
71
+	 * @param $field
72
+	 * @param $value
73
+	 * @return mixed
74
+	 */
75
+	public function setHeader($field, $value);
76
+
77
+	//--------------------------------------------------------------------
78
+
79
+	//--------------------------------------------------------------------
80
+	// Options
81
+	//--------------------------------------------------------------------
82
+
83
+	/**
84
+	 * Sets the email address to send the email to.
85
+	 *
86
+	 * @param $email
87
+	 * @return mixed
88
+	 */
89
+	public function to($email);
90 90
     
91
-    //--------------------------------------------------------------------
92
-
93
-    /**
94
-     * Sets who the email is coming from.
95
-     *
96
-     * @param $email
97
-     * @param null $name
98
-     * @return mixed
99
-     */
100
-    public function from($email, $name=null);
101
-
102
-    //--------------------------------------------------------------------
103
-
104
-    /**
105
-     * Sets a single additional email address to 'cc'.
106
-     *
107
-     * @param $email
108
-     * @return mixed
109
-     */
110
-    public function cc($email);
111
-
112
-    //--------------------------------------------------------------------
113
-
114
-    /**
115
-     * Sets a single email address to 'bcc' to.
116
-     *
117
-     * @param $email
118
-     * @return mixed
119
-     */
120
-    public function bcc($email);
121
-
122
-    //--------------------------------------------------------------------
123
-
124
-    /**
125
-     * Sets the reply to address.
126
-     *
127
-     * @param $email
128
-     * @param $name
129
-     * @return mixed
130
-     */
131
-    public function reply_to($email, $name=null);
132
-
133
-    //--------------------------------------------------------------------
134
-
135
-    /**
136
-     * Sets the subject line of the email.
137
-     *
138
-     * @param $subject
139
-     * @return mixed
140
-     */
141
-    public function subject($subject);
142
-
143
-    //--------------------------------------------------------------------
144
-
145
-    /**
146
-     * Sets the HTML portion of the email address. Optional.
147
-     *
148
-     * @param $message
149
-     * @return mixed
150
-     */
151
-    public function html_message($message);
152
-
153
-    //--------------------------------------------------------------------
154
-
155
-    /**
156
-     * Sets the text portion of the email address. Optional.
157
-     *
158
-     * @param $message
159
-     * @return mixed
160
-     */
161
-    public function text_message($message);
162
-
163
-    //--------------------------------------------------------------------
164
-
165
-    /**
166
-     * Sets the format to send the email in. Either 'html' or 'text'.
167
-     *
168
-     * @param $format
169
-     * @return mixed
170
-     */
171
-    public function format($format);
172
-
173
-    //--------------------------------------------------------------------
174
-
175
-    /**
176
-     * Resets the state to blank, ready for a new email. Useful when
177
-     * sending emails in a loop and you need to make sure that the
178
-     * email is reset.
179
-     *
180
-     * @param bool $clear_attachments
181
-     * @return mixed
182
-     */
183
-    public function reset($clear_attachments=true);
184
-
185
-    //--------------------------------------------------------------------
91
+	//--------------------------------------------------------------------
92
+
93
+	/**
94
+	 * Sets who the email is coming from.
95
+	 *
96
+	 * @param $email
97
+	 * @param null $name
98
+	 * @return mixed
99
+	 */
100
+	public function from($email, $name=null);
101
+
102
+	//--------------------------------------------------------------------
103
+
104
+	/**
105
+	 * Sets a single additional email address to 'cc'.
106
+	 *
107
+	 * @param $email
108
+	 * @return mixed
109
+	 */
110
+	public function cc($email);
111
+
112
+	//--------------------------------------------------------------------
113
+
114
+	/**
115
+	 * Sets a single email address to 'bcc' to.
116
+	 *
117
+	 * @param $email
118
+	 * @return mixed
119
+	 */
120
+	public function bcc($email);
121
+
122
+	//--------------------------------------------------------------------
123
+
124
+	/**
125
+	 * Sets the reply to address.
126
+	 *
127
+	 * @param $email
128
+	 * @param $name
129
+	 * @return mixed
130
+	 */
131
+	public function reply_to($email, $name=null);
132
+
133
+	//--------------------------------------------------------------------
134
+
135
+	/**
136
+	 * Sets the subject line of the email.
137
+	 *
138
+	 * @param $subject
139
+	 * @return mixed
140
+	 */
141
+	public function subject($subject);
142
+
143
+	//--------------------------------------------------------------------
144
+
145
+	/**
146
+	 * Sets the HTML portion of the email address. Optional.
147
+	 *
148
+	 * @param $message
149
+	 * @return mixed
150
+	 */
151
+	public function html_message($message);
152
+
153
+	//--------------------------------------------------------------------
154
+
155
+	/**
156
+	 * Sets the text portion of the email address. Optional.
157
+	 *
158
+	 * @param $message
159
+	 * @return mixed
160
+	 */
161
+	public function text_message($message);
162
+
163
+	//--------------------------------------------------------------------
164
+
165
+	/**
166
+	 * Sets the format to send the email in. Either 'html' or 'text'.
167
+	 *
168
+	 * @param $format
169
+	 * @return mixed
170
+	 */
171
+	public function format($format);
172
+
173
+	//--------------------------------------------------------------------
174
+
175
+	/**
176
+	 * Resets the state to blank, ready for a new email. Useful when
177
+	 * sending emails in a loop and you need to make sure that the
178
+	 * email is reset.
179
+	 *
180
+	 * @param bool $clear_attachments
181
+	 * @return mixed
182
+	 */
183
+	public function reset($clear_attachments=true);
184
+
185
+	//--------------------------------------------------------------------
186 186
 }
Please login to merge, or discard this patch.
myth/Mail/Queue.php 1 patch
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -1,41 +1,41 @@
 block discarded – undo
1 1
 <?php namespace Myth\Mail;
2 2
 /**
3
- * Sprint
4
- *
5
- * A set of power tools to enhance the CodeIgniter framework and provide consistent workflow.
6
- *
7
- * Permission is hereby granted, free of charge, to any person obtaining a copy
8
- * of this software and associated documentation files (the "Software"), to deal
9
- * in the Software without restriction, including without limitation the rights
10
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
- * copies of the Software, and to permit persons to whom the Software is
12
- * furnished to do so, subject to the following conditions:
13
- *
14
- * The above copyright notice and this permission notice shall be included in
15
- * all copies or substantial portions of the Software.
16
- *
17
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
- * THE SOFTWARE.
24
- *
25
- * @package     Sprint
26
- * @author      Lonnie Ezell
27
- * @copyright   Copyright 2014-2015, New Myth Media, LLC (http://newmythmedia.com)
28
- * @license     http://opensource.org/licenses/MIT  (MIT)
29
- * @link        http://sprintphp.com
30
- * @since       Version 1.0
31
- */
3
+	 * Sprint
4
+	 *
5
+	 * A set of power tools to enhance the CodeIgniter framework and provide consistent workflow.
6
+	 *
7
+	 * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+	 * of this software and associated documentation files (the "Software"), to deal
9
+	 * in the Software without restriction, including without limitation the rights
10
+	 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+	 * copies of the Software, and to permit persons to whom the Software is
12
+	 * furnished to do so, subject to the following conditions:
13
+	 *
14
+	 * The above copyright notice and this permission notice shall be included in
15
+	 * all copies or substantial portions of the Software.
16
+	 *
17
+	 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+	 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+	 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+	 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+	 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+	 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
+	 * THE SOFTWARE.
24
+	 *
25
+	 * @package     Sprint
26
+	 * @author      Lonnie Ezell
27
+	 * @copyright   Copyright 2014-2015, New Myth Media, LLC (http://newmythmedia.com)
28
+	 * @license     http://opensource.org/licenses/MIT  (MIT)
29
+	 * @link        http://sprintphp.com
30
+	 * @since       Version 1.0
31
+	 */
32 32
 
33 33
 use Myth\Models\CIDbModel;
34 34
 
35 35
 class Queue extends CIDbModel {
36 36
 
37
-    protected $table_name = 'mail_queue';
37
+	protected $table_name = 'mail_queue';
38 38
 
39
-    protected $set_created = false;
40
-    protected $set_modified = false;
39
+	protected $set_created = false;
40
+	protected $set_modified = false;
41 41
 }
Please login to merge, or discard this patch.
myth/Settings/ConfigStore.php 1 patch
Indentation   +138 added lines, -138 removed lines patch added patch discarded remove patch
@@ -49,143 +49,143 @@
 block discarded – undo
49 49
  */
50 50
 class ConfigStore implements SettingsStoreInterface {
51 51
 
52
-    protected $ci;
53
-
54
-    //--------------------------------------------------------------------
55
-
56
-    public function __construct( $ci=null )
57
-    {
58
-        if (is_object($ci))
59
-        {
60
-            $this->ci =& $ci;
61
-        }
62
-        else {
63
-            $this->ci =& get_instance();
64
-        }
65
-    }
66
-
67
-    //--------------------------------------------------------------------
68
-
69
-    /**
70
-     * Inserts/Replaces a single setting item.
71
-     *
72
-     * @param $key
73
-     * @param null $value
74
-     * @param string $group
75
-     */
76
-    public function save($key, $value=null, $group='app')
77
-    {
78
-        // Treat the 'app' group as our primary, un-sectioned
79
-        // config files.
80
-        if ($group != 'app')
81
-        {
82
-            return $this->ci->config->set_item($key, $value);
83
-        }
84
-
85
-        // Otherwise, we'll need to ensure a section exists
86
-        if (! isset($this->ci->config->config[$group]))
87
-        {
88
-            $this->ci->config->config[$group] = [];
89
-        }
90
-
91
-        $this->ci->config->config[$group][$key] = $value;
92
-    }
93
-
94
-    //--------------------------------------------------------------------
95
-
96
-    /**
97
-     * Retrieves a single item. If the config system doesn't have the
98
-     * value loaded, yet, it will attempt to load a config file matching
99
-     * the 'group' name and grab the value from that.
100
-     *
101
-     * @param $key
102
-     * @param string $group
103
-     * @return mixed
104
-     */
105
-    public function get($key, $group='application')
106
-    {
107
-        // First, see if CI already has this key loaded.
108
-        $result = $this->ci->config->item($key);
109
-
110
-        // This bit will fail when the actual value is NULL
111
-        // but should result in false hits infrequently.
112
-        if ($result !== null)
113
-        {
114
-            return $result;
115
-        }
116
-
117
-        // Try to load the 'group' file, then try to load a
118
-        // config file that matches the group name
119
-        $this->ci->load->config($group, false, true);
52
+	protected $ci;
53
+
54
+	//--------------------------------------------------------------------
55
+
56
+	public function __construct( $ci=null )
57
+	{
58
+		if (is_object($ci))
59
+		{
60
+			$this->ci =& $ci;
61
+		}
62
+		else {
63
+			$this->ci =& get_instance();
64
+		}
65
+	}
66
+
67
+	//--------------------------------------------------------------------
68
+
69
+	/**
70
+	 * Inserts/Replaces a single setting item.
71
+	 *
72
+	 * @param $key
73
+	 * @param null $value
74
+	 * @param string $group
75
+	 */
76
+	public function save($key, $value=null, $group='app')
77
+	{
78
+		// Treat the 'app' group as our primary, un-sectioned
79
+		// config files.
80
+		if ($group != 'app')
81
+		{
82
+			return $this->ci->config->set_item($key, $value);
83
+		}
84
+
85
+		// Otherwise, we'll need to ensure a section exists
86
+		if (! isset($this->ci->config->config[$group]))
87
+		{
88
+			$this->ci->config->config[$group] = [];
89
+		}
90
+
91
+		$this->ci->config->config[$group][$key] = $value;
92
+	}
93
+
94
+	//--------------------------------------------------------------------
95
+
96
+	/**
97
+	 * Retrieves a single item. If the config system doesn't have the
98
+	 * value loaded, yet, it will attempt to load a config file matching
99
+	 * the 'group' name and grab the value from that.
100
+	 *
101
+	 * @param $key
102
+	 * @param string $group
103
+	 * @return mixed
104
+	 */
105
+	public function get($key, $group='application')
106
+	{
107
+		// First, see if CI already has this key loaded.
108
+		$result = $this->ci->config->item($key);
109
+
110
+		// This bit will fail when the actual value is NULL
111
+		// but should result in false hits infrequently.
112
+		if ($result !== null)
113
+		{
114
+			return $result;
115
+		}
116
+
117
+		// Try to load the 'group' file, then try to load a
118
+		// config file that matches the group name
119
+		$this->ci->load->config($group, false, true);
120 120
         
121
-        $result = $this->ci->config->item($key);
122
-
123
-        return $result;
124
-    }
125
-
126
-    //--------------------------------------------------------------------
127
-
128
-    /**
129
-     * Deletes a single item.
130
-     *
131
-     * NOT supported by this store.
132
-     *
133
-     * @param $key
134
-     * @param $group
135
-     * @return mixed
136
-     */
137
-    public function delete($key, $group='app')
138
-    {
139
-        return false;
140
-    }
141
-
142
-    //--------------------------------------------------------------------
143
-
144
-    /**
145
-     * Searches the store for any items with $field = $value.
146
-     *
147
-     * Does not work.
148
-     *
149
-     * @param $field
150
-     * @param $value
151
-     * @return mixed
152
-     */
153
-    public function findBy($field, $value)
154
-    {
155
-        return false;
156
-    }
157
-
158
-    //--------------------------------------------------------------------
159
-
160
-    /**
161
-     * Retrieves all items in the store either globally or for a single group.
162
-     *
163
-     * @param string $group
164
-     * @return mixed
165
-     */
166
-    public function all($group=null)
167
-    {
168
-        if (empty($group))
169
-        {
170
-            return $this->ci->config->config;
171
-        }
172
-
173
-        // If we're a group, does the group already exists
174
-        // as a 'section' in the config array?
175
-        if (isset($this->ci->config->config[$group]))
176
-        {
177
-            return $this->ci->config->config[$group];
178
-        }
179
-
180
-        // Still here? Attempt to load the file into a section
181
-        // and try one last time.
182
-        if ($this->ci->load->config($group))
183
-        {
184
-            return $this->ci->config->config($group);
185
-        }
186
-
187
-        return null;
188
-    }
189
-
190
-    //--------------------------------------------------------------------
121
+		$result = $this->ci->config->item($key);
122
+
123
+		return $result;
124
+	}
125
+
126
+	//--------------------------------------------------------------------
127
+
128
+	/**
129
+	 * Deletes a single item.
130
+	 *
131
+	 * NOT supported by this store.
132
+	 *
133
+	 * @param $key
134
+	 * @param $group
135
+	 * @return mixed
136
+	 */
137
+	public function delete($key, $group='app')
138
+	{
139
+		return false;
140
+	}
141
+
142
+	//--------------------------------------------------------------------
143
+
144
+	/**
145
+	 * Searches the store for any items with $field = $value.
146
+	 *
147
+	 * Does not work.
148
+	 *
149
+	 * @param $field
150
+	 * @param $value
151
+	 * @return mixed
152
+	 */
153
+	public function findBy($field, $value)
154
+	{
155
+		return false;
156
+	}
157
+
158
+	//--------------------------------------------------------------------
159
+
160
+	/**
161
+	 * Retrieves all items in the store either globally or for a single group.
162
+	 *
163
+	 * @param string $group
164
+	 * @return mixed
165
+	 */
166
+	public function all($group=null)
167
+	{
168
+		if (empty($group))
169
+		{
170
+			return $this->ci->config->config;
171
+		}
172
+
173
+		// If we're a group, does the group already exists
174
+		// as a 'section' in the config array?
175
+		if (isset($this->ci->config->config[$group]))
176
+		{
177
+			return $this->ci->config->config[$group];
178
+		}
179
+
180
+		// Still here? Attempt to load the file into a section
181
+		// and try one last time.
182
+		if ($this->ci->load->config($group))
183
+		{
184
+			return $this->ci->config->config($group);
185
+		}
186
+
187
+		return null;
188
+	}
189
+
190
+	//--------------------------------------------------------------------
191 191
 }
Please login to merge, or discard this patch.
myth/Settings/DatabaseStore.php 1 patch
Indentation   +208 added lines, -208 removed lines patch added patch discarded remove patch
@@ -1,214 +1,214 @@
 block discarded – undo
1 1
 <?php namespace Myth\Settings;
2 2
 /**
3
- * Sprint
4
- *
5
- * A set of power tools to enhance the CodeIgniter framework and provide consistent workflow.
6
- *
7
- * Permission is hereby granted, free of charge, to any person obtaining a copy
8
- * of this software and associated documentation files (the "Software"), to deal
9
- * in the Software without restriction, including without limitation the rights
10
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
- * copies of the Software, and to permit persons to whom the Software is
12
- * furnished to do so, subject to the following conditions:
13
- *
14
- * The above copyright notice and this permission notice shall be included in
15
- * all copies or substantial portions of the Software.
16
- *
17
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
- * THE SOFTWARE.
24
- *
25
- * @package     Sprint
26
- * @author      Lonnie Ezell
27
- * @copyright   Copyright 2014-2015, New Myth Media, LLC (http://newmythmedia.com)
28
- * @license     http://opensource.org/licenses/MIT  (MIT)
29
- * @link        http://sprintphp.com
30
- * @since       Version 1.0
31
- */
3
+	 * Sprint
4
+	 *
5
+	 * A set of power tools to enhance the CodeIgniter framework and provide consistent workflow.
6
+	 *
7
+	 * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+	 * of this software and associated documentation files (the "Software"), to deal
9
+	 * in the Software without restriction, including without limitation the rights
10
+	 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+	 * copies of the Software, and to permit persons to whom the Software is
12
+	 * furnished to do so, subject to the following conditions:
13
+	 *
14
+	 * The above copyright notice and this permission notice shall be included in
15
+	 * all copies or substantial portions of the Software.
16
+	 *
17
+	 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+	 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+	 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+	 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+	 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+	 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
+	 * THE SOFTWARE.
24
+	 *
25
+	 * @package     Sprint
26
+	 * @author      Lonnie Ezell
27
+	 * @copyright   Copyright 2014-2015, New Myth Media, LLC (http://newmythmedia.com)
28
+	 * @license     http://opensource.org/licenses/MIT  (MIT)
29
+	 * @link        http://sprintphp.com
30
+	 * @since       Version 1.0
31
+	 */
32 32
 
33 33
 class DatabaseStore implements SettingsStoreInterface {
34 34
 
35
-    protected $ci;
36
-
37
-    protected $db;
38
-
39
-    //--------------------------------------------------------------------
40
-
41
-    public function __construct( $ci=null )
42
-    {
43
-        if (is_object($ci))
44
-        {
45
-            $this->ci =& $ci;
46
-        }
47
-        else {
48
-            $this->ci =& get_instance();
49
-        }
50
-
51
-        // Ensure that the database is loaded.
52
-        if (empty($this->ci->db))
53
-        {
54
-            $this->ci->load->database();
55
-        }
56
-    }
57
-
58
-    //--------------------------------------------------------------------
59
-
60
-    /**
61
-     * Inserts or Replaces an setting value.
62
-     *
63
-     * @param $key
64
-     * @param null $value
65
-     * @param string $group
66
-     * @return bool
67
-     */
68
-    public function save($key, $value=null, $group='app')
69
-    {
70
-        if (empty($this->ci->db) || ! is_object($this->ci->db))
71
-        {
72
-            return false;
73
-        }
74
-
75
-        $where = [
76
-            'name'  => $key,
77
-            'group' => $group
78
-        ];
79
-        $this->ci->db->delete('settings', $where);
80
-
81
-        if (is_array($value) || is_object($value))
82
-        {
83
-            $value = serialize($value);
84
-        }
85
-
86
-        $data = [
87
-            'name'  => $key,
88
-            'value' => $value,
89
-            'group' => $group
90
-        ];
91
-        return $this->ci->db->insert('settings', $data);
92
-    }
93
-
94
-    //--------------------------------------------------------------------
95
-
96
-    /**
97
-     * Retrieves a single item.
98
-     *
99
-     * @param $key
100
-     * @param string $group
101
-     * @return mixed
102
-     */
103
-    public function get($key, $group='app')
104
-    {
105
-        if (empty($this->ci->db) || ! is_object($this->ci->db))
106
-        {
107
-            return false;
108
-        }
109
-
110
-        $where = [
111
-            'name'  => $key,
112
-            'group' => $group
113
-        ];
114
-
115
-        $query = $this->ci->db->where($where)
116
-                              ->get('settings');
117
-
118
-        if (! $query->num_rows())
119
-        {
120
-            return false;
121
-        }
122
-
123
-        $value = $query->row()->value;
124
-
125
-        // Check to see if it needs to be unserialized
126
-        $data = @unserialize($value);   // We don't need to issue an E_NOTICE here...
127
-
128
-        // Check for a value of false or
129
-        if ($value === 'b:0;' || $data !== false)
130
-        {
131
-            $value = $data;
132
-        }
133
-
134
-        return $value;
135
-    }
136
-
137
-    //--------------------------------------------------------------------
138
-
139
-    /**
140
-     * Deletes a single item.
141
-     *
142
-     * @param $key
143
-     * @param $group
144
-     * @return mixed
145
-     */
146
-    public function delete($key, $group='app')
147
-    {
148
-        if (empty($this->ci->db) || ! is_object($this->ci->db))
149
-        {
150
-            return false;
151
-        }
152
-
153
-        $where = [
154
-            'name'  => $key,
155
-            'group' => $group
156
-        ];
157
-
158
-        return $this->ci->db->delete('settings', $where);
159
-    }
160
-
161
-    //--------------------------------------------------------------------
162
-
163
-    /**
164
-     * Searches the store for any items with $field = $value.
165
-     *
166
-     * @param $field
167
-     * @param $value
168
-     * @return mixed
169
-     */
170
-    public function findBy($field, $value)
171
-    {
172
-        if (empty($this->ci->db) || ! is_object($this->ci->db))
173
-        {
174
-            return false;
175
-        }
176
-
177
-        $query = $this->ci->db->where($field, $value)
178
-                              ->get('settings');
179
-
180
-        if (! $query->num_rows())
181
-        {
182
-            return false;
183
-        }
184
-
185
-        return $query->result_array();
186
-    }
187
-
188
-    //--------------------------------------------------------------------
189
-
190
-    /**
191
-     * Retrieves all items in the store either globally or for a single group.
192
-     *
193
-     * @param string $group
194
-     * @return mixed
195
-     */
196
-    public function all($group=null)
197
-    {
198
-        if (empty($this->ci->db) || ! is_object($this->ci->db))
199
-        {
200
-            return false;
201
-        }
202
-
203
-        $query = $this->ci->db->get('settings');
204
-
205
-        if (! $query->num_rows())
206
-        {
207
-            return false;
208
-        }
209
-
210
-        return $query->result_array();
211
-    }
212
-
213
-    //--------------------------------------------------------------------
35
+	protected $ci;
36
+
37
+	protected $db;
38
+
39
+	//--------------------------------------------------------------------
40
+
41
+	public function __construct( $ci=null )
42
+	{
43
+		if (is_object($ci))
44
+		{
45
+			$this->ci =& $ci;
46
+		}
47
+		else {
48
+			$this->ci =& get_instance();
49
+		}
50
+
51
+		// Ensure that the database is loaded.
52
+		if (empty($this->ci->db))
53
+		{
54
+			$this->ci->load->database();
55
+		}
56
+	}
57
+
58
+	//--------------------------------------------------------------------
59
+
60
+	/**
61
+	 * Inserts or Replaces an setting value.
62
+	 *
63
+	 * @param $key
64
+	 * @param null $value
65
+	 * @param string $group
66
+	 * @return bool
67
+	 */
68
+	public function save($key, $value=null, $group='app')
69
+	{
70
+		if (empty($this->ci->db) || ! is_object($this->ci->db))
71
+		{
72
+			return false;
73
+		}
74
+
75
+		$where = [
76
+			'name'  => $key,
77
+			'group' => $group
78
+		];
79
+		$this->ci->db->delete('settings', $where);
80
+
81
+		if (is_array($value) || is_object($value))
82
+		{
83
+			$value = serialize($value);
84
+		}
85
+
86
+		$data = [
87
+			'name'  => $key,
88
+			'value' => $value,
89
+			'group' => $group
90
+		];
91
+		return $this->ci->db->insert('settings', $data);
92
+	}
93
+
94
+	//--------------------------------------------------------------------
95
+
96
+	/**
97
+	 * Retrieves a single item.
98
+	 *
99
+	 * @param $key
100
+	 * @param string $group
101
+	 * @return mixed
102
+	 */
103
+	public function get($key, $group='app')
104
+	{
105
+		if (empty($this->ci->db) || ! is_object($this->ci->db))
106
+		{
107
+			return false;
108
+		}
109
+
110
+		$where = [
111
+			'name'  => $key,
112
+			'group' => $group
113
+		];
114
+
115
+		$query = $this->ci->db->where($where)
116
+							  ->get('settings');
117
+
118
+		if (! $query->num_rows())
119
+		{
120
+			return false;
121
+		}
122
+
123
+		$value = $query->row()->value;
124
+
125
+		// Check to see if it needs to be unserialized
126
+		$data = @unserialize($value);   // We don't need to issue an E_NOTICE here...
127
+
128
+		// Check for a value of false or
129
+		if ($value === 'b:0;' || $data !== false)
130
+		{
131
+			$value = $data;
132
+		}
133
+
134
+		return $value;
135
+	}
136
+
137
+	//--------------------------------------------------------------------
138
+
139
+	/**
140
+	 * Deletes a single item.
141
+	 *
142
+	 * @param $key
143
+	 * @param $group
144
+	 * @return mixed
145
+	 */
146
+	public function delete($key, $group='app')
147
+	{
148
+		if (empty($this->ci->db) || ! is_object($this->ci->db))
149
+		{
150
+			return false;
151
+		}
152
+
153
+		$where = [
154
+			'name'  => $key,
155
+			'group' => $group
156
+		];
157
+
158
+		return $this->ci->db->delete('settings', $where);
159
+	}
160
+
161
+	//--------------------------------------------------------------------
162
+
163
+	/**
164
+	 * Searches the store for any items with $field = $value.
165
+	 *
166
+	 * @param $field
167
+	 * @param $value
168
+	 * @return mixed
169
+	 */
170
+	public function findBy($field, $value)
171
+	{
172
+		if (empty($this->ci->db) || ! is_object($this->ci->db))
173
+		{
174
+			return false;
175
+		}
176
+
177
+		$query = $this->ci->db->where($field, $value)
178
+							  ->get('settings');
179
+
180
+		if (! $query->num_rows())
181
+		{
182
+			return false;
183
+		}
184
+
185
+		return $query->result_array();
186
+	}
187
+
188
+	//--------------------------------------------------------------------
189
+
190
+	/**
191
+	 * Retrieves all items in the store either globally or for a single group.
192
+	 *
193
+	 * @param string $group
194
+	 * @return mixed
195
+	 */
196
+	public function all($group=null)
197
+	{
198
+		if (empty($this->ci->db) || ! is_object($this->ci->db))
199
+		{
200
+			return false;
201
+		}
202
+
203
+		$query = $this->ci->db->get('settings');
204
+
205
+		if (! $query->num_rows())
206
+		{
207
+			return false;
208
+		}
209
+
210
+		return $query->result_array();
211
+	}
212
+
213
+	//--------------------------------------------------------------------
214 214
 }
Please login to merge, or discard this patch.
myth/Settings/Settings.php 1 patch
Indentation   +277 added lines, -277 removed lines patch added patch discarded remove patch
@@ -1,34 +1,34 @@  discard block
 block discarded – undo
1 1
 <?php namespace Myth\Settings;
2 2
 /**
3
- * Sprint
4
- *
5
- * A set of power tools to enhance the CodeIgniter framework and provide consistent workflow.
6
- *
7
- * Permission is hereby granted, free of charge, to any person obtaining a copy
8
- * of this software and associated documentation files (the "Software"), to deal
9
- * in the Software without restriction, including without limitation the rights
10
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
- * copies of the Software, and to permit persons to whom the Software is
12
- * furnished to do so, subject to the following conditions:
13
- *
14
- * The above copyright notice and this permission notice shall be included in
15
- * all copies or substantial portions of the Software.
16
- *
17
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
- * THE SOFTWARE.
24
- *
25
- * @package     Sprint
26
- * @author      Lonnie Ezell
27
- * @copyright   Copyright 2014-2015, New Myth Media, LLC (http://newmythmedia.com)
28
- * @license     http://opensource.org/licenses/MIT  (MIT)
29
- * @link        http://sprintphp.com
30
- * @since       Version 1.0
31
- */
3
+	 * Sprint
4
+	 *
5
+	 * A set of power tools to enhance the CodeIgniter framework and provide consistent workflow.
6
+	 *
7
+	 * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+	 * of this software and associated documentation files (the "Software"), to deal
9
+	 * in the Software without restriction, including without limitation the rights
10
+	 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+	 * copies of the Software, and to permit persons to whom the Software is
12
+	 * furnished to do so, subject to the following conditions:
13
+	 *
14
+	 * The above copyright notice and this permission notice shall be included in
15
+	 * all copies or substantial portions of the Software.
16
+	 *
17
+	 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+	 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+	 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+	 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+	 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+	 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
+	 * THE SOFTWARE.
24
+	 *
25
+	 * @package     Sprint
26
+	 * @author      Lonnie Ezell
27
+	 * @copyright   Copyright 2014-2015, New Myth Media, LLC (http://newmythmedia.com)
28
+	 * @license     http://opensource.org/licenses/MIT  (MIT)
29
+	 * @link        http://sprintphp.com
30
+	 * @since       Version 1.0
31
+	 */
32 32
 
33 33
 /**
34 34
  * Class Settings
@@ -40,253 +40,253 @@  discard block
 block discarded – undo
40 40
  */
41 41
 class Settings {
42 42
 
43
-    /**
44
-     * Holds instantiated data stores.
45
-     *
46
-     * @var array
47
-     */
48
-    protected static $stores = [];
49
-
50
-    protected static $default_store = '';
51
-
52
-    protected static $initialized = false;
53
-
54
-    //--------------------------------------------------------------------
55
-
56
-    /**
57
-     * Fires up instances of the datastores and gets us ready to roll.
58
-     */
59
-    public static function init()
60
-    {
61
-        if (self::$initialized === true)
62
-        {
63
-            return;
64
-        }
65
-
66
-        // Load up and instantiate our setting stores.
67
-        $user_stores = config_item('settings.stores');
68
-
69
-        if (is_array($user_stores))
70
-        {
71
-            foreach ($user_stores as $alias => $class)
72
-            {
73
-                self::$stores[ strtolower($alias) ] = new $class();
74
-            }
75
-        }
76
-
77
-        self::$default_store = config_item('settings.default_store');
78
-
79
-        if (empty(self::$stores[ self::$default_store ]))
80
-        {
81
-            show_error( lang('settings.bad_default') );
82
-        }
83
-    }
84
-
85
-    //--------------------------------------------------------------------
86
-
87
-    /**
88
-     * Inserts/Replaces a single setting item.
89
-     *
90
-     * @param $key
91
-     * @param null $value
92
-     * @param string $group
93
-     * @param string $store
94
-     */
95
-    public static function save($key, $value=null, $group='app', $store=null)
96
-    {
97
-        self::init();
98
-
99
-        if (empty($store) || empty(self::$stores[$store]))
100
-        {
101
-            // we've already determined that the default store exists
102
-            // in the init() method.
103
-            $store = self::$default_store;
104
-        }
105
-
106
-        return self::$stores[ $store ]->save($key, $value, $group);
107
-    }
108
-
109
-    //--------------------------------------------------------------------
110
-
111
-    /**
112
-     * Retrieves a single item. If not $store is specified, will loop
113
-     * through the stores in order until it finds it. If $store is
114
-     * specified, will only look within that store for it.
115
-     *
116
-     * @param $key
117
-     * @param string $group
118
-     * @param string $store
119
-     * @return mixed
120
-     */
121
-    public static function get($key, $group='app', $store=null)
122
-    {
123
-        self::init();
124
-
125
-        $group = strtolower($group);
126
-
127
-        // If the store is specified but doesn't exist, crap out
128
-        // so that they developer has a chance to fix it.
129
-        if (! is_null($store) && empty(self::$stores[$store]))
130
-        {
131
-            show_error( sprintf( lang('settings.cant_retrieve'), $store ) );
132
-        }
133
-
134
-        // If $store is set, get the value from that store only.
135
-        if (! empty($store))
136
-        {
137
-            return self::$stores[$store]->get($key, $group);
138
-        }
139
-
140
-        // Otherwise loop through each store until we find it
141
-        foreach (self::$stores as $s)
142
-        {
143
-            if ($found = $s->get($key, $group))
144
-            {
145
-                return $found;
146
-            }
147
-        }
148
-
149
-        // Still here... guess we didn't find anything, then...
150
-        return false;
151
-    }
152
-
153
-    //--------------------------------------------------------------------
154
-
155
-    /**
156
-     * Deletes a single item.
157
-     *
158
-     * @param $key
159
-     * @param $group
160
-     * @param $store
161
-     * @return mixed
162
-     */
163
-    public static function delete($key, $group='app', $store=null)
164
-    {
165
-        self::init();
166
-
167
-        $group = strtolower($group);
168
-
169
-        // If the store is specified but doesn't exist, crap out
170
-        // so that they developer has a chance to fix it.
171
-        if (! is_null($store) && empty(self::$stores[$store]))
172
-        {
173
-            show_error( sprintf( lang('settings.cant_retrieve'), $store ) );
174
-        }
175
-
176
-        // If $store is set, get the value from that store only.
177
-        if (! empty($store))
178
-        {
179
-            return self::$stores[$store]->delete($key, $group);
180
-        }
181
-
182
-        // Otherwise delete from the default store
183
-        return self::$stores[ self::$default_store ]->delete($key, $group);
184
-    }
185
-
186
-    //--------------------------------------------------------------------
187
-
188
-    /**
189
-     * Searches the store for any items with $field = $value.
190
-     *
191
-     * @param $field
192
-     * @param $value
193
-     * @return mixed
194
-     */
195
-    public static function findBy($field, $value)
196
-    {
197
-        self::init();
198
-
199
-        foreach (self::$stores as $s)
200
-        {
201
-            if ($found = $s->findBy($field, $value))
202
-            {
203
-                return $found;
204
-            }
205
-        }
206
-
207
-        return false;
208
-    }
209
-
210
-    //--------------------------------------------------------------------
211
-
212
-    /**
213
-     * Retrieves all items in the store either globally or for a single group.
214
-     *
215
-     * @param string $group
216
-     * @return mixed
217
-     */
218
-    public static function all($group=null, $store=null)
219
-    {
220
-        self::init();
221
-
222
-        $group = strtolower($group);
223
-
224
-        if (! empty($store))
225
-        {
226
-            return self::$stores[ $store ]->all($group);
227
-        }
228
-
229
-        // Otherwise combine the results from all stores
230
-        $results = [];
231
-
232
-        foreach (self::$stores as $s)
233
-        {
234
-            $found = $s->all($group);
235
-            if ($found)
236
-            {
237
-                $results = array_merge($results, (array)$found);
238
-            }
239
-        }
240
-
241
-        return $results;
242
-    }
243
-
244
-    //--------------------------------------------------------------------
245
-
246
-    /**
247
-     * Appends a new datastore the end of the curent stores.
248
-     *
249
-     * @param $alias
250
-     * @param $class
251
-     * @return bool
252
-     */
253
-    public static function addStore($alias, $class)
254
-    {
255
-        self::init();
256
-
257
-        if (class_exists($class))
258
-        {
259
-            self::$stores[ strtolower($alias) ] = new $class();
260
-            return true;
261
-        }
262
-
263
-        return false;
264
-    }
265
-
266
-    //--------------------------------------------------------------------
267
-
268
-    /**
269
-     * Removes a datastore from the list of stores currently available.
270
-     *
271
-     * @param $alias
272
-     * @return bool
273
-     */
274
-    public static function removeStore($alias)
275
-    {
276
-        self::init();
277
-
278
-        $alias = strtolower($alias);
279
-
280
-        if (empty(self::$stores[$alias]))
281
-        {
282
-            return false;
283
-        }
284
-
285
-        unset(self::$stores[$alias]);
286
-
287
-        return true;
288
-    }
289
-
290
-    //--------------------------------------------------------------------
43
+	/**
44
+	 * Holds instantiated data stores.
45
+	 *
46
+	 * @var array
47
+	 */
48
+	protected static $stores = [];
49
+
50
+	protected static $default_store = '';
51
+
52
+	protected static $initialized = false;
53
+
54
+	//--------------------------------------------------------------------
55
+
56
+	/**
57
+	 * Fires up instances of the datastores and gets us ready to roll.
58
+	 */
59
+	public static function init()
60
+	{
61
+		if (self::$initialized === true)
62
+		{
63
+			return;
64
+		}
65
+
66
+		// Load up and instantiate our setting stores.
67
+		$user_stores = config_item('settings.stores');
68
+
69
+		if (is_array($user_stores))
70
+		{
71
+			foreach ($user_stores as $alias => $class)
72
+			{
73
+				self::$stores[ strtolower($alias) ] = new $class();
74
+			}
75
+		}
76
+
77
+		self::$default_store = config_item('settings.default_store');
78
+
79
+		if (empty(self::$stores[ self::$default_store ]))
80
+		{
81
+			show_error( lang('settings.bad_default') );
82
+		}
83
+	}
84
+
85
+	//--------------------------------------------------------------------
86
+
87
+	/**
88
+	 * Inserts/Replaces a single setting item.
89
+	 *
90
+	 * @param $key
91
+	 * @param null $value
92
+	 * @param string $group
93
+	 * @param string $store
94
+	 */
95
+	public static function save($key, $value=null, $group='app', $store=null)
96
+	{
97
+		self::init();
98
+
99
+		if (empty($store) || empty(self::$stores[$store]))
100
+		{
101
+			// we've already determined that the default store exists
102
+			// in the init() method.
103
+			$store = self::$default_store;
104
+		}
105
+
106
+		return self::$stores[ $store ]->save($key, $value, $group);
107
+	}
108
+
109
+	//--------------------------------------------------------------------
110
+
111
+	/**
112
+	 * Retrieves a single item. If not $store is specified, will loop
113
+	 * through the stores in order until it finds it. If $store is
114
+	 * specified, will only look within that store for it.
115
+	 *
116
+	 * @param $key
117
+	 * @param string $group
118
+	 * @param string $store
119
+	 * @return mixed
120
+	 */
121
+	public static function get($key, $group='app', $store=null)
122
+	{
123
+		self::init();
124
+
125
+		$group = strtolower($group);
126
+
127
+		// If the store is specified but doesn't exist, crap out
128
+		// so that they developer has a chance to fix it.
129
+		if (! is_null($store) && empty(self::$stores[$store]))
130
+		{
131
+			show_error( sprintf( lang('settings.cant_retrieve'), $store ) );
132
+		}
133
+
134
+		// If $store is set, get the value from that store only.
135
+		if (! empty($store))
136
+		{
137
+			return self::$stores[$store]->get($key, $group);
138
+		}
139
+
140
+		// Otherwise loop through each store until we find it
141
+		foreach (self::$stores as $s)
142
+		{
143
+			if ($found = $s->get($key, $group))
144
+			{
145
+				return $found;
146
+			}
147
+		}
148
+
149
+		// Still here... guess we didn't find anything, then...
150
+		return false;
151
+	}
152
+
153
+	//--------------------------------------------------------------------
154
+
155
+	/**
156
+	 * Deletes a single item.
157
+	 *
158
+	 * @param $key
159
+	 * @param $group
160
+	 * @param $store
161
+	 * @return mixed
162
+	 */
163
+	public static function delete($key, $group='app', $store=null)
164
+	{
165
+		self::init();
166
+
167
+		$group = strtolower($group);
168
+
169
+		// If the store is specified but doesn't exist, crap out
170
+		// so that they developer has a chance to fix it.
171
+		if (! is_null($store) && empty(self::$stores[$store]))
172
+		{
173
+			show_error( sprintf( lang('settings.cant_retrieve'), $store ) );
174
+		}
175
+
176
+		// If $store is set, get the value from that store only.
177
+		if (! empty($store))
178
+		{
179
+			return self::$stores[$store]->delete($key, $group);
180
+		}
181
+
182
+		// Otherwise delete from the default store
183
+		return self::$stores[ self::$default_store ]->delete($key, $group);
184
+	}
185
+
186
+	//--------------------------------------------------------------------
187
+
188
+	/**
189
+	 * Searches the store for any items with $field = $value.
190
+	 *
191
+	 * @param $field
192
+	 * @param $value
193
+	 * @return mixed
194
+	 */
195
+	public static function findBy($field, $value)
196
+	{
197
+		self::init();
198
+
199
+		foreach (self::$stores as $s)
200
+		{
201
+			if ($found = $s->findBy($field, $value))
202
+			{
203
+				return $found;
204
+			}
205
+		}
206
+
207
+		return false;
208
+	}
209
+
210
+	//--------------------------------------------------------------------
211
+
212
+	/**
213
+	 * Retrieves all items in the store either globally or for a single group.
214
+	 *
215
+	 * @param string $group
216
+	 * @return mixed
217
+	 */
218
+	public static function all($group=null, $store=null)
219
+	{
220
+		self::init();
221
+
222
+		$group = strtolower($group);
223
+
224
+		if (! empty($store))
225
+		{
226
+			return self::$stores[ $store ]->all($group);
227
+		}
228
+
229
+		// Otherwise combine the results from all stores
230
+		$results = [];
231
+
232
+		foreach (self::$stores as $s)
233
+		{
234
+			$found = $s->all($group);
235
+			if ($found)
236
+			{
237
+				$results = array_merge($results, (array)$found);
238
+			}
239
+		}
240
+
241
+		return $results;
242
+	}
243
+
244
+	//--------------------------------------------------------------------
245
+
246
+	/**
247
+	 * Appends a new datastore the end of the curent stores.
248
+	 *
249
+	 * @param $alias
250
+	 * @param $class
251
+	 * @return bool
252
+	 */
253
+	public static function addStore($alias, $class)
254
+	{
255
+		self::init();
256
+
257
+		if (class_exists($class))
258
+		{
259
+			self::$stores[ strtolower($alias) ] = new $class();
260
+			return true;
261
+		}
262
+
263
+		return false;
264
+	}
265
+
266
+	//--------------------------------------------------------------------
267
+
268
+	/**
269
+	 * Removes a datastore from the list of stores currently available.
270
+	 *
271
+	 * @param $alias
272
+	 * @return bool
273
+	 */
274
+	public static function removeStore($alias)
275
+	{
276
+		self::init();
277
+
278
+		$alias = strtolower($alias);
279
+
280
+		if (empty(self::$stores[$alias]))
281
+		{
282
+			return false;
283
+		}
284
+
285
+		unset(self::$stores[$alias]);
286
+
287
+		return true;
288
+	}
289
+
290
+	//--------------------------------------------------------------------
291 291
 
292 292
 }
Please login to merge, or discard this patch.
myth/Settings/SettingsStoreInterface.php 1 patch
Indentation   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -40,58 +40,58 @@
 block discarded – undo
40 40
  */
41 41
 interface SettingsStoreInterface {
42 42
 
43
-    /**
44
-     * Inserts/Replaces a single setting item.
45
-     *
46
-     * @param $key
47
-     * @param null $value
48
-     * @param string $group
49
-     */
50
-    public function save($key, $value=null, $group='app');
43
+	/**
44
+	 * Inserts/Replaces a single setting item.
45
+	 *
46
+	 * @param $key
47
+	 * @param null $value
48
+	 * @param string $group
49
+	 */
50
+	public function save($key, $value=null, $group='app');
51 51
 
52
-    //--------------------------------------------------------------------
52
+	//--------------------------------------------------------------------
53 53
 
54
-    /**
55
-     * Retrieves a single item.
56
-     *
57
-     * @param $key
58
-     * @param string $group
59
-     * @return mixed
60
-     */
61
-    public function get($key, $group='app');
54
+	/**
55
+	 * Retrieves a single item.
56
+	 *
57
+	 * @param $key
58
+	 * @param string $group
59
+	 * @return mixed
60
+	 */
61
+	public function get($key, $group='app');
62 62
 
63
-    //--------------------------------------------------------------------
63
+	//--------------------------------------------------------------------
64 64
 
65
-    /**
66
-     * Deletes a single item.
67
-     *
68
-     * @param $key
69
-     * @param $group
70
-     * @return mixed
71
-     */
72
-    public function delete($key, $group='app');
65
+	/**
66
+	 * Deletes a single item.
67
+	 *
68
+	 * @param $key
69
+	 * @param $group
70
+	 * @return mixed
71
+	 */
72
+	public function delete($key, $group='app');
73 73
 
74
-    //--------------------------------------------------------------------
74
+	//--------------------------------------------------------------------
75 75
 
76
-    /**
77
-     * Searches the store for any items with $field = $value.
78
-     *
79
-     * @param $field
80
-     * @param $value
81
-     * @return mixed
82
-     */
83
-    public function findBy($field, $value);
76
+	/**
77
+	 * Searches the store for any items with $field = $value.
78
+	 *
79
+	 * @param $field
80
+	 * @param $value
81
+	 * @return mixed
82
+	 */
83
+	public function findBy($field, $value);
84 84
 
85
-    //--------------------------------------------------------------------
85
+	//--------------------------------------------------------------------
86 86
 
87
-    /**
88
-     * Retrieves all items in the store either globally or for a single group.
89
-     *
90
-     * @param string $group
91
-     * @return mixed
92
-     */
93
-    public function all($group=null);
87
+	/**
88
+	 * Retrieves all items in the store either globally or for a single group.
89
+	 *
90
+	 * @param string $group
91
+	 * @return mixed
92
+	 */
93
+	public function all($group=null);
94 94
 
95
-    //--------------------------------------------------------------------
95
+	//--------------------------------------------------------------------
96 96
 
97 97
 }
Please login to merge, or discard this patch.