I'm moving my blog from one site running 6.11 to another. I've used 6.x-2.6 to export a blog node, copied and pasted the code over to the import window of the new site, but I get the errors below. I'd appreciate any pointers.

Parse error: syntax error, unexpected T_STRING, expecting ')' in /home5/smithwe1/public_html/drupal-6.11/sites/all/modules/node_export/node_export.pages.inc(325) : eval()'d code on line 30

Fatal error: __clone method called on non-object in /home5/smithwe1/public_html/drupal-6.11/includes/common.inc on line 1691

The data being imported is:
array(
'nid' => NULL,
'type' => 'blog',
'language' => '',
'uid' => '1',
'status' => '1',
'created' => NULL,
'changed' => '1234118257',
'comment' => '2',
'promote' => '1',
'moderate' => '0',
'sticky' => '0',
'tnid' => '0',
'translate' => '0',
'vid' => NULL,
'revision_uid' => '1',
'title' => 'Hiking Sugarloaf with Evan',
'body' => 'Yesterday, Evan and I left Molly at home and went to Sugarloaf to hike. Evan followed good hiking practice by having a pre-hike nap in the car on the way.
[G2:4639]

Several of the trails still had snow on them and the trail up to the peak was pretty treacherous.
[G2:4644 class=\"g2image_float_left\"][G2:4642]

We found passable routes, though, and a good spot with a nice view to stop for a snack.
[G2:4646 class=\"g2image_float_left\"][G2:4648]

After a couple hours of hiking, we spent some time playing in the snow before loading up to come home.
[G2:4650 class=\"g2image_float_left\"][G2:4652]

Unfortunately, on the way home Evan got sick...very sick. There was used Z-Bar all over the back seat. He\'s still a little under the weather today, but seems to be on the mend.

Once I got him home and cleaned up, my first thought was, \"I really wish I had sprung for the upholstery protection package when I bought my car.\" Everything came right up though. I was amazed.',
'teaser' => 'Yesterday, Evan and I left Molly at home and went to Sugarloaf to hike. Evan followed good hiking practice by having a pre-hike nap in the car on the way.
[G2:4639]

Several of the trails still had snow on them and the trail up to the peak was pretty treacherous.
[G2:4644 class=\"g2image_float_left\"][G2:4642]

',
'log' => '',
'revision_timestamp' => '1234118257',
'format' => '1',
'name' => 'Barrett',
'picture' => '',
'data' => 'a:2:{s:7:\"contact\";i:0;s:13:\"form_build_id\";s:37:\"form-474d88df20e558c63cf8e3a74c34c6b6\";}',
'path' => NULL,
'last_comment_timestamp' => '1234104158',
'last_comment_name' => NULL,
'comment_count' => '0',
'taxonomy' => array(
'1' => array(
'3' => '3',
),
'tags' => array(
'2' => 'hiking, Sugarloaf',
),
),
'files' => array(),
'menu' => NULL,
'#_export_node_encode_object' => '1',
)

Comments

danielb’s picture

can you please paste the code in a code block or pastebin?

Make sure there are no input filters or wysiwyg on the textarea where you paste it.

barrett’s picture

array(
  'nid' => NULL,
  'type' => 'blog',
  'language' => '',
  'uid' => '1',
  'status' => '1',
  'created' => NULL,
  'changed' => '1234118257',
  'comment' => '2',
  'promote' => '1',
  'moderate' => '0',
  'sticky' => '0',
  'tnid' => '0',
  'translate' => '0',
  'vid' => NULL,
  'revision_uid' => '1',
  'title' => 'Hiking Sugarloaf with Evan',
  'body' => 'Yesterday, Evan and I left Molly at home and went to <a href=\"http://www.sugarloafmd.com/\" target=\"_blank\" title=\"Sugarloaf Mountain, MD\">Sugarloaf</a> to hike.  Evan followed good hiking practice by having a pre-hike nap in the car on the way.
[G2:4639]

Several of the <a href=\"http://www.sugarloafmd.com/images/maps/sugarloaf_map1.pdf\" title=\"Trail Map\" target=\"_blank\">trails</a> still had snow on them and the trail up to the peak was pretty treacherous.
[G2:4644 class=\"g2image_float_left\"][G2:4642]

We found passable routes, though, and a good spot with a nice view to stop for a snack.
[G2:4646 class=\"g2image_float_left\"][G2:4648]

After a couple hours of hiking, we spent some time playing in the snow before loading up to come home.
[G2:4650 class=\"g2image_float_left\"][G2:4652]

Unfortunately, on the way home Evan got sick...very sick.  There was used <a href=\"http://www.clifbar.com/food/products_clif_kid_zbar/\" title=\"Clif ZBar\" target=\"_blank\">Z-Bar</a> all over the back seat.  He\'s still a little under the weather today, but seems to be on the mend.

Once I got him home and cleaned up, my first thought was, \"I really wish I had sprung for the upholstery protection package when I bought my car.\"  Everything came right up though.  I was amazed.',
  'teaser' => 'Yesterday, Evan and I left Molly at home and went to <a href=\"http://www.sugarloafmd.com/\" target=\"_blank\" title=\"Sugarloaf Mountain, MD\">Sugarloaf</a> to hike.  Evan followed good hiking practice by having a pre-hike nap in the car on the way.
[G2:4639]

Several of the <a href=\"http://www.sugarloafmd.com/images/maps/sugarloaf_map1.pdf\" title=\"Trail Map\" target=\"_blank\">trails</a> still had snow on them and the trail up to the peak was pretty treacherous.
[G2:4644 class=\"g2image_float_left\"][G2:4642]

',
  'log' => '',
  'revision_timestamp' => '1234118257',
  'format' => '1',
  'name' => 'Barrett',
  'picture' => '',
  'data' => 'a:2:{s:7:\"contact\";i:0;s:13:\"form_build_id\";s:37:\"form-474d88df20e558c63cf8e3a74c34c6b6\";}',
  'path' => NULL,
  'last_comment_timestamp' => '1234104158',
  'last_comment_name' => NULL,
  'comment_count' => '0',
  'taxonomy' => array(
    '1' => array(
      '3' => '3',
    ),
    'tags' => array(
      '2' => 'hiking, Sugarloaf',
    ),
  ),
  'files' => array(),
  'menu' => NULL,
  '#_export_node_encode_object' => '1',
)
danielb’s picture

Works fine for me mate.

barrett’s picture

I don't understand it, but I get the same errors (albeit related to different line numbers) no matter what I try to import. I've tried uninstalling and reinstalling the module, running as root and as non-root, importing different content types (e.g., blogs, books) and with different combinations of settings for the import and I get the same error every time.

danielb’s picture

Have you tried pasting it back into the site you got it from, does it work there?

Are you sure nothing could change the submitted text in the form like another module or input format?

barrett’s picture

Thanks for your help with this, danielb.

It does throw the same error when importing back to the site from which it was exported.

I'm importing through the Import form at admin/content/import. I have no wysiwygs, etc installed and I see no indication as to what filter (if any) that form is applying. The site default is filtered html but even turning off all the filters within that configuration results in the same errors

Node Export is the only non-core module enabled on the exporting site.

I don't know what the relevance is, but I'm also seeing: "Invalid argument supplied for foreach() in /home5/smithwe1/public_html/barrett/sites/all/modules/node_export/node_export.pages.inc on line 334." reported in my error logs immediately after each failed import attempt.

danielb’s picture

Status: Active » Postponed (maintainer needs more info)

I can't reproduce this. My strategy would have been to debug the code in node_export.page.inc on line 321-328 using messages and checking the output corresponds to what is expected. For example:

/**
 *  eval and return decoded string
 */
function node_export_node_decode($string) {
  drupal_set_message('node_export_node_decode()<pre>'.htmlspecialchars(print_r($string,true)));
  $array = eval('return '.$string.';');
  $return = node_export_node_decode_objects($array);
  return $return;
}

I see you are a module developer so you may be willing to have a go at this, otherwise I have no clue whats going on :/

barrett’s picture

I've determined that something isn't going correctly with escaping of single quotes in the body and/or teaser. Notice the line "He's still a little under the weather.." in the body element declaration below. As you can see in the code block showing the code imported (http://drupal.org/node/460756#comment-1582606), it's escaped in the statement as exported but based on the output below is getting lost somewhere in processing.

When I edit the imported code to either remove the single-quote/apostrophe or double escape it (ie "He\\'s") in the code to be imported, it works fine.

node_export_node_decode()

array(
  'nid' => NULL,
  'type' => 'blog',
  'language' => '',
  'uid' => '1',
  'status' => '1',
  'created' => NULL,
  'changed' => '1234118257',
  'comment' => '2',
  'promote' => '1',
  'moderate' => '0',
  'sticky' => '0',
  'tnid' => '0',
  'translate' => '0',
  'vid' => NULL,
  'revision_uid' => '1',
  'title' => 'Hiking Sugarloaf with Evan',
  'body' => 'Yesterday, Evan and I left Molly at home and went to <a href="http://www.sugarloafmd.com/" target="_blank" title="Sugarloaf Mountain, MD">Sugarloaf</a> to hike.  Evan followed good hiking practice by having a pre-hike nap in the car on the way.
[G2:4639]

Several of the <a href="http://www.sugarloafmd.com/images/maps/sugarloaf_map1.pdf" title="Trail Map" target="_blank">trails</a> still had snow on them and the trail up to the peak was pretty treacherous.
[G2:4644 class="g2image_float_left"][G2:4642]

We found passable routes, though, and a good spot with a nice view to stop for a snack.
[G2:4646 class="g2image_float_left"][G2:4648]

After a couple hours of hiking, we spent some time playing in the snow before loading up to come home.
[G2:4650 class="g2image_float_left"][G2:4652]

Unfortunately, on the way home Evan got sick...very sick.  There was used <a href="http://www.clifbar.com/food/products_clif_kid_zbar/" title="Clif ZBar" target="_blank">Z-Bar</a> all over the back seat.  He's still a little under the weather today, but seems to be on the mend.

Once I got him home and cleaned up, my first thought was, "I really wish I had sprung for the upholstery protection package when I bought my car."  Everything came right up though.  I was amazed.',
  'teaser' => 'Yesterday, Evan and I left Molly at home and went to <a href="http://www.sugarloafmd.com/" target="_blank" title="Sugarloaf Mountain, MD">Sugarloaf</a> to hike.  Evan followed good hiking practice by having a pre-hike nap in the car on the way.
[G2:4639]

Several of the <a href="http://www.sugarloafmd.com/images/maps/sugarloaf_map1.pdf" title="Trail Map" target="_blank">trails</a> still had snow on them and the trail up to the peak was pretty treacherous.
[G2:4644 class="g2image_float_left"][G2:4642]

',
  'log' => '',
  'revision_timestamp' => '1234118257',
  'format' => '1',
  'name' => 'Barrett',
  'picture' => '',
  'data' => 'a:2:{s:7:"contact";i:0;s:13:"form_build_id";s:37:"form-474d88df20e558c63cf8e3a74c34c6b6";}',
  'path' => NULL,
  'last_comment_timestamp' => '1234104158',
  'last_comment_name' => NULL,
  'comment_count' => '0',
  'taxonomy' => array(
    '1' => array(
      '3' => '3',
    ),
    'tags' => array(
      '2' => 'hiking, Sugarloaf',
    ),
  ),
  'files' => array(),
  'menu' => NULL,
  '#_export_node_encode_object' => '1',
)
danielb’s picture

Can you tell me about your server config?

I wonder why it works on mine.

barrett’s picture

magic_quotes was the first thing I thought of. They're off. What else would you like to know? Nothing else is jumping out at me in the settings.

danielb’s picture

What version of PHP are you running?

barrett’s picture

5.2.9 on linux

danielb’s picture

I have 5.2.8, surely that would be similar enough.

danielb’s picture

Status: Postponed (maintainer needs more info) » Active

OK I found something that might explain what is going on.
http://au2.php.net/stripslashes and http://au2.php.net/addslashes
It seems there are magic_quotes settings in php that may do this automatically and cause my stripslashes() to go one step too far.

line 338-340 in node_export.pages.inc

<?php

    if (is_string($v)) {
      $array[$k] = stripslashes($v);
    }

?>

should become:

<?php

    if (is_string($v)) {
      if (get_magic_quotes_gpc()) {
          $array[$k] = stripslashes($v);
      }
      else {
          $array[$k] = $v;
      }
    }

?>

that's my theory for now

are you able to check your magic quotes settings in php?

here are mine:

magic_quotes_gpc On On
magic_quotes_runtime Off Off
magic_quotes_sybase Off Off

barrett’s picture

That seems reasonable. My settings have all the magic_quotes functions off.

magic_quotes_gpc Off Off
magic_quotes_runtime Off Off
magic_quotes_sybase Off Off

The solution you gave doesn't work though. The $array variable in node_export_node_decode is a string, not an array, because the escaping slash has been stripped before the string is passed into that function, so evaluating it as an array fails.

danielb’s picture

damn ok

how about something like this to manually double escape stuff???

line 324 node_export.pages.inc


function node_export_node_decode($string) {
  $string = str_replace('\\\'', '\\\\\'', $string);
  $array = eval('return '.$string.';');
  $return = node_export_node_decode_objects($array);
  return $return;
}


danielb’s picture

obviously i'd also need an if test to make sure it only does it for those with magic quotes off.
Just wondering whether the logic of the string replace is correct.

barrett’s picture

The slash is getting stripped even farther upstream than that. Adding watchdog('WTF', 'node_export_node_import:<pre>'.htmlspecialchars($node_code).'</pre>'); to node_export_node_import, I get the code below.

I thought that perhaps adding slashes at the stop of node_export_node_import would work, but of course some of the slashes should not be escaped. I think we need to be looking at the export routines instead. Perhaps instead of the export window showing "He\'s" it needs to be displaying "He's"?

node_export_node_import:

array(
  'nid' => NULL,
  'type' => 'blog',
  'language' => '',
  'uid' => '1',
  'status' => '1',
  'created' => NULL,
  'changed' => '1234118257',
  'comment' => '2',
  'promote' => '1',
  'moderate' => '0',
  'sticky' => '0',
  'tnid' => '0',
  'translate' => '0',
  'vid' => NULL,
  'revision_uid' => '1',
  'title' => 'Hiking Sugarloaf with Evan',
  'body' => 'Yesterday, Evan and I left Molly at home and went to <a href="http://www.sugarloafmd.com/" target="_blank" title="Sugarloaf Mountain, MD">Sugarloaf</a> to hike.  Evan followed good hiking practice by having a pre-hike nap in the car on the way.
[G2:4639]

Several of the <a href="http://www.sugarloafmd.com/images/maps/sugarloaf_map1.pdf" title="Trail Map" target="_blank">trails</a> still had snow on them and the trail up to the peak was pretty treacherous.
[G2:4644 class="g2image_float_left"][G2:4642]

We found passable routes, though, and a good spot with a nice view to stop for a snack.
[G2:4646 class="g2image_float_left"][G2:4648]

After a couple hours of hiking, we spent some time playing in the snow before loading up to come home.
[G2:4650 class="g2image_float_left"][G2:4652]

Unfortunately, on the way home Evan got sick...very sick.  There was used <a href="http://www.clifbar.com/food/products_clif_kid_zbar/" title="Clif ZBar" target="_blank">Z-Bar</a> all over the back seat.  He's still a little under the weather today, but seems to be on the mend.

Once I got him home and cleaned up, my first thought was, "I really wish I had sprung for the upholstery protection package when I bought my car."  Everything came right up though.  I was amazed.',
  'teaser' => 'Yesterday, Evan and I left Molly at home and went to <a href="http://www.sugarloafmd.com/" target="_blank" title="Sugarloaf Mountain, MD">Sugarloaf</a> to hike.  Evan followed good hiking practice by having a pre-hike nap in the car on the way.
[G2:4639]

Several of the <a href="http://www.sugarloafmd.com/images/maps/sugarloaf_map1.pdf" title="Trail Map" target="_blank">trails</a> still had snow on them and the trail up to the peak was pretty treacherous.
[G2:4644 class="g2image_float_left"][G2:4642]

',
  'log' => '',
  'revision_timestamp' => '1234118257',
  'format' => '1',
  'name' => 'Barrett',
  'picture' => '',
  'data' => 'a:2:{s:7:"contact";i:0;s:13:"form_build_id";s:37:"form-474d88df20e558c63cf8e3a74c34c6b6";}',
  'path' => NULL,
  'last_comment_timestamp' => '1234104158',
  'last_comment_name' => NULL,
  'comment_count' => '0',
  'taxonomy' => array(
    '1' => array(
      '3' => '3',
    ),
    'tags' => array(
      '2' => 'hiking, Sugarloaf',
    ),
  ),
  'files' => array(),
  'menu' => NULL,
  '#_export_node_encode_object' => '1',
)
danielb’s picture

i'm going to do some testing with magic quotes off

danielb’s picture

OK I can turn magic_quotes_runtime off but it doesn't seem the make a difference, the code is still imported fine.

I don't think there is anything wrong with the export code as it matches the syntax of other exports done in Drupal.

Have you encountered problems importing/exporting content types with apostrophe's in the type description? (using content_copy module that comes with cck) - is it double escaped there?

barrett’s picture

I thought your previous post said it was magic_quotes_gpc you have enabled.

I'm hopeful I'll be able too spend some time today testing out issues like the importing of content types you mentioned. I'll post back with results as soon as I get them. Thanks again for sticking with this.

danielb’s picture

Yes but you cannot turn magic_quotes_gpc off :( If I try changing the htaccess file it breaks the whole site, and I don't have access to php.ini

danielb’s picture

The situation with my hosting is giving my a lot of grief, I'm going to set up apache on my netbook and use it as a server for a while.

barrett’s picture

I've confirmed that turning on magic_quotes_gpc makes things work. I haven't found a fix to handle cases when it's off yet, but the search continues.

danielb’s picture

Well the impression I get from the PHP manual is the correct thing to do is code with magic quotes off in the first place, and then apply a fix when magic_quotes_gpc() is on. D'oh.
I have setup drupal on my new apache server and turned magic quotes off, but I'm too tired to debug this right now.

danielb’s picture

Just tested with magic quotes gpc and runtime off, works fine for me :/

barrett’s picture

Status: Active » Closed (fixed)

You're kidding me, right? :^\

You know, I'm just looking to do a one-shot migration of my blog content from one site to another. If I'm the only one reporting a problem then it doesn't make sense to spend more time on it. I'll just turn off magic quotes, do the import, and turn them back off.

Thanks for all your time.

danielb’s picture

Title: parse and syntax errors when importing in 6.11 using 6.x-2.6 for both import and export » Import: unexpected T_STRING, expecting ')'
Category: support » bug
Status: Closed (fixed) » Active

I wouldn't mind keeping this open for a few weeks to see if anyone else replies.
Plus, I have to remove the attempted fix in 2.8 in the next release, so this will remind me.

danielb’s picture

The attempted fix was removed.

danielb’s picture

Status: Active » Closed (won't fix)
brightbold’s picture

Version: 6.x-2.6 » 6.x-2.21
Component: Code » Node Export
Status: Closed (won't fix) » Active

I had this exact same error last night when trying to import a webform:

Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ')' in /home/masste5/public_html/sites/all/modules/node_export/node_export.module(878) : eval()'d code on line 818.

    * warning: Invalid argument supplied for foreach() in /home/masste5/public_html/sites/all/modules/node_export/node_export.module on line 887.
    * Error encountered during import. Node type unknown on this site. No nodes imported.

I can successfully import the node back into the site it came from (a local development copy) but not onto the production server (shared hosting, no shell access, so I don't know if I'd be permitted to turn off magic quotes there.) However, if I turn ON magic quotes on my local WAMPserver, then the import fails, so I can confirm this is reproducable.

If this is complicated to fix, it would be great if at least the error message could be altered to tell people they can solve the problem by turning off magic quotes or escaping any quotes in the content. I spent a long time chasing down the "node type unknown" portion of the error, which was not really the problem, and eventually ended up recreating the webform by hand. (I didn't originally see the Parse Error portion of the message because it was black text on my dark theme header background, so I was focused on the parts in the Drupal messages area.) So you could save people a lot of headaches if the error message provided the solution.

Great module by the way - I moved a bunch of nodes between dev and production servers yesterday and with the exception of this one webform, the whole thing went smoothly.

danielb’s picture

Status: Active » Closed (won't fix)

Unfortunately theres nothing in your post that can lead me to a solution, nor am I able to change what the error messages say, as far as I know.

brightbold’s picture

All I meant was the solution you and the OP had already discovered - that we need to turn off magic quotes on the server. But I hadn't thought about the fact that the error message is generated by PHP and not by your module, so there's of course not any way for you to alter that.