Browse Source

Initial import of quotes db

pull/2/head
Chris Smith 14 years ago
commit
414ed002bb
32 changed files with 1518 additions and 0 deletions
  1. 2
    0
      .gitignore
  2. 3
    0
      .gitmodules
  3. 6
    0
      .htaccess
  4. 52
    0
      best.php
  5. 131
    0
      browse.php
  6. 20
    0
      dostanding.php
  7. 151
    0
      dostandingbeta.php
  8. 97
    0
      dostandinggamma.php
  9. 61
    0
      inc/account.php
  10. 11
    0
      inc/database.php
  11. 3
    0
      inc/footer.php
  12. 68
    0
      inc/header.php
  13. 21
    0
      inc/settings.php
  14. 94
    0
      index.php
  15. 52
    0
      latest.php
  16. 146
    0
      login.php
  17. 1
    0
      openid
  18. 52
    0
      random.php
  19. 33
    0
      rate.php
  20. 29
    0
      rateajax.php
  21. 119
    0
      register.php
  22. 33
    0
      res/ajax.js
  23. BIN
      res/bl.png
  24. BIN
      res/br.png
  25. BIN
      res/minus.png
  26. BIN
      res/neutral.png
  27. BIN
      res/plus.png
  28. 113
    0
      res/style.css
  29. 34
    0
      rss.php
  30. 66
    0
      submit.php
  31. 68
    0
      unrated.php
  32. 52
    0
      worst.php

+ 2
- 0
.gitignore View File

@@ -0,0 +1,2 @@
1
+/openid/keycache.php
2
+/inc/*.private.php

+ 3
- 0
.gitmodules View File

@@ -0,0 +1,3 @@
1
+[submodule "openid"]
2
+	path = openid
3
+	url = git://chris.smith.name/~chris/poidsy

+ 6
- 0
.htaccess View File

@@ -0,0 +1,6 @@
1
+RewriteEngine On
2
+
3
+RewriteCond %{REQUEST_FILENAME} !-f
4
+RewriteCond %{REQUEST_FILENAME} !-d
5
+RewriteRule ^/?(quotes/)?(.*)$ /quotes/$2.php [L]
6
+

+ 52
- 0
best.php View File

@@ -0,0 +1,52 @@
1
+<?PHP
2
+
3
+ require_once('inc/database.php');
4
+
5
+ define('TITLE', 'Best');
6
+
7
+ require_once('inc/header.php');
8
+
9
+ $sql = 'SELECT quote_id, quote_quote, quote_rating FROM quotes ORDER BY quote_rating DESC LIMIT 0,25';
10
+ $res = mysql_query($sql)
11
+
12
+?>
13
+<div>
14
+ <h2>Best quotes</h2>
15
+<?PHP
16
+
17
+ $i = 0;
18
+ while ($row = mysql_fetch_array($res)) {
19
+  $i = 1 - $i;
20
+  if ($i == 1) { $e = 'even'; } else { $e = 'odd'; }
21
+?>
22
+ <div class="quote <?PHP echo $e; ?>">
23
+<?PHP
24
+ if (isset($_SESSION['uid'])) {
25
+  doRate($row['quote_id']);
26
+ }
27
+?>
28
+  <p>
29
+   Quote <a href="<?PHP echo BASE; ?>browse?q=<?PHP echo $row['quote_id']; ?>">#<?PHP echo $row['quote_id']; ?></a>.
30
+   Rating <?PHP echo round($row['quote_rating'],2); ?>.
31
+<?PHP
32
+
33
+ if (!isset($_SESSION['uid'])) {
34
+  echo ' <a href="'.BASE.'login">Login to rate</a>.';
35
+ }
36
+
37
+?>
38
+  </p>
39
+  <div class="quotebody">
40
+   <?PHP echo nl2br(htmlentities($row['quote_quote'], ENT_QUOTES, 'UTF-8')); ?>
41
+  </div>
42
+ </div>
43
+<?PHP
44
+ }
45
+
46
+?>
47
+</div>
48
+<?PHP
49
+
50
+ require_once('inc/footer.php');
51
+
52
+?>

+ 131
- 0
browse.php View File

@@ -0,0 +1,131 @@
1
+<?PHP
2
+
3
+ require_once('inc/database.php');
4
+
5
+ define('TITLE', 'Browse quotes');
6
+
7
+ require_once('inc/header.php');
8
+
9
+ if (isset($_GET['q']) && ctype_digit($_GET['q'])) {
10
+
11
+  $sql = 'SELECT quote_id, quote_quote, quote_rating FROM quotes WHERE quote_id = '.m($_GET['q']);
12
+  $res = mysql_query($sql);
13
+  
14
+  if (mysql_num_rows($res) == 0) {
15
+   echo '<h2>Error</h2><p>That quote wasn\'t found. Try <a href="?">browsing</a> for it?</p>';
16
+  } else {
17
+
18
+ echo '<h2>Viewing quote</h2>';
19
+
20
+ $i = 0;
21
+ while ($row = mysql_fetch_array($res)) {
22
+  $i = 1 - $i;
23
+  if ($i == 1) { $e = 'even'; } else { $e = 'odd'; }
24
+?>
25
+ <div class="quote <?PHP echo $e; ?>">
26
+<?PHP
27
+ if (isset($_SESSION['uid'])) {
28
+  doRate($row['quote_id']);
29
+ }
30
+?>
31
+  <p>
32
+   Quote #<?PHP echo $row['quote_id']; ?>.
33
+   Rating <?PHP echo round($row['quote_rating'],2); ?>.
34
+<?PHP
35
+
36
+ if (!isset($_SESSION['uid'])) {
37
+  echo ' <a href="'.BASE.'login">Login to rate</a>.';
38
+ }
39
+
40
+?>
41
+  </p>
42
+  <div class="quotebody">
43
+   <?PHP echo nl2br(htmlentities($row['quote_quote'], ENT_QUOTES, 'UTF-8')); ?>
44
+  </div>
45
+ </div>
46
+<?PHP
47
+ }
48
+
49
+
50
+  }
51
+
52
+
53
+ } else {
54
+
55
+  $offset = 0;
56
+  if (isset($_GET['o']) && ctype_digit($_GET['o'])) {
57
+   $offset = $_GET['o'];
58
+  }
59
+
60
+ $sql = 'SELECT COUNT(*) FROM quotes';
61
+ $res = mysql_query($sql);
62
+ $row = mysql_fetch_array($res);
63
+ define('QUOTES', $row[0]);
64
+
65
+ $sql = 'SELECT quote_id, quote_quote, quote_rating FROM quotes ORDER BY quote_id LIMIT '.$offset.',25';
66
+ $res = mysql_query($sql)
67
+
68
+?>
69
+<div>
70
+ <h2>Browse quotes</h2>
71
+<?PHP
72
+
73
+ echo '<div class="nav">';
74
+ if ($offset > 0) {
75
+  echo '<a href="browse?o='.($offset-25).'">&lt;&lt; Previous</a> |';
76
+ }
77
+ if ($offset + 25 > QUOTES) { $max = QUOTES; } else { $max = $offset + 25; }
78
+ echo ' Viewing quotes '.(1+$offset).' to '.$max.' of '.QUOTES.'.';
79
+ if ($max < QUOTES) {
80
+  echo ' | <a href="browse?o='.$max.'">Next &gt;&gt;</a>';
81
+ }
82
+ echo '</div>';
83
+
84
+
85
+ $i = 0;
86
+ while ($row = mysql_fetch_array($res)) {
87
+  $i = 1 - $i;
88
+  if ($i == 1) { $e = 'even'; } else { $e = 'odd'; }
89
+?>
90
+ <div class="quote <?PHP echo $e; ?>">
91
+<?PHP
92
+ if (isset($_SESSION['uid'])) {
93
+  doRate($row['quote_id']);
94
+ }
95
+?>
96
+  <p>
97
+   Quote <a href="<?PHP echo BASE; ?>browse?q=<?PHP echo $row['quote_id']; ?>">#<?PHP echo $row['quote_id']; ?></a>. 
98
+   Rating <?PHP echo round($row['quote_rating'],2); ?>.
99
+<?PHP
100
+
101
+ if (!isset($_SESSION['uid'])) {
102
+  echo ' <a href="'.BASE.'login">Login to rate</a>.';
103
+ }
104
+
105
+?>
106
+  </p>
107
+  <div class="quotebody">
108
+   <?PHP echo nl2br(htmlentities($row['quote_quote'], ENT_QUOTES, 'UTF-8')); ?>
109
+  </div>
110
+ </div>
111
+<?PHP
112
+ }
113
+
114
+ echo '<div class="nav">';
115
+ if ($offset > 0) {
116
+  echo '<a href="browse?o='.($offset-25).'">&lt;&lt; Previous</a> |';
117
+ }
118
+ if ($offset + 25 > QUOTES) { $max = QUOTES; } else { $max = $offset + 25; }
119
+ echo ' Viewing quotes '.(1+$offset).' to '.$max.' of '.QUOTES.'.';
120
+ if ($max < QUOTES) {
121
+  echo ' | <a href="browse?o='.$max.'">Next &gt;&gt;</a>';
122
+ }
123
+ echo '</div>';
124
+
125
+?>
126
+</div>
127
+<?PHP
128
+}
129
+ require_once('inc/footer.php');
130
+
131
+?>

+ 20
- 0
dostanding.php View File

@@ -0,0 +1,20 @@
1
+<?PHP
2
+
3
+/* require_once('inc/database.php');
4
+
5
+ $users = array();
6
+
7
+ $sql = 'SELECT user_id, quote_rating FROM quotes WHERE quote_rated > 0';
8
+ $res = mysql_query($sql);
9
+ while ($row = mysql_fetch_array($res)) {
10
+  $user =& $users[($row['user_id'])];
11
+  $user += (($row['quote_rating']-1)/50) * (10 - $user);
12
+ }
13
+
14
+ foreach ($users as $uid=>$st) {
15
+  mysql_query('UPDATE users SET user_standing = '.$st.' WHERE user_id = '.$uid);
16
+ }*/
17
+
18
+ require('dostandingbeta.php');
19
+
20
+?>

+ 151
- 0
dostandingbeta.php View File

@@ -0,0 +1,151 @@
1
+<?PHP
2
+
3
+ require_once('inc/database.php');
4
+
5
+ $users = array();
6
+ $quotes = array();
7
+
8
+ $sql = 'SELECT COUNT(*), user_id FROM quotes GROUP BY user_id';
9
+ $res = mysql_query($sql);
10
+ $max = 0;
11
+ while ($row = mysql_fetch_array($res)) {
12
+  if ($row[0] > $max) { $max = $row[0]; }
13
+  $quotes[($row[1])] = $row[0];
14
+ }
15
+
16
+ $sql = 'SELECT u.user_id, r.rating_change, r.quote_id, r.user_id AS rater FROM ratings AS r, quotes AS u WHERE u.quote_id = r.quote_id';
17
+
18
+ $qr = array();
19
+
20
+ $res = mysql_query($sql);
21
+ while ($row = mysql_fetch_array($res)) {
22
+  if (!isset($qr[($row['quote_id'])])) {
23
+   $qr[($row['quote_id'])] = array('for'=>array(),'against'=>array());
24
+  }
25
+  $user =& $users[($row['user_id'])];
26
+  if ($row['rating_change'] == 0) {
27
+   $user += 0;
28
+  } elseif ($row['rating_change'] > 0) {
29
+   $user += 1;
30
+   $qr[($row['quote_id'])]['for'][] = $row['rater'];
31
+  } else {
32
+   $user -= 1;
33
+   $qr[($row['quote_id'])]['against'][] = $row['rater'];
34
+  }
35
+ }
36
+
37
+ foreach ($qr as $quote => $rankings) {
38
+  $for = count($rankings['for']);
39
+  $against = count($rankings['against']);
40
+  $total = $for + $against;
41
+  if ($for == 0) {
42
+   foreach ($rankings['against'] as $uid) {
43
+    $users[$uid] += 0.5;
44
+   }
45
+  } elseif ($against == 0) {
46
+   foreach ($rankings['for'] as $uid) {
47
+    $users[$uid] += 0.5;
48
+   }
49
+  } else {
50
+   $forscore = $for/$total - 0.5;
51
+   $againstscore = $against/$total - 0.5;
52
+   foreach ($rankings['for'] as $uid) {
53
+    $users[$uid] += $forscore;
54
+   }
55
+   foreach ($rankings['against'] as $uid) {
56
+    $users[$uid] -= $againstscore;
57
+   }
58
+  }
59
+ }
60
+
61
+ foreach ($users as $uid => $user) {
62
+  #echo $uid.' ==&gt; '.$user.' == &gt; '.(10*$user*(1+$quotes[$uid])/pow($max,2)).'<br>';
63
+ }
64
+
65
+ $nusers = array();
66
+
67
+ $sql = 'SELECT u.user_id, r.rating_change FROM ratings AS r, quotes AS u WHERE u.quote_id = r.quote_id';
68
+
69
+ $res = mysql_query($sql);
70
+ while ($row = mysql_fetch_array($res)) {
71
+  $user =& $nusers[($row['user_id'])];
72
+  if ($row['rating_change'] == 0) {
73
+   $base = 0;
74
+  } elseif ($row['rating_change'] > 0) {
75
+   $base = 1;
76
+  } else {
77
+   $base = -1;
78
+  }
79
+  $base *= ($users[($row['user_id'])]+10)/10;
80
+  $user += $base; 
81
+ }
82
+
83
+ $sql = 'SELECT COUNT(*) FROM users';
84
+ $res = mysql_query($sql);
85
+ $row = mysql_fetch_array($res);
86
+ $cusers = $row[0];
87
+
88
+ foreach ($qr as $quote => $rankings) {
89
+  $for = count($rankings['for']);
90
+  $against = count($rankings['against']);
91
+  $total = $for + $against;
92
+  if ($for == 0) {
93
+   foreach ($rankings['against'] as $uid) {
94
+    $nusers[$uid] += 0.5;
95
+   }
96
+  } elseif ($against == 0) {
97
+   foreach ($rankings['for'] as $uid) {
98
+    $nusers[$uid] += 0.5;
99
+   }
100
+  } else {
101
+   $forscore = $for/$total - 0.5;
102
+   $againstscore = $against/$total - 0.5;
103
+   foreach ($rankings['for'] as $uid) {
104
+    $nusers[$uid] += $forscore;
105
+   }
106
+   foreach ($rankings['against'] as $uid) {
107
+    $nusers[$uid] -= $againstscore;
108
+   }
109
+  }
110
+ }
111
+
112
+
113
+ #echo '<hr>';
114
+ foreach ($nusers as $uid => $user) {
115
+  #echo $uid.' ==&gt; '.(10*$user*(1+$quotes[$uid])/(pow($max,2)*$cusers*2)).'<br>';
116
+  $nusers[$uid] = (10*$user*(1+$quotes[$uid])/(pow($max,2)*$cusers*2));
117
+  $sql = 'UPDATE users SET user_standing = '.$nusers[$uid].' WHERE user_id = '.$uid;
118
+  mysql_query($sql);
119
+ }
120
+
121
+ #echo '<hr>';
122
+
123
+ $quotes = array();
124
+ 
125
+ $sql = 'SELECT quote_id, user_id, rating_change FROM ratings';
126
+
127
+ $res = mysql_query($sql);
128
+ while ($row = mysql_fetch_array($res)) {
129
+  if (isset($nusers[($row['user_id'])])) {
130
+   $user = $nusers[($row['user_id'])];
131
+  } else {
132
+   $user = 0;
133
+  }
134
+  if ($row['rating_change'] == 0) {
135
+   $base = 0;
136
+  } elseif ($row['rating_change'] > 0) {
137
+   $base = 1;
138
+  } else {
139
+   $base = -1;
140
+  }
141
+  $base *= ($user+10)/10;
142
+  $quotes[($row['quote_id'])] += $base;
143
+ }
144
+
145
+ foreach ($quotes as $qid => $score) {
146
+  $sql = 'UPDATE quotes SET quote_rating = '.$score.' WHERE quote_id = '.$qid;
147
+  mysql_query($sql);
148
+  #echo "$qid ==&gt; $score<br>";
149
+ }
150
+
151
+?>

+ 97
- 0
dostandinggamma.php View File

@@ -0,0 +1,97 @@
1
+<?PHP
2
+
3
+ require_once('inc/database.php');
4
+
5
+ class quote {
6
+  public $id;
7
+  public $owner;
8
+  public $good = array();
9
+  public $neutral = array();
10
+  public $bad = array();
11
+ }
12
+
13
+ $quotes = array();
14
+ $users = array();
15
+
16
+ // Read the quotes into an array
17
+
18
+ $sql = 'SELECT quote_id, user_id FROM quotes';
19
+ $res = mysql_query($sql);
20
+ while ($row = mysql_fetch_assoc($res)) {
21
+  if (!isset($users[($row['user_id'])])) {
22
+   $users[($row['user_id'])] = 0;
23
+  }
24
+
25
+  $quotes[($row['quote_id'])] = new quote;
26
+  $quotes[($row['quote_id'])]->id = $row['quote_id'];
27
+  $quotes[($row['quote_id'])]->owner = $row['user_id'];
28
+ }
29
+
30
+ // And read the ratings in
31
+
32
+ $sql = 'SELECT user_id, quote_id, rating_change FROM ratings';
33
+ $res = mysql_query($sql);
34
+ while ($row = mysql_fetch_assoc($res)) {
35
+  $q =& $quotes[($row['quote_id'])];
36
+  $u =  $row['user_id'];
37
+
38
+  if (!isset($users[$u])) { $users[$u] = 0; }
39
+  
40
+  if ($row['rating_change'] > 0) {
41
+   $q->good[] = $u;
42
+  } elseif ($row['rating_change'] < 0) {
43
+   $q->bad[] = $u;
44
+  } else {
45
+   $q->neutral[] = $u;
46
+  }
47
+ }
48
+
49
+ define('USERS', count($users));
50
+ define('QUOTES', count($quotes));
51
+
52
+ // First pass: standings based on rating agreement
53
+
54
+ foreach ($quotes as $quote) {
55
+  $num = count($quote->good) + count($quote->bad);
56
+
57
+  if ($num == 0) { continue; }
58
+
59
+  $off = (1/QUOTES) * ($num/USERS);
60
+  $bad = $bad / $num;
61
+
62
+  foreach ($quote->bad as $uid) {
63
+   $users[$uid] += $off * $bad;
64
+  }
65
+  foreach ($quote->good as $uid) {
66
+   $users[$uid] += $off * (1 - $bad);
67
+  }
68
+  foreach ($quote->neutral as $uid) {
69
+   $users[$uid] += $off * 0.5;
70
+  } 
71
+ }
72
+
73
+ $fstanding = 0;
74
+ foreach ($users as $stand) { $fstanding += $stand; }
75
+ define('FSTANDING', $fstanding);
76
+
77
+ // Second pass: quote ratings
78
+
79
+ foreach ($quotes as $quote) {
80
+  $score = 0;
81
+
82
+  $off = 10/FSTANDING;
83
+
84
+  foreach ($quote->bad as $uid) {
85
+   $score -= $off * $users[$uid];
86
+  }
87
+  foreach ($quote->good as $uid) {
88
+   $score += $off * $users[$uid]; 
89
+  }
90
+  echo "Quote: ".$quote->id.' scores '.$score.'<br>';
91
+ }
92
+
93
+ echo "<hr>";
94
+
95
+ // Third pass: user standings
96
+ 
97
+?>

+ 61
- 0
inc/account.php View File

@@ -0,0 +1,61 @@
1
+<?PHP
2
+
3
+ require_once('inc/database.php');
4
+
5
+ session_name('qdb');
6
+ session_start();
7
+
8
+ if (!isset($_SESSION['uid']) && isset($_COOKIE['quotedbperm'])) {
9
+  $sql = 'SELECT user_id, user_standing, user_name FROM users WHERE user_hash = \''.m($_COOKIE['quotedbperm']).'\'';
10
+  $res = mysql_query($sql);
11
+  if (mysql_num_rows($res) == 1) {
12
+   $row = mysql_fetch_array($res);
13
+   $_SESSION['uid'] = $row['user_id'];
14
+   $_SESSION['uname'] = $row['user_name'];
15
+   $_SESSION['standing'] = $row['user_standing'];
16
+  }
17
+ }
18
+
19
+ if (isset($_SESSION['standing'])) {
20
+  $sql = 'SELECT user_standing FROM users WHERE user_id = '.$_SESSION['uid'];
21
+  $res = mysql_query($sql);
22
+  $row = mysql_fetch_array($res);
23
+  $_SESSION['standing'] = $row[0];
24
+ }
25
+
26
+ function doRate($id, $div = true) {
27
+  $sql = 'SELECT rating_change FROM ratings WHERE user_id = '.$_SESSION['uid'].' AND quote_id = '.$id;
28
+  $res = mysql_query($sql);
29
+  if (mysql_num_rows($res) == 0) {
30
+   if ($div) {
31
+    echo '<div class="rate" id="rate'.$id.'">';
32
+   }
33
+   echo '<form action="'.BASE.'rate" method="post">';
34
+   echo ' <input type="hidden" name="ref" value="'.$_SERVER['REQUEST_URI'].'">';
35
+   echo ' <input type="hidden" name="quote" value="'.$id.'">';
36
+   echo ' <input type="image" name="rateup" src="'.BASE.'res/plus.png" value="up" alt="Good" title="This is a good quote" onClick="return doRate(\'rateup\', '.$id.');">';
37
+   echo ' <input type="image" name="rateneutral" src="'.BASE.'res/neutral.png" value="neutral" alt="Neutral" title="This is an average quote" onClick="return doRate(\'rateneutral\', '.$id.');">';
38
+   echo ' <input type="image" name="ratedown" src="'.BASE.'res/minus.png" value="down" alt="Bad" title="This is a bad quote" onClick="return doRate(\'ratedown\', '.$id.');">';
39
+   echo '</form>';
40
+   if ($div) {
41
+    echo '</div>';
42
+   }
43
+  } else {
44
+   $row = mysql_fetch_array($res);
45
+   if ($div) {
46
+    echo '<div class="rate">';
47
+   }
48
+   if ($row['rating_change'] > 0) {
49
+    echo 'You rated this quote as good.';
50
+   } elseif ($row['rating_change'] == 0) {
51
+    echo 'You rated this quote as average.';
52
+   } else {
53
+    echo 'You rated this quote as bad.';
54
+   }
55
+   if ($div) {
56
+    echo '</div>';
57
+   }
58
+  }
59
+ }
60
+
61
+?>

+ 11
- 0
inc/database.php View File

@@ -0,0 +1,11 @@
1
+<?PHP
2
+
3
+ require_once('inc/settings.php');
4
+
5
+ mysql_connect(MYSQL_SERVER, MYSQL_USER, MYSQL_PASS);
6
+ mysql_select_db(MYSQL_DB);
7
+
8
+ function m ($t) { return mysql_real_escape_string($t); }
9
+
10
+
11
+?>

+ 3
- 0
inc/footer.php View File

@@ -0,0 +1,3 @@
1
+  </div>
2
+ </body>
3
+</html>

+ 68
- 0
inc/header.php View File

@@ -0,0 +1,68 @@
1
+<?PHP
2
+
3
+require_once('inc/settings.php');
4
+require_once('inc/account.php');
5
+
6
+?>
7
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
8
+<html>
9
+ <head>
10
+  <title>Quote db<?PHP if (defined('TITLE')) { echo ' : ' .TITLE; } ?></title>
11
+  <link rel="stylesheet" href="res/style.css" type="text/css">
12
+  <link rel="alternate" type="application/rss+xml" title="RSS 2.0" href="<?PHP echo BASE; ?>rss">
13
+  <script type="text/javascript" src="<?PHP echo BASE; ?>res/ajax.js">
14
+  </script>
15
+  <script type="text/javascript">
16
+   function stateChange (id) {
17
+    if (xmlhttp.readyState == 4) {
18
+     document.getElementById('rate'+id).innerHTML = xmlhttp.responseText;
19
+    }
20
+   }
21
+
22
+   function doRate (value, id) {
23
+    if (!xmlhttp) { return true; }
24
+
25
+    xmlhttp.open("GET", '<?PHP echo BASE; ?>rateajax?quote='+id+'&'+value, true);
26
+    xmlhttp.onreadystatechange = function () { stateChange(id); };
27
+    xmlhttp.send(null);
28
+
29
+    document.getElementById('rate'+id).innerHTML = 'Submitting...';
30
+
31
+    return false;
32
+   }
33
+  </script>
34
+ </head>
35
+ <body>
36
+  <h1>Quote db</h1>
37
+  <div id="menu">
38
+   <img src="<?PHP echo BASE; ?>res/bl.png" alt="Corner">
39
+   <span id="links">
40
+    <a href="<?PHP echo BASE; ?>">Overview</a> |
41
+    <a href="<?PHP echo BASE; ?>latest">Latest</a> |
42
+    <a href="<?PHP echo BASE; ?>best">Best</a> |
43
+    <a href="<?PHP echo BASE; ?>browse">Browse</a> |
44
+    <a href="<?PHP echo BASE; ?>random">Random</a>
45
+   </span>
46
+   <span id="rlinks">
47
+<?PHP
48
+
49
+ if (!isset($_SESSION['uid'])) {
50
+
51
+?>
52
+    <a href="<?PHP echo BASE; ?>login">Login</a> |
53
+    <a href="<?PHP echo BASE; ?>register">Register</a>
54
+<?PHP
55
+ } else {
56
+?>
57
+    <!--<a href="<?PHP echo BASE; ?>account">My account</a> |-->
58
+    <!--<a href="<?PHP echo BASE; ?>standing">-->
59
+    <a href="<?PHP echo BASE; ?>login">Logged in as <?PHP echo htmlentities($_SESSION['uname']); ?></a>
60
+    <!--</a>--> |
61
+    <a href="<?PHP echo BASE; ?>unrated">Unrated quotes</a> |
62
+    <a href="<?PHP echo BASE; ?>submit">Add quote</a>
63
+<?PHP
64
+ }
65
+?>    
66
+   </span>
67
+  </div>
68
+  <div id="content">

+ 21
- 0
inc/settings.php View File

@@ -0,0 +1,21 @@
1
+<?PHP
2
+
3
+ /* This is the settings file for the quotes database.
4
+  *
5
+  * You can either alter the constants below to configure the db,
6
+  * or you can copy them to settings.private.php (which is excluded
7
+  * from the VCS, if you're interested in developing the db further)
8
+  */
9
+
10
+ if (file_exists(dirname(__FILE__) . '/settings.private.php')) {
11
+  require_once(dirname(__FILE__) . '/settings.private.php');
12
+ } else {
13
+  define('BASE', '/quotes/'); // Absolute path to the quotes db
14
+
15
+  define('MYSQL_SERVER', 'localhost'); // MySQL server
16
+  define('MYSQL_USER', '');            // MySQL user
17
+  define('MYSQL_PASS', '');            // MySQL password
18
+  define('MYSQL_DB', '');              // MySQL db name
19
+ }
20
+
21
+?>

+ 94
- 0
index.php View File

@@ -0,0 +1,94 @@
1
+<?PHP
2
+
3
+require_once('inc/database.php');
4
+
5
+require_once('inc/header.php');
6
+
7
+?>
8
+<div class="oneThird right stats">
9
+ <h2>Statistics</h2>
10
+<?PHP
11
+
12
+ $sql = 'SELECT COUNT(*), AVG(quote_rating) FROM quotes';
13
+ $res = mysql_query($sql) or print(mysql_error());
14
+ $row = mysql_fetch_array($res); $quotes = $row[0];
15
+
16
+ echo '<p>We have <em>'.$row[0].'</em> quotes, with an average rating of <em>';
17
+ echo round($row[1],2).'</em>. These quotes were contributed by some of our ';
18
+
19
+ $sql = 'SELECT COUNT(*) FROM users';
20
+ $res = mysql_query($sql) or print(mysql_error());
21
+ $row = mysql_fetch_array($res); $users = $row[0];
22
+
23
+ echo '<em>'.$row[0].'</em> users, who have made a total of <em>';
24
+
25
+ $sql = 'SELECT COUNT(*) FROM ratings';
26
+ $res = mysql_query($sql) or print(mysql_error());
27
+ $row = mysql_fetch_array($res);
28
+
29
+ echo $row[0].'</em> individual ratings, an average of <em>';
30
+ echo round($row[0]/$users,1).'</em> quotes rated per user.</p>';
31
+
32
+ if (isset($_SESSION['uid'])) { 
33
+ 
34
+  echo '<h2>Your stats</h2>';
35
+  echo '<p>';
36
+ 
37
+  $sql = 'SELECT COUNT(*), AVG(quote_rating) FROM quotes WHERE user_id = '.$_SESSION['uid'];
38
+  $res = mysql_query($sql) or print(mysql_error());
39
+  $row = mysql_fetch_array($res);
40
+
41
+  echo 'You have submitted <em>'.$row[0].'</em> quote';
42
+  echo ($row[0] != 1 ? 's' : '').' that have an average rating of <em>';
43
+  echo round($row[1],2).'</em>.';
44
+
45
+  $sql = 'SELECT COUNT(*) FROM ratings WHERE user_id = '.$_SESSION['uid'];
46
+  $res = mysql_query($sql) or print(mysql_error());
47
+  $row = mysql_fetch_array($res);
48
+
49
+  echo ' You have rated <em>'.$row[0].'</em> quote';
50
+  if ($row[0] != 1) { echo 's'; }
51
+  echo '.';
52
+
53
+  if ($row[0] < $quotes) {
54
+   echo ' Why not rate <a href="'.BASE.'unrated">some more</a>?.';
55
+  } else {
56
+   echo ' Wow, that\'s all of them. Why not <a href="'.BASE.'submit">add a new quote</a>?';
57
+  }
58
+ }
59
+?>
60
+</div>
61
+<div>
62
+ <h2>Welcome</h2>
63
+ <p>Welcome to the quote db. You might think that this is just another bash
64
+ clone, and you'd be partly right. But the quote db has some key differences.
65
+ First off, we don't have any moderators. Every person starts with the same
66
+ access to the site. When you submit a quote, it appears instantly on the 
67
+ <a href="<?PHP echo BASE; ?>latest">latest quotes</a> page, where other users
68
+ can rate it as good, bad or neutral. 
69
+ </p>
70
+ <p>
71
+  If the quotes you submit get a poor rating, this will reflect on you and your
72
+  <em>standing</em> will decrease. Your standing is displayed on the right of
73
+  the menu bar when you're logged in, and operates on a scale of -10 to +10.
74
+  If your standing drops too low, your ability to add quotes will be suspended.
75
+  Conversely, if your quotes are met with a standing ovation (and good ratings),
76
+  your standing will increase. This, in turn, affects how much your opinion is
77
+  taken into account when you rate quotes. The higher standing you have, the
78
+  more of an impact your ratings will have.
79
+ </p>
80
+ <p>
81
+  The Quote DB now supports OpenID. Simply enter your
82
+  OpenID identifier on the <a href="<?PHP echo BASE; ?>login">login</a>
83
+  page.
84
+ </p>
85
+ <p>
86
+  <strong>New!</strong> The Quote DB now fully supports Unicode (UTF-8) quotes
87
+ </p>
88
+</div>
89
+
90
+<?PHP
91
+
92
+require_once('inc/footer.php');
93
+
94
+?>

+ 52
- 0
latest.php View File

@@ -0,0 +1,52 @@
1
+<?PHP
2
+
3
+ require_once('inc/database.php');
4
+
5
+ define('TITLE', 'Latest');
6
+
7
+ require_once('inc/header.php');
8
+
9
+ $sql = 'SELECT quote_id, quote_quote, quote_rating FROM quotes ORDER BY quote_id DESC LIMIT 0,25';
10
+ $res = mysql_query($sql)
11
+
12
+?>
13
+<div>
14
+ <h2>Latest quotes</h2>
15
+<?PHP
16
+
17
+ $i = 0;
18
+ while ($row = mysql_fetch_array($res)) {
19
+  $i = 1 - $i;
20
+  if ($i == 1) { $e = 'even'; } else { $e = 'odd'; }
21
+?>
22
+ <div class="quote <?PHP echo $e; ?>">
23
+<?PHP
24
+ if (isset($_SESSION['uid'])) {
25
+  doRate($row['quote_id']);
26
+ }
27
+?>
28
+  <p>
29
+   Quote <a href="<?PHP echo BASE; ?>browse?q=<?PHP echo $row['quote_id']; ?>">#<?PHP echo $row['quote_id']; ?></a>.
30
+   Rating <?PHP echo round($row['quote_rating'],2); ?>.
31
+<?PHP
32
+
33
+ if (!isset($_SESSION['uid'])) {
34
+  echo ' <a href="'.BASE.'login">Login to rate</a>.';
35
+ }
36
+
37
+?>
38
+  </p>
39
+  <div class="quotebody">
40
+   <?PHP echo nl2br(htmlentities($row['quote_quote'], ENT_QUOTES, 'UTF-8')); ?>
41
+  </div>
42
+ </div>
43
+<?PHP
44
+ }
45
+
46
+?>
47
+</div>
48
+<?PHP
49
+
50
+ require_once('inc/footer.php');
51
+
52
+?>

+ 146
- 0
login.php View File

@@ -0,0 +1,146 @@
1
+<?PHP
2
+
3
+ require_once('inc/database.php');
4
+ require_once('inc/account.php');
5
+ require_once('inc/settings.php');
6
+
7
+
8
+
9
+ if (isset($_POST['openid_url']) || isset($_REQUEST['openid_mode'])) {
10
+  // OpenID login in progress
11
+
12
+  require_once('openid/processor.php');
13
+ } else if (isset($_SESSION['openid']) && $_SESSION['openid']['validated']) {
14
+  // OpenID login succeeded
15
+
16
+  $sql  = 'SELECT user_id, user_name, user_standing FROM users WHERE user_name = ';
17
+  $sql .= '\'' . m($_SESSION['openid']['identity']) . '\'';
18
+  $res  = mysql_query($sql);
19
+
20
+  if (mysql_num_rows($res) == 0) {
21
+   $sql  = 'INSERT INTO users (user_name, user_pass) VALUES (\'' . m($_SESSION['openid']['identity']);
22
+   $sql .= '\', \'openid user\')';
23
+   $res  = mysql_query($sql);
24
+
25
+   $_SESSION['uid'] = mysql_insert_id();
26
+   $_SESSION['uname'] = $_SESSION['openid']['identity'];
27
+   $_SESSION['standing'] = 0;
28
+  } else {
29
+   $row = mysql_fetch_assoc($res);
30
+ 
31
+   $_SESSION['uid'] = $row['user_id'];
32
+   $_SESSION['uname'] = $row['user_name'];
33
+   $_SESSION['standing'] = $row['user_standing'];
34
+  }
35
+
36
+  unset($_SESSION['openid']);
37
+  if (isset($_POST['remember'])) {
38
+   $row = mysql_fetch_array(mysql_query('SELECT user_hash FROM users WHERE user_id = '.$_SESSION['uid']));
39
+   if (strlen($row[0]) != 32) {
40
+    $row[0] = md5(uniqid($_SESSION['uid']).time());
41
+    mysql_query('UPDATE users SET user_hash = \''.$row[0].'\' WHERE user_id = '.$_SESSION['uid']);
42
+   }
43
+   setcookie('quotedbperm', $row[0], time()+60*24*24*365.24);
44
+  }
45
+  header('Location: '.BASE);
46
+  exit;
47
+ } else if (isset($_SESSION['openid']['error'])) {
48
+  // OpenID login failed
49
+
50
+  define('MESSAGE', $_SESSION['openid']['error']);
51
+  unset($_SESSION['openid']['error']);
52
+ } else if (isset($_POST['user']) && isset($_POST['pass'])) {
53
+  // Normal login
54
+
55
+  $sql  = 'SELECT user_id, user_name, user_standing FROM users ';
56
+  $sql .= 'WHERE user_name = \''.m($_POST['user']).'\' AND user_pass = \''.m(md5($_POST['user'].$_POST['pass'])).'\'';
57
+  $res = mysql_query($sql);
58
+  if (mysql_num_rows($res) == 0) {
59
+   define('MESSAGE', 'Login failed. Please check your username and password.');
60
+  } else {
61
+   $row = mysql_fetch_array($res);
62
+   $_SESSION['uid'] = $row['user_id'];
63
+   $_SESSION['uname'] = $row['user_name'];
64
+   $_SESSION['standing'] = $row['user_standing'];
65
+   if (isset($_POST['remember'])) {
66
+    $row = mysql_fetch_array(mysql_query('SELECT user_hash FROM users WHERE user_id = '.$_SESSION['uid']));
67
+    if (strlen($row[0]) != 32) {
68
+     $row[0] = md5(uniqid($row['user_id']).time());
69
+     mysql_query('UPDATE users SET user_hash = \''.$row[0].'\' WHERE user_id = '.$_SESSION['uid']);
70
+    }
71
+    setcookie('quotedbperm', $row[0], time()+60*24*24*365.24);
72
+   }
73
+   header('Location: '.BASE);
74
+   exit;
75
+  }
76
+ }
77
+
78
+ define('TITLE', 'Login');
79
+
80
+ require_once('inc/header.php');
81
+
82
+?>
83
+ <div class="oneThird right">
84
+  <h2>Why login?</h2>
85
+  <p>
86
+   Because of the public nature of this quotes database (there are no
87
+   moderators or admins, just users), and the way we reward good users
88
+   and punish bad ones (standings), we require that you be logged in in
89
+   order to rate a quote or add a new one.
90
+  </p>
91
+  <p>
92
+   You can still browse quotes without being logged in, but to contribute
93
+   to the site at all you'll have to login.
94
+  </p>
95
+ </div>
96
+ <div>
97
+  <h2>Login</h2>
98
+<?PHP
99
+
100
+ if (defined('MESSAGE')) {
101
+  echo '<div id="message">'.MESSAGE.'</div>';
102
+ }
103
+
104
+
105
+?>
106
+  <p>
107
+   If you don't have an account, <a href="<?PHP echo BASE; ?>register">
108
+   register one</a> in a few seconds.
109
+  </p>
110
+  <form action="<?PHP echo BASE; ?>login" method="post">
111
+   <table class="form">
112
+    <tr>
113
+     <th>Username</th>
114
+     <td><input type="text" name="user"></td>
115
+    </tr>
116
+    <tr>
117
+     <th>Password</th>
118
+     <td><input type="password" name="pass"></td>
119
+    </tr>
120
+    <tr>
121
+     <th>Remember?</th>
122
+     <td><input type="checkbox" name="remember" style="width: 20px;"> (Requires cookies)</td>
123
+    </tr>
124
+   </table>
125
+   <input type="submit" value="Login">
126
+  </form>
127
+  <p>Alternatively, you can log in using OpenID:</p>
128
+  <form action="<?PHP echo BASE; ?>login" method="post">
129
+   <table class="form">
130
+    <tr><th>Identifier</th>
131
+        <td>
132
+    <input type="text" name="openid_url" id="openid_url" style="background: url('openid/openid.gif') no-repeat; padding-left: 20px;">
133
+    </td></tr>
134
+    <tr>
135
+     <th>Remember?</th>
136
+     <td><input type="checkbox" name="remember" style="width: 20px;"> (Requires cookies)</td>
137
+    </tr>
138
+   </table>
139
+   <input type="submit" value="Login">
140
+  </form>
141
+ </div>
142
+<?PHP
143
+
144
+ require_once('inc/footer.php');
145
+
146
+?>

+ 1
- 0
openid

@@ -0,0 +1 @@
1
+Subproject commit dce9787dab059f4270c0506c307dc7dbd8cdc5ea

+ 52
- 0
random.php View File

@@ -0,0 +1,52 @@
1
+<?PHP
2
+
3
+ require_once('inc/database.php');
4
+
5
+ define('TITLE', 'Random');
6
+
7
+ require_once('inc/header.php');
8
+
9
+ $sql = 'SELECT quote_id, quote_quote, quote_rating FROM quotes ORDER BY RAND() DESC LIMIT 0,25';
10
+ $res = mysql_query($sql)
11
+
12
+?>
13
+<div>
14
+ <h2>Random quotes</h2>
15
+<?PHP
16
+
17
+ $i = 0;
18
+ while ($row = mysql_fetch_array($res)) {
19
+  $i = 1 - $i;
20
+  if ($i == 1) { $e = 'even'; } else { $e = 'odd'; }
21
+?>
22
+ <div class="quote <?PHP echo $e; ?>">
23
+<?PHP
24
+ if (isset($_SESSION['uid'])) {
25
+  doRate($row['quote_id']);
26
+ }
27
+?>
28
+  <p>
29
+   Quote <a href="<?PHP echo BASE; ?>browse?q=<?PHP echo $row['quote_id']; ?>">#<?PHP echo $row['quote_id']; ?></a>.
30
+   Rating <?PHP echo round($row['quote_rating'],2); ?>.
31
+<?PHP
32
+
33
+ if (!isset($_SESSION['uid'])) {
34
+  echo ' <a href="'.BASE.'login">Login to rate</a>.';
35
+ }
36
+
37
+?>
38
+  </p>
39
+  <div class="quotebody">
40
+   <?PHP echo nl2br(htmlentities($row['quote_quote'], ENT_QUOTES, 'UTF-8')); ?>
41
+  </div>
42
+ </div>
43
+<?PHP
44
+ }
45
+
46
+?>
47
+</div>
48
+<?PHP
49
+
50
+ require_once('inc/footer.php');
51
+
52
+?>

+ 33
- 0
rate.php View File

@@ -0,0 +1,33 @@
1
+<?PHP
2
+
3
+ require_once('inc/account.php');
4
+ require_once('inc/settings.php');
5
+ require_once('inc/database.php');
6
+
7
+ if (!isset($_SESSION['uid'])) {
8
+  header('Location: '.BASE.'login');
9
+  exit;
10
+ }
11
+
12
+ if (isset($_POST['quote']) && ctype_digit($_POST['quote'])) {
13
+  if (isset($_POST['rateup'])) { $base = 1; } elseif (isset($_POST['ratedown'])) { $base = -1; } else { $base = 0; }
14
+  $base *= (($_SESSION['standing'] + 10) / 10);
15
+  $sql = 'SELECT rating_change FROM ratings WHERE user_id = '.$_SESSION['uid'].' AND quote_id = '.m($_POST['quote']);
16
+  $res = mysql_query($sql);
17
+  if (mysql_num_rows($res) == 0) {
18
+   if ($_POST['quote'] != 62) {
19
+    mysql_query('INSERT INTO ratings (user_id, quote_id, rating_change) VALUES ('.$_SESSION['uid'].', '.m($_POST['quote']).', '.$base.')');
20
+    mysql_query('UPDATE quotes SET quote_rating = quote_rating + '.$base.', quote_rated = quote_rated + 1 WHERE quote_id = '.m($_POST['quote']));
21
+    require('dostanding.php');
22
+   }
23
+   header('Location: '.$_POST['ref']);
24
+   exit;
25
+  } else {
26
+   header('Location: '.$_POST['ref']);
27
+   exit;  
28
+  }
29
+ } else {
30
+  die('Invalid quote');
31
+ }
32
+
33
+?>

+ 29
- 0
rateajax.php View File

@@ -0,0 +1,29 @@
1
+<?PHP
2
+
3
+ require_once('inc/account.php');
4
+ require_once('inc/settings.php');
5
+ require_once('inc/database.php');
6
+
7
+ if (!isset($_SESSION['uid'])) {
8
+  header('Location: '.BASE.'login');
9
+  exit;
10
+ }
11
+
12
+ if (isset($_GET['quote']) && ctype_digit($_GET['quote'])) {
13
+  if (isset($_GET['rateup'])) { $base = 1; } elseif (isset($_GET['ratedown'])) { $base = -1; } else { $base = 0; }
14
+  $base *= (($_SESSION['standing'] + 10) / 10);
15
+  $sql = 'SELECT rating_change FROM ratings WHERE user_id = '.$_SESSION['uid'].' AND quote_id = '.m($_GET['quote']);
16
+  $res = mysql_query($sql);
17
+  if (mysql_num_rows($res) == 0) {
18
+   if ($_GET['quote'] != 62) {
19
+    mysql_query('INSERT INTO ratings (user_id, quote_id, rating_change) VALUES ('.$_SESSION['uid'].', '.m($_GET['quote']).', '.$base.')');
20
+    mysql_query('UPDATE quotes SET quote_rating = quote_rating + '.$base.', quote_rated = quote_rated + 1 WHERE quote_id = '.m($_GET['quote']));
21
+    require('dostanding.php');
22
+   }
23
+  }
24
+  doRate($_GET['quote'], false);
25
+ } else {
26
+  die('Invalid quote');
27
+ }
28
+
29
+?>

+ 119
- 0
register.php View File

@@ -0,0 +1,119 @@
1
+<?PHP
2
+
3
+ require_once('inc/database.php');
4
+ require_once('inc/settings.php');
5
+ require_once('inc/account.php');
6
+
7
+ function oink() {
8
+  if (isset($_POST['user']) && isset($_POST['pass']) && isset($_POST['pass2'])) {
9
+   if ($_POST['pass2'] != $_POST['pass']) {
10
+    define('MESSAGE', 'Your passwords do not match.');
11
+    return;
12
+   }
13
+
14
+   if (strlen($_POST['pass']) < 5) {
15
+    define('MESSAGE', 'Your password must be at least 5 characters.');
16
+    return;
17
+   }
18
+
19
+   if (strlen($_POST['user']) < 3) {
20
+    define('MESSAGE', 'Your username must be at least 3 characters.');
21
+    return;
22
+   }
23
+
24
+   if (strlen($_POST['user']) > 20) {
25
+    define('MESSAGE', 'Your username must be at most 20 characters.');
26
+    return;
27
+   }
28
+
29
+   if (!preg_match('/^[a-zA-Z0-9\-]+$/', $_POST['user'])) {
30
+    define('MESSAGE', 'Your username may only contain letters, numbers and hyphens.');
31
+    return;
32
+   }
33
+
34
+   $sql = 'SELECT user_id FROM users WHERE user_name LIKE \''.m($_POST['user']).'\'';
35
+   $res = mysql_query($sql);
36
+   if (mysql_num_rows($res) > 0) {
37
+    define('MESSAGE', 'That username is in use. Please try another.');
38
+    return;
39
+   }
40
+
41
+   $sql = 'INSERT INTO users (user_name, user_pass) VALUES (\''.m($_POST['user']).'\', \''.m(md5($_POST['user'].$_POST['pass'])).'\')';
42
+   $res = mysql_query($sql);
43
+   $id = mysql_insert_id();
44
+   
45
+   $_SESSION['uid'] = $id;
46
+   $_SESSION['uname'] = $_POST['user'];
47
+   $_SESSION['standing'] = 0;
48
+
49
+   if (isset($_POST['remember'])) {
50
+    $row = mysql_fetch_array(mysql_query('SELECT user_hash FROM users WHERE user_id = '.$_SESSION['uid']));
51
+    if (strlen($row[0]) != 32) {
52
+     $row[0] = md5(uniqid($row['user_id']).time());
53
+     mysql_query('UPDATE users SET user_hash = \''.$row[0].'\' WHERE user_id = '
54
+.$_SESSION['uid']);
55
+    }
56
+    setcookie('quotedbperm', $row[0], time()+60*24*24*365.24);
57
+   }
58
+  
59
+   header('Location: '.BASE);
60
+   exit;
61
+  }
62
+ }
63
+
64
+ oink();
65
+
66
+ define('TITLE', 'Register');
67
+
68
+ require_once('inc/header.php');
69
+
70
+?>
71
+ <div class="oneThird right">
72
+  <h2>Why register?</h2>
73
+  <p>
74
+   Because of the public nature of this quotes database (there are no
75
+   moderators or admins, just users), and the way we reward good users
76
+   and punish bad ones (standings), we require that you be logged in in
77
+   order to rate a quote or add a new one.
78
+  </p>
79
+  <p>
80
+   In order to log in to the site, you first need a user account. To obtain
81
+   an account, simply fill out the form to the left. 
82
+  </p>
83
+ </div>
84
+ <div>
85
+  <h2>Register</h2>
86
+<?PHP
87
+ if (defined('MESSAGE')) { echo '<div id="message">'.MESSAGE.'</div>'; }
88
+?>
89
+  <p>
90
+   If you already have an account, you should 
91
+   <a href="<?PHP echo BASE; ?>login">login</a> instead.
92
+  </p>
93
+  <form action="<?PHP echo BASE; ?>register" method="post">
94
+   <table class="form">
95
+    <tr>
96
+     <th>Username</th>
97
+     <td><input type="text" name="user"></td>
98
+    </tr>
99
+    <tr>
100
+     <th>Password</th>
101
+     <td><input type="password" name="pass"></td>
102
+    </tr>
103
+    <tr>
104
+     <th>Confirm password</th>
105
+     <td><input type="password" name="pass2"></td>
106
+    </tr>
107
+    <tr>
108
+     <th>Remember?</th>
109
+     <td><input type="checkbox" name="remember" style="width: 20px;"> (Requires cookies)</td>
110
+    </tr>
111
+   </table>
112
+   <input type="submit" value="Login">
113
+  </form>
114
+ </div>
115
+<?PHP
116
+
117
+ require_once('inc/footer.php');
118
+
119
+?>

+ 33
- 0
res/ajax.js View File

@@ -0,0 +1,33 @@
1
+var xmlhttp=false;
2
+
3
+/*@cc_on @*/
4
+/*@if (@_jscript_version >= 5)
5
+// JScript gives us Conditional compilation, we can cope with old IE versions.
6
+// and security blocked creation of the objects.
7
+try {
8
+ xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
9
+} catch (e) {
10
+ try {
11
+  xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
12
+ } catch (E) {
13
+  xmlhttp = false;
14
+ }
15
+}
16
+@end @*/
17
+
18
+if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
19
+ try {
20
+  xmlhttp = new XMLHttpRequest();
21
+ } catch (e) {
22
+  xmlhttp = false;
23
+ }
24
+}
25
+
26
+if (!xmlhttp && window.createRequest) {
27
+ try {
28
+  xmlhttp = window.createRequest();
29
+ } catch (e) {
30
+  xmlhttp = false;
31
+ }
32
+}
33
+

BIN
res/bl.png View File


BIN
res/br.png View File


BIN
res/minus.png View File


BIN
res/neutral.png View File


BIN
res/plus.png View File


+ 113
- 0
res/style.css View File

@@ -0,0 +1,113 @@
1
+body {
2
+ margin: 0px 50px;
3
+ padding: 0px;
4
+ font-family: tahoma, arial, sans-serif;
5
+}
6
+
7
+h1 {
8
+ margin: 0px;
9
+ padding: 3px 10px;
10
+ color: #fff;
11
+ background-color: #006;
12
+ font-size: 2em;
13
+ font-family: serif;
14
+}
15
+
16
+div#menu {
17
+ background-color: #ccc;
18
+ padding: 0px; 
19
+ background-image: url('br.png');
20
+ background-position: bottom right;
21
+ background-repeat: no-repeat;
22
+ height: 40px;
23
+}
24
+
25
+div#menu img {
26
+ float: left;
27
+}
28
+
29
+div#menu a {
30
+ color: #339;
31
+ padding: 0px 10px;
32
+}
33
+
34
+div#menu a:visited {
35
+ color: #333;
36
+}
37
+
38
+span#links {
39
+ float: left;
40
+ padding-top: 10px;
41
+}
42
+
43
+span#rlinks {
44
+ float: right;
45
+ padding-top: 10px;
46
+ padding-right: 25px;
47
+}
48
+
49
+div#content {
50
+ padding: 5px 10px;
51
+ line-height: 150%;
52
+}
53
+
54
+div.oneThird {
55
+ width: 30%;
56
+}
57
+
58
+div.right {
59
+ float: right;
60
+ padding-left: 20px;
61
+}
62
+
63
+table.form  {
64
+ border-collapse: collapse;
65
+ margin: 0px 0px 10px 0px;
66
+}
67
+
68
+table.form td, table.form th {
69
+ border: 1px solid #666;
70
+ padding: 5px;
71
+}
72
+
73
+table.form th {
74
+ background-color: #ccc;
75
+ text-align: right;
76
+}
77
+
78
+table.form input {
79
+ border: 0px;
80
+ width: 200px;
81
+}
82
+
83
+div.quote {
84
+ margin: 0px 10px;
85
+ padding: 5px 10px 5px;
86
+}
87
+
88
+div.quote p { margin: 0px 0px 5px 0px; }
89
+
90
+div.odd {
91
+ background-color: #ddd;
92
+ border-top: 10px solid #fff;
93
+ border-bottom: 10px solid #fff;
94
+}
95
+
96
+div.quotebody {
97
+ font-size: small;
98
+}
99
+
100
+.rate {
101
+ float: right;
102
+}
103
+
104
+div.stats em {
105
+ font-style: normal;
106
+ font-weight: bold;
107
+}
108
+
109
+div.nav {
110
+ margin: 10px;
111
+ padding-left: 10px;
112
+ padding-bottom: 20px; 
113
+}

+ 34
- 0
rss.php View File

@@ -0,0 +1,34 @@
1
+<?PHP
2
+
3
+ require_once('inc/database.php');
4
+
5
+ header('Content-type: text/xml');
6
+
7
+
8
+ $sql  = 'SELECT quote_id, quote_quote, quote_rating FROM quotes ';
9
+
10
+ if (isset($_GET['id'])) {
11
+  $sql .= 'WHERE quote_id = ' . ((int) $_GET['id']) . ' ';
12
+ }
13
+
14
+ $sql .= 'ORDER BY quote_id DESC LIMIT 0,25';
15
+ $res = mysql_query($sql)
16
+
17
+?>
18
+<?PHP echo '<?xml version="1.0" encoding="UTF-8"?>'; ?>
19
+<rss version="2.0">
20
+<channel>
21
+ <title>Quote db</title>
22
+ <link>http://apps.MD87.co.uk/quotes/</link>
23
+ <description>Latest quotes from the quote database</description>
24
+<?PHP
25
+ while ($row = mysql_fetch_array($res)) {
26
+   echo '<item><title>Quote '.$row['quote_id'].'</title>';
27
+   echo '<guid isPermaLink="true">http://apps.MD87.co.uk/quotes/browse?q='.$row['quote_id'].'</guid><description><![CDATA[';
28
+   echo nl2br(htmlentities($row['quote_quote'], ENT_QUOTES, 'UTF-8')); 
29
+   echo ']]></description></item>';
30
+ }
31
+
32
+?>
33
+</channel>
34
+</rss>

+ 66
- 0
submit.php View File

@@ -0,0 +1,66 @@
1
+<?PHP
2
+
3
+ require_once('inc/account.php');
4
+ require_once('inc/database.php');
5
+ require_once('inc/settings.php');
6
+
7
+ if (!isset($_SESSION['uid'])) {
8
+  header('Location: '.BASE);
9
+  exit('Must be logged in');
10
+ }
11
+
12
+ if (isset($_POST['quote']) && $_SESSION['standing'] > -2) {
13
+  if (get_magic_quotes_gpc()) {
14
+   $_POST['quote'] = stripslashes($_POST['quote']);
15
+  }
16
+  $sql = 'INSERT INTO quotes (quote_quote, quote_time, user_id) VALUES (\''.m($_POST['quote']).'\', '.time().', '.$_SESSION['uid'].')';
17
+  mysql_query($sql);
18
+  header('Location: '.BASE.'latest');
19
+  exit;
20
+ }
21
+
22
+ define('TITLE', 'Add quote');
23
+
24
+ require_once('inc/header.php');
25
+
26
+
27
+?>
28
+<div class="oneThird right">
29
+ <h2>Quote guidelines</h2>
30
+ <p>
31
+  The usual quote-site rules apply: don't include anything that's not 
32
+  neccessary, such as timestamps, hostmasks, twenty 'lol's after the funny
33
+  part, etc. Try to avoid injokes if possible.
34
+ </p>
35
+ <p>
36
+  <em>Quotes go live as soon as you submit them</em>. There is no moderation.
37
+  If you submit a rubbish quote, people will rate it down, and your standing
38
+  will fall.
39
+ </p>
40
+ <p>
41
+  Try to stick to standard notation. Enclose nicks in angle brackets
42
+  (&lt;nick&gt; hi!), and prefix actions with an asterisk (* nick waves).
43
+  Remove mode prefixes (@, +, etc) that don't directly add to the humour.
44
+ </p>
45
+</div>
46
+<div>
47
+<?PHP if ($_SESSION['standing'] > -2) { ?>
48
+ <h2>Add a quote</h2>
49
+ <p>Enter your quote in the text area below. Please read the guidelines to
50
+ the right if you haven't done so before.</p>
51
+ <form action="submit" method="post">
52
+  <textarea name="quote" cols="80" rows="10"></textarea>
53
+  <br>
54
+  <input type="submit" value="Add">
55
+ </form>
56
+<?PHP } else { ?>
57
+ <h2>Error</h2>
58
+ <p>You do not have sufficient standing to submit a new quote. Please try
59
+ <a href="unrated">rating some quotes</a> to increase your standings. </p>
60
+<?PHP } ?>
61
+</div>
62
+<?PHP
63
+
64
+ require_once('inc/footer.php');
65
+
66
+?>

+ 68
- 0
unrated.php View File

@@ -0,0 +1,68 @@
1
+<?PHP
2
+
3
+ require_once('inc/database.php');
4
+ require_once('inc/account.php');
5
+ require_once('inc/settings.php');
6
+
7
+ if (!isset($_SESSION['uid'])) { header('Location: '.BASE.'latest'); exit; }
8
+
9
+ define('TITLE', 'Unrated');
10
+
11
+ require_once('inc/header.php');
12
+
13
+ $sql = 'SELECT quote_id FROM ratings WHERE user_id = '.$_SESSION['uid'];
14
+ $res = mysql_query($sql);
15
+ $s = '(1';
16
+ while ($row = mysql_fetch_array($res)) {
17
+  $s .= ' AND quote_id <> '.$row[0];
18
+ }
19
+ $s .= ')';
20
+
21
+ $sql = 'SELECT quote_id, quote_quote, quote_rating FROM quotes WHERE '.$s.' ORDER BY quote_id DESC LIMIT 0,25';
22
+ $res = mysql_query($sql)
23
+
24
+?>
25
+<div>
26
+ <h2>Unrated quotes</h2>
27
+<?PHP
28
+
29
+ if (mysql_num_rows($res) == 0) {
30
+  echo '<p>You\'ve rated every quote in the database! Why not <a href="'.BASE.'"submit">add a new one?</a></p>';
31
+ }
32
+
33
+ $i = 0;
34
+ while ($row = mysql_fetch_array($res)) {
35
+  $i = 1 - $i;
36
+  if ($i == 1) { $e = 'even'; } else { $e = 'odd'; }
37
+?>
38
+ <div class="quote <?PHP echo $e; ?>">
39
+<?PHP
40
+ if (isset($_SESSION['uid'])) {
41
+  doRate($row['quote_id']);
42
+ }
43
+?>
44
+  <p>
45
+   Quote <a href="<?PHP echo BASE; ?>browse?q=<?PHP echo $row['quote_id']; ?>">#<?PHP echo $row['quote_id']; ?></a>.
46
+   Rating <?PHP echo round($row['quote_rating'],2); ?>.
47
+<?PHP
48
+
49
+ if (!isset($_SESSION['uid'])) {
50
+  echo ' <a href="'.BASE.'login">Login to rate</a>.';
51
+ }
52
+
53
+?>
54
+  </p>
55
+  <div class="quotebody">
56
+   <?PHP echo nl2br(htmlentities($row['quote_quote'])); ?>
57
+  </div>
58
+ </div>
59
+<?PHP
60
+ }
61
+
62
+?>
63
+</div>
64
+<?PHP
65
+
66
+ require_once('inc/footer.php');
67
+
68
+?>

+ 52
- 0
worst.php View File

@@ -0,0 +1,52 @@
1
+<?PHP
2
+
3
+ require_once('inc/database.php');
4
+
5
+ define('TITLE', 'Worst');
6
+
7
+ require_once('inc/header.php');
8
+
9
+ $sql = 'SELECT quote_id, quote_quote, quote_rating FROM quotes ORDER BY quote_rating LIMIT 0,25';
10
+ $res = mysql_query($sql)
11
+
12
+?>
13
+<div>
14
+ <h2>Worst quotes</h2>
15
+<?PHP
16
+
17
+ $i = 0;
18
+ while ($row = mysql_fetch_array($res)) {
19
+  $i = 1 - $i;
20
+  if ($i == 1) { $e = 'even'; } else { $e = 'odd'; }
21
+?>
22
+ <div class="quote <?PHP echo $e; ?>">
23
+<?PHP
24
+ if (isset($_SESSION['uid'])) {
25
+  doRate($row['quote_id']);
26
+ }
27
+?>
28
+  <p>
29
+   Quote <a href="<?PHP echo BASE; ?>browse?q=<?PHP echo $row['quote_id']; ?>">#<?PHP echo $row['quote_id']; ?></a>.
30
+   Rating <?PHP echo round($row['quote_rating'],2); ?>.
31
+<?PHP
32
+
33
+ if (!isset($_SESSION['uid'])) {
34
+  echo ' <a href="'.BASE.'login">Login to rate</a>.';
35
+ }
36
+
37
+?>
38
+  </p>
39
+  <div class="quotebody">
40
+   <?PHP echo nl2br(htmlentities($row['quote_quote'], ENT_QUOTES, 'UTF-8')); ?>
41
+  </div>
42
+ </div>
43
+<?PHP
44
+ }
45
+
46
+?>
47
+</div>
48
+<?PHP
49
+
50
+ require_once('inc/footer.php');
51
+
52
+?>

Loading…
Cancel
Save