mirror of
https://github.com/wbbaddons/Tims-Chat.git
synced 2024-12-22 21:40:08 +00:00
Adding Suspension-Handling
This commit is contained in:
parent
f91a03aa32
commit
e8607eaf56
@ -1,5 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace wcf\data\chat\room;
|
namespace wcf\data\chat\room;
|
||||||
|
use \wcf\data\chat\suspension\ChatSuspension;
|
||||||
use \wcf\system\cache\CacheHandler;
|
use \wcf\system\cache\CacheHandler;
|
||||||
use \wcf\system\WCF;
|
use \wcf\system\WCF;
|
||||||
|
|
||||||
@ -45,8 +46,15 @@ public function __toString() {
|
|||||||
*/
|
*/
|
||||||
public function canEnter() {
|
public function canEnter() {
|
||||||
$ph = \wcf\system\chat\permission\ChatPermissionHandler::getInstance();
|
$ph = \wcf\system\chat\permission\ChatPermissionHandler::getInstance();
|
||||||
|
$suspensions = ChatSuspension::getSuspensionsForUser();
|
||||||
|
|
||||||
return $ph->getPermission($this, 'user.canEnter') || $ph->getPermission($this, 'mod.canAlwaysEnter');
|
$canEnter = $ph->getPermission($this, 'user.canEnter');
|
||||||
|
if (isset($suspensions[$this->roomID][ChatSuspension::TYPE_BAN])) {
|
||||||
|
if ($suspensions[$this->roomID][ChatSuspension::TYPE_BAN]['time'] > TIME_NOW) {
|
||||||
|
$canEnter = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $canEnter || $ph->getPermission($this, 'mod.canAlwaysEnter');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -56,8 +64,16 @@ public function canEnter() {
|
|||||||
*/
|
*/
|
||||||
public function canWrite() {
|
public function canWrite() {
|
||||||
$ph = \wcf\system\chat\permission\ChatPermissionHandler::getInstance();
|
$ph = \wcf\system\chat\permission\ChatPermissionHandler::getInstance();
|
||||||
|
$suspensions = ChatSuspension::getSuspensionsForUser();
|
||||||
|
|
||||||
return $ph->getPermission($this, 'user.canWrite') || $ph->getPermission($this, 'mod.canAlwaysWrite');
|
$canWrite = $ph->getPermission($this, 'user.canWrite');
|
||||||
|
if (isset($suspensions[$this->roomID][ChatSuspension::TYPE_MUTE])) {
|
||||||
|
if ($suspensions[$this->roomID][ChatSuspension::TYPE_MUTE]['time'] > TIME_NOW) {
|
||||||
|
$canWrite = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $canWrite || $ph->getPermission($this, 'mod.canAlwaysWrite');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
52
file/lib/data/chat/suspension/ChatSuspension.class.php
Normal file
52
file/lib/data/chat/suspension/ChatSuspension.class.php
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
<?php
|
||||||
|
namespace wcf\data\chat\suspension;
|
||||||
|
use \wcf\system\WCF;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a chat suspension.
|
||||||
|
*
|
||||||
|
* @author Tim Düsterhus
|
||||||
|
* @copyright 2010-2012 Tim Düsterhus
|
||||||
|
* @license Creative Commons Attribution-NonCommercial-ShareAlike <http://creativecommons.org/licenses/by-nc-sa/3.0/legalcode>
|
||||||
|
* @package be.bastelstu.wcf.chat
|
||||||
|
* @subpackage data.chat.suspension
|
||||||
|
*/
|
||||||
|
class ChatSuspension extends \wcf\data\DatabaseObject {
|
||||||
|
/**
|
||||||
|
* @see \wcf\data\DatabaseObject::$databaseTableName
|
||||||
|
*/
|
||||||
|
protected static $databaseTableName = 'chat_suspension';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see \wcf\data\DatabaseObject::$databaseTableIndexName
|
||||||
|
*/
|
||||||
|
protected static $databaseTableIndexName = 'suspensionID';
|
||||||
|
|
||||||
|
const TYPE_MUTE = 1;
|
||||||
|
const TYPE_BAN = 2;
|
||||||
|
|
||||||
|
public static function getSuspensionsForUser(\wcf\data\user\User $user = null) {
|
||||||
|
if ($user === null) $user = WCF::getUser();
|
||||||
|
$suspensions = \wcf\util\ChatUtil::readUserData('suspensions', $user);
|
||||||
|
if ($suspensions === null) {
|
||||||
|
$sql = "SELECT
|
||||||
|
*
|
||||||
|
FROM
|
||||||
|
wcf".WCF_N."_chat_suspension
|
||||||
|
WHERE
|
||||||
|
userID = ?
|
||||||
|
AND time > ?";
|
||||||
|
$stmt = WCF::getDB()->prepareStatement($sql);
|
||||||
|
$stmt->execute(array($user->userID, TIME_NOW));
|
||||||
|
|
||||||
|
$suspensions = array();
|
||||||
|
while ($row = $stmt->fetchArray()) {
|
||||||
|
$suspensions[$row['roomID']][$row['type']] = $row;
|
||||||
|
}
|
||||||
|
|
||||||
|
\wcf\util\ChatUtil::writeUserData(array('suspensions' => $suspensions), $user);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $suspensions;
|
||||||
|
}
|
||||||
|
}
|
38
file/lib/data/chat/suspension/ChatSuspensionAction.class.php
Normal file
38
file/lib/data/chat/suspension/ChatSuspensionAction.class.php
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
namespace wcf\data\chat\suspension;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Executes chat-suspension-related actions.
|
||||||
|
*
|
||||||
|
* @author Tim Düsterhus
|
||||||
|
* @copyright 2010-2012 Tim Düsterhus
|
||||||
|
* @license Creative Commons Attribution-NonCommercial-ShareAlike <http://creativecommons.org/licenses/by-nc-sa/3.0/legalcode>
|
||||||
|
* @package be.bastelstu.wcf.chat
|
||||||
|
* @subpackage data.chat.suspension
|
||||||
|
*/
|
||||||
|
class ChatSuspensionAction extends \wcf\data\AbstractDatabaseObjectAction {
|
||||||
|
/**
|
||||||
|
* @see \wcf\data\AbstractDatabaseObjectAction::$className
|
||||||
|
*/
|
||||||
|
protected $className = '\wcf\data\chat\suspension\ChatSuspensionEditor';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes expired suspensions.
|
||||||
|
*
|
||||||
|
* @return integer Number of deleted suspensions
|
||||||
|
*/
|
||||||
|
public function prune() {
|
||||||
|
$sql = "SELECT
|
||||||
|
".call_user_func(array($this->className, 'getDatabaseTableIndexName'))."
|
||||||
|
FROM
|
||||||
|
".call_user_func(array($this->className, 'getDatabaseTableName'))."
|
||||||
|
WHERE
|
||||||
|
time < ?";
|
||||||
|
$stmt = \wcf\system\WCF::getDB()->prepareStatement($sql);
|
||||||
|
$stmt->execute(array(TIME_NOW));
|
||||||
|
$objectIDs = array();
|
||||||
|
while ($objectIDs[] = $stmt->fetchColumn());
|
||||||
|
|
||||||
|
return call_user_func(array($this->className, 'deleteAll'), $objectIDs);
|
||||||
|
}
|
||||||
|
}
|
29
file/lib/data/chat/suspension/ChatSuspensionEditor.class.php
Normal file
29
file/lib/data/chat/suspension/ChatSuspensionEditor.class.php
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
namespace wcf\data\chat\suspension;
|
||||||
|
use \wcf\system\WCF;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides functions to edit chat suspensions.
|
||||||
|
*
|
||||||
|
* @author Tim Düsterhus
|
||||||
|
* @copyright 2010-2012 Tim Düsterhus
|
||||||
|
* @license Creative Commons Attribution-NonCommercial-ShareAlike <http://creativecommons.org/licenses/by-nc-sa/3.0/legalcode>
|
||||||
|
* @package be.bastelstu.wcf.chat
|
||||||
|
* @subpackage data.chat.suspension
|
||||||
|
*/
|
||||||
|
class ChatSuspensionEditor extends \wcf\data\DatabaseObjectEditor implements \wcf\data\IEditableCachedObject {
|
||||||
|
/**
|
||||||
|
* @see \wcf\data\DatabaseObjectDecorator::$baseClass
|
||||||
|
*/
|
||||||
|
protected static $baseClass = '\wcf\data\chat\suspension\ChatSuspension';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clears the suspension cache.
|
||||||
|
*/
|
||||||
|
public static function resetCache() {
|
||||||
|
$packageID = \wcf\util\ChatUtil::getPackageID();
|
||||||
|
$ush = \wcf\system\user\storage\UserStorageHandler::getInstance();
|
||||||
|
|
||||||
|
$ush->resetAll('suspensions', $packageID);
|
||||||
|
}
|
||||||
|
}
|
@ -16,12 +16,6 @@
|
|||||||
*/
|
*/
|
||||||
class ChatPermissionHandler extends \wcf\system\SingletonFactory {
|
class ChatPermissionHandler extends \wcf\system\SingletonFactory {
|
||||||
protected $chatPermissions = array();
|
protected $chatPermissions = array();
|
||||||
protected static $defaults = array(
|
|
||||||
'user.canEnter' => true,
|
|
||||||
'user.canWrite' => true,
|
|
||||||
'mod.canAlwaysEnter' => false,
|
|
||||||
'mod.canAlwaysWrite' => false
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see \wcf\system\SingletonFactory::init()
|
* @see \wcf\system\SingletonFactory::init()
|
||||||
|
@ -29,7 +29,7 @@ final class ChatUtil {
|
|||||||
*/
|
*/
|
||||||
const PACKAGE_IDENTIFIER = 'be.bastelstu.wcf.chat';
|
const PACKAGE_IDENTIFIER = 'be.bastelstu.wcf.chat';
|
||||||
|
|
||||||
public static $serialize = array('color' => true);
|
public static $serialize = array('color' => true, 'suspensions' => true);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cached packageID of Tims Chat.
|
* Cached packageID of Tims Chat.
|
||||||
@ -158,7 +158,7 @@ public static function readUserData($field, \wcf\data\user\User $user = null) {
|
|||||||
$data[$user->userID] = array(1 => self::getRandomNumber(), 2 => self::getRandomNumber() * 0xFFFF);
|
$data[$user->userID] = array(1 => self::getRandomNumber(), 2 => self::getRandomNumber() * 0xFFFF);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
static::writeUserData(array($field => $data[$user->userID]));
|
if ($data[$user->userID] !== null) static::writeUserData(array($field => $data[$user->userID]));
|
||||||
|
|
||||||
return $data[$user->userID];
|
return $data[$user->userID];
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user