예제 #1
0
/**
 * nggSinglePicture() - show a single picture based on the id
 * 
 * @access public 
 * @param int $imageID, db-ID of the image
 * @param int (optional) $width, width of the image
 * @param int (optional) $height, height of the image
 * @param string $mode (optional) could be none, watermark, web20
 * @param string $float (optional) could be none, left, right
 * @param string $template (optional) name for a template file, look for singlepic-$template
 * @param string $caption (optional) additional caption text
 * @param string $link (optional) link to a other url instead the full image
 * @return the content
 */
function nggSinglePicture($imageID, $width = 250, $height = 250, $mode = '', $float = '', $template = '', $caption = '', $link = '')
{
    global $post;
    $ngg_options = nggGallery::get_option('ngg_options');
    // get picturedata
    $picture = nggdb::find_image($imageID);
    // if we didn't get some data, exit now
    if ($picture == null) {
        return __('[SinglePic not found]', 'nggallery');
    }
    // add float to img
    switch ($float) {
        case 'left':
            $float = ' ngg-left';
            break;
        case 'right':
            $float = ' ngg-right';
            break;
        case 'center':
            $float = ' ngg-center';
            break;
        default:
            $float = '';
            break;
    }
    // clean mode if needed
    $mode = preg_match('/(web20|watermark)/i', $mode) ? $mode : '';
    //let's initiate the url
    $picture->thumbnailURL = false;
    // check fo cached picture
    if ($post->post_status == 'publish') {
        $picture->thumbnailURL = $picture->cached_singlepic_file($width, $height, $mode);
    }
    // if we didn't use a cached image then we take the on-the-fly mode
    if (!$picture->thumbnailURL) {
        $picture->thumbnailURL = trailingslashit(home_url()) . 'index.php?callback=image&pid=' . $imageID . '&width=' . $width . '&height=' . $height . '&mode=' . $mode;
    }
    // add more variables for render output
    $picture->imageURL = empty($link) ? $picture->imageURL : $link;
    $picture->href_link = $picture->get_href_link();
    $picture->alttext = html_entity_decode(stripslashes(nggGallery::i18n($picture->alttext, 'pic_' . $picture->pid . '_alttext')));
    $picture->linktitle = htmlspecialchars(stripslashes(nggGallery::i18n($picture->description, 'pic_' . $picture->pid . '_description')));
    $picture->description = html_entity_decode(stripslashes(nggGallery::i18n($picture->description, 'pic_' . $picture->pid . '_description')));
    $picture->classname = 'ngg-singlepic' . $float;
    $picture->thumbcode = $picture->get_thumbcode('singlepic' . $imageID);
    $picture->height = (int) $height;
    $picture->width = (int) $width;
    $picture->caption = nggGallery::i18n($caption);
    // filter to add custom content for the output
    $picture = apply_filters('ngg_image_object', $picture, $imageID);
    // let's get the meta data
    $meta = new nggMeta($imageID);
    $meta->sanitize();
    $exif = $meta->get_EXIF();
    $iptc = $meta->get_IPTC();
    $xmp = $meta->get_XMP();
    $db = $meta->get_saved_meta();
    //if we get no exif information we try the database
    $exif = $exif == false ? $db : $exif;
    // look for singlepic-$template.php or pure singlepic.php
    $filename = empty($template) ? 'singlepic' : 'singlepic-' . $template;
    // create the output
    $out = nggGallery::capture($filename, array('image' => $picture, 'meta' => $meta, 'exif' => $exif, 'iptc' => $iptc, 'xmp' => $xmp, 'db' => $db));
    $out = apply_filters('ngg_show_singlepic_content', $out, $picture);
    return $out;
}
예제 #2
0
// look up for the path
require_once dirname(dirname(__FILE__)) . '/ngg-config.php';
require_once NGGALLERY_ABSPATH . '/lib/meta.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 meta data'
$meta = new nggMeta($id);
$dbdata = $meta->get_saved_meta();
$exifdata = $meta->get_EXIF();
$iptcdata = $meta->get_IPTC();
$xmpdata = $meta->get_XMP();
?>
	<!-- META DATA -->
	<fieldset class="options nggallery">
	<h3><?php 
_e('Meta Data', 'nggallery');
?>
</h3>
	<?php 
if ($dbdata) {
    ?>
		<table id="the-list-x" width="100%" cellspacing="3" cellpadding="3">
			<thead>
				<tr>
예제 #3
0
 /**
  * Rotated/Flip an image based on the orientation flag or a definded angle
  * 
  * @param int|object $image
  * @param string (optional) $dir, CW (clockwise)or CCW (counter clockwise), if set to false, the exif flag will be used
  * @param string (optional)  $flip, could be either false | V (flip vertical) | H (flip horizontal)
  * @return string result code
  */
 function rotate_image($image, $dir = false, $flip = false)
 {
     global $ngg;
     if (!class_exists('ngg_Thumbnail')) {
         require_once nggGallery::graphic_library();
     }
     if (is_numeric($image)) {
         $image = nggdb::find_image($image);
     }
     if (!is_object($image)) {
         return __('Object didn\'t contain correct data', 'nggallery');
     }
     if (!is_writable($image->imagePath)) {
         return ' <strong>' . $image->filename . __(' is not writeable', 'nggallery') . '</strong>';
     }
     // if you didn't define a rotation, we look for the orientation flag in EXIF
     if ($dir === false) {
         $meta = new nggMeta($image->pid);
         $exif = $meta->get_EXIF();
         if (isset($exif['Orientation'])) {
             switch ($exif['Orientation']) {
                 case 5:
                     // vertical flip + 90 rotate right
                     $flip = 'V';
                 case 6:
                     // 90 rotate right
                     $dir = 'CW';
                     break;
                 case 7:
                     // horizontal flip + 90 rotate right
                     $flip = 'H';
                 case 8:
                     // 90 rotate left
                     $dir = 'CCW';
                     break;
                 case 4:
                     // vertical flip
                     $flip = 'V';
                     break;
                 case 3:
                     // 180 rotate left
                     $dir = 180;
                     break;
                 case 2:
                     // horizontal flip
                     $flip = 'H';
                     break;
                 case 1:
                     // no action in the case it doesn't need a rotation
                 // no action in the case it doesn't need a rotation
                 default:
                     return '0';
                     break;
             }
         } else {
             return '0';
         }
     }
     $file = new ngg_Thumbnail($image->imagePath, TRUE);
     // skip if file is not there
     if (!$file->error) {
         // If required save a backup copy of the file
         if ($ngg->options['imgBackup'] == 1 && !file_exists($image->imagePath . '_backup')) {
             @copy($image->imagePath, $image->imagePath . '_backup');
         }
         // before we start we import the meta data to database (required for uploads before V1.4.X)
         nggAdmin::maybe_import_meta($image->pid);
         if ($dir !== 0) {
             $file->rotateImage($dir);
         }
         if ($dir === 180) {
             $file->rotateImage('CCW');
         }
         // very special case, we rotate the image two times
         if ($flip == 'H') {
             $file->flipImage(true, false);
         }
         if ($flip == 'V') {
             $file->flipImage(false, true);
         }
         $file->save($image->imagePath, $ngg->options['imgQuality']);
         // read the new sizes
         $size = @getimagesize($image->imagePath);
         // add them to the database
         nggdb::update_image_meta($image->pid, array('width' => $size[0], 'height' => $size[1]));
     }
     $file->destruct();
     if (!empty($file->errmsg)) {
         return ' <strong>' . $image->filename . ' (Error : ' . $file->errmsg . ')</strong>';
     }
     return '1';
 }
예제 #4
0
 /**
  * Rotated/Flip an image based on the orientation flag or a definded angle
  *
  * @param int|object $image
  * @param string (optional) $dir, CW (clockwise)or CCW (counter clockwise), if set to false, the exif flag will be used
  * @param string (optional)  $flip, could be either false | V (flip vertical) | H (flip horizontal)
  * @return string result code
  */
 static function rotate_image($image, $dir = false, $flip = false)
 {
     if (is_object($image)) {
         if (isset($image->id)) {
             $image = $image->id;
         } elseif (isset($image->pid)) {
             $image = $image->pid;
         }
     }
     $storage = C_Gallery_Storage::get_instance();
     // XXX NextGEN Legacy wasn't handling watermarks or reflections at this stage, so we're forcefully disabling them to maintain compatibility
     $params = array('watermark' => false, 'reflection' => false);
     $rotation = null;
     if ($dir === 'CW') {
         $rotation = 90;
     } else {
         if ($dir === 'CCW') {
             $rotation = -90;
         } else {
             if ($dir === false) {
                 $meta = new nggMeta($image);
                 $exif = $meta->get_EXIF();
                 if (isset($exif['Orientation'])) {
                     switch ($exif['Orientation']) {
                         case 5:
                             // vertical flip + 90 rotate right
                             $flip = 'V';
                         case 6:
                             // 90 rotate right
                             $rotation = 90;
                             break;
                         case 7:
                             // horizontal flip + 90 rotate right
                             $flip = 'H';
                         case 8:
                             // 90 rotate left
                             $rotation = -90;
                             break;
                         case 4:
                             // vertical flip
                             $flip = 'V';
                             break;
                         case 3:
                             // 180 rotate left
                             $rotation = -180;
                             break;
                         case 2:
                             // horizontal flip
                             $flip = 'H';
                             break;
                         case 1:
                             // no action in the case it doesn't need a rotation
                         // no action in the case it doesn't need a rotation
                         default:
                             return '0';
                             break;
                     }
                 } else {
                     return '0';
                 }
             }
         }
     }
     if ($rotation != null) {
         $params['rotation'] = $rotation;
     }
     if ($flip != null) {
         $params['flip'] = $flip;
     }
     $result = $storage->generate_image_size($image, 'full', $params);
     if (!$result) {
         // XXX there isn't any error handling unfortunately at the moment in the generate_thumbnail functions, need a way to return proper error status
         return __('Error while rotating image.', 'nggallery');
     }
     // success
     return '1';
 }
예제 #5
0
/**
 * nggCreateImageBrowser()
 *
 * @access internal
 * @param array $picturelist
 * @param string $template (optional) name for a template file, look for imagebrowser-$template
 * @return the content
 */
function nggCreateImageBrowser($picturelist, $template = '')
{
    global $nggRewrite, $ngg;
    require_once dirname(__FILE__) . '/lib/meta.php';
    // $_GET from wp_query
    $pid = get_query_var('pid');
    // we need to know the current page id
    $current_page = get_the_ID() == false ? 0 : get_the_ID();
    // create a array with id's for better walk inside
    foreach ($picturelist as $picture) {
        $picarray[] = $picture->pid;
    }
    $total = count($picarray);
    if (!empty($pid)) {
        if (is_numeric($pid)) {
            $act_pid = intval($pid);
        } else {
            // in the case it's a slug we need to search for the pid
            foreach ($picturelist as $key => $picture) {
                if ($picture->image_slug == $pid) {
                    $act_pid = $key;
                    break;
                }
            }
        }
    } else {
        reset($picarray);
        $act_pid = current($picarray);
    }
    // get ids for back/next
    $key = array_search($act_pid, $picarray);
    if (!$key) {
        $act_pid = reset($picarray);
        $key = key($picarray);
    }
    $back_pid = $key >= 1 ? $picarray[$key - 1] : end($picarray);
    $next_pid = $key < $total - 1 ? $picarray[$key + 1] : reset($picarray);
    // get the picture data
    $picture = nggdb::find_image($act_pid);
    // if we didn't get some data, exit now
    if ($picture == null) {
        return;
    }
    // add more variables for render output
    $picture->href_link = $picture->get_href_link();
    $args['pid'] = $ngg->options['usePermalinks'] ? $picturelist[$back_pid]->image_slug : $back_pid;
    $picture->previous_image_link = $nggRewrite->get_permalink($args);
    $picture->previous_pid = $back_pid;
    $args['pid'] = $ngg->options['usePermalinks'] ? $picturelist[$next_pid]->image_slug : $next_pid;
    $picture->next_image_link = $nggRewrite->get_permalink($args);
    $picture->next_pid = $next_pid;
    $picture->number = $key + 1;
    $picture->total = $total;
    $picture->linktitle = empty($picture->description) ? ' ' : htmlspecialchars(stripslashes(nggGallery::i18n($picture->description, 'pic_' . $picture->pid . '_description')));
    $picture->alttext = empty($picture->alttext) ? ' ' : html_entity_decode(stripslashes(nggGallery::i18n($picture->alttext, 'pic_' . $picture->pid . '_alttext')));
    $picture->description = empty($picture->description) ? ' ' : html_entity_decode(stripslashes(nggGallery::i18n($picture->description, 'pic_' . $picture->pid . '_description')));
    $picture->anchor = 'ngg-imagebrowser-' . $picture->galleryid . '-' . $current_page;
    // filter to add custom content for the output
    $picture = apply_filters('ngg_image_object', $picture, $act_pid);
    // let's get the meta data
    $meta = new nggMeta($act_pid);
    $meta->sanitize();
    $exif = $meta->get_EXIF();
    $iptc = $meta->get_IPTC();
    $xmp = $meta->get_XMP();
    $db = $meta->get_saved_meta();
    //if we get no exif information we try the database
    $exif = $exif == false ? $db : $exif;
    // look for imagebrowser-$template.php or pure imagebrowser.php
    $filename = empty($template) ? 'imagebrowser' : 'imagebrowser-' . $template;
    // create the output
    $out = nggGallery::capture($filename, array('image' => $picture, 'meta' => $meta, 'exif' => $exif, 'iptc' => $iptc, 'xmp' => $xmp, 'db' => $db));
    return $out;
}
예제 #6
0
/**
 * nggSinglePicture() - show a single picture based on the id
 * 
 * @access public 
 * @param int $imageID, db-ID of the image
 * @param int (optional) $width, width of the image
 * @param int (optional) $height, height of the image
 * @param string $mode (optional) could be none, watermark, web20
 * @param string $float (optional) could be none, left, right
 * @param string $template (optional) name for a template file, look for singlepic-$template
 * @param string $caption (optional) additional caption text
 * @return the content
 */
function nggSinglePicture($imageID, $width = 250, $height = 250, $mode = '', $float = '', $template = '', $caption = '')
{
    global $post;
    $ngg_options = nggGallery::get_option('ngg_options');
    // get picturedata
    $picture = nggdb::find_image($imageID);
    // if we didn't get some data, exit now
    if ($picture == null) {
        return __('[SinglePic not found]', 'nggallery');
    }
    // add float to img
    if (!empty($float)) {
        switch ($float) {
            case 'left':
                $float = ' ngg-left';
                break;
            case 'right':
                $float = ' ngg-right';
                break;
            case 'center':
                $float = ' ngg-center';
                break;
            default:
                $float = '';
                break;
        }
    }
    // check fo cached picture
    if ($ngg_options['imgCacheSinglePic'] && $post->post_status == 'publish') {
        $picture->thumbnailURL = $picture->cached_singlepic_file($width, $height, $mode);
    } else {
        $picture->thumbnailURL = NGGALLERY_URLPATH . 'nggshow.php?pid=' . $imageID . '&amp;width=' . $width . '&amp;height=' . $height . '&amp;mode=' . $mode;
    }
    // add more variables for render output
    $picture->href_link = $picture->get_href_link();
    $picture->alttext = html_entity_decode(stripslashes($picture->alttext));
    $picture->description = html_entity_decode(stripslashes($picture->description));
    $picture->classname = 'ngg-singlepic' . $float;
    $picture->thumbcode = $picture->get_thumbcode('singlepic' . $imageID);
    $picture->height = (int) $height;
    $picture->width = (int) $width;
    $picture->caption = $caption;
    // let's get the meta data
    $meta = new nggMeta($picture->imagePath);
    $exif = $meta->get_EXIF();
    $iptc = $meta->get_IPTC();
    $xmp = $meta->get_XMP();
    // look for singlepic-$template.php or pure singlepic.php
    $filename = empty($template) ? 'singlepic' : 'singlepic-' . $template;
    // create the output
    $out = nggGallery::capture($filename, array('image' => $picture, 'meta' => $meta, 'exif' => $exif, 'iptc' => $iptc, 'xmp' => $xmp));
    $out = apply_filters('ngg_show_singlepic_content', $out, $picture);
    return $out;
}