Example #1
0
File: content.php Project: cwcw/cms
function showArchiveCategory($id = 0, $gid, &$access, $pop, $option, $now)
{
    global $database, $mainframe, $mosConfig_offset;
    global $Itemid;
    // Parameters
    $noauth = !$mainframe->getCfg('shownoauth');
    $year = mosGetParam($_REQUEST, 'year', date('Y'));
    $month = mosGetParam($_REQUEST, 'month', date('m'));
    $module = trim(mosGetParam($_REQUEST, 'module', ''));
    // used by archive module
    if ($module) {
        $check = '';
    } else {
        $check = 'AND a.catid = ' . $id;
    }
    if ($Itemid) {
        $menu = new mosMenu($database);
        $menu->load($Itemid);
        $params =& new mosParameters($menu->params);
    } else {
        $menu = "";
        $params =& new mosParameters('');
    }
    $params->set('year', $year);
    $params->set('month', $month);
    // Ordering control
    $orderby_sec = $params->def('orderby', 'rdate');
    $order_sec = _orderby_sec($orderby_sec);
    // used in query
    $where = _where(-2, $access, $noauth, $gid, $id, NULL, $year, $month);
    // query to determine if there are any archived entries for the category
    $query = "SELECT a.id" . "\n FROM #__content as a" . "\n WHERE a.state = '-1'" . "\n " . $check;
    $database->setQuery($query);
    $items = $database->loadObjectList();
    $archives = count($items);
    $query = "SELECT a.*, ROUND( v.rating_sum / v.rating_count ) AS rating, v.rating_count, u.name AS author, u.usertype, s.name AS section, g.name AS groups" . "\n FROM #__content AS a" . "\n LEFT JOIN #__users AS u ON u.id = a.created_by" . "\n LEFT JOIN #__content_rating AS v ON a.id = v.content_id" . "\n LEFT JOIN #__sections AS s ON a.sectionid = s.id" . "\n LEFT JOIN #__groups AS g ON a.access = g.id" . (count($where) ? "\n WHERE " . implode("\n AND ", $where) : '') . "\n AND s.access <= " . $gid . "\n ORDER BY " . $order_sec;
    $database->setQuery($query);
    $rows = $database->loadObjectList();
    // initiate form
    echo '<form action="' . sefRelToAbs('index.php?option=' . $option . '&amp;task=archivecategory&amp;id=' . $id . '&amp;Itemid=' . $Itemid) . '" method="post">';
    // Page Title
    $mainframe->SetPageTitle($menu->name);
    if (!$archives) {
        // if no archives for category, hides search and outputs empty message
        echo '<br /><div align="center">' . _CATEGORY_ARCHIVE_EMPTY . '</div>';
    } else {
        BlogOutput($rows, $params, $gid, $access, $pop, $menu, 1);
    }
    echo '</form>';
}
Example #2
0
function showItem($uid, $gid, &$access, $pop, $option = 'com_content', $now)
{
    global $database, $mainframe, $Itemid;
    global $mosConfig_MetaTitle, $mosConfig_MetaAuthor;
    $now = _CURRENT_SERVER_TIME;
    $nullDate = $database->getNullDate();
    if ($access->canEdit) {
        $xwhere = '';
    } else {
        $xwhere = " AND ( a.state = 1 OR a.state = -1 )" . "\n AND ( a.publish_up = " . $database->Quote($nullDate) . " OR a.publish_up <= " . $database->Quote($now) . " )" . "\n AND ( a.publish_down = " . $database->Quote($nullDate) . " OR a.publish_down >= " . $database->Quote($now) . " )";
    }
    // main query
    $query = "SELECT a.*, u.name AS author, u.usertype, cc.name AS category, s.name AS section, g.name AS groups," . "\n s.published AS sec_pub, cc.published AS cat_pub, s.access AS sec_access, cc.access AS cat_access," . "\n s.id AS sec_id, cc.id as cat_id" . "\n FROM #__content AS a" . "\n LEFT JOIN #__categories AS cc ON cc.id = a.catid" . "\n LEFT JOIN #__sections AS s ON s.id = cc.section AND s.scope = 'content'" . "\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.id = " . (int) $uid . $xwhere . "\n AND a.access <= " . (int) $gid;
    $database->setQuery($query);
    $row = NULL;
    if ($database->loadObject($row)) {
        /*
         * check whether category is published
         */
        if (!$row->cat_pub && $row->catid) {
            mosNotAuth();
            return;
        }
        /*
         * check whether section is published
         */
        if (!$row->sec_pub && $row->sectionid) {
            mosNotAuth();
            return;
        }
        /*
         * check whether category access level allows access
         */
        if ($row->cat_access > $gid && $row->catid) {
            mosNotAuth();
            return;
        }
        /*
         * check whether section access level allows access
         */
        if ($row->sec_access > $gid && $row->sectionid) {
            mosNotAuth();
            return;
        }
        $params = new mosParameters($row->attribs);
        $params->set('intro_only', 0);
        $params->def('back_button', $mainframe->getCfg('back_button'));
        if ($row->sectionid == 0) {
            $params->set('item_navigation', 0);
        } else {
            $params->set('item_navigation', $mainframe->getCfg('item_navigation'));
        }
        // loads the links for Next & Previous Button
        if ($params->get('item_navigation')) {
            // Paramters for menu item as determined by controlling Itemid
            $menu = $mainframe->get('menu');
            $mparams = new mosParameters($menu->params);
            // the following is needed as different menu items types utilise a different param to control ordering
            // for Blogs the `orderby_sec` param is the order controlling param
            // for Table and List views it is the `orderby` param
            $mparams_list = $mparams->toArray();
            if (array_key_exists('orderby_sec', $mparams_list)) {
                $order_method = $mparams->get('orderby_sec', '');
            } else {
                $order_method = $mparams->get('orderby', '');
            }
            // additional check for invalid sort ordering
            if ($order_method == 'front') {
                $order_method = '';
            }
            $orderby = _orderby_sec($order_method);
            // array of content items in same category correctly ordered
            $query = "SELECT a.id" . "\n FROM #__content AS a" . "\n WHERE a.catid = " . (int) $row->catid . "\n AND a.state = " . (int) $row->state . ($access->canEdit ? '' : "\n AND a.access <= " . (int) $gid) . $xwhere . "\n ORDER BY {$orderby}";
            $database->setQuery($query);
            $list = $database->loadResultArray();
            // this check needed if incorrect Itemid is given resulting in an incorrect result
            if (!is_array($list)) {
                $list = array();
            }
            // location of current content item in array list
            $location = array_search($uid, $list);
            $row->prev = '';
            $row->next = '';
            if ($location - 1 >= 0) {
                // the previous content item cannot be in the array position -1
                $row->prev = $list[$location - 1];
            }
            if ($location + 1 < count($list)) {
                // the next content item cannot be in an array position greater than the number of array postions
                $row->next = $list[$location + 1];
            }
        }
        // page title
        $mainframe->setPageTitle($row->title);
        if ($mosConfig_MetaTitle == '1') {
            $mainframe->addMetaTag('title', $row->title);
        }
        if ($mosConfig_MetaAuthor == '1') {
            $mainframe->addMetaTag('author', $row->author);
        }
        show($row, $params, $gid, $access, $pop);
    } else {
        mosNotAuth();
        return;
    }
}