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

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