PSR-4 compatible legacy code autoloading.

This commit is contained in:
Yuriy Pikhtarev 2017-05-22 22:52:41 +03:00
commit 80a035d191
No known key found for this signature in database
GPG key ID: 3A9B5A757B48ECC6
50 changed files with 5296 additions and 4522 deletions

View file

@ -52,122 +52,7 @@ if (!$tor = bdecode($file_contents)) {
return $lang['TORFILE_INVALID'];
}
$torrent = new TorrentFileList($tor);
$torrent = new TorrentPier\Legacy\TorrentFileList($tor);
$tor_filelist = $torrent->get_filelist();
$this->response['html'] = $tor_filelist;
/**
* Class TorrentFileList
*/
class TorrentFileList
{
public $tor_decoded = [];
public $files_ary = [
'/' => []
];
public $multiple = false;
public $root_dir = '';
public $files_html = '';
public function __construct($decoded_file_contents)
{
$this->tor_decoded = $decoded_file_contents;
}
public function get_filelist()
{
global $html;
$this->build_filelist_array();
if ($this->multiple) {
if ($this->files_ary['/'] !== '') {
$this->files_ary = array_merge($this->files_ary, $this->files_ary['/']);
unset($this->files_ary['/']);
}
$filelist = $html->array2html($this->files_ary);
return "<div class=\"tor-root-dir\">{$this->root_dir}</div>$filelist";
} else {
return implode('', $this->files_ary['/']);
}
}
private function build_filelist_array()
{
$info = $this->tor_decoded['info'];
if (isset($info['name.utf-8'])) {
$info['name'] =& $info['name.utf-8'];
}
if (isset($info['files']) && is_array($info['files'])) {
$this->root_dir = isset($info['name']) ? '../' . clean_tor_dirname($info['name']) : '...';
$this->multiple = true;
foreach ($info['files'] as $f) {
if (isset($f['path.utf-8'])) {
$f['path'] =& $f['path.utf-8'];
}
if (!isset($f['path']) || !is_array($f['path'])) {
continue;
}
array_deep($f['path'], 'clean_tor_dirname');
$length = isset($f['length']) ? (float)$f['length'] : 0;
$subdir_count = count($f['path']) - 1;
if ($subdir_count > 0) {
$name = array_pop($f['path']);
$cur_files_ary =& $this->files_ary;
for ($i = 0, $j = 1; $i < $subdir_count; $i++, $j++) {
$subdir = $f['path'][$i];
if (!isset($cur_files_ary[$subdir])) {
$cur_files_ary[$subdir] = array();
}
$cur_files_ary =& $cur_files_ary[$subdir];
if ($j == $subdir_count) {
if (is_string($cur_files_ary)) {
$GLOBALS['bnc_error'] = 1;
break(1);
}
$cur_files_ary[] = $this->build_file_item($name, $length);
}
}
natsort($cur_files_ary);
} else {
$name = $f['path'][0];
$this->files_ary['/'][] = $this->build_file_item($name, $length);
natsort($this->files_ary['/']);
}
}
} else {
$name = clean_tor_dirname($info['name']);
$length = (float)$info['length'];
$this->files_ary['/'][] = $this->build_file_item($name, $length);
natsort($this->files_ary['/']);
}
}
private function build_file_item($name, $length)
{
global $bb_cfg, $images, $lang;
$magnet_name = $magnet_ext = '';
if ($bb_cfg['magnet_links_enabled']) {
$magnet_name = '<a title="' . $lang['DC_MAGNET'] . '" href="dchub:magnet:?kt=' . $name . '&xl=' . $length . '"><img src="' . $images['icon_dc_magnet'] . '" width="10" height="10" border="0" /></a>';
$magnet_ext = '<a title="' . $lang['DC_MAGNET_EXT'] . '" href="dchub:magnet:?kt=.' . substr(strrchr($name, '.'), 1) . '&xl=' . $length . '"><img src="' . $images['icon_dc_magnet_ext'] . '" width="10" height="10" border="0" /></a>';
}
return "$name <i>$length</i> $magnet_name $magnet_ext";
}
}
function clean_tor_dirname($dirname)
{
return str_replace(array('[', ']', '<', '>', "'"), array('&#91;', '&#93;', '&lt;', '&gt;', '&#039;'), $dirname);
}