public static function post($file_fid, $body, $user_uid) { //$body = strip_tags($body, "<br><a><strong><em>"); // Replace new lines with br, and limit the number of sucessive new // lines to 2. //$body = nl2br(preg_replace('/\n(\s)*\n/',"\n\n",$body)); $body = sanitize_body_text($body); // Verify title wasn't garbage if (empty($body)) { return array('status' => false, 'message' => 'You must enter a comment'); } if (empty($file_fid)) { return array('status' => false, 'message' => 'No torrent was given'); } if (empty($user_uid)) { return array('status' => false, 'message' => 'The comment must be from someone'); } $query = "INSERT INTO xbt_comments (file_fid, user_uid, body, ctime) VALUES (" . DB::escape($file_fid) . ", " . DB::escape($user_uid) . ", '" . DB::escape($body) . "', unix_timestamp())"; if ($results = DB::query($query, true)) { return array('status' => true, 'message' => 'Your comment has been posted.'); } else { return array('status' => false, 'message' => 'The comment could not be posted at this time.'); } }
public static function upload($title, $description, $category_cid, $file, $user) { // Verify title wasn't garbage if (strlen($title) < 2) { return array('status' => false, 'message' => 'The torrent\'s title is too short!'); } // Verify category was set properly if (!Category::find(array('cid' => $category_cid))) { return array('status' => false, 'message' => 'The specified category does not exist!'); } // Grab the metainfo for the torrent $metainfo = new File_Bittorrent2_Decode(); try { $metainfo->decodeFile($file['tmp_name']); } catch (File_Bittorrent2_Exception $e) { return array('status' => false, 'message' => 'The .torrent file was either invalid or corrupt!'); } // Ensure metainfo is private if (!$metainfo->getPrivate()) { return array('status' => false, 'message' => 'Your torrent is not flagged as private! Please recreate it as a private torrent before attempting to add it again.'); } // Ensure tracker was set properly if (!$metainfo->getAnnounce() == $user->url_announce) { return array('status' => false, 'message' => 'The announce URL is not properly set in the torrent!'); } // Ensure metainfo is unique $info_hash = '0x' . $metainfo->getInfoHash(); $query = 'SELECT * FROM xbt_files WHERE info_hash = ' . $info_hash; $results = DB::query($query); if (mysql_num_rows($results) > 0) { return array('status' => false, 'message' => 'Duplicate torrent detected! Either you or somebody else already added it.'); } // Grab basic metainfo properties $path = DB::escape(basename($file['name'])); $title = DB::escape($title); $description = sanitize_body_text($description); $description = DB::escape($description); $size = 0; $user_uid = $user->uid; // Get total torrent size foreach ($metainfo->getFiles() as $f) { $size += $f['size']; } // Insert metainfo into database $query = "INSERT INTO xbt_files (info_hash, mtime, ctime, path, title, description, size, user_uid, category_cid) VALUES (" . $info_hash . ", unix_timestamp(), unix_timestamp(), '" . $path . "', '" . $title . "', '" . $description . "', " . $size . ", " . $user_uid . ", " . $category_cid . ")"; $results = DB::query($query, true); // Grab the metainfo_id of the newly inserted metainfo $handle = DB::get_handle(); $metainfo_id = mysql_insert_id($handle); foreach ($metainfo->getFiles() as $f) { $f_path = DB::escape($f['filename']); $f_size = DB::escape($f['size']); $query = "INSERT INTO xbt_paths (torrent_fid, path, size) VALUES (" . $metainfo_id . ", '" . $f_path . "', " . $f_size . ")"; $results = DB::query($query, true); } // Move .torrent to path using fid as filename $dest = TORRENT_BASE_PATH . '/' . $metainfo_id . '.torrent'; move_uploaded_file($file['tmp_name'], $dest); return array('status' => true, 'message' => 'The torrent has been successfully uploaded. Congratulations!', 'id' => $metainfo_id); }