aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--actions/widgets/save.php34
-rw-r--r--engine/lib/widgets.php143
-rw-r--r--languages/en.php9
-rw-r--r--views/default/widgets/editwrapper.php3
4 files changed, 159 insertions, 30 deletions
diff --git a/actions/widgets/save.php b/actions/widgets/save.php
new file mode 100644
index 000000000..b50010e6f
--- /dev/null
+++ b/actions/widgets/save.php
@@ -0,0 +1,34 @@
+<?php
+
+ /**
+ * Elgg widget save 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/
+ */
+
+ $guid = get_input('guid');
+ $params = get_input('params');
+ $pageurl = get_input('pageurl');
+
+ $result = false;
+
+ if (!empty($guid)) {
+
+ $result = save_widget_info($guid,$params);
+
+ }
+
+ if ($result) {
+ system_message('widgets:save:success');
+ } else {
+ system_message('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 aa12bf76b..8d44e14a8 100644
--- a/engine/lib/widgets.php
+++ b/engine/lib/widgets.php
@@ -29,25 +29,6 @@
}
}
-
-
- /**
- * Registers a particular action with a widget handler
- *
- * @param string $handler_name
- * @param unknown_type $action
- */
- function add_widget_save_action($handler_name, $action) {
-
- global $CONFIG;
- if (!isset($CONFIG->widgets->saveactions))
- $CONFIG->widgets->saveactions = array();
-
- if (!empty($handler_name)) {
- $CONFIG->widgets->saveactions[$handler_name] = $action;
- }
-
- }
/**
* When given a widget entity and a new requested location, saves the new location
@@ -141,18 +122,11 @@
* Displays a particular widget
*
* @param ElggObject $widget The widget to display
- * @param boolean $edit Should we display edit mode?
* @return string The HTML for the widget, including JavaScript wrapper
*/
- function display_widget(ElggObject $widget, $edit = false) {
-
- if ($edit) {
- $body = elgg_view("widgets/" . $widget->handler . "/edit", array('entity' => $widget));
- } else {
- $body = elgg_view("widgets/" . $widget->handler . "/view", array('entity' => $widget));
- }
+ function display_widget(ElggObject $widget) {
- return elgg_view("widgets/wrapper",array('body' => $body, 'widget' => $widget, 'edit' => $edit));
+ return elgg_view_entity($widget);
}
@@ -168,7 +142,7 @@
*/
function add_widget($user_guid, $handler, $context, $order = 0, $column = 1) {
- if (empty($user_guid) || empty($context) || empty($handler))
+ if (empty($user_guid) || empty($context) || empty($handler) || !widget_type_exists($handler))
return false;
if ($user = get_user($user_guid)) {
@@ -185,6 +159,117 @@
return false;
}
+
+ /**
+ * Define a new widget type
+ *
+ * @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
+ * @return true|false Depending on success
+ */
+
+ function add_widget_type($handler, $name, $description) {
+
+ if (!empty($handler) && !empty($name)) {
+
+ global $CONFIG;
+
+ if (!isset($CONFIG->widgets))
+ $CONFIG->widgets = new stdClass;
+
+ if (!isset($CONFIG->widgets->handlers))
+ $CONFIG->widgets->handlers = array();
+
+ $handlerobj = new stdClass;
+ $handlerobj->name = $name;
+ $handlerobj->description = $description;
+
+ $CONFIG->widgets->handlers[$handler] = $handlerobj;
+
+ return true;
+
+ }
+
+ return false;
+
+ }
+
+ /**
+ * Determines whether or not widgets with the specified handler have been defined
+ *
+ * @param string $handler The widget handler identifying string
+ * @return true|false Whether or not those widgets exist
+ */
+ function widget_type_exists($handler) {
+
+ global $CONFIG;
+ if (!empty($CONFIG->widgets)
+ && !empty($CONFIG->widgets->handlers)
+ && is_array($CONFIG->widgets->handlers)
+ && array_key_exists($handler, $CONFIG->widgets->handlers))
+ return true;
+
+ return false;
+
+ }
+
+ /**
+ * Returns an array of stdClass objects representing the defined widget types
+ *
+ * @return array A list of types defined (if any)
+ */
+ function get_widget_types() {
+
+ global $CONFIG;
+ if (!empty($CONFIG->widgets)
+ && !empty($CONFIG->widgets->handlers)
+ && is_array($CONFIG->widgets->handlers)) {
+
+ return $CONFIG->widgets->handlers;
+
+ }
+
+ return array();
+
+ }
+
+ /**
+ * Saves a widget's settings (by passing an array of (name => value) pairs to save_{$handler}_widget)
+ *
+ * @param int $widget_guid The GUID of the widget we're saving to
+ * @param array $params An array of name => value parameters
+ */
+ function save_widget_info($widget_guid, $params) {
+
+ if ($widget = get_entity($widget_guid)) {
+
+ if ($widget->subtype != "widget") return false;
+ $handler = $widget->handler;
+ if (empty($handler)) return false;
+ $function = "save_{$handler}_widget";
+ if (!is_callable($function)) return false;
+
+ return $function($params);
+
+ }
+
+ return false;
+
+ }
+
+ /**
+ * Function to initialise widgets functionality on Elgg init
+ *
+ */
+ function widget_init() {
+
+ register_action('widgets/save');
+
+ }
+
+ // Register event
+ register_elgg_event_handler('init','system','widgets_init');
?> \ No newline at end of file
diff --git a/languages/en.php b/languages/en.php
index cd714143a..f89b20365 100644
--- a/languages/en.php
+++ b/languages/en.php
@@ -265,6 +265,15 @@
'importsuccess' => "Import of data was successful",
/**
+ * Widgets
+ */
+
+ 'widgets' => "Widgets",
+ 'widget' => "Widget",
+ 'widgets:save:success' => "The widget was successfully saved.",
+ 'widgets:save:failure' => "We could not save your widget. Please try again.",
+
+ /**
* Installation and system settings
*/
diff --git a/views/default/widgets/editwrapper.php b/views/default/widgets/editwrapper.php
index eff8ec2a0..2411e4ca6 100644
--- a/views/default/widgets/editwrapper.php
+++ b/views/default/widgets/editwrapper.php
@@ -13,7 +13,7 @@
?>
-<form>
+<form action="<?php echo $vars['url']; ?>action/widgets/save" method="post">
<?php
@@ -22,6 +22,7 @@
?>
<p>
+ <input type="hidden" name="guid" value="<?php echo $vars['entity']->getGUID(); ?>" />
<input type="submit" value="<?php
echo elgg_echo('save');