Ejemplo n.º 1
0
 protected function process()
 {
     $torrent = new Transform_Torrent($this->file);
     if (!$torrent->is_valid()) {
         throw new Error_Upload(Error_Upload::NOT_A_TORRENT);
     }
     $torrent->delete('announce-list');
     $torrent->set('announce', def::tracker('announce'));
     $data = $torrent->encode();
     $hash = $torrent->get_hash();
     $post_id = Database::get_field('post_torrent', 'post_id', 'hash = ?', $hash);
     if ($post_id) {
         throw new Error_Upload(Error_Upload::ALREADY_EXISTS);
     }
     $filename = pathinfo(urldecode($this->name), PATHINFO_FILENAME);
     $filename = Transform_File::make_name($filename);
     $filename = substr($filename, 0, 200) . '.torrent';
     if (!is_dir(FILES . SL . 'torrent' . SL . $hash)) {
         mkdir(FILES . SL . 'torrent' . SL . $hash, 0755);
     }
     $newfile = FILES . SL . 'torrent' . SL . $hash . SL . $filename;
     file_put_contents($newfile, $data);
     $size = $torrent->get_size();
     $size = Transform_File::weight_short($size);
     $return_data = '<input size="24%" type="text" name="torrent[0][name]" value="Скачать" />:' . "\n" . '<input readonly size="24%" type="text" name="torrent[0][file]" value="' . $filename . '" />' . "\n" . '<input type="hidden" name="torrent[0][hash]" value="' . $hash . '" />' . "\n" . '<input readonly size="4%" type="text" name="torrent[0][size]" value="' . $size . '" />' . "\n" . '<input type="submit" class="disabled sign remove_link" rel="torrent" value="-" />';
     $this->set(array('success' => true, 'data' => $return_data, 'file' => $filename, 'hash' => $hash, 'name' => 'Скачать', 'size' => $size));
 }
Ejemplo n.º 2
0
 protected function get_torrent_size()
 {
     $file = $this->get('file');
     $hash = $this->get('hash');
     if (empty($file) || empty($hash)) {
         return 0;
     }
     $path = FILES . SL . 'torrent' . SL . $hash . SL . $file;
     $torrent = new Transform_Torrent($path);
     if ($torrent->get_hash() != $hash) {
         throw new Error('Incorrect torrent hash');
     }
     $size = $torrent->get_size();
     $type = 0;
     while ($size > 1024) {
         $type++;
         $size = $size / 1024;
     }
     $this->set('size', $size);
     $this->set('sizetype', $type);
 }