2018-01-09 02:09:07 +03:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @package Kleeja
|
2020-04-11 22:45:48 +02:00
|
|
|
* @copyright (c) 2007 Kleeja.net
|
2018-01-09 02:09:07 +03:00
|
|
|
* @license ./docs/license.txt
|
2019-05-16 04:23:30 +02:00
|
|
|
*
|
2018-01-09 02:09:07 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @ignore
|
|
|
|
|
*/
|
|
|
|
|
define('IN_KLEEJA', true);
|
2019-05-18 01:47:17 +03:00
|
|
|
define('IN_DOWNLOAD', true);
|
2018-01-09 02:09:07 +03:00
|
|
|
require_once 'includes/common.php';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
is_array($plugin_run_result = Plugins::getInstance()->run('begin_download_page', get_defined_vars())) ? extract($plugin_run_result) : null; //run hook
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
//page of wait downloading files
|
|
|
|
|
//
|
|
|
|
|
if (ig('id') || ig('filename'))
|
|
|
|
|
{
|
|
|
|
|
is_array($plugin_run_result = Plugins::getInstance()->run('begin_download_id_filename', get_defined_vars())) ? extract($plugin_run_result) : null; //run hook
|
|
|
|
|
|
2019-05-03 23:52:08 +03:00
|
|
|
$query = [
|
2020-05-24 18:18:00 +02:00
|
|
|
'SELECT' => 'f.id, f.real_filename, f.about, f.name, f.folder, f.size, f.time, f.uploads, f.type',
|
2019-05-18 01:47:17 +03:00
|
|
|
'FROM' => "{$dbprefix}files f",
|
|
|
|
|
'LIMIT' => '1',
|
2019-05-03 23:52:08 +03:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
//if user system is default, we use users table
|
|
|
|
|
if ((int) $config['user_system'] == 1)
|
|
|
|
|
{
|
|
|
|
|
$query['SELECT'] .= ', u.name AS fusername, u.id AS fuserid';
|
2019-05-18 01:47:17 +03:00
|
|
|
$query['JOINS'] = [
|
2019-05-03 23:52:08 +03:00
|
|
|
[
|
2019-05-18 01:47:17 +03:00
|
|
|
'LEFT JOIN' => "{$dbprefix}users u",
|
|
|
|
|
'ON' => 'u.id=f.user'
|
2019-05-03 23:52:08 +03:00
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ig('filename'))
|
|
|
|
|
{
|
|
|
|
|
$filename_l = (string) $SQL->escape(g('filename'));
|
|
|
|
|
|
|
|
|
|
if (ig('x'))
|
|
|
|
|
{
|
2019-05-18 01:47:17 +03:00
|
|
|
$query['WHERE'] = "f.name='" . $filename_l . '.' . $SQL->escape(g('x')) . "'";
|
2019-05-03 23:52:08 +03:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-05-18 01:47:17 +03:00
|
|
|
$query['WHERE'] = "f.name='" . $filename_l . "'";
|
2019-05-03 23:52:08 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-05-18 01:47:17 +03:00
|
|
|
$id_l = g('id', 'int');
|
|
|
|
|
$query['WHERE'] = 'f.id=' . $id_l;
|
2019-05-03 23:52:08 +03:00
|
|
|
}
|
2018-01-09 02:09:07 +03:00
|
|
|
|
|
|
|
|
is_array($plugin_run_result = Plugins::getInstance()->run('qr_download_id_filename', get_defined_vars())) ? extract($plugin_run_result) : null; //run hook
|
2019-05-18 01:47:17 +03:00
|
|
|
$result = $SQL->build($query);
|
2018-01-09 02:09:07 +03:00
|
|
|
|
2019-05-03 23:52:08 +03:00
|
|
|
if ($SQL->num_rows($result) != 0)
|
|
|
|
|
{
|
|
|
|
|
$file_info = $SQL->fetch_array($result);
|
2018-01-09 02:09:07 +03:00
|
|
|
|
2019-05-03 23:52:08 +03:00
|
|
|
$SQL->freeresult($result);
|
2018-01-09 02:09:07 +03:00
|
|
|
|
2019-05-03 23:52:08 +03:00
|
|
|
// some vars
|
|
|
|
|
$id = $file_info['id'];
|
|
|
|
|
$name = $fname = $file_info['name'];
|
2018-01-09 02:09:07 +03:00
|
|
|
$real_filename = $file_info['real_filename'];
|
2019-05-03 23:52:08 +03:00
|
|
|
$type = $file_info['type'];
|
|
|
|
|
$size = $file_info['size'];
|
|
|
|
|
$time = $file_info['time'];
|
|
|
|
|
$uploads = $file_info['uploads'];
|
2020-05-24 18:18:00 +02:00
|
|
|
$about_file = ! in_array($file_info['about'], ['', null]) ? $file_info['about'] : $lang['FILE_NO_INFO'];
|
2019-05-03 23:52:08 +03:00
|
|
|
|
|
|
|
|
|
2020-05-24 18:18:00 +02:00
|
|
|
$fname2 = str_replace('.', '-', htmlspecialchars($name));
|
|
|
|
|
$name = $real_filename != '' ? str_replace('.' . $type, '', htmlspecialchars($real_filename)) : $name;
|
|
|
|
|
$name = strlen($name) > 70 ? substr($name, 0, 70) . '...' : $name;
|
|
|
|
|
$fusername = $config['user_system'] == 1 && $file_info['fuserid'] > -1 ? $file_info['fusername'] : false;
|
|
|
|
|
$userfolder = $config['siteurl'] . ($config['mod_writer'] ? 'fileuser-' . $file_info['fuserid'] . '.html' : 'ucp.php?go=fileuser&id=' . $file_info['fuserid']);
|
2022-08-27 15:40:31 +01:00
|
|
|
$isFileOwnerOfFounder = ($fusername == $usrcp->name() && $usrcp->name()) || ($usrcp->id() < 1 ? false : $usrcp->get_data('founder')['founder'] == 1);
|
2020-05-24 18:18:00 +02:00
|
|
|
|
|
|
|
|
if (ip('change_file_about') && $isFileOwnerOfFounder)
|
|
|
|
|
{
|
|
|
|
|
$newAbout = (String) p('about') != '' ? (string) p('about') : null;
|
|
|
|
|
$SQL->query("UPDATE {$dbprefix}files SET about = \"{$newAbout}\" WHERE id = {$file_info['id']}");
|
|
|
|
|
|
|
|
|
|
exit;
|
|
|
|
|
}
|
2019-05-03 23:52:08 +03:00
|
|
|
|
|
|
|
|
if (ig('filename'))
|
|
|
|
|
{
|
2019-05-18 01:47:17 +03:00
|
|
|
$url_file = $config['mod_writer'] ? $config['siteurl'] . 'downf-' . $fname2 . '.html' : $config['siteurl'] . 'do.php?downf=' . $fname;
|
2019-05-03 23:52:08 +03:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-05-18 01:47:17 +03:00
|
|
|
$url_file = $config['mod_writer'] ? $config['siteurl'] . 'down-' . $file_info['id'] . '.html' : $config['siteurl'] . 'do.php?down=' . $file_info['id'];
|
2019-05-03 23:52:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (! empty($config['livexts']))
|
|
|
|
|
{
|
|
|
|
|
$livexts = explode(',', $config['livexts']);
|
2018-01-09 02:09:07 +03:00
|
|
|
|
|
|
|
|
if (in_array($type, $livexts))
|
2019-05-03 23:52:08 +03:00
|
|
|
{
|
|
|
|
|
if (ig('filename'))
|
|
|
|
|
{
|
2019-05-18 01:47:17 +03:00
|
|
|
$url_filex = $config['mod_writer'] ? $config['siteurl'] . 'downexf-' . $fname2 . '.html' : $config['siteurl'] . 'do.php?downexf=' . $fname;
|
2019-05-03 23:52:08 +03:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-05-18 01:47:17 +03:00
|
|
|
$url_filex = $config['mod_writer'] ? $config['siteurl'] . 'downex-' . $file_info['id'] . '.html' : $config['siteurl'] . 'do.php?downex=' . $file_info['id'];
|
2019-05-03 23:52:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
redirect($url_filex, false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-18 01:47:17 +03:00
|
|
|
$REPORT = ($config['mod_writer']) ? $config['siteurl'] . 'report-' . $file_info['id'] . '.html' : $config['siteurl'] . 'go.php?go=report&id=' . $file_info['id'];
|
|
|
|
|
$seconds_w = user_can('enter_acp') ? 0 : $config['sec_down'];
|
|
|
|
|
$time = kleeja_date($time);
|
|
|
|
|
$size = readable_size($size);
|
2019-05-03 23:52:08 +03:00
|
|
|
|
2019-05-18 01:47:17 +03:00
|
|
|
$file_ext_icon = file_exists('images/filetypes/' . $type . '.png') ? 'images/filetypes/' . $type . '.png' : 'images/filetypes/file.png';
|
|
|
|
|
$sty = 'download';
|
|
|
|
|
$title = $name . ' - ' . $lang['DOWNLAOD'];
|
2019-05-03 23:52:08 +03:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
//file not exists
|
2018-01-09 02:09:07 +03:00
|
|
|
is_array($plugin_run_result = Plugins::getInstance()->run('not_exists_qr_downlaod_file', get_defined_vars())) ? extract($plugin_run_result) : null; //run hook
|
2019-05-03 23:52:08 +03:00
|
|
|
kleeja_err($lang['FILE_NO_FOUNDED']);
|
|
|
|
|
}
|
2018-01-09 02:09:07 +03:00
|
|
|
|
2019-01-18 23:31:49 +03:00
|
|
|
$show_style = true;
|
|
|
|
|
|
2018-01-09 02:09:07 +03:00
|
|
|
is_array($plugin_run_result = Plugins::getInstance()->run('b4_showsty_downlaod_id_filename', get_defined_vars())) ? extract($plugin_run_result) : null; //run hook
|
|
|
|
|
|
2019-05-03 23:52:08 +03:00
|
|
|
//add http reffer to session to prevent errors with some browsers !
|
2018-01-09 02:09:07 +03:00
|
|
|
$_SESSION['HTTP_REFERER'] = $file_info['id'];
|
|
|
|
|
|
2019-01-18 23:31:49 +03:00
|
|
|
// show style
|
2019-05-03 23:52:08 +03:00
|
|
|
if ($show_style)
|
2019-01-18 23:31:49 +03:00
|
|
|
{
|
|
|
|
|
Saaheader($title);
|
|
|
|
|
echo $tpl->display($sty);
|
|
|
|
|
Saafooter();
|
|
|
|
|
}
|
2018-01-09 02:09:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
//download file
|
|
|
|
|
//
|
2019-05-03 23:52:08 +03:00
|
|
|
// guidelines for _get variable names
|
|
|
|
|
//
|
|
|
|
|
// down: [0-9], default, came from do.php?id=[0-9]
|
|
|
|
|
// downf: [a-z0-9].[ext], came from do.php?filename=[a-z0-9].[ext]
|
|
|
|
|
//
|
|
|
|
|
// img: [0-9], default, direct from do.php?img=[0-9]
|
|
|
|
|
// imgf: [a-z0-9].[ext], direct from do.php?imgf=[a-z0-9].[ext]
|
|
|
|
|
//
|
|
|
|
|
// thmb: [0-9], default, direct from do.php?thmb=[0-9]
|
|
|
|
|
// thmbf: [a-z0-9].[ext], direct from do.php?thmbf=[a-z0-9].[ext]
|
|
|
|
|
//
|
|
|
|
|
// live extensions feature uses downex, downexf as in down & downf
|
|
|
|
|
//
|
|
|
|
|
// x : used only for html links, where x = extension, downf is filename without extension
|
|
|
|
|
|
|
|
|
|
elseif (ig('down') || ig('downf') ||
|
2024-10-07 17:15:05 +01:00
|
|
|
ig('img') || ig('imgf') ||
|
2019-05-03 23:52:08 +03:00
|
|
|
ig('thmb') || ig('thmbf') ||
|
2024-10-07 17:15:05 +01:00
|
|
|
ig('downex') || ig('downexf'))
|
2018-01-09 02:09:07 +03:00
|
|
|
{
|
|
|
|
|
is_array($plugin_run_result = Plugins::getInstance()->run('begin_down_go_page', get_defined_vars())) ? extract($plugin_run_result) : null; //run hook
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//kleeja_log('downloading file start - (' . var_dump($_GET) . ') -> ' . $_SERVER['HTTP_REFERER']);
|
|
|
|
|
|
|
|
|
|
//must know from where he came ! and stop him if not image
|
|
|
|
|
//todo: if it's download manger, let's pass this
|
|
|
|
|
if (ig('down') || ig('downf'))
|
|
|
|
|
{
|
|
|
|
|
//if not from our site and the waiting page
|
|
|
|
|
$not_reffer = true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$isset_down_h = ig('downf') && ig('x') ? 'downloadf-' . g('downf') . '-' . g('x') . '.html' : (ig('down') ? 'download' . g('down') . '.html' : '');
|
|
|
|
|
|
2019-05-03 23:52:08 +03:00
|
|
|
if (! empty($_SERVER['HTTP_REFERER'])
|
2018-01-09 02:09:07 +03:00
|
|
|
&& strpos($_SERVER['HTTP_REFERER'], $isset_down_h) !== false)
|
|
|
|
|
{
|
|
|
|
|
$not_reffer = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$isset_down = ig('downf') ? 'do.php?filename=' . g('downf') : (ig('down') ? 'do.php?id=' . g('down') : '');
|
|
|
|
|
|
2019-05-03 23:52:08 +03:00
|
|
|
if (! empty($_SERVER['HTTP_REFERER'])
|
2018-01-09 02:09:07 +03:00
|
|
|
&& strpos($_SERVER['HTTP_REFERER'], $isset_down) !== false)
|
|
|
|
|
{
|
|
|
|
|
$not_reffer = false;
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-03 23:52:08 +03:00
|
|
|
if (! empty($_SERVER['HTTP_REFERER'])
|
|
|
|
|
&& strpos($config['siteurl'], str_replace(['http://', 'www.', 'https://'], '', htmlspecialchars($_SERVER['HTTP_REFERER']))))
|
2018-01-09 02:09:07 +03:00
|
|
|
{
|
|
|
|
|
$not_reffer = false;
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-03 23:52:08 +03:00
|
|
|
if (isset($_SERVER['HTTP_RANGE']))
|
2018-01-09 02:09:07 +03:00
|
|
|
{
|
|
|
|
|
$not_reffer = false;
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-03 23:52:08 +03:00
|
|
|
if (isset($_SESSION['HTTP_REFERER']))
|
2018-01-09 02:09:07 +03:00
|
|
|
{
|
|
|
|
|
$not_reffer = false;
|
|
|
|
|
|
|
|
|
|
unset($_SESSION['HTTP_REFERER']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($not_reffer)
|
|
|
|
|
{
|
|
|
|
|
if (ig('downf'))
|
|
|
|
|
{
|
2019-05-03 23:52:08 +03:00
|
|
|
$go_to = $config['siteurl'] . ($config['mod_writer'] && ig('x') ? 'downloadf-' . g('downf') . '-' . g('x') . '.html' : 'do.php?filename=' . g('downf'));
|
2018-01-09 02:09:07 +03:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
$go_to = $config['siteurl'] . ($config['mod_writer'] ? 'download' . g('down') . '.html' : 'do.php?id=' . g('down'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
redirect($go_to);
|
|
|
|
|
$SQL->close();
|
2019-05-03 23:52:08 +03:00
|
|
|
|
2018-01-09 02:09:07 +03:00
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//download by id or filename
|
|
|
|
|
//is the requested variable is filename(filename123.gif) or id (123) ?
|
|
|
|
|
$is_id_filename = ig('downf') || ig('imgf') || ig('thmbf') || ig('downexf') ? true : false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$filename = $id = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($is_id_filename)
|
|
|
|
|
{
|
|
|
|
|
$var = ig('downf') ? 'downf' : (ig('imgf') ? 'imgf' : (ig('thmbf') ? 'thmbf' : (ig('downexf') ? 'downexf' : false)));
|
|
|
|
|
|
2019-05-03 23:52:08 +03:00
|
|
|
//x, represent the extension, came from html links
|
2018-01-09 02:09:07 +03:00
|
|
|
if (ig('x') && $var)
|
|
|
|
|
{
|
|
|
|
|
$filename = $SQL->escape(g($var)) . '.' . $SQL->escape(g('x'));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
$filename = $SQL->escape(g($var));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
$id = ig('down') ? g('down', 'int') : (ig('img') ? g('img', 'int') : (ig('thmb') ? g('thmb', 'int') : (ig('downex') ? g('downex', 'int') : null)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//is internet explore 8 ?
|
|
|
|
|
$is_ie8 = is_browser('ie8');
|
|
|
|
|
//is internet explore 6 ?
|
2019-06-02 05:46:15 +03:00
|
|
|
// $is_ie6 = is_browser('ie6');
|
2018-01-09 02:09:07 +03:00
|
|
|
|
2019-05-03 23:52:08 +03:00
|
|
|
$livexts = explode(',', $config['livexts']);
|
2018-01-09 02:09:07 +03:00
|
|
|
|
|
|
|
|
//get info file
|
2019-05-20 01:46:20 +02:00
|
|
|
$query = ['SELECT' => 'f.id, f.name, f.real_filename, f.folder, f.type, f.size, f.time',
|
2019-05-03 23:52:08 +03:00
|
|
|
'FROM' => "{$dbprefix}files f",
|
|
|
|
|
'WHERE' => $is_id_filename ? "f.name='" . $filename . "'" . (ig('downexf') ? " AND f.type IN ('" . implode("', '", $livexts) . "')" : '') :
|
2018-01-09 02:09:07 +03:00
|
|
|
'f.id=' . $id . (ig('downex') ? " AND f.type IN ('" . implode("', '", $livexts) . "')" : ''),
|
|
|
|
|
'LIMIT' => '1'
|
2019-05-03 23:52:08 +03:00
|
|
|
];
|
2018-01-09 02:09:07 +03:00
|
|
|
|
|
|
|
|
is_array($plugin_run_result = Plugins::getInstance()->run('qr_down_go_page_filename', get_defined_vars())) ? extract($plugin_run_result) : null; //run hook
|
|
|
|
|
$result = $SQL->build($query);
|
|
|
|
|
|
|
|
|
|
$is_live = false;
|
2019-05-03 23:52:08 +03:00
|
|
|
$pre_ext = ! empty($filename) && strpos($filename, '.') !== false ? explode('.', $filename) : [];
|
2022-07-26 23:41:05 +02:00
|
|
|
$pre_ext = ! empty($pre_ext) ? array_pop($pre_ext) : '';
|
2018-01-09 02:09:07 +03:00
|
|
|
|
|
|
|
|
|
2019-05-03 23:52:08 +03:00
|
|
|
$is_image = in_array(strtolower(trim($pre_ext)), ['gif', 'jpg', 'jpeg', 'bmp', 'png']) ? true : false;
|
2018-01-09 02:09:07 +03:00
|
|
|
|
2019-05-03 23:52:08 +03:00
|
|
|
//initiate variables
|
2018-01-09 02:09:07 +03:00
|
|
|
$ii = $n = $rn = $t = $f = $ftime = $d_size = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($SQL->num_rows($result))
|
|
|
|
|
{
|
|
|
|
|
$row = $SQL->fetch($result);
|
|
|
|
|
|
2019-05-03 23:52:08 +03:00
|
|
|
$ii = $row['id'];
|
|
|
|
|
$n = $row['name'];
|
|
|
|
|
$rn = $row['real_filename'];
|
|
|
|
|
$t = strtolower(trim($row['type']));
|
|
|
|
|
$f = $row['folder'];
|
|
|
|
|
$ftime = $row['time'];
|
2018-01-09 02:09:07 +03:00
|
|
|
$d_size = $row['size'];
|
|
|
|
|
|
|
|
|
|
|
2019-05-03 23:52:08 +03:00
|
|
|
//img or not
|
|
|
|
|
$is_image = in_array($t, ['gif', 'jpg', 'jpeg', 'bmp', 'png']) ? true : false;
|
|
|
|
|
//live url
|
2018-01-09 02:09:07 +03:00
|
|
|
$is_live = in_array($t, $livexts) ? true : false;
|
|
|
|
|
|
|
|
|
|
|
2019-05-30 07:32:17 +03:00
|
|
|
$SQL->freeresult($result);
|
2018-01-09 02:09:07 +03:00
|
|
|
|
|
|
|
|
//fix bug where a user can override files wait counter
|
2019-05-03 23:52:08 +03:00
|
|
|
if (! $is_image && (ig('img') || ig('thmb')))
|
2018-01-09 02:09:07 +03:00
|
|
|
{
|
|
|
|
|
$go_to = $config['siteurl'] . ($config['mod_writer'] ? 'download' . $ii . '.html' : 'do.php?id=' . $ii);
|
|
|
|
|
redirect($go_to);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//check if the vistor is new in this page before updating kleeja counter
|
2019-05-03 23:52:08 +03:00
|
|
|
if (! preg_match('/,' . $ii . ',/i', $usrcp->kleeja_get_cookie('oldvistor')) && ! isset($_SERVER['HTTP_RANGE']))
|
2018-01-09 02:09:07 +03:00
|
|
|
{
|
2019-05-20 01:46:20 +02:00
|
|
|
if ($usrcp->group_id() != 1)
|
2018-01-09 02:09:07 +03:00
|
|
|
{
|
2019-05-19 03:16:44 +02:00
|
|
|
//updates number of uploads ..
|
|
|
|
|
$update_query = [
|
|
|
|
|
'UPDATE' => "{$dbprefix}files",
|
|
|
|
|
'SET' => 'uploads=uploads+1, last_down=' . time(),
|
|
|
|
|
'WHERE' => $is_id_filename ? "name='" . $filename . "'" : 'id=' . $id,
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
is_array($plugin_run_result = Plugins::getInstance()->run('qr_update_no_uploads_down', get_defined_vars())) ? extract($plugin_run_result) : null; //run hook
|
|
|
|
|
$SQL->build($update_query);
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
//Define as old vistor
|
|
|
|
|
//if this vistor has other views then add this view too
|
|
|
|
|
//old vistor just for 1 day
|
|
|
|
|
//
|
|
|
|
|
if ($usrcp->kleeja_get_cookie('oldvistor'))
|
|
|
|
|
{
|
|
|
|
|
$usrcp->kleeja_set_cookie('oldvistor', $usrcp->kleeja_get_cookie('oldvistor') . $ii . ',', time() + 86400);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
//first time
|
|
|
|
|
$usrcp->kleeja_set_cookie('oldvistor', ',' . $ii . ',', time() + 86400);
|
|
|
|
|
}
|
2018-01-09 02:09:07 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
//not exists img or thumb
|
|
|
|
|
if (ig('img') || ig('thmb') || ig('thmbf') || ig('imgf'))
|
|
|
|
|
{
|
|
|
|
|
is_array($plugin_run_result = Plugins::getInstance()->run('not_exists_qr_down_img', get_defined_vars())) ? extract($plugin_run_result) : null; //run hook
|
|
|
|
|
|
|
|
|
|
$f = 'images';
|
|
|
|
|
$n = 'not_exists.jpg';
|
|
|
|
|
|
|
|
|
|
//set image condition on
|
|
|
|
|
$is_image = true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
//not exists file
|
|
|
|
|
is_array($plugin_run_result = Plugins::getInstance()->run('not_exists_qr_down_file', get_defined_vars())) ? extract($plugin_run_result) : null; //run hook
|
|
|
|
|
kleeja_err($lang['FILE_NO_FOUNDED']);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//download process
|
2019-05-03 23:52:08 +03:00
|
|
|
$path_file = ig('thmb') || ig('thmbf') ? "./{$f}/thumbs/{$n}" : "./{$f}/{$n}";
|
|
|
|
|
$chunksize = 8192;
|
2023-07-23 11:20:26 +01:00
|
|
|
$resuming_on = $config['enable_multipart'] == 1;
|
2018-01-09 02:09:07 +03:00
|
|
|
|
|
|
|
|
is_array($plugin_run_result = Plugins::getInstance()->run('down_go_page', get_defined_vars())) ? extract($plugin_run_result) : null; //run hook
|
|
|
|
|
|
2019-05-03 23:52:08 +03:00
|
|
|
// this is a solution to ignore downloading through the file, redirect to the actual file
|
|
|
|
|
// where you can add 'define("MAKE_DOPHP_301_HEADER", true);' in config.php to stop the load
|
|
|
|
|
// if there is any.ead
|
2018-01-09 02:09:07 +03:00
|
|
|
if (defined('MAKE_DOPHP_301_HEADER'))
|
|
|
|
|
{
|
|
|
|
|
header('HTTP/1.1 301 Moved Permanently');
|
|
|
|
|
header('Location: ' . $path_file);
|
|
|
|
|
$SQL->close();
|
2019-05-03 23:52:08 +03:00
|
|
|
|
2018-01-09 02:09:07 +03:00
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//start download ,,
|
2019-05-03 23:52:08 +03:00
|
|
|
if (! is_readable($path_file))
|
2018-01-09 02:09:07 +03:00
|
|
|
{
|
|
|
|
|
is_array($plugin_run_result = Plugins::getInstance()->run('down_file_not_exists', get_defined_vars())) ? extract($plugin_run_result) : null; //run hook
|
|
|
|
|
|
|
|
|
|
if ($is_image)
|
|
|
|
|
{
|
|
|
|
|
$path_file = 'images/not_exists.jpg';
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
big_error($lang['FILE_NO_FOUNDED'], $lang['NOT_FOUND']);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-22 19:33:52 +03:00
|
|
|
if (! ($size = @filesize($path_file)))
|
2018-01-09 02:09:07 +03:00
|
|
|
{
|
|
|
|
|
$size = $d_size;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$name = empty($rn) ? $n : $rn;
|
|
|
|
|
|
2019-06-02 05:46:15 +03:00
|
|
|
$dots_in_name = substr_count($name, '.') - 1;
|
|
|
|
|
|
|
|
|
|
if ($dots_in_name > 0)
|
|
|
|
|
{
|
2019-06-02 06:31:02 +03:00
|
|
|
$name = preg_replace('/\./', '_', $name, $dots_in_name);
|
2019-06-02 05:46:15 +03:00
|
|
|
}
|
|
|
|
|
|
2018-01-09 02:09:07 +03:00
|
|
|
if (is_browser('mozilla'))
|
|
|
|
|
{
|
|
|
|
|
$h_name = "filename*=UTF-8''" . rawurlencode(htmlspecialchars_decode($name));
|
|
|
|
|
}
|
2019-05-03 23:52:08 +03:00
|
|
|
elseif (is_browser('opera, safari, konqueror'))
|
2018-01-09 02:09:07 +03:00
|
|
|
{
|
|
|
|
|
$h_name = 'filename="' . str_replace('"', '', htmlspecialchars_decode($name)) . '"';
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
$h_name = 'filename="' . rawurlencode(htmlspecialchars_decode($name)) . '"';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Figure out the MIME type (if not specified)
|
|
|
|
|
$ext = explode('.', $path_file);
|
|
|
|
|
$ext = array_pop($ext);
|
|
|
|
|
|
|
|
|
|
$mime_type = get_mime_for_header($ext);
|
|
|
|
|
|
|
|
|
|
|
2019-05-03 23:52:08 +03:00
|
|
|
//disable execution time limit
|
2018-01-09 02:09:07 +03:00
|
|
|
@set_time_limit(0);
|
|
|
|
|
|
2019-05-03 23:52:08 +03:00
|
|
|
//disable output buffering
|
|
|
|
|
//TODO check effectiveness
|
2018-01-09 02:09:07 +03:00
|
|
|
$level = ob_get_level();
|
|
|
|
|
while ($level > 0)
|
|
|
|
|
{
|
|
|
|
|
ob_end_clean();
|
|
|
|
|
$level--;
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-03 23:52:08 +03:00
|
|
|
if (! is_null($SQL))
|
2018-01-09 02:09:07 +03:00
|
|
|
{
|
|
|
|
|
$SQL->close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
session_write_close();
|
|
|
|
|
|
|
|
|
|
|
2019-05-03 23:52:08 +03:00
|
|
|
// required for IE, otherwise Content-Disposition may be ignored
|
|
|
|
|
if (@ini_get('zlib.output_compression'))
|
|
|
|
|
{
|
|
|
|
|
@ini_set('zlib.output_compression', 'Off');
|
|
|
|
|
}
|
2018-01-09 02:09:07 +03:00
|
|
|
|
|
|
|
|
|
2019-05-03 23:52:08 +03:00
|
|
|
//open the file
|
2018-01-09 02:09:07 +03:00
|
|
|
if (($fp = @fopen($path_file, 'rb')) === false)
|
|
|
|
|
{
|
2019-05-03 23:52:08 +03:00
|
|
|
//so ... it's failed to open !
|
|
|
|
|
header('HTTP/1.0 404 Not Found');
|
2018-01-09 02:09:07 +03:00
|
|
|
@fclose($fp);
|
|
|
|
|
big_error($lang['FILE_NO_FOUNDED'], $lang['NOT_FOUND']);
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-03 23:52:08 +03:00
|
|
|
//Unsetting all previously set headers.
|
2018-01-09 02:09:07 +03:00
|
|
|
header_remove();
|
|
|
|
|
|
|
|
|
|
is_array($plugin_run_result = Plugins::getInstance()->run('do_page_before_headers_set', get_defined_vars())) ? extract($plugin_run_result) : null; //run hook
|
|
|
|
|
|
|
|
|
|
|
2019-05-03 23:52:08 +03:00
|
|
|
//send file headers
|
2018-01-09 02:09:07 +03:00
|
|
|
header('Pragma: public');
|
2024-10-07 17:15:05 +01:00
|
|
|
|
|
|
|
|
if ($resuming_on)
|
|
|
|
|
{
|
2023-07-29 19:46:16 +01:00
|
|
|
header('Accept-Ranges: bytes');
|
2024-10-07 17:15:05 +01:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2023-07-29 19:46:16 +01:00
|
|
|
header('Accept-Ranges: none');
|
|
|
|
|
}
|
2019-05-03 23:52:08 +03:00
|
|
|
header('Content-Description: File Transfer');
|
2019-06-02 06:31:02 +03:00
|
|
|
|
|
|
|
|
//dirty fix
|
2019-06-02 20:19:01 +03:00
|
|
|
if ($ext != 'apk')
|
2019-06-02 06:31:02 +03:00
|
|
|
{
|
|
|
|
|
header("Content-Type: $mime_type");
|
|
|
|
|
}
|
2018-01-09 02:09:07 +03:00
|
|
|
header('Date: ' . gmdate('D, d M Y H:i:s', empty($ftime) ? time() : $ftime) . ' GMT');
|
2019-05-03 23:52:08 +03:00
|
|
|
//header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $ftime) . ' GMT');
|
|
|
|
|
//header('Content-Encoding: none');
|
2018-01-09 02:09:07 +03:00
|
|
|
header('Content-Disposition: ' . ($is_image || $is_live ? 'inline' : 'attachment') . '; ' . $h_name);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
is_array($plugin_run_result = Plugins::getInstance()->run('do_page_headers_set', get_defined_vars())) ? extract($plugin_run_result) : null; //run hook
|
|
|
|
|
|
|
|
|
|
|
2019-05-03 23:52:08 +03:00
|
|
|
//if(!$is_image && !$is_live && $is_ie8)
|
|
|
|
|
//{
|
2019-05-18 01:47:17 +03:00
|
|
|
// header('X-Download-Options: noopen');
|
2019-05-03 23:52:08 +03:00
|
|
|
//}
|
2018-01-09 02:09:07 +03:00
|
|
|
|
2019-05-03 23:52:08 +03:00
|
|
|
//add multipart download and resume support
|
2023-07-29 19:46:16 +01:00
|
|
|
if (isset($_SERVER['HTTP_RANGE']) && $resuming_on)
|
2018-01-09 02:09:07 +03:00
|
|
|
{
|
2023-07-29 19:46:16 +01:00
|
|
|
list($a, $range) = explode('=', $_SERVER['HTTP_RANGE'], 2);
|
|
|
|
|
list($range) = explode(',', $range, 2);
|
|
|
|
|
list($range, $range_end) = explode('-', $range, 2);
|
|
|
|
|
$range = round(floatval($range), 0);
|
|
|
|
|
$range_end = ! $range_end ? $size - 1 : round(floatval($range_end), 0);
|
2024-10-07 17:15:05 +01:00
|
|
|
|
|
|
|
|
if ($range < 0 || $range >= $size || $range > $range_end || $range_end >= $size)
|
|
|
|
|
{
|
2023-07-29 19:46:16 +01:00
|
|
|
header('HTTP/1.1 416 Requested Range Not Satisfiable');
|
|
|
|
|
header("Content-Range: bytes */$size");
|
|
|
|
|
fclose($fp);
|
2024-10-07 17:15:05 +01:00
|
|
|
|
2023-07-23 11:20:26 +01:00
|
|
|
exit;
|
|
|
|
|
}
|
2024-10-07 17:15:05 +01:00
|
|
|
|
2023-07-29 19:46:16 +01:00
|
|
|
$partial_length = $range_end - $range + 1;
|
|
|
|
|
header('HTTP/1.1 206 Partial Content');
|
|
|
|
|
header("Content-Length: $partial_length");
|
|
|
|
|
header("Content-Range: bytes $range-$range_end/$size");
|
|
|
|
|
|
|
|
|
|
fseek($fp, $range);
|
2018-01-09 02:09:07 +03:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-06-02 06:31:02 +03:00
|
|
|
header('HTTP/1.1 200 OK');
|
2018-01-09 02:09:07 +03:00
|
|
|
$partial_length = $size;
|
|
|
|
|
header("Content-Length: $partial_length");
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-03 23:52:08 +03:00
|
|
|
//output file
|
2018-01-09 02:09:07 +03:00
|
|
|
$bytes_sent = 0;
|
|
|
|
|
|
2019-05-03 23:52:08 +03:00
|
|
|
//read and output the file in chunks
|
|
|
|
|
while (! feof($fp) && (! connection_aborted()) && ($bytes_sent < $partial_length))
|
2018-01-09 02:09:07 +03:00
|
|
|
{
|
|
|
|
|
$buffer = fread($fp, $chunksize);
|
|
|
|
|
print($buffer);
|
|
|
|
|
flush();
|
|
|
|
|
$bytes_sent += strlen($buffer);
|
|
|
|
|
|
2019-05-03 23:52:08 +03:00
|
|
|
if (defined('TrottleLimit'))
|
2018-01-09 02:09:07 +03:00
|
|
|
{
|
2019-05-03 23:52:08 +03:00
|
|
|
usleep(1000000 * 0.3);
|
2018-01-09 02:09:07 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fclose($fp);
|
|
|
|
|
|
|
|
|
|
|
2019-05-03 23:52:08 +03:00
|
|
|
if (function_exists('fastcgi_finish_request'))
|
2018-01-09 02:09:07 +03:00
|
|
|
{
|
|
|
|
|
fastcgi_finish_request();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
//no one of above are there, you can use this hook to get more actions here
|
|
|
|
|
//
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-01-18 23:31:26 +03:00
|
|
|
$error = true;
|
|
|
|
|
|
2018-01-09 02:09:07 +03:00
|
|
|
is_array($plugin_run_result = Plugins::getInstance()->run('err_navig_download_page', get_defined_vars())) ? extract($plugin_run_result) : null; //run hook
|
2019-01-18 23:31:26 +03:00
|
|
|
|
2019-05-03 23:52:08 +03:00
|
|
|
if ($error)
|
2019-01-18 23:31:26 +03:00
|
|
|
{
|
|
|
|
|
kleeja_err($lang['ERROR_NAVIGATATION']);
|
|
|
|
|
}
|
2018-01-09 02:09:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
is_array($plugin_run_result = Plugins::getInstance()->run('end_download_page', get_defined_vars())) ? extract($plugin_run_result) : null; //run hook
|
|
|
|
|
|
|
|
|
|
|
2019-05-03 23:52:08 +03:00
|
|
|
//<-- EOF
|