|
|
Stargeek's PHP ScriptsPlease select a category: |
Search Stargeek's PHP Scripts Database
|
php rss aggregator script php rss aggregator this php script will Pull a List of RSS feed addresses out of a mysql database. Perform responsiveness check with socket connection, compare poll results to database of headlines, if unique, add. Also formats template for display.
#!/usr/bin/php4
<?php
// this is run as a cli php script
/*
the Rss entry Table
CREATE TABLE `headlines` (
`id` int(10) unsigned NOT NULL auto_increment,
`site` text,
`date` text,
`category` text,
`link` text,
`headline` text,
`description` text,
PRIMARY KEY (`id`),
FULLTEXT KEY `description` (`description`,`headline`),
FULLTEXT KEY `headline` (`headline`)
) TYPE=MyISAM;
the Feed URL table:
CREATE TABLE `feeds` (
`address` varchar(255) default NULL,
`site` varchar(255) default NULL,
UNIQUE KEY `address` (`address`)
) TYPE=MyISAM;
*/
echo "Start Grabber.php v0.0.3 \n";
ini_set('include_path', '.:/usr/local/lib/php');
require('RSS.php');
function getmicrotime(){
list($usec, $sec) = explode(" ",microtime());
return ((float)$usec + (float)$sec);
}
$start = getmicrotime();
//conection code $linkID should be db connection
//i use log . php as an include file
$feedsResult = mysql_query('select * from feeds', $linkID);
while ($line = mysql_fetch_assoc($feedsResult))
{
$feeds[] = $line;
}
$headlinesResult = mysql_query('select * from headlines', $linkID);
while ($line = mysql_fetch_assoc($headlinesResult))
{
if ($line['date']< (mktime()))
{
$titles[] = trim($line['headline']);
$links[] = trim($line['link']);
}
}
mysql_close($linkID);
$numbers = range (1,20);
srand ((float)microtime()*1000000);
shuffle ($feeds);
foreach ($feeds as $f)
{
echo $f['address']."\n";
$this = split('/', $f['address']);
$fp = fsockopen ($this[2], 80, $errno, $errstr, 8);
if ($fp)
{
//use php library's, pear's, XML_RSS class as the parser
$r = &new XML_RSS($f['address']);
$r->parse();
foreach ($r->getItems() as $value)
{
$value['title']= trim($value['title']);
$value['link']= trim($value['link']);
if ( (!in_array(trim($value['title']), $titles)) and (!(in_array($value['link'], $links))) and ($value['title']))
{
$titles[] = $value['title'];
$links[] = $value['link'];
echo $value['title']."\n";
list($link, $extension) = explode(".", $value['link']);
$title = $value['title']." ".$value['description'];
$title = $value['title'];
$link = $value['link'];
$desc = $value['description'];
$date = mktime();
$site = $f['site'];
$query = ("insert into headlines (site, date, category, link, headline, description) values ('".mysql_escape_string($site)."','".mysql_escape_string($date)."', '".mysql_escape_string($category)."', '".mysql_escape_string($link)."', '".mysql_escape_string($title)."', '".mysql_escape_string($desc)."')");
echo "inserting\n$query\n";
flush();
//conection code $linkID should be db connection
//i use log . php as an include file
$result = mysql_query($query, $linkID);
mysql_close($linkID);
}
}
}
else
{
echo "unresponsive\n";
}
}
//conection code $linkID should be db connection
//i use log . php as an include file
//make index.html page, used as a template by index . php
$query = "select id, link, headline, date, category, site, description from headlines order by id desc limit 40";
$result = mysql_query($query, $linkID);
$categories = array();
$counter=0;
while($line = mysql_fetch_assoc($result))
{
if($sites[$line['site']] >3)
{
}
else
{
$main[$counter]['headline'] = "<a class=\"hd\" target=\"blank\" href=\"http://www.stargeek.com/link.php?link=".$line['id']."\">".$line['headline']."</a>";
$main[$counter]['date'] = date("m/d/y h:i", $line['date']);
$main[$counter]['text'] = wordwrap ( $line['description']."[Site: ".$line['site']."]", 40, '<br/>', 1);
$categories[] = $line['category'];
$sites[$line['site']]++;
$counter++;
}
}
$date = 'Last Updated: '.date("m/d/y h:i");
$result = mysql_query("select site from feeds", $linkID);
$totalFeeds = mysql_num_rows($result);
$proctime = getmicrotime() - $start;
$title = "stargeek.com";
ob_start();
include("www/index2.html");
$output = ob_get_contents();
ob_end_clean();
echo "index.html created\n";
flush();
$fp = fopen("www/index.inc.php", "w+");
fputs ($fp, $output);?>
|
|