Advertisement
Guest User

Untitled

a guest
Jul 9th, 2017
494
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.50 KB | None | 0 0
  1. <?php
  2. /*
  3. * =============================================================================
  4. * SourceMod Extended ChatLog v1.3.5 WebUI Example
  5. * Reads a chatlog database for sourcemod and prints the sauce, in ajaxxx!
  6. *
  7. * (C)2009 Nephyrin@doublezen.net
  8. * =============================================================================
  9. *
  10. * This program is free software; you can redistribute it and/or modify it under
  11. * the terms of the GNU General Public License, version 3.0, as published by the
  12. * Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful, but WITHOUT
  15. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  16. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  17. * details.
  18. *
  19. * You should have received a copy of the GNU General Public License along with
  20. * this program. If not, see <http://www.gnu.org/licenses/>.
  21. *
  22. */
  23.  
  24. //
  25. // This is a SIMPLE example. Modify it as you wish. Keep in mind that it is GPL
  26. // Licensed.
  27. //
  28. $START_ROWS = 5000; // How many lines of chat we should display to start.
  29.  
  30. // $DB_HOST [$DB_PORT] $DB_USER $DB_PASS $DB_DATABASE
  31. $DB_HOST = "localhost";
  32. $DB_PORT = "3306";
  33. $DB_USER = "xxxxxxxxxxxxx";
  34. $DB_PASS = "xxxxxxxxxx";
  35. $DB_DATABASE = "xxxxxxxxxxx";
  36.  
  37. // Gives a nicer back-end ID for the javascript.
  38. function cleanId($in)
  39. {
  40. return preg_replace("/[^0-9a-zA-Z]/", "_", $in);
  41. }
  42. function formatRow($R)
  43. {
  44. $class;
  45. if ($R['team'] == 3)
  46. $class = "bluename";
  47. elseif ($R['team'] == 2)
  48. $class = "redname";
  49. elseif ($R['team'] == 10)
  50. $class = "violetname";
  51. else
  52. $class = "greyname";
  53.  
  54. $team = "";
  55. $dead = "";
  56. $name = htmlspecialchars($R['name'], ENT_QUOTES);
  57. $text = htmlspecialchars($R['text'], ENT_QUOTES);
  58.  
  59. if ($R['type'] >= 0)
  60. {
  61. if ($R['type'] & 2)
  62. $team = "[TEAM] ";
  63. if ($R['type'] & 1)
  64. $dead = "<span class=\"deadname\">*DEAD*</span> ";
  65.  
  66. $name = "$dead<span class=\"$class\">$team$name: </span>";
  67. }
  68. else
  69. {
  70. if($R['team'] == 10)
  71. {
  72. $team = "[ADMIN] ";
  73. $name = "<span class=\"$class\">$team$name: </span>";
  74. }
  75. else
  76. $text = "<span class=\"servermsg\">$text</span>";
  77. }
  78.  
  79. // Hours modifier
  80. $hoursmod = 0;
  81.  
  82. // http://fi2.php.net/manual/en/function.date.php
  83. // European timestamp
  84. //$date = date("j.m.y H:i:s", $R['date'] + ($hoursmod * 3600));
  85. $date = date("n/j g:i:sa", $R['date'] + ($hoursmod * 3600));
  86.  
  87. $id = cleanId($R['srvid']);
  88. return "$id\x01<span class=\"line\"><span class=\"timestamp\">$date </span>$name$text</span><br />";
  89. }
  90.  
  91. $SQL = @mysql_connect($DB_PORT ? "$DB_HOST:$DB_PORT" : $DB_HOST, $DB_USER, $DB_PASS);
  92. if (!$SQL) die("Failed to connect to MySQL Database");
  93. @mysql_select_db($DB_DATABASE) or die("MySQL Failure: " . mysql_error());
  94.  
  95. // Set output encoding to UTF-8
  96. mysql_query('SET NAMES utf8', $SQL) or die("MySQL Failure: " . mysql_error());
  97.  
  98. if (isset($_GET['mark']) && $mark = $_GET['mark'] + 0):
  99. if ($mark == -1)
  100. $Q = "SELECT name,seqid,type,srvid,team,text,UNIX_TIMESTAMP(`date`) AS `date` FROM `chatlogs` ORDER BY `seqid` DESC LIMIT $START_ROWS";
  101. else
  102. $Q = "SELECT name,seqid,type,srvid,team,text,UNIX_TIMESTAMP(`date`) AS `date` FROM `chatlogs` WHERE `seqid` > $mark ORDER BY `seqid` DESC";
  103.  
  104. $Q = @mysql_query($Q, $SQL) or die("MySQL Failure: " . mysql_error());
  105. $ar = array();
  106. $R = mysql_fetch_array($Q);
  107. if (!$R)
  108. {
  109. // No new data, echo same mark back
  110. echo($mark);
  111. exit();
  112. }
  113. $newmark = $R['seqid'];
  114. do
  115. {
  116. array_push($ar, formatRow($R));
  117. } while ($R = mysql_fetch_array($Q));
  118. array_push($ar, $newmark); // Add mark to bottom (top once reversed)
  119. $ar = array_reverse($ar);// Query selects rows in reverse order, and mark is on bottom
  120. echo(implode("\n", $ar));
  121. else:
  122. $Q = "SELECT DISTINCT `srvid` FROM `chatlogs`";
  123. $Q = @mysql_query($Q, $SQL) or die("MySQL Failure: " . mysql_error());
  124. $PB = "";
  125. $PS = "";
  126. while ($R = mysql_fetch_row($Q))
  127. {
  128. $id = cleanId($R[0]);
  129. $PB .= "<div class=\"dat\">
  130. <div class=\"dhead\">Server \"$R[0]\"</div>
  131. <div class=\"dbody\" id=\"dbody_$id\">
  132. <div class=\"dtext\" id=\"dat_$id\"></div>
  133. <div id=\"dscrollto_$id\"></div>
  134. </div>
  135. </div>\n";
  136. $PS .= "srvz.push(\"$id\");\n";
  137. }
  138. echo "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>";
  139. ?>
  140. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  141. <html xmlns="http://www.w3.org/1999/xhtml">
  142. <head>
  143. <title>ToXoR's Server - ChatLog WebUI</title>
  144. <script type="text/javascript" src="./jquery-1.3.min.js"></script>
  145. <script type="text/javascript">
  146. var srvz = new Array();
  147. var mark = -1;
  148. var loading = 1;
  149. <?php echo($PS); ?>
  150. function dead(wat)
  151. {
  152. alert("Server side error. Dying:" + wat);
  153. }
  154. function cback(data, textStatus)
  155. {
  156. if (textStatus == "success")
  157. {
  158. var lines = data.split("\n");
  159. mark = lines[0];
  160. if (mark + 0 == 0) die(3);
  161. var line;
  162. var scrollme = new Array();
  163. for(var i = 1; i < lines.length; i++)
  164. {
  165. line = lines[i].split("\x01");
  166. // 0 srvid
  167. // 1 string
  168. // Formatted serverside
  169. if ($("#dscrollto_" + line[0]).offset().top <= $("#dbody_" + line[0]).height() + $("#dbody_" + line[0]).offset().top)
  170. if (!scrollme[line[0]]) scrollme[line[0]] = true;
  171. if (line.length != 2) return dead("1");
  172. var box = $("#dat_" + line[0]);
  173. if (!box) return dead("2");
  174. for(var j = i + 1; j < lines.length; j++)
  175. {
  176. if(lines[j].split("\x01").length != 1) break;
  177. line[1] += "<br />" + lines[j];
  178. i = j;
  179. }
  180. if (loading)
  181. {
  182. box.html(line[1]);
  183. loading = 0;
  184. }
  185. else
  186. {
  187. box.append(line[1]);
  188. }
  189. box.children(".line:last").fadeIn(500);
  190. }
  191. for (var sid in scrollme)
  192. {
  193. // Scroll it, thanks to learningjquery.com!
  194. var divOffset = $("#dbody_" + sid).offset().top;
  195. var endOffset = $("#dscrollto_" + sid).offset().top;
  196. var Scroll = endOffset - divOffset;
  197. $("#dbody_" + sid).animate({scrollTop: '+=' + Scroll + 'px'}, 500);
  198. }
  199. }
  200. window.setTimeout("proc()", 2000);
  201. }
  202. function proc()
  203. {
  204. $.get("<?php echo($_SERVER["PHP_SELF"]); ?>?mark=" + mark, cback);
  205. }
  206. </script>
  207. <style>
  208. body
  209. {
  210. background-color: #333;
  211. font-family: verdana, arial;
  212. font-size: 12px;
  213. }
  214. .dat
  215. {
  216. border: 1px solid #000;
  217. background-color: #EEE;
  218. padding: 10px;
  219. margin: 10px;
  220. width: 700px;
  221. margin-left: auto;
  222. margin-right: auto;
  223. }
  224. .dbody
  225. {
  226. height: 250px;
  227. width: 700px;
  228. overflow: auto;
  229. }
  230. .dhead
  231. {
  232. font-weight: bold;
  233. font-size: 150%;
  234. }
  235. .dtext
  236. {
  237. padding-left: 7em;
  238. }
  239. .line
  240. {
  241. position: relative;
  242. margin-left: -7em;
  243. display: none;
  244. }
  245. .redname
  246. {
  247. color: red;
  248. font-weight: bold;
  249. }
  250. .bluename
  251. {
  252. color: blue;
  253. font-weight: bold;
  254. }
  255. .greyname
  256. {
  257. color: grey;
  258. font-weight: bold;
  259. }
  260. .violetname
  261. {
  262. color: #aa00b7;
  263. font-weight: bold;
  264. }
  265. .deadname
  266. {
  267. color: grey;
  268. font-weight: bold;
  269. font-style: italic;
  270. }
  271. .servermsg
  272. {
  273. color: grey;
  274. font-style: italic;
  275. }
  276. .timestamp
  277. {
  278. font-size: 80%;
  279. font-color: black;
  280. font-style: italic;
  281. }
  282. </style>
  283. </head>
  284. <body onload="javascript:proc()">
  285. <?php echo($PB); ?>
  286. </body>
  287. </html>
  288. <?php endif; ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement