<commit_before><?php

App::uses('AppController', 'Controller');
/**
 * Slides Controller.
 *
 * @property Slide $Slide
 * @property PaginatorComponent $Paginator
 * @property SessionComponent $Session
 */
class SlidesController extends AppController
{
    /**
     * presetVars.
     */
    public $presetVars = array(
        array('field' => 'name', 'type' => 'value'),
        array('field' => 'display_name', 'type' => 'value'),
        array('field' => 'description', 'type' => 'value'),
        array('field' => 'category', 'type' => 'value'),
        array('field' => 'created_f', 'type' => 'value'),
        array('field' => 'created_t', 'type' => 'value'),
    );

    /**
     * uses.
     */
    public $uses = array('Slide', 'User');

    /**
     * SlideProcessing.
     *
     * @var mixed
     */
    public $SlideProcessing;


    /**
     * paginate
     *
     * @var mixed
     */
    public $paginate;

    /**
     * beforeFilter.
     */
    public function beforeFilter()
    {
        $this->Auth->allow('index', 'view', 'update_view', 'download', 'embedded', 'popular', 'latest');
        parent::beforeFilter();
    }

    /**
     * index method.
     */
    public function search()
    {
        $this->set('title_for_layout', __('All Slides'));
        $this->Slide->recursive = 0;

        $this->Prg->commonProcess();

        $add_query = array('Slide.convert_status = ' . SUCCESS_CONVERT_COMPLETED);

        $val = isset($this->passedArgs['created_f']) ? $this->passedArgs['created_f'] : null;
        if (!empty($val)) {
            $add_query[] = "Slide.created >= '" . $val . "'";
        }
        $val = isset($this->passedArgs['created_t']) ? $this->passedArgs['created_t'] : null;
        if (!empty($val)) {
            $add_query[] = "Slide.created <= '" . $val . "'";
        }

        $this->paginate = array(
            'Slide' => array(
                'conditions' => array($this->Slide->parseCriteria($this->passedArgs), $add_query),
                'limit' => 20,
                'recursive' => 2,
                'order' => array('id' => 'desc'),
            ),
        );

        $this->set('slides', $this->Paginator->paginate());
    }

    /**
     * index
     *
     */
    public function index()
    {
        $slides_popular = $this->Slide->find('all', $this->Slide->get_conditions_to_get_popular_slides(8));
        $slides_latest = $this->Slide->find('all', $this->Slide->get_conditions_to_get_latest_slides(8));
        $this->set('slides_popular', $slides_popular);
        $this->set('slides_latest', $slides_latest);
    }

    /**
     * latest
     *
     */
    public function latest()
    {
        $this->set('title_for_layout', __('Latest Slides'));
        $conditions = $this->Slide->get_conditions_to_get_latest_slides(20);

        if ($this->RequestHandler->isRss()) {
            return $this->render_rss($conditions, __('Latest Slides'), __('Latest Slides'));
        }

        $this->Paginator->settings = $conditions;
        $this->set('slides', $this->Paginator->paginate('Slide'));
    }

    /**
     * popular
     *
     */
    public function popular()
    {
        $this->set('title_for_layout', __('Popular Slides'));
        $conditions = $this->Slide->get_conditions_to_get_popular_slides(20);

        if ($this->RequestHandler->isRss()) {
            return $this->render_rss($conditions, __('Popular Slides'), __('Popular Slides'));
        }

        $this->Paginator->settings = $conditions;
        $this->set('slides', $this->Paginator->paginate('Slide'));
    }

    /**
     * render_rss
     *
     * @param array $conditions
     * @param string $title
     * @param string $description
     */
    private function render_rss($conditions = array(), $title = '', $description = '')
    {
        Configure::write('debug', 0);
        $slides = $this->Slide->find('all', $conditions);
        $this->set(compact('slides'));
        $this->set('title', __('Popular Slides'));
        $this->set('description', __('Popular Slides'));
        return $this->render('slide_list');
    }

    /**
     * view method.
     *
     * @throws NotFoundException
     *
     * @param string $id
     */
    public function view($id = null, $display_position = 1)
    {
        $user = $this->Auth->User();
        $user_id = $user['id'];
        $this->set('user_id', $user_id);

        if (!$this->Slide->exists($id)) {
            throw new NotFoundException(__('Invalid slide'));
        }
        $slide = $this->Slide->get_slide($id);
        $this->set('title_for_layout', h($slide['Slide']['name']));
        $this->set('slide', $slide);
        $userinfo = $this->User->read(null, $slide['Slide']['user_id']);
        $this->set('user', $userinfo);

        $file_list = $this->SlideProcessing->get_slide_pages_list($slide['Slide']['key']);
        $this->set('file_list', $file_list);

        if (count($file_list) > $display_position) {
            $start_position = 0;
        } elseif ($display_position <= 0) {
            $start_position = 0;<commit_msg>refactor<commit_after><?php

App::uses('AppController', 'Controller');
/**
 * Slides Controller.
 *
 * @property Slide $Slide
 * @property PaginatorComponent $Paginator
 * @property SessionComponent $Session
 */
class SlidesController extends AppController
{
    /**
     * presetVars.
     */
    public $presetVars = array(
        array('field' => 'name', 'type' => 'value'),
        array('field' => 'display_name', 'type' => 'value'),
        array('field' => 'description', 'type' => 'value'),
        array('field' => 'category', 'type' => 'value'),
        array('field' => 'created_f', 'type' => 'value'),
        array('field' => 'created_t', 'type' => 'value'),
    );

    /**
     * uses.
     */
    public $uses = array('Slide', 'User');

    /**
     * SlideProcessing.
     *
     * @var mixed
     */
    public $SlideProcessing;


    /**
     * paginate
     *
     * @var mixed
     */
    public $paginate;

    /**
     * beforeFilter.
     */
    public function beforeFilter()
    {
        $this->Auth->allow('index', 'view', 'update_view', 'download', 'embedded', 'popular', 'latest');
        parent::beforeFilter();
    }

    /**
     * index method.
     */
    public function search()
    {
        $this->set('title_for_layout', __('All Slides'));
        $this->Slide->recursive = 0;

        $this->Prg->commonProcess();

        $add_query = array('Slide.convert_status = ' . SUCCESS_CONVERT_COMPLETED);

        $val = isset($this->passedArgs['created_f']) ? $this->passedArgs['created_f'] : null;
        if (!empty($val)) {
            $add_query[] = "Slide.created >= '" . $val . "'";
        }
        $val = isset($this->passedArgs['created_t']) ? $this->passedArgs['created_t'] : null;
        if (!empty($val)) {
            $add_query[] = "Slide.created <= '" . $val . "'";
        }

        $this->paginate = array(
            'Slide' => array(
                'conditions' => array($this->Slide->parseCriteria($this->passedArgs), $add_query),
                'limit' => 20,
                'recursive' => 2,
                'order' => array('id' => 'desc'),
            ),
        );

        $this->set('slides', $this->Paginator->paginate());
    }

    /**
     * index
     *
     */
    public function index()
    {
        $slides_popular = $this->Slide->find('all', $this->Slide->get_conditions_to_get_popular_slides(8));
        $slides_latest = $this->Slide->find('all', $this->Slide->get_conditions_to_get_latest_slides(8));
        $this->set('slides_popular', $slides_popular);
        $this->set('slides_latest', $slides_latest);
    }

    /**
     * latest
     *
     */
    public function latest()
    {
        $conditions = $this->Slide->get_conditions_to_get_latest_slides(20);
        return $this->render_slides($conditions, __('Latest Slides'), __('Latest Slides'));
    }

    /**
     * popular
     *
     */
    public function popular()
    {
        $conditions = $this->Slide->get_conditions_to_get_popular_slides(20);
        return $this->render_slides($conditions, __('Popular Slides'), __('Popular Slides'));
    }

    /**
     * render_slides
     *
     * @param array $conditions
     * @param string $title
     * @param string $description
     */
    private function render_slides($conditions = array(), $title = '', $description = '')
    {
        $this->set('title_for_layout', $title);

        if ($this->RequestHandler->isRss()) {
            Configure::write('debug', 0);
            $slides = $this->Slide->find('all', $conditions);
            $this->set(compact('slides'));
            $this->set('title', __('Popular Slides'));
            $this->set('description', __('Popular Slides'));
            return $this->render('slide_list');
        }

        $this->Paginator->settings = $conditions;
        $this->set('slides', $this->Paginator->paginate('Slide'));
    }

    /**
     * view method.
     *
     * @throws NotFoundException
     *
     * @param string $id
     */
    public function view($id = null, $display_position = 1)
    {
        $user = $this->Auth->User();
        $user_id = $user['id'];
        $this->set('user_id', $user_id);

        if (!$this->Slide->exists($id)) {
            throw new NotFoundException(__('Invalid slide'));
        }
        $slide = $this->Slide->get_slide($id);
        $this->set('title_for_layout', h($slide['Slide']['name']));
        $this->set('slide', $slide);
        $userinfo = $this->User->read(null, $slide['Slide']['user_id']);
        $this->set('user', $userinfo);

        $file_list = $this->SlideProcessing->get_slide_pages_list($slide['Slide']['key']);
        $this->set('file_list', $file_list);

        if (count($file_list) > $display_position) {
            $start_position = 0;
        } elseif ($display_position <= 0) {
            $start_position = 0;
{'fraction_non_alphanumeric': 0.1916826486322802, 'fraction_numerical': 0.003028161905723226, 'mean_word_length': 2.342780026990553, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 177, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3849826', 'n_tokens_mistral': 3164, 'n_tokens_neox': 3082, 'n_words': 503}