Projet

Général

Profil

Révision ca0757b9

Ajouté par Assos Assos il y a plus de 9 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/date_ical/date_ical.module
10 10
 * value of the iCal feeds created by Date iCal. It's primarily used for
11 11
 * debugging.
12 12
 */
13
define('DATE_ICAL_VERSION', '3.2');
13
define('DATE_ICAL_VERSION', '3.3');
14 14

  
15 15
/**
16 16
 * Exception class for generic exceptions thrown by this module.
......
222 222
/**
223 223
 * Reformats the provided text to be compliant with the iCal spec.
224 224
 *
225
 * If the text contains HTML tags, those tags will be stripped (with <p> tags
226
 * converted to "\n\n" and link tags converted to footnotes), and uneeded
227
 * whitespace will be cleaned up.
225
 * If the text contains HTML tags, those tags will be stripped. Paragraph,
226
 * heading, and div tags will be replaced with newlines.
228 227
 *
229 228
 * @param string $text
230 229
 *   The text to be sanitized.
231 230
 */
232 231
function date_ical_sanitize_text($text = '') {
233
  // Use Drupal's built-in HTML to Text converter, which does a mostly
234
  // adequate job of making the text iCal-compliant.
235
  $text = trim(drupal_html_to_text($text));
236
  // Replace instances of more than one space with exactly one space. This
237
  // cleans up the whitespace mess that drupal_html_to_text() leaves behind.
238
  $text = preg_replace("/  +/", " ", $text);
239
  // The call to drupal_html_to_text() above converted <p> to \n\n, and also
240
  // shoved a \n into the string every 80 characters. We don't want those
241
  // single \n's lying around, because iCalcreator will properly "fold" long
242
  // text fields for us. So, we need to remove all instances of \n which
243
  // are neither immediately preceeded, nor followed, by another \n.
244
  // However, \n's which are followed immediately by a > character should
245
  // remain, because of how drupal_html_to_text() converts <blockquote>.
246
  $text = preg_replace("/(?<!\n)\n(?![\n\>])/", " ", $text);
247
  return $text;
232
  // HTML tags may get converted to &lt; and such by the View code, so we need
233
  // to convert them back to HTML so we can remove them with strip_tags().
234
  $text = decode_entities($text);
235
  
236
  // Convert <p> tags to double newlines.
237
  $text = trim(preg_replace("/<p.*?>/i", "\n\n", $text));
238
  // Separate heading tags from the text around them in both directions.
239
  $text = trim(preg_replace("/<\\?h\d.*?>/i", "\n\n", $text));
240
  // Add a newline for each <div>.
241
  $text = trim(preg_replace("/<div.*?>/i", "\n", $text));
242
  
243
  // Strip the remaining HTML.
244
  $text = strip_tags($text);
245
  // Remove newlines added at the beginning.
246
  return trim($text);
248 247
}
249 248

  
250 249
/**

Formats disponibles : Unified diff