diff --git a/ground/classes/Markdown.php b/ground/classes/Markdown.php new file mode 100644 index 0000000..640c9ee --- /dev/null +++ b/ground/classes/Markdown.php @@ -0,0 +1,70 @@ + 0; $index--) { + + $pr = '/(^#{' . $index . '} .{1,})/m'; + + preg_match_all($pr, $string, $headers); + + if (isset($headers[0][0])) { + foreach ($headers[0] as $header) { + $hI = $index+1; + $string = str_replace($header, "" . mb_substr($header, $index + 1, NULL, 'UTF-8') . "", $string); + } + } + } + + return $string; + } + + static private function replaceBoldItalic($string) + { + $pr = '(\*{3}(.+?)\*{3})'; + $rep = '$1'; + return preg_replace($pr, $rep, $string); + } + + static private function replaceBold($string) + { + $pr = '(\*{2}(.+?)\*{2})'; + $rep = '$1'; + return preg_replace($pr, $rep, $string); + } + + static private function replaceItalic($string) + { + $pr = '(\*{1}(.+?)\*{1})'; + $rep = '$1'; + return preg_replace($pr, $rep, $string); + } + + static private function replaceUnderline($string) + { + $pr = '(\_{1}(.+?)\_{1})'; + $rep = '$1'; + return preg_replace($pr, $rep, $string); + } + + static private function replaceUrls($string) + { + $pr = '((https{0,1}:\/\/[\da-z\.-]+\.[a-z]{2,6})[\/\w\?=&#%+\.,-]*\/?)'; + $rep = '$1'; + return preg_replace($pr, $rep, $string); + } +} diff --git a/ground/controllers/ArticlesController.php b/ground/controllers/ArticlesController.php index 5813beb..78b8228 100644 --- a/ground/controllers/ArticlesController.php +++ b/ground/controllers/ArticlesController.php @@ -76,6 +76,7 @@ class ArticlesController extends Controller $id = (int) $_POST['id']; $title = $_POST['title']; $text = $_POST['text']; + $text = strip_tags($text); $allowComments = (int) isset($_POST['allowComments']); $article = $id ? Article::model()->getByPK($id) : new Article(); diff --git a/ground/controllers/PageController.php b/ground/controllers/PageController.php index 627870c..79c6d6d 100644 --- a/ground/controllers/PageController.php +++ b/ground/controllers/PageController.php @@ -195,6 +195,7 @@ class PageController extends Controller App::setConfig('title', $article->title . ' - wikipoints.ru'); $article->text = Helper::replaceLinks($article->text, 'html'); $article->text = Helper::replaceImgs($article->text, 'html'); + $article->text = Markdown::processing($article->text); $article->text = nl2br($article->text); self::render('article.php', array(