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']);
}