function clean_tag($tag) { $clean = ""; $tag = trim($tag); if (substr($tag, 0, 1) == "/") { $end = true; $tag = substr($tag, 1); } else { $end = false; } $type = string_next($tag, " "); //print "type [$type]\n"; if ($type == "br") { return "<br/>"; } if ($type == "b" || $type == "i" || $type == "u" || $type == "s" || $type == "q" || $type == "strong" || $type == "em") { if ($type == "strong") { $type = "b"; } else { if ($type == "em") { $type = "i"; } } if ($end) { return "</{$type}>FORCEWHITESPACE"; } else { return "FORCEWHITESPACE<{$type}>"; } } //if ($type == "p" || $type == "ol" || $type == "ul" || $type == "li" || $type == "pre") { //if ($type == "pre") { if ($type == "ol" || $type == "ul" || $type == "li" || $type == "pre" || $type == "blockquote") { if ($end) { return "</{$type}>"; } else { return "<{$type}>"; } } if ($type == "a") { if ($end) { if ($type == "a") { return "</a>FORCEWHITESPACE"; } else { return "</{$type}>"; } } $tag = str_replace(" ", "", $tag); $tag = str_replace("\"", "\" ", $tag); $tag = str_replace("=\" ", "=\"", $tag); $tag = trim($tag); $map_old = map_from_tag_string($tag); $map_new = array(); if ($type == "a") { $map_new["href"] = @$map_old["href"]; } if (count($map_new) == 0) { return "<{$type}>"; } else { if ($type == "a") { return "FORCEWHITESPACE<{$type} " . map_to_tag_string($map_new) . ">"; } else { return "<{$type} " . map_to_tag_string($map_new) . ">"; } } } return ""; }
function db_get_rec($table, $id) { global $db_table; global $cache_enabled; if ($cache_enabled && !is_array($id)) { $cache_key = "{$table}.rec.{$id}"; $s = cache_get($cache_key); if ($s !== false) { //print "cached\n"; return map_from_conf_string($s); } //print "not cached\n"; } if (!array_key_exists($table, $db_table)) { die("unknown table [{$table}]"); } $key = $db_table[$table]["key"]; $col = $db_table[$table]["col"]; if (is_array($id)) { $k = array_keys($id); $a = array(); $sql = "select * from {$table} where "; for ($i = 0; $i < count($id); $i++) { $sql .= $k[$i] . ' = ? and '; $a[] = $id[$k[$i]]; } $sql = substr($sql, 0, -5); $row = run_sql($sql, $a); } else { $row = run_sql("select * from {$table} where {$key} = ?", array($id)); } if (count($row) == 0) { if (is_array($id)) { die("record not found - table [{$table}] id [" . map_to_tag_string($id) . "]"); } else { die("record not found - table [{$table}] id [{$id}]"); } } $rec = array(); for ($i = 0; $i < count($col); $i++) { $rec[$col[$i]] = $row[0][$col[$i]]; } if ($cache_enabled && !is_array($id)) { cache_set($cache_key, map_to_conf_string($rec)); } return $rec; }