From fe36da64909a2ad8b7f48be5b4307ed6115ecc39 Mon Sep 17 00:00:00 2001 From: Patrick Davison Date: Thu, 28 Feb 2013 23:09:41 -0800 Subject: Chat /me and URL Linking --- ajax/chat.ajax.php | 7 ++++--- css/chat.css | 14 +++++++++++++- index.php | 5 +++++ pages/chat.php | 41 +++++++++++++++++++++++------------------ 4 files changed, 45 insertions(+), 22 deletions(-) diff --git a/ajax/chat.ajax.php b/ajax/chat.ajax.php index 5ac77e4..ac682a7 100644 --- a/ajax/chat.ajax.php +++ b/ajax/chat.ajax.php @@ -49,13 +49,14 @@ if ($_REQUEST['messages']) { $insertID = addchat(-1, substr($message, 5)); } } - //Anyone commands: - if ($command == 'spoiler') { + //javascript based commands: + if ($command == 'spoiler' OR $command == 'me') { $insertID = addchat($userID, $message); } + //For anyone if ($command == 'help') { $r[0]['serverMessage'] = 'true'; - $r[0]['message'] = "Commands: /help /time /spoiler . - Chat by Pathery.com"; + $r[0]['message'] = "Commands: /help /time /spoiler /me. - Chat by Pathery.com"; $r[0]['secondsSince'] = 0; $r[0]['userID'] = -1; echo json_encode($r); diff --git a/css/chat.css b/css/chat.css index c8f15b6..9608093 100644 --- a/css/chat.css +++ b/css/chat.css @@ -35,12 +35,24 @@ .chatUsername { font-family: 'Trebuchet MS1', 'Trebuchet MS', sans-serif; font-size: 17px; - text-overflow: ellipsis; + text-overflow: clip; overflow:hidden; float: left; padding-top: 5px; width: 115px; } +.chatUsername:after { + content:":"; +} +.chatUsername.me { + text-align:right; +} +.chatUsername.me:after { + content:""; +} +.chatUsername.me:before { + content:"*"; +} .chatText { font-family: 'Trebuchet MS1', 'Trebuchet MS', sans-serif; font-size: 16px; diff --git a/index.php b/index.php index f5f6037..9a5f7d7 100644 --- a/index.php +++ b/index.php @@ -98,6 +98,11 @@ switch ($request) { require("pages/tutorial.php"); break; + case "redirect": + $to = $_GET['to']; + DoRedirect("THIS URL COULD BE UNSAFE! Please confirm!
", $to, $duration = "8"); + break; + case "hometutorial": header("Location: $mydomain"."tutorial"); exit; diff --git a/pages/chat.php b/pages/chat.php index 67c6831..f68db7e 100644 --- a/pages/chat.php +++ b/pages/chat.php @@ -80,7 +80,14 @@ function getChatDone(data) { chat.message = chat.message.substring(9); isSpoiler = true; } - + + var usernameClass = ''; + if (chat.message.indexOf("/me ") == 0) { + chat.message = chat.message.substring(4); + usernameClass = ' me'; + } + + //console.log("INSIDE BUILD START"); p = ''; p = p+ "
"; @@ -93,15 +100,15 @@ function getChatDone(data) { p = p+ "
"; if (chat.userID == '-1') { - p = p+ ""; + p = p+ ""; } else { - p = p+ ""; + p = p+ ""; } - p = p+ chat.displayName+":"; + p = p+ chat.displayName+""; if (isSpoiler == true) p = p+ " "; else p = p+ " "; - p = p+ htmlEncode(chat.message); + p = p+ chatReplaceAndEncode(chat.message); p = p+ " "; p = p+ "
"; @@ -118,21 +125,9 @@ function getChatDone(data) { if (newChats) { if (chatTimerDelay > chatTimerDelayLower) chatTimerDelay -= 1000; - //var new_chatDiv = $('
', { - //'class': 'my-new-list', - //'style': 'display: none', - //html: items.join('') - //}); - var elem = $("#chatContainer"); - //var atBottom = (elem[0].scrollHeight - elem.scrollTop() == elem.outerHeight()); var atBottom = (elem.scrollTop() >= elem[0].scrollHeight - elem.outerHeight() - 1); - - - //var elem = $("#chatContainer"); console.log ("Ret", elem[0].scrollHeight, elem.scrollTop(), elem.outerHeight(), elem[0].scrollHeight - elem.scrollTop()); - - //new_chatDiv.appendTo('#chatContainer').slideDown('fast'); - //new_chatDiv.appendTo('#chatContainer'); + $("#chatContainer").append(items.join('')); if (atBottom || firstGetChat) { @@ -146,6 +141,16 @@ function getChatDone(data) { } } +function chatReplaceAndEncode(chat) { + chat = htmlEncode(chat); + chat = chat.replace(/\*(\S(.*?\S)?)\*/gm, "$1"); + + var URLexp = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig; + chat = chat.replace(URLexp, "$1"); + + return chat; +} + function prepChat(chat) { chat = chat.join('|:|'); chat = chat.replace(/\&/g,'%26') -- cgit v1.2.3