Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function display_quote($id, $submit = false)
- {
- $table = ($submit ? 'submissions' : 'quotes');
- $id = intval($id);
- $row = mysql_fetch_assoc(sql_query(sprintf("
- SELECT * FROM `%s` WHERE id=%d
- ", $table, $id)));
- // Gather the info from the table and null for safety
- $quote = $row['quote'];
- $votes = $row['votes'];
- $row = null;
- // Sanitize for output
- $quote = trim($quote);
- $quote = htmlspecialchars($quote);
- // turn multiple line breaks into single ones
- $quote = nl2br($quote);
- do {
- $quote = str_replace('<br />'.PHP_EOL.'<br />', '<br />', $quote, $substitutions);
- } while (0 < $substitutions);
- // Trim "< " to "<" && the same for >
- $quote = str_replace('< ', '<', $quote);
- $quote = str_replace(' >', '>', $quote);
- // Process the quote header: Quote #XXX +/-
- if ($submit) {
- $head = sprintf('
- <input type="checkbox" name="%d" />
- ', $id);
- $event = sprintf('
- document.getElementById(\'b1\').value=%d;
- document.getElementById(\'b2\').value=%d;
- ', $id, $id);
- }
- else {
- $head = sprintf('
- (%d) <a href="#" onclick="page.vote(\'%d\', \'&op=plus\');">+</a> <a href="#" onclick="page.vote(\'%d\', \'&op=minus\')">-</a>
- ', $votes, $id, $id);
- $event = sprintf('
- page.load(\'search\', \'&list=ASC&by=id&id=%d\')
- ', $id);
- }
- echo sprintf('
- <a href="#" onclick="%s">Quote #%d</a> %s <br />'
- . PHP_EOL
- , $event, $id, $head);
- echo $quote . '<br /> <br />' . PHP_EOL;
- }
Add Comment
Please, Sign In to add comment