Code

Udpated Comments
[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     return($this->data."\n");
13   } 
14     
15   function sieve_comment($data,$object_id)
16   {
17     $this->object_id = $object_id;
19     if($data == NULL){
20       $data = array('ELEMENTS' => array(array('class' => "quoted-string" ,"text" => "/*"._("Your comment here")."*/")));
21     }
23     foreach($data['ELEMENTS'] as $node){
24        $this->data .= $node['text'];
25     }
26   }
28   function check()
29   {
30     return(array())  ;
31   }
33   function save_object()
34   {
35     if(isset($_POST['comment_'.$this->object_id])){
36       $cm = stripslashes( $_POST['comment_'.$this->object_id]);
37       $this->data = "/*".$cm."*/";
38     }
39   
40     if(isset($_POST['toggle_small_'.$this->object_id])){
41       $this->small = !$this->small;
42     }
43   }
45   function execute()
46   {
47     $smarty = get_smarty();
48     $smarty->assign("ID", $this->object_id);
49     $smarty->assign("Small", $this->small);
50     $object_container = $smarty->fetch(get_template_path("templates/object_container.tpl",TRUE,dirname(__FILE__)));
51     $Comment = $this->data;
53     /* Remove comment tags */
54     if(preg_match("/^#/",$Comment)){
55       $Comment = preg_replace("/^#/","",$Comment);
56     }elseif(preg_match("#\/\*#",$Comment)){
57       $Comment = preg_replace("#^\/\*#","",$Comment);
58       $Comment = preg_replace("#\*\/$#","",$Comment);
59     }
61     if($this->small){
62       $Comment = nl2br($Comment);
63     }
64  
65     /* Create html object */ 
66     $smarty = get_smarty();
67     $smarty->assign("Comment",$Comment);
68     $smarty->assign("ID",$this->object_id);
69     $object = $smarty->fetch(get_template_path("templates/element_comment.tpl",TRUE,dirname(__FILE__)));    
70     $str = preg_replace("/%%OBJECT_CONTENT%%/",$object,$object_container);
71     return($str);
72   }
73 }
74 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
75 ?>