Skip to content

Instantly share code, notes, and snippets.

@chadclark
Last active August 29, 2015 14:16
Show Gist options
  • Save chadclark/57cc4802980b38cfaaed to your computer and use it in GitHub Desktop.
Save chadclark/57cc4802980b38cfaaed to your computer and use it in GitHub Desktop.
EE 1.x to Statamic Conversion
{assign_variable:master_weblog_name="blahg"}
{exp:rss:feed weblog="blahg"}
<?xml version="1.0" encoding="UTF-8"?>
<!-- This is a WordPress eXtended RSS file generated by ExpressionEngine as an export of your blog. -->
<!-- It contains information about your blog's posts, comments, trackbacks and categories. -->
<!-- You use this file to transfer content from your ExpressionEngine blog to your WordPress blog. -->
<!-- To import this information into a WordPress blog follow these steps. -->
<!-- 1. Log into that blog as an administrator. -->
<!-- 2. Go to Tools: Import in the blog's admin panels (or Manage: Import in older versions of WordPress). -->
<!-- 3. Choose "WordPress" from the list. -->
<!-- 4. Upload this file using the form provided on that page. -->
<!-- 5. You will first be asked to map the authors in this export file to users -->
<!-- on the blog. For each author, you may choose to map to an -->
<!-- existing user on the blog or to create a new user -->
<!-- 6. WordPress will then import each of the posts, comments, trackbacks and categories -->
<!-- contained in this file into your blog -->
<!-- generator="WordPress/2.8.4" created="2009-09-20 01:49"-->
<rss version="2.0"
xmlns:excerpt="http://wordpress.org/export/1.0/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.0/"
>
<channel>
<title>{weblog_name}</title>
<link>http://also-ran.com/blahg</link>
<description>{weblog_description}</description>
<pubDate></pubDate>
<generator>http://wordpress.org/?v=2.8.4</generator>
<language>{weblog_language}</language>
<wp:wxr_version>1.0</wp:wxr_version>
<wp:base_site_url>{trimmed_url}</wp:base_site_url>
<wp:base_blog_url>{trimmed_url}</wp:base_blog_url>
{exp:weblog:entries weblog="blahg" limit="999" rdf="off" dynamic_start="on" disable="member_data|trackbacks|pagination"}
<item>
<title>{exp:xml_encode}{title}{/exp:xml_encode}</title>
<link></link>
<pubDate>{entry_date format="%r"}</pubDate>
<dc:creator><![CDATA[{author}]]></dc:creator>
{categories}
<category><![CDATA[{category_name}]]></category>
<category domain="category" nicename="{category_name}"><![CDATA[{category_name}]]></category>
{/categories}
<guid isPermaLink="false"></guid>
<description></description>
<content:encoded><![CDATA[{blahg_copy}]]></content:encoded>
<wp:post_id></wp:post_id>
<wp:post_date>{entry_date format="%Y-%m-%d %H:%i:%s"}</wp:post_date>
<wp:post_date_gmt>{gmt_date format="%Y-%m-%d %H:%i:%s"}</wp:post_date_gmt>
<wp:comment_status>open</wp:comment_status>
<wp:ping_status>open</wp:ping_status>
<wp:post_name>{url_title}</wp:post_name>
<wp:status>publish</wp:status>
<wp:post_parent>0</wp:post_parent>
<wp:menu_order>0</wp:menu_order>
<wp:post_type>post</wp:post_type>
<wp:post_password></wp:post_password>
{embed="export/comments" the_entry_id="{entry_id}"}
</item>
{/exp:weblog:entries}
</channel>
</rss>
{/exp:rss:feed}
<?php
// USAGE: php convert.php
// Edit the details below to your needs
$wp_file = 'data/blahg.xml';
$export_folder = '_import/blahg/'; // existing files will be over-written, use with care
if (file_exists($wp_file)) {
$xml = simplexml_load_file($wp_file);
$count = 0;
foreach ($xml->channel->item as $item) {
$count ++;
print "Exporting: (".$count.") " . $item->title."\n";
$title = $item->title;
$tags = array();
$categories = array();
$item_date = strtotime($item->pubDate);
$file_name = $export_folder.date("Y-m-d", $item_date)."-".slugify($title).".md";
if ($title == '') {
$title = 'Untitled post';
}
foreach($item->category as $taxonomy) {
if ($taxonomy['domain'] == 'post_tag') {
$tags[] = $taxonomy['nicename'];
}
if ($taxonomy['domain'] == 'category') {
$categories[] = $taxonomy['nicename'];
}
}
print " -- filename: ".$file_name;
$markdown = "---\n";
$markdown .= "title: '" . $title ."'\n";
if (sizeof($tags)) {
$markdown .= "tags:\n - ".implode("\n - ", $tags)."\n";
}
if (sizeof($categories)) {
$markdown .= "categories:\n - ".implode("\n - ", $categories)."\n";
}
$markdown .= "meta_title: " . $title . "\n";
$markdown .= "meta_description: \n";
$markdown .= "meta_image: \n";
$markdown .= "meta_og_title: \n";
$markdown .= "meta_og_description: \n";
$markdown .= "meta_og_type: article\n";
$markdown .= "meta_twitter_title: " . $title . "\n";
$markdown .= "meta_twitter_description: \n";
$markdown .= "meta_twitter_type: summary\n";
$markdown .= "excerpt: \n";
$markdown .= "content_builder:\n";
$markdown .= " -\n";
$markdown .= " type: content_block\n";
$markdown .= " content: '" . str_replace(array("\n", "\t", "\r"), '', $item->children('content', true)->encoded) . "'\n";
$markdown .= "---\n";
//$markdown .= $item->children('content', true)->encoded;
$markdown .= "\n";
file_put_contents($file_name, $markdown);
print "\n";
}
}
// Credit: http://sourcecookbook.com/en/recipes/8/function-to-slugify-strings-in-php
function slugify($text)
{
// replace non letter or digits by -
$text = preg_replace('~[^\\pL\d]+~u', '-', $text);
// trim
$text = trim($text, '-');
// transliterate
if (function_exists('iconv'))
{
$text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);
}
// lowercase
$text = strtolower($text);
// remove unwanted characters
$text = preg_replace('~[^-\w]+~', '', $text);
if (empty($text))
{
return 'n-a';
}
return $text;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment