177524754014614f098aadbbcb2f7c0524aad994
[atutor.git] / mods / wiki / fragments / blocks / news.php
1 <?php
2
3 /*
4    This block prints out a short paragraph of the pages that were
5    linked from the "News" page. This is much like the page_wikinews,
6    but gets the list of to-be-printed pages from another one instead of
7    using the list of newest pages.
8
9    It respects following $ewiki_config[] entries:
10     ["newsblock_links"] - use which pages` links ("News")
11     ["newsblock_num"] - how many new articles to be shown
12     ["newsblock_len"] - string length of the excerpts
13    (or just customize the defaults below)
14 */
15
16
17 if (true)   #-- this is not a function here
18 {
19
20    global $ewiki_plugins, $ewiki_config;
21
22    #-- conf
23    ($n_get = $ewiki_config["newsblock_links"]) || ($n_get = "News");
24    ($n_num = $ewiki_config["newsblock_num"]) || ($n_num = 10);
25    ($n_len = $ewiki_config["newsblock_len"]) || ($n_len = 196);
26
27    #-- fetch all page entries from DB, for sorting on creation time
28    $links = ewiki_db::GET($n_get);
29    $links = explode("\n", trim($links["refs"]));
30
31    #-- cut
32    $links = array_slice($links, 0, $n_num);
33
34    #-- gen output
35    $o = "";
36    foreach ($links as $uu=>$id) {
37
38       if ($row = ewiki_db::GET($id)) {
39
40          $text = substr($row["content"], 0, $n_len);
41          $text = trim(strip_tags(strtr($text, "\r\n\t", "   ")));
42          $text = str_replace("[internal://", "[  internal://", $text);
43          $text .= "\n";
44 #         $text .= " [...[read more | $id]]\n";
45
46          $o .= "__[$id]__\n"
47              . "$text\n"
48              . "%%%\n";
49       }
50    }
51
52    #-- pass thru renderer
53    if ($o) {
54       $o = ewiki_format($o);
55       echo('<div class="block-news">' . $o . '</div>');
56    }
57 }
58
59 ?>