/** * 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; }
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'; }
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'; }
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'; }
/** * 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; } }