This hack allows you, when you are going
to start a torrent, to specify the path where you want
the files downloaded.
This hack can be
enabled/disabled/configured in the admin
settings.
What you can configure is the depth of the
download folder tree. So you can choose how many levels
of subfolder you want to display.
This hack is linux
only.
First, make a backup of
index.php,
admin.php, functions.php and startpop.php, as these
files will be modified. And well, it doesn't hurt to
backup your database too.
Second, run this sql
command over your torrentflux database:
IINSERT INTO `tf_settings` ( `tf_key` ,
`tf_value` )
VALUES (
'showdirtree', '0'
),
(
'maxdepth', '0'
);
Open
functions.php and add in the end:
function dirTree2($dir,
$maxdepth)
{
echo
"<option
value=\"".$dir."\">".$dir."</option>\n"
;
if (is_numeric
($maxdepth))
{
if
($maxdepth == 0)
{
$last = exec ("du ".$dir." | cut -f 2- | sort", $retval)
;
for ($i = 1; $i <
(count ($retval) - 1); $i++)
{
echo "<option
value=\"".$retval[$i]."\">".$retval[$i]."</option>\n"
;
}
}
else if
($maxdepth > 0)
{
$last = exec ("du --max-depth=".$maxdepth." ".$dir." |
cut -f 2- | sort", $retval) ;
for ($i = 1; $i < (count ($retval) - 1);
$i++)
{
echo
"<option
value=\"".$retval[$i]."\">".$retval[$i]."</option>\n"
;
}
}
else
{
echo
"<option
value=\"".$dir."\">".$dir."</option>\n"
;
}
}
else
{
echo "<option
value=\"".$dir."\">".$dir."</option>\n"
;
}
return $retval
;
}
?>
Now open
admin.phpLine 1136, add this:
if
(isNumber(document.theForm.maxdepth.value) ==
false)
{
msg = msg + "* Max Depth must be a valid number.\n"
;
}
Go line
1545, which is </table>, and add above it:
<tr>
<td align="left" width="350"
valign="top"><strong>Show Directory
Tree</strong><br>
Show Directory Tree when you are
going to start a torrent,
allowing you to select the path where you
want
to
download the file(s).
</td>
<td valign="top">
<select
name="showdirtree">
<option
value="1">true</option>
<option value="0" <?php
if (!$cfg["showdirtree"])
{
echo "selected";
}
?>>false</option>
</select>
</td>
</tr>
<tr>
<td align="left" width="350"
valign="top"><strong>Max Depth in Directory
Tree</strong><br>
Set the max depth of subfolders in
your user directory when
displaying directory tree. Set it to 0 if
you want to
display all subfolders.
</td>
<td valign="top">
<input name="maxdepth" type="Text"
maxlength="1" value="<?php echo
($cfg["maxdepth"]); ?>" size="1">
</td>
</tr>
So now </table>
is line 1573
Open
index.phpFind the
function "StartTorrent" (line 667)
Replace it with
this one:
function
StartTorrent(name_file)
{
<?php if
($cfg["showdirtree"])
{ ?>
window.open
(name_file,'_blank','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=700,height=670')
<?php }
else
{ ?>
window.open
(name_file,'_blank','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=700,height=530')
<?php } ?>
}
Go up to line 197,
which is "$owner = getOwner($torrent);"
Add below
it:
$savepath =
getRequestVar('savepath') ;
if
(empty($savepath))
{
$savepath = $cfg['path'].$owner ;
}
Go line 285, which is
$command = "cd " . $cfg["path"] .
$owner . "; HOME=".$cfg["path"]."; export HOME; nohup "
. $pyCmd . " " .$cfg["btphpbin"] . " " .
$command;
Comment it out, and add below:
$command = "cd " . $savepath . ";
HOME=".$cfg["path"]."; export HOME; nohup " . $pyCmd . "
" .$cfg["btphpbin"] . " " . $command . " > /dev/null
&";
Finally, open
startpop.phpGo line 231 and insert:
<?php
if
($cfg["showdirtree"])
{
?>
<table>
<tr>
<td aligh="right">Save Path:</td>
<td
colspan="3"><input type="text" name="savepath"
size="45" value="<?php echo
$cfg["path"].getOwner($torrent).'/'
;?>"></td>
</tr>
<tr>
<td align="right">Or use this
path:</td>
<td colspan="3"><SELECT width="45"
size="8" ONCHANGE="savepath.value=
this.options[this.selectedIndex].value;"><?php
$arDirTree = dirTree2
($cfg["path"].getOwner($torrent).'/', $cfg["maxdepth"])
; ?></SELECT></td>
</tr>
</table>
<?php }
?>
Now, to enable the hack:
You have to enable the hack going
in Admin -> Settings, and set Show Directory Tree to
Yes
Then, when you start a torrent, you'll be able to
choose where you want to save the file in the start
torrent popup.That's all
folks!
Thanks to
Sylver for the fixes for
the hack to TF 2.1b5, I've been careful about my
copy/paste this time
And many thanks to
Qrome, for
TorrentFlux first, and to have cleaned a lot the code (I
can see a huuuge difference in startpop.php) for TF2.1
final, it makes this hack a lot easier to
implement!