| 1 |
<?php</span> |
|---|
| 2 |
<span class="code-lang">$root_path = './'; |
|---|
| 3 |
require_once ($root_path . 'include/config.php'); |
|---|
| 4 |
require_once ($root_path . 'include/ajax.php'); |
|---|
| 5 |
|
|---|
| 6 |
$userdata = session_pagestart($user_ip); |
|---|
| 7 |
init_userprefs($userdata); |
|---|
| 8 |
loggedinorreturn();</span> |
|---|
| 9 |
<span class="code-lang"> |
|---|
| 10 |
if (empty($_SERVER['HTTP_REFERER'])) { |
|---|
| 11 |
redirect( append_sid($root_path)); |
|---|
| 12 |
} |
|---|
| 13 |
|
|---|
| 14 |
$JsHttpRequest = new JsHttpRequest(); |
|---|
| 15 |
|
|---|
| 16 |
$action = request_var('action', ''); |
|---|
| 17 |
|
|---|
| 18 |
$db->sql_return_on_error(true); |
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
$template->assign_vars(array(</span> |
|---|
| 22 |
<span class="code-lang"> 'S_USER_LOGGED_IN' => $userdata['session_logged_in'], |
|---|
| 23 |
'S_USER_IS_MOD' => ( $userdata['class'] >= UC_MODERATOR ) ? 1 : 0, |
|---|
| 24 |
)); |
|---|
| 25 |
|
|---|
| 26 |
switch ( $action ) { |
|---|
| 27 |
|
|---|
| 28 |
case 'viewhost': |
|---|
| 29 |
require_once ($root_path . 'include/functions_check.php'); |
|---|
| 30 |
|
|---|
| 31 |
$ip = request_var('ip', ''); |
|---|
| 32 |
|
|---|
| 33 |
if ( !check_ip($ip) ) { |
|---|
| 34 |
return $_RESULT = array('host' => 'unknown' ); |
|---|
| 35 |
} |
|---|
| 36 |
$dom = htmlspecialchars(@gethostbyaddr($ip)); |
|---|
| 37 |
if ( !($dom == $ip) || $dom) { |
|---|
| 38 |
$host = strtoupper($dom); |
|---|
| 39 |
} |
|---|
| 40 |
else { |
|---|
| 41 |
$host = $ip; |
|---|
| 42 |
} |
|---|
| 43 |
return $_RESULT = array('host' => $host ); |
|---|
| 44 |
|
|---|
| 45 |
break; |
|---|
| 46 |
|
|---|
| 47 |
case 'thanks': |
|---|
| 48 |
$id = request_var('id', 0); |
|---|
| 49 |
|
|---|
| 50 |
$sql = 'SELECT user_reputation, user_reputation_level, user_rank_id, uid |
|---|
| 51 |
FROM ' . TORRENTS_TABLE . ' t, ' . USERS_TABLE . ' u |
|---|
| 52 |
WHERE u.uid = t.owner |
|---|
| 53 |
AND t.fid = ' . $id; |
|---|
| 54 |
$result = $db->sql_query($sql); |
|---|
| 55 |
if ( !($owner_row = $db->sql_fetchrow($result)) ) { |
|---|
| 56 |
return $_RESULT = array('text' => $lang['error'] . "\n" . sprintf($lang['invalid_id'], $id) ); |
|---|
| 57 |
} |
|---|
| 58 |
|
|---|
| 59 |
if ( $owner_row['uid'] == $userdata['uid'] ) { |
|---|
| 60 |
return $_RESULT = array( 'text' => $lang['owner_cant_thanks'] ); |
|---|
| 61 |
} |
|---|
| 62 |
else { |
|---|
| 63 |
$sql = 'SELECT COUNT(*) AS count FROM ' . THANKS_TABLE . ' WHERE torrentid = ' . $id . ' AND userid = ' . $userdata['uid']; |
|---|
| 64 |
$result = $db->sql_query($sql); |
|---|
| 65 |
$count = ( $row = $db->sql_fetchrow($result) ) ? intval($row['count']) : 0; |
|---|
| 66 |
if ( $count ) { |
|---|
| 67 |
return $_RESULT = array( 'text' => $lang['already_thanked'] ); |
|---|
| 68 |
} |
|---|
| 69 |
else { |
|---|
| 70 |
$sql = 'INSERT INTO ' . THANKS_TABLE . ' (torrentid, userid) VALUES (' . $id . ', ' . $userdata['uid'] . ')'; |
|---|
| 71 |
$db->sql_query($sql); |
|---|
| 72 |
$thanksby = '<a href="' . append_sid('userdetails.php?id=' . $userdata['uid']) . '">' . $userdata['name'] . '</a>'; |
|---|
| 73 |
|
|---|
| 74 |
update_reputation($owner_row, SIMPATY_THANKS_TO_UPLOAD, 1); |
|---|
| 75 |
|
|---|
| 76 |
return $_RESULT = array( 'text' => $lang['thanks_added'], 'thanks_users' => $thanksby ); |
|---|
| 77 |
} |
|---|
| 78 |
} |
|---|
| 79 |
|
|---|
| 80 |
break; |
|---|
| 81 |
|
|---|
| 82 |
case 'sos': |
|---|
| 83 |
$id = request_var('id', 0); |
|---|
| 84 |
|
|---|
| 85 |
$sql = 'SELECT COUNT(*) AS count FROM ' . SOS_TABLE . ' WHERE torrentid = ' . $id . ' AND userid = ' . $userdata['uid']; |
|---|
| 86 |
$result = $db->sql_query($sql); |
|---|
| 87 |
$count = ( $row = $db->sql_fetchrow($result) ) ? $row['count'] : 0; |
|---|
| 88 |
if ( $count ) { |
|---|
| 89 |
return $_RESULT = array( 'text' => $lang['already_sos'] ); |
|---|
| 90 |
} |
|---|
| 91 |
else { |
|---|
| 92 |
$sql = 'SELECT name FROM ' . TORRENTS_TABLE . ' WHERE fid = ' . $id; |
|---|
| 93 |
$result = $db->sql_query($sql); |
|---|
| 94 |
if ( $row = $db->sql_fetchrow($result) ) { |
|---|
| 95 |
|
|---|
| 96 |
$torrent_name = $row['name']; |
|---|
| 97 |
|
|---|
| 98 |
$sql = 'INSERT INTO ' . SOS_TABLE . ' (torrentid, userid) VALUES (' . $id . ', ' . $userdata['uid'] . ')'; |
|---|
| 99 |
$db->sql_query($sql); |
|---|
| 100 |
|
|---|
| 101 |
$sql = 'SELECT s.userid, u.language, u.name, u.email, u.notifs, u.class |
|---|
| 102 |
FROM ' . SNATCHED_TABLE . ' s, ' . USERS_TABLE . ' u |
|---|
| 103 |
WHERE s.torrentid = ' . $id . ' AND s.completedat != 0 AND s.userid = u.uid'; |
|---|
| 104 |
$result = $db->sql_query($sql); |
|---|
| 105 |
|
|---|
| 106 |
$users = array(); |
|---|
| 107 |
|
|---|
| 108 |
if ( $row = $db->sql_fetchrow($result) ) { |
|---|
| 109 |
do { |
|---|
| 110 |
$users[$row['language']][] = $row; |
|---|
| 111 |
} |
|---|
| 112 |
while ( $row = $db->sql_fetchrow($result) ); |
|---|
| 113 |
|
|---|
| 114 |
$db->sql_freeresult($result); |
|---|
| 115 |
|
|---|
| 116 |
foreach ( $users AS $user_lang => $ary ) { |
|---|
| 117 |
require_once($root_path . 'languages/lang_' . $user_lang . '/lang_pms.php'); |
|---|
| 118 |
|
|---|
| 119 |
$count = sizeof($ary); |
|---|
| 120 |
|
|---|
| 121 |
for ( $i = 0; $i < $count; $i++ ) { |
|---|
| 122 |
$pm_ary[] = array( |
|---|
| 123 |
'sender' => 0, |
|---|
| 124 |
'receiver' => $ary[$i]['userid'], |
|---|
| 125 |
'msg' => sprintf($lang['pm_need_seed_body'], generate_base_url(), $id, $torrent_name, generate_base_url(), $userdata['uid'], $userdata['name']), |
|---|
| 126 |
'subject' => $lang['pm_need_seed_subject'], |
|---|
| 127 |
'name' => $ary[$i]['name'], |
|---|
| 128 |
'email' => $ary[$i]['email'], |
|---|
| 129 |
'notifs' => $ary[$i]['notifs'], |
|---|
| 130 |
'language' => $ary[$i]['language'], |
|---|
| 131 |
'class' => $ary[$i]['class'] |
|---|
| 132 |
); |
|---|
| 133 |
} |
|---|
| 134 |
} |
|---|
| 135 |
|
|---|
| 136 |
send_pm($pm_ary); |
|---|
| 137 |
} |
|---|
| 138 |
return $_RESULT = array( 'text' => $lang['sos_sended'] ); |
|---|
| 139 |
} |
|---|
| 140 |
else { |
|---|
| 141 |
return $_RESULT = array( 'text' => $lang['error'] . "\n" . sprintf($lang['invalid_id'], $id) ); |
|---|
| 142 |
} |
|---|
| 143 |
} |
|---|
| 144 |
|
|---|
| 145 |
break; |
|---|
| 146 |
|
|---|
| 147 |
case 'rating': |
|---|
| 148 |
$id = request_var('torrent_id', 0); |
|---|
| 149 |
$rating = request_var('rating', 0); |
|---|
| 150 |
$error = false; |
|---|
| 151 |
$msg = ''; |
|---|
| 152 |
$rating_sum = $numratings = 0; |
|---|
| 153 |
|
|---|
| 154 |
if ( !$id || $rating <= 0 || $rating > 5 ) { |
|---|
| 155 |
gc(json_encode(array('error' => $error, 'msg' => $lang['bad_rating']))); |
|---|
| 156 |
} |
|---|
| 157 |
$sql = 'SELECT numratings, ratingsum, owner FROM ' . TORRENTS_TABLE . ' WHERE fid = ' . $id; |
|---|
| 158 |
$result = $db->sql_query($sql); |
|---|
| 159 |
if ( !$row = $db->sql_fetchrow($result) ) { |
|---|
| 160 |
$msg = $lang['bad_torrent']; |
|---|
| 161 |
$error = true; |
|---|
| 162 |
} |
|---|
| 163 |
else { |
|---|
| 164 |
if ( $row['owner'] == $userdata['uid'] ) { |
|---|
| 165 |
$error = true; |
|---|
| 166 |
$msg = $lang['bad_torrent']; |
|---|
| 167 |
} |
|---|
| 168 |
$rating_sum = $row['ratingsum']; |
|---|
| 169 |
$numratings = $row['numratings']; |
|---|
| 170 |
} |
|---|
| 171 |
if ( !$error ) { |
|---|
| 172 |
$sql = 'SELECT torrent FROM ' . RATINGS_TABLE . ' WHERE torrent = ' . $id . ' AND user = ' . $userdata['uid']; |
|---|
| 173 |
$result = $db->sql_query($sql); |
|---|
| 174 |
if ( $row = $db->sql_fetchrow($result) ) { |
|---|
| 175 |
$error = true; |
|---|
| 176 |
$msg = $lang['dupe_vote']; |
|---|
| 177 |
} |
|---|
| 178 |
|
|---|
| 179 |
if ( !$error ) { |
|---|
| 180 |
$sql = 'INSERT INTO ' . RATINGS_TABLE . ' (torrent, user, rating) VALUES (' . $id . ', ' . $userdata['uid'] . ', ' . $rating . ')'; |
|---|
| 181 |
$db->sql_query($sql); |
|---|
| 182 |
$sql = 'UPDATE ' . TORRENTS_TABLE . ' SET numratings = numratings + 1, ratingsum = ratingsum + ' . $rating. ' WHERE fid = ' . $id; |
|---|
| 183 |
$db->sql_query($sql); |
|---|
| 184 |
|
|---|
| 185 |
$rating_sum += $rating; |
|---|
| 186 |
++$numratings; |
|---|
| 187 |
|
|---|
| 188 |
$msg = sprintf($lang['rating_added'], $rating, $numratings, $config['minvotes']); |
|---|
| 189 |
} |
|---|
| 190 |
} |
|---|
| 191 |
|
|---|
| 192 |
$rating = ratingpic($numratings, $rating_sum, false); |
|---|
| 193 |
|
|---|
| 194 |
gc(json_encode(array('error' => $error, 'msg' => $msg, 'rating_pic_width' => $rating * $config['rating_pic_width'], 'rating_title' => sprintf($lang['total_rating'], $rating, $rating, $numratings)))); |
|---|
| 195 |
break; |
|---|
| 196 |
|
|---|
| 197 |
case 'preview': |
|---|
| 198 |
|
|---|
| 199 |
require_once ($root_path . 'include/bbcode/bbcode.lib.php'); |
|---|
| 200 |
|
|---|
| 201 |
$name = request_var('name', ''); |
|---|
| 202 |
$message = request_var('message', ''); |
|---|
| 203 |
$preview_type = request_var('preview_type', ''); |
|---|
| 204 |
|
|---|
| 205 |
$preview_type = ( !$preview_type ? 'basic' : 'upload' ); |
|---|
| 206 |
|
|---|
| 207 |
$name = ( !empty($name) ? censor_text($name) : $lang['preview'] ); |
|---|
| 208 |
|
|---|
| 209 |
$bb_code = new bbcode($message); |
|---|
| 210 |
$message = $bb_code->get_html(); |
|---|
| 211 |
$message = censor_text($message); |
|---|
| 212 |
|
|---|
| 213 |
$template->set_filenames(array( |
|---|
| 214 |
'preview_tpl' => 'preview_box.html') |
|---|
| 215 |
); |
|---|
| 216 |
|
|---|
| 217 |
$template->assign_block_vars($preview_type . '_preview_box', array( |
|---|
| 218 |
'MESSAGE' => $message, |
|---|
| 219 |
'NAME' => $name ) |
|---|
| 220 |
); |
|---|
| 221 |
|
|---|
| 222 |
$tpl = $template->assign_display('preview_tpl'); |
|---|
| 223 |
|
|---|
| 224 |
return $_RESULT = array( 'tpl' => $tpl ); |
|---|
| 225 |
|
|---|
| 226 |
break; |
|---|
| 227 |
|
|---|
| 228 |
case 'edit_template_preview': |
|---|
| 229 |
|
|---|
| 230 |
require_once ($root_path . 'include/bbcode/bbcode.lib.php'); |
|---|
| 231 |
|
|---|
| 232 |
$template_prev = request_var('template', ''); |
|---|
| 233 |
|
|---|
| 234 |
$template->set_filenames(array( |
|---|
| 235 |
'preview_tpl' => '../admin/admin_categories_preview_box.html') |
|---|
| 236 |
); |
|---|
| 237 |
|
|---|
| 238 |
$bb_code = new bbcode($template_prev); |
|---|
| 239 |
$template_prev = $bb_code->get_html(); |
|---|
| 240 |
|
|---|
| 241 |
$template->assign_vars(array( |
|---|
| 242 |
'PREVIEW_VIEW' => $template_prev) |
|---|
| 243 |
); |
|---|
| 244 |
|
|---|
| 245 |
$tpl = $template->assign_display('preview_tpl'); |
|---|
| 246 |
|
|---|
| 247 |
return $_RESULT = array( 'tpl' => $tpl ); |
|---|
| 248 |
|
|---|
| 249 |
break; |
|---|
| 250 |
|
|---|
| 251 |
case 'update_tag': |
|---|
| 252 |
require_once($root_path . 'include/class.tags.php'); |
|---|
| 253 |
|
|---|
| 254 |
$name = request_var('tag_name', ''); |
|---|
| 255 |
$tag_type = request_var('tag_type', TYPE_TORRENT); |
|---|
| 256 |
$id = request_var('id', 0); |
|---|
| 257 |
$type = request_var('type', ''); |
|---|
| 258 |
|
|---|
| 259 |
$message = tags::add_tag($tag_type, $id, $name, $type); |
|---|
| 260 |
|
|---|
| 261 |
if ( $message ) { |
|---|
| 262 |
gc(json_encode(array('message' => $message, 'tpl' => ''))); |
|---|
| 263 |
} |
|---|
| 264 |
else { |
|---|
| 265 |
|
|---|
| 266 |
$tags = tags::tags_for_single($tag_type, $id); |
|---|
| 267 |
|
|---|
| 268 |
foreach ( $tags AS $_null => $tag_ary ) { |
|---|
| 269 |
$template->assign_block_vars('tags_row', array( |
|---|
| 270 |
'TAG_NAME' => $tag_ary['tag_name'], |
|---|
| 271 |
'JS_TAG_NAME' => $tag_ary['js_tag_name'], |
|---|
| 272 |
'ENC_TAG_NAME' => $tag_ary['enc_tag_name'], |
|---|
| 273 |
'TAG_SIZE' => $tag_ary['tag_size'], |
|---|
| 274 |
'TAG_NUM' => $tag_ary['tag_num'], |
|---|
| 275 |
|
|---|
| 276 |
'U_TAG' => append_sid($root_path . 'browse.php?search_in=3&search=' . $tag_ary['enc_tag_name']), |
|---|
| 277 |
'U_TAG_USERS' => append_sid($root_path . 'modtask.php?action=tags&do=view_users&tag_name=' . $tag_ary['enc_tag_name'] . '&tag_type=' . $tag_type . '&tag_for_id=' . $id), |
|---|
| 278 |
)); |
|---|
| 279 |
} |
|---|
| 280 |
|
|---|
| 281 |
$template->assign_vars(array( |
|---|
| 282 |
'TAG_TYPE' => $tag_type, |
|---|
| 283 |
'ID' => $id, |
|---|
| 284 |
'ALLOW_ADD_TAGS' => tags::return_allow_add_tag($tag_type, $id), |
|---|
| 285 |
)); |
|---|
| 286 |
|
|---|
| 287 |
$template->set_filenames(array( |
|---|
| 288 |
'template' => 'tags_view_form.html' |
|---|
| 289 |
)); |
|---|
| 290 |
|
|---|
| 291 |
$tpl = $template->assign_display('template', 'TEMPLATE_FILE'); |
|---|
| 292 |
|
|---|
| 293 |
gc(json_encode(array('message' => '', 'tpl' => $tpl))); |
|---|
| 294 |
} |
|---|
| 295 |
break; |
|---|
| 296 |
|
|---|
| 297 |
case 'autocomplete_tags': |
|---|
| 298 |
$tag_name = request_var('q', ''); |
|---|
| 299 |
|
|---|
| 300 |
$tag_length = utf_strlen($tag_name); |
|---|
| 301 |
|
|---|
| 302 |
if ( $tag_length < $config['tags_min_length'] ) { |
|---|
| 303 |
return false; |
|---|
| 304 |
} |
|---|
| 305 |
else { |
|---|
| 306 |
$sql = 'SELECT SUM(tag_count) AS sum, tag_name |
|---|
| 307 |
FROM ' . TAGS_TABLE . ' |
|---|
| 308 |
WHERE tag_name LIKE \'' . $db->sql_escape($tag_name) . '%\' |
|---|
| 309 |
GROUP BY tag_name |
|---|
| 310 |
ORDER BY sum DESC'; |
|---|
| 311 |
$result = $db->sql_query($sql); |
|---|
| 312 |
|
|---|
| 313 |
header('Content-type: text/html; charset=UTF-8'); |
|---|
| 314 |
while ( $row = $db->sql_fetchrow($result) ) { |
|---|
| 315 |
echo $row['tag_name'] . "\n"; |
|---|
| 316 |
} |
|---|
| 317 |
gc(); |
|---|
| 318 |
} |
|---|
| 319 |
break; |
|---|
| 320 |
|
|---|
| 321 |
default: |
|---|
| 322 |
redirect( append_sid($root_path, true) ); |
|---|
| 323 |
break; |
|---|
| 324 |
|
|---|
| 325 |
} |
|---|
| 326 |
?> |
|---|