Example #1
0
 /**
  * Ajoute un commentaire sur un torrent
  * 
  * @param $slug Slug du torrent
  * @param $id Id tu torrent
  */
 public function torrent($slug, $id)
 {
     $torrent = Torrent::find($id);
     $user = Auth::user();
     $comment = new Comment();
     $comment->content = Input::get('content');
     $comment->user_id = $user->id;
     $comment->torrent_id = $torrent->id;
     $v = Validator::make($comment->toArray(), array('content' => 'required', 'user_id' => 'required', 'torrent_id' => 'required'));
     if ($v->passes()) {
         $comment->save();
         Session::put('message', 'Your comment has been added');
     } else {
         Session::put('message', 'An error has occurred');
     }
     return Redirect::route('torrent', array('slug' => $torrent->slug, 'id' => $torrent->id));
 }
Example #2
0
 /**
  * Telecharge le torrent
  *
  * @access public
  * @param string $slug Slug du torrent
  * @param int $id Id du torrent 
  * @return file
  */
 public function download($slug, $id)
 {
     // Find the torrent in the database
     $torrent = Torrent::find($id);
     if (Auth::check()) {
         // Current user is the logged in user
         $user = Auth::user();
         // User's ratio is too low
         if ($user->getDownloaded() / $user->getUploaded() < Config::get('other.ratio') && Config::get('other.freeleech') == false) {
             return Redirect::route('torrent', ['slug' => $torrent->slug, 'id' => $torrent->id])->with('message', 'You can\'t download torrents anymore your ratio is too low');
         }
     } else {
         $user = null;
     }
     // Define the filename for the download
     $tmpFileName = $torrent->slug . '.torrent';
     // The torrent file exist ?
     if (!file_exists(getcwd() . '/files/torrents/' . $torrent->file_name)) {
         return Redirect::route('torrent', array('slug' => $torrent->slug, 'id' => $torrent->id))->with('message', 'The torrent file is currently unavailable');
     } else {
         // Delete the last torrent tmp file
         if (file_exists(getcwd() . '/files/tmp/' . $tmpFileName)) {
             unlink(getcwd() . '/files/tmp/' . $tmpFileName);
         }
     }
     // Get the content of the torrent
     $dict = Bencode::bdecode(file_get_contents(getcwd() . '/files/torrents/' . $torrent->file_name));
     // Freeleech ?
     if (Config::get('other.freeleech') == true) {
         // Set the announce key only
         $dict['announce'] = route('announce');
     } else {
         if (Auth::check()) {
             // Set the announce key and add the user passkey
             $dict['announce'] = route('announce', array('passkey' => $user->passkey));
             // Remove Other announce url
             unset($dict['announce-list']);
         } else {
             return Redirect::to('/login');
         }
     }
     $fileToDownload = Bencode::bencode($dict);
     file_put_contents(getcwd() . '/files/tmp/' . $tmpFileName, $fileToDownload);
     return Response::download(getcwd() . '/files/tmp/' . $tmpFileName);
 }
Example #3
0
 public function getDownload($id)
 {
     $torrent = Torrent::find($id);
     if (!$torrent) {
         App::abort(404);
     }
     $torrent->downloads += 1;
     $torrent->save();
     $decoded = Bencode::decode($torrent->file);
     $decoded['announce'] = Config::get('app.url') . '/announce/' . $torrent->id . '/' . Auth::user()->id;
     unset($decoded['announce-list']);
     $torrent->file = Bencode::encode($decoded);
     $response = Response::make($torrent->file, 200);
     $response->header('Content-Type', 'application/x-bittorrent');
     // http://x-bittorrent.mime-application.com/
     $response->header('Content-Disposition', 'attachment; filename=' . $torrent->name . '.torrent');
     // http://stackoverflow.com/questions/93551/how-to-encode-the-filename-parameter-of-content-disposition-header-in-http
     return $response;
 }
Example #4
0
 function __construct($params = array())
 {
     $this->cid = $params['cid'];
     $this->body = $params['body'];
     $this->torrent = Torrent::find(array('fid' => $params['file_fid']));
     $this->user = User::find(array('uid' => $params['user_uid']));
     $this->ctime = $params['ctime'];
 }
Example #5
0
 public static function delete($fid, $user)
 {
     $torrent = Torrent::find(array('fid' => $fid));
     if (!$torrent) {
         return array('status' => false, 'message' => 'The torrent was not found!');
     }
     if (!$torrent->has_access(array('user' => $user))) {
         return array('status' => false, 'message' => 'You are not authorized to delete the specified torrent!');
     }
     $query_torrent = "UPDATE xbt_files SET flags = 1 WHERE fid = " . DB::escape($fid);
     $query_paths = "DELETE FROM xbt_paths WHERE torrent_fid = " . DB::escape($fid);
     if (DB::query($query_torrent, true) and DB::query($query_paths, true)) {
         return array('status' => true, 'message' => 'The torrent was successfully deleted. Congratulations!');
     } else {
         return array('status' => false, 'message' => 'The torrent was not deleted.');
     }
 }
Example #6
0
 public function actionEdit($fid = null)
 {
     $active_user = User::require_active_user();
     $this->setLayoutVar('active_user', $active_user);
     $this->setVar('active_user', $active_user);
     //Edit &mdash; <?php echo $torrent->title;
     if (is_null($fid)) {
         throw new Lvc_Exception('Null fid on edit action');
     }
     if ($torrent = Torrent::find(array('fid' => $fid))) {
         if ($torrent->has_access(array('user' => $active_user))) {
             if (!empty($this->post['submit'])) {
                 $result = Torrent::edit($fid, $this->post['title'], $this->post['description'], $this->post['category_cid'], $active_user);
                 if ($result['status']) {
                     Flash::set('success', $result['message']);
                     $this->redirect('/torrent/' . $fid);
                     die;
                 } else {
                     $this->setVar('fail_message', $result['message']);
                 }
             }
             $categories = Category::find_all();
             $this->setVar('categories', $categories);
             $this->setVar('torrent', $torrent);
             $this->setLayoutVar('pageHead', 'Edit &mdash; ' . $torrent->title);
             $this->setLayoutVar('pageTitle', 'Edit - ' . $torrent->title);
         } else {
             throw new Lvc_Exception('Unauthorized user: '******' tried to edit torrent: ' . $torrent->fid);
         }
     } else {
         throw new Lvc_Exception('Torrent Not Found: ' . $fid);
     }
 }