<?php
/*
Скрипт загруз центра для JohnCMS
Автор: Максим (simba)
ICQ: 61590077
Сайт: http://symbos.su
R866920725287
Z117468354234
*/

define('_IN_JOHNCMS', 1);
$headmod = 'loadview';
require_once '../incfiles/core.php';
require_once 'functions.php';
$viewf = intval($_GET['view']);
$file = mysql_query("SELECT * FROM `downfiles` WHERE `id` = '" . $viewf . "'");
if (mysql_num_rows($file)) {
    $file = mysql_fetch_array($file);
    $dopway = str_replace(basename($file['way']), '', $file['way']);
    $file22 = mysql_query("SELECT * FROM `downfiles` WHERE `pathid` = '" . $viewf .
        "' AND `type` = 1");
    $namee = explode('||||', $file['name']);
    $textl = '' . str_replace('_', ' ', $namee[0]) . 'ni bepul yuklash!';
    require_once '../incfiles/head.php';
    if (!$file['size']) {
        $siz = filesize($loadroot.'/'.$file[way]);
        mysql_query("UPDATE `downfiles` set `size` = '" . $siz . "' WHERE `id` = '" . $viewf .
            "'");
    } else {
        $siz = $file['size'];
    }
    $filtime = date("d.m.Y", $file['time']);

    $nadir = $file[pathid];
    $pat = "";
    while ($nadir != "") {

        $dnew = mysql_query("select * from `downpath` where id = '" . $nadir . "';");
        $dnew1 = mysql_fetch_array($dnew);
        $pat = '<a href="dir_' . $dnew1['id'] . '.html" title="' . $dnew1['name'] . '">' .
            $dnew1['name'] . '</a> &gt;  ' . $pat;

        $nadir = $dnew1[refid];
    }

    $tf = pathinfo($file['way'], PATHINFO_EXTENSION);
    echo '<div class="phdr"><a href="index.html">Yuklamalar</a> ' . $pat .
        '<strong>' . str_replace('_', ' ', $namee[0]) . '</strong> [' . size_convert($siz) .
        ']</div>';
    $gol = explode('|', $file['gol']);
    echo '<div class="menu">Reyting: ' . $rating = $file['rating'] ? $file['rating'] : '0';
    echo '&nbsp;Baholar: ' . $gol1 = $file['rating'] ? count($gol) : '0';
    echo '<br/>';
    echo rat_star($file['rating']) . '</div>';


    $idd = explode('|', $file['gol']);

    if ($user_id && !in_array("$user_id", $idd)) {
        echo '<div class="menu">Оценить: <a href="index.php?act=rat&amp;id=' . $file['id'] .
            '&amp;rat=1">1</a> | <a href="index.php?act=rat&amp;id=' . $file['id'] .
            '&amp;rat=2">2</a> |<a href="index.php?act=rat&amp;id=' . $file['id'] .
            '&amp;rat=3">3</a> | <a href="index.php?act=rat&amp;id=' . $file['id'] .
            '&amp;rat=4">4</a> | <a href="index.php?act=rat&amp;id=' . $file['id'] .
            '&amp;rat=5">5</a></div>';
    }
    
    echo '<div class="menu"><b>Тип файла:</b> ' . $tf . '</div>';

    //////////////////////////
    ////// Скриншоты /////////
    //////////////////////////
    $scr = mysql_result(mysql_query("SELECT COUNT(*) FROM `downscreen` WHERE `fileid` = '" .
        $viewf . "'"), 0);
    if ($scr) {
        echo '<div class="menu">';
        $screen = mysql_query("SELECT * FROM `downscreen` WHERE `fileid` = '" . $viewf .
            "'");
        $i = 1;
        while ($screen1 = mysql_fetch_array($screen)) {
            if ($i == 1) {
                if ($down_setting['screenshot'])
                    echo '<img src="graftemp/' . $screen1[way] . '" alt="Скриншот..."/><br/>';
                echo 'Скриншот: ';
            }

            if (!is_file('graftemp/' . $screen1[way])) {
                $img = new ImageEdit($screenroot . '/' . $screen1['way'], $down_setting['scr_size']);
                $img->setQuality(90);
                if($down_setting['scr_copy'])
                $img->setCopy($down_setting['scr_copy_size'], $down_setting['scr_copy_text']);
                $img->saveImage('graftemp/' . $screen1[way]);
            }
            echo '<a href="getthumb.php?file=screens/' . $screen1[way] .
                '&amp;size=0&amp;q=100&amp;copy=' . $down_setting['scr_copy_text'] . '">' . $i .
                '</a> ';
            $i++;
        }
        echo '<br/>';
        echo '</div>';
    }

    /////////////////////////
    ///// Скрин к темам /////
    /////////////////////////
    echo '<div class="menu">';
    if ($down_setting['screenview']) {
        if ($tf == 'thm') {
            if (!is_file($loadroot . '/' . $file['way'] . '.GIF'))
                autoscreen_thm($loadroot . '/' . $file['way'], 128, 160, $loadroot . '/' . $file['way'] .
                    '.GIF');
            echo '<img src="' . $loadroot . '/' . $file['way'] .
                '.GIF" alt="Скриншот..."/><br/>';
        } elseif ($tf == 'nth') {
            if (!is_file($loadroot . '/' . $file['way'] . '.GIF'))
                autoscreen_nth($loadroot . '/' . $file['way'], 128, 160, $loadroot . '/' . $file['way'] .
                    '.GIF');
            echo '<img src="' . $loadroot . '/' . $file['way'] .
                '.GIF" alt="Скриншот.."/><br/>';
        }
    }
    /////////////////////////
    ///// Скрин к видео /////
    /////////////////////////
    //TODO:Переделать обработку видео...
    if ($tf == '3gp' or $tf == 'avi' or $tf == 'mp4') {
        if ($down_setting['screenvideo']) {
            if (!is_file($loadroot . '/' . $file['way'] . '.GIF'))
                autoscreen_video($loadroot . '/' . $file['way'], $loadroot . '/' . $file['way'] .
                    '.GIF', 132, 96);
            echo '<img src="' . $loadroot . '/' . $file['way'] .
                '.GIF" alt="Скриншот..."/><br/>';
        }
        if ($down_setting['infvideo']) {
            $media = new ffmpeg_movie($loadroot . '/' . $file['way']);
            echo 'Время ролика: ' . date('i:s', $media->getDuration()) . '<br/>';
            echo 'Разрешение: ' . $media->getFrameHeight() . 'x' . $media->getFrameWidth() .
                '<br/>';
            echo 'Битрейт: ' . ceil(($media->getBitRate())/1024) . 'kpbs <br />';
			echo 'Частота кадров: ' . $media->getFrameRate() . '<br />';
			echo 'Кодек (видео): ' . $media->getVideoCodec() . '<br />';
			
        }
		
echo '<p id="preview">Установите флэш плеер для просмотра...</p>
<script type="text/javascript" src="swfobject.js"></script>
<script type="text/javascript">
var so = new SWFObject("player.swf","player","300","180","2","#" );
so.addParam("allowfullscreen","true");
so.addParam("allowscriptaccess","always");
so.addParam("wmode","opaque");
so.addParam("flashvars","file='.$home.'/download/files/'.$file['way'].'");
so.write("preview");
</script>';
    }

    ////////////////////////////////////
    //////// Скрин к картинке //////////
    ////////////////////////////////////
    if ($tf == 'gif' or $tf == 'png' or $tf == 'jpg' or $tf == 'jpeg') {
        if (!$down_setting['screencache']) {
            echo '<img src="getthumb.php?file=' . $loadroot . '/' . $file['way'] .
                '&amp;size=120" alt="Скриншот..."/><br/>';
        } else {
            if (!is_file('graftemp/' . $file['id'] . '.big.' . $tf)) {
                $img = new ImageEdit($loadroot . '/' . $file['way'], $down_setting['scr_size']);
                // Подаём оригинал и максимальный размер
                $img->setQuality(90);
                // Качество
                if($down_setting['scr_copy'])
                $img->setCopy($down_setting['scr_copy_size'], $down_setting['scr_copy_text']);
                $img->saveImage('graftemp/' . $file['id'] . '.big.' . $tf);
                // Сохраняем во временную папку
            }
            echo '<img src="graftemp/' . $file['id'] . '.big.' . $tf .
                '" alt="Скриншот..."/><br/>';
        }
    }


echo '<b>Qo\'shildi</b> ' . $filtime . '</div>';
    if ($file['login']) {
echo '<div class="menu"><b>Qo\'shdi:</b> <a href="../users/profile.php?user='.$file['user_id'].'">' . $file['login'] . '</a></div>';
    }
    echo '<div class="menu"><b>Yuklangan:</b> ' . ending($file['count']) . '</div>';

    ///////////////////////////////
    //////// Если это JAR /////////
    ///////////////////////////////
    if ($tf == 'jar') {    
        $archive2 = new JarInfo($loadroot . '/' . $file['way']);
        
        //$archive2->setDeleteConfirm('Скачать программу повторно можно с сайта symbos.su');
        //$archive2->saveManifest();
        
        if ($down_setting['jar_version'] > 0 && $archive2->getVersion())
            echo '<div class="menu"><b>Версия:</b> ' . $archive2->getVersion() . '</div>';
        if ($down_setting['jar_name'] > 0 && $archive2->getName())
            echo '<div class="menu"><b>Название:</b> ' . $archive2->getName() . '</div>';
        if ($down_setting['jar_vendor'] > 0 && $archive2->getVendor())
            echo '<div class="menu"><b>Производитель:</b> ' . $archive2->getVendor() .
                '</div>';
        if ($down_setting['jar_profile'] > 0 && $archive2->getProfile())
            echo '<div class="menu"><b>Профиль:</b> ' . $archive2->getProfile() . '</div>';
        if ($down_setting['jar_url'] > 0 && $archive2->getUrl())
            echo '<div class="menu"><b>Url:</b> ' . $archive2->getUrl() . '</div>';
        // Получаем иконку если её ещё нет.
        $icon = 'graftemp/' . $file['id'] . '.icon.png';
        if (!is_file('graftemp/' . $file['id'] . '.icon.png')) {
            if (!$archive2->getIcon('graftemp/' . $file['id'] . '.icon.png'))
                $icon = 'img/jar.png';
        }
    }
    ///////////////////////
    ////// Описание ///////
    ///////////////////////
    echo '<div class="menu">';
    if ($file['desc']) {
        echo functions::checkout($file['desc'], 1, 1);
    } else {
        echo 'Описания нет!';
    }
    echo '</div>';

    /////////////////////////
    ////// Инфа о mp3 ///////
    /////////////////////////
    if ($down_setting['mp3info']) {
        if ($tf == 'mp3') {
            echo '<div class="menu">';
            
			if ($rights >= 7) {
 echo '<div><img src="img/edit.png" alt="." /> <a href="tageditor.php?file=files' . DIRECTORY_SEPARATOR . $file['way'] . '">Teglarni tahrirlash ' . $namee[1] . '</a></div>';
 }
 
            require_once 'classes/classAudioFile.php';
            $f = new AudioFile;
            // добавляем аудиофайл
            $f->loadFile($loadroot.'/'.$file[way]);
            // выводим информацию
/////// echo functions::checkout(str_replace('&', '&amp;', $f->printSampleInfo()), 1, 1);//////
            

            echo '<b>Tinglash :</b> <br/>';
            echo '<center><object type="application/x-shockwave-flash" name="audioplayer_1" style="outline: none; visibility: visible;" data="http://uzmuz.tv/download/player/player.swf" width="80%" height="24" id="audioplayer_1"><param name="movie" value="mp3player.swf" /><param name="flashvars" value="animation=no&amp;encode=no&amp;initialvolume=70&amp;remaining=yes&amp;noinfo=no&amp;buffer=5&amp;checkpolicy=no&amp;rtl=no&amp;bg=f8fcff&amp;text=000000&amp;leftbg=5D80A6&amp;lefticon=ffffff&amp;volslider=62a5e0&amp;voltrack=ffffff&amp;rightbg=5D80A6&amp;rightbghover=5895cc&amp;righticon=ffffff&amp;righticonhover=ffffff&amp;track=FFFFFF&amp;loader=5D80A6&amp;border=5D80A6&amp;tracker=62a5e0&amp;skip=ff284b&amp;soundFile='.$loadroot.'/'.$file['way'].'&amp;autostart=no&amp;playerID=audioplayer_1" /></object></center>';


            echo '</div>';
        }
    }


    ///////////////////////////////////
    ////// Обсуждение на форуме ///////
    ///////////////////////////////////
    if ($file['themeid'])
    {
        echo '<div class="menu"><img src="img/peopl.png" alt="."/> <a href="../forum/index.php?id=' .
            $file['themeid'] . '">Обсудить на форуме</a></div>';
    }


    if ($dostguest == 'open') {

        if (!$namee[1]) {
$namee[1] = 'Yuklab Olish';
        }
        if (!isset($icon))
            $icon = 'img/save.png';

        echo '<div class="menu"><img src="' . $icon .
            '" alt="."/> <a href="loadfile.php?down=' . $file['way'] . '">Скачать ' . $namee[1] .
            '</a>';

        //////////////////////////
        ////// Получаем JAD //////
        //////////////////////////
        if ($tf == 'jar' && $down_setting['jadgen']) {
            $jadf = str_ireplace('.jar', '.jad', $file['way']);
            $jarurl = '' . $home . '/' . $downpat . '/' . $file['way']; //// Адрес файла записываемый в JAD
            if (!is_file($loadroot . '/' . $jadf))
                $archive2->getJad($jarurl);
            echo '&nbsp;<a href="loadfile.php?down=' . $file['way'] .
                '&amp;jad=1">[JAD]</a>';
        }
        echo ' [' . $file['count'] . ']</div>';

        ///////////////////////////////////////
        ///// Выбор размеров для картинок /////
        ///////////////////////////////////////
        if ($tf == 'gif' || $tf == 'jpg' || $tf == 'png') {
            echo "<div class='menu'><form action='image.php' method='get'>
<img src=\"img/view.png\" alt='.'/> <b>Скачать с нужным размером:</b><br/><select title='Выберите размер' name='size'>";
echo '<option value="640x480">640x480</option><option value="240x320">240x320</option><option value="208x208">208x208</option><option value="176x220">176x220</option><option value="176x208">176x208</option><option value="132x176">132x176</option><option value="128x160">128x160</option></select>
<input type="hidden" name="file" value="' . $loadroot.'/'.$file['way'] . '"/>
<input type="submit" value="Скачать"/></form></div>';
        }

        ///////////////////////////////
        ////// Просмотр архивов ///////
        ///////////////////////////////
        if ($down_setting['zipview']) {
            if ($tf == "zip") {
                echo '<div class="menu"><img src="img/rar.png" alt="."/> <a href="zipview.php?file=' .
                    $file['way'] . '&amp;file_id=' . $viewf . '">Просмотреть архив</a></div>';
            }
        }

        echo '<div class="menu">Fayl URL adresiL:<br/>
<input type="text" name="url" value="' . $home . str_replace("..", "", $filesroot) .
            '/loadfile.php?down=' . $file['way'] . '"/></div>';

        ////////////////////////////////
        ///// Дополнительные файлы /////
        ////////////////////////////////
        if (mysql_num_rows($file22)) {
            while ($file2 = mysql_fetch_array($file22)) {
                $tf = pathinfo($file2['way'], PATHINFO_EXTENSION);
                echo '<div class="menu"><img src="img/save.png" alt="."/> <a href="loadfile.php?down=' .
                    $file2['way'] . '">Скачать ' . $file2['name'] . '</a>';
                if ($tf == "jar" && $down_setting['jadgen']) {
                    $archive2 = new JarInfo($loadroot . '/' . $file2['way']);
                    $jadf = str_ireplace('.jar', '.jad', $file2['way']);
                    $jarurl = '' . $home . '/' . $downpat . '/' . $file2['way']; //// Адрес файла записываемый в JAD
                    if (!is_file($loadroot . '/' . $jadf))
                        $archive2->getJad($jarurl);
                    echo '&nbsp;<a href="loadfile.php?down=' . $file2['way'] .
                        '&amp;jad=1">[JAD]</a>';
                }
                echo '&nbsp;[' . $file2['count'] . ']<br/>
' . functions::checkout($file2['desc'], 1, 1) . '</div>';

                if ($tf == "zip" && $down_setting['zipview'])
                    echo '<img src="img/rar.png" alt="."/> <a href="zipview.php?file=' . $file2[way] .
                        '&amp;file_id=' . $viewf . '">Просмотреть архив</a><br/>';
            }
        }
    } else {
        echo '<b>Faqat sayt a\'zolari yuklab olishi mumkin!</b><br/>';
    }

    //////////////////////////////////
    /////// Поделиться ссылкой ///////
    //////////////////////////////////
    echo '<div class="menu" align="center">Do\'stlarga ulashish:<br/><script type="text/javascript" src="//yastatic.net/es5-shims/0.0.2/es5-shims.min.js" charset="utf-8"></script>
<script type="text/javascript" src="//yastatic.net/share2/share.js" charset="utf-8"></script>
<div class="ya-share2" data-services="vkontakte,facebook,odnoklassniki,moimir,twitter,viber,whatsapp"></div></div>';

echo'<div class="phdr">Komment yozish</div>';
	if ($user_id) {
    if (isset($_POST['submit']))
    {
        
    if(empty($_POST['txt']))
    {
        echo'<div class="rmenu">Matn kiritilmadi!</div>';
    } else {
    
    mysql_query("INSERT INTO `downkomm` (`id`, `fileid`, `time`, `userid`, `text`, `plus`, `minus`, `golos`) VALUES (NULL, '".$viewf."', '".time()."', '".$user_id."', '".mysql_real_escape_string($_POST['txt'])."', '0', '0', '');");    
    $req = mysql_query("SELECT * from `users` where id = '".$user_id."';");
    $res = mysql_fetch_array($req);
    $fpst = $res['komm'] + 1;
    mysql_query("UPDATE `users` SET `komm`='" . $fpst . "' WHERE `id`='" . $user_id . "';");


        if($down_setting['priv'] > 0)
        {
            $text_mail = 'Yuklamalarda komment qoldirildi. [url='.core::$system_set['homeurl'].'/download/file_'.$viewf.'.html]Ko\'rish[/url]';
            mysql_query("INSERT INTO `cms_mail` SET
                    `user_id` = '0',
                    `from_id` = '" . $down_setting['priv_user'] . "',
                    `text` = '" . mysql_real_escape_string($text_mail) . "',
                    `time` = '" . time() . "',
                    `sys` = '1'") or die(mysql_error());
        }

    
    echo'<div class="gmenu">Komment qo\'shildi!</div>';   
    }
	}
        
    $set_download = unserialize($datauser['set_forum']);
    
    echo '<form method="post" name="komm">
    <div class="menu">';
    if(!$is_mobile)
    echo bbcode::emoji('komm', 'txt');
    echo '<textarea cols="' . $set_user['field_w'] . '" rows="' . $set_user['field_h'] . '" name="txt"></textarea></div>
    <div class="menu">
    <input type="submit" name="submit" value="Yozish"/></div>
    </form>';
	}
echo'<div class="phdr">Kommentlar </div>';    
    $total = mysql_result(mysql_query("SELECT COUNT(*) FROM `downkomm` WHERE `fileid` = '" . $viewf . "';"), 0);
    if ($total > 0) {
    $query = mysql_query("select * from `downkomm` where fileid='" . $viewf . "' ORDER BY `time` DESC LIMIT " . $start . "," . $kmess);
    while($arr = mysql_fetch_array($query)){
    echo ($i % 2) ? '<div class="list1">' : '<div class="list2">';
    $i++;
    $res = mysql_fetch_array(mysql_query("SELECT * from `users` where id = '".$arr['userid']."';"));      
    
    $text = functions::checkout($arr['text'], 1, 1);
    $text = functions::smileys($text);
    $vrp = $arr['time'] + $sdvig * 3600;
    $idd = explode('|',$arr['golos']);
    $vr = date("d.m.y / H:i", $vrp);
    $upr = '';
    if($rights >= 1)
    $upr .= '<a href="komm.php?act=del&amp;komid='.$arr['id'].'&amp;id='.$viewf.'">[O\'chirish]</a> ';
    $arg = array ('stshide' => 1, 'header' => '('.$vr.')',
    'body' => $text,
    'sub' => $upr,
    'iphide' => 1);
    echo functions::display_user($res, $arg) . '</div>';
    } 
    }else
    echo'<div class="rmenu">Hozircha kommentlar mavjud emas, birinchi bo\'l!</div>';
    echo'<div class="phdr">Umumiy kommentlar: '.$total.'</div>';
    
    if ($total > $kmess){
   	echo '<div class="menu">' . functions::display_pagination('komm.php?id='.$viewf.'&amp;', $start, $total, $kmess) . '';
   	echo '<form action="komm.php" method="get"><input type="hidden" name="id" value="'.$viewf.'"/><input type="text" name="page" size="2"/><input type="submit" value="К странице &gt;&gt;"/></form></div>';
    }

    if ($user_id)
        echo '<div class="menu"><img src="img/apply.png" alt="."/> <a href="index.php?act=bookmarks&amp;dejst=add&amp;id=' .
            $viewf . '">Faylni zakladkaga qo\'shish</a></div>';

} else {
    echo '<div class="rmenu">Fayl topilmadi!</div>';
}
echo '<div class="phdr"><a href="dir_' . $file['pathid'] .
    '.html">Ortga</a></div>';

require_once '../incfiles/end.php';
?>