noticeaction improvements
[statusnet:freesocial.git] / plugins / ThemeManager / classes / forms / newnotice.php
1 <?php
2
3 class NewnoticeForm extends ThemeForm {
4     protected $content   = null;
5     protected $returnto  = null;
6     protected $inreplyto = null;
7     protected $private   = null;
8     protected $charlimit = null;
9
10         protected $loopClass = 'newnotice';
11
12         protected function validate() {
13                 if (!empty($this->inreplyto)) {
14                         $this->loopClass .= ' reply';
15                 }
16
17                 return parent::validate();
18         }
19
20     protected function initialize() {
21         parent::initialize();
22
23         $this->attributes['action'] = common_local_url('newnotice');
24
25         if (empty($this->charlimit)) {
26             $this->charlimit = Notice::maxContent();
27         }
28     }
29
30     function get_list() {
31                 $legend = _m('Send a notice');
32                 $txtId  = 'newnotice';
33                 
34                 if (!empty($this->inreplyto)) {
35                         $parent = Notice::staticGet('id', $this->inreplyto);
36             $legend = sprintf(_m('Reply to %s'), $parent->getProfile()->getBestName());
37                         $txtId  = 'inreplyto-'.$this->inreplyto;
38                 }
39                 $attId = "$txtId-attach";
40                 $irtId = "$txtId-inreplyto";
41                 $retId = "$txtId-returnto";
42                 $sbmId = "$txtId-submit";
43
44                 $fieldset = 'newnotice';
45         
46                 $list = array($fieldset=>array(
47                                         array('field'=>'legend', 'content'=>$legend),
48                                         array('field'=>'textarea', 'args'=>array('name'=>'status_textarea', 'class'=>'notice_data-text','id'=>$txtId),
49                                                         'content'=>$this->content),
50                                         array('field'=>'span', 'args'=>array('class'=>'count'), 'content'=>$this->charlimit),
51                                         array('field'=>'submit', 'args'=>array('id'=>$sbmId,
52                                                         'value'=>(empty($this->inreplyto) ? _m('BUTTON', 'Send') : _m('BUTTON', 'Reply'))))
53                                 ));
54
55         if (common_config('attachments', 'uploads')) {
56                         $maxsize = common_config('attachments', 'file_quota');
57                         // if content is an array, we use 'tag' instead of 'field'!
58                         // the content array MUST contain the same kind of field-specifying arrays as we used before
59             $list[$fieldset][] = array('tag'=>'div', 'args'=>array('class'=>'attachments'), 'content'=>array(
60                                                                         array('field'=>'hidden', 'args'=>array('name'=>'MAX_FILE_SIZE', 'value'=>$maxsize)),
61                                                                         array('field'=>'file', 'args'=>array('name'=>'attach[]', 'id'=>$attId, 'multiple'=>'multiple'), 'label'=>_m('Attach a file.'))
62                                                                 ));
63         }
64         if (!empty($this->returnto)) {
65             $list[$fieldset][] = array('field'=>'hidden', 'args'=>array('name'=>'returnto', 'value'=>$this->returnto, 'id'=>$retId));
66         }
67         $list[$fieldset][] = array('field'=>'hidden', 'args'=>array('name'=>'inreplyto', 'value'=>$this->inreplyto, 'id'=>$irtId));
68         return $list;
69     }
70 }