@@ -38,7 +38,6 @@ public function __construct($identifier = 0) {
$this->_db = JFactory::getDBO ();
$this->_app = JFactory::getApplication ();
$this->_config = KunenaFactory::getConfig ();
$this->_session_timeout = time() - $this->_app->getCfg ( 'lifetime', 15 ) * 60;
}

/**
@@ -218,14 +217,28 @@ public function getMessageOrdering() {
return $ordering;
}

public function isAdmin($catid = 0) {
$acl = KunenaAccess::getInstance();
return $acl->isAdmin ( $this, $catid );
/**
* Checks if user has administrator permissions in the category.
*
* If no category is given, check is against global administrator permissions.
*
* @param KunenaForumCategory $category
* @return bool
*/
public function isAdmin(KunenaForumCategory $category = null) {
return KunenaAccess::getInstance()->isAdmin ( $this, !empty($category->id) ? $category->id : null );
}

public function isModerator($catid = 0) {
$acl = KunenaAccess::getInstance();
return $acl->isModerator ( $this, $catid );
/**
* Checks if user has moderator permissions in the category.
*
* If no category is given, check is against global moderator permissions.
*
* @param KunenaForumCategory $category
* @return bool
*/
public function isModerator(KunenaForumCategory $category = null) {
return KunenaAccess::getInstance()->isModerator ( $this, !empty($category->id) ? $category->id : null );
}

public function isBanned() {
@@ -299,16 +312,17 @@ public function getType($catid = 0, $code=false) {
'banned'=>'COM_KUNENA_VIEW_BANNED',
'blocked'=>'COM_KUNENA_VIEW_BANNED'
);
$category = KunenaForumCategoryHelper::get($catid);
if (!$this->_type) {
if ($this->userid == 0) {
$this->_type = 'guest';
} elseif ($this->isBanned ()) {
$this->_type = 'banned';
} elseif ($this->isAdmin ( $catid )) {
} elseif ($this->isAdmin ( $category )) {
$this->_type = 'admin';
} elseif ($this->isModerator ( null )) {
$this->_type = 'globalmod';
} elseif ($this->isModerator ( $catid )) {
} elseif ($catid && $this->isModerator ( $category )) {
$this->_type = 'moderator';
} else {
$this->_type = 'user';
@@ -329,6 +343,8 @@ public function getRank($catid = 0, $type = false) {
$rank->rank_image = null;

$config = KunenaFactory::getConfig ();
$category = KunenaForumCategoryHelper::get($catid);

if (! $config->showranking)
return;
if (self::$_ranks === null) {
@@ -357,7 +373,7 @@ public function getRank($catid = 0, $type = false) {
}
} else if ($this->rank != 0 && isset ( self::$_ranks [$this->rank] )) {
$rank = self::$_ranks [$this->rank];
} else if ($this->rank == 0 && $this->isAdmin ( $catid )) {
} else if ($this->rank == 0 && $this->isAdmin ( $category )) {
$rank->rank_id = 0;
$rank->rank_title = JText::_ ( 'COM_KUNENA_RANK_ADMINISTRATOR' );
$rank->rank_special = 1;
@@ -368,7 +384,7 @@ public function getRank($catid = 0, $type = false) {
break;
}
}
} else if ($this->rank == 0 && $this->isModerator ( $catid )) {
} else if ($this->rank == 0 && $this->isModerator ( $category )) {
$rank->rank_id = 0;
$rank->rank_title = JText::_ ( 'COM_KUNENA_RANK_MODERATOR' );
$rank->rank_special = 1;
@@ -91,9 +91,10 @@ public function getAdminCategories() {
$category->parent_id = 0;
$category->name = JText::_ ( 'COM_KUNENA_CATEGORY_ORPHAN' ) . ' : ' . $category->name;
}
$category->up = $this->me->isAdmin($category->parent_id) && reset($siblings) != $category->id;
$category->down = $this->me->isAdmin($category->parent_id) && end($siblings) != $category->id;
$category->reorder = $this->me->isAdmin($category->parent_id);
$parent = $category->getParent();
$category->up = $this->me->isAdmin($parent) && reset($siblings) != $category->id;
$category->down = $this->me->isAdmin($parent) && end($siblings) != $category->id;
$category->reorder = $this->me->isAdmin($parent);
// FIXME: stop creating access names manually
if ($category->accesstype == 'joomla.level') {
$groupname = $acl->getGroupName($category->accesstype, $category->access);
@@ -136,13 +137,13 @@ public function getAdminCategories() {
} else {
$category->admin_group = JText::_ ( $acl->getGroupName($category->accesstype, $category->admin_access ));
}
if ($this->me->isAdmin($category->id) && $category->isCheckedOut(0)) {
if ($this->me->isAdmin($category) && $category->isCheckedOut(0)) {
$category->editor = KunenaFactory::getUser($category->checked_out)->getName();
} else {
$category->checked_out = 0;
$category->editor = '';
}
$admin += $this->me->isAdmin($category->id);
$admin += $this->me->isAdmin($category);
}
$this->setState ( 'list.count.admin', $admin );
}
@@ -158,13 +159,11 @@ public function getAdminNavigation() {
}

public function getAdminCategory() {
$parent_id = $this->getState ( 'item.parent_id' );
$catid = $this->getState ( 'item.id' );
if (!$this->me->isAdmin(null) && !$this->me->isAdmin($catid)) {
$category = KunenaForumCategoryHelper::get ( $this->getState ( 'item.id' ) );
if (!$this->me->isAdmin($category)) {
return false;
}
if ($this->_admincategory === false) {
$category = KunenaForumCategoryHelper::get ( $catid );
if ($category->exists ()) {
if (!$category->isCheckedOut ( $this->me->userid ))
$category->checkout ( $this->me->userid );
@@ -174,7 +173,7 @@ public function getAdminCategory() {
$db->setQuery ( "SELECT a.id, a.name FROM #__kunena_categories AS a WHERE parent_id='0' AND id!='$category->id' ORDER BY ordering" );
$sections = $db->loadObjectList ();
KunenaError::checkDatabaseError ();
$category->parent_id = $parent_id;
$category->parent_id = $this->getState ( 'item.parent_id' );
$category->published = 0;
$category->ordering = 9999;
$category->pub_recurse = 1;
@@ -87,7 +87,7 @@ public function post() {
}

// Flood protection
if ($this->config->floodprotection && ! $this->me->isModerator($category->id)) {
if ($this->config->floodprotection && ! $this->me->isModerator($category)) {
$timelimit = JFactory::getDate()->toUnix() - $this->config->floodprotection;
$ip = $_SERVER ["REMOTE_ADDR"];

@@ -116,7 +116,7 @@ public function post() {
$message->hold = 1;
}
// If configured: Hold posts from users
if ( !$this->me->isModerator() && $this->me->posts < $this->config->hold_newusers_posts ) {
if ( !$this->me->isModerator($category) && $this->me->posts < $this->config->hold_newusers_posts ) {
$message->hold = 1;
}

@@ -255,7 +255,7 @@ protected function karma($karmaDelta) {
}

$now = JFactory::getDate()->toUnix();
if (!$this->me->isModerator($catid) && $now - $this->me->karma_time < $karma_delay) {
if (!$this->me->isModerator() && $now - $this->me->karma_time < $karma_delay) {
$this->app->enqueueMessage ( JText::_ ( 'COM_KUNENA_KARMA_WAIT' ), 'notice' );
$this->redirectBack ();
}
@@ -39,6 +39,6 @@ function getAnnouncement() {
}

function getAnnouncements() {
return KunenaForumAnnouncementHelper::getAnnouncements($this->getState ( 'list.start'), $this->getState ( 'list.limit'), !$this->me->isModerator('global'));
return KunenaForumAnnouncementHelper::getAnnouncements($this->getState ( 'list.start'), $this->getState ( 'list.limit'), !$this->me->isModerator());
}
}
@@ -108,7 +108,7 @@ public function getCategories() {
$userlist += $subcat->moderators;
}

if ($this->me->isModerator ( $subcat->id ))
if ($this->me->isModerator ( $subcat ))
$modcats [] = $subcat->id;
}
$categories [$subcat->parent_id] [] = $subcat;
@@ -143,6 +143,7 @@ public function getCategories() {
}
}
// Fix last post position when user can see unapproved or deleted posts
// FIXME: isModerator()
if ($lastpostlist && !$topic_ordering && $this->me->userid && $this->me->isModerator()) {
KunenaForumMessageHelper::loadLocation($lastpostlist);
}
@@ -216,6 +217,7 @@ public function getTopics() {
$lastreadlist = KunenaForumTopicHelper::fetchNewStatus($this->topics);

// Fetch last / new post positions when user can see unapproved or deleted posts
// FIXME: isModerator()
if (($lastpostlist || $lastreadlist) && $this->me->userid && $this->me->isModerator()) {
KunenaForumMessageHelper::loadLocation($lastpostlist + $lastreadlist);
}
@@ -22,7 +22,7 @@ protected function populateState() {
}

public function getAnnouncement() {
$items = KunenaForumAnnouncementHelper::getAnnouncements(0, 1, $this->me->isModerator('global'));
$items = KunenaForumAnnouncementHelper::getAnnouncements(0, 1, $this->me->isModerator());
return array_pop($items);
}
}
@@ -262,6 +262,7 @@ protected function _common() {
$lastreadlist = KunenaForumTopicHelper::fetchNewStatus($this->topics);
// Fetch last / new post positions when user can see unapproved or deleted posts
$me = KunenaUserHelper::get();
// FIXME: isModerator()
if (($lastpostlist || $lastreadlist) && $me->userid && $me->isModerator()) {
KunenaForumMessageHelper::loadLocation($lastpostlist + $lastreadlist);
}
@@ -123,7 +123,7 @@
<span onclick="document.adminForm.childforums.checked=(! document.adminForm.childforums.checked);"><?php echo JText::_('COM_KUNENA_SEARCH_SEARCHIN_CHILDREN'); ?></span>
</label>
</fieldset>
<?php if ( $this->me->isModerator() ) : ?>
<?php if ( $this->me->isModerator() ) : // FIXME: isModerator() ?>
<fieldset class="fieldset">
<legend><?php echo JText::_('COM_KUNENA_SEARCH_SHOW'); ?></legend>
<input id="show0" type="radio" name="show" value="0" <?php if ($this->state->get('query.show') == 0) echo 'checked="checked"'; ?> />
@@ -54,7 +54,7 @@
<?php echo JText::_('COM_KUNENA_POLL_BUTTON_CHANGEVOTE'); ?>
</a>
<?php endif; ?>
<?php if( $this->me->isModerator() ) : ?>
<?php if( $this->me->isModerator($this->topic->getCategory()) ) : ?>
<a href="<?php echo KunenaRoute::_("index.php?option=com_kunena&view=topic&id={$this->topic->id}&catid={$this->category->id}&pollid={$this->poll->id}&task=resetvotes&".JUtility::getToken() .'=1') ?>"><?php echo JText::_('COM_KUNENA_TOPIC_VOTE_RESET'); ?></a>
<?php endif; ?>
</td>
@@ -140,7 +140,7 @@
</tr>
<?php endif; ?>

<?php if ($this->config->keywords && $this->me->isModerator ( $this->message->catid ) ) : ?>
<?php if ($this->config->keywords && $this->me->isModerator ( $this->topic->getCategory() ) ) : ?>
<tr id="kpost-tags" class="krow<?php echo 1 + $this->k^=1;?>">
<td class="kcol-first">
<strong><?php echo JText::_('COM_KUNENA_EDITOR_TOPIC_TAGS') ?></strong>
@@ -87,7 +87,7 @@
</label>
</fieldset>

<?php if ( $this->me->isModerator() ) : ?>
<?php if ( $this->me->isModerator() ) : // FIXME: isModerator() ?>
<fieldset class="fieldset kbox-hover kbox-border kbox-border_radius">
<legend><?php echo JText::_('COM_KUNENA_SEARCH_SHOW') ?></legend>
<input id="show0" type="radio" name="show" value="0" <?php if ($this->state->get('query.show') == 0) echo 'checked="checked"' ?> />
@@ -25,7 +25,7 @@
<?php else: ?>
<li class="topic-taglist-title"><?php echo JText::_('COM_KUNENA_TOPIC_NO_TAGS') ?></li>
<?php endif ?>
<?php if ( $this->me->userid == $this->topic->first_post_userid || intval($this->me->isModerator('global')) ): ?><li class="topic-taglist-edit"><a id="edit_keywords" class="link"><?php echo JText::_('COM_KUNENA_TOPIC_TAGS_ADD_EDIT') ?></a></li><?php endif ?>
<?php if ( $this->me->userid == $this->topic->first_post_userid || $this->me->isModerator($this->topic->getCategory()) ): ?><li class="topic-taglist-edit"><a id="edit_keywords" class="link"><?php echo JText::_('COM_KUNENA_TOPIC_TAGS_ADD_EDIT') ?></a></li><?php endif ?>
</ul>
<?php endif ?>
</div>
@@ -57,7 +57,7 @@
<?php endif; ?>
</li>
<li>
<?php if( $this->me->isModerator() ) : ?>
<?php if( $this->me->isModerator($this->topic->getCategory()) ) : ?>
<a href="<?php echo KunenaRoute::_("index.php?option=com_kunena&view=topic&id={$this->topic->id}&catid={$this->category->id}&pollid={$this->poll->id}&task=resetvotes&".JUtility::getToken() .'=1') ?>">Reset votes</a>
<?php endif; ?>
</li>
@@ -153,7 +153,7 @@
</div>
</div>
</li>
<?php if ($this->config->keywords && $this->me->isModerator ( $this->message->catid ) ) : ?>
<?php if ($this->config->keywords && $this->me->isModerator ( $this->topic->getCategory() ) ) : ?>
<li class="postmessage-row kbox-hover kbox-hover_list-row">
<div class="form-label">
<div class="innerspacer-left kbox-full">
@@ -25,7 +25,7 @@
<?php else: ?>
<li class="topic-taglist-title"><?php echo JText::_('COM_KUNENA_TOPIC_NO_TAGS') ?></li>
<?php endif ?>
<?php if ( $this->me->userid == $this->topic->first_post_userid || intval($this->me->isModerator('global')) ): ?><li class="topic-taglist-edit"><a href="#" id="edit_keywords" class="link"><?php echo JText::_('COM_KUNENA_TOPIC_TAGS_ADD_EDIT') ?></a></li><?php endif ?>
<?php if ( $this->me->userid == $this->topic->first_post_userid || $this->me->isModerator($this->topic->getCategory()) ): ?><li class="topic-taglist-edit"><a href="#" id="edit_keywords" class="link"><?php echo JText::_('COM_KUNENA_TOPIC_TAGS_ADD_EDIT') ?></a></li><?php endif ?>
</ul>
<?php endif ?>
</div>
@@ -25,7 +25,7 @@
<?php else: ?>
<li class="topic-taglist-title"><?php echo JText::_('COM_KUNENA_TOPIC_NO_TAGS') ?></li>
<?php endif ?>
<?php if ( $this->me->userid == $this->topic->first_post_userid || intval($this->me->isModerator('global')) ): ?><li class="topic-taglist-edit"><a href="#" id="edit_keywords" class="link"><?php echo JText::_('COM_KUNENA_TOPIC_TAGS_ADD_EDIT') ?></a></li><?php endif ?>
<?php if ( $this->me->userid == $this->topic->first_post_userid || $this->me->isModerator($this->topic->getCategory()) ): ?><li class="topic-taglist-edit"><a href="#" id="edit_keywords" class="link"><?php echo JText::_('COM_KUNENA_TOPIC_TAGS_ADD_EDIT') ?></a></li><?php endif ?>
</ul>
<?php endif ?>
</div>
@@ -61,7 +61,7 @@ function displayList($tpl = null) {

if ($this->category->isSection()) {
// TODO: turn this on:
/* if ($this->me->isAdmin(null)) {
/* if ($this->me->isAdmin($this->category)) {
$url = KunenaRoute::_("index.php?option=com_kunena&view=category&layout=manage&catid={$this->category->id}");
$this->category_manage = $this->getButton($url, 'manage', 'category', 'moderation');
}*/
@@ -152,7 +152,6 @@ function displayBreadcrumb($tpl = null) {
function displayWhosonline($tpl = null) {
if ($this->offline) return;

$moderator = intval($this->me->isModerator());
$cache = JFactory::getCache('com_kunena', 'output');
// FIXME: enable caching after fixing the issues
//if ($cache->start("{$this->ktemplate->name}.common.whosonline.{$moderator}", "com_kunena.template")) return;
@@ -179,10 +178,11 @@ function displayWhosonline($tpl = null) {

$this->onlineList = array();
$this->hiddenList = array();
$moderator = $this->me->isModerator();
foreach ($users as $userid=>$usertime) {
$user = KunenaUserHelper::get($userid);
if ( !$user->showOnline ) {
if ($this->me->isModerator()) $this->hiddenList[$user->getName()] = $user;
if ($moderator) $this->hiddenList[$user->getName()] = $user;
} else {
$this->onlineList[$user->getName()] = $user;
}
@@ -301,7 +301,7 @@ function displayLoginBox($tpl = null) {
//$this->editProfileLink = '<a href="' . $url.'">'. JText::_('COM_KUNENA_PROFILE_EDIT').'</a>';

// Announcements
if ( $this->me->isModerator()) {
if ( $this->me->isAdmin()) {
$this->announcementsLink = '<a href="' . KunenaForumAnnouncementHelper::getUrl('list').'">'. JText::_('COM_KUNENA_ANN_ANNOUNCEMENTS').'</a>';
}

@@ -658,7 +658,7 @@ function getMessageActions() {
$this->messageButtons->set('reply', $this->getButton ( sprintf($layout, 'reply'), 'reply', 'message', 'communication'));
$this->messageButtons->set('quote', $this->getButton ( sprintf($layout, 'reply&quote=1'), 'quote', 'message', 'communication'));

} elseif (!$this->me->isModerator ( $this->topic->category_id )) {
} elseif (!$this->me->isModerator ( $this->topic->getCategory() )) {
// User is not allowed to write a post
$this->message_closed = $this->topic->locked ? JText::_('COM_KUNENA_POST_LOCK_SET') : JText::_('COM_KUNENA_VIEW_DISABLED');
}
@@ -709,8 +709,8 @@ function displayMessage($id, $message, $template=null) {
$task = "index.php?option=com_kunena&view=topic&task=%s&catid={$this->category->id}&id={$this->topic->id}&mesid={$this->message->id}&" . JUtility::getToken() . '=1';
$thankyou = $this->message->getThankyou();
//TODO: for normal users, show only limited number of thankyou (config->thankyou_max)
foreach( $thankyou->getList() as $userid=>$time){
$thankyou_delete = $this->me->isModerator() ? ' <a title="'.JText::_('COM_KUNENA_BUTTON_THANKYOU_REMOVE_LONG').'" href="'
foreach( $thankyou->getList() as $userid=>$time) {
$thankyou_delete = $this->me->isModerator($this->message->getCategory()) ? ' <a title="'.JText::_('COM_KUNENA_BUTTON_THANKYOU_REMOVE_LONG').'" href="'
. KunenaRoute::_(sprintf($task, "unthankyou&userid={$userid}")).'"><img src="'.$this->ktemplate->getImagePath('icons/publish_x.png').'" title="" alt="" /></a>' : '';
$this->thankyou[] = KunenaFactory::getUser(intval($userid))->getLink().$thankyou_delete;
}
@@ -116,6 +116,7 @@ protected function displayCommon($tpl = null) {
$this->signatureHtml = KunenaHtmlParser::parseBBCode($this->signature, null, $this->config->maxsig);
$this->localtime = KunenaDate::getInstance('now', $this->user->getParam('timezone', $this->app->getCfg ( 'offset', 0 )));
$this->localtime->setOffset($this->user->getParam('timezone', $this->app->getCfg ( 'offset', 0 )));
// FIXME: isModerator()
$this->moderator = $this->profile->isModerator();
$this->admin = $this->profile->isAdmin();
switch ($this->profile->gender) {
@@ -151,10 +152,11 @@ protected function displayCommon($tpl = null) {
$this->showSubscriptions = $this->config->allowsubscriptions && $this->me->userid == $this->profile->userid;
$this->showFavorites = $this->config->allowfavorites && $this->me->userid == $this->profile->userid;
$this->showThankyou = $this->config->showthankyou && $this->me->exists();
// FIXME: isModerator()
$this->showUnapprovedPosts = $this->me->isModerator(); // || $this->me->userid == $this->profile->userid;
$this->showAttachments = $this->canManageAttachments() && ($this->me->isModerator(false) || $this->me->userid == $this->profile->userid);
$this->showBanManager = $this->me->isModerator(false) && $this->me->userid == $this->profile->userid;
$this->showBanHistory = $this->me->isModerator(false) && $this->me->userid != $this->profile->userid;
$this->showAttachments = $this->canManageAttachments() && ($this->me->isModerator() || $this->me->userid == $this->profile->userid);
$this->showBanManager = $this->me->isModerator() && $this->me->userid == $this->profile->userid;
$this->showBanHistory = $this->me->isModerator() && $this->me->userid != $this->profile->userid;
$this->showBanUser = $this->canBan;

if ($this->me->userid != $this->profile->userid) {