Первая версия именно блогов - многое теперь можно делать со страницы пользователя.
This commit is contained in:
parent
685a2a23df
commit
e0af30c50f
|
|
@ -27,6 +27,10 @@ class ArticleController extends Controller
|
|||
App::error404();
|
||||
}
|
||||
|
||||
if ($article->status == 'del') {
|
||||
App::error404();
|
||||
}
|
||||
|
||||
if ($article->status == 'draft' && (!App::$user || App::$user->id != $article->author)) {
|
||||
App::error404();
|
||||
}
|
||||
|
|
@ -55,4 +59,143 @@ class ArticleController extends Controller
|
|||
App::error404();
|
||||
}
|
||||
}
|
||||
|
||||
static function actionNew()
|
||||
{
|
||||
self::actionEdit();
|
||||
}
|
||||
|
||||
static function actionEdit()
|
||||
{
|
||||
if (!App::$user) {
|
||||
App::error404();
|
||||
}
|
||||
$articleId = (int) App::getParam('id');
|
||||
|
||||
self::$layout = 'layoutClear.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('/js/articleEdit.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');
|
||||
self::addStyle('/css/articleEdit.css?ver=' . App::getConfig('version'));
|
||||
|
||||
$article = Article::model()->getByPK($articleId);
|
||||
|
||||
if ($articleId > 0 && (!$article || $article->author != App::$user->id)) {
|
||||
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::error404();
|
||||
}
|
||||
|
||||
if (!(isset($_POST['id']) && isset($_POST['title']) && isset($_POST['text']))) {
|
||||
App::error404();
|
||||
}
|
||||
|
||||
$id = (int) $_POST['id'];
|
||||
$title = strip_tags($_POST['title']);
|
||||
$text = str_replace(array('<','>'), array('<','>'), $_POST['text']);
|
||||
|
||||
$html = strip_tags($_POST['text']);
|
||||
$html = str_replace(array('<','>',"'"), array('<','>','′'), $html);
|
||||
$html = Markdown::processing($html);
|
||||
$html = nl2br($html);
|
||||
|
||||
$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 ? $title : 'Без названия';
|
||||
$article->text = $text;
|
||||
$article->html = $html;
|
||||
$article->status = (isset($_POST['save']) && $_POST['save'] == 'published') ? 'published' : 'draft';
|
||||
$article->pubDate = time();
|
||||
$article->photoId = Helper::getFirstImg($text);
|
||||
$article->allowComments = $allowComments;
|
||||
$article->save();
|
||||
|
||||
preg_match_all("((\[#(\d+)[>\|](.*?)\])|(\[#(\d+)\]))", $text, $links);
|
||||
$links = isset($links[0]) ? $links[0] : FALSE;
|
||||
|
||||
ArticlePoints::model()->deleteByArticle($article->id);
|
||||
if ($links) {
|
||||
foreach ($links as $link) {
|
||||
$idAndLink = mb_substr($link, 2, -1);
|
||||
$delimiter = strpos($idAndLink, '|') === FALSE ? '>' : '|';
|
||||
$idAndLink = explode($delimiter, $idAndLink);
|
||||
$linkId = $idAndLink[0];
|
||||
|
||||
if (Point::model()->getByPK($linkId)) {
|
||||
ArticlePoints::model()->add(array(
|
||||
'articleId' => $article->id,
|
||||
'pointId' => $linkId,
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
App::redirect('/article/edit/id/'.$article->id);
|
||||
}
|
||||
|
||||
static function actionDel()
|
||||
{
|
||||
if (!App::$user) {
|
||||
App::error404();
|
||||
}
|
||||
|
||||
$articleId = (int) App::getParam('id');
|
||||
|
||||
$article = Article::model()->getByPK($articleId);
|
||||
|
||||
if ($articleId == 0 || $article->id == 0 || $article->author != App::$user->id) {
|
||||
App::error404();
|
||||
}
|
||||
|
||||
$article->status = 'del';
|
||||
$article->save();
|
||||
App::redirect('/user/');
|
||||
}
|
||||
|
||||
static function actionMarkdown()
|
||||
{
|
||||
if (isset($_POST['text']) ){
|
||||
$html = strip_tags($_POST['text']);
|
||||
$html = str_replace(array('<','>',"'"), array('<','>','′'), $html);
|
||||
$html = Markdown::processing($html);
|
||||
$html = nl2br($html);
|
||||
$html = Helper::replaceLinks($html, 'html');
|
||||
$html = Helper::replaceImgs($html, 'html', 'small');
|
||||
|
||||
print $html;
|
||||
}
|
||||
|
||||
die;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,5 +1,9 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Подумать и снести нафиг!
|
||||
*/
|
||||
|
||||
class ArticlesController extends Controller
|
||||
{
|
||||
|
||||
|
|
@ -28,118 +32,4 @@ class ArticlesController extends Controller
|
|||
));
|
||||
}
|
||||
|
||||
static function actionEdit()
|
||||
{
|
||||
if (!App::$user || !App::$user->isAdmin) {
|
||||
App::error404();
|
||||
}
|
||||
|
||||
$articleId = (int) App::getParam('id');
|
||||
|
||||
self::$layout = 'layoutClear.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('/js/articleEdit.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');
|
||||
self::addStyle('/css/articleEdit.css?ver=' . App::getConfig('version'));
|
||||
|
||||
$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 = strip_tags($_POST['title']);
|
||||
$text = str_replace(array('<','>'), array('<','>'), $_POST['text']);
|
||||
|
||||
$html = strip_tags($_POST['text']);
|
||||
$html = str_replace(array('<','>',"'"), array('<','>','′'), $html);
|
||||
$html = Markdown::processing($html);
|
||||
$html = nl2br($html);
|
||||
|
||||
$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->html = $html;
|
||||
$article->status = (isset($_POST['save']) && $_POST['save'] == 'published') ? 'published' : 'draft';
|
||||
$article->pubDate = time();
|
||||
$article->photoId = Helper::getFirstImg($text);
|
||||
$article->allowComments = $allowComments;
|
||||
$article->save();
|
||||
|
||||
preg_match_all("((\[#(\d+)[>\|](.*?)\])|(\[#(\d+)\]))", $text, $links);
|
||||
$links = isset($links[0]) ? $links[0] : FALSE;
|
||||
|
||||
ArticlePoints::model()->deleteByArticle($article->id);
|
||||
if ($links) {
|
||||
foreach ($links as $link) {
|
||||
$idAndLink = mb_substr($link, 2, -1);
|
||||
$delimiter = strpos($idAndLink, '|') === FALSE ? '>' : '|';
|
||||
$idAndLink = explode($delimiter, $idAndLink);
|
||||
$linkId = $idAndLink[0];
|
||||
|
||||
if (Point::model()->getByPK($linkId)) {
|
||||
ArticlePoints::model()->add(array(
|
||||
'articleId' => $article->id,
|
||||
'pointId' => $linkId,
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
App::redirect('/articles/edit/id/'.$article->id);
|
||||
}
|
||||
|
||||
static function actionMarkdown()
|
||||
{
|
||||
if (isset($_POST['text']) ){
|
||||
$html = strip_tags($_POST['text']);
|
||||
$html = str_replace(array('<','>',"'"), array('<','>','′'), $html);
|
||||
$html = Markdown::processing($html);
|
||||
$html = nl2br($html);
|
||||
$html = Helper::replaceLinks($html, 'html');
|
||||
$html = Helper::replaceImgs($html, 'html', 'small');
|
||||
|
||||
print $html;
|
||||
}
|
||||
|
||||
die;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,16 +34,17 @@ class UserController extends Controller
|
|||
self::addStyle('http://cdnjs.cloudflare.com/ajax/libs/fotorama/4.6.3/fotorama.css');
|
||||
|
||||
if (App::$user && App::$user->id == $id) {
|
||||
$articles = Article::model()->getAll(array('where'=>'`author`='.(int)$user->id));
|
||||
$articles = Article::model()->getAll(array('where'=>'`author`='.(int)$user->id.' AND `status` != "del"', 'order' => '`pubDate` DESC'));
|
||||
} else {
|
||||
$articles = Article::model()->getAll(array('where'=>'`author`='.(int)$user->id . ' AND `status` = "published" '));
|
||||
$articles = Article::model()->getAll(array('where'=>'`author`='.(int)$user->id . ' AND `status` = "published" ', 'order' => '`pubDate` DESC'));
|
||||
}
|
||||
|
||||
$randomPoint = Point::model()->getRandom();
|
||||
$randomPoint->description = mb_substr($randomPoint->description, 0, 400, 'UTF-8');
|
||||
$randomPoint->description = Helper::replaceLinks($randomPoint->description);
|
||||
|
||||
$photos = ArticlePhotos::model()->getByUser($id, 5);
|
||||
// $photos = ArticlePhotos::model()->getByUser($id, 5);
|
||||
$photos = NULL; // Скрыл фотоленту, так как туда могут попадать фотки неопубликованных статей
|
||||
|
||||
self::render('user/index.php', array(
|
||||
'user' => $user,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
<form method="POST" action="/articles/save" style="height: 100%;">
|
||||
<form method="POST" action="/article/save" style="height: 100%;">
|
||||
<input type="hidden" name="id" value="<?= $article->id ?>" />
|
||||
<input type="hidden" name="allowComments" value="1" />
|
||||
<!-- <input type="checkbox" name="allowComments" id="articleComments" <?= $article->allowComments ? 'checked' : '' ?> />Разрешить комментарии-->
|
||||
|
|
@ -19,7 +19,7 @@
|
|||
<?php if ($article->id): ?>
|
||||
<a href="/article/<?= $article->id ?>" target="_blank" class="btn btn-sm btn-default" title="Просмотр последней сохраненой версии"><span class="glyphicon glyphicon-eye-open" aria-hidden="true"></span> предпросмотр</a>
|
||||
<?php endif; ?>
|
||||
<a href="/articles/" class="btn btn-sm btn-danger" title="Выйти без сохранения"><span class="glyphicon glyphicon-floppy-remove" aria-hidden="true"></span> не сохранять</a>
|
||||
<a href="/user/" class="btn btn-sm btn-danger" onclick="return confirm('Выйти без сохранения изменений?')" title="Выйти без сохранения"><span class="glyphicon glyphicon-floppy-remove" aria-hidden="true"></span> выйти не сохраняя</a>
|
||||
</div>
|
||||
<div class="btn-group" role="group" aria-label="...">
|
||||
<button type="submit" class="btn btn-sm btn-default" name="save" value="published" title="Сохранить"><span class="glyphicon glyphicon-floppy-saved"></span> опубликовать</button>
|
||||
|
|
|
|||
|
|
@ -15,8 +15,12 @@
|
|||
<div class="container lightBody">
|
||||
<div class="row">
|
||||
<div class="col-md-12 articlesList">
|
||||
|
||||
<h2>Записи: </h2>
|
||||
<h2>
|
||||
<?php if ($imAuthor) : ?>
|
||||
<a href="/article/new/" class="pull-right btn btn-success"><span class="glyphicon glyphicon-plus"></span> Новая запись</a>
|
||||
<?php endif; ?>
|
||||
Записи:
|
||||
</h2>
|
||||
|
||||
<?php if ($articles): foreach ($articles as $article): ?>
|
||||
<div class="article">
|
||||
|
|
@ -27,8 +31,14 @@
|
|||
<img src="/img/noPhoto200150.png" />
|
||||
<?php endif; ?>
|
||||
</a>
|
||||
<div class="pull-right date"><?= date('H:i | d.m.Y',$article->pubDate) ?></div>
|
||||
<a href="/article/<?= $article->id ?>" target="_blank" class="h"><?= $article->title ?></a>
|
||||
<?= mb_substr(Markdown::getClear(str_replace('"', 'ʺ', $article->text)), 0, 250, 'UTF-8') ?>…
|
||||
<?php if ($imAuthor) : ?>
|
||||
<br/>
|
||||
<a href="/article/edit/id/<?= $article->id ?>" title="Редактировать" class="pull-right btn btn-sm btn-info"><span class="glyphicon glyphicon-pencil"></span></a>
|
||||
<a href="/article/del/id/<?= $article->id ?>" onclick="return confirm('Удалить запись?')" title="Удалить" class="pull-right btn btn-sm btn-danger"><span class="glyphicon glyphicon-trash"></span></a>
|
||||
<?php endif; ?>
|
||||
<div class="clear"></div>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
.darkHeader .userPic img {height: 70px; border-radius: 5px;}
|
||||
.darkHeader .socialNetworks {margin-top: 10px;}
|
||||
.darkHeader .socialNetworks a.toPoints{color: #fff;}
|
||||
.darkHeader .socialNetworks img {height: 30px; margin: 0 5px;}
|
||||
.darkHeader .socialNetworks img {height: 24px; margin: 0 5px;}
|
||||
|
||||
.lightBody {background-color: rgba(255,255,255, 0.8);margin-top: 0px;padding-bottom: 30px;}
|
||||
|
||||
|
|
@ -12,6 +12,7 @@
|
|||
.articlesList .article {border: solid 1px #ddd; border-radius: 3px; padding: 4px; margin-bottom: 5px;background-color: rgba(255,255,255, 0.8);}
|
||||
.articlesList .article img {width: 100px; float: left; margin-right: 10px;}
|
||||
.articlesList .article .h {font-size: 18px; font-weight: bold; display: block;}
|
||||
.articlesList .article .date {font-size: 11px; color: #bbb; }
|
||||
|
||||
.photoList {}
|
||||
.photoList .photo {display: inline-block; border: solid 3px #fff; margin: 3px;}
|
||||
|
|
|
|||
|
|
@ -92,7 +92,7 @@ function wrapText(elementID, openTag, closeTag) {
|
|||
|
||||
function markdown()
|
||||
{
|
||||
$.post('/articles/markdown', {text: $('#articleText').val()}, function (data) {
|
||||
$.post('/article/markdown', {text: $('#articleText').val()}, function (data) {
|
||||
$('#monitor').html(data);
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue