From: Brion Vibber Date: Wed, 6 Oct 2010 20:07:29 +0000 (-0700) Subject: Merge branch '0.9.x' into 1.0.x X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=71176b9a98ef5298162f821c621a0e467dd9570b;p=quix0rs-gnu-social.git Merge branch '0.9.x' into 1.0.x --- 71176b9a98ef5298162f821c621a0e467dd9570b diff --cc lib/util.php index b20ed8225f,35fcfdb090..df339d4b1e --- a/lib/util.php +++ b/lib/util.php @@@ -916,23 -901,33 +916,45 @@@ function common_linkify($url) function common_shorten_links($text, $always = false) { - $maxLength = Notice::maxContent(); - if (!$always && ($maxLength == 0 || mb_strlen($text) <= $maxLength)) return $text; - return common_replace_urls_callback($text, array('File_redirection', 'makeShort')); + common_debug("common_shorten_links() called"); + + $user = common_current_user(); + + $maxLength = User_urlshortener_prefs::maxNoticeLength($user); + + common_debug("maxLength = $maxLength"); + + if ($always || mb_strlen($text) > $maxLength) { + common_debug("Forcing shortening"); + return common_replace_urls_callback($text, array('File_redirection', 'forceShort')); + } else { + common_debug("Not forcing shortening"); + return common_replace_urls_callback($text, array('File_redirection', 'makeShort')); + } } + /** + * Very basic stripping of invalid UTF-8 input text. + * + * @param string $str + * @return mixed string or null if invalid input + * + * @todo ideally we should drop bad chars, and maybe do some of the checks + * from common_xml_safe_str. But we can't strip newlines, etc. + * @todo Unicode normalization might also be useful, but not needed now. + */ + function common_validate_utf8($str) + { + // preg_replace will return NULL on invalid UTF-8 input. + return preg_replace('//u', '', $str); + } + + /** + * Make sure an arbitrary string is safe for output in XML as a single line. + * + * @param string $str + * @return string + */ function common_xml_safe_str($str) { // Replace common eol and extra whitespace input chars