<?php
$showerrors = "0";
if ($showerros == "1") {
error_reporting(E_ALL);
ini_set('display_errors', '1');
}
if ((ini_get('open_basedir') == "") OR (ini_get('safe_mode' == 'Off'))) {
$usefollow = "1";
}
set_time_limit(0);
require_once(ABSPATH . 'wp-content/plugins/myvideoblog/mvb_functions.php');
// Cheking configs and filters ------------------------------
$myconfigs = $wpdb->get_row("SELECT tid, posttemplate, removeurls, descsize, pwsize, phsize, utf8_active, jwplayer FROM ".$table_prefix."mvbconfig WHERE tid = '1'");
$mytemplate = $myconfigs->posttemplate;
$mytemplate = stripslashes($mytemplate);
$removeurls = $myconfigs->removeurls;
$descsize = $myconfigs->descsize;
$pwsize = $myconfigs->pwsize;
$phsize = $myconfigs->phsize;
$utf8_active = $myconfigs->utf8_active;
$jwplayer = $myconfigs->jwplayer;
$weekday = date("l");
$weekday = strtolower($weekday);
if ($type == "manual") {
$getfeeds = $wpdb->get_results("SELECT feed, category, active, maxvideos, poststatus, commentstatus, pingstatus, blocktags, checktitle, checkdesc, checktags, postauthor FROM ".$table_prefix."myvideoblog WHERE active = 'yes'");
} else if ($type == "processfeed") {
$getfeeds = $wpdb->get_results("SELECT fid, feed, category, active, maxvideos, poststatus, commentstatus, pingstatus, blocktags, checktitle, checkdesc, checktags, postauthor FROM ".$table_prefix."myvideoblog WHERE fid = '$fid'");
} else {
$getfeeds = $wpdb->get_results("SELECT feed, category, active, maxvideos, poststatus, commentstatus, pingstatus, blocktags, checktitle, checkdesc, checktags, postauthor FROM ".$table_prefix."myvideoblog WHERE active = 'yes' AND $weekday = 'yes'");
}
$ftotaladded=0;
$ptotaladded=0;
$feednotfound=0;
$youtube=0;
if($descsize == "0") {$descsize = "10000";}
// Looping active feeds ------------------------------
$mvbstats = array();
$notfoundstats = array();
if ($showoutput == "yes") {
echo "<p align=\"left\"><h2>Manual Update - Results</h2></p>";
flush_buffers();
}
foreach ($getfeeds as $myfeeds) {
$url = $myfeeds->feed;
$maxvideos = $myfeeds->maxvideos;
$category = unserialize($myfeeds->category);
$poststatus = $myfeeds->poststatus;
$commentstatus = $myfeeds->commentstatus;
$pingstatus = $myfeeds->pingstatus;
$checktitle = $myfeeds->checktitle;
$checkdesc = $myfeeds->checkdesc;
$checktags = $myfeeds->checktags;
$postauthor = $myfeeds->postauthor;
$blocktags = unserialize($myfeeds->blocktags);
$feedhost = strtolower($url);
$feedhost = str_replace("http://", "", $feedhost);
$feedhost = str_replace("www.", "", $feedhost);
$feedhost2 = strstr($feedhost, "/");
if ($feedhost2) {$feedhost = str_replace($feedhost2, "", $feedhost);}
if ($showoutput == "yes") {
$showfeedhost = str_replace("en.", '', $feedhost);
$showfeedhost = str_replace("gdata.", '', $showfeedhost);
$showfeedhost = str_replace("rss.", '', $showfeedhost);
echo "<p align=\"left\"><i><b>Connecting $showfeedhost...</b></i><br></p>";
flush_buffers();
}
// Looping Feed items ------------------------------
$max = 1;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
if($usefollow == "1") {
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
}
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
$curl_feed = curl_exec($ch);
curl_close($ch);
if (!$curl_feed) {
$feednotfound++;
$notfoundstats[] = $url;
continue;
} else {
$feed = simplexml_load_string($curl_feed, 'SimpleXMLElement', LIBXML_NOCDATA);
}
if ($feedhost == "gdata.youtube.com") {$theforeach = $feed->entry;} else {$theforeach = $feed->channel->item;}
foreach ($theforeach as $item) {
if($max > $maxvideos) {
break;
} else {
$media = $item->children('http://search.yahoo.com/mrss/');
$media_dm = $item->children('http://search.yahoo.com/mrss');
$extra = $item->children('http://www.itunes.com/dtds/podcast-1.0.dtd');
$metakewego = $item->children('http://www.w3.org/1999/02/22-rdf-syntax-ns');
if(isset($item->title)) {$title = $item->title;}
else if(isset($media->title)) {$title = $media->title;}
else if(isset($media_dm->title)) {$title = $media_dm->title;}
else if(isset($media->group->title)) {$title = $media->group->title;}
else if(isset($media->content->title)) {$title = $media->content->title;}
else {continue;}
$title = fixEncoding($title);
$checklink = sanitize_title($title);
if (!$checklink) {continue;}
$cl = $wpdb->get_var("SELECT post_name FROM $wpdb->posts WHERE post_name = '$checklink'");
if ($cl) {continue;}
// Get Videos from Gdata.YouTube.com ------------------------------
if ($feedhost == "gdata.youtube.com") {
if (!$media->group->content) {continue;}
$vidoriginal = $media->group->player->attributes();
$vidurl_original = str_replace("&feature=youtube_gdata", '', $vidoriginal['url']);
$vidinfo = $media->group->content->attributes();
preg_match("#http://(?:www\.)?youtube\.com/v\/([_\-a-z0-9]+)#i", $vidinfo, $matches);
$vidcod = $matches[1];
$vidtype = $vidinfo['type'];
$attrs = $media->group->thumbnail->attributes();
$thumbnail = $attrs['url'];
$keywords = $media->group->keywords;
$description = $media->group->description;
$description = trim(substr((str_replace("\n", ' ', str_replace("\r", ' ', strip_tags(StupefyEntities($description))))),0,$descsize))."...";
if ($jwplayer == "yes") {$siteurl = get_option('siteurl'); $postcontent = player_youtube_jwp($vidcod,$pwsize,$phsize,$siteurl);} else {$postcontent = player_youtube($vidcod,$pwsize,$phsize);}
$youtube++;
$mvbstats['Youtube'] = $youtube;
} // Get Videos from YouTube.com ------------------------------
else if ($feedhost == "youtube.com") {
if (!$item->enclosure) {continue;}
$vidinfo = $item->enclosure->attributes();
$vidurl_original = $vidinfo['url'];
$vidtype = $vidinfo['type'];
$vidcod = str_replace("http://youtube.com", "http://www.youtube.com", $vidurl_original);
$vidcod = str_replace("?v=", "v/", $vidcod);
$vidcod = str_replace("&f=videos&app=youtube_gdata", "", $vidcod);
$attrs = $media->thumbnail->attributes();
$thumbnail = $attrs['url'];
$keywords = $media->category;
$description = $item->description;
$removerest = strstr($description, "Author:");
$description = str_replace($removerest, "", $description);
$description = trim(substr((str_replace("\n", ' ', str_replace("\r", ' ', strip_tags(StupefyEntities($description))))),0,$descsize))."...";
if ($jwplayer == "yes") {$siteurl = get_option('siteurl'); $postcontent = player_youtube_jwp($vidcod,$pwsize,$phsize,$siteurl);} else {$postcontent = player_youtube($vidcod,$pwsize,$phsize);}
$youtube++;
$mvbstats['Youtube'] = $youtube;
} else {
continue;
}
}// Saving Data ------------------------------
$keywords = fixkeywords($keywords);
$keywords = fixEncoding($keywords);
$fixthumb = strstr($thumbnail, "?");
$thumbnail = str_replace($fixthumb, "", $thumbnail);
$videoimage = $thumbnail;
if($removeurls == "yes") {
$description = preg_replace("/(http:\/\/|(www\.))(([^\s<]{4,68})[^\s<]*)/", '', $description);
}
savepost($table_prefix, $mytemplate, $category, $postname, $keywords, $videoimage, $description, $postcontent, $poststatus, $title, $commentstatus, $pingstatus, $copyimages, $type, $imglib, $feedhost, $vidcod, $postauthor, $vidurl_original);
if ($showoutput == "yes") {
echo "<p align=\"left\"><i><font color=\"green\">Video added:</font> ".stripslashes($title)." <font color=\"green\">(".$poststatus.")</font></i><br></p>";
flush_buffers();
}
$ptotaladded++;
$max++;
} // END Item feeds ------------------------------
$ftotaladded++;
} // END Looping active feeds ------------------------------
if ($showoutput == "yes") {
echo "<p align=\"left\"><i><b>Done!</b></i></p>";
flush_buffers();
}
// Show Results ------------------------------
if(($type == "manual") OR ($type == "processfeed")) {
if ($feednotfound != "0") {
?>
<center><table class="widefat" width="70%" cellspacing="0">
<thead>
<tr>
<th scope="col"><b>MVB can not reach <?php echo "$feednotfound";?> feed(s):</b></th>
</tr>
</thead>
<?php
foreach ($notfoundstats as $feedsoff) {
echo "<tr><td bgcolor=\"#DDDDDD\"><a href=\"$feedsoff\" target=\"_blank\">$feedsoff</a></td></tr>";
}
?>
</table></center><br><br>
<?php
}
if ($ptotaladded > "0") {
?>
<center><table class="widefat" width="70%" cellspacing="0">
<thead>
<tr>
<th scope="col"><b>Sources:</b></th>
<th scope="col"><b><?php echo "$ptotaladded";?> videos added:</b></th>
</tr>
</thead>
<?php
foreach ($mvbstats as $provider => $grabs) {
echo "<tr><td bgcolor=\"#DDDDDD\">$provider</td><td bgcolor=\"#DDDDDD\">$grabs</td></tr>";
}
?>
</table></center><br><br>
<?php
} else {
echo "No videos added.<br>Maybe you already have all the videos from this source. Wait for the source to be updated.";
}
}else if($type == "internal") {
$notifymail = get_option("mvbcron_mail");
$frommail = get_option("admin_email");
if ($notifymail) {
$header = "From: PHPMyVideoBlog <" . $frommail . ">\r\n";
$mailmsg = "Hello!\n\n$ptotaladded new video(s) were added from $ftotaladded feed(s)!\n\nCheers!\nPHPMyVideoblog.com";
mail($notifymail, 'MVB - Blog Updated!', $mailmsg, $header);
}
echo "";
} else {
echo "OK! $ptotaladded new videos added from $ftotaladded feed(s)!<br>";
}
?>