aboutsummaryrefslogtreecommitdiffstats
path: root/lib/news.php
diff options
context:
space:
mode:
authorRomain d'Alverny <rda@mageia.org>2010-11-29 11:21:24 +0000
committerRomain d'Alverny <rda@mageia.org>2010-11-29 11:21:24 +0000
commit2a26057508c233ec832dcd263f8e9ec8285cb480 (patch)
treec1b16b9ec6c717dfc4a9f23abad66977d10c53de /lib/news.php
parentc8faed7a799128f45e58e6430bb3ccac77c70b53 (diff)
downloadwww-2a26057508c233ec832dcd263f8e9ec8285cb480.tar
www-2a26057508c233ec832dcd263f8e9ec8285cb480.tar.gz
www-2a26057508c233ec832dcd263f8e9ec8285cb480.tar.bz2
www-2a26057508c233ec832dcd263f8e9ec8285cb480.tar.xz
www-2a26057508c233ec832dcd263f8e9ec8285cb480.zip
new layout for fr home page
Diffstat (limited to 'lib/news.php')
-rw-r--r--lib/news.php89
1 files changed, 89 insertions, 0 deletions
diff --git a/lib/news.php b/lib/news.php
new file mode 100644
index 000000000..6ff918d4a
--- /dev/null
+++ b/lib/news.php
@@ -0,0 +1,89 @@
+<?php
+/**
+*/
+
+
+/**
+ * @param string $locale
+ *
+ * @return array
+*/
+function html_news($locale = 'en')
+{
+ $news = get_news($locale);
+ $html = '<ul class="news">';
+ $item_tmpl = '<li><span class="dt">%s</span> <a href="%s">%s</a> </li>';
+ foreach ($news as $item)
+ {
+ $html .= sprintf($item_tmpl,
+ news_date($item['date'], $locale),
+ $item['link'],
+ $item['title']
+ );
+ }
+ $html .= '</ul>';
+ return $html;
+}
+
+/**
+ * @param string $dt
+ * @param string $locale
+ *
+ * @return string
+*/
+function news_date($dt, $locale = 'en')
+{
+ $formats = array(
+ 'en' => 'M d Y',
+ 'fr' => 'd M Y',
+ 'default' => 'Y-m-d'
+ );
+ $ft = array_key_exists($locale, $formats) ? $locale : 'default';
+
+ $dts = strtotime($dt);
+ return date($formats[$ft], $dts);
+}
+
+/**
+ * @param string $locale
+ * @param integer $count
+ * @param integer $cache_timeout
+ *
+ * @return array
+*/
+function get_news($locale = 'en', $count = 5, $cache_timeout = 5)
+{
+ $news = array(
+ 'en' => 'http://blog.mageia.org/',
+ 'fr' => 'http://blog.mageia.org/fr/',
+ 'es' => 'http://blog.mageia.org/es/'
+ );
+
+ if (!array_key_exists($locale, $news))
+ $locale = 'en';
+
+ $source_url = $news[$locale];
+
+ include_once G_APP_ROOT . '/lib/simplepie/simplepie.inc';
+ $feed = new SimplePie($source_url,
+ realpath(G_APP_ROOT . '/var/tmp/cache'),
+ 3600 * $cache_timeout);
+
+ //$feed->enable_order_by_date(true);
+
+ $feed->handle_content_type();
+
+ $items = array();
+ foreach ($feed->get_items(0, $count) as $item)
+ $items[] = array(
+ 'link' => $item->get_permalink(),
+ 'title' => $item->get_title(),
+ 'date' => $item->get_date('c'),
+ 'desc' => $item->get_description(),
+ 'author' => $item->get_author()
+ );
+
+ unset($feed);
+
+ return $items;
+} \ No newline at end of file