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

class Page extends CI_Controller {
	
	public function __construct() {
		parent::__construct();
		$this->load->library('ion_auth');
		$this->load->library('form_validation');
		$this->load->helper('text');
		$this->load->model('settings_model');
		$this->load->model('pages_model');
		$this->load->model('assets_model');
		$this->load->model('attributes_model');
		$this->load->model('options_model');
		
		$this->lang->load('storyengine');
	}
	
	public function index() {
		// If not logged in redirect to login page
		if (!$this->ion_auth->logged_in()) { redirect('story/login', 'refresh'); }
		
		// Redirect to start page
		$start_page = $this->settings_model->get_value('start_page');
		redirect('page/show/'.$start_page);
	}
	
	public function show($id) {
		if (!$this->ion_auth->logged_in()) { redirect('story/login', 'refresh'); }
		
		// TODO: Implement page handling
		// TODO: Achievemnt unlocking
		$this->data['page'] = $this->pages_model->get($id);
		$this->data['image'] = $this->assets_model->get_page_image($this->data['page']['image']);
		
		// Apply consequences (story_page_consequences)
		$consequences = $this->pages_model->get_consequences($id);
		foreach ($consequences as $consequence) {
			$attribute = $consequence['attribute'];
			$value = $this->attributes_model->get_for_user($this->ion_auth->user()->row()->id, $attribute);
			$value = $value['value'];
			$operator = $consequence['operator'];
			$consequence_value = $consequence['value'];
			
			switch ($operator) {
				case 1: // +=
					$value += $consequence_value; break;
				case 2: // -=
					$value -= $consequence_value; break;
				case 3: // =
					$value = $consequence_value; break;
			}
			
			// Apply
			$this->attributes_model->update_for_user($this->ion_auth->user()->row()->id, $attribute, $value);
		}
		
		// Option filtering
		$options = array();
		$options_for_page = $this->options_model->get_options_for_page($id);
		foreach ($options_for_page as $option) {
			$conditions = $this->options_model->get_conditions_for_option($option['id']);
			
			$conditions_met = true;
			foreach ($conditions as $condition) {
				// Check conditions
				$value = $this->attributes_model->get_for_user($this->ion_auth->user()->row()->id, $condition['attribute']);
				$value = $value['value'];
				$comparison = $condition['comparison'];
				$condition_value = $condition['value'];<commit_msg>Fixed no page no image error<commit_after><?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Page extends CI_Controller {
	
	public function __construct() {
		parent::__construct();
		$this->load->library('ion_auth');
		$this->load->library('form_validation');
		$this->load->helper('text');
		$this->load->model('settings_model');
		$this->load->model('pages_model');
		$this->load->model('assets_model');
		$this->load->model('attributes_model');
		$this->load->model('options_model');
		
		$this->lang->load('storyengine');
	}
	
	public function index() {
		// If not logged in redirect to login page
		if (!$this->ion_auth->logged_in()) { redirect('story/login', 'refresh'); }
		
		// Redirect to start page
		$start_page = $this->settings_model->get_value('start_page');
		redirect('page/show/'.$start_page);
	}
	
	public function show($id) {
		if (!$this->ion_auth->logged_in()) { redirect('story/login', 'refresh'); }
		
		$this->data['page'] = $this->pages_model->get($id);
		$this->data['image'] = ($this->data['page'] != null) ? $this->assets_model->get_page_image($this->data['page']['image']) : null;
		
		// Apply consequences (story_page_consequences)
		$consequences = $this->pages_model->get_consequences($id);
		foreach ($consequences as $consequence) {
			$attribute = $consequence['attribute'];
			$value = $this->attributes_model->get_for_user($this->ion_auth->user()->row()->id, $attribute);
			$value = $value['value'];
			$operator = $consequence['operator'];
			$consequence_value = $consequence['value'];
			
			switch ($operator) {
				case 1: // +=
					$value += $consequence_value; break;
				case 2: // -=
					$value -= $consequence_value; break;
				case 3: // =
					$value = $consequence_value; break;
			}
			
			// Apply
			$this->attributes_model->update_for_user($this->ion_auth->user()->row()->id, $attribute, $value);
		}
		
		// TODO: Achievement unlocking
		
		
		// Option filtering
		$options = array();
		$options_for_page = $this->options_model->get_options_for_page($id);
		foreach ($options_for_page as $option) {
			$conditions = $this->options_model->get_conditions_for_option($option['id']);
			
			$conditions_met = true;
			foreach ($conditions as $condition) {
				// Check conditions
				$value = $this->attributes_model->get_for_user($this->ion_auth->user()->row()->id, $condition['attribute']);
				$value = $value['value'];
				$comparison = $condition['comparison'];
				$condition_value = $condition['value'];
{'fraction_non_alphanumeric': 0.19662243667068757, 'fraction_numerical': 0.0012062726176115801, 'mean_word_length': 4.491169977924945, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 114, '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': '2113932', 'n_tokens_mistral': 1807, 'n_tokens_neox': 1551, 'n_words': 273}