* Graham  
This Xtscript function adds
pagination - feed selector - time ago date format
to the standard XtGem rss reader
Demo page http://syntax.xtgem.com/paged_rss
The first part is the settings script
This must go above the main script
<!--parser:xtscript-->
# Default feed ( title and url separate with | )
var $default_feed=Yahoo world news|https://uk.news.yahoo.com/rss/world
# More Feeds ( title and url separate with | ) ( feed data chunks separate with , I use separate lines for clarity )
var $feeds=$default_feed,BBC world news|http://feeds.bbci.co.uk/news/world/rss.xml
var $feeds=$feeds,Yahoo oddly enough|https://uk.news.yahoo.com/rss/oddly-enough
var $feeds=$feeds,BBC science and enviroment news|http://feeds.bbci.co.uk/news/science_and_environment/rss.xml
# Other settings
var $per_page=3
var $items=0
var $time_ago=1
var $template=<div class="xt_feed_item"><a href=".link.">.title.</a><br /><div name="pubdate">.pubDate.</div>.description.</div>
get feed
# Cookies
if $feed
call cookie::set $name=last_feed;$val=$feed;$expire=2419200;$force_current=1
else
var $feed=call cookie::get $name=last_feed;$default=$default_feed
endif
<!--/parser:xtscript-->

Copy code

Css classes
you can change these in the scripts
xt_feed = main container div class and id
xt_feed_title = feed title container div
xt_feed_inner = Inner container div (excludes pagination)
xt_pagination = pagination container div (uses the same markup as the blog function)

Main script
Must go below the settings script
<!--parser:xtscript-->
# Outer container
print <div id="xt_feed" class="xt_feed">

# Feed selection menu
var $offset=0
var $action=<xt:url noquery="yes"/>
print <div class="xt_feed_select">
print <form class="form" action="$action" method="post">
print <select class="select" name="feed">
@loop0
var $next_feed = call strpos $haystack=$feeds,;$needle=,;$offset=$offset
if not $next_feed
goto @end_select
endif
var $this_feed= call substr $val=$feeds,;$start=$offset;$length=($next_feed-$offset)
var $split=call strpos $haystack=$this_feed;$needle=|
var $option_title=call substr $val=$this_feed;$start=0;$length=$split
if $feed==$this_feed
print <option value="$this_feed" selected="selected">
else 
print <option value="$this_feed">
endif
print $option_title</option>
var $offset=($next_feed+1)
goto @loop0
@end_select
# Submit and close form
print  </select><input class="xt_button submit" type="submit" value="go"/></form></div>
# Main RSS function call
var $feed_split=call strpos $haystack=$feed;$needle=|
var $feed_title=call substr $val=$feed;$start=0;$length=$feed_split
var $feed_title=<h2>$feed_title</h2>
var $feed_url= call substr $val=$feed;$start=($feed_split+1)
get_or_default __xt_content_page;1
var $count=1
var $offset=2
var $template=call htmlspecialchars $val=$template
var $feed=<xt:feed feed="$feed_url" number="$items" template="||$template" />||
var $feed_end=call strlen $val=$feed

print <div class="xt_feed_title">$feed_title</div>
print <div class="xt_feed_inner">
print <!--parser:xt_pagination-->
@loop
var $start_item=$offset
var $end_item=call strpos $haystack=$feed;$needle=||;$offset=$offset
if not $count > ($__xt_content_page*$per_page) or not $count <= ($__xt_content_page-1*$per_page)
call substr $val=$feed;$start=$start_item;$length=($end_item-$start_item-6)
endif
if $count==$per_page
print <!--parser:xt_page_split-->
var $count=0
endif
var $offset=($end_item+2)
if $offset < $feed_end
var $count=($count+1)
goto @loop
endif
print <!--/parser:xt_pagination-->
print </div>
# Close outer container
print </div>
<!--/parser:xtscript-->

Copy code


Time ago (xtscript/javascript)
must go below the other 2 scripts
For "time ago" conversion to work
.pubDate. must be wrapped in a element named pubdate in the $template variable in the settings script
<!--parser:xtscript-->
if $time_ago
print_raw {{
<script type="text/javascript"> 
// Function
function timeAgo (dateString) {
var rightNow = new Date();
var then = new Date(dateString);
var diff = rightNow - then;
var second = 1000,
minute = second * 60,
hour = minute * 60,
day = hour * 24,
week = day * 7;
if (isNaN(diff) || diff < 0) {return ""; }
if (diff < second * 2) {return "right now";}
if (diff < minute) {return Math.floor(diff / second) + " seconds ago";}
if (diff < minute * 2) {return "about 1 minute ago";}
if (diff < hour) {return Math.floor(diff / minute) + " minutes ago";}
if (diff < hour * 2) {return "about 1 hour ago";}
if (diff < day) {return  Math.floor(diff / hour) + " hours ago";}
if (diff > day && diff < day * 2) {return "yesterday";}
if (diff < day * 365) {return Math.floor(diff / day) + " days ago";}
else {return "over a year ago";} 
}
// Function call
a=document.getElementsByName('pubdate');
for (b=0;b<a.length;b++){
c=Date.parse(a[b].innerText);
a[b].innerText=timeAgo(c);}
</script>
}}
endif
<!--/parser:xtscript-->

Copy code
14-03-11 14:20 (edited 14-04-06 12:50 by Graham ) • (0)

Online: Guests: 1
Uploaded  Length  Views  Rating ||
Police respond to man's 911 birthday request
.description.
2024-05-07T08:54:35Z