Esempio n. 1
0
/**
 * nggShowAlbumTags() - create a gallery based on the tags
 * 
 * @access public 
 * @param string $taglist list of tags as csv
 * @return the content
 */
function nggShowAlbumTags($taglist)
{
    global $wpdb, $nggRewrite;
    // $_GET from wp_query
    $tag = get_query_var('gallerytag');
    $pageid = get_query_var('pageid');
    // look for gallerytag variable
    if ($pageid == get_the_ID() || !is_home()) {
        if (!empty($tag)) {
            // avoid this evil code $sql = 'SELECT name FROM wp_ngg_tags WHERE slug = \'slug\' union select concat(0x7c,user_login,0x7c,user_pass,0x7c) from wp_users WHERE 1 = 1';
            $slug = esc_attr($tag);
            $tagname = $wpdb->get_var($wpdb->prepare("SELECT name FROM {$wpdb->terms} WHERE slug = %s", $slug));
            $out = '<div id="albumnav"><span><a href="' . get_permalink() . '" title="' . __('Overview', 'nggallery') . ' ">' . __('Overview', 'nggallery') . '</a> | ' . $tagname . '</span></div>';
            $out .= nggShowGalleryTags($slug);
            return $out;
        }
    }
    // get now the related images
    $picturelist = nggTags::get_album_images($taglist);
    // go on if not empty
    if (empty($picturelist)) {
        return;
    }
    // re-structure the object that we can use the standard template
    foreach ($picturelist as $key => $picture) {
        $picturelist[$key]->previewpic = $picture->pid;
        $picturelist[$key]->previewname = $picture->filename;
        $picturelist[$key]->previewurl = site_url() . '/' . $picture->path . '/thumbs/thumbs_' . $picture->filename;
        $picturelist[$key]->counter = $picture->count;
        $picturelist[$key]->title = $picture->name;
        $picturelist[$key]->pagelink = $nggRewrite->get_permalink(array('gallerytag' => $picture->slug));
    }
    //TODO: Add pagination later
    $navigation = '<div class="ngg-clear"></div>';
    // create the output
    $out = nggGallery::capture('album-compact', array('album' => 0, 'galleries' => $picturelist, 'pagination' => $navigation));
    $out = apply_filters('ngg_show_album_tags_content', $out, $taglist);
    return $out;
}
Esempio n. 2
0
 function search_images()
 {
     global $nggdb;
     if (empty($_GET['s'])) {
         return;
     }
     //on what ever reason I need to set again the query var
     set_query_var('s', $_GET['s']);
     $request = get_search_query();
     // look now for the images
     $search_for_images = (array) $nggdb->search_for_images($request);
     $search_for_tags = (array) nggTags::find_images_for_tags($request, 'ASC');
     // finally merge the two results together
     $this->search_result = array_merge($search_for_images, $search_for_tags);
     // TODO: Currently we didn't support a proper pagination
     $nggdb->paged['total_objects'] = $nggdb->paged['objects_per_page'] = count($this->search_result);
     $nggdb->paged['max_objects_per_page'] = 1;
     // show pictures page
     $this->mode = 'edit';
 }
Esempio n. 3
0
 /**
  * Copy images to another gallery
  * 
  * @class nggAdmin
  * @param array|int $pic_ids ID's of the images
  * @param int $dest_gid destination gallery
  * @return void
  */
 function copy_images($pic_ids, $dest_gid)
 {
     require_once NGGALLERY_ABSPATH . '/lib/meta.php';
     $errors = $messages = '';
     if (!is_array($pic_ids)) {
         $pic_ids = array($pic_ids);
     }
     // Get destination gallery
     $destination = nggdb::find_gallery($dest_gid);
     if ($destination == null) {
         nggGallery::show_error(__('The destination gallery does not exist', 'nggallery'));
         return;
     }
     // Check for folder permission
     if (!is_writeable(WINABSPATH . $destination->path)) {
         $message = sprintf(__('Unable to write to directory %s. Is this directory writable by the server?', 'nggallery'), WINABSPATH . $destination->path);
         nggGallery::show_error($message);
         return;
     }
     // Get pictures
     $images = nggdb::find_images_in_list($pic_ids);
     $destination_path = WINABSPATH . $destination->path;
     foreach ($images as $image) {
         // WPMU action
         if (nggWPMU::check_quota()) {
             return;
         }
         $i = 0;
         $tmp_prefix = '';
         $destination_file_name = $image->filename;
         while (file_exists($destination_path . '/' . $destination_file_name)) {
             $tmp_prefix = 'copy_' . $i++ . '_';
             $destination_file_name = $tmp_prefix . $image->filename;
         }
         $destination_file_path = $destination_path . '/' . $destination_file_name;
         $destination_thumb_file_path = $destination_path . '/' . $image->thumbFolder . $image->thumbPrefix . $destination_file_name;
         // Copy files
         if (!@copy($image->imagePath, $destination_file_path)) {
             $errors .= sprintf(__('Failed to copy image %1$s to %2$s', 'nggallery'), $image->filename, $destination_file_path) . '<br />';
             continue;
         }
         // Copy backup file, if possible
         @copy($image->imagePath . '_backup', $destination_file_path . '_backup');
         // Copy the thumbnail if possible
         @copy($image->thumbPath, $destination_thumb_file_path);
         // Create new database entry for the image
         $new_pid = nggdb::insert_image($destination->gid, $destination_file_name, $image->alttext, $image->description, $image->exclude);
         if (!isset($new_pid)) {
             $errors .= sprintf(__('Failed to copy database row for picture %s', 'nggallery'), $image->pid) . '<br />';
             continue;
         }
         // Copy tags
         nggTags::copy_tags($image->pid, $new_pid);
         // Copy meta information
         $meta = new nggMeta($image->pid);
         nggdb::update_image_meta($new_pid, $meta->image->meta_data);
         if ($tmp_prefix != '') {
             $messages .= sprintf(__('Image %1$s (%2$s) copied as image %3$s (%4$s) &raquo; The file already existed in the destination gallery.', 'nggallery'), $image->pid, $image->filename, $new_pid, $destination_file_name) . '<br />';
         } else {
             $messages .= sprintf(__('Image %1$s (%2$s) copied as image %3$s (%4$s)', 'nggallery'), $image->pid, $image->filename, $new_pid, $destination_file_name) . '<br />';
         }
     }
     // Finish by showing errors or success
     if ($errors == '') {
         $link = '<a href="' . admin_url() . 'admin.php?page=nggallery-manage-gallery&mode=edit&gid=' . $destination->gid . '" >' . $destination->title . '</a>';
         $messages .= '<hr />' . sprintf(__('Copied %1$s picture(s) to gallery: %2$s .', 'nggallery'), count($images), $link);
     }
     if ($messages != '') {
         nggGallery::show_message($messages);
     }
     if ($errors != '') {
         nggGallery::show_error($errors);
     }
     return;
 }
Esempio n. 4
0
 function search_images()
 {
     global $nggdb;
     if (empty($_GET['s'])) {
         return;
     }
     //on what ever reason I need to set again the query var
     set_query_var('s', $_GET['s']);
     $request = get_search_query();
     // look now for the images
     $this->search_result = array_merge((array) $nggdb->search_for_images($request), (array) nggTags::find_images_for_tags($request, 'ASC'));
     // show pictures page
     $this->mode = 'edit';
 }
Esempio n. 5
0
</h3>
						<?php 
$output = array();
foreach ($order_array as $sort => $title) {
    $output[] = $sort == $sort_order ? '<span style="color: red;">' . $title . '</span>' : '<a href="' . $admin_base_url . esc_attr(stripslashes($_GET['page'])) . '&amp;tag_sortorder=' . $sort . $search_url . '">' . $title . '</a>';
}
echo implode('<br />', $output);
$output = array();
unset($output);
?>
					</div>

					<div id="ajax_area_tagslist">
						<ul>
							<?php 
$tags = (array) nggTags::find_tags($param, true);
foreach ($tags as $tag) {
    echo '<li><span>' . $tag->name . '</span>&nbsp;<a href="' . get_tag_link($tag->term_id) . '" title="' . sprintf(__('View all images tagged with %s', 'nggallery'), $tag->name) . '">(' . $tag->count . ')</a></li>' . "\n";
}
unset($tags);
?>
						</ul>

						<?php 
if ($prev_offset != '' || $next_offset != '') {
    ?>
						<div class="navigation">

							<?php 
    if ($prev_offset != '') {
        ?>
 function start_process()
 {
     global $ngg;
     if (!$this->valid_access()) {
         return;
     }
     switch ($this->method) {
         case 'search':
             //search for some images
             $this->result['images'] = array_merge((array) nggdb::search_for_images($this->term), (array) nggTags::find_images_for_tags($this->term, 'ASC'));
             break;
         case 'album':
             //search for some album  //TODO : Get images for each gallery, could end in a big db query
             $this->result['album'] = nggdb::find_album($this->id);
             break;
         case 'gallery':
             //search for some gallery
             $this->result['images'] = $this->id == 0 ? nggdb::find_last_images(0, 100) : nggdb::get_gallery($this->id, $ngg->options['galSort'], $ngg->options['galSortDir'], true, 0, 0, true);
             break;
         case 'image':
             //search for some image
             $this->result['images'] = nggdb::find_image($this->id);
             break;
         case 'tag':
             //search for images based on tags
             $this->result['images'] = nggTags::find_images_for_tags($this->term, 'ASC');
             break;
         case 'recent':
             //search for images based on tags
             $this->result['images'] = nggdb::find_last_images(0, $this->limit);
             break;
         case 'autocomplete':
             //return images, galleries or albums for autocomplete drop down list
             return $this->autocomplete();
             break;
         case 'version':
             $this->result = array('stat' => 'ok', 'version' => $ngg->version);
             return;
             break;
         default:
             $this->result = array('stat' => 'fail', 'code' => '98', 'message' => 'Method not known.');
             return false;
             break;
     }
     // result should be fine
     $this->result['stat'] = 'ok';
 }
Esempio n. 7
0
 /**
  * Rename tags
  */
 function rename_tags($old = '', $new = '')
 {
     $return_value = array('status' => 'ok', 'message' => '');
     if (trim(str_replace(',', '', stripslashes($new))) == '') {
         $return_value['message'] = __('No new tag specified!', 'nggallery');
         $return_value['status'] = 'error';
         return $return_value;
     }
     // String to array
     $old_tags = explode(',', $old);
     $new_tags = explode(',', $new);
     // Remove empty element and trim
     $old_tags = array_filter($old_tags, 'nggtags_delete_empty_element');
     $new_tags = array_filter($new_tags, 'nggtags_delete_empty_element');
     // If old/new tag are empty => exit !
     if (empty($old_tags) || empty($new_tags)) {
         $return_value['message'] = __('No new/old valid tag specified!', 'nggallery');
         $return_value['status'] = 'error';
         return $return_value;
     }
     $counter = 0;
     if (count($old_tags) == count($new_tags)) {
         // Rename only
         foreach ((array) $old_tags as $i => $old_tag) {
             $new_name = $new_tags[$i];
             // Get term by name
             $term = get_term_by('name', $old_tag, 'ngg_tag');
             if (!$term) {
                 continue;
             }
             // Get objects from term ID
             $objects_id = get_objects_in_term($term->term_id, 'ngg_tag', array('fields' => 'all_with_object_id'));
             // Delete old term
             wp_delete_term($term->term_id, 'ngg_tag');
             // Set objects to new term ! (Append no replace)
             foreach ((array) $objects_id as $object_id) {
                 wp_set_object_terms($object_id, $new_name, 'ngg_tag', true);
             }
             // Clean cache
             clean_object_term_cache($objects_id, 'ngg_tag');
             clean_term_cache($term->term_id, 'ngg_tag');
             // Increment
             $counter++;
         }
         if ($counter == 0) {
             $return_value['message'] = __('No tag renamed.', 'nggallery');
         } else {
             $return_value['message'] = sprintf(__('Renamed tag(s) &laquo;%1$s&raquo; to &laquo;%2$s&raquo;', 'nggallery'), $old, $new);
         }
     } elseif (count($new_tags) == 1) {
         // Merge
         // Set new tag
         $new_tag = $new_tags[0];
         if (empty($new_tag)) {
             $return_value['message'] = __('No valid new tag.', 'nggallery');
             $return_value['status'] = 'error';
             return $return_value;
         }
         // Get terms ID from old terms names
         $terms_id = array();
         foreach ((array) $old_tags as $old_tag) {
             $term = get_term_by('name', addslashes($old_tag), 'ngg_tag');
             $terms_id[] = (int) $term->term_id;
         }
         // Get objects from terms ID
         $objects_id = get_objects_in_term($terms_id, 'ngg_tag', array('fields' => 'all_with_object_id'));
         // No objects ? exit !
         if (!$objects_id) {
             $return_value['message'] = __('No objects (post/page) found for specified old tags.', 'nggallery');
             $return_value['status'] = 'error';
             return $return_value;
         }
         // Delete old terms
         foreach ((array) $terms_id as $term_id) {
             wp_delete_term($term_id, 'ngg_tag');
         }
         // Set objects to new term ! (Append no replace)
         foreach ((array) $objects_id as $object_id) {
             wp_set_object_terms($object_id, $new_tag, 'ngg_tag', true);
             $counter++;
         }
         // Test if term is also a category
         if (term_exists($new_tag, 'category')) {
             // Edit the slug to use the new term
             $slug = sanitize_title($new_tag);
             nggTags::edit_tag_slug($new_tag, $slug);
             unset($slug);
         }
         // Clean cache
         clean_object_term_cache($objects_id, 'ngg_tag');
         clean_term_cache($terms_id, 'ngg_tag');
         if ($counter == 0) {
             $return_value['message'] = __('No tag merged.', 'nggallery');
         } else {
             $return_value['message'] = sprintf(__('Merge tag(s) &laquo;%1$s&raquo; to &laquo;%2$s&raquo;. %3$s objects edited.', 'nggallery'), $old, $new, $counter);
         }
     } else {
         // Error
         $return_value['message'] = sprintf(__('Error. Not enough tags provided to rename or merge.', 'nggallery'), $old);
         $return_value['status'] = 'error';
     }
     do_action('ngg_manage_tags', $new_tags);
     return $return_value;
 }
Esempio n. 8
0
/**
 * nggShowRelatedGallery() - create a gallery based on the tags
 *
 * @access public
 * @param string $taglist list of tags as csv
 * @param integer $maxImages (optional) limit the number of images to show
 * @return the content
 */
function nggShowRelatedGallery($taglist, $maxImages = 0)
{
    $ngg_options = nggGallery::get_option('ngg_options');
    // get now the related images
    $picturelist = nggTags::find_images_for_tags($taglist, 'RAND');
    // go on if not empty
    if (empty($picturelist)) {
        return;
    }
    // cut the list to maxImages
    if ($maxImages > 0) {
        array_splice($picturelist, $maxImages);
    }
    // *** build the gallery output
    $out = '<div class="ngg-related-gallery">';
    foreach ($picturelist as $picture) {
        // get the effect code
        $thumbcode = $picture->get_thumbcode(__('Related images for', 'nggallery') . ' ' . get_the_title());
        $out .= '<a href="' . $picture->imageURL . '" title="' . stripslashes(nggGallery::i18n($picture->description, 'pic_' . $picture->pid . '_description')) . '" ' . $thumbcode . ' >';
        $out .= '<img title="' . stripslashes(nggGallery::i18n($picture->alttext, 'pic_' . $picture->pid . '_alttext')) . '" alt="' . stripslashes(nggGallery::i18n($picture->alttext, 'pic_' . $picture->pid . '_alttext')) . '" src="' . $picture->thumbURL . '" />';
        $out .= '</a>' . "\n";
    }
    $out .= '</div>' . "\n";
    $out = apply_filters('ngg_show_related_gallery_content', $out, $taglist);
    return $out;
}
 /**
  * POST action for downloading a bunch of NextGEN gallery images as a ZIP archive
  */
 public static function nggDownloadZip()
 {
     global $nggdb;
     // pick up gallery ID and array of image IDs from AJAX request
     $images = isset($_REQUEST['pid']) && is_array($_REQUEST['pid']) ? array_map('intval', $_REQUEST['pid']) : false;
     $gallery = isset($_REQUEST['gallery']) ? trim(wp_unslash($_REQUEST['gallery'])) : '';
     // sanity check
     if (!is_object($nggdb)) {
         wp_die(__('NextGEN Download Gallery requires NextGEN Gallery or NextCellent Gallery', 'nextgen-download-gallery'));
     }
     // check for request to download everything
     if (!empty($_REQUEST['download-all']) && !empty($_REQUEST['all-id'])) {
         $allID = wp_unslash($_REQUEST['all-id']);
         if (defined('NEXTGEN_GALLERY_PLUGIN_VERSION')) {
             // decode NGG2 encoded query for virtual gallery
             $json = base64_decode($allID);
             $query = $json ? json_decode($json, true) : false;
             // reduce query to permitted fields
             $query = $query ? array_intersect_key($query, array_flip(self::getNgg2QueryFields())) : false;
             if (!empty($query)) {
                 $mapper = C_Displayed_Gallery_Mapper::get_instance();
                 $factory = C_Component_Factory::get_instance();
                 $displayed_gallery = $factory->create('displayed_gallery', $query, $mapper);
                 $entities = $displayed_gallery->get_entities(false, false, true);
                 $images = array();
                 foreach ($entities as $image) {
                     $images[] = $image->pid;
                 }
                 if (empty($gallery)) {
                     $gallery = self::getNgg2DownloadTitle($displayed_gallery);
                 }
             }
         } else {
             $images = $nggdb->get_ids_from_gallery($allID);
         }
     } else {
         if (!empty($_REQUEST['all-tags'])) {
             $picturelist = nggTags::find_images_for_tags(wp_unslash($_REQUEST['all-tags']), 'ASC');
             $images = array();
             foreach ($picturelist as $image) {
                 $images[] = $image->pid;
             }
         }
     }
     // if no gallery name, confect one
     if (empty($gallery)) {
         $gallery = md5(implode(',', $images));
     }
     if (is_array($images) && count($images) > 0) {
         // allow a long script run for pulling together lots of images
         @set_time_limit(HOUR_IN_SECONDS);
         // stop/clear any output buffering
         while (ob_get_level()) {
             ob_end_clean();
         }
         // turn off compression on the server
         if (function_exists('apache_setenv')) {
             @apache_setenv('no-gzip', 1);
         }
         @ini_set('zlib.output_compression', 'Off');
         if (!class_exists('PclZip')) {
             require ABSPATH . 'wp-admin/includes/class-pclzip.php';
         }
         $filename = tempnam(get_temp_dir(), 'zip');
         $zip = new PclZip($filename);
         $files = array();
         foreach ($images as $image) {
             $image = $nggdb->find_image($image);
             if ($image) {
                 $files[] = apply_filters('ngg_dlgallery_image_path', $image->imagePath, $image);
             }
         }
         if (count($files) > 0) {
             // allow other plugins / themes to preprocess files added to the zip archive
             $preAddCallback = apply_filters('ngg_dlgallery_zip_pre_add', '__return_true');
             // create the Zip archive, without paths or compression (images are generally already compressed)
             $properties = $zip->create($files, PCLZIP_OPT_REMOVE_ALL_PATH, PCLZIP_OPT_NO_COMPRESSION, PCLZIP_CB_PRE_ADD, $preAddCallback);
             if (!is_array($properties)) {
                 wp_die($zip->errorInfo(true));
             }
             unset($zip);
             // send the Zip archive to the browser
             $zipName = apply_filters('ngg_dlgallery_zip_filename', sanitize_file_name(strtr($gallery, ',', '-')) . '.zip', $gallery);
             do_action('ngg_dlgallery_zip_before_send', $zipName, $filename, $images);
             header('Content-Description: File Transfer');
             header('Content-Type: application/zip');
             header('Content-Disposition: attachment; filename=' . $zipName);
             header('Content-Transfer-Encoding: binary');
             header('Expires: 0');
             header('Cache-Control: must-revalidate');
             header('Pragma: public');
             header('Content-Length: ' . filesize($filename));
             $chunksize = 512 * 1024;
             $file = @fopen($filename, 'rb');
             while (!feof($file)) {
                 echo @fread($file, $chunksize);
                 flush();
             }
             fclose($file);
             // check for bug in some old PHP versions, close a second time!
             if (is_resource($file)) {
                 @fclose($file);
             }
             do_action('ngg_dlgallery_zip_after_send', $zipName, $filename, $images);
             // delete the temporary file
             @unlink($filename);
             exit;
         }
         // no files, report to user
         wp_die(__('No files found to download', 'nextgen-download-gallery'));
     }
     wp_die(__('No images selected for download', 'nextgen-download-gallery'));
 }
 function widget($args, $instance)
 {
     global $wpdb;
     extract($args);
     // Set params
     $title = apply_filters('widget_title', $instance['title']);
     $html_id = $this->get_val($instance, 'html_id', 'slider');
     $width = $this->get_val_numeric($instance, 'width');
     $height = $this->get_val_numeric($instance, 'height');
     $order = $this->get_val($instance, 'order', 'asc', false);
     $tags = $this->get_val($instance, 'tags');
     $shuffle = $this->get_val($instance, 'shuffle');
     $limit = $this->get_val_numeric($instance, 'max_pictures');
     $center = $this->get_val($instance, 'center');
     $gallery = $this->get_val_numeric($instance, 'gallery');
     $shortcode = $this->get_val($instance, 'shortcode');
     // Set nivo params
     $effect = $this->get_val($instance, 'effect');
     $slices = $this->get_val($instance, 'slices');
     $boxcols = $this->get_val($instance, 'boxcols');
     $boxrows = $this->get_val($instance, 'boxrows');
     $animspeed = $this->get_val($instance, 'animspeed');
     $pausetime = $this->get_val($instance, 'pausetime');
     $startslide = $this->get_val($instance, 'startslide');
     $directionnav = $this->get_val($instance, 'directionnav');
     $directionnavhide = $this->get_val($instance, 'directionnavhide');
     $controlnav = $this->get_val($instance, 'controlnav');
     $controlnavthumbs = $this->get_val($instance, 'controlnavthumbs');
     $thumbswidth = $this->get_val_numeric($instance, 'thumbswidth');
     $thumbsheight = $this->get_val_numeric($instance, 'thumbsheight');
     $thumbscontainerheight = $this->get_val_numeric($instance, 'thumbscontainerheight');
     $thumbsgap = $this->get_val_numeric($instance, 'thumbsgap');
     $controlnavthumbsfromrel = $this->get_val($instance, 'controlnavthumbsfromrel');
     $controlnavthumbssearch = $this->get_val($instance, 'controlnavthumbssearch');
     $controlnavthumbsreplace = $this->get_val($instance, 'controlnavthumbsreplace');
     $keyboardnav = $this->get_val($instance, 'keyboardnav');
     $pauseonhover = $this->get_val($instance, 'pauseonhover');
     $manualadvance = $this->get_val($instance, 'manualadvance');
     $captionopacity = $this->get_val($instance, 'captionopacity');
     $disablecaptions = $this->get_val($instance, 'disablecaptions');
     $beforechange = $this->get_val($instance, 'beforechange', '', false);
     $afterchange = $this->get_val($instance, 'afterchange', '', false);
     $slideshowend = $this->get_val($instance, 'slideshowend', '', false);
     $lastslide = $this->get_val($instance, 'lastslide', '', false);
     $afterload = $this->get_val($instance, 'afterload', '', false);
     // SQL defaults
     $sql_order = '';
     $sql_where = ' WHERE exclude = 0';
     $sql_limit = '';
     // Set SQL order
     if ($order == 'random') {
         $sql_order = 'RAND()';
     } elseif ($order == 'asc') {
         $sql_order = 'galleryid ASC';
     } elseif ($order == 'desc') {
         $sql_order = 'galleryid DESC';
     } elseif ($order == 'sortorder') {
         $sql_order = 'sortorder ASC';
     } else {
         $sql_order = 'galleryid ASC';
     }
     if ($gallery != '') {
         $sql_where .= ' AND galleryid = ' . $gallery;
     }
     // Set limit defaults only it tags are not being used
     $num_limit = -1;
     if (is_numeric($limit)) {
         $num_limit = (int) $limit;
         if ($tags == '') {
             $sql_limit = ' LIMIT 0, ' . $limit;
         }
     }
     $results = $wpdb->get_results("SELECT * FROM {$wpdb->nggpictures}" . $sql_where . " ORDER BY " . $sql_order . $sql_limit);
     $p_size = 0;
     if (is_array($results)) {
         // Filter by tag if entered
         if ($tags != '') {
             $tagged_images = nggTags::find_images_for_tags($tags);
             if ($tagged_images) {
                 $tagged_image_ids = array();
                 foreach ($tagged_images as $image) {
                     $tagged_image_ids[] = $image->pid;
                 }
                 if (sizeof($tagged_image_ids) > 0) {
                     $filtered_results = array();
                     $tagged_count = 0;
                     foreach ($results as $result) {
                         if ($num_limit != -1 && $tagged_count >= $num_limit) {
                             break;
                         } else {
                             if (in_array($result->pid, $tagged_image_ids)) {
                                 $filtered_results[] = $result;
                                 $tagged_count += 1;
                             }
                         }
                     }
                     $results = $filtered_results;
                 }
             } else {
                 $results = array();
             }
         }
         $p_size = count($results);
     }
     $output = '';
     if ($p_size > 0) {
         if ($title != '') {
             if ($shortcode != '1') {
                 $output .= "\n" . $before_title . $title . $after_title;
             } else {
                 $output .= "\n<h3>" . $title . "</h3>";
             }
         }
         $has_control_nav = $controlnav == '' || $controlnav == 'true';
         $has_thumbs = $controlnavthumbs == 'true' || $controlnavthumbs == 'nextgen_thumbs' || $controlnavthumbs == 'nextgen_original';
         $has_center = $center == '1' && $width != '';
         if ($width != '' || $height != '') {
             $width_s = '';
             $height_s = '';
             if ($width != '') {
                 $width_s = "width: " . $width . "px !important;";
             }
             if ($height != '') {
                 $height_s = "height: " . $height . "px !important;";
             }
             $output .= "\n<style type=\"text/css\">";
             if ($width_s != '' || $height_s != '') {
                 $output .= "\n  div#" . $html_id . " { " . $width_s . $height_s . " }";
             }
             if ($width_s != '') {
                 $output .= "\n  div#" . $html_id . "_container .nivo_slider .nivo-controlNav { " . $width_s . " }";
             }
             if ($has_control_nav && $has_thumbs) {
                 if ($thumbscontainerheight != '') {
                     $output .= "\n  div#" . $html_id . "_container { padding-bottom: " . $thumbscontainerheight . "px; }";
                     $output .= "\n  div#" . $html_id . "_container .nivo-controlNav { bottom: -" . $thumbscontainerheight . "px; }";
                 }
                 if ($thumbsgap != '' || $thumbswidth != '' || $thumbsheight != '') {
                     $output .= "\n  div#" . $html_id . "_container .nivo-controlNav img { ";
                     if ($thumbsgap != '') {
                         $output .= "margin-right: " . $thumbsgap . "px;";
                     }
                     if ($thumbswidth != '') {
                         $output .= "width: " . $thumbswidth . "px ;";
                     }
                     if ($thumbsheight != '') {
                         $output .= "height: " . $thumbsheight . "px;";
                     }
                     $output .= " }";
                 }
                 if ($has_center && $thumbsgap != '') {
                     $output .= "\n  div#" . $html_id . "_container .nivo-controlNav img.first_thumb { margin-left: " . $thumbsgap . "px; }";
                 }
             }
             $output .= "\n</style>";
         }
         $container_class = '';
         if ($has_center) {
             $container_class = ' nivo_slider_center';
         }
         if ($has_control_nav) {
             if ($has_thumbs) {
                 $container_class .= ' nivo_slider_controlNavImages';
             } else {
                 $container_class .= ' nivo_slider_controlNavText';
             }
         }
         $output .= "\n<div id=\"" . $html_id . "_container\" class=\"nivo_slider_container" . $container_class . "\">";
         $output .= "\n  <div id=\"" . $html_id . "\" class=\"nivo_slider\">";
         $image_alt = null;
         $image_description = null;
         foreach ($results as $result) {
             $gallery = $wpdb->get_row("SELECT * FROM {$wpdb->nggallery} WHERE gid = '" . $result->galleryid . "'");
             foreach ($gallery as $key => $value) {
                 $result->{$key} = $value;
             }
             $image = new nggImage($result);
             $image_alt = trim($image->alttext);
             $image_description = trim($image->description);
             $output .= "\n    ";
             // check that alt is url with a simple validation
             $use_url = false;
             if ($image_alt != '' && (substr($image_alt, 0, 1) == '/' || substr($image_alt, 0, 4) == 'http' || substr($image_alt, 0, 3) == 'ftp')) {
                 $use_url = true;
             }
             if ($use_url != '') {
                 $output .= "<a href=\"" . esc_attr($image_alt) . "\">";
             }
             if ($disablecaptions != '1' && $image_description != '') {
                 $image_description = "title=\"" . $this->quote_fix($image_description) . "\" ";
             } else {
                 $image_description = '';
             }
             $output .= "<img src=\"" . $image->imageURL . "\" " . $image_description . "class=\"nivo_image\" alt=\"nivo slider image\" />";
             if ($use_url != '') {
                 $output .= "</a>";
             }
         }
         $output .= "\n  </div>";
         $output .= "\n</div>";
     }
     // Nivo arguments
     $javascript_args = array();
     // Modifications if only 1 picture
     if ($p_size <= 1) {
         $startslide = '0';
         $directionnav = 'false';
         $controlnav = 'false';
         $keyboardnav = 'false';
         $pauseonhover = 'false';
         $manualadvance = 'false';
         $beforechange = '';
         $afterchange = '';
         $slideshowend = '';
         $lastslide = '';
         $afterload = '';
     }
     if ($effect != "") {
         $javascript_args[] = "effect: '" . $effect . "'";
     }
     if ($slices != "") {
         $javascript_args[] = "slices: " . $slices . "";
     }
     if ($boxcols != "") {
         $javascript_args[] = "boxCols: " . $boxcols . "";
     }
     if ($boxrows != "") {
         $javascript_args[] = "boxRows: " . $boxrows . "";
     }
     if ($animspeed != "") {
         $javascript_args[] = "animSpeed: " . $animspeed;
     }
     if ($pausetime != "") {
         $javascript_args[] = "pauseTime: " . $pausetime;
     }
     if ($startslide != "") {
         $javascript_args[] = "startSlide: " . $startslide;
     }
     if ($directionnav != "") {
         $javascript_args[] = "directionNav: " . $directionnav;
     }
     if ($directionnavhide != "") {
         $javascript_args[] = "directionNavHide: " . $directionnavhide;
     }
     if ($controlnav != "") {
         $javascript_args[] = "controlNav: " . $controlnav;
     }
     if ($controlnavthumbs != "") {
         $javascript_args[] = "controlNavThumbs: " . ($has_thumbs ? 'true' : 'false');
     }
     if ($controlnavthumbsfromrel != "") {
         $javascript_args[] = "controlNavThumbsFromRel: " . $controlnavthumbsfromrel;
     }
     if ($controlnavthumbssearch != "") {
         $javascript_args[] = "controlNavThumbsSearch: '" . $controlnavthumbssearch . "'";
     }
     if ($controlnavthumbsreplace != "") {
         $javascript_args[] = "controlNavThumbsReplace: '" . $controlnavthumbsreplace . "'";
     }
     if ($keyboardnav != "") {
         $javascript_args[] = "keyboardNav: " . $keyboardnav;
     }
     if ($pauseonhover != "") {
         $javascript_args[] = "pauseOnHover: " . $pauseonhover;
     }
     if ($manualadvance != "") {
         $javascript_args[] = "manualAdvance: " . $manualadvance;
     }
     if ($captionopacity != "") {
         $javascript_args[] = "captionOpacity: " . $captionopacity;
     }
     if ($beforechange != "") {
         $javascript_args[] = "beforeChange: " . $beforechange;
     }
     if ($afterchange != "") {
         $javascript_args[] = "afterChange: " . $afterchange;
     }
     if ($slideshowend != "") {
         $javascript_args[] = "slideshowEnd: " . $slideshowend;
     }
     if ($lastslide != "") {
         $javascript_args[] = "lastSlide: " . $lastslide;
     }
     if ($afterload != "") {
         $javascript_args[] = "afterLoad: " . $afterload;
     }
     // Add javascript
     $output .= "\n<script type=\"text/javascript\">";
     $output .= "\n  jQuery(window).load(function() {";
     // Shuffle results on random order so even if page is cached the order will be different each time
     if ($order == 'random' && $shuffle == 'true') {
         $output .= "\n    jQuery('div#" . $html_id . "').jj_ngg_shuffle();";
     }
     $output .= "\n    jQuery('div#" . $html_id . "').nivoSlider(";
     if (count($javascript_args) > 0) {
         $output .= "{" . implode(",", $javascript_args) . "}";
     }
     $output .= ");";
     if ($has_control_nav && $has_thumbs) {
         if ($controlnavthumbs == 'nextgen_thumbs' || $controlnavthumbs == 'nextgen_original') {
             $output .= "\n    JJNGGUtils.wordpressThumbs('" . $html_id . "', " . ($controlnavthumbs == 'nextgen_thumbs' ? 'true' : 'false') . ");";
         }
         if ($has_center && $thumbsgap != '') {
             $output .= "\n    JJNGGUtils.wordpressThumbsCenterFix('" . $html_id . "');";
         }
         $output .= "\n    jQuery('div#" . $html_id . " div.nivo-controlNav').css('visibility', 'visible');";
     }
     $output .= "\n  });";
     $output .= "\n</script>\n";
     if ($shortcode != '1') {
         echo $before_widget . "\n<ul class=\"ul_jj_slider\">\n    <li class=\"li_jj_slider\">" . $output . "\n    </li>\n  </ul>\n" . $after_widget;
     } else {
         echo $output;
     }
 }