XOOPS  2.6.0
comment.php
Go to the documentation of this file.
1 <?php
2 /*
3  You may not change or alter any portion of this comment or credits
4  of supporting developers from this source code or any supporting source code
5  which is considered copyrighted (c) material of the original comment or credit authors.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10  */
11 
13 
23 {
27  public function __construct(CommentsComment $obj)
28  {
31  $module = $xoops->getModuleById($obj->getVar('modid'));
32  if (!is_object($module)) {
34  }
35  $dirname = $module->getVar('dirname');
36 
37  // create form
38  if ($xoops->isAdminSide) {
39  $url = $helper->url("admin/comment_post.php");
40  } else {
41  $url = $helper->url("comment_post.php");
42  }
43  parent::__construct(_MD_COMMENTS_POSTCOMMENT, "commentform", $url, "post", true);
44 
45  switch ($xoops->getModuleConfig('com_rule', $dirname)) {
46  case COMMENTS_APPROVEALL:
47  $rule_text = _MD_COMMENTS_COMAPPROVEALL;
48  break;
49  case COMMENTS_APPROVEUSER:
50  $rule_text = _MD_COMMENTS_COMAPPROVEUSER;
51  break;
52  case COMMENTS_APPROVEADMIN:
53  default:
54  $rule_text = _MD_COMMENTS_COMAPPROVEADMIN;
55  break;
56  }
57  $this->addElement(new Xoops\Form\Label(_MD_COMMENTS_COMRULES, $rule_text));
58 
59  $this->addElement(new Xoops\Form\Text(_MD_COMMENTS_TITLE, 'com_title', 50, 255, $obj->getVar('title', 'e')), true);
60  $icons_radio = new Xoops\Form\Radio(XoopsLocale::MESSAGE_ICON, 'com_icon', $obj->getVar('icon', 'e'));
61  $subject_icons = XoopsLists::getSubjectsList();
62  foreach ($subject_icons as $iconfile) {
63  $icons_radio->addOption($iconfile, '<img src="' . \XoopsBaseConfig::get('url') . '/images/subject/' . $iconfile . '" alt="" />');
64  }
65  $this->addElement($icons_radio);
66  // editor
67  $editor = $helper->getConfig('com_editor');
68  if (class_exists('Xoops\Form\Editor')) {
69  $configs = array(
70  'name' => 'com_text',
71  'value' => $obj->getVar('text', 'e'),
72  'rows' => 25,
73  'cols' => 90,
74  'width' => '100%',
75  'height' => '400px',
76  'editor' => $editor
77  );
78  $this->addElement(new Xoops\Form\Editor(_MD_COMMENTS_MESSAGE, 'com_text', $configs, false, $onfailure = 'textarea'));
79  } else {
80  $this->addElement(new Xoops\Form\DhtmlTextArea(_MD_COMMENTS_MESSAGE, 'com_text', $obj->getVar('text', 'e'), 10, 50), true);
81  }
82  $option_tray = new Xoops\Form\ElementTray(XoopsLocale::OPTIONS, '<br />');
83  $button_tray = new Xoops\Form\ElementTray('', '&nbsp;');
84 
85  if ($xoops->isUser()) {
86  if ($xoops->getModuleConfig('com_anonpost', $dirname)) {
87  $noname = $obj->getVar('noname', 'e') ? 1 : 0;
88  $noname_checkbox = new Xoops\Form\Checkbox('', 'com_noname', $noname);
89  $noname_checkbox->addOption(1, XoopsLocale::POST_ANONYMOUSLY);
90  $option_tray->addElement($noname_checkbox);
91  }
92  if (false != $xoops->user->isAdmin($obj->getVar('modid'))) {
93  // show status change box when editing (comment id is not empty)
94  if ($obj->getVar('id', 'e')) {
95  $status_select = new Xoops\Form\Select(_MD_COMMENTS_STATUS, 'com_status', $obj->getVar('status', 'e'));
96  $status_select->addOptionArray(array(
97  COMMENTS_PENDING => _MD_COMMENTS_PENDING,
98  COMMENTS_ACTIVE => _MD_COMMENTS_ACTIVE,
99  COMMENTS_HIDDEN => _MD_COMMENTS_HIDDEN
100  ));
101  $this->addElement($status_select);
102  $button_tray->addElement(new Xoops\Form\Button('', 'com_dodelete', XoopsLocale::A_DELETE, 'submit'));
103  }
104  if (isset($editor) && in_array($editor, array('textarea', 'dhtmltextarea'))) {
105  $html_checkbox = new Xoops\Form\Checkbox('', 'com_dohtml', $obj->getVar('dohtml', 'e'));
106  $html_checkbox->addOption(1, _MD_COMMENTS_DOHTML);
107  $option_tray->addElement($html_checkbox);
108  }
109  }
110  }
111  if (isset($editor) && in_array($editor, array('textarea', 'dhtmltextarea'))) {
112  //Yeah, what?
113  }
114  $smiley_checkbox = new Xoops\Form\Checkbox('', 'com_dosmiley', $obj->getVar('domsiley', 'e'));
115  $smiley_checkbox->addOption(1, _MD_COMMENTS_DOSMILEY);
116  $option_tray->addElement($smiley_checkbox);
117  $xcode_checkbox = new Xoops\Form\Checkbox('', 'com_doxcode', $obj->getVar('doxcode', 'e'));
118  $xcode_checkbox->addOption(1, _MD_COMMENTS_DOXCODE);
119  $option_tray->addElement($xcode_checkbox);
120  if (isset($editor) && in_array($editor, array('textarea', 'dhtmltextarea'))) {
121  $br_checkbox = new Xoops\Form\Checkbox('', 'com_dobr', $obj->getVar('dobr', 'e'));
122  $br_checkbox->addOption(1, _MD_COMMENTS_DOAUTOWRAP);
123  $option_tray->addElement($br_checkbox);
124  } else {
125  $this->addElement(new Xoops\Form\Hidden('com_dohtml', 1));
126  $this->addElement(new Xoops\Form\Hidden('com_dobr', 0));
127  }
128  $this->addElement($option_tray);
129  if (!$xoops->isUser()) {
130  $this->addElement(new Xoops\Form\Captcha());
131  }
132  $this->addElement(new Xoops\Form\Hidden('com_modid', $obj->getVar('modid', 'e')));
133  $this->addElement(new Xoops\Form\Hidden('com_pid', $obj->getVar('pid', 'e')));
134  $this->addElement(new Xoops\Form\Hidden('com_rootid', $obj->getVar('rootid', 'e')));
135  $this->addElement(new Xoops\Form\Hidden('com_id', $obj->getVar('id', 'e')));
136  $this->addElement(new Xoops\Form\Hidden('com_itemid', $obj->getVar('itemid', 'e')));
137  $this->addElement(new Xoops\Form\Hidden('com_order', Request::getInt('com_order', $helper->getUserConfig('com_order'))));
138  $this->addElement(new Xoops\Form\Hidden('com_mode', Request::getString('com_mode', $helper->getUserConfig('com_mode'))));
139 
140  // add module specific extra params
141  if (!$xoops->isAdminSide) {
142  /* @var $plugin CommentsPluginInterface */
143  $plugin = \Xoops\Module\Plugin::getPlugin($dirname, 'comments');
144  if (is_array($extraParams = $plugin->extraParams())) {
146  foreach ($extraParams as $extra_param) {
147  // This routine is included from forms accessed via both GET and POST
148  if (isset($_POST[$extra_param])) {
149  $hidden_value = $myts->stripSlashesGPC($_POST[$extra_param]);
150  } else {
151  if (isset($_GET[$extra_param])) {
152  $hidden_value = $myts->stripSlashesGPC($_GET[$extra_param]);
153  } else {
154  $hidden_value = '';
155  }
156  }
157  $this->addElement(new Xoops\Form\Hidden($extra_param, $hidden_value));
158  }
159  }
160  }
161  $button_tray->addElement(new Xoops\Form\Button('', 'com_dopreview', XoopsLocale::A_PREVIEW, 'submit'));
162  $button_tray->addElement(new Xoops\Form\Button('', 'com_dopost', _MD_COMMENTS_POSTCOMMENT, 'submit'));
163  $this->addElement($button_tray);
164  return $this;
165  }
166 }
const _MD_COMMENTS_DOSMILEY
Definition: main.php:21
const OPTIONS
Definition: en_US.php:888
static getInstance()
Definition: Xoops.php:160
addElement(Element $formElement, $required=false)
Definition: Form.php:206
static getInstance()
Definition: helper.php:46
const _MD_COMMENTS_ACTIVE
Definition: main.php:28
const _MD_COMMENTS_DOAUTOWRAP
Definition: main.php:23
const _MD_COMMENTS_PENDING
Definition: main.php:26
const _MD_COMMENTS_COMAPPROVEADMIN
Definition: main.php:53
const _MD_COMMENTS_DOHTML
Definition: main.php:22
const MESSAGE_ICON
Definition: en_US.php:836
const _MD_COMMENTS_MESSAGE
Definition: main.php:20
const _MD_COMMENTS_TITLE
Definition: main.php:19
const _MD_COMMENTS_DOXCODE
Definition: main.php:24
getVar($key, $format= 's')
const POST_ANONYMOUSLY
Definition: en_US.php:908
addOptionArray($options)
Definition: Select.php:129
$xoops
Definition: admin.php:25
const _MD_COMMENTS_HIDDEN
Definition: main.php:27
const _MD_COMMENTS_POSTCOMMENT
Definition: main.php:30
addOption($value, $name= '')
Definition: Checkbox.php:77
static get($name)
const _MD_COMMENTS_COMAPPROVEUSER
Definition: main.php:52
const _MD_COMMENTS_COMRULES
Definition: main.php:50
$module
Definition: main.php:52
const A_PREVIEW
Definition: en_US.php:109
$configs
Definition: config.php:27
const E_NO_ACCESS_PERMISSION
Definition: en_US.php:351
__construct(CommentsComment $obj)
Definition: comment.php:27
const _MD_COMMENTS_COMAPPROVEALL
Definition: main.php:51
$helper
$url
Definition: register.php:72
$button_tray
Definition: xoops_code.php:26
$dirname
Definition: backend.php:38
const A_DELETE
Definition: en_US.php:89
$myts
Definition: edituser.php:38
const _MD_COMMENTS_STATUS
Definition: main.php:29
$editor