Skip to content

Commit 7510693

Browse files
committed
Add secureData method and options
Add secureData method and options
1 parent 8091aa8 commit 7510693

File tree

3 files changed

+35
-9
lines changed

3 files changed

+35
-9
lines changed

config/config.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,11 @@
2525
* @var integer sent_email_ttl : Sent email time to live in days.
2626
* After that TTL, a sent email can be trashed/flushed.
2727
*/
28-
'sent_email_ttl' => 390
28+
'sent_email_ttl' => 390,
29+
30+
/**
31+
* @var boolean secure_data : Secure raw data before inserting it into database
32+
* (doing a pdo quote on all external stored datas)
33+
*/
34+
'secure_data' => true
2935
];

src/classes/modeles/AbstrModeles.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,26 @@ public function create_table($table_map_query)
4949

5050

5151

52+
/**
53+
* Secure Data before inserting it into database
54+
*
55+
* @param string $data : data value
56+
* @param string $type : data type (integer, boolean, email)
57+
* @param boolean $html : use htmlentities
58+
*
59+
* @return mixed data value formated and secured
60+
*/
61+
protected function secureData($data, $type='', $html=false)
62+
{
63+
if ($this->secure_data) {
64+
return \BfwMailer\Helpers\Secure::secureData($data, $type, $html);
65+
}
66+
67+
return $data;
68+
}
69+
70+
71+
5272
/**
5373
* Fetching, verifying and returning data on a Sql Fetch
5474
*

src/classes/modeles/Content.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ public function create_table($table_map_query = null)
5555
public function search($subject, $body, $alt_body, $attachments)
5656
{
5757
$req = $this->select()->from($this->tableName, '*')
58-
->where(self::DB_SUBJECT. '=:sub', array(':sub' => $subject))
59-
->where(self::DB_BODY. '=:body', array(':body' => $body))
60-
->where(self::DB_ALT_BODY. '=:altb', array(':altb' => $alt_body))
61-
->where(self::DB_ATTACHMENTS.'=:att', array(':att' => $attachments))
58+
->where(self::DB_SUBJECT. '=:sub', array(':sub' => $this->secureData($subject)))
59+
->where(self::DB_BODY. '=:body', array(':body' => $this->secureData($body, '', true)))
60+
->where(self::DB_ALT_BODY. '=:altb', array(':altb' => $this->secureData($alt_body)))
61+
->where(self::DB_ATTACHMENTS.'=:att', array(':att' => $this->secureData($attachments)))
6262
->limit(1);
6363
$result = $this->fetch_sql($req, 'fetchRow');
6464

@@ -83,10 +83,10 @@ public function search($subject, $body, $alt_body, $attachments)
8383
public function add($subject, $body, $alt_body, $attachments)
8484
{
8585
$content = array(
86-
self::DB_SUBJECT => $subject,
87-
self::DB_BODY => \BfwMailer\Helpers\Secure::secureData($body, 'string', true),
88-
self::DB_ALT_BODY => $alt_body,
89-
self::DB_ATTACHMENTS => $attachments
86+
self::DB_SUBJECT => $this->secureData($subject),
87+
self::DB_BODY => $this->secureData($body, '', true),
88+
self::DB_ALT_BODY => $this->secureData($alt_body),
89+
self::DB_ATTACHMENTS => $this->secureData($attachments)
9090
);
9191

9292
$req = $this->insert()->into($this->tableName, $content)->execute();

0 commit comments

Comments
 (0)