wordtube = $wpdb->prefix . 'wordtube';
$wpdb->wordtube_med2play = $wpdb->prefix . 'wordtube_med2play';
// Adds parameters
if (get_pt_options('p_rounded') == 'true')
$this->addArg = '&rounded=1';
else
$this->addArg = '&rounded=0';
if (get_pt_options('p_keep_ratio') == 'true')
$this->addArg .= '&keepratio=1';
else
$this->addArg .= '&keepratio=0';
if (get_pt_options('p_max') == 'true')
$this->addArg .= '&max=1';
else
$this->addArg .= '&max=0';
if (get_pt_options('p_subfolder') != '')
$this->addArg .= '&subfolder='.get_pt_options('p_subfolder');
if (get_pt_options('p_dirname') != '' && get_pt_options('p_dirname') != '0')
$this->addArg .= '&dirname='.get_pt_options('p_dirname');
if (get_pt_options('p_use_png') == 'true')
$this->addArg .= '&mime=png';
if (get_pt_options('p_lightbox') == 'true') $this->lightbox = ' rel="lightbox"';
$this->p_has_caption = (get_pt_options('p_caption') == 'true');
$this->p_rel = (get_pt_options('p_rel') == 'true');
// ReplaceImage is activated with rel="thumb" in the img
add_filter('the_content', array(&$this, 'ReplaceImage'));
// Other options can only be available if highslide is activated
if (((POSTTHUMB_USE_HS || POSTTHUMB_USE_TB))) {
// ReplaceLinks is activated with rel="ptlink" in the img
add_filter('the_content', array(&$this, 'ReplaceLinks'));
// Image with thumbnails filter
if (get_pt_options('pt_replace') == 'true') {
add_filter('the_content', array(&$this, 'ReplaceThumbnails'));
}
// wordTube filter
if (get_pt_options('wt_media') == 'true') {
add_filter('the_content', array(&$this, 'ReplaceWTMedia'));
if (get_pt_options('wt_playlist') == 'true')
add_filter('the_content', array(&$this, 'ReplaceWTPlaylist'));
}
// Youtube filter
if (get_pt_options('ytb_media') == 'true')
add_filter('the_content', array(&$this, 'ReplaceYoutube'));
}
add_filter('the_content_rss', array(&$this, 'ReplaceImage'), 5);
add_action('rss2_item', array(&$this, 'ReplaceImage'), 5);
}
/****************************************************************/
/* Filter function (if Highslide is activated)
/****************************************************************/
function ReplaceThumbnails($content) {
$attrList=array ("src", "alt", "title", "align", "width", "height");
if (is_feed()) return $content;
$r_ID = rand();
// Replace thumbnail
$pattern = '/]*)href=[\'|"]([^>]*).(bmp|jpg|jpeg|gif|png)[\'|"]([^>]*)>]*)\/><\/a>/si';
if (preg_match_all($pattern,$content,$matches, PREG_SET_ORDER)) {
$i=1;
foreach ($matches as $match) :
$ID = $r_ID.$i;
if (POSTTHUMB_USE_HS) {
$href = '';
$img_src = '
';
$caption = '
)*\s*\[MEDIA=([0-9]+%?)\]\s*(?:
)*@i'; if (preg_match_all($pattern, $content, $matches, PREG_SET_ORDER)) { $play_width = get_pt_options('wordtube_pwidth'); $play_height = get_pt_options('wordtube_pheight'); foreach ($matches as $match) : $replacement = $this->GetwordTubeMedia($match[1], $play_width, $play_height); if ($replacement != '') $content = str_replace($match[0], $replacement, $content); $i++; endforeach; } $pattern = '@(?:)*\s*\[MEDIA=([0-9]+%?)(.*?)\]\s*(?:
)*@i'; if (preg_match_all($pattern, $content, $matches, PREG_SET_ORDER)) { foreach ($matches as $match) : $str_match = strtoupper($match[0]); if (preg_match('/\[(.*?)WIDTH=([0-9]+%?)(.*?)\]/i', $str_match, $foo3)) $play_width = $foo3[2]; else $play_width = get_pt_options('wordtube_pwidth'); if (preg_match('/\[(.*?)HEIGHT=([0-9]+%?)(.*?)\]/i', $str_match, $foo4)) $play_height = $foo4[2]; else $play_height = get_pt_options('wordtube_pheight'); $replacement = $this->GetwordTubeMedia($match[1], $play_width, $play_height); if ($replacement != '') $content = str_replace($match[0], $replacement, $content); $i++; endforeach; } return $content; } /****************************************************************/ /* Filter function (if Highslide is activated) /****************************************************************/ function ReplaceWTPlaylist($content) { global $wpdb; if (is_feed()) return $content; if (stripos($content, '[PTPLAYLIST=') === false) return $content; // Replace wordTube post-thumb ptplaylist $pattern = '@(?:)*\s*\[PTPLAYLIST=\((.*?)\)(.*?)]\s*(?:
)*@i'; if (preg_match_all($pattern, $content, $matches, PREG_SET_ORDER)) { foreach ($matches as $match) : $str_match = strtoupper($match[0]); $vid_array = explode(",",$match[1]); if ($match[1] != '0') $where = "WHERE vid IN ('" . implode("','", $vid_array) . "')"; $dbresults = $wpdb->get_results("SELECT * FROM $wpdb->wordtube $where"); if ($dbresults) { $replacement = ''; $mp3 = strpos($str_match, 'MP3'); $flv = strpos($str_match, 'FLV'); if (preg_match('/\[(.*?)WIDTH=([0-9]+%?)(.*?)\]/i', $str_match, $foo3)) $play_width = $foo3[2]; else $play_width = get_pt_options('wordtube_pwidth'); if (preg_match('/\[(.*?)HEIGHT=([0-9]+%?)(.*?)\]/i', $str_match, $foo4)) $play_height = $foo4[2]; else $play_height = get_pt_options('wordtube_pheight'); foreach ($dbresults as $media) : $replacement .= $this->ReturnMediaFromPlaylist($media, $play_width, $play_height, $mp3, $flv); endforeach; $content = str_replace($match[0], $replacement, $content); } unset($dbresults); $i++; endforeach; } // Replace wordTube ptplaylist $pattern = '@(?:)*\s*\[PTPLAYLIST=([0-9]+%?)(.*?)]\s*(?:
)*@i'; if (preg_match_all($pattern, $content, $matches, PREG_SET_ORDER)) { foreach ($matches as $match) : $str_match = strtoupper($match[0]); $dbresults = $this->GetwordTubePlaylist($match[1]); if ($dbresults) { $replacement = ''; $mp3 = stripos($str_match, 'MP3'); $flv = stripos($str_match, 'FLV'); if (preg_match('/\[(.*?)WIDTH=([0-9]+%?)(.*?)\]/i', $str_match, $foo3)) $play_width = $foo3[2]; else $play_width = get_pt_options('wordtube_pwidth'); if (preg_match('/\[(.*?)HEIGHT=([0-9]+%?)(.*?)\]/i', $str_match, $foo4)) $play_height = $foo4[2]; else $play_height = get_pt_options('wordtube_pheight'); foreach ($dbresults as $media) : $replacement .= $this->ReturnMediaFromPlaylist($media, $play_width, $play_height, $mp3, $flv); endforeach; $content = str_replace($match[0], $replacement, $content); } unset($dbresults); endforeach; } return $content; } /****************************************************************/ /* Returns wordTube media /****************************************************************/ function ReturnMediaFromPlaylist($media, $play_width, $play_height, $mp3, $flv, $arg='') { $replacement = ''; if ($mp3 || $flv) { $med_url = pathinfo($media->file); if ($mp3) { if (strtoupper($med_url['extension']) == 'MP3') { $replacement = $this->GetVideo($media->name, $media->file, $media->image, $play_width, $play_height, $arg, $media->vid); } } if ($flv) { if (strtoupper($med_url['extension']) == 'FLV') { $replacement = $this->GetVideo($media->name, $media->file, $media->image, $play_width, $play_height, $arg, $media->vid); } } } else $replacement = $this->GetVideo($media->name, $media->file, $media->image, $play_width, $play_height, $arg, $media->vid); return $replacement; } /****************************************************************/ /* Returns wordTube media /****************************************************************/ function GetwordTubeMedia($vid, $play_width, $play_height, $arg='') { global $wpdb; $select = " SELECT * FROM $wpdb->wordtube WHERE vid = ".$vid; $media = $wpdb->get_row($select); if ($media) { if ($play_height == 0) $play_height = $play_width * $media->height / $media->width; return $this->GetVideo($media->name, $media->file, $media->image, $play_width, $play_height, $arg, $vid); } else return ''; } /****************************************************************/ /* Returns wordTube playlist /****************************************************************/ function 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 GetWTMedia ($vid, $arg='', $play_width=0, $play_height=0) { if ($play_width == 0) $play_width = get_pt_options('wordtube_pwidth'); if ($play_height == 0) $play_height = get_pt_options('wordtube_pheight'); $replacement = $this->GetwordTubeMedia($vid, $play_width, $play_height, $arg); return $replacement; } /****************************************************************/ /* Returns formatted wordTube playlist /****************************************************************/ function GetWTPlaylist($pid, $arg='', $play_width=0, $play_height=0, $mp3=false, $flv=false) { if ($play_width == 0) $play_width = get_pt_options('wordtube_pwidth'); if ($play_height == 0) $play_height = get_pt_options('wordtube_pheight'); $new_args = pt_parse_arg($arg); 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->GetwordTubePlaylist($pid); if ($dbresults) { $replacement = ''; $i=1; foreach ($dbresults as $media) : if ($i > $l) break; if ($i > $offset) $replacement .= $this->ReturnMediaFromPlaylist($media, $play_width, $play_height, $mp3, $flv, $arg); $i++; endforeach; } unset ($dbresults); return $replacement; } /****************************************************************/ /* Filter function (if Highslide is activated) /****************************************************************/ function ReplaceLinks($content) { $attrList=array ("src", "alt", "title", "align", "width", "height"); if (is_feed()) return $content; if ((stripos($content, 'rel="ptlink"') === false) and (stripos($content, "rel='ptlink'") === false)) return $content; $r_ID = rand(); // Replace thumbnail $pattern = '/)*\s*\[youtube=\((.*?)\)(.*?)\]\s*(?:
)*@i'; $pattern2 = '@(?:)*\s*\\s*(?:
)*@i'; $pattern3 = '@(?:)*\s*\
)*@is'; $pat_title = '/(.*?)title=[\'|"](.*?)[\'|"]/i'; // $pattern3 = '/\/is'; if (stripos($content, 'http://youtube.com/watch?v=') !== false) { if (preg_match_all($pattern2, $content, $matches, PREG_SET_ORDER)) { foreach ($matches as $match) : if (preg_match($pat_title, $match[0], $mat_title)) $title = $mat_title[2]; else $title = ''; $thumb = 'http://img.youtube.com/vi/'.$match[2].'/0.jpg" width="'.get_pt_options('youtube_width').'" height="'.get_pt_options('youtube_height'); $replacement = SetYoutubeVideo ($match[2], $title, $thumb, get_pt_options_all()); $content = str_replace($match[0],$replacement, $content); endforeach; } } if (stripos($content, 'http://www.youtube.com/v/') !== false) { if (preg_match_all($pattern3, $content, $matches, PREG_SET_ORDER)) { foreach ($matches as $match) : str_replace (''.$match[0].'
', $match[0], $content); if (preg_match($pat_title, $match[0], $mat_title)) $title = $mat_title[2]; else $title = ''; $ytbID = explode('&', $match[4]); $thumb = 'http://img.youtube.com/vi/'.$ytbID[0].'/0.jpg" width="'.get_pt_options('youtube_width').'" height="'.get_pt_options('youtube_height'); $replacement = SetYoutubeVideo ($ytbID[0], '', $thumb, get_pt_options_all()); $content = str_replace($match[0],$replacement, $content); endforeach; } } if (stripos($content, '[youtube=') !== false) { if (preg_match_all($pattern1, $content, $matches, PREG_SET_ORDER)) { foreach ($matches as $match) : str_replace (''.$match[0].'
', $match[0], $content); $thumb = 'http://img.youtube.com/vi/'.$match[1].'/0.jpg" width="'.get_pt_options('youtube_width').'" height="'.get_pt_options('youtube_height'); if (preg_match($pat_title, $match[0], $mat_title)) $title = $mat_title[2]; else $title = ''; $replacement = SetYoutubeVideo ($match[1], $title, $thumb, get_pt_options_all()); $content = str_replace($match[0],$replacement, $content); endforeach; } } return $content; } /****************************************************************/ /* Get category image /****************************************************************/ function GetVideo ($name, $file, $image, $play_width, $play_height, $arg='', $vid) { // Init parameters $settings = ''; $path = pathinfo($file); $extension = strtolower($path['extension']); $hs_width = $play_width; $ID = 'v'.rand(); // Prepare the script string if ($extension == "flv") $text = get_pt_options('wordtube_vtext'); elseif ($extension == "mp3") { $text = get_pt_options('wordtube_mtext'); $playertype = get_wt_playertypemp3(); if (get_wt_options('showeq')) $play_height=70; else $play_height = 20; } $new_args = pt_parse_arg($arg); if (isset($new_args['MYCLASSHREF'])) $myclasshref = $new_args['MYCLASSHREF']; else $myclasshref = ''; if (isset($new_args['MYCLASSIMG'])) $myclassimg = ' class="'.$new_args['MYCLASSIMG'].'"'; else $myclassimg = ''; // Get thumbnail if ($arg == '') $t = new pt_thumbnail(get_pt_options_all(), $image, 'keepratio=0&width='.get_pt_options('wordtube_width').'&height='.get_pt_options('wordtube_height').'&altappend='.get_pt_options('wordtube_text').'&textbox=1&text='.$text.$this->addArg); else $t = new pt_thumbnail(get_pt_options_all(), $image, $arg.$this->addArg); $thumb_url = $t->thumb_url; unset($t); // returns custom message for RSS feeds if (is_feed()) { if (!empty($thumb_url)) $replace = '