Файл: modules/obmen/index.php
Строк: 201
<?php
/* Мод "Обменник"
 * Версия v0.0.1
 * Дата последнего редактирования 24.11.2014
 * Двиг DCMS Special
 * Модифицировал densnet
 * Файл index.php
 * Описание: Выводит список папок и файлов
 */
require_once '../../sys/inc/start.php';
if (isset($_GET['showinfo']) || !isset($_GET['f']) || isset($_GET['komm'])) {
    require_once H . 'sys/inc/compress.php';
}
require_once H . 'sys/inc/sess.php';
require_once H . 'sys/inc/settings.php';
require_once H . 'sys/inc/db_connect.php';
require_once H . 'sys/inc/ipua.php';
require_once H . 'sys/inc/fnc.php';
require_once H . 'sys/inc/obmen.php';
require_once H . 'sys/inc/user.php';
define('DIR_OBMEN', '/modules/obmen/');
if (isset($_GET['d']) && text::esc($_GET['d']) != NULL) {
    $l = preg_replace("#.{2,}#", NULL, text::esc(urldecode($_GET['d'])));
    $l = preg_replace("#./|/.#", NULL, $l);
    $l = preg_replace("#(/){1,}#", "/", $l);
    $l = '/' . preg_replace("#(^(/){1,})|((/){1,}$)#", "", $l);
} else {
    $l = '/';
}
if ($l == '/') {
    $dir_id['upload'] = 0;
    $id_dir = 0;
    $l = '/';
} elseif (mysql_result(mysql_query("SELECT COUNT(*) FROM `obmennik_dir` WHERE `dir` = '/$l' OR `dir` = '$l/' OR `dir` = '$l' LIMIT 1"), 0) != 0) {
    $dir_id = mysql_fetch_assoc(mysql_query("SELECT * FROM `obmennik_dir` WHERE `dir` = '/$l' OR `dir` = '$l/' OR `dir` = '$l' LIMIT 1"));
    $id_dir = $dir_id['id'];
} else {
    $dir_id['upload'] = 0;
    $id_dir = 0;
    $l = '/';
}
if (isset($_GET['f'])) {
    $f = text::esc(urldecode($_GET['f']));
    $name = preg_replace('#.[^.]*$#', NULL, $f); // имя файла без расширения
    $ras = strtolower(preg_replace('#^.*.#', NULL, $f));
    $ras = str_replace('jad', 'jar', $ras);
    if (mysql_result(mysql_query("SELECT COUNT(*) FROM `obmennik_files` WHERE `id_dir` = '$id_dir' AND `name`='$name' AND `ras` = '$ras' LIMIT 1"), 0) != 0) {
        $file_id = mysql_fetch_assoc(mysql_query("SELECT * FROM `obmennik_files` WHERE `id_dir` = '$id_dir' AND `name`='$name' AND `ras` = '$ras' LIMIT 1"));
        $ras = $file_id['ras'];
        $file = H . "sys/obmen/files/$file_id[id].dat";
        $name = $file_id['name'];
        $size = $file_id['size'];
        define('SCR_WIDTH', IS_WEB ? $set['loads_screen_size_web'] : $set['loads_screen_size_wap']); // максимальная ширина скриншотов
        define('LF_FILE', $file_id['name'] . '.' . $file_id['ras']); // название файла на сервере
        define('LF_PATH', realpath(H . "sys/obmen/files/$file_id[id].dat")); // полный путь до файла
        define('LF_RAS', $ras); // расширение (в нижнем регистре)
        define('LF_NAME', $name);
        define('LF_ID', $file_id['id']);
        if (!isset($_GET['showinfo']) && !isset($_GET['komm']) && is_file(H . 'sys/obmen/files/' . $file_id['id'] . '.dat')) {
            if ($ras == 'jar' && strtolower(eregi_replace('^.*.', NULL, $f)) == 'jad') {
                $zip = new PclZip(H . 'sys/obmen/files/' . $file_id['id'] . '.dat');
                $content = $zip->extract(PCLZIP_OPT_BY_NAME, "META-INF/MANIFEST.MF", PCLZIP_OPT_EXTRACT_AS_STRING);
                $jad = preg_replace("#(MIDlet-Jar-URL:( )*[^(n|r)]*)#i", NULL, $content[0]['content']);
                $jad = preg_replace("#(MIDlet-Jar-Size:( )*[^(n|r)]*)(n|r)#i", NULL, $jad);
                $jad = trim($jad);
                $jad.="rnMIDlet-Jar-Size: " . filesize(H . 'sys/obmen/files/' . $file_id['id'] . '.dat') . "";
                $jad.="rnMIDlet-Jar-URL: /modules/obmen$dir_id[dir]$file_id[name].$file_id[ras]";
                $jad = br($jad, "rn");
                header('Content-Type: text/vnd.sun.j2me.app-descriptor');
                header('Content-Disposition: attachment; filename="' . $file_id['name'] . '.jad";');
                echo $jad;
                exit;
            }
            @mysql_query("UPDATE `obmennik_files` SET `k_loads` = '" . ($file_id['k_loads'] + 1) . "' WHERE `id` = '$file_id[id]' LIMIT 1");
            require_once H . 'sys/inc/downloadfile.php';
            DownloadFile(H . 'sys/obmen/files/' . $file_id['id'] . '.dat', $name . '.' . $ras, ras_to_mime($ras));
            exit;
        } elseif (isset($_GET['komm']) && is_file(H . 'sys/obmen/files/' . $file_id['id'] . '.dat')) {
            $set['title'] = 'Обменник - Комментарии - ' . $file_id['name']; // заголовок страницы
            $_SESSION['page'] = 1;
            require_once H . 'sys/inc/thead.php';
            title();
            require_once 'inc/komm_act.php'; // действия с комментариями
            require_once 'inc/komm.php';
            echo "<div class = 'razd'>";
            echo img('left.png') . " <a href = '/modules/obmen$dir_id[dir]" . urlencode($file_id['name']) . ".$file_id[ras]?showinfo'>К описанию</a><br />n";
            echo img('left.png') . " <a href='/modules/obmen$dir_id[dir]'>В папку</a><br />n";
            echo "</div>";
            require_once H . 'sys/inc/tfoot.php';
            exit;
        } else {
            $set['title'] = 'Обменник - ' . $file_id['name']; // заголовок страницы
            require_once H . 'sys/inc/thead.php';
            title();
            $ank = user::get_user($file_id['id_user']);
            include 'inc/file_act.php';
            err();
            aut(); // форма авторизации
            if (is_file("inc/file/$ras.php")) {
                include "inc/file/$ras.php";
            } else {
                require_once 'inc/file.php';
            }
            if ($file_id['blok'] != NULL) {
                echo "<div class = 'razd'>";
                echo "<font color = 'red'><b> Файл заблокирован </b></font><br />";
                if ($file_id['blok'] != NULL) {
                    echo "<div class = 'errs'><b>Причина</b><br />";
                    echo text::toOutput($file_id['blok']) . "</div>n";
                }
                if (user::access('obmen_file_delete')) {
                    if ($file_id['blok'] != NULL) {
                        echo "<br /><a class = 'count' href='?showinfo&act=blokk&ok'>" . img('bl.png') . " Разблокировать файл</a><br />n";
                    } else {
                        echo "<br /><a class = 'count' href='?showinfo&act=blokk'>" . img('bl.png') . " Заблокировать файл</a><br />n";
                    }
                }
                echo "</div>";
            } elseif ($file_id['parol'] != NULL && @$_POST['paroll'] != $file_id['parol'] && !user::access('obmen_file_delete') && $user['id'] != $file_id['id_user']) {
                echo "<div class = 'razd'>";
                echo "<font color = 'red'><b>Файл защищен паролем </b></font>";
                if ($file_id['parol'] != NULL && @$_POST['paroll'] != $file_id['parol'] && !user::access('obmen_file_delete') && $user['id'] != $file_id['id_user']) {
                    if (isset($_POST['paroll']) && @$_POST['paroll'] != $file_id['parol']) {
                        echo "<div class = 'errs'>Пароль не верный </div>";
                    }
                    echo "<form method = 'post' action = '?showinfo'>n";
                    echo "<b>Пароль</b><br />";
                    echo "<input type = 'text' name = 'paroll' value = '' maxlength = '512' /><br />";
                    echo "<button name = 'save' class = 'clik'>Войти</button>";
                    echo "</form>";
                }
                if (isset($user) && $user['id'] == $file_id['id_user'] || user::access('obmen_file_delete')) {
                    echo "<div class = 'razd'>";
                    echo "<a class = 'count' href = '?showinfo&act=edit'>" . img('set_mini.png') . " Параметры</a> ";
                    echo "<a class = 'count' href = '?showinfo&act=delete'>" . img('del.png') . " Удалить файл</a><br />";
                    if ($file_id['parol'] != NULL && $file_id['blok'] == NULL) {
                        echo "<br /><a class = 'count' href = '?showinfo&act=parol'>" . img('lock-small.png') . " Изменить пароль</a> ";
                        echo "<a class = 'count' href = '?showinfo&act=paroll&ok'>" . img('lock-small.png') . " Убрать пароль</a><br />n";
                    } else if ($file_id['blok'] == NULL) {
                        echo "<br /><a class = 'count' href = '?showinfo&act=parol'>" . img('lock-small.png') . " Поставить пароль</a><br />n";
                    }
                    echo "</div>n";
                }
                echo "</div>";
            } else {
                //echo "<input type = 'text' value='http://$_SERVER[SERVER_NAME]/obmen$dir_id[dir]" . urlencode($file_id['name']) . ".$file_id[ras]' /><br />n";
                echo "<div class = 'razd'>";
                if ($file_id['k_loads'] == 0 || $file_id['k_loads'] == 1 || $file_id['k_loads'] >= 5 && $file_id['k_loads'] <= 21 || $file_id['k_loads'] >= 25 && $file_id['k_loads'] <= 1111111111) {
                    $kol = "раз";
                } elseif ($file_id['k_loads'] >= 2 && $file_id['k_loads'] <= 4 || $file_id['k_loads'] >= 22 && $file_id['k_loads'] <= 24) {
                    $kol = "раза";
                }
                if ($file_id['ras'] == 'jar') {
                    echo "<a class = 'count' href='/modules/obmen$dir_id[dir]" . urlencode($file_id['name']) . ".jad'>" . img('.png') . " Скачать</a> <a href='/obmen$dir_id[dir]" . urlencode($file_id['name']) . ".$file_id[ras]'>JAR</a>  ";
                } else {
                    echo "<a class = 'count' href='/modules/obmen$dir_id[dir]" . urlencode($file_id['name']) . ".$file_id[ras]'>" . img('down.png') . " Скачать</a> ";
                }
                echo "<a class = 'count'><font color = 'blue'>Скачано <b>$file_id[k_loads]</b> $kol</font></a>";
                echo "</div>";
                include 'inc/file_form.php';
                echo "<a href='/modules/obmen$dir_id[dir]'><div class = 'razd'>" . img('left.png') . " В папку</div></a>";
            }
            require_once H . 'sys/inc/tfoot.php';
        }
    }
}
require_once 'inc/dir.php';
require_once H . 'sys/inc/tfoot.php';