Ejemplo n.º 1
0
function blog_import($file, $dropoldcontent)
{
    global $blog;
    if ($dropoldcontent) {
        $blog['pdo']->exec(<<<SQL
\t\t\t\t\tDROP TABLE {$blog['tablePrefix']}Info;
SQL
);
        $blog['pdo']->exec(<<<SQL
\t\t\t\t\tDROP TABLE {$blog['tablePrefix']}Articles;
SQL
);
        $blog['pdo']->exec(<<<SQL
\t\t\t\t\tDROP TABLE {$blog['tablePrefix']}Comments;
SQL
);
        init_blog_db();
    }
    // Open the xml file
    $xml = simplexml_load_file($file);
    foreach ($xml->children() as $article) {
        if ($article->getName() == "item") {
            $stmt = $blog['pdo']->prepare("INSERT INTO {$blog['tablePrefix']}Articles(ID, Title, Timestamp, Content, RateTotal, RateCount, Draft) \r\n\t\t\t\t\t\t\t\t\t\t VALUES (:id, :title, :timestamp, :content, :rateTotal, :rateCount, :draft)");
            $stmt->bindValue(":id", intval($article->id));
            $stmt->bindValue(":title", $article->title);
            $stmt->bindValue(":timestamp", intval(strtotime($article->timestamp)));
            $stmt->bindValue(":content", $article->content);
            $stmt->bindValue(":rateTotal", intval($article->rateTotal));
            $stmt->bindValue(":rateCount", intval($article->rateCount));
            $stmt->bindValue(":draft", intval($article->draft));
            $stmt->execute();
            foreach ($article->comments->children() as $comment) {
                if ($comment->getName() == "comment") {
                    try {
                        $stmt = $blog['pdo']->prepare("INSERT INTO {$blog['tablePrefix']}Comments(ID, IDArticle, Name, Email, Website, Content, PendingReview, ByAuthor, TimeStamp) VALUES (:id, :idarticle, :name, :email, :website, :content, :pendingreview, :byauthor, :timestamp)");
                        $stmt->bindValue(":id", intval($comment->id));
                        $stmt->bindValue(":idarticle", intval($article->id));
                        $stmt->bindValue(":name", $comment->name);
                        $stmt->bindValue(":email", $comment->email);
                        $stmt->bindValue(":website", $comment->website);
                        $stmt->bindValue(":content", $comment->content);
                        $stmt->bindValue(":pendingreview", intval($comment->pending));
                        $stmt->bindValue(":byauthor", intval($comment->byauthor));
                        $stmt->bindValue(":timestamp", intval(strtotime($comment->timestamp)));
                        $stmt->execute();
                    } catch (Exception $e) {
                        throw new Exception("Error inserting comment " . intval($comment->id) . " + " . intval($article->id));
                    }
                }
            }
        }
    }
}
Ejemplo n.º 2
0
function upgrade()
{
    init_blog_db();
    jabRedirect(blog_link(""));
}