Passed
Pull Request — 1.0.0-dev (#1)
by
unknown
02:46
created
core/libraries/Email.php 2 patches
Indentation   +727 added lines, -727 removed lines patch added patch discarded remove patch
@@ -1,732 +1,732 @@
 block discarded – undo
1 1
 <?php
2
-	defined('ROOT_PATH') || exit('Access denied');
3
-	/**
4
-	 * Simple Mail
5
-	 *
6
-	 * A simple PHP wrapper class for sending email using the mail() method.
7
-	 *
8
-	 * PHP version > 5.2
9
-	 *
10
-	 * LICENSE: This source file is subject to the MIT license, which is
11
-	 * available through the world-wide-web at the following URI:
12
-	 * http://github.com/eoghanobrien/php-simple-mail/LICENCE.txt
13
-	 *
14
-	 * @category  SimpleMail
15
-	 * @package   SimpleMail
16
-	 * @author    Eoghan O'Brien <[email protected]>
17
-	 * @copyright 2009 - 2017 Eoghan O'Brien
18
-	 * @license   http://github.com/eoghanobrien/php-simple-mail/LICENCE.txt MIT
19
-	 * @version   1.7.1
20
-	 * @link      http://github.com/eoghanobrien/php-simple-mail
21
-	 */
22
-
23
-	/**
24
-	 * Simple Mail class.
25
-	 *
26
-	 * @category  SimpleMail
27
-	 * @package   SimpleMail
28
-	 * @author    Eoghan O'Brien <[email protected]>
29
-	 * @copyright 2009 - 2017 Eoghan O'Brien
30
-	 * @license   http://github.com/eoghanobrien/php-simple-mail/LICENCE.txt MIT
31
-	 * @version   1.7.1
32
-	 * @link      http://github.com/eoghanobrien/php-simple-mail
33
-	 */
34
-	class Email extends BaseClass
35
-	{
36
-		/**
37
-		 * @var int $_wrap
38
-		 */
39
-		protected $_wrap = 78;
40
-
41
-		/**
42
-		 * @var array $_to
43
-		 */
44
-		protected $_to = array();
45
-
46
-		/**
47
-		 * @var string $_subject
48
-		 */
49
-		protected $_subject;
50
-
51
-		/**
52
-		 * @var string $_message
53
-		 */
54
-		protected $_message;
55
-
56
-		/**
57
-		 * @var array $_headers
58
-		 */
59
-		protected $_headers = array();
60
-
61
-		/**
62
-		 * @var string $_parameters
63
-		 */
64
-		protected $_params;
65
-
66
-		/**
67
-		 * @var array $_attachments
68
-		 */
69
-		protected $_attachments = array();
70
-
71
-		/**
72
-		 * @var string $_uid
73
-		 */
74
-		protected $_uid;
2
+    defined('ROOT_PATH') || exit('Access denied');
3
+    /**
4
+     * Simple Mail
5
+     *
6
+     * A simple PHP wrapper class for sending email using the mail() method.
7
+     *
8
+     * PHP version > 5.2
9
+     *
10
+     * LICENSE: This source file is subject to the MIT license, which is
11
+     * available through the world-wide-web at the following URI:
12
+     * http://github.com/eoghanobrien/php-simple-mail/LICENCE.txt
13
+     *
14
+     * @category  SimpleMail
15
+     * @package   SimpleMail
16
+     * @author    Eoghan O'Brien <[email protected]>
17
+     * @copyright 2009 - 2017 Eoghan O'Brien
18
+     * @license   http://github.com/eoghanobrien/php-simple-mail/LICENCE.txt MIT
19
+     * @version   1.7.1
20
+     * @link      http://github.com/eoghanobrien/php-simple-mail
21
+     */
22
+
23
+    /**
24
+     * Simple Mail class.
25
+     *
26
+     * @category  SimpleMail
27
+     * @package   SimpleMail
28
+     * @author    Eoghan O'Brien <[email protected]>
29
+     * @copyright 2009 - 2017 Eoghan O'Brien
30
+     * @license   http://github.com/eoghanobrien/php-simple-mail/LICENCE.txt MIT
31
+     * @version   1.7.1
32
+     * @link      http://github.com/eoghanobrien/php-simple-mail
33
+     */
34
+    class Email extends BaseClass
35
+    {
36
+        /**
37
+         * @var int $_wrap
38
+         */
39
+        protected $_wrap = 78;
40
+
41
+        /**
42
+         * @var array $_to
43
+         */
44
+        protected $_to = array();
45
+
46
+        /**
47
+         * @var string $_subject
48
+         */
49
+        protected $_subject;
50
+
51
+        /**
52
+         * @var string $_message
53
+         */
54
+        protected $_message;
55
+
56
+        /**
57
+         * @var array $_headers
58
+         */
59
+        protected $_headers = array();
60
+
61
+        /**
62
+         * @var string $_parameters
63
+         */
64
+        protected $_params;
65
+
66
+        /**
67
+         * @var array $_attachments
68
+         */
69
+        protected $_attachments = array();
70
+
71
+        /**
72
+         * @var string $_uid
73
+         */
74
+        protected $_uid;
75 75
 		
76 76
 
77
-		/**
78
-		 * __construct
79
-		 *
80
-		 * Resets the class properties.
81
-		 */
82
-		public function __construct()
83
-		{
84
-			parent::__construct();
85
-			$this->reset();
86
-		}
87
-
88
-		/**
89
-		 * reset
90
-		 *
91
-		 * Resets all properties to initial state.
92
-		 *
93
-		 * @return self
94
-		 */
95
-		public function reset()
96
-		{
97
-			$this->_to = array();
98
-			$this->_headers = array();
99
-			$this->_subject = null;
100
-			$this->_message = null;
101
-			$this->_wrap = 78;
102
-			$this->_params = null;
103
-			$this->_attachments = array();
104
-			$this->_uid = $this->getUniqueId();
105
-			return $this;
106
-		}
77
+        /**
78
+         * __construct
79
+         *
80
+         * Resets the class properties.
81
+         */
82
+        public function __construct()
83
+        {
84
+            parent::__construct();
85
+            $this->reset();
86
+        }
87
+
88
+        /**
89
+         * reset
90
+         *
91
+         * Resets all properties to initial state.
92
+         *
93
+         * @return self
94
+         */
95
+        public function reset()
96
+        {
97
+            $this->_to = array();
98
+            $this->_headers = array();
99
+            $this->_subject = null;
100
+            $this->_message = null;
101
+            $this->_wrap = 78;
102
+            $this->_params = null;
103
+            $this->_attachments = array();
104
+            $this->_uid = $this->getUniqueId();
105
+            return $this;
106
+        }
107 107
 		
108
-		 /**
109
-		 * setFrom
110
-		 *
111
-		 * @param string $email The email to send as from.
112
-		 * @param string $name  The name to send as from.
113
-		 *
114
-		 * @return self
115
-		 */
116
-		public function setFrom($email, $name = null)
117
-		{
118
-			$this->addMailHeader('From', (string) $email, (string) $name);
119
-			return $this;
120
-		}
121
-
122
-		/**
123
-		 * setTo
124
-		 *
125
-		 * @param string $email The email address to send to.
126
-		 * @param string $name  The name of the person to send to.
127
-		 *
128
-		 * @return self
129
-		 */
130
-		public function setTo($email, $name = null)
131
-		{
132
-			$this->_to[] = $this->formatHeader((string) $email, (string) $name);
133
-			return $this;
134
-		}
108
+            /**
109
+             * setFrom
110
+             *
111
+             * @param string $email The email to send as from.
112
+             * @param string $name  The name to send as from.
113
+             *
114
+             * @return self
115
+             */
116
+        public function setFrom($email, $name = null)
117
+        {
118
+            $this->addMailHeader('From', (string) $email, (string) $name);
119
+            return $this;
120
+        }
121
+
122
+        /**
123
+         * setTo
124
+         *
125
+         * @param string $email The email address to send to.
126
+         * @param string $name  The name of the person to send to.
127
+         *
128
+         * @return self
129
+         */
130
+        public function setTo($email, $name = null)
131
+        {
132
+            $this->_to[] = $this->formatHeader((string) $email, (string) $name);
133
+            return $this;
134
+        }
135 135
 		
136
-		/**
137
-		* Set destination using array
138
-		* @params array $emails the list of recipient. This is an associative array name => email
139
-		* @example array('John Doe' => '[email protected]')
140
-		* @return Object the current instance
141
-		*/
142
-		public function setTos(array $emails)
143
-		{
144
-			foreach ($emails as $name => $email) {
145
-				if(is_numeric($name)){
146
-					$this->setTo($email);
147
-				} else{
148
-					$this->setTo($email, $name);
149
-				}
150
-			}
151
-			return $this;
152
-		}
153
-
154
-
155
-		/**
156
-		 * getTo
157
-		 *
158
-		 * Return an array of formatted To addresses.
159
-		 *
160
-		 * @return array
161
-		 */
162
-		public function getTo()
163
-		{
164
-			return $this->_to;
165
-		}
166
-
167
-
168
-		/**
169
-		 * setCc
170
-		 *
171
-		 * @param array  $pairs  An array of name => email pairs.
172
-		 *
173
-		 * @return self
174
-		 */
175
-		public function setCc(array $pairs)
176
-		{
177
-			return $this->addMailHeaders('Cc', $pairs);
178
-		}
179
-
180
-		/**
181
-		 * setBcc
182
-		 *
183
-		 * @param array  $pairs  An array of name => email pairs.
184
-		 *
185
-		 * @return self
186
-		 */
187
-		public function setBcc(array $pairs)
188
-		{
189
-			return $this->addMailHeaders('Bcc', $pairs);
190
-		}
191
-
192
-		/**
193
-		 * setReplyTo
194
-		 *
195
-		 * @param string $email
196
-		 * @param string $name
197
-		 *
198
-		 * @return self
199
-		 */
200
-		public function setReplyTo($email, $name = null)
201
-		{
202
-			return $this->addMailHeader('Reply-To', $email, $name);
203
-		}
204
-
205
-		/**
206
-		 * setHtml
207
-		 *
208
-		 * @return self
209
-		 */
210
-		public function setHtml()
211
-		{
212
-			$this->addGenericHeader(
213
-				'Content-Type', 'text/html; charset="utf-8"'
214
-			);
215
-			return $this;
216
-		}
217
-
218
-		/**
219
-		 * setSubject
220
-		 *
221
-		 * @param string $subject The email subject
222
-		 *
223
-		 * @return self
224
-		 */
225
-		public function setSubject($subject)
226
-		{
227
-			$this->_subject = $this->encodeUtf8(
228
-				$this->filterOther((string) $subject)
229
-			);
230
-			return $this;
231
-		}
232
-
233
-		/**
234
-		 * getSubject function.
235
-		 *
236
-		 * @return string
237
-		 */
238
-		public function getSubject()
239
-		{
240
-			return $this->_subject;
241
-		}
242
-
243
-		/**
244
-		 * setMessage
245
-		 *
246
-		 * @param string $message The message to send.
247
-		 *
248
-		 * @return self
249
-		 */
250
-		public function setMessage($message)
251
-		{
252
-			$this->_message = str_replace("\n.", "\n..", (string) $message);
253
-			return $this;
254
-		}
255
-
256
-		/**
257
-		 * getMessage
258
-		 *
259
-		 * @return string
260
-		 */
261
-		public function getMessage()
262
-		{
263
-			return $this->_message;
264
-		}
265
-
266
-		/**
267
-		 * addAttachment
268
-		 *
269
-		 * @param string $path The file path to the attachment.
270
-		 * @param string $filename The filename of the attachment when emailed.
271
-		 * @param string $data
272
-		 * 
273
-		 * @return self
274
-		 */
275
-		public function addAttachment($path, $filename = null, $data = null)
276
-		{
277
-			if (!file_exists($path)) {
278
-				show_error('The file [' . $path . '] does not exists.');
279
-			}
280
-			$filename = empty($filename) ? basename($path) : $filename;
281
-			$filename = $this->encodeUtf8($this->filterOther((string) $filename));
282
-			$data = empty($data) ? $this->getAttachmentData($path) : $data;
283
-			$this->_attachments[] = array(
284
-				'path' => $path,
285
-				'file' => $filename,
286
-				'data' => chunk_split(base64_encode($data))
287
-			);
288
-			return $this;
289
-		}
290
-
291
-		/**
292
-		 * getAttachmentData
293
-		 *
294
-		 * @param string $path The path to the attachment file.
295
-		 *
296
-		 * @return string
297
-		 */
298
-		public function getAttachmentData($path)
299
-		{
300
-			if (!file_exists($path)) {
301
-				show_error('The file [' . $path . '] does not exists.');
302
-			}
303
-			$filesize = filesize($path);
304
-			$handle = fopen($path, "r");
305
-			$attachment = null;
306
-			if (is_resource($handle)) {
307
-				$attachment = fread($handle, $filesize);
308
-				fclose($handle);
309
-			}
310
-			return $attachment;
311
-		}
312
-
313
-		/**
314
-		 * addMailHeader
315
-		 *
316
-		 * @param string $header The header to add.
317
-		 * @param string $email  The email to add.
318
-		 * @param string $name   The name to add.
319
-		 *
320
-		 * @return self
321
-		 */
322
-		public function addMailHeader($header, $email, $name = null)
323
-		{
324
-			$address = $this->formatHeader((string) $email, (string) $name);
325
-			$this->_headers[] = sprintf('%s: %s', (string) $header, $address);
326
-			return $this;
327
-		}
328
-
329
-		/**
330
-		 * addMailHeaders
331
-		 *
332
-		 * @param string $header The header to add.
333
-		 * @param array  $pairs  An array of name => email pairs.
334
-		 *
335
-		 * @return self
336
-		 */
337
-		public function addMailHeaders($header, array $pairs)
338
-		{
339
-			if (count($pairs) === 0) {
340
-				show_error('You must pass at least one name => email pair.');
341
-			}
342
-			$addresses = array();
343
-			foreach ($pairs as $name => $email) {
344
-				$name = is_numeric($name) ? null : $name;
345
-				$addresses[] = $this->formatHeader($email, $name);
346
-			}
347
-			$this->addGenericHeader($header, implode(',', $addresses));
348
-			return $this;
349
-		}
350
-
351
-		/**
352
-		 * addGenericHeader
353
-		 *
354
-		 * @param string $name The generic header to add.
355
-		 * @param mixed  $value  The value of the header.
356
-		 *
357
-		 * @return self
358
-		 */
359
-		public function addGenericHeader($name, $value)
360
-		{
361
-			$this->_headers[] = sprintf(
362
-				'%s: %s',
363
-				(string) $name,
364
-				(string) $value
365
-			);
366
-			return $this;
367
-		}
368
-
369
-		/**
370
-		 * getHeaders
371
-		 *
372
-		 * Return the headers registered so far as an array.
373
-		 *
374
-		 * @return array
375
-		 */
376
-		public function getHeaders()
377
-		{
378
-			return $this->_headers;
379
-		}
380
-
381
-		/**
382
-		 * setAdditionalParameters
383
-		 *
384
-		 * Such as "[email protected]
385
-		 *
386
-		 * @param string $additionalParameters The addition mail parameter.
387
-		 *
388
-		 * @return self
389
-		 */
390
-		public function setParameters($additionalParameters)
391
-		{
392
-			$this->_params = (string) $additionalParameters;
393
-			return $this;
394
-		}
395
-
396
-		/**
397
-		 * getAdditionalParameters
398
-		 *
399
-		 * @return string
400
-		 */
401
-		public function getParameters()
402
-		{
403
-			return $this->_params;
404
-		}
405
-
406
-		/**
407
-		 * setWrap
408
-		 *
409
-		 * @param int $wrap The number of characters at which the message will wrap.
410
-		 *
411
-		 * @return self
412
-		 */
413
-		public function setWrap($wrap = 78)
414
-		{
415
-			$wrap = (int) $wrap;
416
-			if ($wrap < 1) {
417
-				$wrap = 78;
418
-			}
419
-			$this->_wrap = $wrap;
420
-			return $this;
421
-		}
422
-
423
-		/**
424
-		 * getWrap
425
-		 *
426
-		 * @return int
427
-		 */
428
-		public function getWrap()
429
-		{
430
-			return $this->_wrap;
431
-		}
432
-
433
-		/**
434
-		 * hasAttachments
435
-		 * 
436
-		 * Checks if the email has any registered attachments.
437
-		 *
438
-		 * @return bool
439
-		 */
440
-		public function hasAttachments()
441
-		{
442
-			return !empty($this->_attachments);
443
-		}
444
-
445
-		/**
446
-		 * assembleAttachment
447
-		 *
448
-		 * @return string
449
-		 */
450
-		public function assembleAttachmentHeaders()
451
-		{
452
-			$head = array();
453
-			$head[] = "MIME-Version: 1.0";
454
-			$head[] = "Content-Type: multipart/mixed; boundary=\"{$this->_uid}\"";
455
-
456
-			return join(PHP_EOL, $head);
457
-		}
458
-
459
-		/**
460
-		 * assembleAttachmentBody
461
-		 *
462
-		 * @return string
463
-		 */
464
-		public function assembleAttachmentBody()
465
-		{
466
-			$body = array();
467
-			$body[] = "This is a multi-part message in MIME format.";
468
-			$body[] = "--{$this->_uid}";
469
-			$body[] = "Content-Type: text/html; charset=\"utf-8\"";
470
-			$body[] = "Content-Transfer-Encoding: quoted-printable";
471
-			$body[] = "";
472
-			$body[] = quoted_printable_encode($this->_message);
473
-			$body[] = "";
474
-			$body[] = "--{$this->_uid}";
475
-
476
-			foreach ($this->_attachments as $attachment) {
477
-				$body[] = $this->getAttachmentMimeTemplate($attachment);
478
-			}
479
-
480
-			return implode(PHP_EOL, $body) . '--';
481
-		}
482
-
483
-		/**
484
-		 * getAttachmentMimeTemplate
485
-		 *
486
-		 * @param array  $attachment An array containing 'file' and 'data' keys.
487
-		 *
488
-		 * @return string
489
-		 */
490
-		public function getAttachmentMimeTemplate($attachment)
491
-		{
492
-			$file = $attachment['file'];
493
-			$data = $attachment['data'];
494
-
495
-			$head = array();
496
-			$head[] = "Content-Type: application/octet-stream; name=\"{$file}\"";
497
-			$head[] = "Content-Transfer-Encoding: base64";
498
-			$head[] = "Content-Disposition: attachment; filename=\"{$file}\"";
499
-			$head[] = "";
500
-			$head[] = $data;
501
-			$head[] = "";
502
-			$head[] = "--{$this->_uid}";
503
-
504
-			return implode(PHP_EOL, $head);
505
-		}
506
-
507
-		/**
508
-		 * send the email
509
-		 *
510
-		 * @return boolean
511
-		 */
512
-		public function send()
513
-		{
514
-			$to = $this->getToForSend();
515
-			$headers = $this->getHeadersForSend();
516
-
517
-			if (empty($to)) {
518
-				show_error('Unable to send, no To address has been set.');
519
-			}
520
-
521
-			if ($this->hasAttachments()) {
522
-				$message  = $this->assembleAttachmentBody();
523
-				$headers .= PHP_EOL . $this->assembleAttachmentHeaders();
524
-			} else {
525
-				$message = $this->getWrapMessage();
526
-			}
527
-			$this->logger->info('Sending new mail, the information are listed below: destination: ' . $to . ', headers: ' . $headers . ', message: ' . $message);
528
-			return mail($to, $this->_subject, $message, $headers, $this->_params);
529
-		}
530
-
531
-		/**
532
-		 * debug
533
-		 *
534
-		 * @return string
535
-		 */
536
-		public function debug()
537
-		{
538
-			return '<pre>' . print_r($this, true) . '</pre>';
539
-		}
540
-
541
-		/**
542
-		 * magic __toString function
543
-		 *
544
-		 * @return string
545
-		 */
546
-		public function __toString()
547
-		{
548
-			return print_r($this, true);
549
-		}
550
-
551
-		/**
552
-		 * formatHeader
553
-		 *
554
-		 * Formats a display address for emails according to RFC2822 e.g.
555
-		 * Name <[email protected]>
556
-		 *
557
-		 * @param string $email The email address.
558
-		 * @param string $name  The display name.
559
-		 *
560
-		 * @return string
561
-		 */
562
-		public function formatHeader($email, $name = null)
563
-		{
564
-			$email = $this->filterEmail((string) $email);
565
-			if (empty($name)) {
566
-				return $email;
567
-			}
568
-			$name = $this->encodeUtf8($this->filterName((string) $name));
569
-			return sprintf('"%s" <%s>', $name, $email);
570
-		}
571
-
572
-		/**
573
-		 * encodeUtf8
574
-		 *
575
-		 * @param string $value The value to encode.
576
-		 *
577
-		 * @return string
578
-		 */
579
-		public function encodeUtf8($value)
580
-		{
581
-			$value = trim($value);
582
-			if (preg_match('/(\s)/', $value)) {
583
-				return $this->encodeUtf8Words($value);
584
-			}
585
-			return $this->encodeUtf8Word($value);
586
-		}
587
-
588
-		/**
589
-		 * encodeUtf8Word
590
-		 *
591
-		 * @param string $value The word to encode.
592
-		 *
593
-		 * @return string
594
-		 */
595
-		public function encodeUtf8Word($value)
596
-		{
597
-			return sprintf('=?UTF-8?B?%s?=', base64_encode($value));
598
-		}
599
-
600
-		/**
601
-		 * encodeUtf8Words
602
-		 *
603
-		 * @param string $value The words to encode.
604
-		 *
605
-		 * @return string
606
-		 */
607
-		public function encodeUtf8Words($value)
608
-		{
609
-			$words = explode(' ', $value);
610
-			$encoded = array();
611
-			foreach ($words as $word) {
612
-				$encoded[] = $this->encodeUtf8Word($word);
613
-			}
614
-			return join($this->encodeUtf8Word(' '), $encoded);
615
-		}
616
-
617
-		/**
618
-		 * filterEmail
619
-		 *
620
-		 * Removes any carriage return, line feed, tab, double quote, comma
621
-		 * and angle bracket characters before sanitizing the email address.
622
-		 *
623
-		 * @param string $email The email to filter.
624
-		 *
625
-		 * @return string
626
-		 */
627
-		public function filterEmail($email)
628
-		{
629
-			$rule = array(
630
-				"\r" => '',
631
-				"\n" => '',
632
-				"\t" => '',
633
-				'"'  => '',
634
-				','  => '',
635
-				'<'  => '',
636
-				'>'  => ''
637
-			);
638
-			$email = strtr($email, $rule);
639
-			$email = filter_var($email, FILTER_SANITIZE_EMAIL);
640
-			return $email;
641
-		}
642
-
643
-		/**
644
-		 * filterName
645
-		 *
646
-		 * Removes any carriage return, line feed or tab characters. Replaces
647
-		 * double quotes with single quotes and angle brackets with square
648
-		 * brackets, before sanitizing the string and stripping out html tags.
649
-		 *
650
-		 * @param string $name The name to filter.
651
-		 *
652
-		 * @return string
653
-		 */
654
-		public function filterName($name)
655
-		{
656
-			$rule = array(
657
-				"\r" => '',
658
-				"\n" => '',
659
-				"\t" => '',
660
-				'"'  => "'",
661
-				'<'  => '[',
662
-				'>'  => ']',
663
-			);
664
-			$filtered = filter_var(
665
-				$name,
666
-				FILTER_SANITIZE_STRING,
667
-				FILTER_FLAG_NO_ENCODE_QUOTES
668
-			);
669
-			return trim(strtr($filtered, $rule));
670
-		}
671
-
672
-		/**
673
-		 * filterOther
674
-		 *
675
-		 * Removes ASCII control characters including any carriage return, line
676
-		 * feed or tab characters.
677
-		 *
678
-		 * @param string $data The data to filter.
679
-		 *
680
-		 * @return string
681
-		 */
682
-		public function filterOther($data)
683
-		{
684
-			return filter_var($data, FILTER_UNSAFE_RAW, FILTER_FLAG_STRIP_LOW);
685
-		}
686
-
687
-		/**
688
-		 * getHeadersForSend
689
-		 *
690
-		 * @return string
691
-		 */
692
-		public function getHeadersForSend()
693
-		{
694
-			if (empty($this->_headers)) {
695
-				return '';
696
-			}
697
-			return join(PHP_EOL, $this->_headers);
698
-		}
699
-
700
-		/**
701
-		 * getToForSend
702
-		 *
703
-		 * @return string
704
-		 */
705
-		public function getToForSend()
706
-		{
707
-			if (empty($this->_to)) {
708
-				return '';
709
-			}
710
-			return join(', ', $this->_to);
711
-		}
712
-
713
-		/**
714
-		 * getUniqueId
715
-		 *
716
-		 * @return string
717
-		 */
718
-		public function getUniqueId()
719
-		{
720
-			return md5(uniqid(time()));
721
-		}
722
-
723
-		/**
724
-		 * getWrapMessage
725
-		 *
726
-		 * @return string
727
-		 */
728
-		public function getWrapMessage()
729
-		{
730
-			return wordwrap($this->_message, $this->_wrap);
731
-		}
732
-	}
136
+        /**
137
+         * Set destination using array
138
+         * @params array $emails the list of recipient. This is an associative array name => email
139
+         * @example array('John Doe' => '[email protected]')
140
+         * @return Object the current instance
141
+         */
142
+        public function setTos(array $emails)
143
+        {
144
+            foreach ($emails as $name => $email) {
145
+                if(is_numeric($name)){
146
+                    $this->setTo($email);
147
+                } else{
148
+                    $this->setTo($email, $name);
149
+                }
150
+            }
151
+            return $this;
152
+        }
153
+
154
+
155
+        /**
156
+         * getTo
157
+         *
158
+         * Return an array of formatted To addresses.
159
+         *
160
+         * @return array
161
+         */
162
+        public function getTo()
163
+        {
164
+            return $this->_to;
165
+        }
166
+
167
+
168
+        /**
169
+         * setCc
170
+         *
171
+         * @param array  $pairs  An array of name => email pairs.
172
+         *
173
+         * @return self
174
+         */
175
+        public function setCc(array $pairs)
176
+        {
177
+            return $this->addMailHeaders('Cc', $pairs);
178
+        }
179
+
180
+        /**
181
+         * setBcc
182
+         *
183
+         * @param array  $pairs  An array of name => email pairs.
184
+         *
185
+         * @return self
186
+         */
187
+        public function setBcc(array $pairs)
188
+        {
189
+            return $this->addMailHeaders('Bcc', $pairs);
190
+        }
191
+
192
+        /**
193
+         * setReplyTo
194
+         *
195
+         * @param string $email
196
+         * @param string $name
197
+         *
198
+         * @return self
199
+         */
200
+        public function setReplyTo($email, $name = null)
201
+        {
202
+            return $this->addMailHeader('Reply-To', $email, $name);
203
+        }
204
+
205
+        /**
206
+         * setHtml
207
+         *
208
+         * @return self
209
+         */
210
+        public function setHtml()
211
+        {
212
+            $this->addGenericHeader(
213
+                'Content-Type', 'text/html; charset="utf-8"'
214
+            );
215
+            return $this;
216
+        }
217
+
218
+        /**
219
+         * setSubject
220
+         *
221
+         * @param string $subject The email subject
222
+         *
223
+         * @return self
224
+         */
225
+        public function setSubject($subject)
226
+        {
227
+            $this->_subject = $this->encodeUtf8(
228
+                $this->filterOther((string) $subject)
229
+            );
230
+            return $this;
231
+        }
232
+
233
+        /**
234
+         * getSubject function.
235
+         *
236
+         * @return string
237
+         */
238
+        public function getSubject()
239
+        {
240
+            return $this->_subject;
241
+        }
242
+
243
+        /**
244
+         * setMessage
245
+         *
246
+         * @param string $message The message to send.
247
+         *
248
+         * @return self
249
+         */
250
+        public function setMessage($message)
251
+        {
252
+            $this->_message = str_replace("\n.", "\n..", (string) $message);
253
+            return $this;
254
+        }
255
+
256
+        /**
257
+         * getMessage
258
+         *
259
+         * @return string
260
+         */
261
+        public function getMessage()
262
+        {
263
+            return $this->_message;
264
+        }
265
+
266
+        /**
267
+         * addAttachment
268
+         *
269
+         * @param string $path The file path to the attachment.
270
+         * @param string $filename The filename of the attachment when emailed.
271
+         * @param string $data
272
+         * 
273
+         * @return self
274
+         */
275
+        public function addAttachment($path, $filename = null, $data = null)
276
+        {
277
+            if (!file_exists($path)) {
278
+                show_error('The file [' . $path . '] does not exists.');
279
+            }
280
+            $filename = empty($filename) ? basename($path) : $filename;
281
+            $filename = $this->encodeUtf8($this->filterOther((string) $filename));
282
+            $data = empty($data) ? $this->getAttachmentData($path) : $data;
283
+            $this->_attachments[] = array(
284
+                'path' => $path,
285
+                'file' => $filename,
286
+                'data' => chunk_split(base64_encode($data))
287
+            );
288
+            return $this;
289
+        }
290
+
291
+        /**
292
+         * getAttachmentData
293
+         *
294
+         * @param string $path The path to the attachment file.
295
+         *
296
+         * @return string
297
+         */
298
+        public function getAttachmentData($path)
299
+        {
300
+            if (!file_exists($path)) {
301
+                show_error('The file [' . $path . '] does not exists.');
302
+            }
303
+            $filesize = filesize($path);
304
+            $handle = fopen($path, "r");
305
+            $attachment = null;
306
+            if (is_resource($handle)) {
307
+                $attachment = fread($handle, $filesize);
308
+                fclose($handle);
309
+            }
310
+            return $attachment;
311
+        }
312
+
313
+        /**
314
+         * addMailHeader
315
+         *
316
+         * @param string $header The header to add.
317
+         * @param string $email  The email to add.
318
+         * @param string $name   The name to add.
319
+         *
320
+         * @return self
321
+         */
322
+        public function addMailHeader($header, $email, $name = null)
323
+        {
324
+            $address = $this->formatHeader((string) $email, (string) $name);
325
+            $this->_headers[] = sprintf('%s: %s', (string) $header, $address);
326
+            return $this;
327
+        }
328
+
329
+        /**
330
+         * addMailHeaders
331
+         *
332
+         * @param string $header The header to add.
333
+         * @param array  $pairs  An array of name => email pairs.
334
+         *
335
+         * @return self
336
+         */
337
+        public function addMailHeaders($header, array $pairs)
338
+        {
339
+            if (count($pairs) === 0) {
340
+                show_error('You must pass at least one name => email pair.');
341
+            }
342
+            $addresses = array();
343
+            foreach ($pairs as $name => $email) {
344
+                $name = is_numeric($name) ? null : $name;
345
+                $addresses[] = $this->formatHeader($email, $name);
346
+            }
347
+            $this->addGenericHeader($header, implode(',', $addresses));
348
+            return $this;
349
+        }
350
+
351
+        /**
352
+         * addGenericHeader
353
+         *
354
+         * @param string $name The generic header to add.
355
+         * @param mixed  $value  The value of the header.
356
+         *
357
+         * @return self
358
+         */
359
+        public function addGenericHeader($name, $value)
360
+        {
361
+            $this->_headers[] = sprintf(
362
+                '%s: %s',
363
+                (string) $name,
364
+                (string) $value
365
+            );
366
+            return $this;
367
+        }
368
+
369
+        /**
370
+         * getHeaders
371
+         *
372
+         * Return the headers registered so far as an array.
373
+         *
374
+         * @return array
375
+         */
376
+        public function getHeaders()
377
+        {
378
+            return $this->_headers;
379
+        }
380
+
381
+        /**
382
+         * setAdditionalParameters
383
+         *
384
+         * Such as "[email protected]
385
+         *
386
+         * @param string $additionalParameters The addition mail parameter.
387
+         *
388
+         * @return self
389
+         */
390
+        public function setParameters($additionalParameters)
391
+        {
392
+            $this->_params = (string) $additionalParameters;
393
+            return $this;
394
+        }
395
+
396
+        /**
397
+         * getAdditionalParameters
398
+         *
399
+         * @return string
400
+         */
401
+        public function getParameters()
402
+        {
403
+            return $this->_params;
404
+        }
405
+
406
+        /**
407
+         * setWrap
408
+         *
409
+         * @param int $wrap The number of characters at which the message will wrap.
410
+         *
411
+         * @return self
412
+         */
413
+        public function setWrap($wrap = 78)
414
+        {
415
+            $wrap = (int) $wrap;
416
+            if ($wrap < 1) {
417
+                $wrap = 78;
418
+            }
419
+            $this->_wrap = $wrap;
420
+            return $this;
421
+        }
422
+
423
+        /**
424
+         * getWrap
425
+         *
426
+         * @return int
427
+         */
428
+        public function getWrap()
429
+        {
430
+            return $this->_wrap;
431
+        }
432
+
433
+        /**
434
+         * hasAttachments
435
+         * 
436
+         * Checks if the email has any registered attachments.
437
+         *
438
+         * @return bool
439
+         */
440
+        public function hasAttachments()
441
+        {
442
+            return !empty($this->_attachments);
443
+        }
444
+
445
+        /**
446
+         * assembleAttachment
447
+         *
448
+         * @return string
449
+         */
450
+        public function assembleAttachmentHeaders()
451
+        {
452
+            $head = array();
453
+            $head[] = "MIME-Version: 1.0";
454
+            $head[] = "Content-Type: multipart/mixed; boundary=\"{$this->_uid}\"";
455
+
456
+            return join(PHP_EOL, $head);
457
+        }
458
+
459
+        /**
460
+         * assembleAttachmentBody
461
+         *
462
+         * @return string
463
+         */
464
+        public function assembleAttachmentBody()
465
+        {
466
+            $body = array();
467
+            $body[] = "This is a multi-part message in MIME format.";
468
+            $body[] = "--{$this->_uid}";
469
+            $body[] = "Content-Type: text/html; charset=\"utf-8\"";
470
+            $body[] = "Content-Transfer-Encoding: quoted-printable";
471
+            $body[] = "";
472
+            $body[] = quoted_printable_encode($this->_message);
473
+            $body[] = "";
474
+            $body[] = "--{$this->_uid}";
475
+
476
+            foreach ($this->_attachments as $attachment) {
477
+                $body[] = $this->getAttachmentMimeTemplate($attachment);
478
+            }
479
+
480
+            return implode(PHP_EOL, $body) . '--';
481
+        }
482
+
483
+        /**
484
+         * getAttachmentMimeTemplate
485
+         *
486
+         * @param array  $attachment An array containing 'file' and 'data' keys.
487
+         *
488
+         * @return string
489
+         */
490
+        public function getAttachmentMimeTemplate($attachment)
491
+        {
492
+            $file = $attachment['file'];
493
+            $data = $attachment['data'];
494
+
495
+            $head = array();
496
+            $head[] = "Content-Type: application/octet-stream; name=\"{$file}\"";
497
+            $head[] = "Content-Transfer-Encoding: base64";
498
+            $head[] = "Content-Disposition: attachment; filename=\"{$file}\"";
499
+            $head[] = "";
500
+            $head[] = $data;
501
+            $head[] = "";
502
+            $head[] = "--{$this->_uid}";
503
+
504
+            return implode(PHP_EOL, $head);
505
+        }
506
+
507
+        /**
508
+         * send the email
509
+         *
510
+         * @return boolean
511
+         */
512
+        public function send()
513
+        {
514
+            $to = $this->getToForSend();
515
+            $headers = $this->getHeadersForSend();
516
+
517
+            if (empty($to)) {
518
+                show_error('Unable to send, no To address has been set.');
519
+            }
520
+
521
+            if ($this->hasAttachments()) {
522
+                $message  = $this->assembleAttachmentBody();
523
+                $headers .= PHP_EOL . $this->assembleAttachmentHeaders();
524
+            } else {
525
+                $message = $this->getWrapMessage();
526
+            }
527
+            $this->logger->info('Sending new mail, the information are listed below: destination: ' . $to . ', headers: ' . $headers . ', message: ' . $message);
528
+            return mail($to, $this->_subject, $message, $headers, $this->_params);
529
+        }
530
+
531
+        /**
532
+         * debug
533
+         *
534
+         * @return string
535
+         */
536
+        public function debug()
537
+        {
538
+            return '<pre>' . print_r($this, true) . '</pre>';
539
+        }
540
+
541
+        /**
542
+         * magic __toString function
543
+         *
544
+         * @return string
545
+         */
546
+        public function __toString()
547
+        {
548
+            return print_r($this, true);
549
+        }
550
+
551
+        /**
552
+         * formatHeader
553
+         *
554
+         * Formats a display address for emails according to RFC2822 e.g.
555
+         * Name <[email protected]>
556
+         *
557
+         * @param string $email The email address.
558
+         * @param string $name  The display name.
559
+         *
560
+         * @return string
561
+         */
562
+        public function formatHeader($email, $name = null)
563
+        {
564
+            $email = $this->filterEmail((string) $email);
565
+            if (empty($name)) {
566
+                return $email;
567
+            }
568
+            $name = $this->encodeUtf8($this->filterName((string) $name));
569
+            return sprintf('"%s" <%s>', $name, $email);
570
+        }
571
+
572
+        /**
573
+         * encodeUtf8
574
+         *
575
+         * @param string $value The value to encode.
576
+         *
577
+         * @return string
578
+         */
579
+        public function encodeUtf8($value)
580
+        {
581
+            $value = trim($value);
582
+            if (preg_match('/(\s)/', $value)) {
583
+                return $this->encodeUtf8Words($value);
584
+            }
585
+            return $this->encodeUtf8Word($value);
586
+        }
587
+
588
+        /**
589
+         * encodeUtf8Word
590
+         *
591
+         * @param string $value The word to encode.
592
+         *
593
+         * @return string
594
+         */
595
+        public function encodeUtf8Word($value)
596
+        {
597
+            return sprintf('=?UTF-8?B?%s?=', base64_encode($value));
598
+        }
599
+
600
+        /**
601
+         * encodeUtf8Words
602
+         *
603
+         * @param string $value The words to encode.
604
+         *
605
+         * @return string
606
+         */
607
+        public function encodeUtf8Words($value)
608
+        {
609
+            $words = explode(' ', $value);
610
+            $encoded = array();
611
+            foreach ($words as $word) {
612
+                $encoded[] = $this->encodeUtf8Word($word);
613
+            }
614
+            return join($this->encodeUtf8Word(' '), $encoded);
615
+        }
616
+
617
+        /**
618
+         * filterEmail
619
+         *
620
+         * Removes any carriage return, line feed, tab, double quote, comma
621
+         * and angle bracket characters before sanitizing the email address.
622
+         *
623
+         * @param string $email The email to filter.
624
+         *
625
+         * @return string
626
+         */
627
+        public function filterEmail($email)
628
+        {
629
+            $rule = array(
630
+                "\r" => '',
631
+                "\n" => '',
632
+                "\t" => '',
633
+                '"'  => '',
634
+                ','  => '',
635
+                '<'  => '',
636
+                '>'  => ''
637
+            );
638
+            $email = strtr($email, $rule);
639
+            $email = filter_var($email, FILTER_SANITIZE_EMAIL);
640
+            return $email;
641
+        }
642
+
643
+        /**
644
+         * filterName
645
+         *
646
+         * Removes any carriage return, line feed or tab characters. Replaces
647
+         * double quotes with single quotes and angle brackets with square
648
+         * brackets, before sanitizing the string and stripping out html tags.
649
+         *
650
+         * @param string $name The name to filter.
651
+         *
652
+         * @return string
653
+         */
654
+        public function filterName($name)
655
+        {
656
+            $rule = array(
657
+                "\r" => '',
658
+                "\n" => '',
659
+                "\t" => '',
660
+                '"'  => "'",
661
+                '<'  => '[',
662
+                '>'  => ']',
663
+            );
664
+            $filtered = filter_var(
665
+                $name,
666
+                FILTER_SANITIZE_STRING,
667
+                FILTER_FLAG_NO_ENCODE_QUOTES
668
+            );
669
+            return trim(strtr($filtered, $rule));
670
+        }
671
+
672
+        /**
673
+         * filterOther
674
+         *
675
+         * Removes ASCII control characters including any carriage return, line
676
+         * feed or tab characters.
677
+         *
678
+         * @param string $data The data to filter.
679
+         *
680
+         * @return string
681
+         */
682
+        public function filterOther($data)
683
+        {
684
+            return filter_var($data, FILTER_UNSAFE_RAW, FILTER_FLAG_STRIP_LOW);
685
+        }
686
+
687
+        /**
688
+         * getHeadersForSend
689
+         *
690
+         * @return string
691
+         */
692
+        public function getHeadersForSend()
693
+        {
694
+            if (empty($this->_headers)) {
695
+                return '';
696
+            }
697
+            return join(PHP_EOL, $this->_headers);
698
+        }
699
+
700
+        /**
701
+         * getToForSend
702
+         *
703
+         * @return string
704
+         */
705
+        public function getToForSend()
706
+        {
707
+            if (empty($this->_to)) {
708
+                return '';
709
+            }
710
+            return join(', ', $this->_to);
711
+        }
712
+
713
+        /**
714
+         * getUniqueId
715
+         *
716
+         * @return string
717
+         */
718
+        public function getUniqueId()
719
+        {
720
+            return md5(uniqid(time()));
721
+        }
722
+
723
+        /**
724
+         * getWrapMessage
725
+         *
726
+         * @return string
727
+         */
728
+        public function getWrapMessage()
729
+        {
730
+            return wordwrap($this->_message, $this->_wrap);
731
+        }
732
+    }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -142,9 +142,9 @@
 block discarded – undo
142 142
 		public function setTos(array $emails)
143 143
 		{
144 144
 			foreach ($emails as $name => $email) {
145
-				if(is_numeric($name)){
145
+				if (is_numeric($name)) {
146 146
 					$this->setTo($email);
147
-				} else{
147
+				} else {
148 148
 					$this->setTo($email, $name);
149 149
 				}
150 150
 			}
Please login to merge, or discard this patch.
core/libraries/Cookie.php 2 patches
Indentation   +84 added lines, -84 removed lines patch added patch discarded remove patch
@@ -1,93 +1,93 @@
 block discarded – undo
1 1
 <?php
2
-	defined('ROOT_PATH') || exit('Access denied');
3
-	/**
4
-	 * TNH Framework
5
-	 *
6
-	 * A simple PHP framework using HMVC architecture
7
-	 *
8
-	 * This content is released under the GNU GPL License (GPL)
9
-	 *
10
-	 * Copyright (C) 2017 Tony NGUEREZA
11
-	 *
12
-	 * This program is free software; you can redistribute it and/or
13
-	 * modify it under the terms of the GNU General Public License
14
-	 * as published by the Free Software Foundation; either version 3
15
-	 * of the License, or (at your option) any later version.
16
-	 *
17
-	 * This program is distributed in the hope that it will be useful,
18
-	 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
-	 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
-	 * GNU General Public License for more details.
21
-	 *
22
-	 * You should have received a copy of the GNU General Public License
23
-	 * along with this program; if not, write to the Free Software
24
-	 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
-	*/
2
+    defined('ROOT_PATH') || exit('Access denied');
3
+    /**
4
+     * TNH Framework
5
+     *
6
+     * A simple PHP framework using HMVC architecture
7
+     *
8
+     * This content is released under the GNU GPL License (GPL)
9
+     *
10
+     * Copyright (C) 2017 Tony NGUEREZA
11
+     *
12
+     * This program is free software; you can redistribute it and/or
13
+     * modify it under the terms of the GNU General Public License
14
+     * as published by the Free Software Foundation; either version 3
15
+     * of the License, or (at your option) any later version.
16
+     *
17
+     * This program is distributed in the hope that it will be useful,
18
+     * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
+     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
+     * GNU General Public License for more details.
21
+     *
22
+     * You should have received a copy of the GNU General Public License
23
+     * along with this program; if not, write to the Free Software
24
+     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
+     */
26 26
 
27
-	class Cookie extends BaseStaticClass {
27
+    class Cookie extends BaseStaticClass {
28 28
 
29
-		/**
30
-		 * Get the cookie item value
31
-		 * @param  string $item    the cookie item name to get
32
-		 * @param  mixed $default the default value to use if can not find the cokkie item in the list
33
-		 * @return mixed          the cookie value if exist or the default value
34
-		 */
35
-		public static function get($item, $default = null) {
36
-			$logger = self::getLogger();
37
-			if (array_key_exists($item, $_COOKIE)) {
38
-				return $_COOKIE[$item];
39
-			}
40
-			$logger->warning('Cannot find cookie item [' . $item . '], using the default value [' . $default . ']');
41
-			return $default;
42
-		}
29
+        /**
30
+         * Get the cookie item value
31
+         * @param  string $item    the cookie item name to get
32
+         * @param  mixed $default the default value to use if can not find the cokkie item in the list
33
+         * @return mixed          the cookie value if exist or the default value
34
+         */
35
+        public static function get($item, $default = null) {
36
+            $logger = self::getLogger();
37
+            if (array_key_exists($item, $_COOKIE)) {
38
+                return $_COOKIE[$item];
39
+            }
40
+            $logger->warning('Cannot find cookie item [' . $item . '], using the default value [' . $default . ']');
41
+            return $default;
42
+        }
43 43
 
44
-		/**
45
-		 * Set the cookie item value
46
-		 * @param string  $name     the cookie item name
47
-		 * @param string  $value    the cookie value to set
48
-		 * @param integer $expire   the time to live for this cookie
49
-		 * @param string  $path     the path that the cookie will be available
50
-		 * @param string  $domain   the domain that the cookie will be available
51
-		 * @param boolean $secure   if this cookie will be available on secure connection or not
52
-		 * @param boolean $httponly if this cookie will be available under HTTP protocol.
53
-		 */
54
-		public static function set($name, $value = '', $expire = 0, $path = '/', $domain = '', $secure = false, $httponly = false) {
55
-			if (headers_sent()) {
56
-				show_error('There exists a cookie that we wanted to create that we couldn\'t 
44
+        /**
45
+         * Set the cookie item value
46
+         * @param string  $name     the cookie item name
47
+         * @param string  $value    the cookie value to set
48
+         * @param integer $expire   the time to live for this cookie
49
+         * @param string  $path     the path that the cookie will be available
50
+         * @param string  $domain   the domain that the cookie will be available
51
+         * @param boolean $secure   if this cookie will be available on secure connection or not
52
+         * @param boolean $httponly if this cookie will be available under HTTP protocol.
53
+         */
54
+        public static function set($name, $value = '', $expire = 0, $path = '/', $domain = '', $secure = false, $httponly = false) {
55
+            if (headers_sent()) {
56
+                show_error('There exists a cookie that we wanted to create that we couldn\'t 
57 57
 						    because headers was already sent. Make sure to do this first 
58 58
 							before outputing anything.');
59
-			}
60
-			$timestamp = $expire;
61
-			if ($expire) {
62
-				$timestamp = time() + $expire;
63
-			}
64
-			setcookie($name, $value, $timestamp, $path, $domain, $secure, $httponly);
65
-		}
59
+            }
60
+            $timestamp = $expire;
61
+            if ($expire) {
62
+                $timestamp = time() + $expire;
63
+            }
64
+            setcookie($name, $value, $timestamp, $path, $domain, $secure, $httponly);
65
+        }
66 66
 
67
-		/**
68
-		 * Delete the cookie item in the list
69
-		 * @param  string $item the cookie item name to be cleared
70
-		 * @return boolean true if the item exists and is deleted successfully otherwise will return false.
71
-		 */
72
-		public static function delete($item){
73
-			$logger = self::getLogger();
74
-			if(array_key_exists($item, $_COOKIE)){
75
-				$logger->info('Delete cookie item ['.$item.']');
76
-				unset($_COOKIE[$item]);
77
-				return true;
78
-			} else{
79
-				$logger->warning('Cookie item ['.$item.'] to be deleted does not exists');
80
-				return false;
81
-			}
82
-		}
67
+        /**
68
+         * Delete the cookie item in the list
69
+         * @param  string $item the cookie item name to be cleared
70
+         * @return boolean true if the item exists and is deleted successfully otherwise will return false.
71
+         */
72
+        public static function delete($item){
73
+            $logger = self::getLogger();
74
+            if(array_key_exists($item, $_COOKIE)){
75
+                $logger->info('Delete cookie item ['.$item.']');
76
+                unset($_COOKIE[$item]);
77
+                return true;
78
+            } else{
79
+                $logger->warning('Cookie item ['.$item.'] to be deleted does not exists');
80
+                return false;
81
+            }
82
+        }
83 83
 
84
-		/**
85
-		 * Check if the given cookie item exists
86
-		 * @param  string $item the cookie item name
87
-		 * @return boolean       true if the cookie item is set, false or not
88
-		 */
89
-		public static function exists($item) {
90
-			return array_key_exists($item, $_COOKIE);
91
-		}
84
+        /**
85
+         * Check if the given cookie item exists
86
+         * @param  string $item the cookie item name
87
+         * @return boolean       true if the cookie item is set, false or not
88
+         */
89
+        public static function exists($item) {
90
+            return array_key_exists($item, $_COOKIE);
91
+        }
92 92
 
93
-	}
93
+    }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -69,14 +69,14 @@
 block discarded – undo
69 69
 		 * @param  string $item the cookie item name to be cleared
70 70
 		 * @return boolean true if the item exists and is deleted successfully otherwise will return false.
71 71
 		 */
72
-		public static function delete($item){
72
+		public static function delete($item) {
73 73
 			$logger = self::getLogger();
74
-			if(array_key_exists($item, $_COOKIE)){
75
-				$logger->info('Delete cookie item ['.$item.']');
74
+			if (array_key_exists($item, $_COOKIE)) {
75
+				$logger->info('Delete cookie item [' . $item . ']');
76 76
 				unset($_COOKIE[$item]);
77 77
 				return true;
78
-			} else{
79
-				$logger->warning('Cookie item ['.$item.'] to be deleted does not exists');
78
+			} else {
79
+				$logger->warning('Cookie item [' . $item . '] to be deleted does not exists');
80 80
 				return false;
81 81
 			}
82 82
 		}
Please login to merge, or discard this patch.
core/libraries/StringHash.php 1 patch
Indentation   +58 added lines, -58 removed lines patch added patch discarded remove patch
@@ -1,65 +1,65 @@
 block discarded – undo
1 1
 <?php 
2
-	defined('ROOT_PATH') || exit('Access denied');
3
-	/**
4
-	 * TNH Framework
5
-	 *
6
-	 * A simple PHP framework using HMVC architecture
7
-	 *
8
-	 * This content is released under the GNU GPL License (GPL)
9
-	 *
10
-	 * Copyright (C) 2017 Tony NGUEREZA
11
-	 *
12
-	 * This program is free software; you can redistribute it and/or
13
-	 * modify it under the terms of the GNU General Public License
14
-	 * as published by the Free Software Foundation; either version 3
15
-	 * of the License, or (at your option) any later version.
16
-	 *
17
-	 * This program is distributed in the hope that it will be useful,
18
-	 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
-	 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
-	 * GNU General Public License for more details.
21
-	 *
22
-	 * You should have received a copy of the GNU General Public License
23
-	 * along with this program; if not, write to the Free Software
24
-	 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
-	*/
2
+    defined('ROOT_PATH') || exit('Access denied');
3
+    /**
4
+     * TNH Framework
5
+     *
6
+     * A simple PHP framework using HMVC architecture
7
+     *
8
+     * This content is released under the GNU GPL License (GPL)
9
+     *
10
+     * Copyright (C) 2017 Tony NGUEREZA
11
+     *
12
+     * This program is free software; you can redistribute it and/or
13
+     * modify it under the terms of the GNU General Public License
14
+     * as published by the Free Software Foundation; either version 3
15
+     * of the License, or (at your option) any later version.
16
+     *
17
+     * This program is distributed in the hope that it will be useful,
18
+     * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
+     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
+     * GNU General Public License for more details.
21
+     *
22
+     * You should have received a copy of the GNU General Public License
23
+     * along with this program; if not, write to the Free Software
24
+     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
+     */
26 26
 
27
-	class StringHash {
27
+    class StringHash {
28 28
 		 
29
-		 //blowfish
30
-		private static $algo = '$2a';
29
+            //blowfish
30
+        private static $algo = '$2a';
31 31
 		
32
-		//cost parameter
33
-		private static $cost = '$10';
32
+        //cost parameter
33
+        private static $cost = '$10';
34 34
 
35
-		/**
36
-		 * Get the unique salt for the string hash
37
-		 * @return string the unique generated salt
38
-		 */
39
-		private static function uniqueSalt() {
40
-			return substr(sha1(mt_rand()), 0, 22);
41
-		}
35
+        /**
36
+         * Get the unique salt for the string hash
37
+         * @return string the unique generated salt
38
+         */
39
+        private static function uniqueSalt() {
40
+            return substr(sha1(mt_rand()), 0, 22);
41
+        }
42 42
 
43
-		/**
44
-		 * Hash the given string
45
-		 * @param  string $value the plain string text to be hashed
46
-		 * @return string           the hashed string
47
-		 */
48
-		public static function hash($value) {
49
-			return crypt($value, self::$algo .
50
-					self::$cost .
51
-					'$' . self::uniqueSalt());
52
-		}
43
+        /**
44
+         * Hash the given string
45
+         * @param  string $value the plain string text to be hashed
46
+         * @return string           the hashed string
47
+         */
48
+        public static function hash($value) {
49
+            return crypt($value, self::$algo .
50
+                    self::$cost .
51
+                    '$' . self::uniqueSalt());
52
+        }
53 53
 
54
-		/**
55
-		 * Check if the hash and plain string is valid
56
-		 * @param  string $hash     the hashed string
57
-		 * @param  string $plain the plain text
58
-		 * @return boolean  true if is valid or false if not
59
-		 */
60
-		public static function check($hash, $plain) {
61
-			$full_salt = substr($hash, 0, 29);
62
-			$new_hash = crypt($plain, $full_salt);
63
-			return ($hash === $new_hash);
64
-		}	
65
-	}
66 54
\ No newline at end of file
55
+        /**
56
+         * Check if the hash and plain string is valid
57
+         * @param  string $hash     the hashed string
58
+         * @param  string $plain the plain text
59
+         * @return boolean  true if is valid or false if not
60
+         */
61
+        public static function check($hash, $plain) {
62
+            $full_salt = substr($hash, 0, 29);
63
+            $new_hash = crypt($plain, $full_salt);
64
+            return ($hash === $new_hash);
65
+        }	
66
+    }
67 67
\ No newline at end of file
Please login to merge, or discard this patch.
core/libraries/Benchmark.php 1 patch
Indentation   +81 added lines, -81 removed lines patch added patch discarded remove patch
@@ -1,89 +1,89 @@
 block discarded – undo
1 1
 <?php
2
-	defined('ROOT_PATH') or exit('Access denied');
3
-	/**
4
-	 * TNH Framework
5
-	 *
6
-	 * A simple PHP framework using HMVC architecture
7
-	 *
8
-	 * This content is released under the GNU GPL License (GPL)
9
-	 *
10
-	 * Copyright (C) 2017 Tony NGUEREZA
11
-	 *
12
-	 * This program is free software; you can redistribute it and/or
13
-	 * modify it under the terms of the GNU General Public License
14
-	 * as published by the Free Software Foundation; either version 3
15
-	 * of the License, or (at your option) any later version.
16
-	 *
17
-	 * This program is distributed in the hope that it will be useful,
18
-	 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
-	 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
-	 * GNU General Public License for more details.
21
-	 *
22
-	 * You should have received a copy of the GNU General Public License
23
-	 * along with this program; if not, write to the Free Software
24
-	 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
-	*/
2
+    defined('ROOT_PATH') or exit('Access denied');
3
+    /**
4
+     * TNH Framework
5
+     *
6
+     * A simple PHP framework using HMVC architecture
7
+     *
8
+     * This content is released under the GNU GPL License (GPL)
9
+     *
10
+     * Copyright (C) 2017 Tony NGUEREZA
11
+     *
12
+     * This program is free software; you can redistribute it and/or
13
+     * modify it under the terms of the GNU General Public License
14
+     * as published by the Free Software Foundation; either version 3
15
+     * of the License, or (at your option) any later version.
16
+     *
17
+     * This program is distributed in the hope that it will be useful,
18
+     * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
+     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
+     * GNU General Public License for more details.
21
+     *
22
+     * You should have received a copy of the GNU General Public License
23
+     * along with this program; if not, write to the Free Software
24
+     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
+     */
26 26
 
27
-	/**
28
-	 * Class for Benchmark
29
-	 */
30
-	class Benchmark {
31
-		/**
32
-		 * The markers for excution time
33
-		 * @var array
34
-		 */
35
-		private $markersTime = array();
27
+    /**
28
+     * Class for Benchmark
29
+     */
30
+    class Benchmark {
31
+        /**
32
+         * The markers for excution time
33
+         * @var array
34
+         */
35
+        private $markersTime = array();
36 36
 		
37
-		/**
38
-		 * The markers for memory usage
39
-		 * @var array
40
-		 */
41
-		private $markersMemory = array();
37
+        /**
38
+         * The markers for memory usage
39
+         * @var array
40
+         */
41
+        private $markersMemory = array();
42 42
 		
43
-		/**
44
-		 * This method is used to mark one point for benchmark (execution time and memory usage)
45
-		 * @param  string $name the marker name
46
-		 */
47
-		public function mark($name) {
48
-			//Marker for execution time
49
-			$this->markersTime[$name] = microtime(true);
50
-			//Marker for memory usage
51
-			$this->markersMemory[$name] = memory_get_usage(true);
52
-		}
43
+        /**
44
+         * This method is used to mark one point for benchmark (execution time and memory usage)
45
+         * @param  string $name the marker name
46
+         */
47
+        public function mark($name) {
48
+            //Marker for execution time
49
+            $this->markersTime[$name] = microtime(true);
50
+            //Marker for memory usage
51
+            $this->markersMemory[$name] = memory_get_usage(true);
52
+        }
53 53
 		
54
-		/**
55
-		 * This method is used to get the total excution time in second between two markers
56
-		 * @param  string  $startMarkerName the marker for start point
57
-		 * @param  string  $endMarkerName   the marker for end point
58
-		 * @param  integer $decimalCount   the number of decimal
59
-		 * @return string         the total execution time
60
-		 */
61
-		public function elapsedTime($startMarkerName = null, $endMarkerName = null, $decimalCount = 6) {
62
-			if (!$startMarkerName || !isset($this->markersTime[$startMarkerName])) {
63
-				return 0;
64
-			}
54
+        /**
55
+         * This method is used to get the total excution time in second between two markers
56
+         * @param  string  $startMarkerName the marker for start point
57
+         * @param  string  $endMarkerName   the marker for end point
58
+         * @param  integer $decimalCount   the number of decimal
59
+         * @return string         the total execution time
60
+         */
61
+        public function elapsedTime($startMarkerName = null, $endMarkerName = null, $decimalCount = 6) {
62
+            if (!$startMarkerName || !isset($this->markersTime[$startMarkerName])) {
63
+                return 0;
64
+            }
65 65
 			
66
-			if (!isset($this->markersTime[$endMarkerName])) {
67
-				$this->markersTime[$endMarkerName] = microtime(true);
68
-			}
69
-			return number_format($this->markersTime[$endMarkerName] - $this->markersTime[$startMarkerName], $decimalCount);
70
-		}
66
+            if (!isset($this->markersTime[$endMarkerName])) {
67
+                $this->markersTime[$endMarkerName] = microtime(true);
68
+            }
69
+            return number_format($this->markersTime[$endMarkerName] - $this->markersTime[$startMarkerName], $decimalCount);
70
+        }
71 71
 		
72
-		/**
73
-		 * This method is used to get the total memory usage in byte between two markers
74
-		 * @param  string  $startMarkerName the marker for start point
75
-		 * @param  string  $endMarkerName   the marker for end point
76
-		 * @param  integer $decimalCount   the number of decimal
77
-		 * @return string         the total memory usage
78
-		 */
79
-		public function memoryUsage($startMarkerName = null, $endMarkerName = null, $decimalCount = 6) {
80
-			if (!$startMarkerName || !isset($this->markersMemory[$startMarkerName])) {
81
-				return 0;
82
-			}
72
+        /**
73
+         * This method is used to get the total memory usage in byte between two markers
74
+         * @param  string  $startMarkerName the marker for start point
75
+         * @param  string  $endMarkerName   the marker for end point
76
+         * @param  integer $decimalCount   the number of decimal
77
+         * @return string         the total memory usage
78
+         */
79
+        public function memoryUsage($startMarkerName = null, $endMarkerName = null, $decimalCount = 6) {
80
+            if (!$startMarkerName || !isset($this->markersMemory[$startMarkerName])) {
81
+                return 0;
82
+            }
83 83
 			
84
-			if (!isset($this->markersMemory[$endMarkerName])) {
85
-				$this->markersMemory[$endMarkerName] = microtime(true);
86
-			}
87
-			return number_format($this->markersMemory[$endMarkerName] - $this->markersMemory[$startMarkerName], $decimalCount);
88
-		}
89
-	}
84
+            if (!isset($this->markersMemory[$endMarkerName])) {
85
+                $this->markersMemory[$endMarkerName] = microtime(true);
86
+            }
87
+            return number_format($this->markersMemory[$endMarkerName] - $this->markersMemory[$startMarkerName], $decimalCount);
88
+        }
89
+    }
Please login to merge, or discard this patch.
core/libraries/Assets.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
      *  @since 1.0.0
39 39
      *  @filesource
40 40
      */
41
-    class Assets extends BaseStaticClass{
41
+    class Assets extends BaseStaticClass {
42 42
 
43 43
 
44 44
         /**
@@ -53,13 +53,13 @@  discard block
 block discarded – undo
53 53
          *  @param string $asset the name of the assets file path with the extension.
54 54
          *  @return string|null the absolute path of the assets file, if it exists otherwise returns null if the file does not exist.
55 55
          */
56
-        public static function path($asset){
56
+        public static function path($asset) {
57 57
             $logger = self::getLogger();	
58 58
             $path = ASSETS_PATH . $asset;
59 59
 			
60 60
             $logger->debug('Including the Assets file [' . $path . ']');
61 61
             //Check if the file exists
62
-            if(file_exists($path)){
62
+            if (file_exists($path)) {
63 63
                 $logger->info('Assets file [' . $path . '] included successfully');
64 64
                 return Url::base_url($path);
65 65
             }
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
          *  @param string $path the name of the css file without the extension.
80 80
          *  @return string|null the absolute path of the css file, if it exists otherwise returns null if the file does not exist.
81 81
          */
82
-        public static function css($path){
82
+        public static function css($path) {
83 83
             $logger = self::getLogger();
84 84
             /*
85 85
 			* if the file name contains the ".css" extension, replace it with 
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
 			
91 91
             $logger->debug('Including the Assets file [' . $path . '] for CSS');
92 92
             //Check if the file exists
93
-            if(file_exists($path)){
93
+            if (file_exists($path)) {
94 94
                 $logger->info('Assets file [' . $path . '] for CSS included successfully');
95 95
                 return Url::base_url($path);
96 96
             }
@@ -110,12 +110,12 @@  discard block
 block discarded – undo
110 110
          *  @param string $path the name of the javascript file without the extension.
111 111
          *  @return string|null the absolute path of the javascript file, if it exists otherwise returns null if the file does not exist.
112 112
          */
113
-        public static function js($path){
113
+        public static function js($path) {
114 114
             $logger = self::getLogger();
115 115
             $path = str_ireplace('.js', '', $path);
116 116
             $path = ASSETS_PATH . 'js/' . $path . '.js';
117 117
             $logger->debug('Including the Assets file [' . $path . '] for javascript');
118
-            if(file_exists($path)){
118
+            if (file_exists($path)) {
119 119
                 $logger->info('Assets file [' . $path . '] for Javascript included successfully');
120 120
                 return Url::base_url($path);
121 121
             }
@@ -135,11 +135,11 @@  discard block
 block discarded – undo
135 135
          *  @param string $path the name of the image file with the extension.
136 136
          *  @return string|null the absolute path of the image file, if it exists otherwise returns null if the file does not exist.
137 137
          */
138
-        public static function img($path){
138
+        public static function img($path) {
139 139
             $logger = self::getLogger();
140 140
             $path = ASSETS_PATH . 'images/' . $path;
141 141
             $logger->debug('Including the Assets file [' . $path . '] for image');
142
-            if(file_exists($path)){
142
+            if (file_exists($path)) {
143 143
                 $logger->info('Assets file [' . $path . '] for image included successfully');
144 144
                 return Url::base_url($path);
145 145
             }
Please login to merge, or discard this patch.
core/libraries/Pagination.php 2 patches
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -42,14 +42,14 @@  discard block
 block discarded – undo
42 42
          * Create an instance of pagination
43 43
          * @param array $overwriteConfig the list of configuration to overwrite the defined configuration in config_pagination.php
44 44
          */
45
-        public function __construct(array $overwriteConfig = array()){
46
-            if (file_exists(CONFIG_PATH . 'config_pagination.php')){
45
+        public function __construct(array $overwriteConfig = array()) {
46
+            if (file_exists(CONFIG_PATH . 'config_pagination.php')) {
47 47
                 $config = array();
48 48
                 require_once CONFIG_PATH . 'config_pagination.php';
49
-                if (empty($config) || ! is_array($config)){
49
+                if (empty($config) || !is_array($config)) {
50 50
                     show_error('No configuration found in ' . CONFIG_PATH . 'config_pagination.php');
51 51
                 }
52
-                else{
52
+                else {
53 53
                     $config = array_merge($config, $overwriteConfig);
54 54
                     $this->config = $config;
55 55
                     //put it gobally
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
              * @param string $paginationQueryString the new value
98 98
              * @return object
99 99
              */
100
-        public function setPaginationQueryString($paginationQueryString){
100
+        public function setPaginationQueryString($paginationQueryString) {
101 101
             $this->paginationQueryString = $paginationQueryString;
102 102
             return $this;
103 103
         }
@@ -108,22 +108,22 @@  discard block
 block discarded – undo
108 108
          * 
109 109
          * @return object
110 110
          */
111
-        public function determinePaginationQueryStringValue(){
111
+        public function determinePaginationQueryStringValue() {
112 112
             $pageQueryName = $this->config['page_query_string_name'];
113 113
             $queryString = Url::queryString();
114 114
             $currentUrl = Url::current();
115 115
             $query = '';
116
-                if ($queryString == ''){
116
+                if ($queryString == '') {
117 117
                 $query = '?' . $pageQueryName . '=';
118
-            } else{
118
+            } else {
119 119
                 $tab = explode($pageQueryName . '=', $queryString);
120 120
                 $nb = count($tab);
121
-                if ($nb == 1){
121
+                if ($nb == 1) {
122 122
                     $query = '?' . $queryString . '&' . $pageQueryName . '=';
123
-                } else{
124
-                    if ($tab[0] == ''){
123
+                } else {
124
+                    if ($tab[0] == '') {
125 125
                         $query = '?' . $pageQueryName . '=';
126
-                    } else{
126
+                    } else {
127 127
                         $query = '?' . $tab[0] . '' . $pageQueryName . '=';
128 128
                     }
129 129
                 }
@@ -141,10 +141,10 @@  discard block
 block discarded – undo
141 141
          * 
142 142
          * @return string the pagination link
143 143
          */
144
-        public function getLink($totalRows, $currentPageNumber){
144
+        public function getLink($totalRows, $currentPageNumber) {
145 145
             $numberOfLink = $this->config['nb_link'];
146 146
             $numberOfRowPerPage = $this->config['pagination_per_page'];
147
-            if (empty($this->paginationQueryString)){
147
+            if (empty($this->paginationQueryString)) {
148 148
                 //determine the pagination query string value
149 149
                 $this->determinePaginationQueryStringValue();
150 150
             }
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
             $numberOfLink = (int) $numberOfLink;
156 156
             $numberOfRowPerPage = (int) $numberOfRowPerPage;
157 157
 			
158
-            if ($currentPageNumber <= 0){
158
+            if ($currentPageNumber <= 0) {
159 159
                 $currentPageNumber = 1;
160 160
             }
161 161
             if ($numberOfPage <= 1 || $numberOfLink <= 0 || $numberOfRowPerPage <= 0) {
@@ -170,18 +170,18 @@  discard block
 block discarded – undo
170 170
          * @param  int $numberOfPage      the total number of page
171 171
          * @return string
172 172
          */
173
-        protected function buildPaginationNavbar($currentPageNumber, $numberOfPage){
173
+        protected function buildPaginationNavbar($currentPageNumber, $numberOfPage) {
174 174
             $values = $this->getPaginationBeginAndEndNumber($currentPageNumber, $numberOfPage);
175 175
             $begin = $values['begin'];
176 176
             $end   = $values['end'];
177 177
             $navbar = null;
178
-            if ($currentPageNumber == 1){
178
+            if ($currentPageNumber == 1) {
179 179
                 $navbar .= $this->buildPaginationLinkForFirstPage($begin, $end, $currentPageNumber);
180 180
             }
181
-            else if ($currentPageNumber > 1 && $currentPageNumber < $numberOfPage){
181
+            else if ($currentPageNumber > 1 && $currentPageNumber < $numberOfPage) {
182 182
                 $navbar .= $this->buildPaginationLinkForMiddlePage($begin, $end, $currentPageNumber);
183 183
             }
184
-            else if ($currentPageNumber == $numberOfPage){
184
+            else if ($currentPageNumber == $numberOfPage) {
185 185
                 $navbar .= $this->buildPaginationLinkForLastPage($begin, $end, $currentPageNumber);
186 186
             }
187 187
             $navbar = $this->config['pagination_open'] . $navbar . $this->config['pagination_close'];
Please login to merge, or discard this patch.
Braces   +10 added lines, -20 removed lines patch added patch discarded remove patch
@@ -48,16 +48,14 @@  discard block
 block discarded – undo
48 48
                 require_once CONFIG_PATH . 'config_pagination.php';
49 49
                 if (empty($config) || ! is_array($config)){
50 50
                     show_error('No configuration found in ' . CONFIG_PATH . 'config_pagination.php');
51
-                }
52
-                else{
51
+                } else{
53 52
                     $config = array_merge($config, $overwriteConfig);
54 53
                     $this->config = $config;
55 54
                     //put it gobally
56 55
                     Config::setAll($config);
57 56
                     unset($config);
58 57
                 }
59
-            }
60
-            else {
58
+            } else {
61 59
                 show_error('Unable to find the pagination configuration file');
62 60
             }
63 61
         }
@@ -177,11 +175,9 @@  discard block
 block discarded – undo
177 175
             $navbar = null;
178 176
             if ($currentPageNumber == 1){
179 177
                 $navbar .= $this->buildPaginationLinkForFirstPage($begin, $end, $currentPageNumber);
180
-            }
181
-            else if ($currentPageNumber > 1 && $currentPageNumber < $numberOfPage){
178
+            } else if ($currentPageNumber > 1 && $currentPageNumber < $numberOfPage){
182 179
                 $navbar .= $this->buildPaginationLinkForMiddlePage($begin, $end, $currentPageNumber);
183
-            }
184
-            else if ($currentPageNumber == $numberOfPage){
180
+            } else if ($currentPageNumber == $numberOfPage){
185 181
                 $navbar .= $this->buildPaginationLinkForLastPage($begin, $end, $currentPageNumber);
186 182
             }
187 183
             $navbar = $this->config['pagination_open'] . $navbar . $this->config['pagination_close'];
@@ -202,20 +198,17 @@  discard block
 block discarded – undo
202 198
             if ($numberOfLink % 2 == 0) {
203 199
                 $start = $currentPageNumber - ($numberOfLink / 2) + 1;
204 200
                 $end   = $currentPageNumber + ($numberOfLink / 2);
205
-            }
206
-            else {
201
+            } else {
207 202
                 $start = $currentPageNumber - floor($numberOfLink / 2);
208 203
                 $end   = $currentPageNumber + floor($numberOfLink / 2);
209 204
             }
210 205
             if ($start <= 1) {
211 206
                 $begin = 1;
212 207
                 $end   = $numberOfLink;
213
-            }
214
-            else if ($start > 1 && $end < $numberOfPage) {
208
+            } else if ($start > 1 && $end < $numberOfPage) {
215 209
                 $begin = $start;
216 210
                 $end = $end;
217
-            }
218
-            else {
211
+            } else {
219 212
                 $begin = ($numberOfPage - $numberOfLink) + 1;
220 213
                 $end   = $numberOfPage;
221 214
             }
@@ -242,8 +235,7 @@  discard block
 block discarded – undo
242 235
             for ($i = $begin; $i <= $end; $i++) {
243 236
                 if ($i == $currentPageNumber) {
244 237
                     $navbar .= $this->config['active_link_open'] . $currentPageNumber . $this->config['active_link_close'];
245
-                }
246
-                else {
238
+                } else {
247 239
                     $navbar .= $this->config['digit_open'] 
248 240
                             . '<a href="' . $query . $i . '" ' . attributes_to_string($this->config['attributes']) . '>' . $i . '</a>' 
249 241
                             . $this->config['digit_close'];
@@ -271,8 +263,7 @@  discard block
 block discarded – undo
271 263
             for ($i = $begin; $i <= $end; $i++) {
272 264
                 if ($i == $currentPageNumber) {
273 265
                     $navbar .= $this->config['active_link_open'] . $currentPageNumber . $this->config['active_link_close'];
274
-                }
275
-                else {
266
+                } else {
276 267
                     $navbar .= $this->config['digit_open'] 
277 268
                                     . '<a href="' . $query . $i . '"' . attributes_to_string($this->config['attributes']) . '>' . $i . '</a>' 
278 269
                                     . $this->config['digit_close'];
@@ -300,8 +291,7 @@  discard block
 block discarded – undo
300 291
                     $navbar .= $this->config['active_link_open'] 
301 292
                                 . $currentPageNumber 
302 293
                                 . $this->config['active_link_close'];
303
-                }
304
-                else {
294
+                } else {
305 295
                     $navbar .= $this->config['digit_open'] 
306 296
                                 . '<a href="' . $query . $i . '"' . attributes_to_string($this->config['attributes']) . '>' . $i . '</a>' 
307 297
                                 . $this->config['digit_close'];
Please login to merge, or discard this patch.
core/libraries/FormValidation.php 2 patches
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -245,11 +245,11 @@  discard block
 block discarded – undo
245 245
             $this->_forceFail = false;
246 246
 
247 247
             foreach ($this->getData() as $inputName => $inputVal) {
248
-    			if(is_array($this->data[$inputName])){
249
-    				$this->data[$inputName] = array_map('trim', $this->data[$inputName]);
250
-    			} else{
251
-    				$this->data[$inputName] = trim($this->data[$inputName]);
252
-    			}
248
+                if(is_array($this->data[$inputName])){
249
+                    $this->data[$inputName] = array_map('trim', $this->data[$inputName]);
250
+                } else{
251
+                    $this->data[$inputName] = trim($this->data[$inputName]);
252
+                }
253 253
 
254 254
                 if (array_key_exists($inputName, $this->_rules)) {
255 255
                     foreach ($this->_parseRuleString($this->_rules[$inputName]) as $eachRule) {
@@ -613,7 +613,7 @@  discard block
 block discarded – undo
613 613
                     $this->_setError($inputName, $ruleName, $this->_getLabel($inputName));
614 614
                 }
615 615
             } else if($inputVal == '') {
616
-				$this->_setError($inputName, $ruleName, $this->_getLabel($inputName));
616
+                $this->_setError($inputName, $ruleName, $this->_getLabel($inputName));
617 617
             }
618 618
         }
619 619
 
Please login to merge, or discard this patch.
Spacing   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -25,13 +25,13 @@  discard block
 block discarded – undo
25 25
      */
26 26
 
27 27
 
28
-        class FormValidation extends BaseClass{
28
+        class FormValidation extends BaseClass {
29 29
 		 
30 30
         /**
31 31
          * The form validation status
32 32
          * @var boolean
33 33
          */
34
-        protected $_success  = false;
34
+        protected $_success = false;
35 35
 
36 36
         /**
37 37
          * The list of errors messages
@@ -40,31 +40,31 @@  discard block
 block discarded – undo
40 40
         protected $_errorsMessages = array();
41 41
         
42 42
         // Array of rule sets, fieldName => PIPE seperated ruleString
43
-        protected $_rules             = array();
43
+        protected $_rules = array();
44 44
         
45 45
         // Array of errors, niceName => Error Message
46
-        protected $_errors             = array();
46
+        protected $_errors = array();
47 47
         
48 48
         // Array of post Key => Nice name labels
49
-        protected $_labels          = array();
49
+        protected $_labels = array();
50 50
         
51 51
         /**
52 52
          * The errors delimiters
53 53
          * @var array
54 54
          */
55
-        protected $_allErrorsDelimiter   = array('<div class="error">', '</div>');
55
+        protected $_allErrorsDelimiter = array('<div class="error">', '</div>');
56 56
 
57 57
         /**
58 58
          * The each error delimiter
59 59
          * @var array
60 60
          */
61
-        protected $_eachErrorDelimiter   = array('<p class="error">', '</p>');
61
+        protected $_eachErrorDelimiter = array('<p class="error">', '</p>');
62 62
         
63 63
         /**
64 64
          * Indicated if need force the validation to be failed
65 65
          * @var boolean
66 66
          */
67
-        protected $_forceFail            = false;
67
+        protected $_forceFail = false;
68 68
 
69 69
         /**
70 70
          * The list of the error messages overrides by the original
@@ -177,7 +177,7 @@  discard block
 block discarded – undo
177 177
          *
178 178
          * @return string the function name
179 179
          */
180
-        protected function _toCallCase($funcName, $prefix='_validate') {
180
+        protected function _toCallCase($funcName, $prefix = '_validate') {
181 181
             $funcName = strtolower($funcName);
182 182
             $finalFuncName = $prefix;
183 183
             foreach (explode('_', $funcName) as $funcNamePart) {
@@ -221,13 +221,13 @@  discard block
 block discarded – undo
221 221
          * Validate the CSRF 
222 222
          * @return void 
223 223
          */
224
-        protected function validateCSRF(){
225
-            if(get_instance()->request->method() == 'POST'){
224
+        protected function validateCSRF() {
225
+            if (get_instance()->request->method() == 'POST') {
226 226
                 $this->logger->debug('Check if CSRF is enabled in configuration');
227 227
                 //first check for CSRF
228
-                if (get_config('csrf_enable', false) && ! Security::validateCSRF()){
228
+                if (get_config('csrf_enable', false) && !Security::validateCSRF()) {
229 229
                     show_error('Invalide data, Cross Site Request Forgery do his job, the data to validate is corrupted.');
230
-                } else{
230
+                } else {
231 231
                     $this->logger->info('CSRF is not enabled in configuration or not set manully, no need to check it');
232 232
                 }
233 233
             }
@@ -245,9 +245,9 @@  discard block
 block discarded – undo
245 245
             $this->_forceFail = false;
246 246
 
247 247
             foreach ($this->getData() as $inputName => $inputVal) {
248
-    			if(is_array($this->data[$inputName])){
248
+    			if (is_array($this->data[$inputName])) {
249 249
     				$this->data[$inputName] = array_map('trim', $this->data[$inputName]);
250
-    			} else{
250
+    			} else {
251 251
     				$this->data[$inputName] = trim($this->data[$inputName]);
252 252
     			}
253 253
 
@@ -460,25 +460,25 @@  discard block
 block discarded – undo
460 460
             /*
461 461
             //////////////// hack for regex rule that can contain "|"
462 462
             */
463
-            if(strpos($ruleString, 'regex') !== false){
463
+            if (strpos($ruleString, 'regex') !== false) {
464 464
                 $regexRule = array();
465 465
                 $rule = '#regex\[\/(.*)\/([a-zA-Z0-9]?)\]#';
466 466
                 preg_match($rule, $ruleString, $regexRule);
467 467
                 $ruleStringTemp = preg_replace($rule, '', $ruleString);
468
-                    if(!empty($regexRule[0])){
468
+                    if (!empty($regexRule[0])) {
469 469
                         $ruleSets[] = $regexRule[0];
470 470
                     }
471 471
                     $ruleStringRegex = explode('|', $ruleStringTemp);
472 472
                 foreach ($ruleStringRegex as $rule) {
473 473
                     $rule = trim($rule);
474
-                    if($rule){
474
+                    if ($rule) {
475 475
                         $ruleSets[] = $rule;
476 476
                     }
477 477
                 }
478 478
                  
479 479
             }
480 480
             /***********************************/
481
-            else{
481
+            else {
482 482
                 if (strpos($ruleString, '|') !== FALSE) {
483 483
                     $ruleSets = explode('|', $ruleString);
484 484
                 } else {
@@ -607,12 +607,12 @@  discard block
 block discarded – undo
607 607
          */
608 608
         protected function _validateRequired($inputName, $ruleName, array $ruleArgs) {
609 609
             $inputVal = $this->post($inputName);
610
-            if(array_key_exists(1, $ruleArgs) && function_exists($ruleArgs[1])) {
610
+            if (array_key_exists(1, $ruleArgs) && function_exists($ruleArgs[1])) {
611 611
                 $callbackReturn = $this->_runEmptyCallback($ruleArgs[1]);
612 612
                 if ($inputVal == '' && $callbackReturn == true) {
613 613
                     $this->_setError($inputName, $ruleName, $this->_getLabel($inputName));
614 614
                 }
615
-            } else if($inputVal == '') {
615
+            } else if ($inputVal == '') {
616 616
 				$this->_setError($inputName, $ruleName, $this->_getLabel($inputName));
617 617
             }
618 618
         }
@@ -638,7 +638,7 @@  discard block
 block discarded – undo
638 638
         protected function _validateCallback($inputName, $ruleName, array $ruleArgs) {
639 639
             if (function_exists($ruleArgs[1]) && !empty($this->data[$inputName])) {
640 640
                 $result = $this->_runCallback($this->data[$inputName], $ruleArgs[1]);
641
-                if(! $result){
641
+                if (!$result) {
642 642
                     $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName)));
643 643
                 }
644 644
             }
@@ -671,7 +671,7 @@  discard block
 block discarded – undo
671 671
                         $this->_setError($inputName, $ruleName . ',post:key', array($this->_getLabel($inputName), $this->_getLabel(str_replace('post:', '', $doNotEqual))));
672 672
                         continue;
673 673
                     }
674
-                } else{
674
+                } else {
675 675
                     if ($inputVal == $doNotEqual) {
676 676
                         $this->_setError($inputName, $ruleName . ',string', array($this->_getLabel($inputName), $doNotEqual));
677 677
                         continue;
@@ -813,9 +813,9 @@  discard block
 block discarded – undo
813 813
          */
814 814
         protected function _validateExists($inputName, $ruleName, array $ruleArgs) {
815 815
             $inputVal = $this->post($inputName);
816
-            if (! is_object($this->databaseInstance)){
816
+            if (!is_object($this->databaseInstance)) {
817 817
                 $obj = & get_instance();
818
-                if(isset($obj->database)){
818
+                if (isset($obj->database)) {
819 819
                     $this->databaseInstance = $obj->database;
820 820
                 } 
821 821
             }
@@ -850,7 +850,7 @@  discard block
 block discarded – undo
850 850
                                                         ->where($column, $inputVal);
851 851
             $this->databaseInstance->get();
852 852
             if ($this->databaseInstance->numRows() > 0) {
853
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
853
+                if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
854 854
                     return;
855 855
                 }
856 856
                 $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName)));
@@ -865,14 +865,14 @@  discard block
 block discarded – undo
865 865
          */
866 866
         protected function _validateIsUniqueUpdate($inputName, $ruleName, array $ruleArgs) {
867 867
             $inputVal = $this->post($inputName);
868
-            if (! is_object($this->databaseInstance)){
868
+            if (!is_object($this->databaseInstance)) {
869 869
                 $obj = & get_instance();
870
-                if(isset($obj->database)){
870
+                if (isset($obj->database)) {
871 871
                     $this->databaseInstance = $obj->database;
872 872
                 } 
873 873
             }
874 874
             $data = explode(',', $ruleArgs[1]);
875
-            if(count($data) < 2){
875
+            if (count($data) < 2) {
876 876
                 return;
877 877
             }
878 878
             list($table, $column) = explode('.', $data[0]);
@@ -882,7 +882,7 @@  discard block
 block discarded – undo
882 882
                                                         ->where($field, '!=', trim($val));
883 883
             $this->databaseInstance->get();
884 884
             if ($this->databaseInstance->numRows() > 0) {
885
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
885
+                if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
886 886
                     return;
887 887
                 }
888 888
                 $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName)));
@@ -916,8 +916,8 @@  discard block
 block discarded – undo
916 916
         protected function _validateRegex($inputName, $ruleName, array $ruleArgs) {
917 917
             $inputVal = $this->post($inputName);
918 918
             $regex = $ruleArgs[1];
919
-            if (! preg_match($regex, $inputVal)) {
920
-                if (! $this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
919
+            if (!preg_match($regex, $inputVal)) {
920
+                if (!$this->_fieldIsRequired($inputName) && empty($this->data[$inputName])) {
921 921
                     return;
922 922
                 }
923 923
                 $this->_setError($inputName, $ruleName, array($this->_getLabel($inputName)));
Please login to merge, or discard this patch.
core/libraries/PDF.php 2 patches
Indentation   +71 added lines, -71 removed lines patch added patch discarded remove patch
@@ -1,79 +1,79 @@
 block discarded – undo
1 1
 <?php
2
-	defined('ROOT_PATH') or exit('Access denied');
3
-	/**
4
-	 * TNH Framework
5
-	 *
6
-	 * A simple PHP framework using HMVC architecture
7
-	 *
8
-	 * This content is released under the GNU GPL License (GPL)
9
-	 *
10
-	 * Copyright (C) 2017 Tony NGUEREZA
11
-	 *
12
-	 * This program is free software; you can redistribute it and/or
13
-	 * modify it under the terms of the GNU General Public License
14
-	 * as published by the Free Software Foundation; either version 3
15
-	 * of the License, or (at your option) any later version.
16
-	 *
17
-	 * This program is distributed in the hope that it will be useful,
18
-	 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
-	 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
-	 * GNU General Public License for more details.
21
-	 *
22
-	 * You should have received a copy of the GNU General Public License
23
-	 * along with this program; if not, write to the Free Software
24
-	 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
-	*/
2
+    defined('ROOT_PATH') or exit('Access denied');
3
+    /**
4
+     * TNH Framework
5
+     *
6
+     * A simple PHP framework using HMVC architecture
7
+     *
8
+     * This content is released under the GNU GPL License (GPL)
9
+     *
10
+     * Copyright (C) 2017 Tony NGUEREZA
11
+     *
12
+     * This program is free software; you can redistribute it and/or
13
+     * modify it under the terms of the GNU General Public License
14
+     * as published by the Free Software Foundation; either version 3
15
+     * of the License, or (at your option) any later version.
16
+     *
17
+     * This program is distributed in the hope that it will be useful,
18
+     * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
+     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
+     * GNU General Public License for more details.
21
+     *
22
+     * You should have received a copy of the GNU General Public License
23
+     * along with this program; if not, write to the Free Software
24
+     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
+     */
26 26
 
27
-	/**
28
-	 * PDF library to generate PDF document using the library DOMPDF
29
-	 */
30
-	class PDF extends BaseClass {
27
+    /**
28
+     * PDF library to generate PDF document using the library DOMPDF
29
+     */
30
+    class PDF extends BaseClass {
31 31
 		
32
-		/**
33
-		 * The dompdf instance
34
-		 * @var Dompdf
35
-		 */
36
-		private $dompdf = null;
32
+        /**
33
+         * The dompdf instance
34
+         * @var Dompdf
35
+         */
36
+        private $dompdf = null;
37 37
 		
38
-		/**
39
-		 * Create PDF library instance
40
-		 */
41
-		public function __construct() {
42
-			parent::__construct();
38
+        /**
39
+         * Create PDF library instance
40
+         */
41
+        public function __construct() {
42
+            parent::__construct();
43 43
 
44
-			require_once VENDOR_PATH . 'dompdf/dompdf_config.inc.php';
45
-			$this->dompdf = new Dompdf();
46
-		}
44
+            require_once VENDOR_PATH . 'dompdf/dompdf_config.inc.php';
45
+            $this->dompdf = new Dompdf();
46
+        }
47 47
 
48
-		/**
49
-		 * Generate PDF document
50
-		 * @param  string  $html        the HTML content to use for generation
51
-		 * @param  string  $filename    the generated PDF document filename
52
-		 * @param  boolean $stream      if need send the generated PDF to browser for download
53
-		 * @param  string  $paper       the PDF document paper type like 'A4', 'A5', 'letter', etc.
54
-		 * @param  string  $orientation the PDF document orientation like 'portrait', 'landscape'
55
-		 * @return string|void               if $stream is true send PDF document to browser for download, else return the generated PDF
56
-		 * content like to join in Email attachment of for other purpose use.
57
-		 */
58
-		public function generate($html, $filename = 'output.pdf', $stream = true, $paper = 'A4', $orientation = 'portrait'){
59
-			$this->logger->info('Generating of PDF document: filename [' .$filename. '], stream [' .($stream ? 'TRUE':'FALSE'). '], paper [' .$paper. '], orientation [' .$orientation. ']');
60
-			$this->dompdf->load_html($html);
61
-			$this->dompdf->set_paper($paper, $orientation);
62
-			$this->dompdf->render();
63
-			if($stream){
64
-				$this->dompdf->stream($filename);
65
-			} else{
66
-				return $this->dompdf->output();
67
-			}
68
-		}
48
+        /**
49
+         * Generate PDF document
50
+         * @param  string  $html        the HTML content to use for generation
51
+         * @param  string  $filename    the generated PDF document filename
52
+         * @param  boolean $stream      if need send the generated PDF to browser for download
53
+         * @param  string  $paper       the PDF document paper type like 'A4', 'A5', 'letter', etc.
54
+         * @param  string  $orientation the PDF document orientation like 'portrait', 'landscape'
55
+         * @return string|void               if $stream is true send PDF document to browser for download, else return the generated PDF
56
+         * content like to join in Email attachment of for other purpose use.
57
+         */
58
+        public function generate($html, $filename = 'output.pdf', $stream = true, $paper = 'A4', $orientation = 'portrait'){
59
+            $this->logger->info('Generating of PDF document: filename [' .$filename. '], stream [' .($stream ? 'TRUE':'FALSE'). '], paper [' .$paper. '], orientation [' .$orientation. ']');
60
+            $this->dompdf->load_html($html);
61
+            $this->dompdf->set_paper($paper, $orientation);
62
+            $this->dompdf->render();
63
+            if($stream){
64
+                $this->dompdf->stream($filename);
65
+            } else{
66
+                return $this->dompdf->output();
67
+            }
68
+        }
69 69
 		
70
-		/**
71
-		* Return the instance of Dompdf
72
-		*
73
-		* @return object the dompdf instance
74
-		*/
75
-		public function getDompdf() {
76
-			return $this->dompdf;
77
-		}
70
+        /**
71
+         * Return the instance of Dompdf
72
+         *
73
+         * @return object the dompdf instance
74
+         */
75
+        public function getDompdf() {
76
+            return $this->dompdf;
77
+        }
78 78
 		
79
-	}
79
+    }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -55,14 +55,14 @@
 block discarded – undo
55 55
 		 * @return string|void               if $stream is true send PDF document to browser for download, else return the generated PDF
56 56
 		 * content like to join in Email attachment of for other purpose use.
57 57
 		 */
58
-		public function generate($html, $filename = 'output.pdf', $stream = true, $paper = 'A4', $orientation = 'portrait'){
59
-			$this->logger->info('Generating of PDF document: filename [' .$filename. '], stream [' .($stream ? 'TRUE':'FALSE'). '], paper [' .$paper. '], orientation [' .$orientation. ']');
58
+		public function generate($html, $filename = 'output.pdf', $stream = true, $paper = 'A4', $orientation = 'portrait') {
59
+			$this->logger->info('Generating of PDF document: filename [' . $filename . '], stream [' . ($stream ? 'TRUE' : 'FALSE') . '], paper [' . $paper . '], orientation [' . $orientation . ']');
60 60
 			$this->dompdf->load_html($html);
61 61
 			$this->dompdf->set_paper($paper, $orientation);
62 62
 			$this->dompdf->render();
63
-			if($stream){
63
+			if ($stream) {
64 64
 				$this->dompdf->stream($filename);
65
-			} else{
65
+			} else {
66 66
 				return $this->dompdf->output();
67 67
 			}
68 68
 		}
Please login to merge, or discard this patch.
core/libraries/Upload.php 1 patch
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
      *    @package FileUpload
38 38
      *    @version 1.5
39 39
      */
40
-    class Upload extends BaseClass{
40
+    class Upload extends BaseClass {
41 41
 
42 42
         /**
43 43
          *   Version
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
          *    @version    1.0
70 70
          *    @var        array
71 71
          */
72
-        private $file_array    = array();
72
+        private $file_array = array();
73 73
 
74 74
         /**
75 75
          *    If the file you are trying to upload already exists it will
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
          *    @version    1.0
120 120
          *    @var        float
121 121
          */
122
-        private $max_file_size= 0.0;
122
+        private $max_file_size = 0.0;
123 123
 
124 124
         /**
125 125
          *    List of allowed mime types
@@ -211,11 +211,11 @@  discard block
 block discarded – undo
211 211
          *    @return    object
212 212
          *    @method    object    __construct
213 213
          */
214
-        public function __construct(){
214
+        public function __construct() {
215 215
             parent::__construct();
216 216
 
217 217
             Loader::lang('file_upload');
218
-            $obj =& get_instance();
218
+            $obj = & get_instance();
219 219
 
220 220
             $this->error_messages = array(
221 221
                 'upload_err_ini_size' => $obj->lang->get('fu_upload_err_ini_size'),
@@ -470,8 +470,8 @@  discard block
 block discarded – undo
470 470
                     if (mkdir($destination_directory, 0775, true)) {
471 471
                         $this->destination_directory = $destination_directory;
472 472
                         chdir($destination_directory);
473
-                    } else{
474
-                        $this->logger->warning('Can not create the upload directory [' .$destination_directory. ']');
473
+                    } else {
474
+                        $this->logger->warning('Can not create the upload directory [' . $destination_directory . ']');
475 475
                     }
476 476
                 }
477 477
             }
@@ -617,12 +617,12 @@  discard block
 block discarded – undo
617 617
          *    @return    boolean
618 618
          *    @method    boolean    save
619 619
          */
620
-        public function save(){
620
+        public function save() {
621 621
             if (count($this->file_array) > 0 && array_key_exists($this->input, $this->file_array)) {
622 622
                 // set original filename if not have a new name
623 623
                 if (empty($this->filename)) {
624 624
                     $this->filename = $this->file_array[$this->input]['name'];
625
-                } else{
625
+                } else {
626 626
                     // Replace %s for extension in filename
627 627
                     // Before: /[\w\d]*(.[\d\w]+)$/i
628 628
                     // After: /^[\s[:alnum:]\-\_\.]*\.([\d\w]+)$/iu
@@ -745,21 +745,21 @@  discard block
 block discarded – undo
745 745
          * Check if file upload has error
746 746
          * @return boolean
747 747
          */
748
-        protected function uploadHasError(){
748
+        protected function uploadHasError() {
749 749
             //check if file upload is  allowed in the configuration
750
-            if(! ini_get('file_uploads')){
750
+            if (!ini_get('file_uploads')) {
751 751
                 $this->setError($this->error_messages['file_uploads']);
752 752
                 return true;
753 753
             }
754 754
 
755 755
                 //check for php upload error
756
-            if(is_numeric($this->file['error']) && $this->file['error'] > 0){
756
+            if (is_numeric($this->file['error']) && $this->file['error'] > 0) {
757 757
                 $this->setError($this->getPhpUploadErrorMessageByCode($this->file['error']));
758 758
                 return true;
759 759
             }
760 760
             
761 761
             //check for mime type
762
-            if (! $this->checkMimeType($this->file['mime'])) {
762
+            if (!$this->checkMimeType($this->file['mime'])) {
763 763
                 $this->setError($this->error_messages['accept_file_types']);
764 764
                 return true;
765 765
             }
Please login to merge, or discard this patch.