Advertisement
Guest User

Untitled

a guest
Sep 4th, 2016
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.78 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>SplashMC.de ChatLog</title>
  5. <meta charset="utf-8"/>
  6. <meta name="language" content="de"/>
  7. <meta name="viewport" content="width=device-width, initial-scale=1"/>
  8. <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
  9.  
  10. <link rel="stylesheet" type="text/css" href="style.css"/>
  11. <link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:400,700,300"/>
  12. </head>
  13. <body>
  14. <?php
  15. include("script/Chatlog.php");
  16. if(@$_GET['ID'] != null) {
  17. showLog($_GET['ID']);
  18. }
  19. ?>
  20. <div class="wrapper">
  21. <center>
  22. <h1>SplashMC | ChatLog</h1>
  23. <div class="wrappercontent">
  24. <form action="index.php" method="get">
  25. <input class="form-input" type="text" placeholder="ChatLog-ID" name="ID">
  26. <br></br>
  27. <input class="form-button" type="submit" value="Go">
  28. </form>
  29. </div>
  30. </center>
  31. <br></br>
  32. <div id="content">
  33. </div>
  34. </div>
  35. <div class="footer">
  36. <center>
  37. <h5>Copyright © 2016 SplashMC.de</h5>
  38. <h5>Created by Vinka01</h5>
  39. <h5><a href="http://splashmc.de/imprint.html">Impressum</a></h5>
  40. </center>
  41. </div>
  42. </body>
  43. </html>
  44.  
  45.  
  46.  
  47.  
  48. <?php
  49. $con;
  50. $dom;
  51. $div;
  52. function showLog($logID) {
  53. if($logID != null) {
  54. libxml_use_internal_errors(true);
  55. error_reporting(0);
  56. $con = connectDB();
  57.  
  58. $html = file_get_contents('index.php');
  59. $dom = new DOMDocument();
  60. $dom->loadHTML($html);
  61. $finder = new DOMXPath($dom);
  62. $div = $dom->getElementById('content');
  63.  
  64. /*addMessage("Testuser1", "Testnachricht nr1","12:45",$dom,$div);
  65. addMessage("Testuser2", "Testnachricht nr2","12:45",$dom,$div);
  66. addMessage("Testuser1", "hallo","12:45",$dom,$div);
  67. addMessage("Testuser2", "jo was geht?","12:45",$dom,$div);
  68. addMessage("Testuser1", "alles gut bei dir?","12:45",$dom,$div);
  69. addMessage("Testuser2", "klar","12:45",$dom,$div); */
  70. setChatLog(getMessage(),$dom,$div);
  71. echo getMessage();
  72.  
  73. print $dom->saveHTML();
  74. }
  75. }
  76.  
  77. function connectDB() {
  78. $host = "localhost";
  79. $user = "root";
  80. $pass = "vkyd6600!!!";
  81. $database = "splashmc_chatlog";
  82.  
  83. $con = new mysqli($host, $user);
  84. mysqli_select_db($con, $database);
  85.  
  86. $createTable = "CREATE TABLE IF NOT EXISTS ChatLog(MESSAGEID INT AUTO_INCREMENT, AUTHOR LONGTEXT, MESSAGE LONGTEXT, DATE LONGTEXT, LOGID LONGTEXT, PRIMARY KEY(MESSAGEID))";
  87. mysqli_query($con, $createTable) or die("Fehler beim ausführen!" . mysqli_error($con));
  88. }
  89.  
  90. function getMessage() {
  91. for($i = 0; $i < 6; $i++) {
  92. if($i%2) {
  93. $json["Sender"] = "s1";
  94. } else {
  95. $json["Sender"] = "s2";
  96. }
  97. $json["Message"] = "Hallo";
  98. $json["Timestep"] = "123";
  99. $msg["Message"][] = $json;
  100. }
  101. return json_encode($msg);
  102. }
  103.  
  104. function setChatLog($message,$dom,$div) {
  105. $decode = json_decode($message);
  106. $msgarr = $decode->{'Message'};
  107. for($i = 0; $i < count($msgarr); $i++) {
  108. $rawmsg = $msgarr[$i];
  109. addMessage($rawmsg->{'Sender'},$rawmsg->{'Message'},$rawmsg->{'Timestep'},$dom,$div);
  110. }
  111. }
  112.  
  113. function addMessage($author,$message,$time,$dom,$parent) {
  114. $wrapper = $dom->createElement('div');
  115. $wrapper->setAttribute('class', 'msg');
  116. $parent->appendChild($wrapper);
  117.  
  118. $author = $dom->createElement('p', $author);
  119. $author->setAttribute('class', 'author');
  120. $wrapper->appendChild($author);
  121.  
  122. $text = $dom->createElement('p'," : " . $message);
  123. $author->appendChild($text);
  124.  
  125. $timestep = $dom->createElement('p', $time);
  126. $timestep->setAttribute('class', 'timestep');
  127. $wrapper->appendChild($timestep);
  128.  
  129. }
  130. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement