/**
  * Discussion reply save action
  * @return \hypeJunction\DiscussionReply|false
  */
 public static function saveAction()
 {
     $guid = (int) get_input('guid');
     if (!$guid) {
         $action = 'create';
         $entity = new \hypeJunction\DiscussionReply();
         $container_guid = (int) get_input('topic_guid');
         $container = get_entity($container_guid);
     } else {
         $action = 'update';
         $entity = get_entity($guid);
         if (!$entity instanceof \hypeJunction\DiscussionReply) {
             register_error(elgg_echo('discussion:reply:error:notfound'));
             return false;
         }
         if (!$entity->canEdit()) {
             register_error(elgg_echo('discussion:reply:error:cannot_edit'));
             return false;
         }
         $container = $entity->getContainerEntity();
     }
     if (!$container instanceof \hypeJunction\Discussion || !$container->canWriteToContainer(0, 'object', 'discussion_reply')) {
         register_error(elgg_echo('discussion:reply:error:permissions'));
         return false;
     }
     $description = get_input('description');
     if (empty($description)) {
         register_error(elgg_echo('discussion:reply:missing'));
         return false;
     }
     $entity->description = $description;
     $entity->container_guid = $container->guid;
     $entity->access_id = $container->access_id;
     $result = $entity->save();
     if (!$result) {
         if ($action == 'update') {
             register_error(elgg_echo('discussion:reply:error'));
         } else {
             register_error(elgg_echo('discussion:post:failure'));
         }
     }
     if (elgg_is_active_plugin('hypeAttachments')) {
         hypeapps_attach_uploaded_files($entity, 'uploads', ['origin' => 'discussion_reply', 'container_guid' => $entity->guid, 'access_id' => $entity->access_id]);
     }
     if ($action == 'update') {
         system_message(elgg_echo('discussion:reply:edited'));
     } else {
         system_message(elgg_echo('discussion:post:success'));
         elgg_create_river_item(array('view' => 'river/object/discussion_reply/create', 'action_type' => 'reply', 'subject_guid' => elgg_get_logged_in_user_guid(), 'object_guid' => $entity->guid, 'target_guid' => $entity->container_guid));
     }
     return $entity;
 }
예제 #2
0
 /**
  * Saves discussion from form input
  * @return \hypeJunction\Discussion|false
  */
 public static function saveAction()
 {
     $guid = get_input('topic_guid');
     if (!$guid) {
         $action = 'create';
         $entity = new \hypeJunction\Discussion();
         $container_guid = get_input('container_guid');
         $container = get_entity($container_guid);
     } else {
         $action = 'update';
         $entity = get_entity($guid);
         if (!$entity instanceof \hypeJunction\Discussion || !$entity->canEdit()) {
             register_error(elgg_echo('discussion:topic:notfound'));
             return false;
         }
         $container = $entity->getContainerEntity();
     }
     if (!$container || !$container->canWriteToContainer(0, 'object', \hypeJunction\Discussion::SUBTYPE)) {
         register_error(elgg_echo('discussion:error:permissions'));
         return false;
     }
     $title = htmlspecialchars(get_input('title', '', false), ENT_QUOTES, 'UTF-8');
     $description = get_input('description');
     if (!$title || !$description) {
         register_error(elgg_echo('discussion:error:missing'));
         return false;
     }
     $entity->title = $title;
     $entity->description = $description;
     $entity->status = get_input('status', 'open');
     $entity->access_id = get_input('access_id', $container->access_id);
     $entity->container_guid = $container->guid;
     $entity->threads = (bool) get_input('threads');
     $entity->tags = string_to_tag_array(get_input('tags', ''));
     $result = $entity->save();
     if (!$result) {
         register_error(elgg_echo('discussion:error:notsaved'));
         return false;
     }
     if (elgg_is_active_plugin('hypeAttachments')) {
         hypeapps_attach_uploaded_files($entity, 'uploads', ['origin' => 'discussion', 'container_guid' => $entity->guid, 'access_id' => $entity->access_id]);
     }
     if ($action == 'update') {
         system_message(elgg_echo('discussion:topic:updated'));
     } else {
         system_message(elgg_echo('discussion:topic:created'));
         elgg_create_river_item(['view' => 'river/object/discussion/create', 'action_type' => 'create', 'subject_guid' => elgg_get_logged_in_user_guid(), 'object_guid' => $entity->guid, 'target_guid' => $entity->container_guid]);
     }
     return $entity;
 }
예제 #3
0
    $comment = new Comment();
    $comment->owner_guid = $poster->guid;
    $comment->container_guid = $entity->guid;
    $comment->access_id = $entity->access_id;
}
$comment->description = $description;
$title = htmlspecialchars(get_input('title', '', false), ENT_QUOTES, 'UTF-8');
if ($title) {
    $comment->title = $title;
}
if (!$comment->save()) {
    register_error(elgg_echo('generic_comment:failure'));
    forward(REFERER);
}
if (elgg_is_active_plugin('hypeAttachments')) {
    hypeapps_attach_uploaded_files($comment, 'uploads', ['origin' => 'comment', 'container_guid' => $comment->guid, 'access_id' => $comment->access_id]);
}
if ($new_comment) {
    if ($entity->owner_guid != $poster->guid) {
        // Send a notification to the content owner
        $recipient = $entity->getOwnerEntity();
        $language = $recipient->language;
        $messages = (new NotificationFormatter($comment, $recipient, $language))->prepare();
        notify_user($recipient->guid, $poster->guid, $messages->subject, $messages->body, array('object' => $comment, 'action' => 'create', 'summary' => $messages->summary));
    }
    // Add to river
    elgg_create_river_item(array('view' => 'river/object/comment/create', 'action_type' => 'create', 'subject_guid' => $poster->guid, 'object_guid' => $comment->guid, 'target_guid' => $entity->guid));
}
if (elgg_is_xhr()) {
    elgg_push_context('comments');
    if ($comment_guid) {