<commit_before><?php
/**
*  phpBB Extension - marttiphpbb customcode
* @copyright (c) 2014 marttiphpbb <<EMAIL>>
* @license http://opensource.org/licenses/MIT
*/

namespace marttiphpbb\customcode\acp;

class main_module
{
	var $u_action;
	
	protected $dir = 'store/customcode';
	
	protected $events = array(
		'overall_footer_after.html',
		'overall_footer_copyright_append.html',
		'overall_header_content_before.html',		
		'overall_header_head_append.html',
		'overall_header_stylesheets_after.html',
		
	);

	function main($id, $mode)
	{
		global $template, $request, $phpbb_root_path, $user, $cache, $config;
		

		$user->add_lang_ext('marttiphpbb/customcode', 'common');
		add_form_key('marttiphpbb/customcode');
			
		$filenames = array_diff(scandir($phpbb_root_path . $this->dir), array('.', '..', '.htaccess'));
			
		switch($mode)
		{
			case 'edit': 
				$this->tpl_name = 'edit';
				$this->page_title = $user->lang('ACP_CUSTOMCODE_EDIT');

				$file =	$request->variable('filename', '', true);
				$editor_rows = max(5, min(999, $request->variable('editor_rows', 8)));

				$save = $request->is_set_post('save');
				$save_purge_cache = $request->is_set_post('save_purge_cache');

				if ($save || $save_purge_cache)
				{
					
					$data	= utf8_normalize_nfc($request->variable('file_data', '', true));
					$data	= htmlspecialchars_decode($data);					
					
					
					if (confirm_box(true))
					{
						if (!($f = @fopen($phpbb_root_path . $this->dir . '/' . $file, 'wb')))
						{
							trigger_error(sprintf($user->lang('ACP_CUSTOMCODE_NOT_WRITABLE'), $file) . adm_back_link($this->u_action), E_USER_WARNING);
						}
			
						fwrite($f, $data);
						fclose($f);	
						
						if ($save_purge_cache)
						{
							$config->increment('assets_version', 1);
							$cache->purge();								
							trigger_error(sprintf($user->lang('ACP_CUSTOMCODE_FILE_SAVED_CACHE_PURGED'), $file) . adm_back_link($this->u_action));			
						}
						
						trigger_error(sprintf($user->lang('ACP_CUSTOMCODE_FILE_SAVED'), $file) . adm_back_link($this->u_action));
					}

					if (!in_array($file, $filenames))
					{
						trigger_error(sprintf($user->lang('ACP_CUSTOMCODE_FILE_NOT_EXIST'), $file) . adm_back_link($this->u_action), E_USER_WARNING);
					}
					
					$confirm_message = ($save_purge_cache) ? 'ACP_CUSTOMCODE_SAVE_PURGE_CACHE_CONFIRM' : 'ACP_CUSTOMCODE_SAVE_CONFIRM';
					
					$s_hidden_fields = array(
						'filename'			=> $file,
						'file_data' 		=> utf8_htmlspecialchars($data),
						'mode'				=> 'edit',					<commit_msg>adm backlink land on same file after save<commit_after><?php
/**
*  phpBB Extension - marttiphpbb customcode
* @copyright (c) 2014 marttiphpbb <<EMAIL>>
* @license http://opensource.org/licenses/MIT
*/

namespace marttiphpbb\customcode\acp;

class main_module
{
	var $u_action;
	
	protected $dir = 'store/customcode';
	
	protected $events = array(
		'overall_footer_after.html',
		'overall_footer_copyright_append.html',
		'overall_header_content_before.html',		
		'overall_header_head_append.html',
		'overall_header_stylesheets_after.html',
		
	);

	function main($id, $mode)
	{
		global $template, $request, $phpbb_root_path, $user, $cache, $config;
		

		$user->add_lang_ext('marttiphpbb/customcode', 'common');
		add_form_key('marttiphpbb/customcode');
			
		$filenames = array_diff(scandir($phpbb_root_path . $this->dir), array('.', '..', '.htaccess'));
	
		switch($mode)
		{
			case 'edit': 
				$this->tpl_name = 'edit';
				$this->page_title = $user->lang('ACP_CUSTOMCODE_EDIT');

				$file =	$request->variable('filename', '', true);
				$editor_rows = max(5, min(999, $request->variable('editor_rows', 8)));

				$save = $request->is_set_post('save');
				$save_purge_cache = $request->is_set_post('save_purge_cache');

				if ($save || $save_purge_cache)
				{
					
					$data	= utf8_normalize_nfc($request->variable('file_data', '', true));
					$data	= htmlspecialchars_decode($data);					
					
					
					if (confirm_box(true))
					{
						if (!($f = @fopen($phpbb_root_path . $this->dir . '/' . $file, 'wb')))
						{
							trigger_error(sprintf($user->lang('ACP_CUSTOMCODE_NOT_WRITABLE'), $file) . adm_back_link($this->u_action . '&amp;filename=' . $file), E_USER_WARNING);
						}
			
						fwrite($f, $data);
						fclose($f);	
						
						if ($save_purge_cache)
						{
							$config->increment('assets_version', 1);
							$cache->purge();								
							trigger_error(sprintf($user->lang('ACP_CUSTOMCODE_FILE_SAVED_CACHE_PURGED'), $file) . adm_back_link($this->u_action . '&amp;filename='. $file));			
						}
						
						trigger_error(sprintf($user->lang('ACP_CUSTOMCODE_FILE_SAVED'), $file) . adm_back_link($this->u_action . '&amp;filename=' . $file));
					}

					if (!in_array($file, $filenames))
					{
						trigger_error(sprintf($user->lang('ACP_CUSTOMCODE_FILE_NOT_EXIST'), $file) . adm_back_link($this->u_action), E_USER_WARNING);
					}
					
					$confirm_message = ($save_purge_cache) ? 'ACP_CUSTOMCODE_SAVE_PURGE_CACHE_CONFIRM' : 'ACP_CUSTOMCODE_SAVE_CONFIRM';
					
					$s_hidden_fields = array(
						'filename'			=> $file,
						'file_data' 		=> utf8_htmlspecialchars($data),
						'mode'				=> 'edit',					
{'fraction_non_alphanumeric': 0.16762783544790466, 'fraction_numerical': 0.00461361014994233, 'mean_word_length': 3.658012533572068, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 55, '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': '1504444', 'n_tokens_mistral': 2410, 'n_tokens_neox': 1907, 'n_words': 251}