aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorben <ben@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-06-18 15:46:57 +0000
committerben <ben@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-06-18 15:46:57 +0000
commitf46b9a78e84dc57b7673691c7297aaf81f6f7b07 (patch)
tree8b163c22a449fb48d484b0df45a071fca0e0f39c
parenta783b882e7f9422d75ab3ff9192558a01943d252 (diff)
downloadelgg-f46b9a78e84dc57b7673691c7297aaf81f6f7b07.tar.gz
elgg-f46b9a78e84dc57b7673691c7297aaf81f6f7b07.tar.bz2
Added widget handling.
git-svn-id: https://code.elgg.org/elgg/trunk@972 36083f99-b078-4883-b0ff-0f9b5a30f544
-rw-r--r--actions/widgets/reorder.php31
-rw-r--r--engine/lib/widgets.php81
-rw-r--r--views/default/canvas/layouts/widgets.php143
-rw-r--r--views/default/input/access.php2
4 files changed, 184 insertions, 73 deletions
diff --git a/actions/widgets/reorder.php b/actions/widgets/reorder.php
new file mode 100644
index 000000000..47d446519
--- /dev/null
+++ b/actions/widgets/reorder.php
@@ -0,0 +1,31 @@
+<?php
+
+ /**
+ * Elgg widget reorder action
+ *
+ * @package Elgg
+ * @subpackage Core
+ * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
+ * @author Curverider Ltd
+ * @copyright Curverider Ltd 2008
+ * @link http://elgg.org/
+ */
+
+
+ $owner = get_input('owner');
+ $context = get_input('context');
+
+ $maincontent = get_input('debugField1');
+ $sidebar = get_input('debugField2');
+
+ $result = reorder_widgets_from_panel($maincontent, $sidebar, $context, $owner);
+
+ if ($result) {
+ system_message(elgg_echo('widgets:save:success'));
+ } else {
+ system_message(elgg_echo('widgets:save:failure'));
+ }
+
+ forward($_SERVER['HTTP_REFERER']);
+
+?> \ No newline at end of file
diff --git a/engine/lib/widgets.php b/engine/lib/widgets.php
index 8a7a82e92..5838ef2de 100644
--- a/engine/lib/widgets.php
+++ b/engine/lib/widgets.php
@@ -133,6 +133,9 @@
}
$widgetorder[$order] = $widget;
}
+
+ ksort($widgetorder);
+
return $widgetorder;
}
@@ -303,12 +306,90 @@
}
+ function reorder_widgets_from_panel($panelstring1, $panelstring2, $context, $owner) {
+
+ $return = true;
+
+ $mainwidgets = explode('::',$panelstring1);
+ $sidewidgets = explode('::',$panelstring2);
+
+ $handlers = array();
+ $guids = array();
+
+ if (is_array($mainwidgets) && sizeof($mainwidgets) > 0) {
+ foreach($mainwidgets as $widget) {
+
+ $guid = (int) $widget;
+
+ if ("{$guid}" == "{$widget}") {
+ $guids[1][] = $widget;
+ } else {
+ $handlers[1][] = $widget;
+ }
+
+ }
+ }
+ if (is_array($sidewidgets) && sizeof($sidewidgets) > 0) {
+ foreach($sidewidgets as $widget) {
+
+ $guid = (int) $widget;
+
+ if ("{$guid}" == "{$widget}") {
+ $guids[2][] = $widget;
+ } else {
+ $handlers[2][] = $widget;
+ }
+
+ }
+ }
+
+ // Reorder existing widgets or delete ones that have vanished
+ foreach (array(1,2) as $column) {
+ if ($dbwidgets = get_widgets($owner,$context,$column)) {
+
+ foreach($dbwidgets as $dbwidget) {
+ if (in_array($dbwidget->getGUID(),$guids[1]) || in_array($dbwidget->getGUID(),$guids[2])) {
+ if (in_array($dbwidget->getGUID(),$guids[1])) {
+ $pos = array_search($dbwidget->getGUID(),$guids[1]);
+ $col = 1;
+ } else {
+ $pos = array_search($dbwidget->getGUID(),$guids[2]);
+ $col = 2;
+ }
+ $pos = ($pos + 1) * 10;
+ $dbwidget->column = $col;
+ $dbwidget->order = $pos;
+ } else {
+ if (!$dbwidget->delete())
+ $return = false;
+ }
+ }
+
+ }
+ // Add new ones
+ if (sizeof($guids[$column]) > 0) {
+ foreach($guids[$column] as $key => $guid) {
+ if ($guid == 0) {
+ $pos = ($key + 1) * 10;
+ $handler = $handlers[$column][$key];
+ if (!add_widget($owner,$handler,$context,$pos,$column))
+ $return = false;
+ }
+ }
+ }
+ }
+
+ return $return;
+
+ }
+
/**
* Function to initialise widgets functionality on Elgg init
*
*/
function widgets_init() {
+ register_action('widgets/reorder');
register_action('widgets/save');
register_action('widgets/add');
diff --git a/views/default/canvas/layouts/widgets.php b/views/default/canvas/layouts/widgets.php
index 2b4600c2f..2c9783148 100644
--- a/views/default/canvas/layouts/widgets.php
+++ b/views/default/canvas/layouts/widgets.php
@@ -15,7 +15,11 @@
$owner = page_owner_entity();
+ $area1widgets = get_widgets(page_owner(),get_context(),1);
+ $area2widgets = get_widgets(page_owner(),get_context(),2);
+
if (is_array($widgettypes) && sizeof($widgettypes) > 0 && $owner->canEdit()) {
+
?>
@@ -60,60 +64,74 @@
<div id="main_widgets">
<h2>Main content area widgets</h2>
-<table class="draggable_widget" cellspacing="0"><tr><td width="149px"><h3>Widget 1 Title<input type="hidden" name="handler" value="placeholder1" />
- <input type="hidden" name="guid" value="01" /></h3></td>
-<td width="17px" align="right"><a href="#"><img src="<?php echo $vars['url']; ?>_graphics/icon_customise_remove.gif" class="remove_me" /></a></td>
-<td width="17px" align="right"><a href="#"><img src="<?php echo $vars['url']; ?>_graphics/icon_customise_info.gif" class="more_info" /></a></td>
-<td width="17px" align="right"><a href="#"><img src="<?php echo $vars['url']; ?>_graphics/icon_customise_drag.gif" class="drag_handle" /></a></td>
-</tr></table>
-<table class="draggable_widget" cellspacing="0"><tr><td width="149px"><h3>Widget 2 Title megacalculatorextrodinaire<input type="hidden" name="handler" value="placeholder2" />
- <input type="hidden" name="guid" value="02" /></h3></td>
-<td width="17px" align="right"><a href="#"><img src="<?php echo $vars['url']; ?>_graphics/icon_customise_remove.gif" class="remove_me" /></a></td>
-<td width="17px" align="right"><a href="#"><img src="<?php echo $vars['url']; ?>_graphics/icon_customise_info.gif" class="more_info" /></a></td>
-<td width="17px" align="right"><a href="#"><img src="<?php echo $vars['url']; ?>_graphics/icon_customise_drag.gif" class="drag_handle" /></a></td>
-</tr></table>
-<table class="draggable_widget" cellspacing="0"><tr><td width="149px"><h3>Widget 3 Title<input type="hidden" name="handler" value="placeholder3" />
- <input type="hidden" name="guid" value="03" /></h3></td>
-<td width="17px" align="right"><a href="#"><img src="<?php echo $vars['url']; ?>_graphics/icon_customise_remove.gif" class="remove_me" /></a></td>
-<td width="17px" align="right"><a href="#"><img src="<?php echo $vars['url']; ?>_graphics/icon_customise_info.gif" class="more_info" /></a></td>
-<td width="17px" align="right"><a href="#"><img src="<?php echo $vars['url']; ?>_graphics/icon_customise_drag.gif" class="drag_handle" /></a></td>
-</tr></table>
-<table class="draggable_widget" cellspacing="0"><tr><td width="149px"><h3>Widget 4 Title<input type="hidden" name="handler" value="placeholder4" />
- <input type="hidden" name="guid" value="04" /></h3></td>
-<td width="17px" align="right"><a href="#"><img src="<?php echo $vars['url']; ?>_graphics/icon_customise_remove.gif" class="remove_me" /></a></td>
-<td width="17px" align="right"><a href="#"><img src="<?php echo $vars['url']; ?>_graphics/icon_customise_info.gif" class="more_info" /></a></td>
-<td width="17px" align="right"><a href="#"><img src="<?php echo $vars['url']; ?>_graphics/icon_customise_drag.gif" class="drag_handle" /></a></td>
-</tr></table>
-<table class="draggable_widget" cellspacing="0"><tr><td width="149px"><h3>Widget 5 Title<input type="hidden" name="handler" value="placeholder5" />
- <input type="hidden" name="guid" value="05" /></h3></td>
+<?php
+ $mainwidgetstring = "";
+ if (is_array($area1widgets) && sizeof($area1widgets) > 0) {
+ foreach($area1widgets as $widget) {
+ if (!empty($mainwidgetstring)) {
+ $mainwidgetstring .= "::";
+ }
+ $mainwidgetstring .= "{$widget->handler}::{$widget->getGUID()}";
+?>
+
+<table class="draggable_widget" cellspacing="0"><tr><td width="149px">
+ <h3>
+ <?php echo $widgettypes[$widget->handler]->name; ?>
+ <input type="hidden" name="handler" value="<?php
+ echo $widget->handler;
+ ?>" />
+ <input type="hidden" name="description" value="<?php echo htmlentities($widgettypes[$widget->handler]->description); ?>" />
+ <input type="hidden" name="guid" value="<?php echo $widget->getGUID(); ?>" />
+ </h3>
+</td>
<td width="17px" align="right"><a href="#"><img src="<?php echo $vars['url']; ?>_graphics/icon_customise_remove.gif" class="remove_me" /></a></td>
<td width="17px" align="right"><a href="#"><img src="<?php echo $vars['url']; ?>_graphics/icon_customise_info.gif" class="more_info" /></a></td>
<td width="17px" align="right"><a href="#"><img src="<?php echo $vars['url']; ?>_graphics/icon_customise_drag.gif" class="drag_handle" /></a></td>
</tr></table>
+
+<?php
+
+ }
+ }
+?>
</div>
</td>
<td width="240px">
<div id="rightsidebar_widgets">
<h2>Right sidebar widgets</h2>
-<table class="draggable_widget" cellspacing="0"><tr><td width="149px"><h3>Widget 6 Title<input type="hidden" name="handler" value="placeholder6" />
- <input type="hidden" name="guid" value="06" /></h3></td>
-<td width="17px" align="right"><a href="#"><img src="<?php echo $vars['url']; ?>_graphics/icon_customise_remove.gif" class="remove_me" /></a></td>
-<td width="17px" align="right"><a href="#"><img src="<?php echo $vars['url']; ?>_graphics/icon_customise_info.gif" class="more_info" /></a></td>
-<td width="17px" align="right"><a href="#"><img src="<?php echo $vars['url']; ?>_graphics/icon_customise_drag.gif" class="drag_handle" /></a></td>
-</tr></table>
-<table class="draggable_widget" cellspacing="0"><tr><td width="149px"><h3>Widget 7 Title<input type="hidden" name="handler" value="placeholder7" />
- <input type="hidden" name="guid" value="07" /></h3></td>
-<td width="17px" align="right"><a href="#"><img src="<?php echo $vars['url']; ?>_graphics/icon_customise_remove.gif" class="remove_me" /></a></td>
-<td width="17px" align="right"><a href="#"><img src="<?php echo $vars['url']; ?>_graphics/icon_customise_info.gif" class="more_info" /></a></td>
-<td width="17px" align="right"><a href="#"><img src="<?php echo $vars['url']; ?>_graphics/icon_customise_drag.gif" class="drag_handle" /></a></td>
-</tr></table>
-<table class="draggable_widget" cellspacing="0"><tr><td width="149px"><h3>Widget 8 Title<input type="hidden" name="handler" value="placeholder8" />
- <input type="hidden" name="guid" value="08" /></h3></td>
+
+<?php
+ $sidebarwidgetstring = "";
+ if (is_array($area2widgets) && sizeof($area2widgets) > 0) {
+ foreach($area2widgets as $widget) {
+ if (!empty($sidebarwidgetstring)) {
+ $sidebarwidgetstring .= "::";
+ }
+ $sidebarwidgetstring .= "{$widget->handler}::{$widget->getGUID()}";
+?>
+
+<table class="draggable_widget" cellspacing="0"><tr><td width="149px">
+ <h3>
+ <?php echo $widgettypes[$widget->handler]->name; ?>
+ <input type="hidden" name="handler" value="<?php
+ echo $widget->handler;
+ ?>" />
+ <input type="hidden" name="description" value="<?php echo htmlentities($widgettypes[$widget->handler]->description); ?>" />
+ <input type="hidden" name="guid" value="<?php echo $widget->getGUID(); ?>" />
+ </h3>
+</td>
<td width="17px" align="right"><a href="#"><img src="<?php echo $vars['url']; ?>_graphics/icon_customise_remove.gif" class="remove_me" /></a></td>
<td width="17px" align="right"><a href="#"><img src="<?php echo $vars['url']; ?>_graphics/icon_customise_info.gif" class="more_info" /></a></td>
<td width="17px" align="right"><a href="#"><img src="<?php echo $vars['url']; ?>_graphics/icon_customise_drag.gif" class="drag_handle" /></a></td>
</tr></table>
+
+<?php
+
+ }
+ }
+?>
+
</div>
</td>
@@ -122,33 +140,18 @@
</div><!-- /#customise_page_view -->
-<textarea type="textarea" value="Main widgets" style="width:400px;height:70px;" id="debugField1" /></textarea>
-<textarea type="textarea" value="Right widgets" style="width:400px;height:70px;" id="debugField2" /></textarea>
-
+<form action="<?php echo $vars['url']; ?>action/widgets/reorder" method="post">
+<textarea type="textarea" value="Main widgets" style="display:none" name="debugField1" id="debugField1" /><?php echo $mainwidgetstring; ?></textarea>
+<textarea type="textarea" value="Right widgets" style="display:none" name="debugField2" id="debugField2" /><?php echo $sidebarwidgetstring; ?></textarea>
+<input type="hidden" name="context" value="<?php echo get_context(); ?>" />
+<input type="hidden" name="owner" value="<?php echo page_owner(); ?>" />
<input type="submit" value="Save changes" class="submit_button" />
-
+</form>
</div><!-- /customise_editpanel -->
<!-- temporary customise button here -->
<a href="javascript:void(0);" class="toggle_customise_edit_panel">Customise Layout</a>
- <p>
- <b>Temporarily, add a widget to this page:</b><br />
-
-<?php
-
- foreach($widgettypes as $handler => $widgettype) {
- $url = $vars['url'] . "action/widgets/add";
- $url .= "?handler=" . $handler;
- $url .= "&amp;context=" . get_context();
- $url .= "&amp;user=" . page_owner();
- $url .= "&amp;column=1";
- echo "<a href=\"{$url}\">{$widgettype->name}</a><br />";
- }
-
-?>
- </p>
-
<?php
}
@@ -160,14 +163,12 @@
<div id="wrapper_sidebar_right">
- <?php echo $vars['area2']; ?>
+ <?php if (isset($vars['area2'])) echo $vars['area2']; ?>
<?php
- if ($widgets = get_widgets(page_owner(),get_context(),2)) {
- if (is_array($widgets) && sizeof($widgets) > 0)
- foreach($widgets as $widget) {
- echo elgg_view_entity($widget);
- }
+ if (is_array($area2widgets) && sizeof($area2widgets) > 0)
+ foreach($area2widgets as $widget) {
+ echo elgg_view_entity($widget);
}
?>
@@ -185,11 +186,9 @@
<?php echo $vars['area1']; ?>
<?php
- if ($widgets = get_widgets(page_owner(),get_context(),1)) {
- if (is_array($widgets) && sizeof($widgets) > 0)
- foreach($widgets as $widget) {
- echo elgg_view_entity($widget);
- }
+ if (is_array($area1widgets) && sizeof($area1widgets) > 0)
+ foreach($area1widgets as $widget) {
+ echo elgg_view_entity($widget);
}
?>
diff --git a/views/default/input/access.php b/views/default/input/access.php
index cbabf3cc4..91ee2cca8 100644
--- a/views/default/input/access.php
+++ b/views/default/input/access.php
@@ -24,7 +24,7 @@
?>
-<select name="<?php echo $vars['internalname']; ?>" <?php echo $vars['js']; ?>>
+<select name="<?php echo $vars['internalname']; ?>" <?php if (isset($vars['js'])) echo $vars['js']; ?>>
<?php
foreach($vars['options'] as $key => $option) {