Location: PHPKode > scripts > MyVideoBlog LITE - Automatic Wordpress Video Blogs! > myvideoblog-lite-automatic-wordpress-video-blogs/myvideoblog/mvb_main.php
<?php
/*
Plugin Name: PHP MyVideoBlog LITE
Plugin URI: http://www.phpmyvideoblog.com
Description: Auto add post videos to your blog. LITE Version
Version: 3.1.5
Author: JotaBiz
Author URI: http://www.phpmyvideoblog.com
*/

$mvb_version = "3.1";
$mvb_showversion = "3.1.5";

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

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

    return $string;
}

function mvb_install () {
   global $wpdb;
   global $mvb_version;

$charset_collate = '';

if ( version_compare(mysql_get_server_info(), '4.1.0', '>=') ) {
	if ( ! empty($wpdb->charset) )
		$charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
	if ( ! empty($wpdb->collate) )
		$charset_collate .= " COLLATE $wpdb->collate";
}

   $table_name = $wpdb->prefix . "myvideoblog";
   if($wpdb->get_var("show tables like '$table_name'") != $table_name) {
      
      $sql = "CREATE TABLE " . $table_name . " (
	  fid mediumint(9) NOT NULL AUTO_INCREMENT,
	  feed varchar(200) NOT NULL,
	  category varchar(200) NOT NULL,
	  active varchar(3) NOT NULL,
	  maxvideos mediumint(9) NOT NULL,
	  poststatus varchar(10) NOT NULL,
	  sunday char(3) NOT NULL,
	  monday char(3) NOT NULL,
	  tuesday char(3) NOT NULL,
	  wednesday char(3) NOT NULL,
	  thursday char(3) NOT NULL,
	  friday char(3) NOT NULL,
	  saturday char(3) NOT NULL,
	  commentstatus varchar(10) NOT NULL,
	  pingstatus varchar(10) NOT NULL,
	  blocktags blob NOT NULL,
	  checktitle varchar(3) NOT NULL,
	  checkdesc varchar(3) NOT NULL,
	  checktags varchar(3) NOT NULL,
	  postauthor mediumint(3) NOT NULL DEFAULT  '1',
	  scheduletime int(10) NOT NULL,
	  grab_comments varchar(3) NOT NULL DEFAULT 'no',
	  max_comments int(50) NOT NULL DEFAULT '0',
	  aprove_comments varchar(3) NOT NULL DEFAULT 'yes',
	  PRIMARY KEY fid (fid)
	) $charset_collate;";

      require_once(ABSPATH . 'wp-admin/upgrade-functions.php');
      dbDelta($sql);
}
   $table_name = $wpdb->prefix . "mvbconfig";
   if($wpdb->get_var("show tables like '$table_name'") != $table_name) {
      
      $sql = "CREATE TABLE " . $table_name . " (
	tid smallint(6) NOT NULL auto_increment,
	postdefault text NOT NULL,
	posttemplate text NOT NULL,
	securitykey varchar(12) NOT NULL,
	removeurls varchar(3) NOT NULL,
	copyimages varchar(3) NOT NULL,
	descsize smallint(3) NOT NULL,
	imglib varchar(3) NOT NULL,
	pwsize smallint(3) NOT NULL,
	phsize smallint(3) NOT NULL,
	myplayer varchar(3) NOT NULL,
	utf8_active varchar(3) NOT NULL,
	customfield_thumb varchar(30) NOT NULL,
	customfield_desc varchar(30) NOT NULL,
	customfield_vid varchar(30) NOT NULL,
	customfield_vidsource varchar(30) NOT NULL,
	thumbs_dir varchar(30) NOT NULL,
	theme_setting varchar(20) NOT NULL,
	jwplayer varchar(3) NOT NULL,
	customfield_vidembed varchar(30) NOT NULL,
	PRIMARY KEY  (`tid`)
	) $charset_collate;";

      $sk = mainnewsk();
      $sql2 = "INSERT INTO ".$table_name." VALUES (1, '<p>\n<a href=\"[posturl]\"><img src=\"[videoimage]\" width=\"120\" height=\"80\" alt=\"[videotitle]\" border=\"0\" align=\"left\"></a>\n[videodescription]\n<br clear=\"all\">\n</p>\n[hide]\n<p>\n<center>\n[videoplayer]\n</center>\n</p>', '<p>\n<a href=\"[posturl]\"><img src=\"[videoimage]\" width=\"120\" height=\"80\" alt=\"[videotitle]\" border=\"0\" align=\"left\"></a>\n[videodescription]\n<br clear=\"all\">\n</p>\n[hide]\n<p>\n<center>\n[videoplayer]\n</center>\n</p>', '$sk', 'yes', 'yes', '400', 'no', '430', '350', 'no', 'yes', 'mvb_thumb_url', 'mvb_vid_desc', 'mvb_vid_url', 'mvb_vid_source', 'videoimages', 'default', 'no', '');";

      require_once(ABSPATH . 'wp-admin/upgrade-functions.php');
      dbDelta($sql);
      dbDelta($sql2);
      add_option('mvb_installed_ver', '3.1');
   }
	  
	$cronfile = ABSPATH . 'wp-content/plugins/myvideoblog/mvb_cronserver.php';
	$newcronfile = ABSPATH . ''.$sk.'.php';
	if (file_exists($cronfile)) {
	rename($cronfile, $newcronfile);
	}
	
	$installed_ver = get_option('mvb_installed_ver');
	if((!$installed_ver) OR ($installed_ver != $mvb_version )) {
	$table_name = $wpdb->prefix . "myvideoblog";
	$sql = "CREATE TABLE " . $table_name . " (
	  fid mediumint(9) NOT NULL AUTO_INCREMENT,
	  feed varchar(200) NOT NULL,
	  category varchar(200) NOT NULL,
	  active varchar(3) NOT NULL,
	  maxvideos mediumint(9) NOT NULL,
	  poststatus varchar(10) NOT NULL,
	  sunday char(3) NOT NULL,
	  monday char(3) NOT NULL,
	  tuesday char(3) NOT NULL,
	  wednesday char(3) NOT NULL,
	  thursday char(3) NOT NULL,
	  friday char(3) NOT NULL,
	  saturday char(3) NOT NULL,
	  commentstatus varchar(10) NOT NULL,
	  pingstatus varchar(10) NOT NULL,
	  blocktags blob NOT NULL,
	  checktitle varchar(3) NOT NULL,
	  checkdesc varchar(3) NOT NULL,
	  checktags varchar(3) NOT NULL,
	  postauthor mediumint(3) NOT NULL DEFAULT  '1',
	  scheduletime int(10) NOT NULL,
	  grab_comments varchar(3) NOT NULL DEFAULT 'no',
	  max_comments int(50) NOT NULL DEFAULT '0',
	  aprove_comments varchar(3) NOT NULL DEFAULT 'yes',
	  PRIMARY KEY fid (fid)
	) $charset_collate;";

      require_once(ABSPATH . 'wp-admin/upgrade-functions.php');
      dbDelta($sql);
	
	$table_name = $wpdb->prefix . "mvbconfig";
	$sql = "CREATE TABLE " . $table_name . " (
	tid smallint(6) NOT NULL auto_increment,
	postdefault text NOT NULL,
	posttemplate text NOT NULL,
	securitykey varchar(12) NOT NULL,
	removeurls varchar(3) NOT NULL,
	copyimages varchar(3) NOT NULL,
	descsize smallint(3) NOT NULL,
	imglib varchar(3) NOT NULL,
	pwsize smallint(3) NOT NULL,
	phsize smallint(3) NOT NULL,
	myplayer varchar(3) NOT NULL,
	utf8_active varchar(3) NOT NULL,
	customfield_thumb varchar(30) NOT NULL,
	customfield_desc varchar(30) NOT NULL,
	customfield_vid varchar(30) NOT NULL,
	customfield_vidsource varchar(30) NOT NULL,
	thumbs_dir varchar(30) NOT NULL,
	theme_setting varchar(20) NOT NULL,
	jwplayer varchar(3) NOT NULL,
	customfield_vidembed varchar(30) NOT NULL,
	PRIMARY KEY  (`tid`)
	) $charset_collate;";

      $sql2 = "UPDATE ".$table_name." SET myplayer = 'no', utf8_active = 'yes', customfield_thumb = 'mvb_thumb_url', customfield_desc = 'mvb_vid_desc', customfield_vid = 'mvb_vid_url', customfield_vidsource = 'mvb_vid_source', thumbs_dir = 'videoimages', theme_setting = 'default', jwplayer = 'no', customfield_vidembed = ''";

      require_once(ABSPATH . 'wp-admin/upgrade-functions.php');
      dbDelta($sql);
	  dbDelta($sql2);
      update_option('mvb_installed_ver', '3.1');
	  
	  
	 $table_name = $wpdb->prefix."myvideoblog";
	 $getcats = $wpdb->get_results("SELECT fid, category FROM ".$table_name." ORDER BY fid");
	 foreach ($getcats as $theinfo) {
	 $thecat = $theinfo->category;
	 $thefid = $theinfo->fid;
	 if (!is_array(unserialize($thecat))) {  
	 $arraycats = array();
	 $arraycats[] = "".$thecat."";
	 $thecategories = serialize($arraycats);
	 $wpdb->query("UPDATE ".$table_name." SET category = '$thecategories' WHERE fid = '$thefid'");
	 }
	 }
	 require_once(ABSPATH . 'wp-content/plugins/myvideoblog/mvb_upgrade.php');
	}
}

register_activation_hook( __FILE__, 'mvb_install' );

add_action('admin_head', 'mvbjs_header_admin');
function mvbjs_header_admin() {
	echo '<script type=\'text/javascript\' src=\''.get_option('siteurl').'/wp-content/plugins/myvideoblog/includes/functions.js\'></script>'."\n";
	}

add_action('admin_menu', 'myvideoblog_admin_menu');
function myvideoblog_admin_menu() {
	add_menu_page('MyVideoBlog', 'MyVideoBlog', 8, 'myvideoblog/mvb_main.php', 'MyVideoBlog_showfeeds');
        add_submenu_page('myvideoblog/mvb_main.php', 'My Feeds', 'My Feeds', 8, 'myvideoblog/mvb_main.php', 'MyVideoBlog_showfeeds');
        add_submenu_page('myvideoblog/mvb_main.php', 'Add New Feed', 'Add New Feed', 8, 'MVB_Add_New_Feed', 'MyVideoBlog_newfeed');
        add_submenu_page('myvideoblog/mvb_main.php', 'MVB Settings', 'MVB Settings', 8, 'MVB_Settings', 'MyVideoBlog_settings');
        add_submenu_page('myvideoblog/mvb_main.php', 'Auto-Updates Settings', 'Auto-Updates Settings', 8, 'MVB_Auto-Updates_Settings', 'MyVideoBlog_cronjob');
		add_submenu_page('myvideoblog/mvb_main.php', 'MVB Edit Feed', '', 8, 'MVB_Edit_Feed', 'MyVideoBlog_editfeed');
}

add_action('mvbcron_hook','MyVideoBlog_InternalCron');
add_action('deleted_post','MyVideoBlog_RemoveThumb');

function MyVideoBlog_showfeeds() {
global $wpdb, $wp_version, $mvb_version, $installed_ver;
require(ABSPATH . 'wp-content/plugins/myvideoblog/mvb_showfeeds.php');
}
function MyVideoBlog_newfeed() {
global $wpdb, $wp_version, $mvb_version;
require(ABSPATH . 'wp-content/plugins/myvideoblog/mvb_newfeed.php');
}
function MyVideoBlog_editfeed() {
global $wpdb, $wp_version, $mvb_version;
require(ABSPATH . 'wp-content/plugins/myvideoblog/mvb_editfeed.php');
}
function MyVideoBlog_cronjob() {
global $wpdb, $wp_version, $mvb_version;
require(ABSPATH . 'wp-content/plugins/myvideoblog/mvb_cronjob.php');
}
function MyVideoBlog_rewrite() {
global $wpdb, $wp_version, $mvb_version;
require(ABSPATH . 'wp-content/plugins/myvideoblog/mvb_rewrite.php');
}
function MyVideoBlog_settings() {
global $wpdb, $wp_version, $mvb_version;
require(ABSPATH . 'wp-content/plugins/myvideoblog/mvb_settings.php');
}
function MyVideoBlog_manualupdate() {
global $wpdb, $wp_version, $mvb_version;
$type = "manual";
$showoutput = $_REQUEST['showoutput'];
require(ABSPATH . 'wp-content/plugins/myvideoblog/mvb_getvideos.php');
}
function MyVideoBlog_processfeed() {
global $wpdb, $wp_version, $mvb_version;
$type = "processfeed";
$fid = $_GET['updatefeed'];
$showoutput = $_GET['showoutput'];
require(ABSPATH . 'wp-content/plugins/myvideoblog/mvb_getvideos.php');
}
function MyVideoBlog_InternalCron() {
global $wpdb, $wp_version, $mvb_version;
$type = "internal";
require(ABSPATH . 'wp-content/plugins/myvideoblog/mvb_getvideos.php');
update_option("mvbcron_triggercount",get_option("mvbcron_triggercount")+1);
}
function MyVideoBlog_RemoveThumb($post_id) {
global $wpdb, $wp_version;
$table_prefix = $wpdb->prefix;
$myconfigs = $wpdb->get_row("SELECT customfield_thumb, thumbs_dir FROM ".$table_prefix."mvbconfig WHERE tid = '1'");
$customfield_thumb = $myconfigs->customfield_thumb;
$thumbs_dir = $myconfigs->thumbs_dir;
$thumb_path = "".ABSPATH."wp-content/".$thumbs_dir."/";
if( strstr($thumb_path,"\\")){
$thumb_path = str_replace("/", "\\", $thumb_path);
}
$search_id = "img_".$post_id."_";
if(file_exists($thumb_path)) {
$search_thumb_dir = new DirectoryIterator($thumb_path);
foreach ( $search_thumb_dir as $thumb ) {
	$thumb_file = $thumb->getFilename();
	$thumb_full_path = "".$thumb_path."".$thumb_file."";
	if( strstr($thumb_file, $search_id)){
	unlink ($thumb_full_path);
	}
	}
}
}
function mvb_embed_code($postid, $pwsize, $phsize) {
global $wpdb, $id;
$getinfo = get_post_meta($id, mvb_vid_code, true);

if( strstr($getinfo,"|")){
$vidinfo  = explode('|', $getinfo);
$videohost = $vidinfo[0];
$vidcod = $vidinfo[1];
$vidcod = str_replace("http://www.youtube.com/v/", "", $vidcod);
$vidcod = str_replace("http://www.dailymotion.com/swf/video/", "", $vidcod);
$vidcod = str_replace("http://www.dailymotion.com/swf/", "", $vidcod);
$vidcod = str_replace("http://www.metacafe.com/fplayer/", "", $vidcod);
$vidcod = str_replace("/video.swf", "", $vidcod);
$vidcod = str_replace("&related=0", "", $vidcod);
$vidcod = str_replace("&f=gdata_videos", "", $vidcod);
$str_after = strstr($vidcod, "?f");
if ($str_after) {$vidcod = str_replace($str_after, "", $vidcod);}
}else{
$videohost = get_post_meta($id, mvb_vid_source, true);
$vidcod = $getinfo;
}
$videohost = str_replace("gdata.", '', $videohost);
$videohost = str_replace("en.", '', $videohost);
$videohost = str_replace("rss.", '', $videohost);

$table_prefix = $wpdb->prefix;
$myconfigs = $wpdb->get_row("SELECT jwplayer FROM ".$table_prefix."mvbconfig WHERE tid = '1'");
$jwplayer = $myconfigs->jwplayer;

$siteurl = get_option('siteurl');
require(ABSPATH . 'wp-content/plugins/myvideoblog/mvb_players.php');
require(ABSPATH . 'wp-content/plugins/myvideoblog/mvb_showembed.php');
echo $embedcode;
}

function MyVideoBlog_showfooter() {
global $mvb_showversion;
echo "<br><br><div class=\"wrap\"><center>PHP MyVideoBlog LITE V".$mvb_showversion."<br><b>Buy Pro Version at <a href=\"http://www.phpmyvideoblog.com\" target=\"_blank\">PHPMyVideoBlog.com</a></b></center></div><br><br>";
}
?>
Return current item: MyVideoBlog LITE - Automatic Wordpress Video Blogs!