diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..fc43316 Binary files /dev/null and b/.DS_Store differ diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..7493b97 --- /dev/null +++ b/.travis.yml @@ -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/ \ No newline at end of file diff --git a/CHANGELOG b/CHANGELOG deleted file mode 100644 index 9b2e34e..0000000 --- a/CHANGELOG +++ /dev/null @@ -1 +0,0 @@ -0.1 Reworked to correctly function with SS 2.4, also now changes image links to work with SS assets folder. \ No newline at end of file diff --git a/LICENSE b/LICENSE deleted file mode 100644 index e6bcfb1..0000000 --- a/LICENSE +++ /dev/null @@ -1,24 +0,0 @@ -* 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 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. \ No newline at end of file diff --git a/README b/README deleted file mode 100644 index 8ebd801..0000000 --- a/README +++ /dev/null @@ -1,54 +0,0 @@ -############################################### -Wordpress Import Module - Redux! (A re-work) -############################################### - -Maintainer Contact ------------------------------------------------ -Original Module by: -Saophalkun Ponlu (Nickname: phalkunz) - - -Additional Updates: -Cam Findlay (Nickname: camfindlay) - -Damian Mooyman (Nickname: tractorcow) - - - -Requirements ------------------------------------------------ -mod_rewrite -Silverstripe 3.0 - -Documentation ------------------------------------------------ - - -Installation Instructions ------------------------------------------------ - -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 while maintaining -images in your posts. - -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: ------------------------------------------------ - -Content can lose a lot of the formatting coming from Wordpress. -Perhaps parsing the content through a nl2br might help? \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..4c8c15d --- /dev/null +++ b/README.md @@ -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) +* Damian Mooyman (Nickname: tractorcow) + + +##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. + + + + diff --git a/_config.php b/_config.php index 8cdc4b9..b3d9bbc 100644 --- a/_config.php +++ b/_config.php @@ -1,10 +1 @@ array( - 'WordpressID' => 'Int' - ) - ); - } + private static $db = array( + 'WordpressID' => 'Int' + ); } \ No newline at end of file diff --git a/code/WpImporter.php b/code/WpImporter.php index 3c54948..ca8466d 100644 --- a/code/WpImporter.php +++ b/code/WpImporter.php @@ -8,7 +8,7 @@ class WpImporter extends DataExtension { - function updateCMSFields(FieldList $fields) { + public function updateCMSFields(FieldList $fields) { $html_str = ''; $fields->addFieldToTab('Root.Import', new LiteralField("ImportIframe", $html_str)); } @@ -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 @@ -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']; @@ -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(); @@ -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(); @@ -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'])) diff --git a/code/tasks/DeletePostsTask.php b/code/tasks/DeletePostsTask.php index d4adf93..d6f001e 100644 --- a/code/tasks/DeletePostsTask.php +++ b/code/tasks/DeletePostsTask.php @@ -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')) diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..64c832f --- /dev/null +++ b/composer.json @@ -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": "cam@silverstripe.com" + }, + { + "name": "Damian Mooyman", + "email": "damian.mooyman@gmail.com" + } + ], + "require": { + "silverstripe/framework": "~3.1.2", + "silverstripe/cms": "~3.1.2", + "silverstripe/blog": "*", + "silverstripe/comments": "*" + } +} \ No newline at end of file diff --git a/tests/WpParserTests.php b/tests/WpParserTest.php similarity index 98% rename from tests/WpParserTests.php rename to tests/WpParserTest.php index 5a8872f..fab3ebd 100644 --- a/tests/WpParserTests.php +++ b/tests/WpParserTest.php @@ -1,9 +1,9 @@