2011-11-27 11:46:10 +00:00
|
|
|
<?php
|
|
|
|
namespace wcf\system\menu\page;
|
2011-12-15 09:54:18 +00:00
|
|
|
use \wcf\data\chat\room\ChatRoom;
|
2011-11-27 11:46:10 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* PageMenuItemProvider for chat.
|
|
|
|
*
|
|
|
|
* @author Tim Düsterhus
|
2012-01-28 16:50:33 +00:00
|
|
|
* @copyright 2010-2012 Tim Düsterhus
|
2011-11-27 11:46:10 +00:00
|
|
|
* @license Creative Commons Attribution-NonCommercial-ShareAlike <http://creativecommons.org/licenses/by-nc-sa/3.0/legalcode>
|
|
|
|
* @package timwolla.wcf.chat
|
|
|
|
* @subpackage system.menu.page
|
|
|
|
*/
|
|
|
|
class ChatPageMenuItemProvider extends DefaultPageMenuItemProvider {
|
2011-12-15 09:54:18 +00:00
|
|
|
protected $room = null;
|
|
|
|
|
2011-11-27 11:46:10 +00:00
|
|
|
/**
|
|
|
|
* Hides the button when there is no valid room
|
|
|
|
*
|
2011-12-15 09:54:18 +00:00
|
|
|
* @see \wcf\system\menu\page\PageMenuItemProvider::isVisible()
|
2011-11-27 11:46:10 +00:00
|
|
|
*/
|
|
|
|
public function isVisible() {
|
2011-11-27 19:01:28 +00:00
|
|
|
// guests are not supported
|
2011-11-29 15:57:44 +00:00
|
|
|
if (!\wcf\system\WCF::getUser()->userID) return false;
|
2011-11-27 19:01:28 +00:00
|
|
|
|
2011-11-27 11:46:10 +00:00
|
|
|
try {
|
2011-12-15 16:14:55 +00:00
|
|
|
$cache = ChatRoom::getCache();
|
2011-12-26 11:43:19 +00:00
|
|
|
$i = 0;
|
|
|
|
|
|
|
|
do {
|
|
|
|
$cache->seek($i++);
|
2012-01-03 12:10:46 +00:00
|
|
|
$this->room = $cache->current();
|
2011-12-26 11:43:19 +00:00
|
|
|
}
|
|
|
|
while (!$this->room->canEnter());
|
|
|
|
|
2011-11-27 11:46:10 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
catch (\OutOfBoundsException $e) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2011-12-15 09:54:18 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Modifies the link to show the Link we would be redirect to.
|
|
|
|
*
|
|
|
|
* @see \wcf\system\menu\page\PageMenuItemProvider::getLink()
|
|
|
|
*/
|
|
|
|
public function getLink() {
|
2011-12-15 16:14:55 +00:00
|
|
|
return \wcf\system\request\LinkHandler::getInstance()->getLink('Chat', array(
|
|
|
|
'object' => $this->room
|
|
|
|
));
|
2011-12-15 09:54:18 +00:00
|
|
|
}
|
2011-11-27 11:46:10 +00:00
|
|
|
}
|