Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#31 2005-06-22 09:30:51

uHunkler
New Member
From: Braunschweig
Registered: 2005-01-11
Posts: 4

Re: I made some scripts that import/export templates, forms and css

Scott, the situation kept me thinking. I found the reason:

The apostrophe ' in the JS call: onclick="onOff('de'); return false;" hindered your script to place the code in the datafield. When I escape the apostrophe like onclick="onOff(\'de\'); return false;" everything goes well. The line in the code in TXP after the import looks like the first one, the backslash has been deleted during the import.

Can you reproduce the situation? Does it have to do with the MySQL import function? Can you integrate a workaround in your scripts escaping the single quote after having read the files?

I tried a patch of your script, which works for me. One added line replaces the apostrophe with the escaped one:
# update db page table where row name is $template_name
$template_data2 = str_replace("\x27", "\x5c\x27", $template_data);
safe_update("txp_page", "user_html = '$template_data2'", "name = '$template_name [1]'");

I am no PHP programmer, so please look if this patch is ok.

I hope I am on the right way ;-)
Urs

Last edited by uHunkler (2005-06-22 09:37:59)

Offline

#32 2005-06-22 10:35:05

kemie
Plugin Author
From: mexico<-->sweden
Registered: 2004-05-20
Posts: 495
Website

Re: I made some scripts that import/export templates, forms and css

how did i miss this before???
thank you so much scott, i love being able to edit and back up to my hearts content!


~~~~~~~~~~~~~| monolinea.com | pixilate.com | istockphoto.com/kemie |~~~~~~~~~~~~~

Offline

#33 2005-06-22 18:50:37

soulship
Member
From: Always Sunny Charleston
Registered: 2004-04-30
Posts: 669
Website

Re: I made some scripts that import/export templates, forms and css

@kemie

Same here kemie. I bookmarked the thread when he made the scripts a year ago and never really needed them until a month ago. I think I spent a hour sifting through my bookmarks to find the damned link. It looks like its geeting good mileage now that its been brought back from the forum boneyard.

The scripts work great and there’s some really great potential here for using this for server migration. export forms/css/pages/image info—>new server—>fresh txp install—>import forms/css/pages/image info NO sql version conflicts! No php version conflicts! It will take a really bad variable out and make it irrelevent. I hope someone jumps in to help him work this into something admin and realize its full potential.

Offline

#34 2005-06-22 22:04:47

rossharvey
Member
From: Earth. Sometimes.
Registered: 2005-03-16
Posts: 233
Website

Re: I made some scripts that import/export templates, forms and css

Link is down, anyone care to mirror?

Offline

#35 2005-06-23 01:13:09

soulship
Member
From: Always Sunny Charleston
Registered: 2004-04-30
Posts: 669
Website

Re: I made some scripts that import/export templates, forms and css

It’s up now. here

Offline

#36 2005-06-23 03:21:03

swf
Plugin Author
From: Saskatoon, Saskatchewan Canada
Registered: 2004-06-21
Posts: 109
Website

Re: I made some scripts that import/export templates, forms and css

I’m lost when it come to escapeing characters, but at least you figured it out. I don’t really know what your string replace is doing. Is it a fix only for your template or for and single quote?

BTW:
I’m trying to move all my stuff over to a new domain so you can also download here

Offline

#37 2005-06-23 06:23:45

uHunkler
New Member
From: Braunschweig
Registered: 2005-01-11
Posts: 4

Re: I made some scripts that import/export templates, forms and css

Scott, \x27 is the hex value for the apostrophe (singelquote) ' and \x5c for the backslash. The replacement string \x5c\x27 means \'.

> Is it a fix only for your template or for and single quote?

The line $template_data2 = str_replace("\x27", "\x5c\x27", $template_data); replaces all apostrophes in all files.

I did some research and found the php function addslashes()

addslashes()
(PHP 3, PHP 4, PHP 5)
addslashes—Quote string with slashes

… An example use of addslashes() is when you’re entering data into a database. For example, to insert the name O’reilly into a database, you will need to escape it. …”

So php has a build in function for the escaping. Before every line starting with “safe_update(…” and “safe_insert(…” you should add the line:

$template_data = addslashes($template_data);

I changed your script and it works as expected. The page part of the file “template-import.php” will look for example:

<pre>
<code>
/* if import==1 and database does not contain entry */
elseif($db_data!=$template_data && $import_new==“1” && $db_data==’‘) { #import into database $template_data = addslashes($template_data); safe_insert(“txp_page”, “name = ‘$template_name1‘, user_html = ‘$template_data’”); $message = ‘<span class=“notice”>inserted into database</span>’;
}
else { # update db page table where row name is $template_name $template_data = addslashes($template_data); safe_update(“txp_page”, “user_html = ‘$template_data’”, “name = ‘$template_name1‘”); $message = ‘<span class=“notice”>updated</span>’;
</code>
</pre>

Scott, I think you should update your import script ;-)
And many thanks again for your welthy scripts.
Urs

Last edited by uHunkler (2005-06-23 07:19:18)

Offline

#38 2005-06-23 19:29:13

swf
Plugin Author
From: Saskatoon, Saskatchewan Canada
Registered: 2004-06-21
Posts: 109
Website

Re: I made some scripts that import/export templates, forms and css

I’ve updated the plugin to incorporate uHunkler’s suggestion. Seems to work now.

The update is available here

Offline

#39 2005-06-24 08:12:25

rossharvey
Member
From: Earth. Sometimes.
Registered: 2005-03-16
Posts: 233
Website

Re: I made some scripts that import/export templates, forms and css

Looking forward to trying this when I get home from work, thanks swf.

Offline

#40 2005-06-26 04:03:59

swf
Plugin Author
From: Saskatoon, Saskatchewan Canada
Registered: 2004-06-21
Posts: 109
Website

Re: I made some scripts that import/export templates, forms and css

Wonder what ahppened to my semi colin, i know i had one here a minute ago, can ai borrow yours ;)

I’ll fix this right now.

Offline

#41 2005-08-30 09:22:17

boblet
Member
Registered: 2005-08-08
Posts: 53

Re: I made some scripts that import/export templates, forms and css

Hey swf,
this looks like exactly what I’ve been wanting – having everything in the db is great and all, but it doesn’t play well with svn. Just a quick question before I fry my site .. er, install this puppy; is it ok for TxP v4?
peace – boblet

Offline

#42 2005-08-30 09:45:22

boblet
Member
Registered: 2005-08-08
Posts: 53

Re: I made some scripts that import/export templates, forms and css

ok forget I spoke – this exports and imports successfully in TxP v4. Rockin’!

Offline

#43 2005-08-30 10:18:21

davidm
Member
From: Paris, France
Registered: 2004-04-27
Posts: 719

Re: I made some scripts that import/export templates, forms and css

> boblet wrote:

> ok forget I spoke – this exports and imports successfully in TxP v4. Rockin’!

That’s very cool news I’ll try it !

Thanks for sharing :-)


.: Retired :.

Offline

#44 2005-08-30 17:28:46

bizartist
Member
From: Los Angeles, CA
Registered: 2005-03-11
Posts: 62
Website

Re: I made some scripts that import/export templates, forms and css

I can’t seem to get it to work, I followed the instructions exactly, and the script appears to be running, but the _template folder is empty. I tried it with both 755 and 777 (eek!) permissions on the folder, to no avail. Any ideas?


After enduring years of Art School, mild mannered Owen Waring noticed some unusual changes… the constant bombardment of criticism, it seems, had altered his DNA. Half pixel pusher, half programmer, he had become…. THE BIZARTIST

Offline

Board footer

Powered by FluxBB