From f46b9a78e84dc57b7673691c7297aaf81f6f7b07 Mon Sep 17 00:00:00 2001 From: ben Date: Wed, 18 Jun 2008 15:46:57 +0000 Subject: Added widget handling. git-svn-id: https://code.elgg.org/elgg/trunk@972 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/lib/widgets.php | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) (limited to 'engine') 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'); -- cgit v1.2.3