/** * Edit or add a discussion topic * * @param string $type 'add' or 'edit' * @param int $guid GUID of group or topic */ function discussion_handle_edit_page($type, $guid) { elgg_gatekeeper(); if ($type == 'add') { $group = get_entity($guid); if (!elgg_instanceof($group, 'group')) { register_error(elgg_echo('group:notfound')); forward(); } // make sure user has permissions to add a topic to container if (!$group->canWriteToContainer(0, 'object', 'groupforumtopic')) { register_error(elgg_echo('groups:permissions:error')); forward($group->getURL()); } $title = elgg_echo('groups:addtopic'); elgg_push_breadcrumb($group->name, "discussion/owner/{$group->guid}"); elgg_push_breadcrumb($title); $body_vars = discussion_prepare_form_vars(); $content = elgg_view_form('discussion/save', array(), $body_vars); } else { $topic = get_entity($guid); if (!elgg_instanceof($topic, 'object', 'groupforumtopic') || !$topic->canEdit()) { register_error(elgg_echo('discussion:topic:notfound')); forward(); } $group = $topic->getContainerEntity(); if (!elgg_instanceof($group, 'group')) { register_error(elgg_echo('group:notfound')); forward(); } $title = elgg_echo('groups:edittopic'); elgg_push_breadcrumb($group->name, "discussion/owner/{$group->guid}"); elgg_push_breadcrumb($topic->title, $topic->getURL()); elgg_push_breadcrumb($title); $body_vars = discussion_prepare_form_vars($topic); $content = elgg_view_form('discussion/save', array(), $body_vars); } $params = array('content' => $content, 'title' => $title, 'sidebar' => elgg_view('discussion/sidebar/edit'), 'filter' => ''); $body = elgg_view_layout('content', $params); echo elgg_view_page($title, $body); }
<?php elgg_gatekeeper(); $guid = elgg_extract('guid', $vars); elgg_entity_gatekeeper($guid); elgg_group_gatekeeper(true, $guid); $container = get_entity($guid); // Make sure user has permissions to add a topic to container if (!$container->canWriteToContainer(0, 'object', 'discussion')) { register_error(elgg_echo('actionunauthorized')); forward(REFERER); } $title = elgg_echo('discussion:addtopic'); elgg_push_breadcrumb($container->getDisplayName(), "discussion/owner/{$container->guid}"); elgg_push_breadcrumb($title); $body_vars = discussion_prepare_form_vars(); $content = elgg_view_form('discussion/save', array(), $body_vars); $params = array('content' => $content, 'title' => $title, 'sidebar' => elgg_view('discussion/sidebar/edit'), 'filter' => ''); $body = elgg_view_layout('content', $params); echo elgg_view_page($title, $body);
<?php elgg_gatekeeper(); $guid = elgg_extract('guid', $vars); $topic = get_entity($guid); if (!elgg_instanceof($topic, 'object', 'discussion') || !$topic->canEdit()) { register_error(elgg_echo('discussion:topic:notfound')); forward(); } $container = $topic->getContainerEntity(); $title = elgg_echo('discussion:topic:edit'); elgg_push_breadcrumb($container->getDisplayName(), "discussion/owner/{$container->guid}"); elgg_push_breadcrumb($topic->title, $topic->getURL()); elgg_push_breadcrumb($title); $body_vars = discussion_prepare_form_vars($topic); $content = elgg_view_form('discussion/save', array(), $body_vars); $params = array('content' => $content, 'title' => $title, 'sidebar' => elgg_view('discussion/sidebar/edit'), 'filter' => ''); $body = elgg_view_layout('content', $params); echo elgg_view_page($title, $body);