/**
  * Enqueue admin scripts
  */
 public function enqueue_scripts()
 {
     global $pagenow, $post;
     // Enqueue Edit Post JS
     wp_enqueue_script('dlm_insert_download', plugins_url('/assets/js/insert-download' . (!SCRIPT_DEBUG ? '.min' : '') . '.js', WP_DLM::get_plugin_file()), array('jquery'), DLM_VERSION);
     // Make JavaScript strings translatable
     wp_localize_script('dlm_insert_download', 'dlm_id_strings', $this->get_strings('edit-post'));
     if ($pagenow == 'post.php' || $pagenow == 'post-new.php') {
         // Enqueue Downloadable Files Metabox JS
         if ($pagenow == 'post.php' && isset($post) && 'dlm_download' === $post->post_type || $pagenow == 'post-new.php' && isset($_GET['post_type']) && 'dlm_download' == $_GET['post_type']) {
             // Enqueue Edit Download JS
             wp_enqueue_script('dlm_edit_download', plugins_url('/assets/js/edit-download' . (!SCRIPT_DEBUG ? '.min' : '') . '.js', WP_DLM::get_plugin_file()), array('jquery'), DLM_VERSION);
             // Make JavaScript strings translatable
             wp_localize_script('dlm_edit_download', 'dlm_ed_strings', $this->get_strings('edit-download'));
         }
     }
     if ('edit.php' == $pagenow && isset($_GET['post_type']) && 'dlm_download' === $_GET['post_type'] && !isset($_GET['page'])) {
         // Enqueue Settings JS
         wp_enqueue_script('dlm_download_overview', plugins_url('/assets/js/overview-download' . (!SCRIPT_DEBUG ? '.min' : '') . '.js', WP_DLM::get_plugin_file()), array('jquery'), DLM_VERSION, true);
     }
     if ('edit.php' == $pagenow && isset($_GET['page']) && ('download-monitor-settings' === $_GET['page'] || 'dlm-extensions' === $_GET['page'])) {
         // Enqueue Settings JS
         wp_enqueue_script('dlm_settings', plugins_url('/assets/js/settings' . (!SCRIPT_DEBUG ? '.min' : '') . '.js', WP_DLM::get_plugin_file()), array('jquery'), DLM_VERSION);
         if ('dlm-extensions' === $_GET['page']) {
             // Enqueue Extesions JS
             wp_enqueue_script('dlm_extensions', plugins_url('/assets/js/extensions' . (!SCRIPT_DEBUG ? '.min' : '') . '.js', WP_DLM::get_plugin_file()), array('jquery'), DLM_VERSION);
         }
     }
 }
 /**
  * get_template_part method.
  *
  * @access public
  *
  * @param string $slug
  * @param string $name (default: '')
  * @param string $custom_dir
  * @param array $args
  *
  * @return void
  */
 public function get_template_part($slug, $name = '', $custom_dir = '', $args = array())
 {
     $template = '';
     // The plugin path
     $plugin_path = WP_DLM::get_plugin_path();
     // Look in yourtheme/slug-name.php and yourtheme/download-monitor/slug-name.php
     if ($name) {
         $template = locate_template(array("{$slug}-{$name}.php", "download-monitor/{$slug}-{$name}.php"));
     }
     // If a custom path was defined, check that next
     if (!$template && $custom_dir && file_exists(trailingslashit($custom_dir) . "{$slug}-{$name}.php")) {
         $template = trailingslashit($custom_dir) . "{$slug}-{$name}.php";
     }
     // Get default slug-name.php
     if (!$template && $name && file_exists($plugin_path . "/templates/{$slug}-{$name}.php")) {
         $template = $plugin_path . "/templates/{$slug}-{$name}.php";
     }
     // If template file doesn't exist, look in yourtheme/slug.php and yourtheme/download-monitor/slug.php
     if (!$template) {
         $template = locate_template(array("{$slug}.php", "download-monitor/{$slug}.php"));
     }
     // If a custom path was defined, check that next
     if (!$template && $custom_dir && file_exists(trailingslashit($custom_dir) . "{$slug}.php")) {
         $template = trailingslashit($custom_dir) . "{$slug}.php";
     }
     // Get default slug-name.php
     if (!$template && file_exists($plugin_path . "/templates/{$slug}.php")) {
         $template = $plugin_path . "/templates/{$slug}.php";
     }
     // Allow 3rd party plugin filter template file from their plugin
     $template = apply_filters('dlm_get_template_part', $template, $slug, $name);
     // Load template if we've found one
     if ($template) {
         // Extract args if there are any
         if (is_array($args) && count($args) > 0) {
             extract($args);
         }
         do_action('dlm_before_template_part', $template, $slug, $name, $custom_dir, $args);
         include $template;
         do_action('dlm_after_template_part', $template, $slug, $name, $custom_dir, $args);
         //load_template( $template, false );
     }
 }
    /**
     * media_browser function.
     *
     * @access public
     * @return void
     */
    public function media_browser()
    {
        // File Manager
        $file_manager = new DLM_File_Manager();
        // Files
        $files = $file_manager->list_files(ABSPATH, 1);
        echo '<!DOCTYPE html><html lang="en"><head><title>' . __('Browse for a file', 'download-monitor') . '</title>';
        wp_enqueue_style('download_monitor_admin_css', WP_DLM::get_plugin_url() . '/assets/css/admin.css', array('dashicons'));
        do_action('admin_print_styles');
        do_action('admin_print_scripts');
        do_action('admin_head');
        echo '<meta charset="utf-8" /></head><body>';
        echo '<ul class="download_monitor_file_browser">';
        foreach ($files as $found_file) {
            $file = pathinfo($found_file['path']);
            if ($found_file['type'] == 'folder') {
                echo '<li><a href="#" class="folder" data-path="' . trailingslashit($file['dirname']) . $file['basename'] . '">' . $file['basename'] . '</a></li>';
            } else {
                $filename = $file['basename'];
                $extension = empty($file['extension']) ? '' : $file['extension'];
                if (substr($filename, 0, 1) == '.') {
                    continue;
                }
                // Ignore files starting with . like htaccess
                if (in_array($extension, array('', 'php', 'html', 'htm', 'tmp'))) {
                    continue;
                }
                // Ignored file types
                echo '<li><a href="#" class="file filetype-' . sanitize_title($extension) . '" data-path="' . trailingslashit($file['dirname']) . $file['basename'] . '">' . $file['basename'] . '</a></li>';
            }
        }
        echo '</ul>';
        ?>
		<script type="text/javascript">
			jQuery( function () {
				jQuery( '.download_monitor_file_browser' ).on( 'click', 'a', function () {

					var $link = jQuery( this );
					var $parent = $link.closest( 'li' );

					if ( $link.is( '.file' ) ) {

						var win = window.dialogArguments || opener || parent || top;

						win.send_to_editor( $link.attr( 'data-path' ) );

					} else if ( $link.is( '.folder_open' ) ) {

						$parent.find( 'ul' ).remove();
						$link.removeClass( 'folder_open' );

					} else {

						$link.after( '<ul class="load_tree loading"></ul>' );

						var data = {
							action: 'download_monitor_list_files',
							path: jQuery( this ).attr( 'data-path' ),
							security: '<?php 
        echo wp_create_nonce("list-files");
        ?>
'
						};

						jQuery.post( '<?php 
        echo admin_url('admin-ajax.php');
        ?>
', data, function ( response ) {

							$link.addClass( 'folder_open' );

							if ( response ) {
								$parent.find( '.load_tree' ).html( response );
							} else {
								$parent.find( '.load_tree' ).html( '<li class="nofiles"><?php 
        _e('No files found', 'download-monitor');
        ?>
</li>' );
							}
							$parent.find( '.load_tree' ).removeClass( 'load_tree loading' );

						} );
					}
					return false;
				} );
			} );
		</script>
		<?php 
        echo '</body></html>';
    }
 /**
  * get_the_image function.
  *
  * @access public
  *
  * @param string $size (default: 'full')
  *
  * @return void
  */
 public function get_the_image($size = 'full')
 {
     if (has_post_thumbnail($this->id)) {
         return get_the_post_thumbnail($this->id, $size);
     } else {
         return '<img alt="Placeholder" class="wp-post-image" src="' . apply_filters('dlm_placeholder_image_src', WP_DLM::get_plugin_url() . '/assets/images/placeholder.png') . '" />';
     }
 }
 /**
  * custom_columns function.
  *
  * @access public
  *
  * @param mixed $column
  *
  * @return void
  */
 public function custom_columns($column)
 {
     global $post;
     $download = new DLM_Download($post->ID);
     $file = $download->get_file_version();
     switch ($column) {
         case "thumb":
             echo $download->get_the_image();
             break;
         case "download_id":
             echo $post->ID;
             break;
         case "download_cat":
             if (!($terms = get_the_term_list($post->ID, 'dlm_download_category', '', ', ', ''))) {
                 echo '<span class="na">&ndash;</span>';
             } else {
                 echo $terms;
             }
             break;
         case "download_tag":
             if (!($terms = get_the_term_list($post->ID, 'dlm_download_tag', '', ', ', ''))) {
                 echo '<span class="na">&ndash;</span>';
             } else {
                 echo $terms;
             }
             break;
         case "featured":
             if ($download->is_featured()) {
                 echo '<span class="yes">' . __('Yes', 'download-monitor') . '</span>';
             } else {
                 echo '<span class="na">&ndash;</span>';
             }
             break;
         case "members_only":
             if ($download->is_members_only()) {
                 echo '<span class="yes">' . __('Yes', 'download-monitor') . '</span>';
             } else {
                 echo '<span class="na">&ndash;</span>';
             }
             break;
         case "redirect_only":
             if ($download->redirect_only()) {
                 echo '<span class="yes">' . __('Yes', 'download-monitor') . '</span>';
             } else {
                 echo '<span class="na">&ndash;</span>';
             }
             break;
         case "file":
             if ($file) {
                 echo '<a href="' . $download->get_the_download_link() . '"><code>' . $file->filename;
                 if ($size = $download->get_the_filesize()) {
                     echo ' &ndash; ' . $size;
                 }
                 echo '</code></a>';
             } else {
                 echo '<span class="na">&ndash;</span>';
             }
             break;
         case "version":
             if ($file && $file->version) {
                 echo $file->version;
             } else {
                 echo '<span class="na">&ndash;</span>';
             }
             break;
         case "download_count":
             echo number_format($download->get_the_download_count(), 0, '.', ',');
             break;
         case "featured":
             if ($download->is_featured()) {
                 echo '<img src="' . WP_DLM::get_plugin_url() . '/assets/images/on.png" alt="yes" />';
             } else {
                 echo '<span class="na">&ndash;</span>';
             }
             break;
     }
 }
 /**
  * admin_enqueue_scripts function.
  *
  * @access public
  * @return void
  */
 public function admin_enqueue_scripts($hook)
 {
     global $post;
     wp_enqueue_style('download_monitor_menu_css', WP_DLM::get_plugin_url() . '/assets/css/menu.css');
     if ($hook == 'index.php') {
         wp_enqueue_style('download_monitor_dashboard_css', WP_DLM::get_plugin_url() . '/assets/css/dashboard.css');
     }
     $enqueue = false;
     if ($hook == 'post-new.php' || $hook == 'post.php' || $hook == 'edit.php') {
         if (!empty($_GET['post_type']) && $_GET['post_type'] == 'dlm_download' || !empty($post->post_type) && 'dlm_download' === $post->post_type) {
             $enqueue = true;
         }
     }
     if (strstr($hook, 'dlm_download_page')) {
         $enqueue = true;
     }
     if ($hook == 'edit-tags.php' && strstr($_GET['taxonomy'], 'dlm_download')) {
         $enqueue = true;
     }
     if (!$enqueue) {
         return;
     }
     wp_enqueue_script('jquery-blockui', WP_DLM::get_plugin_url() . '/assets/js/blockui.min.js', array('jquery'), '2.61');
     wp_enqueue_script('jquery-ui-sortable');
     wp_enqueue_script('jquery-ui-datepicker');
     wp_enqueue_style('jquery-ui-style', is_ssl() ? 'https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/themes/smoothness/jquery-ui.css' : 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/themes/smoothness/jquery-ui.css');
     wp_enqueue_style('download_monitor_admin_css', WP_DLM::get_plugin_url() . '/assets/css/admin.css', array('dashicons'));
 }
    /**
     * media_browser function.
     *
     * @access public
     * @return void
     */
    public function media_browser()
    {
        // Enqueue scripts and styles for panel
        wp_enqueue_style('download_monitor_admin_css', WP_DLM::get_plugin_url() . '/assets/css/admin.css', array('dashicons'));
        wp_enqueue_script('common');
        wp_enqueue_style('global');
        wp_enqueue_style('wp-admin');
        wp_enqueue_style('colors');
        wp_enqueue_script('plupload-all');
        echo '<!DOCTYPE html><html lang="en"><head><title>' . __('Insert Download', 'download-monitor') . '</title><meta charset="utf-8" />';
        do_action('admin_print_styles');
        do_action('admin_print_scripts');
        do_action('admin_head');
        echo '<body id="insert-download" class="wp-core-ui">';
        ?>
		<h2 class="nav-tab-wrapper">
			<a href="#insert-shortcode"
			   class="nav-tab nav-tab-active"><?php 
        _e('Insert Shortcode', 'download-monitor');
        ?>
</a><a
				href="#quick-add" class="nav-tab"><?php 
        _e('Quick-add download', 'download-monitor');
        ?>
</a>
		</h2>
		<?php 
        // Handle quick-add form
        if (!empty($_POST['download_url']) && !empty($_POST['download_title']) && wp_verify_nonce($_POST['quick-add-nonce'], 'quick-add')) {
            $url = stripslashes($_POST['download_url']);
            $title = sanitize_text_field(stripslashes($_POST['download_title']));
            $version = sanitize_text_field(stripslashes($_POST['download_version']));
            try {
                $download = array('post_title' => $title, 'post_content' => '', 'post_status' => 'publish', 'post_author' => get_current_user_id(), 'post_type' => 'dlm_download');
                $download_id = wp_insert_post($download);
                if ($download_id) {
                    // Meta
                    update_post_meta($download_id, '_featured', 'no');
                    update_post_meta($download_id, '_members_only', 'no');
                    update_post_meta($download_id, '_redirect_only', 'no');
                    update_post_meta($download_id, '_download_count', 0);
                    // File
                    $file = array('post_title' => 'Download #' . $download_id . ' File Version', 'post_content' => '', 'post_status' => 'publish', 'post_author' => get_current_user_id(), 'post_parent' => $download_id, 'post_type' => 'dlm_download_version');
                    $file_id = wp_insert_post($file);
                    if (!$file_id) {
                        throw new Exception(__('Error: File was not created.', 'download-monitor'));
                    }
                    // File Manager
                    $file_manager = new DLM_File_Manager();
                    // Meta
                    update_post_meta($file_id, '_version', $version);
                    update_post_meta($file_id, '_filesize', $file_manager->get_file_size($url));
                    update_post_meta($file_id, '_files', $file_manager->json_encode_files(array($url)));
                    // Hashes
                    $hashes = $file_manager->get_file_hashes($url);
                    // Set hashes
                    update_post_meta($file_id, '_md5', $hashes['md5']);
                    update_post_meta($file_id, '_sha1', $hashes['sha1']);
                    update_post_meta($file_id, '_crc32', $hashes['crc32']);
                    // Success message
                    echo '<div class="updated"><p>' . __('Download successfully created.', 'download-monitor') . '</p></div>';
                } else {
                    throw new Exception(__('Error: Download was not created.', 'download-monitor'));
                }
            } catch (Exception $e) {
                echo '<div class="error"><p>' . $e->getMessage() . "</p></div>";
            }
        }
        // Get all downloads
        $downloads = get_posts(array('post_status' => 'publish', 'post_type' => 'dlm_download', 'orderby' => 'ID', 'posts_per_page' => -1));
        ?>
		<form id="insert-shortcode">

			<fieldset>
				<legend><?php 
        _e('Choose a download', 'download-monitor');
        ?>
:</legend>
				<?php 
        $limit = 10;
        $page = isset($_GET['paged']) ? absint($_GET['paged']) : 1;
        $dlm_query = new WP_Query(array('post_status' => 'publish', 'post_type' => 'dlm_download', 'posts_per_page' => $limit, 'offset' => ($page - 1) * $limit));
        while ($dlm_query->have_posts()) {
            $dlm_query->the_post();
            $download = new DLM_Download($dlm_query->post->ID);
            echo '<label><input name="download_id" class="radio" type="radio" value="' . absint($download->id) . '" /> #' . $download->id . ' &ndash; ' . $download->get_the_title() . ' &ndash; ' . $download->get_the_filename() . '</label>';
        }
        if ($dlm_query->max_num_pages > 1) {
            echo paginate_links(apply_filters('download_monitor_pagination_args', array('base' => str_replace(999999999, '%#%', get_pagenum_link(999999999, false)), 'format' => '', 'current' => $page, 'total' => $dlm_query->max_num_pages, 'prev_text' => '&larr;', 'next_text' => '&rarr;', 'type' => 'list', 'end_size' => 3, 'mid_size' => 3)));
        }
        ?>
			</fieldset>

			<p>
				<label for="template_name"><?php 
        _e('Template', 'download-monitor');
        ?>
:</label>
				<input type="text" id="template_name" value="" class="input"
				       placeholder="<?php 
        _e('Template Name', 'download-monitor');
        ?>
"/>
				<span class="description">
					<?php 
        _e('Leaving this blank will use the default <code>content-download.php</code> template file. If you enter, for example, <code>image</code>, the <code>content-download-image.php</code> template will be used instead.', 'download-monitor');
        ?>
				</span>
			</p>

			<p>
				<input type="button" class="button insert_download button-primary button-large"
				       value="<?php 
        _e('Insert Shortcode', 'download-monitor');
        ?>
"/>
			</p>

		</form>

		<form id="quick-add" action="" method="post">

			<!-- Uploader section -->
			<div id="plupload-upload-ui" class="hide-if-no-js">
				<div id="drag-drop-area" style="height:240px">
					<div class="drag-drop-inside">
						<p class="drag-drop-info"><?php 
        _e('Drop file here', 'download-monitor');
        ?>
</p>

						<p><?php 
        echo _x('or', 'Drop file here *or* select file', 'download-monitor');
        ?>
</p>

						<p class="drag-drop-buttons"><input id="plupload-browse-button" type="button"
						                                    value="<?php 
        esc_attr_e('Select File', 'download-monitor');
        ?>
"
						                                    class="button"/></p>
					</div>
				</div>
				<p><a href="#" class="add_manually"><?php 
        _e('Enter URL manually', 'download-monitor');
        ?>
 &rarr;</a>
				</p>
			</div>
			<div id="quick-add-details" style="display:none">
				<p>
					<label for="download_url"><?php 
        _e('Download URL', 'download-monitor');
        ?>
:</label>
					<input type="text" name="download_url" id="download_url" value="" class="download_url input"
					       placeholder="<?php 
        _e('Required URL', 'download-monitor');
        ?>
"/>
				</p>

				<p>
					<label for="download_title"><?php 
        _e('Download Title', 'download-monitor');
        ?>
:</label>
					<input type="text" name="download_title" id="download_title" value="" class="download_title input"
					       placeholder="<?php 
        _e('Required title', 'download-monitor');
        ?>
"/>
				</p>

				<p>
					<label for="download_version"><?php 
        _e('Version', 'download-monitor');
        ?>
:</label>
					<input type="text" name="download_version" id="download_version" value="" class="input"
					       placeholder="<?php 
        _e('Optional version number', 'download-monitor');
        ?>
"/>
				</p>

				<p>
					<input type="submit" class="button button-primary button-large"
					       value="<?php 
        _e('Save Download', 'download-monitor');
        ?>
"/>
					<?php 
        wp_nonce_field('quick-add', 'quick-add-nonce');
        ?>
				</p>
			</div>

		</form>

		<script type="text/javascript">
			jQuery( function () {

				jQuery( '.nav-tab-wrapper a' ).click( function () {
					jQuery( '#insert-shortcode, #quick-add' ).hide();
					jQuery( jQuery( this ).attr( 'href' ) ).show();
					jQuery( 'a.nav-tab-active' ).removeClass( 'nav-tab-active' );
					jQuery( this ).addClass( 'nav-tab-active' );
					return false;
				} );

				jQuery( '#quick-add' ).hide();

				jQuery( 'body' ).on( 'click', '.insert_download', function () {

					var win = window.dialogArguments || opener || parent || top;

					var download_id = jQuery( 'input[name="download_id"]:checked' ).val();
					var template = jQuery( '#template_name' ).val();
					var shortcode = '[download id="' + download_id + '"';

					if ( template )
						shortcode = shortcode + ' template="' + template + '"';

					shortcode = shortcode + ']';

					win.send_to_editor( shortcode );

					return false;
				} );

				jQuery( '.add_manually' ).click( function () {
					jQuery( '#plupload-upload-ui' ).slideUp();
					jQuery( '#quick-add-details' ).slideDown();
					return false;
				} );

				<?php 
        $plupload_init = array('runtimes' => 'html5,silverlight,flash,html4', 'browse_button' => 'plupload-browse-button', 'container' => 'plupload-upload-ui', 'drop_element' => 'drag-drop-area', 'file_data_name' => 'async-upload', 'multiple_queues' => false, 'max_file_size' => wp_max_upload_size() . 'b', 'url' => admin_url('admin-ajax.php'), 'flash_swf_url' => includes_url('js/plupload/plupload.flash.swf'), 'silverlight_xap_url' => includes_url('js/plupload/plupload.silverlight.xap'), 'filters' => array(array('title' => __('Allowed Files'), 'extensions' => '*')), 'multipart' => true, 'urlstream_upload' => true, 'multipart_params' => array('_ajax_nonce' => wp_create_nonce('file-upload'), 'action' => 'download_monitor_insert_panel_upload', 'type' => 'dlm_download'));
        // we should probably not apply this filter, plugins may expect wp's media uploader...
        $plupload_init = apply_filters('plupload_init', $plupload_init);
        ?>

				// create the uploader and pass the config from above
				var uploader = new plupload.Uploader( <?php 
        echo json_encode($plupload_init);
        ?>
 );

				// checks if browser supports drag and drop upload, makes some css adjustments if necessary
				uploader.bind( 'Init', function ( up ) {
					var uploaddiv = jQuery( '#plupload-upload-ui' );

					if ( up.features.dragdrop ) {
						uploaddiv.addClass( 'drag-drop' );

						jQuery( '#drag-drop-area' )
							.bind( 'dragover.wp-uploader', function () {
								uploaddiv.addClass( 'drag-over' );
							} )
							.bind( 'dragleave.wp-uploader, drop.wp-uploader', function () {
								uploaddiv.removeClass( 'drag-over' );
							} );

					} else {
						uploaddiv.removeClass( 'drag-drop' );
						jQuery( '#drag-drop-area' ).unbind( '.wp-uploader' );
					}
				} );

				uploader.init();

				// a file was added in the queue
				uploader.bind( 'FilesAdded', function ( up, files ) {
					var hundredmb = 100 * 1024 * 1024, max = parseInt( up.settings.max_file_size, 10 );

					plupload.each( files, function ( file ) {
						if ( max > hundredmb && file.size > hundredmb && up.runtime != 'html5' ) {
							// file size error?
						} else {
							jQuery( '.drag-drop-inside' ).html( '<p><?php 
        _e('Please wait...', 'download-monitor');
        ?>
</p>' );
						}
					} );

					up.refresh();
					up.start();
				} );

				// a file was uploaded
				uploader.bind( 'FileUploaded', function ( up, file, response ) {
					jQuery( '#quick-add-details' ).find( 'input.download_url' ).val( response.response );
					jQuery( '#quick-add-details' ).find( 'input.download_title' ).val( basename( response.response ) );
					jQuery( '#plupload-upload-ui' ).slideUp();
					jQuery( '#quick-add-details' ).slideDown();
				} );

				function basename( path ) {
					return path.split( '/' ).reverse()[ 0 ];
				}

			} );
		</script>
		<?php 
        echo '</body></html>';
    }
    /**
     * download_files function.
     *
     * @access public
     * @return void
     */
    public function download_files()
    {
        global $post;
        wp_nonce_field('save_meta_data', 'dlm_nonce');
        ?>
		<div class="download_monitor_files dlm-metaboxes-wrapper">

			<input type="hidden" name="dlm_post_id" id="dlm-post-id" value="<?php 
        echo $post->ID;
        ?>
" />
			<input type="hidden" name="dlm_post_id" id="dlm-plugin-url" value="<?php 
        echo WP_DLM::get_plugin_url();
        ?>
" />
			<input type="hidden" name="dlm_post_id" id="dlm-ajax-nonce-add-file" value="<?php 
        echo wp_create_nonce("add-file");
        ?>
" />
			<input type="hidden" name="dlm_post_id" id="dlm-ajax-nonce-remove-file" value="<?php 
        echo wp_create_nonce("remove-file");
        ?>
" />

			<?php 
        do_action('dlm_download_monitor_files_writepanel_start');
        ?>

			<p class="toolbar">
				<a href="#" class="button plus add_file"><?php 
        _e('Add file', 'download-monitor');
        ?>
</a>
				<a href="#" class="close_all"><?php 
        _e('Close all', 'download-monitor');
        ?>
</a>
				<a href="#" class="expand_all"><?php 
        _e('Expand all', 'download-monitor');
        ?>
</a>
			</p>

			<div class="dlm-metaboxes downloadable_files">
				<?php 
        $i = -1;
        $files = get_posts('post_parent=' . $post->ID . '&post_type=dlm_download_version&orderby=menu_order&order=ASC&post_status=any&numberposts=-1');
        if ($files) {
            foreach ($files as $file) {
                $i++;
                $file_id = $file->ID;
                $file_version = ($file_version = get_post_meta($file->ID, '_version', true)) ? $file_version : '';
                $file_post_date = $file->post_date;
                $file_download_count = absint(get_post_meta($file->ID, '_download_count', true));
                $file_urls = get_post_meta($file->ID, '_files', true);
                if (is_string($file_urls)) {
                    $file_urls = array_filter((array) json_decode($file_urls));
                } elseif (is_array($file_urls)) {
                    $file_urls = array_filter($file_urls);
                } else {
                    $file_urls = array();
                }
                include 'html-downloadable-file-version.php';
            }
        }
        ?>
			</div>

			<?php 
        do_action('dlm_download_monitor_files_writepanel_end');
        ?>

		</div>
	<?php 
    }