+ initial commit
[sfa:tema.git] / atom-innspill.php
1 <?php
2 /**
3  * @package sfa
4  * @subpackage sfa-theme
5  */
6 /*
7 Template Name: atom-gi-innspill
8 */
9
10 $arr_topic = array("Frafall i videregående opplæring", "Sykefravær", "Bærekraftig økonomi", "Næringsutvikling");
11  
12 global $wpdb;
13 header('Content-Type: ' . feed_content_type('atom') . '; charset=' . get_option('blog_charset'), true);
14 echo '<?xml version="1.0" encoding="' . get_option('blog_charset') . '" ?' . '>';
15
16 $topic = '';
17
18 if(isset($_GET['topic']))
19 {
20         $topic = $_GET['topic'];
21         
22         switch($topic)
23         {
24                 case 'frafall':
25                         $topic = $arr_topic[0];
26                         break;
27                 case 'fravaer':
28                         $topic = $arr_topic[1];
29                         break;
30                 case 'okonomi':
31                         $topic = $arr_topic[2];
32                         break;
33                 case 'naeringsutvikling':
34                         $topic = $arr_topic[3];
35                         break;
36                 
37         }
38         $where = " WHERE topic='$topic' ";
39 }
40 /*
41 else
42         $wpdb->show_errors();
43 */
44
45 $feedbacks = $wpdb->get_results("SELECT *, INET_NTOA(Ip) AS Ip FROM ".$wpdb->prefix."input_article ".$where." ORDER BY date desc LIMIT 0,20");
46
47 $feed_updated;
48
49 if(!empty($feedbacks[0]))
50         $feed_updated = mysql2date('Y-m-d\TH:i:s\Z', $feedbacks[0]->date, false);
51 ?>
52
53 <feed
54         xmlns="http://www.w3.org/2005/Atom"
55         xml:lang="<?php echo get_option('rss_language'); ?>"
56         xmlns:thr="http://purl.org/syndication/thread/1.0"
57         <?php do_action('atom_ns'); do_action('atom_comments_ns'); ?>
58 >
59         <title type="text">Innspill om artikler og blogginnlegg <?php echo ($topic!='' ? ' om emnet '.strtolower($topic) : '') ?></title>
60         <subtitle type="text"></subtitle>
61         <updated><?php echo $feed_updated ?></updated>
62         <?php the_generator( 'atom' ); ?>
63         <link rel="alternate" type="<?php bloginfo_rss('html_type'); ?>" href="<?php bloginfo_rss('home'); ?>" />
64         <id><?php bloginfo_rss('atom_url'); ?>custom</id>
65
66 <?php
67 if ( !empty($feedbacks) )
68 {
69         foreach ( $feedbacks as $feedback )
70         {
71 ?>
72         <entry>
73                 <id>tag:samarbeidforarbeid.no,<?php echo mysql2date('Y-m-d', $feedback->date, false) ?>:<?php echo sha1($feedback->id.$feedback->alias)?></id>
74                 <title type="html"><![CDATA[<?php echo $feedback->subject;?>]]></title>
75                 <author>
76                         <name type="html"><![CDATA[<?php echo $feedback->alias ?>]]></name>
77                 </author>
78                 <updated><?php echo mysql2date('Y-m-d\TH:i:s\Z', $feedback->date, false); ?></updated>
79                 <published><?php echo mysql2date('Y-m-d\TH:i:s\Z', $feedback->date, false); ?></published>
80                 <content type="html"><![CDATA[Emne: <?php echo $feedback->topic ?><br/><a href="<?php echo $feedback->url ?>" target="_blank"><?php echo $feedback->url ?></a>]]></content>
81         </entry>
82
83 <?php 
84         }
85 }
86 else
87 {
88 ?>
89
90         <entry>
91                 <id>tag:samarbeidforarbeid.no</id>
92                 <title>empty</title>
93                 <author>
94                         <name></name>
95                 </author>
96         </entry>
97
98 <?php
99 }
100 ?>
101 </feed>