diff options
author | Jason Oster <parasytic@users.sourceforge.net> | 2009-05-20 17:10:09 +0000 |
---|---|---|
committer | Jason Oster <parasytic@users.sourceforge.net> | 2009-05-20 17:10:09 +0000 |
commit | 78b585135fc16c268a9de69a1156231873995a49 (patch) | |
tree | 44083f219143e7c452db9096a15b785959148443 | |
parent | f5cfc55764e413a120f414e31ed608249303c27b (diff) | |
download | phpicalendar-78b585135fc16c268a9de69a1156231873995a49.tar.gz phpicalendar-78b585135fc16c268a9de69a1156231873995a49.tar.bz2 phpicalendar-78b585135fc16c268a9de69a1156231873995a49.zip |
Force makeTitle() to limit the amount of text put into a title
-rw-r--r-- | functions/date_functions.php | 6 | ||||
-rw-r--r-- | functions/init/sanitize.php | 17 |
2 files changed, 20 insertions, 3 deletions
diff --git a/functions/date_functions.php b/functions/date_functions.php index 3d55d7b..d722c17 100644 --- a/functions/date_functions.php +++ b/functions/date_functions.php @@ -163,7 +163,7 @@ function chooseOffset($time, $timezone = '') { function makeTitle($arr, $time) { global $timeFormat, $dateFormat_week; - $event_text = stripslashes(urldecode($arr["event_text"])); + $event_text = chopToWordCount(sanitizeForWeb(urldecode($arr["event_text"])), 25); if ($time == -1) { $start = localizeDate($dateFormat_week, $arr['start_unixtime']); $end = localizeDate($dateFormat_week, ($arr['end_unixtime'] - 60)); @@ -177,10 +177,10 @@ function makeTitle($arr, $time) { } if (!empty($arr['description'])) { - $title .= "\n\nDescription: ".urldecode($arr['description']); + $title .= "\n\nDescription: " . chopToWordCount(sanitizeForWeb(urldecode($arr['description'])), 100); } if (!empty($arr['location'])) { - $title .= "\n\nLocation: ".urldecode($arr['location']); + $title .= "\n\nLocation: " . chopToWordCount(sanitizeForWeb(urldecode($arr['location'])), 25); } $title = trim($title); diff --git a/functions/init/sanitize.php b/functions/init/sanitize.php index 5e9d57e..0370f9f 100644 --- a/functions/init/sanitize.php +++ b/functions/init/sanitize.php @@ -33,6 +33,23 @@ function recursiveSanitize($value) { } +/** + * Truncate a string to a specific number of words + */ +function chopToWordCount($string, $count) { + $wc = str_word_count($string); + if ($wc > $count) { + $words = str_word_count($string, 2); + $last_word = array_slice($words, $count, 1, true); + $pos = key($last_word); + $string = substr($string, 0, $pos); + } + return $string; +} + +/** + * Strip "dangerous" HTML to make it safe to print to web browsers + */ function sanitizeForWeb($string) { $string = preg_replace('/<br\s*\/?>/', "\n", $string); |