Собс-но, я решил данную проблему. В 1 сообщение темы можно цеплять несколько торрент-файлов, в остальные сообщения темы - нельзя цеплять ни одного торрент-файла. Естественно, работает только в тех разделах форума, которые помечены как трекер.
Для этого придется модифицировать код плагина 2.0.0826 Attachment Upload (modify torrent and info_hash), который использует хук attachdata_presave.
Вот новый код плагина:
PHP код:
if ($this->fetch_field('extension')=='torrent') {
if ($this->registry->userinfo['permissions']['vbttpermissions'] & $this->registry->bf_ugp_vbttpermissions['vbttcanview']) {
global $foruminfo, $post, $threadinfo;
if (in_array($foruminfo['forumid'], explode(',',$this->registry->options['vbtt_forums']))) {
if ($post['postid']==$threadinfo['firstpostid']) {
require_once(DIR . '/includes/benc.php');
if (!empty($this->info['filedata']))
$torrent = bdec($this->info['filedata']);
else if (!empty($this->info['filedata_location']) AND file_exists($this->info['filedata_location']))
$torrent = bdec(file_get_contents($this->info['filedata_location']));
if (isset($torrent)) {
if ($this->registry->options['vbtt_filename_template']) {
$vbttfilename=array();
if ($this->registry->options['vbtt_privateurl']=='') {
$temp=parse_url($this->registry->options['bburl']);
$vbttfilename['prefix'] = $temp['host'];
unset($temp);
}
else $vbttfilename['prefix'] = $this->registry->options['vbtt_privateurl'];
$vbttfilename['filename'] = substr($this->fetch_field('filename'),0,-8);
$vbttfilename['wo_pref'] = str_ireplace($vbttfilename['prefix'],'',$vbttfilename['filename']);
$vbttfilename['wo_pref1'] = str_ireplace('['.$vbttfilename['prefix'].']','',$vbttfilename['filename']);
$vbttfilename['rand_num'] = substr('0000000'.rand(0,99999999),-8);
$t_a = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$vbttfilename['rand_str'] = '';
for ($t_i = 0; $t_i < 8; $t_i++) $vbttfilename['rand_str'] .= $t_a[rand() % strlen($t_a)];
eval('$vbttfilename_res = "' . fetch_template('VBTT_filename_template') . '";');
$this->set('filename',$vbttfilename_res.'.torrent');
unset($vbttfilename,$t_i,$t_a,$vbttfilename_res);
}
unset($torrent['value']['announce-list']);
unset($torrent['value']['comment']);
unset($torrent['value']['nodes']);
if (!in_array($foruminfo['forumid'], explode(',',$this->registry->options['vbtt_private_disable_forums']))) {
// unset($torrent['value']['info']['value']['publisher']);
// unset($torrent['value']['info']['value']['publisher-url']);
unset($torrent['value']['info']['value']['privateurl']);
unset($torrent['value']['info']['value']['private']);
if ($this->registry->options['vbtt_private_setting'])
$torrent['value']['info']['value']['private']=bdec('i1e');
if ($this->registry->options['vbtt_privateurl_ts'])
$this->registry->options['vbtt_privateurl'].=TIMENOW;
if ($this->registry->options['vbtt_privateurl']!='')
$torrent['value']['info']['value']['privateurl']=bdec(benc_str($this->registry->options['vbtt_privateurl']));
}
// $this->info['filedata']=benc($torrent);
// $this->verify_filedata($this->info['filedata']);
$this->set_info('filedata',benc($torrent));
$torrent = bdec($this->info['filedata']);
$info_hash=pack('H*', sha1($torrent['value']['info']['string']));
$this->set('info_hash',$info_hash);
if ($info_hash) {
if ($torrent['value']['info']['value']['length']) {
$this->torfiles[]=Array('name'=>$torrent['value']['info']['value']['name']['value'], 'size' => $torrent['value']['info']['value']['length']['value']);
$this->set('size',$torrent['value']['info']['value']['length']['value']);
}
else {
$bt_size = 0;
foreach ($torrent['value']['info']['value']['files']['value'] as $bt_file) {
$bt_name = '';
foreach ($bt_file['value']['path']['value'] as $bt_a)
$bt_name .= '/' . $bt_a['value'];
$this->torfiles[]=Array('name'=>$bt_name, 'size' => $bt_file['value']['length']['value']);
$bt_size += (float) $bt_file['value']['length']['value'];
}
$this->set('size',$bt_size);
unset($bt_size,$bt_name,$bt_a,$bt_file);
}
$this->set('mtime',TIMENOW);
if ($this->save_torrent) $this->torrent=$torrent;
if ($this->save_infohash) $this->torrent_info=$torrent['value']['info']['string'];
}
unset($torrent,$info_hash);
}
}
else
{
$this->error('upload_invalid_file');
}
} else {
$this->error('vbtt_disabled_forum');
}
}
else {
$this->error('upload_invalid_file');
}
if (sizeof($this->errors)) $return_value = false;
}
У данного метода есть один минус: при редактировании первого сообщения темы добавить туда торрент уже не получится. Всё делается только при создании.
|