Please login or register.

Login with username, password and session length
Advanced search  

News:

You need/want an older version of sNews ? Download an older/unsupported version here.

Author Topic: [ADDON] Presenting External feeds on your site (sNews 1.4)  (Read 5832 times)

Patric Ahlqvist

  • Nobodys perfect, but Im pretty effing close
  • ULTIMATE member
  • ******
  • Karma: 65
  • Posts: 4867
  • I'm a self-made man and worships my creator.
    • p-ahlqvist.com
[ADDON] Presenting External feeds on your site (sNews 1.4)
« on: August 15, 2006, 06:52:23 pm »

Ok, So I got ahold of this modification from Luka, and his CSSheaven.com.

In order to be able to present other site's feeds on your site, just copy this and upload it to your server (this particular one is called grabfeed.php, but you can call it whatever the "warm place" you want, as long as including it right ;)):
Code: [Select]
<?php

/*************************************

 GRABFEED v1.0
 project: CSS HEAVEN (cssheaven.com)
 usage: 
 Paste <? include ("grabfeed.php"); ?>

 where you want feeds to display

*************************************/


/* listing fresh feeds */
$rss = array(
"http://www.solucija.com/rss.xml",
"http://andreasviklund.com/feed/",
"http://www.cssbeauty.com/rss/news/", "http://www.cssplay.co.uk/feed.xml",
"http://p-ahlqvist.com/rss.xml");
/*************************************/


foreach ($rss as $file) {
set_time_limit(0);
$rss_channel = array();
$currently_writing = "";
$main = "";
$item_counter = 0;

$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 HTML
 
if (isset($rss_channel["ITEMS"])) {
if (count($rss_channel["ITEMS"]) > 0) {
for($i = 0;$i < 1;$i++) {
if (isset($rss_channel["ITEMS"][$i]["LINK"])) {
echo "<p><a title='Read Full Article' href=\"" . $rss_channel["ITEMS"][$i]["LINK"] . "\">" . $rss_channel["ITEMS"][$i]["TITLE"] . "</a>
";
} else {
echo "<p>" .$rss_channel["ITEMS"][$i]["TITLE"]. "
";
}
echo substr($rss_channel["ITEMS"][$i]["DESCRIPTION"], 0, 67) . "...</p>"; }
} else {
echo "<b>There are no articles in this feed.</b>";
}
}}

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 {
$rss_channel[$main][$item_counter][$currently_writing] = $data;
}
break;
}
}
}?>
As it says in the beginning of the script, place this snippet on your site in order to show the feeds:
Code: [Select]
<? include ("grabfeed.php"); ?>And change the path if you placed the file somewhere else. Now all you have to do is to manually change (if you want) the feeds and viola, there it is... A demo would ie be this: http://p-ahlqvist.com (check below the center function, sort of the last article)

Patric.
« Last Edit: January 04, 2009, 03:31:27 am by philmoz »
Logged
"It's only dead fish that goes with the flow... "
Updated

bryn

  • Hero Member
  • *****
  • Karma: 2
  • Posts: 934
    • http://www.cssugly.com
[ADDON] Presenting External feeds on your site (sNews 1.4)
« Reply #1 on: August 15, 2006, 07:38:30 pm »

excellent Patric, and Luka of course! ;)

might I suggest that this be adapted so that those rss links open a new window rather than replace..

..doesn't hurt to keep your site visitors around a wee bit longer eh? :D
Logged
Over 1,000 posts of joy, sNews is not only brilliant, but fun too! thanks guys :D

Fred K

  • Still trying to learn stuff
  • ULTIMATE member
  • ******
  • Karma: 130
  • Posts: 2728
    • Personal
[ADDON] Presenting External feeds on your site (sNews 1.4)
« Reply #2 on: August 15, 2006, 07:40:08 pm »

Nice one. I can see myself using it. Thanks Patric-Luka!
Logged

Patric Ahlqvist

  • Nobodys perfect, but Im pretty effing close
  • ULTIMATE member
  • ******
  • Karma: 65
  • Posts: 4867
  • I'm a self-made man and worships my creator.
    • p-ahlqvist.com
[ADDON] Presenting External feeds on your site (sNews 1.4)
« Reply #3 on: August 15, 2006, 08:21:56 pm »

Quote from: bryn
excellent Patric, and Luka of course! ;)

might I suggest that this be adapted so that those rss links open a new window rather than replace..

..doesn't hurt to keep your site visitors around a wee bit longer eh? :D
Well it just might be a way... But I'm in over my head ;)... I'm just the ideea popper, you know, the coding has to be done by someone else...

But if we could implement this line to the code:
Code: [Select]
<script type="text/javascript">external_link("http://www.url.com","linkname",1);</script>Perhaps somewhere around here:
Code: [Select]
echo "<p><a title='Read Full Article' href=\"" . $rss_channel["ITEMS"][$i]["LINK"] . "\">" . $rss_channel["ITEMS"][$i]["TITLE"] . "</a>
";
And then use this piece of javascript that I stole from Brauck (where did you get this, I want this in english ;)):
Code: [Select]
var _root='http://www.ulr.com/';  //don't forget the trailing slash
var _imgpath = _root + 'images/'; //link to an image representing the popup named "new_window.gif"

//*********************************** used in contactgeg.php and printme.php **************************
function afdrukken() {
 document.write("<a href=\"javascript:window.print()\">Afdrukken</a>");
}

function sluiten() {
  document.write("<a href=\"javascript:window.close()\">Sluit dit venter</a>");
}

function printContactgegevens() {
 popup = '<a href="javascript: NewWindow(\'contactgeg.php\',\'Contactgegevens\',400,240,\'no\')"'
       + 'onMouseOut="MM_swapImgRestore()"'
       + 'onMouseOver="MM_swapImage(\'afdrukken\',\'\',\''
       + _imgpath
       + 'bt_print_over.gif\',1)">'
       + '<img src="'
       + _imgpath
       + 'bt_print.gif" width="78" height="16" border="0" alt="Printen" name="afdrukken"></a>';
 document.write(popup);
}
/***********************************************************************************************/
function backButton() {
document.write("<a href='javascript: history.back()' onMouseOut=\"MM_swapImgRestore()\" onMouseOver=\"MM_swapImage(\'back\',\'\',\'" + _imgpath + "bt_back_over.gif\',1)\"><img src=\" " + _imgpath + "bt_back.gif\" alt=\"\" name=\"back\" width=\"54\" height=\"16\" border=\"0\"></a>");
}

function printButton() {
document.write("<a href='javascript: window.print()' onMouseOut=\"MM_swapImgRestore()\" onMouseOver=\"MM_swapImage(\'print\',\'\',\'" + _imgpath + "bt_print_over.gif\',1)\"><img src=\" " + _imgpath + "bt_print.gif\" alt=\"\" name=\"print\" width=\"78\" height=\"16\" border=\"0\"></a>");
}

function goBack() {
document.write("<a href='javascript: history.back()'>Terug</a>");
}

function external_link(url,linktxt,pic) {

    var linksetting = '<a href=\"'+url+'\"';    
   linksetting +=' class=\"external\"';
linksetting +=' onclick=\"n_window(this.href);return false\" target=\"_blank\">';
linksetting +=linktxt;
linksetting +='</a>';
if(pic==0) {
          document.write(linksetting); }
else {
 linksetting +='<img src=\"' + _imgpath + 'new_window.gif\" alt=\"New window\">';
 document.write(linksetting);
}
}
//*********************************** block multiple form submissions *****************************
// recommend.php

var formerrormsg="U heeft geprobeerd dit formulier meerdere keren achter elkaar te verzenden.\n Herlaad de pagina indien u een tweede formulier wilt verzenden."

function checksubmit(submitbtn){
submitbtn.form.submit()
checksubmit=blocksubmit
return false
}

function blocksubmit(){
if (typeof formerrormsg!="undefined")
alert(formerrormsg)
return false
}
//*********************************** Pop-up Center ***********************************************
//Deze functie wordt gebruikt in contact.html

function NewWindow(page,name,w,h,scroll){
  var win= null;
  var winl = (screen.width-w)/2;
  var wint = (screen.height-h)/2;
  var settings  ='height='+h+',';
      settings +='width='+w+',';
      settings +='top='+wint+',';
      settings +='left='+winl+',';
      settings +='scrollbars='+scroll+',';
      settings +='resizable=no'+',';
      settings +='status=no';  
  win=window.open(page,name,settings);
  if(parseInt(navigator.appVersion) >= 4){win.window.focus();}
}
//************************************* full window ***********************************************
//Deze functie wordt gebruikt
function fullWindow(url) {
    var str = "left=0,screenX=0,top=0,screenY=0";
    if (window.screen) {
      var ah = screen.availHeight - 30;
      var aw = screen.availWidth - 10;
      str += ",height=" + ah;
      str += ",innerHeight=" + ah;
      str += ",width=" + aw;
      str += ",innerWidth=" + aw;
 str += ",directories=no";  
 str += ",location=no";
 str += ",menubar=yes";  
 str += ",resizable=yes";
 str += ",scrollbars=yes";
 str += ",status=no";  
 str += ",toolbar=yes";
    }
    win=window.open(url, "w", str);
}
//*********************************** links in new window ****************************************
//Deze functie wordt gebruikt in banners.php - footer.php
//
function n_window(theurl)
{
// set width and height
var the_width=760;
var the_height=550;
// set window position
var from_top=20;
var from_left=20;
// set other attributes
var has_toolbar='yes';
var has_location='yes';
var has_directories='yes';
var has_status='yes';
var has_menubar='yes';
var has_scrollbars='yes';
var is_resizable='yes';
// atrributes put together
var the_atts='width='+the_width+',height='+the_height+',top='+from_top+',screenY='+from_top+',left='+from_left+',screenX='+from_left;
the_atts+=',toolbar='+has_toolbar+',location='+has_location+',directories='+has_directories+',status='+has_status;
the_atts+=',menubar='+has_menubar+',scrollbars='+has_scrollbars+',resizable='+is_resizable;
// open the window
window.open(theurl,'',the_atts);
}
//************************************* roll-overs *******************************************
// Wordt gebruikt in index2.php
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

/***********************************************************************************************/

function bigFont() {
document.write("<a href=\"#\" onClick=\"changeStyle(\'bigfont\');\" onMouseOver=\"return overlib(\' Groot lettertype \', WIDTH, 100);\" onMouseOut=\"return nd();\"><img src=\"http://pc02/gpj/img/a_plus.gif\" alt=\"\" width=\"25\" height=\"25\" border=\"0\" /></a>");
}

function normalFont() {
document.write("<a href=\"#\" onClick=\"changeStyle(\'default\');\" onMouseOver=\"return overlib(\' Normaal lettertype \', WIDTH, 110);\" onMouseOut=\"return nd();\"><img src=\"http://pc02/gpj/img/a_min.gif\" alt=\"\" width=\"25\" height=\"25\" border=\"0\" /></a>");
}
/***********************************************************************************************
                             Script to swap between stylesheets
    Written by Mark Wilton-Jones, 05/12/2002. v2.2 updated 29/04/2004 for Konqeror XHTML fix
************************************************************************************************

Please see http://www.howtocreate.co.uk/jslibs/ for details and a demo of this script
Please see http://www.howtocreate.co.uk/jslibs/termsOfUse.html for terms of use
*/

function getAllSheets() {
if( !window.ScriptEngine && navigator.__ice_version ) { return document.styleSheets; }
if( document.getElementsByTagName ) { var Lt = document.getElementsByTagName('link'), St = document.getElementsByTagName('style');
} else if( document.styleSheets && document.all ) { var Lt = document.all.tags('LINK'), St = document.all.tags('STYLE');
} else { return []; } for( var x = 0, os = []; Lt[x]; x++ ) {
var rel = Lt[x].rel ? Lt[x].rel : Lt[x].getAttribute ? Lt[x].getAttribute('rel') : '';
if( typeof( rel ) == 'string' && rel.toLowerCase().indexOf('style') + 1 ) { os[os.length] = Lt[x]; }
} for( var x = 0; St[x]; x++ ) { os[os.length] = St[x]; } return os;
}
function changeStyle() {
window.userHasChosen = window.MWJss;
for( var x = 0, ss = getAllSheets(); ss[x]; x++ ) {
if( ss[x].title ) { ss[x].disabled = true; }
for( var y = 0; y < arguments.length; y++ ) { if( ss[x].title == arguments[y] ) { ss[x].disabled = false; } }
} }
function rememberStyle( cookieName, cookieLife ) {
for( var viewUsed = false, ss = getAllSheets(), x = 0; window.MWJss && ss[x]; x++ ) { if( ss[x].disabled != MWJss[x] ) { viewUsed = true; break; } }
if( !window.userHasChosen && !viewUsed ) { return; }
for( var x = 0, outLine = '', doneYet = []; ss[x]; x++ ) {
if( ss[x].title && ss[x].disabled == false && !doneYet[ss[x].title] ) { doneYet[ss[x].title] = true; outLine += ( outLine ? ' MWJ ' : '' ) + escape( ss[x].title ); } }
if( ss.length ) { document.cookie = escape( cookieName ) + '=' + escape( outLine ) + ( cookieLife ? ';expires=' + new Date( ( new Date() ).getTime() + ( cookieLife * 86400000 ) ).toGMTString() : '' ) + ';path=/'; }
}
function useStyleAgain( cookieName ) {
for( var x = 0; x < document.cookie.split( "; " ).length; x++ ) {
var oneCookie = document.cookie.split( "; " )[x].split( "=" );
if( oneCookie[0] == escape( cookieName ) ) {
var styleStrings = unescape( oneCookie[1] ).split( " MWJ " );
for( var y = 0, funcStr = ''; styleStrings[y]; y++ ) { funcStr += ( y ? ',' : '' ) + 'unescape( styleStrings[' + y + '] )'; }
eval( 'changeStyle(' + funcStr + ');' ); break;
} } window.MWJss = []; for( var ss = getAllSheets(), x = 0; ss[x]; x++ ) { MWJss[x] = ss[x].disabled; }
}

/***********************************************************************************************/
function popUp(url, br, ho){
  var w = br;
  var h = ho;
  var scroll = 1;
  var win= null;
  var winl = (screen.width-w)/2;
  var wint = (screen.height-h)/2;
  var settings  ='height='+h+',';
      settings +='width='+w+',';
      settings +='top='+wint+',';
      settings +='left='+winl+',';
      settings +='scrollbars='+scroll+',';
      settings +='resizable=no'+',';
      settings +='status=no';
  win=window.open(url,name,settings);
  if(parseInt(navigator.appVersion) >= 4){win.window.focus();}

}
The first piece of code way up in this post uses this javascript to open a new window pretty neat... I don't know if it's possible. It works though, go check http://www.brauck.nl and that little "doubl window" icon beside a link...

Patric.
« Last Edit: January 04, 2009, 03:31:48 am by philmoz »
Logged
"It's only dead fish that goes with the flow... "
Updated

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6020
  • Semantically Challenged
    • snews.ca
[ADDON] Presenting External feeds on your site (sNews 1.4)
« Reply #4 on: August 15, 2006, 08:46:18 pm »

Here's another javascript (in english) that opens new windows on clicking URL links - http://www.web-source.net/javascript_open_windows.htm.
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

Luka

  • Administrator
  • ULTIMATE member
  • ******
  • Karma: 36
  • Posts: 1717
    • http://www.snewscms.com
[ADDON] Presenting External feeds on your site (sNews 1.4)
« Reply #5 on: August 15, 2006, 08:53:54 pm »

To open a new window/tab you might want to use target=_blank but that'll cause your code not to validate unless you use transitional doctype.

Also, I wouldn't suggest doing that cause the surfer knows why he clicked and where. If he wanted to open a new window, he would have just clicked his scroller and opened a new tab in Firefox. Give the surfer a choice :) Just my 2 eurocents...
Logged

bryn

  • Hero Member
  • *****
  • Karma: 2
  • Posts: 934
    • http://www.cssugly.com
[ADDON] Presenting External feeds on your site (sNews 1.4)
« Reply #6 on: August 15, 2006, 09:07:45 pm »

mmm..I just had a thought in my head to open RSS feeds in a 'Thickbox' type way using miniscule Ajax..but as far as I know [not tested yet], not possible to open an external url

but your right of course Luka..we must attempt to validate at least :P though opening in a new tab is only applicable to FF or the like users, what about untabbed browsers like IE?

just a thought ;)
Logged
Over 1,000 posts of joy, sNews is not only brilliant, but fun too! thanks guys :D

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6020
  • Semantically Challenged
    • snews.ca
[ADDON] Presenting External feeds on your site (sNews 1.4)
« Reply #7 on: August 15, 2006, 09:35:49 pm »

OK - here is another approach - giving the viewer a choice of whether he/she wants to open a new window OR stay in the same window before clicking the link. This comes from http://javascript.internet.com/navigation/open-links-option.html.

Paste the following into a new blank file and save it as openLinks.js  in the same folder as the file using it (in the case of index.php... in the root directory).
Code: [Select]
function openLink() {
  for (var i=0; i<=(document.links.length-1); i++) {
    if (document.form1.tick.checked == true) {document.links[i].target = "_blank"}
    if (document.form1.tick.checked == false) {document.links[i].target = "_self"}
  }
}
In the head part of index.php (under the stylesheet links and title function statement) paste:
Code: [Select]
<script type="text/javascript" src="openLinks.js"></script>In the body of index.php, where you want the links displayed, paste:
Code: [Select]
<form name="form1">
<label for="1"><input id="1" type="checkbox" name="tick"> Open link in new window.</label>
</form>

<a href="http://www.solucija.com/rss.xml" onclick="openLink()">Solucija RSS</a>

<a href="http://andreasviklund.com/feed/" onclick="openLink()">A-Viklund RSS</a>

<a href="http://www.cssbeauty.com/rss/news/" onclick="openLink()">CSSBeauty RSS</a>

<a href="http://www.cssplay.co.uk/feed.xml" onclick="openLink()">CSSPlay RSS</a>

<a href="http://p-ahlqvist.com/rss.xml" onclick="openLink()">Patric's RSS</a>
Only one question since I have not done anything with RSS before... are these links supposed to open actual web pages or just content wrapped in a host of HTML tags on a plain, white packground?
« Last Edit: January 04, 2009, 03:33:00 am by philmoz »
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6020
  • Semantically Challenged
    • snews.ca
[ADDON] Presenting External feeds on your site (sNews 1.4)
« Reply #8 on: August 15, 2006, 10:27:33 pm »

Aaaannnnd... here is the simplest - one-liner way to open your RSS links in new windows WITHOUT using target="_blank". I had used this some time ago for links to external pages on other sites and it slipped my mind. Just wrap your URLs in this script  - nothing else needed - and the pages will open in new windows.

Code: [Select]
<a target="newwindow" href="http://www.yoursite.com/newpage.htm">link-text-here</a>
« Last Edit: January 04, 2009, 03:33:43 am by philmoz »
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

Fred K

  • Still trying to learn stuff
  • ULTIMATE member
  • ******
  • Karma: 130
  • Posts: 2728
    • Personal
[ADDON] Presenting External feeds on your site (sNews 1.4)
« Reply #9 on: August 15, 2006, 10:59:54 pm »

I'm with Luka on this, as WCAG guidelines convey the message that the user should be in control, regardless of how icky that feels for us designers.

However, I do from time to time employ a nice little javascript for external links. There are enough solutions above though so I'll only post it upon request.
Logged

yoyo

  • Newbie
  • *
  • Karma: 0
  • Posts: 5
[ADDON] Presenting External feeds on your site (sNews 1.4)
« Reply #10 on: September 29, 2006, 06:22:13 pm »

How can i include more than one article from one feed?
And how can i display the feeds only in my home page?
Logged