Первая версия улучшенных статей - добавлена админка
This commit is contained in:
parent
17478e1cb0
commit
7e1f425704
|
|
@ -0,0 +1,100 @@
|
|||
<?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');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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');
|
||||
|
|
|
|||
|
|
@ -0,0 +1,35 @@
|
|||
<div id="pageSmoothBackground" style="background-image: url(<?= $randomPoint->getImg('middle') ?>);"></div>
|
||||
|
||||
<div class="container" style="background-color: rgba(255,255,255, 0.8);margin-top: -10px;padding-bottom: 30px;">
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<h1 style="text-align: right;">Редактирование статьи</h1>
|
||||
<div class="coords-container">
|
||||
Вернуться: <a href="/articles">к списку статей</a> / <a href="/">на карту</a>.
|
||||
</div>
|
||||
<div style="text-align: justify;">
|
||||
<form method="POST" action="/articles/save">
|
||||
<input type="hidden" name="id" value="<?= $article->id ?>" />
|
||||
|
||||
<div class="form-group">
|
||||
<label for="articleTitle">Название статьи</label>
|
||||
<input type="text" name="title" id="articleTitle" class="form-control" value="<?= $article->title ?>" placeholder="" />
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="articleText">Текст статьи</label>
|
||||
<textarea name="text" id="articleText" class="form-control" rows="18"><?= $article->text ?></textarea>
|
||||
</div>
|
||||
|
||||
<div class="checkbox">
|
||||
<label>
|
||||
<input type="checkbox" name="allowComments" id="articleComments" <?= $article->allowComments ? 'checked' : '' ?> />Разрешить комментарии
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn btn-default">Сохранить</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
<div id="pageSmoothBackground" style="background-image: url(<?= $randomPoint->getImg('middle') ?>);"></div>
|
||||
|
||||
<div class="container" style="background-color: rgba(255,255,255, 0.8);margin-top: -10px;padding-bottom: 30px;">
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<h1 style="text-align: right;">Список всех статей</h1>
|
||||
<div class="coords-container">
|
||||
Вернуться <a href="/">на карту</a>.
|
||||
</div>
|
||||
<div style="text-align: justify;">
|
||||
<a href="/articles/edit/id/0" class="btn btn-default" title="Добавить новую статью"><span class="glyphicon glyphicon-plus"></span> Добавить новую статью</a><br/>
|
||||
<br/>
|
||||
<?php foreach ($articles as $article): ?>
|
||||
<a href="/articles/edit/id/<?= $article->id ?>">#<?= $article->id ?> <?= $article->title ? $article->title : 'НАЗВАНИЕ НЕ ЗАДАНО!' ?></a>
|
||||
<br/>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- hr/>
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<a href="/page/point/id/<?= $randomPoint->id ?>" style="float: left; margin: 0 20px 0 0;"><img src="<?= $randomPoint->getImg() ?>" style="width: 200px;"/></a>
|
||||
<h3 style="margin-top: 0;">Это интересно: <?= $randomPoint->name ?></h3>
|
||||
<p>
|
||||
<?= mb_substr($randomPoint->description, 0, 400, 'UTF-8') ?>...
|
||||
<a class="" href="/page/point/id/<?= $randomPoint->id ?>" role="button"><nobr> читать далее »</nobr></a>
|
||||
</p>
|
||||
</div>
|
||||
</div -->
|
||||
</div>
|
||||
Loading…
Reference in New Issue