<commit_before><?php

App::uses('FrontendController', 'Controller');

/**
 * BlogPostsController
 *
 * FoodCoopShop - The open source software for your foodcoop
 *
 * Licensed under The MIT License
 * For full copyright and license information, please see the LICENSE.txt
 * Redistributions of files must retain the above copyright notice.
 *
 * @since         FoodCoopShop 1.0.0
 * @license       http://www.opensource.org/licenses/mit-license.php MIT License
 * @author        <NAME> <<EMAIL>>
 * @copyright     Copyright (c) <NAME>, http://www.rothauer-it.com
 * @link          https://www.foodcoopshop.com
 */
class BlogPostsController extends FrontendController
{

    public function beforeFilter()
    {

        parent::beforeFilter();

        switch ($this->action) {
            case 'detail':
                $blogPostId = (int) $this->params['pass'][0];
                $blogPost = $this->BlogPost->find('first', array(
                    'conditions' => array(
                        'BlogPost.id_smart_blog_post' => $blogPostId,
                        'BlogPost.active' => APP_ON
                    )
                ));
                if (!empty($blogPost) && !$this->AppAuth->loggedIn()
                    && ($blogPost['BlogPost']['is_private'] || (isset($blogPost['Manufacturer']) && $blogPost['Manufacturer']['is_private']))
                    ) {
                        $this->AppAuth->deny($this->action);
                }
                break;
        }
    }

    public function detail()
    {
        $blogPostId = (int) $this->params['pass'][0];

        $conditions = array(
            'BlogPost.active' => APP_ON,
            'BlogPostLang.id_lang' => Configure::read('app.langId'),
            'BlogPostShop.id_shop' => Configure::read('app.shopId')
        );
        $conditions['BlogPost.id_smart_blog_post'] = $blogPostId; // needs to be last element of conditions

        $blogPost = $this->BlogPost->find('first', array(
            'conditions' => $conditions
        ));

        if (empty($blogPost)) {
            throw new MissingActionException('blogPost not found');
        }

        $correctSlug = Configure::read('slugHelper')->getBlogPostDetail($blogPostId, $blogPost['BlogPostLang']['meta_title']);
        if ($correctSlug != Configure::read('slugHelper')->getBlogPostDetail($blogPostId, StringComponent::removeIdFromSlug($this->params['pass'][0]))) {
            $this->redirect($correctSlug);
        }

        $this->set('blogPost', $blogPost);

        array_pop($conditions); // do not filter last condition element blogPostId
        $neighbors = $this->BlogPost->find('neighbors', array(
            'field' => 'BlogPost.modified',
            'value' => $blogPost['BlogPost']['modified'],
            'conditions' => $conditions,
            'order' => array(
                'BlogPost.modified' => 'DESC'
            )
        ));
        $this->set('neighbors', $neighbors);

        $this->set('title_for_layout', $blogPost['BlogPostLang']['meta_title']);
    }

    public function index()
    {
        $conditions = array(
            'BlogPost.active' => APP_ON,
            'BlogPostLang.id_lang' => Configure::read('app.langId'),
            'BlogPostShop.id_shop' => Configure::read('app.shopId')
        );

        if (isset($this->params['manufacturerSlug'])) {
            $manufacturerId = (int) $this->params['manufacturerSlug'];
            $this->loadModel('Manufacturer');
            $this->Manufacturer->recursive = 1;
            $manufacturer = $this->Manufacturer->find('first', array(
                'conditions' => array(<commit_msg>prev/next blog posts were not checked for is_private<commit_after><?php

App::uses('FrontendController', 'Controller');

/**
 * BlogPostsController
 *
 * FoodCoopShop - The open source software for your foodcoop
 *
 * Licensed under The MIT License
 * For full copyright and license information, please see the LICENSE.txt
 * Redistributions of files must retain the above copyright notice.
 *
 * @since         FoodCoopShop 1.0.0
 * @license       http://www.opensource.org/licenses/mit-license.php MIT License
 * @author        <NAME> <<EMAIL>>
 * @copyright     Copyright (c) <NAME>, http://www.rothauer-it.com
 * @link          https://www.foodcoopshop.com
 */
class BlogPostsController extends FrontendController
{

    public function beforeFilter()
    {

        parent::beforeFilter();

        switch ($this->action) {
            case 'detail':
                $blogPostId = (int) $this->params['pass'][0];
                $blogPost = $this->BlogPost->find('first', array(
                    'conditions' => array(
                        'BlogPost.id_smart_blog_post' => $blogPostId,
                        'BlogPost.active' => APP_ON
                    )
                ));
                if (!empty($blogPost) && !$this->AppAuth->loggedIn()
                    && ($blogPost['BlogPost']['is_private'] || (isset($blogPost['Manufacturer']) && $blogPost['Manufacturer']['is_private']))
                    ) {
                        $this->AppAuth->deny($this->action);
                }
                break;
        }
    }

    public function detail()
    {
        $blogPostId = (int) $this->params['pass'][0];

        $conditions = array(
            'BlogPost.active' => APP_ON,
            'BlogPostLang.id_lang' => Configure::read('app.langId'),
            'BlogPostShop.id_shop' => Configure::read('app.shopId')
        );
        $conditions['BlogPost.id_smart_blog_post'] = $blogPostId; // needs to be last element of conditions

        $blogPost = $this->BlogPost->find('first', array(
            'conditions' => $conditions
        ));

        if (empty($blogPost)) {
            throw new MissingActionException('blogPost not found');
        }

        $correctSlug = Configure::read('slugHelper')->getBlogPostDetail($blogPostId, $blogPost['BlogPostLang']['meta_title']);
        if ($correctSlug != Configure::read('slugHelper')->getBlogPostDetail($blogPostId, StringComponent::removeIdFromSlug($this->params['pass'][0]))) {
            $this->redirect($correctSlug);
        }

        $this->set('blogPost', $blogPost);

        // START find neighbors
        array_pop($conditions); // do not filter last condition element blogPostId
        if (!$this->AppAuth->loggedIn()) {
            $conditions['BlogPost.is_private'] = APP_OFF;
            $conditions[] = '(Manufacturer.is_private IS NULL OR Manufacturer.is_private = ' . APP_OFF.')';
        }
        $neighbors = $this->BlogPost->find('neighbors', array(
            'field' => 'BlogPost.modified',
            'value' => $blogPost['BlogPost']['modified'],
            'conditions' => $conditions,
            'order' => array(
                'BlogPost.modified' => 'DESC'
            )
        ));
        $this->set('neighbors', $neighbors);

        $this->set('title_for_layout', $blogPost['BlogPostLang']['meta_title']);
    }

    public function index()
    {
        $conditions = array(
            'BlogPost.active' => APP_ON,
            'BlogPostLang.id_lang' => Configure::read('app.langId'),
            'BlogPostShop.id_shop' => Configure::read('app.shopId')
        );

        if (isset($this->params['manufacturerSlug'])) {
            $manufacturerId = (int) $this->params['manufacturerSlug'];
            $this->loadModel('Manufacturer');
            $this->Manufacturer->recursive = 1;
            $manufacturer = $this->Manufacturer->find('first', array(
                'conditions' => array(
{'fraction_non_alphanumeric': 0.1539989406779661, 'fraction_numerical': 0.001853813559322034, 'mean_word_length': 2.272530329289428, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 101, 'https://': 2, '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': '7200952', 'n_tokens_mistral': 2199, 'n_tokens_neox': 2076, 'n_words': 378}