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 }
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'];
28 /* Convert \t to spaces */
29 $text = preg_replace("#\t#"," ",$text);
31 /* Remove comment indicator '#' but keep spaces */
32 $text = preg_replace("/^([ ]*)\#/","\\1",$text);
34 /* Remove comment indicator '/ *' */
35 $text = preg_replace("#\/\*#","",$text);
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 $this->data = $cm;
55 }
57 if(isset($_POST['toggle_small_'.$this->object_id])){
58 $this->small = !$this->small;
59 }
60 }
62 function execute()
63 {
64 $smarty = get_smarty();
65 $smarty->assign("ID", $this->object_id);
66 $smarty->assign("Small", $this->small);
67 $object_container = $smarty->fetch(get_template_path("templates/object_container.tpl",TRUE,dirname(__FILE__)));
68 $Comment = $this->data;
70 if($this->small){
71 $Comment = nl2br(preg_replace("/ /"," ",$Comment));
72 }
74 /* Create html object */
75 $smarty->assign("Comment",$Comment);
76 $smarty->assign("ID",$this->object_id);
77 $object = $smarty->fetch(get_template_path("templates/element_comment.tpl",TRUE,dirname(__FILE__)));
78 $str = preg_replace("/%%OBJECT_CONTENT%%/",$object,$object_container);
79 return($str);
80 }
81 }
82 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
83 ?>