| 1 |
<?php</span> |
|---|
| 2 |
<span class="code-lang">$root_path = './'; |
|---|
| 3 |
require ($root_path . 'include/config.php'); |
|---|
| 4 |
require ($root_path . 'include/functions_check.php'); |
|---|
| 5 |
require ($root_path . 'include/functions_selects.php'); |
|---|
| 6 |
require ($root_path . 'languages/lang_' . $config['default_lang'] . '/lang_upload_templates.php'); |
|---|
| 7 |
require ($root_path . 'languages/lang_' . $config['default_lang'] . '/lang_modcomment_log.php'); |
|---|
| 8 |
|
|---|
| 9 |
$userdata = session_pagestart($user_ip); |
|---|
| 10 |
init_userprefs($userdata); |
|---|
| 11 |
loggedinorreturn(); |
|---|
| 12 |
|
|---|
| 13 |
$type = request_var('type', 'main'); |
|---|
| 14 |
$cat_id = request_var('cat', 0); |
|---|
| 15 |
$cats = $cache->obtain_cats();</span> |
|---|
| 16 |
<span class="code-lang"> |
|---|
| 17 |
if ( defined('USE_XBTT') ) { |
|---|
| 18 |
$base_announce = $config['xbt_listen_url'] . ':' . $config['listen_port'] . '/' . ( $userdata['session_logged_in'] ? $userdata['torrent_pass'] . '/' : '' ) . 'announce/'; |
|---|
| 19 |
} |
|---|
| 20 |
else { |
|---|
| 21 |
$base_announce = generate_base_url() . '/announce.php' . ( $userdata['session_logged_in'] ? '?passkey=' . $userdata['torrent_pass'] : '' ); |
|---|
| 22 |
} |
|---|
| 23 |
|
|---|
| 24 |
if ( !check_user_class($config['min_class_allow_upload']) ) { |
|---|
| 25 |
set_config('min_class_allow_upload', UC_UPLOADER); |
|---|
| 26 |
$min_class_allow_upload = UC_UPLOADER; |
|---|
| 27 |
} |
|---|
| 28 |
else { |
|---|
| 29 |
$min_class_allow_upload = $config['min_class_allow_upload']; |
|---|
| 30 |
} |
|---|
| 31 |
|
|---|
| 32 |
switch ( $type ) { |
|---|
| 33 |
case 'request': |
|---|
| 34 |
$heading = $lang['requests']; |
|---|
| 35 |
$minclass = UC_USER; |
|---|
| 36 |
$simpaty_type = SIMPATY_REQUEST; |
|---|
| 37 |
break; |
|---|
| 38 |
|
|---|
| 39 |
case 'offer': |
|---|
| 40 |
$heading = $lang['offers']; |
|---|
| 41 |
$minclass = $min_class_allow_upload; |
|---|
| 42 |
$simpaty_type = SIMPATY_OFFER; |
|---|
| 43 |
break; |
|---|
| 44 |
|
|---|
| 45 |
default: |
|---|
| 46 |
$heading = $lang['uploading']; |
|---|
| 47 |
$minclass = $min_class_allow_upload; |
|---|
| 48 |
$simpaty_type = SIMPATY_TORRENT; |
|---|
| 49 |
break; |
|---|
| 50 |
} |
|---|
| 51 |
|
|---|
| 52 |
if ( $userdata['class'] < $minclass ) { |
|---|
| 53 |
trigger_error($lang['access_denied']); |
|---|
| 54 |
} |
|---|
| 55 |
|
|---|
| 56 |
if ( isset($cats[$cat_id]['torrents_limit']) && $cats[$cat_id]['torrents_limit'] ) { |
|---|
| 57 |
$sql = 'SELECT COUNT(*) AS limit_count FROM ' . TORRENTS_TABLE . ' WHERE category = ' . $cat_id . ' AND ctime > ' . ( time() - 24 * 60 * 60 ); |
|---|
| 58 |
$result = $db->sql_query($sql); |
|---|
| 59 |
$limit_count = ( $row = $db->sql_fetchrow($result) ) ? intval($row['limit_count']) : 0; |
|---|
| 60 |
if ( $limit_count >= $cats[$cat_id]['torrents_limit'] ) { |
|---|
| 61 |
trigger_error( sprintf($lang['torrent_upload_limit_reached'], $cats[$cat_id]['cat_name']) ); |
|---|
| 62 |
} |
|---|
| 63 |
} |
|---|
| 64 |
|
|---|
| 65 |
if ( isset($_POST['upload']) ) { |
|---|
| 66 |
$name = request_var('name', ''); |
|---|
| 67 |
$descr = request_var('descr', ''); |
|---|
| 68 |
|
|---|
| 69 |
if ( !$name || !$descr || !$cat_id ) { |
|---|
| 70 |
trigger_error($lang['dont_empty_fields']); |
|---|
| 71 |
} |
|---|
| 72 |
if ( !check_category_id($cat_id, true) ) { |
|---|
| 73 |
trigger_error( sprintf($lang['invalid_id'], $cat_id) ); |
|---|
| 74 |
} |
|---|
| 75 |
|
|---|
| 76 |
if ( $type == 'request' ) { |
|---|
| 77 |
$sql_ary = array('hits' => 1, |
|---|
| 78 |
'userid' => $userdata['uid'], |
|---|
| 79 |
'cat' => $cat_id, |
|---|
| 80 |
'request' => $name, |
|---|
| 81 |
'descr' => $descr, |
|---|
| 82 |
'added' => time() |
|---|
| 83 |
); |
|---|
| 84 |
$sql = 'INSERT INTO ' . REQUESTS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary); |
|---|
| 85 |
$db->sql_query($sql); |
|---|
| 86 |
$id = $db->sql_nextid(); |
|---|
| 87 |
if ( $userdata['commentpm'] ) { |
|---|
| 88 |
$sql = 'INSERT INTO ' . COMMENTS_NOTIFY_TABLE . ' (checkcomm_userid, checkcomm_for_id, checkcomm_type, checkcomm_view_status) VALUES (' . $userdata['uid'] . ', ' . $id . ', ' . TYPE_REQUEST . ', ' . VIEW_STATUS_VIEWED . ')'; |
|---|
| 89 |
$db->sql_query($sql); |
|---|
| 90 |
} |
|---|
| 91 |
$sql = 'INSERT INTO ' . REQUESTS_VOTES_TABLE . ' (requestid, userid) VALUES(' . $id . ', ' . $userdata['uid'] . ')'; |
|---|
| 92 |
$db->sql_query($sql); |
|---|
| 93 |
|
|---|
| 94 |
update_reputation($userdata, $simpaty_type, 1); |
|---|
| 95 |
|
|---|
| 96 |
redirect( append_sid('requests.php?id=' . $id)); |
|---|
| 97 |
} |
|---|
| 98 |
elseif ( $type == 'offer' ) { |
|---|
| 99 |
$sql_ary = array('userid' => $userdata['uid'], |
|---|
| 100 |
'category' => $cat_id, |
|---|
| 101 |
'name' => $name, |
|---|
| 102 |
'descr' => $descr, |
|---|
| 103 |
'added' => time() |
|---|
| 104 |
); |
|---|
| 105 |
|
|---|
| 106 |
$sql = 'INSERT INTO ' . OFFERS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary); |
|---|
| 107 |
$db->sql_query($sql); |
|---|
| 108 |
|
|---|
| 109 |
$id = $db->sql_nextid(); |
|---|
| 110 |
|
|---|
| 111 |
if ( $userdata['commentpm'] ) { |
|---|
| 112 |
$sql = 'INSERT INTO ' . COMMENTS_NOTIFY_TABLE . ' (checkcomm_userid, checkcomm_for_id, checkcomm_type, checkcomm_view_status) VALUES (' . $userdata['uid'] . ', ' . $id . ', ' . TYPE_OFFER . ', ' . VIEW_STATUS_VIEWED . ')'; |
|---|
| 113 |
$db->sql_query($sql); |
|---|
| 114 |
} |
|---|
| 115 |
|
|---|
| 116 |
update_reputation($userdata, $simpaty_type, 1); |
|---|
| 117 |
|
|---|
| 118 |
redirect( append_sid('offers.php?id=' . $id)); |
|---|
| 119 |
} |
|---|
| 120 |
else { |
|---|
| 121 |
$hidden = ( isset($_POST['hidden']) && ( $userdata['hiddentorrents'] || $userdata['class'] >= UC_MODERATOR ) ? 1 : 0); |
|---|
| 122 |
|
|---|
| 123 |
|
|---|
| 124 |
|
|---|
| 125 |
$nfo = ''; |
|---|
| 126 |
$nfofile = $_FILES['nfo']; |
|---|
| 127 |
if ( $nfofile['size'] > 65535 ) { |
|---|
| 128 |
trigger_error($lang['nfo_too_big']); |
|---|
| 129 |
} |
|---|
| 130 |
elseif ( @is_uploaded_file($nfofile['tmp_name']) && @filesize($nfofile['tmp_name']) > 0 ) { |
|---|
| 131 |
@move_uploaded_file($nfofile['tmp_name'], $root_path . '/cache/' . $nfofile['name']); |
|---|
| 132 |
$nfo = @file_get_contents($root_path . '/cache/' . $nfofile['name']); |
|---|
| 133 |
@unlink($root_path . '/cache/' . $nfofile['name']); |
|---|
| 134 |
$nfo = str_replace('\x0d\x0a', "\n", $nfo); |
|---|
| 135 |
$nfo = trim($nfo); |
|---|
| 136 |
|
|---|
| 137 |
if ( function_exists('iconv') ) { |
|---|
| 138 |
$nfo = iconv(mb_detect_encoding($nfo, 'auto', 1), 'UTF-8//TRANSLIT', $nfo); |
|---|
| 139 |
} |
|---|
| 140 |
else { |
|---|
| 141 |
$nfo = utf8_encode($nfo); |
|---|
| 142 |
} |
|---|
| 143 |
} |
|---|
| 144 |
|
|---|
| 145 |
|
|---|
| 146 |
//start torrent check |
|---|
| 147 |
if ( !isset($_FILES['file']) ) { |
|---|
| 148 |
trigger_error($lang['dont_empty_fields']); |
|---|
| 149 |
} |
|---|
| 150 |
list($infohash, $fname, $totallen, $filelist, $dname, $filename) = check_torrent($_FILES['file']); |
|---|
| 151 |
|
|---|
| 152 |
|
|---|
| 153 |
if ( $config['default_type_moderated_torrents'] == MODERATED_ALL_TORRENTS ) { |
|---|
| 154 |
$moderated = 0; |
|---|
| 155 |
} |
|---|
| 156 |
elseif ( $config['default_type_moderated_torrents'] == MODERATED_ONLY_NON_UPLOADERS_TORRENTS && $userdata['class'] < UC_UPLOADER ) { |
|---|
| 157 |
$moderated = 0; |
|---|
| 158 |
} |
|---|
| 159 |
else { |
|---|
| 160 |
$moderated = 1; |
|---|
| 161 |
} |
|---|
| 162 |
$torrent_dir = $root_path . ( !empty($config['torrent_dir']) ? $config['torrent_dir'] : 'torrents'); |
|---|
| 163 |
|
|---|
| 164 |
$sql = 'SELECT name, fid, category FROM ' . TORRENTS_TABLE . ' WHERE info_hash = ' . "'" . $db->sql_escape($infohash) . "'"; |
|---|
| 165 |
$result = $db->sql_query($sql); |
|---|
| 166 |
|
|---|
| 167 |
if ( $row = $db->sql_fetchrow($result) ) { |
|---|
| 168 |
|
|---|
| 169 |
if ( isset($cats[$cats[$row['category']]['cat_parent']]['cat_name']) ) { |
|---|
| 170 |
|
|---|
| 171 |
$seo->set_url($cat_parent['cat_name'], $cat_parent['cat_id'], $seo->seo_static['browse']); |
|---|
| 172 |
$seo->set_parent($cats[$row['category']]['cat_id'], $seo->seo_static['browse'], $cat_parent['cat_id'], $seo->seo_static['browse']); |
|---|
| 173 |
|
|---|
| 174 |
} |
|---|
| 175 |
|
|---|
| 176 |
|
|---|
| 177 |
$seo->set_url($cats[$row['category']]['cat_name'], $cats[$row['category']]['cat_id'], $seo->seo_static['browse']); |
|---|
| 178 |
$seo->set_parent($row['fid'], $seo->seo_static['details'], $cats[$row['category']]['cat_id'], $seo->seo_static['browse']); |
|---|
| 179 |
$seo->set_url(censor_text($row['name']), $row['fid'], $seo->seo_static['details']); |
|---|
| 180 |
|
|---|
| 181 |
@unlink($torrent_dir . DIRECTORY_SEPARATOR . $filename . '.torrent'); |
|---|
| 182 |
$message = sprintf($lang['torrent_already_uploaded'], append_sid($root_path . 'details.php?id=' . $row['fid']), $row['name']); |
|---|
| 183 |
trigger_error($message); |
|---|
| 184 |
} |
|---|
| 185 |
|
|---|
| 186 |
$sql_ary = array('filename' => $fname, |
|---|
| 187 |
'owner' => $userdata['uid'], |
|---|
| 188 |
'info_hash' => $infohash, |
|---|
| 189 |
'name' => $name, |
|---|
| 190 |
'size' => $totallen, |
|---|
| 191 |
'numfiles' => sizeof($filelist), |
|---|
| 192 |
'descr' => $descr, |
|---|
| 193 |
'category' => $cat_id, |
|---|
| 194 |
'ctime' => time(), |
|---|
| 195 |
'mtime' => time(), |
|---|
| 196 |
'nfo' => $nfo, |
|---|
| 197 |
'hidden' => $hidden, |
|---|
| 198 |
'moderated' => $moderated, |
|---|
| 199 |
); |
|---|
| 200 |
|
|---|
| 201 |
$sql = 'INSERT INTO ' . TORRENTS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary); |
|---|
| 202 |
$db->sql_query($sql); |
|---|
| 203 |
$id = $db->sql_nextid(); |
|---|
| 204 |
|
|---|
| 205 |
@rename($torrent_dir . DIRECTORY_SEPARATOR . $filename . '.torrent', $torrent_dir . DIRECTORY_SEPARATOR . $id . '.torrent'); |
|---|
| 206 |
|
|---|
| 207 |
$sql = 'INSERT INTO ' . COMMENTS_NOTIFY_TABLE . ' (checkcomm_userid, checkcomm_for_id, checkcomm_type, checkcomm_view_status) VALUES (' . $userdata['uid'] . ', ' . $id . ', ' . TYPE_TORRENT . ', ' . VIEW_STATUS_VIEWED . ')'; |
|---|
| 208 |
$db->sql_query($sql); |
|---|
| 209 |
|
|---|
| 210 |
$sql = 'DELETE FROM ' . FILES_TABLE . ' WHERE torrent = ' . $id; |
|---|
| 211 |
$db->sql_query($sql); |
|---|
| 212 |
foreach ( $filelist AS $file ) { |
|---|
| 213 |
$sql = 'INSERT INTO ' . FILES_TABLE . ' (torrent, filename, size) VALUES (' . $id . ", '" . $db->sql_escape($file[0]) . "'," . $file[1] . ')'; |
|---|
| 214 |
$db->sql_query($sql); |
|---|
| 215 |
} |
|---|
| 216 |
|
|---|
| 217 |
|
|---|
| 218 |
|
|---|
| 219 |
require_once($root_path . 'include/class.tags.php'); |
|---|
| 220 |
|
|---|
| 221 |
if ( tags::return_allow_add_tag(TYPE_TORRENT, 0, $userdata['uid']) ) { |
|---|
| 222 |
$tags_name = request_var('tag_name', ''); |
|---|
| 223 |
$tag_type = TYPE_TORRENT; |
|---|
| 224 |
|
|---|
| 225 |
tags::set_tag_cat_id($cat_id); |
|---|
| 226 |
tags::set_tag_owner($userdata['uid']); |
|---|
| 227 |
tags::set_fast_add_mode(); |
|---|
| 228 |
tags::add_tag(TYPE_TORRENT, $id, $tags_name, 'up'); |
|---|
| 229 |
} |
|---|
| 230 |
|
|---|
| 231 |
|
|---|
| 232 |
write_log( sprintf($lang['log_torrent_uploaded'], $id, $name, $userdata['uid'], $userdata['name']) ); |
|---|
| 233 |
|
|---|
| 234 |
if ( $moderated ) { |
|---|
| 235 |
update_reputation($userdata, $simpaty_type, 1); |
|---|
| 236 |
} |
|---|
| 237 |
|
|---|
| 238 |
|
|---|
| 239 |
$seo->set_torrent_url($id, $name, $cat_id); |
|---|
| 240 |
|
|---|
| 241 |
|
|---|
| 242 |
redirect( append_sid($root_path . 'details.php?id=' . $id . '&uploaded=1')); |
|---|
| 243 |
|
|---|
| 244 |
} |
|---|
| 245 |
} |
|---|
| 246 |
|
|---|
| 247 |
elseif ( isset($_POST['cat']) ) { |
|---|
| 248 |
$template->assign_block_vars('uploading', array()); |
|---|
| 249 |
|
|---|
| 250 |
$name = request_var('name', ''); |
|---|
| 251 |
$descr = request_var('descr', ''); |
|---|
| 252 |
|
|---|
| 253 |
if ( !check_category_id($cat_id, true) ) { |
|---|
| 254 |
trigger_error( sprintf($lang['invalid_id'], $cat_id) ); |
|---|
| 255 |
} |
|---|
| 256 |
|
|---|
| 257 |
|
|---|
| 258 |
require ($root_path . 'include/bbcode/bbcode.lib.php'); |
|---|
| 259 |
|
|---|
| 260 |
|
|---|
| 261 |
$cat_parent_name = ( isset($cats[$cats[$cat_id]['cat_parent']]['cat_name']) ? $cats[$cats[$cat_id]['cat_parent']]['cat_name'] . ' -> ' : '' ); |
|---|
| 262 |
|
|---|
| 263 |
$template->assign_vars(array( |
|---|
| 264 |
'S_FORM_ACTION' => append_sid('upload.php'), |
|---|
| 265 |
'FORM_ENCTYPE' => ( $type == 'main' ? ' enctype="multipart/form-data"' : '' ), |
|---|
| 266 |
'MAX_TORRENT_SIZE' => $config['max_torrent_size'], |
|---|
| 267 |
'NAME' => $name, |
|---|
| 268 |
'DESCRIPTION' => $descr, |
|---|
| 269 |
'CAT_NAME' => $cat_parent_name . $cats[$cat_id]['cat_name'], |
|---|
| 270 |
'CATEGORY' => $cat_id, |
|---|
| 271 |
'TYPE' => $type, |
|---|
| 272 |
'S_ANNOUNCE_ADDRESS' => sprintf($lang['tracker_announce_address'], $base_announce) |
|---|
| 273 |
)); |
|---|
| 274 |
|
|---|
| 275 |
if ( ( $userdata['hiddentorrents'] || $userdata['class'] >= UC_MODERATOR ) && $type == 'main' ) { |
|---|
| 276 |
$template->assign_block_vars('switch_hidden_section', array( |
|---|
| 277 |
'HIDDEN_CHECKED' => ( isset($_POST['hidden']) ? ' checked="checked"' : '') |
|---|
| 278 |
)); |
|---|
| 279 |
} |
|---|
| 280 |
|
|---|
| 281 |
$bb_code = new bbcode($descr); |
|---|
| 282 |
$descr = $bb_code->get_html(); |
|---|
| 283 |
$descr = censor_text($descr); |
|---|
| 284 |
|
|---|
| 285 |
$template->assign_block_vars('uploading_preview', array( |
|---|
| 286 |
'NAME' => censor_text($name), |
|---|
| 287 |
'DESCRIPTION' => $descr |
|---|
| 288 |
)); |
|---|
| 289 |
|
|---|
| 290 |
stdhead($heading, false); |
|---|
| 291 |
$template->set_filenames(array( |
|---|
| 292 |
'body' => 'upload_body.html' |
|---|
| 293 |
)); |
|---|
| 294 |
stdfoot(); |
|---|
| 295 |
} |
|---|
| 296 |
|
|---|
| 297 |
elseif ( $cat_id ) { |
|---|
| 298 |
if ( !check_category_id($cat_id, true) ) { |
|---|
| 299 |
trigger_error( sprintf($lang['invalid_id'], $cat_id) ); |
|---|
| 300 |
} |
|---|
| 301 |
$template->set_filenames(array( |
|---|
| 302 |
'template' => '../upload_templates/' . $cat_id . '.html' |
|---|
| 303 |
)); |
|---|
| 304 |
|
|---|
| 305 |
$sql = 'SELECT pic_url, group_name FROM ' . RELEASE_GROUPS_TABLE . ' ORDER by group_name ASC'; |
|---|
| 306 |
$result = $db->sql_query($sql); |
|---|
| 307 |
$release_group_options = '<option value="0">(' . $lang['choose'] . ')</option>'; |
|---|
| 308 |
while ( $row = $db->sql_fetchrow($result) ) { |
|---|
| 309 |
$release_group_options .= '<option value="[img]' . generate_base_url() . '/pic/groups/' . $row['pic_url'] . '[/img]">' . $row['group_name'] . '</option>'; |
|---|
| 310 |
} |
|---|
| 311 |
|
|---|
| 312 |
$template->assign_vars(array( |
|---|
| 313 |
'S_FORM_ACTION' => append_sid('upload.php'), |
|---|
| 314 |
'TYPE' => $type, |
|---|
| 315 |
'CATEGORY' => $cat_id, |
|---|
| 316 |
'ANNOUNCE_URL' => ( $type == 'main'? $base_announce : '' ), |
|---|
| 317 |
'L_JS_UNFILLED_FIELDS' => str_replace("'", "\'", $lang['js_unfilled_fields']), |
|---|
| 318 |
'RELEASE_GROUP_OPTIONS' => $release_group_options ) |
|---|
| 319 |
); |
|---|
| 320 |
|
|---|
| 321 |
$template_tpl = $template->assign_display('template', 'TEMPLATE_FILE', false); |
|---|
| 322 |
|
|---|
| 323 |
stdhead($heading, false); |
|---|
| 324 |
$template->set_filenames(array( |
|---|
| 325 |
'body' => 'upload_template_body.html' |
|---|
| 326 |
)); |
|---|
| 327 |
stdfoot(); |
|---|
| 328 |
} |
|---|
| 329 |
else { |
|---|
| 330 |
$s = categories_select('-', 'cat', true, true); |
|---|
| 331 |
|
|---|
| 332 |
$s .= '<input type="hidden" name="sid" value="' . $userdata['session_id'] . '" />'; |
|---|
| 333 |
|
|---|
| 334 |
$template->assign_vars(array( |
|---|
| 335 |
'S_FORM_ACTION' => append_sid('upload.php'), |
|---|
| 336 |
'CATS_SELECT' => $s, |
|---|
| 337 |
'TYPE' => $type |
|---|
| 338 |
)); |
|---|
| 339 |
|
|---|
| 340 |
stdhead($heading); |
|---|
| 341 |
$template->set_filenames(array( |
|---|
| 342 |
'body' => 'cats_select_body.html' |
|---|
| 343 |
)); |
|---|
| 344 |
stdfoot(); |
|---|
| 345 |
} |
|---|
| 346 |
?> |
|---|