Пример #1
0
 function __construct()
 {
     $this->m_articles = M_Articles::Instance();
     $this->mysql = MSQL::Instance();
     $this->m_users = M_Users::Instance();
     parent::__construct();
 }
Пример #2
0
 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']);
     }
 }
Пример #3
0
 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);
 }
Пример #4
0
 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);
 }