Code

Added some templates && functionality
[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         {
13                 /* Create dump of current sieve script */
14                 if(isset($_POST['Save_Copy'])){
15                         echo "Move this into Management";
16                 
17                         /* force download dialog */
18                         header("Content-type: application/tiff\n");
19                         if (preg_match('/MSIE 5.5/', $HTTP_USER_AGENT) ||
20                                         preg_match('/MSIE 6.0/', $HTTP_USER_AGENT)) {
21                                 header('Content-Disposition: filename="dump.txt"');
22                         } else {
23                                 header('Content-Disposition: attachment; filename="dump.txt"');
24                         }
25                         header("Content-transfer-encoding: binary\n");
26                         header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
27                         header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
28                         header("Cache-Control: no-cache");
29                         header("Pragma: no-cache");
30                         header("Cache-Control: post-check=0, pre-check=0");
31                         echo $this->get_sieve_script(); 
32                         exit(); 
33                 }
34         
35                 $ret = $this->dumpParseTree();
36                 return($ret);
37         }
38         
40         /* Check if there are errors, collect them and return them */
41         function check()
42         {
43                 return($this->tree_->check());
44         }
45         
47         /* Initiate parser, but use some other 
48      *  classes, that are rewritten.
49      */
50         function parse($script) 
51         {
52         $this->status_text = "incomplete";
53         $this->script_ = $script;
54         $this->tree_ = new My_Tree(@Scanner::scriptStart());
55         $this->tree_->setDumpFunc(array(&$this, 'dumpToken_'));
56         $this->scanner_ = new Scanner($this->script_);
57         $this->scanner_->setCommentFunc(array($this, 'comment_'));
59         if ($this->commands_($this->tree_->getRoot()) &&
60             $this->scanner_->nextTokenIs('script-end'))
61         {
62             return $this->success_('success');
63         }
65         return $this->status_;
66         }
68         
69         function get_sieve_script()
70         {
71                 return($this->tree_->get_sieve_script());
72         }               
74         
75         function save_object()
76         {
77                 $this->tree_->save_object();
78         }
81         /* Should be obsolete in the end. */
82         function dumpToken_(&$token)
83         {
84                 if (is_array($token))
85                 {
86                         $str = "<" . $token['text'] . "> ";
87                         foreach ($token as $k => $v)
88                         {
89                                 $str .= " $k:$v";
90                         }
91                         return $str;
92                 }
93                 return strval($token);
94         }
97         function dumpParseTree()
98         {
99                 return $this->tree_->execute();
100         }
102 ?>