From af5b59b518123a15a7182ebfe2487a9e10f67ee8 Mon Sep 17 00:00:00 2001 From: cash Date: Sat, 22 Jan 2011 16:36:30 +0000 Subject: more clean up of the pages plugin to use new HTML/CSS git-svn-id: http://code.elgg.org/elgg/trunk@7898 36083f99-b078-4883-b0ff-0f9b5a30f544 --- mod/pages/actions/pages/edit.php | 125 +++++++++++++++------------------------ 1 file changed, 47 insertions(+), 78 deletions(-) (limited to 'mod/pages/actions') diff --git a/mod/pages/actions/pages/edit.php b/mod/pages/actions/pages/edit.php index 4487c67a3..e8e7a254a 100644 --- a/mod/pages/actions/pages/edit.php +++ b/mod/pages/actions/pages/edit.php @@ -1,110 +1,79 @@ pages as $shortname => $valuetype) { - $input[$shortname] = get_input($shortname); - if ($shortname == 'title') { - $input[$shortname] = strip_tags($input[$shortname]); +foreach ($variables as $name => $type) { + $input[$name] = get_input($name); + if ($name == 'title') { + $input[$name] = strip_tags($input[$name]); + } + if ($type == 'tags') { + $input[$name] = string_to_tag_array($input[$name]); } - if ($valuetype == 'tags') - $input[$shortname] = string_to_tag_array($input[$shortname]); } -// Get parent -$parent_guid = (int)get_input('parent_guid', 0); +// Get guids +$page_guid = (int)get_input('page_guid'); +$container_guid = (int)get_input('container_guid'); +$parent_guid = (int)get_input('parent_guid'); -// New or old? -$page = NULL; -$pages_guid = (int)get_input('pages_guid'); +elgg_make_sticky_form('page'); -if ($pages_guid) { - $page = get_entity($pages_guid); - if (!$page->canEdit()) { - $page = NULL; // if we can't edit it, go no further. - } +if (!$input['title']) { + register_error(elgg_echo('pages:error:no_title')); + forward(REFERER); +} - //select river boolean to edit - $which_river = 'edit'; +if ($page_guid) { + $page = get_entity($page_guid); + if (!$page || !$page->canEdit()) { + register_error(elgg_echo('pages:error:no_save')); + forward(REFERER); + } + $new_page = false; } else { $page = new ElggObject(); - if (!$parent_guid) { - $page->subtype = 'page_top'; - } else { + if ($parent_guid) { $page->subtype = 'page'; + } else { + $page->subtype = 'page_top'; } - - // New instance, so set container_guid - $container_guid = get_input('container_guid', get_loggedin_userid()); - $page->container_guid = $container_guid; - - // cache data in session in case data from form does not validate - $_SESSION['page_description'] = $input['description']; - $_SESSION['page_tags'] = get_input('tags'); - $_SESSION['page_read_access'] = (int)get_input('access_id'); - $_SESSION['page_write_access'] = (int)get_input('write_access_id'); + $new_page = true; } -// Have we got it? Can we edit it? -if ($page instanceof ElggObject) { - // Save fields - note we always save latest description as both description and annotation - if (sizeof($input) > 0) { - foreach($input as $shortname => $value) { - $page->$shortname = $value; - } +if (sizeof($input) > 0) { + foreach ($input as $name => $value) { + $page->$name = $value; } +} - if (!$page->title) { - register_error(elgg_echo("pages:notitle")); +// need to add check to make sure user can write to container +$page->container_guid = $container_guid; - forward(REFERER); - } - - $page->access_id = (int)get_input('access_id', ACCESS_PRIVATE); - $page->write_access_id = (int)get_input('write_access_id', ACCESS_PRIVATE); +if ($parent_guid) { $page->parent_guid = $parent_guid; - $page->owner_guid = ($page->owner_guid ? $page->owner_guid : get_loggedin_userid()); - - if ($page->save()) { +} - // Now save description as an annotation - $page->annotate('page', $page->description, $page->access_id); +if ($page->save()) { - // clear cache - unset($_SESSION['page_description']); - unset($_SESSION['page_tags']); - unset($_SESSION['page_read_access']); - unset($_SESSION['page_write_access']); + elgg_clear_sticky_form('page'); - system_message(elgg_echo("pages:saved")); + // Now save description as an annotation + $page->annotate('page', $page->description, $page->access_id); - //add to river - if ($which_river == 'new') { - add_to_river('river/object/page/create','create',get_loggedin_userid(),$page->guid); - } + system_message(elgg_echo('pages:saved')); - // Forward to the user's profile - forward($page->getUrl()); - } else { - register_error(elgg_echo('pages:notsaved')); + if ($new_page) { + add_to_river('river/object/page/create', 'create', get_loggedin_userid(), $page->guid); } + forward($page->getURL()); } else { - register_error(elgg_echo("pages:noaccess")); + register_error(elgg_echo('pages:error:no_save')); + forward(REFERER); } - -// Forward to the user's profile -forward($page->getUrl()); \ No newline at end of file -- cgit v1.2.3