#native_company# #native_desc#
#native_cta#

commondreams.org headline grabber

By Aaron
on April 17, 2002

Version: 0.1

Type: Full Script

Category: Other

License: GNU General Public License

Description: Returns a table with the latest headlines (you specify how many) from the politically lefty-leaning website commondreams.org.

<?php
// name:   	commondreams.inc
// date:    04/17/2002
// author: 	Aaron Smith
// email:  	[email protected]
// purpose: Returns a table containing the latest news from www.commondreams.org (a political site with a lefty bent). 
// use:     Just paste this somewhere in a script and it will output the table with the headlines
// notes:   Just something I threw together for my website (www.deadskunk.org -- has an example on the main page) as all
//          the news grabbing stuff is either too geeky or too corporate for my tastes.  Edit as much as you want, send
//          me an email if you have questions/comments.

$grab_url = "http://www.commondreams.org/headlines02/headlines.htm";
$number_of_headlines=5; //edit this to change the number of headlines that are displayed
$grab_start=array();
$grab_end=array();
$grab_start[0] = array("<!-- #BeginEditable "Body" -->","0");  
$grab_end[0] = array("<!-- #EndEditable -->","0");
$open_file = fopen("$grab_url", "r"); 
$retrieve_file = fread($open_file, 40000);  
fclose($open_file); 

$sizeof_grab_start=sizeof($grab_start);
$sizeof_grab_end=sizeof($grab_end);

if ($sizeof_grab_start>$sizeof_grab_end) {
	$sizeof_grab=$sizeof_grab_start;
} else {
	$sizeof_grab=$sizeof_grab_end;
}

for ($x=0;$x<$sizeof_grab;$x++) {
	if ($grab_start[$x]) {
	  if ($grab_start[$x][1]) {
			$grab_length=strlen($grab_end[$x][0])-1;
			$retrieve_file=strstr($retrieve_file,$grab_start[$x][0]);
			$retrieve_file=substr($retrieve_file,$grab_length);
		} else {
			$retrieve_file=strstr($retrieve_file,$grab_start[$x][0]);
		}
	}
	if ($grab_end[$x]) {
		if ($grab_end[$x][1]) {
			$grab_length=strlen($grab_end[$x][0]);
			$string_length=strlen($retrieve_file);
			$retrieve_file=strrev(strstr(strrev($retrieve_file),strrev($grab_end[$x][0])));
			$retrieve_file=substr($retrieve_file,0,$string_length-$grab_length);
		} else {
			$retrieve_file=strrev(strstr(strrev($retrieve_file),strrev($grab_end[$x][0])));
		}
	}
}
$retrieve_file=str_replace("href","target="_blank" href",$retrieve_file); // force clicks to open new browser window

if ($retrieve_file) { // this is where the formatting starts edit away here
	?>
	<table bgcolor=black width=200>
		<tr>
			<td>
				<center><font color="white"><b>News from Commondreams</font></center>
				<table bgcolor="#E1F0FF">
					<tr>
						<td>
							<?php
								$output=explode("n",$retrieve_file);
								for ($x=0;$x<$number_of_headlines;$x++) {
									echo $output[$x];
								}
							?>
						</td>
					</tr>
				</table>
			</td>
		</tr>
	</table>
	<?php
} // end of formatting, end of script
?>