Просмотр файла mc-2.7.0/modules/forum/controllers/forum.php

Размер файла: 24.7Kb
  1. <?php
  2.  
  3. /**
  4. * MobileCMS
  5. *
  6. * Open source content management system for mobile sites
  7. *
  8. * @author MobileCMS Team <support@mobilecms.pro>
  9. * @copyright Copyright (c) 2011-2019, MobileCMS Team
  10. * @link https://mobilecms.pro Official site
  11. * @license MIT license
  12. */
  13. defined('IN_SYSTEM') or die('<b>403<br />Запрет доступа!</b>');
  14.  
  15. /**
  16. * Контроллер форума, пользовательская часть
  17. */
  18. class Forum_Controller extends Controller {
  19.  
  20. /**
  21. * Метод по умолчанию
  22. */
  23. public function action_index() {
  24. $this->action_list_sections();
  25. }
  26.  
  27. /**
  28. * Список разделов
  29. */
  30. public function action_list_sections() {
  31. $sections = array();
  32. $result = $this->db->query("SELECT * FROM #__forum_sections ORDER BY position");
  33. while ($section = $this->db->fetch_array($result)) {
  34. if ($this->config['forum']['show_forums_in_list_sections'] || $section['section_id'] == @$_GET['section_id']) {
  35. $section['forums'] = array();
  36. $result1 = $this->db->query("SELECT * FROM #__forum_forums WHERE section_id = '" . $section['section_id'] . "' ORDER BY position");
  37. while ($forum = $this->db->fetch_array($result1))
  38. $section['forums'][] = $forum;
  39. }
  40. $sections[] = $section;
  41. }
  42.  
  43. $this->tpl->assign(array(
  44. 'sections' => $sections
  45. ));
  46.  
  47. $this->tpl->display('list_sections');
  48. }
  49.  
  50. /**
  51. * Просмотр форума
  52. */
  53. public function action_viewforum() {
  54. $this->per_page = $this->config['forum']['topics_per_page'];
  55.  
  56. if ($_GET['type'] != 'new') {
  57. if (!$forum = $this->db->get_row("SELECT * FROM #__forum_forums WHERE forum_id = '" . intval($_GET['forum_id']) . "'"))
  58. a_error("Форум не найден!");
  59. }
  60.  
  61. # Получение данных
  62. switch ($_GET['type']) {
  63. case 'new':
  64. $sql = "SELECT SQL_CALC_FOUND_ROWS ft.*, u.username AS last_username
  65. FROM #__forum_topics AS ft
  66. INNER JOIN #__users AS u ON ft.last_user_id = u.user_id
  67. ORDER BY ft.time DESC
  68. LIMIT $this->start, $this->per_page";
  69. break;
  70. default:
  71. $sql = "SELECT SQL_CALC_FOUND_ROWS ft.*, u.username AS last_username
  72. FROM #__forum_topics AS ft
  73. INNER JOIN #__users AS u ON ft.last_user_id = u.user_id
  74. WHERE ft.forum_id = '" . $forum['forum_id'] . "'
  75. ORDER BY ft.is_top_topic DESC, ft.last_message_time DESC
  76. LIMIT $this->start, $this->per_page";
  77. break;
  78. }
  79.  
  80. $topics = $this->db->get_array($sql);
  81. $total = $this->db->get_one("SELECT FOUND_ROWS()");
  82.  
  83. # Пагинация
  84. $pg_conf['base_url'] = a_url('forum/viewforum', 'forum_id=' . $_GET['forum_id'] . '&amp;type=' . $_GET['type'] . '&amp;start=');
  85. $pg_conf['total_rows'] = $total;
  86. $pg_conf['per_page'] = $this->per_page;
  87.  
  88. a_import('libraries/pagination');
  89. $pg = new CI_Pagination($pg_conf);
  90.  
  91. $this->tpl->assign(array(
  92. 'topics' => $topics,
  93. 'forum' => $forum,
  94. 'total' => $total,
  95. 'pagination' => $pg->create_links(),
  96. 'section' => $this->db->get_row("SELECT * FROM #__forum_sections WHERE section_id = '" . $forum['section_id'] . "'"),
  97. 'messages_per_page' => $this->config['forum']['messages_per_page']
  98. ));
  99.  
  100. $this->tpl->display('viewforum');
  101. }
  102.  
  103. /**
  104. * Просмотр темы
  105. */
  106. public function action_viewtopic() {
  107. $this->per_page = $this->config['forum']['messages_per_page'];
  108.  
  109. if (!$topic = $this->db->get_row("SELECT * FROM #__forum_topics WHERE topic_id = '" . intval($_GET['topic_id']) . "'"))
  110. a_error("Тема не найдена!");
  111.  
  112. # Получение данных
  113. $result = $this->db->query("SELECT SQL_CALC_FOUND_ROWS fm.*, u.username AS username, u.status AS user_status, up.avatar AS avatar_exists, u.last_visit, ff.file_id, ff.file_size, ff.file_downloads, ff.file_name
  114. FROM #__forum_messages AS fm
  115. INNER JOIN #__users AS u USING(user_id)
  116. LEFT JOIN #__users_profiles AS up USING(user_id)
  117. LEFT JOIN #__forum_files AS ff USING(message_id)
  118. WHERE fm.topic_id = '" . $topic['topic_id'] . "'
  119. ORDER BY fm.message_id ASC
  120. LIMIT $this->start, $this->per_page
  121. ");
  122.  
  123. $messages = array();
  124. $num = $this->start;
  125. if (!class_exists('smiles'))
  126. a_import('modules/smiles/helpers/smiles');
  127. while ($message = $this->db->fetch_array($result)) {
  128. $message['num'] = ++$num;
  129. $message['message'] = main::bbcode($message['message']);
  130. $message['message'] = smiles::smiles_replace($message['message']);
  131. $message['message'] = nl2br($message['message']);
  132. $messages[] = $message;
  133. }
  134.  
  135. $total = $this->db->get_one("SELECT FOUND_ROWS()");
  136.  
  137. # Пагинация
  138. $pg_conf['base_url'] = a_url('forum/viewtopic', 'topic_id=' . $_GET['topic_id'] . '&amp;start=');
  139. $pg_conf['total_rows'] = $total;
  140. $pg_conf['per_page'] = $this->per_page;
  141.  
  142. a_import('libraries/pagination');
  143. $pg = new CI_Pagination($pg_conf);
  144.  
  145. $this->tpl->assign(array(
  146. 'messages' => $messages,
  147. 'topic' => $topic,
  148. 'total' => $total,
  149. 'pagination' => $pg->create_links(),
  150. 'forum' => $this->db->get_row("SELECT * FROM #__forum_forums WHERE forum_id = '" . $topic['forum_id'] . "'")
  151. ));
  152.  
  153. $this->tpl->display('viewtopic');
  154. }
  155.  
  156. /**
  157. * Закрепление / открепление темы
  158. */
  159. public function action_topic_top() {
  160. if (!$topic = $this->db->get_row("SELECT * FROM #__forum_topics WHERE topic_id = '" . intval($_GET['topic_id']) . "'"))
  161. a_error("Тема не найдена!");
  162.  
  163. if (ACCESS_LEVEL < 8)
  164. a_error('У вас нет прав на выполнение этой операции!');
  165.  
  166. $status = $_GET['a'] == 'top' ? 1 : 0;
  167. $this->db->query("UPDATE #__forum_topics SET is_top_topic = '$status' WHERE topic_id = '" . $topic['topic_id'] . "'");
  168.  
  169. header("Location: " . a_url('forum/viewforum', 'forum_id=' . $topic['forum_id'] . '&start=' . @$_GET['start'], TRUE));
  170. exit;
  171. }
  172.  
  173. /**
  174. * Закрытие / окрытие темы
  175. */
  176. public function action_topic_close() {
  177. if (!$topic = $this->db->get_row("SELECT * FROM #__forum_topics WHERE topic_id = '" . intval($_GET['topic_id']) . "'"))
  178. a_error("Тема не найдена!");
  179.  
  180. if (ACCESS_LEVEL < 8)
  181. a_error('У вас нет прав на выполнение этой операции!');
  182.  
  183. $status = $_GET['a'] == 'close' ? 1 : 0;
  184. $this->db->query("UPDATE #__forum_topics SET is_close_topic = '$status' WHERE topic_id = '" . $topic['topic_id'] . "'");
  185.  
  186. header("Location: " . a_url('forum/viewforum', 'forum_id=' . $topic['forum_id'] . '&start=' . @$_GET['start'], TRUE));
  187. exit;
  188. }
  189.  
  190. /**
  191. * Закрытие / окрытие темы
  192. */
  193. public function action_topic_delete() {
  194. if (!$topic = $this->db->get_row("SELECT * FROM #__forum_topics WHERE topic_id = '" . intval($_GET['topic_id']) . "'")) {
  195. a_error("Тема не найдена!");
  196. }
  197.  
  198. if (ACCESS_LEVEL < 8) {
  199. a_error('У вас нет прав на выполнение этой операции!');
  200. }
  201.  
  202. if (!empty($_GET['confirm'])) {
  203. # удаляем тему
  204. $this->db->query("DELETE FROM #__forum_topics WHERE topic_id = '" . $topic['topic_id'] . "'");
  205. # удаляем сообщения в теме
  206. $this->db->query("DELETE FROM #__forum_messages WHERE topic_id = '" . $topic['topic_id'] . "'");
  207. # обновляем счетчик тем и сообщений в форуме
  208. $this->db->query("UPDATE #__forum_forums SET
  209. topics = topics - 1,
  210. messages = messages - " . $topic['messages'] . " - 1
  211. WHERE forum_id = '" . $topic['forum_id'] . "'
  212. ");
  213.  
  214. header("Location: " . a_url('forum/viewforum', 'forum_id=' . $topic['forum_id'] . '&start=' . @$_GET['start'], TRUE));
  215. exit;
  216. } else {
  217. a_confirm('Действительно хотите удалить тему &laquo;' . $topic['name'] . '&raquo; со всеми сообщениями?', a_url('forum/topic_delete', 'confirm=yes&amp;topic_id=' . $topic['topic_id'] . '&amp;start=' . @$_GET['start']), a_url('forum/viewforum', 'forum_id=' . $topic['forum_id'] . '&amp;start=' . @$_GET['start']));
  218. }
  219. }
  220.  
  221. /**
  222. * Удаление сообщения
  223. */
  224. public function action_message_delete() {
  225. if (!$message = $this->db->get_row("SELECT m.*,
  226. (SELECT status FROM #__users AS u WHERE u.user_id = m.user_id) AS user_status
  227. FROM #__forum_messages AS m
  228. WHERE message_id = '" . intval($_GET['message_id']) . "'")) {
  229. a_error("Сообщение не найдено!");
  230. }
  231.  
  232. if (!a_check_rights($message['user_id'], $message['user_status']) || !$message['is_last_message']) {
  233. a_error('У вас нет права удалять данное сообщение!');
  234. }
  235.  
  236. if (!empty($_GET['confirm'])) {
  237. # Удаляем сообщение
  238. $this->db->query("DELETE FROM #__forum_messages WHERE message_id = '" . $message['message_id'] . "'");
  239. # Обновляем счетчики сообщений
  240. $this->db->query("UPDATE #__forum_topics SET messages = messages - 1 WHERE topic_id = '" . $message['topic_id'] . "'");
  241. $this->db->query("UPDATE #__forum_forums SET messages = messages - 1 WHERE forum_id = '" . $message['forum_id'] . "'");
  242.  
  243. # Отнимаем рейтинг
  244. user::rating_update(-1, $message['user_id']);
  245.  
  246. header("Location: " . a_url('forum/viewtopic', 'topic_id=' . $message['topic_id'] . '&start=' . @$_GET['start'], TRUE));
  247. exit;
  248. } else {
  249. a_confirm('Действительно хотите удалить данное сообщение?', a_url('forum/message_delete', 'confirm=yes&amp;message_id=' . $message['message_id'] . '&amp;start=' . @$_GET['start']), a_url('forum/viewtopic', 'topic_id=' . $message['topic_id'] . '&amp;start=' . @$_GET['start']));
  250. }
  251. }
  252.  
  253. /**
  254. * Постинг
  255. */
  256. public function action_posting() {
  257. if (!empty($_GET['new_topic'])) {
  258. if (!$forum = $this->db->get_row("SELECT * FROM #__forum_forums WHERE forum_id = '" . intval($_GET['forum_id']) . "'")) {
  259. a_error("Форум не найден!");
  260. }
  261. $action = 'new_topic';
  262. $message = array();
  263. $title = "Новая тема";
  264.  
  265. if (USER_ID == -1 && !$this->config['forum']['guests_create_topics']) {
  266. a_error("Гости не имеют права создвать темы!<br />Зарегистрируйтесь или войдите под своим именем.");
  267. }
  268. } else {
  269. if (is_numeric($_GET['message_id'])) {
  270. if (!$message = $this->db->get_row("SELECT * FROM #__forum_messages WHERE message_id = '" . intval($_GET['message_id']) . "'")) {
  271. a_error("Сообщение не найдено!");
  272. }
  273.  
  274. if (ACCESS_LEVEL < 8 && $message['user_id'] != USER_ID) {
  275. a_error("У вас нет прав редактировать данное сообщение!");
  276. }
  277.  
  278. if ($message['is_first_message'] == 1) {
  279. $action = 'edit_first_message';
  280. } else {
  281. $action = 'edit_message';
  282. }
  283.  
  284. $title = "Редактировать сообщение";
  285. $message_text = $message['message'];
  286. $topic_id = $message['topic_id'];
  287. } else {
  288. $action = 'new_message';
  289. $message = array();
  290. $title = "Новое сообщение";
  291. $topic_id = $_GET['topic_id'];
  292.  
  293. $message_text = '';
  294.  
  295. if (!empty($_GET['replay'])) {
  296. $message_text .= '[b]' . $_GET['replay'] . '[/b], ';
  297. } elseif (is_numeric($_GET['q'])) {
  298. if (!$q_post = $this->db->get_row("SELECT * FROM #__forum_messages LEFT JOIN #__users USING(user_id) WHERE message_id = '" . intval($_GET['q']) . "'"))
  299. a_error("Не найден пост для цитирования");
  300.  
  301. $message_text .= '[q]' . $q_post['username'] . ' (' . date('d.m.Y в H:i', $q_post['time']) . ')' . PHP_EOL;
  302. $message_text .= $q_post['message'] . '[/q]' . PHP_EOL;
  303. }
  304.  
  305. if (USER_ID == -1 && !$this->config['forum']['guests_write_messages'])
  306. a_error("Гости не имеют отвечать на темы!<br />Зарегистрируйтесь или войдите под своим именем.");
  307. }
  308.  
  309. if (!$topic = $this->db->get_row("SELECT * FROM #__forum_topics WHERE topic_id = '" . intval($topic_id) . "'"))
  310. a_error("Тема не найдена!");
  311.  
  312. # Определяем можно ли постить в теме
  313. if (ACCESS_LEVEL < 8 && $topic['is_close_topic'])
  314. a_error("Тема закрыта, вы не имеете права писать и редактировать сообщения!");
  315. }
  316.  
  317. if (isset($_POST['submit'])) {
  318. if ($action == 'new_topic' || $action == 'edit_first_message') {
  319. if (empty($_POST['topic_name'])) {
  320. $this->error .= 'Укажите название темы!<br />';
  321. }
  322. }
  323. if (empty($_POST['message'])) {
  324. $this->error .= 'Укажите сообщение!<br />';
  325. }
  326. # Проверка кода с картинки
  327. if (USER_ID == -1) {
  328. if ($_POST['captcha_code'] != $_SESSION['captcha_code']) {
  329. $this->error .= 'Неверно указан код с картинки<br />';
  330. }
  331. }
  332. # Проверка прикрепляемого файла
  333. if (!empty($_FILES['attach']['tmp_name'])) {
  334. $file_ext = array_pop(explode('.', $_FILES['attach']['name']));
  335.  
  336. if (!strstr(';' . $this->config['forum']['allowed_filetypes'] . ';', ';' . $file_ext . ';'))
  337. $this->error .= 'Вы пытаетесь загрузить запрещенный тип файла<br />';
  338.  
  339. if (filesize($_FILES['attach']['tmp_name']) > $this->config['forum']['max_filesize'] * 1048576)
  340. $this->error .= 'Размер загружаемого файла превышает допустимый размер (' . $this->config['forum']['max_filesize'] . ' Mb)<br />';
  341. }
  342.  
  343. if (!$this->error) {
  344. $_SESSION['captcha_code'] = main::get_unique_code(4);
  345.  
  346. switch ($action) {
  347. # Создание темы
  348. case 'new_topic':
  349. # Добавляем тему
  350. $this->db->query("INSERT INTO #__forum_topics SET
  351. section_id = '" . $forum['section_id'] . "',
  352. forum_id = '" . $forum['forum_id'] . "',
  353. user_id = '" . USER_ID . "',
  354. name = '" . a_safe($_POST['topic_name']) . "',
  355. time = UNIX_TIMESTAMP(),
  356. last_message_time = UNIX_TIMESTAMP(),
  357. last_user_id = '" . USER_ID . "'
  358. ");
  359. $topic_id = $this->db->insert_id();
  360.  
  361. # Добавляем сообщение
  362. $this->db->query("INSERT INTO #__forum_messages SET
  363. topic_id = '" . $topic_id . "',
  364. section_id = '" . $forum['section_id'] . "',
  365. forum_id = '" . $forum['forum_id'] . "',
  366. user_id = '" . USER_ID . "',
  367. message = '" . a_safe($_POST['message']) . "',
  368. is_first_message = 1,
  369. time = UNIX_TIMESTAMP()
  370. ");
  371. $message_id = $this->db->insert_id();
  372.  
  373. # Увеличиваем количество тем и сообщений в форуме
  374. $this->db->query("UPDATE #__forum_forums SET
  375. topics = topics + 1,
  376. messages = messages + 1
  377. WHERE
  378. forum_id = '" . $forum['forum_id'] . "'
  379. ");
  380.  
  381. # Добавляем рейтинг
  382. user::rating_update();
  383.  
  384. $location = a_url('forum/viewtopic', 'topic_id=' . $topic_id, true);
  385. break;
  386. # Добавление сообщения
  387. case 'new_message':
  388. # Снимаем метку с последнего сообщения
  389. $this->db->query("UPDATE #__forum_messages SET is_last_message = 0 WHERE topic_id = '" . $topic['topic_id'] . "'");
  390.  
  391. # Добавляем сообщение
  392. $this->db->query("INSERT INTO #__forum_messages SET
  393. topic_id = '" . $topic['topic_id'] . "',
  394. section_id = '" . $topic['section_id'] . "',
  395. forum_id = '" . $topic['forum_id'] . "',
  396. user_id = '" . USER_ID . "',
  397. message = '" . a_safe($_POST['message']) . "',
  398. is_last_message = 1,
  399. time = UNIX_TIMESTAMP()
  400. ");
  401. $message_id = $this->db->insert_id();
  402.  
  403. # Обновляем счетчик сообщений темы и время последнего сообщения
  404. $this->db->query("UPDATE #__forum_topics SET
  405. messages = messages + 1,
  406. last_message_time = UNIX_TIMESTAMP(),
  407. last_user_id = '" . USER_ID . "'
  408. WHERE topic_id = '" . $topic['topic_id'] . "'
  409. ");
  410.  
  411. # Увеличиваем количество сообщений в форуме
  412. $this->db->query("UPDATE #__forum_forums SET
  413. messages = messages + 1
  414. WHERE
  415. forum_id = '" . $topic['forum_id'] . "'
  416. ");
  417.  
  418. # Добавляем рейтинг
  419. user::rating_update();
  420.  
  421. # Определяем start для пагинации
  422. $messages = $topic['messages'] + 1;
  423. $start = floor($messages / $this->config['forum']['messages_per_page']) * $this->config['forum']['messages_per_page'];
  424.  
  425. $location = a_url('forum/viewtopic', 'topic_id=' . $topic['topic_id'] . '&start=' . $start, true);
  426. break;
  427. # Редактирование сообщения
  428. case 'edit_first_message':
  429. $this->db->query("UPDATE #__forum_topics SET name = '" . a_safe($_POST['topic_name']) . "' WHERE topic_id = '" . $message['topic_id'] . "'");
  430. case 'edit_message':
  431. # Изменяем сообщение
  432. $this->db->query("UPDATE #__forum_messages SET
  433. message = '" . a_safe($_POST['message']) . "',
  434. edit_editor = '" . $this->user['username'] . "',
  435. edit_time = UNIX_TIMESTAMP(),
  436. edit_count = edit_count + 1
  437. WHERE
  438. message_id = '" . $message['message_id'] . "'
  439. ");
  440. $message_id = $message['message_id'];
  441.  
  442. $location = a_url('forum/viewtopic', 'topic_id=' . $message['topic_id'], true);
  443. break;
  444. }
  445.  
  446. if (!empty($_FILES['attach']['tmp_name'])) {
  447. # Удаляем старый файл, если имеется
  448. if ($old_file = $this->db->get_row("SELECT * FROM #__forum_files WHERE message_id = '$message_id'")) {
  449. @unlink(ROOT . 'files/forum/' . main::get_dir($old_file['file_id']) . '/' . $old_file['file_name']);
  450. $this->db->query("DELETE FROM #__forum_files WHERE file_id = '" . $old_file['file_id'] . "'");
  451. }
  452.  
  453. # Получаем ID нового файла
  454. $this->db->query("INSERT INTO #__forum_files SET file_id = NULL");
  455. $file_id = $this->db->insert_id();
  456.  
  457. # Генерируем имя загружаемого файла
  458. $file_name = $file_id . '_' . preg_replace('/[^a-zA-Z0-9_\.]+/', '', $_FILES['attach']['name']);
  459.  
  460. # Создаем папку для файла если необходимо
  461. $directory = ROOT . 'files/forum/' . main::get_dir($file_id);
  462. if (!file_exists($directory)) {
  463. mkdir($directory);
  464. chmod($directory, 0777);
  465. }
  466.  
  467. # Перемещаем новый файл
  468. move_uploaded_file($_FILES['attach']['tmp_name'], $directory . '/' . $file_name);
  469. chmod($directory . '/' . $file_name, 0777);
  470.  
  471. # Получаем размер файла
  472. $file_size = filesize($directory . '/' . $file_name);
  473.  
  474. # Обновляем данные о файле
  475. $this->db->query("UPDATE #__forum_files SET
  476. message_id = '$message_id',
  477. file_name = '" . a_safe($file_name) . "',
  478. file_size = '$file_size'
  479. WHERE file_id = $file_id
  480. ");
  481. }
  482.  
  483. header('Location: ' . $location);
  484. exit;
  485. }
  486. }
  487. if (!isset($_POST['submit']) || $this->error) {
  488. $_SESSION['captcha_code'] = main::get_unique_code(4);
  489.  
  490. $this->tpl->assign(array(
  491. 'error' => $this->error,
  492. 'title' => $title,
  493. 'message' => $message,
  494. 'topic' => $topic,
  495. 'forum' => $forum,
  496. 'action' => $action,
  497. 'message_text' => $message_text
  498. ));
  499.  
  500. $this->tpl->display('posting');
  501. }
  502. }
  503.  
  504. /**
  505. * Листинг новых сообщений
  506. */
  507. public function action_new_messages() {
  508. $this->per_page = $this->config['forum']['messages_per_page'];
  509.  
  510. $sql = "SELECT SQL_CALC_FOUND_ROWS m.*, t.name AS topic_name, u.username, u.last_visit, up.avatar AS avatar_exists,
  511. (SELECT COUNT(*) FROM #__forum_messages AS fm WHERE fm.topic_id = m.topic_id) AS all_messages
  512. FROM #__forum_messages AS m LEFT JOIN #__forum_topics AS t USING(topic_id) LEFT JOIN #__users AS u ON u.user_id = m.user_id LEFT JOIN #__users_profiles AS up ON up.user_id = u.user_id
  513. ORDER BY m.time DESC
  514. LIMIT $this->start, $this->per_page
  515. ";
  516.  
  517. $result = $this->db->query($sql);
  518. $total = $this->db->get_one("SELECT FOUND_ROWS()");
  519.  
  520. $messages = array();
  521. if (!class_exists('smiles'))
  522. a_import('modules/smiles/helpers/smiles');
  523. while ($message = $this->db->fetch_array($result)) {
  524. $message['message'] = main::bbcode($message['message']);
  525. $message['message'] = smiles::smiles_replace($message['message']);
  526. $message['message'] = nl2br($message['message']);
  527. $messages[] = $message;
  528. }
  529.  
  530. # Пагинация
  531. $pg_conf['base_url'] = a_url('forum/new_messages', 'start=');
  532. $pg_conf['total_rows'] = $total;
  533. $pg_conf['per_page'] = $this->per_page;
  534.  
  535. a_import('libraries/pagination');
  536. $pg = new CI_Pagination($pg_conf);
  537.  
  538. $this->tpl->assign(array(
  539. 'messages' => $messages,
  540. 'total' => $total,
  541. 'pagination' => $pg->create_links(),
  542. 'messages_per_page' => $this->per_page
  543. ));
  544.  
  545. $this->tpl->display('new_messages');
  546. }
  547.  
  548. /**
  549. * Скачивание прикрепленного файла
  550. */
  551. public function action_download_attach() {
  552. if (!$file = $this->db->get_row("SELECT * FROM #__forum_files WHERE file_id = '" . intval($_GET['file_id']) . "'"))
  553. a_error('Файл не найден!');
  554.  
  555. # Обновляем счетчик скачиваний
  556. $this->db->query("UPDATE #__forum_files SET file_downloads = file_downloads + 1 WHERE file_id = '" . $file['file_id'] . "'");
  557.  
  558. # Перенаправляем на файл
  559. header('Location: ' . URL . 'files/forum/' . main::get_dir($file['file_id']) . '/' . $file['file_name']);
  560. }
  561.  
  562. }
  563.  
  564. ?>