<commit_before><?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Resource extends CI_Controller {

	function __construct() {
		parent::__construct();
		$this->load->library('session');
		$this->load->model('common','',TRUE);
		/*
		if($this->session->userdata('user_auth')) {
			$sess = $this->session->userdata('user_auth');
			if($sess['serv']=='peter')
				redirect('admin', 'refresh');
		} else {
			redirect('login', 'refresh');
		}
		*/
	}
	function index() {
		$this->load->helper('form');
		$this->load->helper('url');
		
		$data['sess'] = $this->session->userdata('user_auth');
		$head['title'] = "Resource";

		$this->load->vars($data);
		$this->load->view('resource_head', $head);
		$this->load->view('menu_view');
		$this->load->view('resource_view');
		$this->load->view('foot');
	}
	function manage($project_id = FALSE) {
		$this->load->helper('form');
		$this->load->helper('url');
		
		$data['sess'] = $this->session->userdata('user_auth');
		$head['title'] = "Resource";

		$this->load->vars($data);
		$this->load->view('resource_head', $head);
		$this->load->view('menu_view');
		$this->load->view('resource_view');
		$this->load->view('foot');
	}
	public function do_upload() {
		$this->load->helper('url');

		$sess = $this->session->userdata('user_auth');
		$proj = $this->session->userdata('active_project');
		$resource_type = $this->input->post('restype');
		$path_to_project = 'resources/' . $sess['id'] . '/' . $proj['id'] . '/';

		// sprite type resource
		if($resource_type == 1) {
			$upload_path_url = base_url() . $path_to_project . 'sprite/';
			$config['upload_path'] = FCPATH . $path_to_project . 'sprite/';
			$config['allowed_types'] = 'jpg|jpeg|png|bmp';
			$config['overwrite'] = FALSE;
			$config['max_size'] = 20 * 1024 * 1024; //20 MB
			$config['encrypt_name'] = TRUE;
			$this->load->library('upload', $config);

			if($this->upload->do_upload() == FALSE){
				$this->fb->log($this->upload->display_errors());
			}
			else{
				$data = $this->upload->data();
				$config['source_image'] = $data['full_path'];
				$config['new_image'] =  FCPATH . $path_to_project . 'sprite/thumbs/';
				$config['maintain_ratio'] = TRUE;
				$config['create_thumb'] = TRUE;
				$config['thumb_marker'] = '_thumb';
				$config['quality'] = '70%';
				$config['width'] = 400;
				$config['height'] = 400;
				$this->load->library('image_lib', $config);
				//resize original image for thumbnail
				if($this->image_lib->resize() == FALSE){
					$this->fb->log($this->image_lib->display_errors());
				}

				//extract original filename without extension
				$base_file_name = $this->trimExtension($data['orig_name']);
				//get post data for character name and figure name
				$character_name = $this->input->post('charname');
				$figure_name = $this->input->post('figname');
				// $this->fb->log($character_name);
				//write file record to database
				$pass = $this->common->createSpriteResource($base_file_name, $data['file_name'], $character_name, $figure_name, '1', $proj['id']);
				if($pass != NULL) {
					$info = new StdClass;
					$info->id = $pass;
					$info->name = $base_file_name;
					$info->size = $data['file_size'];
					$info->type = $data['file_type'];
					//generate url info with url to thumb file
					$info->url = $upload_path_url . 'thumbs/' . $data['raw_name'] . '_thumb' . $data['file_ext'];
					$info->error = null;
					$info->resource_type = $resource_type;
					$info->character_name = $character_name;
					$info->figure_name = $figure_name;
					$files[] = $info;
					if($this->input->is_ajax_request()){
						$this->output->set_content_type('application/json')->set_output(json_encode(array("files" => $files)));
						//$this->fb->log(json_encode(array("files" => $files)));
					}
					else{
						exit('No direct script access allowed');
					}
				}

				
			}
		}
		// background type resource
		else if($resource_type == 2) {
			$upload_path_url = base_url() . $path_to_project . 'background/';
			$config['upload_path'] = FCPATH . $path_to_project . 'background/';
			$config['allowed_types'] = 'jpg|jpeg|png|bmp';
			$config['overwrite'] = FALSE;
			$config['max_size'] = 20 * 1024 * 1024;
			$config['encrypt_name'] = TRUE;
			$config['remove_spaces'] = TRUE;
			$this->load->library('upload', $config);

			if($this->upload->do_upload() == FALSE){
				$this->fb->log($this->upload->display_errors());
			}
			else{
				$data = $this->upload->data();
				//config for image resize
				$config['image_library'] = 'ImageMagick';
				$config['source_image'] = $data['full_path'];
				$config['new_image'] =  FCPATH . $path_to_project . 'background/thumbs/';
				$config['maintain_ratio'] = TRUE;
				$config['create_thumb'] = TRUE;
				$config['thumb_marker'] = '_thumb';
				$config['quality'] = '70%';
				$config['width'] = 80;
				$config['height'] = 80;
				$this->load->library('image_lib', $config);
				//resize original image for thumbnail
				if($this->image_lib->resize() == FALSE){
					$this->fb->log($this->image_lib->display_errors());
				}

				//trim original filename
				$base_file_name = $this->trimExtension($data['orig_name']);
				//write file info to database
				$pass = $this->common->createBackgroundResource($base_file_name, $data['file_name'], '2', $proj['id']);
				if($pass != NULL) {
					$info = new StdClass;
					$info->id = $pass;
					$info->name = $base_file_name;<commit_msg>fix background resource not creating thumb on upload<commit_after><?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Resource extends CI_Controller {

	function __construct() {
		parent::__construct();
		$this->load->library('session');
		$this->load->model('common','',TRUE);
		/*
		if($this->session->userdata('user_auth')) {
			$sess = $this->session->userdata('user_auth');
			if($sess['serv']=='peter')
				redirect('admin', 'refresh');
		} else {
			redirect('login', 'refresh');
		}
		*/
	}
	function index() {
		$this->load->helper('form');
		$this->load->helper('url');
		
		$data['user'] = $this->session->userdata('user_auth');
		$head['title'] = "Resource";

		$this->load->vars($data);
		$this->load->view('resource_head', $head);
		$this->load->view('menu_view');
		$this->load->view('resource_view');
		$this->load->view('foot');
	}
	function manage($project_id = FALSE) {
		$this->load->helper('form');
		$this->load->helper('url');
		
		$data['user'] = $this->session->userdata('user_auth');
		$head['title'] = "Resource";

		$this->load->vars($data);
		$this->load->view('resource_head', $head);
		$this->load->view('menu_view');
		$this->load->view('resource_view');
		$this->load->view('foot');
	}
	public function do_upload() {
		$this->load->helper('url');

		$sess = $this->session->userdata('user_auth');
		$proj = $this->session->userdata('active_project');
		$resource_type = $this->input->post('restype');
		$path_to_project = 'resources/' . $sess['id'] . '/' . $proj['id'] . '/';

		// sprite type resource
		if($resource_type == 1) {
			$upload_path_url = base_url() . $path_to_project . 'sprite/';
			$config['upload_path'] = FCPATH . $path_to_project . 'sprite/';
			$config['allowed_types'] = 'jpg|jpeg|png|bmp';
			$config['overwrite'] = FALSE;
			$config['max_size'] = 20 * 1024 * 1024; //20 MB
			$config['encrypt_name'] = TRUE;
			$this->load->library('upload', $config);

			if($this->upload->do_upload() == FALSE){
				$this->fb->log($this->upload->display_errors());
			}
			else{
				$data = $this->upload->data();
				$config['source_image'] = $data['full_path'];
				$config['new_image'] =  FCPATH . $path_to_project . 'sprite/thumbs/';
				$config['maintain_ratio'] = TRUE;
				$config['create_thumb'] = TRUE;
				$config['thumb_marker'] = '_thumb';
				$config['quality'] = '70%';
				$config['width'] = 400;
				$config['height'] = 400;
				$this->load->library('image_lib', $config);
				//resize original image for thumbnail
				if($this->image_lib->resize() == FALSE){
					$this->fb->log($this->image_lib->display_errors());
				}

				//extract original filename without extension
				$base_file_name = $this->trimExtension($data['orig_name']);
				//get post data for character name and figure name
				$character_name = $this->input->post('charname');
				$figure_name = $this->input->post('figname');
				// $this->fb->log($character_name);
				//write file record to database
				$pass = $this->common->createSpriteResource($base_file_name, $data['file_name'], $character_name, $figure_name, '1', $proj['id']);
				if($pass != NULL) {
					$info = new StdClass;
					$info->id = $pass;
					$info->name = $base_file_name;
					$info->size = $data['file_size'];
					$info->type = $data['file_type'];
					//generate url info with url to thumb file
					$info->url = $upload_path_url . 'thumbs/' . $data['raw_name'] . '_thumb' . $data['file_ext'];
					$info->error = null;
					$info->resource_type = $resource_type;
					$info->character_name = $character_name;
					$info->figure_name = $figure_name;
					$files[] = $info;
					if($this->input->is_ajax_request()){
						$this->output->set_content_type('application/json')->set_output(json_encode(array("files" => $files)));
						//$this->fb->log(json_encode(array("files" => $files)));
					}
					else{
						exit('No direct script access allowed');
					}
				}

				
			}
		}
		// background type resource
		else if($resource_type == 2) {
			$upload_path_url = base_url() . $path_to_project . 'background/';
			$config['upload_path'] = FCPATH . $path_to_project . 'background/';
			$config['allowed_types'] = 'jpg|jpeg|png|bmp';
			$config['overwrite'] = FALSE;
			$config['max_size'] = 20 * 1024 * 1024;
			$config['encrypt_name'] = TRUE;
			$config['remove_spaces'] = TRUE;
			$this->load->library('upload', $config);

			if($this->upload->do_upload() == FALSE){
				$this->fb->log($this->upload->display_errors());
			}
			else{
				$this->fb->log($sess['id']);
				$this->fb->log($proj['id']);
				$data = $this->upload->data();
				//config for image resize
				// $config['image_library'] = 'ImageMagick';
				$config['source_image'] = $data['full_path'];
				$config['new_image'] =  FCPATH . $path_to_project . 'background/thumbs/';
				$config['maintain_ratio'] = TRUE;
				$config['create_thumb'] = TRUE;
				$config['thumb_marker'] = '_thumb';
				$config['quality'] = '70%';
				$config['width'] = 80;
				$config['height'] = 80;
				$this->load->library('image_lib', $config);
				//resize original image for thumbnail
				if($this->image_lib->resize() == FALSE){
					$this->fb->log($this->image_lib->display_errors());
				}

				//trim original filename
				$base_file_name = $this->trimExtension($data['orig_name']);
				//write file info to database
				$pass = $this->common->createBackgroundResource($base_file_name, $data['file_name'], '2', $proj['id']);
				if($pass != NULL) {
					$info = new StdClass;
					$info->id = $pass;
					$info->name = $base_file_name;
{'fraction_non_alphanumeric': 0.2183446007674036, 'fraction_numerical': 0.0073086058834277365, 'mean_word_length': 3.9511533242876524, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 239, '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': '5611658', 'n_tokens_mistral': 4491, 'n_tokens_neox': 3704, 'n_words': 614}