Pa kakav ti je site , jel koristis neki cms???nane_hercegovac wrote:Kako ubaciti onaj kod na stranicu sa RSS-a
Ne kontam, kad ubacim u svoju stranicu taj RSS ono mi bude isto kao kod, evo recimo hocu neke stvari da skinem sa SA-x ali ne znam kako to ide.
Pomozite
Kako ubaciti RSS
Moderator: Benq
-
Kid_A
- Posts: 217
- Joined: 14/03/2007 07:42
#1 Re: Kako ubaciti RSS
-
ABAP
- Posts: 162
- Joined: 10/05/2006 18:14
#3
Code: Select all
<?php
/* PHP RSS Reader v1.1
By Richard James Kendall
Bugs to [email protected]
Free to use, please acknowledge me
Place the URL of an RSS feed in the $file variable.
The $rss_channel array will be filled with data from the feed,
every RSS feed is different by by and large it should contain:
Array {
[TITLE] = feed title
[DESCRIPTION] = feed description
[LINK] = link to their website
[IMAGE] = Array {
[URL] = url of image
[DESCRIPTION] = alt text of image
}
[ITEMS] = Array {
[0] = Array {
[TITLE] = item title
[DESCRIPTION] = item description
[LINK = a link to the story
}
.
.
.
}
}
By default it retrives the Reuters Oddly Enough RSS feed. The data is put into the array
structure so you can format the information as you see fit.
*/
set_time_limit(0);
$file = "http://www.sarajevo-x.com/rss/sport";
$rss_channel = array();
$currently_writing = "";
$main = "";
$item_counter = 0;
function startElement($parser, $name, $attrs) {
global $rss_channel, $currently_writing, $main;
switch($name) {
case "RSS":
case "RDF:RDF":
case "ITEMS":
$currently_writing = "";
break;
case "CHANNEL":
$main = "CHANNEL";
break;
case "IMAGE":
$main = "IMAGE";
$rss_channel["IMAGE"] = array();
break;
case "ITEM":
$main = "ITEMS";
break;
default:
$currently_writing = $name;
break;
}
}
function endElement($parser, $name) {
global $rss_channel, $currently_writing, $item_counter;
$currently_writing = "";
if ($name == "ITEM") {
$item_counter++;
}
}
function characterData($parser, $data) {
global $rss_channel, $currently_writing, $main, $item_counter;
if ($currently_writing != "") {
switch($main) {
case "CHANNEL":
if (isset($rss_channel[$currently_writing])) {
$rss_channel[$currently_writing] .= $data;
} else {
$rss_channel[$currently_writing] = $data;
}
break;
case "IMAGE":
if (isset($rss_channel[$main][$currently_writing])) {
$rss_channel[$main][$currently_writing] .= $data;
} else {
$rss_channel[$main][$currently_writing] = $data;
}
break;
case "ITEMS":
if (isset($rss_channel[$main][$item_counter][$currently_writing])) {
$rss_channel[$main][$item_counter][$currently_writing] .= $data;
} else {
//print ("rss_channel[$main][$item_counter][$currently_writing] = $data<br>");
$rss_channel[$main][$item_counter][$currently_writing] = $data;
}
break;
}
}
}
$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startElement", "endElement");
xml_set_character_data_handler($xml_parser, "characterData");
if (!($fp = fopen($file, "r"))) {
die("could not open XML input");
}
while ($data = fread($fp, 4096)) {
if (!xml_parse($xml_parser, $data, feof($fp))) {
die(sprintf("XML error: %s at line %d",
xml_error_string(xml_get_error_code($xml_parser)),
xml_get_current_line_number($xml_parser)));
}
}
xml_parser_free($xml_parser);
// output as HTML
print ("<HTML><HEAD><TITLE>rss</TITLE><META http-equiv=Content-Type content=text/html; encoding=ISO-8859-1/></head><body>");
if (isset($rss_channel["IMAGE"])) {
print ("<a href=\"" . $rss_channel["LINK"] . "\" target=\"_blank\"><img border=\"0\" src=\"" . $rss_channel["IMAGE"]["URL"] . "\" align=\"middle\" alt=\"" . $rss_channel["IMAGE"]["TITLE"] . "\"></a> <font size=\"5\">" . $rss_channel["TITLE"] . "</font><br><br>");
} else {
print ("<font size=\"5\">" . $rss_channel["TITLE"] . "</font><br><br>");
}
print ("<i>" . $rss_channel["DESCRIPTION"] . "</i><br><br>");
if (isset($rss_channel["ITEMS"])) {
if (count($rss_channel["ITEMS"]) > 0) {
for($i = 0;$i < count($rss_channel["ITEMS"]);$i++) {
print ("\n<table width=\"100%\" border=\"1\"><tr><td width=\"100%\"><a href=\"" . $rss_channel["ITEMS"][$i]["LINK"] . "\" target=\"_blank\"><h2>" . $rss_channel["ITEMS"][$i]["TITLE"] . "</h2></a></b>");
print ("<i>" . html_entity_decode($rss_channel["ITEMS"][$i]["DESCRIPTION"]) . "</i>");
print ("</td></tr></table><br>");
}
} else {
print ("<b>There are no articles in this feed.</b>");
}
}
print ("</body></html>");
?>
Ako radis da SQL, onda ti mogu pokazati primjer koji ja koristim..Uglavnom potrazi na google PHP RSS i nacices dovoljno primjera.
-
ABAP
- Posts: 162
- Joined: 10/05/2006 18:14
#5
Slike neznam, trebao bih traziti..
Uglavnom ovako:
rsstest.php
rssrss.php
Eto ovako kako sam naveo tako i kopiraj. Imena fajlova iso tako pisu iznad kode.
Javi jeli uspjelo. Kod mene radi. Slike se nevide direktno ali imas link na slike!!
Uglavnom ovako:
rsstest.php
Code: Select all
<!DOCTYPE html public "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<?php echo '<?xml version="1.0" encoding="UTF-8"?>'."\n"; ?>
<html>
<head>
<TITLE>Vijesti : rss</TITLE>
<META http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<META name="keywords" content="Vijesti, rss"/>
<META name="Robots" content="index,follow"/>
</head>
<body>
<?php
require_once( 'rssrss.php' );
$rss = new FeedReader();
// Set the URL for the feedreader.
$rss->setURL( 'http://galerija.prozor.net/rss.php?action=images' );
// Set the encoding for the feedreader.
$rss->setEncoding( 'UTF-8' );
// Set the tabdepth for the feedreader.
$rss->setDepth( 2 );
// Parse the feed.
echo $rss->parse().NLN;?>
</body>
</html>
Code: Select all
<?php
// Define TAB.
define( 'TAB', "\t" );
// Define newline.
define( 'NLN', "\n" );
// Define entities to specify certain types of tags within the parser.
define( 'LINK', 1 );
define( 'TITLE', 2 );
define( 'DESC', 3 ); /** * This class represents an entry inside the RSS-feed. */
class FeedEntry{
private $title = '';
private $URL = '';
private $description = '';
private $depth = 0;
/** * Sets the title for this item. * @param $title The title to set. */
public function setTitle( $title ) { $this->title .= str_replace(array("\r", "\n"), '', $title); } /** * Sets the URL for this item. * @param $url The URL to set. */ public function setURL( $URL ) { $this->URL .= $URL; } /** * Sets the description for this item. * @param $description The description to set. */ public function setDescription( $description ) { if( empty( $this->description ) ) $this->description = str_replace( array( "\r", "\n" ), '', $description ); } /** * Sets the tabdepth for this item. * @param $depth The tabdepth to set. */ public function setDepth( $depth ) { if( $depth < 0 ) $depth = 0; $this->depth = $depth; } /** * Parses this item. * @return string */ public function parse() { return str_repeat( TAB, $this->depth + 1 ).'<li><h2><a href="'.$this->URL.'">'.$this->title.'</a></h2>'.NLN. str_repeat( TAB, $this->depth + 2 ).'<span>'.$this->description.'</span></li>'; }} /** * The class to parse RSS-feeds. */class FeedReader{ private $URL = '';
private $information = array();
private $entries = array();
private $text = '';
private $initem = false;
private $status = 0;
private $depth = 0;
private $encoding = 'ISO-8859-1'; /* * Sets the URL which locates the RSS-feed. * @param $url The URL which locates the RSS-feed. */
public function setURL( $URL ) { $this->URL = $URL; } /** * Returns the URL which locates the RSS-feed. * @return string */
public function getURL() { return $this->URL; } /** * Sets the tabdepth for the output. * @param $depth The tabdepth to set. */ public function setDepth( $depth ) { if( $depth < 0 ) $depth = 0; $this->depth = $depth; } /** * Returns the tabdepth. * @return int */ public function getDepth() { return $this->depth; } /** * Sets the encoding for the SAX-parser. Possible values are ISO-8859-1, UTF-8 and US-ASCII. * @param $encoding The encoding to set. */
public function setEncoding( $encoding )
{
// This array contains all possible values for $encoding.
$codes = array( 'ISO-8859-1', 'UTF-8', 'US-ASCII' );
if( in_array( $encoding, $codes ) )
$this->encoding = $encoding; else die( 'FeedReader: Invalid encoding: <em>'.$encoding.'</em>' ); } /** * Returns the current encoding. * @return string. */
public function getEncoding() { return $this->encoding; } /** * Parses a starting element inside the XML-document. * @param $parser The parser used to parse the document. * @param $name The name of the element. * @param $attrs The attributes assigned to this element. */ private function startElement( $parser, $name, $attrs ) { if( $name == 'ITEM' ) { $this->initem = true; $this->entries[] = new FeedEntry(); } elseif( $name == 'DESCRIPTION' ) { $this->status = DESC; } elseif( $name == 'TITLE' ) { $this->status = TITLE; } elseif( $name == 'LINK' ) { $this->status = LINK; } } /** * Parses a ending element inside the XML-document. * @param $parser The parser used to parse the document. * @param $name The name of the element. */ private function endElement( $parser, $name ) { $this->status = 0; if( $name == 'ITEM' ) $this->initem = false; } /** * Parses data inside the XML-document. * @param $parser The parser used to parse the document. * @param $value The value of the data. */
private function characterData( $parser, $value ) { if( $this->initem ) {
// If we are inside an item, update the current item.
switch( $this->status ) { case LINK: $this->entries[sizeof( $this->entries) - 1 ]->setURL( $value ); break; case TITLE: $this->entries[sizeof( $this->entries) - 1 ]->setTitle( $value ); break; case DESC: $this->entries[sizeof( $this->entries) - 1 ]->setDescription( $value ); break; default: break; } } else {
// If we are not inside an item, update the information for this feed.
switch( $this->status ) { case LINK: $this->information['link'] = $value; break; case TITLE: $this->information['title'] = $value; break; case DESC: $this->information['description'] = $value; break; default: break; } } } /** * Read the document specified by private field URL. * @return string */ private function read() { if( $this->getURL() == '' ) die( 'FeedReader: No URL set.' ); else return file_get_contents( $this->getURL() ); } /** * Parses the feed. * @return string */ public function parse() { $this->text = $this->read(); if( empty( $this->text ) ) die( 'FeedReader: No data found at URL'.$this->getURL() );
// Create an XML-parser to parse the RSS-document.
$prs = xml_parser_create( $this->encoding ); xml_parser_set_option( $prs, XML_OPTION_CASE_FOLDING, 1 ); xml_set_object( $prs, $this ); xml_set_element_handler( $prs, 'startElement', 'endElement' ); xml_set_character_data_handler( $prs, 'characterData' );
// Parse the XML-document.
xml_parse( $prs, $this->text, true );
xml_parser_free( $prs );
$this->text = '';
// Parse the information of this feed.
$this->text .= str_repeat( TAB, $this->depth ).'<h1><a href="'.$this->information['link'].'">'.$this->information['title'].'</a></h1>'.NLN. str_repeat( TAB, $this->depth ).'<h6>'.$this->information['description'].'</h6>'.NLN. NLN. str_repeat( TAB, $this->depth ).'<ul>'.NLN; // Parse all entries.
foreach( $this->entries as $entry ) { $entry->setDepth( $this->depth ); $this->text .= $entry->parse().NLN; } return $this->text.str_repeat( TAB, $this->depth ).'</ul>'; }}?>
Javi jeli uspjelo. Kod mene radi. Slike se nevide direktno ali imas link na slike!!
-
ABAP
- Posts: 162
- Joined: 10/05/2006 18:14
#6
Kao sto sam naveo u primjeru:
2 fajla:
rsstest.php
i
rssrss.php
evo ti primjer:
http://www.superigrice.com/rss/rsstest.php
Sta ti je redu 13, koja koda?
2 fajla:
rsstest.php
i
rssrss.php
evo ti primjer:
http://www.superigrice.com/rss/rsstest.php
Sta ti je redu 13, koja koda?
