/** * This function is used to display the cog options for any users * @param $targetId * @param int $groupId * @param int $eventId * @param bool $getHTML * @return stdClass|type */ public static function getUserCog($targetId, $groupId = 0, $eventId = 0, $getHTML = false) { if (!$targetId) { return false; } $my = CFactory::getUser(); //current user $user = CFactory::getUser($targetId); $display = new stdClass(); $display->canFeature = false; $display->canBlock = false; $display->canIgnore = false; $display->canBan = false; $display->canUnfeature = false; $display->canUnblock = false; $display->canUnignore = false; $display->canSetGroupAdmin = false; $display->canUnsetGroupAdmin = false; $display->canSetEventAdmin = false; $display->canUnsetEventAdmin = false; $display->canBanFromGroup = false; $display->canUnbanFromGroup = false; $display->canRemoveFromGroup = false; $display->canBanFromGroup = false; $datas = array('canFeature' => array('lang' => 'COM_COMMUNITY_MAKE_FEATURED', 'href' => 'joms.api.userAddFeatured("' . $targetId . '")'), 'canUnfeature' => array('lang' => 'COM_COMMUNITY_REMOVE_FEATURED', 'href' => 'joms.api.userRemoveFeatured("' . $targetId . '")'), 'canBlock' => array('lang' => 'COM_COMMUNITY_BLOCK_USER', 'href' => 'joms.api.userBlock("' . $targetId . '")'), 'canUnblock' => array('lang' => 'COM_COMMUNITY_UNBLOCK_USER', 'href' => 'joms.api.userUnblock("' . $targetId . '")'), 'canBan' => array('lang' => 'COM_COMMUNITY_BAN_USER', 'href' => 'joms.api.userBan("' . $targetId . '")'), 'canIgnore' => array('lang' => 'COM_COMMUNITY_PREFERENCES_IGNORE', 'href' => 'joms.api.userIgnore("' . $targetId . '")'), 'canUnignore' => array('lang' => 'COM_COMMUNITY_PREFERENCES_UNIGNORE', 'href' => 'joms.api.userUnignore("' . $targetId . '")'), 'canSetGroupAdmin' => array('lang' => 'COM_COMMUNITY_GROUPS_ADMIN', 'href' => 'jax.call("community", "groups,ajaxAddAdmin", "' . $targetId . '", "' . $groupId . '")'), 'canUnsetGroupAdmin' => array('lang' => 'COM_COMMUNITY_GROUPS_REVERT_ADMIN', 'href' => 'jax.call("community", "groups,ajaxRemoveAdmin", "' . $targetId . '", "' . $groupId . '")'), 'canSetEventAdmin' => array('lang' => 'COM_COMMUNITY_EVENTS_ADMIN_SET', 'href' => 'jax.call("community","events,ajaxManageAdmin","' . $targetId . '", "' . $eventId . '","add")'), 'canUnsetEventAdmin' => array('lang' => 'COM_COMMUNITY_EVENTS_ADMIN_REVERT', 'href' => 'jax.call("community","events,ajaxManageAdmin","' . $targetId . '", "' . $eventId . '","remove")'), 'canBanFromGroup' => array('lang' => 'COM_COMMUNITY_GROUPS_BAN_FROM_GROUP', 'href' => 'joms.api.groupBanMember("' . $groupId . '", "' . $targetId . '")'), 'canUnbanFromGroup' => array('lang' => 'COM_COMMUNITY_GROUPS_UNBAN_FROM_GROUP', 'href' => 'joms.api.groupUnbanMember("' . $groupId . '", "' . $targetId . '")'), 'canRemoveFromGroup' => array('lang' => 'COM_COMMUNITY_GROUPS_REMOVE_FROM_GROUP', 'href' => 'joms.api.groupRemoveMember("' . $groupId . '", "' . $targetId . '")')); //if user is not logged in, nothing should be displayed at all if (!$my->id || $my->id == $targetId) { return false; } if (COwnerHelper::isCommunityAdmin($my->id)) { $featured = new CFeatured(FEATURED_USERS); $isFeatured = $featured->isFeatured($user->id); if ($isFeatured) { $display->canUnfeature = true; } else { $display->canFeature = true; } $display->canBan = true; //always true because if useajaxStreamAddr is banned, he shouldn't be in the list anymore } //we can only ignore or block user. We cannot do both $blockModel = CFactory::getModel('block'); $block = $blockModel->getBlockStatus($my->id, $user->id, true); if ($block) { if (isset($block->type) && $block->type == 'block') { $display->canUnblock = true; $display->canIgnore = true; } else { //this is ignore list $display->canUnignore = true; $display->canBlock = true; } } else { $display->canIgnore = true; $display->canBlock = true; } //For Group only if ($groupId) { $datas['canBan']['lang'] = 'COM_COMMUNITY_BAN_FROM_SITE'; $group = JTable::getInstance('Group', 'CTable'); $group->load($groupId); if ($group->isAdmin($my->id) || COwnerHelper::isCommunityAdmin()) { if ($group->ownerid != $user->id) { //if user is admin, then we can unset him, unless the admin is the creator if ($group->isAdmin($user->id)) { $display->canUnsetGroupAdmin = true; } else { $display->canSetGroupAdmin = true; } //we can ban any member of the group if ($group->isBanned($user->id)) { $display->canUnbanFromGroup = true; } else { $display->canBanFromGroup = true; } $display->canRemoveFromGroup = true; } } } //for event only if ($eventId) { $datas['canBan']['lang'] = 'COM_COMMUNITY_BAN_FROM_SITE'; $event = JTable::getInstance('Event', 'CTable'); $event->load($eventId); if ($event->isAdmin($my->id) || COwnerHelper::isCommunityAdmin()) { if ($event->isMember($user->id) && !$event->isCreator($user->id)) { //if user is admin, then we can unset him, unless the admin is the creator if ($event->isAdmin($user->id)) { $display->canUnsetEventAdmin = true; } else { $display->canSetEventAdmin = true; } } } } if ($getHTML) { $tmpl = new CTemplate(); return $tmpl->set('options', $display)->set('datas', $datas)->set('groupid', $groupId ? $groupId : false)->set('eventid', $eventId ? $eventId : false)->fetch('general/user-cog'); } return $display; }
private function _getAdminControlHTML($userid) { $adminControlHTML = ''; if (COwnerHelper::isCommunityAdmin()) { $user = CFactory::getUser($userid); $params = $user->getParams(); $videoid = $params->get('profileVideo', 0); $tmpl = new CTemplate(); $tmpl->set('userid', $userid); $isDefaultPhoto = $user->getThumbAvatar() == rtrim(JURI::root(), '/') . '/components/com_community/assets/default_thumb.jpg' ? true : false; CFactory::load('libraries', 'featured'); $featured = new CFeatured(FEATURED_USERS); $isFeatured = $featured->isFeatured($user->id); $jConfig = JFactory::getConfig(); $tmpl->set('videoid', $videoid); $tmpl->set('isCommunityAdmin', COwnerHelper::isCommunityAdmin($user->id)); $tmpl->set('blocked', $user->isBlocked()); $tmpl->set('isFeatured', $isFeatured); $tmpl->set('isDefaultPhoto', $isDefaultPhoto); $tmpl->set('jConfig', $jConfig); $adminControlHTML = $tmpl->fetch('admin.controls'); } return $adminControlHTML; }