<commit_before><?php

/**
 * This class renders all the blog pages
 *
 * @package     Nails
 * @subpackage  module-blog
 * @category    Controller
 * @author      Nails Dev Team
 * @link
 */

//  Include _blog.php; executes common functionality
require_once '_blog.php';

class NAILS_Blog extends NAILS_Blog_Controller
{
    public function __construct()
    {
        parent::__construct();

        $this->data['isIndex']    = false;
        $this->data['isSingle']   = false;
        $this->data['isCategory'] = false;
        $this->data['isTag']      = false;
        $this->data['isRss']      = false;

        // --------------------------------------------------------------------------

        $this->data['skinLoadView'] = function ($sSkin, $aData = array()) {

            $this->loadView($sSkin, $aData);
        };
    }

    // --------------------------------------------------------------------------

    /**
     * Browse all posts
     * @return void
     */
    public function index()
    {
        //  Meta & Breadcrumbs
        $this->data['page']->title            = APP_NAME . ' Blog';
        $this->data['page']->seo->description = '';
        $this->data['page']->seo->keywords    = '';

        // --------------------------------------------------------------------------

        //  Handle pagination
        $page      = $this->uri->rsegment(3);
        $perPage  = appSetting('home_per_page', 'blog-' . $this->oBlog->id);
        $perPage  = $perPage ? $perPage : 10;

        $this->data['pagination']           = new stdClass();
        $this->data['pagination']->page     = $page;
        $this->data['pagination']->per_page = $perPage;

        // --------------------------------------------------------------------------

        //  Send any additional data
        $data                    = array();
        $data['include_body']    = !appSetting('use_excerpts', 'blog-' . $this->oBlog->id);
        $data['include_gallery'] = appSetting('home_show_gallery', 'blog-' . $this->oBlog->id);
        $data['sort']            = array('bp.published', 'desc');

        //  Only published items which are not schduled for the future
        $data['where']   = array();
        $data['where'][] = array('column' => 'blog_id',      'value' => $this->oBlog->id);
        $data['where'][] = array('column' => 'is_published', 'value' => true);
        $data['where'][] = array('column' => 'published <=', 'value' => 'NOW()', 'escape' => false);

        // --------------------------------------------------------------------------

        //  Load posts and count
        $this->data['posts'] = $this->blog_post_model->getAll($page, $perPage, $data);
        $this->data['pagination']->total = $this->blog_post_model->countAll($data);

        // --------------------------------------------------------------------------

        //  Widgets
        $this->fetchSidebarWidgets();

        // --------------------------------------------------------------------------

        $this->data['isIndex'] = true;

        // --------------------------------------------------------------------------

        //  Load views
        $this->load->view('structure/header', $this->data);
        $this->loadView('browse', $this->data);
        $this->load->view('structure/footer', $this->data);
    }

    // --------------------------------------------------------------------------

    public function preview()
    {
        $this->blog_post_model->usePreviewTables(true);
        return $this->single($this->uri->rsegment(4), true);
    }

    // --------------------------------------------------------------------------

    /**
     * View a single post
     * @return void
     */
    public function single($id = null, $bIsPreview = false)
    {
        //  Get the single post by its slug
        if ($id) {

            $this->data['post'] = $this->blog_post_model->getById($id);

        } else {

            $this->data['post'] = $this->blog_post_model->getBySlug($this->uri->rsegment(3));
        }

        // --------------------------------------------------------------------------

        //  Check we have something to show, otherwise, bail out
        if (!$this->data['post']) {

            show_404();
        }

        // --------------------------------------------------------------------------

        /**
         * If this post's status is not published then 404, unless logged in as a user
         * with post managing permissions.
         */
        if (!$this->data['post']->is_published || strtotime($this->data['post']->published) > time()) {

            /**
             * This post hasn't been published, or is scheduled. However, check to see
             * if the user has post management permissions.
             */
            if (!userHasPermission('admin:blog:post:' . $this->oBlog->id . ':manage')) {

                show_404();
            }
        }

        // --------------------------------------------------------------------------

        //  Correct URL?
        if (!$bIsPreview && site_url(uri_string()) !== $this->data['post']->url) {

            redirect($this->data['post']->url, 301);
        }

        // --------------------------------------------------------------------------

        //  Widgets
        $this->fetchSidebarWidgets();

        // --------------------------------------------------------------------------

        //  Meta
        $this->data['page']->title  = $this->oBlog->label . ': ';
        $this->data['page']->title .= $this->data['post']->seo_title ? $this->data['post']->seo_title : $this->data['post']->title;
        $this->data['page']->seo->description = $this->data['post']->seo_description;
        $this->data['page']->seo->keywords    = $this->data['post']->seo_keywords;

        // --------------------------------------------------------------------------

        //  Assets<commit_msg>Loading associations for posts<commit_after><?php

/**
 * This class renders all the blog pages
 *
 * @package     Nails
 * @subpackage  module-blog
 * @category    Controller
 * @author      Nails Dev Team
 * @link
 */

//  Include _blog.php; executes common functionality
require_once '_blog.php';

class NAILS_Blog extends NAILS_Blog_Controller
{
    public function __construct()
    {
        parent::__construct();

        $this->data['isIndex']    = false;
        $this->data['isSingle']   = false;
        $this->data['isCategory'] = false;
        $this->data['isTag']      = false;
        $this->data['isRss']      = false;

        // --------------------------------------------------------------------------

        $this->data['skinLoadView'] = function ($sSkin, $aData = array()) {

            $this->loadView($sSkin, $aData);
        };
    }

    // --------------------------------------------------------------------------

    /**
     * Browse all posts
     * @return void
     */
    public function index()
    {
        //  Meta & Breadcrumbs
        $this->data['page']->title            = APP_NAME . ' Blog';
        $this->data['page']->seo->description = '';
        $this->data['page']->seo->keywords    = '';

        // --------------------------------------------------------------------------

        //  Handle pagination
        $page      = $this->uri->rsegment(3);
        $perPage  = appSetting('home_per_page', 'blog-' . $this->oBlog->id);
        $perPage  = $perPage ? $perPage : 10;

        $this->data['pagination']           = new stdClass();
        $this->data['pagination']->page     = $page;
        $this->data['pagination']->per_page = $perPage;

        // --------------------------------------------------------------------------

        //  Send any additional data
        $data                    = array();
        $data['include_body']    = !appSetting('use_excerpts', 'blog-' . $this->oBlog->id);
        $data['include_gallery'] = appSetting('home_show_gallery', 'blog-' . $this->oBlog->id);
        $data['sort']            = array('bp.published', 'desc');

        //  Only published items which are not schduled for the future
        $data['where']   = array();
        $data['where'][] = array('column' => 'blog_id',      'value' => $this->oBlog->id);
        $data['where'][] = array('column' => 'is_published', 'value' => true);
        $data['where'][] = array('column' => 'published <=', 'value' => 'NOW()', 'escape' => false);

        // --------------------------------------------------------------------------

        //  Load posts and count
        $this->data['posts'] = $this->blog_post_model->getAll($page, $perPage, $data);
        $this->data['pagination']->total = $this->blog_post_model->countAll($data);

        // --------------------------------------------------------------------------

        //  Widgets
        $this->fetchSidebarWidgets();

        // --------------------------------------------------------------------------

        $this->data['isIndex'] = true;

        // --------------------------------------------------------------------------

        //  Load views
        $this->load->view('structure/header', $this->data);
        $this->loadView('browse', $this->data);
        $this->load->view('structure/footer', $this->data);
    }

    // --------------------------------------------------------------------------

    public function preview()
    {
        $this->blog_post_model->usePreviewTables(true);
        return $this->single($this->uri->rsegment(4), true);
    }

    // --------------------------------------------------------------------------

    /**
     * View a single post
     * @return void
     */
    public function single($id = null, $bIsPreview = false)
    {
        //  Get the single post by its slug
        if ($id) {

            $this->data['post'] = $this->blog_post_model->getById($id);

        } else {

            $this->data['post'] = $this->blog_post_model->getBySlug($this->uri->rsegment(3));
        }

        // --------------------------------------------------------------------------

        //  Check we have something to show, otherwise, bail out
        if (!$this->data['post']) {

            show_404();
        }

        // --------------------------------------------------------------------------

        /**
         * If this post's status is not published then 404, unless logged in as a user
         * with post managing permissions.
         */
        if (!$this->data['post']->is_published || strtotime($this->data['post']->published) > time()) {

            /**
             * This post hasn't been published, or is scheduled. However, check to see
             * if the user has post management permissions.
             */
            if (!userHasPermission('admin:blog:post:' . $this->oBlog->id . ':manage')) {

                show_404();
            }
        }

        // --------------------------------------------------------------------------

        //  Get associations
        $this->blog_model->getAssociations($this->data['post']->id);

        // --------------------------------------------------------------------------

        //  Correct URL?
        if (!$bIsPreview && site_url(uri_string()) !== $this->data['post']->url) {

            redirect($this->data['post']->url, 301);
        }

        // --------------------------------------------------------------------------

        //  Widgets
        $this->fetchSidebarWidgets();

        // --------------------------------------------------------------------------

        //  Meta
        $this->data['page']->title  = $this->oBlog->label . ': ';
        $this->data['page']->title .= $this->data['post']->seo_title ? $this->data['post']->seo_title : $this->data['post']->title;
        $this->data['page']->seo->description = $this->data['post']->seo_description;
        $this->data['page']->seo->keywords    = $this->data['post']->seo_keywords;

        // --------------------------------------------------------------------------

        //  Assets
{'fraction_non_alphanumeric': 0.3503026283061106, 'fraction_numerical': 0.0028190033993864523, 'mean_word_length': 1.0814495254529768, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 211, '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': '3275368', 'n_tokens_mistral': 3084, 'n_tokens_neox': 2915, 'n_words': 539}