Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Change these
- $databaseHostname = "localhost";
- $databaseName = "musiny";
- $databaseUser = "root";
- $databasePassword = "changeme";
- $fileName = "export.xml";
- $wordpressPostType = "post";
- //
- // Do not edit below this line
- // =============================================================================
- // =============================================================================
- $pdo = new \PDO("mysql:host={$databaseHostname};dbname={$databaseName};charset=utf8", $databaseUser, $databasePassword);
- $pdo->exec("set names utf8");
- $xmlFile = __DIR__ . "/" . $fileName;
- $xmlBeginning = '
- <?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>
- ';
- file_put_contents($xmlFile, $xmlBeginning);
- $iteration = 0;
- $batchSize = 1000;
- do {
- $limit = $batchSize;
- $offset = $batchSize * $iteration;
- $statement = $pdo->query("
- SELECT *
- FROM spodeli
- WHERE cat = '69'
- AND title NOT LIKE '%София – Ден и Нощ%'
- GROUP by title
- ORDER BY added ASC
- LIMIT {$limit}
- OFFSET {$offset}
- ");
- $songs = $statement->fetchAll(\PDO::FETCH_ASSOC);
- $xmlItems = "";
- foreach ($songs as $song) {
- $xmlItems .= <<<XML
- <item>
- <title>{$song["title"]}</title>
- <description></description>
- <content:encoded><![CDATA[{$song["info"]}]]></content:encoded>
- <excerpt:encoded><![CDATA[]]></excerpt:encoded>
- <wp:status>publish</wp:status>
- <wp:post_type>{$wordpressPostType}</wp:post_type>
- </item>
- XML;
- }
- file_put_contents($xmlFile, $xmlItems, FILE_APPEND);
- $iteration++;
- } while ($songs && !empty($songs));
- $xmlEnd = '
- </channel>
- </rss>
- ';
- file_put_contents($xmlFile, $xmlEnd, FILE_APPEND);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement