b44d226711b99343b53ce50db7173a5b97849e29
[atutor.git] / mods / wiki / plugins / mpi / mpi_blog.php
1 <?php
2
3 /*
4    Description: prints out a wiki-news style summary of blog entries for   the current  page.
5
6    The Calendar plugin should be included for page creation and archival browsing.
7    
8    Adapted from:  Wikinews
9    Developed by AndyFundinger 
10    Extended by WojciechJanKalka <w@kalka.org>
11
12    Usage:
13    <?plugin Blog
14             page=MyBlogPage  // Page ID
15             num=20           // List how many Items
16             len=512          // List length till more
17             sort=0           // Sort order  1 ->pagename or 0 ->entrydate
18             sort_reverse=0   // Reverse sort 
19             calendar=0       // Normal blog or calendar blog (0/1)
20             hr=0             // Horizontal Rule each item (0/1)
21             more=0           // Show more link to blog page (0/1)
22    ?>
23   
24    1.1.4 - cleaned up the code, added documentation (wjk)
25    1.1.3 - +added sort on and reverse sort (wjk)
26            +added calendar blog choice (wjk) *untested*
27            +added some other boolean switches (wjk)
28    1.1.2 - changed the plugin from calendarlist to blog (wjk)
29            +added ewiki_blog_list (wjk)
30    1.1.1 - started this plugin (wjk)
31 */
32  
33
34 // display a list of blog itmes 
35 function ewiki_blog_list($n_num,$n_len,$b_sort,$b_sortrev,$b_hr,$b_more,$c_regex){
36   global $ewiki_plugins, $ewiki_config;
37
38   #-- fetch all page entries from DB, for sorting on pagename or lastmodified
39   if ($b_sort) {
40     $result = ewiki_db::GETALL(array("pagename"));
41   } else {
42     $result = ewiki_db::GETALL(array("lastmodified"));
43   }
44   
45   $sorted = array();
46
47   // get an array from the database
48   while ($row = $result->get(0, 0x0137, EWIKI_DB_F_TEXT)) {
49   
50       if ($c_regex && !preg_match($c_regex, $row["id"])) {
51         continue;
52       }
53       
54       if ($b_sort) { 
55       $sorted[$row["id"]] = $row["pagename"];
56       } else {
57       $sorted[$row["id"]] = $row["lastmodified"];
58       }
59   }
60   
61   #-- sort normal or reversed
62   if ($b_sortrev) {
63   asort($sorted);
64   } else {
65   // if we sort on lastmodified reverse sort
66   arsort($sorted);
67   }
68     
69   $displayed  = 0;//$displayed will count pages successfully displayed
70   
71   #-- gen output
72   $o = "";
73   foreach ($sorted as $id=>$uu) {
74   
75     $row = ewiki_db::GET($id);
76   
77     #-- require auth
78     if (EWIKI_PROTECTED_MODE && !ewiki_auth($id, $row, "view", $ring=false, $force=0)) {
79        if (EWIKI_PROTECTED_MODE_HIDING) {
80           continue;
81        } else {
82           $row["content"] = ewiki_t("FORBIDDEN");
83        }
84     }
85     
86     $text = "\n".substr($row["content"], 0, $n_len);
87     $text = str_replace("[internal://", "[  internal://", $text);
88     
89     #-- shore more link or not 
90     if ($b_more) {
91     $text .= " [...[read more | $id]]\n";
92     }
93     
94     #-- title mangling (from ewiki.php)
95     $title=$id;      
96     if ($ewiki_config["split_title"] && $may_split) {
97       $title = ewiki_split_title($title, $ewiki_config["split_title"], 0&($title!=$ewiki_title));   //Why 0&?
98     }
99     else {
100       $title = htmlentities($title);
101     }      
102     if ($pf_a = @$ewiki_plugins["title_transform"]) {
103       foreach ($pf_a as $pf) { $pf($id, $title, $go_action); }
104     }
105     
106     if($ewiki_config["wm_publishing_headers"]){
107       $text = preg_replace("/^!([^!])/m","!! \$1",$text);
108       $o .= "\n" .
109           "! [\"$title\"$id]";
110     }else{
111       $text = preg_replace("/^!!!/m","!!",$text);
112       $o .= "\n" .
113           "!!! [\"$title\"$id]";      
114     }
115     $o .=" µµ". strftime(ewiki_t("LASTCHANGED"), $row["lastmodified"])."µµ\n";
116     $o .= " $text\n";
117     
118     // add a horizontal line if wanted 
119     if ($b_hr) { 
120     $o .= "----\n";
121     }
122   
123     if (!($n_num--)) {
124        break;
125     }
126   }
127   
128   
129   #-- render requested wiki page  <-- goal !!!
130   $render_args = array(
131     "scan_links" => 1,
132     "html" => (EWIKI_ALLOW_HTML||(@$data["flags"]&EWIKI_DB_F_HTML)),
133   );
134    $o =  $ewiki_plugins["render"][0] ($o, $render_args);
135   
136   return($o);
137 }
138
139 $ewiki_plugins["mpi"]["blog"] = "ewiki_mpi_blog";
140
141 // the mpi funcion call
142 function ewiki_mpi_blog($action="html", $args, &$iii, &$s) {
143
144   global $ewiki_config;
145
146   // read parameters or use default values
147  ($id = $args["page"]) or ($id = $GLOBALS["ewiki_id"]); 
148  ($n_num = $args["line"]) or ($n_num = 20); 
149  ($n_len = $args["length"]) or ($n_len = 512);
150  ($b_hr = $args["hr"]) or ($b_hr = 0);
151  ($b_sort = $args["sort"]) or ($b_sort = 0);
152  ($b_calendar = $args["calendar"]) or ($b_calendar = 0);
153  ($b_more = $args["displaymore"]) or ($b_more = 0);
154  ($b_sortrev = $args["sort_reverse"]) or ($b_sortrev = 0);
155
156   // if we use the plugin for the calendar, quit on no  calendar pages 
157   if ( (!calendar_exists(false)) && ($b_calendar) ){
158     return;
159   }
160
161    // the output 
162    $o='<div class="text-blog">'
163     //  .'DEBUG -> '.' Line = '.$hr.' Sort = '.$sort.' Reverse = '.$b_sortrev
164       .ewiki_blog_list($n_num,$n_len,$b_sort,$b_sortrev,$b_hr,$b_more,'/^'.$id.EWIKI_NAME_SEP.'\d{8}$/')
165       . '</div>';
166
167   return($o);
168 }
169
170
171 ?>