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 AliasFile
26
{
27
    var $theFile;
28
 
29
    // File Properties
30
    var $running = "1";
31
    var $percent_done = "0.0";
32
    var $time_left = "";
33
    var $down_speed = "";
34
    var $up_speed = "";
35
    var $sharing = "";
36
    var $torrentowner = "";
37
    var $seeds = "";
38
    var $peers = "";
39
    var $seedlimit = "";
40
    var $uptotal = "";
41
    var $downtotal = "";
42
    var $size = "";
43
    var $errors = array();
44
 
45
    function AliasFile( $inFile, $user="" )
46
    {
47
        $this->theFile = $inFile;
48
 
49
        if ($user != "")
50
        {
51
            $this->torrentowner = $user;
52
        }
53
 
54
        if(file_exists($inFile))
55
        {
56
            // read the alias file
57
            $arStatus = file($inFile);
58
            $this->running = trim($arStatus[0]);
59
            $this->percent_done = trim($arStatus[1]);
60
            $this->time_left = trim($arStatus[2]);
61
            $this->down_speed = trim($arStatus[3]);
62
            $this->up_speed = trim($arStatus[4]);
63
            $this->torrentowner = trim($arStatus[5]);
64
            $this->seeds = trim($arStatus[6]);
65
            $this->peers = trim($arStatus[7]);
66
            $this->sharing = trim($arStatus[8]);
67
            $this->seedlimit = trim($arStatus[9]);
68
            $this->uptotal = trim($arStatus[10]);
69
            $this->downtotal = trim($arStatus[11]);
70
            $this->size = trim($arStatus[12]);
71
 
72
            if (sizeof($arStatus) > 13)
73
            {
74
                for ($inx = 13; $inx < sizeof($arStatus); $inx++)
75
                {
76
                    array_push($this->errors, $arStatus[$inx]);
77
                }
78
            }
79
        }
80
        else
81
        {
82
            // this file does not exist (yet)
83
        }
84
    }
85
 
86
    //----------------------------------------------------------------
87
    // Call this when wanting to create a new alias and/or starting it
88
    function StartTorrentFile()
89
    {
90
        // Reset all the var to new state (all but torrentowner)
91
        $this->running = "1";
92
        $this->percent_done = "0.0";
93
        $this->time_left = "Starting...";
94
        $this->down_speed = "";
95
        $this->up_speed = "";
96
        $this->sharing = "";
97
        $this->seeds = "";
98
        $this->peers = "";
99
        $this->seedlimit = "";
100
        $this->uptotal = "";
101
        $this->downtotal = "";
102
        $this->errors = array();
103
 
104
        // Write to file
105
        $this->WriteFile();
106
    }
107
 
108
    //----------------------------------------------------------------
109
    // Call this when wanting to create a new alias and/or starting it
110
    function QueueTorrentFile()
111
    {
112
        // Reset all the var to new state (all but torrentowner)
113
        $this->running = "3";
114
        $this->time_left = "Waiting...";
115
        $this->down_speed = "";
116
        $this->up_speed = "";
117
        $this->seeds = "";
118
        $this->peers = "";
119
        $this->errors = array();
120
 
121
        // Write to file
122
        $this->WriteFile();
123
    }
124
 
125
 
126
    //----------------------------------------------------------------
127
    // Common WriteFile Method
128
    function WriteFile()
129
    {
130
        $fw    = fopen($this->theFile,"w");
131
        fwrite($fw, $this->BuildOutput());
132
        fclose($fw);
133
    }
134
 
135
    //----------------------------------------------------------------
136
    // Private Function to put the variables into a string for writing to file
137
    function BuildOutput()
138
    {
139
        $output  = $this->running."\n";
140
        $output .= $this->percent_done."\n";
141
        $output .= $this->time_left."\n";
142
        $output .= $this->down_speed."\n";
143
        $output .= $this->up_speed."\n";
144
        $output .= $this->torrentowner."\n";
145
        $output .= $this->seeds."\n";
146
        $output .= $this->peers."\n";
147
        $output .= $this->sharing."\n";
148
        $output .= $this->seedlimit."\n";
149
        $output .= $this->uptotal."\n";
150
        $output .= $this->downtotal."\n";
151
        $output .= $this->size;
152
        for ($inx = 0; $inx < sizeof($this->errors); $inx++)
153
        {
154
            if ($this->errors[$inx] != "")
155
            {
156
                $output .= "\n".$this->errors[$inx];
157
            }
158
        }
159
        return $output;
160
    }
161
 
162
    //----------------------------------------------------------------
163
    // Public Function to display real total download in MB
164
    function GetRealDownloadTotal()
165
    {
166
        return (($this->percent_done * $this->size)/100)/(1024*1024);
167
    }
168
}
169
 
170
?>