summaryrefslogtreecommitdiffstats
path: root/views.module
diff options
context:
space:
mode:
Diffstat (limited to 'views.module')
-rw-r--r--views.module33
1 files changed, 33 insertions, 0 deletions
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;
+}