#1 June 26, 2014 2:48pm

jmason03
Member
Registered: January 9, 2014
Posts: 123

Importing Outside Content Into Pages

We are setting up a new site in BigTree and having to import all of our old content from an old database. I have setup a script that currently takes the HTML code from our old database and escapes the forward slashes with backslahses (ie <\/span>) and removes any <br /> tag and replaces it with \r\n. I then recreate the string that exists in my resources column in bigtree_pages for my content template.

So the string that is placed in there by BigTree when I create a new page through the CMS looks like this:
'{"featured_image":"{staticroot}files\/pages\/contentimage-2.jpg","page_header":"Biology Course Descriptions","page_content":"<h2>Biology Course Descriptions<\/h2>\r\n","callouts":[]}'

And the string that I insert from my old database after the modifications looks like this:
'{"featured_image":"{staticroot}files\/pages\/contentimage-2.jpg","page_header":"Phillip Stepp","page_content":"<p><strong>Office: <\/strong>Trustee Science Center, Room 102\r\n","photo_file":"","caption":"","callouts":[]}'

After I insert the new record into the database (the parent is set correctly as well as the other columns), I go to Pages in BigTree and my new page is listed there and I click the Edit icon to modify the template resources and when the page loads there is nothing there. No text in the page header, or in the HTML editor (page_content), or a featured image.

So I know that I'm close but I just can't figure out why when the page loads it removes or at least doesn't correctly load all of my resource data. Is there something that you are aware of that I'm missing? Do I need to insert information in another table as well? Is what I'm trying to do even possible?

Thanks

Offline

#2 June 26, 2014 2:59pm

timbuckingham
Administrator
From: Baltimore, MD
Registered: April 2, 2012
Posts: 974

Re: Importing Outside Content Into Pages

I don't see anything wrong with the JSON string you're inserting (assuming it's the "resources" column in the pages). It decodes properly as JSON, so it should work fine. One thing to note: you don't have to escape forward slashes (it's just the default behavior of json_encode in PHP). BigTree 4.2 (the pre-alpha at this point) will preferentially use pretty print JSON without forward slash escaping.

As for why it's not working, there must be something else at play other than the resource string. Is the template set properly in the inserted row?
Other random thing: The <p> tag isn't closed in the page_content field. Shouldn't cause the admin to not show the content, though.

Offline

#3 June 26, 2014 5:54pm

jmason03
Member
Registered: January 9, 2014
Posts: 123

Re: Importing Outside Content Into Pages

Yeah with the missing </p> that was because I had trimmed off the string when I pasted it into my post because it was rather long.

One thing I did just discover was that I wasn't escaping double quote marks. Now, I am replacing all " with \" but still not having any luck. I checked on the template and it is set to content the same as the other BigTree pages. I'll continue to mess with different things and just keep trying but I did want to ask if you could think of any other characters I would need to escape besides double quotes?

Thanks

Offline

#4 June 26, 2014 7:30pm

timbuckingham
Administrator
From: Baltimore, MD
Registered: April 2, 2012
Posts: 974

Re: Importing Outside Content Into Pages

I believe the only thing you need to escape for something to be properly JSON encoded is quotes (either single or double depending on which ones you encase the original string with).

If you're using PHP to do the importing I would just go with creating an array and JSON encoding it directly using json_encode.

Offline

#5 June 27, 2014 2:02pm

jmason03
Member
Registered: January 9, 2014
Posts: 123

Re: Importing Outside Content Into Pages

Finally solved it. In case anyone else tries this in the future, I had to remove carriage return characters from my old database string as well as escape the other characters. Carriage Return: &#13; and Horizontal Tab: &#9;

Offline

Board footer

Powered by FluxBB

The Discussion Forum is not available on displays of this size.