function wppa_get_thumb_default($id)
{
    global $wpdb;
    // Validate args
    if (!wppa_is_int($id) || $id < '0') {
        wppa_dbg_msg('Please check file wppa-theme.php or any other php file that calls wppa_get_thumb_default(). Argument 1: photo id is missing or illegal!', 'red', 'force');
        die('Please check your configuration');
    }
    // Initialize
    $result = '';
    // Encrypted photo id
    $xid = wppa_encrypt_photo($id);
    // Get the photo info
    $thumb = wppa_cache_thumb($id);
    // Get the album info
    $album = wppa_cache_album($thumb['album']);
    wppa('current_album', $album['id']);
    // Get photo info
    $is_video = wppa_is_video($id);
    $has_audio = wppa_has_audio($id);
    $com_alt = wppa('is_comten') && wppa_switch('comten_alt_display') && !wppa_in_widget();
    $frameattr_a = wppa_get_thumb_frame_style_a();
    $framestyle = $frameattr_a['style'];
    $framewidth = $frameattr_a['width'];
    $frameheight = $frameattr_a['height'];
    // Get class depending of comment alt display
    if ($com_alt) {
        $class = 'thumbnail-frame-comalt thumbnail-frame-comalt-' . wppa('mocc') . ' thumbnail-frame-photo-' . $xid;
    } else {
        $class = 'thumbnail-frame thumbnail-frame-' . wppa('mocc') . ' thumbnail-frame-photo-' . $xid;
    }
    // If no image to display, die gracefully
    $imgsrc = wppa_fix_poster_ext(wppa_get_thumb_path($id), $id);
    if (!wppa_is_video($id) && !is_file($imgsrc) && !wppa_has_audio($id)) {
        $result .= '<div' . ' class="' . $class . '"' . ' style="' . $framestyle . '; color:red;" >' . 'Missing thumbnail image #' . $id . '</div>';
        return $result;
    }
    // Find image attributes
    $alt = $album['alt_thumbsize'] == 'yes' ? '_alt' : '';
    $imgattr_a = wppa_get_imgstyle_a($id, $imgsrc, wppa_opt('thumbsize' . $alt), 'optional', 'thumb');
    $imgstyle = $imgattr_a['style'];
    $imgwidth = $imgattr_a['width'];
    $imgheight = $imgattr_a['height'];
    $imgmargintop = $imgattr_a['margin-top'];
    $imgmarginbottom = $imgattr_a['margin-bottom'];
    // Special case for comment alt display
    if ($com_alt) {
        $imgwidth = wppa_opt('comten_alt_thumbsize');
        $imgheight = round($imgwidth * $imgattr_a['height'] / $imgattr_a['width']);
        $imgstyle .= 'float:left; margin:0 20px 8px 0;width:' . $imgwidth . 'px; height:' . $imgheight . 'px;';
    }
    // Cursor depends on link
    $cursor = $imgattr_a['cursor'];
    // Find the required image sizes
    if (wppa_switch('use_thumb_popup')) {
        // Landscape?
        if ($imgwidth > $imgheight) {
            $popwidth = wppa_opt('popupsize');
            $popheight = round($popwidth * $imgheight / $imgwidth);
        } else {
            $popheight = wppa_opt('popupsize');
            $popwidth = round($popheight * $imgwidth / $imgheight);
        }
    } else {
        $popwidth = $imgwidth;
        $popheight = $imgheight;
    }
    // More image attributes
    $imgurl = wppa_fix_poster_ext(wppa_get_thumb_url($id, '', $popwidth, $popheight), $id);
    $events = wppa_get_imgevents('thumb', $id);
    $imgalt = wppa_get_imgalt($id);
    // returns something like ' alt="Any text" '
    $title = esc_attr(wppa_get_photo_name($id));
    // Feed ?
    if (is_feed()) {
        $imgattr_a = wppa_get_imgstyle_a($id, $imgsrc, '100', '4', 'thumb');
        $style = $imgattr_a['style'];
        $result .= '<a href="' . get_permalink() . '">' . '<img src="' . $imgurl . '" ' . $imgalt . ' title="' . $title . '" style="' . $style . '" />' . '</a>';
        return $result;
    }
    // Open Com alt wrapper
    if ($com_alt) {
        $result .= '<div>';
    }
    // Open the thumbframe
    $result .= '<div' . ' id="thumbnail_frame_' . $xid . '_' . wppa('mocc') . '"' . ' class="' . $class . '"' . ' style="' . $framestyle . '"' . ' >';
    // Open the image container
    $imgcontheight = $com_alt ? $imgheight : max($imgwidth, $imgheight);
    if (!is_file($imgsrc) && !wppa_is_video($id)) {
        $imgcontheight = 2 * wppa_get_audio_control_height();
    }
    if ($com_alt) {
        $framewidth = $imgwidth + '4';
    }
    $result .= '<div' . ' class="wppa-tn-img-container"' . ' style="' . 'height:' . $imgcontheight . 'px;' . 'width:' . $framewidth . 'px;' . ($com_alt ? 'float:left;' : '') . 'overflow:hidden;"' . '>';
    // The medals if at the top
    $medalsize = $com_alt ? 'S' : 'M';
    $result .= wppa_get_medal_html_a(array('id' => $id, 'size' => $medalsize, 'where' => 'top'));
    // The audio when no popup
    if (wppa_switch('thumb_audio') && wppa_has_audio($id) && !$com_alt) {
        $result .= '<div style="position:relative;z-index:11;">';
        $is_safari = strpos($_SERVER["HTTP_USER_AGENT"], 'Safari');
        $cont_h = $is_safari ? 16 : 28;
        $audiotop = $imgattr_a['height'] + $imgattr_a['margin-top'] - $cont_h;
        if (!is_file($imgsrc)) {
            // Audio without image
            $audiotop = wppa_get_audio_control_height();
            $imgwidth = wppa_opt('tf_width');
            $imgheight = wppa_get_audio_control_height();
        }
        $result .= wppa_get_audio_html(array('id' => $id, 'width' => $imgwidth, 'height' => $cont_h, 'style' => 'position:absolute;top:' . $audiotop . 'px;left:0;border:none;'));
        $result .= '</div>';
    }
    // Get the image link
    if (wppa('is_topten')) {
        $no_album = !wppa('start_album');
        if ($no_album) {
            $tit = __('View the top rated photos', 'wp-photo-album-plus');
        } else {
            $tit = esc_attr(__(stripslashes($thumb['description'])));
        }
        $link = wppa_get_imglnk_a('thumb', $id, '', $tit, '', $no_album);
    } else {
        $link = wppa_get_imglnk_a('thumb', $id);
    }
    // voor parent uplr
    // See if ajax possible
    if ($link) {
        // Is link an url?
        if ($link['is_url']) {
            if (wppa_switch('allow_ajax') && wppa_opt('thumb_linktype') == 'photo' && wppa_opt('thumb_linkpage') == '0' && !wppa_switch('thumb_blank') && !(wppa_switch('thumb_overrule') && $thumb['linkurl']) && !wppa('is_topten') && !wppa('is_lasten') && !wppa('is_comten') && !wppa('is_featen') && !wppa('is_tag') && !wppa('is_upldr') && !wppa('src') && !wppa('supersearch') && (wppa_is_int(wppa('start_album')) || wppa('start_album') == '')) {
                // Ajax	possible
                // The a img ajax
                $p = wppa('calendar') ? '' : '&amp;wppa-photo=' . $xid;
                $onclick = 'wppaDoAjaxRender( ' . wppa('mocc') . ', \'' . wppa_encrypt_url(wppa_get_slideshow_url_ajax(wppa('start_album'), '0')) . '&amp;wppa-photo=' . $xid . '\', \'' . wppa_convert_to_pretty(wppa_encrypt_url(wppa_get_slideshow_url(wppa('start_album'), '0') . $p)) . '\' )';
                $result .= '<a style="position:static;" class="thumb-img" id="x-' . $xid . '-' . wppa('mocc') . '">';
                // Video?
                if ($is_video) {
                    $result .= wppa_get_video_html(array('id' => $id, 'width' => $imgwidth, 'height' => $imgheight, 'controls' => wppa_switch('thumb_video'), 'margin_top' => '0', 'margin_bottom' => '0', 'tagid' => 'i-' . $id . '-' . wppa('mocc'), 'cursor' => 'cursor:pointer;', 'events' => $events, 'title' => $title, 'preload' => 'metadata', 'onclick' => $onclick, 'lb' => false, 'class' => '', 'style' => $imgstyle));
                } else {
                    $result .= '<img' . ' onclick="' . $onclick . '"' . ' id="i-' . $xid . '-' . wppa('mocc') . '"' . ' src="' . $imgurl . '"' . ' ' . $imgalt . ($title ? ' title="' . $title . '"' : '') . ' width="' . $imgwidth . '"' . ' height="' . $imgheight . '"' . ' style="' . $imgstyle . ' cursor:pointer;"' . ' ' . $events . ' />';
                }
                // Close the a img ajax
                $result .= '</a>';
            } else {
                // The a img non ajax
                $result .= '<a style="position:static;" href="' . $link['url'] . '" target="' . $link['target'] . '" class="thumb-img" id="x-' . $xid . '-' . wppa('mocc') . '">';
                if ($is_video) {
                    $result .= wppa_get_video_html(array('id' => $id, 'width' => $imgwidth, 'height' => $imgheight, 'controls' => wppa_switch('thumb_video'), 'margin_top' => '0', 'margin_bottom' => '0', 'tagid' => 'i-' . $xid . '-' . wppa('mocc'), 'cursor' => 'cursor:pointer;', 'events' => $events, 'title' => $title, 'preload' => 'metadata', 'onclick' => '', 'lb' => false, 'class' => '', 'style' => $imgstyle));
                } else {
                    $result .= '<img' . ' id="i-' . $xid . '-' . wppa('mocc') . '"' . ' src="' . $imgurl . '" ' . $imgalt . ($title ? ' title="' . $title . '"' : '') . ' width="' . $imgwidth . '"' . ' height="' . $imgheight . '"' . ' style="' . $imgstyle . ' cursor:pointer;"' . ' ' . $events . ' />';
                }
                // Close the img non ajax
                $result .= '</a>';
            }
        } elseif ($link['is_lightbox']) {
            $title = wppa_get_lbtitle('thumb', $id);
            // The a img
            $result .= '<a href="' . $link['url'] . '" target="' . $link['target'] . '"' . ($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') . '[occ' . wppa('mocc') . ']"' . ' ' . wppa('lbtitle') . '="' . $title . '" ' . ' class="thumb-img" id="x-' . $xid . '-' . wppa('mocc') . '"' . ' data-alt="' . esc_attr(wppa_get_imgalt($id, true)) . '"' . ' >';
            if ($is_video) {
                $result .= wppa_get_video_html(array('id' => $id, 'width' => $imgwidth, 'height' => $imgheight, 'controls' => wppa_switch('thumb_video'), 'margin_top' => '0', 'margin_bottom' => '0', 'tagid' => 'i-' . $xid . '-' . wppa('mocc'), 'cursor' => $cursor, 'events' => $events, 'title' => wppa_zoom_in($id), 'preload' => 'metadata', 'onclick' => '', 'lb' => false, 'class' => '', 'style' => $imgstyle));
            } else {
                $title = wppa_zoom_in($id);
                $result .= '<img' . ' id="i-' . $xid . '-' . wppa('mocc') . '"' . ' src="' . $imgurl . '"' . ' ' . $imgalt . ($title ? ' title="' . $title . '"' : '') . ' width="' . $imgwidth . '"' . ' height="' . $imgheight . '"' . ' style="' . $imgstyle . $cursor . '"' . ' ' . $events . ' />';
            }
            // Close the a img
            $result .= '</a>';
        } else {
            // is onclick
            // The div img
            $result .= '<div onclick="' . $link['url'] . '" class="thumb-img" id="x-' . $xid . '-' . wppa('mocc') . '">';
            if ($is_video) {
                $result .= wppa_get_video_html(array('id' => $id, 'width' => $imgwidth, 'height' => $imgheight, 'controls' => wppa_switch('thumb_video'), 'margin_top' => '0', 'margin_bottom' => '0', 'tagid' => 'i-' . $xid . '-' . wppa('mocc'), 'cursor' => 'cursor:pointer;', 'events' => $events, 'title' => $title, 'preload' => 'metadata', 'onclick' => '', 'lb' => false, 'class' => '', 'style' => $imgstyle));
            } else {
                $result .= '<img' . ' id="i-' . $xid . '-' . wppa('mocc') . '"' . ' src="' . $imgurl . '"' . ' ' . $imgalt . ($title ? ' title="' . $title . '"' : '') . ' width="' . $imgwidth . '"' . ' height="' . $imgheight . '"' . ' style="' . $imgstyle . ' cursor:pointer;"' . ' ' . $events . ' />';
            }
            $result .= '</div>';
            $result .= '<script type="text/javascript">';
            $result .= '/* <![CDATA[ */';
            $result .= 'wppaPopupOnclick[' . $id . '] = "' . $link['url'] . '";';
            $result .= '/* ]]> */';
            $result .= '</script>';
        }
    } else {
        // no link
        if (wppa_switch('use_thumb_popup')) {
            $result .= '<div id="x-' . $xid . '-' . wppa('mocc') . '">';
            if ($is_video) {
                $result .= wppa_get_video_html(array('id' => $id, 'width' => $imgwidth, 'height' => $imgheight, 'controls' => false, 'margin_top' => '0', 'margin_bottom' => '0', 'tagid' => 'i-' . $xid . '-' . wppa('mocc'), 'cursor' => '', 'events' => $events, 'title' => $title, 'preload' => 'metadata', 'onclick' => '', 'lb' => false, 'class' => '', 'style' => $imgstyle));
            } else {
                $result .= '<img' . ' src="' . $imgurl . '"' . ' ' . $imgalt . ($title ? ' title="' . $title . '"' : '') . ' width="' . $imgwidth . '"' . ' height="' . $imgheight . '"' . ' style="' . $imgstyle . '"' . ' ' . $events . ' />';
            }
            $result .= '</div>';
        } else {
            if ($is_video) {
                $result .= wppa_get_video_html(array('id' => $id, 'width' => $imgwidth, 'height' => $imgheight, 'controls' => wppa_switch('thumb_video'), 'margin_top' => '0', 'margin_bottom' => '0', 'tagid' => 'i-' . $id . '-' . wppa('mocc'), 'cursor' => '', 'events' => $events, 'title' => $title, 'preload' => 'metadata', 'onclick' => '', 'lb' => false, 'class' => '', 'style' => $imgstyle));
            } else {
                $result .= '<img' . ' src="' . $imgurl . '"' . ' ' . $imgalt . ($title ? ' title="' . $title . '"' : '') . ' width="' . $imgwidth . '"' . ' height="' . $imgheight . '"' . ' style="' . $imgstyle . '"' . ' ' . $events . ' />';
            }
        }
    }
    // The medals if near the bottom
    $result .= wppa_get_medal_html_a(array('id' => $id, 'size' => $medalsize, 'where' => 'bot'));
    // Close the image container
    $result .= '</div>';
    /*
    	// The audio when popup
    	if ( wppa_switch( 'use_thumb_popup' ) && wppa_switch( 'thumb_audio' ) && wppa_has_audio( $id ) && ! $com_alt ) {
    		$result .= wppa_get_audio_html( array(
    							'id' 		=> $id,
    							'width'		=> $imgwidth
    							));
    	}
    */
    // Comten alt display?
    if ($com_alt) {
        $comaltwidth = wppa_get_container_width() - $imgwidth - 16 - wppa_get_thumbnail_area_delta();
        $result .= '<div' . ' class="wppa-com-alt wppa-com-alt-' . wppa('mocc') . '"' . ' style="' . 'height:' . $imgheight . 'px;' . 'overflow:auto;' . 'margin: 0 0 8px 10px;' . 'border:1px solid ' . wppa_opt('bcolor_alt') . ';' . 'width:' . $comaltwidth . 'px;' . '"' . ' >';
        $comments = $wpdb->get_results($wpdb->prepare("SELECT * FROM `" . WPPA_COMMENTS . "` WHERE `photo` = %s AND `status` = 'approved' ORDER BY `timestamp` DESC", $id), ARRAY_A);
        $first = true;
        if ($comments) {
            foreach ($comments as $com) {
                $result .= '<h6' . ' style="' . 'font-size:10px;' . 'line-height:12px;' . 'font-weight:bold;' . 'padding:' . ($first ? '0' : '6px') . ' 0 0 6px;' . 'margin:0;float:left;' . '"' . '>' . $com['user'] . ' ' . __('wrote', 'wp-photo-album-plus') . ' ' . wppa_get_time_since($com['timestamp']) . ':' . '</h6>' . '<p' . ' style="' . 'font-size:10px;' . 'line-height:12px;' . 'padding:0 0 0 6px;' . 'text-align:left;' . 'margin:0;' . 'clear:left;' . '"' . '>' . html_entity_decode(convert_smilies(stripslashes($com['comment']))) . '</p>';
                $first = false;
            }
        }
        $result .= '</div>';
    } else {
        // Open the subtext container
        $margtop = wppa_switch('align_thumbtext') ? '' : 'margin-top:' . -$imgmarginbottom . 'px;';
        $subtextcontheight = $frameheight - max($imgwidth, $imgheight);
        if (!wppa_switch('align_thumbtext')) {
            $subtextcontheight += $imgmarginbottom;
        }
        $result .= '<div' . ' class="thumbnail-subtext-frame"' . ' style="' . 'height:' . $subtextcontheight . 'px;' . 'width:' . $framewidth . 'px;' . 'position:absolute;' . $margtop . 'overflow:hidden;' . '" >';
        // Single button voting system
        if (wppa_opt('rating_max') == '1' && wppa_switch('vote_thumb')) {
            $mylast = $wpdb->get_row($wpdb->prepare('SELECT * FROM `' . WPPA_RATING . '` WHERE `photo` = %s AND `user` = %s ORDER BY `id` DESC LIMIT 1', $id, wppa_get_user()), ARRAY_A);
            // Likes
            if (wppa_opt('rating_display_type') == 'likes') {
                $lt = wppa_get_like_title_a($id);
                $src = $lt['mine'] ? wppa_get_imgdir() . 'thumbdown.png' : wppa_get_imgdir() . 'thumbup.png';
                $result .= '<div' . ' id="wppa-like-imgdiv-' . wppa('mocc') . '"' . ' style="display:inline"' . ' >' . '<img' . ' id="wppa-like-' . $id . '-' . wppa('mocc') . '"' . ' src="' . $src . '"' . ' alt="up"' . ' title="' . esc_attr($lt['title']) . '"' . ' style="height:16px; margin:0 0 -3px 0; padding:0 4px; box-shadow:none; display:inline;"' . ' class="no-shadow"' . ' onmouseover="jQuery(this).stop().fadeTo(100, 1.0);"' . ' onmouseout="jQuery(this).stop().fadeTo(100, wppaStarOpacity);"' . ' onclick="wppaOvlRateIt( \'' . wppa_encrypt_photo($id) . '\', 1, ' . wppa('mocc') . ' );' . '"' . ' onload="jQuery(this).trigger(\'onmouseout\');"' . ' />';
                if (wppa_switch('show_avg_rating')) {
                    $result .= '<span' . ' id="wppa-liketext-' . $id . '-' . wppa('mocc') . '"' . ' class="wppa-thumb-text"' . ' style="' . __wcs('wppa-thumb-text') . '"' . '> ' . $lt['display'] . '</span>';
                }
                $result .= '</div>';
            } else {
                $buttext = $mylast ? __(wppa_opt('voted_button_text'), 'wp-photo-album-plus') : __(wppa_opt('vote_button_text'), 'wp-photo-album-plus');
                $result .= '<input' . ' id="wppa-vote-button-' . wppa('mocc') . '-' . $xid . '"' . ' class="wppa-vote-button-thumb"' . ' style="margin:0;"' . ' type="button"' . ' onclick="wppaVoteThumb( ' . wppa('mocc') . ', \'' . $xid . '\' )"' . ' value="' . $buttext . '"' . ' />';
            }
        }
        // Name
        if (wppa_switch('thumb_text_name') || wppa_switch('thumb_text_owner')) {
            $result .= '<div' . ' class="wppa-thumb-text"' . ' style="' . __wcs('wppa-thumb-text') . '"' . ' >' . wppa_get_photo_name($id, wppa_switch('thumb_text_owner'), false, false, wppa_switch('thumb_text_name')) . '</div>';
        }
        // searching, link to album
        //		if ( wppa( 'src' ) || wppa( 'supersearch' ) || ( ( wppa( 'is_comten') || wppa( 'is_topten' ) || wppa( 'is_lasten' ) || wppa( 'is_featen') ) && wppa( 'start_album' ) != $thumb['album'] ) ) {
        if (wppa_switch('thumb_text_virt_album') && wppa_is_virtual() && wppa('start_album') != $thumb['album']) {
            $result .= '<div' . ' class="wppa-thumb-text"' . ' style="' . __wcs('wppa-thumb-text') . '"' . ' >' . '<a' . ' href="' . wppa_get_album_url($thumb['album']) . '"' . ' >' . '<span class="wppa-tnpar" >(</span>' . stripslashes(__(wppa_get_album_name($thumb['album']), 'wp-photo-album-plus')) . '<span class="wppa-tnpar" >)</span>' . '</a>' . '</div>';
        }
        // Share
        if (wppa_switch('share_on_thumbs')) {
            $result .= '<div' . ' class="wppa-thumb-text"' . ' style="' . __wcs('wppa-thumb-text') . '"' . ' >' . wppa_get_share_html($id, 'thumb') . '</div>';
        }
        // Delete and Edit links
        if (wppa_switch('edit_thumb')) {
            // Open the div
            $result .= '<div' . ' class="wppa-thumb-text"' . ' style="' . __wcs('wppa-thumb-text') . '"' . ' >';
            // The admins choice link
            if (wppa_user_is('administrator') && wppa_switch('enable_admins_choice')) {
                $result .= '<span' . ' id="admin-choice-' . wppa_encrypt_photo($thumb['id']) . '-' . wppa('mocc') . '"' . ' style="color:gray;"' . ' >';
                if (!wppa_is_photo_in_zip($thumb['id'])) {
                    $result .= '<a' . ' style="color:blue;cursor:pointer;"' . ' onclick="' . esc_attr('if ( confirm( "' . __('Are you sure you want to add this photo to your zip?', 'wp-photo-album-plus') . '" ) ) ' . 'wppaAjaxAddPhotoToZip( ' . wppa('mocc') . ', \'' . wppa_encrypt_photo($thumb['id']) . '\', false ); return false;') . '"' . '>' . __('MyChoice', 'wp-photo-album-plus') . '</a>';
                } else {
                    $result .= __('Selected', 'wp-photo-album-plus');
                }
                $result .= '</span>&nbsp;';
            }
            // The delete link
            if (wppa_may_user_fe_delete($id)) {
                $result .= '<a' . ' style="color:red;cursor:pointer;"' . ' onclick="' . esc_attr('if ( confirm( "' . __('Are you sure you want to remove this photo?', 'wp-photo-album-plus') . '" ) ) wppaAjaxRemovePhoto( ' . wppa('mocc') . ', \'' . $xid . '\', false ); return false;') . '"' . ' >' . __('Delete', 'wp-photo-album-plus') . '</a>' . '&nbsp;';
            }
            // The edit link
            if (wppa_may_user_fe_edit($id)) {
                $result .= '<a' . ' style="color:green;cursor:pointer;"' . ' onclick="wppaEditPhoto( ' . wppa('mocc') . ', \'' . $xid . '\' ); return false;"' . ' >' . __('Edit', 'wp-photo-album-plus') . '</a>';
            }
            // Close the div
            $result .= '</div>';
        }
        // Description
        if (wppa_switch('thumb_text_desc') || $thumb['status'] == 'pending' || $thumb['status'] == 'scheduled') {
            $desc = '';
            if ($thumb['status'] == 'pending' || $thumb['status'] == 'scheduled') {
                $desc .= wppa_moderate_links('thumb', $id);
            }
            $desc .= wppa_get_photo_desc($id, wppa_switch('allow_foreign_shortcodes_thumbs'));
            $result .= '<div' . ' class="wppa-thumb-text"' . ' style="' . __wcs('wppa-thumb-text') . '"' . ' >' . $desc . '</div>';
        }
        // Rating
        if (wppa_switch('thumb_text_rating')) {
            $rating = wppa_get_rating_by_id($id);
            if ($rating && wppa_switch('show_rating_count')) {
                $rating .= ' ( ' . wppa_get_rating_count_by_id($id) . ' )';
            }
            $result .= '<div' . ' class="wppa-thumb-text"' . ' style="' . __wcs('wppa-thumb-text') . '"' . ' >' . $rating . '</div>';
        }
        // Comcount
        if (wppa_switch('thumb_text_comcount')) {
            $comcount = $wpdb->get_var("SELECT COUNT(*) FROM `" . WPPA_COMMENTS . "` WHERE `photo` = " . $id);
            if ($comcount) {
                $result .= '<div' . ' class="wppa-thumb-text"' . ' style="' . __wcs('wppa-thumb-text') . '"' . ' >' . sprintf(_n('%d comment', '%d comments', $comcount, 'wp-photo-album-plus'), $comcount) . '</div>';
            }
        }
        // Viewcount
        if (wppa_switch('thumb_text_viewcount')) {
            $result .= '<div' . ' class="wppa-thumb-text"' . ' style="clear:both;' . __wcs('wppa-thumb-text') . '"' . ' >' . sprintf(_n('%d view', '%d views', $thumb['views'], 'wp-photo-album-plus'), $thumb['views']) . '</div>';
        }
        // Close the subtext container
        $result .= '</div>';
    }
    // if ! $com_alt
    // Close the thumbframe
    $result .= '</div>';
    if ($com_alt) {
        $result .= '</div>';
    }
    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;
}