$value)
$this->$key = $value ;
// Finish initialisation
$this->name = $gallery->name;
$this->path = $gallery->path;
$this->title = stripslashes($gallery->title);
$this->pageid = $gallery->pageid;
$this->previewpic = $gallery->previewpic;
// set urls and paths
$this->imageURL = site_url() . '/' . $this->path . '/' . $this->filename;
$this->thumbURL = site_url() . '/' . $this->path . '/thumbs/thumbs_' . $this->filename;
$this->imagePath = WINABSPATH.$this->path . '/' . $this->filename;
$this->thumbPath = WINABSPATH.$this->path . '/thumbs/thumbs_' . $this->filename;
$this->meta_data = unserialize($this->meta_data);
$this->imageHTML = $this->get_href_link();
$this->thumbHTML = $this->get_href_thumb_link();
do_action_ref_array('ngg_get_image', array(&$this));
wp_cache_add($this->pid, $this, 'ngg_image');
// Get tags only if necessary
unset($this->tags);
}
/**
* Get the thumbnail code (to add effects on thumbnail click)
*
* Applies the filter 'ngg_get_thumbcode'
*/
function get_thumbcode($galleryname = '') {
// read the option setting
$ngg_options = get_option('ngg_options');
// get the effect code
if ($ngg_options['thumbEffect'] != "none")
$this->thumbcode = stripslashes($ngg_options['thumbCode']);
// for highslide to a different approach
if ($ngg_options['thumbEffect'] == "highslide")
$this->thumbcode = str_replace("%GALLERY_NAME%", "'".$galleryname."'", $this->thumbcode);
else
$this->thumbcode = str_replace("%GALLERY_NAME%", $galleryname, $this->thumbcode);
return apply_filters('ngg_get_thumbcode', $this->thumbcode, $this);
}
function get_href_link() {
// create the a href link from the picture
$this->href = "\n".'get_thumbcode($this->name).'>'."\n\t";
$this->href .= '
'."\n".''."\n";
return $this->href;
}
function get_href_thumb_link() {
// create the a href link with the thumbanil
$this->href = "\n".'get_thumbcode($this->name).'>'."\n\t";
$this->href .= '
'."\n".''."\n";
return $this->href;
}
/**
* This function creates a cache for all singlepics to reduce the CPU load
*
* @param int $width
* @param int $height
* @param string $mode could be watermark | web20 | crop
* @return the url for the image or false if failed
*/
function cached_singlepic_file($width = '', $height = '', $mode = '' ) {
$ngg_options = get_option('ngg_options');
include_once( nggGallery::graphic_library() );
// cache filename should be unique
$cachename = $this->pid . '_' . $mode . '_'. $width . 'x' . $height . '_' . $this->filename;
$cachefolder = WINABSPATH .$ngg_options['gallerypath'] . 'cache/';
$cached_url = site_url() . '/' . $ngg_options['gallerypath'] . 'cache/' . $cachename;
$cached_file = $cachefolder . $cachename;
// check first for the file
if ( file_exists($cached_file) )
return $cached_url;
// create folder if needed
if ( !file_exists($cachefolder) )
if ( !wp_mkdir_p($cachefolder) )
return false;
$thumb = new ngg_Thumbnail($this->imagePath, TRUE);
// echo $thumb->errmsg;
if (!$thumb->error) {
if ($mode == 'crop') {
// calculates the new dimentions for a downsampled image
list ( $ratio_w, $ratio_h ) = wp_constrain_dimensions($thumb->currentDimensions['width'], $thumb->currentDimensions['height'], $width, $height);
// check ratio to decide which side should be resized
( $ratio_h < $height || $ratio_w == $width ) ? $thumb->resize(0, $height) : $thumb->resize($width, 0);
// get the best start postion to crop from the middle
$ypos = ($thumb->currentDimensions['height'] - $height) / 2;
$thumb->crop(0, $ypos, $width, $height);
} else
$thumb->resize($width , $height);
if ($mode == 'watermark') {
if ($ngg_options['wmType'] == 'image') {
$thumb->watermarkImgPath = $ngg_options['wmPath'];
$thumb->watermarkImage($ngg_options['wmPos'], $ngg_options['wmXpos'], $ngg_options['wmYpos']);
}
if ($ngg_options['wmType'] == 'text') {
$thumb->watermarkText = $ngg_options['wmText'];
$thumb->watermarkCreateText($ngg_options['wmColor'], $ngg_options['wmFont'], $ngg_options['wmSize'], $ngg_options['wmOpaque']);
$thumb->watermarkImage($ngg_options['wmPos'], $ngg_options['wmXpos'], $ngg_options['wmYpos']);
}
}
if ($mode == 'web20') {
$thumb->createReflection(40,40,50,false,'#a4a4a4');
}
// save the new cache picture
$thumb->save($cached_file,$ngg_options['imgQuality']);
}
$thumb->destruct();
// check again for the file
if (file_exists($cached_file))
return $cached_url;
return false;
}
/**
* Get the tags associated to this image
*/
function get_tags() {
if ( !isset($this->tags) )
$this->tags = wp_get_object_terms($this->pid, 'ngg_tag', 'fields=all');
return $this->tags;
}
/**
* Get the permalink to the image
* TODO Get a permalink to a page presenting the image
*/
function get_permalink() {
if ($this->permalink == '')
$this->permalink = $this->imageURL;
return $this->permalink;
}
}
endif;
?>