CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Drupal Modules (Moderator: Donald Lobo) »
  • View of CiviEvents displays html
Pages: [1]

Author Topic: View of CiviEvents displays html  (Read 1746 times)

Shai

  • I post frequently
  • ***
  • Posts: 202
  • Karma: 8
    • Content2zero
  • CiviCRM version: 4.3.x, 4.4.x, 4.5.x
  • CMS version: Drupal 7
  • MySQL version: 5.5.x
  • PHP version: 5.3.x, 5.4.x
View of CiviEvents displays html
August 18, 2009, 03:27:34 pm
I've created a Drupal View of CiviEvents using Views 2. But unfortunately in the description field, any html that gets put in by Civi's FCK Editor will show up literally in the View without being processed.

Can Views 2's "rewrite the output of this field" handle some regex that would strip the html?

Any other ideas?

Thanks,

Shai
Don't miss out! Sign up now for free expert advice on CiviCRM's new StackExchange help site.

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: View of CiviEvents displays html
August 18, 2009, 04:04:28 pm

you might want to play around with the views2 integration code and the data definitions. I'm pretty sure views2 can handle html fields and i suspect you can specify this in the data definition for the various fields

i suspect the changes will need to be made in: drupal/modules/views/civicrm.views.inc, line 1255 or so

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

jalama

  • I post frequently
  • ***
  • Posts: 176
  • Karma: 22
    • Rooty Hollow LLC
  • CiviCRM version: 3.3.5
  • CMS version: Drupal 6 and 7
  • MySQL version: 5.1
  • PHP version: 5.2.5 and 5.3
Re: View of CiviEvents displays html
August 20, 2009, 06:56:31 am
You would need to write a handler to work with Drupal's input filter system.  A likely issue will be that the the check_markup function that filters the text will run it using the Drupal's default input filter.  This is likely to be the most restrictive filter as all authenticated users have access to it.  So something would have to be worked out there, which could be simply bypassing the input filter, but that would be a slight vulnerability open to any user who have the ability to create/edit events.  I don't know if CiviCRM has an equivalent filtering function that could be used here?

FYI:
The current node body field, which allows markup, is run through the views_handler_field_markup

the description field is run through the generic 'views_handler_field' which filters everything through the drupal check_plain function, check_plain escapes/stripes all markup
http://www.rootyhollow.com

Chris Burgess

  • Ask me questions
  • ****
  • Posts: 675
  • Karma: 59
Re: View of CiviEvents displays html
October 08, 2009, 03:34:24 pm
A client asked me to look at this today - he was displaying CiviCRM information in a view, and the HTML content was being escaped, so you'd end up with <p>Blah blah.</p> in the page.

By inspecting the view using theme_devel module, I found that views was using views-view-fields.tpl.php to display each field.

I added some debugging to identify the field ID which contained the HTML, and then inspected the $field variable which is where views gets the information from. This revealed that the raw HTML was stored in $field->raw, while views was using $field->content.

For security, I applied Drupal's default input filter to the HTML before display using check_markup(). The second parameter to check_markup() is the ID of the Drupal input filter to use; you should check that the input filter you use is appropriately restrictive, ESPECIALLY if accepting submitted data from users and displaying it in a view.

Here's the resulting code for views-view-fields.tpl.php that we used:

Code: [Select]
<?php
// $Id: views-view-fields.tpl.php,v 1.6 2008/09/24 22:48:21 merlinofchaos Exp $
/**
 * @file views-view-fields.tpl.php
 * Default simple view template to all the fields as a row.
 *
 * - $view: The view in use.
 * - $fields: an array of $field objects. Each one contains:
 *   - $field->content: The output of the field.
 *   - $field->raw: The raw data for the field, if it exists. This is NOT output safe.
 *   - $field->class: The safe class id to use.
 *   - $field->handler: The Views field handler object controlling this field. Do not use
 *     var_export to dump this object, as it can't handle the recursion.
 *   - $field->inline: Whether or not the field should be inline.
 *   - $field->inline_html: either div or span based on the above flag.
 *   - $field->separator: an optional separator that may appear before a field.
 * - $row: The raw result object from the query, with all data it fetched.
 *
 * @ingroup views_templates
 */
?>

<?php foreach ($fields as $id => $field): ?>
  <?php if (!empty($field->separator)): ?>
    <?php print $field->separator; ?>
  <?php endif; ?>

  <<?php print $field->inline_html;?> class="views-field-<?php print $field->class; ?>">
    <?php if ($field->label): ?>
      <label class="views-label-<?php print $field->class; ?>">
        <?php print $field->label; ?>:
      </label>
    <?php endif; ?>
      <?php
      
// $field->element_type is either SPAN or DIV depending upon whether or not
      // the field is a 'block' element type or 'inline' element type.
      
?>

      <<?php print $field->element_type; ?> class="field-content">
        <?php if ( $id == 'description' ) : ?>
          <?php
            
/**
             * to enable HTML in more fields, update the test above - eg to
             * also allow field "myotherfield", you'd replace the if() above 
             * with
             *
             *   if ( $id == 'description' || $id == 'myotherfield' ) :
             * 
             * this is description which is HTML text - we want to extract
             * the raw HTML version (which is in $field->raw instead of 
             * $field->content), then run it through check_markup() to strip
             * any disallowed HTML tags or other HTML naughties
             *
             * the second param to check_markup() is the ID of the filter
             * format to use (from filter_formats DB table)
             */
            
print check_markup($field->raw,1) ; 
           
?>
       
        <?php else : ?>
          <?php print $field->content; ?>
        <?php endif ; ?>
      </<?php print $field->element_type; ?>>
  </<?php print $field->inline_html;?>>
<?php endforeach; ?>
@xurizaemon ● www.fuzion.co.nz

Shai

  • I post frequently
  • ***
  • Posts: 202
  • Karma: 8
    • Content2zero
  • CiviCRM version: 4.3.x, 4.4.x, 4.5.x
  • CMS version: Drupal 7
  • MySQL version: 5.5.x
  • PHP version: 5.3.x, 5.4.x
Re: View of CiviEvents displays html
October 08, 2009, 03:48:49 pm
@xurizaemon,

Awesome! Thank you soooo much for this!

Shai
Don't miss out! Sign up now for free expert advice on CiviCRM's new StackExchange help site.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Drupal Modules (Moderator: Donald Lobo) »
  • View of CiviEvents displays html

This forum was archived on 2017-11-26.