19
19
* along with this program; if not, write to the Free Software
20
20
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
24
* @version $Revision: 1.37 $ $Date: 2005/08/23 03:49:01 $
23
* @version $Revision: 1.42 $ $Date: 2006/01/30 22:52:14 $
26
25
* @subpackage UserInterface
27
26
* @author Bharat Mediratta <bharat@menalto.com>
47
53
/* Make sure we have permission to add a comment */
48
54
$ret = GalleryCoreApi::assertHasItemPermission($itemId, 'comment.add');
49
if ($ret->isError()) {
50
56
return array($ret->wrap(__FILE__, __LINE__), null);
59
$redirect = $status = $error = array();
56
60
if (isset($form['action']['add'])) {
61
GalleryCoreApi::requireOnce(
62
'modules/comment/classes/GalleryCommentHelper.class');
58
64
if (empty($form['subject'])) {
59
65
$error[] = 'form[error][subject][missing]';
62
67
if (empty($form['comment'])) {
63
68
$error[] = 'form[error][comment][missing]';
71
list ($ret, $useValidationPlugins) = GalleryCommentHelper::useValidationPlugins();
73
return array($ret->wrap(__FILE__, __LINE__), null);
75
if (empty($error) && $useValidationPlugins) {
76
if (isset($this->_pluginInstances)) {
77
$pluginInstances = $this->_pluginInstances;
79
list ($ret, $pluginInstances) =
80
GalleryCoreApi::getAllFactoryImplementationIds('GalleryValidationPlugin');
82
return array($ret->wrap(__FILE__, __LINE__), null);
85
foreach (array_keys($pluginInstances) as $pluginId) {
86
list ($ret, $pluginInstances[$pluginId]) =
87
GalleryCoreApi::newFactoryInstanceById('GalleryValidationPlugin',
90
return array($ret->wrap(__FILE__, __LINE__), null);
95
/* Let each plugin do its verification */
96
foreach ($pluginInstances as $plugin) {
97
list ($ret, $pluginErrors, $continue) = $plugin->performValidation($form);
99
return array($ret->wrap(__FILE__, __LINE__), null);
102
$error = array_merge($error, $pluginErrors);
66
109
if (empty($error)) {
67
110
/* Add the comment */
68
111
list ($ret, $comment) =
69
112
GalleryCoreApi::newFactoryInstance('GalleryEntity', 'GalleryComment');
70
if ($ret->isError()) {
71
114
return array($ret->wrap(__FILE__, __LINE__), null);
74
117
if (!isset($comment)) {
75
return array(GalleryStatus::error(ERROR_MISSING_OBJECT, __FILE__, __LINE__),
118
return array(GalleryCoreApi::error(ERROR_MISSING_OBJECT, __FILE__, __LINE__),
79
122
$ret = $comment->create($itemId);
80
if ($ret->isError()) {
81
return array($ret->wrap(__FILE__, __LINE__), null);
124
return array($ret->wrap(__FILE__, __LINE__), null);
127
list ($ret, $markup) =
128
GalleryCoreApi::getPluginParameter('module', 'core', 'misc.markup');
130
return array($ret->wrap(__FILE__, __LINE__), null);
132
if ($markup == 'html') {
133
/* Strip malicious content if html markup allowed */
134
$form['subject'] = GalleryUtilities::htmlSafe($form['subject'], true);
135
$form['comment'] = GalleryUtilities::htmlSafe($form['comment'], true);
84
138
$comment->setCommenterId($gallery->getActiveUserId());
140
194
* @see GalleryView::loadTemplate
142
196
function loadTemplate(&$template, &$form) {
197
GalleryCoreApi::requireOnce('modules/comment/classes/GalleryCommentHelper.class');
143
199
/* Load our item */
144
200
list ($ret, $item) = $this->_getItem();
145
if ($ret->isError()) {
146
202
return array($ret->wrap(__FILE__, __LINE__), null);
149
205
/* Make sure we have permission to add a comment */
150
206
$ret = GalleryCoreApi::assertHasItemPermission($item->getId(), 'comment.add');
151
if ($ret->isError()) {
152
208
return array($ret->wrap(__FILE__, __LINE__), null);
155
211
if ($form['formName'] != 'AddComment') {
156
212
$form['formName'] = 'AddComment';
157
$form['subject'] = '';
158
$form['comment'] = '';
213
$form['subject'] = $form['comment'] = '';
160
215
foreach (array('subject', 'comment') as $key) {
161
216
if (empty($form[$key])) {
167
$AddComment = array();
168
$AddComment['host'] = GalleryUtilities::getRemoteHostAddress();
169
$AddComment['itemId'] = $item->getId();
171
$template->setVariable('AddComment', $AddComment);
222
/* Check if we should use validation plugins for new comments */
224
list ($ret, $useValidationPlugins) = GalleryCommentHelper::useValidationPlugins();
226
return array($ret->wrap(__FILE__, __LINE__), null);
228
if ($useValidationPlugins) {
229
list ($ret, $allPluginIds) =
230
GalleryCoreApi::getAllFactoryImplementationIds('GalleryValidationPlugin');
232
return array($ret->wrap(__FILE__, __LINE__), null);
235
/* Let each plugin load its template data */
236
foreach (array_keys($allPluginIds) as $pluginId) {
237
list ($ret, $plugin) =
238
GalleryCoreApi::newFactoryInstanceById('GalleryValidationPlugin', $pluginId);
240
return array($ret->wrap(__FILE__, __LINE__), null);
242
list ($ret, $data['file'], $data['l10Domain']) = $plugin->loadTemplate($form);
244
return array($ret->wrap(__FILE__, __LINE__), null);
246
if (isset($data['file'])) {
252
$template->setVariable('AddComment',
253
array('itemId' => $item->getId(),
254
'host' => GalleryUtilities::getRemoteHostAddress(),
255
'plugins' => $plugins));
172
256
$template->setVariable('controller', 'comment.AddComment');
174
258
list($ret, $module) = GalleryCoreApi::loadPlugin('module', 'comment');
175
if ($ret->isError()) {
176
260
return array($ret->wrap(__FILE__, __LINE__), null);
179
263
$template->title($module->translate('Add Comment'));
181
return array(GalleryStatus::success(),
182
266
array('body' => 'modules/comment/templates/AddComment.tpl'));