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') include(PT_ABSPATH . 'lib/post-thumb-highslide.php'); if (POSTTHUMB_USE_TB == 'true') include(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; var $LoadPostLimit = 200; /** * PostThumbRevisited * * Constructor for the PostThumbRevisited class. */ function PostThumbRevisited () { global $table_prefix, $wpdb, $wp_query; // 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 = 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 { if (is_feed()) { $PTRevisited->settings['hs_use']='false'; $PTRevisited->settings['tb_use']='false'; } $this->GetPostList(); } // add filters if ($this->settings['pt_replace'] == 'true') add_filter('the_content', array(&$this, 'pt_ReplaceImage'), 31); if ($this->settings['hs_post'] == 'true') { add_filter('the_content', array(&$this, 'pt_ReplaceThumbnails')); 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 LIMIT ".$this->LoadPostLimit); if ($dbresults) { foreach ($dbresults as $dbresult) : $this->post_array[$dbresult->post_id] = stripslashes($dbresult->body); endforeach; } unset($dbresults); } } /***********************************************************************************/ /* Get thumbnail. Loop function. /***********************************************************************************/ function GetPostData ($key) { if (array_key_exists($key, $this->post_array)) return unserialize($this->post_array[$key]); else return ''; } /***********************************************************************************/ /* Get thumbnail. Loop function. /***********************************************************************************/ function GetThumb ($arg='') { global $post; setup_postdata($post); return $this->GetSingleThumb ($post, $arg, $beforeli, $afterli, $this->GetPostData($post->ID)); } /***********************************************************************************/ /* 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'], true); $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'], true); $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'], true); $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 ''; } /***********************************************************************************/ /* 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); // Retrieves specific parameters 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'];$catid = explode(',', $cat_ID);$cat_arg = '&cat='.$cat_ID; } else {$cat_arg = '';$cat_ID='';$catid=array();} $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'] == '' && $this->in_category($post_array, $catid)) { $content .= $this->GetSingleThumb ('', $arg, $beforeli, $afterli, $post_array); $i++; } } else { if ($post_array['media_url'] == '' && in_category($post_array, $cat_ID)) $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'] != '' && $this->in_category($post_array, $catid)) { $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'] != '' && $this->in_category($post_array, $catid)) { $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'] != '' && $this->in_category($post_array, $catid)) { $content .= $this->GetSingleThumb ('', $arg, $beforeli, $afterli, $post_array); $i++; } } else { if ($post_array['media_url'] != '') $i++; } endforeach; } else { $posts = $my_query->query('showposts='.$limit.'&offset='.$offset.$cat_arg); foreach ($posts as $post) : $post_array = $this->GetPostData($post->ID); $content .= $this->GetSingleThumb ($post, $arg, $beforeli, $afterli, $post_array); endforeach; unset ($my_query); unset ($posts); } $content .= $after; return $content; } /****************************************************************/ /* Returns true if post is in category id /****************************************************************/ function in_category($post_array, $catid='') { if ($catid[0] == '') return true; if ($catid[0] < 0) { $catid= explode('-', implode('', $catid)); return (count(array_intersect($catid, unserialize($post_array['categories']))) == 0); } else return (count(array_intersect($catid, unserialize($post_array['categories']))) != 0); } /***********************************************************************************/ /* Return random thumbnails. /* /* LIMIT: number of thumbnail to display. Default is 1. /***********************************************************************************/ function GetRandomThumb ($arg='', $beforeli='', $afterli='', $before='', $after='') { parse_str($arg, $new_args); $new_args = array_change_key_case($new_args, CASE_UPPER); // Retrieves specific parameters if (isset($new_args['LIMIT'])) { $limit = $new_args['LIMIT']; settype($limit,"integer"); } else $limit = 1; if (isset($new_args['CATEGORY'])) $catid = explode(',', $new_args['CATEGORY']); else $catid =array(); if (isset($new_args['ALTAPPEND'])) $altappend = $new_args['ALTAPPEND']; else $altappend = 'azerty123456789'; if (isset($new_args['BASENAME'])) $basename = ($new_args['BASENAME'] == 1); else $basename = false; $posts = $this->RandomId($limit, $catid); if ($limit == 1) $random_str = $this->GetSingleThumb ('', $arg.'&ALTAPPEND='.$altappend, $beforeli, $afterli, $this->GetPostData($posts)); else { $i = 1; foreach ($posts as $post) : if ($basename) $add = $i; else $add = ''; $random_str .= $this->GetSingleThumb ('', $arg.'&ALTAPPEND='.$altappend.$add, $beforeli, $afterli, $this->GetPostData($post)); $i++; endforeach; } return $random_str; } /****************************************************************/ /* Returns displayable post content /****************************************************************/ function RandomId($limit=1, $catid='') { if ($catid[0] == '') $ret = array_rand ($this->post_array, $limit); else { $rand = array(); $i = 0; foreach ($this->post_array as $key => $post_arrayS) : $post_array = $this->GetPostData($key); if ($this->in_category($post_array, $catid)) { $rand[$key]=$post_array; $i++; } endforeach; if ($i < $limit) $limit = $i; $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, $media->vid);
}
}
if ($flv) {
if (strtoupper($med_url['extension']) == 'FLV') {
$replacement = $this->pt_GetVideo($media->name, $media->file, $media->image, $play_width, $play_height, $arg, $media->vid);
}
}
}
else
$replacement = $this->pt_GetVideo($media->name, $media->file, $media->image, $play_width, $play_height, $arg, $media->vid);
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, $vid);
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 = '/(.*?) \n".$match[0]."\n ".$match[0]."/is';
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 = '/
/is';
if (preg_match_all($pattern, $content, $matches, PREG_SET_ORDER)) {
foreach ($matches as $match) :
str_replace ("
/is';
if (preg_match_all($pattern, $content, $matches, PREG_SET_ORDER)) {
foreach ($matches as $match) :
str_replace ("