function wppa_do_frontend_file_upload($file, $alb)
{
    global $wpdb;
    // Log upload attempt
    wppa_log('Upl', 'FE Upload attempt of file ' . $file['name'] . ', size=' . filesize($file['tmp_name']));
    $album = wppa_cache_album($alb);
    if (!wppa_allow_uploads($alb) || !wppa_allow_user_uploads()) {
        wppa_alert(__('Max uploads reached', 'wp-photo-album-plus'));
        return false;
    }
    if ($file['error'] != '0') {
        wppa_alert(__('Error during upload', 'wp-photo-album-plus'));
        return false;
    }
    $imgsize = getimagesize($file['tmp_name']);
    if (!is_array($imgsize)) {
        wppa_alert(__('Uploaded file is not an image', 'wp-photo-album-plus'));
        return false;
    }
    if ($imgsize[2] < 1 || $imgsize[2] > 3) {
        wppa_alert(sprintf(__('Only gif, jpg and png image files are supported. Returned filetype = %d.', 'wp-photo-album-plus'), $imagesize[2]));
        return false;
    }
    $ms = wppa_opt('upload_fronend_maxsize');
    if ($ms) {
        // Max size configured
        if ($imgsize[0] > $ms || $imgsize[0] > $ms) {
            wppa_alert(sprintf(__('Uploaded file is larger than the allowed maximum of %d x %d pixels.', 'wp-photo-album-plus'), $ms, $ms));
            return false;
        }
    }
    if (wppa_switch('void_dups')) {
        // Check for already exists
        if (wppa_file_is_in_album(wppa_sanitize_file_name($file['name']), $alb)) {
            wppa_alert(sprintf(__('Uploaded file %s already exists in this album.', 'wp-photo-album-plus'), wppa_sanitize_file_name($file['name'])));
            return false;
        }
    }
    $mayupload = wppa_check_memory_limit('', $imgsize[0], $imgsize[1]);
    if ($mayupload === false) {
        $maxsize = wppa_check_memory_limit(false);
        if (is_array($maxsize)) {
            wppa_alert(sprintf(__('The image is too big. Max photo size: %d x %d (%2.1f MegaPixel)', 'wp-photo-album-plus'), $maxsize['maxx'], $maxsize['maxy'], $maxsize['maxp'] / (1024 * 1024)));
            return false;
        }
    }
    switch ($imgsize[2]) {
        // mime type
        case 1:
            $ext = 'gif';
            break;
        case 2:
            $ext = 'jpg';
            break;
        case 3:
            $ext = 'png';
            break;
    }
    if (wppa_get_post('user-name')) {
        $name = wppa_get_post('user-name');
    } else {
        $name = $file['name'];
    }
    $name = wppa_sanitize_photo_name($name);
    $desc = balanceTags(wppa_get_post('user-desc'), true);
    $linktarget = '_self';
    $status = wppa_switch('upload_moderate') && !current_user_can('wppa_admin') ? 'pending' : 'publish';
    $filename = wppa_sanitize_file_name($file['name']);
    $id = wppa_create_photo_entry(array('album' => $alb, 'ext' => $ext, 'name' => $name, 'description' => $desc, 'status' => $status, 'filename' => $filename));
    if (!$id) {
        wppa_alert(__('Could not insert photo into db.', 'wp-photo-album-plus'));
        return false;
    } else {
        wppa_save_source($file['tmp_name'], $filename, $alb);
        wppa_update_album(array('id' => $alb, 'modified' => time()));
        wppa_flush_treecounts($alb);
        wppa_flush_upldr_cache('photoid', $id);
    }
    if (wppa_make_the_photo_files($file['tmp_name'], $id, $ext)) {
        // Repair photoname if not standard
        if (!wppa_get_post('user-name')) {
            wppa_set_default_name($id, $file['name']);
        }
        // Custom data
        if (wppa_switch('fe_custom_fields')) {
            $custom_data = array('', '', '', '', '', '', '', '', '', '');
            for ($i = '0'; $i < '10'; $i++) {
                if (isset($_POST['wppa-user-custom-' . $i])) {
                    $custom_data[$i] = strip_tags($_POST['wppa-user-custom-' . $i]);
                }
            }
            wppa_update_photo(array('id' => $id, 'custom' => serialize($custom_data)));
        }
        // Default tags
        wppa_set_default_tags($id);
        // Custom tags
        $tags = wppa_get_photo_item($id, 'tags');
        $oldt = $tags;
        for ($i = '1'; $i < '4'; $i++) {
            if (isset($_POST['wppa-user-tags-' . $i])) {
                // Existing tags
                $tags .= ',' . implode(',', $_POST['wppa-user-tags-' . $i]);
            }
        }
        if (isset($_POST['wppa-new-tags'])) {
            // New tags
            $newt = $_POST['wppa-new-tags'];
            $tags .= ',' . $newt;
        } else {
            $newt = '';
        }
        $tags = wppa_sanitize_tags(str_replace(array('\'', '"'), ',', wppa_filter_iptc(wppa_filter_exif($tags, $id), $id)));
        if ($tags != $oldt) {
            // Added tag(s)
            wppa_update_photo(array('id' => $id, 'tags' => $tags));
        }
        // Index
        wppa_index_add('photo', $id);
        // Tags
        if ($tags) {
            wppa_clear_taglist();
            // Forces recreation
        }
        // and add watermark ( optionally ) to fullsize image only
        wppa_add_watermark($id);
        // Also to thumbnail?
        if (wppa_switch('watermark_thumbs')) {
            wppa_create_thumbnail($id);
            // create new thumb
        }
        // Is it a default coverimage?
        wppa_check_coverimage($id);
        // Mail
        if (wppa_switch('upload_notify')) {
            $to = get_bloginfo('admin_email');
            $subj = sprintf(__('New photo uploaded: %s', 'wp-photo-album-plus'), $name);
            $cont['0'] = sprintf(__('User %1$s uploaded photo %2$s into album %3$s', 'wp-photo-album-plus'), wppa_get_user(), $id, wppa_get_album_name($alb));
            if (wppa_switch('upload_moderate') && !current_user_can('wppa_admin')) {
                $cont['1'] = __('This upload requires moderation', 'wp-photo-album-plus');
                $cont['2'] = '<a href="' . get_admin_url() . 'admin.php?page=wppa_admin_menu&tab=pmod&photo=' . $id . '" >' . __('Moderate manage photo', 'wp-photo-album-plus') . '</a>';
            } else {
                $cont['1'] = __('Details:', 'wp-photo-album-plus');
                $cont['1'] .= ' <a href="' . get_admin_url() . 'admin.php?page=wppa_admin_menu&tab=pmod&photo=' . $id . '" >' . __('Manage photo', 'wp-photo-album-plus') . '</a>';
            }
            wppa_send_mail($to, $subj, $cont, $id);
        }
        return true;
    } else {
        return false;
    }
}
function wppa_insert_photo($file = '', $alb = '', $name = '', $desc = '', $porder = '0', $id = '0', $linkurl = '', $linktitle = '')
{
    global $wpdb;
    global $warning_given_small;
    $album = wppa_cache_album($alb);
    if (!wppa_allow_uploads($alb)) {
        if (is_admin() && !wppa('ajax')) {
            wppa_error_message(sprintf(__('Album %s is full', 'wp-photo-album-plus'), wppa_get_album_name($alb)));
        } else {
            wppa_alert(sprintf(__('Album %s is full', 'wp-photo-album-plus'), wppa_get_album_name($alb)));
        }
        return false;
    }
    if ($file != '' && $alb != '') {
        // Get the name if not given
        if ($name == '') {
            $name = basename($file);
        }
        // Sanitize name
        $filename = wppa_sanitize_file_name($name);
        $name = wppa_sanitize_photo_name($name);
        // If not dups allowed and its already here, quit
        if (isset($_POST['wppa-nodups']) || wppa_switch('void_dups')) {
            $exists = wppa_file_is_in_album($filename, $alb);
            if ($exists) {
                if (isset($_POST['del-after-p'])) {
                    unlink($file);
                    $msg = __('Photo %s already exists in album number %s. Removed from depot.', 'wp-photo-album-plus');
                } else {
                    $msg = __('Photo %s already exists in album number %s.', 'wp-photo-album-plus');
                }
                wppa_warning_message(sprintf($msg, $name, $alb));
                return false;
            }
        }
        // Verify file exists
        if (!wppa('is_remote') && !file_exists($file)) {
            if (!is_dir(dirname($file))) {
                wppa_error_message('Error: Directory ' . dirname($file) . ' does not exist.');
                return false;
            }
            if (!is_writable(dirname($file))) {
                wppa_error_message('Error: Directory ' . dirname($file) . ' is not writable.');
                return false;
            }
            wppa_error_message('Error: File ' . $file . ' does not exist.');
            return false;
        }
        //		else {
        //			wppa_ok_message( 'Good: File '.$file.' exists.' );
        //		}
        // Get and verify the size
        $img_size = getimagesize($file);
        if ($img_size) {
            if (wppa_check_memory_limit('', $img_size['0'], $img_size['1']) === false) {
                wppa_error_message(sprintf(__('ERROR: Attempt to upload a photo that is too large to process (%s).', 'wp-photo-album-plus'), $name) . wppa_check_memory_limit());
                wppa('ajax_import_files_error', __('Too big', 'wp-photo-album-plus'));
                return false;
            }
            if (!$warning_given_small && ($img_size['0'] < wppa_get_minisize() && $img_size['1'] < wppa_get_minisize())) {
                wppa_warning_message(__('WARNING: You are uploading photos that are too small. Photos must be larger than the thumbnail size and larger than the coverphotosize.', 'wp-photo-album-plus'));
                wppa('ajax_import_files_error', __('Too small', 'wp-photo-album-plus'));
                $warning_given_small = true;
            }
        } else {
            wppa_error_message(__('ERROR: Unable to retrieve image size of', 'wp-photo-album-plus') . ' ' . $name . ' ' . __('Are you sure it is a photo?', 'wp-photo-album-plus'));
            wppa('ajax_import_files_error', __('No imagesize', 'wp-photo-album-plus'));
            return false;
        }
        // Get ext based on mimetype, regardless of ext
        switch ($img_size[2]) {
            // mime type
            case 1:
                $ext = 'gif';
                break;
            case 2:
                $ext = 'jpg';
                break;
            case 3:
                $ext = 'png';
                break;
            default:
                wppa_error_message(__('Unsupported mime type encountered:', 'wp-photo-album-plus') . ' ' . $img_size[2] . '.');
                return false;
        }
        // Get an id if not yet there
        if ($id == '0') {
            $id = wppa_nextkey(WPPA_PHOTOS);
        }
        // Get opt deflt desc if empty
        if ($desc == '' && wppa_switch('apply_newphoto_desc')) {
            $desc = stripslashes(wppa_opt('newphoto_description'));
        }
        // Reset rating
        $mrat = '0';
        // Find ( new ) owner
        $owner = wppa_get_user();
        // Validate album
        if (!is_numeric($alb) || $alb < '1') {
            wppa_error_message(__('Album not known while trying to add a photo', 'wp-photo-album-plus'));
            return false;
        }
        if (!wppa_have_access($alb)) {
            wppa_error_message(sprintf(__('Album %s does not exist or is not accessable while trying to add a photo', 'wp-photo-album-plus'), $alb));
            return false;
        }
        $status = wppa_switch('upload_moderate') && !current_user_can('wppa_admin') ? 'pending' : 'publish';
        // Add photo to db
        $id = wppa_create_photo_entry(array('id' => $id, 'album' => $alb, 'ext' => $ext, 'name' => $name, 'p_order' => $porder, 'description' => $desc, 'linkurl' => $linkurl, 'linktitle' => $linktitle, 'owner' => $owner, 'status' => $status, 'filename' => $filename));
        if (!$id) {
            wppa_error_message(__('Could not insert photo.', 'wp-photo-album-plus'));
        } else {
            // Save the source
            wppa_save_source($file, $filename, $alb);
            wppa_flush_treecounts($alb);
            wppa_update_album(array('id' => $alb, 'modified' => time()));
            wppa_flush_upldr_cache('photoid', $id);
        }
        // Make the photo files
        if (wppa_make_the_photo_files($file, $id, $ext)) {
            // Repair photoname if not supplied and not standard
            wppa_set_default_name($id, $name);
            // Tags
            wppa_set_default_tags($id);
            // Index
            wppa_index_add('photo', $id);
            // and add watermark ( optionally ) to fullsize image only
            wppa_add_watermark($id);
            // also to thumbnail?
            if (wppa_switch('watermark_thumbs')) {
                wppa_create_thumbnail($id);
            }
            // Is it a default coverimage?
            wppa_check_coverimage($id);
            return $id;
        }
    } else {
        wppa_error_message(__('ERROR: Unknown file or album.', 'wp-photo-album-plus'));
        return false;
    }
}
function _wppa_page_upload()
{
    global $target;
    global $wppa_revno;
    global $upload_album;
    // sanitize system
    $user = wppa_get_user();
    wppa_sanitize_files();
    // Sanitize album input
    if (isset($_POST['wppa-album'])) {
        $upload_album = strval(intval($_POST['wppa-album']));
    } else {
        $upload_album = null;
    }
    // Update watermark settings for the user if new values supplied
    if (wppa_switch('watermark_on') && (wppa_switch('watermark_user') || current_user_can('wppa_settings'))) {
        // File
        if (isset($_POST['wppa-watermark-file'])) {
            // Sanitize input
            $watermark_file = $_POST['wppa-watermark-file'];
            if (stripos($watermark_file, '.png') !== false) {
                $watermark_file = sanitize_file_name($watermark_file);
            } else {
                if (!in_array($watermark_file, array('--- none ---', '---name---', '---filename---', '---description---', '---predef---'))) {
                    $watermark_file = 'nil';
                }
            }
            // Update setting
            update_option('wppa_watermark_file_' . $user, $watermark_file);
        }
        // Position
        if (isset($_POST['wppa-watermark-pos'])) {
            // Sanitize input
            $watermark_pos = $_POST['wppa-watermark-pos'];
            if (!in_array($watermark_pos, array('toplft', 'topcen', 'toprht', 'cenlft', 'cencen', 'cenrht', 'botlft', 'botcen', 'botrht'))) {
                $watermark_pos = 'nil';
            }
            // Update setting
            update_option('wppa_watermark_pos_' . $user, $watermark_pos);
        }
    }
    // If from album admin set the last album
    if (isset($_REQUEST['wppa-set-album'])) {
        wppa_set_last_album(strval(intval($_REQUEST['wppa-set-album'])));
    }
    // Do the upload if requested
    // From BOX A
    if (isset($_POST['wppa-upload-multiple'])) {
        check_admin_referer('$wppa_nonce', WPPA_NONCE);
        wppa_upload_multiple();
        if (isset($_POST['wppa-go-edit-multiple'])) {
            if (current_user_can('wppa_admin')) {
                wppa_ok_message(__('Connecting to edit album...', 'wp-photo-album-plus'));
                ?>
				<script type="text/javascript">document.location = '<?php 
                echo wppa_dbg_url(get_admin_url() . 'admin.php?page=wppa_admin_menu&tab=edit&edit_id=' . $upload_album, 'js');
                ?>
';</script>
			<?php 
            } else {
                wppa_ok_message(__('Connecting to edit photos...', 'wp-photo-album-plus'));
                ?>
				<script type="text/javascript">document.location = '<?php 
                echo wppa_dbg_url(get_admin_url() . 'admin.php?page=wppa_edit_photo', 'js');
                ?>
';</script>
			<?php 
            }
        }
    }
    // From BOX B
    if (isset($_POST['wppa-upload'])) {
        check_admin_referer('$wppa_nonce', WPPA_NONCE);
        wppa_upload_photos();
        if (isset($_POST['wppa-go-edit-single'])) {
            if (current_user_can('wppa_admin')) {
                wppa_ok_message(__('Connecting to edit album...', 'wp-photo-album-plus'));
                ?>
				<script type="text/javascript">document.location = '<?php 
                echo wppa_dbg_url(get_admin_url() . 'admin.php?page=wppa_admin_menu&tab=edit&edit_id=' . $upload_album, 'js');
                ?>
';</script>
			<?php 
            } else {
                wppa_ok_message(__('Connecting to edit photos...', 'wp-photo-album-plus'));
                ?>
				<script type="text/javascript">document.location = '<?php 
                echo wppa_dbg_url(get_admin_url() . 'admin.php?page=wppa_edit_photo', 'js');
                ?>
';</script>
			<?php 
            }
        }
    }
    // From BOX C
    if (isset($_POST['wppa-upload-zip'])) {
        check_admin_referer('$wppa_nonce', WPPA_NONCE);
        $err = wppa_upload_zip();
        if (isset($_POST['wppa-go-import']) && $err == '0') {
            wppa_ok_message(__('Connecting to your depot...', 'wp-photo-album-plus'));
            update_option('wppa_import_source_' . $user, WPPA_DEPOT_PATH);
            ?>
			<script type="text/javascript">document.location = '<?php 
            echo wppa_dbg_url(get_admin_url() . 'admin.php?page=wppa_import_photos&zip=' . $target, 'js');
            ?>
';</script>
		<?php 
        }
    }
    // sanitize system again
    wppa_sanitize_files();
    // Open the form
    echo '<div class="wrap">' . '<h2>' . __('Upload Photos', 'wp-photo-album-plus') . '</h2>';
    // Get some req'd data
    $max_files = ini_get('max_file_uploads');
    $max_files_txt = $max_files;
    if ($max_files < '1') {
        $max_files_txt = __('unknown', 'wp-photo-album-plus');
        $max_files = '15';
    }
    $max_size = ini_get('upload_max_filesize');
    /* debug */
    // $max_size = '2G';
    /**/
    $max_size_mbytes = substr($max_size, 0, strlen($max_size) - 1);
    if (substr($max_size, -1) == 'G') {
        // May upload gigabytes!!
        $max_size_mbytes *= 1024;
    }
    $max_time = ini_get('max_input_time');
    if ($max_time < '1') {
        $max_time = __('unknown', 'wp-photo-album-plus');
    }
    // check if albums exist before allowing upload
    if (!wppa_has_albums()) {
        $url = wppa_dbg_url(get_admin_url() . 'admin.php?page=wppa_admin_menu');
        echo '<p>' . __('No albums exist. You must', 'wp-photo-album-plus') . ' <a href="' . $url . '" >' . __('create one', 'wp-photo-album-plus') . '</a> ' . __('before you can upload your photos.', 'wp-photo-album-plus') . '</p>' . '</div>';
        return;
    }
    // Upload One only configured and not administrator or super user?
    if (wppa_switch('upload_one_only') && !wppa_user_is('administrator')) {
        // One only
        echo '<div style="border:1px solid #ccc; padding:10px; margin-bottom:10px; width: 600px;">' . '<h3 style="margin-top:0px;">' . __('Upload a single photo', 'wp-photo-album-plus') . '</h3>' . '<form enctype="multipart/form-data" action="' . wppa_dbg_url(get_admin_url() . 'admin.php?page=wppa_upload_photos') . '" method="post">' . wp_nonce_field('$wppa_nonce', WPPA_NONCE) . '<input id="my_files" type="file" name="my_files[]" />' . '<p>' . '<label for="wppa-album">' . __('Album:', 'wp-photo-album-plus') . '</label>' . '<select name="wppa-album" id="wppa-album-s" >' . wppa_album_select_a(array('path' => wppa_switch('hier_albsel'), 'addpleaseselect' => true, 'checkowner' => true, 'checkupload' => true)) . '</select>' . '</p>';
        if (wppa_switch('watermark_on') && (wppa_switch('watermark_user') || current_user_can('wppa_settings'))) {
            echo '<p>' . __('Apply watermark file:', 'wp-photo-album-plus') . '<select name="wppa-watermark-file" id="wppa-watermark-file" >' . wppa_watermark_file_select() . '</select>' . __('Position:', 'wp-photo-album-plus') . '<select name="wppa-watermark-pos" id="wppa-watermark-pos" >' . wppa_watermark_pos_select() . '</select>' . '</p>';
        }
        echo '<input' . ' type="submit" class="button-primary"' . ' name="wppa-upload-multiple"' . ' value="' . __('Upload Photo', 'wp-photo-album-plus') . '"' . ' onclick="if ( document.getElementById( \'wppa-album-s\' ).value == 0 ) { alert( \'' . __('Please select an album', 'wp-photo-album-plus') . '\' ); return false; }"' . ' />' . '<input type="checkbox"' . ' id="wppa-go-edit-multiple"' . ' name="wppa-go-edit-multiple"' . ' style="display:none"' . ' checked="checked"' . ' />' . '</form>' . '</div>';
    } else {
        // The information box
        echo '<div' . ' style="' . 'border:1px solid #ccc;' . 'padding:10px;' . 'margin-bottom:10px;' . 'width:600px;' . 'background-color:#fffbcc;' . 'border-color:#e6db55;' . '"' . ' >' . sprintf(__('<b>Notice:</b> your server allows you to upload <b>%s</b> files of maximum total <b>%s</b> bytes and allows <b>%s</b> seconds to complete.', 'wp-photo-album-plus'), $max_files_txt, $max_size, $max_time) . __('If your request exceeds these limitations, it will fail, probably without an errormessage.', 'wp-photo-album-plus') . __('Additionally your hosting provider may have set other limitations on uploading files.', 'wp-photo-album-plus') . '<br />' . wppa_check_memory_limit() . '</div>';
        // Box A: Upload Multple photos
        echo '<div' . ' style="' . 'border:1px solid #ccc;' . 'padding:10px;' . 'margin-bottom:10px;' . 'width: 600px;' . '"' . ' >' . '<h3 style="margin-top:0px;">' . __('Box A:', 'wp-photo-album-plus') . ' ' . __('Multiple Photos in one selection', 'wp-photo-album-plus') . '</h3>' . sprintf(__('You can select up to %s photos in one selection and upload them.', 'wp-photo-album-plus'), $max_files_txt) . '<br />' . '<small style="color:blue" >' . __('You need a modern browser that supports HTML-5 to select multiple files', 'wp-photo-album-plus') . '</small>' . '<form' . ' enctype="multipart/form-data"' . ' action="' . wppa_dbg_url(get_admin_url() . 'admin.php?page=wppa_upload_photos') . '"' . ' method="post" >' . wp_nonce_field('$wppa_nonce', WPPA_NONCE, true, false) . '<input' . ' id="my_files"' . ' type="file"' . ' multiple="multiple"' . ' name="my_files[]"' . ' onchange="showit()"' . ' />' . '<div id="files_list2" >' . '<h3>' . __('Selected Files:', 'wp-photo-album-plus') . '</h3>' . '</div>' . '<script type="text/javascript">' . 'function showit() {' . 'var maxsize = parseInt( \'' . $max_size_mbytes . '\' ) * 1024 * 1024;' . 'var maxcount = parseInt( \'' . $max_files_txt . '\' );' . 'var totsize = 0;' . 'var files = document.getElementById( \'my_files\' ).files;' . 'var tekst = "<h3>' . __('Selected Files:', 'wp-photo-album-plus') . '</h3>";' . 'tekst += "<table><thead><tr>";' . 'tekst += "<td>' . __('Name', 'wp-photo-album-plus') . '</td>";' . 'tekst += "<td>' . __('Size', 'wp-photo-album-plus') . '</td>";' . 'tekst += "<td>' . __('Type', 'wp-photo-album-plus') . '</td>";' . 'tekst += "</tr></thead>";' . 'tekst += "<tbody>";' . 'tekst += "<tr><td><hr /></td><td><hr /></td><td><hr /></td></tr>";' . 'for ( var i=0;i<files.length;i++ ) {' . 'tekst += "<tr>";' . 'tekst += "<td>" + files[i].name + "</td>";' . 'tekst += "<td>" + files[i].size + "</td>";' . 'totsize += files[i].size;' . 'tekst += "<td>" + files[i].type + "</td>";' . 'tekst += "</tr>";' . '}' . 'tekst += "<tr><td><hr /></td><td><hr /></td><td><hr /></td></tr>";' . 'var style1 = "";' . 'var style2 = "";' . 'var style3 = "";' . 'var warn1 = "";' . 'var warn2 = "";' . 'var warn3 = "";' . 'if ( maxcount > 0 && files.length > maxcount ) {' . 'style1 = "color:red";' . 'warn1 = "' . __('Too many!', 'wp-photo-album-plus') . '";' . '}' . 'if ( maxsize > 0 && totsize > maxsize ) {' . 'style2 = "color:red";' . 'warn2 = "' . __('Too big!', 'wp-photo-album-plus') . '";' . '}' . 'if ( warn1 || warn2 ) {' . 'style3 = "color:green";' . 'warn3 = "' . __('Try again!', 'wp-photo-album-plus') . '";' . '}' . 'tekst += "<tr><td style="+style1+" >' . __('Total', 'wp-photo-album-plus') . ': "+files.length+" "+warn1+"</td><td style="+style2+" >"+totsize+" "+warn2+"</td><td style="+style3+" >"+warn3+"</td></tr>";' . 'tekst += "</tbody>";' . 'tekst += "</table>";' . 'jQuery( "#files_list2" ).html( tekst );' . '}' . '</script>' . '<p>' . '<label for="wppa-album">' . __('Album:', 'wp-photo-album-plus') . '</label>' . '<select name="wppa-album" id="wppa-album-s">' . wppa_album_select_a(array('path' => wppa_switch('hier_albsel'), 'addpleaseselect' => true, 'checkowner' => true, 'checkupload' => true)) . '</select>' . '</p>';
        // Watermark?
        if (wppa_switch('watermark_on') && (wppa_switch('watermark_user') || current_user_can('wppa_settings'))) {
            echo '<p>' . __('Apply watermark file:', 'wp-photo-album-plus') . '<select name="wppa-watermark-file" id="wppa-watermark-file" >' . wppa_watermark_file_select() . '</select>' . __('Position:', 'wp-photo-album-plus') . '<select name="wppa-watermark-pos" id="wppa-watermark-pos" >' . wppa_watermark_pos_select() . '</select>' . '</p>';
        }
        // Submit section
        echo '<input' . ' type="submit"' . ' class="button-primary"' . ' name="wppa-upload-multiple"' . ' value="' . __('Upload Multiple Photos', 'wp-photo-album-plus') . '"' . ' onclick="if ( document.getElementById( \'wppa-album-s\' ).value == 0 ) { alert( \'' . __('Please select an album', 'wp-photo-album-plus') . '\' ); return false; }"' . ' />' . ' ' . '<input' . ' type="checkbox"' . ' id="wppa-go-edit-multiple"' . ' name="wppa-go-edit-multiple"' . ' onchange="wppaCookieCheckbox( this, \'wppa-go-edit-multiple\' )"' . ' />' . '<script type="text/javascript" >' . 'if ( wppa_getCookie( \'wppa-go-edit-multiple\' ) == \'on\' ) document.getElementById( \'wppa-go-edit-multiple\' ).checked = \'checked\';' . '</script>';
        if (current_user_can('wppa_admin')) {
            _e('After upload: Go to the <b>Edit Album</b> page.', 'wp-photo-album-plus');
        } else {
            _e('After upload: Go to the <b>Edit Photos</b> page.', 'wp-photo-album-plus');
        }
        echo '</form>' . '</div>';
        // End BOX A
        // Box B: Single photos
        echo '<div style="border:1px solid #ccc; padding:10px; margin-bottom:10px; width: 600px;" >' . '<h3 style="margin-top:0px;" >' . __('Box B:', 'wp-photo-album-plus') . ' ' . __('Single Photos in multiple selections', 'wp-photo-album-plus') . '</h3>' . sprintf(__('You can select up to %s photos one by one and upload them at once.', 'wp-photo-album-plus'), $max_files_txt) . '<form' . ' enctype="multipart/form-data"' . ' action="' . wppa_dbg_url(get_admin_url() . 'admin.php?page=wppa_upload_photos') . '"' . ' method="post" ' . ' >' . wp_nonce_field('$wppa_nonce', WPPA_NONCE, true, false) . '<input' . ' id="my_file_element"' . ' type="file"' . ' name="file_1"' . '/>' . '<div id="files_list">' . '<h3>' . __('Selected Files:', 'wp-photo-album-plus') . '</h3>' . '</div>' . '<p>' . '<label for="wppa-album">' . __('Album:', 'wp-photo-album-plus') . '</label>' . '<select name="wppa-album" id="wppa-album-m">' . wppa_album_select_a(array('path' => wppa_switch('hier_albsel'), 'addpleaseselect' => true, 'checkowner' => true, 'checkupload' => true)) . '</select>' . '</p>';
        // Watermark?
        if (wppa_switch('watermark_on') && (wppa_switch('watermark_user') || current_user_can('wppa_settings'))) {
            echo '<p>' . __('Apply watermark file:', 'wp-photo-album-plus') . '<select name="wppa-watermark-file" id="wppa-watermark-file" >' . wppa_watermark_file_select() . '</select>' . __('Position:', 'wp-photo-album-plus') . '<select name="wppa-watermark-pos" id="wppa-watermark-pos" >' . wppa_watermark_pos_select() . '</select>' . '</p>';
        }
        // Submit section
        echo '<input' . ' type="submit"' . ' class="button-primary"' . ' name="wppa-upload"' . ' value="' . __('Upload Single Photos', 'wp-photo-album-plus') . '"' . ' onclick="if ( document.getElementById( \'wppa-album-m\' ).value == 0 ) { alert( \'' . __('Please select an album', 'wp-photo-album-plus') . '\' ); return false; }"' . ' />' . ' ' . '<input' . ' type="checkbox"' . ' id="wppa-go-edit-single"' . ' name="wppa-go-edit-single"' . ' onchange="wppaCookieCheckbox( this, \'wppa-go-edit-single\' )" />' . '<script type="text/javascript" >' . 'if ( wppa_getCookie( \'wppa-go-edit-single\' ) == \'on\' ) document.getElementById( \'wppa-go-edit-single\' ).checked = \'checked\';' . '</script>';
        if (current_user_can('wppa_admin')) {
            _e('After upload: Go to the <b>Edit Album</b> page.', 'wp-photo-album-plus');
        } else {
            _e('After upload: Go to the <b>Edit Photos</b> page.', 'wp-photo-album-plus');
        }
        echo '</form>' . '<script type="text/javascript">' . '<!-- Create an instance of the multiSelector class, pass it the output target and the max number of files -->' . 'var multi_selector = new MultiSelector( document.getElementById( \'files_list\' ), ' . $max_files . ');' . '<!-- Pass in the file element -->' . 'multi_selector.addElement( document.getElementById( \'my_file_element\' ) );' . '</script>' . '</div>';
        // End Box B
        // Box C: Single zips, useless if user can not imort, or when php <50207: no unzip
        if (current_user_can('wppa_import')) {
            if (PHP_VERSION_ID >= 50207) {
                echo '<div style="border:1px solid #ccc; padding:10px; width: 600px;" >' . '<h3 style="margin-top:0px;" >' . __('Box C:', 'wp-photo-album-plus') . ' ' . __('Zipped Photos in one selection', 'wp-photo-album-plus') . '</h3>' . sprintf(__('You can upload one zipfile. It will be placed in your personal wppa-depot: <b>.../%s</b><br/>Once uploaded, use <b>Import Photos</b> to unzip the file and place the photos in any album.', 'wp-photo-album-plus'), WPPA_DEPOT) . '<form' . ' enctype="multipart/form-data"' . ' action="' . wppa_dbg_url(get_admin_url() . 'admin.php?page=wppa_upload_photos') . '"' . ' method="post"' . ' >' . wp_nonce_field('$wppa_nonce', WPPA_NONCE, true, false) . '<input' . ' id="my_zipfile_element"' . ' type="file"' . ' name="file_zip"' . ' />' . '<br/><br/>' . '<input' . ' type="submit"' . ' class="button-primary"' . ' name="wppa-upload-zip"' . ' value="' . __('Upload Zipped Photos', 'wp-photo-album-plus') . '"' . ' />' . ' ' . '<input' . ' type="checkbox"' . ' id="wppa-go-import"' . ' name="wppa-go-import"' . ' onchange="wppaCookieCheckbox( this, \'wppa-go-import\' )"' . ' />' . '<script type="text/javascript" >' . 'if ( wppa_getCookie( \'wppa-go-import\' ) == \'on\' ) document.getElementById( \'wppa-go-import\' ).checked = \'checked\';' . '</script>' . __('After upload: Go to the <b>Import Photos</b> page.', 'wp-photo-album-plus') . '</form>' . '</div>';
            } else {
                echo '<div style="border:1px solid #ccc; padding:10px; width: 600px;">' . '<small>' . __('Ask your administrator to upgrade php to version 5.2.7 or later. This will enable you to upload zipped photos.', 'wp-photo-album-plus') . '</small>' . '</div>';
            }
        }
    }
    echo '</div>';
}
Example #4
0
function _wppa_page_upload()
{
    global $target;
    global $wppa_revno;
    // sanitize system
    $user = wppa_get_user();
    wppa_sanitize_files();
    // Update watermark settings for the user ifnew values supplied
    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']);
        }
    }
    // If from album admin set the last album
    if (isset($_REQUEST['wppa-set-album'])) {
        wppa_set_last_album($_REQUEST['wppa-set-album']);
    }
    // Do the upload if requested
    // From BOX A
    if (isset($_POST['wppa-upload-multiple'])) {
        check_admin_referer('$wppa_nonce', WPPA_NONCE);
        wppa_upload_multiple();
        if (isset($_POST['wppa-go-edit-multiple'])) {
            if (current_user_can('wppa_admin')) {
                wppa_ok_message(__('Connecting to edit album...', 'wppa'));
                ?>
				<script type="text/javascript">document.location = '<?php 
                echo wppa_dbg_url(get_admin_url() . 'admin.php?page=wppa_admin_menu&tab=edit&edit_id=' . $_POST['wppa-album'], 'js');
                ?>
';</script>
			<?php 
            } else {
                wppa_ok_message(__('Connecting to edit photos...', 'wppa'));
                ?>
				<script type="text/javascript">document.location = '<?php 
                echo wppa_dbg_url(get_admin_url() . 'admin.php?page=wppa_edit_photo', 'js');
                ?>
';</script>
			<?php 
            }
        }
    }
    // From BOX B
    if (isset($_POST['wppa-upload'])) {
        check_admin_referer('$wppa_nonce', WPPA_NONCE);
        wppa_upload_photos();
        if (isset($_POST['wppa-go-edit-single'])) {
            if (current_user_can('wppa_admin')) {
                wppa_ok_message(__('Connecting to edit album...', 'wppa'));
                ?>
				<script type="text/javascript">document.location = '<?php 
                echo wppa_dbg_url(get_admin_url() . 'admin.php?page=wppa_admin_menu&tab=edit&edit_id=' . $_POST['wppa-album'], 'js');
                ?>
';</script>
			<?php 
            } else {
                wppa_ok_message(__('Connecting to edit photos...', 'wppa'));
                ?>
				<script type="text/javascript">document.location = '<?php 
                echo wppa_dbg_url(get_admin_url() . 'admin.php?page=wppa_edit_photo', 'js');
                ?>
';</script>
			<?php 
            }
        }
    }
    // From BOX C
    if (isset($_POST['wppa-upload-zip'])) {
        check_admin_referer('$wppa_nonce', WPPA_NONCE);
        $err = wppa_upload_zip();
        if (isset($_POST['wppa-go-import']) && $err == '0') {
            wppa_ok_message(__('Connecting to your depot...', 'wppa'));
            update_option('wppa_import_source_' . $user, WPPA_DEPOT);
            ?>
			<script type="text/javascript">document.location = '<?php 
            echo wppa_dbg_url(get_admin_url() . 'admin.php?page=wppa_import_photos&zip=' . $target, 'js');
            ?>
';</script>
		<?php 
        }
    }
    // sanitize system again
    wppa_sanitize_files();
    ?>
	
	<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('Upload Photos', 'wppa');
    ?>
</h2>

		<?php 
    // Check for trivial requirements
    if (!function_exists('imagecreatefromjpeg')) {
        wppa_error_message(__('There is a serious misconfiguration in your servers PHP config. Function imagecreatefromjpeg() does not exist. You will encounter problems when uploading photos and not be able to generate thumbnail images. Ask your hosting provider to add GD support with a minimal version 1.8.', 'wppa'));
    }
    $max_files = ini_get('max_file_uploads');
    $max_files_txt = $max_files;
    if ($max_files < '1') {
        $max_files_txt = __('unknown', 'wppa');
        $max_files = '15';
    }
    $max_size = ini_get('upload_max_filesize');
    $max_time = ini_get('max_input_time');
    if ($max_time < '1') {
        $max_time = __('unknown', 'wppa');
    }
    // chek if albums exist before allowing upload
    if (wppa_has_albums()) {
        if (wppa_switch('wppa_upload_one_only') && !current_user_can('administrator')) {
            /* One only */
            ?>
				<div style="border:1px solid #ccc; padding:10px; margin-bottom:10px; width: 600px;">
					<h3 style="margin-top:0px;"><?php 
            _e('Upload a single photo', 'wppa');
            ?>
</h3>
					<form enctype="multipart/form-data" action="<?php 
            echo wppa_dbg_url(get_admin_url() . 'admin.php?page=wppa_upload_photos');
            ?>
" method="post">
					<?php 
            wp_nonce_field('$wppa_nonce', WPPA_NONCE);
            ?>
						<input id="my_files" type="file" name="my_files[]" />
						<p>
							<label for="wppa-album"><?php 
            _e('Album:', 'wppa');
            ?>
 </label>
							<select name="wppa-album" id="wppa-album-s">
								<?php 
            echo wppa_album_select_a(array('path' => wppa_switch('wppa_hier_albsel'), 'addpleaseselect' => true, 'checkowner' => true, 'checkupload' => true));
            ?>
							</select>
						</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 
            }
            ?>
						<input type="submit" class="button-primary" name="wppa-upload-multiple" value="<?php 
            _e('Upload Photo', 'wppa');
            ?>
" onclick="if ( document.getElementById( 'wppa-album-s' ).value == 0 ) { alert( '<?php 
            _e('Please select an album', 'wppa');
            ?>
' ); return false; }" />
						<input type="checkbox" id="wppa-go-edit-multiple" name="wppa-go-edit-multiple" style="display:none" checked="checked" />&nbsp;
					</form>
				</div>
<?php 
        } else {
            ?>
				<div style="border:1px solid #ccc; padding:10px; margin-bottom:10px; width: 600px; background-color:#fffbcc; border-color:#e6db55;">
				<?php 
            echo sprintf(__('<b>Notice:</b> your server allows you to upload <b>%s</b> files of maximum total <b>%s</b> bytes and allows <b>%s</b> seconds to complete.', 'wppa'), $max_files_txt, $max_size, $max_time);
            ?>
				<?php 
            _e('If your request exceeds these limitations, it will fail, probably without an errormessage.', 'wppa');
            ?>
				<?php 
            _e('Additionally your hosting provider may have set other limitations on uploading files.', 'wppa');
            ?>
				<?php 
            echo '<br />' . wppa_check_memory_limit();
            ?>
				</div>
				<?php 
            /* Multple photos */
            ?>
				<div style="border:1px solid #ccc; padding:10px; margin-bottom:10px; width: 600px;">
					<h3 style="margin-top:0px;"><?php 
            _e('Box A:', 'wppa');
            echo ' ';
            _e('Multiple Photos in one selection', 'wppa');
            ?>
</h3>
					<?php 
            echo sprintf(__('You can select up to %s photos in one selection and upload them.', 'wppa'), $max_files_txt);
            ?>
					<br /><small style="color:blue" ><?php 
            _e('You need a modern browser that supports HTML-5 to select multiple files', 'wppa');
            ?>
</small>
					<form enctype="multipart/form-data" action="<?php 
            echo wppa_dbg_url(get_admin_url() . 'admin.php?page=wppa_upload_photos');
            ?>
" method="post">
					<?php 
            wp_nonce_field('$wppa_nonce', WPPA_NONCE);
            ?>
						<input id="my_files" type="file" multiple="multiple" name="my_files[]" onchange="showit()" />
						<div id="files_list2">
							<h3><?php 
            _e('Selected Files:', 'wppa');
            ?>
</h3>
							
						</div>
						<script type="text/javascript">
							function showit() {
								var maxsize = parseInt( '<?php 
            echo $max_size;
            ?>
' ) * 1024 * 1024;
								var maxcount = parseInt( '<?php 
            echo $max_files_txt;
            ?>
' );
								var totsize = 0;
								var files = document.getElementById( 'my_files' ).files;
								var tekst = '<h3><?php 
            _e('Selected Files:', 'wppa');
            ?>
</h3>';
								tekst += '<table><thead><tr>';
										tekst += '<td><?php 
            _e('Name', 'wppa');
            ?>
</td><td><?php 
            _e('Size', 'wppa');
            ?>
</td><td><?php 
            _e('Type', 'wppa');
            ?>
</td>';
									tekst += '</tr></thead>';
									tekst += '<tbody>';
										tekst += '<tr><td><hr /></td><td><hr /></td><td><hr /></td></tr>';
										for ( var i=0;i<files.length;i++ ) {
											tekst += '<tr>';
												tekst += '<td>' + files[i].name + '</td>';
												tekst += '<td>' + files[i].size + '</td>';
												totsize += files[i].size;
												tekst += '<td>' + files[i].type + '</td>';
											tekst += '</tr>';
										}
										tekst += '<tr><td><hr /></td><td><hr /></td><td><hr /></td></tr>';
									var style1 = '';
									var style2 = '';
									var style3 = '';
									var warn1 = '';
									var warn2 = '';
									var warn3 = '';
									if ( maxcount > 0 && files.length > maxcount ) {
										style1 = 'color:red';
										warn1 = '<?php 
            _e('Too many!', 'wppa');
            ?>
';
									}
									if ( maxsize > 0 && totsize > maxsize ) {
										style2 = 'color:red';
										warn2 = '<?php 
            _e('Too big!', 'wppa');
            ?>
';
									}
									if ( warn1 || warn2 ) {
										style3 = 'color:green';
										warn3 = '<?php 
            _e('Try again!', 'wppa');
            ?>
';
									}
									tekst += '<tr><td style="'+style1+'" ><?php 
            _e('Total', 'wppa');
            ?>
: '+files.length+' '+warn1+'</td><td style="'+style2+'" >'+totsize+' '+warn2+'</td><td style="'+style3+'" >'+warn3+'</td></tr>';
									tekst += '</tbody>';
								tekst += '</table>';
								jQuery( '#files_list2' ).html( tekst ); 
							}
						</script>
						<p>
							<label for="wppa-album"><?php 
            _e('Album:', 'wppa');
            ?>
 </label>
							<select name="wppa-album" id="wppa-album-s">
								<?php 
            echo wppa_album_select_a(array('path' => wppa_switch('wppa_hier_albsel'), 'addpleaseselect' => true, 'checkowner' => true, 'checkupload' => true));
            ?>
							</select>
						</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 
            }
            ?>
						<input  type="submit" class="button-primary" name="wppa-upload-multiple" value="<?php 
            _e('Upload Multiple Photos', 'wppa');
            ?>
" onclick="if ( document.getElementById( 'wppa-album-s' ).value == 0 ) { alert( '<?php 
            _e('Please select an album', 'wppa');
            ?>
' ); return false; }" />
						<input type="checkbox" id="wppa-go-edit-multiple" name="wppa-go-edit-multiple" onchange="wppaCookieCheckbox( this, 'wppa-go-edit-multiple' )" />&nbsp;
						<script type="text/javascript" >
							if ( wppa_getCookie( 'wppa-go-edit-multiple' ) == 'on' ) document.getElementById( 'wppa-go-edit-multiple' ).checked = 'checked';
						</script>
						<?php 
            if (current_user_can('wppa_admin')) {
                _e('After upload: Go to the <b>Edit Album</b> page.', 'wppa');
            } else {
                _e('After upload: Go to the <b>Edit Photos</b> page.', 'wppa');
            }
            ?>
					</form>
				</div>
				<?php 
            /* End multiple */
            ?>

				<?php 
            /* Single photos */
            ?>
				<div style="border:1px solid #ccc; padding:10px; margin-bottom:10px; width: 600px;">
					<h3 style="margin-top:0px;"><?php 
            _e('Box B:', 'wppa');
            echo ' ';
            _e('Single Photos in multiple selections', 'wppa');
            ?>
</h3>
					<?php 
            echo sprintf(__('You can select up to %s photos one by one and upload them at once.', 'wppa'), $max_files_txt);
            ?>
					<form enctype="multipart/form-data" action="<?php 
            echo wppa_dbg_url(get_admin_url() . 'admin.php?page=wppa_upload_photos');
            ?>
" method="post">
					<?php 
            wp_nonce_field('$wppa_nonce', WPPA_NONCE);
            ?>
						<input id="my_file_element" type="file" name="file_1" />
						<div id="files_list">
							<h3><?php 
            _e('Selected Files:', 'wppa');
            ?>
</h3>
							
						</div>
						<p>
							<label for="wppa-album"><?php 
            _e('Album:', 'wppa');
            ?>
 </label>
							<select name="wppa-album" id="wppa-album-m">
								<?php 
            echo wppa_album_select_a(array('path' => wppa_switch('wppa_hier_albsel'), 'addpleaseselect' => true, 'checkowner' => true, 'checkupload' => true));
            //( '', '', false, false, false, false, false, true ) );
            ?>
							</select>
						</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 
            }
            ?>
						<input type="submit" class="button-primary" name="wppa-upload" value="<?php 
            _e('Upload Single Photos', 'wppa');
            ?>
" onclick="if ( document.getElementById( 'wppa-album-m' ).value == 0 ) { alert( '<?php 
            _e('Please select an album', 'wppa');
            ?>
' ); return false; }" />
						<input type="checkbox" id="wppa-go-edit-single" name="wppa-go-edit-single" onchange="wppaCookieCheckbox( this, 'wppa-go-edit-single' )" />&nbsp;
						<script type="text/javascript" >
							if ( wppa_getCookie( 'wppa-go-edit-single' ) == 'on' ) document.getElementById( 'wppa-go-edit-single' ).checked = 'checked';
						</script>
						<?php 
            if (current_user_can('wppa_admin')) {
                _e('After upload: Go to the <b>Edit Album</b> page.', 'wppa');
            } else {
                _e('After upload: Go to the <b>Edit Photos</b> page.', 'wppa');
            }
            ?>
					</form>
					<script type="text/javascript">
					<!-- Create an instance of the multiSelector class, pass it the output target and the max number of files -->
						var multi_selector = new MultiSelector( document.getElementById( 'files_list' ), <?php 
            echo $max_files;
            ?>
 );
					<!-- Pass in the file element -->
						multi_selector.addElement( document.getElementById( 'my_file_element' ) );
					</script>
				</div>
				<?php 
            /* End single photos */
            ?>

				<?php 
            /* Single zips */
            ?>
				<?php 
            if (current_user_can('wppa_import')) {
                ?>
					<?php 
                if (PHP_VERSION_ID >= 50207) {
                    ?>
						<div style="border:1px solid #ccc; padding:10px; width: 600px;">
							<h3 style="margin-top:0px;"><?php 
                    _e('Box C:', 'wppa');
                    echo ' ';
                    _e('Zipped Photos in one selection', 'wppa');
                    ?>
</h3>
							<?php 
                    echo sprintf(__('You can upload one zipfile. It will be placed in your personal wppa-depot: <b>.../%s</b><br/>Once uploaded, use <b>Import Photos</b> to unzip the file and place the photos in any album.', 'wppa'), WPPA_DEPOT);
                    ?>
							<form enctype="multipart/form-data" action="<?php 
                    echo wppa_dbg_url(get_admin_url() . 'admin.php?page=wppa_upload_photos');
                    ?>
" method="post">
							<?php 
                    wp_nonce_field('$wppa_nonce', WPPA_NONCE);
                    ?>
								<input id="my_zipfile_element" type="file" name="file_zip" /><br/><br/>
								<input type="submit" class="button-primary" name="wppa-upload-zip" value="<?php 
                    _e('Upload Zipped Photos', 'wppa');
                    ?>
" />
								<input type="checkbox" id="wppa-go-import" name="wppa-go-import" onchange="wppaCookieCheckbox( this, 'wppa-go-import' )" />&nbsp;
								<script type="text/javascript" >
									if ( wppa_getCookie( 'wppa-go-import' ) == 'on' ) document.getElementById( 'wppa-go-import' ).checked = 'checked';
								</script>
								<?php 
                    _e('After upload: Go to the <b>Import Photos</b> page.', 'wppa');
                    ?>
							</form>
						</div>
					<?php 
                } else {
                    ?>
						<div style="border:1px solid #ccc; padding:10px; width: 600px;">
						<?php 
                    _e('<small>Ask your administrator to upgrade php to version 5.2.7 or later. This will enable you to upload zipped photos.</small>', 'wppa');
                    ?>
						</div>
					<?php 
                }
            }
        }
    } 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 
    }
    ?>
	</div>
<?php 
}
function wppa_do_frontend_file_upload($file, $alb)
{
    global $wpdb;
    global $wppa_supported_video_extensions;
    global $wppa_supported_audio_extensions;
    // Log upload attempt
    wppa_log('Upl', 'FE Upload attempt of file ' . $file['name'] . ', size=' . filesize($file['tmp_name']));
    $album = wppa_cache_album($alb);
    // Legal here?
    if (!wppa_allow_uploads($alb) || !wppa_allow_user_uploads()) {
        wppa_alert(__('Max uploads reached', 'wp-photo-album-plus'));
        return false;
    }
    // No error during upload?
    if ($file['error'] != '0') {
        wppa_alert(__('Error during upload', 'wp-photo-album-plus'));
        return false;
    }
    // Find the filename
    $filename = wppa_sanitize_file_name($file['name']);
    $filename = wppa_strip_ext($filename);
    // See if this filename with any extension already exists in this album
    $id = $wpdb->get_var("SELECT `id` FROM `" . WPPA_PHOTOS . "` WHERE `filename` LIKE '" . $filename . ".%' AND `album` = " . $alb);
    // Addition to an av item?
    if ($id) {
        $is_av = wppa_get_photo_item($id, 'ext') == 'xxx';
    } else {
        $is_av = false;
    }
    // see if audio / video and process
    if (wppa_switch('enable_video') && wppa_switch('user_upload_video_on') && in_array(strtolower(wppa_get_ext($file['name'])), $wppa_supported_video_extensions) || wppa_switch('enable_audio') && wppa_switch('user_upload_audio_on') && in_array(strtolower(wppa_get_ext($file['name'])), $wppa_supported_audio_extensions)) {
        $is_av = true;
        // Find the name
        if (wppa_get_post('user-name')) {
            $name = wppa_get_post('user-name');
        } else {
            $name = $file['name'];
        }
        $name = wppa_sanitize_photo_name($name);
        $filename .= '.xxx';
        // update entry
        if ($id) {
            wppa_update_photo(array('id' => $id, 'ext' => 'xxx', 'filename' => $filename));
        }
        // Add new entry
        if (!$id) {
            $id = wppa_create_photo_entry(array('album' => $alb, 'filename' => $filename, 'ext' => 'xxx', 'name' => $name, 'description' => balanceTags(wppa_get_post('user-desc'), true)));
            if (!$id) {
                wppa_alert(__('Could not insert media into db.', 'wp-photo-album-plus'));
                return false;
            }
        }
        // Housekeeping
        wppa_update_album(array('id' => $alb, 'modified' => time()));
        wppa_flush_treecounts($alb);
        wppa_flush_upldr_cache('photoid', $id);
        // Add video filetype
        $ext = strtolower(wppa_get_ext($file['name']));
        $newpath = wppa_strip_ext(wppa_get_photo_path($id)) . '.' . $ext;
        copy($file['tmp_name'], $newpath);
        // Repair name if not standard
        if (!wppa_get_post('user-name')) {
            wppa_set_default_name($id, $file['name']);
        }
        // tags
        wppa_fe_add_tags($id);
        // custom
        wppa_fe_add_custom($id);
        // Done!
        return $id;
    }
    // If not already an existing audio / video; Forget the id from a previously found item with the same filename.
    if (!$is_av) {
        $id = false;
    }
    // Is it an image?
    $imgsize = getimagesize($file['tmp_name']);
    if (!is_array($imgsize)) {
        wppa_alert(__('Uploaded file is not an image', 'wp-photo-album-plus'));
        return false;
    }
    // Is it a supported image filetype?
    if ($imgsize[2] != IMAGETYPE_GIF && $imgsize[2] != IMAGETYPE_JPEG && $imgsize[2] != IMAGETYPE_PNG) {
        wppa_alert(sprintf(__('Only gif, jpg and png image files are supported. Returned info = %s.', 'wp-photo-album-plus'), wppa_serialize($imgsize)), false, false);
        return false;
    }
    // Is it not too big?
    $ms = wppa_opt('upload_fronend_maxsize');
    if ($ms) {
        // Max size configured
        if ($imgsize[0] > $ms || $imgsize[1] > $ms) {
            wppa_alert(sprintf(__('Uploaded file is larger than the allowed maximum of %d x %d pixels.', 'wp-photo-album-plus'), $ms, $ms));
            return false;
        }
    }
    // Check for already exists
    if (wppa_switch('void_dups')) {
        if (wppa_file_is_in_album(wppa_sanitize_file_name($file['name']), $alb)) {
            wppa_alert(sprintf(__('Uploaded file %s already exists in this album.', 'wp-photo-album-plus'), wppa_sanitize_file_name($file['name'])));
            return false;
        }
    }
    // Check for max memory needed to rocess image?
    $mayupload = wppa_check_memory_limit('', $imgsize[0], $imgsize[1]);
    if ($mayupload === false) {
        $maxsize = wppa_check_memory_limit(false);
        if (is_array($maxsize)) {
            wppa_alert(sprintf(__('The image is too big. Max photo size: %d x %d (%2.1f MegaPixel)', 'wp-photo-album-plus'), $maxsize['maxx'], $maxsize['maxy'], $maxsize['maxp'] / (1024 * 1024)));
            return false;
        }
    }
    // Find extension from mimetype
    switch ($imgsize[2]) {
        // mime type
        case 1:
            $ext = 'gif';
            break;
        case 2:
            $ext = 'jpg';
            break;
        case 3:
            $ext = 'png';
            break;
    }
    // Did the user supply a photoname?
    if (wppa_get_post('user-name')) {
        $name = wppa_get_post('user-name');
    } else {
        $name = $file['name'];
    }
    // Sanitize input
    $name = wppa_sanitize_photo_name($name);
    $desc = balanceTags(wppa_get_post('user-desc'), true);
    // If BlogIt! and no descrption given, use name field - this is for the shortcode used: typ"mphoto"
    if (!$desc && isset($_POST['wppa-blogit'])) {
        $desc = 'w#name';
    }
    // Find status and other needed data
    $linktarget = '_self';
    $status = wppa_switch('upload_moderate') && !current_user_can('wppa_admin') ? 'pending' : 'publish';
    if (wppa_switch('fe_upload_private')) {
        $status = 'private';
    }
    $filename = wppa_sanitize_file_name($file['name']);
    // Create new entry if this is not a posterfile
    if (!$is_av) {
        $id = wppa_create_photo_entry(array('album' => $alb, 'ext' => $ext, 'name' => $name, 'description' => $desc, 'status' => $status, 'filename' => $filename));
    }
    if (!$id) {
        wppa_alert(__('Could not insert photo into db.', 'wp-photo-album-plus'));
        return false;
    } else {
        wppa_save_source($file['tmp_name'], $filename, $alb);
        wppa_make_o1_source($id);
        wppa_update_album(array('id' => $alb, 'modified' => time()));
        wppa_flush_treecounts($alb);
        wppa_flush_upldr_cache('photoid', $id);
    }
    if (wppa_make_the_photo_files($file['tmp_name'], $id, $ext)) {
        // Repair photoname if not standard
        if (!wppa_get_post('user-name')) {
            wppa_set_default_name($id, $file['name']);
        }
        // Custom data
        wppa_fe_add_custom($id);
        // Add tags
        wppa_fe_add_tags($id);
        // and add watermark ( optionally ) to fullsize image only
        wppa_add_watermark($id);
        // Also to thumbnail?
        if (wppa_switch('watermark_thumbs')) {
            wppa_create_thumbnail($id);
            // create new thumb
        }
        // Is it a default coverimage?
        wppa_check_coverimage($id);
        // Mail
        if (wppa_switch('upload_notify')) {
            $to = get_bloginfo('admin_email');
            $subj = sprintf(__('New photo uploaded: %s', 'wp-photo-album-plus'), $name);
            $cont['0'] = sprintf(__('User %1$s uploaded photo %2$s into album %3$s', 'wp-photo-album-plus'), wppa_get_user(), $id, wppa_get_album_name($alb));
            if (wppa_switch('upload_moderate') && !current_user_can('wppa_admin')) {
                $cont['1'] = __('This upload requires moderation', 'wp-photo-album-plus');
                $cont['2'] = '<a href="' . get_admin_url() . 'admin.php?page=wppa_admin_menu&tab=pmod&photo=' . $id . '" >' . __('Moderate manage photo', 'wp-photo-album-plus') . '</a>';
            } else {
                $cont['1'] = __('Details:', 'wp-photo-album-plus');
                $cont['1'] .= ' <a href="' . get_admin_url() . 'admin.php?page=wppa_admin_menu&tab=pmod&photo=' . $id . '" >' . __('Manage photo', 'wp-photo-album-plus') . '</a>';
            }
            wppa_send_mail($to, $subj, $cont, $id);
        }
        return $id;
    }
    return false;
}
Example #6
0
function wppa_get_user_upload_html($alb, $width, $where = '', $mcr = false)
{
    static $seqno;
    // Init
    $result = '';
    $mocc = wppa('mocc');
    $occur = wppa('occur');
    // Using seqno to distinguish from different places within one occurrence because
    // the album no is not known when there is a selection box.
    if ($seqno) {
        $seqno++;
    } else {
        $seqno = '1';
    }
    // Feature enabled?
    if (!wppa_switch('user_upload_on')) {
        return '';
    }
    // Login required?
    if (wppa_switch('user_upload_login')) {
        if (!is_user_logged_in()) {
            return '';
        }
    }
    // I should have access to this album ( $alb > 0 ).
    if ($alb > '0') {
        $album_owner = wppa_get_album_item($alb, 'owner');
        if ($album_owner != wppa_get_user() && $album_owner != '--- public ---' && !wppa_have_access($alb)) {
            return '';
        }
    } else {
        if (!wppa_have_access()) {
            return '';
        }
    }
    // Find max files for the user
    $allow_me = wppa_allow_user_uploads();
    if (!$allow_me) {
        if (wppa_switch('show_album_full')) {
            $result .= '<div style="clear:both"></div>' . '<span style="color:red">' . __('Max uploads reached', 'wp-photo-album-plus') . wppa_time_to_wait_html('0', true) . '</span>';
        }
        return $result;
    }
    // Find max files for the album
    $allow_alb = wppa_allow_uploads($alb);
    if (!$allow_alb) {
        if (wppa_switch('show_album_full')) {
            $result .= '<div style="clear:both"></div>' . '<span style="color:red">' . __('Max uploads reached', 'wp-photo-album-plus') . wppa_time_to_wait_html($alb) . '</span>';
        }
        return $result;
    }
    if (wppa_is_user_blacklisted()) {
        return '';
    }
    // Find max files for the system
    $allow_sys = ini_get('max_file_uploads');
    // THE max
    if ($allow_me == '-1') {
        $allow_me = $allow_sys;
    }
    if ($allow_alb == '-1') {
        $allow_alb = $allow_sys;
    }
    $max = min($allow_me, $allow_alb, $allow_sys);
    // In a widget or multi column responsive?
    $small = wppa_in_widget() == 'upload' || $mcr;
    // Ajax upload?
    $ajax_upload = wppa_switch('ajax_upload') && wppa_browser_can_html5();
    //					&&
    // WINDOWS 10 / Edge bug
    //					! strpos( $_SERVER["HTTP_USER_AGENT"], 'Edge' ) &&
    //					! strpos( $_SERVER["HTTP_USER_AGENT"], 'Windows NT 10.0' );
    // Create the return url
    if ($ajax_upload) {
        $returnurl = wppa_switch('ajax_non_admin') ? WPPA_URL . '/wppa-ajax-front.php' : admin_url('admin-ajax.php');
        $returnurl .= '?action=wppa&amp;wppa-action=do-fe-upload';
    } else {
        $returnurl = wppa_get_permalink();
        if ($where == 'cover') {
            $returnurl .= 'wppa-album=' . $alb . '&amp;wppa-cover=0&amp;wppa-occur=' . $occur;
        } elseif ($where == 'thumb') {
            $returnurl .= 'wppa-album=' . $alb . '&amp;wppa-cover=0&amp;wppa-occur=' . $occur;
        } elseif ($where == 'widget' || $where == 'uploadbox') {
        }
        if (wppa('page')) {
            $returnurl .= '&amp;wppa-page=' . wppa('page');
        }
        $returnurl = trim($returnurl, '?');
        $returnurl = wppa_trim_wppa_($returnurl);
    }
    // Make the HTML
    $t = $mcr ? 'mcr-' : '';
    $result .= '<div style="clear:both"></div>' . '<a' . ' id="wppa-up-' . $alb . '-' . $mocc . '"' . ' class="wppa-upload-' . $where . '"' . ' onclick="' . 'jQuery( \'#wppa-file-' . $t . $alb . '-' . $mocc . '\' ).css( \'display\',\'block\' );' . 'jQuery( \'#wppa-up-' . $alb . '-' . $mocc . '\' ).css( \'display\',\'none\' );' . 'jQuery( \'#wppa-cr-' . $alb . '-' . $mocc . '\' ).css( \'display\',\'none\' );' . 'jQuery( \'#wppa-ea-' . $alb . '-' . $mocc . '\' ).css( \'display\',\'none\' );' . 'jQuery( \'#wppa-cats-' . $alb . '-' . $mocc . '\' ).css( \'display\',\'none\' );' . 'jQuery( \'#_wppa-up-' . $alb . '-' . $mocc . '\' ).css( \'display\',\'block\' );' . '_wppaDoAutocol( ' . $mocc . ' )' . '"' . ' style="float:left; cursor:pointer;' . '" >' . __('Upload Photo', 'wp-photo-album-plus') . '</a>' . '<a' . ' id="_wppa-up-' . $alb . '-' . $mocc . '"' . ' class="wppa-upload-' . $where . '"' . ' onclick="' . 'jQuery( \'#wppa-file-' . $t . $alb . '-' . $mocc . '\' ).css( \'display\',\'none\' );' . 'jQuery( \'#wppa-cr-' . $alb . '-' . $mocc . '\' ).css( \'display\',\'block\' );' . 'jQuery( \'#wppa-up-' . $alb . '-' . $mocc . '\' ).css( \'display\',\'block\' );' . 'jQuery( \'#wppa-ea-' . $alb . '-' . $mocc . '\' ).css( \'display\',\'block\' );' . 'jQuery( \'#wppa-cats-' . $alb . '-' . $mocc . '\' ).css( \'display\',\'block\' );' . 'jQuery( \'#_wppa-up-' . $alb . '-' . $mocc . '\' ).css( \'display\',\'none\' );' . '_wppaDoAutocol( ' . $mocc . ' )' . '"' . ' style="float:right; cursor:pointer;display:none;' . '" >' . __(wppa_opt('close_text'), 'wp-photo-album-plus') . '</a>' . '<div' . ' id="wppa-file-' . $t . $alb . '-' . $mocc . '"' . ' class="wppa-file-' . $t . $mocc . '"' . ' style="width:' . $width . 'px;text-align:center;display:none; clear:both;"' . ' >' . '<form' . ' id="wppa-uplform-' . $alb . '-' . $mocc . '"' . ' action="' . $returnurl . '"' . ' method="post"' . ' enctype="multipart/form-data"' . ' >' . wppa_nonce_field('wppa-check', 'wppa-nonce', false, false, $alb);
    // If no album given: select one
    if (!$alb) {
        $result .= '<select' . ' id="wppa-upload-album-' . $mocc . '-' . $seqno . '"' . ' name="wppa-upload-album"' . ' style="float:left; max-width: ' . $width . 'px;"' . ' onchange="jQuery( \'#wppa-sel-' . $alb . '-' . $mocc . '\' ).trigger( \'onchange\' )"' . ' >' . wppa_album_select_a(array('addpleaseselect' => true, 'checkowner' => true, 'checkupload' => true, 'path' => wppa_switch('hier_albsel'))) . '</select>' . '<br />';
    } else {
        $result .= '<input' . ' type="hidden"' . ' id="wppa-upload-album-' . $mocc . '-' . $seqno . '"' . ' name="wppa-upload-album"' . ' value="' . $alb . '"' . ' />';
    }
    // One only ?
    if (wppa_switch('upload_one_only') && !current_user_can('administrator')) {
        $result .= '<input' . ' type="file"' . ' accept="image/*"' . (wppa_switch('camera_connect') ? ' capture="capture"' : '') . ' class="wppa-user-file"' . ' style="' . 'width:auto;' . 'max-width:' . $width . ';' . 'margin:6px 0;' . 'float:left;' . __wcs('wppa-box-text') . '"' . ' id="wppa-user-upload-' . $alb . '-' . $mocc . '"' . ' name="wppa-user-upload-' . $alb . '-' . $mocc . '[]"' . ' onchange="jQuery( \'#wppa-user-submit-' . $alb . '-' . $mocc . '\' ).css( \'display\', \'block\' )"' . ' />';
    } else {
        $result .= '<input' . ' type="file"' . ' accept="image/*"' . (wppa_switch('camera_connect') ? ' capture="capture"' : '') . ' multiple="multiple"' . ' class="wppa-user-file"' . ' style="' . 'width:auto;' . 'max-width:' . $width . ';' . 'margin:6px 0;' . 'float:left;' . __wcs('wppa-box-text') . '"' . ' id="wppa-user-upload-' . $alb . '-' . $mocc . '"' . ' name="wppa-user-upload-' . $alb . '-' . $mocc . '[]"' . ' onchange="jQuery( \'#wppa-user-submit-' . $alb . '-' . $mocc . '\' ).css( \'display\', \'block\' )"' . ' />';
    }
    // Explanation
    if (!wppa_switch('upload_one_only') && !current_user_can('administrator')) {
        if ($max) {
            $result .= '<span style="font-size:10px;" >' . sprintf(_n('You may upload %d photo', 'You may upload up to %d photos at once if your browser supports HTML-5 multiple file upload', $max, 'wp-photo-album-plus'), $max) . '</span>';
            $maxsize = wppa_check_memory_limit(false);
            if (is_array($maxsize)) {
                $result .= '<br />' . '<span style="font-size:10px;" >' . sprintf(__('Max photo size: %d x %d (%2.1f MegaPixel)', 'wp-photo-album-plus'), $maxsize['maxx'], $maxsize['maxy'], $maxsize['maxp'] / (1024 * 1024)) . '</span>';
            }
        }
    }
    // Copyright notice
    if (wppa_switch('copyright_on')) {
        $result .= '<div style="clear:both;" >' . __(wppa_opt('copyright_notice'), 'wp-photo-album-plus') . '</div>';
    }
    // Watermark
    if (wppa_switch('watermark_on') && wppa_switch('watermark_user')) {
        $result .= '<table' . ' class="wppa-watermark wppa-box-text"' . ' style="margin:0; border:0; ' . __wcs('wppa-box-text') . '"' . ' >' . '<tbody>' . '<tr valign="top" style="border: 0 none; " >' . '<td' . ' class="wppa-box-text wppa-td"' . ' style="' . __wcs('wppa-box-text') . __wcs('wppa-td') . '"' . ' >' . __('Apply watermark file:', 'wp-photo-album-plus') . '</td>' . '</tr>' . '<tr>' . '<td' . ' class="wppa-box-text wppa-td"' . ' style="width: ' . $width . ';' . __wcs('wppa-box-text') . __wcs('wppa-td') . '"' . ' >' . '<select' . ' style="margin:0; padding:0; text-align:left; width:auto; "' . ' name="wppa-watermark-file"' . ' id="wppa-watermark-file"' . ' >' . wppa_watermark_file_select() . '</select>' . '</td>' . '</tr>' . '<tr valign="top" style="border: 0 none; " >' . '<td' . ' class="wppa-box-text wppa-td"' . ' style="width: ' . $width . ';' . __wcs('wppa-box-text') . __wcs('wppa-td') . '"' . ' >' . __('Position:', 'wp-photo-album-plus') . '</td>' . ($small ? '</tr><tr>' : '') . '<td' . ' class="wppa-box-text wppa-td"' . ' style="width: ' . $width . ';' . __wcs('wppa-box-text') . __wcs('wppa-td') . '"' . ' >' . '<select' . ' style="margin:0; padding:0; text-align:left; width:auto; "' . ' name="wppa-watermark-pos"' . ' id="wppa-watermark-pos"' . ' >' . wppa_watermark_pos_select() . '</select>' . '</td>' . '</tr>' . '</tbody>' . '</table>';
    }
    // Name
    if (wppa_switch('name_user')) {
        switch (wppa_opt('newphoto_name_method')) {
            case 'none':
                $expl = '';
                break;
            case '2#005':
                $expl = __('If you leave this blank, iptc tag 005 (Graphic name) will be used as photoname if available, else the original filename will be used as photo name.', 'wp-photo-album-plus');
                break;
            case '2#120':
                $expl = __('If you leave this blank, iptc tag 120 (Caption) will be used as photoname if available, else the original filename will be used as photo name.', 'wp-photo-album-plus');
                break;
            default:
                $expl = __('If you leave this blank, the original filename will be used as photo name.', 'wp-photo-album-plus');
        }
        $result .= '<div' . ' class="wppa-box-text wppa-td"' . ' style="' . 'clear:both;' . 'float:left;' . 'text-align:left;' . __wcs('wppa-box-text') . __wcs('wppa-td') . '"' . ' >' . __('Enter photo name', 'wp-photo-album-plus') . '&nbsp;' . '<span style="font-size:10px;" >' . $expl . '</span>' . '</div>' . '<input' . ' type="text"' . ' class="wppa-box-text wppa-file-' . $t . $mocc . '"' . ' style="padding:0; width:' . ($width - 6) . 'px; ' . __wcs('wppa-box-text') . '"' . ' name="wppa-user-name"' . ' />';
    }
    // Description user fillable ?
    if (wppa_switch('desc_user')) {
        $desc = wppa_switch('apply_newphoto_desc_user') ? stripslashes(wppa_opt('newphoto_description')) : '';
        $result .= '<div' . ' class="wppa-box-text wppa-td"' . ' style="clear:both; float:left; text-align:left; ' . __wcs('wppa-box-text') . __wcs('wppa-td') . '"' . ' >' . __('Enter/modify photo description', 'wp-photo-album-plus') . '</div>' . '<textarea' . ' class="wppa-user-textarea wppa-box-text wppa-file-' . $t . $mocc . '"' . ' style="height:120px; width:' . ($width - 6) . 'px; ' . __wcs('wppa-box-text') . '"' . ' name="wppa-user-desc"' . ' >' . $desc . '</textarea>';
    } elseif (wppa_switch('apply_newphoto_desc_user')) {
        $result .= '<input' . ' type="hidden"' . ' value="' . esc_attr(wppa_opt('newphoto_description')) . '"' . ' name="wppa-user-desc"' . ' />';
    }
    // Custom fields
    if (wppa_switch('fe_custom_fields')) {
        for ($i = '0'; $i < '10'; $i++) {
            if (wppa_opt('custom_caption_' . $i)) {
                $result .= '<div' . ' class="wppa-box-text wppa-td"' . ' style="clear:both; float:left; text-align:left; ' . __wcs('wppa-box-text') . __wcs('wppa-td') . '"' . ' >' . __(wppa_opt('custom_caption_' . $i), 'wp-photo-album-plus') . ': ' . (wppa_switch('custom_visible_' . $i) ? '' : '&nbsp;<small><i>(&nbsp;' . __('hidden', 'wp-photo-album-plus') . '&nbsp;)</i></small>') . '</div>' . '<input' . ' type="text"' . ' class="wppa-box-text wppa-file-' . $t . $mocc . '"' . ' style="padding:0; width:' . ($width - 6) . 'px; ' . __wcs('wppa-box-text') . '"' . ' name="wppa-user-custom-' . $i . '"' . ' />';
            }
        }
    }
    // Tags
    if (wppa_switch('fe_upload_tags')) {
        // Prepare onclick action
        $onc = 'wppaPrevTags(\'wppa-sel-' . $alb . '-' . $mocc . '\', \'wppa-inp-' . $alb . '-' . $mocc . '\', \'wppa-upload-album-' . $mocc . '-' . $seqno . '\', \'wppa-prev-' . $alb . '-' . $mocc . '\')';
        // Open the tag enter area
        $result .= '<div class="wppa-box-text wppa-td" style="clear:both; float:left; text-align:left; ' . __wcs('wppa-box-text') . __wcs('wppa-td') . '" >';
        // Selection boxes 1..3
        for ($i = '1'; $i < '4'; $i++) {
            if (wppa_switch('up_tagselbox_on_' . $i)) {
                $result .= '<div style="float:left; margin-right:4px;" >' . '<small>' . __(wppa_opt('up_tagselbox_title_' . $i), 'wp-photo-album-plus') . '</small><br />' . '<select' . ' id="wppa-sel-' . $alb . '-' . $mocc . '-' . $i . '"' . ' style="float:left; margin-right: 4px;"' . ' name="wppa-user-tags-' . $i . '[]"' . (wppa_switch('up_tagselbox_multi_' . $i) ? ' multiple' : '') . ' onchange="' . $onc . '"' . ' >';
                if (wppa_opt('up_tagselbox_content_' . $i)) {
                    // List of tags supplied
                    $tags = explode(',', wppa_opt('up_tagselbox_content_' . $i));
                    $result .= '<option value="" >&nbsp;</option>';
                    if (is_array($tags)) {
                        foreach ($tags as $tag) {
                            $result .= '<option class="wppa-sel-' . $alb . '-' . $mocc . '" value="' . $tag . '">' . $tag . '</option>';
                        }
                    }
                } else {
                    // All existing tags
                    $tags = wppa_get_taglist();
                    $result .= '<option value="" >&nbsp;</option>';
                    if (is_array($tags)) {
                        foreach ($tags as $tag) {
                            $result .= '<option class="wppa-sel-' . $alb . '-' . $mocc . '" value="' . $tag['tag'] . '">' . $tag['tag'] . '</option>';
                        }
                    }
                }
                $result .= '</select>' . '</div>';
            }
        }
        // New tags
        if (wppa_switch('up_tag_input_on')) {
            $result .= '<div style="float:left; margin-right:4px;" >' . '<small>' . __(wppa_opt('up_tag_input_title'), 'wp-photo-album-plus') . '</small><br />' . '<input' . ' id="wppa-inp-' . $alb . '-' . $mocc . '"' . ' type="text"' . ' class="wppa-box-text"' . ' style="padding:0; width:150px; ' . __wcs('wppa-box-text') . '"' . ' name="wppa-new-tags"' . ' onchange="' . $onc . '"' . ' />' . '</div>';
        }
        // Preview area
        if (wppa_switch('up_tag_preview')) {
            $result .= '<div style="margin:0; clear:both;" >' . __('Preview tags:', 'wp-photo-album-plus') . ' <small id="wppa-prev-' . $alb . '-' . $mocc . '"></small>' . '</div>' . '<script type="text/javascript" >jQuery( document ).ready(function() {' . $onc . '})</script>';
        }
        // Close tag enter area
        $result .= '</div>';
    }
    /* start submit section */
    // Onclick submit verify album is known
    if (!$alb) {
        $onclick = ' onclick="if ( document.getElementById( \'wppa-upload-album-' . $mocc . '-' . $seqno . '\' ).value == 0 )' . ' {alert( \'' . esc_js(__('Please select an album and try again', 'wp-photo-album-plus')) . '\' );return false;}"';
    } else {
        $onclick = '';
    }
    // The submit button
    $result .= '<input' . ' type="submit"' . ' id="wppa-user-submit-' . $alb . '-' . $mocc . '"' . $onclick . ' style="display:none; margin: 6px 0; float:right; ' . __wcs('wppa-box-text') . '"' . ' class="wppa-user-submit"' . ' name="wppa-user-submit-' . $alb . '-' . $mocc . '" value="' . __('Upload photo', 'wp-photo-album-plus') . '"' . ' />' . '<div style="clear:both"></div>';
    // if ajax: progression bar
    if ($ajax_upload) {
        $result .= '<div' . ' id="progress-' . $alb . '-' . $mocc . '"' . ' class="wppa-progress"' . ' style="border-color:' . wppa_opt('bcolor_upload') . '"' . ' >' . '<div id="bar-' . $alb . '-' . $mocc . '" class="wppa-bar" ></div>' . '<div id="percent-' . $alb . '-' . $mocc . '" class="wppa-percent" >0%</div >' . '</div>' . '<div id="message-' . $alb . '-' . $mocc . '" class="wppa-message" ></div>';
    }
    /* End submit section */
    // Done
    $result .= '</form></div>';
    // Ajax upload script
    if ($ajax_upload) {
        $result .= '<script>' . 'jQuery(document).ready(function() {

					var options = {
						beforeSend: function() {
							jQuery("#progress-' . $alb . '-' . $mocc . '").show();
							//clear everything
							jQuery("#bar-' . $alb . '-' . $mocc . '").width(\'0%\');
							jQuery("#message-' . $alb . '-' . $mocc . '").html("");
							jQuery("#percent-' . $alb . '-' . $mocc . '").html("");
						},
						uploadProgress: function(event, position, total, percentComplete) {
							jQuery("#bar-' . $alb . '-' . $mocc . '").width(percentComplete+\'%\');
							if ( percentComplete < 95 ) {
								jQuery("#percent-' . $alb . '-' . $mocc . '").html(percentComplete+\'%\');
							}
							else {
								jQuery("#percent-' . $alb . '-' . $mocc . '").html(\'Processing...\');
							}
						},
						success: function() {
							jQuery("#bar-' . $alb . '-' . $mocc . '").width(\'100%\');
							jQuery("#percent-' . $alb . '-' . $mocc . '").html(\'Done!\');
						},
						complete: function(response) {
							jQuery("#message-' . $alb . '-' . $mocc . '").html( \'<span style="font-size: 10px;" >\'+response.responseText+\'</span>\' );' . ($where == 'thumb' ? 'document.location.reload(true)' : '') . '
						},
						error: function() {
							jQuery("#message-' . $alb . '-' . $mocc . '").html( \'<span style="color: red;" >' . __('ERROR: unable to upload files.', 'wp-photo-album-plus') . '</span>\' );
						}
					};

					jQuery("#wppa-uplform-' . $alb . '-' . $mocc . '").ajaxForm(options);
				});
			</script>';
    }
    return $result;
}
function wppa_get_user_upload_html($xalb, $width, $where = '', $mcr = false)
{
    global $wpdb;
    global $wppa_supported_video_extensions;
    global $wppa_supported_audio_extensions;
    static $seqno;
    static $albums_granted;
    $albums_created = array();
    // Create granted albums only if not done yet i a previous occurance,
    // and an album id is given not being '0'
    if (wppa_is_int($xalb) && $xalb > '0') {
        if (!in_array($xalb, (array) $albums_granted, true)) {
            // This function will check if $xalb is a grant parent,
            // and make my subalbum if it does not already exist.
            $ta = wppa_grant_albums($xalb);
            if (!empty($ta)) {
                $albums_created = array_merge($albums_created, $ta);
            }
            // Remember we processed this possible grant parent
            $albums_granted[] = $xalb;
        }
    } elseif (wppa_is_enum($xalb)) {
        $temp = explode('.', wppa_expand_enum($xalb));
        foreach ($temp as $t) {
            if (!in_array($t, (array) $albums_granted, true)) {
                $ta = wppa_grant_albums($t);
                if (!empty($ta)) {
                    $albums_created = array_merge($albums_created, $ta);
                }
                $albums_granted[] = $t;
            }
        }
    }
    // If albums created, add them to the list, so they appear immediately
    $alb = $xalb;
    if (!empty($albums_created)) {
        foreach ($albums_created as $a) {
            $alb .= '.' . $a;
        }
    }
    // Init
    $mocc = wppa('mocc');
    $occur = wppa('occur');
    $yalb = str_replace('.', '', $xalb);
    // Open wrapper
    $result = '<div style="clear:both"></div>';
    //<div id="fe-upl-wrap-' . $mocc . '" style="background-color:#FFC;" >';
    // Using seqno to distinguish from different places within one occurrence because
    // the album no is not known when there is a selection box.
    if ($seqno) {
        $seqno++;
    } else {
        $seqno = '1';
    }
    // Feature enabled?
    if (!wppa_switch('user_upload_on')) {
        return '';
    }
    // Login required?
    if (wppa_switch('user_upload_login')) {
        if (!is_user_logged_in()) {
            return '';
        }
    } elseif (!is_user_logged_in()) {
        $public_exist = $wpdb->get_var("SELECT COUNT(*) " . "FROM `" . WPPA_ALBUMS . "` " . "WHERE `owner` = '--- public ---' ");
        if (!$public_exist) {
            return '';
        }
    }
    // Basically there are 3 possibilities for supplied album id(s)
    // 1. A single album
    // 2. '' or '0', meaning 'any'
    // 3. An album enumerations
    //
    // Now we are going to test if the visitor has access
    // Case 1. A single album. I should have access to this album ( $alb > 0 ).
    if (wppa_is_int($alb) && $alb > '0') {
        if (!wppa_have_access($alb)) {
            if (wppa_switch('upload_owner_only')) {
                return '';
            }
        }
    } elseif (!$alb) {
        $alb = trim(wppa_alb_to_enum_children('0') . '.' . wppa_alb_to_enum_children('-1'), '.');
    }
    // Case 3. An enumeration. Test for all albums in the enumeration, and remove the albums that he has no access to.
    // In this event, if a single album remains, there will not be a selectionbox, but its treated as if a single album was supplied.
    if (wppa_is_enum($alb)) {
        $albarr = explode('.', wppa_expand_enum($alb));
        foreach (array_keys($albarr) as $key) {
            if (!wppa_have_access($albarr[$key])) {
                if (wppa_switch('upload_owner_only')) {
                    unset($albarr[$key]);
                }
            }
        }
        if (empty($albarr)) {
            $alb = '';
        }
        if (count($albarr) == 1) {
            $alb = reset($albarr);
        } else {
            $alb = $albarr;
        }
    }
    // If no more albums left, no access, quit this proc.
    if (!$alb) {
        return '';
    }
    // The result is: $alb is either an album id, or an array of album ids. Always with upload access.
    // Find max files for the user
    $allow_me = wppa_allow_user_uploads();
    if (!$allow_me) {
        if (wppa_switch('show_album_full')) {
            $result .= '<h6 style="color:red">' . __('Max uploads reached', 'wp-photo-album-plus') . wppa_time_to_wait_html('0', true) . '</h6>';
        }
        return $result;
    }
    // Find max files for the album
    if (wppa_is_int($alb)) {
        $allow_alb = wppa_allow_uploads($alb);
        if (!$allow_alb) {
            if (wppa_switch('show_album_full')) {
                $result .= '<h6 style="color:red">' . __('Max uploads reached', 'wp-photo-album-plus') . wppa_time_to_wait_html($alb) . '</h6>';
            }
            return $result;
        }
    } else {
        $allow_alb = '-1';
    }
    if (wppa_is_user_blacklisted()) {
        return '';
    }
    // Find max files for the system
    $allow_sys = ini_get('max_file_uploads');
    // THE max
    if ($allow_me == '-1') {
        $allow_me = $allow_sys;
    }
    if ($allow_alb == '-1') {
        $allow_alb = $allow_sys;
    }
    $max = min($allow_me, $allow_alb, $allow_sys);
    // In a widget or multi column responsive?
    $small = wppa_in_widget() == 'upload' || $mcr;
    // Ajax upload?
    $ajax_upload = wppa_switch('ajax_upload') && wppa_browser_can_html5();
    // Create the return url
    if ($ajax_upload) {
        $returnurl = wppa_switch('ajax_non_admin') ? WPPA_URL . '/wppa-ajax-front.php' : admin_url('admin-ajax.php');
        $returnurl .= '?action=wppa&amp;wppa-action=do-fe-upload';
    } else {
        $returnurl = wppa_get_permalink();
        if ($where == 'cover') {
            $returnurl .= 'wppa-album=' . $alb . '&amp;wppa-cover=0&amp;wppa-occur=' . $occur;
        } elseif ($where == 'thumb') {
            $returnurl .= 'wppa-album=' . $alb . '&amp;wppa-cover=0&amp;wppa-occur=' . $occur;
        } elseif ($where == 'widget' || $where == 'uploadbox') {
        }
        if (wppa('page')) {
            $returnurl .= '&amp;wppa-page=' . wppa('page');
        }
        $returnurl = trim($returnurl, '?');
        $returnurl = wppa_trim_wppa_($returnurl);
    }
    // Make the HTML
    $t = $mcr ? 'mcr-' : '';
    $result .= '<a' . ' id="wppa-up-' . str_replace('.', '-', $yalb) . '-' . $mocc . '"' . ' class="wppa-upload-' . $where . ' wppa-album-cover-link"' . ' onclick="' . 'jQuery( \'#wppa-file-' . $t . str_replace('.', '-', $yalb) . '-' . $mocc . '\' ).css( \'display\',\'block\' );' . 'jQuery( \'#wppa-up-' . str_replace('.', '-', $yalb) . '-' . $mocc . '\' ).css( \'display\',\'none\' );' . 'jQuery( \'#wppa-cr-' . str_replace('.', '-', $yalb) . '-' . $mocc . '\' ).css( \'display\',\'none\' );' . 'jQuery( \'#wppa-ea-' . str_replace('.', '-', $yalb) . '-' . $mocc . '\' ).css( \'display\',\'none\' );' . 'jQuery( \'#wppa-cats-' . str_replace('.', '-', $yalb) . '-' . $mocc . '\' ).css( \'display\',\'none\' );' . 'jQuery( \'#_wppa-up-' . str_replace('.', '-', $yalb) . '-' . $mocc . '\' ).css( \'display\',\'block\' );' . '_wppaDoAutocol( ' . $mocc . ' )' . '"' . ' style="float:left; cursor:pointer;' . '" >' . __('Upload Photo', 'wp-photo-album-plus') . '</a>' . '<a' . ' id="_wppa-up-' . str_replace('.', '-', $yalb) . '-' . $mocc . '"' . ' class="wppa-upload-' . $where . ' wppa-album-cover-link"' . ' onclick="' . 'jQuery( \'#wppa-file-' . $t . str_replace('.', '-', $yalb) . '-' . $mocc . '\' ).css( \'display\',\'none\' );' . 'jQuery( \'#wppa-cr-' . str_replace('.', '-', $yalb) . '-' . $mocc . '\' ).css( \'display\',\'block\' );' . 'jQuery( \'#wppa-up-' . str_replace('.', '-', $yalb) . '-' . $mocc . '\' ).css( \'display\',\'block\' );' . 'jQuery( \'#wppa-ea-' . str_replace('.', '-', $yalb) . '-' . $mocc . '\' ).css( \'display\',\'block\' );' . 'jQuery( \'#wppa-cats-' . str_replace('.', '-', $yalb) . '-' . $mocc . '\' ).css( \'display\',\'block\' );' . 'jQuery( \'#_wppa-up-' . str_replace('.', '-', $yalb) . '-' . $mocc . '\' ).css( \'display\',\'none\' );' . '_wppaDoAutocol( ' . $mocc . ' )' . '"' . ' style="float:right; cursor:pointer;display:none;' . '" >' . __(wppa_opt('close_text'), 'wp-photo-album-plus') . '</a>' . '<div' . ' id="wppa-file-' . $t . str_replace('.', '-', $yalb) . '-' . $mocc . '"' . ' class=""' . ' style="width:100%;text-align:center;display:none; clear:both;"' . ' >' . '<form' . ' id="wppa-uplform-' . $yalb . '-' . $mocc . '"' . ' action="' . $returnurl . '"' . ' method="post"' . ' enctype="multipart/form-data"' . ' >' . wppa_nonce_field('wppa-check', 'wppa-nonce', false, false, $yalb);
    // Single Album given
    if (wppa_is_int($alb)) {
        $result .= '<input' . ' type="hidden"' . ' id="wppa-upload-album-' . $mocc . '-' . $seqno . '"' . ' name="wppa-upload-album"' . ' value="' . $alb . '"' . ' />';
    } else {
        if (!is_array($alb)) {
            $alb = explode('.', wppa_expand_enum($alb));
        }
        // Can an selection box be displayed?
        if (!wppa_opt('fe_upload_max_albums') || wppa_opt('fe_upload_max_albums') > wppa_get_uploadable_album_count($alb)) {
            // Below max
            $result .= '<select' . ' id="wppa-upload-album-' . $mocc . '-' . $seqno . '"' . ' name="wppa-upload-album"' . ' style="float:left; max-width: 100%;"' . ' onchange="jQuery( \'#wppa-sel-' . $yalb . '-' . $mocc . '\' ).trigger( \'onchange\' )"' . ' >' . wppa_album_select_a(array('addpleaseselect' => true, 'checkowner' => true, 'checkupload' => true, 'path' => wppa_switch('hier_albsel'), 'checkarray' => count($alb) > 1, 'array' => $alb)) . '</select>' . '<br />';
        } else {
            $result .= '<input' . ' id="wppa-upload-album-' . $mocc . '-' . $seqno . '"' . ' type="number"' . ' placeholder="' . esc_attr(__('Enter album id', 'wp-photo-album-plus')) . '"' . ' name="wppa-upload-album"' . ' style="float:left; max-width: 100%;"' . ' onchange="jQuery( \'#wppa-sel-' . $yalb . '-' . $mocc . '\' ).trigger( \'onchange\' )"' . ' />' . '<br />';
        }
    }
    $one_only = wppa_switch('upload_one_only');
    $multiple = !$one_only;
    $on_camera = wppa_switch('camera_connect');
    $may_video = wppa_switch('user_upload_video_on');
    $may_audio = wppa_switch('user_upload_audio_on');
    $accept = '.jpg,.gif,.png';
    if ($may_video) {
        $accept .= ',.' . implode(',.', $wppa_supported_video_extensions);
    }
    if ($may_audio) {
        $accept .= ',.' . implode(',.', $wppa_supported_audio_extensions);
    }
    if ($one_only) {
        if ($on_camera) {
            if ($may_video) {
                $value = esc_attr(__('Select Photo / Video / Camera', 'wp-photo-album-plus'));
            } else {
                $value = esc_attr(__('Select Photo / Camera', 'wp-photo-album-plus'));
            }
        } else {
            if ($may_video) {
                $value = esc_attr(__('Select Photo / Video', 'wp-photo-album-plus'));
            } else {
                $value = esc_attr(__('Select Photo', 'wp-photo-album-plus'));
            }
        }
    } else {
        if ($on_camera) {
            if ($may_video) {
                $value = esc_attr(__('Select Photos / Video / Camera', 'wp-photo-album-plus'));
            } else {
                $value = esc_attr(__('Select Photos / Camera', 'wp-photo-album-plus'));
            }
        } else {
            if ($may_video) {
                $value = esc_attr(__('Select Photos / Video', 'wp-photo-album-plus'));
            } else {
                $value = esc_attr(__('Select Photos', 'wp-photo-album-plus'));
            }
        }
    }
    $result .= '<input' . ' type="file"' . ' accept="' . $accept . '"' . ($multiple ? ' multiple="multiple"' : '') . ' style="' . 'display:none;' . '"' . ' id="wppa-user-upload-' . $yalb . '-' . $mocc . '"' . ' name="wppa-user-upload-' . $yalb . '-' . $mocc . '[]"' . ' onchange="' . 'jQuery( \'#wppa-user-submit-' . $yalb . '-' . $mocc . '\' ).css( \'display\', \'block\' );' . 'wppaDisplaySelectedFiles(\'wppa-user-upload-' . $yalb . '-' . $mocc . '\')' . '"' . ' />';
    if ($on_camera) {
        $result .= '<script>jQuery(\'#wppa-user-upload-' . $yalb . '-' . $mocc . '\').attr(\'capture\',\'capture\')</script>';
    }
    $result .= '<input' . ' type="button"' . ' style="width:100%;margin-top:8px;margin-bottom:8px;padding-left:0;padding-right:0;"' . ' id="wppa-user-upload-' . $yalb . '-' . $mocc . '-display"' . ' value="' . $value . '"' . ' onclick="jQuery( \'#wppa-user-upload-' . $yalb . '-' . $mocc . '\' ).click();"' . '/>';
    // Explanation
    if (!wppa_switch('upload_one_only')) {
        if ($max) {
            $result .= '<div style="font-size:10px;" >' . sprintf(_n('You may upload %d photo', 'You may upload up to %d photos at once if your browser supports HTML-5 multiple file upload', $max, 'wp-photo-album-plus'), $max) . '</div>';
            $maxsize = wppa_check_memory_limit(false);
            if (is_array($maxsize)) {
                $result .= '<div style="font-size:10px;" >' . sprintf(__('Max photo size: %d x %d (%2.1f MegaPixel)', 'wp-photo-album-plus'), $maxsize['maxx'], $maxsize['maxy'], $maxsize['maxp'] / (1024 * 1024)) . '</div>';
            }
        }
    }
    // Copyright notice
    if (wppa_switch('copyright_on')) {
        $result .= '<div style="width:100%;clear:both;" >' . __(wppa_opt('copyright_notice'), 'wp-photo-album-plus') . '</div>';
    }
    // Watermark
    if (wppa_switch('watermark_on') && wppa_switch('watermark_user')) {
        $result .= '<table' . ' class="wppa-watermark wppa-box-text"' . ' style="margin:0; border:0; ' . __wcs('wppa-box-text') . '"' . ' >' . '<tbody>' . '<tr valign="top" style="border: 0 none; " >' . '<td' . ' class="wppa-box-text wppa-td"' . ' style="' . __wcs('wppa-box-text') . __wcs('wppa-td') . '"' . ' >' . __('Apply watermark file:', 'wp-photo-album-plus') . '</td>' . '</tr>' . '<tr>' . '<td' . ' class="wppa-box-text wppa-td"' . ' style="width: ' . $width . ';' . __wcs('wppa-box-text') . __wcs('wppa-td') . '"' . ' >' . '<select' . ' style="margin:0; padding:0; text-align:left; width:auto; "' . ' name="wppa-watermark-file"' . ' id="wppa-watermark-file"' . ' >' . wppa_watermark_file_select() . '</select>' . '</td>' . '</tr>' . '<tr valign="top" style="border: 0 none; " >' . '<td' . ' class="wppa-box-text wppa-td"' . ' style="width: ' . $width . ';' . __wcs('wppa-box-text') . __wcs('wppa-td') . '"' . ' >' . __('Position:', 'wp-photo-album-plus') . '</td>' . ($small ? '</tr><tr>' : '') . '<td' . ' class="wppa-box-text wppa-td"' . ' style="width: ' . $width . ';' . __wcs('wppa-box-text') . __wcs('wppa-td') . '"' . ' >' . '<select' . ' style="margin:0; padding:0; text-align:left; width:auto; "' . ' name="wppa-watermark-pos"' . ' id="wppa-watermark-pos"' . ' >' . wppa_watermark_pos_select() . '</select>' . '</td>' . '</tr>' . '</tbody>' . '</table>';
    }
    // Name
    if (wppa_switch('name_user')) {
        switch (wppa_opt('newphoto_name_method')) {
            case 'none':
                $expl = '';
                break;
            case '2#005':
                $expl = __('If you leave this blank, iptc tag 005 (Graphic name) will be used as photoname if available, else the original filename will be used as photo name.', 'wp-photo-album-plus');
                break;
            case '2#120':
                $expl = __('If you leave this blank, iptc tag 120 (Caption) will be used as photoname if available, else the original filename will be used as photo name.', 'wp-photo-album-plus');
                break;
            default:
                $expl = __('If you leave this blank, the original filename will be used as photo name.', 'wp-photo-album-plus');
        }
        $result .= '<h6>' . __('Photo name', 'wp-photo-album-plus') . '</h6>' . '<div style="clear:left;font-size:10px;" >' . $expl . '</div>' . '<input' . ' type="text"' . ' class="wppa-box-text"' . ' style="border:1 px solid ' . wppa_opt('bcolor_upload') . ';clear:left; padding:0; width:100%; ' . __wcs('wppa-box-text') . '"' . ' name="wppa-user-name"' . ' />';
    }
    // Description user fillable ?
    if (wppa_switch('desc_user')) {
        $desc = wppa_switch('apply_newphoto_desc_user') ? stripslashes(wppa_opt('newphoto_description')) : '';
        $result .= '<h6>' . __('Photo description', 'wp-photo-album-plus') . '</h6>' . '<textarea' . ' class="wppa-user-textarea wppa-box-text"' . ' style="border:1 px solid ' . wppa_opt('bcolor_upload') . ';clear:left; padding:0; height:120px; width:100%; ' . __wcs('wppa-box-text') . '"' . ' name="wppa-user-desc"' . ' >' . $desc . '</textarea>';
    } elseif (wppa_switch('apply_newphoto_desc_user')) {
        $result .= '<input' . ' type="hidden"' . ' value="' . esc_attr(wppa_opt('newphoto_description')) . '"' . ' name="wppa-user-desc"' . ' />';
    }
    // Custom fields
    if (wppa_switch('fe_custom_fields')) {
        for ($i = '0'; $i < '10'; $i++) {
            if (wppa_opt('custom_caption_' . $i)) {
                $result .= '<h6>' . __(wppa_opt('custom_caption_' . $i), 'wp-photo-album-plus') . ': ' . (wppa_switch('custom_visible_' . $i) ? '' : '&nbsp;<small><i>(&nbsp;' . __('hidden', 'wp-photo-album-plus') . '&nbsp;)</i></small>') . '</h6>' . '<input' . ' type="text"' . ' class="wppa-box-text"' . ' style="border:1 px solid ' . wppa_opt('bcolor_upload') . ';clear:left; padding:0; width:100%; ' . __wcs('wppa-box-text') . '"' . ' name="wppa-user-custom-' . $i . '"' . ' />';
            }
        }
    }
    // Tags
    if (wppa_switch('fe_upload_tags')) {
        // Prepare onclick action
        $onc = 'wppaPrevTags(\'wppa-sel-' . $yalb . '-' . $mocc . '\', \'wppa-inp-' . $yalb . '-' . $mocc . '\', \'wppa-upload-album-' . $mocc . '-' . $seqno . '\', \'wppa-prev-' . $yalb . '-' . $mocc . '\')';
        // Open the tag enter area
        $result .= '<div style="clear:both;" >';
        // Selection boxes 1..3
        for ($i = '1'; $i < '4'; $i++) {
            if (wppa_switch('up_tagselbox_on_' . $i)) {
                $result .= '<h6>' . __(wppa_opt('up_tagselbox_title_' . $i), 'wp-photo-album-plus') . '</h6>' . '<select' . ' id="wppa-sel-' . $yalb . '-' . $mocc . '-' . $i . '"' . ' name="wppa-user-tags-' . $i . '[]"' . (wppa_switch('up_tagselbox_multi_' . $i) ? ' multiple' : '') . ' onchange="' . $onc . '"' . ' >';
                if (wppa_opt('up_tagselbox_content_' . $i)) {
                    // List of tags supplied
                    $tags = explode(',', wppa_opt('up_tagselbox_content_' . $i));
                    $result .= '<option value="" >&nbsp;</option>';
                    if (is_array($tags)) {
                        foreach ($tags as $tag) {
                            $result .= '<option class="wppa-sel-' . $yalb . '-' . $mocc . '" value="' . urlencode($tag) . '">' . $tag . '</option>';
                        }
                    }
                } else {
                    // All existing tags
                    $tags = wppa_get_taglist();
                    $result .= '<option value="" >&nbsp;</option>';
                    if (is_array($tags)) {
                        foreach ($tags as $tag) {
                            $result .= '<option class="wppa-sel-' . $yalb . '-' . $mocc . '" value="' . urlencode($tag['tag']) . '">' . $tag['tag'] . '</option>';
                        }
                    }
                }
                $result .= '</select><div style="clear:both;" ></div>';
            }
        }
        // New tags
        if (wppa_switch('up_tag_input_on')) {
            $result .= '<h6>' . __(wppa_opt('up_tag_input_title'), 'wp-photo-album-plus') . '</h6>' . '<input' . ' id="wppa-inp-' . $yalb . '-' . $mocc . '"' . ' type="text"' . ' class="wppa-box-text "' . ' style="padding:0; width:100%; ' . __wcs('wppa-box-text') . '"' . ' name="wppa-new-tags"' . ' onchange="' . $onc . '"' . ' />';
        }
        // Preview area
        if (wppa_switch('up_tag_preview')) {
            $result .= '<h6>' . __('Preview tags:', 'wp-photo-album-plus') . ' <small id="wppa-prev-' . $yalb . '-' . $mocc . '"></small>' . '</h6>' . '<script type="text/javascript" >jQuery( document ).ready(function() {' . $onc . '})</script>';
        }
        // Close tag enter area
        $result .= '</div>';
    }
    /* The Blogit section */
    if (($where == 'widget' || $where == 'uploadbox') && current_user_can('edit_posts') && wppa_switch('blog_it')) {
        $result .= '<div style="margin-top:6px;" >' . '<input' . ' type="button"' . ' value="' . esc_attr(__('Blog it?', 'wp-photo-album-plus')) . '"' . ' onclick="jQuery(\'#wppa-blogit-' . $yalb . '-' . $mocc . '\').trigger(\'click\')"' . ' />' . ' <input' . ' type="checkbox"' . ' id="wppa-blogit-' . $yalb . '-' . $mocc . '"' . ' name="wppa-blogit"' . ' style="display:none;"' . ' onchange="if ( jQuery(this).attr(\'checked\') ) { ' . 'jQuery(\'#blog-div-' . $yalb . '-' . $mocc . '\').css(\'display\',\'block\'); ' . 'jQuery(\'#wppa-user-submit-' . $yalb . '-' . $mocc . '\').attr(\'value\', \'' . esc_js(__('Upload and blog', 'wp-photo-album-plus')) . '\'); ' . '} ' . 'else { ' . 'jQuery(\'#blog-div-' . $yalb . '-' . $mocc . '\').css(\'display\',\'none\'); ' . 'jQuery(\'#wppa-user-submit-' . $yalb . '-' . $mocc . '\').attr(\'value\', \'' . esc_js(__('Upload photo', 'wp-photo-album-plus')) . '\'); ' . '} "' . ' />' . '<div' . ' id="blog-div-' . $yalb . '-' . $mocc . '"' . ' style="display:none;"' . ' />' . '<h6>' . __('Post title:', 'wp-photo-album-plus') . '</h6>' . '<input' . ' id="wppa-blogit-title-' . $yalb . '-' . $mocc . '"' . ' type="text"' . ' class="wppa-box-text "' . ' style="padding:0; width:100%; ' . __wcs('wppa-box-text') . '"' . ' name="wppa-post-title"' . ' />' . '<h6>' . __('Text BEFORE the image:', 'wp-photo-album-plus') . '</h6>' . '<textarea' . ' id="wppa-blogit-pretext-' . $yalb . '-' . $mocc . '"' . ' name="wppa-blogit-pretext"' . ' class=wppa-user-textarea wppa-box-text"' . ' style="border:1 px solid ' . wppa_opt('bcolor_upload') . ';clear:left; padding:0; height:120px; width:100%; ' . __wcs('wppa-box-text') . '"' . ' >' . '</textarea>' . '<h6>' . __('Text AFTER the image:', 'wp-photo-album-plus') . '</h6>' . '<textarea' . ' id="wppa-blogit-posttext-' . $yalb . '-' . $mocc . '"' . ' name="wppa-blogit-posttext"' . ' class=wppa-user-textarea wppa-box-text"' . ' style="border:1 px solid ' . wppa_opt('bcolor_upload') . ';clear:left; padding:0; height:120px; width:100%; ' . __wcs('wppa-box-text') . '"' . '>' . '</textarea>' . '</div>' . '</div>';
    }
    /* start submit section */
    // Onclick submit verify album is known
    if (!$alb) {
        $onclick = ' onclick="if ( document.getElementById( \'wppa-upload-album-' . $mocc . '-' . $seqno . '\' ).value == 0 )' . ' {alert( \'' . esc_js(__('Please select an album and try again', 'wp-photo-album-plus')) . '\' );return false;}"';
    } else {
        $onclick = '';
    }
    // The submit button
    $result .= '<div style="height:6px;;clear:both;" ></div>' . '<input' . ' type="submit"' . ' id="wppa-user-submit-' . $yalb . '-' . $mocc . '"' . $onclick . ' style="display:none; margin: 6px 0; float:right;"' . ' class="wppa-user-submit"' . ' name="wppa-user-submit-' . $yalb . '-' . $mocc . '" value="' . esc_attr(__('Upload photo', 'wp-photo-album-plus')) . '"' . ' />' . '<div style="height:6px;clear:both;"></div>';
    // if ajax: progression bar
    if ($ajax_upload) {
        $result .= '<div' . ' id="progress-' . $yalb . '-' . $mocc . '"' . ' class="wppa-progress "' . ' style="width:100%;border-color:' . wppa_opt('bcolor_upload') . '"' . ' >' . '<div id="bar-' . $yalb . '-' . $mocc . '" class="wppa-bar" ></div>' . '<div id="percent-' . $yalb . '-' . $mocc . '" class="wppa-percent" >0%</div >' . '</div>' . '<div id="message-' . $yalb . '-' . $mocc . '" class="wppa-message" ></div>';
    }
    /* End submit section */
    // Done
    $result .= '</form></div>';
    // Ajax upload script
    if ($ajax_upload) {
        $result .= '<script>' . 'jQuery(document).ready(function() {

					var options = {
						beforeSend: function() {
							jQuery("#progress-' . $yalb . '-' . $mocc . '").show();
							//clear everything
							jQuery("#bar-' . $yalb . '-' . $mocc . '").width(\'0%\');
							jQuery("#message-' . $yalb . '-' . $mocc . '").html("");
							jQuery("#percent-' . $yalb . '-' . $mocc . '").html("");
						},
						uploadProgress: function(event, position, total, percentComplete) {
							jQuery("#bar-' . $yalb . '-' . $mocc . '").width(percentComplete+\'%\');
							if ( percentComplete < 95 ) {
								jQuery("#percent-' . $yalb . '-' . $mocc . '").html(percentComplete+\'%\');
							}
							else {
								jQuery("#percent-' . $yalb . '-' . $mocc . '").html(\'Processing...\');
							}
						},
						success: function() {
							jQuery("#bar-' . $yalb . '-' . $mocc . '").width(\'100%\');
							jQuery("#percent-' . $yalb . '-' . $mocc . '").html(\'Done!\');
						},
						complete: function(response) {
							jQuery("#message-' . $yalb . '-' . $mocc . '").html( \'<span style="font-size: 10px;" >\'+response.responseText+\'</span>\' );' . ($where == 'thumb' ? 'document.location.reload(true)' : '') . '
						},
						error: function() {
							jQuery("#message-' . $yalb . '-' . $mocc . '").html( \'<span style="color: red;" >' . __('ERROR: unable to upload files.', 'wp-photo-album-plus') . '</span>\' );
						}
					};

					jQuery("#wppa-uplform-' . $yalb . '-' . $mocc . '").ajaxForm(options);
				});
			</script>';
    }
    // Close wrapper
    //	$result .= '</div>';
    return $result;
}