示例#1
0
function wppa_cache_album($id, $data = '')
{
    global $wpdb;
    static $album;
    static $album_cache_2;
    // Action?
    if ($id == 'invalidate') {
        if (isset($album_cache_2[$data])) {
            unset($album_cache_2[$data]);
        }
        $album = false;
        return false;
    }
    if ($id == 'add') {
        if (!$data) {
            // Nothing to add
            return false;
        } elseif (isset($data['id'])) {
            // Add a single album to 2nd level cache
            $album_cache_2[$data['id']] = $data;
            // Looks valid
        } else {
            foreach ($data as $album) {
                // Add multiple
                if (isset($album['id'])) {
                    // Looks valid
                    $album_cache_2[$album['id']] = $album;
                }
            }
        }
        return false;
    }
    if ($id == 'count') {
        if (is_array($album_cache_2)) {
            return count($album_cache_2);
        } else {
            return false;
        }
    }
    if (wppa_is_enum($id) && !wppa_is_int($id)) {
        return false;
        // enums not supporte yet
    }
    if (!wppa_is_int($id) || $id < '1') {
        $album = false;
        wppa_dbg_msg('Invalid arg wppa_cache_album(' . $id . ')', 'red');
        return false;
    }
    // In first level cache?
    if (isset($album['id']) && $album['id'] == $id) {
        wppa_dbg_q('G-A1');
        return $album;
    }
    // In  second level cache?
    if (!empty($album_cache_2)) {
        if (in_array($id, array_keys($album_cache_2))) {
            $album = $album_cache_2[$id];
            wppa_dbg_q('G-A2');
            return $album;
        }
    }
    // Not in cache, do query
    $album = $wpdb->get_row($wpdb->prepare("SELECT * FROM `" . WPPA_ALBUMS . "` WHERE `id` = %s", $id), ARRAY_A);
    wppa_dbg_q('Q-A');
    // Found one?
    if ($album) {
        // Store in second level cache
        $album_cache_2[$id] = $album;
        return $album;
    } else {
        wppa_dbg_msg('Album ' . $id . ' does not exist', 'red');
        return false;
    }
}
function wppa_get_album_id_by_name($xname, $report_dups = false)
{
    global $wpdb;
    global $allalbums;
    if (wppa_is_int($xname)) {
        return $xname;
        // Already numeric
    }
    if (wppa_is_enum($xname)) {
        return $xname;
        // Is enumeration
    }
    $name = wppa_decode_uri_component($xname);
    $name = str_replace('\'', '%', $name);
    // A trick for single quotes
    $name = str_replace('"', '%', $name);
    // A trick for double quotes
    $name = stripslashes($name);
    $albs = $wpdb->get_results("SELECT `id` FROM `" . WPPA_ALBUMS . "` WHERE `name` LIKE '%" . $name . "%'", ARRAY_A);
    if ($albs) {
        if (count($albs == 1)) {
            wppa_dbg_msg('Alb ' . $albs[0]['id'], ' found for ' . $xname);
            $aid = $albs[0]['id'];
        } else {
            wppa_dbg_msg('Dups found for ' . $xname);
            if ($report_dups) {
                $aid = false;
            } else {
                $aid = $albs[0]['id'];
            }
        }
    } else {
        $aid = false;
    }
    if ($aid) {
        wppa_dbg_msg('Aid ' . $aid . ' found for ' . $name);
    } else {
        wppa_dbg_msg('No aid found for ' . $name);
    }
    return $aid;
}
function wppa_cache_album($id, $data = '')
{
    global $wpdb;
    static $album;
    static $album_cache_2;
    // Init. If there are less than 1000 albums, cache them all on beforehand.
    // This reduces the number of queries for albums to two.
    // Only for front-end
    if (empty($album_cache_2) && !is_admin()) {
        // Find # of albums
        $n_albs = $wpdb->get_var("SELECT COUNT(*) FROM `" . WPPA_ALBUMS . "`");
        if ($n_albs && $n_albs < 1000) {
            // Get them all
            $allalbs = $wpdb->get_results("SELECT * FROM `" . WPPA_ALBUMS . "`", ARRAY_A);
            // Store in 2nd level cache
            foreach ($allalbs as $album) {
                // Add multiple
                if (isset($album['id'])) {
                    // Looks valid
                    $album_cache_2[$album['id']] = $album;
                }
            }
        }
    }
    // Action?
    if ($id == 'invalidate') {
        if (isset($album_cache_2[$data])) {
            unset($album_cache_2[$data]);
        }
        $album = false;
        return false;
    }
    if ($id == 'add') {
        if (!$data) {
            // Nothing to add
            return false;
        } elseif (isset($data['id'])) {
            // Add a single album to 2nd level cache
            $album_cache_2[$data['id']] = $data;
            // Looks valid
        } else {
            foreach ($data as $album) {
                // Add multiple
                if (isset($album['id'])) {
                    // Looks valid
                    $album_cache_2[$album['id']] = $album;
                }
            }
        }
        return false;
    }
    if ($id == 'count') {
        if (is_array($album_cache_2)) {
            return count($album_cache_2);
        } else {
            return false;
        }
    }
    if (wppa_is_enum($id) && !wppa_is_int($id)) {
        return false;
        // enums not supporte yet
    }
    if ($id == '-9') {
        return false;
    }
    if (!wppa_is_int($id) || $id < '1') {
        $album = false;
        wppa_dbg_msg('Invalid arg wppa_cache_album(' . $id . ')', 'red');
        return false;
    }
    // In first level cache?
    if (isset($album['id']) && $album['id'] == $id) {
        wppa_dbg_cachecounts('albumhit');
        return $album;
    }
    // In  second level cache?
    if (!empty($album_cache_2)) {
        if (in_array($id, array_keys($album_cache_2))) {
            $album = $album_cache_2[$id];
            wppa_dbg_cachecounts('albumhit');
            return $album;
        }
    }
    // Not in cache, do query
    $album = $wpdb->get_row($wpdb->prepare("SELECT * FROM `" . WPPA_ALBUMS . "` WHERE `id` = %s", $id), ARRAY_A);
    wppa_dbg_cachecounts('albummis');
    // Found one?
    if ($album) {
        // Store in second level cache
        $album_cache_2[$id] = $album;
        return $album;
    } else {
        wppa_dbg_msg('Album ' . $id . ' does not exist (cache album)', 'red');
        wppa_log('dbg', 'Album ' . $id . ' does not exist (cache album)', true);
        return false;
    }
}
function wppa_get_album_id_by_name($xname, $report_dups = false)
{
    global $wpdb;
    global $allalbums;
    if (wppa_is_int($xname)) {
        return $xname;
        // Already numeric
    }
    if (wppa_is_enum($xname)) {
        return $xname;
        // Is enumeration
    }
    $name = wppa_decode_uri_component($xname);
    $name = str_replace('\'', '%', $name);
    // A trick for single quotes
    $name = str_replace('"', '%', $name);
    // A trick for double quotes
    $name = stripslashes($name);
    $query = "SELECT * FROM `" . WPPA_ALBUMS . "` WHERE `name` LIKE '%" . $name . "%'";
    $albs = $wpdb->get_results($query, ARRAY_A);
    if ($albs) {
        if (count($albs) == 1) {
            wppa_dbg_msg('Alb ' . $albs[0]['id'], ' found for ' . $xname);
            $aid = $albs[0]['id'];
        } else {
            wppa_dbg_msg('Dups found for ' . $xname);
            if ($report_dups == 'report_dups') {
                $aid = false;
            } elseif ($report_dups == 'return_dups') {
                $aid = '';
                foreach ($albs as $alb) {
                    $aid .= $alb['id'] . '.';
                }
                $aid = rtrim($aid, '.');
            } else {
                // Find the best match
                foreach ($albs as $alb) {
                    $aname = __($alb['name']);
                    // Possibly qTranslate translated
                    $aname = str_replace('\'', '%', $aname);
                    // A trick for single quotes
                    $aname = str_replace('"', '%', $aname);
                    // A trick for double quotes
                    $aname = stripslashes($aname);
                    wppa_dbg_msg('Testing ' . $aname . ' for ' . $name . ' (get_album_id_by_name)');
                    if (strcasecmp($aname, $name) == 0) {
                        $aid = $alb['id'];
                    }
                }
                // No perfect match, take the first 'like' option
                if (!$aid) {
                    $aid = $albs[0]['id'];
                }
            }
        }
    } else {
        $aid = false;
    }
    if ($aid) {
        wppa_dbg_msg('Aid ' . $aid . ' found for ' . $name);
    } else {
        wppa_dbg_msg('No aid found for ' . $name);
    }
    return $aid;
}
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;
}