summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEarl Miles2010-03-22 19:22:08 (GMT)
committer Earl Miles2010-03-22 19:22:08 (GMT)
commit52454fd9bdbeb4cab6761323eb2fac9fa022eae7 (patch)
tree518b9d00dd47895dd5effbf684bf00b76666317b
parent84be236136981b47c2d25e9a5001a148bdc8c787 (diff)
#675154 by dereine and Crashtest_: Improvements to rendering trim text and tag stripping.
-rw-r--r--CHANGELOG.txt1
-rw-r--r--handlers/views_handler_field.inc59
-rw-r--r--views.module33
3 files changed, 48 insertions, 45 deletions
diff --git a/CHANGELOG.txt b/CHANGELOG.txt
index 8d21b20..56b5386 100644
--- a/CHANGELOG.txt
+++ b/CHANGELOG.txt
@@ -75,6 +75,7 @@ Views 2.x-dev
o #730454 by stella: Add "translate" link along with view/edit/delete links on nodes.
o #474174 by dereine: Analyze will now warn about "node/%" not being a valid path for Views.
o #619642 by dereine: Allow argument for user language.
+ o #675154 by dereine and Crashtest_: Improvements to rendering trim text and tag stripping.
Views 2.8 (Dec 02, 2009)
Bug fixes:
diff --git a/handlers/views_handler_field.inc b/handlers/views_handler_field.inc
index db385bd..9365950 100644
--- a/handlers/views_handler_field.inc
+++ b/handlers/views_handler_field.inc
@@ -362,17 +362,6 @@ class views_handler_field extends views_handler {
),
);
- $form['alter']['strip_tags'] = array(
- '#type' => 'checkbox',
- '#title' => t('Strip HTML tags'),
- '#description' => t('If checked, all HTML tags will be stripped.'),
- '#default_value' => $this->options['alter']['strip_tags'],
- '#process' => array('views_process_dependency'),
- '#dependency' => array(
- 'edit-options-alter-trim' => array(1)
- ),
- );
-
$form['alter']['html'] = array(
'#type' => 'checkbox',
'#title' => t('Field can contain HTML'),
@@ -383,7 +372,16 @@ class views_handler_field extends views_handler {
'edit-options-alter-trim' => array(1)
),
);
+
+ $form['alter']['strip_tags'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Strip HTML tags'),
+ '#description' => t('If checked, all HTML tags will be stripped.'),
+ '#default_value' => $this->options['alter']['strip_tags'],
+ '#process' => array('views_process_dependency'),
+ );
}
+
$form['empty'] = array(
'#type' => 'textfield',
'#title' => t('Empty text'),
@@ -498,6 +496,10 @@ class views_handler_field extends views_handler {
$tokens = $this->get_render_tokens($alter);
$value = $this->render_altered($alter, $tokens);
}
+
+ if (!empty($alter['strip_tags'])) {
+ $value = strip_tags($value);
+ }
if (!empty($alter['trim']) && !empty($alter['max_length'])) {
$value = $this->render_trim_text($alter, $value);
@@ -529,45 +531,12 @@ class views_handler_field extends views_handler {
*/
function render_trim_text($alter, $value) {
if (!empty($alter['strip_tags'])) {
- $value = strip_tags($value);
// NOTE: It's possible that some external fields might override the
// element type so if someone from, say, CCK runs into a bug here,
// this may be why =)
$this->definition['element type'] = 'span';
}
-
- if (drupal_strlen($value) <= $alter['max_length']) {
- return $value;
- }
-
- $value = drupal_substr($value, 0, $alter['max_length']);
-
- // TODO: replace this with cleanstring of ctools
- if (!empty($alter['word_boundary'])) {
- $regex = "(.*)\b.+";
- if (function_exists('mb_ereg')) {
- mb_regex_encoding('UTF-8');
- $found = mb_ereg($regex, $value, $matches);
- }
- else {
- $found = preg_match("/$regex/us", $value, $matches);
- }
- if ($found) {
- $value = $matches[1];
- }
- }
- // Remove scraps of HTML entities from the end of a strings
- $value = rtrim(preg_replace('/(?:<(?!.+>)|&(?!.+;)).*$/us', '', $value));
-
- if (!empty($alter['ellipsis'])) {
- $value .= '&#8230;';
- }
-
- if (!empty($alter['html'])) {
- $value = _filter_htmlcorrector($value);
- }
-
- return $value;
+ return drupal_trim_text($alter, $value);
}
/**
diff --git a/views.module b/views.module
index 5275d2f..678d2b9 100644
--- a/views.module
+++ b/views.module
@@ -1293,3 +1293,36 @@ function views_microtime() {
list($usec, $sec) = explode(' ', microtime());
return (float)$sec + (float)$usec;
}
+
+/**
+ * Trim the field down to the specified length.
+ *
+ * @param $alter
+ * - max_length: Maximum lenght of the string, the rest gets truncated.
+ * - word_boundary: Trim only on a word boundary.
+ * - ellipsis: Trim only on a word boundary.
+ * - html: Take sure that the html is correct.
+ */
+function drupal_trim_text($alter, $value) {
+ dsm('strlen $value ' . drupal_strlen($value));
+ dsm('max_length ' . $alter['max_length']);
+ if (drupal_strlen($value) > $alter['max_length']) {
+ $value = drupal_substr($value, 0, $alter['max_length']);
+ if (!empty($alter['word_boundary'])) {
+ if (preg_match("/(.*)\b.+/us", $value, $matches)) {
+ $value = $matches[1];
+ }
+ }
+ // Remove scraps of HTML entities from the end of a strings
+ $value = rtrim(preg_replace('/(?:<(?!.+>)|&(?!.+;)).*$/us', '', $value));
+
+ if (!empty($alter['ellipsis'])) {
+ $value .= '...';
+ }
+ }
+ if (!empty($alter['html'])) {
+ $value = _filter_htmlcorrector($value);
+ }
+
+ return $value;
+}