function __construct() { $this->m_articles = M_Articles::Instance(); $this->mysql = MSQL::Instance(); $this->m_users = M_Users::Instance(); parent::__construct(); }
public static function Instance() { if (self::$instance == null) { self::$instance = new M_Articles(); } return self::$instance; }
protected function OnInput() { parent::onInput(); $this->m_articles = M_Articles::Instance(); $this->mysql->Connect('localhost', 'root', '', 'liveblog'); $result = $this->m_users->Get(); if ($this->isPost()) { if (isset($_POST['save'])) { if ($this->m_articles->Edit($_GET['id'], $_POST['title'], $_POST['content'], $result['login'])) { header('Location: index.php?c=editor'); die; } } if (isset($_POST['delete'])) { if ($this->m_articles->Delete($_GET['id'])) { header('Location: index.php?c=editor'); die; } } $this->form_art['title'] = $_POST['title']; $this->form_art['content'] = $_POST['content']; } else { $this->form_art = $this->m_articles->show_one_article($_GET['id']); } }
public static function Instance() { // гарантия одного экземпляра if (self::$instance === null) { self::$instance = new self(); } return self::$instance; }
public function action_new() { // Обработка отправки формы if (isset($_POST['submit'])) { if ($_POST['title_art'] != "" && $_POST['content_art'] != "") { M_Articles::getInstance()->article_new($_POST['title_art'], $_POST['date_art'], $_POST['content_art']); die(header('Location: index.php')); } } $this->title .= '::Добавить статью'; $this->content = $this->Template('v/v_new.php'); }
public function action_index() { // Значение по умолчанию для кол-ва статей на одной странице if ($_SESSION['num'] == null) { $_SESSION['num'] = 5; } // Проверка ГЕТ запроса, содержащего кол-во статей, которое должно отображаться на одной страние(по-умолчанию 5) if (isset($_GET['num'])) { // Сохранение в переменную $num = (int) $_GET['num']; // Проверка значения if ($num <= 10 && $num > 0) { // Запись в сессию и редирект $_SESSION['num'] = $num; redirect('index.php'); } } // Подсчет кол-ва статей в БД $count = M_MYSQL::getInstance()->articles_count(); // Переменная равная отношению кол-ва статей в БД к требуемому кол-ву статей на одной странице $n = $count / $_SESSION['num']; // Проверка ГЕТ запроса, содержащего номер страницы if (isset($_GET['page'])) { // Сохранение в переменную $num_page = (int) $_GET['page']; // Округление в большую сторону $n1 = ceil($n); // Проверка значения if ($num_page > $n1 || $num_page <= 1) { redirect('index.php'); } } // Подготовка данных $articles_all = M_Articles::getInstance()->All_main(40, $_GET['page'], $_SESSION['num']); $this->title .= '::Список статей'; $nav = $this->template('v/block/v_block_sort.php', array('n' => $n)); $sort = $this->template('v/block/v_block_sort.php'); $this->content = $this->template('v/v_index.php', array('articles_all' => $articles_all, 'nav' => $nav, 'sort' => $sort)); }
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_show() { $mArticles = M_Articles::Instance(); $mComments = M_Comments::Instance(); $mUsers = M_Users::Instance(); $User = $mUsers->Get(); $this->id = isset($this->params[0]) ? (int) $this->params[0] : 1; //array_shift($params); $display_page = (int) $this->id; if ($display_page < 1) { // Неверный запрос, редирект die(header('Location: ./index.php?c=index&act=index')); } //var_dump ($this -> comments); $record = $mArticles->Get($display_page); $article = $record[0]; $this->requested_id = $article['id_article']; $this->requested_name = $article['title']; $this->requested_text = $article['content']; if ($this->requested_name == '') { // Неверный запрос, редирект die(redirect('/page/index')); } // получение массива комментариев к статье //$this-> mysql = M_MYSQL::getInstance(); $mComments = M_Comments::Instance(); $this->comments = $mComments->All_by_art_id($this->requested_id); //Обработка POST-запроса $this->mysql = M_MSQL::Instance(); if (!empty($_POST) && isset($_POST['com_text'])) { $mUsers = M_Users::Instance(); $User = $mUsers->Get(); // успешно данные добавлены, редирект $table = 'comments'; $object = array(); $object['id_article'] = $this->requested_id; $object['name'] = $User['name']; $object['comment'] = $_POST['com_text']; $object['date'] = date("Y-m-d"); if ($this->mysql->insert($table, $object)) { $i = (int) $this->requested_id; $this->redirect('/page/index'); } } if ($mUsers->Can('DELETE_COMMENTS')) { $comm_delete = true; } else { $comm_delete = false; } $comm_add = ''; if (!$mUsers->Can('ADD_ARTICLES')) { $comm_add = 'hidden'; } $nick = $User["name"]; if ($User["name"] == '') { $nick = 'Гость'; } $this->title .= ':: Статья ' . $this->requested_id; $vars = array('layout' => 'regular', 'username' => $nick); $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('comments' => $this->comments, 'comm_delete' => $comm_delete, 'comm_add' => $comm_add); $this->comments_ = $this->Template('./v/elements/comments.php', $vars); $vars = array('requested_name' => $this->requested_name, 'requested_text' => $this->requested_text, 'menu' => $this->menu, 'comments' => $this->comments_, 'left_block' => $this->left_block); $this->content = $this->Template('./v/v_article.php', $vars); }