-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathqdb.php
120 lines (112 loc) · 3.3 KB
/
qdb.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<?php require_once("./header.php");?>
<body>
<div id="content">
<a href="./submit.php">Submit a new quote</a>
<?php
# doesn't need to be sanitized; not going to the database
#print_r(sanitize($_GET));
if ($_GET['sort'] == "vote")
echo '<a href="/?sort=date">Sort by date</a>';
else
echo '<a href="/?sort=vote">Sort by vote</a>';
echo '<span id="search">Search: press Ctrl+F</span>';
$db = new MySQL();
if (sanitize($_GET['sort']) == "vote")
$query = "SELECT * FROM qdb q LEFT JOIN qdb_votes qv ON qv.quote_id = q.id ORDER BY qv.votes DESC";
else
$query = "SELECT * FROM qdb q LEFT JOIN qdb_votes qv ON qv.quote_id = q.id ORDER BY q.id DESC";
$rows = $db->setRunBuild($query);
$i = 1;
foreach ($rows as $key => $value) {
echo "<div class='quoteContainer'>\n";
echo "<div class='quoteIDBox'>\n";
echo "<a href='./quote.php?id=".$value['id']."'>#".$value['id']."</a>";
echo " votes: ";
echo "<span id='voteValue".$value['id']."'>";
if (isset($value['votes'])) echo $value['votes']; else echo "0";
echo "</span>"; # end voteValue span
echo "<span class='quoteDate'>";
echo $value['date'];
echo "</span>";
echo "<div class='downArrow' id='".$value['id']."'>";
echo "↓";
echo "</div>";
echo "<div class='upArrow' id='".$value['id']."'>";
echo "↑";
echo "</div>";
echo "</div>"; // quote id
echo "<div class='quote' id='quote".$value['id']."'>\n";
echo "<div class='quote_interior' name='".$value['id']."'>";
$value['quote'] = str_replace("<","< ", $value['quote']);
echo str_replace("\n", "<br />", autolink($value['quote']));
echo "<br />\n";
echo "</div>"; // end quote_interior
echo "</div>\n"; // end quote div
echo "</div>\n"; // end container div
}
?>
<script>
// responsive voice removed because they added an api key requirement
// and i can't be arsed
$(".upArrow").hover(
function() {
$(this).css('color','green');
},
function() {
$(this).css('color','');
});
$(".downArrow").hover(
function() {
$(this).css('color','red');
},
function() {
$(this).css('color','');
});
$(".upArrow").click(function(event) {
var p = {};
var id = p['id'] = $(this).attr('id');
// incremement the votevalue
$("#voteValue"+id)[0].innerHTML = parseInt($("#voteValue"+id)[0].innerHTML) + 1;
p['vote'] = "1";
$.post(
'vote.php',
p,
function(data) {
var jobj = jQuery.parseJSON(data);
event.target.innerHTML = jobj.text;
}
);
$(this).unbind('click');
$(this).unbind('hover');
});
$(".downArrow").click(function(event) {
var p = {};
var id = p['id'] = $(this).attr('id');
// decrement vote value
$("#voteValue"+id)[0].innerHTML = parseInt($("#voteValue"+id)[0].innerHTML) - 1;
p['vote'] = "-1";
$.post(
'vote.php',
p,
function(data) {
var jobj = jQuery.parseJSON(data);
event.target.innerHTML = jobj.text;
}
);
$(this).unbind('click');
$(this).unbind('hover');
});
function getRandomInt(min,max){
if((typeof min === "number") && Math.floor(min) === min && (typeof max === "number") && Math.floor(max) === max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}else{
//logger.error('min or max number is not a valid number');
throw 'min or max number is not a valid number';
}
}
</script>
<?php
echo "copyright LOLOLOL";
echo "</div>"; # end content div
echo "</body></html>";
?>