diff --git a/api.php b/api.php index dd9207f..c6990b3 100644 --- a/api.php +++ b/api.php @@ -4,20 +4,20 @@ $database = new SQLite3('outchat.db'); $action = $_GET['action']; -if($action === 'getMessages'){ +if ($action === 'getMessages') { $timestamp = $database->escapeString(htmlspecialchars($_GET['timestamp'])); $timestamp = ($timestamp == 0) ? strtotime('-6 hours') : $timestamp; - $results = $database->query('SELECT * FROM messages WHERE timestamp > '.$timestamp); + $results = $database->query('SELECT * FROM messages WHERE timestamp > ' . $timestamp); $messageArray = []; - while($row = $results->fetchArray(SQLITE3_ASSOC)) { + while ($row = $results->fetchArray(SQLITE3_ASSOC)) { $row['datetime'] = date('d/m H:i', $row['timestamp']); $image_search = preg_match('/(http|https):\/\/[^ ]+(\.gif|\.jpg|\.jpeg|\.png)/', $row['text'], $out); - if($image_search > 0){ - $row['text_processed'] = str_replace($out[0], '
', $row['text']); + if ($image_search > 0) { + $row['text_processed'] = str_replace($out[0], '', $row['text']); } else { $row['text_processed'] = $row['text']; } @@ -27,17 +27,17 @@ if($action === 'getMessages'){ echo json_encode($messageArray); } -if($action === 'createMessage'){ +if ($action === 'createMessage') { $timestamp = time(); $name = $database->escapeString(htmlspecialchars($_POST['name'])); $text = $database->escapeString(htmlspecialchars($_POST['text'])); -/* - $payload = file_get_contents('php://input'); - $data = json_decode($payload); - var_dump($data); - */ + /* + $payload = file_get_contents('php://input'); + $data = json_decode($payload); + var_dump($data); + */ - $database->query('INSERT INTO messages (name, text, timestamp) VALUES ("'.$name.'", "'.$text.'", "'.$timestamp.'")'); + $database->query('INSERT INTO messages (name, text, timestamp) VALUES ("' . $name . '", "' . $text . '", "' . $timestamp . '")'); } ?> \ No newline at end of file diff --git a/helpers.js b/helpers.js index 1252691..9e7faee 100644 --- a/helpers.js +++ b/helpers.js @@ -7,12 +7,12 @@ function htmlToElements(html) { function hashCode(str) { // java String#hashCode var hash = 0; for (var i = 0; i < str.length; i++) { - hash = str.charCodeAt(i) + ((hash << 5) - hash); + hash = str.charCodeAt(i) + ((hash << 5) - hash); } return hash; -} +} -function intToRGB(i){ +function intToRGB(i) { const c = (i & 0x00FFFFFF) .toString(16) .toUpperCase(); @@ -26,7 +26,7 @@ function getCookie(name) { if (parts.length == 2) return parts.pop().split(";").shift(); } -function nl2br(str, is_xhtml){ +function nl2br(str, is_xhtml) { if (typeof str === 'undefined' || str === null) { return ''; } @@ -34,6 +34,6 @@ function nl2br(str, is_xhtml){ return (str + '').replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '$1' + breakTag + '$2'); } -function scrollWindowDown(){ +function scrollWindowDown() { window.scrollTo(0, document.body.scrollHeight) } \ No newline at end of file diff --git a/index.php b/index.php index e95ed26..0f5776a 100644 --- a/index.php +++ b/index.php @@ -4,15 +4,15 @@