protected function action_article() { $mArticles = M_Article::Instance(); $this->Only = $mArticles->Only($_GET['id']); //print_r($this->Only); $this->title_h1 .= '::Выбор одной статьи'; $m_comments = M_Comments::Instance(); $this->All_comments = $m_comments->All_comments($_GET['id']); if ($_POST) { $this->Add_comments = $m_comments->Add_comments($this->Only['id'], $_POST['login'], $_POST['text'], $_POST['created_date']); } else { $this->Add_comments = ''; } $this->content = $this->Template('v/v_article.php', array('article' => $this->Only, 'comments' => $this->All_comments, 'Add_comments' => $this->Add_comments)); //print_r($this->All_coments); //$this->comments = $this->Template('v/v_comments.php', array('comments' => $this->All_comments)); }
public function action_archive() { // Получение номера страницы $page_num = isset($_GET['page']) ? (int) $_GET['page'] : 1; if ($page_num < 1) { $page_num = 1; } $time = isset($_GET['date']) ? strtotime($_GET['date']) : false; if ($time == false) { $this->p404(); } $date = date("Y-m-d", $time); $this->active = date("Y-m", $time); $this->title = 'Архив за ' . date("Y-m", $time); $this->breadCrambsActive = $this->title; $this->pageUrl = rtrim(M_Link::ToPage('archive'), '/'); // Создание объекта постраничной навигации(обязательные параметры) $mPagination = new M_Pagination('posts', M_Link::ToPage('archive', $this->active)); // Задание свойств объекта $this->pages = $mPagination->on_page(5)->page_num($page_num)->fields("post_id, post_title, post_content, \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tpost_date_create, views, comment_status, user_name")->left_join('users ON post_author = user_id')->where("post_status = 'publish' AND post_type = 'post' AND\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t(post_date_create BETWEEN '{$date}' AND \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tDATE_ADD(LAST_DAY('{$date}'), INTERVAL 1 DAY))")->order_by('post_date_create DESC')->page(); foreach ($this->pages as $key => $value) { $postion = mb_strpos($value['post_content'], '<!--anonsbreak-->'); if ($postion !== false) { $this->pages[$key]['anons'] = mb_substr($value['post_content'], 0, $postion - 1); } } // Получение пути к шаблону $templateName = $this->getTemplate('v_navbar.php'); // Получение hmlt-кода панели навигации $this->navBar = $this->Template($templateName, $mPagination); // $this->navParams = $mPagination->navparams(); $mComments = M_Comments::Instance(); $this->countComments = $mComments->countItemsByAllSubjects(); // Получение пути к шаблону $templateName = $this->getTemplate('components/page/v_index.php'); // Формирование контента страницы //$this->content = $this->Template($templateName, $this); $this->blocks['_content_page'] = $this->Template($templateName, $this); }
public function action_edit() { $mArticles = M_Articles::Instance(); $mComments = M_Comments::Instance(); $mUsers = M_Users::Instance(); $User = $mUsers->Get(); if (!$mUsers->Can('EDIT_ARTICLES')) { $this->redirect('/editor/editor'); } $this->title .= ':: Редактирование'; $this->id = isset($this->params[0]) ? (int) $this->params[0] : 1; $record = $mArticles->Get($this->id); $article = $record[0]; if (isset($article)) { $this->art_title = $article['title']; $this->art_text = $article['content']; $this->error = false; } else { $this->redirect('/editor/editor/'); } // Обработка отправки формы - Удаление статьи if (!empty($_POST) && $_POST['delete_'] == 'on') { $this->msql = M_MSQL::Instance(); $table1 = 'articles'; $table2 = 'comments'; $where = '`id_article` = ' . $this->id; if ($this->msql->delete($table1, $where) || $this->msql->delete($table2, $where)) { $this->redirect('/editor/editor/'); } } // Изменение статьи if (!empty($_POST) && $_POST['delete_'] != 'on') { // Данные изменены, редирект if ($mArticles->is_real_article($_POST['title'], $_POST['content'])) { if ($mArticles->articles_edit($this->id, $_POST['title'], $_POST['content'])) { $this->redirect('/editor/editor/'); } } else { $this->art_title = $_POST['title']; $this->art_text = $_POST['content']; $error = true; $this->message = 'В заголовке должно присутствовать хотябы одно слово, в тексте - несколько предложений!'; } } //Вывод $vars = array('layout' => 'regular', 'username' => $User["name"]); $this->menu = $this->Template('./v/elements/menu.php', $vars); $this->left_block = $mComments->latest_comments(); $vars = array('left_block' => $this->left_block); $this->left_block = $this->Template('./v/elements/new_comments.php', $vars); $vars = array('art_title' => $this->art_title, 'art_text' => $this->art_text, 'menu' => $this->menu, 'error' => $this->error, 'left_block' => $this->left_block, 'message' => $this->message); $this->content = $this->Template('./v/v_edit.php', $vars); }
public function action_delcom() { $mUsers = M_Users::Instance(); $mComments = M_Comments::Instance(); $User = $mUsers->Get(); $this->id_comm = isset($this->params[0]) ? (int) $this->params[0] : 1; // Удаление комментария $page_redir = $mComments->comment_delete($this->id_comm); if ($page_redir != 0) { $this->redirect("/page/show/{$page_redir}"); } else { $this->redirect('/'); } }
public function getLastestComments() { $comments = M_Comments::Instance()->getLastestComments(5); // Получение пути к шаблону $templateName = $this->getTemplate('components/page/v_posts_lastest_comments.php'); $_comments = $this->Template($templateName, array('comments' => $comments)); return $_comments; }
public function get_for_post($post_id) { $mComments = M_Comments::Instance(); $mComments->setIdSubject($post_id); $this->isLogged = (bool) $this->user; if ($this->isPost() && isset($_POST["comment_btn"])) { $comment_id = isset($_POST['comment_id']) ? (int) $_POST['comment_id'] : 0; if ($this->user) { $_POST['comment_author_id'] = $this->user['user_id']; $_POST['comment_author'] = $this->user['user_name']; $_POST['comment_author_email'] = $this->user['login']; } else { $_POST['comment_author_id'] = 0; } $new_comment_id = $mComments->add($_POST, $comment_id); if (!empty($new_comment_id)) { $url = M_Link::ToPage('post', $post_id) . '#commentItem' . $new_comment_id; $this->redirect($url); } $this->messages = $mComments->errors(); $this->fields = $_POST; } else { $this->fields = array_fill_keys(array('comment_author', 'comment_author_email', 'comment_content'), ''); } // Получаем переменные для шаблона $this->comments = $mComments->getTree(); $this->post_id = $post_id; // Получение пути к шаблону $templateName = $this->getTemplate('components/page/v_comments.php'); // Формирование контента страницы $treeComment = $this->blocks['_content_page'] = $this->Template($templateName, $this); return $treeComment; }