Skip to content

Instantly share code, notes, and snippets.

@dilantha
Created September 17, 2013 11:04
Show Gist options
  • Save dilantha/6592883 to your computer and use it in GitHub Desktop.
Save dilantha/6592883 to your computer and use it in GitHub Desktop.
Some WordPress import code in Laravel 3.
<?php
class Import_Controller extends Base_Controller {
public $restful = TRUE;
public function get_index()
{
// code here..
return View::make('import.index');
}
public function post_wordpress()
{
Input::upload('wp-file', 'storage/temp', 'wp_export.xml');
$xml = simplexml_load_file('storage/temp/wp_export.xml');
foreach ($xml->channel->item as $item) {
$namespaces = $item->getNameSpaces(true);
$xml_content = $item->children($namespaces['content']);
var_dump($item);
$post = new Post;
$post->title = $item->title;
$post->type = 'article';
$post->date = date("Y-m-d H:i:s", strtotime($item->pubDate));
$post->body = $xml_content->encoded;
var_dump($post);
$post->save();
break;
}
// return Redirect::to('import');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment