<commit_before><?php

/**
 * Habari ThemeHandler Class
 *
 * Requires PHP 5.0.4 or later
 * @package Habari
 */

// TODO: Make this not use a specific theme
define('THEME_DIR', HABARI_PATH . '/themes/k2/');
//define('THEME_DIR', HABARI_PATH . '/themes/so-fresh/');
class ThemeHandler extends ActionHandler
{

	/**
	 * function __call
	 * Handles all calls to this class for methods that don't exist.
	 * In this class, method names correlated with action names set in the URL rules.
	 * Throws an execption if the requested action isn't valid.
	 * @param string The action that was called.
	 * @param array Settings passed in from the URL
	 **/	 	 
	public function __call($action, $settings) {
		global $url, $theme;
	
		// What this handler handles and how
		$handle = array(
			'post'=>'post.php', 
			'home'=>'index.php',
			'login'=>'login.php',
			'logout'=>'login.php',
		);
		
		$theme = new ThemeEngine();
	
		if(isset($handle[$action])) {
			$potential_template = THEME_DIR . $handle[$action];
			if(file_exists($potential_template)) {
				include $potential_template;
			}
		}
		else {
			throw new Exception("ThemeHandler does not handle the action {$action}.");
		}<commit_msg>Added basic error handling to ThemeHandler for requests for posts that  don't exist.  An error.php file will be used when a requested post does  not exist.  A basic error.php has been added to the k2 theme.<commit_after><?php

/**
 * Habari ThemeHandler Class
 *
 * Requires PHP 5.0.4 or later
 * @package Habari
 */

// TODO: Make this not use a specific theme
define('THEME_DIR', HABARI_PATH . '/themes/k2/');
//define('THEME_DIR', HABARI_PATH . '/themes/so-fresh/');
class ThemeHandler extends ActionHandler
{

	/**
	 * function __call
	 * Handles all calls to this class for methods that don't exist.
	 * In this class, method names correlated with action names set in the URL rules.
	 * Throws an execption if the requested action isn't valid.
	 * @param string The action that was called.
	 * @param array Settings passed in from the URL
	 **/	 	 
	public function __call($action, $settings) {
		global $url, $theme;
	
		// What this handler handles and how
		$handle = array(
			'post'=>'post.php', 
			'home'=>'index.php',
			'login'=>'login.php',
			'logout'=>'login.php',
			'error'=>'error.php',
		);
		
		$theme = new ThemeEngine();

		if(isset($handle[$action])) {
			$potential_template = THEME_DIR . $handle[$action];
			// is this a request for a single post?
			if ( 'post' == $action )
			{
				// let's see if that post actually exists
				if ( $post = Post::get() )
				{
					$potential_template = THEME_DIR . $post->slug . '.php';
					if ( ! file_exists($potential_template) )
					{
						// no specific file, so use default
						$potential_template = THEME_DIR . $handle[$action];
					}
				}
				else
				{
					// no such post -- display the error page
					$action = 'error';
					$potential_template = THEME_DIR . $handle[$action];
				}
			}
			if(file_exists($potential_template)) {
				include $potential_template;
			}
		}
		else {
			throw new Exception("ThemeHandler does not handle the action {$action}.");
		}
{'fraction_non_alphanumeric': 0.13065646908859146, 'fraction_numerical': 0.0028680688336520078, 'mean_word_length': 3.157615894039735, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, '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': '3816873', 'n_tokens_mistral': 1130, 'n_tokens_neox': 959, 'n_words': 323}