Browse Source

Prep for public tracker and web seed support

pjc 5 years ago
parent
commit
a97f793ba7
4 changed files with 386 additions and 354 deletions
  1. 84
    76
      classes/bencode.class.php
  2. 148
    138
      classes/bencodedecode.class.php
  3. 145
    132
      classes/bencodetorrent.class.php
  4. 9
    8
      static/styles/oppai/style.css

+ 84
- 76
classes/bencode.class.php View File

1
-<?
1
+<?php
2
 /**
2
 /**
3
  * If we're running a 32bit PHP version, we use small objects to store ints.
3
  * If we're running a 32bit PHP version, we use small objects to store ints.
4
  * Overhead from the function calls is small enough to not worry about
4
  * Overhead from the function calls is small enough to not worry about
5
  */
5
  */
6
-class Int64 {
7
-  private $Num;
6
+class Int64
7
+{
8
+    private $Num;
8
 
9
 
9
-  public function __construct($Val) {
10
-    $this->Num = $Val;
11
-  }
10
+    public function __construct($Val)
11
+    {
12
+        $this->Num = $Val;
13
+    }
12
 
14
 
13
-  public static function make($Val) {
14
-    return PHP_INT_SIZE === 4 ? new Int64($Val) : (int)$Val;
15
-  }
15
+    public static function make($Val)
16
+    {
17
+        return PHP_INT_SIZE === 4 ? new Int64($Val) : (int)$Val;
18
+    }
16
 
19
 
17
-  public static function get($Val) {
18
-    return PHP_INT_SIZE === 4 ? $Val->Num : $Val;
19
-  }
20
+    public static function get($Val)
21
+    {
22
+        return PHP_INT_SIZE === 4 ? $Val->Num : $Val;
23
+    }
20
 
24
 
21
-  public static function is_int($Val) {
22
-    return is_int($Val) || (is_object($Val) && get_class($Val) === 'Int64');
23
-  }
25
+    public static function is_int($Val)
26
+    {
27
+        return is_int($Val) || (is_object($Val) && get_class($Val) === 'Int64');
28
+    }
24
 }
29
 }
25
 
30
 
26
 /**
31
 /**
27
  * The encode class is simple and straightforward. The only thing to
32
  * The encode class is simple and straightforward. The only thing to
28
  * note is that empty dictionaries are represented by boolean trues
33
  * note is that empty dictionaries are represented by boolean trues
29
  */
34
  */
30
-class Bencode {
31
-  private $DefaultKeys = array( // Get rid of everything except these keys to save some space
35
+class Bencode
36
+{
37
+    private $DefaultKeys = array( // Get rid of everything except these keys to save some space
32
       'created by', 'creation date', 'encoding', 'info', 'comment');
38
       'created by', 'creation date', 'encoding', 'info', 'comment');
33
-  private $Data;
34
-  public $Enc;
39
+    private $Data;
40
+    public $Enc;
35
 
41
 
36
-  /**
37
-   * Encode an arbitrary array (usually one that's just been decoded)
38
-   *
39
-   * @param array $Arg the thing to encode
40
-   * @param mixed $Keys string or array with keys in the input array to encode or true to encode everything
41
-   * @return bencoded string representing the content of the input array
42
-   */
43
-  public function encode($Arg = false, $Keys = false) {
44
-    if ($Arg === false) {
45
-      $Data =& $this->Dec;
46
-    } else {
47
-      $Data =& $Arg;
42
+    /**
43
+     * Encode an arbitrary array (usually one that's just been decoded)
44
+     *
45
+     * @param array $Arg the thing to encode
46
+     * @param mixed $Keys string or array with keys in the input array to encode or true to encode everything
47
+     * @return bencoded string representing the content of the input array
48
+     */
49
+    public function encode($Arg = false, $Keys = false)
50
+    {
51
+        if ($Arg === false) {
52
+            $Data =& $this->Dec;
53
+        } else {
54
+            $Data =& $Arg;
55
+        }
56
+        if ($Keys === true) {
57
+            $this->Data = $Data;
58
+        } elseif ($Keys === false) {
59
+            $this->Data = array_intersect_key($Data, array_flip($this->DefaultKeys));
60
+        } elseif (is_array($Keys)) {
61
+            $this->Data = array_intersect_key($Data, array_flip($Keys));
62
+        } else {
63
+            $this->Data = isset($Data[$Keys]) ? $Data[$Keys] : false;
64
+        }
65
+        if (!$this->Data) {
66
+            return false;
67
+        }
68
+        $this->Enc = $this->_benc();
69
+        return $this->Enc;
48
     }
70
     }
49
-    if ($Keys === true) {
50
-      $this->Data = $Data;
51
-    } elseif ($Keys === false) {
52
-      $this->Data = array_intersect_key($Data, array_flip($this->DefaultKeys));
53
-    } elseif (is_array($Keys)) {
54
-      $this->Data = array_intersect_key($Data, array_flip($Keys));
55
-    } else {
56
-      $this->Data = isset($Data[$Keys]) ? $Data[$Keys] : false;
57
-    }
58
-    if (!$this->Data) {
59
-      return false;
60
-    }
61
-    $this->Enc = $this->_benc();
62
-    return $this->Enc;
63
-  }
64
 
71
 
65
-  /**
66
-   * Internal encoding function that does the actual job
67
-   *
68
-   * @return bencoded string
69
-   */
70
-  private function _benc() {
71
-    if (!is_array($this->Data)) {
72
-      if (Int64::is_int($this->Data)) { // Integer
73
-        return 'i'.Int64::get($this->Data).'e';
74
-      }
75
-      if ($this->Data === true) { // Empty dictionary
76
-        return 'de';
77
-      }
78
-      return strlen($this->Data).':'.$this->Data; // String
79
-    }
80
-    if (empty($this->Data) || Int64::is_int(key($this->Data))) {
81
-      $IsDict = false;
82
-    } else {
83
-      $IsDict = true;
84
-      ksort($this->Data); // Dictionaries must be sorted
85
-    }
86
-    $Ret = $IsDict ? 'd' : 'l';
87
-    foreach ($this->Data as $Key => $Value) {
88
-      if ($IsDict) {
89
-        $Ret .= strlen($Key).':'.$Key;
90
-      }
91
-      $this->Data = $Value;
92
-      $Ret .= $this->_benc();
72
+    /**
73
+     * Internal encoding function that does the actual job
74
+     *
75
+     * @return bencoded string
76
+     */
77
+    private function _benc()
78
+    {
79
+        if (!is_array($this->Data)) {
80
+            if (Int64::is_int($this->Data)) { // Integer
81
+                return 'i'.Int64::get($this->Data).'e';
82
+            }
83
+            if ($this->Data === true) { // Empty dictionary
84
+                return 'de';
85
+            }
86
+            return strlen($this->Data).':'.$this->Data; // String
87
+        }
88
+        if (empty($this->Data) || Int64::is_int(key($this->Data))) {
89
+            $IsDict = false;
90
+        } else {
91
+            $IsDict = true;
92
+            ksort($this->Data); // Dictionaries must be sorted
93
+        }
94
+        $Ret = $IsDict ? 'd' : 'l';
95
+        foreach ($this->Data as $Key => $Value) {
96
+            if ($IsDict) {
97
+                $Ret .= strlen($Key).':'.$Key;
98
+            }
99
+            $this->Data = $Value;
100
+            $Ret .= $this->_benc();
101
+        }
102
+        return $Ret.'e';
93
     }
103
     }
94
-    return $Ret.'e';
95
-  }
96
 }
104
 }

+ 148
- 138
classes/bencodedecode.class.php View File

1
-<?
1
+<?php
2
 /**
2
 /**
3
  * The decode class is simple and straightforward. The only thing to
3
  * The decode class is simple and straightforward. The only thing to
4
  * note is that empty dictionaries are represented by boolean trues
4
  * note is that empty dictionaries are represented by boolean trues
5
  */
5
  */
6
-class BencodeDecode extends Bencode {
7
-  private $Data;
8
-  private $Length;
9
-  private $Pos = 0;
10
-  public $Dec = [];
11
-  public $ExitOnError = true;
12
-  const SnipLength = 40;
6
+class BencodeDecode extends Bencode
7
+{
8
+    private $Data;
9
+    private $Length;
10
+    private $Pos = 0;
11
+    public $Dec = [];
12
+    public $ExitOnError = true;
13
+    const SnipLength = 40;
13
 
14
 
14
-  /**
15
-   * Decode prepararations
16
-   *
17
-   * @param string $Arg bencoded string or path to bencoded file to decode
18
-   * @param bool $IsPath needs to be true if $Arg is a path
19
-   * @return decoded data with a suitable structure
20
-   */
21
-  function __construct($Arg = false, $IsPath = false, $Strict = true) {
22
-    if (!$Strict) {
23
-      $this->ExitOnError = false;
24
-    }
25
-    if ($Arg === false) {
26
-      if (empty($this->Enc)) {
27
-        return false;
28
-      }
29
-    } else {
30
-      if ($IsPath === true) {
31
-        return $this->bdec_file($Arg);
32
-      }
33
-      $this->Data = $Arg;
15
+    /**
16
+     * Decode prepararations
17
+     *
18
+     * @param string $Arg bencoded string or path to bencoded file to decode
19
+     * @param bool $IsPath needs to be true if $Arg is a path
20
+     * @return decoded data with a suitable structure
21
+     */
22
+    public function __construct($Arg = false, $IsPath = false, $Strict = true)
23
+    {
24
+        if (!$Strict) {
25
+            $this->ExitOnError = false;
26
+        }
27
+        if ($Arg === false) {
28
+            if (empty($this->Enc)) {
29
+                return false;
30
+            }
31
+        } else {
32
+            if ($IsPath === true) {
33
+                return $this->bdec_file($Arg);
34
+            }
35
+            $this->Data = $Arg;
36
+        }
37
+        return $this->decode();
34
     }
38
     }
35
-    return $this->decode();
36
-  }
37
 
39
 
38
-  /**
39
-   * Decodes a bencoded file
40
-   *
41
-   * @param $Path path to bencoded file to decode
42
-   * @return decoded data with a suitable structure
43
-   */
44
-  public function bdec_file($Path = false) {
45
-    if (empty($Path)) {
46
-      return false;
47
-    }
48
-    if (!$this->Data = @file_get_contents($Path, FILE_BINARY)) {
49
-      return $this->error("Error: file '$Path' could not be opened.\n");
40
+    /**
41
+     * Decodes a bencoded file
42
+     *
43
+     * @param $Path path to bencoded file to decode
44
+     * @return decoded data with a suitable structure
45
+     */
46
+    public function bdec_file($Path = false)
47
+    {
48
+        if (empty($Path)) {
49
+            return false;
50
+        }
51
+        if (!$this->Data = @file_get_contents($Path, FILE_BINARY)) {
52
+            return $this->error("Error: file '$Path' could not be opened.\n");
53
+        }
54
+        return $this->decode();
50
     }
55
     }
51
-    return $this->decode();
52
-  }
53
 
56
 
54
-  /**
55
-   * Decodes a string with bencoded data
56
-   *
57
-   * @param mixed $Arg bencoded data or false to decode the content of $this->Data
58
-   * @return decoded data with a suitable structure
59
-   */
60
-  public function decode($Arg = false) {
61
-    if ($Arg !== false) {
62
-      $this->Data = $Arg;
63
-    } elseif (!$this->Data) {
64
-      $this->Data = $this->Enc;
65
-    }
66
-    if (!$this->Data) {
67
-      return false;
68
-    }
69
-    $this->Length = strlen($this->Data);
70
-    $this->Pos = 0;
71
-    $this->Dec = $this->_bdec();
72
-    if ($this->Pos < $this->Length) {
73
-      // Not really necessary, but if the torrent is invalid, it's better to warn than to silently truncate it
74
-      return $this->error();
57
+    /**
58
+     * Decodes a string with bencoded data
59
+     *
60
+     * @param mixed $Arg bencoded data or false to decode the content of $this->Data
61
+     * @return decoded data with a suitable structure
62
+     */
63
+    public function decode($Arg = false)
64
+    {
65
+        if ($Arg !== false) {
66
+            $this->Data = $Arg;
67
+        } elseif (!$this->Data) {
68
+            $this->Data = $this->Enc;
69
+        }
70
+        if (!$this->Data) {
71
+            return false;
72
+        }
73
+        $this->Length = strlen($this->Data);
74
+        $this->Pos = 0;
75
+        $this->Dec = $this->_bdec();
76
+        if ($this->Pos < $this->Length) {
77
+            // Not really necessary, but if the torrent is invalid, it's better to warn than to silently truncate it
78
+            return $this->error();
79
+        }
80
+        return $this->Dec;
75
     }
81
     }
76
-    return $this->Dec;
77
-  }
78
 
82
 
79
-  /**
80
-   * Internal decoding function that does the actual job
81
-   *
82
-   * @return decoded data with a suitable structure
83
-   */
84
-  private function _bdec() {
85
-    switch ($this->Data[$this->Pos]) {
83
+    /**
84
+     * Internal decoding function that does the actual job
85
+     *
86
+     * @return decoded data with a suitable structure
87
+     */
88
+    private function _bdec()
89
+    {
90
+        switch ($this->Data[$this->Pos]) {
86
 
91
 
87
       case 'i':
92
       case 'i':
88
         $this->Pos++;
93
         $this->Pos++;
89
         $Value = substr($this->Data, $this->Pos, strpos($this->Data, 'e', $this->Pos) - $this->Pos);
94
         $Value = substr($this->Data, $this->Pos, strpos($this->Data, 'e', $this->Pos) - $this->Pos);
90
         if (!ctype_digit($Value) && !($Value[0] == '-' && ctype_digit(substr($Value, 1)))) {
95
         if (!ctype_digit($Value) && !($Value[0] == '-' && ctype_digit(substr($Value, 1)))) {
91
-          return $this->error();
96
+            return $this->error();
92
         }
97
         }
93
         $this->Pos += strlen($Value) + 1;
98
         $this->Pos += strlen($Value) + 1;
94
         return Int64::make($Value);
99
         return Int64::make($Value);
97
         $Value = [];
102
         $Value = [];
98
         $this->Pos++;
103
         $this->Pos++;
99
         while ($this->Data[$this->Pos] != 'e') {
104
         while ($this->Data[$this->Pos] != 'e') {
100
-          if ($this->Pos >= $this->Length) {
101
-            return $this->error();
102
-          }
103
-          $Value[] = $this->_bdec();
105
+            if ($this->Pos >= $this->Length) {
106
+                return $this->error();
107
+            }
108
+            $Value[] = $this->_bdec();
104
         }
109
         }
105
         $this->Pos++;
110
         $this->Pos++;
106
         return $Value;
111
         return $Value;
109
         $Value = [];
114
         $Value = [];
110
         $this->Pos++;
115
         $this->Pos++;
111
         while ($this->Data[$this->Pos] != 'e') {
116
         while ($this->Data[$this->Pos] != 'e') {
112
-          $Length = substr($this->Data, $this->Pos, strpos($this->Data, ':', $this->Pos) - $this->Pos);
113
-          if (!ctype_digit($Length)) {
114
-            return $this->error();
115
-          }
116
-          $this->Pos += strlen($Length) + $Length + 1;
117
-          $Key = substr($this->Data, $this->Pos - $Length, $Length);
118
-          if ($this->Pos >= $this->Length) {
119
-            return $this->error();
120
-          }
121
-          $Value[$Key] = $this->_bdec();
117
+            $Length = substr($this->Data, $this->Pos, strpos($this->Data, ':', $this->Pos) - $this->Pos);
118
+            if (!ctype_digit($Length)) {
119
+                return $this->error();
120
+            }
121
+            $this->Pos += strlen($Length) + $Length + 1;
122
+            $Key = substr($this->Data, $this->Pos - $Length, $Length);
123
+            if ($this->Pos >= $this->Length) {
124
+                return $this->error();
125
+            }
126
+            $Value[$Key] = $this->_bdec();
122
         }
127
         }
123
         $this->Pos++;
128
         $this->Pos++;
124
         // Use boolean true to keep track of empty dictionaries
129
         // Use boolean true to keep track of empty dictionaries
127
       default:
132
       default:
128
         $Length = substr($this->Data, $this->Pos, strpos($this->Data, ':', $this->Pos) - $this->Pos);
133
         $Length = substr($this->Data, $this->Pos, strpos($this->Data, ':', $this->Pos) - $this->Pos);
129
         if (!ctype_digit($Length)) {
134
         if (!ctype_digit($Length)) {
130
-          return $this->error(); // Even if the string is likely to be decoded correctly without this check, it's malformed
135
+            return $this->error(); // Even if the string is likely to be decoded correctly without this check, it's malformed
131
         }
136
         }
132
         $this->Pos += strlen($Length) + $Length + 1;
137
         $this->Pos += strlen($Length) + $Length + 1;
133
         return substr($this->Data, $this->Pos - $Length, $Length);
138
         return substr($this->Data, $this->Pos - $Length, $Length);
134
     }
139
     }
135
-  }
136
-
137
-  /**
138
-   * Convert everything to the correct data types and optionally escape strings
139
-   *
140
-   * @param bool $Escape whether to escape the textual data
141
-   * @param mixed $Data decoded data or false to use the $Dec property
142
-   * @return decoded data with more useful data types
143
-   */
144
-  public function dump($Escape = true, $Data = false) {
145
-    if ($Data === false) {
146
-      $Data = $this->Dec;
147
-    }
148
-    if (Int64::is_int($Data)) {
149
-      return Int64::get($Data);
150
     }
140
     }
151
-    if (is_bool($Data)) {
152
-      return [];
153
-    }
154
-    if (is_array($Data)) {
155
-      $Output = [];
156
-      foreach ($Data as $Key => $Val) {
157
-        $Output[$Key] = $this->dump($Escape, $Val);
158
-      }
159
-      return $Output;
160
-    }
161
-    return $Escape ? htmlentities($Data) : $Data;
162
-  }
163
 
141
 
164
-  /**
165
-   * Display an error and halt the operation unless the $ExitOnError property is false
166
-   *
167
-   * @param string $ErrMsg the error message to display
168
-   */
169
-  private function error($ErrMsg = false) {
170
-    static $ErrorPos;
171
-    if ($this->Pos === $ErrorPos) {
172
-      // The recursive nature of the class requires this to avoid duplicate error messages
173
-      return false;
142
+    /**
143
+     * Convert everything to the correct data types and optionally escape strings
144
+     *
145
+     * @param bool $Escape whether to escape the textual data
146
+     * @param mixed $Data decoded data or false to use the $Dec property
147
+     * @return decoded data with more useful data types
148
+     */
149
+    public function dump($Escape = true, $Data = false)
150
+    {
151
+        if ($Data === false) {
152
+            $Data = $this->Dec;
153
+        }
154
+        if (Int64::is_int($Data)) {
155
+            return Int64::get($Data);
156
+        }
157
+        if (is_bool($Data)) {
158
+            return [];
159
+        }
160
+        if (is_array($Data)) {
161
+            $Output = [];
162
+            foreach ($Data as $Key => $Val) {
163
+                $Output[$Key] = $this->dump($Escape, $Val);
164
+            }
165
+            return $Output;
166
+        }
167
+        return $Escape ? htmlentities($Data) : $Data;
174
     }
168
     }
175
-    if ($this->ExitOnError) {
176
-      if ($ErrMsg === false) {
177
-        printf("Malformed string. Invalid character at pos 0x%X: %s\n",
178
-            $this->Pos, str_replace(array("\r","\n"), array('',' '), htmlentities(substr($this->Data, $this->Pos, self::SnipLength))));
179
-      } else {
180
-        echo $ErrMsg;
181
-      }
182
-      exit();
169
+
170
+    /**
171
+     * Display an error and halt the operation unless the $ExitOnError property is false
172
+     *
173
+     * @param string $ErrMsg the error message to display
174
+     */
175
+    private function error($ErrMsg = false)
176
+    {
177
+        static $ErrorPos;
178
+        if ($this->Pos === $ErrorPos) {
179
+            // The recursive nature of the class requires this to avoid duplicate error messages
180
+            return false;
181
+        }
182
+        if ($this->ExitOnError) {
183
+            if ($ErrMsg === false) {
184
+                printf(
185
+                    "Malformed string. Invalid character at pos 0x%X: %s\n",
186
+                    $this->Pos,
187
+                    str_replace(array("\r","\n"), array('',' '), htmlentities(substr($this->Data, $this->Pos, self::SnipLength)))
188
+                );
189
+            } else {
190
+                echo $ErrMsg;
191
+            }
192
+            exit();
193
+        }
194
+        $ErrorPos = $this->Pos;
195
+        return false;
183
     }
196
     }
184
-    $ErrorPos = $this->Pos;
185
-    return false;
186
-  }
187
 }
197
 }

+ 145
- 132
classes/bencodetorrent.class.php View File

1
-<?
1
+<?php
2
 /**
2
 /**
3
  * Torrent class that contains some convenient functions related to torrent meta data
3
  * Torrent class that contains some convenient functions related to torrent meta data
4
  */
4
  */
5
-class BencodeTorrent extends BencodeDecode {
6
-  private $PathKey = 'path';
7
-  public $Files = [];
8
-  public $Size = 0;
5
+class BencodeTorrent extends BencodeDecode
6
+{
7
+    private $PathKey = 'path';
8
+    public $Files = [];
9
+    public $Size = 0;
9
 
10
 
10
-  /**
11
-   * Create a list of the files in the torrent and their sizes as well as the total torrent size
12
-   *
13
-   * @return array with a list of files and file sizes
14
-   */
15
-  public function file_list() {
16
-    if (empty($this->Dec)) {
17
-      return false;
18
-    }
19
-    $InfoDict =& $this->Dec['info'];
20
-    if (!isset($InfoDict['files'])) {
21
-      // Single-file torrent
22
-      $this->Size = (Int64::is_int($InfoDict['length'])
11
+    /**
12
+     * Create a list of the files in the torrent and their sizes as well as the total torrent size
13
+     *
14
+     * @return array with a list of files and file sizes
15
+     */
16
+    public function file_list()
17
+    {
18
+        if (empty($this->Dec)) {
19
+            return false;
20
+        }
21
+        $InfoDict =& $this->Dec['info'];
22
+        if (!isset($InfoDict['files'])) {
23
+            // Single-file torrent
24
+            $this->Size = (Int64::is_int($InfoDict['length'])
23
         ? Int64::get($InfoDict['length'])
25
         ? Int64::get($InfoDict['length'])
24
         : $InfoDict['length']);
26
         : $InfoDict['length']);
25
-      $Name = (isset($InfoDict['name.utf-8'])
27
+            $Name = (isset($InfoDict['name.utf-8'])
26
         ? $InfoDict['name.utf-8']
28
         ? $InfoDict['name.utf-8']
27
         : $InfoDict['name']);
29
         : $InfoDict['name']);
28
-      $this->Files[] = array($this->Size, $Name);
29
-    } else {
30
-      if (isset($InfoDict['path.utf-8']['files'][0])) {
31
-        $this->PathKey = 'path.utf-8';
32
-      }
33
-      foreach ($InfoDict['files'] as $File) {
34
-        $TmpPath = [];
35
-        foreach ($File[$this->PathKey] as $SubPath) {
36
-          $TmpPath[] = $SubPath;
37
-        }
38
-        $CurSize = (Int64::is_int($File['length'])
30
+            $this->Files[] = array($this->Size, $Name);
31
+        } else {
32
+            if (isset($InfoDict['path.utf-8']['files'][0])) {
33
+                $this->PathKey = 'path.utf-8';
34
+            }
35
+            foreach ($InfoDict['files'] as $File) {
36
+                $TmpPath = [];
37
+                foreach ($File[$this->PathKey] as $SubPath) {
38
+                    $TmpPath[] = $SubPath;
39
+                }
40
+                $CurSize = (Int64::is_int($File['length'])
39
           ? Int64::get($File['length'])
41
           ? Int64::get($File['length'])
40
           : $File['length']);
42
           : $File['length']);
41
-        $this->Files[] = array($CurSize, implode('/', $TmpPath));
42
-        $this->Size += $CurSize;
43
-      }
44
-      uasort($this->Files, function($a, $b) {
45
-          return strnatcasecmp($a[1], $b[1]);
46
-        });
43
+                $this->Files[] = array($CurSize, implode('/', $TmpPath));
44
+                $this->Size += $CurSize;
45
+            }
46
+            uasort($this->Files, function ($a, $b) {
47
+                return strnatcasecmp($a[1], $b[1]);
48
+            });
49
+        }
50
+        return array($this->Size, $this->Files);
47
     }
51
     }
48
-    return array($this->Size, $this->Files);
49
-  }
50
 
52
 
51
-  /**
52
-   * Find out the name of the torrent
53
-   *
54
-   * @return string torrent name
55
-   */
56
-  public function get_name() {
57
-    if (empty($this->Dec)) {
58
-      return false;
59
-    }
60
-    if (isset($this->Dec['info']['name.utf-8'])) {
61
-      return $this->Dec['info']['name.utf-8'];
53
+    /**
54
+     * Find out the name of the torrent
55
+     *
56
+     * @return string torrent name
57
+     */
58
+    public function get_name()
59
+    {
60
+        if (empty($this->Dec)) {
61
+            return false;
62
+        }
63
+        if (isset($this->Dec['info']['name.utf-8'])) {
64
+            return $this->Dec['info']['name.utf-8'];
65
+        }
66
+        return $this->Dec['info']['name'];
62
     }
67
     }
63
-    return $this->Dec['info']['name'];
64
-  }
65
 
68
 
66
-  /**
67
-   * Find out the total size of the torrent
68
-   *
69
-   * @return string torrent size
70
-   */
71
-  public function get_size() {
72
-    if (empty($this->Files)) {
73
-      if (empty($this->Dec)) {
74
-        return false;
75
-      }
76
-      $FileList = $this->file_list();
69
+    /**
70
+     * Find out the total size of the torrent
71
+     *
72
+     * @return string torrent size
73
+     */
74
+    public function get_size()
75
+    {
76
+        if (empty($this->Files)) {
77
+            if (empty($this->Dec)) {
78
+                return false;
79
+            }
80
+            $FileList = $this->file_list();
81
+        }
82
+        return $FileList[0];
77
     }
83
     }
78
-    return $FileList[0];
79
-  }
80
 
84
 
81
-  /**
82
-   * Checks if the "private" flag is present in the torrent
83
-   *
84
-   * @return true if the "private" flag is set
85
-   */
86
-  public function is_private() {
87
-    if (empty($this->Dec)) {
88
-      return false;
89
-    }
90
-    return isset($this->Dec['info']['private']) && Int64::get($this->Dec['info']['private']) == 1;
91
-  }
92
-  /**
93
-   * Add the "private" flag to the torrent
94
-   *
95
-   * @return true if a change was required
96
-   */
97
-  public function make_private() {
98
-    if (empty($this->Dec)) {
99
-      return false;
85
+    /**
86
+     * Checks if the "private" flag is present in the torrent
87
+     *
88
+     * @return true if the "private" flag is set
89
+     */
90
+    public function is_private()
91
+    {
92
+        if (empty($this->Dec)) {
93
+            return false;
94
+        }
95
+        return isset($this->Dec['info']['private']) && Int64::get($this->Dec['info']['private']) == 1;
100
     }
96
     }
101
-    if ($this->is_private()) {
102
-      return false;
97
+    
98
+    /**
99
+     * Add the "private" flag to the torrent
100
+     *
101
+     * @return true if a change was required
102
+     */
103
+    public function make_private()
104
+    {
105
+        if (empty($this->Dec)) {
106
+            return false;
107
+        }
108
+        if ($this->is_private()) {
109
+            return false;
110
+        }
111
+        $this->Dec['info']['private'] = Int64::make(1);
112
+        ksort($this->Dec['info']);
113
+        return true;
103
     }
114
     }
104
-    $this->Dec['info']['private'] = Int64::make(1);
105
-    ksort($this->Dec['info']);
106
-    return true;
107
-  }
108
 
115
 
109
-  /**
110
-   * Add the "source" field to the torrent
111
-   *
112
-   * @return true if a change was required
113
-   */
114
-  public function make_sourced() {
115
-    $Sources = Users::get_upload_sources();
116
-    if (empty($this->Dec)) { return false; }
117
-    if (isset($this->Dec['info']['source']) && ($this->Dec['info']['source'] == $Sources[0] || $this->Dec['info']['source'] == $Sources[1])) {
118
-      return false;
116
+    /**
117
+     * Add the "source" field to the torrent
118
+     *
119
+     * @return true if a change was required
120
+     */
121
+    public function make_sourced()
122
+    {
123
+        $Sources = Users::get_upload_sources();
124
+        if (empty($this->Dec)) {
125
+            return false;
126
+        }
127
+        if (isset($this->Dec['info']['source']) && ($this->Dec['info']['source'] == $Sources[0] || $this->Dec['info']['source'] == $Sources[1])) {
128
+            return false;
129
+        }
130
+        $this->Dec['info']['source'] = $Sources[0];
131
+        ksort($this->Dec['info']);
132
+        return true;
119
     }
133
     }
120
-    $this->Dec['info']['source'] = $Sources[0];
121
-    ksort($this->Dec['info']);
122
-    return true;
123
-  }
124
 
134
 
125
-  /**
126
-   * Calculate the torrent's info hash
127
-   *
128
-   * @return info hash in hexadecimal form
129
-   */
130
-  public function info_hash() {
131
-    if (empty($this->Dec) || !isset($this->Dec['info'])) {
132
-      return false;
135
+    /**
136
+     * Calculate the torrent's info hash
137
+     *
138
+     * @return info hash in hexadecimal form
139
+     */
140
+    public function info_hash()
141
+    {
142
+        if (empty($this->Dec) || !isset($this->Dec['info'])) {
143
+            return false;
144
+        }
145
+        return sha1($this->encode(false, 'info'));
133
     }
146
     }
134
-    return sha1($this->encode(false, 'info'));
135
-  }
136
 
147
 
137
-  /**
138
-   * Add the announce URL to a torrent
139
-   */
140
-  public static function add_announce_url($Data, $Url) {
141
-    return 'd8:announce'.strlen($Url).':'.$Url.substr($Data, 1);
142
-  }
148
+    /**
149
+     * Add the announce URL to a torrent
150
+     */
151
+    public static function add_announce_url($Data, $Url)
152
+    {
153
+        return 'd8:announce'.strlen($Url).':'.$Url.substr($Data, 1);
154
+    }
143
 
155
 
144
-  /**
145
-   * Add list of announce URLs to a torrent
146
-   */
147
-  public static function add_announce_list($Data, $Urls) {
148
-    $r = 'd13:announce-listl';
149
-    for ($i = 0; $i < count($Urls); $i++) {
150
-      $r .= 'l';
151
-      for ($j = 0; $j < count($Urls[$i]); $j++) {
152
-        $r .= strlen($Urls[$i][$j]).':'.$Urls[$i][$j];
153
-      }
154
-      $r .= 'e';
156
+    /**
157
+     * Add list of announce URLs to a torrent
158
+     */
159
+    public static function add_announce_list($Data, $Urls)
160
+    {
161
+        $r = 'd13:announce-listl';
162
+        for ($i = 0; $i < count($Urls); $i++) {
163
+            $r .= 'l';
164
+            for ($j = 0; $j < count($Urls[$i]); $j++) {
165
+                $r .= strlen($Urls[$i][$j]).':'.$Urls[$i][$j];
166
+            }
167
+            $r .= 'e';
168
+        }
169
+        return $r.'e'.substr($Data, 1);
155
     }
170
     }
156
-    return $r.'e'.substr($Data, 1);
157
-  }
158
 }
171
 }

+ 9
- 8
static/styles/oppai/style.css View File

310
   border: 1px solid transparent;
310
   border: 1px solid transparent;
311
   box-sizing: border-box;
311
   box-sizing: border-box;
312
   padding: 2px 2px 2px 4px;
312
   padding: 2px 2px 2px 4px;
313
-  font-size: 0.9em;
313
+  /* font-size: 0.9em; */
314
   background-color: white;
314
   background-color: white;
315
   width: 100%;
315
   width: 100%;
316
   color: black;
316
   color: black;
371
   text-align: center;
371
   text-align: center;
372
   color: black;
372
   color: black;
373
   font-weight: bold;
373
   font-weight: bold;
374
-  font-size: 0.95em;
374
+  /* font-size: 0.95em; */
375
   width: 350px;
375
   width: 350px;
376
-  margin: 0 auto 0px auto;
376
+  margin: 2em auto;
377
   padding: 10px;
377
   padding: 10px;
378
-  margin-bottom: 8px;
379
 }
378
 }
380
 .alertbar.warning {
379
 .alertbar.warning {
381
   background-color: #ffe68a;
380
   background-color: #ffe68a;
618
 }
617
 }
619
 
618
 
620
 .error_message {
619
 .error_message {
621
-  padding: 8px 0px;
620
+  padding: 10px;
622
   background-color: #AF2525;
621
   background-color: #AF2525;
623
   text-align: center;
622
   text-align: center;
624
   color: white;
623
   color: white;
626
 }
625
 }
627
 
626
 
628
 .save_message {
627
 .save_message {
629
-  padding: 8px 0px;
630
-  background-color: #F8C2E8;
628
+  padding: 10px;
629
+  width: 50%;
630
+  margin: 2em auto;
631
+  background: #fbe180;
631
   text-align: center;
632
   text-align: center;
632
-  color: #555555;
633
+  color: black;
633
   font-weight: bold;
634
   font-weight: bold;
634
 }
635
 }
635
 
636
 

Loading…
Cancel
Save