function html_allow_tags($s, $allow)
{
    $s = html_once(trim($s));
    preg_match_all('#<([a-z]+)>#i', $allow, $match);
    foreach ($match[1] as $tag) {
        $s = preg_replace('#&lt;' . $tag . '\\s+style\\s*=\\s*&quot;([^"<>]+)&quot;\\s*&gt;#i', '<' . $tag . ' style="$1">', $s);
        $s = str_replace('&lt;' . $tag . '&gt;', '<' . $tag . '>', $s);
        $s = str_replace('&lt;/' . $tag . '&gt;', '</' . $tag . '>', $s);
    }
    return $s;
}
示例#2
0
function import($file, $ignore_errors = false, $transaction = false, $force_myisam = false, $query_start = false)
{
    // @import PHP
    global $db_driver, $db_link, $db_charset;
    if ($ignore_errors && $transaction) {
        echo '<div>You cannot select both: ignoring errors and transaction</div>';
        exit;
    }
    $count_errors = 0;
    set_time_limit(0);
    $fp = fopen($file, 'r');
    if (!$fp) {
        exit('fopen(' . $file . ') failed');
    }
    flock($fp, 1);
    $text = trim(fread($fp, filesize($file)));
    flock($fp, 3);
    fclose($fp);
    if ($force_myisam) {
        $text = preg_replace('#TYPE\\s*=\\s*InnoDB#i', 'TYPE=MyISAM', $text);
    }
    $text = preg_split("#;(\r\n|\n|\r)#", $text);
    $x = 0;
    echo '<div>Ignoring errors: <b>' . ($ignore_errors ? 'Yes' : 'No') . '</b></div>';
    echo '<div>Transaction: <b>' . ($transaction ? 'Yes' : 'No') . '</b></div>';
    echo '<div>Force MyIsam: <b>' . ($force_myisam ? 'Yes' : 'No') . '</b></div>';
    echo '<div>Query start: <b>#' . $query_start . '</b></div>';
    echo '<div>Queries found: <b>' . count($text) . '</b></div>';
    echo '<div>Executing ...</div>';
    flush();
    if ($transaction) {
        echo '<div>BEGIN;</div>';
        db_begin();
    }
    $time = time_start();
    $query_start = (int) $query_start;
    if (!$query_start) {
        $query_start = 1;
    }
    $query_no = 0;
    foreach ($text as $key => $value) {
        $x++;
        $query_no++;
        if ($query_start > $query_no) {
            continue;
        }
        if ('mysql' == $db_driver) {
            $result = @mysql_query($value . ';', $db_link);
        }
        if ('pgsql' == $db_driver) {
            $result = @pg_query($db_link, $value . ';');
        }
        if (!$result) {
            $x--;
            if (!$count_errors) {
                echo '<table class="ls" cellspacing="1"><tr><th width="25%">Error</th><th>Query</th></tr>';
            }
            $count_errors++;
            echo '<tr><td>#' . $query_no . ' ' . db_error() . ')' . '</td><td>' . nl2br(html_once($value)) . '</td></tr>';
            flush();
            if (!$ignore_errors) {
                echo '</table>';
                echo '<div><span style="color: red;"><b>Import failed.</b></span></div>';
                echo '<div>Queries executed: <b>' . ($x - $query_start + 1) . '</b>.</div>';
                if ($transaction) {
                    echo '<div>ROLLBACK;</div>';
                    db_rollback();
                }
                echo '<br><div><a href="' . $_SERVER['PHP_SELF'] . '?import=1">&lt;&lt; go back</a></div>';
                exit;
            }
        }
    }
    if ($count_errors) {
        echo '</table>';
    }
    if ($transaction) {
        echo '<div>COMMIT;</div>';
        db_end();
    }
    echo '<div><span style="color: green;"><b>Import finished.</b></span></div>';
    echo '<div>Queries executed: <b>' . ($x - $query_start + 1) . '</b>.</div>';
    echo '<div>Time: <b>' . time_end($time) . '</b> sec</div>';
    echo '<br><div><a href="' . $_SERVER['PHP_SELF'] . '?import=1">&lt;&lt; go back</a></div>';
}