Script to Import Static Pages into GetSimple CMS

I’ve recently been impressed with a very simple Content Management System called GetSimple. It provides just the very basics that allows a user to edit their own website content. For brochure sites with owners who don’t want the complexity of a larger CMS, I think it is pretty ideal.

When I develop a site though, I typically have a header and footer, and then all of the content pages exist as PHP files that simply include that header and footer. Converting a static site like that into the CMS takes a bunch of copy/pasting. I always try to avoid such tedious jobs, and so developed a script that will import those static pages into a GetSimple installation.

To run this script, I wanted to import a bunch of files in a ‘static’ directory where I had moved all of the static files to. I then ran this from the command line to import all of the content into GetSimple

# for file in `find static -type f`
> do
> ./getsimple_import_file.php $file
> done

The script is available as getsimple_import_file.php

It takes a little configuration before running it. It works by simulating the data that you would submit when creating the page through the web interface, so we have to fake the necessary session cookie. Uncomment the bit in the middle that will display your cookie and run the script once. You’ll need to copy your cookie name and value into the script before doing any actual imports.

Once you’ve done that, you will probably want to change the regular expression that attempts to grab the page title from your file. You may also want to manipulate how it figures the URL to use.

Feel free to post comments here if you found this useful, or made any changes you’d like to share with other users

10 thoughts on “Script to Import Static Pages into GetSimple CMS”

  1. I recently saw a post about this script at the Get Simple CMS forum. It’s a great idea. I can see how it could help me to solve a problem that is coming my way soon.

    My question is:
    As a newbie web designer and Mac user, I am somewhat lost with the steps to use the script. IS there any help that you could offer or point me to?

    Thanks.

    homershines

  2. I’m assuming that you are able to, and familiar with logging in to your hosting environment with SSH. Your host must support it, and there are plenty of resources for learning how to use SSH. I don’t use a Mac, so am not really qualified to tell you how to do that.

  3. Another question. My site is online, but I also have it on my localhost. Can I use this method on a localhost as well?

    Thanks.

    homershines

  4. Hello,

    Is there any more documentation you can provide about the ssh steps? I do not understand them however I can get my way around a ssh client, so I am confident I can figure it out with a little direction!

    If you are willing to offer further help I would probably be able to provide compensation as this will greatly**** help me out in transferring 100s of websites over to my custom getsimple build.

  5. @Mike,

    You’ll need to upload the getsimple_upload_file.php script to the admin directory in GetSimple. Modify it as needed to match the page titles (I have the title surrounded by <h2> tags). Also change the ‘static’ to match the directory that your files are in.

    Once that is all changed, then you would just run the shell commands mentioned in the original post. That finds all of the files in the ‘static’ directory and then calls getsimple_upload_file.php for each file.

  6. After spending much of the day working on it I am still hitting a dead end.

    Is the directory for the static files suppose to be in the admin directory as well?

    If you have the time, I am available on skype. I am sure I am missing something tiny and will compensate you for any time spent.

  7. In ssh it is displaying that it is importing all the pages after putting in the prompt..

    However, upon checking the site and data folder, there is no new pages.

  8. I ended up not using the script above because I could not get the cookie to work. Instead, I took your idea and used it in a different sort of way.

    My pages had tons of php includes. I needed the source of the includes to replace the includes when the page is made.

    So I parsed the documents using simplehtmldom, put the meta tags into an array, parsed the title, and all of the content within my content wrapper, and then it included changedata.php and submitted the page.

    I am using the same exact ssh command that you posted above to achieve this.

    I will make some edits to the script so it can easily be used by others and post it!

    Thanks for your help and your script!

Leave a Reply

Your email address will not be published. Required fields are marked *