function widget($args, $instance)
 {
     extract($args);
     $title = apply_filters('widget_title', empty($instance['title']) ? ' ' : $instance['title'], $instance, $this->id_base);
     global $wpdb;
     $items = $instance['items'];
     $exclude = $instance['exclude'];
     $list = $instance['list'];
     $webslice = $instance['webslice'];
     $count = $wpdb->get_var("SELECT COUNT(*) FROM {$wpdb->nggpictures} WHERE exclude != 1 ");
     if ($count < $instance['items']) {
         $instance['items'] = $count;
     }
     $exclude_list = '';
     // THX to Kay Germer for the idea & addon code
     if (!empty($list) && $exclude != 'all') {
         $list = explode(',', $list);
         // Prepare for SQL
         $list = "'" . implode("', '", $list) . "'";
         if ($exclude == 'denied') {
             $exclude_list = "AND NOT (t.gid IN ({$list}))";
         }
         if ($exclude == 'allow') {
             $exclude_list = "AND t.gid IN ({$list})";
         }
         // Limit the output to the current author, can be used on author template pages
         if ($exclude == 'user_id') {
             $exclude_list = "AND t.author IN ({$list})";
         }
     }
     if ($instance['type'] == 'random') {
         $imageList = $wpdb->get_results("SELECT t.*, tt.* FROM {$wpdb->nggallery} AS t INNER JOIN {$wpdb->nggpictures} AS tt ON t.gid = tt.galleryid WHERE tt.exclude != 1 {$exclude_list} ORDER by rand() limit {$items}");
     } else {
         $imageList = $wpdb->get_results("SELECT t.*, tt.* FROM {$wpdb->nggallery} AS t INNER JOIN {$wpdb->nggpictures} AS tt ON t.gid = tt.galleryid WHERE tt.exclude != 1 {$exclude_list} ORDER by pid DESC limit 0,{$items}");
     }
     // IE8 webslice support if needed
     if ($webslice) {
         $before_widget .= "\n" . '<div class="hslice" id="ngg-webslice" >' . "\n";
         //the headline needs to have the class enty-title
         $before_title = str_replace('class="', 'class="entry-title ', $before_title);
         $after_widget = '</div>' . "\n" . $after_widget;
     }
     echo $before_widget . $before_title . $title . $after_title;
     echo "\n" . '<div class="ngg-widget entry-content">' . "\n";
     if (is_array($imageList)) {
         foreach ($imageList as $image) {
             // get the URL constructor
             $image = new nggImage($image);
             // get the effect code
             $thumbcode = $image->get_thumbcode($widget_id);
             // enable i18n support for alttext and description
             $alttext = htmlspecialchars(stripslashes(nggGallery::i18n($image->alttext, 'pic_' . $image->pid . '_alttext')));
             $description = htmlspecialchars(stripslashes(nggGallery::i18n($image->description, 'pic_' . $image->pid . '_description')));
             //TODO:For mixed portrait/landscape it's better to use only the height setting, if widht is 0 or vice versa
             $out = '<a href="' . $image->imageURL . '" title="' . $description . '" ' . $thumbcode . '>';
             // Typo fix for the next updates (happend until 1.0.2)
             $instance['show'] = $instance['show'] == 'orginal' ? 'original' : $instance['show'];
             if ($instance['show'] == 'original') {
                 $out .= '<img src="' . trailingslashit(home_url()) . 'index.php?callback=image&amp;pid=' . $image->pid . '&amp;width=' . $instance['width'] . '&amp;height=' . $instance['height'] . '" title="' . $alttext . '" alt="' . $alttext . '" />';
             } else {
                 $out .= '<img src="' . $image->thumbURL . '" width="' . $instance['width'] . '" height="' . $instance['height'] . '" title="' . $alttext . '" alt="' . $alttext . '" />';
             }
             echo $out . '</a>' . "\n";
         }
     }
     echo '</div>' . "\n";
     echo $after_widget;
 }
Ejemplo n.º 2
0
 function ngg_widget_output($args, $widget_args = 1, $options = false)
 {
     global $wpdb;
     extract($args, EXTR_SKIP);
     if (is_numeric($widget_args)) {
         $widget_args = array('number' => $widget_args);
     }
     $widget_args = wp_parse_args($widget_args, array('number' => -1));
     extract($widget_args, EXTR_SKIP);
     // We could get this also as parameter
     if (!$options) {
         $options = get_option('ngg_widget');
     }
     $title = $options[$number]['title'];
     $items = $options[$number]['items'];
     $exclude = $options[$number]['exclude'];
     $list = $options[$number]['list'];
     $count = $wpdb->get_var("SELECT COUNT(*) FROM {$wpdb->nggpictures} WHERE exclude != 1 ");
     if ($count < $options[$number]['items']) {
         $options[$number]['items'] = $count;
     }
     $exclude_list = '';
     // THX to Kay Germer for the idea & addon code
     if (!empty($list) && $exclude != 'all') {
         $list = explode(',', $list);
         // Prepare for SQL
         $list = "'" . implode("', '", $list) . "'";
         if ($exclude == 'denied') {
             $exclude_list = "AND NOT t.gid IN ({$list})";
         }
         if ($exclude == 'allow') {
             $exclude_list = "AND t.gid IN ({$list})";
         }
     }
     if ($options[$number]['type'] == 'random') {
         $imageList = $wpdb->get_results("SELECT t.*, tt.* FROM {$wpdb->nggallery} AS t INNER JOIN {$wpdb->nggpictures} AS tt ON t.gid = tt.galleryid WHERE tt.exclude != 1 {$exclude_list} ORDER by rand() limit {$items}");
     } else {
         $imageList = $wpdb->get_results("SELECT t.*, tt.* FROM {$wpdb->nggallery} AS t INNER JOIN {$wpdb->nggpictures} AS tt ON t.gid = tt.galleryid WHERE tt.exclude != 1 {$exclude_list} ORDER by pid DESC limit 0,{$items}");
     }
     echo $before_widget . $before_title . $title . $after_title;
     echo "\n" . '<div class="ngg-widget">' . "\n";
     if (is_array($imageList)) {
         foreach ($imageList as $image) {
             // get the URL constructor
             $image = new nggImage($image);
             // get the effect code
             $thumbcode = $image->get_thumbcode("sidebar_" . $number);
             //TODO:For mixed portrait/landscape it's better to use only the height setting, if widht is 0 or vice versa
             $out = '<a href="' . $image->imageURL . '" title="' . stripslashes($image->description) . '" ' . $thumbcode . '>';
             if ($options[$number]['show'] == 'orginal') {
                 $out .= '<img src="' . NGGALLERY_URLPATH . 'nggshow.php?pid=' . $image->pid . '&amp;width=' . $options[$number]['width'] . '&amp;height=' . $options[$number]['height'] . '" width="' . $options[$number]['width'] . '" height="' . $options[$number]['height'] . '" title="' . $image->alttext . '" alt="' . $image->alttext . '" />';
             } else {
                 $out .= '<img src="' . $image->thumbURL . '" width="' . $options[$number]['width'] . '" height="' . $options[$number]['height'] . '" title="' . $image->alttext . '" alt="' . $image->alttext . '" />';
             }
             echo $out . '</a>' . "\n";
         }
     }
     echo '</div>' . "\n";
     echo $after_widget;
 }
Ejemplo n.º 3
0
 /**
  * Front-end display of widget.
  *
  * @see WP_Widget::widget()
  *
  * @todo Needs to be better, without the mess to call to the database, but this requires a better database API.
  *
  * @param array $args Widget arguments.
  * @param array $instance Saved values from the database.
  */
 public function widget($args, $instance)
 {
     $title = apply_filters('widget_title', empty($instance['title']) ? '&nbsp;' : $instance['title'], $instance, $this->id_base);
     global $wpdb;
     $items = min($instance['items'], $wpdb->get_var("SELECT COUNT(*) FROM {$wpdb->nggpictures} WHERE exclude != 1 "));
     $exclude = $instance['exclude'];
     $list = $instance['list'];
     $exclude_list = '';
     // THX to Kay Germer for the idea & addon code
     if (!empty($list) && $exclude != 'all') {
         $list = explode(',', $list);
         // Prepare for SQL
         $list = "'" . implode("', '", $list) . "'";
         if ($exclude == 'denied') {
             $exclude_list = "AND NOT (t.gid IN ({$list}))";
         }
         if ($exclude == 'allow') {
             $exclude_list = "AND t.gid IN ({$list})";
         }
     }
     if ($instance['type'] == 'random') {
         $imageList = $wpdb->get_results("SELECT t.*, tt.* FROM {$wpdb->nggallery} AS t INNER JOIN {$wpdb->nggpictures} AS tt ON t.gid = tt.galleryid WHERE tt.exclude != 1 {$exclude_list} ORDER by rand() limit {$items}");
     } else {
         $imageList = $wpdb->get_results("SELECT t.*, tt.* FROM {$wpdb->nggallery} AS t INNER JOIN {$wpdb->nggpictures} AS tt ON t.gid = tt.galleryid WHERE tt.exclude != 1 {$exclude_list} ORDER by pid DESC limit 0,{$items}");
     }
     echo $args['before_widget'] . $args['before_title'] . $title . $args['after_title'];
     echo "\n" . '<div class="ngg-widget entry-content">' . "\n";
     if (is_array($imageList)) {
         foreach ($imageList as $image) {
             // get the URL constructor
             $image = new nggImage($image);
             // get the effect code
             $thumbcode = $image->get_thumbcode($args['widget_id']);
             // enable i18n support for alttext and description
             $alttext = htmlspecialchars(stripslashes(nggGallery::i18n($image->alttext, 'pic_' . $image->pid . '_alttext')));
             $description = htmlspecialchars(stripslashes(nggGallery::i18n($image->description, 'pic_' . $image->pid . '_description')));
             //TODO:For mixed portrait/landscape it's better to use only the height setting, if widht is 0 or vice versa
             $out = '<a href="' . $image->imageURL . '" title="' . $description . '" ' . $thumbcode . '>';
             if ($instance['show'] == 'original') {
                 $out .= '<img src="' . trailingslashit(home_url()) . 'index.php?callback=image&amp;pid=' . $image->pid . '&amp;width=' . $instance['width'] . '&amp;height=' . $instance['height'] . '" title="' . $alttext . '" alt="' . $alttext . '" />';
             } else {
                 $out .= '<img src="' . $image->thumbURL . '" width="' . $instance['width'] . '" height="' . $instance['height'] . '" title="' . $alttext . '" alt="' . $alttext . '" />';
             }
             echo $out . '</a>' . "\n";
         }
     }
     echo '</div>' . "\n";
     echo $args['after_widget'];
 }