<commit_before><?php
namespace Concrete\Controller\Search;


use Concrete\Core\Controller\AbstractController;
use Concrete\Core\Entity\Search\Query;
use Concrete\Core\File\FileList;
use Concrete\Core\File\Filesystem;
use Concrete\Core\File\FolderItemList;
use Concrete\Core\File\Search\ColumnSet\FolderSet;
use Concrete\Core\File\Search\Result\Result;
use Concrete\Core\Search\Field\FieldInterface;
use Concrete\Core\Search\Field\ManagerFactory;
use Concrete\Core\Search\ItemList\Pager\PagerProviderInterface;
use Concrete\Core\Search\StickyRequest;
use Concrete\Core\Tree\Node\Node;
use Concrete\Core\Tree\Node\Type\SearchPreset;
use Symfony\Component\HttpFoundation\JsonResponse;

class FileFolder extends AbstractController
{
    protected $list;
    protected $result;
    protected $filesystem;

    public function __construct()
    {
        parent::__construct();
        $this->filesystem = new Filesystem();
    }

    public function search(Query $query = null)
    {
        $searchRequest = new StickyRequest('file_manager_folder');

        if ($this->request->get('folder')) {
            $searchRequest->resetSearchRequest();
            $node = Node::getByID($this->request->get('folder'));
            if (is_object($node) &&
                ($node instanceof \Concrete\Core\Tree\Node\Type\FileFolder ||
                    $node instanceof SearchPreset)) {
                    $folder = $node;
            }
        } else {
            $req = $searchRequest->getSearchRequest();
            if (isset($req['folder'])) {
                $node = Node::getByID($req['folder']);
                if (is_object($node) &&
                    ($node instanceof \Concrete\Core\Tree\Node\Type\FileFolder ||
                        $node instanceof SearchPreset)) {
                    $folder = $node;
                }
            }
        }

        if (isset($folder)) {

            if ($folder instanceof SearchPreset) {
                $search = $folder->getSavedSearchObject();
                $query = $search->getQuery();
                $provider = \Core::make('Concrete\Core\File\Search\SearchProvider');
                $ilr = $provider->getSearchResultFromQuery($query);
                $ilr->setBaseURL(\URL::to('/ccm/system/search/files/preset', $search->getID()));
            }

            $searchRequest->addToSearchRequest('folder', $folder->getTreeNodeID());

        }

        if (!isset($ilr)) {

            if (!isset($folder)) {
                $folder = $this->filesystem->getRootFolder();
            }
            $u = new \User();
            $list = $folder->getFolderItemList($u, $this->request);
            $fields = $this->request->get('field');
            $filters = array();
            if (count($fields)) { // We are passing in something like "filter by images"
                $manager = ManagerFactory::get('file_folder');
                $filters = $manager->getFieldsFromRequest($this->request->query->all());
            }

            if (count($filters)) {
                /**
                 * @var $field FieldInterface
                 */
                foreach($filters as $field) {
                    $field->filterList($list);
                }
            }

            $columns = new FolderSet();

            $list->disableAutomaticSorting(); // We don't need the automatic sorting found in the item list. it fires too late.
            $data = $this->request->query->all();

            if (!$list->getActiveSortColumn()) {
                $column = $columns->getDefaultSortColumn();
                $list->sortBySearchColumn($column);
            }

            if (isset($data[$list->getQuerySortColumnParameter()])) {
                $value = $data[$list->getQuerySortColumnParameter()];
                $sortColumn = $columns->getColumnByKey($value);

                if (isset($data[$list->getQuerySortDirectionParameter()])) {
                    $direction = $data[$list->getQuerySortDirectionParameter()];
                } else{
                    $direction = $sortColumn->getColumnDefaultSortDirection();
                }

                $sortColumn->setColumnSortDirection($direction);
                $list->sortBySearchColumn($sortColumn, $direction);
            }

            if ($list instanceof PagerProviderInterface) {
                $manager = $list->getPagerManager();
                $manager->sortListByCursor($list, $list->getActiveSortDirection());
            }
<commit_msg>better checking for invalid search columns<commit_after><?php
namespace Concrete\Controller\Search;


use Concrete\Core\Controller\AbstractController;
use Concrete\Core\Entity\Search\Query;
use Concrete\Core\File\FileList;
use Concrete\Core\File\Filesystem;
use Concrete\Core\File\FolderItemList;
use Concrete\Core\File\Search\ColumnSet\FolderSet;
use Concrete\Core\File\Search\Result\Result;
use Concrete\Core\Search\Field\FieldInterface;
use Concrete\Core\Search\Field\ManagerFactory;
use Concrete\Core\Search\ItemList\Pager\PagerProviderInterface;
use Concrete\Core\Search\StickyRequest;
use Concrete\Core\Tree\Node\Node;
use Concrete\Core\Tree\Node\Type\SearchPreset;
use Symfony\Component\HttpFoundation\JsonResponse;

class FileFolder extends AbstractController
{
    protected $list;
    protected $result;
    protected $filesystem;

    public function __construct()
    {
        parent::__construct();
        $this->filesystem = new Filesystem();
    }

    public function search(Query $query = null)
    {
        $searchRequest = new StickyRequest('file_manager_folder');

        if ($this->request->get('folder')) {
            $searchRequest->resetSearchRequest();
            $node = Node::getByID($this->request->get('folder'));
            if (is_object($node) &&
                ($node instanceof \Concrete\Core\Tree\Node\Type\FileFolder ||
                    $node instanceof SearchPreset)) {
                    $folder = $node;
            }
        } else {
            $req = $searchRequest->getSearchRequest();
            if (isset($req['folder'])) {
                $node = Node::getByID($req['folder']);
                if (is_object($node) &&
                    ($node instanceof \Concrete\Core\Tree\Node\Type\FileFolder ||
                        $node instanceof SearchPreset)) {
                    $folder = $node;
                }
            }
        }

        if (isset($folder)) {

            if ($folder instanceof SearchPreset) {
                $search = $folder->getSavedSearchObject();
                $query = $search->getQuery();
                $provider = \Core::make('Concrete\Core\File\Search\SearchProvider');
                $ilr = $provider->getSearchResultFromQuery($query);
                $ilr->setBaseURL(\URL::to('/ccm/system/search/files/preset', $search->getID()));
            }

            $searchRequest->addToSearchRequest('folder', $folder->getTreeNodeID());

        }

        if (!isset($ilr)) {

            if (!isset($folder)) {
                $folder = $this->filesystem->getRootFolder();
            }
            $u = new \User();
            $list = $folder->getFolderItemList($u, $this->request);
            $fields = $this->request->get('field');
            $filters = array();
            if (count($fields)) { // We are passing in something like "filter by images"
                $manager = ManagerFactory::get('file_folder');
                $filters = $manager->getFieldsFromRequest($this->request->query->all());
            }

            if (count($filters)) {
                /**
                 * @var $field FieldInterface
                 */
                foreach($filters as $field) {
                    $field->filterList($list);
                }
            }

            $columns = new FolderSet();

            $list->disableAutomaticSorting(); // We don't need the automatic sorting found in the item list. it fires too late.
            $data = $this->request->query->all();

            if (!$list->getActiveSortColumn()) {
                $column = $columns->getDefaultSortColumn();
                $list->sortBySearchColumn($column);
            }

            if (isset($data[$list->getQuerySortColumnParameter()])) {
                $value = $data[$list->getQuerySortColumnParameter()];
                $sortColumn = $columns->getColumnByKey($value);

                if (isset($data[$list->getQuerySortDirectionParameter()])) {
                    $direction = $data[$list->getQuerySortDirectionParameter()];
                } else{
                    $direction = $sortColumn->getColumnDefaultSortDirection();
                }

                if ($sortColumn) {
                    $sortColumn->setColumnSortDirection($direction);
                    $list->sortBySearchColumn($sortColumn, $direction);
                }
            }

            if ($list instanceof PagerProviderInterface) {
                $manager = $list->getPagerManager();
                $manager->sortListByCursor($list, $list->getActiveSortDirection());
            }

{'fraction_non_alphanumeric': 0.13494694960212203, 'fraction_numerical': 0.0, 'mean_word_length': 1.9963576158940397, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 89, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '5440222', 'n_tokens_mistral': 2384, 'n_tokens_neox': 2278, 'n_words': 399}