changed git call from https to git readonly
[atutor.git] / mods / wiki / plugins / page / extractall.php
1 <?php
2 /*
3 * This plugin extracts  items from every page in the wiki database.
4 * You can view items by specific users by entering their initials in the textbox
5 * The filter supports the use of 'and' and 'or' expressions but not both.
6 * Example items.
7
8 ! ToDo Items
9
10 * Start a todo item with @@ followed by a todo item type, item types are:
11 ** @@Todo JE: Todo
12 ** @@DONE JE: DONE
13 ** @@cancelled JE: cancelled
14 ** @@dEaDlInE JE: dEaDlInE 
15 ** @@SuBjEcT SuBjEcT
16 * Case of the class names does not matter.
17 * DO NOT use a colon ":" after the class name, this may seem logical but it will cause problems for EWikiCSS
18
19 Written By: Jeffrey Engleman
20 */
21
22 $ewiki_t["en"]["EXTODOTITLE"] = "Site Wide Todo Lists"; 
23 $ewiki_t["en"]["EXTODOFOR"] = "Todo items for ";        
24 $ewiki_t["en"]["EXTODOFORALL"] = "All todo items.";     
25 $ewiki_t["en"]["EXALLCONTROLS"] = '<div id="ewiki_todofilter"><form name="input" action="liveweb.php?" method="get"><p>Enter initials: 
26   <input type="hidden" value="$controlid" name="id"><input type="text" id="q" name="q" size="2" maxlength"16"> <input type="submit"
27   value="Extract Items"><br />(Hint: For multiple users connect initials using "and" or "or")</p></form></div>';
28 $ewiki_t["en"]["EXALLERROR"] = "<p><h4>Error</h4><ul><li>Unable to complete query.  Please do not combine the 'and' and 'or' operators.</li></ul></p>";
29
30 define("EWIKI_PAGE_EXALL", "ExAllTodo");
31
32 $ewiki_plugins["page"][EWIKI_PAGE_EXALL]="ewiki_page_exall";
33
34 function ewiki_page_exall($id=0, $data=0, $action=0){
35   global $ewiki_plugins, $ewiki_config;
36   
37   //$timestart=getmicrotime();
38   $action=str_replace("all", "", strtolower($id));
39   $invalid=false;
40   
41   $initials=ewiki_get_uservar("Initials");
42   $exinitials=ewiki_get_uservar("ExtractorInitials");
43   
44   if(isset($_GET['q']) && $_GET['q']!=""){
45     if($_GET['q']!='ALL'){
46       $str_usr=str_replace(array("or", " ", "and"), array("|", "", "|"), $_GET['q']);
47       //$str_usr=$_GET['q']; //initials were entered
48       if(!(stristr($_GET['q'], "or")&& stristr($_GET['q'], "and"))){
49         if(stristr($_GET['q'], "and")){
50           $operator="and";
51         }
52         $extractFor=$_GET['q'];
53       }else {
54         $invalid=true;
55       }
56     }
57   }elseif(strlen($initials)){ 
58     $str_usr=$initials;
59     $extractFor=$str_usr;
60   }elseif(strlen($exinitials)){ 
61     $str_usr=$exinitials;
62     $extractFor=$str_usr;    
63   }else {
64     $str_usr="."; //no initials were entered
65     $o = ewiki_make_title($id, ewiki_t(strtoupper($action)."TITLE"), 2);
66   }
67
68   if(isset($extractFor)){
69     $o = ewiki_make_title($id, ewiki_t(strtoupper($action)."FOR").$extractFor, 2);
70     if(($extractFor != $exinitials)&&($extractFor != $initials)&&(strlen($extractFor)==2)){
71       ewiki_set_uservar("ExtractorInitials",$extractFor);
72     }
73   } else {
74     $o = ewiki_make_title($id, ewiki_t(strtoupper($action)."TITLE"), 2);
75   }  
76  
77   $o .= ewiki_t("EXALLCONTROLS", array("controlid"=>$id)); //prints text, textbox, and button
78   
79   $o.='<p>';
80   if(strlen($initials)){ 
81     $o.= '<a href="' . ewiki_script("", $id,array('q'=>$initials)) . '">' . ewiki_t(strtoupper($action)."FOR").$initials . "</a> ";
82   }
83   if(strlen($exinitials)&&($exinitials!=$initials)){ 
84     $o.= '<a href="' . ewiki_script("", $id,array('q'=>$exinitials) ). '">' . ewiki_t(strtoupper($action)."FOR").$exinitials . "</a> ";
85   }  
86   $o.='<a href="' . ewiki_script("", $id,array('q'=>'ALL')) . '">' . ewiki_t(strtoupper($action)."FORALL"). "</a> ".'</p>';
87
88   if($invalid){
89     return($o.ewiki_t("EXALLERROR"));
90   }
91   //define types of todo/policy items
92   $ext_types = $ewiki_config["extracttypes"][$action];
93   
94   //get data from database
95   $data = ewiki_db::GETALL(array("content", "pagename", "flags"));
96   
97   while ($content = $data->get()) {
98     $str_null=NULL;
99     
100     if (($content["flags"] & EWIKI_DB_F_TYPE) == EWIKI_DB_F_TEXT) {
101       //code hijacked from action_extracttodo and modified
102       preg_match_all("/^([;:#\*\- ]*)((@@(".implode("|",$ext_types).")) ((".$str_usr.")+.*)(:.*))$/im", $content["content"], $matches);
103
104       if(!empty($matches[0])){
105         $extractedContent=NULL;
106         for($index=0;$index<sizeof($matches[0]);$index++){
107           //extract each todo/policy item
108           if($operator=="and"){
109             $all=true;
110             $a_users=explode("|", $str_usr);
111             foreach($a_users as $str_user){
112               if(!stristr($matches[5][$index],$str_user)){
113                 $all=false;
114               }
115             }
116             if(!$all){
117               continue;                
118             }
119           }
120           //security layer
121           if (EWIKI_PROTECTED_MODE && EWIKI_PROTECTED_MODE_HIDING && !ewiki_auth($content["id"], $str_null, $action)) {
122             continue; //skip rest of loop and start from beginning
123           }
124           $extractedContent.="*".$matches[2][$index]."@@\n";              
125         }
126         if($extractedContent!=NULL){
127           $o.=$ewiki_plugins["render"][0]("!!!".ewiki_t(strtoupper($action)."FROM")."[".$content["id"]."]");
128           $o .= "<div class='ewiki_page_todolist'>".$ewiki_plugins["render"][0] ( $extractedContent , 1,
129           EWIKI_ALLOW_HTML || (@$content["flags"]&EWIKI_DB_F_HTML) )."</div>";
130         }
131       }
132     }
133   }
134
135   $o.=$ewiki_plugins["render"][0](ewiki_t(strtoupper($action)."POSTSCRIPT"));
136   /*$timeend=getmicrotime();
137   $o.="time: ".($timeend-$timestart);*/
138   return($o);
139 }
140
141
142 ?>