Code

Updated function.inc
[gosa.git] / include / sieve / class_sieveElement_Comment.inc
1 <?php
3 /* Sieve comment tag */
4 class sieve_comment 
5 {
6   var $data = "";
7   var $object_id= -1;
8   var $small  = TRUE;
10   function get_sieve_script_part()
11   {
12     $str = "\n/*".$this->data."*/";
13     return($str);
14   } 
15     
16   function sieve_comment($data,$object_id)
17   {
18     $this->object_id = $object_id;
20     if($data == NULL){
21       $data = array('ELEMENTS' => array(array('class' => "quoted-string" ,"text" => "/*"._("Your comment here")."*/")));
22     }
24     foreach($data['ELEMENTS'] as $node){
26       $text = $node['text'];
27   
28       /* Convert \t to spaces  */ 
29       $text = preg_replace("#\t#","    ",$text);
30       
31       /* Remove comment indicator '#' but keep spaces */
32       $text = preg_replace("/^([ ]*)\#/","\\1",$text);
33      
34       /* Remove comment indicator '/ *' */ 
35       $text = preg_replace("#\/\*#","",$text);
36       
37       /* Remove comment indicator '* /' */ 
38       $text = preg_replace("#\*\/#","",$text);
40       $this->data .= $text."\n";
41     }
42     $this->data = rtrim($this->data)."\n";
43   }
45   function check()
46   {
47     return(array())  ;
48   }
50   function save_object()
51   {
52     if(isset($_POST['comment_'.$this->object_id])){
53       $cm = stripslashes( $_POST['comment_'.$this->object_id]);
54       $cm = preg_replace("/\*\//","* /",$cm);
55       $this->data = $cm;
56     }
57   
58     if(isset($_POST['toggle_small_'.$this->object_id])){
59       $this->small = !$this->small;
60     }
61   }
63   function execute()
64   {
65     $smarty = get_smarty();
66     $smarty->assign("ID", $this->object_id);
67     $smarty->assign("Small", $this->small);
68     $object_container = $smarty->fetch(get_template_path("templates/object_container.tpl",TRUE,dirname(__FILE__)));
69     $Comment = $this->data;
71     if($this->small){
72       $Comment = nl2br(preg_replace("/ /","&nbsp;",$Comment));
73     }
74  
75     /* Create html object */ 
76     $smarty->assign("Comment",$Comment);
77     $smarty->assign("ID",$this->object_id);
78     $object = $smarty->fetch(get_template_path("templates/element_comment.tpl",TRUE,dirname(__FILE__)));    
79     $str = preg_replace("/%%OBJECT_CONTENT%%/",addcslashes($object,"\\"),$object_container);
80     return($str);
81   }
82 }
83 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
84 ?>