TorrentFlux.com Hey, OppTupacShakur, you have 11 messages, 0 are new.
06-27-2007, 13:16:57
Home Help Search Profile Logout donate chat
News:


+  TorrentFlux Forums
|-+  Code Hacks and Tools
| |-+  TorrentFlux 2.1 Hacks
| | |-+  [TF21] Specific save path
« previous next »
Pages: [1] 2 3 4 Go Down Reply Notify of replies Send this topic Print
Author Topic: [TF21] Specific save path  (Read 6161 times)
coldfire
Jr. Member
**
Offline Offline

Posts: 64






View Profile Personal Message (Offline)
« on: 04-07-2006, 02:06:48 » Reply with quote

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:
Code:
IINSERT INTO `tf_settings` ( `tf_key` , `tf_value` )
VALUES (
'showdirtree', '0'
), (
'maxdepth', '0'
);

Open functions.php and add in the end:
Code:
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.php
Line 1136, add this:
Code:
        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:
Code:
        <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.php
Find the function "StartTorrent" (line 667)
Replace it with this one:
Code:
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:
Code:
    $savepath = getRequestVar('savepath') ;
    if (empty($savepath))
    {
       $savepath = $cfg['path'].$owner ;
    }

Go line 285, which is
Code:
                $command = "cd " . $cfg["path"] . $owner . "; HOME=".$cfg["path"]."; export HOME; nohup " . $pyCmd . " " .$cfg["btphpbin"] . " " . $command;
Comment it out, and add below:
Code:
                $command = "cd " . $savepath . "; HOME=".$cfg["path"]."; export HOME; nohup " . $pyCmd . " " .$cfg["btphpbin"] . " " . $command . " > /dev/null &";

Finally, open startpop.php
Go line 231 and insert:
Code:
        <?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 Smiley
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!
« Last Edit: 05-02-2006, 05:00:07 by coldfire » Report to moderator   Logged

Gentoo 2005-r1, TF 2.1 final + Specific Save Path, Multi-Upload and Page Refresh Countdown Timer hacks, 120GB dedicated to TF
kboy
Global Moderator
Jr. Member
*****
Offline Offline

Posts: 79





View Profile Personal Message (Offline)
« Reply #1 on: 04-07-2006, 17:08:56 » Reply with quote

Quote
Go line 285, which is
Code:

                $command = "cd " . $cfg["path"] . $owner . "; HOME=".$cfg["path"]."; export HOME; nohup " . $pyCmd . " " .$cfg["btphpbin"] . " " . $command;

Comment it out, and add below:
Code:

                $command = "cd " . $savepath . "; HOME=".$cfg["path"]."; export HOME; nohup " . $pyCmd . " " .$cfg["btphpbin"] . " " . $command . " > /dev/null &";

Actually I believe it should look like this.

Code:
                $command = "cd " . $savepath . "; HOME=".$cfg["path"]."; export HOME; nohup " . $pyCmd . " " .$cfg["btphpbin"] . " " . $command;

The redirect to null is not needed on this line. as it is already in the command var. from line 255
Code:
            $command .= " ".$cfg["cmd_options"]." > /dev/null &";
« Last Edit: 04-07-2006, 17:12:26 by kboy » Report to moderator   Logged
coldfire
Jr. Member
**
Offline Offline

Posts: 64






View Profile Personal Message (Offline)
« Reply #2 on: 04-08-2006, 02:22:54 » Reply with quote

You're right, this copy-paste from previous versions of this hack was perhaps too quick Wink

Nevertheless, does it work fine for you?
Report to moderator   Logged

Gentoo 2005-r1, TF 2.1 final + Specific Save Path, Multi-Upload and Page Refresh Countdown Timer hacks, 120GB dedicated to TF
JimmyTheGrunt
Newbie
*
Offline Offline

TF Base: Linux 2.x
Posts: 42





View Profile Email Personal Message (Offline)
« Reply #3 on: 04-08-2006, 10:27:38 » Reply with quote

I got it working but I might have missed/done something wrong.

I set max depth to 3 but it is still showing all the way back to /home/account/public/.

Have I done something wrong?
Report to moderator   Logged

Python 2.2.3
RHEL 3
PHP 5.0.5
MYSQL 4.1.21-standard
TF 2.1 B7
Bandi
Jr. Member
**
Offline Offline

TF Base: Linux 2.x
Posts: 87



View Profile Email Personal Message (Offline)
« Reply #4 on: 04-08-2006, 10:45:55 » Reply with quote

Nice One... It's working fine...
Report to moderator   Logged
derders
Newbie
*
Offline Offline

Posts: 16



View Profile Email Personal Message (Offline)
« Reply #5 on: 04-08-2006, 11:16:42 » Reply with quote

Can someone help me pls ?

I am very new in msql and and ...
 
Second, run this sql command over your torrentflux database:
Code:

INSERT INTO `tf_settings` ( `tf_key` , `tf_value` )
VALUES (
'showdirtree', '0'
);


ähmm what? sorry perhapse for a very newbie a step by step help :-)

thanks a lot for help
Report to moderator   Logged

Debian Sarge OS
Torrentflux 2.0beta
Xampp - for apache,mysql,php
localhost server
JimmyTheGrunt
Newbie
*
Offline Offline

TF Base: Linux 2.x
Posts: 42





View Profile Email Personal Message (Offline)
« Reply #6 on: 04-08-2006, 11:34:28 » Reply with quote

You have to run that in phpmyadmin if you have access to that part of your web site.
Report to moderator   Logged

Python 2.2.3
RHEL 3
PHP 5.0.5
MYSQL 4.1.21-standard
TF 2.1 B7
frode
Newbie
*
Offline Offline

Posts: 4



View Profile Personal Message (Offline)
« Reply #7 on: 04-08-2006, 15:49:17 » Reply with quote

I have for sure done something wrong, hope someone can help me figure out what.

In the admin setting when setting any numer 0-9 I get this error message

if (isNumber(document.theForm.maxdepth.value) == false) { msg = msg + "* Max Depth must be a valid number.\n" ; }
Report to moderator   Logged
coldfire
Jr. Member
**
Offline Offline

Posts: 64






View Profile Personal Message (Offline)
« Reply #8 on: 04-09-2006, 01:57:33 » Reply with quote

derders: yes, what it says is that you have to create a new entry in the tf_settings table, named showdirtree, with its value to 0.
And my mistake, there are two values to create, so I've edited my first post with the right sql query.
frode: your problem may be due to the fact I forgot one entry in the sql request you have to do to create the two settings fields.

New request is:

Code:
INSERT INTO `tf_settings` ( `tf_key` , `tf_value` )
VALUES (
'showdirtree', '0'
), (
'maxdepth', '0'
);

If you have already created showdirtree, just create maxdepth with
Code:
INSERT INTO `tf_settings` ( `tf_key` , `tf_value` )
VALUES (
'maxdepth', '0'
);

frode: does it fix your problem? I'm not sure it should, but, I've tested changing the depth on my TF, and I don't have this message.
Which PHP version do you have?
And make sure in admin.php, around line 1136, it now looks like this:
Code:
        if (document.theForm.maxport.value < document.theForm.minport.value)
        {
            msg = msg + "* Port Range is not valid.\n";
            document.theForm.minport.focus();
        }
        if (isNumber(document.theForm.maxdepth.value) == false)
        {
                    msg = msg + "* Max Depth must be a valid number.\n" ;
        }
        if (msg != "")
        {
            rtnValue = false;
            alert("Please check the following:\n\n" + msg);
        }
« Last Edit: 04-09-2006, 02:00:30 by coldfire » Report to moderator   Logged

Gentoo 2005-r1, TF 2.1 final + Specific Save Path, Multi-Upload and Page Refresh Countdown Timer hacks, 120GB dedicated to TF
vertex
Newbie
*
Offline Offline

Posts: 1



View Profile Personal Message (Offline)
« Reply #9 on: 04-09-2006, 02:42:03 » Reply with quote

works Cheesy . thanks i am loving TF and this great Hack
« Last Edit: 04-09-2006, 21:42:35 by vertex » Report to moderator   Logged
frode
Newbie
*
Offline Offline

Posts: 4



View Profile Personal Message (Offline)
« Reply #10 on: 04-09-2006, 06:56:51 » Reply with quote

vertex: added the sql codechange and redid the hack, working good now. Would it be possible to make it get directories on a lower level or have a list of predefined directories to choose from?

Thanks for the help and big ups for the people involded in this hack and tf! loving it!
Report to moderator   Logged
JimmyTheGrunt
Newbie
*
Offline Offline

TF Base: Linux 2.x
Posts: 42





View Profile Email Personal Message (Offline)
« Reply #11 on: 04-09-2006, 08:58:04 » Reply with quote

I checked my database and it has everything needed in it.  I have max depth set at 3 and it is still showing all the way back to root.
Report to moderator   Logged

Python 2.2.3
RHEL 3
PHP 5.0.5
MYSQL 4.1.21-standard
TF 2.1 B7
spikey
Newbie
*
Offline Offline

Posts: 1



View Profile Personal Message (Offline)
« Reply #12 on: 04-09-2006, 16:06:57 » Reply with quote

Loving the hack & TF in general!

For me seems to take a while loading the start popup, assuming this is because its gotta list the dirs. So just wondering if it easy enough to set a few predefined directories? (thinking this wont then cause the slow load)

I will try and have ago myself at some point so i'll get back to you when i get around to it Smiley

Report to moderator   Logged
coldfire
Jr. Member
**
Offline Offline

Posts: 64






View Profile Personal Message (Offline)
« Reply #13 on: 04-09-2006, 17:32:26 » Reply with quote

For a list of predefined directories, in startpop.php remove this part:

Code:
<?php $arDirTree = dirTree2 ($cfg["path"].getOwner($torrent).'/', $cfg["maxdepth"]) ; ?>

and replace it with:
Code:
<OPTION value="/path/to/folder1/">/path/to/folder1</OPTION>
<OPTION value="/path/to/folder2/">/path/to/folder2</OPTION>
<OPTION value="/path/to/folder3/">/path/to/folder3</OPTION>
You can insert these option tags just before the call to dirTree2 too, so you have these predefined pathes in the list, on top of the recursive folders listing. Now you have the choice!

vertex: download the attached files, they include the hack. But be careful, the index.php also calls "multiple upload hack" and included the countdown to refresh hack (in the end of the page it displays a countdown before the 60 seconds refresh), so make sure to download multiup.php from the multiple uploads hack.

* admin.php (83.04 KB - downloaded 28 times.)
* functions.php (81.8 KB - downloaded 24 times.)
* index.php (34.21 KB - downloaded 25 times.)
* startpop.php (9.12 KB - downloaded 29 times.)
« Last Edit: 04-09-2006, 17:34:10 by coldfire » Report to moderator   Logged

Gentoo 2005-r1, TF 2.1 final + Specific Save Path, Multi-Upload and Page Refresh Countdown Timer hacks, 120GB dedicated to TF
JimmyTheGrunt
Newbie
*
Offline Offline

TF Base: Linux 2.x
Posts: 42





View Profile Email Personal Message (Offline)
« Reply #14 on: 04-09-2006, 17:51:13 » Reply with quote

Will someone explain to me what the max depth option does?  I want to make sure I understand it correctly.
Report to moderator   Logged

Python 2.2.3
RHEL 3
PHP 5.0.5
MYSQL 4.1.21-standard
TF 2.1 B7
Pages: [1] 2 3 4 Go Up Reply Notify of replies Send this topic Print 
« previous next »
Jump to:  


Powered by MySQL Powered by SMF 1.1.1 | SMF © 2006, Simple Machines LLC Powered by PHP