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

class Pages extends Front_Controller {

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

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

	//--------------------------------------------------------------------
	
	/*
		Remaps everything to flow into the index method. 
	*/
	public function _remap() 
	{
		$this->index();
	}
	
	//--------------------------------------------------------------------

	/*
		Method: index()
		
		Loads and displays the page.	
	*/
	public function index() 
	{		
		global $OUT;
		$output = null;
		$alias = $this->uri->uri_string();
		
		// Are we displaying the home page? 
		if (empty($alias))
		{
			$alias = config_item('pages.home_page_alias');
			
			if (empty($alias))
			{
				show_404();
			}
		}
	
		// Try to get it from the cache
		$page = $this->cache->get('pages_'. $alias);
		
		// No cache? Then get it from the db
		if ($page == false)
		{  
			$page = $this->get_page($alias);
			
			// Render the page.
			Template::set('body_content', $page->body);
			Template::render();
			
			$output = $OUT->get_output();
			
			// If set, cache this bad boy.
			if ($page->cacheable)
			{ 	
				$this->cache->save('pages_'. $alias, $output, 60*60*24*365);	// 365 days - is deleted on page update.
			}
		}
		
		// Render the output
		if (empty($output) && $page != false)
		{ 
			$output = $page;
		}
		
		$OUT->set_output($output);
		
		// Should we track page hits?
		if (config_item('pages.track_hits'))
		{
			$this->track_hit(null, $alias);
		}
	}
	
	//--------------------------------------------------------------------
	
	//--------------------------------------------------------------------
	// !PRIVATE METHODS
	//--------------------------------------------------------------------
	
	/*
		Method: get_page()
	
		Retrieves the page from the database, check permissions,
		process the document according to rte_type.
		
		Parameters:
			$alias	- the alias to find.
			
		Return:
			A stdObject with all of the page details.
	*/
	private function get_page($alias=null) 
	{
		if (empty($alias))
		{
			return false;
		}
		
		$this->load->model('Page_model', 'page_model', true);
		
		$message = '';
		
		// Find the page in the database that matches the alias
		$page = $this->page_model->find_by('alias', $alias);
		
		if (is_array($page))
		{
			$page = $page[0];
		}
		
		// If the user can manage pages, show the page, whether it's 
		// published or note.
		$today = date('Y-m-d H:i:s', time());
		if ($page->published == 0 || $page->pub_date > $today || $page->unpub_date < $today)
		{ 
			if (has_permission('Bonfire.Pages.Manage'))
			{
				$message = Template::message('This page is <b>not published</b>.', 'attention');
			} else
			{
				show_404();
			}
		}
		
		
		switch ($page->rte_type)
		{
			case 'html':
				$this->load->helper('typography');
				$page->body = auto_typography($page->body);
				break;
			case 'markdown':<commit_msg>Fixed published check in pages controller<commit_after><?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Pages extends Front_Controller {

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

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

	//--------------------------------------------------------------------
	
	/*
		Remaps everything to flow into the index method. 
	*/
	public function _remap() 
	{
		$this->index();
	}
	
	//--------------------------------------------------------------------

	/*
		Method: index()
		
		Loads and displays the page.	
	*/
	public function index() 
	{		
		global $OUT;
		$output = null;
		$alias = $this->uri->uri_string();
		
		// Are we displaying the home page? 
		if (empty($alias))
		{
			$alias = config_item('pages.home_page_alias');
			
			if (empty($alias))
			{
				show_404();
			}
		}
	
		// Try to get it from the cache
		$page = $this->cache->get('pages_'. $alias);
		
		// No cache? Then get it from the db
		if ($page == false)
		{  
			$page = $this->get_page($alias);
			
			// Render the page.
			Template::set('body_content', $page->body);
			Template::render();
			
			$output = $OUT->get_output();
			
			// If set, cache this bad boy.
			if ($page->cacheable)
			{ 	
				$this->cache->save('pages_'. $alias, $output, 60*60*24*365);	// 365 days - is deleted on page update.
			}
		}
		
		// Render the output
		if (empty($output) && $page != false)
		{ 
			$output = $page;
		}
		
		$OUT->set_output($output);
		
		// Should we track page hits?
		if (config_item('pages.track_hits'))
		{
			$this->track_hit(null, $alias);
		}
	}
	
	//--------------------------------------------------------------------
	
	//--------------------------------------------------------------------
	// !PRIVATE METHODS
	//--------------------------------------------------------------------
	
	/*
		Method: get_page()
	
		Retrieves the page from the database, check permissions,
		process the document according to rte_type.
		
		Parameters:
			$alias	- the alias to find.
			
		Return:
			A stdObject with all of the page details.
	*/
	private function get_page($alias=null) 
	{
		if (empty($alias))
		{
			return false;
		}
		
		$this->load->model('Page_model', 'page_model', true);
		
		$message = '';
		
		// Find the page in the database that matches the alias
		$page = $this->page_model->find_by('alias', $alias);
		
		if (is_array($page))
		{
			$page = $page[0];
		}
		
		// If the user can manage pages, show the page, whether it's 
		// published or note.
		$today = date('Y-m-d H:i:s', time());
		if ($page->published == 0 || ($page->published == 1 && ($page->pub_date > $today || ($page->unpub_date != '0000-00-00 00:00:00' && $page->unpub_date < $today))))
		{ 
			if (has_permission('Bonfire.Pages.Manage'))
			{
				$message = Template::message('This page is <b>not published</b>.', 'attention');
			} else
			{
				show_404();
			}
		}
		
		
		switch ($page->rte_type)
		{
			case 'html':
				$this->load->helper('typography');
				$page->body = auto_typography($page->body);
				break;
			case 'markdown':
{'fraction_non_alphanumeric': 0.27986348122866894, 'fraction_numerical': 0.008938729075247847, 'mean_word_length': 1.6908613904678618, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 61, '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': '5394098', 'n_tokens_mistral': 2316, 'n_tokens_neox': 1853, 'n_words': 475}