<commit_before><?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/**
 * Name:		Render
 *
 * Description:	Renders a CMS controlled page
 *
 **/

/**
 * OVERLOADING NAILS' AUTH MODULE
 *
 * Note the name of this class; done like this to allow apps to extend this class.
 * Read full explanation at the bottom of this file.
 *
 **/

//	Include _cdn.php; executes common functionality
require_once '_cms.php';

class NAILS_Render extends NAILS_CMS_Controller
{
	protected $_page_id;
	protected $_is_preview;


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


	public function __construct()
	{
		parent::__construct();

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

		$this->load->model( 'cms/cms_page_model', 'cms_page' );

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

		$this->_page_id		= $this->uri->rsegment( 3 );
		$this->_is_preview	= FALSE;
	}


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


	public function page( $preview = FALSE )
	{
		$_page = $this->cms_page->get_by_id( $this->_page_id, TRUE );

		if ( ! $_page || $_page->is_deleted ) :

			show_404();

		endif;

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

		//	If a page is not published, show_404()
		if ( ! $_page->is_published ) :

			if ( ! $this->_is_preview ) :

				show_404();

			endif;

		endif;

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

		//	Determine which data to use
		if ( $this->_is_preview ) :

			$_data = $_page->draft;

		else :

			$_data = $_page->published;

		endif;

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

		//	If the page is the homepage and we're viewing it by slug, then redirect to
		//	the non slugg'd version

		if ( $_page->is_homepage && uri_string() == $_data->slug ) :

			redirect( '', 'location', 301 );

		endif;

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

		//	Set some page level data
		$this->data['page']->title			= $_data->title;
		$this->data['page']->description	= $_data->seo_description;
		$this->data['page']->keywords		= $_data->seo_keywords;

		//	Prepare data
		$_render					= new stdClass();
		$_render->widgets			= isset( $_data->template_data->widget_areas->{$_data->template} ) ? $_data->template_data->widget_areas->{$_data->template} : array();
		$_render->additional_fields	= isset( $_data->template_data->data->additional_fields->{$_data->template} ) ? $_data->template_data->data->additional_fields->{$_data->template} : array();
		//	Decode manual config
		if ( isset( $_render->additional_fields->manual_config ) ) :

			$_render->additional_fields->manual_config = json_decode( $_render->additional_fields->manual_config );

		endif;

		//	Actually render
		$_html	= $this->cms_page->render_template( $_data->template, $_render->widgets, $_render->additional_fields, $this->data );

		$this->output->set_output( $_html );<commit_msg>Adding some additional data for the CMS templates<commit_after><?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/**
 * Name:		Render
 *
 * Description:	Renders a CMS controlled page
 *
 **/

/**
 * OVERLOADING NAILS' AUTH MODULE
 *
 * Note the name of this class; done like this to allow apps to extend this class.
 * Read full explanation at the bottom of this file.
 *
 **/

//	Include _cdn.php; executes common functionality
require_once '_cms.php';

class NAILS_Render extends NAILS_CMS_Controller
{
	protected $_page_id;
	protected $_is_preview;


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


	public function __construct()
	{
		parent::__construct();

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

		$this->load->model( 'cms/cms_page_model', 'cms_page' );

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

		$this->_page_id		= $this->uri->rsegment( 3 );
		$this->_is_preview	= FALSE;
	}


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


	public function page( $preview = FALSE )
	{
		$_page = $this->cms_page->get_by_id( $this->_page_id, TRUE );

		if ( ! $_page || $_page->is_deleted ) :

			show_404();

		endif;

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

		//	If a page is not published, show_404()
		if ( ! $_page->is_published ) :

			if ( ! $this->_is_preview ) :

				show_404();

			endif;

		endif;

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

		//	Determine which data to use
		if ( $this->_is_preview ) :

			$_data = $_page->draft;

		else :

			$_data = $_page->published;

		endif;

		$this->data['page_data'] =& $_data;

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

		//	If the page is the homepage and we're viewing it by slug, then redirect to
		//	the non slugg'd version

		if ( $_page->is_homepage && uri_string() == $_data->slug ) :

			redirect( '', 'location', 301 );

		endif;

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

		//	Set some page level data
		$this->data['page']->id				= $_page->id;
		$this->data['page']->title			= $_data->title;
		$this->data['page']->description	= $_data->seo_description;
		$this->data['page']->keywords		= $_data->seo_keywords;

		//	Prepare data
		$_render					= new stdClass();
		$_render->widgets			= isset( $_data->template_data->widget_areas->{$_data->template} ) ? $_data->template_data->widget_areas->{$_data->template} : array();
		$_render->additional_fields	= isset( $_data->template_data->data->additional_fields->{$_data->template} ) ? $_data->template_data->data->additional_fields->{$_data->template} : array();

		//	Decode manual config
		if ( isset( $_render->additional_fields->manual_config ) ) :

			$_render->additional_fields->manual_config = json_decode( $_render->additional_fields->manual_config );

		endif;

		//	Actually render
		$_html	= $this->cms_page->render_template( $_data->template, $_render->widgets, $_render->additional_fields, $this->data );

		$this->output->set_output( $_html );
{'fraction_non_alphanumeric': 0.3239840637450199, 'fraction_numerical': 0.004143426294820717, 'mean_word_length': 1.68779443254818, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 127, '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': '3499090', 'n_tokens_mistral': 1977, 'n_tokens_neox': 1701, 'n_words': 383}