1
0
mirror of https://github.com/wbbaddons/Tims-Chat.git synced 2024-10-31 14:10:08 +00:00

Merge branch 'chatTplRedesign' of github.com:wbbaddons/Tims-Chat into chatTplRedesign

Conflicts:
	file/js/jCounter.jQuery.coffee
This commit is contained in:
Tim Düsterhus 2011-12-23 15:31:32 +01:00
commit a8af8023a9
11 changed files with 173 additions and 121 deletions

3
.gitignore vendored
View File

@ -48,3 +48,6 @@ nbactions.xml
# Ignore packages build directly in the workspace. They can however be added manually via git add, if wanted. # Ignore packages build directly in the workspace. They can however be added manually via git add, if wanted.
*.tar *.tar
*.tar.gz *.tar.gz
# Javascript - CoffeeScript is used instead ;)
*.js

View File

@ -178,7 +178,8 @@ TimWolla.WCF ?= {}
$.ajax $('#chatForm').attr('action'), $.ajax $('#chatForm').attr('action'),
data: data:
text: $('#chatInput').val() text: $('#chatInput').val(),
smilies: $('#chatSmilies').data('status')
type: 'POST', type: 'POST',
beforeSend: (jqXHR) -> beforeSend: (jqXHR) ->
$('#chatInput').addClass 'ajaxLoad' $('#chatInput').addClass 'ajaxLoad'

View File

@ -7,27 +7,38 @@
# @package jQuery.jCounter # @package jQuery.jCounter
### ###
(($) -> (($) ->
$.fn.jCounter = (max = 140, options) -> $.fn.jCounter = (container, options) ->
options = $.extend options = $.extend
container: '<span></span>' max: 0
counterClass: 'counter' counterClass: 'counter'
countUp: false countUp: false
, options , options
jCounterContainer = $ options.container if this.attr('maxlength')
max = this.attr('maxlength')
else max = options.max
this.on 'keypress keydown keyup', $.proxy () -> if !container
this.wrap('<div class="counterContainer"><div></div></div>').parent().append('<div class="' + options.counterClass + ' color-1">' + max + '</div>');
jCounterContainer = $(this).parent().children('.' + options.counterClass)
else
if `typeof container == "object"`
jCounterContainer = container
else
jCounterContainer = $ container
this.on 'keypress keyup', $.proxy () ->
if options.countUp if options.countUp
length = this.val().length length = this.val().length
else else
length = maxChars - this.val().length length = max - this.val().length
if options.countUp if options.countUp
color = 1 color = 1
else else
if length > maxChars / 2 if length > max / 2
color = 1 color = 1
else if length <= maxChars / 2 and length >= maxChars / 6 else if length <= max / 2 and length >= max / 6
color = 2 color = 2
else else
color = 3 color = 3

View File

@ -59,7 +59,7 @@ public function getFormattedMessage() {
break; break;
case self::TYPE_NORMAL: case self::TYPE_NORMAL:
if (!$this->enableHTML) { if (!$this->enableHTML) {
$message = \wcf\system\bbcode\SimpleMessageParser::getInstance()->parse($message, $this->enableSmilies); $message = \wcf\system\bbcode\SimpleMessageParser::getInstance()->parse($message, true, $this->enableSmilies);
} }
} }
return $message; return $message;

View File

@ -3,8 +3,6 @@
use \wcf\data\chat; use \wcf\data\chat;
use \wcf\system\exception\PermissionDeniedException; use \wcf\system\exception\PermissionDeniedException;
use \wcf\system\exception\UserInputException; use \wcf\system\exception\UserInputException;
use \wcf\system\package\PackageDependencyHandler;
use \wcf\system\user\storage\UserStorageHandler;
use \wcf\system\WCF; use \wcf\system\WCF;
use \wcf\util\StringUtil; use \wcf\util\StringUtil;
@ -19,6 +17,7 @@
*/ */
class ChatForm extends AbstractForm { class ChatForm extends AbstractForm {
public $message = ''; public $message = '';
public $enableSmilies = 1;
public $userData = array(); public $userData = array();
public $useTemplate = false; public $useTemplate = false;
@ -26,7 +25,9 @@ class ChatForm extends AbstractForm {
* @see \wcf\page\AbstractPage::readData() * @see \wcf\page\AbstractPage::readData()
*/ */
public function readData() { public function readData() {
$this->readUserData(); $this->userData['color'] = \wcf\util\ChatUtil::readUserData('color');
$this->userData['roomID'] = \wcf\util\ChatUtil::readUserData('roomID');
parent::readData(); parent::readData();
} }
@ -37,34 +38,7 @@ public function readFormParameters() {
parent::readFormParameters(); parent::readFormParameters();
if (isset($_REQUEST['text'])) $this->message = StringUtil::trim($_REQUEST['text']); if (isset($_REQUEST['text'])) $this->message = StringUtil::trim($_REQUEST['text']);
} if (isset($_REQUEST['smilies'])) $this->enableSmilies = intval($_REQUEST['smilies']);
/**
* Reads user data.
*/
public function readUserData() {
// TODO: Move this into ChatUtil
$ush = UserStorageHandler::getInstance();
$packageID = PackageDependencyHandler::getPackageID('timwolla.wcf.chat');
// load storage
$ush->loadStorage(array(WCF::getUser()->userID), $packageID);
$data = $ush->getStorage(array(WCF::getUser()->userID), 'color', $packageID);
if ($data[WCF::getUser()->userID] === null) {
// set defaults
$data[WCF::getUser()->userID] = array(1 => 0xFF0000, 2 => 0x00FF00); // TODO: Change default values
$ush->update(WCF::getUser()->userID, 'color', serialize($data[WCF::getUser()->userID]), $packageID);
}
else {
// load existing data
$data[WCF::getUser()->userID] = unserialize($data[WCF::getUser()->userID]);
}
$this->userData['color'] = $data[WCF::getUser()->userID];
$data = $ush->getStorage(array(WCF::getUser()->userID), 'roomID', $packageID);
$this->userData['roomID'] = $data[WCF::getUser()->userID];
} }
/** /**
@ -96,6 +70,7 @@ public function save() {
'time' => TIME_NOW, 'time' => TIME_NOW,
'type' => chat\message\ChatMessage::TYPE_NORMAL, 'type' => chat\message\ChatMessage::TYPE_NORMAL,
'message' => $this->message, 'message' => $this->message,
'enableSmilies' => $this->enableSmilies,
'color1' => $this->userData['color'][1], 'color1' => $this->userData['color'][1],
'color2' => $this->userData['color'][2] 'color2' => $this->userData['color'][2]
) )

View File

@ -2,8 +2,6 @@
namespace wcf\page; namespace wcf\page;
use \wcf\data\chat; use \wcf\data\chat;
use \wcf\system\cache\CacheHandler; use \wcf\system\cache\CacheHandler;
use \wcf\system\package\PackageDependencyHandler;
use \wcf\system\user\storage\UserStorageHandler;
use \wcf\system\WCF; use \wcf\system\WCF;
/** /**
@ -66,7 +64,9 @@ public function readData() {
parent::readData(); parent::readData();
$this->readRoom(); $this->readRoom();
$this->readUserData(); $this->userData['color'] = \wcf\util\ChatUtil::readUserData('color');
\wcf\util\ChatUtil::writeUserData(array('roomID' => $this->room->roomID));
if (CHAT_DISPLAY_JOIN_LEAVE) { if (CHAT_DISPLAY_JOIN_LEAVE) {
$messageAction = new chat\message\ChatMessageAction(array(), 'create', array( $messageAction = new chat\message\ChatMessageAction(array(), 'create', array(
'data' => array( 'data' => array(
@ -146,33 +146,6 @@ public function readRoom() {
if (!$this->room) throw new \wcf\system\exception\IllegalLinkException(); if (!$this->room) throw new \wcf\system\exception\IllegalLinkException();
} }
/**
* Reads user data.
*/
public function readUserData() {
// TODO: Move this into ChatUtil
$ush = UserStorageHandler::getInstance();
$packageID = PackageDependencyHandler::getPackageID('timwolla.wcf.chat');
// load storage
$ush->loadStorage(array(WCF::getUser()->userID), $packageID);
$data = $ush->getStorage(array(WCF::getUser()->userID), 'color', $packageID);
if ($data[WCF::getUser()->userID] === null) {
// set defaults
$data[WCF::getUser()->userID] = array(1 => 0xFF0000, 2 => 0x00FF00); // TODO: Change default values
$ush->update(WCF::getUser()->userID, 'color', serialize($data[WCF::getUser()->userID]), $packageID);
}
else {
// load existing data
$data[WCF::getUser()->userID] = unserialize($data[WCF::getUser()->userID]);
}
$this->userData['color'] = $data[WCF::getUser()->userID];
$ush->update(WCF::getUser()->userID, 'roomID', $this->room->roomID, $packageID);
}
/** /**
* @see \wcf\page\IPage::show() * @see \wcf\page\IPage::show()
*/ */

View File

@ -2,8 +2,6 @@
namespace wcf\page; namespace wcf\page;
use \wcf\data\chat; use \wcf\data\chat;
use \wcf\system\cache\CacheHandler; use \wcf\system\cache\CacheHandler;
use \wcf\system\package\PackageDependencyHandler;
use \wcf\system\user\storage\UserStorageHandler;
use \wcf\system\WCF; use \wcf\system\WCF;
/** /**
@ -28,32 +26,13 @@ class ChatRefreshRoomListPage extends AbstractPage {
*/ */
public function readData() { public function readData() {
parent::readData(); parent::readData();
$this->readUserData(); $this->roomID = \wcf\util\ChatUtil::readUserData('roomID');
$this->rooms = chat\room\ChatRoom::getCache(); $this->rooms = chat\room\ChatRoom::getCache();
$this->room = $this->rooms->search($this->roomID); $this->room = $this->rooms->search($this->roomID);
if (!$this->room) throw new \wcf\system\exception\IllegalLinkException(); if (!$this->room) throw new \wcf\system\exception\IllegalLinkException();
} }
/**
* Reads user data.
*/
public function readUserData() {
// TODO: Move this into ChatUtil
$ush = UserStorageHandler::getInstance();
$packageID = PackageDependencyHandler::getPackageID('timwolla.wcf.chat');
// load storage
$ush->loadStorage(array(WCF::getUser()->userID), $packageID);
$data = $ush->getStorage(array(WCF::getUser()->userID), 'roomID', $packageID);
if ($data[WCF::getUser()->userID] === null) {
throw new \wcf\system\exception\IllegalLinkException();
}
$this->roomID = $data[WCF::getUser()->userID];
}
/** /**
* @see \wcf\page\IPage::show() * @see \wcf\page\IPage::show()
*/ */

View File

@ -1,5 +1,8 @@
<?php <?php
namespace wcf\util; namespace wcf\util;
use \wcf\system\user\storage\UserStorageHandler;
use \wcf\system\package\PackageDependencyHandler;
use \wcf\system\WCF;
/** /**
* Chat utilities * Chat utilities
@ -19,6 +22,8 @@ class ChatUtil {
*/ */
const TIME_MODIFIER_REGEX = '((?:[0-9]+[s|h|d|w|m|y|S|H|D|W|M|Y]?,?)+)'; const TIME_MODIFIER_REGEX = '((?:[0-9]+[s|h|d|w|m|y|S|H|D|W|M|Y]?,?)+)';
public static $serialize = array('color' => true);
/** /**
* Creates a gradient out of two colors represented by an integer. * Creates a gradient out of two colors represented by an integer.
* The first byte is red, the second byte is green, the third one is blue. * The first byte is red, the second byte is green, the third one is blue.
@ -27,7 +32,7 @@ class ChatUtil {
* @param string $string * @param string $string
* @param integer $start * @param integer $start
* @param integer $end * @param integer $end
* @returen string * @return string
*/ */
public static function gradient($string, $start, $end) { public static function gradient($string, $start, $end) {
$string = self::str_split($string); $string = self::str_split($string);
@ -45,6 +50,47 @@ public static function gradient($string, $start, $end) {
return $result; return $result;
} }
/**
* Reads user data.
*
* @param string $field
* @return mixed
*/
public static function readUserData($field) {
$ush = UserStorageHandler::getInstance();
$packageID = PackageDependencyHandler::getPackageID('timwolla.wcf.chat');
// load storage
$ush->loadStorage(array(WCF::getUser()->userID), $packageID);
$data = $ush->getStorage(array(WCF::getUser()->userID), $field, $packageID);
if ($data[WCF::getUser()->userID] === null) {
switch ($field) {
case 'color':
$data[WCF::getUser()->userID] = array(1 => 0xFF0000, 2 => 0x00FF00);
break;
}
static::writeUserData(array($field => $data[WCF::getUser()->userID]));
}
if (isset(static::$serialize[$field])) return unserialize($data[WCF::getUser()->userID]);
else return $data[WCF::getUser()->userID];
}
/**
* Writes user data
*
* @param array $data
*/
public static function writeUserData(array $data) {
$ush = UserStorageHandler::getInstance();
$packageID = PackageDependencyHandler::getPackageID('timwolla.wcf.chat');
foreach($data as $key => $value) {
$ush->update(WCF::getUser()->userID, $key, (isset(static::$serialize[$key])) ? serialize($value) : $value, $packageID);
}
}
/** /**
* Splits a string into smaller chunks. * Splits a string into smaller chunks.
* UTF-8 safe version of str_split(). * UTF-8 safe version of str_split().

View File

@ -21,7 +21,7 @@ CREATE TABLE wcf1_chat_message (
DROP TABLE IF EXISTS wcf1_chat_room; DROP TABLE IF EXISTS wcf1_chat_room;
CREATE TABLE wcf1_chat_room ( CREATE TABLE wcf1_chat_room (
roomID int(10) NOT NULL AUTO_INCREMENT, roomID int(10) NOT NULL AUTO_INCREMENT,
title varchar(255) NOT NULL, title varchar(25) NOT NULL,
topic varchar(255) NOT NULL, topic varchar(255) NOT NULL,
position int(10) NOT NULL DEFAULT 0, position int(10) NOT NULL DEFAULT 0,
permanent tinyint(1) NOT NULL DEFAULT 1, permanent tinyint(1) NOT NULL DEFAULT 1,

View File

@ -31,7 +31,20 @@
<item name="wcf.chat.title"><![CDATA[Chat]]></item> <item name="wcf.chat.title"><![CDATA[Chat]]></item>
<item name="wcf.chat.protocol"><![CDATA[Protokoll]]></item> <item name="wcf.chat.protocol"><![CDATA[Protokoll]]></item>
<item name="wcf.chat.rooms"><![CDATA[Räume]]></item> <item name="wcf.chat.rooms"><![CDATA[Räume]]></item>
<item name="wcf.chat.users"><![CDATA[Nutzer]]></item>
<item name="wcf.chat.copyright"><![CDATA[<a href="http://timwolla.wbbaddons.de">Chat{if CHAT_SHOW_VERSION == 1} Version {$chatVersion}{/if} entwickelt von TimWolla</a>]]></item> <item name="wcf.chat.copyright"><![CDATA[<a href="http://timwolla.wbbaddons.de">Chat{if CHAT_SHOW_VERSION == 1} Version {$chatVersion}{/if} entwickelt von TimWolla</a>]]></item>
<item name="wcf.chat.submit.default"><![CDATA[Zum Senden Enter drücker]]></item>
<item name="wcf.chat.scroll"><![CDATA[Scrollen]]></item>
<item name="wcf.chat.notify"><![CDATA[Benachrichtigen]]></item>
<item name="wcf.chat.smilies"><![CDATA[Smilies]]></item>
<item name="wcf.chat.clear"><![CDATA[Chat leeren]]></item>
<item name="wcf.chat.mark"><![CDATA[Markieren]]></item>
<item name="wcf.chat.query"><![CDATA[Privates Gespräch]]></item>
<item name="wcf.chat.kick"><![CDATA[Kicken]]></item>
<item name="wcf.chat.ban"><![CDATA[Bannen]]></item>
<item name="wcf.chat.profile"><![CDATA[Profil]]></item>
</category> </category>
<category name="wcf.chat.message"> <category name="wcf.chat.message">
<!-- 1 = TYPE_JOIN --> <!-- 1 = TYPE_JOIN -->

View File

@ -22,10 +22,14 @@
margin-bottom: -20px !important; margin-bottom: -20px !important;
} }
aside { .left aside {
overflow: auto; overflow: auto;
padding: 0 1px 0 0; padding: 0 1px 0 0;
width: 190px; }
.right aside {
overflow: auto;
padding: 0 0 1px 0;
} }
aside h2 { aside h2 {
@ -130,6 +134,10 @@
background-image: url({icon size='S'}toLeft1{/icon}); background-image: url({icon size='S'}toLeft1{/icon});
} }
.chatMessageContainer {
padding-left: 7px !important;
}
.ajaxLoad { .ajaxLoad {
background-position: right center; background-position: right center;
background-repeat: no-repeat; background-repeat: no-repeat;
@ -141,33 +149,74 @@
} }
.chatSidebarTabs { .chatSidebarTabs {
height: 30px; height: 32px;
background-color: #FFFFFF; z-index: 101;
position: relative;
}
.left .chatSidebarTabs {
margin-right: 1px;
}
.right .chatSidebarTabs {
margin-left: 1px;
}
.chatSidebarTabs ul {
background-color: rgba(0, 0, 0, 0.2);
border-bottom: 1px solid #FFFFFF;
height: 31px;
} }
.chatSidebarTabs ul li { .chatSidebarTabs ul li {
width: 50%; width: 50%;
float: left; float: left;
text-align: center; text-align: center;
border-bottom: 1px solid #BBCCDD;
} }
.chatSidebarTabs ul li a { .chatSidebarTabs ul li a {
padding: 7px 0px 0px 0px; color: rgba(0, 0, 0, 0.4);
color: #666666; text-shadow: none;
height: 23px; height: 22px;
background-color: rgba(0, 0, 0, 0.05); padding: 9px 0 0;
}
.chatSidebarTabs ul li:first-child a { -moz-transition-property: border-radius, background-color, font-size; -moz-transition-duration: .2s;
border-right: 1px solid #BBCCDD; -webkit-transition-property: border-radius, background-color, font-size; -webkit-transition-duration: .2s;
transition-property: border-radius, background-color, font-size; transition-duration: .2s;
} }
.chatSidebarTabs ul li.active a { .chatSidebarTabs ul li.active a {
background-color: #FFFFFF;
border-bottom: 1px solid #BBCCDD;
border-radius: 0 0 7px 7px;
color: #000000;
font-size: 130%; font-size: 130%;
font-weight: bold; font-weight: bold;
color: #000000;
background-color: #FFFFFF; height: 23px;
padding: 7px 0 0;
}
.collapsed .chatSidebarTabs ul li a {
border: none !important;
}
.chatSidebarTabs ul li:first-child.active a {
border-radius: 0 0 7px 0;
border-right: 1px solid #BBCCDD;
}
.chatSidebarTabs ul li:last-child.active a {
border-radius: 0 0 0 7px;
border-left: 1px solid #BBCCDD;
}
.left .chatSidebarTabs ul li:last-child.active a {
margin-right: -1px;
}
.right .chatSidebarTabs ul li:first-child.active a {
margin-left: -1px;
} }
#chatRoomList { #chatRoomList {
@ -231,8 +280,8 @@
<div id="sidebar"> <div id="sidebar">
<nav class="chatSidebarTabs"> <nav class="chatSidebarTabs">
<ul> <ul>
<li id="toggleUsers" class="active"><a href="javascript:;" title="{lang}wcf.chat.users{/lang}">{lang}wcf.chat.users{/lang}</a></li>
<li id="toggleRooms"><a href="javascript:;" title="{lang}wcf.chat.rooms{/lang}" data-refresh-url="{link controller="Chat" action="RefreshRoomList"}{/link}">{lang}wcf.chat.rooms{/lang}</a></li> <li id="toggleRooms"><a href="javascript:;" title="{lang}wcf.chat.rooms{/lang}" data-refresh-url="{link controller="Chat" action="RefreshRoomList"}{/link}">{lang}wcf.chat.rooms{/lang}</a></li>
<li id="toggleUsers" class="active"><a href="javascript:;" title="{lang}wcf.chat.users{/lang}">{lang}wcf.chat.users{/lang}</a></li>
</ul> </ul>
</nav> </nav>
@ -243,10 +292,10 @@
<span class="bgFix"><a class="chatUserLink" href="javascript:;">User {$user}</a></span> <span class="bgFix"><a class="chatUserLink" href="javascript:;">User {$user}</a></span>
<ul class="chatUserMenu"> <ul class="chatUserMenu">
<li> <li>
<a href="javascript:;">Query</a> <a href="javascript:;">{lang}wcf.chat.query{/lang}</a>
<a href="javascript:;">Kick</a> <a href="javascript:;">{lang}wcf.chat.kick{/lang}</a>
<a href="javascript:;">Ban</a> <a href="javascript:;">{lang}wcf.chat.ban{/lang}</a>
<a href="{link controller="User" id=$user}{/link}">Profile</a> <a href="{link controller="User" id=$user}{/link}">{lang}wcf.chat.profile{/lang}</a>
</li> </li>
</ul> </ul>
</li> </li>
@ -275,10 +324,7 @@
</div> </div>
<form id="chatForm" action="{link controller="Chat" action="Send"}{/link}" method="post"> <form id="chatForm" action="{link controller="Chat" action="Send"}{/link}" method="post">
<div class="counterContainer"><div> <input type="text" id="chatInput" class="inputText long counterInput" name="text" autocomplete="off" maxlength="{CHAT_LENGTH}" required="required" placeholder="{lang}wcf.chat.submit.default{/lang}" />
<input type="text" id="chatInput" class="inputText long counterInput" name="text" autocomplete="off" maxlength="{CHAT_LENGTH}" required="required" placeholder="{lang}wcf.chat.submit.default{/lang}" />
<div class="counter color-1">{CHAT_LENGTH}</div>
</div></div>
</form> </form>
<div id="chatControls"> <div id="chatControls">
@ -304,6 +350,11 @@
<img alt="" src="{icon}disabled1{/icon}" /> <span>{lang}wcf.chat.notify{/lang}</span> <img alt="" src="{icon}disabled1{/icon}" /> <span>{lang}wcf.chat.notify{/lang}</span>
</a> </a>
</li> </li>
<li>
<a id="chatSmilies" href="javascript:;" class="chatToggle balloonTooltip" title="{lang}wcf.global.button.disable{/lang}" data-disable-message="{lang}wcf.global.button.disable{/lang}" data-enable-message="{lang}wcf.global.button.enable{/lang}" data-status="1">
<img alt="" src="{icon}enabled1{/icon}" /> <span>{lang}wcf.chat.smilies{/lang}</span>
</a>
</li>
<li> <li>
<a id="chatClear" href="javascript:;" class="balloonTooltip" title="Clear the chat"> <a id="chatClear" href="javascript:;" class="balloonTooltip" title="Clear the chat">
<img alt="" src="{icon}delete1{/icon}" /> <span>{lang}wcf.chat.clear{/lang}</span> <img alt="" src="{icon}delete1{/icon}" /> <span>{lang}wcf.chat.clear{/lang}</span>
@ -338,7 +389,7 @@
maxTextLength: {CHAT_LENGTH} maxTextLength: {CHAT_LENGTH}
} }
$('#chatInput').jCounter($('#chatInput').attr('maxlength'), { container: '.counter' }); $('#chatInput').jCounter();
$('#sidebar').wcfSidebar(); $('#sidebar').wcfSidebar();
//]]> //]]>
</script> </script>