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
function getFile($var)
26
{
27
    if ($var < 65535)
28
        return true;
29
    else
30
        return false;
31
}
32
 
33
//*********************************************************
34
// setPriority()
35
function setPriority($torrent)
36
{
37
    global $cfg;
38
 
39
    // we will use this to determine if we should create a prio file.
40
    // if the user passes all 1's then they want the whole thing.
41
    // so we don't need to create a prio file.
42
    // if there is a -1 in the array then they are requesting
43
    // to skip a file. so we will need to create the prio file.
44
 
45
    $okToCreate = false;
46
 
47
    if(!empty($torrent))
48
    {
49
 
50
        $alias = getAliasName($torrent);
51
        $fileName = $cfg["torrent_file_path"].$alias.".prio";
52
 
53
        $result = array();
54
 
55
        $files = array_filter($_REQUEST['files'],"getFile");
56
 
57
        // if there are files to get then process and create a prio file.
58
        if (count($files) > 0)
59
        {
60
            for($i=0;$i<getRequestVar('count');$i++)
61
            {
62
                if(in_array($i,$files))
63
                {
64
                    array_push($result,1);
65
                }
66
                else
67
                {
68
                    $okToCreate = true;
69
                    array_push($result,-1);
70
                }
71
            }
72
            $alias = getAliasName($torrent);
73
 
74
            if ($okToCreate)
75
            {
76
                $fp = fopen($fileName, "w");
77
                fwrite($fp,getRequestVar('filecount').",");
78
                fwrite($fp,implode($result,','));
79
                fclose($fp);
80
            }
81
            else
82
            {
83
                // No files to skip so must be wanting them all.
84
                // So we will remove the prio file.
85
                @unlink($fileName);
86
            }
87
        }
88
        else
89
        {
90
            // No files selected so must be wanting them all.
91
            // So we will remove the prio file.
92
            @unlink($fileName);
93
        }
94
    }
95
}
96
 
97
?>