Skip to content

Commit

Permalink
Merge pull request #5 from camfindlay/3.1
Browse files Browse the repository at this point in the history
3.1 Branch into master for SS3.1 compatibility
  • Loading branch information
camfindlay committed Jan 26, 2014
2 parents 94cd3eb + d52b55d commit c157832
Show file tree
Hide file tree
Showing 13 changed files with 165 additions and 112 deletions.
Binary file added .DS_Store
Binary file not shown.
22 changes: 22 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
language: php

php:
- 5.3

env:
- DB=MYSQL CORE_RELEASE=3.1
- DB=SQLITE CORE_RELEASE=3.1

matrix:
include:
- php: 5.4
env: DB=MYSQL CORE_RELEASE=3.1

before_script:
- git clone git://github.com/silverstripe-labs/silverstripe-travis-support.git ~/travis-support
- php ~/travis-support/travis_setup.php --source `pwd` --target ~/builds/ss
- cd ~/builds/ss
- "if [ -d silverstripe-wordpressimport ]; then mv silverstripe-wordpressimport wordpressimport; fi;"

script:
- phpunit wordpressimport/tests/
1 change: 0 additions & 1 deletion CHANGELOG

This file was deleted.

24 changes: 0 additions & 24 deletions LICENSE

This file was deleted.

54 changes: 0 additions & 54 deletions README

This file was deleted.

71 changes: 71 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#Wordpress Import Module
[![Build Status](https://travis-ci.org/camfindlay/silverstripe-wordpressimport.png?branch=master)](https://travis-ci.org/camfindlay/silverstripe-wordpressimport)

##Maintainer Contacts
* Cam Findlay (Nickname: camfindlay) <cam (at) silverstripe.com>
* Damian Mooyman (Nickname: tractorcow) <damian (dot) mooyman (at) gmail (dot) com>


##Requirements
* mod_rewrite (optional, if you need to cater for old incoming links and are using Apache)
* SilverStripe Framework & CMS 3.1.x
* silverstripe/blog
* silverstripe/comments

##Installation Instructions

composer require silverstripe/wordpressimport 0.3.*

###Usage Overview
It will change any links to uploaded images and
files in your posts that follow the convention
"http://yourdomain.com/wp-content/uploads/yyyy/mm/filesname.jpg"
to "http://yourdomain.com/assets/Uploads/yyyy/mm/filesname.jpg"
which allows you to migrate you uploaded images
and files over to SilverStripe assets folder while maintaining
images in your posts.

###Optional Rewriting
Add this in your .htaccess file to port old
wordpress posts in the form /yyyy/mm/name-of-post/
to new SilverStripe /blog/name-of-post convention.


RewriteRule ^[0-9]{4}/[0-9]{2}/(.*)$ /blog/$1 [R,L]


##Known issues:
1. Content can lose a lot of the formatting coming from Wordpress.
1. Perhaps parsing the content through a nl2br might help?
1. Image captions need to be catered for and styled otherwise they end up looking like un-parse shortcodes.


##License
Copyright (c) 2008, Silverstripe Ltd.
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Silverstripe Ltd. nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY Silverstripe Ltd. ``AS IS'' AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL Silverstripe Ltd. BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.




9 changes: 0 additions & 9 deletions _config.php
Original file line number Diff line number Diff line change
@@ -1,10 +1 @@
<?php
// Add wordpress import extension to BlogHolder page type
if (class_exists('BlogHolder'))
{
Object::add_extension('BlogHolder', 'WpImporter');
Object::add_extension('BlogEntry', 'WpImportedObject');
}

if(class_exists('Comment'))
Object::add_extension('Comment', 'WpImportedObject');
12 changes: 12 additions & 0 deletions _config/wordpressimport.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
Name: wordpressimport
---
BlogHolder:
extensions:
- WpImporter
BlogEntry:
extensions:
- WpImportedObject
Comment:
extensions:
- WpImportedObject
10 changes: 3 additions & 7 deletions code/WpImportedObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@

class WpImportedObject extends DataExtension
{
function extraStatics($class = null, $extension = null) {
return array(
'db' => array(
'WordpressID' => 'Int'
)
);
}
private static $db = array(
'WordpressID' => 'Int'
);
}
45 changes: 31 additions & 14 deletions code/WpImporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
class WpImporter extends DataExtension
{

function updateCMSFields(FieldList $fields) {
public function updateCMSFields(FieldList $fields) {
$html_str = '<iframe name="WpImport" src="WpImporter_Controller/index/' . $this->owner->ID . '" width="500"> </iframe>';
$fields->addFieldToTab('Root.Import', new LiteralField("ImportIframe", $html_str));
}
Expand All @@ -17,8 +17,13 @@ function updateCMSFields(FieldList $fields) {

class WpImporter_Controller extends Controller
{
private static $allowed_actions = array(
'index',
'UploadForm',
'doUpload'
);

function init() {
public function init() {
parent::init();

// Do security check in case this controller is called by unauthorised user using direct url
Expand All @@ -30,6 +35,10 @@ function init() {
user_error('Please install the blog module before importing from Wordpress', E_USER_ERROR);
}

public function index($request) {
return $this->renderWith('WpImporter');
}

protected function getBlogHolderID() {
if (isset($_REQUEST['BlogHolderID']))
return $_REQUEST['BlogHolderID'];
Expand All @@ -41,20 +50,20 @@ protected function getBlogHolderID() {
* Outputs an file upload form
*/

function UploadForm() {
return new Form($this, "UploadForm",
new FieldList(
new FileField("XMLFile", 'Wordpress XML file'),
new HiddenField("BlogHolderID", '', $this->getBlogHolderID())
public function UploadForm() {
return Form::create($this, "UploadForm",
FieldList::create(
FileField::create("XMLFile", 'Wordpress XML file'),
HiddenField::create("BlogHolderID", '', $this->getBlogHolderID())
),
new FieldList(
new FormAction('doUpload', 'Import Wordpress XML file')
FieldList::create(
FormAction::create('doUpload', 'Import Wordpress XML file')
)
);
}

protected function getOrCreateComment($wordpressID) {
if ($wordpressID && $comment = DataObject::get('Comment')->filter(array('WordpressID' => $wordpressID))->first())
if ($wordpressID && $comment = Comment::get()->filter(array('WordpressID' => $wordpressID))->first())
return $comment;

return Comment::create();
Expand All @@ -75,7 +84,7 @@ protected function importComments($post, $entry) {
}

protected function getOrCreatePost($wordpressID) {
if ($wordpressID && $post = DataObject::get('BlogEntry')->filter(array('WordpressID' => $wordpressID))->first())
if ($wordpressID && $post = BlogEntry::get()->filter(array('WordpressID' => $wordpressID))->first())
return $post;

return BlogEntry::create();
Expand All @@ -91,16 +100,24 @@ protected function importPost($post) {
// so we can use update here.

$entry->update($post);
$entry->write();
if ($post['IsPublished'])

//Create an initial write as a draft copy otherwise a write()
//in SS3.1.2+ will go live and never have a draft Version.
//@see http://doc.silverstripe.org/framework/en/changelogs/3.1.2#default-current-versioned-
//stage-to-live-rather-than-stage for details.
$entry->writeToStage('Stage');

//If the post was published on WP, now ensure it is also live in SS.
if ($post['IsPublished']){
$entry->publish("Stage", "Live");
}

$this->importComments($post, $entry);

return $entry;
}

function doUpload($data, $form) {
public function doUpload($data, $form) {

// Checks if a file is uploaded
if (!is_uploaded_file($_FILES['XMLFile']['tmp_name']))
Expand Down
2 changes: 1 addition & 1 deletion code/tasks/DeletePostsTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class DeletPostsTask extends BuildTask

protected $description = 'Deletes all blog posts and any associated comments.';

function init() {
public function init() {
parent::init();

if (!Permission::check('ADMIN'))
Expand Down
23 changes: 23 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "silverstripe/wordpressimport",
"description": "Imports Wordpress content from an exported XML file",
"type": "silverstripe-module",
"keywords": ["silverstripe","blog","wordpress", "migration"],
"license": "BSD-3-Clause",
"authors": [
{
"name": "Cam Findlay",
"email": "[email protected]"
},
{
"name": "Damian Mooyman",
"email": "[email protected]"
}
],
"require": {
"silverstripe/framework": "~3.1.2",
"silverstripe/cms": "~3.1.2",
"silverstripe/blog": "*",
"silverstripe/comments": "*"
}
}
4 changes: 2 additions & 2 deletions tests/WpParserTests.php → tests/WpParserTest.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php

/**
* @package comments
* @package wordpressimport
*/
class WpParserTests extends FunctionalTest
class WpParserTest extends FunctionalTest
{
static $testImportFile = 'WordpressExport.xml';

Expand Down

0 comments on commit c157832

Please sign in to comment.