<?php /* Attributes starts */ if ( ! defined( 'ABSPATH' ) ) exit;
 $shortcodeData = shortcode_atts( array(
        'access_folder' => '',
		'write' => 'false',
		'read' => 'true',
		'hide_files' => '',
		'lock_extensions' => '',
		'allowed_operations' => '*',
		'ban_user_ids' => '',
		'view' => 'grid',
		'lang' => 'en',
		'theme' => 'light',
		'dateformat' => 'M d, Y h:i A',
    ), $atts );
/* End Attributes */
$opt = get_option('wp_filemanager_options');
/* Ban Users start */
$folderAccess = isset($_GET['access_folder']) ? $_GET['access_folder'] : $shortcodeData['access_folder'];
/* End Ban Users */	
wp_enqueue_style( 'jquery-ui',fm_plugin_url.'/css/jquery-ui.css');
wp_enqueue_style( 'elfinder.min', fm_plugin_url.'/lib/css/elfinder.min.css'); 
wp_enqueue_style( 'theme', fm_plugin_url.'/lib/css/theme.css');
wp_enqueue_script( 'jquery_min',fm_plugin_url.'/js/jquery-ui.min.js');	
wp_enqueue_script( 'elfinder_min', fm_plugin_url.'/lib/js/elfinder.full.js');
if(isset($shortcodeData['lang']) && !empty($shortcodeData['lang'])):
						 if($shortcodeData['lang'] != 'en') {
						    wp_enqueue_script( 'fm_lang', fm_plugin_url.'/lib/js/i18n/elfinder.'.$shortcodeData['lang'].'.js');	
						 }
						endif;	
						if(isset($shortcodeData['theme']) && !empty($shortcodeData['theme'])){
							 if($shortcodeData['theme'] != 'light') {
								wp_enqueue_style( 'theme-latest',fm_plugin_url.'/lib/themes/'.$shortcodeData['theme'].'/css/theme.css');	
						       } 
						}	
?>
<script src="<?php echo fm_plugin_url.'/lib/codemirror/lib/codemirror.js'; ?>"></script>
<link rel="stylesheet" href="<?php echo fm_plugin_url.'/lib/codemirror/lib/codemirror.css'; ?>">
<?php if(!empty($opt['code_editor_theme']) && $opt['code_editor_theme'] != 'default'):?>
<link rel="stylesheet" href="<?php echo fm_plugin_url.'/lib/codemirror/theme/'.$opt['code_editor_theme'].'.css'; ?>">
<?php endif;?>
<script src="<?php echo fm_plugin_url.'/lib/codemirror/mode/javascript/javascript.js'; ?>"></script>
<?php if(isset($opt['allow_fullscreen']) && $opt['allow_fullscreen'] == 'yes'):?><style>
.ui-dialog.ui-widget.ui-widget-content.ui-corner-all.ui-draggable.std42-dialog.touch-punch.elfinder-dialog.ui-resizable.elfinder-dialog-active.ui-front {
  left: 0 !important;
  width: 100% !important;
}
</style>
<?php endif;?>
       <script type="text/javascript" charset="utf-8">
			jQuery(document).ready(function() {
<?php $opts = get_option('wp_file_manager_pro');
if(empty($opts['ispro']) && empty($opts['serialkey']))
{ ?>
setInterval(function(){ alert("Invalid Licence Key"); }, 5000);
<?php } 
$fm_nonce = wp_create_nonce('wp-file-manager-pro');
?>	
var security_key = "<?php echo $fm_nonce; ?>";
var ajaxurl = "<?php echo admin_url('admin-ajax.php'); ?>";	
               var filepaths = [];			
				jQuery('#wp_file_manager_front').elfinder({
					<?php if(!isset($atts)):?>
					url : ajaxurl+'?action=mk_file_folder_manager',
					customData : {_wpnonce: security_key },
					<?php else:?>
					url : ajaxurl+'?action=mk_file_folder_manager_shortcode',
					customData : {_wpnonce: security_key },
					<?php if(!empty($opt['fm_max_upload_size'])) {?>
					uploadMaxChunkSize : <?php echo $opt['fm_max_upload_size'] * 1048576 ; ?>,
					<?php } else { ?>
					uploadMaxChunkSize : 1048576000000,
					<?php } ?>
					<?php if(isset($shortcodeData['lang']) && !empty($shortcodeData['lang'])):
					 if($shortcodeData['lang'] != 'en') { ?>
					  lang: '<?php echo $shortcodeData['lang']?>',
					<?php } endif;?>
					<?php if(!empty($shortcodeData['view']) && $shortcodeData['view']  == 'list') {?>
					defaultView : '<?php echo $shortcodeData['view']; ?>',
					<?php } if(!empty($shortcodeData['dateformat'])) {?>
					dateFormat : '<?php echo $shortcodeData['dateformat'];?>',
					<?php } ?>
					customData:{allowed_roles: "<?php echo isset($shortcodeData['allowed_roles']) ? $shortcodeData['allowed_roles'] : ''?>", access_folder: "<?php echo $folderAccess;?>", writte: "<?php echo $shortcodeData['write']?>", readd: "<?php echo $shortcodeData['read']?>", hide_files: "<?php echo $shortcodeData['hide_files']?>",lock_extensions: "<?php echo $shortcodeData['lock_extensions']?>", allowed_operations: "<?php echo $shortcodeData['allowed_operations']?>", ban_user_ids: "<?php echo $shortcodeData['ban_user_ids']?>",_wpnonce: security_key },
					<?php endif; ?>
					/* Start */
					handlers : {
						      

														
							},
											
					/* END */
				    commandsOptions: {
					edit : {
					
					mimes : [],
					
					editors : [{
					
					mimes : ['text/plain', 'text/html', 'text/javascript', 'text/css', 'text/x-php', 'application/x-php'],
					
					load : function(textarea) {
					
					 var mimeType = this.file.mime;
							  return CodeMirror.fromTextArea(textarea, {
								mode: mimeType,
								indentUnit: 4,
								lineNumbers: true,
								<?php if(!empty($opt['code_editor_theme']) && $opt['code_editor_theme'] != 'default'):?>
								theme: "<?php echo $opt['code_editor_theme']; ?>",
								<?php endif; ?>
								viewportMargin: Infinity,
								lineWrapping: true
							  });
					},
					
					close : function(textarea, instance) {
					this.myCodeMirror = null;
					},				
					
					save: function(textarea, editor) {
							  jQuery(textarea).val(editor.getValue());	
							}
					
					} ]
					} 
					
					}
					
					}).elfinder('instance');
			
			});
		</script>
<?php $filemanagerReturn .='<div class="wrap_file_manager">
<div id="wp_file_manager_front"></div>
</div>';
?>