<commit_before><?php
/**
 * @version        $Id$
 * @package        Nooku_Server
 * @subpackage     Articles
 * @copyright      Copyright (C) 2009 - 2012 Timble CVBA and Contributors. (http://www.timble.net)
 * @license        GNU GPLv3 <http://www.gnu.org/licenses/gpl.html>
 * @link           http://www.nooku.org
 */

/**
 * Article controller class.
 *
 * @author     <NAME> <http://nooku.assembla.com/profile/arunasmazeika>
 * @package    Nooku_Server
 * @subpackage Articles
 */
class ComArticlesControllerArticle extends ComArticlesControllerDefault
{
    protected function _initialize(KConfig $config)
    {
        $config->append(array(
            'toolbars'  => array('article'))
        );

        parent::_initialize($config);
    }

    public function setRequest(array $request)
    {
        $view = isset($request['view']) ? $request['view'] : null;

        if ($view && KInflector::isPlural($view))
        {
            if ($request['format'] != 'json')
            {
                $sort_by_map = array(
                    'newest' => array('created_on' => 'DESC'),
                    'oldest' => array('created_on' => 'ASC'),
                    'order'  => array('ordering' => 'ASC'));

                // Get the parameters
                $params = $this->getService('application')->getParams();

                // Force some request vars based on setting parameters.
                $request['limit']     = (int) $params->get('articles_per_page', 10);
                $request['featured']  = (int) $params->get('show_featured', 0);
                $sort_by              = $sort_by_map[$params->get('sort_by', 'newest')];
                $request['sort']      = key($sort_by);
                $request['direction'] = current($sort_by);
            }

            // Allow editors (and above) to view unpublished items on lists.
            if (!$this->canEdit()) {
                $request['published'] = 1;
            }

            //Always show child category articles
            $request['category_recurse'] = true;
        }

        return parent::setRequest($request);
    }

    protected function _actionAdd(KCommandContext $context)
    {
        //Force article to unpublished if you cannot edit
        if (!$this->canEdit()) {
            $context->data->published = 0;
        }

        return parent::_actionAdd($context);
    }
}<commit_msg>Refactored request handling. Synced with framework changes.<commit_after><?php
/**
 * @version        $Id$
 * @package        Nooku_Server
 * @subpackage     Articles
 * @copyright      Copyright (C) 2009 - 2012 Timble CVBA and Contributors. (http://www.timble.net)
 * @license        GNU GPLv3 <http://www.gnu.org/licenses/gpl.html>
 * @link           http://www.nooku.org
 */

/**
 * Article controller class.
 *
 * @author     <NAME> <http://nooku.assembla.com/profile/arunasmazeika>
 * @package    Nooku_Server
 * @subpackage Articles
 */
class ComArticlesControllerArticle extends ComArticlesControllerDefault
{
    protected function _initialize(KConfig $config)
    {
        $config->append(array(
            'toolbars'  => array('article'))
        );

        parent::_initialize($config);
    }

    public function getRequest()
    {
        $request = parent::getRequest();

        $view = $request->query->get('view', 'cmd', null);

        if ($view && KInflector::isPlural($view))
        {
            if ($request->getFormat() != 'json')
            {
                $sort_by_map = array(
                    'newest' => array('created_on' => 'DESC'),
                    'oldest' => array('created_on' => 'ASC'),
                    'order'  => array('ordering' => 'ASC'));

                // Get the parameters
                $params = $this->getService('application')->getParams();

                // Force some request vars based on setting parameters.
                $request->query->limit     = (int) $params->get('articles_per_page', 10);
                $request->query->featured  = (int) $params->get('show_featured', 0);

                $sort_by = $sort_by_map[$params->get('sort_by', 'newest')];
                $request->query->sort = key($sort_by);
                $request->direction   = current($sort_by);
            }

            // Allow editors (and above) to view unpublished items on lists.
            if (!$this->canEdit()) {
                $request->query->published = 1;
            }

            //Always show child category articles
            $request->query->category_recurse = true;
        }

        return $request;
    }

    protected function _actionAdd(KCommandContext $context)
    {
        //Force article to unpublished if you cannot edit
        if (!$this->canEdit()) {
            $context->request->data->set('published', 0);
        }

        return parent::_actionAdd($context);
    }
}
{'fraction_non_alphanumeric': 0.14559308072487645, 'fraction_numerical': 0.005766062602965404, 'mean_word_length': 1.9525835866261398, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 58, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6436942', 'n_tokens_mistral': 1406, 'n_tokens_neox': 1325, 'n_words': 287}