}
return (is_array($array) && count($array) > 0);
}
+
+ /**
+ * @brief Callback function for "esc_array"
+ *
+ * @param mixed $value Array value
+ * @param string $key Array key
+ * @param boolean $add_quotation add quoatation marks for string values
+ */
+ private static function esc_array_callback(&$value, $key, $add_quotation) {
+
+ if (!$add_quotation) {
+ if (is_bool($value)) {
+ $value = ($value ? '1' : '0');
+ } else {
+ $value = dbesc($value);
+ }
+ return;
+ }
+
+ if (is_bool($value)) {
+ $value = ($value ? 'true' : 'false');
+ } elseif (is_numeric($value)) {
+ $value = (string)$value;
+ } else {
+ $value = "'".dbesc($value)."'";
+ }
+ }
+
+ /**
+ * @brief Escapes a whole array
+ *
+ * @param mixed $arr Array with values to be escaped
+ * @param boolean $add_quotation add quoatation marks for string values
+ */
+ public static function esc_array(&$arr, $add_quotation = false) {
+ array_walk($arr, 'self::esc_array_callback', $add_quotation);
+ }
}
?>
$msg["seen"] = 0;
$msg["replied"] = 0;
- dbesc_array($msg);
+ dbm::esc_array($msg, true);
- $r = dbq("INSERT INTO `mail` (`".implode("`, `", array_keys($msg))."`) VALUES ('".implode("', '", array_values($msg))."')");
+ $r = dbq("INSERT INTO `mail` (`".implode("`, `", array_keys($msg))."`) VALUES (".implode(", ", array_values($msg)).")");
// send notifications.
// Store the unescaped version
$unescaped = $arr;
- dbesc_array($arr);
+ dbm::esc_array($arr, true);
logger('item_store: ' . print_r($arr,true), LOGGER_DATA);
$r = dbq("INSERT INTO `item` (`"
. implode("`, `", array_keys($arr))
- . "`) VALUES ('"
- . implode("', '", array_values($arr))
- . "')");
+ . "`) VALUES ("
+ . implode(", ", array_values($arr))
+ . ")");
// And restore it
$arr = $unescaped;
$photo = $parms["photo"];
// Escape the entire array
-
- dbesc_array($parms);
-
+ dbm::esc_array($parms);
/*
* Create a contact record on our site for the other person
$parms['issued-id'] = $issued_id;
$photo = $parms["photo"];
- dbesc_array($parms);
+ dbm::esc_array($parms);
$r = q("INSERT INTO `contact` ( `uid`, `created`, `url`, `nurl`, `addr`, `name`, `nick`, `issued-id`, `photo`, `site-pubkey`,
`request`, `confirm`, `notify`, `poll`, `poco`, `network`, `blocked`, `pending` )
VALUES ( %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d )",
$r1[0]['net-publish'] = 0;
$r1[0]['profile-name'] = dbesc($name);
- dbesc_array($r1[0]);
+ dbm::esc_array($r1[0], true);
$r2 = dbq("INSERT INTO `profile` (`"
. implode("`, `", array_keys($r1[0]))
- . "`) VALUES ('"
- . implode("', '", array_values($r1[0]))
- . "')" );
+ . "`) VALUES ("
+ . implode(", ", array_values($r1[0]))
+ . ")" );
$r3 = q("SELECT `id` FROM `profile` WHERE `uid` = %d AND `profile-name` = '%s' LIMIT 1",
intval(local_user()),