Category: 3rd Party Integration
Submitted: 04 July 2009
Last Updated: 04 July 2009
File Type: php
Screenshot: Not Available
File Size: 4.9K ZIP-File (Attached File at the bottom)
Download also at: http://www.pieces-of...m/RSSparser.zip
See also at: http://www.etomite.c...ds&showfile=303
O.K. here it is. I hope, i made no mistakes in this posting.
I've written a set of snippets for RSS-Feeds, which consists of two parts: a RSSparserCall and a RSSparserShow-Snippet.
The kernel of the snippets are basing on a script from Christian Jörgensen, http://www.technobabble.dk/.
At first i adapted the script to Etomite for my own use. On inquiry i got the permission from Christian Jörgensen, to publish it also in Etomite. Many thanks Christian.
Now the speciality of the snippets are, to show a list of Feeds in a select-form via [!RSSparserCall!] and then to open the selected feed in the document, which contains the [!RSSparserShow!] snippet call.
The snippets are tested and running with Etomite Version 1.1.1 Prelude.
You can see the scripts running at http://www.pieces-of-poetry.com/ . See at the left side in the index and take a look at the nifty select box.
I wish you much fun with these snippets.
[[RSSparserCall]]
// Snippet Name: RSSparserCall
// Snippet Description:
// RSSparserCall snippet for use with RSSparserShow.
// RSSparserCall script will parse a selected RSS/XML file that comes from a URL feed.
// Then Output will be generated by the snippet RSSparserShow in a list, which is coded in UTF-8.
// Images, Listings or Links will also be shown in the descriptions.
//
// Revision: 1.00
// Running with: Etomite Version 1.1.1 Prelude
// Written by Liv Christiane Göhner,
// http://www.pieces-of-poetry.com/
// mailto: "mail at gobeg dot de"
// Kernel is basing upon a script from Christian Jørgensen, http://www.technobabble.dk/, mailto: "mail at razor dot dk"
// This snippet is published also with the friendly permission of Christian Jørgensen (Joergensen),
// http://www.technobabble.dk/,
// mailto: "mail at razor dot dk"
//
// Use: Place [!RSSparserCall?resultsid=###!] snippet call directly in the template at that place, you wish,
// where ### is the document id of the page, which contains the [!RSSparserShow!] snippet call.
// e.g. [!RSSparserCall!] (then DefaultPage is used with the id, named in line 64 )
// [!RSSparserCall?resultsid=5!] (then page with id=5 is used)
// e.g. with a Div-Layer:
// <div id="indexBox" class="backgroundBox" title="Index">
// <h2>Index</h2>
// [!ListMenu!]
// <h3>The latest news</h3>
// [!RSSparserCall!]
// </div>
//
// Remember: You have to put in the Snippet-Call [!RSSparserShow!] on the DefaultPage or page with id=###
//
// Prepare your list of RSS-Feeds in that way:
// "URL_1" => "Comment_1",
// "URL_2" => "Comment_2",
// e.g.
// "http://www.tagesschau.de/newsticker.rdf" => "Tagesschau",
// "http://www.heute.de/ZDFheute/infoservices/rss-feed/" => "ZDFheute",
// "http://news.bbc.co.uk/rss/newsonline_uk_edition/world/americas/rss091.xml" => "BBC Americas",
// and so on ...
//
// Then copy that list into the "DataArray: RSS-Feeds and Comments"-field
// below the comment in line 72 up to the "End of the list of RSS-Feeds" .
//
// Feeds can be found e.g.
// in German on http://www.rss-verzeichnis.de/
// in English on http://www.rssdirectory.com/
// http://www.webdevtips.co.uk/webdevtips/resources/rssdir.php
// and so on ...
//
//
// The output can be formatted via CSS:
// form: id="rssparserform"
// label: id="rss_label"
// input: id="rssparserbutton"
//
// Button-Text can be changed in line 63
// Remember: ID of the DefaultPage can be changed in line 64
//
// Don't remove original credits and comments above!
//
// **************************************************************************************************************************
//
$submit = "Go"; // Submit button text: change it as you wish
$resultsDefault = "3"; // Document id to use if $resultsid not sent: change it as you wish
//
// ******** DataArray: RSS-Feeds and Comments *******************************************************************************
// This is the dataarray containing the URLs and Names of the feeds to fetch. The URL goes as key.
//
$GLOBALS['backends'] = array(
//
// Beginning of the list of RSS-Feeds (Examples)
//
"http://www.tagesschau.de/newsticker.rdf" => "Tagesschau",
"http://www.heute.de/ZDFheute/infoservices/rss-feed/" => "ZDFheute",
"http://www.tomshardware.com/de/feeds/rss2/tom-s-hardware-de,12-2.xml" => "THG-Artikel",
//
// End of the list of RSS-Feeds
//
// **************************************************************************************************************************
//
//
// Don't change code below!
//
);
/*
*Initialization
*/
$resultsid = isset($resultsid) ? $resultsid : $resultsDefault;
$output = "";
/*
* Functions
*/
function select_box($array, $selected, $name) {
// This is a nifty selectbox-function <img src='http://www.etomite.com/public/style_emoticons/<#EMO_DIR#>/smile.gif' class='bbc_emoticon' alt=':)' />
$out = "n<label id='rss_label' for="$name">RSS-Feed:</label>n<select id="$name" name="$name">n";
foreach ($array as $key => $value) $out .= sprintf("<option value="$key"%s>$value</option>n", $key == $selected ? ' selected' : '');
$out .= "</select>n";
return $out;
}
/*
* The form containing the selectbox
*/
$output = sprintf('<form id="rssparserform" action="[~'.$resultsid.'~]" method="post">');
$output .= select_box($GLOBALS['backends'], $GLOBALS['backend'], "backend");
$output .= sprintf('<input id="rssparserbutton" type="submit" name="sub" class="button" value="'.$submit.'" />');
$output .= sprintf("n");
$output .= sprintf('</form>');
return $output; // Don't remove
[[RSSparserShow]]
// Snippet Name: RSSparserShow
// Snippet Description:
// RSSparserShow snippet for use with RSSparserCall.
// RSSparserCall script will parse a selected RSS/XML file that comes from a URL feed.
// Then Output will be generated by the snippet RSSparserShow in a list, which is coded in UTF-8.
// If no Feed is selected, Feed will be chosen randomly.
//
// Revision: 1.00
// Running with: Etomite Version 1.1.1 Prelude
// Written by Liv Christiane Göhner,
// http://www.pieces-of-poetry.com/
// mailto: "mail at gobeg dot de"
// Kernel is basing upon a script from Christian Jørgensen, http://www.technobabble.dk/, mailto: "mail at razor dot dk"
// This snippet is published also with the friendly permission of Christian Jørgensen (Joergensen),
// http://www.technobabble.dk/,
// mailto: "mail at razor dot dk"
//
// Put [!RSSparserShow!] on the (content-)page, where you want to show the RSS-Feeds.
// Call the parser by using [!RSSparserCall?resultsid=###!] , where ### is the id of the( content-)page.
//
// The output can be formatted via CSS:
// H3: class='rss_source' (Headline, Source of the Feed)
// fieldset: class='rss_fieldset'
// legend: class='rss_legend'
// a: class='rss_a' (Link to the News-Text)
// p: class='rss_p' (News-text)
//
// Don't remove original credits and comments above!
//
// **************************************************************************************************************************
//
$source = "Source: "; // Heading: change it as you wish
//
// **************************************************************************************************************************
//
// Don't change code below!
//
/*
* Functions
*/
function startElement($parser, $tagName, $attrs) {
// The function used when an element is encountered
global $insideitem, $tag;
if ($insideitem) {
$tag = $tagName;
} elseif ($tagName == "ITEM") {
$insideitem = true;
}
}
function characterData($parser, $data) {
// The function used to parse all other data than tags
global $insideitem, $tag, $title, $description, $link, $pubDate;
if ($insideitem) {
switch ($tag) {
case "TITLE":
$title .= $data;
break;
case "DESCRIPTION":
$description .= $data;
break;
case "LINK":
$link .= $data;
break;
case "PUBDATE":
$pubDate .= $data;
break;
}
}
}
function endElement($parser, $tagName) {
// This function is used when an end-tag is encountered.
global $insideitem, $tag, $title, $description, $link, $pubDate;
if ($tagName == "ITEM") {
$link = trim($link);
$title = htmlspecialchars(trim($title));
$pubDate = htmlspecialchars(trim($pubDate));
$category = htmlspecialchars(trim($category));
$description = htmlspecialchars_decode(htmlspecialchars(trim($description)));
$GLOBALS['output'] .= "<fieldset class='rss_fieldset'>n<legend class='rss_legend'>n";
$GLOBALS['output'] .= "<a class='rss_a' href=".$link." target='NewsWindow'>".$title."</a>n</legend>n";
$GLOBALS['output'] .= "<p class='rss_p'>".$description."</p>n";
$GLOBALS['output'] .= "</fieldset>n";
$title = $description = $link = $insideitem = $pubDate = false;
}
}
if (!$GLOBALS['backend']) {
// If no backend is chosen, chose a random
srand((float) microtime() * 10000000);
$GLOBALS['backend'] = array_rand($GLOBALS['backends']);
}
$GLOBALS['output'] = "<h3 class='rss_source'>".$source.$GLOBALS['backends'][$GLOBALS['backend']]."</h3>n";
// Some vars used later on
$insideitem = false;
$tag = "";
$title = "";
$description = "";
$link = "";
$pubDate = "";
// Now to the parsing itself. Starts by creating it:
$xml_parser = xml_parser_create();
// Then setup the handlers:
xml_set_element_handler($xml_parser, "startElement", "endElement");
xml_set_character_data_handler($xml_parser, "characterData");
// Open the actual datafile:
$fp = fopen($GLOBALS['backend'], r);
// Run through it line by line and parse:
while ($data = fread($fp, 4096)) {
xml_parse($xml_parser, $data, feof($fp))
or die(sprintf("XML error: %s at line %d",
xml_error_string(xml_get_error_code($xml_parser)),
xml_get_current_line_number($xml_parser)));
}
// Close the datafile
fclose($fp);
// Free any memmory used
xml_parser_free($xml_parser);
return $GLOBALS['output'];
{{RSSparser.css}}
/*
****** RSSparser.css ***************************************************
****** Chunk for RSSparserCall and RSSparserShow ***********************
****** written by Liv Christiane Göhner ********************************
****** Change it for your own use. *************************************
************************************************************************
Informations:
<Form id="rssparserform"> (Nifty Selectbox)
<Label id="rss_label" > (Label for the Selectbox)
<input id="rssparserbutton">(Button of the Selectbox)
<h3 class='rss_source'> (Source of the RSS-Feed)
<fieldset class='rss_fieldset'>(Fieldset)
<legend class='rss_legend'> (Legend) ......
<a class='rss_a'> (Link corresponding to the News-Text)
<p class='rss_p'> (News-Text)
************************************************************************
*/
#rssparserform {
background: transparent;
border: 0px;
margin-left: 20px;
margin-top: -14px;
padding: 0;
}
#rss_label {
visibility:hidden;
}
#rssparserbutton{
font-size: 13px;
font-weight: bold;
float: none;
width: auto;
}
.rss_source {
font-size: 18px;
color: #0000E6;
}
.rss_fieldset {
background-color: transparent;
border: 1px solid #0000FF;
margin-top: 10px;
margin-bottom: 10px;
}
.rss_legend {
font-size: 13px;
}
.rss_a {
text-decoration:none;
}
.rss_p {
font-size: 12px;
color: #000066;
}
ReadMe.txt
This zip-archive contains four files:
ReadMe.txt
RSSParserCall.php
RSSParserShow.php
RSSParser.css
To install code in Etomite, please follow these steps:
1. Open a new snipppet and call it RSSparserCall
2. Put in the code according to RSSparserCall.php-file
3. Also have a look at the description in the head-section of the snippet
4. After preparing with your data (DefaultPage-id ...), save it and put snippet call [!RSSparserCall!] in your template.
5. Open a new snipppet and call it RSSparserShow
6. Put in the code according to RSSparserShow.php-file
7. Also have a look at the description in the head-section of the snippet
8. After preparing with your data, save it and e.g. put snippet call [!RSSparserShow!] in your DefaultPage.
9. Open a new chunk and call it RSSparser.css
10.Put in the style according to RSSparser.css-file
11.Change style as you wish and save it
12.Call the Chunk with your Styles "RSSparser.css" in the head-section of your Template with
<style type="text/css" media="screen">
<!--
{{RSSparser.css}}
-->
</style>
Attached Files
Edited by Christiane, 04 July 2009 - 04:08 PM.











