Source for file Web.php
Documentation is available at Web.php
* This is a HTML driver for PEAR_PackageUpdate.
* LICENSE: This source file is subject to version 3.01 of the PHP license
* that is available through the world-wide-web at the following URI:
* http://www.php.net/license/3_01.txt. If you did not receive a copy of
* the PHP License and are unable to obtain it through the web, please
* send a note to license@php.net so we can mail you a copy immediately.
* @package PEAR_PackageUpdate_Web
* @author Laurent Laville <pear@laurent-laville.org>
* @copyright 2006 Laurent Laville
* @license http://www.php.net/license/3_01.txt PHP License 3.01
* @version CVS: $Id: Web.php,v 1.2 2006/05/25 14:44:40 farell Exp $
* @since File available since Release 0.1.0
require_once 'PEAR/PackageUpdate.php';
require_once 'HTML/QuickForm.php';
if (!defined('PEAR_PACKAGEUPDATE_DATA_DIR')) {
define('PEAR_PACKAGEUPDATE_DATA_DIR',
'@data_dir@' . DIRECTORY_SEPARATOR .
'@package_name@' . DIRECTORY_SEPARATOR );
* This is a HTML driver for PEAR_PackageUpdate.
* A package to make adding self updating functionality to other
* The interface for this package must allow for the following
* - check to see if a new version is available for a given
* package on a given channel
* - present information regarding the upgrade (version, size)
* - inform user about dependencies
* - allow user to confirm or cancel upgrade
* - download and install the package
* - track preferences on a per package basis
* - don't ask until next release
* - only ask for state XXXX or higher
* - bug/minor/major updates only
* - update channel automatically
* - force application to exit when upgrade complete
* - PHP-GTK/CLI apps must exit to allow classes to reload
* - web front end could send headers to reload certain page
* This class is simply a wrapper for PEAR classes that actually
* // Check for updates...
* require_once 'PEAR/PackageUpdate.php';
* $ppu =& PEAR_PackageUpdate::factory('Web', 'XML_RPC', 'pear');
* if ($ppu->checkUpdate()) {
* // Use a dialog window to ask permission to update.
* if ($ppu->presentUpdate()) {
* // If the update succeeded, the application should
* @package PEAR_PackageUpdate_Web
* @author Laurent Laville <pear@laurent-laville.org>
* @copyright 2006 Laurent Laville
* @license http://www.php.net/license/3_01.txt PHP License 3.01
* @version Release: @package_version@
* @since Class available since Release 0.1.0
* The main Dialog widget.
* The preference Dialog widget.
* The error Dialog widget.
* Creates the dialog that will ask the user if it is ok to update.
$this->mainwidget = new HTML_QuickForm ('infoPPU');
$this->mainwidget->removeAttribute ('name'); // XHTML compliance
// Create a title string.
$title = 'Update available for: ' . $this->packageName;
$this->mainwidget->addElement ('header', '', $title);
// Create an image placeholder and the message for the dialog.
$msg = 'A new version of ' . $this->packageName . ' ';
$msg .= " is available.\n\nWould you like to upgrade?";
$this->mainwidget->addElement ('static', 'message', '<div id="widget-icon-info"></div>', nl2br($msg));
$this->mainwidget->addElement ('text', 'current_version', 'Current Version:');
$this->mainwidget->addElement ('text', 'release_version', 'Release Version:');
$this->mainwidget->addElement ('text', 'release_date', 'Release Date:');
$this->mainwidget->addElement ('text', 'release_state', 'Release State:');
$this->mainwidget->addElement ('static', 'release_notes', 'Release Notes:',
'<div class="autoscroll">' .
nl2br($this->info['releasenotes']) .
$this->mainwidget->addElement ('text', 'release_by', 'Released By:');
'current_version' => $this->instVersion,
'release_version' => $this->latestVersion,
'release_date' => $this->info['releasedate'],
'release_state' => $this->info['state'],
'release_by' => $this->info['doneby']
// Add the preferences button.
$buttons[] = &HTML_QuickForm ::createElement ('submit', 'btnPrefs', 'Preferences');
// Add the yes/no buttons.
$buttons[] = &HTML_QuickForm ::createElement ('submit', 'mainBtnNo', 'No');
$buttons[] = &HTML_QuickForm ::createElement ('submit', 'mainBtnYes', 'Yes');
$this->mainwidget->addGroup ($buttons, 'buttons', '', ' ', false );
* Creates the dialog that will ask the user for his preferences.
$this->prefwidget = new HTML_QuickForm ('prefPPU');
$this->prefwidget->removeAttribute ('name'); // XHTML compliance
// Create the preferences dialog title.
$title = $this->packageName . ' Update Preferences';
$this->prefwidget->addElement ('header', '', $title);
// It needs a check box for "Don't ask again"
$this->prefwidget->addElement ('checkbox', 'dontAsk', '', 'Don\'t ask me again');
if (isset ($prefs[PEAR_PACKAGEUPDATE_PREF_NOUPDATES ])) {
$this->prefwidget->setDefaults (array ('dontAsk' => $prefs[PEAR_PACKAGEUPDATE_PREF_NOUPDATES ]));
// It needs a check box for the next release.
$this->prefwidget->addElement ('checkbox', 'nextRelease', '', 'Don\'t ask again until the next release.');
if (isset ($prefs[PEAR_PACKAGEUPDATE_PREF_NEXTRELEASE ])) {
$this->prefwidget->setDefaults (array ('nextRelease' => $prefs[PEAR_PACKAGEUPDATE_PREF_NEXTRELEASE ]));
// It needs a radio group for the state.
$allStates[] = &HTML_QuickForm ::createElement ('radio', null , null , 'All states', 'all');
$allStates[] = &HTML_QuickForm ::createElement ('radio', null , null , 'devel', PEAR_PACKAGEUPDATE_STATE_DEVEL );
$allStates[] = &HTML_QuickForm ::createElement ('radio', null , null , 'alpha', PEAR_PACKAGEUPDATE_STATE_ALPHA );
$allStates[] = &HTML_QuickForm ::createElement ('radio', null , null , 'beta', PEAR_PACKAGEUPDATE_STATE_BETA );
$allStates[] = &HTML_QuickForm ::createElement ('radio', null , null , 'stable', PEAR_PACKAGEUPDATE_STATE_STABLE );
$this->prefwidget->addGroup ($allStates, 'allStates', 'Only ask when the state is at least:', '<br />');
$stateDef = (isset ($prefs[PEAR_PACKAGEUPDATE_PREF_STATE ])) ?
$prefs[PEAR_PACKAGEUPDATE_PREF_STATE ] : 'all';
$this->prefwidget->setDefaults (array ('allStates' => $stateDef));
// It needs a radio group for the type.
$allTypes[] = &HTML_QuickForm ::createElement ('radio', null , null , 'All Release Types', 'all');
$allTypes[] = &HTML_QuickForm ::createElement ('radio', null , null , 'Bug fix', PEAR_PACKAGEUPDATE_TYPE_BUG );
$allTypes[] = &HTML_QuickForm ::createElement ('radio', null , null , 'Minor', PEAR_PACKAGEUPDATE_TYPE_MINOR );
$allTypes[] = &HTML_QuickForm ::createElement ('radio', null , null , 'Major', PEAR_PACKAGEUPDATE_TYPE_MAJOR );
$this->prefwidget->addGroup ($allTypes, 'allTypes', 'Only ask when the type is at least:', '<br />');
$typeDef = (isset ($prefs[PEAR_PACKAGEUPDATE_PREF_TYPE ])) ?
$prefs[PEAR_PACKAGEUPDATE_PREF_TYPE ] : 'all';
$this->prefwidget->setDefaults (array ('allTypes' => $typeDef));
// Add the yes/no buttons.
$buttons[] = &HTML_QuickForm ::createElement ('submit', 'prefBtnNo', 'No');
$buttons[] = &HTML_QuickForm ::createElement ('submit', 'prefBtnYes', 'Yes');
$this->prefwidget->addGroup ($buttons, 'buttons', '', ' ', false );
* Creates the dialog that will show errors to the user.
// Don't do anything if the dialog already exists.
$this->errwidget = new HTML_QuickForm ('errorPPU');
$this->errwidget->removeAttribute ('name'); // XHTML compliance
// Create a title string.
$title = 'Error(s) occured while trying to Update for: ' . $this->packageName;
$this->errwidget->addElement ('header', '', $title);
// Create an image placeholder and the message for the dialog.
$this->errwidget->addElement ('static', 'icon', '<div id="widget-icon-error"></div>');
$this->errwidget->addElement ('static', 'message', 'Message:');
// The error context details.
$this->errwidget->addElement ('text', 'context_file', 'File:');
$this->errwidget->addElement ('text', 'context_line', 'Line:');
$this->errwidget->addElement ('text', 'context_function', 'Function:');
$this->errwidget->addElement ('text', 'context_class', 'Class:');
$buttons[] = &HTML_QuickForm ::createElement ('submit', 'errorBtnOk', 'Ok');
$this->errwidget->addGroup ($buttons, 'buttons', '', ' ', false );
* Creates and runs a dialog for setting preferences.
* @return boolean true if the preferences were set and saved.
// The preferences dialog needs to have some inputs for the user.
// Get the current preferences so that defaults can be set.
$prefs = $this->getPackagePreferences ();
// Create the preference dialog widget.
// Get Html code to display
$html = $this->toHtml($renderer);
// Run the dialog and return whether or not the user clicked "Yes".
if (isset ($safe['prefBtnYes'])) {
// Get all of the preferences.
// Check for the don't ask preference.
$prefs[PEAR_PACKAGEUPDATE_PREF_NOUPDATES ] = isset ($safe['dontAsk']);
// Check for next version.
$prefs[PEAR_PACKAGEUPDATE_PREF_NEXTRELEASE ] = isset ($safe['nextRelease']);
$prefs[PEAR_PACKAGEUPDATE_PREF_TYPE ] = $safe['allTypes'];
$prefs[PEAR_PACKAGEUPDATE_PREF_STATE ] = $safe['allStates'];
return $this->setPreferences ($prefs);
} elseif (isset ($safe['prefBtnNo'])) {
* Redirects or exits to force the user to restart the application.
header('Location: ' . $_SERVER['PHP_SELF']);
* Presents the user with the option to update.
* @return boolean true if the user would like to update the package.
// Make sure the info has been grabbed.
// This will just return if the info has already been grabbed.
// Create the main dialog widget.
// Get Html code to display
$html = $this->toHtml($renderer);
// Run the dialog and return whether or not the user clicked "Yes".
if (isset ($safe['mainBtnYes'])) {
} elseif (isset ($safe['mainBtnNo'])) {
* Presents an error in a dialog window.
* @param boolean $context true if you want to have error context details
* @return boolean true if an error was displayed.
// Check to see if there are errors into stack.
if ($this->hasErrors ()) {
$error = $this->popError ();
// Create the error dialog widget.
$this->errwidget->setConstants (array ('message' => $error['message']));
// Fill the context details
$file = $line = $function = $class = '';
if (isset ($error['context']['file'])) {
$file = $error['context']['file'];
if (isset ($error['context']['line'])) {
$line = $error['context']['line'];
if (isset ($error['context']['function'])) {
$function = $error['context']['function'];
if (isset ($error['context']['class'])) {
$class = $error['context']['class'];
'context_function' => $function,
'context_class' => $class
// Get Html code to display
$html = $this->toHtml($renderer);
* Returns HTML renderer for a dialog with input labels and values
* @return object instance of a QuickForm renderer
$formTemplate = "\n<form{attributes}>"
. "\n<table class=\"dialogbox\">"
$headerTemplate = "\n<tr>"
. "\n\t<td class=\"widget-header\" colspan=\"2\">"
$elementTemplate = "\n<tr>"
. "\n\t<td class=\"widget-label\"><!-- BEGIN label -->{label}<!-- END label --></td>"
. "\n\t<td class=\"widget-input\">{element}</td>"
$elementNavig = "\n<tr class=\"widget-buttons\">"
. "\n\t<td>{element}</td>"
$renderer = & $widget->defaultRenderer ();
$renderer->setFormTemplate ($formTemplate);
$renderer->setHeaderTemplate ($headerTemplate);
$renderer->setElementTemplate ($elementTemplate);
$renderer->setElementTemplate ($elementNavig, 'buttons');
$widget->accept ($renderer);
* Returns HTML renderer for a dialog with only input values (no labels)
* @return object instance of a QuickForm renderer
$formTemplate = "\n<form{attributes}>"
. "\n<table class=\"dialogbox\">"
$headerTemplate = "\n<tr>"
. "\n\t<td class=\"widget-header\">"
$elementTemplate = "\n<tr>"
. "\n\t<td class=\"widget-input\">{element}</td>"
$elementNavig = "\n<tr class=\"widget-buttons\">"
. "\n\t<td>{element}</td>"
. "\n\t<td class=\"widget-input\"><!-- BEGIN label -->{label}<!-- END label --><br />{element}</td>"
$renderer = & $widget->defaultRenderer ();
$renderer->setFormTemplate ($formTemplate);
$renderer->setHeaderTemplate ($headerTemplate);
$renderer->setElementTemplate ($elementTemplate);
$renderer->setElementTemplate ($elementNavig, 'buttons');
$renderer->setElementTemplate ($elementRadio, 'allStates');
$renderer->setElementTemplate ($elementRadio, 'allTypes');
$widget->accept ($renderer);
* Returns HTML code of a dialog box.
background-color: #CCCCCC;
$body = $renderer->toHtml ();
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<title>PEAR_PackageUpdate Web Frontend</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
Documentation generated on Mon, 11 Mar 2019 14:41:57 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|