/** @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();
 }
 /** @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);
 }
Example #3
0
function wppa_do_the_widget_thumb($type, $image, $album, $display, $link, $title, $imgurl, $imgstyle_a, $imgevents)
{
    global $widget_content;
    $result = wppa_get_the_widget_thumb($type, $image, $album, $display, $link, $title, $imgurl, $imgstyle_a, $imgevents);
    $widget_content .= $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);
 }
 /** @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;
 }
 /** @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();
     $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;
 }