Exemple #1
0
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 "";
}
Exemple #2
0
function run_sql($sql, $arg = array(), $fatal = true)
{
    global $sql_open;
    global $sql_dbh;
    global $sql_server;
    global $sql_error;
    if (substr($sql_server, 0, 4) == "http") {
        $request = array("sql" => $sql, "count" => count($arg));
        for ($i = 0; $i < count($arg); $i++) {
            if (is_int($arg[$i])) {
                $request["type_{$i}"] = "int";
            } else {
                if (is_numeric($arg[$i])) {
                    $request["type_{$i}"] = "float";
                } else {
                    $request["{$type_}{$i}"] = "string";
                }
            }
            $request["value_{$i}"] = $arg[$i];
        }
        $request = map_to_url_string($request);
        $body = http_slap($sql_server, $request);
        $row = array();
        $a = explode("\n", trim($body));
        for ($i = 0; $i < count($a); $i++) {
            if ($a[$i] != "") {
                $row[] = map_from_tag_string($a[$i]);
            }
        }
    } else {
        if (!$sql_open) {
            open_database();
        }
        $sth = $sql_dbh->prepare($sql);
        try {
            //if (string_has($sql_server, "sqlsrv:")) {
            //	// XXX: bug workaround - can't bind a zero length string when using mssql native client
            //	for ($i = 0; $i < count($arg); $i++) {
            //		if (is_string($arg[$i])) {
            //			if ($arg[$i] == "") {
            //				$arg[$i] = " ";
            //			}
            //		}
            //	}
            //}
            $sth->execute($arg);
            if ($sth->columnCount() == 0) {
                return;
            }
            $row = $sth->fetchAll();
        } catch (PDOException $exception) {
            $msg = $exception->getMessage();
            $sql_error = "sql [{$sql}] arg [" . implode(", ", $arg) . "] msg [{$msg}]";
            if ($fatal) {
                default_error($sql_error);
            }
            return false;
        }
    }
    return $row;
}