Ejemplo n.º 1
0
 public static function getAclCategories($type = DISCUSS_CATEGORY_ACL_ACTION_VIEW, $userId = '', $parentId = false)
 {
     static $categories = array();
     //$sig = serialize( array($type, $userId, $parentId) );
     $sig = (int) $type . '-' . (int) $userId . '-' . (int) $parentId;
     //if( !array_key_exists($sig, $categories) )
     if (!isset($categories[$sig])) {
         $db = DiscussHelper::getDBO();
         $gid = '';
         if (DiscussHelper::getJoomlaVersion() >= '1.6') {
             if ($userId == '') {
                 $gid = JAccess::getGroupsByUser(0, false);
             } else {
                 $gid = DiscussHelper::getUserGids($userId);
             }
         } else {
             $gid = DiscussHelper::getUserGids($userId);
         }
         $gids = '';
         if (count($gid) > 0) {
             foreach ($gid as $id) {
                 $gids .= empty($gids) ? $db->Quote($id) : ',' . $db->Quote($id);
             }
         }
         $query = 'select c.`id` from `#__discuss_category` as c';
         $query .= ' where not exists (';
         $query .= '		select b.`category_id` from `#__discuss_category_acl_map` as b';
         $query .= '			where b.`category_id` = c.`id` and b.`acl_id` = ' . $db->Quote($type);
         $query .= '			and b.`type` = ' . $db->Quote('group');
         $query .= '			and b.`content_id` IN (' . $gids . ')';
         //logged in user
         if (!empty($userId)) {
             $query .= '			union ';
             $query .= '			select b.`category_id` from `#__discuss_category_acl_map` as b';
             $query .= '				where b.`category_id` = c.`id` and b.`acl_id` = ' . $db->Quote($type);
             $query .= '				and b.`type` = ' . $db->Quote('user');
             $query .= '				and b.`content_id` = ' . $db->Quote($userId);
         }
         $query .= '      )';
         $query .= ' and c.`private` = ' . $db->Quote(DISCUSS_PRIVACY_ACL);
         if ($parentId !== false) {
             $query .= ' and c.`parent_id` = ' . $db->Quote($parentId);
         }
         $db->setQuery($query);
         $categories[$sig] = $db->loadObjectList();
     }
     return $categories[$sig];
 }
Ejemplo n.º 2
0
 public static function getPrivateCategories($acltype = DISCUSS_CATEGORY_ACL_ACTION_VIEW)
 {
     $db = DiscussHelper::getDBO();
     $my = JFactory::getUser();
     static $result = array();
     $excludeCats = array();
     $sig = (int) $my->id . '-' . (int) $acltype;
     if (!isset($result[$sig])) {
         if ($my->id == 0) {
             $catQuery = 'select distinct a.`id`, a.`private`';
             $catQuery .= ' from `#__discuss_category` as a';
             $catQuery .= ' 	left join `#__discuss_category_acl_map` as b on a.`id` = b.`category_id`';
             $catQuery .= ' 		and b.`acl_id` = ' . $db->Quote($acltype);
             $catQuery .= ' 		and b.`type` = ' . $db->Quote('group');
             $catQuery .= ' where a.`private` != ' . $db->Quote('0');
             $gid = array();
             $gids = '';
             if (DiscussHelper::getJoomlaVersion() >= '1.6') {
                 // $gid	= JAccess::getGroupsByUser(0, false);
                 $gid = DiscussHelper::getUserGroupId($my);
             } else {
                 $gid = DiscussHelper::getUserGids();
             }
             if (count($gid) > 0) {
                 foreach ($gid as $id) {
                     $gids .= empty($gids) ? $db->Quote($id) : ',' . $db->Quote($id);
                 }
                 $catQuery .= ' and a.`id` NOT IN (';
                 $catQuery .= '     SELECT c.category_id FROM `#__discuss_category_acl_map` as c ';
                 $catQuery .= '        WHERE c.acl_id = ' . $db->Quote($acltype);
                 $catQuery .= '        AND c.type = ' . $db->Quote('group');
                 $catQuery .= '        AND c.content_id IN (' . $gids . ') )';
             }
             $db->setQuery($catQuery);
             $result = $db->loadObjectList();
         } else {
             $result = self::getAclCategories($acltype, $my->id);
         }
         for ($i = 0; $i < count($result); $i++) {
             $item =& $result[$i];
             $item->childs = null;
             DiscussHelper::buildNestedCategories($item->id, $item, true);
             $catIds = array();
             $catIds[] = $item->id;
             DiscussHelper::accessNestedCategoriesId($item, $catIds);
             $excludeCats = array_merge($excludeCats, $catIds);
         }
         $result[$sig] = $excludeCats;
     }
     return $result[$sig];
 }
Ejemplo n.º 3
0
$password = $siteDetails->get('sitePassword');
$ftpurl = $siteDetails->get('ftpUrl');
$ftpusername = $siteDetails->get('ftpUsername');
$ftppassword = $siteDetails->get('ftpPassword');
$siteinfo = $siteDetails->get('optional');
$showProfileDetails = true;
if (empty($siteUrl) && empty($siteusername) && empty($password) && empty($ftpurl) && empty($ftpusername) && empty($ftppassword)) {
    $showProfileDetails = false;
}
$access = trim($system->config->get('tab_site_access'));
// Nobody can view this if access is not set yet.
if (!$access) {
    return;
}
$access = explode(',', $access);
$gids = DiscussHelper::getUserGids();
$url = $this->getFieldData('siteurl', $post->params);
if (stristr($url[0], 'http://') === false && stristr($url[0], 'https://') === false) {
    $url[0] = 'http://' . $url[0];
}
if (!$showProfileDetails) {
    $siteusernameTemp = $this->getFieldData('siteusername', $post->params);
    $passwordTemp = $this->getFieldData('sitepassword', $post->params);
    $ftpurlTemp = $this->getFieldData('ftpurl', $post->params);
    $ftpusernameTemp = $this->getFieldData('ftpusername', $post->params);
    $ftppasswordTemp = $this->getFieldData('ftppassword', $post->params);
    $siteinfoTemp = $this->getFieldData('siteinfo', $post->params);
    $siteUrl = $this->escape($url[0]);
    $siteusername = $siteusernameTemp[0];
    $password = $passwordTemp[0];
    $ftpurl = $ftpurlTemp[0];
Ejemplo n.º 4
0
 public static function isModerator($categoryId = null, $userId = null)
 {
     static $result = array();
     if (!$userId) {
         $userId = JFactory::getUser()->id;
     }
     // If user id is 0, we know for sure they are not a moderator.
     if (!$userId) {
         return false;
     }
     // Site admin is always a moderator.
     if (DiscussHelper::isSiteAdmin($userId)) {
         return true;
     }
     // If category is not supplied, caller might just want to check if
     // the user is a moderator of any category.
     if (is_null($categoryId)) {
         if (isset($result['isModerator'])) {
             return $result['isModerator'];
         }
         $db = DiscussHelper::getDBO();
         // Get the user's groups first.
         $gids = DiscussHelper::getUserGids($userId);
         // Now, check if the current user has any assignments to this acl id or not.
         $query = array();
         $query[] = 'SELECT COUNT(1) FROM ' . $db->nameQuote('#__discuss_category_acl_map');
         $query[] = 'WHERE ' . $db->nameQuote('acl_id') . ' = ' . $db->Quote(DISCUSS_CATEGORY_ACL_MODERATOR);
         if ($userId) {
             $query[] = 'AND (';
             if ($gids) {
                 $query[] = $db->nameQuote('type') . '=' . $db->Quote('group');
                 $query[] = 'AND ' . $db->nameQuote('content_id') . ' IN(';
                 for ($i = 0; $i < count($gids); $i++) {
                     $query[] = $db->Quote($gids[$i]);
                     if (next($gids) !== false) {
                         $query[] = ',';
                     }
                 }
                 $query[] = ')';
             }
             $query[] = ')';
             $query[] = 'OR';
             $query[] = '(' . $db->nameQuote('type') . ' = ' . $db->Quote('user');
             $query[] = 'AND ' . $db->nameQuote('content_id') . '=' . $db->Quote($userId);
             $query[] = ')';
         }
         $query = implode(' ', $query);
         $db->setQuery($query);
         $count = $db->loadResult();
         $isModerator = $count > 0;
         $result['isModerator'] = $isModerator;
         return $result['isModerator'];
     }
     if (!array_key_exists('groupId', $result)) {
         $table = DiscussHelper::getTable('Category');
         $table->load($categoryId);
         $result[$categoryId] = $table->getModerators();
     }
     $isModerator = in_array($userId, $result[$categoryId]);
     return $isModerator;
 }