function wppa_get_video_html($args)
{
    global $wppa;
    extract(wp_parse_args((array) $args, array('id' => '0', 'width' => '0', 'height' => '0', 'controls' => true, 'margin_top' => '0', 'margin_bottom' => '0', 'tagid' => 'video-' . $wppa['mocc'], 'cursor' => '', 'events' => '', 'title' => '', 'preload' => 'metadata', 'onclick' => '', 'lb' => false, 'class' => '', 'style' => '', 'use_thumb' => false, 'autoplay' => false)));
    // No id? no go
    if (!$id) {
        return '';
    }
    // Not a video? no go
    if (!wppa_is_video($id)) {
        return '';
    }
    extract(wp_parse_args((array) wppa_is_video($id), array('mp4' => false, 'ogv' => false, 'webm' => false)));
    // Prepare attributes
    $w = $width ? ' width:' . $width . 'px;' : '';
    $h = $height ? ' height:' . $height . 'px;' : '';
    $t = $margin_top ? ' margin-top:' . $margin_top . 'px;' : '';
    $b = $margin_bottom ? ' margin-bottom:' . $margin_bottom . 'px;' : '';
    $ctrl = $controls ? ' controls' : '';
    $tit = $title ? ' title="' . $title . '"' : '';
    $onc = $onclick ? ' onclick="' . $onclick . '"' : '';
    $cls = $class ? ' class="' . $class . '"' : '';
    $style = $style ? rtrim(trim($style), ';') . ';' : '';
    $play = $autoplay ? ' autoplay' : '';
    // See if there is a poster image
    $poster_photo_path = wppa_fix_poster_ext(wppa_get_photo_path($id), $id);
    $poster_thumb_path = wppa_fix_poster_ext(wppa_get_thumb_path($id), $id);
    $poster_photo = is_file($poster_photo_path) ? ' poster="' . wppa_fix_poster_ext(wppa_get_photo_url($id), $id) . '"' : '';
    $poster_thumb = is_file($poster_thumb_path) ? ' poster="' . wppa_fix_poster_ext(wppa_get_thumb_url($id), $id) . '"' : '';
    $poster = '';
    // Init to none
    // Thumbnail?
    if ($use_thumb) {
        $poster = $poster_thumb;
    } else {
        $poster = $poster_photo;
    }
    // If the poster exists and no controls, we need no preload at all.
    if ($poster && !$controls) {
        $preload = 'none';
    }
    // Do we have html5 video tag supported filetypes on board?
    if ($mp4 || $ogv || $webm) {
        // Assume the browser supports html5
        $result = '<video id="' . $tagid . '" ' . $ctrl . $play . ' style="' . $style . $w . $h . $t . $b . $cursor . '" ' . $events . ' ' . $tit . $onc . $poster . ' preload="' . $preload . '"' . $cls . ' >';
        $result .= wppa_get_video_body($id, false, $width, $height);
        // Close the video tag
        $result .= '</video>';
    }
    // Done
    return $result;
}
function _wppa_sidebar_page_options()
{
    global $wpdb;
    global $wppa_defaults;
    wppa_set_defaults();
    $onch = 'myReload()';
    // Handle spinner js and declare functions
    echo '<script type="text/javascript" >' . 'var didsome=false;' . 'jQuery(document).ready(function() {' . 'jQuery(\'#wppa-spinner\').css(\'display\', \'none\');' . '});' . 'function myReload() {' . 'jQuery(\'#wppa-spinner\').css(\'display\', \'block\');' . '_wppaRefreshAfter = true;' . '};' . 'function wppaSetFixed(id) {' . 'if (jQuery(\'#wppa-widget-photo-\' + id).attr(\'checked\') == \'checked\' ) {' . '_wppaRefreshAfter = true;' . 'wppaAjaxUpdateOptionValue(\'potd_photo\', id);' . '}' . '};' . '</script>';
    // The spinner
    echo '<img' . ' id="wppa-spinner"' . ' style="position:fixed;top:50%;left:50%;z-index:1000;margin-top:-33px;margin-left:-33px;display:block;"' . ' src="' . wppa_get_imgdir('loader.gif') . '"' . '/>';
    // Open wrapper
    echo '<div class="wrap">';
    // The settings icon
    echo '<img src="' . wppa_get_imgdir('settings32.png') . '" />';
    // The Page title
    echo '<h1 style="display:inline;" >' . __('Photo of the Day (Widget) Settings', 'wp-photo-album-plus') . '</h1>' . __('Changes are updated immediately. The page will reload if required.', 'wp-photo-album-plus') . '<br />&nbsp;';
    // The nonce
    wp_nonce_field('wppa-nonce', 'wppa-nonce');
    // The settings table
    echo '<table class="widefat wppa-table wppa-setting-table">';
    // The header
    echo '<thead style="font-weight: bold; " class="wppa_table_1">' . '<tr>' . '<td>' . __('#', 'wp-photo-album-plus') . '</td>' . '<td>' . __('Name', 'wp-photo-album-plus') . '</td>' . '<td>' . __('Description', 'wp-photo-album-plus') . '</td>' . '<td>' . __('Setting', 'wp-photo-album-plus') . '</td>' . '<td>' . __('Help', 'wp-photo-album-plus') . '</td>' . '</tr>' . '</thead>';
    // Open the table body
    echo '<tbody class="wppa_table" >';
    $name = __('Widget Title:', 'wp-photo-album-plus');
    $desc = __('The title of the widget.', 'wp-photo-album-plus');
    $help = esc_js(__('Enter/modify the title for the widget. This is a default and can be overriden at widget activation.', 'wp-photo-album-plus'));
    $slug = 'wppa_potd_title';
    $html = wppa_input($slug, '85%');
    wppa_setting($slug, '1', $name, $desc, $html, $help);
    $name = __('Widget Photo Width:', 'wp-photo-album-plus');
    $desc = __('Enter the desired display width of the photo in the sidebar.', 'wp-photo-album-plus');
    $help = '';
    $slug = 'wppa_potd_widget_width';
    $html = wppa_input($slug, '40px', '', __('pixels wide', 'wp-photo-album-plus'));
    wppa_setting($slug, '2', $name, $desc, $html, $help);
    $name = __('Horizontal alignment:', 'wp-photo-album-plus');
    $desc = __('Enter the desired display alignment of the photo in the sidebar.', 'wp-photo-album-plus');
    $help = '';
    $slug = 'wppa_potd_align';
    $opts = array(__('--- none ---', 'wp-photo-album-plus'), __('left', 'wp-photo-album-plus'), __('center', 'wp-photo-album-plus'), __('right', 'wp-photo-album-plus'));
    $vals = array('none', 'left', 'center', 'right');
    $html = wppa_select($slug, $opts, $vals);
    wppa_setting($slug, '3', $name, $desc, $html, $help);
    $linktype = wppa_opt('potd_linktype');
    if ($linktype == 'custom') {
        $name = __('Link to:', 'wp-photo-album-plus');
        $desc = __('Enter the url. Do\'nt forget the HTTP://', 'wp-photo-album-plus');
        $help = '';
        $slug = 'wppa_potd_linkurl';
        $html = wppa_input($slug, '85%');
        wppa_setting($slug, '4', $name, $desc, $html, $help);
        $name = __('Link Title:', 'wp-photo-album-plus');
        $desc = __('The balloon text when hovering over the photo.', 'wp-photo-album-plus');
        $help = '';
        $slug = 'wppa_potd_linktitle';
        $html = wppa_input($slug, '85%');
        wppa_setting($slug, '4a', $name, $desc, $html, $help);
    } else {
        $name = __('Link to:', 'wp-photo-album-plus');
        $desc = __('Links are set on the <b>Photo Albums -> Settings</b> screen.', 'wp-photo-album-plus');
        $help = '';
        $slug = 'wppa_potd_linkurl';
        $html = '';
        wppa_setting($slug, '4', $name, $desc, $html, $help);
    }
    $name = __('Subtitle:', 'wp-photo-album-plus');
    $desc = __('Select the content of the subtitle.', 'wp-photo-album-plus');
    $help = '';
    $slug = 'wppa_potd_subtitle';
    $opts = array(__('--- none ---', 'wp-photo-album-plus'), __('Photo Name', 'wp-photo-album-plus'), __('Description', 'wp-photo-album-plus'), __('Owner', 'wp-photo-album-plus'));
    $vals = array('none', 'name', 'desc', 'owner');
    $html = wppa_select($slug, $opts, $vals);
    wppa_setting($slug, '5', $name, $desc, $html, $help);
    $name = __('Counter:', 'wp-photo-album-plus');
    $desc = __('Display a counter of other photos in the album.', 'wp-photo-album-plus');
    $help = '';
    $slug = 'wppa_potd_counter';
    $html = wppa_checkbox($slug);
    wppa_setting($slug, '6', $name, $desc, $html, $help);
    $name = __('Link to:', 'wp-photo-album-plus');
    $desc = __('The counter links to.', 'wp-photo-album-plus');
    $help = '';
    $slug = 'wppa_potd_counter_link';
    $opts = array(__('thumbnails', 'wp-photo-album-plus'), __('slideshow', 'wp-photo-album-plus'), __('single image', 'wp-photo-album-plus'));
    $vals = array('thumbs', 'slide', 'single');
    $html = wppa_select($slug, $opts, $vals);
    wppa_setting($slug, '7', $name, $desc, $html, $help);
    $name = __('Type of album(s) to use:', 'wp-photo-album-plus');
    $desc = __('Select physical or virtual.', 'wp-photo-album-plus');
    $help = '';
    $slug = 'wppa_potd_album_type';
    $opts = array(__('physical albums', 'wp-photo-album-plus'), __('virtual albums', 'wp-photo-album-plus'));
    $vals = array('physical', 'virtual');
    $html = wppa_select($slug, $opts, $vals, $onch);
    wppa_setting($slug, '8', $name, $desc, $html, $help);
    $name = __('Albums to use:', 'wp-photo-album-plus');
    $desc = __('Select the albums to use for the photo of the day.', 'wp-photo-album-plus');
    $help = '';
    $slug = 'wppa_potd_album';
    if (get_option('wppa_potd_album_type') == 'physical') {
        $html = '<select' . ' id="wppa_potd_album"' . ' name="wppa_potd_album"' . ' style="float:left; max-width: 100%;"' . ' multiple="multiple"' . ' onchange="didsome=true;wppaAjaxUpdateOptionValue(\'potd_album\', this, true)"' . ' onmouseout="if(didsome)document.location.reload(true);"' . ' size="10"' . ' >' . wppa_album_select_a(array('path' => true, 'optionclass' => 'potd_album', 'selected' => get_option('wppa_potd_album'))) . '</select>' . '<img id="img_potd_album" class="" src="' . wppa_get_imgdir() . 'star.ico" title="' . __('Setting unmodified', 'wp-photo-album-plus') . '" style="padding:0 4px; float:left; height:16px; width:16px;" />';
        wppa_setting($slug, '9', $name, $desc, $html, $help);
    } else {
        $desc = __('Select the albums to use for the photo of the day.', 'wp-photo-album-plus');
        $opts = array(__('- all albums -', 'wp-photo-album-plus'), __('- all -separate- albums -', 'wp-photo-album-plus'), __('- all albums except -separate-', 'wp-photo-album-plus'), __('- top rated photos -', 'wp-photo-album-plus'));
        $vals = array('all', 'sep', 'all-sep', 'topten');
        $html = wppa_select($slug, $opts, $vals);
        wppa_setting($slug, '9', $name, $desc, $html, $help);
    }
    if (get_option('wppa_potd_album_type') == 'physical') {
        $name = __('Include (grand)children:', 'wp-photo-album-plus');
        $desc = __('Include the photos of all sub albums?', 'wp-photo-album-plus');
        $help = '';
        $slug = 'wppa_potd_include_subs';
        $html = wppa_checkbox($slug, $onch);
        wppa_setting($slug, '9a', $name, $desc, $html, $help);
        $name = __('Inverse selection:', 'wp-photo-album-plus');
        $desc = __('Use any album, except the selection made above.', 'wp-photo-album-plus');
        $help = '';
        $slug = 'wppa_potd_inverse';
        $html = wppa_checkbox($slug, $onch);
        wppa_setting($slug, '9b', $name, $desc, $html, $help);
    }
    $name = __('Status filter:', 'wp-photo-album-plus');
    $desc = __('Use only photos with a certain status.', 'wp-photo-album-plus');
    $help = esc_js(__('Select - none - if you want no filtering on status.', 'wp-photo-album-plus'));
    $slug = 'wppa_potd_status_filter';
    $opts = array(__('- none -', 'wp-photo-album-plus'), __('Publish', 'wp-photo-album-plus'), __('Featured', 'wp-photo-album-plus'), __('Gold', 'wp-photo-album-plus'), __('Silver', 'wp-photo-album-plus'), __('Bronze', 'wp-photo-album-plus'), __('Any medal', 'wp-photo-album-plus'));
    $vals = array('none', 'publish', 'featured', 'gold', 'silver', 'bronze', 'anymedal');
    $html = wppa_select($slug, $opts, $vals);
    wppa_setting($slug, '10', $name, $desc, $html, $help);
    $name = __('Display method:', 'wp-photo-album-plus');
    $desc = __('Select the way a photo will be selected.', 'wp-photo-album-plus');
    $help = '';
    $slug = 'wppa_potd_method';
    $opts = array(__('Fixed photo', 'wp-photo-album-plus'), __('Random', 'wp-photo-album-plus'), __('Last upload', 'wp-photo-album-plus'), __('Change every', 'wp-photo-album-plus'));
    $vals = array('1', '2', '3', '4');
    $html = wppa_select($slug, $opts, $vals, $onch);
    wppa_setting($slug, '11', $name, $desc, $html, $help);
    if (get_option('wppa_potd_method') == '4') {
        // Change every
        $name = __('Change every period:', 'wp-photo-album-plus');
        $desc = __('The time period a certain photo is used.', 'wp-photo-album-plus');
        $help = '';
        $slug = 'wppa_potd_period';
        $opts = array(__('pageview.', 'wp-photo-album-plus'), __('hour.', 'wp-photo-album-plus'), __('day.', 'wp-photo-album-plus'), __('week.', 'wp-photo-album-plus'), __('month.', 'wp-photo-album-plus'), __('day of week is order#', 'wp-photo-album-plus'), __('day of month is order#', 'wp-photo-album-plus'), __('day of year is order#', 'wp-photo-album-plus'));
        $vals = array('0', '1', '24', '168', '736', 'day-of-week', 'day-of-month', 'day-of-year');
        $html = wppa_select($slug, $opts, $vals, $onch);
        wppa_setting($slug, '11a', $name, $desc, $html, $help);
        $wppa_widget_period = get_option('wppa_potd_period');
        if (substr($wppa_widget_period, 0, 7) == 'day-of-') {
            switch (substr($wppa_widget_period, 7)) {
                case 'week':
                    $n_days = '7';
                    $date_key = 'w';
                    break;
                case 'month':
                    $n_days = '31';
                    $date_key = 'd';
                    break;
                case 'year':
                    $n_days = '366';
                    $date_key = 'z';
                    break;
            }
            while (get_option('wppa_potd_offset', '0') > $n_days) {
                update_option('wppa_potd_offset', get_option('wppa_potd_offset') - $n_days);
            }
            while (get_option('wppa_potd_offset', '0') < '0') {
                update_option('wppa_potd_offset', get_option('wppa_potd_offset') + $n_days);
            }
            $name = __('Day offset:', 'wp-photo-album-plus');
            $desc = __('The difference between daynumber and photo order number.', 'wp-photo-album-plus');
            $help = '';
            $slug = 'wppa_potd_offset';
            $opts = array();
            $day = '0';
            while ($day < $n_days) {
                $opts[] = $day;
                $day++;
            }
            $vals = $opts;
            $html = '<span style="float:left;" >' . sprintf(__('Current day# = %s, offset =', 'wp-photo-album-plus'), wppa_local_date($date_key)) . '</span> ' . wppa_select($slug, $opts, $vals, $onch);
            $photo_order = wppa_local_date($date_key) - get_option('wppa_potd_offset', '0');
            while ($photo_order < '0') {
                $photo_order += $n_days;
            }
            $html .= sprintf(__('Todays photo order# = %s.', 'wp-photo-album-plus'), $photo_order);
            wppa_setting($slug, '11b', $name, $desc, $html, $help);
        }
    }
    $name = __('Preview', 'wp-photo-album-plus');
    $desc = __('Current "photo of the day":', 'wp-photo-album-plus');
    $help = '';
    $slug = 'wppa_potd_photo';
    $photo = wppa_get_potd();
    if ($photo) {
        $html = '<div style="display:inline-block;width:25%;text-align:center;vertical-align:middle;">' . '<img src="' . wppa_fix_poster_ext(wppa_get_thumb_url($photo['id']), $photo['id']) . '" />' . '</div>' . '<div style="display:inline-block;width:75%;text-align:center;vertical-align:middle;" >' . __('Album', 'wp-photo-album-plus') . ': ' . wppa_get_album_name($photo['album']) . '<br />' . __('Uploader', 'wp-photo-album-plus') . ': ' . $photo['owner'] . '</div>';
    } else {
        $html = __('Not found.', 'wp-photo-album-plus');
    }
    wppa_setting($slug, '12', $name, $desc, $html, $help);
    $name = __('Show selection', 'wp-photo-album-plus');
    $desc = __('Show the photos in the current selection.', 'wp-photo-album-plus');
    $help = '';
    $slug = 'wppa_potd_preview';
    $html = wppa_checkbox($slug, $onch);
    wppa_setting($slug, '13', $name, $desc, $html, $help);
    // Cose table body
    echo '</tbody>';
    // Table footer
    echo '<tfoot style="font-weight: bold;" >' . '<tr>' . '<td>' . __('#', 'wp-photo-album-plus') . '</td>' . '<td>' . __('Name', 'wp-photo-album-plus') . '</td>' . '<td>' . __('Description', 'wp-photo-album-plus') . '</td>' . '<td>' . __('Setting', 'wp-photo-album-plus') . '</td>' . '<td>' . __('Help', 'wp-photo-album-plus') . '</td>' . '</tr>' . '</tfoot>' . '</table>';
    // Diagnostic
    //		echo
    //		'Diagnostic: wppa_potd_album = ' . get_option( 'wppa_potd_album' ) . ' wppa_potd_photo = ' . get_option( 'wppa_potd_photo' );
    // Status star must be here for js
    echo '<img' . ' id="img_potd_photo"' . ' src="' . wppa_get_imgdir('star.ico') . '" style="height:12px;display:none;"' . ' />';
    // The potd photo pool
    echo '<table class="widefat wppa-table wppa-setting-table" >';
    // Table header
    echo '<thead>' . '<tr>' . '<td>' . __('Photos in the current selection', 'wp-photo-album-plus') . '</td>' . '</tr>' . '</thead>';
    // Table body
    if (wppa_switch('potd_preview')) {
        echo '<tbody>' . '<tr>' . '<td>';
        // Get the photos
        $alb = wppa_opt('potd_album');
        $opt = wppa_is_int($alb) ? ' ' . wppa_get_photo_order($alb) . ' ' : '';
        $photos = wppa_get_widgetphotos($alb, $opt);
        // Count them
        $cnt = count($photos);
        // Find current
        $curid = wppa_opt('potd_photo');
        // See if we do this
        if (empty($photos)) {
            _e('No photos in the selection', 'wp-photo-album-plus');
        } elseif ($cnt > '5000') {
            echo sprintf(__('There are too many photos in the selection to show a preview ( %d )', 'wp-photo-album-plus'), $cnt);
        } else {
            // Yes, display the pool
            foreach ($photos as $photo) {
                $id = $photo['id'];
                // Open container div
                echo '<div' . ' class="photoselect"' . ' style="' . 'width:180px;' . 'height:300px;' . '" >';
                // Open image container div
                echo '<div' . ' style="' . 'width:180px;' . 'height:135px;' . 'overflow:hidden;' . 'text-align:center;' . '" >';
                // The image if a video
                if (wppa_is_video($id)) {
                    echo wppa_get_video_html(array('id' => $id, 'style' => 'width:180px;'));
                } else {
                    echo '<img' . ' src=" ' . wppa_fix_poster_ext(wppa_get_thumb_url($id), $id) . '"' . ' style="' . 'max-width:180px;' . 'max-height:135px;' . 'margin:auto;' . '"' . ' alt="' . esc_attr(wppa_get_photo_name($id)) . '" />';
                    // Audio ?
                    if (wppa_has_audio($id)) {
                        echo wppa_get_audio_html(array('id' => $id, 'style' => 'width:180px;' . 'position:relative;' . 'bottom:' . (wppa_get_audio_control_height() + 4) . 'px;'));
                    }
                }
                // Close image container div
                echo '</div>';
                // The order# and select radio box
                echo '<div style="clear:both;width:100%;margin:3px 0;position:relative;top:5px;" >' . '<div style="font-size:9px; line-height:10px;float:left;">(#' . $photo['p_order'] . ')</div>';
                if (get_option('wppa_potd_method') == '1') {
                    // Only if fixed photo
                    echo '<input' . ' style="float:right;"' . ' type="radio"' . ' name="wppa-widget-photo"' . ' id="wppa-widget-photo-' . $id . '"' . ' value="' . $id . '"' . ($id == $curid ? 'checked="checked"' : '') . ' onchange="wppaSetFixed(' . $id . ');"' . ' />';
                }
                echo '</div>';
                // The name/desc boxecho
                echo '<div style="clear:both;overflow:hidden;height:150px;position:relative;top:10px;" >' . '<div style="font-size:11px; overflow:hidden;">' . wppa_get_photo_name($id) . '</div>' . '<div style="font-size:9px; line-height:10px;">' . wppa_get_photo_desc($id) . '</div>' . '</div>';
                // Close container
                echo '</div>';
            }
            echo '<div class="clear"></div>';
        }
        // Close the table
        echo '</td>' . '</tr>' . '</tbody>';
    }
    echo '</table>';
    // Close wrap
    echo '</div>';
}
 /** @see WP_Widget::widget */
 function widget($args, $instance)
 {
     global $wpdb;
     require_once dirname(__FILE__) . '/wppa-links.php';
     require_once dirname(__FILE__) . '/wppa-styles.php';
     require_once dirname(__FILE__) . '/wppa-functions.php';
     require_once dirname(__FILE__) . '/wppa-thumbnails.php';
     require_once dirname(__FILE__) . '/wppa-boxes-html.php';
     require_once dirname(__FILE__) . '/wppa-slideshow.php';
     wppa_initialize_runtime();
     wppa('in_widget', 'topten');
     wppa_bump_mocc();
     extract($args);
     $instance = wp_parse_args((array) $instance, array('title' => '', 'sortby' => 'mean_rating', 'title' => '', 'album' => '', 'display' => 'thumbs', 'meanrat' => 'yes', 'ratcount' => 'yes', 'viewcount' => 'yes', 'includesubs' => 'yes', 'medalsonly' => 'no', 'showowner' => 'no', 'showalbum' => 'no'));
     $widget_title = apply_filters('widget_title', $instance['title']);
     $page = in_array(wppa_opt('topten_widget_linktype'), wppa('links_no_page')) ? '' : wppa_get_the_landing_page('topten_widget_linkpage', __('Top Ten Photos', 'wp-photo-album-plus'));
     $albumlinkpage = wppa_get_the_landing_page('topten_widget_album_linkpage', __('Top Ten Photo album', 'wp-photo-album-plus'));
     $max = wppa_opt('topten_count');
     $album = $instance['album'];
     switch ($instance['sortby']) {
         case 'mean_rating':
             $sortby = '`mean_rating` DESC, `rating_count` DESC, `views` DESC';
             break;
         case 'rating_count':
             $sortby = '`rating_count` DESC, `mean_rating` DESC, `views` DESC';
             break;
         case 'views':
             $sortby = '`views` DESC, `mean_rating` DESC, `rating_count` DESC';
             break;
     }
     $display = $instance['display'];
     $meanrat = $instance['meanrat'] == 'yes';
     $ratcount = $instance['ratcount'] == 'yes';
     $viewcount = $instance['viewcount'] == 'yes';
     $includesubs = $instance['includesubs'] == 'yes';
     $albenum = '';
     $medalsonly = $instance['medalsonly'] == 'yes';
     $showowner = $instance['showowner'] == 'yes';
     $showalbum = $instance['showalbum'] == 'yes';
     wppa('medals_only', $medalsonly);
     $likes = wppa_opt('rating_display_type') == 'likes';
     // When likes only, mean rating has no meaning, chan to (rating)(like)count
     if ($likes && $instance['sortby'] == 'mean_rating') {
         $instance['sortby'] = 'rating_count';
     }
     // Album specified?
     if ($album) {
         // All albums ?
         if ($album == '-2') {
             $album = '0';
         }
         // Albums of owner is current logged in user or public?
         if ($album == '-3') {
             $temp = $wpdb->get_results("SELECT `id` FROM `" . WPPA_ALBUMS . "` WHERE `owner` = '--- public ---' OR `owner` = '" . wppa_get_user() . "' ORDER BY `id`", ARRAY_A);
             $album = '';
             if ($temp) {
                 foreach ($temp as $t) {
                     $album .= '.' . $t['id'];
                 }
                 $album = ltrim($album, '.');
             }
         }
         // Including subalbums?
         if ($includesubs) {
             $albenum = wppa_alb_to_enum_children($album);
             $albenum = wppa_expand_enum($albenum);
             $album = str_replace('.', ',', $albenum);
         }
         // Doit
         if ($medalsonly) {
             $thumbs = $wpdb->get_results("SELECT * FROM `" . WPPA_PHOTOS . "` " . "WHERE `album` IN (" . $album . ") " . "AND `status` IN ( 'gold', 'silver', 'bronze' ) " . "ORDER BY " . $sortby . " " . "LIMIT " . $max, ARRAY_A);
         } else {
             $thumbs = $wpdb->get_results("SELECT * FROM `" . WPPA_PHOTOS . "` " . "WHERE `album` IN (" . $album . ") " . "ORDER BY " . $sortby . " " . "LIMIT " . $max, ARRAY_A);
         }
     } else {
         if ($medalsonly) {
             $thumbs = $wpdb->get_results("SELECT * FROM `" . WPPA_PHOTOS . "` " . "WHERE `status` IN ( 'gold', 'silver', 'bronze' ) " . "ORDER BY " . $sortby . " " . "LIMIT " . $max, ARRAY_A);
         } else {
             $thumbs = $wpdb->get_results("SELECT * FROM `" . WPPA_PHOTOS . "` " . "ORDER BY " . $sortby . " " . "LIMIT " . $max, ARRAY_A);
         }
     }
     $widget_content = "\n" . '<!-- WPPA+ TopTen Widget start -->';
     $maxw = wppa_opt('topten_size');
     $maxh = $maxw;
     $lineheight = wppa_opt('fontsize_widget_thumb') * 1.5;
     $maxh += $lineheight;
     if ($meanrat) {
         $maxh += $lineheight;
     }
     if ($ratcount) {
         $maxh += $lineheight;
     }
     if ($viewcount) {
         $maxh += $lineheight;
     }
     if ($showowner) {
         $maxh += $lineheight;
     }
     if ($showalbum) {
         $maxh += $lineheight;
     }
     if ($thumbs) {
         foreach ($thumbs as $image) {
             $thumb = $image;
             // Make the HTML for current picture
             if ($display == 'thumbs') {
                 $widget_content .= "\n" . '<div class="wppa-widget" style="width:' . $maxw . 'px; height:' . $maxh . 'px; margin:4px; display:inline; text-align:center; float:left;">';
             } else {
                 $widget_content .= "\n" . '<div class="wppa-widget" >';
             }
             if ($image) {
                 $no_album = !$album;
                 if ($no_album) {
                     $tit = __('View the top rated photos', 'wp-photo-album-plus');
                 } else {
                     $tit = esc_attr(__(stripslashes($image['description'])));
                 }
                 $compressed_albumenum = wppa_compress_enum($albenum);
                 $link = wppa_get_imglnk_a('topten', $image['id'], '', $tit, '', $no_album, $compressed_albumenum);
                 $file = wppa_get_thumb_path($image['id']);
                 $imgstyle_a = wppa_get_imgstyle_a($image['id'], $file, $maxw, 'center', 'ttthumb');
                 $imgurl = wppa_get_thumb_url($image['id'], '', $imgstyle_a['width'], $imgstyle_a['height']);
                 $imgevents = wppa_get_imgevents('thumb', $image['id'], true);
                 $title = $link ? esc_attr(stripslashes($link['title'])) : '';
                 $widget_content .= wppa_get_the_widget_thumb('topten', $image, $album, $display, $link, $title, $imgurl, $imgstyle_a, $imgevents);
                 $widget_content .= "\n\t" . '<div style="font-size:' . wppa_opt('fontsize_widget_thumb') . 'px; line-height:' . $lineheight . 'px;">';
                 // Display (owner) ?
                 if ($showowner) {
                     $widget_content .= '<div>(' . $image['owner'] . ')</div>';
                 }
                 // Display (album) ?
                 if ($showalbum) {
                     $href = wppa_convert_to_pretty(wppa_encrypt_url(wppa_get_album_url($image['album'], $albumlinkpage, 'content', '1')));
                     $widget_content .= '<div>(<a href="' . $href . '" >' . wppa_get_album_name($image['album']) . '</a>)</div>';
                 }
                 // Display the rating
                 if ($likes) {
                     $lt = wppa_get_like_title_a($image['id']);
                 }
                 switch ($instance['sortby']) {
                     case 'mean_rating':
                         if ($meanrat == 'yes') {
                             $widget_content .= '<div>' . wppa_get_rating_by_id($image['id']) . '</div>';
                         }
                         if ($ratcount == 'yes') {
                             $n = wppa_get_rating_count_by_id($image['id']);
                             $widget_content .= '<div>' . sprintf(_n('%d vote', '%d votes', $n, 'wp-photo-album-plus'), $n) . '</div>';
                         }
                         if ($viewcount == 'yes') {
                             $n = $image['views'];
                             $widget_content .= '<div>' . sprintf(_n('%d view', '%d views', $n, 'wp-photo-album-plus'), $n) . '</div>';
                         }
                         break;
                     case 'rating_count':
                         if ($ratcount == 'yes') {
                             $n = wppa_get_rating_count_by_id($image['id']);
                             $widget_content .= '<div>' . ($likes ? $lt['display'] : sprintf(_n('%d vote', '%d votes', $n, 'wp-photo-album-plus'), $n)) . '</div>';
                         }
                         if ($meanrat == 'yes') {
                             $widget_content .= '<div>' . wppa_get_rating_by_id($image['id']) . '</div>';
                         }
                         if ($viewcount == 'yes') {
                             $n = $image['views'];
                             $widget_content .= '<div>' . sprintf(_n('%d view', '%d views', $n, 'wp-photo-album-plus'), $n) . '</div>';
                         }
                         break;
                     case 'views':
                         if ($viewcount == 'yes') {
                             $n = $image['views'];
                             $widget_content .= '<div>' . sprintf(_n('%d view', '%d views', $n, 'wp-photo-album-plus'), $n) . '</div>';
                         }
                         if ($meanrat == 'yes') {
                             $widget_content .= '<div>' . wppa_get_rating_by_id($image['id']) . '</div>';
                         }
                         if ($ratcount == 'yes') {
                             $n = wppa_get_rating_count_by_id($image['id']);
                             $widget_content .= '<div>' . ($likes ? $lt['display'] : sprintf(_n('%d vote', '%d votes', $n, 'wp-photo-album-plus'), $n)) . '</div>';
                         }
                         break;
                 }
                 $widget_content .= '</div>';
             } else {
                 // No image
                 $widget_content .= __('Photo not found', 'wp-photo-album-plus');
             }
             $widget_content .= "\n" . '</div>';
         }
     } else {
         $widget_content .= __('There are no rated photos (yet)', 'wp-photo-album-plus');
     }
     $widget_content .= '<div style="clear:both"></div>';
     $widget_content .= "\n" . '<!-- WPPA+ TopTen Widget end -->';
     echo "\n" . $before_widget;
     if (!empty($widget_title)) {
         echo $before_title . $widget_title . $after_title;
     }
     echo $widget_content . $after_widget;
     //wppa( 'in_widget', false );
     wppa_reset_occurrance();
 }
function _wppa_comment_admin()
{
    global $wpdb;
    $continue = true;
    // Check input
    wppa_vfy_arg('tab', true);
    wppa_vfy_arg('edit_id');
    wppa_vfy_arg('wppa-page');
    wppa_vfy_arg('commentid');
    wppa_vfy_arg('delete_id');
    if (isset($_GET['tab'])) {
        if ($_GET['tab'] == 'edit') {
            $id = $_GET['edit_id'];
            $comment = $wpdb->get_row($wpdb->prepare("SELECT * FROM " . WPPA_COMMENTS . " WHERE id = %s LIMIT 1", $id), ARRAY_A);
            if ($comment) {
                ?>
			<div class="wrap">
				<?php 
                $iconurl = WPPA_URL . '/img/comment.png';
                ?>
				<div id="icon-album" class="icon32" style="background: transparent url(<?php 
                echo $iconurl;
                ?>
) no-repeat">
					<br />
				</div>
				<h2><?php 
                _e('Photo Albums -> Edit Comment', 'wp-photo-album-plus');
                ?>
</h2>
				<?php 
                $action = wppa_dbg_url(get_admin_url() . 'admin.php?page=wppa_manage_comments');
                if (isset($_GET['wppa-page'])) {
                    $action .= '&compage=' . strval(intval($_GET['wppa-page']));
                }
                if (isset($_GET['commentid'])) {
                    $action .= '&commentid=' . strval(intval($_GET['commentid']));
                }
                ?>
				<form action="<?php 
                echo $action;
                ?>
" method="post">

					<?php 
                wp_nonce_field('$wppa_nonce', WPPA_NONCE);
                ?>
					<input type="hidden" name="edit_comment" value="<?php 
                echo $comment['id'];
                ?>
" />
					<table class="form-table albumtable">
						<tbody>
							<tr style="vertical-align:top" >
								<th>
									<?php 
                $photo = $wpdb->get_row($wpdb->prepare("SELECT * FROM " . WPPA_PHOTOS . " WHERE id =  %s", $comment['photo']), "ARRAY_A");
                ?>
									<?php 
                $url = wppa_fix_poster_ext(wppa_get_thumb_url($comment['photo']), $comment['photo']);
                ?>
									<img src="<?php 
                echo $url;
                ?>
" />
								</th>
								<td>
									<?php 
                echo __($photo['name']) . '<br/><br/>' . __(stripslashes($photo['description']));
                ?>
								</td>
							</tr>
							<tr>
								<th scope="row"><label ><?php 
                _e('Photo:', 'wp-photo-album-plus');
                ?>
</label></th>
								<td><?php 
                echo $comment['photo'];
                ?>
</td>
							</tr>
							<tr>
								<th scope="row"><label ><?php 
                _e('Album:', 'wp-photo-album-plus');
                ?>
</label></th>
								<td><?php 
                echo wppa_get_album_name($photo['album']);
                ?>
								</td>
							</tr>
							<tr>
								<th scope="row"><label ><?php 
                _e('User:'******'wp-photo-album-plus');
                ?>
</label></th>
								<td><input style="width:300px;" type="text" name="user" value="<?php 
                echo $comment['user'];
                ?>
" /></td>
							</tr>
							<tr>
								<th scope="row"><label ><?php 
                _e('Email:', 'wp-photo-album-plus');
                ?>
</label></th>
								<td><input style="width:300px;" type="text" name="email" value="<?php 
                echo $comment['email'];
                ?>
" /></td>
							</tr>
							<tr>
								<th scope="row"><label><?php 
                _e('Comment:', 'wp-photo-album-plus');
                ?>
</label></th>
								<td><textarea style="width:300px; height:150px;" name="comment"><?php 
                echo esc_textarea(stripslashes($comment['comment']));
                ?>
</textarea></td>
							</tr>
						</tbody>
					</table>
					<p>
						<input type="submit" class="button-primary" name="wppa_submit" value="<?php 
                _e('Save Changes', 'wp-photo-album-plus');
                ?>
" />
					</p>
				</form>
			<?php 
            }
            $continue = false;
        }
        if ($_GET['tab'] == 'delete') {
            $id = strval(intval($_GET['delete_id']));
            $photo = $wpdb->get_var($wpdb->prepare("SELECT `photo` FROM `" . WPPA_COMMENTS . "` WHERE `id` = %s", $id));
            $iret = $wpdb->query($wpdb->prepare("DELETE FROM `" . WPPA_COMMENTS . "` WHERE `id` = %s LIMIT 1", $id));
            if ($iret !== false) {
                if (wppa_switch('search_comments')) {
                    wppa_index_update('photo', $photo);
                }
                wppa_update_message(__('Comment deleted', 'wp-photo-album-plus'));
            } else {
                wppa_error_message('Error deleting comment');
            }
            $continue = true;
        }
    }
    if ($continue) {
        // Update anything or do bulkaction
        if (isset($_POST['wppa_submit'])) {
            // Security check
            check_admin_referer('$wppa_nonce', WPPA_NONCE);
            // Updates
            $iret = true;
            if (isset($_POST['wppa_comadmin_show'])) {
                wppa_update_option('wppa_comadmin_show', $_POST['wppa_comadmin_show']);
            }
            if (isset($_POST['wppa_comadmin_linkpage'])) {
                wppa_update_option('wppa_comadmin_linkpage', $_POST['wppa_comadmin_linkpage']);
            }
            if (isset($_POST['wppa_comadmin_order'])) {
                wppa_update_option('wppa_comadmin_order', $_POST['wppa_comadmin_order']);
            }
            if (isset($_POST['edit_comment'])) {
                $iret = wppa_edit_comment($_POST['edit_comment']);
            }
            // Bulk actions
            if (isset($_POST['bulkaction'])) {
                switch ($_POST['bulkaction']) {
                    case 'approveall':
                        $coms_to_proc = $wpdb->get_results("SELECT `id` FROM `" . WPPA_COMMENTS . "` WHERE status = 'pending'", ARRAY_A);
                        $query = "UPDATE " . WPPA_COMMENTS . " SET status = 'approved' WHERE status = 'pending'";
                        if ($wpdb->query($query) === false) {
                            wppa_error_message(__('Could not bulk update status', 'wp-photo-album-plus'));
                            $iret = false;
                        } else {
                            if ($coms_to_proc) {
                                foreach ($coms_to_proc as $item) {
                                    wppa_send_comment_approved_email($item['id']);
                                }
                            }
                            $iret = true;
                        }
                        break;
                    case 'spamall':
                        $query = "UPDATE " . WPPA_COMMENTS . " SET status = 'spam' WHERE status = 'pending'";
                        if ($wpdb->query($query) === false) {
                            wppa_error_message(__('Could not bulk update status', 'wp-photo-album-plus'));
                            $iret = false;
                        } else {
                            $iret = true;
                        }
                        break;
                    case 'delspam':
                        $query = "DELETE FROM " . WPPA_COMMENTS . " WHERE status = 'spam'";
                        if ($wpdb->query($query) === false) {
                            wppa_error_message(__('Could not bulk delete spam', 'wp-photo-album-plus'));
                            $iret = false;
                        }
                        break;
                }
            }
            if ($iret) {
                wppa_update_message(__('Changes Saved', 'wp-photo-album-plus'));
            }
            // Clear (super)cache
            wppa_clear_cache();
        }
        // Submit
        // Delete trash
        $query = "DELETE FROM " . WPPA_COMMENTS . " WHERE status = 'trash'";
        $wpdb->query($query);
        // Initialize normal display
        $wppa_comadmin_linkpage = get_option('wppa_comadmin_linkpage', '0');
        if ($wppa_comadmin_linkpage) {
            $exists = $wpdb->get_var("SELECT `post_title` FROM `" . $wpdb->posts . "` WHERE `ID` = " . $wppa_comadmin_linkpage);
            if (!$exists) {
                $wppa_comadmin_linkpage = '0';
                update_option('wppa_comadmin_linkpage', '0');
            }
        }
        $moderating = isset($_REQUEST['commentid']);
        ?>
		<div class="wrap">
			<?php 
        $iconurl = WPPA_URL . '/img/comment.png';
        ?>
			<div id="icon-album" class="icon32" style="background: transparent url(<?php 
        echo $iconurl;
        ?>
) no-repeat">
				<br />
			</div>
			<h2>
				<?php 
        if ($moderating) {
            _e('Photo Albums -> Moderate Comment', 'wp-photo-album-plus');
        } else {
            _e('Photo Albums -> Comment admin', 'wp-photo-album-plus');
        }
        ?>
			</h2>

			<?php 
        if (!wppa_switch('show_comments')) {
            _e('<h3>The Comment system is not activated</h3><p>To activate: check Table II item 18 on the <b>Photo Albums -> Settings</b> screen and press <b>Save Changes</b>', 'wp-photo-album-plus');
        }
        ?>

			<?php 
        if (!$moderating) {
            ?>
			<!-- Statistics -->
			<table>
				<tbody>
					<tr>
						<td><h3 style="margin:0; color:#777777;"><?php 
            _e('Total:', 'wp-photo-album-plus');
            ?>
</h3></td>
						<td><h3 style="margin:0;"><?php 
            $count = $wpdb->get_var("SELECT COUNT(*) FROM `" . WPPA_COMMENTS . "`");
            echo $count;
            ?>
</h3></td>
					</tr>
					<tr>
						<td><h3 style="margin:0; color:green;"><?php 
            _e('Approved:', 'wp-photo-album-plus');
            ?>
</h3></td>
						<td><h3 style="margin:0;"><?php 
            $count = $wpdb->get_var("SELECT COUNT(*) FROM `" . WPPA_COMMENTS . "` WHERE `status` = 'approved'");
            echo $count;
            ?>
</h3></td>
					</tr>
					<tr>
						<td><h3 style="margin:0; color:#e66f00;"><?php 
            _e('Pending:', 'wp-photo-album-plus');
            ?>
</h3></td>
						<td><h3 style="margin:0;"><?php 
            $count = $wpdb->get_var("SELECT COUNT(*) FROM `" . WPPA_COMMENTS . "` WHERE `status` = 'pending'");
            echo $count;
            ?>
</h3></td>
					</tr>
					<tr>
						<td><h3 style="margin:0; color:red;"><?php 
            _e('Spam:', 'wp-photo-album-plus');
            ?>
</h3></td>
						<td><h3 style="margin:0;"><?php 
            $count = $wpdb->get_var("SELECT COUNT(*) FROM `" . WPPA_COMMENTS . "` WHERE `status` = 'spam'");
            echo $count;
            ?>
</h3></td>
					</tr>
					<?php 
            if (wppa_opt('spam_maxage') != 'none') {
                ?>
					<tr>
						<td><h3 style="margin:0; color:red;"><?php 
                _e('Auto deleted spam:', 'wp-photo-album-plus');
                ?>
</h3></td>
						<td><h3 style="margin:0;"><?php 
                echo get_option('wppa_spam_auto_delcount', '0');
                ?>
</h3></td>
					</tr>
					<?php 
            }
            ?>
				</tbody>
			</table>
			<!-- end statistics -->

			<!-- Settings -->
			<div style="border:1px solid #ccc; padding:4px; margin:4px 0" >
				<h3><?php 
            _e('Settings', 'wp-photo-album-plus');
            ?>
</h3>
				<form action="<?php 
            echo wppa_dbg_url(get_admin_url() . 'admin.php?page=wppa_manage_comments');
            ?>
" method="post">
					<p>
						<?php 
            wp_nonce_field('$wppa_nonce', WPPA_NONCE);
            _e('Linkpage:', 'wp-photo-album-plus');
            ?>
						<select name="wppa_comadmin_linkpage">
							<option value="0" <?php 
            if ($wppa_comadmin_linkpage == '0') {
                echo 'selected="selected"';
            }
            ?>
 disabled="disabled" ><?php 
            _e('--- Please select a page ---', 'wp-photo-album-plus');
            ?>
</option>
							<?php 
            $query = "SELECT `ID`, `post_title`, `post_content` FROM `" . $wpdb->posts . "` WHERE `post_type` = 'page' AND `post_status` = 'publish' ORDER BY `post_title` ASC";
            $pages = $wpdb->get_results($query, ARRAY_A);
            if ($pages) {
                foreach ($pages as $page) {
                    if (stripos($page['post_content'], '%%wppa%%') !== false || stripos($page['post_content'], '[wppa') !== false) {
                        if ($wppa_comadmin_linkpage == $page['ID']) {
                            $sel = 'selected="selected"';
                        } else {
                            $sel = '';
                        }
                        echo '<option value="' . $page['ID'] . '" ' . $sel . '>' . __($page['post_title'], 'wp-photo-album-plus') . '</option>';
                    }
                }
            }
            ?>
						</select>
						<?php 
            _e('You can see the photo and all its comments on the selected page by clicking on the thumbnail image', 'wp-photo-album-plus');
            ?>
					</p>
					<?php 
            $comment_show = wppa_opt('comadmin_show');
            ?>
					<p>
						<?php 
            _e('Display status:', 'wp-photo-album-plus');
            ?>
						<select name="wppa_comadmin_show">
							<option value="all" <?php 
            if ($comment_show == 'all') {
                echo 'selected="selected"';
            }
            ?>
><?php 
            _e('all', 'wp-photo-album-plus');
            ?>
</option>
							<option value="pending" <?php 
            if ($comment_show == 'pending') {
                echo 'selected="selected"';
            }
            ?>
><?php 
            _e('pending', 'wp-photo-album-plus');
            ?>
</option>
							<option value="approved" <?php 
            if ($comment_show == 'approved') {
                echo 'selected="selected"';
            }
            ?>
><?php 
            _e('approved', 'wp-photo-album-plus');
            ?>
</option>
							<option value="spam" <?php 
            if ($comment_show == 'spam') {
                echo 'selected="selected"';
            }
            ?>
><?php 
            _e('spam', 'wp-photo-album-plus');
            ?>
</option>
						</select>
						<?php 
            $comment_order = wppa_opt('comadmin_order');
            ?>
						<?php 
            _e('Display order:', 'wp-photo-album-plus');
            ?>
						<select name="wppa_comadmin_order">
							<option value="timestamp" <?php 
            if ($comment_order == 'timestamp') {
                echo 'selected="selected"';
            }
            ?>
><?php 
            _e('timestamp', 'wp-photo-album-plus');
            ?>
</option>
							<option value="photo" <?php 
            if ($comment_order == 'photo') {
                echo 'selected="selected"';
            }
            ?>
><?php 
            _e('photo', 'wp-photo-album-plus');
            ?>
</option>
						</select>
						<?php 
            _e('Bulk action:', 'wp-photo-album-plus');
            ?>
						<select name="bulkaction">
							<option value=""><?php 
            ?>
</option>
							<option value="approveall"><?php 
            _e('Approve all pending', 'wp-photo-album-plus');
            ?>
</option>
							<option value="spamall"><?php 
            _e('Move all pending to spam', 'wp-photo-album-plus');
            ?>
</option>
							<option value="delspam"><?php 
            _e('Delete all spam', 'wp-photo-album-plus');
            ?>
</option>
						</select>
						<input type="submit" class="button-primary" name="wppa_submit" value="<?php 
            _e('Save Settings / Perform bulk action', 'wp-photo-album-plus');
            ?>
" />
					</p>
				</form>
			</div>
			<!-- End Settings -->

			<?php 
        }
        if ($moderating) {
            $pagesize = '1';
            $where = " WHERE `id` = '" . $_REQUEST['commentid'] . "'";
            $order = '';
            $curpage = '1';
            $limit = '';
        } else {
            $pagsize = wppa_opt('comment_admin_pagesize');
            $where = $comment_show == 'all' ? '' : " WHERE `status` = '" . $comment_show . "'";
            $order = " ORDER BY `" . $comment_order . "`";
            if ($comment_order == 'timestamp') {
                $order .= " DESC";
            }
            if (isset($_GET['wppa-page'])) {
                $curpage = strval(intval($_GET['wppa-page']));
                $offset = (strval(intval($_GET['wppa-page'])) - 1) * $pagsize;
                $limit = " LIMIT " . $offset . "," . $pagsize;
            } else {
                $limit = ' LIMIT 0,' . $pagsize;
                $curpage = '1';
            }
            if ($pagsize == '0') {
                $limit = '';
            }
            // Paginating is off
            $nitems = $wpdb->get_var("SELECT COUNT(*) FROM " . WPPA_COMMENTS . $where);
            $link = wppa_dbg_url(get_admin_url() . 'admin.php?page=wppa_manage_comments');
            wppa_admin_page_links($curpage, $pagsize, $nitems, $link);
        }
        ?>
			<table class="widefat">
				<thead style="font-weight: bold" class="">
					<tr>
						<th scope="col"><?php 
        _e('Photo', 'wp-photo-album-plus');
        ?>
<br />
										<?php 
        _e('(Album)', 'wp-photo-album-plus');
        ?>
</th>
						<th scope="col"><?php 
        _e('#', 'wp-photo-album-plus');
        ?>
</th>
						<th scope="col"><?php 
        _e('IP', 'wp-photo-album-plus');
        ?>
</th>
						<th scope="col"><?php 
        _e('User', 'wp-photo-album-plus');
        ?>
</th>
						<th scope="col"><?php 
        _e('Email', 'wp-photo-album-plus');
        ?>
</th>
						<th scope="col"><?php 
        _e('Time since', 'wp-photo-album-plus');
        ?>
</th>
						<th scope="col"><?php 
        _e('Comment', 'wp-photo-album-plus');
        ?>
</th>
						<th scope="col" style="width: 130px;" ><?php 
        _e('Status', 'wp-photo-album-plus');
        ?>
</th>
						<th scope="col"><?php 
        _e('Edit', 'wp-photo-album-plus');
        ?>
</th>
						<th scope="col"><?php 
        _e('Delete', 'wp-photo-album-plus');
        ?>
</th>
					</tr>
				</thead>
				<tbody class="wppa_table_1">
					<?php 
        $comments = $wpdb->get_results("SELECT * FROM `" . WPPA_COMMENTS . "`" . $where . $order . $limit, ARRAY_A);
        if ($comments) {
            foreach ($comments as $com) {
                ?>
							<tr>
								<?php 
                $photo = $wpdb->get_row($wpdb->prepare("SELECT * FROM " . WPPA_PHOTOS . " WHERE id = %s", $com['photo']), 'ARRAY_A');
                if ($photo) {
                    $alb = $photo['album'];
                    $pname = __($photo['name'], 'wp-photo-album-plus');
                    $albname = '(' . wppa_get_album_name($alb) . ')';
                } else {
                    $alb = '';
                    $pname = '';
                    $albname = '';
                }
                if ($wppa_comadmin_linkpage == '0') {
                    ?>
									<td style="text-align:center">
										<img src="<?php 
                    echo wppa_fix_poster_ext(wppa_get_thumb_url($com['photo']), $com['photo']);
                    ?>
" style="max-height:64px;max-width:64px;" />
										<br />
										<?php 
                    echo $albname;
                    ?>
									</td><?php 
                } else {
                    $url = get_page_link($wppa_comadmin_linkpage);
                    if (strpos($url, '?')) {
                        $url .= '&';
                    } else {
                        $url .= '?';
                    }
                    $url .= 'wppa-album=' . $alb . '&wppa-photo=' . $com['photo'] . '&wppa-occur=1';
                    ?>
									<td style="text-align:center">
										<a href="<?php 
                    echo $url;
                    ?>
" target="_blank">
											<img title="<?php 
                    _e('Click to see the fullsize photo and all comments', 'wp-photo-album-plus');
                    ?>
" src="<?php 
                    echo wppa_fix_poster_ext(wppa_get_thumb_url($com['photo']), $com['photo']);
                    ?>
" style="max-height:64px;max-width:64px;" />
										</a>
										<br />
										<?php 
                    echo $albname;
                    ?>
									</td><?php 
                }
                ?>
								<td><?php 
                echo $com['photo'];
                ?>
</td>
								<td><?php 
                echo $com['ip'];
                ?>
</td>
								<td><?php 
                echo $com['user'];
                ?>
</td>
								<td><?php 
                if ($com['email']) {
                    $subject = str_replace(' ', '%20', sprintf(__('Reply to your comment on photo: %s on %s', 'wp-photo-album-plus'), $pname, get_bloginfo('name')));
                    echo '<a href="mailto:' . $com['email'] . '?Subject=' . $subject . '" title="' . __('Reply', 'wp-photo-album-plus') . '" >' . $com['email'] . '</a>';
                } else {
                    echo $com['email'];
                }
                ?>
								</td>
								<td><?php 
                echo wppa_get_time_since($com['timestamp']);
                ?>
</td>
								<td><?php 
                echo stripslashes($com['comment']);
                ?>
</td>
								<td>
									<input type="hidden" id="photo-nonce-<?php 
                echo $com['photo'];
                ?>
" value="<?php 
                echo wp_create_nonce('wppa_nonce_' . $com['photo']);
                ?>
" />
									<select name="status['<?php 
                echo $com['id'];
                ?>
']" onchange="jQuery('#wppa-comment-spin-<?php 
                echo $com['id'];
                ?>
').css('visibility', 'visible'); wppaAjaxUpdateCommentStatus(<?php 
                echo $com['photo'];
                ?>
, <?php 
                echo $com['id'];
                ?>
, this.value)">
										<option value="pending" 	<?php 
                if ($com['status'] == 'pending') {
                    echo 'selected="selected"';
                }
                ?>
><?php 
                _e('Pending', 'wp-photo-album-plus');
                ?>
</option>
										<option value="approved" 	<?php 
                if ($com['status'] == 'approved') {
                    echo 'selected="selected"';
                }
                ?>
><?php 
                _e('Approved', 'wp-photo-album-plus');
                ?>
</option>
										<option value="spam" 		<?php 
                if ($com['status'] == 'spam') {
                    echo 'selected="selected"';
                }
                ?>
><?php 
                _e('Spam', 'wp-photo-album-plus');
                ?>
</option>
									</select>
									<img id="wppa-comment-spin-<?php 
                echo $com['id'];
                ?>
" src="<?php 
                echo wppa_get_imgdir() . 'spinner.gif';
                ?>
" style="visibility:hidden" />
								</td>
								<?php 
                $url = wppa_dbg_url(get_admin_url() . 'admin.php?page=wppa_manage_comments&tab=edit&edit_id=' . $com['id']);
                if (isset($_GET['wppa-page'])) {
                    $url .= '&compage=' . strval(intval($_GET['wppa-page']));
                }
                if (isset($_GET['commentid'])) {
                    $url .= '&commentid=' . strval(intval($_GET['commentid']));
                }
                ?>
								<?php 
                $delurl = wppa_dbg_url(get_admin_url() . 'admin.php?page=wppa_manage_comments&tab=delete&delete_id=' . $com['id']);
                ?>
								<td style="color:green; cursor:pointer;" onclick="document.location='<?php 
                echo $url;
                ?>
'"><b><?php 
                _e('Edit', 'wp-photo-album-plus');
                ?>
</b></td>
								<td style="color:red; cursor:pointer;" onclick="if (confirm('<?php 
                _e('Are you sure you want to delete this comment?', 'wp-photo-album-plus');
                ?>
')) document.location = '<?php 
                echo $delurl;
                ?>
';"><b><?php 
                _e('Delete', 'wp-photo-album-plus');
                ?>
</b></td>
							</tr>
						<?php 
            }
        }
        ?>
				</tbody>
				<tfoot style="font-weight: bold" class="">
					<tr>
						<th scope="col"><?php 
        _e('Photo', 'wp-photo-album-plus');
        ?>
<br />
										<?php 
        _e('(Album)', 'wp-photo-album-plus');
        ?>
</th>
						<th scope="col"><?php 
        _e('#', 'wp-photo-album-plus');
        ?>
</th>
						<th scope="col"><?php 
        _e('IP', 'wp-photo-album-plus');
        ?>
</th>
						<th scope="col"><?php 
        _e('User', 'wp-photo-album-plus');
        ?>
</th>
						<th scope="col"><?php 
        _e('Email', 'wp-photo-album-plus');
        ?>
</th>
						<th scope="col"><?php 
        _e('Time since', 'wp-photo-album-plus');
        ?>
</th>
						<th scope="col"><?php 
        _e('Comment', 'wp-photo-album-plus');
        ?>
</th>
						<th scope="col"><?php 
        _e('Status', 'wp-photo-album-plus');
        ?>
</th>
						<th scope="col"><?php 
        _e('Edit', 'wp-photo-album-plus');
        ?>
</th>
						<th scope="col"><?php 
        _e('Delete', 'wp-photo-album-plus');
        ?>
</th>
					</tr>
				</tfoot>
			</table>
			<?php 
        if (!$moderating) {
            wppa_admin_page_links($curpage, $pagsize, $nitems, $link);
        }
        ?>
		</form>
	</div>
	<?php 
    }
}
function wppa_get_tnres_url($id)
{
    $tnres_url = wppa_fix_poster_ext(wppa_get_thumb_url($id), $id);
    $temp = explode('?', $tnres_url);
    $tnres_url = $temp['0'];
    return $tnres_url;
}
function wppa_do_maintenance_popup($slug)
{
    global $wpdb;
    global $thumb;
    $result = '';
    switch ($slug) {
        case 'wppa_list_index':
            $start = get_option('wppa_list_index_display_start', '');
            $total = $wpdb->get_var("SELECT COUNT(*) FROM `" . WPPA_INDEX . "`");
            $indexes = $wpdb->get_results($wpdb->prepare("SELECT * FROM `" . WPPA_INDEX . "` WHERE `slug` >= %s ORDER BY `slug` LIMIT 1000", $start), ARRAY_A);
            $result .= '
			<style>td, th { border-right: 1px solid darkgray; } </style>
			<h2>List of Searcheable words <small>( Max 1000 entries of total ' . $total . ' )</small></h2>
			<div style="float:left; clear:both; width:100%; overflow:auto; background-color:#f1f1f1; border:1px solid #ddd;" >';
            if ($indexes) {
                $result .= '
				<table>
					<thead>
						<tr>
							<th><span style="float:left;" >Word</span></th>
							<th style="max-width:400px;" ><span style="float:left;" >Albums</span></th>
							<th><span style="float:left;" >Photos</span></th>
						</tr>
						<tr><td colspan="3"><hr /></td></tr>
					</thead>
					<tbody>';
                foreach ($indexes as $index) {
                    $result .= '
						<tr>
							<td>' . $index['slug'] . '</td>
							<td style="max-width:400px; word-wrap: break-word;" >' . $index['albums'] . '</td>
							<td>' . $index['photos'] . '</td>
						</tr>';
                }
                $result .= '
					</tbody>
				</table>';
            } else {
                $result .= __('There are no index items.', 'wppa');
            }
            $result .= '
				</div><div style="clear:both;"></div>';
            break;
        case 'wppa_list_errorlog':
            $filename = WPPA_CONTENT_PATH . '/wppa-depot/admin/error.log';
            $result .= '
				<h2>List of WPPA+ error messages <small>( Newest first )</small></h2>
				<div style="float:left; clear:both; width:100%; overflow:auto; word-wrap:none; background-color:#f1f1f1; border:1px solid #ddd;" >';
            if (!($file = @fopen($filename, 'r'))) {
                $result .= __('There are no error log messages', 'wppa');
            } else {
                $size = filesize($filename);
                $data = fread($file, $size);
                $messages = explode("\n", $data);
                $count = count($messages);
                $idx = $count - '2';
                while ($idx >= '0') {
                    $msg = $messages[$idx];
                    $msg = htmlspecialchars(strip_tags($msg));
                    // Security fix
                    $result .= $msg . '<br />';
                    $idx--;
                }
            }
            $result .= '
				</div><div style="clear:both;"></div>
				';
            break;
        case 'wppa_list_rating':
            $total = $wpdb->get_var("SELECT COUNT(*) FROM `" . WPPA_RATING . "`");
            $ratings = $wpdb->get_results("SELECT * FROM `" . WPPA_RATING . "` ORDER BY `timestamp` DESC LIMIT 1000", ARRAY_A);
            $result .= '
			<style>td, th { border-right: 1px solid darkgray; } </style>
			<h2>List of recent ratings <small>( Max 1000 entries of total ' . $total . ' )</small></h2>
			<div style="float:left; clear:both; width:100%; overflow:auto; background-color:#f1f1f1; border:1px solid #ddd;" >';
            if ($ratings) {
                $result .= '
				<table>
					<thead>
						<tr>
							<th>Id</th>
							<th>Timestamp</th>
							<th>Date/time</th>
							<th>Status</th>
							<th>User</th>
							<th>Value</th>
							<th>Photo id</th>
							<th></th>
							<th># ratings</th>
							<th>Average</th>
						</tr>
						<tr><td colspan="10"><hr /></td></tr>
					</thead>
					<tbody>';
                foreach ($ratings as $rating) {
                    wppa_cache_thumb($rating['photo']);
                    $result .= '
						<tr>
							<td>' . $rating['id'] . '</td>
							<td>' . $rating['timestamp'] . '</td>
							<td>' . ($rating['timestamp'] ? wppa_local_date(get_option('date_format', "F j, Y,") . ' ' . get_option('time_format', "g:i a"), $rating['timestamp']) : 'pre-historic') . '</td>
							<td>' . $rating['status'] . '</td>
							<td>' . $rating['user'] . '</td>
							<td>' . $rating['value'] . '</td>
							<td>' . $rating['photo'] . '</td>
							<td style="width:250px; text-align:center;"><img src="' . wppa_get_thumb_url($rating['photo']) . '" 
								style="height: 40px;" 
								onmouseover="jQuery(this).stop().animate({height:this.naturalHeight}, 200);"
								onmouseout="jQuery(this).stop().animate({height:\'40px\'}, 200);" /></td>
							<td>' . $thumb['rating_count'] . '</td>
							<td>' . $thumb['mean_rating'] . '</td>
						</tr>';
                }
                $result .= '
					</tbody>
				</table>';
            } else {
                $result .= __('There are no ratings', 'wppa');
            }
            $result .= '
				</div><div style="clear:both;"></div>';
            break;
        case 'wppa_list_session':
            $total = $wpdb->get_var("SELECT COUNT(*) FROM `" . WPPA_SESSION . "` WHERE `status` = 'valid'");
            $sessions = $wpdb->get_results("SELECT * FROM `" . WPPA_SESSION . "` WHERE `status` = 'valid' ORDER BY `id` DESC LIMIT 1000", ARRAY_A);
            $result .= '
			<style>td, th { border-right: 1px solid darkgray; } </style>
			<h2>List of active sessions <small>( Max 1000 entries of total ' . $total . ' )</small></h2>
			<div style="float:left; clear:both; width:100%; overflow:auto; background-color:#f1f1f1; border:1px solid #ddd;" >';
            if ($sessions) {
                $result .= '
				<table>
					<thead>
						<tr>
							<th>Id</th>
							<th>Session id</th>
							<th>User</th>
							<th>Rs</th>
							<th>Started</th>
							<th>Count</th>
							<th>Page</th>
							<th>Ajax</th>
							<th>Albums viewed</th>
							<th>Photos viewed</th>
							<th>Search string</th>
							<th>root</th>
							<th>sub</th>
							<th>Superview</th>
						</tr>
						<tr><td colspan="14"><hr /></td></tr>
					</thead>
					<tbody>';
                foreach ($sessions as $session) {
                    $data = unserialize($session['data']);
                    $result .= '
							<tr>
								<td>' . $session['id'] . '</td>
								<td>' . $session['session'] . '</td>
								<td>' . $session['user'] . '</td>
								<td>' . $data['randseed'] . '</td>
								<td style="text-wrap:none;" >' . wppa_local_date(get_option('date_format', "F j, Y,") . ' ' . get_option('time_format', "g:i a"), $session['timestamp']) . '</td>
								<td>' . $session['count'] . '</td>
								<td>' . (isset($data['page']) ? $data['page'] : '') . '</td>
								<td>' . (isset($data['ajax']) ? $data['ajax'] : '') . '</td>
								<td>' . (isset($data['album']) ? wppa_index_array_to_string(array_keys($data['album'])) : '') . '</td>
								<td>' . (isset($data['photo']) ? wppa_index_array_to_string(array_keys($data['photo'])) : '') . '</td>
								<td>' . (isset($data['use_searchstring']) ? $data['use_searchstring'] : '') . '</td>
								<td style="text-wrap:unrestricted; max-width:300px;" >' . (isset($data['search_root']) ? $data['search_root'] . ' ' : '') . (isset($data['rootbox']) ? $data['rootbox'] ? 'on' : 'off' : '') . '</td>
								<td>' . (isset($data['subbox']) ? $data['subbox'] ? 'Y' : 'N' : '') . '</td>
								<td>' . (isset($data['superalbum']) ? $data['superalbum'] . ' ' : '') . (isset($data['superview']) ? $data['superview'] : '') . '</td>
							</tr>';
                }
                $result .= '
					</tbody>
				</table>';
            } else {
                $result .= __('There are no active sessions', 'wppa');
            }
            $result .= '
				</div><div style="clear:both;"></div>';
            break;
        default:
            $result = 'Error: Unimplemented slug: ' . $slug . ' in wppa_do_maintenance_popup()';
    }
    return $result;
}
function wppa_get_slide_info($index, $id, $callbackid = '')
{
    global $wpdb;
    static $user;
    // Make sure $thumb contains our image data
    $thumb = wppa_cache_thumb($id);
    if (!$user) {
        $user = wppa_get_user();
    }
    $photo = wppa_get_get('photo');
    $ratingphoto = wppa_get_get('rating-id');
    if (!$callbackid) {
        $callbackid = $id;
    }
    // Process a comment if given for this photo
    $comment_request = wppa_get_post('commentbtn') && $id == $photo;
    $comment_allowed = !wppa_switch('comment_login') || is_user_logged_in();
    if (wppa_switch('show_comments') && $comment_request && $comment_allowed) {
        wppa_do_comment($id);
    }
    // Find rating
    if (wppa_switch('rating_on') && !wppa('is_slideonly') && !wppa('is_filmonly')) {
        // Find my ( avg ) rating
        if (wppa_opt('rating_display_type') == 'likes') {
            $lt = wppa_get_like_title_a($id);
            $myrat = $lt['mine'];
            $my_youngest_rating_dtm = 0;
        } else {
            $rats = $wpdb->get_results($wpdb->prepare("SELECT `value`, `timestamp` FROM `" . WPPA_RATING . "` " . "WHERE `photo` = %s AND `user` = %s AND `status` = 'publish'", $id, $user), ARRAY_A);
            if ($rats) {
                $n = 0;
                $accu = 0;
                foreach ($rats as $rat) {
                    $accu += $rat['value'];
                    $n++;
                    $my_youngest_rating_dtm = $rat['timestamp'];
                }
                $myrat = $accu / $n;
                $i = wppa_opt('rating_prec');
                $j = $i + '1';
                $myrat = sprintf('%' . $j . '.' . $i . 'f', $myrat);
            } else {
                $myrat = '0';
                $my_youngest_rating_dtm = 0;
            }
        }
        // Find the avg rating
        if (wppa_opt('rating_display_type') == 'likes') {
            $avgrat = esc_js($lt['title'] . '|' . $lt['display']);
        } else {
            $avgrat = wppa_get_rating_by_id($id, 'nolabel');
            if (!$avgrat) {
                $avgrat = '0';
            }
            $avgrat .= '|' . wppa_get_rating_count_by_id($id);
        }
        // Find the dislike count
        $discount = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM `" . WPPA_RATING . "` WHERE `photo` = %s AND `value` = -1 AND `status` = %s", $id, 'publish'));
        // Make the discount textual
        $distext = wppa_get_distext($discount, $myrat);
        // Test if rating is one per period and period not expired yet
        $wait_text = esc_js(wppa_get_rating_wait_text($id, $user));
    } else {
        // Rating off
        $myrat = '0';
        $avgrat = '0';
        $discount = '0';
        $distext = '';
        $wait_text = '';
    }
    // Find comments
    $comment = wppa_switch('show_comments') && !wppa('is_filmonly') && !wppa('is_slideonly') ? wppa_comment_html($id, $comment_allowed) : '';
    // Get the callback url.
    if (wppa_switch('rating_on')) {
        $url = wppa_get_slide_callback_url($callbackid);
        $url = str_replace('&amp;', '&', $url);
        // js use
    } else {
        $url = '';
    }
    // Find link url, link title and link target
    if (wppa_in_widget() == 'ss') {
        $link = wppa_get_imglnk_a('sswidget', $id);
    } else {
        $link = wppa_get_imglnk_a('slideshow', $id);
    }
    $linkurl = $link['url'];
    $linktitle = $link['title'];
    $linktarget = $link['target'];
    // Find full image style and size
    if (wppa('is_filmonly')) {
        $style_a['style'] = '';
        $style_a['width'] = '';
        $style_a['height'] = '';
    } else {
        $style_a = wppa_get_fullimgstyle_a($id);
    }
    // Find image url
    if (wppa_switch('fotomoto_on') && !wppa_is_stereo($id)) {
        $photourl = wppa_get_hires_url($id);
    } elseif (wppa_use_thumb_file($id, $style_a['width'], $style_a['height']) && !wppa_is_stereo($id)) {
        $photourl = wppa_get_thumb_url($id, '', $style_a['width'], $style_a['height']);
    } else {
        $photourl = wppa_get_photo_url($id, '', $style_a['width'], $style_a['height']);
    }
    if (wppa_has_audio($id)) {
        $photourl = wppa_fix_poster_ext($photourl, $id);
    }
    // Find iptc data
    $iptc = wppa_switch('show_iptc') && !wppa('is_slideonly') && !wppa('is_filmonly') ? wppa_iptc_html($id) : '';
    // Find EXIF data
    $exif = wppa_switch('show_exif') && !wppa('is_slideonly') && !wppa('is_filmonly') ? wppa_exif_html($id) : '';
    // Lightbox subtitle
    $doit = false;
    if (wppa_opt('slideshow_linktype') == 'lightbox' || wppa_opt('slideshow_linktype') == 'lightboxsingle') {
        $doit = true;
    }
    // For fullsize
    if (wppa_switch('filmstrip') && wppa_opt('film_linktype') == 'lightbox') {
        // For filmstrip?
        if (!wppa('is_slideonly')) {
            $doit = true;
        }
        // Film below fullsize
        if (wppa('film_on')) {
            $doit = true;
        }
        // Film explicitly on ( slideonlyf )
    }
    if ($doit) {
        $lbtitle = wppa_get_lbtitle('slide', $id);
    } else {
        $lbtitle = '';
    }
    // Name
    $name = '';
    $fullname = '';
    if ((!wppa('is_slideonly') || wppa('name_on')) && !wppa('is_filmonly')) {
        $name = esc_js(wppa_get_photo_name($id));
        if (!$name) {
            $name = '&nbsp;';
        }
        $fullname = wppa_get_photo_name($id, wppa_switch('show_full_owner'), true, true, wppa_switch('show_full_name'));
        if (!$fullname) {
            $fullname = '&nbsp;';
        }
    }
    // Shareurl
    if (wppa('is_filmonly') || wppa('is_slideonly')) {
        $shareurl = '';
    } else {
        $shareurl = wppa_get_image_page_url_by_id($id, false, wppa('start_album'));
        $shareurl = wppa_convert_to_pretty($shareurl);
        $shareurl = str_replace('&amp;', '&', $shareurl);
    }
    // Make photo desc, filtered
    $desc = '';
    if ((!wppa('is_slideonly') || wppa('desc_on')) && !wppa('is_filmonly')) {
        $desc .= wppa_get_photo_desc($id, wppa_switch('allow_foreign_shortcodes'), 'do_geo');
        // Foreign shortcodes is handled here
        // Run wpautop on description?
        if (wppa_opt('wpautop_on_desc') == 'wpautop') {
            $desc = wpautop($desc);
        } elseif (wppa_opt('wpautop_on_desc') == 'nl2br') {
            $desc = nl2br($desc);
        }
        // And format
        $desc = wppa_html(esc_js(stripslashes($desc)));
        // Remove extra space created by other filters like wpautop
        if (wppa_switch('allow_foreign_shortcodes') && wppa_switch('clean_pbr')) {
            $desc = str_replace(array("<p>", "</p>", "<br>", "<br/>", "<br />"), " ", $desc);
        }
        if (!$desc) {
            $desc = '&nbsp;';
        }
    }
    // Edit photo link
    $editlink = '';
    $dellink = '';
    $choicelink = '';
    if (!wppa('is_filmonly') && !wppa('is_slideonly')) {
        if (wppa_may_user_fe_edit($id)) {
            $editlink = '
				<input' . ' type="button"' . ' style="float:right; margin-right:6px;"' . ' onclick="_wppaStop( ' . wppa('mocc') . ' );wppaEditPhoto( ' . wppa('mocc') . ', ' . esc_js('\'' . wppa_encrypt_photo($thumb['id']) . '\'') . ' );"' . ' value="' . esc_attr(__(wppa_opt('fe_edit_button'))) . '"' . ' /><span></span>';
        }
        if (wppa_may_user_fe_delete($id)) {
            $dellink = '
				<input' . ' type="button"' . ' style="float:right; margin-right:6px;"' . ' onclick="' . '_wppaStop( ' . wppa('mocc') . ' );' . esc_attr('if ( confirm( "' . __('Are you sure you want to remove this photo?', 'wp-photo-album-plus') . '" ) ) ' . 'wppaAjaxRemovePhoto( ' . wppa('mocc') . ', ' . esc_js('\'' . wppa_encrypt_photo($thumb['id']) . '\'') . ', true );') . '"' . ' value="' . __('Delete', 'wp-photo-album-plus') . '"' . ' />';
        }
        if (wppa_user_is('administrator') && wppa_switch('enable_admins_choice')) {
            $choicelink = '
				<div' . ' id="admin-choice-' . wppa_encrypt_photo($thumb['id']) . '-' . wppa('mocc') . '"' . ' style="float:right;margin-right:6px;color:gray;"' . ' >';
            if (!wppa_is_photo_in_zip($thumb['id'])) {
                $choicelink .= '<a' . ' style="color:blue;"' . ' onclick="' . '_wppaStop( ' . wppa('mocc') . ' );' . esc_attr('if ( confirm( "' . __('Are you sure you want to add this photo to your zip?', 'wp-photo-album-plus') . '" ) ) ' . 'wppaAjaxAddPhotoToZip( ' . wppa('mocc') . ', ' . esc_js('\'' . wppa_encrypt_photo($thumb['id']) . '\'') . ', true ); return false;') . '"' . '>' . __('MyChoice', 'wp-photo-album-plus') . '</a>';
            } else {
                $choicelink .= __('Selected', 'wp-photo-album-plus');
            }
            $choicelink .= '</div>';
        }
    }
    if ($editlink || $dellink || $choicelink) {
        $desc = $editlink . $dellink . $choicelink . '<div style="clear:both"></div>' . $desc;
    }
    if (in_array($thumb['status'], array('pending', 'scheduled'))) {
        $desc .= wppa_html(esc_js(wppa_moderate_links('slide', $id)));
    }
    // Share HTML
    $sharehtml = wppa('is_filmonly') || wppa('is_slideonly') ? '' : wppa_get_share_html($id);
    // Og Description
    $ogdsc = '';
    if (wppa_switch('facebook_comments') && !wppa_in_widget() && !wppa('is_filmonly') && !wppa('is_slideonly')) {
        $ogdsc = strip_shortcodes(wppa_strip_tags(wppa_html(wppa_get_photo_desc($id)), 'all'));
        $ogdsc = esc_js($ogdsc);
    }
    // Hires url. Use photo url in case of stereo image. The (source) hires is the double image.
    $hiresurl = wppa_is_stereo($id) ? esc_js(wppa_fix_poster_ext(wppa_get_photo_url($id), $id)) : esc_js(wppa_fix_poster_ext(wppa_get_hires_url($id), $id));
    // Video html
    $videohtml = wppa_get_video_body($id);
    // Audio html
    $audiohtml = wppa_get_audio_body($id);
    // Image alt
    $image_alt = esc_js(wppa_get_imgalt($id, true));
    // Poster url if video
    $poster_url = '';
    if (wppa_is_video($id)) {
        if (is_file(wppa_fix_poster_ext(wppa_get_photo_path($id), $id))) {
            $poster_url = wppa_fix_poster_ext(wppa_get_photo_url($id), $id);
        }
    }
    // Produce final result
    $result = "'" . wppa('mocc') . "','";
    $result .= $index . "','";
    $result .= $photourl . "','";
    $result .= $style_a['style'] . "','";
    $result .= ($videohtml ? wppa_get_videox($id) : $style_a['width']) . "','";
    $result .= ($videohtml ? wppa_get_videoy($id) : $style_a['height']) . "','";
    $result .= $fullname . "','";
    $result .= $name . "','";
    $result .= $desc . "','";
    $result .= wppa_encrypt_photo($id) . "','";
    //wppa_dbg_msg('id='.$id, 'red');
    $result .= $avgrat . "','";
    $result .= $distext . "','";
    $result .= $myrat . "','";
    $result .= $url . "','";
    //wppa_dbg_msg('url='.$url, 'red');
    $result .= $linkurl . "','" . $linktitle . "','" . $linktarget . "','";
    //wppa_dbg_msg('linkurl='.$linkurl, 'red');
    $result .= wppa('in_widget_timeout') . "','";
    $result .= $comment . "','";
    $result .= $iptc . "','";
    $result .= $exif . "','";
    $result .= $lbtitle . "','";
    $result .= $shareurl . "','";
    // Used for history.pushstate()
    //wppa_dbg_msg('shareurl='.$shareurl, 'red');
    $result .= $sharehtml . "','";
    // The content of the SM ( share ) box
    $result .= $ogdsc . "','";
    $result .= $hiresurl . "','";
    $result .= $videohtml . "','";
    $result .= $audiohtml . "','";
    $result .= $wait_text . "','";
    $result .= $image_alt . "','";
    $result .= $poster_url . "'";
    // This is an ingenious line of code that is going to prevent us from very much trouble.
    // Created by OpaJaap on Jan 15 2012, 14:36 local time. Thanx.
    // Make sure there are no linebreaks in the result that would screw up Javascript.
    return str_replace(array("\r\n", "\n", "\r"), " ", $result);
    //	return $result;
}
function _wppa_sidebar_page_options()
{
    global $wpdb;
    $options_error = false;
    if (isset($_GET['walbum'])) {
        $walbum = wppa_walbum_sanitize($_GET['walbum']);
        wppa_update_option('wppa_widget_album', $walbum);
    }
    if (isset($_REQUEST['wppa-set-submit'])) {
        if (!wp_verify_nonce($_REQUEST['wppa-update-check'], 'wppa-update-check')) {
            echo 'Trying:' . $_REQUEST['wppa-update-check'];
        }
        if (isset($_POST['wppa-widgettitle'])) {
            wppa_update_option('wppa_widgettitle', $_POST['wppa-widgettitle']);
        }
        if (isset($_POST['wppa-potd-align'])) {
            wppa_update_option('wppa_potd_align', $_POST['wppa-potd-align']);
        }
        if (isset($_POST['wppa-widget-albums'])) {
            wppa_update_option('wppa_widget_album', wppa_walbum_sanitize($_POST['wppa-widget-albums']));
        }
        if (isset($_POST['wppa-widget-photo'])) {
            wppa_update_option('wppa_widget_photo', $_POST['wppa-widget-photo']);
        }
        if (isset($_POST['wppa-widget-method'])) {
            wppa_update_option('wppa_widget_method', $_POST['wppa-widget-method']);
        }
        if (isset($_REQUEST['wppa-widget-period'])) {
            wppa_update_option('wppa_widget_period', $_REQUEST['wppa-widget-period']);
        }
        if (isset($_POST['wppa-widget-subtitle'])) {
            wppa_update_option('wppa_widget_subtitle', $_POST['wppa-widget-subtitle']);
        }
        if (isset($_POST['wppa-widget-linkpage'])) {
            wppa_update_option('wppa_widget_linkpage', $_POST['wppa-widget-linkpage']);
        }
        if (isset($_POST['wppa-widget-linkurl'])) {
            wppa_update_option('wppa_widget_linkurl', $_POST['wppa-widget-linkurl']);
        }
        if (isset($_POST['wppa-widget-linktitle'])) {
            wppa_update_option('wppa_widget_linktitle', $_POST['wppa-widget-linktitle']);
        }
        if (isset($_POST['wppa-widget-linktype'])) {
            wppa_update_option('wppa_widget_linktype', $_POST['wppa-widget-linktype']);
        }
        if (isset($_POST['wppa-widget-status-filter'])) {
            wppa_update_option('wppa_widget_status_filter', $_POST['wppa-widget-status-filter']);
        }
        if (isset($_POST['wppa-potd-offset'])) {
            wppa_update_option('wppa_potd_offset', $_POST['wppa-potd-offset']);
        }
        if (isset($_POST['wppa-potd-widget-width'])) {
            if (wppa_check_numeric($_POST['wppa-potd-widget-width'], '100', __('Widget Photo Width.', 'wp-photo-album-plus'))) {
                wppa_update_option('wppa_potd_widget_width', $_POST['wppa-potd-widget-width']);
            } else {
                $options_error = true;
            }
        }
        if (!$options_error && isset($_POST['wppa-set-submit'])) {
            wppa_update_message(__('Changes Saved. Don\'t forget to activate the widget!', 'wp-photo-album-plus'));
        }
    }
    wppa_initialize_runtime('force');
    ?>
	
	<div class="wrap">
		<?php 
    $iconurl = WPPA_URL . '/images/settings32.png';
    ?>
		<div id="icon-album" class="icon32" style="background: transparent url(<?php 
    echo $iconurl;
    ?>
) no-repeat">
			<br />
		</div>
		<h2><?php 
    _e('Photo of the Day Widget Settings', 'wp-photo-album-plus');
    ?>
</h2>
		
		<?php 
    $action_url = wppa_dbg_url(get_admin_url() . 'admin.php?page=wppa_photo_of_the_day');
    ?>
		
		<form action="<?php 
    echo $action_url;
    ?>
" method="post">
			<?php 
    echo wp_nonce_field('wppa-update-check', 'wppa-update-check');
    ?>

			<table class="form-table wppa-table wppa-photo-table">
				<tbody>
					<tr valign="top">
						<th scope="row">
							<label ><?php 
    _e('Widget Title:', 'wp-photo-album-plus');
    ?>
</label>
						</th>
						<td>
							<input type="text" name="wppa-widgettitle" id="wppa-widgettitle" value="<?php 
    echo wppa_opt('widgettitle');
    ?>
" />
							<span class="description"><br/><?php 
    _e('Enter/modify the title for the widget. This is a default and can be overriden at widget activation.', 'wp-photo-album-plus');
    ?>
</span>
						</td>
					</tr>	
					
					<tr valign="top">
						<th scope="row">
							<label ><?php 
    _e('Widget Photo Width:', 'wp-photo-album-plus');
    ?>
</label>
						</th>
						<td>
							<input type="text" name="wppa-potd-widget-width" id="wppa-potd-widget-width" value="<?php 
    echo wppa_opt('potd_widget_width');
    ?>
" style="width: 50px;" />
							<?php 
    _e('pixels.', 'wp-photo-album-plus');
    echo ' ';
    _e('Horizontal alignment:', 'wp-photo-album-plus');
    ?>
							<select name="wppa-potd-align" id="wppa-potd-align">
								<?php 
    $ali = wppa_opt('potd_align');
    ?>
								<?php 
    $sel = 'selected="selected"';
    ?>
								<option value="none" <?php 
    if ($ali == 'none') {
        echo $sel;
    }
    ?>
><?php 
    _e('--- none ---', 'wp-photo-album-plus');
    ?>
</option>
								<option value="left" <?php 
    if ($ali == 'left') {
        echo $sel;
    }
    ?>
><?php 
    _e('left', 'wp-photo-album-plus');
    ?>
</option>
								<option value="center" <?php 
    if ($ali == 'center') {
        echo $sel;
    }
    ?>
><?php 
    _e('center', 'wp-photo-album-plus');
    ?>
</option>
								<option value="right" <?php 
    if ($ali == 'right') {
        echo $sel;
    }
    ?>
><?php 
    _e('right', 'wp-photo-album-plus');
    ?>
</option>
							</select>
							<span class="description"><br/><?php 
    _e('Enter the desired display width and alignment of the photo in the sidebar.', 'wp-photo-album-plus');
    ?>
</span>
						</td>
					</tr>

					<tr valign="top">
						<th scope="row">
							<label ><?php 
    _e('Use album(s):', 'wp-photo-album-plus');
    ?>
</label>
						</th>
						<td>
							<script type="text/javascript">
							/* <![CDATA[ */
							function wppaCheckWa() {
								document.getElementById('wppa-spin').style.visibility = 'visible';
								document.getElementById('wppa-upd').style.visibility = 'hidden';
								var album = document.getElementById('wppa-wa').value;
								if ( album != 'all' && album != 'sep' && album != 'all-sep' && album != 'topten' && album != 'clr' )
									album = document.getElementById('wppa-was').value + ',' + album;
								var url = "<?php 
    echo wppa_dbg_url(get_admin_url() . 'admin.php?page=wppa_photo_of_the_day');
    ?>
&walbum=" + album;
								document.location.href = url;
							}
							/* ]]> */
							</script>
							<?php 
    _e('Select:', 'wp-photo-album-plus');
    ?>
<select name="wppa-widget-album" id="wppa-wa" onchange="wppaCheckWa()" ><?php 
    echo wppa_walbum_select(wppa_opt('widget_album'));
    ?>
</select>
							<img id="wppa-spin" src="<?php 
    echo wppa_get_imgdir();
    ?>
wpspin.gif" style="visibility:hidden;"/>
							<?php 
    _e('Or Edit:', 'wp-photo-album-plus');
    ?>
<input type="text" name="wppa-widget-albums" id="wppa-was" value="<?php 
    echo wppa_opt('widget_album');
    ?>
" />
							<input class="button-primary" name="wppa-upd" id="wppa-upd" value="<?php 
    _e('Update thumbnails', 'wp-photo-album-plus');
    ?>
" onclick="wppaCheckWa()" />
							<span class="description"><br/>
								<?php 
    _e('Select or edit the album(s) you want to use the photos of for the widget.', 'wp-photo-album-plus');
    ?>
								<br />
								<?php 
    _e('If you want a <b>- special -</b> selection or get rid of it, you may need to use <b>- start over -</b> first.', 'wp-photo-album-plus');
    ?>
							</span>
						</td>
					</tr>
					<!-- Status filter -->
					<tr valign="top" >
						<th scope="row" >
							<label ><?php 
    _e('Status filter:', 'wp-photo-album-plus');
    ?>
</label>
						</th>
						<td>
							<?php 
    $sel = 'selected="selected"';
    ?>
							<?php 
    $filter = wppa_opt('widget_status_filter');
    ?>
							<select name="wppa-widget-status-filter" >
								<option value="" <?php 
    if ($filter == 'none') {
        echo $sel;
    }
    ?>
><?php 
    _e('- none -', 'wp-photo-album-plus');
    ?>
</option>
								<option value="publish" <?php 
    if ($filter == 'publish') {
        echo $sel;
    }
    ?>
 ><?php 
    _e('Publish', 'wp-photo-album-plus');
    ?>
</option>
								<option value="featured" <?php 
    if ($filter == 'featured') {
        echo $sel;
    }
    ?>
 ><?php 
    _e('Featured', 'wp-photo-album-plus');
    ?>
</option>
								<option value="gold" <?php 
    if ($filter == 'gold') {
        echo $sel;
    }
    ?>
 ><?php 
    _e('Gold', 'wp-photo-album-plus');
    ?>
</option>
								<option value="silver" <?php 
    if ($filter == 'silver') {
        echo $sel;
    }
    ?>
 ><?php 
    _e('Silver', 'wp-photo-album-plus');
    ?>
</option>
								<option value="bronze" <?php 
    if ($filter == 'bronze') {
        echo $sel;
    }
    ?>
 ><?php 
    _e('Bronze', 'wp-photo-album-plus');
    ?>
</option>
								<option value="anymedal" <?php 
    if ($filter == 'anymedal') {
        echo $sel;
    }
    ?>
 ><?php 
    _e('Any medal', 'wp-photo-album-plus');
    ?>
</option>
							</select>
						</td>
					</tr>
					<tr valign="top" >
						<th scope="row">
							<label ><?php 
    _e('Display method:', 'wp-photo-album-plus');
    ?>
</label>
						</th>
						<td>
							<?php 
    $sel = 'selected="selected"';
    ?>
							<?php 
    $method = wppa_opt('widget_method');
    ?>
							<select name="wppa-widget-method" id="wppa-wm" onchange="wppaCheckWidgetMethod()" >
								<option value="1" <?php 
    if ($method == '1') {
        echo $sel;
    }
    ?>
><?php 
    _e('Fixed photo', 'wp-photo-album-plus');
    ?>
</option> 
								<option value="2" <?php 
    if ($method == '2') {
        echo $sel;
    }
    ?>
><?php 
    _e('Random', 'wp-photo-album-plus');
    ?>
</option>
								<option value="3" <?php 
    if ($method == '3') {
        echo $sel;
    }
    ?>
><?php 
    _e('Last upload', 'wp-photo-album-plus');
    ?>
</option>
								<option value="4" <?php 
    if ($method == '4') {
        echo $sel;
    }
    ?>
><?php 
    _e('Change every', 'wp-photo-album-plus');
    ?>
</option>
							</select>
							<?php 
    $period = wppa_opt('widget_period');
    $text = esc_attr(__('The page will now be reloaded', 'wp-photo-album-plus'));
    $onchange = esc_attr('alert(\'' . $text . '\');wppaPotdChangePeriod()');
    ?>
							<script type="text/javascript" >
								function wppaPotdChangePeriod() {
									var url = '<?php 
    echo $action_url;
    ?>
';
									url += '&wppa-set-submit=1';
									url += '&wppa-update-check='+jQuery('#wppa-update-check').val();
									url += '&wppa-widget-period='+jQuery('#wppa-wp').val();
									document.location.href = url;
								}
							</script>
							<select name="wppa-widget-period" id="wppa-wp" onchange="<?php 
    echo $onchange;
    ?>
" >
								<option value="0" <?php 
    if ($period == '0') {
        echo $sel;
    }
    ?>
><?php 
    _e('pageview.', 'wp-photo-album-plus');
    ?>
</option>
								<option value="1" <?php 
    if ($period == '1') {
        echo $sel;
    }
    ?>
><?php 
    _e('hour.', 'wp-photo-album-plus');
    ?>
</option>
								<option value="24" <?php 
    if ($period == '24') {
        echo $sel;
    }
    ?>
><?php 
    _e('day.', 'wp-photo-album-plus');
    ?>
</option>
								<option value="168" <?php 
    if ($period == '168') {
        echo $sel;
    }
    ?>
><?php 
    _e('week.', 'wp-photo-album-plus');
    ?>
</option>
								<option value="736" <?php 
    if ($period == '736') {
        echo $sel;
    }
    ?>
><?php 
    _e('month.', 'wp-photo-album-plus');
    ?>
</option>
								<option value="day-of-week" <?php 
    if ($period == 'day-of-week') {
        echo $sel;
    }
    ?>
><?php 
    _e('day of week is order#', 'wp-photo-album-plus');
    ?>
</option>
								<option value="day-of-month" <?php 
    if ($period == 'day-of-month') {
        echo $sel;
    }
    ?>
><?php 
    _e('day of month is order#', 'wp-photo-album-plus');
    ?>
</option>
								<option value="day-of-year" <?php 
    if ($period == 'day-of-year') {
        echo $sel;
    }
    ?>
><?php 
    _e('day of year is order#', 'wp-photo-album-plus');
    ?>
</option>
							</select>
							<span class="description"><br/><?php 
    _e('Select how the widget should display.', 'wp-photo-album-plus');
    ?>
</span>
							<div class="wppa-order" >
							<?php 
    if (substr(wppa_opt('widget_period'), 0, 7) == 'day-of-') {
        switch (substr(wppa_opt('widget_period'), 7)) {
            case 'week':
                $n_days = '7';
                $date_key = 'w';
                break;
            case 'month':
                $n_days = '31';
                $date_key = 'd';
                break;
            case 'year':
                $n_days = '366';
                $date_key = 'z';
                break;
        }
        while (get_option('wppa_potd_offset', '0') > $n_days) {
            update_option('wppa_potd_offset', get_option('wppa_potd_offset') - $n_days);
        }
        echo sprintf(__('Current day# = %s, offset =', 'wp-photo-album-plus'), date_i18n($date_key)) . ' ';
        echo '<select name="wppa-potd-offset" >';
        $day = '0';
        while ($day < $n_days) {
            echo '<option value="' . $day . '" ' . (get_option('wppa_potd_offset', '0') == $day ? 'selected="selected"' : '') . ' >' . $day . '</option>';
            $day++;
        }
        echo '</select>';
        $photo_order = date_i18n($date_key) - get_option('wppa_potd_offset', '0');
        while ($photo_order < '1') {
            $photo_order += $n_days;
        }
        echo '. ' . sprintf(__('Todays photo order# = %s.', 'wp-photo-album-plus'), $photo_order);
        $photo = wppa_get_potd();
        if ($photo) {
            echo ' <img src="' . wppa_fix_poster_ext(wppa_get_thumb_url($photo['id']), $photo['id']) . '" style="width:100px;" />';
        } else {
            echo ' ' . __('Not found.', 'wp-photo-album-plus');
        }
    }
    ?>
							</div>
						</td>
					</tr>
<?php 
    $linktype = wppa_opt('widget_linktype');
    if ($linktype != 'custom') {
        ?>
						<tr>
							<th scope="row">
								<label ><?php 
        _e('Link to:', 'wp-photo-album-plus');
        ?>
</label>
							</th>
							<td>
								<?php 
        _e('Links are set on the <b>Photo Albums -> Settings</b> screen.', 'wp-photo-album-plus');
        ?>
							</td>
						</tr>
<?php 
    } else {
        ?>
						<tr class="wppa-wlu" >
							<th scope="row">
								<label ><?php 
        _e('Link to:', 'wp-photo-album-plus');
        ?>
</label>
							</th>
							<td>
								<?php 
        _e('Title:', 'wp-photo-album-plus');
        ?>
								<input type="text" name="wppa-widget-linktitle" id="wppa-widget-linktitle" value="<?php 
        echo wppa_opt('widget_linktitle');
        ?>
"style="width:20%" />
								<?php 
        _e('Url:', 'wp-photo-album-plus');
        ?>
								<input type="text"  name="wppa-widget-linkurl" id="wppa-widget-linkurl" value="<?php 
        echo wppa_opt('widget_linkurl');
        ?>
" style="width:50%" />
								<span class="description"><br/><?php 
        _e('Enter the title and the url. Do\'nt forget the HTTP://', 'wp-photo-album-plus');
        ?>
</span>
							</td>
						</tr>
<?php 
    }
    ?>
					<!--<script type="text/javascript">wppaCheckWidgetLink()</script>-->
					<tr>
						<th scope="row">
							<label ><?php 
    _e('Subtitle:', 'wp-photo-album-plus');
    ?>
</label>
						</th>
						<td>
							<?php 
    $subtit = wppa_opt('widget_subtitle');
    ?>
							<select name="wppa-widget-subtitle" id="wppa-st" >
								<option value="none" <?php 
    if ($subtit == 'none') {
        echo $sel;
    }
    ?>
><?php 
    _e('--- none ---', 'wp-photo-album-plus');
    ?>
</option>
								<option value="name" <?php 
    if ($subtit == 'name') {
        echo $sel;
    }
    ?>
><?php 
    _e('Photo Name', 'wp-photo-album-plus');
    ?>
</option>
								<option value="desc" <?php 
    if ($subtit == 'desc') {
        echo $sel;
    }
    ?>
><?php 
    _e('Description', 'wp-photo-album-plus');
    ?>
</option>
								<option value="owner" <?php 
    if ($subtit == 'owner') {
        echo $sel;
    }
    ?>
><?php 
    _e('Owner', 'wp-photo-album-plus');
    ?>
</option>
							</select>
							<span class="description"><br/><?php 
    _e('Select the content of the subtitle.', 'wp-photo-album-plus');
    ?>
</span>	
						</td>
					</tr>
				</tbody>
			</table>
			<p>
				<input type="submit" class="button-primary" name="wppa-set-submit" value="<?php 
    _e('Save Changes', 'wp-photo-album-plus');
    ?>
" />
			</p>
			<?php 
    $alb = wppa_opt('widget_album');
    $opt = wppa_is_int($alb) ? ' ' . wppa_get_photo_order($alb) . ' ' : '';
    $photos = wppa_get_widgetphotos($alb, $opt);
    if (empty($photos)) {
        echo '<p>' . __('No photos yet in this album.', 'wp-photo-album-plus') . '</p>';
    } else {
        $curid = wppa_opt('widget_photo');
        // Process photos
        foreach ($photos as $photo) {
            $id = $photo['id'];
            // Open container div
            echo '<div' . ' class="photoselect"' . ' style="' . 'width:180px;' . 'height:300px;' . '" >';
            // Open image container div
            echo '<div' . ' style="' . 'width:180px;' . 'height:135px;' . 'overflow:hidden;' . 'text-align:center;' . '" >';
            // The image if a video
            if (wppa_is_video($id)) {
                echo wppa_get_video_html(array('id' => $id, 'style' => 'width:180px;'));
            } else {
                echo '<img' . ' src=" ' . wppa_fix_poster_ext(wppa_get_thumb_url($id), $id) . '"' . ' style="' . 'max-width:180px;' . 'max-height:135px;' . 'margin:auto;' . '"' . ' alt="' . esc_attr(wppa_get_photo_name($photo['id'])) . '" />';
                // Audio ?
                if (wppa_has_audio($id)) {
                    echo wppa_get_audio_html(array('id' => $id, 'style' => 'width:180px;' . 'position:relative;' . 'bottom:' . (wppa_get_audio_control_height() + 4) . 'px;'));
                }
            }
            // Close image container div
            echo '</div>';
            ?>
						<div style="clear:both;width:100%;margin:3px 0;" >
							<div style="font-size:9px; line-height:10px;float:left;"><?php 
            echo '(#' . $photo['p_order'] . ')';
            ?>
</div>
							<input style="float:right;" type="radio" name="wppa-widget-photo" id="wppa-widget-photo<?php 
            echo $id;
            ?>
" value="<?php 
            echo $id;
            ?>
" <?php 
            if ($id == $curid) {
                echo 'checked="checked"';
            }
            ?>
/>
						</div>
						<div style="clear:both;overflow:auto;height:150px" >
							<div style="font-size:11px; overflow:hidden;"><?php 
            echo wppa_get_photo_name($photo['id']);
            ?>
</div>
							<div style="font-size:9px; line-height:10px;"><?php 
            echo wppa_get_photo_desc($photo['id']);
            ?>
</div>
						</div>
					</div>
					<?php 
        }
        echo '<div class="clear"></div>';
    }
    ?>
			<script type="text/javascript">wppaCheckWidgetMethod();</script>
			<br />
			<p>
				<input type="submit" class="button-primary" name="wppa-set-submit" value="<?php 
    _e('Save Changes', 'wp-photo-album-plus');
    ?>
" />
			</p>
		</form>
	</div>
<?php 
}
function wppa_album_sequence($parent)
{
    global $wpdb;
    // Get the albums
    $albumorder = wppa_get_album_order($parent);
    $is_descending = strpos($albumorder, 'DESC') !== false;
    $albums = $wpdb->get_results($wpdb->prepare('SELECT * FROM `' . WPPA_ALBUMS . '` WHERE `a_parent` = %s ' . $albumorder, $parent), ARRAY_A);
    // Anything to do here ?
    if (empty($albums)) {
        return;
    }
    // Check my access rights
    foreach ($albums as $album) {
        if (!wppa_have_access($album['id'])) {
            return;
        }
    }
    // Check album order
    if (!strpos($albumorder, 'a_order')) {
        if ($parent == '0') {
            echo '<br />';
            _e('You can edit top-level album sequence order here when you set the album order to "Order #" or "Order # desc" in Table IV-D1.');
        } else {
            _e('You can edit sub-album sequence order here when you set the album order to "Order #" or "Order # desc" in the "Sub album sort order:" selection box above.');
        }
        return;
    }
    echo '<h2>' . __('Manage album order', 'wp-photo-album-plus') . ' - ' . '<small>' . '<i>' . __('Change sequence order by drag and drop, or use the up/down arrows.', 'wp-photo-album-plus') . '</i>' . ' ' . __('Do not leave this page unless the bar is entirely green.', 'wp-photo-album-plus') . '</small>' . '</h2>';
    echo '<table>' . '<thead>' . '<tr>' . '<th>' . __('Color', 'wp-photo-album-plus') . '</th>' . '<th>' . __('Meaning', 'wp-photo-album-plus') . '</th>' . '</tr>' . '</thead>' . '<tbody>' . '<tr>' . '<td>' . '<div style="background-color:green;height:12px;" ></div>' . '</td>' . '<td>' . __('Up to date', 'wp-photo-album-plus') . '</td>' . '</tr>' . '<tr>' . '<td>' . '<div style="background-color:yellow;height:12px;" ></div>' . '</td>' . '<td>' . __('Updating', 'wp-photo-album-plus') . '</td>' . '</tr>' . '<tr>' . '<td>' . '<div style="background-color:orange;height:12px;" ></div>' . '</td>' . '<td>' . __('Needs update', 'wp-photo-album-plus') . '</td>' . '</tr>' . '<tr>' . '<td>' . '<div style="background-color:red;height:12px;" ></div>' . '</td>' . '<td>' . __('Error', 'wp-photo-album-plus') . '</td>' . '</tr>' . '</tbody>' . '</table>';
    ?>
		<style>
			.sortable-placeholder-albums {
				width: 100%;
				height: 60px;
				margin: 5px;
				border: 1px dotted #cccccc;
				border-radius:3px;
				float: left;
			}
			.ui-state-default-albums {
				position: relative;
				width: 100%;
				height: 60px;
				margin: 5px;
				border: 1px solid #cccccc;
				border-radius:3px;
				float: left;
			}
			.ui-state-default-albums td {
				padding:0;
				line-height:12px;
				text-align:center;
			}
		</style>
		<script>
			jQuery( function() {
				jQuery( "#sortable-albums" ).sortable( {
					cursor: 		"move",
					placeholder: 	"sortable-placeholder-albums",
					stop: 			function( event, ui ) { wppaDoRenumber(); }
				} );
			} );
			var wppaRenumberPending = false;
			var wppaAjaxInProgress 	= 0;

			function wppaDoRenumber() {

				// Busy?
				if ( wppaAjaxInProgress > 0 ) {
					wppaRenumberPending = true;
				}

				// Not busy
				else {
					_wppaDoRenumber();
				}
			}

			function _wppaDoRenumber() {

				// Init
				var ids = jQuery( ".wppa-sort-item-albums" );
				var seq = jQuery( ".wppa-sort-seqn-albums" );
				var descend = <?php 
    if ($is_descending) {
        echo 'true';
    } else {
        echo 'false';
    }
    ?>
;

				// Mark needs update
				var idx = 0;
				while ( idx < ids.length ) {
					var newvalue;
					if ( descend ) newvalue = ids.length - idx;
					else newvalue = idx + 1;
					var oldvalue = seq[idx].value;
					var album = ids[idx].value;
					if ( newvalue != oldvalue ) {
						jQuery( '#wppa-pb-'+idx ).css({backgroundColor:'orange'});
					}
					idx++;
				}

				// Process
				var idx = 0;
				while ( idx < ids.length ) {
					var newvalue;
					if ( descend ) newvalue = ids.length - idx;
					else newvalue = idx + 1;
					var oldvalue = seq[idx].value;
					var album = ids[idx].value;
					if ( newvalue != oldvalue ) {
						wppaDoSeqUpdateAlbum( album, newvalue );
						jQuery( '#wppa-pb-'+idx ).css({backgroundColor:'yellow'});
						wppaLastAlbum = album;
					}
					idx++;
				}
			}

			function wppaDoSeqUpdateAlbum( album, seqno ) {

				var data = 	'action=wppa' +
							'&wppa-action=update-album' +
							'&album-id=' + album +
							'&item=a_order' +
							'&wppa-nonce=' + document.getElementById( 'album-nonce-' + album ).value +
							'&value=' + seqno;
				var xmlhttp = new XMLHttpRequest();

				xmlhttp.onreadystatechange = function() {
					if ( xmlhttp.readyState == 4 && xmlhttp.status != 404 ) {
						var ArrValues = xmlhttp.responseText.split( "||" );
						if ( ArrValues[0] != '' ) {
							alert( 'The server returned unexpected output:\n' + ArrValues[0] );
						}
						switch ( ArrValues[1] ) {
							case '0':	// No error
								var i = seqno - 1;
								var descend = <?php 
    if ($is_descending) {
        echo 'true';
    } else {
        echo 'false';
    }
    ?>
;
								if ( descend ) {
									i = <?php 
    echo count($albums);
    ?>
 - seqno;
								}
								jQuery( '#wppa-album-seqno-' + album ).html( seqno );
								if ( wppaRenumberPending ) {
									jQuery( '#wppa-pb-'+i ).css({backgroundColor:'orange'});
								}
								else {
									jQuery( '#wppa-pb-'+i ).css({backgroundColor:'green'});
								}
								if ( wppaLastAlbum = album ) {
									wppaRenumberBusy = false;
								}
								break;
							default:	// Any error
								jQuery( '#wppa-album-seqno-' + album ).html( '<span style="color"red" >Err:' + ArrValues[1] + '</span>' );
								break;
						}
						wppaAjaxInProgress--;

						// No longer busy?
						if ( wppaAjaxInProgress == 0 ) {

							if ( wppaRenumberPending ) {

								// Redo
								wppaRenumberPending = false;
								wppaDoRenumber();
							}
						}
					}
				}
				xmlhttp.open( 'POST',wppaAjaxUrl,true );
				xmlhttp.setRequestHeader( "Content-type","application/x-www-form-urlencoded" );
				xmlhttp.send( data );
				wppaAjaxInProgress++;

				jQuery( "#wppa-sort-seqn-albums-" + album ).attr( 'value', seqno );	// set hidden value to new value to prevent duplicate action
				var spinnerhtml = '<img src="' + wppaImageDirectory + 'spinner.gif' + '" />';
				jQuery( '#wppa-album-seqno-' + album ).html( spinnerhtml );
			}
		</script>

		<br />

		<div id="wppa-progbar" style="width:100%;height:12px;" >
			<?php 
    $c = count($albums);
    $l = 100 / $c;
    $i = 0;
    while ($i < $c) {
        echo '<div' . ' id="wppa-pb-' . $i . '"' . ' style="display:inline;float:left;background-color:green;height:12px;width:' . $l . '%;"' . ' >' . '</div>';
        $i++;
    }
    ?>
		</div>

		<br />

		<div class="widefat" style="max-width:600px;" >
			<div id="sortable-albums">
				<?php 
    foreach ($albums as $album) {
        $cover_photo_id = wppa_get_coverphoto_id($album['id']);
        echo '
					<div' . ' id="albumitem-' . $album['id'] . '"' . ' class="ui-state-default-albums"' . ' style="background-color:#eeeeee;cursor:move;"' . ' >' . '<div' . ' style="height:100%;width:25%;float:left;text-align:center;overflow:hidden;" >';
        if (wppa_is_video($cover_photo_id)) {
            echo wppa_get_video_html(array('id' => $cover_photo_id, 'height' => '50', 'margin_top' => '5', 'margin_bottom' => '5', 'controls' => false));
        } else {
            echo '<img' . ' class="wppa-cover-image"' . ' src="' . wppa_fix_poster_ext(wppa_get_thumb_url(wppa_get_coverphoto_id($album['id'])), $cover_photo_id) . '"' . ' style="max-height:50px; margin: 5px;"' . ' />';
        }
        echo '</div>' . '<div style="height:100%;width:40%;float:left;font-size:12px;overflow:hidden;" >' . '<b>' . wppa_get_album_name($album['id']) . '</b>' . '<br />' . wppa_get_album_desc($album['id']) . '</div>' . '<div style="float:right;width:10%;" >' . '<table>' . '<tr><td>' . '<img' . ' src="' . wppa_get_imgdir('up.png') . '"' . ' title="' . esc_attr(__('To top', 'wp-photo-album-plus')) . '"' . ' style="cursor:pointer;"' . ' onclick="' . 'jQuery( \'#albumitem-' . $album['id'] . '\' ).parent().prepend(jQuery( \'#albumitem-' . $album['id'] . '\' ));' . 'wppaDoRenumber();' . '"' . ' />' . '</td></tr>' . '<tr><td>' . '<img' . ' src="' . wppa_get_imgdir('up.png') . '"' . ' title="' . esc_attr(__('One up', 'wp-photo-album-plus')) . '"' . ' style="cursor:pointer;width:24px;"' . ' onclick="' . 'jQuery( \'#albumitem-' . $album['id'] . '\' ).prev().before(jQuery( \'#albumitem-' . $album['id'] . '\' ));' . 'wppaDoRenumber();' . '"' . ' />' . '</td></tr>' . '<tr><td>' . '<img' . ' src="' . wppa_get_imgdir('down.png') . '"' . ' title="' . esc_attr(__('One down', 'wp-photo-album-plus')) . '"' . ' style="cursor:pointer;width:24px;"' . ' onclick="' . 'jQuery( \'#albumitem-' . $album['id'] . '\' ).next().after(jQuery( \'#albumitem-' . $album['id'] . '\' ));' . 'wppaDoRenumber();' . '"' . ' />' . '</td></tr>' . '<tr><td>' . '<img' . ' src="' . wppa_get_imgdir('down.png') . '"' . ' title="' . esc_attr(__('To bottom', 'wp-photo-album-plus')) . '"' . ' style="cursor:pointer;"' . ' onclick="' . 'jQuery( \'#albumitem-' . $album['id'] . '\' ).parent().append(jQuery( \'#albumitem-' . $album['id'] . '\' ));' . 'wppaDoRenumber();' . '"' . ' />' . '</td></tr>' . '</table>' . '</div>' . '<div style="float:right; width:25%;" >' . '<span style=""> ' . __('Id:', 'wp-photo-album-plus') . ' ' . $album['id'] . '</span>' . '<span style=""> - ' . __('Ord:', 'wp-photo-album-plus') . '</span>' . '<span id="wppa-album-seqno-' . $album['id'] . '" > ' . $album['a_order'] . '</span>' . '<br />' . '<a href="' . wppa_ea_url($album['id']) . '" style="position:absolute;bottom:0;" >' . __('Edit', 'wp-photo-album-plus') . '</a>' . '</div>' . '<input type="hidden" id="album-nonce-' . $album['id'] . '" value="' . wp_create_nonce('wppa_nonce_' . $album['id']) . '" />' . '<input type="hidden" class="wppa-sort-item-albums" value="' . $album['id'] . '" />' . '<input type="hidden" class="wppa-sort-seqn-albums" id="wppa-sort-seqn-albums-' . $album['id'] . '" value="' . $album['a_order'] . '" />' . '</div>';
    }
    ?>
			</div>
			<div style="clear:both;"></div>
		</div>
		<?php 
}
function wppa_fe_edit_new_style($photo)
{
    $items = array('name', 'description', 'tags', 'custom_0', 'custom_1', 'custom_2', 'custom_3', 'custom_4', 'custom_5', 'custom_6', 'custom_7', 'custom_8', 'custom_9');
    $titles = array(__('Name', 'wp-photo-album-plus'), __('Description', 'wp-photo-album-plus'), __('Tags', 'wp-photo-album-plus'), apply_filters('translate_text', wppa_opt('custom_caption_0')), apply_filters('translate_text', wppa_opt('custom_caption_1')), apply_filters('translate_text', wppa_opt('custom_caption_2')), apply_filters('translate_text', wppa_opt('custom_caption_3')), apply_filters('translate_text', wppa_opt('custom_caption_4')), apply_filters('translate_text', wppa_opt('custom_caption_5')), apply_filters('translate_text', wppa_opt('custom_caption_6')), apply_filters('translate_text', wppa_opt('custom_caption_7')), apply_filters('translate_text', wppa_opt('custom_caption_8')), apply_filters('translate_text', wppa_opt('custom_caption_9')));
    $types = array('text', 'textarea', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text');
    $doit = array(wppa_switch('fe_edit_name'), wppa_switch('fe_edit_desc'), wppa_switch('fe_edit_tags'), wppa_switch('custom_edit_0'), wppa_switch('custom_edit_1'), wppa_switch('custom_edit_2'), wppa_switch('custom_edit_3'), wppa_switch('custom_edit_4'), wppa_switch('custom_edit_5'), wppa_switch('custom_edit_6'), wppa_switch('custom_edit_7'), wppa_switch('custom_edit_8'), wppa_switch('custom_edit_9'));
    // Open page
    echo '<div' . ' style="width:100%;margin-top:8px;padding:8px;display:block;box-sizing:border-box;background-color:#fff;"' . ' >' . '<h3>' . '<img' . ' style="height:50px;"' . ' src="' . wppa_get_thumb_url($photo) . '"' . ' alt="' . $photo . '"' . ' />' . '&nbsp;&nbsp;' . wppa_opt('fe_edit_caption') . '</h3>';
    // Open form
    echo '<form' . ' >' . '<input' . ' type="hidden"' . ' id="wppa-nonce-' . $photo . '"' . ' name="wppa-nonce"' . ' value="' . wp_create_nonce('wppa-nonce-' . $photo) . '"' . ' />';
    // Get custom data
    $custom = wppa_get_photo_item($photo, 'custom');
    if ($custom) {
        $custom_data = unserialize($custom);
    } else {
        $custom_data = array('', '', '', '', '', '', '', '', '', '');
    }
    // Items
    foreach (array_keys($items) as $idx) {
        if ($titles[$idx] && $doit[$idx]) {
            echo '<h6>' . $titles[$idx] . '</h6>';
            if (wppa_is_int(substr($items[$idx], -1))) {
                $value = stripslashes($custom_data[substr($items[$idx], -1)]);
            } else {
                $value = wppa_get_photo_item($photo, $items[$idx]);
                if ($items[$idx] == 'tags') {
                    $value = trim($value, ',');
                }
            }
            if ($types[$idx] == 'text') {
                echo '<input' . ' type="text"' . ' style="width:100%;"' . ' id="' . $items[$idx] . '"' . ' name="' . $items[$idx] . '"' . ' value="' . esc_attr($value) . '"' . ' />';
            }
            if ($types[$idx] == 'textarea') {
                echo '<textarea' . ' style="width:100%;min-width:100%;max-width:100%;"' . ' id="' . $items[$idx] . '"' . ' name="' . $items[$idx] . '"' . ' >' . esc_textarea(stripslashes($value)) . '</textarea>';
            }
        }
    }
    // Submit
    echo '<input' . ' type="button"' . ' style="margin-top:8px;margin-right:8px;"' . ' value="' . esc_attr(__('Send', 'wp-photo-album-plus')) . '"' . ' onclick="wppaUpdatePhotoNew(' . $photo . ');document.location.reload(true);"' . ' />';
    // Cancel
    echo '<input' . ' type="button"' . ' style="margin-top:8px;"' . ' value="' . esc_attr(__('Cancel', 'wp-photo-album-plus')) . '"' . ' onclick="jQuery( \'.ui-button\' ).trigger(\'click\')"' . ' />';
    // Close form
    echo '</form>';
    // Close page
    echo '</div>';
}
function wppa_album_sequence($parent)
{
    global $wpdb;
    // Get the albums
    $albumorder = wppa_get_album_order($parent);
    $is_descending = strpos($albumorder, 'DESC') !== false;
    $albums = $wpdb->get_results($wpdb->prepare('SELECT * FROM `' . WPPA_ALBUMS . '` WHERE `a_parent` = %s ' . $albumorder, $parent), ARRAY_A);
    // Anything to do here ?
    if (empty($albums)) {
        return;
    }
    // Check my access rights
    foreach ($albums as $album) {
        if (!wppa_have_access($album['id'])) {
            return;
        }
    }
    // Check album order
    if (!strpos($albumorder, 'a_order')) {
        if ($parent == '0') {
            echo '<br />';
            _e('You can edit top-level album sequence order here when you set the album order to "Order #" or "Order # desc" in Table IV-D1.');
        } else {
            _e('You can edit sub-album sequence order here when you set the album order to "Order #" or "Order # desc" in the "Sub album sort order:" selection box above.');
        }
        return;
    }
    echo '<h2>' . __('Manage album order', 'wp-photo-album-plus') . ' - ' . '<small><i>' . __('Change sequence order by drag and drop', 'wp-photo-album-plus') . '</i></small>' . '</h2>';
    ?>
		<style>
			.sortable-placeholder-albums {
				width: 100%;
				height: 60px;
				margin: 5px;
				border: 1px dotted #cccccc;
				border-radius:3px;
				float: left;
			}
			.ui-state-default-albums {
				position: relative;
				width: 100%;
				height: 60px;
				margin: 5px;
				border: 1px solid #cccccc;
				border-radius:3px;
				float: left;
			}
		</style>
		<script>
			jQuery( function() {
				jQuery( "#sortable-albums" ).sortable( {
					cursor: "move",
					placeholder: "sortable-placeholder-albums",
					stop: function( event, ui ) {
						var ids = jQuery( ".wppa-sort-item-albums" );
						var seq = jQuery( ".wppa-sort-seqn-albums" );
						var idx = 0;
						var descend = <?php 
    if ($is_descending) {
        echo 'true';
    } else {
        echo 'false';
    }
    ?>
;
						while ( idx < ids.length ) {
							var newvalue;
							if ( descend ) newvalue = ids.length - idx;
							else newvalue = idx + 1;
							var oldvalue = seq[idx].value;
							var album = ids[idx].value;
							if ( newvalue != oldvalue ) {
								wppaDoSeqUpdateAlbum( album, newvalue );
							}
							idx++;
						}
					}
				} );
			} );
			function wppaDoSeqUpdateAlbum( album, seqno ) {
				var data = 	'action=wppa' +
							'&wppa-action=update-album' +
							'&album-id=' + album +
							'&item=a_order' +
							'&wppa-nonce=' + document.getElementById( 'album-nonce-' + album ).value +
							'&value=' + seqno;
				var xmlhttp = new XMLHttpRequest();

				xmlhttp.onreadystatechange = function() {
					if ( xmlhttp.readyState == 4 && xmlhttp.status != 404 ) {
						var ArrValues = xmlhttp.responseText.split( "||" );
						if ( ArrValues[0] != '' ) {
							alert( 'The server returned unexpected output:\n' + ArrValues[0] );
						}
						switch ( ArrValues[1] ) {
							case '0':	// No error
								jQuery( '#wppa-album-seqno-' + album ).html( seqno );
								break;
							default:	// Any error
								jQuery( '#wppa-album-seqno-' + album ).html( '<span style="color"red" >Err:' + ArrValues[1] + '</span>' );
								break;
						}
					}
				}
				xmlhttp.open( 'POST',wppaAjaxUrl,true );
				xmlhttp.setRequestHeader( "Content-type","application/x-www-form-urlencoded" );
				xmlhttp.send( data );
				jQuery( "#wppa-sort-seqn-albums-" + album ).attr( 'value', seqno );	// set hidden value to new value to prevent duplicate action
				var spinnerhtml = '<img src="' + wppaImageDirectory + 'wpspin.gif' + '" />';
				jQuery( '#wppa-album-seqno-' + album ).html( spinnerhtml );
			}
		</script>

		<div class="widefat" style="max-width:500px;" >
			<div id="sortable-albums">
				<?php 
    foreach ($albums as $album) {
        echo '
					<div' . ' id="albumitem-' . $album['id'] . '"' . ' class="ui-state-default-albums"' . ' style="background-color:#eeeeee;cursor:move;"' . ' >' . '<div' . ' style="height:100%;width:25%;float:left;text-align:center;overflow:hidden;" >' . '<img' . ' class="wppa-cover-image"' . ' src="' . wppa_fix_poster_ext(wppa_get_thumb_url(wppa_get_coverphoto_id($album['id'])), wppa_get_coverphoto_id($album['id'])) . '"' . ' style="max-height:50px; margin: 5px;"' . ' />' . '</div>' . '<div style="height:100%;width:50%;float:left;font-size:12px;overflow:hidden;" >' . '<b>' . wppa_get_album_name($album['id']) . '</b>' . '<br />' . wppa_get_album_desc($album['id']) . '</div>' . '<div style="float:right; width:25%;" >' . '<span style=""> ' . __('Id:', 'wp-photo-album-plus') . ' ' . $album['id'] . '</span>' . '<span style=""> - ' . __('Ord:', 'wp-photo-album-plus') . '</span>' . '<span id="wppa-album-seqno-' . $album['id'] . '" > ' . $album['a_order'] . '</span>' . '<br />' . '<a href="' . wppa_ea_url($album['id']) . '" style="position:absolute;bottom:0;" >' . __('Edit', 'wp-photo-album-plus') . '</a>' . '</div>' . '<input type="hidden" id="album-nonce-' . $album['id'] . '" value="' . wp_create_nonce('wppa_nonce_' . $album['id']) . '" />' . '<input type="hidden" class="wppa-sort-item-albums" value="' . $album['id'] . '" />' . '<input type="hidden" class="wppa-sort-seqn-albums" id="wppa-sort-seqn-albums-' . $album['id'] . '" value="' . $album['a_order'] . '" />' . '</div>';
    }
    ?>
			</div>
			<div style="clear:both;"></div>
		</div>
		<?php 
}
 /** @see WP_Widget::widget */
 function widget($args, $instance)
 {
     global $wpdb;
     global $wppa;
     $wppa['in_widget'] = 'potd';
     $wppa['mocc']++;
     require_once dirname(__FILE__) . '/wppa-links.php';
     require_once dirname(__FILE__) . '/wppa-styles.php';
     require_once dirname(__FILE__) . '/wppa-functions.php';
     require_once dirname(__FILE__) . '/wppa-thumbnails.php';
     require_once dirname(__FILE__) . '/wppa-boxes-html.php';
     require_once dirname(__FILE__) . '/wppa-slideshow.php';
     wppa_initialize_runtime();
     extract($args);
     $widget_title = apply_filters('widget_title', $instance['title']);
     // get the photo  ($image)
     $image = wppa_get_potd();
     // Make the HTML for current picture
     $widget_content = "\n" . '<!-- WPPA+ Photo of the day Widget start -->';
     $ali = wppa_opt('wppa_potd_align');
     if ($ali != 'none') {
         $align = 'text-align:' . $ali . ';';
     } else {
         $align = '';
     }
     $widget_content .= "\n" . '<div class="wppa-widget-photo" style="' . $align . ' padding-top:2px; ">';
     if ($image) {
         $id = $image['id'];
         $w = wppa_opt('wppa_potd_widget_width');
         $ratio = wppa_get_photoy($id) / wppa_get_photox($id);
         $h = round($w * $ratio);
         $usethumb = wppa_use_thumb_file($id, wppa_opt('wppa_widget_width'), '0');
         $imgurl = wppa_fix_poster_ext($usethumb ? wppa_get_thumb_url($id, '', $w, $h) : wppa_get_photo_url($id, '', $w, $h), $id);
         $name = wppa_get_photo_name($id);
         $page = in_array(wppa_opt('wppa_widget_linktype'), $wppa['links_no_page']) ? '' : wppa_get_the_landing_page('wppa_widget_linkpage', __a('Photo of the day'));
         $link = wppa_get_imglnk_a('potdwidget', $id);
         $is_video = wppa_is_video($id);
         $has_audio = wppa_has_audio($id);
         if ($link['is_lightbox']) {
             $lightbox = ($is_video ? ' data-videohtml="' . esc_attr(wppa_get_video_body($id)) . '"' . ' data-videonatwidth="' . wppa_get_videox($id) . '"' . ' data-videonatheight="' . wppa_get_videoy($id) . '"' : '') . ($has_audio ? ' data-audiohtml="' . esc_attr(wppa_get_audio_body($id)) . '"' : '') . ' ' . wppa('rel') . '="' . wppa_opt('lightbox_name') . '"';
         } else {
             $lightbox = '';
         }
         if ($link) {
             if ($link['is_lightbox']) {
                 $cursor = ' cursor:url(' . wppa_get_imgdir() . wppa_opt('wppa_magnifier') . '),pointer;';
                 $title = wppa_zoom_in($id);
                 $ltitle = wppa_get_lbtitle('potd', $id);
             } else {
                 $cursor = ' cursor:pointer;';
                 $title = $link['title'];
                 $ltitle = $title;
             }
         } else {
             $cursor = ' cursor:default;';
             $title = esc_attr(stripslashes(__($image['name'])));
         }
         // The medal if on top
         $widget_content .= wppa_get_medal_html_a(array('id' => $id, 'size' => 'M', 'where' => 'top'));
         // The link, if any
         if ($link) {
             $widget_content .= "\n\t" . '<a href = "' . $link['url'] . '" target="' . $link['target'] . '" ' . $lightbox . ' ' . wppa('lbtitle') . '="' . $ltitle . '">';
         }
         // The image
         if (wppa_is_video($id)) {
             $widget_content .= "\n\t\t" . wppa_get_video_html(array('id' => $id, 'width' => wppa_opt('wppa_potd_widget_width'), 'title' => $title, 'controls' => wppa_opt('widget_linktype') == 'none', 'cursor' => $cursor));
         } else {
             $widget_content .= '<img' . ' src="' . $imgurl . '"' . ' style="width: ' . wppa_opt('wppa_potd_widget_width') . 'px;' . $cursor . '"' . ' ' . wppa_get_imgalt($id) . ($title ? 'title="' . $title . '"' : '') . '/ >';
         }
         // Close the link
         if ($link) {
             $widget_content .= "\n\t" . '</a>';
         }
         // The medal if at the bottom
         $widget_content .= wppa_get_medal_html_a(array('id' => $id, 'size' => 'M', 'where' => 'bot'));
         // Audio
         if (wppa_has_audio($id)) {
             $widget_content .= wppa_get_audio_html(array('id' => $id, 'width' => wppa_opt('wppa_potd_widget_width'), 'controls' => true));
         }
     } else {
         // No image
         $widget_content .= __a('Photo not found.', 'wppa_theme');
     }
     $widget_content .= "\n" . '</div>';
     // Add subtitle, if any
     switch (wppa_opt('wppa_widget_subtitle')) {
         case 'none':
             break;
         case 'name':
             if ($image && $image['name'] != '') {
                 $widget_content .= "\n" . '<div class="wppa-widget-text wppa-potd-text" style="' . $align . '">' . wppa_get_photo_name($id) . '</div>';
             }
             break;
         case 'desc':
             if ($image && $image['description'] != '') {
                 $widget_content .= "\n" . '<div class="wppa-widget-text wppa-potd-text" style="' . $align . '">' . wppa_get_photo_desc($id) . '</div>';
             }
             break;
         case 'owner':
             if ($image) {
                 $owner = $image['owner'];
                 $user = get_user_by('login', $owner);
                 $owner = $user->display_name;
                 $widget_content .= "\n" . '<div class="wppa-widget-text wppa-potd-text" style="' . $align . '">' . __a('By:') . ' ' . $owner . '</div>';
             }
     }
     $widget_content .= "\n" . '<!-- WPPA+ Photo of the day Widget end -->';
     echo "\n" . $before_widget;
     if (!empty($widget_title)) {
         echo $before_title . $widget_title . $after_title;
     }
     echo $widget_content . $after_widget;
     $wppa['in_widget'] = false;
 }
 /** @see WP_Widget::widget */
 function widget($args, $instance)
 {
     global $wpdb;
     global $wppa_opt;
     global $wppa;
     require_once dirname(__FILE__) . '/wppa-links.php';
     require_once dirname(__FILE__) . '/wppa-styles.php';
     require_once dirname(__FILE__) . '/wppa-functions.php';
     require_once dirname(__FILE__) . '/wppa-thumbnails.php';
     require_once dirname(__FILE__) . '/wppa-boxes-html.php';
     require_once dirname(__FILE__) . '/wppa-slideshow.php';
     wppa_initialize_runtime();
     $wppa['in_widget'] = 'lasten';
     $wppa['mocc']++;
     extract($args);
     $instance = wp_parse_args((array) $instance, array('title' => '', 'album' => '', 'albumenum' => '', 'timesince' => 'yes', 'display' => 'thumbs'));
     $widget_title = apply_filters('widget_title', $instance['title']);
     $page = in_array($wppa_opt['wppa_lasten_widget_linktype'], $wppa['links_no_page']) ? '' : wppa_get_the_landing_page('wppa_lasten_widget_linkpage', __a('Last Ten Uploaded Photos'));
     //		$page 		= $wppa_opt['wppa_lasten_widget_linkpage'];
     $max = $wppa_opt['wppa_lasten_count'];
     $album = $instance['album'];
     $timesince = $instance['timesince'];
     $display = $instance['display'];
     $albumenum = $instance['albumenum'];
     $generic = $album == '-2';
     if ($generic) {
         $album = '0';
         $max += '1000';
     }
     if ($album == '-99') {
         $album = implode("' OR `album` = '", explode(',', $albumenum));
     }
     // If you want only 'New' photos in the selection, the period must be <> 0;
     if (wppa_switch('wppa_lasten_limit_new') && wppa_opt('wppa_max_photo_newtime')) {
         $newtime = " `timestamp` >= " . (time() - wppa_opt('wppa_max_photo_newtime'));
         if ($album) {
             $q = "SELECT * FROM `" . WPPA_PHOTOS . "` WHERE (" . $newtime . ") AND ( `album` = '" . $album . "' ) AND ( `status` <> 'pending' AND `status` <> 'scheduled' ) ORDER BY `timestamp` DESC LIMIT " . $max;
         } else {
             $q = "SELECT * FROM `" . WPPA_PHOTOS . "` WHERE (" . $newtime . ") AND `status` <> 'pending' AND `status` <> 'scheduled' ORDER BY `timestamp` DESC LIMIT " . $max;
         }
     } else {
         if ($album) {
             $q = "SELECT * FROM `" . WPPA_PHOTOS . "` WHERE ( `album` = '" . $album . "' ) AND ( `status` <> 'pending' AND `status` <> 'scheduled' ) ORDER BY `timestamp` DESC LIMIT " . $max;
         } else {
             $q = "SELECT * FROM `" . WPPA_PHOTOS . "` WHERE `status` <> 'pending' AND `status` <> 'scheduled' ORDER BY `timestamp` DESC LIMIT " . $max;
         }
     }
     // echo $q;
     $thumbs = $wpdb->get_results($q, ARRAY_A);
     $widget_content = "\n" . '<!-- WPPA+ LasTen Widget start -->';
     $maxw = $wppa_opt['wppa_lasten_size'];
     $maxh = $maxw;
     $lineheight = $wppa_opt['wppa_fontsize_widget_thumb'] * 1.5;
     $maxh += $lineheight;
     if ($timesince == 'yes') {
         $maxh += $lineheight;
     }
     $count = '0';
     if ($thumbs) {
         foreach ($thumbs as $image) {
             global $thumb;
             $thumb = $image;
             if ($generic && wppa_is_separate($thumb['album'])) {
                 continue;
             }
             // Make the HTML for current picture
             if ($display == 'thumbs') {
                 $widget_content .= "\n" . '<div class="wppa-widget" style="width:' . $maxw . 'px; height:' . $maxh . 'px; margin:4px; display:inline; text-align:center; float:left;">';
             } else {
                 $widget_content .= "\n" . '<div class="wppa-widget" >';
             }
             if ($image) {
                 $no_album = !$album;
                 if ($no_album) {
                     $tit = __a('View the most recent uploaded photos', 'wppa_theme');
                 } else {
                     $tit = esc_attr(wppa_qtrans(stripslashes($image['description'])));
                 }
                 $link = wppa_get_imglnk_a('lasten', $image['id'], '', $tit, '', $no_album, $albumenum);
                 $file = wppa_get_thumb_path($image['id']);
                 $imgstyle_a = wppa_get_imgstyle_a($image['id'], $file, $maxw, 'center', 'ltthumb');
                 $imgurl = wppa_get_thumb_url($image['id'], '', $imgstyle_a['width'], $imgstyle_a['height']);
                 $imgevents = wppa_get_imgevents('thumb', $image['id'], true);
                 $title = $link ? esc_attr(stripslashes($link['title'])) : '';
                 $widget_content .= wppa_get_the_widget_thumb('lasten', $image, $album, $display, $link, $title, $imgurl, $imgstyle_a, $imgevents);
                 $widget_content .= "\n\t" . '<div style="font-size:' . $wppa_opt['wppa_fontsize_widget_thumb'] . 'px; line-height:' . $lineheight . 'px;">';
                 if ($timesince == 'yes') {
                     $widget_content .= "\n\t" . '<div>' . wppa_get_time_since($image['timestamp']) . '</div>';
                 }
                 $widget_content .= '</div>';
             } else {
                 // No image
                 $widget_content .= __a('Photo not found.', 'wppa_theme');
             }
             $widget_content .= "\n" . '</div>';
             $count++;
             if ($count == $wppa_opt['wppa_lasten_count']) {
                 break;
             }
         }
     } else {
         $widget_content .= 'There are no uploaded photos (yet).';
     }
     $widget_content .= '<div style="clear:both"></div>';
     $widget_content .= "\n" . '<!-- WPPA+ LasTen Widget end -->';
     echo "\n" . $before_widget;
     if (!empty($widget_title)) {
         echo $before_title . $widget_title . $after_title;
     }
     echo $widget_content . $after_widget;
     $wppa['in_widget'] = false;
 }
function wppa_do_maintenance_popup($slug)
{
    global $wpdb;
    global $wppa_log_file;
    // Open wrapper with dedicated styles
    $result = '<div' . ' id="wppa-maintenance-list"' . ' >' . '<style' . ' tyle="text/css"' . ' >' . '#wppa-maintenance-list h2 {' . 'margin-top:0;' . '}' . '#wppa-maintenance-list div {' . 'background-color:#f1f1f1; border:1px solid #ddd;' . '}' . '#wppa-maintenance-list td, #wppa-maintenance-list th {' . 'border-right: 1px solid darkgray;' . '}' . '</style>';
    switch ($slug) {
        // List the search index table
        case 'wppa_list_index':
            $start = get_option('wppa_list_index_display_start', '');
            $total = $wpdb->get_var("SELECT COUNT(*) FROM `" . WPPA_INDEX . "`");
            $indexes = $wpdb->get_results($wpdb->prepare("SELECT * FROM `" . WPPA_INDEX . "` WHERE `slug` >= %s ORDER BY `slug` LIMIT 1000", $start), ARRAY_A);
            $result .= '<h2>' . sprintf(__('List of Searcheable words <small>( Max 1000 entries of total %d )</small>', 'wp-photo-album-plus'), $total) . '</h2>' . '<div' . ' style="float:left; clear:both; width:100%; overflow:auto;"' . ' >';
            if ($indexes) {
                $result .= '
				<table>
					<thead>
						<tr>
							<th><span style="float:left;" >Word</span></th>
							<th style="max-width:400px;" ><span style="float:left;" >Albums</span></th>
							<th><span style="float:left;" >Photos</span></th>
						</tr>
						<tr><td colspan="3"><hr /></td></tr>
					</thead>
					<tbody>';
                foreach ($indexes as $index) {
                    $result .= '
						<tr>
							<td>' . $index['slug'] . '</td>
							<td style="max-width:400px; word-wrap: break-word;" >' . $index['albums'] . '</td>
							<td>' . $index['photos'] . '</td>
						</tr>';
                }
                $result .= '
					</tbody>
				</table>';
            } else {
                $result .= __('There are no index items.', 'wp-photo-album-plus');
            }
            $result .= '
				</div><div style="clear:both;"></div>';
            break;
        case 'wppa_list_errorlog':
            $result .= '<h2>' . __('List of WPPA+ log messages', 'wp-photo-album-plus') . '</h2>' . '<div style="float:left; clear:both; width:100%; overflow:auto; word-wrap:none;" >';
            if (!($file = @fopen($wppa_log_file, 'r'))) {
                $result .= __('There are no error log messages', 'wp-photo-album-plus');
            } else {
                $size = filesize($wppa_log_file);
                $data = fread($file, $size);
                $data = htmlspecialchars(strip_tags($data));
                $data = str_replace(array('{b}', '{/b}', "\n"), array('<b>', '</b>', '<br />'), $data);
                $result .= $data;
                fclose($file);
            }
            $result .= '
				</div><div style="clear:both;"></div>
				';
            break;
        case 'wppa_list_rating':
            $total = $wpdb->get_var("SELECT COUNT(*) FROM `" . WPPA_RATING . "`");
            $ratings = $wpdb->get_results("SELECT * FROM `" . WPPA_RATING . "` ORDER BY `timestamp` DESC LIMIT 1000", ARRAY_A);
            $result .= '<h2>' . sprintf(__('List of recent ratings <small>( Max 1000 entries of total %d )</small>', 'wp-photo-album-plus'), $total) . '</h2>' . '<div' . ' style="float:left; clear:both; width:100%; overflow:auto;"' . ' >';
            if ($ratings) {
                $result .= '
				<table>
					<thead>
						<tr>
							<th>Id</th>
							<th>Timestamp</th>
							<th>Date/time</th>
							<th>Status</th>
							<th>User</th>
							<th>Value</th>
							<th>Photo id</th>
							<th></th>
							<th># ratings</th>
							<th>Average</th>
						</tr>
						<tr><td colspan="10"><hr /></td></tr>
					</thead>
					<tbody>';
                foreach ($ratings as $rating) {
                    $thumb = wppa_cache_thumb($rating['photo']);
                    $result .= '
						<tr>
							<td>' . $rating['id'] . '</td>
							<td>' . $rating['timestamp'] . '</td>
							<td>' . ($rating['timestamp'] ? wppa_local_date(get_option('date_format', "F j, Y,") . ' ' . get_option('time_format', "g:i a"), $rating['timestamp']) : 'pre-historic') . '</td>
							<td>' . $rating['status'] . '</td>
							<td>' . $rating['user'] . '</td>
							<td>' . $rating['value'] . '</td>
							<td>' . $rating['photo'] . '</td>
							<td style="width:250px; text-align:center;"><img src="' . wppa_get_thumb_url($rating['photo']) . '"
								style="height: 40px;"
								onmouseover="jQuery(this).stop().animate({height:this.naturalHeight}, 200);"
								onmouseout="jQuery(this).stop().animate({height:\'40px\'}, 200);" /></td>
							<td>' . $thumb['rating_count'] . '</td>
							<td>' . $thumb['mean_rating'] . '</td>
						</tr>';
                }
                $result .= '
					</tbody>
				</table>';
            } else {
                $result .= __('There are no ratings', 'wp-photo-album-plus');
            }
            $result .= '
				</div><div style="clear:both;"></div>';
            break;
        case 'wppa_list_session':
            $total = $wpdb->get_var("SELECT COUNT(*) FROM `" . WPPA_SESSION . "`");
            $sessions = $wpdb->get_results("SELECT * FROM `" . WPPA_SESSION . "` ORDER BY `id` DESC LIMIT 1000", ARRAY_A);
            $result .= '<h2>' . sprintf(__('List of sessions <small>( Max 1000 entries of total %d )</small>', 'wp-photo-album-plus'), $total) . '</h2>' . '<div' . ' style="float:left; clear:both; width:100%; overflow:auto;"' . ' >';
            if ($sessions) {
                $result .= '
				<table>
					<thead>
						<tr>
							<th>Id</th>

							<th>IP</th>
							<th>Started</th>
							<th>Count</th>
							<th>Status</th>
							<th>Data</th>
							<th>Uris</th>
						</tr>
						<tr><td colspan="7"><hr /></td></tr>
					</thead>
					<tbody style="overflow:auto;" >';
                foreach ($sessions as $session) {
                    $data = unserialize($session['data']);
                    $result .= '
							<tr>
								<td>' . $session['id'] . '</td>

								<td>' . (strlen($session['ip']) > 15 ? substr($session['ip'], 0, 12) . '...' : $session['ip']) . '</td>
								<td style="width:150px;" >' . wppa_local_date(get_option('date_format', "F j, Y,") . ' ' . get_option('time_format', "g:i a"), $session['timestamp']) . '</td>
								<td>' . $session['count'] . '</td>' . '<td>' . $session['status'] . '</td>' . '<td style="border-bottom:1px solid gray;max-width:300px;" >';
                    if (is_array($data)) {
                        foreach (array_keys($data) as $key) {
                            if ($key != 'uris') {
                                if (is_array($data[$key])) {
                                    $result .= '[' . $key . '] => Array(' . implode(',', array_keys($data[$key])) . ')<br />';
                                } else {
                                    $result .= '[' . $key . '] => ' . $data[$key] . '<br />';
                                }
                            }
                        }
                    }
                    $result .= '
								</td>
								<td style="border-bottom:1px solid gray;" >';
                    if (is_array($data['uris'])) {
                        foreach ($data['uris'] as $uri) {
                            $result .= $uri . '<br />';
                        }
                    }
                    $result .= '
								</td>
							</tr>';
                }
                $result .= '
					</tbody>
				</table>';
            } else {
                $result .= __('There are no active sessions', 'wp-photo-album-plus');
            }
            $result .= '
				</div><div style="clear:both;"></div>';
            break;
        case 'wppa_list_comments':
            $total = $wpdb->get_var("SELECT COUNT(*) FROM `" . WPPA_COMMENTS . "`");
            $order = wppa_opt('list_comments_by');
            if ($order == 'timestamp') {
                $order .= ' DESC';
            }
            if ($order == 'name') {
                $order = 'user';
            }
            $query = "SELECT * FROM `" . WPPA_COMMENTS . "` ORDER BY " . $order . " LIMIT 1000";
            //	$result .= $query.'<br />';
            $comments = $wpdb->get_results($query, ARRAY_A);
            $result .= '<h2>' . sprintf(__('List of comments <small>( Max 1000 entries of total %d )</small>', 'wp-photo-album-plus'), $total) . '</h2>' . '<div style="float:left; clear:both; width:100%; overflow:auto;" >';
            if ($comments) {
                $result .= '
				<table>
					<thead>
						<tr>
							<th>Id</th>
							<th>Timestamp</th>
							<th>Date/time</th>
							<th>Status</th>
							<th>User</th>
							<th>Email</th>
							<th>Photo id</th>
							<th></th>
							<th>Comment</th>
						</tr>
						<tr><td colspan="10"><hr /></td></tr>
					</thead>
					<tbody>';
                foreach ($comments as $comment) {
                    $thumb = wppa_cache_thumb($comment['photo']);
                    $result .= '
						<tr>
							<td>' . $comment['id'] . '</td>
							<td>' . $comment['timestamp'] . '</td>
							<td>' . ($comment['timestamp'] ? wppa_local_date(get_option('date_format', "F j, Y,") . ' ' . get_option('time_format', "g:i a"), $comment['timestamp']) : 'pre-historic') . '</td>
							<td>' . $comment['status'] . '</td>
							<td>' . $comment['user'] . '</td>
							<td>' . $comment['email'] . '</td>
							<td>' . $comment['photo'] . '</td>
							<td style="width:250px; text-align:center;"><img src="' . wppa_get_thumb_url($comment['photo']) . '"
								style="height: 40px;"
								onmouseover="jQuery(this).stop().animate({height:this.naturalHeight}, 200);"
								onmouseout="jQuery(this).stop().animate({height:\'40px\'}, 200);" /></td>
							<td>' . $comment['comment'] . '</td>
						</tr>';
                }
                $result .= '
					</tbody>
				</table>';
            } else {
                $result .= __('There are no comments', 'wp-photo-album-plus');
                $result .= '<br />Query=' . $wpdb->prepare("SELECT * FROM `" . WPPA_COMMENTS . "` ORDER BY %s DESC LIMIT 1000", wppa_opt('list_comments_by'));
            }
            $result .= '
				</div><div style="clear:both;"></div>';
            break;
        default:
            $result = 'Error: Unimplemented slug: ' . $slug . ' in wppa_do_maintenance_popup()';
    }
    $result .= '</div>';
    return $result;
}
 /** @see WP_Widget::widget */
 function widget($args, $instance)
 {
     global $wpdb;
     require_once dirname(__FILE__) . '/wppa-links.php';
     require_once dirname(__FILE__) . '/wppa-styles.php';
     require_once dirname(__FILE__) . '/wppa-functions.php';
     require_once dirname(__FILE__) . '/wppa-thumbnails.php';
     require_once dirname(__FILE__) . '/wppa-boxes-html.php';
     require_once dirname(__FILE__) . '/wppa-slideshow.php';
     wppa_initialize_runtime();
     wppa('in_widget', 'topten');
     wppa_bump_mocc();
     extract($args);
     $instance = wp_parse_args((array) $instance, array('title' => '', 'sortby' => 'mean_rating', 'title' => '', 'album' => '', 'display' => 'thumbs', 'meanrat' => 'yes', 'ratcount' => 'yes', 'viewcount' => 'yes', 'includesubs' => 'yes', 'showowner' => 'no', 'showalbum' => 'no'));
     $widget_title = apply_filters('widget_title', $instance['title']);
     $page = in_array(wppa_opt('topten_widget_linktype'), wppa('links_no_page')) ? '' : wppa_get_the_landing_page('wppa_topten_widget_linkpage', __('Top Ten Photos', 'wp-photo-album-plus'));
     $albumlinkpage = wppa_get_the_landing_page('wppa_topten_widget_album_linkpage', __('Top Ten Photo album', 'wp-photo-album-plus'));
     $max = wppa_opt('topten_count');
     $album = $instance['album'];
     switch ($instance['sortby']) {
         case 'mean_rating':
             $sortby = '`mean_rating` DESC, `rating_count` DESC, `views` DESC';
             break;
         case 'rating_count':
             $sortby = '`rating_count` DESC, `mean_rating` DESC, `views` DESC';
             break;
         case 'views':
             $sortby = '`views` DESC, `mean_rating` DESC, `rating_count` DESC';
             break;
     }
     $display = $instance['display'];
     $meanrat = $instance['meanrat'] == 'yes';
     $ratcount = $instance['ratcount'] == 'yes';
     $viewcount = $instance['viewcount'] == 'yes';
     $includesubs = $instance['includesubs'] == 'yes';
     $albenum = '';
     $showowner = $instance['showowner'] == 'yes';
     $showalbum = $instance['showalbum'] == 'yes';
     if ($album) {
         if ($album == '-2') {
             $album = '0';
         }
         if ($includesubs) {
             $albenum = wppa_alb_to_enum_children($album);
             $albenum = wppa_expand_enum($albenum);
             $album = str_replace('.', ',', $albenum);
         }
         $thumbs = $wpdb->get_results("SELECT * FROM `" . WPPA_PHOTOS . "` WHERE `album` IN (" . $album . ") ORDER BY " . $sortby . " LIMIT " . $max, ARRAY_A);
         //wppa_log('dbg', "SELECT * FROM `".WPPA_PHOTOS."` WHERE `album` IN (".$album.") ORDER BY " . $sortby . " LIMIT " . $max);
     } else {
         $thumbs = $wpdb->get_results("SELECT * FROM `" . WPPA_PHOTOS . "` ORDER BY " . $sortby . " LIMIT " . $max, ARRAY_A);
     }
     $widget_content = "\n" . '<!-- WPPA+ TopTen Widget start -->';
     $maxw = wppa_opt('topten_size');
     $maxh = $maxw;
     $lineheight = wppa_opt('fontsize_widget_thumb') * 1.5;
     $maxh += $lineheight;
     if ($meanrat) {
         $maxh += $lineheight;
     }
     if ($ratcount) {
         $maxh += $lineheight;
     }
     if ($viewcount) {
         $maxh += $lineheight;
     }
     if ($showowner) {
         $maxh += $lineheight;
     }
     if ($showalbum) {
         $maxh += $lineheight;
     }
     if ($thumbs) {
         foreach ($thumbs as $image) {
             $thumb = $image;
             // Make the HTML for current picture
             if ($display == 'thumbs') {
                 $widget_content .= "\n" . '<div class="wppa-widget" style="width:' . $maxw . 'px; height:' . $maxh . 'px; margin:4px; display:inline; text-align:center; float:left;">';
             } else {
                 $widget_content .= "\n" . '<div class="wppa-widget" >';
             }
             if ($image) {
                 $no_album = !$album;
                 if ($no_album) {
                     $tit = __('View the top rated photos', 'wp-photo-album-plus');
                 } else {
                     $tit = esc_attr(__(stripslashes($image['description'])));
                 }
                 $compressed_albumenum = wppa_compress_enum($albenum);
                 $link = wppa_get_imglnk_a('topten', $image['id'], '', $tit, '', $no_album, $compressed_albumenum);
                 $file = wppa_get_thumb_path($image['id']);
                 $imgstyle_a = wppa_get_imgstyle_a($image['id'], $file, $maxw, 'center', 'ttthumb');
                 $imgurl = wppa_get_thumb_url($image['id'], '', $imgstyle_a['width'], $imgstyle_a['height']);
                 $imgevents = wppa_get_imgevents('thumb', $image['id'], true);
                 $title = $link ? esc_attr(stripslashes($link['title'])) : '';
                 $widget_content .= wppa_get_the_widget_thumb('topten', $image, $album, $display, $link, $title, $imgurl, $imgstyle_a, $imgevents);
                 $widget_content .= "\n\t" . '<div style="font-size:' . wppa_opt('fontsize_widget_thumb') . 'px; line-height:' . $lineheight . 'px;">';
                 // Display (owner) ?
                 if ($showowner) {
                     $widget_content .= '<div>(' . $image['owner'] . ')</div>';
                 }
                 // Display (album) ?
                 if ($showalbum) {
                     $href = wppa_convert_to_pretty(wppa_get_album_url($image['album'], $albumlinkpage, 'content', '1'));
                     $widget_content .= '<div>(<a href="' . $href . '" >' . wppa_get_album_name($image['album']) . '</a>)</div>';
                 }
                 $rating = wppa_get_rating_by_id($image['id']);
                 switch ($instance['sortby']) {
                     case 'mean_rating':
                         if ($meanrat == 'yes') {
                             $widget_content .= '<div>' . wppa_get_rating_by_id($image['id']) . '</div>';
                         }
                         if ($ratcount == 'yes') {
                             $widget_content .= '<div>' . sprintf(__('%s Votes', 'wp-photo-album-plus'), wppa_get_rating_count_by_id($image['id'])) . '</div>';
                         }
                         if ($viewcount == 'yes' && $image['views']) {
                             $widget_content .= '<div>' . sprintf(__('Views: %s times', 'wp-photo-album-plus'), $image['views']) . '</div>';
                         }
                         break;
                     case 'rating_count':
                         if ($ratcount == 'yes') {
                             $widget_content .= '<div>' . sprintf(__('%s Votes', 'wp-photo-album-plus'), wppa_get_rating_count_by_id($image['id'])) . '</div>';
                         }
                         if ($meanrat == 'yes') {
                             $widget_content .= '<div>' . wppa_get_rating_by_id($image['id']) . '</div>';
                         }
                         if ($viewcount == 'yes' && $image['views']) {
                             $widget_content .= '<div>' . sprintf(__('Views: %s times', 'wp-photo-album-plus'), $image['views']) . '</div>';
                         }
                         break;
                     case 'views':
                         if ($viewcount == 'yes' && $image['views']) {
                             $widget_content .= '<div>' . sprintf(__('Views: %s times', 'wp-photo-album-plus'), $image['views']) . '</div>';
                         }
                         if ($meanrat == 'yes') {
                             $widget_content .= '<div>' . wppa_get_rating_by_id($image['id']) . '</div>';
                         }
                         if ($ratcount == 'yes') {
                             $widget_content .= '<div>' . sprintf(__('%s Votes', 'wp-photo-album-plus'), wppa_get_rating_count_by_id($image['id'])) . '</div>';
                         }
                         break;
                 }
                 $widget_content .= '</div>';
             } else {
                 // No image
                 $widget_content .= __('Photo not found.', 'wp-photo-album-plus');
             }
             $widget_content .= "\n" . '</div>';
         }
     } else {
         $widget_content .= 'There are no rated photos (yet).';
     }
     $widget_content .= '<div style="clear:both"></div>';
     $widget_content .= "\n" . '<!-- WPPA+ TopTen Widget end -->';
     echo "\n" . $before_widget;
     if (!empty($widget_title)) {
         echo $before_title . $widget_title . $after_title;
     }
     echo $widget_content . $after_widget;
     wppa('in_widget', false);
 }
 /** @see WP_Widget::widget */
 function widget($args, $instance)
 {
     global $wpdb;
     global $wppa_opt;
     global $wppa;
     require_once dirname(__FILE__) . '/wppa-links.php';
     require_once dirname(__FILE__) . '/wppa-styles.php';
     require_once dirname(__FILE__) . '/wppa-functions.php';
     require_once dirname(__FILE__) . '/wppa-thumbnails.php';
     require_once dirname(__FILE__) . '/wppa-boxes-html.php';
     require_once dirname(__FILE__) . '/wppa-slideshow.php';
     wppa_initialize_runtime();
     extract($args);
     $instance = wp_parse_args((array) $instance, array('title' => '', 'album' => ''));
     $widget_title = apply_filters('widget_title', $instance['title']);
     $page = in_array($wppa_opt['wppa_featen_widget_linktype'], $wppa['links_no_page']) ? '' : wppa_get_the_landing_page('wppa_featen_widget_linkpage', __a('Featured photos'));
     $max = $wppa_opt['wppa_featen_count'];
     $album = $instance['album'];
     $generic = $album == '-2';
     if ($generic) {
         $album = '0';
         $max += '1000';
     }
     if ($album) {
         $thumbs = $wpdb->get_results($wpdb->prepare("SELECT * FROM `" . WPPA_PHOTOS . "` WHERE `status`= 'featured' AND `album` = %s ORDER BY RAND(" . wppa_get_randseed() . ") DESC LIMIT " . $max, $album), ARRAY_A);
     } else {
         $thumbs = $wpdb->get_results("SELECT * FROM `" . WPPA_PHOTOS . "` WHERE `status` = 'featured' ORDER BY RAND(" . wppa_get_randseed() . ") DESC LIMIT " . $max, ARRAY_A);
     }
     $widget_content = "\n" . '<!-- WPPA+ FeaTen Widget start -->';
     $maxw = $wppa_opt['wppa_featen_size'];
     $maxh = $maxw;
     $lineheight = $wppa_opt['wppa_fontsize_widget_thumb'] * 1.5;
     $maxh += $lineheight;
     if (false) {
         $maxh += $lineheight;
     }
     $count = '0';
     if ($thumbs) {
         foreach ($thumbs as $image) {
             global $thumb;
             $thumb = $image;
             if ($generic && wppa_is_separate($thumb['album'])) {
                 continue;
             }
             // Make the HTML for current picture
             $widget_content .= "\n" . '<div class="wppa-widget" style="width:' . $maxw . 'px; height:' . $maxh . 'px; margin:4px; display:inline; text-align:center; float:left;">';
             if ($image) {
                 $no_album = !$album;
                 if ($no_album) {
                     $tit = __a('View the featured photos', 'wppa_theme');
                 } else {
                     $tit = esc_attr(wppa_qtrans(stripslashes($image['description'])));
                 }
                 $link = wppa_get_imglnk_a('featen', $image['id'], '', $tit, '', $no_album);
                 $file = wppa_get_thumb_path($image['id']);
                 $imgstyle_a = wppa_get_imgstyle_a($image['id'], $file, $maxw, 'center', 'ttthumb');
                 $imgstyle = $imgstyle_a['style'];
                 $width = $imgstyle_a['width'];
                 $height = $imgstyle_a['height'];
                 $cursor = $imgstyle_a['cursor'];
                 $imgurl = wppa_get_thumb_url($image['id'], '', $width, $height);
                 $imgevents = wppa_get_imgevents('thumb', $image['id'], true);
                 if ($link) {
                     $title = esc_attr(stripslashes($link['title']));
                 } else {
                     $title = '';
                 }
                 $album = '0';
                 $display = 'thumbs';
                 $widget_content .= wppa_get_the_widget_thumb('featen', $image, $album, $display, $link, $title, $imgurl, $imgstyle_a, $imgevents);
             } else {
                 // No image
                 $widget_content .= __a('Photo not found.', 'wppa_theme');
             }
             $widget_content .= "\n" . '</div>';
             $count++;
             if ($count == $wppa_opt['wppa_featen_count']) {
                 break;
             }
         }
     } else {
         $widget_content .= 'There are no featured photos (yet).';
     }
     $widget_content .= '<div style="clear:both"></div>';
     $widget_content .= "\n" . '<!-- WPPA+ FeaTen Widget end -->';
     echo "\n" . $before_widget;
     if (!empty($widget_title)) {
         echo $before_title . $widget_title . $after_title;
     }
     echo $widget_content . $after_widget;
 }
function wppa_album_cover_longdesc($albumid, $multicolresp = false)
{
    global $wppa;
    global $cover_count_key;
    global $wpdb;
    $album = wppa_cache_album($albumid);
    if ($multicolresp) {
        $mcr = 'mcr-';
    } else {
        $mcr = '';
    }
    $coverphoto = wppa_get_coverphoto_id($albumid);
    $image = $wpdb->get_row($wpdb->prepare("SELECT * FROM `" . WPPA_PHOTOS . "` WHERE `id` = %s", $coverphoto), ARRAY_A);
    $photocount = wppa_get_photo_count($albumid, true);
    $albumcount = wppa_get_album_count($albumid, true);
    $mincount = wppa_get_mincount();
    $title = '';
    $linkpage = '';
    $href_title = '';
    $href_slideshow = '';
    $href_content = '';
    $onclick_title = '';
    $onclick_slideshow = '';
    $onclick_content = '';
    // See if there is substantial content to the album
    $has_content = $albumcount > '0' || $photocount > $mincount;
    // What is the albums title linktype
    $linktype = $album['cover_linktype'];
    if (!$linktype) {
        $linktype = 'content';
    }
    // Default
    // What is the albums title linkpage
    $linkpage = $album['cover_linkpage'];
    if ($linkpage == '-1') {
        $linktype = 'none';
    }
    // for backward compatibility
    // Find the cover title href, onclick and title
    $title_attr = wppa_get_album_title_attr_a($albumid, $linktype, $linkpage, $has_content, $coverphoto, $photocount);
    $href_title = $title_attr['href'];
    $onclick_title = $title_attr['onclick'];
    $title = $title_attr['title'];
    // Find the slideshow link and onclick
    $href_slideshow = wppa_convert_to_pretty(wppa_get_slideshow_url($albumid, $linkpage));
    if (wppa_switch('wppa_allow_ajax') && !$linkpage) {
        $onclick_slideshow = "wppaDoAjaxRender( " . $wppa['mocc'] . ", '" . wppa_get_slideshow_url_ajax($albumid, $linkpage) . "', '" . wppa_convert_to_pretty($href_slideshow) . "' )";
        $href_slideshow = "#";
    }
    // Find the content 'View' link
    $href_content = wppa_convert_to_pretty(wppa_get_album_url($albumid, $linkpage));
    if (wppa_switch('wppa_allow_ajax') && !$linkpage) {
        $onclick_content = "wppaDoAjaxRender( " . $wppa['mocc'] . ", '" . wppa_get_album_url_ajax($albumid, $linkpage) . "', '" . wppa_convert_to_pretty($href_content) . "' )";
        $href_content = "#";
    }
    // Find the coverphoto link
    if ($coverphoto) {
        $photolink = wppa_get_imglnk_a('coverimg', $coverphoto, $href_title, $title, $onclick_title, '', $albumid);
    } else {
        $photolink = false;
    }
    // Find the coverphoto details
    if ($coverphoto) {
        $path = wppa_get_thumb_path($coverphoto);
        $imgattr_a = wppa_get_imgstyle_a($coverphoto, $path, wppa_opt('wppa_smallsize'), '', 'cover');
        $src = wppa_get_thumb_url($coverphoto, '', $imgattr_a['width'], $imgattr_a['height']);
    } else {
        $path = '';
        $imgattr_a = false;
        $src = '';
    }
    // Feed?
    if (is_feed()) {
        $events = '';
    } else {
        $events = wppa_get_imgevents('cover');
    }
    $photo_pos = $wppa['coverphoto_pos'];
    $style = __wcs('wppa-box') . __wcs('wppa-' . wppa('alt'));
    if (is_feed()) {
        $style .= ' padding:7px;';
    }
    $wid = wppa_get_cover_width('cover');
    $style .= 'width: ' . $wid . 'px;';
    if ($cover_count_key == 'm') {
        $style .= 'margin-left: 8px;';
    } elseif ($cover_count_key == 'r') {
        $style .= 'float:right;';
    } else {
        $style .= 'clear:both;';
    }
    wppa_step_covercount('cover');
    $target = wppa_switch('wppa_allow_ajax') ? '_self' : $photolink['target'];
    // Open the album box
    $wppa['out'] .= wppa_nltab('+') . '<div id="album-' . $albumid . '-' . $wppa['mocc'] . '" class="wppa-album-cover-longdesc album wppa-box wppa-cover-box wppa-cover-box-' . $mcr . $wppa['mocc'] . ' wppa-' . wppa('alt') . '" style="' . $style . __wcs('wppa-cover-box') . '" >';
    // First The Cover photo?
    if ($photo_pos == 'left' || $photo_pos == 'top') {
        wppa_the_coverphoto($albumid, $image, $src, $photo_pos, $photolink, $title, $imgattr_a, $events);
    }
    // Open the Cover text frame
    $textframestyle = wppa_get_text_frame_style($photo_pos, 'cover');
    $wppa['out'] .= wppa_nltab('+') . '<div id="covertext_frame_' . $albumid . '_' . $wppa['mocc'] . '" class="wppa-text-frame-' . $wppa['mocc'] . ' wppa-text-frame wppa-cover-text-frame wppa-asym-text-frame-' . $mcr . $wppa['mocc'] . '" ' . $textframestyle . '>';
    // The Album title
    wppa_the_album_title($albumid, $href_title, $onclick_title, $title, $target);
    // The 'Slideshow'/'Browse' link
    wppa_the_slideshow_browse_link($photocount, $href_slideshow, $onclick_slideshow, $target);
    // The 'View' link
    wppa_album_cover_view_link($albumid, $has_content, $photocount, $albumcount, $mincount, $href_content, $target, $onclick_content);
    // Close the Cover text frame
    $wppa['out'] .= wppa_nltab('-') . '</div><!-- covertext-frame -->';
    // The Cover photo last?
    if ($photo_pos == 'right' || $photo_pos == 'bottom') {
        wppa_the_coverphoto($albumid, $image, $src, $photo_pos, $photolink, $title, $imgattr_a, $events);
    }
    // The Album description
    if (wppa_switch('wppa_show_cover_text')) {
        $textheight = wppa_opt('wppa_text_frame_height') > '0' ? 'min-height:' . wppa_opt('wppa_text_frame_height') . 'px; ' : '';
        $wppa['out'] .= wppa_nltab() . '<div id="coverdesc_frame_' . $albumid . '_' . $wppa['mocc'] . '" style="clear:both" ><p class="wppa-box-text wppa-black wppa-box-text-desc" style="' . $textheight . __wcs('wppa-box-text') . __wcs('wppa-black') . '">' . wppa_get_album_desc($albumid) . '</p></div>';
    }
    // The sublinks
    wppa_albumcover_sublinks($albumid, wppa_get_cover_width('cover'), $multicolresp);
    // Prepare for closing
    $wppa['out'] .= wppa_nltab() . '<div style="clear:both;"></div>';
    // Close the album box
    $wppa['out'] .= wppa_nltab('-') . '</div><!-- #album-' . $albumid . '-' . $wppa['mocc'] . ' -->';
    // Toggle alt/even
    wppa_toggle_alt();
}
 /** @see WP_Widget::widget */
 function widget($args, $instance)
 {
     global $wpdb;
     global $wppa;
     global $thumb;
     require_once dirname(__FILE__) . '/wppa-links.php';
     require_once dirname(__FILE__) . '/wppa-styles.php';
     require_once dirname(__FILE__) . '/wppa-functions.php';
     require_once dirname(__FILE__) . '/wppa-thumbnails.php';
     require_once dirname(__FILE__) . '/wppa-boxes-html.php';
     require_once dirname(__FILE__) . '/wppa-slideshow.php';
     wppa_initialize_runtime();
     $wppa['in_widget'] = 'alb';
     $wppa['mocc']++;
     extract($args);
     $instance = wp_parse_args((array) $instance, array('title' => '', 'parent' => 'none', 'name' => 'no', 'skip' => 'yes'));
     $widget_title = apply_filters('widget_title', $instance['title']);
     $page = in_array(wppa_opt('wppa_album_widget_linktype'), $wppa['links_no_page']) ? '' : wppa_get_the_landing_page('wppa_album_widget_linkpage', __a('Photo Albums'));
     $max = wppa_opt('wppa_album_widget_count');
     if (!$max) {
         $max = '10';
     }
     $parent = $instance['parent'];
     $name = $instance['name'];
     $skip = $instance['skip'];
     if (is_numeric($parent)) {
         $albums = $wpdb->get_results($wpdb->prepare('SELECT * FROM `' . WPPA_ALBUMS . '` WHERE `a_parent` = %s ' . wppa_get_album_order($parent), $parent), ARRAY_A);
     } else {
         switch ($parent) {
             case 'all':
                 $albums = $wpdb->get_results('SELECT * FROM `' . WPPA_ALBUMS . '` ' . wppa_get_album_order(), ARRAY_A);
                 break;
             case 'last':
                 $albums = $wpdb->get_results('SELECT * FROM `' . WPPA_ALBUMS . '` ORDER BY `timestamp` DESC', ARRAY_A);
                 break;
             default:
                 wppa_dbg_msg('Error, unimplemented album selection: ' . $parent . ' in Album widget.', 'red', true);
         }
     }
     $widget_content = "\n" . '<!-- WPPA+ album Widget start -->';
     $maxw = wppa_opt('wppa_album_widget_size');
     $maxh = $maxw;
     if ($name == 'yes') {
         $maxh += 18;
     }
     $count = 0;
     if ($albums) {
         foreach ($albums as $album) {
             if ($count < $max) {
                 global $thumb;
                 $imageid = wppa_get_coverphoto_id($album['id']);
                 $image = $wpdb->get_row($wpdb->prepare('SELECT * FROM `' . WPPA_PHOTOS . '` WHERE `id` = %s', $imageid), ARRAY_A);
                 $imgcount = $wpdb->get_var($wpdb->prepare('SELECT COUNT(*) FROM ' . WPPA_PHOTOS . ' WHERE `album` = %s', $album['id']));
                 $subalbumcount = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM `" . WPPA_ALBUMS . "` WHERE `a_parent` = %s", $album['id']));
                 $thumb = $image;
                 // Make the HTML for current picture
                 if ($image && ($imgcount > wppa_opt('wppa_min_thumbs') || $subalbumcount)) {
                     $link = wppa_get_imglnk_a('albwidget', $image['id']);
                     $file = wppa_get_thumb_path($image['id']);
                     $imgevents = wppa_get_imgevents('thumb', $image['id'], true);
                     $imgstyle_a = wppa_get_imgstyle_a($image['id'], $file, $maxw, 'center', 'albthumb');
                     $imgstyle = $imgstyle_a['style'];
                     $width = $imgstyle_a['width'];
                     $height = $imgstyle_a['height'];
                     $cursor = $imgstyle_a['cursor'];
                     if (wppa_switch('wppa_show_albwidget_tooltip')) {
                         $title = esc_attr(strip_tags(wppa_get_album_desc($album['id'])));
                     } else {
                         $title = '';
                     }
                     $imgurl = wppa_get_thumb_url($image['id'], '', $width, $height);
                 } else {
                     $link = '';
                     $file = '';
                     $imgevents = '';
                     $imgstyle = 'width:' . $maxw . ';height:' . $maxh . ';';
                     $width = $maxw;
                     $height = $maxw;
                     // !!
                     $cursor = 'default';
                     $title = sprintf(__a('Upload at least %d photos to this album!', 'wppa_theme'), wppa_opt('wppa_min_thumbs') - $imgcount + 1);
                     if ($imageid) {
                         // The 'empty album has a cover image
                         $file = wppa_get_thumb_path($image['id']);
                         $imgstyle_a = wppa_get_imgstyle_a($image['id'], $file, $maxw, 'center', 'albthumb');
                         $imgstyle = $imgstyle_a['style'];
                         $width = $imgstyle_a['width'];
                         $height = $imgstyle_a['height'];
                         $imgurl = wppa_get_thumb_url($image['id'], '', $width, $height);
                     } else {
                         $imgurl = wppa_get_imgdir() . 'album32.png';
                     }
                 }
                 $imgurl = wppa_fix_poster_ext($imgurl, $image['id']);
                 if ($imgcount > wppa_opt('wppa_min_thumbs') || $skip == 'no') {
                     $widget_content .= "\n" . '<div class="wppa-widget" style="width:' . $maxw . 'px; height:' . $maxh . 'px; margin:4px; display:inline; text-align:center; float:left;">';
                     if ($link) {
                         if ($link['is_url']) {
                             // Is a href
                             $widget_content .= "\n\t" . '<a href="' . $link['url'] . '" title="' . $title . '" target="' . $link['target'] . '" >';
                             if (wppa_is_video($image['id'])) {
                                 $widget_content .= wppa_get_video_html(array('id' => $image['id'], 'width' => $width, 'height' => $height, 'controls' => false, 'margin_top' => $imgstyle_a['margin-top'], 'margin_bottom' => $imgstyle_a['margin-bottom'], 'cursor' => 'pointer', 'events' => $imgevents, 'tagid' => 'i-' . $image['id'] . '-' . $wppa['mocc'], 'title' => $title));
                             } else {
                                 $widget_content .= "\n\t\t" . '<img id="i-' . $image['id'] . '-' . $wppa['mocc'] . '" title="' . $title . '" src="' . $imgurl . '" width="' . $width . '" height="' . $height . '" style="' . $imgstyle . ' cursor:pointer;" ' . $imgevents . ' ' . wppa_get_imgalt($image['id']) . ' >';
                             }
                             $widget_content .= "\n\t" . '</a>';
                         } elseif ($link['is_lightbox']) {
                             $thumbs = $wpdb->get_results($wpdb->prepare("SELECT * FROM `" . WPPA_PHOTOS . "` WHERE `album` = %s " . wppa_get_photo_order($album['id']), $album['id']), 'ARRAY_A');
                             if ($thumbs) {
                                 foreach ($thumbs as $thumb) {
                                     $title = wppa_get_lbtitle('alw', $thumb['id']);
                                     if (wppa_is_video($thumb['id'])) {
                                         $siz['0'] = wppa_get_videox($thumb['id']);
                                         $siz['1'] = wppa_get_videoy($thumb['id']);
                                     } else {
                                         //	$siz = getimagesize( wppa_get_photo_path( $thumb['id'] ) );
                                         $siz['0'] = wppa_get_photox($thumb['id']);
                                         $siz['1'] = wppa_get_photoy($thumb['id']);
                                     }
                                     $link = wppa_fix_poster_ext(wppa_get_photo_url($thumb['id'], '', $siz['0'], $siz['1']), $thumb['id']);
                                     $is_video = wppa_is_video($thumb['id']);
                                     $has_audio = wppa_has_audio($thumb['id']);
                                     $widget_content .= "\n\t" . '<a href="' . $link . '"' . ($is_video ? ' data-videohtml="' . esc_attr(wppa_get_video_body($thumb['id'])) . '"' . ' data-videonatwidth="' . wppa_get_videox($thumb['id']) . '"' . ' data-videonatheight="' . wppa_get_videoy($thumb['id']) . '"' : '') . ($has_audio ? ' data-audiohtml="' . esc_attr(wppa_get_audio_body($thumb['id'])) . '"' : '') . ' ' . wppa('rel') . '="' . wppa_opt('wppa_lightbox_name') . '[alw-' . $wppa['mocc'] . '-' . $album['id'] . ']"' . ' ' . wppa('lbtitle') . '="' . $title . '" >';
                                     if ($thumb['id'] == $image['id']) {
                                         // the cover image
                                         if (wppa_is_video($image['id'])) {
                                             $widget_content .= wppa_get_video_html(array('id' => $image['id'], 'width' => $width, 'height' => $height, 'controls' => false, 'margin_top' => $imgstyle_a['margin-top'], 'margin_bottom' => $imgstyle_a['margin-bottom'], 'cursor' => $cursor, 'events' => $imgevents, 'tagid' => 'i-' . $image['id'] . '-' . $wppa['mocc'], 'title' => wppa_zoom_in($image['id'])));
                                         } else {
                                             $widget_content .= "\n\t\t" . '<img id="i-' . $image['id'] . '-' . $wppa['mocc'] . '" title="' . wppa_zoom_in($image['id']) . '" src="' . $imgurl . '" width="' . $width . '" height="' . $height . '" style="' . $imgstyle . $cursor . '" ' . $imgevents . ' ' . wppa_get_imgalt($image['id']) . ' >';
                                         }
                                     }
                                     $widget_content .= "\n\t" . '</a>';
                                 }
                             }
                         } else {
                             // Is an onclick unit
                             if (wppa_is_video($image['id'])) {
                                 $widget_content .= wppa_get_video_html(array('id' => $image['id'], 'width' => $width, 'height' => $height, 'controls' => false, 'margin_top' => $imgstyle_a['margin-top'], 'margin_bottom' => $imgstyle_a['margin-bottom'], 'cursor' => 'pointer', 'events' => $imgevents . ' onclick="' . $link['url'] . '"', 'tagid' => 'i-' . $image['id'] . '-' . $wppa['mocc'], 'title' => $title));
                             } else {
                                 $widget_content .= "\n\t" . '<img id="i-' . $image['id'] . '-' . $wppa['mocc'] . '" title="' . $title . '" src="' . $imgurl . '" width="' . $width . '" height="' . $height . '" style="' . $imgstyle . ' cursor:pointer;" ' . $imgevents . ' onclick="' . $link['url'] . '" ' . wppa_get_imgalt($image['id']) . ' >';
                             }
                         }
                     } else {
                         if (wppa_is_video($image['id'])) {
                             $widget_content .= wppa_get_video_html(array('id' => $image['id'], 'width' => $width, 'height' => $height, 'controls' => false, 'margin_top' => $imgstyle_a['margin-top'], 'margin_bottom' => $imgstyle_a['margin-bottom'], 'cursor' => 'pointer', 'events' => $imgevents, 'tagid' => 'i-' . $image['id'] . '-' . $wppa['mocc'], 'title' => $title));
                         } else {
                             $widget_content .= "\n\t" . '<img id="i-' . $image['id'] . '-' . $wppa['mocc'] . '" title="' . $title . '" src="' . $imgurl . '" width="' . $width . '" height="' . $height . '" style="' . $imgstyle . '" ' . $imgevents . ' ' . wppa_get_imgalt($image['id']) . ' >';
                         }
                     }
                     if ($name == 'yes') {
                         $widget_content .= "\n\t" . '<span style="font-size:' . wppa_opt('wppa_fontsize_widget_thumb') . 'px; min-height:100%;">' . __(stripslashes($album['name'])) . '</span>';
                     }
                     $widget_content .= "\n" . '</div>';
                     $count++;
                 }
             }
         }
     } else {
         $widget_content .= 'There are no albums (yet).';
     }
     $widget_content .= '<div style="clear:both"></div>';
     $widget_content .= "\n" . '<!-- WPPA+ thumbnail Widget end -->';
     echo "\n" . $before_widget;
     if (!empty($widget_title)) {
         echo $before_title . $widget_title . $after_title;
     }
     echo $widget_content . $after_widget;
     $wppa['in_widget'] = false;
 }
function wppa_album_photos_sequence($album)
{
    global $wpdb;
    if ($album) {
        $photoorder = wppa_get_photo_order($album, 'norandom');
        $is_descending = strpos($photoorder, 'DESC') !== false;
        $is_p_order = strpos($photoorder, 'p_order') !== false;
        $photos = $wpdb->get_results($wpdb->prepare('SELECT * FROM `' . WPPA_PHOTOS . '` WHERE `album` = %s ' . $photoorder, $album), ARRAY_A);
        $link = wppa_dbg_url(get_admin_url() . 'admin.php?page=wppa_admin_menu&tab=edit&edit_id=' . $album . '&bulk');
        $size = '180';
        if ($photos) {
            ?>
			<style>
				.sortable-placeholder {
					width: <?php 
            echo $size;
            ?>
px;
					height: <?php 
            echo $size;
            ?>
px;
					margin: 5px;
					border: 1px solid #cccccc;
					border-radius:3px;
					float: left;
				}
				.ui-state-default {
					position: relative;
					width: <?php 
            echo $size;
            ?>
px;
					height: <?php 
            echo $size;
            ?>
px;
					margin: 5px;
					border-radius:3px;
					float: left;
				}
				.wppa-publish {
					border: 1px solid;
					background-color: rgb( 255, 255, 224 );
					border-color: rgb( 230, 219, 85 );
				}
				.wppa-featured {
					border: 1px solid;
					background-color: rgb( 224, 255, 224 );
					border-color: rgb( 85, 238, 85 );
				}
				.wppa-pending {
					border: 1px solid;
					background-color: rgb( 255, 235, 232 );
					border-color: rgb( 204, 0, 0 );
				}
			</style>
			<script>
				jQuery( function() {
					jQuery( "#sortable" ).sortable( {
						cursor: "move",
						placeholder: "sortable-placeholder",
						stop: function( event, ui ) {
							var ids = jQuery( ".wppa-sort-item" );
							var seq = jQuery( ".wppa-sort-seqn" );
							var idx = 0;
							var descend = <?php 
            if ($is_descending) {
                echo 'true';
            } else {
                echo 'false';
            }
            ?>
;
							while ( idx < ids.length ) {
								var newvalue;
								if ( descend ) newvalue = ids.length - idx;
								else newvalue = idx + 1;
								var oldvalue = seq[idx].value;
								var photo = ids[idx].value;
								if ( newvalue != oldvalue ) {
									wppaDoSeqUpdate( photo, newvalue );
								}
								idx++;
							}
						}
					} );
				} );
				function wppaDoSeqUpdate( photo, seqno ) {
					var data = 'action=wppa&wppa-action=update-photo&photo-id='+photo+'&item=p_order&wppa-nonce='+document.getElementById( 'photo-nonce-'+photo ).value+'&value='+seqno;
					var xmlhttp = new XMLHttpRequest();

					xmlhttp.onreadystatechange = function() {
						if ( xmlhttp.readyState == 4 && xmlhttp.status != 404 ) {
							var ArrValues = xmlhttp.responseText.split( "||" );
							if ( ArrValues[0] != '' ) {
								alert( 'The server returned unexpected output:\n'+ArrValues[0] );
							}
							switch ( ArrValues[1] ) {
								case '0':	// No error
									jQuery( '#wppa-seqno-'+photo ).html( seqno );
									break;
								case '99':	// Photo is gone
									jQuery( '#wppa-seqno-'+photo ).html( '<span style="color"red" >deleted</span>' );
									break;
								default:	// Any error
									jQuery( '#wppa-seqno-'+photo ).html( '<span style="color"red" >Err:'+ArrValues[1]+'</span>' );
									break;
							}
						}
					}
					xmlhttp.open( 'POST',wppaAjaxUrl,true );
					xmlhttp.setRequestHeader( "Content-type","application/x-www-form-urlencoded" );
					xmlhttp.send( data );
					jQuery( "#wppa-sort-seqn-"+photo ).attr( 'value', seqno );	// set hidden value to new value to prevent duplicate action
					var spinnerhtml = '<img src="'+wppaImageDirectory+'wpspin.gif'+'" />';
					jQuery( '#wppa-seqno-'+photo ).html( spinnerhtml );
				}
			</script>
			<?php 
            if (!$is_p_order) {
                wppa_warning_message(__('Setting photo sequence order has only effect if the photo order method is set to <b>Order#</b>', 'wp-photo-album-plus'));
            }
            ?>
			<div class="widefat" style="border-color:#cccccc" >
				<div id="sortable">
					<?php 
            foreach ($photos as $photo) {
                if (wppa_is_video($photo['id'])) {
                    $imgs['0'] = wppa_get_videox($photo['id']);
                    $imgs['1'] = wppa_get_videoy($photo['id']);
                } else {
                    //							$imgs = getimagesize( wppa_get_thumb_path( $photo['id'] ) );
                    $imgs['0'] = wppa_get_thumbx($photo['id']);
                    $imgs['1'] = wppa_get_thumby($photo['id']);
                }
                if (!$imgs['0']) {
                    // missing thuimbnail, prevent division by zero
                    $imgs['0'] = 200;
                    $imgs['1'] = 150;
                }
                $mw = $size - '20';
                $mh = $mw * '3' / '4';
                if ($imgs[1] / $imgs[0] > $mh / $mw) {
                    // more portrait than 200x150, y is limit
                    $mt = '15';
                } else {
                    // x is limit
                    $mt = ($mh - $imgs[1] / $imgs[0] * $mw) / '2' + '15';
                }
                ?>
					<div id="photoitem-<?php 
                echo $photo['id'];
                ?>
" class="ui-state-default wppa-<?php 
                echo $photo['status'];
                ?>
" style="background-image:none; text-align:center; cursor:move;" >
					<?php 
                if (wppa_is_video($photo['id'])) {
                    ?>
					<?php 
                    $id = $photo['id'];
                    ?>
					<?php 
                    $imgstyle = 'max-width:' . $mw . 'px; max-height:' . $mh . 'px; margin-top:' . $mt . 'px;';
                    ?>
					<?php 
                    echo wppa_get_video_html(array('id' => $id, 'controls' => false, 'tagid' => 'pa-id-' . $id, 'preload' => 'metadata', 'class' => 'wppa-bulk-thumb', 'style' => $imgstyle, 'use_thumb' => true));
                    ?>
	<!--					<video preload="metadata" class="wppa-bulk-thumb" style="max-width:<?php 
                    echo $mw;
                    ?>
px; max-height:<?php 
                    echo $mh;
                    ?>
px; margin-top: <?php 
                    echo $mt;
                    ?>
px;" >
						 // echo //wppa_get_video_body( $photo['id'] ) ?>
						</video>
	-->
					<?php 
                } else {
                    ?>
						<img class="wppa-bulk-thumb" src="<?php 
                    echo wppa_fix_poster_ext(wppa_get_thumb_url($photo['id']), $photo['id']);
                    ?>
" style="max-width:<?php 
                    echo $mw;
                    ?>
px; max-height:<?php 
                    echo $mh;
                    ?>
px; margin-top: <?php 
                    echo $mt;
                    ?>
px;" />
					<?php 
                }
                ?>
						<div style="font-size:9px; position:absolute; bottom:24px; text-align:center; width:<?php 
                echo $size;
                ?>
px;" ><?php 
                echo wppa_get_photo_name($photo['id']);
                ?>
</div>
						<div style="text-align: center; width: <?php 
                echo $size;
                ?>
px; position:absolute; bottom:8px;" >
							<span style="margin-left:15px;float:left"><?php 
                echo __('Id: ', 'wp-photo-album-plus') . $photo['id'];
                ?>
</span>
							<?php 
                if (wppa_is_video($photo['id'])) {
                    _e('Video', 'wp-photo-album-plus');
                }
                ?>
							<?php 
                if (wppa_has_audio($photo['id'])) {
                    _e('Audio', 'wp-photo-album-plus');
                }
                ?>
							<span style="float:right; margin-right:15px;"><?php 
                echo __('Ord: ', 'wp-photo-album-plus') . '<span id="wppa-seqno-' . $photo['id'] . '" >' . $photo['p_order'];
                ?>
</span>
						</div>
						<input type="hidden" id="photo-nonce-<?php 
                echo $photo['id'];
                ?>
" value="<?php 
                echo wp_create_nonce('wppa_nonce_' . $photo['id']);
                ?>
" />
						<input type="hidden" class="wppa-sort-item" value="<?php 
                echo $photo['id'];
                ?>
" />
						<input type="hidden" class="wppa-sort-seqn" id="wppa-sort-seqn-<?php 
                echo $photo['id'];
                ?>
" value="<?php 
                echo $photo['p_order'];
                ?>
" />
					</div>
					<?php 
            }
            ?>
				</div>
				<div style="clear:both;"></div>
			</div>
			<?php 
        } else {
            echo '<h3>' . __('The album is empty.', 'wp-photo-album-plus') . '</h3>';
        }
    } else {
        wppa_dbg_msg('Missing required argument in wppa_album_photos() 3', 'red', 'force');
    }
}
 /** @see WP_Widget::widget */
 function widget($args, $instance)
 {
     global $wpdb;
     require_once dirname(__FILE__) . '/wppa-links.php';
     require_once dirname(__FILE__) . '/wppa-styles.php';
     require_once dirname(__FILE__) . '/wppa-functions.php';
     require_once dirname(__FILE__) . '/wppa-thumbnails.php';
     require_once dirname(__FILE__) . '/wppa-boxes-html.php';
     require_once dirname(__FILE__) . '/wppa-slideshow.php';
     wppa_initialize_runtime();
     wppa('in_widget', 'tn');
     wppa_bump_mocc();
     extract($args);
     $instance = wp_parse_args((array) $instance, array('title' => '', 'album' => 'no', 'link' => '', 'linktitle' => '', 'name' => 'no', 'display' => 'thumbs', 'sortby' => wppa_get_photo_order('0'), 'limit' => wppa_opt('thumbnail_widget_count')));
     //		$widget_title 	= apply_filters('widget_title', $instance['title']);
     $widget_title = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title'], $instance, $this->id_base);
     $widget_link = $instance['link'];
     $page = in_array(wppa_opt('thumbnail_widget_linktype'), wppa('links_no_page')) ? '' : wppa_get_the_landing_page('wppa_thumbnail_widget_linkpage', __('Thumbnail photos', 'wp-photo-album-plus'));
     $max = $instance['limit'];
     $sortby = $instance['sortby'];
     $album = $instance['album'];
     $name = $instance['name'];
     $display = $instance['display'];
     $linktitle = $instance['linktitle'];
     $generic = $album == '-2';
     if ($generic) {
         $album = '0';
         $max += '1000';
     }
     $separate = $album == '-1';
     if ($separate) {
         $album = '0';
         $max += '1000';
     }
     if ($album) {
         $thumbs = $wpdb->get_results($wpdb->prepare("SELECT * FROM `" . WPPA_PHOTOS . "` WHERE `status` <> 'pending' AND `status` <> 'scheduled' AND `album` = %s " . $sortby . " LIMIT %d", $album, $max), 'ARRAY_A');
     } else {
         $thumbs = $wpdb->get_results($wpdb->prepare("SELECT * FROM `" . WPPA_PHOTOS . "` WHERE `status` <> 'pending' AND `status` <> 'scheduled'" . $sortby . " LIMIT %d", $max), 'ARRAY_A');
     }
     global $widget_content;
     $widget_content = "\n" . '<!-- WPPA+ thumbnail Widget start -->';
     $maxw = wppa_opt('thumbnail_widget_size');
     $maxh = $maxw;
     $lineheight = wppa_opt('fontsize_widget_thumb') * 1.5;
     $maxh += $lineheight;
     if ($name == 'yes') {
         $maxh += $lineheight;
     }
     $count = '0';
     if ($thumbs) {
         foreach ($thumbs as $image) {
             $thumb = $image;
             if ($generic && wppa_is_separate($thumb['album'])) {
                 continue;
             }
             if ($separate && !wppa_is_separate($thumb['album'])) {
                 continue;
             }
             // Make the HTML for current picture
             if ($display == 'thumbs') {
                 $widget_content .= "\n" . '<div class="wppa-widget" style="width:' . $maxw . 'px; height:' . $maxh . 'px; margin:4px; display:inline; text-align:center; float:left;">';
             } else {
                 $widget_content .= "\n" . '<div class="wppa-widget" >';
             }
             if ($image) {
                 $link = wppa_get_imglnk_a('tnwidget', $image['id']);
                 $file = wppa_get_thumb_path($image['id']);
                 $imgstyle_a = wppa_get_imgstyle_a($image['id'], $file, $maxw, 'center', 'twthumb');
                 $imgurl = wppa_get_thumb_url($image['id'], '', $imgstyle_a['width'], $imgstyle_a['height']);
                 $imgevents = wppa_get_imgevents('thumb', $image['id'], true);
                 $title = $link ? esc_attr(stripslashes($link['title'])) : '';
                 wppa_do_the_widget_thumb('thumbnail', $image, $album, $display, $link, $title, $imgurl, $imgstyle_a, $imgevents);
                 $widget_content .= "\n\t" . '<div style="font-size:' . wppa_opt('fontsize_widget_thumb') . 'px; line-height:' . $lineheight . 'px;">';
                 if ($name == 'yes' && $display == 'thumbs') {
                     $widget_content .= "\n\t" . '<div>' . __(stripslashes($image['name']), 'wp-photo-album-plus') . '</div>';
                 }
                 $widget_content .= "\n\t" . '</div>';
             } else {
                 // No image
                 $widget_content .= __('Photo not found', 'wp-photo-album-plus');
             }
             $widget_content .= "\n" . '</div>';
             $count++;
             if ($count == $instance['limit']) {
                 break;
             }
         }
     } else {
         $widget_content .= __('There are no photos (yet)', 'wp-photo-album-plus');
     }
     $widget_content .= '<div style="clear:both"></div>';
     $widget_content .= "\n" . '<!-- WPPA+ thumbnail Widget end -->';
     echo "\n" . $before_widget;
     if (!empty($widget_title)) {
         echo $before_title;
         if (!empty($widget_link)) {
             echo "\n" . '<a href="' . $widget_link . '" title="' . $linktitle . '" >' . $widget_title . '</a>';
         } else {
             echo $widget_title;
         }
         echo $after_title;
     }
     echo $widget_content . $after_widget;
     wppa('in_widget', false);
 }
 /** @see WP_Widget::widget */
 function widget($args, $instance)
 {
     global $wpdb;
     wppa('in_widget', 'potd');
     wppa_bump_mocc();
     require_once dirname(__FILE__) . '/wppa-links.php';
     require_once dirname(__FILE__) . '/wppa-styles.php';
     require_once dirname(__FILE__) . '/wppa-functions.php';
     require_once dirname(__FILE__) . '/wppa-thumbnails.php';
     require_once dirname(__FILE__) . '/wppa-boxes-html.php';
     require_once dirname(__FILE__) . '/wppa-slideshow.php';
     wppa_initialize_runtime();
     extract($args);
     $widget_title = apply_filters('widget_title', $instance['title']);
     // get the photo  ($image)
     $image = wppa_get_potd();
     // Make the HTML for current picture
     $widget_content = "\n" . '<!-- WPPA+ Photo of the day Widget start -->';
     $ali = wppa_opt('potd_align');
     if ($ali != 'none') {
         $align = 'text-align:' . $ali . ';';
     } else {
         $align = '';
     }
     $widget_content .= "\n" . '<div class="wppa-widget-photo" style="' . $align . ' padding-top:2px;position:relative;" >';
     if ($image) {
         $id = $image['id'];
         $w = wppa_opt('potd_widget_width');
         $ratio = wppa_get_photoy($id) / wppa_get_photox($id);
         $h = round($w * $ratio);
         $usethumb = wppa_use_thumb_file($id, wppa_opt('potd_widget_width'), '0');
         $imgurl = wppa_fix_poster_ext($usethumb ? wppa_get_thumb_url($id, '', $w, $h) : wppa_get_photo_url($id, '', $w, $h), $id);
         $name = wppa_get_photo_name($id);
         $page = in_array(wppa_opt('potd_linktype'), wppa('links_no_page')) && !wppa_switch('potd_counter') ? '' : wppa_get_the_landing_page('potd_linkpage', __('Photo of the day', 'wp-photo-album-plus'));
         $link = wppa_get_imglnk_a('potdwidget', $id);
         $is_video = wppa_is_video($id);
         $has_audio = wppa_has_audio($id);
         if ($link['is_lightbox']) {
             $lightbox = ($is_video ? ' data-videohtml="' . esc_attr(wppa_get_video_body($id)) . '"' . ' data-videonatwidth="' . wppa_get_videox($id) . '"' . ' data-videonatheight="' . wppa_get_videoy($id) . '"' : '') . ($has_audio ? ' data-audiohtml="' . esc_attr(wppa_get_audio_body($id)) . '"' : '') . ' ' . wppa('rel') . '="' . wppa_opt('lightbox_name') . '"' . ' data-alt="' . esc_attr(wppa_get_imgalt($id, true)) . '"';
         } else {
             $lightbox = '';
         }
         if ($link) {
             if ($link['is_lightbox']) {
                 $cursor = ' cursor:url(' . wppa_get_imgdir() . wppa_opt('magnifier') . '),pointer;';
                 $title = wppa_zoom_in($id);
                 $ltitle = wppa_get_lbtitle('potd', $id);
             } else {
                 $cursor = ' cursor:pointer;';
                 $title = $link['title'];
                 $ltitle = $title;
             }
         } else {
             $cursor = ' cursor:default;';
             $title = esc_attr(stripslashes(__($image['name'], 'wp-photo-album-plus')));
         }
         // The medal if on top
         $widget_content .= wppa_get_medal_html_a(array('id' => $id, 'size' => 'M', 'where' => 'top'));
         // The link, if any
         if ($link) {
             $widget_content .= "\n\t" . '<a href = "' . $link['url'] . '" target="' . $link['target'] . '" ' . $lightbox . ' ' . wppa('lbtitle') . '="' . $ltitle . '">';
         }
         // The image
         if (wppa_is_video($id)) {
             $widget_content .= "\n\t\t" . wppa_get_video_html(array('id' => $id, 'width' => wppa_opt('potd_widget_width'), 'title' => $title, 'controls' => wppa_opt('potd_linktype') == 'none', 'cursor' => $cursor));
         } else {
             $widget_content .= '<img' . ' src="' . $imgurl . '"' . ' style="width: ' . wppa_opt('potd_widget_width') . 'px;' . $cursor . '"' . ' ' . wppa_get_imgalt($id) . ($title ? 'title="' . $title . '"' : '') . ' />';
         }
         // Close the link
         if ($link) {
             $widget_content .= '</a>';
         }
         // The medal if at the bottom
         $widget_content .= wppa_get_medal_html_a(array('id' => $id, 'size' => 'M', 'where' => 'bot'));
         // The counter
         if (wppa_switch('potd_counter')) {
             // If we want this
             $alb = wppa_get_photo_item($id, 'album');
             $c = $wpdb->get_var("SELECT COUNT(*) FROM `" . WPPA_PHOTOS . "` WHERE `album` = " . $alb) - 1;
             if ($c > 0) {
                 if (wppa_opt('potd_counter_link') == 'thumbs') {
                     $lnk = wppa_get_album_url($alb, $page, 'thumbs', '1');
                 } elseif (wppa_opt('potd_counter_link') == 'slide') {
                     $lnk = wppa_get_slideshow_url($alb, $page, $id, '1');
                 } elseif (wppa_opt('potd_counter_link') == 'single') {
                     $lnk = wppa_encrypt_url(get_permalink($page) . '?occur=1&photo=' . $id);
                     //	wppa_get_image_page_url_by_id( $id, true, false, $page );
                 } else {
                     wppa_log('Err', 'Unimplemented counter link type in wppa-potd-widget: ' . wppa_opt('potd_counter_link'));
                 }
                 $widget_content .= '<a href="' . $lnk . '" >' . '<div style="font-size:12px;position:absolute;right:4px;bottom:4px;" >+' . $c . '</div>' . '</a>';
             }
         }
         // Audio
         if (wppa_has_audio($id)) {
             $widget_content .= wppa_get_audio_html(array('id' => $id, 'width' => wppa_opt('potd_widget_width'), 'controls' => true));
         }
     } else {
         // No image
         $widget_content .= __('Photo not found', 'wp-photo-album-plus');
     }
     $widget_content .= "\n" . '</div>';
     // Add subtitle, if any
     if ($image) {
         switch (wppa_opt('potd_subtitle')) {
             case 'none':
                 break;
             case 'name':
                 $widget_content .= '<div class="wppa-widget-text wppa-potd-text" style="' . $align . '">' . wppa_get_photo_name($id) . '</div>';
                 break;
             case 'desc':
                 $widget_content .= "\n" . '<div class="wppa-widget-text wppa-potd-text" style="' . $align . '">' . wppa_get_photo_desc($id) . '</div>';
                 break;
             case 'owner':
                 $owner = $image['owner'];
                 $user = get_user_by('login', $owner);
                 $owner = $user->display_name;
                 $widget_content .= "\n" . '<div class="wppa-widget-text wppa-potd-text" style="' . $align . '">' . __('By:', 'wp-photo-album-plus') . ' ' . $owner . '</div>';
                 break;
             default:
                 wppa_log('Err', 'Unimplemented potd_subtitle found in wppa-potd-widget: ' . wppa_opt('potd_subtitle'));
         }
     }
     $widget_content .= '<div style="clear:both;" ></div>';
     $widget_content .= "\n" . '<!-- WPPA+ Photo of the day Widget end -->';
     echo "\n" . $before_widget;
     if (!empty($widget_title)) {
         echo $before_title . $widget_title . $after_title;
     }
     echo $widget_content . $after_widget;
     wppa('in_widget', false);
 }
function wppa_sphoto()
{
    $id = wppa('single_photo');
    $width = wppa_get_container_width();
    $height = floor($width / wppa_get_ratio($id));
    $usethumb = wppa_use_thumb_file($id, $width, $height);
    $src = $usethumb ? wppa_get_thumb_url($id, '', $width, $height) : wppa_get_photo_url($id, '', $width, $height);
    if (wppa_has_audio($id)) {
        $src = wppa_fix_poster_ext($src, $id);
    }
    if (!wppa_in_widget()) {
        wppa_bump_viewcount('photo', $id);
    }
    $autocol = wppa('auto_colwidth') || $width > 0 && $width <= 1.0;
    // The initial width is $width if not autocol, else it should default to initial column width when auto
    // or initial column width * fraction
    if ($autocol) {
        if ($width == 'auto') {
            $contwidth = wppa_opt('initial_colwidth');
        } else {
            $contwidth = wppa_opt('initial_colwidth') * $width;
        }
    } else {
        $contwidth = $width;
    }
    // Open the pseudo container
    wppa_out('<div' . ' id="wppa-container-' . wppa('mocc') . '"' . ' class="' . (wppa('align') ? 'align' . wppa('align') : '') . ' wppa-sphoto-' . wppa('mocc') . '"' . ' style="width:' . $contwidth . 'px;position:relative;"' . ' >');
    // The script for responsive
    wppa_add_js_page_data("\n" . '<script type="text/javascript">');
    if ($autocol) {
        wppa_add_js_page_data("\n" . 'wppaAutoColumnWidth[' . wppa('mocc') . '] = true;');
        if ($width > 0 && $width <= 1.0) {
            wppa_add_js_page_data("\n" . 'wppaAutoColumnFrac[' . wppa('mocc') . '] = ' . $width . ';');
        } else {
            wppa_add_js_page_data("\n" . 'wppaAutoColumnFrac[' . wppa('mocc') . '] = 1.0;');
        }
        wppa_add_js_page_data("\n" . 'wppaColWidth[' . wppa('mocc') . '] = 0;');
    }
    wppa_add_js_page_data("\n" . 'wppaTopMoc = ' . wppa('mocc') . ';');
    wppa_add_js_page_data("\n" . '</script>');
    wppa('portrait_only', true);
    $fis = wppa_get_fullimgstyle_a($id);
    $width = $fis['width'];
    $height = $fis['height'];
    $style = $fis['style'];
    $style .= 'box-sizing:content-box;vertical-align:middle;';
    // The link
    $link = wppa_get_imglnk_a('sphoto', $id);
    if ($link) {
        if ($link['is_lightbox']) {
            $lbtitle = wppa_get_lbtitle('sphoto', $id);
            $videobody = esc_attr(wppa_get_video_body($id));
            $audiobody = esc_attr(wppa_get_audio_body($id));
            $videox = wppa_get_videox($id);
            $videoy = wppa_get_videoy($id);
            wppa_out('<a' . ' href="' . $link['url'] . '"' . ($lbtitle ? ' ' . wppa('lbtitle') . '="' . $lbtitle . '"' : '') . ($videobody ? ' data-videohtml="' . $videobody . '"' : '') . ($audiobody ? ' data-audiohtml="' . $audiobody . '"' : '') . ($videox ? ' data-videonatwidth="' . $videox . '"' : '') . ($videoy ? ' data-videonatheight="' . $videoy . '"' : '') . ' ' . wppa('rel') . '="' . wppa_opt('lightbox_name') . '"' . ($link['target'] ? ' target="' . $link['target'] . '"' : '') . ' class="thumb-img"' . ' id="a-' . $id . '-' . wppa('mocc') . '"' . ' >');
        } else {
            wppa_out('<a' . ' href="' . $link['url'] . '"' . ' title="' . $link['title'] . '"' . ' target="' . $link['target'] . '"' . ' class="thumb-img"' . ' id="a-' . $id . '-' . wppa('mocc') . '"' . ' >');
        }
    }
    // The image
    $title = $link ? esc_attr($link['title']) : esc_attr(stripslashes(wppa_get_photo_name($id)));
    if ($link['is_lightbox']) {
        $style .= ' cursor:url( ' . wppa_get_imgdir() . wppa_opt('magnifier') . ' ),pointer;';
        $title = wppa_zoom_in($id);
    }
    if (wppa_is_video($id)) {
        if ($autocol) {
            wppa_out(wppa_get_video_html(array('id' => $id, 'controls' => !$link['is_lightbox'], 'style' => $style, 'class' => 'size-medium wppa-sphoto wppa-simg-' . wppa('mocc'))));
        } else {
            wppa_out(wppa_get_video_html(array('id' => $id, 'width' => $width, 'height' => $height, 'controls' => !$link['is_lightbox'], 'style' => $style, 'class' => 'size-medium wppa-sphoto wppa-simg-' . wppa('mocc'))));
        }
    } else {
        wppa_out('<img' . ' src="' . $src . '"' . ' ' . wppa_get_imgalt($id) . ' class="size-medium wppa-sphoto wppa-simg-' . wppa('mocc') . '"' . ' ' . wppa_get_imgalt($id) . ($title ? ' title="' . $title . '" ' : '') . ' style="' . $style . '"' . ($autocol ? '' : ' width="' . $width . '" height="' . $height . '" ') . '/ >');
    }
    // Close the link
    if ($link) {
        wppa_out('</a>');
    }
    // Add audio?			sphoto
    if (wppa_has_audio($id)) {
        wppa_out('<div style="position:relative;z-index:11;" >');
        $margl = wppa_opt('fullimage_border_width') === '' ? 0 : wppa_opt('fullimage_border_width') + 1;
        $margb = $margl;
        wppa_out(wppa_get_audio_html(array('id' => $id, 'cursor' => 'cursor:pointer;', 'style' => $style . 'position:absolute;' . 'left:' . $margl . 'px;' . 'bottom:' . $margb . 'px;' . 'padding:0;' . 'margin:0;' . 'border:none;' . 'height:' . wppa_get_audio_control_height() . 'px;' . 'border-radius:0;', 'class' => 'size-medium wppa-sphoto wppa-simg-' . wppa('mocc'))));
        wppa_out('</div>');
    }
    // The pseudo container
    wppa_out('</div>');
}
function wppa_get_picture_html($args)
{
    // Init
    $defaults = array('id' => '0', 'type' => '', 'class' => '');
    $args = wp_parse_args($args, $defaults);
    $id = strval(intval($args['id']));
    $type = $args['type'];
    $class = $args['class'];
    // Check existance of required args
    foreach (array('id', 'type') as $item) {
        if (!$args[$item]) {
            wppa_dbg_msg('Missing ' . $item . ' in call to wppa_get_picture_html()', 'red', 'force');
            return false;
        }
    }
    // Check validity of args
    if (!wppa_photo_exists($id)) {
        wppa_dbg_msg('Photo ' . $id . ' does not exist in call to wppa_get_picture_html(). Type = ' . $type, 'red', 'force');
        return false;
    }
    $types = array('sphoto', 'mphoto', 'xphoto', 'cover', 'thumb', 'ttthumb', 'comthumb', 'fthumb', 'twthumb', 'ltthumb', 'albthumb');
    if (!in_array($type, $types)) {
        wppa_dbg_msg('Unimplemented type ' . $type . ' in call to wppa_get_picture_html()', 'red', 'force');
        return false;
    }
    // Get other data
    $link = wppa_get_imglnk_a($type, $id);
    $isthumb = strpos($type, 'thumb') !== false;
    $file = wppa_fix_poster_ext($isthumb ? wppa_get_thumb_path($id) : wppa_get_photo_path($id), $id);
    $href = wppa_fix_poster_ext($isthumb ? wppa_get_thumb_url($id) : wppa_get_photo_url($id), $id);
    $autocol = wppa('auto_colwidth') || wppa('fullsize') > 0 && wppa('fullsize') <= 1.0;
    $title = $link ? esc_attr($link['title']) : esc_attr(stripslashes(wppa_get_photo_name($id)));
    $alt = wppa_get_imgalt($id);
    // Find image style
    switch ($type) {
        case 'sphoto':
            $style = 'width:100%;margin:0;';
            if (!wppa_in_widget()) {
                switch (wppa_opt('fullimage_border_width')) {
                    case '':
                        $style .= 'padding:0;' . 'border:none;';
                        break;
                    case '0':
                        $style .= 'padding:0;' . 'border:1px solid ' . wppa_opt('bcolor_fullimg') . ';' . 'box-sizing:border-box;';
                        break;
                    default:
                        $style .= 'padding:' . (wppa_opt('fullimage_border_width') - '1') . 'px;' . 'border:1px solid ' . wppa_opt('bcolor_fullimg') . ';' . 'box-sizing:border-box;' . 'background-color:' . wppa_opt('bgcolor_fullimg') . ';';
                        // If we do round corners...
                        if (wppa_opt('bradius') > '0') {
                            // then also here
                            $style .= 'border-radius:' . wppa_opt('fullimage_border_width') . 'px;';
                        }
                }
            }
            break;
        case 'mphoto':
        case 'xphoto':
            $style = 'width:100%;margin:0;padding:0;border:none;';
            break;
        default:
            wppa_dbg_msg('Style for type ' . $type . ' is not implemented yet in wppa_get_picture_html()', 'red', 'force');
            return false;
    }
    if ($link['is_lightbox']) {
        $style .= 'cursor:url( ' . wppa_get_imgdir() . wppa_opt('magnifier') . ' ),pointer;';
        $title = wppa_zoom_in($id);
    }
    // Create the html
    $result = '';
    // The link
    if ($link) {
        // Link is lightbox
        if ($link['is_lightbox']) {
            $lbtitle = wppa_get_lbtitle($type, $id);
            $videobody = esc_attr(wppa_get_video_body($id));
            $audiobody = esc_attr(wppa_get_audio_body($id));
            $videox = wppa_get_videox($id);
            $videoy = wppa_get_videoy($id);
            $result .= '<a' . ' href="' . $link['url'] . '"' . ($lbtitle ? ' ' . wppa('lbtitle') . '="' . $lbtitle . '"' : '') . ($videobody ? ' data-videohtml="' . $videobody . '"' : '') . ($audiobody ? ' data-audiohtml="' . $audiobody . '"' : '') . ($videox ? ' data-videonatwidth="' . $videox . '"' : '') . ($videoy ? ' data-videonatheight="' . $videoy . '"' : '') . ' ' . wppa('rel') . '="' . wppa_opt('lightbox_name') . '"' . ($link['target'] ? ' target="' . $link['target'] . '"' : '') . ' class="thumb-img"' . ' id="a-' . $id . '-' . wppa('mocc') . '"' . ' data-alt="' . esc_attr(wppa_get_imgalt($id, true)) . '"' . ' >';
        } else {
            $result .= '<a' . (wppa_is_mobile() ? ' ontouchstart="wppaStartTime();" ontouchend="wppaTapLink(\'' . $id . '\',\'' . $link['url'] . '\');" ' : ' onclick="_bumpClickCount( \'' . $id . '\' );window.open(\'' . $link['url'] . '\', \'' . $link['target'] . '\' )"') . ' title="' . $link['title'] . '"' . ' class="thumb-img"' . ' id="a-' . $id . '-' . wppa('mocc') . '"' . ' >';
        }
    }
    // The image
    // Video?
    if (wppa_is_video($id)) {
        $result .= wppa_get_video_html(array('id' => $id, 'controls' => !$link, 'style' => $style, 'class' => $class));
    } else {
        $result .= '<img' . ' id="ph-' . $id . '-' . wppa('mocc') . '"' . ' src="' . $href . '"' . ' ' . wppa_get_imgalt($id) . ($class ? ' class="' . $class . '" ' : '') . ($title ? ' title="' . $title . '" ' : '') . ' style="' . $style . '"' . ' />';
    }
    // Close the link
    if ($link) {
        $result .= '</a>';
    }
    // Add audio?			sphoto
    if (wppa_has_audio($id)) {
        $result .= '<div style="position:relative;z-index:11;" >';
        // Find style for audio controls
        switch ($type) {
            case 'sphoto':
                $pad = wppa_opt('fullimage_border_width') === '' ? 0 : wppa_opt('fullimage_border_width') + 1;
                $bot = wppa_opt('fullimage_border_width') === '' ? 0 : wppa_opt('fullimage_border_width') - 1;
                $style = 'margin:0;' . 'padding:0 ' . $pad . 'px;' . 'bottom:' . $bot . 'px;';
                $class = 'size-medium wppa-sphoto wppa-sphoto-' . wppa('mocc');
                break;
            case 'mphoto':
            case 'xphoto':
                $style = 'margin:0;' . 'padding:0;' . 'bottom:0;';
                $class = 'size-medium wppa-' . $type . ' wppa-' . $type . '-' . wppa('mocc');
                break;
            default:
                $style = 'margin:0;' . 'padding:0;';
                $class = '';
        }
        // Get the html for audio
        $result .= wppa_get_audio_html(array('id' => $id, 'cursor' => 'cursor:pointer;', 'style' => $style . 'position:absolute;' . 'box-sizing:border-box;' . 'width:100%;' . 'border:none;' . 'height:' . wppa_get_audio_control_height() . 'px;' . 'border-radius:0;', 'class' => $class));
        $result .= '</div>';
    }
    // Update statistics
    if (!wppa_in_widget()) {
        wppa_bump_viewcount('photo', $id);
    }
    // Done !
    return $result;
}
 /** @see WP_Widget::widget */
 function widget($args, $instance)
 {
     global $wpdb;
     require_once dirname(__FILE__) . '/wppa-links.php';
     require_once dirname(__FILE__) . '/wppa-styles.php';
     require_once dirname(__FILE__) . '/wppa-functions.php';
     require_once dirname(__FILE__) . '/wppa-thumbnails.php';
     require_once dirname(__FILE__) . '/wppa-boxes-html.php';
     require_once dirname(__FILE__) . '/wppa-slideshow.php';
     wppa_initialize_runtime();
     wppa('in_widget', 'com');
     wppa_bump_mocc();
     // Hide widget if not logged in and login required to see comments
     if (wppa_switch('comment_view_login') && !is_user_logged_in()) {
         return;
     }
     extract($args);
     $page = in_array(wppa_opt('comment_widget_linktype'), wppa('links_no_page')) ? '' : wppa_get_the_landing_page('wppa_comment_widget_linkpage', __('Recently commented photos', 'wp-photo-album-plus'));
     $max = wppa_opt('comten_count');
     $widget_title = apply_filters('widget_title', $instance['title']);
     $photo_ids = wppa_get_comten_ids($max);
     $widget_content = "\n" . '<!-- WPPA+ Comment Widget start -->';
     $maxw = wppa_opt('comten_size');
     $maxh = $maxw + 18;
     if ($photo_ids) {
         foreach ($photo_ids as $id) {
             // Make the HTML for current comment
             $widget_content .= "\n" . '<div class="wppa-widget" style="width:' . $maxw . 'px; height:' . $maxh . 'px; margin:4px; display:inline; text-align:center; float:left;">';
             $image = wppa_cache_thumb($id);
             if ($image) {
                 $link = wppa_get_imglnk_a('comten', $id, '', '', true);
                 $file = wppa_get_thumb_path($id);
                 $imgstyle_a = wppa_get_imgstyle_a($id, $file, $maxw, 'center', 'comthumb');
                 $imgstyle = $imgstyle_a['style'];
                 $width = $imgstyle_a['width'];
                 $height = $imgstyle_a['height'];
                 $cursor = $imgstyle_a['cursor'];
                 $imgurl = wppa_get_thumb_url($id, '', $width, $height);
                 $imgevents = wppa_get_imgevents('thumb', $id, true);
                 $title = '';
                 $comments = $wpdb->get_results($wpdb->prepare("SELECT * FROM `" . WPPA_COMMENTS . "` WHERE `photo` = %s ORDER BY `timestamp` DESC", $id), ARRAY_A);
                 if ($comments) {
                     $first_comment = $comments['0'];
                     foreach ($comments as $comment) {
                         $title .= $comment['user'] . ' ' . __('wrote', 'wp-photo-album-plus') . ' ' . wppa_get_time_since($comment['timestamp']) . ":\n";
                         $title .= $comment['comment'] . "\n\n";
                     }
                 }
                 $title = esc_attr(strip_tags(trim($title)));
                 $album = '0';
                 $display = 'thumbs';
                 $widget_content .= wppa_get_the_widget_thumb('comten', $image, $album, $display, $link, $title, $imgurl, $imgstyle_a, $imgevents);
             } else {
                 $widget_content .= __('Photo not found.', 'wp-photo-album-plus');
             }
             $widget_content .= "\n\t" . '<span style="font-size:' . wppa_opt('fontsize_widget_thumb') . 'px; cursor:pointer;" title="' . esc_attr($first_comment['comment']) . '" >' . $first_comment['user'] . '</span>';
             $widget_content .= "\n" . '</div>';
         }
     } else {
         $widget_content .= 'There are no commented photos (yet).';
     }
     $widget_content .= '<div style="clear:both"></div>';
     $widget_content .= "\n" . '<!-- WPPA+ comment Widget end -->';
     echo "\n" . $before_widget;
     if (!empty($widget_title)) {
         echo $before_title . $widget_title . $after_title;
     }
     echo $widget_content . $after_widget;
     wppa('in_widget', false);
 }
function wppa_subalbumlinks_html($id, $top = true)
{
    global $wpdb;
    // Do they need us? Anything to display?
    if (wppa_opt('cover_sublinks_display') == 'none') {
        return;
    }
    // Display type
    $display_type = wppa_opt('cover_sublinks_display');
    // Link type
    $link_type = wppa_opt('cover_sublinks');
    // Init
    $is_list = $display_type == 'list' || $display_type == 'recursivelist';
    $is_recursive = $display_type == 'recursivelist';
    $first = true;
    // Get the children
    $subs = $wpdb->get_results("SELECT * FROM `" . WPPA_ALBUMS . "` WHERE `a_parent` = " . $id . " " . wppa_get_album_order($id), ARRAY_A);
    // Only if there are sub-albums
    if (!empty($subs)) {
        wppa_out('<div>');
        // Local css
        if ($top) {
            if ($is_list) {
                wppa_out('<style scoped="scoped" >' . 'ul, li { margin:0; }' . 'ul {' . 'list-style-type:disc;' . 'list-style-position:inside;' . 'padding:0 0 0 24px;' . '}' . 'li { cursor:pointer; }' . '</style>');
            }
            if ($display_type == 'microthumbs') {
                wppa_out('<style scoped="scoped" >' . 'img {' . 'max-width:100px;' . 'max-height:50px;' . 'padding:1px;' . 'margin:1px;' . 'background-color:' . wppa_opt('bgcolor_img') . ';' . 'float:left;' . '}' . '</style>');
            }
        }
        // Start list if required
        if ($is_list) {
            wppa_out('<ul class="wppa-cover-sublink-list" style="clear:both;" >');
        } else {
            wppa_out('<div style="clear:both;" ></div>');
        }
        // Process the sub-albums
        foreach ($subs as $album) {
            // What is the albums title linktype
            $linktype = $album['cover_linktype'];
            if (!$linktype) {
                $linktype = 'content';
            }
            // Default
            // What is the albums title linkpage
            $linkpage = $album['cover_linkpage'];
            if ($linkpage == '-1') {
                $linktype = 'none';
            }
            // for backward compatibility
            // Find the content 'View' link
            $albumid = $album['id'];
            $photocount = wppa_get_photo_count($albumid, 'use_treecounts');
            // Thumbnails and covers, show sub-album covers
            // in case slideshow is requested on an empty album
            if (wppa_opt('cover_sublinks') == 'content' || !$photocount) {
                if (wppa_switch('allow_ajax') && !$linkpage) {
                    $href_content = '';
                    $onclick_content = "wppaDoAjaxRender( " . wppa('mocc') . ", '" . wppa_get_album_url_ajax($albumid, $linkpage) . "', '" . wppa_convert_to_pretty($href_content) . "' )";
                } else {
                    $href_content = wppa_convert_to_pretty(wppa_get_album_url($albumid, $linkpage));
                    $onclick_content = '';
                }
            } else {
                if (wppa_switch('allow_ajax') && !$linkpage) {
                    $href_content = '';
                    $onclick_content = "wppaDoAjaxRender( " . wppa('mocc') . ", '" . wppa_get_slideshow_url_ajax($albumid, $linkpage) . "', '" . wppa_convert_to_pretty($href_content) . "' )";
                } else {
                    $href_content = wppa_convert_to_pretty(wppa_get_slideshow_url($albumid, $linkpage));
                    $onclick_content = '';
                }
            }
            // Do the output
            $title = esc_attr(__('View the album', 'wp-photo-album-plus') . ': ' . wppa_get_album_name($album['id']));
            switch ($display_type) {
                case 'list':
                case 'recursivelist':
                    if ($link_type == 'none') {
                        wppa_out('<li>' . wppa_get_album_name($album['id']) . '</li>');
                    } else {
                        wppa_out('<li>' . '<a' . ($href_content ? ' href="' . $href_content . '"' : '') . ($onclick_content ? ' onclick="' . $onclick_content . '"' : '') . ' title="' . $title . '"' . ' >' . wppa_get_album_name($album['id']) . '</a>' . '</li>');
                    }
                    break;
                case 'enum':
                    if (!$first) {
                        wppa_out(', ');
                    }
                    if ($link_type == 'none') {
                        wppa_out(wppa_get_album_name($album['id']));
                    } else {
                        wppa_out('<a' . ($href_content ? ' href="' . $href_content . '"' : '') . ($onclick_content ? ' onclick="' . $onclick_content . '"' : '') . ' title="' . $title . '"' . ' >' . wppa_get_album_name($album['id']) . '</a>');
                    }
                    $first = false;
                    break;
                case 'microthumbs':
                    $coverphoto_id = wppa_get_coverphoto_id($album['id']);
                    $src = wppa_fix_poster_ext(wppa_get_thumb_url($coverphoto_id), $coverphoto_id);
                    if ($link_type == 'none') {
                        wppa_out('<img' . ' class="wppa-cover-sublink-img"' . ' src="' . $src . '"' . ' alt="' . wppa_get_album_name($album['id']) . '"' . ' />');
                    } else {
                        wppa_out('<a' . ($href_content ? ' href="' . $href_content . '"' : '') . ($onclick_content ? ' onclick="' . $onclick_content . '"' : '') . ' title="' . $title . '"' . ' >' . '<img' . ' class="wppa-cover-sublink-img"' . ' src="' . $src . '"' . ' alt="' . wppa_get_album_name($album['id']) . '"' . ' />' . '</a>');
                    }
                    break;
            }
            // Go deeper for grandchildren
            if ($is_recursive) {
                wppa_subalbumlinks_html($album['id'], false);
            }
        }
        // End list
        if ($is_list) {
            wppa_out('</ul>');
        }
        wppa_out('</div>');
    }
}
Exemple #26
0
function wppa_do_filmthumb($id, $idx, $do_for_feed = false, $glue = false)
{
    $thumb = wppa_cache_thumb($id);
    $result = '';
    $src = wppa_fix_poster_ext(wppa_get_thumb_path($thumb['id']), $thumb['id']);
    $max_size = wppa_opt('thumbsize');
    if (wppa_in_widget()) {
        $max_size /= 2;
    }
    $com_alt = wppa('is_comten') && wppa_switch('comten_alt_display') && !wppa_in_widget();
    $imgattr_a = wppa_get_imgstyle_a($thumb['id'], $src, $max_size, 'optional', 'fthumb');
    $imgstyle = $imgattr_a['style'];
    $imgwidth = $imgattr_a['width'];
    $imgheight = $imgattr_a['height'];
    $cursor = $imgattr_a['cursor'];
    $url = wppa_fix_poster_ext(wppa_get_thumb_url($thumb['id'], '', $imgwidth, $imgheight), $thumb['id']);
    $furl = str_replace('/thumbs', '', $url);
    $events = wppa_get_imgevents('film', $thumb['id'], 'nopopup', $idx);
    $thumbname = wppa_get_photo_name($thumb['id']);
    $target = wppa_switch('film_blank') || $thumb['linktarget'] == '_blank' ? 'target="_blank" ' : '';
    $psotitle = $thumb['linktitle'] ? 'title="' . esc_attr($thumb['linktitle']) . '" ' : '';
    $psourl = wppa_switch('film_overrule') && $thumb['linkurl'] ? 'href="' . $thumb['linkurl'] . '" ' . $target . $psotitle : '';
    $imgalt = wppa_get_imgalt($thumb['id']);
    if (wppa_opt('film_linktype') == 'lightbox') {
        //		$title = esc_attr( wppa_zoom_in( $thumb['id'] ) );
    } else {
        $events .= ' onclick="wppaGotoKeepState( ' . wppa('mocc') . ', ' . $idx . ' )"';
        $events .= ' ondblclick="wppaStartStop( ' . wppa('mocc') . ', -1 )"';
    }
    if (is_feed()) {
        if ($do_for_feed) {
            $style_a = wppa_get_imgstyle_a($thumb['id'], $src, '100', '4', 'thumb');
            $style = $style_a['style'];
            $result .= '<a href="' . get_permalink() . '">' . '<img' . ' src="' . $url . '"' . ' ' . $imgalt . ' title="' . $thumbname . '"' . ' style="' . $style . '"' . ' />' . '</a>';
        }
    } else {
        // If ! $do_for_feed: pre-or post-ambule. To avoid dup id change it in that case
        $tmp = $do_for_feed ? 'film' : 'pre';
        $style = $glue ? 'style="' . wppa_get_thumb_frame_style($glue, 'film') . '"' : '';
        $result .= '<div' . ' id="' . $tmp . '_wppatnf_' . $thumb['id'] . '_' . wppa('mocc') . '"' . ' class="thumbnail-frame"' . ' ' . $style . ' >';
        if ($psourl) {
            // True only when pso activated and data present
            $result .= '<a ' . $psourl . '>';
            // $psourl contains url, target and title
        } elseif (wppa_opt('film_linktype') == 'lightbox' && $tmp == 'film') {
            $title = wppa_get_lbtitle('slide', $thumb['id']);
            $videohtml = esc_attr(wppa_get_video_body($thumb['id']));
            $audiohtml = esc_attr(wppa_get_audio_body($thumb['id']));
            $result .= '<a href="' . $furl . '"' . ($videohtml ? ' data-videohtml="' . $videohtml . '"' . ' data-videonatwidth="' . wppa_get_videox($thumb['id']) . '"' . ' data-videonatheight="' . wppa_get_videoy($thumb['id']) . '"' : '') . ($audiohtml ? ' data-audiohtml="' . $audiohtml . '"' : '') . ' ' . wppa('rel') . '="' . wppa_opt('lightbox_name') . '[occ' . wppa('mocc') . ']"' . ($title ? ' ' . wppa('lbtitle') . '="' . $title . '"' : '') . ' >';
        }
        if ($tmp == 'pre' && wppa_opt('film_linktype') == 'lightbox') {
            $cursor = 'cursor:default;';
        }
        if ($tmp == 'film' && !$com_alt && !wppa_cdn('front') && !wppa_switch('lazy_or_htmlcomp')) {
            $result .= '<!--';
        }
        if (wppa_is_video($thumb['id'])) {
            $result .= wppa_get_video_html(array('id' => $thumb['id'], 'width' => $imgattr_a['width'], 'height' => $imgattr_a['height'], 'controls' => false, 'margin_top' => $imgattr_a['margin-top'], 'margin_bottom' => $imgattr_a['margin-bottom'], 'cursor' => $imgattr_a['cursor'], 'events' => $events, 'tagid' => 'wppa-' . $tmp . '-' . $idx . '-' . wppa('mocc')));
        } else {
            $result .= '<img' . ' id="wppa-' . $tmp . '-' . $idx . '-' . wppa('mocc') . '"' . ' class="wppa-' . $tmp . '-' . wppa('mocc') . '"' . ' src="' . $url . '"' . ' ' . $imgalt . ' style="' . $imgstyle . $cursor . '"' . ' ' . $events . ' data-title="' . ($psourl ? esc_attr($thumb['linktitle']) : '') . '"' . ' />';
        }
        if ($tmp == 'film' && !$com_alt && !wppa_cdn('front') && !wppa_switch('lazy_or_htmlcomp')) {
            $result .= '-->';
        }
        if ($psourl) {
            // True only when pso activated and data present
            $result .= '</a>';
            // $psourl contains url, target and title
        } elseif (wppa_opt('film_linktype') == 'lightbox' && $tmp == 'film') {
            $result .= '</a>';
        }
        $result .= '</div>';
    }
    wppa_out($result);
}
function _wppa_sidebar_page_options()
{
    global $wpdb;
    $options_error = false;
    if (isset($_GET['walbum'])) {
        $walbum = wppa_walbum_sanitize($_GET['walbum']);
        wppa_update_option('wppa_widget_album', $walbum);
    }
    if (isset($_POST['wppa-set-submit'])) {
        check_admin_referer('$wppa_nonce', WPPA_NONCE);
        if (isset($_POST['wppa-widgettitle'])) {
            wppa_update_option('wppa_widgettitle', $_POST['wppa-widgettitle']);
        }
        if (isset($_POST['wppa-potd-align'])) {
            wppa_update_option('wppa_potd_align', $_POST['wppa-potd-align']);
        }
        if (isset($_POST['wppa-widget-albums'])) {
            wppa_update_option('wppa_widget_album', wppa_walbum_sanitize($_POST['wppa-widget-albums']));
        }
        if (isset($_POST['wppa-widget-photo'])) {
            wppa_update_option('wppa_widget_photo', $_POST['wppa-widget-photo']);
        }
        if (isset($_POST['wppa-widget-method'])) {
            wppa_update_option('wppa_widget_method', $_POST['wppa-widget-method']);
        }
        if (isset($_POST['wppa-widget-period'])) {
            wppa_update_option('wppa_widget_period', $_POST['wppa-widget-period']);
        }
        if (isset($_POST['wppa-widget-subtitle'])) {
            wppa_update_option('wppa_widget_subtitle', $_POST['wppa-widget-subtitle']);
        }
        if (isset($_POST['wppa-widget-linkpage'])) {
            wppa_update_option('wppa_widget_linkpage', $_POST['wppa-widget-linkpage']);
        }
        if (isset($_POST['wppa-widget-linkurl'])) {
            wppa_update_option('wppa_widget_linkurl', $_POST['wppa-widget-linkurl']);
        }
        if (isset($_POST['wppa-widget-linktitle'])) {
            wppa_update_option('wppa_widget_linktitle', $_POST['wppa-widget-linktitle']);
        }
        if (isset($_POST['wppa-widget-linktype'])) {
            wppa_update_option('wppa_widget_linktype', $_POST['wppa-widget-linktype']);
        }
        if (wppa_check_numeric($_POST['wppa-potd-widget-width'], '100', __('Widget Photo Width.'))) {
            wppa_update_option('wppa_potd_widget_width', $_POST['wppa-potd-widget-width']);
        } else {
            $options_error = true;
        }
        if (!$options_error) {
            wppa_update_message(__('Changes Saved. Don\'t forget to activate the widget!', 'wppa'));
        }
    }
    wppa_initialize_runtime('force');
    ?>
	
	<div class="wrap">
		<?php 
    $iconurl = WPPA_URL . '/images/settings32.png';
    ?>
		<div id="icon-album" class="icon32" style="background: transparent url(<?php 
    echo $iconurl;
    ?>
) no-repeat">
			<br />
		</div>
		<h2><?php 
    _e('Photo of the Day Widget Settings', 'wppa');
    ?>
</h2>
		
		<form action="<?php 
    echo wppa_dbg_url(get_admin_url() . 'admin.php?page=wppa_photo_of_the_day');
    ?>
" method="post">
			<?php 
    wp_nonce_field('$wppa_nonce', WPPA_NONCE);
    ?>

			<table class="form-table wppa-table wppa-photo-table">
				<tbody>
					<tr valign="top">
						<th scope="row">
							<label ><?php 
    _e('Widget Title:', 'wppa');
    ?>
</label>
						</th>
						<td>
							<input type="text" name="wppa-widgettitle" id="wppa-widgettitle" value="<?php 
    echo wppa_opt('widgettitle');
    ?>
" />
							<span class="description"><br/><?php 
    _e('Enter/modify the title for the widget. This is a default and can be overriden at widget activation.', 'wppa');
    ?>
</span>
						</td>
					</tr>	
					
					<tr valign="top">
						<th scope="row">
							<label ><?php 
    _e('Widget Photo Width:', 'wppa');
    ?>
</label>
						</th>
						<td>
							<input type="text" name="wppa-potd-widget-width" id="wppa-potd-widget-width" value="<?php 
    echo wppa_opt('potd_widget_width');
    ?>
" style="width: 50px;" />
							<?php 
    _e('pixels.', 'wppa');
    echo ' ';
    _e('Horizontal alignment:', 'wppa');
    ?>
							<select name="wppa-potd-align" id="wppa-potd-align">
								<?php 
    $ali = wppa_opt('potd_align');
    ?>
								<?php 
    $sel = 'selected="selected"';
    ?>
								<option value="none" <?php 
    if ($ali == 'none') {
        echo $sel;
    }
    ?>
><?php 
    _e('--- none ---', 'wppa');
    ?>
</option>
								<option value="left" <?php 
    if ($ali == 'left') {
        echo $sel;
    }
    ?>
><?php 
    _e('left', 'wppa');
    ?>
</option>
								<option value="center" <?php 
    if ($ali == 'center') {
        echo $sel;
    }
    ?>
><?php 
    _e('center', 'wppa');
    ?>
</option>
								<option value="right" <?php 
    if ($ali == 'right') {
        echo $sel;
    }
    ?>
><?php 
    _e('right', 'wppa');
    ?>
</option>
							</select>
							<span class="description"><br/><?php 
    _e('Enter the desired display width and alignment of the photo in the sidebar.', 'wppa');
    ?>
</span>
						</td>
					</tr>

					<tr valign="top">
						<th scope="row">
							<label ><?php 
    _e('Use album(s):', 'wppa');
    ?>
</label>
						</th>
						<td>
							<script type="text/javascript">
							/* <![CDATA[ */
							function wppaCheckWa() {
								document.getElementById('wppa-spin').style.visibility = 'visible';
								document.getElementById('wppa-upd').style.visibility = 'hidden';
								var album = document.getElementById('wppa-wa').value;
								if ( album != 'all' && album != 'sep' && album != 'all-sep' && album != 'topten' && album != 'clr' )
									album = document.getElementById('wppa-was').value + ',' + album;
								var url = "<?php 
    echo wppa_dbg_url(get_admin_url() . 'admin.php?page=wppa_photo_of_the_day');
    ?>
&walbum=" + album;
								document.location.href = url;
							}
							/* ]]> */
							</script>
							<?php 
    _e('Select:', 'wppa');
    ?>
<select name="wppa-widget-album" id="wppa-wa" onchange="wppaCheckWa()" ><?php 
    echo wppa_walbum_select(wppa_opt('widget_album'));
    ?>
</select>
							<img id="wppa-spin" src="<?php 
    echo wppa_get_imgdir();
    ?>
wpspin.gif" style="visibility:hidden;"/>
							<?php 
    _e('Or Edit:', 'wppa');
    ?>
<input type="text" name="wppa-widget-albums" id="wppa-was" value="<?php 
    echo wppa_opt('widget_album');
    ?>
" />
							<input class="button-primary" name="wppa-upd" id="wppa-upd" value="<?php 
    _e('Update thumbnails', 'wppa');
    ?>
" onclick="wppaCheckWa()" />
							<span class="description"><br/>
								<?php 
    _e('Select or edit the album(s) you want to use the photos of for the widget.', 'wppa');
    ?>
								<br />
								<?php 
    _e('If you want a <b>- special -</b> selection or get rid of it, you may need to use <b>- start over -</b> first.', 'wppa');
    ?>
							</span>
						</td>
					</tr>
					<tr valign="top">
						<th scope="row">
							<label ><?php 
    _e('Display method:', 'wppa');
    ?>
</label>
						</th>
						<td>
							<?php 
    $sel = 'selected="selected"';
    ?>
							<?php 
    $method = wppa_opt('widget_method');
    ?>
							<select name="wppa-widget-method" id="wppa-wm" onchange="wppaCheckWidgetMethod()" >
								<option value="1" <?php 
    if ($method == '1') {
        echo $sel;
    }
    ?>
><?php 
    _e('Fixed photo', 'wppa');
    ?>
</option> 
								<option value="2" <?php 
    if ($method == '2') {
        echo $sel;
    }
    ?>
><?php 
    _e('Random', 'wppa');
    ?>
</option>
								<option value="3" <?php 
    if ($method == '3') {
        echo $sel;
    }
    ?>
><?php 
    _e('Last upload', 'wppa');
    ?>
</option>
								<option value="4" <?php 
    if ($method == '4') {
        echo $sel;
    }
    ?>
><?php 
    _e('Change every', 'wppa');
    ?>
</option>
							</select>
							<?php 
    $period = wppa_opt('widget_period');
    ?>
							<select name="wppa-widget-period" id="wppa-wp" >
								<option value="0" <?php 
    if ($period == '0') {
        echo $sel;
    }
    ?>
><?php 
    _e('pageview.', 'wppa');
    ?>
</option>
								<option value="1" <?php 
    if ($period == '1') {
        echo $sel;
    }
    ?>
><?php 
    _e('hour.', 'wppa');
    ?>
</option>
								<option value="24" <?php 
    if ($period == '24') {
        echo $sel;
    }
    ?>
><?php 
    _e('day.', 'wppa');
    ?>
</option>
								<option value="168" <?php 
    if ($period == '168') {
        echo $sel;
    }
    ?>
><?php 
    _e('week.', 'wppa');
    ?>
</option>
								<option value="736" <?php 
    if ($period == '736') {
        echo $sel;
    }
    ?>
><?php 
    _e('month.', 'wppa');
    ?>
</option>
								<option value="day-of-week" <?php 
    if ($period == 'day-of-week') {
        echo $sel;
    }
    ?>
><?php 
    _e('day of week is order#', 'wppa');
    ?>
</option>
								<option value="day-of-month" <?php 
    if ($period == 'day-of-month') {
        echo $sel;
    }
    ?>
><?php 
    _e('day of month is order#', 'wppa');
    ?>
</option>
							</select>
							<span class="description"><br/><?php 
    _e('Select how the widget should display.', 'wppa');
    ?>
</span>								
						</td>
					</tr>
<?php 
    $linktype = wppa_opt('widget_linktype');
    if ($linktype != 'custom') {
        ?>
						<tr>
							<th scope="row">
								<label ><?php 
        _e('Link to:', 'wppa');
        ?>
</label>
							</th>
							<td>
								<?php 
        _e('Links are set on the <b>Photo Albums -> Settings</b> screen.', 'wppa');
        ?>
							</td>
						</tr>
<?php 
    } else {
        ?>
						<tr class="wppa-wlu" >
							<th scope="row">
								<label ><?php 
        _e('Link to:', 'wppa');
        ?>
</label>
							</th>
							<td>
								<?php 
        _e('Title:', 'wppa');
        ?>
								<input type="text" name="wppa-widget-linktitle" id="wppa-widget-linktitle" value="<?php 
        echo wppa_opt('widget_linktitle');
        ?>
"style="width:20%" />
								<?php 
        _e('Url:', 'wppa');
        ?>
								<input type="text"  name="wppa-widget-linkurl" id="wppa-widget-linkurl" value="<?php 
        echo wppa_opt('widget_linkurl');
        ?>
" style="width:50%" />
								<span class="description"><br/><?php 
        _e('Enter the title and the url. Do\'nt forget the HTTP://', 'wppa');
        ?>
</span>
							</td>
						</tr>
<?php 
    }
    ?>
					<!--<script type="text/javascript">wppaCheckWidgetLink()</script>-->
					<tr>
						<th scope="row">
							<label ><?php 
    _e('Subtitle:', 'wppa');
    ?>
</label>
						</th>
						<td>
							<?php 
    $subtit = wppa_opt('widget_subtitle');
    ?>
							<select name="wppa-widget-subtitle" id="wppa-st" onchange="wppaCheckWidgetSubtitle()" >
								<option value="none" <?php 
    if ($subtit == 'none') {
        echo $sel;
    }
    ?>
><?php 
    _e('--- none ---', 'wppa');
    ?>
</option>
								<option value="name" <?php 
    if ($subtit == 'name') {
        echo $sel;
    }
    ?>
><?php 
    _e('Photo Name', 'wppa');
    ?>
</option>
								<option value="desc" <?php 
    if ($subtit == 'desc') {
        echo $sel;
    }
    ?>
><?php 
    _e('Description', 'wppa');
    ?>
</option>
								<option value="owner" <?php 
    if ($subtit == 'owner') {
        echo $sel;
    }
    ?>
><?php 
    _e('Owner', 'wppa');
    ?>
</option>
							</select>
							<span class="description"><br/><?php 
    _e('Select the content of the subtitle.', 'wppa');
    ?>
</span>	
						</td>
					</tr>
				</tbody>
			</table>
			<p>
				<input type="submit" class="button-primary" name="wppa-set-submit" value="<?php 
    _e('Save Changes', 'wppa');
    ?>
" />
			</p>
			<?php 
    $alb = wppa_opt('widget_album');
    $photos = wppa_get_widgetphotos($alb);
    if (empty($photos)) {
        echo '<p>' . __('No photos yet in this album.', 'wppa') . '</p>';
    } else {
        $curid = wppa_opt('widget_photo');
        $wi = wppa_get_minisize() + 24;
        $hi = $wi + 48;
        // Process photos
        foreach ($photos as $photo) {
            $id = $photo['id'];
            // Open container div
            echo '<div' . ' class="photoselect"' . ' style="' . 'width:' . wppa_opt('widget_width') . 'px;' . 'height:' . $hi . 'px;' . 'overflow:hidden;' . '" >';
            // The image if a video
            if (wppa_is_video($id)) {
                echo wppa_get_video_html(array('id' => $id, 'style' => 'width:' . wppa_opt('widget_width') . 'px;'));
            } else {
                echo '<img' . ' src=" ' . wppa_fix_poster_ext(wppa_get_thumb_url($id), $id) . '"' . ' style="' . 'width:' . wppa_opt('widget_width') . 'px;' . '"' . ' alt="' . $photo['name'] . '" />';
                // Audio ?
                if (wppa_has_audio($id)) {
                    echo wppa_get_audio_html(array('id' => $id, 'style' => 'width:' . wppa_opt('widget_width') . 'px;' . 'position:relative;' . 'bottom:' . (wppa_get_audio_control_height() + 4) . 'px;'));
                }
            }
            ?>
						<input type="radio" name="wppa-widget-photo" id="wppa-widget-photo<?php 
            echo $id;
            ?>
" value="<?php 
            echo $id;
            ?>
" <?php 
            if ($id == $curid) {
                echo 'checked="checked"';
            }
            ?>
/>
						<div class="clear"></div>
						<h4 style="position: absolute; top:<?php 
            echo $wi - 12;
            ?>
px; font-size:11px; overflow:hidden;"><?php 
            echo wppa_qtrans(stripslashes($photo['name']));
            ?>
</h4>
						<h6 style="position: absolute; top:<?php 
            echo $wi + 6;
            ?>
px; font-size:9px; line-height:10px;"><?php 
            echo wppa_qtrans(stripslashes($photo['description']));
            ?>
</h6>
						<h5 style="position: absolute; top:<?php 
            echo $wi + 24;
            ?>
px; font-size:9px; line-height:10px;"><?php 
            echo '(#' . $photo['p_order'] . ')';
            ?>
</h5>
						</div><?php 
        }
        echo '<div class="clear"></div>';
    }
    ?>
			<script type="text/javascript">wppaCheckWidgetMethod();</script>
			<script type="text/javascript">wppaCheckWidgetSubtitle();</script>
			<br />
			<p>
				<input type="submit" class="button-primary" name="wppa-set-submit" value="<?php 
    _e('Save Changes', 'wppa');
    ?>
" />
			</p>
		</form>
	</div>
<?php 
}
 /** @see WP_Widget::widget */
 function widget($args, $instance)
 {
     global $wpdb;
     global $wppa_opt;
     require_once dirname(__FILE__) . '/wppa-links.php';
     require_once dirname(__FILE__) . '/wppa-styles.php';
     require_once dirname(__FILE__) . '/wppa-functions.php';
     require_once dirname(__FILE__) . '/wppa-thumbnails.php';
     require_once dirname(__FILE__) . '/wppa-boxes-html.php';
     require_once dirname(__FILE__) . '/wppa-slideshow.php';
     wppa_initialize_runtime();
     wppa('in_widget', 'lasten');
     wppa_bump_mocc();
     extract($args);
     $instance = wp_parse_args((array) $instance, array('title' => '', 'album' => '', 'albumenum' => '', 'timesince' => 'yes', 'display' => 'thumbs', 'includesubs' => 'no'));
     $widget_title = apply_filters('widget_title', $instance['title']);
     $page = in_array(wppa_opt('lasten_widget_linktype'), wppa('links_no_page')) ? '' : wppa_get_the_landing_page('lasten_widget_linkpage', __('Last Ten Uploaded Photos', 'wp-photo-album-plus'));
     $max = wppa_opt('lasten_count');
     $album = $instance['album'];
     $timesince = $instance['timesince'];
     $display = $instance['display'];
     $albumenum = $instance['albumenum'];
     $subs = $instance['includesubs'] == 'yes';
     switch ($album) {
         case '-99':
             // 'Multiple see below' is a list of id, seperated by comma's
             $album = str_replace(',', '.', $albumenum);
             if ($subs) {
                 $album = wppa_expand_enum(wppa_alb_to_enum_children($album));
             }
             $album = str_replace('.', ',', $album);
             break;
         case '0':
             // ---all---
             break;
         case '-2':
             // ---generic---
             $albs = $wpdb->get_results("SELECT `id` FROM `" . WPPA_ALBUMS . "` WHERE `a_parent` = '0'", ARRAY_A);
             $album = '';
             foreach ($albs as $alb) {
                 $album .= '.' . $alb['id'];
             }
             $album = ltrim($album, '.');
             if ($subs) {
                 $album = wppa_expand_enum(wppa_alb_to_enum_children($album));
             }
             $album = str_replace('.', ',', $album);
             break;
         default:
             if ($subs) {
                 $album = wppa_expand_enum(wppa_alb_to_enum_children($album));
                 $album = str_replace('.', ',', $album);
             }
             break;
     }
     $album = trim($album, ',');
     // Eiter look at timestamp or at date/time modified
     $order_by = wppa_switch('lasten_use_modified') ? 'modified' : 'timestamp';
     // If you want only 'New' photos in the selection, the period must be <> 0;
     if (wppa_switch('lasten_limit_new') && wppa_opt('max_photo_newtime')) {
         $newtime = " `" . $order_by . "` >= " . (time() - wppa_opt('max_photo_newtime'));
         if ($album) {
             $q = "SELECT * FROM `" . WPPA_PHOTOS . "` WHERE (" . $newtime . ") AND `album` IN ( " . $album . " ) AND ( `status` <> 'pending' AND `status` <> 'scheduled' ) ORDER BY `" . $order_by . "` DESC LIMIT " . $max;
         } else {
             $q = "SELECT * FROM `" . WPPA_PHOTOS . "` WHERE (" . $newtime . ") AND `status` <> 'pending' AND `status` <> 'scheduled' ORDER BY `" . $order_by . "` DESC LIMIT " . $max;
         }
     } else {
         if ($album) {
             $q = "SELECT * FROM `" . WPPA_PHOTOS . "` WHERE `album` IN ( " . $album . " ) AND ( `status` <> 'pending' AND `status` <> 'scheduled' ) ORDER BY `" . $order_by . "` DESC LIMIT " . $max;
         } else {
             $q = "SELECT * FROM `" . WPPA_PHOTOS . "` WHERE `status` <> 'pending' AND `status` <> 'scheduled' ORDER BY `" . $order_by . "` DESC LIMIT " . $max;
         }
     }
     $thumbs = $wpdb->get_results($q, ARRAY_A);
     $widget_content = "\n" . '<!-- WPPA+ LasTen Widget start -->';
     $maxw = wppa_opt('lasten_size');
     $maxh = $maxw;
     $lineheight = wppa_opt('fontsize_widget_thumb') * 1.5;
     $maxh += $lineheight;
     if ($timesince == 'yes') {
         $maxh += $lineheight;
     }
     $count = '0';
     if ($thumbs) {
         foreach ($thumbs as $image) {
             $thumb = $image;
             // Make the HTML for current picture
             if ($display == 'thumbs') {
                 $widget_content .= "\n" . '<div class="wppa-widget" style="width:' . $maxw . 'px; height:' . $maxh . 'px; margin:4px; display:inline; text-align:center; float:left;">';
             } else {
                 $widget_content .= "\n" . '<div class="wppa-widget" >';
             }
             if ($image) {
                 $no_album = !$album;
                 if ($no_album) {
                     $tit = __('View the most recent uploaded photos', 'wp-photo-album-plus');
                 } else {
                     $tit = esc_attr(__(stripslashes($image['description'])));
                 }
                 $link = wppa_get_imglnk_a('lasten', $image['id'], '', $tit, '', $no_album, str_replace(',', '.', $album));
                 $file = wppa_get_thumb_path($image['id']);
                 $imgstyle_a = wppa_get_imgstyle_a($image['id'], $file, $maxw, 'center', 'ltthumb');
                 $imgurl = wppa_get_thumb_url($image['id'], '', $imgstyle_a['width'], $imgstyle_a['height']);
                 $imgevents = wppa_get_imgevents('thumb', $image['id'], true);
                 $title = $link ? esc_attr(stripslashes($link['title'])) : '';
                 $widget_content .= wppa_get_the_widget_thumb('lasten', $image, $album, $display, $link, $title, $imgurl, $imgstyle_a, $imgevents);
                 $widget_content .= "\n\t" . '<div style="font-size:' . wppa_opt('fontsize_widget_thumb') . 'px; line-height:' . $lineheight . 'px;">';
                 if ($timesince == 'yes') {
                     $widget_content .= "\n\t" . '<div>' . wppa_get_time_since($image[$order_by]) . '</div>';
                 }
                 $widget_content .= '</div>';
             } else {
                 // No image
                 $widget_content .= __('Photo not found', 'wp-photo-album-plus');
             }
             $widget_content .= "\n" . '</div>';
             $count++;
             if ($count == wppa_opt('lasten_count')) {
                 break;
             }
         }
     } else {
         $widget_content .= __('There are no uploaded photos (yet)', 'wp-photo-album-plus');
     }
     $widget_content .= '<div style="clear:both"></div>';
     $widget_content .= "\n" . '<!-- WPPA+ LasTen Widget end -->';
     echo "\n" . $before_widget;
     if (!empty($widget_title)) {
         echo $before_title . $widget_title . $after_title;
     }
     echo $widget_content . $after_widget;
     wppa('in_widget', false);
 }
function wppa_do_maintenance_popup($slug)
{
    global $wpdb;
    $result = '';
    switch ($slug) {
        case 'wppa_list_index':
            $start = get_option('wppa_list_index_display_start', '');
            $total = $wpdb->get_var("SELECT COUNT(*) FROM `" . WPPA_INDEX . "`");
            $indexes = $wpdb->get_results($wpdb->prepare("SELECT * FROM `" . WPPA_INDEX . "` WHERE `slug` >= %s ORDER BY `slug` LIMIT 1000", $start), ARRAY_A);
            $result .= '
			<style>td, th { border-right: 1px solid darkgray; } </style>
			<h2>List of Searcheable words <small>( Max 1000 entries of total ' . $total . ' )</small></h2>
			<div style="float:left; clear:both; width:100%; overflow:auto; background-color:#f1f1f1; border:1px solid #ddd;" >';
            if ($indexes) {
                $result .= '
				<table>
					<thead>
						<tr>
							<th><span style="float:left;" >Word</span></th>
							<th style="max-width:400px;" ><span style="float:left;" >Albums</span></th>
							<th><span style="float:left;" >Photos</span></th>
						</tr>
						<tr><td colspan="3"><hr /></td></tr>
					</thead>
					<tbody>';
                foreach ($indexes as $index) {
                    $result .= '
						<tr>
							<td>' . $index['slug'] . '</td>
							<td style="max-width:400px; word-wrap: break-word;" >' . $index['albums'] . '</td>
							<td>' . $index['photos'] . '</td>
						</tr>';
                }
                $result .= '
					</tbody>
				</table>';
            } else {
                $result .= __('There are no index items.', 'wp-photo-album-plus');
            }
            $result .= '
				</div><div style="clear:both;"></div>';
            break;
        case 'wppa_list_errorlog':
            $filename = WPPA_CONTENT_PATH . '/wppa-depot/admin/error.log';
            $result .= '
				<h2>List of WPPA+ error messages</h2>
				<div style="float:left; clear:both; width:100%; overflow:auto; word-wrap:none; background-color:#f1f1f1; border:1px solid #ddd;" >';
            if (!($file = @fopen($filename, 'r'))) {
                $result .= __('There are no error log messages', 'wp-photo-album-plus');
            } else {
                $size = filesize($filename);
                $data = fread($file, $size);
                $data = htmlspecialchars(strip_tags($data));
                $data = str_replace(array('{b}', '{/b}', "\n"), array('<b>', '</b>', '<br />'), $data);
                $result .= $data;
                fclose($file);
            }
            $result .= '
				</div><div style="clear:both;"></div>
				';
            break;
        case 'wppa_list_rating':
            $total = $wpdb->get_var("SELECT COUNT(*) FROM `" . WPPA_RATING . "`");
            $ratings = $wpdb->get_results("SELECT * FROM `" . WPPA_RATING . "` ORDER BY `timestamp` DESC LIMIT 1000", ARRAY_A);
            $result .= '
			<style>td, th { border-right: 1px solid darkgray; } </style>
			<h2>List of recent ratings <small>( Max 1000 entries of total ' . $total . ' )</small></h2>
			<div style="float:left; clear:both; width:100%; overflow:auto; background-color:#f1f1f1; border:1px solid #ddd;" >';
            if ($ratings) {
                $result .= '
				<table>
					<thead>
						<tr>
							<th>Id</th>
							<th>Timestamp</th>
							<th>Date/time</th>
							<th>Status</th>
							<th>User</th>
							<th>Value</th>
							<th>Photo id</th>
							<th></th>
							<th># ratings</th>
							<th>Average</th>
						</tr>
						<tr><td colspan="10"><hr /></td></tr>
					</thead>
					<tbody>';
                foreach ($ratings as $rating) {
                    $thumb = wppa_cache_thumb($rating['photo']);
                    $result .= '
						<tr>
							<td>' . $rating['id'] . '</td>
							<td>' . $rating['timestamp'] . '</td>
							<td>' . ($rating['timestamp'] ? wppa_local_date(get_option('date_format', "F j, Y,") . ' ' . get_option('time_format', "g:i a"), $rating['timestamp']) : 'pre-historic') . '</td>
							<td>' . $rating['status'] . '</td>
							<td>' . $rating['user'] . '</td>
							<td>' . $rating['value'] . '</td>
							<td>' . $rating['photo'] . '</td>
							<td style="width:250px; text-align:center;"><img src="' . wppa_get_thumb_url($rating['photo']) . '"
								style="height: 40px;"
								onmouseover="jQuery(this).stop().animate({height:this.naturalHeight}, 200);"
								onmouseout="jQuery(this).stop().animate({height:\'40px\'}, 200);" /></td>
							<td>' . $thumb['rating_count'] . '</td>
							<td>' . $thumb['mean_rating'] . '</td>
						</tr>';
                }
                $result .= '
					</tbody>
				</table>';
            } else {
                $result .= __('There are no ratings', 'wp-photo-album-plus');
            }
            $result .= '
				</div><div style="clear:both;"></div>';
            break;
        case 'wppa_list_session':
            $total = $wpdb->get_var("SELECT COUNT(*) FROM `" . WPPA_SESSION . "` WHERE `status` = 'valid'");
            $sessions = $wpdb->get_results("SELECT * FROM `" . WPPA_SESSION . "` WHERE `status` = 'valid' ORDER BY `id` DESC LIMIT 1000", ARRAY_A);
            $result .= '
			<style>td, th { border-right: 1px solid darkgray; } </style>
			<h2>List of active sessions <small>( Max 1000 entries of total ' . $total . ' )</small></h2>
			<div style="float:left; clear:both; width:100%; overflow:auto; background-color:#f1f1f1; border:1px solid #ddd;" >';
            if ($sessions) {
                $result .= '
				<table>
					<thead>
						<tr>
							<th>Id</th>
							<th>Session id</th>
							<th>IP</th>
							<th>Started</th>
							<th>Count</th>
							<th>Data</th>
						</tr>
						<tr><td colspan="14"><hr /></td></tr>
					</thead>
					<tbody>';
                foreach ($sessions as $session) {
                    $data = unserialize($session['data']);
                    $result .= '
							<tr>
								<td>' . $session['id'] . '</td>
								<td>' . $session['session'] . '</td>
								<td>' . $session['ip'] . '</td>
								<td style="width:150px;" >' . wppa_local_date(get_option('date_format', "F j, Y,") . ' ' . get_option('time_format', "g:i a"), $session['timestamp']) . '</td>
								<td>' . $session['count'] . '</td>' . '<td style="border-bottom:1px solid gray;" >';
                    foreach (array_keys($data) as $key) {
                        if (is_array($data[$key])) {
                            $result .= '[' . $key . '] => Array(' . implode(',', array_keys($data[$key])) . ')<br />';
                        } else {
                            $result .= '[' . $key . '] => ' . $data[$key] . '<br />';
                        }
                    }
                    '</td>
							</tr>';
                }
                $result .= '
					</tbody>
				</table>';
            } else {
                $result .= __('There are no active sessions', 'wp-photo-album-plus');
            }
            $result .= '
				</div><div style="clear:both;"></div>';
            break;
        default:
            $result = 'Error: Unimplemented slug: ' . $slug . ' in wppa_do_maintenance_popup()';
    }
    return $result;
}