Slike neznam, trebao bih traziti..
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>
rssrss.php
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>'; }}?>
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!!