101 lines
2.8 KiB
PHP
101 lines
2.8 KiB
PHP
<?php
|
|
|
|
class ArticlesController extends Controller
|
|
{
|
|
|
|
static function actionIndex()
|
|
{
|
|
self::$layout = 'layoutPage.php';
|
|
self::addStyle('/css/style.css?ver=' . App::getConfig('version'));
|
|
self::addStyle('/css/pageStyle.css?ver=' . App::getConfig('version'));
|
|
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::addStyle('/css/bootstrap.min.css');
|
|
self::addStyle('/css/bootstrap-theme.min.css');
|
|
|
|
if (!App::$user || !App::$user->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');
|
|
}
|
|
|
|
}
|