Skip to main content
php
ini_set('display_errors', 1);
require_once('config.php');
foreach ($fileUrls as $keyword = $fileUrl) {
$filename = basename($fileUrl) . PHP_EOL;
$filenameUrl = parse_url($fileUrl);
$filenameUrl = $filenameUrl["path"];
$ext = pathinfo($fileUrl, PATHINFO_EXTENSION);
if ($filename != NULL && $ext != NULL) {
if (file_exists('..' . $filenameUrl)) {
$html = new DOMDocument();
@$html->loadHTMLFile('..' . $filenameUrl);
// get container block
$rssblock = $html->getElementById('rssfeed');
// var_dump($rssblock);
if ($rssblock) {
$rssblock->nodeValue = '';
// exit();
$blockquote = $html->createElement('blockquote');
$url = 'http://news.google.com/news/feeds?pz=2&cf=all&hl=en&output=rss&q=' . $keyword;
$news = simplexml_load_file($url);
if ($news) {
$i = 1;
foreach ($news->channel->item as $item) {
// foreach ($item as $key => $value):
// var_dump($key);
// endforeach;
// exit();
$title = NULL;
$link = NULL;
$site_title = NULL;
$story = NULL;
$parts = explode('', $item->description);
$date = $title = (string) $item->pubDate;
$title = (string) $item->title;
$link = (string) $item->link;
$link = explode('&url=', $link);
$link = $link[1];
$site_title = strip_tags($parts[1]);
$story = strip_tags($parts[2]);
$rss_feed = $html->createElement('div');
$rss_feed->setAttribute('class', 'rss_feed');
////////////// rss content ////////////////
$rss_content = $html->createElement('div');
$rss_content->setAttribute('class', 'rss_content');
$rss_feed->appendChild($rss_content);
///////////// title /////////////////
$rss_link = $html->createElement('a');
$rss_link->setAttribute('href', $link);
$rss_link->setAttribute('class', 'rss_link');
$rss_link->setAttribute('rel', 'nofollow');
$rss_content->appendChild($rss_link);
$rss_content_title = $html->createElement('span');
$rss_content_title->setAttribute('class', 'rss_content_title');
$rss_content_title->nodeValue = $title;
$rss_link->appendChild($rss_content_title);
////////////////// date of news ///////////////
$rss_content_date = $html->createElement('span');
$rss_content_date->setAttribute('class', 'rss_content_date');
$rss_content_date->nodeValue = $date;
$rss_content->appendChild($rss_content_date);
///////////////// story /////////////////////
$rss_content_story = $html->createElement('span');
$rss_content_story->setAttribute('class', 'rss_content_story');
$rss_content_story->nodeValue = $story;
$rss_content->appendChild($rss_content_story);
$blockquote->appendChild($rss_feed);
if ($i == $newsCount):
break;
endif;
$i++;
}
$rssblock->appendChild($blockquote);
$html->saveHTMLFile('..' . $filenameUrl);
echo 'OK ... rss successfully added on