page: text/plain request triggers api mode
[minimedit.git] / upload.inc.php
index c578a2dc66ab36c0d36c772ff00ea1ab7868aad4..6175fe20a685b1b1df707ccba8e74f4bad2564f1 100644 (file)
@@ -37,3 +37,21 @@ function userupload($input, $target = NULL, $filename = NULL)
        }
        return $target;
 }
+
+function messagehtml($input)
+{
+       # convert user textarea post to formatted html
+       global $User;
+       if (empty($input)) {
+               return;
+       }
+       if ($User->admin and preg_match('/\A<[a-z][^>]*>/', $input)) {
+               return $input;  # allow html input as is if privileged
+       }
+       $html = preg_replace(
+               ["/\r?\n/", "'(?:<br />\n?){2}'"],
+               ["<br />\n", "</p>\n\n<p>"],
+               htmlspecialchars($input)
+       );
+       return "<p>$html</p>";
+}