root/branches/licq/website/archive.php

Revision 4129, 3.7 kB (checked in by anonymous, 4 years ago)

This commit was manufactured by cvs2svn to create branch 'licq'.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1<?
2
3function news_last_id()
4{
5  $aux = file("news/last_id");
6  return $aux[0];
7}
8
9function news_check_item($id)
10{
11  return is_readable("news/$id");
12}
13
14function news_read_item($id)
15{
16    return file("news/$id");
17}
18
19/* check if there is a previous item and return id else -1 */
20function news_check_prev_item($cur_id)
21{
22  while ( $cur_id > 0 )
23  {
24        $cur_id--;
25        if ( !news_check_item( $cur_id ) )
26            continue;
27        return $cur_id;
28    }
29    return -1;
30}
31
32/* check if there is a next item and return id else -1 */
33function news_check_next_item( $cur_id )
34{
35    $last_id = news_last_id();
36    while ( $cur_id < $last_id )
37    {
38        $cur_id++;
39        if ( !news_check_item( $cur_id ) )
40            continue;
41        return $cur_id;
42    }
43    return -1;
44}
45
46function news_show_item( $data )
47{
48    $title = $data[1];
49    $aux = split( "-", str_replace( ":", "-", str_replace( " ", "-", $data[0] ) ) );
50    $date = date( "M jS G:i Y", mktime($aux[3],$aux[4],0,$aux[1],$aux[2],$aux[0] ) );
51    ?>
52    <div class="news">
53      <h2><B><?echo $title;?></B> - <I><?echo $date;?></I></h2>
54      <p>
55      <? for ( $i =2; $i < count ( $data ); $i++ ) echo $data[$i]; ?>
56      </p>
57      <div class="footer">
58        <div class="footer_right"></div>
59      </div>
60    </div>
61    <?
62}
63
64function news_show_latest()
65{
66    $max_news_items = 10;
67    $cur_id = news_last_id();
68    settype( $cur_id, "integer" );
69    /* read the latest valid newsitems from archive */
70    $count = 0;
71    while ( $count < $max_news_items && $cur_id >= 0 )
72    {
73        if ( news_check_item( $cur_id ) )
74        {
75          $aux = news_read_item( $cur_id );
76          news_show_item( $aux );
77          $count++;
78        }
79        $cur_id--;
80    }
81    echo "<center>[ <A href=\"news.php?action=show_news&news_action=show_archive\">News Archive</A> ]</center>";
82}
83
84function news_show_archive()
85{
86    $entries = dir_get_entries( "news" );
87    echo "<P align=\"center\"><B>",count($entries)-2," news items found.</B></P>";
88    echo "<DIV align=\"center\">";
89    echo "<TABLE width=50% border=0 cellpadding=0 cellspacing=0><TR><TD>";
90    $cur_id = news_last_id();
91    settype( $cur_id, "integer" );
92    while ( $cur_id >= 0 )
93    {
94        if ( news_check_item( $cur_id ) )
95        {
96            $aux = news_read_item( $cur_id );
97            echo "<TABLE width=100% border=0 cellpadding=0 cellspacing=0>";
98            echo "<TR><TD align=\"left\"><B><A href=\"news.php?action=show_news&news_action=show_item&item_id=$cur_id\">$aux[1]</A></B></TD><TD align=\"right\"><FONT size=-1>( $aux[0] )</FONT></TD></TR>";
99            //echo "<TR><TD colspan=2 bgcolor=\"#000000\"><IMG alt=\"\" src=\"images/spacer1.gif\"></TD></TR>";
100            echo "</TABLE>";
101            echo "";
102        }
103        $cur_id--;
104    }
105    echo "</TD></TR></TABLE>";
106    echo "</DIV>";
107}
108
109function news_show_single_item()
110{
111    global $item_id;
112    $data = news_read_item( $item_id );
113    news_show_item( $data );
114    $prev_id = news_check_prev_item( $item_id );
115    $next_id = news_check_next_item( $item_id );
116    echo "<center>";
117    if ( $prev_id != -1 )
118        echo "[ <A href=\"news.php?news_action=show_item&item_id=$prev_id\">Prev</A> ]";
119    echo "[ <A href=\"news.php?news_action=show_archive\">News Archive</A> ]";
120    if ( $next_id != -1 )
121        echo "[ <A href=\"news.php?news_action=show_item&item_id=$next_id\">Next</A> ]";
122    echo "</center>";
123}
124
125/*
126 * Get all directory entries except . and ..
127 */
128function dir_get_entries( $path ) {
129    $i = 0;
130    $hdir = opendir( $path );
131    while( $entry = readdir( $hdir ) ) {
132        if ( $entry == "." ) continue;
133        if ( $entry == ".." ) continue;
134        $data[$i++] = $entry;
135    }
136    closedir( $hdir );
137    if ( !empty( $data ) ) sort( $data );
138    return $data;
139}
140?>
Note: See TracBrowser for help on using the browser.