Location: PHPKode > scripts > MyVideoBlog LITE - Automatic Wordpress Video Blogs! > myvideoblog-lite-automatic-wordpress-video-blogs/myvideoblog/mvb_functions.php
<?php
require(ABSPATH . 'wp-content/plugins/myvideoblog/mvb_players.php');
$table_prefix = $wpdb->prefix;
$wp_posts = "posts";
$mvbfeeds = "myvideoblog";
$mvbconf = "mvbconfig";
$tabletopost = "$table_prefix$wp_posts";
$tablemvbfeeds = "$table_prefix$mvbfeeds";
$tablemvbconfig = "$table_prefix$mvbconf";


function flush_buffers(){ 
    ob_start();
    ob_flush(); 
    flush(); 
    ob_end_flush(); 
} 

function returnImage($text) {
    //$text = html_entity_decode($text, ENT_QUOTES, 'UTF-8');
    //echo $text;
    $pattern = "/<img[^>]+\>/i";
    preg_match($pattern, $text, $matches);
    $text = $matches[0];
    return $text;
}

function fixEncoding($in_str) 
{ 
if (function_exists('mb_detect_encoding')) {
  $cur_encoding = mb_detect_encoding($in_str) ; 
  if($cur_encoding == "UTF-8" && mb_check_encoding($in_str,"UTF-8")) 
    return $in_str; 
  else 
    return utf8_encode($in_str); 
} else {
    return $in_str;
}
}

function scrapeImage($text) {
    
    $pattern = '/src=[\'"]?([^\'" >]+)[\'" >]/'; 
    
preg_match($pattern, $text, $link);

$link = $link[1];
return $link;
}

function shortdesc($string, $length) {
    $suffix = '...';
    $short_desc = trim(str_replace("\n", ' ', str_replace("\r", ' ', strip_tags(StupefyEntities($string)))));
    $desc = trim(substr($short_desc, 0, $length));
    $lastchar = substr($desc, -1, 1);
    if ($lastchar == '.' || $lastchar == '!' || $lastchar == '?') $suffix='';
    $desc .= $suffix;
}

// SmartyPants 1.5.1 changes rolled in May 2004 by Alex Rosenberg, http://monauraljerk.org/smartypants-php/
function StupefyEntities($s = '') {
    $inputs = array('–', '—', '‘', '’', '“', '”', '…', '[', ']');
    $outputs = array('-', '--', "'", "'", '"', '"', '...', '[', ']');
    $s = str_replace($inputs, $outputs, $s);
    return $s;
}

function newsk() {
    $length = 10;
    $characters = "0123456789abcdefghijklmnopqrstuvwxyz";   

    for ($p = 0; $p < $length; $p++) {
        $string .= $characters[mt_rand(0, strlen($characters))];
    }

    return $string;
}

function fixkeywords($keywords) {
$keywords = preg_replace('/(\'|")/', '', $keywords);
$keywords = trim($keywords);
$keywords = ucwords($keywords);
$keywords = ereg_replace("[.!#?$%&@*¨]","",$keywords);
$keywords = str_replace(" ", ',', $keywords);
return $keywords;
}

function makethumbtitle($thumbtitle) {
$thumbtitle = stripslashes($thumbtitle);
$thumbtitle = trim($thumbtitle);
$thumbtitle = ereg_replace("[.!#?$%&@:*¨]","",$thumbtitle);
$thumbtitle = str_replace("-", "", $thumbtitle);
$thumbtitle = str_replace("  ", "_", $thumbtitle);
$thumbtitle = str_replace(" ", "_", $thumbtitle);
$thumbtitle = str_replace(',', "", $thumbtitle);
$thumbtitle = preg_replace('/(\'|")/', '', $thumbtitle);
return $thumbtitle;
}

function savepost($table_prefix, $mytemplate, $category, $postname, $keywords, $thumbnail, $description, $postcontent, $poststatus, $title, $commentstatus, $pingstatus, $copyimages, $type, $imglib, $feedhost, $vidcod, $postauthor, $vidurl_original) {
global $wpdb;

$grabconfigs = $wpdb->get_row("SELECT * FROM ".$table_prefix."mvbconfig WHERE tid = '1'");
$mytemplate = $grabconfigs->posttemplate;
$mytemplate = stripslashes($mytemplate);
$copyimages = $grabconfigs->copyimages;
$imglib = $grabconfigs->imglib;
$customfield_thumb = $grabconfigs->customfield_thumb;
$customfield_desc = $grabconfigs->customfield_desc;
$customfield_vid = $grabconfigs->customfield_vid;
$customfield_vidsource = $grabconfigs->customfield_vidsource;
$thumbs_dir = $grabconfigs->thumbs_dir;
$theme_setting = $grabconfigs->theme_setting;
$customfield_vidembed = $grabconfigs->customfield_vidembed;

$mvb_savepost = array();
$mvb_savepost['post_title'] = $title;
$mvb_savepost['post_content'] = $description;
$mvb_savepost['post_status'] = $poststatus;
$mvb_savepost['post_author'] = $postauthor;
$mvb_savepost['comment_status'] = $commentstatus;
$mvb_savepost['ping_status'] = $pingstatus;
$mvb_savepost['post_category'] = $category;
if (($poststatus == "draft") OR ($poststatus == "pending")) {
$newpostname = sanitize_title($title);
$mvb_savepost['post_name'] = $newpostname;
}

// feed object to wp_insert_post
$post_id = wp_insert_post($mvb_savepost);
$guid = get_permalink($post_id);

if ($copyimages == "yes") {
	$videoimage = $thumbnail;
} else {
	$videoimage = $thumbnail;
}

$usetemplate = $mytemplate;
$usetemplate = str_replace("[videoimage]", $videoimage, $usetemplate);
$usetemplate = str_replace("[videotitle]", $title, $usetemplate);
$usetemplate = str_replace("[posturl]", $guid, $usetemplate);
$usetemplate = str_replace("[videodescription]", $description, $usetemplate);
$usetemplate = str_replace("[videourl]", $vidurl_original, $usetemplate);
$usetemplate = str_replace("[videosource]", $feedhost, $usetemplate);
$usetemplate = str_replace("[hide]", "<!--more-->", $usetemplate);
$usetemplate = str_replace("[videoplayer]", "<!--videoplayer-->".$postcontent."<!--endvideoplayer-->", $usetemplate);
$usetemplate = addslashes($usetemplate);
$wpdb->query("UPDATE $wpdb->posts SET post_content = '$usetemplate' WHERE ID = '$post_id'");



if (!is_array($keywords)) {
$keywords = explode(',', $keywords);
}
foreach ($keywords as $thetag) {
wp_add_post_tags($post_id, $thetag);
}

$feedhost = str_replace("gdata.", '', $feedhost);
$feedhost = str_replace("en.", '', $feedhost);
$feedhost = str_replace("rss.", '', $feedhost);

add_post_meta($post_id, $customfield_vidsource, $feedhost, true);
add_post_meta($post_id, 'mvb_vid_code', $vidcod, true);
add_post_meta($post_id, $customfield_desc, $description, true);
add_post_meta($post_id, $customfield_vid, $vidurl_original, true);
add_post_meta($post_id, $customfield_thumb, $videoimage, true);

if ($customfield_vidembed) {
	add_post_meta($post_id, $customfield_vidembed, $postcontent, true);
}

return $post_id;
}
?>
Return current item: MyVideoBlog LITE - Automatic Wordpress Video Blogs!