2ccda59cecac071aaf68d06c01131792dc639244
[atutor.git] / mods / wiki / plugins / page / wikinews.php
1 <?php
2
3 /*
4    prints out a short summary of changed wiki pages
5    (an "updated-articles-list")
6
7    It respects following $ewiki_config[] entries:
8     ["wikinews_num"] - how many new articles to be shown
9     ["wikinews_len"] - string length of the excerpts
10     ["wikinews_regex"] - use only pages that match this /pregex/
11 */
12
13
14 $ewiki_plugins["page"]["WikiNews"] = "ewiki_page_wikinews";
15
16 function ewiki_page_wikinews($newsid, $data, $action) {
17   global $ewiki_config;
18
19    #-- conf
20    ($n_num = $ewiki_config["wikinews_num"]) || ($n_num = 10);
21    ($n_len = $ewiki_config["wikinews_len"]) || ($n_len = 512);
22    ($c_regex = $ewiki_config["wikinews_regex"]) || ($c_regex = false);
23
24   return(ewiki_make_title($newsid,$newsid, 2).ewiki_wikinews_summary($n_num,$n_len,$c_regex));
25 }
26
27 function ewiki_wikinews_summary($n_num,$n_len,$c_regex){
28   global $ewiki_plugins, $ewiki_config;
29
30   #-- fetch all page entries from DB, for sorting on creation time
31   $result = ewiki_db::GETALL(array("lastmodified"));
32   $sorted = array();
33   while ($row = $result->get()) {
34   
35     if (EWIKI_DB_F_TEXT == ($row["flags"] & EWIKI_DB_F_TYPE)) {
36   
37       if ($c_regex && !preg_match($c_regex, $row["id"])) {
38         continue;
39       }
40       
41       $sorted[$row["id"]] = $row["lastmodified"];
42     }
43   }
44   
45   #-- sort 
46   arsort($sorted);
47     
48   $displayed  = 0;//$displayed will count pages successfully displayed
49   
50   #-- gen output
51   $o = "";
52   foreach ($sorted as $id=>$uu) {
53   
54     $row = ewiki_db::GET($id);
55   
56     #-- require auth
57     if (EWIKI_PROTECTED_MODE && !ewiki_auth($id, $row, "view", $ring=false, $force=0)) {
58        if (EWIKI_PROTECTED_MODE_HIDING) {
59           continue;
60        } else {
61           $row["content"] = ewiki_t("FORBIDDEN");
62        }
63     }
64     
65     $text = "\n".substr($row["content"], 0, $n_len);
66     $text = str_replace("[internal://", "[  internal://", $text);
67     $text .= " [...[read more | $id]]\n";
68     
69     #-- title mangling (from ewiki.php)
70     $title=$id;      
71     if ($ewiki_config["split_title"] && $may_split) {
72       $title = ewiki_split_title($title, $ewiki_config["split_title"], 0&($title!=$ewiki_title));   //Why 0&?
73     }
74     else {
75       $title = htmlentities($title);
76     }      
77     if ($pf_a = @$ewiki_plugins["title_transform"]) {
78       foreach ($pf_a as $pf) { $pf($id, $title, $go_action); }
79     }
80     
81     if($ewiki_config["wm_publishing_headers"]){
82       $text = preg_replace("/^!([^!])/m","!! \$1",$text);
83       $o .= "\n" .
84           "! [\"$title\"$id]";
85     }else{
86       $text = preg_replace("/^!!!/m","!!",$text);
87       $o .= "\n" .
88           "!!! [\"$title\"$id]";      
89     }
90     $o .=" µµ". strftime(ewiki_t("LASTCHANGED"), $row["lastmodified"])."µµ\n";
91     $o .= " $text\n";
92     $o .= "----\n";
93   
94     if (!($n_num--)) {
95        break;
96     }
97   }
98   
99   
100   #-- render requested wiki page  <-- goal !!!
101   $render_args = array(
102     "scan_links" => 1,
103     "html" => (EWIKI_ALLOW_HTML||(@$data["flags"]&EWIKI_DB_F_HTML)),
104   );
105    $o =  $ewiki_plugins["render"][0] ($o, $render_args);
106   
107   return($o);
108 }
109
110 ?>