news.php 3.17 KB
Newer Older
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
1
2
3
4
5
6
<?php
/*
 * $style: either "full" or "title"
 * $max: number of news to print (0 to print all news)
 *
 */
7
    function shownews($style,$max,$mockup=false) {
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
8
    ?>
Christoph Miebach's avatar
Christoph Miebach committed
9
10
    <div dir="ltr" lang="en">

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
11
12
13
14
15
16
17
18
19
20
21
22
23
    <script type="text/javascript">
    function toggle(count) {
        var text = "news-span-"+count;
        var read = "read-"+count;
        if(document.getElementById(text))
        {
            if(document.getElementById(text).style.display == 'none')
            {
                document.getElementById(text).style.display = 'inline';
                document.getElementById(read).innerHTML = "(Read less...)";
            }
            else
            {
24
                document.getElementById(text).style.display = 'none';
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
25
26
27
28
29
30
31
                document.getElementById(read).innerHTML = "(Read more...)";
            }
        }
    }
    </script>
    <?php
    $file=fopen("news.msg","r");
32
    $count = 0;
33
    $msg = "";
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
34
35

    if(!$file)
Christoph Miebach's avatar
Christoph Miebach committed
36
    {
Christoph Miebach's avatar
Christoph Miebach committed
37
        echo ('</div><!-- news are en only -->');
Christoph Miebach's avatar
Christoph Miebach committed
38
39
        return(0);
    }
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
40
41
42

    while( !feof($file) )
    {
43
        $line=preg_replace("/\n/","",fgets($file,4096));
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
44
45

        // Comments are allowed
46
        if( !preg_match("/^ *#/",$line) && !preg_match("/^ *$/",$line) )
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
47
48
        {
            // Topics start with "|"
49
            if( preg_match("/^ *\|/",$line) && $msg )
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
50
51
52
53
54
            {
                $ex=explode("|",$msg);
                $date = $ex[1];
                $title = $ex[2];
                $short = $ex[3];
55
56
                if( count($ex) > 4)
                    $remain = $ex[4];
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
57

58
59
60
61
62
63
64
                if( $count ++ < 15 ) {
                   if( $mockup )
                       echo ("<td><div class='item'>\n");
                   else
                       echo ("<div class='item'>\n");
                }
                else { echo ("<div class='item-really-old'>\n"); }
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
65
                $postdate = date("Y-m-d", strtotime( $date) );
66
                echo "<a id='news-$postdate' name='news-$postdate'></a>";
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
67

68
                echo ("<div class='title'><a href=\"/news.html#news-$postdate\">".$title."</a></div>\n" );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
69
                //echo "<div id=\"news-$count\">";
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
70
                echo ("<div class='date'>".$postdate."</div>\n");
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
71
                echo "<p class='news-descr'>".$short;
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
72
                if( isset($remain) )
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
73
74
75
76
77
78
79
80
                {
                    echo "<span id=\"news-span-$count\">$remain</span> ";
                    echo "<script type=\"text/javascript\"><!--\n";
                    echo "document.writeln('<br /><a id=\"read-$count\" ";
                    echo "href=\"javascript:toggle(\'$count\')\">(Read more...)";
                    echo "</a>');toggle( $count );\n--></script>";
                }
                echo "</p>\n</div>\n";
81
82
                $max--;
                if($max != 0 ) echo '<div class="horizontalRule"></div>';
83
                if( $mockup ) echo "</td>";
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
84

85
86
87
88
                if($max == 0) {
                    echo ('</div><!-- news are en only -->');
                    return;
                }
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
89
90
91
92
93
94
                $msg="";
             }
            $msg.=" ".$line;
        }
    }
    fclose($file);
Christoph Miebach's avatar
Christoph Miebach committed
95
    echo ('</div><!-- news are en only -->');
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
96
97
}

98
99
function shownews_mockup($style,$max) {
    shownews($style,$max,true);
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
100
}
Christoph Miebach's avatar
Christoph Miebach committed
101
?>