aboutsummaryrefslogtreecommitdiff
path: root/mod/pages/actions
diff options
context:
space:
mode:
Diffstat (limited to 'mod/pages/actions')
-rw-r--r--mod/pages/actions/pages/edit.php125
1 files changed, 47 insertions, 78 deletions
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 @@
<?php
/**
- * Edit a page
+ * Create or edit a page
*
* @package ElggPages
*/
-// Load configuration
-global $CONFIG;
-
-elgg_set_context('pages');
-
-//boolean to select correct add to river. It will be new or edit
-$which_river = 'new';
-
-// Get group fields
+$variables = elgg_get_config('pages');
$input = array();
-foreach($CONFIG->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