Closed (outdated)
Project:
Views Bonus Pack
Version:
6.x-1.1
Component:
Views Export
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
16 Feb 2011 at 23:38 UTC
Updated:
8 Mar 2023 at 20:00 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
exiled_hammer commentedWill answer my own question!
It's by design, see template_preprocess_views_bonus_export_csv()
Comment #2
burningdog commentedIf this is "by design" then the design is wrong. The body field has a checkbox option which reads, "Strip HTML tags". That means the default behaviour should be including html tags, which views_bonus doesn't do.
Comment #3
exiled_hammer commentedI agree it's not obvious but that's what lines 38 to 46 of views_bonus_export.theme.inc imply:
I came across this because my client wants a CSV file for the English version of his site so that it can be translated then imported it back using the node_import module.
So, unless there is a good reason for the tags being stripped, should it be patched?
Comment #4
burningdog commentedMost of the html tags *do* need to be stripped, because by the time the above function starts dealing with them, they're in full html, which is unsuitable for a csv export. For instance, I have a CCK colorpicker field which defines the colour of a background in my node (on a per-node basis). The value of it is
#b00f0fbut when it hitstemplate_preprocess_views_bonus_export_csv()its value is:I can see that it was easier for the views_bonus author to simply set
$output = decode_entities(strip_tags($value));- which works well for any field that we *don't* want html in - but doesn't work for any field that we *do* want html in.@exiled_hammer: any idea *where* we can check if the "Strip HTML tags" checkbox in views for a particular field is checked, and then change the value sent to
template_preprocess_views_bonus_export_csv()?Comment #5
burningdog commentedI'm onto something - instead of working in
template_preprocess_views_bonus_export_csv()to check if html tags should be stripped, it's better to work infunction _views_bonus_export_shared_preprocess()in views_bonus_export.moduleIn there I can check the value of strip_tags per field, and if it's set, then strip the html tags there. For almost all fields we want to strip html tags; we only need to check the value of strip_tags on textareas. This involves 2 checks: the 'body' field, and any CCK fields which use an input format.
Patch to follow.
Comment #6
burningdog commentedPatch attached. Works for me using the body field, and also a CCK textarea (which uses an input format). The patch respects the "Strip HTML" option for these fields in views.
Comment #7
burningdog commentedOh no - the above patch doesn't strip the html within fields that it should be stripped from. It works fine on the body field and all CCK fields. Unfortunately, I was mistaken: checking for the presence of 'format' (in
$fields[$id]->options['format']) does *not* differentiate between CCK fields which use input formats and those that don't. For those that don't, the value of$fields[$id]->options['format']is simply 'default', which means that it's impossible to tell which fields need html stripped from them and which ones don't. Unless we explicitly do this in views.Unfortunately, this significantly alters the behaviour of the csv export, because now *all* fields that generate html must be manually edited in views to have the checkbox "Strip HTML" selected. This setting makes sense to me, because the default behaviour of views is to generate html (that views_bonus then strips), but this does mean that if this patch is accepted, everyone will need to re-edit all their views upon upgrading.
Nonetheless, patch attached.
Comment #8
burningdog commentedMaybe a better approach would be to first check if the field value contains html (i.e. strip the first and last html tags that views adds by default), and if it does, then check if "Strip HTML" has been checked. That would at least preserve the current behaviour of the csv export.
However, my regex-fu is not good enough to strip the first and last html tags in a string. Anyone else?
Comment #9
burningdog commentedAfter much investigation, I can't figure out how to tell the difference between fields that legitimately have html in them (like a body field or cck textarea) and other fields (like a file field, believe it or not) programmatically. The best I can do is count the number of closed html tags, and if it's greater than 2, AND views tells us to, then to strip tags from the field. If the count is less than 2 but views doesn't tell us to strip the tags, then leave it alone.
Something like this:
At least this preserves the behaviour of the cvs exports. It will break for any field containing html that contains less than 2 html tags, e.g.
<p><a href="http://example.com">Link!</a></p>will come out asLink! whether views says to strip it or not.There must be a better way! Patch attached, at any rate.
Comment #10
exiled_hammer commentedThanks for the work Roger, had to put this issue on the back burner for a bit to keep the development on track. For the moment I have hacked the views_bonus_export.theme.inc but I do need a long term solution.
Will have a look at the patches next week and get back to you.
Cheers
Comment #11
burningdog commentedI'm kind of wondering if my approach is wrong. What I'm trying to do is export content from a drupal site so that I can import it into another. I don't particularly mind how that happens, and csv seems to be a decent approach.
However, given the complexity of how to do this, it might be that a views XML feed and the feeds module is actually a much better fit for me. That also lets me move content directly from one site to another, rather than going through the intermediate step of downloading a csv file, and uploading it again.
Adding the patch at #9 might be useful in some cases, but I think it's impossible to handle the edge cases, in which case this introduces more possibility for confusion.
Comment #12
exiled_hammer commentedThis project might be of interest http://drupal.org/project/content_push once it's been reviewed.
I met the maintainer, Joachim at DrupalCamp Edninburgh last year and he did a demonstration where nodes & users from Drupal 5 site were imported into Drupal 6.
Comment #13
rcahana commentedAre there any updates?
exiled_hammer: did you get to update the patch?
Comment #14
tonytosta commentedSearching for an update as well.
Comment #15
technikh commentedpatch in #9 worked for me.
Comment #16
Abelito commentedpatch in #9 worked for me too!
Comment #17
jennypanighetti commentedPatch in #9 worked great for me, thanks.
Comment #18
siva_drupal commentedBut Patch for #9 not worked for me please advice
Comment #19
siva_drupal commentedplease attach any exported csv file for reference
Comment #20
captjanko commented@siva_drupal what version of Views Bonus Pack are you using?
Comment #21
neclimdul