<commit_before><?php if (!defined('BASEPATH')) exit('No direct script access allowed');
/**
 * Bonfire
 *
 * An open source project to allow developers get a jumpstart their development of CodeIgniter applications
 *
 * @package   Bonfire
 * @author    Bonfire Dev Team
 * @copyright Copyright (c) 2011 - 2013, Bonfire Dev Team
 * @license   http://guides.cibonfire.com/license.html
 * @link      http://cibonfire.com
 * @since     Version 1.0
 * @filesource
 */

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

/**
 * Logs Developer Context
 *
 * Allows the developer to view the logs that have been generated by the system.
 *
 * @package    Bonfire
 * @subpackage Modules_Logs
 * @category   Controllers
 * @author     Bonfire Dev Team
 * @link       http://guides.cibonfire.com/helpers/file_helpers.html
 *
 */
class Developer extends Admin_Controller
{

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

	/**
	 * Sets up the permissions and loads the language file
	 *
	 * @return void
	 */
	public function __construct()
	{
		parent::__construct();

		$this->auth->restrict('Site.Developer.View');
		$this->auth->restrict('Bonfire.Logs.View');

		$this->lang->load('logs');
		Template::set('toolbar_title', lang('log_title'));

		Template::set_block('sub_nav', 'developer/_sub_nav');

		// Logging enabled?
		Template::set('log_threshold', $this->config->item('log_threshold'));
	}//end __construct()

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

	/**
	 * Lists all log files and allows you to change the log_threshold.
	 *
	 * @access public
	 *
	 * @return void
	 */
	public function index()
	{
		$this->load->helper('file');

		// Are we doing bulk actions?
		if (isset($_POST['delete']))
		{
			$this->auth->restrict('Bonfire.Logs.Manage');

			$checked = $this->input->post('checked');

			if (is_array($checked) && count($checked))
			{
				foreach ($checked as $file)
				{
					@unlink($this->config->item('log_path') . $file);
					$activity_text = 'log file '.date('F j, Y', strtotime(str_replace('.php', '', str_replace('log-', '', $file))));
					log_activity($this->current_user->id, ucfirst($activity_text) . ' deleted from: ' . $this->input->ip_address(), 'logs');
				}

				Template::set_message(sprintf(lang('log_deleted'), count($checked)), 'success');
			}
		}
		elseif (isset($_POST['delete_all']))
		{
			$this->auth->restrict('Bonfire.Logs.Manage');

			delete_files($this->config->item('log_path'));
			// restore the index.html file
			@copy(APPPATH.'/index.html',$this->config->item('log_path').'/index.html');

			// Log the activity
			$activity_text = "all log files";
			log_activity($this->current_user->id, ucfirst($activity_text) . ' deleted from: ' . $this->input->ip_address(), 'logs');

			Template::set_message("Successfully deleted " . $activity_text, 'success');
		}

		// Load the Log Files
		$logs = array_reverse(get_filenames($this->config->item('log_path')));

		// Pagination
		$this->load->library('pagination');

		$offset = $this->uri->segment(5) ? $this->uri->segment(5) : 0;
		//$limit = $this->limit;
		$limit = 10;

		$this->pager['base_url'] = site_url(SITE_AREA .'/developer/logs/index');
		$this->pager['total_rows'] = count($logs);
		$this->pager['per_page'] = $limit;
		$this->pager['uri_segment']	= 5;

		$this->pagination->initialize($this->pager);

		Template::set('logs', array_slice($logs, $offset, $limit));

		Template::render();

	}//end index()

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

	/**
	 * Display the page which lets the user choose the logging threshold.
	 *
	 * @access public
	 *
	 * @return void<commit_msg>Fix sort on System Logs<commit_after><?php if (!defined('BASEPATH')) exit('No direct script access allowed');
/**
 * Bonfire
 *
 * An open source project to allow developers get a jumpstart their development of CodeIgniter applications
 *
 * @package   Bonfire
 * @author    Bonfire Dev Team
 * @copyright Copyright (c) 2011 - 2013, Bonfire Dev Team
 * @license   http://guides.cibonfire.com/license.html
 * @link      http://cibonfire.com
 * @since     Version 1.0
 * @filesource
 */

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

/**
 * Logs Developer Context
 *
 * Allows the developer to view the logs that have been generated by the system.
 *
 * @package    Bonfire
 * @subpackage Modules_Logs
 * @category   Controllers
 * @author     Bonfire Dev Team
 * @link       http://guides.cibonfire.com/helpers/file_helpers.html
 *
 */
class Developer extends Admin_Controller
{

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

	/**
	 * Sets up the permissions and loads the language file
	 *
	 * @return void
	 */
	public function __construct()
	{
		parent::__construct();

		$this->auth->restrict('Site.Developer.View');
		$this->auth->restrict('Bonfire.Logs.View');

		$this->lang->load('logs');
		Template::set('toolbar_title', lang('log_title'));

		Template::set_block('sub_nav', 'developer/_sub_nav');

		// Logging enabled?
		Template::set('log_threshold', $this->config->item('log_threshold'));
	}//end __construct()

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

	/**
	 * Lists all log files and allows you to change the log_threshold.
	 *
	 * @access public
	 *
	 * @return void
	 */
	public function index()
	{
		$this->load->helper('file');

		// Are we doing bulk actions?
		if (isset($_POST['delete']))
		{
			$this->auth->restrict('Bonfire.Logs.Manage');

			$checked = $this->input->post('checked');

			if (is_array($checked) && count($checked))
			{
				foreach ($checked as $file)
				{
					@unlink($this->config->item('log_path') . $file);
					$activity_text = 'log file '.date('F j, Y', strtotime(str_replace('.php', '', str_replace('log-', '', $file))));
					log_activity($this->current_user->id, ucfirst($activity_text) . ' deleted from: ' . $this->input->ip_address(), 'logs');
				}

				Template::set_message(sprintf(lang('log_deleted'), count($checked)), 'success');
			}
		}
		elseif (isset($_POST['delete_all']))
		{
			$this->auth->restrict('Bonfire.Logs.Manage');

			delete_files($this->config->item('log_path'));
			// restore the index.html file
			@copy(APPPATH.'/index.html',$this->config->item('log_path').'/index.html');

			// Log the activity
			$activity_text = "all log files";
			log_activity($this->current_user->id, ucfirst($activity_text) . ' deleted from: ' . $this->input->ip_address(), 'logs');

			Template::set_message("Successfully deleted " . $activity_text, 'success');
		}

		// Load the Log Files
		$logs = get_filenames($this->config->item('log_path'));
        arsort($logs);

		// Pagination
		$this->load->library('pagination');

		$offset = $this->uri->segment(5) ? $this->uri->segment(5) : 0;
		$limit = 10;

		$this->pager['base_url'] = site_url(SITE_AREA . '/developer/logs/index');
		$this->pager['total_rows'] = count($logs);
		$this->pager['per_page'] = $limit;
		$this->pager['uri_segment']	= 5;

		$this->pagination->initialize($this->pager);

		Template::set('logs', array_slice($logs, $offset, $limit));

		Template::render();

	}//end index()

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

	/**
	 * Display the page which lets the user choose the logging threshold.
	 *
	 * @access public
	 *
	 * @return void
{'fraction_non_alphanumeric': 0.24445646295294754, 'fraction_numerical': 0.004326663061114116, 'mean_word_length': 2.726448362720403, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 94, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4034090', 'n_tokens_mistral': 2495, 'n_tokens_neox': 2222, 'n_words': 476}