]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/util.php
Updating Markdown class + use spl_autoload_register
[quix0rs-gnu-social.git] / lib / util.php
index 7b75a467843f1c56452c3d1218c76cd166000712..9026e931e7df9c4aa2d2b2d737dd2657e839b3dd 100644 (file)
@@ -832,7 +832,7 @@ function common_find_mentions_raw($text)
 
 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');
@@ -1797,6 +1797,44 @@ function common_accept_to_prefs($accept, $def = '*/*')
     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)) {
@@ -1954,7 +1992,6 @@ function common_confirmation_code($bits)
 }
 
 // convert markup to HTML
-
 function common_markup_to_html($c, $args=null)
 {
     if ($c === null) {
@@ -1975,7 +2012,8 @@ function common_markup_to_html($c, $args=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)