Просмотр файла download/index.php

Размер файла: 9.97Kb
  1. <?php
  2. /**
  3. *@author Flyself
  4. */
  5. include '../engine/includes/start.php';
  6. if (!$user_id)
  7. Core::stop();
  8. $do = isset($_GET['do'])? $_GET['do'] : false;
  9. $error = false;
  10. $dir_load = 'download';
  11. $filesroot = '../' . $dir_load;
  12. $screenroot = $filesroot . '/screen';
  13. $loadroot = $filesroot . '/files';
  14. $set_down = array('mod' => 1, 'theme_screen' => 1, 'top' => 25);
  15. $old = $time - 259200;
  16. $array = array('add_cat', 'down_file', 'view', 'open_zip', 'jad_file', 'txt_in_jar', 'txt_in_zip', 'edit_about', 'edit_screen', 'file_more', 'load_file', 'del_file', 'comms', 'new_files', 'top_files', 'comms_all', 'recount', 'edit_cat', 'del_cat', 'scan_dir', 'mod_files', 'search');
  17. Core::get(array('text.class', 'page.class', 'cache.class'), 'classes');
  18.  
  19. function format($file)
  20. {
  21. return pathinfo($file, PATHINFO_EXTENSION);
  22. }
  23. function display_error($msg)
  24. {
  25. return '<div class="err">'.$msg.'</div>';
  26. }
  27. function check($str)
  28. {
  29. return my_esc($str, true);
  30. }
  31. function show_file($res_down = array())
  32. {
  33. global $filesroot;
  34. $out = '';
  35. $f1 = strrpos($res_down['name'], ".");
  36. $f2 = substr($res_down['name'], $f1 + 1, 999);
  37. $format_file = strtolower($f2);
  38. if ($format_file == 'jpg' || $format_file == 'jpeg' || $format_file == 'gif' || $format_file == 'png') {
  39. $preview = $res_down['dir'] . '/' . $res_down['name'];
  40. }
  41. /* else
  42. if ($format_file == 'thm' || $format_file == 'nth') {
  43. if (is_file('screen/' . $res_down['id'] . '.gif')) {
  44. $preview = 'screen/' . $res_down['id'] . '.gif';
  45. }
  46. else {
  47. $preview = 'images/easy.gif';
  48. }
  49. }*/
  50. if (isset($preview)) {
  51. //$out = '<img src="preview.php?type=1&amp;img=' . urlencode($preview) . '" alt="preview" />';
  52. $out = '<img src="'.htmlspecialchars($preview) . '" width="10%" alt="preview" />';
  53. }
  54. $out .= '<img src="' . $filesroot . '/images/' . (file_exists($filesroot . '/images/' . $format_file . '.png') ? $format_file . '.png' : 'file.gif') . '" alt="file" /> ';
  55. $out .= '<a href="?act=view&amp;id=' . $res_down['id'] . '">' . text::output($res_down['rus_name']) . '</a> (' . $res_down['field'] . ')';
  56. if (is_file('about/' . $res_down['id'] . '.txt')) {
  57. $about = file_get_contents('about/' . $res_down['id'] . '.txt');
  58. if (mb_strlen($about) > 100)
  59. $about = iconv('UTF-8', 'UTF-8//IGNORE', mb_substr($about, 0, 90, 'utf-8')) . '...';
  60. $out .= '<br />'.text::output($about);
  61. }
  62. $out .= '<div class="status"><a href="index.php?act=comms&amp;id=' . $res_down['id'] . '">Комментарии</a> (' . $res_down['total'] . ')</div>';
  63. return $out;
  64. }
  65.  
  66. if (in_array($act, $array) && file_exists('include/' . $act . '.php')) {
  67. require_once (H.'download/include/' . $act . '.php');
  68. }
  69. else {
  70. $tree = array();
  71. $sql->query("SELECT * FROM `down_files` WHERE `type` = 1 AND `id` = '$id' LIMIT 1");
  72. $cat = $sql->num_rows();
  73. $res_down_cat = $sql->fetch();
  74. $way = null;
  75. $dirid = $id;
  76. while ($dirid != '0' && $dirid != "") {
  77. $res_down = $sql->query("SELECT * FROM `down_files` WHERE `type` = 1 AND `id` = '$dirid' LIMIT 1")->fetch();
  78. $tree[] = '<a href="index.php?id=' . $dirid . '">' . text::output($res_down['rus_name']) . '</a>';
  79. $dirid = $res_down['refid'];
  80. }
  81. krsort($tree);
  82. //$way = implode(',', $tree);
  83. //$set['meta_keywords'] = $res_down_cat['rus_name'];
  84. //$set['meta_description']= strip_tags($way);
  85. $set['title'] = 'Загрузки' . ($id ? ' / ' . $res_down_cat['rus_name'] : null);
  86. include H.'engine/includes/head.php';
  87. $cache = new cache(H.'engine/files/tmp/download[dir='.$id.';page='.(isset($_GET['page']) ? intval($_GET['page']) : 1).'].swc');
  88. if (!$cache->life())
  89. {
  90. ob_start();
  91.  
  92. if ($id) {
  93. if ($cat == 0 || !is_dir($res_down_cat['dir'] . '/' . $res_down_cat['name'])) {
  94. // Если неправильно выбран каталог, выводим ошибку
  95. echo 'Каталог не существует<br /><a href="index.php">К категориям</a>';
  96. include H.'engine/includes/foot.php';
  97. }
  98. $title_pages = mb_substr($res_down_cat['rus_name'], 0, 30);
  99. $textl = mb_strlen($res_down_cat['rus_name']) > 30 ? $title_pages . '...' : $title_pages;
  100.  
  101. $cdir = array_pop($tree);
  102. echo '<div class="p_m"><a href="index.php?">Загрузки</a> &raquo; ';
  103. echo implode(',', $tree);
  104. echo '<b>' . strip_tags($cdir) . '</b></div>';
  105. $total_new = $sql->query("SELECT COUNT(*) FROM `down_files` WHERE `type` = '2' AND `time` > $old AND `dir` LIKE '" . ($res_down_cat['dir'] . '/' . $res_down_cat['name']) . "%'")->result();
  106. if($total_new)
  107. echo '<div class="menu_razd"><a href="index.php?act=new_files&amp;id=' . $id . '">Новые файлы</a> (' . $total_new . ')</div>';
  108. }
  109. else {
  110. echo '<div class="fmenu">Загрузки</div>';
  111. $total_mod = $sql->query("SELECT COUNT(*) FROM `down_files` WHERE `type` = '3'")->result();
  112. if($total_mod)
  113. echo '<div class="err"><a href="index.php?act=mod_files">Файлы на модерации</a> (' . $total_mod . ')</div>';
  114. $total_new = $sql->query("SELECT COUNT(*) FROM `down_files` WHERE `type` = '2' AND `time` > $old")->result();
  115. if($total_new)
  116. echo '<div class="p_t"><a href="index.php?act=new_files">Новые файлы</a> (' . $total_new . ')</div>';
  117. echo '
  118. <div class="menu_razd"><a href="index.php?act=top_files&amp;id=0">Популярные</a> | ',
  119. '<a href="index.php?act=top_files&amp;id=1">Самые комментируемые</a> | ',
  120. '<a href="index.php?act=comms_all">Обзор комментариев</a></div>';
  121. }
  122. // Подсчитываем число папок и файлов
  123. $total_cat = $sql->query("SELECT COUNT(*) FROM `down_files` WHERE `refid` = '$id' AND `type` = 1")->result();
  124. $total_files = $sql->query("SELECT COUNT(*) FROM `down_files` WHERE `refid` = '$id' AND `type` = 2")->result();
  125. $sum_total = $total_files + $total_cat;
  126. $page = new page($sum_total, $set['p_str']);
  127.  
  128. if ($sum_total) {
  129. // Сортировка
  130. $_SESSION['sort_down'] = $_SESSION['sort_down2'] = 0;
  131. if (isset($_POST['sort_down']))
  132. $_SESSION['sort_down'] = $_POST['sort_down'] ? 1 : 0;
  133. if (isset($_POST['sort_down2']))
  134. $_SESSION['sort_down2'] = $_POST['sort_down2'] ? 1 : 0;
  135. $sql_sort = $_SESSION['sort_down'] ? '`name`' : '`time`';
  136. $sql_sort .= $_SESSION['sort_down2'] ? ' ASC' : ' DESC';
  137. $sql->query("SELECT * FROM `down_files` WHERE `refid` = '$id' AND `type` < 3 ORDER BY `type` ASC, $sql_sort LIMIT ".$page->limit());
  138. $i = 1;
  139. //Выводим список папок и файлов
  140. while ($res_down = $sql->fetch()) {
  141. echo $i % 2 ? '<div class="p_t">' : '<div class="p_m">';
  142. //$preview = '';
  143. if ($res_down['type'] == 1) {
  144. echo '<img src="' . $filesroot . '/images/cat.gif" alt="cat" /> <a href="index.php?id=' . $res_down['id'] . '">' . text::output($res_down['rus_name']) . '</a> (' . $res_down['total'] . ')';
  145. if ($res_down['field'])
  146. echo '<div class="status">Расширения для выгрузки: ' . $res_down['text'] . '</div>';
  147. }
  148. else
  149. echo show_file($res_down);
  150. echo '</div>';
  151. ++$i;
  152. }
  153. }
  154. //else
  155. // echo '<div class="err">В данной категории нет файлов</div>';
  156. if ($id)
  157. {
  158. echo '<div class="sub">Загрузки / ';
  159. if ($total_cat > 0)
  160. echo 'Папок: ' . $total_cat;
  161. echo '&nbsp;&nbsp;';
  162. if ($total_files > 0)
  163. echo 'Файлов: ' . $total_files;
  164. echo '</div>';
  165. }
  166. // Постраничная навигация
  167. $page->display('index.php?id=' . $id . '&amp;');
  168. $cache->write();
  169. }
  170. echo $cache->read();
  171.  
  172. if ($moder) {
  173. // Выводим ссылки на модерские функции
  174. echo '<div class="menu">';
  175. echo '<a href="index.php?act=recount&amp;cat&amp;id=' . $id . '">Пересчитать файлы в папке</a><br /><a href="index.php?act=recount">Пересчитать файлы в ЗЦ</a><br /><a href="index.php?act=add_cat&amp;id=' . $id . '">Создать папку</a><br/>';
  176. if ($id) {
  177. $del_cat = $sql->query("SELECT COUNT(*) FROM `down_files` WHERE `type` = 1 AND`refid` = '$id'")->result();
  178. if (!$del_cat) {
  179. echo '<a href="index.php?act=del_cat&amp;id=' . $id . '">Удалить папку</a><br/>';
  180. }
  181. echo '<a href="index.php?act=edit_cat&amp;id=' . $id . '">Изменить папку</a><br/>';
  182. //echo "<a href='?act=import&amp;cat=" . $cat . "'>Импорт файла</a><br/>";
  183. echo '<a href="index.php?act=down_file&amp;id=' . $id . '">Выгрузить файл</a><br />';
  184. }
  185. echo '<a href="index.php?act=scan_dir&amp;id=' . $id . '">Обновить</a> ' . ($id ? '| <a href="index.php?act=scan_dir">ЗЦ</a>' : '') . ' <br/><a href="index.php?act=scan_dir&amp;do=clean&amp;id=' . $id . '">Очистка БД от мусора</a>';
  186. echo'</div>';
  187.  
  188. }
  189. else
  190. if ($id)
  191. echo '<div class="menu"><a href="index.php?act=down_file&amp;id=' . $id . '">Выгрузить файл</a></div>';
  192. echo '<div class="post"><a href="index.php?act=search">Поиск</a>';
  193. if (!empty($cat))
  194. echo '<br /><a href="index.php">В загрузки</a>';
  195. echo '</div>';
  196. }
  197.  
  198. include H.'engine/includes/foot.php';