Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
drupal.org
date_ical
Commits
fda25132
Commit
fda25132
authored
Jun 25, 2014
by
byrond
Committed by
Robert Rollins
Jun 25, 2014
Browse files
Issue #2289981: Changed the way exported fields get converted to plaintext.
parent
2fa55376
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
27 deletions
+24
-27
date_ical.module
date_ical.module
+17
-18
includes/date_ical_plugin_row_ical_entity.inc
includes/date_ical_plugin_row_ical_entity.inc
+4
-4
includes/date_ical_plugin_row_ical_fields.inc
includes/date_ical_plugin_row_ical_fields.inc
+3
-5
No files found.
date_ical.module
View file @
fda25132
...
...
@@ -222,29 +222,28 @@ function date_ical_feeds_processor_targets_alter(&$targets, $entity_type, $bundl
/**
* Reformats the provided text to be compliant with the iCal spec.
*
* If the text contains HTML tags, those tags will be stripped (with <p> tags
* converted to "\n\n" and link tags converted to footnotes), and uneeded
* whitespace will be cleaned up.
* If the text contains HTML tags, those tags will be stripped. Paragraph,
* heading, and div tags will be replaced with newlines.
*
* @param string $text
* The text to be sanitized.
*/
function
date_ical_sanitize_text
(
$text
=
''
)
{
//
Use Drupal's built-in HTML to Text converter, which does a mostly
//
adequate job of making the text iCal-compliant
.
$text
=
trim
(
drupal_html_to_text
(
$text
)
)
;
// Replace instances of more than one space with exactly one space. This
//
cleans up the whitespace mess that drupal_html_to_text() leaves behind
.
$text
=
preg_replace
(
"/
+/"
,
"
"
,
$text
);
//
The call to drupal_html_to_text() above converted <p> to \n\n, and also
// shoved a \n into the string every 80 characters. We don't want those
//
single \n's lying around, because iCalcreator will properly "fold" long
//
text
fields for us. So, we need to remove all instances of \n which
// are neither immediately preceeded, nor followed, by another \n.
//
However, \n's which are followed immediately by a > character should
// remain, because of how drupal_html_to_text() converts <blockquote>.
$text
=
preg_replace
(
"/(?<!
\n
)
\n
(?![
\n
\>])/"
,
" "
,
$text
);
return
$text
;
//
HTML tags may get converted to < and such by the View code, so we need
//
to convert them back to HTML so we can remove them with strip_tags()
.
$text
=
decode_entities
(
$text
);
//
Convert <p> tags to double newlines
.
$text
=
trim
(
preg_replace
(
"/
<p.*?>/i"
,
"
\n\n
"
,
$text
)
)
;
//
Separate heading tags from the text around them in both directions.
$text
=
trim
(
preg_replace
(
"/<
\\
?h\d.*?>/i"
,
"
\n\n
"
,
$text
));
//
Add a newline for each <div>.
$
text
=
trim
(
preg_replace
(
"/<div.*?>/i"
,
"
\n
"
,
$text
));
//
Strip the remaining HTML.
$text
=
strip_tags
(
$text
);
// Remove newlines added at the beginning.
return
trim
(
$text
)
;
}
/**
...
...
includes/date_ical_plugin_row_ical_entity.inc
View file @
fda25132
...
...
@@ -248,7 +248,7 @@ class date_ical_plugin_row_ical_entity extends views_plugin_row {
// Make sure this Node Reference actually references a node.
if
(
$location_field
[
'nid'
])
{
$node
=
node_load
(
$location_field
[
'nid'
]);
$location
=
check_plain
(
$node
->
title
)
;
$location
=
$node
->
title
;
}
}
elseif
(
$location_info
[
'type'
]
==
'addressfield'
)
{
...
...
@@ -276,10 +276,10 @@ class date_ical_plugin_row_ical_entity extends views_plugin_row {
$location_data
[]
=
$location_field
[
$included_field
];
}
}
$location
=
check_plain
(
implode
(
', '
,
$location_data
)
)
;
$location
=
implode
(
', '
,
$location_data
);
}
else
{
$location
=
check_plain
(
$location_field
[
'value'
]
)
;
$location
=
$location_field
[
'value'
];
}
}
}
...
...
@@ -345,7 +345,7 @@ class date_ical_plugin_row_ical_entity extends views_plugin_row {
$event
[
'url'
]
=
url
(
$uri
[
'path'
],
$uri
[
'options'
]);
$event
[
'rrule'
]
=
$is_field
&&
array_key_exists
(
'rrule'
,
$date_field
)
?
$date_field
[
'rrule'
]
:
''
;
if
(
$location
)
{
$event
[
'location'
]
=
$location
;
$event
[
'location'
]
=
date_ical_sanitize_text
(
$location
)
;
}
// For this event's UID, use either the date_id generated by the Date
...
...
includes/date_ical_plugin_row_ical_fields.inc
View file @
fda25132
...
...
@@ -226,13 +226,11 @@ class date_ical_plugin_row_ical_fields extends views_plugin_row {
drupal_alter
(
'date_ical_export_html'
,
$text_fields
,
$this
->
view
,
$context
);
// Sanitize the text fields for iCal compliance, and add them to the event.
// Also strip all HTML from the summary and location fields, since they
// must be plaintext, and may have been set as links by the view.
$event
[
'summary'
]
=
date_ical_sanitize_text
(
strip_tags
(
$text_fields
[
'summary'
]));
$event
[
'location'
]
=
date_ical_sanitize_text
(
strip_tags
(
$text_fields
[
'location'
]));
$event
[
'summary'
]
=
date_ical_sanitize_text
(
$text_fields
[
'summary'
]);
$event
[
'location'
]
=
date_ical_sanitize_text
(
$text_fields
[
'location'
]);
$event
[
'description'
]
=
date_ical_sanitize_text
(
$text_fields
[
'description'
]);
// Allow other modules to alter the event object
,
before it gets passed to
// Allow other modules to alter the event object before it gets passed to
// the style plugin to be converted into an iCal VEVENT.
drupal_alter
(
'date_ical_export_raw_event'
,
$event
,
$this
->
view
,
$context
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment