isAdmin) { App::error404(); } // ------------------------------------------ App::setConfig('title', App::$defaultTitle); self::render('articles/index.php', array( '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 = '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; } }