From 7e1f42570423fb8fa37535844faf0b6ba7e23fcf Mon Sep 17 00:00:00 2001 From: Krivchikov Dmitry Date: Sun, 30 Aug 2015 11:19:57 +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=83=D0=BB=D1=83=D1=87=D1=88?= =?UTF-8?q?=D0=B5=D0=BD=D0=BD=D1=8B=D1=85=20=D1=81=D1=82=D0=B0=D1=82=D0=B5?= =?UTF-8?q?=D0=B9=20-=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD?= =?UTF-8?q?=D0=B0=20=D0=B0=D0=B4=D0=BC=D0=B8=D0=BD=D0=BA=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ground/controllers/ArticlesController.php | 100 ++++++++++++++++++++++ ground/controllers/PageController.php | 14 +++ ground/views/articles/edit.php | 35 ++++++++ ground/views/articles/index.php | 31 +++++++ 4 files changed, 180 insertions(+) create mode 100644 ground/controllers/ArticlesController.php create mode 100644 ground/views/articles/edit.php create mode 100644 ground/views/articles/index.php diff --git a/ground/controllers/ArticlesController.php b/ground/controllers/ArticlesController.php new file mode 100644 index 0000000..7bd51f2 --- /dev/null +++ b/ground/controllers/ArticlesController.php @@ -0,0 +1,100 @@ +isAdmin) { + App::error404(); + } + // ------------------------------------------ + + $res = App::DB()->query("SELECT COUNT(`id`) pointsCount FROM `points`")->fetch(PDO::FETCH_ASSOC); + App::setConfig('title', $res['pointsCount'] . ' или даже больше поводов не сидеть дома'); + + self::render('articles/index.php', array( + 'categories' => $categories, + 'user' => App::$user, + 'articles' => Article::model()->getAll(), + 'randomPoint' => Point::model()->getRandom(), + )); + } + + static function actionEdit() + { + if (!App::$user || !App::$user->isAdmin) { + App::error404(); + } + + $articleId = (int) App::getParam('id'); + + self::$layout = 'layoutPage.php'; + self::addScript('/js/jquery-2.1.0.min.js'); + self::addScript('/js/jquery-ui-1.10.4.custom.min.js'); + self::addScript('/js/bootstrap.min.js'); + self::addScript('/js/app.js?ver=' . App::getConfig('version')); + self::addScript('http://cdnjs.cloudflare.com/ajax/libs/fotorama/4.6.3/fotorama.js'); + self::addStyle('/css/style.css?ver=' . App::getConfig('version')); + self::addStyle('/css/pageStyle.css?ver=' . App::getConfig('version')); + self::addStyle('/css/bootstrap.min.css'); + self::addStyle('/css/bootstrap-theme.min.css'); + self::addStyle('http://cdnjs.cloudflare.com/ajax/libs/fotorama/4.6.3/fotorama.css'); + + $article = Article::model()->getByPK($articleId); + + if (!$article) { + App::error404(); + } + + App::setConfig('title', $article->title . ' - wikipoints.ru'); + + self::render('articles/edit.php', array( + 'article' => $article, + 'randomPoint' => Point::model()->getRandom(), + )); + } + + static function actionSave() + { + if (!App::$user || !App::$user->isAdmin) { + App::error404(); + } + + if (!(isset($_POST['id']) && isset($_POST['title']) && isset($_POST['text']))) { + App::error404(); + } + + $id = (int) $_POST['id']; + $title = $_POST['title']; + $text = $_POST['text']; + $allowComments = (int) isset($_POST['allowComments']); + + $article = $id ? Article::model()->getByPK($id) : new Article(); + + if (!$article) { + App::error404(); + } + + if ($id == 0) { + $article->author = App::$user->id; + } + + $article->title = $title; + $article->text = $text; + $article->allowComments = $allowComments; + $article->save(); + + App::redirect('/articles'); + } + +} diff --git a/ground/controllers/PageController.php b/ground/controllers/PageController.php index 928778f..d753933 100644 --- a/ground/controllers/PageController.php +++ b/ground/controllers/PageController.php @@ -193,6 +193,7 @@ class PageController extends Controller } App::setConfig('title', $article->title . ' - wikipoints.ru'); + $article->text = nl2br(Helper::replaceLinks($article->text, 'html')); self::render('article.php', array( 'article' => $article, @@ -205,6 +206,19 @@ class PageController extends Controller } } + static function actionMyprofile() + { + $userId = App::$user ? App::$user->id : 0; + + die($userId); + } + +// static function actionProfile() +// { +// $userId = (int) App::getParam('user'); +// +// } + static function actionVkpoint() { $pointId = (int) App::getParam('id'); diff --git a/ground/views/articles/edit.php b/ground/views/articles/edit.php new file mode 100644 index 0000000..6da8dc8 --- /dev/null +++ b/ground/views/articles/edit.php @@ -0,0 +1,35 @@ +
+ +
+
+
+

Редактирование статьи

+
+ Вернуться: к списку статей / на карту. +
+
+
+ + +
+ + +
+ +
+ + +
+ +
+ +
+ + +
+
+
+
+
diff --git a/ground/views/articles/index.php b/ground/views/articles/index.php new file mode 100644 index 0000000..a823bc1 --- /dev/null +++ b/ground/views/articles/index.php @@ -0,0 +1,31 @@ +
+ +
+
+ +
+ +