index.php 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. <?php
  2. // This is the web page for the QuoteEngine
  3. //
  4. // It goes with the QuoteEngine script for eggdrop by JamesOff
  5. // http://jamesoff.net
  6. //
  7. // There are a couple of things to change in the settings file
  8. // before this script can be used
  9. require("settings.inc");
  10. if (SETTINGS_EDITED == false) {
  11. die("Please edit the settings.inc file before using the script.");
  12. }
  13. if (!mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASS)) {
  14. die("Unable to connect to database.");
  15. }
  16. if (!mysql_select_db(MYSQL_DB)) {
  17. die("Unable to select database.");
  18. }
  19. if (isset($_GET['channel'])) {
  20. $channel = $_GET['channel'];
  21. }
  22. else {
  23. $channel = DEFAULT_CHAN;
  24. }
  25. if (isset($_GET['remote'])) {
  26. $remote = $_GET['remote'];
  27. }
  28. if (isset($_GET['filter'])) {
  29. $filter = $_GET['filter'];
  30. }
  31. if (isset($_GET['page'])) {
  32. $page = $_GET['page'];
  33. }
  34. if (empty($channel)) {
  35. $channel = DEFAULT_CHAN;
  36. }
  37. if (!isset($remote) || empty($remote)) {
  38. $remote = 0;
  39. }
  40. function parse_quote($quote) {
  41. }
  42. if (!$remote) {
  43. ?>
  44. <html>
  45. <head>
  46. <title><?php
  47. if ($channel == "__all") {
  48. echo "Quotes from " . QUOTES_HOST;
  49. }
  50. else {
  51. echo "#" . $channel . " quotes from " . QUOTES_HOST;
  52. }
  53. ?></title>
  54. <link rel="stylesheet" type="text/css" href="<?php echo QUOTES_CSS; ?>">
  55. </head>
  56. <?php
  57. }
  58. //check if we should be displaying all quotes from a channel
  59. $single_quote = "";
  60. if (isset($_GET['q']) && !empty($_GET['q']) && is_numeric($_GET['q'])) {
  61. $single_quote = mysql_real_escape_string($_GET['q']);
  62. }
  63. if ($single_quote == "") {
  64. //display list
  65. if (!$remote) {
  66. ?>
  67. <body>
  68. <h1><center><?php
  69. if ($channel == "__all") {
  70. echo "All";
  71. }
  72. else {
  73. echo "#" . $channel;
  74. }
  75. ?> quotes</center></h1>
  76. <br>
  77. <center><form method="get" action="<?=$_SERVER['PHP_SELF'];?>">
  78. Filter for: <input type="text" name="filter" maxlength="32" size="32"> <input type="submit" value="go"><input type="hidden" name="channel" value="<?=$channel?>">
  79. </form>
  80. <?php
  81. $result = mysql_query("SELECT DISTINCT channel FROM quotes ORDER BY channel");
  82. echo "<small>Other channels<br> :: ";
  83. while ($chan = mysql_fetch_object($result)) {
  84. $chanlink = preg_replace("/#(.+)/", "\\1", $chan->channel);
  85. echo "<a href=\"" . $_SERVER['PHP_SELF']. "?channel=$chanlink\">$chan->channel</a> :: ";
  86. }
  87. ?>
  88. <a href="<?php echo $SERVER['PHP_SELF']; ?>?channel=__all">(All channels)</a> ::
  89. </center>
  90. <br><br>
  91. Sorted with most recent first.
  92. <?php
  93. }
  94. $chan = mysql_real_escape_string($channel);
  95. $filter = mysql_real_escape_string($filter);
  96. $channel = "#" . $channel;
  97. $sql = "SELECT * FROM quotes ";
  98. $filters = array();
  99. if (isset($filter) && !empty($filter)) {
  100. $filters[] = "quote LIKE '%" . $filter . "%'";
  101. }
  102. if ($chan != "__all") {
  103. $filters[] = "channel = '#" . $chan . "'";
  104. }
  105. if (sizeof($filters) > 0) {
  106. $sql .= "WHERE " . implode(" AND ", $filters);
  107. }
  108. $sql .= " ORDER BY timestamp DESC";
  109. if ($remote) {
  110. $sql .= " LIMIT 20";
  111. }
  112. $results = mysql_query($sql);
  113. if ($results && mysql_num_rows($results)) {
  114. $count = mysql_num_rows($results);
  115. if (!$remote) {
  116. $quoted = array();
  117. $quoter = array();
  118. echo "<table>";
  119. echo "<tr><th>#</th><th>Added by</th><th>When</th><th align=\"left\">Quote</th></tr>";
  120. $class = 0;
  121. }
  122. if (!empty($page)) {
  123. mysql_data_seek($results, $page * 100);
  124. }
  125. else {
  126. $page = 0;
  127. }
  128. $counter = 0;
  129. while (($quote = mysql_fetch_object($results)) && ($counter < 100)) {
  130. if (!$remote) {
  131. $counter++;
  132. echo "<tr class=\"";
  133. echo ($class == 0) ? "odd" : "even";
  134. $class = !$class;
  135. echo "\"><td valign=\"top\"><a name=\"$quote->id\"><a href=\"" . $PHP_SELF . "?q=$quote->id\"><small>" . $quote->id . "</small></a></td><td class=\"nick\" valign=\"top\" nowrap>";
  136. echo "<span title=\"" . $quote->host . "\">";
  137. echo $quote->nick;
  138. echo "</span>";
  139. if ($chan == "__all") {
  140. echo "<br><small>in " . $quote->channel . "</small>";
  141. }
  142. echo "</td>";
  143. echo "<td class=\"time\" valign=\"top\" nowrap><small>";
  144. echo date("H:i j M y", $quote->timestamp);
  145. echo "</small></td>";
  146. if (empty($quoter[$quote->nick])) {
  147. $quoter[$quote->nick] = 1;
  148. }
  149. else {
  150. $quoter[$quote->nick]++;
  151. }
  152. $quote_text = htmlentities($quote->quote);
  153. $quotes = @preg_split("/ \| /", $quote_text);
  154. $newquote = "";
  155. foreach ($quotes as $q) {
  156. $q = trim($q);
  157. //no timestamps
  158. $q = preg_replace('/^\[?[0-9:.]+\]?/', '', $q);
  159. //$q = preg_replace('/^((&lt;|\\[|\\()*.*?)( )(.*?(&gt;|\\]|\\))+:?)/', "\\1&nbsp;\\4", $q);
  160. //hilight nicks
  161. if (!preg_match("/^\* /", $q)) {
  162. if (preg_match('/^((&lt;|\\[|\\()*[@%+]?([^\]>\\\)]+?)[@%+]?(&gt;|\\]|\\))+:?)/', $q, $matches)) {
  163. if (empty($quoted[$matches[3]])) {
  164. $quoted[$matches[3]] = 1;
  165. }
  166. else {
  167. $quoted[$matches[3]] = $quoted[$matches[3]] + 1;
  168. }
  169. }
  170. $q = preg_replace('/^((&lt;|\\[|\\()*[^\]>\\\)]+?(&gt;|\\]|\\))+:?)/', "<b>\\1</b>", $q);
  171. }
  172. else {
  173. if (preg_match('/^\* [@%+]?(\S+)[@%+]?/', $q, $matches)) {
  174. if (empty($quoted[$matches[1]])) {
  175. $quoted[$matches[1]] = 1;
  176. }
  177. else {
  178. $quoted[$matches[1]] = $quoted[$matches[1]] + 1;
  179. }
  180. }
  181. $q = preg_replace('/^\* (\S+)/', "* <b>\\1</b>", $q);
  182. }
  183. //$newquote .= preg_replace('/ /', "&nbsp;", $q);
  184. $newquote .= $q;
  185. $newquote .= "<br>";
  186. }
  187. $quote_text = preg_replace('/ \| /', "<br>", $quote_text);
  188. echo "<td class=\"quote\">" . $newquote . "</td>";
  189. echo "</tr>";
  190. }
  191. else {
  192. //remote
  193. echo $quote->quote . "\n";
  194. }
  195. }
  196. if (!$remote) {
  197. echo "</table>";
  198. echo "$count results<br>";
  199. if ($page > 0) {
  200. echo "<a href=\"" . $_SERVER['PHP_SELF'] . "?channel=$chan&filter=$filter&page=" . ($page - 1) . "\">&lt;&lt; Prev page</a>&nbsp;&nbsp";
  201. }
  202. if (($counter + ($page * 100)) < $count) {
  203. echo "<a href=\"" . $_SERVER['PHP_SELF'];
  204. echo "?channel=$chan";
  205. echo "&page=";
  206. echo ($page + 1);
  207. echo "&filter=$filter";
  208. echo "\">Next page &gt;&gt;</a>";
  209. }
  210. echo "<br><br>";
  211. echo "<table width=\"70%\" cellpadding=\"5\" align=\"center\">";
  212. echo "<tr><td valign=\"top\">";
  213. arsort($quoted);
  214. $i = 0;
  215. echo "<h3>Top 5 Quoted</h3>";
  216. echo "<small>on this page of results</small><br><br>";
  217. foreach($quoted as $q => $count) {
  218. echo "$q was quoted $count times<br>";
  219. if (++$i > 5) {
  220. break;
  221. }
  222. }
  223. echo "</td><td valign=\"top\">";
  224. echo "<h3>Top 5 Quoters</h3>";
  225. echo "<small>on this page of results</small><br><br>";
  226. arsort($quoter);
  227. $i = 0;
  228. foreach($quoter as $q => $count) {
  229. echo "$q added $count quotes<br>";
  230. if (++$i > 5) {
  231. break;
  232. }
  233. }
  234. echo "</td></tr></table>";
  235. }
  236. }
  237. else echo "oops: no results<br>" . mysql_error();
  238. if ($remote) {
  239. exit;
  240. }
  241. } //list (not quote)
  242. else {
  243. //display single quote
  244. $sql = "SELECT * FROM quotes WHERE id='$single_quote'";
  245. $result = mysql_query($sql);
  246. if ($result && mysql_num_rows($result)) {
  247. $quote = mysql_fetch_object($result);
  248. ?>
  249. <div class="singlequote">
  250. <h1>Quote #<?=$quote->id?></h1>
  251. <div class="quote">
  252. <?php
  253. $quote_text = htmlentities($quote->quote);
  254. $quotes = @preg_split("/ \| /", $quote_text);
  255. $newquote = "";
  256. foreach ($quotes as $q) {
  257. $q = trim($q);
  258. //no timestamps
  259. $q = preg_replace('/^\[?[0-9:.]+\]?/', '', $q);
  260. //$q = preg_replace('/^((&lt;|\\[|\\()*.*?)( )(.*?(&gt;|\\]|\\))+:?)/', "\\1&nbsp;\\4", $q);
  261. //hilight nicks
  262. if (!preg_match("/^\* /", $q)) {
  263. $q = preg_replace('/^((&lt;|\\[|\\()*[^\]>\\\)]+?(&gt;|\\]|\\))+:?)/', "<b>\\1</b>", $q);
  264. }
  265. else {
  266. $q = preg_replace('/^\* (\S+)/', "* <b>\\1</b>", $q);
  267. }
  268. $newquote .= $q;
  269. $newquote .= "<br>";
  270. }
  271. ?>
  272. <?=$newquote?><br><br>
  273. <div class="meta">
  274. Added <?=date("Y-m-d H:i:s", $quote->timestamp)?> by <?=$quote->nick?> on <?=$quote->channel?>
  275. </div>
  276. </div>
  277. </div>
  278. <?php
  279. }
  280. else {
  281. echo "Sorry, can't find that quote.";
  282. }
  283. }
  284. ?>
  285. <br><br><br><br><br><br>
  286. <center>
  287. <a href="http://jamesoff.net/site/code/eggdrop-scripts/quoteengine/">QuoteEngine</a> by <a href="//www.jamesoff.net/">JamesOff</a> <br>
  288. Quotes gatered by <?php echo QUOTES_HOST; ?>
  289. </center>
  290. </body>
  291. </html>