Code

Put each class in a single file.
[gosa.git] / include / sieve / class_My_Parser.inc
1 <?php
3 define("SIEVE_INDENT_TAB","  ");
5 /* This class is inherited from the original 'Parser'
6  *  class written by Heiko Hund
7  */
8 class My_Parser extends Parser 
9 {
11         function execute()
12         {
15                 /* Add Element requested */
16                 if(isset($_POST['Add_Element'])){
17                         $this->tree_->Add_Element();
18                         echo "Move this into Management";
19                 }
21                 /* Create dump of current sieve script */
22                 if(isset($_POST['Save_Copy'])){
23                         echo "Move this into Management";
24                 
25                         /* force download dialog */
26                         header("Content-type: application/tiff\n");
27                         if (preg_match('/MSIE 5.5/', $HTTP_USER_AGENT) ||
28                                         preg_match('/MSIE 6.0/', $HTTP_USER_AGENT)) {
29                                 header('Content-Disposition: filename="dump.txt"');
30                         } else {
31                                 header('Content-Disposition: attachment; filename="dump.txt"');
32                         }
33                         header("Content-transfer-encoding: binary\n");
34                         header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
35                         header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
36                         header("Cache-Control: no-cache");
37                         header("Pragma: no-cache");
38                         header("Cache-Control: post-check=0, pre-check=0");
39                         echo $this->get_sieve_script(); 
40                         exit(); 
41                 }
42         
43                 $ret = $this->dumpParseTree();
44                 return($ret);
45         }
46         
48         /* Check if there are errors, collect them and return them */
49         function check()
50         {
51                 return($this->tree_->check());
52         }
53         
55         
57         /* Initiate parser, but use some other 
58      *  classes, that are rewritten.
59      */
60         function parse($script) 
61         {
62         $this->status_text = "incomplete";
63         $this->script_ = $script;
64         $this->tree_ = new My_Tree(@Scanner::scriptStart());
65         $this->tree_->setDumpFunc(array(&$this, 'dumpToken_'));
66         $this->scanner_ = new Scanner($this->script_);
67         $this->scanner_->setCommentFunc(array($this, 'comment_'));
69         if ($this->commands_($this->tree_->getRoot()) &&
70             $this->scanner_->nextTokenIs('script-end'))
71         {
72             return $this->success_('success');
73         }
75         return $this->status_;
76         }
78         
79         function get_sieve_script()
80         {
81                 return($this->tree_->get_sieve_script());
82         }               
84         
85         function save_object()
86         {
87                 $this->tree_->save_object();
88         }
91         /* Should be obsolete in the end. */
92         function dumpToken_(&$token)
93         {
94                 if (is_array($token))
95                 {
96                         $str = "<" . $token['text'] . "> ";
97                         foreach ($token as $k => $v)
98                         {
99                                 $str .= " $k:$v";
100                         }
101                         return $str;
102                 }
103                 return strval($token);
104         }
106 ?>