function common_render_text($text)
{
- $r = htmlspecialchars($text);
+ $r = nl2br(htmlspecialchars($text));
$r = preg_replace('/[\x{0}-\x{8}\x{b}-\x{c}\x{e}-\x{19}]/', '', $r);
$r = common_replace_urls_callback($r, 'common_linkify');
return $prefs;
}
+// Match by our supported file extensions
+function common_supported_ext_to_mime($fileext)
+{
+ // Accept a filename and take out the extension
+ if (strpos($fileext, '.') !== false) {
+ $fileext = substr(strrchr($fileext, '.'), 1);
+ }
+
+ $supported = common_config('attachments', 'supported');
+ foreach($supported as $type => $ext) {
+ if ($ext === $fileext) {
+ return $type;
+ }
+ }
+
+ throw new ServerException('Unsupported file extension');
+}
+
+// Match by our supported mime types
+function common_supported_mime_to_ext($mimetype)
+{
+ $supported = common_config('attachments', 'supported');
+ foreach($supported as $type => $ext) {
+ if ($mimetype === $type) {
+ return $ext;
+ }
+ }
+
+ throw new ServerException('Unsupported MIME type');
+}
+
+// The MIME "media" is the part before the slash (video in video/webm)
+function common_get_mime_media($type)
+{
+ $tmp = explode('/', $type);
+ return strtolower($tmp[0]);
+}
+
function common_mime_type_match($type, $avail)
{
if(array_key_exists($type, $avail)) {
}
// convert markup to HTML
-
function common_markup_to_html($c, $args=null)
{
if ($c === null) {
$c = preg_replace_callback('/%%action.(\w+)%%/', function ($m) { return common_local_url($m[1]); }, $c);
$c = preg_replace_callback('/%%doc.(\w+)%%/', function ($m) { return common_local_url('doc', array('title'=>$m[1])); }, $c);
$c = preg_replace_callback('/%%(\w+).(\w+)%%/', function ($m) { return common_config($m[1], $m[2]); }, $c);
- return Markdown($c);
+
+ return \Michelf\Markdown::defaultTransform($c);
}
function common_user_property($property)