From df94762e70f5c143b728a62d90c298fb887231c6 Mon Sep 17 00:00:00 2001 From: ben Date: Mon, 30 Jun 2008 16:36:52 +0000 Subject: Added the ability to control widget contexts git-svn-id: https://code.elgg.org/elgg/trunk@1211 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/lib/widgets.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'engine/lib') diff --git a/engine/lib/widgets.php b/engine/lib/widgets.php index 6ffc976a2..5156a6332 100644 --- a/engine/lib/widgets.php +++ b/engine/lib/widgets.php @@ -196,10 +196,13 @@ * @param string $handler The identifier for the widget handler * @param string $name The name of the widget type * @param string $description A description for the widget type + * @param string $context A comma-separated list of contexts where this widget is allowed (default: 'all') + * @param true|false $multiple Whether or not multiple instances of this widget are allowed on a single dashboard (default: false) + * @param string $position A comma-separated list of positions on the page (side or main) where this widget is allowed (default: "side,main") * @return true|false Depending on success */ - function add_widget_type($handler, $name, $description) { + function add_widget_type($handler, $name, $description, $context = "all", $multiple = false, $positions = "side,main") { if (!empty($handler) && !empty($name)) { @@ -214,6 +217,9 @@ $handlerobj = new stdClass; $handlerobj->name = $name; $handlerobj->description = $description; + $handlerobj->context = explode(",",$context); + $handlerobj->multiple = $multiple; + $handlerobj->positions = explode(",",$positions); $CONFIG->widgets->handlers[$handler] = $handlerobj; @@ -256,6 +262,15 @@ && !empty($CONFIG->widgets->handlers) && is_array($CONFIG->widgets->handlers)) { + $context = get_context(); + + foreach($CONFIG->widgets->handlers as $key => $handler) { + if (!in_array('all',$handler->context) && + !in_array($context,$handler->context)) { + unset($CONFIG->widgets->handlers[$key]); + } + } + return $CONFIG->widgets->handlers; } -- cgit v1.2.3