예제 #1
0
function _wppa_page_import()
{
    global $wppa_revno;
    global $wppa;
    global $wpdb;
    global $wppa_supported_photo_extensions;
    global $wppa_supported_video_extensions;
    global $wppa_supported_audio_extensions;
    if ($wppa['ajax']) {
        ob_start();
    }
    // Suppress output if ajax operation
    // Init
    $ngg_opts = get_option('ngg_options', false);
    $user = wppa_get_user();
    // Check database
    wppa_check_database(true);
    // Sanitize system
    $count = wppa_sanitize_files();
    if ($count) {
        wppa_error_message($count . ' ' . __('illegal files deleted.', 'wppa'));
    }
    // Update watermark settings
    if (wppa_switch('wppa_watermark_on') && (wppa_switch('wppa_watermark_user') || current_user_can('wppa_settings'))) {
        if (isset($_POST['wppa-watermark-file'])) {
            update_option('wppa_watermark_file_' . $user, $_POST['wppa-watermark-file']);
        }
        if (isset($_POST['wppa-watermark-pos'])) {
            update_option('wppa_watermark_pos_' . $user, $_POST['wppa-watermark-pos']);
        }
    }
    // Update last used albums
    if (isset($_POST['wppa-photo-album'])) {
        update_option('wppa-photo-album-import-' . wppa_get_user(), $_POST['wppa-photo-album']);
        // nog in form verwerken
    }
    if (isset($_POST['wppa-video-album'])) {
        update_option('wppa-video-album-import-' . wppa_get_user(), $_POST['wppa-video-album']);
    }
    if (isset($_POST['wppa-audio-album'])) {
        update_option('wppa-audio-album-import-' . wppa_get_user(), $_POST['wppa-audio-album']);
    }
    // Verify last albums still exist
    $alb = strval(intval(get_option('wppa-photo-album-import-' . wppa_get_user(), '0')));
    if ($alb) {
        $exists = $wpdb->get_var("SELECT COUNT(*) FROM `" . WPPA_ALBUMS . "`  WHERE `id` = " . $alb);
        if (!$exists) {
            update_option('wppa-photo-album-import-' . wppa_get_user(), '0');
        }
    }
    $alb = get_option('wppa-video-album-import-' . wppa_get_user(), '0');
    if ($alb) {
        $exists = $wpdb->get_var("SELECT COUNT(*) FROM `" . WPPA_ALBUMS . "`  WHERE `id` = " . $alb);
        if (!$exists) {
            update_option('wppa-video-album-import-' . wppa_get_user(), '0');
        }
    }
    $alb = get_option('wppa-audio-album-import-' . wppa_get_user(), '0');
    if ($alb) {
        $exists = $wpdb->get_var("SELECT COUNT(*) FROM `" . WPPA_ALBUMS . "`  WHERE `id` = " . $alb);
        if (!$exists) {
            update_option('wppa-audio-album-import-' . wppa_get_user(), '0');
        }
    }
    // Extract zip
    if (isset($_GET['zip'])) {
        wppa_extract($_GET['zip'], true);
    }
    // Set local / remote
    if (isset($_POST['wppa-local-remote'])) {
        check_admin_referer('$wppa_nonce', WPPA_NONCE);
        update_option('wppa_import_source_type_' . $user, $_POST['wppa-local-remote']);
    }
    // Set import source dir ( when local )
    if (isset($_POST['wppa-import-set-source-dir'])) {
        check_admin_referer('$wppa_nonce', WPPA_NONCE);
        if (isset($_POST['wppa-source'])) {
            update_option('wppa_import_source_' . $user, $_POST['wppa-source']);
        }
    }
    // Set import source url ( when remote )
    if (isset($_POST['wppa-import-set-source-url'])) {
        check_admin_referer('$wppa_nonce', WPPA_NONCE);
        if (isset($_POST['wppa-source-remote'])) {
            update_option('wppa_import_source_url_' . $user, $_POST['wppa-source-remote']);
            update_option('wppa_import_source_url_found_' . $user, false);
            update_option('wppa_import_remote_max_' . $user, strval(intval($_POST['wppa-import-remote-max'])));
        }
    }
    // Hit the submit button
    if (isset($_POST['wppa-import-submit'])) {
        if ($wppa['ajax']) {
            if (!wp_verify_nonce($_POST['wppa-update-check'], '$wppa_nonce')) {
                echo $_POST['wppa-update-check'] . ' Security check failure';
                exit;
            }
        } else {
            check_admin_referer('$wppa_nonce', WPPA_NONCE);
        }
        if (isset($_POST['del-after-p'])) {
            $delp = true;
        } else {
            $delp = false;
        }
        if (isset($_POST['del-after-a'])) {
            $dela = true;
        } else {
            $dela = false;
        }
        if (isset($_POST['del-after-z'])) {
            $delz = true;
        } else {
            $delz = false;
        }
        if (isset($_POST['del-after-v'])) {
            $delv = true;
        } else {
            $delv = false;
        }
        if (isset($_POST['del-after-u'])) {
            $delu = true;
        } else {
            $delu = false;
        }
        if (isset($_POST['del-after-c'])) {
            $delc = true;
        } else {
            $delc = false;
        }
        wppa_import_photos($delp, $dela, $delz, $delv, $delu, $delc);
    } elseif (isset($_GET['continue'])) {
        if (wp_verify_nonce($_GET['nonce'], 'dirimport')) {
            wppa_import_photos();
        }
    }
    // If we did this by ajax, setup reporting results for it
    if ($wppa['ajax']) {
        ob_end_clean();
        if ($wppa['ajax_import_files_done']) {
            echo '<span style="color:green" >' . $wppa['ajax_import_files'] . ' ' . __('Done!', 'wppa') . '</span>';
        } elseif ($wppa['ajax_import_files_error']) {
            echo '<span style="color:red" >' . $wppa['ajax_import_files'] . ' ' . $wppa['ajax_import_files_error'] . '</span>';
        } else {
            echo '<span style="color:red" >' . $wppa['ajax_import_files'] . ' ' . __('Failed!', 'wppa') . '</span>';
        }
        exit;
    }
    // Sanitize again
    $count = wppa_sanitize_files();
    if ($count) {
        wppa_error_message($count . ' ' . __('illegal files deleted.', 'wppa'));
    }
    ?>
	
	<div class="wrap">
		<?php 
    $iconurl = WPPA_URL . '/images/camera32.png';
    ?>
		<div id="icon-camera" class="icon32" style="background: transparent url( <?php 
    echo $iconurl;
    ?>
 ) no-repeat"></div>
		<?php 
    $iconurl = WPPA_URL . '/images/arrow32.png';
    ?>
		<div id="icon-arrow" class="icon32" style="background: transparent url( <?php 
    echo $iconurl;
    ?>
 ) no-repeat"></div>
		<?php 
    $iconurl = WPPA_URL . '/images/album32.png';
    ?>
		<div id="icon-album" class="icon32" style="background: transparent url( <?php 
    echo $iconurl;
    ?>
 ) no-repeat"><br /></div>
		
		<h2><?php 
    _e('Import Photos', 'wppa');
    ?>
</h2><br />
		<?php 
    // Get this users current source directory setting
    $can_remote = ini_get('allow_url_fopen') && function_exists('curl_init');
    // $can_remote = false; // Debug
    if (!$can_remote) {
        update_option('wppa_import_source_type_' . $user, 'local');
    }
    $source_type = get_option('wppa_import_source_type_' . $user, 'local');
    if ($source_type == 'local') {
        $source = get_option('wppa_import_source_' . $user, WPPA_DEPOT);
        if (!$source || !is_dir(WPPA_ABSPATH . $source)) {
            $source = WPPA_DEPOT;
            update_option('wppa_import_source_' . $user, WPPA_DEPOT);
        }
        $source_path = WPPA_ABSPATH . $source;
        $source_url = get_bloginfo('url') . '/' . $source;
        // See if the current source is the 'home' directory
        $is_depot = $source == WPPA_DEPOT;
        // See if the current souce is a wp upload location or a wppa+ sourcefile location ( if so: no delete checkbox )
        $is_sub_depot = substr($source, 0, strlen(WPPA_DEPOT)) == WPPA_DEPOT && substr(WPPA_ABSPATH . $source, 0, strlen(wppa_opt('wppa_source_dir'))) != wppa_opt('wppa_source_dir');
        // See what's in there
        $files = wppa_get_import_files();
        $zipcount = wppa_get_zipcount($files);
        $albumcount = wppa_get_albumcount($files);
        $photocount = wppa_get_photocount($files);
        $videocount = wppa_get_video_count($files);
        $audiocount = wppa_get_audio_count($files);
        $dircount = $is_depot ? wppa_get_dircount($files) : '0';
        $csvcount = $is_depot ? wppa_get_csvcount($files) : '0';
        // echo 'zips:'.$zipcount,' albs:'.$albumcount.' pho:'.$photocount.' dirs:'.$dircount;
        if ($ngg_opts) {
            $is_ngg = strpos($source, $ngg_opts['gallerypath']) !== false;
            // this is false for the ngg root !!
        } else {
            $is_ngg = false;
        }
    }
    if ($source_type == 'remote') {
        $wppa['is_remote'] = true;
        $source = get_option('wppa_import_source_url_' . $user, 'http://');
        $source_path = $source;
        $source_url = $source;
        $is_depot = false;
        $is_sub_depot = false;
        $files = wppa_get_import_files();
        $zipcount = '0';
        $albumcount = '0';
        $photocount = $files ? count($files) : '0';
        $videocount = '0';
        $audiocount = '0';
        $dircount = '0';
        $csvcount = '0';
        $is_ngg = false;
        $remote_max = get_option('wppa_import_remote_max_' . $user, '10');
    }
    ?>
		
	<form action="<?php 
    echo wppa_dbg_url(get_admin_url() . 'admin.php?page=wppa_import_photos');
    ?>
" method="post">
		<?php 
    if (current_user_can('administrator') || !wppa_switch('wppa_chgsrc_is_restricted')) {
        ?>

		<div style="border:1px solid gray; padding:4px; margin: 3px 0;" >
			<?php 
        wp_nonce_field('$wppa_nonce', WPPA_NONCE);
        _e('Select Local or Remote', 'wppa');
        $disabled = $can_remote ? '' : 'disabled="disabled"';
        ?>
			<select name="wppa-local-remote" >
				<option value="local" <?php 
        if ($source_type == 'local') {
            echo 'selected="selected"';
        }
        ?>
><?php 
        _e('Local', 'wppa');
        ?>
</option>
				<option value="remote" <?php 
        echo $disabled;
        if ($source_type == 'remote') {
            echo 'selected="selected"';
        }
        ?>
><?php 
        _e('Remote', 'wppa');
        ?>
</option>
			</select>
			<?php 
        if ($can_remote) {
            ?>
				<input type="submit" class="button-secundary" name="wppa-import-set-source" value="<?php 
            _e('Set Local/Remote', 'wppa');
            ?>
" />
			<?php 
        } else {
            if (!ini_get('allow_url_fopen')) {
                _e('The server does not allow you to import from remote locations. ( The php directive allow_url_fopen is not set to 1 )', 'wppa');
            }
            if (!function_exists('curl_init')) {
                _e('The server does not allow you to import from remote locations. ( The curl functions are not set up )', 'wppa');
            }
        }
        ?>
		</div>
		<div style="border:1px solid gray; padding:4px; margin: 3px 0;" >
			<?php 
        wp_nonce_field('$wppa_nonce', WPPA_NONCE);
        ?>
			<?php 
        _e('Import photos from:', 'wppa');
        ?>
			<?php 
        if ($source_type == 'local') {
            ?>
			<select name="wppa-source">
				<option value="<?php 
            echo WPPA_DEPOT;
            ?>
" <?php 
            if ($is_depot) {
                echo 'selected="selected"';
            }
            ?>
><?php 
            _e('--- My depot ---', 'wppa');
            ?>
</option>
				<?php 
            wppa_walktree(WPPA_DEPOT, $source, true, true);
            // Allow the name 'wppa', exclude topdir
            if ($ngg_opts) {
                $nextgen_root = trim($ngg_opts['gallerypath'], '/');
                wppa_walktree($nextgen_root, $source, true, true, false);
                // Allow the name 'wppa', exclude topdir, do not allow 'thumbs' */
            }
            wppa_walktree(WPPA_UPLOAD, $source, false, false);
            // Do NOT allow the name 'wppa', include topdir
            ?>
			</select>
			<input type="submit" class="button-secundary" name="wppa-import-set-source-dir" value="<?php 
            _e('Set source directory', 'wppa');
            ?>
" />
			<?php 
        } else {
            ?>
			<input type="text" style="width:50%" name="wppa-source-remote" value="<?php 
            echo $source;
            ?>
" />
			<?php 
            _e('Max:', 'wppa');
            ?>
			<input type="text" style="width:50px;" name="wppa-import-remote-max" value="<?php 
            echo $remote_max;
            ?>
" />
			<input type="submit" onclick="jQuery( '#rem-rem' ).css( 'display','inline' ); return true;" class="button-secundary" name="wppa-import-set-source-url" value="<?php 
            _e('Find remote photos', 'wppa');
            ?>
" />
			<span id="rem-rem" style="display:none;"><?php 
            _e('Working, please wait...', 'wppa');
            ?>
</span>
			<?php 
            _e('<br />You can enter either a web page address like <i>http://mysite.com/mypage/</i> or a full url to an image file like <i>http://mysite.com/wp-content/uploads/wppa/4711.jpg</i>', 'wppa');
            ?>
			<?php 
        }
        ?>
		</div>
		
		<?php 
    }
    ?>
	</form>

<?php 
    // check if albums exist or will be made before allowing upload
    if (wppa_has_albums() || $albumcount > '0' || $zipcount > '0' || $dircount > '0' || $videocount > '0' || $audiocount > '0' || $csvcount > '0') {
        if ($photocount > '0' || $albumcount > '0' || $zipcount > '0' || $dircount > '0' || $videocount > '0' || $audiocount > '0' || $csvcount > '0') {
            ?>
			
				<form action="<?php 
            echo wppa_dbg_url(get_admin_url() . 'admin.php?page=wppa_import_photos');
            ?>
" method="post">
				<?php 
            wp_nonce_field('$wppa_nonce', WPPA_NONCE);
            // Display the zips
            if (PHP_VERSION_ID >= 50207 && $zipcount > '0') {
                ?>
	
					<div style="border:1px solid gray; padding:4px; margin: 3px 0;" >
						<p><b>
							<?php 
                _e('There are', 'wppa');
                echo ' ' . $zipcount . ' ';
                _e('zipfiles in the depot.', 'wppa');
                ?>
<br/>
						</b></p>
						<table class="form-table wppa-table widefat" style="margin-bottom:0;" >
							<thead>
								<tr>
									<td>
										<input type="checkbox" id="all-zip" checked="checked" onchange="checkAll( 'all-zip', '.wppa-zip' )" /><b>&nbsp;&nbsp;<?php 
                _e('Check/uncheck all', 'wppa');
                ?>
</b>
									</td>
									<?php 
                if ($is_sub_depot) {
                    ?>
										<td>
											<input type="checkbox" id="del-after-z" name="del-after-z" checked="checked" /><b>&nbsp;&nbsp;<?php 
                    _e('Delete after successful extraction.', 'wppa');
                    ?>
</b>
										</td>
									<?php 
                }
                ?>
								</tr>
							</thead>
						</table>
						<table class="form-table wppa-table widefat" style="margin-top:0;" >
							<tr>
								<?php 
                $ct = 0;
                $idx = '0';
                foreach ($files as $file) {
                    $ext = strtolower(substr(strrchr($file, "."), 1));
                    if ($ext == 'zip') {
                        ?>
										<td>
											<input type="checkbox" id="file-<?php 
                        echo $idx;
                        ?>
" name="file-<?php 
                        echo $idx;
                        ?>
" class="wppa-zip" checked="checked" />&nbsp;&nbsp;<?php 
                        echo wppa_sanitize_file_name(basename($file));
                        ?>
										</td>
										<?php 
                        if ($ct == 3) {
                            echo '</tr><tr>';
                            $ct = 0;
                        } else {
                            $ct++;
                        }
                    }
                    $idx++;
                }
                ?>
							</tr>
						</table>
					</div>
				<?php 
            }
            // Dispay the albums ( .amf files )
            if ($albumcount > '0') {
                ?>
					<div style="border:1px solid gray; padding:4px; margin: 3px 0;" >
						<p><b>
							<?php 
                _e('There are', 'wppa');
                echo ' ' . $albumcount . ' ';
                _e('albumdefinitions in the depot.', 'wppa');
                ?>
<br/>
						</b></p>
						<table class="form-table wppa-table widefat" style="margin-bottom:0;" >
							<thead>
								<tr>
									<td>
										<input type="checkbox" id="all-amf" checked="checked" onchange="checkAll( 'all-amf', '.wppa-amf' )" /><b>&nbsp;&nbsp;<?php 
                _e('Check/uncheck all', 'wppa');
                ?>
</b>
									</td>
									<?php 
                if ($is_sub_depot) {
                    ?>
										<td>
											<input type="checkbox" id="del-after-a" name="del-after-a" checked="checked" /><b>&nbsp;&nbsp;<?php 
                    _e('Remove from depot after successful import, or if the album already exists.', 'wppa');
                    ?>
</b>
										</td>
									<?php 
                }
                ?>
								</tr>
							</thead>
						</table>
						<table class="form-table wppa-table widefat"  style="margin-top:0;" >
							<tr>
								<?php 
                $ct = 0;
                $idx = '0';
                foreach ($files as $file) {
                    $ext = strtolower(substr(strrchr($file, "."), 1));
                    if ($ext == 'amf') {
                        ?>
										<td>
											<input type="checkbox" id="file-<?php 
                        echo $idx;
                        ?>
" name="file-<?php 
                        echo $idx;
                        ?>
" class="wppa-amf" checked="checked" />&nbsp;&nbsp;<?php 
                        echo basename($file);
                        ?>
&nbsp;<?php 
                        echo stripslashes(wppa_get_meta_name($file, '( '));
                        ?>
										</td>
										<?php 
                        if ($ct == 3) {
                            echo '</tr><tr>';
                            $ct = 0;
                        } else {
                            $ct++;
                        }
                    }
                    $idx++;
                }
                ?>
							</tr>
						</table>
					</div>
				<?php 
            }
            // Display the single photos
            if ($photocount > '0') {
                ?>
					<div style="border:1px solid gray; padding:4px; margin: 3px 0;" >
						<p><b>
							<?php 
                _e('There are', 'wppa');
                echo ' ' . $photocount . ' ';
                if ($source_type == 'local') {
                    if ($is_ngg) {
                        _e('photos in the ngg gallery.', 'wppa');
                    } else {
                        _e('photos in the depot.', 'wppa');
                    }
                } else {
                    _e('possible photos found remote.', 'wppa');
                }
                if (wppa_switch('wppa_resize_on_upload')) {
                    echo ' ';
                    _e('Photos will be downsized during import.', 'wppa');
                }
                ?>
<br/>
						</b></p>
						<p class="hideifupdate" >
							<?php 
                _e('Default album for import:', 'wppa');
                ?>
							<select name="wppa-photo-album" id="wppa-photo-album">
								<?php 
                echo wppa_album_select_a(array('path' => wppa_switch('wppa_hier_albsel'), 'selected' => get_option('wppa-photo-album-import-' . wppa_get_user(), '0'), 'addpleaseselect' => true, 'checkowner' => true, 'checkupload' => true));
                ?>
							</select>
							<?php 
                _e('Photos that have (<em>name</em>)[<em>album</em>] will be imported by that <em>name</em> in that <em>album</em>.', 'wppa');
                ?>
						</p>
						<?php 
                if (wppa_switch('wppa_watermark_on') && (wppa_switch('wppa_watermark_user') || current_user_can('wppa_settings'))) {
                    ?>
							<p>
								<?php 
                    _e('Apply watermark file:', 'wppa');
                    ?>
								<select name="wppa-watermark-file" id="wppa-watermark-file">
									<?php 
                    echo wppa_watermark_file_select();
                    ?>
								</select>
								<?php 
                    _e('Position:', 'wppa');
                    ?>
								<select name="wppa-watermark-pos" id="wppa-watermark-pos">
									<?php 
                    echo wppa_watermark_pos_select();
                    ?>
								</select>
							</p>
						<?php 
                }
                ?>
						<table class="form-table wppa-table widefat" style="margin-bottom:0;" >
							<thead>
								<tr>
									<td>
										<input type="checkbox" id="all-pho" <?php 
                if ($is_sub_depot) {
                    echo 'checked="checked"';
                }
                ?>
 onchange="checkAll( 'all-pho', '.wppa-pho' )" /><b>&nbsp;&nbsp;<?php 
                _e('Check/uncheck all', 'wppa');
                ?>
</b>
									</td>
									<?php 
                if ($is_sub_depot) {
                    ?>
										<td>
											<input type="checkbox" id="del-after-p" name="del-after-p" checked="checked" /><b>&nbsp;&nbsp;<?php 
                    _e('Remove from depot after successful import.', 'wppa');
                    ?>
</b>
										</td>
									<?php 
                }
                ?>
									<?php 
                if ($is_ngg) {
                    ?>
										<td>
											<input type="checkbox" id="cre-album" name="cre-album" checked="checked" value="<?php 
                    echo esc_attr(basename($source));
                    ?>
" /><b>&nbsp;&nbsp;<?php 
                    echo sprintf(__('Import into album <i>%s</i>.', 'wppa'), basename($source));
                    ?>
</b>
											<br /><small><?php 
                    _e('The album will be created if it does not exist', 'wppa');
                    ?>
</small>
										</td>
										<td>
											<input type="checkbox" id="use-backup" name="use-backup" checked="checked" /><b>&nbsp;&nbsp;<?php 
                    _e('Use backup if available', 'wppa');
                    ?>
</b>
										</td>
									<?php 
                }
                ?>
									<td>
										<input type="checkbox" id="wppa-update" onchange="impUpd( this, '#submit' )" name="wppa-update"><b>&nbsp;&nbsp;<?php 
                _e('Update existing photos', 'wppa');
                ?>
</b>
									</td>
									<td>
									<?php 
                if (wppa_switch('wppa_void_dups')) {
                    ?>
										<input type="hidden" id="wppa-nodups" name="wppa-nodups" value="true" />
									<?php 
                } else {
                    ?>
										<input type="checkbox" id="wppa-nodups" name="wppa-nodups" checked="checked" ><b>&nbsp;&nbsp;<?php 
                    _e('Do not create duplicates', 'wppa');
                    ?>
</b>
									<?php 
                }
                ?>
									</td>
									<?php 
                if (wppa_switch('wppa_import_preview')) {
                    ?>
										<td>
											<input type="checkbox" id="wppa-zoom" onclick="wppa_setCookie('zoompreview', this.checked, '365')" ><b>&nbsp;&nbsp;<?php 
                    _e('Zoom previews', 'wppa');
                    ?>
</b>
											<script type="text/javascript">if ( wppa_getCookie('zoompreview') == true ) { jQuery('#wppa-zoom').attr('checked', 'checked') }</script>
										</td>
									<?php 
                }
                ?>
								</tr>
							</thead>
						</table>				
						<table class="form-table wppa-table widefat" style="margin-top:0;" >
							<tr> 
								<?php 
                $ct = 0;
                $idx = '0';
                if (is_array($files)) {
                    foreach ($files as $file) {
                        $ext = strtolower(substr(strrchr($file, "."), 1));
                        $meta = wppa_strip_ext($file) . 'pmf';
                        if (in_array($ext, $wppa_supported_photo_extensions)) {
                            ?>
										<td id="td-file-<?php 
                            echo $idx;
                            ?>
" >
											<input type="checkbox" id="file-<?php 
                            echo $idx;
                            ?>
" name="file-<?php 
                            echo $idx;
                            ?>
" title="<?php 
                            echo $file;
                            ?>
" class= "wppa-pho" <?php 
                            if ($is_sub_depot) {
                                echo 'checked="checked"';
                            }
                            ?>
 /><span id="name-file-<?php 
                            echo $idx;
                            ?>
" >&nbsp;&nbsp;<?php 
                            echo wppa_sanitize_file_name(basename($file));
                            ?>
&nbsp;<?php 
                            echo stripslashes(wppa_get_meta_name($meta, '( '));
                            echo stripslashes(wppa_get_meta_album($meta, '['));
                            ?>
</span>
											<?php 
                            if (wppa_switch('wppa_import_preview')) {
                                if ($wppa['is_remote']) {
                                    if (strpos($file, '//res.cloudinary.com/') !== false) {
                                        $img_url = dirname($file) . '/h_144/' . basename($file);
                                    } else {
                                        $img_url = $file;
                                    }
                                } else {
                                    $img_url = str_replace(ABSPATH, home_url() . '/', $file);
                                }
                                ?>
											<img src="<?php 
                                echo $img_url;
                                ?>
" alt="N.A." style="max-height:48px;" onmouseover="if (jQuery('#wppa-zoom').attr('checked')) jQuery(this).css('max-height', '144px')" onmouseout="if (jQuery('#wppa-zoom').attr('checked')) jQuery(this).css('max-height', '48px')" />
											<?php 
                            }
                            ?>
										</td>
										<?php 
                            if ($ct == 3) {
                                echo '</tr><tr>';
                                $ct = 0;
                            } else {
                                $ct++;
                            }
                        }
                        $idx++;
                    }
                }
                ?>
							</tr>
						</table>
					</div>
				<?php 
            }
            // Display the videos
            if ($videocount > '0' && wppa_switch('enable_video')) {
                ?>
					<div style="border:1px solid gray; padding:4px; margin: 3px 0;" >
						<p><b>
							<?php 
                _e('There are', 'wppa');
                echo ' ' . $videocount . ' ';
                _e('videos in the depot.', 'wppa');
                ?>
<br/>
						</b></p>
						<p class="hideifupdate" >
							<?php 
                _e('Album to import to:', 'wppa');
                ?>
							<select name="wppa-video-album" id="wppa-video-album">
								<?php 
                echo wppa_album_select_a(array('path' => wppa_switch('wppa_hier_albsel'), 'selected' => get_option('wppa-video-album-import-' . wppa_get_user(), '0'), 'addpleaseselect' => true, 'checkowner' => true, 'checkupload' => true));
                ?>
							</select>
						</p>
						<table class="form-table wppa-table widefat" style="margin-bottom:0;" >
							<thead>
								<tr>
									<td>
										<input type="checkbox" id="all-video" checked="checked" onchange="checkAll( 'all-video', '.wppa-video' )" /><b>&nbsp;&nbsp;<?php 
                _e('Check/uncheck all', 'wppa');
                ?>
</b>
									</td>
									<?php 
                if ($is_sub_depot) {
                    ?>
										<td>
											<input type="checkbox" id="del-after-v" name="del-after-v" checked="checked" /><b>&nbsp;&nbsp;<?php 
                    _e('Remove from depot after successful import.', 'wppa');
                    ?>
</b>
										</td>
									<?php 
                }
                ?>
								</tr>
							</thead>
						</table>
						<table class="form-table wppa-table widefat" style="margin-top:0;" >
							<tr>
								<?php 
                $ct = 0;
                $idx = '0';
                if (is_array($files)) {
                    foreach ($files as $file) {
                        $ext = strtolower(substr(strrchr($file, "."), 1));
                        if (in_array($ext, $wppa_supported_video_extensions)) {
                            ?>
										<td>
											<input type="checkbox" id="file-<?php 
                            echo $idx;
                            ?>
" name="file-<?php 
                            echo $idx;
                            ?>
" title="<?php 
                            echo $file;
                            ?>
" class="wppa-video" checked="checked" /><span id="name-file-<?php 
                            echo $idx;
                            ?>
" >&nbsp;&nbsp;<?php 
                            echo wppa_sanitize_file_name(basename($file));
                            ?>
</span>
										</td>
										<?php 
                            if ($ct == 3) {
                                echo '</tr><tr>';
                                $ct = 0;
                            } else {
                                $ct++;
                            }
                        }
                        $idx++;
                    }
                }
                ?>
							</tr>
						</table>
					</div>
				<?php 
            }
            // Display the audios
            if ($audiocount > '0' && wppa_switch('enable_audio')) {
                ?>
					<div style="border:1px solid gray; padding:4px; margin: 3px 0;" >
						<p><b>
							<?php 
                _e('There are', 'wppa');
                echo ' ' . $audiocount . ' ';
                _e('audios in the depot.', 'wppa');
                ?>
<br/>
						</b></p>
						<p class="hideifupdate" >
							<?php 
                _e('Album to import to:', 'wppa');
                ?>
							<select name="wppa-audio-album" id="wppa-audio-album">
								<?php 
                echo wppa_album_select_a(array('path' => wppa_switch('wppa_hier_albsel'), 'selected' => get_option('wppa-audio-album-import-' . wppa_get_user(), '0'), 'addpleaseselect' => true, 'checkowner' => true, 'checkupload' => true));
                ?>
							</select>
						</p>
						<table class="form-table wppa-table widefat" style="margin-bottom:0;" >
							<thead>
								<tr>
									<td>
										<input type="checkbox" id="all-audio" checked="checked" onchange="checkAll( 'all-audio', '.wppa-audio' )" /><b>&nbsp;&nbsp;<?php 
                _e('Check/uncheck all', 'wppa');
                ?>
</b>
									</td>
									<?php 
                if ($is_sub_depot) {
                    ?>
										<td>
											<input type="checkbox" id="del-after-u" name="del-after-u" checked="checked" /><b>&nbsp;&nbsp;<?php 
                    _e('Remove from depot after successful import.', 'wppa');
                    ?>
</b>
										</td>
									<?php 
                }
                ?>
								</tr>
							</thead>
						</table>
						<table class="form-table wppa-table widefat" style="margin-top:0;" >
							<tr>
								<?php 
                $ct = 0;
                $idx = '0';
                if (is_array($files)) {
                    foreach ($files as $file) {
                        $ext = strtolower(substr(strrchr($file, "."), 1));
                        if (in_array($ext, $wppa_supported_audio_extensions)) {
                            ?>
										<td>
											<input type="checkbox" id="file-<?php 
                            echo $idx;
                            ?>
" name="file-<?php 
                            echo $idx;
                            ?>
" title="<?php 
                            echo $file;
                            ?>
" class="wppa-audio" checked="checked" /><span id="name-file-<?php 
                            echo $idx;
                            ?>
" >&nbsp;&nbsp;<?php 
                            echo wppa_sanitize_file_name(basename($file));
                            ?>
</span>
										</td>
										<?php 
                            if ($ct == 3) {
                                echo '</tr><tr>';
                                $ct = 0;
                            } else {
                                $ct++;
                            }
                        }
                        $idx++;
                    }
                }
                ?>
							</tr>
						</table>
					</div>
				<?php 
            }
            // Display the directories to be imported as albums. Do this in the depot only!!
            if ($is_depot && $dircount > '0') {
                ?>
					<div style="border:1px solid gray; padding:4px; margin: 3px 0;" >
						<p><b>
							<?php 
                _e('There are', 'wppa');
                echo ' ' . $dircount . ' ';
                _e('albumdirectories in the depot.', 'wppa');
                ?>
<br/>
						</b></p>
						<table class="form-table wppa-table widefat" style="margin-bottom:0;" >
							<thead>
								<tr>
									<td>
										<input type="checkbox" id="all-dir" checked="checked" onchange="checkAll( 'all-dir', '.wppa-dir' )" /><b>&nbsp;&nbsp;<?php 
                _e('Check/uncheck all', 'wppa');
                ?>
</b>
									</td>
								</tr>
							</thead>
						</table>				
						<table class="form-table wppa-table widefat" style="margin-top:0;" >
							<?php 
                $ct = 0;
                $idx = '0';
                foreach ($files as $dir) {
                    if (basename($dir) == '.') {
                    } elseif (basename($dir) == '..') {
                    } elseif (is_dir($dir)) {
                        ?>
										<tr>
											<td>
												<input type="checkbox" id="file-<?php 
                        echo $idx;
                        ?>
" name="file-<?php 
                        echo $idx;
                        ?>
" class= "wppa-dir" checked="checked" />&nbsp;&nbsp;<b><?php 
                        echo wppa_sanitize_file_name(basename($dir));
                        ?>
</b>
												<?php 
                        $subfiles = glob($dir . '/*');
                        $subdircount = '0';
                        if ($subfiles) {
                            foreach ($subfiles as $subfile) {
                                if (is_dir($subfile) && basename($subfile) != '.' && basename($subfile) != '..') {
                                    $subdircount++;
                                }
                            }
                        }
                        $sfcount = empty($subfiles) ? '0' : wppa_get_photocount($subfiles);
                        echo ' Contains ' . $sfcount . ' files';
                        if ($subdircount) {
                            echo ' and ' . $subdircount . ' sub directories.';
                        }
                        ?>
											</td>
										</tr>
									<?php 
                    }
                    $idx++;
                }
                ?>
						</table>
					</div>				
				<?php 
            }
            ?>
				<?php 
            // Display the csv files
            if ($is_depot && $csvcount > '0') {
                ?>
					<div style="border:1px solid gray; padding:4px; margin: 3px 0;" >
						<p><b>
							<?php 
                _e('There are', 'wppa');
                echo ' ' . $csvcount . ' ';
                _e('csv files in the depot.', 'wppa');
                ?>
<br/>
						</b></p>
						<table class="form-table wppa-table widefat" style="margin-bottom:0;" >
							<thead>
								<tr>
									<td>
										<input type="checkbox" id="all-csv" checked="checked" onchange="checkAll( 'all-csv', '.wppa-csv' )" /><b>&nbsp;&nbsp;<?php 
                _e('Check/uncheck all', 'wppa');
                ?>
</b>
									</td>
									<td>
										<input type="checkbox" id="del-after-c" name="del-after-c" checked="checked" disabled="disabled" /><b>&nbsp;&nbsp;<?php 
                _e('Remove from depot after successful import.', 'wppa');
                ?>
</b>
									</td>
								</tr>
							</thead>
						</table>				
						<table class="form-table wppa-table widefat" style="margin-top:0;" >
							<?php 
                $ct = 0;
                $idx = '0';
                foreach ($files as $csv) {
                    if (is_file($csv) && strtolower(wppa_get_ext($csv) == 'csv')) {
                        ?>
										<tr>
											<td>
												<input type="checkbox" id="file-<?php 
                        echo $idx;
                        ?>
" name="file-<?php 
                        echo $idx;
                        ?>
" class= "wppa-csv" checked="checked" />&nbsp;&nbsp;<b><?php 
                        echo wppa_sanitize_file_name(basename($csv)) . ' (' . sprintf('%5.1f', filesize($csv) / 1024) . ' kb)';
                        ?>
</b>
											</td>
										</tr>
									<?php 
                    }
                    $idx++;
                }
                ?>
						</table>
					</div>				
				
				<?php 
            }
            ?>
				<?php 
            // The submit button
            ?>
				<p>
					<script type="text/javascript">
						function wppaVfyAlbum() {
							var csvs = jQuery( '.wppa-csv' );
							if ( jQuery( '#wppa-update' ).attr( 'checked' ) != 'checked' ) {
								if ( 	! parseInt( jQuery( '#wppa-photo-album' ).attr( 'value' ) ) && 
										! parseInt( jQuery( '#wppa-video-album' ).attr( 'value' ) ) && 
										! parseInt( jQuery( '#wppa-audio-album' ).attr( 'value' ) ) &&
										csvs.length == 0
									) {
									alert( 'Please select an album first' );
									return false;
								}
							}
							return true;
						}
						function wppaCheckInputVars() {
							var checks = jQuery( ':checked' );
							var nChecks = checks.length;
							var nMax = <?php 
            echo ini_get('max_input_vars');
            ?>
;
							if ( nMax == 0 ) nMax = 100;
							if ( nChecks > nMax ) { 
								alert ( 'There are '+nChecks+' boxes checked or selected, that is more than the maximum allowed number of '+nMax );
								return false;
							}
							var dirs = jQuery( '.wppa-dir' );
							var nDirsChecked = 0;
							if ( dirs.length > 0 ) {
								var i = 0;
								while ( i < dirs.length ) {
									if ( jQuery( dirs[i] ).attr( 'checked' ) == 'checked' ) {
										nDirsChecked++;
									}
									i++;
								}
							}
							var zips = jQuery( '.wppa-zip' );
							var nZipsChecked = 0;
							if ( zips.length > 0 ) {
								var i = 0;
								while ( i < zips.length ) {
									if ( jQuery( zips[i] ).attr( 'checked' ) == 'checked' ) {
										nZipsChecked++;
									}
									i++;
								}
							}
							// If no dirs to import checked, there must be an album selected
							if ( 0 == nDirsChecked && 0 == nZipsChecked && ! wppaVfyAlbum() ) return false;
							return true;
						}
					</script>
					<input type="submit" onclick="return wppaCheckInputVars()" class="button-primary" id="submit" name="wppa-import-submit" value="<?php 
            _e('Import', 'wppa');
            ?>
" />
					<script type="text/javascript" >
						var wppaImportRuns = false;
						function wppaDoAjaxImport() {
							wppaImportRuns = true;
							var data = '';
							data += 'wppa-update-check='+jQuery( '#wppa-update-check' ).attr( 'value' );
							data += '&wppa-photo-album='+jQuery( '#wppa-photo-album' ).attr( 'value' );
							data += '&wppa-video-album='+jQuery( '#wppa-video-album' ).attr( 'value' );
							data += '&wppa-audio-album='+jQuery( '#wppa-audio-album' ).attr( 'value' );
							data += '&wppa-watermark-file='+jQuery( '#wppa-watermark-file' ).attr( 'value' );
							data += '&wppa-watermark-pos='+jQuery( '#wppa-watermark-pos' ).attr( 'value' );
							if ( jQuery( '#cre-album' ).attr( 'checked' ) ) data += '&cre-album='+jQuery( '#cre-album' ).attr( 'value' );
							if ( jQuery( '#use-backup' ).attr( 'checked' ) ) data += '&use-backup=on'; //+jQuery( '#use-backup' ).attr( 'value' );
							if ( jQuery( '#wppa-update' ).attr( 'checked' ) ) data += '&wppa-update=on'; //+jQuery( '#wppa-update' ).attr( 'value' );
							if ( jQuery( '#wppa-nodups' ).attr( 'checked' ) ) data += '&wppa-nodups=on'; //+jQuery( '#wppa-nudups' ).attr( 'value' );
							if ( jQuery( '#del-after-p' ).attr( 'checked' ) ) data += '&del-after-p=on';
							if ( jQuery( '#del-after-v' ).attr( 'checked' ) ) data += '&del-after-v=on';
							if ( jQuery( '#del-after-u' ).attr( 'checked' ) ) data += '&del-after-u=on';
							data += '&wppa-import-submit=ajax';
							
							var files = jQuery( ':checked' );
							var found = false;
							var i=0;
							var elm;
							var fulldata;
							for ( i=0; i<files.length; i++ ) {
								found = false;	// assume done
								elm = files[i];
								// Is it a file checkbox?
								var temp = elm.id.split( '-' );
								if ( temp[0] != 'file' ) continue;	// no
								fulldata = data+'&import-ajax-file='+elm.title;
								found = true;
								break;
							}
							//	alert( data );
							if ( ! found ) {
								wppaStopAjaxImport();
								return;	// nothing left
							}
							// found one, do it
							var oldhtml=jQuery( '#name-'+elm.id ).html();
							var xmlhttp = wppaGetXmlHttp();
							xmlhttp.onreadystatechange = function() {
								if ( xmlhttp.readyState == 4 ) {
									if ( xmlhttp.status!=404 ) {
										if ( jQuery( '#del-after-p' ).attr( 'checked' ) ) {
											elm.checked = '';
											elm.disabled = 'disabled';
											elm.title = '';
											jQuery( '#name-'+elm.id ).html( '&nbsp;&nbsp;<b>'+xmlhttp.responseText+'</b>' );
										}
										else {
											elm.checked = '';
											
											jQuery( '#name-'+elm.id ).html( '&nbsp;&nbsp;<b>'+xmlhttp.responseText+'</b>' );
										}
										if ( wppaImportRuns ) {
											setTimeout( 'wppaDoAjaxImport()', 100 );
										}
									}
									else {
										jQuery( '#name-'+elm.id ).html( '&nbsp;&nbsp;<b>Not found</b>' );
									}
								}
							}
							var url = wppaAjaxUrl+'?action=wppa&wppa-action=import';
							xmlhttp.open( 'POST',url,true );
							xmlhttp.setRequestHeader( "Content-type","application/x-www-form-urlencoded" );
							xmlhttp.send( fulldata );
							jQuery( '#name-'+elm.id ).html( '&nbsp;&nbsp;<b style="color:blue" >Working...</b>' );
							jQuery( '#wppa-start-ajax' ).css( 'display', 'none' );
							jQuery( '#wppa-stop-ajax' ).css( 'display', 'inline' );
						}
						function wppaStopAjaxImport() {
							wppaImportRuns = false;
							jQuery( '#wppa-start-ajax' ).css( 'display', 'inline' );
							jQuery( '#wppa-stop-ajax' ).css( 'display', 'none' );
						}
					</script>
					<?php 
            if (($photocount || $videocount || $audiocount) && !$albumcount && !$dircount && !$zipcount) {
                ?>
					<input id="wppa-start-ajax" type="button" onclick="if ( wppaVfyAlbum() ) { wppaDoAjaxImport() }" class="button-secundary" value="Start Ajax" />
					<input id="wppa-stop-ajax" style="display:none;" type="button" onclick="wppaStopAjaxImport()" class="button-secundary" value="Stop Ajax" />
					<?php 
            }
            ?>
				</p>
				</form>

		<?php 
        } else {
            if ($source_type == 'local') {
                wppa_ok_message(__('There are no importable files found in directory:', 'wppa') . ' ' . $source_url);
            } else {
                wppa_ok_message(__('There are no photos found or left to process at url:', 'wppa') . ' ' . $source_url);
            }
        }
        echo '<br /><b>';
        _e('You can import the following file types:', 'wppa');
        echo '</b><br />';
        if (PHP_VERSION_ID >= 50207) {
            echo '<br />';
            _e('Compressed file types: .zip', 'wppa');
        }
        if (true) {
            echo '<br />';
            _e('Photo file types:', 'wppa');
            foreach ($wppa_supported_photo_extensions as $ext) {
                echo ' .' . $ext;
            }
        }
        if (wppa_switch('enable_video')) {
            echo '<br />';
            _e('Video file types:', 'wppa');
            foreach ($wppa_supported_video_extensions as $ext) {
                echo ' .' . $ext;
            }
        }
        if (wppa_switch('enable_audio')) {
            echo '<br />';
            _e('Audio file types:', 'wppa');
            foreach ($wppa_supported_audio_extensions as $ext) {
                echo ' .' . $ext;
            }
        }
        echo '<br />';
        _e('WPPA+ file types: .amf .pmf', 'wppa');
        echo '<br />';
        _e('Directories with optional subdirs containig photos', 'wppa');
        echo '<br />';
        _e('Custom data files of type .csv', 'wppa');
        echo '<br /><br />';
        _e('Your depot directory is:', 'wppa');
        echo '<b> .../' . WPPA_DEPOT . '/</b>';
    } else {
        ?>
		<?php 
        $url = wppa_dbg_url(get_admin_url() . 'admin.php?page=wppa_admin_menu');
        ?>
		<p><?php 
        _e('No albums exist. You must', 'wppa');
        ?>
 <a href="<?php 
        echo $url;
        ?>
"><?php 
        _e('create one', 'wppa');
        ?>
</a> <?php 
        _e('beofre you can upload your photos.', 'wppa');
        ?>
</p><?php 
    }
    if ($wppa['continue']) {
        wppa_warning_message(__('Trying to continue...', 'wppa'));
        echo '<script type="text/javascript">document.location=\'' . get_admin_url() . 'admin.php?page=wppa_import_photos&continue&nonce=' . wp_create_nonce('dirimport') . '\';</script>';
    }
    ?>
	</div>
<?php 
}
function wppa_walktree($relroot, $source, $allowwppa = false, $subdirsonly = false, $allowthumbs = true)
{
    if (!$subdirsonly) {
        if ($relroot == $source) {
            $sel = ' selected="selected"';
        } else {
            $sel = ' ';
        }
        $display = str_replace(WPPA_DEPOT, __('--- My depot --- ', 'wppa'), $relroot);
        $ngg_opts = get_option('ngg_options', false);
        if ($ngg_opts) {
            $display = str_replace($ngg_opts['gallerypath'], __('--- Ngg Galleries --- ', 'wppa'), $display);
        }
        echo '<option value="' . $relroot . '"' . $sel . '>' . $display . '</option>';
    }
    $dirs = glob(WPPA_ABSPATH . $relroot . '/*', GLOB_ONLYDIR);
    if ($dirs) {
        foreach ($dirs as $path) {
            $dir = basename($path);
            if ($dir != "." && $dir != ".." && ($dir != "wppa" || $allowwppa) && ($dir != "thumbs" || $allowthumbs)) {
                $newroot = $relroot . '/' . $dir;
                wppa_walktree($newroot, $source, $allowwppa, false, $allowthumbs);
            }
        }
    }
}