website rev 808

Improbe get_feed function
author Christophe Lincoln <pankso@slitaz.org>
date Wed Mar 30 20:31:49 2011 +0200 (2011-03-30)
parents c750cc8467b8
children 06cbe83c458a
files en/index.php en/packages/index.php fr/index.php index.php libs/get-feed.php libs/get-feeds.php libs/get-feeds.sh libs/get-latest.sh
line diff
     1.1 --- a/en/index.php	Wed Mar 30 18:37:02 2011 +0200
     1.2 +++ b/en/index.php	Wed Mar 30 20:31:49 2011 +0200
     1.3 @@ -180,7 +180,7 @@
     1.4  
     1.5  <h2>Project Activity</h2>
     1.6  <?php
     1.7 -	require_once("../libs/get-feed.php");
     1.8 +	require_once("../libs/get-feeds.php");
     1.9  ?>
    1.10  
    1.11  <div class="activity">
    1.12 @@ -188,7 +188,7 @@
    1.13  		<a href="http://scn.slitaz.org/activity/"><img 
    1.14  			src="../images/users.png" alt="users.png" /></a>
    1.15  		Community activity
    1.16 -		<?php get_rss_feed("/var/cache/slitaz/website/scn.xml"); ?>
    1.17 +		<?php get_feed("scn.xml"); ?>
    1.18  	</div>
    1.19  	<p class="activity_more">
    1.20  		<a href="http://scn.slitaz.org/activity/">More activity</a>
    1.21 @@ -200,7 +200,7 @@
    1.22  		<a href="http://hg.slitaz.org/">
    1.23  			<img src="../images/development.png" alt="development.png" /></a>
    1.24  		Latest commits in wok
    1.25 -		<?php get_rss_feed("/var/cache/slitaz/website/wok.xml"); ?>
    1.26 +		<?php get_feed("wok.xml"); ?>
    1.27  	</div>
    1.28  	<p class="activity_more">
    1.29  		<a href="http://hg.slitaz.org/">More commits</a>
     2.1 --- a/en/packages/index.php	Wed Mar 30 18:37:02 2011 +0200
     2.2 +++ b/en/packages/index.php	Wed Mar 30 20:31:49 2011 +0200
     2.3 @@ -119,14 +119,14 @@
     2.4  
     2.5  <h2>Activity</h2>
     2.6  
     2.7 -<?php require_once("../../libs/get-feed.php"); ?>
     2.8 +<?php require_once("../../libs/get-feeds.php"); ?>
     2.9  
    2.10  <div class="activity">
    2.11  	<p>
    2.12  		<a href="http://hg.slitaz.org/">
    2.13  			<img src="../../images/development.png" alt="development.png" /></a>
    2.14  		Latest commits in wok
    2.15 -		<?php get_rss_feed("/var/cache/slitaz/website/wok.xml"); ?>
    2.16 +		<?php get_feed("wok.xml"); ?>
    2.17  	</div>
    2.18  	<p class="activity_more">
    2.19  		<a href="http://hg.slitaz.org/">More commits</a>
     3.1 --- a/fr/index.php	Wed Mar 30 18:37:02 2011 +0200
     3.2 +++ b/fr/index.php	Wed Mar 30 20:31:49 2011 +0200
     3.3 @@ -97,7 +97,7 @@
     3.4  <h2>Actualités du projet</h2>
     3.5  <p>
     3.6  	Le site web de SliTaz propose les principales nouvelles du projet, et
     3.7 -	<a href="http://labs.slitaz.org/">les laboratoires</a> des nouvelles
     3.8 +	<a href="http://scn.slitaz.org/">le blog officiel</a> des nouvelles
     3.9  	sur l'activité générale des différents sous-projets. Ces nouvelles sont
    3.10  	aussi disponibles sous forme de <a href="rss.xml">flux XML</a>. De 
    3.11  	même, le projet propose une petite lettre d'information mensuelle et
    3.12 @@ -108,9 +108,7 @@
    3.13  
    3.14  <div class="box">
    3.15  	<img src="../images/news.png" alt="news.png" />
    3.16 -	<a href="http://labs.slitaz.org/news">Nouvelles des Labs</a>
    3.17 -	(<a href="http://labs.slitaz.org/news?format=atom">flux</a>)
    3.18 -	<img src="../pics/website/news.png" alt="news.png" />
    3.19 +	<a href="http://scn.slitaz.org/">Nouvelles du Blog</a> |
    3.20  	<a href="http://doc.slitaz.org/fr:newsletter:start">Lettre d'information</a>
    3.21  </div>
    3.22  
    3.23 @@ -318,7 +316,7 @@
    3.24  
    3.25  <h2>Activité du projet</h2>
    3.26  <?php
    3.27 -	require_once("../libs/get-feed.php");
    3.28 +	require_once("../libs/get-feeds.php");
    3.29  ?>
    3.30  
    3.31  <div class="activity">
    3.32 @@ -326,7 +324,7 @@
    3.33  		<a href="http://scn.slitaz.org/activity/"><img 
    3.34  			src="../images/users.png" alt="users.png" /></a>
    3.35  		Activité de la communauté
    3.36 -		<?php get_rss_feed("/var/cache/slitaz/website/scn.xml"); ?>
    3.37 +		<?php get_feed("scn.xml"); ?>
    3.38  	</div>
    3.39  	<p class="activity_more">
    3.40  		<a href="http://scn.slitaz.org/activity/">Plus d'activité</a>
    3.41 @@ -338,7 +336,7 @@
    3.42  		<a href="http://hg.slitaz.org/">
    3.43  			<img src="../images/development.png" alt="development.png" /></a>
    3.44  		Derniers commits dans le wok
    3.45 -		<?php get_rss_feed("/var/cache/slitaz/website/wok.xml"); ?>
    3.46 +		<?php get_feed("wok.xml"); ?>
    3.47  	</div>
    3.48  	<p class="activity_more">
    3.49  		<a href="http://hg.slitaz.org/">Plus de commits</a>
     4.1 --- a/index.php	Wed Mar 30 18:37:02 2011 +0200
     4.2 +++ b/index.php	Wed Mar 30 20:31:49 2011 +0200
     4.3 @@ -104,7 +104,7 @@
     4.4  
     4.5  <h2>Project Activity</h2>
     4.6  <?php
     4.7 -	require_once("libs/get-feed.php");
     4.8 +	require_once("libs/get-feeds.php");
     4.9  ?>
    4.10  
    4.11  <div class="activity">
    4.12 @@ -112,7 +112,7 @@
    4.13  		<a href="http://scn.slitaz.org/activity/"><img 
    4.14  			src="images/users.png" alt="users.png" /></a>
    4.15  		Community activity
    4.16 -		<?php get_rss_feed("/var/cache/slitaz/website/scn.xml"); ?>
    4.17 +		<?php get_feed("scn.xml"); ?>
    4.18  	</div>
    4.19  	<p class="activity_more">
    4.20  		<a href="http://scn.slitaz.org/activity/">More activity</a>
    4.21 @@ -124,7 +124,7 @@
    4.22  		<a href="http://hg.slitaz.org/">
    4.23  			<img src="images/development.png" alt="development.png" /></a>
    4.24  		Latest commits in wok
    4.25 -		<?php get_rss_feed("/var/cache/slitaz/website/wok.xml"); ?>
    4.26 +		<?php get_feed("wok.xml"); ?>
    4.27  	</div>
    4.28  	<p class="activity_more">
    4.29  		<a href="http://hg.slitaz.org/">More commits</a>
     5.1 --- a/libs/get-feed.php	Wed Mar 30 18:37:02 2011 +0200
     5.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.3 @@ -1,28 +0,0 @@
     5.4 -<?php
     5.5 -// Read RSS Feed
     5.6 -function get_rss_feed($feed_url) {
     5.7 -	if ( ! file_exists($feed_url)) {
     5.8 -		echo "</p>\n<div>\n";
     5.9 -		echo "Missing feed: $feed_url\n" . "</div>\n";
    5.10 -	}
    5.11 -	else {
    5.12 -		$content = file_get_contents($feed_url);
    5.13 -		$x = new SimpleXmlElement($content);
    5.14 -		$entries = 4;
    5.15 -		$count = 0;
    5.16 -		// We look for last item, channel may not have a PubDate*
    5.17 -		$up = ($x->channel->item->pubDate);
    5.18 -		echo "<span>Updated: " . substr("$up", 5, 17) . "</span>\n";
    5.19 -		echo "</p>\n<div>\n<ul>\n";
    5.20 -		foreach($x->channel->item as $entry) {
    5.21 -			$count = $count + 1;
    5.22 -			echo "	<li><a href='$entry->link' title='$entry->title'>" . 
    5.23 -				$entry->title . "</a></li>\n";
    5.24 -			if ($count == $entries) {
    5.25 -				break;
    5.26 -			}
    5.27 -		}
    5.28 -		echo "</ul>\n";
    5.29 -	}
    5.30 -}
    5.31 -?>
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/libs/get-feeds.php	Wed Mar 30 20:31:49 2011 +0200
     6.3 @@ -0,0 +1,62 @@
     6.4 +<?php
     6.5 +
     6.6 +// Read RSS Feed
     6.7 +function get_feed($feed) {
     6.8 +	$cache = '/var/cache/slitaz/website';
     6.9 +	$entries = 4;
    6.10 +	// have the page displayed even if any xml file
    6.11 +	if ( ! file_exists("$cache/$feed")) {
    6.12 +		echo "</p>\n<div>\n";
    6.13 +		echo "Missing feed: $cache/$feed\n" . "</div>\n";
    6.14 +	}
    6.15 +	else {
    6.16 +		$content = file_get_contents("$cache/$feed");
    6.17 +		$x = new SimpleXmlElement($content);
    6.18 +		$count = 0;
    6.19 +		// We look for last item, channel may not have a PubDate*
    6.20 +		$up = ($x->channel->item->pubDate);
    6.21 +		echo "<span>Updated: " . substr("$up", 5, 17) . "</span>\n";
    6.22 +		echo "</p>\n<div>\n<ul>\n";
    6.23 +		foreach($x->channel->item as $entry) {
    6.24 +			$count = $count + 1;
    6.25 +			echo "	<li><a href='$entry->link' title='$entry->title'>" . 
    6.26 +				$entry->title . "</a></li>\n";
    6.27 +			if ($count == $entries) {
    6.28 +				break;
    6.29 +			}
    6.30 +		}
    6.31 +		echo "</ul>\n";
    6.32 +	}
    6.33 +}
    6.34 +
    6.35 +// Read Blog RSS Feed
    6.36 +function get_feed_blog($feed) {
    6.37 +	$cache = '/var/cache/slitaz/website';
    6.38 +	$entries = 4;
    6.39 +	// have the page displayed even if any xml file
    6.40 +	if ( ! file_exists("$cache/$feed")) {
    6.41 +		echo "Missing feed: $cache/$feed\n" . "</div>\n";
    6.42 +	}
    6.43 +	else {
    6.44 +		$content = file_get_contents("$cache/$feed");
    6.45 +		$x = new SimpleXmlElement($content);
    6.46 +		$count = 0;
    6.47 +		// We look for last item, channel may not have a PubDate*
    6.48 +		$up = ($x->channel->item->pubDate);
    6.49 +		
    6.50 +		echo "<ul>\n";
    6.51 +		foreach($x->channel->item as $entry) {
    6.52 +			$count = $count + 1;
    6.53 +			echo "	<li><strong><a href='$entry->link' title='$entry->title'>" . 
    6.54 +				$entry->title . "</strong></a>\n";
    6.55 +			echo "<span>" . substr("$entry->pubDate", 5, 17) . "</span>\n";
    6.56 +			echo "<p>$entry->description</p>\n</li>";
    6.57 +			if ($count == $entries) {
    6.58 +				break;
    6.59 +			}
    6.60 +		}
    6.61 +		echo "</ul>\n";
    6.62 +	}
    6.63 +}
    6.64 +
    6.65 +?>
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/libs/get-feeds.sh	Wed Mar 30 20:31:49 2011 +0200
     7.3 @@ -0,0 +1,27 @@
     7.4 +#!/bin/sh
     7.5 +# 
     7.6 +# Get latest commits and feeds to display on the website main page.
     7.7 +# On Tank, this script is executed by cron each hour.
     7.8 +#
     7.9 +
    7.10 +URL="http://hg.slitaz.org/wok"
    7.11 +PKGS="/home/slitaz/cooking/packages"
    7.12 +CACHE="/var/cache/slitaz/website"
    7.13 +OUTPUT="$CACHE/latest.html"
    7.14 +
    7.15 +# Feeds URL
    7.16 +SCN_FEED='http://scn.slitaz.org/activity/feed/'
    7.17 +BLOG_FEED='http://scn.slitaz.org/category/news/feed/'
    7.18 +WOK_FEED='http://hg.slitaz.org/wok/rss-log'
    7.19 +
    7.20 +# Clean cache
    7.21 +mkdir -p $CACHE && cd $CACHE
    7.22 +rm -f *.xml
    7.23 +
    7.24 +# Cache all feeds to save bandwidth (updated by cron)
    7.25 +echo -n "Getting latest rss feeds... "
    7.26 +wget -O scn.xml $SCN_FEED 2>/dev/null
    7.27 +wget -O wok.xml $WOK_FEED 2>/dev/null
    7.28 +wget -O blog.xml $BLOG_FEED 2>/dev/null
    7.29 +echo "Done"
    7.30 +
     8.1 --- a/libs/get-latest.sh	Wed Mar 30 18:37:02 2011 +0200
     8.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.3 @@ -1,41 +0,0 @@
     8.4 -#!/bin/sh
     8.5 -# 
     8.6 -# Get latest commits and packages to display on the website main page.
     8.7 -# On Tank, this script is executed by cron each hour.
     8.8 -#
     8.9 -
    8.10 -REPO="/home/slitaz/repos/wok"
    8.11 -URL="http://hg.slitaz.org/wok"
    8.12 -PKGS="/home/slitaz/cooking/packages"
    8.13 -CACHE="/var/cache/slitaz/website"
    8.14 -OUTPUT="$CACHE/latest.html"
    8.15 -
    8.16 -# Feed URLs
    8.17 -SCN_FEED='http://scn.slitaz.org/activity/feed/'
    8.18 -DOC_FEED='http://doc.slitaz.org/feed.php'
    8.19 -FORUM_FEED='http://forum.slitaz.org/rss/'
    8.20 -BUGS_FEED='http://labs.slitaz.org/issues.atom?query_id='
    8.21 -WOK_FEED='http://hg.slitaz.org/wok/rss-log'
    8.22 -
    8.23 -# Clean cache
    8.24 -mkdir -p $CACHE && cd $CACHE
    8.25 -rm *.xml
    8.26 -
    8.27 -# Cache all feeds to save bandwidth (updated by cron)
    8.28 -#wget -O doc.xml $DOC_FEED
    8.29 -#wget -O forum.xml $FORUM_FEED 
    8.30 -#wget -O bugs.xml $BUGS_FEED
    8.31 -wget -O scn.xml $SCN_FEED
    8.32 -wget -O wok.xml $WOK_FEED
    8.33 -
    8.34 -# Latest cooked packages by the build bot.
    8.35 -#echo -n "Getting latest cooked packages... "
    8.36 -#echo '<ul>' > $OUTPUT
    8.37 -#cd $PKGS && ls -1t *.tazpkg | head -8 | \
    8.38 -#while read file
    8.39 -#do
    8.40 -	#echo -n '	<li>'$(stat -c '%y' $PKGS/$file | \
    8.41 -	#cut -d ' ' -f 1); echo " - $file</li>"
    8.42 -#done >> $OUTPUT
    8.43 -#echo '</ul>' >> $OUTPUT
    8.44 -#echo "Done"