aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mod/pages/actions/pages/edit.php25
-rw-r--r--mod/pages/languages/en.php3
-rw-r--r--mod/pages/lib/pages.php53
-rw-r--r--mod/pages/start.php1
-rw-r--r--mod/pages/views/default/forms/pages/edit.php7
-rw-r--r--mod/pages/views/default/input/parent.php37
6 files changed, 110 insertions, 16 deletions
diff --git a/mod/pages/actions/pages/edit.php b/mod/pages/actions/pages/edit.php
index fe5754d76..29fbf022b 100644
--- a/mod/pages/actions/pages/edit.php
+++ b/mod/pages/actions/pages/edit.php
@@ -60,6 +60,9 @@ if (sizeof($input) > 0) {
if (($name == 'access_id' || $name == 'write_access_id') && !$can_change_access) {
continue;
}
+ if ($name == 'parent_guid') {
+ continue;
+ }
$page->$name = $value;
}
@@ -68,7 +71,27 @@ if (sizeof($input) > 0) {
// need to add check to make sure user can write to container
$page->container_guid = $container_guid;
-if ($parent_guid) {
+if ($parent_guid && $parent_guid != $page_guid) {
+ // Check if parent isn't below of the page in the tree
+ if ($page_guid) {
+ $tree_page = get_entity($parent_guid);
+ while ($tree_page->parent_guid > 0 && $page_guid != $tree_page->guid) {
+ $tree_page = get_entity($tree_page->parent_guid);
+ }
+ // If is below, bring all child elements forward
+ if ($page_guid == $tree_page->guid) {
+ $previous_parent = $page->parent_guid;
+ $children = elgg_get_entities_from_metadata(array(
+ 'metadata_name' => 'parent_guid',
+ 'metadata_value' => $page->getGUID()
+ ));
+ if ($children) {
+ foreach ($children as $child) {
+ $child->parent_guid = $previous_parent;
+ }
+ }
+ }
+ }
$page->parent_guid = $parent_guid;
}
diff --git a/mod/pages/languages/en.php b/mod/pages/languages/en.php
index eb9d22708..930676b3e 100644
--- a/mod/pages/languages/en.php
+++ b/mod/pages/languages/en.php
@@ -61,6 +61,7 @@ View and comment on the new page:
'pages:title' => 'Page title',
'pages:description' => 'Page text',
'pages:tags' => 'Tags',
+ 'pages:parent_guid' => 'Parent page',
'pages:access_id' => 'Read access',
'pages:write_access_id' => 'Write access',
@@ -110,4 +111,4 @@ View and comment on the new page:
'pages:backtoparent' => "Back to '%s'",
);
-add_translation("en", $english); \ No newline at end of file
+add_translation("en", $english);
diff --git a/mod/pages/lib/pages.php b/mod/pages/lib/pages.php
index 9a9ba12e9..afe42b68f 100644
--- a/mod/pages/lib/pages.php
+++ b/mod/pages/lib/pages.php
@@ -65,11 +65,11 @@ function pages_prepare_parent_breadcrumbs($page) {
}
/**
- * Register the navigation menu
+ * Produce the navigation tree
*
* @param ElggEntity $container Container entity for the pages
*/
-function pages_register_navigation_tree($container) {
+function pages_get_navigation_tree($container) {
if (!$container) {
return;
}
@@ -84,13 +84,18 @@ function pages_register_navigation_tree($container) {
if (!$top_pages) {
return;
}
+
+ $tree = array();
+ $depths = array();
foreach ($top_pages as $page) {
- elgg_register_menu_item('pages_nav', array(
- 'name' => $page->getGUID(),
- 'text' => $page->title,
- 'href' => $page->getURL(),
- ));
+ $tree[] = array(
+ 'guid' => $page->getGUID(),
+ 'title' => $page->title,
+ 'url' => $page->getURL(),
+ 'depth' => 0,
+ );
+ $depths[$page->guid] = 0;
$stack = array();
array_push($stack, $page);
@@ -106,15 +111,37 @@ function pages_register_navigation_tree($container) {
if ($children) {
foreach ($children as $child) {
- elgg_register_menu_item('pages_nav', array(
- 'name' => $child->getGUID(),
- 'text' => $child->title,
- 'href' => $child->getURL(),
- 'parent_name' => $parent->getGUID(),
- ));
+ $tree[] = array(
+ 'guid' => $child->getGUID(),
+ 'title' => $child->title,
+ 'url' => $child->getURL(),
+ 'parent_guid' => $parent->getGUID(),
+ 'depth' => $depths[$parent->guid] + 1,
+ );
+ $depths[$child->guid] = $depths[$parent->guid] + 1;
array_push($stack, $child);
}
}
}
}
+ return $tree;
+}
+
+/**
+ * Register the navigation menu
+ *
+ * @param ElggEntity $container Container entity for the pages
+ */
+function pages_register_navigation_tree($container) {
+ $pages = pages_get_navigation_tree($container);
+ if ($pages) {
+ foreach ($pages as $page) {
+ elgg_register_menu_item('pages_nav', array(
+ 'name' => $page['guid'],
+ 'text' => $page['title'],
+ 'href' => $page['url'],
+ 'parent_name' => $page['parent_guid'],
+ ));
+ }
+ }
}
diff --git a/mod/pages/start.php b/mod/pages/start.php
index 6b0ad38b0..6d974f122 100644
--- a/mod/pages/start.php
+++ b/mod/pages/start.php
@@ -63,6 +63,7 @@ function pages_init() {
'title' => 'text',
'description' => 'longtext',
'tags' => 'tags',
+ 'parent_guid' => 'parent',
'access_id' => 'access',
'write_access_id' => 'write_access',
));
diff --git a/mod/pages/views/default/forms/pages/edit.php b/mod/pages/views/default/forms/pages/edit.php
index 9469f5eb9..653a7ee47 100644
--- a/mod/pages/views/default/forms/pages/edit.php
+++ b/mod/pages/views/default/forms/pages/edit.php
@@ -18,6 +18,10 @@ foreach ($variables as $name => $type) {
if (($type == 'access' || $type == 'write_access') && !$can_change_access) {
continue;
}
+ // don't show parent picker input for top or new pages.
+ if ($name == 'parent_guid' && (!$vars['parent_guid'] || !$vars['guid'])) {
+ continue;
+ }
?>
<div>
<label><?php echo elgg_echo("pages:$name") ?></label>
@@ -29,6 +33,7 @@ foreach ($variables as $name => $type) {
echo elgg_view("input/$type", array(
'name' => $name,
'value' => $vars[$name],
+ 'entity' => ($name == 'parent_guid') ? $vars['entity'] : null,
));
?>
</div>
@@ -52,7 +57,7 @@ echo elgg_view('input/hidden', array(
'name' => 'container_guid',
'value' => $vars['container_guid'],
));
-if ($vars['parent_guid']) {
+if (!$vars['guid']) {
echo elgg_view('input/hidden', array(
'name' => 'parent_guid',
'value' => $vars['parent_guid'],
diff --git a/mod/pages/views/default/input/parent.php b/mod/pages/views/default/input/parent.php
new file mode 100644
index 000000000..f354129fe
--- /dev/null
+++ b/mod/pages/views/default/input/parent.php
@@ -0,0 +1,37 @@
+<?php
+/**
+ * Parent picker
+ *
+ * @uses $vars['value'] The current value, if any
+ * @uses $vars['options_values']
+ * @uses $vars['name'] The name of the input field
+ * @uses $vars['entity'] Optional. The child entity (uses container_guid)
+ */
+
+elgg_load_library('elgg:pages');
+
+if (empty($vars['entity'])) {
+ $container = elgg_get_page_owner_entity();
+} else {
+ $container = $vars['entity']->getContainerEntity();
+}
+
+$pages = pages_get_navigation_tree($container);
+$options = array();
+
+foreach ($pages as $page) {
+ $spacing = "";
+ for ($i = 0; $i < $page['depth']; $i++) {
+ $spacing .= "--";
+ }
+ $options[$page['guid']] = "$spacing " . $page['title'];
+}
+
+$defaults = array(
+ 'class' => 'elgg-input-parent-picker',
+ 'options_values' => $options,
+);
+
+$vars = array_merge($defaults, $vars);
+
+echo elgg_view('input/dropdown', $vars);