示例#1
0
文件: content.php 项目: cwcw/cms
/**
* @param int The category id
* @param int The group id of the user
* @param int The access level of the user
* @param int The section id
* @param int The number of items to dislpay
* @param int The offset for pagination
*/
function showCategory($id, $gid, &$access, $sectionid, $limit, $limitstart, $now)
{
    global $database, $mainframe, $Itemid, $mosConfig_offset, $mosConfig_list_limit;
    $noauth = !$mainframe->getCfg('shownoauth');
    $selected = mosGetParam($_POST, 'order', '');
    // Paramters
    $params = new stdClass();
    if ($Itemid) {
        $menu = new mosMenu($database);
        $menu->load($Itemid);
        $params =& new mosParameters($menu->params);
    } else {
        $menu = "";
        $params =& new mosParameters('');
    }
    if ($selected) {
        $orderby = $selected;
    } else {
        $orderby = $params->get('orderby', 'rdate');
        $selected = $orderby;
    }
    $params->def('page_title', 1);
    $params->def('title', 1);
    $params->def('hits', $mainframe->getCfg('hits'));
    $params->def('author', !$mainframe->getCfg('hideAuthor'));
    $params->def('date', !$mainframe->getCfg('hideCreateDate'));
    $params->def('date_format', _DATE_FORMAT_LC);
    $params->def('navigation', 2);
    $params->def('display', 1);
    $params->def('display_num', $mosConfig_list_limit);
    $params->def('other_cat', 1);
    $params->def('empty_cat', 0);
    $params->def('cat_items', 1);
    $params->def('cat_description', 1);
    $params->def('back_button', $mainframe->getCfg('back_button'));
    $params->def('pageclass_sfx', '');
    $params->def('headings', 1);
    $params->def('order_select', 1);
    $params->def('filter', 1);
    $params->def('filter_type', 'title');
    // Ordering control
    $orderby = _orderby_sec($orderby);
    $category = new mosCategory($database);
    $category->load($id);
    if ($sectionid == 0) {
        $sectionid = $category->section;
    }
    if ($access->canEdit) {
        $xwhere = '';
        $xwhere2 = "AND b.state >= '0'";
    } else {
        $xwhere = "\n AND c.published='1'";
        $xwhere2 = "\n AND b.state='1'" . "\n AND ( publish_up = '0000-00-00 00:00:00' OR publish_up <= '" . $now . "' )" . "\n AND ( publish_down = '0000-00-00 00:00:00' OR publish_down >= '" . $now . "' )";
    }
    // check if this is a category menu item
    if ($Itemid) {
        $menu = new mosMenu($database);
        $menu->load($Itemid);
        if ($menu->type == 'content_category') {
            $xwhere = "\n\tAND a.id = '" . $id . "'";
        }
    } else {
        $menu = "";
    }
    // show/hide empty categories
    if ($params->get('empty_cat')) {
        $empty = '';
    } else {
        $empty = "\n HAVING COUNT( b.id ) > 0";
    }
    // get the list of other categories
    $query = "SELECT c.*, COUNT( b.id ) AS numitems" . "\n FROM #__categories AS c" . "\n LEFT JOIN #__content AS b ON b.catid = c.id " . $xwhere2 . "\n WHERE c.section = '" . $category->section . "'" . ($noauth ? "\n AND c.access <= '" . $gid . "'" : '') . "\n GROUP BY c.id" . $empty . "\n ORDER BY c.ordering";
    $database->setQuery($query);
    $other_categories = $database->loadObjectList();
    // get the total number of published items in the category
    if ($access->canEdit) {
        $xwhere = "AND a.state >= '0'";
    } else {
        $xwhere = "\n AND a.state='1'" . "\n AND ( publish_up = '0000-00-00 00:00:00' OR publish_up <= '{$now}' )" . "\n AND ( publish_down = '0000-00-00 00:00:00' OR publish_down >= '{$now}' )";
    }
    $query = "SELECT a.id" . "\n FROM #__content AS a" . "\n WHERE a.sectionid = '" . $category->section . "'" . "\n AND a.catid = '" . $category->id . "'" . $xwhere;
    $database->setQuery($query);
    $counter = $database->loadObjectList();
    $total = count($counter);
    $limit = $limit ? $limit : $params->get('display_num');
    if ($total <= $limit) {
        $limitstart = 0;
    }
    require_once $GLOBALS['mosConfig_absolute_path'] . '/includes/pageNavigation.php';
    $pageNav = new mosPageNav($total, $limitstart, $limit);
    // filter functionality
    $filter = trim(mosGetParam($_POST, 'filter', ''));
    $filter = strtolower($filter);
    $and = '';
    if ($filter) {
        if ($params->get('filter')) {
            switch ($params->get('filter_type')) {
                case 'title':
                    $and = "\n AND LOWER( a.title ) LIKE '%" . $filter . "%'";
                    break;
                case 'author':
                    $and = "\n AND ( ( LOWER( u.name ) LIKE '%" . $filter . "%' ) OR ( LOWER( a.created_by_alias ) LIKE '%" . $filter . "%' ) )";
                    break;
                case 'hits':
                    $and = "\n AND a.hits LIKE '%" . $filter . "%'";
                    break;
            }
        }
    }
    // get the list of items for this category
    $query = "SELECT a.id, a.title, a.hits, a.created_by, a.created_by_alias, a.created AS created, a.access, u.name AS author, a.state, g.name AS groups" . "\n FROM #__content AS a" . "\n LEFT JOIN #__users AS u ON u.id = a.created_by" . "\n LEFT JOIN #__groups AS g ON a.access = g.id" . "\n WHERE a.catid='" . $category->id . "' " . $xwhere . ($noauth ? "\n AND a.access<='" . $gid . "'" : '') . "\n AND '" . $category->access . "'<='" . $gid . "'" . $and . "\n ORDER BY " . $orderby . "" . "\n LIMIT " . $limitstart . ", " . $limit;
    $database->setQuery($query);
    $items = $database->loadObjectList();
    $check = 0;
    if ($params->get('date')) {
        $order[] = mosHTML::makeOption('date', _ORDER_DROPDOWN_DA);
        $order[] = mosHTML::makeOption('rdate', _ORDER_DROPDOWN_DD);
        $check .= 1;
    }
    if ($params->get('title')) {
        $order[] = mosHTML::makeOption('alpha', _ORDER_DROPDOWN_TA);
        $order[] = mosHTML::makeOption('ralpha', _ORDER_DROPDOWN_TD);
        $check .= 1;
    }
    if ($params->get('hits')) {
        $order[] = mosHTML::makeOption('hits', _ORDER_DROPDOWN_HA);
        $order[] = mosHTML::makeOption('rhits', _ORDER_DROPDOWN_HD);
        $check .= 1;
    }
    if ($params->get('author')) {
        $order[] = mosHTML::makeOption('author', _ORDER_DROPDOWN_AUA);
        $order[] = mosHTML::makeOption('rauthor', _ORDER_DROPDOWN_AUD);
        $check .= 1;
    }
    $order[] = mosHTML::makeOption('order', _ORDER_DROPDOWN_O);
    $lists['order'] = mosHTML::selectList($order, 'order', 'class="inputbox" size="1"  onchange="document.adminForm.submit();"', 'value', 'text', $selected);
    if ($check < 1) {
        $lists['order'] = '';
        $params->set('order_select', 0);
    }
    $lists['task'] = 'category';
    $lists['filter'] = $filter;
    // Dynamic Page Title
    $mainframe->SetPageTitle($menu->name);
    HTML_content::showContentList($category, $items, $access, $id, $sectionid, $gid, $params, $pageNav, $other_categories, $lists);
}
示例#2
0
/**
* @param int The category id
* @param int The group id of the user
* @param int The access level of the user
* @param int The section id
* @param int The number of items to dislpay
* @param int The offset for pagination
*/
function showCategory($id, $gid, &$access, $sectionid, $limit, $selected, $limitstart, $now, $selected, $filter)
{
    global $database, $mainframe, $Itemid, $mosConfig_list_limit;
    $category = new mosCategory($database);
    $category->load((int) $id);
    /*
    Check if category is published
    */
    if (!$category->published) {
        mosNotAuth();
        return;
    }
    /*
     * check whether category access level allows access
     */
    if ($category->access > $gid) {
        mosNotAuth();
        return;
    }
    $section = new mosSection($database);
    $section->load($category->section);
    /*
    Check if category is published
    */
    if (!$section->published) {
        mosNotAuth();
        return;
    }
    /*
     * check whether section access level allows access
     */
    if ($section->access > $gid) {
        mosNotAuth();
        return;
    }
    $now = _CURRENT_SERVER_TIME;
    $nullDate = $database->getNullDate();
    $noauth = !$mainframe->getCfg('shownoauth');
    // Paramters
    $params = new stdClass();
    if ($Itemid) {
        $menu = $mainframe->get('menu');
        $params = new mosParameters($menu->params);
    } else {
        $menu = '';
        $params = new mosParameters('');
    }
    $lists['order_value'] = '';
    if ($selected) {
        $orderby = $selected;
        $lists['order_value'] = $selected;
    } else {
        $orderby = $params->get('orderby', 'rdate');
        $selected = $orderby;
    }
    $params->set('type', 'category');
    $params->def('description_cat', 1);
    $params->def('description_cat_image', 1);
    $params->def('page_title', 1);
    $params->def('title', 1);
    $params->def('hits', $mainframe->getCfg('hits'));
    $params->def('author', !$mainframe->getCfg('hideAuthor'));
    $params->def('date', !$mainframe->getCfg('hideCreateDate'));
    $params->def('date_format', _DATE_FORMAT_LC);
    $params->def('navigation', 2);
    $params->def('display', 1);
    $params->def('display_num', $mosConfig_list_limit);
    $params->def('other_cat', 1);
    $params->def('empty_cat', 0);
    $params->def('cat_items', 1);
    $params->def('cat_description', 0);
    $params->def('back_button', $mainframe->getCfg('back_button'));
    $params->def('pageclass_sfx', '');
    $params->def('headings', 1);
    $params->def('order_select', 1);
    $params->def('filter', 1);
    $params->def('filter_type', 'title');
    // param controls whether unpublished items visible to publishers and above
    $params->def('unpublished', 1);
    // Ordering control
    $orderby = _orderby_sec($orderby);
    // Description & Description Image control
    $params->def('description', $params->get('description_cat'));
    $params->def('description_image', $params->get('description_cat_image'));
    if ($sectionid == 0) {
        $sectionid = $category->section;
    }
    if ($access->canEdit) {
        $xwhere = '';
        if ($params->get('unpublished')) {
            // shows unpublished items for publishers and above
            $xwhere2 = "\n AND b.state >= 0";
        } else {
            // unpublished items NOT shown for publishers and above
            $xwhere2 = "\n AND b.state = 1";
        }
    } else {
        $xwhere = "\n AND c.published = 1";
        $xwhere2 = "\n AND b.state = 1" . "\n AND ( b.publish_up = " . $database->Quote($nullDate) . " OR b.publish_up <= " . $database->Quote($now) . " )" . "\n AND ( b.publish_down = " . $database->Quote($nullDate) . " OR b.publish_down >= " . $database->Quote($now) . " )";
    }
    $pagetitle = '';
    if ($Itemid) {
        $pagetitle = $menu->name;
    }
    // show/hide empty categories
    $empty = '';
    if (!$params->get('empty_cat')) {
        $empty = "\n HAVING COUNT( b.id ) > 0";
    }
    // get the list of other categories
    $query = "SELECT c.*, COUNT( b.id ) AS numitems" . "\n FROM #__categories AS c" . "\n LEFT JOIN #__content AS b ON b.catid = c.id " . $xwhere2 . ($noauth ? "\n AND b.access <= " . (int) $gid : '') . "\n WHERE c.section = '" . (int) $category->section . "'" . $xwhere . ($noauth ? "\n AND c.access <= " . (int) $gid : '') . "\n GROUP BY c.id" . $empty . "\n ORDER BY c.ordering";
    $database->setQuery($query);
    $other_categories = $database->loadObjectList();
    // get the total number of published items in the category
    // filter functionality
    $and = null;
    if ($params->get('filter')) {
        if ($filter) {
            // clean filter variable
            $filter = strtolower($filter);
            switch ($params->get('filter_type')) {
                case 'title':
                    $and = "\n AND LOWER( a.title ) LIKE '%" . $database->getEscaped($filter, true) . "%'";
                    break;
                case 'author':
                    $and = "\n AND ( ( LOWER( u.name ) LIKE '%" . $database->getEscaped($filter, true) . "%' ) OR ( LOWER( a.created_by_alias ) LIKE '%" . $database->getEscaped($filter, true) . "%' ) )";
                    break;
                case 'hits':
                    $and = "\n AND a.hits LIKE '%" . $database->getEscaped($filter, true) . "%'";
                    break;
            }
        }
    }
    if ($access->canEdit) {
        if ($params->get('unpublished')) {
            // shows unpublished items for publishers and above
            $xwhere = "\n AND a.state >= 0";
        } else {
            // unpublished items NOT shown for publishers and above
            $xwhere = "\n AND a.state = 1";
        }
    } else {
        $xwhere = "\n AND a.state = 1" . "\n AND ( publish_up = " . $database->Quote($nullDate) . " OR publish_up <= " . $database->Quote($now) . " )" . "\n AND ( publish_down = " . $database->Quote($nullDate) . " OR publish_down >= " . $database->Quote($now) . " )";
    }
    // query to determine total number of records
    $query = "SELECT COUNT(a.id) as numitems" . "\n FROM #__content AS a" . "\n LEFT JOIN #__users AS u ON u.id = a.created_by" . "\n LEFT JOIN #__groups AS g ON a.access = g.id" . "\n WHERE a.catid = " . (int) $category->id . $xwhere . ($noauth ? "\n AND a.access <= " . (int) $gid : '') . "\n AND " . (int) $category->access . " <= " . (int) $gid . $and . "\n ORDER BY {$orderby}";
    $database->setQuery($query);
    $counter = $database->loadObjectList();
    $total = $counter[0]->numitems;
    $limit = $limit ? $limit : $params->get('display_num');
    if ($total <= $limit) {
        $limitstart = 0;
    }
    require_once $GLOBALS['mosConfig_absolute_path'] . '/includes/pageNavigation.php';
    $pageNav = new mosPageNav($total, $limitstart, $limit);
    // get the list of items for this category
    $query = "SELECT a.id, a.title, a.hits, a.created_by, a.created_by_alias, a.created AS created, a.access, u.name AS author, a.state, g.name AS groups" . "\n FROM #__content AS a" . "\n LEFT JOIN #__users AS u ON u.id = a.created_by" . "\n LEFT JOIN #__groups AS g ON a.access = g.id" . "\n WHERE a.catid = " . (int) $category->id . $xwhere . ($noauth ? "\n AND a.access <= " . (int) $gid : '') . "\n AND " . (int) $category->access . " <= " . (int) $gid . $and . "\n ORDER BY {$orderby}";
    $database->setQuery($query, $limitstart, $limit);
    $items = $database->loadObjectList();
    $check = 0;
    if ($params->get('date')) {
        $order[] = mosHTML::makeOption('date', _ORDER_DROPDOWN_DA);
        $order[] = mosHTML::makeOption('rdate', _ORDER_DROPDOWN_DD);
        $check .= 1;
    }
    if ($params->get('title')) {
        $order[] = mosHTML::makeOption('alpha', _ORDER_DROPDOWN_TA);
        $order[] = mosHTML::makeOption('ralpha', _ORDER_DROPDOWN_TD);
        $check .= 1;
    }
    if ($params->get('hits')) {
        $order[] = mosHTML::makeOption('hits', _ORDER_DROPDOWN_HA);
        $order[] = mosHTML::makeOption('rhits', _ORDER_DROPDOWN_HD);
        $check .= 1;
    }
    if ($params->get('author')) {
        $order[] = mosHTML::makeOption('author', _ORDER_DROPDOWN_AUA);
        $order[] = mosHTML::makeOption('rauthor', _ORDER_DROPDOWN_AUD);
        $check .= 1;
    }
    $order[] = mosHTML::makeOption('order', _ORDER_DROPDOWN_O);
    $lists['order'] = mosHTML::selectList($order, 'order', 'class="inputbox" size="1"  onchange="document.adminForm.submit();"', 'value', 'text', $selected);
    if ($check < 1) {
        $lists['order'] = '';
        $params->set('order_select', 0);
    }
    $lists['task'] = 'category';
    $lists['filter'] = $filter;
    // remove slashes
    $category->name = stripslashes($category->name);
    // Dynamic Page Title
    $mainframe->SetPageTitle($pagetitle);
    HTML_content::showContentList($category, $items, $access, $id, $sectionid, $gid, $params, $pageNav, $other_categories, $lists, $selected, true);
}