This book shall give you an itroduction on how to use the PHP-UWA Widget Library.
Intro
The Universal Widget Architecture Standard is defined and documented on the
Netvibes Development Page. The goal is to code a widget and use it on several sites:
- On the Netvibes page.
- Macintosh (incl iPhone)
- iGoogle
- Opera
- Windows Vista
- Windows live
- Yahoo
- And soon: Facebook and OpenSocial
This might trigger an activity in widget-development. Let us use this to the benefit of siteadmins and to the one of the widget-coderz.
Screenshots
The included example shows all possibilities in a simple way:
[img_assist|nid=29|title=PHP-Uwa Library Example|desc=|link=popup|align=none|width=81|height=100]
One application is a
Moodle Block.
Moodle is an open source learningmanagement system (lms):
[img_assist|nid=41|title=Moodle Unit Wdget|desc=|link=none|align=none|width=253|height=319]
[img_assist|nid=38|title=Moodle Google Notebook Widget|desc=|link=none|align=none|width=248|height=318]
Usage
Show a widget
To show a widget, the library has to be included and the class has to be instantiated. A Call to
getWidgetHTML shows the code:
<?php
require_once('uwawidget.php');
$uwawidget=new uwawidget('http://www.netvibes.com/api/uwa/examples/digg.xhtml');
echo $uwawidget->getWidgetHTML();
?>
All values are filled with defaults.
Getting metatdata
There are two types of metadata, packed in arrays:
- $uwawidget->getMetaData()
- Author, Keywords, ...
- $uwawidget->getAdditionalData()
- Icon, Stylesheets, ...
Displaying editforms
There are two types of settings:
- Configuration
- Displaysettings for the widget. These are the same for all widgets.
- Preferences
- These are widget dependent, Not every widget has preferences.
You can get all needed data in a handy array by calling
getSettingsFormData($section).
$section is one of the following:
- general
- Mainly the widget url.
- configuration
- Display Configuration Settings.
- preferences
- Widget dependend preferences.
Even more simple is the possibility to get the HTML:
<form action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="post">
<?php
$settingshtml['general']= $uwawidget->getSettingsHTML('general');
$settingshtml['configuration']= $uwawidget->getSettingsHTML('configuration');
$prefs= $uwawidget->getSettingsHTML('preferences');
if ($prefs) {
$settingshtml['preferences']= $prefs;
}
// Show Hidden fields
foreach ($settingshtml as $section => $fields) {
if (isset ($fields['hidden'])) {
foreach ($fields['hidden'] as $hiddenfield) {
echo $hiddenfield;
}
unset ($settingshtml[$section]['hidden']);
}
}?>
<table cellpadding="9" cellspacing="0">
<?
foreach ($settingshtml as $section => $setting) {
echo '<tr>' . "\n";
echo ' <td colspan="2">' . "\n";
echo ' <b>' . get_string($section, 'block_uwa_widget') . '</b></td>' . "\n";
echo '</tr>' . "\n";
foreach ($setting as $label => $html) {
echo '<tr valign="top">' . "\n";
echo '<td align="right">' . $label . ':</td>' . "\n";
echo '<td>' . $html . '</td>' . "\n";
echo '</tr>' . "\n";
}
}
?>
<tr>
<td colspan="2" align="center">
<input type="submit" value="<?php print_string("savechanges") ?>" /></td></tr>
</table>
For setting these values in the widget, you can use the classes' setters:
if(isset($_POST['moduleUrl'])) {
$index=$_POST['moduleUrl'];
$uwawidget->setModuleUrl($examplewidgets[$index]['moduleUrl']);
}
if(isset($_POST['configuration'])) {
$uwawidget->setConfiguration($_POST['configuration']);
}
if(isset($_POST['preferences'])) {
$uwawidget->setPreferences($_POST['preferences']);
}