if (empty(self::Types[$type])) return null;
return self::Types[$type];
}
+
+ private static function _finfo(&$content,&$info) {
+ if (!$content) return;
+
+ static $finfo;
+ if (!isset($finfo)) $finfo = new finfo(FILEINFO_MIME);
+
+ $type = $finfo->buffer($content);
+ if (! preg_match('/^([^\/]+\/([^\s;]+)).*$/',$type,$m) ) return;
+ $info['mime'] = $m[1];
+ $info['ext'] = $m[2];
+ #if ($info['ext'] == 'jpeg') debug($m);
+ return true;
+ }
+
+ public static function getContent($content) {
+ if (!$content) return;
+
+ static $finfo;
+ if (!isset($finfo)) $finfo = new finfo(FILEINFO_MIME);
+
+ $type = $finfo->buffer($content);
+ if (! preg_match('/^([^\/]+\/([^\s;]+)).*$/',$type,$m) ) return;
+ return $m[1];
+ }
+
+ public static function html(&$str) {
+
+ if (!$str) return $str;
+
+ if (is_array($str)) {
+ foreach ($str as $k => $v) {
+ $str[$k] = self::html($v);
+ }
+ return $str;
+ }
+
+ $mime = self::getContent($str);
+
+ if (preg_match('@^image/@',$mime)) {
+ $v = self::is_base64($str) ? $v : base64_encode($str);
+ return '<img src="data:image/jpeg;base64,'.$v.'" />';
+ }
+
+ return $str;
+ }
+
+ private static function is_base64($str) {
+ static $done = 0;
+ if (!$done) {
+ require_once(realpath(dirname(__FILE__).'/nb.php'));
+ $done = 1;
+ }
+ return Nb::is_base64($str);
+ }
}
#var_export(Http::msg(500));
* format ar variable for scalar output
*/
public static function row_parse(&$row,$o=[]) {
- foreach ($row as $k => $v) {
+ if (empty($o['no_format'])) foreach ($row as $k => $v) {
$row[$k] = self::format($v,null,$o);
}
if (isset($o['row_parse_post'])) {
if (empty($head)) $head = [];
if (empty($this->default_limit)) $this->default_limit = $this->db->limits[0];
- # NB 31.01.18: Move to out.php or ldap.php
- $exp = '^(jpegPhoto)$';
- if ($fct === null and $this->is_html) $fct = function(&$r) use ($exp) {
- static $i; # to detect first header line
- if ($i) foreach ($r as $k => $v) {
- #$finfo = new finfo(FILEINFO_MIME); debug( $finfo->buffer($v) );
- if ($v and preg_match("/$exp/",$k) and $this->is_base64($v)) {
- $r[$k] = '<img src="data:image/jpeg;base64,'.$v.'" />';
- #debug($r);
- }
- }
- $i++;
- };
-
// Write output
if ($this->expires and !preg_match('/^(dump|insert|update|replace|rm|vi)$/',$this->params['action'])) $this->page->expires = $this->expires;
if (empty($this->_nopage)) {
$row_parse_post = $this->db()->row_parse_post;
return;
}
+ # nb 31.01.18: move to out.php or ldap.php
+ if ($this->is_html) mime::html($r);
+
if (empty($row_parse_post)) return;
$row_parse_post($r,$this->table);
}
public static function form_hidden($r) {
$h = '';
- foreach ($r as $k => $v) {
- $h .= '<input type="hidden" name="'.htmlentities($k).'" value="'.htmlentities($v).'"/>';
+ #debug($r);
+ foreach ($r as $k => $values) {
+ $values = (array)$values;
+ $suff = count($values)>1 ? '[]' : '';
+ foreach ($values as $v) {
+ $h .= '<input type="hidden" name="'.htmlentities($k).$suff.'" value="'.htmlentities($v).'"/>';
+ }
}
return $h;
}