Subversion Repositories svnkaklik

Rev

Details | Last modification | View Log

Rev Author Line No. Line
36 kaklik 1
<?php
2
 
3
/*************************************************************
4
*  TorrentFlux - PHP Torrent Manager
5
*  www.torrentflux.com
6
**************************************************************/
7
/*
8
    This file is part of TorrentFlux.
9
 
10
    TorrentFlux is free software; you can redistribute it and/or modify
11
    it under the terms of the GNU General Public License as published by
12
    the Free Software Foundation; either version 2 of the License, or
13
    (at your option) any later version.
14
 
15
    TorrentFlux is distributed in the hope that it will be useful,
16
    but WITHOUT ANY WARRANTY; without even the implied warranty of
17
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
    GNU General Public License for more details.
19
 
20
    You should have received a copy of the GNU General Public License
21
    along with TorrentFlux; if not, write to the Free Software
22
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23
*/
24
 
25
class dir
26
{
27
    var $name;
28
    var $subdirs;
29
    var $files;
30
    var $num;
31
    var $prio;
32
 
33
    function dir($name,$num,$prio)
34
    {
35
        $this->name = $name;
36
        $this->num = $num;
37
        $this->prio = $prio;
38
        $this->files = array();
39
        $this->subdirs = array();
40
    }
41
 
42
    function &addFile($file)
43
    {
44
        $this->files[] =& $file;
45
        return $file;
46
    }
47
 
48
    function &addDir($dir)
49
    {
50
        $this->subdirs[] =& $dir;
51
        return $dir;
52
    }
53
 
54
    // code changed to support php4
55
    // thx to Mistar Muffin
56
    function &findDir($name)
57
    {
58
        foreach (array_keys($this->subdirs) as $v)
59
        {
60
            $dir =& $this->subdirs[$v];
61
            if($dir->name == $name)
62
            {
63
                return $dir;
64
            }
65
        }
66
        return false;
67
    }
68
 
69
    function draw($parent)
70
    {
71
        echo("d.add(".$this->num.",".$parent.",\"".$this->name."\",".$this->prio.",0);\n");
72
 
73
        foreach($this->subdirs as $v)
74
        {
75
            $v->draw($this->num);
76
        }
77
 
78
        foreach($this->files as $v)
79
        {
80
            if(is_object($v))
81
            {
82
              echo("d.add(".$v->num.",".$this->num.",\"".$v->name."\",".$v->prio.",".$v->size.");\n");
83
            }
84
        }
85
    }
86
 
87
}
88
 
89
class file {
90
 
91
    var $name;
92
    var $prio;
93
    var $size;
94
    var $num;
95
 
96
    function file($name,$num,$size,$prio)
97
    {
98
        $this->name = $name;
99
        $this->num  = $num;
100
        $this->size = $size;
101
        $this->prio = $prio;
102
    }
103
}
104
 
105
function showMetaInfo($torrent, $allowSave=false)
106
{
107
    global $cfg;
108
 
109
    if (empty($torrent))
110
    {
111
        echo _NORECORDSFOUND;
112
    }
113
    elseif ($cfg["enable_file_priority"])
114
    {
115
 
116
        $prioFileName = $cfg["torrent_file_path"].getAliasName($torrent).".prio";
117
 
118
        require_once('BDecode.php');
119
 
120
        echo '<link rel="StyleSheet" href="dtree.css" type="text/css" /><script type="text/javascript" src="dtree.js"></script>';
121
 
122
        $ftorrent=$cfg["torrent_file_path"].$torrent;
123
 
124
        $fp = fopen($ftorrent, "rd");
125
        $alltorrent = fread($fp, filesize($ftorrent));
126
        fclose($fp);
127
 
128
        $btmeta = BDecode($alltorrent);
129
        $torrent_size = $btmeta["info"]["piece length"] * (strlen($btmeta["info"]["pieces"]) / 20);
130
 
131
        if (array_key_exists('files',$btmeta['info']))
132
        {
133
            $dirnum = count($btmeta['info']['files']);
134
        }
135
        else
136
        {
137
            $dirnum = 0;
138
        }
139
 
140
        if ( is_readable($prioFileName))
141
        {
142
            $prio = split(',',file_get_contents($prioFileName));
143
            $prio = array_splice($prio,1);
144
        }
145
        else
146
        {
147
            $prio = array();
148
            for($i=0;$i<$dirnum;$i++)
149
            {
150
                $prio[$i] = -1;
151
            }
152
        }
153
 
154
        $tree = new dir("/",$dirnum,isset($prio[$dirnum])?$prio[$dirnum]:-1);
155
 
156
        if (array_key_exists('files',$btmeta['info']))
157
        {
158
            foreach( $btmeta['info']['files'] as $filenum => $file)
159
            {
160
 
161
                $depth = count($file['path']);
162
                $branch =& $tree;
163
 
164
                for($i=0; $i < $depth; $i++)
165
                {
166
                    if ($i != $depth-1)
167
                    {
168
                        $d =& $branch->findDir($file['path'][$i]);
169
 
170
                        if($d)
171
                        {
172
                            $branch =& $d;
173
                        }
174
                        else
175
                        {
176
                            $dirnum++;
177
                            $d =& $branch->addDir(new dir($file['path'][$i], $dirnum, (isset($prio[$dirnum])?$prio[$dirnum]:-1)));
178
                            $branch =& $d;
179
                        }
180
                    }
181
                    else
182
                    {
183
                        $branch->addFile(new file($file['path'][$i]." (".$file['length'].")",$filenum,$file['length'],$prio[$filenum]));
184
                    }
185
 
186
                }
187
            }
188
        }
189
 
190
        echo "<table><tr>";
191
        echo "<tr><td width=\"110\">Metainfo File:</td><td>".$torrent."</td></tr>";
192
        echo "<tr><td>Directory Name:</td><td>".$btmeta['info']['name']."</td></tr>";
193
        echo "<tr><td>Announce URL:</td><td>".$btmeta['announce']."</td></tr>";
194
 
195
        if(array_key_exists('comment',$btmeta))
196
        {
197
            echo "<tr><td valign=\"top\">Comment:</td><td>".$btmeta['comment']."</td></tr>";
198
        }
199
 
200
        echo "<tr><td>Created:</td><td>".date("F j, Y, g:i a",$btmeta['creation date'])."</td></tr>";
201
        echo "<tr><td>Torrent Size:</td><td>".$torrent_size." (".formatBytesToKBMGGB($torrent_size).")</td></tr>";
202
        echo "<tr><td>Chunk size:</td><td>".$btmeta['info']['piece length']." (".formatBytesToKBMGGB($btmeta['info']['piece length']).")</td></tr>";
203
 
204
        if (array_key_exists('files',$btmeta['info']))
205
        {
206
 
207
            echo "<tr><td>Selected size:</td><td id=\"sel\">0</td></tr>";
208
            echo "</table><br>\n";
209
 
210
            if ($allowSave)
211
            {
212
                echo "<form name=\"priority\" action=\"index.php\" method=\"POST\" >";
213
                echo "<input type=\"hidden\" name=\"torrent\" value=\"".$torrent."\" >";
214
                echo "<input type=\"hidden\" name=\"setPriorityOnly\" value=\"true\" >";
215
            }
216
 
217
            echo "<script type=\"text/javascript\">\n";
218
            echo "var sel = 0;\n";
219
            echo "d = new dTree('d');\n";
220
 
221
            $tree->draw(-1);
222
 
223
            echo "document.write(d);\n";
224
            echo "sel = getSizes();\n";
225
            echo "drawSel();\n";
226
            echo "</script>\n";
227
 
228
            echo "<input type=\"hidden\" name=\"filecount\" value=\"".count($btmeta['info']['files'])."\">";
229
            echo "<input type=\"hidden\" name=\"count\" value=\"".$dirnum."\">";
230
            echo "<br>";
231
            if ($allowSave)
232
            {
233
                echo '<input type="submit" value="Save" >';
234
                echo "<br>";
235
            }
236
            echo "</form>";
237
        }
238
        else
239
        {
240
            echo "</table><br>";
241
            echo $btmeta['info']['name'].$torrent_size." (".formatBytesToKBMGGB($torrent_size).")";
242
        }
243
    }
244
    else
245
    {
246
        $result = shell_exec("cd " . $cfg["torrent_file_path"]."; " . $cfg["pythonCmd"] . " -OO " . $cfg["btshowmetainfo"]." \"".$torrent."\"");
247
        echo "<pre>";
248
        echo $result;
249
        echo "</pre>";
250
    }
251
}
252
?>