diff options
author | ben <ben@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2008-06-12 17:57:25 +0000 |
---|---|---|
committer | ben <ben@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2008-06-12 17:57:25 +0000 |
commit | 683f50786a7aec4a936b7b5d59a8e6338b1c7071 (patch) | |
tree | c674bb5a47b3ac98837743d09991013a33232fb1 | |
parent | d423fd2379171706c75c60600442a2dbdc12d87a (diff) | |
download | elgg-683f50786a7aec4a936b7b5d59a8e6338b1c7071.tar.gz elgg-683f50786a7aec4a936b7b5d59a8e6338b1c7071.tar.bz2 |
Widgets, including a test widget plugin
git-svn-id: https://code.elgg.org/elgg/trunk@900 36083f99-b078-4883-b0ff-0f9b5a30f544
-rw-r--r-- | actions/widgets/add.php | 43 | ||||
-rw-r--r-- | actions/widgets/save.php | 7 | ||||
-rw-r--r-- | engine/lib/widgets.php | 23 | ||||
-rw-r--r-- | mod/profile/index.php | 2 | ||||
-rw-r--r-- | mod/profile/start.php | 4 | ||||
-rw-r--r-- | mod/widgettest/start.php | 13 | ||||
-rw-r--r-- | mod/widgettest/views/default/widgets/widgettest/edit.php | 7 | ||||
-rw-r--r-- | mod/widgettest/views/default/widgets/widgettest/view.php | 13 | ||||
-rw-r--r-- | views/default/canvas/layouts/widgets.php | 29 | ||||
-rw-r--r-- | views/default/widgets/wrapper.php | 13 |
10 files changed, 140 insertions, 14 deletions
diff --git a/actions/widgets/add.php b/actions/widgets/add.php new file mode 100644 index 000000000..07e167a96 --- /dev/null +++ b/actions/widgets/add.php @@ -0,0 +1,43 @@ +<?php
+
+ /**
+ * Elgg widget add 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('user');
+ $handler = get_input('handler');
+ $context = get_input('context');
+ $column = get_input('column');
+
+ $result = false;
+
+ if (!empty($guid)) {
+
+ if ($user = get_entity($guid)) {
+
+ if ($user->canEdit()) {
+
+ $result = add_widget($user->getGUID(),$handler,$context,0,$column);
+
+ }
+
+ }
+
+ }
+
+ 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/actions/widgets/save.php b/actions/widgets/save.php index b50010e6f..deb4bb911 100644 --- a/actions/widgets/save.php +++ b/actions/widgets/save.php @@ -11,8 +11,9 @@ * @link http://elgg.org/
*/
+
$guid = get_input('guid');
- $params = get_input('params');
+ $params = $_REQUEST['params'];
$pageurl = get_input('pageurl');
$result = false;
@@ -24,9 +25,9 @@ }
if ($result) {
- system_message('widgets:save:success');
+ system_message(elgg_echo('widgets:save:success'));
} else {
- system_message('widgets:save:failure');
+ system_message(elgg_echo('widgets:save:failure'));
}
forward($_SERVER['HTTP_REFERER']);
diff --git a/engine/lib/widgets.php b/engine/lib/widgets.php index bf36cf001..b4ad9bd93 100644 --- a/engine/lib/widgets.php +++ b/engine/lib/widgets.php @@ -82,6 +82,8 @@ return true;
+ } else {
+ register_error($widget->subtype);
}
}
@@ -102,13 +104,17 @@ if ($widgets = get_user_objects_by_metadata($user_guid, "widget", array(
'column' => $column,
- 'location' => $context,
+ 'context' => $context,
), 10000)) {
$widgetorder = array();
foreach($widgets as $widget) {
- $widgetorder[$widget->order] = $widget;
+ $order = $widget->order;
+ while(isset($widgetorder[$order])) {
+ $order++;
+ }
+ $widgetorder[$order] = $widget;
}
return $widgetorder;
@@ -148,11 +154,14 @@ if ($user = get_user($user_guid)) {
$widget = new ElggObject;
+ $widget->subtype = "widget";
$widget->handler = $handler;
$widget->context = $context;
+ $widget->column = $column;
if (!$widget->save())
return false;
- return save_widget_location($widget, $order, $column);
+ save_widget_location($widget, $order, $column);
+ return true;
}
@@ -244,7 +253,9 @@ if ($widget = get_entity($widget_guid)) {
- if ($widget->subtype != "widget") return false;
+ $subtype = $widget->getSubtype();
+
+ if ($subtype != "widget") return false;
$handler = $widget->handler;
if (empty($handler) || !widget_type_exists($handler)) return false;
@@ -257,6 +268,7 @@ $widget->$name = $value;
}
}
+ $widget->save();
}
$function = "save_{$handler}_widget";
@@ -276,9 +288,10 @@ * Function to initialise widgets functionality on Elgg init
*
*/
- function widget_init() {
+ function widgets_init() {
register_action('widgets/save');
+ register_action('widgets/add');
}
diff --git a/mod/profile/index.php b/mod/profile/index.php index 35c1e41a6..e1f4f1651 100644 --- a/mod/profile/index.php +++ b/mod/profile/index.php @@ -29,7 +29,7 @@ }
- $body.= elgg_view("river/shell", array('river' => get_river_entries())); + $body = elgg_view_layout('widgets',$body);
page_draw($title, $body);
diff --git a/mod/profile/start.php b/mod/profile/start.php index ddf136425..d76be446c 100644 --- a/mod/profile/start.php +++ b/mod/profile/start.php @@ -117,8 +117,6 @@ register_action("profile/iconupload",false,$CONFIG->pluginspath . "profile/actions/iconupload.php");
// Define widgets for use in this context
- if (is_callable('use_widgets')) {
- use_widgets('profile');
- }
+ use_widgets('profile');
?>
\ No newline at end of file diff --git a/mod/widgettest/start.php b/mod/widgettest/start.php new file mode 100644 index 000000000..b02423b66 --- /dev/null +++ b/mod/widgettest/start.php @@ -0,0 +1,13 @@ +<?php
+
+ // TEMPORARY!
+
+ function widgettest_init() {
+
+ add_widget_type('widgettest',"Test widget!","This is a test widget.");
+
+ }
+
+ register_elgg_event_handler('init','system','widgettest_init');
+
+?>
\ No newline at end of file diff --git a/mod/widgettest/views/default/widgets/widgettest/edit.php b/mod/widgettest/views/default/widgets/widgettest/edit.php new file mode 100644 index 000000000..10958a7ba --- /dev/null +++ b/mod/widgettest/views/default/widgets/widgettest/edit.php @@ -0,0 +1,7 @@ +<?php
+
+?>
+ <p>
+ Display a message:
+ <input type="text" name="params[description]" value="<?php echo htmlentities($vars['entity']->description); ?>" />
+ </p>
\ No newline at end of file diff --git a/mod/widgettest/views/default/widgets/widgettest/view.php b/mod/widgettest/views/default/widgets/widgettest/view.php new file mode 100644 index 000000000..16ec7390e --- /dev/null +++ b/mod/widgettest/views/default/widgets/widgettest/view.php @@ -0,0 +1,13 @@ +<h1>I am a test widget!</h1>
+<p>
+ <?php
+
+ $description = $vars['entity']->description;
+ if (!empty($description)) {
+ echo $vars['entity']->description;
+ } else {
+ echo "Click 'edit' to change my message.";
+ }
+
+ ?>
+</p>
\ No newline at end of file diff --git a/views/default/canvas/layouts/widgets.php b/views/default/canvas/layouts/widgets.php index e98d2f99a..39a5b92c9 100644 --- a/views/default/canvas/layouts/widgets.php +++ b/views/default/canvas/layouts/widgets.php @@ -11,6 +11,33 @@ * @link http://elgg.org/ */ + $widgettypes = get_widget_types(); + + if (is_array($widgettypes) && sizeof($widgettypes) > 0) { + +?> + + <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 .= "&context=" . get_context(); + $url .= "&user=" . page_owner(); + $url .= "&column=1"; + echo "<a href=\"{$url}\">{$widgettype->name}</a><br />"; + } + +?> + </p> + +<?php + + } + ?> <!-- right sidebar --> @@ -22,6 +49,7 @@ <?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); } @@ -44,6 +72,7 @@ <?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); } diff --git a/views/default/widgets/wrapper.php b/views/default/widgets/wrapper.php index 93db61725..fcf3782fe 100644 --- a/views/default/widgets/wrapper.php +++ b/views/default/widgets/wrapper.php @@ -18,7 +18,7 @@ $handler = "error";
$title = elgg_echo("error");
}
-
+
?>
<div class="collapsable_box">
@@ -29,7 +29,16 @@ echo $vars['entity']->title;
?></h1></div>
- <div class="collapsable_box_editpanel"><?php echo elgg_view('widgets/editwrapper',array('body' => elgg_view("widgets/{$handler}/edit",$vars))); ?></div><!-- /collapsable_box_editpanel -->
+ <div class="collapsable_box_editpanel"><?php
+
+ echo elgg_view('widgets/editwrapper',
+ array(
+ 'body' => elgg_view("widgets/{$handler}/edit",$vars),
+ 'entity' => $vars['entity']
+ )
+ );
+
+ ?></div><!-- /collapsable_box_editpanel -->
<div class="collapsable_box_content">
<?php echo elgg_view("widgets/{$handler}/view",$vars); ?>
</div><!-- /.collapsable_box_content -->
|