function action_post($input) { global $prefs, $user; $type = $input->type->text(); $objectId = $input->objectId->pagename(); $parentId = $input->parentId->int(); $return_url = $input->return_url->url(); // Check general permissions if (!$this->isEnabled($type, $objectId)) { throw new Services_Exception(tr('Comments not allowed on this page.'), 403); } if (!$this->canPost($type, $objectId)) { throw new Services_Exception(tr('Permission denied.'), 403); } $commentslib = TikiLib::lib('comments'); if ($parentId && $prefs['feature_comments_locking'] == 'y') { $parent = $commentslib->get_comment($parentId); if ($parent['locked'] == 'y') { throw new Services_Exception(tr('Parent is locked.'), 403); } } $errors = array(); $title = trim($input->title->text()); $data = trim($input->data->wikicontent()); $contributions = array(); $anonymous_name = ''; $anonymous_email = ''; $anonymous_website = ''; if (empty($user) || $prefs['feature_comments_post_as_anonymous'] == 'y') { $anonymous_name = $input->anonymous_name->text(); $anonymous_email = $input->anonymous_email->email(); $anonymous_website = $input->anonymous_website->website(); } if ($input->post->int()) { // Validate if (empty($user)) { if (empty($anonymous_name)) { $errors['anonymous_name'] = tr('Pseudonym must be specified'); } } if (!empty($anonymous_name) && empty($anonymous_email)) { $errors['anonymous_emal'] = tr('Email must be specified'); } if ($prefs['comments_notitle'] != 'y' && empty($title)) { $errors['title'] = tr('Title is empty'); } if (empty($data)) { $errors['data'] = tr('Content is empty'); } if (empty($user) && $prefs['feature_antibot'] == 'y') { $captchalib = TikiLib::lib('captcha'); if (!$captchalib->validate($input->none())) { $errors[] = $captchalib->getErrors(); } } if ($prefs['comments_notitle'] == 'y') { $title = 'Untitled ' . TikiLib::lib('tiki')->get_long_datetime(TikiLib::lib('tikidate')->getTime()); } if (count($errors) === 0) { $message_id = ''; // By ref $threadId = $commentslib->post_new_comment("{$type}:{$objectId}", $parentId, $user, $title, $data, $message_id, isset($parent['message_id']) ? $parent['message_id'] : '', 'n', '', '', $contributions, $anonymous_name, '', $anonymous_email, $anonymous_website); $feedback = array(); if ($prefs['feature_comments_moderation'] === 'y' && !$this->canModerate($type, $objectId)) { $feedback[] = tr('Your message has been queued for approval and will be posted after a moderator approves it.'); } if ($threadId) { $this->rememberCreatedComment($threadId); if ($prefs['wiki_watch_comments'] == 'y' && $type == 'wiki page') { require_once 'lib/notifications/notificationemaillib.php'; sendCommentNotification('wiki', $objectId, $title, $data); } else { if ($type == 'article') { require_once 'lib/notifications/notificationemaillib.php'; sendCommentNotification('article', $objectId, $title, $data); } elseif ($prefs['feature_blogs'] == 'y' && $type == 'blog post') { // Blog comment mail require_once 'lib/notifications/notificationemaillib.php'; sendCommentNotification('blog', $objectId, $title, $data); } elseif ($type == 'trackeritem') { require_once 'lib/notifications/notificationemaillib.php'; sendCommentNotification('trackeritem', $objectId, $title, $data, $threadId); } } $access = TikiLib::lib('access'); if ($return_url && !$access->is_xml_http_request()) { $access->redirect($return_url, tr('Your comment was posted.')); } return array('threadId' => $threadId, 'parentId' => $parentId, 'type' => $type, 'objectId' => $objectId, 'feedback' => $feedback); } } } return array('parentId' => $parentId, 'type' => $type, 'objectId' => $objectId, 'title' => $title, 'data' => $data, 'contributions' => $contributions, 'anonymous_name' => $anonymous_name, 'anonymous_email' => $anonymous_email, 'anonymous_website' => $anonymous_website, 'errors' => $errors, 'return_url' => $return_url); }
function action_post($input) { global $prefs, $user; $type = $input->type->text(); $objectId = $input->objectId->pagename(); $parentId = $input->parentId->int(); // Check general permissions if (!$this->isEnabled($type, $objectId)) { throw new Services_Exception(tr('Comments not allowed on this page.'), 403); } if (!$this->canPost($type, $objectId)) { throw new Services_Exception(tr('Permission denied.'), 403); } $commentslib = TikiLib::lib('comments'); if ($parentId && $prefs['feature_comments_locking'] == 'y') { $parent = $commentslib->get_comment($parentId); if ($parent['locked'] == 'y') { throw new Services_Exception(tr('Parent is locked.'), 403); } } $errors = array(); $title = trim($input->title->text()); $data = trim($input->data->wikicontent()); $contributions = array(); $anonymous_name = ''; $anonymous_email = ''; $anonymous_website = ''; if (empty($user) || $prefs['feature_comments_post_as_anonymous'] == 'y') { $anonymous_name = $input->anonymous_name->text(); $anonymous_email = $input->anonymous_email->email(); $anonymous_website = $input->anonymous_website->website(); } if ($input->post->int()) { // Validate if (empty($user)) { if (empty($anonymous_name)) { $errors['anonymous_name'] = tr('Pseudonym must be specified'); } } if (!empty($anonymous_name) && empty($anonymous_email)) { $errors['anonymous_emal'] = tr('Email must be specified'); } if ($prefs['comments_notitle'] != 'y' && empty($title)) { $errors['title'] = tr('Title is empty'); } if (empty($data)) { $errors['data'] = tr('Content is empty'); } if (empty($user) && $prefs['feature_antibot'] == 'y') { $captchalib = TikiLib::lib('captcha'); if (!$captchalib->validate(array('recaptcha_challenge_field' => $input->recaptcha_challenge_field->none(), 'recaptcha_response_field' => $input->recaptcha_response_field->none(), 'captcha' => $input->captcha->none()))) { $errors[] = $captchalib->getErrors(); } } if ($prefs['comments_notitle'] == 'y') { $title = 'Untitled ' . TikiLib::lib('tiki')->get_long_datetime(TikiLib::lib('tikidate')->getTime()); } if (count($errors) === 0) { $message_id = ''; // By ref $threadId = $commentslib->post_new_comment("{$type}:{$objectId}", $parentId, $user, $title, $data, $message_id, $parent ? $parent['message_id'] : '', 'n', '', '', $contributions, $anonymous_name, '', $anonymous_email, $anonymous_website); if ($threadId) { if ($prefs['wiki_watch_comments'] == 'y' && $type == 'wiki page') { require_once 'lib/notifications/notificationemaillib.php'; sendCommentNotification('wiki', $objectId, $title, $data); } else { if ($type == 'article') { require_once 'lib/notifications/notificationemaillib.php'; sendCommentNotification('article', $objectId, $title, $data); } elseif ($type == 'trackeritem') { require_once 'lib/notifications/notificationemaillib.php'; sendCommentNotification('trackeritem', $objectId, $title, $data, $threadId); } } return array('threadId' => $threadId, 'parentId' => $parentId, 'type' => $type, 'objectId' => $objectId); } } } return array('parentId' => $parentId, 'type' => $type, 'objectId' => $objectId, 'title' => $title, 'data' => $data, 'contributions' => $contributions, 'anonymous_name' => $anonymous_name, 'anonymous_email' => $anonymous_email, 'anonymous_website' => $anonymous_website, 'errors' => $errors); }