aboutsummaryrefslogtreecommitdiffstats
path: root/include/text.php
diff options
context:
space:
mode:
authorMario Vavti <mario@mariovavti.com>2018-06-05 10:36:37 +0200
committerMario Vavti <mario@mariovavti.com>2018-06-05 10:36:37 +0200
commit30c00df4f324b0934861195e1f04e36063ef3590 (patch)
tree2bfeefa16655781f89bbab1507e713cd70248e90 /include/text.php
parent6019a34da2184519bc535fa771b30695d9580b92 (diff)
parente1b85a361cf53fd7bb79ef24d9d5b0dfb145fccf (diff)
downloadvolse-hubzilla-30c00df4f324b0934861195e1f04e36063ef3590.tar.gz
volse-hubzilla-30c00df4f324b0934861195e1f04e36063ef3590.tar.bz2
volse-hubzilla-30c00df4f324b0934861195e1f04e36063ef3590.zip
Merge remote-tracking branch 'mike/master' into dev
Diffstat (limited to 'include/text.php')
-rw-r--r--include/text.php28
1 files changed, 20 insertions, 8 deletions
diff --git a/include/text.php b/include/text.php
index 4a84c09f8..a8c28d7bd 100644
--- a/include/text.php
+++ b/include/text.php
@@ -3186,21 +3186,33 @@ function array2XML($obj, $array) {
*
* @param string $table
* @param array $arr
+ * @param array $binary_fields - fields which will be cleansed with dbescbin rather than dbesc; this is critical for postgres
* @return boolean|PDOStatement
*/
-function create_table_from_array($table, $arr) {
+function create_table_from_array($table, $arr, $binary_fields = []) {
if(! ($arr && $table))
return false;
- if(dbesc_array($arr)) {
- $r = dbq("INSERT INTO " . TQUOT . $table . TQUOT . " (" . TQUOT
- . implode(TQUOT . ', ' . TQUOT, array_keys($arr))
- . TQUOT . ") VALUES ('"
- . implode("', '", array_values($arr))
- . "')"
- );
+ $clean = [];
+ foreach($arr as $k => $v) {
+ $matches = false;
+ if(preg_match('/([^a-zA-Z0-9\-\_\.])/',$k,$matches)) {
+ return false;
+ }
+ if(in_array($k,$binary_fields)) {
+ $clean[$k] = dbescbin($v);
+ }
+ else {
+ $clean[$k] = dbesc($v);
+ }
}
+ $r = dbq("INSERT INTO " . TQUOT . $table . TQUOT . " (" . TQUOT
+ . implode(TQUOT . ', ' . TQUOT, array_keys($clean))
+ . TQUOT . ") VALUES ('"
+ . implode("', '", array_values($clean))
+ . "')"
+ );
return $r;
}