index.php 8.8 KB

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