function gimage_thumb($photo_path, $params) { global $serendipity; $path_parts = pathinfo($photo_path); //The pathinfo funtion returns 'filename' from PHP 5.2 upwards, but until that has wide support, the below returns it too... if (strlen($path_parts["extension"]) > 0) { $path_parts['filename'] = substr($path_parts["basename"], 0, strlen($path_parts["basename"]) - (strlen($path_parts["extension"]) + 1)); } else { $path_parts['filename'] = $path_parts["basename"]; } $album = $path_parts['dirname']; $photo = $path_parts['filename']; $extension = $path_parts['extension']; $gallery_base = $this->get_config('gallery_base'); $album_base = $this->get_config('album_base'); $album_abs = $this->get_config('album_abs'); $photo_ext = $extension ? "{$extension}" : "jpg"; if ($this->get_config('gversion') == 2) { $album_base = $this->get_config('album_base') . "/albums"; } // get popup max image size, default if not good. $popup_max = $this->get_config('popup_max'); if ($popup_max < 100) { $popup_max = 640; } $paramlist = explode(";", $params); //split up the parameters $param_array = array(); foreach ($paramlist as $parameter) { $temp = explode("=", $parameter); $param_array[trim(strtolower($temp[0]))] = trim($temp[1]); } if ($this->get_config('gversion') == 2) { $image = $album_abs . '/albums/' . $album . '/' . $photo . '.' . $photo_ext; $image_path = $serendipity['baseURL'] . ($serendipity['rewrite'] == "none" ? $serendipity['indexFile'] . "?/" : "/") . "plugin/g2wrapper?"; $image_path .= "album=" . $album; $image_path .= "&image=" . $photo; $image_path .= "&ext=" . $photo_ext; //handle the parameters // size = thumb sized or full image? switch (strtolower($param_array['size'])) { case 'sized': $image_path .= "&size=sized"; break; case 'full': $image_path .= "&size=full"; break; case 'thumb': default: $image_path .= "&size=thumb"; break; } } //handle the parameters // size = thumb sized or full image? switch (strtolower($param_array['size'])) { case 'sized': $image_size = ".sized."; break; case 'full': $image_size = "."; break; case 'thumb': default: $image_size = ".thumb."; break; } // link = image, page, album, none? if ($this->get_config('gversion') == 2) { switch (strtolower($param_array['link'])) { case 'image': $image_link = $serendipity['baseURL'] . ($serendipity['rewrite'] == "none" ? $serendipity['indexFile'] . "?/" : "/") . "plugin/g2wrapper?"; $image_link .= "album=" . $album; $image_link .= "&image=" . $photo; $image_link .= "&ext=" . $photo_ext; $image_link .= "&size="; break; case 'image_sized': $image_link = $serendipity['baseURL'] . ($serendipity['rewrite'] == "none" ? $serendipity['indexFile'] . "?/" : "/") . "plugin/g2wrapper?"; $image_link .= "album=" . $album; $image_link .= "&image=" . $photo; $image_link .= "&ext=" . $photo_ext; $image_link .= "&size=sized"; break; case 'album': include_once $this->get_config('gallery_abs') . "/embed.php"; if (!class_exists('GalleryEmbed')) { break; } $ret = GalleryEmbed::init(array('fullInit' => true, 'activeUserId' => '')); if (is_object($ret) && $ret->isError()) { echo $ret->getAsHtml(); exit; } $ret_aid = GalleryCoreApi::fetchItemIdByPath($album); $album_id = is_array($ret_aid) && intval($ret_aid[1]) >= 1 ? intval($ret_aid[1]) : 0; $image_link = $gallery_base . '/main.php?g2_view=core.ShowItem&g2_itemId=' . $album_id; break; case 'page': default: include_once $this->get_config('gallery_abs') . "/embed.php"; if (!class_exists('GalleryEmbed')) { break; } $ret = GalleryEmbed::init(array('fullInit' => true, 'activeUserId' => '')); if (is_object($ret) && $ret->isError()) { echo $ret->getAsHtml(); exit; } $ret_iid = GalleryCoreApi::fetchItemIdByPath($album . "/" . $photo . "." . $photo_ext); $fullsize_id = is_array($ret_iid) && intval($ret_iid[1]) >= 1 ? intval($ret_iid[1]) : 0; $image_link = $gallery_base . '/main.php?g2_view=core.ShowItem&g2_itemId=' . $fullsize_id; break; } } else { switch (strtolower($param_array['link'])) { case 'image': $image_link = $album_base . '/' . $album . '/' . $photo . '.' . $photo_ext; break; case 'image_sized': $image_link = $album_base . '/' . $album . '/' . $photo . '.sized.' . $photo_ext; break; case 'album': $image_link = $gallery_base . '/view_album.php?set_albumName=' . $album; break; case 'page': default: $image_link = $gallery_base . '/view_photo.php?set_albumName=' . $album . '&id=' . $photo; break; } } if ($this->get_config('gversion') != 2) { // get thumbnail image attributes list($width, $height, $type, $attr) = getimagesize($album_base . '/' . $album . '/' . $photo . $image_size . $photo_ext); } else { $thissize = getimagesize($album_abs . '/albums/' . $album . '/' . $photo . "." . $photo_ext); if (strtolower($param_array['size']) == 'sized') { $newsize = $this->g2_imagesize($thissize[0], $thissize[1], $this->get_config('popup_max')); $width = $newsize[0]; $height = $newsize[1]; $attr = 'width="' . $width . '" height="' . $height . '"'; } elseif (strtolower($param_array['size']) == 'thumb') { $newsize = $this->g2_imagesize($thissize[0], $thissize[1], $this->get_config('thumb_max')); $width = $newsize[0]; $height = $newsize[1]; $attr = 'width="' . $width . '" height="' . $height . '"'; } else { list($width, $height, $type, $attr) = getimagesize($album_abs . "/albums/" . $album . "/" . $photo . "." . $photo_ext); } } // target=default|new|popup only allow popup for link=image and link-image_sized switch (strtolower($param_array['target'])) { case 'popup': if ($this->get_config('gversion') != 2) { if (strtolower($param_array['link']) == 'image' || strtolower($param_array['link']) == 'image_sized') { // get target image attributes list($pwidth, $pheight, $ptype, $pattr) = getimagesize($image_link); //work out popup image window size if ($pwidth >= $pheight && $pwidth > $popup_max) { $pwidth = $popup_max; $pheight = round($popup_max * $height / $width); //from thumbnail } elseif ($pheight >= $pwidth && $pheight > $popup_max) { $pheight = $popup_max; $pwidth = round($popup_max * $width / $height); //from thumbnail } //standard spacing for windows and title bars $pwidth += 30; $pheight += 50; $link_target = '<a href="javascript:;" '; $link_target .= ' onclick="w = window.open('; $link_target .= "'" . $image_link . "', 'GImage Popup','width={$pwidth},height={$pheight},menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no');"; $link_target .= 'w.resizeTo(' . $pwidth . ',' . $pheight . ')">'; } else { $link_target = '<a href="' . $image_link . '">'; } } else { $link_target = '<a href="' . $image_link . '">'; } break; case 'new': $link_target = '<a href="' . $image_link . '" target="_blank">'; break; case 'none': $link_target = ''; break; case 'default': default: $link_target = '<a href="' . $image_link . '">'; break; } // align = left, center, right? default center switch (strtolower($param_array['align'])) { case 'left': $div_align = 'left'; $img_align = 'align=left'; $img_pre = ''; $img_post = ''; break; case 'right': $div_align = 'right'; $img_align = 'align=right'; $img_pre = ''; $img_post = ''; break; case 'center': $div_align = 'center'; $img_align = ''; $img_pre = '<center>'; $img_post = '</center>'; break; case 'none': default: $div_align = 'center'; $img_align = ''; $img_pre = ''; $img_post = ''; break; } // caption = image alt text or caption if ($param_array['caption'] == "") { $param_array['caption'] = "[PHOTO]"; } $param_array['caption'] = str_replace("\"", "", $param_array['caption']); $param_array['caption'] = str_replace("'", "", $param_array['caption']); $param_array['caption'] = str_replace(""", "", $param_array['caption']); // style = link, image or fancy (s9y stylesheet image amanager style)? switch (strtolower($param_array['style'])) { case 'image': if ($this->get_config('gversion') == 2) { $output = $img_pre . '<img ' . $img_align . ' src="' . $image_path . '" alt="' . $param_array['caption'] . '" />' . $img_post; } else { $output = $img_pre . '<img ' . $img_align . ' src="' . $album_base . '/' . $album . '/' . $photo . $image_size . $photo_ext . '" alt="' . $param_array['caption'] . '" />' . $img_post; } break; case 'fancy': $output = '<div class="serendipity_imageComment_' . $div_align . '" style="width: ' . $width . 'px">'; $output .= '<div class="serendipity_imageComment_img">'; if ($this->get_config('gversion') == 2) { $output .= $link_target . '<img src="' . $image_path . '" border="0" hspace="5" ' . $attr . ' /></a>'; } else { $output .= $link_target . '<img src="' . $album_base . '/' . $album . '/' . $photo . $image_size . $photo_ext . '" border="0" hspace="5" ' . $attr . ' /></a>'; } $output .= '</div><div class="serendipity_imageComment_txt">' . $param_array['caption'] . '</div></div>'; break; case 'link': default: if ($this->get_config('gversion') == 2) { $output = $img_pre . $link_target . '<img ' . $img_align . ' src="' . $image_path . '" alt="' . $param_array['caption'] . '" /></a>' . $img_post; } else { $output = $img_pre . $link_target . '<img ' . $img_align . ' src="' . $album_base . '/' . $album . '/' . $photo . $image_size . $photo_ext . '" alt="' . $param_array['caption'] . '" /></a>' . $img_post; } break; } return $output; }