/[svn]/web/trunk/www.linuxsampler.org/news_internal.php
ViewVC logotype

Annotation of /web/trunk/www.linuxsampler.org/news_internal.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1268 - (hide annotations) (download)
Tue Aug 7 19:56:17 2007 UTC (12 years, 10 months ago) by schoenebeck
File size: 1902 byte(s)
- news for the website are now maintained in a separate file called
  news.xml and the front page automatically includes only the
  youngest 3 entries (older news entries can be seen on a separate
  history page)

1 schoenebeck 1268 <?php
2    
3     // XML file with news data
4     $file = "news.xml";
5     // show all news entries by default
6     $max_items = -1;
7    
8     function startElement($parser, $name, $attribs) {
9     global $max_items;
10     if ($max_items == 0) return;
11    
12     if ($name == "entry") {
13     if (count($attribs) && isset($attribs["date"])) {
14     $d = $attribs["date"];
15     echo "<div class=\"news\">";
16     echo "<span class=\"news_date\">$d</span> ";
17     } else echo "<b>???</b> ";
18     } else if ($name == "link") {
19     $addr = (isset($attribs["ref"])) ? $attribs["ref"] : "";
20     echo "<a href=\"$addr\">";
21     } else if ($name == "list") {
22     echo "<ul class=\"news\">";
23     } else if ($name == "li") {
24     echo "<li class=\"news\">";
25     }
26     }
27    
28     function endElement($parser, $name) {
29     global $max_items;
30     if ($max_items == 0) return;
31    
32     if ($name == "entry") { echo "</div>\n";
33     if ($max_items > 0) $max_items--;
34     }
35     else if ($name == "link") echo "</a>";
36     else if ($name == "list") echo "</ul>";
37     else if ($name == "li") echo "</li>";
38     }
39    
40     function characterData($parser, $data) {
41     global $max_items;
42     if ($max_items == 0) return;
43    
44     echo $data;
45     }
46    
47     if (isset($HTTP_GET_VARS['max_items'])) {
48     $max_items = $HTTP_GET_VARS['max_items'];
49     }
50    
51     $xml_parser = xml_parser_create();
52     xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, false);
53     xml_set_element_handler($xml_parser, "startElement", "endElement");
54     xml_set_character_data_handler($xml_parser, "characterData");
55     if (!($fp = fopen($file, "r"))) {
56     die("Could not open news XML file!");
57     }
58     while ($data = fread($fp, 4096)) {
59     if (!xml_parse($xml_parser, $data, feof($fp))) {
60     die(sprintf("XML error: %s at line %d",
61     xml_error_string(xml_get_error_code($xml_parser)),
62     xml_get_current_line_number($xml_parser)));
63     }
64     }
65     xml_parser_free($xml_parser);
66    
67     ?>

  ViewVC Help
Powered by ViewVC