Code

New sieve filter, not yet finished.
[gosa.git] / include / sieve / class_My_Tree.inc
1 <?php
3 class My_Tree extends Tree
4 {
5   var $dumpFn_;
6   var $dump_;
8   var $mode_stack = array();
9   var $pap              = array();
12   function dump()
13   {
14     error_reporting(E_ALL);    
15     $this->dump_ = "";
16     $this->mode_stack = array();
17     $this->pap = array();
18     $this->doDump_(0, '', true);
20     $this->dump_ ="<table width='100%'><tr><td style='background-color:#BBBBBB;border: solid 2px #FFFFFF;padding-left:20px;'>";
21     foreach($this->pap as $object){
22       if(is_object($object)){
23         $this->dump_ .= $object->execute()."<br>"; 
24       }
25     }
26     $this->dump_ .= "</td></tr></table>";
27     return $this->dump_;
28   }
31   /* This function walks through the object tree generated by the "Parse" class.
32    * All Commands will be resolved and grouped. So the Commands and their 
33    *  parameter are combined. Like "IF" and ":comparator"...
34    */  
35   function doDump_($node_id, $prefix, $last,$num = 1)
36   {
37     /* Indicates that current comman will only be valid for a single line. 
38      *  this command type will be removed from mode_stack after displaying it.
39      */
40     $rewoke_last = FALSE;
42     /* Get node */ 
43     $node = $this->nodes_[$node_id];
45     /* This closes the last mode */
46     if($node['class'] == "block-start"){
47       $tmp = array_pop($this->mode_stack);
48       $this->handle_elements($tmp);
49       $this->handle_elements(array("TYPE" => "block_start"));
50     }
52     /* This closes the last mode */
53     if($node['class'] == "block-end"){
54       $tmp = array_pop($this->mode_stack);
55       $this->handle_elements($tmp);
56       $this->handle_elements(array("TYPE" => "block_end"));
57     }
59     /* Semicolon indicates a new command */
60     if($node['class'] == "semicolon"){
61       $tmp =array_pop($this->mode_stack);
62       $this->handle_elements($tmp);
63     }
65     /* Handle comments */
66     if($node['class'] == "comment"){
67       $this->mode_stack[] = array("TYPE" => $node['class']);
68       $rewoke_last = TRUE;
69     }
71     /* Handle identifiers */
72     $identifiers = array("if","elsif","end","reject","redirect","vacation","keep","discard","comment","fileinto","require");
73     if($node['class'] == "identifier" && in_array($node['text'],$identifiers)){
74       $this->mode_stack[] = array("TYPE" => $node['text']); 
75     }
77     /* Add current node to current command stack */
78     end($this->mode_stack);
79     $key = key($this->mode_stack);
80     $this->mode_stack[$key]['ELEMENTS'][] = $node;
82     /* Remove last mode from mode stack, cause it was only valid for a single line */
83     if($rewoke_last){
84       $tmp =array_pop($this->mode_stack);
85       $this->handle_elements($tmp);
86     }
88     /* If this is a sub element, just call this for all childs */       
89     if(isset($this->childs_[$node_id])){
90       $childs = $this->childs_[$node_id];
91       for ($i=0; $i<count($childs); ++$i)
92       {
93         $c_last = false;
94         if ($i+1 == count($childs))
95         {
96           $c_last = true;
97         }
98         $this->doDump_($childs[$i], "", $num);
99       }
100     }
101   }
104   function handle_elements($data)
105   {
106     if(!isset($data['TYPE'])){
107       return;
108     }
109     $type = $data['TYPE'];
110     
111     $class_name= "sieve_".$type ;
112     if(class_exists($class_name)){
113       $this->pap[] = new $class_name($data);
114     }else{
115       echo "<font color='red'>Missing : ".$class_name."</font>"."<br>";
116     }
117   }
119 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
120 ?>