| 157 | | return $_RESULT = array('text' => $lang['bad_torrent'] ); |
|---|
| 158 | | } |
|---|
| 159 | | |
|---|
| 160 | | $sql = 'SELECT COUNT(*) AS count FROM ' . RATINGS_TABLE . ' WHERE torrent = ' . $id . ' AND user = ' . $userdata['uid']; |
|---|
| 161 | | $result = $db->sql_query($sql); |
|---|
| 162 | | $count = ( $row = $db->sql_fetchrow($result) ) ? intval($row['count']) : 0; |
|---|
| 163 | | if ( $count ) { |
|---|
| 164 | | return $_RESULT = array('text' => $lang['dupe_vote'] ); |
|---|
| 165 | | } |
|---|
| 166 | | $sql = 'INSERT INTO ' . RATINGS_TABLE . ' (torrent, user, rating) VALUES (' . $id . ', ' . $userdata['uid'] . ', ' . $rating . ')'; |
|---|
| 167 | | $db->sql_query($sql); |
|---|
| 168 | | $sql = 'UPDATE ' . TORRENTS_TABLE . ' SET numratings = numratings + 1, ratingsum = ratingsum + ' . $rating. ' WHERE fid = ' . $id; |
|---|
| 169 | | $db->sql_query($sql); |
|---|
| 170 | | |
|---|
| 171 | | $sql = 'SELECT t.numratings, t.ratingsum |
|---|
| 172 | | FROM ' . TORRENTS_TABLE . ' t |
|---|
| 173 | | WHERE t.fid = ' . $id; |
|---|
| 174 | | $result = $db->sql_query($sql); |
|---|
| 175 | | $row = $db->sql_fetchrow($result); |
|---|
| 176 | | |
|---|
| 177 | | $rating_message = ''; |
|---|
| 178 | | if ( $row['numratings'] < $config['minvotes'] ) { |
|---|
| 179 | | if ( $config['minvotes'] > 1 ) { |
|---|
| 180 | | $rating_message .= sprintf($lang['no_rating'], $config['minvotes']); |
|---|
| 181 | | if ($row['numratings']) { |
|---|
| 182 | | $rating_message .= ( $row['numratings'] == 1? sprintf($lang['voice'], $row['numratings']) : sprintf($lang['voices'], $row['numratings']) ); |
|---|
| 183 | | } |
|---|
| 184 | | else { |
|---|
| 185 | | $rating_message .= $lang['no_voices']; |
|---|
| 186 | | } |
|---|
| 187 | | $rating_message .= ')'; |
|---|
| 188 | | } |
|---|
| 189 | | else { |
|---|
| 190 | | $rating_message .= $lang['no_one_voices']; |
|---|
| 191 | | } |
|---|
| 192 | | } |
|---|
| 193 | | else { |
|---|
| 194 | | $rating_tot = round($row['ratingsum'] / $row['numratings'], 1); |
|---|
| 195 | | $rpic = ratingpic($rating_tot); |
|---|
| 196 | | $rating_message .= sprintf($lang['total_rating'], $rpic, $rating_tot, $row['numratings']); |
|---|
| 197 | | } |
|---|
| 198 | | $rating_message .= sprintf($lang['you_voted_for_this_torrent'], $rating, $lang['ratings_ary'][$rating]); |
|---|
| 199 | | return $_RESULT = array( 'text' => $lang['rating_added'], 'rating_message' => $rating_message ); |
|---|
| 200 | | |
|---|
| | 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)))); |
|---|
| 262 | | $name = urldecode($name); |
|---|
| 263 | | |
|---|
| 264 | | if ( !$name ) { |
|---|
| 265 | | return; |
|---|
| 266 | | } |
|---|
| 267 | | |
|---|
| 268 | | if ( strpos($name, ',') !== false ) { |
|---|
| 269 | | $name = explode(',', $name); |
|---|
| 270 | | } |
|---|
| 271 | | else { |
|---|
| 272 | | $name = array($name); |
|---|
| 273 | | } |
|---|
| 274 | | |
|---|
| 275 | | //start tags allow |
|---|
| 276 | | $allow_add_tags = false; |
|---|
| 277 | | |
|---|
| 278 | | switch ( $config['tags_who_allowed'] ) { |
|---|
| 279 | | case 0: |
|---|
| 280 | | $allow_add_tags = true; |
|---|
| 281 | | break; |
|---|
| 282 | | |
|---|
| 283 | | case 1: |
|---|
| 284 | | $sql = 'SELECT owner FROM ' . TORRENTS_TABLE . ' WHERE fid = ' . $id; |
|---|
| 285 | | $result = $db->sql_query($sql); |
|---|
| 286 | | $owner = ( $row = $db->sql_fetchrow($result) ) ? $row['owner'] : 0; |
|---|
| 287 | | |
|---|
| 288 | | $allow_add_tags = $userdata['uid'] == $owner || $userdata['class'] >= UC_MODERATOR; |
|---|
| 289 | | break; |
|---|
| 290 | | |
|---|
| 291 | | case 2: |
|---|
| 292 | | $allow_add_tags = $userdata['class'] >= UC_MODERATOR; |
|---|
| 293 | | break; |
|---|
| 294 | | } |
|---|
| 295 | | |
|---|
| 296 | | if ( !$allow_add_tags ) { |
|---|
| 297 | | return $_RESULT = array( 'message' => $lang['access_denied'] ); |
|---|
| 298 | | } |
|---|
| 299 | | |
|---|
| 300 | | //end tags allow |
|---|
| 301 | | |
|---|
| 302 | | if ( $config['tags_max_allow'] ) { |
|---|
| 303 | | $sql = 'SELECT COUNT(*) AS count FROM ' . TAGS_USERS_TABLE . ' WHERE tag_users_uid = ' . $userdata['uid'] . ' AND tag_users_for_id = ' . $id . ' AND tag_users_type = ' . $tag_type; |
|---|
| 304 | | $result = $db->sql_query($sql); |
|---|
| 305 | | $count = ( $row = $db->sql_fetchrow($result) ) ? $row['count'] : 0; |
|---|
| 306 | | |
|---|
| 307 | | if ( $count >= $config['tags_max_allow'] || ( ( sizeof($name) + $count ) >= $config['tags_max_allow'] ) ) { |
|---|
| 308 | | return $_RESULT = array( 'message' => sprintf($lang['no_more_tags_allowed'], $config['tags_max_allow']) ); |
|---|
| 309 | | } |
|---|
| 310 | | } |
|---|
| 311 | | |
|---|
| 312 | | $message = ''; |
|---|
| 313 | | $tags = ''; |
|---|
| 314 | | |
|---|
| 315 | | foreach ( $name AS $_null => $tag_name ) { |
|---|
| 316 | | $tag_name = trim($tag_name); |
|---|
| 317 | | $tag_name = preg_replace('/[\.,:\^]/', '', $tag_name); |
|---|
| 318 | | $tag_length = utf_strlen($tag_name); |
|---|
| 319 | | |
|---|
| 320 | | if ( $config['tags_max_length'] && $tag_length > $config['tags_max_length'] ) { |
|---|
| 321 | | $message .= sprintf($lang['tag_is_too_short_or_long'], $tag_name, $config['tags_min_length'], $config['tags_max_length']); |
|---|
| 322 | | continue; |
|---|
| 323 | | } |
|---|
| 324 | | |
|---|
| 325 | | if ( $config['tags_min_length'] && $tag_length < $config['tags_min_length'] ) { |
|---|
| 326 | | $message .= sprintf($lang['tag_is_too_short_or_long'], $tag_name, $config['tags_min_length'], $config['tags_max_length']); |
|---|
| 327 | | continue; |
|---|
| 328 | | } |
|---|
| 329 | | |
|---|
| 330 | | //get info for this tag and user from db -> mb user already voted for this tag? |
|---|
| 331 | | |
|---|
| 332 | | $sql = 'SELECT tag_users_for_id |
|---|
| 333 | | FROM ' . TAGS_USERS_TABLE . ' |
|---|
| 334 | | WHERE tag_users_uid = ' . $userdata['uid'] . ' |
|---|
| 335 | | AND tag_users_for_id = ' . $id . ' |
|---|
| 336 | | AND tag_users_type = ' . $tag_type . ' |
|---|
| 337 | | AND tag_users_name = \'' . $db->sql_escape($tag_name) . '\''; |
|---|
| 338 | | $result = $db->sql_query($sql); |
|---|
| 339 | | |
|---|
| 340 | | if ( $row = $db->sql_fetchrow($result) ) { |
|---|
| 341 | | $message = $lang['dupe_vote']; |
|---|
| 342 | | } |
|---|
| 343 | | else { |
|---|
| 344 | | if ( $type == 'down' ) { |
|---|
| 345 | | $sql = 'SELECT tag_count |
|---|
| 346 | | FROM ' . TAGS_TABLE . ' |
|---|
| 347 | | WHERE tag_name = \'' . $db->sql_escape($tag_name) . '\' |
|---|
| 348 | | AND tag_type = ' . $tag_type . ' |
|---|
| 349 | | AND tag_for_id = ' . $id; |
|---|
| 350 | | $result = $db->sql_query($sql); |
|---|
| 351 | | $tag_count = ( $row = $db->sql_fetchrow($result) ) ? $row['tag_count'] : false; |
|---|
| 352 | | |
|---|
| 353 | | if ( $tag_count <= 1 && $tag_count !== false ) { |
|---|
| 354 | | $sql = 'DELETE |
|---|
| 355 | | FROM ' . TAGS_TABLE . ' |
|---|
| 356 | | WHERE tag_name = \'' . $db->sql_escape($tag_name) . '\' |
|---|
| 357 | | AND tag_type = ' . $tag_type . ' |
|---|
| 358 | | AND tag_for_id = ' . $id; |
|---|
| 359 | | $lets_insert = false; |
|---|
| 360 | | } |
|---|
| 361 | | else { |
|---|
| 362 | | $sql = 'UPDATE ' . TAGS_TABLE . ' |
|---|
| 363 | | SET tag_count = tag_count - 1 |
|---|
| 364 | | WHERE tag_name = \'' . $db->sql_escape($tag_name) . '\' |
|---|
| 365 | | AND tag_type = ' . $tag_type . ' |
|---|
| 366 | | AND tag_for_id = ' . $id; |
|---|
| 367 | | $lets_insert = true; |
|---|
| 368 | | } |
|---|
| 369 | | |
|---|
| 370 | | $db->sql_query($sql); |
|---|
| 371 | | } |
|---|
| 372 | | else { |
|---|
| 373 | | $sql = 'UPDATE ' . TAGS_TABLE . ' |
|---|
| 374 | | SET tag_count = tag_count + 1 |
|---|
| 375 | | WHERE tag_name = \'' . $db->sql_escape($tag_name) . '\' |
|---|
| 376 | | AND tag_type = ' . $tag_type . ' |
|---|
| 377 | | AND tag_for_id = ' . $id; |
|---|
| 378 | | $db->sql_query($sql); |
|---|
| 379 | | $lets_insert = true; |
|---|
| 380 | | } |
|---|
| 381 | | |
|---|
| 382 | | //we using LOWER function in mysql, not in php - it's not a mistake! |
|---|
| 383 | | // new tag, let's insert |
|---|
| 384 | | if ( !$db->sql_affectedrows() && $lets_insert ) { |
|---|
| 385 | | $sql = 'INSERT INTO ' . TAGS_TABLE . ' VALUES (LOWER(\'' . $db->sql_escape($tag_name) . '\'), ' . $tag_type . ', ' . $id . ', 1)'; |
|---|
| 386 | | $db->sql_query($sql); |
|---|
| 387 | | |
|---|
| 388 | | $tags .= ' <a href="' . append_sid($root_path . 'browse.php?search_in=3&search=' . $tag_name) . '">' . $tag_name . '</a>'; |
|---|
| 389 | | } |
|---|
| 390 | | |
|---|
| 391 | | $sql = 'INSERT INTO ' . TAGS_USERS_TABLE . ' VALUES (' . $userdata['uid'] . ', ' . $id . ', ' . $tag_type . ', LOWER(\'' . $db->sql_escape($tag_name) . '\'))'; |
|---|
| 392 | | $db->sql_query($sql); |
|---|
| 393 | | |
|---|
| 394 | | //$message .= sprintf($lang['tag_added'], $tag_name) . "\n"; |
|---|
| 395 | | } |
|---|
| 396 | | } |
|---|
| | 258 | |
|---|
| | 259 | $message = tags::add_tag($tag_type, $id, $name, $type); |
|---|
| 399 | | return $_RESULT = array( 'message' => $message, 'tpl' => '' ); |
|---|
| 400 | | } |
|---|
| 401 | | else { |
|---|
| 402 | | $sql = 'SELECT tag_name, tag_count |
|---|
| 403 | | FROM ' . TAGS_TABLE . ' |
|---|
| 404 | | WHERE tag_type = ' . TYPE_TORRENT . ' |
|---|
| 405 | | AND tag_for_id = ' . $id; |
|---|
| 406 | | $result = $db->sql_query($sql); |
|---|
| 407 | | |
|---|
| 408 | | $tags = array(); |
|---|
| 409 | | while ( $row = $db->sql_fetchrow($result) ) { |
|---|
| 410 | | $tags[$row['tag_name']] = $row['tag_count']; |
|---|
| 411 | | } |
|---|
| 412 | | |
|---|
| 413 | | //simple tag cloud find here http://www.bytemycode.com/snippets/snippet/415/ |
|---|
| 414 | | $max_qty = max(array_values($tags)); |
|---|
| 415 | | $min_qty = min(array_values($tags)); |
|---|
| 416 | | |
|---|
| 417 | | $spread = $max_qty - $min_qty; |
|---|
| 418 | | $spread = ( $spread == 0 ? 1 : $spread ); |
|---|
| 419 | | |
|---|
| 420 | | $step = ( $config['max_tag_size'] - $config['min_tag_size'] ) / $spread; |
|---|
| 421 | | |
|---|
| 422 | | $i = 0; |
|---|
| 423 | | |
|---|
| 424 | | foreach ( $tags AS $tag_name => $tag_count ) { |
|---|
| 425 | | $size = round($config['min_tag_size'] + (($tag_count - $min_qty) * $step)); |
|---|
| 426 | | ++$i; |
|---|
| 427 | | |
|---|
| 428 | | $enc_tag_name = undo_htmlspecialchars($tag_name); |
|---|
| 429 | | $enc_tag_name = urlencode($enc_tag_name); |
|---|
| 430 | | |
|---|
| | 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 ) { |
|---|
| 432 | | 'TAG_NAME' => $tag_name, |
|---|
| 433 | | 'JS_TAG_NAME' => str_replace("'", "\'", $tag_name), |
|---|
| 434 | | 'ENC_TAG_NAME' => $enc_tag_name, |
|---|
| 435 | | 'TAG_SIZE' => $size, |
|---|
| 436 | | 'TAG_NUM' => $i, |
|---|
| 437 | | |
|---|
| 438 | | 'U_TAG' => append_sid($root_path . 'browse.php?search_in=3&search=' . $enc_tag_name), |
|---|
| 439 | | 'U_TAG_USERS' => append_sid($root_path . 'modtask.php?action=tags&do=view_users&tag_name=' . $enc_tag_name . '&tag_type=' . TYPE_TORRENT . '&tag_for_id=' . $id), |
|---|
| | 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), |
|---|