From cb0d6c614fbe6e84e5ad57d6eafe9c7a7c755088 Mon Sep 17 00:00:00 2001 From: Krivchikov Dmitry Date: Wed, 9 Sep 2015 23:52:58 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B2=D0=B0=D1=8F=20=D0=B2?= =?UTF-8?q?=D0=B5=D1=80=D1=81=D0=B8=D1=8F=20=D1=80=D0=B0=D0=B7=D0=BC=D0=B5?= =?UTF-8?q?=D1=82=D0=BA=D0=B8=20=D0=BC=D0=B0=D1=80=D0=BA=D0=B4=D0=B0=D1=83?= =?UTF-8?q?=D0=BD,=20=D1=83=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20?= =?UTF-8?q?=D1=82=D0=B5=D0=B3=D0=BE=D0=B2=20=D0=B8=D0=B7=20=D1=81=D0=BE?= =?UTF-8?q?=D1=85=D1=80=D0=B0=D0=BD=D1=8F=D0=B5=D0=BC=D0=BE=D0=B3=D0=BE=20?= =?UTF-8?q?=D1=82=D0=B5=D0=BA=D1=81=D1=82=D0=B0=20=D1=81=D1=82=D0=B0=D1=82?= =?UTF-8?q?=D1=8C=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ground/classes/Markdown.php | 70 +++++++++++++++++++++++ ground/controllers/ArticlesController.php | 1 + ground/controllers/PageController.php | 1 + 3 files changed, 72 insertions(+) create mode 100644 ground/classes/Markdown.php 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(