Guest User

Untitled

a guest
Oct 23rd, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. function display_quote($id, $submit = false)
  2. {
  3. $table = ($submit ? 'submissions' : 'quotes');
  4. $id = intval($id);
  5.  
  6. $row = mysql_fetch_assoc(sql_query(sprintf("
  7. SELECT * FROM `%s` WHERE id=%d
  8. ", $table, $id)));
  9.  
  10. // Gather the info from the table and null for safety
  11. $quote = $row['quote'];
  12. $votes = $row['votes'];
  13. $row = null;
  14.  
  15. // Sanitize for output
  16. $quote = trim($quote);
  17. $quote = htmlspecialchars($quote);
  18.  
  19. // turn multiple line breaks into single ones
  20. $quote = nl2br($quote);
  21. do {
  22. $quote = str_replace('<br />'.PHP_EOL.'<br />', '<br />', $quote, $substitutions);
  23. } while (0 < $substitutions);
  24.  
  25. // Trim "< " to "<" && the same for >
  26. $quote = str_replace('< ', '<', $quote);
  27. $quote = str_replace(' >', '>', $quote);
  28.  
  29. // Process the quote header: Quote #XXX +/-
  30. if ($submit) {
  31. $head = sprintf('
  32. <input type="checkbox" name="%d" />
  33. ', $id);
  34. $event = sprintf('
  35. document.getElementById(\'b1\').value=%d;
  36. document.getElementById(\'b2\').value=%d;
  37. ', $id, $id);
  38. }
  39. else {
  40. $head = sprintf('
  41. (%d) <a href="#" onclick="page.vote(\'%d\', \'&op=plus\');">+</a> <a href="#" onclick="page.vote(\'%d\', \'&op=minus\')">-</a>
  42. ', $votes, $id, $id);
  43. $event = sprintf('
  44. page.load(\'search\', \'&list=ASC&by=id&id=%d\')
  45. ', $id);
  46. }
  47.  
  48. echo sprintf('
  49. <a href="#" onclick="%s">Quote #%d</a> %s <br />'
  50. . PHP_EOL
  51. , $event, $id, $head);
  52.  
  53. echo $quote . '<br /> <br />' . PHP_EOL;
  54. }
Add Comment
Please, Sign In to add comment