function getCountsByCat($cat_id = 0, $status, $inSubCat = false) { $ret = array(); $sql = 'SELECT c.parentid, i.categoryid, COUNT(*) AS count FROM ' . $this->db->prefix('smartsection_items') . ' AS i INNER JOIN ' . $this->db->prefix('smartsection_categories') . ' AS c ON i.categoryid=c.categoryid'; if (intval($cat_id) > 0) { $sql .= ' WHERE i.categoryid = ' . intval($cat_id); $sql .= ' AND i.status IN (' . implode(',', $status) . ')'; } else { $sql .= ' WHERE i.status IN (' . implode(',', $status) . ')'; if (!smartsection_userIsAdmin()) { $smartsectionPermHandler =& xoops_getmodulehandler('permission', 'smartsection'); $items = $smartsectionPermHandler->getGrantedItems('item_read'); $sql .= ' AND i.itemid IN (' . implode(',', $items) . ')'; } } $sql .= ' GROUP BY i.categoryid ORDER BY c.parentid ASC, i.categoryid ASC'; //echo "<br />$sql<br />"; $result = $this->db->query($sql); if (!$result) { return $ret; } $categories = array(); if (!$inSubCat) { while ($row = $this->db->fetchArray($result)) { $catsCount[$row['categoryid']] = $row['count']; } return $catsCount; } while ($row = $this->db->fetchArray($result)) { $catsCount[$row['parentid']][$row['categoryid']] = $row['count']; } global $resultCatCounts; $resultCatCounts = array(); foreach ($catsCount[0] as $subCatId => $count) { $resultCatCounts[$subCatId] = $count; if (isset($catsCount[$subCatId])) { $resultCatCounts[$subCatId] = $resultCatCounts[$subCatId] + $this->countArticlesByCat($subCatId, $catsCount); } } return $resultCatCounts; }
function smartsection_itemAccessGranted(&$itemObj) { global $xoopsUser; if (smartsection_userIsAdmin()) { $result = true; } else { $result = false; $categoryid = $itemObj->categoryid(); $itemid = $itemObj->itemid(); if ($itemObj->status() != _SSECTION_STATUS_PUBLISHED) { return false; } $groups = $xoopsUser ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS; $gperm_handler =& xoops_gethandler('groupperm'); $hModule =& xoops_gethandler('module'); $hModConfig =& xoops_gethandler('config'); $smartModule =& $hModule->getByDirname('smartsection'); $module_id = $smartModule->getVar('mid'); // Do we have access to the parent category if ($gperm_handler->checkRight('category_read', $categoryid, $groups, $module_id)) { // Do we have access to the item ? if ($gperm_handler->checkRight('item_read', $itemid, $groups, $module_id)) { $result = true; } else { // No we don't ! $result = false; } } else { // No we don't ! $result = false; } } return $result; }
} include_once $common_lang_file; // include smartobject framework if (!file_exists(XOOPS_ROOT_PATH . '/modules/smartobject/include/common.php')) { trigger_error('SmartObject Framework not found.', E_USER_ERROR); } include_once XOOPS_ROOT_PATH . '/modules/smartobject/include/common.php'; include_once SMARTSECTION_ROOT_PATH . "include/functions.php"; // Check XOOPS version to see if we are on XOOPS 2.2.x plateform $xoops22 = smartsection_isXoops22(); include_once SMARTSECTION_ROOT_PATH . "include/seo_functions.php"; include_once SMARTSECTION_ROOT_PATH . "class/keyhighlighter.class.php"; // Creating the SmartModule object $smartModule =& smartsection_getModuleInfo(); // Find if the user is admin of the module $smartsection_isAdmin = smartsection_userIsAdmin(); $smartsection_moduleName = $smartModule->getVar('name'); // Creating the SmartModule config Object $smartConfig =& smartsection_getModuleConfig(); include_once SMARTSECTION_ROOT_PATH . "class/smartmetagen.php"; include_once SMARTSECTION_ROOT_PATH . "class/permission.php"; include_once SMARTSECTION_ROOT_PATH . "class/category.php"; include_once SMARTSECTION_ROOT_PATH . "class/item.php"; include_once SMARTSECTION_ROOT_PATH . "class/file.php"; include_once SMARTSECTION_ROOT_PATH . "class/session.php"; // Creating the item handler object $smartsection_item_handler =& xoops_getmodulehandler('item', SMARTSECTION_DIRNAME); // Creating the category handler object $smartsection_category_handler =& xoops_getmodulehandler('category', SMARTSECTION_DIRNAME); // Creating the permission handler object $smartsection_permission_handler =& xoops_getmodulehandler('permission', SMARTSECTION_DIRNAME);
function &getCategories($limit = 0, $start = 0, $parentid = 0, $sort = 'weight', $order = 'ASC', $id_as_key = true) { global $smartsection_isAdmin; if (!isset($smartsection_isAdmin)) { // Find if the user is admin of the module $smartsection_isAdmin = smartsection_userIsAdmin(); } $criteria = new CriteriaCompo(); $criteria->setSort($sort); $criteria->setOrder($order); if ($parentid != -1) { $criteria->add(new Criteria('parentid', $parentid)); } if (!$smartsection_isAdmin) { $smartsectionPermHandler =& xoops_getmodulehandler('permission', 'smartsection'); $categoriesGranted = $smartsectionPermHandler->getGrantedItems('category_read'); $criteria->add(new Criteria('categoryid', "(" . implode(',', $categoriesGranted) . ")", 'IN')); } $criteria->setStart($start); $criteria->setLimit($limit); $ret = $this->getObjects($criteria, $id_as_key); return $ret; }