mirror of
https://github.com/wbbaddons/Tims-Chat.git
synced 2024-10-31 14:10:08 +00:00
Moved readUserData to chatUtil
closes 2
This commit is contained in:
parent
cf72777f13
commit
0f411e8015
@ -3,8 +3,6 @@
|
||||
use \wcf\data\chat;
|
||||
use \wcf\system\exception\PermissionDeniedException;
|
||||
use \wcf\system\exception\UserInputException;
|
||||
use \wcf\system\package\PackageDependencyHandler;
|
||||
use \wcf\system\user\storage\UserStorageHandler;
|
||||
use \wcf\system\WCF;
|
||||
use \wcf\util\StringUtil;
|
||||
|
||||
@ -27,7 +25,9 @@ class ChatForm extends AbstractForm {
|
||||
* @see \wcf\page\AbstractPage::readData()
|
||||
*/
|
||||
public function readData() {
|
||||
$this->readUserData();
|
||||
$this->userData['color'] = \wcf\util\ChatUtil::readUserData('color');
|
||||
$this->userData['roomID'] = \wcf\util\ChatUtil::readUserData('roomID');
|
||||
|
||||
parent::readData();
|
||||
}
|
||||
|
||||
@ -41,34 +41,6 @@ public function readFormParameters() {
|
||||
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];
|
||||
}
|
||||
|
||||
/**
|
||||
* @see \wcf\form\AbstractForm::validate()
|
||||
*/
|
||||
|
@ -2,8 +2,6 @@
|
||||
namespace wcf\page;
|
||||
use \wcf\data\chat;
|
||||
use \wcf\system\cache\CacheHandler;
|
||||
use \wcf\system\package\PackageDependencyHandler;
|
||||
use \wcf\system\user\storage\UserStorageHandler;
|
||||
use \wcf\system\WCF;
|
||||
|
||||
/**
|
||||
@ -65,8 +63,10 @@ public function readChatVersion() {
|
||||
public function readData() {
|
||||
parent::readData();
|
||||
|
||||
$this->readRoom();
|
||||
$this->readUserData();
|
||||
$this->readRoom();
|
||||
$this->userData['color'] = \wcf\util\ChatUtil::readUserData('color');
|
||||
\wcf\util\ChatUtil::writeUserData(array('roomID' => $this->room->roomID));
|
||||
|
||||
if (CHAT_DISPLAY_JOIN_LEAVE) {
|
||||
$messageAction = new chat\message\ChatMessageAction(array(), 'create', array(
|
||||
'data' => array(
|
||||
@ -146,33 +146,6 @@ public function readRoom() {
|
||||
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()
|
||||
*/
|
||||
|
@ -2,8 +2,6 @@
|
||||
namespace wcf\page;
|
||||
use \wcf\data\chat;
|
||||
use \wcf\system\cache\CacheHandler;
|
||||
use \wcf\system\package\PackageDependencyHandler;
|
||||
use \wcf\system\user\storage\UserStorageHandler;
|
||||
use \wcf\system\WCF;
|
||||
|
||||
/**
|
||||
@ -28,32 +26,13 @@ class ChatRefreshRoomListPage extends AbstractPage {
|
||||
*/
|
||||
public function readData() {
|
||||
parent::readData();
|
||||
$this->readUserData();
|
||||
$this->roomID = \wcf\util\ChatUtil::readUserData('roomID');
|
||||
$this->rooms = chat\room\ChatRoom::getCache();
|
||||
|
||||
$this->room = $this->rooms->search($this->roomID);
|
||||
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()
|
||||
*/
|
||||
|
@ -1,5 +1,8 @@
|
||||
<?php
|
||||
namespace wcf\util;
|
||||
use \wcf\system\user\storage\UserStorageHandler;
|
||||
use \wcf\system\package\PackageDependencyHandler;
|
||||
use \wcf\system\WCF;
|
||||
|
||||
/**
|
||||
* 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]?,?)+)';
|
||||
|
||||
public static $serialize = array('color' => true);
|
||||
|
||||
/**
|
||||
* 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.
|
||||
@ -27,7 +32,7 @@ class ChatUtil {
|
||||
* @param string $string
|
||||
* @param integer $start
|
||||
* @param integer $end
|
||||
* @returen string
|
||||
* @return string
|
||||
*/
|
||||
public static function gradient($string, $start, $end) {
|
||||
$string = self::str_split($string);
|
||||
@ -45,6 +50,47 @@ public static function gradient($string, $start, $end) {
|
||||
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.
|
||||
* UTF-8 safe version of str_split().
|
||||
|
Loading…
Reference in New Issue
Block a user