settings['full_domain_name'], '/',SITEURL).'/wp-content/plugins/' . PLUGIN_BASENAME.'/'); define('POSTTHUMB_USE_HS', $PTRevisited->settings['hs_use']=='true'); define('POSTTHUMB_USE_TB', $PTRevisited->settings['tb_use']=='true'); // call classes if (POSTTHUMB_USE_HS == 'true') require(PT_ABSPATH . 'lib/post-thumb-highslide.php'); if (POSTTHUMB_USE_TB == 'true') require(PT_ABSPATH . 'lib/post-thumb-thickbox.php'); ################################################################################ ########## MAIN CLASS ################################################################################ class PostThumbRevisited { var $settings; var $post_array = array(); var $wordtube_options; var $playertype; var $playertypemp3; var $wordtube_abspath; var $wt_path = 'wordtube'; var $table_pt_post; /** * PostThumbRevisited * * Constructor for the PostThumbRevisited class. */ function PostThumbRevisited () { global $table_prefix, $wpdb; // Load language file $locale = get_locale(); if ( !empty($locale) ) load_textdomain('post-thumb', PT_ABSPATH.'languages/' . 'post-thumb'.$locale.'.mo'); // Insert the menu and options add_option('post_thumbnail_settings','','Post Thumb Revisited Options'); if (function_exists('pt_include_header')) add_action('wp_head', array(&$this, 'pt_include_header')); $this->table_pt_post = $table_prefix . "pt_post"; // $this->settings = get_option('post_thumbnail_settings'); $this->settings = pt_GetStarterOptions(); $wpdb->wordtube = $table_prefix . 'wordtube'; $wpdb->wordtube_med2play = $table_prefix . 'wordtube_med2play'; if (is_admin()) { include ( PT_ABSPATH . '/post-thumb-options.php' ); $PTAdmin = new PostThumbAdmin($this); } else $this->GetPostList(); // add filters if ($this->settings['hs_post'] == 'true') { add_filter('the_content', array(&$this, 'pt_ReplaceThumbnails')); if ($this->settings['pt_replace'] == 'true') add_filter('the_content', array(&$this, 'pt_ReplaceImage')); if ($this->settings['hs_wordtube'] == 'true') { $this->InitWordTube(); if ($this->settings['wt_media'] == 'true') add_filter('the_content', array(&$this, 'pt_ReplaceWTMedia')); if ($this->settings['wt_playlist'] == 'true') add_filter('the_content', array(&$this, 'pt_ReplaceWTPlaylist')); } if ($this->settings['hs_youtube'] == 'true') add_filter('the_content', array(&$this, 'pt_ReplaceYoutube')); } } /***********************************************************************************/ /* Retrieve posts informations /***********************************************************************************/ function GetPostList () { global $wpdb; if($wpdb->get_var("show tables like '$this->table_pt_post'") == $this->table_pt_post) { $dbresults = $wpdb->get_results(" SELECT * FROM ".$this->table_pt_post." ORDER BY post_id DESC"); if ($dbresults) { foreach ($dbresults as $dbresult) : $this->post_array[$dbresult->post_id] = stripslashes($dbresult->body); endforeach; } unset($dbresults); } // print_r($this->post_array); } /***********************************************************************************/ /* Get thumbnail. Loop function. /***********************************************************************************/ function GetPostData ($key) { return unserialize($this->post_array[$key]); } /***********************************************************************************/ /* Get thumbnail. Loop function. /***********************************************************************************/ function GetThumb ($arg='') { global $post; setup_postdata($post); $post_link = $this->GetSingleThumb ($post, $arg); return $post_link; } /***********************************************************************************/ /* Get thumbnail. Loop function. /***********************************************************************************/ function GetSingleThumb ($post, $arg='', $before='', $after='', $post_array='') { $path = pathinfo($post_array['media_url']); if ($post_array['media_url'] != '' && $path['extension']=='') { $p = new pt_post_thumbnail( $this->settings, $post, $arg, $post_array['image_url'], $post_array['media_url'], $post_array['permalink'], $post_array['title'], $post_array['date'], $post_array['author'], false); $p->InitWordTube($this->wordtube_options, $this->playertype); $post_link = $p->pt_GetImgHTML(); unset ($p); } if ($post_array['media_url'] != '') { $p = new pt_post_thumbnail( $this->settings, $post, $arg, $post_array['image_url'], $post_array['media_url'], $post_array['permalink'], $post_array['title'], $post_array['date'], $post_array['author'], false); $p->InitWordTube($this->wordtube_options, $this->playertype); $post_link = $p->pt_GetImgHTML(); unset ($p); } elseif ($post_array['image_url'] != '') { $p = new pt_post_thumbnail( $this->settings, $post, $arg, $post_array['image_url'], $post_array['media_url'], $post_array['permalink'], $post_array['title'], $post_array['date'], $post_array['author'], false); $post_link = $p->pt_GetImgHTML(); unset ($p); } else { $p = new pt_post_thumbnail($this->settings, $post, $arg); $post_link = $p->pt_GetImgHTML(); unset ($p); } if ( !empty($post_link) ) return $before.$post_link.$after; else return $before.$after; } /***********************************************************************************/ /* Returns recent posts /***********************************************************************************/ function GetTheRecentThumbs ($arg='', $beforeli='', $afterli='', $before='', $after='') { // Create a query object to retrieve posts $my_query = new WP_Query(); parse_str($arg, $new_args); $new_args = array_change_key_case($new_args, CASE_UPPER); if (isset($new_args['MEDIA'])) $media = $new_args['MEDIA']; else $media = 'all'; if (isset($new_args['LIMIT'])) { $limit = $new_args['LIMIT']; settype($limit,"integer"); } else $limit = 8; if (isset($new_args['OFFSET'])) { $offset = $new_args['OFFSET']; settype($offset,"integer"); } else $offset = 0; if (isset($new_args['CATEGORY'])) { $cat_ID = $new_args['CATEGORY']; $posts = $my_query->query('cat='.$cat_ID.'&showposts='.$limit.'&offset='.$offset); } else $posts = $my_query->query('showposts='.$limit.'&offset='.$offset); unset ($my_query); $content = $before; $l = $limit+$offset; // Retrieve only images if ($media == '0') { $i = 1; foreach ($this->post_array as $key => $post_arrayS) : $post_array = $this->GetPostData($key); if ($i > $l) break; if ($i > $offset) { if ($post_array['media_url'] == '') { $content .= $this->GetSingleThumb ('', $arg, $beforeli, $afterli, $post_array); $i++; } } else { if ($post_array['media_url'] == '') $i++; } endforeach; } // Retrieve non-youtube media elseif ($media == '1') { $i = 1; foreach ($this->post_array as $key => $post_arrayS) : $post_array = $this->GetPostData($key); if ($i > $l) break; if ($i > $offset) { if ($post_array['media_url'] != '') { $path = pathinfo($post_array['media_url']); if ($path['extension'] != '') { $content .= $this->GetSingleThumb ('', $arg, $beforeli, $afterli, $post_array); $i++; } } } else { if ($post_array['media_url'] != '') $i++; } endforeach; } // Retrieve youtube media elseif ($media == '2') { $i = 1; foreach ($this->post_array as $key => $post_arrayS) : $post_array = $this->GetPostData($key); if ($i > $l) break; if ($i > $offset) { if ($post_array['media_url'] != '') { $path = pathinfo($post_array['media_url']); if ($path['extension'] == '') { $content .= $this->GetSingleThumb ('', $arg, $beforeli, $afterli, $post_array); $i++; } } } else { if ($post_array['media_url'] != '') { $path = pathinfo($post_array['media_url']); if ($path['extension'] == '') $i++; } } endforeach; } // Retrieve all-media elseif ($media == '3') { $i = 1; foreach ($this->post_array as $key => $post_arrayS) : $post_array = $this->GetPostData($key); if ($i > $l) break; if ($i > $offset) { if ($post_array['media_url'] != '') { $content .= $this->GetSingleThumb ('', $arg, $beforeli, $afterli, $post_array); $i++; } } else { if ($post_array['media_url'] != '') $i++; } endforeach; } else { foreach ($posts as $post) : $post_array = $this->GetPostData($post->ID); $content .= $this->GetSingleThumb ($post, $arg, $beforeli, $afterli, $post_array); endforeach; } $content .= $after; return $content; } /***********************************************************************************/ /* Return random thumbnails. /* /* LIMIT: number of posts to test to obtain an image. Default is 5. /* RLIMIT: number of thumbnail to display. Default is 1. /***********************************************************************************/ function GetRandomThumb ($arg='', $beforeli='', $afterli='', $before='', $after='') { global $wp_query; $temp_query = $wp_query; $random_str = ''; parse_str($arg, $new_args); $new_args = array_change_key_case($new_args, CASE_UPPER); if (isset($new_args['LIMIT'])) { $limit = $new_args['LIMIT']; settype($limit,"integer"); } else $limit = 1; if (isset($new_args['CATEGORY'])) $cat_ID = $new_args['CATEGORY']; else $cat_ID =''; $posts = $this->RandomId($limit, $cat_ID); if ($limit == 1) $random_str = $this->GetSingleThumb ('', $arg.'&BASENAME=1&ALTAPPEND=azerty123456789'.$i, $beforeli, $afterli, $this->GetPostData($posts)); else { for ($i=1; $i <= $limit; $i++) : $random_str .= $this->GetSingleThumb ('', $arg.'&BASENAME=1&ALTAPPEND=azerty123456789'.$i, $beforeli, $afterli, $this->GetPostData($posts[$i])); endfor; } $wp_query = $temp_query; unset ($temp_query); return $random_str; } /****************************************************************/ /* Returns displayable post content /****************************************************************/ function RandomId($limit=1, $catid='') { if ($catid == '') $ret = array_rand ($this->post_array, $limit); else { $rand = array(); foreach ($this->post_array as $key => $post_arrayS) : $post_array = $this->GetPostData($key); if (in_array($catid, $post_array['categories'])) $rand[$key]=$post_array; endforeach; $ret = array_rand ($rand, $limit); } unset($rand); return $ret; } /****************************************************************/ /* Returns displayable post content /****************************************************************/ function pt_TheExcerpt($length=40, $title_after= false, $arg='') { global $post; setup_postdata($post); $p = new pt_post_thumbnail($this->settings, $post, $arg); $post_link = $p->pt_GetImgHTML(); unset ($p); $post->post_content = exclude_regex($post->post_content); $excerpt = get_excerpt_revisited($length); if ($title_after) $title = '
\[PTPLAYLIST=(.*?)]\<\/p>/i'; if (preg_match_all($pattern, $content, $matches, PREG_SET_ORDER)) { foreach ($matches as $match) : $replacement = '[PTPLAYLIST='.$match[1].'(.*?)]'; $content = str_replace($match[0], $replacement, $content); endforeach; } return $content; } /****************************************************************/ /* Filter function (if Highslide is activated) /****************************************************************/ function pt_CleanWTMedia($content) { // Replace wordTube MEDIA with parameters $pattern = '/\
\[MEDIA=(.*?)\]\<\/p>/i';
if (preg_match_all($pattern, $content, $matches, PREG_SET_ORDER)) {
foreach ($matches as $match) :
$replacement = '[MEDIA='.$match[1].'(.*?)]';
$content = str_replace($match[0], $replacement, $content);
endforeach;
}
return $content;
}
/****************************************************************/
/* Returns wordTube media
/****************************************************************/
function pt_ReturnMediaFromPlaylist($media, $play_width, $play_height, $mp3, $flv, $arg='') {
if ($mp3 || $flv) {
$med_url = pathinfo($media->file);
if ($mp3) {
if (strtoupper($med_url['extension']) == 'MP3') {
$replacement = $this->pt_GetVideo($media->name, $media->file, $media->image, $play_width, $play_height, $arg);
}
}
if ($flv) {
if (strtoupper($med_url['extension']) == 'FLV') {
$replacement = $this->pt_GetVideo($media->name, $media->file, $media->image, $play_width, $play_height, $arg);
}
}
}
else
$replacement = $this->pt_GetVideo($media->name, $media->file, $media->image, $play_width, $play_height, $arg);
return $replacement;
}
/****************************************************************/
/* Returns wordTube media
/****************************************************************/
function pt_GetwordTubeMedia($vid, $play_width, $play_height, $arg='') {
global $wpdb;
$select = " SELECT * FROM $wpdb->wordtube WHERE vid = ".$vid;
$media = $wpdb->get_row($select);
if ($media)
return $this->pt_GetVideo($media->name, $media->file, $media->image, $play_width, $play_height, $arg);
else
return '';
}
/****************************************************************/
/* Returns wordTube playlist
/****************************************************************/
function pt_GetwordTubePlaylist($pid) {
global $wpdb;
if ($pid == '0')
$select = " SELECT * FROM {$wpdb->wordtube} ORDER BY vid DESC";
else
$select = " SELECT * FROM {$wpdb->wordtube} w
INNER JOIN {$wpdb->wordtube_med2play} m
WHERE (m.playlist_id = '".$pid."' AND m.media_id = w.vid)
GROUP BY w.vid
ORDER BY m.rel_id DESC";
return $wpdb->get_results($select);
}
/****************************************************************/
/* Returns formatted wordTube playlist
/****************************************************************/
function pt_GetWTMedia ($vid, $arg='', $play_width=0, $play_height=0) {
if ($play_width == 0) $play_width = $this->settings['wordtube_pwidth'];
if ($play_height == 0) $play_height = $this->settings['wordtube_pheight'];
$replacement = $this->pt_GetwordTubeMedia($vid, $play_width, $play_height, $arg);
return $replacement;
}
/****************************************************************/
/* Returns formatted wordTube playlist
/****************************************************************/
function pt_GetWTPlaylist($pid, $arg='', $play_width=0, $play_height=0, $mp3=false, $flv=false) {
if ($play_width == 0) $play_width = $this->settings['wordtube_pwidth'];
if ($play_height == 0) $play_height = $this->settings['wordtube_pheight'];
parse_str($arg, $new_args);
$new_args = array_change_key_case($new_args, CASE_UPPER);
if (isset($new_args['LIMIT'])) { $limit = $new_args['LIMIT']; settype($limit,"integer"); } else $limit = 5;
if (isset($new_args['OFFSET'])) { $offset = $new_args['OFFSET']; settype($offset,"integer"); } else $offset = 0;
$l = $limit+$offset;
$dbresults = $this->pt_GetwordTubePlaylist($pid);
if ($dbresults) {
$replacement = '';
$i=1;
foreach ($dbresults as $media) :
if ($i > $l) break;
if ($i > $offset)
$replacement .= $this->pt_ReturnMediaFromPlaylist($media, $play_width, $play_height, $mp3, $flv, $arg);
$i++;
endforeach;
}
unset ($dbresults);
return $replacement;
}
/****************************************************************/
/* Filter function (if Highslide is activated)
/****************************************************************/
function pt_ReplaceThumbnails($content) {
$r_ID = rand();
// Replace thumbnail
$pattern = '/(.*?)/i';
if (preg_match_all($pattern,$content,$matches, PREG_SET_ORDER)) {
$i=1;
foreach ($matches as $match) :
$ID = $r_ID.$i;
$href = "\n".'';
$img_src = "\n\t".'
';
$caption = "\n".'';
$replacement = $href.$img_src.$caption;
$content = str_replace($match[0], $replacement, $content);
$i++;
endforeach;
}
return $content;
}
/****************************************************************/
/* Filter function (if Highslide is activated)
/****************************************************************/
function pt_ReplaceImage($content) {
// Thumbnails image and replace
$pattern = '/
/i';
if (preg_match_all($pattern, $content, $matches, PREG_SET_ORDER)) {
foreach ($matches as $match) :
$replacement = $this->pt_MakeThumb($match);
$content = str_replace($match[0], $replacement, $content);
endforeach;
}
$pattern = '/
/i';
if (preg_match_all($pattern, $content, $matches, PREG_SET_ORDER)) {
foreach ($matches as $match) :
$match2 = array( 1 => $match[1], 2 => $match[3], 3 => $match[4], 4 => $match[2], 5 => $match[5]);
$replacement = $this->pt_MakeThumb($match2);
$content = str_replace($match[0], $replacement, $content);
endforeach;
}
return $content;
}
/****************************************************************/
/* Filter function (if Highslide is activated)
/****************************************************************/
function pt_ReplaceYoutube($content) {
// Replace Youtube
$pattern1 = '/\[youtube=\((.*?)\)(.*?)\]/i';
$pattern2 = '@\@i';
$pattern3 = '/\