@@ -30,164 +30,164 @@ |
||
30 | 30 | */ |
31 | 31 | class zipfile |
32 | 32 | { |
33 | - /** |
|
34 | - * Array to store compressed data |
|
35 | - * |
|
36 | - * @var array $datasec |
|
37 | - */ |
|
38 | - var $datasec = []; |
|
39 | - |
|
40 | - /** |
|
41 | - * Central directory |
|
42 | - * |
|
43 | - * @var array $ctrl_dir |
|
44 | - */ |
|
45 | - var $ctrl_dir = []; |
|
46 | - |
|
47 | - /** |
|
48 | - * End of central directory record |
|
49 | - * |
|
50 | - * @var string $eof_ctrl_dir |
|
51 | - */ |
|
52 | - var $eof_ctrl_dir = "\x50\x4b\x05\x06\x00\x00\x00\x00"; |
|
53 | - |
|
54 | - /** |
|
55 | - * Last offset position |
|
56 | - * |
|
57 | - * @var integer $old_offset |
|
58 | - */ |
|
59 | - var $old_offset = 0; |
|
60 | - |
|
61 | - |
|
62 | - /** |
|
63 | - * Converts an Unix timestamp to a four byte DOS date and time format (date |
|
64 | - * in high two bytes, time in low two bytes allowing magnitude comparison). |
|
65 | - * |
|
66 | - * @param integer current Unix timestamp |
|
67 | - * |
|
68 | - * @return integer current date in a four byte DOS format |
|
69 | - * |
|
70 | - * @access private |
|
71 | - */ |
|
72 | - function unix2DosTime($unixtime = 0) { |
|
73 | - $timearray = ($unixtime == 0) ? getdate() : getdate($unixtime); |
|
74 | - |
|
75 | - if ($timearray['year'] < 1980) { |
|
76 | - $timearray['year'] = 1980; |
|
77 | - $timearray['mon'] = 1; |
|
78 | - $timearray['mday'] = 1; |
|
79 | - $timearray['hours'] = 0; |
|
80 | - $timearray['minutes'] = 0; |
|
81 | - $timearray['seconds'] = 0; |
|
82 | - } // end if |
|
83 | - |
|
84 | - return (($timearray['year'] - 1980) << 25) | ($timearray['mon'] << 21) | ($timearray['mday'] << 16) | |
|
85 | - ($timearray['hours'] << 11) | ($timearray['minutes'] << 5) | ($timearray['seconds'] >> 1); |
|
86 | - } // end of the 'unix2DosTime()' method |
|
87 | - |
|
88 | - |
|
89 | - /** |
|
90 | - * Adds "file" to archive |
|
91 | - * |
|
92 | - * @param string file contents |
|
93 | - * @param string name of the file in the archive (may contains the path) |
|
94 | - * @param integer the current timestamp |
|
95 | - * |
|
96 | - * @access public |
|
97 | - */ |
|
98 | - function addFile($data, $name, $time = 0) |
|
99 | - { |
|
100 | - $name = str_replace('\\', '/', $name); |
|
101 | - |
|
102 | - $dtime = dechex($this->unix2DosTime($time)); |
|
103 | - $hexdtime = '\x' . $dtime[6] . $dtime[7] |
|
104 | - . '\x' . $dtime[4] . $dtime[5] |
|
105 | - . '\x' . $dtime[2] . $dtime[3] |
|
106 | - . '\x' . $dtime[0] . $dtime[1]; |
|
107 | - eval('$hexdtime = "' . $hexdtime . '";'); |
|
108 | - |
|
109 | - $fr = "\x50\x4b\x03\x04"; |
|
110 | - $fr .= "\x14\x00"; // ver needed to extract |
|
111 | - $fr .= "\x00\x00"; // gen purpose bit flag |
|
112 | - $fr .= "\x08\x00"; // compression method |
|
113 | - $fr .= $hexdtime; // last mod time and date |
|
114 | - |
|
115 | - // "local file header" segment |
|
116 | - $unc_len = strlen($data); |
|
117 | - $crc = crc32($data); |
|
118 | - $zdata = gzcompress($data); |
|
119 | - $zdata = substr(substr($zdata, 0, strlen($zdata) - 4), 2); // fix crc bug |
|
120 | - $c_len = strlen($zdata); |
|
121 | - $fr .= pack('V', $crc); // crc32 |
|
122 | - $fr .= pack('V', $c_len); // compressed filesize |
|
123 | - $fr .= pack('V', $unc_len); // uncompressed filesize |
|
124 | - $fr .= pack('v', strlen($name)); // length of filename |
|
125 | - $fr .= pack('v', 0); // extra field length |
|
126 | - $fr .= $name; |
|
127 | - |
|
128 | - // "file data" segment |
|
129 | - $fr .= $zdata; |
|
130 | - |
|
131 | - // "data descriptor" segment (optional but necessary if archive is not |
|
132 | - // served as file) |
|
133 | - // nijel(2004-10-19): this seems not to be needed at all and causes |
|
134 | - // problems in some cases (bug #1037737) |
|
135 | - //$fr .= pack('V', $crc); // crc32 |
|
136 | - //$fr .= pack('V', $c_len); // compressed filesize |
|
137 | - //$fr .= pack('V', $unc_len); // uncompressed filesize |
|
138 | - |
|
139 | - // add this entry to array |
|
140 | - $this -> datasec[] = $fr; |
|
141 | - |
|
142 | - // now add to central directory record |
|
143 | - $cdrec = "\x50\x4b\x01\x02"; |
|
144 | - $cdrec .= "\x00\x00"; // version made by |
|
145 | - $cdrec .= "\x14\x00"; // version needed to extract |
|
146 | - $cdrec .= "\x00\x00"; // gen purpose bit flag |
|
147 | - $cdrec .= "\x08\x00"; // compression method |
|
148 | - $cdrec .= $hexdtime; // last mod time & date |
|
149 | - $cdrec .= pack('V', $crc); // crc32 |
|
150 | - $cdrec .= pack('V', $c_len); // compressed filesize |
|
151 | - $cdrec .= pack('V', $unc_len); // uncompressed filesize |
|
152 | - $cdrec .= pack('v', strlen($name)); // length of filename |
|
153 | - $cdrec .= pack('v', 0); // extra field length |
|
154 | - $cdrec .= pack('v', 0); // file comment length |
|
155 | - $cdrec .= pack('v', 0); // disk number start |
|
156 | - $cdrec .= pack('v', 0); // internal file attributes |
|
157 | - $cdrec .= pack('V', 32); // external file attributes - 'archive' bit set |
|
158 | - |
|
159 | - $cdrec .= pack('V', $this -> old_offset); // relative offset of local header |
|
160 | - $this -> old_offset += strlen($fr); |
|
161 | - |
|
162 | - $cdrec .= $name; |
|
163 | - |
|
164 | - // optional extra field, file comment goes here |
|
165 | - // save to central directory |
|
166 | - $this -> ctrl_dir[] = $cdrec; |
|
167 | - } // end of the 'addFile()' method |
|
168 | - |
|
169 | - |
|
170 | - /** |
|
171 | - * Dumps out file |
|
172 | - * |
|
173 | - * @return string the zipped file |
|
174 | - * |
|
175 | - * @access public |
|
176 | - */ |
|
177 | - function file() |
|
178 | - { |
|
179 | - $data = implode('', $this -> datasec); |
|
180 | - $ctrldir = implode('', $this -> ctrl_dir); |
|
181 | - |
|
182 | - return |
|
183 | - $data . |
|
184 | - $ctrldir . |
|
185 | - $this -> eof_ctrl_dir . |
|
186 | - pack('v', sizeof($this -> ctrl_dir)) . // total # of entries "on this disk" |
|
187 | - pack('v', sizeof($this -> ctrl_dir)) . // total # of entries overall |
|
188 | - pack('V', strlen($ctrldir)) . // size of central dir |
|
189 | - pack('V', strlen($data)) . // offset to start of central dir |
|
190 | - "\x00\x00"; // .zip file comment length |
|
191 | - } // end of the 'file()' method |
|
33 | + /** |
|
34 | + * Array to store compressed data |
|
35 | + * |
|
36 | + * @var array $datasec |
|
37 | + */ |
|
38 | + var $datasec = []; |
|
39 | + |
|
40 | + /** |
|
41 | + * Central directory |
|
42 | + * |
|
43 | + * @var array $ctrl_dir |
|
44 | + */ |
|
45 | + var $ctrl_dir = []; |
|
46 | + |
|
47 | + /** |
|
48 | + * End of central directory record |
|
49 | + * |
|
50 | + * @var string $eof_ctrl_dir |
|
51 | + */ |
|
52 | + var $eof_ctrl_dir = "\x50\x4b\x05\x06\x00\x00\x00\x00"; |
|
53 | + |
|
54 | + /** |
|
55 | + * Last offset position |
|
56 | + * |
|
57 | + * @var integer $old_offset |
|
58 | + */ |
|
59 | + var $old_offset = 0; |
|
60 | + |
|
61 | + |
|
62 | + /** |
|
63 | + * Converts an Unix timestamp to a four byte DOS date and time format (date |
|
64 | + * in high two bytes, time in low two bytes allowing magnitude comparison). |
|
65 | + * |
|
66 | + * @param integer current Unix timestamp |
|
67 | + * |
|
68 | + * @return integer current date in a four byte DOS format |
|
69 | + * |
|
70 | + * @access private |
|
71 | + */ |
|
72 | + function unix2DosTime($unixtime = 0) { |
|
73 | + $timearray = ($unixtime == 0) ? getdate() : getdate($unixtime); |
|
74 | + |
|
75 | + if ($timearray['year'] < 1980) { |
|
76 | + $timearray['year'] = 1980; |
|
77 | + $timearray['mon'] = 1; |
|
78 | + $timearray['mday'] = 1; |
|
79 | + $timearray['hours'] = 0; |
|
80 | + $timearray['minutes'] = 0; |
|
81 | + $timearray['seconds'] = 0; |
|
82 | + } // end if |
|
83 | + |
|
84 | + return (($timearray['year'] - 1980) << 25) | ($timearray['mon'] << 21) | ($timearray['mday'] << 16) | |
|
85 | + ($timearray['hours'] << 11) | ($timearray['minutes'] << 5) | ($timearray['seconds'] >> 1); |
|
86 | + } // end of the 'unix2DosTime()' method |
|
87 | + |
|
88 | + |
|
89 | + /** |
|
90 | + * Adds "file" to archive |
|
91 | + * |
|
92 | + * @param string file contents |
|
93 | + * @param string name of the file in the archive (may contains the path) |
|
94 | + * @param integer the current timestamp |
|
95 | + * |
|
96 | + * @access public |
|
97 | + */ |
|
98 | + function addFile($data, $name, $time = 0) |
|
99 | + { |
|
100 | + $name = str_replace('\\', '/', $name); |
|
101 | + |
|
102 | + $dtime = dechex($this->unix2DosTime($time)); |
|
103 | + $hexdtime = '\x' . $dtime[6] . $dtime[7] |
|
104 | + . '\x' . $dtime[4] . $dtime[5] |
|
105 | + . '\x' . $dtime[2] . $dtime[3] |
|
106 | + . '\x' . $dtime[0] . $dtime[1]; |
|
107 | + eval('$hexdtime = "' . $hexdtime . '";'); |
|
108 | + |
|
109 | + $fr = "\x50\x4b\x03\x04"; |
|
110 | + $fr .= "\x14\x00"; // ver needed to extract |
|
111 | + $fr .= "\x00\x00"; // gen purpose bit flag |
|
112 | + $fr .= "\x08\x00"; // compression method |
|
113 | + $fr .= $hexdtime; // last mod time and date |
|
114 | + |
|
115 | + // "local file header" segment |
|
116 | + $unc_len = strlen($data); |
|
117 | + $crc = crc32($data); |
|
118 | + $zdata = gzcompress($data); |
|
119 | + $zdata = substr(substr($zdata, 0, strlen($zdata) - 4), 2); // fix crc bug |
|
120 | + $c_len = strlen($zdata); |
|
121 | + $fr .= pack('V', $crc); // crc32 |
|
122 | + $fr .= pack('V', $c_len); // compressed filesize |
|
123 | + $fr .= pack('V', $unc_len); // uncompressed filesize |
|
124 | + $fr .= pack('v', strlen($name)); // length of filename |
|
125 | + $fr .= pack('v', 0); // extra field length |
|
126 | + $fr .= $name; |
|
127 | + |
|
128 | + // "file data" segment |
|
129 | + $fr .= $zdata; |
|
130 | + |
|
131 | + // "data descriptor" segment (optional but necessary if archive is not |
|
132 | + // served as file) |
|
133 | + // nijel(2004-10-19): this seems not to be needed at all and causes |
|
134 | + // problems in some cases (bug #1037737) |
|
135 | + //$fr .= pack('V', $crc); // crc32 |
|
136 | + //$fr .= pack('V', $c_len); // compressed filesize |
|
137 | + //$fr .= pack('V', $unc_len); // uncompressed filesize |
|
138 | + |
|
139 | + // add this entry to array |
|
140 | + $this -> datasec[] = $fr; |
|
141 | + |
|
142 | + // now add to central directory record |
|
143 | + $cdrec = "\x50\x4b\x01\x02"; |
|
144 | + $cdrec .= "\x00\x00"; // version made by |
|
145 | + $cdrec .= "\x14\x00"; // version needed to extract |
|
146 | + $cdrec .= "\x00\x00"; // gen purpose bit flag |
|
147 | + $cdrec .= "\x08\x00"; // compression method |
|
148 | + $cdrec .= $hexdtime; // last mod time & date |
|
149 | + $cdrec .= pack('V', $crc); // crc32 |
|
150 | + $cdrec .= pack('V', $c_len); // compressed filesize |
|
151 | + $cdrec .= pack('V', $unc_len); // uncompressed filesize |
|
152 | + $cdrec .= pack('v', strlen($name)); // length of filename |
|
153 | + $cdrec .= pack('v', 0); // extra field length |
|
154 | + $cdrec .= pack('v', 0); // file comment length |
|
155 | + $cdrec .= pack('v', 0); // disk number start |
|
156 | + $cdrec .= pack('v', 0); // internal file attributes |
|
157 | + $cdrec .= pack('V', 32); // external file attributes - 'archive' bit set |
|
158 | + |
|
159 | + $cdrec .= pack('V', $this -> old_offset); // relative offset of local header |
|
160 | + $this -> old_offset += strlen($fr); |
|
161 | + |
|
162 | + $cdrec .= $name; |
|
163 | + |
|
164 | + // optional extra field, file comment goes here |
|
165 | + // save to central directory |
|
166 | + $this -> ctrl_dir[] = $cdrec; |
|
167 | + } // end of the 'addFile()' method |
|
168 | + |
|
169 | + |
|
170 | + /** |
|
171 | + * Dumps out file |
|
172 | + * |
|
173 | + * @return string the zipped file |
|
174 | + * |
|
175 | + * @access public |
|
176 | + */ |
|
177 | + function file() |
|
178 | + { |
|
179 | + $data = implode('', $this -> datasec); |
|
180 | + $ctrldir = implode('', $this -> ctrl_dir); |
|
181 | + |
|
182 | + return |
|
183 | + $data . |
|
184 | + $ctrldir . |
|
185 | + $this -> eof_ctrl_dir . |
|
186 | + pack('v', sizeof($this -> ctrl_dir)) . // total # of entries "on this disk" |
|
187 | + pack('v', sizeof($this -> ctrl_dir)) . // total # of entries overall |
|
188 | + pack('V', strlen($ctrldir)) . // size of central dir |
|
189 | + pack('V', strlen($data)) . // offset to start of central dir |
|
190 | + "\x00\x00"; // .zip file comment length |
|
191 | + } // end of the 'file()' method |
|
192 | 192 | |
193 | 193 | } |
@@ -3,321 +3,321 @@ |
||
3 | 3 | |
4 | 4 | final class NZBVortex |
5 | 5 | { |
6 | - protected $nonce = null; |
|
7 | - protected $session = null; |
|
8 | - |
|
9 | - public function __construct() |
|
10 | - { |
|
11 | - if (is_null($this->session)) |
|
12 | - { |
|
13 | - $this->getNonce(); |
|
14 | - $this->login(); |
|
15 | - } |
|
16 | - } |
|
17 | - |
|
18 | - /** |
|
19 | - * get text for state |
|
20 | - * @param int $code |
|
21 | - * @return string |
|
22 | - */ |
|
23 | - public function getState($code = 0) |
|
24 | - { |
|
25 | - $states = array |
|
26 | - ( |
|
27 | - 0 => 'Waiting', |
|
28 | - 1 => 'Downloading', |
|
29 | - 2 => 'Waiting for save', |
|
30 | - 3 => 'Saving', |
|
31 | - 4 => 'Saved', |
|
32 | - 5 => 'Password request', |
|
33 | - 6 => 'Queued for processing', |
|
34 | - 7 => 'User wait for processing', |
|
35 | - 8 => 'Checking', |
|
36 | - 9 => 'Repairing', |
|
37 | - 10 => 'Joining', |
|
38 | - 11 => 'Wait for further processing', |
|
39 | - 12 => 'Joining', |
|
40 | - 13 => 'Wait for uncompress', |
|
41 | - 14 => 'Uncompressing', |
|
42 | - 15 => 'Wait for cleanup', |
|
43 | - 16 => 'Cleaning up', |
|
44 | - 17 => 'Cleaned up', |
|
45 | - 18 => 'Moving to completed', |
|
46 | - 19 => 'Move completed', |
|
47 | - 20 => 'Done', |
|
48 | - 21 => 'Uncompress failed', |
|
49 | - 22 => 'Check failed, data corrupt', |
|
50 | - 23 => 'Move failed', |
|
51 | - 24 => 'Badly encoded download (uuencoded)' |
|
52 | - ); |
|
53 | - |
|
54 | - return (isset($states[$code])) ? |
|
55 | - $states[$code] : -1; |
|
56 | - } |
|
57 | - |
|
58 | - /** |
|
59 | - * get overview of NZB's in queue |
|
60 | - * @return array |
|
61 | - */ |
|
62 | - public function getOverview() |
|
63 | - { |
|
64 | - $params = array('sessionid' => $this->session); |
|
65 | - $response = $this->sendRequest(sprintf('app/webUpdate'), $params); |
|
66 | - foreach ($response['nzbs'] as &$nzb) |
|
67 | - { |
|
68 | - $nzb['original_state'] = $nzb['state']; |
|
69 | - $nzb['state'] = (1 == $nzb['isPaused']) ? 'Paused' : $this->getState($nzb['state']); |
|
70 | - } |
|
71 | - |
|
72 | - return $response; |
|
73 | - } |
|
74 | - |
|
75 | - |
|
76 | - /** |
|
77 | - * add NZB to queue |
|
78 | - * @param string $nzb |
|
79 | - * @return void |
|
80 | - */ |
|
81 | - public function addQueue($nzb = '') |
|
82 | - { |
|
83 | - if (!empty($nzb)) |
|
84 | - { |
|
85 | - $page = new Page; |
|
86 | - $user = new Users; |
|
87 | - |
|
88 | - $host = $page->serverurl; |
|
89 | - $data = $user->getById($user->currentUserId()); |
|
90 | - $url = sprintf("%sgetnzb/%s.nzb&i=%s&r=%s", $host, $nzb, $data['id'], $data['rsstoken']); |
|
91 | - |
|
92 | - $params = array |
|
93 | - ( |
|
94 | - 'sessionid' => $this->session, |
|
95 | - 'url' => $url |
|
96 | - ); |
|
97 | - |
|
98 | - $response = $this->sendRequest('nzb/add', $params); |
|
99 | - } |
|
100 | - } |
|
101 | - |
|
102 | - |
|
103 | - /** |
|
104 | - * resume NZB |
|
105 | - * @param int $id |
|
106 | - * @return void |
|
107 | - */ |
|
108 | - public function resume($id = 0) |
|
109 | - { |
|
110 | - if ($id > 0) |
|
111 | - { |
|
112 | - # /nzb/(id)/resume |
|
113 | - $params = array('sessionid' => $this->session); |
|
114 | - $response = $this->sendRequest(sprintf('nzb/%s/resume', $id), $params); |
|
115 | - } |
|
116 | - } |
|
117 | - |
|
118 | - |
|
119 | - /** |
|
120 | - * pause NZB |
|
121 | - * @param int $id |
|
122 | - * @return void |
|
123 | - */ |
|
124 | - public function pause($id = 0) |
|
125 | - { |
|
126 | - if ($id > 0) |
|
127 | - { |
|
128 | - # /nzb/(id)/pause |
|
129 | - $params = array('sessionid' => $this->session); |
|
130 | - $response = $this->sendRequest(sprintf('nzb/%s/pause', $id), $params); |
|
131 | - } |
|
132 | - } |
|
133 | - |
|
134 | - |
|
135 | - /** |
|
136 | - * move NZB up in queue |
|
137 | - * @param int $id |
|
138 | - * @return void |
|
139 | - */ |
|
140 | - public function moveUp($id = 0) |
|
141 | - { |
|
142 | - if ($id > 0) |
|
143 | - { |
|
144 | - # nzb/(nzbid)/moveup |
|
145 | - $params = array('sessionid' => $this->session); |
|
146 | - $response = $this->sendRequest(sprintf('nzb/%s/moveup', $id), $params); |
|
147 | - } |
|
148 | - } |
|
149 | - |
|
150 | - |
|
151 | - /** |
|
152 | - * move NZB down in queue |
|
153 | - * @param int $id |
|
154 | - * @return void |
|
155 | - */ |
|
156 | - public function moveDown($id = 0) |
|
157 | - { |
|
158 | - if ($id > 0) |
|
159 | - { |
|
160 | - # nzb/(nzbid)/movedown |
|
161 | - $params = array('sessionid' => $this->session); |
|
162 | - $response = $this->sendRequest(sprintf('nzb/%s/movedown', $id), $params); |
|
163 | - } |
|
164 | - } |
|
165 | - |
|
166 | - |
|
167 | - /** |
|
168 | - * move NZB to bottom of queue |
|
169 | - * @param int $id |
|
170 | - * @return void |
|
171 | - */ |
|
172 | - public function moveBottom($id = 0) |
|
173 | - { |
|
174 | - if ($id > 0) |
|
175 | - { |
|
176 | - # nzb/(nzbid)/movebottom |
|
177 | - $params = array('sessionid' => $this->session); |
|
178 | - $response = $this->sendRequest(sprintf('nzb/%s/movebottom', $id), $params); |
|
179 | - } |
|
180 | - } |
|
181 | - |
|
182 | - |
|
183 | - /** |
|
184 | - * Remove a (finished/unfinished) NZB from queue and delete files |
|
185 | - * @param int $id |
|
186 | - * @return void |
|
187 | - */ |
|
188 | - public function delete($id = 0) |
|
189 | - { |
|
190 | - if ($id > 0) |
|
191 | - { |
|
192 | - # nzb/(nzbid)/movebottom |
|
193 | - $params = array('sessionid' => $this->session); |
|
194 | - $response = $this->sendRequest(sprintf('nzb/%s/cancelDelete', $id), $params); |
|
195 | - } |
|
196 | - } |
|
197 | - |
|
198 | - |
|
199 | - /** |
|
200 | - * move NZB to top of queue |
|
201 | - * @param int $id |
|
202 | - * @return void |
|
203 | - */ |
|
204 | - public function moveTop($id = 0) |
|
205 | - { |
|
206 | - if ($id > 0) |
|
207 | - { |
|
208 | - # nzb/(nzbid)/movebottom |
|
209 | - $params = array('sessionid' => $this->session); |
|
210 | - $response = $this->sendRequest(sprintf('nzb/%s/movetop', $id), $params); |
|
211 | - } |
|
212 | - } |
|
213 | - |
|
214 | - |
|
215 | - /** |
|
216 | - * get filelist for nzb |
|
217 | - * @param int $id |
|
218 | - * @return array|bool |
|
219 | - */ |
|
220 | - public function getFilelist($id = 0) |
|
221 | - { |
|
222 | - if ($id > 0) |
|
223 | - { |
|
224 | - # file/(nzbid) |
|
225 | - $params = array('sessionid' => $this->session); |
|
226 | - $response = $this->sendRequest(sprintf('file/%s', $id), $params); |
|
227 | - return $response; |
|
228 | - } |
|
229 | - |
|
230 | - return false; |
|
231 | - } |
|
232 | - |
|
233 | - |
|
234 | - /** |
|
235 | - * get /auth/nonce |
|
236 | - * @return void |
|
237 | - */ |
|
238 | - protected function getNonce() |
|
239 | - { |
|
240 | - $response = $this->sendRequest('auth/nonce'); |
|
241 | - $this->nonce = $response['authNonce']; |
|
242 | - } |
|
243 | - |
|
244 | - /** |
|
245 | - * @return void |
|
246 | - */ |
|
247 | - protected function login() |
|
248 | - { |
|
249 | - $user = new Users(); |
|
250 | - $data = $user->getById($user->currentUserId()); |
|
251 | - $cnonce = generateUuid(); |
|
252 | - $hash = hash('sha256', sprintf("%s:%s:%s", $this->nonce, $cnonce, $data['nzbvortex_api_key']), true); |
|
253 | - $hash = base64_encode($hash); |
|
254 | - |
|
255 | - $params = array |
|
256 | - ( |
|
257 | - 'nonce' => $this->nonce, |
|
258 | - 'cnonce' => $cnonce, |
|
259 | - 'hash' => $hash |
|
260 | - ); |
|
261 | - |
|
262 | - $response = $this->sendRequest('auth/login', $params); |
|
263 | - |
|
264 | - if ('successful' == $response['loginResult']) |
|
265 | - $this->session = $response['sessionID']; |
|
266 | - |
|
267 | - if ('failed' == $response['loginResult']) { } |
|
268 | - } |
|
269 | - |
|
270 | - /** |
|
271 | - * sendRequest() |
|
272 | - * |
|
273 | - * @param $path |
|
274 | - * @param array $params |
|
275 | - * |
|
276 | - * @return array |
|
277 | - * @throws \Exception |
|
278 | - */ |
|
279 | - protected function sendRequest($path, $params = []) |
|
280 | - { |
|
281 | - $user = new Users; |
|
282 | - $data = $user->getById($user->currentUserId()); |
|
283 | - |
|
284 | - $url = sprintf('%s/api', $data['nzbvortex_server_url']); |
|
285 | - $params = http_build_query($params); |
|
286 | - $ch = curl_init(sprintf("%s/%s?%s", $url, $path, $params)); |
|
287 | - |
|
288 | - curl_setopt($ch, CURLOPT_HEADER, 0); |
|
289 | - curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); |
|
290 | - curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); |
|
291 | - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
|
292 | - curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); |
|
293 | - |
|
294 | - #curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1); |
|
295 | - #curl_setopt($ch, CURLOPT_PROXY, 'localhost:8888'); |
|
296 | - |
|
297 | - $response = curl_exec($ch); |
|
298 | - $response = json_decode($response, true); |
|
299 | - $status = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
|
300 | - $error = curl_error($ch); |
|
301 | - |
|
302 | - curl_close($ch); |
|
303 | - |
|
304 | - switch ($status) |
|
305 | - { |
|
306 | - case 0: |
|
307 | - throw new \Exception(sprintf('Unable to connect. Is NZBVortex running? Is your API key correct? Is something blocking ports? (Err: %s)', $error)); |
|
308 | - break; |
|
309 | - |
|
310 | - case 200: |
|
311 | - return $response; |
|
312 | - break; |
|
313 | - |
|
314 | - case 403: |
|
315 | - throw new \Exception('Unable to login. Is your API key correct?'); |
|
316 | - break; |
|
317 | - |
|
318 | - default: |
|
319 | - throw new \Exception(sprintf("%s (%s): %s", $path, $status, $response['result'])); |
|
320 | - break; |
|
321 | - } |
|
322 | - } |
|
6 | + protected $nonce = null; |
|
7 | + protected $session = null; |
|
8 | + |
|
9 | + public function __construct() |
|
10 | + { |
|
11 | + if (is_null($this->session)) |
|
12 | + { |
|
13 | + $this->getNonce(); |
|
14 | + $this->login(); |
|
15 | + } |
|
16 | + } |
|
17 | + |
|
18 | + /** |
|
19 | + * get text for state |
|
20 | + * @param int $code |
|
21 | + * @return string |
|
22 | + */ |
|
23 | + public function getState($code = 0) |
|
24 | + { |
|
25 | + $states = array |
|
26 | + ( |
|
27 | + 0 => 'Waiting', |
|
28 | + 1 => 'Downloading', |
|
29 | + 2 => 'Waiting for save', |
|
30 | + 3 => 'Saving', |
|
31 | + 4 => 'Saved', |
|
32 | + 5 => 'Password request', |
|
33 | + 6 => 'Queued for processing', |
|
34 | + 7 => 'User wait for processing', |
|
35 | + 8 => 'Checking', |
|
36 | + 9 => 'Repairing', |
|
37 | + 10 => 'Joining', |
|
38 | + 11 => 'Wait for further processing', |
|
39 | + 12 => 'Joining', |
|
40 | + 13 => 'Wait for uncompress', |
|
41 | + 14 => 'Uncompressing', |
|
42 | + 15 => 'Wait for cleanup', |
|
43 | + 16 => 'Cleaning up', |
|
44 | + 17 => 'Cleaned up', |
|
45 | + 18 => 'Moving to completed', |
|
46 | + 19 => 'Move completed', |
|
47 | + 20 => 'Done', |
|
48 | + 21 => 'Uncompress failed', |
|
49 | + 22 => 'Check failed, data corrupt', |
|
50 | + 23 => 'Move failed', |
|
51 | + 24 => 'Badly encoded download (uuencoded)' |
|
52 | + ); |
|
53 | + |
|
54 | + return (isset($states[$code])) ? |
|
55 | + $states[$code] : -1; |
|
56 | + } |
|
57 | + |
|
58 | + /** |
|
59 | + * get overview of NZB's in queue |
|
60 | + * @return array |
|
61 | + */ |
|
62 | + public function getOverview() |
|
63 | + { |
|
64 | + $params = array('sessionid' => $this->session); |
|
65 | + $response = $this->sendRequest(sprintf('app/webUpdate'), $params); |
|
66 | + foreach ($response['nzbs'] as &$nzb) |
|
67 | + { |
|
68 | + $nzb['original_state'] = $nzb['state']; |
|
69 | + $nzb['state'] = (1 == $nzb['isPaused']) ? 'Paused' : $this->getState($nzb['state']); |
|
70 | + } |
|
71 | + |
|
72 | + return $response; |
|
73 | + } |
|
74 | + |
|
75 | + |
|
76 | + /** |
|
77 | + * add NZB to queue |
|
78 | + * @param string $nzb |
|
79 | + * @return void |
|
80 | + */ |
|
81 | + public function addQueue($nzb = '') |
|
82 | + { |
|
83 | + if (!empty($nzb)) |
|
84 | + { |
|
85 | + $page = new Page; |
|
86 | + $user = new Users; |
|
87 | + |
|
88 | + $host = $page->serverurl; |
|
89 | + $data = $user->getById($user->currentUserId()); |
|
90 | + $url = sprintf("%sgetnzb/%s.nzb&i=%s&r=%s", $host, $nzb, $data['id'], $data['rsstoken']); |
|
91 | + |
|
92 | + $params = array |
|
93 | + ( |
|
94 | + 'sessionid' => $this->session, |
|
95 | + 'url' => $url |
|
96 | + ); |
|
97 | + |
|
98 | + $response = $this->sendRequest('nzb/add', $params); |
|
99 | + } |
|
100 | + } |
|
101 | + |
|
102 | + |
|
103 | + /** |
|
104 | + * resume NZB |
|
105 | + * @param int $id |
|
106 | + * @return void |
|
107 | + */ |
|
108 | + public function resume($id = 0) |
|
109 | + { |
|
110 | + if ($id > 0) |
|
111 | + { |
|
112 | + # /nzb/(id)/resume |
|
113 | + $params = array('sessionid' => $this->session); |
|
114 | + $response = $this->sendRequest(sprintf('nzb/%s/resume', $id), $params); |
|
115 | + } |
|
116 | + } |
|
117 | + |
|
118 | + |
|
119 | + /** |
|
120 | + * pause NZB |
|
121 | + * @param int $id |
|
122 | + * @return void |
|
123 | + */ |
|
124 | + public function pause($id = 0) |
|
125 | + { |
|
126 | + if ($id > 0) |
|
127 | + { |
|
128 | + # /nzb/(id)/pause |
|
129 | + $params = array('sessionid' => $this->session); |
|
130 | + $response = $this->sendRequest(sprintf('nzb/%s/pause', $id), $params); |
|
131 | + } |
|
132 | + } |
|
133 | + |
|
134 | + |
|
135 | + /** |
|
136 | + * move NZB up in queue |
|
137 | + * @param int $id |
|
138 | + * @return void |
|
139 | + */ |
|
140 | + public function moveUp($id = 0) |
|
141 | + { |
|
142 | + if ($id > 0) |
|
143 | + { |
|
144 | + # nzb/(nzbid)/moveup |
|
145 | + $params = array('sessionid' => $this->session); |
|
146 | + $response = $this->sendRequest(sprintf('nzb/%s/moveup', $id), $params); |
|
147 | + } |
|
148 | + } |
|
149 | + |
|
150 | + |
|
151 | + /** |
|
152 | + * move NZB down in queue |
|
153 | + * @param int $id |
|
154 | + * @return void |
|
155 | + */ |
|
156 | + public function moveDown($id = 0) |
|
157 | + { |
|
158 | + if ($id > 0) |
|
159 | + { |
|
160 | + # nzb/(nzbid)/movedown |
|
161 | + $params = array('sessionid' => $this->session); |
|
162 | + $response = $this->sendRequest(sprintf('nzb/%s/movedown', $id), $params); |
|
163 | + } |
|
164 | + } |
|
165 | + |
|
166 | + |
|
167 | + /** |
|
168 | + * move NZB to bottom of queue |
|
169 | + * @param int $id |
|
170 | + * @return void |
|
171 | + */ |
|
172 | + public function moveBottom($id = 0) |
|
173 | + { |
|
174 | + if ($id > 0) |
|
175 | + { |
|
176 | + # nzb/(nzbid)/movebottom |
|
177 | + $params = array('sessionid' => $this->session); |
|
178 | + $response = $this->sendRequest(sprintf('nzb/%s/movebottom', $id), $params); |
|
179 | + } |
|
180 | + } |
|
181 | + |
|
182 | + |
|
183 | + /** |
|
184 | + * Remove a (finished/unfinished) NZB from queue and delete files |
|
185 | + * @param int $id |
|
186 | + * @return void |
|
187 | + */ |
|
188 | + public function delete($id = 0) |
|
189 | + { |
|
190 | + if ($id > 0) |
|
191 | + { |
|
192 | + # nzb/(nzbid)/movebottom |
|
193 | + $params = array('sessionid' => $this->session); |
|
194 | + $response = $this->sendRequest(sprintf('nzb/%s/cancelDelete', $id), $params); |
|
195 | + } |
|
196 | + } |
|
197 | + |
|
198 | + |
|
199 | + /** |
|
200 | + * move NZB to top of queue |
|
201 | + * @param int $id |
|
202 | + * @return void |
|
203 | + */ |
|
204 | + public function moveTop($id = 0) |
|
205 | + { |
|
206 | + if ($id > 0) |
|
207 | + { |
|
208 | + # nzb/(nzbid)/movebottom |
|
209 | + $params = array('sessionid' => $this->session); |
|
210 | + $response = $this->sendRequest(sprintf('nzb/%s/movetop', $id), $params); |
|
211 | + } |
|
212 | + } |
|
213 | + |
|
214 | + |
|
215 | + /** |
|
216 | + * get filelist for nzb |
|
217 | + * @param int $id |
|
218 | + * @return array|bool |
|
219 | + */ |
|
220 | + public function getFilelist($id = 0) |
|
221 | + { |
|
222 | + if ($id > 0) |
|
223 | + { |
|
224 | + # file/(nzbid) |
|
225 | + $params = array('sessionid' => $this->session); |
|
226 | + $response = $this->sendRequest(sprintf('file/%s', $id), $params); |
|
227 | + return $response; |
|
228 | + } |
|
229 | + |
|
230 | + return false; |
|
231 | + } |
|
232 | + |
|
233 | + |
|
234 | + /** |
|
235 | + * get /auth/nonce |
|
236 | + * @return void |
|
237 | + */ |
|
238 | + protected function getNonce() |
|
239 | + { |
|
240 | + $response = $this->sendRequest('auth/nonce'); |
|
241 | + $this->nonce = $response['authNonce']; |
|
242 | + } |
|
243 | + |
|
244 | + /** |
|
245 | + * @return void |
|
246 | + */ |
|
247 | + protected function login() |
|
248 | + { |
|
249 | + $user = new Users(); |
|
250 | + $data = $user->getById($user->currentUserId()); |
|
251 | + $cnonce = generateUuid(); |
|
252 | + $hash = hash('sha256', sprintf("%s:%s:%s", $this->nonce, $cnonce, $data['nzbvortex_api_key']), true); |
|
253 | + $hash = base64_encode($hash); |
|
254 | + |
|
255 | + $params = array |
|
256 | + ( |
|
257 | + 'nonce' => $this->nonce, |
|
258 | + 'cnonce' => $cnonce, |
|
259 | + 'hash' => $hash |
|
260 | + ); |
|
261 | + |
|
262 | + $response = $this->sendRequest('auth/login', $params); |
|
263 | + |
|
264 | + if ('successful' == $response['loginResult']) |
|
265 | + $this->session = $response['sessionID']; |
|
266 | + |
|
267 | + if ('failed' == $response['loginResult']) { } |
|
268 | + } |
|
269 | + |
|
270 | + /** |
|
271 | + * sendRequest() |
|
272 | + * |
|
273 | + * @param $path |
|
274 | + * @param array $params |
|
275 | + * |
|
276 | + * @return array |
|
277 | + * @throws \Exception |
|
278 | + */ |
|
279 | + protected function sendRequest($path, $params = []) |
|
280 | + { |
|
281 | + $user = new Users; |
|
282 | + $data = $user->getById($user->currentUserId()); |
|
283 | + |
|
284 | + $url = sprintf('%s/api', $data['nzbvortex_server_url']); |
|
285 | + $params = http_build_query($params); |
|
286 | + $ch = curl_init(sprintf("%s/%s?%s", $url, $path, $params)); |
|
287 | + |
|
288 | + curl_setopt($ch, CURLOPT_HEADER, 0); |
|
289 | + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); |
|
290 | + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); |
|
291 | + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
|
292 | + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); |
|
293 | + |
|
294 | + #curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1); |
|
295 | + #curl_setopt($ch, CURLOPT_PROXY, 'localhost:8888'); |
|
296 | + |
|
297 | + $response = curl_exec($ch); |
|
298 | + $response = json_decode($response, true); |
|
299 | + $status = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
|
300 | + $error = curl_error($ch); |
|
301 | + |
|
302 | + curl_close($ch); |
|
303 | + |
|
304 | + switch ($status) |
|
305 | + { |
|
306 | + case 0: |
|
307 | + throw new \Exception(sprintf('Unable to connect. Is NZBVortex running? Is your API key correct? Is something blocking ports? (Err: %s)', $error)); |
|
308 | + break; |
|
309 | + |
|
310 | + case 200: |
|
311 | + return $response; |
|
312 | + break; |
|
313 | + |
|
314 | + case 403: |
|
315 | + throw new \Exception('Unable to login. Is your API key correct?'); |
|
316 | + break; |
|
317 | + |
|
318 | + default: |
|
319 | + throw new \Exception(sprintf("%s (%s): %s", $path, $status, $response['result'])); |
|
320 | + break; |
|
321 | + } |
|
322 | + } |
|
323 | 323 | } |
@@ -71,10 +71,10 @@ discard block |
||
71 | 71 | { |
72 | 72 | if($refdate !== Null){ |
73 | 73 | if(is_string($refdate)){ |
74 | - // ensure we're in the right format |
|
74 | + // ensure we're in the right format |
|
75 | 75 | $refdate=date("Y-m-d H:i:s", strtotime($refdate)); |
76 | 76 | }else if(is_int($refdate)){ |
77 | - // ensure we're in the right format |
|
77 | + // ensure we're in the right format |
|
78 | 78 | $refdate=date("Y-m-d H:i:s", $refdate); |
79 | 79 | }else{ |
80 | 80 | // leave it as null (bad content anyhow) |
@@ -87,9 +87,9 @@ discard block |
||
87 | 87 | if($refdate !== Null) |
88 | 88 | $clause[] = "createddate >= '$refdate'"; |
89 | 89 | |
90 | - // set localOnly to Null to include both local and remote |
|
91 | - // set localOnly to true to only receive local comment count |
|
92 | - // set localOnly to false to only receive remote comment count |
|
90 | + // set localOnly to Null to include both local and remote |
|
91 | + // set localOnly to true to only receive local comment count |
|
92 | + // set localOnly to false to only receive remote comment count |
|
93 | 93 | if($localOnly === true){ |
94 | 94 | $clause[] = "sourceid = 0"; |
95 | 95 | }else if($localOnly === false){ |
@@ -101,8 +101,8 @@ |
||
101 | 101 | public $releaseImage; |
102 | 102 | |
103 | 103 | /** |
104 | - * @var int Time (hours) to wait before creating a stuck collection into a release. |
|
105 | - */ |
|
104 | + * @var int Time (hours) to wait before creating a stuck collection into a release. |
|
105 | + */ |
|
106 | 106 | private $collectionTimeout; |
107 | 107 | |
108 | 108 | /** |
@@ -203,7 +203,6 @@ |
||
203 | 203 | /** |
204 | 204 | * Calls the API to lookup the TvMaze info for a given TVDB or TVRage ID |
205 | 205 | * Returns a formatted array of show data or false if no match |
206 | - |
|
207 | 206 | * @param $site |
208 | 207 | * @param $siteId |
209 | 208 | * |
@@ -127,16 +127,16 @@ |
||
127 | 127 | abstract protected function formatEpisodeInfo($episode); |
128 | 128 | |
129 | 129 | /** |
130 | - * Retrieve releases for TV processing |
|
131 | - * Returns a PDO Object of rows or false if none found |
|
132 | - * |
|
133 | - * @param string $groupID -- ID of the usenet group to process |
|
134 | - * @param string $guidChar -- threading method by first guid character |
|
135 | - * @param int $lookupSetting -- whether or not to use the API |
|
136 | - * @param int $status -- release processing status of tv_episodes_id |
|
137 | - * |
|
138 | - * @return false|int|\PDOStatement |
|
139 | - */ |
|
130 | + * Retrieve releases for TV processing |
|
131 | + * Returns a PDO Object of rows or false if none found |
|
132 | + * |
|
133 | + * @param string $groupID -- ID of the usenet group to process |
|
134 | + * @param string $guidChar -- threading method by first guid character |
|
135 | + * @param int $lookupSetting -- whether or not to use the API |
|
136 | + * @param int $status -- release processing status of tv_episodes_id |
|
137 | + * |
|
138 | + * @return false|int|\PDOStatement |
|
139 | + */ |
|
140 | 140 | public function getTvReleases($groupID = '', $guidChar = '', $lookupSetting = 1, $status = 0) |
141 | 141 | { |
142 | 142 | $ret = 0; |
@@ -12,10 +12,10 @@ discard block |
||
12 | 12 | public $zipcount = 0; |
13 | 13 | public $videocount = 0; |
14 | 14 | public $audiocount = 0; |
15 | - public $imgcount = 0; |
|
16 | - public $srrcount = 0; |
|
17 | - public $txtcount = 0; |
|
18 | - public $sfvcount = 0; |
|
15 | + public $imgcount = 0; |
|
16 | + public $srrcount = 0; |
|
17 | + public $txtcount = 0; |
|
18 | + public $sfvcount = 0; |
|
19 | 19 | public $filesize = 0; |
20 | 20 | public $poster = ''; |
21 | 21 | public $postedfirst = 0; |
@@ -31,27 +31,27 @@ discard block |
||
31 | 31 | public $mediafiles = []; |
32 | 32 | public $audiofiles = []; |
33 | 33 | public $rarfiles = []; |
34 | - public $imgfiles = []; |
|
35 | - public $srrfiles = []; |
|
36 | - public $txtfiles = []; |
|
37 | - public $sfvfiles = []; |
|
34 | + public $imgfiles = []; |
|
35 | + public $srrfiles = []; |
|
36 | + public $txtfiles = []; |
|
37 | + public $sfvfiles = []; |
|
38 | 38 | public $segmentfiles = []; |
39 | - public $parfiles = []; |
|
39 | + public $parfiles = []; |
|
40 | 40 | |
41 | - private $isLoaded = false; |
|
41 | + private $isLoaded = false; |
|
42 | 42 | private $loadAllVars = false; |
43 | 43 | |
44 | 44 | public function __construct() |
45 | 45 | { |
46 | - $this->nfofileregex = '/[ "\(\[].*?\.(nfo|ofn)[ "\)\]]/iS'; |
|
47 | - $this->mediafileregex = '/.*\.(AVI|VOB|MKV|MP4|TS|WMV|MOV|M4V|F4V|MPG|MPEG)(\.001)?[ "\)\]]/iS'; |
|
48 | - $this->audiofileregex = '/\.(MP3|FLAC|AAC|OGG|AIFF)[ "\)\]]/iS'; |
|
49 | - $this->rarfileregex = '/.*\W(?:part0*1|(?!part\d+)[^.]+)\.(rar|001)[ "\)\]]/iS'; |
|
50 | - $this->imgfileregex = '/\.(jpe?g|gif)[ "\)\]]/iS'; |
|
51 | - $this->srrfileregex = '/\.(srr)[ "\)\]]/iS'; |
|
52 | - $this->txtfileregex = '/\.(txt)[ "\)\]]/iS'; |
|
53 | - $this->sfvfileregex = '/\.(sfv)[ "\)\]]/iS'; |
|
54 | - } |
|
46 | + $this->nfofileregex = '/[ "\(\[].*?\.(nfo|ofn)[ "\)\]]/iS'; |
|
47 | + $this->mediafileregex = '/.*\.(AVI|VOB|MKV|MP4|TS|WMV|MOV|M4V|F4V|MPG|MPEG)(\.001)?[ "\)\]]/iS'; |
|
48 | + $this->audiofileregex = '/\.(MP3|FLAC|AAC|OGG|AIFF)[ "\)\]]/iS'; |
|
49 | + $this->rarfileregex = '/.*\W(?:part0*1|(?!part\d+)[^.]+)\.(rar|001)[ "\)\]]/iS'; |
|
50 | + $this->imgfileregex = '/\.(jpe?g|gif)[ "\)\]]/iS'; |
|
51 | + $this->srrfileregex = '/\.(srr)[ "\)\]]/iS'; |
|
52 | + $this->txtfileregex = '/\.(txt)[ "\)\]]/iS'; |
|
53 | + $this->sfvfileregex = '/\.(sfv)[ "\)\]]/iS'; |
|
54 | + } |
|
55 | 55 | |
56 | 56 | public function loadFromString($str, $loadAllVars=false) |
57 | 57 | { |
@@ -68,39 +68,39 @@ discard block |
||
68 | 68 | return $this->isLoaded; |
69 | 69 | } |
70 | 70 | |
71 | - public function loadFromFile($loc, $loadAllVars=false) |
|
72 | - { |
|
73 | - $this->source = $loc; |
|
74 | - $this->loadAllVars = $loadAllVars; |
|
75 | - |
|
76 | - if (file_exists($loc)) |
|
77 | - { |
|
78 | - if (preg_match('/\.(gz|zip)$/i', $loc, $ext)) |
|
79 | - { |
|
80 | - switch(strtolower($ext[1])) |
|
81 | - { |
|
82 | - case 'gz': |
|
83 | - $loc = 'compress.zlib://'.$loc; |
|
84 | - break; |
|
85 | - case 'zip': |
|
86 | - $zip = new ZipArchive; |
|
87 | - if ($zip->open($loc) === true && $zip->numFiles == 1) |
|
88 | - return $this->loadFromString($zip->getFromIndex(0), $loadAllVars); |
|
89 | - else |
|
90 | - $loc = 'zip://'.$loc; |
|
91 | - break; |
|
92 | - } |
|
93 | - } |
|
94 | - |
|
95 | - libxml_use_internal_errors(true); |
|
96 | - $xmlObj = @simplexml_load_file($loc); |
|
97 | - if ($this->isValidNzb($xmlObj)) |
|
98 | - $this->parseNzb($xmlObj); |
|
99 | - |
|
100 | - unset($xmlObj); |
|
101 | - } |
|
102 | - return $this->isLoaded; |
|
103 | - } |
|
71 | + public function loadFromFile($loc, $loadAllVars=false) |
|
72 | + { |
|
73 | + $this->source = $loc; |
|
74 | + $this->loadAllVars = $loadAllVars; |
|
75 | + |
|
76 | + if (file_exists($loc)) |
|
77 | + { |
|
78 | + if (preg_match('/\.(gz|zip)$/i', $loc, $ext)) |
|
79 | + { |
|
80 | + switch(strtolower($ext[1])) |
|
81 | + { |
|
82 | + case 'gz': |
|
83 | + $loc = 'compress.zlib://'.$loc; |
|
84 | + break; |
|
85 | + case 'zip': |
|
86 | + $zip = new ZipArchive; |
|
87 | + if ($zip->open($loc) === true && $zip->numFiles == 1) |
|
88 | + return $this->loadFromString($zip->getFromIndex(0), $loadAllVars); |
|
89 | + else |
|
90 | + $loc = 'zip://'.$loc; |
|
91 | + break; |
|
92 | + } |
|
93 | + } |
|
94 | + |
|
95 | + libxml_use_internal_errors(true); |
|
96 | + $xmlObj = @simplexml_load_file($loc); |
|
97 | + if ($this->isValidNzb($xmlObj)) |
|
98 | + $this->parseNzb($xmlObj); |
|
99 | + |
|
100 | + unset($xmlObj); |
|
101 | + } |
|
102 | + return $this->isLoaded; |
|
103 | + } |
|
104 | 104 | |
105 | 105 | public function summarize() |
106 | 106 | { |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | $out[] = ' -size: '.round(($this->filesize / 1048576), 2).' MB in '.$this->filecount.' Files'; |
130 | 130 | $out[] = ' -'.$this->rarcount.' rars'; |
131 | 131 | $out[] = ' -'.$this->parcount.' pars'; |
132 | - $out[] = ' -'.$this->sfvcount.' sfvs'; |
|
132 | + $out[] = ' -'.$this->sfvcount.' sfvs'; |
|
133 | 133 | $out[] = ' -'.$this->zipcount.' zips'; |
134 | 134 | $out[] = ' -'.$this->videocount.' videos'; |
135 | 135 | $out[] = ' -'.$this->audiocount.' audios'; |
@@ -146,7 +146,7 @@ discard block |
||
146 | 146 | if (!$xmlObj || strtolower($xmlObj->getName()) != 'nzb' || !isset($xmlObj->file)) |
147 | 147 | return false; |
148 | 148 | |
149 | - return true; |
|
149 | + return true; |
|
150 | 150 | } |
151 | 151 | |
152 | 152 | private function parseNzb($xmlObj) |
@@ -216,27 +216,27 @@ discard block |
||
216 | 216 | $fileArr['filesize'] += $bytes; |
217 | 217 | $fileArr['segmentactual']++; |
218 | 218 | $fileArr['segments'][$number] = (string) $segment; |
219 | - $fileArr['segmentbytes'][$number] = $bytes; |
|
219 | + $fileArr['segmentbytes'][$number] = $bytes; |
|
220 | + } |
|
221 | + |
|
222 | + $pattern = '|\((\d+)[\/](\d+)\)|i'; |
|
223 | + preg_match_all($pattern, $subject, $matches, PREG_PATTERN_ORDER); |
|
224 | + $matchcnt = sizeof($matches[0]); |
|
225 | + $msgPart = $msgTotalParts = 0; |
|
226 | + for ($i=0; $i<$matchcnt; $i++) |
|
227 | + { |
|
228 | + //not (int)'d here because of the preg_replace later on |
|
229 | + $msgPart = $matches[1][$i]; |
|
230 | + $msgTotalParts = $matches[2][$i]; |
|
220 | 231 | } |
232 | + if((int)$msgPart > 0 && (int)$msgTotalParts > 0) |
|
233 | + { |
|
234 | + $this->segmenttotal += (int) $msgTotalParts; |
|
235 | + $fileArr['segmenttotal'] = (int) $msgTotalParts; |
|
236 | + $fileArr['completion'] = number_format(($fileArr['segmentactual']/$fileArr['segmenttotal'])*100, 0); |
|
221 | 237 | |
222 | - $pattern = '|\((\d+)[\/](\d+)\)|i'; |
|
223 | - preg_match_all($pattern, $subject, $matches, PREG_PATTERN_ORDER); |
|
224 | - $matchcnt = sizeof($matches[0]); |
|
225 | - $msgPart = $msgTotalParts = 0; |
|
226 | - for ($i=0; $i<$matchcnt; $i++) |
|
227 | - { |
|
228 | - //not (int)'d here because of the preg_replace later on |
|
229 | - $msgPart = $matches[1][$i]; |
|
230 | - $msgTotalParts = $matches[2][$i]; |
|
231 | - } |
|
232 | - if((int)$msgPart > 0 && (int)$msgTotalParts > 0) |
|
233 | - { |
|
234 | - $this->segmenttotal += (int) $msgTotalParts; |
|
235 | - $fileArr['segmenttotal'] = (int) $msgTotalParts; |
|
236 | - $fileArr['completion'] = number_format(($fileArr['segmentactual']/$fileArr['segmenttotal'])*100, 0); |
|
237 | - |
|
238 | - $fileArr['subject'] = utf8_encode(trim(preg_replace('|\('.$msgPart.'[\/]'.$msgTotalParts.'\)|i', '', $subject))); |
|
239 | - } |
|
238 | + $fileArr['subject'] = utf8_encode(trim(preg_replace('|\('.$msgPart.'[\/]'.$msgTotalParts.'\)|i', '', $subject))); |
|
239 | + } |
|
240 | 240 | |
241 | 241 | //file counts |
242 | 242 | $this->filecount++; |
@@ -268,36 +268,36 @@ discard block |
||
268 | 268 | $this->audiocount++; |
269 | 269 | } |
270 | 270 | |
271 | - if (preg_match($this->imgfileregex, $subject) && !preg_match('/\.(par2|vol\d+\+|sfv|nzb)/iS', $subject)) |
|
272 | - { |
|
273 | - $this->imgfiles[] = $fileArr; |
|
274 | - $this->imgcount++; |
|
275 | - } |
|
276 | - |
|
277 | - if (preg_match($this->srrfileregex, $subject) && !preg_match('/\.(par2|vol\d+\+|sfv|nzb)/iS', $subject)) |
|
278 | - { |
|
279 | - $this->srrfiles[] = $fileArr; |
|
280 | - $this->srrcount++; |
|
281 | - } |
|
282 | - |
|
283 | - if (preg_match($this->txtfileregex, $subject) && !preg_match('/\.(par2|vol\d+\+|sfv|nzb)/iS', $subject)) |
|
284 | - { |
|
285 | - $this->txtfiles[] = $fileArr; |
|
286 | - $this->txtcount++; |
|
287 | - } |
|
288 | - |
|
289 | - if (preg_match($this->sfvfileregex, $subject) && !preg_match('/\.(par2|vol\d+\+|nzb)/iS', $subject)) |
|
290 | - { |
|
291 | - $this->sfvfiles[] = $fileArr; |
|
292 | - $this->sfvcount++; |
|
293 | - } |
|
294 | - |
|
295 | - if (preg_match('/\.par2(?!\.)/iS', $subject)) |
|
296 | - { |
|
297 | - $this->parcount++; |
|
298 | - if (!preg_match('/(vol\d+\+|vol[_\.\s]\d)/iS', $subject) && $fileArr['segmenttotal'] < 3) |
|
299 | - $this->parfiles[] = $fileArr; |
|
300 | - } |
|
271 | + if (preg_match($this->imgfileregex, $subject) && !preg_match('/\.(par2|vol\d+\+|sfv|nzb)/iS', $subject)) |
|
272 | + { |
|
273 | + $this->imgfiles[] = $fileArr; |
|
274 | + $this->imgcount++; |
|
275 | + } |
|
276 | + |
|
277 | + if (preg_match($this->srrfileregex, $subject) && !preg_match('/\.(par2|vol\d+\+|sfv|nzb)/iS', $subject)) |
|
278 | + { |
|
279 | + $this->srrfiles[] = $fileArr; |
|
280 | + $this->srrcount++; |
|
281 | + } |
|
282 | + |
|
283 | + if (preg_match($this->txtfileregex, $subject) && !preg_match('/\.(par2|vol\d+\+|sfv|nzb)/iS', $subject)) |
|
284 | + { |
|
285 | + $this->txtfiles[] = $fileArr; |
|
286 | + $this->txtcount++; |
|
287 | + } |
|
288 | + |
|
289 | + if (preg_match($this->sfvfileregex, $subject) && !preg_match('/\.(par2|vol\d+\+|nzb)/iS', $subject)) |
|
290 | + { |
|
291 | + $this->sfvfiles[] = $fileArr; |
|
292 | + $this->sfvcount++; |
|
293 | + } |
|
294 | + |
|
295 | + if (preg_match('/\.par2(?!\.)/iS', $subject)) |
|
296 | + { |
|
297 | + $this->parcount++; |
|
298 | + if (!preg_match('/(vol\d+\+|vol[_\.\s]\d)/iS', $subject) && $fileArr['segmenttotal'] < 3) |
|
299 | + $this->parfiles[] = $fileArr; |
|
300 | + } |
|
301 | 301 | |
302 | 302 | if (preg_match('/\.zip(?!\.)/i', $subject) && !preg_match('/\.(par2|vol\d+\+|sfv|nzb)/i', $subject)) |
303 | 303 | $this->zipcount++; |
@@ -319,40 +319,40 @@ discard block |
||
319 | 319 | return $this->isLoaded; |
320 | 320 | } |
321 | 321 | |
322 | - public function toNzb() |
|
323 | - { |
|
324 | - if ($this->loadAllVars === false) |
|
325 | - return false; |
|
326 | - |
|
327 | - $nzb = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; |
|
328 | - $nzb .= "<!DOCTYPE nzb PUBLIC \"-//newzBin//DTD NZB 1.1//EN\" \"http://www.newzbin.com/DTD/nzb/nzb-1.1.dtd\">\n"; |
|
329 | - $nzb .= "<nzb xmlns=\"http://www.newzbin.com/DTD/2003/nzb\">\n\n"; |
|
330 | - if (!empty($this->metadata)) |
|
331 | - { |
|
332 | - $nzb .= "<head>\n"; |
|
322 | + public function toNzb() |
|
323 | + { |
|
324 | + if ($this->loadAllVars === false) |
|
325 | + return false; |
|
326 | + |
|
327 | + $nzb = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; |
|
328 | + $nzb .= "<!DOCTYPE nzb PUBLIC \"-//newzBin//DTD NZB 1.1//EN\" \"http://www.newzbin.com/DTD/nzb/nzb-1.1.dtd\">\n"; |
|
329 | + $nzb .= "<nzb xmlns=\"http://www.newzbin.com/DTD/2003/nzb\">\n\n"; |
|
330 | + if (!empty($this->metadata)) |
|
331 | + { |
|
332 | + $nzb .= "<head>\n"; |
|
333 | 333 | $out = []; |
334 | - foreach($this->metadata as $mk=>$mv) |
|
335 | - $out[] = ' <meta type="'.$mk.'">'.$mv."</meta>\n"; |
|
336 | - $nzb .= "</head>\n"; |
|
337 | - } |
|
338 | - foreach($this->nzb as $postFile) |
|
339 | - { |
|
340 | - $nzb .= "<file poster=\"".htmlspecialchars($postFile["poster"], ENT_QUOTES, 'utf-8')."\" date=\"".$postFile["posted"]."\" subject=\"".htmlspecialchars($postFile["subject"], ENT_QUOTES, 'utf-8')." (1/".$postFile["segmenttotal"].")\">\n"; |
|
341 | - $nzb .= " <groups>\n"; |
|
342 | - foreach($postFile['groups'] as $fileGroup) |
|
343 | - { |
|
344 | - $nzb .= " <group>".$fileGroup."</group>\n"; |
|
345 | - } |
|
346 | - $nzb .= " </groups>\n"; |
|
347 | - $nzb .= " <segments>\n"; |
|
348 | - foreach($postFile['segments'] as $fileSegmentNum=>$fileSegment) |
|
349 | - { |
|
350 | - $nzb .= " <segment bytes=\"".$postFile['segmentbytes'][$fileSegmentNum]."\" number=\"".$fileSegmentNum."\">".htmlspecialchars($fileSegment, ENT_QUOTES, 'utf-8')."</segment>\n"; |
|
351 | - } |
|
352 | - $nzb .= " </segments>\n</file>\n"; |
|
353 | - } |
|
354 | - $nzb .= "<!-- nntmux ".date("Y-m-d H:i:s")." -->\n</nzb>"; |
|
355 | - |
|
356 | - return $nzb; |
|
357 | - } |
|
334 | + foreach($this->metadata as $mk=>$mv) |
|
335 | + $out[] = ' <meta type="'.$mk.'">'.$mv."</meta>\n"; |
|
336 | + $nzb .= "</head>\n"; |
|
337 | + } |
|
338 | + foreach($this->nzb as $postFile) |
|
339 | + { |
|
340 | + $nzb .= "<file poster=\"".htmlspecialchars($postFile["poster"], ENT_QUOTES, 'utf-8')."\" date=\"".$postFile["posted"]."\" subject=\"".htmlspecialchars($postFile["subject"], ENT_QUOTES, 'utf-8')." (1/".$postFile["segmenttotal"].")\">\n"; |
|
341 | + $nzb .= " <groups>\n"; |
|
342 | + foreach($postFile['groups'] as $fileGroup) |
|
343 | + { |
|
344 | + $nzb .= " <group>".$fileGroup."</group>\n"; |
|
345 | + } |
|
346 | + $nzb .= " </groups>\n"; |
|
347 | + $nzb .= " <segments>\n"; |
|
348 | + foreach($postFile['segments'] as $fileSegmentNum=>$fileSegment) |
|
349 | + { |
|
350 | + $nzb .= " <segment bytes=\"".$postFile['segmentbytes'][$fileSegmentNum]."\" number=\"".$fileSegmentNum."\">".htmlspecialchars($fileSegment, ENT_QUOTES, 'utf-8')."</segment>\n"; |
|
351 | + } |
|
352 | + $nzb .= " </segments>\n</file>\n"; |
|
353 | + } |
|
354 | + $nzb .= "<!-- nntmux ".date("Y-m-d H:i:s")." -->\n</nzb>"; |
|
355 | + |
|
356 | + return $nzb; |
|
357 | + } |
|
358 | 358 | } |
@@ -281,7 +281,7 @@ |
||
281 | 281 | { |
282 | 282 | $title = preg_replace('/[^\w]/', '', $title); |
283 | 283 | $searchtitle = preg_replace('/[^\w]/', '', $searchtitle); |
284 | - similar_text($title , $searchtitle, $p); |
|
284 | + similar_text($title , $searchtitle, $p); |
|
285 | 285 | if ($p == 100) { |
286 | 286 | return true; |
287 | 287 | } else { |
@@ -18,26 +18,26 @@ |
||
18 | 18 | */ |
19 | 19 | function smarty_make_timestamp($string) |
20 | 20 | { |
21 | - if (empty($string)) { |
|
22 | - // use "now": |
|
23 | - return time(); |
|
24 | - } elseif ($string instanceof DateTime || (interface_exists('DateTimeInterface', false) && $string instanceof DateTimeInterface)) { |
|
25 | - return (int) $string->format('U'); // PHP 5.2 BC |
|
26 | - } elseif (strlen($string) == 14 && ctype_digit($string)) { |
|
27 | - // it is mysql timestamp format of YYYYMMDDHHMMSS? |
|
28 | - return mktime(substr($string, 8, 2), substr($string, 10, 2), substr($string, 12, 2), |
|
29 | - substr($string, 4, 2), substr($string, 6, 2), substr($string, 0, 4)); |
|
30 | - } elseif (is_numeric($string)) { |
|
31 | - // it is a numeric string, we handle it as timestamp |
|
32 | - return (int) $string; |
|
33 | - } else { |
|
34 | - // strtotime should handle it |
|
35 | - $time = strtotime($string); |
|
36 | - if ($time == - 1 || $time === false) { |
|
37 | - // strtotime() was not able to parse $string, use "now": |
|
38 | - return time(); |
|
39 | - } |
|
21 | + if (empty($string)) { |
|
22 | + // use "now": |
|
23 | + return time(); |
|
24 | + } elseif ($string instanceof DateTime || (interface_exists('DateTimeInterface', false) && $string instanceof DateTimeInterface)) { |
|
25 | + return (int) $string->format('U'); // PHP 5.2 BC |
|
26 | + } elseif (strlen($string) == 14 && ctype_digit($string)) { |
|
27 | + // it is mysql timestamp format of YYYYMMDDHHMMSS? |
|
28 | + return mktime(substr($string, 8, 2), substr($string, 10, 2), substr($string, 12, 2), |
|
29 | + substr($string, 4, 2), substr($string, 6, 2), substr($string, 0, 4)); |
|
30 | + } elseif (is_numeric($string)) { |
|
31 | + // it is a numeric string, we handle it as timestamp |
|
32 | + return (int) $string; |
|
33 | + } else { |
|
34 | + // strtotime should handle it |
|
35 | + $time = strtotime($string); |
|
36 | + if ($time == - 1 || $time === false) { |
|
37 | + // strtotime() was not able to parse $string, use "now": |
|
38 | + return time(); |
|
39 | + } |
|
40 | 40 | |
41 | - return $time; |
|
42 | - } |
|
41 | + return $time; |
|
42 | + } |
|
43 | 43 | } |