Last active
May 28, 2017 20:37
-
-
Save chiliec/ea43a75aaa65543ee008e97ec55aba7b to your computer and use it in GitHub Desktop.
export posts to wordpress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
date_default_timezone_set('America/Los_Angeles'); | |
$mysqli = new mysqli("localhost:8889", "root", "root", "kripipastacom"); | |
if ($mysqli->connect_errno) { | |
echo "Не удалось подключиться к MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error; | |
} | |
$file = fopen('export.xml', "w+"); | |
$header = '<?xml version="1.0" encoding="UTF-8" ?> | |
<rss version="2.0" | |
xmlns:excerpt="http://wordpress.org/export/1.2/excerpt/" | |
xmlns:content="http://purl.org/rss/1.0/modules/content/" | |
xmlns:wfw="http://wellformedweb.org/CommentAPI/" | |
xmlns:dc="http://purl.org/dc/elements/1.1/" | |
xmlns:wp="http://wordpress.org/export/1.2/" | |
> | |
<channel> | |
<wp:wxr_version>1.2</wp:wxr_version> | |
<wp:author></wp:author>'; | |
$footer = '</channel> | |
</rss>'; | |
fwrite($file, $header); | |
$res = $mysqli->query("SELECT id, title, content, create_time, url, approved FROM kp_story WHERE approved != 2 ORDER BY id ASC"); | |
$res->data_seek(0); | |
while ($row = $res->fetch_assoc()) { | |
$likes = $mysqli->query("SELECT id FROM kp_rating WHERE model_id = 0 AND target_id = " . $row['id'] . " AND value = 1")->num_rows; | |
$dislikes = $mysqli->query("SELECT id FROM kp_rating WHERE model_id = 0 AND target_id = " . $row['id'] . " AND value = 0")->num_rows; | |
$text = ' | |
<item> | |
<title>' . htmlspecialchars($row['title']) . '</title> | |
<description></description> | |
<content:encoded><![CDATA[' . htmlspecialchars(str_replace('<img src="', '<img src="http://kripipasta.com', $row['content'])) . ']]></content:encoded> | |
<excerpt:encoded><![CDATA[]]></excerpt:encoded> | |
<wp:status>publish</wp:status> | |
<wp:post_type>post</wp:post_type> | |
<pubDate>' . date('D, d F Y h:i:s +0000') . '</pubDate> | |
<wp:post_date><![CDATA[' . date('Y-m-d h:i:s', $row['create_time']) . ']]></wp:post_date> | |
<wp:post_date_gmt><![CDATA[' . date('Y-m-d h:i:s', $row['create_time']) . ']]></wp:post_date_gmt> | |
<category domain="category" nicename="strange"><![CDATA["Разное"]]></category> | |
<wp:post_type>post</wp:post_type> | |
<wp:postmeta> | |
<wp:meta_key><![CDATA[vortex_system_dislikes]]></wp:meta_key> | |
<wp:meta_value><![CDATA[' . $dislikes . ']]></wp:meta_value> | |
</wp:postmeta> | |
<wp:postmeta> | |
<wp:meta_key><![CDATA[vortex_system_likes]]></wp:meta_key> | |
<wp:meta_value><![CDATA[' . $likes . ']]></wp:meta_value> | |
</wp:postmeta> | |
</item>'; | |
fwrite($file, $text); | |
} | |
fwrite($file, $footer); | |
fclose($file); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment