If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Bad Astronomy and Universe Today Forum > Universe Today > Universe Today Website Feedback
Register FAQ Members List Calendar Mark Forums Read

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-April-2005, 11:26 PM
karansokhey karansokhey is offline
Junior Member
 
Join Date: Apr 2005
Posts: 8
Default

I emailed info@universetoday.com but I didnt recive a reply and its been over 2 days. I just thought I would register to the forums and ask some questions. My emailed is quoted below, as I didnt want to take my time typing it out again. *I wasnt sure if Universe Today was admined by a single person or a group of members.
Quote:
I wanted the script on my website to educate the members. I don't like
the idea of using the java script and placing it on a website. You
can't skin the way it should appear on the page. With PHP you can do
this, and I can help. You can still have it so you update the file
like you do every weekday. It will have a file which they can download
and skin. Another file will be placed on universetoday.com In this
file there will be variables such as story1 and img1, story2 and img2.
You can also have the variable copyright or date... anything you wish.
In the file that the users will download they can customize how the
story should appear by placing where they would like the variables. So
now they can have the images on the right or the last story first...
you get the idea. Im new to PHP but this seems as an easy task and I
have many friends who are able to help me. I can take a couple days
and finish the script and you can have a look at it. You don't have to
take it under your consideration but just give the chance. I'd like to
have Space News on my website but have the ability to skin it. I've
drawn a little diagram which will help explain how it will work


I think this would give us PHP people benfits.
Reply With Quote
  #2 (permalink)  
Old 08-April-2005, 04:23 AM
Fraser's Avatar
Fraser Fraser is offline
Administrator
 
Join Date: Jul 2003
Location: Courtenay, BC, Canada
Posts: 10,743
Default

Hi Karan, the stories in Universe Today are available as an RSS feed.

http://www.universetoday.com/universetoday.xml

So you can format that data into your website in any way you like. I'm not sure about the images, though. Right now there are 1000s of websites currently depending on me to not change any part of the Javascript file. So, I'm going to hold off changing the way I syndicate things.

I appreciate your suggestions, though.
__________________
Fraser Cain
Publisher
Universe Today - Free space news delivered by email every weekday.
Reply With Quote
  #3 (permalink)  
Old 08-April-2005, 08:55 PM
karansokhey karansokhey is offline
Junior Member
 
Join Date: Apr 2005
Posts: 8
Default

Yes I understand that a lot of people are using the Javascript. It was worth a try. Can I see any examples of how it looks when its customized with the RSS. I never got the chance to see how RSS exactly works. Can you explain it to me please.
Reply With Quote
  #4 (permalink)  
Old 10-April-2005, 10:32 PM
gavwvin's Avatar
gavwvin gavwvin is offline
Senior Member
 
Join Date: Oct 2004
Posts: 230
Default

RSS is an incarnation of xml, which is a format very easily read by computers- similar to html in structure in that you have an opening tag, some data, then a closing tag. PHP has built in functions to parse an xml document such as an rss feed, enabling you to extract and display the information in any way you please.
Basically (unless you have php 5) to get php to parse a xml document you define 3 functions, what to do when php finds an opening tag, what to do when it finds some data between tags, and what to do when it finds a closing tag. In your case you want something like:
Code:
if($name=="LINK") {
  echo "<a href='".$data."'>Click here for the full UT story</a>";
} else if($name=="TITLE") {
  echo "<h2>".$data."</h2>";
} else if($name=="DESCRIPTION") {
  echo "<p>".$data."</p>";
}
I have done this on my website:
http://www.astronomyforbeginners.com/astro.../news.php?js=no
I can post or send you the php code if you like.
(Although note that the rss feed on UT does not contain urls for the images, so you can't show images for the stories)
Reply With Quote
  #5 (permalink)  
Old 13-April-2005, 09:13 PM
karansokhey karansokhey is offline
Junior Member
 
Join Date: Apr 2005
Posts: 8
Default

yes please could you post the code for me. I really wanted the images but what can you do btw why cant you have them? *new to php and all the rest but html* btw the news looks really cool on your website. if your allowed to upload a file could you do that please or send it to karansokhey@gmail.com

thank you
Reply With Quote
  #6 (permalink)  
Old 14-April-2005, 09:23 PM
gavwvin's Avatar
gavwvin gavwvin is offline
Senior Member
 
Join Date: Oct 2004
Posts: 230
Default

here goes:
Code:
<?php
function start_element($xml_parser,$name,$attr)
{
   	global $inside_item, $tag;
   if($inside_item) $tag=$name;
   else if($name=="ITEM") $inside_item=true;
}
function end_element($xml_parser,$name)
{
	global $inside_item, $tag, $title, $description, $link, $stories;
	if($name=="ITEM") {
 /*This is the bit you change to suit your display*/
 $stories[]="
 	<h2><a target='_blank' href='".$link."'>".$title."</a></h2>
 	<p>".$description."</p><br />
 	<hr />
 	<br />
 ";
 $title="";
 $link="";
 $description="";
 $inside_item=false;
	} 
}
function inside_element($xml_parser,$data)
{
	global $inside_item, $tag, $title, $description, $link;
	if($inside_item) {
 switch($tag) {
 	case "TITLE":
 	$title.=$data;
 	break;
 	
 	case "DESCRIPTION":
 	$description.=$data;
 	break;
 	
 	case "LINK":
 	$link.=$data;
 	break;
 }
	}
}
//--------end xml functions---------

function rss_feed($provider, $view = "all")
{
 //variables
  global $inside_item, $tag, $title, $description, $link, $stories;
  $inside_item = false;
  $title = "";
  $description = "";
  $link = "";
  $tag = "";
  $stories = array();
 
  //create parser
  $parser = xml_parser_create();
  xml_set_element_handler($parser, "start_element", "end_element");
  xml_set_character_data_handler($parser, "inside_element");
   
  //read xml file
	if($fh=@fopen($provider, "rb")) {
 while($fdata=fread($fh, 4096)) {
 	if(!@xml_parse($parser, $fdata,feof($fh))) {
  $failed = true;
  return false;
 	}
 }
	} else {
 $failed=true;
 return false;
  }
  fclose($fh);
  xml_parser_free($parser);
 
	//output
	if(!$failed) {
    if($view=="r") {
     return $stories[rand(0,(count($stories)-1))];
    } else if($view=="1") {
     return $stories[0];
    } else {
     $output="";
 	foreach($stories as $key=>$story) {
      $output.=$story;
     }
 	return $output;
    }
	}
}
?>
paste the above code into the page you want to use the feed (or in a functions file that is included from every page or something)
Then to get the output you do this:
Code:
$ut = rss_feed("http://www.universetoday.com/universetoday.xml");
echo $ut;
to output all the stories. Change the bit I've commented in the end_element() function to change the look of each story. You can also call the rss_feed function with a second argument to give one story chosen at random:
Code:
$ut = rss_feed("http://www.universetoday.com/universetoday.xml","r");
echo $ut;
or just the top story:
Code:
$ut = rss_feed("http://www.universetoday.com/universetoday.xml","1");
echo $ut;
As for images, you'll have to ask fraser about that. I would like to see the image urls included as well, but its up to him.

Incidentally you can use the function for any feed that uses the same format, just call the function with the appropriate URL address of the feed.
Reply With Quote
  #7 (permalink)  
Old 15-April-2005, 12:51 AM
karansokhey karansokhey is offline
Junior Member
 
Join Date: Apr 2005
Posts: 8
Default

Cool thanks a lot. It works. I was just wondering if I only wanted to show 3 or 4 stories. How would that be done? I've already tried

Code:
$ut = rss_feed("http://www.universetoday.com/universetoday.xml","1,2,3");
echo $ut;
Code:
$ut = rss_feed("http://www.universetoday.com/universetoday.xml","1","2","3");
echo $ut;
Code:
$ut = rss_feed("http://www.universetoday.com/universetoday.xml","1");
echo $ut;
$ut = rss_feed("http://www.universetoday.com/universetoday.xml","2");
echo $ut;
$ut = rss_feed("http://www.universetoday.com/universetoday.xml","3");
echo $ut;
Code:
$ut = rss_feed("http://www.universetoday.com/universetoday.xml","3");
echo $ut;
Thanks bro.
Reply With Quote
  #8 (permalink)  
Old 15-April-2005, 12:58 AM
karansokhey karansokhey is offline
Junior Member
 
Join Date: Apr 2005
Posts: 8
Default

oh almost forgot to request something from fraser. do you think you could add images to the rss feed? it makes it so much more interesting. Right now it just looks like plain text that wouldnt mean anything to the audiance such as kids.
Reply With Quote
  #9 (permalink)  
Old 15-April-2005, 07:08 AM
gavwvin's Avatar
gavwvin gavwvin is offline
Senior Member
 
Join Date: Oct 2004
Posts: 230
Default

Have to adapt the function for that (the 3 or 4 stories). Sent you a PM with the modifications to the function (don't want to bore everyone else by posting all that code again )
Reply With Quote
  #10 (permalink)  
Old 16-April-2005, 06:13 PM
karansokhey karansokhey is offline
Junior Member
 
Join Date: Apr 2005
Posts: 8
Default

thanks a lot gavwvin. It works!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 08:19 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.0.0
©  2006 Bad Astronomy and Universe Today