thumb_url : thumbnail url
$this->thumb_path : thumbnail path on server
**********************************************************************/
class pt_thumbnail {
var $settings;
var $arg;
var $the_image;
var $extension;
var $thumb_url;
var $thumb_path;
var $sub_folder;
var $alt_append;
var $alt_append2;
var $append;
var $resize_width=0;
var $resize_height=0;
var $crop_x=0;
var $crop_y=0;
var $keep_ratio=false;
var $rounded=false;
var $base_name=false;
var $textBox;
var $text;
var $width = 0;
var $height = 0;
var $use_png = false;
var $use_jpg = false;
var $error = false;
var $wordtube_options='';
var $playertype='';
/****************************************************************/
/* Constructor
/****************************************************************/
function pt_thumbnail ($settings, $img_url='', $arg='') {
$this->the_image = $img_url;
$this->settings = $settings;
$this->arg = $arg;
$this->pt_parse_arg();
$this->pt_get_thumbnail();
}
/****************************************************************/
/* Retrieve all parameters
/****************************************************************/
function pt_parse_arg () {
parse_str($this->arg, $new_args);
$new_args = array_change_key_case($new_args, CASE_UPPER);
if (isset($new_args['SUBFOLDER']))
$this->sub_folder = '/'.$new_args['SUBFOLDER'];
else $this->sub_folder ='';
if ($this->sub_folder == '/') $this->sub_folder ='';
if (isset($new_args['ALTAPPEND']))
$this->alt_append = $new_args['ALTAPPEND'];
else
$this->alt_append = $this->settings['append_text'];
if (isset($new_args['APPEND']))
$this->append = ($new_args['APPEND']==1);
else
$this->append = ($this->settings['append'] == 'true');
if (isset($new_args['ADDAPPEND']))
$this->alt_append2 = $new_args['ADDAPPEND'];
else
$this->alt_append2 = '';
if (isset($new_args['WIDTH']))
$this->resize_width = $new_args['WIDTH'];
else
$this->resize_width = (int) $this->settings['resize_width'];
if (isset($new_args['HEIGHT']))
$this->resize_height = $new_args['HEIGHT'];
else
$this->resize_height = (int) $this->settings['resize_height'];
if (isset($new_args['HCROP']))
$this->crop_x = $new_args['HCROP'];
else
$this->crop_x = 0;
if (isset($new_args['VCROP']))
$this->crop_y = $new_args['VCROP'];
else
$this->crop_y = 0;
if (isset($new_args['KEEPRATIO']))
$this->keep_ratio = ($new_args['KEEPRATIO']==1);
else
$this->keep_ratio = ($this->settings['keep_ratio'] == 'true');
if (isset($new_args['MIME'])) {
$this->use_png = ($new_args['MIME']=='png');
$this->use_jpg = ($new_args['MIME']=='jpg');
}
else
$this->use_png = ($this->settings['use_png'] == 'true');
if (isset($new_args['ROUNDED']))
$this->rounded = ($new_args['ROUNDED']==1);
else
$this->rounded = ($this->settings['rounded'] == 'true');
if ($this->rounded) $this->use_png = true;
if (isset($new_args['BASENAME']))
$this->base_name = ($new_args['BASENAME']==1);
else
$this->base_name = false;
if (isset($new_args['TEXTBOX']))
$this->textBox = ($new_args['TEXTBOX']==1);
else
$this->textBox = false;
if (isset($new_args['TEXT']))
$this->text = $new_args['TEXT'];
else
$this->text = '';
}
/****************************************************************/
/* Creates and returns thumbnail
/****************************************************************/
function pt_get_thumbnail() {
$the_image_server = str_replace(' ', '%20', str_replace($this->settings['full_domain_name'], $this->settings['base_path'], $this->the_image));
$dest_path = pathinfo($the_image_server);
$dest_path_temp['basename'] = $dest_path['basename'];
// dir to save thumbnail to
$save_dir = $this->settings['base_path'].'/'.$this->settings['folder_name'].$this->sub_folder;
// name to save to - Adds append text - Check extension
if ($this->use_png)
$this->extension = 'png';
elseif ($this->use_jpg)
$this->extension = 'jpg';
else
$this->extension = $dest_path['extension'];
$filename = substr($dest_path_temp['basename'], 0, strrpos($dest_path_temp['basename'], "."));
if ($this->base_name)
$rename_to = $this->alt_append.'.'.$this->extension;
elseif ($this->append == 'true')
$rename_to = $filename.$this->alt_append.$this->alt_append2.'.'.$this->extension;
else
$rename_to = $this->alt_append.$filename.$this->alt_append2.'.'.$this->extension;
$rename_to = str_replace (' ', '_', htmlentities($rename_to));
// checks if file already exists - returns location if it does
// If basename, force thumbnail generation
if (file_exists($save_dir.'/'.$rename_to) && (!$this->base_name)) {
$this->thumb_url = $this->settings['full_domain_name'].'/'.$this->settings['folder_name'].$this->sub_folder.'/'.$rename_to;
$this->thumb_path = $save_dir.'/'.$rename_to;
}
// check if image exists. If doesn't exist, can't do anything so return default image
elseif (!remote_file_exists($the_image_server)) {
$this->thumb_url = $this->settings['full_domain_name'].$this->sub_folder."/".$this->settings['default_image'];
$this->thumb_path = $this->settings['base_path']."/".$this->settings['default_image'];
}
// if file has to be generated, generates thumbnails
else {
$this->thumb_url = $this->settings['full_domain_name']."/".$this->settings['folder_name'].$this->sub_folder."/".$rename_to;
$this->thumb_path = $save_dir.'/'.$rename_to;
// Create the image
$thumb = new ImageEditor($dest_path['basename'],$dest_path['dirname'].'/', '', $this->settings);
// $thumb = new ImageEditor($this->the_image,'', '', $this->settings);
if ($thumb->img_error || $thumb->error) {
unset($thumb);
$this->error = true;
return false;
}
// Set output type if different from image
if ($this->use_png) $thumb->setImageType('png');
if ($this->use_jpg) $thumb->setImageType('jpg');
// Resize image
$thumb->resize($this->resize_width, $this->resize_height, $this->crop_x, $this->crop_y, $this->keep_ratio, $this->rounded);
// Round corner if option is checked
if ($this->rounded) {
$thumb->setImageType('png');
$thumb->rounded($this->settings['corner_ratio']);
}
// Adds text box if option is checked
if ($this->textBox && $this->text<>'') $thumb->AddBox (true, 0, 0, 0, 15, $this->text, 255, 255, 255, 15);
if (!$thumb->error) {
// If no error so far, saves thumbnail on server
$thumb->outputFile($save_dir."/".$rename_to, "", $this->settings['jpg_rate'], $this->settings['png_rate']);
// Get thumbnail size (may be different from resize size
$this->width = $thumb->getWidth();
$this->height = $thumb->getHeight();
}
else
$this->error = true;
unset($thumb);
}
}
} // End of pt_thumbnail class
/**********************************************************************
Class: pt_post_thumbnail
Generate a html linked to a post. This html:
- can contain a thumbnail from an image of the post
- can show several informations from the post
Returns:
$this->html
$this->thumb_url : thumbnail url
$this->thumb_path : thumbnail path on server
$this->the_image : url of the linked image
**********************************************************************/
class pt_post_thumbnail {
var $post;
var $settings;
var $arg;
var $the_default_image; // Image to use first
var $permalink;
var $default_title;
var $default_date;
var $default_author;
var $search;
var $post_url;
var $media_url;
var $media_title;
var $meta_content;
var $the_image;
var $extension;
var $has_image = true;
var $has_media = false;
var $has_youtube = false;
var $has_caption;
var $thumb_url;
var $thumb_path;
var $html;
var $title;
var $alt_text;
var $use_catname;
var $show_title;
var $img_title;
var $myclasshref;
var $myclassimg;
var $LB_effect;
var $showpost;
var $def_url;
var $width;
var $height;
var $resize_width;
/****************************************************************/
/* Constructor
/****************************************************************/
function pt_post_thumbnail ($settings, $post='', $arg='', $default_image='', $default_media='', $permalink='', $title='', $date='', $author='', $search=true) {
// Get all parameters
$this->post = $post;
$this->settings = $settings;
$this->arg = $arg;
$this->the_default_image = $default_image;
$this->the_default_media = $default_media;
$this->permalink = $permalink;
$this->default_title = $title;
$this->default_date = $date;
$this->default_author = $author;
$this->search = $search;
// Init local parameters
$path = pathinfo($this->the_default_media);
$this->has_media = ($this->the_default_media != '' && $path['extension']!='');
$this->has_youtube = ($this->the_default_media != '' && $path['extension']=='');
$this->def_url = $this->settings['full_domain_name']."/".$this->settings['default_image'];
$this->use_hs = ($this->settings['hs_use'] == 'true');
$this->use_tb = ($this->settings['tb_use'] == 'true');
if ($this->has_youtube) $this->arg .='&ADDAPPEND='.$this->the_default_media;
// Sets title && use jLanguage if present
if ($this->default_title != '')
$this->title = $this->default_title;
else
$this->title = $this->post->post_title;
if (function_exists('jLanguage_processTitle'))
$this->title = jLanguage_processTitle($this->title);
// Init permalink
if ($permalink == '')
$this->post_url = get_permalink($this->post->ID);
else
$this->post_url = $permalink;
// Set all the parameter options
$this->pt_parse_arg();
// Check if image should be retrieved first from meta data
if ($this->settings['use_meta'] == 'true' && $this->search)
$this->meta_content = get_post_meta($this->post->ID, 'pt_meta_thumb', true);
else
$this->meta_content = false;
// Get the image to thumbnailed
if ($this->search)
$this->pt_search_the_image();
else
$this->pt_get_the_image();
// Generate thumbnail
$t = new pt_thumbnail ($this->settings, $this->the_image, $this->arg);
if ($t->error) {
unset($t);
$t = new pt_thumbnail ($this->settings, $this->def_url, $this->arg);
}
$this->thumb_url = $t->thumb_url;
$this->thumb_path = $t->thumb_path;
$this->width = $t->width;
$this->height = $t->height;
unset($t);
// Use $this->pt_GetImgHTML(); to get output string
}
/****************************************************************/
/****************************************************************/
function pt_parse_arg ()
{
parse_str($this->arg, $new_args);
$new_args = array_change_key_case($new_args, CASE_UPPER);
if (isset($new_args['WIDTH']))
$this->resize_width = $new_args['WIDTH'];
else
$this->resize_width = (int) $this->settings['resize_width'];
if (isset($new_args['ALTTEXT']))
$this->alt_text = str_clean ($new_args['ALTTEXT']);
else
$this->alt_text = $this->post->post_title;
if (isset($new_args['USECATNAME']))
$this->use_catname = ($new_args['USECATNAME']==1);
else
$this->use_catname = ($this->settings['use_catname']=='true');
if (isset($new_args['SHOWTITLE']))
$this->show_title = $this->Return_Title($new_args['SHOWTITLE']);
else
$this->show_title = '';
if (isset($new_args['CAPTION']))
$this->has_caption = ($new_args['CAPTION'] == 1);
else
$this->has_caption = ($this->settings['caption']=='true');
if (isset($new_args['TITLE']))
$this->img_title = $this->Get_Title($new_args['TITLE']);
else
$this->img_title = $this->title;
if (isset($new_args['MYCLASSHREF']))
$this->myclasshref = $new_args['MYCLASSHREF'];
else
$this->myclasshref = '';
if (isset($new_args['MYCLASSIMG']))
$this->myclassimg = ' class="'.$new_args['MYCLASSIMG'].'"';
else
$this->myclassimg = '';
if (isset($new_args['LB_EFFECT']))
$this->LB_effect = ($new_args['LB_EFFECT']==1);
else
$this->LB_effect = false;
if (isset($new_args['SHOWPOST'])) {
$this->showpost = ($new_args['SHOWPOST']==1);
} else
$this->showpost = false;
}
/****************************************************************/
/****************************************************************/
function pt_get_the_image() {
// if image is already given
if ($this->the_default_image != '') {
$this->the_image = $this->the_default_image;
}
// If no image, return default image
else {
$this->the_image = $this->def_url;
$this->has_image = false;
}
}
/****************************************************************/
/****************************************************************/
function pt_search_the_image() {
// if image is already given
if ($this->the_default_image != '') {
$this->the_image = $this->the_default_image;
}
// finds an attachement to the post
elseif ($this->meta_content !== false && $this->meta_content != '') {
// put matches into recognizable vars
$this->the_image = tb_thumb_absolute($this->meta_content);
}
// finds an image from the post content
elseif (preg_match('//i', $this->post->post_content, $matches)) {
// put matches into recognizable vars
$this->the_image = tb_thumb_absolute($matches[2]);
// detects if the image is already linked to a thumbnail
$img_src = str_replace('/', '\/', $matches[2]);
$pattern = '/(.*?)
/i';
if (preg_match($pattern,$this->post->post_content,$matches))
$this->the_image = tb_thumb_absolute($matches[2].'.'.$matches[3]);
}
// If no image found in the post content - checks for video
elseif ($this->use_catname) {
$this->Get_DefaultCategory();
$this->image = $this->def_url;
$this->has_image = false;
}
// If no image found in the post content - checks for video
elseif (!empty($this->settings['video_regex']) && $this->pt_content_check_video()) {
$this->the_image = $this->settings['full_domain_name']."/".$this->settings['video_default'];
$this->has_image = false;
}
// If no image found yet - checks for videostream
elseif ($settings['stream_check']) {
$this->the_image = $this->pt_check_stream();
$this->has_image = false;
}
// If really no image, return default image
else {
$this->the_image = $this->def_url;
$this->has_image = false;
}
}
/****************************************************************/
/* Returns html string with link and thumbnail
/****************************************************************/
function pt_GetImgHTML() {
// Starts Highslide output
if ($this->LB_effect && $this->use_hs) {
// If showpost true, or post doesn't has picture, and post doesn't have media
if ($this->showpost || (!$this->has_image && !$this->has_media && !$this->has_youtube)) {
$h = new pt_highslide($this->post_url, $this->thumb_url, $this->title);
$h->set_colors($this->settings['bgcolor']);
$h->set_borders($this->settings['hsframe']);
$h->set_href_text($this->title, $this->myclassimg);
$h->set_myclasshref($this->myclasshref);
$h->set_bottom('Lien direct vers : '.$this->title, $this->post_url);
$h->set_size(800, 600);
$this->html = $h->highslide_link('iframe');
unset($h);
}
// If a media is given, links to the media
elseif ($this->has_media) {
$this->InitWordTube();
$this->html = $this->pt_GetVideo ($this->title, $this->the_default_media, $this->thumb_url, $this->settings['wordtube_pwidth'], $this->settings['wordtube_pheight']);
}
// If a media is given, links to the media
elseif ($this->has_youtube) {
$this->html = SetYoutubeVideo ($this->the_default_media, $this->title, $this->thumb_url, $this->settings, $this->myclassimg);
}
// Otherwise, links to picture
else {
$h = new pt_highslide($this->the_image, $this->thumb_url, $this->title);
$h->set_borders ($this->settings['ovframe']);
$h->set_href_text('', $this->myclassimg);
$h->set_myclasshref($this->myclasshref);
if ($this->has_caption)
$h->set_caption($this->title);
$this->html = $h->highslide_link('overlay');
unset($h);
}
}
// Starts Thickbox output
elseif ($this->LB_effect && $this->use_tb) {
// If an image and showpost false
if ($this->showpost || (!$this->has_image && !$this->has_media && !$this->has_youtube)) {
$this->html = "\n".'html .= ' title="'.$this->title.'"';
if ($this->myclasshref !='') $this->html .= ' class="'.$this->myclasshref.'"';
$this->html .= '>';
$this->html .= "\n\t".'
myclassimg != '') $this->html .= ' class="'.$this->myclassimg.'"';
$this->html .= ' />'."\n".'';
unset($h);
}
// If a media is given, links to the media
elseif ($this->has_media) {
$this->InitWordTube();
$this->html = $this->pt_GetVideo ($this->title, $this->the_default_media, $this->thumb_url, $this->settings['wordtube_pwidth'], $this->settings['wordtube_pheight']);
}
// If a media is given, links to the media
elseif ($this->has_youtube) {
$this->html = SetYoutubeVideo ($this->the_default_media, $this->title, $this->thumb_url, $this->settings, $this->myclassimg);
}
else {
$h = new pt_thickbox ($this->the_image, $this->thumb_url, $this->title);
$h->set_myclasshref($this->myclasshref);
$this->html = $h->thickbox_link('overlay');
unset($h);
}
}
// Starts output using no javascript library
else {
if ($this->showpost || !$this->has_image)
$this->html = "\n".'html = "\n".'html .= ' title="'.$this->title.'"';
if ($this->myclasshref !='') $this->html .= ' class="'.$this->myclasshref.'"';
$this->html .= '>';
$this->html .= "\n\t".'
html .= $this->myclassimg;
$this->html .= ' />'."\n".'';
}
if ($this->show_title != '') $this->pt_get_add_html();
return $this->html;
}
/****************************************************************/
/* Set additionnal html string with link and thumbnail
/****************************************************************/
function pt_get_add_html() {
$this->html .= $this->show_title;
}
/****************************************************************/
/* Check if there is a video in content using REGEX
/****************************************************************/
function pt_content_check_video() {
return (preg_match('/'.$this->settings['video_regex'].'/i',$this->post->post_content,$matches));
}
/****************************************************************/
/* Returns adhoc thumbnail for videostream
/****************************************************************/
function pt_check_stream() {
$the_image = '';
if (strpos($this->post->post_content, 'http://www.youtube.com/watch') !== false) {
$the_image = POSTTHUMB_URLPATH.'images/youtube.png';
}
// Tag from post-thumb library
elseif (!(strpos(strtoupper($this->post->post_content), '[YOUTUBE=(') === false)) {
$the_image = POSTTHUMB_URLPATH.'images/youtube.png';
}
// Tag from post-thumb library
elseif (!(strpos(strtoupper($this->post->post_content), '[DAILYMOTION=(') === false)) {
$the_image = POSTTHUMB_URLPATH.'/images/dailymotion.png';
}
elseif (!(strpos($this->post->post_content, 'http://www.dailymotion.com/swf') === false)) {
$the_image = POSTTHUMB_URLPATH.'/images/dailymotion.png';
}
elseif (!(strpos($this->post->post_content, 'http://video.google.fr/videoplay') === false)) {
$the_image = POSTTHUMB_URLPATH.'/images/gvideo.png';
}
elseif (!(strpos($this->post->post_content, 'http://video.google.com/videoplay') === false)) {
$the_image = POSTTHUMB_URLPATH.'/images/gvideo.png';
}
elseif (!(strpos($this->post->post_content, 'http://video.google.com/videoplay') === false)) {
$the_image = $this->settings['full_domain_name']."/".$this->settings['default_image'];
}
return $the_image;
}
/****************************************************************/
/* Returns adhoc thumbnail for videostream
/****************************************************************/
function pt_content_check_stream() {
$test = pt_check_stream();
return ($test == '');
}
/***********************************************************************************/
/* Test if image in content
/* $img_only = true : return true if an image is found in the current post
/* $img_only = false : return true if an image or a video is found in the current post
/***********************************************************************************/
function pt_post_content_test($img_only=false, $content='') {
// find an image from the post content
if (preg_match('/
post->post_content,$matches))
return true;
else
{
if (!empty($this->settings['video_regex']) && (!$img_only) && $this->pt_content_check_video())
return true;
if (($this->settings['stream_check']) && (!$img_only) && ($this->pt_content_check_stream()))
return true;
return false;
}
}
/****************************************************************/
/* Add post-thumb option SHOWTITLE
/****************************************************************/
function Return_Title ($showtitle='') {
$arg = strtoupper($showtitle);
$ret = "\n".'