/** * Validates whether the gallery can be saved */ function validation() { // If a title is present, we can auto-populate some other properties if (isset($this->object->title)) { // If no name is present, use the title to generate one if (!isset($this->object->name)) { $this->object->name = sanitize_file_name(sanitize_title($this->object->title)); $this->object->name = apply_filters('ngg_gallery_name', $this->object->name); } // If no slug is set, use the title to generate one if (!isset($this->object->slug)) { $this->object->slug = nggdb::get_unique_slug(sanitize_title($this->object->title), 'gallery'); } } // Set what will be the path to the gallery if (empty($this->object->path)) { $storage = $this->object->get_registry()->get_utility('I_Gallery_Storage'); $this->object->path = $storage->get_upload_relpath($this->object); unset($storage); } $this->object->validates_presence_of('title'); $this->object->validates_presence_of('name'); $this->object->validates_uniqueness_of('slug'); $this->object->validates_numericality_of('author'); return $this->object->is_valid(); }
/** * nggMeta::nggMeta() * * @param int $image path to a image * @param bool $onlyEXIF parse only exif if needed * @return */ function nggMeta($pic_id, $onlyEXIF = false) { //get the path and other data about the image $this->image = nggdb::find_image($pic_id); $this->image = apply_filters('ngg_find_image_meta', $this->image); if (!file_exists($this->image->imagePath)) { return false; } $this->size = @getimagesize($this->image->imagePath, $metadata); if ($this->size && is_array($metadata)) { // get exif - data if (is_callable('exif_read_data')) { $this->exif_data = @exif_read_data($this->image->imagePath, 0, true); } // stop here if we didn't need other meta data if ($onlyEXIF) { return true; } // get the iptc data - should be in APP13 if (is_callable('iptcparse') && isset($metadata['APP13'])) { $this->iptc_data = @iptcparse($metadata['APP13']); } // get the xmp data in a XML format if (is_callable('xml_parser_create')) { $this->xmp_data = $this->extract_XMP($this->image->imagePath); } return true; } return false; }
public function slideshow($galleryID, $type) { if (!$galleryID) { return ""; } $fade = $type == "widget" ? 'data-fade="enabled"' : ""; $picturelist = nggdb::get_gallery($galleryID, $this->options['galSort'], $this->options['galSortDir']); $html = '<div class="sliderWrap"><div class="slider" data-delay="3" data-pause="enabled" ' . $fade . '>'; $blank = PE_THEME_URL . "/img/blank.png"; $first = true; foreach ($picturelist as $p) { if ($first) { $src = $p->thumbURL; $data = ""; $first = false; } else { $src = $blank; $data = $p->thumbURL; } $html .= <<<EOL <a data-target="prettyphoto" href="{$p->imageURL}" title="{$p->title}"><img src="{$src}" data-src="{$data}" alt="{$p->title}"/></a> EOL; } $html .= "</div></div>"; return $html; }
/** * Image edit functions via AJAX * * @author Alex Rabe * * * @return void */ function ngg_ajax_operation() { // if nonce is not correct it returns -1 check_ajax_referer("ngg-ajax"); // check for correct capability if (!is_user_logged_in()) { die('-1'); } // check for correct NextGEN capability if (!current_user_can('NextGEN Upload images') && !current_user_can('NextGEN Manage gallery')) { die('-1'); } // include the ngg function include_once dirname(__FILE__) . '/functions.php'; // Get the image id if (isset($_POST['image'])) { $id = (int) $_POST['image']; // let's get the image data $picture = nggdb::find_image($id); // what do you want to do ? switch ($_POST['operation']) { case 'create_thumbnail': $result = nggAdmin::create_thumbnail($picture); break; case 'resize_image': $result = nggAdmin::resize_image($picture); break; case 'rotate_cw': $result = nggAdmin::rotate_image($picture, 'CW'); nggAdmin::create_thumbnail($picture); break; case 'rotate_ccw': $result = nggAdmin::rotate_image($picture, 'CCW'); nggAdmin::create_thumbnail($picture); break; case 'set_watermark': $result = nggAdmin::set_watermark($picture); break; case 'recover_image': $result = nggAdmin::recover_image($id) ? '1' : '0'; break; case 'import_metadata': $result = C_Image_Mapper::get_instance()->reimport_metadata($id) ? '1' : '0'; break; case 'get_image_ids': $result = nggAdmin::get_image_ids($id); break; default: do_action('ngg_ajax_' . $_POST['operation']); die('-1'); break; } // A success should return a '1' die($result); } // The script should never stop here die('0'); }
/** * Sets the defaults for an album * @param C_DataMapper_Model|C_Album|stdClass $entity */ function set_defaults($entity) { $this->object->_set_default_value($entity, 'name', ''); $this->object->_set_default_value($entity, 'albumdesc', ''); $this->object->_set_default_value($entity, 'sortorder', array()); $this->object->_set_default_value($entity, 'previewpic', 0); $this->object->_set_default_value($entity, 'exclude', 0); $this->object->_set_default_value($entity, 'slug', nggdb::get_unique_slug(sanitize_title($entity->name), 'album')); }
function ewww_added_new_image($image, $storage = null) { ewwwio_debug_message('<b>' . __FUNCTION__ . '()</b>'); global $ewww_defer; if (empty($storage)) { // creating the 'registry' object for working with nextgen $registry = C_Component_Registry::get_instance(); // creating a database storage object from the 'registry' object $storage = $registry->get_utility('I_Gallery_Storage'); } // find the image id if (is_array($image)) { $image_id = $image['id']; $image = $storage->object->_image_mapper->find($image_id, TRUE); } else { $image_id = $storage->object->_get_image_id($image); } ewwwio_debug_message("image id: {$image_id}"); if ($ewww_defer && ewww_image_optimizer_get_option('ewww_image_optimizer_defer')) { ewww_image_optimizer_add_deferred_attachment("nextgen2,{$image_id}"); return; } // get an array of sizes available for the $image $sizes = $storage->get_image_sizes(); // run the optimizer on the image for each $size foreach ($sizes as $size) { if ($size === 'full') { $full_size = true; } else { $full_size = false; } // get the absolute path $file_path = $storage->get_image_abspath($image, $size); ewwwio_debug_message("optimizing (nextgen): {$file_path}"); // optimize the image and grab the results $res = ewww_image_optimizer($file_path, 2, false, false, $full_size); ewwwio_debug_message("results {$res[1]}"); // only if we're dealing with the full-size original if ($size === 'full') { // update the metadata for the optimized image $image->meta_data['ewww_image_optimizer'] = $res[1]; } else { $image->meta_data[$size]['ewww_image_optimizer'] = $res[1]; } nggdb::update_image_meta($image_id, $image->meta_data); ewwwio_debug_message('storing results for full size image'); } return $image; }
function ewww_added_new_image($image, $storage = null) { global $ewww_debug; $ewww_debug .= "<b>ewww_added_new_image()</b><br>"; if (empty($storage)) { // creating the 'registry' object for working with nextgen $registry = C_Component_Registry::get_instance(); // creating a database storage object from the 'registry' object $storage = $registry->get_utility('I_Gallery_Storage'); } // find the image id $image_id = $storage->object->_get_image_id($image); $ewww_debug .= "image id: {$image_id}<br>"; // get an array of sizes available for the $image $sizes = $storage->get_image_sizes(); // run the optimizer on the image for each $size foreach ($sizes as $size) { if ($size === 'full') { $full_size = true; } else { $full_size = false; } // get the absolute path $file_path = $storage->get_image_abspath($image, $size); $ewww_debug .= "optimizing (nextgen): {$file_path}<br>"; // optimize the image and grab the results $res = ewww_image_optimizer($file_path, 2, false, false, $full_size); $ewww_debug .= "results " . $res[1] . "<br>"; // only if we're dealing with the full-size original if ($size === 'full') { // update the metadata for the optimized image $image->meta_data['ewww_image_optimizer'] = $res[1]; } else { $image->meta_data[$size]['ewww_image_optimizer'] = $res[1]; } nggdb::update_image_meta($image_id, $image->meta_data); $ewww_debug .= 'storing results for full size image<br>'; } ewww_image_optimizer_debug_log(); return $image; }
function ngg_ajax_operation() { global $wpdb; // if nonce is not correct it returns -1 check_ajax_referer("ngg-ajax"); // check for correct capability if (!is_user_logged_in()) { die('-1'); } // check for correct NextGEN capability if (!current_user_can('NextGEN Upload images') || !current_user_can('NextGEN Manage gallery')) { die('-1'); } // include the ngg function include_once dirname(__FILE__) . '/functions.php'; // Get the image id if (isset($_POST['image'])) { $id = (int) $_POST['image']; // let's get the image data $picture = nggdb::find_image($id); // what do you want to do ? switch ($_POST['operation']) { case 'create_thumbnail': $result = nggAdmin::create_thumbnail($picture); break; case 'resize_image': $result = nggAdmin::resize_image($picture); break; case 'set_watermark': $result = nggAdmin::set_watermark($picture); break; default: die('-1'); break; } // A success should retun a '1' die($result); } // The script should never stop here die('0'); }
function add_gallery_gid($gid = '', $title = '', $path = '', $description = '', $pageid = 0, $previewpic = 0, $author = 0 ) { global $wpdb; $slug = nggdb::get_unique_slug( sanitize_title( $title ), 'gallery' ); if ( false === $wpdb->query( $wpdb->prepare( "INSERT INTO $wpdb->nggallery ( gid, name, slug, path, title, galdesc, pageid, previewpic, author ) VALUES ( %d, %s, %s, %s, %s, %s, %d, %d, %d)", $gid, $slug, $slug, $path, $title, $description, $pageid, $previewpic, $author ))) { return false; } $galleryID = (int) $wpdb->insert_id; //and give me the new id return $galleryID; }
function getNGGalleryImages($ngGalleries, $ngImages, $dt, $lat, $lon, $dtoffset, &$error) { $result = array(); $galids = explode(',', $ngGalleries); $imgids = explode(',', $ngImages); if (!isNGGalleryActive()) { return ''; } try { $pictures = array(); foreach ($galids as $g) { $pictures = array_merge($pictures, nggdb::get_gallery($g)); } foreach ($imgids as $i) { array_push($pictures, nggdb::find_image($i)); } foreach ($pictures as $p) { $item = array(); $item["data"] = $p->thumbHTML; if (is_callable('exif_read_data')) { $exif = @exif_read_data($p->imagePath); if ($exif !== false) { $item["lon"] = getExifGps($exif["GPSLongitude"], $exif['GPSLongitudeRef']); $item["lat"] = getExifGps($exif["GPSLatitude"], $exif['GPSLatitudeRef']); if ($item["lat"] != 0 || $item["lon"] != 0) { $result[] = $item; } else { if (isset($p->imagedate)) { $_dt = strtotime($p->imagedate) + $dtoffset; $_item = findItemCoordinate($_dt, $dt, $lat, $lon); if ($_item != null) { $item["lat"] = $_item["lat"]; $item["lon"] = $_item["lon"]; $result[] = $item; } } } } } else { $error .= "Sorry, <a href='http://php.net/manual/en/function.exif-read-data.php' target='_blank' >exif_read_data</a> function not found! check your hosting..<br />"; } } /* START FIX NEXT GEN GALLERY 2.x */ if (class_exists("C_Component_Registry")) { $renderer = C_Component_Registry::get_instance()->get_utility('I_Displayed_Gallery_Renderer'); $params['gallery_ids'] = $ngGalleries; $params['image_ids'] = $ngImages; $params['display_type'] = NEXTGEN_GALLERY_BASIC_THUMBNAILS; $params['images_per_page'] = 999; // also add js references to get the gallery working $dummy = $renderer->display_images($params, $inner_content); /* START FIX NEXT GEN GALLERY PRO */ if (preg_match("/data-nplmodal-gallery-id=[\"'](.*?)[\"']/", $dummy, $m)) { $galid = $m[1]; if ($galid) { for ($i = 0; $i < count($result); ++$i) { $result[$i]["data"] = str_replace("%PRO_LIGHTBOX_GALLERY_ID%", $galid, $result[$i]["data"]); } } } /* END FIX NEXT GEN GALLERY PRO */ } /* END FIX NEXT GEN GALLERY 2.x */ } catch (Exception $e) { $error .= 'Error When Retrieving NextGen Gallery galleries/images: $e <br />'; } return $result; }
function media_upload_nextgen_form($errors) { global $wpdb, $wp_query, $wp_locale, $type, $tab, $post_mime_types, $ngg; media_upload_header(); $post_id = intval($_REQUEST['post_id']); $galleryID = 0; $total = 1; $picarray = array(); $form_action_url = site_url("wp-admin/media-upload.php?type={$GLOBALS['type']}&tab=nextgen&post_id={$post_id}", 'admin'); // Get number of images in gallery if (isset($_REQUEST['select_gal'])) { $galleryID = (int) $_REQUEST['select_gal']; $total = $wpdb->get_var("SELECT COUNT(*) FROM {$wpdb->nggpictures} WHERE galleryid = '{$galleryID}'"); } // Build navigation $_GET['paged'] = isset($_GET['paged']) ? intval($_GET['paged']) : 0; if ($_GET['paged'] < 1) { $_GET['paged'] = 1; } $start = ($_GET['paged'] - 1) * 10; if ($start < 1) { $start = 0; } // Get the images if ($galleryID != 0) { $picarray = $wpdb->get_col("SELECT pid FROM {$wpdb->nggpictures} WHERE galleryid = '{$galleryID}' AND exclude != 1 ORDER BY {$ngg->options['galSort']} {$ngg->options['galSortDir']} LIMIT {$start}, 10 "); } // WP-Core code for Post-thumbnail $calling_post_id = 0; if (isset($_GET['post_id'])) { $calling_post_id = $_GET['post_id']; } ?> <script type="text/javascript"> <!-- function NGGSetAsThumbnail(id){ var $link = jQuery('a#ngg-post-thumbnail-' + id); $link.text( setPostThumbnailL10n.saving ); jQuery.post(ajaxurl, { action:"ngg_set_post_thumbnail", post_id: post_id, thumbnail_id: id, cookie: encodeURIComponent(document.cookie) }, function(str){ var win = window.dialogArguments || opener || parent || top; $link.text( setPostThumbnailL10n.setThumbnail ); if ( str == '0' ) { alert( setPostThumbnailL10n.error ); } else { jQuery('a.ngg-post-thumbnail').show(); $link.text( setPostThumbnailL10n.done ); $link.fadeOut( 2000 ); // set some id as meta input filed win.WPSetThumbnailID('ngg-' + id); // replace the meta box with the image win.WPSetThumbnailHTML(str); } } ); } //--> </script> <form id="filter" action="" method="get"> <input type="hidden" name="type" value="<?php echo esc_attr($GLOBALS['type']); ?> " /> <input type="hidden" name="tab" value="<?php echo esc_attr($GLOBALS['tab']); ?> " /> <input type="hidden" name="post_id" value="<?php echo (int) $post_id; ?> " /> <div class="tablenav"> <?php $page_links = paginate_links(array('base' => add_query_arg('paged', '%#%'), 'format' => '', 'total' => ceil($total / 10), 'current' => $_GET['paged'])); if ($page_links) { echo "<div class='tablenav-pages'>{$page_links}</div>"; } ?> <div class="alignleft actions"> <select id="select_gal" name="select_gal" style="width:120px;">; <option value="0" <?php selected('0', $galleryID); ?> ><?php esc_attr(_e('No gallery', "nggallery")); ?> </option> <?php // Show gallery selection $gallerylist = $wpdb->get_results("SELECT * FROM {$wpdb->nggallery} ORDER BY gid ASC"); if (is_array($gallerylist)) { foreach ($gallerylist as $gallery) { $selected = $gallery->gid == $galleryID ? ' selected="selected"' : ""; echo '<option value="' . $gallery->gid . '"' . $selected . ' >' . $gallery->title . '</option>' . "\n"; } } ?> </select> <input type="submit" id="show-gallery" value="<?php esc_attr(_e('Select »', 'nggallery')); ?> " class="button-secondary" /> </div> <br style="clear:both;" /> </div> </form> <form enctype="multipart/form-data" method="post" action="<?php echo esc_attr($form_action_url); ?> " class="media-upload-form" id="library-form"> <?php wp_nonce_field('ngg-media-form'); ?> <script type="text/javascript"> <!-- jQuery(function($){ var preloaded = $(".media-item.preloaded"); if ( preloaded.length > 0 ) { preloaded.each(function(){prepareMediaItem({id:this.id.replace(/[^0-9]/g, '')},'');}); updateMediaForm(); } }); --> </script> <div id="media-items"> <?php if (is_array($picarray)) { foreach ($picarray as $picid) { //TODO:Reduce SQL Queries $picture = nggdb::find_image($picid); ?> <div id='media-item-<?php echo $picid; ?> ' class='media-item preloaded'> <div class='filename'></div> <a class='toggle describe-toggle-on' href='#'><?php esc_attr(_e('Show', "nggallery")); ?> </a> <a class='toggle describe-toggle-off' href='#'><?php esc_attr(_e('Hide', "nggallery")); ?> </a> <div class='filename new'><?php echo empty($picture->alttext) ? wp_html_excerpt($picture->filename, 60) : stripslashes(wp_html_excerpt($picture->alttext, 60)); ?> </div> <table class='slidetoggle describe startclosed'><tbody> <tr> <td rowspan='4'><img class='thumbnail' alt='<?php echo esc_attr($picture->alttext); ?> ' src='<?php echo esc_attr($picture->thumbURL); ?> '/></td> <td><?php esc_attr(_e('Image ID:', "nggallery")); echo $picid; ?> </td> </tr> <tr><td><?php echo esc_attr($picture->filename); ?> </td></tr> <tr><td><?php echo esc_attr(stripslashes($picture->alttext)); ?> </td></tr> <tr><td> </td></tr> <tr> <td class="label"><label for="image[<?php echo $picid; ?> ][alttext]"><?php esc_attr_e('Alt/Title text', "nggallery"); ?> </label></td> <td class="field"><input id="image[<?php echo $picid; ?> ][alttext]" name="image[<?php echo $picid; ?> ][alttext]" value="<?php esc_attr_e(stripslashes($picture->alttext)); ?> " type="text"/></td> </tr> <tr> <td class="label"><label for="image[<?php echo $picid; ?> ][description]"><?php esc_attr_e("Description", "nggallery"); ?> </label></td> <td class="field"><textarea name="image[<?php echo $picid; ?> ][description]" id="image[<?php echo $picid; ?> ][description]"><?php esc_attr_e(stripslashes($picture->description)); ?> </textarea></td> </tr> <tr class="align"> <td class="label"><label for="image[<?php echo $picid; ?> ][align]"><?php esc_attr_e("Alignment"); ?> </label></td> <td class="field"> <input name="image[<?php echo $picid; ?> ][align]" id="image-align-none-<?php echo $picid; ?> " checked="checked" value="none" type="radio" /> <label for="image-align-none-<?php echo $picid; ?> " class="align image-align-none-label"><?php esc_attr_e("None"); ?> </label> <input name="image[<?php echo $picid; ?> ][align]" id="image-align-left-<?php echo $picid; ?> " value="left" type="radio" /> <label for="image-align-left-<?php echo $picid; ?> " class="align image-align-left-label"><?php esc_attr_e("Left"); ?> </label> <input name="image[<?php echo $picid; ?> ][align]" id="image-align-center-<?php echo $picid; ?> " value="center" type="radio" /> <label for="image-align-center-<?php echo $picid; ?> " class="align image-align-center-label"><?php esc_attr_e("Center"); ?> </label> <input name="image[<?php echo $picid; ?> ][align]" id="image-align-right-<?php echo $picid; ?> " value="right" type="radio" /> <label for="image-align-right-<?php echo $picid; ?> " class="align image-align-right-label"><?php esc_attr_e("Right"); ?> </label> </td> </tr> <tr class="image-size"> <th class="label"><label for="image[<?php echo $picid; ?> ][size]"><span class="alignleft"><?php esc_attr_e("Size"); ?> </span></label> </th> <td class="field"> <input name="image[<?php echo $picid; ?> ][size]" id="image-size-thumb-<?php echo $picid; ?> " type="radio" checked="checked" value="thumbnail" /> <label for="image-size-thumb-<?php echo $picid; ?> "><?php esc_attr_e("Thumbnail"); ?> </label> <input name="image[<?php echo $picid; ?> ][size]" id="image-size-full-<?php echo $picid; ?> " type="radio" value="full" /> <label for="image-size-full-<?php echo $picid; ?> "><?php esc_attr_e("Full size"); ?> </label> <input name="image[<?php echo $picid; ?> ][size]" id="image-size-singlepic-<?php echo $picid; ?> " type="radio" value="singlepic" /> <label for="image-size-singlepic-<?php echo $picid; ?> "><?php esc_attr_e("Singlepic", "nggallery"); ?> </label> </td> </tr> <tr class="submit"> <td> <input type="hidden" name="image[<?php echo $picid; ?> ][thumb]" value="<?php echo $picture->thumbURL; ?> " /> <input type="hidden" name="image[<?php echo $picid; ?> ][url]" value="<?php echo $picture->imageURL; ?> " /> </td> <td class="savesend"> <?php if ($calling_post_id && current_theme_supports('post-thumbnails', get_post_type($calling_post_id))) { echo "<a class='ngg-post-thumbnail' id='ngg-post-thumbnail-" . $picid . "' href='#' onclick='NGGSetAsThumbnail(\"{$picid}\");return false;'>" . esc_html__('Use as featured image') . "</a>"; } ?> <button type="submit" class="button" value="1" name="send[<?php echo $picid; ?> ]"><?php esc_html_e('Insert into Post'); ?> </button> </td> </tr> </tbody></table> </div> <?php } } ?> </div> <p class="ml-submit"> <input type="submit" class="button savebutton" name="save" value="<?php esc_attr(_e('Save all changes', 'nggallery')); ?> " /> </p> <input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?> " /> <input type="hidden" name="select_gal" id="select_gal" value="<?php echo (int) $galleryID; ?> " /> </form> <?php }
function ewww_image_optimizer_bulk_next($delay, $attachments) { // toggle the resume flag to indicate an operation is in progress update_option('ewww_image_optimizer_bulk_ngg_resume', 'true'); // need this file to work with metadata require_once WP_CONTENT_DIR . '/plugins/nextcellent-gallery-nextgen-legacy/lib/meta.php'; foreach ($attachments as $id) { sleep($delay); // find out what time we started, in microseconds $started = microtime(true); // get the metadata $meta = new nggMeta($id); // retrieve the filepath $file_path = $meta->image->imagePath; // run the optimizer on the current image $fres = ewww_image_optimizer($file_path, 2, false, false, true); // update the metadata of the optimized image nggdb::update_image_meta($id, array('ewww_image_optimizer' => $fres[1])); // output the results of the optimization WP_CLI::line(__('Optimized image:', EWWW_IMAGE_OPTIMIZER_DOMAIN) . $meta->image->filename); WP_CLI::line(sprintf(__('Full size - %s', EWWW_IMAGE_OPTIMIZER_DOMAIN), html_entity_decode($fres[1]))); // get the filepath of the thumbnail image $thumb_path = $meta->image->thumbPath; // run the optimization on the thumbnail $tres = ewww_image_optimizer($thumb_path, 2, false, true); // output the results of the thumb optimization WP_CLI::line(sprintf(__('Thumbnail - %s', EWWW_IMAGE_OPTIMIZER_DOMAIN), html_entity_decode($tres[1]))); // outupt how much time we spent $elapsed = microtime(true) - $started; WP_CLI::line(sprintf(__('Elapsed: %.3f seconds', EWWW_IMAGE_OPTIMIZER_DOMAIN), $elapsed)); // get the list of attachments remaining from the db $attachments = get_option('ewww_image_optimizer_bulk_ngg_attachments'); // remove the first item if (!empty($attachments)) { array_shift($attachments); } // and store the list back in the db update_option('ewww_image_optimizer_bulk_ngg_attachments', $attachments, false); } // reset all the bulk options in the db update_option('ewww_image_optimizer_bulk_ngg_resume', ''); update_option('ewww_image_optimizer_bulk_ngg_attachments', '', false); // and let the user know we are done WP_CLI::success(__('Finished Optimization!', EWWW_IMAGE_OPTIMIZER_DOMAIN)); }
/** * display_thumb() * * This method displays the post thumbnail. * * @author Luca Grandicelli <*****@*****.**> * @copyright (C) 2011-2014 Luca Grandicelli * @package special-recent-posts-free * @version 2.0.4 * @param $post The global WP post object. * @access private * @return mixed It could return the HTML code for the post thumbnail or false in case of some error. */ private function display_thumb($post) { // Checking if featured thumbnails setting is active, if the current post has one and if it exists as file. if (function_exists('has_post_thumbnail') && has_post_thumbnail($post->ID)) { // Fetching Thumbnail ID. $thumbnail_id = get_post_thumbnail_id($post->ID); // Checking if current featured thumbnail comes from the NExtGen Plugin. if (stripos($thumbnail_id, 'ngg-') !== false && class_exists('nggdb')) { try { // Creating New NextGen Class instance. $nggdb = new nggdb(); // Fetching NGG thumbnail object. $nggImage = $nggdb->find_image(str_replace('ngg-', '', $thumbnail_id)); // Retrieving physical path of NGG thumbnail image. $featured_physical_path = $nggImage->imagePath; // Fetching NGG thumbnail image URL. $featured_thumb_url = $nggImage->imageURL; } catch (Exception $e) { } } else { // Retrieving featured image attachment src. $featured_thumb_attachment = wp_get_attachment_image_src($thumbnail_id, 'large'); // Retrieving physical path of featured image. $featured_physical_path = get_attached_file($thumbnail_id); // Retrieving featured image url. $featured_thumb_url = $featured_thumb_attachment[0]; } // Parsing featured image url. $featured_thumb_url_obj = parse_url($featured_thumb_url); // Retrieving featured image basename. $featured_thumb_basename = pathinfo(basename($featured_thumb_url)); // Removing querystring from image to save. This fixed the Jetpack Photon Issue. $featured_thumb_basename['extension'] = preg_replace('/\\?.*/', '', $featured_thumb_basename['extension']); // Building featured image cached path. $featured_thumb_cache = $this->cache_basepath . 'srpthumb-p' . $post->ID . '-' . $this->widget_args['thumbnail_width'] . 'x' . $this->widget_args['thumbnail_height'] . '-' . $this->widget_args['thumbnail_rotation'] . '.' . $featured_thumb_basename['extension']; // Checking if the thumbnail already exists. In this case, simply render it. Otherwise generate it. if (file_exists(SRP_PLUGIN_DIR . $featured_thumb_cache) || $this->generate_gd_image($post, 'featured', $featured_physical_path, SRP_PLUGIN_DIR . $featured_thumb_cache, $this->widget_args['thumbnail_width'], $this->widget_args['thumbnail_height'], $this->widget_args['thumbnail_rotation'])) { // Return cached image as source (URL path). $featured_thumb_src = SRP_PLUGIN_URL . $featured_thumb_cache; // Generating Image HTML Tag. $featured_htmltag = '<img src="' . $featured_thumb_src . '" class="srp-post-thumbnail" alt="' . esc_attr($post->post_title) . '" />'; } else { // No featured image has been found. Trying to fetch the first image tag from the post content. $featured_htmltag = $this->get_first_image_url($post, $this->widget_args['thumbnail_width'], $this->widget_args['thumbnail_height'], $post->post_title); } // Checking if thumbnail should be linked to post. if ('yes' == $this->widget_args['thumbnail_link']) { // Building featured image link tag. $featured_temp_content = $this->srp_create_tag('a', $featured_htmltag, array('class' => 'srp-post-thumbnail-link', 'href' => get_permalink($post->ID), 'title' => $post->post_title)); } else { // Displaying post thumbnail without link. $featured_temp_content = $featured_htmltag; } } else { // No featured image has been found. Trying to fetch the first image tag from the post content. $featured_htmltag = $this->get_first_image_url($post, $this->widget_args['thumbnail_width'], $this->widget_args['thumbnail_height'], $post->post_title); // Checking if returned image is real or it is a false value due to skip_noimage_posts option enabled. if ($featured_htmltag) { // Checking if thumbnail should be linked to post. if ('yes' == $this->widget_args['thumbnail_link']) { // Building image tag. $featured_temp_content = $this->srp_create_tag('a', $featured_htmltag, array('class' => 'srp-post-thumbnail-link', 'href' => get_permalink($post->ID), 'title' => $post->post_title)); } else { // Displaying post thumbnail without link. $featured_temp_content = $featured_htmltag; } } else { // Return false. return false; } } // Return all the image process. return $featured_temp_content; }
/** * Output HTML for the post thumbnail meta-box. * * @see wp-admin\includes\post.php * @param int $thumbnail_id ID of the image used for thumbnail * @return string html output */ function _wp_post_thumbnail_html($thumbnail_id = NULL) { global $_wp_additional_image_sizes, $post_ID; $set_thumbnail_link = '<p class="hide-if-no-js"><a title="' . esc_attr__('Set featured image') . '" href="' . esc_url(get_upload_iframe_src('image')) . '" id="set-post-thumbnail" class="thickbox">%s</a></p>'; $content = sprintf($set_thumbnail_link, esc_html__('Set featured image')); $image = nggdb::find_image($thumbnail_id); $img_src = false; // get the options $ngg_options = nggGallery::get_option('ngg_options'); if ($image) { if (is_array($_wp_additional_image_sizes) && isset($_wp_additional_image_sizes['post-thumbnail'])) { // Use post thumbnail settings if defined $width = absint($_wp_additional_image_sizes['post-thumbnail']['width']); $height = absint($_wp_additional_image_sizes['post-thumbnail']['height']); $mode = $_wp_additional_image_sizes['post-thumbnail']['crop'] ? 'crop' : ''; // check fo cached picture $img_src = $image->cached_singlepic_file($width, $height, $mode); } // if we didn't use a cached image then we take the on-the-fly mode if ($img_src == false) { $img_src = trailingslashit(home_url()) . 'index.php?callback=image&pid=' . $image->pid . '&width=' . $width . '&height=' . $height . '&mode=crop'; } $thumbnail_html = '<img width="266" src="' . $img_src . '" alt="' . $image->alttext . '" title="' . $image->alttext . '" />'; if (!empty($thumbnail_html)) { $ajax_nonce = wp_create_nonce("set_post_thumbnail-{$post_ID}"); $content = sprintf($set_thumbnail_link, $thumbnail_html); $content .= '<p class="hide-if-no-js"><a href="#" id="remove-post-thumbnail" onclick="WPRemoveThumbnail(\'' . $ajax_nonce . '\');return false;">' . esc_html__('Remove featured image') . '</a></p>'; } } return $content; }
function ewww_ngg_optimize($id) { // retrieve the metadata for the image $meta = new nggMeta($id); // retrieve the image path $file_path = $meta->image->imagePath; // run the optimizer on the current image $fres = ewww_image_optimizer($file_path, 2, false, false, true); // update the metadata for the optimized image nggdb::update_image_meta($id, array('ewww_image_optimizer' => $fres[1])); // get the filepath of the thumbnail image $thumb_path = $meta->image->thumbPath; // run the optimization on the thumbnail $tres = ewww_image_optimizer($thumb_path, 2, false, true); return array($fres, $tres); }
function set_defaults($entity) { // If not set already, we'll add an exclude property. This is used // by NextGEN Gallery itself, as well as the Attach to Post module $this->object->_set_default_value($entity, 'exclude', 0); // Ensure that the object has a description attribute $this->object->_set_default_value($entity, 'description', ''); // If not set already, set a default sortorder $this->object->_set_default_value($entity, 'sortorder', 0); // The imagedate must be set if (!isset($entity->imagedate) or is_null($entity->imagedate) or $entity->imagedate == '0000-00-00 00:00:00') { $entity->imagedate = date("Y-m-d H:i:s"); } // If a filename is set, and no alttext is set, then set the alttext // to the basename of the filename (legacy behavior) if (isset($entity->filename)) { $path_parts = pathinfo($entity->filename); $alttext = !isset($path_parts['filename']) ? substr($path_parts['basename'], 0, strpos($path_parts['basename'], '.')) : $path_parts['filename']; $this->object->_set_default_value($entity, 'alttext', $alttext); } // Set unique slug if (isset($entity->alttext) && !isset($entity->image_slug)) { $entity->image_slug = nggdb::get_unique_slug(sanitize_title_with_dashes($entity->alttext), 'image'); } // Ensure that the exclude parameter is an integer or boolean-evaluated // value if (is_string($entity->exclude)) { $entity->exclude = intval($entity->exclude); } // Trim alttext and description $entity->description = trim($entity->description); $entity->alttext = trim($entity->alttext); }
public static function images_from_ngg_gallery($nggGallery_ID) { if (method_exists('nggdb', 'get_gallery')) { // if NextGen is installed and the function get_gallery exists $options = get_option('wp-supersized_options'); if ($options['background_url']) { $full_background_url = "http://" . $options['background_url']; } else { $full_background_url = ''; } $full_output = ''; $imagesList = nggdb::get_gallery($nggGallery_ID, 'sortorder', 'ASC'); // calls the NextGen Gallery function to retrieve the content of the NextGen gallery with ID $nggGallery_ID. Images are sorted in ascending order of Sort Order. if ($imagesList) { // if there are images in the gallery global $totalSlides; $totalSlides = count($imagesList); foreach ($imagesList as $image) { $ngggallery_url = $image->imageURL; // full link to the full size image $ngggallery_thumburl = $image->thumbURL; // full link to the thumbnail $ngggallery_title = $image->alttext; // image title $ngggallery_caption = $image->description; // image caption if ($ngggallery_caption == '') { $ngggallery_caption = $ngggallery_title; } // if there is no caption, use title instead $full_output = $full_output . "\n{image : '" . $ngggallery_url . "', title : '" . $ngggallery_caption . "', thumb : '" . $ngggallery_thumburl . "', url : '" . $full_background_url . "'},"; } $full_output = substr($full_output, 0, -1) . "\n"; // removes the trailing comma to avoid trouble in IE echo $full_output; } else { self::output_error_image('nextgen-gallery_images_not_present'); } // if the requested NextGEN Gallery images are not present, display error image } }
function get_image_path() { global $post; $id = get_post_thumbnail_id(); // check to see if NextGen Gallery is present if (stripos($id, 'ngg-') !== false && class_exists('nggdb')) { $nggImage = nggdb::find_image(str_replace('ngg-', '', $id)); $thumbnail = array($nggImage->imageURL, $nggImage->width, $nggImage->height); // otherwise, just get the wp thumbnail } else { $thumbnail = wp_get_attachment_image_src($id, 'full', true); } $theimage = $thumbnail[0]; return $theimage; }
function update_pictures() { global $wpdb, $nggdb; //TODO:Error message when update failed $description = isset($_POST['description']) ? $_POST['description'] : array(); $alttext = isset($_POST['alttext']) ? $_POST['alttext'] : array(); $exclude = isset($_POST['exclude']) ? $_POST['exclude'] : false; $taglist = isset($_POST['tags']) ? $_POST['tags'] : false; $pictures = isset($_POST['pid']) ? $_POST['pid'] : false; if (is_array($pictures)) { foreach ($pictures as $pid) { $image = $nggdb->find_image($pid); if ($image) { // description field $image->description = $description[$image->pid]; // only uptade this field if someone change the alttext if ($image->alttext != $alttext[$image->pid]) { $image->alttext = $alttext[$image->pid]; $image->image_slug = nggdb::get_unique_slug(sanitize_title($image->alttext), 'image', $image->pid); } // set exclude flag if (is_array($exclude)) { $image->exclude = array_key_exists($image->pid, $exclude) ? 1 : 0; } else { $image->exclude = 0; } // update the database $wpdb->query($wpdb->prepare("UPDATE {$wpdb->nggpictures} SET image_slug = '%s', alttext = '%s', description = '%s', exclude = %d WHERE pid = %d", $image->image_slug, $image->alttext, $image->description, $image->exclude, $image->pid)); // remove from cache wp_cache_delete($image->pid, 'ngg_image'); // hook for other plugins after image is updated do_action('ngg_image_updated', $image); } } } //TODO: This produce 300-400 queries ! if (is_array($taglist)) { foreach ($taglist as $key => $value) { $tags = explode(',', $value); wp_set_object_terms($key, $tags, 'ngg_tag'); } } return; }
/** * call the callback after nggallery image upload * @param $image_info */ public function nggallery_image_upload_hook($image_info) { //get the gallery path gallerypath $nggdb = new nggdb(); $current_gallery = $nggdb->find_gallery($image_info['galleryID']); $current_filename = $image_info["filename"]; //now get the absolute path $ws_image_path = $options = get_option('siteurl') . "/" . $current_gallery->path . "/" . $current_filename; $static_generator = new StaticGenerator(); $options = get_option(MakeItStatic::CONFIG_TABLE_FIELD); $callback_urls = $options["nggallery_callback_url"]; $static_generator->callback_file($ws_image_path, $callback_urls, $current_filename, 'nggallery_image'); }
/** * Return a JSON coded array of Image ids for a requested gallery * * @class nggAdmin * @param int $galleryID * @return arry (JSON) */ function get_image_ids($galleryID) { if (!function_exists('json_encode')) { return -2; } $gallery = nggdb::get_ids_from_gallery($galleryID, 'pid', 'ASC', false); header('Content-Type: text/plain; charset=' . get_option('blog_charset'), true); $output = json_encode($gallery); return $output; }
NextGen Gallery : Alex Rabe | http://alexrabe.boelinger.com/wordpress-plugins/nextgen-gallery/ jCrop : Kelly Hallman <*****@*****.**> | http://deepliquid.com/content/Jcrop.html **/ require_once dirname(dirname(__FILE__)) . '/ngg-config.php'; require_once NGGALLERY_ABSPATH . '/lib/image.php'; if (!is_user_logged_in()) { die(__('Cheatin’ uh?')); } if (!current_user_can('NextGEN Manage gallery')) { die(__('Cheatin’ uh?')); } global $wpdb; $id = (int) $_GET['id']; // let's get the image data $picture = nggdb::find_image($id); include_once nggGallery::graphic_library(); $ngg_options = get_option('ngg_options'); $thumb = new ngg_Thumbnail($picture->imagePath, TRUE); $thumb->resize(350, 350); // we need the new dimension $resizedPreviewInfo = $thumb->newDimensions; $thumb->destruct(); $preview_image = NGGALLERY_URLPATH . 'nggshow.php?pid=' . $picture->pid . '&width=350&height=350'; $imageInfo = @getimagesize($picture->imagePath); $rr = round($imageInfo[0] / $resizedPreviewInfo['newWidth'], 2); if ($ngg_options['thumbfix'] == 1) { $WidthHtmlPrev = $ngg_options['thumbwidth']; $HeightHtmlPrev = $ngg_options['thumbheight']; } else { // H > W
/** * nggShowRandomRecent($type, $maxImages, $template, $galleryId) - return recent or random images * * @access public * @param string $type 'id' (for latest addition to DB), 'date' (for image with the latest date), 'sort' (for image sorted by user order) or 'random' * @param integer $maxImages of images * @param string $template (optional) name for a template file, look for gallery-$template * @param int $galleryId Limit to a specific gallery * @return the content */ function nggShowRandomRecent($type, $maxImages, $template = '', $galleryId = 0) { // $_GET from wp_query $pid = get_query_var('pid'); $pageid = get_query_var('pageid'); // get now the recent or random images switch ($type) { case 'random': $picturelist = nggdb::get_random_images($maxImages, $galleryId); break; case 'id': $picturelist = nggdb::find_last_images(0, $maxImages, true, $galleryId, 'id'); break; case 'date': $picturelist = nggdb::find_last_images(0, $maxImages, true, $galleryId, 'date'); break; case 'sort': $picturelist = nggdb::find_last_images(0, $maxImages, true, $galleryId, 'sort'); break; default: // default is by pid $picturelist = nggdb::find_last_images(0, $maxImages, true, $galleryId, 'id'); } // look for ImageBrowser if we have a $_GET('pid') if ($pageid == get_the_ID() || !is_home()) { if (!empty($pid)) { $out = nggCreateImageBrowser($picturelist); return $out; } } // go on if not empty if (empty($picturelist)) { return; } // show gallery if (is_array($picturelist)) { $out = nggCreateGallery($picturelist, false, $template); } $out = apply_filters('ngg_show_images_content', $out, $picturelist); return $out; }
function output() { global $wpdb, $nggdb; //TODO:Code MUST be optimized, how to flag a used gallery better ? $used_list = $this->get_used_galleries(); ?> <script type="text/javascript"> jQuery(document).ready( function() { jQuery("#previewpic").nggAutocomplete( { type: 'image',domain: "<?php echo home_url('index.php', is_ssl() ? 'https' : 'http'); ?> ",width: "95%" }); jQuery('#selectContainer').sortable( { items: '.groupItem', placeholder: 'sort_placeholder', opacity: 0.7, tolerance: 'intersect', distance: 2, forcePlaceholderSize: true , connectWith: ['#galleryContainer'] } ); jQuery('#galleryContainer').sortable( { items: '.groupItem', placeholder: 'sort_placeholder', opacity: 0.7, tolerance: 'intersect', distance: 2, forcePlaceholderSize: true , connectWith: ['#selectContainer', '#albumContainer'] } ); jQuery('#albumContainer').sortable( { items: '.groupItem', placeholder: 'sort_placeholder', opacity: 0.7, tolerance: 'intersect', distance: 2, forcePlaceholderSize: true , connectWith: ['#galleryContainer'] } ); jQuery('a.min').bind('click', toggleContent); // Hide used galleries jQuery('a#toggle_used').click(function() { jQuery('#selectContainer div.inUse').toggle(); return false; } ); // Maximize All Portlets (whole site, no differentiation) jQuery('a#all_max').click(function() { jQuery('div.itemContent:hidden').show(); return false; } ); // Minimize All Portlets (whole site, no differentiation) jQuery('a#all_min').click(function() { jQuery('div.itemContent:visible').hide(); return false; } ); // Auto Minimize if more than 4 (whole site, no differentiation) if(jQuery('a.min').length > 4) { jQuery('a.min').html('[+]'); jQuery('div.itemContent:visible').hide(); jQuery('#selectContainer div.inUse').toggle(); }; } ); var toggleContent = function(e) { var targetContent = jQuery('div.itemContent', this.parentNode.parentNode); if (targetContent.css('display') == 'none') { targetContent.slideDown(300); jQuery(this).html('[-]'); } else { targetContent.slideUp(300); jQuery(this).html('[+]'); } return false; } function ngg_serialize(s) { //serial = jQuery.SortSerialize(s); serial = jQuery('#galleryContainer').sortable('serialize'); jQuery('input[name=sortorder]').val(serial); } function showDialog() { jQuery( "#editalbum").dialog({ width: 640, resizable : false, modal: true, title: '<?php echo esc_js(__('Edit Album', 'nggallery')); ?> ' }); jQuery('#editalbum .dialog-cancel').click(function() { jQuery( "#editalbum" ).dialog("close"); }); } </script> <div class="wrap album" id="wrap" > <?php screen_icon('nextgen-gallery'); ?> <h2><?php esc_html_e('Manage Albums', 'nggallery'); ?> </h2> <form id="selectalbum" method="POST" onsubmit="ngg_serialize()" accept-charset="utf-8"> <?php wp_nonce_field('ngg_album'); ?> <input name="sortorder" type="hidden" /> <div class="albumnav tablenav"> <div class="alignleft actions"> <?php esc_html_e('Select album', 'nggallery'); ?> <select id="act_album" name="act_album" onchange="this.form.submit();"> <option value="0" ><?php esc_html_e('No album selected', 'nggallery'); ?> </option> <?php if (is_array($this->albums)) { foreach ($this->albums as $album) { $selected = $this->currentID == $album->id ? 'selected="selected" ' : ''; echo '<option value="' . $album->id . '" ' . $selected . '>' . $album->id . ' - ' . esc_attr($album->name) . '</option>' . "\n"; } } ?> </select> <?php if ($this->currentID > 0) { ?> <input class="button-primary" type="submit" name="update" value="<?php esc_attr_e('Update', 'nggallery'); ?> "/> <?php if (nggGallery::current_user_can('NextGEN Edit album settings')) { ?> <input class="button-secondary" type="submit" name="showThickbox" value="<?php esc_attr_e('Edit album', 'nggallery'); ?> " onclick="showDialog(); return false;" /> <?php } ?> <?php if (nggGallery::current_user_can('NextGEN Add/Delete album')) { ?> <input class="button-secondary action "type="submit" name="delete" value="<?php esc_attr_e('Delete', 'nggallery'); ?> " onclick="javascript:check=confirm('<?php echo esc_js('Delete album ?', 'nggallery'); ?> ');if(check==false) return false;"/> <?php } ?> <?php } else { ?> <?php if (nggGallery::current_user_can('NextGEN Add/Delete album')) { ?> <span><?php esc_html_e('Add new album', 'nggallery'); ?> </span> <input class="search-input" id="newalbum" name="newalbum" type="text" value="" /> <input class="button-secondary action" type="submit" name="add" value="<?php esc_attr_e('Add', 'nggallery'); ?> "/> <?php } ?> <?php } ?> </div> </div> </form> <br class="clear"/> <div> <div style="float:right;"> <a href="#" title="<?php esc_attr_e('Show / hide used galleries', 'nggallery'); ?> " id="toggle_used"><?php esc_html_e('[Show all]', 'nggallery'); ?> </a> | <a href="#" title="<?php esc_attr_e('Maximize the widget content', 'nggallery'); ?> " id="all_max"><?php esc_html_e('[Maximize]', 'nggallery'); ?> </a> | <a href="#" title="<?php esc_attr_e('Minimize the widget content', 'nggallery'); ?> " id="all_min"><?php esc_html_e('[Minimize]', 'nggallery'); ?> </a> </div> <?php esc_html_e('After you create and select a album, you can drag and drop a gallery or another album into your new album below', 'nggallery'); ?> </div> <br class="clear" /> <div class="container"> <!-- /#album container --> <div class="widget widget-right"> <div class="widget-top"> <h3><?php esc_html_e('Select album', 'nggallery'); ?> </h3> </div> <div id="albumContainer" class="widget-holder"> <?php if (is_array($this->albums)) { foreach ($this->albums as $album) { $this->get_container('a' . $album->id); } } ?> </div> </div> <!-- /#select container --> <div class="widget widget-right"> <div class="widget-top"> <h3><?php esc_html_e('Select gallery', 'nggallery'); ?> </h3> </div> <div id="selectContainer" class="widget-holder"> <?php if (is_array($this->galleries)) { //get the array of galleries $sort_array = $this->currentID > 0 ? (array) $this->albums[$this->currentID]->galleries : array(); foreach ($this->galleries as $gallery) { if (!in_array($gallery->gid, $sort_array)) { if (in_array($gallery->gid, $used_list)) { $this->get_container($gallery->gid, true); } else { $this->get_container($gallery->gid, false); } } } } ?> </div> </div> <!-- /#target-album --> <div class="widget target-album widget-left"> <?php if ($this->currentID > 0) { $album = $this->albums[$this->currentID]; ?> <div class="widget-top"> <h3><?php esc_html_e('Album ID', 'nggallery'); ?> <?php echo $album->id . ' : ' . esc_html($album->name); ?> </h3> </div> <div id="galleryContainer" class="widget-holder target"> <?php $sort_array = (array) $this->albums[$this->currentID]->galleries; foreach ($sort_array as $galleryid) { $this->get_container($galleryid, false); } } else { ?> <div class="widget-top"> <h3><?php esc_html_e('No album selected!', 'nggallery'); ?> </h3> </div> <div class="widget-holder target"> <?php } ?> </div> </div><!-- /#target-album --> </div><!-- /#container --> </div><!-- /#wrap --> <?php if ($this->currentID > 0) { ?> <!-- #editalbum --> <div id="editalbum" style="display: none;" > <form id="form-edit-album" method="POST" accept-charset="utf-8"> <?php wp_nonce_field('ngg_thickbox_form'); ?> <input type="hidden" id="current_album" name="act_album" value="<?php echo $this->currentID; ?> " /> <table width="100%" border="0" cellspacing="3" cellpadding="3" > <tr> <th> <?php esc_html_e('Album name:', 'nggallery'); ?> <br /> <input class="search-input" id="album_name" name="album_name" type="text" value="<?php echo esc_attr($album->name); ?> " style="width:95%" /> </th> </tr> <tr> <th> <?php esc_html_e('Album description:', 'nggallery'); ?> <br /> <textarea class="search-input" id="album_desc" name="album_desc" cols="50" rows="2" style="width:95%" ><?php echo esc_attr($album->albumdesc); ?> </textarea> </th> </tr> <tr> <th> <?php esc_html_e('Select a preview image:', 'nggallery'); ?> <br /> <select id="previewpic" name="previewpic" style="width:95%" > <?php if ($album->previewpic == 0) { } ?> <option value="0"><?php esc_html_e('No picture', 'nggallery'); ?> </option> <?php if ($album->previewpic == 0) { echo '<option value="0" selected="selected">' . __('No picture', 'nggallery') . '</option>'; } else { $picture = nggdb::find_image($album->previewpic); echo '<option value="' . $picture->pid . '" selected="selected" >' . $picture->pid . ' - ' . (empty($picture->alltext) ? esc_attr($picture->filename) : esc_attr($picture->alltext)) . ' </option>' . "\n"; } ?> </select> </th> </tr> <tr> <th> <?php esc_html_e('Page Link to', 'nggallery'); ?> <br /> <select name="pageid" style="width:95%"> <option value="0" ><?php esc_html_e('Not linked', 'nggallery'); ?> </option> <?php if (!isset($album->pageid)) { $album->pageid = 0; } parent_dropdown($album->pageid); ?> </select> </th> </tr> <?php do_action('ngg_edit_album_settings', $this->currentID); ?> <tr align="right"> <td class="submit"> <input type="submit" class="button-primary" name="update_album" value="<?php esc_attr_e('OK', 'nggallery'); ?> " /> <input class="button-secondary dialog-cancel" type="reset" value="<?php esc_attr_e('Cancel', 'nggallery'); ?> "/> </td> </tr> </table> </form> </div> <!-- /#editalbum --> <?php } ?> <?php }
/** * Overrides the NextGen Gallery function, to smush the dynamic images and thumbnails created by gallery * * @param C_Image|int|stdClass $image * @param $size * @param null $params * @param bool|false $skip_defaults * * @return bool|object */ function generate_image_size($image, $size, $params = null, $skip_defaults = false) { global $WpSmush; $image_id = !empty($image->pid) ? $image->pid : ''; //Get image from storage object if we don't have it already if (empty($image_id)) { //Get metadata For the image // Registry Object for NextGen Gallery $registry = C_Component_Registry::get_instance(); //Gallery Storage Object $storage = $registry->get_utility('I_Gallery_Storage'); $image_id = $storage->object->_get_image_id($image); } //Call the actual function to generate the image, and pass the image to smush $success = $this->call_parent('generate_image_size', $image, $size, $params, $skip_defaults); if ($success) { $filename = $success->fileName; //Smush it, if it exists if (file_exists($filename)) { $response = $WpSmush->do_smushit($filename, $image_id, 'nextgen'); //If the image was smushed if (!is_wp_error($response) && !empty($response['data']) && $response['data']->bytes_saved > 0) { //Check for existing stats if (!empty($image->meta_data) && !empty($image->meta_data['wp_smush'])) { $stats = $image->meta_data['wp_smush']; } else { //Initialize stats array $stats = array("stats" => array_merge($WpSmush->_get_size_signature(), array('api_version' => -1, 'lossy' => -1, 'keep_exif' => false)), 'sizes' => array()); $stats['bytes'] = $response['data']->bytes_saved; $stats['percent'] = $response['data']->compression; $stats['size_after'] = $response['data']->after_size; $stats['size_before'] = $response['data']->before_size; $stats['time'] = $response['data']->time; } $stats['sizes'][$size] = (object) $WpSmush->_array_fill_placeholders($WpSmush->_get_size_signature(), (array) $response['data']); if (isset($image->metadata)) { $image->meta_data['wp_smush'] = $stats; nggdb::update_image_meta($image->pid, $image->meta_data); } //Allows To get the stats for each image, after the image is smushed do_action('wp_smush_nextgen_image_stats', $image_id, $stats); } } } return $success; }
/** * Get the XML <rss> node corresponding to an album * * @param $album The album to include in RSS */ function get_album_mrss($album) { $title = stripslashes(nggGallery::i18n($album->name)); $description = ''; $link = nggMediaRss::get_permalink(0); $prev_link = ''; $next_link = ''; $images = nggdb::find_images_in_album($album->id); return nggMediaRss::get_mrss_root_node($title, $description, $link, $prev_link, $next_link, $images); }
/** * Parse the single image shortcode and return all images into an array * * @param array $atts * @return */ function add_images($atts) { extract(shortcode_atts(array('id' => 0), $atts)); // make an array out of the ids (for thumbs shortcode)) $pids = explode(',', $id); // Some error checks if (count($pids) == 0) { return; } $images = nggdb::find_images_in_list($pids); foreach ($images as $image) { $src = $image->imageURL; $newimage = array(); if (!empty($image->title)) { $newimage['title'] = $image->title; } if (!empty($image->alttext)) { $newimage['alt'] = $image->alttext; } $this->images[$src] = $newimage; } return; }
/** * This rebuild the slugs for albums, galleries and images as ajax routine, max 50 elements per request * * @since 1.7.0 * @return string '1' */ function ngg_ajax_rebuild_unique_slugs() { global $wpdb; $action = $_POST['_action']; $offset = (int) $_POST['offset']; switch ($action) { case 'images': $images = $wpdb->get_results("SELECT * FROM {$wpdb->nggpictures} ORDER BY pid ASC LIMIT {$offset}, 50", OBJECT_K); if (is_array($images)) { foreach ($images as $image) { //slug must be unique, we use the alttext for that $image->slug = nggdb::get_unique_slug(sanitize_title($image->alttext), 'image'); $wpdb->query($wpdb->prepare("UPDATE {$wpdb->nggpictures} SET image_slug= '%s' WHERE pid = '%d'", $image->slug, $image->pid)); } } break; case 'gallery': $galleries = $wpdb->get_results("SELECT * FROM {$wpdb->nggallery} ORDER BY gid ASC LIMIT {$offset}, 50", OBJECT_K); if (is_array($galleries)) { foreach ($galleries as $gallery) { //slug must be unique, we use the title for that $gallery->slug = nggdb::get_unique_slug(sanitize_title($gallery->title), 'gallery'); $wpdb->query($wpdb->prepare("UPDATE {$wpdb->nggallery} SET slug= '%s' WHERE gid = '%d'", $gallery->slug, $gallery->gid)); } } break; case 'album': $albumlist = $wpdb->get_results("SELECT * FROM {$wpdb->nggalbum} ORDER BY id ASC LIMIT {$offset}, 50", OBJECT_K); if (is_array($albumlist)) { foreach ($albumlist as $album) { //slug must be unique, we use the name for that $album->slug = nggdb::get_unique_slug(sanitize_title($album->name), 'album'); $wpdb->query($wpdb->prepare("UPDATE {$wpdb->nggalbum} SET slug= '%s' WHERE id = '%d'", $album->slug, $album->id)); } } break; } die(1); }
function ewww_ngg_bulk_loop() { if (!wp_verify_nonce($_REQUEST['ewww_wpnonce'], 'ewww-image-optimizer-bulk') || !current_user_can('edit_others_posts')) { wp_die(__('Access token has expired, please reload the page.', EWWW_IMAGE_OPTIMIZER_DOMAIN)); } // need this file to work with metadata ewww_image_optimizer_require(WP_CONTENT_DIR . '/plugins/nextgen-gallery/lib/meta.php'); // find out what time we started, in microseconds $started = microtime(true); $id = $_POST['ewww_attachment']; // get the metadata $meta = new nggMeta($id); // retrieve the filepath $file_path = $meta->image->imagePath; // run the optimizer on the current image $fres = ewww_image_optimizer($file_path, 2, false, false, true); global $ewww_exceed; if (!empty($ewww_exceed)) { echo '-9exceeded'; die; } // update the metadata of the optimized image nggdb::update_image_meta($id, array('ewww_image_optimizer' => $fres[1])); // output the results of the optimization printf("<p>" . __('Optimized image:', EWWW_IMAGE_OPTIMIZER_DOMAIN) . " <strong>%s</strong><br>", $meta->image->filename); printf(__('Full size - %s', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "<br>", $fres[1]); // get the filepath of the thumbnail image $thumb_path = $meta->image->thumbPath; // run the optimization on the thumbnail $tres = ewww_image_optimizer($thumb_path, 2, false, true); // output the results of the thumb optimization printf(__('Thumbnail - %s', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "<br>", $tres[1]); // outupt how much time we spent $elapsed = microtime(true) - $started; printf(__('Elapsed: %.3f seconds', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</p>", $elapsed); // get the list of attachments remaining from the db $attachments = get_option('ewww_image_optimizer_bulk_ngg_attachments'); // remove the first item if (!empty($attachments)) { array_shift($attachments); } // and store the list back in the db update_option('ewww_image_optimizer_bulk_ngg_attachments', $attachments); die; }
/** * Get all the images from a given album * * @param object|int $album The album object or the id * @param string $order_by * @param string $order_dir * @param bool $exclude * @return An array containing the nggImage objects representing the images in the album. */ static function find_images_in_album($album, $order_by = 'galleryid', $order_dir = 'ASC', $exclude = true) { global $wpdb; if (!is_object($album)) { $album = nggdb::find_album($album); } // Get gallery list $gallery_list = implode(',', $album->gallery_ids); // Check for the exclude setting $exclude_clause = $exclude ? ' AND tt.exclude<>1 ' : ''; // Say no to any other value $order_dir = $order_dir == 'DESC' ? 'DESC' : 'ASC'; $order_by = empty($order_by) ? 'galleryid' : $order_by; $result = $wpdb->get_results("SELECT t.*, tt.* FROM {$wpdb->nggallery} AS t INNER JOIN {$wpdb->nggpictures} AS tt ON t.gid = tt.galleryid WHERE tt.galleryid IN ({$gallery_list}) {$exclude_clause} ORDER BY tt.{$order_by} {$order_dir}"); // Return the object from the query result if ($result) { foreach ($result as $image) { $images[] = new nggImage($image); } return $images; } return null; }