c846609f0d041e1b8b52845a510b58fdc845cc95
[atutor.git] / mods / wiki / plugins / action / extract.php
1 <?php
2
3 /*
4 * This plugin extracts todo items(@@TODO, @@DONE, @@CANCELLED ) from the 
5 * page it is run on.  A change to ewiki_control_links submitted with 
6 * this plugin adds a link back to the 'normal' view.
7
8 * This plugin is designed to work with the EWikiCSS plugins but they are
9 * not necessary.
10 * Load this plugin _after_ the core ewiki.php script.
11 *
12 * Defining a new set of $ewiki_config["extracttypes"] will allow you to 
13 * extract other one line items once an $ewiki_plugins["action"]["exXXXX"]
14 * action is defined.
15 *
16 * See http://erfurtwiki.sourceforge.net/?id=TodoExtractorPlugin for more 
17 * details.
18
19 * AndyFundinger(Andy@burgiss.com)
20
21 * Add this text to your WikiMarkup page to explain this plugin to your users:
22
23 ! ToDo Items
24
25 * Start a todo item with @@ followed by a todo item type, item types are:
26 ** @@Todo AF: Todo
27 ** @@DONE AF: DONE
28 ** @@cancelled AF: cancelled
29 ** @@dEaDlInE AF: dEaDlInE 
30 ** @@SuBjEcT SuBjEcT
31 * Case of the class names does not matter.
32 * DO NOT use a colon ":" after the class name, this may seem logical but it will cause problems for EWikiCSS
33 * The ErfurtWiki:ToDoExtractorPlugin will extract todos and headlines from pages on which it is used.
34 * See our ToDoListConvention for more information and guidelines.
35
36 */
37
38  $ewiki_t["en"]["EXTODOFROM"] = "Todos extracted from ";                
39  $ewiki_t["en"]["EXTTODO"] = "Extract todo List";               
40  $ewiki_t["en"]["VIEWCOMPL"] = "View complete page";            
41  $ewiki_t["en"]["EXTODOPOSTSCRIPT"] = "\n\nplease follow our [ToDoListConvention]";             
42  $ewiki_t["de"]["EXTODOFROM"] = "ToDos aus ";
43  $ewiki_t["de"]["EXTTODO"] = "Zeige ToDo-Liste";
44  $ewiki_t["de"]["VIEWCOMPL"] = "Zeige komplette Seite";
45  $ewiki_t["de"]["EXTODOPOSTSCRIPT"] = "\n\nBitte folge unserer [ToDoListConvention]";
46   
47  $ewiki_plugins["action"]["extodo"] = "ewiki_extract";
48  $ewiki_config["action_links"]["extodo"]=$ewiki_config["action_links"]["view"];
49  $ewiki_config["action_links"]["extodo"]["view"] = ewiki_t("VIEWCOMPL");
50  $ewiki_config["action_links"]["view"]["extodo"] = ewiki_t("EXTTODO");
51
52  $ewiki_config["extracttypes"]["extodo"]=array("TODO","DONE","CANCELLED","SUBJECT","DEADLINE");
53
54  function ewiki_extract($id, $data, $action){ 
55     global $ewiki_links,$ewiki_config, $ewiki_plugins, $ewiki_ring, $ewiki_title;
56  
57     $extracttypes = $ewiki_config["extracttypes"][$action];
58  
59     $o = ewiki_make_title($id, ewiki_t(strtoupper($action)."FROM").$ewiki_title, 2, $action, "", "_MAY_SPLIT=1");
60  
61                                 //ignore any number of list markup tags in front of an @@{todotype},
62                                 //extract only the @@, the types, and their message                             
63                                         //or                            
64                                 //extract any header line                                                       
65                                         //1 2         3  4-Class                      5     6   
66         preg_match_all("/^(([-;:#\* ]*)(@@(".implode("|",$extracttypes).")(.*))|(!+.*))$/im",$data["content"],$matches);
67         for($index=0;$index<sizeof($matches[0]);$index++){
68                 //a line will be either header or todo, concatenate the two sub expressions 
69                 $extractedContent.=$matches[3][$index].$matches[6][$index]."\n\n";
70         }
71         
72         //Render extracted lines as a wiki page, this code extracted from ewiki_page
73                 
74       #-- render requested wiki page  <-- goal !!!
75       $o .= "<div class='ewiki_page_todolist'>".$ewiki_plugins["render"][0] ( $extractedContent.ewiki_t(strtoupper($action)."POSTSCRIPT") , 1,
76             EWIKI_ALLOW_HTML || (@$data["flags"]&EWIKI_DB_F_HTML) )."</div>";
77
78       #-- control line + other per-page info stuff
79       if ($pf_a = $ewiki_plugins["view_append"]) {
80          ksort($pf_a);
81          foreach ($pf_a as $n => $pf) { 
82                         
83                         $o .= $pf($id, $data, $action); 
84                 }
85       }
86       if ($pf_a = $ewiki_plugins["view_final"]) {
87          ksort($pf_a);
88          foreach ($pf_a as $n => $pf) { 
89                         if(!preg_match('/_title/',$pf)){
90                                 $pf($o, $id, $data, $action); 
91                         }
92                 }
93       }
94
95     return($o);
96  }
97
98
99 ?>