PageRenderTime 27ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/Quản lý website đọc truyện online PHP/forum/includes/files.php

https://gitlab.com/phamngsinh/baitaplon_sinhvien
PHP | 181 lines | 147 code | 4 blank | 30 comment | 25 complexity | e811aa48592b0cbe58de212e1bb67e8f MD5 | raw file
  1. <?php
  2. /**
  3. * @package JohnCMS
  4. * @link http://johncms.com
  5. * @copyright Copyright (C) 2008-2011 JohnCMS Community
  6. * @license LICENSE.txt (see attached file)
  7. * @version VERSION.txt (see attached file)
  8. * @author http://johncms.com/about
  9. */
  10. defined('_IN_JOHNCMS') or die('Error: restricted access');
  11. $headmod = 'forumfiles';
  12. require('../incfiles/head.php');
  13. $types = array(
  14. 1 => $lng_forum['files_type_win'],
  15. 2 => $lng_forum['files_type_java'],
  16. 3 => $lng_forum['files_type_sis'],
  17. 4 => $lng_forum['files_type_txt'],
  18. 5 => $lng_forum['files_type_pic'],
  19. 6 => $lng_forum['files_type_arc'],
  20. 7 => $lng_forum['files_type_video'],
  21. 8 => $lng_forum['files_type_audio'],
  22. 9 => $lng_forum['files_type_other']
  23. );
  24. $new = time() - 86400; // Сколько времени файлы считать новыми?
  25. /*
  26. -----------------------------------------------------------------
  27. Получаем ID раздела и подготавливаем запрос
  28. -----------------------------------------------------------------
  29. */
  30. $c = abs(intval($_GET['c'])); // ID раздела
  31. $s = abs(intval($_GET['s'])); // ID подраздела
  32. $t = abs(intval($_GET['t'])); // ID топика
  33. $do = isset($_GET['do']) && intval($_GET['do']) > 0 && intval($_GET['do']) < 10 ? intval($_GET['do']) : 0;
  34. if ($c) {
  35. $id = $c;
  36. $lnk = '&amp;c=' . $c;
  37. $sql = " AND `cat` = '" . $c . "'";
  38. $caption = '<b>' . $lng_forum['files_category'] . '</b>: ';
  39. $input = '<input type="hidden" name="c" value="' . $c . '"/>';
  40. } elseif ($s) {
  41. $id = $s;
  42. $lnk = '&amp;s=' . $s;
  43. $sql = " AND `subcat` = '" . $s . "'";
  44. $caption = '<b>' . $lng_forum['files_section'] . '</b>: ';
  45. $input = '<input type="hidden" name="s" value="' . $s . '"/>';
  46. } elseif ($t) {
  47. $id = $t;
  48. $lnk = '&amp;t=' . $t;
  49. $sql = " AND `topic` = '" . $t . "'";
  50. $caption = '<b>' . $lng_forum['files_topic'] . '</b>: ';
  51. $input = '<input type="hidden" name="t" value="' . $t . '"/>';
  52. } else {
  53. $id = false;
  54. $sql = '';
  55. $lnk = '';
  56. $caption = '<b>' . $lng_forum['files_forum'] . '</b>';
  57. $input = '';
  58. }
  59. if ($c || $s || $t) {
  60. // Получаем имя нужной категории форума
  61. $req = mysql_query("SELECT `text` FROM `forum` WHERE `website` = '$website' AND `id` = '$id'");
  62. if (mysql_num_rows($req) > 0) {
  63. $res = mysql_fetch_assoc($req);
  64. $caption .= $res['text'];
  65. } else {
  66. echo functions::display_error($lng['error_wrong_data'], '<a href="index.php">' . $lng['to_forum'] . '</a>');
  67. require('../incfiles/end.php');
  68. exit;
  69. }
  70. }
  71. if ($do || isset($_GET['new'])) {
  72. /*
  73. -----------------------------------------------------------------
  74. Выводим список файлов нужного раздела
  75. -----------------------------------------------------------------
  76. */
  77. $total = mysql_result(mysql_query("SELECT COUNT(*) FROM `cms_forum_files` WHERE `website` = '$website' AND " . (isset($_GET['new'])
  78. ? " `time` > '$new'" : " `filetype` = '$do'") . $sql), 0);
  79. if ($total > 0) {
  80. // Заголовок раздела
  81. echo '<div class="phdr">' . $caption . (isset($_GET['new']) ? '<br />' . $lng['new_files']
  82. : '') . '</div>' . ($do ? '<div class="bmenu">' . $types[$do] . '</div>' : '');
  83. $req = mysql_query("SELECT `cms_forum_files`.*, `forum`.`user_id`, `forum`.`text`, `topicname`.`text` AS `topicname`
  84. FROM `cms_forum_files`
  85. LEFT JOIN `forum` ON `cms_forum_files`.`post` = `forum`.`id`
  86. LEFT JOIN `forum` AS `topicname` ON `cms_forum_files`.`topic` = `topicname`.`id`
  87. WHERE `forum`.`website` = '$website' AND " . (isset($_GET['new']) ? " `cms_forum_files`.`time` > '$new'" : " `filetype` = '$do'") . ($rights >= 7
  88. ? '' : " AND `del` != '1'") . $sql .
  89. "ORDER BY `time` DESC LIMIT $start,$kmess");
  90. while ($res = mysql_fetch_assoc($req)) {
  91. $req_u = mysql_query("SELECT `id`, `name`, `sex`, `rights`, `lastdate`, `status`, `datereg`, `ip`, `browser` FROM `users` WHERE `website` = '$website' AND `id` = '" . $res['user_id'] . "'");
  92. $res_u = mysql_fetch_assoc($req_u);
  93. echo $i % 2 ? '<div class="list2">' : '<div class="list1">';
  94. // Выводим текст поста
  95. $text = mb_substr($res['text'], 0, 500);
  96. $text = functions::checkout($text, 1, 0);
  97. $text = preg_replace('#\[c\](.*?)\[/c\]#si', '', $text);
  98. $page = ceil(mysql_result(mysql_query("SELECT COUNT(*) FROM `forum` WHERE `website` = '$website' AND `refid` = '" . $res['topic'] . "' AND `id` " . ($set_forum['upfp']
  99. ? ">=" : "<=") . " '" . $res['post'] . "'"), 0) / $kmess);
  100. $text = '<b><a href="index.php?id=' . $res['topic'] . '&amp;page=' . $page . '">' . $res['topicname'] . '</a></b><br />' . $text;
  101. if (mb_strlen($res['text']) > 500)
  102. $text .= '<br /><a href="index.php?act=post&amp;id=' . $res['post'] . '">' . $lng_forum['read_all'] . ' &gt;&gt;</a>';
  103. // Формируем ссылку на файл
  104. $fls = @filesize('../files/forum/attach/' . $res['filename']);
  105. $fls = round($fls / 1024, 0);
  106. $att_ext = strtolower(functions::format('./files/forum/attach/' . $res['filename']));
  107. $pic_ext = array(
  108. 'gif',
  109. 'jpg',
  110. 'jpeg',
  111. 'png'
  112. );
  113. if (in_array($att_ext, $pic_ext)) {
  114. // Если картинка, то выводим предпросмотр
  115. $file = '<div><a href="index.php?act=file&amp;id=' . $res['id'] . '">';
  116. $file .= '<img src="thumbinal.php?file=' . (urlencode($res['filename'])) . '" alt="' . $lng_forum['click_to_view'] . '" /></a></div>';
  117. } else {
  118. // Если обычный файл, выводим значок и ссылку
  119. $file = ($res['del'] ? '<img src="http://img.infoviet.net/images/del.png" width="16" height="16" />'
  120. : '') . '<img src="http://img.infoviet.net/images/system/' . $res['filetype'] . '.png" width="16" height="16" />&#160;';
  121. }
  122. $file .= '<a href="index.php?act=file&amp;id=' . $res['id'] . '">' . htmlspecialchars($res['filename']) . '</a><br />';
  123. $file .= '<small><span class="gray">' . $lng_forum['size'] . ': ' . $fls . ' kb.<br />' . $lng_forum['downloaded'] . ': ' . $res['dlcount'] . ' ' . $lng_forum['time'] . '</span></small>';
  124. $arg = array(
  125. 'iphide' => 1,
  126. 'sub' => $file,
  127. 'body' => $text
  128. );
  129. echo functions::display_user($res_u, $arg);
  130. echo '</div>';
  131. ++$i;
  132. }
  133. echo '<div class="phdr">' . $lng['total'] . ': ' . $total . '</div>';
  134. if ($total > $kmess) {
  135. // Постраничная навигация
  136. echo '<p>' . functions::display_pagination('index.php?act=files&amp;' . (isset($_GET['new']) ? 'new'
  137. : 'do=' . $do) . $lnk . '&amp;', $start, $total, $kmess) . '</p>' .
  138. '<p><form action="index.php" method="get">' .
  139. '<input type="hidden" name="act" value="files"/>' .
  140. '<input type="hidden" name="do" value="' . $do . '"/>' . $input . '<input type="text" name="page" size="2"/>' .
  141. '<input type="submit" value="' . $lng['to_page'] . ' &gt;&gt;"/></form></p>';
  142. }
  143. } else {
  144. echo '<div class="list1">' . $lng['list_empty'] . '</div>';
  145. }
  146. } else {
  147. /*
  148. -----------------------------------------------------------------
  149. Выводим список разделов, в которых есть файлы
  150. -----------------------------------------------------------------
  151. */
  152. $countnew = mysql_result(mysql_query("SELECT COUNT(*) FROM `cms_forum_files` WHERE `website` = '$website' AND `time` > '$new'" . ($rights >= 7
  153. ? '' : " AND `del` != '1'") . $sql), 0);
  154. echo '<p>' . ($countnew > 0
  155. ? '<a href="index.php?act=files&amp;new' . $lnk . '">' . $lng['new_files'] . ' (' . $countnew . ')</a>'
  156. : $lng_forum['new_files_empty']) . '</p>';
  157. echo '<div class="phdr">' . $caption . '</div>';
  158. $link = array();
  159. $total = 0;
  160. for ($i = 1; $i < 10; $i++) {
  161. $count = mysql_result(mysql_query("SELECT COUNT(*) FROM `cms_forum_files` WHERE `website` = '$website' AND `filetype` = '$i'" . ($rights >= 7
  162. ? '' : " AND `del` != '1'") . $sql), 0);
  163. if ($count > 0) {
  164. $link[] = '<img src="http://img.infoviet.net/images/system/' . $i . '.png" width="16" height="16" class="left" />&#160;<a href="index.php?act=files&amp;do=' . $i . $lnk . '">' . $types[$i] . '</a>&#160;(' . $count . ')';
  165. $total = $total + $count;
  166. }
  167. }
  168. foreach ($link as $var) {
  169. echo ($i % 2 ? '<div class="list2">' : '<div class="list1">') . $var . '</div>';
  170. ++$i;
  171. }
  172. echo '<div class="phdr">' . $lng['total'] . ': ' . $total . '</div>';
  173. }
  174. echo '<p>' . (($do || isset($_GET['new']))
  175. ? '<a href="index.php?act=files' . $lnk . '">' . $lng_forum['section_list'] . '</a><br />'
  176. : '') . '<a href="index.php' . ($id ? '?id=' . $id : '') . '">' . $lng['forum'] . '</a></p>';
  177. ?>